[svn-commits] dvossel: branch dvossel/sip_uri_encode_decode r235739 - /team/dvossel/sip_uri...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 18 18:22:17 CST 2009


Author: dvossel
Date: Fri Dec 18 18:22:15 2009
New Revision: 235739

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=235739
Log:
removed duplicate code that does the same thing as parse_uri()

Modified:
    team/dvossel/sip_uri_encode_decode/channels/chan_sip.c

Modified: team/dvossel/sip_uri_encode_decode/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_uri_encode_decode/channels/chan_sip.c?view=diff&rev=235739&r1=235738&r2=235739
==============================================================================
--- team/dvossel/sip_uri_encode_decode/channels/chan_sip.c (original)
+++ team/dvossel/sip_uri_encode_decode/channels/chan_sip.c Fri Dec 18 18:22:15 2009
@@ -13517,8 +13517,7 @@
 	enum check_auth_result res = AUTH_NOT_FOUND;
 	struct sip_peer *peer;
 	char tmp[256];
-	char *name, *c;
-	char *domain;
+	char *name = NULL, *c, *domain = NULL, *dummy;
 	char *uri2 = ast_strdupa(uri);
 
 	terminate_uri(uri2);
@@ -13530,34 +13529,17 @@
 	c = get_in_brackets(tmp);
 	c = remove_uri_parameters(c);
 
-	if (!strncasecmp(c, "sip:", 4)) {
-		name = c + 4;
-	} else if (!strncasecmp(c, "sips:", 5)) {
-		name = c + 5;
-	} else {
-		name = c;
+	if (parse_uri(c, "sip:,sips:", &name, &dummy, &domain, &dummy, &dummy, NULL)) {
 		ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_inet_ntoa(sin->sin_addr));
-	}
-
-	/*! \todo XXX here too we interpret a missing @domain as a name-only
-	 * URI, whereas the RFC says this is a domain-only uri.
-	 */
-	/* Strip off the domain name */
-	if ((c = strchr(name, '@'))) {
-		*c++ = '\0';
-		domain = c;
-		if ((c = strchr(domain, ':')))	/* Remove :port */
-			*c = '\0';
-		if (!AST_LIST_EMPTY(&domain_list)) {
-			if (!check_sip_domain(domain, NULL, 0)) {
-				transmit_response(p, "404 Not found (unknown domain)", &p->initreq);
-				return AUTH_UNKNOWN_DOMAIN;
-			}
-		}
-	}
-	c = strchr(name, ';');	/* Remove any Username parameters */
-	if (c)
-		*c = '\0';
+		return -1;
+	}
+
+	if (!AST_LIST_EMPTY(&domain_list)) {
+		if (!check_sip_domain(domain, NULL, 0)) {
+			transmit_response(p, "404 Not found (unknown domain)", &p->initreq);
+			return AUTH_UNKNOWN_DOMAIN;
+		}
+	}
 
 	ast_string_field_set(p, exten, name);
 	build_contact(p);
@@ -14034,10 +14016,9 @@
 */
 static int get_destination(struct sip_pvt *p, struct sip_request *oreq)
 {
-	char tmp[256] = "", *uri, *a;
+	char tmp[256] = "", *uri, *a, *dummy;
 	char tmpf[256] = "", *from = NULL;
 	struct sip_request *req;
-	char *colon;
 	char *decoded_uri;
 	
 	req = oreq;
@@ -14052,15 +14033,13 @@
 		ast_uri_decode(tmp);
 
 	uri = get_in_brackets(tmp);
-	
-	if (!strncasecmp(uri, "sip:", 4)) {
-		uri += 4;
-	} else if (!strncasecmp(uri, "sips:", 5)) {
-		uri += 5;
-	} else {
-		ast_log(LOG_WARNING, "Huh?  Not a SIP header (%s)?\n", uri);
+
+	if (parse_uri(uri, "sip:,sips", &uri, &dummy, &a, &dummy, &dummy, NULL)) {
+		ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", uri);
 		return -1;
 	}
+
+	ast_string_field_set(p, domain, a);
 
 	/* Now find the From: caller ID and name */
 	/* XXX Why is this done in get_destination? Isn't it already done?
@@ -14072,42 +14051,14 @@
 			ast_uri_decode(tmpf);
 		from = get_in_brackets(tmpf);
 	}
-	
+
 	if (!ast_strlen_zero(from)) {
-		if (!strncasecmp(from, "sip:", 4)) {
-			from += 4;
-		} else if (!strncasecmp(from, "sips:", 5)) {
-			from += 5;
-		} else {
-			ast_log(LOG_WARNING, "Huh?  Not a SIP header (%s)?\n", from);
+		if (parse_uri(from, "sip:,sips", &from, &dummy, &a, &dummy, &dummy, NULL)) {
+			ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", from);
 			return -1;
 		}
-		if ((a = strchr(from, '@')))
-			*a++ = '\0';
-		else
-			a = from;	/* just a domain */
-		from = strsep(&from, ";");	/* Remove userinfo options */
-		a = strsep(&a, ";");		/* Remove URI options */
 		ast_string_field_set(p, fromdomain, a);
 	}
-
-	/* Skip any options and find the domain */
-
-	/* Get the target domain */
-	if ((a = strchr(uri, '@'))) {
-		*a++ = '\0';
-	} else {	/* No username part */
-		a = uri;
-		uri = "s";	/* Set extension to "s" */
-	}
-	colon = strchr(a, ':'); /* Remove :port */
-	if (colon)
-		*colon = '\0';
-
-	uri = strsep(&uri, ";");	/* Remove userinfo options */
-	a = strsep(&a, ";");		/* Remove URI options */
-
-	ast_string_field_set(p, domain, a);
 
 	if (!AST_LIST_EMPTY(&domain_list)) {
 		char domain_context[AST_MAX_EXTENSION];
@@ -14432,7 +14383,7 @@
  */
 static int get_also_info(struct sip_pvt *p, struct sip_request *oreq)
 {
-	char tmp[256] = "", *c, *a;
+	char tmp[256] = "", *c, *a, *dummy;
 	struct sip_request *req = oreq ? oreq : &p->initreq;
 	struct sip_refer *referdata = NULL;
 	const char *transfer_context = NULL;
@@ -14448,23 +14399,15 @@
 	if (sip_cfg.pedanticsipchecking)
 		ast_uri_decode(c);
 
-	if (!strncasecmp(c, "sip:", 4)) {
-		c += 4;
-	} else if (!strncasecmp(c, "sips:", 5)) {
-		c += 5;
-	} else {
+	if (parse_uri(c, "sip:,sips", &c, &dummy, &a, &dummy, &dummy, NULL)) {
 		ast_log(LOG_WARNING, "Huh?  Not a SIP header in Also: transfer (%s)?\n", c);
 		return -1;
 	}
 
-	if ((a = strchr(c, ';'))) 	/* Remove arguments */
-		*a = '\0';
-	
-	if ((a = strchr(c, '@'))) {	/* Separate Domain */
-		*a++ = '\0';
+	if (!ast_strlen_zero(a)) {
 		ast_copy_string(referdata->refer_to_domain, a, sizeof(referdata->refer_to_domain));
 	}
-	
+
 	if (sip_debug_test_pvt(p))
 		ast_verbose("Looking for %s in %s\n", c, p->context);
 




More information about the svn-commits mailing list