[asterisk-commits] jpeeler: trunk r132425 - /trunk/channels/chan_dahdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 21 10:33:14 CDT 2008


Author: jpeeler
Date: Mon Jul 21 10:33:13 2008
New Revision: 132425

URL: http://svn.digium.com/view/asterisk?view=rev&rev=132425
Log:
make buffers config option (chan_dahdi.conf) parsing safer and added logging in case of failure

Modified:
    trunk/channels/chan_dahdi.c

Modified: trunk/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_dahdi.c?view=diff&rev=132425&r1=132424&r2=132425
==============================================================================
--- trunk/channels/chan_dahdi.c (original)
+++ trunk/channels/chan_dahdi.c Mon Jul 21 10:33:13 2008
@@ -13776,7 +13776,6 @@
 static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct ast_variable *v, int reload, int options)
 {
 	struct dahdi_pvt *tmp;
-	const char *tempstr; /* temporary string for parsing the dring number, buffers policy */
 	int y;
 	int found_pseudo = 0;
 	char dahdichan[MAX_CHANLIST_LEN] = {};
@@ -13803,17 +13802,24 @@
  			if (build_channels(confp, iscrv, v->value, reload, v->lineno, &found_pseudo))
  					return -1;
 		} else if (!strcasecmp(v->name, "buffers")) {
-			char policy[8];
-			tempstr = v->value;
-			sscanf(tempstr, "%d,%s", &confp->chan.buf_no, policy);
+			int res;
+			char policy[8] = "";
+			res = sscanf(v->value, "%d,%s", &confp->chan.buf_no, policy);
+			if (res != 2) {
+				ast_log(LOG_WARNING, "Parsing buffers option data failed, using defaults.\n");
+				confp->chan.buf_no = numbufs;
+				continue;
+			}
 			if (confp->chan.buf_no < 0)
 				confp->chan.buf_no = numbufs;
 			if (!strcasecmp(policy, "full")) {
 				confp->chan.buf_policy = DAHDI_POLICY_WHEN_FULL;
 			} else if (!strcasecmp(policy, "half")) {
 				confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE /*HALF_FULL*/;
+			} else if (!strcasecmp(policy, "immediate")) {
+				confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE;
 			} else {
-				confp->chan.buf_policy = DAHDI_POLICY_IMMEDIATE;
+				ast_log(LOG_WARNING, "Invalid policy name given (%s).\n", policy);
 			}
  		} else if (!strcasecmp(v->name, "dahdichan")) {
  			ast_copy_string(dahdichan, v->value, sizeof(dahdichan));
@@ -13834,14 +13840,11 @@
 		} else if (!strcasecmp(v->name, "dring3range")) {
 			confp->chan.drings.ringnum[2].range = atoi(v->value);
 		} else if (!strcasecmp(v->name, "dring1")) {
-			tempstr = v->value;
-			sscanf(tempstr, "%d,%d,%d", &confp->chan.drings.ringnum[0].ring[0], &confp->chan.drings.ringnum[0].ring[1], &confp->chan.drings.ringnum[0].ring[2]);
+			sscanf(v->value, "%d,%d,%d", &confp->chan.drings.ringnum[0].ring[0], &confp->chan.drings.ringnum[0].ring[1], &confp->chan.drings.ringnum[0].ring[2]);
 		} else if (!strcasecmp(v->name, "dring2")) {
-			tempstr = v->value;
-			sscanf(tempstr,"%d,%d,%d", &confp->chan.drings.ringnum[1].ring[0], &confp->chan.drings.ringnum[1].ring[1], &confp->chan.drings.ringnum[1].ring[2]);
+			sscanf(v->value,"%d,%d,%d", &confp->chan.drings.ringnum[1].ring[0], &confp->chan.drings.ringnum[1].ring[1], &confp->chan.drings.ringnum[1].ring[2]);
 		} else if (!strcasecmp(v->name, "dring3")) {
-			tempstr = v->value;
-			sscanf(tempstr, "%d,%d,%d", &confp->chan.drings.ringnum[2].ring[0], &confp->chan.drings.ringnum[2].ring[1], &confp->chan.drings.ringnum[2].ring[2]);
+			sscanf(v->value, "%d,%d,%d", &confp->chan.drings.ringnum[2].ring[0], &confp->chan.drings.ringnum[2].ring[1], &confp->chan.drings.ringnum[2].ring[2]);
 		} else if (!strcasecmp(v->name, "usecallerid")) {
 			confp->chan.use_callerid = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "cidsignalling")) {




More information about the asterisk-commits mailing list