public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Filippo Giunchedi <filippo@esaurito.net>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH] update test/agent.c API usage
Date: Sat, 6 Jun 2009 22:34:16 +0200	[thread overview]
Message-ID: <20090606203416.GA27173@esaurito.net> (raw)

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

             reply	other threads:[~2009-06-06 20:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-06 20:34 Filippo Giunchedi [this message]
2009-06-06 23:18 ` [PATCH] update test/agent.c API usage Marcel Holtmann
2009-06-07  8:11   ` [PATCH] make test/agent.c use new API Filippo Giunchedi
2009-06-07  8:42     ` Marcel Holtmann
2009-06-07 10:14       ` [PATCH] test/agent.c: update dbus API usage Filippo Giunchedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090606203416.GA27173@esaurito.net \
    --to=filippo@esaurito.net \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox