Diffstat (limited to 'gammu/emb/gammu/smsd/smsdcore.c') (more/less context) (show whitespace changes)
-rw-r--r-- | gammu/emb/gammu/smsd/smsdcore.c | 130 |
1 files changed, 103 insertions, 27 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,2 +1,2 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek and Joergen Thomsen */ | 1 | /* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */ |
2 | 2 | ||
@@ -16,3 +16,5 @@ | |||
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) |
@@ -20,2 +22,3 @@ static void SMSSendingSMSStatus (char *Device, int status, int mr) | |||
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) { |
@@ -75,3 +78,3 @@ void WriteSMSDLog(char *format, ...) | |||
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 | { |
@@ -104,2 +107,3 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
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 | } |
@@ -114,11 +118,2 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
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); |
@@ -129,3 +124,6 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
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 | ||
@@ -137,2 +135,7 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
137 | 135 | ||
136 | Config->PhoneID = INI_GetValue(smsdcfgfile, "smsd", "phoneid", false); | ||
137 | if (Config->PhoneID == NULL) Config->PhoneID = ""; | ||
138 | if (log) WriteSMSDLog("phoneid = %s", Config->PhoneID); | ||
139 | |||
140 | if (!strcmp(service,"FILES")) { | ||
138 | Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false); | 141 | Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false); |
@@ -162,2 +165,18 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
162 | if (log) WriteSMSDLog("SMS with errors moved to \"%s\"",Config->errorsmspath); | 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 | ||
@@ -178,2 +197,4 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) | |||
178 | Config->prevSMSID[0] = 0; | 197 | Config->prevSMSID[0] = 0; |
198 | Config->SMSC.Location = 0; | ||
199 | Config->relativevalidity = -1; | ||
179 | } | 200 | } |
@@ -194,2 +215,3 @@ bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) | |||
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 */ |
@@ -328,2 +350,3 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
328 | } | 350 | } |
351 | Service->RefreshPhoneStatus(Config); | ||
329 | } | 352 | } |
@@ -335,3 +358,3 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
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 | } |
@@ -340,2 +363,3 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
340 | } | 363 | } |
364 | |||
341 | if (!gshutdown) { | 365 | if (!gshutdown) { |
@@ -348,3 +372,3 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
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 | } |
@@ -358,5 +382,29 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
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)); |
@@ -364,3 +412,5 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
364 | } | 412 | } |
413 | Service->RefreshPhoneStatus(Config); | ||
365 | j=0; | 414 | j=0; |
415 | TPMR = -1; | ||
366 | SendingSMSStatus = ERR_TIMEOUT; | 416 | SendingSMSStatus = ERR_TIMEOUT; |
@@ -375,2 +425,4 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
375 | } | 425 | } |
426 | Service->RefreshSendStatus(Config, Config->SMSID); | ||
427 | Service->RefreshPhoneStatus(Config); | ||
376 | if (SendingSMSStatus != ERR_TIMEOUT) break; | 428 | if (SendingSMSStatus != ERR_TIMEOUT) break; |
@@ -380,2 +432,3 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
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)); |
@@ -383,3 +436,3 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
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) { |
@@ -388,6 +441,2 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) | |||
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, ""); |
@@ -405,3 +454,3 @@ void SMSDaemon(int argc, char *argv[]) | |||
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; |
@@ -419,3 +468,3 @@ void SMSDaemon(int argc, char *argv[]) | |||
419 | 468 | ||
420 | SMSD_ReadConfig(argv[3], &Config, true); | 469 | SMSD_ReadConfig(argv[3], &Config, true, argv[2]); |
421 | 470 | ||
@@ -430,3 +479,4 @@ void SMSDaemon(int argc, char *argv[]) | |||
430 | 479 | ||
431 | time1 = time(NULL); | 480 | lastreceive = time(NULL); |
481 | lastreset = time(NULL); | ||
432 | SendingSMSStatus = ERR_UNKNOWN; | 482 | SendingSMSStatus = ERR_UNKNOWN; |
@@ -447,3 +497,23 @@ void SMSDaemon(int argc, char *argv[]) | |||
447 | Phone = s.Phone.Functions; | 497 | Phone = s.Phone.Functions; |
498 | if (errors == 255) { | ||
448 | errors = 0; | 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 */ |
@@ -459,4 +529,4 @@ void SMSDaemon(int argc, char *argv[]) | |||
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 | ||
@@ -470,3 +540,3 @@ void SMSDaemon(int argc, char *argv[]) | |||
470 | 540 | ||
471 | if (!SMSD_CheckSMSStatus(&Config,Service)) { | 541 | if (!SMSD_CheckSMSStatus(&Config,Service)) { /* read all incoming SMS */ |
472 | errors++; | 542 | errors++; |
@@ -474,2 +544,7 @@ void SMSDaemon(int argc, char *argv[]) | |||
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 | } |
@@ -477,2 +552,3 @@ void SMSDaemon(int argc, char *argv[]) | |||
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); |
@@ -496,3 +572,3 @@ GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *s | |||
496 | 572 | ||
497 | SMSD_ReadConfig(filename, &Config, false); | 573 | SMSD_ReadConfig(filename, &Config, false, service); |
498 | 574 | ||