[svn-commits] branch crichter/config-update - r7815 in /team/crichter/config-update/channel...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Jan 5 05:21:56 CST 2006


Author: crichter
Date: Thu Jan  5 05:21:53 2006
New Revision: 7815

URL: http://svn.digium.com/view/asterisk?rev=7815&view=rev
Log:
the new config engine should be all-ready now. minor bugs may still exist though...

Modified:
    team/crichter/config-update/channels/chan_misdn.c
    team/crichter/config-update/channels/chan_misdn_config.c
    team/crichter/config-update/channels/misdn/chan_misdn_config.h

Modified: team/crichter/config-update/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/config-update/channels/chan_misdn.c?rev=7815&r1=7814&r2=7815&view=diff
==============================================================================
--- team/crichter/config-update/channels/chan_misdn.c (original)
+++ team/crichter/config-update/channels/chan_misdn.c Thu Jan  5 05:21:53 2006
@@ -523,12 +523,12 @@
 	
 	if (argc == 3 || onlyport == 0) {
 		ast_cli(fd,"Misdn General-Config: \n"); 
-		ast_cli(fd," ->  VERSION: " CHAN_MISDN_VERSION "\n");
-		
+		ast_cli(fd," -> Version: chan_misdn-" CHAN_MISDN_VERSION "\n");
 		for (elem = MISDN_GEN_FIRST + 1, linebreak = 1; elem < MISDN_GEN_LAST; elem++, linebreak++) {
 			misdn_cfg_get_config_string( 0, elem, buffer, BUFFERSIZE);
 			ast_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
 		}
+		ast_cli(fd, "\n");
 	}
 
 	if (onlyport < 0) {
@@ -552,10 +552,9 @@
 			}	
 			ast_cli(fd, "\n");
 		} else {
-		  ast_cli(fd, "Port %d is not active!\n", onlyport);
-		}
-	}
-	ast_cli(fd, "\n");
+			ast_cli(fd, "Port %d is not active!\n", onlyport);
+		}
+	}
 	return 0;
 }
 
@@ -3523,8 +3522,6 @@
 
 int load_module(void)
 {
-	sleep(2);
-	
 	int i;
 	
 	char ports[256]="";

Modified: team/crichter/config-update/channels/chan_misdn_config.c
URL: http://svn.digium.com/view/asterisk/team/crichter/config-update/channels/chan_misdn_config.c?rev=7815&r1=7814&r2=7815&view=diff
==============================================================================
--- team/crichter/config-update/channels/chan_misdn_config.c (original)
+++ team/crichter/config-update/channels/chan_misdn_config.c Thu Jan  5 05:21:53 2006
@@ -39,9 +39,8 @@
 #include <asterisk/lock.h>
 #include <asterisk/pbx.h>
 #include <asterisk/strings.h>
-
-
 #include <asterisk/utils.h>
+
 #define AST_LOAD_CFG ast_config_load
 #define AST_DESTROY_CFG ast_config_destroy
 
@@ -72,6 +71,7 @@
 	int *num;
 	struct msn_list *ml;
 	ast_group_t *grp;
+	void *any;
 };
 
 struct misdn_cfg_spec {
@@ -213,25 +213,50 @@
 
 static void _free_port_cfg (void)
 {
-/* 	int i, j; */
-
-/* 	for (i = 0; i < NUM_PORT_ELEMENTS; i++) */
-/* 		for (j = 0; j < (max_ports + 1); j++) */
-/* 			; */
+	int i, j;
+	int gn = map[MISDN_CFG_GROUPNAME];
+	union misdn_cfg_pt* free_list[max_ports + 1];
+	
+	memset(free_list, 0, sizeof(free_list));
+	free_list[0] = port_cfg[0];
+	for (i = 1; i <= max_ports; ++i) {
+		if (port_cfg[i][gn].str) { /* we always have a groupname in the non-default case */
+			for (j = 1; j <= max_ports; ++j) {
+				if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str)
+					break;
+				else if (!free_list[j]) {
+					free_list[j] = port_cfg[i];
+					break;
+				}
+			}
+		}
+	}
+
+	for (j = 0; free_list[j]; ++j) {
+		for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
+			if (free_list[j][i].any) {
+				if (port_spec[i].type == MISDN_CTYPE_MSNLIST)
+					_free_msn_list(free_list[j][i].ml);
+				else
+					free(free_list[j][i].any);
+			}
+		}
+	}
 }
 
 static void _free_general_cfg (void)
 {
-/* 	int i; */
-
-/* 	for (i = 0; i < NUM_PORT_ELEMENTS; i++) */
-/*		; */
+	int i;
+
+	for (i = 0; i < NUM_GEN_ELEMENTS; i++) 
+		if (general_cfg[i].any)
+			free(general_cfg[i].any);
 }
 
 void misdn_cfg_get(int port, enum misdn_cfg_elements elem, void *buf, int bufsize)
 {
 	int place;
-	
+
 	if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
 		memset(buf, 0, bufsize);
 		ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
@@ -242,68 +267,60 @@
 
 	if (elem == MISDN_CFG_PTP) {
 		if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
-			memset(buf, 0, bufsize);
+																				 memset(buf, 0, bufsize);
 	} else if (elem < MISDN_CFG_LAST) {
 		if ((place = map[elem]) >= 0) {
 			switch (port_spec[place].type) {
 			case MISDN_CTYPE_STR:
-				{
-					if (port_cfg[port][place].str) {
-						if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize))
-							memset(buf, 0, 1);
-					} else if (port_cfg[0][place].str) {
-						if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize))
-							memset(buf, 0, 1);
-						else
-							memset(buf, 0, 1);
-					}
+				if (port_cfg[port][place].str) {
+					if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize))
+						memset(buf, 0, 1);
+				} else if (port_cfg[0][place].str) {
+					if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize))
+						memset(buf, 0, 1);
+					else
+						memset(buf, 0, 1);
 				}
 				break;
 			default:
-				{
-					if (port_cfg[port][place].num)
-						memcpy(buf, port_cfg[port][place].num, bufsize);
-					else if (port_cfg[0][place].num)
-						memcpy(buf, port_cfg[0][place].num, bufsize);
-					else
-						memset(buf, 0, bufsize);
-				}
+				if (port_cfg[port][place].num)
+					memcpy(buf, port_cfg[port][place].num, bufsize);
+				else if (port_cfg[0][place].num)
+					memcpy(buf, port_cfg[0][place].num, bufsize);
+				else
+					memset(buf, 0, bufsize);
 			}
 		} else
 			memset(buf, 0, bufsize);
 	} else if ((place = map[elem]) >= 0) {
 		switch (gen_spec[place].type) {
 		case MISDN_CTYPE_STR:
-			{
-				if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize))
-					memset(buf, 0, 1);
-			}
+			if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize))
+				memset(buf, 0, 1);
 			break;
 		default:
-			{
-				if (general_cfg[place].num)
-					memcpy(buf, general_cfg[place].num, bufsize);
-				else
-					memset(buf, 0, bufsize);
-			}
+			if (general_cfg[place].num)
+				memcpy(buf, general_cfg[place].num, bufsize);
+			else
+				memset(buf, 0, bufsize);
 		}
 	} else
 		memset(buf, 0, bufsize);
-		
+
 	misdn_cfg_unlock();
 }
 
 int misdn_cfg_is_msn_valid (int port, char* msn)
 {
 	struct msn_list *iter;
-	
+
 	if (!misdn_cfg_is_port_valid(port)) {
 		ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
 		return 0;
 	}
 
 	misdn_cfg_lock();
-	
+
 	if (port_cfg[port][MISDN_CFG_MSNS-1].ml)
 		iter = port_cfg[port][MISDN_CFG_MSNS-1].ml;
 	else
@@ -313,9 +330,9 @@
 			misdn_cfg_unlock();
 			return 1;
 		}
-	
+
 	misdn_cfg_unlock();
-	
+
 	return 0;
 }
 
@@ -328,9 +345,9 @@
 {
 	int i, re = 0;
 	char *method = NULL;
-	
+
 	misdn_cfg_lock();
-	
+
 	for (i = 1; i <= max_ports; i++) {
 		if (port_cfg[i]) {
 			if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
@@ -357,9 +374,9 @@
 {
 	char tmp[16];
 	int l, i;
-	
+
 	*ports = 0;
-	
+
 	misdn_cfg_lock();
 	for (i = 1; i <= max_ports; i++) {
 		if (port_cfg[i]) {
@@ -389,21 +406,21 @@
 	}
 
 	place = map[elem];
-	
+
+	misdn_cfg_lock();
 	if (elem == MISDN_CFG_PTP) {
 		snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
 	}
-	else if (elem < MISDN_CFG_LAST) {
-	  
-	  switch (port_spec[place].type) {
-	  case MISDN_CTYPE_INT:
-	  case MISDN_CTYPE_BOOLINT:
+	else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
+		switch (port_spec[place].type) {
+		case MISDN_CTYPE_INT:
+		case MISDN_CTYPE_BOOLINT:
 			if (port_cfg[port][place].num)
 				snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
 			else if (port_cfg[0][place].num)
 				snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
 			else
-				*buf = 0;
+				snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
 			break;
 		case MISDN_CTYPE_BOOL:
 			if (port_cfg[port][place].num)
@@ -411,7 +428,7 @@
 			else if (port_cfg[0][place].num)
 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
 			else
-				*buf = 0;
+				snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
 			break;
 		case MISDN_CTYPE_ASTGROUP:
 			if (port_cfg[port][place].grp)
@@ -421,7 +438,7 @@
 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, 
 						 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
 			else
-				*buf = 0;
+				snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
 			break;
 		case MISDN_CTYPE_MSNLIST:
 			if (port_cfg[port][place].ml)
@@ -436,58 +453,57 @@
 			snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
 			break;
 		case MISDN_CTYPE_STR:
-		  
-		  if ( port_cfg[port][place].str) {
-		    snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
-		  } else if (port_cfg[0][place].str) {
-		    snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
-		  } else {
-		    *buf = 0;
-		  }
+			if ( port_cfg[port][place].str) {
+				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
+			} else if (port_cfg[0][place].str) {
+				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
+			} else {
+				snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
+			}
 			break;
 		}
 	} else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
-	  switch (gen_spec[place].type) {
-	  case MISDN_CTYPE_INT:
-	  case MISDN_CTYPE_BOOLINT:
-	    if (general_cfg[place].num)
-	      snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
-	    else
-	      *buf = 0;
-	    break;
-	  case MISDN_CTYPE_BOOL:
-	    if (general_cfg[place].num)
-	      snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
-	    else
-	      *buf = 0;
-	    break;
-	  case MISDN_CTYPE_STR:
-	    if ( general_cfg[place].str) {
-	      snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
-	    } else {
-	      *buf = 0;
-	    }
-	    break;
-	  default:
-	    snprintf(buf, bufsize, " -> type not handled yet");
-	    break;
-	  }
-	} else
-	  snprintf(buf, bufsize, " -> else test");
-	
+		switch (gen_spec[place].type) {
+		case MISDN_CTYPE_INT:
+		case MISDN_CTYPE_BOOLINT:
+			if (general_cfg[place].num)
+				snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
+			else
+				snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
+			break;
+		case MISDN_CTYPE_BOOL:
+			if (general_cfg[place].num)
+				snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
+			else
+				snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
+			break;
+		case MISDN_CTYPE_STR:
+			if ( general_cfg[place].str) {
+				snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
+			} else {
+				snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
+			}
+			break;
+		default:
+			snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
+			break;
+		}
+	} else {
+		*buf = 0;
+		ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
+	}
+	misdn_cfg_unlock();
 }
 
 int misdn_cfg_get_next_port (int port)
 {	
 	misdn_cfg_lock();
-	
 	for (port++; port <= max_ports; port++) {
 		if (port_cfg[port]) {
 			misdn_cfg_unlock();
 			return port;
 		}
 	}
-	
 	misdn_cfg_unlock();
 
 	return -1;
@@ -496,7 +512,6 @@
 int misdn_cfg_get_next_port_spin (int port)
 {
 	int ret = misdn_cfg_get_next_port(port);
-
 	if (ret > 0)
 		return ret;
 
@@ -506,7 +521,7 @@
 static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type type, int boolint_def)
 {
 	int re = 0;
-	
+
 	switch (type) {
 	case MISDN_CTYPE_STR:
 		{
@@ -576,14 +591,13 @@
 static void _build_general_config (struct ast_variable *v)
 {
 	int pos;
-	
+
 	if (!v) 
 		return;
 
 	for (; v; v = v->next) {
-		if ((pos = get_cfg_position(v->name, GEN_CFG)) < 0)
-			CLI_ERROR(v->name, v->value, "general");
-		else if (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0)
+		if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) || 
+			(_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
 			CLI_ERROR(v->name, v->value, "general");
 	}
 }
@@ -596,25 +610,20 @@
 
 	if (!v || !cat)
 		return;
-	
+
 	memset(cfg_tmp, 0, sizeof(cfg_tmp));
 	memset(cfg_for_ports, 0, sizeof(cfg_for_ports));
-	
+
 	if (!strcasecmp(cat, "default")) {
 		cfg_for_ports[0] = 1;
 	}
 
-	if ((pos = get_cfg_position("name", PORT_CFG)) < 0) { 
+	if (((pos = get_cfg_position("name", PORT_CFG)) < 0) || 
+		(_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
 		CLI_ERROR(v->name, v->value, cat);
 		return;
 	}
-	
-	
-	if (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0) {
-	  CLI_ERROR(v->name, v->value, cat);
-	  return;
-	}
-        
+
 	for (; v; v = v->next) {
 		if (!strcasecmp(v->name, "ports")) {
 			char *token;
@@ -643,17 +652,16 @@
 				}
 			}
 		} else {
-			if ((pos = get_cfg_position(v->name, PORT_CFG)) < 0)
+			if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) || 
+				(_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
 				CLI_ERROR(v->name, v->value, cat);
-			else if (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0)
-				CLI_ERROR(v->name, v->value, cat);
 		}
 	}
 
 	for (i = 0; i < (max_ports + 1); ++i) {
-	  if (cfg_for_ports[i]) {
-	    memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
-	  }
+		if (cfg_for_ports[i]) {
+			memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
+		}
 	}
 }
 
@@ -663,7 +671,7 @@
 	char line[BUFFERSIZE];
 
 	misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
-	
+
 	if (misdn_init) {
 		FILE *fp = fopen(misdn_init,"r");
 		if (fp) {
@@ -716,6 +724,7 @@
 	free(port_cfg);
 	free(general_cfg);
 	free(ptp);
+	free(map);
 
 	misdn_cfg_unlock();
 	ast_mutex_destroy(&config_mutex);
@@ -724,7 +733,8 @@
 void misdn_cfg_init (int this_max_ports)
 {
 	char config[] = "misdn.conf";
-	char *cat;
+	char *cat, *p;
+	int i;
 	struct ast_config *cfg;
 	struct ast_variable *v;
 
@@ -734,33 +744,34 @@
 	}
 
 	misdn_cfg_lock();
-	
+
 	if (this_max_ports) {
-	  int i=0;
-	  /* this is the first run */
+		/* this is the first run */
 		max_ports = this_max_ports;
-		port_cfg = calloc( max_ports + 1, sizeof(union misdn_cfg_pr*));
-		for (i=0; i<=max_ports; i++)
-		  port_cfg[i] = malloc( sizeof(union misdn_cfg_pt) * NUM_PORT_ELEMENTS);
-		
+		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;
+		p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
+		for (i = 0; i <= max_ports; ++i) {
+			port_cfg[i] = (union misdn_cfg_pt *)p;
+			p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
+		}
 		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 {
 		_free_port_cfg();
 		_free_general_cfg();
-		memset(port_cfg, 0, (max_ports + 1) * 
-				sizeof(union misdn_cfg_pt *) * NUM_PORT_ELEMENTS);
-		memset(general_cfg, 0, 
-				sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
+		for (i = 0; i <= max_ports; ++i) {
+			memset(port_cfg[i], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
+		}
+		memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
 		memset(ptp, 0, sizeof(int) * (max_ports + 1));
-		memset(map, 0, sizeof(int) * (MISDN_GEN_LAST + 1));
-	}
-
-	_enum_array_map();
-	
+	}
+
 	cat = ast_category_browse(cfg, NULL);
 
 	while(cat) {
@@ -775,13 +786,6 @@
 
 	_fill_defaults();
 
-//DEBUG
-	int k;
-	for (k = 0; k < (MISDN_GEN_LAST + 1); ++k) {
-		printf("map %d = %d\n", k, map[k]);
-	}
-//DEBUG
-	
 	misdn_cfg_unlock();
 	AST_DESTROY_CFG(cfg);
 }

Modified: team/crichter/config-update/channels/misdn/chan_misdn_config.h
URL: http://svn.digium.com/view/asterisk/team/crichter/config-update/channels/misdn/chan_misdn_config.h?rev=7815&r1=7814&r2=7815&view=diff
==============================================================================
--- team/crichter/config-update/channels/misdn/chan_misdn_config.h (original)
+++ team/crichter/config-update/channels/misdn/chan_misdn_config.h Thu Jan  5 05:21:53 2006
@@ -58,8 +58,6 @@
 	MISDN_GEN_MISDN_INIT,           /* char[] */
 	MISDN_GEN_DEBUG,               /* int */
 	MISDN_GEN_TRACEFILE,           /* char[] */
-	MISDN_GEN_TRACE_CALLS,         /* int (bool) */
-	MISDN_GEN_TRACE_DIR,           /* char[] */
 	MISDN_GEN_BRIDGING,            /* int (bool) */
 	MISDN_GEN_STOP_TONE,           /* int (bool) */
 	MISDN_GEN_APPEND_DIGITS2EXTEN, /* int (bool) */



More information about the svn-commits mailing list