]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Made ast_sockaddr_split_hostport() port warning msgs more meaningful.
authorRichard Mudgett <rmudgett@digium.com>
Tue, 14 Jun 2011 17:21:39 +0000 (17:21 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 14 Jun 2011 17:21:39 +0000 (17:21 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@323394 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/netsock2.c

index f57c8425ab163c63cafdfcd5e6c26b3f28739f13..b6c6d89d42649026b33553bf686f1d7f8b71e1a5 100644 (file)
@@ -121,8 +121,10 @@ char *ast_sockaddr_stringify_fmt(const struct ast_sockaddr *sa, int format)
 int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
 {
        char *s = str;
+       char *orig_str = str;/* Original string in case the port presence is incorrect. */
+       char *host_end = NULL;/* Delay terminating the host in case the port presence is incorrect. */
 
-       ast_debug(5, "Splitting '%s' gives...\n", str);
+       ast_debug(5, "Splitting '%s' into...\n", str);
        *host = NULL;
        *port = NULL;
        if (*s == '[') {
@@ -130,7 +132,8 @@ int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
                for (; *s && *s != ']'; ++s) {
                }
                if (*s == ']') {
-                       *s++ = '\0';
+                       host_end = s;
+                       ++s;
                }
                if (*s == ':') {
                        *port = s + 1;
@@ -148,11 +151,10 @@ int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
                        }
                }
                if (*port) {
-                       **port = '\0';
+                       host_end = *port;
                        ++*port;
                }
        }
-       ast_debug(5, "...host '%s' and port '%s'.\n", *host, *port);
 
        switch (flags & PARSE_PORT_MASK) {
        case PARSE_PORT_IGNORE:
@@ -160,18 +162,23 @@ int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
                break;
        case PARSE_PORT_REQUIRE:
                if (*port == NULL) {
-                       ast_log(LOG_WARNING, "missing port\n");
+                       ast_log(LOG_WARNING, "Port missing in %s\n", orig_str);
                        return 0;
                }
                break;
        case PARSE_PORT_FORBID:
                if (*port != NULL) {
-                       ast_log(LOG_WARNING, "port disallowed\n");
+                       ast_log(LOG_WARNING, "Port disallowed in %s\n", orig_str);
                        return 0;
                }
                break;
        }
 
+       /* Can terminate the host string now if needed. */
+       if (host_end) {
+               *host_end = '\0';
+       }
+       ast_debug(5, "...host '%s' and port '%s'.\n", *host, *port ? *port : "");
        return 1;
 }