From c374a46f5575b362b13e6ed90159d535b789b4c3 Mon Sep 17 00:00:00 2001 From: Pedro Kiefer Date: Mon, 13 Aug 2012 13:36:44 -0300 Subject: [PATCH 2/7] Clean up load_config making it more readable --- apps/app_alarmreceiver.c | 91 ++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c index a0189e8..4ff27ef 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 */ @@ -658,59 +658,64 @@ static int load_config(void) ast_verb(4, "AlarmReceiver: No config file\n"); return 0; } else if (cfg == CONFIG_STATUS_FILEINVALID) { - ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", ALMRCV_CONFIG); + 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)); + } + + if ((value = ast_variable_retrieve(cfg, "general", "eventcmd")) != NULL ) { + ast_copy_string(event_app, value, sizeof(event_app)); + } + + if ((value = ast_variable_retrieve(cfg, "general", "loudness")) != NULL ) { + toneloudness = atoi(value); + if (toneloudness < 100) { + toneloudness = 100; } - p = ast_variable_retrieve(cfg, "general", "loudness"); - if (p) { - toneloudness = atoi(p); - if(toneloudness < 100) - toneloudness = 100; - if(toneloudness > 8192) - toneloudness = 8192; + 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; + } + + 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", "sdtimeout"); - if (p) { - sdtimeout = atoi(p); - if(sdtimeout < 110) - sdtimeout = 110; - if(sdtimeout > 4000) - sdtimeout = 4000; + 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", "logindividualevents"); - if (p) - log_individual_events = ast_true(p); + if ((value = ast_variable_retrieve(cfg, "general", "logindividualevents")) != NULL ) { + log_individual_events = ast_true(value); + } - 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", "eventspooldir")) != NULL ) { + ast_copy_string(event_spool_dir, value, sizeof(event_spool_dir)); + } - 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", "timestampformat")) != NULL ) { + ast_copy_string(time_stamp_format, value, sizeof(time_stamp_format)); + } - 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", "db-family")) != NULL ) { + ast_copy_string(db_family, value, sizeof(db_family)); } + + ast_config_destroy(cfg); + return 1; } -- 1.7.9.6 (Apple Git-31.1)