From: Slawomir Bochenski <lkslawek@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Slawomir Bochenski <lkslawek@gmail.com>
Subject: [PATCH obexd v3 1/3] MAP: Add implementation of map_ap_encode()
Date: Tue, 27 Mar 2012 14:59:25 +0200 [thread overview]
Message-ID: <1332853167-13676-1-git-send-email-lkslawek@gmail.com> (raw)
---
v3: Add spaces after cast
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 b6a039a..6efc484 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(GByteArray *buf, struct ap_entry *entry)
+{
+ struct obex_ap_header *hdr;
+
+ hdr = (struct obex_ap_header *) buf->data + buf->len;
+ g_byte_array_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(GByteArray *buf, struct ap_entry *entry)
+{
+ struct obex_ap_header *hdr;
+ uint16_t val;
+
+ hdr = (struct obex_ap_header *) buf->data + buf->len;
+
+ g_byte_array_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(GByteArray *buf, struct ap_entry *entry)
+{
+ uint32_t val;
+ struct obex_ap_header *hdr;
+
+ hdr = (struct obex_ap_header *) buf->data + buf->len;
+ g_byte_array_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(GByteArray *buf, struct ap_entry *entry)
+{
+ size_t len;
+ struct obex_ap_header *hdr;
+
+ hdr = (struct obex_ap_header *) buf->data + buf->len;
+ len = strlen(entry->val.str);
+ g_byte_array_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;
+ GByteArray *buf;
+ GHashTableIter iter;
+ gpointer key, value;
+ struct ap_entry *entry;
+ int offset;
+
+ buf = g_byte_array_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 g_byte_array_free(buf, FALSE);
}
gboolean map_ap_get_u8(map_ap_t *ap, enum map_ap_tag tag, uint8_t *val)
--
1.7.4.1
next reply other threads:[~2012-03-27 12:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-27 12:59 Slawomir Bochenski [this message]
2012-03-27 12:59 ` [PATCH obexd v3 2/3] MAP: Initial outgoing parameters support Slawomir Bochenski
2012-03-27 12:59 ` [PATCH obexd v3 3/3] MAP: Output parameters in folder listing reply Slawomir Bochenski
2012-03-28 9:38 ` [PATCH obexd v3 1/3] MAP: Add implementation of map_ap_encode() Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1332853167-13676-1-git-send-email-lkslawek@gmail.com \
--to=lkslawek@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox