diff options
Diffstat (limited to 'gammu')
-rw-r--r-- | gammu/CMakeLists.txt | 6 | ||||
-rw-r--r-- | gammu/CMakeTests.txt | 1 | ||||
-rw-r--r-- | gammu/backupsms.c | 126 | ||||
-rw-r--r-- | gammu/depend/nokia/dct4.c | 2 | ||||
-rw-r--r-- | gammu/depend/siemens/dsiemens.c | 11 | ||||
-rw-r--r-- | gammu/files.c | 16 | ||||
-rw-r--r-- | gammu/gammu.c | 9 | ||||
-rw-r--r-- | gammu/message.c | 57 | ||||
-rw-r--r-- | gammu/misc.c | 142 | ||||
-rw-r--r-- | gammu/misc.h | 2 | ||||
-rw-r--r-- | gammu/mms.c | 3 | ||||
-rw-r--r-- | gammu/nokia.c | 6 |
12 files changed, 157 insertions, 224 deletions
diff --git a/gammu/CMakeLists.txt b/gammu/CMakeLists.txt index 4f9c053..6857340 100644 --- a/gammu/CMakeLists.txt +++ b/gammu/CMakeLists.txt @@ -18,7 +18,6 @@ set (BINARY_SRC depend/nokia/dct4.c depend/siemens/dsiemens.c depend/siemens/chiffre.c - sniff.c common.c memory.c message.c @@ -34,6 +33,10 @@ if (WITH_BACKUP) list(APPEND BINARY_SRC backup.c backupsms.c) endif (WITH_BACKUP) +if (DEBUG) + list(APPEND BINARY_SRC sniff.c) +endif() + # Hides default case in switch, to allow checking whether all cases are handled. if(DEBUG) @@ -42,6 +45,7 @@ endif(DEBUG) # Gammu program add_executable (gammu ${BINARY_SRC}) +add_coverage (gammu) target_link_libraries (gammu libGammu) target_link_libraries (gammu messagedisplay) diff --git a/gammu/CMakeTests.txt b/gammu/CMakeTests.txt index ae6ba23..41d4cc1 100644 --- a/gammu/CMakeTests.txt +++ b/gammu/CMakeTests.txt @@ -344,7 +344,6 @@ gammu_test_fail(getwapbookmark "Entry is empty" 3) if (ONLINE_TESTING AND CURL_FOUND) gammu_test(checkversion "") - gammu_test(getlocation "Number of samples;Could not connect to the server;Could not resolve the host name") endif (ONLINE_TESTING AND CURL_FOUND) # MMS decoding diff --git a/gammu/backupsms.c b/gammu/backupsms.c index 9c18b4d..82ddb6a 100644 --- a/gammu/backupsms.c +++ b/gammu/backupsms.c @@ -19,14 +19,24 @@ void BackupSMS(int argc UNUSED, char *argv[]) { GSM_Error error; - GSM_SMS_Backup Backup; - GSM_MultiSMSMessage sms; + GSM_SMS_Backup *Backup; + GSM_MultiSMSMessage *sms; GSM_SMSFolders folders; gboolean BackupFromFolder[GSM_MAX_SMS_FOLDERS]; gboolean start = TRUE; gboolean DeleteAfter = FALSE, askdelete = TRUE; int j, smsnum = 0; + sms = malloc(sizeof(GSM_MultiSMSMessage)); + if (sms == NULL) { + return; + } + Backup = malloc(sizeof(GSM_SMS_Backup)); + if (Backup == NULL) { + free(sms); + return; + } + if (argc == 4) { if (strcasecmp(argv[3],"-yes") == 0) { always_answer_yes = TRUE; @@ -40,9 +50,9 @@ void BackupSMS(int argc UNUSED, char *argv[]) GSM_Init(TRUE); - Backup.SMS[0] = NULL; - sms.SMS[0].Location = 0; - sms.Number = 0; + Backup->SMS[0] = NULL; + sms->SMS[0].Location = 0; + sms->Number = 0; error=GSM_GetSMSFolders(gsm, &folders); Print_Error(error); @@ -61,31 +71,31 @@ void BackupSMS(int argc UNUSED, char *argv[]) } while (error == ERR_NONE) { - sms.SMS[0].Folder=0x00; - error=GSM_GetNextSMS(gsm, &sms, start); + sms->SMS[0].Folder=0x00; + error=GSM_GetNextSMS(gsm, sms, start); switch (error) { case ERR_EMPTY: break; default: Print_Error(error); - for (j=0;j<sms.Number;j++) { - if (BackupFromFolder[sms.SMS[j].Folder-1]) { - switch (sms.SMS[j].PDU) { + for (j=0;j<sms->Number;j++) { + if (BackupFromFolder[sms->SMS[j].Folder-1]) { + switch (sms->SMS[j].PDU) { case SMS_Status_Report: break; case SMS_Submit: case SMS_Deliver: - if (sms.SMS[j].Length == 0) break; + if (sms->SMS[j].Length == 0) break; if (smsnum < GSM_BACKUP_MAX_SMS) { - Backup.SMS[smsnum] = malloc(sizeof(GSM_SMSMessage)); - if (Backup.SMS[smsnum] == NULL) Print_Error(ERR_MOREMEMORY); - Backup.SMS[smsnum + 1] = NULL; + Backup->SMS[smsnum] = malloc(sizeof(GSM_SMSMessage)); + if (Backup->SMS[smsnum] == NULL) Print_Error(ERR_MOREMEMORY); + Backup->SMS[smsnum + 1] = NULL; } else { printf(_(" Increase %s\n") , "GSM_BACKUP_MAX_SMS"); GSM_Terminate(); Terminate(1); } - *Backup.SMS[smsnum] = sms.SMS[j]; + *(Backup->SMS[smsnum]) = sms->SMS[j]; smsnum++; break; } @@ -95,13 +105,13 @@ void BackupSMS(int argc UNUSED, char *argv[]) start=FALSE; } - error = GSM_AddSMSBackupFile(argv[2],&Backup); + error = GSM_AddSMSBackupFile(argv[2], Backup); Print_Error(error); if (DeleteAfter) { for (j=0;j<smsnum;j++) { - Backup.SMS[j]->Folder = 0; - error=GSM_DeleteSMS(gsm, Backup.SMS[j]); + Backup->SMS[j]->Folder = 0; + error=GSM_DeleteSMS(gsm, Backup->SMS[j]); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Deleting:")); @@ -110,43 +120,60 @@ void BackupSMS(int argc UNUSED, char *argv[]) } } - GSM_FreeSMSBackup(&Backup); + GSM_FreeSMSBackup(Backup); + + free(Backup); + free(sms); GSM_Terminate(); } -void AddSMS(int argc UNUSED, char *argv[]) +void AddSMS(int argc, char *argv[]) { GSM_Error error; - GSM_MultiSMSMessage SMS; - GSM_SMS_Backup Backup; + GSM_MultiSMSMessage *SMS; + GSM_SMS_Backup *Backup; int smsnum = 0; int folder; if (argc == 5 && strcasecmp(argv[4],"-yes") == 0) always_answer_yes = TRUE; + SMS = malloc(sizeof(GSM_MultiSMSMessage)); + if (SMS == NULL) { + return; + } + Backup = malloc(sizeof(GSM_SMS_Backup)); + if (Backup == NULL) { + free(SMS); + return; + } + + folder = GetInt(argv[2]); - error = GSM_ReadSMSBackupFile(argv[3], &Backup); + error = GSM_ReadSMSBackupFile(argv[3], Backup); Print_Error(error); GSM_Init(TRUE); - while (Backup.SMS[smsnum] != NULL) { - Backup.SMS[smsnum]->Folder = folder; - Backup.SMS[smsnum]->SMSC.Location = 1; - SMS.Number = 1; - SMS.SMS[0] = *Backup.SMS[smsnum]; - DisplayMultiSMSInfo(&SMS,FALSE,FALSE,NULL, gsm); + while (Backup->SMS[smsnum] != NULL) { + Backup->SMS[smsnum]->Folder = folder; + Backup->SMS[smsnum]->SMSC.Location = 1; + SMS->Number = 1; + SMS->SMS[0] = *(Backup->SMS[smsnum]); + DisplayMultiSMSInfo(SMS, FALSE, FALSE, NULL, gsm); if (answer_yes("%s", _("Restore message?"))) { - error=GSM_AddSMS(gsm, Backup.SMS[smsnum]); + error=GSM_AddSMS(gsm, Backup->SMS[smsnum]); Print_Error(error); } smsnum++; } /* We don't need this anymore */ - GSM_FreeSMSBackup(&Backup); + GSM_FreeSMSBackup(Backup); + + free(Backup); + free(SMS); GSM_Terminate(); } @@ -154,15 +181,25 @@ void AddSMS(int argc UNUSED, char *argv[]) void RestoreSMS(int argc, char *argv[]) { GSM_Error error; - GSM_MultiSMSMessage SMS; - GSM_SMS_Backup Backup; + GSM_MultiSMSMessage *SMS; + GSM_SMS_Backup *Backup; GSM_SMSFolders folders; int smsnum = 0; gboolean restore8bit; + SMS = malloc(sizeof(GSM_MultiSMSMessage)); + if (SMS == NULL) { + return; + } + Backup = malloc(sizeof(GSM_SMS_Backup)); + if (Backup == NULL) { + free(SMS); + return; + } + if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE; - error = GSM_ReadSMSBackupFile(argv[2], &Backup); + error = GSM_ReadSMSBackupFile(argv[2], Backup); Print_Error(error); restore8bit = answer_yes("%s", _("Do you want to restore binary SMS?")); @@ -172,17 +209,17 @@ void RestoreSMS(int argc, char *argv[]) error = GSM_GetSMSFolders(gsm, &folders); Print_Error(error); - while (Backup.SMS[smsnum] != NULL) { - if (restore8bit || Backup.SMS[smsnum]->Coding != SMS_Coding_8bit) { - SMS.Number = 1; - memcpy(&SMS.SMS[0],Backup.SMS[smsnum],sizeof(GSM_SMSMessage)); - DisplayMultiSMSInfo(&SMS,FALSE,FALSE,NULL, gsm); + while (Backup->SMS[smsnum] != NULL) { + if (restore8bit || Backup->SMS[smsnum]->Coding != SMS_Coding_8bit) { + SMS->Number = 1; + memcpy(&(SMS->SMS[0]), Backup->SMS[smsnum], sizeof(GSM_SMSMessage)); + DisplayMultiSMSInfo(SMS, FALSE, FALSE, NULL, gsm); if (answer_yes(_("Restore %03i sms to folder \"%s\"%s?"), smsnum + 1, - DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder - 1].Name), - folders.Folder[Backup.SMS[smsnum]->Folder - 1].Memory == MEM_SM ? _(" (SIM)") : "")) { + DecodeUnicodeConsole(folders.Folder[Backup->SMS[smsnum]->Folder - 1].Name), + folders.Folder[Backup->SMS[smsnum]->Folder - 1].Memory == MEM_SM ? _(" (SIM)") : "")) { smprintf(gsm, _("saving %i SMS\n"),smsnum); - error = GSM_AddSMS(gsm, Backup.SMS[smsnum]); + error = GSM_AddSMS(gsm, Backup->SMS[smsnum]); Print_Error(error); } } @@ -190,7 +227,10 @@ void RestoreSMS(int argc, char *argv[]) } /* We don't need this anymore */ - GSM_FreeSMSBackup(&Backup); + GSM_FreeSMSBackup(Backup); + + free(Backup); + free(SMS); GSM_Terminate(); } diff --git a/gammu/depend/nokia/dct4.c b/gammu/depend/nokia/dct4.c index b7a5300..a5c0877 100644 --- a/gammu/depend/nokia/dct4.c +++ b/gammu/depend/nokia/dct4.c @@ -300,7 +300,7 @@ void DCT4SetPhoneMenus(int argc, char *argv[]) } if (current == 10) { - printf("%s\n", _("Sorry, but configuration matrix for this model has not yet been added. See <http://wammu.eu/support/bugs/> for information how to report it.")); + printf("%s\n", _("Sorry, but configuration matrix for this model has not yet been added. See <https://wammu.eu/support/bugs/> for information how to report it.")); return; } diff --git a/gammu/depend/siemens/dsiemens.c b/gammu/depend/siemens/dsiemens.c index 85f7ce2..5cffcb6 100644 --- a/gammu/depend/siemens/dsiemens.c +++ b/gammu/depend/siemens/dsiemens.c @@ -195,9 +195,11 @@ GSM_Error ATSIEMENS_Reply_GetSAT(GSM_Protocol_Message *msg, GSM_StateMachine *sm result = 0; GetBufferI(buf+14,&j,&result,5); - if (new_variable) + if (new_variable) { MeasureResult.NeighbourCell[i].ChFreq = frequency[result+1]; - else MeasureResult.NeighbourCell[i].ChFreq = frequency[result]; + } else { + MeasureResult.NeighbourCell[i].ChFreq = frequency[result]; + } result = 0; GetBufferI(buf+14,&j,&result,3); @@ -206,10 +208,11 @@ GSM_Error ATSIEMENS_Reply_GetSAT(GSM_Protocol_Message *msg, GSM_StateMachine *sm GetBufferI(buf+14,&j,&result,3); MeasureResult.NeighbourCell[i].NB += result; - if (MeasureResult.NeighbourCell[i].ChFreq) + if (MeasureResult.NeighbourCell[i].ChFreq) { printf("CH = %i,\t",MeasureResult.NeighbourCell[i].ChFreq); - else + } else { printf("CH = Unknown\t"); + } printf("RX Lev = %i dBm\t",MeasureResult.NeighbourCell[i].RxLev); printf("BSIC CELL = %i\n",MeasureResult.NeighbourCell[i].NB); } diff --git a/gammu/files.c b/gammu/files.c index a9c8da5..9ddd6cb 100644 --- a/gammu/files.c +++ b/gammu/files.c @@ -46,15 +46,15 @@ static GSM_Error PrintFileSystemStatus(void) printf("\n"); printf(LISTFORMAT, _("Phone memory")); - printf(_("%i bytes (free %i bytes, used %i bytes)"), - Status.Free + Status.Used, Status.Free, Status.Used); + printf(_("%ld bytes (free %ld bytes, used %ld bytes)"), + (long)(Status.Free + Status.Used), (long)(Status.Free), (long)(Status.Used)); printf("\n"); if (Status.UsedImages != 0 || Status.UsedSounds != 0 || Status.UsedThemes != 0) { printf(LISTFORMAT, _("Usage details")); - printf(_("images: %i, sounds: %i, themes: %i"), - Status.UsedImages, Status.UsedSounds, Status.UsedThemes); + printf(_("images: %ld, sounds: %ld, themes: %ld"), + (long)(Status.UsedImages), (long)(Status.UsedSounds), (long)(Status.UsedThemes)); printf("\n"); } @@ -105,7 +105,7 @@ void GetFileSystem(int argc, char *argv[]) } } - if (argc <= 2 || !strcasecmp(argv[2], "-flatall") == 0) { + if (argc <= 2 || strcasecmp(argv[2], "-flatall") != 0) { /* Nokia filesystem 1 */ if (UnicodeLength(Files.ID_FullName) != 0 && (DecodeUnicodeString(Files.ID_FullName)[0] == 'C' || @@ -348,7 +348,8 @@ static void GetOneFile(GSM_File * File, gboolean newtime, int i) gboolean start; unsigned char buffer[5000]; struct utimbuf filedate; - int Handle, Size, p, q, j, old1; + int Handle, p, q, j, old1; + size_t Size; time_t t_time1, t_time2; long diff; @@ -578,7 +579,8 @@ void GetFileFolder(int argc, char *argv[]) void AddOneFile(GSM_File * File, const char *text, const gboolean send) { GSM_Error error; - int Pos, Handle, i, j, old1; + size_t Pos; + int Handle, i, j, old1; time_t t_time1, t_time2; GSM_DateTime dt; long diff; diff --git a/gammu/gammu.c b/gammu/gammu.c index 4d234f2..b88109c 100644 --- a/gammu/gammu.c +++ b/gammu/gammu.c @@ -53,7 +53,7 @@ #define ALL_MEMORY_TYPES "DC|MC|RC|ON|VM|SM|ME|MT|FD|SL" -#define RSS_URL "http://wammu.eu/news/rss/" +#define RSS_URL "https://wammu.eu/news/rss/" #define RSS_STABLE_STRING "Gammu stable version " #define RSS_TESTING_STRING "Gammu test version " @@ -329,7 +329,7 @@ static void Version(int argc UNUSED, char *argv[]UNUSED) { PrintVersion(); - printf("%s\n", _("Copyright (C) 2003 - 2015 Michal Cihar <michal@cihar.com> and other authors.")); + printf("%s\n", _("Copyright (C) 2003 - 2016 Michal Cihar <michal@cihar.com> and other authors.")); printf("\n"); @@ -341,7 +341,7 @@ static void Version(int argc UNUSED, char *argv[]UNUSED) printf("\n"); - printf("%s\n", _("Check <http://wammu.eu/gammu/> for updates.")); + printf("%s\n", _("Check <https://wammu.eu/gammu/> for updates.")); printf("\n"); } @@ -509,7 +509,6 @@ static GSM_Parameters Parameters[] = { {"features", 0, 0, Features, {H_Gammu,0}, ""}, {"checkversion", 0, 1, CheckVersion, {H_Gammu,0}, "[STABLE]"}, {"getdisplaystatus", 0, 0, GetDisplayStatus, {H_Info,0}, ""}, - {"getlocation", 0, 0, GetLocation, {H_Info,0}, ""}, {"monitor", 0, 1, Monitor, {H_Info,H_Network,H_Call,0}, "[times]"}, {"battery", 0, 0, Battery, {H_Info,0}, ""}, {"setautonetworklogin", 0, 0, SetAutoNetworkLogin, {H_Network,0}, ""}, @@ -1241,7 +1240,7 @@ int main(int argc, char *argv[]) } /* Check used version vs. compiled */ - if (!strcasecmp(GetGammuVersion(), GAMMU_VERSION) == 0) { + if (strcasecmp(GetGammuVersion(), GAMMU_VERSION) != 0) { printf_err(_("Version of installed libGammu.so (%s) is different to version of Gammu (%s)\n"), GetGammuVersion(), GAMMU_VERSION); Terminate(98); diff --git a/gammu/message.c b/gammu/message.c index 11a157e..2c8e577 100644 --- a/gammu/message.c +++ b/gammu/message.c @@ -135,17 +135,18 @@ void GetUSSD(int argc UNUSED, char *argv[]) GSM_SetIncomingUSSDCallback(gsm, IncomingUSSD2, NULL); - error=GSM_SetIncomingUSSD(gsm,TRUE); + error = GSM_SetIncomingUSSD(gsm, TRUE); Print_Error(error); - error=GSM_DialService(gsm, argv[2]); + num_replies = 0; + + error = GSM_DialService(gsm, argv[2]); /* Fallback to voice call, it can work with some phones */ if (error == ERR_NOTIMPLEMENTED || error == ERR_NOTSUPPORTED) { - error=GSM_DialVoice(gsm, argv[2], GSM_CALL_DefaultNumberPresence); + error = GSM_DialVoice(gsm, argv[2], GSM_CALL_DefaultNumberPresence); } Print_Error(error); - num_replies = 0; last_replies = 0; last_reply = time(NULL); while (!gshutdown) { @@ -155,14 +156,15 @@ void GetUSSD(int argc UNUSED, char *argv[]) } else if (num_replies == 0 && difftime(time(NULL), last_reply) > 60) { /* Wait one minute for reply */ gshutdown = TRUE; - } else if (num_replies > 0 && difftime(time(NULL), last_reply) > 30) { - /* Wait for consequent replies for 30 seconds */ + } else if (num_replies > 0 && difftime(time(NULL), last_reply) > 10) { + /* Wait for consequent replies for 10 seconds */ gshutdown = TRUE; } + GSM_ReadDevice(gsm, FALSE); } - error=GSM_SetIncomingUSSD(gsm, FALSE); + error = GSM_SetIncomingUSSD(gsm, FALSE); Print_Error(error); GSM_Terminate(); @@ -553,11 +555,16 @@ void SendSMSStatus (GSM_StateMachine *sm, int status, int MessageReference, void void SendSaveDisplaySMS(int argc, char *argv[]) { GSM_Error error; - GSM_MultiSMSMessage sms; + GSM_MultiSMSMessage *sms; GSM_Message_Type type; GSM_SMSFolders folders; int i=0; + sms = malloc(sizeof(GSM_MultiSMSMessage)); + if (sms == NULL) { + return; + } + if (strcasestr(argv[1], "savesms") != NULL) { type = SMS_Save; } else if (strcasestr(argv[1], "sendsmsdsms") != NULL) { @@ -567,23 +574,24 @@ void SendSaveDisplaySMS(int argc, char *argv[]) } else if (strcasestr(argv[1], "displaysms") != NULL) { type = SMS_Display; } else { + free(sms); return; } GSM_Init(TRUE); - error = CreateMessage(&type, &sms, argc, 2, argv, gsm); + error = CreateMessage(&type, sms, argc, 2, argv, gsm); Print_Error(error); switch (type) { case SMS_Display: - for (i = 0; i < sms.Number; i++) { + for (i = 0; i < sms->Number; i++) { printf(LISTFORMAT "%i\n", _("Message number"), i); - error = DisplaySMSFrame(&sms.SMS[i], gsm); + error = DisplaySMSFrame(&(sms->SMS[i]), gsm); Print_Error(error); } - printf(LISTFORMAT "%i\n", _("Number of messages"), sms.Number); + printf(LISTFORMAT "%i\n", _("Number of messages"), sms->Number); break; case SMS_Save: case SMS_SendSaved: @@ -598,15 +606,15 @@ void SendSaveDisplaySMS(int argc, char *argv[]) fflush(stderr); } - for (i=0;i<sms.Number;i++) { - printf(_("Saving SMS %i/%i\n"),i+1,sms.Number); - error = GSM_AddSMS(gsm, &sms.SMS[i]); + for (i = 0; i < sms->Number; i++) { + printf(_("Saving SMS %i/%i\n"),i+1,sms->Number); + error = GSM_AddSMS(gsm, &(sms->SMS[i])); Print_Error(error); printf(_("Saved in folder number %d \"%s\", location %i"), - sms.SMS[i].Folder, - DecodeUnicodeConsole(folders.Folder[sms.SMS[i].Folder-1].Name), - sms.SMS[i].Location); - if (sms.SMS[i].Memory == MEM_SM) { + sms->SMS[i].Folder, + DecodeUnicodeConsole(folders.Folder[sms->SMS[i].Folder-1].Name), + sms->SMS[i].Location); + if (sms->SMS[i].Memory == MEM_SM) { printf(", %s\n", _("SIM")); } else { printf(", %s\n", _("phone")); @@ -614,10 +622,10 @@ void SendSaveDisplaySMS(int argc, char *argv[]) if (type == SMS_SendSaved) { printf(_("Sending sms from folder \"%s\", location %i\n"), - DecodeUnicodeString(folders.Folder[sms.SMS[i].Folder-1].Name),sms.SMS[i].Location); + DecodeUnicodeString(folders.Folder[sms->SMS[i].Folder-1].Name),sms->SMS[i].Location); fflush(stdout); SMSStatus = ERR_TIMEOUT; - error = GSM_SendSavedSMS(gsm, 0, sms.SMS[i].Location); + error = GSM_SendSavedSMS(gsm, 0, sms->SMS[i].Location); Print_Error(error); printf("%s", _("....waiting for network answer")); fflush(stdout); @@ -639,11 +647,11 @@ void SendSaveDisplaySMS(int argc, char *argv[]) GSM_SetSendSMSStatusCallback(gsm, SendSMSStatus, NULL); - for (i=0;i<sms.Number;i++) { - printf(_("Sending SMS %i/%i"),i+1,sms.Number); + for (i=0;i<sms->Number;i++) { + printf(_("Sending SMS %i/%i"),i+1,sms->Number); fflush(stdout); SMSStatus = ERR_TIMEOUT; - error=GSM_SendSMS(gsm, &sms.SMS[i]); + error=GSM_SendSMS(gsm, &(sms->SMS[i])); Print_Error(error); printf("%s", _("....waiting for network answer")); fflush(stdout); @@ -662,6 +670,7 @@ void SendSaveDisplaySMS(int argc, char *argv[]) printf_err("%s", _("Something went wrong, unknown message operation!\n")); } + free(sms); GSM_Terminate(); } diff --git a/gammu/misc.c b/gammu/misc.c index 1d1c58b..cbfe5c3 100644 --- a/gammu/misc.c +++ b/gammu/misc.c @@ -195,7 +195,7 @@ void PrintBatteryCharge(GSM_BatteryCharge *BatteryCharge) } } -GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone) +GSM_Error GSM_PlayRingtone(GSM_Ringtone *ringtone) { int i; gboolean first=TRUE; @@ -204,11 +204,11 @@ GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone) signal(SIGINT, interrupt); printf("%s\n", _("Press Ctrl+C to break...")); - for (i=0;i<ringtone.NoteTone.NrCommands;i++) { + for (i = 0; i < ringtone->NoteTone.NrCommands; i++) { if (gshutdown) break; - if (ringtone.NoteTone.Commands[i].Type != RING_Note) continue; - error=PHONE_RTTLPlayOneNote(gsm,ringtone.NoteTone.Commands[i].Note,first); - if (error!=ERR_NONE) return error; + if (ringtone->NoteTone.Commands[i].Type != RING_Note) continue; + error = PHONE_RTTLPlayOneNote(gsm, ringtone->NoteTone.Commands[i].Note, first); + if (error != ERR_NONE) return error; first = FALSE; } @@ -230,139 +230,12 @@ void PlayRingtone(int argc UNUSED, char *argv[]) GSM_Init(TRUE); - error=GSM_PlayRingtone(ringtone2); + error = GSM_PlayRingtone(&ringtone2); Print_Error(error); GSM_Terminate(); } -/** - * Get's location from OpenCellID. - */ -void GetLocation(int argc UNUSED, char *argv[]UNUSED) -{ - GSM_File OpenCell; - char url[70 + GSM_MAX_MODEL_LENGTH]; - char *pos; - GSM_Error error; - GSM_NetworkInfo netinfo; - float latitude, longitude; - long int mnc, mcc, lac, cellid, nbSamples, range; - char *ret, *old_locale = NULL; - gboolean failure = FALSE; - - GSM_Init(TRUE); - - /* Get model information */ - error = GSM_GetNetworkInfo(gsm, &netinfo); - Print_Error(error); - - if (netinfo.State == GSM_NoNetwork) { - printf_err("%s", _("Not logged to network!\n")); - GSM_Terminate(); - return; - } - - /* We need decimal numbers */ - lac = strtol(netinfo.LAC, NULL, 16); - cellid = strtol(netinfo.CID, NULL, 16); - - /* Split code to country and network (beware ncc+nmc without space) */ - if (sscanf(netinfo.NetworkCode, "%3ld%ld", &mcc, &mnc) != 2) { - printf_err("%s", _("Wrong network code from phone!\n")); - GSM_Terminate(); - return; - } - - /* Request information from OpenCellID */ - sprintf(url, "http://www.opencellid.org/cell/get?key=%s&mnc=%ld&mcc=%ld&lac=%ld&cellid=%ld", - OPENCELLID_API_KEY, - mnc, mcc, lac, cellid); - - OpenCell.Buffer = NULL; - OpenCell.Used = 0; - error = GSM_ReadHTTPFile(url, &OpenCell); - Print_Error(error); - - /* We need to reset numeric locales because we parse floats with . as decimal separator */ - ret = setlocale(LC_NUMERIC, "C"); - if (ret != NULL) { - old_locale = strdup(ret); - } - - /* Parse reply: - <?xml version="1.0" encoding="UTF-8"?> - <rsp stat="ok"> - <cell range="6000" lac="0" lat="54.4910893937777" nbSamples="46" lon="27.9390742994699" cellId="29513" mcc="250" mnc="99"/> - </rsp> - */ - if (strstr(OpenCell.Buffer, "stat=\"ok\"") == NULL) { - printf_err("%s", _("Request for information from OpenCellID failed!\n")); - failure = TRUE; - goto done; - } - pos = strstr(OpenCell.Buffer, "lat=\""); - if (pos == NULL) { - printf_err("%s", _("Failed to find latitude in OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - if (sscanf(pos, "lat=\"%f\"", &latitude) == 0) { - printf_err("%s", _("Failed to parse latitude from OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - pos = strstr(OpenCell.Buffer, "lon=\""); - if (pos == NULL) { - printf_err("%s", _("Failed to find longitude in OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - if (sscanf(pos, "lon=\"%f\"", &longitude) == 0) { - printf_err("%s", _("Failed to parse longitude from OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - pos = strstr(OpenCell.Buffer, "range=\""); - if (pos == NULL) { - printf_err("%s", _("Failed to find range in OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - if (sscanf(pos, "range=\"%ld\"", &range) == 0) { - printf_err("%s", _("Failed to parse range from OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - pos = strstr(OpenCell.Buffer, "nbSamples=\""); - if (pos == NULL) { - printf_err("%s", _("Failed to find nbSamples in OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - if (sscanf(pos, "nbSamples=\"%ld\"", &nbSamples) == 0) { - printf_err("%s", _("Failed to parse nbSamples from OpenCellID reply!\n")); - failure = TRUE; - goto done; - } - -done: - if (old_locale != NULL) { - setlocale(LC_NUMERIC, old_locale); - free(old_locale); - } - if (!failure) { - printf(LISTFORMAT "%f\n", _("Latitude"), latitude); - printf(LISTFORMAT "%f\n", _("Longitude"), longitude); - printf(LISTFORMAT "%ld\n", _("Range"), range); - printf(LISTFORMAT "%ld\n", _("Number of samples"), nbSamples); - } - - free(OpenCell.Buffer); - GSM_Terminate(); -} - - void Identify(int argc, char *argv[]) { @@ -1033,7 +906,8 @@ void GetBitmap(int argc, char *argv[]) { GSM_File File; GSM_MultiBitmap MultiBitmap; - int location=0, Handle, Size; + int location=0, Handle; + size_t Size; GSM_AllRingtonesInfo Info = {0, NULL}; unsigned char buffer[10]; const unsigned char *ringtonename; diff --git a/gammu/misc.h b/gammu/misc.h index baf5651..15a00d3 100644 --- a/gammu/misc.h +++ b/gammu/misc.h @@ -47,7 +47,7 @@ extern void SetAutoNetworkLogin(int argc, char *argv[]); extern void GetFMStation(int argc, char *argv[]); extern void CallDivert(int argc, char *argv[]); extern void CancelAllDiverts(int argc, char *argv[]); -extern GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone); +extern GSM_Error GSM_PlayRingtone(GSM_Ringtone *ringtone); extern void Battery(int argc, char *argv[]); extern void Screenshot(int argc, char *argv[]); extern void Install(int argc, char *argv[]); diff --git a/gammu/mms.c b/gammu/mms.c index e6a3cee..83d9301 100644 --- a/gammu/mms.c +++ b/gammu/mms.c @@ -149,7 +149,8 @@ void GetEachMMS(int argc, char *argv[]) GSM_File File; gboolean start = TRUE; GSM_MMSFolders folders; - int Handle,Size,num = -1; + int Handle,num = -1; + size_t Size; GSM_Error error; if (argc>2 && strcasecmp(argv[2],"-save") == 0) num=0; diff --git a/gammu/nokia.c b/gammu/nokia.c index 62c3af1..4a099da 100644 --- a/gammu/nokia.c +++ b/gammu/nokia.c @@ -263,7 +263,7 @@ void NokiaAddPlayLists2(unsigned char *ID,unsigned char *Name,unsigned char *IDF break; } if (error == ERR_FILENOTEXIST) { - return; + goto out; } Print_Error(error); @@ -412,6 +412,8 @@ void NokiaAddPlayLists2(unsigned char *ID,unsigned char *Name,unsigned char *IDF j+=UnicodeLength(Names2+j)*2+2; } } + +out: free(Names); free(Names2); } @@ -437,7 +439,7 @@ void NokiaAddPlayLists(int argc UNUSED, char *argv[] UNUSED) Print_Error(error); } if (error == ERR_FILENOTEXIST) { - printf("%s\n", _("Your phone model is not supported. Please report it to authors (see <http://wammu.eu/support/bugs/>). Thank you.")); + printf("%s\n", _("Your phone model is not supported. Please report it to authors (see <https://wammu.eu/support/bugs/>). Thank you.")); GSM_Terminate(); Terminate(2); } else if (error != ERR_EMPTY) { |