All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml
@ 2012-06-27 12:04 Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 02/10] test: Update map-client to the changes in GetFolderListing Luiz Augusto von Dentz
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This parses the response and return as a list of dictionary where each
entry is a folder and its properties, similar to what
FileTransfer.ListFolder does.
---
 client/map.c |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 89 insertions(+), 2 deletions(-)

diff --git a/client/map.c b/client/map.c
index 5242cb3..e3a6c6c 100644
--- a/client/map.c
+++ b/client/map.c
@@ -29,6 +29,7 @@
 #include <glib.h>
 #include <gdbus.h>
 
+#include "dbus.h"
 #include "log.h"
 
 #include "map.h"
@@ -132,6 +133,91 @@ done:
 	dbus_message_unref(map->msg);
 }
 
+static void folder_element(GMarkupParseContext *ctxt, const gchar *element,
+				const gchar **names, const gchar **values,
+				gpointer user_data, GError **gerr)
+{
+	DBusMessageIter dict, *iter = user_data;
+	gchar *key;
+	gint i;
+
+	if (strcasecmp("folder", element) != 0)
+		return;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	i = 0;
+	for (key = (gchar *) names[i]; key; key = (gchar *) names[++i]) {
+		key[0] = g_ascii_toupper(key[0]);
+
+		if (!g_str_equal("Name", key))
+			continue;
+
+		obex_dbus_dict_append(&dict, key, DBUS_TYPE_STRING,
+								&values[i]);
+	}
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static const GMarkupParser folder_parser = {
+	folder_element,
+	NULL,
+	NULL,
+	NULL,
+	NULL
+};
+
+static void folder_listing_cb(struct obc_session *session,
+						struct obc_transfer *transfer,
+						GError *err, void *user_data)
+{
+	struct map_data *map = user_data;
+	GMarkupParseContext *ctxt;
+	DBusMessage *reply;
+	DBusMessageIter iter, array;
+	char *contents;
+	size_t size;
+	int perr;
+
+	if (err != NULL) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"%s", err->message);
+		goto done;
+	}
+
+	perr = obc_transfer_get_contents(transfer, &contents, &size);
+	if (perr < 0) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"Error reading contents: %s",
+						strerror(-perr));
+		goto done;
+	}
+
+	reply = dbus_message_new_method_return(map->msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_ARRAY_AS_STRING
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array);
+	ctxt = g_markup_parse_context_new(&folder_parser, 0, &array, NULL);
+	g_markup_parse_context_parse(ctxt, contents, size, NULL);
+	g_markup_parse_context_free(ctxt);
+	dbus_message_iter_close_container(&iter, &array);
+	g_free(contents);
+
+done:
+	g_dbus_send_message(conn, reply);
+	dbus_message_unref(map->msg);
+}
+
 static DBusMessage *map_get_folder_listing(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
@@ -144,7 +230,8 @@ static DBusMessage *map_get_folder_listing(DBusConnection *connection,
 	if (transfer == NULL)
 		goto fail;
 
-	if (obc_session_queue(map->session, transfer, buffer_cb, map, &err)) {
+	if (obc_session_queue(map->session, transfer, folder_listing_cb, map,
+								&err)) {
 		map->msg = dbus_message_ref(message);
 		return NULL;
 	}
@@ -196,7 +283,7 @@ static const GDBusMethodTable map_methods[] = {
 				map_setpath) },
 	{ GDBUS_ASYNC_METHOD("GetFolderListing",
 					GDBUS_ARGS({ "dummy", "a{ss}" }),
-					GDBUS_ARGS({ "content", "s" }),
+					GDBUS_ARGS({ "content", "aa{sv}" }),
 					map_get_folder_listing) },
 	{ GDBUS_ASYNC_METHOD("GetMessageListing",
 			GDBUS_ARGS({ "folder", "s" }, { "dummy", "a{ss}" }),
-- 
1.7.10.2


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

* [PATCH obexd 02/10] test: Update map-client to the changes in GetFolderListing
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 03/10] client-doc: Add documentation of MessageAccess.GetFolderListing Luiz Augusto von Dentz
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This makes map-client to print only the name of the folders similar
to what ftp-client does.
---
 test/map-client |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/map-client b/test/map-client
index bf843f3..da357a9 100755
--- a/test/map-client
+++ b/test/map-client
@@ -50,7 +50,8 @@ if  __name__ == '__main__':
 		set_folder(map, options.new_dir)
 
 	if options.ls_dir:
-		print map.GetFolderListing(dict())
+		for i in map.GetFolderListing(dict()):
+			print "%s/" % (i["Name"])
 
 	if options.ls_msg is not None:
 		print map.GetMessageListing(options.ls_msg, dict())
-- 
1.7.10.2


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

* [PATCH obexd 03/10] client-doc: Add documentation of MessageAccess.GetFolderListing
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 02/10] test: Update map-client to the changes in GetFolderListing Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 04/10] client: Change MessageAccess.GetMessageListing to not return raw xml Luiz Augusto von Dentz
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 doc/client-api.txt |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index 58a824d..5a960e1 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -352,6 +352,15 @@ Methods		void SetFolder(string name)
 			Set working directory for current session, *name* may
 			be the directory name or '..[/dir]'.
 
+		array{dict} GetFolderListing(dict filter)
+
+			Returns a dictionary containing information about
+			the current folder content.
+
+			The following keys are defined:
+
+				string Name : Folder name
+
 Transfer hierarchy
 ==================
 
-- 
1.7.10.2


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

* [PATCH obexd 04/10] client: Change MessageAccess.GetMessageListing to not return raw xml
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 02/10] test: Update map-client to the changes in GetFolderListing Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 03/10] client-doc: Add documentation of MessageAccess.GetFolderListing Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 05/10] test: Update map-client to the changes in GetMessageListing Luiz Augusto von Dentz
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This parses the response and return as a list of dictionary where each
entry is a message and its properties,
---
 client/map.c |  175 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 138 insertions(+), 37 deletions(-)

diff --git a/client/map.c b/client/map.c
index e3a6c6c..2fc9b23 100644
--- a/client/map.c
+++ b/client/map.c
@@ -98,41 +98,6 @@ static DBusMessage *map_setpath(DBusConnection *connection,
 	return NULL;
 }
 
-static void buffer_cb(struct obc_session *session,
-						struct obc_transfer *transfer,
-						GError *err, void *user_data)
-{
-	struct map_data *map = user_data;
-	DBusMessage *reply;
-	char *contents;
-	size_t size;
-	int perr;
-
-	if (err != NULL) {
-		reply = g_dbus_create_error(map->msg,
-						ERROR_INTERFACE ".Failed",
-						"%s", err->message);
-		goto done;
-	}
-
-	perr = obc_transfer_get_contents(transfer, &contents, &size);
-	if (perr < 0) {
-		reply = g_dbus_create_error(map->msg,
-						ERROR_INTERFACE ".Failed",
-						"Error reading contents: %s",
-						strerror(-perr));
-		goto done;
-	}
-
-	reply = g_dbus_create_reply(map->msg, DBUS_TYPE_STRING, &contents,
-							DBUS_TYPE_INVALID);
-
-	g_free(contents);
-done:
-	g_dbus_send_message(conn, reply);
-	dbus_message_unref(map->msg);
-}
-
 static void folder_element(GMarkupParseContext *ctxt, const gchar *element,
 				const gchar **names, const gchar **values,
 				gpointer user_data, GError **gerr)
@@ -243,6 +208,141 @@ fail:
 	return reply;
 }
 
+static void msg_element(GMarkupParseContext *ctxt, const gchar *element,
+				const gchar **names, const gchar **values,
+				gpointer user_data, GError **gerr)
+{
+	DBusMessageIter dict, *iter = user_data;
+	gchar *key;
+	gint i;
+
+	if (strcasecmp("msg", element) != 0)
+		return;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	i = 0;
+	for (key = (gchar *) names[i]; key; key = (gchar *) names[++i]) {
+		if (strcasecmp(key, "handle") == 0) {
+			obex_dbus_dict_append(&dict, "Handle",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "subject") == 0) {
+			obex_dbus_dict_append(&dict, "Subject",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "datetime") == 0) {
+			obex_dbus_dict_append(&dict, "Timestamp",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "sender_name") == 0) {
+			obex_dbus_dict_append(&dict, "Sender",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "sender_addressing") == 0) {
+			obex_dbus_dict_append(&dict, "SenderAddress",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "replyto_addressing") == 0) {
+			obex_dbus_dict_append(&dict, "ReplyTo",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "recipient_name") == 0) {
+			obex_dbus_dict_append(&dict, "Recipient",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "recipient_addressing") == 0) {
+			obex_dbus_dict_append(&dict, "RecipientAddress",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "type") == 0) {
+			obex_dbus_dict_append(&dict, "Type",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "reception_status") == 0) {
+			obex_dbus_dict_append(&dict, "Status",
+						DBUS_TYPE_STRING, &values[i]);
+		} else if (strcasecmp(key, "size") == 0) {
+			guint64 value = g_ascii_strtoll(values[i], NULL, 10);
+
+			obex_dbus_dict_append(&dict, "Size",
+						DBUS_TYPE_UINT64, &value);
+		} else if (strcasecmp(key, "priority") == 0) {
+			gboolean value = strcasecmp(values[i], "no");
+
+			obex_dbus_dict_append(&dict, "Priority",
+						DBUS_TYPE_BOOLEAN, &value);
+		} else if (strcasecmp(key, "read") == 0) {
+			gboolean value = strcasecmp(values[i], "no");
+
+			obex_dbus_dict_append(&dict, "Read",
+						DBUS_TYPE_BOOLEAN, &value);
+		} else if (strcasecmp(key, "sent") == 0) {
+			gboolean value = strcasecmp(values[i], "no");
+
+			obex_dbus_dict_append(&dict, "Sent",
+						DBUS_TYPE_BOOLEAN, &value);
+		} else if (strcasecmp(key, "protected") == 0) {
+			gboolean value = strcasecmp(values[i], "no");
+
+			obex_dbus_dict_append(&dict, "Protected",
+						DBUS_TYPE_BOOLEAN, &value);
+		}
+
+	}
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static const GMarkupParser msg_parser = {
+	msg_element,
+	NULL,
+	NULL,
+	NULL,
+	NULL
+};
+
+static void message_listing_cb(struct obc_session *session,
+						struct obc_transfer *transfer,
+						GError *err, void *user_data)
+{
+	struct map_data *map = user_data;
+	GMarkupParseContext *ctxt;
+	DBusMessage *reply;
+	DBusMessageIter iter, array;
+	char *contents;
+	size_t size;
+	int perr;
+
+	if (err != NULL) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"%s", err->message);
+		goto done;
+	}
+
+	perr = obc_transfer_get_contents(transfer, &contents, &size);
+	if (perr < 0) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"Error reading contents: %s",
+						strerror(-perr));
+		goto done;
+	}
+
+	reply = dbus_message_new_method_return(map->msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_ARRAY_AS_STRING
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array);
+	ctxt = g_markup_parse_context_new(&msg_parser, 0, &array, NULL);
+	g_markup_parse_context_parse(ctxt, contents, size, NULL);
+	g_markup_parse_context_free(ctxt);
+	dbus_message_iter_close_container(&iter, &array);
+	g_free(contents);
+
+done:
+	g_dbus_send_message(conn, reply);
+	dbus_message_unref(map->msg);
+}
+
 static DBusMessage *map_get_message_listing(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
@@ -265,7 +365,8 @@ static DBusMessage *map_get_message_listing(DBusConnection *connection,
 	if (transfer == NULL)
 		goto fail;
 
-	if (obc_session_queue(map->session, transfer, buffer_cb, map, &err)) {
+	if (obc_session_queue(map->session, transfer, message_listing_cb, map,
+								&err)) {
 		map->msg = dbus_message_ref(message);
 		return NULL;
 	}
@@ -287,7 +388,7 @@ static const GDBusMethodTable map_methods[] = {
 					map_get_folder_listing) },
 	{ GDBUS_ASYNC_METHOD("GetMessageListing",
 			GDBUS_ARGS({ "folder", "s" }, { "dummy", "a{ss}" }),
-			GDBUS_ARGS({ "messages", "s" }),
+			GDBUS_ARGS({ "messages", "aa{sv}" }),
 			map_get_message_listing) },
 	{ }
 };
-- 
1.7.10.2


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

* [PATCH obexd 05/10] test: Update map-client to the changes in GetMessageListing
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2012-06-27 12:04 ` [PATCH obexd 04/10] client: Change MessageAccess.GetMessageListing to not return raw xml Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 06/10] client-doc: Add documentation of MessageAccess.GetMessageListing Luiz Augusto von Dentz
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This makes map-client to print the message properties dictionary
---
 test/map-client |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/test/map-client b/test/map-client
index da357a9..986fcad 100755
--- a/test/map-client
+++ b/test/map-client
@@ -54,6 +54,9 @@ if  __name__ == '__main__':
 			print "%s/" % (i["Name"])
 
 	if options.ls_msg is not None:
-		print map.GetMessageListing(options.ls_msg, dict())
+		for i in map.GetMessageListing(options.ls_msg, dict()):
+			for (key, value) in i.items():
+				print("%s = %s" % (key, value))
+			print "\n"
 
 	mainloop.run()
-- 
1.7.10.2


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

* [PATCH obexd 06/10] client-doc: Add documentation of MessageAccess.GetMessageListing
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2012-06-27 12:04 ` [PATCH obexd 05/10] test: Update map-client to the changes in GetMessageListing Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 07/10] client: Use filter instead of dummy as argument name in MAP Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 doc/client-api.txt |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index 5a960e1..1ad9001 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -361,6 +361,30 @@ Methods		void SetFolder(string name)
 
 				string Name : Folder name
 
+		array{dict} GetMessageListing(string folder, dict filter)
+
+			Returns a dictionary containing information about
+			the messages in the given folder.
+
+			The following keys are defined:
+
+				string Handle : Message handle
+				string Subject : Message subject
+				string Timestamp: Message timestamp
+				string Sender: Message sender name
+				string SenderAddress: Message sender address
+				string ReplyTo: Message Reply-To address
+				string Recipient: Message recipient name
+				string RecipientAddress: Message recipient
+							 address
+				string Type: Message type
+				uint64 Size: Message size in bytes
+				string Status: Message reception status
+				boolean Priority: Message priority flag
+				boolean Read: Message read flag
+				boolean Sent: Message sent flag
+				boolean Protected: Message protected flag
+
 Transfer hierarchy
 ==================
 
-- 
1.7.10.2


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

* [PATCH obexd 07/10] client: Use filter instead of dummy as argument name in MAP
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
                   ` (4 preceding siblings ...)
  2012-06-27 12:04 ` [PATCH obexd 06/10] client-doc: Add documentation of MessageAccess.GetMessageListing Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 08/10] client-doc: Add documentation of MessageAccess.GetMessage Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This is aligned with the documentation that uses filter as well.
---
 client/map.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/client/map.c b/client/map.c
index 2fc9b23..b8c0cb8 100644
--- a/client/map.c
+++ b/client/map.c
@@ -383,11 +383,11 @@ static const GDBusMethodTable map_methods[] = {
 				GDBUS_ARGS({ "name", "s" }), NULL,
 				map_setpath) },
 	{ GDBUS_ASYNC_METHOD("GetFolderListing",
-					GDBUS_ARGS({ "dummy", "a{ss}" }),
+					GDBUS_ARGS({ "filter", "a{ss}" }),
 					GDBUS_ARGS({ "content", "aa{sv}" }),
 					map_get_folder_listing) },
 	{ GDBUS_ASYNC_METHOD("GetMessageListing",
-			GDBUS_ARGS({ "folder", "s" }, { "dummy", "a{ss}" }),
+			GDBUS_ARGS({ "folder", "s" }, { "filter", "a{ss}" }),
 			GDBUS_ARGS({ "messages", "aa{sv}" }),
 			map_get_message_listing) },
 	{ }
-- 
1.7.10.2


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

* [PATCH obexd 08/10] client-doc: Add documentation of MessageAccess.GetMessage
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
                   ` (5 preceding siblings ...)
  2012-06-27 12:04 ` [PATCH obexd 07/10] client: Use filter instead of dummy as argument name in MAP Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 09/10] client: Add MessageAccess.GetMessage implementation Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 10/10] test: Add support for MessageAccess.GetMessage to map-client Luiz Augusto von Dentz
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

GetMessage takes the message handle, which can be discovered using
GetMessageListing, and file location where the contents of the message
will be stored.

It returns the transfer object and its properties so the user application
can track progress of the operation.
---
 doc/client-api.txt |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index 1ad9001..cf16a6a 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -385,6 +385,22 @@ Methods		void SetFolder(string name)
 				boolean Sent: Message sent flag
 				boolean Protected: Message protected flag
 
+		object, dict GetMessage(string handle, string targetfile)
+
+			Download message by its handle, the message handle can
+			be discovered using GetMessageListing, and store it
+			in the target file.
+
+			If an empty target file is given, a temporary file
+			will be automatically generated.
+
+			The returned path represents the newly created transfer,
+			which should be used to find out if the content has been
+			successfully transferred or if the operation fails.
+
+			The properties of this transfer are also returned along
+			with the object path, to avoid a call to GetProperties.
+
 Transfer hierarchy
 ==================
 
-- 
1.7.10.2


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

* [PATCH obexd 09/10] client: Add MessageAccess.GetMessage implementation
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
                   ` (6 preceding siblings ...)
  2012-06-27 12:04 ` [PATCH obexd 08/10] client-doc: Add documentation of MessageAccess.GetMessage Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  2012-06-27 12:04 ` [PATCH obexd 10/10] test: Add support for MessageAccess.GetMessage to map-client Luiz Augusto von Dentz
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 client/map.c |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/client/map.c b/client/map.c
index b8c0cb8..e5236d0 100644
--- a/client/map.c
+++ b/client/map.c
@@ -378,6 +378,38 @@ fail:
 	return reply;
 }
 
+static DBusMessage *map_get_message(DBusConnection *connection,
+					DBusMessage *message, void *user_data)
+{
+	struct map_data *map = user_data;
+	struct obc_transfer *transfer;
+	const char *handle, *target_file;
+	GError *err = NULL;
+	DBusMessage *reply;
+
+	if (dbus_message_get_args(message, NULL,
+				DBUS_TYPE_STRING, &handle,
+				DBUS_TYPE_STRING, &target_file,
+				DBUS_TYPE_INVALID) == FALSE)
+		return g_dbus_create_error(message,
+				ERROR_INTERFACE ".InvalidArguments", NULL);
+
+	transfer = obc_transfer_get("x-bt/message", handle, target_file, &err);
+	if (transfer == NULL)
+		goto fail;
+
+	if (!obc_session_queue(map->session, transfer, NULL, NULL, &err))
+		goto fail;
+
+	return obc_transfer_create_dbus_reply(transfer, message);
+
+fail:
+	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+								err->message);
+	g_error_free(err);
+	return reply;
+}
+
 static const GDBusMethodTable map_methods[] = {
 	{ GDBUS_ASYNC_METHOD("SetFolder",
 				GDBUS_ARGS({ "name", "s" }), NULL,
@@ -390,6 +422,11 @@ static const GDBusMethodTable map_methods[] = {
 			GDBUS_ARGS({ "folder", "s" }, { "filter", "a{ss}" }),
 			GDBUS_ARGS({ "messages", "aa{sv}" }),
 			map_get_message_listing) },
+	{ GDBUS_METHOD("GetMessage",
+			GDBUS_ARGS({ "handle", "s" }, { "file", "s" }),
+			GDBUS_ARGS({ "transfer", "o" },
+						{ "properties", "a{sv}" }),
+			map_get_message) },
 	{ }
 };
 
-- 
1.7.10.2


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

* [PATCH obexd 10/10] test: Add support for MessageAccess.GetMessage to map-client
  2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
                   ` (7 preceding siblings ...)
  2012-06-27 12:04 ` [PATCH obexd 09/10] client: Add MessageAccess.GetMessage implementation Luiz Augusto von Dentz
@ 2012-06-27 12:04 ` Luiz Augusto von Dentz
  8 siblings, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-27 12:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds -g/--get <handle> option to map-client so it downloads and
prints the contents of the message.

In addition add MapClient class to handle transfer signals similar to
what other scripts do.
---
 test/map-client |   93 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 83 insertions(+), 10 deletions(-)

diff --git a/test/map-client b/test/map-client
index 986fcad..2850900 100755
--- a/test/map-client
+++ b/test/map-client
@@ -2,6 +2,8 @@
 
 import gobject
 
+import sys
+import os
 import dbus
 import dbus.mainloop.glib
 from optparse import OptionParser
@@ -16,12 +18,85 @@ def parse_options():
 	parser.add_option("-v", "--verbose", action="store_true", dest="verbose")
 	parser.add_option("-L", "--lsmsg", action="store", dest="ls_msg",
 			help="List messages in supplied CWD subdir")
+	parser.add_option("-g", "--get", action="store", dest="get_msg",
+			help="List messages in supplied CWD subdir")
 
 	return parser.parse_args()
 
 def set_folder(session, new_dir):
 	session.SetFolder(new_dir)
 
+class MapClient:
+	def __init__(self, session_path, verbose=False):
+		self.progress = 0
+		self.transfer_path = None
+		self.props = dict()
+		self.verbose = verbose
+		bus = dbus.SessionBus()
+		obj = bus.get_object("org.bluez.obex.client", session_path)
+		self.session = dbus.Interface(obj, "org.bluez.obex.Session")
+		self.map = dbus.Interface(obj, "org.bluez.obex.MessageAccess")
+		bus.add_signal_receiver(self.transfer_complete,
+				dbus_interface="org.bluez.obex.Transfer",
+				signal_name="Complete",
+				path_keyword="path")
+		bus.add_signal_receiver(self.transfer_error,
+				dbus_interface="org.bluez.obex.Transfer",
+				signal_name="Error",
+				path_keyword="path")
+
+	def create_transfer_reply(self, reply):
+		(path, properties) = reply
+		self.transfer_path = path
+		self.props[path] = properties
+		if self.verbose:
+			print "Transfer created: %s (file %s)" % (path,
+							properties["Filename"])
+
+	def generic_reply(self):
+		if self.verbose:
+			print "Operation succeeded"
+
+	def error(self, err):
+		print err
+		mainloop.quit()
+
+	def transfer_complete(self, path):
+		if path != self.transfer_path:
+			return
+		if self.verbose:
+			print "Transfer finished"
+		properties = self.props.get(path)
+		if properties == None:
+			return
+		f = open(properties["Filename"], "r")
+		os.remove(properties["Filename"])
+		print f.readlines()
+
+	def transfer_error(self, code, message, path):
+		if path != self.transfer_path:
+			return
+		print "Transfer finished with error %s: %s" % (code, message)
+		mainloop.quit()
+
+	def set_folder(self, new_dir):
+		self.map.SetFolder(new_dir)
+
+	def list_folders(self):
+		for i in self.map.GetFolderListing(dict()):
+			print "%s/" % (i["Name"])
+
+	def list_messages(self, folder):
+		for i in self.map.GetMessageListing(folder, dict()):
+			for (key, value) in i.items():
+				print("%s = %s" % (key, value))
+			print "\n"
+
+	def get_message(self, handle):
+		self.map.GetMessage(handle, "",
+				reply_handler=self.create_transfer_reply,
+				error_handler=self.error)
+
 if  __name__ == '__main__':
 
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -40,23 +115,21 @@ if  __name__ == '__main__':
 	client = dbus.Interface(bus.get_object("org.bluez.obex.client", "/"),
 				"org.bluez.obex.Client")
 
+	print "Creating Session"
 	path = client.CreateSession(options.device, { "Target": "map" })
 
-	obj = bus.get_object("org.bluez.obex.client", path)
-	session = dbus.Interface(obj, "org.bluez.obex.Session")
-	map = dbus.Interface(obj, "org.bluez.obex.MessageAccess")
+	map_client = MapClient(path, options.verbose)
 
 	if options.new_dir:
-		set_folder(map, options.new_dir)
+		map_client.set_folder(options.new_dir)
 
 	if options.ls_dir:
-		for i in map.GetFolderListing(dict()):
-			print "%s/" % (i["Name"])
+		map_client.list_folders()
 
 	if options.ls_msg is not None:
-		for i in map.GetMessageListing(options.ls_msg, dict()):
-			for (key, value) in i.items():
-				print("%s = %s" % (key, value))
-			print "\n"
+		map_client.list_messages(options.ls_msg)
+
+	if options.get_msg is not None:
+		map_client.get_message(options.get_msg)
 
 	mainloop.run()
-- 
1.7.10.2


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

* Re: [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml
  2012-07-03 18:28 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
@ 2012-07-18 12:14 ` Johan Hedberg
  0 siblings, 0 replies; 12+ messages in thread
From: Johan Hedberg @ 2012-07-18 12:14 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

On Tue, Jul 03, 2012, Luiz Augusto von Dentz wrote:
> This parses the response and return as a list of dictionary where each
> entry is a folder and its properties, similar to what
> FileTransfer.ListFolder does.
> ---
>  client/map.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 86 insertions(+), 2 deletions(-)

This set has been pushed upstream. Thanks.

Johan

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

* [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml
@ 2012-07-03 18:28 Luiz Augusto von Dentz
  2012-07-18 12:14 ` Johan Hedberg
  0 siblings, 1 reply; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2012-07-03 18:28 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This parses the response and return as a list of dictionary where each
entry is a folder and its properties, similar to what
FileTransfer.ListFolder does.
---
 client/map.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 86 insertions(+), 2 deletions(-)

diff --git a/client/map.c b/client/map.c
index 5242cb3..4475ad5 100644
--- a/client/map.c
+++ b/client/map.c
@@ -29,6 +29,7 @@
 #include <glib.h>
 #include <gdbus.h>
 
+#include "dbus.h"
 #include "log.h"
 
 #include "map.h"
@@ -132,6 +133,88 @@ done:
 	dbus_message_unref(map->msg);
 }
 
+static void folder_element(GMarkupParseContext *ctxt, const gchar *element,
+				const gchar **names, const gchar **values,
+				gpointer user_data, GError **gerr)
+{
+	DBusMessageIter dict, *iter = user_data;
+	const gchar *key;
+	gint i;
+
+	if (strcasecmp("folder", element) != 0)
+		return;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+	for (i = 0, key = names[i]; key; key = names[++i]) {
+		if (strcasecmp("name", key) == 0)
+			obex_dbus_dict_append(&dict, "Name", DBUS_TYPE_STRING,
+								&values[i]);
+	}
+
+	dbus_message_iter_close_container(iter, &dict);
+}
+
+static const GMarkupParser folder_parser = {
+	folder_element,
+	NULL,
+	NULL,
+	NULL,
+	NULL
+};
+
+static void folder_listing_cb(struct obc_session *session,
+						struct obc_transfer *transfer,
+						GError *err, void *user_data)
+{
+	struct map_data *map = user_data;
+	GMarkupParseContext *ctxt;
+	DBusMessage *reply;
+	DBusMessageIter iter, array;
+	char *contents;
+	size_t size;
+	int perr;
+
+	if (err != NULL) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"%s", err->message);
+		goto done;
+	}
+
+	perr = obc_transfer_get_contents(transfer, &contents, &size);
+	if (perr < 0) {
+		reply = g_dbus_create_error(map->msg,
+						ERROR_INTERFACE ".Failed",
+						"Error reading contents: %s",
+						strerror(-perr));
+		goto done;
+	}
+
+	reply = dbus_message_new_method_return(map->msg);
+	if (reply == NULL)
+		return;
+
+	dbus_message_iter_init_append(reply, &iter);
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_ARRAY_AS_STRING
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array);
+	ctxt = g_markup_parse_context_new(&folder_parser, 0, &array, NULL);
+	g_markup_parse_context_parse(ctxt, contents, size, NULL);
+	g_markup_parse_context_free(ctxt);
+	dbus_message_iter_close_container(&iter, &array);
+	g_free(contents);
+
+done:
+	g_dbus_send_message(conn, reply);
+	dbus_message_unref(map->msg);
+}
+
 static DBusMessage *map_get_folder_listing(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
@@ -144,7 +227,8 @@ static DBusMessage *map_get_folder_listing(DBusConnection *connection,
 	if (transfer == NULL)
 		goto fail;
 
-	if (obc_session_queue(map->session, transfer, buffer_cb, map, &err)) {
+	if (obc_session_queue(map->session, transfer, folder_listing_cb, map,
+								&err)) {
 		map->msg = dbus_message_ref(message);
 		return NULL;
 	}
@@ -196,7 +280,7 @@ static const GDBusMethodTable map_methods[] = {
 				map_setpath) },
 	{ GDBUS_ASYNC_METHOD("GetFolderListing",
 					GDBUS_ARGS({ "dummy", "a{ss}" }),
-					GDBUS_ARGS({ "content", "s" }),
+					GDBUS_ARGS({ "content", "aa{sv}" }),
 					map_get_folder_listing) },
 	{ GDBUS_ASYNC_METHOD("GetMessageListing",
 			GDBUS_ARGS({ "folder", "s" }, { "dummy", "a{ss}" }),
-- 
1.7.10.4


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

end of thread, other threads:[~2012-07-18 12:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-27 12:04 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 02/10] test: Update map-client to the changes in GetFolderListing Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 03/10] client-doc: Add documentation of MessageAccess.GetFolderListing Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 04/10] client: Change MessageAccess.GetMessageListing to not return raw xml Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 05/10] test: Update map-client to the changes in GetMessageListing Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 06/10] client-doc: Add documentation of MessageAccess.GetMessageListing Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 07/10] client: Use filter instead of dummy as argument name in MAP Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 08/10] client-doc: Add documentation of MessageAccess.GetMessage Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 09/10] client: Add MessageAccess.GetMessage implementation Luiz Augusto von Dentz
2012-06-27 12:04 ` [PATCH obexd 10/10] test: Add support for MessageAccess.GetMessage to map-client Luiz Augusto von Dentz
2012-07-03 18:28 [PATCH obexd 01/10] client: Change MessageAccess.GetFolderListing to not return raw xml Luiz Augusto von Dentz
2012-07-18 12:14 ` Johan Hedberg

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.