[Asterisk-cvs] asterisk callerid.c, 1.22, 1.23 cdr.c, 1.22, 1.23 channel.c, 1.139, 1.140 cli.c, 1.53, 1.54 manager.c, 1.74, 1.75 pbx.c, 1.154, 1.155

markster at lists.digium.com markster at lists.digium.com
Fri Oct 1 20:56:25 CDT 2004


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

Modified Files:
	callerid.c cdr.c channel.c cli.c manager.c pbx.c 
Log Message:
Huge callerid rework (might break H.323, others)


Index: callerid.c
===================================================================
RCS file: /usr/cvsroot/asterisk/callerid.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- callerid.c	30 Sep 2004 17:54:41 -0000	1.22
+++ callerid.c	2 Oct 2004 00:58:31 -0000	1.23
@@ -24,6 +24,7 @@
 #include <asterisk/ulaw.h>
 #include <asterisk/alaw.h>
 #include <asterisk/frame.h>
+#include <asterisk/channel.h>
 #include <asterisk/callerid.h>
 #include <asterisk/logger.h>
 #include <asterisk/fskmodem.h>
@@ -638,30 +639,53 @@
 	return -1;
 }
 
-static int __ast_callerid_generate(unsigned char *buf, char *callerid, int callwaiting, int codec)
+static int __ast_callerid_generate(unsigned char *buf, char *name, char *number, int callwaiting, int codec)
 {
-	char tmp[256];
-	char *n, *l;
-	if (!callerid)
-		return callerid_generate(buf, NULL, NULL, 0, callwaiting, codec);
-	strncpy(tmp, callerid, sizeof(tmp)-1);
-	if (ast_callerid_parse(tmp, &n, &l)) {
-		ast_log(LOG_WARNING, "Unable to parse '%s' into CallerID name & number\n", callerid);
-		return callerid_generate(buf, NULL, NULL, 0, callwaiting, codec);
-	}
-	if (l)
-		ast_shrink_phone_number(l);
-	if (!ast_isphonenumber(l))
-		return callerid_generate(buf, NULL, n, 0, callwaiting, codec);
-	return callerid_generate(buf, l, n, 0, callwaiting, codec);
+	if (name && ast_strlen_zero(name))
+		name = NULL;
+	if (number && ast_strlen_zero(number))
+		number = NULL;
+	return callerid_generate(buf, number, name, 0, callwaiting, codec);
 }
 
-int ast_callerid_generate(unsigned char *buf, char *callerid, int codec)
+int ast_callerid_generate(unsigned char *buf, char *name, char *number, int codec)
 {
-	return __ast_callerid_generate(buf, callerid, 0, codec);
+	return __ast_callerid_generate(buf, name, number, 0, codec);
 }
 
-int ast_callerid_callwaiting_generate(unsigned char *buf, char *callerid, int codec)
+int ast_callerid_callwaiting_generate(unsigned char *buf, char *name, char *number, int codec)
 {
-	return __ast_callerid_generate(buf, callerid, 1, codec);
+	return __ast_callerid_generate(buf, name, number, 1, codec);
+}
+
+char *ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num)
+{
+	if (name && num)
+		snprintf(buf, bufsiz, "\"%s\" <%s>", name, num);
+	else if (name) 
+		strncpy(buf, name, bufsiz - 1);
+	else if (num)
+		strncpy(buf, num, bufsiz - 1);
+	else
+		strncpy(buf, "<unknown>", bufsiz - 1);
+	return buf;
+}
+int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int numlen)
+{
+	char *tmp;
+	char *l = NULL, *n = NULL;
+	tmp = ast_strdupa(buf);
+	if (!tmp) {
+		name[0] = '\0';
+		num[0] = '\0';
+		return -1;
+	}
+	ast_callerid_parse(tmp, &n, &l);
+	if (n)
+		strncpy(name, n, namelen - 1);
+	if (l) {
+		ast_shrink_phone_number(l);
+		strncpy(num, l, numlen - 1);
+	}
+	return 0;
 }

Index: cdr.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- cdr.c	24 Sep 2004 21:32:56 -0000	1.22
+++ cdr.c	2 Oct 2004 00:58:31 -0000	1.23
@@ -251,23 +251,28 @@
 int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *c)
 {
 	char tmp[AST_MAX_EXTENSION] = "";
-	char *num, *name;
+	char *num;
 	while (cdr) {
 		if(!ast_cdr_has_flag(cdr,AST_CDR_FLAG_LOCKED)) {
 			/* Grab source from ANI or normal Caller*ID */
-			if (c->ani)
-				strncpy(tmp, c->ani, sizeof(tmp) - 1);
-			else if (c->callerid)
-				strncpy(tmp, c->callerid, sizeof(tmp) - 1);
-			if (c->callerid)
-				strncpy(cdr->clid, c->callerid, sizeof(cdr->clid) - 1);
-			name = NULL;
-			num = NULL;
-			ast_callerid_parse(tmp, &name, &num);
-			if (num) {
-				ast_shrink_phone_number(num);
+			if (c->cid.cid_ani)
+				num = c->cid.cid_ani;
+			else
+				num = c->cid.cid_num;
+			
+			if (c->cid.cid_name && num)
+				snprintf(tmp, sizeof(tmp), "\"%s\" <%s>", c->cid.cid_name, num);
+			else if (c->cid.cid_name)
+				strncpy(tmp, c->cid.cid_name, sizeof(tmp) - 1);
+			else if (num)
+				strncpy(tmp, num, sizeof(tmp) - 1);
+			else
+				strcpy(tmp, "");
+			strncpy(cdr->clid, tmp, sizeof(cdr->clid) - 1);
+			if (num)
 				strncpy(cdr->src, num, sizeof(cdr->src) - 1);
-			}
+			else
+				strcpy(cdr->src, "");
 		}
 		cdr = cdr->next;
 	}
@@ -277,7 +282,7 @@
 int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *c)
 {
 	char *chan;
-	char *num, *name;
+	char *num;
 	char tmp[AST_MAX_EXTENSION] = "";
 	while (cdr) {
 		if(!ast_cdr_has_flag(cdr,AST_CDR_FLAG_LOCKED)) {
@@ -286,20 +291,25 @@
 				ast_log(LOG_WARNING, "CDR already initialized on '%s'\n", chan); 
 			strncpy(cdr->channel, c->name, sizeof(cdr->channel) - 1);
 			/* Grab source from ANI or normal Caller*ID */
-			if (c->ani)
-				strncpy(tmp, c->ani, sizeof(tmp) - 1);
-			else if (c->callerid)
-				strncpy(tmp, c->callerid, sizeof(tmp) - 1);
-			if (c->callerid)
-				strncpy(cdr->clid, c->callerid, sizeof(cdr->clid) - 1);
-			name = NULL;
-			num = NULL;
-			ast_callerid_parse(tmp, &name, &num);
-			if (num) {
-				ast_shrink_phone_number(num);
-				strncpy(cdr->src, num, sizeof(cdr->src) - 1);
-			}
+			if (c->cid.cid_ani)
+				num = c->cid.cid_ani;
+			else
+				num = c->cid.cid_num;
 			
+			if (c->cid.cid_name && num)
+				snprintf(tmp, sizeof(tmp), "\"%s\" <%s>", c->cid.cid_name, num);
+			else if (c->cid.cid_name)
+				strncpy(tmp, c->cid.cid_name, sizeof(tmp) - 1);
+			else if (num)
+				strncpy(tmp, num, sizeof(tmp) - 1);
+			else
+				strcpy(tmp, "");
+			strncpy(cdr->clid, tmp, sizeof(cdr->clid) - 1);
+			if (num)
+				strncpy(cdr->src, num, sizeof(cdr->src) - 1);
+			else
+				strcpy(cdr->src, "");
+
 			if (c->_state == AST_STATE_UP)
 				cdr->disposition = AST_CDR_ANSWERED;
 			else
@@ -419,26 +429,31 @@
 int ast_cdr_update(struct ast_channel *c)
 {
 	struct ast_cdr *cdr = c->cdr;
-	char *name, *num;
+	char *num;
 	char tmp[AST_MAX_EXTENSION] = "";
 	/* Grab source from ANI or normal Caller*ID */
 	while (cdr) {
 		if(!ast_cdr_has_flag(cdr,AST_CDR_FLAG_LOCKED)) {
-			if (c->ani)
-				strncpy(tmp, c->ani, sizeof(tmp) - 1);
-			else if (c->callerid && !ast_strlen_zero(c->callerid))
-				strncpy(tmp, c->callerid, sizeof(tmp) - 1);
-			if (c->callerid && !ast_strlen_zero(c->callerid))
-				strncpy(cdr->clid, c->callerid, sizeof(cdr->clid) - 1);
+			/* Grab source from ANI or normal Caller*ID */
+			if (c->cid.cid_ani)
+				num = c->cid.cid_ani;
 			else
-				cdr->clid[0] = '\0';
-			name = NULL;
-			num = NULL;
-			ast_callerid_parse(tmp, &name, &num);
-			if (num) {
-				ast_shrink_phone_number(num);
+				num = c->cid.cid_num;
+			
+			if (c->cid.cid_name && num)
+				snprintf(tmp, sizeof(tmp), "\"%s\" <%s>", c->cid.cid_name, num);
+			else if (c->cid.cid_name)
+				strncpy(tmp, c->cid.cid_name, sizeof(tmp) - 1);
+			else if (num)
+				strncpy(tmp, num, sizeof(tmp) - 1);
+			else
+				strcpy(tmp, "");
+			strncpy(cdr->clid, tmp, sizeof(cdr->clid) - 1);
+			if (num)
 				strncpy(cdr->src, num, sizeof(cdr->src) - 1);
-			}
+			else
+				strcpy(cdr->src, "");
+
 			/* Copy account code et-al */	
 			strncpy(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode) - 1);
 			/* Destination information */

Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- channel.c	15 Sep 2004 14:12:45 -0000	1.139
+++ channel.c	2 Oct 2004 00:58:31 -0000	1.140
@@ -558,6 +558,20 @@
 	return 0;
 }
 
+static void free_cid(struct ast_callerid *cid)
+{
+	if (cid->cid_dnid)
+		free(cid->cid_dnid);
+	if (cid->cid_num)
+		free(cid->cid_num);	
+	if (cid->cid_name)
+		free(cid->cid_name);	
+	if (cid->cid_ani)
+		free(cid->cid_ani);
+	if (cid->cid_rdnis)
+		free(cid->cid_rdnis);
+}
+
 void ast_channel_free(struct ast_channel *chan)
 {
 	struct ast_channel *last=NULL, *cur;
@@ -607,14 +621,7 @@
 		ast_translator_free_path(chan->pvt->writetrans);
 	if (chan->pbx) 
 		ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
-	if (chan->dnid)
-		free(chan->dnid);
-	if (chan->callerid)
-		free(chan->callerid);	
-	if (chan->ani)
-		free(chan->ani);
-	if (chan->rdnis)
-		free(chan->rdnis);
+	free_cid(&chan->cid);
 	ast_mutex_destroy(&chan->lock);
 	/* Close pipes if appropriate */
 	if ((fd = chan->pvt->alertpipe[0]) > -1)
@@ -1743,7 +1750,7 @@
 	return 0;
 }
 
-struct ast_channel *__ast_request_and_dial(char *type, int format, void *data, int timeout, int *outstate, char *callerid, struct outgoing_helper *oh)
+struct ast_channel *__ast_request_and_dial(char *type, int format, void *data, int timeout, int *outstate, char *cid_num, char *cid_name, struct outgoing_helper *oh)
 {
 	int state = 0;
 	struct ast_channel *chan;
@@ -1764,13 +1771,11 @@
 			while( (var = strtok_r(NULL, "|", &tmp)) ) {
 				pbx_builtin_setvar( chan, var );
 			} /* /JDG */
-			if (oh->callerid && *oh->callerid)
-				ast_set_callerid(chan, oh->callerid, 1);
+			ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
 			if (oh->account && *oh->account)
 				ast_cdr_setaccount(chan, oh->account);
 		}
-		if (callerid && !ast_strlen_zero(callerid))
-			ast_set_callerid(chan, callerid, 1);
+		ast_set_callerid(chan, cid_num, cid_name, cid_num);
 
 		if (!ast_call(chan, data, 0)) {
 			while(timeout && (chan->_state != AST_STATE_UP)) {
@@ -1853,9 +1858,9 @@
 	return chan;
 }
 
-struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int timeout, int *outstate, char *callerid)
+struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int timeout, int *outstate, char *cidnum, char *cidname)
 {
-	return __ast_request_and_dial(type, format, data, timeout, outstate, callerid, NULL);
+	return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL);
 }
 
 struct ast_channel *ast_request(char *type, int format, void *data)
@@ -1889,8 +1894,9 @@
 					"Channel: %s\r\n"
 					"State: %s\r\n"
 					"Callerid: %s\r\n"
+					"CalleridName: %s\r\n"
 					"Uniqueid: %s\r\n",
-					c->name, ast_state2str(c->_state), c->callerid ? c->callerid : "<unknown>", c->uniqueid);
+					c->name, ast_state2str(c->_state), c->cid.cid_num ? c->cid.cid_num : "<unknown>", c->cid.cid_name ? c->cid.cid_name : "<unknown>",c->uniqueid);
 				}
 			}
 			return c;
@@ -2194,10 +2200,10 @@
 	int x,i;
 	int res=0;
 	int origstate;
-	char *tmp;
 	struct ast_var_t *varptr;
 	struct ast_frame *cur, *prev;
 	struct ast_channel_pvt *p;
+	struct ast_callerid tmpcid;
 	struct ast_channel *clone = original->masq;
 	int rformat = original->readformat;
 	int wformat = original->writeformat;
@@ -2336,16 +2342,11 @@
 	/* Stream stuff stays the same */
 	/* Keep the original state.  The fixup code will need to work with it most likely */
 
-	/* dnid and callerid change to become the new, HOWEVER, we also link the original's
-	   fields back into the defunct 'clone' so that they will be freed when
-	   ast_frfree is eventually called */
-	tmp = original->dnid;
-	original->dnid = clone->dnid;
-	clone->dnid = tmp;
-	
-	tmp = original->callerid;
-	original->callerid = clone->callerid;
-	clone->callerid = tmp;
+	/* Just swap the whole structures, nevermind the allocations, they'll work themselves
+	   out. */
+	tmpcid = original->cid;
+	original->cid = clone->cid;
+	clone->cid = tmpcid;
 	
 	/* Restore original timing file descriptor */
 	original->fds[AST_MAX_FDS - 2] = original->timingfd;
@@ -2400,29 +2401,43 @@
 	return 0;
 }
 
-void ast_set_callerid(struct ast_channel *chan, char *callerid, int anitoo)
+void ast_set_callerid(struct ast_channel *chan, char *callerid, char *calleridname, char *ani)
 {
-	if (chan->callerid)
-		free(chan->callerid);
-	if (anitoo && chan->ani)
-		free(chan->ani);
 	if (callerid) {
-		chan->callerid = strdup(callerid);
-		if (anitoo)
-			chan->ani = strdup(callerid);
-	} else {
-		chan->callerid = NULL;
-		if (anitoo)
-			chan->ani = NULL;
+		if (chan->cid.cid_num)
+			free(chan->cid.cid_num);
+		if (ast_strlen_zero(callerid))
+			chan->cid.cid_num = NULL;
+		else
+			chan->cid.cid_num = strdup(callerid);
+	}
+	if (calleridname) {
+		if (chan->cid.cid_name)
+			free(chan->cid.cid_name);
+		if (ast_strlen_zero(calleridname))
+			chan->cid.cid_name = NULL;
+		else
+			chan->cid.cid_name = strdup(calleridname);
+	}
+	if (ani) {
+		if (chan->cid.cid_ani)
+			free(chan->cid.cid_ani);
+		if (ast_strlen_zero(ani))
+			chan->cid.cid_ani = NULL;
+		else
+			chan->cid.cid_ani = strdup(ani);
 	}
 	if (chan->cdr)
 		ast_cdr_setcid(chan->cdr, chan);
 	manager_event(EVENT_FLAG_CALL, "Newcallerid", 
 				"Channel: %s\r\n"
 				"Callerid: %s\r\n"
+				"CalleridName: %s\r\n"
 				"Uniqueid: %s\r\n",
-				chan->name, chan->callerid ? 
-				chan->callerid : "<Unknown>",
+				chan->name, chan->cid.cid_num ? 
+				chan->cid.cid_num : "<Unknown>",
+				chan->cid.cid_name ? 
+				chan->cid.cid_name : "<Unknown>",
 				chan->uniqueid);
 }
 
@@ -2437,15 +2452,23 @@
 			"Channel: %s\r\n"
 			"State: %s\r\n"
 			"Callerid: %s\r\n"
+			"CalleridName: %s\r\n"
 			"Uniqueid: %s\r\n",
-			chan->name, ast_state2str(chan->_state), chan->callerid ? chan->callerid : "<unknown>", chan->uniqueid);
+			chan->name, ast_state2str(chan->_state), 
+			chan->cid.cid_num ? chan->cid.cid_num : "<unknown>", 
+			chan->cid.cid_name ? chan->cid.cid_name : "<unknown>", 
+			chan->uniqueid);
 		} else {
 			manager_event(EVENT_FLAG_CALL, "Newstate", 
 				"Channel: %s\r\n"
 				"State: %s\r\n"
 				"Callerid: %s\r\n"
+				"CalleridName: %s\r\n"
 				"Uniqueid: %s\r\n",
-				chan->name, ast_state2str(chan->_state), chan->callerid ? chan->callerid : "<unknown>", chan->uniqueid);
+				chan->name, ast_state2str(chan->_state), 
+				chan->cid.cid_num ? chan->cid.cid_num : "<unknown>", 
+				chan->cid.cid_name ? chan->cid.cid_name : "<unknown>", 
+				chan->uniqueid);
 		}
 	}
 	return 0;

Index: cli.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cli.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- cli.c	13 Sep 2004 18:19:15 -0000	1.53
+++ cli.c	2 Oct 2004 00:58:31 -0000	1.54
@@ -370,7 +370,7 @@
 		if(concise)
 			ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
 					c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "" ): "",
-					(c->callerid && !ast_strlen_zero(c->callerid)) ? c->callerid : "",
+					(c->cid.cid_num && !ast_strlen_zero(c->cid.cid_num)) ? c->cid.cid_num : "",
 					(c->accountcode && !ast_strlen_zero(c->accountcode)) ? c->accountcode : "",c->amaflags);
 		else
 			ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
@@ -590,6 +590,7 @@
 	"           Type: %s\n"
 	"       UniqueID: %s\n"
 	"      Caller ID: %s\n"
+	" Caller ID Name: %s\n"
 	"    DNID Digits: %s\n"
 	"          State: %s (%d)\n"
 	"          Rings: %d\n"
@@ -612,8 +613,9 @@
 	"          Stack: %d\n"
 	"    Blocking in: %s\n",
 	c->name, c->type, c->uniqueid,
-	(c->callerid ? c->callerid : "(N/A)"),
-	(c->dnid ? c->dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat,
+	(c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
+	(c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
+	(c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat,
 	c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
 	c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
 	hour, min, sec, 

Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- manager.c	22 Sep 2004 14:11:44 -0000	1.74
+++ manager.c	2 Oct 2004 00:58:31 -0000	1.75
@@ -29,6 +29,7 @@
 #include <asterisk/file.h>
 #include <asterisk/manager.h>
 #include <asterisk/config.h>
+#include <asterisk/callerid.h>
 #include <asterisk/lock.h>
 #include <asterisk/logger.h>
 #include <asterisk/options.h>
@@ -46,7 +47,8 @@
 	int timeout;
 	char app[256];
 	char appdata[256];
-	char callerid[256];
+	char cid_name[256];
+	char cid_num[256];
 	char variable[256];
 	char account[256];
 	char context[256];
@@ -693,6 +695,7 @@
 			"Event: Status\r\n"
 			"Channel: %s\r\n"
 			"CallerID: %s\r\n"
+			"CallerIDName: %s\r\n"
 			"Account: %s\r\n"
 			"State: %s\r\n"
 			"Context: %s\r\n"
@@ -703,7 +706,9 @@
 			"Uniqueid: %s\r\n"
 			"%s"
 			"\r\n",
-			c->name, c->callerid ? c->callerid : "<unknown>", 
+			c->name, 
+			c->cid.cid_num ? c->cid.cid_num : "<unknown>", 
+			c->cid.cid_name ? c->cid.cid_name : "<unknown>", 
 			c->accountcode,
 			ast_state2str(c->_state), c->context,
 			c->exten, c->priority, (long)elapsed_seconds, bridge, c->uniqueid, idText);
@@ -712,13 +717,16 @@
 			"Event: Status\r\n"
 			"Channel: %s\r\n"
 			"CallerID: %s\r\n"
+			"CallerIDName: %s\r\n"
 			"Account: %s\r\n"
 			"State: %s\r\n"
 			"%s"
 			"Uniqueid: %s\r\n"
 			"%s"
 			"\r\n",
-			c->name, c->callerid ? c->callerid : "<unknown>", 
+			c->name, 
+			c->cid.cid_num ? c->cid.cid_num : "<unknown>", 
+			c->cid.cid_name ? c->cid.cid_name : "<unknown>", 
 			c->accountcode,
 			ast_state2str(c->_state), bridge, c->uniqueid, idText);
 		}
@@ -810,9 +818,15 @@
 	int res;
 	int reason = 0;
 	if (!ast_strlen_zero(in->app)) {
-		res = ast_pbx_outgoing_app(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->app, in->appdata, &reason, 1, !ast_strlen_zero(in->callerid) ? in->callerid : NULL, in->variable, in->account);
+		res = ast_pbx_outgoing_app(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->app, in->appdata, &reason, 1, 
+			!ast_strlen_zero(in->cid_num) ? in->cid_num : NULL, 
+			!ast_strlen_zero(in->cid_name) ? in->cid_name : NULL,
+			in->variable, in->account);
 	} else {
-		res = ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, !ast_strlen_zero(in->callerid) ? in->callerid : NULL, in->variable, in->account);
+		res = ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, 
+			!ast_strlen_zero(in->cid_num) ? in->cid_num : NULL, 
+			!ast_strlen_zero(in->cid_name) ? in->cid_name : NULL,
+			in->variable, in->account);
 	}   
 	if (!res)
 		manager_event(EVENT_FLAG_CALL,
@@ -859,18 +873,21 @@
 	char *priority = astman_get_header(m, "Priority");
 	char *timeout = astman_get_header(m, "Timeout");
 	char *callerid = astman_get_header(m, "CallerID");
-    	char *variable = astman_get_header(m, "Variable");
-    	char *account = astman_get_header(m, "Account");
+    char *variable = astman_get_header(m, "Variable");
+    char *account = astman_get_header(m, "Account");
 	char *app = astman_get_header(m, "Application");
 	char *appdata = astman_get_header(m, "Data");
 	char *async = astman_get_header(m, "Async");
 	char *id = astman_get_header(m, "ActionID");
 	char *tech, *data;
+	char *l=NULL, *n=NULL;
 	int pi = 0;
 	int res;
 	int to = 30000;
 	int reason = 0;
 	char tmp[256];
+	char tmp2[256]="";
+	
 	pthread_t th;
 	pthread_attr_t attr;
 	if (!name) {
@@ -894,6 +911,17 @@
 	}
 	*data = '\0';
 	data++;
+	strncpy(tmp2, callerid, sizeof(tmp2) - 1);
+	ast_callerid_parse(tmp2, &n, &l);
+	if (n) {
+		if (ast_strlen_zero(n))
+			n = NULL;
+	}
+	if (l) {
+		ast_shrink_phone_number(l);
+		if (ast_strlen_zero(l))
+			l = NULL;
+	}
 	if (ast_true(async)) {
 		struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper));
 		if (!fast) {
@@ -906,7 +934,10 @@
    			strncpy(fast->data, data, sizeof(fast->data) - 1);
 			strncpy(fast->app, app, sizeof(fast->app) - 1);
 			strncpy(fast->appdata, appdata, sizeof(fast->appdata) - 1);
-			strncpy(fast->callerid, callerid, sizeof(fast->callerid) - 1);
+			if (l)
+				strncpy(fast->cid_num, l, sizeof(fast->cid_num) - 1);
+			if (n)
+				strncpy(fast->cid_name, n, sizeof(fast->cid_name) - 1);
 			strncpy(fast->variable, variable, sizeof(fast->variable) - 1);
 			strncpy(fast->account, account, sizeof(fast->account) - 1);
 			strncpy(fast->context, context, sizeof(fast->context) - 1);
@@ -922,10 +953,10 @@
 			}
 		}
 	} else if (!ast_strlen_zero(app)) {
-        	res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 0, !ast_strlen_zero(callerid) ? callerid : NULL, variable, account);
+        	res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 0, l, n, variable, account);
     	} else {
 		if (exten && context && pi)
-	        	res = ast_pbx_outgoing_exten(tech, AST_FORMAT_SLINEAR, data, to, context, exten, pi, &reason, 0, !ast_strlen_zero(callerid) ? callerid : NULL, variable, account);
+	        	res = ast_pbx_outgoing_exten(tech, AST_FORMAT_SLINEAR, data, to, context, exten, pi, &reason, 0, l, n, variable, account);
 		else {
 			astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
 			return 0;

Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -d -r1.154 -r1.155
--- pbx.c	24 Sep 2004 21:32:56 -0000	1.154
+++ pbx.c	2 Oct 2004 00:58:31 -0000	1.155
@@ -3,7 +3,7 @@
  *
  * Core PBX routines.
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
  *
  * Mark Spencer <markster at digium.com>
  *
@@ -696,9 +696,7 @@
 
 static int matchcid(char *cidpattern, char *callerid)
 {
-	char tmp[AST_MAX_EXTENSION];
 	int failresult;
-	char *name, *num;
 	
 	/* If the Caller*ID pattern is empty, then we're matching NO Caller*ID, so
 	   failing to get a number should count as a match, otherwise not */
@@ -712,15 +710,7 @@
 	if (!callerid)
 		return failresult;
 
-	/* Copy original Caller*ID */
-	strncpy(tmp, callerid, sizeof(tmp)-1);
-	/* Parse Number */
-	if (ast_callerid_parse(tmp, &name, &num)) 
-		return failresult;
-	if (!num)
-		return failresult;
-	ast_shrink_phone_number(num);
-	return ast_extension_match(cidpattern, num);
+	return ast_extension_match(cidpattern, callerid);
 }
 
 static struct ast_exten *pbx_find_extension(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, int action, char *incstack[], int *stacklen, int *status, struct ast_switch **swo, char **data)
@@ -824,7 +814,6 @@
 	struct tm brokentime;
 	int offset,offset2;
 	struct ast_var_t *variables;
-	char *name, *num; /* for callerid name + num variables */
 	struct varshead *headp=NULL;
 
 	if (c) 
@@ -876,31 +865,39 @@
 			*ret+=strlen(*ret)+offset;
 		(*ret)[offset2] = '\0';
 	} else if (c && !strcmp(var, "CALLERIDNUM")) {
-		if (c->callerid)
-			strncpy(workspace, c->callerid, workspacelen - 1);
-		ast_callerid_parse(workspace, &name, &num);
-		if (num) {
-			ast_shrink_phone_number(num);
-			*ret = num;
+		if (c->cid.cid_num) {
+			strncpy(workspace, c->cid.cid_num, workspacelen - 1);
+			*ret = workspace;
 		} else
+			*ret = NULL;
+	} else if (c && !strcmp(var, "CALLERANI")) {
+		if (c->cid.cid_ani) {
+			strncpy(workspace, c->cid.cid_ani, workspacelen - 1);
 			*ret = workspace;
+		} else
+			*ret = NULL;
 	} else if (c && !strcmp(var, "CALLERIDNAME")) {
-		if (c->callerid)
-			strncpy(workspace, c->callerid, workspacelen - 1);
-		ast_callerid_parse(workspace, &name, &num);
-		if (name)
-			*ret = name;
-		else
+		if (c->cid.cid_name) {
+			strncpy(workspace, c->cid.cid_name, workspacelen - 1);
 			*ret = workspace;
+		} else
+			*ret = NULL;
 	} else if (c && !strcmp(var, "CALLERID")) {
-		if (c->callerid) {
-			strncpy(workspace, c->callerid, workspacelen - 1);
+		if (c->cid.cid_num) {
+			if (c->cid.cid_name) {
+				snprintf(workspace, workspacelen, "\"%s\" <%s>", c->cid.cid_name, c->cid.cid_num);
+			} else {
+				strncpy(workspace, c->cid.cid_num, workspacelen - 1);
+			}
 			*ret = workspace;
-		} else 
+		} else if (c->cid.cid_name) {
+			strncpy(workspace, c->cid.cid_name, workspacelen - 1);
+			*ret = workspace;
+		} else
 			*ret = NULL;
 	} else if (c && !strcmp(var, "DNID")) {
-		if (c->dnid) {
-			strncpy(workspace, c->dnid, workspacelen - 1);
+		if (c->cid.cid_dnid) {
+			strncpy(workspace, c->cid.cid_dnid, workspacelen - 1);
 			*ret = workspace;
 		} else
 			*ret = NULL;
@@ -923,8 +920,8 @@
 		*ret = workspace;
 		ast_log(LOG_WARNING, "The use of 'EXTEN-foo' has been deprecated in favor of 'EXTEN:foo'\n");
 	} else if (c && !strcmp(var, "RDNIS")) {
-		if (c->rdnis) {
-			strncpy(workspace, c->rdnis, workspacelen - 1);
+		if (c->cid.cid_rdnis) {
+			strncpy(workspace, c->cid.cid_rdnis, workspacelen - 1);
 			*ret = workspace;
 		} else
 			*ret = NULL;
@@ -935,7 +932,16 @@
 		snprintf(workspace, workspacelen, "%d", c->priority);
 		*ret = workspace;
 	} else if (c && !strcmp(var, "CALLINGPRES")) {
-		snprintf(workspace, workspacelen, "%d", c->callingpres);
+		snprintf(workspace, workspacelen, "%d", c->cid.cid_pres);
+		*ret = workspace;
+	} else if (c && !strcmp(var, "CALLINGANI2")) {
+		snprintf(workspace, workspacelen, "%d", c->cid.cid_ani2);
+		*ret = workspace;
+	} else if (c && !strcmp(var, "CALLINGTON")) {
+		snprintf(workspace, workspacelen, "%d", c->cid.cid_ton);
+		*ret = workspace;
+	} else if (c && !strcmp(var, "CALLINGTNS")) {
+		snprintf(workspace, workspacelen, "%d", c->cid.cid_tns);
 		*ret = workspace;
 	} else if (c && !strcmp(var, "CHANNEL")) {
 		strncpy(workspace, c->name, workspacelen - 1);
@@ -1793,12 +1799,12 @@
 	c->pbx->dtimeout = 5;
 
 	/* Start by trying whatever the channel is set to */
-	if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
+	if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
 		/* JK02: If not successfull fall back to 's' */
 		if (option_verbose > 1)
 			ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
 		strncpy(c->exten, "s", sizeof(c->exten)-1);
-		if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
+		if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
 			/* JK02: And finally back to default if everything else failed */
 			if (option_verbose > 1)
 				ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
@@ -1811,9 +1817,9 @@
 	for(;;) {
 		pos = 0;
 		digit = 0;
-		while(ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
+		while(ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
 			memset(exten, 0, sizeof(exten));
-			if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->callerid))) {
+			if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
 				/* Something bad happened, or a hangup has been requested. */
 				if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
 					(res == '*') || (res == '#')) {
@@ -1851,7 +1857,7 @@
 					goto out;
 				}
 			}
-			if ((c->_softhangup == AST_SOFTHANGUP_TIMEOUT) && (ast_exists_extension(c,c->context,"T",1,c->callerid))) {
+			if ((c->_softhangup == AST_SOFTHANGUP_TIMEOUT) && (ast_exists_extension(c,c->context,"T",1,c->cid.cid_num))) {
 				strncpy(c->exten,"T",sizeof(c->exten) - 1);
 				/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
 				c->whentohangup = 0;
@@ -1865,9 +1871,9 @@
 			firstpass = 0;
 			c->priority++;
 		}
-		if (!ast_exists_extension(c, c->context, c->exten, 1, c->callerid)) {
+		if (!ast_exists_extension(c, c->context, c->exten, 1, c->cid.cid_num)) {
 			/* It's not a valid extension anymore */
-			if (ast_exists_extension(c, c->context, "i", 1, c->callerid)) {
+			if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
 				if (option_verbose > 2)
 					ast_verbose(VERBOSE_PREFIX_3 "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
 				pbx_builtin_setvar_helper(c, "INVALID_EXTEN", c->exten);
@@ -1887,7 +1893,7 @@
 				waittime = c->pbx->dtimeout;
 			else
 				waittime = c->pbx->rtimeout;
-			while (ast_matchmore_extension(c, c->context, exten, 1, c->callerid)) {
+			while (ast_matchmore_extension(c, c->context, exten, 1, c->cid.cid_num)) {
 				/* As long as we're willing to wait, and as long as it's not defined, 
 				   keep reading digits until we can't possibly get a right answer anymore.  */
 				digit = ast_waitfordigit(c, waittime * 1000);
@@ -1904,7 +1910,7 @@
 					waittime = c->pbx->dtimeout;
 				}
 			}
-			if (ast_exists_extension(c, c->context, exten, 1, c->callerid)) {
+			if (ast_exists_extension(c, c->context, exten, 1, c->cid.cid_num)) {
 				/* Prepare the next cycle */
 				strncpy(c->exten, exten, sizeof(c->exten)-1);
 				c->priority = 1;
@@ -1912,7 +1918,7 @@
 				/* No such extension */
 				if (!ast_strlen_zero(exten)) {
 					/* An invalid extension */
-					if (ast_exists_extension(c, c->context, "i", 1, c->callerid)) {
+					if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
 						if (option_verbose > 2)
 							ast_verbose( VERBOSE_PREFIX_3 "Invalid extension '%s' in context '%s' on %s\n", exten, c->context, c->name);
 						pbx_builtin_setvar_helper(c, "INVALID_EXTEN", exten);
@@ -1924,7 +1930,7 @@
 					}
 				} else {
 					/* A simple timeout */
-					if (ast_exists_extension(c, c->context, "t", 1, c->callerid)) {
+					if (ast_exists_extension(c, c->context, "t", 1, c->cid.cid_num)) {
 						if (option_verbose > 2)
 							ast_verbose( VERBOSE_PREFIX_3 "Timeout on %s\n", c->name);
 						strncpy(c->exten, "t", sizeof(c->exten)-1);
@@ -1945,12 +1951,12 @@
 	if (firstpass) 
 		ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name);
 out:
-	if ((res != AST_PBX_KEEPALIVE) && ast_exists_extension(c, c->context, "h", 1, c->callerid)) {
+	if ((res != AST_PBX_KEEPALIVE) && ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) {
 		c->exten[0] = 'h';
 		c->exten[1] = '\0';
 		c->priority = 1;
-		while(ast_exists_extension(c, c->context, c->exten, c->priority, c->callerid)) {
-			if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->callerid))) {
+		while(ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
+			if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
 				/* Something bad happened, or a hangup has been requested. */
 				if (option_debug)
 					ast_log(LOG_DEBUG, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
@@ -4033,7 +4039,7 @@
 	return NULL;
 }
 
-int ast_pbx_outgoing_exten(char *type, int format, void *data, int timeout, char *context, char *exten, int priority, int *reason, int sync, char *callerid, char *variable, char *account)
+int ast_pbx_outgoing_exten(char *type, int format, void *data, int timeout, char *context, char *exten, int priority, int *reason, int sync, char *cid_num, char *cid_name, char *variable, char *account)
 {
 	struct ast_channel *chan;
 	struct async_stat *as;
@@ -4044,7 +4050,7 @@
 		
 	if (sync) {
 		LOAD_OH(oh);
-		chan = __ast_request_and_dial(type, format, data, timeout, reason, callerid, &oh);
+		chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
 		if (chan) {
 			pbx_builtin_setaccount(chan, account);
 			if (chan->_state == AST_STATE_UP) {
@@ -4099,7 +4105,7 @@
 		if (!as)
 			return -1;
 		memset(as, 0, sizeof(struct async_stat));
-		chan = ast_request_and_dial(type, format, data, timeout, reason, callerid);
+		chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
 		if (!chan) {
 			free(as);
 			return -1;
@@ -4151,7 +4157,7 @@
 	return NULL;
 }
 
-int ast_pbx_outgoing_app(char *type, int format, void *data, int timeout, char *app, char *appdata, int *reason, int sync, char *callerid, char *variable, char *account)
+int ast_pbx_outgoing_app(char *type, int format, void *data, int timeout, char *app, char *appdata, int *reason, int sync, char *cid_num, char *cid_name, char *variable, char *account)
 {
 	struct ast_channel *chan;
 	struct async_stat *as;
@@ -4163,7 +4169,7 @@
 	if (!app || ast_strlen_zero(app))
 		return -1;
 	if (sync) {
-		chan = ast_request_and_dial(type, format, data, timeout, reason, callerid);
+		chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
 		if (chan) {
 			pbx_builtin_setaccount(chan, account);
 			if (variable) {
@@ -4209,7 +4215,7 @@
 		if (!as)
 			return -1;
 		memset(as, 0, sizeof(struct async_stat));
-		chan = ast_request_and_dial(type, format, data, timeout, reason, callerid);
+		chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
 		if (!chan) {
 			free(as);
 			return -1;




More information about the svn-commits mailing list