Index: chan_sip.c =================================================================== --- chan_sip.c (revision 206937) +++ chan_sip.c (working copy) @@ -2069,7 +2069,8 @@ AST_STRING_FIELD(nonce); /*!< Authorization nonce */ AST_STRING_FIELD(opaque); /*!< Opaque nonsense */ AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */ - AST_STRING_FIELD(domain); /*!< Authorization domain */ + AST_STRING_FIELD(authdomain); /*!< Authorization domain */ + AST_STRING_FIELD(regdomain); /*!< Registration domain */ AST_STRING_FIELD(username); /*!< Who we are registering as */ AST_STRING_FIELD(authuser); /*!< Who we *authenticate* as */ AST_STRING_FIELD(hostname); /*!< Domain or host we register to */ @@ -7446,7 +7447,7 @@ char buf[256] = ""; char *username = NULL; char *hostname=NULL, *secret=NULL, *authuser=NULL, *expire=NULL, *tmp=NULL; - char *callback=NULL, *peername=NULL; + char *callback=NULL, *peername=NULL, *regdomain=NULL; if (!value) return -1; @@ -7500,6 +7501,13 @@ if ((secret) && (ast_strlen_zero(secret))) secret = NULL; + /* The user portion may be of the form username@regdomain so split off any regdomain */ + regdomain = strchr(username, '@'); + if (regdomain) { + *regdomain++ = '\0'; + } + + if (!(reg = ast_calloc(1, sizeof(*reg)))) { ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n"); return -1; @@ -7518,6 +7526,9 @@ ast_string_field_set(reg, username, username); if (hostname) ast_string_field_set(reg, hostname, hostname); + ast_string_field_set(reg, regdomain, hostname); + if (regdomain) + ast_string_field_set(reg, regdomain, regdomain); if (authuser) ast_string_field_set(reg, authuser, authuser); if (secret) @@ -11534,8 +11545,6 @@ struct sip_pvt *p; struct sip_peer *peer; int res; - char *fromdomain; - char *domainport = NULL; /* exit if we are already in process with this registrar ?*/ if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) { @@ -11619,8 +11628,6 @@ if (!r->dnsmgr && r->portno) { p->sa.sin_port = htons(r->portno); p->recv.sin_port = htons(r->portno); - } else { /* Set registry port to the port set from the peer definition/srv or default */ - r->portno = ntohs(p->sa.sin_port); } ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Registration is outgoing call */ r->call = dialog_ref(p, "copying dialog into registry r->call"); /* Save pointer to SIP dialog */ @@ -11672,55 +11679,20 @@ ast_debug(1, "Scheduled a registration timeout for %s id #%d \n", r->hostname, r->timeout); } - if ((fromdomain = strchr(r->username, '@'))) { - /* the domain name is just behind '@' */ - fromdomain++ ; - /* We have a domain in the username for registration */ - snprintf(from, sizeof(from), ";tag=%s", r->username, p->tag); - if (!ast_strlen_zero(p->theirtag)) - snprintf(to, sizeof(to), ";tag=%s", r->username, p->theirtag); - else - snprintf(to, sizeof(to), "", r->username); - - /* If the registration username contains '@', then the domain should be used as - the equivalent of "fromdomain" for the registration */ - if (ast_strlen_zero(p->fromdomain)) { - ast_string_field_set(p, fromdomain, fromdomain); - } + snprintf(from, sizeof(from), ";tag=%s", r->username, r->regdomain, p->tag); + if (!ast_strlen_zero(p->theirtag)) { + snprintf(to, sizeof(to), ";tag=%s", r->username, r->regdomain, p->theirtag); } else { - snprintf(from, sizeof(from), ";tag=%s", r->username, p->tohost, p->tag); - if (!ast_strlen_zero(p->theirtag)) - snprintf(to, sizeof(to), ";tag=%s", r->username, p->tohost, p->theirtag); - else - snprintf(to, sizeof(to), "", r->username, p->tohost); + snprintf(to, sizeof(to), "", r->username, r->regdomain); } - - /* Fromdomain is what we are registering to, regardless of actual + + /* Domain is what we are registering to, regardless of actual host name from SRV */ - if (!ast_strlen_zero(p->fromdomain)) { - domainport = strrchr(p->fromdomain, ':'); - if (domainport) { - *domainport++ = '\0'; /* trim off domainport from p->fromdomain */ - if (ast_strlen_zero(domainport)) - domainport = NULL; - } - if (domainport) { - if (atoi(domainport) != STANDARD_SIP_PORT) - snprintf(addr, sizeof(addr), "sip:%s:%s", p->fromdomain, domainport); - else - snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain); - } else { - if (r->portno && r->portno != STANDARD_SIP_PORT) - snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno); - else - snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain); - } - } else { - if (r->portno && r->portno != STANDARD_SIP_PORT) - snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, r->portno); - else - snprintf(addr, sizeof(addr), "sip:%s", r->hostname); - } + if (ntohs(p->sa.sin_port) != STANDARD_SIP_PORT) + snprintf(addr, sizeof(addr), "sip:%s:%d", r->regdomain, ntohs(p->sa.sin_port)); + else + snprintf(addr, sizeof(addr), "sip:%s", r->regdomain); + ast_string_field_set(p, uri, addr); p->branch ^= ast_random(); @@ -11756,7 +11728,7 @@ ast_debug(1, " >>> Re-using Auth data for %s@%s\n", r->username, r->hostname); ast_string_field_set(p, realm, r->realm); ast_string_field_set(p, nonce, r->nonce); - ast_string_field_set(p, domain, r->domain); + ast_string_field_set(p, domain, r->authdomain); ast_string_field_set(p, opaque, r->opaque); ast_string_field_set(p, qop, r->qop); p->noncecount = ++r->noncecount; @@ -14690,11 +14662,12 @@ "Host: %s\r\n" "Port: %d\r\n" "Username: %s\r\n" + "Domain: %s\r\n" "Refresh: %d\r\n" "State: %s\r\n" "RegistrationTime: %ld\r\n" "\r\n", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT, - iterator->username, iterator->refresh, regstate2str(iterator->regstate), (long) iterator->regtime.tv_sec); + iterator->username, iterator->regdomain, iterator->refresh, regstate2str(iterator->regstate), (long) iterator->regtime.tv_sec); ASTOBJ_UNLOCK(iterator); total++; } while(0)); @@ -15837,6 +15810,7 @@ #define FORMAT2 "%-30.30s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" #define FORMAT "%-30.30s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" char host[80]; + char user[80]; char tmpdat[256]; struct ast_tm tm; int counter = 0; @@ -15859,12 +15833,13 @@ ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { ASTOBJ_RDLOCK(iterator); snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT); + snprintf(user, sizeof(user), "%s@%s", iterator->username, iterator->regdomain); if (iterator->regtime.tv_sec) { ast_localtime(&iterator->regtime, &tm, NULL); ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm); } else tmpdat[0] = '\0'; - ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat); + ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", user, iterator->refresh, regstate2str(iterator->regstate), tmpdat); ASTOBJ_UNLOCK(iterator); counter++; } while(0)); @@ -17174,7 +17149,7 @@ if (strcmp(r->nonce, p->nonce)) { ast_string_field_set(r, realm, p->realm); ast_string_field_set(r, nonce, p->nonce); - ast_string_field_set(r, domain, p->domain); + ast_string_field_set(r, authdomain, p->domain); ast_string_field_set(r, opaque, p->opaque); ast_string_field_set(r, qop, p->qop); r->noncecount = 0;