---
 src/service.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 87 insertions(+), 1 deletions(-)

diff --git a/src/service.c b/src/service.c
index 18c11f4..2787c3a 100644
--- a/src/service.c
+++ b/src/service.c
@@ -719,13 +719,85 @@ static gboolean get_conversation_get_args(DBusMessage 
*dbus_msg,
        return TRUE;
 }

+static gboolean is_recipient(const char *recipients, const char *number)
+{
+       const char *rec, *num;
+
+       while (*recipients != '\0') {
+               rec = recipients;
+               num = number;
+
+               while (*rec != '\0' && *num != '\0') {
+                       if (*rec == *num) {
+                               rec++;
+                               num++;
+                       } else {
+                               if (*rec == '-' || *rec == '.') {
+                                       rec++;
+                                       continue;
+                               }
+
+                               if (*num == '-' || *num == '.') {
+                                       num++;
+                                       continue;
+                               }
+
+                               rec++;
+                               break;
+                       }
+               }
+
+               /*
+                * Phone numbers in recipients end with /TYPE=PLMN, so the
+                * wanted number is found if the whole string number is found
+                * and if the matched phone number ends with the wanted number
+                * (i.e.: "/TYPE=PLMN" must follow).
+                */
+               if (*num == '\0' && *rec == '/')
+                       return TRUE;
+
+               recipients = rec;
+       }
+
+       return FALSE;
+}
+
+static GList *fill_conversation(const struct mms_service *service,
+                               GList *conversation, const char *number)
+{
+       GHashTableIter table_iter;
+       gpointer key, value;
+
+       g_hash_table_iter_init(&table_iter, service->messages);
+       while (g_hash_table_iter_next(&table_iter, &key, &value)) {
+               struct mms_message *msg = value;
+               char *recipients;
+
+               if (msg->type == MMS_MESSAGE_TYPE_SEND_REQ)
+                       recipients = msg->sr.to;
+               else if (msg->type == MMS_MESSAGE_TYPE_RETRIEVE_CONF)
+                       recipients = msg->rc.from;
+               else
+                       continue;
+
+               if (is_recipient(recipients, number) == TRUE)
+                       conversation = g_list_prepend(conversation, value);
+       }
+
+       return conversation;
+}
+
 static DBusMessage *get_conversation(DBusConnection *conn,
                                        DBusMessage *dbus_msg, void *data)
 {
        DBusMessage *reply;
        DBusMessageIter iter, array;
+       const struct mms_service *service = data;
+       struct mms_message *msg;
+       GList *msg_elt = NULL;
+       GList *conversation = NULL;
        const char *number;
-       unsigned int count;
+       unsigned int count, i;

        if (get_conversation_get_args(dbus_msg, &number, &count) == FALSE) {
                mms_debug("Invalid arguments");
@@ -742,6 +814,20 @@ static DBusMessage *get_conversation(DBusConnection *conn,
        dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
                                                        "(oa{sv})", &array);

+       conversation = fill_conversation(service, conversation, number);
+       if (conversation == NULL)
+               goto out;
+
+       i = 0;
+
+       for (msg_elt = g_list_first(conversation); msg_elt != NULL;
+                                       msg_elt = g_list_next(msg_elt), i++) {
+               if (count != 0 && i == count)
+                       break;
+               msg = msg_elt->data;
+               append_message_entry(msg->path, service, msg, &array);
+       }
+out:
        dbus_message_iter_close_container(&iter, &array);

        return reply;
--
1.7.4.1

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to