Skip to contentSkip to conversation

mmsd: GetConversation support

PATCH Superseded Ronald Tessier 2 participants 12 messages Apr 25, 2012 – Apr 27, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mmsd: GetConversation support

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

Ronald Tessier (5):
service: Add GetConversation method
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 |    9 +++-
 src/service.c       |  171 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 179 insertions(+), 1 deletions(-)

--
1.7.4.1

#1 lore raw

PATCH 1/5 service: Add GetConversation method

---
 src/service.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
src/service.c +21 -0
index f89fd3f..24c89b6 100644
@@ -690,6 +690,26 @@ static DBusMessage *get_messages(DBusConnection *conn,
 	return reply;
 }
 
+static DBusMessage *get_conversation(DBusConnection *conn,
+					DBusMessage *dbus_msg, void *data)
+{
+	DBusMessage *reply;
+	DBusMessageIter iter, array;
+
+	reply = dbus_message_new_method_return(dbus_msg);
+	if (reply == NULL)
+		return __mms_error_trans_failure(dbus_msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+							"(oa{sv})", &array);
+
+	dbus_message_iter_close_container(&iter, &array);
+
+	return reply;
+}
+
 static gboolean mms_attachment_is_smil(const struct mms_attachment *part)
 {
 	if (g_str_has_prefix(part->content_type, "application/smil"))
@@ -813,6 +833,7 @@ release_msg:
 static GDBusMethodTable service_methods[] = {
 	{ "SendMessage", "assa(sss)", "o", send_message },
 	{ "GetMessages", "", "a(oa{sv})", get_messages },
+	{ "GetConversation", "su", "a(oa{sv})", get_conversation },
 	{ }
 };
 

--
1.7.4.1

#2 lore raw

Re: [PATCHv1 1/5] service: Add GetConversation method

Hi Ronald,

Quoted 2 lines
 src/service.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

patch has been applied.

Regards

Marcel

#3 lore raw

PATCH 2/5 service: Retrieve get_conversation() args

In reply to Ronald Tessier
---
 src/service.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
src/service.c +37 -0
index 24c89b6..18c11f4 100644
@@ -690,11 +690,48 @@ static DBusMessage *get_messages(DBusConnection *conn,
 	return reply;
 }
 
+static gboolean get_conversation_get_args(DBusMessage *dbus_msg,
+				const char **number, unsigned int *count)
+{
+	DBusMessageIter top_iter;
+
+	if (dbus_message_iter_init(dbus_msg, &top_iter) == FALSE)
+		return FALSE;
+
+	if (dbus_message_iter_get_arg_type(&top_iter) != DBUS_TYPE_STRING)
+		return FALSE;
+
+	dbus_message_iter_get_basic(&top_iter, number);
+	if (*number[0] == '\0')
+		return FALSE;
+
+	if (valid_number_format(*number) == FALSE)
+		return FALSE;
+
+	if (!dbus_message_iter_next(&top_iter))
+		return FALSE;
+
+	if (dbus_message_iter_get_arg_type(&top_iter) != DBUS_TYPE_UINT32)
+		return FALSE;
+
+	dbus_message_iter_get_basic(&top_iter, count);
+
+	return TRUE;
+}
+
 static DBusMessage *get_conversation(DBusConnection *conn,
 					DBusMessage *dbus_msg, void *data)
 {
 	DBusMessage *reply;
 	DBusMessageIter iter, array;
+	const char *number;
+	unsigned int count;
+
+	if (get_conversation_get_args(dbus_msg, &number, &count) == FALSE) {
+		mms_debug("Invalid arguments");
+
+		return __mms_error_invalid_args(dbus_msg);
+	}
 
 	reply = dbus_message_new_method_return(dbus_msg);
 	if (reply == NULL)

--
1.7.4.1

#4 lore raw

Re: [PATCHv1 2/5] service: Retrieve get_conversation() args

Hi Ronald,

Quoted 44 lines
---
 src/service.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
src/service.c +29 -0
index 24c89b6..18c11f4 100644
@@ -690,11 +690,48 @@ static DBusMessage *get_messages(DBusConnection *conn,
 	return reply;
 }
 
+static gboolean get_conversation_get_args(DBusMessage *dbus_msg,
+				const char **number, unsigned int *count)
+{
+	DBusMessageIter top_iter;
+
+	if (dbus_message_iter_init(dbus_msg, &top_iter) == FALSE)
+		return FALSE;
+
+	if (dbus_message_iter_get_arg_type(&top_iter) != DBUS_TYPE_STRING)
+		return FALSE;
+
+	dbus_message_iter_get_basic(&top_iter, number);
+	if (*number[0] == '\0')
+		return FALSE;
+
+	if (valid_number_format(*number) == FALSE)
+		return FALSE;
+
+	if (!dbus_message_iter_next(&top_iter))
+		return FALSE;
+
+	if (dbus_message_iter_get_arg_type(&top_iter) != DBUS_TYPE_UINT32)
+		return FALSE;
+
+	dbus_message_iter_get_basic(&top_iter, count);
+
+	return TRUE;
+}
+
 static DBusMessage *get_conversation(DBusConnection *conn,
 					DBusMessage *dbus_msg, void *data)
 {

src/service.c static DBusMessage *get_messages(DBusConnection *conn, · line 734

Quoted 10 lines
src/service.c +8 -0
 	DBusMessage *reply;
 	DBusMessageIter iter, array;
+	const char *number;
+	unsigned int count;
+
+	if (get_conversation_get_args(dbus_msg, &number, &count) == FALSE) {
+		mms_debug("Invalid arguments");
+
+		return __mms_error_invalid_args(dbus_msg);
+	}

in this case I don't really see that it is useful to split this into a separate function. And the debug print is actually useless. Please remove that one.

src/service.c static DBusMessage *get_messages(DBusConnection *conn, · line 737

Quoted 3 lines
src/service.c +0 -0
 	reply = dbus_message_new_method_return(dbus_msg);
 	if (reply == NULL)

Regards

Marcel

#5 lore raw

PATCH 3/5 service: Fill conversation list with messages

In reply to Ronald Tessier
---
 src/service.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 87 insertions(+), 1 deletions(-)
src/service.c +87 -1
index 18c11f4..2787c3a 100644
@@ -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

#6 lore raw

Re: [PATCHv1 3/5] service: Fill conversation list with messages

Hi Ronald,

Quoted 44 lines
---
 src/service.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 87 insertions(+), 1 deletions(-)
src/service.c +32 -0
index 18c11f4..2787c3a 100644
@@ -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

src/service.c static gboolean get_conversation_get_args(DBusMessage *dbus_msg, · line 763

Quoted 10 lines
src/service.c +10 -0
+		 * (i.e.: "/TYPE=PLMN" must follow).
+		 */
+		if (*num == '\0' && *rec == '/')
+			return TRUE;
+
+		recipients = rec;
+	}
+
+	return FALSE;
+}

please explain what this function is actually doing? Adding a comment seems like a good idea here.

Regards

Marcel

#7 lore raw

PATCH 4/5 service: Sort conversation list by message date

In reply to Ronald Tessier
---
 src/service.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
src/service.c +27 -0
index 2787c3a..1bd4671 100644
@@ -719,6 +719,31 @@ static gboolean get_conversation_get_args(DBusMessage *dbus_msg,
 	return TRUE;
 }
 
+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 *rec, *num;
@@ -784,6 +809,8 @@ static GList *fill_conversation(const struct mms_service *service,
 			conversation = g_list_prepend(conversation, value);
 	}
 
+	conversation = g_list_sort(conversation, fill_conversation_sort);
+
 	return conversation;
 }
 

--
1.7.4.1

#8 lore raw

Re: [PATCHv1 4/5] service: Sort conversation list by message date

Hi Ronald,

Quoted 40 lines
 src/service.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
src/service.c +25 -0
index 2787c3a..1bd4671 100644
@@ -719,6 +719,31 @@ static gboolean get_conversation_get_args(DBusMessage *dbus_msg,
 	return TRUE;
 }
 
+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 *rec, *num;

src/service.c static GList *fill_conversation(const struct mms_service *service, · line 813

Quoted 5 lines
src/service.c +2 -0
@@ -784,6 +809,8 @@ static GList *fill_conversation(const struct mms_service *service,
 			conversation = g_list_prepend(conversation, value);
 	}
 
+	conversation = g_list_sort(conversation, fill_conversation_sort);
+

is it really more efficient to prepend and then later sort the list? Can we just not insert items sorted to begin with?

Regards

Marcel

#9 lore raw

PATCH 5/5 doc: Update service-api.txt

In reply to Ronald Tessier
---
 doc/service-api.txt |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
doc/service-api.txt +8 -1
index 46989f4..99e80be 100644
@@ -24,11 +24,18 @@ Methods		array{object,dict} GetMessages()
 			that are part of a conversation between the service
 			entity and the number provided.
 
+			The number parameter must only contains	significant digits
+			to look for (i.e.: n last digits of the phone number), only
+			messages with a recipient containing 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
+			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

#10 lore raw

Re: [PATCHv1 5/5] doc: Update service-api.txt

Hi Ronald,

doc/service-api.txt Methods array{object,dict} GetMessages() · line 27

Quoted 12 lines
 doc/service-api.txt |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
doc/service-api.txt +1 -0
index 46989f4..99e80be 100644
@@ -24,11 +24,18 @@ Methods		array{object,dict} GetMessages()
 			that are part of a conversation between the service
 			entity and the number provided.
 
+			The number parameter must only contains	significant digits

actually using "must" is a wrong description.

doc/service-api.txt Methods array{object,dict} GetMessages() · line 30

Quoted 3 lines
doc/service-api.txt +3 -0
+			to look for (i.e.: n last digits of the phone number), only
+			messages with a recipient containing the given number will
+			be part of the GetConversation result.

And I am not sure we do wanna make some sort of assumption here anyway. These are not CLIP numbers where the operators don't seem to get this right. For SMS and MMS is seems the international numbering plan is used.

Or do you have counter examples. If so, please post them here first.

doc/service-api.txt Methods array{object,dict} GetMessages() · line 38

Quoted 9 lines
doc/service-api.txt +4 -1
+
 			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
+			Possible Errors:
+				[service].Error.InvalidArguments
+				[service].Error.TransientFailure

Please don't invent your own indentation here. Keep it aligned as all the other documents in oFono and mmsd do.

Regards

Marcel

#11 lore raw

Re: [PATCHv1 5/5] doc: Update service-api.txt

Hi Marcel,

Quoted 25 lines · Marcel Holtmann

Hi Ronald,

doc/service-api.txt Methods array{object,dict} GetMessages() · line 27

Quoted 12 lines
  doc/service-api.txt |    9 ++++++++-
  1 files changed, 8 insertions(+), 1 deletions(-)
doc/service-api.txt +1 -0
index 46989f4..99e80be 100644
@@ -24,11 +24,18 @@ Methods		array{object,dict} GetMessages()
  			that are part of a conversation between the service
  			entity and the number provided.
 
+			The number parameter must only contains	significant digits

actually using "must" is a wrong description.

doc/service-api.txt Methods array{object,dict} GetMessages() · line 30

Quoted 3 lines
doc/service-api.txt +3 -0
+			to look for (i.e.: n last digits of the phone number), only
+			messages with a recipient containing the given number will
+			be part of the GetConversation result.

And I am not sure we do wanna make some sort of assumption here anyway. These are not CLIP numbers where the operators don't seem to get this right. For SMS and MMS is seems the international numbering plan is used.

Quoted 1 line

Or do you have counter examples. If so, please post them here first.

I fully agree with you, for received MMS the international format is used. But for sent messages, the number is given by the user, the number can be international or local format, it can even contain '-' or '.'. For example, in my storage, received message used +33612345678 and sent message used the local version such as 0612345678, to get the conversation, we need to look for 612345678.
That's why I proposed to limit the number parameter (the one we're looking for in the messages) to its significant digits in GetConversation method.

Otherwise (if we want to use international format for number parameter) we have to force the user to only use international numbering plan when sending message, is it right ?

Quoted 6 lines
Quoted 6 lines
doc/service-api.txt +1 -0
+
  			The count parameter can either be 0 for unlimited
  			messages in the conversation or limit the conversation
  			to count last messages.
 
Quoted 7 lines

doc/service-api.txt Methods array{object,dict} GetMessages() · line 38

Quoted 4 lines
doc/service-api.txt +3 -1
-			Possible Errors: [service].Error.InvalidArguments
+			Possible Errors:
+				[service].Error.InvalidArguments
+				[service].Error.TransientFailure

Please don't invent your own indentation here. Keep it aligned as all the other documents in oFono and mmsd do.

No problem, I'll also change 'SendMessage' documentation to indent as it is done in oFono ;-)

Regards,

Ronald