Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.692 diff -u -r1.692 chan_sip.c --- channels/chan_sip.c 24 Mar 2005 23:06:21 -0000 1.692 +++ channels/chan_sip.c 25 Mar 2005 09:11:06 -0000 @@ -9414,7 +9414,7 @@ int oldformat; struct sip_pvt *p; struct ast_channel *tmpc = NULL; - char *ext, *host; + char *ext = NULL, *host, *user = NULL, *userdomain = NULL; char tmp[256] = ""; char *dest = data; @@ -9431,33 +9431,49 @@ } strncpy(tmp, dest, sizeof(tmp) - 1); - host = strchr(tmp, '@'); - if (host) { + /* Destination format: + + SIP// the same as @ + SIP/ + SIP/@ the same as / + SIP/@/ set caller ID/From: and dial exten@host + SIP/@@/ set full SIP From: user@domain and dial exten@host + + The SIP/ part is already gone, so we got the rest to process in this routine. + */ + /* Check for @ */ + userdomain = strchr(tmp, '@'); + if (userdomain) { + host = strchr(userdomain+1, '@'); + if (!host) { /* No userdomain, only hostname */ + /* Found one @-sign, find the hostname/domain */ + host = userdomain; + } *host = '\0'; - host++; - ext = tmp; - } else { - ext = strchr(tmp, '/'); - if (ext) { - *ext++ = '\0'; - host = tmp; - } - else { - host = tmp; - ext = NULL; - } + host ++; + } + /* 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); + + /* Recalculate our side, and recalculate Call ID */ if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip)) memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); @@ -9469,6 +9485,9 @@ like SIP/peername/extension SIP/peername will still use the full contact */ if (ext) { + /* If username AND extension is given, username is caller ID/From: header */ + if (user) + strncpy(p->fromuser, user, sizeof(p->fromuser) -1); strncpy(p->username, ext, sizeof(p->username) - 1); p->fullcontact[0] = 0; }