Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.678 diff -u -r1.678 chan_sip.c --- channels/chan_sip.c 19 Mar 2005 17:31:33 -0000 1.678 +++ channels/chan_sip.c 19 Mar 2005 20:59:14 -0000 @@ -9129,7 +9129,7 @@ int oldformat; struct sip_pvt *p; struct ast_channel *tmpc = NULL; - char *ext, *host; + char *ext = NULL, *host, *user = NULL; char tmp[256] = ""; char *dest = data; @@ -9146,33 +9146,46 @@ } strncpy(tmp, dest, sizeof(tmp) - 1); + /* Destination format: + SIP// + SIP/ + SIP/@ + SIP/@/ + The SIP/ part is already gone, so we got the rest to + process in this routine. + */ + /* Check for @ */ host = strchr(tmp, '@'); if (host) { + /* Found a @-sign, find the hostname/domain */ *host = '\0'; host++; - ext = tmp; - } else { - ext = strchr(tmp, '/'); - if (ext) { - *ext++ = '\0'; - host = tmp; - } - else { - host = tmp; - ext = NULL; - } + } + /* Tmp now points to the username part + Pick the exten from the host part */ + user = tmp; + + /* Find the extension */ + ext = strchr(host, '/'); + if (ext) { + *ext++ = '\0'; } /* Assign a default capability */ p->capability = global_capability; + /* is either a [peer] or a DNS domain + or a host name - create_addr will sort it out for us */ if (create_addr(p, host)) { *cause = AST_CAUSE_UNREGISTERED; sip_destroy(p); return NULL; } - if (ast_strlen_zero(p->peername) && ext) - strncpy(p->peername, ext, sizeof(p->peername) - 1); + + /* Use the user name */ + if (user) + strncpy(p->fromuser, user, sizeof(p->fromuser) -1); + /* Recalculate our side, and recalculate Call ID */ if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip)) memcpy(&p->ourip, &__ourip, sizeof(p->ourip));