[asterisk-commits] oej: trunk r62640 - /trunk/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed May 2 02:41:03 MST 2007


Author: oej
Date: Wed May  2 04:41:03 2007
New Revision: 62640

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62640
Log:
Handle sip:username;parameter=12345 at example.com;parameter=1234 URI's properly

Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=62640&r1=62639&r2=62640
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed May  2 04:41:03 2007
@@ -2429,10 +2429,11 @@
 	return tmp;
 }
 
-/*!
- * parses a URI in its components.
- * If scheme is specified, drop it from the top.
- * If a component is not requested, do not split around it.
+/*! \brief * parses a URI in its components.
+ *
+ * \note 
+ *- If scheme is specified, drop it from the top.
+ * - If a component is not requested, do not split around it.
  * This means that if we don't have domain, we cannot split
  * name:pass and domain:port.
  * It is safe to call with ret_name, pass, domain, port
@@ -2440,6 +2441,7 @@
  * Init pointers to empty string so we never get NULL dereferencing.
  * Overwrites the string.
  * return 0 on success, other values on error.
+ * general form we are expecting is sip[s]:username[:password][;parameter]@host[:port][;...] 
  */
 static int parse_uri(char *uri, char *scheme,
 	char **ret_name, char **pass, char **domain, char **port, char **options)
@@ -2452,13 +2454,12 @@
 		*pass = "";
 	if (port)
 		*port = "";
-	name = strsep(&uri, ";");	/* remove options */
 	if (scheme) {
 		int l = strlen(scheme);
-		if (!strncmp(name, scheme, l))
-			name += l;
+		if (!strncmp(uri, scheme, l))
+			uri += l;
 		else {
-			ast_log(LOG_NOTICE, "Missing scheme '%s' in '%s'\n", scheme, name);
+			ast_log(LOG_NOTICE, "Missing scheme '%s' in '%s'\n", scheme, uri);
 			error = -1;
 		}
 	}
@@ -2472,14 +2473,20 @@
 		 */
 		char *c, *dom = "";
 
-		if ((c = strchr(name, '@')) == NULL) {
+		if ((c = strchr(uri, '@')) == NULL) {
 			/* domain-only URI, according to the SIP RFC. */
-			dom = name;
+			dom = uri;
 			name = "";
 		} else {
 			*c++ = '\0';
 			dom = c;
-		}
+			name = uri;
+		}
+
+		/* Remove options in domain and name */
+		dom = strsep(&dom, ";");
+		name = strsep(&name, ";");
+
 		if (port && (c = strchr(dom, ':'))) { /* Remove :port */
 			*c++ = '\0';
 			*port = c;
@@ -5922,7 +5929,7 @@
 	int debug=sip_debug_test_pvt(p);
 
 	/* Parse uri to h (host) and port - uri is already just the part inside the <> */
-	/* general form we are expecting is sip[s]:username[:password]@host[:port][;...] */
+	/* general form we are expecting is sip[s]:username[:password][;parameter]@host[:port][;...] */
 
 	if (debug)
 		ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri);
@@ -7077,12 +7084,20 @@
 {
 	char stripped[BUFSIZ];
 	char *c;
+	char *atsign;
 
 	ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped));
 	c = get_in_brackets(stripped);
-	c = strsep(&c, ";");	/* trim ; and beyond */
+	/* Cut the URI at the at sign after the @, not in the username part */
+	atsign = strchr(c, '@');	/* First, locate the at sign */
+	if (!atsign)
+		atsign = c;	/* Ok hostname only, let's stick with the rest */
+	atsign = strchr(atsign, ';');	/* Locate semi colon */
+	if (atsign)
+		*atsign = '\0';	/* Kill at the semi colon */
 	if (!ast_strlen_zero(c))
 		ast_string_field_set(p, uri, c);
+
 }
 
 /*! \brief Build contact header - the contact header we send out */



More information about the asterisk-commits mailing list