[Asterisk-cvs] asterisk/channels chan_modem.c,1.21,1.22 chan_modem_i4l.c,1.14,1.15 chan_sip.c,1.415,1.416

markster at lists.digium.com markster at lists.digium.com
Mon Jun 21 00:43:54 CDT 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv9964/channels

Modified Files:
	chan_modem.c chan_modem_i4l.c chan_sip.c 
Log Message:
Merge outgoing MSN support + Remote Party ID for SIP (bug #1841) with cleanups


Index: chan_modem.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_modem.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- chan_modem.c	9 Jun 2004 01:45:08 -0000	1.21
+++ chan_modem.c	21 Jun 2004 04:29:50 -0000	1.22
@@ -63,6 +63,9 @@
 /* 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 @@
 		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 @@
 			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")) {

Index: chan_modem_i4l.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_modem_i4l.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- chan_modem_i4l.c	9 Jun 2004 01:45:08 -0000	1.14
+++ chan_modem_i4l.c	21 Jun 2004 04:29:50 -0000	1.15
@@ -528,6 +528,32 @@
 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");

Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.415
retrieving revision 1.416
diff -u -d -r1.415 -r1.416
--- chan_sip.c	18 Jun 2004 16:23:56 -0000	1.415
+++ chan_sip.c	21 Jun 2004 04:29:50 -0000	1.416
@@ -154,6 +154,8 @@
 
 static int globalrtpholdtimeout = 0;
 
+static int globaltrustrpid = 0;
+
 static int usecnt =0;
 AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
@@ -326,6 +328,8 @@
     	int stateid;
 	int dialogver;
 	
+        int trustrpid;
+	
         int dtmfmode;
         struct ast_dsp *vad;
 	
@@ -379,6 +383,7 @@
 	int outUse;
 	int outgoinglimit;
 	int restrictcid;
+        int trustrpid;
 	struct ast_ha *ha;
 	struct sip_user *next;
 };
@@ -411,6 +416,7 @@
 	unsigned int callgroup;
 	unsigned int pickupgroup;
         int dtmfmode;
+        int trustrpid;
 	struct sockaddr_in addr;
 	struct in_addr mask;
 
@@ -2083,6 +2089,7 @@
 	/* 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 @@
 	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 @@
 	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 @@
 			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 @@
 					else
 						p->noncodeccapability &= ~AST_RTP_DTMF;
 				}
+				p->trustrpid = peer->trustrpid;
+
 			}
 			if (peer->temponly) {
 				if (peer->ha) {
@@ -4920,6 +4968,15 @@
 		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 @@
 		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 @@
 				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 @@
 	peer->rtpholdtimeout = globalrtpholdtimeout;
 	peer->selfdestruct = 1;
 	peer->dynamic = 1;
+	peer->trustrpid = globaltrustrpid;
 	reg_source_db(peer);
 	return peer;
 }
@@ -7428,6 +7489,7 @@
 		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 @@
 					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 @@
 			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")) {




More information about the svn-commits mailing list