gobex: Integrate GObexApparam with GObexHeader

This introduce 2 new convenient functions: g_obex_header_get_apparam
which parses and decode an header into GObexApparam and
gobex_header_new_apparam that encode GObexApparam into GObexHeader.
This commit is contained in:
Luiz Augusto von Dentz 2012-08-09 13:32:27 +03:00 committed by Marcel Holtmann
parent 2476a6cb13
commit 63d1b60c8c
2 changed files with 28 additions and 0 deletions

View File

@ -337,6 +337,19 @@ gboolean g_obex_header_get_bytes(GObexHeader *header, const guint8 **val,
return TRUE;
}
GObexApparam *g_obex_header_get_apparam(GObexHeader *header)
{
gboolean ret;
const guint8 *val;
gsize len;
ret = g_obex_header_get_bytes(header, &val, &len);
if (!ret)
return NULL;
return g_obex_apparam_decode(val, len);
}
gboolean g_obex_header_get_uint8(GObexHeader *header, guint8 *val)
{
g_obex_debug(G_OBEX_DEBUG_HEADER, "header 0x%02x",
@ -411,6 +424,18 @@ GObexHeader *g_obex_header_new_bytes(guint8 id, const void *data, gsize len)
return header;
}
GObexHeader *g_obex_header_new_apparam(GObexApparam *apparam)
{
guint8 buf[1024];
gssize len;
len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
if (len < 0)
return NULL;
return g_obex_header_new_bytes(G_OBEX_HDR_APPARAM, buf, len);
}
GObexHeader *g_obex_header_new_uint8(guint8 id, guint8 val)
{
GObexHeader *header;

View File

@ -25,6 +25,7 @@
#include <glib.h>
#include <gobex/gobex-defs.h>
#include <gobex/gobex-apparam.h>
/* Header ID's */
#define G_OBEX_HDR_INVALID 0x00
@ -77,11 +78,13 @@ gboolean g_obex_header_get_bytes(GObexHeader *header, const guint8 **val,
gsize *len);
gboolean g_obex_header_get_uint8(GObexHeader *header, guint8 *val);
gboolean g_obex_header_get_uint32(GObexHeader *header, guint32 *val);
GObexApparam *g_obex_header_get_apparam(GObexHeader *header);
GObexHeader *g_obex_header_new_unicode(guint8 id, const char *str);
GObexHeader *g_obex_header_new_bytes(guint8 id, const void *data, gsize len);
GObexHeader *g_obex_header_new_uint8(guint8 id, guint8 val);
GObexHeader *g_obex_header_new_uint32(guint8 id, guint32 val);
GObexHeader *g_obex_header_new_apparam(GObexApparam *apparam);
GSList *g_obex_header_create_list(guint8 first_hdr_id, va_list args,
gsize *total_len);