summaryrefslogtreecommitdiff
path: root/libgammu
diff options
context:
space:
mode:
Diffstat (limited to 'libgammu')
-rw-r--r--libgammu/CMakeLists.txt7
-rw-r--r--libgammu/api.c6
-rw-r--r--libgammu/debug.c6
-rw-r--r--libgammu/debug.h4
-rw-r--r--libgammu/device/irda/irda.h4
-rw-r--r--libgammu/gsmcomon.c6
-rw-r--r--libgammu/gsmphones.c4
-rw-r--r--libgammu/gsmreply.h1
-rw-r--r--libgammu/gsmstate.c32
-rw-r--r--libgammu/gsmstate.h22
-rw-r--r--libgammu/misc/coding/coding.c74
-rw-r--r--libgammu/misc/coding/coding.h20
-rw-r--r--libgammu/misc/misc.c16
-rw-r--r--libgammu/misc/misc.h6
-rw-r--r--libgammu/phone/alcatel/alcatel.c10
-rw-r--r--libgammu/phone/at/at-sms.c27
-rw-r--r--libgammu/phone/at/atgen.c33
-rw-r--r--libgammu/phone/atobex/atobex.c7
-rw-r--r--libgammu/phone/dummy/dummy.c77
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/6510file.c24
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/6510file.h4
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/n6510.c49
-rw-r--r--libgammu/phone/nokia/wd2/n3650.c2
-rw-r--r--libgammu/phone/obex/mobex.c3
-rw-r--r--libgammu/phone/obex/obexfunc.h6
-rw-r--r--libgammu/phone/obex/obexgen.c19
-rw-r--r--libgammu/phone/pfunc.c3
-rw-r--r--libgammu/protocol/at/at.c146
-rw-r--r--libgammu/protocol/at/at.h7
-rw-r--r--libgammu/service/backup/backtext.c62
-rw-r--r--libgammu/service/gsmdata.c2
-rw-r--r--libgammu/service/sms/gsmmulti.c20
32 files changed, 415 insertions, 294 deletions
diff --git a/libgammu/CMakeLists.txt b/libgammu/CMakeLists.txt
index 9b7d6e8..aa3c798 100644
--- a/libgammu/CMakeLists.txt
+++ b/libgammu/CMakeLists.txt
@@ -4,6 +4,8 @@
project (libGammu C)
+include(GammuTuneFlags)
+
set (LIBRARY_SRC
gsmcomon.c
gsmphones.c
@@ -113,13 +115,12 @@ if(MSVC)
else(MSVC)
add_library (libGammu ${LIBRARY_SRC})
endif(MSVC)
+add_coverage (libGammu)
set_target_properties (libGammu PROPERTIES
VERSION ${GAMMU_SOVERSION}.${GAMMU_VERSION}
SOVERSION ${GAMMU_SOVERSION}
OUTPUT_NAME Gammu)
-if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_MINGW AND NOT CMAKE_COMPILER_IS_CYGWIN)
- set_target_properties (libGammu PROPERTIES COMPILE_FLAGS -fPIC)
-endif (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_MINGW AND NOT CMAKE_COMPILER_IS_CYGWIN)
+GAMMU_TUNE_SHARED(libGammu)
if(CMAKE_COMPILER_IS_MINGW AND BUILD_SHARED_LIBS)
SET_TARGET_PROPERTIES(libGammu PROPERTIES LINK_FLAGS
"-Wl,--output-def,${CMAKE_CURRENT_BINARY_DIR}/libGammu.def")
diff --git a/libgammu/api.c b/libgammu/api.c
index 6b501fd..3ae8dbb 100644
--- a/libgammu/api.c
+++ b/libgammu/api.c
@@ -1742,7 +1742,7 @@ GSM_Error GSM_SetFileAttributes(GSM_StateMachine *s, GSM_File *File)
/**
* Retrieves file part.
*/
-GSM_Error GSM_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size)
+GSM_Error GSM_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
{
GSM_Error err;
@@ -1755,7 +1755,7 @@ GSM_Error GSM_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, int
/**
* Adds file part to filesystem.
*/
-GSM_Error GSM_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error GSM_AddFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_Error err;
@@ -1768,7 +1768,7 @@ GSM_Error GSM_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Ha
/**
* Sends file to phone, it's up to phone to decide what to do with it.
*/
-GSM_Error GSM_SendFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error GSM_SendFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_Error err;
diff --git a/libgammu/debug.c b/libgammu/debug.c
index 40d270f..e3cd444 100644
--- a/libgammu/debug.c
+++ b/libgammu/debug.c
@@ -311,9 +311,9 @@ int smprintf_level(GSM_StateMachine * s, GSM_DebugSeverity severity, const char
#define CHARS_PER_LINE (16)
/* Dumps a message */
-void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const int messagesize)
+void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
{
- int i, j = 0;
+ size_t i, j = 0;
char buffer[(CHARS_PER_LINE * 5) + 1];
smfprintf(d, "\n");
@@ -368,7 +368,7 @@ void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const int mess
#undef CHARS_PER_LINE
-void DumpMessageText(GSM_Debug_Info *d, const unsigned char *message, const int messagesize)
+void DumpMessageText(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
{
if (d == NULL || (d->dl != DL_TEXTALL && d->dl == DL_TEXTALLDATE)) return;
DumpMessage(d, message, messagesize);
diff --git a/libgammu/debug.h b/libgammu/debug.h
index 0abe681..9bc1ca6 100644
--- a/libgammu/debug.h
+++ b/libgammu/debug.h
@@ -10,8 +10,8 @@
extern GSM_Debug_Info GSM_global_debug;
extern GSM_Debug_Info GSM_none_debug;
-void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const int messagesize);
-void DumpMessageText(GSM_Debug_Info *d, const unsigned char *message, const int messagesize);
+void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize);
+void DumpMessageText(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize);
/* ------------------------------------------------------------------------- */
diff --git a/libgammu/device/irda/irda.h b/libgammu/device/irda/irda.h
index 455e6af..953aa84 100644
--- a/libgammu/device/irda/irda.h
+++ b/libgammu/device/irda/irda.h
@@ -10,7 +10,11 @@
#endif
typedef struct {
+#ifdef WIN32
+ SOCKET hPhone;
+#else
int hPhone;
+#endif
struct sockaddr_irda peer;
} GSM_Device_IrdaData;
diff --git a/libgammu/gsmcomon.c b/libgammu/gsmcomon.c
index 9fed2fa..b3c9798 100644
--- a/libgammu/gsmcomon.c
+++ b/libgammu/gsmcomon.c
@@ -95,9 +95,9 @@ static PrintErrorEntry PrintErrorEntries[] = {
{ERR_DEVICEREADERROR, "DEVICEREADERROR", N_("Error during reading from the device.")},
{ERR_DEVICEPARITYERROR, "DEVICEPARITYERROR", N_("Can't set parity on the device.")},
{ERR_TIMEOUT, "TIMEOUT", N_("No response in specified timeout. Probably phone not connected.")},
- {ERR_FRAMENOTREQUESTED, "FRAMENOTREQUESTED", N_("Frame not requested right now. See <http://wammu.eu/support/bugs/> for information how to report it.")},
- {ERR_UNKNOWNRESPONSE, "UNKNOWNRESPONSE", N_("Unknown response from phone. See <http://wammu.eu/support/bugs/> for information how to report it.")},
- {ERR_UNKNOWNFRAME, "UNKNOWNFRAME", N_("Unknown frame. See <http://wammu.eu/support/bugs/> for information how to report it.")},
+ {ERR_FRAMENOTREQUESTED, "FRAMENOTREQUESTED", N_("Frame not requested right now. See <https://wammu.eu/support/bugs/> for information how to report it.")},
+ {ERR_UNKNOWNRESPONSE, "UNKNOWNRESPONSE", N_("Unknown response from phone. See <https://wammu.eu/support/bugs/> for information how to report it.")},
+ {ERR_UNKNOWNFRAME, "UNKNOWNFRAME", N_("Unknown frame. See <https://wammu.eu/support/bugs/> for information how to report it.")},
{ERR_UNKNOWNCONNECTIONTYPESTRING, "UNKNOWNCONNECTIONTYPESTRING",N_("Unknown connection type string. Check config file.")},
{ERR_UNKNOWNMODELSTRING, "UNKNOWNMODELSTRING", N_("Unknown model type string. Check config file.")},
{ERR_SOURCENOTAVAILABLE, "SOURCENOTAVAILABLE", N_("Some functions not available for your system (disabled in config or not implemented).")},
diff --git a/libgammu/gsmphones.c b/libgammu/gsmphones.c
index ce0fd98..6f0c2b8 100644
--- a/libgammu/gsmphones.c
+++ b/libgammu/gsmphones.c
@@ -966,6 +966,7 @@ GSM_PhoneModel allmodels[] = {
{"E398", "E398", "", {F_SMS_LOCATION_0, F_ENCODED_USSD, F_FOUR_DIGIT_YEAR, F_RESET_AFTER_TIMEOUT, F_HUAWEI_INIT, 0}},
{"E3131", "E3131", "", {F_SMS_LOCATION_0, F_ENCODED_USSD, F_FOUR_DIGIT_YEAR, F_RESET_AFTER_TIMEOUT, F_HUAWEI_INIT, 0}},
{"K3765", "K3765", "", {F_SMS_LOCATION_0, F_ENCODED_USSD, F_FOUR_DIGIT_YEAR, F_RESET_AFTER_TIMEOUT, F_HUAWEI_INIT, 0}},
+ {"K3770", "K3770", "", {F_SMS_LOCATION_0, F_ENCODED_USSD, F_FOUR_DIGIT_YEAR, F_RESET_AFTER_TIMEOUT, F_HUAWEI_INIT, 0}},
{"K4505", "K4505", "", {F_SMS_LOCATION_0, F_ENCODED_USSD, F_FOUR_DIGIT_YEAR, F_RESET_AFTER_TIMEOUT, F_HUAWEI_INIT, 0}},
{"K4511", "K4511", "", {F_SMS_LOCATION_0, F_ENCODED_USSD, F_FOUR_DIGIT_YEAR, F_RESET_AFTER_TIMEOUT, F_HUAWEI_INIT, 0}},
@@ -975,6 +976,9 @@ GSM_PhoneModel allmodels[] = {
/* Ubinetics */
{"GDC201", "GDC201", "", {F_SMS_NO_ME, 0}},
+ /* Dell */
+ {"DW5560", "DW5560", "", {0}},
+
/* Other */
{"SIMCOM_SIM300D","SIMCOM_SIM300D","", {F_ENCODED_USSD, 0}},
diff --git a/libgammu/gsmreply.h b/libgammu/gsmreply.h
index d92df45..0c8bc20 100644
--- a/libgammu/gsmreply.h
+++ b/libgammu/gsmreply.h
@@ -210,6 +210,7 @@ typedef enum {
ID_User9,
ID_User10,
+ ID_All,
ID_EachFrame
} GSM_Phone_RequestID;
diff --git a/libgammu/gsmstate.c b/libgammu/gsmstate.c
index d876ee3..9761f68 100644
--- a/libgammu/gsmstate.c
+++ b/libgammu/gsmstate.c
@@ -462,7 +462,7 @@ GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
s->ConnectionType == GCT_BLUEPHONET) {
/* Try to detect phone type */
if (strcmp(model->model, "unknown") == 0 && model->features[0] == 0) {
- smprintf(s, "WARNING: phone not known, please report it to authors (see <http://wammu.eu/support/bugs/>). Thank you.\n");
+ smprintf(s, "WARNING: phone not known, please report it to authors (see <https://wammu.eu/support/bugs/>). Thank you.\n");
if (strncmp(s->Phone.Data.Model, "RM-", 3) == 0) {
/* 167 is really a wild guess */
if (atoi(s->Phone.Data.Model + 3) > 167) {
@@ -984,7 +984,7 @@ GSM_Error GSM_AbortOperation(GSM_StateMachine * s)
}
GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned const char *buffer,
- int length, int type, int timeout)
+ size_t length, int type, int timeout)
{
GSM_Phone_Data *Phone = &s->Phone.Data;
GSM_Protocol_Message sentmsg;
@@ -1027,7 +1027,7 @@ GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned const char *buffer,
}
GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned const char *buffer,
- int length, int type, int timeout,
+ size_t length, int type, int timeout,
GSM_Phone_RequestID request)
{
GSM_Phone_Data *Phone = &s->Phone.Data;
@@ -1137,6 +1137,8 @@ GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
GSM_Reply_Function *Reply;
int reply;
+ s->MessagesCount++;
+
GSM_DumpMessageTextRecv(s, msg->Buffer, msg->Length, msg->Type);
GSM_DumpMessageBinaryRecv(s, msg->Buffer, msg->Length, msg->Type);
@@ -1183,7 +1185,7 @@ GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
}
if (disp) {
- smprintf(s,". Please report the error, see <http://wammu.eu/support/bugs/>. Thank you\n");
+ smprintf(s,". Please report the error, see <https://wammu.eu/support/bugs/>. Thank you\n");
if (Phone->SentMsg != NULL) {
smprintf(s,"LAST SENT frame ");
smprintf(s, "type 0x%02X/length %ld", Phone->SentMsg->Type, (long)Phone->SentMsg->Length);
@@ -1533,7 +1535,7 @@ fail:
return error;
}
-void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *message, int messagesize, int type, const char *text)
+void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, const char *text)
{
GSM_Debug_Info *curdi;
@@ -1544,25 +1546,25 @@ void GSM_DumpMessageText_Custom(GSM_StateMachine *s, unsigned const char *messag
curdi->dl == DL_TEXTDATE ||
curdi->dl == DL_TEXTALLDATE) {
smprintf(s, "%s ", text);
- smprintf(s, "type 0x%02X/length 0x%02X/%i",
- type, messagesize, messagesize);
+ smprintf(s, "type 0x%02X/length 0x%02lX/%ld",
+ type, (long)messagesize, (long)messagesize);
DumpMessage(curdi, message, messagesize);
}
}
-void GSM_DumpMessageText(GSM_StateMachine *s, unsigned const char *message, int messagesize, int type)
+void GSM_DumpMessageText(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
{
GSM_DumpMessageText_Custom(s, message, messagesize, type, "SENDING frame");
}
-void GSM_DumpMessageTextRecv(GSM_StateMachine *s, unsigned const char *message, int messagesize, int type)
+void GSM_DumpMessageTextRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
{
GSM_DumpMessageText_Custom(s, message, messagesize, type, "RECEIVED frame");
}
-void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *message, int messagesize, int type, int direction)
+void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type, int direction)
{
- int i=0;
+ size_t i=0;
GSM_Debug_Info *curdi;
curdi = GSM_GetDI(s);
@@ -1570,20 +1572,20 @@ void GSM_DumpMessageBinary_Custom(GSM_StateMachine *s, unsigned const char *mess
if (curdi->dl == DL_BINARY) {
smprintf(s,"%c", direction);
smprintf(s,"%c",type);
- smprintf(s,"%c",messagesize/256);
- smprintf(s,"%c",messagesize%256);
+ smprintf(s,"%c",(int)(messagesize/256));
+ smprintf(s,"%c",(int)(messagesize%256));
for (i=0;i<messagesize;i++) {
smprintf(s,"%c",message[i]);
}
}
}
-void GSM_DumpMessageBinary(GSM_StateMachine *s, unsigned const char *message, int messagesize, int type)
+void GSM_DumpMessageBinary(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
{
GSM_DumpMessageBinary_Custom(s, message, messagesize, type, 0x01);
}
-void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, int messagesize, int type)
+void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type)
{
GSM_DumpMessageBinary_Custom(s, message, messagesize, type, 0x02);
}
diff --git a/libgammu/gsmstate.h b/libgammu/gsmstate.h
index 6a3e027..2d665ea 100644
--- a/libgammu/gsmstate.h
+++ b/libgammu/gsmstate.h
@@ -1266,15 +1266,15 @@ typedef struct {
/**
* Retrieves file part.
*/
- GSM_Error (*GetFilePart) (GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size);
+ GSM_Error (*GetFilePart) (GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size);
/**
* Adds file part to filesystem.
*/
- GSM_Error (*AddFilePart) (GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle);
+ GSM_Error (*AddFilePart) (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle);
/**
* Sends file to phone, it's up to phone to decide what to do with it.
*/
- GSM_Error (*SendFilePart) (GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle);
+ GSM_Error (*SendFilePart) (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle);
/**
* Acquires filesystem status.
*/
@@ -1417,6 +1417,10 @@ struct _GSM_StateMachine {
* Flag for interrupting communication.
*/
volatile gboolean Abort;
+ /**
+ * Counter for dispatched messages.
+ */
+ volatile size_t MessagesCount;
GSM_Device Device; /**< Device driver data and functions */
GSM_Protocol Protocol; /**< Protocol driver data and functions */
@@ -1436,7 +1440,7 @@ struct _GSM_StateMachine {
GSM_Error GSM_RegisterAllPhoneModules (GSM_StateMachine *s);
GSM_Error GSM_WaitForOnce (GSM_StateMachine *s, unsigned const char *buffer,
- int length, int type, int timeout);
+ size_t length, int type, int timeout);
/**
* Wait for reply from the phone.
@@ -1451,7 +1455,7 @@ GSM_Error GSM_WaitForOnce (GSM_StateMachine *s, unsigned const char *buffer,
* \return Error code, ERR_NONE on sucecss.
*/
GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned const char *buffer,
- int length, int type, int timeout,
+ size_t length, int type, int timeout,
GSM_Phone_RequestID request) WARNUNUSED;
/**
@@ -1472,10 +1476,10 @@ GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned const char *buffer,
GSM_Error GSM_DispatchMessage (GSM_StateMachine *s);
-void GSM_DumpMessageText (GSM_StateMachine *s, unsigned const char *message, int messagesize, int type);
-void GSM_DumpMessageTextRecv (GSM_StateMachine *s, unsigned const char *message, int messagesize, int type);
-void GSM_DumpMessageBinary (GSM_StateMachine *s, unsigned const char *message, int messagesize, int type);
-void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, int messagesize, int type);
+void GSM_DumpMessageText (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type);
+void GSM_DumpMessageTextRecv (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type);
+void GSM_DumpMessageBinary (GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type);
+void GSM_DumpMessageBinaryRecv(GSM_StateMachine *s, unsigned const char *message, size_t messagesize, int type);
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description);
diff --git a/libgammu/misc/coding/coding.c b/libgammu/misc/coding/coding.c
index e1b3a25..28f9f2e 100644
--- a/libgammu/misc/coding/coding.c
+++ b/libgammu/misc/coding/coding.c
@@ -279,9 +279,9 @@ char *DecodeUnicodeConsole(const unsigned char *src)
}
/* Encode string to Unicode. Len is number of input chars */
-void DecodeISO88591 (unsigned char *dest, const char *src, int len)
+void DecodeISO88591 (unsigned char *dest, const char *src, size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < len; i++) {
/* Hack for Euro sign */
@@ -298,9 +298,9 @@ void DecodeISO88591 (unsigned char *dest, const char *src, int len)
}
/* Encode string to Unicode. Len is number of input chars */
-void EncodeUnicode (unsigned char *dest, const char *src, int len)
+void EncodeUnicode (unsigned char *dest, const char *src, size_t len)
{
- int i_len = 0, o_len;
+ size_t i_len = 0, o_len;
wchar_t wc;
for (o_len = 0; i_len < len; o_len++) {
@@ -325,9 +325,10 @@ int DecodeWithBCDAlphabet(unsigned char value)
return 10*(value & 0x0f)+(value >> 4);
}
-void DecodeBCD (unsigned char *dest, const unsigned char *src, int len)
+void DecodeBCD (unsigned char *dest, const unsigned char *src, size_t len)
{
- int i,current=0,digit;
+ size_t i,current=0;
+ int digit;
for (i = 0; i < len; i++) {
digit=src[i] & 0x0f;
@@ -338,9 +339,9 @@ void DecodeBCD (unsigned char *dest, const unsigned char *src, int len)
dest[current]=0;
}
-void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, gboolean fill)
+void EncodeBCD (unsigned char *dest, const unsigned char *src, size_t len, gboolean fill)
{
- int i,current=0;
+ size_t i,current=0;
for (i = 0; i < len; i++) {
if (i & 0x01) {
@@ -407,9 +408,10 @@ void EncodeHexUnicode (char *dest, const unsigned char *src, size_t len)
EncodeHexBin(dest, src, len * 2);
}
-gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, int len)
+gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, size_t len)
{
- int i,current=0, low, high;
+ size_t i,current=0;
+ int low, high;
for (i = 0; i < len/2 ; i++) {
low = DecodeWithHexBinAlphabet(src[i*2+1]);
@@ -828,7 +830,8 @@ static unsigned char ConvertTable[] =
void EncodeDefault(unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
{
- size_t i,current=0,j,z;
+ size_t i,current=0;
+ int j,z;
char ret;
gboolean FoundSpecial,FoundNormal;
@@ -947,7 +950,7 @@ void FindDefaultAlphabetLen(const unsigned char *src, size_t *srclen, size_t *sm
#define ByteMask ((1 << Bits) - 1)
-int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
+int GSM_UnpackEightBitsToSeven(size_t offset, size_t in_length, size_t out_length,
const unsigned char *input, unsigned char *output)
{
/* (c) by Pavel Janik and Pawel Kot */
@@ -955,11 +958,11 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
unsigned char *output_pos = output; /* Current pointer to the output buffer */
const unsigned char *input_pos = input; /* Current pointer to the input buffer */
unsigned char Rest = 0x00;
- int Bits;
+ size_t Bits;
Bits = offset ? offset : 7;
- while ((input_pos - input) < in_length) {
+ while ((size_t)(input_pos - input) < in_length) {
*output_pos = ((*input_pos & ByteMask) << (7 - Bits)) | Rest;
Rest = *input_pos >> Bits;
@@ -970,7 +973,7 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
if ((input_pos != input) || (Bits == 7)) output_pos++;
input_pos++;
- if ((output_pos - output) >= out_length) break;
+ if ((size_t)(output_pos - output) >= out_length) break;
/* After reading 7 octets we have read 7 full characters but
we have 7 bits as well. This is the next character */
@@ -987,7 +990,7 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
return output_pos - output;
}
-int GSM_PackSevenBitsToEight(int offset, const unsigned char *input, unsigned char *output, int length)
+int GSM_PackSevenBitsToEight(size_t offset, const unsigned char *input, unsigned char *output, size_t length)
{
/* (c) by Pavel Janik and Pawel Kot */
@@ -1004,7 +1007,7 @@ int GSM_PackSevenBitsToEight(int offset, const unsigned char *input, unsigned ch
output_pos++;
}
- while ((input_pos - input) < length) {
+ while ((size_t)(input_pos - input) < length) {
unsigned char Byte = *input_pos;
*output_pos = Byte >> (7 - Bits);
@@ -1242,12 +1245,12 @@ void ReadUnicodeFile(unsigned char *Dest, const unsigned char *Source)
Dest[current] = 0;
}
-INLINE int GetBit(unsigned char *Buffer, size_t BitNum)
+int GetBit(unsigned char *Buffer, size_t BitNum)
{
return Buffer[BitNum / 8] & (1 << (7 - (BitNum % 8)));
}
-INLINE int SetBit(unsigned char *Buffer, size_t BitNum)
+int SetBit(unsigned char *Buffer, size_t BitNum)
{
return Buffer[BitNum / 8] |= 1 << (7 - (BitNum % 8));
}
@@ -1361,9 +1364,9 @@ void GetBufferI(unsigned char *Source,
* We replace single ~ chars into it. When user give double ~, it's replaced
* to single ~
*/
-void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len)
+void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i,current = 0;
+ size_t i,current = 0;
gboolean special=FALSE;
for (i = 0; i < len; i++) {
@@ -1395,9 +1398,9 @@ void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *sr
dest[current] = 0x00;
}
-void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len)
+void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i=0,current=0;
+ size_t i=0,current=0;
for (i=0;i<len;i++) {
switch (src[2*i]) {
@@ -1860,7 +1863,7 @@ gboolean EncodeUTF8(char *dest, const unsigned char *src)
}
/* Decode UTF8 char to Unicode char */
-int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, int len)
+int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, size_t len)
{
if (len < 1) return 0;
if (src[0] < 128) {
@@ -1883,9 +1886,9 @@ int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, int len)
/* Make Unicode string from ISO-8859-1 string */
-void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, int len)
+void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i = 0, j = 0;
+ size_t i = 0, j = 0;
while (i < len) {
if (src[i] == '=' && i + 2 < len
@@ -1905,9 +1908,10 @@ void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src
}
/* Make Unicode string from UTF8 string */
-void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, int len)
+void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, size_t len)
{
- int i,j=0,z;
+ size_t i,j=0;
+ int z;
unsigned char mychar[10];
wchar_t ret;
@@ -1940,9 +1944,9 @@ void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, int len)
dest[j] = 0;
}
-void DecodeUTF8(unsigned char *dest, const char *src, int len)
+void DecodeUTF8(unsigned char *dest, const char *src, size_t len)
{
- int i=0,j=0,z;
+ size_t i=0,j=0,z;
wchar_t ret;
while (i < len) {
@@ -1959,13 +1963,13 @@ void DecodeUTF8(unsigned char *dest, const char *src, int len)
dest[j] = 0;
}
-void DecodeXMLUTF8(unsigned char *dest, const char *src, int len)
+void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len)
{
char *tmp;
char *pos, *pos_end;
const char *lastpos;
char *entity;
- unsigned long int c;
+ unsigned long long int c;
int tmplen;
/* Allocate buffer */
@@ -2015,7 +2019,7 @@ void DecodeXMLUTF8(unsigned char *dest, const char *src, int len)
} else {
c = strtoull(entity + 1, NULL, 10);
}
- dbgprintf(NULL, "Unicode char 0x%04lx\n", c);
+ dbgprintf(NULL, "Unicode char 0x%04llx\n", c);
tmplen = strlen(tmp);
tmplen += EncodeWithUTF8Alphabet(c, tmp + tmplen);
tmp[tmplen] = 0;
@@ -2044,9 +2048,9 @@ void DecodeXMLUTF8(unsigned char *dest, const char *src, int len)
tmp=NULL;
}
-void DecodeUTF7(unsigned char *dest, const unsigned char *src, int len)
+void DecodeUTF7(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i=0,j=0,z,p;
+ size_t i=0,j=0,z,p;
wchar_t ret;
while (i<=len) {
diff --git a/libgammu/misc/coding/coding.h b/libgammu/misc/coding/coding.h
index 69de058..0800a1c 100644
--- a/libgammu/misc/coding/coding.h
+++ b/libgammu/misc/coding/coding.h
@@ -33,8 +33,8 @@ gboolean myiswspace (unsigned const char *src);
void ReverseUnicodeString (unsigned char *String);
-void DecodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, int len);
-void EncodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, int len);
+void DecodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len);
+void EncodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len);
unsigned char *EncodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer);
unsigned char *DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer);
@@ -43,21 +43,21 @@ unsigned char *DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned cha
unsigned char EncodeWithBCDAlphabet (int value);
int DecodeWithBCDAlphabet (unsigned char value);
-void DecodeBCD (unsigned char *dest, const unsigned char *src, int len);
-void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, gboolean fill);
+void DecodeBCD (unsigned char *dest, const unsigned char *src, size_t len);
+void EncodeBCD (unsigned char *dest, const unsigned char *src, size_t len, gboolean fill);
/* ------------------------------ UTF7 ------------------------------------- */
-void DecodeUTF7 (unsigned char *dest, const unsigned char *src, int len);
+void DecodeUTF7 (unsigned char *dest, const unsigned char *src, size_t len);
/* ---------------------------- ISO88591 ----------------------------------- */
-void DecodeISO88591 (unsigned char *dest, const char *src, int len);
-void DecodeISO88591QuotedPrintable (unsigned char *dest, const unsigned char *src, int len);
+void DecodeISO88591 (unsigned char *dest, const char *src, size_t len);
+void DecodeISO88591QuotedPrintable (unsigned char *dest, const unsigned char *src, size_t len);
/**
* Decodes UTF-8 text with XML entities to Unicode.
*/
-void DecodeXMLUTF8(unsigned char *dest, const char *src, int len);
+void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len);
/* ------------------------------- BASE64 ---------------------------------- */
void EncodeBASE64 (const unsigned char *Input, char *Output, const size_t Length);
@@ -68,8 +68,8 @@ void EncodeDefault (unsigned char *dest, const unsigned char *src, size_t *l
void DecodeDefault (unsigned char *dest, const unsigned char *src, size_t len, gboolean UseExtensions, unsigned char *ExtraAlphabet);
void FindDefaultAlphabetLen (const unsigned char *src, size_t *srclen, size_t *smslen, size_t maxlen);
-int GSM_PackSevenBitsToEight (int offset, const unsigned char *input, unsigned char *output, int length);
-int GSM_UnpackEightBitsToSeven (int offset, int in_length, int out_length,
+int GSM_PackSevenBitsToEight (size_t offset, const unsigned char *input, unsigned char *output, size_t length);
+int GSM_UnpackEightBitsToSeven (size_t offset, size_t in_length, size_t out_length,
const unsigned char *input, unsigned char *output);
/* ----------------- Phone numbers according to GSM specs ------------------ */
diff --git a/libgammu/misc/misc.c b/libgammu/misc/misc.c
index 8866d3a..ced397b 100644
--- a/libgammu/misc/misc.c
+++ b/libgammu/misc/misc.c
@@ -149,7 +149,7 @@ int GSM_GetLocalTimezoneOffset() {
gmtime_r(&now, &tg);
localtime_r(&now, &tl);
// Returns offset including daylight saving (found as boolean in tl.tm_isdst).
- return mktime(&tl) - mktime(&tg);
+ return (int)(mktime(&tl) - mktime(&tg));
}
void GSM_DateTimeToTimestamp(GSM_DateTime *Date, char *str)
@@ -367,7 +367,7 @@ gboolean CheckTime(GSM_DateTime *date)
date->Second <= 59;
}
-int GetLine(FILE *File, char *Line, int count)
+size_t GetLine(FILE *File, char *Line, int count)
{
int num;
@@ -398,12 +398,12 @@ void FreeLines(GSM_CutLines *lines)
lines->retval = NULL;
}
-void SplitLines(const char *message, const int messagesize, GSM_CutLines *lines,
- const char *whitespaces, const int spaceslen,
- const char *quotes, const int quoteslen,
+void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines,
+ const char *whitespaces, const size_t spaceslen,
+ const char *quotes, const size_t quoteslen,
const gboolean eot)
{
- int i=0,number=0,j=0, lastquote = -1;
+ size_t i=0,number=0,j=0, lastquote = 0;
gboolean whitespace = TRUE, nowwhite = FALSE, insidequotes = FALSE;
/* Clean current lines */
@@ -414,9 +414,9 @@ void SplitLines(const char *message, const int messagesize, GSM_CutLines *lines,
/* Go through message */
for (i = 0; i < messagesize; i++) {
/* Reallocate buffer if needed */
- if (number + 1 >= lines->allocated - 1) {
+ if (number + 2 >= lines->allocated) {
lines->allocated += 20;
- lines->numbers = (int *)realloc(lines->numbers, lines->allocated * sizeof(int));
+ lines->numbers = (size_t *)realloc(lines->numbers, lines->allocated * sizeof(size_t));
if (lines->numbers == NULL) {
return;
}
diff --git a/libgammu/misc/misc.h b/libgammu/misc/misc.h
index f702589..7875635 100644
--- a/libgammu/misc/misc.h
+++ b/libgammu/misc/misc.h
@@ -35,11 +35,11 @@ typedef struct {
/**
* Cut points.
*/
- int *numbers;
+ size_t *numbers;
/**
* Number of currently allocated entries.
*/
- int allocated;
+ size_t allocated;
/**
* Storage for return value.
*/
@@ -49,7 +49,7 @@ typedef struct {
/**
* Calculates string cut points to split it to lines.
*/
-void SplitLines(const char *message, const int messagesize, GSM_CutLines *lines, const char *whitespaces, const int spaceslen, const char *quotes, const int quoteslen, const gboolean eot);
+void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines, const char *whitespaces, const size_t spaceslen, const char *quotes, const size_t quoteslen, const gboolean eot);
/**
* Returns pointer to static buffer containing line.
diff --git a/libgammu/phone/alcatel/alcatel.c b/libgammu/phone/alcatel/alcatel.c
index a77994f..9ad9b44 100644
--- a/libgammu/phone/alcatel/alcatel.c
+++ b/libgammu/phone/alcatel/alcatel.c
@@ -847,7 +847,7 @@ static void ALCATEL_DecodeString(GSM_StateMachine *s, unsigned const char *buffe
len = buffer[0];
if (Priv->ProtocolVersion == V_1_1 && (buffer[1] == ALCATEL_UNICODE_FLAG)) {
/* UCS-2-BE string */
- if (GSM_PHONEBOOK_TEXT_LENGTH < len/2) {
+ if (GSM_PHONEBOOK_TEXT_LENGTH <= len / 2) {
smprintf(s, "WARNING: Text truncated, to %d from %d\n", maxlen, len/2 + 1);
len = GSM_PHONEBOOK_TEXT_LENGTH * 2;
}
@@ -856,7 +856,7 @@ static void ALCATEL_DecodeString(GSM_StateMachine *s, unsigned const char *buffe
Priv->ReturnString[len + 2] = 0;
} else {
/* Alcatel alphabet string */
- if (GSM_PHONEBOOK_TEXT_LENGTH < len) {
+ if (GSM_PHONEBOOK_TEXT_LENGTH <= len) {
smprintf(s, "WARNING: Text truncated, to %d from %d\n", maxlen, len + 1);
len = GSM_PHONEBOOK_TEXT_LENGTH;
}
@@ -2066,11 +2066,13 @@ static GSM_Error ALCATEL_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
break;
case PBK_Text_LastName:
UpdatedFields[0] = TRUE;
- if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 0, entry->Entries[i].Text)) != ERR_NONE) return error; NameSet = TRUE;
+ if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 0, entry->Entries[i].Text)) != ERR_NONE) return error;
+ NameSet = TRUE;
break;
case PBK_Text_FirstName:
UpdatedFields[1] = TRUE;
- if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 1, entry->Entries[i].Text)) != ERR_NONE) return error; NameSet = TRUE;
+ if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 1, entry->Entries[i].Text)) != ERR_NONE) return error;
+ NameSet = TRUE;
break;
case PBK_Text_Company:
UpdatedFields[2] = TRUE;
diff --git a/libgammu/phone/at/at-sms.c b/libgammu/phone/at/at-sms.c
index 12d071b..0cd0d65 100644
--- a/libgammu/phone/at/at-sms.c
+++ b/libgammu/phone/at/at-sms.c
@@ -408,7 +408,7 @@ GSM_Error ATGEN_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigne
(*location)--;
}
smprintf(s, "SMS folder %i & location %i -> ATGEN folder %i & location %i\n",
- sms->Folder,sms->Location,*folderid,*location);
+ sms->Folder, sms->Location, *folderid, *location);
/* Set the needed memory type */
if (Priv->SIMSMSMemory == AT_AVAILABLE &&
@@ -1534,7 +1534,6 @@ GSM_Error ATGEN_ReplyAddSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *
GSM_Error error;
GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
size_t i = 0;
- int folder = 0;
switch (Priv->ReplyState) {
case AT_Reply_SMSEdit:
@@ -1564,11 +1563,13 @@ GSM_Error ATGEN_ReplyAddSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *
smprintf(s, "Saved at AT location %i\n",
s->Phone.Data.SaveSMSMessage->Location);
/* Adjust location */
- folder = s->Phone.Data.SaveSMSMessage->Folder;
- ATGEN_SetSMSLocation(s, s->Phone.Data.SaveSMSMessage,
- (folder / 2), /* We care only about SIM/Phone */
- s->Phone.Data.SaveSMSMessage->Location);
- s->Phone.Data.SaveSMSMessage->Folder = folder;
+ ATGEN_SetSMSLocation(
+ s,
+ s->Phone.Data.SaveSMSMessage,
+ /* We care only about SIM/Phone */
+ s->Phone.Data.SaveSMSMessage->Folder <= 2 ? 1 : 2,
+ s->Phone.Data.SaveSMSMessage->Location
+ );
return ERR_NONE;
case AT_Reply_Error:
smprintf(s, "Error\n");
@@ -1584,7 +1585,7 @@ GSM_Error ATGEN_ReplyAddSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *
return ERR_UNKNOWNRESPONSE;
}
-GSM_Error ATGEN_MakeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *message, unsigned char *hexreq, int *current, size_t *length2)
+GSM_Error ATGEN_MakeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *message, unsigned char *hexreq, size_t hexlength, int *current, size_t *length2)
{
GSM_Error error;
GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
@@ -1708,7 +1709,7 @@ GSM_Error ATGEN_MakeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *message, unsig
/* If not SMS with UDH, it's as normal text */
if (message->UDH.Type == UDH_NoUDH) {
error = ATGEN_EncodeText(
- s, message->Text, UnicodeLength(message->Text), hexreq, sizeof(hexreq), length2
+ s, message->Text, UnicodeLength(message->Text), hexreq, hexlength, length2
);
if (error != ERR_NONE) {
return error;
@@ -1783,7 +1784,7 @@ GSM_Error ATGEN_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
}
/* Format SMS frame */
- error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &length);
+ error = ATGEN_MakeSMSFrame(s, sms, hexreq, sizeof(hexreq), &current, &length);
if (error != ERR_NONE) {
return error;
@@ -1803,7 +1804,7 @@ GSM_Error ATGEN_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
/* No (good and 100% working) support for alphanumeric numbers */
if (sms->Number[1]!='+' && (sms->Number[1]<'0' || sms->Number[1]>'9')) {
EncodeUnicode(sms->Number,"123",3);
- error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &length);
+ error = ATGEN_MakeSMSFrame(s, sms, hexreq, sizeof(hexreq), &current, &length);
if (error != ERR_NONE) return error;
}
}
@@ -1960,7 +1961,7 @@ GSM_Error ATGEN_SendSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
if (sms->PDU == SMS_Deliver) {
sms->PDU = SMS_Submit;
}
- error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &length);
+ error = ATGEN_MakeSMSFrame(s, sms, hexreq, sizeof(hexreq), &current, &length);
if (error != ERR_NONE) {
return error;
@@ -2422,6 +2423,7 @@ int *GetRange(GSM_StateMachine *s, const char *buffer)
/* Did we parse anything? */
if (endptr == chr) {
smprintf(s, "Failed to find number in range!\n");
+ free(result);
return NULL;
}
/* Allocate more memory if needed */
@@ -2457,6 +2459,7 @@ int *GetRange(GSM_StateMachine *s, const char *buffer)
break;
} else if (*chr != ',') {
smprintf(s, "Bad character in range: %c\n", *chr);
+ free(result);
return NULL;
}
}
diff --git a/libgammu/phone/at/atgen.c b/libgammu/phone/at/atgen.c
index c1b65ca..067f5d4 100644
--- a/libgammu/phone/at/atgen.c
+++ b/libgammu/phone/at/atgen.c
@@ -437,7 +437,7 @@ GSM_Error ATGEN_WaitFor(GSM_StateMachine *s, const char * cmd, size_t len,
*
* \return True when text does not contain non hex chars.
*/
-INLINE gboolean ATGEN_HasOnlyHexChars(const char *text, const size_t length)
+gboolean ATGEN_HasOnlyHexChars(const char *text, const size_t length)
{
size_t i = 0;
@@ -456,7 +456,7 @@ INLINE gboolean ATGEN_HasOnlyHexChars(const char *text, const size_t length)
*
* \return True when text does not contain non digits chars.
*/
-INLINE gboolean ATGEN_HasOnlyDigits(const char *text, const size_t length)
+gboolean ATGEN_HasOnlyDigits(const char *text, const size_t length)
{
size_t i = 0;
@@ -476,7 +476,7 @@ INLINE gboolean ATGEN_HasOnlyDigits(const char *text, const size_t length)
* \param text Text.
* \return True when text can be UCS2.
*/
-INLINE gboolean ATGEN_IsUCS2(const char *text, const size_t length)
+gboolean ATGEN_IsUCS2(const char *text, const size_t length)
{
return (length > 3) &&
(length % 4 == 0) &&
@@ -491,7 +491,7 @@ INLINE gboolean ATGEN_IsUCS2(const char *text, const size_t length)
* \param text Text.
* \return True when text can be HEX.
*/
-INLINE gboolean ATGEN_IsHex(const char *text, const size_t length)
+gboolean ATGEN_IsHex(const char *text, const size_t length)
{
return (length > 4) &&
(length % 2 == 0) &&
@@ -506,7 +506,7 @@ INLINE gboolean ATGEN_IsHex(const char *text, const size_t length)
* \param text Text.
* \return True when text can be HEX.
*/
-INLINE gboolean ATGEN_IsNumber(const char *text, const size_t length)
+gboolean ATGEN_IsNumber(const char *text, const size_t length)
{
return ATGEN_HasOnlyDigits(text, length);
}
@@ -759,7 +759,10 @@ GSM_Error ATGEN_DecodeText(GSM_StateMachine *s,
return ERR_MOREMEMORY;
}
DecodeHexBin(buffer, input, length);
- if (2 * strlen(buffer) >= outlength) return ERR_MOREMEMORY;
+ if (2 * strlen(buffer) >= outlength) {
+ free(buffer);
+ return ERR_MOREMEMORY;
+ }
DecodeDefault(output, buffer, strlen(buffer), TRUE, NULL);
free(buffer);
buffer = NULL;
@@ -1613,6 +1616,7 @@ GSM_Error ATGEN_SQWEReply(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
GSM_Error ATGEN_ReplyGetUSSD(GSM_Protocol_Message *msg, GSM_StateMachine *s)
{
+ GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
GSM_USSDMessage ussd;
GSM_Error error;
unsigned char *pos = NULL;
@@ -1719,13 +1723,16 @@ GSM_Error ATGEN_ReplyGetUSSD(GSM_Protocol_Message *msg, GSM_StateMachine *s)
coding = GSM_GetMessageCoding(&(s->di), dcs);
}
- smprintf(s, "coding %d -> %d\n", dcs, coding);
+ smprintf(s, "USSD coding DCS = %d -> Coding = %d\n", dcs, coding);
if (coding == SMS_Coding_Default_No_Compression) {
- DecodeHexBin(packed, hex_encoded, strlen(hex_encoded));
- GSM_UnpackEightBitsToSeven(0, strlen(hex_encoded), sizeof(decoded), packed, decoded);
- DecodeDefault(ussd.Text, decoded, strlen(decoded), TRUE, NULL);
-
+ if (Priv->Charset == AT_CHARSET_HEX || GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_ENCODED_USSD)) {
+ DecodeHexBin(packed, hex_encoded, strlen(hex_encoded));
+ GSM_UnpackEightBitsToSeven(0, strlen(hex_encoded), sizeof(decoded), packed, decoded);
+ DecodeDefault(ussd.Text, decoded, strlen(decoded), TRUE, NULL);
+ } else {
+ DecodeDefault(ussd.Text, hex_encoded, strlen(hex_encoded), TRUE, NULL);
+ }
} else if (coding == SMS_Coding_Unicode_No_Compression) {
DecodeHexUnicode(ussd.Text, hex_encoded + offset, strlen(hex_encoded));
} else if (coding == SMS_Coding_8bit) {
@@ -4766,7 +4773,7 @@ GSM_Error ATGEN_ReplyGetDivert(GSM_Protocol_Message *msg, GSM_StateMachine *s)
if (error != ERR_NONE) {
error = ATGEN_ParseReply(s, str,
- "+CCFC: @i, @i, @p, @I, @s, @i, @i",
+ "+CCFC: @i, @i, @p, @I, @s, @I, @I",
&status,
&class,
response->Entries[response->EntriesNum].Number,
@@ -6146,7 +6153,6 @@ GSM_Reply_Function ATGENReplyFunctions[] = {
{ATGEN_GenericReply, "AT+CLIP" ,0x00,0x00,ID_SetIncomingCall },
{ATGEN_GenericReply, "AT+CCWA" ,0x00,0x00,ID_SetIncomingCall },
{ATGEN_GenericReply, "AT+CUSD" ,0x00,0x00,ID_SetUSSD },
-{ATGEN_ReplyGetUSSD, "AT+CUSD" ,0x00,0x00,ID_GetUSSD },
{ATGEN_ReplyGetUSSD, "+CUSD" ,0x00,0x00,ID_IncomingFrame },
{ATGEN_GenericReply, "AT+CLIP=1" ,0x00,0x00,ID_IncomingFrame },
{ATGEN_ReplyIncomingCallInfo, "+CLIP" ,0x00,0x00,ID_IncomingFrame },
@@ -6205,6 +6211,7 @@ GSM_Reply_Function ATGENReplyFunctions[] = {
{ATGEN_GenericReplyIgnore, "^HCSQ:" ,0x00,0x00,ID_IncomingFrame },
{ATGEN_GenericReplyIgnore, "^SRVST:" ,0x00,0x00,ID_IncomingFrame },
{ATGEN_GenericReplyIgnore, "^SIMST:" ,0x00,0x00,ID_IncomingFrame },
+{ATGEN_GenericReplyIgnore, "^STIN:" ,0x00,0x00,ID_IncomingFrame },
{ATGEN_GenericReplyIgnore, "+ZUSIMR:" ,0x00,0x00,ID_IncomingFrame },
{ATGEN_GenericReplyIgnore, "+ZEND" ,0x00,0x00,ID_IncomingFrame },
{ATGEN_GenericReplyIgnore, "+CDSI:" ,0x00,0x00,ID_IncomingFrame },
diff --git a/libgammu/phone/atobex/atobex.c b/libgammu/phone/atobex/atobex.c
index 9285d51..fcf0953 100644
--- a/libgammu/phone/atobex/atobex.c
+++ b/libgammu/phone/atobex/atobex.c
@@ -647,7 +647,7 @@ GSM_Error ATOBEX_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
* @{
*/
-GSM_Error ATOBEX_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error ATOBEX_AddFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_Error error;
@@ -658,7 +658,7 @@ GSM_Error ATOBEX_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int
return OBEXGEN_AddFilePart(s, File, Pos, Handle);
}
-GSM_Error ATOBEX_SendFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error ATOBEX_SendFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_Error error;
@@ -669,7 +669,7 @@ GSM_Error ATOBEX_SendFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int
return OBEXGEN_SendFilePart(s, File, Pos, Handle);
}
-GSM_Error ATOBEX_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size)
+GSM_Error ATOBEX_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
{
GSM_Error error;
@@ -1448,7 +1448,6 @@ GSM_Error ATOBEX_ReplyGetBatteryCharge(GSM_Protocol_Message *msg, GSM_StateMachi
bat->ChargeVoltage *= 10;
switch (method) {
case 0:
- bat->BatteryType = GSM_BatteryLiPol;
bat->BatteryType = GSM_BatteryNiMH;
break;
case 1:
diff --git a/libgammu/phone/dummy/dummy.c b/libgammu/phone/dummy/dummy.c
index 41a6cd7..778e682 100644
--- a/libgammu/phone/dummy/dummy.c
+++ b/libgammu/phone/dummy/dummy.c
@@ -57,10 +57,11 @@
#include <dirent.h>
#endif
-GSM_Error DUMMY_Error(GSM_StateMachine *s, const char *message)
+GSM_Error DUMMY_Error(GSM_StateMachine *s, const char *message, const char *path)
{
int tmp_errno;
tmp_errno = errno;
+ smprintf(s, "Filesystem path: %s\n", path);
GSM_OSErrorInfo(s, message);
if (tmp_errno == ENOENT) {
return ERR_EMPTY;
@@ -533,7 +534,7 @@ GSM_Error DUMMY_DeleteSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
if (unlink(filename) == 0) {
error = ERR_NONE;
} else {
- error = DUMMY_Error(s, "SMS unlink failed");
+ error = DUMMY_Error(s, "SMS unlink failed", filename);
}
free(filename);
filename=NULL;
@@ -994,7 +995,7 @@ GSM_Error DUMMY_DeleteAlarm(GSM_StateMachine *s, GSM_Alarm *entry)
if (unlink(filename) == 0) {
error = ERR_NONE;
} else {
- error = DUMMY_Error(s, "calendar unlink failed");
+ error = DUMMY_Error(s, "calendar unlink failed", filename);
}
free(filename);
@@ -1068,11 +1069,11 @@ GSM_Error DUMMY_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
{
switch (bookmark->Location) {
case 1:
- EncodeUnicode(bookmark->Address, "http://blog.cihar.com/", 22);
+ EncodeUnicode(bookmark->Address, "https://blog.cihar.com/", 23);
EncodeUnicode(bookmark->Title, "Michals weblog", 14);
return ERR_NONE;
case 2:
- EncodeUnicode(bookmark->Address, "http://wammu.eu/", 16);
+ EncodeUnicode(bookmark->Address, "https://wammu.eu/", 17);
EncodeUnicode(bookmark->Title, "Wammu website", 13);
return ERR_NONE;
default:
@@ -1097,7 +1098,7 @@ GSM_Error DUMMY_SetFileAttributes(GSM_StateMachine *s, GSM_File *File)
return ERR_NONE;
}
-GSM_Error DUMMY_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error DUMMY_AddFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
char *path;
FILE *file;
@@ -1118,21 +1119,21 @@ GSM_Error DUMMY_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *
file = fopen(path, "w");
if (file == NULL) {
+ error = DUMMY_Error(s, "fopen(w) failed", path);
free(path);
- error = DUMMY_Error(s, "fopen(w) failed");
if (error == ERR_EMPTY) return ERR_PERMISSION;
return error;
}
if (fwrite(File->Buffer, 1, File->Used, file) != File->Used) {
+ error = DUMMY_Error(s, "fwrite failed", path);
free(path);
- error = DUMMY_Error(s, "fwrite failed");
fclose(file);
if (error == ERR_EMPTY) return ERR_PERMISSION;
return error;
}
if (fclose(file) != 0) {
+ error = DUMMY_Error(s, "fclose failed", path);
free(path);
- error = DUMMY_Error(s, "fclose failed");
if (error == ERR_EMPTY) return ERR_PERMISSION;
return error;
}
@@ -1144,13 +1145,13 @@ GSM_Error DUMMY_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *
return ERR_EMPTY;
}
-GSM_Error DUMMY_SendFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error DUMMY_SendFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
EncodeUnicode(File->ID_FullName, "incoming/", 9);
return DUMMY_AddFilePart(s, File, Pos, Handle);
}
-GSM_Error DUMMY_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size)
+GSM_Error DUMMY_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
{
char *path, *name, *pos;
GSM_Error error;
@@ -1179,6 +1180,7 @@ GSM_Error DUMMY_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, in
GSM_Error DUMMY_GetFolderListing(GSM_StateMachine *s, GSM_File *File, gboolean start)
{
GSM_Phone_DUMMYData *Priv = &s->Phone.Data.Priv.DUMMY;
+ GSM_Error error;
char *path;
struct dirent *dp;
struct stat sb;
@@ -1191,12 +1193,15 @@ GSM_Error DUMMY_GetFolderListing(GSM_StateMachine *s, GSM_File *File, gboolean s
smprintf(s, "listing %s\n", path);
strcpy(Priv->dirnames[DUMMY_MAX_FS_DEPTH], path);
Priv->dir[DUMMY_MAX_FS_DEPTH] = opendir(path);
- free(path);
- path=NULL;
if (Priv->dir[DUMMY_MAX_FS_DEPTH] == NULL) {
- return DUMMY_Error(s, "opendir failed");
+ error = DUMMY_Error(s, "opendir failed", path);
+ free(path);
+ path=NULL;
+ return error;
}
+ free(path);
+ path=NULL;
}
read_next_entry:
@@ -1214,9 +1219,10 @@ read_next_entry:
/* Stat file */
path = DUMMY_GetFSPath(s, dp->d_name, DUMMY_MAX_FS_DEPTH);
if (stat(path, &sb) < 0) {
+ error = DUMMY_Error(s, "stat failed", path);
free(path);
path=NULL;
- return DUMMY_Error(s, "stat failed");
+ return error;
}
/* Fill file structure */
@@ -1247,9 +1253,10 @@ read_next_entry:
Priv->fs_depth++;
Priv->dir[Priv->fs_depth] = opendir(path);
if (Priv->dir[Priv->fs_depth] == NULL) {
+ error = DUMMY_Error(s, "nested opendir failed", path);
free(path);
path=NULL;
- return DUMMY_Error(s, "nested opendir failed");
+ return error;
}
strcpy(Priv->dirnames[Priv->fs_depth], path);
}
@@ -1261,6 +1268,7 @@ read_next_entry:
GSM_Error DUMMY_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean start)
{
GSM_Phone_DUMMYData *Priv = &s->Phone.Data.Priv.DUMMY;
+ GSM_Error error;
char *path;
struct dirent *dp;
struct stat sb;
@@ -1276,12 +1284,15 @@ GSM_Error DUMMY_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean
path = DUMMY_GetFilePath(s, "fs");
strcpy(Priv->dirnames[0], path);
Priv->dir[0] = opendir(path);
- free(path);
- path=NULL;
if (Priv->dir[0] == NULL) {
- return DUMMY_Error(s, "opendir failed");
+ error = DUMMY_Error(s, "opendir failed", path);
+ free(path);
+ path = NULL;
+ return error;
}
+ free(path);
+ path=NULL;
Priv->fs_depth = 0;
}
@@ -1302,9 +1313,10 @@ read_next_entry:
/* Stat file */
path = DUMMY_GetFSPath(s, dp->d_name, Priv->fs_depth);
if (stat(path, &sb) < 0) {
+ error = DUMMY_Error(s, "stat failed", path);
free(path);
- path=NULL;
- return DUMMY_Error(s, "stat failed");
+ path = NULL;
+ return error;
}
/* Fill file structure */
@@ -1335,9 +1347,10 @@ read_next_entry:
Priv->fs_depth++;
Priv->dir[Priv->fs_depth] = opendir(path);
if (Priv->dir[Priv->fs_depth] == NULL) {
+ error = DUMMY_Error(s, "nested opendir failed", path);
free(path);
path=NULL;
- return DUMMY_Error(s, "nested opendir failed");
+ return error;
}
strcpy(Priv->dirnames[Priv->fs_depth], path);
}
@@ -1353,9 +1366,9 @@ GSM_Error DUMMY_DeleteFile(GSM_StateMachine *s, unsigned char *ID)
path = DUMMY_GetFSFilePath(s, ID);
if (unlink(path) != 0) {
+ error = DUMMY_Error(s, "unlink failed", path);
free(path);
- path=NULL;
- error = DUMMY_Error(s, "unlink failed");
+ path = NULL;
if (error == ERR_EMPTY) return ERR_FILENOTEXIST;
return error;
}
@@ -1372,9 +1385,9 @@ GSM_Error DUMMY_DeleteFolder(GSM_StateMachine *s, unsigned char *ID)
path = DUMMY_GetFSFilePath(s, ID);
smprintf(s, "Deleting directory %s\n", path);
if (rmdir(path) != 0) {
+ error = DUMMY_Error(s, "rmdir failed", path);
free(path);
- path=NULL;
- error = DUMMY_Error(s, "rmdir failed");
+ path = NULL;
if (error == ERR_EMPTY) return ERR_FILENOTEXIST;
return error;
}
@@ -1387,6 +1400,7 @@ GSM_Error DUMMY_AddFolder(GSM_StateMachine *s, GSM_File *File)
{
char *path;
size_t pos;
+ GSM_Error error;
pos = UnicodeLength(File->ID_FullName);
if (pos > 0 && (File->ID_FullName[2*pos - 2] != 0 || File->ID_FullName[2*pos - 1] != '/')) {
@@ -1398,9 +1412,10 @@ GSM_Error DUMMY_AddFolder(GSM_StateMachine *s, GSM_File *File)
path = DUMMY_GetFSFilePath(s, File->ID_FullName);
if (MKDIR(path) != 0) {
+ error = DUMMY_Error(s, "mkdir failed", path);
free(path);
path=NULL;
- return DUMMY_Error(s, "mkdir failed");
+ return error;
}
free(path);
path=NULL;
@@ -1492,7 +1507,7 @@ GSM_Error DUMMY_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
if (unlink(filename) == 0) {
error = ERR_NONE;
} else {
- error = DUMMY_Error(s, "memory unlink failed");
+ error = DUMMY_Error(s, "memory unlink failed", filename);
}
free(filename);
@@ -1603,7 +1618,7 @@ GSM_Error DUMMY_DeleteToDo(GSM_StateMachine *s, GSM_ToDoEntry *entry)
if (unlink(filename) == 0) {
error = ERR_NONE;
} else {
- error = DUMMY_Error(s, "todo unlink failed");
+ error = DUMMY_Error(s, "todo unlink failed", filename);
}
free(filename);
@@ -1707,7 +1722,7 @@ GSM_Error DUMMY_DeleteCalendar(GSM_StateMachine *s, GSM_CalendarEntry *entry)
if (unlink(filename) == 0) {
error = ERR_NONE;
} else {
- error = DUMMY_Error(s, "calendar unlink failed");
+ error = DUMMY_Error(s, "calendar unlink failed", filename);
}
free(filename);
@@ -1823,7 +1838,7 @@ GSM_Error DUMMY_DeleteNote(GSM_StateMachine *s, GSM_NoteEntry *entry)
if (unlink(filename) == 0) {
error = ERR_NONE;
} else {
- error = DUMMY_Error(s, "note unlink failed");
+ error = DUMMY_Error(s, "note unlink failed", filename);
}
free(filename);
filename=NULL;
diff --git a/libgammu/phone/nokia/dct4s40/6510/6510file.c b/libgammu/phone/nokia/dct4s40/6510/6510file.c
index 66eba04..fa59ea5 100644
--- a/libgammu/phone/nokia/dct4s40/6510/6510file.c
+++ b/libgammu/phone/nokia/dct4s40/6510/6510file.c
@@ -379,7 +379,7 @@ static GSM_Error N6510_GetFileSystemStatus1(GSM_StateMachine *s, GSM_FileSystemS
return GSM_WaitFor (s, req, 10, 0x6D, 4, ID_FileSystemStatus);
}
-static GSM_Error N6510_GetFilePart1(GSM_StateMachine *s, GSM_File *File, int *Handle UNUSED, int *Size)
+static GSM_Error N6510_GetFilePart1(GSM_StateMachine *s, GSM_File *File, int *Handle UNUSED, size_t *Size)
{
GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
int old;
@@ -564,7 +564,7 @@ GSM_Error N6510_ReplyAddFilePart1(GSM_Protocol_Message *msg UNUSED, GSM_StateMac
return ERR_NONE;
}
-static GSM_Error N6510_AddFilePart1(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle UNUSED)
+static GSM_Error N6510_AddFilePart1(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle UNUSED)
{
GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
GSM_File File2;
@@ -642,7 +642,7 @@ static GSM_Error N6510_AddFilePart1(GSM_StateMachine *s, GSM_File *File, int *Po
Add[12] = j / 256;
Add[13] = j % 256;
memcpy(Add+14,File->Buffer+(*Pos),j);
- smprintf(s, "Adding file part %i %i\n",*Pos,j);
+ smprintf(s, "Adding file part %ld %i\n", (long)*Pos,j);
error=GSM_WaitFor (s, Add, 14+j, 0x6D, 4, ID_AddFile);
if (error != ERR_NONE) return error;
*Pos = *Pos + j;
@@ -1186,7 +1186,7 @@ static GSM_Error N6510_GetNextFileFolder2(GSM_StateMachine *s, GSM_File *File, g
return error;
}
-static GSM_Error N6510_GetFilePart2(GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size)
+static GSM_Error N6510_GetFilePart2(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
{
int old,j;
GSM_Error error;
@@ -1318,7 +1318,7 @@ static GSM_Error N6510_SetFileAttributes2(GSM_StateMachine *s, GSM_File *File)
return ERR_NONE;
}
-static GSM_Error N6510_AddFilePart2(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+static GSM_Error N6510_AddFilePart2(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_Error error;
int j,P;
@@ -1365,7 +1365,7 @@ static GSM_Error N6510_AddFilePart2(GSM_StateMachine *s, GSM_File *File, int *Po
req[13] = j % 256;
memcpy(req+14,File->Buffer+(*Pos),j);
- smprintf(s, "Adding file part %i %i\n",*Pos,j);
+ smprintf(s, "Adding file part %ld %i\n",(long)*Pos,j);
error=GSM_WaitFor (s, req, 14+j, 0x6D, 4, ID_AddFile);
if (error != ERR_NONE) return error;
*Pos = *Pos + j;
@@ -1681,7 +1681,7 @@ GSM_Error N6510_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean
return N6510_GetNextFileFolder2(s,File,start);
}
-GSM_Error N6510_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size)
+GSM_Error N6510_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
{
GSM_File File2;
char buf[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))];
@@ -1711,7 +1711,7 @@ GSM_Error N6510_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, in
}
}
-GSM_Error N6510_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error N6510_AddFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_File File2;
GSM_Error error;
@@ -2126,7 +2126,8 @@ GSM_Error N6510_GetNextMMSFileInfo(GSM_StateMachine *s, unsigned char *FileID, i
GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
GSM_Error error;
GSM_File file;
- int Handle,Size;
+ int Handle;
+ size_t Size;
if (start) {
error = N6510_GetMMSFolders(s, &folders);
@@ -2497,7 +2498,7 @@ GSM_Error N6510_DecodeFilesystemSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sm
break;
}
if (unknown) {
- smprintf(s, "WARNING: Unknown block 0x%02x, see <http://wammu.eu/support/bugs/> how to report\n", FFF->Buffer[pos]);
+ smprintf(s, "WARNING: Unknown block 0x%02x, see <https://wammu.eu/support/bugs/> how to report\n", FFF->Buffer[pos]);
DumpMessage(&(s->di), FFF->Buffer + pos, 3 + (FFF->Buffer[pos + 1] << 8) + FFF->Buffer[pos + 2]);
#ifdef DEBUG
} else {
@@ -2529,7 +2530,8 @@ GSM_Error N6510_GetNextFilesystemSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *s
{
GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
unsigned char folderid;
- int location,Size,Handle;
+ int location,Handle;
+ size_t Size;
GSM_Error error;
GSM_File FFF;
gboolean start2=start;
diff --git a/libgammu/phone/nokia/dct4s40/6510/6510file.h b/libgammu/phone/nokia/dct4s40/6510/6510file.h
index ed7e94d..12810e9 100644
--- a/libgammu/phone/nokia/dct4s40/6510/6510file.h
+++ b/libgammu/phone/nokia/dct4s40/6510/6510file.h
@@ -4,8 +4,8 @@ GSM_Error N6510_GetNextFileFolder (GSM_StateMachine *s, GSM_File *File, gboolea
GSM_Error N6510_GetFolderListing (GSM_StateMachine *s, GSM_File *File, gboolean start);
GSM_Error N6510_AddFolder (GSM_StateMachine *s, GSM_File *File);
GSM_Error N6510_DeleteFolder (GSM_StateMachine *s, unsigned char *ID);
-GSM_Error N6510_GetFilePart (GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size);
-GSM_Error N6510_AddFilePart (GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle);
+GSM_Error N6510_GetFilePart (GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size);
+GSM_Error N6510_AddFilePart (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle);
GSM_Error N6510_DeleteFile (GSM_StateMachine *s, unsigned char *ID);
GSM_Error N6510_SetFileAttributes (GSM_StateMachine *s, GSM_File *File);
GSM_Error N6510_GetNextRootFolder (GSM_StateMachine *s, GSM_File *File);
diff --git a/libgammu/phone/nokia/dct4s40/6510/n6510.c b/libgammu/phone/nokia/dct4s40/6510/n6510.c
index 9796c74..cde4ff7 100644
--- a/libgammu/phone/nokia/dct4s40/6510/n6510.c
+++ b/libgammu/phone/nokia/dct4s40/6510/n6510.c
@@ -2229,8 +2229,14 @@ static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSe
if (((length + pad) % 2)) pad = 2; else pad = 0;
pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].HomePage, TRUE);
- if (settings->Settings[loc1].IsContinuous) req[pos] = 0x01; pos++;
- if (settings->Settings[loc1].IsSecurity) req[pos] = 0x01; pos++;
+ if (settings->Settings[loc1].IsContinuous) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (settings->Settings[loc1].IsSecurity) {
+ req[pos] = 0x01;
+ }
+ pos++;
} else if (loc2 != -1) {
/* Name */
length = UnicodeLength(settings->Settings[loc2].Title);
@@ -2242,8 +2248,14 @@ static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSe
if (((length + pad) % 2)) pad = 2; else pad = 0;
pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].HomePage, TRUE);
- if (settings->Settings[loc2].IsContinuous) req[pos] = 0x01; pos++;
- if (settings->Settings[loc2].IsSecurity) req[pos] = 0x01; pos++;
+ if (settings->Settings[loc2].IsContinuous) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (settings->Settings[loc2].IsSecurity) {
+ req[pos] = 0x01;
+ }
+ pos++;
} else {
/* Name */
length = 0;
@@ -2295,8 +2307,14 @@ static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSe
req[pos++] = length % 256;
if (loc1 != -1) {
- if (!settings->Settings[loc1].IsNormalAuthentication) req[pos]=0x01; pos++;
- if (settings->Settings[loc1].IsISDNCall) req[pos]=0x01; pos++;
+ if (!settings->Settings[loc1].IsNormalAuthentication) {
+ req[pos]=0x01;
+ }
+ pos++;
+ if (settings->Settings[loc1].IsISDNCall) {
+ req[pos]=0x01;
+ }
+ pos++;
switch (settings->Settings[loc1].Speed) {
case WAPSETTINGS_SPEED_AUTO : break;
case WAPSETTINGS_SPEED_9600 : req[pos]=0x01; break;
@@ -2304,7 +2322,9 @@ static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSe
}
pos++;
req[pos++]=0x01;
- if (!settings->Settings[loc1].ManualLogin) req[pos] = 0x01; pos++;
+ if (!settings->Settings[loc1].ManualLogin) {
+ req[pos] = 0x01;
+ }pos++;
pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].IPAddress, FALSE);
pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].DialUp, TRUE);
@@ -2337,9 +2357,18 @@ static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSe
req[pos++] = length % 256;
if (loc2 != -1) {
- if (!settings->Settings[loc2].IsNormalAuthentication) req[pos] = 0x01; pos++;
- if (!settings->Settings[loc2].IsContinuous) req[pos] = 0x01; pos++;
- if (!settings->Settings[loc2].ManualLogin) req[pos] = 0x01; pos++;
+ if (!settings->Settings[loc2].IsNormalAuthentication) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (!settings->Settings[loc2].IsContinuous) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (!settings->Settings[loc2].ManualLogin) {
+ req[pos] = 0x01;
+ }
+ pos++;
pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].DialUp, FALSE);
pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].IPAddress, TRUE);
diff --git a/libgammu/phone/nokia/wd2/n3650.c b/libgammu/phone/nokia/wd2/n3650.c
index 6fc9ee5..8a68da3 100644
--- a/libgammu/phone/nokia/wd2/n3650.c
+++ b/libgammu/phone/nokia/wd2/n3650.c
@@ -43,7 +43,7 @@ static GSM_Error N3650_ReplyGetFilePart(GSM_Protocol_Message *msg, GSM_StateMach
return ERR_NONE;
}
-static GSM_Error N3650_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle UNUSED, int *Size)
+static GSM_Error N3650_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle UNUSED, size_t *Size)
{
unsigned int len=10,i;
GSM_Error error;
diff --git a/libgammu/phone/obex/mobex.c b/libgammu/phone/obex/mobex.c
index 81dcd4f..fe3b1ed 100644
--- a/libgammu/phone/obex/mobex.c
+++ b/libgammu/phone/obex/mobex.c
@@ -282,6 +282,9 @@ GSM_Error MOBEX_GetNextEntry(GSM_StateMachine *s, const char *path, const gboole
if (*pos + 4 > *size) {
return ERR_EMPTY;
}
+ if (*data == NULL) {
+ return ERR_BUG;
+ }
/* Return values */
*entry = *data + *pos + 4;
diff --git a/libgammu/phone/obex/obexfunc.h b/libgammu/phone/obex/obexfunc.h
index ac7703c..f7fbf67 100644
--- a/libgammu/phone/obex/obexfunc.h
+++ b/libgammu/phone/obex/obexfunc.h
@@ -10,9 +10,9 @@
extern GSM_Reply_Function OBEXGENReplyFunctions[];
extern GSM_Error OBEXGEN_InitialiseVars(GSM_StateMachine *s);
extern void OBEXGEN_FreeVars(GSM_StateMachine *s);
-extern GSM_Error OBEXGEN_GetFilePart (GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size);
-extern GSM_Error OBEXGEN_AddFilePart (GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle);
-extern GSM_Error OBEXGEN_SendFilePart (GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle);
+extern GSM_Error OBEXGEN_GetFilePart (GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size);
+extern GSM_Error OBEXGEN_AddFilePart (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle);
+extern GSM_Error OBEXGEN_SendFilePart (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle);
extern GSM_Error OBEXGEN_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean start);
extern GSM_Error OBEXGEN_Disconnect (GSM_StateMachine *s);
extern GSM_Error OBEXGEN_Connect (GSM_StateMachine *s, OBEX_Service service);
diff --git a/libgammu/phone/obex/obexgen.c b/libgammu/phone/obex/obexgen.c
index af3808c..4802023 100644
--- a/libgammu/phone/obex/obexgen.c
+++ b/libgammu/phone/obex/obexgen.c
@@ -747,7 +747,7 @@ static GSM_Error OBEXGEN_ReplyAddFilePart(GSM_Protocol_Message *msg, GSM_StateMa
return ERR_UNKNOWNRESPONSE;
}
-GSM_Error OBEXGEN_PrivAddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle UNUSED, gboolean HardDelete)
+GSM_Error OBEXGEN_PrivAddFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle UNUSED, gboolean HardDelete)
{
GSM_Error error;
size_t j;
@@ -815,22 +815,22 @@ GSM_Error OBEXGEN_PrivAddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos,
j = File->Used - *Pos;
/* End of file body block */
OBEXAddBlock(req, &Current, 0x49, File->Buffer+(*Pos), j);
- smprintf(s, "Adding last file part %i %ld\n", *Pos, (long)j);
+ smprintf(s, "Adding last file part %ld %ld\n", (long)*Pos, (long)j);
*Pos = *Pos + j;
- error = GSM_WaitFor (s, req, Current, 0x82, OBEX_TIMEOUT * 10, ID_AddFile);
+ error = GSM_WaitFor (s, req, (long)Current, 0x82, OBEX_TIMEOUT * 10, ID_AddFile);
if (error != ERR_NONE) return error;
return ERR_EMPTY;
} else {
/* File body block */
OBEXAddBlock(req, &Current, 0x48, File->Buffer+(*Pos), j);
- smprintf(s, "Adding file part %i %ld\n", *Pos, (long)j);
+ smprintf(s, "Adding file part %ld %ld\n", (long)*Pos, (long)j);
*Pos = *Pos + j;
- error=GSM_WaitFor (s, req, Current, 0x02, OBEX_TIMEOUT * 10, ID_AddFile);
+ error=GSM_WaitFor (s, req, (long)Current, 0x02, OBEX_TIMEOUT * 10, ID_AddFile);
}
return error;
}
-GSM_Error OBEXGEN_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error OBEXGEN_AddFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_Error error;
@@ -850,7 +850,7 @@ GSM_Error OBEXGEN_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int
return error;
}
-GSM_Error OBEXGEN_SendFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
+GSM_Error OBEXGEN_SendFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
{
GSM_Error error;
@@ -1067,7 +1067,7 @@ static GSM_Error OBEXGEN_PrivGetFilePart(GSM_StateMachine *s, GSM_File *File, gb
return ERR_EMPTY;
}
-GSM_Error OBEXGEN_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size)
+GSM_Error OBEXGEN_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
{
GSM_Error error;
@@ -1395,7 +1395,8 @@ GSM_Error OBEXGEN_SetFile(GSM_StateMachine *s, const char *FileName, const unsig
{
GSM_Error error = ERR_NONE;
GSM_File File;
- int Pos = 0, Handle;
+ size_t Pos = 0;
+ int Handle;
/* Fill file structure */
EncodeUnicode(File.ID_FullName, FileName, strlen(FileName));
diff --git a/libgammu/phone/pfunc.c b/libgammu/phone/pfunc.c
index 92afbb0..22bcd9c 100644
--- a/libgammu/phone/pfunc.c
+++ b/libgammu/phone/pfunc.c
@@ -172,7 +172,8 @@ GSM_Error PHONE_FindDataFile(GSM_StateMachine *s, GSM_File * File, const char *E
GSM_Error PHONE_UploadFile(GSM_StateMachine *s, GSM_File * File)
{
- int Pos = 0, Handle = 0;
+ size_t Pos = 0;
+ int Handle = 0;
GSM_Error error = ERR_NONE;;
while (error == ERR_NONE) {
diff --git a/libgammu/protocol/at/at.c b/libgammu/protocol/at/at.c
index 38f32f6..620bd62 100644
--- a/libgammu/protocol/at/at.c
+++ b/libgammu/protocol/at/at.c
@@ -51,14 +51,14 @@ typedef struct {
GSM_Phone_RequestID requestid;
} SpecialAnswersStruct;
-static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
+GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
{
GSM_Protocol_Message Msg2;
GSM_Protocol_ATData *d = &s->Protocol.Data.AT;
size_t i;
/* These are lines with end of "normal" answers */
- static const char *StartStrings[] = {
+ static const char *StatusStrings[] = {
/* Standard AT */
"OK\r",
"ERROR\r",
@@ -85,99 +85,109 @@ static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
static const SpecialAnswersStruct SpecialAnswers[] = {
/* Standard GSM */
{"+CGREG:" ,1, ID_GetNetworkInfo},
- {"+CBM:" ,1, ID_None},
- {"+CMT:" ,2, ID_None},
- {"+CMTI:" ,1, ID_None},
- {"+CDS:" ,2, ID_None},
- {"+CDSI:" ,1, ID_None},
+ {"+CBM:" ,1, ID_All},
+ {"+CMT:" ,2, ID_All},
+ {"+CMTI:" ,1, ID_All},
+ {"+CDS:" ,2, ID_All},
+ {"+CDSI:" ,1, ID_All},
{"+CREG:" ,1, ID_GetNetworkInfo},
- {"+CUSD" ,1, ID_None},
- {"+COLP" ,1, ID_None},
- {"+CLIP" ,1, ID_None},
- {"+CRING" ,1, ID_None},
- {"+CCWA" ,1, ID_None},
+ {"+CUSD" ,1, ID_All},
+ {"+COLP" ,1, ID_All},
+ {"+CLIP" ,1, ID_All},
+ {"+CRING" ,1, ID_All},
+ {"+CCWA" ,1, ID_All},
/* Standard AT */
- {"RING" ,1, ID_None},
- {"NO CARRIER" ,1, ID_None},
- {"NO ANSWER" ,1, ID_None},
+ {"RING" ,1, ID_All},
+ {"NO CARRIER" ,1, ID_All},
+ {"NO ANSWER" ,1, ID_All},
/* GlobeTrotter */
- {"_OSIGQ:" ,1, ID_None},
- {"_OBS:" ,1, ID_None},
+ {"_OSIGQ:" ,1, ID_All},
+ {"_OBS:" ,1, ID_All},
- {"^SCN:" ,1, ID_None},
+ {"^SCN:" ,1, ID_All},
/* Sony-Ericsson */
- {"*EBCA" ,1, ID_None},
+ {"*EBCA" ,1, ID_All},
/* Samsung binary transfer end */
- {"SDNDCRC =" ,1, ID_None},
+ {"SDNDCRC =" ,1, ID_All},
/* Samsung reply to SSHT in some cases */
- {"SAMSUNG PTS DG Test", 1, ID_None},
+ {"SAMSUNG PTS DG Test", 1, ID_All},
/* Cross PD1101wi reply to almost anything */
- {"NOT FOND ^,NOT CUSTOM AT", 1, ID_None},
+ {"NOT FOND ^,NOT CUSTOM AT", 1, ID_All},
/* Motorola banner */
- {"+MBAN:" ,1, ID_None},
+ {"+MBAN:" ,1, ID_All},
/* HSPA CORPORATION */
- {"+ZEND" ,1, ID_None},
+ {"+ZEND" ,1, ID_All},
/* Huawei */
- {"^RSSI:" ,1, ID_None}, /* ^RSSI:18 */
- {"^HCSQ:" ,1, ID_None}, /* ^HCSQ:"WCDMA",39,29,45 */
- {"^DSFLOWRPT:" ,1, ID_None}, /* ^DSFLOWRPT:00000124,00000082,00000EA6,0000000000012325,000000000022771D,0000BB80,0001F400 */
- {"^BOOT:" ,1, ID_None}, /* ^BOOT:27710117,0,0,0,75 */
- {"^MODE:" ,1, ID_None}, /* ^MODE:3,3 */
- {"^CSNR:" ,1, ID_None}, /* ^CSNR:-93,-23 */
- {"^HCSQ:" ,1, ID_None}, /* ^HCSQ:"LTE",59,50,161,24 */
- {"^SRVST:" ,1, ID_None}, /* ^SRVST:0 */
- {"^SIMST:" ,1, ID_None}, /* ^SIMST:1 */
+ {"^RSSI:" ,1, ID_All}, /* ^RSSI:18 */
+ {"^HCSQ:" ,1, ID_All}, /* ^HCSQ:"WCDMA",39,29,45 */
+ {"^DSFLOWRPT:" ,1, ID_All}, /* ^DSFLOWRPT:00000124,00000082,00000EA6,0000000000012325,000000000022771D,0000BB80,0001F400 */
+ {"^BOOT:" ,1, ID_All}, /* ^BOOT:27710117,0,0,0,75 */
+ {"^MODE:" ,1, ID_All}, /* ^MODE:3,3 */
+ {"^CSNR:" ,1, ID_All}, /* ^CSNR:-93,-23 */
+ {"^HCSQ:" ,1, ID_All}, /* ^HCSQ:"LTE",59,50,161,24 */
+ {"^SRVST:" ,1, ID_All}, /* ^SRVST:0 */
+ {"^SIMST:" ,1, ID_All}, /* ^SIMST:1 */
+ {"^STIN:" ,1, ID_All}, /* ^STIN: 7, 0, 0 */
/* ONDA */
- {"+ZUSIMR:" ,1, ID_None}, /* +ZUSIMR:2 */
+ {"+ZUSIMR:" ,1, ID_All}, /* +ZUSIMR:2 */
- {NULL ,1, ID_None}};
+ {NULL ,1, ID_All}};
- /* Ignore leading CR, LF and ESC */
- if (d->Msg.Length == 0) {
- if (rx_char == 10 || rx_char == 13 || rx_char == 27) return ERR_NONE;
- d->LineStart = d->Msg.Length;
+ /* We're starting new message */
+ if (d->Msg.Length == 0) {
+ /* Ignore leading CR, LF and ESC */
+ if (rx_char == 10 || rx_char == 13 || rx_char == 27) {
+ return ERR_NONE;
+ }
+ d->LineStart = 0;
}
+ /* Allocate more memory if needed */
if (d->Msg.BufferUsed < d->Msg.Length + 2) {
- d->Msg.BufferUsed = d->Msg.Length + 2;
+ d->Msg.BufferUsed = d->Msg.Length + 200;
d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed);
if (d->Msg.Buffer == NULL) {
return ERR_MOREMEMORY;
}
}
+
+ /* Store current char in the buffer */
d->Msg.Buffer[d->Msg.Length++] = rx_char;
d->Msg.Buffer[d->Msg.Length ] = 0;
+ /* Parse char */
switch (rx_char) {
case 0:
break;
case 10:
case 13:
- if (!d->wascrlf) {
+ /* Store line end (if we did not do it in last char */
+ if (! d->wascrlf) {
d->LineEnd = d->Msg.Length - 1;
}
d->wascrlf = TRUE;
- if (d->Msg.Length > 0 && rx_char == 10 && d->Msg.Buffer[d->Msg.Length-2]==13) {
- i = 0;
- while (StartStrings[i] != NULL) {
- if (strncmp(StartStrings[i],
+
+ /* Process line after \r\n */
+ if (d->Msg.Length > 0 && rx_char == 10 && d->Msg.Buffer[d->Msg.Length - 2] == 13) {
+ /* Process standard responses */
+ for (i = 0; StatusStrings[i] != NULL; i++) {
+ if (strncmp(StatusStrings[i],
d->Msg.Buffer + d->LineStart,
- strlen(StartStrings[i])) == 0) {
+ strlen(StatusStrings[i])) == 0) {
s->Phone.Data.RequestMsg = &d->Msg;
s->Phone.Data.DispatchError = s->Phone.Functions->DispatchMessage(s);
d->Msg.Length = 0;
break;
}
- i++;
}
/* Generally hack for A2D */
if (d->CPINNoOK) {
@@ -187,13 +197,12 @@ static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
s->Phone.Data.RequestMsg = &d->Msg;
s->Phone.Data.DispatchError = s->Phone.Functions->DispatchMessage(s);
d->Msg.Length = 0;
+ break;
}
}
- if (d->Msg.Length == 0)
- break;
- i = 0;
- while (SpecialAnswers[i].text != NULL) {
+ /* Check for incoming frames */
+ for (i = 0; SpecialAnswers[i].text != NULL; i++) {
if (strncmp(SpecialAnswers[i].text,
d->Msg.Buffer + d->LineStart,
strlen(SpecialAnswers[i].text)) == 0) {
@@ -210,14 +219,13 @@ static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
d->SpecialAnswerStart = d->LineStart;
d->SpecialAnswerLines = SpecialAnswers[i].lines;
}
- i++;
}
-
+ /* Last line of incoming frame */
if (d->SpecialAnswerLines == 1) {
/* This is end of special answer. We copy it and send to phone module */
Msg2.Buffer = (unsigned char *)malloc(d->LineEnd - d->SpecialAnswerStart + 3);
- memcpy(Msg2.Buffer,d->Msg.Buffer+d->SpecialAnswerStart,d->LineEnd - d->SpecialAnswerStart + 2);
+ memcpy(Msg2. Buffer, d->Msg.Buffer + d->SpecialAnswerStart, d->LineEnd - d->SpecialAnswerStart + 2);
Msg2.Length = d->LineEnd - d->SpecialAnswerStart + 2;
Msg2.Buffer[Msg2.Length] = '\0';
Msg2.Type = 0;
@@ -225,7 +233,7 @@ static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
s->Phone.Data.RequestMsg = &Msg2;
s->Phone.Data.DispatchError = s->Phone.Functions->DispatchMessage(s);
free(Msg2.Buffer);
- Msg2.Buffer=NULL;
+ Msg2.Buffer = NULL;
/* We cut special answer from main buffer */
d->Msg.Length = d->SpecialAnswerStart;
@@ -236,8 +244,8 @@ static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
/* We need to find earlier values of all variables */
d->wascrlf = FALSE;
d->LineStart = 0;
- for (i=0;i<d->Msg.Length;i++) {
- switch(d->Msg.Buffer[i]) {
+ for (i = 0;i < d->Msg.Length; i++) {
+ switch (d->Msg.Buffer[i]) {
case 0:
break;
case 10:
@@ -256,24 +264,26 @@ static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
}
d->Msg.Buffer[d->Msg.Length] = 0;
}
- if (d->SpecialAnswerLines > 0) d->SpecialAnswerLines--;
+ if (d->SpecialAnswerLines > 0) {
+ d->SpecialAnswerLines--;
+ }
}
break;
case 'T':
/* When CONNECT string received, we know there will not follow
* anything AT related, after CONNECT can follow ppp data, alcabus
- * data and also other things.
- */
- if (strncmp(d->Msg.Buffer+d->LineStart, "CONNECT", 7) == 0) {
- s->Phone.Data.RequestMsg = &d->Msg;
- s->Phone.Data.DispatchError = s->Phone.Functions->DispatchMessage(s);
- d->LineStart = -1;
+ * data and also other things.
+ */
+ if (strncmp(d->Msg.Buffer + d->LineStart, "CONNECT", 7) == 0) {
+ s->Phone.Data.RequestMsg = &d->Msg;
+ s->Phone.Data.DispatchError = s->Phone.Functions->DispatchMessage(s);
+ d->LineStart = -1;
d->Msg.Length = 0;
- break;
- }
+ break;
+ }
default:
if (d->wascrlf) {
- d->LineStart = d->Msg.Length-1;
+ d->LineStart = d->Msg.Length - 1;
d->wascrlf = FALSE;
}
if (d->EditMode) {
@@ -287,7 +297,7 @@ static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
return ERR_NONE;
}
-static GSM_Error AT_Initialise(GSM_StateMachine *s)
+GSM_Error AT_Initialise(GSM_StateMachine *s)
{
GSM_Protocol_ATData *d = &s->Protocol.Data.AT;
GSM_Error error;
diff --git a/libgammu/protocol/at/at.h b/libgammu/protocol/at/at.h
index 632b40b..606d76f 100644
--- a/libgammu/protocol/at/at.h
+++ b/libgammu/protocol/at/at.h
@@ -5,11 +5,14 @@
#include "../protocol.h"
+GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char);
+GSM_Error AT_Initialise(GSM_StateMachine *s);
+
typedef struct {
GSM_Protocol_Message Msg;
gboolean wascrlf;
- int LineStart,LineEnd;
- int SpecialAnswerLines,SpecialAnswerStart;
+ size_t LineStart, LineEnd;
+ size_t SpecialAnswerLines, SpecialAnswerStart;
gboolean EditMode; /* wait for modem answer or not */
gboolean FastWrite;
diff --git a/libgammu/service/backup/backtext.c b/libgammu/service/backup/backtext.c
index a908b84..99d2f89 100644
--- a/libgammu/service/backup/backtext.c
+++ b/libgammu/service/backup/backtext.c
@@ -1854,7 +1854,9 @@ static void ReadPbkEntry(INI_Section *file_info, char *section, GSM_MemoryEntry
}
sprintf(buffer,"Entry%02iType",num);
readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
- if (strcasecmp(readvalue,"NumberGeneral") == 0) {
+ if (readvalue == NULL) {
+ Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Other;
+ } else if (strcasecmp(readvalue,"NumberGeneral") == 0) {
Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_General;
} else if (strcasecmp(readvalue,"NumberVideo") == 0) {
Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Video;
@@ -2074,8 +2076,10 @@ loadpicture:
if (readvalue != NULL) {
/* We allocate here more memory than is actually required */
Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = (char *)malloc(strlen(readvalue));
- if (Pbk->Entries[Pbk->EntriesNum].Picture.Buffer == NULL)
+ if (Pbk->Entries[Pbk->EntriesNum].Picture.Buffer == NULL) {
+ free(readvalue);
break;
+ }
Pbk->Entries[Pbk->EntriesNum].Picture.Length =
DecodeBASE64(readvalue, Pbk->Entries[Pbk->EntriesNum].Picture.Buffer, strlen(readvalue));
@@ -2100,8 +2104,12 @@ loadtext:
Pbk->Entries[Pbk->EntriesNum].SMSList[i] = 0;
sprintf(buffer,"Entry%02iSMSList%02i",num,i);
readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
- if (readvalue==NULL) break;
+ if (readvalue==NULL) {
+ free(readvalue);
+ break;
+ }
Pbk->Entries[Pbk->EntriesNum].SMSList[i] = atoi(readvalue);
+ free(readvalue);
i++;
}
loaddone:
@@ -3020,7 +3028,9 @@ static void ReadProfileEntry(INI_Section *file_info, char *section, GSM_Profile
if (!unknown) {
sprintf(buffer,"Value%02i",num);
readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
- if (strcasecmp(readvalue,"Level1") == 0) {
+ if (readvalue == NULL) {
+ Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VOLUME_LEVEL1;
+ } else if (strcasecmp(readvalue,"Level1") == 0) {
Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VOLUME_LEVEL1;
if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_KeypadTone) {
Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_KEYPAD_LEVEL1;
@@ -3232,9 +3242,15 @@ GSM_Error LoadBackup(const char *FileName, GSM_Backup *backup)
}
readvalue = ReadCFGText(file_info, buffer, "IMEI", UseUnicode);
- if (readvalue!=NULL) strcpy(backup->IMEI,readvalue);
+ if (readvalue!=NULL) {
+ strncpy(backup->IMEI, readvalue, sizeof(backup->IMEI) - 1);
+ backup->IMEI[sizeof(backup->IMEI) - 1] = 0;
+ }
readvalue = ReadCFGText(file_info, buffer, "Phone", UseUnicode);
- if (readvalue!=NULL) strcpy(backup->Model,readvalue);
+ if (readvalue!=NULL) {
+ strncpy(backup->Model, readvalue, sizeof(backup->Model) - 1);
+ backup->Model[sizeof(backup->Model) - 1] = 0;
+ }
readvalue = ReadCFGText(file_info, buffer, "Creator", UseUnicode);
if (readvalue!=NULL) {
strncpy(backup->Creator,readvalue, sizeof(backup->Creator) - 1);
@@ -4002,11 +4018,17 @@ GSM_Error SaveTextComment(FILE *file, unsigned char *comment)
static GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
{
int i=0;
- unsigned char buffer[10000]={0};
+ unsigned char *buffer;
const char *s;
GSM_DateTime DT;
GSM_Error error;
+ buffer = malloc(10000);
+ if (buffer == NULL) {
+ return ERR_MOREMEMORY;
+ }
+ buffer[0] = 0;
+
fprintf(file, BACKUP_MAIN_HEADER "\n");
fprintf(file, BACKUP_INFO_HEADER "\n");
GSM_GetCurrentDateTime (&DT);
@@ -4023,14 +4045,20 @@ static GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
case SMS_Coding_Unicode_No_Compression:
case SMS_Coding_Default_No_Compression:
error = SaveTextComment(file, backup->SMS[i]->Text);
- if (error != ERR_NONE) return error;
+ if (error != ERR_NONE) {
+ free(buffer);
+ return error;
+ }
break;
default:
break;
}
if (backup->SMS[i]->PDU == SMS_Deliver) {
error = SaveBackupText(file, "SMSC", backup->SMS[i]->SMSC.Number, FALSE);
- if (error != ERR_NONE) return error;
+ if (error != ERR_NONE) {
+ free(buffer);
+ return error;
+ }
if (backup->SMS[i]->ReplyViaSameSMSC) {
fprintf(file,"SMSCReply = TRUE\n");
}
@@ -4043,7 +4071,10 @@ static GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
if (backup->SMS[i]->DateTime.Year != 0) {
fprintf(file,"DateTime");
error = SaveVCalDateTime(file,&backup->SMS[i]->DateTime, FALSE);
- if (error != ERR_NONE) return error;
+ if (error != ERR_NONE) {
+ free(buffer);
+ return error;
+ }
}
fprintf(file,"State = ");
switch (backup->SMS[i]->State) {
@@ -4053,9 +4084,15 @@ static GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
case SMS_UnSent : fprintf(file,"UnSent\n"); break;
}
error = SaveBackupText(file, "Number", backup->SMS[i]->Number, FALSE);
- if (error != ERR_NONE) return error;
+ if (error != ERR_NONE) {
+ free(buffer);
+ return error;
+ }
error = SaveBackupText(file, "Name", backup->SMS[i]->Name, FALSE);
- if (error != ERR_NONE) return error;
+ if (error != ERR_NONE) {
+ free(buffer);
+ return error;
+ }
if (backup->SMS[i]->UDH.Type != UDH_NoUDH) {
EncodeHexBin(buffer,backup->SMS[i]->UDH.Text,backup->SMS[i]->UDH.Length);
fprintf(file,"UDH = %s\n",buffer);
@@ -4084,6 +4121,7 @@ static GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
fprintf(file,"\n");
i++;
}
+ free(buffer);
return ERR_NONE;
}
diff --git a/libgammu/service/gsmdata.c b/libgammu/service/gsmdata.c
index 829752b..9ff5998 100644
--- a/libgammu/service/gsmdata.c
+++ b/libgammu/service/gsmdata.c
@@ -389,7 +389,7 @@ void GSM_EncodeMMSIndicatorSMSText(unsigned char *Buffer, size_t *Length, GSM_MM
Buffer[(*Length)++] = 0x89;
sprintf(buffer,"%s/TYPE=PLMN",Indicator->Sender);
/* Field size */
- Buffer[(*Length)++] = strlen(buffer) + 2;
+ Buffer[(*Length)++] = (unsigned char)(strlen(buffer) + 2);
/* Sender address is present */
Buffer[(*Length)++] = 0x80;
strcpy(Buffer+(*Length),buffer);
diff --git a/libgammu/service/sms/gsmmulti.c b/libgammu/service/sms/gsmmulti.c
index 34a21c1..5cb826b 100644
--- a/libgammu/service/sms/gsmmulti.c
+++ b/libgammu/service/sms/gsmmulti.c
@@ -751,14 +751,8 @@ GSM_Error GSM_EncodeMultiPartSMS(GSM_Debug_Info *di,
break;
case SMS_NokiaVCARD10Long:
Coding = SMS_Coding_Default_No_Compression;
- /* is 1 SMS ? 8 = length of ..SCKE2 */
- if (Length<=GSM_MAX_SMS_CHARS_LENGTH-8) {
- sprintf(Buffer,"//SCKE2 ");
- Length = 8;
- } else {
- UDH = UDH_NokiaPhonebookLong;
- }
- error = GSM_EncodeVCARD(di, Buffer, buffer_size, &Length,Info->Entries[0].Phonebook,TRUE,Nokia_VCard10);
+ UDH = UDH_NokiaPhonebookLong;
+ error = GSM_EncodeVCARD(di, Buffer, buffer_size, &Length, Info->Entries[0].Phonebook, TRUE, Nokia_VCard10);
if (error != ERR_NONE) {
goto out;
}
@@ -766,18 +760,12 @@ GSM_Error GSM_EncodeMultiPartSMS(GSM_Debug_Info *di,
EncodeUnicode(Buffer,Buffer2,Length);
break;
case SMS_NokiaVCARD21Long:
- error = GSM_EncodeVCARD(di, Buffer, buffer_size, &Length,Info->Entries[0].Phonebook,TRUE,Nokia_VCard21);
+ error = GSM_EncodeVCARD(di, Buffer, buffer_size, &Length, Info->Entries[0].Phonebook, TRUE, Nokia_VCard21);
if (error != ERR_NONE) {
goto out;
}
Coding = SMS_Coding_Default_No_Compression;
- /* Is 1 SMS ? 12 = length of ..SCKL23F4 */
- if (Length <= GSM_MAX_SMS_CHARS_LENGTH - 12) {
- sprintf(Buffer,"//SCKL23F4%c%c",13,10);
- Length = 12;
- } else {
- UDH = UDH_NokiaPhonebookLong;
- }
+ UDH = UDH_NokiaPhonebookLong;
memcpy(Buffer2,Buffer,Length);
EncodeUnicode(Buffer,Buffer2,Length);
break;