summaryrefslogtreecommitdiffabout
path: root/gammu/emb/gammu
Unidiff
Diffstat (limited to 'gammu/emb/gammu') (more/less context) (show whitespace changes)
-rw-r--r--gammu/emb/gammu/depend/nokia/dct3.c6
-rw-r--r--gammu/emb/gammu/depend/nokia/dct4.c11
-rw-r--r--gammu/emb/gammu/depend/nokia/dct4.h13
-rw-r--r--gammu/emb/gammu/gammu.c626
-rw-r--r--gammu/emb/gammu/gammu.h8
-rw-r--r--gammu/emb/gammu/smsd/s_files.c81
-rw-r--r--gammu/emb/gammu/smsd/s_files.h2
-rw-r--r--gammu/emb/gammu/smsd/s_mysql.c572
-rw-r--r--gammu/emb/gammu/smsd/smsdcore.c130
-rw-r--r--gammu/emb/gammu/smsd/smsdcore.h27
10 files changed, 1023 insertions, 453 deletions
diff --git a/gammu/emb/gammu/depend/nokia/dct3.c b/gammu/emb/gammu/depend/nokia/dct3.c
index d4a55da..b9e47ea 100644
--- a/gammu/emb/gammu/depend/nokia/dct3.c
+++ b/gammu/emb/gammu/depend/nokia/dct3.c
@@ -607,16 +607,20 @@ static GSM_Error DCT3_Reply7191GetSecurityCode(GSM_Protocol_Message msg, GSM_Sta
607 printf("Security Code is \"%s\"\n",msg.Buffer+6); 607 printf("Security Code is \"%s\"\n",msg.Buffer+6);
608 return ERR_NONE; 608 return ERR_NONE;
609} 609}
610 610
611void DCT3GetSecurityCode(int argc, char *argv[]) 611void DCT3GetSecurityCode(int argc, char *argv[])
612{ 612{
613#ifdef GSM_ENABLE_NOKIA6110
613 unsigned char req6110[] = {0x00, 0x01, 0x6e, 614 unsigned char req6110[] = {0x00, 0x01, 0x6e,
614 0x01};/* Code type */ 615 0x01};/* Code type */
616#endif
617#if defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210)
615 unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee, 618 unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee,
616 0x1c};/* Setting */ 619 0x1c};/* Setting */
620#endif
617 621
618 if (CheckDCT3Only()!=ERR_NONE) return; 622 if (CheckDCT3Only()!=ERR_NONE) return;
619 623
620 error=DCT3_EnableSecurity (&s, 0x01); 624 error=DCT3_EnableSecurity (&s, 0x01);
621 Print_Error(error); 625 Print_Error(error);
622 626
@@ -764,14 +768,16 @@ void DCT3DisplayOutput(int argc, char *argv[])
764 768
765 GSM_Terminate(); 769 GSM_Terminate();
766} 770}
767#endif 771#endif
768 772
769static GSM_Reply_Function UserReplyFunctions3[] = { 773static GSM_Reply_Function UserReplyFunctions3[] = {
774#ifdef GSM_ENABLE_NOKIA6110
770 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame}, 775 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame},
771 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 }, 776 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 },
777#endif
772 778
773 {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity}, 779 {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity},
774 {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 }, 780 {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 },
775 {DCT3_ReplyGetADC, "\x40",0x02,0x68,ID_User3 }, 781 {DCT3_ReplyGetADC, "\x40",0x02,0x68,ID_User3 },
776 {DCT3_ReplyGetPPS, "\x40",0x02,0x6A,ID_User4 }, 782 {DCT3_ReplyGetPPS, "\x40",0x02,0x6A,ID_User4 },
777 {DCT3_ReplySetPPS, "\x40",0x02,0x6B,ID_User4 }, 783 {DCT3_ReplySetPPS, "\x40",0x02,0x6B,ID_User4 },
diff --git a/gammu/emb/gammu/depend/nokia/dct4.c b/gammu/emb/gammu/depend/nokia/dct4.c
index f4ed305..4bf958d 100644
--- a/gammu/emb/gammu/depend/nokia/dct4.c
+++ b/gammu/emb/gammu/depend/nokia/dct4.c
@@ -32,13 +32,14 @@ GSM_Error CheckDCT4Only()
32 if (strstr(N3320Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; 32 if (strstr(N3320Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true;
33#endif 33#endif
34 if (!found) return ERR_NOTSUPPORTED; 34 if (!found) return ERR_NOTSUPPORTED;
35 35
36 if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 && 36 if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 &&
37 s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_PHONETBLUE && 37 s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_PHONETBLUE &&
38 s.ConnectionType!=GCT_IRDAPHONET && s.ConnectionType!=GCT_BLUEPHONET) { 38 s.ConnectionType!=GCT_IRDAPHONET && s.ConnectionType!=GCT_BLUEPHONET &&
39 s.ConnectionType!=GCT_FBUS2DKU5) {
39 return ERR_OTHERCONNECTIONREQUIRED; 40 return ERR_OTHERCONNECTIONREQUIRED;
40 } 41 }
41 return ERR_NONE; 42 return ERR_NONE;
42} 43}
43 44
44static void CheckDCT4() 45static void CheckDCT4()
@@ -882,12 +883,14 @@ void DCT4GetT9(int argc, char *argv[])
882 i+=T9Size; 883 i+=T9Size;
883 } 884 }
884 885
885 fclose(T9File); 886 fclose(T9File);
886} 887}
887 888
889#ifdef GSM_ENABLE_NOKIA6510
890
888extern GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, bool enable); 891extern GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, bool enable);
889 892
890void DCT4SetLight(int argc, char *argv[]) 893void DCT4SetLight(int argc, char *argv[])
891{ 894{
892 int i; 895 int i;
893 N6510_PHONE_LIGHTS type; 896 N6510_PHONE_LIGHTS type;
@@ -918,12 +921,13 @@ void DCT4SetLight(int argc, char *argv[])
918 921
919 error=N6510_SetLight(&s, type, enable); 922 error=N6510_SetLight(&s, type, enable);
920 Print_Error(error); 923 Print_Error(error);
921 924
922 GSM_Terminate(); 925 GSM_Terminate();
923} 926}
927#endif
924 928
925void DCT4DisplayTest(int argc, char *argv[]) 929void DCT4DisplayTest(int argc, char *argv[])
926{ 930{
927 unsigned char ans[200]; 931 unsigned char ans[200];
928 unsigned char req0[] = {0x00, 0x08, 0x0D, 0x00, 0x0F, 0x00}; 932 unsigned char req0[] = {0x00, 0x08, 0x0D, 0x00, 0x0F, 0x00};
929 unsigned char req[] = {0x00, 0x08, 0x0E, 0x00, 0x12, 0x01, 0x00, 0x04, 933 unsigned char req[] = {0x00, 0x08, 0x0E, 0x00, 0x12, 0x01, 0x00, 0x04,
@@ -1018,12 +1022,14 @@ void DCT4GetADC(int argc, char *argv[])
1018 printf("%s\n",DCT4ADC[i].unit); 1022 printf("%s\n",DCT4ADC[i].unit);
1019 i++; 1023 i++;
1020 if (DCT4ADC[i].name[0] == 0x00) break; 1024 if (DCT4ADC[i].name[0] == 0x00) break;
1021 } 1025 }
1022} 1026}
1023 1027
1028#ifdef GSM_ENABLE_NOKIA6510
1029
1024 static double RadioFreq; 1030 static double RadioFreq;
1025 static unsigned char RadioName[100]; 1031 static unsigned char RadioName[100];
1026 1032
1027static GSM_Error DCT4_ReplyTuneRadio(GSM_Protocol_Message msg, GSM_StateMachine *s) 1033static GSM_Error DCT4_ReplyTuneRadio(GSM_Protocol_Message msg, GSM_StateMachine *s)
1028{ 1034{
1029 int length; 1035 int length;
@@ -1171,12 +1177,13 @@ void DCT4TuneRadio(int argc, char *argv[])
1171 1177
1172 error=GSM_WaitFor (&s, Disable, 6, 0x3E, 4, ID_User3); 1178 error=GSM_WaitFor (&s, Disable, 6, 0x3E, 4, ID_User3);
1173 Print_Error(error); 1179 Print_Error(error);
1174 1180
1175 GSM_Terminate(); 1181 GSM_Terminate();
1176} 1182}
1183#endif
1177 1184
1178void DCT4PlaySavedRingtone(int argc, char *argv[]) 1185void DCT4PlaySavedRingtone(int argc, char *argv[])
1179{ 1186{
1180 unsigned char req[] = {N6110_FRAME_HEADER, 1187 unsigned char req[] = {N6110_FRAME_HEADER,
1181 0x01, 1188 0x01,
1182 0x00,0x64,//id 1189 0x00,0x64,//id
@@ -1310,16 +1317,18 @@ static GSM_Reply_Function UserReplyFunctions4[] = {
1310 1317
1311 {DCT4_ReplyTestsStartup, "\x35",0x02,0x01,ID_User3}, 1318 {DCT4_ReplyTestsStartup, "\x35",0x02,0x01,ID_User3},
1312 {DCT4_ReplyTestsStartup, "\x35",0x02,0x02,ID_User3}, 1319 {DCT4_ReplyTestsStartup, "\x35",0x02,0x02,ID_User3},
1313 {DCT4_ReplyTestsNames, "\x35",0x02,0x03,ID_User1}, 1320 {DCT4_ReplyTestsNames, "\x35",0x02,0x03,ID_User1},
1314 {DCT4_ReplyTestsStatus, "\x35",0x02,0x04,ID_User2}, 1321 {DCT4_ReplyTestsStatus, "\x35",0x02,0x04,ID_User2},
1315 1322
1323#ifdef GSM_ENABLE_NOKIA6510
1316 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x09,ID_User3}, 1324 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x09,ID_User3},
1317 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_User3}, 1325 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_User3},
1318 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_SetFMStation}, 1326 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_SetFMStation},
1319 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x16,ID_User3}, 1327 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x16,ID_User3},
1328#endif
1320 1329
1321 {DCT4_ReplyGetVoiceRecord, "\x4A",0x03,0x31,ID_User4}, 1330 {DCT4_ReplyGetVoiceRecord, "\x4A",0x03,0x31,ID_User4},
1322 1331
1323 {DCT4_ReplyGetSimlock, "\x53",0x03,0x0D,ID_User6}, 1332 {DCT4_ReplyGetSimlock, "\x53",0x03,0x0D,ID_User6},
1324 {DCT4_ReplyGetSimlock, "\x53",0x03,0x13,ID_User6}, 1333 {DCT4_ReplyGetSimlock, "\x53",0x03,0x13,ID_User6},
1325 1334
diff --git a/gammu/emb/gammu/depend/nokia/dct4.h b/gammu/emb/gammu/depend/nokia/dct4.h
index fde5b08..fae809f 100644
--- a/gammu/emb/gammu/depend/nokia/dct4.h
+++ b/gammu/emb/gammu/depend/nokia/dct4.h
@@ -3,27 +3,30 @@
3#include "../../../common/gsmstate.h" 3#include "../../../common/gsmstate.h"
4 4
5 void DCT4SetPhoneMenus (int argc, char *argv[]); 5 void DCT4SetPhoneMenus (int argc, char *argv[]);
6 void DCT4SelfTests (int argc, char *argv[]); 6 void DCT4SelfTests (int argc, char *argv[]);
7 void DCT4SetVibraLevel (int argc, char *argv[]); 7 void DCT4SetVibraLevel (int argc, char *argv[]);
8void DCT4GetSecurityCode (int argc, char *argv[]); 8void DCT4GetSecurityCode (int argc, char *argv[]);
9#ifdef DEBUG
10void DCT4ResetSecurityCode (int argc, char *argv[]);
11#endif
12 void DCT4GetVoiceRecord (int argc, char *argv[]); 9 void DCT4GetVoiceRecord (int argc, char *argv[]);
13 void DCT4Info (int argc, char *argv[]); 10 void DCT4Info (int argc, char *argv[]);
14 void DCT4GetT9 (int argc, char *argv[]); 11 void DCT4GetT9 (int argc, char *argv[]);
15 void DCT4SetLight (int argc, char *argv[]);
16 void DCT4DisplayTest (int argc, char *argv[]); 12 void DCT4DisplayTest (int argc, char *argv[]);
17 void DCT4GetADC (int argc, char *argv[]); 13 void DCT4GetADC (int argc, char *argv[]);
18 void DCT4VibraTest (int argc, char *argv[]); 14 void DCT4VibraTest (int argc, char *argv[]);
19 void DCT4TuneRadio (int argc, char *argv[]);
20void DCT4PlaySavedRingtone (int argc, char *argv[]); 15void DCT4PlaySavedRingtone (int argc, char *argv[]);
21void DCT4MakeCameraShoot (int argc, char *argv[]); 16void DCT4MakeCameraShoot (int argc, char *argv[]);
22 void DCT4GetScreenDump (int argc, char *argv[]); 17 void DCT4GetScreenDump (int argc, char *argv[]);
23 18
19#ifdef DEBUG
20 void DCT4ResetSecurityCode (int argc, char *argv[]);
21#endif
22#ifdef GSM_ENABLE_NOKIA6510
23 void DCT4SetLight (int argc, char *argv[]);
24 void DCT4TuneRadio (int argc, char *argv[]);
25#endif
26
24/* ------------------- features matrix ------------------------------------- */ 27/* ------------------- features matrix ------------------------------------- */
25 28
26typedef enum { 29typedef enum {
27 DCT4_ALWAYS_ONLINE = 1, 30 DCT4_ALWAYS_ONLINE = 1,
28 DCT4_GPRS_PCCH, 31 DCT4_GPRS_PCCH,
29 DCT4_GEA1, 32 DCT4_GEA1,
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c
index 997485a..f49ae36 100644
--- a/gammu/emb/gammu/gammu.c
+++ b/gammu/emb/gammu/gammu.c
@@ -6,13 +6,12 @@
6#include <stdlib.h> 6#include <stdlib.h>
7#include <stdarg.h> 7#include <stdarg.h>
8#include <locale.h> 8#include <locale.h>
9#include <signal.h> 9#include <signal.h>
10#include <ctype.h> 10#include <ctype.h>
11#include <wchar.h> 11#include <wchar.h>
12#undef HAVE_MYSQL_MYSQL_H
13#ifdef WIN32 12#ifdef WIN32
14# include <windows.h> 13# include <windows.h>
15# include <process.h> 14# include <process.h>
16# ifdef _MSC_VER 15# ifdef _MSC_VER
17# include <sys/utime.h> 16# include <sys/utime.h>
18# else 17# else
@@ -45,33 +44,21 @@
45 44
46#ifdef HAVE_SYS_IOCTL_H 45#ifdef HAVE_SYS_IOCTL_H
47# include <sys/ioctl.h> 46# include <sys/ioctl.h>
48#endif 47#endif
49 48
50 49
51 //static GSM_StateMachine s; 50 GSM_StateMachine s;
52 //static GSM_Phone_Functions *Phone; 51 GSM_Phone_Functions *Phone;
53 static INI_Section *cfg = NULL; 52 static INI_Section *cfg = NULL;
54 53
55 //static GSM_Error error = ERR_NONE; 54 GSM_Error error = ERR_NONE;
56 static int i; 55 static int i;
57 56
58 //static bool gshutdown = false; 57 volatile bool gshutdown = false;
59typedef struct {
60 unsigned char Connection[50];
61} OneConnectionInfo;
62
63typedef struct {
64 unsigned char Device[50];
65 OneConnectionInfo Connections[6];
66 //GSM_StateMachines;
67} OneDeviceInfo;
68 58
69 static int num;
70 static OneDeviceInfo SearchDevices[100];
71 static bool SearchOutput;
72void interrupt(int sign) 59void interrupt(int sign)
73{ 60{
74 signal(sign, SIG_IGN); 61 signal(sign, SIG_IGN);
75 gshutdown = true; 62 gshutdown = true;
76} 63}
77 64
@@ -240,12 +227,13 @@ static GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone)
240 first = false; 227 first = false;
241 } 228 }
242 229
243 /* Disables buzzer */ 230 /* Disables buzzer */
244 return s.Phone.Functions->PlayTone(&s,255*255,0,false); 231 return s.Phone.Functions->PlayTone(&s,255*255,0,false);
245} 232}
233
246static void PlayRingtone(int argc, char *argv[]) 234static void PlayRingtone(int argc, char *argv[])
247{ 235{
248 GSM_Ringtone ringtone,ringtone2; 236 GSM_Ringtone ringtone,ringtone2;
249 237
250 ringtone.Format= 0; 238 ringtone.Format= 0;
251 error=GSM_ReadRingtoneFile(argv[2],&ringtone); 239 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
@@ -338,13 +326,12 @@ static void Identify(int argc, char *argv[])
338 DCT4Info(argc, argv); 326 DCT4Info(argc, argv);
339#endif 327#endif
340 328
341 GSM_Terminate(); 329 GSM_Terminate();
342} 330}
343 331
344//#if 0
345static void GetDateTime(int argc, char *argv[]) 332static void GetDateTime(int argc, char *argv[])
346{ 333{
347 GSM_DateTime date_time; 334 GSM_DateTime date_time;
348 GSM_Localelocale; 335 GSM_Localelocale;
349 336
350 GSM_Init(true); 337 GSM_Init(true);
@@ -372,12 +359,13 @@ static void GetDateTime(int argc, char *argv[])
372 if (locale.AMPMTime) printmsg("12 hours\n"); else printmsg("24 hours\n"); 359 if (locale.AMPMTime) printmsg("12 hours\n"); else printmsg("24 hours\n");
373 printmsg("Date format is "); 360 printmsg("Date format is ");
374 switch (locale.DateFormat) { 361 switch (locale.DateFormat) {
375 case GSM_Date_DDMMYYYY:printmsg("DD MM YYYY");break; 362 case GSM_Date_DDMMYYYY:printmsg("DD MM YYYY");break;
376 case GSM_Date_MMDDYYYY:printmsg("MM DD YYYY");break; 363 case GSM_Date_MMDDYYYY:printmsg("MM DD YYYY");break;
377 case GSM_Date_YYYYMMDD:printmsg("YYYY MM DD"); 364 case GSM_Date_YYYYMMDD:printmsg("YYYY MM DD");
365 default :break;
378 } 366 }
379 printmsg(", date separator is %c\n",locale.DateSeparator); 367 printmsg(", date separator is %c\n",locale.DateSeparator);
380 } 368 }
381 369
382 GSM_Terminate(); 370 GSM_Terminate();
383} 371}
@@ -584,14 +572,15 @@ static void GetAllMemory(int argc, char *argv[])
584 572
585 GSM_Terminate(); 573 GSM_Terminate();
586} 574}
587 575
588static void GetMemory(int argc, char *argv[]) 576static void GetMemory(int argc, char *argv[])
589{ 577{
590 int j, start, stop; 578 int j, start, stop, emptynum = 0, fillednum = 0;
591 GSM_MemoryEntry entry; 579 GSM_MemoryEntry entry;
580 bool empty = true;
592 581
593 entry.MemoryType=0; 582 entry.MemoryType=0;
594 583
595 if (mystrncasecmp(argv[2],"DC",0)) entry.MemoryType=MEM_DC; 584 if (mystrncasecmp(argv[2],"DC",0)) entry.MemoryType=MEM_DC;
596 if (mystrncasecmp(argv[2],"ON",0)) entry.MemoryType=MEM_ON; 585 if (mystrncasecmp(argv[2],"ON",0)) entry.MemoryType=MEM_ON;
597 if (mystrncasecmp(argv[2],"RC",0)) entry.MemoryType=MEM_RC; 586 if (mystrncasecmp(argv[2],"RC",0)) entry.MemoryType=MEM_RC;
@@ -604,34 +593,50 @@ static void GetMemory(int argc, char *argv[])
604 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]); 593 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]);
605 exit (-1); 594 exit (-1);
606 } 595 }
607 596
608 GetStartStop(&start, &stop, 3, argc, argv); 597 GetStartStop(&start, &stop, 3, argc, argv);
609 598
599 if (argc > 5 && strcmp(argv[5],"")) {
600 if (mystrncasecmp(argv[5],"-nonempty",0)) {
601 empty = false;
602 } else {
603 printmsg("ERROR: unknown parameter \"%s\"\n",argv[5]);
604 exit (-1);
605 }
606 }
607
610 GSM_Init(true); 608 GSM_Init(true);
611 609
612 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310")) { 610 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310")) {
613 if (s.Phone.Data.VerNum<=4.06) printmsg("WARNING: you will have null names in entries. Upgrade firmware in phone to higher than 4.06\n"); 611 if (s.Phone.Data.VerNum<=4.06) printmsg("WARNING: you will have null names in entries. Upgrade firmware in phone to higher than 4.06\n");
614 } 612 }
615 613
616 for (j=start;j<=stop;j++) { 614 for (j=start;j<=stop;j++) {
617 printmsg("Memory %s, Location %i\n",argv[2],j); 615 if (empty) printmsg("Memory %s, Location %i\n",argv[2],j);
618 616
619 entry.Location=j; 617 entry.Location=j;
620 618
621 error=Phone->GetMemory(&s, &entry); 619 error=Phone->GetMemory(&s, &entry);
622 if (error != ERR_EMPTY) Print_Error(error); 620 if (error != ERR_EMPTY) Print_Error(error);
623 621
624 if (error == ERR_EMPTY) { 622 if (error == ERR_EMPTY) {
623 emptynum++;
624 if (empty) {
625 printmsg("Entry is empty\n"); 625 printmsg("Entry is empty\n");
626 printf("\n"); 626 printf("\n");
627 }
627 } else { 628 } else {
629 fillednum++;
630 if (!empty) printmsg("Memory %s, Location %i\n",argv[2],j);
628 PrintMemoryEntry(&entry); 631 PrintMemoryEntry(&entry);
629 } 632 }
630 } 633 }
631 634
635 printmsg("%i entries empty, %i entries filled\n",emptynum,fillednum);
636
632 GSM_Terminate(); 637 GSM_Terminate();
633} 638}
634 639
635#define MemoryLocationToString(x) ( \ 640#define MemoryLocationToString(x) ( \
636 x == MEM_ON ? "ON" : \ 641 x == MEM_ON ? "ON" : \
637 x == MEM_RC ? "RC" : \ 642 x == MEM_RC ? "RC" : \
@@ -671,13 +676,13 @@ static void SearchOneEntry(GSM_MemoryEntry *Entry, unsigned char *Text)
671 case PBK_Text_Country : 676 case PBK_Text_Country :
672 case PBK_Text_Custom1 : 677 case PBK_Text_Custom1 :
673 case PBK_Text_Custom2 : 678 case PBK_Text_Custom2 :
674 case PBK_Text_Custom3 : 679 case PBK_Text_Custom3 :
675 case PBK_Text_Custom4 : 680 case PBK_Text_Custom4 :
676 case PBK_Caller_Group : 681 case PBK_Caller_Group :
677 if (mystrstr(Entry->Entries[i].Text, Text) != NULL) { 682 if (mywstrstr(Entry->Entries[i].Text, Text) != NULL) {
678 fprintf(stderr,"\n"); 683 fprintf(stderr,"\n");
679 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry->MemoryType),Entry->Location); 684 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry->MemoryType),Entry->Location);
680 PrintMemoryEntry(Entry); 685 PrintMemoryEntry(Entry);
681 return; 686 return;
682 } 687 }
683 break; 688 break;
@@ -821,13 +826,13 @@ static void ListMemoryCategory(int argc, char *argv[])
821 for (count=0,j=1;count<Status.Used;j++) { 826 for (count=0,j=1;count<Status.Used;j++) {
822 Category.Location=j; 827 Category.Location=j;
823 error=Phone->GetCategory(&s, &Category); 828 error=Phone->GetCategory(&s, &Category);
824 829
825 if (error != ERR_EMPTY) { 830 if (error != ERR_EMPTY) {
826 count++; 831 count++;
827 if (mystrstr(Category.Name, Text) != NULL) { 832 if (mywstrstr(Category.Name, Text) != NULL) {
828 ListMemoryCategoryEntries(j); 833 ListMemoryCategoryEntries(j);
829 } 834 }
830 } 835 }
831 } 836 }
832 } 837 }
833 } 838 }
@@ -844,13 +849,13 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp
844 case SMS_Sent : printmsg("Sent");break; 849 case SMS_Sent : printmsg("Sent");break;
845 case SMS_Read : printmsg("Read");break; 850 case SMS_Read : printmsg("Read");break;
846 case SMS_UnRead : printmsg("UnRead");break; 851 case SMS_UnRead : printmsg("UnRead");break;
847 case SMS_UnSent : printmsg("UnSent");break; 852 case SMS_UnSent : printmsg("UnSent");break;
848 } 853 }
849 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number)); 854 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
850 printmsg("Reference number: 0x%02X\n",sms.MessageReference); 855 printmsg("Reference number: %d\n",sms.MessageReference);
851 printmsg("Sent : %s\n",OSDateTime(sms.DateTime,true)); 856 printmsg("Sent : %s\n",OSDateTime(sms.DateTime,true));
852 printmsg("SMSC number : \"%s\"\n",DecodeUnicodeConsole(sms.SMSC.Number)); 857 printmsg("SMSC number : \"%s\"\n",DecodeUnicodeConsole(sms.SMSC.Number));
853 printmsg("SMSC response : %s\n",OSDateTime(sms.SMSCTime,true)); 858 printmsg("SMSC response : %s\n",OSDateTime(sms.SMSCTime,true));
854 printmsg("Delivery status : %s\n",DecodeUnicodeConsole(sms.Text)); 859 printmsg("Delivery status : %s\n",DecodeUnicodeConsole(sms.Text));
855 printmsg("Details : "); 860 printmsg("Details : ");
856 if (sms.DeliveryStatus & 0x40) { 861 if (sms.DeliveryStatus & 0x40) {
@@ -891,25 +896,32 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp
891 default : printmsg("Reserved/Specific to SC: %x",sms.DeliveryStatus);break; 896 default : printmsg("Reserved/Specific to SC: %x",sms.DeliveryStatus);break;
892 } 897 }
893 printf("\n"); 898 printf("\n");
894 break; 899 break;
895 case SMS_Deliver: 900 case SMS_Deliver:
896 printmsg("SMS message\n"); 901 printmsg("SMS message\n");
902 if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) {
903 printmsg("Saved : %s\n",OSDateTime(sms.DateTime,true));
904 } else {
897 printmsg("SMSC number : \"%s\"",DecodeUnicodeConsole(sms.SMSC.Number)); 905 printmsg("SMSC number : \"%s\"",DecodeUnicodeConsole(sms.SMSC.Number));
898 if (sms.ReplyViaSameSMSC) printmsg(" (set for reply)"); 906 if (sms.ReplyViaSameSMSC) printmsg(" (set for reply)");
899 printmsg("\nSent : %s\n",OSDateTime(sms.DateTime,true)); 907 printmsg("\nSent : %s\n",OSDateTime(sms.DateTime,true));
908 }
900 /* No break. The only difference for SMS_Deliver and SMS_Submit is, 909 /* No break. The only difference for SMS_Deliver and SMS_Submit is,
901 * that SMS_Deliver contains additional data. We wrote them and then go 910 * that SMS_Deliver contains additional data. We wrote them and then go
902 * for data shared with SMS_Submit 911 * for data shared with SMS_Submit
903 */ 912 */
904 case SMS_Submit: 913 case SMS_Submit:
905 if (sms.ReplaceMessage != 0) printmsg("SMS replacing ID : %i\n",sms.ReplaceMessage); 914 if (sms.ReplaceMessage != 0) printmsg("SMS replacing ID : %i\n",sms.ReplaceMessage);
906 /* If we went here from "case SMS_Deliver", we don't write "SMS Message" */ 915 /* If we went here from "case SMS_Deliver", we don't write "SMS Message" */
907 if (sms.PDU==SMS_Submit) { 916 if (sms.PDU==SMS_Submit) {
908 printmsg("SMS message\n"); 917 printmsg("SMS message\n");
909 printmsg("Reference number : 0x%02X\n",sms.MessageReference); 918 if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) {
919 } else {
920 printmsg("Reference number : %d\n",sms.MessageReference);
921 }
910 } 922 }
911 if (sms.Name[0] != 0x00 || sms.Name[1] != 0x00) { 923 if (sms.Name[0] != 0x00 || sms.Name[1] != 0x00) {
912 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(sms.Name)); 924 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(sms.Name));
913 } 925 }
914 if (sms.Class != -1) { 926 if (sms.Class != -1) {
915 printmsg("Class : %i\n",sms.Class); 927 printmsg("Class : %i\n",sms.Class);
@@ -917,20 +929,23 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp
917 printmsg("Coding : "); 929 printmsg("Coding : ");
918 switch (sms.Coding) { 930 switch (sms.Coding) {
919 case SMS_Coding_Unicode : printmsg("Unicode\n"); break; 931 case SMS_Coding_Unicode : printmsg("Unicode\n"); break;
920 case SMS_Coding_Default : printmsg("Default GSM alphabet\n");break; 932 case SMS_Coding_Default : printmsg("Default GSM alphabet\n");break;
921 case SMS_Coding_8bit : printmsg("8 bit\n"); break; 933 case SMS_Coding_8bit : printmsg("8 bit\n"); break;
922 } 934 }
935 if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) {
936 } else {
937 printmsg("Remote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
938 }
923 printmsg("Status : "); 939 printmsg("Status : ");
924 switch (sms.State) { 940 switch (sms.State) {
925 case SMS_Sent : printmsg("Sent");break; 941 case SMS_Sent : printmsg("Sent\n");break;
926 case SMS_Read : printmsg("Read");break; 942 case SMS_Read : printmsg("Read\n");break;
927 case SMS_UnRead : printmsg("UnRead");break; 943 case SMS_UnRead : printmsg("UnRead\n");break;
928 case SMS_UnSent : printmsg("UnSent");break; 944 case SMS_UnSent : printmsg("UnSent\n");break;
929 } 945 }
930 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
931 if (sms.UDH.Type != UDH_NoUDH) { 946 if (sms.UDH.Type != UDH_NoUDH) {
932 printmsg("User Data Header : "); 947 printmsg("User Data Header : ");
933 switch (sms.UDH.Type) { 948 switch (sms.UDH.Type) {
934 case UDH_ConcatenatedMessages : printmsg("Concatenated (linked) message"); break; 949 case UDH_ConcatenatedMessages : printmsg("Concatenated (linked) message"); break;
935 case UDH_ConcatenatedMessages16bit : printmsg("Concatenated (linked) message"); break; 950 case UDH_ConcatenatedMessages16bit : printmsg("Concatenated (linked) message"); break;
936 case UDH_DisableVoice : printmsg("Disables voice indicator"); break; 951 case UDH_DisableVoice : printmsg("Disables voice indicator"); break;
@@ -975,13 +990,13 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp
975 printmsg("8 bit SMS, cannot be displayed here\n"); 990 printmsg("8 bit SMS, cannot be displayed here\n");
976 } 991 }
977 } 992 }
978 break; 993 break;
979 } 994 }
980} 995}
981//#if 0 996
982static void displaymultismsinfo (GSM_MultiSMSMessage sms, bool eachsms, bool ems) 997static void displaymultismsinfo (GSM_MultiSMSMessage sms, bool eachsms, bool ems)
983{ 998{
984 GSM_MultiPartSMSInfoSMSInfo; 999 GSM_MultiPartSMSInfoSMSInfo;
985 bool RetVal,udhinfo=true; 1000 bool RetVal,udhinfo=true;
986 int j; 1001 int j;
987 1002
@@ -1282,20 +1297,27 @@ static void Monitor(int argc, char *argv[])
1282 1297
1283 printmsg("Leaving monitor mode...\n"); 1298 printmsg("Leaving monitor mode...\n");
1284 1299
1285 GSM_Terminate(); 1300 GSM_Terminate();
1286} 1301}
1287 1302
1303static void IncomingUSSD2(char *Device, char *Buffer)
1304{
1305 printmsg("Service reply: \"%s\"\n",DecodeUnicodeConsole(Buffer));
1306
1307 gshutdown = true;
1308}
1309
1288static void GetUSSD(int argc, char *argv[]) 1310static void GetUSSD(int argc, char *argv[])
1289{ 1311{
1290 GSM_Init(true); 1312 GSM_Init(true);
1291 1313
1292 signal(SIGINT, interrupt); 1314 signal(SIGINT, interrupt);
1293 printmsgerr("Press Ctrl+C to break...\n"); 1315 printmsgerr("Press Ctrl+C to break...\n");
1294 1316
1295 s.User.IncomingUSSD = IncomingUSSD; 1317 s.User.IncomingUSSD = IncomingUSSD2;
1296 1318
1297 error=Phone->SetIncomingUSSD(&s,true); 1319 error=Phone->SetIncomingUSSD(&s,true);
1298 Print_Error(error); 1320 Print_Error(error);
1299 1321
1300 error=Phone->DialVoice(&s, argv[2], GSM_CALL_DefaultNumberPresence); 1322 error=Phone->DialVoice(&s, argv[2], GSM_CALL_DefaultNumberPresence);
1301 Print_Error(error); 1323 Print_Error(error);
@@ -1342,13 +1364,22 @@ static void GetSMSC(int argc, char *argv[])
1342 case SMS_VALID_1_Hour : printmsg("1 hour"); break; 1364 case SMS_VALID_1_Hour : printmsg("1 hour"); break;
1343 case SMS_VALID_6_Hours : printmsg("6 hours"); break; 1365 case SMS_VALID_6_Hours : printmsg("6 hours"); break;
1344 case SMS_VALID_1_Day : printmsg("24 hours"); break; 1366 case SMS_VALID_1_Day : printmsg("24 hours"); break;
1345 case SMS_VALID_3_Days : printmsg("72 hours"); break; 1367 case SMS_VALID_3_Days : printmsg("72 hours"); break;
1346 case SMS_VALID_1_Week : printmsg("1 week"); break; 1368 case SMS_VALID_1_Week : printmsg("1 week"); break;
1347 case SMS_VALID_Max_Time: printmsg("Maximum time"); break; 1369 case SMS_VALID_Max_Time: printmsg("Maximum time"); break;
1348 default : printmsg("Unknown"); 1370 default :
1371 if (smsc.Validity.Relative >= 0 && smsc.Validity.Relative <= 143) {
1372 printmsg("%i minutes",(smsc.Validity.Relative+1)*5);
1373 } else if (smsc.Validity.Relative >= 144 && smsc.Validity.Relative <= 167) {
1374 printmsg("%i minutes",12*60 + (smsc.Validity.Relative-143)*30);
1375 } else if (smsc.Validity.Relative >= 168 && smsc.Validity.Relative <= 196) {
1376 printmsg("%i days",smsc.Validity.Relative-166);
1377 } else if (smsc.Validity.Relative >= 197 && smsc.Validity.Relative <= 255) {
1378 printmsg("%i weeks",smsc.Validity.Relative-192);
1379 }
1349 } 1380 }
1350 printf("\n"); 1381 printf("\n");
1351 } 1382 }
1352 1383
1353 GSM_Terminate(); 1384 GSM_Terminate();
1354} 1385}
@@ -1425,13 +1456,12 @@ static void GetAllSMS(int argc, char *argv[])
1425 1456
1426 GSM_Init(true); 1457 GSM_Init(true);
1427 1458
1428 error=Phone->GetSMSFolders(&s, &folders); 1459 error=Phone->GetSMSFolders(&s, &folders);
1429 Print_Error(error); 1460 Print_Error(error);
1430 1461
1431 fprintf(stderr,"Reading: ");
1432 while (error == ERR_NONE) { 1462 while (error == ERR_NONE) {
1433 sms.SMS[0].Folder=0x00; 1463 sms.SMS[0].Folder=0x00;
1434 error=Phone->GetNextSMS(&s, &sms, start); 1464 error=Phone->GetNextSMS(&s, &sms, start);
1435 switch (error) { 1465 switch (error) {
1436 case ERR_EMPTY: 1466 case ERR_EMPTY:
1437 break; 1467 break;
@@ -1445,13 +1475,12 @@ static void GetAllSMS(int argc, char *argv[])
1445 default : break; 1475 default : break;
1446 } 1476 }
1447 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder"); 1477 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder");
1448 printf("\n"); 1478 printf("\n");
1449 displaymultismsinfo(sms,false,false); 1479 displaymultismsinfo(sms,false,false);
1450 } 1480 }
1451 fprintf(stderr,"*");
1452 start=false; 1481 start=false;
1453 } 1482 }
1454 fprintf(stderr,"\n"); 1483 fprintf(stderr,"\n");
1455 1484
1456#ifdef GSM_ENABLE_BEEP 1485#ifdef GSM_ENABLE_BEEP
1457 GSM_PhoneBeep(); 1486 GSM_PhoneBeep();
@@ -1576,13 +1605,14 @@ static void GetRingtone(int argc, char *argv[])
1576 error=Phone->GetRingtone(&s,&ringtone,PhoneRingtone); 1605 error=Phone->GetRingtone(&s,&ringtone,PhoneRingtone);
1577 Print_Error(error); 1606 Print_Error(error);
1578 1607
1579 switch (ringtone.Format) { 1608 switch (ringtone.Format) {
1580 case RING_NOTETONE : printmsg("Smart Messaging");break; 1609 case RING_NOTETONE : printmsg("Smart Messaging");break;
1581 case RING_NOKIABINARY : printmsg("Nokia binary");break; 1610 case RING_NOKIABINARY : printmsg("Nokia binary");break;
1582 case RING_MIDI : printmsg("Midi format");break; 1611 case RING_MIDI : printmsg("MIDI"); break;
1612 case RING_MMF : printmsg("SMAF (MMF)");break;
1583 } 1613 }
1584 printmsg(" format, ringtone \"%s\"\n",DecodeUnicodeConsole(ringtone.Name)); 1614 printmsg(" format, ringtone \"%s\"\n",DecodeUnicodeConsole(ringtone.Name));
1585 1615
1586 if (argc==4) { 1616 if (argc==4) {
1587 error=GSM_SaveRingtoneFile(argv[3], &ringtone); 1617 error=GSM_SaveRingtoneFile(argv[3], &ringtone);
1588 Print_Error(error); 1618 Print_Error(error);
@@ -2039,14 +2069,14 @@ static void GetAllCalendar(int argc, char *argv[])
2039 2069
2040 GSM_Init(true); 2070 GSM_Init(true);
2041 2071
2042 while (!gshutdown) { 2072 while (!gshutdown) {
2043 error=Phone->GetNextCalendar(&s,&Note,refresh); 2073 error=Phone->GetNextCalendar(&s,&Note,refresh);
2044 if (error == ERR_EMPTY) break; 2074 if (error == ERR_EMPTY) break;
2045 PrintCalendar(&Note);
2046 Print_Error(error); 2075 Print_Error(error);
2076 PrintCalendar(&Note);
2047 refresh=false; 2077 refresh=false;
2048 } 2078 }
2049 2079
2050 GSM_Terminate(); 2080 GSM_Terminate();
2051} 2081}
2052 2082
@@ -2239,12 +2269,14 @@ static void GetBitmap(int argc, char *argv[])
2239 } 2269 }
2240 break; 2270 break;
2241 case GSM_PictureImage: 2271 case GSM_PictureImage:
2242 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]); 2272 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2243 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text)); 2273 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2244 printmsg("Sender : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Sender)); 2274 printmsg("Sender : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Sender));
2275 if (MultiBitmap.Bitmap[0].Name)
2276 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Name));
2245 if (argc>4) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap); 2277 if (argc>4) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap);
2246 break; 2278 break;
2247 case GSM_WelcomeNote_Text: 2279 case GSM_WelcomeNote_Text:
2248 printmsg("Welcome note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text)); 2280 printmsg("Welcome note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2249 break; 2281 break;
2250 case GSM_DealerNote_Text: 2282 case GSM_DealerNote_Text:
@@ -2502,24 +2534,24 @@ static void DisplaySMSFrame(GSM_SMSMessage *SMS)
2502#endif 2534#endif
2503} 2535}
2504 2536
2505#define SEND_SAVE_SMS_BUFFER_SIZE 10000 2537#define SEND_SAVE_SMS_BUFFER_SIZE 10000
2506 2538
2507static GSM_Error SMSStatus; 2539static GSM_Error SMSStatus;
2508//#if 0 2540
2509static void SendSMSStatus (char *Device, int status, int MessageReference) 2541static void SendSMSStatus (char *Device, int status, int MessageReference)
2510{ 2542{
2511 dbgprintf("Sent SMS on device: \"%s\"\n",Device); 2543 dbgprintf("Sent SMS on device: \"%s\"\n",Device);
2512 if (status==0) { 2544 if (status==0) {
2513 printmsg("..OK"); 2545 printmsg("..OK");
2514 SMSStatus = ERR_NONE; 2546 SMSStatus = ERR_NONE;
2515 } else { 2547 } else {
2516 printmsg("..error %i",status); 2548 printmsg("..error %i",status);
2517 SMSStatus = ERR_UNKNOWN; 2549 SMSStatus = ERR_UNKNOWN;
2518 } 2550 }
2519 printmsg(", message reference=%02x\n",MessageReference); 2551 printmsg(", message reference=%d\n",MessageReference);
2520} 2552}
2521 2553
2522static void SendSaveDisplaySMS(int argc, char *argv[]) 2554static void SendSaveDisplaySMS(int argc, char *argv[])
2523{ 2555{
2524#ifdef GSM_ENABLE_BACKUP 2556#ifdef GSM_ENABLE_BACKUP
2525 GSM_Backup Backup; 2557 GSM_Backup Backup;
@@ -2571,13 +2603,17 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2571 startarg = 0; 2603 startarg = 0;
2572 } else { 2604 } else {
2573 EncodeUnicode(Sender,argv[3],strlen(argv[3])); 2605 EncodeUnicode(Sender,argv[3],strlen(argv[3]));
2574 startarg = 1; 2606 startarg = 1;
2575 Validity.Format = 0; 2607 Validity.Format = 0;
2576 } 2608 }
2577 if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) startarg=startarg+2; 2609 if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) {
2610 startarg=startarg+2;
2611 EncodeUnicode(SMSC,"1234",4);
2612 SMSCSet= 0;
2613 }
2578 2614
2579 if (mystrncasecmp(argv[2],"TEXT",0)) { 2615 if (mystrncasecmp(argv[2],"TEXT",0)) {
2580 chars_read = fread(InputBuffer, 1, SEND_SAVE_SMS_BUFFER_SIZE/2, stdin); 2616 chars_read = fread(InputBuffer, 1, SEND_SAVE_SMS_BUFFER_SIZE/2, stdin);
2581 if (chars_read == 0) printmsg("Warning: 0 chars read !\n"); 2617 if (chars_read == 0) printmsg("Warning: 0 chars read !\n");
2582 InputBuffer[chars_read] = 0x00; 2618 InputBuffer[chars_read] = 0x00;
2583 InputBuffer[chars_read+1] = 0x00; 2619 InputBuffer[chars_read+1] = 0x00;
@@ -2597,24 +2633,37 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2597 } else if (mystrncasecmp(argv[2],"EMS",0)) { 2633 } else if (mystrncasecmp(argv[2],"EMS",0)) {
2598 SMSInfo.UnicodeCoding = false; 2634 SMSInfo.UnicodeCoding = false;
2599 SMSInfo.EntriesNum = 0; 2635 SMSInfo.EntriesNum = 0;
2600 startarg += 3; 2636 startarg += 3;
2601 } else if (mystrncasecmp(argv[2],"MMSINDICATOR",0)) { 2637 } else if (mystrncasecmp(argv[2],"MMSINDICATOR",0)) {
2602 if (argc<6+startarg) { 2638 if (argc<6+startarg) {
2603 printmsg("Where is ringtone filename ?\n"); 2639 printmsg("Where are parameters ?\n");
2604 exit(-1); 2640 exit(-1);
2605 } 2641 }
2606 SMSInfo.Entries[0].ID = SMS_MMSIndicatorLong; 2642 SMSInfo.Entries[0].ID = SMS_MMSIndicatorLong;
2607 SMSInfo.Entries[0].MMSIndicator = &MMSInfo; 2643 SMSInfo.Entries[0].MMSIndicator = &MMSInfo;
2608 if (mystrncasecmp(argv[1],"--savesms",0)) { 2644 if (mystrncasecmp(argv[1],"--savesms",0)) {
2609 EncodeUnicode(Sender,"MMS Info",8); 2645 EncodeUnicode(Sender,"MMS Info",8);
2610 } 2646 }
2611 strcpy(MMSInfo.Address,argv[3+startarg]); 2647 strcpy(MMSInfo.Address,argv[3+startarg]);
2612 strcpy(MMSInfo.Title,argv[4+startarg]); 2648 strcpy(MMSInfo.Title,argv[4+startarg]);
2613 strcpy(MMSInfo.Sender,argv[5+startarg]); 2649 strcpy(MMSInfo.Sender,argv[5+startarg]);
2614 startarg += 6; 2650 startarg += 6;
2651 } else if (mystrncasecmp(argv[2],"WAPINDICATOR",0)) {
2652 if (argc<5+startarg) {
2653 printmsg("Where are parameters ?\n");
2654 exit(-1);
2655 }
2656 SMSInfo.Entries[0].ID = SMS_WAPIndicatorLong;
2657 SMSInfo.Entries[0].MMSIndicator = &MMSInfo;
2658 if (mystrncasecmp(argv[1],"--savesms",0)) {
2659 EncodeUnicode(Sender,"WAP Info",8);
2660 }
2661 strcpy(MMSInfo.Address,argv[3+startarg]);
2662 strcpy(MMSInfo.Title,argv[4+startarg]);
2663 startarg += 5;
2615 } else if (mystrncasecmp(argv[2],"RINGTONE",0)) { 2664 } else if (mystrncasecmp(argv[2],"RINGTONE",0)) {
2616 if (argc<4+startarg) { 2665 if (argc<4+startarg) {
2617 printmsg("Where is ringtone filename ?\n"); 2666 printmsg("Where is ringtone filename ?\n");
2618 exit(-1); 2667 exit(-1);
2619 } 2668 }
2620 ringtone[0].Format=RING_NOTETONE; 2669 ringtone[0].Format=RING_NOTETONE;
@@ -2707,13 +2756,13 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2707 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) { 2756 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) {
2708 if (argc<5+startarg) { 2757 if (argc<5+startarg) {
2709 printmsg("Where is backup filename and location ?\n"); 2758 printmsg("Where is backup filename and location ?\n");
2710 exit(-1); 2759 exit(-1);
2711 } 2760 }
2712 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2761 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2713 Print_Error(error); 2762 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2714 i = 0; 2763 i = 0;
2715 while (Backup.WAPBookmark[i]!=NULL) { 2764 while (Backup.WAPBookmark[i]!=NULL) {
2716 if (i == atoi(argv[4+startarg])-1) break; 2765 if (i == atoi(argv[4+startarg])-1) break;
2717 i++; 2766 i++;
2718 } 2767 }
2719 if (i != atoi(argv[4+startarg])-1) { 2768 if (i != atoi(argv[4+startarg])-1) {
@@ -2730,13 +2779,13 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2730 } else if (mystrncasecmp(argv[2],"WAPSETTINGS",0)) { 2779 } else if (mystrncasecmp(argv[2],"WAPSETTINGS",0)) {
2731 if (argc<6+startarg) { 2780 if (argc<6+startarg) {
2732 printmsg("Where is backup filename and location ?\n"); 2781 printmsg("Where is backup filename and location ?\n");
2733 exit(-1); 2782 exit(-1);
2734 } 2783 }
2735 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2784 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2736 Print_Error(error); 2785 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2737 i = 0; 2786 i = 0;
2738 while (Backup.WAPSettings[i]!=NULL) { 2787 while (Backup.WAPSettings[i]!=NULL) {
2739 if (i == atoi(argv[4+startarg])-1) break; 2788 if (i == atoi(argv[4+startarg])-1) break;
2740 i++; 2789 i++;
2741 } 2790 }
2742 if (i != atoi(argv[4+startarg])-1) { 2791 if (i != atoi(argv[4+startarg])-1) {
@@ -2773,13 +2822,13 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2773 } else if (mystrncasecmp(argv[2],"MMSSETTINGS",0)) { 2822 } else if (mystrncasecmp(argv[2],"MMSSETTINGS",0)) {
2774 if (argc<5+startarg) { 2823 if (argc<5+startarg) {
2775 printmsg("Where is backup filename and location ?\n"); 2824 printmsg("Where is backup filename and location ?\n");
2776 exit(-1); 2825 exit(-1);
2777 } 2826 }
2778 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2827 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2779 Print_Error(error); 2828 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2780 i = 0; 2829 i = 0;
2781 while (Backup.MMSSettings[i]!=NULL) { 2830 while (Backup.MMSSettings[i]!=NULL) {
2782 if (i == atoi(argv[4+startarg])-1) break; 2831 if (i == atoi(argv[4+startarg])-1) break;
2783 i++; 2832 i++;
2784 } 2833 }
2785 if (i != atoi(argv[4+startarg])-1) { 2834 if (i != atoi(argv[4+startarg])-1) {
@@ -2809,13 +2858,13 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2809 } else if (mystrncasecmp(argv[2],"CALENDAR",0)) { 2858 } else if (mystrncasecmp(argv[2],"CALENDAR",0)) {
2810 if (argc<5+startarg) { 2859 if (argc<5+startarg) {
2811 printmsg("Where is backup filename and location ?\n"); 2860 printmsg("Where is backup filename and location ?\n");
2812 exit(-1); 2861 exit(-1);
2813 } 2862 }
2814 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2863 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2815 Print_Error(error); 2864 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2816 i = 0; 2865 i = 0;
2817 while (Backup.Calendar[i]!=NULL) { 2866 while (Backup.Calendar[i]!=NULL) {
2818 if (i == atoi(argv[4+startarg])-1) break; 2867 if (i == atoi(argv[4+startarg])-1) break;
2819 i++; 2868 i++;
2820 } 2869 }
2821 if (i != atoi(argv[4+startarg])-1) { 2870 if (i != atoi(argv[4+startarg])-1) {
@@ -2831,13 +2880,13 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2831 } else if (mystrncasecmp(argv[2],"TODO",0)) { 2880 } else if (mystrncasecmp(argv[2],"TODO",0)) {
2832 if (argc<5+startarg) { 2881 if (argc<5+startarg) {
2833 printmsg("Where is backup filename and location ?\n"); 2882 printmsg("Where is backup filename and location ?\n");
2834 exit(-1); 2883 exit(-1);
2835 } 2884 }
2836 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2885 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2837 Print_Error(error); 2886 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2838 i = 0; 2887 i = 0;
2839 while (Backup.ToDo[i]!=NULL) { 2888 while (Backup.ToDo[i]!=NULL) {
2840 if (i == atoi(argv[4+startarg])-1) break; 2889 if (i == atoi(argv[4+startarg])-1) break;
2841 i++; 2890 i++;
2842 } 2891 }
2843 if (i != atoi(argv[4+startarg])-1) { 2892 if (i != atoi(argv[4+startarg])-1) {
@@ -2853,13 +2902,13 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
2853 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) { 2902 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) {
2854 if (argc<6+startarg) { 2903 if (argc<6+startarg) {
2855 printmsg("Where is backup filename and location and memory type ?\n"); 2904 printmsg("Where is backup filename and location and memory type ?\n");
2856 exit(-1); 2905 exit(-1);
2857 } 2906 }
2858 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2907 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2859 Print_Error(error); 2908 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2860 i = 0; 2909 i = 0;
2861 if (mystrncasecmp(argv[4+startarg],"SM",0)) { 2910 if (mystrncasecmp(argv[4+startarg],"SM",0)) {
2862 while (Backup.SIMPhonebook[i]!=NULL) { 2911 while (Backup.SIMPhonebook[i]!=NULL) {
2863 if (i == atoi(argv[5+startarg])-1) break; 2912 if (i == atoi(argv[5+startarg])-1) break;
2864 i++; 2913 i++;
2865 } 2914 }
@@ -3806,13 +3855,13 @@ static void SaveFile(int argc, char *argv[])
3806 if (mystrncasecmp(argv[2],"CALENDAR",0)) { 3855 if (mystrncasecmp(argv[2],"CALENDAR",0)) {
3807 if (argc<5) { 3856 if (argc<5) {
3808 printmsg("Where is backup filename and location ?\n"); 3857 printmsg("Where is backup filename and location ?\n");
3809 exit(-1); 3858 exit(-1);
3810 } 3859 }
3811 error=GSM_ReadBackupFile(argv[4],&Backup); 3860 error=GSM_ReadBackupFile(argv[4],&Backup);
3812 Print_Error(error); 3861 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3813 i = 0; 3862 i = 0;
3814 while (Backup.Calendar[i]!=NULL) { 3863 while (Backup.Calendar[i]!=NULL) {
3815 if (i == atoi(argv[5])-1) break; 3864 if (i == atoi(argv[5])-1) break;
3816 i++; 3865 i++;
3817 } 3866 }
3818 if (i != atoi(argv[5])-1) { 3867 if (i != atoi(argv[5])-1) {
@@ -3824,13 +3873,13 @@ static void SaveFile(int argc, char *argv[])
3824 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) { 3873 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) {
3825 if (argc<5) { 3874 if (argc<5) {
3826 printmsg("Where is backup filename and location ?\n"); 3875 printmsg("Where is backup filename and location ?\n");
3827 exit(-1); 3876 exit(-1);
3828 } 3877 }
3829 error=GSM_ReadBackupFile(argv[4],&Backup); 3878 error=GSM_ReadBackupFile(argv[4],&Backup);
3830 Print_Error(error); 3879 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3831 i = 0; 3880 i = 0;
3832 while (Backup.WAPBookmark[i]!=NULL) { 3881 while (Backup.WAPBookmark[i]!=NULL) {
3833 if (i == atoi(argv[5])-1) break; 3882 if (i == atoi(argv[5])-1) break;
3834 i++; 3883 i++;
3835 } 3884 }
3836 if (i != atoi(argv[5])-1) { 3885 if (i != atoi(argv[5])-1) {
@@ -3842,13 +3891,13 @@ static void SaveFile(int argc, char *argv[])
3842 } else if (mystrncasecmp(argv[2],"NOTE",0)) { 3891 } else if (mystrncasecmp(argv[2],"NOTE",0)) {
3843 if (argc<5) { 3892 if (argc<5) {
3844 printmsg("Where is backup filename and location ?\n"); 3893 printmsg("Where is backup filename and location ?\n");
3845 exit(-1); 3894 exit(-1);
3846 } 3895 }
3847 error=GSM_ReadBackupFile(argv[4],&Backup); 3896 error=GSM_ReadBackupFile(argv[4],&Backup);
3848 Print_Error(error); 3897 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3849 i = 0; 3898 i = 0;
3850 while (Backup.Note[i]!=NULL) { 3899 while (Backup.Note[i]!=NULL) {
3851 if (i == atoi(argv[5])-1) break; 3900 if (i == atoi(argv[5])-1) break;
3852 i++; 3901 i++;
3853 } 3902 }
3854 if (i != atoi(argv[5])-1) { 3903 if (i != atoi(argv[5])-1) {
@@ -3860,13 +3909,13 @@ static void SaveFile(int argc, char *argv[])
3860 } else if (mystrncasecmp(argv[2],"TODO",0)) { 3909 } else if (mystrncasecmp(argv[2],"TODO",0)) {
3861 if (argc<5) { 3910 if (argc<5) {
3862 printmsg("Where is backup filename and location ?\n"); 3911 printmsg("Where is backup filename and location ?\n");
3863 exit(-1); 3912 exit(-1);
3864 } 3913 }
3865 error=GSM_ReadBackupFile(argv[4],&Backup); 3914 error=GSM_ReadBackupFile(argv[4],&Backup);
3866 Print_Error(error); 3915 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3867 i = 0; 3916 i = 0;
3868 while (Backup.ToDo[i]!=NULL) { 3917 while (Backup.ToDo[i]!=NULL) {
3869 if (i == atoi(argv[5])-1) break; 3918 if (i == atoi(argv[5])-1) break;
3870 i++; 3919 i++;
3871 } 3920 }
3872 if (i != atoi(argv[5])-1) { 3921 if (i != atoi(argv[5])-1) {
@@ -3878,13 +3927,13 @@ static void SaveFile(int argc, char *argv[])
3878 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) { 3927 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) {
3879 if (argc<6) { 3928 if (argc<6) {
3880 printmsg("Where is backup filename and location and memory type ?\n"); 3929 printmsg("Where is backup filename and location and memory type ?\n");
3881 exit(-1); 3930 exit(-1);
3882 } 3931 }
3883 error=GSM_ReadBackupFile(argv[4],&Backup); 3932 error=GSM_ReadBackupFile(argv[4],&Backup);
3884 Print_Error(error); 3933 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3885 i = 0; 3934 i = 0;
3886 if (mystrncasecmp(argv[5],"SM",0)) { 3935 if (mystrncasecmp(argv[5],"SM",0)) {
3887 while (Backup.SIMPhonebook[i]!=NULL) { 3936 while (Backup.SIMPhonebook[i]!=NULL) {
3888 if (i == atoi(argv[6])-1) break; 3937 if (i == atoi(argv[6])-1) break;
3889 i++; 3938 i++;
3890 } 3939 }
@@ -3927,20 +3976,23 @@ static void Backup(int argc, char *argv[])
3927{ 3976{
3928 int i, used; 3977 int i, used;
3929 GSM_MemoryStatusMemStatus; 3978 GSM_MemoryStatusMemStatus;
3930 GSM_ToDoEntry ToDo; 3979 GSM_ToDoEntry ToDo;
3931 GSM_ToDoStatus ToDoStatus; 3980 GSM_ToDoStatus ToDoStatus;
3932 GSM_MemoryEntry Pbk; 3981 GSM_MemoryEntry Pbk;
3933 GSM_CalendarEntryNote; 3982 GSM_CalendarEntryCalendar;
3934 GSM_Bitmap Bitmap; 3983 GSM_Bitmap Bitmap;
3935 GSM_WAPBookmark Bookmark; 3984 GSM_WAPBookmark Bookmark;
3936 GSM_Profile Profile; 3985 GSM_Profile Profile;
3937 GSM_MultiWAPSettingsSettings; 3986 GSM_MultiWAPSettingsSettings;
3987 GSM_SyncMLSettingsSyncML;
3988 GSM_ChatSettingsChat;
3938 GSM_Ringtone Ringtone; 3989 GSM_Ringtone Ringtone;
3939 GSM_SMSC SMSC; 3990 GSM_SMSC SMSC;
3940 GSM_Backup Backup; 3991 GSM_Backup Backup;
3992 GSM_NoteEntry Note;
3941 GSM_Backup_Info Info; 3993 GSM_Backup_Info Info;
3942 GSM_FMStation FMStation; 3994 GSM_FMStation FMStation;
3943 GSM_GPRSAccessPointGPRSPoint; 3995 GSM_GPRSAccessPointGPRSPoint;
3944 bool DoBackup; 3996 bool DoBackup;
3945 3997
3946 if (argc == 4 && mystrncasecmp(argv[3],"-yes",0)) always_answer_yes = true; 3998 if (argc == 4 && mystrncasecmp(argv[3],"-yes",0)) always_answer_yes = true;
@@ -4071,13 +4123,13 @@ static void Backup(int argc, char *argv[])
4071 } 4123 }
4072 printmsgerr("\n"); 4124 printmsgerr("\n");
4073 } 4125 }
4074 DoBackup = false; 4126 DoBackup = false;
4075 if (Info.Calendar) { 4127 if (Info.Calendar) {
4076 printmsg("Checking calendar\n"); 4128 printmsg("Checking calendar\n");
4077 error=Phone->GetNextCalendar(&s,&Note,true); 4129 error=Phone->GetNextCalendar(&s,&Calendar,true);
4078 if (error==ERR_NONE) { 4130 if (error==ERR_NONE) {
4079 if (answer_yes(" Backup calendar notes")) DoBackup = true; 4131 if (answer_yes(" Backup calendar notes")) DoBackup = true;
4080 } 4132 }
4081 } 4133 }
4082 if (DoBackup) { 4134 if (DoBackup) {
4083 used = 0; 4135 used = 0;
@@ -4089,15 +4141,15 @@ static void Backup(int argc, char *argv[])
4089 Backup.Calendar[used+1] = NULL; 4141 Backup.Calendar[used+1] = NULL;
4090 } else { 4142 } else {
4091 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES"); 4143 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES");
4092 GSM_Terminate(); 4144 GSM_Terminate();
4093 exit(-1); 4145 exit(-1);
4094 } 4146 }
4095 *Backup.Calendar[used]=Note; 4147 *Backup.Calendar[used]=Calendar;
4096 used ++; 4148 used ++;
4097 error=Phone->GetNextCalendar(&s,&Note,false); 4149 error=Phone->GetNextCalendar(&s,&Calendar,false);
4098 printmsgerr("*"); 4150 printmsgerr("*");
4099 if (gshutdown) { 4151 if (gshutdown) {
4100 GSM_Terminate(); 4152 GSM_Terminate();
4101 exit(0); 4153 exit(0);
4102 } 4154 }
4103 } 4155 }
@@ -4133,12 +4185,44 @@ static void Backup(int argc, char *argv[])
4133 exit(0); 4185 exit(0);
4134 } 4186 }
4135 } 4187 }
4136 printmsgerr("\n"); 4188 printmsgerr("\n");
4137 } 4189 }
4138 DoBackup = false; 4190 DoBackup = false;
4191 if (Info.Note) {
4192 printmsg("Checking notes\n");
4193 error=Phone->GetNextNote(&s,&Note,true);
4194 if (error==ERR_NONE) {
4195 if (answer_yes(" Backup notes")) DoBackup = true;
4196 }
4197 }
4198 if (DoBackup) {
4199 used = 0;
4200 printmsgerr(" Reading : ");
4201 while (error == ERR_NONE) {
4202 if (used < GSM_BACKUP_MAX_NOTE) {
4203 Backup.Note[used] = malloc(sizeof(GSM_NoteEntry));
4204 if (Backup.Note[used] == NULL) Print_Error(ERR_MOREMEMORY);
4205 Backup.Note[used+1] = NULL;
4206 } else {
4207 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_NOTE");
4208 GSM_Terminate();
4209 exit(-1);
4210 }
4211 *Backup.Note[used]=Note;
4212 used ++;
4213 error=Phone->GetNextNote(&s,&Note,false);
4214 printmsgerr("*");
4215 if (gshutdown) {
4216 GSM_Terminate();
4217 exit(0);
4218 }
4219 }
4220 printmsgerr("\n");
4221 }
4222 DoBackup = false;
4139 if (Info.CallerLogos) { 4223 if (Info.CallerLogos) {
4140 printmsg("Checking caller logos\n"); 4224 printmsg("Checking caller logos\n");
4141 Bitmap.Type = GSM_CallerGroupLogo; 4225 Bitmap.Type = GSM_CallerGroupLogo;
4142 Bitmap.Location = 1; 4226 Bitmap.Location = 1;
4143 error=Phone->GetBitmap(&s,&Bitmap); 4227 error=Phone->GetBitmap(&s,&Bitmap);
4144 if (error == ERR_NONE) { 4228 if (error == ERR_NONE) {
@@ -4231,12 +4315,80 @@ static void Backup(int argc, char *argv[])
4231 if (DoBackup) { 4315 if (DoBackup) {
4232 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap)); 4316 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap));
4233 if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY); 4317 if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY);
4234 *Backup.OperatorLogo = Bitmap; 4318 *Backup.OperatorLogo = Bitmap;
4235 } 4319 }
4236 DoBackup = false; 4320 DoBackup = false;
4321 if (Info.WAPBookmark) {
4322 printmsg("Checking WAP bookmarks\n");
4323 Bookmark.Location = 1;
4324 error=Phone->GetWAPBookmark(&s,&Bookmark);
4325 if (error==ERR_NONE) {
4326 if (answer_yes(" Backup WAP bookmarks")) DoBackup = true;
4327 }
4328 }
4329 if (DoBackup) {
4330 used = 0;
4331 printmsgerr(" Reading : ");
4332 while (error == ERR_NONE) {
4333 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) {
4334 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark));
4335 if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY);
4336 Backup.WAPBookmark[used+1] = NULL;
4337 } else {
4338 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK");
4339 GSM_Terminate();
4340 exit(-1);
4341 }
4342 *Backup.WAPBookmark[used]=Bookmark;
4343 used ++;
4344 Bookmark.Location = used+1;
4345 error=Phone->GetWAPBookmark(&s,&Bookmark);
4346 printmsgerr("*");
4347 if (gshutdown) {
4348 GSM_Terminate();
4349 exit(0);
4350 }
4351 }
4352 printmsgerr("\n");
4353 }
4354 DoBackup = false;
4355 if (Info.WAPSettings) {
4356 printmsg("Checking WAP settings\n");
4357 Settings.Location = 1;
4358 error=Phone->GetWAPSettings(&s,&Settings);
4359 if (error==ERR_NONE) {
4360 if (answer_yes(" Backup WAP settings")) DoBackup = true;
4361 }
4362 }
4363 if (DoBackup) {
4364 used = 0;
4365 printmsgerr(" Reading : ");
4366 while (error == ERR_NONE) {
4367 if (used < GSM_BACKUP_MAX_WAPSETTINGS) {
4368 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
4369 if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4370 Backup.WAPSettings[used+1] = NULL;
4371 } else {
4372 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS");
4373 GSM_Terminate();
4374 exit(-1);
4375 }
4376 *Backup.WAPSettings[used]=Settings;
4377 used ++;
4378 Settings.Location = used+1;
4379 error=Phone->GetWAPSettings(&s,&Settings);
4380 printmsgerr("*");
4381 if (gshutdown) {
4382 GSM_Terminate();
4383 exit(0);
4384 }
4385 }
4386 printmsgerr("\n");
4387 }
4388 DoBackup = false;
4237 if (Info.MMSSettings) { 4389 if (Info.MMSSettings) {
4238 printmsg("Checking MMS settings\n"); 4390 printmsg("Checking MMS settings\n");
4239 Settings.Location = 1; 4391 Settings.Location = 1;
4240 error=Phone->GetMMSSettings(&s,&Settings); 4392 error=Phone->GetMMSSettings(&s,&Settings);
4241 if (error==ERR_NONE) { 4393 if (error==ERR_NONE) {
4242 if (answer_yes(" Backup MMS settings")) DoBackup = true; 4394 if (answer_yes(" Backup MMS settings")) DoBackup = true;
@@ -4265,71 +4417,71 @@ static void Backup(int argc, char *argv[])
4265 exit(0); 4417 exit(0);
4266 } 4418 }
4267 } 4419 }
4268 printmsgerr("\n"); 4420 printmsgerr("\n");
4269 } 4421 }
4270 DoBackup = false; 4422 DoBackup = false;
4271 if (Info.WAPBookmark) { 4423 if (Info.ChatSettings) {
4272 printmsg("Checking WAP bookmarks\n"); 4424 printmsg("Checking Chat settings\n");
4273 Bookmark.Location = 1; 4425 Chat.Location = 1;
4274 error=Phone->GetWAPBookmark(&s,&Bookmark); 4426 error=Phone->GetChatSettings(&s,&Chat);
4275 if (error==ERR_NONE) { 4427 if (error==ERR_NONE) {
4276 if (answer_yes(" Backup WAP bookmarks")) DoBackup = true; 4428 if (answer_yes(" Backup Chat settings")) DoBackup = true;
4277 } 4429 }
4278 } 4430 }
4279 if (DoBackup) { 4431 if (DoBackup) {
4280 used = 0; 4432 used = 0;
4281 printmsgerr(" Reading : "); 4433 printmsgerr(" Reading : ");
4282 while (error == ERR_NONE) { 4434 while (error == ERR_NONE) {
4283 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) { 4435 if (used < GSM_BACKUP_MAX_CHATSETTINGS) {
4284 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark)); 4436 Backup.ChatSettings[used] = malloc(sizeof(GSM_ChatSettings));
4285 if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY); 4437 if (Backup.ChatSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4286 Backup.WAPBookmark[used+1] = NULL; 4438 Backup.ChatSettings[used+1] = NULL;
4287 } else { 4439 } else {
4288 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK"); 4440 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CHATSETTINGS");
4289 GSM_Terminate(); 4441 GSM_Terminate();
4290 exit(-1); 4442 exit(-1);
4291 } 4443 }
4292 *Backup.WAPBookmark[used]=Bookmark; 4444 *Backup.ChatSettings[used]=Chat;
4293 used ++; 4445 used ++;
4294 Bookmark.Location = used+1; 4446 Chat.Location = used+1;
4295 error=Phone->GetWAPBookmark(&s,&Bookmark); 4447 error=Phone->GetChatSettings(&s,&Chat);
4296 printmsgerr("*"); 4448 printmsgerr("*");
4297 if (gshutdown) { 4449 if (gshutdown) {
4298 GSM_Terminate(); 4450 GSM_Terminate();
4299 exit(0); 4451 exit(0);
4300 } 4452 }
4301 } 4453 }
4302 printmsgerr("\n"); 4454 printmsgerr("\n");
4303 } 4455 }
4304 DoBackup = false; 4456 DoBackup = false;
4305 if (Info.WAPSettings) { 4457 if (Info.SyncMLSettings) {
4306 printmsg("Checking WAP settings\n"); 4458 printmsg("Checking SyncML settings\n");
4307 Settings.Location = 1; 4459 SyncML.Location = 1;
4308 error=Phone->GetWAPSettings(&s,&Settings); 4460 error=Phone->GetSyncMLSettings(&s,&SyncML);
4309 if (error==ERR_NONE) { 4461 if (error==ERR_NONE) {
4310 if (answer_yes(" Backup WAP settings")) DoBackup = true; 4462 if (answer_yes(" Backup SyncML settings")) DoBackup = true;
4311 } 4463 }
4312 } 4464 }
4313 if (DoBackup) { 4465 if (DoBackup) {
4314 used = 0; 4466 used = 0;
4315 printmsgerr(" Reading : "); 4467 printmsgerr(" Reading : ");
4316 while (error == ERR_NONE) { 4468 while (error == ERR_NONE) {
4317 if (used < GSM_BACKUP_MAX_WAPSETTINGS) { 4469 if (used < GSM_BACKUP_MAX_SYNCMLSETTINGS) {
4318 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); 4470 Backup.SyncMLSettings[used] = malloc(sizeof(GSM_SyncMLSettings));
4319 if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); 4471 if (Backup.SyncMLSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4320 Backup.WAPSettings[used+1] = NULL; 4472 Backup.SyncMLSettings[used+1] = NULL;
4321 } else { 4473 } else {
4322 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS"); 4474 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SYNCMLSETTINGS");
4323 GSM_Terminate(); 4475 GSM_Terminate();
4324 exit(-1); 4476 exit(-1);
4325 } 4477 }
4326 *Backup.WAPSettings[used]=Settings; 4478 *Backup.SyncMLSettings[used]=SyncML;
4327 used ++; 4479 used ++;
4328 Settings.Location = used+1; 4480 SyncML.Location = used+1;
4329 error=Phone->GetWAPSettings(&s,&Settings); 4481 error=Phone->GetSyncMLSettings(&s,&SyncML);
4330 printmsgerr("*"); 4482 printmsgerr("*");
4331 if (gshutdown) { 4483 if (gshutdown) {
4332 GSM_Terminate(); 4484 GSM_Terminate();
4333 exit(0); 4485 exit(0);
4334 } 4486 }
4335 } 4487 }
@@ -4499,20 +4651,25 @@ static void Restore(int argc, char *argv[])
4499 GSM_WAPBookmark Bookmark; 4651 GSM_WAPBookmark Bookmark;
4500 int i, used, max = 0; 4652 int i, used, max = 0;
4501 bool Past = true; 4653 bool Past = true;
4502 bool Found, DoRestore; 4654 bool Found, DoRestore;
4503 4655
4504 error=GSM_ReadBackupFile(argv[2],&Backup); 4656 error=GSM_ReadBackupFile(argv[2],&Backup);
4657 if (error!=ERR_NOTIMPLEMENTED) {
4505 Print_Error(error); 4658 Print_Error(error);
4659 } else {
4660 printmsgerr("WARNING: Some data not read from file. It can be damaged or restoring some settings from this file format not implemented (maybe higher Gammu required ?)\n");
4661 }
4506 4662
4507 signal(SIGINT, interrupt); 4663 signal(SIGINT, interrupt);
4508 printmsgerr("Press Ctrl+C to break...\n"); 4664 printmsgerr("Press Ctrl+C to break...\n");
4509 4665
4510 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); 4666 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
4511 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); 4667 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
4512 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); 4668 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
4669 if (Backup.Creator[0]!=0) printmsgerr("File created by : %s\n",Backup.Creator);
4513 4670
4514 if (Backup.MD5Calculated[0]!=0) { 4671 if (Backup.MD5Calculated[0]!=0) {
4515 dbgprintf("\"%s\"\n",Backup.MD5Original); 4672 dbgprintf("\"%s\"\n",Backup.MD5Original);
4516 dbgprintf("\"%s\"\n",Backup.MD5Calculated); 4673 dbgprintf("\"%s\"\n",Backup.MD5Calculated);
4517 if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) { 4674 if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) {
4518 if (!answer_yes("Checksum in backup file do not match. Continue")) return; 4675 if (!answer_yes("Checksum in backup file do not match. Continue")) return;
@@ -4615,35 +4772,32 @@ static void Restore(int argc, char *argv[])
4615 } 4772 }
4616 } 4773 }
4617 printmsgerr("\n"); 4774 printmsgerr("\n");
4618 } 4775 }
4619 4776
4620 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { 4777 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) {
4621 if (/*answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")*/ true ) { 4778 if (answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")) {
4622 GSM_GetCurrentDateTime(&date_time); 4779 GSM_GetCurrentDateTime(&date_time);
4623 4780
4624 error=Phone->SetDateTime(&s, &date_time); 4781 error=Phone->SetDateTime(&s, &date_time);
4625 Print_Error(error); 4782 Print_Error(error);
4626 } 4783 }
4627 } 4784 }
4628 DoRestore = false; 4785 DoRestore = false;
4629 if (Backup.Calendar[0] != NULL) { 4786 if (Backup.Calendar[0] != NULL) {
4630 DoRestore = true;
4631 /* N6110 doesn't support getting calendar status */ 4787 /* N6110 doesn't support getting calendar status */
4632 error = Phone->GetNextCalendar(&s,&Calendar,true); 4788 error = Phone->GetNextCalendar(&s,&Calendar,true);
4633 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { 4789 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) {
4634 max = 0; 4790 max = 0;
4635 while (Backup.Calendar[max] != NULL) max++; 4791 while (Backup.Calendar[max] != NULL) max++;
4636 printmsgerr("%i entries in backup file\n",max); 4792 printmsgerr("%i entries in backup file\n",max);
4793 // LR
4794 //if (answer_yes("Restore calendar notes")) {
4795 //Past = answer_yes("Restore notes from the past");
4637 DoRestore = true; 4796 DoRestore = true;
4638 /* 4797 //}
4639 if (answer_yes("Restore calendar notes")) {
4640 Past = answer_yes("Restore notes from the past");
4641 DoRestore = true;
4642 }
4643 */
4644 } 4798 }
4645 } 4799 }
4646 if (DoRestore) { 4800 if (DoRestore) {
4647 printmsgerr("Deleting old notes: "); 4801 printmsgerr("Deleting old notes: ");
4648 error = Phone->DeleteAllCalendar(&s); 4802 error = Phone->DeleteAllCalendar(&s);
4649 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 4803 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
@@ -4676,27 +4830,24 @@ static void Restore(int argc, char *argv[])
4676 } 4830 }
4677 4831
4678 DoRestore = false; 4832 DoRestore = false;
4679 if (Backup.ToDo[0] != NULL) { 4833 if (Backup.ToDo[0] != NULL) {
4680 error = Phone->GetToDoStatus(&s,&ToDoStatus); 4834 error = Phone->GetToDoStatus(&s,&ToDoStatus);
4681 if (error == ERR_NONE) { 4835 if (error == ERR_NONE) {
4682 error == ERR_NOTSUPPORTED;
4683 DoRestore = true;
4684 max = 0; 4836 max = 0;
4685 while (Backup.ToDo[max]!=NULL) max++; 4837 while (Backup.ToDo[max]!=NULL) max++;
4686 printmsgerr("%i entries in backup file\n",max); 4838 printmsgerr("%i entries in backup file\n",max);
4687 4839
4688 /*if (answer_yes("Restore ToDo")) */DoRestore = true; 4840 //LR if (answer_yes("Restore ToDo"))
4841 DoRestore = true;
4689 } 4842 }
4690 } 4843 }
4691 if (DoRestore) { 4844 if (DoRestore) {
4692 if ( max > 0 ) {
4693 ToDo = *Backup.ToDo[0]; 4845 ToDo = *Backup.ToDo[0];
4694 error = Phone->SetToDo(&s,&ToDo); 4846 error = Phone->SetToDo(&s,&ToDo);
4695 } 4847 }
4696 }
4697 if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { 4848 if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) {
4698 printmsgerr("Deleting old ToDo: "); 4849 printmsgerr("Deleting old ToDo: ");
4699 error=Phone->DeleteAllToDo(&s); 4850 error=Phone->DeleteAllToDo(&s);
4700 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 4851 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
4701 while (1) { 4852 while (1) {
4702 error = Phone->GetNextToDo(&s,&ToDo,true); 4853 error = Phone->GetNextToDo(&s,&ToDo,true);
@@ -4988,13 +5139,13 @@ static void AddNew(int argc, char *argv[])
4988 GSM_ToDoStatus ToDoStatus; 5139 GSM_ToDoStatus ToDoStatus;
4989 GSM_CalendarEntryCalendar; 5140 GSM_CalendarEntryCalendar;
4990 GSM_WAPBookmark Bookmark; 5141 GSM_WAPBookmark Bookmark;
4991 int i, max, j; 5142 int i, max, j;
4992 5143
4993 error=GSM_ReadBackupFile(argv[2],&Backup); 5144 error=GSM_ReadBackupFile(argv[2],&Backup);
4994 Print_Error(error); 5145 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
4995 5146
4996 signal(SIGINT, interrupt); 5147 signal(SIGINT, interrupt);
4997 printmsgerr("Press Ctrl+C to break...\n"); 5148 printmsgerr("Press Ctrl+C to break...\n");
4998 5149
4999 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); 5150 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
5000 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); 5151 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
@@ -5615,14 +5766,13 @@ static void RestoreSMS(int argc, char *argv[])
5615 while (Backup.SMS[smsnum] != NULL) { 5766 while (Backup.SMS[smsnum] != NULL) {
5616 SMS.Number = 1; 5767 SMS.Number = 1;
5617 memcpy(&SMS.SMS[0],Backup.SMS[smsnum],sizeof(GSM_SMSMessage)); 5768 memcpy(&SMS.SMS[0],Backup.SMS[smsnum],sizeof(GSM_SMSMessage));
5618 displaymultismsinfo(SMS,false,false); 5769 displaymultismsinfo(SMS,false,false);
5619 sprintf(buffer,"Restore sms to folder \"%s\"",DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder-1].Name)); 5770 sprintf(buffer,"Restore sms to folder \"%s\"",DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder-1].Name));
5620 if (answer_yes(buffer)) { 5771 if (answer_yes(buffer)) {
5621 Backup.SMS[smsnum]->Location = 0; 5772 error=Phone->AddSMS(&s, Backup.SMS[smsnum]);
5622 error=Phone->SetSMS(&s, Backup.SMS[smsnum]);
5623 Print_Error(error); 5773 Print_Error(error);
5624 } 5774 }
5625 smsnum++; 5775 smsnum++;
5626 } 5776 }
5627 5777
5628 GSM_Terminate(); 5778 GSM_Terminate();
@@ -5810,13 +5960,13 @@ static void NokiaComposer(int argc, char *argv[])
5810 } 5960 }
5811 } 5961 }
5812 } 5962 }
5813 5963
5814 printf("\n"); 5964 printf("\n");
5815} 5965}
5816//#if 0 5966
5817static void CopyRingtone(int argc, char *argv[]) 5967static void CopyRingtone(int argc, char *argv[])
5818{ 5968{
5819 GSM_Ringtone ringtone, ringtone2; 5969 GSM_Ringtone ringtone, ringtone2;
5820 GSM_RingtoneFormatFormat; 5970 GSM_RingtoneFormatFormat;
5821 5971
5822 ringtone.Format= 0; 5972 ringtone.Format= 0;
@@ -6095,13 +6245,13 @@ static void ListToDoCategory(int argc, char *argv[])
6095 for (count=0,j=1;count<Status.Used;j++) { 6245 for (count=0,j=1;count<Status.Used;j++) {
6096 Category.Location=j; 6246 Category.Location=j;
6097 error=Phone->GetCategory(&s, &Category); 6247 error=Phone->GetCategory(&s, &Category);
6098 6248
6099 if (error != ERR_EMPTY) { 6249 if (error != ERR_EMPTY) {
6100 count++; 6250 count++;
6101 if (mystrstr(Category.Name, Text) != NULL) { 6251 if (mywstrstr(Category.Name, Text) != NULL) {
6102 ListToDoCategoryEntries(j); 6252 ListToDoCategoryEntries(j);
6103 } 6253 }
6104 } 6254 }
6105 } 6255 }
6106 } 6256 }
6107 } 6257 }
@@ -6148,37 +6298,30 @@ static void GetAllToDo(int argc, char *argv[])
6148 start = false; 6298 start = false;
6149 } 6299 }
6150 6300
6151 GSM_Terminate(); 6301 GSM_Terminate();
6152} 6302}
6153 6303
6154static void GetNote(int argc, char *argv[]) 6304static void GetAllNotes(int argc, char *argv[])
6155{ 6305{
6156 GSM_NoteEntry Note; 6306 GSM_NoteEntry Note;
6157 int start,stop; 6307 bool start = true;
6158 bool refresh=true;
6159 6308
6160 GetStartStop(&start, &stop, 2, argc, argv); 6309 signal(SIGINT, interrupt);
6310 printmsgerr("Press Ctrl+C to break...\n");
6161 6311
6162 GSM_Init(true); 6312 GSM_Init(true);
6163 6313
6164 for (i=start;i<=stop;i++) { 6314 while (!gshutdown) {
6165 Note.Location=i; 6315 error = Phone->GetNextNote(&s, &Note, start);
6166 printmsg("Location : %i\n",i); 6316 if (error == ERR_EMPTY) break;
6167 error=Phone->GetNote(&s,&Note,refresh); 6317 Print_Error(error);
6168 if (error != ERR_EMPTY) Print_Error(error);
6169
6170 if (error == ERR_EMPTY) {
6171 printmsg("Entry is empty\n\n");
6172 } else {
6173 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note.Text)); 6318 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note.Text));
6174 printf("\n"); 6319 printf("\n");
6175 refresh=false; 6320 start = false;
6176 }
6177 } 6321 }
6178
6179 GSM_Terminate(); 6322 GSM_Terminate();
6180} 6323}
6181 6324
6182static void GetSecurityStatus(int argc, char *argv[]) 6325static void GetSecurityStatus(int argc, char *argv[])
6183{ 6326{
6184 GSM_Init(true); 6327 GSM_Init(true);
@@ -6568,27 +6711,52 @@ static void MakeConvertTable(int argc, char *argv[])
6568} 6711}
6569#endif 6712#endif
6570 6713
6571static void ListNetworks(int argc, char *argv[]) 6714static void ListNetworks(int argc, char *argv[])
6572{ 6715{
6573 extern unsigned char *GSM_Networks[]; 6716 extern unsigned char *GSM_Networks[];
6717 extern unsigned char *GSM_Countries[];
6574 int i=0; 6718 int i=0;
6719 char country[4]="";
6575 6720
6576 printmsg("Network Name\n\n"); 6721 if (argc>2) {
6722 while (GSM_Countries[i*2]!=NULL) {
6723 if (!strncmp(GSM_Countries[i*2+1],argv[2],strlen(argv[2]))) {
6724 strcpy(country,GSM_Countries[i*2]);
6725 printmsg("Networks for %s:\n\n",GSM_Countries[i*2+1]);
6726 break;
6727 }
6728 i++;
6729 }
6730 if (!*country) {
6731 printmsg("Unknown country name.");
6732 exit(-1);
6733 }
6734 }
6735 printmsg("Network Name\n");
6736 i=0;
6577 while (GSM_Networks[i*2]!=NULL) { 6737 while (GSM_Networks[i*2]!=NULL) {
6738 if (argc>2) {
6739 if (!strncmp(GSM_Networks[i*2],country,strlen(country))) {
6578 printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]); 6740 printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]);
6741 }
6742 } else {
6743 printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]);
6744 }
6579 i++; 6745 i++;
6580 } 6746 }
6581} 6747}
6582 6748
6583static void Version(int argc, char *argv[]) 6749static void Version(int argc, char *argv[])
6584{ 6750{
6585 // unsigned char buff[10]; 6751 // unsigned char buff[10];
6586 // int len; 6752 // int len;
6587 6753
6588 printmsg("[Gammu version %s built %s %s]\n\n",VERSION,__TIME__,__DATE__); 6754 printmsg("[Gammu version %s built %s %s",VERSION,__TIME__,__DATE__);
6755 if (strlen(GetCompiler()) != 0) printmsg(" in %s",GetCompiler());
6756 printmsg("]\n\n");
6589 6757
6590#ifdef DEBUG 6758#ifdef DEBUG
6591 printf("GSM_SMSMessage - %i\n",sizeof(GSM_SMSMessage)); 6759 printf("GSM_SMSMessage - %i\n",sizeof(GSM_SMSMessage));
6592 printf("GSM_SMSC - %i\n",sizeof(GSM_SMSC)); 6760 printf("GSM_SMSC - %i\n",sizeof(GSM_SMSC));
6593 printf("GSM_SMS_State - %i\n",sizeof(GSM_SMS_State)); 6761 printf("GSM_SMS_State - %i\n",sizeof(GSM_SMS_State));
6594 printf("GSM_UDHHeader - %i\n",sizeof(GSM_UDHHeader)); 6762 printf("GSM_UDHHeader - %i\n",sizeof(GSM_UDHHeader));
@@ -6699,15 +6867,12 @@ static void GetFileSystem(int argc, char *argv[])
6699 for (j=0;j<Files.Level-2;j++) printf(" | "); 6867 for (j=0;j<Files.Level-2;j++) printf(" | ");
6700 printf(" |-- "); 6868 printf(" |-- ");
6701 } 6869 }
6702 if (Files.Folder) printf("Folder "); 6870 if (Files.Folder) printf("Folder ");
6703 } 6871 }
6704 printf("\"%s\"",DecodeUnicodeConsole(Files.Name)); 6872 printf("\"%s\"",DecodeUnicodeConsole(Files.Name));
6705 printf("\n");
6706
6707 Start = false;
6708 } else if (argc > 2 && mystrncasecmp(argv[2],"-flatall",0)) { 6873 } else if (argc > 2 && mystrncasecmp(argv[2],"-flatall",0)) {
6709 /* format for a folder ID;Folder;FOLDER_NAME;[FOLDER_PARAMETERS] 6874 /* format for a folder ID;Folder;FOLDER_NAME;[FOLDER_PARAMETERS]
6710 * format for a file ID;File;FOLDER_NAME;FILE_NAME;DATESTAMP;FILE_SIZE;[FILE_PARAMETERS] */ 6875 * format for a file ID;File;FOLDER_NAME;FILE_NAME;DATESTAMP;FILE_SIZE;[FILE_PARAMETERS] */
6711 if (!Files.Folder) { 6876 if (!Files.Folder) {
6712 printf("%s;File;",Files.ID_FullName); 6877 printf("%s;File;",Files.ID_FullName);
6713 printf("\"%s\";",FolderName); 6878 printf("\"%s\";",FolderName);
@@ -6723,17 +6888,14 @@ static void GetFileSystem(int argc, char *argv[])
6723 } 6888 }
6724 6889
6725 if (Files.Protected) printf("P"); 6890 if (Files.Protected) printf("P");
6726 if (Files.ReadOnly) printf("R"); 6891 if (Files.ReadOnly) printf("R");
6727 if (Files.Hidden) printf("H"); 6892 if (Files.Hidden) printf("H");
6728 if (Files.System) printf("S"); 6893 if (Files.System) printf("S");
6729
6730 printf("\n");
6731
6732 Start = false;
6733 } 6894 }
6895 Start = false;
6734 } 6896 }
6735 6897
6736 error = Phone->GetFileSystemStatus(&s,&Status); 6898 error = Phone->GetFileSystemStatus(&s,&Status);
6737 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) { 6899 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) {
6738 Print_Error(error); 6900 Print_Error(error);
6739 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used); 6901 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used);
@@ -7035,16 +7197,20 @@ static struct NokiaFolderInfo Folder[] = {
7035 {"", "Gallery", "Graphics","3"}, /* 3510i */ 7197 {"", "Gallery", "Graphics","3"}, /* 3510i */
7036 {"", "Gallery", "Images","3"}, /* 6610 */ 7198 {"", "Gallery", "Images","3"}, /* 6610 */
7037 {"3510", "Gallery", "", "8"}, 7199 {"3510", "Gallery", "", "8"},
7038 {"3510i","Gallery", "", "3"}, 7200 {"3510i","Gallery", "", "3"},
7039 {"5100", "Gallery", "", "3"}, 7201 {"5100", "Gallery", "", "3"},
7040 {"6220", "Gallery", "", "5"}, 7202 {"6220", "Gallery", "", "5"},
7203 {"6610", "Gallery", "", "2"},
7204 {"7210", "Gallery", "", "2"},
7041 {"", "Tones", "Tones","3"}, 7205 {"", "Tones", "Tones","3"},
7042 {"3510i","Tones", "", "4"}, 7206 {"3510i","Tones", "", "4"},
7043 {"5100", "Tones", "", "4"}, 7207 {"5100", "Tones", "", "4"},
7044 {"6220", "Tones", "", "6"}, 7208 {"6220", "Tones", "", "6"},
7209 {"6610", "Tones", "", "4"},
7210 {"7210", "Tones", "", "4"},
7045 /* Language indepedent in OBEX */ 7211 /* Language indepedent in OBEX */
7046 {"obex", "MMSUnreadInbox", "", "predefMessages\\predefINBOX"}, 7212 {"obex", "MMSUnreadInbox", "", "predefMessages\\predefINBOX"},
7047 {"obex", "MMSReadInbox", "", "predefMessages\\predefINBOX"}, 7213 {"obex", "MMSReadInbox", "", "predefMessages\\predefINBOX"},
7048 {"obex", "MMSOutbox", "", "predefMessages\\predefOUTBOX"}, 7214 {"obex", "MMSOutbox", "", "predefMessages\\predefOUTBOX"},
7049 {"obex", "MMSSent", "", "predefMessages\\predefSENT" }, 7215 {"obex", "MMSSent", "", "predefMessages\\predefSENT" },
7050 {"obex", "MMSDrafts", "", "predefMessages\\predefDRAFTS"}, 7216 {"obex", "MMSDrafts", "", "predefMessages\\predefDRAFTS"},
@@ -7555,93 +7721,99 @@ static void CallDivert(int argc, char *argv[])
7555 } 7721 }
7556 printf("\n"); 7722 printf("\n");
7557 7723
7558 GSM_Terminate(); 7724 GSM_Terminate();
7559} 7725}
7560 7726
7561
7562//#if 0
7563static void CancelAllDiverts(int argc, char *argv[]) 7727static void CancelAllDiverts(int argc, char *argv[])
7564{ 7728{
7565 GSM_Init(true); 7729 GSM_Init(true);
7566 7730
7567 error = Phone->CancelAllDiverts(&s); 7731 error = Phone->CancelAllDiverts(&s);
7568 Print_Error(error); 7732 Print_Error(error);
7569 7733
7570 GSM_Terminate(); 7734 GSM_Terminate();
7571} 7735}
7572 7736
7737typedef struct {
7738 unsigned char Connection[50];
7739} OneConnectionInfo;
7740
7741typedef struct {
7742 unsigned char Device[50];
7743 OneConnectionInfo Connections[4];
7744} OneDeviceInfo;
7573 7745
7746 int num;
7747 bool SearchOutput;
7574 7748
7575void SearchPhoneThread(OneDeviceInfo *Info) 7749void SearchPhoneThread(OneDeviceInfo *Info)
7576{ 7750{
7751 //LR
7752#if 0
7577 int j; 7753 int j;
7578 GSM_Error error; 7754 GSM_Error error;
7579 fprintf(stderr,"*********************************** \n"); 7755 GSM_StateMachiness;
7580 fprintf(stderr,"*********************************** \n"); 7756
7581 fprintf(stderr,"*********************************** \n");
7582 fprintf(stderr,"*********************************** \n");
7583 fprintf(stderr,"*********************************** \n");
7584#if 0
7585 j = 0; 7757 j = 0;
7586 while(strlen(Info->Connections[j].Connection) != 0) { 7758 while(strlen(Info->Connections[j].Connection) != 0) {
7587 memcpy(&Info->s.di,&s.di,sizeof(Debug_Info)); 7759 memcpy(&ss.di,&s.di,sizeof(Debug_Info));
7588 Info->s.msg = s.msg; 7760 ss.msg = s.msg;
7589 Info->s.ConfigNum = 1; 7761 ss.ConfigNum = 1;
7590 Info->s.opened = false; 7762 ss.opened = false;
7591 Info->s.Config[0].UseGlobalDebugFile = s.Config[0].UseGlobalDebugFile; 7763 ss.Config[0].UseGlobalDebugFile = s.Config[0].UseGlobalDebugFile;
7592 Info->s.Config[0].Localize = s.Config[0].Localize; 7764 ss.Config[0].Localize = s.Config[0].Localize;
7593 Info->s.Config[0].Device = Info->Device; 7765 ss.Config[0].Device = Info->Device;
7594 Info->s.Config[0].Connection = Info->Connections[j].Connection; 7766 ss.Config[0].Connection = Info->Connections[j].Connection;
7595 Info->s.Config[0].SyncTime = "no"; 7767 ss.Config[0].SyncTime = "no";
7596 Info->s.Config[0].DebugFile = s.Config[0].DebugFile; 7768 ss.Config[0].DebugFile = s.Config[0].DebugFile;
7597 Info->s.Config[0].Model[0] = 0; 7769 ss.Config[0].Model[0] = 0;
7598 strcpy(Info->s.Config[0].DebugLevel,s.Config[0].DebugLevel); 7770 strcpy(ss.Config[0].DebugLevel,s.Config[0].DebugLevel);
7599 Info->s.Config[0].LockDevice = "no"; 7771 ss.Config[0].LockDevice = "no";
7600 Info->s.Config[0].StartInfo = "no"; 7772 ss.Config[0].StartInfo = "no";
7601 7773
7602 error = GSM_InitConnection(&Info->s,1); 7774 error = GSM_InitConnection(&ss,1);
7603 if (SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device); 7775 if (SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device);
7604 if (error == ERR_NONE) { 7776 if (error == ERR_NONE) {
7605 error=Info->s.Phone.Functions->GetManufacturer(&Info->s); 7777 error=ss.Phone.Functions->GetManufacturer(&ss);
7606 if (error == ERR_NONE) { 7778 if (error == ERR_NONE) {
7607 error=Info->s.Phone.Functions->GetModel(&Info->s); 7779 error=ss.Phone.Functions->GetModel(&ss);
7608 if (error == ERR_NONE) { 7780 if (error == ERR_NONE) {
7609 if (!SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device); 7781 if (!SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device);
7610 printmsg(" Manufacturer : %s\n", 7782 printmsg(" Manufacturer : %s\n",
7611 Info->s.Phone.Data.Manufacturer); 7783 ss.Phone.Data.Manufacturer);
7612 printmsg(" Model : %s (%s)\n", 7784 printmsg(" Model : %s (%s)\n",
7613 Info->s.Phone.Data.ModelInfo->model, 7785 ss.Phone.Data.ModelInfo->model,
7614 Info->s.Phone.Data.Model); 7786 ss.Phone.Data.Model);
7615 } else { 7787 } else {
7616 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); 7788 if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg));
7617 } 7789 }
7618 } else { 7790 } else {
7619 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); 7791 if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg));
7620 } 7792 }
7621 } else { 7793 } else {
7622 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); 7794 if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg));
7623 } 7795 }
7624 if (error != ERR_DEVICEOPENERROR) { 7796 if (error != ERR_DEVICEOPENERROR) {
7625 GSM_TerminateConnection(&Info->s); 7797 GSM_TerminateConnection(&ss);
7626 dbgprintf("Closing done\n"); 7798 dbgprintf("Closing done\n");
7627 } 7799 }
7628 if (error == ERR_DEVICEOPENERROR || error == ERR_NONE) break; 7800 if (error == ERR_DEVICEOPENERROR) break;
7629 j++; 7801 j++;
7630 } 7802 }
7631 num--; 7803 num--;
7632#endif 7804#endif
7633} 7805}
7634 7806
7635//#undef HAVE_PTHREAD
7636//#if 0
7637#if defined(WIN32) || defined(HAVE_PTHREAD) 7807#if defined(WIN32) || defined(HAVE_PTHREAD)
7638#ifdef HAVE_PTHREAD 7808#ifdef HAVE_PTHREAD
7639 pthread_t Thread[100]; 7809 pthread_t Thread[100];
7640#endif 7810#endif
7641 7811
7812OneDeviceInfo SearchDevices[60];
7813
7642void MakeSearchThread(int i) 7814void MakeSearchThread(int i)
7643{ 7815{
7644 num++; 7816 num++;
7645#ifdef HAVE_PTHREAD 7817#ifdef HAVE_PTHREAD
7646 if (pthread_create(&Thread[i],NULL,(void *)SearchPhoneThread,&SearchDevices[i])!=0) { 7818 if (pthread_create(&Thread[i],NULL,(void *)SearchPhoneThread,&SearchDevices[i])!=0) {
7647 dbgprintf("Error creating thread\n"); 7819 dbgprintf("Error creating thread\n");
@@ -7664,18 +7836,19 @@ static void SearchPhone(int argc, char *argv[])
7664 7836
7665 num = 0; 7837 num = 0;
7666#ifdef WIN32 7838#ifdef WIN32
7667# ifdef GSM_ENABLE_IRDADEVICE 7839# ifdef GSM_ENABLE_IRDADEVICE
7668 sprintf(SearchDevices[dev].Device,""); 7840 sprintf(SearchDevices[dev].Device,"");
7669 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet"); 7841 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet");
7670 SearchDevices[dev].Connections[1].Connection[0] = 0; 7842 sprintf(SearchDevices[dev].Connections[1].Connection,"irdaat");
7843 SearchDevices[dev].Connections[2].Connection[0] = 0;
7671 dev++; 7844 dev++;
7672# endif 7845# endif
7673# ifdef GSM_ENABLE_SERIALDEVICE 7846# ifdef GSM_ENABLE_SERIALDEVICE
7674 dev2 = dev; 7847 dev2 = dev;
7675 for(i=0;i<10;i++) { 7848 for(i=0;i<20;i++) {
7676 sprintf(SearchDevices[dev2].Device,"com%i:",i+1); 7849 sprintf(SearchDevices[dev2].Device,"com%i:",i+1);
7677 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3"); 7850 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7678 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus"); 7851 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7679 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200"); 7852 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7680 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus"); 7853 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7681 SearchDevices[dev2].Connections[4].Connection[0] = 0; 7854 SearchDevices[dev2].Connections[4].Connection[0] = 0;
@@ -7727,13 +7900,13 @@ static void SearchPhone(int argc, char *argv[])
7727 for(i=0;i<dev;i++) MakeSearchThread(i); 7900 for(i=0;i<dev;i++) MakeSearchThread(i);
7728 while (num != 0) my_sleep(5); 7901 while (num != 0) my_sleep(5);
7729 for(i=dev;i<dev2;i++) MakeSearchThread(i); 7902 for(i=dev;i<dev2;i++) MakeSearchThread(i);
7730 while (num != 0) my_sleep(5); 7903 while (num != 0) my_sleep(5);
7731} 7904}
7732#endif /*Support for threads */ 7905#endif /*Support for threads */
7733// #if 0 7906
7734static void NokiaGetADC(int argc, char *argv[]) 7907static void NokiaGetADC(int argc, char *argv[])
7735{ 7908{
7736 GSM_Init(true); 7909 GSM_Init(true);
7737 7910
7738#ifdef GSM_ENABLE_NOKIA_DCT3 7911#ifdef GSM_ENABLE_NOKIA_DCT3
7739 DCT3GetADC(argc,argv); 7912 DCT3GetADC(argc,argv);
@@ -7790,13 +7963,13 @@ static void NokiaVibraTest(int argc, char *argv[])
7790static GSM_Parameters Parameters[] = { 7963static GSM_Parameters Parameters[] = {
7791 {"--identify", 0, 0, Identify, {H_Info,0}, ""}, 7964 {"--identify", 0, 0, Identify, {H_Info,0}, ""},
7792 {"--version", 0, 0, Version, {H_Other,0}, ""}, 7965 {"--version", 0, 0, Version, {H_Other,0}, ""},
7793 {"--getdisplaystatus", 0, 0, GetDisplayStatus, {H_Info,0}, ""}, 7966 {"--getdisplaystatus", 0, 0, GetDisplayStatus, {H_Info,0}, ""},
7794 {"--monitor", 0, 1, Monitor, {H_Info,H_Network,H_Call,0},"[times]"}, 7967 {"--monitor", 0, 1, Monitor, {H_Info,H_Network,H_Call,0},"[times]"},
7795 {"--setautonetworklogin", 0, 0, SetAutoNetworkLogin, {H_Network,0}, ""}, 7968 {"--setautonetworklogin", 0, 0, SetAutoNetworkLogin, {H_Network,0}, ""},
7796 {"--listnetworks", 0, 0, ListNetworks, {H_Network,0}, ""}, 7969 {"--listnetworks", 0, 1, ListNetworks, {H_Network,0}, "[country]"},
7797 {"--getgprspoint", 1, 2, GetGPRSPoint, {H_Nokia,H_Network,0}, "start [stop]"}, 7970 {"--getgprspoint", 1, 2, GetGPRSPoint, {H_Nokia,H_Network,0}, "start [stop]"},
7798 {"--addfolder", 2, 2, AddFolder, {H_Filesystem,0}, "parentfolderID name"}, 7971 {"--addfolder", 2, 2, AddFolder, {H_Filesystem,0}, "parentfolderID name"},
7799 {"--getfilesystem", 0, 1, GetFileSystem, {H_Filesystem,0}, "[-flatall|-flat]"}, 7972 {"--getfilesystem", 0, 1, GetFileSystem, {H_Filesystem,0}, "[-flatall|-flat]"},
7800 {"--getfilesystemstatus", 0, 0, GetFileSystemStatus, {H_Filesystem,0}, ""}, 7973 {"--getfilesystemstatus", 0, 0, GetFileSystemStatus, {H_Filesystem,0}, ""},
7801 {"--getfiles", 1,40, GetFiles, {H_Filesystem,0}, "ID1, ID2, ..."}, 7974 {"--getfiles", 1,40, GetFiles, {H_Filesystem,0}, "ID1, ID2, ..."},
7802 {"--getfilefolder", 1,40, GetFileFolder, {H_Filesystem,0}, "ID1, ID2, ..."}, 7975 {"--getfilefolder", 1,40, GetFileFolder, {H_Filesystem,0}, "ID1, ID2, ..."},
@@ -7809,14 +7982,14 @@ static GSM_Parameters Parameters[] = {
7809 {"--playsavedringtone", 1, 1, DCT4PlaySavedRingtone, {H_Ringtone,0}, ""}, 7982 {"--playsavedringtone", 1, 1, DCT4PlaySavedRingtone, {H_Ringtone,0}, ""},
7810 {"--getdatetime", 0, 0, GetDateTime, {H_DateTime,0}, ""}, 7983 {"--getdatetime", 0, 0, GetDateTime, {H_DateTime,0}, ""},
7811 {"--setdatetime", 0, 0, SetDateTime, {H_DateTime,0}, ""}, 7984 {"--setdatetime", 0, 0, SetDateTime, {H_DateTime,0}, ""},
7812 {"--getalarm", 0, 0, GetAlarm, {H_DateTime,0}, ""}, 7985 {"--getalarm", 0, 0, GetAlarm, {H_DateTime,0}, ""},
7813 {"--setalarm", 2, 2, SetAlarm, {H_DateTime,0}, "hour minute"}, 7986 {"--setalarm", 2, 2, SetAlarm, {H_DateTime,0}, "hour minute"},
7814 {"--resetphonesettings", 1, 1, ResetPhoneSettings, {H_Settings,0}, "PHONE|DEV|UIF|ALL|FACTORY"}, 7987 {"--resetphonesettings", 1, 1, ResetPhoneSettings, {H_Settings,0}, "PHONE|DEV|UIF|ALL|FACTORY"},
7815 {"--getmemory", 2, 3, GetMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD start [stop]"}, 7988 {"--getmemory", 2, 4, GetMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD start [stop [-nonempty]]"},
7816 {"--getallmemory", 1, 1, GetAllMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD"}, 7989 {"--getallmemory", 1, 2, GetAllMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD"},
7817 {"--searchmemory", 1, 1, SearchMemory, {H_Memory,0}, "text"}, 7990 {"--searchmemory", 1, 1, SearchMemory, {H_Memory,0}, "text"},
7818 {"--listmemorycategory", 1, 1, ListMemoryCategory, {H_Memory, H_Category,0},"text|number"}, 7991 {"--listmemorycategory", 1, 1, ListMemoryCategory, {H_Memory, H_Category,0},"text|number"},
7819 {"--getfmstation", 1, 2, GetFMStation, {H_FM,0}, "start [stop]"}, 7992 {"--getfmstation", 1, 2, GetFMStation, {H_FM,0}, "start [stop]"},
7820 {"--getsmsc", 1, 2, GetSMSC, {H_SMS,0}, "start [stop]"}, 7993 {"--getsmsc", 1, 2, GetSMSC, {H_SMS,0}, "start [stop]"},
7821 {"--getsms", 2, 3, GetSMS, {H_SMS,0}, "folder start [stop]"}, 7994 {"--getsms", 2, 3, GetSMS, {H_SMS,0}, "folder start [stop]"},
7822 {"--deletesms", 2, 3, DeleteSMS, {H_SMS,0}, "folder start [stop]"}, 7995 {"--deletesms", 2, 3, DeleteSMS, {H_SMS,0}, "folder start [stop]"},
@@ -7840,12 +8013,13 @@ static GSM_Parameters Parameters[] = {
7840 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8013 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7841 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS}, 8014 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS},
7842 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8015 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7843 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS}, 8016 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS},
7844 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION frames file1 file2... " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS}, 8017 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION frames file1 file2... " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS},
7845 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR URL Title Sender " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8018 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR URL Title Sender " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
8019 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPINDICATOR URL Title " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7846#ifdef GSM_ENABLE_BACKUP 8020#ifdef GSM_ENABLE_BACKUP
7847 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8021 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7848 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS file location DATA|GPRS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8022 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS file location DATA|GPRS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7849 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8023 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7850 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8024 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7851 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8025 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
@@ -7859,12 +8033,13 @@ static GSM_Parameters Parameters[] = {
7859 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8033 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7860 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS}, 8034 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS},
7861 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8035 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7862 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS}, 8036 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS},
7863 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION destination frames file1 file2... " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS}, 8037 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION destination frames file1 file2... " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS},
7864 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR destination URL Title Sender " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8038 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR destination URL Title Sender " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
8039 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPINDICATOR destination URL Title " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7865#ifdef GSM_ENABLE_BACKUP 8040#ifdef GSM_ENABLE_BACKUP
7866 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8041 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7867 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS destination file location DATA|GPRS " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8042 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS destination file location DATA|GPRS " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7868 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8043 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7869 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8044 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7870 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8045 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
@@ -7904,13 +8079,13 @@ static GSM_Parameters Parameters[] = {
7904 {"--senddtmf", 1, 1, SendDTMF, {H_Call,0}, "sequence"}, 8079 {"--senddtmf", 1, 1, SendDTMF, {H_Call,0}, "sequence"},
7905 {"--getcalendarsettings", 0, 0, GetCalendarSettings, {H_Calendar,H_Settings,0},""}, 8080 {"--getcalendarsettings", 0, 0, GetCalendarSettings, {H_Calendar,H_Settings,0},""},
7906 {"--getalltodo", 0, 0, GetAllToDo, {H_ToDo,0}, ""}, 8081 {"--getalltodo", 0, 0, GetAllToDo, {H_ToDo,0}, ""},
7907 {"--listtodocategory", 1, 1, ListToDoCategory, {H_ToDo, H_Category,0}, "text|number"}, 8082 {"--listtodocategory", 1, 1, ListToDoCategory, {H_ToDo, H_Category,0}, "text|number"},
7908 {"--gettodo", 1, 2, GetToDo, {H_ToDo,0}, "start [stop]"}, 8083 {"--gettodo", 1, 2, GetToDo, {H_ToDo,0}, "start [stop]"},
7909 {"--deletetodo", 1, 2, DeleteToDo, {H_ToDo,0}, "start [stop]"}, 8084 {"--deletetodo", 1, 2, DeleteToDo, {H_ToDo,0}, "start [stop]"},
7910 {"--getnote", 1, 2, GetNote, {H_Note,0}, "start [stop]"}, 8085 {"--getallnotes", 0, 0, GetAllNotes, {H_Note,0}, ""},
7911 {"--deletecalendar", 1, 2, DeleteCalendar, {H_Calendar,0}, "start [stop]"}, 8086 {"--deletecalendar", 1, 2, DeleteCalendar, {H_Calendar,0}, "start [stop]"},
7912 {"--getallcalendar", 0, 0, GetAllCalendar, {H_Calendar,0}, ""}, 8087 {"--getallcalendar", 0, 0, GetAllCalendar, {H_Calendar,0}, ""},
7913 {"--getcalendar", 1, 2, GetCalendar, {H_Calendar,0}, "start [stop]"}, 8088 {"--getcalendar", 1, 2, GetCalendar, {H_Calendar,0}, "start [stop]"},
7914 {"--getcategory", 2, 3, GetCategory, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK start [stop]"}, 8089 {"--getcategory", 2, 3, GetCategory, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK start [stop]"},
7915 {"--getallcategory", 1, 1, GetAllCategories, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK"}, 8090 {"--getallcategory", 1, 1, GetAllCategories, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK"},
7916 {"--reset", 1, 1, Reset, {H_Other,0}, "SOFT|HARD"}, 8091 {"--reset", 1, 1, Reset, {H_Other,0}, "SOFT|HARD"},
@@ -7973,14 +8148,16 @@ static GSM_Parameters Parameters[] = {
7973 {"--nokianetmonitor36", 0, 0, DCT3ResetTest36, {H_Nokia,0}, ""}, 8148 {"--nokianetmonitor36", 0, 0, DCT3ResetTest36, {H_Nokia,0}, ""},
7974 {"--nokiadebug", 1, 2, DCT3SetDebug, {H_Nokia,H_Network,0}, "filename [[v11-22][,v33-44]...]"}, 8149 {"--nokiadebug", 1, 2, DCT3SetDebug, {H_Nokia,H_Network,0}, "filename [[v11-22][,v33-44]...]"},
7975#endif 8150#endif
7976#ifdef GSM_ENABLE_NOKIA_DCT4 8151#ifdef GSM_ENABLE_NOKIA_DCT4
7977 {"--nokiasetvibralevel", 1, 1, DCT4SetVibraLevel, {H_Nokia,H_Other,0}, "level"}, 8152 {"--nokiasetvibralevel", 1, 1, DCT4SetVibraLevel, {H_Nokia,H_Other,0}, "level"},
7978 {"--nokiagetvoicerecord", 1, 1, DCT4GetVoiceRecord, {H_Nokia,H_Other,0}, "location"}, 8153 {"--nokiagetvoicerecord", 1, 1, DCT4GetVoiceRecord, {H_Nokia,H_Other,0}, "location"},
8154#ifdef GSM_ENABLE_NOKIA6510
7979 {"--nokiasetlights", 2, 2, DCT4SetLight, {H_Nokia,H_Tests,0}, "keypad|display|torch on|off"}, 8155 {"--nokiasetlights", 2, 2, DCT4SetLight, {H_Nokia,H_Tests,0}, "keypad|display|torch on|off"},
7980 {"--nokiatuneradio", 0, 0, DCT4TuneRadio, {H_Nokia,H_FM,0}, ""}, 8156 {"--nokiatuneradio", 0, 0, DCT4TuneRadio, {H_Nokia,H_FM,0}, ""},
8157#endif
7981 {"--nokiamakecamerashoot", 0, 0, DCT4MakeCameraShoot, {H_Nokia,H_Other,0}, ""}, 8158 {"--nokiamakecamerashoot", 0, 0, DCT4MakeCameraShoot, {H_Nokia,H_Other,0}, ""},
7982 {"--nokiagetscreendump", 0, 0, DCT4GetScreenDump, {H_Nokia,H_Other,0}, ""}, 8159 {"--nokiagetscreendump", 0, 0, DCT4GetScreenDump, {H_Nokia,H_Other,0}, ""},
7983#endif 8160#endif
7984#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 8161#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
7985 {"--nokiavibratest", 0, 0, NokiaVibraTest, {H_Nokia,H_Tests,0}, ""}, 8162 {"--nokiavibratest", 0, 0, NokiaVibraTest, {H_Nokia,H_Tests,0}, ""},
7986 {"--nokiagett9", 0, 0, NokiaGetT9, {H_Nokia,H_SMS,0}, ""}, 8163 {"--nokiagett9", 0, 0, NokiaGetT9, {H_Nokia,H_SMS,0}, ""},
@@ -8043,17 +8220,17 @@ static void HelpGeneral(void)
8043{ 8220{
8044 inti=0; 8221 inti=0;
8045 8222
8046 HelpHeader(); 8223 HelpHeader();
8047 8224
8048 printmsg("Usage: gammu [confign] [nothing|text|textall|binary|errors] [options]\n\n"); 8225 printmsg("Usage: gammu [confign] [nothing|text|textall|binary|errors] [options]\n\n");
8049 printmsg("First parameter optionally specifies which config section to use (by default are probed all).\n"); 8226 printmsg("First parameter optionally specifies which config section to use (all are probed by default).\n");
8050 printmsg("Second parameter optionally controls debug level, next specify actions.\n\n"); 8227 printmsg("Second parameter optionally controls debug level, next one specifies actions.\n\n");
8051 8228
8052 /* We might want to put here some most used commands */ 8229 /* We might want to put here some most used commands */
8053 printmsg("For more details call help on specific topic (gammu --help topic), topics are:\n\n"); 8230 printmsg("For more details, call help on specific topic (gammu --help topic). Topics are:\n\n");
8054 8231
8055 while (HelpDescriptions[i].category != 0) { 8232 while (HelpDescriptions[i].category != 0) {
8056 printf("%11s - %s\n", HelpDescriptions[i].option, HelpDescriptions[i].description); 8233 printf("%11s - %s\n", HelpDescriptions[i].option, HelpDescriptions[i].description);
8057 i++; 8234 i++;
8058 } 8235 }
8059 printf("\n"); 8236 printf("\n");
@@ -8131,13 +8308,13 @@ static void Help(int argc, char *argv[])
8131 } 8308 }
8132 8309
8133 if (!strcmp(argv[2],"all")) { 8310 if (!strcmp(argv[2],"all")) {
8134 HelpHeader(); 8311 HelpHeader();
8135 } else { 8312 } else {
8136 while (HelpDescriptions[i].category != 0) { 8313 while (HelpDescriptions[i].category != 0) {
8137 if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; 8314 if (mystrncasecmp(argv[2], HelpDescriptions[i].option,strlen(argv[2]))) break;
8138 i++; 8315 i++;
8139 } 8316 }
8140 if (HelpDescriptions[i].category == 0) { 8317 if (HelpDescriptions[i].category == 0) {
8141 HelpGeneral(); 8318 HelpGeneral();
8142 printmsg("Unknown help topic specified!\n"); 8319 printmsg("Unknown help topic specified!\n");
8143 return; 8320 return;
@@ -8203,38 +8380,33 @@ static void Help(int argc, char *argv[])
8203 HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); 8380 HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help);
8204 } 8381 }
8205 } 8382 }
8206 j++; 8383 j++;
8207 } 8384 }
8208} 8385}
8209#if 0 8386
8210#endif // 0
8211int main(int argc, char *argv[]) 8387int main(int argc, char *argv[])
8212{ 8388{
8213 8389 int z = 0,start=0,i;
8214 //fprintf(stderr,"HIIIIIIIIIIIII \n"); 8390 intonly_config = -1;
8215 //#if 0 8391#if !defined(WIN32) && !defined(DJGPP) && defined(LOCALE_PATH)
8216 static int z ,start,i; 8392 char*locale, locale_file[201];
8217 static intonly_config ;
8218#if !defined(WIN32) && defined(LOCALE_PATH)
8219 static char*locale, locale_file[201];
8220#endif 8393#endif
8221 static char*cp; 8394 char*cp;
8222 static boolcount_failed; 8395 boolcount_failed = false;
8223 z = 0; 8396
8224 start=0;only_config = -1;count_failed = false;
8225 s.opened = false; 8397 s.opened = false;
8226 s.msg = NULL; 8398 s.msg = NULL;
8227 s.ConfigNum = 0; 8399 s.ConfigNum = 0;
8228 8400
8229 setlocale(LC_ALL, ""); 8401 setlocale(LC_ALL, "");
8230#ifdef DEBUG 8402#ifdef DEBUG
8231 di.dl = DL_TEXTALL; 8403 di.dl = DL_TEXTALL;
8232 di.df = stdout; 8404 di.df = stdout;
8233#endif 8405#endif
8234 //#if 0 8406
8235 /* Any parameters? */ 8407 /* Any parameters? */
8236 if (argc == 1) { 8408 if (argc == 1) {
8237 HelpGeneral(); 8409 HelpGeneral();
8238 printmsg("Too few parameters!\n"); 8410 printmsg("Too few parameters!\n");
8239 exit(1); 8411 exit(1);
8240 } 8412 }
@@ -8243,74 +8415,30 @@ int main(int argc, char *argv[])
8243 if (strncmp(argv[1 + start], "--help", 6) == 0) { 8415 if (strncmp(argv[1 + start], "--help", 6) == 0) {
8244 Help(argc - start, argv + start); 8416 Help(argc - start, argv + start);
8245 exit(1); 8417 exit(1);
8246 } 8418 }
8247 8419
8248 /* Is first parameter numeric? If so treat it as config that should be loaded. */ 8420 /* Is first parameter numeric? If so treat it as config that should be loaded. */
8249 //if (isdigit(argv[1][0])) { 8421 if (isdigit(argv[1][0])) {
8250 //only_config = atoi(argv[1]); 8422 only_config = atoi(argv[1]);
8251 //if (only_config >= 0) start++; else only_config = -1; 8423 if (only_config >= 0) start++; else only_config = -1;
8252 //}
8253 only_config = 0;;
8254#if 0
8255 GSM_ReadConfig(NULL, &s.Config[0], 0);
8256 s.ConfigNum = 1;
8257 GSM_Config *con = &s.Config[0];
8258
8259 char* tempC;
8260 tempC = argv[argc-1]+2;
8261 if ( *tempC != 0 ) {
8262 fprintf(stderr,"Using model %s \n",tempC);
8263 strcpy(con->Model,tempC );
8264 }
8265 tempC = argv[argc-2]+2;
8266 if ( *tempC != 0 ) {
8267 fprintf(stderr,"Using device %s \n",tempC);
8268 con->Device = strdup(tempC);
8269 con->DefaultDevice = false;
8270 }
8271 tempC = argv[argc-3]+2;
8272 if ( *tempC != 0 ) {
8273 fprintf(stderr,"Using connection %s \n",tempC);
8274 con->Connection = strdup(tempC);
8275 con->DefaultConnection = false;
8276 }
8277 argc = argc-3;
8278 //#if 0
8279 if ( ! mConnection.isEmpty() ) {
8280 cfg->Connection = strdup(mConnection.latin1());
8281 cfg->DefaultConnection = false;
8282 qDebug("Connection set %s ", cfg->Connection );
8283
8284 } 8424 }
8285 if ( ! mDevice.isEmpty() ) {
8286 cfg->Device = strdup(mDevice.latin1());
8287 cfg->DefaultDevice = false;
8288 qDebug("Device set %s ", cfg->Device);
8289
8290 }
8291 if ( ! mModel.isEmpty() ) {
8292 strcpy(cfg->Model,mModel.latin1() );
8293 cfg->DefaultModel = false;
8294 qDebug("Model set %s ",cfg->Model );
8295 }
8296
8297#endif
8298
8299 8425
8300 cfg=GSM_FindGammuRC(); 8426 cfg=GSM_FindGammuRC();
8427 if (cfg == NULL) printmsg("Warning: No configuration file found!\n");
8428
8301 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 8429 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
8302 if (cfg!=NULL) { 8430 if (cfg!=NULL) {
8303 cp = INI_GetValue(cfg, "gammu", "gammucoding", false); 8431 cp = INI_GetValue(cfg, "gammu", "gammucoding", false);
8304 if (cp) di.coding = cp; 8432 if (cp) di.coding = cp;
8305 8433
8306 s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); 8434 s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false);
8307 if (s.Config[i].Localize) { 8435 if (s.Config[i].Localize) {
8308 s.msg=INI_ReadFile(s.Config[i].Localize, true); 8436 s.msg=INI_ReadFile(s.Config[i].Localize, true);
8309 } else { 8437 } else {
8310#if !defined(WIN32) && defined(LOCALE_PATH) 8438#if !defined(WIN32) && !defined(DJGPP) && defined(LOCALE_PATH)
8311 locale = setlocale(LC_MESSAGES, NULL); 8439 locale = setlocale(LC_MESSAGES, NULL);
8312 if (locale != NULL) { 8440 if (locale != NULL) {
8313 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 8441 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
8314 LOCALE_PATH, 8442 LOCALE_PATH,
8315 tolower(locale[0]), 8443 tolower(locale[0]),
8316 tolower(locale[1])); 8444 tolower(locale[1]));
@@ -8318,13 +8446,12 @@ int main(int argc, char *argv[])
8318 } 8446 }
8319#endif 8447#endif
8320 } 8448 }
8321 } 8449 }
8322 8450
8323 /* Wanted user specific configuration? */ 8451 /* Wanted user specific configuration? */
8324
8325 if (only_config != -1) { 8452 if (only_config != -1) {
8326 /* Here we get only in first for loop */ 8453 /* Here we get only in first for loop */
8327 if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; 8454 if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break;
8328 } else { 8455 } else {
8329 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 8456 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
8330 } 8457 }
@@ -8354,35 +8481,12 @@ int main(int argc, char *argv[])
8354 Print_Error(error); 8481 Print_Error(error);
8355 } 8482 }
8356 8483
8357 /* We wanted to read just user specified configuration. */ 8484 /* We wanted to read just user specified configuration. */
8358 if (only_config != -1) {break;} 8485 if (only_config != -1) {break;}
8359 } 8486 }
8360#if 0
8361 GSM_Config *con = &s.Config[0];
8362
8363 char* tempC;
8364 tempC = argv[argc-1]+2;
8365 if ( *tempC != 0 ) {
8366 fprintf(stderr,"Using model %s \n",tempC);
8367 strcpy(con->Model,tempC );
8368 }
8369 tempC = argv[argc-2]+2;
8370 if ( *tempC != 0 ) {
8371 fprintf(stderr,"Using device %s \n",tempC);
8372 con->Device = strdup(tempC);
8373 con->DefaultDevice = false;
8374 }
8375 tempC = argv[argc-3]+2;
8376 if ( *tempC != 0 ) {
8377 fprintf(stderr,"Using connection %s \n",tempC);
8378 con->Connection = strdup(tempC);
8379 con->DefaultConnection = false;
8380 }
8381#endif
8382
8383 8487
8384 /* Do we have enough parameters? */ 8488 /* Do we have enough parameters? */
8385 if (argc == 1 + start) { 8489 if (argc == 1 + start) {
8386 HelpGeneral(); 8490 HelpGeneral();
8387 printmsg("Too few parameters!\n"); 8491 printmsg("Too few parameters!\n");
8388 exit(-2); 8492 exit(-2);
@@ -8396,13 +8500,12 @@ int main(int argc, char *argv[])
8396 } 8500 }
8397 8501
8398 /* Check parameters */ 8502 /* Check parameters */
8399 while (Parameters[z].Function != NULL) { 8503 while (Parameters[z].Function != NULL) {
8400 if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { 8504 if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) {
8401 if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { 8505 if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) {
8402 fprintf(stderr,"Executing \n");
8403 Parameters[z].Function(argc - start, argv + start); 8506 Parameters[z].Function(argc - start, argv + start);
8404 break; 8507 break;
8405 } else { 8508 } else {
8406 count_failed = true; 8509 count_failed = true;
8407 } 8510 }
8408 } 8511 }
@@ -8418,14 +8521,13 @@ int main(int argc, char *argv[])
8418 printmsg("Bad option!\n"); 8521 printmsg("Bad option!\n");
8419 } 8522 }
8420 } 8523 }
8421 8524
8422 /* Close debug output if opened */ 8525 /* Close debug output if opened */
8423 if (di.df!=stdout) fclose(di.df); 8526 if (di.df!=stdout) fclose(di.df);
8424 //#endif // 0 8527
8425 fprintf(stderr,"kammu: Success. End. \n");
8426 exit(0); 8528 exit(0);
8427} 8529}
8428 8530
8429/* How should editor hadle tabs in this file? Add editor commands here. 8531/* How should editor hadle tabs in this file? Add editor commands here.
8430 * vim: noexpandtab sw=8 ts=8 sts=8: 8532 * vim: noexpandtab sw=8 ts=8 sts=8:
8431 */ 8533 */
diff --git a/gammu/emb/gammu/gammu.h b/gammu/emb/gammu/gammu.h
index d3de31b..ff50c9c 100644
--- a/gammu/emb/gammu/gammu.h
+++ b/gammu/emb/gammu/gammu.h
@@ -54,17 +54,17 @@ typedef struct {
54} GSM_Parameters; 54} GSM_Parameters;
55 55
56 void Print_Error (GSM_Error error); 56 void Print_Error (GSM_Error error);
57 void GSM_Init (bool checkerror); 57 void GSM_Init (bool checkerror);
58 void GSM_Terminate (void); 58 void GSM_Terminate (void);
59 59
60 static GSM_StateMachines; 60 extern GSM_StateMachines;
61 static GSM_Phone_Functions*Phone; 61 extern GSM_Phone_Functions*Phone;
62 static GSM_Error error; 62 extern GSM_Error error;
63 63
64 static bool gshutdown; 64 extern volatile bool gshutdown;
65 65
66void interrupt(int sign); 66void interrupt(int sign);
67 67
68#ifdef GSM_ENABLE_BEEP 68#ifdef GSM_ENABLE_BEEP
69 void GSM_PhoneBeep (void); 69 void GSM_PhoneBeep (void);
70#endif 70#endif
diff --git a/gammu/emb/gammu/smsd/s_files.c b/gammu/emb/gammu/smsd/s_files.c
index dac8d9c..b791e58 100644
--- a/gammu/emb/gammu/smsd/s_files.c
+++ b/gammu/emb/gammu/smsd/s_files.c
@@ -1,7 +1,7 @@
1/* (c) 2002-2003 by Joergen Thomsen */ 1/* (c) 2002-2004 by Joergen Thomsen */
2 2
3#include "../../cfg/config.h" 3#include "../../cfg/config.h"
4 4
5#include <string.h> 5#include <string.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <errno.h> 7#include <errno.h>
@@ -103,35 +103,44 @@ static GSM_Error SMSDFiles_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig
103 } 103 }
104 return ERR_NONE; 104 return ERR_NONE;
105} 105}
106 106
107/* Find one multi SMS to sending and return it (or return ERR_EMPTY) 107/* Find one multi SMS to sending and return it (or return ERR_EMPTY)
108 * There is also set ID for SMS 108 * There is also set ID for SMS
109 * File extension convention:
110 * OUTxxxxx.txt : normal text SMS
111 * Options appended to the extension applying to this SMS only:
112 * d: delivery report requested
113 * f: flash SMS
114 * b: WAP bookmark as name,URL
115 * e.g. OUTG20040620_193810_123_+4512345678_xpq.txtdf
116 * is a flash text SMS requesting delivery reports
109 */ 117 */
110static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID) 118static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID)
111{ 119{
112 GSM_Error error = ERR_NOTSUPPORTED; 120 GSM_Error error = ERR_NOTSUPPORTED;
113 GSM_MultiPartSMSInfo SMSInfo; 121 GSM_MultiPartSMSInfo SMSInfo;
122 GSM_WAPBookmark Bookmark;
114 unsigned char FileName[100],FullName[400]; 123 unsigned char FileName[100],FullName[400];
115 unsigned char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; 124 unsigned char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2];
116 unsigned char Buffer2[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; 125 unsigned char Buffer2[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2];
117 FILE *File; 126 FILE *File;
118 int i, len, phlen; 127 int i, len, phlen;
119 char *pos1, *pos2; 128 char *pos1, *pos2, *options;
120#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR & defined HAVE_ALPHASORT 129#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR & defined HAVE_ALPHASORT
121 struct dirent **namelist = NULL; 130 struct dirent **namelist = NULL;
122 int l, m ,n; 131 int l, m ,n;
123 132
124 strcpy(FullName, Config->outboxpath); 133 strcpy(FullName, Config->outboxpath);
125 FullName[strlen(Config->outboxpath)-1] = '\0'; 134 FullName[strlen(Config->outboxpath)-1] = '\0';
126 n = scandir(FullName, &namelist, 0, alphasort); 135 n = scandir(FullName, &namelist, 0, alphasort);
127 m = 0; 136 m = 0;
128 while ((m < n) && ((*(namelist[m]->d_name) == '.') || 137 while ((m < n) && ((*(namelist[m]->d_name) == '.') || // directory and UNIX hidden file
129 !mystrncasecmp(namelist[m]->d_name,"out", 3) || 138 !mystrncasecmp(namelist[m]->d_name,"out", 3) || // must start with 'out'
130 ((strlen(namelist[m]->d_name) >= 4) && 139 ((strlen(namelist[m]->d_name) >= 4) &&
131 !mystrncasecmp(&namelist[m]->d_name[strlen(namelist[m]->d_name)-4],".txt",4) 140 !mystrncasecmp(strrchr(namelist[m]->d_name, '.'),".txt",4)
132 ) 141 )
133 ) 142 )
134 ) m++; 143 ) m++;
135 if (m < n) strcpy(FileName,namelist[m]->d_name); 144 if (m < n) strcpy(FileName,namelist[m]->d_name);
136 for (l=0; l < n; l++) free(namelist[l]); 145 for (l=0; l < n; l++) free(namelist[l]);
137 free(namelist); 146 free(namelist);
@@ -141,58 +150,91 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi
141#else 150#else
142#ifdef WIN32 151#ifdef WIN32
143 struct _finddata_t c_file; 152 struct _finddata_t c_file;
144 long hFile; 153 long hFile;
145 154
146 strcpy(FullName, Config->outboxpath); 155 strcpy(FullName, Config->outboxpath);
147 strcat(FullName, "OUT*.txt"); 156 strcat(FullName, "OUT*.txt*");
148 if((hFile = _findfirst( FullName, &c_file )) == -1L ) { 157 if((hFile = _findfirst( FullName, &c_file )) == -1L ) {
149 return ERR_EMPTY; 158 return ERR_EMPTY;
150 } else { 159 } else {
151 strcpy(FileName,c_file.name); 160 strcpy(FileName,c_file.name);
152 } 161 }
153 _findclose( hFile ); 162 _findclose( hFile );
154 error = ERR_NONE; 163 error = ERR_NONE;
155#endif 164#endif
156#endif 165#endif
157 if (error != ERR_NONE) return error; 166 if (error != ERR_NONE) return error;
158 167 options = strrchr(FileName, '.') + 4;
159 strcpy(FullName, Config->outboxpath); 168 strcpy(FullName, Config->outboxpath);
160 strcat(FullName, FileName); 169 strcat(FullName, FileName);
161 170
162 File = fopen(FullName, "rb"); 171 File = fopen(FullName, "rb");
163 len = fread(Buffer, 1, sizeof(Buffer)-2, File); 172 len = fread(Buffer, 1, sizeof(Buffer)-2, File);
164 fclose(File); 173 fclose(File);
165 if (len<2) return ERR_EMPTY;
166 174
167 if ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) && 175 if ((len < 2) ||
168 (Buffer[0] != 0xFE || Buffer[1] != 0xFF)) { 176 (len >= 2 && ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) &&
177 (Buffer[0] != 0xFE || Buffer[1] != 0xFF)))) {
169 if (len > GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS) len = GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS; 178 if (len > GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS) len = GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS;
170 EncodeUnicode(Buffer2, Buffer, len); 179 EncodeUnicode(Buffer2, Buffer, len);
171 len = len*2; 180 len = len*2;
172 memmove(Buffer, Buffer2, len); 181 memmove(Buffer, Buffer2, len);
173 } 182 }
174 183
175 Buffer[len] = 0; 184 Buffer[len] = 0;
176 Buffer[len+1] = 0; 185 Buffer[len+1] = 0;
177 ReadUnicodeFile(Buffer2,Buffer); 186 ReadUnicodeFile(Buffer2,Buffer);
178 187
188 GSM_ClearMultiPartSMSInfo(&SMSInfo);
189 sms->Number = 0;
190
179 SMSInfo.ReplaceMessage = 0; 191 SMSInfo.ReplaceMessage = 0;
180 SMSInfo.Entries[0].Buffer= Buffer2; 192 SMSInfo.Entries[0].Buffer= Buffer2;
181 SMSInfo.Class = -1; 193 SMSInfo.Class = -1;
182 SMSInfo.EntriesNum = 1; 194 SMSInfo.EntriesNum = 1;
195 Config->currdeliveryreport= -1;
196 if (strchr(options, 'd')) Config->currdeliveryreport= 1;
197 if (strchr(options, 'f')) SMSInfo.Class = 0; /* flash SMS */
198
183 if (mystrncasecmp(Config->transmitformat, "unicode", 0)) { 199 if (mystrncasecmp(Config->transmitformat, "unicode", 0)) {
184 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong; 200 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
185 SMSInfo.UnicodeCoding = true; 201 SMSInfo.UnicodeCoding = true;
186 } else if (mystrncasecmp(Config->transmitformat, "7bit", 0)) { 202 } else if (mystrncasecmp(Config->transmitformat, "7bit", 0)) {
187 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong; 203 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
188 SMSInfo.UnicodeCoding = false; 204 SMSInfo.UnicodeCoding = false;
189 } else { 205 } else {
190 /* auto */ 206 /* auto */
191 SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong; 207 SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong;
192 } 208 }
209
210 if (strchr(options, 'b')) { // WAP bookmark as title,URL
211 SMSInfo.Entries[0].Buffer = NULL;
212 SMSInfo.Entries[0].Bookmark = &Bookmark;
213 SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong;
214 SMSInfo.Entries[0].Bookmark->Location= 0;
215 pos2 = mywstrstr(Buffer2, "\0,");
216 if (pos2 == NULL) {
217 pos2 = Buffer2;
218 } else {
219 *pos2 = '\0'; pos2++; *pos2 = '\0'; pos2++; // replace comma by zero
220 }
221
222 len = UnicodeLength(Buffer2);
223 if (len > 50) len = 50;
224 memmove(&SMSInfo.Entries[0].Bookmark->Title, Buffer2, len * 2);
225 pos1 = &SMSInfo.Entries[0].Bookmark->Title[0] + len * 2;
226 *pos1 = '\0'; pos1++; *pos1 = '\0';
227
228 len = UnicodeLength(pos2);
229 if (len > 255) len = 255;
230 memmove(&SMSInfo.Entries[0].Bookmark->Address, pos2, len * 2);
231 pos1 = &SMSInfo.Entries[0].Bookmark->Address[0] + len * 2;
232 *pos1 = '\0'; pos1++; *pos1 = '\0';
233 }
234
193 GSM_EncodeMultiPartSMS(&SMSInfo,sms); 235 GSM_EncodeMultiPartSMS(&SMSInfo,sms);
194 236
195 pos1 = FileName; 237 pos1 = FileName;
196 strcpy(ID,FileName); 238 strcpy(ID,FileName);
197 for (i = 1; i <= 3 && pos1 != NULL ; i++) pos1 = strchr(++pos1, '_'); 239 for (i = 1; i <= 3 && pos1 != NULL ; i++) pos1 = strchr(++pos1, '_');
198 if (pos1 != NULL) { 240 if (pos1 != NULL) {
@@ -227,21 +269,23 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi
227 EncodeUnicode(sms->SMS[len].Number, pos1, phlen); 269 EncodeUnicode(sms->SMS[len].Number, pos1, phlen);
228 } 270 }
229 271
230#ifdef DEBUG 272#ifdef DEBUG
231 if (sms->Number != 0) { 273 if (sms->Number != 0) {
232 DecodeUnicode(sms->SMS[0].Number,Buffer); 274 DecodeUnicode(sms->SMS[0].Number,Buffer);
233 dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i\n", 275 dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i dlr: %i fls: %i",
234 sms->Number, 276 sms->Number,
235 Buffer, 277 Buffer,
236 DecodeUnicodeString(sms->SMS[0].Text), 278 DecodeUnicodeString(sms->SMS[0].Text),
237 sms->SMS[0].Coding, 279 sms->SMS[0].Coding,
238 sms->SMS[0].Length, 280 sms->SMS[0].Length,
239 sms->SMS[0].UDH.Type, 281 sms->SMS[0].UDH.Type,
240 sms->SMS[0].UDH.Length); 282 sms->SMS[0].UDH.Length,
241 } else dbgprintf("error\n"); 283 Config->currdeliveryreport,
284 SMSInfo.Class);
285 } else dbgprintf("error: SMS-count = 0");
242#endif 286#endif
243 287
244 return ERR_NONE; 288 return ERR_NONE;
245} 289}
246 290
247/* After sending SMS is moved to Sent Items or Error Items. */ 291/* After sending SMS is moved to Sent Items or Error Items. */
@@ -289,25 +333,28 @@ static GSM_Error SMSDFiles_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Con
289 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno); 333 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno);
290 } 334 }
291 return ERR_UNKNOWN; 335 return ERR_UNKNOWN;
292 } 336 }
293} 337}
294 338
295static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK) 339static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR)
296{ 340{
297 if (OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number)); 341 if (err == SMSD_SEND_OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number));
298 342
299 return ERR_NONE; 343 return ERR_NONE;
300} 344}
301 345
302GSM_SMSDService SMSDFiles = { 346GSM_SMSDService SMSDFiles = {
303 NONEFUNCTION, /* Init */ 347 NONEFUNCTION, /* Init */
348 NONEFUNCTION, /* InitAfterConnect */
304 SMSDFiles_SaveInboxSMS, 349 SMSDFiles_SaveInboxSMS,
305 SMSDFiles_FindOutboxSMS, 350 SMSDFiles_FindOutboxSMS,
306 SMSDFiles_MoveSMS, 351 SMSDFiles_MoveSMS,
307 NOTSUPPORTED, /* CreateOutboxSMS*/ 352 NOTSUPPORTED, /* CreateOutboxSMS*/
308 SMSDFiles_AddSentSMSInfo 353 SMSDFiles_AddSentSMSInfo,
354 NOTSUPPORTED, /* RefreshSendStatus*/
355 NOTSUPPORTED /* RefreshPhoneStatus*/
309}; 356};
310 357
311/* How should editor hadle tabs in this file? Add editor commands here. 358/* How should editor handle tabs in this file? Add editor commands here.
312 * vim: noexpandtab sw=8 ts=8 sts=8: 359 * vim: noexpandtab sw=8 ts=8 sts=8:
313 */ 360 */
diff --git a/gammu/emb/gammu/smsd/s_files.h b/gammu/emb/gammu/smsd/s_files.h
index 5cfa05f..ed07ef3 100644
--- a/gammu/emb/gammu/smsd/s_files.h
+++ b/gammu/emb/gammu/smsd/s_files.h
@@ -1,7 +1,7 @@
1/* (c) 2002-2003 by Joergen Thomsen */ 1/* (c) 2002-2004 by Joergen Thomsen */
2 2
3extern GSM_SMSDService SMSDFiles; 3extern GSM_SMSDService SMSDFiles;
4 4
5/* How should editor hadle tabs in this file? Add editor commands here. 5/* How should editor hadle tabs in this file? Add editor commands here.
6 * vim: noexpandtab sw=8 ts=8 sts=8: 6 * vim: noexpandtab sw=8 ts=8 sts=8:
7 */ 7 */
diff --git a/gammu/emb/gammu/smsd/s_mysql.c b/gammu/emb/gammu/smsd/s_mysql.c
index dacc256..5df15e9 100644
--- a/gammu/emb/gammu/smsd/s_mysql.c
+++ b/gammu/emb/gammu/smsd/s_mysql.c
@@ -12,42 +12,230 @@
12# include <windows.h> 12# include <windows.h>
13# pragma comment(lib, "libmysql.lib") 13# pragma comment(lib, "libmysql.lib")
14#endif 14#endif
15 15
16#include "../../common/misc/coding/coding.h" 16#include "../../common/misc/coding/coding.h"
17#include "../../common/service/backup/gsmback.h" 17#include "../../common/service/backup/gsmback.h"
18#include "../gammu.h"
18#include "smsdcore.h" 19#include "smsdcore.h"
19 20
20/* Connects to database */ 21/* Connects to database */
21static GSM_Error SMSDMySQL_Init(GSM_SMSDConfig *Config) 22static GSM_Error SMSDMySQL_Init(GSM_SMSDConfig *Config)
22{ 23{
24 unsigned char buf[400];
25 MYSQL_RES *Res;
26 MYSQL_ROW Row;
27
23 mysql_init(&Config->DB); 28 mysql_init(&Config->DB);
24 if (!mysql_real_connect(&Config->DB,Config->PC,Config->user,Config->password,Config->database,0,NULL,0)) { 29 if (!mysql_real_connect(&Config->DB,Config->PC,Config->user,Config->password,Config->database,0,NULL,0)) {
25 WriteSMSDLog("Error connecting to database: %s\n", mysql_error(&Config->DB)); 30 WriteSMSDLog("Error connecting to database: %s\n", mysql_error(&Config->DB));
26 return ERR_UNKNOWN; 31 return ERR_UNKNOWN;
27 } 32 }
33 sprintf(buf, "SELECT ID FROM `outbox` WHERE 1");
34 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
35 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
36 return ERR_UNKNOWN;
37 }
38 if (!(Res = mysql_store_result(&Config->DB))) {
39 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
40 return ERR_UNKNOWN;
41 }
42 mysql_free_result(Res);
43 sprintf(buf, "SELECT ID FROM `outbox_multipart` WHERE 1");
44 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
45 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
46 return ERR_UNKNOWN;
47 }
48 if (!(Res = mysql_store_result(&Config->DB))) {
49 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
50 return ERR_UNKNOWN;
51 }
52 mysql_free_result(Res);
53 sprintf(buf, "SELECT ID FROM `sentitems` WHERE 1");
54 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
55 WriteSMSDLog("No table for sent sms: %s\n", mysql_error(&Config->DB));
56 return ERR_UNKNOWN;
57 }
58 if (!(Res = mysql_store_result(&Config->DB))) {
59 WriteSMSDLog("No table for sent sms: %s\n", mysql_error(&Config->DB));
60 return ERR_UNKNOWN;
61 }
62 mysql_free_result(Res);
63 sprintf(buf, "SELECT ID FROM `inbox` WHERE 1");
64 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
65 WriteSMSDLog("No table for inbox sms: %s\n", mysql_error(&Config->DB));
66 return ERR_UNKNOWN;
67 }
68 if (!(Res = mysql_store_result(&Config->DB))) {
69 WriteSMSDLog("No table for inbox sms: %s\n", mysql_error(&Config->DB));
70 return ERR_UNKNOWN;
71 }
72 mysql_free_result(Res);
73 sprintf(buf, "SELECT Version FROM `gammu` WHERE 1");
74 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
75 WriteSMSDLog("No Gammu table: %s\n", mysql_error(&Config->DB));
76 return ERR_UNKNOWN;
77 }
78 if (!(Res = mysql_store_result(&Config->DB))) {
79 WriteSMSDLog("No Gammu table: %s\n", mysql_error(&Config->DB));
80 return ERR_UNKNOWN;
81 }
82 if (!(Row = mysql_fetch_row(Res))) {
83 mysql_free_result(Res);
84 WriteSMSDLog("No version info in Gammu table: %s\n", mysql_error(&Config->DB));
85 return ERR_UNKNOWN;
86 }
87 if (atoi(Row[0]) > 4) {
88 mysql_free_result(Res);
89 WriteSMSDLog("DataBase structures are from higher Gammu version");
90 WriteSMSDLog("Please update this client application");
91 return ERR_UNKNOWN;
92 }
93 if (atoi(Row[0]) < 4) {
94 mysql_free_result(Res);
95 WriteSMSDLog("DataBase structures are from older Gammu version");
96 WriteSMSDLog("Please update DataBase, if you want to use this client application");
97 return ERR_UNKNOWN;
98 }
99 mysql_free_result(Res);
100
101 return ERR_NONE;
102}
103
104static GSM_Error SMSDMySQL_InitAfterConnect(GSM_SMSDConfig *Config)
105{
106 unsigned char buf[400],buf2[200];
107
108 sprintf(buf,"DELETE FROM `phones` WHERE `IMEI` = '%s'",s.Phone.Data.IMEI);
109#ifdef DEBUG
110 fprintf(stdout,"%s\n",buf);
111#endif
112 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
113 WriteSMSDLog("Error deleting from database (Init): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
114 return ERR_UNKNOWN;
115 }
116
117 sprintf(buf2,"Gammu %s",VERSION);
118 if (strlen(GetOS()) != 0) {
119 strcat(buf2+strlen(buf2),", ");
120 strcat(buf2+strlen(buf2),GetOS());
121 }
122 if (strlen(GetCompiler()) != 0) {
123 strcat(buf2+strlen(buf2),", ");
124 strcat(buf2+strlen(buf2),GetCompiler());
125 }
126
127 sprintf(buf,"INSERT INTO `phones` (`IMEI`,`ID`,`Send`,`Receive`,`InsertIntoDB`,`TimeOut`,`Client`) VALUES ('%s','%s','yes','yes',NOW(),(NOW() + INTERVAL 10 SECOND)+0,'%s')",s.Phone.Data.IMEI,Config->PhoneID,buf2);
128#ifdef DEBUG
129 fprintf(stdout,"%s\n",buf);
130#endif
131 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
132 WriteSMSDLog("Error deleting from database (Init): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
133 return ERR_UNKNOWN;
134 }
135
28 return ERR_NONE; 136 return ERR_NONE;
29} 137}
30 138
31/* Save SMS from phone (called Inbox sms - it's in phone Inbox) somewhere */ 139/* Save SMS from phone (called Inbox sms - it's in phone Inbox) somewhere */
32static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config) 140static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config)
33{ 141{
34 unsigned charbuffer[10000],buffer2[200],buffer3[2]; 142 MYSQL_RES *Res;
143 MYSQL_ROW Row;
144 unsigned char buffer[10000],buffer2[200],buffer3[50];
35 int i,j,z; 145 int i,j,z;
146 GSM_DateTime DT;
147 time_t t_time1,t_time2;
148 bool found;
149 long diff;
36 150
37 for (i=0;i<sms.Number;i++) { 151 for (i=0;i<sms.Number;i++) {
38 if ((sms.SMS[i].PDU == SMS_Status_Report) && mystrncasecmp(Config->deliveryreport, "log", 3)) { 152 if (sms.SMS[i].PDU == SMS_Status_Report) {
39 strcpy(buffer, DecodeUnicodeString(sms.SMS[i].Number)); 153 strcpy(buffer2, DecodeUnicodeString(sms.SMS[i].Number));
40 WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer); 154 if (mystrncasecmp(Config->deliveryreport, "log", 3)) {
155 WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer2);
156 }
157
158 sprintf(buffer, "SELECT ID,Status,SendingDateTime,DeliveryDateTime,SMSCNumber FROM `sentitems` WHERE \
159 DeliveryDateTime='00000000000000' AND \
160 SenderID='%s' AND TPMR='%i' AND DestinationNumber='%s'",
161 Config->PhoneID, sms.SMS[i].MessageReference, buffer2);
162#ifdef DEBUG
163 fprintf(stdout,"%s\n",buffer);
164#endif
165 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
166 WriteSMSDLog("Error reading from database (SaveInbox): %s %s\n", buffer, mysql_error(&Config->DB));
167 return ERR_UNKNOWN;
168 }
169 if (!(Res = mysql_store_result(&Config->DB))) {
170 WriteSMSDLog("Error reading from database (SaveInbox): %s\n", mysql_error(&Config->DB));
171 return ERR_UNKNOWN;
172 }
173 found = false;
174 while ((Row = mysql_fetch_row(Res))) {
175 if (strcmp(Row[4],DecodeUnicodeString(sms.SMS[i].SMSC.Number))) {
176 if (Config->skipsmscnumber[0] == 0) continue;
177 if (strcmp(Config->skipsmscnumber,Row[4])) continue;
178 }
179 if (!strcmp(Row[1],"SendingOK") || !strcmp(Row[1],"DeliveryPending")) {
180 sprintf(buffer,"%c%c%c%c",Row[2][0],Row[2][1],Row[2][2],Row[2][3]);
181 DT.Year = atoi(buffer);
182 sprintf(buffer,"%c%c",Row[2][4],Row[2][5]);
183 DT.Month = atoi(buffer);
184 sprintf(buffer,"%c%c",Row[2][6],Row[2][7]);
185 DT.Day = atoi(buffer);
186 sprintf(buffer,"%c%c",Row[2][8],Row[2][9]);
187 DT.Hour = atoi(buffer);
188 sprintf(buffer,"%c%c",Row[2][10],Row[2][11]);
189 DT.Minute = atoi(buffer);
190 sprintf(buffer,"%c%c",Row[2][12],Row[2][13]);
191 DT.Second = atoi(buffer);
192 t_time1 = Fill_Time_T(DT,0);
193 t_time2 = Fill_Time_T(sms.SMS[i].DateTime,0);
194 diff = t_time2 - t_time1;
195 // fprintf(stderr,"diff is %i, %i-%i-%i-%i-%i and %i-%i-%i-%i-%i-%i\n",diff,
196 // DT.Year,DT.Month,DT.Day,DT.Hour,DT.Minute,DT.Second,
197 // sms.SMS[i].DateTime.Year,sms.SMS[i].DateTime.Month,sms.SMS[i].DateTime.Day,sms.SMS[i].DateTime.Hour,sms.SMS[i].DateTime.Minute,sms.SMS[i].DateTime.Second);
198 if (diff > -10 && diff < 10) {
199 found = true;
200 break;
201 }
202 }
203 }
204 if (found) {
205 sprintf(buffer,"UPDATE `sentitems` SET `DeliveryDateTime`='%04i%02i%02i%02i%02i%02i', `Status`='",
206 sms.SMS[i].SMSCTime.Year,sms.SMS[i].SMSCTime.Month,sms.SMS[i].SMSCTime.Day,
207 sms.SMS[i].SMSCTime.Hour,sms.SMS[i].SMSCTime.Minute,sms.SMS[i].SMSCTime.Second);
208 sprintf(buffer3,"%s",DecodeUnicodeString(sms.SMS[i].Text));
209 if (!strcmp(buffer3,"Delivered")) {
210 sprintf(buffer+strlen(buffer),"DeliveryOK");
211 } else if (!strcmp(buffer3,"Failed")) {
212 sprintf(buffer+strlen(buffer),"DeliveryFailed");
213 } else if (!strcmp(buffer3,"Pending")) {
214 sprintf(buffer+strlen(buffer),"DeliveryPending");
215 } else if (!strcmp(buffer3,"Unknown")) {
216 sprintf(buffer+strlen(buffer),"DeliveryUnknown");
217 }
218 sprintf(buffer+strlen(buffer),"', `StatusError` = '%i'",sms.SMS[i].DeliveryStatus);
219 sprintf(buffer+strlen(buffer)," WHERE `ID` = '%s' AND `TPMR` = '%i'",Row[0],sms.SMS[i].MessageReference);
220#ifdef DEBUG
221 fprintf(stdout,"%s\n",buffer);
222#endif
223 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
224 WriteSMSDLog("Error writing to database (SaveInboxSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
225 return ERR_UNKNOWN;
226 }
227 }
228 mysql_free_result(Res);
41 continue; 229 continue;
42 } 230 }
43 if (sms.SMS[i].PDU != SMS_Deliver) continue; 231 if (sms.SMS[i].PDU != SMS_Deliver) continue;
44 buffer[0]=0; 232 buffer[0]=0;
45 sprintf(buffer+strlen(buffer),"INSERT INTO `Inbox` \ 233 sprintf(buffer+strlen(buffer),"INSERT INTO `inbox` \
46 (`DateTime`,`Text`,`SenderNumber`,`Coding`,`SMSCNumber`,`UDH`, \ 234 (`ReceivingDateTime`,`Text`,`SenderNumber`,`Coding`,`SMSCNumber`,`UDH`, \
47 `Class`,`TextDecoded`) VALUES ('%04d%02d%02d%02d%02d%02d','", 235 `Class`,`TextDecoded`,`RecipientID`) VALUES ('%04d%02d%02d%02d%02d%02d','",
48 sms.SMS[i].DateTime.Year,sms.SMS[i].DateTime.Month,sms.SMS[i].DateTime.Day, 236 sms.SMS[i].DateTime.Year,sms.SMS[i].DateTime.Month,sms.SMS[i].DateTime.Day,
49 sms.SMS[i].DateTime.Hour,sms.SMS[i].DateTime.Minute,sms.SMS[i].DateTime.Second); 237 sms.SMS[i].DateTime.Hour,sms.SMS[i].DateTime.Minute,sms.SMS[i].DateTime.Second);
50 switch (sms.SMS[i].Coding) { 238 switch (sms.SMS[i].Coding) {
51 case SMS_Coding_Unicode: 239 case SMS_Coding_Unicode:
52 case SMS_Coding_Default: 240 case SMS_Coding_Default:
53 EncodeHexUnicode(buffer+strlen(buffer),sms.SMS[i].Text,UnicodeLength(sms.SMS[i].Text)); 241 EncodeHexUnicode(buffer+strlen(buffer),sms.SMS[i].Text,UnicodeLength(sms.SMS[i].Text));
@@ -93,144 +281,260 @@ static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig
93 } 281 }
94 } 282 }
95 break; 283 break;
96 case SMS_Coding_8bit: 284 case SMS_Coding_8bit:
97 break; 285 break;
98 } 286 }
99 sprintf(buffer+strlen(buffer),"')"); 287 sprintf(buffer+strlen(buffer),"','%s')",Config->PhoneID);
288#ifdef DEBUG
289 fprintf(stdout,"%s\n",buffer);
290#endif
100 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 291 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
101 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 292 WriteSMSDLog("Error writing to database (SaveInbox): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
102 return ERR_UNKNOWN; 293 return ERR_UNKNOWN;
103 } 294 }
104 } 295 }
105 296
106 return ERR_NONE; 297 return ERR_NONE;
107} 298}
108 299
300static GSM_Error SMSDMySQL_RefreshSendStatus(GSM_SMSDConfig *Config, unsigned char *ID)
301{
302 unsigned char buffer[10000];
303
304 sprintf(buffer,"UPDATE `outbox` SET `SendingTimeOut`=(now() + INTERVAL 15 SECOND)+0 WHERE `ID` = '%s' AND `SendingTimeOut` < now()",ID);
305 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
306 WriteSMSDLog("Error writing to database (RefreshSendStatus): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
307 return ERR_UNKNOWN;
308 }
309#ifdef DEBUG
310 fprintf(stdout,"%s\n",buffer);
311 #endif
312 if (mysql_affected_rows(&Config->DB) == 0) return ERR_UNKNOWN;
313 return ERR_NONE;
314}
315
109/* Find one multi SMS to sending and return it (or return ERR_EMPTY) 316/* Find one multi SMS to sending and return it (or return ERR_EMPTY)
110 * There is also set ID for SMS 317 * There is also set ID for SMS
111 */ 318 */
112static GSM_Error SMSDMySQL_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID) 319static GSM_Error SMSDMySQL_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID)
113{ 320{
114 unsigned char buf[400]; 321 unsigned char buf[400];
115 MYSQL_RES *Res; 322 MYSQL_RES *Res;
116 MYSQL_ROW Row; 323 MYSQL_ROW Row;
117 int i; 324 int i;
325 bool found = false;
118 326
119 sprintf(buf, "SELECT ID,DateTime FROM `Outbox` WHERE 1"); 327 sprintf(buf, "SELECT ID,InsertIntoDB,SendingDateTime,SenderID FROM `outbox` WHERE SendingDateTime < NOW() AND SendingTimeOut < NOW()");
120 if (mysql_real_query(&Config->DB,buf,strlen(buf))) { 328 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
121 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 329 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
122 return ERR_UNKNOWN; 330 return ERR_UNKNOWN;
123 } 331 }
124 if (!(Res = mysql_store_result(&Config->DB))) { 332 if (!(Res = mysql_store_result(&Config->DB))) {
125 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 333 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
126 return ERR_UNKNOWN; 334 return ERR_UNKNOWN;
127 } 335 }
128 if (!(Row = mysql_fetch_row(Res))) { 336 while ((Row = mysql_fetch_row(Res))) {
337 sprintf(ID,"%s",Row[0]);
338 sprintf(Config->DT,"%s",Row[1]);
339 if (strlen(Row[3]) == 0 || !strcmp(Row[3],Config->PhoneID)) {
340 if (SMSDMySQL_RefreshSendStatus(Config, ID)==ERR_NONE) {
341 found = true;
342 break;
343 }
344 }
345 }
346 if (!found) {
129 mysql_free_result(Res); 347 mysql_free_result(Res);
130 return ERR_EMPTY; 348 return ERR_EMPTY;
131 } 349 }
132 sprintf(ID,"%s",Row[0]); 350 mysql_free_result(Res);
133 sprintf(Config->DT,"%s",Row[1]);
134 sms->Number = 0; 351 sms->Number = 0;
135 for (i=1;i<10;i++) { 352 for (i=0;i<MAX_MULTI_SMS;i++) {
136 GSM_SetDefaultSMSData(&sms->SMS[sms->Number]); 353 GSM_SetDefaultSMSData(&sms->SMS[i]);
354 sms->SMS[i].SMSC.Number[0] = 0;
355 sms->SMS[i].SMSC.Number[1] = 0;
356 }
357 for (i=1;i<MAX_MULTI_SMS+1;i++) {
137 if (i==1) { 358 if (i==1) {
138 sprintf(buf, "SELECT Text,DestinationNumber,Coding,UDH,SMSCNumber,Class,TextDecoded,ID,MultiPart FROM `Outbox` WHERE ID='%s'",ID); 359 sprintf(buf, "SELECT Text,Coding,UDH,Class,TextDecoded,ID,DestinationNumber,MultiPart,RelativeValidity,DeliveryReport FROM `outbox` WHERE ID='%s'",ID);
139 } else { 360 } else {
140 sprintf(buf, "SELECT Text,DestinationNumber,Coding,UDH,SMSCNumber,Class,TextDecoded,ID,SequencePosition FROM `Outbox_MultiPart` WHERE ID='%s' AND SequencePosition='%i'",ID,i); 361 sprintf(buf, "SELECT Text,Coding,UDH,Class,TextDecoded,ID,SequencePosition FROM `outbox_multipart` WHERE ID='%s' AND SequencePosition='%i'",ID,i);
141 } 362 }
363#ifdef DEBUG
364 fprintf(stdout,"%s\n",buf);
365#endif
142 if (mysql_real_query(&Config->DB,buf,strlen(buf))) { 366 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
143 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 367 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
144 return ERR_UNKNOWN; 368 return ERR_UNKNOWN;
145 } 369 }
146 if (!(Res = mysql_store_result(&Config->DB))) { 370 if (!(Res = mysql_store_result(&Config->DB))) {
147 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 371 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
148 return ERR_UNKNOWN; 372 return ERR_UNKNOWN;
149 } 373 }
150 if (!(Row = mysql_fetch_row(Res))) { 374 if (!(Row = mysql_fetch_row(Res))) {
151 mysql_free_result(Res); 375 mysql_free_result(Res);
152 return ERR_NONE; 376 return ERR_NONE;
153 } 377 }
154 378
155 sms->SMS[sms->Number].Coding=SMS_Coding_Default; 379 sms->SMS[sms->Number].Coding=SMS_Coding_Default;
156 if (!strcmp(Row[2],"Unicode")) sms->SMS[sms->Number].Coding=SMS_Coding_Unicode; 380 if (!strcmp(Row[1],"Unicode")) sms->SMS[sms->Number].Coding=SMS_Coding_Unicode;
157 if (!strcmp(Row[2],"8bit")) sms->SMS[sms->Number].Coding=SMS_Coding_8bit; 381 if (!strcmp(Row[1],"8bit")) sms->SMS[sms->Number].Coding=SMS_Coding_8bit;
158 382
159 if (strlen(Row[0])==0) { 383 if (strlen(Row[0])==0) {
160 EncodeUnicode(sms->SMS[sms->Number].Text,Row[6],strlen(Row[6])); 384 EncodeUnicode(sms->SMS[sms->Number].Text,Row[4],strlen(Row[4]));
161 } else { 385 } else {
162 switch (sms->SMS[sms->Number].Coding) { 386 switch (sms->SMS[sms->Number].Coding) {
163 case SMS_Coding_Unicode: 387 case SMS_Coding_Unicode:
164 case SMS_Coding_Default: 388 case SMS_Coding_Default:
165 DecodeHexUnicode(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0])); 389 DecodeHexUnicode(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0]));
166 break; 390 break;
167 case SMS_Coding_8bit: 391 case SMS_Coding_8bit:
168 DecodeHexBin(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0])); 392 DecodeHexBin(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0]));
169 sms->SMS[sms->Number].Length=strlen(Row[0])/2; 393 sms->SMS[sms->Number].Length=strlen(Row[0])/2;
170 } 394 }
171 } 395 }
172 EncodeUnicode(sms->SMS[sms->Number].Number,Row[1],strlen(Row[1])); 396 if (i == 1) {
397 EncodeUnicode(sms->SMS[sms->Number].Number,Row[6],strlen(Row[6]));
398 } else {
399 CopyUnicodeString(sms->SMS[sms->Number].Number,sms->SMS[0].Number);
400 }
173 sms->SMS[sms->Number].UDH.Type = UDH_NoUDH; 401 sms->SMS[sms->Number].UDH.Type = UDH_NoUDH;
174 if (strlen(Row[3])!=0) { 402 if (strlen(Row[2])!=0) {
175 sms->SMS[sms->Number].UDH.Type = UDH_UserUDH; 403 sms->SMS[sms->Number].UDH.Type = UDH_UserUDH;
176 sms->SMS[sms->Number].UDH.Length = strlen(Row[3])/2; 404 sms->SMS[sms->Number].UDH.Length = strlen(Row[2])/2;
177 DecodeHexBin(sms->SMS[sms->Number].UDH.Text,Row[3],strlen(Row[3])); 405 DecodeHexBin(sms->SMS[sms->Number].UDH.Text,Row[2],strlen(Row[2]));
178 } 406 }
179 EncodeUnicode(sms->SMS[sms->Number].SMSC.Number,Row[4],strlen(Row[4])); 407 sms->SMS[sms->Number].Class = atoi(Row[3]);
180 sms->SMS[sms->Number].Class = atoi(Row[5]);
181 sms->SMS[sms->Number].PDU = SMS_Submit; 408 sms->SMS[sms->Number].PDU = SMS_Submit;
182 sms->SMS[sms->Number].SMSC.Location = 0;
183 sms->Number++; 409 sms->Number++;
184 if (i == 1 && !strcmp(Row[8],"false")) break; 410 if (i==1) {
411 Config->relativevalidity = atoi(Row[8]);
412
413 Config->currdeliveryreport = -1;
414 if (!strcmp(Row[9],"yes")) {
415 Config->currdeliveryreport = 1;
416 } else if (!strcmp(Row[9],"no")) {
417 Config->currdeliveryreport = 0;
185 } 418 }
419
420 if (!strcmp(Row[7],"false")) break;
421
422 }
423 }
424 mysql_free_result(Res);
186 return ERR_NONE; 425 return ERR_NONE;
187} 426}
188 427
189/* After sending SMS is moved to Sent Items or Error Items. */ 428/* After sending SMS is moved to Sent Items or Error Items. */
190static GSM_Error SMSDMySQL_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent) 429static GSM_Error SMSDMySQL_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent)
191{ 430{
192 char *status; 431 unsigned char buffer[10000];
193 unsigned charbuffer[10000],buffer2[200],buffer3[2]; 432
194 int i,j,z; 433 sprintf(buffer,"DELETE FROM `outbox` WHERE `ID` = '%s'",ID);
434 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
435 WriteSMSDLog("Error deleting from database (MoveSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
436 return ERR_UNKNOWN;
437 }
438 sprintf(buffer,"DELETE FROM `outbox_multipart` WHERE `ID` = '%s'",ID);
439 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
440 WriteSMSDLog("Error deleting from database (MoveSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
441 return ERR_UNKNOWN;
442 }
443 return ERR_NONE;
444}
445
446/* Adds SMS to Outbox */
447static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config)
448{
449 unsigned char buffer[10000],buffer2[200],buffer3[2],buffer4[10000];
450 int i,j,z,ID;
451 MYSQL_RES *Res;
452 MYSQL_ROW Row;
195 453
196 if (sent) status = "OK"; else status = "Error"; 454 sprintf(buffer,"SELECT ID FROM outbox ORDER BY ID DESC LIMIT 1");
455 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
456 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
457 return ERR_UNKNOWN;
458 }
459 if (!(Res = mysql_store_result(&Config->DB))) {
460 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
461 return ERR_UNKNOWN;
462 }
463 if ((Row = mysql_fetch_row(Res))) {
464 sprintf(buffer,"%s",Row[0]);
465 ID = atoi(buffer);
466 } else {
467 ID = 0;
468 }
469 mysql_free_result(Res);
197 470
198 for (i=0;i<sms->Number;i++) { 471 for (i=0;i<sms->Number;i++) {
199 buffer[0]=0; 472 buffer[0]=0;
200 sprintf(buffer+strlen(buffer),"UPDATE `SentItems` SET `Text`='"); 473 if (i==0) {
474 sprintf(buffer+strlen(buffer),"INSERT INTO `outbox` (`DeliveryReport`,`MultiPart`,`InsertIntoDB");
475 } else {
476 sprintf(buffer+strlen(buffer),"INSERT INTO `outbox_multipart` (`SequencePosition");
477 }
478 sprintf(buffer+strlen(buffer),"`,`Text`,");
479 if (i==0) {
480 sprintf(buffer+strlen(buffer),"`DestinationNumber`,`RelativeValidity`,");
481 }
482 sprintf(buffer+strlen(buffer),"`Coding`,`UDH`, \
483 `Class`,`TextDecoded`,`ID`) VALUES ('");
484 if (i==0) {
485 if (sms->SMS[i].PDU == SMS_Status_Report) {
486 sprintf(buffer+strlen(buffer),"yes','");
487 } else {
488 sprintf(buffer+strlen(buffer),"default','");
489 }
490 if (sms->Number == 1) {
491 sprintf(buffer+strlen(buffer),"false");
492 } else {
493 sprintf(buffer+strlen(buffer),"true");
494 }
495 sprintf(buffer+strlen(buffer),"',NOW()");
496 } else {
497 sprintf(buffer+strlen(buffer),"%i'",i+1);
498 }
499 sprintf(buffer+strlen(buffer),",'");
201 500
202 switch (sms->SMS[i].Coding) { 501 switch (sms->SMS[i].Coding) {
203 case SMS_Coding_Unicode: 502 case SMS_Coding_Unicode:
204 case SMS_Coding_Default: 503 case SMS_Coding_Default:
205 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[i].Text,UnicodeLength(sms->SMS[i].Text)); 504 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[i].Text,UnicodeLength(sms->SMS[i].Text));
206 break; 505 break;
207 case SMS_Coding_8bit: 506 case SMS_Coding_8bit:
208 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length); 507 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length);
209 } 508 }
210 509 sprintf(buffer+strlen(buffer),"',");
211 sprintf(buffer+strlen(buffer),"',`DestinationNumber`='%s',`Coding`='",DecodeUnicodeString(sms->SMS[i].Number)); 510 if (i==0) {
212 511 sprintf(buffer+strlen(buffer),"'%s',",DecodeUnicodeString(sms->SMS[i].Number));
512 if (sms->SMS[i].SMSC.Validity.Format == SMS_Validity_RelativeFormat) {
513 sprintf(buffer+strlen(buffer),"'%i',",sms->SMS[i].SMSC.Validity.Relative);
514 } else {
515 sprintf(buffer+strlen(buffer),"'-1',");
516 }
517 }
518 sprintf(buffer+strlen(buffer),"'");
213 switch (sms->SMS[i].Coding) { 519 switch (sms->SMS[i].Coding) {
214 case SMS_Coding_Unicode: 520 case SMS_Coding_Unicode:
215 sprintf(buffer+strlen(buffer),"Unicode"); 521 sprintf(buffer+strlen(buffer),"Unicode");
216 break; 522 break;
217 case SMS_Coding_Default: 523 case SMS_Coding_Default:
218 sprintf(buffer+strlen(buffer),"Default"); 524 sprintf(buffer+strlen(buffer),"Default");
219 break; 525 break;
220 case SMS_Coding_8bit: 526 case SMS_Coding_8bit:
221 sprintf(buffer+strlen(buffer),"8bit"); 527 sprintf(buffer+strlen(buffer),"8bit");
222 break; 528 break;
223 } 529 }
224 530 sprintf(buffer+strlen(buffer),"','");
225 sprintf(buffer+strlen(buffer),"',`SMSCNumber`='%s',`UDH`='",DecodeUnicodeString(sms->SMS[i].SMSC.Number));
226 if (sms->SMS[i].UDH.Type != UDH_NoUDH) { 531 if (sms->SMS[i].UDH.Type != UDH_NoUDH) {
227 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length); 532 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length);
228 } 533 }
229 534 sprintf(buffer+strlen(buffer),"','%i','",sms->SMS[i].Class);
230 sprintf(buffer+strlen(buffer),"',`Class`='%i',`TextDecoded`='",sms->SMS[i].Class);
231 switch (sms->SMS[i].Coding) { 535 switch (sms->SMS[i].Coding) {
232 case SMS_Coding_Unicode: 536 case SMS_Coding_Unicode:
233 case SMS_Coding_Default: 537 case SMS_Coding_Default:
234 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[i].Text)); 538 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[i].Text));
235 for (j=0;j<(int)strlen(buffer2);j++) { 539 for (j=0;j<(int)strlen(buffer2);j++) {
236 sprintf(buffer3,"'"); 540 sprintf(buffer3,"'");
@@ -243,95 +547,119 @@ static GSM_Error SMSDMySQL_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Con
243 buffer[z+1]=0; 547 buffer[z+1]=0;
244 buffer[z] =buffer2[j]; 548 buffer[z] =buffer2[j];
245 } 549 }
246 } 550 }
247 break; 551 break;
248 case SMS_Coding_8bit: 552 case SMS_Coding_8bit:
553
249 break; 554 break;
250 } 555 }
251 sprintf(buffer+strlen(buffer),"',`Status`='%s',`DateTime`='%s' ",status,Config->DT); 556 sprintf(buffer+strlen(buffer),"','");
252 sprintf(buffer+strlen(buffer),"WHERE `ID`='%s' AND `SequencePosition`='%i'",ID,i+1); 557 if (i==0) {
253 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 558 while (true) {
254 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 559 ID++;
560 sprintf(buffer4,"SELECT ID FROM sentitems WHERE ID='%i'",ID);
561#ifdef DEBUG
562 fprintf(stdout,"%s\n",buffer4);
563#endif
564 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
565 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
255 return ERR_UNKNOWN; 566 return ERR_UNKNOWN;
256 } 567 }
568 if (!(Res = mysql_store_result(&Config->DB))) {
569 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
570 return ERR_UNKNOWN;
257 } 571 }
258 sprintf(buffer,"DELETE FROM `Outbox` WHERE `ID` = '%s'",ID); 572 if (!(Row = mysql_fetch_row(Res))) {
259 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 573 buffer4[0] = 0;
260 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 574 strcpy(buffer4,buffer);
575 sprintf(buffer4+strlen(buffer4),"%i')",ID);
576#ifdef DEBUG
577 fprintf(stdout,"%s\n",buffer4);
578#endif
579 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
580 if (mysql_errno(&Config->DB) == ER_DUP_ENTRY) {
581 WriteSMSDLog("Duplicated outgoing SMS ID\n");
582 continue;
583 }
584 WriteSMSDLog("Error writing to database (CreateOutbox): %d %s %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB),buffer4);
261 return ERR_UNKNOWN; 585 return ERR_UNKNOWN;
262 } 586 }
263 sprintf(buffer,"DELETE FROM `Outbox_MultiPart` WHERE `ID` = '%s'",ID); 587 mysql_free_result(Res);
264 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 588 break;
265 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 589 }
590 mysql_free_result(Res);
591 }
592 } else {
593 strcpy(buffer4,buffer);
594 sprintf(buffer4+strlen(buffer4),"%i')",ID);
595#ifdef DEBUG
596 fprintf(stdout,"%s\n",buffer4);
597#endif
598 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
599 WriteSMSDLog("Error writing to database (CreateOutbox): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
266 return ERR_UNKNOWN; 600 return ERR_UNKNOWN;
267 } 601 }
602 }
603 }
268 return ERR_NONE; 604 return ERR_NONE;
269} 605}
270 606
271/* Adds SMS to Outbox */ 607
272static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config) 608static GSM_Error SMSDMySQL_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR)
273{ 609{
274 unsigned charbuffer[10000],buffer2[200],buffer3[2],buffer4[10000]; 610 unsigned charbuffer[10000],buffer2[200],buffer3[2],buff[50];
275 int i,j,z; 611 int j,z;
276 GSM_DateTimetime;
277 612
278 for (i=0;i<sms->Number;i++) { 613 if (err == SMSD_SEND_OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number));
279 buffer[0]=0; 614
280 if (i==0) { 615 buff[0] = 0;
281 sprintf(buffer+strlen(buffer),"INSERT INTO `Outbox` (`MultiPart`,`DateTime"); 616 if (err == SMSD_SEND_OK) {
282 } else { 617 if (sms->SMS[Part-1].PDU == SMS_Status_Report) {
283 sprintf(buffer+strlen(buffer),"INSERT INTO `Outbox_MultiPart` (`SequencePosition"); 618 sprintf(buff,"SendingOK");
284 }
285 sprintf(buffer+strlen(buffer),"`,`Text`,`DestinationNumber`,`Coding`,`SMSCNumber`,`UDH`, \
286 `Class`,`TextDecoded`,`ID`) VALUES ('");
287 if (i==0) {
288 if (sms->Number == 1) {
289 sprintf(buffer+strlen(buffer),"false");
290 } else { 619 } else {
291 sprintf(buffer+strlen(buffer),"true"); 620 sprintf(buff,"SendingOKNoReport");
292 } 621 }
293 sprintf(buffer+strlen(buffer),"',NOW()");
294 } else {
295 sprintf(buffer+strlen(buffer),"%i'",i+1);
296 } 622 }
297 sprintf(buffer+strlen(buffer),",'"); 623 if (err == SMSD_SEND_SENDING_ERROR) sprintf(buff,"SendingError");
624 if (err == SMSD_SEND_ERROR) sprintf(buff,"Error");
298 625
299 switch (sms->SMS[i].Coding) { 626 buffer[0] = 0;
627 sprintf(buffer+strlen(buffer),"INSERT INTO `sentitems` \
628 (`ID`,`SequencePosition`,`Status`,`SendingDateTime`, `SMSCNumber`, `TPMR`, \
629 `SenderID`,`Text`,`DestinationNumber`,`Coding`,`UDH`,`Class`,`TextDecoded`,`InsertIntoDB`,`RelativeValidity`) VALUES (");
630 sprintf(buffer+strlen(buffer),"'%s','%i','%s',NOW(),'%s','%i','%s','",ID,Part,buff,DecodeUnicodeString(sms->SMS[Part-1].SMSC.Number),TPMR,Config->PhoneID);
631 switch (sms->SMS[Part-1].Coding) {
300 case SMS_Coding_Unicode: 632 case SMS_Coding_Unicode:
301 case SMS_Coding_Default: 633 case SMS_Coding_Default:
302 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[i].Text,UnicodeLength(sms->SMS[i].Text)); 634 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[Part-1].Text,UnicodeLength(sms->SMS[Part-1].Text));
303 break; 635 break;
304 case SMS_Coding_8bit: 636 case SMS_Coding_8bit:
305 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length); 637 EncodeHexBin(buffer+strlen(buffer),sms->SMS[Part-1].Text,sms->SMS[Part-1].Length);
306 } 638 }
307 sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms->SMS[i].Number)); 639 sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms->SMS[Part-1].Number));
308 switch (sms->SMS[i].Coding) { 640 switch (sms->SMS[Part-1].Coding) {
309 case SMS_Coding_Unicode: 641 case SMS_Coding_Unicode:
310 sprintf(buffer+strlen(buffer),"Unicode"); 642 sprintf(buffer+strlen(buffer),"Unicode");
311 break; 643 break;
312 case SMS_Coding_Default: 644 case SMS_Coding_Default:
313 sprintf(buffer+strlen(buffer),"Default"); 645 sprintf(buffer+strlen(buffer),"Default");
314 break; 646 break;
315 case SMS_Coding_8bit: 647 case SMS_Coding_8bit:
316 sprintf(buffer+strlen(buffer),"8bit"); 648 sprintf(buffer+strlen(buffer),"8bit");
317 break; 649 break;
318 } 650 }
319 sprintf(buffer+strlen(buffer),"','%s'",DecodeUnicodeString(sms->SMS[i].SMSC.Number)); 651 sprintf(buffer+strlen(buffer),"','");
320 if (sms->SMS[i].UDH.Type == UDH_NoUDH) { 652 if (sms->SMS[Part-1].UDH.Type != UDH_NoUDH) {
321 sprintf(buffer+strlen(buffer),",''"); 653 EncodeHexBin(buffer+strlen(buffer),sms->SMS[Part-1].UDH.Text,sms->SMS[Part-1].UDH.Length);
322 } else {
323 sprintf(buffer+strlen(buffer),",'");
324 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length);
325 sprintf(buffer+strlen(buffer),"'");
326 } 654 }
327 sprintf(buffer+strlen(buffer),",'%i','",sms->SMS[i].Class); 655 sprintf(buffer+strlen(buffer),"','%i','",sms->SMS[Part-1].Class);
328 switch (sms->SMS[i].Coding) { 656 switch (sms->SMS[Part-1].Coding) {
329 case SMS_Coding_Unicode: 657 case SMS_Coding_Unicode:
330 case SMS_Coding_Default: 658 case SMS_Coding_Default:
331 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[i].Text)); 659 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[Part-1].Text));
332 for (j=0;j<(int)strlen(buffer2);j++) { 660 for (j=0;j<(int)strlen(buffer2);j++) {
333 sprintf(buffer3,"'"); 661 sprintf(buffer3,"'");
334 z = strlen(buffer); 662 z = strlen(buffer);
335 if (buffer2[j]==buffer3[0]) { 663 if (buffer2[j]==buffer3[0]) {
336 buffer[z+2]=0; 664 buffer[z+2]=0;
337 buffer[z+1]=buffer2[j]; 665 buffer[z+1]=buffer2[j];
@@ -340,74 +668,56 @@ static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon
340 buffer[z+1]=0; 668 buffer[z+1]=0;
341 buffer[z] =buffer2[j]; 669 buffer[z] =buffer2[j];
342 } 670 }
343 } 671 }
344 break; 672 break;
345 case SMS_Coding_8bit: 673 case SMS_Coding_8bit:
346
347 break;
348 }
349 sprintf(buffer+strlen(buffer),"','");
350 if (i==0) {
351 while (true) {
352 GSM_GetCurrentDateTime(&time);
353 buffer4[0] = 0;
354 strcpy(buffer4,buffer);
355 sprintf(buffer4+strlen(buffer4),"%i')",
356 time.Hour*1000000+
357 time.Minute*10000+
358 time.Second*100+time.Day);
359 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
360 if (mysql_errno(&Config->DB) == ER_DUP_ENTRY) {
361 WriteSMSDLog("Duplicated outgoing SMS ID\n");
362 continue;
363 }
364 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
365 return ERR_UNKNOWN;
366 }
367 break; 674 break;
368 } 675 }
676 sprintf(buffer+strlen(buffer),"','%s','",Config->DT);
677 if (sms->SMS[Part-1].SMSC.Validity.Format == SMS_Validity_RelativeFormat) {
678 sprintf(buffer+strlen(buffer),"%i')",sms->SMS[Part-1].SMSC.Validity.Relative);
369 } else { 679 } else {
370 strcpy(buffer4,buffer); 680 sprintf(buffer+strlen(buffer),"-1')");
371 sprintf(buffer4+strlen(buffer4),"%i')",
372 time.Hour*1000000+
373 time.Minute*10000+
374 time.Second*100+time.Day);
375 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
376 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
377 return ERR_UNKNOWN;
378 }
379 } 681 }
682#ifdef DEBUG
683 fprintf(stdout,"%s\n",buffer);
684 #endif
685 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
686 WriteSMSDLog("Error writing to database (AddSent): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
687 return ERR_UNKNOWN;
380 } 688 }
381 return ERR_NONE; 689 return ERR_NONE;
382} 690}
383 691
384static GSM_Error SMSDMySQL_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK) 692static GSM_Error SMSDMySQL_RefreshPhoneStatus(GSM_SMSDConfig *Config)
385{ 693{
386 unsigned char buffer[10000]; 694 unsigned char buffer[500];
387
388 if (OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number));
389 695
390 buffer[0] = 0; 696 sprintf(buffer,"UPDATE `phones` SET `TimeOut`= (NOW() + INTERVAL 10 SECOND)+0");
391 sprintf(buffer+strlen(buffer),"INSERT INTO `SentItems` \ 697 sprintf(buffer+strlen(buffer)," WHERE `IMEI` = '%s'",s.Phone.Data.IMEI);
392 (`ID`,`SequencePosition`,`Status`,`SendingDateTime`) VALUES ("); 698#ifdef DEBUG
393 sprintf(buffer+strlen(buffer),"'%s','%i','Sending',NOW())",ID,Part); 699 fprintf(stdout,"%s\n",buffer);
700#endif
394 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 701 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
395 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 702 WriteSMSDLog("Error writing to database (SaveInboxSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
396 return ERR_UNKNOWN; 703 return ERR_UNKNOWN;
397 } 704 }
398 return ERR_NONE; 705 return ERR_NONE;
399} 706}
400 707
401GSM_SMSDService SMSDMySQL = { 708GSM_SMSDService SMSDMySQL = {
402 SMSDMySQL_Init, 709 SMSDMySQL_Init,
710 SMSDMySQL_InitAfterConnect,
403 SMSDMySQL_SaveInboxSMS, 711 SMSDMySQL_SaveInboxSMS,
404 SMSDMySQL_FindOutboxSMS, 712 SMSDMySQL_FindOutboxSMS,
405 SMSDMySQL_MoveSMS, 713 SMSDMySQL_MoveSMS,
406 SMSDMySQL_CreateOutboxSMS, 714 SMSDMySQL_CreateOutboxSMS,
407 SMSDMySQL_AddSentSMSInfo 715 SMSDMySQL_AddSentSMSInfo,
716 SMSDMySQL_RefreshSendStatus,
717 SMSDMySQL_RefreshPhoneStatus
408}; 718};
409 719
410#endif 720#endif
411 721
412/* How should editor hadle tabs in this file? Add editor commands here. 722/* How should editor hadle tabs in this file? Add editor commands here.
413 * vim: noexpandtab sw=8 ts=8 sts=8: 723 * vim: noexpandtab sw=8 ts=8 sts=8:
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,7 +1,7 @@
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>
6#include <time.h> 6#include <time.h>
7 7
@@ -11,16 +11,19 @@
11#include "s_files.h" 11#include "s_files.h"
12#ifdef HAVE_MYSQL_MYSQL_H 12#ifdef HAVE_MYSQL_MYSQL_H
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;
17static GSM_Error SendingSMSStatus; 18static GSM_Error SendingSMSStatus;
19
18static void SMSSendingSMSStatus (char *Device, int status, int mr) 20static 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;
25 } 28 }
26} 29}
@@ -70,13 +73,13 @@ void WriteSMSDLog(char *format, ...)
70 date_time.Year, date_time.Month, date_time.Day, 73 date_time.Year, date_time.Month, date_time.Day,
71 date_time.Hour, date_time.Minute, date_time.Second,Buffer); 74 date_time.Hour, date_time.Minute, date_time.Second,Buffer);
72 fflush(smsd_log_file); 75 fflush(smsd_log_file);
73 } 76 }
74} 77}
75 78
76void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) 79void 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;
81 static unsigned charemptyPath[1] = "\0"; 84 static unsigned charemptyPath[1] = "\0";
82 85
@@ -99,45 +102,45 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log)
99 102
100 /* Include Numbers used, because we don't want create new variable */ 103 /* Include Numbers used, because we don't want create new variable */
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) {
109 if (log) WriteSMSDLog("No PIN code in %s file",filename); 113 if (log) WriteSMSDLog("No PIN code in %s file",filename);
110 fprintf(stderr,"No PIN code in %s file\n",filename); 114 fprintf(stderr,"No PIN code in %s file\n",filename);
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
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);
139 if (Config->inboxpath == NULL) Config->inboxpath = emptyPath; 142 if (Config->inboxpath == NULL) Config->inboxpath = emptyPath;
140 143
141 Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false); 144 Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false);
142 if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) { 145 if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) {
143 Config->inboxformat = "standard"; 146 Config->inboxformat = "standard";
@@ -157,12 +160,28 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log)
157 if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath; 160 if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath;
158 if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath); 161 if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath);
159 162
160 Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false); 163 Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false);
161 if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath; 164 if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath;
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
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) {
167 if (log) WriteSMSDLog("Include numbers available"); 186 if (log) WriteSMSDLog("Include numbers available");
168 } 187 }
@@ -173,12 +192,14 @@ 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
181bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) 202bool SMSD_CheckSecurity(GSM_SMSDConfig *Config)
182{ 203{
183 GSM_SecurityCode SecurityCode; 204 GSM_SecurityCode SecurityCode;
184 GSM_Error error; 205 GSM_Error error;
@@ -189,12 +210,13 @@ bool SMSD_CheckSecurity(GSM_SMSDConfig *Config)
189 if (error != ERR_NOTSUPPORTED && error != ERR_NONE) { 210 if (error != ERR_NOTSUPPORTED && error != ERR_NONE) {
190 WriteSMSDLog("Error getting security status (%i)", error); 211 WriteSMSDLog("Error getting security status (%i)", error);
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");
199 strcpy(SecurityCode.Code,Config->PINCode); 221 strcpy(SecurityCode.Code,Config->PINCode);
200 error=Phone->EnterSecurityCode(&s,SecurityCode); 222 error=Phone->EnterSecurityCode(&s,SecurityCode);
@@ -323,76 +345,103 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service)
323 GSM_GetCurrentDateTime (&Date); 345 GSM_GetCurrentDateTime (&Date);
324 i=Date.Second; 346 i=Date.Second;
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 }
413 Service->RefreshPhoneStatus(Config);
365 j=0; 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;
370 while (z==Date.Second) { 420 while (z==Date.Second) {
371 my_sleep(10); 421 my_sleep(10);
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 }
397 } 446 }
398 return true; 447 return true;
@@ -400,13 +449,13 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service)
400 449
401void SMSDaemon(int argc, char *argv[]) 450void 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;
411#ifdef HAVE_MYSQL_MYSQL_H 460#ifdef HAVE_MYSQL_MYSQL_H
412 } else if (!strcmp(argv[2],"MYSQL")) { 461 } else if (!strcmp(argv[2],"MYSQL")) {
@@ -414,24 +463,25 @@ void SMSDaemon(int argc, char *argv[])
414#endif 463#endif
415 } else { 464 } else {
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);
425 } 474 }
426 475
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 */
436 if (errors > 2) { 486 if (errors > 2) {
437 if (errors != 255) { 487 if (errors != 255) {
@@ -442,42 +492,68 @@ void SMSDaemon(int argc, char *argv[])
442 WriteSMSDLog("Starting communication"); 492 WriteSMSDLog("Starting communication");
443 error=GSM_InitConnection(&s,2); 493 error=GSM_InitConnection(&s,2);
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;
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 */
450 // di = s.di; 520 // di = s.di;
451 break; 521 break;
452 case ERR_DEVICEOPENERROR: 522 case ERR_DEVICEOPENERROR:
453 GSM_Terminate_SMSD("Can't open device (%i)", error, true, -1); 523 GSM_Terminate_SMSD("Can't open device (%i)", error, true, -1);
454 default: 524 default:
455 WriteSMSDLog("Error at init connection (%i)", error); 525 WriteSMSDLog("Error at init connection (%i)", error);
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++;
466 continue; 536 continue;
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
481GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms) 557GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms)
482{ 558{
483 GSM_SMSDService *Service; 559 GSM_SMSDService *Service;
@@ -491,13 +567,13 @@ GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *s
491#endif 567#endif
492 } else { 568 } else {
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
502 return Service->CreateOutboxSMS(sms,&Config); 578 return Service->CreateOutboxSMS(sms,&Config);
503} 579}
diff --git a/gammu/emb/gammu/smsd/smsdcore.h b/gammu/emb/gammu/smsd/smsdcore.h
index 23e402e..17ffe58 100644
--- a/gammu/emb/gammu/smsd/smsdcore.h
+++ b/gammu/emb/gammu/smsd/smsdcore.h
@@ -1,10 +1,10 @@
1/* (c) 2002-2003 by Marcin Wiacek and Joergen Thomsen */ 1/* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */
2 2
3#include "../../cfg/config.h" 3#include "../../cfg/config.h"
4#undef HAVE_MYSQL_MYSQL_H 4
5#ifdef HAVE_MYSQL_MYSQL_H 5#ifdef HAVE_MYSQL_MYSQL_H
6#ifdef WIN32 6#ifdef WIN32
7# include <mysql.h> 7# include <mysql.h>
8# include <mysqld_error.h> 8# include <mysqld_error.h>
9#else 9#else
10# include <mysql/mysql.h> 10# include <mysql/mysql.h>
@@ -21,37 +21,54 @@ void SMSDaemon (int argc, char *argv[]);
21 GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms); 21 GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms);
22 22
23typedef struct { 23typedef struct {
24 /* general options */ 24 /* general options */
25 INI_Entry *IncludeNumbers, *ExcludeNumbers; 25 INI_Entry *IncludeNumbers, *ExcludeNumbers;
26 unsigned int commtimeout, sendtimeout, receivefrequency; 26 unsigned int commtimeout, sendtimeout, receivefrequency;
27 unsigned intresetfrequency;
27 unsigned char *deliveryreport, *logfilename, *PINCode; 28 unsigned char *deliveryreport, *logfilename, *PINCode;
29 unsigned char*PhoneID;
28 30
29 /* options for FILES */ 31 /* options for FILES */
30 unsigned char *inboxpath, *outboxpath, *sentsmspath; 32 unsigned char *inboxpath, *outboxpath, *sentsmspath;
31 unsigned char *errorsmspath, *inboxformat, *transmitformat; 33 unsigned char *errorsmspath, *inboxformat, *transmitformat;
32 34
33 /* options for MYSQL */ 35 /* options for MYSQL */
34 unsigned char *database, *user, *password; 36 unsigned char *database, *user, *password;
35 unsigned char*PC; 37 unsigned char *PC, *skipsmscnumber;
36 38
37 /* private variables required for work */ 39 /* private variables required for work */
38 unsigned int retries; 40 int relativevalidity;
41 unsigned int retries, currdeliveryreport;
39 unsigned char SMSID[200], prevSMSID[200]; 42 unsigned char SMSID[200], prevSMSID[200];
43 GSM_SMSCSMSC;
40#ifdef HAVE_MYSQL_MYSQL_H 44#ifdef HAVE_MYSQL_MYSQL_H
41 MYSQL DB; char DT[20]; 45 MYSQL DB; char DT[20];
42#endif 46#endif
43} GSM_SMSDConfig; 47} GSM_SMSDConfig;
44 48
49typedef enum {
50 SMSD_SEND_OK = 1,
51 SMSD_SEND_SENDING_ERROR,
52 SMSD_SEND_DELIVERY_PENDING,
53 SMSD_SEND_DELIVERY_FAILED,
54 SMSD_SEND_DELIVERY_OK,
55 SMSD_SEND_DELIVERY_UNKNOWN,
56 SMSD_SEND_ERROR
57} GSM_SMSDSendingError;
58
45typedef struct { 59typedef struct {
46 GSM_Error (*Init) (GSM_SMSDConfig *Config); 60 GSM_Error (*Init) (GSM_SMSDConfig *Config);
61 GSM_Error(*InitAfterConnect) (GSM_SMSDConfig *Config);
47 GSM_Error(*SaveInboxSMS) (GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config); 62 GSM_Error(*SaveInboxSMS) (GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config);
48 GSM_Error(*FindOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID); 63 GSM_Error(*FindOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID);
49 GSM_Error (*MoveSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent); 64 GSM_Error (*MoveSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent);
50 GSM_Error(*CreateOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config); 65 GSM_Error(*CreateOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config);
51 GSM_Error(*AddSentSMSInfo) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK); 66 GSM_Error(*AddSentSMSInfo) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR);
67 GSM_Error(*RefreshSendStatus) (GSM_SMSDConfig *Config, unsigned char *ID);
68 GSM_Error(*RefreshPhoneStatus) (GSM_SMSDConfig *Config);
52} GSM_SMSDService; 69} GSM_SMSDService;
53 70
54#ifdef __GNUC__ 71#ifdef __GNUC__
55__attribute__((format(printf, 1, 2))) 72__attribute__((format(printf, 1, 2)))
56#endif 73#endif
57void WriteSMSDLog(char *format, ...); 74void WriteSMSDLog(char *format, ...);