[asterisk-commits] tilghman: branch tilghman/config_mtime_cache r79442 - in /team/tilghman/confi...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 14 12:58:30 CDT 2007


Author: tilghman
Date: Tue Aug 14 12:58:29 2007
New Revision: 79442

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79442
Log:
Core changes, plus conversions to several files.  More conversions to come.

Modified:
    team/tilghman/config_mtime_cache/channels/chan_agent.c
    team/tilghman/config_mtime_cache/channels/chan_iax2.c
    team/tilghman/config_mtime_cache/channels/chan_mgcp.c
    team/tilghman/config_mtime_cache/channels/chan_oss.c
    team/tilghman/config_mtime_cache/channels/chan_phone.c
    team/tilghman/config_mtime_cache/channels/chan_sip.c
    team/tilghman/config_mtime_cache/channels/chan_zap.c
    team/tilghman/config_mtime_cache/channels/iax2-provision.c
    team/tilghman/config_mtime_cache/channels/iax2-provision.h
    team/tilghman/config_mtime_cache/include/asterisk/config.h
    team/tilghman/config_mtime_cache/main/config.c
    team/tilghman/config_mtime_cache/res/res_adsi.c
    team/tilghman/config_mtime_cache/res/res_config_odbc.c
    team/tilghman/config_mtime_cache/res/res_features.c
    team/tilghman/config_mtime_cache/res/res_indications.c
    team/tilghman/config_mtime_cache/res/res_musiconhold.c
    team/tilghman/config_mtime_cache/res/res_odbc.c
    team/tilghman/config_mtime_cache/res/res_smdi.c

Modified: team/tilghman/config_mtime_cache/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_agent.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_agent.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_agent.c Tue Aug 14 12:58:29 2007
@@ -976,7 +976,7 @@
  *
  * \returns Always 0, or so it seems.
  */
-static int read_agent_config(void)
+static int read_agent_config(int reload)
 {
 	struct ast_config *cfg;
 	struct ast_config *ucfg;
@@ -986,17 +986,19 @@
 	const char *catname;
 	const char *hasagent;
 	int genhasagent;
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
 
 	group = 0;
 	autologoff = 0;
 	wrapuptime = 0;
 	ackcall = 0;
 	endcall = 1;
-	cfg = ast_config_load(config);
+	cfg = ast_config_load(config, config_flags);
 	if (!cfg) {
 		ast_log(LOG_NOTICE, "No agent configuration found -- agent support disabled\n");
 		return 0;
-	}
+	} else if (cfg == FILEUNCHANGED)
+		return -1;
 	AST_LIST_LOCK(&agents);
 	AST_LIST_TRAVERSE(&agents, p, list) {
 		p->dead = 1;
@@ -1081,7 +1083,7 @@
 		}
 		v = v->next;
 	}
-	if ((ucfg = ast_config_load("users.conf"))) {
+	if ((ucfg = ast_config_load("users.conf", config_flags)) && ucfg != FILEUNCHANGED) {
 		genhasagent = ast_true(ast_variable_retrieve(ucfg, "general", "hasagent"));
 		catname = ast_category_browse(ucfg, NULL);
 		while(catname) {
@@ -2276,7 +2278,7 @@
 		return -1;
 	}
 	/* Read in the config */
-	if (!read_agent_config())
+	if (!read_agent_config(0))
 		return AST_MODULE_LOAD_DECLINE;
 	if (persistent_agents)
 		reload_agents();
@@ -2299,9 +2301,10 @@
 
 static int reload(void)
 {
-	read_agent_config();
-	if (persistent_agents)
-		reload_agents();
+	if (!read_agent_config(1)) {
+		if (persistent_agents)
+			reload_agents();
+	}
 	return 0;
 }
 

Modified: team/tilghman/config_mtime_cache/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_iax2.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_iax2.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_iax2.c Tue Aug 14 12:58:29 2007
@@ -9770,15 +9770,30 @@
 	struct iax2_user *user;
 	struct iax2_peer *peer;
 	struct ast_netsock *ns;
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
 #if 0
 	static unsigned short int last_port=0;
 #endif
 
-	cfg = ast_config_load(config_file);
+	for (x = 0; x < 2; x++) {
+		cfg = ast_config_load(config_file, config_flags);
 	
-	if (!cfg) {
-		ast_log(LOG_ERROR, "Unable to load config %s\n", config_file);
-		return -1;
+		if (!cfg) {
+			ast_log(LOG_ERROR, "Unable to load config %s\n", config_file);
+			return -1;
+		} else if (cfg == FILEUNCHANGED) {
+			ucfg = ast_config_load("users.conf", config_flags);
+			if (ucfg == FILEUNCHANGED)
+				return 0;
+			/* Otherwise we need to reread both files */
+			ast_config_destroy(ucfg);
+			ast_clear_flag(&config_flags, OPT_FILEUNCHANGED);
+			continue;
+		} else { /* iax.conf changed, gotta reread users.conf, too */
+			ast_clear_flag(&config_flags, OPT_FILEUNCHANGED);
+			ucfg = ast_config_load("users.conf", config_flags);
+		}
+		break;
 	}
 
 	/* Reset global codec prefs */	
@@ -10042,7 +10057,6 @@
 	}
 	iax2_capability = capability;
 	
-	ucfg = ast_config_load("users.conf");
 	if (ucfg) {
 		struct ast_variable *gen;
 		int genhasiax;
@@ -10170,7 +10184,7 @@
 		iax2_poke_peer(peer, 0);
 	AST_LIST_UNLOCK(&peers);
 	reload_firmware();
-	iax_provision_reload();
+	iax_provision_reload(1);
 
 	return 0;
 }
@@ -11091,7 +11105,7 @@
 	AST_LIST_UNLOCK(&peers);
 
 	reload_firmware();
-	iax_provision_reload();
+	iax_provision_reload(0);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }

Modified: team/tilghman/config_mtime_cache/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_mgcp.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_mgcp.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_mgcp.c Tue Aug 14 12:58:29 2007
@@ -422,8 +422,8 @@
 static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,  
                             int result, unsigned int ident, struct mgcp_request *resp);
 static void dump_cmd_queues(struct mgcp_endpoint *p, struct mgcp_subchannel *sub);
-static int mgcp_do_reload(void);
 static int mgcp_reload(int fd, int argc, char *argv[]);
+static int reload_config(int reload);
 
 static struct ast_channel *mgcp_request(const char *type, int format, void *data, int *cause);
 static int mgcp_call(struct ast_channel *ast, char *dest, int timeout);
@@ -3379,7 +3379,7 @@
 		ast_mutex_unlock(&mgcp_reload_lock);
 		if (reloading) {
 			ast_verb(1, "Reloading MGCP\n");
-			mgcp_do_reload();
+			reload_config(1);
 			/* Add an I/O event to our UDP socket */
 			if (mgcpsock > -1) 
 				mgcpsock_read_id = ast_io_add(io, mgcpsock, mgcpsock_read, AST_IO_IN, NULL);
@@ -4042,7 +4042,7 @@
 	ast_mutex_unlock(&gatelock);
 }
 
-static int reload_config(void)
+static int reload_config(int reload)
 {
 	struct ast_config *cfg;
 	struct ast_variable *v;
@@ -4052,18 +4052,21 @@
 	struct ast_hostent ahp;
 	struct hostent *hp;
 	int format;
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
 	
 	if (gethostname(ourhost, sizeof(ourhost)-1)) {
 		ast_log(LOG_WARNING, "Unable to get hostname, MGCP disabled\n");
 		return 0;
 	}
-	cfg = ast_config_load(config);
+	cfg = ast_config_load(config, config_flags);
 
 	/* We *must* have a config file otherwise stop immediately */
 	if (!cfg) {
 		ast_log(LOG_NOTICE, "Unable to load config %s, MGCP disabled\n", config);
 		return 0;
-	}
+	} else if (cfg == FILEUNCHANGED)
+		return 0;
+
 	memset(&bindaddr, 0, sizeof(bindaddr));
 	dtmfmode = 0;
 
@@ -4222,7 +4225,7 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
-	if (reload_config())
+	if (reload_config(0))
 		return AST_MODULE_LOAD_DECLINE;
 
 	/* Make sure we can register our mgcp channel type */
@@ -4240,13 +4243,6 @@
 	restart_monitor();
 
 	return AST_MODULE_LOAD_SUCCESS;
-}
-
-/*! \brief  mgcp_do_reload: Reload module */
-static int mgcp_do_reload(void)
-{
-	reload_config();
-	return 0;
 }
 
 static int mgcp_reload(int fd, int argc, char *argv[])

Modified: team/tilghman/config_mtime_cache/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_oss.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_oss.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_oss.c Tue Aug 14 12:58:29 2007
@@ -1577,12 +1577,13 @@
 {
 	struct ast_config *cfg = NULL;
 	char *ctg = NULL;
+	struct ast_flags config_flags = { 0 };
 
 	/* Copy the default jb config over global_jbconf */
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
 
 	/* load config file */
-	if (!(cfg = ast_config_load(config))) {
+	if (!(cfg = ast_config_load(config, config_flags))) {
 		ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
 		return AST_MODULE_LOAD_DECLINE;
 	}

Modified: team/tilghman/config_mtime_cache/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_phone.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_phone.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_phone.c Tue Aug 14 12:58:29 2007
@@ -1347,7 +1347,9 @@
 	struct phone_pvt *tmp;
 	int mode = MODE_IMMEDIATE;
 	int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */
-	cfg = ast_config_load(config);
+	struct ast_flags config_flags = { 0 };
+
+	cfg = ast_config_load(config, config_flags);
 
 	/* We *must* have a config file otherwise stop immediately */
 	if (!cfg) {

Modified: team/tilghman/config_mtime_cache/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_sip.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_sip.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_sip.c Tue Aug 14 12:58:29 2007
@@ -17629,16 +17629,31 @@
 	char *cat, *stringp, *context, *oldregcontext;
 	char newcontexts[AST_MAX_CONTEXT], oldcontexts[AST_MAX_CONTEXT];
 	struct ast_flags dummy[2];
+	struct ast_flags config_flags = { OPT_FILEUNCHANGED };
 	int auto_sip_domains = FALSE;
 	struct sockaddr_in old_bindaddr = bindaddr;
-	int registry_count = 0, peer_count = 0, user_count = 0;
-
-	cfg = ast_config_load(config);
-
-	/* We *must* have a config file otherwise stop immediately */
-	if (!cfg) {
-		ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
-		return -1;
+	int registry_count = 0, peer_count = 0, user_count = 0, x;
+
+	for (x = 0; x < 2; x++) {
+		cfg = ast_config_load(config, config_flags);
+
+		/* We *must* have a config file otherwise stop immediately */
+		if (!cfg) {
+			ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
+			return -1;
+		} else if (cfg == FILEUNCHANGED) {
+			ucfg = ast_config_load("users.conf", config_flags);
+			if (ucfg == FILEUNCHANGED)
+				return 0;
+			/* Must reread both files, because one changed */
+			ast_config_destroy(ucfg);
+			ast_clear_flag(&config_flags, OPT_FILEUNCHANGED);
+			continue;
+		} else {
+			ast_clear_flag(&config_flags, OPT_FILEUNCHANGED);
+			ucfg = ast_config_load("users.conf", config_flags);
+		}
+		break;
 	}
 	
 	/* Initialize copy of current global_regcontext for later use in removing stale contexts */

Modified: team/tilghman/config_mtime_cache/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_zap.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_zap.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_zap.c Tue Aug 14 12:58:29 2007
@@ -12623,27 +12623,41 @@
 		
 static int setup_zap(int reload)
 {
-	struct ast_config *cfg;
+	struct ast_config *cfg, *ucfg;
 	struct ast_variable *v;
  	struct zt_chan_conf base_conf = zt_chan_conf_default();
  	struct zt_chan_conf conf;
-	int res;
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
+	int res, x;
 
 #ifdef HAVE_PRI
 	char *c;
 	int spanno;
-	int i, x;
+	int i;
 	int logicalspan;
 	int trunkgroup;
 	int dchannels[NUM_DCHANS];
 #endif
 
-	cfg = ast_config_load(config);
-
-	/* Error if we have no config file */
-	if (!cfg) {
-		ast_log(LOG_ERROR, "Unable to load config %s\n", config);
-		return 0;
+	for (x = 0; x < 2; x++) {
+		cfg = ast_config_load(config, config_flags);
+
+		/* Error if we have no config file */
+		if (!cfg) {
+			ast_log(LOG_ERROR, "Unable to load config %s\n", config);
+			return 0;
+		} else if (cfg == FILEUNCHANGED) {
+			ucfg = ast_config_load("users.conf");
+			if (ucfg == FILEUNCHANGED)
+				return 0;
+			/* Need to reread both, since users.conf has changed */
+			ast_config_destroy(ucfg);
+			ast_clear_flag(&flags, OPT_FILEUNCHANGED);
+			continue;
+		} else {
+			ucfg = ast_config_load("users.conf");
+			break;
+		}
 	}
 
 	/* It's a little silly to lock it, but we mind as well just to be sure */
@@ -12718,25 +12732,24 @@
 	ast_config_destroy(cfg);
 	if (res)
 		return res;
-	cfg = ast_config_load("users.conf");
-	if (cfg) {
+	if (ucfg) {
 		char *cat;
 		const char *chans;
 		process_zap(&base_conf, ast_variable_browse(cfg, "general"), 1, 1);
-		for (cat = ast_category_browse(cfg, NULL); cat ; cat = ast_category_browse(cfg, cat)) {
+		for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) {
 			if (!strcasecmp(cat, "general"))
 				continue;
-			chans = ast_variable_retrieve(cfg, cat, "zapchan");
+			chans = ast_variable_retrieve(ucfg, cat, "zapchan");
 			if (!ast_strlen_zero(chans)) {
 				if (memcpy(&conf, &base_conf, sizeof(conf)) == NULL) {
 					ast_log(LOG_ERROR, "Not enough memory for conf copy\n");
-					ast_config_destroy(cfg);
+					ast_config_destroy(ucfg);
 					return -1;
 				}
-				process_zap(&conf, ast_variable_browse(cfg, cat), reload, 0);
-			}
-		}
-		ast_config_destroy(cfg);
+				process_zap(&conf, ast_variable_browse(ucfg, cat), reload, 0);
+			}
+		}
+		ast_config_destroy(ucfg);
 	}
 #ifdef HAVE_PRI
 	if (!reload) {

Modified: team/tilghman/config_mtime_cache/channels/iax2-provision.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/iax2-provision.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/iax2-provision.c (original)
+++ team/tilghman/config_mtime_cache/channels/iax2-provision.c Tue Aug 14 12:58:29 2007
@@ -485,12 +485,13 @@
 	return 0;
 }
 
-int iax_provision_reload(void)
+int iax_provision_reload(int reload)
 {
 	struct ast_config *cfg;
 	struct iax_template *cur, *prev, *next;
 	char *cat;
 	int found = 0;
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
 	if (!provinit)
 		iax_provision_init();
 	/* Mark all as dead.  No need for locking */
@@ -499,8 +500,8 @@
 		cur->dead = 1;
 		cur = cur->next;
 	}
-	cfg = ast_config_load("iaxprov.conf");
-	if (cfg) {
+	cfg = ast_config_load("iaxprov.conf", config_flags);
+	if (cfg != NULL && cfg != FILEUNCHANGED) {
 		/* Load as appropriate */
 		cat = ast_category_browse(cfg, NULL);
 		while(cat) {
@@ -512,7 +513,9 @@
 			cat = ast_category_browse(cfg, cat);
 		}
 		ast_config_destroy(cfg);
-	} else
+	} else if (cfg == FILEUNCHANGED)
+		return 0;
+	else
 		ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");
 	ast_mutex_lock(&provlock);
 	/* Drop dead entries while locked */

Modified: team/tilghman/config_mtime_cache/channels/iax2-provision.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/iax2-provision.h?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/channels/iax2-provision.h (original)
+++ team/tilghman/config_mtime_cache/channels/iax2-provision.h Tue Aug 14 12:58:29 2007
@@ -46,7 +46,7 @@
 #define PROV_FLAG_DIS_THREEWAY	(1 << 7)	/* Three-way calling, transfer disabled */
 
 char *iax_provflags2str(char *buf, int buflen, unsigned int flags);
-int iax_provision_reload(void);
+int iax_provision_reload(int reload);
 int iax_provision_unload(void);
 int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force);
 int iax_provision_version(unsigned int *signature, const char *template, int force);

Modified: team/tilghman/config_mtime_cache/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/include/asterisk/config.h?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/include/asterisk/config.h (original)
+++ team/tilghman/config_mtime_cache/include/asterisk/config.h Tue Aug 14 12:58:29 2007
@@ -27,11 +27,23 @@
 extern "C" {
 #endif
 
+#include "asterisk/utils.h"
 #include <stdarg.h>
 
 struct ast_config;
 
 struct ast_category;
+
+/*! Options for config_file_load
+ */
+enum {
+	/*! Load the configuration, including comments */
+	OPT_WITHCOMMENTS  = (1 << 0),
+	/*! On a reload, give us a -1 if the file hasn't changed. */
+	OPT_FILEUNCHANGED = (1 << 1),
+};
+
+#define	FILEUNCHANGED	(void *)-1
 
 /*! \brief Structure for variables, used for configurations and for channel variables 
 */
@@ -47,7 +59,7 @@
 	char stuff[0];
 };
 
-typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, int withcomments);
+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_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);
@@ -73,7 +85,7 @@
  * \retval an ast_config data structure on success
  * \retval NULL on error
  */
-struct ast_config *ast_config_load(const char *filename);
+struct ast_config *ast_config_load(const char *filename, struct ast_flags flags);
 struct ast_config *ast_config_load_with_comments(const char *filename);
 
 /*! \brief Destroys a config 
@@ -240,7 +252,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, int withcomments);
+struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags);
 
 /*! \brief Support code to parse config file arguments
  *

Modified: team/tilghman/config_mtime_cache/main/config.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/main/config.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/main/config.c (original)
+++ team/tilghman/config_mtime_cache/main/config.c Tue Aug 14 12:58:29 2007
@@ -65,11 +65,19 @@
 
 
 /*! \brief Structure to keep comments for rewriting configuration files */
-/*! \brief Structure to keep comments for rewriting configuration files */
 struct ast_comment {
 	struct ast_comment *next;
 	char cmt[0];
 };
+
+/*! \brief Hold the mtime for config files, so if we don't need to reread our config, don't. */
+struct cache_file_mtime {
+	AST_LIST_ENTRY(cache_file_mtime) list;
+	time_t mtime;
+	char filename[0];
+};
+
+static AST_LIST_HEAD_STATIC(cfmtime_head, cache_file_mtime);
 
 #define CB_INCR 250
 
@@ -598,6 +606,7 @@
 	struct ast_variable *v;
 	char cmd[512], exec_file[512];
 	int object, do_exec, do_include;
+	struct ast_flags flags = { withcomments ? OPT_WITHCOMMENTS : 0 };
 
 	/* Actually parse the entry */
 	if (cur[0] == '[') {
@@ -710,7 +719,7 @@
 				} else
 					exec_file[0] = '\0';
 				/* A #include */
-				do_include = ast_config_internal_load(cur, cfg, withcomments) ? 1 : 0;
+				do_include = ast_config_internal_load(cur, cfg, flags) ? 1 : 0;
 				if (!ast_strlen_zero(exec_file))
 					unlink(exec_file);
 				if (!do_include)
@@ -769,7 +778,7 @@
 	return 0;
 }
 
-static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg, int withcomments)
+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)
 {
 	char fn[256];
 	char buf[8192];
@@ -780,6 +789,7 @@
 	struct ast_category *cat = NULL;
 	int count = 0;
 	struct stat statbuf;
+	struct cache_file_mtime *cfmtime;
 	/*! Growable string buffer */
 	char *comment_buffer=0;   /*!< this will be a comment collector.*/
 	int   comment_buffer_size=0;  /*!< the amount of storage so far alloc'd for the comment_buffer */
@@ -796,7 +806,7 @@
 		snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, filename);
 	}
 
-	if (withcomments) {
+	if (ast_test_flag(&flags, OPT_WITHCOMMENTS)) {
 		CB_INIT(&comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size);
 		if (!lline_buffer || !comment_buffer) {
 			ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
@@ -833,6 +843,30 @@
 			ast_log(LOG_WARNING, "'%s' is not a regular file, ignoring\n", fn);
 			continue;
 		}
+
+		/* Find our cached entry for this configuration file */
+		AST_LIST_LOCK(&cfmtime_head);
+		AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
+			if (!strcmp(cfmtime->filename, fn))
+				break;
+		}
+		if (!cfmtime) {
+			cfmtime = ast_calloc(1, sizeof(*cfmtime) + strlen(fn) + 1);
+			if (!cfmtime)
+				continue;
+			strcpy(cfmtime->filename, fn);
+			/* Note that the file mtime is initialized to 0, i.e. 1970 */
+			AST_LIST_INSERT_TAIL(&cfmtime_head, cfmtime, list);
+		}
+		AST_LIST_UNLOCK(&cfmtime_head);
+
+		if ((cfmtime->mtime == statbuf.st_mtime) && ast_test_flag(&flags, OPT_MINUSONEWHENFILEISSAME)) {
+			ast_config_destroy(cfg);
+			cfg = (void *)-1;
+			continue;
+		}
+		cfmtime->mtime = statbuf.st_mtime;
+
 		ast_verb(2, "Parsing '%s': ", fn);
 			fflush(stdout);
 		if (!(f = fopen(fn, "r"))) {
@@ -846,7 +880,7 @@
 		while (!feof(f)) {
 			lineno++;
 			if (fgets(buf, sizeof(buf), f)) {
-				if ( withcomments ) {
+				if (ast_test_flag(&flags, OPT_WITHCOMMENTS)) {
 					CB_ADD(&comment_buffer, &comment_buffer_size, lline_buffer);       /* add the current lline buffer to the comment buffer */
 					lline_buffer[0] = 0;        /* erase the lline buffer */
 				}
@@ -883,7 +917,7 @@
 								/* Actually have to move what's left over the top, then continue */
 								char *oldptr;
 								oldptr = process_buf + strlen(process_buf);
-								if ( withcomments ) {
+								if (ast_test_flag(&flags, OPT_WITHCOMMENTS)) {
 									CB_ADD(&comment_buffer, &comment_buffer_size, ";");
 									CB_ADD_LEN(&comment_buffer, &comment_buffer_size, oldptr+1, new_buf-oldptr-1);
 								}
@@ -897,7 +931,7 @@
 						if (!comment) {
 							/* If ; is found, and we are not nested in a comment, 
 							   we immediately stop all comment processing */
-							if ( withcomments ) {
+							if (ast_test_flag(&flags, OPT_WITHCOMMENTS)) {
 								LLB_ADD(&lline_buffer, &lline_buffer_size, comment_p);
 							}
 							*comment_p = '\0'; 
@@ -906,7 +940,7 @@
 							new_buf = comment_p + 1;
 					}
 				}
-				if ( withcomments && comment && !process_buf )
+				if (ast_test_flag(&flags, OPT_WITHCOMMENTS) && comment && !process_buf )
 				{
 					CB_ADD(&comment_buffer, &comment_buffer_size, buf);  /* the whole line is a comment, store it */
 				}
@@ -914,7 +948,7 @@
 				if (process_buf) {
 					char *buf = ast_strip(process_buf);
 					if (!ast_strlen_zero(buf)) {
-						if (process_text_line(cfg, &cat, buf, lineno, fn, withcomments, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size)) {
+						if (process_text_line(cfg, &cat, buf, lineno, fn, ast_test_flag(&flags, OPT_WITHCOMMENTS), &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size)) {
 							cfg = NULL;
 							break;
 						}
@@ -928,7 +962,7 @@
 		ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment - 1]);
 	}
 #ifdef AST_INCLUDE_GLOB
-					if (!cfg)
+					if (!cfg || cfg == (void *)-1)
 						break;
 				}
 				globfree(&globbuf);
@@ -936,7 +970,7 @@
 		}
 #endif
 
-	if (cfg && cfg->include_level == 1 && withcomments && comment_buffer) {
+	if (cfg && cfg != (void *)-1 && cfg->include_level == 1 && ast_test_flag(&flags, OPT_WITHCOMMENTS) && comment_buffer) {
 		ast_free(comment_buffer);
 		ast_free(lline_buffer);
 		comment_buffer = NULL;
@@ -1090,12 +1124,13 @@
 	struct ast_config *config, *configtmp;
 	struct ast_variable *v;
 	char *driver, *table, *database, *stringp, *tmp;
+	struct ast_flags flags = { 0 };
 
 	clear_config_maps();
 
 	configtmp = ast_config_new();
 	configtmp->max_include_level = 1;
-	config = ast_config_internal_load(extconfig_conf, configtmp, 0);
+	config = ast_config_internal_load(extconfig_conf, configtmp, flags);
 	if (!config) {
 		ast_config_destroy(configtmp);
 		return 0;
@@ -1234,7 +1269,7 @@
 	.load_func = config_text_file_load,
 };
 
-struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, int withcomments)
+struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, struct ast_flags flags)
 {
 	char db[256];
 	char table[256];
@@ -1263,9 +1298,9 @@
 		}
 	}
 
-	result = loader->load_func(db, table, filename, cfg, withcomments);
-
-	if (result)
+	result = loader->load_func(db, table, filename, cfg, flags);
+
+	if (result && result != (void *)-1)
 		result->include_level--;
 	else
 		cfg->include_level--;
@@ -1273,7 +1308,7 @@
 	return result;
 }
 
-struct ast_config *ast_config_load(const char *filename)
+struct ast_config *ast_config_load(const char *filename, struct ast_flags flags)
 {
 	struct ast_config *cfg;
 	struct ast_config *result;
@@ -1282,8 +1317,8 @@
 	if (!cfg)
 		return NULL;
 
-	result = ast_config_internal_load(filename, cfg, 0);
-	if (!result)
+	result = ast_config_internal_load(filename, cfg, flags);
+	if (!result || result == (void *)-1)
 		ast_config_destroy(cfg);
 
 	return result;
@@ -1293,13 +1328,14 @@
 {
 	struct ast_config *cfg;
 	struct ast_config *result;
+	struct ast_flags flags = { OPT_WITHCOMMENTS };
 
 	cfg = ast_config_new();
 	if (!cfg)
 		return NULL;
 
-	result = ast_config_internal_load(filename, cfg, 1);
-	if (!result)
+	result = ast_config_internal_load(filename, cfg, flags);
+	if (!result || result == (void *)-1)
 		ast_config_destroy(cfg);
 
 	return result;

Modified: team/tilghman/config_mtime_cache/res/res_adsi.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_adsi.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_adsi.c (original)
+++ team/tilghman/config_mtime_cache/res/res_adsi.c Tue Aug 14 12:58:29 2007
@@ -1067,9 +1067,10 @@
 	int x;
 	struct ast_config *conf;
 	struct ast_variable *v;
+	struct ast_flags config_flags = { 0 };
 	char *name, *sname;
 	init_state();
-	conf = ast_config_load("adsi.conf");
+	conf = ast_config_load("adsi.conf", config_flags);
 	if (conf) {
 		x=0;
 		for (v = ast_variable_browse(conf, "intro"); v; v = v->next) {

Modified: team/tilghman/config_mtime_cache/res/res_config_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_config_odbc.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_config_odbc.c (original)
+++ team/tilghman/config_mtime_cache/res/res_config_odbc.c Tue Aug 14 12:58:29 2007
@@ -486,7 +486,7 @@
 	return sth;
 }
 
-static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg, int withcomments)
+static struct ast_config *config_odbc(const char *database, const char *table, const char *file, struct ast_config *cfg, struct ast_flags flags)
 {
 	struct ast_variable *new_v;
 	struct ast_category *cur_cat;
@@ -500,6 +500,7 @@
 	SQLHSTMT stmt;
 	char last[128] = "";
 	struct config_odbc_obj q;
+	struct ast_flags loader_flags = { 0 };
 
 	memset(&q, 0, sizeof(q));
 
@@ -542,7 +543,7 @@
 
 	while ((res = SQLFetch(stmt)) != SQL_NO_DATA) {
 		if (!strcmp (q.var_name, "#include")) {
-			if (!ast_config_internal_load(q.var_val, cfg, 0)) {
+			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/tilghman/config_mtime_cache/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_features.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_features.c (original)
+++ team/tilghman/config_mtime_cache/res/res_features.c Tue Aug 14 12:58:29 2007
@@ -2768,6 +2768,7 @@
 	struct ast_config *cfg = NULL;
 	struct ast_variable *var = NULL;
 	struct feature_group *fg = NULL;
+	struct ast_flags config_flags = { 0 };
 	char old_parking_ext[AST_MAX_EXTENSION];
 	char old_parking_con[AST_MAX_EXTENSION] = "";
 	char *ctg; 
@@ -2810,7 +2811,7 @@
 	atxferdropcall = DEFAULT_ATXFER_DROP_CALL;
 	atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
 
-	cfg = ast_config_load("features.conf");
+	cfg = ast_config_load("features.conf", config_flags);
 	if (!cfg) {
 		ast_log(LOG_WARNING,"Could not load features.conf\n");
 		return AST_MODULE_LOAD_DECLINE;

Modified: team/tilghman/config_mtime_cache/res/res_indications.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_indications.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_indications.c (original)
+++ team/tilghman/config_mtime_cache/res/res_indications.c Tue Aug 14 12:58:29 2007
@@ -236,7 +236,7 @@
 }
 
 /*! \brief load indications module */
-static int ind_load_module(void)
+static int ind_load_module(int reload)
 {
 	struct ast_config *cfg;
 	struct ast_variable *v;
@@ -244,12 +244,18 @@
 	char *c;
 	struct ind_tone_zone *tones;
 	const char *country = NULL;
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
 
 	/* that the following cast is needed, is yuk! */
 	/* yup, checked it out. It is NOT written to. */
-	cfg = ast_config_load((char *)config);
+	cfg = ast_config_load((char *)config, config_flags);
 	if (!cfg)
 		return -1;
+	else if (cfg == FILEUNCHANGED)
+		return 0;
+
+	if (reload)
+		ast_unregister_indication_country(NULL);
 
 	/* Use existing config to populate the Indication table */
 	cxt = ast_category_browse(cfg, NULL);
@@ -385,7 +391,7 @@
 /*! \brief Load indications module */
 static int load_module(void)
 {
-	if (ind_load_module())
+	if (ind_load_module(0))
 		return AST_MODULE_LOAD_DECLINE; 
 	ast_cli_register_multiple(cli_indications, sizeof(cli_indications) / sizeof(struct ast_cli_entry));
 	ast_register_application("PlayTones", handle_playtones, "Play a tone list", playtones_desc);
@@ -397,10 +403,7 @@
 /*! \brief Reload indications module */
 static int reload(void)
 {
-	/* remove the registed indications... */
-	ast_unregister_indication_country(NULL);
-
-	return ind_load_module();
+	return ind_load_module(1);
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Region-specific tones",

Modified: team/tilghman/config_mtime_cache/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_musiconhold.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_musiconhold.c (original)
+++ team/tilghman/config_mtime_cache/res/res_musiconhold.c Tue Aug 14 12:58:29 2007
@@ -1013,10 +1013,11 @@
 	struct mohclass *class;	
 	char *cat;
 	int numclasses = 0;
-
-	cfg = ast_config_load("musiconhold.conf");
-
-	if (!cfg)
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
+
+	cfg = ast_config_load("musiconhold.conf", config_flags);
+
+	if (cfg == NULL || cfg == FILEUNCHANGED)
 		return 0;
 
 	cat = ast_category_browse(cfg, NULL);

Modified: team/tilghman/config_mtime_cache/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_odbc.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_odbc.c (original)
+++ team/tilghman/config_mtime_cache/res/res_odbc.c Tue Aug 14 12:58:29 2007
@@ -213,10 +213,11 @@
 	char *cat, *dsn, *username, *password, *sanitysql;
 	int enabled, pooling, limit;
 	int connect = 0, res = 0;
+	struct ast_flags config_flags = { 0 };
 
 	struct odbc_class *new;
 
-	config = ast_config_load(cfg);
+	config = ast_config_load(cfg, config_flags);
 	if (!config) {
 		ast_log(LOG_WARNING, "Unable to load config file res_odbc.conf\n");
 		return -1;
@@ -538,6 +539,7 @@
 	char *cat, *dsn, *username, *password, *sanitysql;
 	int enabled, pooling, limit;
 	int connect = 0, res = 0;
+	struct ast_flags config_flags = { OPT_FILEUNCHANGED };
 
 	struct odbc_class *new, *class;
 	struct odbc_obj *current;
@@ -548,8 +550,8 @@
 		class->delme = 1;
 	}
 
-	config = ast_config_load(cfg);
-	if (config) {
+	config = ast_config_load(cfg, config_flags);
+	if (config != NULL && config != FILEUNCHANGED) {
 		for (cat = ast_category_browse(config, NULL); cat; cat=ast_category_browse(config, cat)) {
 			if (!strcasecmp(cat, "ENV")) {
 				for (v = ast_variable_browse(config, cat); v; v = v->next) {

Modified: team/tilghman/config_mtime_cache/res/res_smdi.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_smdi.c?view=diff&rev=79442&r1=79441&r2=79442
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_smdi.c (original)
+++ team/tilghman/config_mtime_cache/res/res_smdi.c Tue Aug 14 12:58:29 2007
@@ -513,6 +513,7 @@
 	struct ast_config *conf;
 	struct ast_variable *v;
 	struct ast_smdi_interface *iface = NULL;
+	struct ast_flags config_flags = { reload ? OPT_FILEUNCHANGED : 0 };
 	int res = 0;
 
 	/* Config options */
@@ -524,13 +525,14 @@
 	int msdstrip = 0;              /* strip zero digits */
 	long msg_expiry = SMDI_MSG_EXPIRY_TIME;
 
-	if (!(conf = ast_config_load(config_file))) {
+	if (!(conf = ast_config_load(config_file, config_flags))) {
 		if (reload)
 			ast_log(LOG_NOTICE, "Unable to reload config %s: SMDI untouched\n", config_file);
 		else
 			ast_log(LOG_NOTICE, "Unable to load config %s: SMDI disabled\n", config_file);
 		return 1;
-	}
+	} else if (conf == FILEUNCHANGED)
+		return 0;
 
 	/* Mark all interfaces that we are listening on.  We will unmark them
 	 * as we find them in the config file, this way we know any interfaces




More information about the asterisk-commits mailing list