[asterisk-commits] dvossel: branch dvossel/sip_string_parse_testing r244062 - in /team/dvossel/s...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jan 30 13:12:54 CST 2010
Author: dvossel
Date: Sat Jan 30 13:12:50 2010
New Revision: 244062
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=244062
Log:
addition of the sip_parse_host unit test
Modified:
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/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_string_parse_testing/channels/chan_sip.c?view=diff&rev=244062&r1=244061&r2=244062
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/chan_sip.c (original)
+++ team/dvossel/sip_string_parse_testing/channels/chan_sip.c Sat Jan 30 13:12:50 2010
@@ -992,7 +992,6 @@
static int handle_request_do(struct sip_request *req, struct sockaddr_in *sin);
static int sip_standard_port(enum sip_transport type, int port);
static int sip_prepare_socket(struct sip_pvt *p);
-static int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport);
/*--- Transmitting responses and requests */
static int sipsock_read(int *id, int fd, short events, void *ignore);
@@ -21571,55 +21570,6 @@
}
return -1;
-}
-
-/*!
- * \brief Small function to parse a config line for a host with a transport
- * i.e. tls://www.google.com:8056
- */
-static int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport)
-{
- char *port;
-
- if ((*hostname = strstr(line, "://"))) {
- *hostname += 3;
-
- if (!strncasecmp(line, "tcp", 3))
- *transport = SIP_TRANSPORT_TCP;
- else if (!strncasecmp(line, "tls", 3))
- *transport = SIP_TRANSPORT_TLS;
- else if (!strncasecmp(line, "udp", 3))
- *transport = SIP_TRANSPORT_UDP;
- else
- ast_log(LOG_NOTICE, "'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", line, lineno);
- } else {
- *hostname = line;
- *transport = SIP_TRANSPORT_UDP;
- }
-
- if ((line = strrchr(*hostname, '@')))
- line++;
- else
- line = *hostname;
-
- if ((port = strrchr(line, ':'))) {
- *port++ = '\0';
-
- if (!sscanf(port, "%5u", portnum)) {
- ast_log(LOG_NOTICE, "'%s' is not a valid port number on line %d of sip.conf. using default.\n", port, lineno);
- port = NULL;
- }
- }
-
- if (!port) {
- if (*transport & SIP_TRANSPORT_TLS) {
- *portnum = STANDARD_TLS_PORT;
- } else {
- *portnum = STANDARD_SIP_PORT;
- }
- }
-
- return 0;
}
/*!
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=244062&r1=244061&r2=244062
==============================================================================
--- 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 13:12:50 2010
@@ -459,15 +459,139 @@
return res;
}
+int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport)
+{
+ char *port;
+
+ if ((*hostname = strstr(line, "://"))) {
+ *hostname += 3;
+
+ if (!strncasecmp(line, "tcp", 3))
+ *transport = SIP_TRANSPORT_TCP;
+ else if (!strncasecmp(line, "tls", 3))
+ *transport = SIP_TRANSPORT_TLS;
+ else if (!strncasecmp(line, "udp", 3))
+ *transport = SIP_TRANSPORT_UDP;
+ else
+ ast_log(LOG_NOTICE, "'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", line, lineno);
+ } else {
+ *hostname = line;
+ *transport = SIP_TRANSPORT_UDP;
+ }
+
+ if ((line = strrchr(*hostname, '@')))
+ line++;
+ else
+ line = *hostname;
+
+ if ((port = strrchr(line, ':'))) {
+ *port++ = '\0';
+
+ if (!sscanf(port, "%5u", portnum)) {
+ ast_log(LOG_NOTICE, "'%s' is not a valid port number on line %d of sip.conf. using default.\n", port, lineno);
+ port = NULL;
+ }
+ }
+
+ if (!port) {
+ if (*transport & SIP_TRANSPORT_TLS) {
+ *portnum = STANDARD_TLS_PORT;
+ } else {
+ *portnum = STANDARD_SIP_PORT;
+ }
+ }
+
+ return 0;
+}
+
+AST_TEST_DEFINE(sip_parse_host_line_test)
+{
+ int res = AST_TEST_PASS;
+ char *host;
+ int port;
+ enum sip_transport transport;
+ char host1[] = "www.blah.com";
+ char host2[] = "tcp://www.blah.com";
+ char host3[] = "tls://10.10.10.10";
+ char host4[] = "tls://10.10.10.10:1234";
+ char host5[] = "10.10.10.10:1234";
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "sip_parse_host_line_test";
+ info->category = "channels/chan_sip/";
+ info->summary = "tests sip.conf host line parsing";
+ info->description =
+ " Tests parsing of various host line configurations."
+ " Verifies output matches expected behavior.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ /* test 1, simple host */
+ sip_parse_host(host1, 1, &host, &port, &transport);
+ if (port != STANDARD_SIP_PORT ||
+ ast_strlen_zero(host) || strcmp(host, "www.blah.com") ||
+ transport != SIP_TRANSPORT_UDP) {
+
+ ast_str_append(&args->ast_test_error_str, 0, "Test 1: simple host failed.\n");
+ res = AST_TEST_FAIL;
+ }
+
+ /* test 2, add tcp transport */
+ sip_parse_host(host2, 1, &host, &port, &transport);
+ if (port != STANDARD_SIP_PORT ||
+ ast_strlen_zero(host) || strcmp(host, "www.blah.com") ||
+ transport != SIP_TRANSPORT_TCP) {
+
+ ast_str_append(&args->ast_test_error_str, 0, "Test 2: tcp host failed.\n");
+ res = AST_TEST_FAIL;
+ }
+
+ /* test 3, add tls transport */
+ sip_parse_host(host3, 1, &host, &port, &transport);
+ if (port != STANDARD_TLS_PORT ||
+ ast_strlen_zero(host) || strcmp(host, "10.10.10.10") ||
+ transport != SIP_TRANSPORT_TLS) {
+
+ ast_str_append(&args->ast_test_error_str, 0, "Test 3: tls host failed. \n");
+ res = AST_TEST_FAIL;
+ }
+
+ /* test 4, add custom port with tls */
+ sip_parse_host(host4, 1, &host, &port, &transport);
+ if (port != 1234 ||
+ ast_strlen_zero(host) || strcmp(host, "10.10.10.10") ||
+ transport != SIP_TRANSPORT_TLS) {
+
+ ast_str_append(&args->ast_test_error_str, 0, "Test 4: tls host with custom port failed.\n");
+ res = AST_TEST_FAIL;
+ }
+
+ /* test 5, simple host with custom port */
+ sip_parse_host(host5, 1, &host, &port, &transport);
+ if (port != 1234 ||
+ ast_strlen_zero(host) || strcmp(host, "10.10.10.10") ||
+ transport != SIP_TRANSPORT_UDP) {
+
+ ast_str_append(&args->ast_test_error_str, 0, "Test 5: simple host with custom port failed.\n");
+ res = AST_TEST_FAIL;
+ }
+ return res;
+}
+
/*! \brief SIP test registration */
void sip_config_parser_register_tests(void)
{
AST_TEST_REGISTER(sip_parse_register_line_test);
+ AST_TEST_REGISTER(sip_parse_host_line_test);
}
/*! \brief SIP test registration */
void sip_config_parser_unregister_tests(void)
{
AST_TEST_UNREGISTER(sip_parse_register_line_test);
+ AST_TEST_UNREGISTER(sip_parse_host_line_test);
}
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=244062&r1=244061&r2=244062
==============================================================================
--- team/dvossel/sip_string_parse_testing/channels/sip/sip.h (original)
+++ team/dvossel/sip_string_parse_testing/channels/sip/sip.h Sat Jan 30 13:12:50 2010
@@ -1290,6 +1290,12 @@
*/
int sip_parse_register_line(struct sip_registry *reg, const char *value, int lineno);
+/*!
+ * \brief Small function to parse a config line for a host with a transport
+ * i.e. tls://www.google.com:8056
+ */
+int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport);
+
/*! \brief register config parsing tests */
void sip_config_parser_register_tests(void);
More information about the asterisk-commits
mailing list