From bf2f209f6a9ede80561a6f421526f7cc55f76033 Mon Sep 17 00:00:00 2001 From: Radoslaw Pajak Date: Tue, 10 Sep 2013 12:41:25 +0200 Subject: [PATCH] [daemon-dev][lib-fix] ListNames in libdbus fix, daemon development - ListNames method of org.freedesktop.DBus fixed in libdbus - daemon on kdbus development: connects to bus and listens, and receives messages and broadcasts Change-Id: I4648a6ce06a1b2678b7b56f1bdefb4e014c45bb5 --- bus/bus.c | 17 +++++++++--- bus/kdbus-d.c | 63 ++------------------------------------------- bus/kdbus-d.h | 4 +-- dbus/dbus-transport-kdbus.c | 32 +++++++++++++---------- 4 files changed, 35 insertions(+), 81 deletions(-) diff --git a/bus/bus.c b/bus/bus.c index 7e56f58..8f8674a 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -446,7 +446,7 @@ process_config_first_time_only (BusContext *context, if(bus_address == NULL) goto failed; - server = fake_server(bus_address); + server = empty_server_init(bus_address); if(server == NULL) { free(bus_address); @@ -462,9 +462,6 @@ process_config_first_time_only (BusContext *context, context->myConnection = daemon_as_client(type, bus_address, error); if(context->myConnection == NULL) goto failed; - - if(!setup_connection(context, error)) - goto failed; } else { @@ -974,6 +971,18 @@ bus_context_new (const DBusString *config_file, dbus_server_free_data_slot (&server_data_slot); + if(context->myConnection) + { + DBusString unique_name; + + bus_connections_setup_connection(context->connections, context->myConnection); + _dbus_string_init_const(&unique_name, ":1.1"); + if(!bus_connection_complete(context->myConnection, &unique_name, error)) + { + _dbus_verbose ("bus connection complete failed\n"); + } + } + return context; failed: diff --git a/bus/kdbus-d.c b/bus/kdbus-d.c index eca6473..2153781 100644 --- a/bus/kdbus-d.c +++ b/bus/kdbus-d.c @@ -12,6 +12,7 @@ #include #include #include +#include "dispatch.h" #include #include @@ -69,7 +70,7 @@ char* make_kdbus_bus(DBusBusType type, DBusError *error) return bus; } -DBusServer* fake_server(char* address) +DBusServer* empty_server_init(char* address) { return dbus_server_init_mini(address); } @@ -101,63 +102,3 @@ failed: return connection; } - -dbus_bool_t setup_connection(BusContext* context, DBusError* error) -{ - //on the basis of bus_connections_setup_connection from connection.c - - dbus_bool_t retval = FALSE; //todo opitimize -// DBusConnection* connection; - - //todo what to do with error - -/* connection = context->myConnection; //todo - dbus_connection_set_route_peer_messages (connection, TRUE); - - if (!dbus_connection_set_watch_functions (connection, - add_connection_watch, - remove_connection_watch, - toggle_connection_watch, - connection, - NULL)) - goto out; - - if (!dbus_connection_set_timeout_functions (connection, - add_connection_timeout, - remove_connection_timeout, - NULL, - connection, NULL)) - goto out; - - dbus_connection_set_dispatch_status_function (connection, - dispatch_status_function, - bus_context_get_loop (context), - NULL); - - if (!bus_dispatch_add_connection (connection)) - goto out; - - retval = TRUE; - - out: - if (!retval) - { - if (!dbus_connection_set_watch_functions (connection, - NULL, NULL, NULL, - connection, - NULL)) - _dbus_assert_not_reached ("setting watch functions to NULL failed"); - - if (!dbus_connection_set_timeout_functions (connection, - NULL, NULL, NULL, - connection, - NULL)) - _dbus_assert_not_reached ("setting timeout functions to NULL failed"); - - - dbus_connection_set_dispatch_status_function (connection, - NULL, NULL, NULL); - } -*/ - return retval; -} diff --git a/bus/kdbus-d.h b/bus/kdbus-d.h index e8a9109..c8874a7 100644 --- a/bus/kdbus-d.h +++ b/bus/kdbus-d.h @@ -17,9 +17,7 @@ #include char* make_kdbus_bus(DBusBusType type, DBusError *error); -DBusServer* fake_server(char* address); +DBusServer* empty_server_init(char* address); DBusConnection* daemon_as_client(DBusBusType type, char* address, DBusError *error); -dbus_bool_t setup_connection(BusContext* context, DBusError* error); - #endif /* KDBUS_H_ */ diff --git a/dbus/dbus-transport-kdbus.c b/dbus/dbus-transport-kdbus.c index 2f0c808..ba08e12 100644 --- a/dbus/dbus-transport-kdbus.c +++ b/dbus/dbus-transport-kdbus.c @@ -1137,13 +1137,13 @@ static int emulateOrgFreedesktopDBus(DBusTransport *transport, DBusMessage *mess { pCmd = realloc(pCmd, cmd_size); //prepare memory if(pCmd == NULL) - return FALSE; + return -1; goto again; //and try again } else { DBusMessage *reply; - DBusMessageIter args; + DBusMessageIter iter, sub; struct kdbus_cmd_name* pCmd_name; char* pName; @@ -1151,28 +1151,35 @@ static int emulateOrgFreedesktopDBus(DBusTransport *transport, DBusMessage *mess if(reply == NULL) goto out; dbus_message_set_sender(reply, DBUS_SERVICE_DBUS); - dbus_message_iter_init_append(reply, &args); - + dbus_message_iter_init_append(reply, &iter); + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &sub)) + { + dbus_message_unref(reply); + goto out; + } for (pCmd_name = pCmd->names; (uint8_t *)(pCmd_name) < (uint8_t *)(pCmd) + pCmd->size; pCmd_name = KDBUS_PART_NEXT(pCmd_name)) { pName = pCmd_name->name; - if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &pName)) + if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &pName)) { dbus_message_unref(reply); goto out; } } - if(add_message_to_received(reply, transport->connection)) + if (!dbus_message_iter_close_container (&iter, &sub)) { - free(pCmd); - return TRUE; + dbus_message_unref (reply); + goto out; } + + if(add_message_to_received(reply, transport->connection)) + ret_value = 0; } out: if(pCmd) free(pCmd); - return FALSE; + return ret_value; } else if(!strcmp(dbus_message_get_member(message), "GetId")) { @@ -1182,7 +1189,6 @@ out: MD5_CTX md5; DBusString binary, encoded; - ret_value = FALSE; path = &transport->address[11]; //start of kdbus bus path if(stat(path, &stats) < -1) { @@ -1230,7 +1236,6 @@ out: { DBusMessage *reply; - ret_value = FALSE; reply = dbus_message_new_method_return(message); if(reply != NULL) { @@ -1238,12 +1243,13 @@ out: if (!dbus_message_append_args (reply, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &info.sec_label, info.sec_label_len, DBUS_TYPE_INVALID)) dbus_message_unref(reply); else if(add_message_to_received(reply, transport->connection)) - ret_value = TRUE; + ret_value = 0; } } } else - return reply_with_error(DBUS_ERROR_UNKNOWN_METHOD, NULL, (char*)dbus_message_get_member(message), message, transport->connection); + return 1; //send to daemon +// return reply_with_error(DBUS_ERROR_UNKNOWN_METHOD, NULL, (char*)dbus_message_get_member(message), message, transport->connection); /* else if(!strcmp(dbus_message_get_member(message), "ListActivatableNames")) //todo { -- 2.7.4