From 003421aed298c52eacd5e58c120f877df5462ea0 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 30 Aug 2011 12:32:00 +0300 Subject: [PATCH] gobex: Add OBEX packet header addition convenience functions --- gobex/gobex-packet.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ gobex/gobex-packet.h | 6 ++++++ 2 files changed, 52 insertions(+) diff --git a/gobex/gobex-packet.c b/gobex/gobex-packet.c index 8303456c3..5765c8b4f 100644 --- a/gobex/gobex-packet.c +++ b/gobex/gobex-packet.c @@ -121,6 +121,52 @@ gboolean g_obex_packet_add_body(GObexPacket *pkt, GObexDataProducer func, return TRUE; } +gboolean g_obex_packet_add_unicode(GObexPacket *pkt, guint8 id, + const char *str) +{ + GObexHeader *hdr; + + hdr = g_obex_header_new_unicode(id, str); + if (hdr == NULL) + return FALSE; + + return g_obex_packet_add_header(pkt, hdr); +} + +gboolean g_obex_packet_add_bytes(GObexPacket *pkt, guint8 id, + const void *data, gsize len) +{ + GObexHeader *hdr; + + hdr = g_obex_header_new_bytes(id, data, len); + if (hdr == NULL) + return FALSE; + + return g_obex_packet_add_header(pkt, hdr); +} + +gboolean g_obex_packet_add_uint8(GObexPacket *pkt, guint8 id, guint8 val) +{ + GObexHeader *hdr; + + hdr = g_obex_header_new_uint8(id, val); + if (hdr == NULL) + return FALSE; + + return g_obex_packet_add_header(pkt, hdr); +} + +gboolean g_obex_packet_add_uint32(GObexPacket *pkt, guint8 id, guint32 val) +{ + GObexHeader *hdr; + + hdr = g_obex_header_new_uint32(id, val); + if (hdr == NULL) + return FALSE; + + return g_obex_packet_add_header(pkt, hdr); +} + const void *g_obex_packet_get_data(GObexPacket *pkt, gsize *len) { if (pkt->data_len == 0) { diff --git a/gobex/gobex-packet.h b/gobex/gobex-packet.h index ff6dcd295..6bdfcf039 100644 --- a/gobex/gobex-packet.h +++ b/gobex/gobex-packet.h @@ -89,6 +89,12 @@ gboolean g_obex_packet_prepend_header(GObexPacket *pkt, GObexHeader *header); gboolean g_obex_packet_add_header(GObexPacket *pkt, GObexHeader *header); gboolean g_obex_packet_add_body(GObexPacket *pkt, GObexDataProducer func, gpointer user_data); +gboolean g_obex_packet_add_unicode(GObexPacket *pkt, guint8 id, + const char *str); +gboolean g_obex_packet_add_bytes(GObexPacket *pkt, guint8 id, + const void *data, gsize len); +gboolean g_obex_packet_add_uint8(GObexPacket *pkt, guint8 id, guint8 val); +gboolean g_obex_packet_add_uint32(GObexPacket *pkt, guint8 id, guint32 val); gboolean g_obex_packet_set_data(GObexPacket *pkt, const void *data, gsize len, GObexDataPolicy data_policy); const void *g_obex_packet_get_data(GObexPacket *pkt, gsize *len); -- 2.47.3