From c869ca28b82757500bb5c86d1f58cdcd9fe5ea52 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 10 Jul 2011 23:09:02 +0300 Subject: [PATCH] gobex: Make use of va-args headers in higher level functions --- gobex/gobex.c | 34 +++++++++++++--------------------- gobex/gobex.h | 6 +++--- tools/obex-client-tool.c | 2 +- unit/test-gobex.c | 2 +- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/gobex/gobex.c b/gobex/gobex.c index f98551ecb..8cd7f17bd 100644 --- a/gobex/gobex.c +++ b/gobex/gobex.c @@ -907,25 +907,21 @@ 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) +guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data, + GError **err, guint8 first_hdr_id, ...) { GObexPacket *req; struct connect_data data; + va_list args; - req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, G_OBEX_HDR_INVALID); + va_start(args, first_hdr_id); + req = g_obex_packet_new_valist(G_OBEX_OP_CONNECT, TRUE, + first_hdr_id, args); + va_end(args); init_connect_data(obex, &data); 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_TARGET, - target, target_len); - g_obex_packet_add_header(req, hdr); - } - return g_obex_send_req(obex, req, -1, func, user_data, err); } @@ -957,15 +953,13 @@ guint g_obex_mkdir(GObex *obex, const char *path, GObexResponseFunc func, gpointer user_data, GError **err) { GObexPacket *req; - GObexHeader *hdr; struct setpath_data data; - req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, G_OBEX_HDR_INVALID); + req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, + G_OBEX_HDR_NAME, path, + G_OBEX_HDR_INVALID); memset(&data, 0, sizeof(data)); - hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, path); - g_obex_packet_add_header(req, hdr); - g_obex_packet_set_data(req, &data, sizeof(data), G_OBEX_DATA_COPY); return g_obex_send_req(obex, req, -1, func, user_data, err); @@ -975,12 +969,10 @@ guint g_obex_delete(GObex *obex, const char *name, GObexResponseFunc func, gpointer user_data, GError **err) { GObexPacket *req; - GObexHeader *hdr; - - req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID); - hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, name); - g_obex_packet_add_header(req, hdr); + req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, + G_OBEX_HDR_NAME, name, + G_OBEX_HDR_INVALID); return g_obex_send_req(obex, req, -1, func, user_data, err); } diff --git a/gobex/gobex.h b/gobex/gobex.h index 1c0e17046..cfe923590 100644 --- a/gobex/gobex.h +++ b/gobex/gobex.h @@ -22,6 +22,7 @@ #ifndef __GOBEX_H #define __GOBEX_H +#include #include #include @@ -65,9 +66,8 @@ 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); +guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data, + GError **err, guint8 first_hdr_id, ...); guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func, gpointer user_data, GError **err); diff --git a/tools/obex-client-tool.c b/tools/obex-client-tool.c index 9b3279a24..a621ec241 100644 --- a/tools/obex-client-tool.c +++ b/tools/obex-client-tool.c @@ -112,7 +112,7 @@ static void conn_complete(GObex *obex, GError *err, GObexPacket *rsp, static void cmd_connect(int argc, char **argv) { - g_obex_connect(obex, NULL, 0, conn_complete, NULL, NULL); + g_obex_connect(obex, conn_complete, NULL, NULL, G_OBEX_HDR_INVALID); } struct put_data { diff --git a/unit/test-gobex.c b/unit/test-gobex.c index 005fe3e5f..bf363f43b 100644 --- a/unit/test-gobex.c +++ b/unit/test-gobex.c @@ -841,7 +841,7 @@ static void test_connect(void) timer_id = g_timeout_add_seconds(1, test_timeout, &d); - g_obex_connect(obex, NULL, 0, req_complete, &d, &d.err); + g_obex_connect(obex, req_complete, &d, &d.err, G_OBEX_HDR_INVALID); g_assert_no_error(d.err); g_main_loop_run(d.mainloop); -- 2.47.3