All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 0/4] mmsd: GetConversation support
@ 2012-05-03 13:19 Ronald Tessier
  2012-05-03 13:20 ` [PATCHv2 1/4] service: Retrieve get_conversation() args Ronald Tessier
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Ronald Tessier @ 2012-05-03 13:19 UTC (permalink / raw)
  To: ofono

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

These patches concern mmsd and implement "GetConversation" D-Bus API.

Ronald Tessier (4):
  service: Retrieve get_conversation() args
  service: Fill conversation list with messages
  service: Sort conversation list by message date
  doc: Update service-api.txt

 doc/service-api.txt |    6 ++
 src/service.c       |  141 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+), 0 deletions(-)

--
1.7.4.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCHv2 1/4] service: Retrieve get_conversation() args
  2012-05-03 13:19 [PATCHv2 0/4] mmsd: GetConversation support Ronald Tessier
@ 2012-05-03 13:20 ` Ronald Tessier
  2012-05-03 13:20 ` [PATCHv2 2/4] service: Fill conversation list with messages Ronald Tessier
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Ronald Tessier @ 2012-05-03 13:20 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/service.c b/src/service.c
index 689a4e1..a8e818a 100644
--- a/src/service.c
+++ b/src/service.c
@@ -703,6 +703,29 @@ static DBusMessage *get_conversation(DBusConnection *conn,
 {
 	DBusMessage *reply;
 	DBusMessageIter iter, array;
+	const char *number;
+	unsigned int count;
+
+	if (dbus_message_iter_init(dbus_msg, &iter) == FALSE)
+		return __mms_error_invalid_args(dbus_msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return __mms_error_invalid_args(dbus_msg);
+
+	dbus_message_iter_get_basic(&iter, &number);
+	if (number[0] == '\0')
+		return __mms_error_invalid_args(dbus_msg);
+
+	if (valid_number_format(number) == FALSE)
+		return __mms_error_invalid_args(dbus_msg);
+
+	if (!dbus_message_iter_next(&iter))
+		return __mms_error_invalid_args(dbus_msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
+		return __mms_error_invalid_args(dbus_msg);
+
+	dbus_message_iter_get_basic(&iter, &count);

 	reply = dbus_message_new_method_return(dbus_msg);
 	if (reply == NULL)
--
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCHv2 2/4] service: Fill conversation list with messages
  2012-05-03 13:19 [PATCHv2 0/4] mmsd: GetConversation support Ronald Tessier
  2012-05-03 13:20 ` [PATCHv2 1/4] service: Retrieve get_conversation() args Ronald Tessier
@ 2012-05-03 13:20 ` Ronald Tessier
  2012-05-03 13:20 ` [PATCHv2 3/4] service: Sort conversation list by message date Ronald Tessier
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Ronald Tessier @ 2012-05-03 13:20 UTC (permalink / raw)
  To: ofono

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

Fill a GList with all messages of a conversation based on number param.
A message is a member of a conversation if the given number belongs to
its recipients list (this is what is_recipient() checks).
'-' and '.' are valid chars in a phone number but they have to be
ignored during checking. To be eligible, a message must have the number
in recipients list AND the number must ends the matched recipient in the
recipients list (ex: a message with "+33612345678/TYPE=PLMN" in its
recipients is member of a conversation where the given number is
"12345678" BUT not if the given number is "1234567").

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

diff --git a/src/service.c b/src/service.c
index a8e818a..93beceb 100644
--- a/src/service.c
+++ b/src/service.c
@@ -698,13 +698,91 @@ static DBusMessage *get_messages(DBusConnection *conn,
 	return reply;
 }

+static gboolean is_recipient(const char *recipients, const char *number)
+{
+	const char *subrecpts, *subnum;
+
+	/*
+	 * Search for "number" substring in "recipients" string,
+	 * ignoring '-' and '.' which are valid chars in a phone number
+	 */
+	while (*recipients != '\0') {
+		subrecpts = recipients;
+		subnum = number;
+
+		while (*subrecpts != '\0' && *subnum != '\0') {
+			if (*subrecpts == *subnum) {
+				subrecpts++;
+				subnum++;
+			} else {
+				if (*subrecpts == '-' || *subrecpts == '.') {
+					subrecpts++;
+					continue;
+				}
+
+				if (*subnum == '-' || *subnum == '.') {
+					subnum++;
+					continue;
+				}
+
+				if (*subrecpts != *number)
+					subrecpts++;
+
+				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 (*subnum == '\0' && *subrecpts == '/')
+			return TRUE;
+
+		recipients = subrecpts;
+	}
+
+	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 (dbus_message_iter_init(dbus_msg, &iter) == FALSE)
 		return __mms_error_invalid_args(dbus_msg);
@@ -736,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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCHv2 3/4] service: Sort conversation list by message date
  2012-05-03 13:19 [PATCHv2 0/4] mmsd: GetConversation support Ronald Tessier
  2012-05-03 13:20 ` [PATCHv2 1/4] service: Retrieve get_conversation() args Ronald Tessier
  2012-05-03 13:20 ` [PATCHv2 2/4] service: Fill conversation list with messages Ronald Tessier
@ 2012-05-03 13:20 ` Ronald Tessier
  2012-05-03 13:20 ` [PATCHv2 4/4] doc: Update service-api.txt Ronald Tessier
  2012-05-09 17:22 ` [PATCHv2 0/4] mmsd: GetConversation support Marcel Holtmann
  4 siblings, 0 replies; 6+ messages in thread
From: Ronald Tessier @ 2012-05-03 13:20 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/service.c b/src/service.c
index 93beceb..6bcdede 100644
--- a/src/service.c
+++ b/src/service.c
@@ -698,6 +698,31 @@ static DBusMessage *get_messages(DBusConnection *conn,
 	return reply;
 }

+static gint fill_conversation_sort(gconstpointer a, gconstpointer b)
+{
+	const struct mms_message *msg1 = a;
+	const struct mms_message *msg2 = b;
+	time_t date1, date2;
+
+	if (msg1->type == MMS_MESSAGE_TYPE_SEND_REQ)
+		date1 = msg1->sr.date;
+	else
+		date1 = msg1->rc.date;
+
+	if (msg2->type == MMS_MESSAGE_TYPE_SEND_REQ)
+		date2 = msg2->sr.date;
+	else
+		date2 = msg2->rc.date;
+
+	if (date1 > date2)
+		return 1;
+
+	if (date1 < date2)
+		return -1;
+
+	return 0;
+}
+
 static gboolean is_recipient(const char *recipients, const char *number)
 {
 	const char *subrecpts, *subnum;
@@ -766,7 +791,8 @@ static GList *fill_conversation(const struct mms_service *service,
 			continue;

 		if (is_recipient(recipients, number) == TRUE)
-			conversation = g_list_prepend(conversation, value);
+			conversation = g_list_insert_sorted(conversation, value,
+							fill_conversation_sort);
 	}

 	return conversation;
--
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCHv2 4/4] doc: Update service-api.txt
  2012-05-03 13:19 [PATCHv2 0/4] mmsd: GetConversation support Ronald Tessier
                   ` (2 preceding siblings ...)
  2012-05-03 13:20 ` [PATCHv2 3/4] service: Sort conversation list by message date Ronald Tessier
@ 2012-05-03 13:20 ` Ronald Tessier
  2012-05-09 17:22 ` [PATCHv2 0/4] mmsd: GetConversation support Marcel Holtmann
  4 siblings, 0 replies; 6+ messages in thread
From: Ronald Tessier @ 2012-05-03 13:20 UTC (permalink / raw)
  To: ofono

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

---
 doc/service-api.txt |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/doc/service-api.txt b/doc/service-api.txt
index 46989f4..36e1161 100644
--- a/doc/service-api.txt
+++ b/doc/service-api.txt
@@ -24,11 +24,17 @@ Methods		array{object,dict} GetMessages()
 			that are part of a conversation between the service
 			entity and the number provided.

+			The number parameter contains digits to look for
+			(i.e.: n last digits of the phone number), only messages
+			with a recipient which ends with the given number will
+			be part of the GetConversation result.
+
 			The count parameter can either be 0 for unlimited
 			messages in the conversation or limit the conversation
 			to count last messages.

 			Possible Errors: [service].Error.InvalidArguments
+					 [service].Error.TransientFailure

 		object SendMessage(array{string} recipients, string smil,
 					array{string id, string content-type,
--
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCHv2 0/4] mmsd: GetConversation support
  2012-05-03 13:19 [PATCHv2 0/4] mmsd: GetConversation support Ronald Tessier
                   ` (3 preceding siblings ...)
  2012-05-03 13:20 ` [PATCHv2 4/4] doc: Update service-api.txt Ronald Tessier
@ 2012-05-09 17:22 ` Marcel Holtmann
  4 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2012-05-09 17:22 UTC (permalink / raw)
  To: ofono

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

Hi Ronald,

> These patches concern mmsd and implement "GetConversation" D-Bus API.
> 
> Ronald Tessier (4):
>   service: Retrieve get_conversation() args
>   service: Fill conversation list with messages
>   service: Sort conversation list by message date
>   doc: Update service-api.txt
> 
>  doc/service-api.txt |    6 ++
>  src/service.c       |  141 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 147 insertions(+), 0 deletions(-)

all 4 patches have been applied.

Regards

Marcel



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-05-09 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-03 13:19 [PATCHv2 0/4] mmsd: GetConversation support Ronald Tessier
2012-05-03 13:20 ` [PATCHv2 1/4] service: Retrieve get_conversation() args Ronald Tessier
2012-05-03 13:20 ` [PATCHv2 2/4] service: Fill conversation list with messages Ronald Tessier
2012-05-03 13:20 ` [PATCHv2 3/4] service: Sort conversation list by message date Ronald Tessier
2012-05-03 13:20 ` [PATCHv2 4/4] doc: Update service-api.txt Ronald Tessier
2012-05-09 17:22 ` [PATCHv2 0/4] mmsd: GetConversation support Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.