[asterisk-commits] tilghman: branch tilghman/config_mtime_cache r79591 - in /team/tilghman/confi...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 15 12:08:55 CDT 2007
Author: tilghman
Date: Wed Aug 15 12:08:54 2007
New Revision: 79591
URL: http://svn.digium.com/view/asterisk?view=rev&rev=79591
Log:
A few more fixes for modules that I didn't have dependencies for, and a revision to the core to update the mtime correctly
Modified:
team/tilghman/config_mtime_cache/cdr/cdr_pgsql.c
team/tilghman/config_mtime_cache/cdr/cdr_sqlite3_custom.c
team/tilghman/config_mtime_cache/channels/chan_alsa.c
team/tilghman/config_mtime_cache/channels/chan_gtalk.c
team/tilghman/config_mtime_cache/channels/chan_jingle.c
team/tilghman/config_mtime_cache/codecs/codec_speex.c
team/tilghman/config_mtime_cache/main/config.c
team/tilghman/config_mtime_cache/pbx/pbx_dundi.c
team/tilghman/config_mtime_cache/res/res_config_pgsql.c
team/tilghman/config_mtime_cache/res/res_jabber.c
Modified: team/tilghman/config_mtime_cache/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/cdr/cdr_pgsql.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/cdr/cdr_pgsql.c (original)
+++ team/tilghman/config_mtime_cache/cdr/cdr_pgsql.c Wed Aug 15 12:08:54 2007
@@ -183,7 +183,7 @@
return 0;
}
-static int my_unload_module(void)
+static int unload_module(void)
{
PQfinish(conn);
if (pghostname)
@@ -202,20 +202,30 @@
return 0;
}
-static int process_my_load_module(struct ast_config *cfg)
+static int config_module(int reload)
{
struct ast_variable *var;
- char *pgerror;
+ char *pgerror;
const char *tmp;
+ struct ast_config *cfg;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((cfg = ast_config_load(config, config_flags)) == NULL) {
+ ast_log(LOG_WARNING, "Unable to load config for PostgreSQL CDR's: %s\n", config);
+ return -1;
+ } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
if (!(var = ast_variable_browse(cfg, "global")))
return 0;
- if (!(tmp = ast_variable_retrieve(cfg,"global","hostname"))) {
- ast_log(LOG_WARNING,"PostgreSQL server hostname not specified. Assuming unix socket connection\n");
+ if (!(tmp = ast_variable_retrieve(cfg, "global", "hostname"))) {
+ ast_log(LOG_WARNING, "PostgreSQL server hostname not specified. Assuming unix socket connection\n");
tmp = ""; /* connect via UNIX-socket by default */
}
-
+
+ if (pghostname)
+ ast_free(pghostname);
if (!(pghostname = ast_strdup(tmp)))
return -1;
@@ -224,6 +234,8 @@
tmp = "asteriskcdrdb";
}
+ if (pgdbname)
+ ast_free(pgdbname);
if (!(pgdbname = ast_strdup(tmp)))
return -1;
@@ -232,6 +244,8 @@
tmp = "asterisk";
}
+ if (pgdbuser)
+ ast_free(pgdbuser);
if (!(pgdbuser = ast_strdup(tmp)))
return -1;
@@ -240,6 +254,8 @@
tmp = "";
}
+ if (pgpassword)
+ ast_free(pgpassword);
if (!(pgpassword = ast_strdup(tmp)))
return -1;
@@ -248,6 +264,8 @@
tmp = "5432";
}
+ if (pgdbport)
+ ast_free(pgdbport);
if (!(pgdbport = ast_strdup(tmp)))
return -1;
@@ -256,6 +274,8 @@
tmp = "cdr";
}
+ if (table)
+ ast_free(table);
if (!(table = ast_strdup(tmp)))
return -1;
@@ -276,49 +296,23 @@
ast_debug(1, "Successfully connected to PostgreSQL database.\n");
connected = 1;
} else {
- pgerror = PQerrorMessage(conn);
+ pgerror = PQerrorMessage(conn);
ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s. CALLS WILL NOT BE LOGGED!!\n", pghostname);
- ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
+ ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
connected = 0;
}
return ast_cdr_register(name, ast_module_info->description, pgsql_log);
-}
-
-static int my_load_module(void)
-{
- struct ast_config *cfg;
- int res;
-
- if (!(cfg = ast_config_load(config))) {
- ast_log(LOG_WARNING, "Unable to load config for PostgreSQL CDR's: %s\n", config);
- return AST_MODULE_LOAD_DECLINE;
- }
-
- res = process_my_load_module(cfg);
- ast_config_destroy(cfg);
-
- return res;
}
static int load_module(void)
{
- return my_load_module();
-}
-
-static int unload_module(void)
-{
- return my_unload_module();
+ return config_module(0) ? AST_MODULE_LOAD_DECLINE : 0;
}
static int reload(void)
{
- int res;
- ast_mutex_lock(&pgsql_lock);
- my_unload_module();
- res = my_load_module();
- ast_mutex_unlock(&pgsql_lock);
- return res;
+ return config_module(1);
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "PostgreSQL CDR Backend",
Modified: team/tilghman/config_mtime_cache/cdr/cdr_sqlite3_custom.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/cdr/cdr_sqlite3_custom.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/cdr/cdr_sqlite3_custom.c (original)
+++ team/tilghman/config_mtime_cache/cdr/cdr_sqlite3_custom.c Wed Aug 15 12:08:54 2007
@@ -74,10 +74,11 @@
static int load_config(int reload)
{
struct ast_config *cfg;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
struct ast_variable *mappingvar;
const char *tmp;
- if (!(cfg = ast_config_load(config_file))) {
+ if (!(cfg = ast_config_load(config_file, config_flags))) {
if (reload)
ast_log(LOG_WARNING, "%s: Failed to reload configuration file.\n", name);
else {
@@ -86,10 +87,10 @@
name);
}
return -1;
- }
-
- if (!reload)
- ast_mutex_lock(&lock);
+ } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
+
+ ast_mutex_lock(&lock);
if (!(mappingvar = ast_variable_browse(cfg, "master"))) {
/* nothing configured */
@@ -125,8 +126,7 @@
return -1;
}
- if (!reload)
- ast_mutex_unlock(&lock);
+ ast_mutex_unlock(&lock);
ast_config_destroy(cfg);
@@ -248,13 +248,7 @@
static int reload(void)
{
- int res;
-
- ast_mutex_lock(&lock);
- res = load_config(1);
- ast_mutex_unlock(&lock);
-
- return res;
+ return load_config(1);
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "SQLite3 Custom CDR Module",
Modified: team/tilghman/config_mtime_cache/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_alsa.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_alsa.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_alsa.c Wed Aug 15 12:08:54 2007
@@ -1082,13 +1082,14 @@
{
struct ast_config *cfg;
struct ast_variable *v;
+ struct ast_flags config_flags = { 0 };
/* Copy the default jb config over global_jbconf */
memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
strcpy(mohinterpret, "default");
- if (!(cfg = ast_config_load(config)))
+ if (!(cfg = ast_config_load(config, config_flags)))
return AST_MODULE_LOAD_DECLINE;
v = ast_variable_browse(cfg, "general");
Modified: team/tilghman/config_mtime_cache/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_gtalk.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_gtalk.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_gtalk.c Wed Aug 15 12:08:54 2007
@@ -1702,8 +1702,9 @@
struct gtalk_candidate *global_candidates = NULL;
struct hostent *hp;
struct ast_hostent ahp;
-
- cfg = ast_config_load(GOOGLE_CONFIG);
+ struct ast_flags config_flags = { 0 };
+
+ cfg = ast_config_load(GOOGLE_CONFIG, config_flags);
if (!cfg)
return 0;
Modified: team/tilghman/config_mtime_cache/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/channels/chan_jingle.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/channels/chan_jingle.c (original)
+++ team/tilghman/config_mtime_cache/channels/chan_jingle.c Wed Aug 15 12:08:54 2007
@@ -1567,8 +1567,9 @@
struct ast_codec_pref prefs;
struct aji_client_container *clients;
struct jingle_candidate *global_candidates = NULL;
-
- cfg = ast_config_load(JINGLE_CONFIG);
+ struct ast_flags config_flags = { 0 };
+
+ cfg = ast_config_load(JINGLE_CONFIG, config_flags);
if (!cfg)
return 0;
Modified: team/tilghman/config_mtime_cache/codecs/codec_speex.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/codecs/codec_speex.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/codecs/codec_speex.c (original)
+++ team/tilghman/config_mtime_cache/codecs/codec_speex.c Wed Aug 15 12:08:54 2007
@@ -375,14 +375,15 @@
.buf_size = BUFFER_SAMPLES * 2, /* XXX maybe a lot less ? */
};
-static void parse_config(void)
-{
- struct ast_config *cfg = ast_config_load("codecs.conf");
+static void parse_config(int reload)
+{
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+ struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
struct ast_variable *var;
int res;
float res_f;
- if (cfg == NULL)
+ if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED)
return;
for (var = ast_variable_browse(cfg, "speex"); var; var = var->next) {
@@ -470,7 +471,7 @@
static int reload(void)
{
- parse_config();
+ parse_config(1);
return 0;
}
@@ -489,7 +490,7 @@
{
int res;
- parse_config();
+ parse_config(0);
res=ast_register_translator(&speextolin);
if (!res)
res=ast_register_translator(&lintospeex);
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=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/main/config.c (original)
+++ team/tilghman/config_mtime_cache/main/config.c Wed Aug 15 12:08:54 2007
@@ -614,6 +614,7 @@
{
struct cache_file_mtime *cfmtime;
struct cache_file_include *cfinclude;
+ struct stat statbuf = { 0, };
/* Find our cached entry for this configuration file */
AST_LIST_LOCK(&cfmtime_head);
@@ -632,6 +633,11 @@
/* Note that the file mtime is initialized to 0, i.e. 1970 */
AST_LIST_INSERT_TAIL(&cfmtime_head, cfmtime, list);
}
+
+ if (!stat(configfile, &statbuf))
+ cfmtime->mtime = 0;
+ else
+ cfmtime->mtime = statbuf.st_mtime;
switch (attrtype) {
case ATTRIBUTE_INCLUDE:
Modified: team/tilghman/config_mtime_cache/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/pbx/pbx_dundi.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/pbx/pbx_dundi.c (original)
+++ team/tilghman/config_mtime_cache/pbx/pbx_dundi.c Wed Aug 15 12:08:54 2007
@@ -4554,13 +4554,14 @@
matchmore: dundi_matchmore,
};
-static int set_config(char *config_file, struct sockaddr_in* sin)
+static int set_config(char *config_file, struct sockaddr_in* sin, int reload)
{
struct ast_config *cfg;
struct ast_variable *v;
char *cat;
int format;
int x;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
char hn[MAXHOSTNAMELEN] = "";
struct ast_hostent he;
struct hostent *hp;
@@ -4569,11 +4570,12 @@
int globalpcmodel = 0;
dundi_eid testeid;
+ if ((cfg = ast_config_load(config_file, config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
+
dundi_ttl = DUNDI_DEFAULT_TTL;
dundi_cache_time = DUNDI_DEFAULT_CACHE_TIME;
- cfg = ast_config_load(config_file);
-
-
+
if (!cfg) {
ast_log(LOG_ERROR, "Unable to load config %s\n", config_file);
return -1;
@@ -4740,7 +4742,7 @@
{
struct sockaddr_in sin;
- if (set_config("dundi.conf", &sin))
+ if (set_config("dundi.conf", &sin, 1))
return -1;
return 0;
@@ -4764,7 +4766,7 @@
if (!io || !sched)
return AST_MODULE_LOAD_FAILURE;
- if (set_config("dundi.conf", &sin))
+ if (set_config("dundi.conf", &sin, 0))
return AST_MODULE_LOAD_DECLINE;
netsocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
Modified: team/tilghman/config_mtime_cache/res/res_config_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_config_pgsql.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_config_pgsql.c (original)
+++ team/tilghman/config_mtime_cache/res/res_config_pgsql.c Wed Aug 15 12:08:54 2007
@@ -62,7 +62,7 @@
static int dbport = 5432;
static time_t connect_time = 0;
-static int parse_config(void);
+static int parse_config(int reload);
static int pgsql_reconnect(const char *database);
static int realtime_pgsql_status(int fd, int argc, char **argv);
@@ -431,7 +431,7 @@
static struct ast_config *config_pgsql(const char *database, const char *table,
const char *file, struct ast_config *cfg,
- int withcomments)
+ struct ast_flags flags)
{
PGresult *result = NULL;
long num_rows;
@@ -496,7 +496,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, 0)) {
+ if (!ast_config_internal_load(field_var_val, cfg, flags)) {
PQclear(result);
ast_mutex_unlock(&pgsql_lock);
return NULL;
@@ -536,35 +536,25 @@
static int load_module(void)
{
- if(!parse_config())
+ if(!parse_config(0))
return AST_MODULE_LOAD_DECLINE;
-
- ast_mutex_lock(&pgsql_lock);
-
- if (!pgsql_reconnect(NULL)) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: Couldn't establish connection. Check debug.\n");
- ast_debug(1, "Postgresql RealTime: Cannot Connect: %s\n", PQerrorMessage(pgsqlConn));
- }
ast_config_engine_register(&pgsql_engine);
ast_verb(1, "Postgresql RealTime driver loaded.\n");
ast_cli_register_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
- ast_mutex_unlock(&pgsql_lock);
-
return 0;
}
static int unload_module(void)
{
- /* Aquire control before doing anything to the module itself. */
+ /* Acquire control before doing anything to the module itself. */
ast_mutex_lock(&pgsql_lock);
if (pgsqlConn) {
PQfinish(pgsqlConn);
pgsqlConn = NULL;
- };
+ }
ast_cli_unregister_multiple(cli_realtime, sizeof(cli_realtime) / sizeof(struct ast_cli_entry));
ast_config_engine_deregister(&pgsql_engine);
ast_verb(1, "Postgresql RealTime unloaded.\n");
@@ -577,40 +567,32 @@
static int reload(void)
{
- /* Aquire control before doing anything to the module itself. */
+ parse_config(1);
+
+ return 0;
+}
+
+static int parse_config(int reload)
+{
+ struct ast_config *config;
+ const char *s;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((config = ast_config_load(RES_CONFIG_PGSQL_CONF, config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return 0;
+
+ if (!config) {
+ ast_log(LOG_WARNING, "Unable to load config %s\n", RES_CONFIG_PGSQL_CONF);
+ return 0;
+ }
+
ast_mutex_lock(&pgsql_lock);
if (pgsqlConn) {
PQfinish(pgsqlConn);
pgsqlConn = NULL;
- };
- parse_config();
-
- if (!pgsql_reconnect(NULL)) {
- ast_log(LOG_WARNING,
- "Postgresql RealTime: Couldn't establish connection. Check debug.\n");
- ast_debug(1, "Postgresql RealTime: Cannot Connect: %s\n", PQerrorMessage(pgsqlConn));
- }
-
- ast_verb(2, "Postgresql RealTime reloaded.\n");
-
- /* Done reloading. Release lock so others can now use driver. */
- ast_mutex_unlock(&pgsql_lock);
-
- return 0;
-}
-
-static int parse_config(void)
-{
- struct ast_config *config;
- const char *s;
-
- config = ast_config_load(RES_CONFIG_PGSQL_CONF);
-
- if (!config) {
- ast_log(LOG_WARNING, "Unable to load config %s\n",RES_CONFIG_PGSQL_CONF);
- return 0;
- }
+ }
+
if (!(s = ast_variable_retrieve(config, "general", "dbuser"))) {
ast_log(LOG_WARNING,
"Postgresql RealTime: No database user found, using 'asterisk' as default.\n");
@@ -671,6 +653,17 @@
ast_debug(1, "Postgresql RealTime Password: %s\n", dbpass);
ast_debug(1, "Postgresql RealTime DBName: %s\n", dbname);
}
+
+ if (!pgsql_reconnect(NULL)) {
+ ast_log(LOG_WARNING,
+ "Postgresql RealTime: Couldn't establish connection. Check debug.\n");
+ ast_debug(1, "Postgresql RealTime: Cannot Connect: %s\n", PQerrorMessage(pgsqlConn));
+ }
+
+ ast_verb(2, "Postgresql RealTime reloaded.\n");
+
+ /* Done reloading. Release lock so others can now use driver. */
+ ast_mutex_unlock(&pgsql_lock);
return 1;
}
Modified: team/tilghman/config_mtime_cache/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/config_mtime_cache/res/res_jabber.c?view=diff&rev=79591&r1=79590&r2=79591
==============================================================================
--- team/tilghman/config_mtime_cache/res/res_jabber.c (original)
+++ team/tilghman/config_mtime_cache/res/res_jabber.c Wed Aug 15 12:08:54 2007
@@ -94,8 +94,8 @@
static int aji_show_clients(int fd, int argc, char *argv[]);
static int aji_create_client(char *label, struct ast_variable *var, int debug);
static int aji_create_buddy(char *label, struct aji_client *client);
-static int aji_reload(void);
-static int aji_load_config(void);
+static int aji_reload(int reload);
+static int aji_load_config(int reload);
static void aji_pruneregister(struct aji_client *client);
static int aji_filter_roster(void *data, ikspak *pak);
static int aji_get_roster(struct aji_client *client);
@@ -2035,7 +2035,7 @@
*/
static int aji_do_reload(int fd, int argc, char *argv[])
{
- aji_reload();
+ aji_reload(1);
ast_cli(fd, "Jabber Reloaded.\n");
return RESULT_SUCCESS;
}
@@ -2371,17 +2371,20 @@
}
/*!< load config file. \return 1. */
-static int aji_load_config(void)
+static int aji_load_config(int reload)
{
char *cat = NULL;
int debug = 1;
struct ast_config *cfg = NULL;
struct ast_variable *var = NULL;
+ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+
+ if ((cfg = ast_config_load(JABBER_CONFIG, config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+ return -1;
/* Reset flags to default value */
ast_set_flag(&globalflags, AJI_AUTOPRUNE | AJI_AUTOREGISTER);
- cfg = ast_config_load(JABBER_CONFIG);
if (!cfg) {
ast_log(LOG_WARNING, "No such configuration file %s\n", JABBER_CONFIG);
return 0;
@@ -2481,13 +2484,17 @@
}
/*! \brief Reload the jabber module */
-static int aji_reload()
-{
+static int aji_reload(int reload)
+{
+ int res;
+
ASTOBJ_CONTAINER_MARKALL(&clients);
- if (!aji_load_config()) {
+ if (!(res = aji_load_config(reload))) {
ast_log(LOG_ERROR, "JABBER: Failed to load config.\n");
return 0;
- }
+ } else if (res == -1)
+ return 1;
+
ASTOBJ_CONTAINER_PRUNE_MARKED(&clients, aji_client_destroy);
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
@@ -2539,7 +2546,7 @@
static int load_module(void)
{
ASTOBJ_CONTAINER_INIT(&clients);
- if(!aji_reload())
+ if(!aji_reload(0))
return AST_MODULE_LOAD_DECLINE;
ast_manager_register2("JabberSend", EVENT_FLAG_SYSTEM, manager_jabber_send,
"Sends a message to a Jabber Client", mandescr_jabber_send);
@@ -2553,7 +2560,7 @@
/*! \brief Wrapper for aji_reload */
static int reload(void)
{
- aji_reload();
+ aji_reload(1);
return 0;
}
More information about the asterisk-commits
mailing list