diff -NaurbB old/chan_sip.c new/chan_sip.c --- old/chan_sip.c 2009-01-21 17:00:22.000000000 +0000 +++ new/chan_sip.c 2009-01-26 17:46:37.000000000 +0000 @@ -1603,7 +1603,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 */ @@ -6467,7 +6468,7 @@ char *username = NULL; char *port = NULL; char *hostname=NULL, *secret=NULL, *authuser=NULL, *expire=NULL; - char *callback=NULL; + char *callback=NULL, char *regdomain=NULL; if (!value) return -1; @@ -6512,6 +6513,12 @@ if (port) { *port = ':'; } + + /* Parse user parameters of the form username@domain now rather than during each registration */ + 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; @@ -6530,6 +6537,7 @@ ast_string_field_set(reg, username, username); if (hostname) ast_string_field_set(reg, hostname, hostname); + ast_string_field_set(reg, regdomain, hostname); if (authuser) ast_string_field_set(reg, authuser, authuser); if (secret) @@ -6542,6 +6550,10 @@ reg->portno = portnum; reg->callid_valid = FALSE; reg->ocseq = INITIAL_CSEQ; + + if (regdomain) + ast_string_field_set(reg, regdomain, regdomain); + ASTOBJ_CONTAINER_LINK(®l, reg); /* Add the new registry entry to the list */ registry_unref(reg, "unref the reg pointer"); /* release the reference given by ASTOBJ_INIT. The container has another reference */ return 0; @@ -9875,7 +9887,6 @@ char addr[80]; struct sip_pvt *p; int res; - char *fromdomain; /* 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))) { @@ -9946,8 +9957,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 */ @@ -9998,42 +10007,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); + 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, p->theirtag); + snprintf(to, sizeof(to), ";tag=%s", r->username, r->regdomain, p->theirtag); else - snprintf(to, sizeof(to), "", r->username); + snprintf(to, sizeof(to), "", r->username, r->regdomain); - /* 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); - } - } 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); - } - /* Fromdomain is what we are registering to, regardless of actual - host name from SRV */ - if (!ast_strlen_zero(p->fromdomain)) { - 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); + /* Host is what we are registering to, regardless of domain */ + + if (ntohs(p->sa.sin_port) != STANDARD_SIP_PORT) + snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, ntohs(p->sa.sin_port)); else snprintf(addr, sizeof(addr), "sip:%s", r->hostname); - } + ast_string_field_set(p, uri, addr); p->branch ^= ast_random(); @@ -10069,7 +10056,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; @@ -12646,11 +12633,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)); @@ -13794,6 +13782,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; @@ -13816,12 +13805,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)); @@ -15126,7 +15116,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;