*
* Copyright (C) 2003 CodeFactory AB
* Copyright (C) 2003, 2004, 2005 Red Hat, Inc.
+ * Copyright (C) 2013 Samsung Electronics
*
* Licensed under the Academic Free License version 2.1
*
#include <dbus/dbus-marshal-recursive.h>
#include <string.h>
+#ifdef ENABLE_KDBUS_TRANSPORT
#include "kdbus-d.h"
#include <stdio.h>
#include <errno.h>
#include <limits.h>
+#include <stdlib.h>
+#endif
static DBusConnection *
bus_driver_get_conn_helper (DBusConnection *connection,
dbus_bool_t retval;
const char *null_service;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
return TRUE;
+#endif
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
{
DBusMessage *message;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
return TRUE;
+#endif
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
{
DBusMessage *message;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
return TRUE;
+#endif
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return FALSE;
}
-
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
if(!kdbus_list_services (connection, &services, &len))
{
}
}
else
- if (!bus_registry_list_services (registry, &services, &len))
- {
- dbus_message_unref (reply);
- BUS_SET_OOM (error);
- return FALSE;
- }
+#endif
+ {
+ if (!bus_registry_list_services (registry, &services, &len))
+ {
+ dbus_message_unref (reply);
+ BUS_SET_OOM (error);
+ return FALSE;
+ }
+ }
dbus_message_iter_init_append (reply, &iter);
return FALSE;
}
- if(!bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(!bus_context_is_kdbus(bus_transaction_get_context (transaction))) //not needed for kdbus, we got it from kdbus_list_services
+#endif
{
+
/* Include the bus driver in the list */
const char *v_STRING = DBUS_SERVICE_DBUS;
if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
retval = FALSE;
reply = NULL;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
if (!bus_registry_acquire_kdbus_service (registry, connection,
message,
goto out;
}
else
+#endif
{
+
_dbus_string_init_const (&service_name, name);
if (!bus_registry_acquire_service (registry, connection,
&service_reply, transaction,
error))
goto out;
-
}
reply = dbus_message_new_method_return (message);
goto out;
}
- _dbus_verbose ("Reply sender: %s, destination: %s\n", dbus_message_get_sender(reply), dbus_message_get_destination(reply)); //todo kdbus incl
-
if (!bus_transaction_send_from_driver (transaction, connection, reply))
{
BUS_SET_OOM (error);
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- registry = bus_connection_get_registry (connection);
-
if (!dbus_message_get_args (message, error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
reply = NULL;
_dbus_string_init_const (&service_name, name);
+ registry = bus_connection_get_registry (connection);
+#ifdef ENABLE_KDBUS_TRANSPORT
if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
- registry = (BusRegistry*) dbus_message_get_sender(message);
- /* todo looks like hack? Yes.
- * But how to pass sender of message to bus_registry_release_service in other way?
- */
+ if (!bus_registry_release_service_kdbus (dbus_message_get_sender(message), connection,
+ &service_name, &service_reply,
+ transaction, error))
+ goto out;
}
-
+ else
+#endif
if (!bus_registry_release_service (registry, connection,
&service_name, &service_reply,
transaction, error))
}
else
{
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
int inter_ret;
struct nameInfo info;
inter_ret = kdbus_NameQuery(name, dbus_connection_get_transport(connection), &info);
- if((inter_ret == 0) || (inter_ret == -ENOENT))
+ if((inter_ret == 0) || (inter_ret == -ENOENT) || (inter_ret == -ENXIO))
service_exists = (inter_ret == 0) ? TRUE : FALSE;
else
{
}
}
else
+#endif
{
_dbus_string_init_const (&service_name, name);
service = bus_registry_lookup (registry, &service_name);
if (rule == NULL)
goto failed;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
if (!kdbus_add_match_rule (connection, message, text, error))
goto failed;
}
else
+#endif
{
+
matchmaker = bus_connection_get_matchmaker (connection);
if (!bus_matchmaker_add_rule (matchmaker, rule))
if (rule == NULL)
goto failed;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
if(!kdbus_remove_match(connection, message, error))
goto failed;
}
+#endif
/* Send the ack before we remove the rule, since the ack is undone
* on transaction cancel, but rule removal isn't.
message, error))
goto failed;
- if(!bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(!bus_context_is_kdbus(bus_transaction_get_context (transaction)))
+#endif
{
matchmaker = bus_connection_get_matchmaker (connection);
BusRegistry *registry;
BusService *service;
DBusMessage *reply;
+#ifdef ENABLE_KDBUS_TRANSPORT
char unique_name[(unsigned int)(snprintf((char*)base_name, 0, "%llu", ULLONG_MAX) + sizeof(":1."))];
+#endif
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
DBUS_TYPE_INVALID))
goto failed;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
- {
- int ret;
- struct nameInfo info;
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
+ {
+ int ret;
- ret = kdbus_NameQuery(text, dbus_connection_get_transport(connection), &info);
- if(ret == 0) //unique id of the name
- {
- sprintf(unique_name, ":1.%llu", (unsigned long long int)info.uniqueId);
- _dbus_verbose("Unique name discovered:%s\n", unique_name);
- base_name = unique_name;
- }
- else if(ret == -ENOENT) //name has no owner
- {
- dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Could not get owner of name '%s': no such name", text);
- goto failed;
- }
- else
- {
- _dbus_verbose("kdbus error sending name query: err %d (%m)\n", errno);
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Could not determine unique name for '%s'", text);
- goto failed;
- }
- }
+ ret = kdbus_get_name_owner(connection, text, unique_name);
+ if(ret == 0)
+ base_name = unique_name;
+ else if((ret == -ENOENT) || (ret == -ENXIO)) //name has no owner
+ {
+ dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "Could not get owner of name '%s': no such name", text);
+ goto failed;
+ }
+ else
+ {
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "Could not determine unique name for '%s'", text);
+ goto failed;
+ }
+ }
else
- {
+#endif
+ {
_dbus_string_init_const (&str, text);
service = bus_registry_lookup (registry, &str);
if (service == NULL &&
if (! _dbus_list_append (&base_names, dbus_service_name))
goto oom;
}
+#ifdef ENABLE_KDBUS_TRANSPORT
+ else if (!bus_context_is_kdbus(bus_transaction_get_context (transaction)) && (service == NULL))
+#else
else if (service == NULL)
+#endif
{
dbus_set_error (error,
DBUS_ERROR_NAME_HAS_NO_OWNER,
}
else
{
- if (!bus_service_list_queued_owners (service,
- &base_names,
- error))
- goto failed;
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
+ {
+ if(!kdbus_list_queued (connection, &base_names, text ,error))
+ goto failed;
+ }
+ else
+#endif
+ {
+ if (!bus_service_list_queued_owners (service,
+ &base_names,
+ error))
+ goto failed;
+ }
}
_dbus_assert (base_names != NULL);
dbus_message_unref (reply);
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
+ {
+ link = _dbus_list_get_first_link (&base_names);
+ while (link != NULL)
+ {
+ DBusList *next = _dbus_list_get_next_link (&base_names, link);
+
+ if(link->data != NULL)
+ free(link->data);
+
+ _dbus_list_free_link (link);
+ link = next;
+ }
+ }
+#endif
+
return TRUE;
oom:
_DBUS_ASSERT_ERROR_IS_SET (error);
if (reply)
dbus_message_unref (reply);
-
if (base_names)
_dbus_list_clear (&base_names);
-
return FALSE;
}
if (reply == NULL)
goto oom;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
- if(!kdbus_get_connection_unix_user(connection, message, &uid, error))
+ const char* name;
+
+ if(!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
+ goto failed;
+ if(!kdbus_get_unix_user(connection, name, &uid, error))
goto failed;
}
else
+#endif
{
conn = bus_driver_get_conn_helper (connection, message, "UID", &service,
error);
reply = dbus_message_new_method_return (message);
if (reply == NULL)
goto oom;
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
+ {
+ const char* name;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
- {
- if(!kdbus_get_connection_unix_process_id(connection, message, &pid, error))
- goto failed;
- }
- else
+ if(!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
+ goto failed;
+ if(!kdbus_get_connection_unix_process_id(connection, name, &pid, error))
+ goto failed;
+ }
+ else
+#endif
{
- conn = bus_driver_get_conn_helper (connection, message, "PID", &service,
- error);
-
- if (conn == NULL)
- goto failed;
-
-
+ conn = bus_driver_get_conn_helper (connection, message, "PID", &service,
+ error);
+ if (conn == NULL)
+ goto failed;
- if (!dbus_connection_get_unix_process_id (conn, &pid))
- {
- dbus_set_error (error,
- DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN,
- "Could not determine PID for '%s'", service);
- goto failed;
- }
+ if (!dbus_connection_get_unix_process_id (conn, &pid))
+ {
+ dbus_set_error (error,
+ DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN,
+ "Could not determine PID for '%s'", service);
+ goto failed;
+ }
}
pid32 = pid;
if (reply == NULL)
goto oom;
- if(bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
if(!kdbus_get_connection_unix_selinux_security_context(connection, message, reply, error))
goto failed;
}
else
+#endif
{
conn = bus_driver_get_conn_helper (connection, message, "security context",
&service, error);
if (reply == NULL)
goto oom;
- if(!bus_context_is_kdbus(bus_transaction_get_context (transaction))) //todo kdbus incl
+#ifdef ENABLE_KDBUS_TRANSPORT
+ if(!bus_context_is_kdbus(bus_transaction_get_context (transaction)))
{
+#endif
conn = bus_driver_get_conn_helper (connection, message, "credentials",
&service, error);
if (!_dbus_asv_add_uint32 (&array_iter, "UnixUserID", ulong_val))
goto oom;
}
+#ifdef ENABLE_KDBUS_TRANSPORT
}
else
{
- if(kdbus_get_connection_unix_process_id(connection, message, &ulong_val, error))
+ const char* name;
+
+ if(!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
+ goto failed;
+ if(kdbus_get_connection_unix_process_id(connection, name, &ulong_val, error))
{
if (!_dbus_asv_add_uint32 (&array_iter, "ProcessID", ulong_val))
goto oom;
else
goto failed;
- if(kdbus_get_connection_unix_user(connection, message, &ulong_val, error))
+ if(kdbus_get_unix_user(connection, name, &ulong_val, error))
{
if (!_dbus_asv_add_uint32 (&array_iter, "UnixUserID", ulong_val))
goto oom;
else
goto failed;
}
+#endif
if (!_dbus_asv_close (&reply_iter, &array_iter))
goto oom;