Index: channels/chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.405
diff -u -r1.405 chan_zap.c
--- channels/chan_zap.c	28 Jan 2005 05:19:06 -0000	1.405
+++ channels/chan_zap.c	2 Feb 2005 17:49:55 -0000
@@ -248,6 +248,11 @@
 static char idleext[AST_MAX_EXTENSION];
 static char idledial[AST_MAX_EXTENSION];
 static int overlapdial = 0;
+static char internationalprefix[256] = "";
+static char nationalprefix[256] = "";
+static char localprefix[256] = "";
+static char privateprefix[256] = "";
+static char unknownprefix[256] = "";
 static struct ast_channel inuse = { "GR-303InUse" };
 #ifdef PRI_GETSET_TIMERS
 static int pritimers[PRI_MAX_TIMERS];
@@ -475,6 +480,7 @@
 	char language[MAX_LANGUAGE];
 	char musicclass[MAX_LANGUAGE];
 	char cid_num[AST_MAX_EXTENSION];
+	int cid_ton;				/* Type Of Number (TON) */
 	char cid_name[AST_MAX_EXTENSION];
 	char lastcid_num[AST_MAX_EXTENSION];
 	char lastcid_name[AST_MAX_EXTENSION];
@@ -503,9 +509,9 @@
 	int hidecallerid;
 	int callreturn;
 	int permhidecallerid;		/* Whether to hide our outgoing caller ID or not */
-	int restrictcid;		/* Whether restrict the callerid -> only send ANI */
+	int restrictcid;			/* Whether restrict the callerid -> only send ANI */
 	int use_callingpres;		/* Whether to use the callingpres the calling switch sends */
-	int callingpres;		/* The value of callling presentation that we're going to use when placing a PRI call */
+	int callingpres;			/* The value of callling presentation that we're going to use when placing a PRI call */
 	int callwaitingrepeat;		/* How many samples to wait before repeating call waiting */
 	int cidcwexpire;			/* When to expire our muting for CID/CW */
 	unsigned char *cidspill;
@@ -544,7 +550,7 @@
 	int inalarm;
 	char accountcode[20];		/* Account code */
 	int amaflags;				/* AMA Flags */
-	char didtdd;			/* flag to say its done it once */
+	char didtdd;				/* flag to say its done it once */
 	struct tdd_state *tdd;		/* TDD flag */
 	int adsi;
 	int cancallforward;
@@ -554,17 +560,17 @@
 	int onhooktime;
 	int msgstate;
 	
-	int confirmanswer;		/* Wait for '#' to confirm answer */
-	int distinctivering;	/* Which distinctivering to use */
-	int cidrings;			/* Which ring to deliver CID on */
-	
-	int faxhandled;			/* Has a fax tone already been handled? */
-	
-	char mate;			/* flag to say its in MATE mode */
-	int pulsedial;		/* whether a pulse dial phone is detected */
-	int dtmfrelax;		/* whether to run in relaxed DTMF mode */
+	int confirmanswer;			/* Wait for '#' to confirm answer */
+	int distinctivering;		/* Which distinctivering to use */
+	int cidrings;				/* Which ring to deliver CID on */
+	
+	int faxhandled;				/* Has a fax tone already been handled? */
+	
+	char mate;					/* flag to say its in MATE mode */
+	int pulsedial;				/* whether a pulse dial phone is detected */
+	int dtmfrelax;				/* whether to run in relaxed DTMF mode */
 	int fake_event;
-	int zaptrcallerid;	/* should we use the callerid from incoming call on zap transfer or not */
+	int zaptrcallerid;			/* should we use the callerid from incoming call on zap transfer or not */
 	int emdigitwait;
 	int hanguponpolarityswitch;
 	int polarityonanswerdelay;
@@ -581,8 +587,13 @@
 	int logicalspan;
 	int alreadyhungup;
 	int proceeding;
-	int setup_ack;		/* wheter we received SETUP_ACKNOWLEDGE or not */
+	int setup_ack;				/* whether we received SETUP_ACKNOWLEDGE or not */
 	int dsp_features;
+	char internationalprefix[256];	/* country access code ('00' for european dialplans) */
+	char nationalprefix[256];		/* area access code ('0' for european dialplans) */
+	char localprefix[256];			/* area access code + area code ('0'+area code for european dialplans) */
+	char privateprefix[256];		/* for private dialplans */
+	char unknownprefix[256];		/* for unknown dialplans */
 #endif	
 #ifdef ZAPATA_R2
 	int r2prot;
@@ -4636,6 +4647,7 @@
 
 		ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
 		tmp->cid.cid_pres = i->callingpres;
+		tmp->cid.cid_ton = i->cid_ton;
 #ifdef ZAPATA_PRI
 		set_calltype(tmp, ctype);
 		/* Assume calls are not idle calls unless we're told differently */
@@ -6617,6 +6629,11 @@
 		tmp->restrictcid = restrictcid;
 		tmp->use_callingpres = use_callingpres;
 		tmp->priindication_oob = priindication_oob;
+		strncpy(tmp->internationalprefix, internationalprefix, sizeof(tmp->internationalprefix)-1);
+		strncpy(tmp->nationalprefix, nationalprefix, sizeof(tmp->nationalprefix)-1);
+		strncpy(tmp->localprefix, localprefix, sizeof(tmp->localprefix)-1);
+		strncpy(tmp->privateprefix, privateprefix, sizeof(tmp->privateprefix)-1);
+		strncpy(tmp->unknownprefix, unknownprefix, sizeof(tmp->unknownprefix)-1);
 		tmp->emdigitwait = cur_emdigitwait;
 		if (tmp->usedistinctiveringdetection) {
 			if (!tmp->use_callerid) {
@@ -6638,6 +6655,7 @@
 		strncpy(tmp->musicclass, musicclass, sizeof(tmp->musicclass)-1);
 		strncpy(tmp->context, context, sizeof(tmp->context)-1);
 		strncpy(tmp->cid_num, cid_num, sizeof(tmp->cid_num)-1);
+		tmp->cid_ton = 0;
 		strncpy(tmp->cid_name, cid_name, sizeof(tmp->cid_name)-1);
 		strncpy(tmp->mailbox, mailbox, sizeof(tmp->mailbox)-1);
 		tmp->msgstate = -1;
@@ -7358,6 +7376,7 @@
 	pthread_t threadid;
 	pthread_attr_t attr;
 	char ani2str[6];
+	char plancallingnum[256];
 	
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -7727,13 +7746,36 @@
 					}
 					pri->pvts[chanpos]->call = e->ring.call;
 					/* Get caller ID */
+					switch (e->ring.callingplan) {
+						case PRI_INTERNATIONAL_ISDN:	/* Q.931 dialplan == 0x11 international dialplan => prepend international prefix digits */
+							snprintf(plancallingnum, sizeof(plancallingnum)-1, "%s%s", pri->pvts[chanpos]->internationalprefix, e->ring.callingnum);
+							break;
+						case PRI_NATIONAL_ISDN:			/* Q.931 dialplan == 0x21 national dialplan => prepend national prefix digits */
+							snprintf(plancallingnum, sizeof(plancallingnum)-1, "%s%s", pri->pvts[chanpos]->nationalprefix, e->ring.callingnum);
+							break;
+						case PRI_LOCAL_ISDN:			/* Q.931 dialplan == 0x41 local dialplan => prepend local prefix digits */
+							snprintf(plancallingnum, sizeof(plancallingnum)-1, "%s%s", pri->pvts[chanpos]->localprefix, e->ring.callingnum);
+							break;
+						case PRI_PRIVATE:				/* Q.931 dialplan == 0x49 private dialplan => prepend private prefix digits */
+							snprintf(plancallingnum, sizeof(plancallingnum)-1, "%s%s", pri->pvts[chanpos]->privateprefix, e->ring.callingnum);
+							break;
+						case PRI_UNKNOWN:				/* Q.931 dialplan == 0x00 unknown dialplan => prepend unknown prefix digits */
+							snprintf(plancallingnum, sizeof(plancallingnum)-1, "%s%s", pri->pvts[chanpos]->unknownprefix, e->ring.callingnum);
+							break;
+						default:						/* other Q.931 dialplan => don't twiddle with callingnum */
+							snprintf(plancallingnum, sizeof(plancallingnum)-1, "%s", e->ring.callingnum);
+							break;
+					}
 					if (pri->pvts[chanpos]->use_callerid) {
-						ast_shrink_phone_number(e->ring.callingnum);
-						strncpy(pri->pvts[chanpos]->cid_num, e->ring.callingnum, sizeof(pri->pvts[chanpos]->cid_num)-1);
+						ast_shrink_phone_number(plancallingnum);
+						strncpy(pri->pvts[chanpos]->cid_num, plancallingnum, sizeof(pri->pvts[chanpos]->cid_num)-1);
 						strncpy(pri->pvts[chanpos]->cid_name, e->ring.callingname, sizeof(pri->pvts[chanpos]->cid_name)-1);
+/*						pri->pvts[chanpos]->cid_ton = e->ring.callingplan>>4; this is the real type of number (ton) */
+						pri->pvts[chanpos]->cid_ton = e->ring.callingplan; /* this is the callingplan */
 					} else {
 						pri->pvts[chanpos]->cid_num[0] = '\0';
 						pri->pvts[chanpos]->cid_name[0] = '\0';
+						pri->pvts[chanpos]->cid_ton = 0;
 					}
 					strncpy(pri->pvts[chanpos]->rdnis, e->ring.redirectingnum, sizeof(pri->pvts[chanpos]->rdnis) - 1);
 					/* If immediate=yes go to s|1 */
@@ -7836,7 +7878,7 @@
 							if (c && !ast_pthread_create(&threadid, &attr, ss_thread, c)) {
 								if (option_verbose > 2)
 									ast_verbose(VERBOSE_PREFIX_3 "Accepting overlap call from '%s' to '%s' on channel %d/%d, span %d\n",
-										e->ring.callingnum, !ast_strlen_zero(pri->pvts[chanpos]->exten) ? pri->pvts[chanpos]->exten : "<unspecified>", 
+										plancallingnum, !ast_strlen_zero(pri->pvts[chanpos]->exten) ? pri->pvts[chanpos]->exten : "<unspecified>", 
 										pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
 							} else {
 								ast_log(LOG_WARNING, "Unable to start PBX on channel %d/%d, span %d\n", 
@@ -7860,7 +7902,7 @@
 								}
 								if (option_verbose > 2)
 									ast_verbose(VERBOSE_PREFIX_3 "Accepting call from '%s' to '%s' on channel %d/%d, span %d\n",
-										e->ring.callingnum, pri->pvts[chanpos]->exten, 
+										plancallingnum, pri->pvts[chanpos]->exten, 
 											pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset, pri->span);
 								zt_enable_ec(pri->pvts[chanpos]);
 							} else {
@@ -8791,6 +8833,7 @@
 			ast_cli(fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no");
 			ast_cli(fd, "Context: %s\n", tmp->context);
 			ast_cli(fd, "Caller ID: %s\n", tmp->cid_num);
+			ast_cli(fd, "Caller ID ton: %d\n", tmp->cid_ton);
 			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);
@@ -9772,6 +9815,16 @@
 				else
 					ast_log(LOG_WARNING, "'%s' is not a valid pri indication value, should be 'inband' or 'outofband' at line %d\n",
 						v->value, v->lineno);
+			} else if (!strcasecmp(v->name, "internationalprefix")) {
+				strncpy(internationalprefix, v->value, sizeof(internationalprefix)-1);
+			} else if (!strcasecmp(v->name, "nationalprefix")) {
+				strncpy(nationalprefix, v->value, sizeof(nationalprefix)-1);
+			} else if (!strcasecmp(v->name, "localprefix")) {
+				strncpy(localprefix, v->value, sizeof(localprefix)-1);
+			} else if (!strcasecmp(v->name, "privateprefix")) {
+				strncpy(privateprefix, v->value, sizeof(privateprefix)-1);
+			} else if (!strcasecmp(v->name, "unknownprefix")) {
+				strncpy(unknownprefix, v->value, sizeof(unknownprefix)-1);
 			} else if (!strcasecmp(v->name, "minunused")) {
 				minunused = atoi(v->value);
 			} else if (!strcasecmp(v->name, "idleext")) {
Index: configs/zapata.conf.sample
===================================================================
RCS file: /usr/cvsroot/asterisk/configs/zapata.conf.sample,v
retrieving revision 1.38
diff -u -r1.38 zapata.conf.sample
--- configs/zapata.conf.sample	21 Jan 2005 01:44:16 -0000	1.38
+++ configs/zapata.conf.sample	2 Feb 2005 17:49:56 -0000
@@ -76,6 +76,23 @@
 ;
 ;prilocaldialplan=national
 ;
+; PRI callerid prefixes based on the given TON/NPI (dialplan)
+; This is especially needed for euroisdn E1-PRIs
+; 
+; sample 1 for Germany 
+;internationalprefix = 00
+;nationalprefix = 0
+;localprefix = 0711
+;privateprefix = 07115678
+;unknownprefix = 
+;
+; sample 2 for Germany 
+;internationalprefix = +
+;nationalprefix = +49
+;localprefix = +49711
+;privateprefix = +497115678
+;unknownprefix = 
+;
 ; Overlap dialing mode (sending overlap digits)
 ;
 ;overlapdial=yes
