* [PATCH obexd 2/9] gobex: add unit test for CONNECT response
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 3/9] gobex: add unit test for CONNECT followed by GET request Luiz Augusto von Dentz
` (7 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
unit/test-gobex-transfer.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
unit/util.c | 3 ++
2 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index ac6356d..32dc8bb 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -668,11 +668,71 @@ static void test_conn_req(void)
g_assert_no_error(d.err);
}
+static void handle_conn_rsp(GObex *obex, GObexPacket *req,
+ gpointer user_data)
+{
+ struct test_data *d = user_data;
+ guint8 op = g_obex_packet_get_operation(req, NULL);
+ GObexPacket *rsp;
+
+ if (op != G_OBEX_OP_CONNECT) {
+ d->err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
+ "Unexpected opcode 0x%02x", op);
+ g_main_loop_quit(d->mainloop);
+ return;
+ }
+
+ rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, G_OBEX_HDR_INVALID);
+ g_obex_send(obex, rsp, &d->err);
+}
+
+static void test_conn_rsp(void)
+{
+ GIOChannel *io;
+ GIOCondition cond;
+ guint io_id, timer_id;
+ GObex *obex;
+ struct test_data d = { 0, NULL, {
+ { conn_rsp, sizeof(conn_rsp) } }, {
+ { NULL, 0 } } };
+
+ create_endpoints(&obex, &io, SOCK_STREAM);
+ d.obex = obex;
+
+ 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_add_request_function(obex, G_OBEX_OP_CONNECT,
+ handle_conn_rsp, &d);
+
+ g_io_channel_write_chars(io, (char *) conn_req, sizeof(conn_req),
+ NULL, &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);
g_test_add_func("/gobex/test_conn_req", test_conn_req);
+ g_test_add_func("/gobex/test_conn_rsp", test_conn_rsp);
g_test_add_func("/gobex/test_put_req", test_put_req);
g_test_add_func("/gobex/test_put_rsp", test_put_rsp);
diff --git a/unit/util.c b/unit/util.c
index 630a70e..5788654 100644
--- a/unit/util.c
+++ b/unit/util.c
@@ -166,6 +166,9 @@ gboolean test_io_cb(GIOChannel *io, GIOCondition cond, gpointer user_data)
goto failed;
}
+ if (send_buf_len == 0)
+ goto failed;
+
g_io_channel_write_chars(io, send_buf, send_buf_len, &bytes_written,
NULL);
if (bytes_written != send_buf_len) {
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH obexd 3/9] gobex: add unit test for CONNECT followed by GET request
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 2/9] gobex: add unit test for CONNECT response Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 15:02 ` Hendrik Sattler
2011-11-10 14:43 ` [PATCH obexd 4/9] gobex: add unit test for CONNECT followed by GET response Luiz Augusto von Dentz
` (6 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
unit/test-gobex-transfer.c | 68 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 68 insertions(+), 0 deletions(-)
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index 32dc8bb..9cb1f46 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -71,6 +71,13 @@ static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
0x00, 0x00, 0x01 };
+static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
+ G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
+ G_OBEX_HDR_TYPE, 0x00, 0x0b,
+ 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
+ G_OBEX_HDR_NAME, 0x00, 0x15,
+ 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
+
static guint8 hdr_type[] = "foo/bar";
static guint8 body_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -727,6 +734,65 @@ static void test_conn_rsp(void)
g_assert_no_error(d.err);
}
+static void conn_complete_get_req(GObex *obex, GError *err, GObexPacket *rsp,
+ gpointer user_data)
+{
+ struct test_data *d = user_data;
+
+ if (err != NULL) {
+ d->err = g_error_copy(err);
+ g_main_loop_quit(d->mainloop);
+ }
+
+ g_obex_get_req(obex, rcv_data, transfer_complete, d, &d->err,
+ G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
+ G_OBEX_HDR_NAME, "file.txt",
+ G_OBEX_HDR_INVALID);
+}
+
+static void test_conn_get_req(void)
+{
+ GIOChannel *io;
+ GIOCondition cond;
+ guint io_id, timer_id;
+ GObex *obex;
+ struct test_data d = { 0, NULL, {
+ { conn_req, sizeof(conn_req) },
+ { conn_get_req_first, sizeof(conn_get_req_first) },
+ { get_req_last, sizeof(get_req_last) }}, {
+ { conn_rsp, sizeof(conn_rsp) } ,
+ { get_rsp_first, sizeof(get_rsp_first) },
+ { get_rsp_last, sizeof(get_rsp_last) } } };
+
+ create_endpoints(&obex, &io, SOCK_STREAM);
+ d.obex = obex;
+ d.provide_delay = 200;
+
+ 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_connect(obex, conn_complete_get_req, &d, &d.err,
+ G_OBEX_HDR_INVALID);
+ g_assert_no_error(d.err);
+
+ g_main_loop_run(d.mainloop);
+
+ g_assert_cmpuint(d.count, ==, 3);
+
+ 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);
@@ -748,6 +814,8 @@ int main(int argc, char *argv[])
g_test_add_func("/gobex/test_put_req_random", test_put_req_random);
+ g_test_add_func("/gobex/test_conn_get_req", test_conn_get_req);
+
g_test_run();
return 0;
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH obexd 3/9] gobex: add unit test for CONNECT followed by GET request
2011-11-10 14:43 ` [PATCH obexd 3/9] gobex: add unit test for CONNECT followed by GET request Luiz Augusto von Dentz
@ 2011-11-10 15:02 ` Hendrik Sattler
2011-11-11 9:00 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 15+ messages in thread
From: Hendrik Sattler @ 2011-11-10 15:02 UTC (permalink / raw)
To: linux-bluetooth
Am 10.11.2011 15:43, schrieb Luiz Augusto von Dentz:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> ---
> unit/test-gobex-transfer.c | 68
> ++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 68 insertions(+), 0 deletions(-)
>
> diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
> index 32dc8bb..9cb1f46 100644
> --- a/unit/test-gobex-transfer.c
> +++ b/unit/test-gobex-transfer.c
> @@ -71,6 +71,13 @@ static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS |
> FINAL_BIT, 0x00, 0x0c,
> 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
> 0x00, 0x00, 0x01 };
>
> +static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT,
> 0x00, 0x28,
> + G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
> + G_OBEX_HDR_TYPE, 0x00, 0x0b,
> + 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
> + G_OBEX_HDR_NAME, 0x00, 0x15,
> + 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0,
> 0 };
If you want the test data to be realistic: when targetting default OBEX
inbox, you can only use type _or_ name, not both.
HS
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH obexd 3/9] gobex: add unit test for CONNECT followed by GET request
2011-11-10 15:02 ` Hendrik Sattler
@ 2011-11-11 9:00 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-11 9:00 UTC (permalink / raw)
To: Hendrik Sattler; +Cc: linux-bluetooth
Hi Hendrik,
On Thu, Nov 10, 2011 at 5:02 PM, Hendrik Sattler
<post@hendrik-sattler.de> wrote:
> Am 10.11.2011 15:43, schrieb Luiz Augusto von Dentz:
>>
>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>
>> ---
>> unit/test-gobex-transfer.c | 68
>> ++++++++++++++++++++++++++++++++++++++++++++
>> 1 files changed, 68 insertions(+), 0 deletions(-)
>>
>> diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
>> index 32dc8bb..9cb1f46 100644
>> --- a/unit/test-gobex-transfer.c
>> +++ b/unit/test-gobex-transfer.c
>> @@ -71,6 +71,13 @@ static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS |
>> FINAL_BIT, 0x00, 0x0c,
>> 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
>> 0x00, 0x00, 0x01 };
>>
>> +static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT,
>> 0x00, 0x28,
>> + G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
>> + G_OBEX_HDR_TYPE, 0x00, 0x0b,
>> + 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
>> + G_OBEX_HDR_NAME, 0x00, 0x15,
>> + 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0,
>> 0 };
>
> If you want the test data to be realistic: when targetting default OBEX
> inbox, you can only use type _or_ name, not both.
For OBEX/Bluetooth specific types it can be true, but type can also be
used as a regular mime-type/RFC 1521, maybe the type in this case is
not realistic and we should be using text/plain.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH obexd 4/9] gobex: add unit test for CONNECT followed by GET response
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 2/9] gobex: add unit test for CONNECT response Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 3/9] gobex: add unit test for CONNECT followed by GET request Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 5/9] gobex: add unit test for CONNECT followed by PUT request Luiz Augusto von Dentz
` (5 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
unit/test-gobex-transfer.c | 59 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 58 insertions(+), 1 deletions(-)
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index 9cb1f46..95d4a93 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -70,6 +70,9 @@ static guint8 conn_req[] = { G_OBEX_OP_CONNECT | FINAL_BIT, 0x00, 0x07,
static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
0x00, 0x00, 0x01 };
+static guint8 conn_rsp_2[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
+ 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
+ 0x00, 0x00, 0x02 };
static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
@@ -77,6 +80,12 @@ static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
G_OBEX_HDR_NAME, 0x00, 0x15,
0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
+static guint8 conn_get_req_first_2[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
+ G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x02,
+ G_OBEX_HDR_TYPE, 0x00, 0x0b,
+ 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
+ G_OBEX_HDR_NAME, 0x00, 0x15,
+ 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
static guint8 hdr_type[] = "foo/bar";
static guint8 body_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -766,7 +775,6 @@ static void test_conn_get_req(void)
create_endpoints(&obex, &io, SOCK_STREAM);
d.obex = obex;
- d.provide_delay = 200;
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);
@@ -793,6 +801,54 @@ static void test_conn_get_req(void)
g_assert_no_error(d.err);
}
+static void test_conn_get_rsp(void)
+{
+ GIOChannel *io;
+ GIOCondition cond;
+ guint io_id, timer_id;
+ GObex *obex;
+ struct test_data d = { 0, NULL, {
+ { conn_rsp_2, sizeof(conn_rsp_2) },
+ { get_rsp_first, sizeof(get_rsp_first) },
+ { get_rsp_last, sizeof(get_rsp_last) } }, {
+ { conn_get_req_first_2, sizeof(conn_get_req_first_2) },
+ { get_req_last, sizeof(get_req_last) },
+ { NULL, 0 } } };
+
+ create_endpoints(&obex, &io, SOCK_STREAM);
+ d.obex = obex;
+
+ 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_add_request_function(obex, G_OBEX_OP_CONNECT,
+ handle_conn_rsp, &d);
+
+ g_obex_add_request_function(obex, G_OBEX_OP_GET,
+ handle_get, &d);
+
+ g_io_channel_write_chars(io, (char *) conn_req, sizeof(conn_req),
+ NULL, &d.err);
+ g_assert_no_error(d.err);
+
+ g_main_loop_run(d.mainloop);
+
+ g_assert_cmpuint(d.count, ==, 2);
+
+ 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);
@@ -815,6 +871,7 @@ int main(int argc, char *argv[])
g_test_add_func("/gobex/test_put_req_random", test_put_req_random);
g_test_add_func("/gobex/test_conn_get_req", test_conn_get_req);
+ g_test_add_func("/gobex/test_conn_get_rsp", test_conn_get_rsp);
g_test_run();
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH obexd 5/9] gobex: add unit test for CONNECT followed by PUT request
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
` (2 preceding siblings ...)
2011-11-10 14:43 ` [PATCH obexd 4/9] gobex: add unit test for CONNECT followed by GET response Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 6/9] gobex: add unit test for CONNECT followed by PUT response Luiz Augusto von Dentz
` (4 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
unit/test-gobex-transfer.c | 76 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 75 insertions(+), 1 deletions(-)
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index 95d4a93..860f129 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -87,6 +87,15 @@ static guint8 conn_get_req_first_2[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
G_OBEX_HDR_NAME, 0x00, 0x15,
0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 };
+static guint8 conn_put_req_first[] = { G_OBEX_OP_PUT, 0x00, 0x35,
+ G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
+ G_OBEX_HDR_TYPE, 0x00, 0x0b,
+ 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
+ G_OBEX_HDR_NAME, 0x00, 0x15,
+ 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
+ G_OBEX_HDR_BODY, 0x00, 0x0d,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
static guint8 hdr_type[] = "foo/bar";
static guint8 body_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -156,9 +165,12 @@ static gssize provide_eagain(void *buf, gsize len, gpointer user_data)
static gssize provide_data(void *buf, gsize len, gpointer user_data)
{
struct test_data *d = user_data;
+ static int count = 0;
- if (d->count > 0)
+ if (count > 0) {
+ count = 0;
return 0;
+ }
if (len < sizeof(body_data)) {
g_set_error(&d->err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
@@ -174,6 +186,8 @@ static gssize provide_data(void *buf, gsize len, gpointer user_data)
g_timeout_add(d->provide_delay, resume_obex, d->obex);
}
+ count++;
+
return sizeof(body_data);
}
@@ -849,6 +863,64 @@ static void test_conn_get_rsp(void)
g_assert_no_error(d.err);
}
+static void conn_complete_put_req(GObex *obex, GError *err, GObexPacket *rsp,
+ gpointer user_data)
+{
+ struct test_data *d = user_data;
+
+ if (err != NULL) {
+ d->err = g_error_copy(err);
+ g_main_loop_quit(d->mainloop);
+ }
+
+ g_obex_put_req(obex, provide_data, transfer_complete, d, &d->err,
+ G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
+ G_OBEX_HDR_NAME, "file.txt",
+ G_OBEX_HDR_INVALID);
+}
+
+static void test_conn_put_req(void)
+{
+ GIOChannel *io;
+ GIOCondition cond;
+ guint io_id, timer_id;
+ GObex *obex;
+ struct test_data d = { 0, NULL, {
+ { conn_req, sizeof(conn_req) },
+ { conn_put_req_first, sizeof(conn_put_req_first) },
+ { put_req_last, sizeof(put_req_last) }}, {
+ { conn_rsp, sizeof(conn_rsp) } ,
+ { put_rsp_first, sizeof(put_rsp_first) },
+ { put_rsp_last, sizeof(put_rsp_last) } } };
+
+ create_endpoints(&obex, &io, SOCK_STREAM);
+ d.obex = obex;
+
+ 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_connect(obex, conn_complete_put_req, &d, &d.err,
+ G_OBEX_HDR_INVALID);
+ g_assert_no_error(d.err);
+
+ g_main_loop_run(d.mainloop);
+
+ g_assert_cmpuint(d.count, ==, 3);
+
+ 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);
@@ -873,6 +945,8 @@ int main(int argc, char *argv[])
g_test_add_func("/gobex/test_conn_get_req", test_conn_get_req);
g_test_add_func("/gobex/test_conn_get_rsp", test_conn_get_rsp);
+ g_test_add_func("/gobex/test_conn_put_req", test_conn_put_req);
+
g_test_run();
return 0;
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH obexd 6/9] gobex: add unit test for CONNECT followed by PUT response
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
` (3 preceding siblings ...)
2011-11-10 14:43 ` [PATCH obexd 5/9] gobex: add unit test for CONNECT followed by PUT request Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 15:25 ` Hendrik Sattler
2011-11-10 14:43 ` [PATCH obexd 7/9] gobex: fix checking connection id for ABORT Luiz Augusto von Dentz
` (3 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
unit/test-gobex-transfer.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index 860f129..f3eb0bf 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -73,6 +73,9 @@ static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
static guint8 conn_rsp_2[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
0x00, 0x00, 0x02 };
+static guint8 conn_rsp_3[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
+ 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
+ 0x00, 0x00, 0x03 };
static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x28,
G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
@@ -95,6 +98,14 @@ static guint8 conn_put_req_first[] = { G_OBEX_OP_PUT, 0x00, 0x35,
0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
G_OBEX_HDR_BODY, 0x00, 0x0d,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+static guint8 conn_put_req_first_3[] = { G_OBEX_OP_PUT, 0x00, 0x35,
+ G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x03,
+ G_OBEX_HDR_TYPE, 0x00, 0x0b,
+ 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
+ G_OBEX_HDR_NAME, 0x00, 0x15,
+ 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0,
+ G_OBEX_HDR_BODY, 0x00, 0x0d,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
static guint8 hdr_type[] = "foo/bar";
static guint8 body_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -921,6 +932,54 @@ static void test_conn_put_req(void)
g_assert_no_error(d.err);
}
+static void test_conn_put_rsp(void)
+{
+ GIOChannel *io;
+ GIOCondition cond;
+ guint io_id, timer_id;
+ GObex *obex;
+ struct test_data d = { 0, NULL, {
+ { conn_rsp_3, sizeof(conn_rsp_3) },
+ { put_rsp_first, sizeof(put_rsp_first) },
+ { put_rsp_last, sizeof(put_rsp_last) } }, {
+ { conn_put_req_first_3, sizeof(conn_put_req_first_3) },
+ { put_req_last, sizeof(put_req_last) },
+ { NULL, 0 } } };
+
+ create_endpoints(&obex, &io, SOCK_STREAM);
+ d.obex = obex;
+
+ 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_add_request_function(obex, G_OBEX_OP_CONNECT,
+ handle_conn_rsp, &d);
+
+ g_obex_add_request_function(obex, G_OBEX_OP_PUT,
+ handle_put, &d);
+
+ g_io_channel_write_chars(io, (char *) conn_req, sizeof(conn_req),
+ NULL, &d.err);
+ g_assert_no_error(d.err);
+
+ g_main_loop_run(d.mainloop);
+
+ g_assert_cmpuint(d.count, ==, 2);
+
+ 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);
@@ -946,6 +1005,7 @@ int main(int argc, char *argv[])
g_test_add_func("/gobex/test_conn_get_rsp", test_conn_get_rsp);
g_test_add_func("/gobex/test_conn_put_req", test_conn_put_req);
+ g_test_add_func("/gobex/test_conn_put_rsp", test_conn_put_rsp);
g_test_run();
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH obexd 6/9] gobex: add unit test for CONNECT followed by PUT response
2011-11-10 14:43 ` [PATCH obexd 6/9] gobex: add unit test for CONNECT followed by PUT response Luiz Augusto von Dentz
@ 2011-11-10 15:25 ` Hendrik Sattler
2011-11-11 9:04 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 15+ messages in thread
From: Hendrik Sattler @ 2011-11-10 15:25 UTC (permalink / raw)
To: linux-bluetooth
Am 10.11.2011 15:43, schrieb Luiz Augusto von Dentz:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> ---
> unit/test-gobex-transfer.c | 60
> ++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 60 insertions(+), 0 deletions(-)
>
> diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
> index 860f129..f3eb0bf 100644
> --- a/unit/test-gobex-transfer.c
> +++ b/unit/test-gobex-transfer.c
> @@ -73,6 +73,9 @@ static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS |
> FINAL_BIT, 0x00, 0x0c,
> static guint8 conn_rsp_2[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00,
> 0x0c,
> 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
> 0x00, 0x00, 0x02 };
> +static guint8 conn_rsp_3[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00,
> 0x0c,
> + 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
> + 0x00, 0x00, 0x03 };
>
> static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT,
> 0x00, 0x28,
> G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
> @@ -95,6 +98,14 @@ static guint8 conn_put_req_first[] = {
> G_OBEX_OP_PUT, 0x00, 0x35,
> 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0,
> 0,
> G_OBEX_HDR_BODY, 0x00, 0x0d,
> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
> +static guint8 conn_put_req_first_3[] = { G_OBEX_OP_PUT, 0x00, 0x35,
> + G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x03,
> + G_OBEX_HDR_TYPE, 0x00, 0x0b,
> + 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
> + G_OBEX_HDR_NAME, 0x00, 0x15,
> + 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0,
> 0,
> + G_OBEX_HDR_BODY, 0x00, 0x0d,
> + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Not BODY_END header?
HS
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH obexd 6/9] gobex: add unit test for CONNECT followed by PUT response
2011-11-10 15:25 ` Hendrik Sattler
@ 2011-11-11 9:04 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-11 9:04 UTC (permalink / raw)
To: Hendrik Sattler; +Cc: linux-bluetooth
Hi Hendrik,
On Thu, Nov 10, 2011 at 5:25 PM, Hendrik Sattler
<post@hendrik-sattler.de> wrote:
> Am 10.11.2011 15:43, schrieb Luiz Augusto von Dentz:
>>
>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>
>> ---
>> unit/test-gobex-transfer.c | 60
>> ++++++++++++++++++++++++++++++++++++++++++++
>> 1 files changed, 60 insertions(+), 0 deletions(-)
>>
>> diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
>> index 860f129..f3eb0bf 100644
>> --- a/unit/test-gobex-transfer.c
>> +++ b/unit/test-gobex-transfer.c
>> @@ -73,6 +73,9 @@ static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS |
>> FINAL_BIT, 0x00, 0x0c,
>> static guint8 conn_rsp_2[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00,
>> 0x0c,
>> 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
>> 0x00, 0x00, 0x02 };
>> +static guint8 conn_rsp_3[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00,
>> 0x0c,
>> + 0x10, 0x00, 0x10, 0x00, 0xcb,
>> 0x00,
>> + 0x00, 0x00, 0x03 };
>>
>> static guint8 conn_get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT,
>> 0x00, 0x28,
>> G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x01,
>> @@ -95,6 +98,14 @@ static guint8 conn_put_req_first[] = {
>> G_OBEX_OP_PUT, 0x00, 0x35,
>> 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0,
>> 0,
>> G_OBEX_HDR_BODY, 0x00, 0x0d,
>> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
>> +static guint8 conn_put_req_first_3[] = { G_OBEX_OP_PUT, 0x00, 0x35,
>> + G_OBEX_HDR_CONNECTION, 0x00, 0x00, 0x00, 0x03,
>> + G_OBEX_HDR_TYPE, 0x00, 0x0b,
>> + 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0',
>> + G_OBEX_HDR_NAME, 0x00, 0x15,
>> + 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0,
>> 0,
>> + G_OBEX_HDR_BODY, 0x00, 0x0d,
>> + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
>
> Not BODY_END header?
BODY_END is sent in a separated packet, see put_req_last, although it
is probably a good idea to add testes which send it in the same
packet.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH obexd 7/9] gobex: fix checking connection id for ABORT
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
` (4 preceding siblings ...)
2011-11-10 14:43 ` [PATCH obexd 6/9] gobex: add unit test for CONNECT followed by PUT response Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 8/9] gobex: fix sending Connection ID header in all requests Luiz Augusto von Dentz
` (2 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
OBEX spec state that it is optional to send a Connection Id header in an
OBEX ABORT operation.
Reported by Hendrik Sattler <post@hendrik-sattler.de>
---
gobex/gobex.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/gobex/gobex.c b/gobex/gobex.c
index 86e1c4a..b0f3716 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -705,9 +705,16 @@ static void handle_request(GObex *obex, GObexPacket *req)
op = g_obex_packet_get_operation(req, NULL);
- if (op == G_OBEX_OP_CONNECT)
+ switch (op) {
+ case G_OBEX_OP_CONNECT:
parse_connect_data(obex, req);
- else if (check_connid(obex, req) == FALSE) {
+ break;
+ case G_OBEX_OP_ABORT:
+ break;
+ default:
+ if (check_connid(obex, req))
+ break;
+
g_obex_debug(G_OBEX_DEBUG_ERROR, "Invalid Connection ID");
g_obex_send_rsp(obex, G_OBEX_RSP_SERVICE_UNAVAILABLE, NULL,
G_OBEX_HDR_INVALID);
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH obexd 8/9] gobex: fix sending Connection ID header in all requests
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
` (5 preceding siblings ...)
2011-11-10 14:43 ` [PATCH obexd 7/9] gobex: fix checking connection id for ABORT Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 14:43 ` [PATCH obexd 9/9] gobex: make connection id check less strict Luiz Augusto von Dentz
2011-11-10 15:08 ` [PATCH obexd 1/9] gobex: add unit test for CONNECT request Hendrik Sattler
8 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
According to both OBEX and GOEP specs Connection ID should only be
included in the first packet of a request.
---
client/transfer.c | 7 +++----
gobex/gobex-transfer.c | 17 ++++++++++-------
gobex/gobex.c | 31 +++++++++++++++++++++----------
gobex/gobex.h | 6 +++---
unit/test-gobex.c | 6 +++---
5 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/client/transfer.c b/client/transfer.c
index b6994d1..d6d3e0d 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -375,9 +375,8 @@ static void get_buf_xfer_progress(GObex *obex, GError *err, GObexPacket *rsp,
req = g_obex_packet_new(G_OBEX_OP_GET, TRUE, G_OBEX_HDR_INVALID);
- transfer->xfer = g_obex_send_req(obex, req, -1, get_buf_xfer_progress,
- transfer, &err);
-
+ transfer->xfer = g_obex_send_req(obex, req, transfer->xfer, -1,
+ get_buf_xfer_progress, transfer, &err);
if (callback)
callback->func(transfer, transfer->transferred, err,
callback->data);
@@ -539,7 +538,7 @@ int obc_transfer_get(struct obc_transfer *transfer, transfer_callback_t func,
transfer->params->size);
if (rsp_cb)
- transfer->xfer = g_obex_send_req(obex, req, -1, rsp_cb,
+ transfer->xfer = g_obex_send_req(obex, req, 0, -1, rsp_cb,
transfer, &err);
else
transfer->xfer = g_obex_get_req_pkt(obex, req, data_cb,
diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index 6d2f7af..80e4781 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -121,7 +121,7 @@ static gssize put_get_data(void *buf, gsize len, gpointer user_data)
return ret;
req = g_obex_packet_new(G_OBEX_OP_ABORT, TRUE, G_OBEX_HDR_INVALID);
- transfer->req_id = g_obex_send_req(transfer->obex, req, -1,
+ transfer->req_id = g_obex_send_req(transfer->obex, req, 0, -1,
transfer_abort_response,
transfer, &err);
if (err != NULL) {
@@ -161,9 +161,11 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
struct transfer *transfer = user_data;
GObexPacket *req;
gboolean rspcode, final;
+ guint id;
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
+ id = transfer->req_id;
transfer->req_id = 0;
if (err != NULL) {
@@ -198,8 +200,9 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
G_OBEX_HDR_INVALID);
}
- transfer->req_id = g_obex_send_req(obex, req, -1, transfer_response,
- transfer, &err);
+ transfer->req_id = g_obex_send_req(obex, req, id, -1,
+ transfer_response, transfer,
+ &err);
failed:
if (err != NULL) {
g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", err->message);
@@ -245,7 +248,7 @@ guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
g_obex_packet_add_body(req, put_get_data, transfer);
- transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
+ transfer->req_id = g_obex_send_req(obex, req, 0, FIRST_PACKET_TIMEOUT,
transfer_response, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
@@ -277,7 +280,7 @@ guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,
g_obex_packet_add_body(req, put_get_data, transfer);
- transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
+ transfer->req_id = g_obex_send_req(obex, req, 0, FIRST_PACKET_TIMEOUT,
transfer_response, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
@@ -426,7 +429,7 @@ guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data);
transfer->data_consumer = data_func;
- transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
+ transfer->req_id = g_obex_send_req(obex, req, 0, FIRST_PACKET_TIMEOUT,
transfer_response, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
@@ -456,7 +459,7 @@ guint g_obex_get_req(GObex *obex, GObexDataConsumer data_func,
first_hdr_id, args);
va_end(args);
- transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
+ transfer->req_id = g_obex_send_req(obex, req, 0, FIRST_PACKET_TIMEOUT,
transfer_response, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
diff --git a/gobex/gobex.c b/gobex/gobex.c
index b0f3716..62d36da 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -397,19 +397,30 @@ gboolean g_obex_send(GObex *obex, GObexPacket *pkt, GError **err)
return ret;
}
-guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
- GObexResponseFunc func, gpointer user_data,
- GError **err)
+guint g_obex_send_req(GObex *obex, GObexPacket *req, guint req_id,
+ gint timeout, GObexResponseFunc func,
+ gpointer user_data, GError **err)
{
GObexHeader *connid;
struct pending_pkt *p;
static guint id = 1;
- g_obex_debug(G_OBEX_DEBUG_COMMAND, "conn %u", obex->conn_id);
+ g_obex_debug(G_OBEX_DEBUG_COMMAND, "conn %u req_id %u", obex->conn_id,
+ req_id);
if (obex->conn_id == CONNID_INVALID)
goto create_pending;
+ if (obex->pending_req && obex->pending_req->id == req_id)
+ goto create_pending;
+
+ if (req_id != 0) {
+ g_set_error(err, G_OBEX_ERROR, G_OBEX_ERROR_INVALID_ARGS,
+ "Invalid arguments");
+ g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", (*err)->message);
+ return 0;
+ }
+
connid = g_obex_packet_get_header(req, G_OBEX_HDR_CONNECTION);
if (connid != NULL)
goto create_pending;
@@ -1076,7 +1087,7 @@ guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
init_connect_data(obex, &data);
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);
+ return g_obex_send_req(obex, req, 0, -1, func, user_data, err);
}
guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
@@ -1102,7 +1113,7 @@ guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
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);
+ return g_obex_send_req(obex, req, 0, -1, func, user_data, err);
}
guint g_obex_mkdir(GObex *obex, const char *path, GObexResponseFunc func,
@@ -1119,7 +1130,7 @@ guint g_obex_mkdir(GObex *obex, const char *path, GObexResponseFunc func,
memset(&data, 0, sizeof(data));
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);
+ return g_obex_send_req(obex, req, 0, -1, func, user_data, err);
}
guint g_obex_delete(GObex *obex, const char *name, GObexResponseFunc func,
@@ -1132,7 +1143,7 @@ guint g_obex_delete(GObex *obex, const char *name, GObexResponseFunc func,
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);
+ return g_obex_send_req(obex, req, 0, -1, func, user_data, err);
}
guint g_obex_copy(GObex *obex, const char *name, const char *dest,
@@ -1149,7 +1160,7 @@ guint g_obex_copy(GObex *obex, const char *name, const char *dest,
G_OBEX_HDR_DESTNAME, dest,
G_OBEX_HDR_INVALID);
- return g_obex_send_req(obex, req, -1, func, user_data, err);
+ return g_obex_send_req(obex, req, 0, -1, func, user_data, err);
}
guint g_obex_move(GObex *obex, const char *name, const char *dest,
@@ -1166,5 +1177,5 @@ guint g_obex_move(GObex *obex, const char *name, const char *dest,
G_OBEX_HDR_DESTNAME, dest,
G_OBEX_HDR_INVALID);
- return g_obex_send_req(obex, req, -1, func, user_data, err);
+ return g_obex_send_req(obex, req, 0, -1, func, user_data, err);
}
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 1b20333..9c45817 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -43,9 +43,9 @@ typedef void (*GObexResponseFunc) (GObex *obex, GError *err, GObexPacket *rsp,
gboolean g_obex_send(GObex *obex, GObexPacket *pkt, GError **err);
-guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
- GObexResponseFunc func, gpointer user_data,
- GError **err);
+guint g_obex_send_req(GObex *obex, GObexPacket *req, guint req_id,
+ gint timeout, GObexResponseFunc func,
+ gpointer user_data, GError **err);
gboolean g_obex_cancel_req(GObex *obex, guint req_id,
gboolean remove_callback);
diff --git a/unit/test-gobex.c b/unit/test-gobex.c
index 62443db..1e31fe8 100644
--- a/unit/test-gobex.c
+++ b/unit/test-gobex.c
@@ -231,7 +231,7 @@ static void send_req(GObexPacket *req, GObexResponseFunc rsp_func,
create_endpoints(&obex, &io, transport_type);
- g_obex_send_req(obex, req, req_timeout, rsp_func, &gerr, &gerr);
+ g_obex_send_req(obex, req, 0, req_timeout, rsp_func, &gerr, &gerr);
g_assert_no_error(gerr);
cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
@@ -340,7 +340,7 @@ static void test_cancel_req_immediate(void)
r.err = NULL;
req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID);
- r.id = g_obex_send_req(r.obex, req, -1, req_done, &r, &r.err);
+ r.id = g_obex_send_req(r.obex, req, 0, -1, req_done, &r, &r.err);
g_assert_no_error(r.err);
g_assert(r.id != 0);
@@ -421,7 +421,7 @@ static void test_cancel_req_delay(int transport_type)
r.err = NULL;
req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID);
- r.id = g_obex_send_req(r.obex, req, -1, req_done, &r, &r.err);
+ r.id = g_obex_send_req(r.obex, req, 0, -1, req_done, &r, &r.err);
g_assert_no_error(r.err);
g_assert(r.id != 0);
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH obexd 9/9] gobex: make connection id check less strict
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
` (6 preceding siblings ...)
2011-11-10 14:43 ` [PATCH obexd 8/9] gobex: fix sending Connection ID header in all requests Luiz Augusto von Dentz
@ 2011-11-10 14:43 ` Luiz Augusto von Dentz
2011-11-10 15:08 ` [PATCH obexd 1/9] gobex: add unit test for CONNECT request Hendrik Sattler
8 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-10 14:43 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
OBEX spec says:
Only the first packet in the request needs to contain the Connection
Id header...
If a Connection Id header is received with an invalid connection
identifier, it is recommended that the operation be rejected with the
response code (0xD3) “Service Unavailable”.
Since not all requests packets need to contain Connection Id header we
should only try to validate it in case a header is received.
Reported by Hendrik Sattler <post@hendrik-sattler.de>
---
gobex/gobex.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gobex/gobex.c b/gobex/gobex.c
index 62d36da..238bbc3 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -702,7 +702,7 @@ static gboolean check_connid(GObex *obex, GObexPacket *pkt)
hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_CONNECTION);
if (hdr == NULL)
- return FALSE;
+ return TRUE;
g_obex_header_get_uint32(hdr, &id);
--
1.7.6.4
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH obexd 1/9] gobex: add unit test for CONNECT request
2011-11-10 14:43 [PATCH obexd 1/9] gobex: add unit test for CONNECT request Luiz Augusto von Dentz
` (7 preceding siblings ...)
2011-11-10 14:43 ` [PATCH obexd 9/9] gobex: make connection id check less strict Luiz Augusto von Dentz
@ 2011-11-10 15:08 ` Hendrik Sattler
2011-11-11 9:00 ` Luiz Augusto von Dentz
8 siblings, 1 reply; 15+ messages in thread
From: Hendrik Sattler @ 2011-11-10 15:08 UTC (permalink / raw)
To: linux-bluetooth
Am 10.11.2011 15:43, schrieb Luiz Augusto von Dentz:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> ---
> unit/test-gobex-transfer.c | 56
> ++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 56 insertions(+), 0 deletions(-)
>
> diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
> index a246418..ac6356d 100644
> --- a/unit/test-gobex-transfer.c
> +++ b/unit/test-gobex-transfer.c
> @@ -65,6 +65,12 @@ static guint8 get_rsp_first[] = {
> G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x10,
> static guint8 get_rsp_last[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT,
> 0x00, 0x06,
> G_OBEX_HDR_BODY_END, 0x00, 0x03 };
>
> +static guint8 conn_req[] = { G_OBEX_OP_CONNECT | FINAL_BIT, 0x00,
> 0x07,
> + 0x10, 0x00, 0x10, 0x00 };
> +static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00,
> 0x0c,
> + 0x10, 0x00, 0x10, 0x00, 0xcb, 0x00,
> + 0x00, 0x00, 0x01 };
> +
Maybe replace 0xcb with G_OBEX_HDR_CONNECTION?
HS
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH obexd 1/9] gobex: add unit test for CONNECT request
2011-11-10 15:08 ` [PATCH obexd 1/9] gobex: add unit test for CONNECT request Hendrik Sattler
@ 2011-11-11 9:00 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2011-11-11 9:00 UTC (permalink / raw)
To: Hendrik Sattler; +Cc: linux-bluetooth
Hi Hendrik,
On Thu, Nov 10, 2011 at 5:08 PM, Hendrik Sattler
<post@hendrik-sattler.de> wrote:
> Am 10.11.2011 15:43, schrieb Luiz Augusto von Dentz:
>>
>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>
>> ---
>> unit/test-gobex-transfer.c | 56
>> ++++++++++++++++++++++++++++++++++++++++++++
>> 1 files changed, 56 insertions(+), 0 deletions(-)
>>
>> diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
>> index a246418..ac6356d 100644
>> --- a/unit/test-gobex-transfer.c
>> +++ b/unit/test-gobex-transfer.c
>> @@ -65,6 +65,12 @@ static guint8 get_rsp_first[] = {
>> G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x10,
>> static guint8 get_rsp_last[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00,
>> 0x06,
>> G_OBEX_HDR_BODY_END, 0x00, 0x03 };
>>
>> +static guint8 conn_req[] = { G_OBEX_OP_CONNECT | FINAL_BIT, 0x00, 0x07,
>> + 0x10, 0x00, 0x10, 0x00 };
>> +static guint8 conn_rsp[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x0c,
>> + 0x10, 0x00, 0x10, 0x00, 0xcb,
>> 0x00,
>> + 0x00, 0x00, 0x01 };
>> +
>
> Maybe replace 0xcb with G_OBEX_HDR_CONNECTION?
Yep, gonna fix it.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 15+ messages in thread