[svn-commits] file: branch file/stasis_peerevent r390399 - in /team/file/stasis_peerevent: ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 4 11:02:48 CDT 2013


Author: file
Date: Tue Jun  4 11:02:46 2013
New Revision: 390399

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390399
Log:
Add a persistent runtime endpoint to chan_pjsip.

Modified:
    team/file/stasis_peerevent/channels/chan_gulp.c
    team/file/stasis_peerevent/include/asterisk/res_sip.h
    team/file/stasis_peerevent/res/res_sip/sip_configuration.c

Modified: team/file/stasis_peerevent/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/channels/chan_gulp.c?view=diff&rev=390399&r1=390398&r2=390399
==============================================================================
--- team/file/stasis_peerevent/channels/chan_gulp.c (original)
+++ team/file/stasis_peerevent/channels/chan_gulp.c Tue Jun  4 11:02:46 2013
@@ -460,6 +460,8 @@
 	ast_channel_context_set(chan, session->endpoint->context);
 	ast_channel_exten_set(chan, S_OR(exten, "s"));
 	ast_channel_priority_set(chan, 1);
+
+	ast_endpoint_add_channel(session->endpoint->persistent, chan);
 
 	return chan;
 }

Modified: team/file/stasis_peerevent/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/include/asterisk/res_sip.h?view=diff&rev=390399&r1=390398&r2=390399
==============================================================================
--- team/file/stasis_peerevent/include/asterisk/res_sip.h (original)
+++ team/file/stasis_peerevent/include/asterisk/res_sip.h Tue Jun  4 11:02:46 2013
@@ -30,6 +30,8 @@
 #include "asterisk/sorcery.h"
 /* Needed for ast_dnsmgr */
 #include "asterisk/dnsmgr.h"
+/* Needed for ast_endpoint */
+#include "asterisk/endpoints.h"
 /* Needed for pj_sockaddr */
 #include <pjlib.h>
 
@@ -326,6 +328,8 @@
 	unsigned int send_rpid;
 	/*! Should unsolicited MWI be aggregated into a single NOTIFY? */
 	unsigned int aggregate_mwi;
+	/*! Pointer to the persistent Asterisk endpoint */
+	struct ast_endpoint *persistent;
 };
 
 /*!

Modified: team/file/stasis_peerevent/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/res/res_sip/sip_configuration.c?view=diff&rev=390399&r1=390398&r2=390399
==============================================================================
--- team/file/stasis_peerevent/res/res_sip/sip_configuration.c (original)
+++ team/file/stasis_peerevent/res/res_sip/sip_configuration.c Tue Jun  4 11:02:46 2013
@@ -17,8 +17,42 @@
 #include "asterisk/utils.h"
 #include "asterisk/sorcery.h"
 #include "asterisk/callerid.h"
+#include "asterisk/stasis_endpoints.h"
+
+/*! \brief Number of buckets for persistent endpoint information */
+#define PERSISTENT_BUCKETS 53
+
+/*! \brief Persistent endpoint information */
+struct sip_persistent_endpoint {
+	/*! \brief Asterisk endpoint itself */
+	struct ast_endpoint *endpoint;
+	/*! \brief AORs that we should react to */
+	char *aors;
+};
+
+/*! \brief Container for persistent endpoint information */
+static struct ao2_container *persistent_endpoints;
 
 static struct ast_sorcery *sip_sorcery;
+
+/*! \brief Hashing function for persistent endpoint information */
+static int persistent_endpoint_hash(const void *obj, const int flags)
+{
+	const struct sip_persistent_endpoint *persistent = obj;
+	const char *id = (flags & OBJ_KEY ? obj : ast_endpoint_get_resource(persistent->endpoint));
+
+	return ast_str_hash(id);
+}
+
+/*! \brief Comparison function for persistent endpoint information */
+static int persistent_endpoint_cmp(void *obj, void *arg, int flags)
+{
+	const struct sip_persistent_endpoint *persistent1 = obj;
+	const struct sip_persistent_endpoint *persistent2 = arg;
+	const char *id = (flags & OBJ_KEY ? arg : ast_endpoint_get_resource(persistent2->endpoint));
+
+	return !strcmp(ast_endpoint_get_resource(persistent1->endpoint), id) ? CMP_MATCH | CMP_STOP : 0;
+}
 
 static char *handle_cli_show_endpoints(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -281,9 +315,59 @@
 	return ao2_alloc(sizeof(struct ast_sip_nat_hook), NULL);
 }
 
+/*! \brief Destructor function for persistent endpoint information */
+static void persistent_endpoint_destroy(void *obj)
+{
+	struct sip_persistent_endpoint *persistent = obj;
+
+	ast_endpoint_shutdown(persistent->endpoint);
+	ast_free(persistent->aors);
+}
+
+/*! \brief Internal function which finds (or creates) persistent endpoint information */
+static struct ast_endpoint *persistent_endpoint_find_or_create(const struct ast_sip_endpoint *endpoint)
+{
+	RAII_VAR(struct sip_persistent_endpoint *, persistent, NULL, ao2_cleanup);
+	SCOPED_AO2LOCK(lock, persistent_endpoints);
+
+	if (!(persistent = ao2_find(persistent_endpoints, ast_sorcery_object_get_id(endpoint), OBJ_KEY | OBJ_NOLOCK))) {
+		if (!(persistent = ao2_alloc(sizeof(*persistent), persistent_endpoint_destroy))) {
+			return NULL;
+		}
+
+		if (!(persistent->endpoint = ast_endpoint_create("Gulp", ast_sorcery_object_get_id(endpoint)))) {
+			return NULL;
+		}
+
+		ao2_link_flags(persistent_endpoints, persistent, OBJ_NOLOCK);
+	}
+
+	ast_free(persistent->aors);
+	persistent->aors = ast_strdup(endpoint->aors);
+
+	ao2_ref(persistent->endpoint, +1);
+	return persistent->endpoint;
+}
+
+/*! \brief Callback function for when an object is finalized */
+static int sip_endpoint_apply_handler(const struct ast_sorcery *sorcery, void *obj)
+{
+	struct ast_sip_endpoint *endpoint = obj;
+
+	if (!(endpoint->persistent = persistent_endpoint_find_or_create(endpoint))) {
+		return -1;
+	}
+
+	return 0;
+}
+
 int ast_res_sip_initialize_configuration(void)
 {
 	if (ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands))) {
+		return -1;
+	}
+
+	if (!(persistent_endpoints = ao2_container_alloc(PERSISTENT_BUCKETS, persistent_endpoint_hash, persistent_endpoint_cmp))) {
 		return -1;
 	}
 
@@ -305,7 +389,7 @@
 
 	ast_sorcery_apply_default(sip_sorcery, "nat_hook", "memory", NULL);
 
-	if (ast_sorcery_object_register(sip_sorcery, "endpoint", ast_sip_endpoint_alloc, NULL, NULL)) {
+	if (ast_sorcery_object_register(sip_sorcery, "endpoint", ast_sip_endpoint_alloc, NULL, sip_endpoint_apply_handler)) {
 		ast_log(LOG_ERROR, "Failed to register SIP endpoint object with sorcery\n");
 		ast_sorcery_unref(sip_sorcery);
 		sip_sorcery = NULL;
@@ -404,6 +488,7 @@
 	destroy_auths(endpoint->sip_inbound_auths, endpoint->num_inbound_auths);
 	destroy_auths(endpoint->sip_outbound_auths, endpoint->num_outbound_auths);
 	ast_party_id_free(&endpoint->id);
+	ao2_cleanup(endpoint->persistent);
 }
 
 void *ast_sip_endpoint_alloc(const char *name)




More information about the svn-commits mailing list