summaryrefslogtreecommitdiff
path: root/gobex/gobex-header.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2011-07-10 21:36:47 +0300
committerMarcel Holtmann <marcel@holtmann.org>2012-12-04 22:22:01 +0100
commitcdcde596874e3a698b674c4ef0c47f13232bbe8c (patch)
tree1dee711fee65a9e46c0c06d0f22ab4d08d3c2bd6 /gobex/gobex-header.c
parentf8e95ce529bd2e65473d9dcd0c8540f664a76393 (diff)
downloadbluez-cdcde596874e3a698b674c4ef0c47f13232bbe8c.tar.gz
gobex: Add va-args based packet creation support
Diffstat (limited to 'gobex/gobex-header.c')
-rw-r--r--gobex/gobex-header.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/gobex/gobex-header.c b/gobex/gobex-header.c
index 1e5e534ac..bf7dc9d7c 100644
--- a/gobex/gobex-header.c
+++ b/gobex/gobex-header.c
@@ -397,3 +397,48 @@ guint16 g_obex_header_get_length(GObexHeader *header)
{
return header->hlen;
}
+
+GSList *g_obex_header_create_list(guint8 first_hdr_id, va_list args,
+ gsize *total_len)
+{
+ unsigned int id = first_hdr_id;
+ GSList *l = NULL;
+
+ *total_len = 0;
+
+ while (id != G_OBEX_HDR_ID_INVALID) {
+ GObexHeader *hdr;
+ const char *str;
+ const void *bytes;
+ unsigned int val;
+ gsize len;
+
+ switch (G_OBEX_HDR_TYPE(id)) {
+ case G_OBEX_HDR_TYPE_UNICODE:
+ str = va_arg(args, const char *);
+ hdr = g_obex_header_new_unicode(id, str);
+ break;
+ case G_OBEX_HDR_TYPE_BYTES:
+ bytes = va_arg(args, void *);
+ len = va_arg(args, gsize);
+ hdr = g_obex_header_new_bytes(id, bytes, len);
+ break;
+ case G_OBEX_HDR_TYPE_UINT8:
+ val = va_arg(args, unsigned int);
+ hdr = g_obex_header_new_uint8(id, val);
+ break;
+ case G_OBEX_HDR_TYPE_UINT32:
+ val = va_arg(args, unsigned int);
+ hdr = g_obex_header_new_uint32(id, val);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ l = g_slist_append(l, hdr);
+ *total_len += hdr->hlen;
+ id = va_arg(args, int);
+ }
+
+ return l;
+}