summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2011-07-05 21:59:47 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2011-07-16 17:50:48 +0300
commitfcf11383f79312beac1d2dda7595cf546aff211e (patch)
tree3b67e6d6cd3d3691e61bf81e34bcb7060cc505e4 /tools
parentfe5c2167bb0075498ab0076a6bb6cb0f02ab87b5 (diff)
downloadobexd-fcf11383f79312beac1d2dda7595cf546aff211e.tar.gz
gobex: Add basic put request parsing to test-server
Diffstat (limited to 'tools')
-rw-r--r--tools/test-server.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/tools/test-server.c b/tools/test-server.c
index 37c95a5..92f4aa9 100644
--- a/tools/test-server.c
+++ b/tools/test-server.c
@@ -61,6 +61,38 @@ static void disconn_func(GObex *obex, GError *err, gpointer user_data)
g_obex_unref(obex);
}
+static guint8 handle_put(GObex *obex, GObexPacket *req)
+{
+ GObexHeader *hdr;
+ const char *type, *name;
+ gsize type_len;
+
+ hdr = g_obex_packet_find_header(req, G_OBEX_HDR_ID_TYPE);
+ if (hdr != NULL) {
+ g_obex_header_get_bytes(hdr, (const guint8 **) &type,
+ &type_len);
+ if (type[type_len - 1] != '\0') {
+ g_printerr("non-nul terminated type header\n");
+ type = NULL;
+ }
+ } else
+ type = NULL;
+
+ hdr = g_obex_packet_find_header(req, G_OBEX_HDR_ID_NAME);
+ if (hdr != NULL)
+ g_obex_header_get_unicode(hdr, &name);
+ else
+ name = NULL;
+
+ g_print("put type \"%s\" name \"%s\"\n", type ? type : "",
+ name ? name : "");
+
+ if (g_obex_packet_find_header(req, G_OBEX_HDR_ID_BODY))
+ return G_OBEX_RSP_CONTINUE;
+ else
+ return G_OBEX_RSP_SUCCESS;
+}
+
static void req_func(GObex *obex, GObexPacket *req, gpointer user_data)
{
gboolean final;
@@ -74,10 +106,7 @@ static void req_func(GObex *obex, GObexPacket *req, gpointer user_data)
rspcode = G_OBEX_RSP_SUCCESS;
break;
case G_OBEX_OP_PUT:
- if (g_obex_packet_find_header(req, G_OBEX_HDR_ID_BODY))
- rspcode = G_OBEX_RSP_CONTINUE;
- else
- rspcode = G_OBEX_RSP_SUCCESS;
+ rspcode = handle_put(obex, req);
break;
default:
rspcode = G_OBEX_RSP_NOT_IMPLEMENTED;