From 0794989ac8cd62fc4818b82873c22ebedae3a12a Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 4 Jul 2011 16:21:45 +0300 Subject: [PATCH] gobex: Add convenience function for sending connect req --- gobex/gobex.c | 31 +++++++++++++++++++++++++++++++ gobex/gobex.h | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/gobex/gobex.c b/gobex/gobex.c index 26ec5c33d..2e9d3bb20 100644 --- a/gobex/gobex.c +++ b/gobex/gobex.c @@ -740,3 +740,34 @@ void g_obex_unref(GObex *obex) g_free(obex); } + +/* Higher level functions */ + +guint g_obex_connect(GObex *obex, void *target, gsize target_len, + GObexResponseFunc func, gpointer user_data, + GError **err) +{ + GObexPacket *req; + struct connect_data data; + guint16 u16; + + req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE); + + memset(&data, 0, sizeof(data)); + data.version = 0x10; + data.flags = 0; + u16 = g_htons(obex->rx_mtu); + memcpy(&data.mtu, &u16, sizeof(u16)); + + g_obex_packet_set_data(req, &data, sizeof(data), G_OBEX_DATA_COPY); + + if (target != NULL) { + GObexHeader *hdr; + hdr = g_obex_header_new_bytes(G_OBEX_HDR_ID_TARGET, + target, target_len, + G_OBEX_DATA_COPY); + g_obex_packet_add_header(req, hdr); + } + + return g_obex_send_req(obex, req, -1, func, user_data, err); +} diff --git a/gobex/gobex.h b/gobex/gobex.h index 2111588fa..ce307c041 100644 --- a/gobex/gobex.h +++ b/gobex/gobex.h @@ -59,4 +59,10 @@ GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type, GObex *g_obex_ref(GObex *obex); void g_obex_unref(GObex *obex); +/* Higher level functions */ + +guint g_obex_connect(GObex *obex, void *target, gsize target_len, + GObexResponseFunc func, gpointer user_data, + GError **err); + #endif /* __GOBEX_H */ -- 2.47.3