summaryrefslogtreecommitdiff
path: root/smsd
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2010-06-03 11:55:51 +0200
committerMichal Čihař <michal@cihar.com>2010-06-03 11:55:51 +0200
commit9e9e58b0758e385940418ad8b412a6a77d45941e (patch)
tree4468003cd66ccaba3e81fe04080c7b0df905e507 /smsd
parent241730d63b033e865af4880a544bef455de6e6bb (diff)
Imported Upstream version 1.27.94
Diffstat (limited to 'smsd')
-rw-r--r--smsd/core.c91
-rw-r--r--smsd/core.h2
-rw-r--r--smsd/services/files.c35
3 files changed, 80 insertions, 48 deletions
diff --git a/smsd/core.c b/smsd/core.c
index 65edb91..3813bf6 100644
--- a/smsd/core.c
+++ b/smsd/core.c
@@ -1207,6 +1207,63 @@ GSM_Error SMSD_ProcessSMS(GSM_SMSDConfig *Config, GSM_SMSDService *Service, GSM_
}
/**
+ * Checks whether to process current (possibly) multipart message.
+ */
+gboolean SMSD_CheckMultipart(GSM_SMSDConfig *Config, GSM_SMSDService *Service, GSM_MultiSMSMessage *MultiSMS)
+{
+ gboolean same_id;
+ /* Does the message have UDH (is multipart)? */
+ if (MultiSMS->SMS[0].UDH.Type != UDH_NoUDH) {
+ return TRUE;
+ }
+
+ /* Do we have same id as last incomplete? */
+ same_id = (Config->IncompleteMessageID == MultiSMS->SMS[0].UDH.ID16bit || Config->IncompleteMessageID == MultiSMS->SMS[0].UDH.ID8bit);
+
+ /* Check if we have all parts */
+ if (MultiSMS->SMS[0].UDH.AllParts != MultiSMS->Number) {
+ goto success;
+ }
+
+
+ /* Have we seen this message recently? */
+ if (same_id) {
+ if (Config->IncompleteMessageTime != 0 && difftime(time(NULL), Config->IncompleteMessageTime) > Config->multiparttimeout) {
+ SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, processing after timeout",
+ Config->IncompleteMessageID);
+ } else {
+ SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, waiting for other parts (waited %.0f seconds)",
+ Config->IncompleteMessageID,
+ difftime(time(NULL), Config->IncompleteMessageTime));
+ return FALSE;
+ }
+ } else {
+ if (Config->IncompleteMessageTime == 0) {
+ if (MultiSMS->SMS[0].UDH.ID16bit != -1) {
+ Config->IncompleteMessageID = MultiSMS->SMS[0].UDH.ID16bit;
+ } else {
+ Config->IncompleteMessageID = MultiSMS->SMS[0].UDH.ID8bit;
+ }
+ Config->IncompleteMessageTime = time(NULL);
+ SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, waiting for other parts",
+ Config->IncompleteMessageID);
+ return FALSE;
+ } else {
+ SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, but waiting for other one",
+ Config->IncompleteMessageID);
+ return FALSE;
+ }
+ }
+
+success:
+ /* Clean multipart wait flag */
+ if (same_id) {
+ Config->IncompleteMessageTime = 0;
+ }
+ return TRUE;
+}
+
+/**
* Reads message from phone, processes it and delete it from phone afterwards.
*
* It tries to link multipart messages together if possible.
@@ -1275,43 +1332,17 @@ gboolean SMSD_ReadDeleteSMS(GSM_SMSDConfig *Config, GSM_SMSDService *Service)
error = GSM_LinkSMS(GSM_GetDebug(Config->gsm), GetSMSData, SortedSMS, TRUE);
/* Free memory */
- i=0;
- while (GetSMSData[i] != NULL) {
+ for (i = 0; GetSMSData[i] != NULL; i++) {
free(GetSMSData[i]);
GetSMSData[i] = NULL;
- i++;
}
free(GetSMSData);
/* Process messages */
- i=0;
-
for (i = 0; SortedSMS[i] != NULL; i++) {
- /* Check if we have all parts */
- if (SortedSMS[i]->SMS[0].UDH.Type != UDH_NoUDH) {
- if (SortedSMS[i]->SMS[0].UDH.AllParts != SortedSMS[i]->Number) {
- if (Config->IncompleteMessageTime != 0 && (Config->IncompleteMessageID == SortedSMS[i]->SMS[0].UDH.ID16bit || Config->IncompleteMessageID == SortedSMS[i]->SMS[0].UDH.ID8bit) && difftime(time(NULL), Config->IncompleteMessageTime) > Config->multiparttimeout) {
- SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, processing after timeout",
- Config->IncompleteMessageID);
- } else {
- if (Config->IncompleteMessageTime == 0) {
- if (SortedSMS[i]->SMS[0].UDH.ID16bit != -1) {
- Config->IncompleteMessageID = SortedSMS[i]->SMS[0].UDH.ID16bit;
- } else {
- Config->IncompleteMessageID = SortedSMS[i]->SMS[0].UDH.ID8bit;
- }
- Config->IncompleteMessageTime = time(NULL);
- }
- SMSD_Log(DEBUG_INFO, Config, "Incomplete multipart message 0x%02X, waiting for other parts (waited %.0f seconds)",
- Config->IncompleteMessageID, difftime(time(NULL), Config->IncompleteMessageTime));
- goto cleanup;
- }
- }
- }
-
- /* Clean multipart wait flag */
- if (Config->IncompleteMessageID == SortedSMS[i]->SMS[0].UDH.ID16bit || Config->IncompleteMessageID == SortedSMS[i]->SMS[0].UDH.ID8bit) {
- Config->IncompleteMessageTime = 0;
+ /* Check multipart message parts */
+ if (!SMSD_CheckMultipart(Config, Service, SortedSMS[i])) {
+ goto cleanup;
}
/* Actually process the message */
diff --git a/smsd/core.h b/smsd/core.h
index a8a64f3..4d4aeba 100644
--- a/smsd/core.h
+++ b/smsd/core.h
@@ -165,7 +165,7 @@ struct _GSM_SMSDConfig {
/**
* Multipart messages processing.
*/
- unsigned char IncompleteMessageID;
+ int IncompleteMessageID;
time_t IncompleteMessageTime;
#ifdef HAVE_SHM
diff --git a/smsd/services/files.c b/smsd/services/files.c
index 1ec64ee..a54d923 100644
--- a/smsd/services/files.c
+++ b/smsd/services/files.c
@@ -472,17 +472,22 @@ static GSM_Error SMSDFiles_MoveSMS(GSM_MultiSMSMessage *sms UNUSED,
/* Adds SMS to Outbox */
static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, char *NewID)
{
- GSM_Error error = ERR_NONE;
int i,j;
unsigned char FileName[100], FullName[400], ext[17], buffer[64],buffer2[400];
FILE *file;
+ time_t rawtime;
+ struct tm* timeinfo;
+
#ifdef GSM_ENABLE_BACKUP
+ GSM_Error error;
GSM_SMS_Backup backup;
#endif
j = 0;
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
- for (i=0;i<sms->Number;i++) {
+ for (i = 0; i < sms->Number; i++) {
if (strcasecmp(Config->outboxformat, "detail") == 0) {
strcpy(ext, "smsbackup");
} else {
@@ -492,12 +497,6 @@ static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon
file = NULL;
do {
- time_t rawtime;
- struct tm* timeinfo;
-
- time(&rawtime);
- timeinfo = localtime(&rawtime);
-
sprintf(FileName,
"OUTC%04d%02d%02d_%02d%02d%02d_00_%s_sms%d.%s",
1900 + timeinfo->tm_year,
@@ -511,7 +510,7 @@ static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon
strcat(FullName, FileName);
if (file) fclose(file);
file = fopen(FullName, "r");
- } while ((i == 0) && file != NULL && (++j < 100));
+ } while (file != NULL && (++j < 100));
if (file) {
fclose(file);
@@ -531,7 +530,13 @@ static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon
}
backup.SMS[sms->Number] = NULL;
error = GSM_AddSMSBackupFile(FullName, &backup);
+
+ if (error != ERR_NONE) {
+ return error;
+ }
#endif
+ /* Force leaving the loop */
+ i = sms->Number;
} else {
file = fopen(FullName, "wb");
if (file == NULL) {
@@ -541,28 +546,24 @@ static GSM_Error SMSDFiles_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDCon
switch (sms->SMS[i].Coding) {
case SMS_Coding_Unicode_No_Compression:
case SMS_Coding_Default_No_Compression:
- DecodeUnicode(sms->SMS[i].Text,buffer2);
if (strcasecmp(Config->outboxformat, "unicode") == 0) {
buffer[0] = 0xFE;
buffer[1] = 0xFF;
chk_fwrite(buffer,1,2,file);
- chk_fwrite(sms->SMS[i].Text,1,strlen(buffer2)*2,file);
+ chk_fwrite(sms->SMS[i].Text, 1, UnicodeLength(sms->SMS[i].Text) * 2, file);
} else {
- chk_fwrite(buffer2,1,strlen(buffer2),file);
+ DecodeUnicode(sms->SMS[i].Text, buffer2);
+ chk_fwrite(buffer2, 1, strlen(buffer2), file);
}
break;
case SMS_Coding_8bit:
- chk_fwrite(sms->SMS[i].Text,1,(size_t)sms->SMS[i].Length,file);
+ chk_fwrite(sms->SMS[i].Text, 1, (size_t)sms->SMS[i].Length, file);
default:
break;
}
fclose(file);
}
- if (error != ERR_NONE) {
- return error;
- }
-
SMSD_Log(DEBUG_INFO, Config, "Created outbox message %s", FileName);
}