[asterisk-commits] nadi: branch crichter/0.4.0 r39294 - in /team/crichter/0.4.0: ./ channels/ ch...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Aug 8 01:28:31 MST 2006


Author: nadi
Date: Tue Aug  8 03:28:30 2006
New Revision: 39294

URL: http://svn.digium.com/view/asterisk?rev=39294&view=rev
Log:
fail on misdn_cfg_init() if elements in the config enum don't match with the config structs in misdn_config.c

Modified:
    team/crichter/0.4.0/Makefile
    team/crichter/0.4.0/channels/chan_misdn.c
    team/crichter/0.4.0/channels/misdn/chan_misdn_config.h
    team/crichter/0.4.0/channels/misdn_config.c

Modified: team/crichter/0.4.0/Makefile
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/Makefile?rev=39294&r1=39293&r2=39294&view=diff
==============================================================================
--- team/crichter/0.4.0/Makefile (original)
+++ team/crichter/0.4.0/Makefile Tue Aug  8 03:28:30 2006
@@ -924,7 +924,7 @@
 	make -C channels/misdn clean
 	
 cm-cleaner: cm-clean
-	rm -f channels/chan_misdn_config.o
+	rm -f channels/misdn_config.o
 	rm -f channels/chan_misdn.o
 	rm -f channels/chan_misdn.so
 

Modified: team/crichter/0.4.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/chan_misdn.c?rev=39294&r1=39293&r2=39294&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/chan_misdn.c (original)
+++ team/crichter/0.4.0/channels/chan_misdn.c Tue Aug  8 03:28:30 2006
@@ -4483,8 +4483,10 @@
 		return -1;
 	}
 	
-	
-	misdn_cfg_init(max_ports);
+	if (misdn_cfg_init(max_ports)) {
+		ast_log(LOG_ERROR, "Unable to initialize misdn_config.\n");
+		return -1;
+	}
 	g_config_initialized=1;
 	
 	misdn_debug = (int *)malloc(sizeof(int) * (max_ports+1));

Modified: team/crichter/0.4.0/channels/misdn/chan_misdn_config.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/chan_misdn_config.h?rev=39294&r1=39293&r2=39294&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/chan_misdn_config.h (original)
+++ team/crichter/0.4.0/channels/misdn/chan_misdn_config.h Tue Aug  8 03:28:30 2006
@@ -102,7 +102,7 @@
 };
 
 /* you must call misdn_cfg_init before any other function of this header file */
-void misdn_cfg_init(int max_ports); 
+int misdn_cfg_init(int max_ports); 
 void misdn_cfg_reload(void);
 void misdn_cfg_destroy(void);
 

Modified: team/crichter/0.4.0/channels/misdn_config.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn_config.c?rev=39294&r1=39293&r2=39294&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn_config.c (original)
+++ team/crichter/0.4.0/channels/misdn_config.c Tue Aug  8 03:28:30 2006
@@ -206,7 +206,7 @@
 	{ "nodialtone", MISDN_CFG_NODIALTONE, MISDN_CTYPE_BOOL, "no", NONE,
 		"Enable this to prevent chan_misdn to generate the dialtone\n"
 		"\tThis makes only sense together with the always_immediate=yes option\n"
-		"\tto generate your own dialtone with Playtones or so.\n"},
+		"\tto generate your own dialtone with Playtones or so."},
 	{ "immediate", MISDN_CFG_IMMEDIATE, MISDN_CTYPE_BOOL, "no", NONE,
 		"Enable this if you want callers which called exactly the base\n"
 		"\tnumber (so no extension is set) to jump into the s extension.\n"
@@ -356,28 +356,41 @@
 		"Please edit your misdn.conf and then do a \"misdn reload\".\n", name, value, section); \
 })
 
-static void _enum_array_map (void)
-{
-	int i, j;
+static int _enum_array_map (void)
+{
+	int i, j, ok;
 
 	for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
 		if (i == MISDN_CFG_PTP)
 			continue;
+		ok = 0;
 		for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
 			if (port_spec[j].elem == i) {
 				map[i] = j;
+				ok = 1;
 				break;
 			}
 		}
+		if (!ok) {
+			ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i);
+			return -1;
+		}
 	}
 	for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
+		ok = 0;
 		for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
 			if (gen_spec[j].elem == i) {
 				map[i] = j;
+				ok = 1;
 				break;
 			}
 		}
-	}
+		if (!ok) {
+			ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i);
+			return -1;
+		}
+	}
+	return 0;
 }
 
 static int get_cfg_position (char *name, int type)
@@ -1012,7 +1025,7 @@
 	ast_mutex_destroy(&config_mutex);
 }
 
-void misdn_cfg_init (int this_max_ports)
+int misdn_cfg_init (int this_max_ports)
 {
 	char config[] = "misdn.conf";
 	char *cat, *p;
@@ -1021,8 +1034,8 @@
 	struct ast_variable *v;
 
 	if (!(cfg = AST_LOAD_CFG(config))) {
-		ast_log(LOG_WARNING,"no misdn.conf ?\n");
-		return;
+		ast_log(LOG_WARNING, "missing file: misdn.conf\n");
+		return -1;
 	}
 
 	ast_mutex_init(&config_mutex);
@@ -1032,6 +1045,9 @@
 	if (this_max_ports) {
 		/* this is the first run */
 		max_ports = this_max_ports;
+		map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
+		if (_enum_array_map())
+			return -1;
 		p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
 						   + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
 		port_cfg = (union misdn_cfg_pt **)p;
@@ -1042,8 +1058,6 @@
 		}
 		general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
 		ptp = (int *)calloc(max_ports + 1, sizeof(int));
-		map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
-		_enum_array_map();
 	}
 	else {
 		/* misdn reload */
@@ -1058,18 +1072,20 @@
 
 	while(cat) {
 		v = ast_variable_browse(cfg, cat);
-		if (!strcasecmp(cat,"general")) {
+		if (!strcasecmp(cat, "general")) {
 			_build_general_config(v);
 		} else {
 			_build_port_config(v, cat);
 		}
-		cat = ast_category_browse(cfg,cat);
+		cat = ast_category_browse(cfg, cat);
 	}
 
 	_fill_defaults();
 
 	misdn_cfg_unlock();
 	AST_DESTROY_CFG(cfg);
-}
-
-
+
+	return 0;
+}
+
+



More information about the asterisk-commits mailing list