--- ../../cvs_asterisk/asterisk/channels/chan_sip.c 2004-08-23 16:31:20.000000000 +0200 +++ channels/chan_sip.c 2004-08-24 16:58:29.000000000 +0200 @@ -12,6 +12,29 @@ */ +/* + +Modifications dz 2004 08 24 + +Using an outgoing proxy means sending the message to host different +from the realm (uri) used inside the sip-message. To do this +the following syntax is supported inside sip.conf: +"user[:secret[:authuser]]@host[:port][/extension]" + +The request will be sent to "host" while "authuser" will be used inside +the sip-message. +When trying to use this at my provider I noticed to problems, this +patch should fix them: +- the first line of the REGISTER request contained "host" (outgoing proxy) +while "authuser" was expected, therefore I replaced this by the authuser variable +- when authenticating "user@authuser" was used instead of "user", therefore +authentication failed, now only "user" is used. + + +*/ + + + #include #include #include @@ -1284,6 +1307,10 @@ } strncpy(r->peername, p->username, sizeof(r->peername)-1); strncpy(r->authname, p->username, sizeof(r->authname)-1); + /* dz 2004-08-23*/ + /* authname shall always be without realm (never use user@realm) */ + if (strchr(r->authname,'@')) + *(strchr(r->authname,'@'))=0; strncpy(r->peersecret, p->secret, sizeof(r->peersecret)-1); strncpy(r->peermd5secret, p->md5secret, sizeof(r->peermd5secret)-1); strncpy(r->username, p->username, sizeof(r->username)-1); @@ -3993,6 +4020,7 @@ char tmp[80]; char via[80]; char addr[80]; + char *hostpart=NULL; /* dz pointer to hostpart of username */ char iabuf[INET_ADDRSTRLEN]; struct sip_pvt *p; @@ -4038,6 +4066,10 @@ if (!ast_strlen_zero(r->username)) { strncpy(p->peername, r->username, sizeof(p->peername)-1); strncpy(p->authname, r->username, sizeof(p->authname)-1); + /* dz 2004-08-23*/ + /* authname shall always be without realm (never use user@realm) */ + if (strchr(p->authname,'@')) + *(strchr(p->authname,'@'))=0; } } if (!ast_strlen_zero(r->username)) @@ -4067,12 +4099,17 @@ if (strchr(r->username, '@')) { snprintf(from, sizeof(from), ";tag=as%08x", r->username, p->tag); snprintf(to, sizeof(to), "", r->username); + /* dz 2004 08 23 use auth and not host in SIP-uri*/ + hostpart = strrchr(r->username, '@')+1; + snprintf(addr, sizeof(addr), "sip:%s", hostpart); } else { snprintf(from, sizeof(from), ";tag=as%08x", r->username, p->tohost, p->tag); snprintf(to, sizeof(to), "", r->username, p->tohost); + /* no outgoing proxy defined */ + snprintf(addr, sizeof(addr), "sip:%s", r->hostname); + } - snprintf(addr, sizeof(addr), "sip:%s", r->hostname); strncpy(p->uri, addr, sizeof(p->uri) - 1); p->branch ^= rand(); @@ -5346,6 +5383,9 @@ if (!ast_strlen_zero(peer->username)) { strncpy(p->username, peer->username, sizeof(p->username) - 1); strncpy(p->authname, peer->username, sizeof(p->authname) - 1); + /* dz 2004-08-23*/ + if (strchr(p->authname,'@')) + *(strchr(p->authname,'@'))=0; } if (!ast_strlen_zero(peer->context)) strncpy(p->context, peer->context, sizeof(p->context) - 1); @@ -5467,7 +5507,7 @@ /*--- sip_show_users: CLI Command 'SIP Show Users' ---*/ static int sip_show_users(int fd, int argc, char *argv[]) { -#define FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-5.5s%-5.5s\n" +#define FORMAT "%-15.15s %-22.22s %-15.15s %-15.15s %-5.5s%-5.5s\n" struct sip_user *user; if (argc != 3) return RESULT_SHOWUSAGE; @@ -5489,8 +5529,8 @@ /*--- sip_show_peers: CLI Show Peers command */ static int sip_show_peers(int fd, int argc, char *argv[]) { -#define FORMAT2 "%-15.15s %-15.15s %s %s %s %-15.15s %-8s %-10s\n" -#define FORMAT "%-15.15s %-15.15s %s %s %s %-15.15s %-8d %-10s\n" +#define FORMAT2 "%-15.15s %-25.25s %s %s %s %-15.15s %-8s %-10s\n" +#define FORMAT "%-15.15s %-25.25s %s %s %s %-15.15s %-8d %-10s\n" struct sip_peer *peer; char name[256] = ""; char iabuf[INET_ADDRSTRLEN];