Commit d0bf7e57 authored by Arman Uguray's avatar Arman Uguray Committed by Marcel Holtmann
Browse files

gdbus/client: Allow specifying ObjectManager path

GDBusClient currently hard-codes "/" as the remote ObjectManager path.
This is generally incorrect, as an application can choose to expose an
ObjectManager at any well-known path. This patch fixes this by allowing
the user to pass in the ObjectManager path by introducing a new
conctructor "g_dbus_client_new_full".
parent 1545d48b
...@@ -42,6 +42,7 @@ struct GDBusClient { ...@@ -42,6 +42,7 @@ struct GDBusClient {
DBusConnection *dbus_conn; DBusConnection *dbus_conn;
char *service_name; char *service_name;
char *base_path; char *base_path;
char *root_path;
guint watch; guint watch;
guint added_watch; guint added_watch;
guint removed_watch; guint removed_watch;
...@@ -1118,9 +1119,10 @@ static void get_managed_objects(GDBusClient *client) ...@@ -1118,9 +1119,10 @@ static void get_managed_objects(GDBusClient *client)
if (client->get_objects_call != NULL) if (client->get_objects_call != NULL)
return; return;
msg = dbus_message_new_method_call(client->service_name, "/", msg = dbus_message_new_method_call(client->service_name,
DBUS_INTERFACE_DBUS ".ObjectManager", client->root_path,
"GetManagedObjects"); DBUS_INTERFACE_OBJECT_MANAGER,
"GetManagedObjects");
if (msg == NULL) if (msg == NULL)
return; return;
...@@ -1198,11 +1200,19 @@ static DBusHandlerResult message_filter(DBusConnection *connection, ...@@ -1198,11 +1200,19 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
GDBusClient *g_dbus_client_new(DBusConnection *connection, GDBusClient *g_dbus_client_new(DBusConnection *connection,
const char *service, const char *path) const char *service, const char *path)
{
return g_dbus_client_new_full(connection, service, path, "/");
}
GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
const char *service,
const char *path,
const char *root_path)
{ {
GDBusClient *client; GDBusClient *client;
unsigned int i; unsigned int i;
if (connection == NULL) if (!connection || !service || !root_path)
return NULL; return NULL;
client = g_try_new0(GDBusClient, 1); client = g_try_new0(GDBusClient, 1);
...@@ -1218,6 +1228,7 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection, ...@@ -1218,6 +1228,7 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection,
client->dbus_conn = dbus_connection_ref(connection); client->dbus_conn = dbus_connection_ref(connection);
client->service_name = g_strdup(service); client->service_name = g_strdup(service);
client->base_path = g_strdup(path); client->base_path = g_strdup(path);
client->root_path = g_strdup(root_path);
client->connected = FALSE; client->connected = FALSE;
client->match_rules = g_ptr_array_sized_new(1); client->match_rules = g_ptr_array_sized_new(1);
...@@ -1228,13 +1239,13 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection, ...@@ -1228,13 +1239,13 @@ GDBusClient *g_dbus_client_new(DBusConnection *connection,
service_disconnect, service_disconnect,
client, NULL); client, NULL);
client->added_watch = g_dbus_add_signal_watch(connection, service, client->added_watch = g_dbus_add_signal_watch(connection, service,
"/", client->root_path,
DBUS_INTERFACE_OBJECT_MANAGER, DBUS_INTERFACE_OBJECT_MANAGER,
"InterfacesAdded", "InterfacesAdded",
interfaces_added, interfaces_added,
client, NULL); client, NULL);
client->removed_watch = g_dbus_add_signal_watch(connection, service, client->removed_watch = g_dbus_add_signal_watch(connection, service,
"/", client->root_path,
DBUS_INTERFACE_OBJECT_MANAGER, DBUS_INTERFACE_OBJECT_MANAGER,
"InterfacesRemoved", "InterfacesRemoved",
interfaces_removed, interfaces_removed,
...@@ -1308,6 +1319,7 @@ void g_dbus_client_unref(GDBusClient *client) ...@@ -1308,6 +1319,7 @@ void g_dbus_client_unref(GDBusClient *client)
g_free(client->service_name); g_free(client->service_name);
g_free(client->base_path); g_free(client->base_path);
g_free(client->root_path);
g_free(client); g_free(client);
} }
......
...@@ -355,6 +355,10 @@ gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy, ...@@ -355,6 +355,10 @@ gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
GDBusClient *g_dbus_client_new(DBusConnection *connection, GDBusClient *g_dbus_client_new(DBusConnection *connection,
const char *service, const char *path); const char *service, const char *path);
GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
const char *service,
const char *path,
const char *root_path);
GDBusClient *g_dbus_client_ref(GDBusClient *client); GDBusClient *g_dbus_client_ref(GDBusClient *client);
void g_dbus_client_unref(GDBusClient *client); void g_dbus_client_unref(GDBusClient *client);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment