* [PATCH obexd 2/8] client: Rename MessageAccess method GetMessagesListing to ListMessages
2012-09-13 13:06 [PATCH obexd 1/8] client: Rename MessageAccess method GetFolderListing to ListFolders Luiz Augusto von Dentz
@ 2012-09-13 13:06 ` Luiz Augusto von Dentz
2012-09-13 13:06 ` [PATCH obexd 3/8] client: Add MessageAccess.ListFilterFields Luiz Augusto von Dentz
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2012-09-13 13:06 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
In addition to that add missing parsing of the filters
---
client/map.c | 317 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 302 insertions(+), 15 deletions(-)
diff --git a/client/map.c b/client/map.c
index a7bdf08..6d1b0f2 100644
--- a/client/map.c
+++ b/client/map.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <string.h>
+#include <stdio.h>
#include <glib.h>
#include <gdbus.h>
@@ -52,6 +53,29 @@
#define DEFAULT_COUNT 1024
#define DEFAULT_OFFSET 0
+static const char * const filter_list[] = {
+ "subject",
+ "timestamp",
+ "sender",
+ "sender-address",
+ "recipient",
+ "recipient-address",
+ "type",
+ "size",
+ "status",
+ "text",
+ "attachment",
+ "priority",
+ "read",
+ "sent",
+ "protected",
+ "replyto",
+ NULL
+};
+
+#define FILTER_BIT_MAX 15
+#define FILTER_ALL 0xFF
+
struct map_data {
struct obc_session *session;
DBusMessage *msg;
@@ -689,28 +713,26 @@ done:
dbus_message_unref(map->msg);
}
-static DBusMessage *map_get_message_listing(DBusConnection *connection,
- DBusMessage *message, void *user_data)
+static DBusMessage *get_message_listing(struct map_data *map,
+ DBusMessage *message,
+ const char *folder,
+ GObexApparam *apparam)
{
- struct map_data *map = user_data;
struct obc_transfer *transfer;
- const char *folder;
- DBusMessageIter msg_iter;
GError *err = NULL;
DBusMessage *reply;
+ guint8 buf[1024];
+ gsize len;
- dbus_message_iter_init(message, &msg_iter);
-
- if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_STRING)
- return g_dbus_create_error(message,
- ERROR_INTERFACE ".InvalidArguments", NULL);
-
- dbus_message_iter_get_basic(&msg_iter, &folder);
+ len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
+ g_obex_apparam_free(apparam);
transfer = obc_transfer_get("x-bt/MAP-msg-listing", folder, NULL, &err);
if (transfer == NULL)
goto fail;
+ obc_transfer_set_params(transfer, buf, len);
+
if (obc_session_queue(map->session, transfer, message_listing_cb, map,
&err)) {
map->msg = dbus_message_ref(message);
@@ -724,6 +746,271 @@ fail:
return reply;
}
+static uint64_t get_filter_mask(const char *filterstr)
+{
+ int i;
+
+ if (!filterstr)
+ return 0;
+
+ if (!g_ascii_strcasecmp(filterstr, "ALL"))
+ return FILTER_ALL;
+
+ for (i = 0; filter_list[i] != NULL; i++)
+ if (!g_ascii_strcasecmp(filterstr, filter_list[i]))
+ return 1ULL << i;
+
+ return 0;
+}
+
+static int set_field(guint32 *filter, const char *filterstr)
+{
+ guint64 mask;
+
+ mask = get_filter_mask(filterstr);
+
+ if (mask == 0)
+ return -EINVAL;
+
+ *filter |= mask;
+ return 0;
+}
+
+static GObexApparam *parse_fields(GObexApparam *apparam, DBusMessageIter *iter)
+{
+ DBusMessageIter array;
+ guint32 filter = 0;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+ return NULL;
+
+ dbus_message_iter_recurse(iter, &array);
+
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
+ const char *string;
+
+ dbus_message_iter_get_basic(&array, &string);
+
+ if (set_field(&filter, string) < 0)
+ return NULL;
+
+ dbus_message_iter_next(&array);
+ }
+
+ return g_obex_apparam_set_uint32(apparam, MAP_AP_PARAMETERMASK,
+ filter);
+}
+
+static GObexApparam *parse_filter_type(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ DBusMessageIter array;
+ guint8 types = 0;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+ return NULL;
+
+ dbus_message_iter_recurse(iter, &array);
+
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
+ const char *string;
+
+ dbus_message_iter_get_basic(&array, &string);
+
+ if (!g_ascii_strcasecmp(string, "sms"))
+ types |= 0x03; /* SMS_GSM and SMS_CDMA */
+ else if (!g_ascii_strcasecmp(string, "email"))
+ types |= 0x04; /* EMAIL */
+ else if (!g_ascii_strcasecmp(string, "mms"))
+ types |= 0x08; /* MMS */
+ else
+ return NULL;
+ }
+
+ return g_obex_apparam_set_uint8(apparam, MAP_AP_FILTERMESSAGETYPE,
+ types);
+}
+
+static GObexApparam *parse_period_begin(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ const char *string;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return NULL;
+
+ dbus_message_iter_get_basic(iter, &string);
+
+ return g_obex_apparam_set_string(apparam, MAP_AP_FILTERPERIODBEGIN,
+ string);
+}
+
+static GObexApparam *parse_period_end(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ const char *string;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return NULL;
+
+ dbus_message_iter_get_basic(iter, &string);
+
+ return g_obex_apparam_set_string(apparam, MAP_AP_FILTERPERIODEND,
+ string);
+}
+
+static GObexApparam *parse_filter_read(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ guint8 status = 0;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BOOLEAN)
+ return NULL;
+
+ dbus_message_iter_get_basic(iter, &status);
+
+ status = (status) ? 0x01 : 0x02;
+
+ return g_obex_apparam_set_uint8(apparam, MAP_AP_FILTERREADSTATUS,
+ status);
+}
+
+static GObexApparam *parse_filter_recipient(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ const char *string;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return NULL;
+
+ dbus_message_iter_get_basic(iter, &string);
+
+ return g_obex_apparam_set_string(apparam, MAP_AP_FILTERRECIPIENT,
+ string);
+}
+
+static GObexApparam *parse_filter_sender(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ const char *string;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return NULL;
+
+ dbus_message_iter_get_basic(iter, &string);
+
+ return g_obex_apparam_set_string(apparam, MAP_AP_FILTERORIGINATOR,
+ string);
+}
+
+static GObexApparam *parse_filter_priority(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ guint8 priority;
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BOOLEAN)
+ return NULL;
+
+ dbus_message_iter_get_basic(iter, &priority);
+
+ priority = (priority) ? 0x01 : 0x02;
+
+ return g_obex_apparam_set_uint8(apparam, MAP_AP_FILTERPRIORITY,
+ priority);
+}
+
+static GObexApparam *parse_message_filters(GObexApparam *apparam,
+ DBusMessageIter *iter)
+{
+ DBusMessageIter array;
+
+ DBG("");
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+ return NULL;
+
+ dbus_message_iter_recurse(iter, &array);
+
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
+ const char *key;
+ DBusMessageIter value, entry;
+
+ dbus_message_iter_recurse(&array, &entry);
+ dbus_message_iter_get_basic(&entry, &key);
+
+ dbus_message_iter_next(&entry);
+ dbus_message_iter_recurse(&entry, &value);
+
+ if (strcasecmp(key, "Offset") == 0) {
+ if (parse_offset(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "MaxCount") == 0) {
+ if (parse_max_count(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "Fields") == 0) {
+ if (parse_fields(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "Types") == 0) {
+ if (parse_filter_type(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "PeriodBegin") == 0) {
+ if (parse_period_begin(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "PeriodEnd") == 0) {
+ if (parse_period_end(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "Read") == 0) {
+ if (parse_filter_read(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "Recipient") == 0) {
+ if (parse_filter_recipient(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "Sender") == 0) {
+ if (parse_filter_sender(apparam, &value) == NULL)
+ return NULL;
+ } else if (strcasecmp(key, "Priority") == 0) {
+ if (parse_filter_priority(apparam, &value) == NULL)
+ return NULL;
+ }
+
+ dbus_message_iter_next(&array);
+ }
+
+ return apparam;
+}
+
+static DBusMessage *map_list_messages(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct map_data *map = user_data;
+ const char *folder;
+ GObexApparam *apparam;
+ DBusMessageIter args;
+
+ dbus_message_iter_init(message, &args);
+
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".InvalidArguments", NULL);
+
+ dbus_message_iter_get_basic(&args, &folder);
+
+ apparam = g_obex_apparam_set_uint16(NULL, MAP_AP_MAXLISTCOUNT,
+ DEFAULT_COUNT);
+ apparam = g_obex_apparam_set_uint16(apparam, MAP_AP_STARTOFFSET,
+ DEFAULT_OFFSET);
+
+ dbus_message_iter_next(&args);
+
+ if (parse_message_filters(apparam, &args) == NULL) {
+ g_obex_apparam_free(apparam);
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".InvalidArguments", NULL);
+ }
+
+ return get_message_listing(map, message, folder, apparam);
+}
+
static const GDBusMethodTable map_methods[] = {
{ GDBUS_ASYNC_METHOD("SetFolder",
GDBUS_ARGS({ "name", "s" }), NULL,
@@ -732,10 +1019,10 @@ static const GDBusMethodTable map_methods[] = {
GDBUS_ARGS({ "filters", "a{sv}" }),
GDBUS_ARGS({ "content", "aa{sv}" }),
map_list_folders) },
- { GDBUS_ASYNC_METHOD("GetMessageListing",
- GDBUS_ARGS({ "folder", "s" }, { "filter", "a{ss}" }),
+ { GDBUS_ASYNC_METHOD("ListMessages",
+ GDBUS_ARGS({ "folder", "s" }, { "filter", "a{sv}" }),
GDBUS_ARGS({ "messages", "a{oa{sv}}" }),
- map_get_message_listing) },
+ map_list_messages) },
{ }
};
--
1.7.11.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH obexd 3/8] client: Add MessageAccess.ListFilterFields
2012-09-13 13:06 [PATCH obexd 1/8] client: Rename MessageAccess method GetFolderListing to ListFolders Luiz Augusto von Dentz
2012-09-13 13:06 ` [PATCH obexd 2/8] client: Rename MessageAccess method GetMessagesListing to ListMessages Luiz Augusto von Dentz
@ 2012-09-13 13:06 ` Luiz Augusto von Dentz
2012-09-13 13:06 ` [PATCH obexd 4/8] client-doc: Update documentation of MessageAccess interface Luiz Augusto von Dentz
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2012-09-13 13:06 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
client/map.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/client/map.c b/client/map.c
index 6d1b0f2..cf3d8ed 100644
--- a/client/map.c
+++ b/client/map.c
@@ -1011,6 +1011,41 @@ static DBusMessage *map_list_messages(DBusConnection *connection,
return get_message_listing(map, message, folder, apparam);
}
+static gchar **get_filter_strs(uint64_t filter, gint *size)
+{
+ gchar **list, **item;
+ gint i;
+
+ list = g_malloc0(sizeof(gchar **) * (FILTER_BIT_MAX + 2));
+
+ item = list;
+
+ for (i = 0; filter_list[i] != NULL; i++)
+ if (filter & (1ULL << i))
+ *(item++) = g_strdup(filter_list[i]);
+
+ *item = NULL;
+ *size = item - list;
+ return list;
+}
+
+static DBusMessage *map_list_filter_fields(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ gchar **filters = NULL;
+ gint size;
+ DBusMessage *reply;
+
+ filters = get_filter_strs(FILTER_ALL, &size);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING, &filters, size,
+ DBUS_TYPE_INVALID);
+
+ g_strfreev(filters);
+ return reply;
+}
+
static const GDBusMethodTable map_methods[] = {
{ GDBUS_ASYNC_METHOD("SetFolder",
GDBUS_ARGS({ "name", "s" }), NULL,
@@ -1023,6 +1058,10 @@ static const GDBusMethodTable map_methods[] = {
GDBUS_ARGS({ "folder", "s" }, { "filter", "a{sv}" }),
GDBUS_ARGS({ "messages", "a{oa{sv}}" }),
map_list_messages) },
+ { GDBUS_METHOD("ListFilterFields",
+ NULL,
+ GDBUS_ARGS({ "fields", "as" }),
+ map_list_filter_fields) },
{ }
};
--
1.7.11.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH obexd 4/8] client-doc: Update documentation of MessageAccess interface
2012-09-13 13:06 [PATCH obexd 1/8] client: Rename MessageAccess method GetFolderListing to ListFolders Luiz Augusto von Dentz
2012-09-13 13:06 ` [PATCH obexd 2/8] client: Rename MessageAccess method GetMessagesListing to ListMessages Luiz Augusto von Dentz
2012-09-13 13:06 ` [PATCH obexd 3/8] client: Add MessageAccess.ListFilterFields Luiz Augusto von Dentz
@ 2012-09-13 13:06 ` Luiz Augusto von Dentz
2012-09-13 13:06 ` [PATCH obexd 5/8] test: Update map-client to work with changes in " Luiz Augusto von Dentz
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2012-09-13 13:06 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
doc/client-api.txt | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 66 insertions(+), 3 deletions(-)
diff --git a/doc/client-api.txt b/doc/client-api.txt
index f447789..f78b8fe 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -368,7 +368,7 @@ Methods void SetFolder(string name)
Set working directory for current session, *name* may
be the directory name or '..[/dir]'.
- array{dict} GetFolderListing(dict filter)
+ array{dict} ListFolders(dict filter)
Returns a dictionary containing information about
the current folder content.
@@ -377,12 +377,22 @@ Methods void SetFolder(string name)
string Name : Folder name
- array{object, dict} GetMessageListing(string folder,
- dict filter)
+ Possible filters: Offset and MaxCount
+
+ array{string} ListFilterFields()
+
+ Return all available fields that can be used in Fields
+ filter.
+
+ array{object, dict} ListMessages(string folder, dict filter)
Returns an array containing the messages found in the
given folder.
+ Possible Filters: Offset, MaxCount, Fields, Type,
+ PeriodStart, PeriodEnd, Status, Recipient, Sender,
+ Priority
+
Each message is represented by an object path followed
by a dictionary of the properties.
@@ -450,6 +460,59 @@ Methods void SetFolder(string name)
Message protected flag
+Filter: uint16 Offset:
+
+ Offset of the first item, default is 0
+
+ uint16 MaxCount:
+
+ Maximum number of items, default is 1024
+
+ array{string} Fields:
+
+ Message fields, default is all values.
+
+ Possible values can be query with ListFilterFields.
+
+ array{string} Types:
+
+ Filter messages by type.
+
+ Possible values: "sms", "email", "mms".
+
+ string PeriodBegin:
+
+ Filter messages by starting period.
+
+ Possible values: Date in "YYYYMMDDTHHMMSS" format.
+
+ string PeriodEnd:
+
+ Filter messages by ending period.
+
+ Possible values: Date in "YYYYMMDDTHHMMSS" format.
+
+ boolean Read:
+
+ Filter messages by read flag.
+
+ Possible values: True for read or False for unread
+
+ string Recipient:
+
+ Filter messages by recipient address.
+
+ string Sender:
+
+ Filter messages by sender address.
+
+ gboolean Priority:
+
+ Filter messages by priority flag.
+
+ Possible values: True for high priority or False for
+ non-high priority
+
Message hierarchy
=================
--
1.7.11.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH obexd 5/8] test: Update map-client to work with changes in MessageAccess interface
2012-09-13 13:06 [PATCH obexd 1/8] client: Rename MessageAccess method GetFolderListing to ListFolders Luiz Augusto von Dentz
` (2 preceding siblings ...)
2012-09-13 13:06 ` [PATCH obexd 4/8] client-doc: Update documentation of MessageAccess interface Luiz Augusto von Dentz
@ 2012-09-13 13:06 ` Luiz Augusto von Dentz
2012-09-13 13:06 ` [PATCH obexd 6/8] client: Fix not sending parameters to get message in map module Luiz Augusto von Dentz
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2012-09-13 13:06 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
test/map-client | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/map-client b/test/map-client
index ac1a8ca..dbb67df 100755
--- a/test/map-client
+++ b/test/map-client
@@ -105,15 +105,15 @@ class MapClient:
self.map.SetFolder(new_dir)
def list_folders(self):
- for i in self.map.GetFolderListing(dict()):
+ for i in self.map.ListFolders(dict()):
print "%s/" % (i["Name"])
def list_messages(self, folder):
- ret = self.map.GetMessageListing(folder, dict())
+ ret = self.map.ListMessages(folder, dict())
print pformat(unwrap(ret))
def get_message(self, handle):
- self.map.GetMessageListing("", dict())
+ self.map.ListMessages("", dict())
path = self.path + "/message" + handle
obj = bus.get_object("org.bluez.obex.client", path)
msg = dbus.Interface(obj, "org.bluez.obex.Message")
--
1.7.11.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH obexd 6/8] client: Fix not sending parameters to get message in map module
2012-09-13 13:06 [PATCH obexd 1/8] client: Rename MessageAccess method GetFolderListing to ListFolders Luiz Augusto von Dentz
` (3 preceding siblings ...)
2012-09-13 13:06 ` [PATCH obexd 5/8] test: Update map-client to work with changes in " Luiz Augusto von Dentz
@ 2012-09-13 13:06 ` Luiz Augusto von Dentz
2012-09-13 13:07 ` [PATCH obexd 7/8] test: Update map-client to work with changes in Message.Get Luiz Augusto von Dentz
2012-09-13 13:07 ` [PATCH obexd 8/8] client: Avoid extra copies while passing apparam to transfer Luiz Augusto von Dentz
6 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2012-09-13 13:06 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Attachment and charset are mandatory, so Message.Get now takes an
additional boolean parameter which the user application should set
if it wants the attachments to be downloaded, charset is always set
to UTF8.
---
client/map.c | 20 +++++++++++++++++++-
doc/client-api.txt | 2 +-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/client/map.c b/client/map.c
index cf3d8ed..4b5f8a2 100644
--- a/client/map.c
+++ b/client/map.c
@@ -53,6 +53,8 @@
#define DEFAULT_COUNT 1024
#define DEFAULT_OFFSET 0
+#define CHARSET_UTF8 1
+
static const char * const filter_list[] = {
"subject",
"timestamp",
@@ -377,11 +379,16 @@ static DBusMessage *map_msg_get(DBusConnection *connection,
struct map_msg *msg = user_data;
struct obc_transfer *transfer;
const char *target_file;
+ gboolean attachment;
GError *err = NULL;
DBusMessage *reply;
+ GObexApparam *apparam;
+ guint8 buf[6];
+ gsize len;
if (dbus_message_get_args(message, NULL,
DBUS_TYPE_STRING, &target_file,
+ DBUS_TYPE_BOOLEAN, &attachment,
DBUS_TYPE_INVALID) == FALSE)
return g_dbus_create_error(message,
ERROR_INTERFACE ".InvalidArguments", NULL);
@@ -391,6 +398,16 @@ static DBusMessage *map_msg_get(DBusConnection *connection,
if (transfer == NULL)
goto fail;
+ apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_ATTACHMENT,
+ attachment);
+ apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_CHARSET,
+ CHARSET_UTF8);
+ len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
+
+ obc_transfer_set_params(transfer, buf, len);
+
+ g_obex_apparam_free(apparam);
+
if (!obc_session_queue(msg->data->session, transfer, NULL, NULL, &err))
goto fail;
@@ -405,7 +422,8 @@ fail:
static const GDBusMethodTable map_msg_methods[] = {
{ GDBUS_METHOD("Get",
- GDBUS_ARGS({ "targetfile", "s" }),
+ GDBUS_ARGS({ "targetfile", "s" },
+ { "attachment", "b" }),
GDBUS_ARGS({ "transfer", "o" },
{ "properties", "a{sv}" }),
map_msg_get) },
diff --git a/doc/client-api.txt b/doc/client-api.txt
index f78b8fe..25fd3e4 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -520,7 +520,7 @@ Service org.bluez.obex.client
Interface org.bluez.obex.Message
Object path [variable prefix]/{session0,session1,...}/{message0,...}
-Methods object, dict Get(string targetfile)
+Methods object, dict Get(string targetfile, boolean attachment)
Download message and store it in the target file.
--
1.7.11.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH obexd 7/8] test: Update map-client to work with changes in Message.Get
2012-09-13 13:06 [PATCH obexd 1/8] client: Rename MessageAccess method GetFolderListing to ListFolders Luiz Augusto von Dentz
` (4 preceding siblings ...)
2012-09-13 13:06 ` [PATCH obexd 6/8] client: Fix not sending parameters to get message in map module Luiz Augusto von Dentz
@ 2012-09-13 13:07 ` Luiz Augusto von Dentz
2012-09-13 13:07 ` [PATCH obexd 8/8] client: Avoid extra copies while passing apparam to transfer Luiz Augusto von Dentz
6 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2012-09-13 13:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
test/map-client | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/map-client b/test/map-client
index dbb67df..2075844 100755
--- a/test/map-client
+++ b/test/map-client
@@ -117,7 +117,7 @@ class MapClient:
path = self.path + "/message" + handle
obj = bus.get_object("org.bluez.obex.client", path)
msg = dbus.Interface(obj, "org.bluez.obex.Message")
- msg.Get("",reply_handler=self.create_transfer_reply,
+ msg.Get("", True, reply_handler=self.create_transfer_reply,
error_handler=self.error)
if __name__ == '__main__':
--
1.7.11.4
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH obexd 8/8] client: Avoid extra copies while passing apparam to transfer
2012-09-13 13:06 [PATCH obexd 1/8] client: Rename MessageAccess method GetFolderListing to ListFolders Luiz Augusto von Dentz
` (5 preceding siblings ...)
2012-09-13 13:07 ` [PATCH obexd 7/8] test: Update map-client to work with changes in Message.Get Luiz Augusto von Dentz
@ 2012-09-13 13:07 ` Luiz Augusto von Dentz
6 siblings, 0 replies; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2012-09-13 13:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
By passing directly the reference to GObexApparam it is no longer
necessary to use intermediate buffers to pass data around.
---
client/map.c | 29 ++++++++---------------
client/pbap.c | 42 +++++++++++----------------------
client/transfer.c | 69 +++++++++++++++++++------------------------------------
client/transfer.h | 6 ++---
4 files changed, 47 insertions(+), 99 deletions(-)
diff --git a/client/map.c b/client/map.c
index 4b5f8a2..e78cd68 100644
--- a/client/map.c
+++ b/client/map.c
@@ -248,17 +248,14 @@ static DBusMessage *get_folder_listing(struct map_data *map,
struct obc_transfer *transfer;
GError *err = NULL;
DBusMessage *reply;
- guint8 buf[8];
- gsize len;
-
- len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
- g_obex_apparam_free(apparam);
transfer = obc_transfer_get("x-obex/folder-listing", NULL, NULL, &err);
- if (transfer == NULL)
+ if (transfer == NULL) {
+ g_obex_apparam_free(apparam);
goto fail;
+ }
- obc_transfer_set_params(transfer, buf, len);
+ obc_transfer_set_apparam(transfer, apparam);
if (obc_session_queue(map->session, transfer, folder_listing_cb, map,
&err)) {
@@ -383,8 +380,6 @@ static DBusMessage *map_msg_get(DBusConnection *connection,
GError *err = NULL;
DBusMessage *reply;
GObexApparam *apparam;
- guint8 buf[6];
- gsize len;
if (dbus_message_get_args(message, NULL,
DBUS_TYPE_STRING, &target_file,
@@ -402,11 +397,8 @@ static DBusMessage *map_msg_get(DBusConnection *connection,
attachment);
apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_CHARSET,
CHARSET_UTF8);
- len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
-
- obc_transfer_set_params(transfer, buf, len);
- g_obex_apparam_free(apparam);
+ obc_transfer_set_apparam(transfer, apparam);
if (!obc_session_queue(msg->data->session, transfer, NULL, NULL, &err))
goto fail;
@@ -739,17 +731,14 @@ static DBusMessage *get_message_listing(struct map_data *map,
struct obc_transfer *transfer;
GError *err = NULL;
DBusMessage *reply;
- guint8 buf[1024];
- gsize len;
-
- len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
- g_obex_apparam_free(apparam);
transfer = obc_transfer_get("x-bt/MAP-msg-listing", folder, NULL, &err);
- if (transfer == NULL)
+ if (transfer == NULL) {
+ g_obex_apparam_free(apparam);
goto fail;
+ }
- obc_transfer_set_params(transfer, buf, len);
+ obc_transfer_set_apparam(transfer, apparam);
if (obc_session_queue(map->session, transfer, message_listing_cb, map,
&err)) {
diff --git a/client/pbap.c b/client/pbap.c
index a8db1cf..ea4a023 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -250,17 +250,11 @@ static void read_return_apparam(struct obc_transfer *transfer,
guint16 *phone_book_size, guint8 *new_missed_calls)
{
GObexApparam *apparam;
- const guint8 *data;
- size_t size;
*phone_book_size = 0;
*new_missed_calls = 0;
- data = obc_transfer_get_params(transfer, &size);
- if (data == NULL)
- return;
-
- apparam = g_obex_apparam_decode(data, size);
+ apparam = obc_transfer_get_apparam(transfer);
if (apparam == NULL)
return;
@@ -269,7 +263,6 @@ static void read_return_apparam(struct obc_transfer *transfer,
g_obex_apparam_get_uint8(apparam, NEWMISSEDCALLS_TAG,
new_missed_calls);
-
g_obex_apparam_free(apparam);
}
@@ -533,20 +526,17 @@ static DBusMessage *pull_phonebook(struct pbap_data *pbap,
struct pending_request *request;
struct obc_transfer *transfer;
char *name;
- guint8 buf[32];
- gsize len;
session_callback_t func;
DBusMessage *reply;
GError *err = NULL;
name = g_strconcat(pbap->path, ".vcf", NULL);
- len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
- g_obex_apparam_free(apparam);
-
transfer = obc_transfer_get("x-bt/phonebook", name, targetfile, &err);
- if (transfer == NULL)
+ if (transfer == NULL) {
+ g_obex_apparam_free(apparam);
goto fail;
+ }
switch (type) {
case PULLPHONEBOOK:
@@ -562,7 +552,7 @@ static DBusMessage *pull_phonebook(struct pbap_data *pbap,
return NULL;
}
- obc_transfer_set_params(transfer, buf, len);
+ obc_transfer_set_apparam(transfer, apparam);
if (!obc_session_queue(pbap->session, transfer, func, request, &err)) {
if (request != NULL)
@@ -592,19 +582,16 @@ static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
{
struct pending_request *request;
struct obc_transfer *transfer;
- guint8 buf[272];
- gsize len;
GError *err = NULL;
DBusMessage *reply;
- len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
- g_obex_apparam_free(apparam);
-
transfer = obc_transfer_get("x-bt/vcard-listing", name, NULL, &err);
- if (transfer == NULL)
+ if (transfer == NULL) {
+ g_obex_apparam_free(apparam);
goto fail;
+ }
- obc_transfer_set_params(transfer, buf, len);
+ obc_transfer_set_apparam(transfer, apparam);
request = pending_request_new(pbap, message);
if (obc_session_queue(pbap->session, transfer,
@@ -711,17 +698,14 @@ static DBusMessage *pull_vcard(struct pbap_data *pbap, DBusMessage *message,
struct obc_transfer *transfer;
DBusMessage *reply;
GError *err = NULL;
- guint8 buf[32];
- gsize len;
-
- len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
- g_obex_apparam_free(apparam);
transfer = obc_transfer_get("x-bt/vcard", name, targetfile, &err);
- if (transfer == NULL)
+ if (transfer == NULL) {
+ g_obex_apparam_free(apparam);
goto fail;
+ }
- obc_transfer_set_params(transfer, buf, len);
+ obc_transfer_set_apparam(transfer, apparam);
if (!obc_session_queue(pbap->session, transfer, NULL, NULL, &err))
goto fail;
diff --git a/client/transfer.c b/client/transfer.c
index e9fabfb..bd5277b 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -57,15 +57,10 @@ struct transfer_callback {
void *data;
};
-struct obc_transfer_params {
- void *data;
- size_t size;
-};
-
struct obc_transfer {
GObex *obex;
+ GObexApparam *apparam;
guint8 op;
- struct obc_transfer_params *params;
struct transfer_callback *callback;
DBusConnection *conn;
DBusMessage *msg;
@@ -273,10 +268,8 @@ static void obc_transfer_free(struct obc_transfer *transfer)
if (transfer->fd > 0)
close(transfer->fd);
- if (transfer->params != NULL) {
- g_free(transfer->params->data);
- g_free(transfer->params);
- }
+ if (transfer->apparam != NULL)
+ g_obex_apparam_free(transfer->apparam);
if (transfer->conn)
dbus_connection_unref(transfer->conn);
@@ -529,6 +522,7 @@ static void get_xfer_progress_first(GObex *obex, GError *err, GObexPacket *rsp,
struct obc_transfer *transfer = user_data;
GObexPacket *req;
GObexHeader *hdr;
+ GObexApparam *apparam;
const guint8 *buf;
gsize len;
guint8 rspcode;
@@ -550,17 +544,9 @@ static void get_xfer_progress_first(GObex *obex, GError *err, GObexPacket *rsp,
hdr = g_obex_packet_get_header(rsp, G_OBEX_HDR_APPARAM);
if (hdr) {
- g_obex_header_get_bytes(hdr, &buf, &len);
- if (len != 0) {
- if (transfer->params == NULL)
- transfer->params =
- g_new0(struct obc_transfer_params, 1);
- else
- g_free(transfer->params->data);
-
- transfer->params->data = g_memdup(buf, len);
- transfer->params->size = len;
- }
+ apparam = g_obex_header_get_apparam(hdr);
+ if (apparam != NULL)
+ obc_transfer_set_apparam(transfer, apparam);
}
hdr = g_obex_packet_get_body(rsp);
@@ -642,6 +628,7 @@ static gboolean report_progress(gpointer data)
static gboolean transfer_start_get(struct obc_transfer *transfer, GError **err)
{
GObexPacket *req;
+ GObexHeader *hdr;
if (transfer->xfer > 0) {
g_set_error(err, OBC_TRANSFER_ERROR, -EALREADY,
@@ -659,10 +646,10 @@ static gboolean transfer_start_get(struct obc_transfer *transfer, GError **err)
g_obex_packet_add_bytes(req, G_OBEX_HDR_TYPE, transfer->type,
strlen(transfer->type) + 1);
- if (transfer->params != NULL)
- g_obex_packet_add_bytes(req, G_OBEX_HDR_APPARAM,
- transfer->params->data,
- transfer->params->size);
+ if (transfer->apparam != NULL) {
+ hdr = g_obex_header_new_apparam(transfer->apparam);
+ g_obex_packet_add_header(req, hdr);
+ }
transfer->xfer = g_obex_send_req(transfer->obex, req,
FIRST_PACKET_TIMEOUT,
@@ -683,6 +670,7 @@ static gboolean transfer_start_get(struct obc_transfer *transfer, GError **err)
static gboolean transfer_start_put(struct obc_transfer *transfer, GError **err)
{
GObexPacket *req;
+ GObexHeader *hdr;
if (transfer->xfer > 0) {
g_set_error(err, OBC_TRANSFER_ERROR, -EALREADY,
@@ -703,10 +691,10 @@ static gboolean transfer_start_put(struct obc_transfer *transfer, GError **err)
if (transfer->size < UINT32_MAX)
g_obex_packet_add_uint32(req, G_OBEX_HDR_LENGTH, transfer->size);
- if (transfer->params != NULL)
- g_obex_packet_add_bytes(req, G_OBEX_HDR_APPARAM,
- transfer->params->data,
- transfer->params->size);
+ if (transfer->apparam != NULL) {
+ hdr = g_obex_header_new_apparam(transfer->apparam);
+ g_obex_packet_add_header(req, hdr);
+ }
transfer->xfer = g_obex_put_req_pkt(transfer->obex, req,
put_xfer_progress, xfer_complete,
@@ -744,31 +732,20 @@ guint8 obc_transfer_get_operation(struct obc_transfer *transfer)
return transfer->op;
}
-void obc_transfer_set_params(struct obc_transfer *transfer,
- const void *data, size_t size)
+void obc_transfer_set_apparam(struct obc_transfer *transfer, void *data)
{
- if (transfer->params != NULL) {
- g_free(transfer->params->data);
- g_free(transfer->params);
- }
+ if (transfer->apparam != NULL)
+ g_obex_apparam_free(transfer->apparam);
if (data == NULL)
return;
- transfer->params = g_new0(struct obc_transfer_params, 1);
- transfer->params->data = g_memdup(data, size);
- transfer->params->size = size;
+ transfer->apparam = data;
}
-const void *obc_transfer_get_params(struct obc_transfer *transfer, size_t *size)
+void *obc_transfer_get_apparam(struct obc_transfer *transfer)
{
- if (transfer->params == NULL)
- return NULL;
-
- if (size != NULL)
- *size = transfer->params->size;
-
- return transfer->params->data;
+ return transfer->apparam;
}
int obc_transfer_get_contents(struct obc_transfer *transfer, char **contents,
diff --git a/client/transfer.h b/client/transfer.h
index 968903a..f7d0423 100644
--- a/client/transfer.h
+++ b/client/transfer.h
@@ -50,10 +50,8 @@ gboolean obc_transfer_start(struct obc_transfer *transfer, void *obex,
GError **err);
guint8 obc_transfer_get_operation(struct obc_transfer *transfer);
-void obc_transfer_set_params(struct obc_transfer *transfer,
- const void *data, size_t size);
-const void *obc_transfer_get_params(struct obc_transfer *transfer,
- size_t *size);
+void obc_transfer_set_apparam(struct obc_transfer *transfer, void *data);
+void *obc_transfer_get_apparam(struct obc_transfer *transfer);
int obc_transfer_get_contents(struct obc_transfer *transfer, char **contents,
size_t *size);
--
1.7.11.4
^ permalink raw reply related [flat|nested] 8+ messages in thread