[svn-commits] mjordan: branch 10 r346856 - /branches/10/channels/chan_sip.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 2 17:27:18 CST 2011


Author: mjordan
Date: Fri Dec  2 17:27:10 2011
New Revision: 346856

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=346856
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/


Modified:
    branches/10/channels/chan_sip.c

Modified: branches/10/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/channels/chan_sip.c?view=diff&rev=346856&r1=346855&r2=346856
==============================================================================
--- branches/10/channels/chan_sip.c (original)
+++ branches/10/channels/chan_sip.c Fri Dec  2 17:27:10 2011
@@ -24276,25 +24276,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");
@@ -24331,15 +24323,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 svn-commits mailing list