* [PATCH v3 1/3] sms: store pending tx pdus on disk
2011-01-28 2:39 [PATCH v3 0/3] Persist TX SMS messages Lucas De Marchi
@ 2011-01-28 2:39 ` Lucas De Marchi
2011-01-28 2:39 ` [PATCH v3 2/3] sms: delete sent sms messages from backup Lucas De Marchi
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Lucas De Marchi @ 2011-01-28 2:39 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3622 bytes --]
Based on patch from Kristen Carlson Accardi <kristen@linux.intel.com>
---
src/sms.c | 21 +++++++++++++++++++++
src/smsutil.c | 29 +++++++++++++++++++++++++++++
src/smsutil.h | 4 ++++
3 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/src/sms.c b/src/sms.c
index 7224bdf..87283d3 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -65,6 +65,7 @@ struct ofono_sms {
struct sms_assembly *assembly;
guint ref;
GQueue *txq;
+ unsigned long tx_counter;
guint tx_source;
struct ofono_message_waiting *mw;
unsigned int mw_watch;
@@ -103,6 +104,7 @@ struct tx_queue_entry {
ofono_sms_txq_submit_cb_t cb;
void *data;
ofono_destroy_func destroy;
+ unsigned long id;
};
static gboolean uuid_equal(gconstpointer v1, gconstpointer v2)
@@ -1814,6 +1816,8 @@ int __ofono_sms_txq_submit(struct ofono_sms *sms, GSList *list,
sms->ref = sms->ref + 1;
}
+ entry->id = sms->tx_counter++;
+
g_queue_push_tail(sms->txq, entry);
if (sms->registered && g_queue_get_length(sms->txq) == 1)
@@ -1822,6 +1826,23 @@ int __ofono_sms_txq_submit(struct ofono_sms *sms, GSList *list,
if (uuid)
memcpy(uuid, &entry->uuid, sizeof(*uuid));
+ if (flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) {
+ const char *uuid_str;
+ unsigned char i;
+
+ uuid_str = ofono_uuid_to_str(&entry->uuid);
+
+ for (i = 0; i < entry->num_pdus; i++) {
+ struct pending_pdu *pdu;
+
+ pdu = &entry->pdus[i];
+
+ sms_tx_backup_store(sms->imsi, entry->id, entry->flags,
+ uuid_str, i, pdu->pdu,
+ pdu->pdu_len, pdu->tpdu_len);
+ }
+ }
+
if (cb)
cb(sms, &entry->uuid, data);
diff --git a/src/smsutil.c b/src/smsutil.c
index 3a54fe6..3e5b7cd 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -48,6 +48,10 @@
#define SMS_SR_BACKUP_PATH STORAGEDIR "/%s/sms_sr"
#define SMS_SR_BACKUP_PATH_FILE SMS_SR_BACKUP_PATH "/%s-%s"
+#define SMS_TX_BACKUP_PATH STORAGEDIR "/%s/tx_queue"
+#define SMS_TX_BACKUP_PATH_DIR SMS_TX_BACKUP_PATH "/%lu-%lu-%s"
+#define SMS_TX_BACKUP_PATH_FILE SMS_TX_BACKUP_PATH_DIR "/%03i"
+
#define SMS_ADDR_FMT "%24[0-9A-F]"
#define SMS_MSGID_FMT "%40[0-9A-F]"
@@ -3143,6 +3147,31 @@ void status_report_assembly_expire(struct status_report_assembly *assembly,
}
}
+gboolean sms_tx_backup_store(const char *imsi, unsigned long id,
+ unsigned long flags, const char *uuid,
+ guint8 seq, const unsigned char *pdu,
+ int pdu_len, int tpdu_len)
+{
+ unsigned char buf[177];
+ int len;
+
+ if (!imsi)
+ return FALSE;
+
+ memcpy(buf + 1, pdu, pdu_len);
+ buf[0] = tpdu_len;
+ len = pdu_len + 1;
+
+ /*
+ * file name is: imsi/tx_queue/order-flags-uuid/pdu
+ */
+ if (write_file(buf, len, SMS_BACKUP_MODE, SMS_TX_BACKUP_PATH_FILE,
+ imsi, id, flags, uuid, seq) != len)
+ return FALSE;
+
+ return TRUE;
+}
+
static inline GSList *sms_list_append(GSList *l, const struct sms *in)
{
struct sms *sms;
diff --git a/src/smsutil.h b/src/smsutil.h
index dd65884..2ae35d7 100644
--- a/src/smsutil.h
+++ b/src/smsutil.h
@@ -517,6 +517,10 @@ void status_report_assembly_add_fragment(struct status_report_assembly
void status_report_assembly_expire(struct status_report_assembly *assembly,
time_t before);
+gboolean sms_tx_backup_store(const char *imsi, unsigned long id,
+ unsigned long flags, const char *uuid,
+ guint8 seq, const unsigned char *pdu,
+ int pdu_len, int tpdu_len);
GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
gboolean use_16bit,
gboolean use_delivery_reports);
--
1.7.3.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 2/3] sms: delete sent sms messages from backup
2011-01-28 2:39 [PATCH v3 0/3] Persist TX SMS messages Lucas De Marchi
2011-01-28 2:39 ` [PATCH v3 1/3] sms: store pending tx pdus on disk Lucas De Marchi
@ 2011-01-28 2:39 ` Lucas De Marchi
2011-01-28 2:39 ` [PATCH v3 3/3] sms: restore pending tx " Lucas De Marchi
2011-01-29 2:38 ` [PATCH v3 0/3] Persist TX SMS messages Denis Kenzior
3 siblings, 0 replies; 5+ messages in thread
From: Lucas De Marchi @ 2011-01-28 2:39 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3006 bytes --]
Based on patch from Kristen Carlson Accardi <kristen@linux.intel.com>
---
src/sms.c | 8 ++++++++
src/smsutil.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
src/smsutil.h | 6 ++++++
3 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/src/sms.c b/src/sms.c
index 87283d3..2fe67c8 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -571,6 +571,11 @@ static void tx_finished(const struct ofono_error *error, int mr, void *data)
goto next_q;
}
+ if (entry->flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS)
+ sms_tx_backup_remove(sms->imsi, entry->id, entry->flags,
+ ofono_uuid_to_str(&entry->uuid),
+ entry->cur_pdu);
+
entry->cur_pdu += 1;
entry->retry = 0;
@@ -607,6 +612,9 @@ next_q:
if (entry->flags & OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS) {
enum message_state ms;
+ sms_tx_backup_free(sms->imsi, entry->id, entry->flags,
+ ofono_uuid_to_str(&entry->uuid));
+
if (ok)
ms = MESSAGE_STATE_SENT;
else
diff --git a/src/smsutil.c b/src/smsutil.c
index 3e5b7cd..db6881e 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -3172,6 +3172,53 @@ gboolean sms_tx_backup_store(const char *imsi, unsigned long id,
return TRUE;
}
+void sms_tx_backup_free(const char *imsi, unsigned long id,
+ unsigned long flags, const char *uuid)
+{
+ char *path;
+ struct dirent **entries;
+ int len;
+
+ path = g_strdup_printf(SMS_TX_BACKUP_PATH_DIR,
+ imsi, id, flags, uuid);
+
+ len = scandir(path, &entries, NULL, versionsort);
+
+ if (len < 0)
+ return;
+
+ /* skip '..' and '.' entries */
+ while (len-- > 2) {
+ struct dirent *dir = entries[len];
+ char *file = g_strdup_printf("%s/%s", path, dir->d_name);
+
+ unlink(file);
+ g_free(file);
+
+ g_free(entries[len]);
+ }
+
+ g_free(entries[1]);
+ g_free(entries[0]);
+ g_free(entries);
+
+ rmdir(path);
+ g_free(path);
+}
+
+void sms_tx_backup_remove(const char *imsi, unsigned long id,
+ unsigned long flags, const char *uuid,
+ guint8 seq)
+{
+ char *path;
+
+ path = g_strdup_printf(SMS_TX_BACKUP_PATH_FILE,
+ imsi, id, flags, uuid, seq);
+ unlink(path);
+
+ g_free(path);
+}
+
static inline GSList *sms_list_append(GSList *l, const struct sms *in)
{
struct sms *sms;
diff --git a/src/smsutil.h b/src/smsutil.h
index 2ae35d7..615b380 100644
--- a/src/smsutil.h
+++ b/src/smsutil.h
@@ -521,6 +521,12 @@ gboolean sms_tx_backup_store(const char *imsi, unsigned long id,
unsigned long flags, const char *uuid,
guint8 seq, const unsigned char *pdu,
int pdu_len, int tpdu_len);
+void sms_tx_backup_remove(const char *imsi, unsigned long id,
+ unsigned long flags, const char *uuid,
+ guint8 seq);
+void sms_tx_backup_free(const char *imsi, unsigned long id,
+ unsigned long flags, const char *uuid);
+
GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
gboolean use_16bit,
gboolean use_delivery_reports);
--
1.7.3.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 3/3] sms: restore pending tx messages from backup
2011-01-28 2:39 [PATCH v3 0/3] Persist TX SMS messages Lucas De Marchi
2011-01-28 2:39 ` [PATCH v3 1/3] sms: store pending tx pdus on disk Lucas De Marchi
2011-01-28 2:39 ` [PATCH v3 2/3] sms: delete sent sms messages from backup Lucas De Marchi
@ 2011-01-28 2:39 ` Lucas De Marchi
2011-01-29 2:38 ` [PATCH v3 0/3] Persist TX SMS messages Denis Kenzior
3 siblings, 0 replies; 5+ messages in thread
From: Lucas De Marchi @ 2011-01-28 2:39 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 8176 bytes --]
Based on patch from: Kristen Carlson Accardi <kristen@linux.intel.com>
---
src/ofono.h | 1 +
src/sms.c | 62 +++++++++++++++++++
src/smsutil.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/smsutil.h | 7 ++
4 files changed, 251 insertions(+), 0 deletions(-)
diff --git a/src/ofono.h b/src/ofono.h
index df20103..6ba0187 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -245,6 +245,7 @@ enum ofono_sms_submit_flag {
OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY = 0x2,
OFONO_SMS_SUBMIT_FLAG_RETRY = 0x4,
OFONO_SMS_SUBMIT_FLAG_EXPOSE_DBUS = 0x8,
+ OFONO_SMS_SUBMIT_FLAG_REUSE_UUID = 0x10,
};
typedef void (*ofono_sms_txq_submit_cb_t)(gboolean ok, void *data);
diff --git a/src/sms.c b/src/sms.c
index 2fe67c8..eb2f215 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -798,6 +798,9 @@ static struct tx_queue_entry *tx_queue_entry_new(GSList *msg_list,
pdu->pdu_len, pdu->tpdu_len);
}
+ if (flags & OFONO_SMS_SUBMIT_FLAG_REUSE_UUID)
+ return entry;
+
if (sms_uuid_from_pdus(entry->pdus, entry->num_pdus, &entry->uuid))
return entry;
@@ -1694,6 +1697,63 @@ static void bearer_init_callback(const struct ofono_error *error, void *data)
ofono_error("Error bootstrapping SMS Bearer Preference");
}
+static void sms_restore_tx_queue(struct ofono_sms *sms)
+{
+ GQueue *backupq;
+ struct txq_backup_entry *backup_entry;
+
+ DBG("");
+
+ backupq = sms_tx_queue_load(sms->imsi);
+
+ if (backupq == NULL)
+ return;
+
+ while ((backup_entry = g_queue_pop_head(backupq))) {
+ struct message *m;
+ struct tx_queue_entry *txq_entry;
+
+ backup_entry->flags |= OFONO_SMS_SUBMIT_FLAG_REUSE_UUID;
+ txq_entry = tx_queue_entry_new(backup_entry->msg_list,
+ backup_entry->flags);
+ if (txq_entry == NULL)
+ goto loop_out;
+
+ txq_entry->flags &= ~OFONO_SMS_SUBMIT_FLAG_REUSE_UUID;
+ memcpy(&txq_entry->uuid.uuid, &backup_entry->uuid,
+ SMS_MSGID_LEN);
+
+ m = message_create(&txq_entry->uuid, sms->atom);
+ if (m == NULL) {
+ tx_queue_entry_destroy(txq_entry);
+
+ goto loop_out;
+ }
+
+ if (message_dbus_register(m) == FALSE) {
+ tx_queue_entry_destroy(txq_entry);
+
+ goto loop_out;
+ }
+
+ message_set_data(m, txq_entry);
+ g_hash_table_insert(sms->messages, &txq_entry->uuid, m);
+
+ txq_entry->id = sms->tx_counter++;
+ g_queue_push_tail(sms->txq, txq_entry);
+
+loop_out:
+ g_slist_foreach(backup_entry->msg_list, (GFunc)g_free, NULL);
+ g_slist_free(backup_entry->msg_list);
+ g_free(backup_entry);
+ }
+
+ if (g_queue_get_length(sms->txq) > 0)
+ sms->tx_source = g_timeout_add(0, tx_next, sms);
+
+ g_queue_free(backupq);
+}
+
/*
* Indicate oFono that a SMS driver is ready for operation
*
@@ -1766,6 +1826,8 @@ void ofono_sms_register(struct ofono_sms *sms)
sms->driver->bearer_set(sms, sms->bearer,
bearer_init_callback, sms);
+ sms_restore_tx_queue(sms);
+
sms->text_handlers = __ofono_watchlist_new(g_free);
sms->datagram_handlers = __ofono_watchlist_new(g_free);
diff --git a/src/smsutil.c b/src/smsutil.c
index db6881e..97e695e 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -2327,6 +2327,15 @@ static gboolean sms_deserialize(const unsigned char *buf,
return sms_decode(buf + 1, len - 1, FALSE, buf[0], sms);
}
+static gboolean sms_deserialize_outgoing(const unsigned char *buf,
+ struct sms *sms, int len)
+{
+ if (len < 1)
+ return FALSE;
+
+ return sms_decode(buf + 1, len - 1, TRUE, buf[0], sms);
+}
+
static gboolean sms_assembly_extract_address(const char *straddr,
struct sms_address *out)
{
@@ -3147,6 +3156,178 @@ void status_report_assembly_expire(struct status_report_assembly *assembly,
}
}
+static int sms_tx_load_filter(const struct dirent *dent)
+{
+ char *endp;
+ guint8 seq;
+
+ if (dent->d_type != DT_REG)
+ return 0;
+
+ seq = strtol(dent->d_name, &endp, 10);
+
+ if (*endp != '\0')
+ return 0;
+
+ return 1;
+}
+
+/*
+ * Each directory contains a file per pdu.
+ */
+static GSList *sms_tx_load(const char *imsi, const struct dirent *dir)
+{
+ GSList *list = NULL;
+ struct dirent **pdus;
+ char *path;
+ int len, r;
+ unsigned char buf[177];
+ struct sms s;
+
+ if (dir->d_type != DT_DIR)
+ return NULL;
+
+ path = g_strdup_printf(SMS_TX_BACKUP_PATH "/%s", imsi, dir->d_name);
+ len = scandir(path, &pdus, sms_tx_load_filter, versionsort);
+ g_free(path);
+
+ if (len < 0)
+ return NULL;
+
+ while (len--) {
+ r = read_file(buf, sizeof(buf), SMS_TX_BACKUP_PATH "/%s/%s",
+ imsi, dir->d_name, pdus[len]->d_name);
+
+ if (r < 0)
+ goto free_pdu;
+
+ if (sms_deserialize_outgoing(buf, &s, r) == FALSE)
+ goto free_pdu;
+
+ list = g_slist_prepend(list, g_memdup(&s, sizeof(s)));
+
+free_pdu:
+ g_free(pdus[len]);
+ }
+
+ g_free(pdus);
+
+ return list;
+}
+
+static int sms_tx_queue_filter(const struct dirent *dirent)
+{
+ if (dirent->d_type != DT_DIR)
+ return 0;
+
+ if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, ".."))
+ return 0;
+
+ return 1;
+}
+
+/*
+ * populate the queue with tx_backup_entry from stored backup
+ * data.
+ */
+GQueue *sms_tx_queue_load(const char *imsi)
+{
+ char *path;
+ GQueue *retq;
+ struct dirent **entries;
+ int len;
+
+ if (imsi == NULL)
+ return NULL;
+
+ path = g_strdup_printf(SMS_TX_BACKUP_PATH, imsi);
+ if (path == NULL)
+ goto nomem_path;
+
+ retq = g_queue_new();
+ if (retq == NULL)
+ goto nomem_retq;
+
+ len = scandir(path, &entries, sms_tx_queue_filter, versionsort);
+
+ if (len < 0)
+ goto nodir_exit;
+
+ while (len--) {
+ char uuid[SMS_MSGID_LEN * 2 + 1];
+ GSList *msg_list;
+ unsigned long flags;
+ char *oldpath, *newpath;
+ struct txq_backup_entry *entry;
+ struct dirent *dir = entries[len];
+ char endc;
+ unsigned long i;
+
+ if (sscanf(dir->d_name, "%*u-%lu-" SMS_MSGID_FMT "%c",
+ &flags, uuid, &endc) != 2)
+ goto err_free_dir;
+
+ if (strlen(uuid) != 2 * SMS_MSGID_LEN)
+ goto err_free_dir;
+
+ entry = g_try_new0(struct txq_backup_entry, 1);
+ if (entry == NULL)
+ goto err_free_dir;
+
+ oldpath = g_strdup_printf("%s/%s", path, dir->d_name);
+ if (oldpath == NULL)
+ goto err_free_entry;
+
+ i = len;
+ newpath = g_strdup_printf(SMS_TX_BACKUP_PATH_DIR,
+ imsi, i, flags, uuid);
+ if (newpath == NULL)
+ goto err_free_oldpath;
+
+ msg_list = sms_tx_load(imsi, dir);
+ if (msg_list == NULL)
+ goto err_free_newpath;
+
+ entry->msg_list = msg_list;
+ entry->flags = flags;
+ decode_hex_own_buf(uuid, -1, NULL, 0, entry->uuid);
+
+ g_queue_push_head(retq, entry);
+
+ /* rename directory to reflect new position in queue */
+ rename(oldpath, newpath);
+
+ g_free(dir);
+ g_free(newpath);
+ g_free(oldpath);
+
+ continue;
+
+err_free_newpath:
+ g_free(newpath);
+err_free_oldpath:
+ g_free(oldpath);
+err_free_entry:
+ g_free(entry);
+err_free_dir:
+ g_free(dir);
+ }
+
+ g_free(entries);
+ g_free(path);
+
+ return retq;
+
+nodir_exit:
+ g_queue_free(retq);
+
+nomem_retq:
+ g_free(path);
+
+nomem_path:
+ return NULL;
+}
+
gboolean sms_tx_backup_store(const char *imsi, unsigned long id,
unsigned long flags, const char *uuid,
guint8 seq, const unsigned char *pdu,
diff --git a/src/smsutil.h b/src/smsutil.h
index 615b380..16b5350 100644
--- a/src/smsutil.h
+++ b/src/smsutil.h
@@ -408,6 +408,12 @@ struct cbs_topic_range {
unsigned short max;
};
+struct txq_backup_entry {
+ GSList *msg_list;
+ unsigned char uuid[SMS_MSGID_LEN];
+ unsigned long flags;
+};
+
static inline gboolean is_bit_set(unsigned char oct, int bit)
{
int mask = 0x1 << bit;
@@ -526,6 +532,7 @@ void sms_tx_backup_remove(const char *imsi, unsigned long id,
guint8 seq);
void sms_tx_backup_free(const char *imsi, unsigned long id,
unsigned long flags, const char *uuid);
+GQueue *sms_tx_queue_load(const char *imsi);
GSList *sms_text_prepare(const char *to, const char *utf8, guint16 ref,
gboolean use_16bit,
--
1.7.3.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v3 0/3] Persist TX SMS messages
2011-01-28 2:39 [PATCH v3 0/3] Persist TX SMS messages Lucas De Marchi
` (2 preceding siblings ...)
2011-01-28 2:39 ` [PATCH v3 3/3] sms: restore pending tx " Lucas De Marchi
@ 2011-01-29 2:38 ` Denis Kenzior
3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2011-01-29 2:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 983 bytes --]
Hi Lucas,
On 01/27/2011 08:39 PM, Lucas De Marchi wrote:
> Third version. It includes some changes suggested by Denis:
>
> - Get rid of the oldpath field in struct txq_backup_entry
> - Store the encoded uuid in struct txq_backup_entry
> - Use SMS_MSGID_FMT to get the file name
> - Some more cleanups
>
> Lucas De Marchi (3):
> sms: store pending tx pdus on disk
> sms: delete sent sms messages from backup
> sms: restore pending tx messages from backup
>
> src/ofono.h | 1 +
> src/sms.c | 91 ++++++++++++++++++++
> src/smsutil.c | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> src/smsutil.h | 17 ++++
> 4 files changed, 366 insertions(+), 0 deletions(-)
>
I applied all three patches but refactored patch 3 afterwards. In my
testing everything seems to be working nicely and I went ahead and
marked the TODO item as done. Please review my changes to make sure I
didn't break anything.
Regards,
-Denis
^ permalink raw reply [flat|nested] 5+ messages in thread