Write state of SMS assembly to disk and restore on startup.
This way we can continue receiving segmented messages over a reset or crash.
--- src/common.c | 29 +++++++ src/common.h | 10 +++ src/sim.c | 34 -------- src/sms.c | 14 +++- src/smsutil.c | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/smsutil.h | 3 +- unit/Makefile.am | 6 +- unit/test-sms.c | 4 +- 8 files changed, 293 insertions(+), 44 deletions(-)
src/common.c +29 -0
@@ -26,6 +26,7 @@#define _GNU_SOURCE#include <string.h> #include <ctype.h> +#include <errno.h> #include <glib.h>
@@ -593,3 +594,31 @@ gboolean is_valid_pin(const char *pin)return TRUE; } + +int create_dirs (const char *filename,const mode_t mode) +{ +struct stat st; +char *dir; +const char *prev, *next; +int err; + + err =stat (filename, &st); +if (!err &&S_ISREG (st.st_mode)) +return 0 ; + + dir =g_malloc (strlen (filename) +1 ); +strcpy (dir,"/" ); + +for (prev = filename; (next =strchr (prev +1 ,'/' )); prev = next) +if (next > prev +1 ) { +strncat (dir, prev +1 , next - prev); + +if (mkdir (dir, mode) && errno !=EEXIST ) { +g_free (dir); +return -1 ; + } + } + +g_free (dir); +return 0 ; +}
src/common.h +10 -0
@@ -135,3 +135,13 @@ const char *ss_control_type_to_string(enum ss_control_type type);const char *bearer_class_to_string (enum bearer_class cls);gboolean is_valid_pin (const char *pin); + +#ifdef TEMP_FAILURE_RETRY +#define TFR TEMP_FAILURE_RETRY +#else +#define TFR +#endif + +#include <fcntl.h> + +int create_dirs (const char *filename,const mode_t mode);
src/sim.c +0 -34
@@ -44,12 +44,6 @@#include "sim.h" #include "simutil.h" -#ifdef TEMP_FAILURE_RETRY -#define TFR TEMP_FAILURE_RETRY -#else -#define TFR -#endif -#define SIM_MANAGER_INTERFACE "org.ofono.SimManager"#define SIM_CACHE_MODE 0600
@@ -515,34 +509,6 @@ static void sim_retrieve_imsi(struct ofono_modem *modem) sim->ops->read_imsi (modem, sim_imsi_cb, modem); } -static int create_dirs (const char *filename,const mode_t mode) -{ -struct stat st; -char *dir; -const char *prev, *next; -int err; - - err =stat (filename, &st); -if (!err &&S_ISREG (st.st_mode)) -return 0 ; - - dir =g_malloc (strlen (filename) +1 ); -strcpy (dir,"/" ); - -for (prev = filename; (next =strchr (prev +1 ,'/' )); prev = next) -if (next > prev +1 ) { -strncat (dir, prev +1 , next - prev); - -if (mkdir (dir, mode) && errno !=EEXIST ) { -g_free (dir); -return -1 ; - } - } - -g_free (dir); -return 0 ; -} -static void sim_op_error (struct ofono_modem *modem) {struct sim_manager_data *sim = modem->sim_manager;
src/sms.c +13 -1
@@ -72,7 +72,6 @@ static struct sms_manager_data *sms_manager_create() sms->sca.type =129 ; sms->ref =1 ; - sms->assembly =sms_assembly_new (); sms->txq =g_queue_new ();return sms;
@@ -792,6 +791,14 @@ void ofono_sms_status_notify(struct ofono_modem *modem, unsigned char *pdu,ofono_error ("SMS Status-Report not yet handled" ); } +static void sms_got_imsi (struct ofono_modem *modem) +{ +const char *imsi =ofono_sim_get_imsi (modem); +struct sms_manager_data *sms = modem->sms_manager; + + sms->assembly =sms_assembly_new (imsi); +} +int ofono_sms_manager_register (struct ofono_modem *modem,struct ofono_sms_ops *ops) {
@@ -830,6 +837,11 @@ int ofono_sms_manager_register(struct ofono_modem *modem,ofono_modem_add_interface (modem,SMS_MANAGER_INTERFACE ); +if (ofono_sim_get_ready (modem)) +sms_got_imsi (modem); +else +ofono_sim_ready_notify_register (modem, sms_got_imsi); +return 0 ; }
src/smsutil.c +233 -4
276 lines not on this page · raw message
src/smsutil.h +2 -1
@@ -360,6 +360,7 @@ struct sms_assembly_node { };struct sms_assembly { +const char *imsi;GSList *assembly_list; };
@@ -454,7 +455,7 @@ gboolean sms_extract_concatenation(const struct sms *sms, guint16 *ref_num,unsigned char *sms_decode_datagram (GSList *sms_list,long *out_len);char *sms_decode_text (GSList *sms_list); -struct sms_assembly *sms_assembly_new (); +struct sms_assembly *sms_assembly_new (const char *imsi);void sms_assembly_free (struct sms_assembly *assembly); GSList *sms_assembly_add_fragment(struct sms_assembly *assembly, const struct sms *sms, time_t ts,
unit/Makefile.am +4 -2
@@ -6,11 +6,13 @@ test_common_SOURCES = test-common.c $(top_srcdir)/src/common.c test_util_SOURCES = test-util.c $(top_srcdir)/src/util.c test_sms_SOURCES = test-sms.c $(top_srcdir)/src/util.c \ - $(top_srcdir)/src/smsutil.c + $(top_srcdir)/src/smsutil.c \ + $(top_srcdir)/src/common.c test_simutil_SOURCES = test-simutil.c $(top_srcdir)/src/util.c \ $(top_srcdir)/src/simutil.c \ - $(top_srcdir)/src/smsutil.c + $(top_srcdir)/src/smsutil.c \ + $(top_srcdir)/src/common.c LDADD = @GLIB_LIBS@ @GTHREAD_LIBS@
unit/test-sms.c +2 -2
@@ -619,7 +619,7 @@ static void test_assembly()unsigned char pdu[164 ];long pdu_len;struct sms sms; -struct sms_assembly *assembly =sms_assembly_new (); +struct sms_assembly *assembly =sms_assembly_new (NULL );guint16 ref;guint8 max;guint8 seq;
@@ -776,7 +776,7 @@ static void test_prepare_concat()struct sms *sms;struct sms decoded;int pdu_len, tpdu_len; -struct sms_assembly *assembly =sms_assembly_new (); +struct sms_assembly *assembly =sms_assembly_new (NULL );guint16 ref;guint8 max;guint8 seq;
Signature · 1 line
1.6.1
Hi Andrew,
Quoted 15 lines · Andrzej Zaborowski
This way we can continue receiving segmented messages over a reset or crash.
--- src/common.c | 29 +++++++ src/common.h | 10 +++ src/sim.c | 34 -------- src/sms.c | 14 +++- src/smsutil.c | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/smsutil.h | 3 +- unit/Makefile.am | 6 +- unit/test-sms.c | 4 +- 8 files changed, 293 insertions(+), 44 deletions(-)
Somehow this patch fell through the cracks completely. Can you rebase and resend?
src/common.c gboolean is_valid_pin(const char *pin) · line 599
Quoted 4 lines
src/common.c +3
-0+ +int create_dirs (const char *filename,const mode_t mode) +{
Can we move this part to storage.c instead of common.c to be more consistent with connman & bluez?
src/common.h const char *ss_control_type_to_string(enum ss_control_type type); · line 147
Quoted 11 lines
src/common.h +10
-0+ +#ifdef TEMP_FAILURE_RETRY +#define TFR TEMP_FAILURE_RETRY +#else +#define TFR +#endif + +#include <fcntl.h> + +int create_dirs (const char *filename,const mode_t mode);
storage.c as well.
Quoted 7 lines
+static GSList *sms_assembly_add_fragment_backup(struct
sms_assembly*assembly,src/smsutil.c +3
-0+ const struct sms *sms, time_t ts, + const struct sms_address *addr, + guint16 ref, guint8 max, guint8seq,
src/smsutil.c char *sms_decode_text(GSList *sms_list) · line 2148
Quoted 8 lines
src/smsutil.c +8
-0+ gboolean backup); + +#define SMS_BACKUP_MODE 0600 +#define SMS_BACKUP_PATH STORAGEDIR "/%s/sms" +#define SMS_BACKUP_PATH_DIR SMS_BACKUP_PATH "/%s-%i-%i" +#define SMS_BACKUP_PATH_FILE SMS_BACKUP_PATH_DIR "/%03i" + +#define SMS_ADDR_FMT "%21[0-9+*#]"
These really belong at the top of the file. Includes, Defines, globals, forward declarations, structure definitions in that order.
src/smsutil.c char *sms_decode_text(GSList *sms_list) · line 2184
Quoted 6 lines
src/smsutil.c +5
-0+ +static void sms_assembly_load (struct sms_assembly *assembly, +const struct dirent *dir) +{ +for (; len--;free (segments[len])) {
Please don't do such evilness. I don't even understand how this can work.
src/smsutil.c char *sms_decode_text(GSList *sms_list) · line 2206
Quoted 13 lines
src/smsutil.c +12
-0+ fd =TFR (open (path,O_RDONLY )); +g_free (path); + +if (fd ==-1 ) +continue ; + +if (fstat (fd, &segment_stat) !=0 ) { +TFR (close (fd)); +continue ; + } + + r =TFR (read (fd, buf,sizeof (buf)));
This part should be a utility function in storage.c. We repeat almost the same code in sim.c
Review
Quoted 10 lines
src/smsutil.c +6
-0+ +if (r >0 &&sms_deserialize (buf, &segment, r)) { + if (sms_assembly_add_fragment_backup(assembly, + &segment, + segment_stat.st_mtime, + &addr, ref, max, seq,FALSE)) {
(quoted diff) +2
-0+ /* This can't happen */ + }
We read it from the backup store and almost immediately overwrite the backup store? Seems inefficient.
Quoted 11 lines
src/smsutil.c +10
-0+if (create_dirs (path,SMS_BACKUP_MODE |S_IXUSR )) { +g_free (path); +return FALSE; + } + + fd =TFR (open (path,O_WRONLY |O_CREAT ,SMS_BACKUP_MODE )); +if (fd ==-1 ) { +g_free (path); +return FALSE; + }
src/smsutil.c char *sms_decode_text(GSList *sms_list) · line 2260
Quoted 10 lines
src/smsutil.c +10
-0+ +if (TFR (write (fd, buf, len)) < len) { +TFR (close (fd)); +unlink (path); +g_free (path); +return FALSE; + } + +g_free (path); +TFR (close (fd));
Again, sounds like this should be a utility function in storage.c
Regards,
-Denis
2009/9/1 Denis Kenzior <[email protected]>:
Quoted 17 lines
Quoted 14 lines · Andrzej Zaborowski
This way we can continue receiving segmented messages over a reset or crash.
---
src/common.c | 29 +++++++
src/common.h | 10 +++
src/sim.c | 34 --------
src/sms.c | 14 +++-
src/smsutil.c | 237
+++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/smsutil.h | 3 +-
unit/Makefile.am | 6 +-
unit/test-sms.c | 4 +-8 files changed, 293 insertions(+), 44 deletions(-)
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+int create_dirs(const char *filename, const mode_t mode) +{Can we move this part to
storage.cinstead ofcommon.cto be more consistent with connman & bluez?
Ok, I moved the common part of the file reading / writing to storage.c but some of the file access in sim.c is still doing it manually because there's lseeking in the middle.
Quoted 10 lines
Quoted 9 lines
+
+ if (r > 0 &&sms_deserialize(buf, &segment, r)) {
+ if (sms_assembly_add_fragment_backup(assembly,
+ &segment,
+ segment_stat.st_mtime,
+ &addr, ref, max, seq, FALSE)) {
+ /* This can't happen */
+ }
Quoted 2 lines
We read it from the backup store and almost immediately overwrite the backup store? Seems inefficient.
The FALSE in the last parameter tells the function not to write the backup, I had renamed the function to sms_assembly_add_fragment_backup and made a wrapper under the old name. I agree the naming is poor.
Sending updated patches in attachments.
Regards
From f986a17536dca707ba6294d17efa3c2907e8f147 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 5 Sep 2009 03:12:19 +0200
Subject: [PATCH 1/2] Move create_dirs to storage.c, add file read/write utilities
--- Makefile.am | 2 +- src/sim.c | 69 ++----------------------------- src/storage.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/storage.h | 36 ++++++++++++++++ 4 files changed, 166 insertions(+), 66 deletions(-) create mode 100644 src/storage.c create mode 100644 src/storage.h
Makefile.am +1 -1
@@ -140,7 +140,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) \ src/call-meter.c src/smsutil.h src/smsutil.c \ src/ssn.c src/call-barring.c src/sim.c \ src/phonebook.c src/history.c src/message-waiting.c \ - src/simutil.h src/simutil.c + src/simutil.h src/simutil.c src/storage.h src/storage.c src_ofonod_LDADD = $(builtin_libadd) \ @GLIB_LIBS@ @GTHREAD_LIBS@ @DBUS_LIBS@ -ldl
src/sim.c +4 -65
99 lines not on this page · raw message
src/storage.c new file +125 -0
125 lines not on this page · raw message
src/storage.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* +* oFono - Open Source Telephony +* +* Copyright (C) 2008-2009 Intel Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +#ifdef TEMP_FAILURE_RETRY +#define TFR TEMP_FAILURE_RETRY +#else +#define TFR +#endif + +#include <fcntl.h> + +int create_dirs (const char *filename,const mode_t mode); + +ssize_t read_file (unsigned char *buffer,size_t len, +const char *path_fmt, ...); + +ssize_t write_file (const unsigned char *buffer,size_t len,mode_t mode, +const char *path_fmt, ...);
Signature · 1 line
1.6.1
From 39ebf0ce647ea37f937028d491b5a530a3074068 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 5 Sep 2009 03:16:02 +0200
Subject: [PATCH 2/2] Write state of SMS assembly to disk and restore on startup.
This way we can continue receiving segmented messages over a reset or crash.
--- Makefile.am | 5 +- src/common.c | 1 + src/sms.c | 58 +++++++++++++++- src/smsutil.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/smsutil.h | 3 +- unit/test-sms.c | 4 +- 6 files changed, 276 insertions(+), 9 deletions(-)
Makefile.am +3 -2
@@ -204,12 +204,13 @@ unit_test_util_SOURCES = unit/test-util.c src/util.c unit_test_util_LDADD = @GLIB_LIBS@ unit_objects += $(unit_test_utils_OBJECTS) -unit_test_sms_SOURCES = unit/test-sms.c src/util.c src/smsutil.c +unit_test_sms_SOURCES = unit/test-sms.c src/util.c src/smsutil.c src/storage.c unit_test_sms_LDADD = @GLIB_LIBS@ unit_objects += $(unit_test_sms_OBJECTS) unit_test_simutil_SOURCES = unit/test-simutil.c src/util.c \ - src/simutil.c src/smsutil.c + src/simutil.c src/smsutil.c \ + src/storage.c unit_test_simutil_LDADD = @GLIB_LIBS@ unit_objects += $(unit_test_simutil_OBJECTS)
src/common.c +1 -0
@@ -26,6 +26,7 @@#define _GNU_SOURCE#include <string.h> #include <ctype.h> +#include <errno.h> #include <glib.h>
src/sms.c +57 -1
94 lines not on this page · raw message
src/smsutil.c +211 -3
259 lines not on this page · raw message
src/smsutil.h +2 -1
@@ -360,6 +360,7 @@ struct sms_assembly_node { };struct sms_assembly { +const char *imsi;GSList *assembly_list; };
@@ -454,7 +455,7 @@ gboolean sms_extract_concatenation(const struct sms *sms, guint16 *ref_num,unsigned char *sms_decode_datagram (GSList *sms_list,long *out_len);char *sms_decode_text (GSList *sms_list); -struct sms_assembly *sms_assembly_new (); +struct sms_assembly *sms_assembly_new (const char *imsi);void sms_assembly_free (struct sms_assembly *assembly); GSList *sms_assembly_add_fragment(struct sms_assembly *assembly, const struct sms *sms, time_t ts,
unit/test-sms.c +2 -2
@@ -619,7 +619,7 @@ static void test_assembly()unsigned char pdu[164 ];long pdu_len;struct sms sms; -struct sms_assembly *assembly =sms_assembly_new (); +struct sms_assembly *assembly =sms_assembly_new (NULL );guint16 ref;guint8 max;guint8 seq;
@@ -776,7 +776,7 @@ static void test_prepare_concat()struct sms *sms;struct sms decoded;int pdu_len, tpdu_len; -struct sms_assembly *assembly =sms_assembly_new (); +struct sms_assembly *assembly =sms_assembly_new (NULL );guint16 ref;guint8 max;guint8 seq;
Signature · 1 line
1.6.1
Hi Andrew,
Both patches have been applied.
I had to fix up a few things in order to make this actually work. Please review the changes and make sure they're OK with you.
Thanks,
-Denis
Hi,
2009/9/8 Denis Kenzior <[email protected]>:
Quoted 4 lines
Both patches have been applied.
I had to fix up a few things in order to make this actually work. Please review the changes and make sure they're OK with you.
Yes, all of the changes make a lot of sense, thanks.
Regards