[asterisk-commits] qwell: branch qwell/fun_with_transports r388341 - in /team/qwell/fun_with_tra...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 10 11:30:54 CDT 2013


Author: qwell
Date: Fri May 10 11:30:52 2013
New Revision: 388341

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388341
Log:
Switch away from sorcery for storage of transports.

Modified:
    team/qwell/fun_with_transports/include/asterisk/res_sip.h
    team/qwell/fun_with_transports/res/res_sip.c
    team/qwell/fun_with_transports/res/res_sip.exports.in
    team/qwell/fun_with_transports/res/res_sip/include/res_sip_private.h
    team/qwell/fun_with_transports/res/res_sip/location.c
    team/qwell/fun_with_transports/res/res_sip_transport_websocket.c

Modified: team/qwell/fun_with_transports/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/include/asterisk/res_sip.h?view=diff&rev=388341&r1=388340&r2=388341
==============================================================================
--- team/qwell/fun_with_transports/include/asterisk/res_sip.h (original)
+++ team/qwell/fun_with_transports/include/asterisk/res_sip.h Fri May 10 11:30:52 2013
@@ -154,7 +154,6 @@
  * \brief A transport to be used for messages to a contact
  */
 struct ast_sip_contact_transport {
-	SORCERY_OBJECT(details);
 	AST_DECLARE_STRING_FIELDS(
 		/*! Full URI of the contact */
 		AST_STRING_FIELD(uri);
@@ -645,6 +644,17 @@
 struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_name);
 
 /*!
+ * \brief Add a transport for a contact to use
+ */
+
+void ast_sip_location_add_contact_transport(struct ast_sip_contact_transport *ct);
+
+/*!
+ * \brief Delete a transport for a contact that went away
+ */
+void ast_sip_location_delete_contact_transport(struct ast_sip_contact_transport *ct);
+
+/*!
  * \brief Retrieve a contact_transport, by URI
  *
  * \param contact_uri URI of the contact

Modified: team/qwell/fun_with_transports/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip.c?view=diff&rev=388341&r1=388340&r2=388341
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip.c (original)
+++ team/qwell/fun_with_transports/res/res_sip.c Fri May 10 11:30:52 2013
@@ -857,6 +857,8 @@
 
 	ast_res_sip_init_options_handling(0);
 
+	ast_res_sip_init_contact_transports();
+
 return AST_MODULE_LOAD_SUCCESS;
 
 error:

Modified: team/qwell/fun_with_transports/res/res_sip.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip.exports.in?view=diff&rev=388341&r1=388340&r2=388341
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip.exports.in (original)
+++ team/qwell/fun_with_transports/res/res_sip.exports.in Fri May 10 11:30:52 2013
@@ -37,6 +37,8 @@
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_contact_from_aor_list;
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_aor_contacts;
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_contact;
+		LINKER_SYMBOL_PREFIXast_sip_location_add_contact_transport;
+		LINKER_SYMBOL_PREFIXast_sip_location_delete_contact_transport;
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_contact_transport_by_uri;
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_contact_transport_by_transport;
 		LINKER_SYMBOL_PREFIXast_sip_location_add_contact;

Modified: team/qwell/fun_with_transports/res/res_sip/include/res_sip_private.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip/include/res_sip_private.h?view=diff&rev=388341&r1=388340&r2=388341
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip/include/res_sip_private.h (original)
+++ team/qwell/fun_with_transports/res/res_sip/include/res_sip_private.h Fri May 10 11:30:52 2013
@@ -40,6 +40,14 @@
 int ast_res_sip_init_options_handling(int reload);
 
 /*!
+ * \brief Initialize transport storage for contacts.
+ *
+ * \retval 0 on success
+ * \retval other on failure
+ */
+int ast_res_sip_init_contact_transports(void);
+
+/*!
  * \brief Initialize outbound authentication support
  *
  * \retval 0 Success

Modified: team/qwell/fun_with_transports/res/res_sip/location.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip/location.c?view=diff&rev=388341&r1=388340&r2=388341
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip/location.c (original)
+++ team/qwell/fun_with_transports/res/res_sip/location.c Fri May 10 11:30:52 2013
@@ -24,6 +24,10 @@
 #include "asterisk/logger.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/sorcery.h"
+#include "include/res_sip_private.h"
+
+#define CONTACT_TRANSPORTS_BUCKETS 7
+static struct ao2_container *contact_transports;
 
 /*! \brief Destructor for AOR */
 static void aor_destroy(void *obj)
@@ -70,30 +74,6 @@
 	return contact;
 }
 
-/*! \brief Destructor for contact_transport */
-static void contact_transport_destroy(void *obj)
-{
-	struct ast_sip_contact_transport *ct = obj;
-
-	ast_string_field_free_memory(ct);
-}
-
-static void *contact_transport_alloc(const char *name)
-{
-	struct ast_sip_contact_transport *ct = ao2_alloc_options(sizeof(*ct), contact_transport_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
-
-	if (!ct) {
-		return NULL;
-	}
-
-	if (ast_string_field_init(ct, 256)) {
-		ao2_cleanup(ct);
-		return NULL;
-	}
-
-	return ct;
-}
-
 /*! \brief Callback function for finding a contact_transport by URI */
 static int contact_transport_find_by_uri(void *obj, void *arg, int flags)
 {
@@ -112,13 +92,25 @@
 	return (ct->transport == transport) ? CMP_MATCH | CMP_STOP : 0;
 }
 
+void ast_sip_location_add_contact_transport(struct ast_sip_contact_transport *ct)
+{
+	ao2_link(contact_transports, ct);
+
+	return;
+}
+
+void ast_sip_location_delete_contact_transport(struct ast_sip_contact_transport *ct)
+{
+	ao2_unlink(contact_transports, ct);
+
+	return;
+}
+
 struct ast_sip_contact_transport *ast_sip_location_retrieve_contact_transport_by_uri(const char *contact_uri)
 {
-	RAII_VAR(struct ao2_container *, cts, NULL, ao2_cleanup);
 	struct ast_sip_contact_transport *ct;
 
-	if (!(cts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact_transport", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL)) ||
-		!(ct = ao2_callback(cts, 0, contact_transport_find_by_uri, (void *)contact_uri))) {
+	if (!(ct = ao2_callback(contact_transports, 0, contact_transport_find_by_uri, (void *)contact_uri))) {
 		return NULL;
 	}
 
@@ -127,11 +119,9 @@
 
 struct ast_sip_contact_transport *ast_sip_location_retrieve_contact_transport_by_transport(pjsip_transport *transport)
 {
-	RAII_VAR(struct ao2_container *, cts, NULL, ao2_cleanup);
 	struct ast_sip_contact_transport *ct;
 
-	if (!(cts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact_transport", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL)) ||
-		!(ct = ao2_callback(cts, 0, contact_transport_find_by_transport, transport))) {
+	if (!(ct = ao2_callback(contact_transports, 0, contact_transport_find_by_transport, transport))) {
 		return NULL;
 	}
 
@@ -307,11 +297,9 @@
 {
 	ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar");
 	ast_sorcery_apply_default(sorcery, "aor", "config", "res_sip.conf,criteria=type=aor");
-	ast_sorcery_apply_default(sorcery, "contact_transport", "memory", NULL);
 
 	if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, NULL) ||
-		ast_sorcery_object_register(sorcery, "aor", aor_alloc, NULL, NULL) ||
-		ast_sorcery_object_register(sorcery, "contact_transport", contact_transport_alloc, NULL, NULL)) {
+		ast_sorcery_object_register(sorcery, "aor", aor_alloc, NULL, NULL)) {
 		return -1;
 	}
 
@@ -328,7 +316,19 @@
 	ast_sorcery_object_field_register_custom(sorcery, "aor", "contact", "", permanent_uri_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register(sorcery, "aor", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, mailboxes));
 
-	ast_sorcery_object_field_register(sorcery, "contact_transport", "uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact_transport, uri));
-
 	return 0;
 }
+
+int ast_res_sip_init_contact_transports(void)
+{
+	if (contact_transports) {
+		ao2_t_ref(contact_transports, -1, "Remove old scheduled qualifies");
+	}
+
+	contact_transports = ao2_t_container_alloc(CONTACT_TRANSPORTS_BUCKETS, NULL, NULL, "Create container for contact transports");
+	if (!contact_transports) {
+		return -1;
+	}
+
+	return 0;
+}

Modified: team/qwell/fun_with_transports/res/res_sip_transport_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip_transport_websocket.c?view=diff&rev=388341&r1=388340&r2=388341
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip_transport_websocket.c (original)
+++ team/qwell/fun_with_transports/res/res_sip_transport_websocket.c Fri May 10 11:30:52 2013
@@ -99,7 +99,7 @@
 	pjsip_transport *transport = data;
 
 	if ((ct = ast_sip_location_retrieve_contact_transport_by_transport(transport))) {
-		ast_sorcery_delete(ast_sip_get_sorcery(), ct);
+		ast_sip_location_delete_contact_transport(ct);
 	}
 
 	pjsip_transport_shutdown(transport);
@@ -300,6 +300,31 @@
 	.outgoing_request = websocket_outgoing_request,
 };
 
+/*!
+ * \brief Destructor for ast_sip_contact_transport
+ */
+static void contact_transport_destroy(void *obj)
+{
+	struct ast_sip_contact_transport *ct = obj;
+
+	ast_string_field_free_memory(ct);
+}
+
+static void *contact_transport_alloc(void)
+{
+	struct ast_sip_contact_transport *ct = ao2_alloc(sizeof(*ct), contact_transport_destroy);
+
+	if (!ct) {
+		return NULL;
+	}
+
+	if (ast_string_field_init(ct, 256)) {
+		ao2_cleanup(ct);
+		return NULL;
+	}
+
+	return ct;
+}
 
 /*!
  * \brief Store the transport a message came in on, so it can be used for outbound messages to that contact.
@@ -321,19 +346,16 @@
 		pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, pjsip_uri_get_uri(contact_hdr->uri), contact_uri, sizeof(contact_uri));
 
 		if ((ct = ast_sip_location_retrieve_contact_transport_by_uri(contact_uri))) {
-			RAII_VAR(struct ast_sip_contact_transport *, ct_copy, ast_sorcery_copy(ast_sip_get_sorcery(), ct), ao2_cleanup);
-			if (!ct_copy) {
+			ct->transport = rdata->tp_info.transport;
+		} else {
+			if (!(ct = contact_transport_alloc())) {
 				return PJ_TRUE;
 			}
-			ct_copy->transport = rdata->tp_info.transport;
-			ast_sorcery_update(ast_sip_get_sorcery(), ct_copy);
-		} else {
-			if (!(ct = ast_sorcery_alloc(ast_sip_get_sorcery(), "contact_transport", NULL))) {
-				return PJ_TRUE;
-			}
+
 			ast_string_field_set(ct, uri, contact_uri);
 			ct->transport = rdata->tp_info.transport;
-			ast_sorcery_create(ast_sip_get_sorcery(), ct);
+
+			ast_sip_location_add_contact_transport(ct);
 		}
 	}
 




More information about the asterisk-commits mailing list