[Asterisk-cvs] asterisk/channels chan_agent.c, 1.81, 1.82 chan_iax2.c, 1.189, 1.190 chan_local.c, 1.32, 1.33 chan_mgcp.c, 1.79, 1.80 chan_modem.c, 1.27, 1.28 chan_modem_bestdata.c, 1.12, 1.13 chan_modem_i4l.c, 1.17, 1.18 chan_oss.c, 1.33, 1.34 chan_phone.c, 1.33, 1.34 chan_sip.c, 1.511, 1.512 chan_skinny.c, 1.54, 1.55 chan_zap.c, 1.346, 1.347

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


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

Modified Files:
	chan_agent.c chan_iax2.c chan_local.c chan_mgcp.c chan_modem.c 
	chan_modem_bestdata.c chan_modem_i4l.c chan_oss.c chan_phone.c 
	chan_sip.c chan_skinny.c chan_zap.c 
Log Message:
Huge callerid rework (might break H.323, others)


Index: chan_agent.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_agent.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- chan_agent.c	11 Aug 2004 19:02:46 -0000	1.81
+++ chan_agent.c	2 Oct 2004 00:58:31 -0000	1.82
@@ -457,12 +457,18 @@
 		/* Call on this agent */
 		if (option_verbose > 2)
 			ast_verbose(VERBOSE_PREFIX_3 "outgoing agentcall, to agent '%s', on '%s'\n", p->agent, p->chan->name);
-		if (p->chan->callerid)
-			free(p->chan->callerid);
-		if (ast->callerid)
-			p->chan->callerid = strdup(ast->callerid);
+		if (p->chan->cid.cid_num)
+			free(p->chan->cid.cid_num);
+		if (ast->cid.cid_num)
+			p->chan->cid.cid_num = strdup(ast->cid.cid_num);
 		else
-			p->chan->callerid = NULL;
+			p->chan->cid.cid_num = NULL;
+		if (p->chan->cid.cid_name)
+			free(p->chan->cid.cid_name);
+		if (ast->cid.cid_name)
+			p->chan->cid.cid_name = strdup(ast->cid.cid_name);
+		else
+			p->chan->cid.cid_name = NULL;
 		res = ast_call(p->chan, p->loginchan, 0);
 		CLEANUP(ast,p);
 		ast_mutex_unlock(&p->lock);
@@ -1290,9 +1296,9 @@
 									filename = "agent-loggedoff";
 								p->acknowledged = 0;
 								/* store/clear the global variable that stores agentid based on the callerid */
-								if (chan->callerid) {
+								if (chan->cid.cid_num) {
 									char agentvar[AST_MAX_BUF];
-									snprintf(agentvar, sizeof(agentvar), "%s_%s",GETAGENTBYCALLERID, chan->callerid);
+									snprintf(agentvar, sizeof(agentvar), "%s_%s",GETAGENTBYCALLERID, chan->cid.cid_num);
 									if (ast_strlen_zero(p->loginchan))
 										pbx_builtin_setvar_helper(NULL, agentvar, NULL);
 									else
@@ -1516,9 +1522,9 @@
 		if (strchr(data, 'n'))
 			nowarnings = 1;
 	}
-	if (chan->callerid) {
+	if (chan->cid.cid_num) {
 		char agentvar[AST_MAX_BUF];
-		snprintf(agentvar, sizeof(agentvar), "%s_%s", GETAGENTBYCALLERID, chan->callerid);
+		snprintf(agentvar, sizeof(agentvar), "%s_%s", GETAGENTBYCALLERID, chan->cid.cid_num);
 		if ((tmp = pbx_builtin_getvar_helper(NULL, agentvar))) {
 			struct agent_pvt *p = agents;
 			strncpy(agent, tmp, sizeof(agent) - 1);
@@ -1544,7 +1550,7 @@
 	}
 	/* check if there is n + 101 priority */
 	if (res) {
-	       if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid)) {
+	       if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) {
 			chan->priority+=100;
 			ast_verbose(VERBOSE_PREFIX_3 "Going to %d priority because there is no callerid or the agentid cannot be found.\n",chan->priority);
 	       }

Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- chan_iax2.c	30 Sep 2004 15:30:05 -0000	1.189
+++ chan_iax2.c	2 Oct 2004 00:58:31 -0000	1.190
@@ -207,7 +207,8 @@
 	int temponly;
 	int capability;
 	int trunk;
-	char callerid[AST_MAX_EXTENSION];
+	char cid_num[AST_MAX_EXTENSION];
+	char cid_name[AST_MAX_EXTENSION];
 	struct ast_ha *ha;
 	struct iax2_context *contexts;
 	struct iax2_user *next;
@@ -220,7 +221,7 @@
 	char username[80];		
 	char secret[80];
 	char outkey[80];		/* What key we use to talk to this peer */
-	char context[AST_MAX_EXTENSION];	/* Default context (for transfer really) */
+	char context[AST_MAX_EXTENSION];	/* For transfers only */
 	char regexten[AST_MAX_EXTENSION];	/* Extension to register (if regcontext is used) */
 	char peercontext[AST_MAX_EXTENSION];	/* Context to pass to peer */
 	char mailbox[AST_MAX_EXTENSION];	/* Mailbox */
@@ -236,7 +237,8 @@
 
 	int hascallerid;
 	/* Suggested caller id if registering */
-	char callerid[AST_MAX_EXTENSION];
+	char cid_num[AST_MAX_EXTENSION];	/* Default context (for transfer really) */
+	char cid_name[AST_MAX_EXTENSION];	/* Default context (for transfer really) */
 	/* Whether or not to send ANI */
 	int sendani;
 	int expire;						/* Schedule entry for expirey */
@@ -410,7 +412,8 @@
 	/* Default Context */
 	char context[80];
 	/* Caller ID if available */
-	char callerid[80];
+	char cid_num[80];
+	char cid_name[80];
 	/* Hidden Caller ID (i.e. ANI) if appropriate */
 	char ani[80];
 	/* Whether or not ani should be transmitted in addition to Caller*ID */
@@ -2253,7 +2256,6 @@
 	char *username;
 	char *secret = NULL;
 	char *hname;
-	char cid[256] = "";
 	char *l=NULL, *n=NULL;
 	struct iax_ie_data ied;
 	char myrdest [5] = "s";
@@ -2314,12 +2316,8 @@
 	if (portno) {
 		sin.sin_port = htons(atoi(portno));
 	}
-	if (c->callerid) {
-		strncpy(cid, c->callerid, sizeof(cid) - 1);
-		ast_callerid_parse(cid, &n, &l);
-		if (l)
-			ast_shrink_phone_number(l);
-	}
+	l = c->cid.cid_num;
+	n = c->cid.cid_name;
 	/* Now build request */	
 	memset(&ied, 0, sizeof(ied));
 	/* On new call, first IE MUST be IAX version of caller */
@@ -2333,19 +2331,13 @@
 		iax_ie_append_str(&ied, IAX_IE_CALLING_NUMBER, l);
 	if (n)
 		iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, n);
-	if (iaxs[callno]->sendani && c->ani) {
-		l = n = NULL;
-		strncpy(cid, c->ani, sizeof(cid) - 1);
-		ast_callerid_parse(cid, &n, &l);
-		if (l) {
-			ast_shrink_phone_number(l);
-			iax_ie_append_str(&ied, IAX_IE_CALLING_ANI, l);
-		}
+	if (iaxs[callno]->sendani && c->cid.cid_ani) {
+		iax_ie_append_str(&ied, IAX_IE_CALLING_ANI, c->cid.cid_ani);
 	}
 	if (c->language && !ast_strlen_zero(c->language))
 		iax_ie_append_str(&ied, IAX_IE_LANGUAGE, c->language);
-	if (c->dnid && !ast_strlen_zero(c->dnid))
-		iax_ie_append_str(&ied, IAX_IE_DNID, c->dnid);
+	if (c->cid.cid_dnid && !ast_strlen_zero(c->cid.cid_dnid))
+		iax_ie_append_str(&ied, IAX_IE_DNID, c->cid.cid_dnid);
 	if (rcontext)
 		iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, rcontext);
 	else if (strlen(peercontext))
@@ -2727,14 +2719,16 @@
 		tmp->pvt->setoption = iax2_setoption;
 		tmp->pvt->bridge = iax2_bridge;
 		tmp->pvt->transfer = iax2_transfer;
-		if (!ast_strlen_zero(i->callerid))
-			tmp->callerid = strdup(i->callerid);
+		if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_num = strdup(i->cid_num);
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
 		if (!ast_strlen_zero(i->ani))
-			tmp->ani = strdup(i->ani);
+			tmp->cid.cid_ani = strdup(i->ani);
 		if (!ast_strlen_zero(i->language))
 			strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
 		if (!ast_strlen_zero(i->dnid))
-			tmp->dnid = strdup(i->dnid);
+			tmp->cid.cid_dnid = strdup(i->dnid);
 		if (!ast_strlen_zero(i->accountcode))
 			strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1);
 		if (i->amaflags)
@@ -3599,13 +3593,10 @@
 		return res;
 	if (ies->called_number)
 		strncpy(iaxs[callno]->exten, ies->called_number, sizeof(iaxs[callno]->exten) - 1);
-	if (ies->calling_number) {
-		if (ies->calling_name)
-			snprintf(iaxs[callno]->callerid, sizeof(iaxs[callno]->callerid), "\"%s\" <%s>", ies->calling_name, ies->calling_number);
-		else
-			strncpy(iaxs[callno]->callerid, ies->calling_number, sizeof(iaxs[callno]->callerid) - 1);
-	} else if (ies->calling_name)
-		strncpy(iaxs[callno]->callerid, ies->calling_name, sizeof(iaxs[callno]->callerid) - 1);
+	if (ies->calling_number) 
+		strncpy(iaxs[callno]->cid_num, ies->calling_number, sizeof(iaxs[callno]->cid_num) - 1);
+	if (ies->calling_name)
+		strncpy(iaxs[callno]->cid_name, ies->calling_name, sizeof(iaxs[callno]->cid_name) - 1);
 	if (ies->calling_ani)
 		strncpy(iaxs[callno]->ani, ies->calling_ani, sizeof(iaxs[callno]->ani) - 1);
 	if (ies->dnid)
@@ -3716,10 +3707,12 @@
 		/* And the permitted authentication methods */
 		iaxs[callno]->authmethods = user->authmethods;
 		/* If they have callerid, override the given caller id.  Always store the ANI */
-		if (!ast_strlen_zero(iaxs[callno]->callerid)) {
-			if (user->hascallerid)
-				strncpy(iaxs[callno]->callerid, user->callerid, sizeof(iaxs[callno]->callerid)-1);
-			strncpy(iaxs[callno]->ani, user->callerid, sizeof(iaxs[callno]->ani)-1);
+		if (!ast_strlen_zero(iaxs[callno]->cid_num) || !ast_strlen_zero(iaxs[callno]->cid_name)) {
+			if (user->hascallerid) {
+				strncpy(iaxs[callno]->cid_num, user->cid_num, sizeof(iaxs[callno]->cid_num)-1);
+				strncpy(iaxs[callno]->cid_name, user->cid_name, sizeof(iaxs[callno]->cid_name)-1);
+			}
+			strncpy(iaxs[callno]->ani, user->cid_num, sizeof(iaxs[callno]->ani)-1);
 		}
 		if (!ast_strlen_zero(user->accountcode))
 			strncpy(iaxs[callno]->accountcode, user->accountcode, sizeof(iaxs[callno]->accountcode)-1);
@@ -4464,8 +4457,10 @@
 				}
 				iax_ie_append_short(&ied, IAX_IE_MSGCOUNT, msgcount);
 			}
-			if (p->hascallerid)
-				iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, p->callerid);
+			if (p->hascallerid) {
+				iax_ie_append_str(&ied, IAX_IE_CALLING_NUMBER, p->cid_num);
+				iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, p->cid_name);
+			}
 		}
 		version = iax_check_version(devtype);
 		if (version) 
@@ -5399,7 +5394,7 @@
 				/* This might re-enter the IAX code and need the lock */
 				if (strcasecmp(iaxs[fr.callno]->exten, "TBD")) {
 					ast_mutex_unlock(&iaxsl[fr.callno]);
-					exists = ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->callerid);
+					exists = ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->cid_num);
 					ast_mutex_lock(&iaxsl[fr.callno]);
 				} else
 					exists = 0;
@@ -5467,10 +5462,10 @@
 					!(iaxs[fr.callno]->state & IAX_STATE_STARTED) && ies.called_number) {
 					if (iaxcompat) {
 						/* Spawn a thread for the lookup */
-						spawn_dp_lookup(fr.callno, iaxs[fr.callno]->context, ies.called_number, iaxs[fr.callno]->callerid);
+						spawn_dp_lookup(fr.callno, iaxs[fr.callno]->context, ies.called_number, iaxs[fr.callno]->cid_num);
 					} else {
 						/* Just look it up */
-						dp_lookup(fr.callno, iaxs[fr.callno]->context, ies.called_number, iaxs[fr.callno]->callerid, 1);
+						dp_lookup(fr.callno, iaxs[fr.callno]->context, ies.called_number, iaxs[fr.callno]->cid_num, 1);
 					}
 				}
 				break;
@@ -5695,7 +5690,7 @@
 				}
 				if (strcasecmp(iaxs[fr.callno]->exten, "TBD")) {
 					/* This might re-enter the IAX code and need the lock */
-					exists = ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->callerid);
+					exists = ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->cid_num);
 				} else
 					exists = 0;
 				if (strcmp(iaxs[fr.callno]->exten, "TBD") && !exists) {
@@ -5755,7 +5750,7 @@
 				if (iaxs[fr.callno]->state & IAX_STATE_TBD) {
 					iaxs[fr.callno]->state &= ~IAX_STATE_TBD;
 					strncpy(iaxs[fr.callno]->exten, ies.called_number ? ies.called_number : "s", sizeof(iaxs[fr.callno]->exten)-1);	
-					if (!ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->callerid)) {
+					if (!ast_exists_extension(NULL, iaxs[fr.callno]->context, iaxs[fr.callno]->exten, 1, iaxs[fr.callno]->cid_num)) {
 						if (authdebug)
 							ast_log(LOG_NOTICE, "Rejected dial attempt from %s, request '%s@%s' does not exist\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
 						memset(&ied0, 0, sizeof(ied0));
@@ -6486,7 +6481,8 @@
 				else
 					peer->capability &= ~format;
 			} else if (!strcasecmp(v->name, "callerid")) {
-				strncpy(peer->callerid, v->value, sizeof(peer->callerid)-1);
+				ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name),
+									peer->cid_num, sizeof(peer->cid_num));
 				peer->hascallerid=1;
 			} else if (!strcasecmp(v->name, "sendani")) {
 				peer->sendani = ast_true(v->value);
@@ -6604,7 +6600,7 @@
 			} else if (!strcasecmp(v->name, "secret")) {
 				strncpy(user->secret, v->value, sizeof(user->secret)-1);
 			} else if (!strcasecmp(v->name, "callerid")) {
-				strncpy(user->callerid, v->value, sizeof(user->callerid)-1);
+				ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
 				user->hascallerid=1;
 			} else if (!strcasecmp(v->name, "accountcode")) {
 				strncpy(user->accountcode, v->value, sizeof(user->accountcode)-1);

Index: chan_local.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_local.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- chan_local.c	12 Jul 2004 14:46:10 -0000	1.32
+++ chan_local.c	2 Oct 2004 00:58:31 -0000	1.33
@@ -239,18 +239,26 @@
 	int res;
 	
 	ast_mutex_lock(&p->lock);
-	if (p->owner->callerid)
-		p->chan->callerid = strdup(p->owner->callerid);
-	else
-		p->chan->callerid = NULL;
-	if (p->owner->rdnis)
-		p->chan->rdnis = strdup(p->owner->rdnis);
+	if (p->owner->cid.cid_num)
+		p->chan->cid.cid_num = strdup(p->owner->cid.cid_num);
+	else 
+		p->chan->cid.cid_num = NULL;
+
+	if (p->owner->cid.cid_name)
+		p->chan->cid.cid_name = strdup(p->owner->cid.cid_name);
+	else 
+		p->chan->cid.cid_name = NULL;
+
+	if (p->owner->cid.cid_rdnis)
+		p->chan->cid.cid_rdnis = strdup(p->owner->cid.cid_rdnis);
 	else
-		p->chan->rdnis = NULL;
-	if (p->owner->ani)
-		p->chan->ani = strdup(p->owner->ani);
+		p->chan->cid.cid_rdnis = NULL;
+
+	if (p->owner->cid.cid_ani)
+		p->chan->cid.cid_ani = strdup(p->owner->cid.cid_ani);
 	else
-		p->chan->ani = NULL;
+		p->chan->cid.cid_ani = NULL;
+
 	strncpy(p->chan->language, p->owner->language, sizeof(p->chan->language) - 1);
 	strncpy(p->chan->accountcode, p->owner->accountcode, sizeof(p->chan->accountcode) - 1);
 	p->chan->cdrflags = p->owner->cdrflags;

Index: chan_mgcp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_mgcp.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- chan_mgcp.c	24 Sep 2004 19:21:24 -0000	1.79
+++ chan_mgcp.c	2 Oct 2004 00:58:31 -0000	1.80
@@ -150,7 +150,8 @@
 
 static char language[MAX_LANGUAGE] = "";
 static char musicclass[MAX_LANGUAGE] = "";
-static char callerid[AST_MAX_EXTENSION] = "";
+static char cid_num[AST_MAX_EXTENSION] = "";
+static char cid_name[AST_MAX_EXTENSION] = "";
 
 static int dtmfmode = 0;
 static int nat = 0;
@@ -356,7 +357,8 @@
 	char exten[AST_MAX_EXTENSION];		/* Extention where to start */
 	char context[AST_MAX_EXTENSION];
 	char language[MAX_LANGUAGE];
-	char callerid[AST_MAX_EXTENSION];	/* Caller*ID */
+	char cid_num[AST_MAX_EXTENSION];	/* Caller*ID */
+	char cid_name[AST_MAX_EXTENSION];	/* Caller*ID */
 	char lastcallerid[AST_MAX_EXTENSION];	/* Last Caller*ID */
 	char call_forward[AST_MAX_EXTENSION];	/* Last Caller*ID */
     char mailbox[AST_MAX_EXTENSION];
@@ -445,7 +447,7 @@
 static int transmit_response(struct mgcp_subchannel *sub, char *msg, struct mgcp_request *req, char *msgrest);
 static int transmit_notify_request(struct mgcp_subchannel *sub, char *tone);
 static int transmit_modify_request(struct mgcp_subchannel *sub);
-static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callerid);
+static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername);
 static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs);
 static int transmit_connection_del(struct mgcp_subchannel *sub);
 static int transmit_audit_endpoint(struct mgcp_endpoint *p);
@@ -840,7 +842,7 @@
             transmit_modify_request(sub->next);
         }
 
-		transmit_notify_request_with_callerid(sub, tone, ast->callerid);
+		transmit_notify_request_with_callerid(sub, tone, ast->cid.cid_num, ast->cid.cid_name);
 		ast_setstate(ast, AST_STATE_RINGING);
 		ast_queue_control(ast, AST_CONTROL_RINGING);
 
@@ -897,7 +899,7 @@
     if ((sub == p->sub) && sub->next->owner) {
         if (p->hookstate == MGCP_OFFHOOK) {
             if (sub->next->owner && sub->next->owner->bridge) {
-                transmit_notify_request_with_callerid(p->sub, "L/wt", sub->next->owner->bridge->callerid);
+                transmit_notify_request_with_callerid(p->sub, "L/wt", sub->next->owner->bridge->cid.cid_num, sub->next->owner->bridge->cid.cid_name);
             }
         } else {
             /* set our other connection as the primary and swith over to it */
@@ -905,7 +907,7 @@
             p->sub->cxmode = MGCP_CX_RECVONLY;
             transmit_modify_request(p->sub);
             if (sub->next->owner && sub->next->owner->bridge) {
-                transmit_notify_request_with_callerid(p->sub, "L/rg", sub->next->owner->callerid);
+                transmit_notify_request_with_callerid(p->sub, "L/rg", sub->next->owner->bridge->cid.cid_num, sub->next->owner->bridge->cid.cid_name);
             }
         }
 
@@ -1291,8 +1293,10 @@
 		strncpy(tmp->call_forward, i->call_forward, sizeof(tmp->call_forward) - 1);
 		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
 		strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
-		if (strlen(i->callerid))
-			tmp->callerid = strdup(i->callerid);
+		if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_num = strdup(i->cid_num);
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
 		if (!i->adsi)
 			tmp->adsicpe = AST_ADSI_UNAVAILABLE;
 		tmp->priority = 1;
@@ -2018,10 +2022,9 @@
 	return send_request(p, NULL, &resp, oseq); /* SC */
 }
 
-static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callerid)
+static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername)
 {
 	struct mgcp_request resp;
-	char cid[256];
 	char tone2[256];
 	char *l, *n;
 	time_t t;
@@ -2030,18 +2033,8 @@
 	
 	time(&t);
 	localtime_r(&t,&tm);
-	if (callerid)
-		strncpy(cid, callerid, sizeof(cid) - 1);
-	else
-		cid[0] = '\0';
-	ast_callerid_parse(cid, &n, &l);
-	if (l) {
-		ast_shrink_phone_number(l);
-		if (!ast_isphonenumber(l)) {
-			n = l;
-			l = "";
-		}
-	} 
+	n = callername;
+	l = callernum;
 	if (!n)
 		n = "";
 	if (!l)
@@ -2458,8 +2451,8 @@
             /*tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);*/
             transmit_notify_request(sub, "L/dl");
         }
-        if (ast_exists_extension(chan, chan->context, exten, 1, p->callerid)) {
-            if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->callerid)) {
+        if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) {
+            if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
                 if (getforward) {
                     /* Record this as the forwarding extension */
                     strncpy(p->call_forward, exten, sizeof(p->call_forward) - 1); 
@@ -2484,16 +2477,20 @@
                     /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
                     ast_indicate(chan, -1);
                     strncpy(chan->exten, exten, sizeof(chan->exten)-1);
-                    if (strlen(p->callerid)) {
+                    if (!ast_strlen_zero(p->cid_num)) {
                         if (!p->hidecallerid) {
                             /* SC: free existing chan->callerid */
-                            if (chan->callerid)
-                                free(chan->callerid);
-                            chan->callerid = strdup(p->callerid);
+                            if (chan->cid.cid_num)
+                                free(chan->cid.cid_num);
+                            chan->cid.cid_num = strdup(p->cid_num);
+                            /* SC: free existing chan->callerid */
+                            if (chan->cid.cid_name)
+                                free(chan->cid.cid_name);
+                            chan->cid.cid_name = strdup(p->cid_name);
                         }
-                        if (chan->ani)
-                            free(chan->ani);
-                        chan->ani = strdup(p->callerid);
+                        if (chan->cid.cid_ani)
+                            free(chan->cid.cid_ani);
+                        chan->cid.cid_ani = strdup(p->cid_num);
                     }
                     ast_setstate(chan, AST_STATE_RING);
                     /*zt_enable_ec(p);*/
@@ -2549,9 +2546,12 @@
             }
             /* Disable Caller*ID if enabled */
             p->hidecallerid = 1;
-            if (chan->callerid)
-                free(chan->callerid);
-            chan->callerid = NULL;
+            if (chan->cid.cid_num)
+                free(chan->cid.cid_num);
+            chan->cid.cid_num = NULL;
+            if (chan->cid.cid_name)
+                free(chan->cid.cid_name);
+            chan->cid.cid_name = NULL;
             /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
             transmit_notify_request(sub, "L/sl");
             len = 0;
@@ -2631,19 +2631,23 @@
             }
             /* Enable Caller*ID if enabled */
             p->hidecallerid = 0;
-            if (chan->callerid)
-                free(chan->callerid);
-            if (strlen(p->callerid))
-                chan->callerid = strdup(p->callerid);
+            if (chan->cid.cid_num)
+                free(chan->cid.cid_num);
+            if (!ast_strlen_zero(p->cid_num))
+                chan->cid.cid_num = strdup(p->cid_num);
+            if (chan->cid.cid_name)
+                free(chan->cid.cid_name);
+            if (!ast_strlen_zero(p->cid_name))
+                chan->cid.cid_name = strdup(p->cid_name);
             /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/
             transmit_notify_request(sub, "L/sl");
             len = 0;
             memset(exten, 0, sizeof(exten));
             timeout = firstdigittimeout;
-        } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->callerid) &&
+        } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
                         ((exten[0] != '*') || (strlen(exten) > 2))) {
             if (option_debug)
-                ast_log(LOG_DEBUG, "Can't match %s from '%s' in context %s\n", exten, chan->callerid ? chan->callerid : "<Unknown Caller>", chan->context);
+                ast_log(LOG_DEBUG, "Can't match %s from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context);
             break;
         }
         if (!timeout)
@@ -3481,10 +3485,12 @@
 			} else if (!strcasecmp(v->name, "nat")) {
 				nat = ast_true(v->value);
 			} else if (!strcasecmp(v->name, "callerid")) {
-				if (!strcasecmp(v->value, "asreceived"))
-					callerid[0] = '\0';
-				else
-					strncpy(callerid, v->value, sizeof(callerid) - 1);
+				if (!strcasecmp(v->value, "asreceived")) {
+					cid_num[0] = '\0';
+					cid_name[0] = '\0';
+				} else {
+					ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
+				}
 			} else if (!strcasecmp(v->name, "language")) {
 				strncpy(language, v->value, sizeof(language)-1);
             } else if (!strcasecmp(v->name, "accountcode")) {
@@ -3558,7 +3564,8 @@
 					//strncpy(e->name, "aaln/*", sizeof(e->name) - 1);
 					/* XXX Should we really check for uniqueness?? XXX */
 					strncpy(e->context, context, sizeof(e->context) - 1);
-					strncpy(e->callerid, callerid, sizeof(e->callerid) - 1);
+					strncpy(e->cid_num, cid_num, sizeof(e->cid_num) - 1);
+					strncpy(e->cid_name, cid_name, sizeof(e->cid_name) - 1);
 					strncpy(e->language, language, sizeof(e->language) - 1);
             		strncpy(e->musicclass, musicclass, sizeof(e->musicclass)-1);
             		strncpy(e->mailbox, mailbox, sizeof(e->mailbox)-1);
@@ -3650,7 +3657,8 @@
                     }
 					/* XXX Should we really check for uniqueness?? XXX */
 					strncpy(e->context, context, sizeof(e->context) - 1);
-					strncpy(e->callerid, callerid, sizeof(e->callerid) - 1);
+					strncpy(e->cid_num, cid_num, sizeof(e->cid_num) - 1);
+					strncpy(e->cid_name, cid_name, sizeof(e->cid_name) - 1);
 					strncpy(e->language, language, sizeof(e->language) - 1);
                     strncpy(e->musicclass, musicclass, sizeof(e->musicclass)-1);
                     strncpy(e->mailbox, mailbox, sizeof(e->mailbox)-1);

Index: chan_modem.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_modem.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- chan_modem.c	27 Aug 2004 16:17:16 -0000	1.27
+++ chan_modem.c	2 Oct 2004 00:58:31 -0000	1.28
@@ -3,9 +3,9 @@
  *
  * A/Open ITU-56/2 Voice Modem Driver (Rockwell, IS-101, and others)
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
  *
- * Mark Spencer <markster at linux-support.net>
+ * Mark Spencer <markster at digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -429,7 +429,8 @@
 	if (p->mc->init)
 		p->mc->init(p);
 	ast_setstate(ast, AST_STATE_DOWN);
-	memset(p->cid, 0, sizeof(p->cid));
+	memset(p->cid_num, 0, sizeof(p->cid_num));
+	memset(p->cid_name, 0, sizeof(p->cid_name));
 	memset(p->dnid, 0, sizeof(p->dnid));
 	((struct ast_modem_pvt *)(ast->pvt->pvt))->owner = NULL;
 	ast_mutex_lock(&usecnt_lock);
@@ -529,8 +530,12 @@
 		tmp->pvt->read = modem_read;
 		tmp->pvt->write = modem_write;
 		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
-		if (strlen(i->cid))
-			tmp->callerid = strdup(i->cid);
+
+		if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_num = strdup(i->cid_num);
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
+
 		if (strlen(i->language))
 			strncpy(tmp->language,i->language, sizeof(tmp->language)-1);
 		if (strlen(i->dnid))
@@ -739,7 +744,8 @@
 		tmp->dialtype = dialtype;
 		tmp->mode = gmode;
 		tmp->group = cur_group;
-		memset(tmp->cid, 0, sizeof(tmp->cid));
+		memset(tmp->cid_num, 0, sizeof(tmp->cid_num));
+		memset(tmp->cid_name, 0, sizeof(tmp->cid_name));
 		strncpy(tmp->context, context, sizeof(tmp->context)-1);
 		strncpy(tmp->initstr, initstr, sizeof(tmp->initstr)-1);
 		tmp->next = NULL;

Index: chan_modem_bestdata.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_modem_bestdata.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- chan_modem_bestdata.c	16 Jul 2004 04:40:54 -0000	1.12
+++ chan_modem_bestdata.c	2 Oct 2004 00:58:31 -0000	1.13
@@ -201,13 +201,14 @@
 		p->gotclid = 1;
 		if ((!strcmp(name,"O")) || (!strcmp(name,"P"))) name[0] = 0;
 		if ((!strcmp(nmbr,"O")) || (!strcmp(nmbr,"P"))) nmbr[0] = 0;
-		if ((name[0]) && (nmbr[0])) snprintf(p->cid,sizeof(p->cid),
-			"\"%s\" <%s>",name,nmbr);
-		else if (name[0]) snprintf(p->cid,sizeof(p->cid),
-			"\"%s\"",name);
-		else if (nmbr[0]) snprintf(p->cid,sizeof(p->cid),
-			"%s",nmbr);
-		if (p->owner) p->owner->callerid = strdup(p->cid);
+		if (name[0])
+			strncpy(p->cid_name, name, sizeof(p->cid_name) - 1);
+		if (nmbr[0])
+			strncpy(p->cid_num, nmbr, sizeof(p->cid_num) - 1);
+		if (p->owner) {
+			p->owner->cid.cid_num = strdup(p->cid_num);
+			p->owner->cid.cid_name = strdup(p->cid_name);
+		}
 		return &p->fr;
 	case '@': /* response from "OK" in command mode */
 		if (p->owner)

Index: chan_modem_i4l.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_modem_i4l.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- chan_modem_i4l.c	24 Jun 2004 13:27:44 -0000	1.17
+++ chan_modem_i4l.c	2 Oct 2004 00:58:31 -0000	1.18
@@ -345,7 +345,7 @@
 				return i4l_handle_escape(p, 'b');
 			} else
 			if (!strncasecmp(result, "CALLER NUMBER: ", 15 )) {
-				strncpy(p->cid, result + 15, sizeof(p->cid)-1);
+				strncpy(p->cid_num, result + 15, sizeof(p->cid_num)-1);
 				return i4l_handle_escape(p, 0);
 			} else
 			if (!strcasecmp(result, "RINGING")) {
@@ -584,30 +584,22 @@
 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 (c && c->cid.cid_num && !(c->cid.cid_pres & 0x20)) {
+	    snprintf(tmpmsn, sizeof(tmpmsn), ",%s,", c->cid.cid_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);
+	      snprintf(cmd, sizeof(cmd), "AT&E%s\n", c->cid.cid_num);
 	      if (ast_modem_send(p, cmd, strlen(cmd))) {
-		ast_log(LOG_WARNING, "Unable to set A number to %s\n",num);
+		ast_log(LOG_WARNING, "Unable to set A number to %s\n", c->cid.cid_num);
 	      }
 
 	    } else {
-	      ast_log(LOG_WARNING, "Outgoing MSN %s not allowed (see outgoingmsn=%s in modem.conf)\n",num,p->outgoingmsn);
+	      ast_log(LOG_WARNING, "Outgoing MSN %s not allowed (see outgoingmsn=%s in modem.conf)\n",c->cid.cid_num,p->outgoingmsn);
 	    }
-	  }
 	}
 
 	snprintf(cmd, sizeof(cmd), "ATD%c %s\n", p->dialtype,stuff);

Index: chan_oss.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_oss.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- chan_oss.c	31 Aug 2004 13:32:11 -0000	1.33
+++ chan_oss.c	2 Oct 2004 00:58:31 -0000	1.34
@@ -7,9 +7,9 @@
  * VERY BADLY WRITTEN DRIVER so please don't use it as a model for
  * writing a driver.
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
  *
- * Mark Spencer <markster at linux-support.net>
+ * Mark Spencer <markster at digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -941,7 +941,7 @@
 			context++;
 		} else
 			context = oss.owner->context;
-		if (ast_exists_extension(oss.owner->bridge, context, tmp, 1, oss.owner->bridge->callerid)) {
+		if (ast_exists_extension(oss.owner->bridge, context, tmp, 1, oss.owner->bridge->cid.cid_num)) {
 			ast_cli(fd, "Whee, transferring %s to %s@%s.\n", 
 					oss.owner->bridge->name, tmp, context);
 			if (ast_async_goto(oss.owner->bridge, context, tmp, 1))

Index: chan_phone.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_phone.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- chan_phone.c	8 Aug 2004 17:15:02 -0000	1.33
+++ chan_phone.c	2 Oct 2004 00:58:31 -0000	1.34
@@ -3,9 +3,9 @@
  *
  * Generic Linux Telephony Interface driver
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
  *
- * Mark Spencer <markster at linux-support.net>
+ * Mark Spencer <markster at digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -119,10 +119,12 @@
 	char obuf[PHONE_MAX_BUF * 2];
 	char ext[AST_MAX_EXTENSION];
 	char language[MAX_LANGUAGE];
-	char callerid[AST_MAX_EXTENSION];
+	char cid_num[AST_MAX_EXTENSION];
+	char cid_name[AST_MAX_EXTENSION];
 } *iflist = NULL;
 
-static char callerid[AST_MAX_EXTENSION];
+static char cid_num[AST_MAX_EXTENSION];
+static char cid_name[AST_MAX_EXTENSION];
 
 static int phone_digit(struct ast_channel *ast, char digit)
 {
@@ -185,24 +187,13 @@
 		snprintf(cid.min, sizeof(cid.min),     "%02d", tm.tm_min);
 	}
 	/* the standard format of ast->callerid is:  "name" <number>, but not always complete */
-	if (!ast->callerid || ast_strlen_zero(ast->callerid)){
+	if (!ast->cid.cid_name || ast_strlen_zero(ast->cid.cid_name))
 		strncpy(cid.name, DEFAULT_CALLER_ID, sizeof(cid.name) - 1);
-		cid.number[0]='\0';
-	} else {
-		char *n, *l;
-		char callerid[256] = "";
-		strncpy(callerid, ast->callerid, sizeof(callerid) - 1);
-		ast_callerid_parse(callerid, &n, &l);
-		if (l) {
-			ast_shrink_phone_number(l);
-			if (!ast_isphonenumber(l))
-				l = NULL;
-		}
-		if (l)
-			strncpy(cid.number, l, sizeof(cid.number) - 1);
-		if (n)
-			strncpy(cid.name, n, sizeof(cid.name) - 1);
-	}
+	else
+		strncpy(cid.name, ast->cid.cid_name, sizeof(cid.name) - 1);
+
+	if (ast->cid.cid_num) 
+		strncpy(cid.number, ast->cid.cid_num, sizeof(cid.number) - 1);
 
 	p = ast->pvt->pvt;
 
@@ -683,8 +674,10 @@
 			strncpy(tmp->exten, "s",  sizeof(tmp->exten) - 1);
 		if (strlen(i->language))
 			strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
-		if (strlen(i->callerid))
-			tmp->callerid = strdup(i->callerid);
+		if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_num = strdup(i->cid_num);
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
 		i->owner = tmp;
 		ast_mutex_lock(&usecnt_lock);
 		usecnt++;
@@ -736,7 +729,7 @@
 			i->dialtone = 0;
 			if (strlen(i->ext) < AST_MAX_EXTENSION - 1)
 				strncat(i->ext, digit, sizeof(i->ext) - strlen(i->ext) - 1);
-			if (ast_exists_extension(NULL, i->context, i->ext, 1, i->callerid)) {
+			if (ast_exists_extension(NULL, i->context, i->ext, 1, i->cid_num)) {
 				/* It's a valid extension in its context, get moving! */
 				phone_new(i, AST_STATE_RING, i->context);
 				/* No need to restart monitor, we are the monitor */
@@ -746,10 +739,10 @@
 					ast_mutex_unlock(&usecnt_lock);
 					ast_update_use_count();
 				}
-			} else if (!ast_canmatch_extension(NULL, i->context, i->ext, 1, i->callerid)) {
+			} else if (!ast_canmatch_extension(NULL, i->context, i->ext, 1, i->cid_num)) {
 				/* There is nothing in the specified extension that can match anymore.
 				   Try the default */
-				if (ast_exists_extension(NULL, "default", i->ext, 1, i->callerid)) {
+				if (ast_exists_extension(NULL, "default", i->ext, 1, i->cid_num)) {
 					/* Check the default, too... */
 					phone_new(i, AST_STATE_RING, "default");
 					if (i->owner) {
@@ -759,7 +752,7 @@
 						ast_update_use_count();
 					}
 					/* XXX This should probably be justified better XXX */
-				}  else if (!ast_canmatch_extension(NULL, "default", i->ext, 1, i->callerid)) {
+				}  else if (!ast_canmatch_extension(NULL, "default", i->ext, 1, i->cid_num)) {
 					/* It's not a valid extension, give a busy signal */
 					if (option_debug)
 						ast_log(LOG_DEBUG, "%s can't match anything in %s or default\n", i->ext, i->context);
@@ -1020,7 +1013,8 @@
 		tmp->obuflen = 0;
 		tmp->dialtone = 0;
 		tmp->cpt = 0;
-		strncpy(tmp->callerid, callerid, sizeof(tmp->callerid)-1);
+		strncpy(tmp->cid_num, cid_num, sizeof(tmp->cid_num)-1);
+		strncpy(tmp->cid_name, cid_name, sizeof(tmp->cid_name)-1);
 		tmp->txgain = txgain;
 		ioctl(tmp->fd, PHONE_PLAY_VOLUME, tmp->txgain);
 		tmp->rxgain = rxgain;
@@ -1183,7 +1177,7 @@
 		} else if (!strcasecmp(v->name, "language")) {
 			strncpy(language, v->value, sizeof(language)-1);
 		} else if (!strcasecmp(v->name, "callerid")) {
-			strncpy(callerid, v->value, sizeof(callerid)-1);
+			ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
 		} else if (!strcasecmp(v->name, "mode")) {
 			if (!strncasecmp(v->value, "di", 2)) 
 				mode = MODE_DIALTONE;

Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.511
retrieving revision 1.512
diff -u -d -r1.511 -r1.512
--- chan_sip.c	30 Sep 2004 19:59:00 -0000	1.511
+++ chan_sip.c	2 Oct 2004 00:58:31 -0000	1.512
@@ -269,6 +269,7 @@
 	int peercapability;			/* Supported peer capability */
 	int prefcodec;				/* Preferred codec (outbound only) */
 	int noncodeccapability;
+	int callingpres;			/* Calling presentation */
 	int outgoing;				/* Outgoing or incoming call? */
 	int authtries;				/* Times we've tried to authenticate */
 	int insecure;				/* Don't check source port/ip */
@@ -311,8 +312,8 @@
 	char uri[256];				/* Original requested URI */
 	char peersecret[256];
 	char peermd5secret[256];
-	char callerid[256];			/* Caller*ID */
-	int restrictcid;			/* hide presentation from remote user */
+	char cid_num[256];			/* Caller*ID */
+	char cid_name[256];			/* Caller*ID */
 	char via[256];
 	char fullcontact[128];		/* Extra parameters to go in the "To" header */
 	char accountcode[20];			/* Account code */
@@ -384,7 +385,8 @@
 	char secret[80];
         char md5secret[80];
 	char context[80];
-	char callerid[80];
+	char cid_num[80];
+	char cid_name[80];
 	char accountcode[20];
 	char language[MAX_LANGUAGE];
 	char musicclass[MAX_LANGUAGE];  /* Music on Hold class */
@@ -394,6 +396,7 @@
 	int nat;
 	int hascallerid;
 	int amaflags;
+	int callingpres;
 	int insecure;
 	int canreinvite;
 	int capability;
@@ -406,7 +409,6 @@
 	int outUse;
 	int outgoinglimit;
 	int promiscredir;
-	int restrictcid;
 	int trustrpid;
 	int progressinband;
 	struct ast_ha *ha;
@@ -1034,7 +1036,7 @@
 			mysql_real_escape_string(mysql, name, user, strlen(user));
 		}
 
-		snprintf(query, sizeof(query), "SELECT name, secret, context, username, ipaddr, port, regseconds, callerid, restrictcid FROM sipfriends WHERE name=\"%s\"", name);
+		snprintf(query, sizeof(query), "SELECT name, secret, context, username, ipaddr, port, regseconds, callerid, callingpres FROM sipfriends WHERE name=\"%s\"", name);
 
 		ast_mutex_lock(&mysqllock);
 		mysql_query(mysql, query);
@@ -1057,8 +1059,8 @@
 						} else if (!strcasecmp(fields[x].name, "regseconds")) {
 							if (sscanf(rowval[x], "%li", &regseconds) != 1)
 								regseconds = 0;
-						} else if (!strcasecmp(fields[x].name, "restrictcid")) {
-							u->restrictcid = 1;
+						} else if (!strcasecmp(fields[x].name, "callingpres")) {
+							u->callingpres = atoi(rowval[x]);
 						} else if (!strcasecmp(fields[x].name, "callerid")) {
 							strncpy(u->callerid, rowval[x], sizeof(u->callerid) - 1);
 							u->hascallerid=1;
@@ -1536,7 +1538,7 @@
 	ast_log(LOG_DEBUG, "Outgoing Call for %s\n", p->username);
 	res = update_user_counter(p,INC_OUT_USE);
 	if ( res != -1 ) {
-		p->restrictcid = ast->restrictcid;
+		p->callingpres = ast->cid.cid_pres;
 		p->jointcapability = p->capability;
 		transmit_invite(p, "INVITE", 1, NULL, NULL, vxml_url,distinctive_ring, osptoken, 1);
 		if (p->maxtime) {
@@ -2073,7 +2075,7 @@
 
 		tmp->callgroup = i->callgroup;
 		tmp->pickupgroup = i->pickupgroup;
-		tmp->restrictcid = i->restrictcid;
+		tmp->cid.cid_pres = i->callingpres;
                 if (!ast_strlen_zero(i->accountcode))
                         strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1);
                 if (i->amaflags)
@@ -2088,12 +2090,14 @@
 		ast_mutex_unlock(&usecnt_lock);
 		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
 		strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
-		if (!ast_strlen_zero(i->callerid))
-			tmp->callerid = strdup(i->callerid);
+		if (!ast_strlen_zero(i->cid_num))
+			tmp->cid.cid_num = strdup(i->cid_num);
+		if (!ast_strlen_zero(i->cid_name))
+			tmp->cid.cid_name = strdup(i->cid_name);
 		if (!ast_strlen_zero(i->rdnis))
-			tmp->rdnis = strdup(i->rdnis);
+			tmp->cid.cid_rdnis = strdup(i->rdnis);
 		if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
-			tmp->dnid = strdup(i->exten);
+			tmp->cid.cid_dnid = strdup(i->exten);
 		tmp->priority = 1;
 		if (!ast_strlen_zero(i->domain)) {
 			pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain);
@@ -3686,22 +3690,16 @@
 	char to[256];
 	char tmp[80];
 	char iabuf[INET_ADDRSTRLEN];
-	char cid[256];
 	char *l = default_callerid, *n=NULL;
 
 	snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", cmd);
 
-	if (p->owner && p->owner->callerid) {
-		strncpy(cid, p->owner->callerid, sizeof(cid) - 1);
-		cid[sizeof(cid) - 1] = '\0';
-		ast_callerid_parse(cid, &n, &l);
-		if (l) 
-			ast_shrink_phone_number(l);
-		if (!l || !ast_isphonenumber(l))
-				l = default_callerid;
-	}
+	l = p->owner->cid.cid_num;
+	n = p->owner->cid.cid_name;
+	if (!l || !ast_isphonenumber(l))
+			l = default_callerid;
 	/* if user want's his callerid restricted */
-	if (p->restrictcid) {
+	if (p->callingpres & AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED) {
 		l = CALLERID_UNKNOWN;
 		n = l;
 	}
@@ -4684,7 +4682,7 @@
 		if (!strlen(osptoken))
 			return -1;
 		/* Validate token */
-		if (ast_osp_validate(NULL, osptoken, &p->osphandle, &osptimelimit, p->callerid, p->sa.sin_addr, p->exten) < 1)
+		if (ast_osp_validate(NULL, osptoken, &p->osphandle, &osptimelimit, p->cid_num, p->sa.sin_addr, p->exten) < 1)
 			return -1;
 		
 		snprintf(tmp, sizeof(tmp), "%d", p->osphandle);
@@ -5305,7 +5303,7 @@
 		*end = '\0';
 
 	if(strstr(input,"privacy=full") || strstr(input,"privacy=uri"))
-		return 1;
+		return AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
 
 	return 0;
 }
@@ -5337,7 +5335,7 @@
 	rpid = get_header(req, "Remote-Party-ID");
 	memset(rpid_num,0,sizeof(rpid_num));
 	if(!ast_strlen_zero(rpid)) 
-	  p->restrictcid = get_rpid_num(rpid,rpid_num, sizeof(rpid_num));
+	  p->callingpres = get_rpid_num(rpid,rpid_num, sizeof(rpid_num));
 
 	of = ditch_braces(from);
 	if (ast_strlen_zero(p->exten)) {
@@ -5360,10 +5358,9 @@
 		*c = '\0';
 	if ((c = strchr(of, ':')))
 		*c = '\0';
+	strncpy(p->cid_num, of, sizeof(p->cid_num) - 1);
 	if (*calleridname)
-		snprintf(p->callerid,sizeof(p->callerid),"\"%s\" <%s>",calleridname,of);
-	else
-		strncpy(p->callerid, of, sizeof(p->callerid) - 1);
+		strncpy(p->cid_name, calleridname, sizeof(p->cid_name) - 1);
 	if (ast_strlen_zero(of))
 			return 0;
 	ast_mutex_lock(&userl.lock);
@@ -5379,9 +5376,8 @@
 		/* replace callerid if rpid found, and not restricted */
 		if(!ast_strlen_zero(rpid_num) && p->trustrpid) {
 		  if (*calleridname)
-		    snprintf(p->callerid, sizeof(p->callerid), "\"%s\" <%s>",calleridname,rpid_num);
-		  else
-		    strncpy(p->callerid, rpid_num, sizeof(p->callerid) - 1);
+		  	strncpy(p->cid_name, calleridname, sizeof(p->cid_name) - 1);
+		  strncpy(p->cid_num, rpid_num, sizeof(p->cid_num) - 1);
 		}
 
 		if (p->rtp) {
@@ -5396,8 +5392,10 @@
 			sip_cancel_destroy(p);
 			if (!ast_strlen_zero(user->context))
 				strncpy(p->context, user->context, sizeof(p->context) - 1);
-			if (!ast_strlen_zero(user->callerid) && !ast_strlen_zero(p->callerid)) 
-				strncpy(p->callerid, user->callerid, sizeof(p->callerid) - 1);
+			if (!ast_strlen_zero(user->cid_num) && !ast_strlen_zero(p->cid_num)) 
+				strncpy(p->cid_num, user->cid_num, sizeof(p->cid_num) - 1);
+			if (!ast_strlen_zero(user->cid_name) && !ast_strlen_zero(p->cid_name)) 
+				strncpy(p->cid_num, user->cid_name, sizeof(p->cid_name) - 1);
 			strncpy(p->username, user->name, sizeof(p->username) - 1);
 			strncpy(p->peersecret, user->secret, sizeof(p->peersecret) - 1);
 			strncpy(p->peermd5secret, user->md5secret, sizeof(p->peermd5secret) - 1);
@@ -5408,7 +5406,7 @@
 			p->amaflags = user->amaflags;
 			p->callgroup = user->callgroup;
 			p->pickupgroup = user->pickupgroup;
-			p->restrictcid = user->restrictcid;
+			p->callingpres = user->callingpres;
 			p->capability = user->capability;
 			p->jointcapability = user->capability;
 			if (p->peercapability)
@@ -5452,9 +5450,8 @@
 			/* replace callerid if rpid found, and not restricted */
 			if(!ast_strlen_zero(rpid_num) && p->trustrpid) {
 			  if (*calleridname)
-			    snprintf(p->callerid,sizeof(p->callerid),"\"%s\" <%s>",calleridname,rpid_num);
-			  else
-			    strncpy(p->callerid, rpid_num, sizeof(p->callerid) - 1);
+			  	strncpy(p->cid_name, calleridname, sizeof(p->cid_name) - 1);
+			  strncpy(p->cid_num, rpid_num, sizeof(p->cid_num) - 1);
 			}
 #ifdef OSP_SUPPORT
 			p->ospauth = peer->ospauth;
@@ -5891,7 +5888,7 @@
 	while (cur) {
 		if (!cur->subscribed && !subscriptions) {
 		   ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), 
-			ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->callerid) ? "(None)" : cur->callerid ) : cur->username, 
+			ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, 
 			cur->callid, 
 			cur->ocseq, cur->icseq, 
 			ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), cur->needdestroy ? "(d)" : "" );
@@ -5899,7 +5896,7 @@
 		}
 		if (cur->subscribed && subscriptions) {
                    ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
-			ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->callerid) ? "(None)" : cur->callerid ) : cur->username, 
+			ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, 
                         cur->callid, cur->uri);
 
                 }
@@ -5976,8 +5973,8 @@
 			   ast_cli(fd, "  Peername:               %s\n", cur->peername);
 			if (!ast_strlen_zero(cur->uri))
 			   ast_cli(fd, "  Original uri:           %s\n", cur->uri);
-			if (!ast_strlen_zero(cur->callerid))
-			   ast_cli(fd, "  Caller-ID:              %s\n", cur->callerid);
+			if (!ast_strlen_zero(cur->cid_num))
+			   ast_cli(fd, "  Caller-ID:              %s\n", cur->cid_num);
 			ast_cli(fd, "  Need Destroy:           %d\n", cur->needdestroy);
 			ast_cli(fd, "  Last Message:           %s\n", cur->lastmsg);
 			ast_cli(fd, "  Promiscuous Redir:      %s\n", cur->promiscredir ? "Yes" : "No");
@@ -8106,7 +8103,7 @@
 				else
 					user->nat = SIP_NAT_RFC3581;
 			} else if (!strcasecmp(v->name, "callerid")) {
-				strncpy(user->callerid, v->value, sizeof(user->callerid)-1);
+				ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
 				user->hascallerid=1;
 			} else if (!strcasecmp(v->name, "callgroup")) {
 				user->callgroup = ast_get_group(v->value);
@@ -8147,8 +8144,8 @@
 					user->capability &= ~format;
 			} else if (!strcasecmp(v->name, "insecure")) {
 				user->insecure = ast_true(v->value);
-			} else if (!strcasecmp(v->name, "restrictcid")) {
-				user->restrictcid = ast_true(v->value);
+			} else if (!strcasecmp(v->name, "callingpres")) {
+				user->callingpres = atoi(v->value);
 			} else if (!strcasecmp(v->name, "trustrpid")) {
 				user->trustrpid = ast_true(v->value);
 			} else if (!strcasecmp(v->name, "progressinband")) {

Index: chan_skinny.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_skinny.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- chan_skinny.c	13 Sep 2004 21:34:47 -0000	1.54
+++ chan_skinny.c	2 Oct 2004 00:58:31 -0000	1.55
@@ -488,7 +488,8 @@
 static char context[AST_MAX_EXTENSION] = "default";
 static char language[MAX_LANGUAGE] = "";
 static char musicclass[MAX_LANGUAGE] = "";
-static char callerid[AST_MAX_EXTENSION] = "";
+static char cid_num[AST_MAX_EXTENSION] = "";
+static char cid_name[AST_MAX_EXTENSION] = "";
 static char linelabel[AST_MAX_EXTENSION] ="";
 static int nat = 0;
 static unsigned int cur_callergroup = 0;
@@ -634,7 +635,8 @@
 	char exten[AST_MAX_EXTENSION];			/* Extention where to start */
 	char context[AST_MAX_EXTENSION];
 	char language[MAX_LANGUAGE];
-	char callerid[AST_MAX_EXTENSION];		/* Caller*ID */
+	char cid_num[AST_MAX_EXTENSION];		/* Caller*ID */
+	char cid_name[AST_MAX_EXTENSION];		/* Caller*ID */
 	char lastcallerid[AST_MAX_EXTENSION];		/* Last Caller*ID */
 	char call_forward[AST_MAX_EXTENSION];	
 	char mailbox[AST_MAX_EXTENSION];
@@ -1060,9 +1062,10 @@
 				nat = ast_true(v->value);
 			} else if (!strcasecmp(v->name, "callerid")) {
 				if (!strcasecmp(v->value, "asreceived")) {
-					callerid[0] = '\0';
+					cid_num[0] = '\0';
+					cid_name[0] = '\0';
 				} else {
-					strncpy(callerid, v->value, sizeof(callerid) - 1);
+					ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
 				}
 			} else if (!strcasecmp(v->name, "language")) {
 				strncpy(language, v->value, sizeof(language)-1);
@@ -1109,7 +1112,8 @@
 					/* XXX Should we check for uniqueness?? XXX */
 					
 					strncpy(l->context, context, sizeof(l->context) - 1);
-					strncpy(l->callerid, callerid, sizeof(l->callerid) - 1);
+					strncpy(l->cid_num, cid_num, sizeof(l->cid_num) - 1);
+					strncpy(l->cid_name, cid_name, sizeof(l->cid_name) - 1);
 					strncpy(l->label, linelabel, sizeof(l->label) - 1);
 					strncpy(l->language, language, sizeof(l->language) - 1);
         				strncpy(l->musicclass, musicclass, sizeof(l->musicclass)-1);
@@ -1272,8 +1276,8 @@
         if (!ast_ignore_pattern(chan->context, exten)) {
 			transmit_tone(s, SKINNY_SILENCE);
         } 
-        if (ast_exists_extension(chan, chan->context, exten, 1, l->callerid)) {
-            if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, l->callerid)) {
+        if (ast_exists_extension(chan, chan->context, exten, 1, l->cid_num)) {
+            if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, l->cid_num)) {
                 if (getforward) {
                     /* Record this as the forwarding extension */
                     strncpy(l->call_forward, exten, sizeof(l->call_forward) - 1); 
@@ -1294,10 +1298,10 @@
                     getforward = 0;
                 } else  {
                     strncpy(chan->exten, exten, sizeof(chan->exten)-1);
-                    if (!ast_strlen_zero(l->callerid)) {
+                    if (!ast_strlen_zero(l->cid_num)) {
                         if (!l->hidecallerid)
-                            chan->callerid = strdup(l->callerid);
-                        chan->ani = strdup(l->callerid);
+                            chan->cid.cid_num = strdup(l->cid_num);
+                        chan->cid.cid_ani = strdup(l->cid_num);
                     }
                     ast_setstate(chan, AST_STATE_RING);
                     res = ast_pbx_run(chan);
@@ -1346,9 +1350,14 @@
             }
             /* Disable Caller*ID if enabled */
             l->hidecallerid = 1;
-            if (chan->callerid)
-                free(chan->callerid);
-            chan->callerid = NULL;
+            if (chan->cid.cid_num)
+                free(chan->cid.cid_num);
+            chan->cid.cid_num = NULL;
+            
+			if (chan->cid.cid_name)
+                free(chan->cid.cid_name);
+            chan->cid.cid_name = NULL;
+			
             transmit_tone(s, SKINNY_DIALTONE);
             len = 0;
             memset(exten, 0, sizeof(exten));
@@ -1422,17 +1431,23 @@
             }
             /* Enable Caller*ID if enabled */
             l->hidecallerid = 0;
-            if (chan->callerid)
-                free(chan->callerid);
-            if (!ast_strlen_zero(l->callerid))
-                chan->callerid = strdup(l->callerid);
+            if (chan->cid.cid_num)
+                free(chan->cid.cid_num);
+            if (!ast_strlen_zero(l->cid_num))
+                chan->cid.cid_num = strdup(l->cid_num);
+
+            if (chan->cid.cid_name)
+                free(chan->cid.cid_name);
+            if (!ast_strlen_zero(l->cid_name))
+                chan->cid.cid_name = strdup(l->cid_name);
+
             transmit_tone(s, SKINNY_DIALTONE);
             len = 0;
             memset(exten, 0, sizeof(exten));
             timeout = firstdigittimeout;
-        } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->callerid) &&
+        } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
                         ((exten[0] != '*') || (!ast_strlen_zero(exten) > 2))) {
-            ast_log(LOG_WARNING, "Can't match [%s] from '%s' in context %s\n", exten, chan->callerid ? chan->callerid : "<Unknown Caller>", chan->context);
+            ast_log(LOG_WARNING, "Can't match [%s] from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context);
             transmit_tone(s, SKINNY_REORDER); 
 			sleep(3); // hang out for 3 seconds to let congestion play
 			break;
@@ -1795,8 +1810,11 @@
 		strncpy(tmp->call_forward, l->call_forward, sizeof(tmp->call_forward) - 1);
 		strncpy(tmp->context, l->context, sizeof(tmp->context)-1);
 		strncpy(tmp->exten,l->exten, sizeof(tmp->exten)-1);
-		if (!ast_strlen_zero(l->callerid)) {
-			tmp->callerid = strdup(l->callerid);
+		if (!ast_strlen_zero(l->cid_num)) {
+			tmp->cid.cid_num = strdup(l->cid_num);
+		}
+		if (!ast_strlen_zero(l->cid_name)) {
+			tmp->cid.cid_name = strdup(l->cid_name);
 		}
 		tmp->priority = 1;
 		if (state != AST_STATE_DOWN) {

Index: chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.346
retrieving revision 1.347
diff -u -d -r1.346 -r1.347
--- chan_zap.c	1 Oct 2004 13:26:47 -0000	1.346
+++ chan_zap.c	2 Oct 2004 00:58:31 -0000	1.347
@@ -154,7 +154,8 @@
 #define DCHAN_AVAILABLE	(DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
 
 static char context[AST_MAX_EXTENSION] = "default";
-static char callerid[256] = "";
+static char cid_num[256] = "";
+static char cid_name[256] = "";
 
 static char language[MAX_LANGUAGE] = "";
 static char musicclass[MAX_LANGUAGE] = "";
@@ -455,10 +456,14 @@
 	char exten[AST_MAX_EXTENSION];
 	char language[MAX_LANGUAGE];
 	char musicclass[MAX_LANGUAGE];
-	char callerid[AST_MAX_EXTENSION];
-	char lastcallerid[AST_MAX_EXTENSION];
-	char *origcallerid;			/* malloced original callerid */
-	char callwaitcid[AST_MAX_EXTENSION];
+	char cid_num[AST_MAX_EXTENSION];
+	char cid_name[AST_MAX_EXTENSION];
+	char lastcid_num[AST_MAX_EXTENSION];
+	char lastcid_name[AST_MAX_EXTENSION];
+	char *origcid_num;			/* malloced original callerid */
+	char *origcid_name;			/* malloced original callerid */
+	char callwait_num[AST_MAX_EXTENSION];
+	char callwait_name[AST_MAX_EXTENSION];
 	char rdnis[AST_MAX_EXTENSION];
 	char dnid[AST_MAX_EXTENSION];
 	unsigned int group;
@@ -1383,13 +1388,13 @@
 	p->cidspill = malloc(MAX_CALLERID_SIZE);
 	if (p->cidspill) {
 		memset(p->cidspill, 0x7f, MAX_CALLERID_SIZE);
-		p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwaitcid, AST_LAW(p));
+		p->cidlen = ast_callerid_callwaiting_generate(p->cidspill, p->callwait_name, p->callwait_num, AST_LAW(p));
 		/* Make sure we account for the end */
 		p->cidlen += READ_SIZE * 4;
 		p->cidpos = 0;
 		send_callerid(p);
 		if (option_verbose > 2)
-			ast_verbose(VERBOSE_PREFIX_3 "CPE supports Call Waiting Caller*ID.  Sending '%s'\n", p->callwaitcid);
+			ast_verbose(VERBOSE_PREFIX_3 "CPE supports Call Waiting Caller*ID.  Sending '%s/%s'\n", p->callwait_name, p->callwait_num);
 	} else return -1;
 	return 0;
 }
@@ -1472,7 +1477,6 @@
 #ifdef ZAPATA_PRI
 	char *s=NULL;
 #endif
-	char callerid[256];
 	char dest[256]; /* must be same length as p->dialdest */
 	ast_mutex_lock(&p->lock);
 	strncpy(dest, rdest, sizeof(dest) - 1);
@@ -1521,7 +1525,7 @@
 				p->cidspill = malloc(MAX_CALLERID_SIZE);
 				p->callwaitcas = 0;
 				if (p->cidspill) {
-					p->cidlen = ast_callerid_generate(p->cidspill, ast->callerid, AST_LAW(p));
+					p->cidlen = ast_callerid_generate(p->cidspill, ast->cid.cid_name, ast->cid.cid_num, AST_LAW(p));
 					p->cidpos = 0;
 					send_callerid(p);
 				} else
@@ -1564,10 +1568,14 @@
 		} else {
 			/* Call waiting call */
 			p->callwaitrings = 0;
-			if (ast->callerid)
-				strncpy(p->callwaitcid, ast->callerid, sizeof(p->callwaitcid)-1);
+			if (ast->cid.cid_num)
+				strncpy(p->callwait_num, ast->cid.cid_num, sizeof(p->callwait_num)-1);
 			else
-				p->callwaitcid[0] = '\0';
+				p->callwait_num[0] = '\0';
+			if (ast->cid.cid_name)
+				strncpy(p->callwait_name, ast->cid.cid_name, sizeof(p->callwait_name)-1);
+			else
+				p->callwait_name[0] = '\0';
 			/* Call waiting tone instead */
 			if (zt_callwait(ast)) {
 				ast_mutex_unlock(&p->lock);
@@ -1578,20 +1586,16 @@
 				ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast->name);
 				
 		}
-		if (ast->callerid) 
-			strncpy(callerid, ast->callerid, sizeof(callerid)-1);
-		else
-			callerid[0] = '\0';
-		ast_callerid_parse(callerid, &n, &l);
-		if (l) {
-			ast_shrink_phone_number(l);
-			if (!ast_isphonenumber(l))
-				l = NULL;
-		}
+		n = ast->cid.cid_name;
+		l = ast->cid.cid_num;
 		if (l)
-			strncpy(p->lastcallerid, l, sizeof(p->lastcallerid) - 1);
+			strncpy(p->lastcid_num, l, sizeof(p->lastcid_num) - 1);
 		else
-			p->lastcallerid[0] = '\0';
+			p->lastcid_num[0] = '\0';
+		if (n)
+			strncpy(p->lastcid_name, n, sizeof(p->lastcid_name) - 1);
+		else
+			p->lastcid_name[0] = '\0';
 		ast_setstate(ast, AST_STATE_RINGING);
 		index = zt_get_index(ast, p, 0);
 		if (index > -1) {
@@ -1642,32 +1646,14 @@
 		ast_log(LOG_DEBUG, "Dialing '%s'\n", c);
 		p->dop.op = ZT_DIAL_OP_REPLACE;
 		if (p->sig == SIG_FEATD) {
-			if (ast->callerid) {
-				strncpy(callerid, ast->callerid, sizeof(callerid)-1);
-				ast_callerid_parse(callerid, &n, &l);
-				if (l) {
-					ast_shrink_phone_number(l);
-					if (!ast_isphonenumber(l))
-						l = NULL;
-				}
-			} else
-				l = NULL;
+			l = ast->cid.cid_num;
 			if (l) 
 				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c + p->stripmsd);
 			else
 				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c + p->stripmsd);
 		} else 
 		if (p->sig == SIG_FEATDMF) {
-			if (ast->callerid) {
-				strncpy(callerid, ast->callerid, sizeof(callerid)-1);
-				ast_callerid_parse(callerid, &n, &l);
-				if (l) {
-					ast_shrink_phone_number(l);
-					if (!ast_isphonenumber(l))
-						l = NULL;
-				}
-			} else
-				l = NULL;
+			l = ast->cid.cid_num;
 			if (l) 
 				snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c + p->stripmsd);
 			else
@@ -1726,16 +1712,13 @@
 			c++;
 		else
 			c = dest;
-		if (ast->callerid && !p->hidecallerid) {
-			strncpy(callerid, ast->callerid, sizeof(callerid)-1);
-			ast_callerid_parse(callerid, &n, &l);
-			if (l) {
-				ast_shrink_phone_number(l);
-				if (!ast_isphonenumber(l))
-					l = NULL;
-			}
-		} else
+		if (!p->hidecallerid) {
+			l = ast->cid.cid_num;
+			n = ast->cid.cid_name;
+		} else {
 			l = NULL;
+			n = NULL;
+		}
 		if (strlen(c) < p->stripmsd) {
 			ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
 			ast_mutex_unlock(&p->lock);
@@ -1786,8 +1769,7 @@
 						((p->law == ZT_LAW_ALAW) ? PRI_LAYER_1_ALAW : PRI_LAYER_1_ULAW)));
 		pri_sr_set_called(sr, c + p->stripmsd, p->pri->dialplan - 1,  s ? 1 : 0);
 		pri_sr_set_caller(sr, l, n, p->pri->localdialplan - 1, 
-					l ? (ast->restrictcid ? PRES_PROHIB_USER_NUMBER_PASSED_SCREEN : 
-						(p->use_callingpres ? ast->callingpres : PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN)) : 
+					l ? (p->use_callingpres ? ast->cid.cid_pres : PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN) : 
 						 PRES_NUMBER_NOT_AVAILABLE);
 		if (pri_setup(p->pri->pri, p->call,  sr)) {
 			ast_log(LOG_WARNING, "Unable to setup call to %s\n", c + p->stripmsd);
@@ -1965,10 +1947,15 @@
 	x = 0;
 	zt_confmute(p, 0);
 	restore_gains(p);
-	if (p->origcallerid) {
-		strncpy(p->callerid, p->origcallerid, sizeof(p->callerid) - 1);
-		free(p->origcallerid);
-		p->origcallerid = NULL;
+	if (p->origcid_num) {
+		strncpy(p->cid_num, p->origcid_num, sizeof(p->cid_num) - 1);
+		free(p->origcid_num);
+		p->origcid_num = NULL;
+	}	
+	if (p->origcid_name) {
+		strncpy(p->cid_name, p->origcid_name, sizeof(p->cid_name) - 1);
+		free(p->origcid_name);
+		p->origcid_name = NULL;
 	}	
 	if (p->dsp)
 		ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | p->dtmfrelax);
@@ -3462,10 +3449,15 @@
 						if (p->subs[SUB_REAL].owner->bridge)
 								ast_moh_stop(p->subs[SUB_REAL].owner->bridge);
 					} else if (!p->subs[SUB_THREEWAY].owner) {
-						char callerid[256];
+						char cid_num[256]="";
+						char cid_name[256]="";
 						if (p->threewaycalling && !check_for_conference(p)) {
-							if (p->zaptrcallerid && p->owner && p->owner->callerid)
-								strncpy(callerid, p->owner->callerid, sizeof(callerid) - 1);
+							if (p->zaptrcallerid && p->owner) {
+								if (p->owner->cid.cid_num)
+									strncpy(cid_num, p->owner->cid.cid_num, sizeof(cid_num) - 1);
+								if (p->owner->cid.cid_name)
+									strncpy(cid_name, p->owner->cid.cid_name, sizeof(cid_name) - 1);
+							}
 							/* XXX This section needs much more error checking!!! XXX */
 							/* Start a 3-way call if feasible */
 							if ((ast->pbx) ||
@@ -3475,13 +3467,20 @@
 									/* Make new channel */
 									chan = zt_new(p, AST_STATE_RESERVED, 0, SUB_THREEWAY, 0, 0);
 									if (p->zaptrcallerid) {
-										if (!p->origcallerid) {
-											p->origcallerid = malloc(strlen(p->callerid) + 1);
-											strncpy(p->origcallerid, p->callerid, strlen(p->callerid)); /* safe */
+										if (!p->origcid_num) {
+											p->origcid_num = malloc(strlen(p->origcid_num) + 1);
+											strncpy(p->origcid_num, p->cid_num, strlen(p->cid_num)); /* safe */
 											/* make sure p->origcallerid is terminated */
-											p->origcallerid[strlen(p->callerid)] = '\0';
+											p->origcid_num[strlen(p->cid_num)] = '\0';
 										}
-										strncpy(p->callerid, callerid, sizeof(p->callerid) -1);
+										if (!p->origcid_name) {
+											p->origcid_name = malloc(strlen(p->origcid_name) + 1);
+											strncpy(p->origcid_name, p->cid_name, strlen(p->cid_name)); /* safe */
+											/* make sure p->origcallerid is terminated */
+											p->origcid_name[strlen(p->cid_name)] = '\0';
+										}
+										strncpy(p->cid_num, cid_num, sizeof(p->cid_num) -1);
+										strncpy(p->cid_name, cid_name, sizeof(p->cid_name) -1);
 									}
 									/* Swap things around between the three-way and real call */
 									swap_subs(p, SUB_THREEWAY, SUB_REAL);
@@ -3853,7 +3852,10 @@
 	}
 
 	if (p->subs[index].needcallerid) {
-		ast_set_callerid(ast, !ast_strlen_zero(p->lastcallerid) ? p->lastcallerid : NULL, 1);
+		ast_set_callerid(ast, !ast_strlen_zero(p->lastcid_num) ? p->lastcid_num : NULL, 
+							!ast_strlen_zero(p->lastcid_name) ? p->lastcid_name : NULL,
+							!ast_strlen_zero(p->lastcid_num) ? p->lastcid_num : NULL
+							);
 		p->subs[index].needcallerid = 0;
 	}
 	
@@ -4033,7 +4035,7 @@
 			if (!p->faxhandled) {
 				p->faxhandled++;
 				if (strcmp(ast->exten, "fax")) {
-					if (ast_exists_extension(ast, ast->context, "fax", 1, ast->callerid)) {
+					if (ast_exists_extension(ast, ast->context, "fax", 1, ast->cid.cid_num)) {
 						if (option_verbose > 2)
 							ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name);
 						/* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
@@ -4441,15 +4443,17 @@
 		if (!ast_strlen_zero(i->exten))
 			strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
 		if (!ast_strlen_zero(i->rdnis))
-			tmp->rdnis = strdup(i->rdnis);
+			tmp->cid.cid_rdnis = strdup(i->rdnis);
 		if (!ast_strlen_zero(i->dnid))
-			tmp->dnid = strdup(i->dnid);
-		if (!ast_strlen_zero(i->callerid)) {
-			tmp->callerid = strdup(i->callerid);
-			tmp->ani = strdup(i->callerid);
+			tmp->cid.cid_dnid = strdup(i->dnid);
+		if (!ast_strlen_zero(i->cid_num)) {
+			tmp->cid.cid_num = strdup(i->cid_num);
+			tmp->cid.cid_ani = strdup(i->cid_num);
 		}
-		tmp->restrictcid = i->restrictcid;
-		tmp->callingpres = i->callingpres;
+		if (!ast_strlen_zero(i->cid_name)) {
+			tmp->cid.cid_name = strdup(i->cid_name);
+		}
+		tmp->cid.cid_pres = i->callingpres;
 #ifdef ZAPATA_PRI
 		set_calltype(tmp, ctype);
 		/* Assume calls are not idle calls unless we're told differently */
@@ -4548,7 +4552,6 @@
 	char exten[AST_MAX_EXTENSION]="";
 	char exten2[AST_MAX_EXTENSION]="";
 	unsigned char buf[256];
-	char cid[256];
 	char dtmfcid[300];
 	char dtmfbuf[300];
 	struct callerid_state *cs;
@@ -4584,12 +4587,12 @@
 		strncpy(exten, p->exten, sizeof(exten) - 1);
 		len = strlen(exten);
 		res = 0;
-		while((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, exten, 1, p->callerid)) {
+		while((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
 			if (len && !ast_ignore_pattern(chan->context, exten))
 				tone_zone_play_tone(p->subs[index].zfd, -1);
 			else
 				tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);
-			if (ast_exists_extension(chan, chan->context, exten, 1, p->callerid))
+			if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num))
 				timeout = matchdigittimeout;
 			else
 				timeout = gendigittimeout;
@@ -4604,7 +4607,7 @@
 				break;
 		}
 		tone_zone_play_tone(p->subs[index].zfd, -1);
-		if (ast_exists_extension(chan, chan->context, exten, 1, p->callerid)) {
+		if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) {
 			/* Start the real PBX */
 			strncpy(chan->exten, exten, sizeof(chan->exten) - 1);
 			ast_dsp_digitreset(p->dsp);
@@ -4710,12 +4713,12 @@
 				s1 = strsep(&stringp, "*");
 				s2 = strsep(&stringp, "*");
 				if (s2) {
-					if (!ast_strlen_zero(p->callerid))
-						chan->callerid = strdup(p->callerid);
+					if (!ast_strlen_zero(p->cid_num))
+						chan->cid.cid_num = strdup(p->cid_num);
 					else
-						chan->callerid = strdup(s1);
-					if (chan->callerid)
-						chan->ani = strdup(chan->callerid);
+						chan->cid.cid_num = strdup(s1);
+					if (chan->cid.cid_num)
+						chan->cid.cid_ani = strdup(chan->cid.cid_num);
 					strncpy(exten, s2, sizeof(exten)-1);
 				} else
 					strncpy(exten, s1, sizeof(exten)-1);
@@ -4731,12 +4734,12 @@
 				s1 = strsep(&stringp, "#");
 				s2 = strsep(&stringp, "#");
 				if (s2) {
-					if (!ast_strlen_zero(p->callerid))
-						chan->callerid = strdup(p->callerid);
+					if (!ast_strlen_zero(p->cid_num))
+						chan->cid.cid_num = strdup(p->cid_num);
 					else
-						if (*(s1 + 2)) chan->callerid = strdup(s1 + 2);
-					if (chan->callerid)
-						chan->ani = strdup(chan->callerid);
+						if (*(s1 + 2)) chan->cid.cid_num = strdup(s1 + 2);
+					if (chan->cid.cid_num)
+						chan->cid.cid_ani = strdup(chan->cid.cid_num);
 					strncpy(exten, s2 + 1, sizeof(exten)-1);
 				} else
 					strncpy(exten, s1 + 2, sizeof(exten)-1);
@@ -4752,13 +4755,13 @@
 				s1 = strsep(&stringp, "#");
 				s2 = strsep(&stringp, "#");
 				if (s2 && (*(s2 + 1) == '0')) {
-					if (*(s2 + 2)) chan->callerid = strdup(s2 + 2);
-					if (chan->callerid)
-						chan->ani = strdup(chan->callerid);
+					if (*(s2 + 2)) chan->cid.cid_num = strdup(s2 + 2);
+					if (chan->cid.cid_num)
+						chan->cid.cid_ani = strdup(chan->cid.cid_num);
 					}
 				if (s1)	strncpy(exten, s1, sizeof(exten)-1);
 				else strncpy(exten, "911", sizeof(exten) - 1);
-				printf("E911: exten: %s, ANI: %s\n",exten,chan->ani);
+				printf("E911: exten: %s, ANI: %s\n",exten, chan->cid.cid_ani);
 			} else
 				ast_log(LOG_WARNING, "Got a non-E911 input on channel %d.  Assuming E&M Wink instead\n", p->channel);
 		}
@@ -4779,7 +4782,7 @@
 		zt_enable_ec(p);
 		if ((p->sig == SIG_FEATDMF) || (p->sig == SIG_E911) || (p->sig == SIG_FEATB)) 
 			ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | p->dtmfrelax); 
-		if (ast_exists_extension(chan, chan->context, exten, 1, chan->callerid)) {
+		if (ast_exists_extension(chan, chan->context, exten, 1, chan->cid.cid_num)) {
 			strncpy(chan->exten, exten, sizeof(chan->exten)-1);
 			ast_dsp_digitreset(p->dsp);
 			res = ast_pbx_run(chan);
@@ -4835,8 +4838,8 @@
 				tone_zone_play_tone(p->subs[index].zfd, -1);
 			else
 				tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);
-			if (ast_exists_extension(chan, chan->context, exten, 1, p->callerid) && strcmp(exten, ast_parking_ext())) {
-				if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->callerid)) {
+			if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num) && strcmp(exten, ast_parking_ext())) {
+				if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
 					if (getforward) {
 						/* Record this as the forwarding extension */
 						strncpy(p->call_forward, exten, sizeof(p->call_forward) - 1); 
@@ -4855,10 +4858,14 @@
 					} else  {
 						res = tone_zone_play_tone(p->subs[index].zfd, -1);
 						strncpy(chan->exten, exten, sizeof(chan->exten)-1);
-						if (!ast_strlen_zero(p->callerid)) {
+						if (!ast_strlen_zero(p->cid_num)) {
 							if (!p->hidecallerid)
-								chan->callerid = strdup(p->callerid);
-							chan->ani = strdup(p->callerid);
+								chan->cid.cid_num = strdup(p->cid_num);
+							chan->cid.cid_ani = strdup(p->cid_num);
+						}
+						if (!ast_strlen_zero(p->cid_name)) {
+							if (!p->hidecallerid)
+								chan->cid.cid_name = strdup(p->cid_name);
 						}
 						ast_setstate(chan, AST_STATE_RING);
 						zt_enable_ec(p);
@@ -4928,9 +4935,12 @@
 					ast_verbose(VERBOSE_PREFIX_3 "Disabling Caller*ID on %s\n", chan->name);
 				/* Disable Caller*ID if enabled */
 				p->hidecallerid = 1;
-				if (chan->callerid)
-					free(chan->callerid);
-				chan->callerid = NULL;
+				if (chan->cid.cid_num)
+					free(chan->cid.cid_num);
+				chan->cid.cid_num = NULL;
+				if (chan->cid.cid_name)
+					free(chan->cid.cid_name);
+				chan->cid.cid_name = NULL;
 				res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
 				if (res) {
 					ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", 
@@ -4941,8 +4951,8 @@
 				timeout = firstdigittimeout;
 			} else if (p->callreturn && !strcmp(exten, "*69")) {
 				res = 0;
-				if (!ast_strlen_zero(p->lastcallerid)) {
-					res = ast_say_digit_str(chan, p->lastcallerid, "", chan->language);
+				if (!ast_strlen_zero(p->lastcid_num)) {
+					res = ast_say_digit_str(chan, p->lastcid_num, "", chan->language);
 				}
 				if (!res)
 					res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
@@ -4987,10 +4997,10 @@
 				if (option_verbose > 2)
 					ast_verbose(VERBOSE_PREFIX_3 "Parking call to '%s'\n", chan->name);
 				break;
-			} else if (!ast_strlen_zero(p->lastcallerid) && !strcmp(exten, "*60")) {
+			} else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
 				if (option_verbose > 2)
-					ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", p->lastcallerid);
-				res = ast_db_put("blacklist", p->lastcallerid, "1");
+					ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", p->lastcid_num);
+				res = ast_db_put("blacklist", p->lastcid_num, "1");
 				if (!res) {
 					res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
 					memset(exten, 0, sizeof(exten));
@@ -5001,10 +5011,16 @@
 					ast_verbose(VERBOSE_PREFIX_3 "Enabling Caller*ID on %s\n", chan->name);
 				/* Enable Caller*ID if enabled */
 				p->hidecallerid = 0;
-				if (chan->callerid)
-					free(chan->callerid);
-				if (!ast_strlen_zero(p->callerid))
-					chan->callerid = strdup(p->callerid);
+				if (chan->cid.cid_num)
+					free(chan->cid.cid_num);
+				chan->cid.cid_num = NULL;
+				if (chan->cid.cid_name)
+					free(chan->cid.cid_name);
+				chan->cid.cid_name = NULL;
+				if (!ast_strlen_zero(p->cid_num))
+					chan->cid.cid_num = strdup(p->cid_num);
+				if (!ast_strlen_zero(p->cid_name))
+					chan->cid.cid_name = strdup(p->cid_name);
 				res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);
 				if (res) {
 					ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n", 
@@ -5047,10 +5063,10 @@
 					ast_hangup(chan);
 					return NULL;
 				}					
-			} else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->callerid) &&
+			} else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
 							((exten[0] != '*') || (strlen(exten) > 2))) {
 				if (option_debug)
-					ast_log(LOG_DEBUG, "Can't match %s from '%s' in context %s\n", exten, chan->callerid ? chan->callerid : "<Unknown Caller>", chan->context);
+					ast_log(LOG_DEBUG, "Can't match %s from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context);
 				break;
 			}
 			if (!timeout)
@@ -5415,21 +5431,23 @@
 		}
 		else
 			cs = NULL;
-		if (name && number) {
-			snprintf(cid, sizeof(cid), "\"%s\" <%s>", name, number);
-		} else if (name) {
-			snprintf(cid, sizeof(cid), "\"%s\"", name);
-		} else if (number) {
-			snprintf(cid, sizeof(cid), "%s", number);
-		} else {
-			cid[0] = '\0';
+		if (chan->cid.cid_num) {
+			free(chan->cid.cid_num);
+			chan->cid.cid_num = NULL;
+		}
+		if (chan->cid.cid_name) {
+			free(chan->cid.cid_name);
+			chan->cid.cid_name = NULL;
 		}
+		if (number && !ast_strlen_zero(number)) {
+			chan->cid.cid_num = strdup(number);
+			chan->cid.cid_ani = strdup(number);
+		}
+		if (name && !ast_strlen_zero(name))
+			chan->cid.cid_name = strdup(name);
+
 		if (cs)
 			callerid_free(cs);
-		if (!ast_strlen_zero(cid)) {
-			chan->callerid = strdup(cid);
-			chan->ani = strdup(cid);
-		}
 		ast_setstate(chan, AST_STATE_RING);
 		chan->rings = 1;
 		p->ringt = RINGT;
@@ -6458,7 +6476,8 @@
 		strncpy(tmp->language, language, sizeof(tmp->language)-1);
 		strncpy(tmp->musicclass, musicclass, sizeof(tmp->musicclass)-1);
 		strncpy(tmp->context, context, sizeof(tmp->context)-1);
-		strncpy(tmp->callerid, callerid, sizeof(tmp->callerid)-1);
+		strncpy(tmp->cid_num, cid_num, sizeof(tmp->cid_num)-1);
+		strncpy(tmp->cid_name, cid_name, sizeof(tmp->cid_name)-1);
 		strncpy(tmp->mailbox, mailbox, sizeof(tmp->mailbox)-1);
 		tmp->msgstate = -1;
 		tmp->group = cur_group;
@@ -7552,12 +7571,12 @@
 					pri->pvts[chanpos]->call = e->ring.call;
 					/* Get caller ID */
 					if (pri->pvts[chanpos]->use_callerid) {
-						if (!ast_strlen_zero(e->ring.callingname)) {
-							snprintf(pri->pvts[chanpos]->callerid, sizeof(pri->pvts[chanpos]->callerid), "\"%s\" <%s>", e->ring.callingname, e->ring.callingnum);
-						} else
-							strncpy(pri->pvts[chanpos]->callerid, e->ring.callingnum, sizeof(pri->pvts[chanpos]->callerid)-1);
-					} else
-						pri->pvts[chanpos]->callerid[0] = '\0';
+						strncpy(pri->pvts[chanpos]->cid_num, e->ring.callingnum, sizeof(pri->pvts[chanpos]->cid_num)-1);
+						strncpy(pri->pvts[chanpos]->cid_name, e->ring.callingname, sizeof(pri->pvts[chanpos]->cid_name)-1);
+					} else {
+						pri->pvts[chanpos]->cid_num[0] = '\0';
+						pri->pvts[chanpos]->cid_name[0] = '\0';
+					}
 					strncpy(pri->pvts[chanpos]->rdnis, e->ring.redirectingnum, sizeof(pri->pvts[chanpos]->rdnis) - 1);
 					/* If immediate=yes go to s|1 */
 					if (pri->pvts[chanpos]->immediate) {
@@ -7580,8 +7599,8 @@
 						pri->pvts[chanpos]->exten[1] = '\0';
 					}
 					/* Make sure extension exists (or in overlap dial mode, can exist) */
-					if ((pri->overlapdial && ast_canmatch_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->callerid)) ||
-						ast_exists_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->callerid)) {
+					if ((pri->overlapdial && ast_canmatch_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) ||
+						ast_exists_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) {
 						/* Setup law */
 						int law;
 						if (pri->switchtype != PRI_SWITCH_GR303_TMC) {
@@ -7612,7 +7631,7 @@
 						/* Get the use_callingpres state */
 						pri->pvts[chanpos]->callingpres = e->ring.callingpres;
 						/* Start PBX */
-						if (pri->overlapdial && ast_matchmore_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->callerid)) {
+						if (pri->overlapdial && ast_matchmore_extension(NULL, pri->pvts[chanpos]->context, pri->pvts[chanpos]->exten, 1, pri->pvts[chanpos]->cid_num)) {
 							/* Release the PRI lock while we create the channel */
 							ast_mutex_unlock(&pri->lock);
 							if (crv) {
@@ -7664,7 +7683,7 @@
 					} else {
 						if (option_verbose > 2)
 							ast_verbose(VERBOSE_PREFIX_3 "Extension '%s' in context '%s' from '%s' does not exist.  Rejecting call on channel %d/%d, span %d\n",
-								pri->pvts[chanpos]->exten, pri->pvts[chanpos]->context, pri->pvts[chanpos]->callerid, pri->pvts[chanpos]->logicalspan, 
+								pri->pvts[chanpos]->exten, pri->pvts[chanpos]->context, pri->pvts[chanpos]->cid_num, pri->pvts[chanpos]->logicalspan, 
 									pri->pvts[chanpos]->prioffset, pri->span);
 						pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_UNALLOCATED);
 						pri->pvts[chanpos]->call = NULL;
@@ -7748,7 +7767,8 @@
 					} else {
 						/* Re-use *69 field for PRI */
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
-						snprintf(pri->pvts[chanpos]->lastcallerid, sizeof(pri->pvts[chanpos]->lastcallerid), "\"%s\" <%s>", e->facname.callingname, e->facname.callingnum);
+						strncpy(pri->pvts[chanpos]->lastcid_num, e->facname.callingnum, sizeof(pri->pvts[chanpos]->lastcid_num) - 1);
+						strncpy(pri->pvts[chanpos]->lastcid_name, e->facname.callingname, sizeof(pri->pvts[chanpos]->lastcid_name) - 1);
 						pri->pvts[chanpos]->subs[SUB_REAL].needcallerid =1;
 						zt_enable_ec(pri->pvts[chanpos]);
 						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
@@ -8497,7 +8517,8 @@
 			ast_cli(fd, "Extension: %s\n", tmp->exten);
 			ast_cli(fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no");
 			ast_cli(fd, "Context: %s\n", tmp->context);
-			ast_cli(fd, "Caller ID string: %s\n", tmp->callerid);
+			ast_cli(fd, "Caller ID: %s\n", tmp->cid_num);
+			ast_cli(fd, "Caller ID name: %s\n", tmp->cid_name);
 			ast_cli(fd, "Destroy: %d\n", tmp->destroy);
 			ast_cli(fd, "InAlarm: %d\n", tmp->inalarm);
 			ast_cli(fd, "Signalling Type: %s\n", sig2str(tmp->sig));
@@ -8639,7 +8660,7 @@
 	int mode = 0;
 	if (data) {
 		mode = atoi((char *)data);
-		chan->callingpres = mode;
+		chan->cid.cid_pres = mode;
 	} else
 		ast_log(LOG_NOTICE, "Application %s requres an argument: %s(number)\n", app_callingpres,app_callingpres);
 	return 0;
@@ -9253,10 +9274,12 @@
 				ast_log(LOG_WARNING, "Invalid tonezone: %s\n", v->value);
 			}
 		} else if (!strcasecmp(v->name, "callerid")) {
-			if (!strcasecmp(v->value, "asreceived"))
-				callerid[0] = '\0';
-			else
-				strncpy(callerid, v->value, sizeof(callerid)-1);
+			if (!strcasecmp(v->value, "asreceived")) {
+				cid_num[0] = '\0';
+				cid_name[0] = '\0';
+			} else {
+				ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
+			}
 		} else if (!strcasecmp(v->name, "useincomingcalleridonzaptransfer")) {
 			zaptrcallerid = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "restrictcid")) {




More information about the svn-commits mailing list