[asterisk-commits] mjordan: trunk r346857 - in /trunk: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 2 17:30:28 CST 2011


Author: mjordan
Date: Fri Dec  2 17:30:21 2011
New Revision: 346857

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=346857
Log:
Update SIP MESSAGE To parsing to correctly handle URI

The previous patch (r346040) incorrectly parsed the URI in the presence
of a port, e.g., user at hostname:port would fail as the port would be
double appended to the SIP message.  This patch uses the parse_uri function
to correctly parse the URI into its username and hostname parts, and places
them in the correct fields in the sip_pvt structure.

(issue ASTERISK-18903)
Review: https://reviewboard.asterisk.org/r/1597/
........

Merged revisions 346856 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/channels/chan_sip.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=346857&r1=346856&r2=346857
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Fri Dec  2 17:30:21 2011
@@ -24332,25 +24332,17 @@
 {
 	struct sip_pvt *pvt;
 	int res;
-	char *uri, *host;
+	char *to_uri, *to_host, *to_user;
 	struct sip_peer *peer_ptr;
 
 	if (!(pvt = sip_alloc(NULL, NULL, 0, SIP_MESSAGE, NULL))) {
 		return -1;
 	}
 
-	uri = ast_strdupa(to);
-	if (!strncasecmp(uri, "sip:", 4)) {
-		uri += 4;
-	} else if (!strncasecmp(uri, "sips:", 5)) {
-		uri += 5;
-	}
-	host = ast_strdupa(uri);
-	if (strchr(host, '@')) {
-		strsep(&host, "@");
-	}
-
-	if (ast_strlen_zero(host)) {
+	to_uri = ast_strdupa(to);
+	parse_uri(to_uri, "sip:,sips:", &to_user, NULL, &to_host, NULL);
+
+	if (ast_strlen_zero(to_host)) {
 		ast_log(LOG_WARNING, "MESSAGE(to) is invalid for SIP - '%s'\n", to);
 		dialog_unlink_all(pvt);
 		dialog_unref(pvt, "MESSAGE(to) is invalid for SIP");
@@ -24387,15 +24379,16 @@
 	sip_pvt_lock(pvt);
 
 	/* Look up the host to contact */
-	if (create_addr(pvt, host, NULL, TRUE, NULL)) {
+	if (create_addr(pvt, to_host, NULL, TRUE, NULL)) {
 		sip_pvt_unlock(pvt);
 		dialog_unlink_all(pvt);
 		dialog_unref(pvt, "create_addr failed sending a MESSAGE");
 		return -1;
 	}
 
-	/* Set the tohost to the full URI provided */
-	ast_string_field_set(pvt, tohost, uri);
+	if (!ast_strlen_zero(to_user)) {
+		ast_string_field_set(pvt, username, to_user);
+	}
 	ast_sip_ouraddrfor(&pvt->sa, &pvt->ourip, pvt);
 	ast_set_flag(&pvt->flags[0], SIP_OUTGOING);
 




More information about the asterisk-commits mailing list