Don't treat a host:port string as a domain
authorTerry Wilson <twilson@digium.com>
Wed, 9 Nov 2011 20:10:52 +0000 (20:10 +0000)
committerTerry Wilson <twilson@digium.com>
Wed, 9 Nov 2011 20:10:52 +0000 (20:10 +0000)
The domain matching code prior to 1.8 used to manually remove the port
from the host:port string when determining if an incoming request
matched the list of domains. When switching to the new parsing
functions, the documentation implied that the "domain" was being
returned by these functions, when instead it was returning the
"hostport" as defined by RFC 3261. This led to confusion and resulted
in 1.8+ rejecting an incoming request from x.x.x.x:xxxxx when
domain=x.x.x.x was set in sip.conf.

This patch renames the "domain" variables in the parsing functions to
"hostport" to more accurately describe what it is that they are
returning and also properly truncates the resulting hostport strings
when dealing with domain matching.

Review: https://reviewboard.asterisk.org/r/1574/
........

Merged revisions 344215 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 344216 from http://svn.asterisk.org/svn/asterisk/branches/10

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@344217 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
channels/sip/include/reqresp_parser.h
channels/sip/include/sip.h
channels/sip/reqresp_parser.c

index 17a8434..ef97d91 100644 (file)
@@ -13915,9 +13915,9 @@ static int parse_ok_contact(struct sip_pvt *pvt, struct sip_request *req)
 }
 
 /*! \brief parse uri in a way that allows semicolon stripping if legacy mode is enabled */
-static int parse_uri_legacy_check(char *uri, const char *scheme, char **user, char **pass, char **domain, char **transport)
+static int parse_uri_legacy_check(char *uri, const char *scheme, char **user, char **pass, char **hostport, char **transport)
 {
-       int ret = parse_uri(uri, scheme, user, pass, domain, transport);
+       int ret = parse_uri(uri, scheme, user, pass, hostport, transport);
        if (sip_cfg.legacy_useroption_parsing) { /* if legacy mode is active, strip semis from the user field */
                char *p;
                if ((p = strchr(uri, (int)';'))) {
@@ -13929,7 +13929,7 @@ static int parse_uri_legacy_check(char *uri, const char *scheme, char **user, ch
 
 static int __set_address_from_contact(const char *fullcontact, struct ast_sockaddr *addr, int tcp)
 {
-       char *domain, *transport;
+       char *hostport, *transport;
        char contact_buf[256];
        char *contact;
 
@@ -13944,7 +13944,7 @@ static int __set_address_from_contact(const char *fullcontact, struct ast_sockad
         * We still need to be able to send to the remote agent through the proxy.
         */
 
-       if (parse_uri_legacy_check(contact, "sip:,sips:", &contact, NULL, &domain,
+       if (parse_uri_legacy_check(contact, "sip:,sips:", &contact, NULL, &hostport,
                      &transport)) {
                ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
        }
@@ -13953,19 +13953,19 @@ static int __set_address_from_contact(const char *fullcontact, struct ast_sockad
        /* We should only do this if it's a name, not an IP */
        /* \todo - if there's no PORT number in contact - we are required to check NAPTR/SRV records
                to find transport, port address and hostname. If there's a port number, we have to
-               assume that the domain part is a host name and only look for an A/AAAA record in DNS.
+               assume that the hostport part is a host name and only look for an A/AAAA record in DNS.
        */
 
-       /* If we took in an invalid URI, domain may not have been initialized */
-       /* ast_sockaddr_resolve requires an initialized domain string. */
-       if (ast_strlen_zero(domain)) {
-               ast_log(LOG_WARNING, "Invalid URI: parse_uri failed to acquire domain\n");
+       /* If we took in an invalid URI, hostport may not have been initialized */
+       /* ast_sockaddr_resolve requires an initialized hostport string. */
+       if (ast_strlen_zero(hostport)) {
+               ast_log(LOG_WARNING, "Invalid URI: parse_uri failed to acquire hostport\n");
                return -1;
        }
 
-       if (ast_sockaddr_resolve_first(addr, domain, 0)) {
+       if (ast_sockaddr_resolve_first(addr, hostport, 0)) {
                ast_log(LOG_WARNING, "Invalid host name in Contact: (can't "
-                       "resolve in DNS) : '%s'\n", domain);
+                       "resolve in DNS) : '%s'\n", hostport);
                return -1;
        }
 
@@ -14002,7 +14002,7 @@ static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, st
        char data[SIPBUFSIZE];
        const char *expires = sip_get_header(req, "Expires");
        int expire = atoi(expires);
-       char *curi = NULL, *domain = NULL, *transport = NULL;
+       char *curi = NULL, *hostport = NULL, *transport = NULL;
        int transport_type;
        const char *useragent;
        struct ast_sockaddr oldsin, testsa;
@@ -14080,7 +14080,7 @@ static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, st
        ast_string_field_build(pvt, our_contact, "<%s>", curi);
 
        /* Make sure it's a SIP URL */
-       if (ast_strlen_zero(curi) || parse_uri_legacy_check(curi, "sip:,sips:", &curi, NULL, &domain, &transport)) {
+       if (ast_strlen_zero(curi) || parse_uri_legacy_check(curi, "sip:,sips:", &curi, NULL, &hostport, &transport)) {
                ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:/sips:) trying to use anyway\n");
        }
 
@@ -14108,15 +14108,15 @@ static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, st
                ast_debug(1, "Store REGISTER's Contact header for call routing.\n");
                /* XXX This could block for a long time XXX */
                /*! \todo Check NAPTR/SRV if we have not got a port in the URI */
-               if (ast_sockaddr_resolve_first(&testsa, domain, 0)) {
-                       ast_log(LOG_WARNING, "Invalid domain '%s'\n", domain);
+               if (ast_sockaddr_resolve_first(&testsa, hostport, 0)) {
+                       ast_log(LOG_WARNING, "Invalid hostport '%s'\n", hostport);
                        ast_string_field_set(peer, fullcontact, "");
                        ast_string_field_set(pvt, our_contact, "");
                        return PARSE_REGISTER_FAILED;
                }
 
                /* If we have a port number in the given URI, make sure we do remember to not check for NAPTR/SRV records.
-                  The domain part is actually a host. */
+                  The hostport part is actually a host. */
                peer->portinuri = ast_sockaddr_port(&testsa) ? TRUE : FALSE;
 
                if (!ast_sockaddr_port(&testsa)) {
@@ -14136,7 +14136,7 @@ static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, st
        /* Check that they're allowed to register at this IP */
        if (ast_apply_ha(sip_cfg.contact_ha, &peer->addr) != AST_SENSE_ALLOW ||
                        ast_apply_ha(peer->contactha, &peer->addr) != AST_SENSE_ALLOW) {
-               ast_log(LOG_WARNING, "Domain '%s' disallowed by contact ACL (violating IP %s)\n", domain,
+               ast_log(LOG_WARNING, "Domain '%s' disallowed by contact ACL (violating IP %s)\n", hostport,
                        ast_sockaddr_stringify_addr(&testsa));
                ast_string_field_set(peer, fullcontact, "");
                ast_string_field_set(pvt, our_contact, "");
@@ -14758,6 +14758,18 @@ static char *terminate_uri(char *uri)
        return uri;
 }
 
+/*! \brief Terminate a host:port at the ':'
+ * \param hostport The address of the hostport string
+ *
+ * \note In the case of a bracket-enclosed IPv6 address, the hostport variable
+ * will contain the non-bracketed host as a result of calling this function.
+ */
+static void extract_host_from_hostport(char **hostport)
+{
+       char *dont_care;
+       ast_sockaddr_split_hostport(*hostport, hostport, &dont_care, PARSE_PORT_IGNORE);
+}
+
 /*! \brief Verify registration of user
        - Registration is done in several steps, first a REGISTER without auth
          to get a challenge (nonce) then a second one with auth
@@ -14787,6 +14799,8 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct ast_sock
        SIP_PEDANTIC_DECODE(name);
        SIP_PEDANTIC_DECODE(domain);
 
+       extract_host_from_hostport(&domain);
+
        /*! \todo XXX here too we interpret a missing @domain as a name-only
         * URI, whereas the RFC says this is a domain-only uri.
         */
@@ -15351,6 +15365,9 @@ static enum sip_get_dest_result get_destination(struct sip_pvt *p, struct sip_re
 
        SIP_PEDANTIC_DECODE(domain);
        SIP_PEDANTIC_DECODE(uri);
+
+       extract_host_from_hostport(&domain);
+
        if (ast_strlen_zero(uri)) {
                /*
                 * Either there really was no extension found or the request
@@ -15377,6 +15394,8 @@ static enum sip_get_dest_result get_destination(struct sip_pvt *p, struct sip_re
                SIP_PEDANTIC_DECODE(from);
                SIP_PEDANTIC_DECODE(domain);
 
+               extract_host_from_hostport(&domain);
+
                ast_string_field_set(p, fromdomain, domain);
        }
 
@@ -16178,6 +16197,8 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
                 * For backward compatibility, we keep this block, but it is
                 * really a mistake and should go away.
                 */
+
+               extract_host_from_hostport(&domain);
                of = domain;
        } else {
                char *tmp = ast_strdupa(of);
@@ -24227,6 +24248,9 @@ static int sip_msg_send(const struct ast_msg *msg, const char *to, const char *f
                        ast_string_field_set(pvt, fromname, name);
                        if (strchr(location, ':')) { /* Must be a URI */
                                parse_uri(location, "sip:,sips:", &user, NULL, &domain, NULL);
+                               SIP_PEDANTIC_DECODE(user);
+                               SIP_PEDANTIC_DECODE(domain);
+                               extract_host_from_hostport(&domain);
                                ast_string_field_set(pvt, fromuser, user);
                                ast_string_field_set(pvt, fromdomain, domain);
                        } else { /* Treat it as an exten/user */
@@ -27234,8 +27258,9 @@ static int check_sip_domain(const char *domain, char *context, size_t len)
 
        AST_LIST_LOCK(&domain_list);
        AST_LIST_TRAVERSE(&domain_list, d, list) {
-               if (strcasecmp(d->domain, domain))
+               if (strcasecmp(d->domain, domain)) {
                        continue;
+               }
 
                if (len && !ast_strlen_zero(d->context))
                        ast_copy_string(context, d->context, len);
index bb18314..f0ab86e 100644 (file)
@@ -43,7 +43,7 @@
  * \endverbatim
  */
 int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass,
-             char **domain, char **transport);
+             char **hostport, char **transport);
 
 /*!
  * \brief parses a URI in to all of its components and any trailing residue
@@ -53,7 +53,7 @@ int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass,
  *
  */
 int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
-                  char **domain, struct uriparams *params, char **headers,
+                  char **hostport, struct uriparams *params, char **headers,
                   char **residue);
 
 /*!
index 0a776ad..c3c7a98 100644 (file)
@@ -1761,7 +1761,7 @@ struct contact {
        char *name;
        char *user;
        char *pass;
-       char *domain;
+       char *hostport;
        struct uriparams params;
        char *headers;
        char *expires;
index 37d77d4..ecce4bd 100644 (file)
@@ -33,7 +33,7 @@ locale_t c_locale;
 
 /*! \brief * parses a URI in its components.*/
 int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
-                  char **domain, struct uriparams *params, char **headers,
+                  char **hostport, struct uriparams *params, char **headers,
                   char **residue)
 {
        char *userinfo = NULL;
@@ -53,8 +53,8 @@ int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
        if (pass) {
                *pass = "";
        }
-       if (domain) {
-               *domain = "";
+       if (hostport) {
+               *hostport = "";
        }
        if (headers) {
                *headers = "";
@@ -85,8 +85,8 @@ int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
                }
        }
 
-       if (!domain) {
-               /* if we don't want to split around domain, keep everything as a
+       if (!hostport) {
+               /* if we don't want to split around hostport, keep everything as a
                 * userinfo - cos thats how old parse_uri operated*/
                userinfo = uri;
        } else {
@@ -102,7 +102,7 @@ int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
                        userinfo = "";
                }
 
-               *domain = dom;
+               *hostport = dom;
        }
 
        if (pass && (c = strchr(userinfo, ':'))) {        /* user:password */
@@ -221,7 +221,7 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
 {
        int res = AST_TEST_PASS;
        char uri[1024];
-       char *user, *pass, *domain, *headers, *residue;
+       char *user, *pass, *hostport, *headers, *residue;
        struct uriparams params;
 
        struct testdata {
@@ -229,13 +229,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                char *uri;
                char **userptr;
                char **passptr;
-               char **domainptr;
+               char **hostportptr;
                char **headersptr;
                char **residueptr;
                struct uriparams *paramsptr;
                char *user;
                char *pass;
-               char *domain;
+               char *hostport;
                char *headers;
                char *residue;
                struct uriparams params;
@@ -252,13 +252,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@host:5060;param=discard;transport=tcp;param2=residue",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "",
                .residue = "param2=residue",
                .params.transport = "tcp",
@@ -271,13 +271,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@host:5060;param=discard;transport=tcp;param2=discard2?header=blah&header2=blah2;param3=residue",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "header=blah&header2=blah2",
                .residue = "param3=residue",
                .params.transport = "tcp",
@@ -290,13 +290,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:-_.!~*'()&=+$,;?/:secret@host:5060;transport=tcp",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "-_.!~*'()&=+$,;?/",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "",
                .residue = "",
                .params.transport = "tcp",
@@ -309,13 +309,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:-_.!~*'()&=+$,@host:5060;transport=tcp",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "-_.!~*'()&=+$,",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "",
                .residue = "",
                .params.transport = "tcp",
@@ -328,13 +328,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@1-1.a-1.:5060;transport=tcp",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "1-1.a-1.:5060",
+               .hostport = "1-1.a-1.:5060",
                .headers = "",
                .residue = "",
                .params.transport = "tcp",
@@ -347,13 +347,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@host:5060;-_.!~*'()[]/:&+$=-_.!~*'()[]/:&+$;transport=tcp",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "",
                .residue = "",
                .params.transport = "tcp",
@@ -366,13 +366,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@host:5060;-_.!~*'()[]/:&+$=-_.!~*'()[]/:&+$?header=blah&header2=blah2;-_.!~*'()[]/:&+$=residue",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "header=blah&header2=blah2",
                .residue = "-_.!~*'()[]/:&+$=residue",
                .params.transport = "",
@@ -385,13 +385,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@host:5060;param=discard;lr?header=blah",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "header=blah",
                .residue = "",
                .params.transport = "",
@@ -404,13 +404,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@host:5060;param=discard;lr=yes?header=blah",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "header=blah",
                .residue = "",
                .params.transport = "",
@@ -423,13 +423,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
                .uri = "sip:user:secret@host:5060;paramlr=lr;lr=no;lr=off;lr=0;lr=;=lr;lrextra;lrparam2=lr?header=blah",
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "header=blah",
                .residue = "",
                .params.transport = "",
@@ -464,19 +464,19 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
        }
 
        AST_LIST_TRAVERSE(&testdatalist, testdataptr, list) {
-               user = pass = domain = headers = residue = NULL;
+               user = pass = hostport = headers = residue = NULL;
                params.transport = params.user = params.method = params.ttl = params.maddr = NULL;
                params.lr = 0;
 
                ast_copy_string(uri,testdataptr->uri,sizeof(uri));
                if (parse_uri_full(uri, "sip:,sips:", testdataptr->userptr,
-                                  testdataptr->passptr, testdataptr->domainptr,
+                                  testdataptr->passptr, testdataptr->hostportptr,
                                   testdataptr->paramsptr,
                                   testdataptr->headersptr,
                                   testdataptr->residueptr) ||
                        ((testdataptr->userptr) && strcmp(testdataptr->user, user)) ||
                        ((testdataptr->passptr) && strcmp(testdataptr->pass, pass)) ||
-                       ((testdataptr->domainptr) && strcmp(testdataptr->domain, domain)) ||
+                       ((testdataptr->hostportptr) && strcmp(testdataptr->hostport, hostport)) ||
                        ((testdataptr->headersptr) && strcmp(testdataptr->headers, headers)) ||
                        ((testdataptr->residueptr) && strcmp(testdataptr->residue, residue)) ||
                        ((testdataptr->paramsptr) && strcmp(testdataptr->params.transport,params.transport)) ||
@@ -494,13 +494,13 @@ AST_TEST_DEFINE(sip_parse_uri_fully_test)
 
 
 int parse_uri(char *uri, const char *scheme, char **user, char **pass,
-             char **domain, char **transport) {
+             char **hostport, char **transport) {
        int ret;
        char *headers;
        struct uriparams params;
 
        headers = NULL;
-       ret = parse_uri_full(uri, scheme, user, pass, domain, &params, &headers, NULL);
+       ret = parse_uri_full(uri, scheme, user, pass, hostport, &params, &headers, NULL);
        if (transport) {
                *transport=params.transport;
        }
@@ -510,7 +510,7 @@ int parse_uri(char *uri, const char *scheme, char **user, char **pass,
 AST_TEST_DEFINE(sip_parse_uri_test)
 {
        int res = AST_TEST_PASS;
-       char *name, *pass, *domain, *transport;
+       char *name, *pass, *hostport, *transport;
        char uri1[] = "sip:name@host";
        char uri2[] = "sip:name@host;transport=tcp";
        char uri3[] = "sip:name:secret@host;transport=tcp";
@@ -537,114 +537,114 @@ AST_TEST_DEFINE(sip_parse_uri_test)
        }
 
        /* Test 1, simple URI */
-       name = pass = domain = transport = NULL;
-       if (parse_uri(uri1, "sip:,sips:", &name, &pass, &domain, &transport) ||
+       name = pass = hostport = transport = NULL;
+       if (parse_uri(uri1, "sip:,sips:", &name, &pass, &hostport, &transport) ||
                        strcmp(name, "name")        ||
                        !ast_strlen_zero(pass)      ||
-                       strcmp(domain, "host")      ||
+                       strcmp(hostport, "host")      ||
                        !ast_strlen_zero(transport)) {
                ast_test_status_update(test, "Test 1: simple uri failed. \n");
                res = AST_TEST_FAIL;
        }
 
        /* Test 2, add tcp transport */
-       name = pass = domain = transport = NULL;
-       if (parse_uri(uri2, "sip:,sips:", &name, &pass, &domain, &transport) ||
+       name = pass = hostport = transport = NULL;
+       if (parse_uri(uri2, "sip:,sips:", &name, &pass, &hostport, &transport) ||
                        strcmp(name, "name")        ||
                        !ast_strlen_zero(pass)      ||
-                       strcmp(domain, "host")    ||
+                       strcmp(hostport, "host")    ||
                        strcmp(transport, "tcp")) {
                ast_test_status_update(test, "Test 2: uri with addtion of tcp transport failed. \n");
                res = AST_TEST_FAIL;
        }
 
        /* Test 3, add secret */
-       name = pass = domain = transport = NULL;
-       if (parse_uri(uri3, "sip:,sips:", &name, &pass, &domain, &transport) ||
+       name = pass = hostport = transport = NULL;
+       if (parse_uri(uri3, "sip:,sips:", &name, &pass, &hostport, &transport) ||
                        strcmp(name, "name")        ||
                        strcmp(pass, "secret")      ||
-                       strcmp(domain, "host")    ||
+                       strcmp(hostport, "host")    ||
                        strcmp(transport, "tcp")) {
                ast_test_status_update(test, "Test 3: uri with addition of secret failed.\n");
                res = AST_TEST_FAIL;
        }
 
        /* Test 4, add port and unparsed header field*/
-       name = pass = domain = transport = NULL;
-       if (parse_uri(uri4, "sip:,sips:", &name, &pass, &domain, &transport) ||
+       name = pass = hostport = transport = NULL;
+       if (parse_uri(uri4, "sip:,sips:", &name, &pass, &hostport, &transport) ||
                        strcmp(name, "name")        ||
                        strcmp(pass, "secret")      ||
-                       strcmp(domain, "host:port") ||
+                       strcmp(hostport, "host:port") ||
                        strcmp(transport, "tcp")) {
                ast_test_status_update(test, "Test 4: add port and unparsed header field failed.\n");
                res = AST_TEST_FAIL;
        }
 
        /* Test 5, verify parse_uri does not crash when given a NULL uri */
-       name = pass = domain = transport = NULL;
-       if (!parse_uri(NULL, "sip:,sips:", &name, &pass, &domain, &transport)) {
+       name = pass = hostport = transport = NULL;
+       if (!parse_uri(NULL, "sip:,sips:", &name, &pass, &hostport, &transport)) {
                ast_test_status_update(test, "Test 5: passing a NULL uri failed.\n");
                res = AST_TEST_FAIL;
        }
 
        /* Test 6, verify parse_uri does not crash when given a NULL output parameters */
-       name = pass = domain = transport = NULL;
+       name = pass = hostport = transport = NULL;
        if (parse_uri(uri6, "sip:,sips:", NULL, NULL, NULL, NULL)) {
                ast_test_status_update(test, "Test 6: passing NULL output parameters failed.\n");
                res = AST_TEST_FAIL;
        }
 
-       /* Test 7, verify parse_uri returns user:secret and domain when no port or secret output parameters are supplied. */
-       name = pass = domain = transport = NULL;
-       if (parse_uri(uri7, "sip:,sips:", &name, NULL, &domain, NULL) ||
+       /* Test 7, verify parse_uri returns user:secret and hostport when no port or secret output parameters are supplied. */
+       name = pass = hostport = transport = NULL;
+       if (parse_uri(uri7, "sip:,sips:", &name, NULL, &hostport, NULL) ||
                        strcmp(name, "name:secret")        ||
-                       strcmp(domain, "host:port")) {
+                       strcmp(hostport, "host:port")) {
 
                ast_test_status_update(test, "Test 7: providing no port and secret output parameters failed.\n");
                res = AST_TEST_FAIL;
        }
 
-       /* Test 8, verify parse_uri can handle a domain only uri */
-       name = pass = domain = transport = NULL;
-       if (parse_uri(uri8, "sip:,sips:", &name, &pass, &domain, &transport) ||
-                       strcmp(domain, "host") ||
+       /* Test 8, verify parse_uri can handle a hostport only uri */
+       name = pass = hostport = transport = NULL;
+       if (parse_uri(uri8, "sip:,sips:", &name, &pass, &hostport, &transport) ||
+                       strcmp(hostport, "host") ||
                        !ast_strlen_zero(name)) {
                ast_test_status_update(test, "Test 8: add port and unparsed header field failed.\n");
                res = AST_TEST_FAIL;
        }
 
-       /* Test 9, add port and unparsed header field with domain only uri*/
-       name = pass = domain = transport = NULL;
-       if (parse_uri(uri9, "sip:,sips:", &name, &pass, &domain, &transport) ||
+       /* Test 9, add port and unparsed header field with hostport only uri*/
+       name = pass = hostport = transport = NULL;
+       if (parse_uri(uri9, "sip:,sips:", &name, &pass, &hostport, &transport) ||
                        !ast_strlen_zero(name)        ||
                        !ast_strlen_zero(pass)      ||
-                       strcmp(domain, "host:port")    ||
+                       strcmp(hostport, "host:port")    ||
                        strcmp(transport, "tcp")) {
-               ast_test_status_update(test, "Test 9: domain only uri failed \n");
+               ast_test_status_update(test, "Test 9: hostport only uri failed \n");
                res = AST_TEST_FAIL;
        }
 
        /* Test 10, handle invalid/missing "sip:,sips:" scheme
         * we expect parse_uri to return an error, but still parse
         * the results correctly here */
-       name = pass = domain = transport = NULL;
-       if (!parse_uri(uri10, "sip:,sips:", &name, &pass, &domain, &transport) ||
+       name = pass = hostport = transport = NULL;
+       if (!parse_uri(uri10, "sip:,sips:", &name, &pass, &hostport, &transport) ||
                        !ast_strlen_zero(name)        ||
                        !ast_strlen_zero(pass)      ||
-                       strcmp(domain, "host:port")    ||
+                       strcmp(hostport, "host:port")    ||
                        strcmp(transport, "tcp")) {
                ast_test_status_update(test, "Test 10: missing \"sip:sips:\" scheme failed\n");
                res = AST_TEST_FAIL;
        }
 
-       /* Test 11, simple domain only URI with missing scheme
+       /* Test 11, simple hostport only URI with missing scheme
         * we expect parse_uri to return an error, but still parse
         * the results correctly here */
-       name = pass = domain = transport = NULL;
-       if (!parse_uri(uri11, "sip:,sips:", &name, &pass, &domain, &transport) ||
+       name = pass = hostport = transport = NULL;
+       if (!parse_uri(uri11, "sip:,sips:", &name, &pass, &hostport, &transport) ||
                        !ast_strlen_zero(name)      ||
                        !ast_strlen_zero(pass)      ||
-                       strcmp(domain, "host")      ||
+                       strcmp(hostport, "host")      ||
                        !ast_strlen_zero(transport)) {
                ast_test_status_update(test, "Test 11: simple uri with missing scheme failed. \n");
                res = AST_TEST_FAIL;
@@ -848,7 +848,7 @@ int get_name_and_number(const char *hdr, char **name, char **number)
        char header[256];
        char tmp_name[50] = { 0, };
        char *tmp_number = NULL;
-       char *domain = NULL;
+       char *hostport = NULL;
        char *dummy = NULL;
 
        if (!name || !number || ast_strlen_zero(hdr)) {
@@ -866,7 +866,7 @@ int get_name_and_number(const char *hdr, char **name, char **number)
        tmp_number = get_in_brackets(header);
 
        /* parse out the number here */
-       if (parse_uri(tmp_number, "sip:,sips:", &tmp_number, &dummy, &domain, NULL) || ast_strlen_zero(tmp_number)) {
+       if (parse_uri(tmp_number, "sip:,sips:", &tmp_number, &dummy, &hostport, NULL) || ast_strlen_zero(tmp_number)) {
                ast_log(LOG_ERROR, "can not parse name and number from sip header.\n");
                return -1;
        }
@@ -1153,7 +1153,7 @@ AST_TEST_DEFINE(get_in_brackets_test)
 
 
 int parse_name_andor_addr(char *uri, const char *scheme, char **name,
-                         char **user, char **pass, char **domain,
+                         char **user, char **pass, char **hostport,
                          struct uriparams *params, char **headers,
                          char **residue)
 {
@@ -1170,7 +1170,7 @@ int parse_name_andor_addr(char *uri, const char *scheme, char **name,
                residue2 = NULL;
        }
 
-       return parse_uri_full(uri, scheme, user, pass, domain, params, headers,
+       return parse_uri_full(uri, scheme, user, pass, hostport, params, headers,
                              residue2);
 }
 
@@ -1178,7 +1178,7 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
 {
        int res = AST_TEST_PASS;
        char uri[1024];
-       char *name, *user, *pass, *domain, *headers, *residue;
+       char *name, *user, *pass, *hostport, *headers, *residue;
        struct uriparams params;
 
        struct testdata {
@@ -1187,14 +1187,14 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
                char **nameptr;
                char **userptr;
                char **passptr;
-               char **domainptr;
+               char **hostportptr;
                char **headersptr;
                char **residueptr;
                struct uriparams *paramsptr;
                char *name;
                char *user;
                char *pass;
-               char *domain;
+               char *hostport;
                char *headers;
                char *residue;
                struct uriparams params;
@@ -1211,14 +1211,14 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
                .nameptr = &name,
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .name =  "name :@ ",
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "",
                .residue = "tag=tag",
                .params.transport = "tcp",
@@ -1232,14 +1232,14 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
                .nameptr = &name,
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .name = "givenname familyname",
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "",
                .residue = "expires=3600",
                .params.transport = "tcp",
@@ -1253,14 +1253,14 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
                .nameptr = &name,
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .name = "",
                .user = "user",
                .pass = "secret",
-               .domain = "host:5060",
+               .hostport = "host:5060",
                .headers = "",
                .residue = "q=1",
                .params.transport = "tcp",
@@ -1274,14 +1274,14 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
                .nameptr = &name,
                .userptr = &user,
                .passptr = &pass,
-               .domainptr = &domain,
+               .hostportptr = &hostport,
                .headersptr = &headers,
                .residueptr = &residue,
                .paramsptr = &params,
                .name = "",
                .user = "",
                .pass = "",
-               .domain = "host",
+               .hostport = "host",
                .headers = "",
                .residue = "",
                .params.transport = "",
@@ -1310,7 +1310,7 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
        }
 
        AST_LIST_TRAVERSE(&testdatalist, testdataptr, list) {
-               name = user = pass = domain = headers = residue = NULL;
+               name = user = pass = hostport = headers = residue = NULL;
                params.transport = params.user = params.method = params.ttl = params.maddr = NULL;
                params.lr = 0;
        ast_copy_string(uri,testdataptr->uri,sizeof(uri));
@@ -1318,14 +1318,14 @@ AST_TEST_DEFINE(parse_name_andor_addr_test)
                                          testdataptr->nameptr,
                                          testdataptr->userptr,
                                          testdataptr->passptr,
-                                         testdataptr->domainptr,
+                                         testdataptr->hostportptr,
                                          testdataptr->paramsptr,
                                          testdataptr->headersptr,
                                          testdataptr->residueptr) ||
                        ((testdataptr->nameptr) && strcmp(testdataptr->name, name)) ||
                        ((testdataptr->userptr) && strcmp(testdataptr->user, user)) ||
                        ((testdataptr->passptr) && strcmp(testdataptr->pass, pass)) ||
-                       ((testdataptr->domainptr) && strcmp(testdataptr->domain, domain)) ||
+                       ((testdataptr->hostportptr) && strcmp(testdataptr->hostport, hostport)) ||
                        ((testdataptr->headersptr) && strcmp(testdataptr->headers, headers)) ||
                        ((testdataptr->residueptr) && strcmp(testdataptr->residue, residue)) ||
                        ((testdataptr->paramsptr) && strcmp(testdataptr->params.transport,params.transport)) ||
@@ -1396,7 +1396,7 @@ int parse_contact_header(char *contactheader, struct contactliststruct *contactl
 
                res = parse_name_andor_addr(contactheader, "sip:,sips:",
                                            &contact->name, &contact->user,
-                                           &contact->pass, &contact->domain,
+                                           &contact->pass, &contact->hostport,
                                            &contact->params, &contact->headers,
                                            &residue);
                if (res == -1) {
@@ -1469,7 +1469,7 @@ AST_TEST_DEFINE(parse_contact_header_test)
                .name = "name :@;?&,",
                .user = "user",
                .pass = "secret",
-               .domain = "host:5082",
+               .hostport = "host:5082",
                .params.transport = "tcp",
                .params.ttl = "",
                .params.lr = 0,
@@ -1488,7 +1488,7 @@ AST_TEST_DEFINE(parse_contact_header_test)
                .name = "",
                .user = ",user1,",
                .pass = ",secret1,",
-               .domain = "host1",
+               .hostport = "host1",
                .params.transport = "",
                .params.ttl = "7",
                .params.lr = 0,
@@ -1500,7 +1500,7 @@ AST_TEST_DEFINE(parse_contact_header_test)
                .name = "",
                .user = "",
                .pass = "",
-               .domain = "host2",
+               .hostport = "host2",
                .params.transport = "",
                .params.ttl = "",
                .params.lr = 0,
@@ -1556,7 +1556,7 @@ AST_TEST_DEFINE(parse_contact_header_test)
                                        strcmp(tdcontactptr->name, contactptr->name) ||
                                        strcmp(tdcontactptr->user, contactptr->user) ||
                                        strcmp(tdcontactptr->pass, contactptr->pass) ||
-                                       strcmp(tdcontactptr->domain, contactptr->domain) ||
+                                       strcmp(tdcontactptr->hostport, contactptr->hostport) ||
                                        strcmp(tdcontactptr->headers, contactptr->headers) ||
                                        strcmp(tdcontactptr->expires, contactptr->expires) ||
                                        strcmp(tdcontactptr->q, contactptr->q) ||