Hi Ronald, On 08/24/2012 08:06 AM, Ronald Tessier wrote: > --- > src/service.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 107 insertions(+), 4 deletions(-) > > diff --git a/src/service.c b/src/service.c > index b3ecc1e..44184cb 100644 > --- a/src/service.c > +++ b/src/service.c > @@ -1300,6 +1300,104 @@ static void emit_service_removed(struct mms_service *service) > &service->path, DBUS_TYPE_INVALID); > } > > +static gboolean get_meta_by_msgid(struct mms_service *service, > + const char *msgid, > + char *uuid) > +{ > + GDir *dir; > + GKeyFile *meta; > + const char *file; > + const char *homedir; > + const char *service_id; > + char *service_path; > + > + homedir = g_get_home_dir(); > + if (homedir == NULL) > + return FALSE; > + > + service_id = service->identity; > + > + service_path = g_strdup_printf("%s/.mms/%s/", homedir, service_id); > + > + dir = g_dir_open(service_path, 0, NULL); > + g_free(service_path); > + if (dir == NULL) > + return FALSE; > + > + while ((file = g_dir_read_name(dir)) != NULL) { > + char *id; > + > + if (g_str_has_suffix(file, MMS_META_UUID_SUFFIX) == FALSE) > + continue; > + > + if (strlen(file) != MMS_META_UUID_LEN + > + MMS_META_UUID_SUFFIX_LEN) > + continue; > + > + strncpy(uuid, file, MMS_META_UUID_LEN); > + uuid[MMS_META_UUID_LEN] = 0; > + > + meta = mms_store_meta_open(service_id, uuid); > + if (meta == NULL) > + goto bail; > + > + id = g_key_file_get_string(meta, "info", "id", NULL); > + if (id == NULL) { > + mms_store_meta_close(service_id, uuid, meta, FALSE); > + continue; > + } > + > + if (g_strcmp0(msgid, id) == 0) { > + mms_store_meta_close(service_id, uuid, meta, FALSE); > + g_dir_close(dir); > + return TRUE; > + } > + > + mms_store_meta_close(service_id, uuid, meta, FALSE); > + } > + > +bail: > + g_dir_close(dir); > + > + return FALSE; > +} > + > +static void process_delivery_ind_notification(struct mms_service *service, > + struct mms_message *di_msg) > +{ > + GKeyFile *meta; > + char uuid[MMS_META_UUID_LEN + 1]; > + char *path; > + char *to; > + > + if (get_meta_by_msgid(service, di_msg->di.msgid, uuid) == FALSE) > + goto bail; > + > + meta = mms_store_meta_open(service->identity, uuid); > + if (meta == NULL) > + return; > + > + to = g_strdup(di_msg->di.to); > + > + mms_address_to_string(to); > + > + g_key_file_set_string(meta, "delivery_status", to, > + delivery_status[di_msg->di.dr_status - 127]); > + > + g_free(to); > + > + mms_store_meta_close(service->identity, uuid, meta, TRUE); > + > + path = g_strdup_printf("%s/%s/%s", MMS_PATH, service->identity, uuid); > + > + g_free(path); > + > +bail: > + mms_store_remove(service->identity, di_msg->uuid); > + > + mms_message_free(di_msg); > +} > + > static gboolean load_message_from_store(const char *service_id, > const char *uuid, struct mms_message *msg) > { > @@ -1485,6 +1583,7 @@ register_sr: > } > } else if (msg->type == MMS_MESSAGE_TYPE_DELIVERY_IND) { > request = NULL; > + process_delivery_ind_notification(service, msg); > } else > request = NULL; > > @@ -1514,15 +1613,17 @@ static void load_messages(struct mms_service *service) > return; > > while ((file = g_dir_read_name(dir)) != NULL) { > - const size_t suffix_len = 7; > char *uuid; > + size_t uuid_len; > > - if (g_str_has_suffix(file, ".status") == FALSE) > + if (g_str_has_suffix(file, MMS_META_UUID_SUFFIX) == FALSE) > continue; > - if (strlen(file) - suffix_len == 0) > + > + uuid_len = strlen(file) - MMS_META_UUID_SUFFIX_LEN; > + if (uuid_len == 0) > continue; > > - uuid = g_strndup(file, strlen(file) - suffix_len); > + uuid = g_strndup(file, uuid_len); > > process_message_on_start(service, uuid); > This chunk should really be in a separate patch since it is related to the previous one. > @@ -2401,6 +2502,8 @@ void mms_service_push_notify(struct mms_service *service, > > mms_store_meta_close(service->identity, uuid, meta, TRUE); > > + process_delivery_ind_notification(service, msg); > + > return; > } > Regards, -Denis