summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2011-07-05 22:51:46 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2011-07-16 17:50:48 +0300
commit90169c268f914d9e93d94e3ad8c39633a09949e0 (patch)
treecdf11f79eaa053012978c4658fff8da649c4f66a /tools
parent7e9ecb3add595c578521f87db40956bd02928c4d (diff)
downloadobexd-90169c268f914d9e93d94e3ad8c39633a09949e0.tar.gz
gobex: Update test-server to use per-opcode request handlers
Diffstat (limited to 'tools')
-rw-r--r--tools/test-server.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/tools/test-server.c b/tools/test-server.c
index 92f4aa9..4864add 100644
--- a/tools/test-server.c
+++ b/tools/test-server.c
@@ -61,8 +61,9 @@ static void disconn_func(GObex *obex, GError *err, gpointer user_data)
g_obex_unref(obex);
}
-static guint8 handle_put(GObex *obex, GObexPacket *req)
+static void handle_put(GObex *obex, GObexPacket *req, gpointer user_data)
{
+ GObexPacket *rsp;
GObexHeader *hdr;
const char *type, *name;
gsize type_len;
@@ -88,32 +89,20 @@ static guint8 handle_put(GObex *obex, GObexPacket *req)
name ? name : "");
if (g_obex_packet_find_header(req, G_OBEX_HDR_ID_BODY))
- return G_OBEX_RSP_CONTINUE;
+ rsp = g_obex_packet_new(G_OBEX_RSP_CONTINUE, TRUE, NULL);
else
- return G_OBEX_RSP_SUCCESS;
+ rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, NULL);
+
+ g_obex_send(obex, rsp, NULL);
}
-static void req_func(GObex *obex, GObexPacket *req, gpointer user_data)
+static void handle_connect(GObex *obex, GObexPacket *req, gpointer user_data)
{
- gboolean final;
- guint8 rspcode, op = g_obex_packet_get_operation(req, &final);
GObexPacket *rsp;
- g_print("Request 0x%02x%s\n", op, final ? " (final)" : "");
-
- switch (op) {
- case G_OBEX_OP_CONNECT:
- rspcode = G_OBEX_RSP_SUCCESS;
- break;
- case G_OBEX_OP_PUT:
- rspcode = handle_put(obex, req);
- break;
- default:
- rspcode = G_OBEX_RSP_NOT_IMPLEMENTED;
- break;
- }
+ g_print("connect\n");
- rsp = g_obex_packet_new(rspcode, TRUE, NULL);
+ rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, NULL);
g_obex_send(obex, rsp, NULL);
}
@@ -161,7 +150,9 @@ static gboolean unix_accept(GIOChannel *chan, GIOCondition cond, gpointer data)
obex = g_obex_new(io, transport, -1, -1);
g_io_channel_unref(io);
g_obex_set_disconnect_function(obex, disconn_func, NULL);
- g_obex_set_request_function(obex, req_func, NULL);
+ g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put, NULL);
+ g_obex_add_request_function(obex, G_OBEX_OP_CONNECT, handle_connect,
+ NULL);
clients = g_slist_append(clients, obex);;
return TRUE;