From 57ede7e7547ebe1abd929f71265ed7cf0e1862dd Mon Sep 17 00:00:00 2001 From: Pedro Kiefer Date: Fri, 20 Jul 2012 12:07:20 -0300 Subject: [PATCH 3/7] Extract constant number to defines --- apps/app_alarmreceiver.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c index 4ff27ef..d410c1a 100644 --- a/apps/app_alarmreceiver.c +++ b/apps/app_alarmreceiver.c @@ -58,6 +58,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision: 362635 $") #define ALMRCV_CONFIG "alarmreceiver.conf" #define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID" +#define ADEMCO_MSG_TYPE_1 "18" +#define ADEMCO_MSG_TYPE_2 "98" struct event_node{ char data[17]; @@ -519,9 +521,8 @@ static int receive_ademco_contact_id(struct ast_channel *chan, const void *data, } /* Check the message type for correctness */ - - if (strncmp(event + 4, "18", 2)) { - if (strncmp(event + 4, "98", 2)) { + if (strncmp(event + 4, ADEMCO_MSG_TYPE_1, 2)) { + if (strncmp(event + 4, ADEMCO_MSG_TYPE_2, 2)) { database_increment("format-errors"); ast_verb(2, "AlarmReceiver: Wrong message type\n"); ast_debug(1, "AlarmReceiver: Wrong message type\n"); @@ -658,17 +659,16 @@ 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", + ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n", ALMRCV_CONFIG); return 0; } - if ((value = ast_variable_retrieve(cfg, "general", "eventcmd")) != NULL ) { + 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 ) { + if ((value = ast_variable_retrieve(cfg, "general", "loudness")) != NULL) { toneloudness = atoi(value); if (toneloudness < 100) { toneloudness = 100; @@ -678,7 +678,7 @@ static int load_config(void) } } - if ((value = ast_variable_retrieve(cfg, "general", "fdtimeout")) != NULL ) { + if ((value = ast_variable_retrieve(cfg, "general", "fdtimeout")) != NULL) { fdtimeout = atoi(value); if (fdtimeout < 1000) { fdtimeout = 1000; @@ -688,7 +688,7 @@ static int load_config(void) } } - if ((value = ast_variable_retrieve(cfg, "general", "sdtimeout")) != NULL ) { + if ((value = ast_variable_retrieve(cfg, "general", "sdtimeout")) != NULL) { sdtimeout = atoi(value); if (sdtimeout < 110) { sdtimeout = 110; @@ -698,19 +698,19 @@ static int load_config(void) } } - if ((value = ast_variable_retrieve(cfg, "general", "logindividualevents")) != NULL ) { + if ((value = ast_variable_retrieve(cfg, "general", "logindividualevents")) != NULL) { log_individual_events = ast_true(value); } - if ((value = ast_variable_retrieve(cfg, "general", "eventspooldir")) != NULL ) { + 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 ) { + 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 ) { + if ((value = ast_variable_retrieve(cfg, "general", "db-family")) != NULL) { ast_copy_string(db_family, value, sizeof(db_family)); } -- 1.7.9.6 (Apple Git-31.1)