From 241002227085577279d03528e06d5f1e90d0ecd2 Mon Sep 17 00:00:00 2001 From: Pedro Kiefer Date: Fri, 20 Jul 2012 12:04:50 -0300 Subject: [PATCH 2/6] Clean up load_config making it more readable --- apps/app_alarmreceiver.c | 87 ++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c index a0189e8..f828956 100644 --- a/apps/app_alarmreceiver.c +++ b/apps/app_alarmreceiver.c @@ -648,7 +648,7 @@ static int alarmreceiver_exec(struct ast_channel *chan, const char *data) static int load_config(void) { struct ast_config *cfg; - const char *p; + const char *value; struct ast_flags config_flags = { 0 }; /* Read in the config file */ @@ -660,57 +660,52 @@ static int load_config(void) } else if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", ALMRCV_CONFIG); return 0; - } else { - p = ast_variable_retrieve(cfg, "general", "eventcmd"); - if (p) { - ast_copy_string(event_app, p, sizeof(event_app)); - } - p = ast_variable_retrieve(cfg, "general", "loudness"); - if (p) { - toneloudness = atoi(p); - if(toneloudness < 100) - toneloudness = 100; - if(toneloudness > 8192) - toneloudness = 8192; - } - p = ast_variable_retrieve(cfg, "general", "fdtimeout"); - if (p) { - fdtimeout = atoi(p); - if(fdtimeout < 1000) - fdtimeout = 1000; - if(fdtimeout > 10000) - fdtimeout = 10000; - } + } - p = ast_variable_retrieve(cfg, "general", "sdtimeout"); - if (p) { - sdtimeout = atoi(p); - if(sdtimeout < 110) - sdtimeout = 110; - if(sdtimeout > 4000) - sdtimeout = 4000; - } + if ((value = ast_variable_retrieve(cfg, "general", "eventcmd")) != NULL) { + ast_copy_string(event_app, value, sizeof(event_app)); + } - p = ast_variable_retrieve(cfg, "general", "logindividualevents"); - if (p) - log_individual_events = ast_true(p); + if ((value = ast_variable_retrieve(cfg, "general", "loudness")) != NULL) { + toneloudness = atoi(value); + if(toneloudness < 100) + toneloudness = 100; + if(toneloudness > 8192) + toneloudness = 8192; + } - p = ast_variable_retrieve(cfg, "general", "eventspooldir"); - if (p) { - ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir)); - } + if ((value = ast_variable_retrieve(cfg, "general", "fdtimeout")) != NULL) { + fdtimeout = atoi(value); + if(fdtimeout < 1000) + fdtimeout = 1000; + if(fdtimeout > 10000) + fdtimeout = 10000; + } - p = ast_variable_retrieve(cfg, "general", "timestampformat"); - if (p) { - ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format)); - } + if ((value = ast_variable_retrieve(cfg, "general", "sdtimeout")) != NULL) { + sdtimeout = atoi(value); + if(sdtimeout < 110) + sdtimeout = 110; + if(sdtimeout > 4000) + sdtimeout = 4000; + } - p = ast_variable_retrieve(cfg, "general", "db-family"); - if (p) { - ast_copy_string(db_family, p, sizeof(db_family)); - } - ast_config_destroy(cfg); + if ((value = ast_variable_retrieve(cfg, "general", "logindividualevents")) != NULL) + log_individual_events = ast_true(value); + + if ((value = ast_variable_retrieve(cfg, "general", "eventspooldir")) != NULL) { + ast_copy_string(event_spool_dir, value, sizeof(event_spool_dir)); } + + if ((value = ast_variable_retrieve(cfg, "general", "timestampformat")) != NULL) { + ast_copy_string(time_stamp_format, value, sizeof(time_stamp_format)); + } + + if ((value = ast_variable_retrieve(cfg, "general", "db-family")) != NULL) { + ast_copy_string(db_family, value, sizeof(db_family)); + } + ast_config_destroy(cfg); + return 1; } -- 1.7.9.5