diff options
author | Michal Čihař <michal@cihar.com> | 2011-11-29 15:13:48 +0100 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2011-11-29 15:13:48 +0100 |
commit | 3dd6a43ccd4feb5e2a041eb8192ce718f03dd885 (patch) | |
tree | b685a15d0469e7592169c938d704cc70e7f80f65 /smsd | |
parent | b0f42d7c65e223a95a7fca8c00986a77695807d2 (diff) |
Imported Upstream version 1.30.91
Diffstat (limited to 'smsd')
-rw-r--r-- | smsd/common.h | 1 | ||||
-rw-r--r-- | smsd/core.c | 85 | ||||
-rw-r--r-- | smsd/core.h | 4 | ||||
-rw-r--r-- | smsd/inject.c | 17 | ||||
-rw-r--r-- | smsd/main.c | 17 | ||||
-rw-r--r-- | smsd/monitor.c | 23 | ||||
-rw-r--r-- | smsd/test-smsd-files-include.sh.in | 6 | ||||
-rwxr-xr-x | smsd/test-smsd.sh.in | 6 |
8 files changed, 126 insertions, 33 deletions
diff --git a/smsd/common.h b/smsd/common.h index 2a3a217..8dc68fb 100644 --- a/smsd/common.h +++ b/smsd/common.h @@ -19,6 +19,7 @@ typedef struct { gboolean run_service; gboolean install_service; gboolean uninstall_service; + gboolean use_log; int max_failures; } SMSD_Parameters; #endif diff --git a/smsd/core.c b/smsd/core.c index b308d42..76607ed 100644 --- a/smsd/core.c +++ b/smsd/core.c @@ -543,6 +543,9 @@ GSM_Error SMSD_LoadNumbersFile(GSM_SMSDConfig *Config, GSM_StringArray *Array, c GSM_Error SMSD_ConfigureLogging(GSM_SMSDConfig *Config, gboolean uselog) { int fd; +#ifdef HAVE_SYSLOG + int facility; +#endif /* No logging configured */ if (Config->logfilename == NULL) { @@ -566,8 +569,34 @@ GSM_Error SMSD_ConfigureLogging(GSM_SMSDConfig *Config, gboolean uselog) #endif #ifdef HAVE_SYSLOG } else if (strcmp(Config->logfilename, "syslog") == 0) { + if (Config->logfacility == NULL) { + facility = LOG_DAEMON; + } else if (strcasecmp(Config->logfacility, "DAEMON")) { + facility = LOG_DAEMON; + } else if (strcasecmp(Config->logfacility, "USER")) { + facility = LOG_USER; + } else if (strcasecmp(Config->logfacility, "LOCAL0")) { + facility = LOG_LOCAL0; + } else if (strcasecmp(Config->logfacility, "LOCAL1")) { + facility = LOG_LOCAL1; + } else if (strcasecmp(Config->logfacility, "LOCAL2")) { + facility = LOG_LOCAL2; + } else if (strcasecmp(Config->logfacility, "LOCAL3")) { + facility = LOG_LOCAL3; + } else if (strcasecmp(Config->logfacility, "LOCAL4")) { + facility = LOG_LOCAL4; + } else if (strcasecmp(Config->logfacility, "LOCAL5")) { + facility = LOG_LOCAL5; + } else if (strcasecmp(Config->logfacility, "LOCAL6")) { + facility = LOG_LOCAL6; + } else if (strcasecmp(Config->logfacility, "LOCAL7")) { + facility = LOG_LOCAL7; + } else { + fprintf(stderr, "Invalid facility \"%s\"\n", Config->logfacility); + facility = LOG_DAEMON; + } Config->log_type = SMSD_LOG_SYSLOG; - openlog(Config->program_name, LOG_PID, LOG_DAEMON); + openlog(Config->program_name, LOG_PID, facility); Config->use_stderr = TRUE; #endif } else { @@ -632,6 +661,7 @@ GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig *Config, gboolean Config->gammu_log_buffer = NULL; Config->gammu_log_buffer_size = 0; Config->logfilename = NULL; + Config->logfacility = NULL; Config->smsdcfgfile = NULL; Config->use_timestamps = TRUE; Config->log_type = SMSD_LOG_NONE; @@ -677,7 +707,9 @@ GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig *Config, gboolean Config->debug_level = 0; } - Config->logfilename=INI_GetValue(Config->smsdcfgfile, "smsd", "logfile", FALSE); + Config->logfilename = INI_GetValue(Config->smsdcfgfile, "smsd", "logfile", FALSE); + Config->logfacility = INI_GetValue(Config->smsdcfgfile, "smsd", "logfacility", FALSE); + error = SMSD_ConfigureLogging(Config, uselog); if (error != ERR_NONE) { return error; @@ -772,7 +804,7 @@ GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig *Config, gboolean str = INI_GetValue(Config->smsdcfgfile, "smsd", "smsc", FALSE); if (str) { - Config->SMSC.Location = 1; + Config->SMSC.Location = 0; Config->SMSC.DefaultNumber[0] = 0; Config->SMSC.DefaultNumber[1] = 0; Config->SMSC.Name[0] = 0; @@ -781,9 +813,12 @@ GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig *Config, gboolean Config->SMSC.Format = SMS_FORMAT_Text; EncodeUnicode(Config->SMSC.Number, str, strlen(str)); } else { - Config->SMSC.Location = 0; + Config->SMSC.Location = -1; } + /* Clear cache */ + Config->SMSCCache.Location = 0; + /* Read service specific configuration */ error = Config->Service->ReadConfiguration(Config); if (error != ERR_NONE) return error; @@ -844,7 +879,7 @@ GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig *Config, gboolean Config->prevSMSID[0] = 0; Config->relativevalidity = -1; Config->Status = NULL; - Config->IncompleteMessageID = 0; + Config->IncompleteMessageID = -1; Config->IncompleteMessageTime = 0; return ERR_NONE; @@ -1239,14 +1274,26 @@ GSM_Error SMSD_ProcessSMS(GSM_SMSDConfig *Config, GSM_MultiSMSMessage *sms) gboolean SMSD_CheckMultipart(GSM_SMSDConfig *Config, GSM_MultiSMSMessage *MultiSMS) { gboolean same_id; + int current_id; /* Does the message have UDH (is multipart)? */ if (MultiSMS->SMS[0].UDH.Type == UDH_NoUDH || MultiSMS->SMS[0].UDH.AllParts == -1) { return TRUE; } + /* Grab current id */ + if (MultiSMS->SMS[0].UDH.ID16bit != -1) { + current_id = MultiSMS->SMS[0].UDH.ID16bit; + } else { + current_id = MultiSMS->SMS[0].UDH.ID8bit; + } + /* Do we have same id as last incomplete? */ - same_id = (Config->IncompleteMessageID == MultiSMS->SMS[0].UDH.ID16bit || Config->IncompleteMessageID == MultiSMS->SMS[0].UDH.ID8bit); + same_id = (Config->IncompleteMessageID != -1 && Config->IncompleteMessageID == current_id); + + /* Some logging */ + SMSD_Log(DEBUG_INFO, Config, "Multipart message 0x%02X, %d parts of %d", + current_id, MultiSMS->Number, MultiSMS->SMS[0].UDH.AllParts); /* Check if we have all parts */ if (MultiSMS->SMS[0].UDH.AllParts == MultiSMS->Number) { @@ -1255,9 +1302,10 @@ gboolean SMSD_CheckMultipart(GSM_SMSDConfig *Config, GSM_MultiSMSMessage *MultiS /* Have we seen this message recently? */ if (same_id) { - if (Config->IncompleteMessageTime != 0 && difftime(time(NULL), Config->IncompleteMessageTime) > Config->multiparttimeout) { + if (Config->IncompleteMessageTime != 0 && difftime(time(NULL), Config->IncompleteMessageTime) >= Config->multiparttimeout) { SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, processing after timeout", Config->IncompleteMessageID); + Config->IncompleteMessageID = -1; } else { SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, waiting for other parts (waited %.0f seconds)", Config->IncompleteMessageID, @@ -1286,6 +1334,7 @@ success: /* Clean multipart wait flag */ if (same_id) { Config->IncompleteMessageTime = 0; + Config->IncompleteMessageID = -1; } return TRUE; } @@ -1493,7 +1542,7 @@ GSM_Error SMSD_SendSMS(GSM_SMSDConfig *Config) if (error != ERR_NONE) { /* Unknown error - escape */ SMSD_Log(DEBUG_INFO, Config, "Error in outbox on '%s'", Config->SMSID); - for (i=0;i<sms.Number;i++) { + for (i = 0; i < sms.Number; i++) { Config->Status->Failed++; Config->Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_ERROR, -1); } @@ -1526,21 +1575,31 @@ GSM_Error SMSD_SendSMS(GSM_SMSDConfig *Config) } for (i = 0; i < sms.Number; i++) { + if (sms.SMS[i].SMSC.Location == 0 && UnicodeLength(sms.SMS[i].SMSC.Number) == 0 && Config->SMSC.Location == 0) { + SMSD_Log(DEBUG_INFO, Config, "Message without SMSC, using configured one"); + memcpy(&sms.SMS[i].SMSC,&Config->SMSC,sizeof(GSM_SMSC)); + sms.SMS[i].SMSC.Location = 0; + if (Config->relativevalidity != -1) { + sms.SMS[i].SMSC.Validity.Format = SMS_Validity_RelativeFormat; + sms.SMS[i].SMSC.Validity.Relative = Config->relativevalidity; + } + + } if (sms.SMS[i].SMSC.Location == 0 && UnicodeLength(sms.SMS[i].SMSC.Number) == 0) { SMSD_Log(DEBUG_INFO, Config, "Message without SMSC, assuming you want to use the one from phone"); sms.SMS[i].SMSC.Location = 1; } if (sms.SMS[i].SMSC.Location != 0) { - if (Config->SMSC.Location != sms.SMS[i].SMSC.Location) { - Config->SMSC.Location = sms.SMS[i].SMSC.Location; - error = GSM_GetSMSC(Config->gsm,&Config->SMSC); + if (Config->SMSCCache.Location != sms.SMS[i].SMSC.Location) { + Config->SMSCCache.Location = sms.SMS[i].SMSC.Location; + error = GSM_GetSMSC(Config->gsm,&Config->SMSCCache); if (error!=ERR_NONE) { SMSD_Log(DEBUG_ERROR, Config, "Error getting SMSC from phone"); return ERR_UNKNOWN; } } - memcpy(&sms.SMS[i].SMSC,&Config->SMSC,sizeof(GSM_SMSC)); + memcpy(&sms.SMS[i].SMSC,&Config->SMSCCache,sizeof(GSM_SMSC)); sms.SMS[i].SMSC.Location = 0; if (Config->relativevalidity != -1) { sms.SMS[i].SMSC.Validity.Format = SMS_Validity_RelativeFormat; @@ -1901,7 +1960,7 @@ GSM_Error SMSD_MainLoop(GSM_SMSDConfig *Config, gboolean exit_on_failure, int ma /* Sleep some time before another loop */ current_time = time(NULL); - if (Config->loopsleep <= 1) { + if (Config->loopsleep == 1) { sleep(1); } else if (difftime(current_time, lastloop) < Config->loopsleep) { sleep(Config->loopsleep - difftime(current_time, lastloop)); diff --git a/smsd/core.h b/smsd/core.h index 3474704..9cac06c 100644 --- a/smsd/core.h +++ b/smsd/core.h @@ -81,7 +81,7 @@ struct _GSM_SMSDConfig { unsigned int resetfrequency; unsigned int hardresetfrequency; unsigned int multiparttimeout; - const char *deliveryreport, *logfilename, *PINCode, *NetworkCode, *PhoneCode; + const char *deliveryreport, *logfilename, *logfacility, *PINCode, *NetworkCode, *PhoneCode; const char *PhoneID; const char *RunOnReceive; const char *RunOnFailure; /* run this command on phone communication failure */ @@ -102,7 +102,7 @@ struct _GSM_SMSDConfig { unsigned int retries; int currdeliveryreport; unsigned char SMSID[200], prevSMSID[200]; - GSM_SMSC SMSC; + GSM_SMSC SMSC, SMSCCache; const char *skipsmscnumber; #if defined(HAVE_MYSQL_MYSQL_H) || defined(HAVE_POSTGRESQL_LIBPQ_FE_H) || defined(LIBDBI_FOUND) || defined(ODBC_FOUND) diff --git a/smsd/inject.c b/smsd/inject.c index 5f65c79..e65ea66 100644 --- a/smsd/inject.c +++ b/smsd/inject.c @@ -85,6 +85,8 @@ void help(void) printf("options:\n"); print_option("h", "help", "shows this help"); print_option("v", "version", "shows version information"); + print_option("l", "use-log", "use logging configuration from config file"); + print_option("L", "no-use-log", "do not use logging configuration from config file (default)"); print_option_param("c", "config", "CONFIG_FILE", "defines path to config file"); printf("\n"); @@ -106,15 +108,17 @@ int process_commandline(int argc, char **argv, SMSD_Parameters * params) {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {"config", 1, 0, 'c'}, + {"use-log", 0, 0, 'l'}, + {"no-use-log", 0, 0, 'L'}, {0, 0, 0, 0} }; int option_index; while ((opt = - getopt_long(argc, argv, "+hvc:", long_options, + getopt_long(argc, argv, "+hvc:lL", long_options, &option_index)) != -1) { #elif defined(HAVE_GETOPT) - while ((opt = getopt(argc, argv, "+hvc:")) != -1) { + while ((opt = getopt(argc, argv, "+hvc:lL")) != -1) { #else /* Poor mans getopt replacement */ int i, optind = -1; @@ -134,6 +138,12 @@ int process_commandline(int argc, char **argv, SMSD_Parameters * params) case 'v': version(); break; + case 'l': + params->use_log = TRUE; + break; + case 'L': + params->use_log = FALSE; + break; case '?': wrong_params(); case 'h': @@ -183,6 +193,7 @@ int main(int argc, char **argv) FALSE, FALSE, FALSE, + FALSE, 0 }; @@ -214,7 +225,7 @@ int main(int argc, char **argv) config = SMSD_NewConfig(program_name); assert(config != NULL); - error = SMSD_ReadConfig(params.config_file, config, TRUE); + error = SMSD_ReadConfig(params.config_file, config, params.use_log); if (error != ERR_NONE) { printf("Failed to read config: %s\n", GSM_ErrorString(error)); SMSD_FreeConfig(config); diff --git a/smsd/main.c b/smsd/main.c index 8f95cab..f7d6da7 100644 --- a/smsd/main.c +++ b/smsd/main.c @@ -152,6 +152,8 @@ void help(void) print_option("S", "run-as-service", "runs as a SMSD Windows service"); print_option_param("n", "service-name", "NAME", "name of a Windows service (default: GammuSMSD)"); #endif + print_option("l", "use-log", "use logging configuration from config file (default)"); + print_option("L", "no-use-log", "do not use logging configuration from config file"); } NORETURN void wrong_params(void) @@ -181,13 +183,15 @@ void process_commandline(int argc, char **argv, SMSD_Parameters * params) {"service-name", 1, 0, 'n'}, {"suicide", 1, 0, 'X'}, {"max-failures", 1, 0, 'f'}, + {"use-log", 0, 0, 'l'}, + {"no-use-log", 0, 0, 'L'}, {0, 0, 0, 0} }; int option_index; - while ((opt = getopt_long(argc, argv, "hvdc:p:iusSkU:G:n:X:f:", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "hvdc:p:iusSkU:G:n:X:f:lL", long_options, &option_index)) != -1) { #elif defined(HAVE_GETOPT) - while ((opt = getopt(argc, argv, "hvdc:p:iusSkU:G:n:X:f:")) != -1) { + while ((opt = getopt(argc, argv, "hvdc:p:iusSkU:G:n:X:f:lL")) != -1) { #else /* Poor mans getopt replacement */ int i; @@ -260,6 +264,12 @@ void process_commandline(int argc, char **argv, SMSD_Parameters * params) case 'v': version(); break; + case 'l': + params->use_log = TRUE; + break; + case 'L': + params->use_log = FALSE; + break; case '?': wrong_params(); case 'h': @@ -350,6 +360,7 @@ int main(int argc, char **argv) FALSE, FALSE, FALSE, + TRUE, 0 }; @@ -420,7 +431,7 @@ read_config: config = SMSD_NewConfig(program_name); assert(config != NULL); - error = SMSD_ReadConfig(params.config_file, config, TRUE); + error = SMSD_ReadConfig(params.config_file, config, params.use_log); if (error != ERR_NONE) { printf("Failed to read config: %s\n", GSM_ErrorString(error)); SMSD_FreeConfig(config); diff --git a/smsd/monitor.c b/smsd/monitor.c index fc583bf..3b39486 100644 --- a/smsd/monitor.c +++ b/smsd/monitor.c @@ -97,8 +97,10 @@ void help(void) "defines path to config file"); print_option_param("d", "delay", "DELAY", "delay in seconds between loops"); - print_option_param("l", "loops", "NUMBER", + print_option_param("n", "loops", "NUMBER", "delay in seconds between loops"); + print_option("l", "use-log", "use logging configuration from config file"); + print_option("L", "no-use-log", "do not use logging configuration from config file (default)"); } NORETURN void wrong_params(void) @@ -117,16 +119,18 @@ int process_commandline(int argc, char **argv, SMSD_Parameters * params) {"version", 0, 0, 'v'}, {"config", 1, 0, 'c'}, {"delay", 1, 0, 'd'}, - {"loops", 1, 0, 'l'}, + {"loops", 1, 0, 'n'}, + {"use-log", 0, 0, 'l'}, + {"no-use-log", 0, 0, 'L'}, {0, 0, 0, 0} }; int option_index; while ((opt = - getopt_long(argc, argv, "+hvc:d:l:C", long_options, + getopt_long(argc, argv, "+hvc:d:n:ClL", long_options, &option_index)) != -1) { #elif defined(HAVE_GETOPT) - while ((opt = getopt(argc, argv, "+hvc:d:l:C")) != -1) { + while ((opt = getopt(argc, argv, "+hvc:d:n:ClL")) != -1) { #else /* Poor mans getopt replacement */ int i, optind = -1; @@ -152,9 +156,15 @@ int process_commandline(int argc, char **argv, SMSD_Parameters * params) case 'd': delay_seconds = atoi(optarg); break; - case 'l': + case 'n': limit_loops = atoi(optarg); break; + case 'l': + params->use_log = TRUE; + break; + case 'L': + params->use_log = FALSE; + break; case '?': wrong_params(); case 'h': @@ -199,6 +209,7 @@ int main(int argc, char **argv) FALSE, FALSE, FALSE, + FALSE, 0 }; @@ -227,7 +238,7 @@ int main(int argc, char **argv) config = SMSD_NewConfig(program_name); assert(config != NULL); - error = SMSD_ReadConfig(params.config_file, config, TRUE); + error = SMSD_ReadConfig(params.config_file, config, params.use_log); if (error != ERR_NONE) { printf("Failed to read config: %s\n", GSM_ErrorString(error)); SMSD_FreeConfig(config); diff --git a/smsd/test-smsd-files-include.sh.in b/smsd/test-smsd-files-include.sh.in index 7fa6672..0ce1e52 100644 --- a/smsd/test-smsd-files-include.sh.in +++ b/smsd/test-smsd-files-include.sh.in @@ -93,8 +93,8 @@ for sms in 10 16 26 ; do done TIMEOUT=0 -while ! @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -l 1 -d 0 | grep -q ";999999999999999;4;3;0;100;42" ; do - @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -l 1 -d 0 +while ! @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -n 1 -d 0 | grep -q ";999999999999999;4;3;0;100;42" ; do + @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -n 1 -d 0 sleep 1 TIMEOUT=$(($TIMEOUT + 1)) if [ $TIMEOUT -gt 60 ] ; then @@ -105,7 +105,7 @@ done sleep 5 -@CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -l 1 -d 0 +@CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -n 1 -d 0 if [ `wc -l < @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/received.log` -ne 3 ] ; then echo "ERROR: Wrong number of messages received!" diff --git a/smsd/test-smsd.sh.in b/smsd/test-smsd.sh.in index e37de4d..86a2674 100755 --- a/smsd/test-smsd.sh.in +++ b/smsd/test-smsd.sh.in @@ -199,8 +199,8 @@ done cp @CMAKE_CURRENT_SOURCE_DIR@/../tests/smsbackups/mms-part.smsbackup $DUMMY_PATH/sms/1/666 TIMEOUT=0 -while ! @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -l 1 -d 0 | grep -q "$TEST_MATCH" ; do - @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -l 1 -d 0 +while ! @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -n 1 -d 0 | grep -q "$TEST_MATCH" ; do + @CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -n 1 -d 0 sleep 5 TIMEOUT=$(($TIMEOUT + 1)) if [ $TIMEOUT -gt 60 ] ; then @@ -211,7 +211,7 @@ done sleep 5 -@CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -l 1 -d 0 +@CMAKE_CURRENT_BINARY_DIR@/gammu-smsd-monitor@GAMMU_TEST_SUFFIX@ -C -c "$CONFIG_PATH" -n 1 -d 0 if [ `wc -l < @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/received.log` -ne 8 ] ; then echo "ERROR: Wrong number of messages received!" |