Diff between 8d7a30ff3e322e1c4aeb902767a4cf91ce7993be and 1b609bec8e4d6d93dd9d13c5b424f953d33a2f97

Changed Files

File Additions Deletions Status
gobex/gobex.c +24 -0 modified
gobex/gobex.h +3 -0 modified
unit/test-gobex.c +45 -0 modified

Full Patch

diff --git a/gobex/gobex.c b/gobex/gobex.c
index d0de3d9..e91e59a 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -923,3 +923,27 @@ guint g_obex_connect(GObex *obex, void *target, gsize target_len,
 
 	return g_obex_send_req(obex, req, -1, func, user_data, err);
 }
+
+guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
+					gpointer user_data, GError **err)
+{
+	GObexPacket *req;
+	struct setpath_data data;
+
+	req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, NULL);
+
+	memset(&data, 0, sizeof(data));
+
+	if (strcmp(path, "..") == 0)
+		data.flags = 0x03;
+	else {
+		GObexHeader *hdr;
+		data.flags = 0x02;
+		hdr = g_obex_header_new_unicode(G_OBEX_HDR_ID_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);
+}
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 318add9..c0b84e7 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -69,4 +69,7 @@ guint g_obex_connect(GObex *obex, void *target, gsize target_len,
 				GObexResponseFunc func, gpointer user_data,
 				GError **err);
 
+guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
+					gpointer user_data, GError **err);
+
 #endif /* __GOBEX_H */
diff --git a/unit/test-gobex.c b/unit/test-gobex.c
index 41fe3ea..dbe1836 100644
--- a/unit/test-gobex.c
+++ b/unit/test-gobex.c
@@ -39,6 +39,13 @@ static uint8_t pkt_connect_req[] = { G_OBEX_OP_CONNECT | FINAL_BIT,
 					0x00, 0x07, 0x10, 0x00, 0x10, 0x00 };
 static uint8_t pkt_connect_rsp[] = { 0x10 | FINAL_BIT, 0x00, 0x07,
 					0x10, 0x00, 0x10, 0x00 };
+
+static uint8_t pkt_setpath_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x10,
+					0x02, 0x00,
+					G_OBEX_HDR_ID_NAME, 0x00, 0x0b,
+					0, 'd', 0, 'i', 0, 'r', 0, 0 };
+static uint8_t pkt_setpath_rsp[] = { 0x20 | FINAL_BIT, 0x00, 0x03 };
+
 static uint8_t pkt_nval_connect_rsp[] = { 0x10 | FINAL_BIT, 0x00, 0x05,
 					0x10, 0x00, };
 static uint8_t pkt_abort_rsp[] = { 0x90, 0x00, 0x03 };
@@ -839,6 +846,42 @@ static void test_connect(void)
 	g_assert_no_error(d.err);
 }
 
+static void test_setpath(void)
+{
+	GIOChannel *io;
+	GIOCondition cond;
+	guint io_id, timer_id;
+	GObex *obex;
+	struct test_data d = { 0, NULL, {
+				{ pkt_setpath_req, sizeof(pkt_setpath_req) } }, {
+				{ pkt_setpath_rsp, sizeof(pkt_setpath_rsp) } } };
+
+	create_endpoints(&obex, &io, SOCK_STREAM);
+
+	cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
+	io_id = g_io_add_watch(io, cond, test_io_cb, &d);
+
+	d.mainloop = g_main_loop_new(NULL, FALSE);
+
+	timer_id = g_timeout_add_seconds(1, test_timeout, &d);
+
+	g_obex_setpath(obex, "dir", req_complete, &d, &d.err);
+	g_assert_no_error(d.err);
+
+	g_main_loop_run(d.mainloop);
+
+	g_assert_cmpuint(d.count, ==, 1);
+
+	g_main_loop_unref(d.mainloop);
+
+	g_source_remove(timer_id);
+	g_io_channel_unref(io);
+	g_source_remove(io_id);
+	g_obex_unref(obex);
+
+	g_assert_no_error(d.err);
+}
+
 int main(int argc, char *argv[])
 {
 	g_test_init(&argc, &argv, NULL);
@@ -892,6 +935,8 @@ int main(int argc, char *argv[])
 
 	g_test_add_func("/gobex/test_connect", test_connect);
 
+	g_test_add_func("/gobex/test_setpath", test_setpath);
+
 	g_test_run();
 
 	return 0;