Index: channels/chan_zap.c
===================================================================
--- channels/chan_zap.c	(revision 42052)
+++ channels/chan_zap.c	(working copy)
@@ -219,8 +219,6 @@
 static int cid_signalling = CID_SIG_BELL;
 static int cid_start = CID_START_RING;
 static int zaptrcallerid = 0;
-static int cur_signalling = -1;
-static int cur_outsignalling = -1;
 
 static ast_group_t cur_group = 0;
 static ast_group_t cur_callergroup = 0;
@@ -527,6 +525,35 @@
 
 #define MAX_SLAVES	4
 
+/** 
+ * This struct is used for parsing the [channels] section of zapata.conf.
+ * Generally there is a field here for every possible configuration item.
+ *
+ * The state of fields is saved along the parsing and whenever a 'channel'
+ * statement is reached, the current zt_chan_conf is used to configure the 
+ * channel (struct zt_pvt)
+ *
+ * @seealso zt_chan_init for the default values.
+ */
+struct zt_chan_conf {
+  int immediate ; 
+  int signalling;
+  int outsignalling;
+  int radio;
+}
+
+/** returns a new zt_chan_conf with default values (by-value) */
+struct zt_chan_conf zt_chan_conf_default(void) {
+	struct zt_chan_conf chan_conf = {
+		immediate = 0,
+                signalling = -1,
+                outsignalling = -1,
+		radio = 0
+	}
+
+	return chan_conf;
+}
+
 static struct zt_pvt {
 	ast_mutex_t lock;
 	struct ast_channel *owner;			/*!< Our current active owner (if applicable) */
@@ -7020,7 +7047,7 @@
 
 #endif
 
-static struct zt_pvt *mkintf(int channel, int signalling, int outsignalling, int radio, struct zt_pri *pri, int reloading)
+static struct zt_pvt *mkintf(int channel, struct zt_chan_conf chan_conf, int radio, struct zt_pri *pri, int reloading)
 {
 	/* Make a zt_pvt structure for this interface (or CRV if "pri" is specified) */
 	struct zt_pvt *tmp = NULL, *tmp2,  *prev = NULL;
@@ -7234,23 +7261,23 @@
 			}
 #endif
 		} else {
-			signalling = tmp->sig;
-			radio = tmp->radio;
+			chan_conf.signalling = tmp->sig;
+			chan_conf.radio = tmp->radio;
 			memset(&p, 0, sizeof(p));
 			if (tmp->subs[SUB_REAL].zfd > -1)
 				res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &p);
 		}
 		/* Adjust starttime on loopstart and kewlstart trunks to reasonable values */
-		if ((signalling == SIG_FXSKS) || (signalling == SIG_FXSLS) ||
-		    (signalling == SIG_EM) || (signalling == SIG_EM_E1) ||  (signalling == SIG_EMWINK) ||
-			(signalling == SIG_FEATD) || (signalling == SIG_FEATDMF) || (signalling == SIG_FEATDMF_TA) ||
-			  (signalling == SIG_FEATB) || (signalling == SIG_E911) ||
-		    (signalling == SIG_SF) || (signalling == SIG_SFWINK) || (signalling == SIG_FGC_CAMA) || (signalling == SIG_FGC_CAMAMF) ||
-			(signalling == SIG_SF_FEATD) || (signalling == SIG_SF_FEATDMF) ||
-			  (signalling == SIG_SF_FEATB)) {
+		if ((chan_conf.signalling == SIG_FXSKS) || (chan_conf.signalling == SIG_FXSLS) ||
+		    (chan_conf.signalling == SIG_EM) || (chan_conf.signalling == SIG_EM_E1) ||  (signalling == SIG_EMWINK) ||
+			(chan_conf.signalling == SIG_FEATD) || (chan_conf.signalling == SIG_FEATDMF) || (chan_conf.signalling == SIG_FEATDMF_TA) ||
+			  (chan_conf.signalling == SIG_FEATB) || (chan_conf.signalling == SIG_E911) ||
+		    (chan_conf.signalling == SIG_SF) || (chan_conf.signalling == SIG_SFWINK) || (chan_conf.signalling == SIG_FGC_CAMA) || (chan_conf.signalling == SIG_FGC_CAMAMF) ||
+			(chan_conf.signalling == SIG_SF_FEATD) || (chan_conf.signalling == SIG_SF_FEATDMF) ||
+			  (chan_conf.signalling == SIG_SF_FEATB)) {
 			p.starttime = 250;
 		}
-		if (radio) {
+		if (chan_conf.radio) {
 			/* XXX Waiting to hear back from Jim if these should be adjustable XXX */
 			p.channo = channel;
 			p.rxwinktime = 1;
@@ -7258,7 +7285,7 @@
 			p.starttime = 1;
 			p.debouncetime = 5;
 		}
-		if (!radio) {
+		if (!chan_conf.radio) {
 			p.channo = channel;
 			/* Override timing settings based on config file */
 			if (cur_prewink >= 0)
@@ -7305,14 +7332,14 @@
 				ast_log(LOG_WARNING, "Unable to check buffer policy on channel %d\n", channel);
 		}
 #endif
-		tmp->immediate = immediate;
+		tmp->immediate = chan_conf.immediate;
 		tmp->transfertobusy = transfertobusy;
-		tmp->sig = signalling;
-		tmp->outsigmod = outsignalling;
-		tmp->radio = radio;
+		tmp->sig = chan_conf.signalling;
+		tmp->outsigmod = chan_conf.outsignalling;
+		tmp->radio = chan_conf.radio;
 		tmp->ringt_base = ringt_base;
 		tmp->firstradio = 0;
-		if ((signalling == SIG_FXOKS) || (signalling == SIG_FXOLS) || (signalling == SIG_FXOGS))
+		if ((chan_conf.signalling == SIG_FXOKS) || (chan_conf.signalling == SIG_FXOLS) || (chan_conf.signalling == SIG_FXOGS))
 			tmp->permcallwaiting = callwaiting;
 		else
 			tmp->permcallwaiting = 0;
@@ -7401,7 +7428,7 @@
 				ast_dsp_digitmode(tmp->dsp, DSP_DIGITMODE_DTMF | tmp->dtmfrelax);
 			update_conf(tmp);
 			if (!here) {
-				if (signalling != SIG_PRI)
+				if (chan_conf.signalling != SIG_PRI)
 					/* Hang it up to be sure it's good */
 					zt_set_hook(tmp->subs[SUB_REAL].zfd, ZT_ONHOOK);
 			}
@@ -10293,7 +10320,7 @@
 	int start, finish,x;
 	int y;
 	int found_pseudo = 0;
-	int cur_radio = 0;
+	struct zt_chan_conf chan_conf = zt_chan_conf_default();
 #ifdef HAVE_PRI
 	int spanno;
 	int i;
@@ -10387,7 +10414,7 @@
 #endif			
 					) {
 			if (reload == 0) {
-				if (cur_signalling < 0) {
+				if (chan_conf.signalling < 0) {
 					ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n");
 					ast_config_destroy(cfg);
 					ast_mutex_unlock(&iflock);
@@ -10448,12 +10475,13 @@
 					finish = start;
 					start = x;
 				}
-				if (cur_outsignalling < 0) cur_outsignalling = cur_signalling;
+				if (chan_conf.outsignalling < 0) 
+					chan_conf.outsignalling = chan_conf.signalling;
 				for (x = start; x <= finish; x++) {
 #ifdef HAVE_PRI
-					tmp = mkintf(x, cur_signalling, cur_outsignalling, cur_radio, pri, reload);
+					tmp = mkintf(x, chan_conf, pri, reload);
 #else					
-					tmp = mkintf(x, cur_signalling, cur_outsignalling, cur_radio, NULL, reload);
+					tmp = mkintf(x, chan_conf, NULL, reload);
 #endif					
 
 					if (tmp) {
@@ -10622,7 +10650,7 @@
 		} else if (!strcasecmp(v->name, "pickupgroup")) {
 			cur_pickupgroup = ast_get_group(v->value);
 		} else if (!strcasecmp(v->name, "immediate")) {
-			immediate = ast_true(v->value);
+			chan_conf.immediate = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "transfertobusy")) {
 			transfertobusy = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "rxgain")) {
@@ -10660,123 +10688,123 @@
 				amaflags = y;
 		} else if (!reload){ 
 			 if (!strcasecmp(v->name, "signalling")) {
-				cur_outsignalling = -1;
+				chan_conf.outsignalling = -1;
 				if (!strcasecmp(v->value, "em")) {
-					cur_signalling = SIG_EM;
+					chan_conf.signalling = SIG_EM;
 				} else if (!strcasecmp(v->value, "em_e1")) {
-					cur_signalling = SIG_EM_E1;
+					chan_conf.signalling = SIG_EM_E1;
 				} else if (!strcasecmp(v->value, "em_w")) {
-					cur_signalling = SIG_EMWINK;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_EMWINK;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fxs_ls")) {
-					cur_signalling = SIG_FXSLS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FXSLS;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fxs_gs")) {
-					cur_signalling = SIG_FXSGS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FXSGS;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fxs_ks")) {
-					cur_signalling = SIG_FXSKS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FXSKS;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fxo_ls")) {
-					cur_signalling = SIG_FXOLS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FXOLS;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fxo_gs")) {
-					cur_signalling = SIG_FXOGS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FXOGS;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fxo_ks")) {
-					cur_signalling = SIG_FXOKS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FXOKS;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fxs_rx")) {
-					cur_signalling = SIG_FXSKS;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_FXSKS;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "fxo_rx")) {
-					cur_signalling = SIG_FXOLS;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_FXOLS;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "fxs_tx")) {
-					cur_signalling = SIG_FXSLS;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_FXSLS;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "fxo_tx")) {
-					cur_signalling = SIG_FXOGS;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_FXOGS;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "em_rx")) {
-					cur_signalling = SIG_EM;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_EM;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "em_tx")) {
-					cur_signalling = SIG_EM;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_EM;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "em_rxtx")) {
-					cur_signalling = SIG_EM;
-					cur_radio = 2;
+					chan_conf.signalling = SIG_EM;
+					chan_conf.radio = 2;
 				} else if (!strcasecmp(v->value, "em_txrx")) {
-					cur_signalling = SIG_EM;
-					cur_radio = 2;
+					chan_conf.signalling = SIG_EM;
+					chan_conf.radio = 2;
 				} else if (!strcasecmp(v->value, "sf")) {
-					cur_signalling = SIG_SF;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_SF;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "sf_w")) {
-					cur_signalling = SIG_SFWINK;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_SFWINK;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "sf_featd")) {
-					cur_signalling = SIG_FEATD;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FEATD;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "sf_featdmf")) {
-					cur_signalling = SIG_FEATDMF;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FEATDMF;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "sf_featb")) {
-					cur_signalling = SIG_SF_FEATB;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_SF_FEATB;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "sf")) {
-					cur_signalling = SIG_SF;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_SF;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "sf_rx")) {
-					cur_signalling = SIG_SF;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_SF;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "sf_tx")) {
-					cur_signalling = SIG_SF;
-					cur_radio = 1;
+					chan_conf.signalling = SIG_SF;
+					chan_conf.radio = 1;
 				} else if (!strcasecmp(v->value, "sf_rxtx")) {
-					cur_signalling = SIG_SF;
-					cur_radio = 2;
+					chan_conf.signalling = SIG_SF;
+					chan_conf.radio = 2;
 				} else if (!strcasecmp(v->value, "sf_txrx")) {
-					cur_signalling = SIG_SF;
-					cur_radio = 2;
+					chan_conf.signalling = SIG_SF;
+					chan_conf.radio = 2;
 				} else if (!strcasecmp(v->value, "featd")) {
-					cur_signalling = SIG_FEATD;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FEATD;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "featdmf")) {
-					cur_signalling = SIG_FEATDMF;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FEATDMF;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "featdmf_ta")) {
-					cur_signalling = SIG_FEATDMF_TA;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FEATDMF_TA;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "e911")) {
-					cur_signalling = SIG_E911;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_E911;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fgccama")) {
-					cur_signalling = SIG_FGC_CAMA;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FGC_CAMA;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "fgccamamf")) {
-					cur_signalling = SIG_FGC_CAMAMF;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FGC_CAMAMF;
+					chan_conf.radio = 0;
 				} else if (!strcasecmp(v->value, "featb")) {
-					cur_signalling = SIG_FEATB;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_FEATB;
+					chan_conf.radio = 0;
 #ifdef HAVE_PRI
 				} else if (!strcasecmp(v->value, "pri_net")) {
-					cur_radio = 0;
-					cur_signalling = SIG_PRI;
+					chan_conf.radio = 0;
+					chan_conf.signalling = SIG_PRI;
 					pritype = PRI_NETWORK;
 				} else if (!strcasecmp(v->value, "pri_cpe")) {
-					cur_signalling = SIG_PRI;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_PRI;
+					chan_conf.radio = 0;
 					pritype = PRI_CPE;
 				} else if (!strcasecmp(v->value, "gr303fxoks_net")) {
-					cur_signalling = SIG_GR303FXOKS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_GR303FXOKS;
+					chan_conf.radio = 0;
 					pritype = PRI_NETWORK;
 				} else if (!strcasecmp(v->value, "gr303fxsks_cpe")) {
-					cur_signalling = SIG_GR303FXSKS;
-					cur_radio = 0;
+					chan_conf.signalling = SIG_GR303FXSKS;
+					chan_conf.radio = 0;
 					pritype = PRI_CPE;
 #endif
 				} else {
@@ -10784,37 +10812,37 @@
 				}
 			 } else if (!strcasecmp(v->name, "outsignalling")) {
 				if (!strcasecmp(v->value, "em")) {
-					cur_outsignalling = SIG_EM;
+					chan_conf.outsignalling = SIG_EM;
 				} else if (!strcasecmp(v->value, "em_e1")) {
-					cur_outsignalling = SIG_EM_E1;
+					chan_conf.outsignalling = SIG_EM_E1;
 				} else if (!strcasecmp(v->value, "em_w")) {
-					cur_outsignalling = SIG_EMWINK;
+					chan_conf.outsignalling = SIG_EMWINK;
 				} else if (!strcasecmp(v->value, "sf")) {
-					cur_outsignalling = SIG_SF;
+					chan_conf.outsignalling = SIG_SF;
 				} else if (!strcasecmp(v->value, "sf_w")) {
-					cur_outsignalling = SIG_SFWINK;
+					chan_conf.outsignalling = SIG_SFWINK;
 				} else if (!strcasecmp(v->value, "sf_featd")) {
-					cur_outsignalling = SIG_FEATD;
+					chan_conf.outsignalling = SIG_FEATD;
 				} else if (!strcasecmp(v->value, "sf_featdmf")) {
-					cur_outsignalling = SIG_FEATDMF;
+					chan_conf.outsignalling = SIG_FEATDMF;
 				} else if (!strcasecmp(v->value, "sf_featb")) {
-					cur_outsignalling = SIG_SF_FEATB;
+					chan_conf.outsignalling = SIG_SF_FEATB;
 				} else if (!strcasecmp(v->value, "sf")) {
-					cur_outsignalling = SIG_SF;
+					chan_conf.outsignalling = SIG_SF;
 				} else if (!strcasecmp(v->value, "featd")) {
-					cur_outsignalling = SIG_FEATD;
+					chan_conf.outsignalling = SIG_FEATD;
 				} else if (!strcasecmp(v->value, "featdmf")) {
-					cur_outsignalling = SIG_FEATDMF;
+					chan_conf.outsignalling = SIG_FEATDMF;
 				} else if (!strcasecmp(v->value, "featdmf_ta")) {
-					cur_outsignalling = SIG_FEATDMF_TA;
+					chan_conf.outsignalling = SIG_FEATDMF_TA;
 				} else if (!strcasecmp(v->value, "e911")) {
-					cur_outsignalling = SIG_E911;
+					chan_conf.outsignalling = SIG_E911;
 				} else if (!strcasecmp(v->value, "fgccama")) {
-					cur_outsignalling = SIG_FGC_CAMA;
+					chan_conf.outsignalling = SIG_FGC_CAMA;
 				} else if (!strcasecmp(v->value, "fgccamamf")) {
-					cur_outsignalling = SIG_FGC_CAMAMF;
+					chan_conf.outsignalling = SIG_FGC_CAMAMF;
 				} else if (!strcasecmp(v->value, "featb")) {
-					cur_outsignalling = SIG_FEATB;
+					chan_conf.outsignalling = SIG_FEATB;
 				} else {
 					ast_log(LOG_ERROR, "Unknown signalling method '%s'\n", v->value);
 				}
@@ -11094,7 +11122,8 @@
 		cur_callergroup = 0;
 		cur_pickupgroup = 0;
 	
-		tmp = mkintf(CHAN_PSEUDO, cur_signalling, cur_signalling, cur_radio, NULL, reload);
+		chan_conf.cur_outsignalling = chan_conf.cur_signalling;
+		tmp = mkintf(CHAN_PSEUDO, chan_conf, NULL, reload);
 
 		if (tmp) {
 			if (option_verbose > 2)
