All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH obexd 1/6] MAP: Process incoming parameters in GET/PUT
@ 2012-03-14 22:54 Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 2/6] map_ap.c: Add implementation for map_ap_get_* Slawomir Bochenski
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Slawomir Bochenski @ 2012-03-14 22:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Slawomir Bochenski

---
 plugins/mas.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/plugins/mas.c b/plugins/mas.c
index 23b1823..8eefe5f 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -38,6 +38,7 @@
 #include "mimetype.h"
 #include "filesystem.h"
 #include "manager.h"
+#include "map_ap.h"
 
 #include "messages.h"
 
@@ -108,12 +109,31 @@ struct mas_session {
 	gboolean finished;
 	gboolean nth_call;
 	GString *buffer;
+	map_ap_t *inparams;
 };
 
 static const uint8_t MAS_TARGET[TARGET_SIZE] = {
 			0xbb, 0x58, 0x2b, 0x40, 0x42, 0x0c, 0x11, 0xdb,
 			0xb0, 0xde, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66  };
 
+static int get_params(struct obex_session *os, struct mas_session *mas)
+{
+	const uint8_t *buffer;
+	ssize_t size;
+
+	size = obex_get_apparam(os, &buffer);
+	if (size < 0)
+		size = 0;
+
+	mas->inparams = map_ap_decode(buffer, size);
+	if (mas->inparams == NULL) {
+		DBG("Error when parsing parameters!");
+		return -EBADR;
+	}
+
+	return 0;
+}
+
 static void reset_request(struct mas_session *mas)
 {
 	if (mas->buffer) {
@@ -121,6 +141,9 @@ static void reset_request(struct mas_session *mas)
 		mas->buffer = NULL;
 	}
 
+	map_ap_free(mas->inparams);
+	mas->inparams = NULL;
+
 	mas->nth_call = FALSE;
 	mas->finished = FALSE;
 }
@@ -178,6 +201,10 @@ static int mas_get(struct obex_session *os, void *user_data)
 	if (type == NULL)
 		return -EBADR;
 
+	ret = get_params(os, mas);
+	if (ret < 0)
+		goto failed;
+
 	ret = obex_get_stream_start(os, name);
 	if (ret < 0)
 		goto failed;
@@ -202,6 +229,10 @@ static int mas_put(struct obex_session *os, void *user_data)
 	if (type == NULL)
 		return -EBADR;
 
+	ret = get_params(os, mas);
+	if (ret < 0)
+		goto failed;
+
 	ret = obex_put_stream_start(os, name);
 	if (ret < 0)
 		goto failed;
-- 
1.7.5.1


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

* [PATCH obexd 2/6] map_ap.c: Add implementation for map_ap_get_*
  2012-03-14 22:54 [PATCH obexd 1/6] MAP: Process incoming parameters in GET/PUT Slawomir Bochenski
@ 2012-03-14 22:54 ` Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 3/6] MAP: Use input parameters for folder listing Slawomir Bochenski
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Slawomir Bochenski @ 2012-03-14 22:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Slawomir Bochenski

---
 src/map_ap.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/map_ap.c b/src/map_ap.c
index 54e3bcf..1f56748 100644
--- a/src/map_ap.c
+++ b/src/map_ap.c
@@ -246,22 +246,72 @@ uint8_t *map_ap_encode(map_ap_t *ap, size_t *length)
 
 gboolean map_ap_get_u8(map_ap_t *ap, enum map_ap_tag tag, uint8_t *val)
 {
-	return FALSE;
+	struct ap_entry *entry;
+	int offset = find_ap_def_offset(tag);
+
+	if (offset < 0 || ap_defs[offset].type != APT_UINT8)
+		return FALSE;
+
+
+	entry = g_hash_table_lookup(ap, GINT_TO_POINTER(tag));
+	if (entry == NULL)
+		return FALSE;
+
+	*val = entry->val.u8;
+
+	return TRUE;
 }
 
 gboolean map_ap_get_u16(map_ap_t *ap, enum map_ap_tag tag, uint16_t *val)
 {
-	return FALSE;
+	struct ap_entry *entry;
+	int offset = find_ap_def_offset(tag);
+
+	if (offset < 0 || ap_defs[offset].type != APT_UINT16)
+		return FALSE;
+
+
+	entry = g_hash_table_lookup(ap, GINT_TO_POINTER(tag));
+	if (entry == NULL)
+		return FALSE;
+
+	*val = entry->val.u16;
+
+	return TRUE;
 }
 
 gboolean map_ap_get_u32(map_ap_t *ap, enum map_ap_tag tag, uint32_t *val)
 {
-	return FALSE;
+	struct ap_entry *entry;
+	int offset = find_ap_def_offset(tag);
+
+	if (offset < 0 || ap_defs[offset].type != APT_UINT32)
+		return FALSE;
+
+
+	entry = g_hash_table_lookup(ap, GINT_TO_POINTER(tag));
+	if (entry == NULL)
+		return FALSE;
+
+	*val = entry->val.u32;
+
+	return TRUE;
 }
 
 const char *map_ap_get_string(map_ap_t *ap, enum map_ap_tag tag)
 {
-	return NULL;
+	struct ap_entry *entry;
+	int offset = find_ap_def_offset(tag);
+
+	if (offset < 0 || ap_defs[offset].type != APT_STR)
+		return NULL;
+
+
+	entry = g_hash_table_lookup(ap, GINT_TO_POINTER(tag));
+	if (entry == NULL)
+		return NULL;
+
+	return entry->val.str;
 }
 
 gboolean map_ap_set_u8(map_ap_t *ap, enum map_ap_tag tag, uint8_t val)
-- 
1.7.5.1


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

* [PATCH obexd 3/6] MAP: Use input parameters for folder listing
  2012-03-14 22:54 [PATCH obexd 1/6] MAP: Process incoming parameters in GET/PUT Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 2/6] map_ap.c: Add implementation for map_ap_get_* Slawomir Bochenski
@ 2012-03-14 22:54 ` Slawomir Bochenski
  2012-03-27 11:22   ` Johan Hedberg
  2012-03-14 22:54 ` [PATCH obexd 4/6] MAP: Add implementation of map_ap_encode() Slawomir Bochenski
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Slawomir Bochenski @ 2012-03-14 22:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Slawomir Bochenski

---
 plugins/mas.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/plugins/mas.c b/plugins/mas.c
index 8eefe5f..f6d4799 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -478,6 +478,9 @@ static void *folder_listing_open(const char *name, int oflag, mode_t mode,
 				void *driver_data, size_t *size, int *err)
 {
 	struct mas_session *mas = driver_data;
+	/* 1024 is the default when there was no MaxListCount sent */
+	uint16_t max = 1024;
+	uint16_t offset = 0;
 
 	if (oflag != O_RDONLY) {
 		*err = -EBADR;
@@ -486,9 +489,11 @@ static void *folder_listing_open(const char *name, int oflag, mode_t mode,
 
 	DBG("name = %s", name);
 
-	/* 1024 is the default when there was no MaxListCount sent */
-	*err = messages_get_folder_listing(mas->backend_data, name, 1024, 0,
-			get_folder_listing_cb, mas);
+	map_ap_get_u16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max);
+	map_ap_get_u16(mas->inparams, MAP_AP_STARTOFFSET, &offset);
+
+	*err = messages_get_folder_listing(mas->backend_data, name, max,
+					offset, get_folder_listing_cb, mas);
 
 	mas->buffer = g_string_new("");
 
-- 
1.7.5.1


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

* [PATCH obexd 4/6] MAP: Add implementation of map_ap_encode()
  2012-03-14 22:54 [PATCH obexd 1/6] MAP: Process incoming parameters in GET/PUT Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 2/6] map_ap.c: Add implementation for map_ap_get_* Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 3/6] MAP: Use input parameters for folder listing Slawomir Bochenski
@ 2012-03-14 22:54 ` Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 5/6] MAP: Initial outgoing parameters support Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 6/6] MAP: Output parameters in folder listing reply Slawomir Bochenski
  4 siblings, 0 replies; 7+ messages in thread
From: Slawomir Bochenski @ 2012-03-14 22:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Slawomir Bochenski

---
 src/map_ap.c |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/src/map_ap.c b/src/map_ap.c
index 1f56748..c852184 100644
--- a/src/map_ap.c
+++ b/src/map_ap.c
@@ -237,11 +237,98 @@ map_ap_t *map_ap_decode(const uint8_t *buffer, size_t length)
 	return ap;
 }
 
+static void ap_encode_u8(GString *buf, struct ap_entry *entry)
+{
+	struct obex_ap_header *hdr;
+
+	hdr = (struct obex_ap_header *)buf->str + buf->len;
+	g_string_set_size(buf, buf->len + sizeof(*hdr) + 1);
+
+	hdr->tag = entry->tag;
+	hdr->len = 1;
+	hdr->val[0] = entry->val.u8;
+}
+
+static void ap_encode_u16(GString *buf, struct ap_entry *entry)
+{
+	struct obex_ap_header *hdr;
+	uint16_t val;
+
+	hdr = (struct obex_ap_header *)buf->str + buf->len;
+
+	g_string_set_size(buf, buf->len + sizeof(*hdr) + 2);
+
+	hdr->tag = entry->tag;
+	hdr->len = 2;
+
+	val = GUINT16_TO_BE(entry->val.u16);
+	memcpy(hdr->val, &val, sizeof(val));
+}
+
+static void ap_encode_u32(GString *buf, struct ap_entry *entry)
+{
+	uint32_t val;
+	struct obex_ap_header *hdr;
+
+	hdr = (struct obex_ap_header *)buf->str + buf->len;
+	g_string_set_size(buf, buf->len + sizeof(*hdr) + 4);
+
+	hdr->tag = entry->tag;
+	hdr->len = 4;
+
+	val = GUINT32_TO_BE(entry->val.u16);
+	memcpy(hdr->val, &val, sizeof(val));
+}
+
+static void ap_encode_str(GString *buf, struct ap_entry *entry)
+{
+	size_t len;
+	struct obex_ap_header *hdr;
+
+	hdr = (struct obex_ap_header *)buf->str + buf->len;
+	len = strlen(entry->val.str);
+	g_string_set_size(buf, buf->len + sizeof(*hdr) + len);
+
+	hdr->tag = entry->tag;
+	hdr->len = len;
+
+	memcpy(hdr->val, entry->val.str, len);
+}
+
 uint8_t *map_ap_encode(map_ap_t *ap, size_t *length)
 {
-	*length = 0;
+	GString *buf;
+	GHashTableIter iter;
+	gpointer key, value;
+	struct ap_entry *entry;
+	int offset;
+
+	buf = g_string_new("");
+	g_hash_table_iter_init(&iter, ap);
+
+	while (g_hash_table_iter_next(&iter, &key, &value)) {
+		entry = (struct ap_entry *)value;
+		offset = find_ap_def_offset(entry->tag);
+
+		switch (ap_defs[offset].type) {
+		case APT_UINT8:
+			ap_encode_u8(buf, entry);
+			break;
+		case APT_UINT16:
+			ap_encode_u16(buf, entry);
+			break;
+		case APT_UINT32:
+			ap_encode_u32(buf, entry);
+			break;
+		case APT_STR:
+			ap_encode_str(buf, entry);
+			break;
+		}
+	}
+
+	*length = buf->len;
 
-	return NULL;
+	return (uint8_t *)g_string_free(buf, FALSE);
 }
 
 gboolean map_ap_get_u8(map_ap_t *ap, enum map_ap_tag tag, uint8_t *val)
-- 
1.7.5.1


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

* [PATCH obexd 5/6] MAP: Initial outgoing parameters support
  2012-03-14 22:54 [PATCH obexd 1/6] MAP: Process incoming parameters in GET/PUT Slawomir Bochenski
                   ` (2 preceding siblings ...)
  2012-03-14 22:54 ` [PATCH obexd 4/6] MAP: Add implementation of map_ap_encode() Slawomir Bochenski
@ 2012-03-14 22:54 ` Slawomir Bochenski
  2012-03-14 22:54 ` [PATCH obexd 6/6] MAP: Output parameters in folder listing reply Slawomir Bochenski
  4 siblings, 0 replies; 7+ messages in thread
From: Slawomir Bochenski @ 2012-03-14 22:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Slawomir Bochenski

---
 plugins/mas.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/plugins/mas.c b/plugins/mas.c
index f6d4799..ea2b4b2 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -110,6 +110,7 @@ struct mas_session {
 	gboolean nth_call;
 	GString *buffer;
 	map_ap_t *inparams;
+	map_ap_t *outparams;
 };
 
 static const uint8_t MAS_TARGET[TARGET_SIZE] = {
@@ -131,6 +132,8 @@ static int get_params(struct obex_session *os, struct mas_session *mas)
 		return -EBADR;
 	}
 
+	mas->outparams = map_ap_new();
+
 	return 0;
 }
 
@@ -143,6 +146,8 @@ static void reset_request(struct mas_session *mas)
 
 	map_ap_free(mas->inparams);
 	mas->inparams = NULL;
+	map_ap_free(mas->outparams);
+	mas->outparams = NULL;
 
 	mas->nth_call = FALSE;
 	mas->finished = FALSE;
-- 
1.7.5.1


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

* [PATCH obexd 6/6] MAP: Output parameters in folder listing reply
  2012-03-14 22:54 [PATCH obexd 1/6] MAP: Process incoming parameters in GET/PUT Slawomir Bochenski
                   ` (3 preceding siblings ...)
  2012-03-14 22:54 ` [PATCH obexd 5/6] MAP: Initial outgoing parameters support Slawomir Bochenski
@ 2012-03-14 22:54 ` Slawomir Bochenski
  4 siblings, 0 replies; 7+ messages in thread
From: Slawomir Bochenski @ 2012-03-14 22:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Slawomir Bochenski

This also introduces reusable any_get_next_header() that will be further
utilised in other requests returning application parameters header.
---
 plugins/mas.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/plugins/mas.c b/plugins/mas.c
index ea2b4b2..5d00ed1 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -25,11 +25,14 @@
 #include <config.h>
 #endif
 
+#include <string.h>
 #include <errno.h>
 #include <glib.h>
 #include <fcntl.h>
 #include <inttypes.h>
 
+#include <gobex/gobex.h>
+
 #include "obexd.h"
 #include "plugin.h"
 #include "log.h"
@@ -111,6 +114,7 @@ struct mas_session {
 	GString *buffer;
 	map_ap_t *inparams;
 	map_ap_t *outparams;
+	gboolean ap_sent;
 };
 
 static const uint8_t MAS_TARGET[TARGET_SIZE] = {
@@ -407,12 +411,26 @@ static void get_folder_listing_cb(void *session, int err, uint16_t size,
 					const char *name, void *user_data)
 {
 	struct mas_session *mas = user_data;
+	uint16_t max = 1024;
 
 	if (err < 0 && err != -EAGAIN) {
 		obex_object_set_io_flags(mas, G_IO_ERR, err);
 		return;
 	}
 
+	map_ap_get_u16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max);
+
+	if (max == 0) {
+		if (!err != -EAGAIN)
+			map_ap_set_u16(mas->outparams,
+					MAP_AP_FOLDERLISTINGSIZE, size);
+
+		if (!name)
+			mas->finished = TRUE;
+
+		goto proceed;
+	}
+
 	if (!mas->nth_call) {
 		g_string_append(mas->buffer, XML_DECL);
 		g_string_append(mas->buffer, FL_DTD);
@@ -578,6 +596,38 @@ static void *message_update_open(const char *name, int oflag, mode_t mode,
 		return mas;
 }
 
+static ssize_t any_get_next_header(void *object, void *buf, size_t mtu,
+								uint8_t *hi)
+{
+	struct mas_session *mas = object;
+	size_t len;
+	uint8_t *apbuf;
+
+	DBG("");
+
+	if (mas->buffer->len == 0 && !mas->finished)
+		return -EAGAIN;
+
+	*hi = G_OBEX_HDR_APPARAM;
+
+	if (mas->ap_sent)
+		return 0;
+
+	mas->ap_sent = TRUE;
+	apbuf = map_ap_encode(mas->outparams, &len);
+
+	if (len > mtu) {
+		DBG("MTU is to small to fit application parameters header!");
+		g_free(apbuf);
+
+		return -EIO;
+	}
+
+	memcpy(buf, apbuf, len);
+
+	return len;
+}
+
 static void *any_open(const char *name, int oflag, mode_t mode,
 				void *driver_data, size_t *size, int *err)
 {
@@ -663,6 +713,7 @@ static struct obex_mime_type_driver mime_folder_listing = {
 	.target = MAS_TARGET,
 	.target_size = TARGET_SIZE,
 	.mimetype = "x-obex/folder-listing",
+	.get_next_header = any_get_next_header,
 	.open = folder_listing_open,
 	.close = any_close,
 	.read = any_read,
-- 
1.7.5.1


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

* Re: [PATCH obexd 3/6] MAP: Use input parameters for folder listing
  2012-03-14 22:54 ` [PATCH obexd 3/6] MAP: Use input parameters for folder listing Slawomir Bochenski
@ 2012-03-27 11:22   ` Johan Hedberg
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2012-03-27 11:22 UTC (permalink / raw)
  To: Slawomir Bochenski; +Cc: linux-bluetooth

Hi Slawek,

On Wed, Mar 14, 2012, Slawomir Bochenski wrote:
> ---
>  plugins/mas.c |   11 ++++++++---
>  1 files changed, 8 insertions(+), 3 deletions(-)

Patches 1-3 have been applied and I'm waiting for a resend of 4-6 with
the GByteArray changes we discussed on IRC.

Johan

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

end of thread, other threads:[~2012-03-27 11:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-14 22:54 [PATCH obexd 1/6] MAP: Process incoming parameters in GET/PUT Slawomir Bochenski
2012-03-14 22:54 ` [PATCH obexd 2/6] map_ap.c: Add implementation for map_ap_get_* Slawomir Bochenski
2012-03-14 22:54 ` [PATCH obexd 3/6] MAP: Use input parameters for folder listing Slawomir Bochenski
2012-03-27 11:22   ` Johan Hedberg
2012-03-14 22:54 ` [PATCH obexd 4/6] MAP: Add implementation of map_ap_encode() Slawomir Bochenski
2012-03-14 22:54 ` [PATCH obexd 5/6] MAP: Initial outgoing parameters support Slawomir Bochenski
2012-03-14 22:54 ` [PATCH obexd 6/6] MAP: Output parameters in folder listing reply Slawomir Bochenski

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.