Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.570 diff -u -r1.570 chan_sip.c --- channels/chan_sip.c 18 Nov 2004 04:26:22 -0000 1.570 +++ channels/chan_sip.c 21 Nov 2004 10:14:36 -0000 @@ -42,6 +42,7 @@ #include #include #include +#include #ifdef OSP_SUPPORT #include #endif @@ -191,8 +192,9 @@ static int videosupport = 0; static int global_dtmfmode = SIP_DTMF_RFC2833; /* DTMF mode default */ -static int recordhistory = 0; +static int recordhistory = 0; /* Record SIP history. Off by default */ static int global_promiscredir; /* Support of 302 REDIR - Default off */ +static int global_usereqphone; /* User=phone support, default 0 */ static char global_musicclass[MAX_LANGUAGE] = ""; /* Global music on hold class */ static char global_realm[AST_MAX_EXTENSION] = "asterisk"; /* Default realm */ @@ -340,6 +342,7 @@ int stateid; int dialogver; int promiscredir; /* Promiscuous redirection */ + int usereqphone; /* Add user=phone to numeric URI. Default off */ int trustrpid; /* Trust RPID headers? */ int progressinband; @@ -450,6 +453,7 @@ int trustrpid; /* Trust Remote Party ID headers? */ int useclientcode; /* SNOM clientcode support */ int progressinband; + int usereqphone; /* Add user=phone to URI. Default off */ struct sockaddr_in addr; /* IP address of peer */ struct in_addr mask; @@ -1283,6 +1287,7 @@ r->noncodeccapability &= ~AST_RTP_DTMF; } r->promiscredir = p->promiscredir; + r->usereqphone = p->usereqphone; strncpy(r->context, p->context,sizeof(r->context)-1); if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) && (!p->maxms || ((p->lastms > 0) && (p->lastms <= p->maxms)))) { @@ -3655,6 +3660,34 @@ char tmp[80]; char iabuf[INET_ADDRSTRLEN]; char *l = default_callerid, *n=NULL; + int x; + char urioptions[256]; + + if (p->usereqphone) { + char onlydigits = 1; + x=0; + + /* Test p->username against allowed characters in AST_DIGIT_ANY + If it matches the allowed characters list, then sipuser = ";user=phone" + + If not, then sipuser = "" + */ + /* + is allowed in first position in a tel: uri */ + if (p->username && p->username[0] == '+') + x=1; + + for (;xusername);x++) { + if (!strchr(AST_DIGIT_ANY, p->username[x])) { + onlydigits = 0; + break; + } + } + + /* If we have only digits, add ;user=phone to the uri */ + if (onlydigits) + strcpy(urioptions, ";user=phone"); + } + snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", cmd); @@ -3687,14 +3720,14 @@ /* Otherwise, use the username while waiting for registration */ } else if (!ast_strlen_zero(p->username)) { if (ntohs(p->sa.sin_port) != DEFAULT_SIP_PORT) { - snprintf(invite, sizeof(invite), "sip:%s@%s:%d",p->username, p->tohost, ntohs(p->sa.sin_port)); + snprintf(invite, sizeof(invite), "sip:%s@%s:%d%s",p->username, p->tohost, ntohs(p->sa.sin_port), urioptions); } else { - snprintf(invite, sizeof(invite), "sip:%s@%s",p->username, p->tohost); + snprintf(invite, sizeof(invite), "sip:%s@%s%s",p->username, p->tohost, urioptions); } } else if (ntohs(p->sa.sin_port) != DEFAULT_SIP_PORT) { - snprintf(invite, sizeof(invite), "sip:%s:%d", p->tohost, ntohs(p->sa.sin_port)); + snprintf(invite, sizeof(invite), "sip:%s:%d%s", p->tohost, ntohs(p->sa.sin_port), urioptions); } else { - snprintf(invite, sizeof(invite), "sip:%s", p->tohost); + snprintf(invite, sizeof(invite), "sip:%s%s", p->tohost, urioptions); } strncpy(p->uri, invite, sizeof(p->uri) - 1); /* If there is a VXML URL append it to the SIP URL */ @@ -5769,6 +5802,7 @@ ast_cli(fd, " ACL : %s\n", (peer->ha?"Yes":"No")); ast_cli(fd, " CanReinvite : %s\n", (peer->canreinvite?"Yes":"No")); ast_cli(fd, " PromiscRedir : %s\n", (peer->promiscredir?"Yes":"No")); + ast_cli(fd, " User=Phone : %s\n", (peer->usereqphone?"Yes":"No")); /* - is enumerated */ ast_cli(fd, " DTMFmode : "); @@ -8319,6 +8353,7 @@ peer->canreinvite = global_canreinvite; peer->dtmfmode = global_dtmfmode; peer->promiscredir = global_promiscredir; + peer->usereqphone = global_usereqphone; peer->nat = global_nat; peer->rtptimeout = global_rtptimeout; peer->rtpholdtimeout = global_rtpholdtimeout; @@ -8386,6 +8421,7 @@ peer->addr.sin_family = AF_INET; peer->defaddr.sin_family = AF_INET; peer->expiry = expiry; + peer->usereqphone = global_usereqphone; } oldha = peer->ha; peer->ha = NULL; @@ -8427,6 +8463,8 @@ strncpy(peer->context, v->value, sizeof(peer->context)-1); else if (!strcasecmp(v->name, "fromdomain")) strncpy(peer->fromdomain, v->value, sizeof(peer->fromdomain)-1); + else if (!strcasecmp(v->name, "usereqphone")) + peer->usereqphone = ast_true(v->value); else if (!strcasecmp(v->name, "promiscredir")) peer->promiscredir = ast_true(v->value); else if (!strcasecmp(v->name, "fromuser")) @@ -8588,7 +8626,8 @@ char iabuf[INET_ADDRSTRLEN]; global_dtmfmode = SIP_DTMF_RFC2833; - global_promiscredir = 0; + global_promiscredir = 0; /* Support 302 redirects */ + global_usereqphone = 0; /* Add user=phone to URI. Default off */ if (gethostname(ourhost, sizeof(ourhost))) { ast_log(LOG_WARNING, "Unable to get hostname, SIP disabled\n"); @@ -8636,6 +8675,8 @@ strncpy(default_useragent, v->value, sizeof(default_useragent)-1); ast_log(LOG_DEBUG, "Setting User Agent Name to %s\n", default_useragent); + } else if (!strcasecmp(v->name, "usereqphone")) { + global_usereqphone = ast_true(v->value); } else if (!strcasecmp(v->name, "relaxdtmf")) { relaxdtmf = ast_true(v->value); } else if (!strcasecmp(v->name, "promiscredir")) { Index: configs/sip.conf.sample =================================================================== RCS file: /usr/cvsroot/asterisk/configs/sip.conf.sample,v retrieving revision 1.44 diff -u -r1.44 sip.conf.sample --- configs/sip.conf.sample 17 Nov 2004 03:11:42 -0000 1.44 +++ configs/sip.conf.sample 21 Nov 2004 10:14:36 -0000 @@ -74,6 +74,8 @@ ;promiscredir = no ; If yes, allows 302 or REDIR to non-local SIP address ; Note that promiscredir when redirects are made to the ; local system will cause loops since SIP is incapable +;usereqphone = no ; If yes, ";user=phone" is added to uri that contains + ; a valid phone number ; of performing a "hairpin" call. ;dtmfmode = rfc2833 ; Set default dtmfmode for sending DTMF. Default: rfc2833 ; Other options: @@ -186,6 +188,7 @@ ;username=yourusername ; Authentication user for outbound proxies ;fromuser=yourusername ; Many SIP providers require this! ;host=box.provider.com +;usereqphone=yes ; This provider requires ";user=phone" on URI ;[grandstream1] ;type=friend ; either "friend" (peer+user), "peer" or "user"