summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-06-22 01:36:06 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-06-22 01:36:06 +0000
commitb8020a613062f229b737174e934e75d96ba607d2 (patch)
tree65a1b45cde427d8e5a9e3e83044a696dc301a715 /hcid
parent1a2e7943da42619730e442d1ff6ab08b9c2c621d (diff)
Improve local connection handling
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-database.c21
-rw-r--r--hcid/dbus-database.h8
-rw-r--r--hcid/server.c38
3 files changed, 57 insertions, 10 deletions
diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c
index 8ee04c36..2f904956 100644
--- a/hcid/dbus-database.c
+++ b/hcid/dbus-database.c
@@ -461,6 +461,27 @@ dbus_bool_t database_init(DBusConnection *conn, const char *path)
NULL, NULL);
}
+DBusHandlerResult database_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMethodVTable *current;
+
+ for (current = database_methods;
+ current->name && current->message_function; current++) {
+ if (!dbus_message_is_method_call(msg, DATABASE_INTERFACE,
+ current->name))
+ continue;
+
+ if (dbus_message_has_signature(msg, current->signature)) {
+ debug("%s: %s.%s()", dbus_message_get_path(msg),
+ DATABASE_INTERFACE, current->name);
+ return current->message_function(conn, msg, data);
+ }
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
void set_sdp_server_enable(void)
{
sdp_server_enable = 1;
diff --git a/hcid/dbus-database.h b/hcid/dbus-database.h
index 8feb1e59..3912e18e 100644
--- a/hcid/dbus-database.h
+++ b/hcid/dbus-database.h
@@ -21,13 +21,11 @@
*
*/
-#ifndef __BLUEZ_DBUS_DATABASE_H
-#define __BLUEZ_DBUS_DATABASE_H
-
#define DATABASE_INTERFACE "org.bluez.Database"
dbus_bool_t database_init(DBusConnection *conn, const char *path);
-void set_sdp_server_enable(void);
+DBusHandlerResult database_message(DBusConnection *conn,
+ DBusMessage *msg, void *data);
-#endif /* __BLUEZ_DBUS_DATABSE_H */
+void set_sdp_server_enable(void);
diff --git a/hcid/server.c b/hcid/server.c
index 57241909..49f9ff54 100644
--- a/hcid/server.c
+++ b/hcid/server.c
@@ -25,17 +25,38 @@
#include <config.h>
#endif
+#include <string.h>
#include <dbus.h>
+#include "dbus-database.h"
+
#include "logging.h"
#include "server.h"
+static DBusHandlerResult filter_function(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ if (dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected") &&
+ strcmp(dbus_message_get_path(msg), DBUS_PATH_LOCAL) == 0) {
+ debug("Received disconnected signal");
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ name_listener_indicate_disconnect(conn);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
static DBusHandlerResult message_handler(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- debug("Incoming message %p", conn);
+ if (strcmp(dbus_message_get_interface(msg), DATABASE_INTERFACE) == 0)
+ return database_message(conn, msg, data);
+
+ debug("%s -> %s.%s", dbus_message_get_path(msg),
+ dbus_message_get_interface(msg), dbus_message_get_member(msg));
- return DBUS_HANDLER_RESULT_HANDLED;
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static void unregister_handler(DBusConnection *conn, void *data)
@@ -50,9 +71,13 @@ static void handle_connection(DBusServer *server, DBusConnection *conn, void *da
debug("New local connection %p", conn);
- //dbus_connection_add_filter(conn, filter_function, NULL, NULL);
+ dbus_connection_add_filter(conn, filter_function, NULL, NULL);
- dbus_connection_register_fallback(conn, "/org/bluez", &vtable, NULL);
+ if (dbus_connection_register_object_path(conn, "/org/bluez",
+ &vtable, NULL) == FALSE) {
+ error("Can't register local object path");
+ return;
+ }
dbus_connection_ref(conn);
@@ -69,8 +94,9 @@ char *get_local_server_address(void)
void init_local_server(void)
{
- DBusError err;
+ const char *ext_only[] = { "EXTERNAL", NULL };
char *address;
+ DBusError err;
dbus_error_init(&err);
@@ -92,6 +118,8 @@ void init_local_server(void)
dbus_server_set_new_connection_function(server, handle_connection,
NULL, NULL);
+
+ dbus_server_set_auth_mechanisms(server, ext_only);
}
void shutdown_local_server(void)