author | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
commit | 50ab40e1e02ad7c65c17a78d08116a808b1257aa (patch) (side-by-side diff) | |
tree | 0d1939e2297fa7bbd8e1f2030f154463854164c6 /gammu/emb/gammu | |
parent | cf8616f64f20e5448d4ff644f7cc15750cf3f85f (diff) | |
download | kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.zip kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.gz kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.bz2 |
updated to latest gammu version
-rw-r--r-- | gammu/emb/gammu/depend/nokia/dct3.c | 6 | ||||
-rw-r--r-- | gammu/emb/gammu/depend/nokia/dct4.c | 11 | ||||
-rw-r--r-- | gammu/emb/gammu/depend/nokia/dct4.h | 13 | ||||
-rw-r--r-- | gammu/emb/gammu/gammu.c | 662 | ||||
-rw-r--r-- | gammu/emb/gammu/gammu.h | 8 | ||||
-rw-r--r-- | gammu/emb/gammu/smsd/s_files.c | 81 | ||||
-rw-r--r-- | gammu/emb/gammu/smsd/s_files.h | 2 | ||||
-rw-r--r-- | gammu/emb/gammu/smsd/s_mysql.c | 608 | ||||
-rw-r--r-- | gammu/emb/gammu/smsd/smsdcore.c | 180 | ||||
-rw-r--r-- | gammu/emb/gammu/smsd/smsdcore.h | 37 |
10 files changed, 1089 insertions, 519 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 @@ -610,10 +610,14 @@ static GSM_Error DCT3_Reply7191GetSecurityCode(GSM_Protocol_Message msg, GSM_Sta void DCT3GetSecurityCode(int argc, char *argv[]) { +#ifdef GSM_ENABLE_NOKIA6110 unsigned char req6110[] = {0x00, 0x01, 0x6e, 0x01}; /* Code type */ +#endif +#if defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210) unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee, 0x1c}; /* Setting */ +#endif if (CheckDCT3Only()!=ERR_NONE) return; @@ -767,8 +771,10 @@ void DCT3DisplayOutput(int argc, char *argv[]) #endif static GSM_Reply_Function UserReplyFunctions3[] = { +#ifdef GSM_ENABLE_NOKIA6110 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame }, {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 }, +#endif {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity }, {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 }, 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 @@ -35,7 +35,8 @@ GSM_Error CheckDCT4Only() if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 && s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_PHONETBLUE && - s.ConnectionType!=GCT_IRDAPHONET && s.ConnectionType!=GCT_BLUEPHONET) { + s.ConnectionType!=GCT_IRDAPHONET && s.ConnectionType!=GCT_BLUEPHONET && + s.ConnectionType!=GCT_FBUS2DKU5) { return ERR_OTHERCONNECTIONREQUIRED; } return ERR_NONE; @@ -885,6 +886,8 @@ void DCT4GetT9(int argc, char *argv[]) fclose(T9File); } +#ifdef GSM_ENABLE_NOKIA6510 + extern GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, bool enable); void DCT4SetLight(int argc, char *argv[]) @@ -921,6 +924,7 @@ void DCT4SetLight(int argc, char *argv[]) GSM_Terminate(); } +#endif void DCT4DisplayTest(int argc, char *argv[]) { @@ -1021,6 +1025,8 @@ void DCT4GetADC(int argc, char *argv[]) } } +#ifdef GSM_ENABLE_NOKIA6510 + static double RadioFreq; static unsigned char RadioName[100]; @@ -1174,6 +1180,7 @@ void DCT4TuneRadio(int argc, char *argv[]) GSM_Terminate(); } +#endif void DCT4PlaySavedRingtone(int argc, char *argv[]) { @@ -1313,10 +1320,12 @@ static GSM_Reply_Function UserReplyFunctions4[] = { {DCT4_ReplyTestsNames, "\x35",0x02,0x03,ID_User1 }, {DCT4_ReplyTestsStatus, "\x35",0x02,0x04,ID_User2 }, +#ifdef GSM_ENABLE_NOKIA6510 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x09,ID_User3 }, {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_User3 }, {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_SetFMStation}, {DCT4_ReplyTuneRadio, "\x3E",0x03,0x16,ID_User3 }, +#endif {DCT4_ReplyGetVoiceRecord, "\x4A",0x03,0x31,ID_User4 }, 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 @@ -6,21 +6,24 @@ void DCT4SetPhoneMenus (int argc, char *argv[]); void DCT4SelfTests (int argc, char *argv[]); void DCT4SetVibraLevel (int argc, char *argv[]); void DCT4GetSecurityCode (int argc, char *argv[]); -#ifdef DEBUG -void DCT4ResetSecurityCode (int argc, char *argv[]); -#endif void DCT4GetVoiceRecord (int argc, char *argv[]); void DCT4Info (int argc, char *argv[]); void DCT4GetT9 (int argc, char *argv[]); -void DCT4SetLight (int argc, char *argv[]); void DCT4DisplayTest (int argc, char *argv[]); void DCT4GetADC (int argc, char *argv[]); void DCT4VibraTest (int argc, char *argv[]); -void DCT4TuneRadio (int argc, char *argv[]); void DCT4PlaySavedRingtone (int argc, char *argv[]); void DCT4MakeCameraShoot (int argc, char *argv[]); void DCT4GetScreenDump (int argc, char *argv[]); +#ifdef DEBUG + void DCT4ResetSecurityCode (int argc, char *argv[]); +#endif +#ifdef GSM_ENABLE_NOKIA6510 + void DCT4SetLight (int argc, char *argv[]); + void DCT4TuneRadio (int argc, char *argv[]); +#endif + /* ------------------- features matrix ------------------------------------- */ typedef enum { 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 @@ -9,7 +9,6 @@ #include <signal.h> #include <ctype.h> #include <wchar.h> -#undef HAVE_MYSQL_MYSQL_H #ifdef WIN32 # include <windows.h> # include <process.h> @@ -48,27 +47,15 @@ #endif -//static GSM_StateMachine s; -//static GSM_Phone_Functions *Phone; +GSM_StateMachine s; +GSM_Phone_Functions *Phone; static INI_Section *cfg = NULL; -//static GSM_Error error = ERR_NONE; - static int i; +GSM_Error error = ERR_NONE; +static int i; -//static bool gshutdown = false; -typedef struct { - unsigned char Connection[50]; -} OneConnectionInfo; +volatile bool gshutdown = false; -typedef struct { - unsigned char Device[50]; - OneConnectionInfo Connections[6]; - //GSM_StateMachine s; -} OneDeviceInfo; - -static int num; -static OneDeviceInfo SearchDevices[100]; -static bool SearchOutput; void interrupt(int sign) { signal(sign, SIG_IGN); @@ -243,6 +230,7 @@ static GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone) /* Disables buzzer */ return s.Phone.Functions->PlayTone(&s,255*255,0,false); } + static void PlayRingtone(int argc, char *argv[]) { GSM_Ringtone ringtone,ringtone2; @@ -341,7 +329,6 @@ static void Identify(int argc, char *argv[]) GSM_Terminate(); } -//#if 0 static void GetDateTime(int argc, char *argv[]) { GSM_DateTime date_time; @@ -375,6 +362,7 @@ static void GetDateTime(int argc, char *argv[]) case GSM_Date_DDMMYYYY:printmsg("DD MM YYYY");break; case GSM_Date_MMDDYYYY:printmsg("MM DD YYYY");break; case GSM_Date_YYYYMMDD:printmsg("YYYY MM DD"); + default :break; } printmsg(", date separator is %c\n",locale.DateSeparator); } @@ -587,8 +575,9 @@ static void GetAllMemory(int argc, char *argv[]) static void GetMemory(int argc, char *argv[]) { - int j, start, stop; + int j, start, stop, emptynum = 0, fillednum = 0; GSM_MemoryEntry entry; + bool empty = true; entry.MemoryType=0; @@ -607,6 +596,15 @@ static void GetMemory(int argc, char *argv[]) GetStartStop(&start, &stop, 3, argc, argv); + if (argc > 5 && strcmp(argv[5],"")) { + if (mystrncasecmp(argv[5],"-nonempty",0)) { + empty = false; + } else { + printmsg("ERROR: unknown parameter \"%s\"\n",argv[5]); + exit (-1); + } + } + GSM_Init(true); if (!strcmp(s.Phone.Data.ModelInfo->model,"3310")) { @@ -614,7 +612,7 @@ static void GetMemory(int argc, char *argv[]) } for (j=start;j<=stop;j++) { - printmsg("Memory %s, Location %i\n",argv[2],j); + if (empty) printmsg("Memory %s, Location %i\n",argv[2],j); entry.Location=j; @@ -622,12 +620,19 @@ static void GetMemory(int argc, char *argv[]) if (error != ERR_EMPTY) Print_Error(error); if (error == ERR_EMPTY) { - printmsg("Entry is empty\n"); - printf("\n"); + emptynum++; + if (empty) { + printmsg("Entry is empty\n"); + printf("\n"); + } } else { + fillednum++; + if (!empty) printmsg("Memory %s, Location %i\n",argv[2],j); PrintMemoryEntry(&entry); } } + + printmsg("%i entries empty, %i entries filled\n",emptynum,fillednum); GSM_Terminate(); } @@ -674,7 +679,7 @@ static void SearchOneEntry(GSM_MemoryEntry *Entry, unsigned char *Text) case PBK_Text_Custom3 : case PBK_Text_Custom4 : case PBK_Caller_Group : - if (mystrstr(Entry->Entries[i].Text, Text) != NULL) { + if (mywstrstr(Entry->Entries[i].Text, Text) != NULL) { fprintf(stderr,"\n"); printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry->MemoryType),Entry->Location); PrintMemoryEntry(Entry); @@ -824,7 +829,7 @@ static void ListMemoryCategory(int argc, char *argv[]) if (error != ERR_EMPTY) { count++; - if (mystrstr(Category.Name, Text) != NULL) { + if (mywstrstr(Category.Name, Text) != NULL) { ListMemoryCategoryEntries(j); } } @@ -847,7 +852,7 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp case SMS_UnSent : printmsg("UnSent"); break; } printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number)); - printmsg("Reference number: 0x%02X\n",sms.MessageReference); + printmsg("Reference number: %d\n",sms.MessageReference); printmsg("Sent : %s\n",OSDateTime(sms.DateTime,true)); printmsg("SMSC number : \"%s\"\n",DecodeUnicodeConsole(sms.SMSC.Number)); printmsg("SMSC response : %s\n",OSDateTime(sms.SMSCTime,true)); @@ -894,9 +899,13 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp break; case SMS_Deliver: printmsg("SMS message\n"); - printmsg("SMSC number : \"%s\"",DecodeUnicodeConsole(sms.SMSC.Number)); - if (sms.ReplyViaSameSMSC) printmsg(" (set for reply)"); - printmsg("\nSent : %s\n",OSDateTime(sms.DateTime,true)); + if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) { + printmsg("Saved : %s\n",OSDateTime(sms.DateTime,true)); + } else { + printmsg("SMSC number : \"%s\"",DecodeUnicodeConsole(sms.SMSC.Number)); + if (sms.ReplyViaSameSMSC) printmsg(" (set for reply)"); + printmsg("\nSent : %s\n",OSDateTime(sms.DateTime,true)); + } /* No break. The only difference for SMS_Deliver and SMS_Submit is, * that SMS_Deliver contains additional data. We wrote them and then go * for data shared with SMS_Submit @@ -906,7 +915,10 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp /* If we went here from "case SMS_Deliver", we don't write "SMS Message" */ if (sms.PDU==SMS_Submit) { printmsg("SMS message\n"); - printmsg("Reference number : 0x%02X\n",sms.MessageReference); + if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) { + } else { + printmsg("Reference number : %d\n",sms.MessageReference); + } } if (sms.Name[0] != 0x00 || sms.Name[1] != 0x00) { printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(sms.Name)); @@ -920,14 +932,17 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp case SMS_Coding_Default : printmsg("Default GSM alphabet\n"); break; case SMS_Coding_8bit : printmsg("8 bit\n"); break; } + if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) { + } else { + printmsg("Remote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number)); + } printmsg("Status : "); switch (sms.State) { - case SMS_Sent : printmsg("Sent"); break; - case SMS_Read : printmsg("Read"); break; - case SMS_UnRead : printmsg("UnRead"); break; - case SMS_UnSent : printmsg("UnSent"); break; + case SMS_Sent : printmsg("Sent\n"); break; + case SMS_Read : printmsg("Read\n"); break; + case SMS_UnRead : printmsg("UnRead\n"); break; + case SMS_UnSent : printmsg("UnSent\n"); break; } - printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number)); if (sms.UDH.Type != UDH_NoUDH) { printmsg("User Data Header : "); switch (sms.UDH.Type) { @@ -978,7 +993,7 @@ static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool disp break; } } -//#if 0 + static void displaymultismsinfo (GSM_MultiSMSMessage sms, bool eachsms, bool ems) { GSM_MultiPartSMSInfo SMSInfo; @@ -1285,6 +1300,13 @@ static void Monitor(int argc, char *argv[]) GSM_Terminate(); } +static void IncomingUSSD2(char *Device, char *Buffer) +{ + printmsg("Service reply: \"%s\"\n",DecodeUnicodeConsole(Buffer)); + + gshutdown = true; +} + static void GetUSSD(int argc, char *argv[]) { GSM_Init(true); @@ -1292,7 +1314,7 @@ static void GetUSSD(int argc, char *argv[]) signal(SIGINT, interrupt); printmsgerr("Press Ctrl+C to break...\n"); - s.User.IncomingUSSD = IncomingUSSD; + s.User.IncomingUSSD = IncomingUSSD2; error=Phone->SetIncomingUSSD(&s,true); Print_Error(error); @@ -1345,7 +1367,16 @@ static void GetSMSC(int argc, char *argv[]) case SMS_VALID_3_Days : printmsg("72 hours"); break; case SMS_VALID_1_Week : printmsg("1 week"); break; case SMS_VALID_Max_Time : printmsg("Maximum time"); break; - default : printmsg("Unknown"); + default : + if (smsc.Validity.Relative >= 0 && smsc.Validity.Relative <= 143) { + printmsg("%i minutes",(smsc.Validity.Relative+1)*5); + } else if (smsc.Validity.Relative >= 144 && smsc.Validity.Relative <= 167) { + printmsg("%i minutes",12*60 + (smsc.Validity.Relative-143)*30); + } else if (smsc.Validity.Relative >= 168 && smsc.Validity.Relative <= 196) { + printmsg("%i days",smsc.Validity.Relative-166); + } else if (smsc.Validity.Relative >= 197 && smsc.Validity.Relative <= 255) { + printmsg("%i weeks",smsc.Validity.Relative-192); + } } printf("\n"); } @@ -1428,7 +1459,6 @@ static void GetAllSMS(int argc, char *argv[]) error=Phone->GetSMSFolders(&s, &folders); Print_Error(error); - fprintf(stderr,"Reading: "); while (error == ERR_NONE) { sms.SMS[0].Folder=0x00; error=Phone->GetNextSMS(&s, &sms, start); @@ -1448,7 +1478,6 @@ static void GetAllSMS(int argc, char *argv[]) printf("\n"); displaymultismsinfo(sms,false,false); } - fprintf(stderr,"*"); start=false; } fprintf(stderr,"\n"); @@ -1579,7 +1608,8 @@ static void GetRingtone(int argc, char *argv[]) switch (ringtone.Format) { case RING_NOTETONE : printmsg("Smart Messaging"); break; case RING_NOKIABINARY : printmsg("Nokia binary"); break; - case RING_MIDI : printmsg("Midi format"); break; + case RING_MIDI : printmsg("MIDI"); break; + case RING_MMF : printmsg("SMAF (MMF)"); break; } printmsg(" format, ringtone \"%s\"\n",DecodeUnicodeConsole(ringtone.Name)); @@ -2042,8 +2072,8 @@ static void GetAllCalendar(int argc, char *argv[]) while (!gshutdown) { error=Phone->GetNextCalendar(&s,&Note,refresh); if (error == ERR_EMPTY) break; - PrintCalendar(&Note); Print_Error(error); + PrintCalendar(&Note); refresh=false; } @@ -2242,6 +2272,8 @@ static void GetBitmap(int argc, char *argv[]) GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]); printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text)); printmsg("Sender : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Sender)); + if (MultiBitmap.Bitmap[0].Name) + printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Name)); if (argc>4) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap); break; case GSM_WelcomeNote_Text: @@ -2505,7 +2537,7 @@ static void DisplaySMSFrame(GSM_SMSMessage *SMS) #define SEND_SAVE_SMS_BUFFER_SIZE 10000 static GSM_Error SMSStatus; -//#if 0 + static void SendSMSStatus (char *Device, int status, int MessageReference) { dbgprintf("Sent SMS on device: \"%s\"\n",Device); @@ -2516,7 +2548,7 @@ static void SendSMSStatus (char *Device, int status, int MessageReference) printmsg("..error %i",status); SMSStatus = ERR_UNKNOWN; } - printmsg(", message reference=%02x\n",MessageReference); + printmsg(", message reference=%d\n",MessageReference); } static void SendSaveDisplaySMS(int argc, char *argv[]) @@ -2530,7 +2562,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) GSM_MultiSMSMessage sms; GSM_Ringtone ringtone[MAX_MULTI_SMS]; GSM_MultiBitmap bitmap[MAX_MULTI_SMS],bitmap2; - GSM_MultiPartSMSInfo SMSInfo; + GSM_MultiPartSMSInfo SMSInfo; GSM_NetworkInfo NetInfo; GSM_MMSIndicator MMSInfo; FILE *ReplaceFile,*f; @@ -2574,7 +2606,11 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) startarg = 1; Validity.Format = 0; } - if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) startarg=startarg+2; + if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) { + startarg=startarg+2; + EncodeUnicode(SMSC,"1234",4); + SMSCSet = 0; + } if (mystrncasecmp(argv[2],"TEXT",0)) { chars_read = fread(InputBuffer, 1, SEND_SAVE_SMS_BUFFER_SIZE/2, stdin); @@ -2600,7 +2636,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) startarg += 3; } else if (mystrncasecmp(argv[2],"MMSINDICATOR",0)) { if (argc<6+startarg) { - printmsg("Where is ringtone filename ?\n"); + printmsg("Where are parameters ?\n"); exit(-1); } SMSInfo.Entries[0].ID = SMS_MMSIndicatorLong; @@ -2612,6 +2648,19 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) strcpy(MMSInfo.Title, argv[4+startarg]); strcpy(MMSInfo.Sender, argv[5+startarg]); startarg += 6; + } else if (mystrncasecmp(argv[2],"WAPINDICATOR",0)) { + if (argc<5+startarg) { + printmsg("Where are parameters ?\n"); + exit(-1); + } + SMSInfo.Entries[0].ID = SMS_WAPIndicatorLong; + SMSInfo.Entries[0].MMSIndicator = &MMSInfo; + if (mystrncasecmp(argv[1],"--savesms",0)) { + EncodeUnicode(Sender,"WAP Info",8); + } + strcpy(MMSInfo.Address, argv[3+startarg]); + strcpy(MMSInfo.Title, argv[4+startarg]); + startarg += 5; } else if (mystrncasecmp(argv[2],"RINGTONE",0)) { if (argc<4+startarg) { printmsg("Where is ringtone filename ?\n"); @@ -2710,7 +2759,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[3+startarg],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.WAPBookmark[i]!=NULL) { if (i == atoi(argv[4+startarg])-1) break; @@ -2733,7 +2782,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[3+startarg],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.WAPSettings[i]!=NULL) { if (i == atoi(argv[4+startarg])-1) break; @@ -2776,7 +2825,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[3+startarg],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.MMSSettings[i]!=NULL) { if (i == atoi(argv[4+startarg])-1) break; @@ -2812,7 +2861,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[3+startarg],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.Calendar[i]!=NULL) { if (i == atoi(argv[4+startarg])-1) break; @@ -2834,7 +2883,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[3+startarg],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.ToDo[i]!=NULL) { if (i == atoi(argv[4+startarg])-1) break; @@ -2856,7 +2905,7 @@ static void SendSaveDisplaySMS(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[3+startarg],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; if (mystrncasecmp(argv[4+startarg],"SM",0)) { while (Backup.SIMPhonebook[i]!=NULL) { @@ -3809,7 +3858,7 @@ static void SaveFile(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[4],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.Calendar[i]!=NULL) { if (i == atoi(argv[5])-1) break; @@ -3827,7 +3876,7 @@ static void SaveFile(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[4],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.WAPBookmark[i]!=NULL) { if (i == atoi(argv[5])-1) break; @@ -3845,7 +3894,7 @@ static void SaveFile(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[4],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.Note[i]!=NULL) { if (i == atoi(argv[5])-1) break; @@ -3863,7 +3912,7 @@ static void SaveFile(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[4],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.ToDo[i]!=NULL) { if (i == atoi(argv[5])-1) break; @@ -3881,7 +3930,7 @@ static void SaveFile(int argc, char *argv[]) exit(-1); } error=GSM_ReadBackupFile(argv[4],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; if (mystrncasecmp(argv[5],"SM",0)) { while (Backup.SIMPhonebook[i]!=NULL) { @@ -3930,14 +3979,17 @@ static void Backup(int argc, char *argv[]) GSM_ToDoEntry ToDo; GSM_ToDoStatus ToDoStatus; GSM_MemoryEntry Pbk; - GSM_CalendarEntry Note; + GSM_CalendarEntry Calendar; GSM_Bitmap Bitmap; GSM_WAPBookmark Bookmark; GSM_Profile Profile; GSM_MultiWAPSettings Settings; + GSM_SyncMLSettings SyncML; + GSM_ChatSettings Chat; GSM_Ringtone Ringtone; GSM_SMSC SMSC; GSM_Backup Backup; + GSM_NoteEntry Note; GSM_Backup_Info Info; GSM_FMStation FMStation; GSM_GPRSAccessPoint GPRSPoint; @@ -4074,7 +4126,7 @@ static void Backup(int argc, char *argv[]) DoBackup = false; if (Info.Calendar) { printmsg("Checking calendar\n"); - error=Phone->GetNextCalendar(&s,&Note,true); + error=Phone->GetNextCalendar(&s,&Calendar,true); if (error==ERR_NONE) { if (answer_yes(" Backup calendar notes")) DoBackup = true; } @@ -4092,9 +4144,9 @@ static void Backup(int argc, char *argv[]) GSM_Terminate(); exit(-1); } - *Backup.Calendar[used]=Note; + *Backup.Calendar[used]=Calendar; used ++; - error=Phone->GetNextCalendar(&s,&Note,false); + error=Phone->GetNextCalendar(&s,&Calendar,false); printmsgerr("*"); if (gshutdown) { GSM_Terminate(); @@ -4136,6 +4188,38 @@ static void Backup(int argc, char *argv[]) printmsgerr("\n"); } DoBackup = false; + if (Info.Note) { + printmsg("Checking notes\n"); + error=Phone->GetNextNote(&s,&Note,true); + if (error==ERR_NONE) { + if (answer_yes(" Backup notes")) DoBackup = true; + } + } + if (DoBackup) { + used = 0; + printmsgerr(" Reading : "); + while (error == ERR_NONE) { + if (used < GSM_BACKUP_MAX_NOTE) { + Backup.Note[used] = malloc(sizeof(GSM_NoteEntry)); + if (Backup.Note[used] == NULL) Print_Error(ERR_MOREMEMORY); + Backup.Note[used+1] = NULL; + } else { + printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_NOTE"); + GSM_Terminate(); + exit(-1); + } + *Backup.Note[used]=Note; + used ++; + error=Phone->GetNextNote(&s,&Note,false); + printmsgerr("*"); + if (gshutdown) { + GSM_Terminate(); + exit(0); + } + } + printmsgerr("\n"); + } + DoBackup = false; if (Info.CallerLogos) { printmsg("Checking caller logos\n"); Bitmap.Type = GSM_CallerGroupLogo; @@ -4234,6 +4318,74 @@ static void Backup(int argc, char *argv[]) *Backup.OperatorLogo = Bitmap; } DoBackup = false; + if (Info.WAPBookmark) { + printmsg("Checking WAP bookmarks\n"); + Bookmark.Location = 1; + error=Phone->GetWAPBookmark(&s,&Bookmark); + if (error==ERR_NONE) { + if (answer_yes(" Backup WAP bookmarks")) DoBackup = true; + } + } + if (DoBackup) { + used = 0; + printmsgerr(" Reading : "); + while (error == ERR_NONE) { + if (used < GSM_BACKUP_MAX_WAPBOOKMARK) { + Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark)); + if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY); + Backup.WAPBookmark[used+1] = NULL; + } else { + printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK"); + GSM_Terminate(); + exit(-1); + } + *Backup.WAPBookmark[used]=Bookmark; + used ++; + Bookmark.Location = used+1; + error=Phone->GetWAPBookmark(&s,&Bookmark); + printmsgerr("*"); + if (gshutdown) { + GSM_Terminate(); + exit(0); + } + } + printmsgerr("\n"); + } + DoBackup = false; + if (Info.WAPSettings) { + printmsg("Checking WAP settings\n"); + Settings.Location = 1; + error=Phone->GetWAPSettings(&s,&Settings); + if (error==ERR_NONE) { + if (answer_yes(" Backup WAP settings")) DoBackup = true; + } + } + if (DoBackup) { + used = 0; + printmsgerr(" Reading : "); + while (error == ERR_NONE) { + if (used < GSM_BACKUP_MAX_WAPSETTINGS) { + Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); + if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); + Backup.WAPSettings[used+1] = NULL; + } else { + printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS"); + GSM_Terminate(); + exit(-1); + } + *Backup.WAPSettings[used]=Settings; + used ++; + Settings.Location = used+1; + error=Phone->GetWAPSettings(&s,&Settings); + printmsgerr("*"); + if (gshutdown) { + GSM_Terminate(); + exit(0); + } + } + printmsgerr("\n"); + } + DoBackup = false; if (Info.MMSSettings) { printmsg("Checking MMS settings\n"); Settings.Location = 1; @@ -4268,31 +4420,31 @@ static void Backup(int argc, char *argv[]) printmsgerr("\n"); } DoBackup = false; - if (Info.WAPBookmark) { - printmsg("Checking WAP bookmarks\n"); - Bookmark.Location = 1; - error=Phone->GetWAPBookmark(&s,&Bookmark); + if (Info.ChatSettings) { + printmsg("Checking Chat settings\n"); + Chat.Location = 1; + error=Phone->GetChatSettings(&s,&Chat); if (error==ERR_NONE) { - if (answer_yes(" Backup WAP bookmarks")) DoBackup = true; + if (answer_yes(" Backup Chat settings")) DoBackup = true; } } if (DoBackup) { used = 0; printmsgerr(" Reading : "); while (error == ERR_NONE) { - if (used < GSM_BACKUP_MAX_WAPBOOKMARK) { - Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark)); - if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY); - Backup.WAPBookmark[used+1] = NULL; + if (used < GSM_BACKUP_MAX_CHATSETTINGS) { + Backup.ChatSettings[used] = malloc(sizeof(GSM_ChatSettings)); + if (Backup.ChatSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); + Backup.ChatSettings[used+1] = NULL; } else { - printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK"); + printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CHATSETTINGS"); GSM_Terminate(); exit(-1); } - *Backup.WAPBookmark[used]=Bookmark; + *Backup.ChatSettings[used]=Chat; used ++; - Bookmark.Location = used+1; - error=Phone->GetWAPBookmark(&s,&Bookmark); + Chat.Location = used+1; + error=Phone->GetChatSettings(&s,&Chat); printmsgerr("*"); if (gshutdown) { GSM_Terminate(); @@ -4302,31 +4454,31 @@ static void Backup(int argc, char *argv[]) printmsgerr("\n"); } DoBackup = false; - if (Info.WAPSettings) { - printmsg("Checking WAP settings\n"); - Settings.Location = 1; - error=Phone->GetWAPSettings(&s,&Settings); + if (Info.SyncMLSettings) { + printmsg("Checking SyncML settings\n"); + SyncML.Location = 1; + error=Phone->GetSyncMLSettings(&s,&SyncML); if (error==ERR_NONE) { - if (answer_yes(" Backup WAP settings")) DoBackup = true; + if (answer_yes(" Backup SyncML settings")) DoBackup = true; } } if (DoBackup) { used = 0; printmsgerr(" Reading : "); while (error == ERR_NONE) { - if (used < GSM_BACKUP_MAX_WAPSETTINGS) { - Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); - if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); - Backup.WAPSettings[used+1] = NULL; + if (used < GSM_BACKUP_MAX_SYNCMLSETTINGS) { + Backup.SyncMLSettings[used] = malloc(sizeof(GSM_SyncMLSettings)); + if (Backup.SyncMLSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); + Backup.SyncMLSettings[used+1] = NULL; } else { - printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS"); + printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SYNCMLSETTINGS"); GSM_Terminate(); exit(-1); } - *Backup.WAPSettings[used]=Settings; + *Backup.SyncMLSettings[used]=SyncML; used ++; - Settings.Location = used+1; - error=Phone->GetWAPSettings(&s,&Settings); + SyncML.Location = used+1; + error=Phone->GetSyncMLSettings(&s,&SyncML); printmsgerr("*"); if (gshutdown) { GSM_Terminate(); @@ -4502,14 +4654,19 @@ static void Restore(int argc, char *argv[]) bool Found, DoRestore; error=GSM_ReadBackupFile(argv[2],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) { + Print_Error(error); + } else { + 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"); + } signal(SIGINT, interrupt); printmsgerr("Press Ctrl+C to break...\n"); - if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); - if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); - if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); + if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); + if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); + if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); + if (Backup.Creator[0]!=0) printmsgerr("File created by : %s\n",Backup.Creator); if (Backup.MD5Calculated[0]!=0) { dbgprintf("\"%s\"\n",Backup.MD5Original); @@ -4618,7 +4775,7 @@ static void Restore(int argc, char *argv[]) } if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { - 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 ) { + 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)")) { GSM_GetCurrentDateTime(&date_time); error=Phone->SetDateTime(&s, &date_time); @@ -4627,20 +4784,17 @@ static void Restore(int argc, char *argv[]) } DoRestore = false; if (Backup.Calendar[0] != NULL) { - DoRestore = true; /* N6110 doesn't support getting calendar status */ error = Phone->GetNextCalendar(&s,&Calendar,true); if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { max = 0; while (Backup.Calendar[max] != NULL) max++; printmsgerr("%i entries in backup file\n",max); + // LR + //if (answer_yes("Restore calendar notes")) { + //Past = answer_yes("Restore notes from the past"); DoRestore = true; - /* - if (answer_yes("Restore calendar notes")) { - Past = answer_yes("Restore notes from the past"); - DoRestore = true; - } - */ + //} } } if (DoRestore) { @@ -4679,20 +4833,17 @@ static void Restore(int argc, char *argv[]) if (Backup.ToDo[0] != NULL) { error = Phone->GetToDoStatus(&s,&ToDoStatus); if (error == ERR_NONE) { - error == ERR_NOTSUPPORTED; - DoRestore = true; max = 0; while (Backup.ToDo[max]!=NULL) max++; printmsgerr("%i entries in backup file\n",max); - /*if (answer_yes("Restore ToDo")) */DoRestore = true; + //LR if (answer_yes("Restore ToDo")) + DoRestore = true; } } if (DoRestore) { - if ( max > 0 ) { ToDo = *Backup.ToDo[0]; error = Phone->SetToDo(&s,&ToDo); - } } if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { printmsgerr("Deleting old ToDo: "); @@ -4991,7 +5142,7 @@ static void AddNew(int argc, char *argv[]) int i, max, j; error=GSM_ReadBackupFile(argv[2],&Backup); - Print_Error(error); + if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); signal(SIGINT, interrupt); printmsgerr("Press Ctrl+C to break...\n"); @@ -5618,8 +5769,7 @@ static void RestoreSMS(int argc, char *argv[]) displaymultismsinfo(SMS,false,false); sprintf(buffer,"Restore sms to folder \"%s\"",DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder-1].Name)); if (answer_yes(buffer)) { - Backup.SMS[smsnum]->Location = 0; - error=Phone->SetSMS(&s, Backup.SMS[smsnum]); + error=Phone->AddSMS(&s, Backup.SMS[smsnum]); Print_Error(error); } smsnum++; @@ -5813,7 +5963,7 @@ static void NokiaComposer(int argc, char *argv[]) printf("\n"); } -//#if 0 + static void CopyRingtone(int argc, char *argv[]) { GSM_Ringtone ringtone, ringtone2; @@ -5974,7 +6124,7 @@ static void PrintToDo(GSM_ToDoEntry *ToDo) unsigned char *name; GSM_Category Category; - printmsg("Location : %i\n",ToDo->Location); + printmsg("Location : %i\n",ToDo->Location); printmsg("Priority : "); switch (ToDo->Priority) { case GSM_Priority_Low : printmsg("Low\n"); break; @@ -6098,7 +6248,7 @@ static void ListToDoCategory(int argc, char *argv[]) if (error != ERR_EMPTY) { count++; - if (mystrstr(Category.Name, Text) != NULL) { + if (mywstrstr(Category.Name, Text) != NULL) { ListToDoCategoryEntries(j); } } @@ -6151,31 +6301,24 @@ static void GetAllToDo(int argc, char *argv[]) GSM_Terminate(); } -static void GetNote(int argc, char *argv[]) +static void GetAllNotes(int argc, char *argv[]) { GSM_NoteEntry Note; - int start,stop; - bool refresh=true; + bool start = true; - GetStartStop(&start, &stop, 2, argc, argv); + signal(SIGINT, interrupt); + printmsgerr("Press Ctrl+C to break...\n"); GSM_Init(true); - for (i=start;i<=stop;i++) { - Note.Location=i; - printmsg("Location : %i\n",i); - error=Phone->GetNote(&s,&Note,refresh); - if (error != ERR_EMPTY) Print_Error(error); - - if (error == ERR_EMPTY) { - printmsg("Entry is empty\n\n"); - } else { - printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note.Text)); - printf("\n"); - refresh=false; - } + while (!gshutdown) { + error = Phone->GetNextNote(&s, &Note, start); + if (error == ERR_EMPTY) break; + Print_Error(error); + printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note.Text)); + printf("\n"); + start = false; } - GSM_Terminate(); } @@ -6571,11 +6714,34 @@ static void MakeConvertTable(int argc, char *argv[]) static void ListNetworks(int argc, char *argv[]) { extern unsigned char *GSM_Networks[]; + extern unsigned char *GSM_Countries[]; int i=0; + char country[4]=""; - printmsg("Network Name\n\n"); + if (argc>2) { + while (GSM_Countries[i*2]!=NULL) { + if (!strncmp(GSM_Countries[i*2+1],argv[2],strlen(argv[2]))) { + strcpy(country,GSM_Countries[i*2]); + printmsg("Networks for %s:\n\n",GSM_Countries[i*2+1]); + break; + } + i++; + } + if (!*country) { + printmsg("Unknown country name."); + exit(-1); + } + } + printmsg("Network Name\n"); + i=0; while (GSM_Networks[i*2]!=NULL) { - printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]); + if (argc>2) { + if (!strncmp(GSM_Networks[i*2],country,strlen(country))) { + printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]); + } + } else { + printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]); + } i++; } } @@ -6585,7 +6751,9 @@ static void Version(int argc, char *argv[]) // unsigned char buff[10]; // int len; - printmsg("[Gammu version %s built %s %s]\n\n",VERSION,__TIME__,__DATE__); + printmsg("[Gammu version %s built %s %s",VERSION,__TIME__,__DATE__); + if (strlen(GetCompiler()) != 0) printmsg(" in %s",GetCompiler()); + printmsg("]\n\n"); #ifdef DEBUG printf("GSM_SMSMessage - %i\n",sizeof(GSM_SMSMessage)); @@ -6702,9 +6870,6 @@ static void GetFileSystem(int argc, char *argv[]) if (Files.Folder) printf("Folder "); } printf("\"%s\"",DecodeUnicodeConsole(Files.Name)); - printf("\n"); - - Start = false; } else if (argc > 2 && mystrncasecmp(argv[2],"-flatall",0)) { /* format for a folder ID;Folder;FOLDER_NAME;[FOLDER_PARAMETERS] * format for a file ID;File;FOLDER_NAME;FILE_NAME;DATESTAMP;FILE_SIZE;[FILE_PARAMETERS] */ @@ -6726,11 +6891,8 @@ static void GetFileSystem(int argc, char *argv[]) if (Files.ReadOnly) printf("R"); if (Files.Hidden) printf("H"); if (Files.System) printf("S"); - - printf("\n"); - - Start = false; } + Start = false; } error = Phone->GetFileSystemStatus(&s,&Status); @@ -7038,10 +7200,14 @@ static struct NokiaFolderInfo Folder[] = { {"3510i","Gallery", "", "3"}, {"5100", "Gallery", "", "3"}, {"6220", "Gallery", "", "5"}, + {"6610", "Gallery", "", "2"}, + {"7210", "Gallery", "", "2"}, {"", "Tones", "Tones", "3"}, {"3510i","Tones", "", "4"}, {"5100", "Tones", "", "4"}, {"6220", "Tones", "", "6"}, + {"6610", "Tones", "", "4"}, + {"7210", "Tones", "", "4"}, /* Language indepedent in OBEX */ {"obex", "MMSUnreadInbox", "", "predefMessages\\predefINBOX" }, {"obex", "MMSReadInbox", "", "predefMessages\\predefINBOX" }, @@ -7558,8 +7724,6 @@ static void CallDivert(int argc, char *argv[]) GSM_Terminate(); } - -//#if 0 static void CancelAllDiverts(int argc, char *argv[]) { GSM_Init(true); @@ -7570,75 +7734,83 @@ static void CancelAllDiverts(int argc, char *argv[]) GSM_Terminate(); } +typedef struct { + unsigned char Connection[50]; +} OneConnectionInfo; +typedef struct { + unsigned char Device[50]; + OneConnectionInfo Connections[4]; +} OneDeviceInfo; + +int num; +bool SearchOutput; void SearchPhoneThread(OneDeviceInfo *Info) { + //LR +#if 0 int j; GSM_Error error; - fprintf(stderr,"*********************************** \n"); - fprintf(stderr,"*********************************** \n"); - fprintf(stderr,"*********************************** \n"); - fprintf(stderr,"*********************************** \n"); - fprintf(stderr,"*********************************** \n"); -#if 0 + GSM_StateMachine ss; + j = 0; while(strlen(Info->Connections[j].Connection) != 0) { - memcpy(&Info->s.di,&s.di,sizeof(Debug_Info)); - Info->s.msg = s.msg; - Info->s.ConfigNum = 1; - Info->s.opened = false; - Info->s.Config[0].UseGlobalDebugFile = s.Config[0].UseGlobalDebugFile; - Info->s.Config[0].Localize = s.Config[0].Localize; - Info->s.Config[0].Device = Info->Device; - Info->s.Config[0].Connection = Info->Connections[j].Connection; - Info->s.Config[0].SyncTime = "no"; - Info->s.Config[0].DebugFile = s.Config[0].DebugFile; - Info->s.Config[0].Model[0] = 0; - strcpy(Info->s.Config[0].DebugLevel,s.Config[0].DebugLevel); - Info->s.Config[0].LockDevice = "no"; - Info->s.Config[0].StartInfo = "no"; - - error = GSM_InitConnection(&Info->s,1); + memcpy(&ss.di,&s.di,sizeof(Debug_Info)); + ss.msg = s.msg; + ss.ConfigNum = 1; + ss.opened = false; + ss.Config[0].UseGlobalDebugFile = s.Config[0].UseGlobalDebugFile; + ss.Config[0].Localize = s.Config[0].Localize; + ss.Config[0].Device = Info->Device; + ss.Config[0].Connection = Info->Connections[j].Connection; + ss.Config[0].SyncTime = "no"; + ss.Config[0].DebugFile = s.Config[0].DebugFile; + ss.Config[0].Model[0] = 0; + strcpy(ss.Config[0].DebugLevel,s.Config[0].DebugLevel); + ss.Config[0].LockDevice = "no"; + ss.Config[0].StartInfo = "no"; + + error = GSM_InitConnection(&ss,1); if (SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device); if (error == ERR_NONE) { - error=Info->s.Phone.Functions->GetManufacturer(&Info->s); + error=ss.Phone.Functions->GetManufacturer(&ss); if (error == ERR_NONE) { - error=Info->s.Phone.Functions->GetModel(&Info->s); + error=ss.Phone.Functions->GetModel(&ss); if (error == ERR_NONE) { if (!SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device); printmsg(" Manufacturer : %s\n", - Info->s.Phone.Data.Manufacturer); + ss.Phone.Data.Manufacturer); printmsg(" Model : %s (%s)\n", - Info->s.Phone.Data.ModelInfo->model, - Info->s.Phone.Data.Model); + ss.Phone.Data.ModelInfo->model, + ss.Phone.Data.Model); } else { - if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); + if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg)); } } else { - if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); + if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg)); } } else { - if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); + if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg)); } if (error != ERR_DEVICEOPENERROR) { - GSM_TerminateConnection(&Info->s); + GSM_TerminateConnection(&ss); dbgprintf("Closing done\n"); } - if (error == ERR_DEVICEOPENERROR || error == ERR_NONE) break; + if (error == ERR_DEVICEOPENERROR) break; j++; } num--; #endif } -//#undef HAVE_PTHREAD -//#if 0 #if defined(WIN32) || defined(HAVE_PTHREAD) #ifdef HAVE_PTHREAD pthread_t Thread[100]; #endif +OneDeviceInfo SearchDevices[60]; + void MakeSearchThread(int i) { num++; @@ -7657,7 +7829,7 @@ void MakeSearchThread(int i) static void SearchPhone(int argc, char *argv[]) { - int i,dev = 0, dev2 = 0; + int i,dev = 0, dev2 = 0; SearchOutput = false; if (argc == 3 && mystrncasecmp(argv[2], "-debug",0)) SearchOutput = true; @@ -7667,12 +7839,13 @@ static void SearchPhone(int argc, char *argv[]) # ifdef GSM_ENABLE_IRDADEVICE sprintf(SearchDevices[dev].Device,""); sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet"); - SearchDevices[dev].Connections[1].Connection[0] = 0; + sprintf(SearchDevices[dev].Connections[1].Connection,"irdaat"); + SearchDevices[dev].Connections[2].Connection[0] = 0; dev++; # endif # ifdef GSM_ENABLE_SERIALDEVICE dev2 = dev; - for(i=0;i<10;i++) { + for(i=0;i<20;i++) { sprintf(SearchDevices[dev2].Device,"com%i:",i+1); sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3"); sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus"); @@ -7730,7 +7903,7 @@ static void SearchPhone(int argc, char *argv[]) while (num != 0) my_sleep(5); } #endif /*Support for threads */ -// #if 0 + static void NokiaGetADC(int argc, char *argv[]) { GSM_Init(true); @@ -7793,7 +7966,7 @@ static GSM_Parameters Parameters[] = { {"--getdisplaystatus", 0, 0, GetDisplayStatus, {H_Info,0}, ""}, {"--monitor", 0, 1, Monitor, {H_Info,H_Network,H_Call,0}, "[times]"}, {"--setautonetworklogin", 0, 0, SetAutoNetworkLogin, {H_Network,0}, ""}, - {"--listnetworks", 0, 0, ListNetworks, {H_Network,0}, ""}, + {"--listnetworks", 0, 1, ListNetworks, {H_Network,0}, "[country]"}, {"--getgprspoint", 1, 2, GetGPRSPoint, {H_Nokia,H_Network,0}, "start [stop]"}, {"--addfolder", 2, 2, AddFolder, {H_Filesystem,0}, "parentfolderID name"}, {"--getfilesystem", 0, 1, GetFileSystem, {H_Filesystem,0}, "[-flatall|-flat]"}, @@ -7812,8 +7985,8 @@ static GSM_Parameters Parameters[] = { {"--getalarm", 0, 0, GetAlarm, {H_DateTime,0}, ""}, {"--setalarm", 2, 2, SetAlarm, {H_DateTime,0}, "hour minute"}, {"--resetphonesettings", 1, 1, ResetPhoneSettings, {H_Settings,0}, "PHONE|DEV|UIF|ALL|FACTORY"}, - {"--getmemory", 2, 3, GetMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD start [stop]"}, - {"--getallmemory", 1, 1, GetAllMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD"}, + {"--getmemory", 2, 4, GetMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD start [stop [-nonempty]]"}, + {"--getallmemory", 1, 2, GetAllMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD"}, {"--searchmemory", 1, 1, SearchMemory, {H_Memory,0}, "text"}, {"--listmemorycategory", 1, 1, ListMemoryCategory, {H_Memory, H_Category,0}, "text|number"}, {"--getfmstation", 1, 2, GetFMStation, {H_FM,0}, "start [stop]"}, @@ -7843,6 +8016,7 @@ static GSM_Parameters Parameters[] = { {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS}, {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION frames file1 file2... " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS}, {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR URL Title Sender " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, + {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPINDICATOR URL Title " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, #ifdef GSM_ENABLE_BACKUP {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS file location DATA|GPRS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, @@ -7862,6 +8036,7 @@ static GSM_Parameters Parameters[] = { {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS}, {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION destination frames file1 file2... " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS}, {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR destination URL Title Sender " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, + {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPINDICATOR destination URL Title " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, #ifdef GSM_ENABLE_BACKUP {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS destination file location DATA|GPRS " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, @@ -7907,7 +8082,7 @@ static GSM_Parameters Parameters[] = { {"--listtodocategory", 1, 1, ListToDoCategory, {H_ToDo, H_Category,0}, "text|number"}, {"--gettodo", 1, 2, GetToDo, {H_ToDo,0}, "start [stop]"}, {"--deletetodo", 1, 2, DeleteToDo, {H_ToDo,0}, "start [stop]"}, - {"--getnote", 1, 2, GetNote, {H_Note,0}, "start [stop]"}, + {"--getallnotes", 0, 0, GetAllNotes, {H_Note,0}, ""}, {"--deletecalendar", 1, 2, DeleteCalendar, {H_Calendar,0}, "start [stop]"}, {"--getallcalendar", 0, 0, GetAllCalendar, {H_Calendar,0}, ""}, {"--getcalendar", 1, 2, GetCalendar, {H_Calendar,0}, "start [stop]"}, @@ -7976,8 +8151,10 @@ static GSM_Parameters Parameters[] = { #ifdef GSM_ENABLE_NOKIA_DCT4 {"--nokiasetvibralevel", 1, 1, DCT4SetVibraLevel, {H_Nokia,H_Other,0}, "level"}, {"--nokiagetvoicerecord", 1, 1, DCT4GetVoiceRecord, {H_Nokia,H_Other,0}, "location"}, +#ifdef GSM_ENABLE_NOKIA6510 {"--nokiasetlights", 2, 2, DCT4SetLight, {H_Nokia,H_Tests,0}, "keypad|display|torch on|off"}, {"--nokiatuneradio", 0, 0, DCT4TuneRadio, {H_Nokia,H_FM,0}, ""}, +#endif {"--nokiamakecamerashoot", 0, 0, DCT4MakeCameraShoot, {H_Nokia,H_Other,0}, ""}, {"--nokiagetscreendump", 0, 0, DCT4GetScreenDump, {H_Nokia,H_Other,0}, ""}, #endif @@ -8046,11 +8223,11 @@ static void HelpGeneral(void) HelpHeader(); printmsg("Usage: gammu [confign] [nothing|text|textall|binary|errors] [options]\n\n"); - printmsg("First parameter optionally specifies which config section to use (by default are probed all).\n"); - printmsg("Second parameter optionally controls debug level, next specify actions.\n\n"); + printmsg("First parameter optionally specifies which config section to use (all are probed by default).\n"); + printmsg("Second parameter optionally controls debug level, next one specifies actions.\n\n"); /* We might want to put here some most used commands */ - printmsg("For more details call help on specific topic (gammu --help topic), topics are:\n\n"); + printmsg("For more details, call help on specific topic (gammu --help topic). Topics are:\n\n"); while (HelpDescriptions[i].category != 0) { printf("%11s - %s\n", HelpDescriptions[i].option, HelpDescriptions[i].description); @@ -8134,7 +8311,7 @@ static void Help(int argc, char *argv[]) HelpHeader(); } else { while (HelpDescriptions[i].category != 0) { - if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; + if (mystrncasecmp(argv[2], HelpDescriptions[i].option,strlen(argv[2]))) break; i++; } if (HelpDescriptions[i].category == 0) { @@ -8206,22 +8383,17 @@ static void Help(int argc, char *argv[]) j++; } } -#if 0 -#endif // 0 + int main(int argc, char *argv[]) { - - //fprintf(stderr,"HIIIIIIIIIIIII \n"); - //#if 0 - static int z ,start,i; - static int only_config ; -#if !defined(WIN32) && defined(LOCALE_PATH) - static char *locale, locale_file[201]; + int z = 0,start=0,i; + int only_config = -1; +#if !defined(WIN32) && !defined(DJGPP) && defined(LOCALE_PATH) + char *locale, locale_file[201]; #endif - static char *cp; - static bool count_failed; - z = 0; - start=0;only_config = -1;count_failed = false; + char *cp; + bool count_failed = false; + s.opened = false; s.msg = NULL; s.ConfigNum = 0; @@ -8231,7 +8403,7 @@ int main(int argc, char *argv[]) di.dl = DL_TEXTALL; di.df = stdout; #endif - //#if 0 + /* Any parameters? */ if (argc == 1) { HelpGeneral(); @@ -8246,58 +8418,14 @@ int main(int argc, char *argv[]) } /* Is first parameter numeric? If so treat it as config that should be loaded. */ - //if (isdigit(argv[1][0])) { - //only_config = atoi(argv[1]); - //if (only_config >= 0) start++; else only_config = -1; - //} - only_config = 0;; -#if 0 - GSM_ReadConfig(NULL, &s.Config[0], 0); - s.ConfigNum = 1; - GSM_Config *con = &s.Config[0]; - - char* tempC; - tempC = argv[argc-1]+2; - if ( *tempC != 0 ) { - fprintf(stderr,"Using model %s \n",tempC); - strcpy(con->Model,tempC ); - } - tempC = argv[argc-2]+2; - if ( *tempC != 0 ) { - fprintf(stderr,"Using device %s \n",tempC); - con->Device = strdup(tempC); - con->DefaultDevice = false; - } - tempC = argv[argc-3]+2; - if ( *tempC != 0 ) { - fprintf(stderr,"Using connection %s \n",tempC); - con->Connection = strdup(tempC); - con->DefaultConnection = false; - } - argc = argc-3; - //#if 0 - if ( ! mConnection.isEmpty() ) { - cfg->Connection = strdup(mConnection.latin1()); - cfg->DefaultConnection = false; - qDebug("Connection set %s ", cfg->Connection ); - - } - if ( ! mDevice.isEmpty() ) { - cfg->Device = strdup(mDevice.latin1()); - cfg->DefaultDevice = false; - qDebug("Device set %s ", cfg->Device); - - } - if ( ! mModel.isEmpty() ) { - strcpy(cfg->Model,mModel.latin1() ); - cfg->DefaultModel = false; - qDebug("Model set %s ",cfg->Model ); - } - -#endif + if (isdigit(argv[1][0])) { + only_config = atoi(argv[1]); + if (only_config >= 0) start++; else only_config = -1; + } + cfg = GSM_FindGammuRC(); + if (cfg == NULL) printmsg("Warning: No configuration file found!\n"); - cfg=GSM_FindGammuRC(); for (i = 0; i <= MAX_CONFIG_NUM; i++) { if (cfg!=NULL) { cp = INI_GetValue(cfg, "gammu", "gammucoding", false); @@ -8307,7 +8435,7 @@ int main(int argc, char *argv[]) if (s.Config[i].Localize) { s.msg=INI_ReadFile(s.Config[i].Localize, true); } else { -#if !defined(WIN32) && defined(LOCALE_PATH) +#if !defined(WIN32) && !defined(DJGPP) && defined(LOCALE_PATH) locale = setlocale(LC_MESSAGES, NULL); if (locale != NULL) { snprintf(locale_file, 200, "%s/gammu_%c%c.txt", @@ -8321,7 +8449,6 @@ int main(int argc, char *argv[]) } /* Wanted user specific configuration? */ - if (only_config != -1) { /* Here we get only in first for loop */ if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; @@ -8357,30 +8484,7 @@ int main(int argc, char *argv[]) /* We wanted to read just user specified configuration. */ if (only_config != -1) {break;} } -#if 0 - GSM_Config *con = &s.Config[0]; - - char* tempC; - tempC = argv[argc-1]+2; - if ( *tempC != 0 ) { - fprintf(stderr,"Using model %s \n",tempC); - strcpy(con->Model,tempC ); - } - tempC = argv[argc-2]+2; - if ( *tempC != 0 ) { - fprintf(stderr,"Using device %s \n",tempC); - con->Device = strdup(tempC); - con->DefaultDevice = false; - } - tempC = argv[argc-3]+2; - if ( *tempC != 0 ) { - fprintf(stderr,"Using connection %s \n",tempC); - con->Connection = strdup(tempC); - con->DefaultConnection = false; - } -#endif - - + /* Do we have enough parameters? */ if (argc == 1 + start) { HelpGeneral(); @@ -8399,7 +8503,6 @@ int main(int argc, char *argv[]) while (Parameters[z].Function != NULL) { if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { - fprintf(stderr,"Executing \n"); Parameters[z].Function(argc - start, argv + start); break; } else { @@ -8421,8 +8524,7 @@ int main(int argc, char *argv[]) /* Close debug output if opened */ if (di.df!=stdout) fclose(di.df); - //#endif // 0 - fprintf(stderr,"kammu: Success. End. \n"); + exit(0); } 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 @@ -57,11 +57,11 @@ void Print_Error (GSM_Error error); void GSM_Init (bool checkerror); void GSM_Terminate (void); -static GSM_StateMachine s; -static GSM_Phone_Functions *Phone; -static GSM_Error error; +extern GSM_StateMachine s; +extern GSM_Phone_Functions *Phone; +extern GSM_Error error; -static bool gshutdown; +extern volatile bool gshutdown; void interrupt(int sign); 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,4 +1,4 @@ -/* (c) 2002-2003 by Joergen Thomsen */ +/* (c) 2002-2004 by Joergen Thomsen */ #include "../../cfg/config.h" @@ -106,17 +106,26 @@ static GSM_Error SMSDFiles_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig /* Find one multi SMS to sending and return it (or return ERR_EMPTY) * There is also set ID for SMS + * File extension convention: + * OUTxxxxx.txt : normal text SMS + * Options appended to the extension applying to this SMS only: + * d: delivery report requested + * f: flash SMS + * b: WAP bookmark as name,URL + * e.g. OUTG20040620_193810_123_+4512345678_xpq.txtdf + * is a flash text SMS requesting delivery reports */ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID) { GSM_Error error = ERR_NOTSUPPORTED; GSM_MultiPartSMSInfo SMSInfo; + GSM_WAPBookmark Bookmark; unsigned char FileName[100],FullName[400]; unsigned char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; unsigned char Buffer2[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; FILE *File; int i, len, phlen; - char *pos1, *pos2; + char *pos1, *pos2, *options; #if defined HAVE_DIRENT_H && defined HAVE_SCANDIR & defined HAVE_ALPHASORT struct dirent **namelist = NULL; int l, m ,n; @@ -125,10 +134,10 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi FullName[strlen(Config->outboxpath)-1] = '\0'; n = scandir(FullName, &namelist, 0, alphasort); m = 0; - while ((m < n) && ((*(namelist[m]->d_name) == '.') || - !mystrncasecmp(namelist[m]->d_name,"out", 3) || + while ((m < n) && ((*(namelist[m]->d_name) == '.') || // directory and UNIX hidden file + !mystrncasecmp(namelist[m]->d_name,"out", 3) || // must start with 'out' ((strlen(namelist[m]->d_name) >= 4) && - !mystrncasecmp(&namelist[m]->d_name[strlen(namelist[m]->d_name)-4],".txt",4) + !mystrncasecmp(strrchr(namelist[m]->d_name, '.'),".txt",4) ) ) ) m++; @@ -144,7 +153,7 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi long hFile; strcpy(FullName, Config->outboxpath); - strcat(FullName, "OUT*.txt"); + strcat(FullName, "OUT*.txt*"); if((hFile = _findfirst( FullName, &c_file )) == -1L ) { return ERR_EMPTY; } else { @@ -155,17 +164,17 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi #endif #endif if (error != ERR_NONE) return error; - + options = strrchr(FileName, '.') + 4; strcpy(FullName, Config->outboxpath); strcat(FullName, FileName); File = fopen(FullName, "rb"); len = fread(Buffer, 1, sizeof(Buffer)-2, File); fclose(File); - if (len<2) return ERR_EMPTY; - if ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) && - (Buffer[0] != 0xFE || Buffer[1] != 0xFF)) { + if ((len < 2) || + (len >= 2 && ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) && + (Buffer[0] != 0xFE || Buffer[1] != 0xFF)))) { if (len > GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS) len = GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS; EncodeUnicode(Buffer2, Buffer, len); len = len*2; @@ -176,10 +185,17 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi Buffer[len+1] = 0; ReadUnicodeFile(Buffer2,Buffer); + GSM_ClearMultiPartSMSInfo(&SMSInfo); + sms->Number = 0; + SMSInfo.ReplaceMessage = 0; SMSInfo.Entries[0].Buffer = Buffer2; SMSInfo.Class = -1; SMSInfo.EntriesNum = 1; + Config->currdeliveryreport = -1; + if (strchr(options, 'd')) Config->currdeliveryreport = 1; + if (strchr(options, 'f')) SMSInfo.Class = 0; /* flash SMS */ + if (mystrncasecmp(Config->transmitformat, "unicode", 0)) { SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong; SMSInfo.UnicodeCoding = true; @@ -190,6 +206,32 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi /* auto */ SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong; } + + if (strchr(options, 'b')) { // WAP bookmark as title,URL + SMSInfo.Entries[0].Buffer = NULL; + SMSInfo.Entries[0].Bookmark = &Bookmark; + SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong; + SMSInfo.Entries[0].Bookmark->Location = 0; + pos2 = mywstrstr(Buffer2, "\0,"); + if (pos2 == NULL) { + pos2 = Buffer2; + } else { + *pos2 = '\0'; pos2++; *pos2 = '\0'; pos2++; // replace comma by zero + } + + len = UnicodeLength(Buffer2); + if (len > 50) len = 50; + memmove(&SMSInfo.Entries[0].Bookmark->Title, Buffer2, len * 2); + pos1 = &SMSInfo.Entries[0].Bookmark->Title[0] + len * 2; + *pos1 = '\0'; pos1++; *pos1 = '\0'; + + len = UnicodeLength(pos2); + if (len > 255) len = 255; + memmove(&SMSInfo.Entries[0].Bookmark->Address, pos2, len * 2); + pos1 = &SMSInfo.Entries[0].Bookmark->Address[0] + len * 2; + *pos1 = '\0'; pos1++; *pos1 = '\0'; + } + GSM_EncodeMultiPartSMS(&SMSInfo,sms); pos1 = FileName; @@ -230,15 +272,17 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi #ifdef DEBUG if (sms->Number != 0) { DecodeUnicode(sms->SMS[0].Number,Buffer); - dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i\n", + dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i dlr: %i fls: %i", sms->Number, Buffer, DecodeUnicodeString(sms->SMS[0].Text), sms->SMS[0].Coding, sms->SMS[0].Length, sms->SMS[0].UDH.Type, - sms->SMS[0].UDH.Length); - } else dbgprintf("error\n"); + sms->SMS[0].UDH.Length, + Config->currdeliveryreport, + SMSInfo.Class); + } else dbgprintf("error: SMS-count = 0"); #endif return ERR_NONE; @@ -292,22 +336,25 @@ static GSM_Error SMSDFiles_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Con } } -static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK) +static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR) { - if (OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number)); + 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)); return ERR_NONE; } GSM_SMSDService SMSDFiles = { NONEFUNCTION, /* Init */ + NONEFUNCTION, /* InitAfterConnect */ SMSDFiles_SaveInboxSMS, SMSDFiles_FindOutboxSMS, SMSDFiles_MoveSMS, NOTSUPPORTED, /* CreateOutboxSMS */ - SMSDFiles_AddSentSMSInfo + SMSDFiles_AddSentSMSInfo, + NOTSUPPORTED, /* RefreshSendStatus */ + NOTSUPPORTED /* RefreshPhoneStatus */ }; -/* How should editor hadle tabs in this file? Add editor commands here. +/* How should editor handle tabs in this file? Add editor commands here. * vim: noexpandtab sw=8 ts=8 sts=8: */ 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,4 +1,4 @@ -/* (c) 2002-2003 by Joergen Thomsen */ +/* (c) 2002-2004 by Joergen Thomsen */ extern GSM_SMSDService SMSDFiles; 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 @@ -15,36 +15,224 @@ #include "../../common/misc/coding/coding.h" #include "../../common/service/backup/gsmback.h" +#include "../gammu.h" #include "smsdcore.h" /* Connects to database */ static GSM_Error SMSDMySQL_Init(GSM_SMSDConfig *Config) { + unsigned char buf[400]; + MYSQL_RES *Res; + MYSQL_ROW Row; + mysql_init(&Config->DB); if (!mysql_real_connect(&Config->DB,Config->PC,Config->user,Config->password,Config->database,0,NULL,0)) { - WriteSMSDLog("Error connecting to database: %s\n", mysql_error(&Config->DB)); - return ERR_UNKNOWN; + WriteSMSDLog("Error connecting to database: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + sprintf(buf, "SELECT ID FROM `outbox` WHERE 1"); + if (mysql_real_query(&Config->DB,buf,strlen(buf))) { + WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; } + mysql_free_result(Res); + sprintf(buf, "SELECT ID FROM `outbox_multipart` WHERE 1"); + if (mysql_real_query(&Config->DB,buf,strlen(buf))) { + WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + mysql_free_result(Res); + sprintf(buf, "SELECT ID FROM `sentitems` WHERE 1"); + if (mysql_real_query(&Config->DB,buf,strlen(buf))) { + WriteSMSDLog("No table for sent sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("No table for sent sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + mysql_free_result(Res); + sprintf(buf, "SELECT ID FROM `inbox` WHERE 1"); + if (mysql_real_query(&Config->DB,buf,strlen(buf))) { + WriteSMSDLog("No table for inbox sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("No table for inbox sms: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + mysql_free_result(Res); + sprintf(buf, "SELECT Version FROM `gammu` WHERE 1"); + if (mysql_real_query(&Config->DB,buf,strlen(buf))) { + WriteSMSDLog("No Gammu table: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("No Gammu table: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Row = mysql_fetch_row(Res))) { + mysql_free_result(Res); + WriteSMSDLog("No version info in Gammu table: %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (atoi(Row[0]) > 4) { + mysql_free_result(Res); + WriteSMSDLog("DataBase structures are from higher Gammu version"); + WriteSMSDLog("Please update this client application"); + return ERR_UNKNOWN; + } + if (atoi(Row[0]) < 4) { + mysql_free_result(Res); + WriteSMSDLog("DataBase structures are from older Gammu version"); + WriteSMSDLog("Please update DataBase, if you want to use this client application"); + return ERR_UNKNOWN; + } + mysql_free_result(Res); + + return ERR_NONE; +} + +static GSM_Error SMSDMySQL_InitAfterConnect(GSM_SMSDConfig *Config) +{ + unsigned char buf[400],buf2[200]; + + sprintf(buf,"DELETE FROM `phones` WHERE `IMEI` = '%s'",s.Phone.Data.IMEI); +#ifdef DEBUG + fprintf(stdout,"%s\n",buf); +#endif + if (mysql_real_query(&Config->DB,buf,strlen(buf))) { + WriteSMSDLog("Error deleting from database (Init): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + + sprintf(buf2,"Gammu %s",VERSION); + if (strlen(GetOS()) != 0) { + strcat(buf2+strlen(buf2),", "); + strcat(buf2+strlen(buf2),GetOS()); + } + if (strlen(GetCompiler()) != 0) { + strcat(buf2+strlen(buf2),", "); + strcat(buf2+strlen(buf2),GetCompiler()); + } + + 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); +#ifdef DEBUG + fprintf(stdout,"%s\n",buf); +#endif + if (mysql_real_query(&Config->DB,buf,strlen(buf))) { + WriteSMSDLog("Error deleting from database (Init): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + return ERR_NONE; } /* Save SMS from phone (called Inbox sms - it's in phone Inbox) somewhere */ static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config) { - unsigned char buffer[10000],buffer2[200],buffer3[2]; - int i,j,z; + MYSQL_RES *Res; + MYSQL_ROW Row; + unsigned char buffer[10000],buffer2[200],buffer3[50]; + int i,j,z; + GSM_DateTime DT; + time_t t_time1,t_time2; + bool found; + long diff; for (i=0;i<sms.Number;i++) { - if ((sms.SMS[i].PDU == SMS_Status_Report) && mystrncasecmp(Config->deliveryreport, "log", 3)) { - strcpy(buffer, DecodeUnicodeString(sms.SMS[i].Number)); - WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer); + if (sms.SMS[i].PDU == SMS_Status_Report) { + strcpy(buffer2, DecodeUnicodeString(sms.SMS[i].Number)); + if (mystrncasecmp(Config->deliveryreport, "log", 3)) { + WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer2); + } + + sprintf(buffer, "SELECT ID,Status,SendingDateTime,DeliveryDateTime,SMSCNumber FROM `sentitems` WHERE \ + DeliveryDateTime='00000000000000' AND \ + SenderID='%s' AND TPMR='%i' AND DestinationNumber='%s'", + Config->PhoneID, sms.SMS[i].MessageReference, buffer2); +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer); +#endif + if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { + WriteSMSDLog("Error reading from database (SaveInbox): %s %s\n", buffer, mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("Error reading from database (SaveInbox): %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + found = false; + while ((Row = mysql_fetch_row(Res))) { + if (strcmp(Row[4],DecodeUnicodeString(sms.SMS[i].SMSC.Number))) { + if (Config->skipsmscnumber[0] == 0) continue; + if (strcmp(Config->skipsmscnumber,Row[4])) continue; + } + if (!strcmp(Row[1],"SendingOK") || !strcmp(Row[1],"DeliveryPending")) { + sprintf(buffer,"%c%c%c%c",Row[2][0],Row[2][1],Row[2][2],Row[2][3]); + DT.Year = atoi(buffer); + sprintf(buffer,"%c%c",Row[2][4],Row[2][5]); + DT.Month = atoi(buffer); + sprintf(buffer,"%c%c",Row[2][6],Row[2][7]); + DT.Day = atoi(buffer); + sprintf(buffer,"%c%c",Row[2][8],Row[2][9]); + DT.Hour = atoi(buffer); + sprintf(buffer,"%c%c",Row[2][10],Row[2][11]); + DT.Minute = atoi(buffer); + sprintf(buffer,"%c%c",Row[2][12],Row[2][13]); + DT.Second = atoi(buffer); + t_time1 = Fill_Time_T(DT,0); + t_time2 = Fill_Time_T(sms.SMS[i].DateTime,0); + diff = t_time2 - t_time1; + // fprintf(stderr,"diff is %i, %i-%i-%i-%i-%i and %i-%i-%i-%i-%i-%i\n",diff, + // DT.Year,DT.Month,DT.Day,DT.Hour,DT.Minute,DT.Second, + // 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); + if (diff > -10 && diff < 10) { + found = true; + break; + } + } + } + if (found) { + sprintf(buffer,"UPDATE `sentitems` SET `DeliveryDateTime`='%04i%02i%02i%02i%02i%02i', `Status`='", + sms.SMS[i].SMSCTime.Year,sms.SMS[i].SMSCTime.Month,sms.SMS[i].SMSCTime.Day, + sms.SMS[i].SMSCTime.Hour,sms.SMS[i].SMSCTime.Minute,sms.SMS[i].SMSCTime.Second); + sprintf(buffer3,"%s",DecodeUnicodeString(sms.SMS[i].Text)); + if (!strcmp(buffer3,"Delivered")) { + sprintf(buffer+strlen(buffer),"DeliveryOK"); + } else if (!strcmp(buffer3,"Failed")) { + sprintf(buffer+strlen(buffer),"DeliveryFailed"); + } else if (!strcmp(buffer3,"Pending")) { + sprintf(buffer+strlen(buffer),"DeliveryPending"); + } else if (!strcmp(buffer3,"Unknown")) { + sprintf(buffer+strlen(buffer),"DeliveryUnknown"); + } + sprintf(buffer+strlen(buffer),"', `StatusError` = '%i'",sms.SMS[i].DeliveryStatus); + sprintf(buffer+strlen(buffer)," WHERE `ID` = '%s' AND `TPMR` = '%i'",Row[0],sms.SMS[i].MessageReference); +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer); +#endif + if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { + WriteSMSDLog("Error writing to database (SaveInboxSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + } + mysql_free_result(Res); continue; } if (sms.SMS[i].PDU != SMS_Deliver) continue; buffer[0]=0; - sprintf(buffer+strlen(buffer),"INSERT INTO `Inbox` \ - (`DateTime`,`Text`,`SenderNumber`,`Coding`,`SMSCNumber`,`UDH`, \ - `Class`,`TextDecoded`) VALUES ('%04d%02d%02d%02d%02d%02d','", + sprintf(buffer+strlen(buffer),"INSERT INTO `inbox` \ + (`ReceivingDateTime`,`Text`,`SenderNumber`,`Coding`,`SMSCNumber`,`UDH`, \ + `Class`,`TextDecoded`,`RecipientID`) VALUES ('%04d%02d%02d%02d%02d%02d','", 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); switch (sms.SMS[i].Coding) { @@ -96,9 +284,12 @@ static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig case SMS_Coding_8bit: break; } - sprintf(buffer+strlen(buffer),"')"); + sprintf(buffer+strlen(buffer),"','%s')",Config->PhoneID); +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer); +#endif if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { - WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + WriteSMSDLog("Error writing to database (SaveInbox): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); return ERR_UNKNOWN; } } @@ -106,45 +297,78 @@ static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig return ERR_NONE; } +static GSM_Error SMSDMySQL_RefreshSendStatus(GSM_SMSDConfig *Config, unsigned char *ID) +{ + unsigned char buffer[10000]; + + sprintf(buffer,"UPDATE `outbox` SET `SendingTimeOut`=(now() + INTERVAL 15 SECOND)+0 WHERE `ID` = '%s' AND `SendingTimeOut` < now()",ID); + if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { + WriteSMSDLog("Error writing to database (RefreshSendStatus): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer); +#endif + if (mysql_affected_rows(&Config->DB) == 0) return ERR_UNKNOWN; + return ERR_NONE; +} + /* Find one multi SMS to sending and return it (or return ERR_EMPTY) * There is also set ID for SMS */ static GSM_Error SMSDMySQL_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID) { - unsigned char buf[400]; - MYSQL_RES *Res; - MYSQL_ROW Row; - int i; + unsigned char buf[400]; + MYSQL_RES *Res; + MYSQL_ROW Row; + int i; + bool found = false; - sprintf(buf, "SELECT ID,DateTime FROM `Outbox` WHERE 1"); + sprintf(buf, "SELECT ID,InsertIntoDB,SendingDateTime,SenderID FROM `outbox` WHERE SendingDateTime < NOW() AND SendingTimeOut < NOW()"); if (mysql_real_query(&Config->DB,buf,strlen(buf))) { - WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); + WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB)); return ERR_UNKNOWN; } if (!(Res = mysql_store_result(&Config->DB))) { - WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); + WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB)); return ERR_UNKNOWN; } - if (!(Row = mysql_fetch_row(Res))) { + while ((Row = mysql_fetch_row(Res))) { + sprintf(ID,"%s",Row[0]); + sprintf(Config->DT,"%s",Row[1]); + if (strlen(Row[3]) == 0 || !strcmp(Row[3],Config->PhoneID)) { + if (SMSDMySQL_RefreshSendStatus(Config, ID)==ERR_NONE) { + found = true; + break; + } + } + } + if (!found) { mysql_free_result(Res); return ERR_EMPTY; } - sprintf(ID,"%s",Row[0]); - sprintf(Config->DT,"%s",Row[1]); + mysql_free_result(Res); sms->Number = 0; - for (i=1;i<10;i++) { - GSM_SetDefaultSMSData(&sms->SMS[sms->Number]); + for (i=0;i<MAX_MULTI_SMS;i++) { + GSM_SetDefaultSMSData(&sms->SMS[i]); + sms->SMS[i].SMSC.Number[0] = 0; + sms->SMS[i].SMSC.Number[1] = 0; + } + for (i=1;i<MAX_MULTI_SMS+1;i++) { if (i==1) { - sprintf(buf, "SELECT Text,DestinationNumber,Coding,UDH,SMSCNumber,Class,TextDecoded,ID,MultiPart FROM `Outbox` WHERE ID='%s'",ID); + sprintf(buf, "SELECT Text,Coding,UDH,Class,TextDecoded,ID,DestinationNumber,MultiPart,RelativeValidity,DeliveryReport FROM `outbox` WHERE ID='%s'",ID); } else { - sprintf(buf, "SELECT Text,DestinationNumber,Coding,UDH,SMSCNumber,Class,TextDecoded,ID,SequencePosition FROM `Outbox_MultiPart` WHERE ID='%s' AND SequencePosition='%i'",ID,i); + sprintf(buf, "SELECT Text,Coding,UDH,Class,TextDecoded,ID,SequencePosition FROM `outbox_multipart` WHERE ID='%s' AND SequencePosition='%i'",ID,i); } +#ifdef DEBUG + fprintf(stdout,"%s\n",buf); +#endif if (mysql_real_query(&Config->DB,buf,strlen(buf))) { - WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); + WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB)); return ERR_UNKNOWN; } if (!(Res = mysql_store_result(&Config->DB))) { - WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); + WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB)); return ERR_UNKNOWN; } if (!(Row = mysql_fetch_row(Res))) { @@ -153,11 +377,11 @@ static GSM_Error SMSDMySQL_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi } sms->SMS[sms->Number].Coding=SMS_Coding_Default; - if (!strcmp(Row[2],"Unicode")) sms->SMS[sms->Number].Coding=SMS_Coding_Unicode; - if (!strcmp(Row[2],"8bit")) sms->SMS[sms->Number].Coding=SMS_Coding_8bit; + if (!strcmp(Row[1],"Unicode")) sms->SMS[sms->Number].Coding=SMS_Coding_Unicode; + if (!strcmp(Row[1],"8bit")) sms->SMS[sms->Number].Coding=SMS_Coding_8bit; if (strlen(Row[0])==0) { - EncodeUnicode(sms->SMS[sms->Number].Text,Row[6],strlen(Row[6])); + EncodeUnicode(sms->SMS[sms->Number].Text,Row[4],strlen(Row[4])); } else { switch (sms->SMS[sms->Number].Coding) { case SMS_Coding_Unicode: @@ -169,100 +393,51 @@ static GSM_Error SMSDMySQL_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi sms->SMS[sms->Number].Length=strlen(Row[0])/2; } } - EncodeUnicode(sms->SMS[sms->Number].Number,Row[1],strlen(Row[1])); + if (i == 1) { + EncodeUnicode(sms->SMS[sms->Number].Number,Row[6],strlen(Row[6])); + } else { + CopyUnicodeString(sms->SMS[sms->Number].Number,sms->SMS[0].Number); + } sms->SMS[sms->Number].UDH.Type = UDH_NoUDH; - if (strlen(Row[3])!=0) { + if (strlen(Row[2])!=0) { sms->SMS[sms->Number].UDH.Type = UDH_UserUDH; - sms->SMS[sms->Number].UDH.Length = strlen(Row[3])/2; - DecodeHexBin(sms->SMS[sms->Number].UDH.Text,Row[3],strlen(Row[3])); + sms->SMS[sms->Number].UDH.Length = strlen(Row[2])/2; + DecodeHexBin(sms->SMS[sms->Number].UDH.Text,Row[2],strlen(Row[2])); } - EncodeUnicode(sms->SMS[sms->Number].SMSC.Number,Row[4],strlen(Row[4])); - sms->SMS[sms->Number].Class = atoi(Row[5]); + sms->SMS[sms->Number].Class = atoi(Row[3]); sms->SMS[sms->Number].PDU = SMS_Submit; - sms->SMS[sms->Number].SMSC.Location = 0; - sms->Number++; - if (i == 1 && !strcmp(Row[8],"false")) break; + sms->Number++; + if (i==1) { + Config->relativevalidity = atoi(Row[8]); + + Config->currdeliveryreport = -1; + if (!strcmp(Row[9],"yes")) { + Config->currdeliveryreport = 1; + } else if (!strcmp(Row[9],"no")) { + Config->currdeliveryreport = 0; + } + + if (!strcmp(Row[7],"false")) break; + + } } + mysql_free_result(Res); return ERR_NONE; } /* After sending SMS is moved to Sent Items or Error Items. */ static GSM_Error SMSDMySQL_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent) { - char *status; - unsigned char buffer[10000],buffer2[200],buffer3[2]; - int i,j,z; - - if (sent) status = "OK"; else status = "Error"; - - for (i=0;i<sms->Number;i++) { - buffer[0]=0; - sprintf(buffer+strlen(buffer),"UPDATE `SentItems` SET `Text`='"); - - switch (sms->SMS[i].Coding) { - case SMS_Coding_Unicode: - case SMS_Coding_Default: - EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[i].Text,UnicodeLength(sms->SMS[i].Text)); - break; - case SMS_Coding_8bit: - EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length); - } - - sprintf(buffer+strlen(buffer),"',`DestinationNumber`='%s',`Coding`='",DecodeUnicodeString(sms->SMS[i].Number)); - - switch (sms->SMS[i].Coding) { - case SMS_Coding_Unicode: - sprintf(buffer+strlen(buffer),"Unicode"); - break; - case SMS_Coding_Default: - sprintf(buffer+strlen(buffer),"Default"); - break; - case SMS_Coding_8bit: - sprintf(buffer+strlen(buffer),"8bit"); - break; - } - - sprintf(buffer+strlen(buffer),"',`SMSCNumber`='%s',`UDH`='",DecodeUnicodeString(sms->SMS[i].SMSC.Number)); - if (sms->SMS[i].UDH.Type != UDH_NoUDH) { - EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length); - } + unsigned char buffer[10000]; - sprintf(buffer+strlen(buffer),"',`Class`='%i',`TextDecoded`='",sms->SMS[i].Class); - switch (sms->SMS[i].Coding) { - case SMS_Coding_Unicode: - case SMS_Coding_Default: - sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[i].Text)); - for (j=0;j<(int)strlen(buffer2);j++) { - sprintf(buffer3,"'"); - z = strlen(buffer); - if (buffer2[j]==buffer3[0]) { - buffer[z+2]=0; - buffer[z+1]=buffer2[j]; - buffer[z] ='\\'; - } else { - buffer[z+1]=0; - buffer[z] =buffer2[j]; - } - } - break; - case SMS_Coding_8bit: - break; - } - sprintf(buffer+strlen(buffer),"',`Status`='%s',`DateTime`='%s' ",status,Config->DT); - sprintf(buffer+strlen(buffer),"WHERE `ID`='%s' AND `SequencePosition`='%i'",ID,i+1); - if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { - WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); - return ERR_UNKNOWN; - } - } - sprintf(buffer,"DELETE FROM `Outbox` WHERE `ID` = '%s'",ID); + sprintf(buffer,"DELETE FROM `outbox` WHERE `ID` = '%s'",ID); if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { - WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + WriteSMSDLog("Error deleting from database (MoveSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); return ERR_UNKNOWN; } - sprintf(buffer,"DELETE FROM `Outbox_MultiPart` WHERE `ID` = '%s'",ID); + sprintf(buffer,"DELETE FROM `outbox_multipart` WHERE `ID` = '%s'",ID); if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { - WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + WriteSMSDLog("Error deleting from database (MoveSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); return ERR_UNKNOWN; } return ERR_NONE; @@ -271,20 +446,47 @@ static GSM_Error SMSDMySQL_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Con /* Adds SMS to Outbox */ static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config) { - unsigned char buffer[10000],buffer2[200],buffer3[2],buffer4[10000]; - int i,j,z; - GSM_DateTime time; + unsigned char buffer[10000],buffer2[200],buffer3[2],buffer4[10000]; + int i,j,z,ID; + MYSQL_RES *Res; + MYSQL_ROW Row; + + sprintf(buffer,"SELECT ID FROM outbox ORDER BY ID DESC LIMIT 1"); + if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { + WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if ((Row = mysql_fetch_row(Res))) { + sprintf(buffer,"%s",Row[0]); + ID = atoi(buffer); + } else { + ID = 0; + } + mysql_free_result(Res); for (i=0;i<sms->Number;i++) { buffer[0]=0; if (i==0) { - sprintf(buffer+strlen(buffer),"INSERT INTO `Outbox` (`MultiPart`,`DateTime"); + sprintf(buffer+strlen(buffer),"INSERT INTO `outbox` (`DeliveryReport`,`MultiPart`,`InsertIntoDB"); } else { - sprintf(buffer+strlen(buffer),"INSERT INTO `Outbox_MultiPart` (`SequencePosition"); + sprintf(buffer+strlen(buffer),"INSERT INTO `outbox_multipart` (`SequencePosition"); } - sprintf(buffer+strlen(buffer),"`,`Text`,`DestinationNumber`,`Coding`,`SMSCNumber`,`UDH`, \ + sprintf(buffer+strlen(buffer),"`,`Text`,"); + if (i==0) { + sprintf(buffer+strlen(buffer),"`DestinationNumber`,`RelativeValidity`,"); + } + sprintf(buffer+strlen(buffer),"`Coding`,`UDH`, \ `Class`,`TextDecoded`,`ID`) VALUES ('"); if (i==0) { + if (sms->SMS[i].PDU == SMS_Status_Report) { + sprintf(buffer+strlen(buffer),"yes','"); + } else { + sprintf(buffer+strlen(buffer),"default','"); + } if (sms->Number == 1) { sprintf(buffer+strlen(buffer),"false"); } else { @@ -304,7 +506,16 @@ static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon case SMS_Coding_8bit: EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length); } - sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms->SMS[i].Number)); + sprintf(buffer+strlen(buffer),"',"); + if (i==0) { + sprintf(buffer+strlen(buffer),"'%s',",DecodeUnicodeString(sms->SMS[i].Number)); + if (sms->SMS[i].SMSC.Validity.Format == SMS_Validity_RelativeFormat) { + sprintf(buffer+strlen(buffer),"'%i',",sms->SMS[i].SMSC.Validity.Relative); + } else { + sprintf(buffer+strlen(buffer),"'-1',"); + } + } + sprintf(buffer+strlen(buffer),"'"); switch (sms->SMS[i].Coding) { case SMS_Coding_Unicode: sprintf(buffer+strlen(buffer),"Unicode"); @@ -316,15 +527,11 @@ static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon sprintf(buffer+strlen(buffer),"8bit"); break; } - sprintf(buffer+strlen(buffer),"','%s'",DecodeUnicodeString(sms->SMS[i].SMSC.Number)); - if (sms->SMS[i].UDH.Type == UDH_NoUDH) { - sprintf(buffer+strlen(buffer),",''"); - } else { - sprintf(buffer+strlen(buffer),",'"); + sprintf(buffer+strlen(buffer),"','"); + if (sms->SMS[i].UDH.Type != UDH_NoUDH) { EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length); - sprintf(buffer+strlen(buffer),"'"); } - sprintf(buffer+strlen(buffer),",'%i','",sms->SMS[i].Class); + sprintf(buffer+strlen(buffer),"','%i','",sms->SMS[i].Class); switch (sms->SMS[i].Coding) { case SMS_Coding_Unicode: case SMS_Coding_Default: @@ -349,31 +556,47 @@ static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon sprintf(buffer+strlen(buffer),"','"); if (i==0) { while (true) { - GSM_GetCurrentDateTime(&time); - buffer4[0] = 0; - strcpy(buffer4,buffer); - sprintf(buffer4+strlen(buffer4),"%i')", - time.Hour*1000000+ - time.Minute*10000+ - time.Second*100+time.Day); + ID++; + sprintf(buffer4,"SELECT ID FROM sentitems WHERE ID='%i'",ID); +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer4); +#endif if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) { - if (mysql_errno(&Config->DB) == ER_DUP_ENTRY) { - WriteSMSDLog("Duplicated outgoing SMS ID\n"); - continue; - } - WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB)); return ERR_UNKNOWN; } - break; + if (!(Res = mysql_store_result(&Config->DB))) { + WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + if (!(Row = mysql_fetch_row(Res))) { + buffer4[0] = 0; + strcpy(buffer4,buffer); + sprintf(buffer4+strlen(buffer4),"%i')",ID); +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer4); +#endif + if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) { + if (mysql_errno(&Config->DB) == ER_DUP_ENTRY) { + WriteSMSDLog("Duplicated outgoing SMS ID\n"); + continue; + } + WriteSMSDLog("Error writing to database (CreateOutbox): %d %s %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB),buffer4); + return ERR_UNKNOWN; + } + mysql_free_result(Res); + break; + } + mysql_free_result(Res); } } else { strcpy(buffer4,buffer); - sprintf(buffer4+strlen(buffer4),"%i')", - time.Hour*1000000+ - time.Minute*10000+ - time.Second*100+time.Day); + sprintf(buffer4+strlen(buffer4),"%i')",ID); +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer4); +#endif if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) { - WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + WriteSMSDLog("Error writing to database (CreateOutbox): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); return ERR_UNKNOWN; } } @@ -381,30 +604,117 @@ static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon return ERR_NONE; } -static GSM_Error SMSDMySQL_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK) + +static GSM_Error SMSDMySQL_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR) { - unsigned char buffer[10000]; + unsigned char buffer[10000],buffer2[200],buffer3[2],buff[50]; + int j,z; + + 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)); - if (OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number)); + buff[0] = 0; + if (err == SMSD_SEND_OK) { + if (sms->SMS[Part-1].PDU == SMS_Status_Report) { + sprintf(buff,"SendingOK"); + } else { + sprintf(buff,"SendingOKNoReport"); + } + } + if (err == SMSD_SEND_SENDING_ERROR) sprintf(buff,"SendingError"); + if (err == SMSD_SEND_ERROR) sprintf(buff,"Error"); buffer[0] = 0; - sprintf(buffer+strlen(buffer),"INSERT INTO `SentItems` \ - (`ID`,`SequencePosition`,`Status`,`SendingDateTime`) VALUES ("); - sprintf(buffer+strlen(buffer),"'%s','%i','Sending',NOW())",ID,Part); + sprintf(buffer+strlen(buffer),"INSERT INTO `sentitems` \ + (`ID`,`SequencePosition`,`Status`,`SendingDateTime`, `SMSCNumber`, `TPMR`, \ + `SenderID`,`Text`,`DestinationNumber`,`Coding`,`UDH`,`Class`,`TextDecoded`,`InsertIntoDB`,`RelativeValidity`) VALUES ("); + sprintf(buffer+strlen(buffer),"'%s','%i','%s',NOW(),'%s','%i','%s','",ID,Part,buff,DecodeUnicodeString(sms->SMS[Part-1].SMSC.Number),TPMR,Config->PhoneID); + switch (sms->SMS[Part-1].Coding) { + case SMS_Coding_Unicode: + case SMS_Coding_Default: + EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[Part-1].Text,UnicodeLength(sms->SMS[Part-1].Text)); + break; + case SMS_Coding_8bit: + EncodeHexBin(buffer+strlen(buffer),sms->SMS[Part-1].Text,sms->SMS[Part-1].Length); + } + sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms->SMS[Part-1].Number)); + switch (sms->SMS[Part-1].Coding) { + case SMS_Coding_Unicode: + sprintf(buffer+strlen(buffer),"Unicode"); + break; + case SMS_Coding_Default: + sprintf(buffer+strlen(buffer),"Default"); + break; + case SMS_Coding_8bit: + sprintf(buffer+strlen(buffer),"8bit"); + break; + } + sprintf(buffer+strlen(buffer),"','"); + if (sms->SMS[Part-1].UDH.Type != UDH_NoUDH) { + EncodeHexBin(buffer+strlen(buffer),sms->SMS[Part-1].UDH.Text,sms->SMS[Part-1].UDH.Length); + } + sprintf(buffer+strlen(buffer),"','%i','",sms->SMS[Part-1].Class); + switch (sms->SMS[Part-1].Coding) { + case SMS_Coding_Unicode: + case SMS_Coding_Default: + sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[Part-1].Text)); + for (j=0;j<(int)strlen(buffer2);j++) { + sprintf(buffer3,"'"); + z = strlen(buffer); + if (buffer2[j]==buffer3[0]) { + buffer[z+2]=0; + buffer[z+1]=buffer2[j]; + buffer[z] ='\\'; + } else { + buffer[z+1]=0; + buffer[z] =buffer2[j]; + } + } + break; + case SMS_Coding_8bit: + break; + } + sprintf(buffer+strlen(buffer),"','%s','",Config->DT); + if (sms->SMS[Part-1].SMSC.Validity.Format == SMS_Validity_RelativeFormat) { + sprintf(buffer+strlen(buffer),"%i')",sms->SMS[Part-1].SMSC.Validity.Relative); + } else { + sprintf(buffer+strlen(buffer),"-1')"); + } +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer); +#endif if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { - WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + WriteSMSDLog("Error writing to database (AddSent): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); return ERR_UNKNOWN; } return ERR_NONE; } +static GSM_Error SMSDMySQL_RefreshPhoneStatus(GSM_SMSDConfig *Config) +{ + unsigned char buffer[500]; + + sprintf(buffer,"UPDATE `phones` SET `TimeOut`= (NOW() + INTERVAL 10 SECOND)+0"); + sprintf(buffer+strlen(buffer)," WHERE `IMEI` = '%s'",s.Phone.Data.IMEI); +#ifdef DEBUG + fprintf(stdout,"%s\n",buffer); +#endif + if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { + WriteSMSDLog("Error writing to database (SaveInboxSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); + return ERR_UNKNOWN; + } + return ERR_NONE; +} + GSM_SMSDService SMSDMySQL = { SMSDMySQL_Init, + SMSDMySQL_InitAfterConnect, SMSDMySQL_SaveInboxSMS, SMSDMySQL_FindOutboxSMS, SMSDMySQL_MoveSMS, SMSDMySQL_CreateOutboxSMS, - SMSDMySQL_AddSentSMSInfo + SMSDMySQL_AddSentSMSInfo, + SMSDMySQL_RefreshSendStatus, + SMSDMySQL_RefreshPhoneStatus }; #endif 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,4 +1,4 @@ -/* (c) 2002-2003 by Marcin Wiacek and Joergen Thomsen */ +/* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */ #include <string.h> #include <signal.h> @@ -14,10 +14,13 @@ #endif FILE *smsd_log_file = NULL; +static int TPMR; static GSM_Error SendingSMSStatus; + static void SMSSendingSMSStatus (char *Device, int status, int mr) { dbgprintf("Incoming SMS device: \"%s\" status=%d, reference=%d\n",Device, status, mr); + TPMR = mr; if (status==0) { SendingSMSStatus = ERR_NONE; } else { @@ -73,7 +76,7 @@ void WriteSMSDLog(char *format, ...) } } -void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) +void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log, char *service) { INI_Section *smsdcfgfile = NULL; GSM_Config smsdcfg; @@ -102,6 +105,7 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) if (Config->IncludeNumbers) { GSM_ReadConfig(smsdcfgfile, &smsdcfg, 0); memcpy(&s.Config,&smsdcfg,sizeof(GSM_Config)); + error=GSM_SetDebugFile(s.Config[0].DebugFile, &di); } Config->PINCode=INI_GetValue(smsdcfgfile, "smsd", "PIN", false); @@ -112,22 +116,16 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) } if (log) WriteSMSDLog("PIN code is \"%s\"",Config->PINCode); - Config->user = INI_GetValue(smsdcfgfile, "smsd", "user", false); - if (Config->user == NULL) Config->user="root"; - Config->password = INI_GetValue(smsdcfgfile, "smsd", "password", false); - if (Config->password == NULL) Config->password=""; - Config->PC = INI_GetValue(smsdcfgfile, "smsd", "pc", false); - if (Config->PC == NULL) Config->PC="localhost"; - Config->database = INI_GetValue(smsdcfgfile, "smsd", "database", false); - if (Config->database == NULL) Config->database="sms"; - str = INI_GetValue(smsdcfgfile, "smsd", "commtimeout", false); if (str) Config->commtimeout=atoi(str); else Config->commtimeout = 1; str = INI_GetValue(smsdcfgfile, "smsd", "sendtimeout", false); if (str) Config->sendtimeout=atoi(str); else Config->sendtimeout = 10; str = INI_GetValue(smsdcfgfile, "smsd", "receivefrequency", false); if (str) Config->receivefrequency=atoi(str); else Config->receivefrequency = 0; - if (log) WriteSMSDLog("commtimeout=%i, sendtimeout=%i, receivefrequency=%i", Config->commtimeout, Config->sendtimeout, Config->receivefrequency); + str = INI_GetValue(smsdcfgfile, "smsd", "resetfrequency", false); + if (str) Config->resetfrequency=atoi(str); else Config->resetfrequency = 0; + if (log) WriteSMSDLog("commtimeout=%i, sendtimeout=%i, receivefrequency=%i, resetfrequency=%i", + Config->commtimeout, Config->sendtimeout, Config->receivefrequency, Config->resetfrequency); Config->deliveryreport = INI_GetValue(smsdcfgfile, "smsd", "deliveryreport", false); if (Config->deliveryreport == NULL || (!mystrncasecmp(Config->deliveryreport, "log", 3) && !mystrncasecmp(Config->deliveryreport, "sms", 3))) { @@ -135,31 +133,52 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) } if (log) WriteSMSDLog("deliveryreport = %s", Config->deliveryreport); - Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false); - if (Config->inboxpath == NULL) Config->inboxpath = emptyPath; + Config->PhoneID = INI_GetValue(smsdcfgfile, "smsd", "phoneid", false); + if (Config->PhoneID == NULL) Config->PhoneID = ""; + if (log) WriteSMSDLog("phoneid = %s", Config->PhoneID); - Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false); - if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) { - Config->inboxformat = "standard"; - } - if (log) WriteSMSDLog("Inbox is \"%s\" with format \"%s\"", Config->inboxpath, Config->inboxformat); + if (!strcmp(service,"FILES")) { + Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false); + if (Config->inboxpath == NULL) Config->inboxpath = emptyPath; - Config->outboxpath=INI_GetValue(smsdcfgfile, "smsd", "outboxpath", false); - if (Config->outboxpath == NULL) Config->outboxpath = emptyPath; + Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false); + if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) { + Config->inboxformat = "standard"; + } + if (log) WriteSMSDLog("Inbox is \"%s\" with format \"%s\"", Config->inboxpath, Config->inboxformat); - Config->transmitformat=INI_GetValue(smsdcfgfile, "smsd", "transmitformat", false); - if (Config->transmitformat == NULL || (!mystrncasecmp(Config->transmitformat, "auto", 4) && !mystrncasecmp(Config->transmitformat, "unicode", 7))) { - Config->transmitformat = "7bit"; - } - if (log) WriteSMSDLog("Outbox is \"%s\" with transmission format \"%s\"", Config->outboxpath, Config->transmitformat); + Config->outboxpath=INI_GetValue(smsdcfgfile, "smsd", "outboxpath", false); + if (Config->outboxpath == NULL) Config->outboxpath = emptyPath; - Config->sentsmspath=INI_GetValue(smsdcfgfile, "smsd", "sentsmspath", false); - if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath; - if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath); + Config->transmitformat=INI_GetValue(smsdcfgfile, "smsd", "transmitformat", false); + if (Config->transmitformat == NULL || (!mystrncasecmp(Config->transmitformat, "auto", 4) && !mystrncasecmp(Config->transmitformat, "unicode", 7))) { + Config->transmitformat = "7bit"; + } + if (log) WriteSMSDLog("Outbox is \"%s\" with transmission format \"%s\"", Config->outboxpath, Config->transmitformat); - Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false); - if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath; - if (log) WriteSMSDLog("SMS with errors moved to \"%s\"",Config->errorsmspath); + Config->sentsmspath=INI_GetValue(smsdcfgfile, "smsd", "sentsmspath", false); + if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath; + if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath); + + Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false); + if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath; + if (log) WriteSMSDLog("SMS with errors moved to \"%s\"",Config->errorsmspath); + } + +#ifdef HAVE_MYSQL_MYSQL_H + if (!strcmp(service,"MYSQL")) { + Config->skipsmscnumber = INI_GetValue(smsdcfgfile, "smsd", "skipsmscnumber", false); + if (Config->skipsmscnumber == NULL) Config->skipsmscnumber=""; + Config->user = INI_GetValue(smsdcfgfile, "smsd", "user", false); + if (Config->user == NULL) Config->user="root"; + Config->password = INI_GetValue(smsdcfgfile, "smsd", "password", false); + if (Config->password == NULL) Config->password=""; + Config->PC = INI_GetValue(smsdcfgfile, "smsd", "pc", false); + if (Config->PC == NULL) Config->PC="localhost"; + Config->database = INI_GetValue(smsdcfgfile, "smsd", "database", false); + if (Config->database == NULL) Config->database="sms"; + } +#endif Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "include_numbers", false); Config->ExcludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "exclude_numbers", false); @@ -174,8 +193,10 @@ void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) } } - Config->retries = 0; - Config->prevSMSID[0] = 0; + Config->retries = 0; + Config->prevSMSID[0] = 0; + Config->SMSC.Location = 0; + Config->relativevalidity = -1; } bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) @@ -192,6 +213,7 @@ bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) } /* No supported - do not check more */ if (error == ERR_NOTSUPPORTED) return true; + /* If PIN, try to enter */ switch (SecurityCode.Type) { case SEC_Pin: @@ -326,6 +348,7 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) my_sleep(10); GSM_GetCurrentDateTime(&Date); } + Service->RefreshPhoneStatus(Config); } return true; } @@ -333,11 +356,12 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) /* Unknown error - escape */ WriteSMSDLog("Error in outbox on %s", Config->SMSID); for (i=0;i<sms.Number;i++) { - Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); + Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_ERROR, -1); } Service->MoveSMS(&sms,Config, Config->SMSID, true,false); return false; } + if (!gshutdown) { if (strcmp(Config->prevSMSID, Config->SMSID) == 0) { Config->retries++; @@ -346,7 +370,7 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) strcpy(Config->prevSMSID, ""); WriteSMSDLog("Moved to errorbox: %s", Config->SMSID); for (i=0;i<sms.Number;i++) { - Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); + Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_ERROR, -1); } Service->MoveSMS(&sms,Config, Config->SMSID, true,false); return false; @@ -355,14 +379,40 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) Config->retries = 0; strcpy(Config->prevSMSID, Config->SMSID); } - for (i=0;i<sms.Number;i++) { - if (strcmp(Config->deliveryreport, "no") != 0) sms.SMS[i].PDU = SMS_Status_Report; + for (i=0;i<sms.Number;i++) { + if (sms.SMS[i].SMSC.Location == 1) { + if (Config->SMSC.Location == 0) { + Config->SMSC.Location = 1; + error = Phone->GetSMSC(&s,&Config->SMSC); + if (error!=ERR_NONE) { + WriteSMSDLog("Error getting SMSC from phone"); + return false; + } + + } + memcpy(&sms.SMS[i].SMSC,&Config->SMSC,sizeof(GSM_SMSC)); + sms.SMS[i].SMSC.Location = 0; + if (Config->relativevalidity != -1) { + sms.SMS[i].SMSC.Validity.Format = SMS_Validity_RelativeFormat; + sms.SMS[i].SMSC.Validity.Relative = Config->relativevalidity; + } + } + + if (Config->currdeliveryreport == 1) { + sms.SMS[i].PDU = SMS_Status_Report; + } else { + if ((strcmp(Config->deliveryreport, "no") != 0 && (Config->currdeliveryreport == -1))) sms.SMS[i].PDU = SMS_Status_Report; + } + error=Phone->SendSMS(&s, &sms.SMS[i]); if (error!=ERR_NONE) { + Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_SENDING_ERROR, -1); WriteSMSDLog("Error sending SMS %s (%i): %s", Config->SMSID, error,print_error(error,s.di.df,s.msg)); return false; } - j=0; + Service->RefreshPhoneStatus(Config); + j = 0; + TPMR = -1; SendingSMSStatus = ERR_TIMEOUT; while (!gshutdown) { GSM_GetCurrentDateTime (&Date); @@ -373,23 +423,22 @@ bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) GSM_ReadDevice(&s,true); if (SendingSMSStatus != ERR_TIMEOUT) break; } + Service->RefreshSendStatus(Config, Config->SMSID); + Service->RefreshPhoneStatus(Config); if (SendingSMSStatus != ERR_TIMEOUT) break; j++; if (j>Config->sendtimeout) break; } if (SendingSMSStatus != ERR_NONE) { + Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_SENDING_ERROR, TPMR); WriteSMSDLog("Error getting send status of %s (%i): %s", Config->SMSID, SendingSMSStatus,print_error(SendingSMSStatus,s.di.df,s.msg)); return false; } - error = Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, true); + error = Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_OK, TPMR); if (error!=ERR_NONE) { return false; } } - while ((int)i<sms.Number-1) { - Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); - i++; - } strcpy(Config->prevSMSID, ""); if (Service->MoveSMS(&sms,Config, Config->SMSID, false, true) != ERR_NONE) { Service->MoveSMS(&sms,Config, Config->SMSID, true, false); @@ -403,7 +452,7 @@ void SMSDaemon(int argc, char *argv[]) int errors = 255, initerrors=0; GSM_SMSDService *Service; GSM_Error error; - time_t time1; + time_t lastreceive, lastreset = 0; GSM_SMSDConfig Config; if (!strcmp(argv[2],"FILES")) { @@ -417,7 +466,7 @@ void SMSDaemon(int argc, char *argv[]) exit(-1); } - SMSD_ReadConfig(argv[3], &Config, true); + SMSD_ReadConfig(argv[3], &Config, true, argv[2]); error = Service->Init(&Config); if (error!=ERR_NONE) { @@ -428,7 +477,8 @@ void SMSDaemon(int argc, char *argv[]) signal(SIGTERM, interrupt); fprintf(stderr,"Press Ctrl+C to stop the program ...\n"); - time1 = time(NULL); + lastreceive = time(NULL); + lastreset = time(NULL); SendingSMSStatus = ERR_UNKNOWN; while (!gshutdown) { @@ -445,7 +495,27 @@ void SMSDaemon(int argc, char *argv[]) case ERR_NONE: s.User.SendSMSStatus = SMSSendingSMSStatus; Phone = s.Phone.Functions; - errors = 0; + if (errors == 255) { + errors = 0; + s.Phone.Data.IMEI[0] = 0; + if (!(Phone->GetIMEI(&s))) { + errors++; + } else { + error = Service->InitAfterConnect(&Config); + if (error!=ERR_NONE) { + GSM_Terminate_SMSD("Stop GAMMU smsd (%i)", error, true, -1); + } + Phone->SetFastSMSSending(&s,true); + } + } else { + errors = 0; + } + if (initerrors > 3 || initerrors < 0) { + error=Phone->Reset(&s, false); /* soft reset */ + WriteSMSDLog("Reset return code: %s (%i) ", error == ERR_NONE? "OK":"ERROR", error); + lastreset = time(NULL); + my_sleep(5000); + } /* Marcin Wiacek: FIXME. To check */ // di = s.di; break; @@ -457,8 +527,8 @@ void SMSDaemon(int argc, char *argv[]) } continue; } - if ((difftime(time(NULL), time1) >= Config.receivefrequency) || (SendingSMSStatus != ERR_NONE)) { - time1 = time(NULL); + if ((difftime(time(NULL), lastreceive) >= Config.receivefrequency) || (SendingSMSStatus != ERR_NONE)) { + lastreceive = time(NULL); if (!SMSD_CheckSecurity(&Config)) { errors++; @@ -468,13 +538,19 @@ void SMSDaemon(int argc, char *argv[]) initerrors = 0; - if (!SMSD_CheckSMSStatus(&Config,Service)) { + if (!SMSD_CheckSMSStatus(&Config,Service)) { /* read all incoming SMS */ errors++; continue; } else errors=0; + + if (Config.resetfrequency > 0 && difftime(time(NULL), lastreset) >= Config.resetfrequency) { /* time for preventive reset */ + errors = 254; initerrors = -2; + continue; + } } if (!SMSD_SendSMS(&Config,Service)) continue; } + Phone->SetFastSMSSending(&s,false); GSM_Terminate_SMSD("Stop GAMMU smsd", 0, false, 0); } @@ -494,7 +570,7 @@ GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *s exit(-1); } - SMSD_ReadConfig(filename, &Config, false); + SMSD_ReadConfig(filename, &Config, false, service); error = Service->Init(&Config); if (error!=ERR_NONE) return ERR_UNKNOWN; 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,7 +1,7 @@ -/* (c) 2002-2003 by Marcin Wiacek and Joergen Thomsen */ +/* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */ #include "../../cfg/config.h" -#undef HAVE_MYSQL_MYSQL_H + #ifdef HAVE_MYSQL_MYSQL_H #ifdef WIN32 # include <mysql.h> @@ -24,7 +24,9 @@ typedef struct { /* general options */ INI_Entry *IncludeNumbers, *ExcludeNumbers; unsigned int commtimeout, sendtimeout, receivefrequency; + unsigned int resetfrequency; unsigned char *deliveryreport, *logfilename, *PINCode; + unsigned char *PhoneID; /* options for FILES */ unsigned char *inboxpath, *outboxpath, *sentsmspath; @@ -32,23 +34,38 @@ typedef struct { /* options for MYSQL */ unsigned char *database, *user, *password; - unsigned char *PC; + unsigned char *PC, *skipsmscnumber; /* private variables required for work */ - unsigned int retries; + int relativevalidity; + unsigned int retries, currdeliveryreport; unsigned char SMSID[200], prevSMSID[200]; + GSM_SMSC SMSC; #ifdef HAVE_MYSQL_MYSQL_H MYSQL DB; char DT[20]; #endif } GSM_SMSDConfig; +typedef enum { + SMSD_SEND_OK = 1, + SMSD_SEND_SENDING_ERROR, + SMSD_SEND_DELIVERY_PENDING, + SMSD_SEND_DELIVERY_FAILED, + SMSD_SEND_DELIVERY_OK, + SMSD_SEND_DELIVERY_UNKNOWN, + SMSD_SEND_ERROR +} GSM_SMSDSendingError; + typedef struct { - GSM_Error (*Init) (GSM_SMSDConfig *Config); - GSM_Error (*SaveInboxSMS) (GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config); - GSM_Error (*FindOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID); - GSM_Error (*MoveSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent); - GSM_Error (*CreateOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config); - GSM_Error (*AddSentSMSInfo) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK); + GSM_Error (*Init) (GSM_SMSDConfig *Config); + GSM_Error (*InitAfterConnect) (GSM_SMSDConfig *Config); + GSM_Error (*SaveInboxSMS) (GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config); + GSM_Error (*FindOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID); + GSM_Error (*MoveSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent); + GSM_Error (*CreateOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config); + GSM_Error (*AddSentSMSInfo) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR); + GSM_Error (*RefreshSendStatus) (GSM_SMSDConfig *Config, unsigned char *ID); + GSM_Error (*RefreshPhoneStatus) (GSM_SMSDConfig *Config); } GSM_SMSDService; #ifdef __GNUC__ |