Diffstat (limited to 'gammu/emb/gammu/smsd/smsdcore.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/gammu/smsd/smsdcore.c | 180 |
1 files changed, 128 insertions, 52 deletions
diff --git a/gammu/emb/gammu/smsd/smsdcore.c b/gammu/emb/gammu/smsd/smsdcore.c index fbc55d3..cc9accc 100644 --- a/gammu/emb/gammu/smsd/smsdcore.c +++ b/gammu/emb/gammu/smsd/smsdcore.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek and Joergen Thomsen */ | 1 | /* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */ |
2 | 2 | ||
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <signal.h> | 4 | #include <signal.h> |
5 | #include <stdarg.h> | 5 | #include <stdarg.h> |
@@ -13,12 +13,15 @@ | |||
13 | # include "s_mysql.h" | 13 | # include "s_mysql.h" |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | FILE *smsd_log_file = NULL; | 16 | FILE *smsd_log_file = NULL; |
17 | static int TPMR; | ||
17 | static GSM_Error SendingSMSStatus; | 18 | static GSM_Error SendingSMSStatus; |
19 | |||
18 | static void SMSSendingSMSStatus (char *Device, int status, int mr) | 20 | static void SMSSendingSMSStatus (char *Device, int status, int mr) |
19 | { | 21 | { |
20 | dbgprintf("Incoming SMS device: \"%s\" status=%d, reference=%d\n",Device, status, mr); | 22 | dbgprintf("Incoming SMS device: \"%s\" status=%d, reference=%d\n",Device, status, mr); |
23 | TPMR = mr; | ||
21 | if (status==0) { | 24 | if (status==0) { |
22 | SendingSMSStatus = ERR_NONE; | 25 | SendingSMSStatus = ERR_NONE; |
23 | } else { | 26 | } else { |
24 | SendingSMSStatus = ERR_UNKNOWN; | 27 | SendingSMSStatus = ERR_UNKNOWN; |
@@ -72,9 +75,9 @@ void WriteSMSDLog(char *format, ...) | |||
72 | fflush(smsd_log_file); | 75 | fflush(smsd_log_file); |
73 | } | 76 | } |
74 | } | 77 | } |
75 | 78 | ||
76 | void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | 79 | void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log, char *service) |
77 | { | 80 | { |
78 | INI_Section *smsdcfgfile = NULL; | 81 | INI_Section *smsdcfgfile = NULL; |
79 | GSM_Config smsdcfg; | 82 | GSM_Config smsdcfg; |
80 | unsigned char *str; | 83 | unsigned char *str; |
@@ -101,8 +104,9 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
101 | Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "gammu", false); | 104 | Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "gammu", false); |
102 | if (Config->IncludeNumbers) { | 105 | if (Config->IncludeNumbers) { |
103 | GSM_ReadConfig(smsdcfgfile, &smsdcfg, 0); | 106 | GSM_ReadConfig(smsdcfgfile, &smsdcfg, 0); |
104 | memcpy(&s.Config,&smsdcfg,sizeof(GSM_Config)); | 107 | memcpy(&s.Config,&smsdcfg,sizeof(GSM_Config)); |
108 | error=GSM_SetDebugFile(s.Config[0].DebugFile, &di); | ||
105 | } | 109 | } |
106 | 110 | ||
107 | Config->PINCode=INI_GetValue(smsdcfgfile, "smsd", "PIN", false); | 111 | Config->PINCode=INI_GetValue(smsdcfgfile, "smsd", "PIN", false); |
108 | if (Config->PINCode == NULL) { | 112 | if (Config->PINCode == NULL) { |
@@ -111,56 +115,71 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
111 | exit(-1); | 115 | exit(-1); |
112 | } | 116 | } |
113 | if (log) WriteSMSDLog("PIN code is \"%s\"",Config->PINCode); | 117 | if (log) WriteSMSDLog("PIN code is \"%s\"",Config->PINCode); |
114 | 118 | ||
115 | Config->user = INI_GetValue(smsdcfgfile, "smsd", "user", false); | ||
116 | if (Config->user == NULL) Config->user="root"; | ||
117 | Config->password = INI_GetValue(smsdcfgfile, "smsd", "password", false); | ||
118 | if (Config->password == NULL) Config->password=""; | ||
119 | Config->PC = INI_GetValue(smsdcfgfile, "smsd", "pc", false); | ||
120 | if (Config->PC == NULL) Config->PC="localhost"; | ||
121 | Config->database = INI_GetValue(smsdcfgfile, "smsd", "database", false); | ||
122 | if (Config->database == NULL) Config->database="sms"; | ||
123 | |||
124 | str = INI_GetValue(smsdcfgfile, "smsd", "commtimeout", false); | 119 | str = INI_GetValue(smsdcfgfile, "smsd", "commtimeout", false); |
125 | if (str) Config->commtimeout=atoi(str); else Config->commtimeout = 1; | 120 | if (str) Config->commtimeout=atoi(str); else Config->commtimeout = 1; |
126 | str = INI_GetValue(smsdcfgfile, "smsd", "sendtimeout", false); | 121 | str = INI_GetValue(smsdcfgfile, "smsd", "sendtimeout", false); |
127 | if (str) Config->sendtimeout=atoi(str); else Config->sendtimeout = 10; | 122 | if (str) Config->sendtimeout=atoi(str); else Config->sendtimeout = 10; |
128 | str = INI_GetValue(smsdcfgfile, "smsd", "receivefrequency", false); | 123 | str = INI_GetValue(smsdcfgfile, "smsd", "receivefrequency", false); |
129 | if (str) Config->receivefrequency=atoi(str); else Config->receivefrequency = 0; | 124 | if (str) Config->receivefrequency=atoi(str); else Config->receivefrequency = 0; |
130 | if (log) WriteSMSDLog("commtimeout=%i, sendtimeout=%i, receivefrequency=%i", Config->commtimeout, Config->sendtimeout, Config->receivefrequency); | 125 | str = INI_GetValue(smsdcfgfile, "smsd", "resetfrequency", false); |
126 | if (str) Config->resetfrequency=atoi(str); else Config->resetfrequency = 0; | ||
127 | if (log) WriteSMSDLog("commtimeout=%i, sendtimeout=%i, receivefrequency=%i, resetfrequency=%i", | ||
128 | Config->commtimeout, Config->sendtimeout, Config->receivefrequency, Config->resetfrequency); | ||
131 | 129 | ||
132 | Config->deliveryreport = INI_GetValue(smsdcfgfile, "smsd", "deliveryreport", false); | 130 | Config->deliveryreport = INI_GetValue(smsdcfgfile, "smsd", "deliveryreport", false); |
133 | if (Config->deliveryreport == NULL || (!mystrncasecmp(Config->deliveryreport, "log", 3) && !mystrncasecmp(Config->deliveryreport, "sms", 3))) { | 131 | if (Config->deliveryreport == NULL || (!mystrncasecmp(Config->deliveryreport, "log", 3) && !mystrncasecmp(Config->deliveryreport, "sms", 3))) { |
134 | Config->deliveryreport = "no"; | 132 | Config->deliveryreport = "no"; |
135 | } | 133 | } |
136 | if (log) WriteSMSDLog("deliveryreport = %s", Config->deliveryreport); | 134 | if (log) WriteSMSDLog("deliveryreport = %s", Config->deliveryreport); |
137 | 135 | ||
138 | Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false); | 136 | Config->PhoneID = INI_GetValue(smsdcfgfile, "smsd", "phoneid", false); |
139 | if (Config->inboxpath == NULL) Config->inboxpath = emptyPath; | 137 | if (Config->PhoneID == NULL) Config->PhoneID = ""; |
138 | if (log) WriteSMSDLog("phoneid = %s", Config->PhoneID); | ||
140 | 139 | ||
141 | Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false); | 140 | if (!strcmp(service,"FILES")) { |
142 | if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) { | 141 | Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false); |
143 | Config->inboxformat = "standard"; | 142 | if (Config->inboxpath == NULL) Config->inboxpath = emptyPath; |
144 | } | ||
145 | if (log) WriteSMSDLog("Inbox is \"%s\" with format \"%s\"", Config->inboxpath, Config->inboxformat); | ||
146 | 143 | ||
147 | Config->outboxpath=INI_GetValue(smsdcfgfile, "smsd", "outboxpath", false); | 144 | Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false); |
148 | if (Config->outboxpath == NULL) Config->outboxpath = emptyPath; | 145 | if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) { |
146 | Config->inboxformat = "standard"; | ||
147 | } | ||
148 | if (log) WriteSMSDLog("Inbox is \"%s\" with format \"%s\"", Config->inboxpath, Config->inboxformat); | ||
149 | 149 | ||
150 | Config->transmitformat=INI_GetValue(smsdcfgfile, "smsd", "transmitformat", false); | 150 | Config->outboxpath=INI_GetValue(smsdcfgfile, "smsd", "outboxpath", false); |
151 | if (Config->transmitformat == NULL || (!mystrncasecmp(Config->transmitformat, "auto", 4) && !mystrncasecmp(Config->transmitformat, "unicode", 7))) { | 151 | if (Config->outboxpath == NULL) Config->outboxpath = emptyPath; |
152 | Config->transmitformat = "7bit"; | ||
153 | } | ||
154 | if (log) WriteSMSDLog("Outbox is \"%s\" with transmission format \"%s\"", Config->outboxpath, Config->transmitformat); | ||
155 | 152 | ||
156 | Config->sentsmspath=INI_GetValue(smsdcfgfile, "smsd", "sentsmspath", false); | 153 | Config->transmitformat=INI_GetValue(smsdcfgfile, "smsd", "transmitformat", false); |
157 | if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath; | 154 | if (Config->transmitformat == NULL || (!mystrncasecmp(Config->transmitformat, "auto", 4) && !mystrncasecmp(Config->transmitformat, "unicode", 7))) { |
158 | if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath); | 155 | Config->transmitformat = "7bit"; |
156 | } | ||
157 | if (log) WriteSMSDLog("Outbox is \"%s\" with transmission format \"%s\"", Config->outboxpath, Config->transmitformat); | ||
159 | 158 | ||
160 | Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false); | 159 | Config->sentsmspath=INI_GetValue(smsdcfgfile, "smsd", "sentsmspath", false); |
161 | if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath; | 160 | if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath; |
162 | if (log) WriteSMSDLog("SMS with errors moved to \"%s\"",Config->errorsmspath); | 161 | if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath); |
162 | |||
163 | Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false); | ||
164 | if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath; | ||
165 | if (log) WriteSMSDLog("SMS with errors moved to \"%s\"",Config->errorsmspath); | ||
166 | } | ||
167 | |||
168 | #ifdef HAVE_MYSQL_MYSQL_H | ||
169 | if (!strcmp(service,"MYSQL")) { | ||
170 | Config->skipsmscnumber = INI_GetValue(smsdcfgfile, "smsd", "skipsmscnumber", false); | ||
171 | if (Config->skipsmscnumber == NULL) Config->skipsmscnumber=""; | ||
172 | Config->user = INI_GetValue(smsdcfgfile, "smsd", "user", false); | ||
173 | if (Config->user == NULL) Config->user="root"; | ||
174 | Config->password = INI_GetValue(smsdcfgfile, "smsd", "password", false); | ||
175 | if (Config->password == NULL) Config->password=""; | ||
176 | Config->PC = INI_GetValue(smsdcfgfile, "smsd", "pc", false); | ||
177 | if (Config->PC == NULL) Config->PC="localhost"; | ||
178 | Config->database = INI_GetValue(smsdcfgfile, "smsd", "database", false); | ||
179 | if (Config->database == NULL) Config->database="sms"; | ||
180 | } | ||
181 | #endif | ||
163 | 182 | ||
164 | Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "include_numbers", false); | 183 | Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "include_numbers", false); |
165 | Config->ExcludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "exclude_numbers", false); | 184 | Config->ExcludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "exclude_numbers", false); |
166 | if (Config->IncludeNumbers != NULL) { | 185 | if (Config->IncludeNumbers != NULL) { |
@@ -173,10 +192,12 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
173 | if (log) WriteSMSDLog("Exclude numbers available, but IGNORED"); | 192 | if (log) WriteSMSDLog("Exclude numbers available, but IGNORED"); |
174 | } | 193 | } |
175 | } | 194 | } |
176 | 195 | ||
177 | Config->retries = 0; | 196 | Config->retries = 0; |
178 | Config->prevSMSID[0] = 0; | 197 | Config->prevSMSID[0] = 0; |
198 | Config->SMSC.Location = 0; | ||
199 | Config->relativevalidity = -1; | ||
179 | } | 200 | } |
180 | 201 | ||
181 | bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) | 202 | bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) |
182 | { | 203 | { |
@@ -191,8 +212,9 @@ bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) | |||
191 | return false; | 212 | return false; |
192 | } | 213 | } |
193 | /* No supported - do not check more */ | 214 | /* No supported - do not check more */ |
194 | if (error == ERR_NOTSUPPORTED) return true; | 215 | if (error == ERR_NOTSUPPORTED) return true; |
216 | |||
195 | /* If PIN, try to enter */ | 217 | /* If PIN, try to enter */ |
196 | switch (SecurityCode.Type) { | 218 | switch (SecurityCode.Type) { |
197 | case SEC_Pin: | 219 | case SEC_Pin: |
198 | WriteSMSDLog("Trying to enter PIN"); | 220 | WriteSMSDLog("Trying to enter PIN"); |
@@ -325,45 +347,73 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
325 | while (i==Date.Second && !gshutdown) { | 347 | while (i==Date.Second && !gshutdown) { |
326 | my_sleep(10); | 348 | my_sleep(10); |
327 | GSM_GetCurrentDateTime(&Date); | 349 | GSM_GetCurrentDateTime(&Date); |
328 | } | 350 | } |
351 | Service->RefreshPhoneStatus(Config); | ||
329 | } | 352 | } |
330 | return true; | 353 | return true; |
331 | } | 354 | } |
332 | if (error != ERR_NONE) { | 355 | if (error != ERR_NONE) { |
333 | /* Unknown error - escape */ | 356 | /* Unknown error - escape */ |
334 | WriteSMSDLog("Error in outbox on %s", Config->SMSID); | 357 | WriteSMSDLog("Error in outbox on %s", Config->SMSID); |
335 | for (i=0;i<sms.Number;i++) { | 358 | for (i=0;i<sms.Number;i++) { |
336 | Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); | 359 | Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_ERROR, -1); |
337 | } | 360 | } |
338 | Service->MoveSMS(&sms,Config, Config->SMSID, true,false); | 361 | Service->MoveSMS(&sms,Config, Config->SMSID, true,false); |
339 | return false; | 362 | return false; |
340 | } | 363 | } |
364 | |||
341 | if (!gshutdown) { | 365 | if (!gshutdown) { |
342 | if (strcmp(Config->prevSMSID, Config->SMSID) == 0) { | 366 | if (strcmp(Config->prevSMSID, Config->SMSID) == 0) { |
343 | Config->retries++; | 367 | Config->retries++; |
344 | if (Config->retries > MAX_RETRIES) { | 368 | if (Config->retries > MAX_RETRIES) { |
345 | Config->retries = 0; | 369 | Config->retries = 0; |
346 | strcpy(Config->prevSMSID, ""); | 370 | strcpy(Config->prevSMSID, ""); |
347 | WriteSMSDLog("Moved to errorbox: %s", Config->SMSID); | 371 | WriteSMSDLog("Moved to errorbox: %s", Config->SMSID); |
348 | for (i=0;i<sms.Number;i++) { | 372 | for (i=0;i<sms.Number;i++) { |
349 | Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); | 373 | Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_ERROR, -1); |
350 | } | 374 | } |
351 | Service->MoveSMS(&sms,Config, Config->SMSID, true,false); | 375 | Service->MoveSMS(&sms,Config, Config->SMSID, true,false); |
352 | return false; | 376 | return false; |
353 | } | 377 | } |
354 | } else { | 378 | } else { |
355 | Config->retries = 0; | 379 | Config->retries = 0; |
356 | strcpy(Config->prevSMSID, Config->SMSID); | 380 | strcpy(Config->prevSMSID, Config->SMSID); |
357 | } | 381 | } |
358 | for (i=0;i<sms.Number;i++) { | 382 | for (i=0;i<sms.Number;i++) { |
359 | if (strcmp(Config->deliveryreport, "no") != 0) sms.SMS[i].PDU = SMS_Status_Report; | 383 | if (sms.SMS[i].SMSC.Location == 1) { |
384 | if (Config->SMSC.Location == 0) { | ||
385 | Config->SMSC.Location = 1; | ||
386 | error = Phone->GetSMSC(&s,&Config->SMSC); | ||
387 | if (error!=ERR_NONE) { | ||
388 | WriteSMSDLog("Error getting SMSC from phone"); | ||
389 | return false; | ||
390 | } | ||
391 | |||
392 | } | ||
393 | memcpy(&sms.SMS[i].SMSC,&Config->SMSC,sizeof(GSM_SMSC)); | ||
394 | sms.SMS[i].SMSC.Location = 0; | ||
395 | if (Config->relativevalidity != -1) { | ||
396 | sms.SMS[i].SMSC.Validity.Format = SMS_Validity_RelativeFormat; | ||
397 | sms.SMS[i].SMSC.Validity.Relative = Config->relativevalidity; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | if (Config->currdeliveryreport == 1) { | ||
402 | sms.SMS[i].PDU = SMS_Status_Report; | ||
403 | } else { | ||
404 | if ((strcmp(Config->deliveryreport, "no") != 0 && (Config->currdeliveryreport == -1))) sms.SMS[i].PDU = SMS_Status_Report; | ||
405 | } | ||
406 | |||
360 | error=Phone->SendSMS(&s, &sms.SMS[i]); | 407 | error=Phone->SendSMS(&s, &sms.SMS[i]); |
361 | if (error!=ERR_NONE) { | 408 | if (error!=ERR_NONE) { |
409 | Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_SENDING_ERROR, -1); | ||
362 | WriteSMSDLog("Error sending SMS %s (%i): %s", Config->SMSID, error,print_error(error,s.di.df,s.msg)); | 410 | WriteSMSDLog("Error sending SMS %s (%i): %s", Config->SMSID, error,print_error(error,s.di.df,s.msg)); |
363 | return false; | 411 | return false; |
364 | } | 412 | } |
365 | j=0; | 413 | Service->RefreshPhoneStatus(Config); |
414 | j = 0; | ||
415 | TPMR = -1; | ||
366 | SendingSMSStatus = ERR_TIMEOUT; | 416 | SendingSMSStatus = ERR_TIMEOUT; |
367 | while (!gshutdown) { | 417 | while (!gshutdown) { |
368 | GSM_GetCurrentDateTime (&Date); | 418 | GSM_GetCurrentDateTime (&Date); |
369 | z=Date.Second; | 419 | z=Date.Second; |
@@ -372,25 +422,24 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
372 | GSM_GetCurrentDateTime(&Date); | 422 | GSM_GetCurrentDateTime(&Date); |
373 | GSM_ReadDevice(&s,true); | 423 | GSM_ReadDevice(&s,true); |
374 | if (SendingSMSStatus != ERR_TIMEOUT) break; | 424 | if (SendingSMSStatus != ERR_TIMEOUT) break; |
375 | } | 425 | } |
426 | Service->RefreshSendStatus(Config, Config->SMSID); | ||
427 | Service->RefreshPhoneStatus(Config); | ||
376 | if (SendingSMSStatus != ERR_TIMEOUT) break; | 428 | if (SendingSMSStatus != ERR_TIMEOUT) break; |
377 | j++; | 429 | j++; |
378 | if (j>Config->sendtimeout) break; | 430 | if (j>Config->sendtimeout) break; |
379 | } | 431 | } |
380 | if (SendingSMSStatus != ERR_NONE) { | 432 | if (SendingSMSStatus != ERR_NONE) { |
433 | Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_SENDING_ERROR, TPMR); | ||
381 | WriteSMSDLog("Error getting send status of %s (%i): %s", Config->SMSID, SendingSMSStatus,print_error(SendingSMSStatus,s.di.df,s.msg)); | 434 | WriteSMSDLog("Error getting send status of %s (%i): %s", Config->SMSID, SendingSMSStatus,print_error(SendingSMSStatus,s.di.df,s.msg)); |
382 | return false; | 435 | return false; |
383 | } | 436 | } |
384 | error = Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, true); | 437 | error = Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_OK, TPMR); |
385 | if (error!=ERR_NONE) { | 438 | if (error!=ERR_NONE) { |
386 | return false; | 439 | return false; |
387 | } | 440 | } |
388 | } | 441 | } |
389 | while ((int)i<sms.Number-1) { | ||
390 | Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); | ||
391 | i++; | ||
392 | } | ||
393 | strcpy(Config->prevSMSID, ""); | 442 | strcpy(Config->prevSMSID, ""); |
394 | if (Service->MoveSMS(&sms,Config, Config->SMSID, false, true) != ERR_NONE) { | 443 | if (Service->MoveSMS(&sms,Config, Config->SMSID, false, true) != ERR_NONE) { |
395 | Service->MoveSMS(&sms,Config, Config->SMSID, true, false); | 444 | Service->MoveSMS(&sms,Config, Config->SMSID, true, false); |
396 | } | 445 | } |
@@ -402,9 +451,9 @@ void SMSDaemon(int argc, char *argv[]) | |||
402 | { | 451 | { |
403 | int errors = 255, initerrors=0; | 452 | int errors = 255, initerrors=0; |
404 | GSM_SMSDService *Service; | 453 | GSM_SMSDService *Service; |
405 | GSM_Error error; | 454 | GSM_Error error; |
406 | time_t time1; | 455 | time_t lastreceive, lastreset = 0; |
407 | GSM_SMSDConfig Config; | 456 | GSM_SMSDConfig Config; |
408 | 457 | ||
409 | if (!strcmp(argv[2],"FILES")) { | 458 | if (!strcmp(argv[2],"FILES")) { |
410 | Service = &SMSDFiles; | 459 | Service = &SMSDFiles; |
@@ -416,9 +465,9 @@ void SMSDaemon(int argc, char *argv[]) | |||
416 | fprintf(stderr,"Unknown service type (\"%s\")\n",argv[2]); | 465 | fprintf(stderr,"Unknown service type (\"%s\")\n",argv[2]); |
417 | exit(-1); | 466 | exit(-1); |
418 | } | 467 | } |
419 | 468 | ||
420 | SMSD_ReadConfig(argv[3], &Config, true); | 469 | SMSD_ReadConfig(argv[3], &Config, true, argv[2]); |
421 | 470 | ||
422 | error = Service->Init(&Config); | 471 | error = Service->Init(&Config); |
423 | if (error!=ERR_NONE) { | 472 | if (error!=ERR_NONE) { |
424 | GSM_Terminate_SMSD("Stop GAMMU smsd (%i)", error, true, -1); | 473 | GSM_Terminate_SMSD("Stop GAMMU smsd (%i)", error, true, -1); |
@@ -427,9 +476,10 @@ void SMSDaemon(int argc, char *argv[]) | |||
427 | signal(SIGINT, interrupt); | 476 | signal(SIGINT, interrupt); |
428 | signal(SIGTERM, interrupt); | 477 | signal(SIGTERM, interrupt); |
429 | fprintf(stderr,"Press Ctrl+C to stop the program ...\n"); | 478 | fprintf(stderr,"Press Ctrl+C to stop the program ...\n"); |
430 | 479 | ||
431 | time1 = time(NULL); | 480 | lastreceive = time(NULL); |
481 | lastreset = time(NULL); | ||
432 | SendingSMSStatus = ERR_UNKNOWN; | 482 | SendingSMSStatus = ERR_UNKNOWN; |
433 | 483 | ||
434 | while (!gshutdown) { | 484 | while (!gshutdown) { |
435 | /* There were errors in communication - try to recover */ | 485 | /* There were errors in communication - try to recover */ |
@@ -444,9 +494,29 @@ void SMSDaemon(int argc, char *argv[]) | |||
444 | switch (error) { | 494 | switch (error) { |
445 | case ERR_NONE: | 495 | case ERR_NONE: |
446 | s.User.SendSMSStatus = SMSSendingSMSStatus; | 496 | s.User.SendSMSStatus = SMSSendingSMSStatus; |
447 | Phone = s.Phone.Functions; | 497 | Phone = s.Phone.Functions; |
448 | errors = 0; | 498 | if (errors == 255) { |
499 | errors = 0; | ||
500 | s.Phone.Data.IMEI[0] = 0; | ||
501 | if (!(Phone->GetIMEI(&s))) { | ||
502 | errors++; | ||
503 | } else { | ||
504 | error = Service->InitAfterConnect(&Config); | ||
505 | if (error!=ERR_NONE) { | ||
506 | GSM_Terminate_SMSD("Stop GAMMU smsd (%i)", error, true, -1); | ||
507 | } | ||
508 | Phone->SetFastSMSSending(&s,true); | ||
509 | } | ||
510 | } else { | ||
511 | errors = 0; | ||
512 | } | ||
513 | if (initerrors > 3 || initerrors < 0) { | ||
514 | error=Phone->Reset(&s, false); /* soft reset */ | ||
515 | WriteSMSDLog("Reset return code: %s (%i) ", error == ERR_NONE? "OK":"ERROR", error); | ||
516 | lastreset = time(NULL); | ||
517 | my_sleep(5000); | ||
518 | } | ||
449 | /* Marcin Wiacek: FIXME. To check */ | 519 | /* Marcin Wiacek: FIXME. To check */ |
450 | // di = s.di; | 520 | // di = s.di; |
451 | break; | 521 | break; |
452 | case ERR_DEVICEOPENERROR: | 522 | case ERR_DEVICEOPENERROR: |
@@ -456,10 +526,10 @@ void SMSDaemon(int argc, char *argv[]) | |||
456 | errors = 250; | 526 | errors = 250; |
457 | } | 527 | } |
458 | continue; | 528 | continue; |
459 | } | 529 | } |
460 | if ((difftime(time(NULL), time1) >= Config.receivefrequency) || (SendingSMSStatus != ERR_NONE)) { | 530 | if ((difftime(time(NULL), lastreceive) >= Config.receivefrequency) || (SendingSMSStatus != ERR_NONE)) { |
461 | time1 = time(NULL); | 531 | lastreceive = time(NULL); |
462 | 532 | ||
463 | if (!SMSD_CheckSecurity(&Config)) { | 533 | if (!SMSD_CheckSecurity(&Config)) { |
464 | errors++; | 534 | errors++; |
465 | initerrors++; | 535 | initerrors++; |
@@ -467,15 +537,21 @@ void SMSDaemon(int argc, char *argv[]) | |||
467 | } else errors=0; | 537 | } else errors=0; |
468 | 538 | ||
469 | initerrors = 0; | 539 | initerrors = 0; |
470 | 540 | ||
471 | if (!SMSD_CheckSMSStatus(&Config,Service)) { | 541 | if (!SMSD_CheckSMSStatus(&Config,Service)) { /* read all incoming SMS */ |
472 | errors++; | 542 | errors++; |
473 | continue; | 543 | continue; |
474 | } else errors=0; | 544 | } else errors=0; |
545 | |||
546 | if (Config.resetfrequency > 0 && difftime(time(NULL), lastreset) >= Config.resetfrequency) { /* time for preventive reset */ | ||
547 | errors = 254; initerrors = -2; | ||
548 | continue; | ||
549 | } | ||
475 | } | 550 | } |
476 | if (!SMSD_SendSMS(&Config,Service)) continue; | 551 | if (!SMSD_SendSMS(&Config,Service)) continue; |
477 | } | 552 | } |
553 | Phone->SetFastSMSSending(&s,false); | ||
478 | GSM_Terminate_SMSD("Stop GAMMU smsd", 0, false, 0); | 554 | GSM_Terminate_SMSD("Stop GAMMU smsd", 0, false, 0); |
479 | } | 555 | } |
480 | 556 | ||
481 | GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms) | 557 | GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms) |
@@ -493,9 +569,9 @@ GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *s | |||
493 | fprintf(stderr,"Unknown service type (\"%s\")\n",service); | 569 | fprintf(stderr,"Unknown service type (\"%s\")\n",service); |
494 | exit(-1); | 570 | exit(-1); |
495 | } | 571 | } |
496 | 572 | ||
497 | SMSD_ReadConfig(filename, &Config, false); | 573 | SMSD_ReadConfig(filename, &Config, false, service); |
498 | 574 | ||
499 | error = Service->Init(&Config); | 575 | error = Service->Init(&Config); |
500 | if (error!=ERR_NONE) return ERR_UNKNOWN; | 576 | if (error!=ERR_NONE) return ERR_UNKNOWN; |
501 | 577 | ||