[asterisk-commits] dvossel: branch dvossel/sip_string_parse_testing r244060 - in /team/dvossel/s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jan 30 12:25:41 CST 2010


Author: dvossel
Date: Sat Jan 30 12:25:36 2010
New Revision: 244060

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=244060
Log:
additional updates to parse_uri unit test

Removes the option parameter to parse_uri as
it is not set correctly and is never used within
chan_sip.

Modified:
    team/dvossel/sip_string_parse_testing/channels/chan_sip.c
    team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c
    team/dvossel/sip_string_parse_testing/channels/sip/sip.h

Modified: team/dvossel/sip_string_parse_testing/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_string_parse_testing/channels/chan_sip.c?view=diff&rev=244060&r1=244059&r2=244060
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/chan_sip.c (original)
+++ team/dvossel/sip_string_parse_testing/channels/chan_sip.c Sat Jan 30 12:25:36 2010
@@ -11109,7 +11109,7 @@
 	 * 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 (parse_uri(contact, "sip:,sips:", &contact, NULL, &host, &pt, &transport)) {
 		ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
 	}
 
@@ -11231,7 +11231,7 @@
 	ast_string_field_build(pvt, our_contact, "<%s>", curi);
 
 	/* Make sure it's a SIP URL */
-	if (parse_uri(curi, "sip:,sips:", &curi, NULL, &host, &pt, NULL, &transport)) {
+	if (parse_uri(curi, "sip:,sips:", &curi, NULL, &host, &pt, &transport)) {
 		ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
 	}
 
@@ -11890,7 +11890,7 @@
 	c = get_in_brackets(tmp);
 	c = remove_uri_parameters(c);
 
-	if (parse_uri(c, "sip:,sips:", &name, NULL, &domain, NULL, NULL, NULL)) {
+	if (parse_uri(c, "sip:,sips:", &name, NULL, &domain, NULL, 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));
 		return -1;
 	}
@@ -12398,7 +12398,7 @@
 	
 	uri = get_in_brackets(tmp);
 
-	if (parse_uri(uri, "sip:,sips:", &uri, NULL, &domain, NULL, NULL, NULL)) {
+	if (parse_uri(uri, "sip:,sips:", &uri, NULL, &domain, NULL, NULL)) {
 		ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", uri);
 		return -1;
 	}
@@ -12415,7 +12415,7 @@
 	ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf));
 	if (!ast_strlen_zero(tmpf)) {
 		from = get_in_brackets(tmpf);
-		if (parse_uri(from, "sip:,sips:", &from, NULL, &domain, NULL, NULL, NULL)) {
+		if (parse_uri(from, "sip:,sips:", &from, NULL, &domain, NULL, NULL)) {
 			ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", from);
 			return -1;
 		}
@@ -12766,7 +12766,7 @@
 	ast_copy_string(tmp, get_header(req, "Also"), sizeof(tmp));
 	c = get_in_brackets(tmp);
 
-	if (parse_uri(c, "sip:,sips:", &c, NULL, &a, NULL, NULL, NULL)) {
+	if (parse_uri(c, "sip:,sips:", &c, NULL, &a, NULL, NULL)) {
 		ast_log(LOG_WARNING, "Huh?  Not a SIP header in Also: transfer (%s)?\n", c);
 		return -1;
 	}
@@ -13302,7 +13302,7 @@
 	ast_string_field_set(p, from, of);
 
 	/* ignore all fields but name */
-	if (parse_uri(of, "sip:,sips:", &of, &dummy, &domain, &dummy, &dummy, NULL)) {
+	if (parse_uri(of, "sip:,sips:", &of, &dummy, &domain, &dummy, NULL)) {
 		ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
 	}
 

Modified: team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c?view=diff&rev=244060&r1=244059&r2=244060
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c (original)
+++ team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c Sat Jan 30 12:25:36 2010
@@ -25,29 +25,22 @@
 
 #include "sip.h"
 
-/*! \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.
- * - 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.
- * It is safe to call with ret_name, pass, domain, port
- * pointing all to the same place.
- * Init pointers to empty string so we never get NULL dereferencing.
- * Overwrites the string.
- * return 0 on success, other values on error.
- * \verbatim
- * general form we are expecting is sip[s]:username[:password][;parameter]@host[:port][;...]
- * \endverbatim
- *
- */
-int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass, char **domain, char **port, char **options, char **transport)
+/*! \brief * parses a URI in its components.*/
+int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass, char **domain, char **port, char **transport)
 {
 	char *name = NULL;
+	char *tmp; /* used as temporary place holder */
 	int error = 0;
+
+	/* check for valid input */
+	if (ast_strlen_zero(uri)) {
+		return -1;
+	}
+
+	/* strip [?headers] from end of uri */
+	if ((tmp = strrchr(uri, '?'))) {
+		*tmp = '\0';
+	}
 
 	/* init field as required */
 	if (pass)
@@ -101,7 +94,7 @@
 			name = uri;
 		}
 
-		/* Remove options in domain and name */
+		/* Remove parameters in domain and name */
 		dom = strsep(&dom, ";");
 		name = strsep(&name, ";");
 
@@ -117,8 +110,6 @@
 	}
 	if (ret_name)	/* same as for domain, store the result only at the end */
 		*ret_name = name;
-	if (options)
-		*options = uri ? uri : "";
 
 	return error;
 }
@@ -126,11 +117,11 @@
 AST_TEST_DEFINE(sip_parse_uri_test)
 {
 	int res = AST_TEST_PASS;
-	char *name, *pass, *domain, *port, *options, *transport;
-	char uri1[] = "sip:name at domain";
-	char uri2[] = "sip:name at domain;transport=tcp";
-	char uri3[] = "sip:name:secret at domain;transport=tcp";
-
+	char *name, *pass, *domain, *port, *transport;
+	char uri1[] = "sip:name at host";
+	char uri2[] = "sip:name at host;transport=tcp";
+	char uri3[] = "sip:name:secret at host;transport=tcp";
+	char uri4[] = "sip:name:secret at host:port;transport=tcp?headers";
 	switch (cmd) {
 	case TEST_INIT:
 		info->name = "sip_uri_parse_test";
@@ -145,26 +136,25 @@
 	}
 
 	/* Test 1, simple URI */
-	name = pass = domain = port = options = transport = NULL;
-	if (parse_uri(uri1, "sip:,sips:", &name, &pass, &domain, &port, &options, &transport) ||
+	name = pass = domain = port = transport = NULL;
+	if (parse_uri(uri1, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
 		strcmp(name, "name")        ||
 		!ast_strlen_zero(pass)      ||
-		strcmp(domain, "domain")    ||
-		!ast_strlen_zero(options)   ||
+		strcmp(domain, "host")      ||
+		!ast_strlen_zero(port)      ||
 		!ast_strlen_zero(transport)) {
-//TODO options and name are the same value right now.  how is this correct?!
-		ast_log(LOG_NOTICE, "name %s domain %s  pass %s port %s options %s transport %s\n",name, domain, pass, port, options, transport);
+
 		ast_str_append(&args->ast_test_error_str, 0, "Test 1: simple uri failed. \n");
 		res = AST_TEST_FAIL;
 	}
 
 	/* Test 2, add tcp transport */
-	name = pass = domain = port = options = transport = NULL;
-	if (parse_uri(uri2, "sip:,sips:", &name, &pass, &domain, &port, &options, &transport) ||
+	name = pass = domain = port = transport = NULL;
+	if (parse_uri(uri2, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
 		strcmp(name, "name")        ||
 		!ast_strlen_zero(pass)      ||
-		strcmp(domain, "domain")    ||
-		!ast_strlen_zero(options)   ||
+		strcmp(domain, "host")    ||
+		!ast_strlen_zero(port)      ||
 		strcmp(transport, "tcp")) {
 
 		ast_str_append(&args->ast_test_error_str, 0, "Test 2: uri with addtion of tcp transport failed. \n");
@@ -172,18 +162,31 @@
 	}
 
 	/* Test 3, add secret */
-	name = pass = domain = port = options = transport = NULL;
-	if (parse_uri(uri3, "sip:,sips:", &name, &pass, &domain, &port, &options, &transport) ||
+	name = pass = domain = port = transport = NULL;
+	if (parse_uri(uri3, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
 	    strcmp(name, "name")        ||
 		strcmp(pass, "secret")      ||
-		strcmp(domain, "domain")    ||
-		!ast_strlen_zero(options)   ||
+		strcmp(domain, "host")    ||
+		!ast_strlen_zero(port)      ||
 		strcmp(transport, "tcp")) {
 
 		ast_str_append(&args->ast_test_error_str, 0, "Test 3: uri with addition of secret failed.\n");
 		res = AST_TEST_FAIL;
 	}
 
+	/* Test 4, add port and unparsed header field*/
+	name = pass = domain = port = transport = NULL;
+	if (parse_uri(uri4, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
+	    strcmp(name, "name")        ||
+		strcmp(pass, "secret")      ||
+		strcmp(domain, "host")    ||
+		strcmp(port, "port")      ||
+		strcmp(transport, "tcp")) {
+
+		ast_str_append(&args->ast_test_error_str, 0, "Test 4: add port and unparsed header field failed.\n");
+		res = AST_TEST_FAIL;
+	}
+
 	return res;
 }
 

Modified: team/dvossel/sip_string_parse_testing/channels/sip/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_string_parse_testing/channels/sip/sip.h?view=diff&rev=244060&r1=244059&r2=244060
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/sip/sip.h (original)
+++ team/dvossel/sip_string_parse_testing/channels/sip/sip.h Sat Jan 30 12:25:36 2010
@@ -1298,26 +1298,25 @@
 
 /* ------------------- request-parser.c ------------------- */
 
-/*! \brief * parses a URI in its components.
+/*! \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.
  * - 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.
- * It is safe to call with ret_name, pass, domain, port
- * pointing all to the same place.
- * Init pointers to empty string so we never get NULL dereferencing.
- * Overwrites the string.
- * return 0 on success, other values on error.
+ * - 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 pointing all to
+ *   the same place.
+ * - This function overwrites the the uri string.
+ * 
+ * \retval 0 on success
+ * \retval -1 on error.
+ *
  * \verbatim
- * general form we are expecting is sip[s]:username[:password][;parameter]@host[:port][;...]
+ * general form we are expecting is sip:user:password;user-parameters at host:port;uri-parameters?headers
  * \endverbatim
  *
  */
-int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass, char **domain, char **port, char **options, char **transport);
+int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass, char **domain, char **port, char **transport);
 
 /*! \brief register request parsing tests */
 void sip_request_parser_register_tests(void);




More information about the asterisk-commits mailing list