[asterisk-commits] dvossel: branch 1.6.2 r215523 - in /branches/1.6.2: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 2 12:35:14 CDT 2009


Author: dvossel
Date: Wed Sep  2 12:35:10 2009
New Revision: 215523

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=215523
Log:
Merged revisions 215522 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r215522 | dvossel | 2009-09-02 12:26:40 -0500 (Wed, 02 Sep 2009) | 11 lines
  
  SIP uri parsing cleanup
  
  Now, the scheme passed to parse_uri can either be a
  single scheme, or a list of schemes ',' delimited.
  This gets rid of the whole problem of having to create
  two buffers and calling parse_uri twice to check for
  separate schemes.
  
  Review: https://reviewboard.asterisk.org/r/343/
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/channels/chan_sip.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.2/channels/chan_sip.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.2/channels/chan_sip.c?view=diff&rev=215523&r1=215522&r2=215523
==============================================================================
--- branches/1.6.2/channels/chan_sip.c (original)
+++ branches/1.6.2/channels/chan_sip.c Wed Sep  2 12:35:10 2009
@@ -4060,6 +4060,7 @@
  * \note 
  * - If scheme is specified, drop it from the top.
  * - If a component is not requested, do not split around it.
+ * - Multiple scheme's can be specified ',' delimited. ex: "sip,sips"
  *
  * This means that if we don't have domain, we cannot split
  * name:pass and domain:port.
@@ -4073,7 +4074,7 @@
  * \endverbatim
  * 
  */
-static int parse_uri(char *uri, char *scheme,
+static int parse_uri(char *uri, const char *scheme,
 	char **ret_name, char **pass, char **domain, char **port, char **options, char **transport)
 {
 	char *name = NULL;
@@ -4085,11 +4086,18 @@
 	if (port)
 		*port = "";
 	if (scheme) {
-		int l = strlen(scheme);
-		if (!strncasecmp(uri, scheme, l))
-			uri += l;
-		else {
-			ast_debug(1, "Missing scheme '%s' in '%s'\n", scheme, uri);
+		int l;
+		char *scheme2 = ast_strdupa(scheme);
+		char *cur = strsep(&scheme2, ",");
+		for (; !ast_strlen_zero(cur); cur = strsep(&scheme2, ",")) {
+			l = strlen(cur);
+			if (!strncasecmp(uri, cur, l)) {
+				uri += l;
+				break;
+			}
+		}
+		if (ast_strlen_zero(cur)) {
+			ast_debug(1, "No supported scheme found in '%s' using the scheme[s] %s\n", uri, scheme);
 			error = -1;
 		}
 	}
@@ -11599,42 +11607,33 @@
 {
 	struct hostent *hp;
 	struct ast_hostent ahp;
-	int port;
-	char *host, *pt;
+	int port = STANDARD_SIP_PORT;
+	char *host, *pt, *transport;
 	char contact_buf[256];
-	char contact2_buf[256];
-	char *contact, *contact2;
+	char *contact;
 	int use_tls = FALSE;
 
 	/* Work on a copy */
 	ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf));
-	ast_copy_string(contact2_buf, fullcontact, sizeof(contact2_buf));
 	contact = contact_buf;
-	contact2 = contact2_buf;
-
-	/* We have only the part in <brackets> here so we just need to parse a SIP URI.*/
-
-       /*! \brief This code is wrong, it assumes that the contact we receive will use the
-               same transport as the request. It's not a valid assumption. The contact for
-               a udp connection can be a SIPS uri, or request ;transport=tcp
-               \todo Fix this buggy code. It doesn't even parse transport!!!!
-
-		Note: The outbound proxy could be using UDP between the proxy and Asterisk.
-		We still need to be able to send to the remote agent through the proxy.
-       */
-	if (tcp) {
-		if (!parse_uri(contact, "sips:", &contact, NULL, &host, &pt, NULL, NULL)) {
+
+	/* 
+	 * We have only the part in <brackets> here so we just need to parse a SIP URI.
+	 *
+	 * Note: The outbound proxy could be using UDP between the proxy and Asterisk.
+	 * We still need to be able to send to the remote agent through the proxy.
+	*/
+
+	if (!parse_uri(contact, "sip,sips", &contact, NULL, &host, &pt, NULL, &transport)) {
+		if (((get_transport_str2enum(transport) == SIP_TRANSPORT_TLS)) ||
+			!(strncasecmp(fullcontact, "sips", 4))) {
 			use_tls = TRUE;
+			port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_TLS_PORT;
 		} else {
-			if (parse_uri(contact2, "sip:", &contact, NULL, &host, &pt, NULL, NULL))
-				ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", contact);
-		}
-		port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_TLS_PORT;
-		/*! \todo XXX why are we setting TLS port if there's no port given? parse_uri needs to return the transport. */
+			port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
+		}
 	} else {
-		if (parse_uri(contact, "sip:", &contact, NULL, &host, &pt, NULL, NULL))
-			ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", contact);
-		port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
+		ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
 	}
 
 	/* XXX This could block for a long time XXX */
@@ -11676,7 +11675,7 @@
 	char data[SIPBUFSIZE];
 	const char *expires = get_header(req, "Expires");
 	int expire = atoi(expires);
-	char *curi, *host, *pt, *curi2, *transport;
+	char *curi, *host, *pt, *transport;
 	int port;
 	int transport_type;
 	const char *useragent;
@@ -11706,7 +11705,6 @@
 	if (strchr(contact, '<') == NULL)	/* No <, check for ; and strip it */
 		strsep(&curi, ";");	/* This is Header options, not URI options */
 	curi = get_in_brackets(contact);
-	curi2 = ast_strdupa(curi);
 
 	/* if they did not specify Contact: or Expires:, they are querying
 	   what we currently have stored as their contact address, so return
@@ -11747,16 +11745,8 @@
 	ast_string_field_build(pvt, our_contact, "<%s>", curi);
 
 	/* Make sure it's a SIP URL */
-	if (pvt->socket.type == SIP_TRANSPORT_TLS) {
-		if (parse_uri(curi, "sips:", &curi, NULL, &host, &pt, NULL, &transport)) {
-			if (parse_uri(curi2, "sip:", &curi, NULL, &host, &pt, NULL, &transport))
-				ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
-		}
-		port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_TLS_PORT;
-	} else {
-		if (parse_uri(curi, "sip:", &curi, NULL, &host, &pt, NULL, &transport))
-			ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
-		port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
+	if (parse_uri(curi, "sip,sips", &curi, NULL, &host, &pt, NULL, &transport)) {
+		ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
 	}
 
 	/* handle the transport type specified in Contact header. */
@@ -11766,8 +11756,11 @@
 		 * same transport used by the pvt struct for the Register dialog. */
 		if (ast_strlen_zero(pt)) {
 			port = (transport_type == SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
+		} else {
+			port = atoi(pt);
 		}
 	} else {
+		port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
 		transport_type = pvt->socket.type;
 	}
 
@@ -13536,7 +13529,7 @@
 	char from[256];
 	char *dummy;	/* dummy return value for parse_uri */
 	char *domain;	/* dummy return value for parse_uri */
-	char *of, *of2;
+	char *of;
 	char rpid_num[50];
 	const char *rpid;
 	enum check_auth_result res;
@@ -13576,19 +13569,9 @@
 	/* save the URI part of the From header */
 	ast_string_field_set(p, from, of);
 
-	of2 = ast_strdupa(of);
-
 	/* ignore all fields but name */
-	/*! \todo Samme logical error as in many places above. Need a generic function for this.
- 	*/
-	if (p->socket.type == SIP_TRANSPORT_TLS) {
-		if (parse_uri(of, "sips:", &of, &dummy, &domain, &dummy, &dummy, NULL)) {
-			if (parse_uri(of2, "sip:", &of, &dummy, &domain, &dummy, &dummy, NULL))
-				ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
-		}
-	} else {
-		if (parse_uri(of, "sip:", &of, &dummy, &domain, &dummy, &dummy, NULL))
-			ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
+	if (parse_uri(of, "sip,sips", &of, &dummy, &domain, &dummy, &dummy, NULL)) {
+		ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
 	}
 
 	if (ast_strlen_zero(of)) {




More information about the asterisk-commits mailing list