summaryrefslogtreecommitdiff
path: root/smsd
diff options
context:
space:
mode:
Diffstat (limited to 'smsd')
-rw-r--r--smsd/CMakeLists.txt10
-rw-r--r--smsd/CMakeTests.txt115
-rw-r--r--smsd/core.c58
-rw-r--r--smsd/core.h6
-rw-r--r--smsd/inject.c5
-rw-r--r--smsd/log-event.c6
-rw-r--r--smsd/main.c25
-rw-r--r--smsd/monitor.c9
-rw-r--r--smsd/services/files.c224
-rw-r--r--smsd/services/mysql.c2
-rw-r--r--smsd/services/odbc.c23
-rw-r--r--smsd/services/sql-core.h2
-rw-r--r--smsd/services/sql.c115
-rw-r--r--smsd/test-smsd-files-include.sh.in7
-rwxr-xr-xsmsd/test-smsd.sh.in44
15 files changed, 401 insertions, 250 deletions
diff --git a/smsd/CMakeLists.txt b/smsd/CMakeLists.txt
index d3feef7..937b15e 100644
--- a/smsd/CMakeLists.txt
+++ b/smsd/CMakeLists.txt
@@ -4,6 +4,8 @@
project (gammu-smsd C)
+include(GammuTuneFlags)
+
set (LIBRARY_SRC
core.c
services/files.c
@@ -109,12 +111,11 @@ if(MSVC)
else(MSVC)
add_library (gsmsd ${LIBRARY_SRC} ${EXTRA_SOURCES})
endif(MSVC)
+add_coverage (gsmsd)
set_target_properties (gsmsd PROPERTIES
VERSION ${GAMMU_SOVERSION}.${GAMMU_VERSION}
SOVERSION ${GAMMU_SOVERSION})
-if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_MINGW AND NOT CMAKE_COMPILER_IS_CYGWIN)
- set_target_properties (gsmsd PROPERTIES COMPILE_FLAGS -fPIC)
-endif (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_MINGW AND NOT CMAKE_COMPILER_IS_CYGWIN)
+GAMMU_TUNE_SHARED(gsmsd)
if(CMAKE_COMPILER_IS_MINGW AND BUILD_SHARED_LIBS)
SET_TARGET_PROPERTIES(gsmsd PROPERTIES LINK_FLAGS
"-Wl,--output-def,${CMAKE_CURRENT_BINARY_DIR}/libgsmsd.def")
@@ -132,12 +133,14 @@ target_link_libraries (gsmsd array)
# Gammu-smsd program
add_executable (gammu-smsd ${DAEMON_SRC} ${SMSD_RESOURCES})
+add_coverage (gammu-smsd)
target_link_libraries (gammu-smsd libGammu)
target_link_libraries (gammu-smsd gsmsd)
# Gammu-smsd-inject program
add_executable (gammu-smsd-inject ${INJECT_SRC})
+add_coverage (gammu-smsd-inject)
target_link_libraries (gammu-smsd-inject libGammu)
target_link_libraries (gammu-smsd-inject gsmsd)
@@ -146,6 +149,7 @@ target_link_libraries (gammu-smsd-inject messagecmdline)
if (HAVE_SHM OR WIN32)
# Gammu-smsd-monitor program
add_executable (gammu-smsd-monitor ${MONITOR_SRC})
+ add_coverage (gammu-smsd-monitor)
target_link_libraries (gammu-smsd-monitor libGammu)
target_link_libraries (gammu-smsd-monitor gsmsd)
diff --git a/smsd/CMakeTests.txt b/smsd/CMakeTests.txt
index ccaac8f..7ade7ed 100644
--- a/smsd/CMakeTests.txt
+++ b/smsd/CMakeTests.txt
@@ -33,49 +33,74 @@ if (WITH_BACKUP)
set_tests_properties("smsd-inject-long-${_driver}" PROPERTIES
FAIL_REGULAR_EXPRESSION "DBI error;SQL failed;ODBC diagnostics"
)
- if (HAVE_ALARM)
- add_test(NAME "smsd-daemon-${_driver}" COMMAND gammu-smsd -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" -X 10 -p ${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/smsd.pid)
- set_tests_properties("smsd-daemon-${_driver}" PROPERTIES
- FAIL_REGULAR_EXPRESSION "DBI error;SQL failed;ODBC diagnostics"
- )
- endif (HAVE_ALARM)
+ if ("${_driver}" STREQUAL "null")
+ if (WIN32 OR HAVE_ALARM)
+ add_test(NAME "smsd-daemon-${_driver}" COMMAND gammu-smsd -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" -X 3)
+ set_tests_properties("smsd-daemon-${_driver}" PROPERTIES
+ FAIL_REGULAR_EXPRESSION "DBI error;SQL failed;ODBC diagnostics"
+ )
+ endif (WIN32 OR HAVE_ALARM)
+ if (HAVE_ALARM AND HAVE_KILL)
+ add_test(NAME "smsd-daemon-${_driver}-pid" COMMAND gammu-smsd -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" -X 3 -p ${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/smsd.pid)
+ endif()
+ if (HAVE_ALARM AND HAVE_SETGID AND HAVE_GETPWNAM AND HAVE_GETGRNAM AND HAVE_SETUID AND HAVE_INITGROUPS)
+ exec_program(id ARGS -g OUTPUT_VARIABLE MY_GROUP)
+ add_test(NAME "smsd-daemon-${_driver}-gid" COMMAND gammu-smsd -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" -X 3 -G ${MY_GROUP})
+ exec_program(id ARGS -gn OUTPUT_VARIABLE MY_GROUP_NAME)
+ add_test(NAME "smsd-daemon-${_driver}-gid-name" COMMAND gammu-smsd -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-${_driver}/.smsdrc" -X 3 -G ${MY_GROUP_NAME})
+ endif()
+ endif()
endmacro(smsd_testsuite _driver)
if (LIBDBI_FOUND AND SH_BIN AND SQLITE_BIN AND SED_BIN)
smsd_testsuite("dbi-sqlite3")
endif (LIBDBI_FOUND AND SH_BIN AND SQLITE_BIN AND SED_BIN)
- smsd_testsuite("files-unicode")
- smsd_testsuite("files-standard")
- smsd_testsuite("files-detail")
- smsd_testsuite("null")
+ if (SH_BIN)
+ smsd_testsuite("files-unicode")
+ smsd_testsuite("files-standard")
+ smsd_testsuite("files-detail")
+ smsd_testsuite("null")
+ endif (SH_BIN)
if (MYSQL_TESTING)
- if (MYSQL_FOUND)
- smsd_testsuite("mysql")
- endif (MYSQL_FOUND)
- if (LIBDBI_FOUND)
- smsd_testsuite("dbi-mysql")
- endif (LIBDBI_FOUND)
- if (ODBC_TESTING)
- if (ODBC_FOUND)
- smsd_testsuite("odbc")
- endif (ODBC_FOUND)
- endif (ODBC_TESTING)
+ if (MYSQL_BIN)
+ if (MYSQL_FOUND)
+ smsd_testsuite("mysql")
+ endif (MYSQL_FOUND)
+ if (LIBDBI_FOUND)
+ smsd_testsuite("dbi-mysql")
+ endif (LIBDBI_FOUND)
+ if (ODBC_TESTING)
+ if (ODBC_FOUND)
+ smsd_testsuite("odbc")
+ endif (ODBC_FOUND)
+ endif (ODBC_TESTING)
+ else()
+ message("MySQL tests disabled, mysql program not found")
+ endif()
endif (MYSQL_TESTING)
if (PSQL_TESTING)
- smsd_testsuite("pgsql")
- if (LIBDBI_FOUND)
- smsd_testsuite("dbi-pgsql")
- endif (LIBDBI_FOUND)
+ if (PSQL_BIN)
+ if (POSTGRES_FOUND)
+ smsd_testsuite("pgsql")
+ endif (POSTGRES_FOUND)
+ if (LIBDBI_FOUND)
+ smsd_testsuite("dbi-pgsql")
+ endif (LIBDBI_FOUND)
+ else()
+ message("PostgreSQL tests disabled, psql program not found")
+ endif()
endif (PSQL_TESTING)
- add_test(NAME "smsd-files-include-unicode" COMMAND "${SH_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/test-smsd-files-include.sh" unicode "$<TARGET_FILE:gammu-smsd>" "$<TARGET_FILE:gammu-smsd-inject>" "$<TARGET_FILE:gammu-smsd-monitor>")
- set_tests_properties("smsd-files-include-unicode" PROPERTIES
- PASS_REGULAR_EXPRESSION ".999999999999999.4.3.0.100.42"
- FAIL_REGULAR_EXPRESSION "ERROR: ;Wrong;Process failed with exit status"
- )
+ if (SH_BIN)
+ add_test(NAME "smsd-files-include-unicode" COMMAND "${SH_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/test-smsd-files-include.sh" unicode "$<TARGET_FILE:gammu-smsd>" "$<TARGET_FILE:gammu-smsd-inject>" "$<TARGET_FILE:gammu-smsd-monitor>")
+ set_tests_properties("smsd-files-include-unicode" PROPERTIES
+ PASS_REGULAR_EXPRESSION ".999999999999999.994299429942994.4.3.0.100.42"
+ FAIL_REGULAR_EXPRESSION "ERROR: ;Wrong;Process failed with exit status"
+ )
+ endif (SH_BIN)
foreach (PROGRAM gammu-smsd gammu-smsd-monitor gammu-smsd-inject)
add_test(NAME ${PROGRAM}-help COMMAND ${PROGRAM} -h)
@@ -83,9 +108,37 @@ if (WITH_BACKUP)
set_tests_properties(${PROGRAM}-version PROPERTIES
PASS_REGULAR_EXPRESSION "${GAMMU_VERSION}"
)
- add_test(NAME ${PROGRAM}-fail COMMAND ${PROGRAM} --nonsense)
+ add_test(NAME ${PROGRAM}-fail-long COMMAND ${PROGRAM} --nonsense)
+ set_tests_properties(
+ ${PROGRAM}-fail-long
+ PROPERTIES WILL_FAIL TRUE)
+ add_test(NAME ${PROGRAM}-fail COMMAND ${PROGRAM} -W)
set_tests_properties(
${PROGRAM}-fail
PROPERTIES WILL_FAIL TRUE)
endforeach (PROGRAM gammu-smsd gammu-smsd-monitor gammu-smsd-inject)
+
+ if (WIN32)
+ # Uninstall without install
+ add_test(NAME gammu-smsd-uninstall-eventlog-fail COMMAND gammu-smsd -E)
+ set_tests_properties(gammu-smsd-uninstall-eventlog-fail PROPERTIES WILL_FAIL TRUE)
+
+ # Install + Uninstall
+ add_test(NAME gammu-smsd-install-eventlog COMMAND gammu-smsd -e)
+ add_test(NAME gammu-smsd-uninstall-eventlog COMMAND gammu-smsd -E)
+ set_tests_properties(gammu-smsd-uninstall-eventlog PROPERTIES DEPENDS gammu-smsd-install-eventlog)
+
+ # Uninstall without install
+ add_test(NAME gammu-smsd-uninstall-service-fail COMMAND gammu-smsd -u)
+ set_tests_properties(gammu-smsd-uninstall-service-fail PROPERTIES WILL_FAIL TRUE)
+
+ # Install without config
+ add_test(NAME gammu-smsd-install-service-fail COMMAND gammu-smsd -i)
+ set_tests_properties(gammu-smsd-install-service-fail PROPERTIES WILL_FAIL TRUE)
+
+ # Install + Uninstall
+ add_test(NAME gammu-smsd-install-service COMMAND gammu-smsd -i -c "${CMAKE_CURRENT_BINARY_DIR}/smsd-test-null/.smsdrc")
+ add_test(NAME gammu-smsd-uninstall-service COMMAND gammu-smsd -u)
+ set_tests_properties(gammu-smsd-uninstall-service PROPERTIES DEPENDS gammu-smsd-install-service)
+ endif (WIN32)
endif (WITH_BACKUP)
diff --git a/smsd/core.c b/smsd/core.c
index 3475311..4d3641b 100644
--- a/smsd/core.c
+++ b/smsd/core.c
@@ -5,6 +5,7 @@
#include <signal.h>
#include <time.h>
#include <assert.h>
+#include <math.h>
#ifndef WIN32
#include <sys/types.h>
#include <sys/wait.h>
@@ -350,7 +351,7 @@ void SMSD_Log_Function(const char *text, void *data)
newsize = pos + strlen(text) + 1;
/* Reallocate buffer if needed */
- if (newsize > Config->gammu_log_buffer_size) {
+ if (newsize > Config->gammu_log_buffer_size || Config->gammu_log_buffer == NULL) {
newsize += 50;
Config->gammu_log_buffer = realloc(Config->gammu_log_buffer, newsize);
if (Config->gammu_log_buffer == NULL) {
@@ -804,6 +805,7 @@ GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig *Config, gboolean
Config->checksecurity = INI_GetBool(Config->smsdcfgfile, "smsd", "checksecurity", TRUE);
Config->hangupcalls = INI_GetBool(Config->smsdcfgfile, "smsd", "hangupcalls", FALSE);
Config->checksignal = INI_GetBool(Config->smsdcfgfile, "smsd", "checksignal", TRUE);
+ Config->checknetwork = INI_GetBool(Config->smsdcfgfile, "smsd", "checknetwork", TRUE);
Config->checkbattery = INI_GetBool(Config->smsdcfgfile, "smsd", "checkbattery", TRUE);
Config->enable_send = INI_GetBool(Config->smsdcfgfile, "smsd", "send", TRUE);
Config->enable_receive = INI_GetBool(Config->smsdcfgfile, "smsd", "receive", TRUE);
@@ -819,8 +821,8 @@ GSM_Error SMSD_ReadConfig(const char *filename, GSM_SMSDConfig *Config, gboolean
SMSD_Log(DEBUG_NOTICE, Config, "CommTimeout=%i, SendTimeout=%i, ReceiveFrequency=%i, ResetFrequency=%i, HardResetFrequency=%i",
Config->commtimeout, Config->sendtimeout, Config->receivefrequency, Config->resetfrequency, Config->hardresetfrequency);
- SMSD_Log(DEBUG_NOTICE, Config, "checks: CheckSecurity=%d, CheckBattery=%d, CheckSignal=%d",
- Config->checksecurity, Config->checkbattery, Config->checksignal);
+ SMSD_Log(DEBUG_NOTICE, Config, "checks: CheckSecurity=%d, CheckBattery=%d, CheckSignal=%d, CheckNetwork=%d",
+ Config->checksecurity, Config->checkbattery, Config->checksignal, Config->checknetwork);
SMSD_Log(DEBUG_NOTICE, Config, "mode: Send=%d, Receive=%d",
Config->enable_send, Config->enable_receive);
@@ -996,7 +998,7 @@ gboolean SMSD_CheckSecurity(GSM_SMSDConfig *Config)
char *SMSD_RunOnCommand(const char *locations, const char *command)
{
char *result;
- int len;
+ size_t len;
assert(command != NULL);
@@ -1526,13 +1528,10 @@ gboolean SMSD_ReadDeleteSMS(GSM_SMSDConfig *Config)
for (j = 0; j < SortedSMS[i]->Number; j++) {
SortedSMS[i]->SMS[j].Folder = 0;
error = GSM_DeleteSMS(Config->gsm, &SortedSMS[i]->SMS[j]);
- switch (error) {
- case ERR_NONE:
- case ERR_EMPTY:
- break;
- default:
- SMSD_LogError(DEBUG_INFO, Config, "Error deleting SMS", error);
- return FALSE;
+ // Empty error can happen if deleting message several times
+ if (error != ERR_NONE && error != ERR_EMPTY) {
+ SMSD_LogError(DEBUG_INFO, Config, "Error deleting SMS", error);
+ return FALSE;
}
}
@@ -1603,6 +1602,18 @@ void SMSD_PhoneStatus(GSM_SMSDConfig *Config) {
if (error != ERR_NONE) {
memset(&(Config->Status->Network), 0, sizeof(Config->Status->Network));
}
+ if (Config->checknetwork) {
+ error = GSM_GetNetworkInfo(Config->gsm, &Config->Status->NetInfo);
+ } else {
+ error = ERR_UNKNOWN;
+ }
+ if (error != ERR_NONE) {
+ memset(&(Config->Status->NetInfo), 0, sizeof(Config->Status->NetInfo));
+ } else if (error == ERR_NONE) {
+ if (Config->Status->NetInfo.State == GSM_NoNetwork) {
+ GSM_SetPower(Config->gsm, TRUE);
+ }
+ }
}
/**
@@ -1656,31 +1667,35 @@ GSM_Error SMSD_SendSMS(GSM_SMSDConfig *Config)
}
for (i = 0; i < sms.Number; i++) {
+ /* No SMSC set in message */
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;
+ sms.SMS[i].SMSC = Config->SMSC;
if (Config->relativevalidity != -1) {
sms.SMS[i].SMSC.Validity.Format = SMS_Validity_RelativeFormat;
sms.SMS[i].SMSC.Validity.Relative = Config->relativevalidity;
}
}
+ /* Still nothing set after using configured one */
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;
}
+ /* Should use SMSC from phone */
if (sms.SMS[i].SMSC.Location != 0) {
+ /* Do we have cached entry? */
if (Config->SMSCCache.Location != sms.SMS[i].SMSC.Location) {
Config->SMSCCache.Location = sms.SMS[i].SMSC.Location;
- error = GSM_GetSMSC(Config->gsm,&Config->SMSCCache);
+ 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->SMSCCache,sizeof(GSM_SMSC));
+ sms.SMS[i].SMSC = Config->SMSCCache;
+ /* Reset location to avoid reading from phone */
sms.SMS[i].SMSC.Location = 0;
if (Config->relativevalidity != -1) {
sms.SMS[i].SMSC.Validity.Format = SMS_Validity_RelativeFormat;
@@ -1733,6 +1748,7 @@ GSM_Error SMSD_SendSMS(GSM_SMSDConfig *Config)
Config->Status->Sent++;
error = Config->Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_OK, Config->TPMR);
if (error != ERR_NONE) {
+ SMSD_LogError(DEBUG_INFO, Config, "Error setting sent status", error);
goto failure_sent;
}
}
@@ -1756,7 +1772,7 @@ failure_unsent:
Config->Service->UpdateRetries(Config, Config->SMSID);
- sleep(60);
+ sleep(60);
return ERR_UNKNOWN;
failure_sent:
@@ -1844,10 +1860,12 @@ GSM_Error SMSD_InitSharedMemory(GSM_SMSDConfig *Config, gboolean writable)
GetCompiler());
memset(&Config->Status->Charge, 0, sizeof(GSM_BatteryCharge));
memset(&Config->Status->Network, 0, sizeof(GSM_SignalQuality));
+ memset(&Config->Status->NetInfo, 0, sizeof(GSM_NetworkInfo));
Config->Status->Received = 0;
Config->Status->Failed = 0;
Config->Status->Sent = 0;
Config->Status->IMEI[0] = 0;
+ Config->Status->IMSI[0] = 0;
}
return ERR_NONE;
}
@@ -1911,6 +1929,7 @@ GSM_Error SMSD_MainLoop(GSM_SMSDConfig *Config, gboolean exit_on_failure, int ma
{
GSM_Error error;
int errors = -1, initerrors=0;
+ unsigned int lastsleep;
time_t lastreceive = 0, lastreset = time(NULL), lasthardreset = time(NULL), lastnothingsent = 0, laststatus = 0;
time_t lastloop = 0, current_time;
int i;
@@ -1989,7 +2008,7 @@ GSM_Error SMSD_MainLoop(GSM_SMSDConfig *Config, gboolean exit_on_failure, int ma
GSM_SetSendSMSStatusCallback(Config->gsm, SMSD_SendSMSStatusCallback, Config);
/* On first start we need to initialize some variables */
if (first_start) {
- if (GSM_GetIMEI(Config->gsm, Config->Status->IMEI) != ERR_NONE) {
+ if (GSM_GetIMEI(Config->gsm, Config->Status->IMEI) != ERR_NONE || GSM_GetSIMIMSI(Config->gsm, Config->Status->IMSI) != ERR_NONE) {
errors++;
} else {
errors = 0;
@@ -2094,10 +2113,11 @@ GSM_Error SMSD_MainLoop(GSM_SMSDConfig *Config, gboolean exit_on_failure, int ma
/* Sleep some time before another loop */
current_time = time(NULL);
+ lastsleep = round(difftime(current_time, lastloop));
if (Config->loopsleep == 1) {
sleep(1);
- } else if (difftime(current_time, lastloop) < Config->loopsleep) {
- sleep(Config->loopsleep - difftime(current_time, lastloop));
+ } else if (lastsleep < Config->loopsleep) {
+ sleep(Config->loopsleep - lastsleep);
}
}
Config->Service->Free(Config);
diff --git a/smsd/core.h b/smsd/core.h
index f969d5a..31a0a98 100644
--- a/smsd/core.h
+++ b/smsd/core.h
@@ -16,8 +16,8 @@
#endif
#define SMSD_SHM_KEY (0xface)
-#define SMSD_SHM_VERSION (1)
-#define SMSD_DB_VERSION (15)
+#define SMSD_SHM_VERSION (2)
+#define SMSD_DB_VERSION (16)
#include "log.h"
@@ -91,6 +91,7 @@ struct _GSM_SMSDConfig {
gboolean hangupcalls;
gboolean checkbattery;
gboolean checksignal;
+ gboolean checknetwork;
gboolean enable_send;
gboolean enable_receive;
unsigned int maxretries;
@@ -151,7 +152,6 @@ struct _GSM_SMSDConfig {
/* configurable SQL queries */
char * SMSDSQL_queries[SQL_QUERY_LAST_NO];
- const char *table_daemons;
const char *table_gammu;
const char *table_inbox;
const char *table_sentitems;
diff --git a/smsd/inject.c b/smsd/inject.c
index bd468b4..76fbb70 100644
--- a/smsd/inject.c
+++ b/smsd/inject.c
@@ -55,13 +55,13 @@ NORETURN void version(void)
printf(" - %s\n", "ODBC");
#endif
printf("\n");
- printf("Copyright (C) 2003 - 2015 Michal Cihar <michal@cihar.com> and other authors.\n");
+ printf("Copyright (C) 2003 - 2016 Michal Cihar <michal@cihar.com> and other authors.\n");
printf("\n");
printf("License GPLv2: GNU GPL version 2 <https://spdx.org/licenses/GPL-2.0>.\n");
printf("This is free software: you are free to change and redistribute it.\n");
printf("There is NO WARRANTY, to the extent permitted by law.\n");
printf("\n");
- printf("Check <http://wammu.eu/gammu/> for updates.\n");
+ printf("Check <https://wammu.eu/gammu/> for updates.\n");
printf("\n");
exit(0);
}
@@ -149,6 +149,7 @@ int process_commandline(int argc, char **argv, SMSD_Parameters * params)
help();
exit(0);
default:
+ fprintf(stderr, "Parameter -%c not known!\n", opt);
wrong_params();
break;
}
diff --git a/smsd/log-event.c b/smsd/log-event.c
index 319728f..1a482a4 100644
--- a/smsd/log-event.c
+++ b/smsd/log-event.c
@@ -96,7 +96,7 @@ gboolean eventlog_register(void)
0,
REG_SZ,
(BYTE *)program_name,
- strlen(program_name) + 1);
+ (DWORD)strlen(program_name) + 1);
if (ret != ERROR_SUCCESS) {
fprintf(stderr, "Failed to write EventMessageFile to registry!\n");
@@ -109,7 +109,7 @@ gboolean eventlog_register(void)
0,
REG_SZ,
(BYTE *)program_name,
- strlen(program_name) + 1);
+ (DWORD)strlen(program_name) + 1);
if (ret != ERROR_SUCCESS) {
fprintf(stderr, "Failed to write ParameterMessageFile to registry!\n");
@@ -149,8 +149,8 @@ void eventlog_log(void *handle, int level, const char *message)
{
LPCTSTR lpstrings[1];
WORD evtype = EVENTLOG_ERROR_TYPE;
+ WORD eventcat = 0;
DWORD eventid = 0;
- DWORD eventcat = 0;
switch (level) {
case DEBUG_ERROR:
diff --git a/smsd/main.c b/smsd/main.c
index 76d48f7..ae21cb3 100644
--- a/smsd/main.c
+++ b/smsd/main.c
@@ -65,6 +65,13 @@ void smsd_resume(int signum)
standby = FALSE;
}
+#ifdef WIN32
+VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
+{
+ SMSD_Shutdown(config);
+}
+#endif
+
NORETURN void version(void)
{
printf("Gammu-smsd version %s\n", GAMMU_VERSION);
@@ -79,7 +86,7 @@ NORETURN void version(void)
#ifdef HAVE_PIDFILE
printf(" - %s\n", "PID");
#endif
-#ifdef HAVE_ALARM
+#if defined(HAVE_ALARM) || defined(WIN32)
printf(" - %s\n", "ALARM");
#endif
#ifdef HAVE_UID
@@ -115,13 +122,13 @@ NORETURN void version(void)
printf(" - %s\n", "ODBC");
#endif
printf("\n");
- printf("Copyright (C) 2003 - 2015 Michal Cihar <michal@cihar.com> and other authors.\n");
+ printf("Copyright (C) 2003 - 2016 Michal Cihar <michal@cihar.com> and other authors.\n");
printf("\n");
printf("License GPLv2: GNU GPL version 2 <https://spdx.org/licenses/GPL-2.0>.\n");
printf("This is free software: you are free to change and redistribute it.\n");
printf("There is NO WARRANTY, to the extent permitted by law.\n");
printf("\n");
- printf("Check <http://wammu.eu/gammu/> for updates.\n");
+ printf("Check <https://wammu.eu/gammu/> for updates.\n");
printf("\n");
exit(0);
}
@@ -156,7 +163,7 @@ void help(void)
print_option_param("G", "group", "GROUP", "run daemon as a group");
#endif
print_option_param("f", "max-failures", "NUM", "number of failures before terminating");
-#ifdef HAVE_ALARM
+#if defined(HAVE_ALARM) || defined(WIN32)
print_option_param("X", "suicide", "SECONDS", "kills itself after number of seconds");
#endif
#ifdef HAVE_WINDOWS_SERVICE
@@ -184,6 +191,9 @@ NORETURN void wrong_params(void)
void process_commandline(int argc, char **argv, SMSD_Parameters * params)
{
int opt;
+#ifdef WIN32
+ HANDLE hTimer = NULL;
+#endif
#ifdef HAVE_GETOPT_LONG
struct option long_options[] = {
@@ -251,9 +261,13 @@ void process_commandline(int argc, char **argv, SMSD_Parameters * params)
case 'f':
params->max_failures = atoi(optarg);
break;
-#ifdef HAVE_ALARM
+#if defined(HAVE_ALARM) || defined(WIN32)
case 'X':
+#ifdef HAVE_ALARM
alarm(atoi(optarg));
+#elif defined(WIN32)
+ CreateTimerQueueTimer(&hTimer, NULL, (WAITORTIMERCALLBACK)TimerRoutine, NULL , atoi(optarg) * 1000, 0, 0);
+#endif
break;
#endif
#ifdef HAVE_DAEMON
@@ -305,6 +319,7 @@ void process_commandline(int argc, char **argv, SMSD_Parameters * params)
help();
exit(0);
default:
+ fprintf(stderr, "Parameter -%c not known!\n", opt);
wrong_params();
break;
}
diff --git a/smsd/monitor.c b/smsd/monitor.c
index 522b957..2efadf6 100644
--- a/smsd/monitor.c
+++ b/smsd/monitor.c
@@ -63,13 +63,13 @@ NORETURN void version(void)
printf(" - %s\n", "ODBC");
#endif
printf("\n");
- printf("Copyright (C) 2003 - 2015 Michal Cihar <michal@cihar.com> and other authors.\n");
+ printf("Copyright (C) 2003 - 2016 Michal Cihar <michal@cihar.com> and other authors.\n");
printf("\n");
printf("License GPLv2: GNU GPL version 2 <https://spdx.org/licenses/GPL-2.0>.\n");
printf("This is free software: you are free to change and redistribute it.\n");
printf("There is NO WARRANTY, to the extent permitted by law.\n");
printf("\n");
- printf("Check <http://wammu.eu/gammu/> for updates.\n");
+ printf("Check <https://wammu.eu/gammu/> for updates.\n");
printf("\n");
exit(0);
}
@@ -171,6 +171,7 @@ void process_commandline(int argc, char **argv, SMSD_Parameters * params)
help();
exit(0);
default:
+ fprintf(stderr, "Parameter -%c not known!\n", opt);
wrong_params();
break;
}
@@ -255,10 +256,11 @@ int main(int argc, char **argv)
return 3;
}
if (compact) {
- printf("%s;%s;%s;%d;%d;%d;%d;%d\n",
+ printf("%s;%s;%s;%s;%d;%d;%d;%d;%d\n",
status.Client,
status.PhoneID,
status.IMEI,
+ status.IMSI,
status.Sent,
status.Received,
status.Failed,
@@ -268,6 +270,7 @@ int main(int argc, char **argv)
printf("Client: %s\n", status.Client);
printf("PhoneID: %s\n", status.PhoneID);
printf("IMEI: %s\n", status.IMEI);
+ printf("IMSI: %s\n", status.IMSI);
printf("Sent: %d\n", status.Sent);
printf("Received: %d\n", status.Received);
printf("Failed: %d\n", status.Failed);
diff --git a/smsd/services/files.c b/smsd/services/files.c
index 7071983..6001755 100644
--- a/smsd/services/files.c
+++ b/smsd/services/files.c
@@ -10,6 +10,8 @@
#include <stdlib.h>
#include <assert.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
#ifdef WIN32
#include <io.h>
@@ -23,6 +25,14 @@
#include "../../helper/string.h"
+#ifndef PATH_MAX
+#ifdef MAX_PATH
+#define PATH_MAX (MAX_PATH)
+#else
+#define PATH_MAX (4069)
+#endif
+#endif
+
/**
* Helper define to check error code from fwrite.
*/
@@ -34,12 +44,12 @@ static GSM_Error SMSDFiles_SaveInboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConfi
{
GSM_Error error = ERR_NONE;
int i, j;
- unsigned char FileName[100], FullName[400], ext[4], buffer[64], buffer2[400];
+ unsigned char FileName[100], FullName[PATH_MAX], ext[4], buffer[64], buffer2[400];
gboolean done;
FILE *file;
size_t locations_size = 0, locations_pos = 0;
#ifdef GSM_ENABLE_BACKUP
- GSM_SMS_Backup backup;
+ GSM_SMS_Backup *backup;
#endif
*Locations = NULL;
@@ -98,12 +108,18 @@ static GSM_Error SMSDFiles_SaveInboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConfi
SMSD_Log(DEBUG_ERROR, Config, "Saving in detail format not compiled in!");
#else
+ backup = malloc(sizeof(GSM_SMS_Backup));
+ if (backup == NULL) {
+ return ERR_MOREMEMORY;
+ }
+
for (j = 0; j < sms->Number; j++) {
- backup.SMS[j] = &sms->SMS[j];
+ backup->SMS[j] = &sms->SMS[j];
}
- backup.SMS[sms->Number] = NULL;
- error = GSM_AddSMSBackupFile(FullName, &backup);
+ backup->SMS[sms->Number] = NULL;
+ error = GSM_AddSMSBackupFile(FullName, backup);
done = TRUE;
+ free(backup);
#endif
} else {
file = fopen(FullName, "wb");
@@ -164,15 +180,16 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConf
{
GSM_MultiPartSMSInfo SMSInfo;
GSM_WAPBookmark Bookmark;
- char FileName[100], FullName[400];
+ char FileName[100], FullName[PATH_MAX];
unsigned char Buffer[(GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS + 1) * 2];
unsigned char Buffer2[(GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS + 1) * 2];
FILE *File;
- int i, len, phlen;
+ int i;
+ size_t len, phlen;
char *pos1, *pos2, *options = NULL;
gboolean backup = FALSE;
#ifdef GSM_ENABLE_BACKUP
- GSM_SMS_Backup smsbackup;
+ GSM_SMS_Backup *smsbackup;
GSM_Error error;
#endif
#ifdef WIN32
@@ -252,21 +269,28 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConf
if (backup) {
#ifdef GSM_ENABLE_BACKUP
+ smsbackup = malloc(sizeof(GSM_SMS_Backup));
+ if (smsbackup == NULL) {
+ return ERR_MOREMEMORY;
+ }
+
/* Remember ID */
strcpy(ID, FileName);
/* Load backup */
- GSM_ClearSMSBackup(&smsbackup);
- error = GSM_ReadSMSBackupFile(FullName, &smsbackup);
+ GSM_ClearSMSBackup(smsbackup);
+ error = GSM_ReadSMSBackupFile(FullName, smsbackup);
if (error != ERR_NONE) {
+ free(smsbackup);
return error;
}
/* Copy it to our message */
sms->Number = 0;
- for (i = 0; smsbackup.SMS[i] != NULL; i++) {
- sms->SMS[sms->Number++] = *smsbackup.SMS[i];
+ for (i = 0; smsbackup->SMS[i] != NULL; i++) {
+ sms->SMS[sms->Number++] = *(smsbackup->SMS[i]);
}
/* Free memory */
- GSM_FreeSMSBackup(&smsbackup);
+ GSM_FreeSMSBackup(smsbackup);
+ free(smsbackup);
/* Set delivery report flag */
if (sms->SMS[0].PDU == SMS_Status_Report) {
@@ -274,7 +298,6 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConf
} else {
Config->currdeliveryreport = -1;
}
-
#else
SMSD_Log(DEBUG_ERROR, Config, "SMS backup loading disabled at compile time!");
return ERR_DISABLED;
@@ -400,8 +423,8 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConf
return ERR_UNKNOWN;
}
- for (len = 0; len < sms->Number; len++) {
- EncodeUnicode(sms->SMS[len].Number, pos1, phlen);
+ for (i = 0; i < sms->Number; i++) {
+ EncodeUnicode(sms->SMS[i].Number, pos1, phlen);
}
}
@@ -434,66 +457,93 @@ static GSM_Error SMSDFiles_MoveSMS(GSM_MultiSMSMessage * sms UNUSED, GSM_SMSDCon
{
FILE *oFile, *iFile;
size_t ilen = 0, olen = 0;
- char Buffer[(GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS + 1) * 2], ifilename[400], ofilename[400];
+ char Buffer[(GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS + 1) * 2], ifilename[PATH_MAX], ofilename[PATH_MAX];
const char *sourcepath, *destpath;
+ GSM_Error error;
sourcepath = Config->outboxpath;
+
+ // Determine target based on status
if (sent) {
destpath = Config->sentsmspath;
} else {
destpath = Config->errorsmspath;
}
+ // Calculate source path
strcpy(ifilename, sourcepath);
strcat(ifilename, ID);
+ // Calculate destination path
strcpy(ofilename, destpath);
strcat(ofilename, ID);
+ // Do move only if paths are not same
if (strcmp(ifilename, ofilename) != 0) {
+ // First try rename
+ if (rename(ifilename, ofilename) == 0) {
+ SMSD_Log(DEBUG_INFO, Config, "Renamed %s to %s", ifilename, ofilename);
+ return ERR_NONE;
+ }
+
+ // Move across devices
+ if (errno != EXDEV) {
+ SMSD_LogErrno(Config, "Can not move file");
+ SMSD_Log(DEBUG_INFO, Config, "Could move %s to %s", ifilename, ofilename);
+ return ERR_UNKNOWN;
+ }
+
+ // Read source file
iFile = fopen(ifilename, "r");
if (iFile == NULL) {
+ SMSD_LogErrno(Config, "Can not open file");
return ERR_CANTOPENFILE;
}
ilen = fread(Buffer, 1, sizeof(Buffer), iFile);
fclose(iFile);
+
+ // Write target file
oFile = fopen(ofilename, "w");
if (oFile == NULL) {
+ SMSD_LogErrno(Config, "Can not open file");
return ERR_CANTOPENFILE;
}
olen = fwrite(Buffer, 1, ilen, oFile);
fclose(oFile);
}
- if (ilen == olen) {
- if ((strcmp(ifilename, "/") == 0) || (remove(ifilename) != 0)) {
- SMSD_LogErrno(Config, "Can not delete file");
- SMSD_Log(DEBUG_INFO, Config, "Could not delete %s", ifilename);
- return ERR_UNKNOWN;
- }
- return ERR_NONE;
+
+ // Did we write all data?
+ error = ERR_NONE;
+ if (ilen != olen) {
+ SMSD_Log(DEBUG_ERROR, Config, "Failed to copy %s to %s", ifilename, ofilename);
+ error = ERR_UNKNOWN;
} else {
- SMSD_Log(DEBUG_INFO, Config, "Error copying SMS %s -> %s", ifilename, ofilename);
- if (alwaysDelete) {
- if ((strcmp(ifilename, "/") == 0) || (remove(ifilename) != 0)) {
- SMSD_LogErrno(Config, "Can not delete file");
- SMSD_Log(DEBUG_INFO, Config, "Could not delete %s", ifilename);
- }
+ SMSD_Log(DEBUG_INFO, Config, "Copied %s to %s", ifilename, ofilename);
+ }
+
+ // Remove source file
+ if (error == ERR_NONE || alwaysDelete) {
+ if (unlink(ifilename) != 0) {
+ SMSD_LogErrno(Config, "Can not remove file");
+ return ERR_UNKNOWN;
}
- return ERR_UNKNOWN;
}
+
+ return error;
}
/* Adds SMS to Outbox */
static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConfig * Config, char *NewID)
{
int i, j;
- unsigned char FileName[100], FullName[400], ext[17], buffer[64], buffer2[400];
- FILE *file;
+ int fd;
+ unsigned char FileName[100], FullName[PATH_MAX], ext[17], buffer[64], buffer2[400];
+ FILE *file = NULL;
time_t rawtime;
struct tm *timeinfo;
#ifdef GSM_ENABLE_BACKUP
GSM_Error error;
- GSM_SMS_Backup backup;
+ GSM_SMS_Backup *backup;
#endif
j = 0;
@@ -508,22 +558,20 @@ static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDCo
}
DecodeUnicode(sms->SMS[i].Number, buffer2);
- file = NULL;
- do {
+ for (j = 0; j < 100; j++) {
sprintf(FileName,
"OUTC%04d%02d%02d_%02d%02d%02d_00_%s_sms%d.%s",
1900 + timeinfo->tm_year, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, buffer2, j, ext);
strcpy(FullName, Config->outboxpath);
strcat(FullName, FileName);
- if (file) {
- fclose(file);
+ fd = open(FileName, O_CREAT | O_EXCL, 0644);
+ if (fd >= 0) {
+ close(fd);
+ break;
}
- file = fopen(FullName, "r");
- } while (file != NULL && (++j < 100));
+ }
- if (file) {
- fclose(file);
- file = NULL;
+ if (j >= 100) {
if (i == 0) {
SMSD_Log(DEBUG_ERROR, Config, "Cannot save %s. No available file names", FileName);
return ERR_CANTOPENFILE;
@@ -535,11 +583,18 @@ static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDCo
SMSD_Log(DEBUG_ERROR, Config, "Saving in detail format not compiled in!");
#else
+ backup = malloc(sizeof(GSM_SMS_Backup));
+ if (backup == NULL) {
+ return ERR_MOREMEMORY;
+ }
+
for (j = 0; j < sms->Number; j++) {
- backup.SMS[j] = &sms->SMS[j];
+ backup->SMS[j] = &sms->SMS[j];
}
- backup.SMS[sms->Number] = NULL;
- error = GSM_AddSMSBackupFile(FullName, &backup);
+ backup->SMS[sms->Number] = NULL;
+ error = GSM_AddSMSBackupFile(FullName, backup);
+
+ free(backup);
if (error != ERR_NONE) {
return error;
@@ -593,10 +648,10 @@ fail:
static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage * sms UNUSED, GSM_SMSDConfig * Config, char *ID UNUSED, int Part, GSM_SMSDSendingError err, int TPMR)
{
FILE *file;
- ssize_t flen = 0, filesize;
- unsigned char FullPath[400];
- char *Buffer = NULL;
- char *lineStart, *lineEnd;
+ GSM_File GSMFile;
+ GSM_Error error;
+ unsigned char FullPath[PATH_MAX];
+ unsigned char *lineStart, *lineEnd;
/* MessageReference TPMR maximum is "255" */
char MessageReferenceBuffer[sizeof("MessageReference = \n") + 4];
@@ -608,60 +663,48 @@ static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage * sms UNUSED, GSM_
strcpy(FullPath, Config->outboxpath);
strcat(FullPath, Config->SMSID);
- file = fopen(FullPath, "r");
+ // Read file content
+ GSMFile.Buffer = NULL;
+ GSMFile.Used = 0;
+ error = GSM_ReadFile(FullPath, &GSMFile);
- if (file == NULL) {
- return ERR_CANTOPENFILE;
+ if (error != ERR_NONE) {
+ SMSD_Log(DEBUG_ERROR, Config, "AddSentSMSInfo: Failed to read file!");
+ free(GSMFile.Buffer);
+ return error;
}
- fseek(file, 0, SEEK_END);
- filesize = ftell(file);
- if (filesize < 0) {
- fclose(file);
- return ERR_CANTOPENFILE;
- }
- fseek(file, 0, SEEK_SET);
+ // Allocate additional space for trailing zero
+ GSMFile.Buffer = realloc(GSMFile.Buffer, GSMFile.Used + 1);
- Buffer = malloc(filesize + 200);
- if (Buffer == NULL) {
- fclose(file);
+ if (GSMFile.Buffer == NULL) {
return ERR_MOREMEMORY;
}
- flen = fread(Buffer, 1, filesize, file);
- fclose(file);
-
- if (flen != filesize) {
- free(Buffer);
- return ERR_CANTOPENFILE;
- }
- Buffer[flen] = '\0';
-
- lineStart = Buffer;
- lineEnd = strchr(lineStart, '\n');
+ GSMFile.Buffer[GSMFile.Used] = '\0';
- while (lineEnd && lineStart - Buffer + 1 < flen) {
- lineStart = lineEnd + 1;
- lineEnd = strchr(lineStart, '\n');
-
- if(!strncmp("MessageReference = ", lineStart, 19)) {
- break;
- }
- }
+ lineStart = strstr(GSMFile.Buffer, "\nMessageReference = ");
/* Message reference not found */
- if (lineEnd == NULL || strncmp("MessageReference = ", lineStart, 19) == 0) {
- free(Buffer);
+ if (lineStart == NULL) {
+ free(GSMFile.Buffer);
return ERR_NONE;
}
+ lineStart++;
+ lineEnd = strchr(GSMFile.Buffer, '\n');
+ /* End of buffer? */
+ if (lineEnd == NULL) {
+ lineEnd = GSMFile.Buffer + GSMFile.Used;
+ }
file = fopen(FullPath, "w");
if (file == NULL) {
- free(Buffer);
+ SMSD_LogErrno(Config, "AddSentSMSInfo: Failed to open file for writing");
+ free(GSMFile.Buffer);
return ERR_CANTOPENFILE;
}
- chk_fwrite(Buffer, lineStart - Buffer, 1, file);
+ chk_fwrite(GSMFile.Buffer, lineStart - GSMFile.Buffer, 1, file);
snprintf(MessageReferenceBuffer, sizeof(MessageReferenceBuffer),
"MessageReference = %d\n", TPMR);
@@ -669,19 +712,18 @@ static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage * sms UNUSED, GSM_
chk_fwrite(MessageReferenceBuffer, strlen(MessageReferenceBuffer), 1, file);
- chk_fwrite(lineEnd + 1, (Buffer - lineEnd) + flen - 1, 1, file);
+ chk_fwrite(lineEnd + 1, (GSMFile.Buffer - lineEnd) + GSMFile.Used - 1, 1, file);
fclose(file);
- free(Buffer);
+ free(GSMFile.Buffer);
return ERR_NONE;
fail:
+ SMSD_LogErrno(Config, "AddSentSMSInfo: Failed to write");
if (file) {
fclose(file);
}
- if (Buffer) {
- free(Buffer);
- }
+ free(GSMFile.Buffer);
return ERR_WRITING_FILE;
}
diff --git a/smsd/services/mysql.c b/smsd/services/mysql.c
index caa80e9..2324434 100644
--- a/smsd/services/mysql.c
+++ b/smsd/services/mysql.c
@@ -14,7 +14,7 @@
#ifdef WIN32
#include <windows.h>
#ifndef __GNUC__
-#pragma comment(lib, "libmysql.lib")
+#pragma comment(lib, "mysqlclient.lib")
#endif
#endif
diff --git a/smsd/services/odbc.c b/smsd/services/odbc.c
index 76e3ad8..293ae5f 100644
--- a/smsd/services/odbc.c
+++ b/smsd/services/odbc.c
@@ -28,7 +28,7 @@
static void SMSDODBC_LogError(GSM_SMSDConfig * Config, SQLRETURN origret, SQLSMALLINT handle_type, SQLHANDLE handle, const char *message)
{
- SQLINTEGER i = 0;
+ SQLSMALLINT i = 0;
SQLINTEGER native;
SQLCHAR state[ 7 ];
SQLCHAR text[256];
@@ -82,8 +82,7 @@ time_t SMSDODBC_GetDate(GSM_SMSDConfig * Config, SQL_result *res, unsigned int f
const char *SMSDODBC_GetString(GSM_SMSDConfig * Config, SQL_result *res, unsigned int field)
{
- SQLLEN sqllen;
- int size;
+ SQLLEN size;
SQLRETURN ret;
char shortbuffer[1];
@@ -93,20 +92,12 @@ const char *SMSDODBC_GetString(GSM_SMSDConfig * Config, SQL_result *res, unsigne
}
/* Figure out string length */
- ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, shortbuffer, 0, &sqllen);
+ ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, shortbuffer, 0, &size);
if (!SQL_SUCCEEDED(ret)) {
SMSDODBC_LogError(Config, ret, SQL_HANDLE_STMT, res->odbc, "SQLGetData(string,0) failed");
return NULL;
}
- /*
- * This hack seems to be needed to avoid type breakage on Win64, don't ask me why.
- *
- * Might be actually bug in MinGW compiler, but when using SQLLEN type below
- * anything fails (it does not match to SQL_NULL_DATA and realloc always fails).
- */
- size = sqllen;
-
/* Did not we get NULL? */
if (size == SQL_NULL_DATA) {
SMSD_Log(DEBUG_SQL, Config, "Field %d returning NULL", field);
@@ -116,12 +107,12 @@ const char *SMSDODBC_GetString(GSM_SMSDConfig * Config, SQL_result *res, unsigne
/* Allocate string */
Config->conn.odbc.retstr[field] = realloc(Config->conn.odbc.retstr[field], size + 1);
if (Config->conn.odbc.retstr[field] == NULL) {
- SMSD_Log(DEBUG_ERROR, Config, "Field %d returning NULL, failed to allocate %d bytes of memory", field, size + 1);
+ SMSD_Log(DEBUG_ERROR, Config, "Field %d returning NULL, failed to allocate %ld bytes of memory", field, (long)(size + 1));
return NULL;
}
/* Actually grab result from database */
- ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, Config->conn.odbc.retstr[field], size + 1, &sqllen);
+ ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, Config->conn.odbc.retstr[field], size + 1, &size);
if (!SQL_SUCCEEDED(ret)) {
SMSDODBC_LogError(Config, ret, SQL_HANDLE_STMT, res->odbc, "SQLGetData(string) failed");
return NULL;
@@ -279,6 +270,8 @@ char * SMSDODBC_QuoteString(GSM_SMSDConfig * Config, const char *string)
strcasecmp(driver_name, "pgsql") == 0 ||
strcasecmp(driver_name, "native_pgsql") == 0 ||
strncasecmp(driver_name, "sqlite", 6) == 0 ||
+ strncasecmp(driver_name, "oracle", 6) == 0 ||
+ strncasecmp(driver_name, "freetds", 6) == 0 ||
strcasecmp(Config->driver, "access") == 0) {
quote = '\'';
}
@@ -342,7 +335,7 @@ unsigned long SMSDODBC_AffectedRows(GSM_SMSDConfig * Config, SQL_result *res)
SMSDODBC_LogError(Config, ret, SQL_HANDLE_DBC, Config->conn.odbc.dbc, "SQLRowCount failed");
return 0;
}
- return count;
+ return (unsigned long)count;
}
struct GSM_SMSDdbobj SMSDODBC = {
diff --git a/smsd/services/sql-core.h b/smsd/services/sql-core.h
index 47cd9d1..0383b9a 100644
--- a/smsd/services/sql-core.h
+++ b/smsd/services/sql-core.h
@@ -90,7 +90,7 @@ typedef enum {
/* NamedQuery SQL parameter value as part of SQL_Var */
typedef union {
const char *s;
- int i;
+ long long int i;
} SQL_Val;
/* NamedQuery SQL parameter passed by caller function */
diff --git a/smsd/services/sql.c b/smsd/services/sql.c
index df85c2d..34c2855 100644
--- a/smsd/services/sql.c
+++ b/smsd/services/sql.c
@@ -1,9 +1,9 @@
/**
- * libsql database service
+ * SQL database service
*
* Part of Gammu project
*
- * Copyright (C) 2009 - 2015 Michal Čihař
+ * Copyright (C) 2009 - 2016 Michal Čihař
* (c) 2010 Miloslav Semler
*
* Licensed under GNU GPL version 2 or later
@@ -49,6 +49,7 @@ const char now_plus_pgsql[] = "now() + interval '%d seconds'";
const char now_plus_sqlite[] = "datetime('now', '+%d seconds', 'localtime')";
const char now_plus_freetds[] = "DATEADD('second', %d, CURRENT_TIMESTAMP)";
const char now_plus_access[] = "now()+#00:00:%d#";
+const char now_plus_oracle[] = "CURRENT_TIMESTAMP + INTERVAL '%d' SECOND'";
const char now_plus_fallback[] = "NOW() + INTERVAL %d SECOND";
@@ -69,6 +70,8 @@ static const char *SMSDSQL_NowPlus(GSM_SMSDConfig * Config, int seconds)
sprintf(result, now_plus_freetds, seconds);
} else if (strcasecmp(driver_name, "access") == 0) {
sprintf(result, now_plus_access, seconds);
+ } else if (strcasecmp(driver_name, "oracle") == 0) {
+ sprintf(result, now_plus_oracle, seconds);
} else if (strcasecmp(driver_name, "odbc") == 0) {
sprintf(result, now_plus_odbc, seconds);
} else {
@@ -81,7 +84,7 @@ const char escape_char_odbc[] = "";
const char escape_char_mysql[] = "`";
const char escape_char_pgsql[] = "\"";
const char escape_char_sqlite[] = "";
-const char escape_char_freetds[] = "";
+const char escape_char_freetds[] = "\"";
const char escape_char_fallback[] = "";
static const char *SMSDSQL_EscapeChar(GSM_SMSDConfig * Config)
@@ -96,7 +99,7 @@ static const char *SMSDSQL_EscapeChar(GSM_SMSDConfig * Config)
return escape_char_pgsql;
} else if (strncasecmp(driver_name, "sqlite", 6) == 0) {
return escape_char_sqlite;
- } else if (strcasecmp(driver_name, "freetds") == 0 || strcasecmp(driver_name, "mssql") == 0 || strcasecmp(driver_name, "sybase") == 0) {
+ } else if (strcasecmp(driver_name, "oracle") == 0 || strcasecmp(driver_name, "freetds") == 0 || strcasecmp(driver_name, "mssql") == 0 || strcasecmp(driver_name, "sybase") == 0) {
return escape_char_freetds;
} else if (strcasecmp(Config->driver, "odbc") == 0) {
return escape_char_odbc;
@@ -105,6 +108,32 @@ static const char *SMSDSQL_EscapeChar(GSM_SMSDConfig * Config)
}
}
+const char rownum_clause_fallback[] = "";
+
+
+static const char *SMSDSQL_RownumClause(GSM_SMSDConfig * Config, const char *count, gboolean in_where)
+{
+ const char *driver_name;
+ static char result[100];
+
+ driver_name = SMSDSQL_SQLName(Config);
+
+ if (strcasecmp(driver_name, "oracle") == 0 || strcasecmp(driver_name, "freetds") == 0) {
+ if (in_where) {
+ strcpy(result, " AND ");
+ } else {
+ strcpy(result, " WHERE ");
+ }
+ strcat(result, "ROWNUM <= ");
+ strcat(result, count);
+ strcat(result, " ");
+ return result;
+ } else {
+ return rownum_clause_fallback;
+ }
+}
+
+
const char top_clause_access[] = "TOP";
const char top_clause_fallback[] = "";
@@ -136,7 +165,7 @@ static const char *SMSDSQL_LimitClause(GSM_SMSDConfig * Config, const char *coun
driver_name = SMSDSQL_SQLName(Config);
- if (strcasecmp(driver_name, "access") == 0) {
+ if (strcasecmp(driver_name, "access") == 0 || strcasecmp(driver_name, "freetds") == 0 || strcasecmp(driver_name, "oracle") == 0) {
return limit_clause_access;
} else {
strcpy(result, limit_clause_fallback);
@@ -173,7 +202,7 @@ static const char *SMSDSQL_CurrentTime(GSM_SMSDConfig * Config)
return currtime_pgsql;
} else if (strncasecmp(driver_name, "sqlite", 6) == 0) {
return currtime_sqlite;
- } else if (strcasecmp(driver_name, "freetds") == 0 || strcasecmp(driver_name, "mssql") == 0 || strcasecmp(driver_name, "sybase") == 0) {
+ } else if (strcasecmp(Config->driver, "oracle") == 0 || strcasecmp(driver_name, "freetds") == 0 || strcasecmp(driver_name, "mssql") == 0 || strcasecmp(driver_name, "sybase") == 0) {
return currtime_freetds;
} else if (strcasecmp(Config->driver, "odbc") == 0) {
return currtime_odbc;
@@ -193,7 +222,7 @@ static const char *SMSDSQL_Now(GSM_SMSDConfig * Config)
return now_pgsql;
} else if (strncasecmp(driver_name, "sqlite", 6) == 0) {
return now_sqlite;
- } else if (strcasecmp(driver_name, "freetds") == 0 || strcasecmp(driver_name, "mssql") == 0 || strcasecmp(driver_name, "sybase") == 0) {
+ } else if (strcasecmp(Config->driver, "oracle") == 0 || strcasecmp(driver_name, "freetds") == 0 || strcasecmp(driver_name, "mssql") == 0 || strcasecmp(driver_name, "sybase") == 0) {
return now_freetds;
} else if (strcasecmp(Config->driver, "access") == 0) {
return now_access;
@@ -289,24 +318,6 @@ static GSM_Error SMSDSQL_NamedQuery(GSM_SMSDConfig * Config, const char *sql_que
int n, argc = 0;
struct GSM_SMSDdbobj *db = Config->db;
- GSM_NetworkInfo NetInfo;
- char empty[1] = "";
- char *NetCode, *NetName;
-
- NetCode = empty;
- NetName = empty;
-
- /* Query network status only if we need it */
- if (
- (strstr(sql_query, "%O") != NULL || strstr(sql_query, "%M") != NULL)
- && GSM_GetNetworkInfo(Config->gsm, &NetInfo) == ERR_NONE
- ) {
- NetCode = NetInfo.NetworkCode;
- if (NetInfo.NetworkName[0] != 0x00 || NetInfo.NetworkName[1] != 0x00) {
- NetName = DecodeUnicodeConsole(NetInfo.NetworkName);
- }
- }
-
if (params != NULL) {
while (params[argc].type != SQL_TYPE_NONE) argc++;
}
@@ -324,7 +335,7 @@ static GSM_Error SMSDSQL_NamedQuery(GSM_SMSDConfig * Config, const char *sql_que
if (n < argc && n >= 0) {
switch(params[n].type){
case SQL_TYPE_INT:
- ptr += sprintf(ptr, "%i", params[n].v.i);
+ ptr += sprintf(ptr, "%lli", params[n].v.i);
break;
case SQL_TYPE_STRING:
buffer2 = db->QuoteString(Config, params[n].v.s);
@@ -350,14 +361,17 @@ static GSM_Error SMSDSQL_NamedQuery(GSM_SMSDConfig * Config, const char *sql_que
case 'I':
to_print = Config->Status->IMEI;
break;
+ case 'S':
+ to_print = Config->Status->IMSI;
+ break;
case 'P':
to_print = Config->PhoneID;
break;
case 'O':
- to_print = NetCode;
+ to_print = Config->Status->NetInfo.NetworkCode;
break;
case 'M':
- to_print = NetName;
+ to_print = DecodeUnicodeConsole(Config->Status->NetInfo.NetworkName);
break;
case 'N':
snprintf(static_buff, sizeof(static_buff), "Gammu %s, %s, %s", GAMMU_VERSION, GetOS(), GetCompiler());
@@ -478,7 +492,14 @@ static GSM_Error SMSDSQL_CheckTable(GSM_SMSDConfig * Config, const char *table)
GSM_Error error;
struct GSM_SMSDdbobj *db = Config->db;
- sprintf(buffer, "SELECT %s * FROM %s %s", SMSDSQL_TopClause(Config, "1"), table, SMSDSQL_LimitClause(Config, "1"));
+ sprintf(
+ buffer,
+ "SELECT %s * FROM %s %s %s",
+ SMSDSQL_TopClause(Config, "1"),
+ table,
+ SMSDSQL_RownumClause(Config, "1", FALSE),
+ SMSDSQL_LimitClause(Config, "1")
+ );
error = SMSDSQL_Query(Config, buffer, &res);
if (error != ERR_NONE) {
SMSD_Log(DEBUG_ERROR, Config, "Table %s not found, disconnecting!", table);
@@ -525,12 +546,6 @@ static GSM_Error SMSDSQL_Init(GSM_SMSDConfig * Config)
if (error != ERR_NONE)
return error;
- error = SMSDSQL_CheckTable(Config, Config->table_daemons);
- if (error != ERR_NONE) {
- SMSD_Log(DEBUG_ERROR, Config, "Failed to open table %s", Config->table_daemons);
- return error;
- }
-
error = SMSDSQL_CheckTable(Config, Config->table_gammu);
if (error != ERR_NONE) {
SMSD_Log(DEBUG_ERROR, Config, "Failed to open table %s", Config->table_gammu);
@@ -581,7 +596,7 @@ static GSM_Error SMSDSQL_Init(GSM_SMSDConfig * Config)
db->Free(Config);
return ERR_UNKNOWN;
}
- version = db->GetNumber(Config, &res, 0);
+ version = (int)db->GetNumber(Config, &res, 0);
db->FreeResult(Config, &res);
error = SMSD_CheckDBVersion(Config, version);
if (error != ERR_NONE) {
@@ -876,8 +891,8 @@ static GSM_Error SMSDSQL_FindOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConfig
sms->Number = 0;
for (i = 0; i < GSM_MAX_MULTI_SMS; i++) {
GSM_SetDefaultSMSData(&sms->SMS[i]);
- sms->SMS[i].SMSC.Number[0] = 0;
- sms->SMS[i].SMSC.Number[1] = 0;
+ /* Force using default SMSC */
+ sms->SMS[i].SMSC.Location = 0;
}
for (i = 1; i < GSM_MAX_MULTI_SMS + 1; i++) {
@@ -981,16 +996,16 @@ static GSM_Error SMSDSQL_FindOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConfig
}
}
- sms->SMS[sms->Number].Class = db->GetNumber(Config, &res, 3);
+ sms->SMS[sms->Number].Class = (int)db->GetNumber(Config, &res, 3);
sms->SMS[sms->Number].PDU = SMS_Submit;
sms->Number++;
if (i == 1) {
strcpy(Config->CreatorID, db->GetString(Config, &res, 10));
- Config->relativevalidity = db->GetNumber(Config, &res, 8);
+ Config->relativevalidity = (int)db->GetNumber(Config, &res, 8);
Config->currdeliveryreport = db->GetBool(Config, &res, 9);
- Config->retries = db->GetNumber(Config, &res, 11);
+ Config->retries = (int)db->GetNumber(Config, &res, 11);
/* Is this a multipart message? */
if (!db->GetBool(Config, &res, 7)) {
@@ -1039,7 +1054,7 @@ static GSM_Error SMSDSQL_CreateOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConf
{
char creator[200];
int i;
- unsigned int ID = 0;
+ unsigned long long ID = 0;
SQL_result res;
SQL_Var vars[6];
struct GSM_SMSDdbobj *db = Config->db;
@@ -1083,9 +1098,9 @@ static GSM_Error SMSDSQL_CreateOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConf
}
db->FreeResult(Config, &res);
}
- SMSD_Log(DEBUG_INFO, Config, "Written message with ID %u", ID);
+ SMSD_Log(DEBUG_INFO, Config, "Written message with ID %llu", ID);
if (NewID != NULL)
- sprintf(NewID, "%d", ID);
+ sprintf(NewID, "%llu", ID);
return ERR_NONE;
}
@@ -1262,10 +1277,6 @@ GSM_Error SMSDSQL_ReadConfiguration(GSM_SMSDConfig *Config)
Config->database="sms";
}
- Config->table_daemons = INI_GetValue(Config->smsdcfgfile, "tables", "daemons", FALSE);
- if (Config->table_daemons == NULL){
- Config->table_daemons = "daemons";
- }
Config->table_gammu = INI_GetValue(Config->smsdcfgfile, "tables", "gammu", FALSE);
if (Config->table_gammu == NULL){
Config->table_gammu = "gammu";
@@ -1344,6 +1355,7 @@ GSM_Error SMSDSQL_ReadConfiguration(GSM_SMSDConfig *Config)
if (SMSDSQL_option(Config, SQL_QUERY_INSERT_PHONE, "insert_phone",
"INSERT INTO ", Config->table_phones, " (",
ESCAPE_FIELD("IMEI"),
+ ", ", ESCAPE_FIELD("IMSI"),
", ", ESCAPE_FIELD("ID"),
", ", ESCAPE_FIELD("NetCode"),
", ", ESCAPE_FIELD("NetName"),
@@ -1354,7 +1366,7 @@ GSM_Error SMSDSQL_ReadConfiguration(GSM_SMSDConfig *Config)
", ", ESCAPE_FIELD("Client"),
", ", ESCAPE_FIELD("Battery"),
", ", ESCAPE_FIELD("Signal"),
- ") VALUES (%I, %P, %O, %M, %1, %2, ",
+ ") VALUES (%I, %S, %P, %O, %M, %1, %2, ",
SMSDSQL_Now(Config),
", ",
SMSDSQL_NowPlus(Config, 10),
@@ -1446,8 +1458,9 @@ GSM_Error SMSDSQL_ReadConfiguration(GSM_SMSDConfig *Config)
" AND ", ESCAPE_FIELD("SendingTimeOut"), " < ", SMSDSQL_Now(Config),
" AND ", ESCAPE_FIELD("SendBefore"), " >= ", SMSDSQL_CurrentTime(Config),
" AND ", ESCAPE_FIELD("SendAfter"), " <= ", SMSDSQL_CurrentTime(Config),
- " AND ( ", ESCAPE_FIELD("SenderID"), " is NULL OR ", ESCAPE_FIELD("SenderID"), " = '' OR ", ESCAPE_FIELD("SenderID"), " = %P )"
- " ORDER BY ", ESCAPE_FIELD("InsertIntoDB"), " ASC ", SMSDSQL_LimitClause(Config, "%1"), NULL) != ERR_NONE) {
+ " AND ( ", ESCAPE_FIELD("SenderID"), " is NULL OR ", ESCAPE_FIELD("SenderID"), " = '' OR ", ESCAPE_FIELD("SenderID"), " = %P )",
+ SMSDSQL_RownumClause(Config, "%1", TRUE),
+ " ORDER BY ", ESCAPE_FIELD("Priority"), " DESC, ", ESCAPE_FIELD("InsertIntoDB"), " ASC ", SMSDSQL_LimitClause(Config, "%1"), NULL) != ERR_NONE) {
return ERR_UNKNOWN;
}
diff --git a/smsd/test-smsd-files-include.sh.in b/smsd/test-smsd-files-include.sh.in
index 71f481e..8d7078c 100644
--- a/smsd/test-smsd-files-include.sh.in
+++ b/smsd/test-smsd-files-include.sh.in
@@ -42,9 +42,11 @@ loglevel = textall
[smsd]
commtimeout = 5
+multiparttimeout = 5
+ReceiveFrequency = 5
debuglevel = 255
logfile = stderr
-runonreceive = @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/received.sh
+runonreceive = @SH_BIN@ @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/received.sh
service = files
inboxpath = @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/inbox/
outboxpath = @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/outbox/
@@ -92,12 +94,13 @@ $SMSD_INJECT_CMD -c "$CONFIG_PATH" TEXT 123465 -text "Lorem ipsum."
sleep 5
+# Incoming messages
for sms in 10 16 26 ; do
cp @CMAKE_CURRENT_SOURCE_DIR@/../tests/at-sms-encode/$sms.backup $DUMMY_PATH/sms/3/$sms
done
TIMEOUT=0
-while ! $SMSD_MONITOR_CMD -C -c "$CONFIG_PATH" -n 1 -d 0 | grep -q ";999999999999999;4;3;0;100;42" ; do
+while ! $SMSD_MONITOR_CMD -C -c "$CONFIG_PATH" -n 1 -d 0 | grep -q ";999999999999999;994299429942994;4;3;0;100;42" ; do
$SMSD_MONITOR_CMD -C -c "$CONFIG_PATH" -n 1 -d 0
sleep 1
TIMEOUT=$(($TIMEOUT + 1))
diff --git a/smsd/test-smsd.sh.in b/smsd/test-smsd.sh.in
index 3b184a9..0350565 100755
--- a/smsd/test-smsd.sh.in
+++ b/smsd/test-smsd.sh.in
@@ -9,7 +9,7 @@ SMSD_CMD="$2"
SMSD_INJECT_CMD="$3"
SMSD_MONITOR_CMD="$4"
-TEST_MATCH=";999999999999999;3;9;0;100;42"
+TEST_MATCH=";999999999999999;994299429942994;3;9;0;100;42"
if [ "x@HAVE_KILL@" = x1 ] ; then
SMSD_EXTRA_PARAMS="-p @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/smsd.pid"
@@ -47,16 +47,17 @@ loglevel = textall
[smsd]
commtimeout = 5
multiparttimeout = 5
+ReceiveFrequency = 5
debuglevel = 255
logfile = stderr
-runonreceive = @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/received.sh
+runonreceive = @SH_BIN@ @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/received.sh
EOT
# Add driver specific configuration
case $SERVICE in
dbi-sqlite3)
cat >> .smsdrc <<EOT
-service = dbi
+service = sql
driver = sqlite3
database = smsd.db
dbdir = @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/
@@ -64,7 +65,7 @@ EOT
;;
dbi-pgsql)
cat >> .smsdrc <<EOT
-service = dbi
+service = sql
driver = pgsql
pc = @PSQL_HOST@
database = @PSQL_DATABASE@
@@ -74,7 +75,8 @@ EOT
;;
pgsql)
cat >> .smsdrc <<EOT
-service = pgsql
+service = sql
+driver = native_pgsql
pc = @PSQL_HOST@
database = @PSQL_DATABASE@
user = @PSQL_USER@
@@ -83,7 +85,7 @@ EOT
;;
dbi-mysql)
cat >> .smsdrc <<EOT
-service = dbi
+service = sql
driver = mysql
pc = @MYSQL_HOST@
database = @MYSQL_DATABASE@
@@ -93,7 +95,8 @@ EOT
;;
mysql)
cat >> .smsdrc <<EOT
-service = mysql
+service = sql
+driver = native_mysql
pc = @MYSQL_HOST@
database = @MYSQL_DATABASE@
user = @MYSQL_USER@
@@ -111,7 +114,7 @@ sql = mysql
EOT
;;
null)
- TEST_MATCH=";999999999999999;0;9;0;100;42"
+ TEST_MATCH=";999999999999999;994299429942994;0;9;0;100;42"
cat >> .smsdrc <<EOT
service = null
EOT
@@ -133,21 +136,21 @@ esac
# Create database structures
case $SERVICE in
*sqlite3)
- @SQLITE_BIN@ smsd.db < @CMAKE_CURRENT_SOURCE_DIR@/../docs/sql/sqlite.sql
+ "@SQLITE_BIN@" smsd.db < @CMAKE_CURRENT_SOURCE_DIR@/../docs/sql/sqlite.sql
;;
*pgsql)
- echo "DROP TABLE IF EXISTS daemons, gammu, inbox, outbox, outbox_multipart, pbk, pbk_groups, phones, sentitems;" | PGPASSWORD=@PSQL_PASSWORD@ @PSQL_BIN@ -h @PSQL_HOST@ -U @PSQL_USER@ @PSQL_DATABASE@
- PGPASSWORD=@PSQL_PASSWORD@ @PSQL_BIN@ -h @PSQL_HOST@ -U @PSQL_USER@ @PSQL_DATABASE@ < @CMAKE_CURRENT_SOURCE_DIR@/../docs/sql/pgsql.sql 2>&1 | grep -v 'ERROR.*language "plpgsql" already exists'
+ echo "DROP TABLE IF EXISTS gammu, inbox, outbox, outbox_multipart, phones, sentitems;" | PGPASSWORD="@PSQL_PASSWORD@" "@PSQL_BIN@" -h "@PSQL_HOST@" -U "@PSQL_USER@" "@PSQL_DATABASE@"
+ PGPASSWORD="@PSQL_PASSWORD@" "@PSQL_BIN@" -h "@PSQL_HOST@" -U "@PSQL_USER@" "@PSQL_DATABASE@" < "@CMAKE_CURRENT_SOURCE_DIR@/../docs/sql/pgsql.sql" 2>&1 | grep -v 'ERROR.*language "plpgsql" already exists'
;;
*mysql|odbc)
- echo "DROP TABLE IF EXISTS daemons, gammu, inbox, outbox, outbox_multipart, pbk, pbk_groups, phones, sentitems;" | @MYSQL_BIN@ -u@MYSQL_USER@ -h@MYSQL_HOST@ -p@MYSQL_PASSWORD@ @MYSQL_DATABASE@
- @MYSQL_BIN@ -h@MYSQL_HOST@ -u@MYSQL_USER@ -p@MYSQL_PASSWORD@ @MYSQL_DATABASE@ < @CMAKE_CURRENT_SOURCE_DIR@/../docs/sql/mysql.sql
+ echo "DROP TABLE IF EXISTS gammu, inbox, outbox, outbox_multipart, phones, sentitems;" | "@MYSQL_BIN@" "-u@MYSQL_USER@" "-h@MYSQL_HOST@" "-p@MYSQL_PASSWORD@" "@MYSQL_DATABASE@"
+ "@MYSQL_BIN@" "-h@MYSQL_HOST@" "-u@MYSQL_USER@" "-p@MYSQL_PASSWORD@" "@MYSQL_DATABASE@" < "@CMAKE_CURRENT_SOURCE_DIR@/../docs/sql/mysql.sql"
;;
files*)
- mkdir -p @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/inbox/
- mkdir -p @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/outbox/
- mkdir -p @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/sent/
- mkdir -p @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/error/
+ mkdir -p "@CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/inbox/"
+ mkdir -p "@CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/outbox/"
+ mkdir -p "@CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/sent/"
+ mkdir -p "@CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/error/"
;;
esac
@@ -180,10 +183,10 @@ case $SERVICE in
echo "INSERT INTO outbox(DestinationNumber,TextDecoded,CreatorID,Coding) VALUES('800123465', 'This is a SQL test message', 'T3st', 'Default_No_Compression');" | @SQLITE_BIN@ smsd.db
;;
*pgsql)
- echo "INSERT INTO outbox(\"DestinationNumber\",\"TextDecoded\",\"CreatorID\",\"Coding\") VALUES('800123465', 'This is a SQL test message', 'T3st', 'Default_No_Compression');" | PGPASSWORD=@PSQL_PASSWORD@ @PSQL_BIN@ -h @PSQL_HOST@ -U @PSQL_USER@ @PSQL_DATABASE@
+ echo "INSERT INTO outbox(\"DestinationNumber\",\"TextDecoded\",\"CreatorID\",\"Coding\") VALUES('800123465', 'This is a SQL test message', 'T3st', 'Default_No_Compression');" | PGPASSWORD="@PSQL_PASSWORD@" "@PSQL_BIN@" -h "@PSQL_HOST@" -U "@PSQL_USER@" "@PSQL_DATABASE@"
;;
*mysql|odbc)
- echo "INSERT INTO outbox(DestinationNumber,TextDecoded,CreatorID,Coding) VALUES('800123465', 'This is a SQL test message', 'T3st', 'Default_No_Compression');" | @MYSQL_BIN@ -u@MYSQL_USER@ -h@MYSQL_HOST@ -p@MYSQL_PASSWORD@ @MYSQL_DATABASE@
+ echo "INSERT INTO outbox(DestinationNumber,TextDecoded,CreatorID,Coding) VALUES('800123465', 'This is a SQL test message', 'T3st', 'Default_No_Compression');" | "@MYSQL_BIN@" "-u@MYSQL_USER@" "-h@MYSQL_HOST@" "-p@MYSQL_PASSWORD@" "@MYSQL_DATABASE@"
;;
files*)
cp @CMAKE_CURRENT_SOURCE_DIR@/tests/OUT+4201234567890.txt @CMAKE_CURRENT_BINARY_DIR@/smsd-test-$SERVICE/outbox/
@@ -196,8 +199,9 @@ $SMSD_INJECT_CMD -c "$CONFIG_PATH" TEXT 123465 -text "Lorem ipsum."
$SMSD_CMD -c "$CONFIG_PATH" $SMSD_EXTRA_PARAMS &
SMSD_PID=$!
-sleep 10
+sleep 5
+# Incoming messages
for sms in 10 16 26 ; do
cp @CMAKE_CURRENT_SOURCE_DIR@/../tests/at-sms-encode/$sms.backup $DUMMY_PATH/sms/3/$sms
done