Open Source Telephony
 help / color / mirror / Atom feed
From: Ronald Tessier <ronald.tessier@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCHv1 3/5] service: Fill conversation list with messages
Date: Wed, 25 Apr 2012 11:01:51 +0200	[thread overview]
Message-ID: <1335344513-2347-4-git-send-email-ronald.tessier@linux.intel.com> (raw)
In-Reply-To: <1335344513-2347-1-git-send-email-ronald.tessier@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 3043 bytes --]

---
 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


  parent reply	other threads:[~2012-04-25  9:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-25  9:01 [PATCHv1 0/5] mmsd: GetConversation support Ronald Tessier
2012-04-25  9:01 ` [PATCHv1 1/5] service: Add GetConversation method Ronald Tessier
2012-04-27 12:26   ` Marcel Holtmann
2012-04-25  9:01 ` [PATCHv1 2/5] service: Retrieve get_conversation() args Ronald Tessier
2012-04-27 12:25   ` Marcel Holtmann
2012-04-25  9:01 ` Ronald Tessier [this message]
2012-04-27 12:25   ` [PATCHv1 3/5] service: Fill conversation list with messages Marcel Holtmann
2012-04-25  9:01 ` [PATCHv1 4/5] service: Sort conversation list by message date Ronald Tessier
2012-04-27 12:23   ` Marcel Holtmann
2012-04-25  9:01 ` [PATCHv1 5/5] doc: Update service-api.txt Ronald Tessier
2012-04-27 12:20   ` Marcel Holtmann
2012-04-27 13:30     ` Ronald Tessier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1335344513-2347-4-git-send-email-ronald.tessier@linux.intel.com \
    --to=ronald.tessier@linux.intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox