[asterisk-commits] mmichelson: branch group/pimp_my_sip r379089 - /team/group/pimp_my_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 14 18:02:34 CST 2013


Author: mmichelson
Date: Mon Jan 14 18:02:31 2013
New Revision: 379089

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379089
Log:
Add a hardcoded transport to the PJSIP endpoint on startup.

With this in place, Asterisk should be able to receive inbound
SIP messages at 127.0.0.1 on UDP port 5060. This doesn't have
much practical value, but it now allows for some simple testing
to be done.


Modified:
    team/group/pimp_my_sip/res/res_sip.c

Modified: team/group/pimp_my_sip/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip.c?view=diff&rev=379089&r1=379088&r2=379089
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Mon Jan 14 18:02:31 2013
@@ -380,6 +380,26 @@
 	return NULL;
 }
 
+static void start_transports(void)
+{
+	/* XXX In reality, this should use sorcery to determine
+	 * configured transports and add them to ast_pjsip_endpoint.
+	 * However, our initial goal is to get just *something* working
+	 * so we're hardcoding our sole transport to UDP 127.0.0.1:5060
+	 */
+	pjsip_transport *hardcoded_transport = NULL;
+	pj_sockaddr addr;
+	pj_str_t home = { "127.0.0.1:5060", 14 };
+	if (pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &home, &addr) != PJ_SUCCESS) {
+		return -1;
+	}
+
+	if (pjsip_udp_transport_start(ast_pjsip_endpoint, &addr, NULL, 2, &hardcoded_transport) != PJ_SUCCESS) {
+		return -1;
+	}
+	return 0;
+}
+
 static int load_module(void)
 {
     /* The third parameter is just copied from
@@ -392,21 +412,31 @@
 	memory_pool = pj_pool_create(&caching_pool.factory, "SIP", 1024, 1024, NULL);
 	if (!memory_pool) {
 		ast_log(LOG_ERROR, "Failed to create memory pool for SIP. Aborting load\n");
-		pjsip_endpt_destroy(ast_pjsip_endpoint);
-		pj_caching_pool_destroy(&caching_pool);
-		return AST_MODULE_LOAD_DECLINE;
+		goto error;
 	}
 
 	status = pj_thread_create(memory_pool, "SIP", (pj_thread_proc *) &monitor_thread_exec,
 			NULL, PJ_THREAD_DEFAULT_STACK_SIZE * 2, 0, &monitor_thread);
 	if (status != PJ_SUCCESS) {
 		ast_log(LOG_ERROR, "Failed to start SIP monitor thread. Aborting load\n");
+		goto error;
+	}
+	if (start_transports()) {
+		ast_log(LOG_ERROR, "Failed to start SIP transports. Aborting load\n");
+		goto error;
+	}
+	return AST_MODULE_LOAD_SUCCESS;
+
+error:
+	if (memory_pool) {
 		pj_pool_release(memory_pool);
+	}
+	if (ast_pjsip_endpoint) {
 		pjsip_endpt_destroy(ast_pjsip_endpoint);
-		pj_caching_pool_destroy(&caching_pool);
-		return AST_MODULE_LOAD_DECLINE;
-	}
-	return AST_MODULE_LOAD_SUCCESS;
+	}
+	pj_caching_pool_destroy(&caching_pool);
+	/* XXX Should have a way of stopping monitor thread */
+	return AST_MODULE_LOAD_DECLINE;
 }
 
 static int unload_module(void)




More information about the asterisk-commits mailing list