Skip to contentSkip to conversation

mmsd: (resending) Support Delivery Report notification

PATCH In review Ronald Tessier 2 participants 25 messages Aug 24, 2012 – Sep 4, 2012

lore
Share & tools
lore
#0 lore raw

cover mmsd: (resending) Support Delivery Report notification

These patches concern mmsd and add delivery report notification support. Add MMS M-Delivery.ind PDU decoding support.
Update meta file of the sent message to store the received msg_id and to add a group [delivery_status] if delivery_report is requested.
Upon MMS M-Delivery.ind PDU reception, update delivery_status recipient entry with the received status (this is described in doc/storage.txt) and signal the new delivery_report status for the recipient concerned.
Modify the monitor_mms test script to add report_changed monitoring. Update message-api.txt doc to describe new ReportChanged signal.

Ronald Tessier (12):
mmsutil: Define mms_delivery_ind struct
mmsutil: Decode delivery_ind msg
service: Store msg_id provided by M-Send.conf PDU
service: Move mms_address_to_string() up
service: Add a group [delivery_status] in the msg status
service: Support M-Delivery.ind in mms_service_push_notify()
service: Support delivery_ind notif on start
store: Define MMS_META_UUID_XXX len and suffix
service: Process delivery_ind notification
service: Send a delivery changed signal
test: Add ReportChanged to monitored signals
doc: Add ReportChanged signal description

 doc/message-api.txt |    7 ++
 src/mmsutil.c       |   22 ++++-
 src/mmsutil.h       |    8 ++
 src/service.c       |  260 ++++++++++++++++++++++++++++++++++++++++++++++-----
 src/store.c         |    8 +-
 src/store.h         |    5 +
 test/monitor-mms    |   10 ++
 7 files changed, 292 insertions(+), 28 deletions(-)

--
1.7.9.5

#1 lore raw

PATCH 1/12 mmsutil: Define mms_delivery_ind struct

---
 src/mmsutil.h |    8 ++++++++
 1 file changed, 8 insertions(+)
src/mmsutil.h +8 -0
index cc3ec67..e32c761 100644
@@ -122,6 +122,13 @@ struct mms_notification_resp_ind {
 	enum mms_message_notify_status notify_status;
 };
 
+struct mms_delivery_ind {
+	enum mms_message_delivery_status dr_status;
+	char *msgid;
+	char *to;
+	time_t date;
+};
+
 struct mms_attachment {
 	unsigned char *data;
 	size_t offset;
@@ -143,6 +150,7 @@ struct mms_message {
 		struct mms_send_req sr;
 		struct mms_send_conf sc;
 		struct mms_notification_resp_ind nri;
+		struct mms_delivery_ind di;
 	};
 };
 
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 2/12 mmsutil: Decode delivery_ind msg

In reply to Ronald Tessier
---
 src/mmsutil.c |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
src/mmsutil.c +21 -1
index a9a12eb..7042276 100644
@@ -964,6 +964,24 @@ static gboolean decode_send_req(struct wsp_header_iter *iter,
 	return TRUE;
 }
 
+static gboolean decode_delivery_ind(struct wsp_header_iter *iter,
+						struct mms_message *out)
+{
+	return mms_parse_headers(iter, MMS_HEADER_MMS_VERSION,
+				HEADER_FLAG_MANDATORY | HEADER_FLAG_PRESET_POS,
+				&out->version,
+				MMS_HEADER_MESSAGE_ID,
+				HEADER_FLAG_MANDATORY, &out->di.msgid,
+				MMS_HEADER_TO,
+				HEADER_FLAG_MANDATORY, &out->di.to,
+				MMS_HEADER_DATE,
+				HEADER_FLAG_MANDATORY, &out->di.date,
+				MMS_HEADER_STATUS,
+				HEADER_FLAG_MANDATORY, &out->di.dr_status,
+				MMS_HEADER_INVALID);
+}
+
+
 #define CHECK_WELL_KNOWN_HDR(hdr)			\
 	if (wsp_header_iter_next(&iter) == FALSE)	\
 		return FALSE;				\
@@ -1016,7 +1034,7 @@ gboolean mms_message_decode(const unsigned char *pdu,
 	case MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND:
 		return FALSE;
 	case MMS_MESSAGE_TYPE_DELIVERY_IND:
-		return FALSE;
+		return decode_delivery_ind(&iter, out);
 	}
 
 	return FALSE;
@@ -1051,6 +1069,8 @@ void mms_message_free(struct mms_message *msg)
 	case MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND:
 		break;
 	case MMS_MESSAGE_TYPE_DELIVERY_IND:
+		g_free(msg->di.msgid);
+		g_free(msg->di.to);
 		break;
 	}
 
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 3/12 service: Store msg_id provided by M-Send.conf PDU

In reply to Ronald Tessier
---
 src/service.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
src/service.c +8 -4
index db9c514..b073ca9 100644
@@ -629,7 +629,7 @@ static gboolean result_request_send_conf(struct mms_request *request)
 
 	uuid = request->msg->uuid;
 
-	path = g_strdup_printf("%s/%s/%s", MMS_PATH, service->identity,	uuid);
+	path = g_strdup_printf("%s/%s/%s", MMS_PATH, service->identity, uuid);
 
 	if (request->status != 200)
 		goto error;
@@ -655,17 +655,21 @@ static gboolean result_request_send_conf(struct mms_request *request)
 
 	mms_debug("response status : %d", msg->sc.rsp_status);
 
-	mms_message_free(msg);
-
 	munmap(pdu, len);
 
 	unlink(request->data_path);
 
 	meta = mms_store_meta_open(service->identity, uuid);
-	if (meta == NULL)
+	if (meta == NULL) {
+		mms_message_free(msg);
+
 		goto error;
+	}
 
 	g_key_file_set_string(meta, "info", "state", "sent");
+	g_key_file_set_string(meta, "info", "id", msg->sc.msgid);
+
+	mms_message_free(msg);
 
 	mms_store_meta_close(service->identity, uuid, meta, TRUE);
 
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 4/12 service: Move mms_address_to_string() up

In reply to Ronald Tessier
---
 src/service.c |   26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
src/service.c +13 -13
index b073ca9..c3dc40a 100644
@@ -354,6 +354,19 @@ static gboolean mmap_file(const char *path, void **out_pdu, size_t *out_len)
 	return TRUE;
 }
 
+static const char *mms_address_to_string(char *mms_address)
+{
+	unsigned int prefix_len;
+
+	if (g_str_has_suffix(mms_address, "/TYPE=PLMN") == TRUE) {
+		prefix_len = strlen(mms_address) - 10;
+
+		mms_address[prefix_len] = '\0';
+	}
+
+	return (const char *) mms_address;
+}
+
 static gboolean send_message_get_recipients(DBusMessageIter *top_iter,
 						struct mms_message *msg)
 {
@@ -1702,19 +1715,6 @@ static void append_msg_attachments(DBusMessageIter *dict, const char *path,
 	}
 }
 
-static const char *mms_address_to_string(char *mms_address)
-{
-	unsigned int prefix_len;
-
-	if (g_str_has_suffix(mms_address, "/TYPE=PLMN") == TRUE) {
-		prefix_len = strlen(mms_address) - 10;
-
-		mms_address[prefix_len] = '\0';
-	}
-
-	return (const char *) mms_address;
-}
-
 static void append_msg_recipients(DBusMessageIter *dict,
 					struct mms_message *msg)
 {
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 5/12 service: Add a group [delivery_status] in the msg status

In reply to Ronald Tessier

This group contains an entry for each message recipients. Each recipient entry will be updated when the corresponding report will be received and then remove the temporary stored delivery report.

---
 src/service.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
src/service.c +33 -0
index c3dc40a..ec1b1b9 100644
@@ -69,6 +69,17 @@ static const char *ctl_chars = "\x01\x02\x03\x04\x05\x06\x07\x08\x0A"
 
 static const char *sep_chars = "()<>@,;:\\\"/[]?={} \t";
 
+static const char *delivery_status[] = {
+	"none",
+	"expired",
+	"retrieved",
+	"rejected",
+	"deferred",
+	"indeterminate",
+	"forwarded",
+	"unreachable"
+};
+
 struct mms_request;
 
 typedef gboolean (*mms_request_result_cb_t) (struct mms_request *request);
@@ -1058,6 +1069,28 @@ static DBusMessage *send_message(DBusConnection *conn,
 
 	g_key_file_set_string(meta, "info", "state", "draft");
 
+	if (service->use_delivery_reports) {
+		char **tos;
+		int i;
+
+		tos = g_strsplit(msg->sr.to, ",", 0);
+
+		for (i = 0; tos[i] != NULL; i++) {
+			char *to = g_strdup(tos[i]);
+
+			mms_address_to_string(to);
+
+			DBG("%s=%s", to, delivery_status[0]);
+
+			g_key_file_set_string(meta, "delivery_status", to,
+							delivery_status[0]);
+
+			g_free(to);
+		}
+
+		g_strfreev(tos);
+	}
+
 	mms_store_meta_close(service->identity, msg->uuid, meta, TRUE);
 
 	if (mms_message_register(service, msg) < 0)
Signature · 1 line
1.7.9.5
#11 lore raw

PATCH 6/12 service: Support M-Delivery.ind in mms_service_push_notify()

In reply to Ronald Tessier
---
 src/service.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
src/service.c +31 -0
index ec1b1b9..8087477 100644
@@ -2325,6 +2325,21 @@ static void process_request_queue(struct mms_service *service)
 						bearer_idle_timeout, service);
 }
 
+static void dump_delivery_ind(struct mms_message *msg)
+{
+	char buf[128];
+
+	strftime(buf, 127, "%Y-%m-%dT%H:%M:%S%z", localtime(&msg->di.date));
+	buf[127] = '\0';
+
+	mms_info("MMS version: %u.%u\n", (msg->version & 0x70) >> 4,
+						msg->version & 0x0f);
+	mms_info("Msg ID: %s\n", msg->di.msgid);
+	mms_info("To: %s\n", msg->di.to);
+	mms_info("Date: %s\n", buf);
+	mms_info("Delivery Report status: %d\n", msg->di.dr_status);
+}
+
 static void dump_notification_ind(struct mms_message *msg)
 {
 	char buf[128];
@@ -2370,6 +2385,22 @@ void mms_service_push_notify(struct mms_service *service,
 	if (mms_message_decode(data + nread, len - nread, msg) == FALSE)
 		goto error;
 
+	if (msg->type == MMS_MESSAGE_TYPE_DELIVERY_IND) {
+		msg->uuid = g_strdup(uuid);
+
+		dump_delivery_ind(msg);
+
+		meta = mms_store_meta_open(service->identity, uuid);
+		if (meta == NULL)
+			goto error;
+
+		g_key_file_set_string(meta, "info", "state", "notification");
+
+		mms_store_meta_close(service->identity, uuid, meta, TRUE);
+
+		return;
+	}
+
 	if (msg->type != MMS_MESSAGE_TYPE_NOTIFICATION_IND)
 		goto error;
 
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH 7/12 service: Support delivery_ind notif on start

In reply to Ronald Tessier
---
 src/service.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/service.c +4 -1
index 8087477..b3ecc1e 100644
@@ -1357,7 +1357,8 @@ static gboolean load_message_from_store(const char *service_id,
 	else if (strcmp(state, "draft") == 0
 			&& msg->type == MMS_MESSAGE_TYPE_SEND_REQ)
 		msg->sr.status = MMS_MESSAGE_STATUS_DRAFT;
-	else if (msg->type != MMS_MESSAGE_TYPE_NOTIFICATION_IND)
+	else if (msg->type != MMS_MESSAGE_TYPE_NOTIFICATION_IND &&
+			msg->type != MMS_MESSAGE_TYPE_DELIVERY_IND)
 		goto out;
 
 	success = TRUE;
@@ -1482,6 +1483,8 @@ register_sr:
 			request = NULL;
 			mms_message_register(service, msg);
 		}
+	} else if (msg->type == MMS_MESSAGE_TYPE_DELIVERY_IND) {
+		request = NULL;
 	} else
 		request = NULL;
 
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH 8/12 store: Define MMS_META_UUID_XXX len and suffix

In reply to Ronald Tessier
---
 src/store.c |    8 +++-----
 src/store.h |    5 +++++
 2 files changed, 8 insertions(+), 5 deletions(-)
src/store.c +3 -5
index b09c17b..f1c5714 100644
@@ -42,8 +42,6 @@
 #define TFR
 #endif
 
-#define MMS_SHA1_UUID_LEN 20
-
 static const char *digest_to_str(const unsigned char *digest)
 {
 	static char buf[MMS_SHA1_UUID_LEN * 2 + 1];
@@ -293,7 +291,7 @@ void mms_store_remove(const char *service_id, const char *uuid)
 
 	unlink(pdu_path);
 
-	meta_path = g_strdup_printf("%s%s", pdu_path, ".status");
+	meta_path = g_strdup_printf("%s%s", pdu_path, MMS_META_UUID_SUFFIX);
 
 	g_free(pdu_path);
 
@@ -312,7 +310,7 @@ GKeyFile *mms_store_meta_open(const char *service_id, const char *uuid)
 	if (pdu_path == NULL)
 		return NULL;
 
-	meta_path = g_strdup_printf("%s%s", pdu_path, ".status");
+	meta_path = g_strdup_printf("%s%s", pdu_path, MMS_META_UUID_SUFFIX);
 
 	g_free(pdu_path);
 
@@ -337,7 +335,7 @@ static void meta_store_sync(const char *service_id, const char *uuid,
 	if (pdu_path == NULL)
 		return;
 
-	meta_path = g_strdup_printf("%s%s", pdu_path, ".status");
+	meta_path = g_strdup_printf("%s%s", pdu_path, MMS_META_UUID_SUFFIX);
 
 	g_free(pdu_path);
 
src/store.h +5 -0
index ba2c080..fb2ca9f 100644
@@ -19,6 +19,11 @@
  *
  */
 
+#define MMS_SHA1_UUID_LEN 20
+#define MMS_META_UUID_SUFFIX ".status"
+#define MMS_META_UUID_SUFFIX_LEN 7
+#define MMS_META_UUID_LEN (MMS_SHA1_UUID_LEN * 2)
+
 const char *mms_store(const char *service_id, unsigned char *pdu,
 							unsigned int len);
 const char *mms_store_file(const char *service_id, const char *path);
Signature · 1 line
1.7.9.5
#17 lore raw

PATCH 9/12 service: Process delivery_ind notification

In reply to Ronald Tessier
---
 src/service.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 107 insertions(+), 4 deletions(-)
src/service.c +107 -4
index b3ecc1e..44184cb 100644
@@ -1300,6 +1300,104 @@ static void emit_service_removed(struct mms_service *service)
 				&service->path, DBUS_TYPE_INVALID);
 }
 
+static gboolean get_meta_by_msgid(struct mms_service *service,
+						const char *msgid,
+						char *uuid)
+{
+	GDir *dir;
+	GKeyFile *meta;
+	const char *file;
+	const char *homedir;
+	const char *service_id;
+	char *service_path;
+
+	homedir = g_get_home_dir();
+	if (homedir == NULL)
+		return FALSE;
+
+	service_id = service->identity;
+
+	service_path = g_strdup_printf("%s/.mms/%s/", homedir, service_id);
+
+	dir = g_dir_open(service_path, 0, NULL);
+	g_free(service_path);
+	if (dir == NULL)
+		return FALSE;
+
+	while ((file = g_dir_read_name(dir)) != NULL) {
+		char *id;
+
+		if (g_str_has_suffix(file, MMS_META_UUID_SUFFIX) == FALSE)
+			continue;
+
+		if (strlen(file) != MMS_META_UUID_LEN +
+						MMS_META_UUID_SUFFIX_LEN)
+			continue;
+
+		strncpy(uuid, file, MMS_META_UUID_LEN);
+		uuid[MMS_META_UUID_LEN] = 0;
+
+		meta = mms_store_meta_open(service_id, uuid);
+		if (meta == NULL)
+			goto bail;
+
+		id = g_key_file_get_string(meta, "info", "id", NULL);
+		if (id == NULL) {
+			mms_store_meta_close(service_id, uuid, meta, FALSE);
+			continue;
+		}
+
+		if (g_strcmp0(msgid, id) == 0) {
+			mms_store_meta_close(service_id, uuid, meta, FALSE);
+			g_dir_close(dir);
+			return TRUE;
+		}
+
+		mms_store_meta_close(service_id, uuid, meta, FALSE);
+	}
+
+bail:
+	g_dir_close(dir);
+
+	return FALSE;
+}
+
+static void process_delivery_ind_notification(struct mms_service *service,
+						struct mms_message *di_msg)
+{
+	GKeyFile *meta;
+	char uuid[MMS_META_UUID_LEN + 1];
+	char *path;
+	char *to;
+
+	if (get_meta_by_msgid(service, di_msg->di.msgid, uuid) == FALSE)
+		goto bail;
+
+	meta = mms_store_meta_open(service->identity, uuid);
+	if (meta == NULL)
+		return;
+
+	to = g_strdup(di_msg->di.to);
+
+	mms_address_to_string(to);
+
+	g_key_file_set_string(meta, "delivery_status", to,
+				delivery_status[di_msg->di.dr_status - 127]);
+
+	g_free(to);
+
+	mms_store_meta_close(service->identity, uuid, meta, TRUE);
+
+	path = g_strdup_printf("%s/%s/%s", MMS_PATH, service->identity, uuid);
+
+	g_free(path);
+
+bail:
+	mms_store_remove(service->identity, di_msg->uuid);
+
+	mms_message_free(di_msg);
+}
+
 static gboolean load_message_from_store(const char *service_id,
 				const char *uuid, struct mms_message *msg)
 {
@@ -1485,6 +1583,7 @@ register_sr:
 		}
 	} else if (msg->type == MMS_MESSAGE_TYPE_DELIVERY_IND) {
 		request = NULL;
+		process_delivery_ind_notification(service, msg);
 	} else
 		request = NULL;
 
@@ -1514,15 +1613,17 @@ static void load_messages(struct mms_service *service)
 		return;
 
 	while ((file = g_dir_read_name(dir)) != NULL) {
-		const size_t suffix_len = 7;
 		char *uuid;
+		size_t uuid_len;
 
-		if (g_str_has_suffix(file, ".status") == FALSE)
+		if (g_str_has_suffix(file, MMS_META_UUID_SUFFIX) == FALSE)
 			continue;
-		if (strlen(file) - suffix_len == 0)
+
+		uuid_len = strlen(file) - MMS_META_UUID_SUFFIX_LEN;
+		if (uuid_len == 0)
 			continue;
 
-		uuid = g_strndup(file, strlen(file) - suffix_len);
+		uuid = g_strndup(file, uuid_len);
 
 		process_message_on_start(service, uuid);
 
@@ -2401,6 +2502,8 @@ void mms_service_push_notify(struct mms_service *service,
 
 		mms_store_meta_close(service->identity, uuid, meta, TRUE);
 
+		process_delivery_ind_notification(service, msg);
+
 		return;
 	}
 
Signature · 1 line
1.7.9.5
#19 lore raw

PATCH 10/12 service: Send a delivery changed signal

In reply to Ronald Tessier
---
 src/service.c |   48 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 3 deletions(-)
src/service.c +45 -3
index 44184cb..ba23b4a 100644
@@ -218,6 +218,40 @@ static void emit_msg_status_changed(const char *path, const char *new_status)
 	g_dbus_send_message(connection, signal);
 }
 
+static void emit_msg_delivery_changed(const char *path, const char *rec,
+							const char *status)
+{
+	DBusMessage *signal;
+	DBusMessageIter iter;
+	DBusMessageIter variant;
+	const char *type = "delivery_report";
+
+	signal = dbus_message_new_signal(path, MMS_MESSAGE_INTERFACE,
+							"ReportChanged");
+	if (signal == NULL)
+		return;
+
+	dbus_message_iter_init_append(signal, &iter);
+
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &type);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_STRING_AS_STRING, &variant);
+
+	dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &rec);
+
+	dbus_message_iter_close_container(&iter, &variant);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_STRING_AS_STRING, &variant);
+
+	dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &status);
+
+	dbus_message_iter_close_container(&iter, &variant);
+
+	g_dbus_send_message(connection, signal);
+}
+
 static DBusMessage *msg_mark_read(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
@@ -269,6 +303,10 @@ static const GDBusMethodTable message_methods[] = {
 static const GDBusSignalTable message_signals[] = {
 	{ GDBUS_SIGNAL("PropertyChanged",
 			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+	{ GDBUS_SIGNAL("ReportChanged",
+			GDBUS_ARGS({ "name", "s" },
+					{ "rec", "v" },
+					{ "status", "v" })) },
 	{ }
 };
 
@@ -1369,6 +1407,7 @@ static void process_delivery_ind_notification(struct mms_service *service,
 	char uuid[MMS_META_UUID_LEN + 1];
 	char *path;
 	char *to;
+	const char *new_status;
 
 	if (get_meta_by_msgid(service, di_msg->di.msgid, uuid) == FALSE)
 		goto bail;
@@ -1381,15 +1420,18 @@ static void process_delivery_ind_notification(struct mms_service *service,
 
 	mms_address_to_string(to);
 
-	g_key_file_set_string(meta, "delivery_status", to,
-				delivery_status[di_msg->di.dr_status - 127]);
+	new_status = delivery_status[di_msg->di.dr_status - 127];
 
-	g_free(to);
+	g_key_file_set_string(meta, "delivery_status", to, new_status);
 
 	mms_store_meta_close(service->identity, uuid, meta, TRUE);
 
 	path = g_strdup_printf("%s/%s/%s", MMS_PATH, service->identity, uuid);
 
+	emit_msg_delivery_changed(path, to, new_status);
+
+	g_free(to);
+
 	g_free(path);
 
 bail:
Signature · 1 line
1.7.9.5
#20 lore raw

PATCH 11/12 test: Add ReportChanged to monitored signals

In reply to Ronald Tessier
---
 test/monitor-mms |   10 ++++++++++
 1 file changed, 10 insertions(+)
test/monitor-mms +10 -0
index 188d028..ef17a13 100755
@@ -29,6 +29,10 @@ def property_changed(name, value, member, path, interface):
 	iface = interface[interface.rfind(".") + 1:]
 	print "{%s} [%s] %s %s" % (iface, name, member, value)
 
+def report_changed(type, rec, status, path, interface):
+	iface = interface[interface.rfind(".") + 1:]
+	print "{%s} [%s] <%s> %s : %s" % (iface, path, type, rec, status)
+
 if __name__ == '__main__':
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
@@ -75,5 +79,11 @@ if __name__ == '__main__':
 						path_keyword="path",
 						interface_keyword="interface")
 
+	bus.add_signal_receiver(report_changed,
+					bus_name="org.ofono.mms",
+					signal_name = "ReportChanged",
+						path_keyword="path",
+						interface_keyword="interface")
+
 	mainloop = gobject.MainLoop()
 	mainloop.run()
Signature · 1 line
1.7.9.5
#21 lore raw

PATCH 12/12 doc: Add ReportChanged signal description

In reply to Ronald Tessier
---
 doc/message-api.txt |    7 +++++++
 1 file changed, 7 insertions(+)
doc/message-api.txt +7 -0
index 2922e5d..274bb98 100644
@@ -31,6 +31,13 @@ Signals		PropertyChanged(string name, variant value)
 			The only expected property change is for the
 			message status.
 
+		ReportChanged(string type, variant recipient, variant status)
+
+			Signal that is sent when a report has been received and
+			processed. It contains the type of the report
+			("delivery_report" or other), the recipient concerned
+			and its new status.
+
 Properties	string Status [readonly]
 
 			The status of the message.  Possible values are
Signature · 1 line
1.7.9.5
#4 lore raw

Re: [PATCH 02/12] mmsutil: Decode delivery_ind msg

In reply to Ronald Tessier

Hi Ronald,

Quoted 20 lines · Ronald Tessier
---
  src/mmsutil.c |   22 +++++++++++++++++++++-
  1 file changed, 21 insertions(+), 1 deletion(-)
src/mmsutil.c +8 -0
index a9a12eb..7042276 100644
@@ -964,6 +964,24 @@ static gboolean decode_send_req(struct wsp_header_iter *iter,
  	return TRUE;
  }
 
+static gboolean decode_delivery_ind(struct wsp_header_iter *iter,
+						struct mms_message *out)
+{
+	return mms_parse_headers(iter, MMS_HEADER_MMS_VERSION,
+				HEADER_FLAG_MANDATORY | HEADER_FLAG_PRESET_POS,
+				&out->version,
+				MMS_HEADER_MESSAGE_ID,
+				HEADER_FLAG_MANDATORY,&out->di.msgid,

src/mmsutil.c static gboolean decode_send_req(struct wsp_header_iter *iter, · line 984

Quoted 10 lines
src/mmsutil.c +10 -0
+				MMS_HEADER_TO,
+				HEADER_FLAG_MANDATORY,&out->di.to,
+				MMS_HEADER_DATE,
+				HEADER_FLAG_MANDATORY,&out->di.date,
+				MMS_HEADER_STATUS,
+				HEADER_FLAG_MANDATORY,&out->di.dr_status,
+				MMS_HEADER_INVALID);
+}
+
+

Why the double empty line?

Quoted 13 lines
src/mmsutil.c +1 -1
  #define CHECK_WELL_KNOWN_HDR(hdr)			\
  	if (wsp_header_iter_next(&iter) == FALSE)	\
  		return FALSE;				\
@@ -1016,7 +1034,7 @@ gboolean mms_message_decode(const unsigned char *pdu,
  	case MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND:
  		return FALSE;
  	case MMS_MESSAGE_TYPE_DELIVERY_IND:
-		return FALSE;
+		return decode_delivery_ind(&iter, out);
  	}
 
  	return FALSE;

src/mmsutil.c void mms_message_free(struct mms_message *msg) · line 1076

Quoted 8 lines
src/mmsutil.c +2 -0
@@ -1051,6 +1069,8 @@ void mms_message_free(struct mms_message *msg)
  	case MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND:
  		break;
  	case MMS_MESSAGE_TYPE_DELIVERY_IND:
+		g_free(msg->di.msgid);
+		g_free(msg->di.to);
  		break;
  	}
 

Regards,
-Denis

#2 lore raw

Re: [PATCH 01/12] mmsutil: Define mms_delivery_ind struct

In reply to Ronald Tessier

Hi Ronald,

Quoted 4 lines · Ronald Tessier
---
  src/mmsutil.h |    8 ++++++++
  1 file changed, 8 insertions(+)

Patch has been applied, thanks.

Regards,
-Denis

#6 lore raw

Re: [PATCH 03/12] service: Store msg_id provided by M-Send.conf PDU

In reply to Ronald Tessier

Hi Ronald,

Quoted 4 lines · Ronald Tessier
---
  src/service.c |   12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

#8 lore raw

Re: [PATCH 04/12] service: Move mms_address_to_string() up

In reply to Ronald Tessier

Hi Ronald,

Quoted 4 lines · Ronald Tessier
---
  src/service.c |   26 +++++++++++++-------------
  1 file changed, 13 insertions(+), 13 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

#10 lore raw

Re: [PATCH 05/12] service: Add a group [delivery_status] in the msg status

In reply to Ronald Tessier

Hi Ronald,

Quoted 7 lines · Ronald Tessier

This group contains an entry for each message recipients. Each recipient entry will be updated when the corresponding report will be received and then remove the temporary stored delivery report.

---
  src/service.c |   33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)

Patch has been applied, thanks.

Regards,
-Denis

#12 lore raw

Re: [PATCH 06/12] service: Support M-Delivery.ind in mms_service_push_notify()

In reply to Ronald Tessier

Hi Ronald,

Quoted 4 lines · Ronald Tessier
---
  src/service.c |   31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)

Patch has been applied, thanks.

Regards,
-Denis

#14 lore raw

Re: [PATCH 07/12] service: Support delivery_ind notif on start

In reply to Ronald Tessier

Hi Ronald,

Quoted 4 lines · Ronald Tessier
---
  src/service.c |    5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)

Patch has been applied, thanks.

Regards,
-Denis

#16 lore raw

Re: [PATCH 08/12] store: Define MMS_META_UUID_XXX len and suffix

In reply to Ronald Tessier

Hi Ronald,

Quoted 5 lines · Ronald Tessier
---
  src/store.c |    8 +++-----
  src/store.h |    5 +++++
  2 files changed, 8 insertions(+), 5 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

#18 lore raw

Re: [PATCH 09/12] service: Process delivery_ind notification

In reply to Ronald Tessier

Hi Ronald,

Quoted 133 lines · Ronald Tessier
---
  src/service.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
  1 file changed, 107 insertions(+), 4 deletions(-)
src/service.c +101 -3
index b3ecc1e..44184cb 100644
@@ -1300,6 +1300,104 @@ static void emit_service_removed(struct mms_service *service)
  				&service->path, DBUS_TYPE_INVALID);
  }
 
+static gboolean get_meta_by_msgid(struct mms_service *service,
+						const char *msgid,
+						char *uuid)
+{
+	GDir *dir;
+	GKeyFile *meta;
+	const char *file;
+	const char *homedir;
+	const char *service_id;
+	char *service_path;
+
+	homedir = g_get_home_dir();
+	if (homedir == NULL)
+		return FALSE;
+
+	service_id = service->identity;
+
+	service_path = g_strdup_printf("%s/.mms/%s/", homedir, service_id);
+
+	dir = g_dir_open(service_path, 0, NULL);
+	g_free(service_path);
+	if (dir == NULL)
+		return FALSE;
+
+	while ((file = g_dir_read_name(dir)) != NULL) {
+		char *id;
+
+		if (g_str_has_suffix(file, MMS_META_UUID_SUFFIX) == FALSE)
+			continue;
+
+		if (strlen(file) != MMS_META_UUID_LEN +
+						MMS_META_UUID_SUFFIX_LEN)
+			continue;
+
+		strncpy(uuid, file, MMS_META_UUID_LEN);
+		uuid[MMS_META_UUID_LEN] = 0;
+
+		meta = mms_store_meta_open(service_id, uuid);
+		if (meta == NULL)
+			goto bail;
+
+		id = g_key_file_get_string(meta, "info", "id", NULL);
+		if (id == NULL) {
+			mms_store_meta_close(service_id, uuid, meta, FALSE);
+			continue;
+		}
+
+		if (g_strcmp0(msgid, id) == 0) {
+			mms_store_meta_close(service_id, uuid, meta, FALSE);
+			g_dir_close(dir);
+			return TRUE;
+		}
+
+		mms_store_meta_close(service_id, uuid, meta, FALSE);
+	}
+
+bail:
+	g_dir_close(dir);
+
+	return FALSE;
+}
+
+static void process_delivery_ind_notification(struct mms_service *service,
+						struct mms_message *di_msg)
+{
+	GKeyFile *meta;
+	char uuid[MMS_META_UUID_LEN + 1];
+	char *path;
+	char *to;
+
+	if (get_meta_by_msgid(service, di_msg->di.msgid, uuid) == FALSE)
+		goto bail;
+
+	meta = mms_store_meta_open(service->identity, uuid);
+	if (meta == NULL)
+		return;
+
+	to = g_strdup(di_msg->di.to);
+
+	mms_address_to_string(to);
+
+	g_key_file_set_string(meta, "delivery_status", to,
+				delivery_status[di_msg->di.dr_status - 127]);
+
+	g_free(to);
+
+	mms_store_meta_close(service->identity, uuid, meta, TRUE);
+
+	path = g_strdup_printf("%s/%s/%s", MMS_PATH, service->identity, uuid);
+
+	g_free(path);
+
+bail:
+	mms_store_remove(service->identity, di_msg->uuid);
+
+	mms_message_free(di_msg);
+}
+
  static gboolean load_message_from_store(const char *service_id,
  				const char *uuid, struct mms_message *msg)
  {
@@ -1485,6 +1583,7 @@ register_sr:
  		}
  	} else if (msg->type == MMS_MESSAGE_TYPE_DELIVERY_IND) {
  		request = NULL;
+		process_delivery_ind_notification(service, msg);
  	} else
  		request = NULL;
 
@@ -1514,15 +1613,17 @@ static void load_messages(struct mms_service *service)
  		return;
 
  	while ((file = g_dir_read_name(dir)) != NULL) {
-		const size_t suffix_len = 7;
  		char *uuid;
+		size_t uuid_len;
 
-		if (g_str_has_suffix(file, ".status") == FALSE)
+		if (g_str_has_suffix(file, MMS_META_UUID_SUFFIX) == FALSE)
  			continue;
-		if (strlen(file) - suffix_len == 0)

src/service.c static void load_messages(struct mms_service *service) · line 1629

Quoted 10 lines
src/service.c +4 -1
+
+		uuid_len = strlen(file) - MMS_META_UUID_SUFFIX_LEN;
+		if (uuid_len == 0)
  			continue;
 
-		uuid = g_strndup(file, strlen(file) - suffix_len);
+		uuid = g_strndup(file, uuid_len);
 
  		process_message_on_start(service, uuid);
 

This chunk should really be in a separate patch since it is related to the previous one.

src/service.c void mms_service_push_notify(struct mms_service *service, · line 2509

Quoted 9 lines
src/service.c +2 -0
@@ -2401,6 +2502,8 @@ void mms_service_push_notify(struct mms_service *service,
 
  		mms_store_meta_close(service->identity, uuid, meta, TRUE);
 
+		process_delivery_ind_notification(service, msg);
+
  		return;
  	}
 

Regards,
-Denis

#22 lore raw

Re: [PATCH 12/12] doc: Add ReportChanged signal description

In reply to Ronald Tessier

Hi Ronald,

Quoted 4 lines · Ronald Tessier
---
  doc/message-api.txt |    7 +++++++
  1 file changed, 7 insertions(+)

Please order any D-Bus API changes before the D-Bus API implementations.
E.g. this patch should be #10 in your series.

Quoted 5 lines
doc/message-api.txt +0 -0
index 2922e5d..274bb98 100644

doc/message-api.txt Signals PropertyChanged(string name, variant value) · line 40

Quoted 10 lines
doc/message-api.txt +7 -0
@@ -31,6 +31,13 @@ Signals		PropertyChanged(string name, variant value)
  			The only expected property change is for the
  			message status.
 
+		ReportChanged(string type, variant recipient, variant status)
+
+			Signal that is sent when a report has been received and
+			processed. It contains the type of the report
+			("delivery_report" or other), the recipient concerned
+			and its new status.
+

Why are we not simply changing the 'Status' to delivered/expired, etc?

doc/message-api.txt Signals PropertyChanged(string name, variant value) · line 43

Quoted 3 lines
doc/message-api.txt +0 -0
  Properties	string Status [readonly]
 
  			The status of the message.  Possible values are

Regards,
-Denis

#23 lore raw

Re: [PATCH 12/12] doc: Add ReportChanged signal description

Hi Denis,

Quoted 20 lines · Denis Kenzior

Hi Ronald,

Quoted 4 lines · Ronald Tessier
---
  doc/message-api.txt |    7 +++++++
  1 file changed, 7 insertions(+)

Please order any D-Bus API changes before the D-Bus API implementations.
E.g. this patch should be #10 in your series.

Quoted 9 lines
doc/message-api.txt +0 -0
index 2922e5d..274bb98 100644
@@ -31,6 +31,13 @@ Signals        PropertyChanged(string name, variant
 value)
              The only expected property change is for the
              message status.
 
Quoted 9 lines

doc/message-api.txt Signals PropertyChanged(string name, variant value) · line 40

Quoted 7 lines
doc/message-api.txt +7 -0
+        ReportChanged(string type, variant recipient, variant status)
+
+            Signal that is sent when a report has been received and
+            processed. It contains the type of the report
+            ("delivery_report" or other), the recipient concerned
+            and its new status.
+

Why are we not simply changing the 'Status' to delivered/expired, etc?

Unfortunately, we cannot use the message status because there is one delivery status per recipient (a message can be sent to 2 (or more) recipients, so it can be delivered to one of them and "not yet delivered" to the other one).

Regards,

Ronald

#24 lore raw

Re: [PATCH 12/12] doc: Add ReportChanged signal description

Hi Ronald,

Quoted 10 lines
Quoted 9 lines

doc/message-api.txt Signals PropertyChanged(string name, variant value) · line 40

Quoted 7 lines

+ ReportChanged(string type, variant recipient, variant status)

doc/message-api.txt +6 -0
+
+ Signal that is sent when a report has been received and
+ processed. It contains the type of the report
+ ("delivery_report" or other), the recipient concerned
+ and its new status.
+

Why are we not simply changing the 'Status' to delivered/expired, etc?

Quoted 5 lines

Unfortunately, we cannot use the message status because there is one delivery status per recipient (a message can be sent to 2 (or more) recipients, so it can be delivered to one of them and "not yet delivered" to the other one).

So how do you expect this to work? Is the application responsible for aggregating the recipients? If so, then that is not a good idea, mmsd should be doing as much work as possible here.

Can't we use delivered/partially_delivered/expired and provide exact status details as a dictionary?

Regards,
-Denis