[asterisk-commits] murf: branch murf/bug8684-trunk r81250 - in /team/murf/bug8684-trunk: include...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 28 11:37:36 CDT 2007


Author: murf
Date: Tue Aug 28 11:37:35 2007
New Revision: 81250

URL: http://svn.digium.com/view/asterisk?view=rev&rev=81250
Log:
Fleshed out the information gathering

Modified:
    team/murf/bug8684-trunk/include/asterisk/config.h
    team/murf/bug8684-trunk/main/config.c
    team/murf/bug8684-trunk/res/res_config_odbc.c
    team/murf/bug8684-trunk/res/res_config_pgsql.c
    team/murf/bug8684-trunk/res/res_config_sqlite.c

Modified: team/murf/bug8684-trunk/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug8684-trunk/include/asterisk/config.h?view=diff&rev=81250&r1=81249&r2=81250
==============================================================================
--- team/murf/bug8684-trunk/include/asterisk/config.h (original)
+++ team/murf/bug8684-trunk/include/asterisk/config.h Tue Aug 28 11:37:35 2007
@@ -62,7 +62,7 @@
 	char stuff[0];
 };
 
-typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags);
+typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file);
 typedef struct ast_variable *realtime_var_get(const char *database, const char *table, va_list ap);
 typedef struct ast_config *realtime_multi_get(const char *database, const char *table, va_list ap);
 typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap);
@@ -251,8 +251,8 @@
 void ast_category_rename(struct ast_category *cat, const char *name);
 
 struct ast_variable *ast_variable_new(const char *name, const char *value, const char *filename);
-struct ast_config_include *ast_include_new(const char *from_file, const char *included_file, int is_exec, int from_lineno);
-	void ast_include_append(struct ast_config *conf, struct ast_config_include *incl);
+struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size);
+struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file);
 void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
 int ast_variable_delete(struct ast_category *category, const char *variable, const char *match);
 int ast_variable_update(struct ast_category *category, const char *variable, 
@@ -260,8 +260,7 @@
 
 int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
 
-struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags);
-
+struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file);
 /*! \brief Support code to parse config file arguments
  *
  * The function ast_parse_arg() provides a generic interface to parse

Modified: team/murf/bug8684-trunk/main/config.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug8684-trunk/main/config.c?view=diff&rev=81250&r1=81249&r2=81250
==============================================================================
--- team/murf/bug8684-trunk/main/config.c (original)
+++ team/murf/bug8684-trunk/main/config.c Tue Aug 28 11:37:35 2007
@@ -202,8 +202,10 @@
 	char *include_location_file; /*!< file name in which the include occurs */
 	int  include_location_lineno; /*!< lineno where include occurred */
 	int  exec; /*!< set to non-zero if itsa #exec statement */
+	char *exec_file; /*!< if it's an exec, you'll have both the /var/tmp to read, and the original script */
 	char *included_file; /*!< file name included */
-	
+	int inclusion_count;
+	int output; /*!< a flag to indicate if the inclusion has been output */
 	struct ast_config_include *next; /*!< ptr to next inclusion in the list */
 };
 
@@ -215,7 +217,7 @@
 	if ((variable = ast_calloc(1, name_len + strlen(value) + 1 + strlen(filename) + 1 + sizeof(*variable)))) {
 		variable->name = variable->stuff;
 		variable->value = variable->stuff + name_len;		
-		variable->file = variable->stuff + name_len + strlen(value) + 1;		
+		variable->file = variable->stuff + name_len + strlen(value) + 1;
 		strcpy(variable->name,name);
 		strcpy(variable->value,value);
 		strcpy(variable->file,filename);
@@ -223,21 +225,51 @@
 	return variable;
 }
 
-struct ast_config_include *ast_include_new(const char *from_file, const char *included_file, int is_exec, int from_lineno)
-{
-	struct ast_config_include *inc = ast_calloc(1,sizeof(struct ast_config_include));
+struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
+{
+	/* a file should be included ONCE. Otherwise, if one of the instances is changed,
+       then all be changed. -- how do we know to include it? -- Handling modified 
+       instances is possible, I'd have
+       to create a new master for each instance. */
+	struct ast_config_include *inc;
 	
+	inc = ast_include_find(conf, included_file);
+	if (inc)
+	{
+		inc->inclusion_count++;
+		snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count);
+		ast_log(LOG_WARNING,"'%s', line %d:  Same File included more than once! This data will be saved in %s if saved back to disk.\n", from_file, from_lineno, real_included_file_name);
+	} else
+		*real_included_file_name = 0;
+	
+	inc = ast_calloc(1,sizeof(struct ast_config_include));
 	inc->include_location_file = ast_strdup(from_file);
 	inc->include_location_lineno = from_lineno;
-	inc->included_file = (char *)included_file;
+	if (inc)
+		inc->included_file = ast_strdup(real_included_file_name);
+	else
+		inc->included_file = ast_strdup(included_file);
+	
 	inc->exec = is_exec;
+	if (is_exec)
+		inc->exec_file = ast_strdup(exec_file);
+	
+	/* attach this new struct to the conf struct */
+	inc->next = conf->includes;
+	conf->includes = inc;
+	
 	return inc;
 }
 
-void ast_include_append(struct ast_config *conf, struct ast_config_include *incl)
-{
-	incl->next = conf->includes;
-	conf->includes = incl;
+struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file)
+{
+	struct ast_config_include *x;
+	for (x=conf->includes;x;x=x->next)
+	{
+		if (strcmp(x->included_file,included_file) == 0)
+			return x;
+	}
+	return 0;
 }
 
 
@@ -687,7 +719,7 @@
 }
 
 static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, struct ast_flags flags,
-				char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size)
+							 char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size, const char *suggested_include_file)
 {
 	char *c;
 	char *cur = buf;
@@ -785,10 +817,15 @@
 		}
 		if (do_include || do_exec) {
 			if (c) {
+				char *cur2;
+				char real_inclusion_name[256];
+				struct ast_config_include *inclu;
+				
 				/* Strip off leading and trailing "'s and <>'s */
 				while ((*c == '<') || (*c == '>') || (*c == '\"')) c++;
 				/* Get rid of leading mess */
 				cur = c;
+				cur2 = cur;
 				while (!ast_strlen_zero(cur)) {
 					c = cur + strlen(cur) - 1;
 					if ((*c == '>') || (*c == '<') || (*c == '\"'))
@@ -811,7 +848,10 @@
 					exec_file[0] = '\0';
 				}
 				/* A #include */
-				do_include = ast_config_internal_load(cur, cfg, flags) ? 1 : 0;
+				/* record this inclusion */
+				inclu = ast_include_new(cfg, configfile, cur, do_exec, cur2, lineno, real_inclusion_name, sizeof(real_inclusion_name));
+
+				do_include = ast_config_internal_load(cur, cfg, flags, real_inclusion_name) ? 1 : 0;
 				if (!ast_strlen_zero(exec_file))
 					unlink(exec_file);
 				if (!do_include)
@@ -844,7 +884,7 @@
 				c++;
 			} else
 				object = 0;
-			if ((v = ast_variable_new(ast_strip(cur), ast_strip(c), configfile))) {
+			if ((v = ast_variable_new(ast_strip(cur), ast_strip(c), *suggested_include_file ? suggested_include_file : configfile))) {
 				v->lineno = lineno;
 				v->object = object;
 				/* Put and reset comments */
@@ -870,7 +910,7 @@
 	return 0;
 }
 
-static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg, struct ast_flags flags)
+static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_file)
 {
 	char fn[256];
 	char buf[8192];
@@ -981,7 +1021,7 @@
 #else
 						ast_copy_string(fn2, cfinclude->include);
 #endif
-						if (config_text_file_load(NULL, NULL, fn2, NULL, flags) == NULL) {
+						if (config_text_file_load(NULL, NULL, fn2, NULL, flags, "") == NULL) { /* that last field needs to be looked at in this case... TODO */
 							unchanged = 0;
 							/* One change is enough to short-circuit and reload the whole shebang */
 							break;
@@ -1088,7 +1128,7 @@
 				if (process_buf) {
 					char *buf = ast_strip(process_buf);
 					if (!ast_strlen_zero(buf)) {
-						if (process_text_line(cfg, &cat, buf, lineno, fn, flags, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size)) {
+						if (process_text_line(cfg, &cat, buf, lineno, fn, flags, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size, suggested_include_file)) {
 							cfg = NULL;
 							break;
 						}
@@ -1270,7 +1310,7 @@
 
 	configtmp = ast_config_new();
 	configtmp->max_include_level = 1;
-	config = ast_config_internal_load(extconfig_conf, configtmp, flags);
+	config = ast_config_internal_load(extconfig_conf, configtmp, flags, "");
 	if (!config) {
 		ast_config_destroy(configtmp);
 		return 0;
@@ -1409,7 +1449,7 @@
 	.load_func = config_text_file_load,
 };
 
-struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, struct ast_flags flags)
+struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_file)
 {
 	char db[256];
 	char table[256];
@@ -1438,7 +1478,7 @@
 		}
 	}
 
-	result = loader->load_func(db, table, filename, cfg, flags);
+	result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file);
 
 	if (result && result != CONFIG_STATUS_FILEUNCHANGED)
 		result->include_level--;
@@ -1457,7 +1497,7 @@
 	if (!cfg)
 		return NULL;
 
-	result = ast_config_internal_load(filename, cfg, flags);
+	result = ast_config_internal_load(filename, cfg, flags, "");
 	if (!result || result == CONFIG_STATUS_FILEUNCHANGED)
 		ast_config_destroy(cfg);
 

Modified: team/murf/bug8684-trunk/res/res_config_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug8684-trunk/res/res_config_odbc.c?view=diff&rev=81250&r1=81249&r2=81250
==============================================================================
--- team/murf/bug8684-trunk/res/res_config_odbc.c (original)
+++ team/murf/bug8684-trunk/res/res_config_odbc.c Tue Aug 28 11:37:35 2007
@@ -625,7 +625,7 @@
 	return sth;
 }
 
-static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg, struct ast_flags flags)
+static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl)
 {
 	struct ast_variable *new_v;
 	struct ast_category *cur_cat;
@@ -682,7 +682,7 @@
 
 	while ((res = SQLFetch(stmt)) != SQL_NO_DATA) {
 		if (!strcmp (q.var_name, "#include")) {
-			if (!ast_config_internal_load(q.var_val, cfg, loader_flags)) {
+			if (!ast_config_internal_load(q.var_val, cfg, loader_flags, "")) {
 				SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 				ast_odbc_release_obj(obj);
 				return NULL;

Modified: team/murf/bug8684-trunk/res/res_config_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug8684-trunk/res/res_config_pgsql.c?view=diff&rev=81250&r1=81249&r2=81250
==============================================================================
--- team/murf/bug8684-trunk/res/res_config_pgsql.c (original)
+++ team/murf/bug8684-trunk/res/res_config_pgsql.c Tue Aug 28 11:37:35 2007
@@ -615,8 +615,8 @@
 
 
 static struct ast_config *config_pgsql(const char *database, const char *table,
-					   const char *file, struct ast_config *cfg,
-					   struct ast_flags flags)
+									   const char *file, struct ast_config *cfg,
+									   struct ast_flags flags, const char *suggested_incl)
 {
 	PGresult *result = NULL;
 	long num_rows;
@@ -681,7 +681,7 @@
 			char *field_var_val = PQgetvalue(result, rowIndex, 2);
 			char *field_cat_metric = PQgetvalue(result, rowIndex, 3);
 			if (!strcmp(field_var_name, "#include")) {
-				if (!ast_config_internal_load(field_var_val, cfg, flags)) {
+				if (!ast_config_internal_load(field_var_val, cfg, flags, "")) {
 					PQclear(result);
 					ast_mutex_unlock(&pgsql_lock);
 					return NULL;

Modified: team/murf/bug8684-trunk/res/res_config_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug8684-trunk/res/res_config_sqlite.c?view=diff&rev=81250&r1=81249&r2=81250
==============================================================================
--- team/murf/bug8684-trunk/res/res_config_sqlite.c (original)
+++ team/murf/bug8684-trunk/res/res_config_sqlite.c Tue Aug 28 11:37:35 2007
@@ -305,9 +305,8 @@
  * \retval NULL if an error occurred
  * \see add_cfg_entry()
  */
-static struct ast_config * config_handler(const char *database,
-	const char *table, const char *file,
-	struct ast_config *cfg, struct ast_flags flags);
+static struct ast_config * config_handler(const char *database, const char *table, const char *file,
+struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl);
 
 /*!
  * \brief Helper function to parse a va_list object into 2 dynamic arrays of
@@ -767,8 +766,8 @@
 	return 0;
 }
 
-static struct ast_config *config_handler(const char *database, 
-	const char *table, const char *file, struct ast_config *cfg, struct ast_flags flags)
+static struct ast_config *config_handler(const char *database,	const char *table, const char *file,
+struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl)
 {
 	struct cfg_entry_args args;
 	char *errormsg;




More information about the asterisk-commits mailing list