--- asterisk-cvs-040609-nogren-1/asterisk/include/asterisk/vmodem.h 2004-06-14 10:46:32.000000000 +0200 +++ asterisk-cvs-040609-nogren/asterisk/include/asterisk/vmodem.h 2004-06-14 10:01:15.000000000 +0200 @@ -109,6 +109,8 @@ struct ast_modem_pvt { char msn[AST_MAX_EXTENSION]; /*! Multiple Subscriber Number we listen to (; seperated list) */ char incomingmsn[AST_MAX_EXTENSION]; + /*! Multiple Subscriber Number we accept for outgoing calls (; seperated list) */ + char outgoingmsn[AST_MAX_EXTENSION]; /*! Group(s) we belong to if available */ unsigned int group; /*! Caller ID if available */ --- asterisk-cvs-040609-nogren-1/asterisk/channels/chan_modem.c 2004-06-14 10:46:32.000000000 +0200 +++ asterisk-cvs-040609-nogren/asterisk/channels/chan_modem.c 2004-06-14 10:00:24.000000000 +0200 @@ -63,6 +63,9 @@ static char msn[AST_MAX_EXTENSION]=""; /* Default Listen */ static char incomingmsn[AST_MAX_EXTENSION]=""; +/* Default valid outgoing MSN */ +static char outgoingmsn[AST_MAX_EXTENSION]=""; + /* Default skip dtmf */ static int allowoutbanddtmf = 1; @@ -721,6 +724,7 @@ static struct ast_modem_pvt *mkif(char * strncpy(tmp->language, language, sizeof(tmp->language)-1); strncpy(tmp->msn, msn, sizeof(tmp->msn)-1); strncpy(tmp->incomingmsn, incomingmsn, sizeof(tmp->incomingmsn)-1); + strncpy(tmp->outgoingmsn, outgoingmsn, sizeof(tmp->outgoingmsn)-1); tmp->allowoutbanddtmf = allowoutbanddtmf; tmp->generateinbanddtmf = generateinbanddtmf; tmp->detectinband = detectinband; @@ -985,6 +989,8 @@ int load_module() strncpy(msn, v->value, sizeof(msn)-1); } else if (!strcasecmp(v->name, "incomingmsn")) { strncpy(incomingmsn, v->value, sizeof(incomingmsn)-1); + } else if (!strcasecmp(v->name, "outgoingmsn")) { + strncpy(outgoingmsn, v->value, sizeof(outgoingmsn)-1); } else if (!strcasecmp(v->name, "allowoutbanddtmf")) { allowoutbanddtmf = atoi(v->value); } else if (!strcasecmp(v->name, "generateinbanddtmf")) { --- asterisk-cvs-040609-nogren-1/asterisk/channels/chan_modem_i4l.c 2004-06-14 10:46:32.000000000 +0200 +++ asterisk-cvs-040609-nogren/asterisk/channels/chan_modem_i4l.c 2004-06-14 10:27:00.000000000 +0200 @@ -25,6 +25,7 @@ #include #include #include +#include #include "alaw.h" #define STATE_COMMAND 0 @@ -583,6 +584,31 @@ static int i4l_dialdigit(struct ast_mode static int i4l_dial(struct ast_modem_pvt *p, char *stuff) { char cmd[80]; + char tmp[255]; + char *name, *num; + struct ast_channel *c = p->owner; + + // Find callerid number first, to set the correct A number + if (c && c->callerid) { + ast_log(LOG_DEBUG, "Finding callerid from %s...\n",c->callerid); + strncpy(tmp, c->callerid, sizeof(tmp) - 1); + ast_callerid_parse(tmp, &name, &num); + if (num) { + ast_shrink_phone_number(num); + + if(strlen(p->outgoingmsn) && strstr(p->outgoingmsn,num) != NULL) { + // Tell ISDN4Linux to use this as A number + snprintf(cmd, sizeof(cmd), "AT&E%s\n", num); + if (ast_modem_send(p, cmd, strlen(cmd))) { + ast_log(LOG_WARNING, "Unable to set A number to %s\n",num); + } + + } else { + ast_log(LOG_WARNING, "Outgoing MSN %s not allowed (see outgoingmsn=%s in modem.conf)\n",num,p->outgoingmsn); + } + } + } + snprintf(cmd, sizeof(cmd), "ATD%c %s\n", p->dialtype,stuff); if (ast_modem_send(p, cmd, strlen(cmd))) { ast_log(LOG_WARNING, "Unable to dial\n"); --- asterisk-cvs-040609-nogren-1/asterisk/configs/modem.conf.sample 2004-06-14 10:59:14.000000000 +0200 +++ asterisk-cvs-040609-nogren/asterisk/configs/modem.conf.sample 2004-06-14 10:52:16.000000000 +0200 @@ -71,3 +71,8 @@ mode=immediate ; group=1 ; group=1,2,3,9-12 ;msn=50780023 +; +; If set, only these numbers are allowed to be set as A number +; when making an outbound call. callerid is used to set A +; number. +outgoingmsn=50780023,50780024 --- asterisk-cvs-040609-nogren-1/asterisk/channels/chan_sip.c 2004-06-09 03:45:08.000000000 +0200 +++ asterisk-cvs-040609-nogren/asterisk/channels/chan_sip.c 2004-06-14 13:42:03.000000000 +0200 @@ -4726,12 +4726,39 @@ static char *get_calleridname(char *inpu return output; } +/*--- get_rpid_num: Get caller id number from Remote-Party-ID header field + * Returns true if valid and no privacy setting found + */ +static int get_rpid_num(char *input,char *output) +{ + char *start; + char *end; + + if(!input) + return 0; + + if(strstr(input,"privacy=full") || strstr(input,"privacy=uri")) + return 0; + + start = strchr(input,':'); + end = strchr(input,'@'); + start++; + end--; + if (!start || !end || (end <= input)) + return 0; + /* we found "number" */ + strncpy(output,start,(int)(end-start+1)); + return 1; +} + + /*--- check_user: Check if matching user or peer is defined ---*/ static int check_user(struct sip_pvt *p, struct sip_request *req, char *cmd, char *uri, int reliable, struct sockaddr_in *sin, int ignore) { struct sip_user *user; struct sip_peer *peer; char *of, from[256] = "", *c; + char rpid_num[50]; int res = 0; char *t; char calleridname[50]; @@ -4744,6 +4771,12 @@ static int check_user(struct sip_pvt *p, strncpy(from, of, sizeof(from) - 1); memset(calleridname,0,sizeof(calleridname)); get_calleridname(from,calleridname); + + of = get_header(req, "Remote-Party-ID"); + if(!ast_strlen_zero(of)) + strncpy(p->remote_party_id,of,sizeof(p->remote_party_id)-1); + memset(rpid_num,0,sizeof(rpid_num)); + of = ditch_braces(from); if (ast_strlen_zero(p->exten)) { t = uri; @@ -4765,6 +4798,10 @@ static int check_user(struct sip_pvt *p, *c = '\0'; if ((c = strchr(of, ':'))) *c = '\0'; + if(!ast_strlen_zero(p->remote_party_id) && get_rpid_num(p->remote_party_id,rpid_num)) { + // privacy not set, and valid number. Use that instead of from-header number + of=(char *)rpid_num; + } if (*calleridname) sprintf(p->callerid,"\"%s\" <%s>",calleridname,of); else