[asterisk-commits] file: branch group/pimp_my_sip r379863 - /team/group/pimp_my_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 09:40:29 CST 2013


Author: file
Date: Tue Jan 22 09:40:25 2013
New Revision: 379863

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379863
Log:
Remove all hardcoded IP addresses and tweak local SDP generation to not require an offer.

Modified:
    team/group/pimp_my_sip/res/res_sip.c
    team/group/pimp_my_sip/res/res_sip.exports.in
    team/group/pimp_my_sip/res/res_sip_sdp_audio.c
    team/group/pimp_my_sip/res/res_sip_session.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=379863&r1=379862&r2=379863
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Tue Jan 22 09:40:25 2013
@@ -485,7 +485,7 @@
 	 */
 	pjsip_transport *hardcoded_transport = NULL;
 	pj_sockaddr addr;
-	pj_str_t home = { "172.16.1.6:5060", 15 };
+	pj_str_t home = { "0.0.0.0:5060", 12 };
 	pj_status_t status;
 	char errbuf[20];
 

Modified: team/group/pimp_my_sip/res/res_sip.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip.exports.in?view=diff&rev=379863&r1=379862&r2=379863
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.exports.in (original)
+++ team/group/pimp_my_sip/res/res_sip.exports.in Tue Jan 22 09:40:25 2013
@@ -25,6 +25,7 @@
 		LINKER_SYMBOL_PREFIXpj_*;
 		LINKER_SYMBOL_PREFIXpjsip_*;
 		LINKER_SYMBOL_PREFIXpjmedia_*;
+		LINKER_SYMBOL_PREFIXPJ_*;
 	local:
 		*;
 };

Modified: team/group/pimp_my_sip/res/res_sip_sdp_audio.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_sdp_audio.c?view=diff&rev=379863&r1=379862&r2=379863
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_sdp_audio.c (original)
+++ team/group/pimp_my_sip/res/res_sip_sdp_audio.c Tue Jan 22 09:40:25 2013
@@ -67,10 +67,19 @@
 /*! \brief Internal function which creates an RTP instance */
 static int audio_create_rtp(struct ast_sip_session *session)
 {
+	pj_sockaddr addr;
+	char hostip[PJ_INET6_ADDRSTRLEN+2];
 	struct ast_sockaddr tmp;
 
-	/* TODO: Add support for IPv6 */
-	ast_sockaddr_parse(&tmp, "0.0.0.0", 0);
+	if (pj_gethostip(pj_AF_INET(), &addr) != PJ_SUCCESS) {
+		return -1;
+	}
+
+	pj_sockaddr_print(&addr, hostip, sizeof(hostip), 2);
+
+	if (!ast_sockaddr_parse(&tmp, hostip, 0)) {
+		return -1;
+	}
 
 	if (!(session->media.audio = ast_rtp_instance_new("asterisk", sched, &tmp, NULL))) {
 		return -1;
@@ -217,8 +226,7 @@
 	ast_rtp_instance_get_local_address(session->media.audio, &addr);
 	pj_strdup2(pool, &media->conn->net_type, "IN");
 	pj_strdup2(pool, &media->conn->addr_type, (ast_sockaddr_is_ipv6(&addr) && !ast_sockaddr_is_ipv4_mapped(&addr)) ? "IP6" : "IP4");
-	pj_strdup2(pool, &media->conn->addr, "172.16.1.6");
-//	pj_strdup2(pool, &media->conn->addr, ast_sockaddr_stringify_addr_remote(&addr));
+	pj_strdup2(pool, &media->conn->addr, ast_sockaddr_stringify_addr_remote(&addr));
 	media->desc.port = (pj_uint16_t) ast_sockaddr_port(&addr);
 	media->desc.port_count = 1;
 

Modified: team/group/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_session.c?view=diff&rev=379863&r1=379862&r2=379863
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Tue Jan 22 09:40:25 2013
@@ -55,7 +55,7 @@
 	char stream_type[1];
 };
 
-static void session_inv_on_rx_offer(pjsip_inv_session *inv, const pjmedia_sdp_session *offer);
+static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer);
 
 static int sdp_handler_list_hash(const void *obj, int flags)
 {
@@ -546,6 +546,7 @@
 	struct ast_sip_session *session = NULL;
 	struct ast_sip_session_supplement *supplement = NULL;
 	pjsip_rdata_sdp_info *sdp_info;
+	pjmedia_sdp_session *local = NULL;
 
 	inv_session = pre_session_setup(rdata);
 	if (!inv_session) {
@@ -611,8 +612,32 @@
 	};
 
         if ((sdp_info = pjsip_rdata_get_sdp_info(rdata)) && (sdp_info->sdp_err == PJ_SUCCESS)) {
-                session_inv_on_rx_offer(inv_session, sdp_info->sdp);
-        }
+		if (handle_incoming_sdp(session, sdp_info->sdp)) {
+			if (pjsip_inv_end_session(inv_session, 500, NULL, &tdata) == PJ_SUCCESS) {
+				ast_sip_session_send_response(session, tdata);
+			} else {
+				pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+			}
+			return;
+		}
+		/* We are creating a local SDP which is an answer to their offer */
+		local = create_local_sdp(inv_session, session, sdp_info->sdp);
+        } else {
+		/* We are creating a local SDP which is an offer */
+		local = create_local_sdp(inv_session, session, NULL);
+	}
+
+	/* If we were unable to create a local SDP terminate the session early, it won't go anywhere */
+	if (!local) {
+		if (pjsip_inv_end_session(inv_session, 500, NULL, &tdata) == PJ_SUCCESS) {
+			ast_sip_session_send_response(session, tdata);
+		} else {
+			pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+		}
+		return;
+	} else {
+		pjsip_inv_set_local_sdp(inv_session, local);
+	}
 
 	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
 		if (!supplement->method || !strcmp(supplement->method, "INVITE")) {
@@ -702,34 +727,54 @@
 	return 0;
 }
 
-static void session_inv_on_rx_offer(pjsip_inv_session *inv, const pjmedia_sdp_session *offer)
-{
-	struct ast_sip_session *session = inv->mod_data[session_module.id];
-	pjmedia_sdp_session *answer;
-
-	if (handle_incoming_sdp(session, offer)) {
-		return;
-	}
-	answer = PJ_POOL_ZALLOC_T(inv->pool, pjmedia_sdp_session);
-	answer->origin.version = offer->origin.version + 1;
-	answer->origin.id = offer->origin.id;
-	pj_strdup2(inv->dlg->pool, &answer->origin.user, "Asterisk");
+static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer)
+{
+	pjmedia_sdp_session *local;
+
+	if (!(local = PJ_POOL_ZALLOC_T(inv->pool, pjmedia_sdp_session))) {
+		return NULL;
+	}
+
+	if (!offer) {
+		local->origin.version = local->origin.id = (pj_uint32_t)(ast_random());
+	} else {
+		local->origin.version = offer->origin.version + 1;
+		local->origin.id = offer->origin.id;
+	}
+
+	pj_strdup2(inv->dlg->pool, &local->origin.user, "Asterisk");
+
 	/* XXX Hardcoded origin net stuff for now. Replace with transport
 	 * stuff later
 	 */
-	pj_strdup2(inv->dlg->pool, &answer->origin.net_type, "IN");
-	pj_strdup2(inv->dlg->pool, &answer->origin.addr_type, "IP4");
-	pj_strdup2(inv->dlg->pool, &answer->origin.addr, "127.0.0.1");
-	answer->name = answer->origin.user;
-	/* Now let the handlers add streams of various types */
-	ao2_callback_data(sdp_handlers, 0, add_sdp_streams, answer, session);
+	pj_strdup2(inv->dlg->pool, &local->origin.net_type, "IN");
+	pj_strdup2(inv->dlg->pool, &local->origin.addr_type, "IP4");
+	local->origin.addr = *pj_gethostname();
+	local->name = local->origin.user;
+
+	/* Now let the handlers add streams of various types, pjmedia will automatically reorder the media streams for us */
+	ao2_callback_data(sdp_handlers, 0, add_sdp_streams, local, session);
 
 	/* Use the connection details of the first media stream if possible for SDP level */
-	if (answer->media_count) {
-		answer->conn = answer->media[0]->conn;
-	}
-
-	pjsip_inv_set_sdp_answer(inv, answer);
+	if (local->media_count) {
+		local->conn = local->media[0]->conn;
+	}
+
+	return local;
+}
+
+static void session_inv_on_rx_offer(pjsip_inv_session *inv, const pjmedia_sdp_session *offer)
+{
+	struct ast_sip_session *session = inv->mod_data[session_module.id];
+	pjmedia_sdp_session *answer;
+
+	if (handle_incoming_sdp(session, offer)) {
+		return;
+	}
+
+	if ((answer = create_local_sdp(inv, session, offer))) {
+		pjsip_inv_set_sdp_answer(inv, answer);
+	}
 }
 
 #if 0




More information about the asterisk-commits mailing list