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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jan 30 00:43:34 CST 2010


Author: dvossel
Date: Sat Jan 30 00:43:30 2010
New Revision: 244057

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=244057
Log:
addition of sip/request-parser.c and beginning of parse_uri unit test

Added:
    team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c   (with props)
Modified:
    team/dvossel/sip_string_parse_testing/channels/Makefile
    team/dvossel/sip_string_parse_testing/channels/chan_sip.c
    team/dvossel/sip_string_parse_testing/channels/sip/config-parser.c
    team/dvossel/sip_string_parse_testing/channels/sip/sip.h

Modified: team/dvossel/sip_string_parse_testing/channels/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_string_parse_testing/channels/Makefile?view=diff&rev=244057&r1=244056&r2=244057
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/Makefile (original)
+++ team/dvossel/sip_string_parse_testing/channels/Makefile Sat Jan 30 00:43:30 2010
@@ -69,7 +69,7 @@
 	rm -f h323/Makefile
 
 $(if $(filter chan_iax2,$(EMBEDDED_MODS)),modules.link,chan_iax2.so): iax2-parser.o iax2-provision.o
-$(if $(filter chan_sip,$(EMBEDDED_MODS)),modules.link,chan_sip.so): sip/config-parser.o
+$(if $(filter chan_sip,$(EMBEDDED_MODS)),modules.link,chan_sip.so): sip/config-parser.o sip/request-parser.o
 $(if $(filter chan_dahdi,$(EMBEDDED_MODS)),modules.link,chan_dahdi.so): sig_analog.o sig_pri.o
 
 ifneq ($(filter chan_h323,$(EMBEDDED_MODS)),)

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=244057&r1=244056&r2=244057
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/chan_sip.c (original)
+++ team/dvossel/sip_string_parse_testing/channels/chan_sip.c Sat Jan 30 00:43:30 2010
@@ -1255,7 +1255,6 @@
 static void change_redirecting_information(struct sip_pvt *p, struct sip_request *req, struct ast_party_redirecting *redirecting, int set_call_forward);
 static int get_domain(const char *str, char *domain, int len);
 static void get_realm(struct sip_pvt *p, const struct sip_request *req);
-static int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass, char **domain, char **port, char **options, char **transport);
 
 /*-- TCP connection handling ---*/
 static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *tcptls_session);
@@ -3258,104 +3257,6 @@
 	}
 	
 	return tmp;
-}
-
-/*! \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
- *
- */
-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;
-	int error = 0;
-
-	/* init field as required */
-	if (pass)
-		*pass = "";
-	if (port)
-		*port = "";
-	if (scheme) {
-		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;
-		}
-	}
-	if (transport) {
-		char *t, *type = "";
-		*transport = "";
-		if ((t = strstr(uri, "transport="))) {
-			strsep(&t, "=");
-			if ((type = strsep(&t, ";"))) {
-				*transport = type;
-			}
-		}
-	}
-
-	if (!domain) {
-		/* if we don't want to split around domain, keep everything as a name,
-		 * so we need to do nothing here, except remember why.
-		 */
-	} else {
-		/* store the result in a temp. variable to avoid it being
-		 * overwritten if arguments point to the same place.
-		 */
-		char *c, *dom = "";
-
-		if ((c = strchr(uri, '@')) == NULL) {
-			/* domain-only URI, according to the SIP RFC. */
-			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;
-		}
-		if (pass && (c = strchr(name, ':'))) {	/* user:password */
-			*c++ = '\0';
-			*pass = c;
-		}
-		*domain = dom;
-	}
-	if (ret_name)	/* same as for domain, store the result only at the end */
-		*ret_name = name;
-	if (options)
-		*options = uri ? uri : "";
-
-	return error;
 }
 
 /*! \brief Send message with Access-URL header, if this is an HTML URL only! */

Modified: team/dvossel/sip_string_parse_testing/channels/sip/config-parser.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_string_parse_testing/channels/sip/config-parser.c?view=diff&rev=244057&r1=244056&r2=244057
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/sip/config-parser.c (original)
+++ team/dvossel/sip_string_parse_testing/channels/sip/config-parser.c Sat Jan 30 00:43:30 2010
@@ -16,7 +16,7 @@
 
 /*!
  * \file
- * \brief sip string parsing functions
+ * \brief sip config parsing functions and unit tests
  */
 
 #include "asterisk.h"

Added: 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=auto&rev=244057
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c (added)
+++ team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c Sat Jan 30 00:43:30 2010
@@ -1,0 +1,160 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief sip request parsing functions and unit tests
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#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)
+{
+	char *name = NULL;
+	int error = 0;
+
+	/* init field as required */
+	if (pass)
+		*pass = "";
+	if (port)
+		*port = "";
+	if (scheme) {
+		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;
+		}
+	}
+	if (transport) {
+		char *t, *type = "";
+		*transport = "";
+		if ((t = strstr(uri, "transport="))) {
+			strsep(&t, "=");
+			if ((type = strsep(&t, ";"))) {
+				*transport = type;
+			}
+		}
+	}
+
+	if (!domain) {
+		/* if we don't want to split around domain, keep everything as a name,
+		 * so we need to do nothing here, except remember why.
+		 */
+	} else {
+		/* store the result in a temp. variable to avoid it being
+		 * overwritten if arguments point to the same place.
+		 */
+		char *c, *dom = "";
+
+		if ((c = strchr(uri, '@')) == NULL) {
+			/* domain-only URI, according to the SIP RFC. */
+			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;
+		}
+		if (pass && (c = strchr(name, ':'))) {	/* user:password */
+			*c++ = '\0';
+			*pass = c;
+		}
+		*domain = dom;
+	}
+	if (ret_name)	/* same as for domain, store the result only at the end */
+		*ret_name = name;
+	if (options)
+		*options = uri ? uri : "";
+
+	return error;
+}
+
+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";
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "sip_uri_parse_test";
+		info->category = "channels/chan_sip/";
+		info->summary = "tests sip uri parsing";
+		info->description =
+							" Tests parsing of various URIs"
+							" Verifies output matches expected behavior.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	/* Test 1, simple URI */
+	name = pass = domain = port = options = transport = NULL;
+	if (parse_uri(uri1, "sip:sips:", &name, &pass, &domain, &port, &options, &transport) ||
+		ast_strlen_zero(name)      || strcmp(name, "name")        ||
+		ast_strlen_zero(pass)      || strcmp(pass, "")            ||
+		ast_strlen_zero(domain)    || strcmp(domain, "domain")    ||
+		ast_strlen_zero(options)   || strcmp(options, "")         ||
+		ast_strlen_zero(transport) || strcmp(transport, "")) {
+
+		ast_str_append(&args->ast_test_error_str, 0, "Test 1: simple uri failed. %s\n", uri1);
+		res = AST_TEST_FAIL;
+	}
+
+	return res;
+}
+

Propchange: team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/sip_string_parse_testing/channels/sip/request-parser.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=244057&r1=244056&r2=244057
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/sip/sip.h (original)
+++ team/dvossel/sip_string_parse_testing/channels/sip/sip.h Sat Jan 30 00:43:30 2010
@@ -1281,6 +1281,7 @@
 /*----------------------------------------------------------*/
 /*----              Function Prototypes                 ----*/
 /*----------------------------------------------------------*/
+/* ------------------ config-parser ----------------------- */
 
 /*! \brief Parse register=> line in sip.conf
  *
@@ -1288,6 +1289,37 @@
  *  \retval 1 on failure
  */
 int sip_parse_register_line(struct sip_registry *reg, const char *value, int lineno);
+
+/*! \brief registration parsing tests */
+void sip_config_register_tests(void);
+
+/*! \brief unregistration parsing tests */
+void sip_config_unregister_tests(void);
+
+/* ------------------- request-parser.c ------------------- */
+
+/*! \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);
+
+/* ------------------- shared sip utils ------------------- */
 
 /*! \brief converts ascii port to int representation. If no
  *  pt buffer is provided or the pt has errors when being converted
@@ -1295,9 +1327,5 @@
  */
 int port_str2int(const char *pt, unsigned int standard);
 
-/*! \brief registration parsing tests */
-void sip_config_register_tests(void);
-
-/*! \brief unregistration parsing tests */
-void sip_config_unregister_tests(void);
+
 #endif




More information about the asterisk-commits mailing list