2009-06-06 20:34:16

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH] update test/agent.c API usage

Hi,
as per subject:

* switch from Request to RequestPin/RequestPasskey
* change argument check in Release
* add Authorize method

thanks,
filippo

---
test/agent.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index b256f52..588f488 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -74,16 +74,14 @@ static DBusHandlerResult request_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
- dbus_bool_t numeric;
+ const char *path;

if (!passkey)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_BOOLEAN, &numeric, DBUS_TYPE_INVALID)) {
- fprintf(stderr, "Invalid arguments for passkey Request method");
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPinCode/RequestPasskey method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

@@ -99,7 +97,7 @@ static DBusHandlerResult request_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}

- printf("Passkey request for device %s\n", address);
+ printf("Passkey request for device %s\n", path);

dbus_message_append_args(reply, DBUS_TYPE_STRING, &passkey,
DBUS_TYPE_INVALID);
@@ -118,16 +116,13 @@ static DBusHandlerResult cancel_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;

- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) {
fprintf(stderr, "Invalid arguments for passkey Confirm method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

- printf("Request canceled for device %s\n", address);
+ printf("Request canceled\n");

reply = dbus_message_new_method_return(msg);
if (!reply) {
@@ -174,10 +169,47 @@ static DBusHandlerResult release_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}

+static DBusHandlerResult authorize_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char *path, *uuid;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for Authorize method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Authorizing request for %s\n", path);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
static DBusHandlerResult agent_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Request"))
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPinCode") ||
+ dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPasskey"))
return request_message(conn, msg, data);

if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Cancel"))
@@ -186,6 +218,9 @@ static DBusHandlerResult agent_message(DBusConnection *conn,
if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Release"))
return release_message(conn, msg, data);

+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Authorize"))
+ return authorize_message(conn, msg, data);
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

--
1.6.3.1


2009-06-07 10:14:33

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH] test/agent.c: update dbus API usage

This patch implements and updates some parts of dbus API missing from
test/agent.c, namely Authorize, RequestPinCode and RequestPasskey.
---
test/agent.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 97 insertions(+), 14 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 7cd4b6e..4796e90 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -70,20 +70,18 @@ static DBusHandlerResult agent_filter(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

-static DBusHandlerResult request_message(DBusConnection *conn,
+static DBusHandlerResult request_pincode_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
- dbus_bool_t numeric;
+ const char *path;

if (!passkey)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_BOOLEAN, &numeric, DBUS_TYPE_INVALID)) {
- fprintf(stderr, "Invalid arguments for passkey Request method");
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPinCode method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

@@ -99,7 +97,7 @@ static DBusHandlerResult request_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}

- printf("Passkey request for device %s\n", address);
+ printf("Pincode request for device %s\n", path);

dbus_message_append_args(reply, DBUS_TYPE_STRING, &passkey,
DBUS_TYPE_INVALID);
@@ -114,20 +112,63 @@ send:
return DBUS_HANDLER_RESULT_HANDLED;
}

-static DBusHandlerResult cancel_message(DBusConnection *conn,
+static DBusHandlerResult request_passkey_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
+ const char *path;
+ unsigned int int_passkey;
+
+ if (!passkey)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPasskey method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Passkey request for device %s\n", path);
+
+ int_passkey = strtoul(passkey, NULL, 10);
+
+ dbus_message_append_args(reply, DBUS_TYPE_UINT32, &int_passkey,
+ DBUS_TYPE_INVALID);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult cancel_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) {
fprintf(stderr, "Invalid arguments for passkey Confirm method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

- printf("Request canceled for device %s\n", address);
+ printf("Request canceled\n");

reply = dbus_message_new_method_return(msg);
if (!reply) {
@@ -174,11 +215,50 @@ static DBusHandlerResult release_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}

+static DBusHandlerResult authorize_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char *path, *uuid;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for Authorize method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Authorizing request for %s\n", path);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
static DBusHandlerResult agent_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Request"))
- return request_message(conn, msg, data);
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPinCode"))
+ return request_pincode_message(conn, msg, data);
+
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPasskey"))
+ return request_passkey_message(conn, msg, data);

if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Cancel"))
return cancel_message(conn, msg, data);
@@ -186,6 +266,9 @@ static DBusHandlerResult agent_message(DBusConnection *conn,
if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Release"))
return release_message(conn, msg, data);

+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Authorize"))
+ return authorize_message(conn, msg, data);
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

--
1.6.3.1

2009-06-07 08:42:30

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] make test/agent.c use new API

Hi Filippo,

> I've fixed the space vs tab usage, sorry.
> I'm not sure how to handle this case:
>
> - if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Request"))
> + if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPinCode") ||
> + dbus_message_is_method_call(msg, "org.bluez.Agent",
> + "RequestPasskey"))
>
> with proper indentation but not going over 80 columns, that's what I came up
> with, hope that's ok.

it is not, because you need to split them into two functions anyway. One
returns a string, the other a uint32. Please read agent-api.txt.

Regards

Marcel



2009-06-07 08:11:01

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH] make test/agent.c use new API

Hi Marcel,
I've fixed the space vs tab usage, sorry.
I'm not sure how to handle this case:

- if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Request"))
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPinCode") ||
+ dbus_message_is_method_call(msg, "org.bluez.Agent",
+ "RequestPasskey"))

with proper indentation but not going over 80 columns, that's what I came up
with, hope that's ok.

thanks,
filippo
---
test/agent.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index b256f52..37ba8f5 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -74,16 +74,14 @@ static DBusHandlerResult request_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
- dbus_bool_t numeric;
+ const char *path;

if (!passkey)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_BOOLEAN, &numeric, DBUS_TYPE_INVALID)) {
- fprintf(stderr, "Invalid arguments for passkey Request method");
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPinCode/RequestPasskey method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

@@ -99,7 +97,7 @@ static DBusHandlerResult request_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}

- printf("Passkey request for device %s\n", address);
+ printf("Passkey request for device %s\n", path);

dbus_message_append_args(reply, DBUS_TYPE_STRING, &passkey,
DBUS_TYPE_INVALID);
@@ -118,16 +116,13 @@ static DBusHandlerResult cancel_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;

- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) {
fprintf(stderr, "Invalid arguments for passkey Confirm method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

- printf("Request canceled for device %s\n", address);
+ printf("Request canceled\n");

reply = dbus_message_new_method_return(msg);
if (!reply) {
@@ -174,10 +169,48 @@ static DBusHandlerResult release_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}

+static DBusHandlerResult authorize_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char *path, *uuid;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for Authorize method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Authorizing request for %s\n", path);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
static DBusHandlerResult agent_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Request"))
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPinCode") ||
+ dbus_message_is_method_call(msg, "org.bluez.Agent",
+ "RequestPasskey"))
return request_message(conn, msg, data);

if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Cancel"))
@@ -186,6 +219,9 @@ static DBusHandlerResult agent_message(DBusConnection *conn,
if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Release"))
return release_message(conn, msg, data);

+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Authorize"))
+ return authorize_message(conn, msg, data);
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

--
1.6.3.1

2009-06-06 23:18:52

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] update test/agent.c API usage

Hi Filippo,

> as per subject:
>
> * switch from Request to RequestPin/RequestPasskey
> * change argument check in Release
> * add Authorize method

please use proper coding style. From the email I can see already that
spaces and tabs are mixed up at least in one place.

Regards

Marcel