aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-21 04:29:50 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-06-21 04:29:50 +0000
commit8bb793aa0b9f55faf60248bafa7e4e0d73f927e1 (patch)
tree5d100e519b6134064e138459063c486568e3106f
parent8c7c364aeb0faf889ca763fb8def30a1da045cfa (diff)
Merge outgoing MSN support + Remote Party ID for SIP (bug #1841) with cleanups
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3253 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xchannels/chan_modem.c6
-rwxr-xr-xchannels/chan_modem_i4l.c26
-rwxr-xr-xchannels/chan_sip.c66
-rwxr-xr-xconfigs/modem.conf.sample6
-rwxr-xr-xconfigs/sip.conf.sample2
-rwxr-xr-xinclude/asterisk/vmodem.h2
6 files changed, 108 insertions, 0 deletions
diff --git a/channels/chan_modem.c b/channels/chan_modem.c
index 905a15d28..59018c09c 100755
--- a/channels/chan_modem.c
+++ b/channels/chan_modem.c
@@ -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 group */
static unsigned int cur_group = 0;
@@ -708,6 +711,7 @@ static struct ast_modem_pvt *mkif(char *iface)
strncpy(tmp->language, language, sizeof(tmp->language)-1);
strncpy(tmp->msn, msn, sizeof(tmp->msn)-1);
strncpy(tmp->incomingmsn, incomingmsn, sizeof(tmp->incomingmsn)-1);
+ snprintf(tmp->outgoingmsn, sizeof(tmp->outgoingmsn), ",%s,", outgoingmsn);
strncpy(tmp->dev, iface, sizeof(tmp->dev)-1);
/* Maybe in the future we want to allow variable
serial settings */
@@ -968,6 +972,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, "language")) {
strncpy(language, v->value, sizeof(language)-1);
} else if (!strcasecmp(v->name, "group")) {
diff --git a/channels/chan_modem_i4l.c b/channels/chan_modem_i4l.c
index a7c28b621..ec854d06d 100755
--- a/channels/chan_modem_i4l.c
+++ b/channels/chan_modem_i4l.c
@@ -528,6 +528,32 @@ static int i4l_dialdigit(struct ast_modem_pvt *p, char digit)
static int i4l_dial(struct ast_modem_pvt *p, char *stuff)
{
char cmd[80];
+ char tmp[255];
+ char tmpmsn[255];
+ char *name, *num;
+ struct ast_channel *c = p->owner;
+
+ // Find callerid number first, to set the correct A number
+ if (c && c->callerid && ! c->restrictcid) {
+ 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);
+ snprintf(tmpmsn, sizeof(tmpmsn), ",%s,", num);
+ if(strlen(p->outgoingmsn) && strstr(p->outgoingmsn,tmpmsn) != 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");
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 1761f9133..316c59208 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -154,6 +154,8 @@ static int globalrtptimeout = 0;
static int globalrtpholdtimeout = 0;
+static int globaltrustrpid = 0;
+
static int usecnt =0;
AST_MUTEX_DEFINE_STATIC(usecnt_lock);
@@ -326,6 +328,8 @@ static struct sip_pvt {
int stateid;
int dialogver;
+ int trustrpid;
+
int dtmfmode;
struct ast_dsp *vad;
@@ -379,6 +383,7 @@ struct sip_user {
int outUse;
int outgoinglimit;
int restrictcid;
+ int trustrpid;
struct ast_ha *ha;
struct sip_user *next;
};
@@ -411,6 +416,7 @@ struct sip_peer {
unsigned int callgroup;
unsigned int pickupgroup;
int dtmfmode;
+ int trustrpid;
struct sockaddr_in addr;
struct in_addr mask;
@@ -2083,6 +2089,7 @@ static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useg
/* Assign default music on hold class */
strncpy(p->musicclass, globalmusicclass, sizeof(p->musicclass));
p->dtmfmode = globaldtmfmode;
+ p->trustrpid = globaltrustrpid;
p->rtptimeout = globalrtptimeout;
p->rtpholdtimeout = globalrtpholdtimeout;
p->capability = capability;
@@ -4762,12 +4769,44 @@ static char *get_calleridname(char *input,char *output)
return output;
}
+/*--- get_rpid_num: Get caller id number from Remote-Party-ID header field
+ * Returns true if number should be restricted (privacy setting found)
+ * output is set to NULL if no number found
+ */
+static int get_rpid_num(char *input,char *output, int maxlen)
+{
+ char *start;
+ char *end;
+
+ start = strchr(input,':');
+ if (!start) {
+ strcpy(output, "");
+ return 0;
+ }
+ start++;
+
+ /* we found "number" */
+ strncpy(output,start,maxlen-1);
+ output[maxlen-1] = '\0';
+
+ end = strchr(output,'@');
+ if (end)
+ *end = '\0';
+
+ if(strstr(input,"privacy=full") || strstr(input,"privacy=uri"))
+ return 1;
+
+ return 0;
+}
+
+
/*--- 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,rpid_num[50];
int res = 0;
char *t;
char calleridname[50];
@@ -4782,6 +4821,12 @@ static int check_user(struct sip_pvt *p, struct sip_request *req, char *cmd, cha
strncpy(from, of, sizeof(from) - 1);
memset(calleridname,0,sizeof(calleridname));
get_calleridname(from,calleridname);
+
+ rpid = get_header(req, "Remote-Party-ID");
+ memset(rpid_num,0,sizeof(rpid_num));
+ if(!ast_strlen_zero(rpid))
+ p->restrictcid = get_rpid_num(p->remote_party_id,rpid_num, sizeof(rpid_num));
+
of = ditch_braces(from);
if (ast_strlen_zero(p->exten)) {
t = uri;
@@ -4833,6 +4878,7 @@ static int check_user(struct sip_pvt *p, struct sip_request *req, char *cmd, cha
strncpy(p->accountcode, user->accountcode, sizeof(p->accountcode) -1);
strncpy(p->language, user->language, sizeof(p->language) -1);
strncpy(p->musicclass, user->musicclass, sizeof(p->musicclass) -1);
+ p->trustrpid = user->trustrpid;
p->canreinvite = user->canreinvite;
p->amaflags = user->amaflags;
p->callgroup = user->callgroup;
@@ -4907,6 +4953,8 @@ static int check_user(struct sip_pvt *p, struct sip_request *req, char *cmd, cha
else
p->noncodeccapability &= ~AST_RTP_DTMF;
}
+ p->trustrpid = peer->trustrpid;
+
}
if (peer->temponly) {
if (peer->ha) {
@@ -4920,6 +4968,15 @@ static int check_user(struct sip_pvt *p, struct sip_request *req, char *cmd, cha
ast_mutex_unlock(&peerl.lock);
}
+
+ /* replace callerid if rpid found, and not restricted */
+ if(!ast_strlen_zero(rpid_num) && p->trustrpid) {
+ if (*calleridname)
+ sprintf(p->callerid,"\"%s\" <%s>",calleridname,rpid_num);
+ else
+ strncpy(p->callerid, rpid_num, sizeof(p->callerid) - 1);
+ }
+
return res;
}
@@ -7257,6 +7314,7 @@ static struct sip_user *build_user(char *name, struct ast_variable *v)
user->capability = capability;
user->canreinvite = globalcanreinvite;
+ user->trustrpid = globaltrustrpid;
/* set default context */
strncpy(user->context, context, sizeof(user->context)-1);
strncpy(user->language, language, sizeof(user->language)-1);
@@ -7333,6 +7391,8 @@ static struct sip_user *build_user(char *name, struct ast_variable *v)
user->insecure = ast_true(v->value);
} else if (!strcasecmp(v->name, "restrictcid")) {
user->restrictcid = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "trustrpid")) {
+ user->trustrpid = ast_true(v->value);
}
/*else if (strcasecmp(v->name,"type"))
* ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
@@ -7369,6 +7429,7 @@ static struct sip_peer *temp_peer(char *name)
peer->rtpholdtimeout = globalrtpholdtimeout;
peer->selfdestruct = 1;
peer->dynamic = 1;
+ peer->trustrpid = globaltrustrpid;
reg_source_db(peer);
return peer;
}
@@ -7428,6 +7489,7 @@ static struct sip_peer *build_peer(char *name, struct ast_variable *v)
peer->rtptimeout = globalrtptimeout;
peer->rtpholdtimeout = globalrtpholdtimeout;
peer->dtmfmode = 0;
+ peer->trustrpid = globaltrustrpid;
while(v) {
if (!strcasecmp(v->name, "secret"))
strncpy(peer->secret, v->value, sizeof(peer->secret)-1);
@@ -7551,6 +7613,8 @@ static struct sip_peer *build_peer(char *name, struct ast_variable *v)
ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno);
peer->maxms = 0;
}
+ } else if (!strcasecmp(v->name, "trustrpid")) {
+ peer->trustrpid = ast_true(v->value);
}
/* else if (strcasecmp(v->name,"type"))
* ast_log(LOG_WARNING, "Ignoring %s\n", v->name);
@@ -7664,6 +7728,8 @@ static int reload_config(void)
autocreatepeer = ast_true(v->value);
} else if (!strcasecmp(v->name, "srvlookup")) {
srvlookup = ast_true(v->value);
+ } else if (!strcasecmp(v->name, "trustrpid")) {
+ globaltrustrpid = ast_true(v->value);
} else if (!strcasecmp(v->name, "pedantic")) {
pedanticsipchecking = ast_true(v->value);
} else if (!strcasecmp(v->name, "canreinvite")) {
diff --git a/configs/modem.conf.sample b/configs/modem.conf.sample
index 81e3a0ff2..77dd64cc0 100755
--- a/configs/modem.conf.sample
+++ b/configs/modem.conf.sample
@@ -64,6 +64,12 @@ mode=immediate
;incomingmsn=50780020,50780021,50780022
;device => /dev/ttyI2
;
+; 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
+;
+;
; two other devices, which are in group '1' and are used when an
; outgoing dial used: exten => s,1,Dial,Modem/g1:1234|60|r
; (we do not need more outgoing devices, since ISDN2 has only 2 channels.)
diff --git a/configs/sip.conf.sample b/configs/sip.conf.sample
index 98446653b..3e6daa34c 100755
--- a/configs/sip.conf.sample
+++ b/configs/sip.conf.sample
@@ -57,6 +57,7 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
; when we're not on hold
;rtpholdtimeout=300 ; Terminate call if 300 seconds of no RTP activity
; when we're on hold (must be > rtptimeout)
+;trustrpid = no ; If Remote-Party-ID should be trusted
;useragent=Asterisk PBX ; Allows you to change the user agent string
; Asterisk can register as a SIP user agent to a SIP proxy (provider)
@@ -121,6 +122,7 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
; allow allow
; disallow disallow
; insecure insecure
+; trustrpid trustrpid
; callerid
; accountcode
; amaflags
diff --git a/include/asterisk/vmodem.h b/include/asterisk/vmodem.h
index 2d80a1440..b6dc37d07 100755
--- a/include/asterisk/vmodem.h
+++ b/include/asterisk/vmodem.h
@@ -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 */