Skip to contentSkip to conversation

mmsd: GetConversation support

PATCH In review Ronald Tessier 2 participants 6 messages May 3, 2012 – May 9, 2012

lore
Share & tools
lore
#0 lore raw

v2 cover mmsd: GetConversation support

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

#1 lore raw

PATCH v2 1/4 service: Retrieve get_conversation() args

---
 src/service.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
src/service.c +23 -0
index 689a4e1..a8e818a 100644
@@ -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

#2 lore raw

PATCH v2 2/4 service: Fill conversation list with messages

In reply to Ronald Tessier

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(-)
src/service.c +93 -1
index a8e818a..93beceb 100644
@@ -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

#3 lore raw

PATCH v2 3/4 service: Sort conversation list by message date

In reply to Ronald Tessier
---
 src/service.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
src/service.c +27 -1
index 93beceb..6bcdede 100644
@@ -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

#4 lore raw

PATCH v2 4/4 doc: Update service-api.txt

In reply to Ronald Tessier
---
 doc/service-api.txt |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
doc/service-api.txt +6 -0
index 46989f4..36e1161 100644
@@ -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

#5 lore raw
In reply to Ronald Tessier

Hi Ronald,

Quoted 11 lines

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