libnm: port to GDBus

Port libnm-core/libnm to GDBus.

The NetworkManager daemon continues to use dbus-glib; the
previously-added connection hash/variant conversion methods are now
moved to NetworkManagerUtils (along with a few other utilities that
are now only needed by the daemon code).
This commit is contained in:
Dan Winship
2014-09-10 13:51:53 -04:00
parent 16871ebc38
commit 6793a32a8c
60 changed files with 1753 additions and 2328 deletions

2
.gitignore vendored
View File

@@ -133,6 +133,8 @@ valgrind-*.log
/initscript/*/[Nn]etwork[Mm]anager /initscript/*/[Nn]etwork[Mm]anager
/introspection/all.xml /introspection/all.xml
/introspection/nmdbus-*.c
/introspection/nmdbus-*.h
/libgsystem/ /libgsystem/

View File

@@ -3,11 +3,11 @@ include $(GLIB_MAKEFILE)
SUBDIRS = \ SUBDIRS = \
. \ . \
include \ include \
introspection \
libnm-core \ libnm-core \
libnm \ libnm \
libnm-util \ libnm-util \
libnm-glib \ libnm-glib \
introspection \
src \ src \
callouts \ callouts \
clients \ clients \

View File

@@ -49,8 +49,7 @@ nm_dispatcher_LDADD = \
libnmdbus-dispatcher.la \ libnmdbus-dispatcher.la \
$(GLIB_LIBS) $(GLIB_LIBS)
# We have to build the gdbus generated code separately, without # See note about gdbus-codegen in introspection/Makefile.am
# -DGLIB_VERSION_MAX_ALLOWED, due to a bug in GLib 2.38
noinst_LTLIBRARIES += libnmdbus-dispatcher.la noinst_LTLIBRARIES += libnmdbus-dispatcher.la

View File

@@ -5,7 +5,6 @@ AM_CPPFLAGS = \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \ -I${top_srcdir}/libnm \
-I${top_builddir}/libnm \ -I${top_builddir}/libnm \
$(DBUS_CFLAGS) \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
-DNMLOCALEDIR=\"$(datadir)/locale\" -DNMLOCALEDIR=\"$(datadir)/locale\"
@@ -19,5 +18,4 @@ nm_online_CPPFLAGS = \
nm_online_LDADD = \ nm_online_LDADD = \
$(top_builddir)/libnm/libnm.la \ $(top_builddir)/libnm/libnm.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) $(GLIB_LIBS)

View File

@@ -9,7 +9,6 @@ AM_CPPFLAGS = \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \ -I${top_srcdir}/libnm \
-I${top_builddir}/libnm \ -I${top_builddir}/libnm \
$(DBUS_CFLAGS) \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
-DG_LOG_DOMAIN=\""nmcli"\" \ -DG_LOG_DOMAIN=\""nmcli"\" \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
@@ -32,7 +31,6 @@ nmcli_SOURCES = \
utils.h utils.h
nmcli_LDADD = \ nmcli_LDADD = \
$(DBUS_LIBS) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(READLINE_LIBS) \ $(READLINE_LIBS) \
$(top_builddir)/libnm/libnm.la $(top_builddir)/libnm/libnm.la

View File

@@ -677,7 +677,7 @@ do_general (NmCli *nmc, int argc, char **argv)
nmc->get_client (nmc); /* create NMClient */ nmc->get_client (nmc); /* create NMClient */
nm_client_set_logging (nmc->client, level, domains, &error); nm_client_set_logging (nmc->client, level, domains, &error);
if (error) { if (error) {
if (g_error_matches (error, DBUS_GERROR, DBUS_GERROR_ACCESS_DENIED)) if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_AUTH_FAILED))
g_string_printf (nmc->return_text, _("Error: access denied to set logging; %s"), error->message); g_string_printf (nmc->return_text, _("Error: access denied to set logging; %s"), error->message);
else else
g_string_printf (nmc->return_text, _("Error: %s"), error->message); g_string_printf (nmc->return_text, _("Error: %s"), error->message);

View File

@@ -12,7 +12,6 @@ AM_CPPFLAGS= \
-I$(srcdir)/newt \ -I$(srcdir)/newt \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(NEWT_CFLAGS) \ $(NEWT_CFLAGS) \
$(DBUS_CFLAGS) \
$(GUDEV_CFLAGS) \ $(GUDEV_CFLAGS) \
-DG_LOG_DOMAIN=\""nmtui"\" \ -DG_LOG_DOMAIN=\""nmtui"\" \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
@@ -121,7 +120,6 @@ nmtui_LDADD = \
$(top_builddir)/libnm/libnm.la \ $(top_builddir)/libnm/libnm.la \
$(builddir)/newt/libnmt-newt.a \ $(builddir)/newt/libnmt-newt.a \
$(GUDEV_LIBS) \ $(GUDEV_LIBS) \
$(DBUS_LIBS) \
$(NEWT_LIBS) \ $(NEWT_LIBS) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(NULL) $(NULL)

View File

@@ -38,11 +38,9 @@ IGNORE_HFILES= \
nm-object-private.h \ nm-object-private.h \
nm-param-spec-dbus.h \ nm-param-spec-dbus.h \
nm-remote-connection-private.h \ nm-remote-connection-private.h \
nm-secret-agent-glue.h \
nm-setting-private.h \ nm-setting-private.h \
nm-types-private.h \ nm-types-private.h \
nm-utils-private.h \ nm-utils-private.h
nm-vpn-plugin-glue.h
# Images to copy into HTML directory. # Images to copy into HTML directory.
HTML_IMAGES = libnm.png HTML_IMAGES = libnm.png

View File

@@ -4,7 +4,6 @@ AM_CPPFLAGS = \
-I${top_builddir}/libnm-core \ -I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \ -I${top_srcdir}/libnm \
-I${top_builddir}/libnm \ -I${top_builddir}/libnm \
$(DBUS_CFLAGS) \
$(GLIB_CFLAGS) $(GLIB_CFLAGS)
noinst_PROGRAMS = \ noinst_PROGRAMS = \
@@ -25,7 +24,6 @@ add_connection_gdbus_LDADD = \
add_connection_libnm_SOURCES = add-connection-libnm.c add_connection_libnm_SOURCES = add-connection-libnm.c
add_connection_libnm_LDADD = \ add_connection_libnm_LDADD = \
$(top_builddir)/libnm/libnm.la \ $(top_builddir)/libnm/libnm.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) $(GLIB_LIBS)
get_active_connections_gdbus_SOURCES = get-active-connections-gdbus.c get_active_connections_gdbus_SOURCES = get-active-connections-gdbus.c
@@ -35,7 +33,6 @@ get_active_connections_gdbus_LDADD = \
get_ap_info_libnm_SOURCES = get-ap-info-libnm.c get_ap_info_libnm_SOURCES = get-ap-info-libnm.c
get_ap_info_libnm_LDADD = \ get_ap_info_libnm_LDADD = \
$(top_builddir)/libnm/libnm.la \ $(top_builddir)/libnm/libnm.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) $(GLIB_LIBS)
list_connections_gdbus_SOURCES = list-connections-gdbus.c list_connections_gdbus_SOURCES = list-connections-gdbus.c
@@ -45,7 +42,6 @@ list_connections_gdbus_LDADD = \
list_connections_libnm_SOURCES = list-connections-libnm.c list_connections_libnm_SOURCES = list-connections-libnm.c
list_connections_libnm_LDADD = \ list_connections_libnm_LDADD = \
$(top_builddir)/libnm/libnm.la \ $(top_builddir)/libnm/libnm.la \
$(DBUS_LIBS) \
$(GLIB_LIBS) $(GLIB_LIBS)
monitor_nm_running_gdbus_SOURCES = monitor-nm-running-gdbus.c monitor_nm_running_gdbus_SOURCES = monitor-nm-running-gdbus.c

View File

@@ -1,3 +1,91 @@
noinst_LTLIBRARIES = \
libnmdbus.la
# gdbus-codegen 2.38 will emit code that requires glib 2.38, which
# will then cause availability warnings if we define
# GLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32.
#
# This is fixed in GLib 2.40 (it emits code that takes
# GLIB_VERSION_MAX_ALLOWED into account), so this workaround can go
# away when we depend on that.
AM_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(GLIB_CFLAGS))
nodist_libnmdbus_la_SOURCES = \
nmdbus-access-point.c \
nmdbus-access-point.h \
nmdbus-active-connection.c \
nmdbus-active-connection.h \
nmdbus-agent-manager.c \
nmdbus-agent-manager.h \
nmdbus-device-bond.c \
nmdbus-device-bond.h \
nmdbus-device-bridge.c \
nmdbus-device-bridge.h \
nmdbus-device-bt.c \
nmdbus-device-bt.h \
nmdbus-device-ethernet.c \
nmdbus-device-ethernet.h \
nmdbus-device.c \
nmdbus-device.h \
nmdbus-device-generic.c \
nmdbus-device-generic.h \
nmdbus-device-gre.c \
nmdbus-device-gre.h \
nmdbus-device-infiniband.c \
nmdbus-device-infiniband.h \
nmdbus-device-macvlan.c \
nmdbus-device-macvlan.h \
nmdbus-device-tun.c \
nmdbus-device-tun.h \
nmdbus-device-veth.c \
nmdbus-device-veth.h \
nmdbus-device-vlan.c \
nmdbus-device-vlan.h \
nmdbus-device-vxlan.c \
nmdbus-device-vxlan.h \
nmdbus-device-wifi.c \
nmdbus-device-wifi.h \
nmdbus-device-wimax.c \
nmdbus-device-wimax.h \
nmdbus-dhcp4-config.c \
nmdbus-dhcp4-config.h \
nmdbus-dhcp6-config.c \
nmdbus-dhcp6-config.h \
nmdbus-ip4-config.c \
nmdbus-ip4-config.h \
nmdbus-ip6-config.c \
nmdbus-ip6-config.h \
nmdbus-manager.c \
nmdbus-manager.h \
nmdbus-ppp-manager.c \
nmdbus-ppp-manager.h \
nmdbus-secret-agent.c \
nmdbus-secret-agent.h \
nmdbus-settings-connection.c \
nmdbus-settings-connection.h \
nmdbus-settings.c \
nmdbus-settings.h \
nmdbus-vpn-connection.c \
nmdbus-vpn-connection.h \
nmdbus-vpn-plugin.c \
nmdbus-vpn-plugin.h
define _make_nmdbus_rule
$(1): $(patsubst nmdbus-%.c,nm-%.xml,$(1))
$$(AM_V_GEN) gdbus-codegen \
--generate-c-code $$(basename $$@) \
--c-namespace NMDBus \
--interface-prefix org.freedesktop.NetworkManager \
$$<
$(basename $(1)).h: $(1)
@true
endef
$(foreach f,$(filter %.c,$(nodist_libnmdbus_la_SOURCES)),$(eval $(call _make_nmdbus_rule,$f)))
CLEANFILES = $(nodist_libnmdbus_la_SOURCES)
EXTRA_DIST = \ EXTRA_DIST = \
all.xml.in \ all.xml.in \
generic-types.xml \ generic-types.xml \

View File

@@ -2,6 +2,7 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.Device.Wired"> <interface name="org.freedesktop.NetworkManager.Device.Wired">
<annotation name="org.gtk.GDBus.C.Name" value="DeviceEthernet"/>
<property name="HwAddress" type="s" access="read"> <property name="HwAddress" type="s" access="read">
<tp:docstring> <tp:docstring>

View File

@@ -2,6 +2,8 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.Device.Wireless"> <interface name="org.freedesktop.NetworkManager.Device.Wireless">
<annotation name="org.gtk.GDBus.C.Name" value="DeviceWifi"/>
<method name="GetAccessPoints"> <method name="GetAccessPoints">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_access_points"/> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_access_points"/>
<arg name="access_points" type="ao" direction="out"> <arg name="access_points" type="ao" direction="out">

View File

@@ -2,6 +2,8 @@
<node name="/org/freedesktop/NetworkManager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/org/freedesktop/NetworkManager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager"> <interface name="org.freedesktop.NetworkManager">
<annotation name="org.gtk.GDBus.C.Name" value="Manager"/>
<method name="GetDevices"> <method name="GetDevices">
<tp:docstring> <tp:docstring>
Get the list of network devices. Get the list of network devices.

View File

@@ -2,6 +2,8 @@
<node name="/"> <node name="/">
<interface name="org.freedesktop.NetworkManager.PPP"> <interface name="org.freedesktop.NetworkManager.PPP">
<annotation name="org.gtk.GDBus.C.Name" value="PPP_Manager"/>
<method name="NeedSecrets"> <method name="NeedSecrets">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_need_secrets"/> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_need_secrets"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>

View File

@@ -2,6 +2,8 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.VPN.Connection"> <interface name="org.freedesktop.NetworkManager.VPN.Connection">
<annotation name="org.gtk.GDBus.C.Name" value="VpnConnection"/>
<tp:docstring> <tp:docstring>
Represents an active connection to a Virtual Private Network. Represents an active connection to a Virtual Private Network.
</tp:docstring> </tp:docstring>

View File

@@ -2,6 +2,8 @@
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.NetworkManager.VPN.Plugin"> <interface name="org.freedesktop.NetworkManager.VPN.Plugin">
<annotation name="org.gtk.GDBus.C.Name" value="VpnPlugin"/>
<tp:docstring> <tp:docstring>
This interface is provided by plugins providing VPN services to the NetworkManager daemon. This interface is provided by plugins providing VPN services to the NetworkManager daemon.
</tp:docstring> </tp:docstring>

View File

@@ -7,8 +7,7 @@ AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\""libnm"\" \ -DG_LOG_DOMAIN=\""libnm"\" \
-DNETWORKMANAGER_COMPILATION \ -DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS)
$(DBUS_CFLAGS)
noinst_LTLIBRARIES = libnm-core.la noinst_LTLIBRARIES = libnm-core.la
@@ -30,7 +29,6 @@ GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
libnm_core_la_LIBADD = \ libnm_core_la_LIBADD = \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_LIBS) \
$(UUID_LIBS) $(UUID_LIBS)
if WITH_GNUTLS if WITH_GNUTLS

View File

@@ -78,9 +78,4 @@ GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
GDestroyNotify free_func); GDestroyNotify free_func);
GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array); GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array);
/* compat */
GVariant *_nm_utils_connection_hash_to_dict (GHashTable *hash);
GHashTable *_nm_utils_connection_dict_to_hash (GVariant *dict);
#endif #endif

View File

@@ -29,9 +29,6 @@ gboolean _nm_utils_string_in_list (const char *str,
gboolean _nm_utils_string_slist_validate (GSList *list, gboolean _nm_utils_string_slist_validate (GSList *list,
const char **valid_values); const char **valid_values);
gboolean _nm_utils_gvalue_array_validate (GValueArray *elements,
guint n_expected, ...);
/* D-Bus transform funcs */ /* D-Bus transform funcs */
GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value); GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value);

View File

@@ -30,7 +30,6 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-utils-private.h" #include "nm-utils-private.h"
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h" #include "nm-setting-private.h"
#include "crypto.h" #include "crypto.h"
@@ -439,54 +438,6 @@ nm_utils_same_ssid (const guint8 *ssid1, gsize len1,
return memcmp (ssid1, ssid2, len1) == 0 ? TRUE : FALSE; return memcmp (ssid1, ssid2, len1) == 0 ? TRUE : FALSE;
} }
static void
value_destroy (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
}
static void
value_dup (gpointer key, gpointer val, gpointer user_data)
{
GHashTable *table = (GHashTable *) user_data;
GValue *value = (GValue *) val;
GValue *dup_value;
dup_value = g_slice_new0 (GValue);
g_value_init (dup_value, G_VALUE_TYPE (val));
g_value_copy (value, dup_value);
g_hash_table_insert (table, g_strdup ((char *) key), dup_value);
}
/**
* nm_utils_gvalue_hash_dup:
* @hash: a #GHashTable mapping string:GValue
*
* Utility function to duplicate a hash table of #GValues.
*
* Returns: (transfer container) (element-type utf8 GObject.Value): a newly allocated duplicated #GHashTable, caller must free the
* returned hash with g_hash_table_unref() or g_hash_table_destroy()
**/
GHashTable *
nm_utils_gvalue_hash_dup (GHashTable *hash)
{
GHashTable *table;
g_return_val_if_fail (hash != NULL, NULL);
table = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
value_destroy);
g_hash_table_foreach (hash, value_dup, table);
return table;
}
gboolean gboolean
_nm_utils_string_in_list (const char *str, const char **valid_strings) _nm_utils_string_in_list (const char *str, const char **valid_strings)
{ {
@@ -512,30 +463,6 @@ _nm_utils_string_slist_validate (GSList *list, const char **valid_values)
return TRUE; return TRUE;
} }
gboolean
_nm_utils_gvalue_array_validate (GValueArray *elements, guint n_expected, ...)
{
va_list args;
GValue *tmp;
int i;
gboolean valid = FALSE;
if (n_expected != elements->n_values)
return FALSE;
va_start (args, n_expected);
for (i = 0; i < n_expected; i++) {
tmp = g_value_array_get_nth (elements, i);
if (G_VALUE_TYPE (tmp) != va_arg (args, GType))
goto done;
}
valid = TRUE;
done:
va_end (args);
return valid;
}
/** /**
* _nm_utils_hash_values_to_slist: * _nm_utils_hash_values_to_slist:
* @hash: a #GHashTable * @hash: a #GHashTable
@@ -564,47 +491,6 @@ _nm_utils_hash_values_to_slist (GHashTable *hash)
return list; return list;
} }
/**
* _nm_utils_connection_hash_to_dict:
* @hash: a hashed #NMConnection
*
* Returns: a (floating) #GVariant equivalent to @hash.
*/
GVariant *
_nm_utils_connection_hash_to_dict (GHashTable *hash)
{
GValue val = { 0, };
GVariant *variant;
if (!hash)
return NULL;
g_value_init (&val, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT);
g_value_set_boxed (&val, hash);
variant = dbus_g_value_build_g_variant (&val);
g_value_unset (&val);
return variant;
}
/**
* _nm_utils_connection_dict_to_hash:
* @dict: a #GVariant-serialized #NMConnection
*
* Returns: a #GHashTable equivalent to @dict.
*/
GHashTable *
_nm_utils_connection_dict_to_hash (GVariant *dict)
{
GValue val = { 0, };
if (!dict)
return NULL;
dbus_g_value_parse_g_variant (dict, &val);
return g_value_get_boxed (&val);
}
GVariant * GVariant *
_nm_utils_strdict_to_dbus (const GValue *prop_value) _nm_utils_strdict_to_dbus (const GValue *prop_value)
{ {
@@ -1143,174 +1029,6 @@ nm_utils_wpa_psk_valid (const char *psk)
return TRUE; return TRUE;
} }
/**
* nm_utils_ip4_addresses_from_gvalue:
* @value: #GValue containing a #GPtrArray of #GArrays of #guint32s
*
* Utility function to convert a #GPtrArray of #GArrays of #guint32s representing
* a list of NetworkManager IPv4 addresses (which is a tuple of address, gateway,
* and prefix) into a #GSList of #NMIP4Address objects. The specific format of
* this serialization is not guaranteed to be stable and the #GArray may be
* extended in the future.
*
* Returns: (transfer full) (element-type NMIP4Address): a newly allocated #GSList of #NMIP4Address objects
**/
GSList *
nm_utils_ip4_addresses_from_gvalue (const GValue *value)
{
GPtrArray *addresses;
int i;
GSList *list = NULL;
addresses = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; addresses && (i < addresses->len); i++) {
GArray *array = (GArray *) g_ptr_array_index (addresses, i);
NMIP4Address *addr;
if (array->len < 3) {
g_warning ("Ignoring invalid IP4 address");
continue;
}
addr = nm_ip4_address_new ();
nm_ip4_address_set_address (addr, g_array_index (array, guint32, 0));
nm_ip4_address_set_prefix (addr, g_array_index (array, guint32, 1));
nm_ip4_address_set_gateway (addr, g_array_index (array, guint32, 2));
list = g_slist_prepend (list, addr);
}
return g_slist_reverse (list);
}
/**
* nm_utils_ip4_addresses_to_gvalue:
* @list: (element-type NMIP4Address): a list of #NMIP4Address objects
* @value: a pointer to a #GValue into which to place the converted addresses,
* which should be unset by the caller (when no longer needed) with
* g_value_unset().
*
* Utility function to convert a #GSList of #NMIP4Address objects into a
* #GPtrArray of #GArrays of #guint32s representing a list of NetworkManager IPv4
* addresses (which is a tuple of address, gateway, and prefix). The specific
* format of this serialization is not guaranteed to be stable and may be
* extended in the future.
**/
void
nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value)
{
GPtrArray *addresses;
GSList *iter;
addresses = g_ptr_array_new ();
for (iter = list; iter; iter = iter->next) {
NMIP4Address *addr = (NMIP4Address *) iter->data;
GArray *array;
guint32 tmp;
array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
tmp = nm_ip4_address_get_address (addr);
g_array_append_val (array, tmp);
tmp = nm_ip4_address_get_prefix (addr);
g_array_append_val (array, tmp);
tmp = nm_ip4_address_get_gateway (addr);
g_array_append_val (array, tmp);
g_ptr_array_add (addresses, array);
}
g_value_take_boxed (value, addresses);
}
/**
* nm_utils_ip4_routes_from_gvalue:
* @value: #GValue containing a #GPtrArray of #GArrays of #guint32s
*
* Utility function to convert a #GPtrArray of #GArrays of #guint32s representing
* a list of NetworkManager IPv4 routes (which is a tuple of route, next hop,
* prefix, and metric) into a #GSList of #NMIP4Route objects. The specific
* format of this serialization is not guaranteed to be stable and may be
* extended in the future.
*
* Returns: (transfer full) (element-type NMIP4Route): a newly allocated #GSList of #NMIP4Route objects
**/
GSList *
nm_utils_ip4_routes_from_gvalue (const GValue *value)
{
GPtrArray *routes;
int i;
GSList *list = NULL;
routes = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; routes && (i < routes->len); i++) {
GArray *array = (GArray *) g_ptr_array_index (routes, i);
NMIP4Route *route;
if (array->len < 4) {
g_warning ("Ignoring invalid IP4 route");
continue;
}
route = nm_ip4_route_new ();
nm_ip4_route_set_dest (route, g_array_index (array, guint32, 0));
nm_ip4_route_set_prefix (route, g_array_index (array, guint32, 1));
nm_ip4_route_set_next_hop (route, g_array_index (array, guint32, 2));
nm_ip4_route_set_metric (route, g_array_index (array, guint32, 3));
list = g_slist_prepend (list, route);
}
return g_slist_reverse (list);
}
/**
* nm_utils_ip4_routes_to_gvalue:
* @list: (element-type NMIP4Route): a list of #NMIP4Route objects
* @value: a pointer to a #GValue into which to place the converted routes,
* which should be unset by the caller (when no longer needed) with
* g_value_unset().
*
* Utility function to convert a #GSList of #NMIP4Route objects into a
* #GPtrArray of #GArrays of #guint32s representing a list of NetworkManager IPv4
* routes (which is a tuple of route, next hop, prefix, and metric). The
* specific format of this serialization is not guaranteed to be stable and may
* be extended in the future.
**/
void
nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value)
{
GPtrArray *routes;
GSList *iter;
routes = g_ptr_array_new ();
for (iter = list; iter; iter = iter->next) {
NMIP4Route *route = (NMIP4Route *) iter->data;
GArray *array;
guint32 tmp;
array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
tmp = nm_ip4_route_get_dest (route);
g_array_append_val (array, tmp);
tmp = nm_ip4_route_get_prefix (route);
g_array_append_val (array, tmp);
tmp = nm_ip4_route_get_next_hop (route);
g_array_append_val (array, tmp);
tmp = nm_ip4_route_get_metric (route);
g_array_append_val (array, tmp);
g_ptr_array_add (routes, array);
}
g_value_take_boxed (value, routes);
}
/** /**
* nm_utils_ip4_dns_to_variant: * nm_utils_ip4_dns_to_variant:
* @dns: (type utf8): an array of IP address strings * @dns: (type utf8): an array of IP address strings
@@ -1608,337 +1326,6 @@ nm_utils_ip4_get_default_prefix (guint32 ip)
return 24; /* Class C - 255.255.255.0 */ return 24; /* Class C - 255.255.255.0 */
} }
/**
* nm_utils_ip6_addresses_from_gvalue:
* @value: gvalue containing a GPtrArray of GValueArrays of (GArray of guchars) and #guint32
*
* Utility function to convert a #GPtrArray of #GValueArrays of (#GArray of guchars) and #guint32
* representing a list of NetworkManager IPv6 addresses (which is a tuple of address,
* prefix, and gateway), into a #GSList of #NMIP6Address objects. The specific format of
* this serialization is not guaranteed to be stable and the #GValueArray may be
* extended in the future.
*
* Returns: (transfer full) (element-type NMIP6Address): a newly allocated #GSList of #NMIP6Address objects
**/
GSList *
nm_utils_ip6_addresses_from_gvalue (const GValue *value)
{
GPtrArray *addresses;
int i;
GSList *list = NULL;
addresses = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; addresses && (i < addresses->len); i++) {
GValueArray *elements = (GValueArray *) g_ptr_array_index (addresses, i);
GValue *tmp;
GByteArray *ba_addr;
GByteArray *ba_gw = NULL;
NMIP6Address *addr;
guint32 prefix;
if (elements->n_values < 2 || elements->n_values > 3) {
g_warning ("%s: ignoring invalid IP6 address structure", __func__);
continue;
}
/* Third element (gateway) is optional */
if ( !_nm_utils_gvalue_array_validate (elements, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT)
&& !_nm_utils_gvalue_array_validate (elements, 3, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY)) {
g_warning ("%s: ignoring invalid IP6 address structure", __func__);
continue;
}
tmp = g_value_array_get_nth (elements, 0);
ba_addr = g_value_get_boxed (tmp);
if (ba_addr->len != 16) {
g_warning ("%s: ignoring invalid IP6 address of length %d",
__func__, ba_addr->len);
continue;
}
tmp = g_value_array_get_nth (elements, 1);
prefix = g_value_get_uint (tmp);
if (prefix > 128) {
g_warning ("%s: ignoring invalid IP6 prefix %d",
__func__, prefix);
continue;
}
if (elements->n_values == 3) {
tmp = g_value_array_get_nth (elements, 2);
ba_gw = g_value_get_boxed (tmp);
if (ba_gw->len != 16) {
g_warning ("%s: ignoring invalid IP6 gateway address of length %d",
__func__, ba_gw->len);
continue;
}
}
addr = nm_ip6_address_new ();
nm_ip6_address_set_prefix (addr, prefix);
nm_ip6_address_set_address (addr, (const struct in6_addr *) ba_addr->data);
if (ba_gw)
nm_ip6_address_set_gateway (addr, (const struct in6_addr *) ba_gw->data);
list = g_slist_prepend (list, addr);
}
return g_slist_reverse (list);
}
/**
* nm_utils_ip6_addresses_to_gvalue:
* @list: (element-type NMIP6Address): a list of #NMIP6Address objects
* @value: a pointer to a #GValue into which to place the converted addresses,
* which should be unset by the caller (when no longer needed) with
* g_value_unset().
*
* Utility function to convert a #GSList of #NMIP6Address objects into a
* #GPtrArray of #GValueArrays representing a list of NetworkManager IPv6 addresses
* (which is a tuple of address, prefix, and gateway). The specific format of
* this serialization is not guaranteed to be stable and may be extended in the
* future.
**/
void
nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value)
{
GPtrArray *addresses;
GSList *iter;
addresses = g_ptr_array_new ();
for (iter = list; iter; iter = iter->next) {
NMIP6Address *addr = (NMIP6Address *) iter->data;
GValueArray *array;
GValue element = G_VALUE_INIT;
GByteArray *ba;
array = g_value_array_new (3);
/* IP address */
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_address (addr), 16);
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
/* Prefix */
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, nm_ip6_address_get_prefix (addr));
g_value_array_append (array, &element);
g_value_unset (&element);
/* Gateway */
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_gateway (addr), 16);
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
g_ptr_array_add (addresses, array);
}
g_value_take_boxed (value, addresses);
}
/**
* nm_utils_ip6_routes_from_gvalue:
* @value: #GValue containing a #GPtrArray of #GValueArrays of (#GArray of #guchars), #guint32,
* (#GArray of #guchars), and #guint32
*
* Utility function #GPtrArray of #GValueArrays of (#GArray of #guchars), #guint32,
* (#GArray of #guchars), and #guint32 representing a list of NetworkManager IPv6
* routes (which is a tuple of destination, prefix, next hop, and metric)
* into a #GSList of #NMIP6Route objects. The specific format of this serialization
* is not guaranteed to be stable and may be extended in the future.
*
* Returns: (transfer full) (element-type NMIP6Route): a newly allocated #GSList of #NMIP6Route objects
**/
GSList *
nm_utils_ip6_routes_from_gvalue (const GValue *value)
{
GPtrArray *routes;
int i;
GSList *list = NULL;
routes = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; routes && (i < routes->len); i++) {
GValueArray *route_values = (GValueArray *) g_ptr_array_index (routes, i);
GByteArray *dest, *next_hop;
guint prefix, metric;
NMIP6Route *route;
if (!_nm_utils_gvalue_array_validate (route_values, 4,
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT,
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT)) {
g_warning ("Ignoring invalid IP6 route");
continue;
}
dest = g_value_get_boxed (g_value_array_get_nth (route_values, 0));
if (dest->len != 16) {
g_warning ("%s: ignoring invalid IP6 dest address of length %d",
__func__, dest->len);
continue;
}
prefix = g_value_get_uint (g_value_array_get_nth (route_values, 1));
next_hop = g_value_get_boxed (g_value_array_get_nth (route_values, 2));
if (next_hop->len != 16) {
g_warning ("%s: ignoring invalid IP6 next_hop address of length %d",
__func__, next_hop->len);
continue;
}
metric = g_value_get_uint (g_value_array_get_nth (route_values, 3));
route = nm_ip6_route_new ();
nm_ip6_route_set_dest (route, (struct in6_addr *)dest->data);
nm_ip6_route_set_prefix (route, prefix);
nm_ip6_route_set_next_hop (route, (struct in6_addr *)next_hop->data);
nm_ip6_route_set_metric (route, metric);
list = g_slist_prepend (list, route);
}
return g_slist_reverse (list);
}
/**
* nm_utils_ip6_routes_to_gvalue:
* @list: (element-type NMIP6Route): a list of #NMIP6Route objects
* @value: a pointer to a #GValue into which to place the converted routes,
* which should be unset by the caller (when no longer needed) with
* g_value_unset().
*
* Utility function to convert a #GSList of #NMIP6Route objects into a #GPtrArray of
* #GValueArrays of (#GArray of #guchars), #guint32, (#GArray of #guchars), and #guint32
* representing a list of NetworkManager IPv6 routes (which is a tuple of destination,
* prefix, next hop, and metric). The specific format of this serialization is not
* guaranteed to be stable and may be extended in the future.
**/
void
nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value)
{
GPtrArray *routes;
GSList *iter;
routes = g_ptr_array_new ();
for (iter = list; iter; iter = iter->next) {
NMIP6Route *route = (NMIP6Route *) iter->data;
GValueArray *array;
const struct in6_addr *addr;
GByteArray *ba;
GValue element = G_VALUE_INIT;
array = g_value_array_new (4);
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
addr = nm_ip6_route_get_dest (route);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, nm_ip6_route_get_prefix (route));
g_value_array_append (array, &element);
g_value_unset (&element);
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
addr = nm_ip6_route_get_next_hop (route);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
g_value_take_boxed (&element, ba);
g_value_array_append (array, &element);
g_value_unset (&element);
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, nm_ip6_route_get_metric (route));
g_value_array_append (array, &element);
g_value_unset (&element);
g_ptr_array_add (routes, array);
}
g_value_take_boxed (value, routes);
}
/**
* nm_utils_ip6_dns_from_gvalue: (skip)
* @value: a #GValue
*
* Converts a #GValue containing a #GPtrArray of IP6 DNS, represented as
* #GByteArrays into a #GSList of IP address strings.
*
* Returns: a #GSList of IP6 addresses.
*/
GSList *
nm_utils_ip6_dns_from_gvalue (const GValue *value)
{
GPtrArray *dns;
int i;
GSList *list = NULL;
dns = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; dns && (i < dns->len); i++) {
GByteArray *bytearray = (GByteArray *) g_ptr_array_index (dns, i);
const char *str;
if (bytearray->len != 16) {
g_warning ("%s: ignoring invalid IP6 address of length %d",
__func__, bytearray->len);
continue;
}
str = nm_utils_inet6_ntop ((struct in6_addr *) bytearray->data, NULL);
list = g_slist_prepend (list, g_strdup (str));
}
return g_slist_reverse (list);
}
/**
* nm_utils_ip6_dns_to_gvalue: (skip)
* @list: a list of #NMIP6Route objects
* @value: a pointer to a #GValue into which to place the converted DNS server
* addresses, which should be unset by the caller (when no longer needed) with
* g_value_unset().
*
* Utility function to convert a #GSList of <literal><type>struct
* in6_addr</type></literal> structs into a #GPtrArray of #GByteArrays
* representing each server's IPv6 addresses in network byte order.
* The specific format of this serialization is not guaranteed to be
* stable and may be extended in the future.
*/
void
nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value)
{
GPtrArray *dns;
GSList *iter;
dns = g_ptr_array_new ();
for (iter = list; iter; iter = iter->next) {
const char *str = iter->data;
GByteArray *bytearray;
bytearray = g_byte_array_new ();
g_byte_array_set_size (bytearray, 16);
inet_pton (AF_INET6, str, bytearray->data);
g_ptr_array_add (dns, bytearray);
}
g_value_take_boxed (value, dns);
}
/** /**
* nm_utils_ip6_dns_to_variant: * nm_utils_ip6_dns_to_variant:
* @dns: (type utf8): an array of IP address strings * @dns: (type utf8): an array of IP address strings

View File

@@ -49,8 +49,6 @@ gboolean nm_utils_same_ssid (const guint8 *ssid1, gsize len1,
gboolean ignore_trailing_null); gboolean ignore_trailing_null);
char * nm_utils_ssid_to_utf8 (const guint8 *ssid, gsize len); char * nm_utils_ssid_to_utf8 (const guint8 *ssid, gsize len);
GHashTable *nm_utils_gvalue_hash_dup (GHashTable *hash);
/** /**
* NMUtilsSecurityType: * NMUtilsSecurityType:
* @NMU_SEC_INVALID: unknown or invalid security, placeholder and not used * @NMU_SEC_INVALID: unknown or invalid security, placeholder and not used
@@ -95,12 +93,6 @@ gboolean nm_utils_ap_mode_security_valid (NMUtilsSecurityType type,
gboolean nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type); gboolean nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type);
gboolean nm_utils_wpa_psk_valid (const char *psk); gboolean nm_utils_wpa_psk_valid (const char *psk);
GSList *nm_utils_ip4_addresses_from_gvalue (const GValue *value);
void nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value);
GSList *nm_utils_ip4_routes_from_gvalue (const GValue *value);
void nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value);
GVariant *nm_utils_ip4_dns_to_variant (char **dns); GVariant *nm_utils_ip4_dns_to_variant (char **dns);
char **nm_utils_ip4_dns_from_variant (GVariant *value); char **nm_utils_ip4_dns_from_variant (GVariant *value);
GVariant *nm_utils_ip4_addresses_to_variant (GPtrArray *addresses); GVariant *nm_utils_ip4_addresses_to_variant (GPtrArray *addresses);
@@ -112,15 +104,6 @@ guint32 nm_utils_ip4_netmask_to_prefix (guint32 netmask);
guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix); guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix);
guint32 nm_utils_ip4_get_default_prefix (guint32 ip); guint32 nm_utils_ip4_get_default_prefix (guint32 ip);
GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value);
void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value);
GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value);
void nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value);
GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value);
void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value);
GVariant *nm_utils_ip6_dns_to_variant (char **dns); GVariant *nm_utils_ip6_dns_to_variant (char **dns);
char **nm_utils_ip6_dns_from_variant (GVariant *value); char **nm_utils_ip6_dns_from_variant (GVariant *value);
GVariant *nm_utils_ip6_addresses_to_variant (GPtrArray *addresses); GVariant *nm_utils_ip6_addresses_to_variant (GPtrArray *addresses);

View File

@@ -4,6 +4,7 @@ SUBDIRS = . tests
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-I$(top_srcdir)/include \ -I$(top_srcdir)/include \
-I$(top_builddir)/introspection \
-I$(top_srcdir)/libnm-core \ -I$(top_srcdir)/libnm-core \
-I$(top_builddir)/libnm-core \ -I$(top_builddir)/libnm-core \
-I$(top_srcdir)/libnm \ -I$(top_srcdir)/libnm \
@@ -12,7 +13,6 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \ -DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
$(GUDEV_CFLAGS) \ $(GUDEV_CFLAGS) \
-DNMRUNDIR=\"$(nmrundir)\" -DNMRUNDIR=\"$(nmrundir)\"
@@ -104,25 +104,15 @@ libnm_la_SOURCES = \
$(libnm_la_csources) \ $(libnm_la_csources) \
$(libnm_la_private_headers) $(libnm_la_private_headers)
nm-secret-agent-glue.h: $(top_srcdir)/introspection/nm-secret-agent.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_secret_agent --mode=glib-server --output=$@ $<
nm-vpn-plugin-glue.h: $(top_srcdir)/introspection/nm-vpn-plugin.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_plugin --mode=glib-server --output=$@ $<
GLIB_GENERATED = nm-enum-types.h nm-enum-types.c GLIB_GENERATED = nm-enum-types.h nm-enum-types.c
nm_enum_types_sources = $(libnminclude_HEADERS) nm_enum_types_sources = $(libnminclude_HEADERS)
GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include <nm-core-enum-types.h>\n' GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include <nm-core-enum-types.h>\n'
GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
BUILT_SOURCES = \
nm-vpn-plugin-glue.h \
nm-secret-agent-glue.h
libnm_la_LIBADD = \ libnm_la_LIBADD = \
$(top_builddir)/libnm-core/libnm-core.la \ $(top_builddir)/libnm-core/libnm-core.la \
$(top_builddir)/introspection/libnmdbus.la \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_LIBS) \
$(UUID_LIBS) \ $(UUID_LIBS) \
$(GUDEV_LIBS) $(GUDEV_LIBS)
@@ -133,7 +123,7 @@ libnm_la_LDFLAGS = -Wl,--version-script=$(SYMBOL_VIS_FILE) \
### ###
BUILT_SOURCES += $(GLIB_GENERATED) BUILT_SOURCES = $(GLIB_GENERATED)
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnm.pc pkgconfig_DATA = libnm.pc
@@ -160,8 +150,8 @@ introspection_sources = \
$(libnm_la_csources) $(libnm_la_csources)
NM-1.0.gir: libnm.la NM-1.0.gir: libnm.la
NM_1_0_gir_INCLUDES = Gio-2.0 DBusGLib-1.0 NM_1_0_gir_INCLUDES = Gio-2.0
NM_1_0_gir_PACKAGES = gio-2.0 dbus-glib-1 gudev-1.0 NM_1_0_gir_PACKAGES = gio-2.0 gudev-1.0
NM_1_0_gir_EXPORT_PACKAGES = libnm NM_1_0_gir_EXPORT_PACKAGES = libnm
NM_1_0_gir_CFLAGS = $(AM_CPPFLAGS) NM_1_0_gir_CFLAGS = $(AM_CPPFLAGS)
NM_1_0_gir_LIBS = libnm.la NM_1_0_gir_LIBS = libnm.la

View File

@@ -866,7 +866,6 @@ global:
nm_utils_deinit; nm_utils_deinit;
nm_utils_escape_ssid; nm_utils_escape_ssid;
nm_utils_file_is_pkcs12; nm_utils_file_is_pkcs12;
nm_utils_gvalue_hash_dup;
nm_utils_hex2byte; nm_utils_hex2byte;
nm_utils_hexstr2bin; nm_utils_hexstr2bin;
nm_utils_hwaddr_atoba; nm_utils_hwaddr_atoba;
@@ -879,30 +878,20 @@ global:
nm_utils_inet4_ntop; nm_utils_inet4_ntop;
nm_utils_inet6_ntop; nm_utils_inet6_ntop;
nm_utils_init; nm_utils_init;
nm_utils_ip4_addresses_from_gvalue;
nm_utils_ip4_addresses_from_variant; nm_utils_ip4_addresses_from_variant;
nm_utils_ip4_addresses_to_gvalue;
nm_utils_ip4_addresses_to_variant; nm_utils_ip4_addresses_to_variant;
nm_utils_ip4_dns_from_variant; nm_utils_ip4_dns_from_variant;
nm_utils_ip4_dns_to_variant; nm_utils_ip4_dns_to_variant;
nm_utils_ip4_get_default_prefix; nm_utils_ip4_get_default_prefix;
nm_utils_ip4_netmask_to_prefix; nm_utils_ip4_netmask_to_prefix;
nm_utils_ip4_prefix_to_netmask; nm_utils_ip4_prefix_to_netmask;
nm_utils_ip4_routes_from_gvalue;
nm_utils_ip4_routes_from_variant; nm_utils_ip4_routes_from_variant;
nm_utils_ip4_routes_to_gvalue;
nm_utils_ip4_routes_to_variant; nm_utils_ip4_routes_to_variant;
nm_utils_ip6_addresses_from_gvalue;
nm_utils_ip6_addresses_from_variant; nm_utils_ip6_addresses_from_variant;
nm_utils_ip6_addresses_to_gvalue;
nm_utils_ip6_addresses_to_variant; nm_utils_ip6_addresses_to_variant;
nm_utils_ip6_dns_from_gvalue;
nm_utils_ip6_dns_from_variant; nm_utils_ip6_dns_from_variant;
nm_utils_ip6_dns_to_gvalue;
nm_utils_ip6_dns_to_variant; nm_utils_ip6_dns_to_variant;
nm_utils_ip6_routes_from_gvalue;
nm_utils_ip6_routes_from_variant; nm_utils_ip6_routes_from_variant;
nm_utils_ip6_routes_to_gvalue;
nm_utils_ip6_routes_to_variant; nm_utils_ip6_routes_to_variant;
nm_utils_is_empty_ssid; nm_utils_is_empty_ssid;
nm_utils_is_uuid; nm_utils_is_uuid;

View File

@@ -32,7 +32,7 @@
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-dbus-helpers.h" #include "nm-dbus-helpers.h"
static GType _nm_active_connection_decide_type (GValue *value); static GType _nm_active_connection_decide_type (GVariant *value);
G_DEFINE_TYPE_WITH_CODE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT,
_nm_object_register_type_func (g_define_type_id, _nm_object_register_type_func (g_define_type_id,
@@ -83,10 +83,10 @@ enum {
}; };
static GType static GType
_nm_active_connection_decide_type (GValue *value) _nm_active_connection_decide_type (GVariant *value)
{ {
/* @value is the value of the o.fd.NM.ActiveConnection property "VPN" */ /* @value is the value of the o.fd.NM.ActiveConnection property "VPN" */
if (g_value_get_boolean (value)) if (g_variant_get_boolean (value))
return NM_TYPE_VPN_CONNECTION; return NM_TYPE_VPN_CONNECTION;
else else
return NM_TYPE_ACTIVE_CONNECTION; return NM_TYPE_ACTIVE_CONNECTION;

View File

@@ -19,7 +19,6 @@
* Copyright 2007 - 2013 Red Hat, Inc. * Copyright 2007 - 2013 Red Hat, Inc.
*/ */
#include <dbus/dbus-glib.h>
#include <string.h> #include <string.h>
#include <nm-utils.h> #include <nm-utils.h>
@@ -32,9 +31,10 @@
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "nm-vpn-connection.h" #include "nm-vpn-connection.h"
#include "nm-object-cache.h" #include "nm-object-cache.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-utils-private.h" #include "nm-dbus-helpers.h"
#include "nmdbus-manager.h"
void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled); void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled);
@@ -51,7 +51,7 @@ G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, NM_TYPE_OBJECT,
#define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate)) #define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate))
typedef struct { typedef struct {
DBusGProxy *client_proxy; NMDBusManager *manager_proxy;
char *version; char *version;
NMState state; NMState state;
gboolean startup; gboolean startup;
@@ -61,7 +61,7 @@ typedef struct {
NMActiveConnection *primary_connection; NMActiveConnection *primary_connection;
NMActiveConnection *activating_connection; NMActiveConnection *activating_connection;
DBusGProxyCall *perm_call; GCancellable *perm_call_cancellable;
GHashTable *permissions; GHashTable *permissions;
/* Activations waiting for their NMActiveConnection /* Activations waiting for their NMActiveConnection
@@ -167,7 +167,7 @@ wireless_enabled_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
poke_wireless_devices_with_rf_status (NM_CLIENT (object)); poke_wireless_devices_with_rf_status (NM_CLIENT (object));
} }
static void client_recheck_permissions (DBusGProxy *proxy, gpointer user_data); static void client_recheck_permissions (NMDBusManager *proxy, gpointer user_data);
static void active_connections_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data); static void active_connections_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data);
static void object_creation_failed_cb (GObject *object, GError *error, char *failed_path); static void object_creation_failed_cb (GObject *object, GError *error, char *failed_path);
@@ -196,18 +196,14 @@ init_dbus (NMObject *object)
NM_OBJECT_CLASS (nm_client_parent_class)->init_dbus (object); NM_OBJECT_CLASS (nm_client_parent_class)->init_dbus (object);
priv->client_proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE); priv->manager_proxy = NMDBUS_MANAGER (_nm_object_get_proxy (object, NM_DBUS_INTERFACE));
_nm_object_register_properties (object, _nm_object_register_properties (object,
NM_DBUS_INTERFACE, NM_DBUS_INTERFACE,
property_info); property_info);
/* Permissions */ /* Permissions */
dbus_g_proxy_add_signal (priv->client_proxy, "CheckPermissions", G_TYPE_INVALID); g_signal_connect (priv->manager_proxy, "check-permissions",
dbus_g_proxy_connect_signal (priv->client_proxy, G_CALLBACK (client_recheck_permissions), object);
"CheckPermissions",
G_CALLBACK (client_recheck_permissions),
object,
NULL);
} }
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK "org.freedesktop.NetworkManager.enable-disable-network" #define NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK "org.freedesktop.NetworkManager.enable-disable-network"
@@ -264,7 +260,7 @@ nm_permission_result_to_client (const char *nm)
} }
static void static void
update_permissions (NMClient *self, GHashTable *permissions) update_permissions (NMClient *self, GVariant *permissions)
{ {
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
GHashTableIter iter; GHashTableIter iter;
@@ -278,11 +274,14 @@ update_permissions (NMClient *self, GHashTable *permissions)
g_hash_table_remove_all (priv->permissions); g_hash_table_remove_all (priv->permissions);
if (permissions) { if (permissions) {
GVariantIter viter;
const char *pkey, *pvalue;
/* Process new permissions */ /* Process new permissions */
g_hash_table_iter_init (&iter, permissions); g_variant_iter_init (&viter, permissions);
while (g_hash_table_iter_next (&iter, &key, &value)) { while (g_variant_iter_next (&viter, "{&s&s}", &pkey, &pvalue)) {
perm = nm_permission_to_client ((const char *) key); perm = nm_permission_to_client (pkey);
perm_result = nm_permission_result_to_client ((const char *) value); perm_result = nm_permission_result_to_client (pvalue);
if (perm) { if (perm) {
g_hash_table_insert (priv->permissions, g_hash_table_insert (priv->permissions,
GUINT_TO_POINTER (perm), GUINT_TO_POINTER (perm),
@@ -319,48 +318,68 @@ update_permissions (NMClient *self, GHashTable *permissions)
static gboolean static gboolean
get_permissions_sync (NMClient *self, GError **error) get_permissions_sync (NMClient *self, GError **error)
{ {
gboolean success; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
GHashTable *permissions = NULL; GVariant *permissions;
success = dbus_g_proxy_call_with_timeout (NM_CLIENT_GET_PRIVATE (self)->client_proxy, if (nmdbus_manager_call_get_permissions_sync (priv->manager_proxy,
"GetPermissions", 3000, error, &permissions,
G_TYPE_INVALID, NULL, error)) {
DBUS_TYPE_G_MAP_OF_STRING, &permissions, G_TYPE_INVALID); update_permissions (self, permissions);
update_permissions (self, success ? permissions : NULL); g_variant_unref (permissions);
if (permissions) return TRUE;
g_hash_table_destroy (permissions); } else {
update_permissions (self, NULL);
return success; return FALSE;
}
} }
static void static void
get_permissions_reply (DBusGProxy *proxy, get_permissions_reply (GObject *object,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
NMClient *self = NM_CLIENT (user_data); NMClient *self;
GHashTable *permissions; NMClientPrivate *priv;
GVariant *permissions = NULL;
GError *error = NULL; GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, /* WARNING: this may be called after the client is disposed, so we can't
DBUS_TYPE_G_MAP_OF_STRING, &permissions, * look at self/priv until after we've determined that that isn't the case.
G_TYPE_INVALID); */
NM_CLIENT_GET_PRIVATE (self)->perm_call = NULL;
update_permissions (NM_CLIENT (user_data), error ? NULL : permissions); nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object),
&permissions,
result, &error);
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
/* @self has been disposed. */
g_error_free (error);
return;
}
self = user_data;
priv = NM_CLIENT_GET_PRIVATE (self);
update_permissions (self, permissions);
g_clear_pointer (&permissions, g_variant_unref);
g_clear_error (&error); g_clear_error (&error);
g_clear_object (&priv->perm_call_cancellable);
} }
static void static void
client_recheck_permissions (DBusGProxy *proxy, gpointer user_data) client_recheck_permissions (NMDBusManager *proxy, gpointer user_data)
{ {
NMClient *self = NM_CLIENT (user_data); NMClient *self = NM_CLIENT (user_data);
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
if (!priv->perm_call) { if (priv->perm_call_cancellable)
priv->perm_call = dbus_g_proxy_begin_call (NM_CLIENT_GET_PRIVATE (self)->client_proxy, "GetPermissions", return;
get_permissions_reply, self, NULL,
G_TYPE_INVALID); priv->perm_call_cancellable = g_cancellable_new ();
} nmdbus_manager_call_get_permissions (priv->manager_proxy,
priv->perm_call_cancellable,
get_permissions_reply,
self);
} }
/** /**
@@ -550,24 +569,21 @@ recheck_pending_activations (NMClient *self, const char *failed_path, GError *er
} }
static void static void
activate_cb (DBusGProxy *proxy, activate_cb (GObject *object,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
ActivateInfo *info = user_data; ActivateInfo *info = user_data;
char *path;
GError *error = NULL; GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, if (nmdbus_manager_call_activate_connection_finish (NMDBUS_MANAGER (object),
DBUS_TYPE_G_OBJECT_PATH, &path, &info->active_path,
G_TYPE_INVALID); result, &error)) {
if (error) { recheck_pending_activations (info->client, NULL, NULL);
} else {
activate_info_complete (info, NULL, error); activate_info_complete (info, NULL, error);
activate_info_free (info); activate_info_free (info);
g_clear_error (&error); g_clear_error (&error);
} else {
info->active_path = path;
recheck_pending_activations (info->client, NULL, NULL);
} }
} }
@@ -644,35 +660,31 @@ nm_client_activate_connection (NMClient *client,
return; return;
} }
dbus_g_proxy_begin_call (priv->client_proxy, "ActivateConnection", nmdbus_manager_call_activate_connection (priv->manager_proxy,
activate_cb, info, NULL, connection ? nm_connection_get_path (connection) : "/",
DBUS_TYPE_G_OBJECT_PATH, connection ? nm_connection_get_path (connection) : "/", device ? nm_object_get_path (NM_OBJECT (device)) : "/",
DBUS_TYPE_G_OBJECT_PATH, device ? nm_object_get_path (NM_OBJECT (device)) : "/", specific_object ? specific_object : "/",
DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/", NULL,
G_TYPE_INVALID); activate_cb, info);
} }
static void static void
add_activate_cb (DBusGProxy *proxy, add_activate_cb (GObject *object,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
ActivateInfo *info = user_data; ActivateInfo *info = user_data;
char *connection_path;
char *active_path;
GError *error = NULL; GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, if (nmdbus_manager_call_add_and_activate_connection_finish (NMDBUS_MANAGER (object),
DBUS_TYPE_G_OBJECT_PATH, &connection_path, &info->new_connection_path,
DBUS_TYPE_G_OBJECT_PATH, &active_path, &info->active_path,
G_TYPE_INVALID); result, &error)) {
if (error) { recheck_pending_activations (info->client, NULL, NULL);
} else {
activate_info_complete (info, NULL, error); activate_info_complete (info, NULL, error);
activate_info_free (info); activate_info_free (info);
} else { g_clear_error (&error);
info->new_connection_path = connection_path;
info->active_path = active_path;
recheck_pending_activations (info->client, NULL, NULL);
} }
} }
@@ -708,7 +720,7 @@ nm_client_add_and_activate_connection (NMClient *client,
{ {
NMClientPrivate *priv; NMClientPrivate *priv;
ActivateInfo *info; ActivateInfo *info;
GHashTable *hash = NULL; GVariant *dict = NULL;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (NM_IS_DEVICE (device)); g_return_if_fail (NM_IS_DEVICE (device));
@@ -718,30 +730,23 @@ nm_client_add_and_activate_connection (NMClient *client,
info->user_data = user_data; info->user_data = user_data;
info->client = client; info->client = client;
if (partial) { if (partial)
GVariant *dict;
dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL); dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL);
hash = _nm_utils_connection_dict_to_hash (dict); if (!dict)
g_variant_unref (dict); dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
}
if (!hash)
hash = g_hash_table_new (g_str_hash, g_str_equal);
priv = NM_CLIENT_GET_PRIVATE (client); priv = NM_CLIENT_GET_PRIVATE (client);
priv->pending_activations = g_slist_prepend (priv->pending_activations, info); priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
if (nm_client_get_nm_running (client)) { if (nm_client_get_nm_running (client)) {
dbus_g_proxy_begin_call (priv->client_proxy, "AddAndActivateConnection", nmdbus_manager_call_add_and_activate_connection (priv->manager_proxy,
add_activate_cb, info, NULL, dict,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, nm_object_get_path (NM_OBJECT (device)),
DBUS_TYPE_G_OBJECT_PATH, nm_object_get_path (NM_OBJECT (device)), specific_object ? specific_object : "/",
DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/", NULL,
G_TYPE_INVALID); add_activate_cb, info);
} else } else
info->idle_id = g_idle_add (activate_nm_not_running, info); info->idle_id = g_idle_add (activate_nm_not_running, info);
g_hash_table_unref (hash);
} }
static void static void
@@ -779,10 +784,9 @@ nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active)
return; return;
path = nm_object_get_path (NM_OBJECT (active)); path = nm_object_get_path (NM_OBJECT (active));
if (!dbus_g_proxy_call (priv->client_proxy, "DeactivateConnection", &error, if (!nmdbus_manager_call_deactivate_connection_sync (priv->manager_proxy,
DBUS_TYPE_G_OBJECT_PATH, path, path,
G_TYPE_INVALID, NULL, &error)) {
G_TYPE_INVALID)) {
g_warning ("Could not deactivate connection '%s': %s", path, error->message); g_warning ("Could not deactivate connection '%s': %s", path, error->message);
g_error_free (error); g_error_free (error);
} }
@@ -838,20 +842,15 @@ nm_client_wireless_get_enabled (NMClient *client)
void void
nm_client_wireless_set_enabled (NMClient *client, gboolean enabled) nm_client_wireless_set_enabled (NMClient *client, gboolean enabled)
{ {
GValue value = G_VALUE_INIT;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
if (!nm_client_get_nm_running (client)) if (!nm_client_get_nm_running (client))
return; return;
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, enabled);
_nm_object_set_property (NM_OBJECT (client), _nm_object_set_property (NM_OBJECT (client),
NM_DBUS_INTERFACE, NM_DBUS_INTERFACE,
"WirelessEnabled", "WirelessEnabled",
&value); "b", enabled);
} }
/** /**
@@ -896,20 +895,15 @@ nm_client_wwan_get_enabled (NMClient *client)
void void
nm_client_wwan_set_enabled (NMClient *client, gboolean enabled) nm_client_wwan_set_enabled (NMClient *client, gboolean enabled)
{ {
GValue value = G_VALUE_INIT;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
if (!nm_client_get_nm_running (client)) if (!nm_client_get_nm_running (client))
return; return;
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, enabled);
_nm_object_set_property (NM_OBJECT (client), _nm_object_set_property (NM_OBJECT (client),
NM_DBUS_INTERFACE, NM_DBUS_INTERFACE,
"WwanEnabled", "WwanEnabled",
&value); "b", enabled);
} }
/** /**
@@ -954,20 +948,15 @@ nm_client_wimax_get_enabled (NMClient *client)
void void
nm_client_wimax_set_enabled (NMClient *client, gboolean enabled) nm_client_wimax_set_enabled (NMClient *client, gboolean enabled)
{ {
GValue value = G_VALUE_INIT;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
if (!nm_client_get_nm_running (client)) if (!nm_client_get_nm_running (client))
return; return;
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, enabled);
_nm_object_set_property (NM_OBJECT (client), _nm_object_set_property (NM_OBJECT (client),
NM_DBUS_INTERFACE, NM_DBUS_INTERFACE,
"WimaxEnabled", "WimaxEnabled",
&value); "b", enabled);
} }
/** /**
@@ -1073,10 +1062,9 @@ nm_client_networking_set_enabled (NMClient *client, gboolean enable)
if (!nm_client_get_nm_running (client)) if (!nm_client_get_nm_running (client))
return; return;
if (!dbus_g_proxy_call (NM_CLIENT_GET_PRIVATE (client)->client_proxy, "Enable", &err, if (!nmdbus_manager_call_enable_sync (NM_CLIENT_GET_PRIVATE (client)->manager_proxy,
G_TYPE_BOOLEAN, enable, enable,
G_TYPE_INVALID, NULL, &err)) {
G_TYPE_INVALID)) {
g_warning ("Error enabling/disabling networking: %s", err->message); g_warning ("Error enabling/disabling networking: %s", err->message);
g_error_free (err); g_error_free (err);
} }
@@ -1154,11 +1142,9 @@ nm_client_get_logging (NMClient *client, char **level, char **domains, GError **
if (!level && !domains) if (!level && !domains)
return TRUE; return TRUE;
return dbus_g_proxy_call (priv->client_proxy, "GetLogging", error, return nmdbus_manager_call_get_logging_sync (priv->manager_proxy,
G_TYPE_INVALID, level, domains,
G_TYPE_STRING, level, NULL, error);
G_TYPE_STRING, domains,
G_TYPE_INVALID);
} }
/** /**
@@ -1193,11 +1179,9 @@ nm_client_set_logging (NMClient *client, const char *level, const char *domains,
if (!level && !domains) if (!level && !domains)
return TRUE; return TRUE;
return dbus_g_proxy_call (priv->client_proxy, "SetLogging", error, return nmdbus_manager_call_set_logging_sync (priv->manager_proxy,
G_TYPE_STRING, level ? level : "", level, domains,
G_TYPE_STRING, domains ? domains : "", NULL, error);
G_TYPE_INVALID,
G_TYPE_INVALID);
} }
/** /**
@@ -1349,7 +1333,7 @@ nm_running_changed_cb (GObject *object,
} else { } else {
_nm_object_suppress_property_updates (NM_OBJECT (client), FALSE); _nm_object_suppress_property_updates (NM_OBJECT (client), FALSE);
_nm_object_reload_properties_async (NM_OBJECT (client), updated_properties, client); _nm_object_reload_properties_async (NM_OBJECT (client), updated_properties, client);
client_recheck_permissions (priv->client_proxy, client); client_recheck_permissions (priv->manager_proxy, client);
} }
} }
@@ -1393,77 +1377,39 @@ nm_client_check_connectivity (NMClient *client,
GError **error) GError **error)
{ {
NMClientPrivate *priv; NMClientPrivate *priv;
NMConnectivityState connectivity; guint32 connectivity;
g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN); g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
priv = NM_CLIENT_GET_PRIVATE (client); priv = NM_CLIENT_GET_PRIVATE (client);
if (!dbus_g_proxy_call (priv->client_proxy, "CheckConnectivity", error, if (nmdbus_manager_call_check_connectivity_sync (priv->manager_proxy,
G_TYPE_INVALID, &connectivity,
G_TYPE_UINT, &connectivity, cancellable, error))
G_TYPE_INVALID)) return connectivity;
connectivity = NM_CONNECTIVITY_UNKNOWN; else
return NM_CONNECTIVITY_UNKNOWN;
return connectivity;
}
typedef struct {
NMClient *client;
DBusGProxyCall *call;
GCancellable *cancellable;
guint cancelled_id;
NMConnectivityState connectivity;
} CheckConnectivityData;
static void
check_connectivity_data_free (CheckConnectivityData *ccd)
{
if (ccd->cancellable) {
if (ccd->cancelled_id)
g_signal_handler_disconnect (ccd->cancellable, ccd->cancelled_id);
g_object_unref (ccd->cancellable);
}
g_slice_free (CheckConnectivityData, ccd);
} }
static void static void
check_connectivity_cb (DBusGProxy *proxy, check_connectivity_cb (GObject *object,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = user_data; GSimpleAsyncResult *simple = user_data;
CheckConnectivityData *ccd = g_simple_async_result_get_op_res_gpointer (simple); guint32 connectivity;
GError *error = NULL; GError *error = NULL;
if (ccd->cancellable) { if (nmdbus_manager_call_check_connectivity_finish (NMDBUS_MANAGER (object),
g_signal_handler_disconnect (ccd->cancellable, ccd->cancelled_id); &connectivity,
ccd->cancelled_id = 0; result, &error))
} g_simple_async_result_set_op_res_gssize (simple, connectivity);
else
if (!dbus_g_proxy_end_call (proxy, call, &error,
G_TYPE_UINT, &ccd->connectivity,
G_TYPE_INVALID))
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple); g_simple_async_result_complete (simple);
g_object_unref (simple); g_object_unref (simple);
} }
static void
check_connectivity_cancelled_cb (GCancellable *cancellable,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
CheckConnectivityData *ccd = g_simple_async_result_get_op_res_gpointer (simple);
g_signal_handler_disconnect (cancellable, ccd->cancelled_id);
ccd->cancelled_id = 0;
dbus_g_proxy_cancel_call (NM_CLIENT_GET_PRIVATE (ccd->client)->client_proxy, ccd->call);
g_simple_async_result_complete_in_idle (simple);
}
/** /**
* nm_client_check_connectivity_async: * nm_client_check_connectivity_async:
* @client: an #NMClient * @client: an #NMClient
@@ -1484,29 +1430,15 @@ nm_client_check_connectivity_async (NMClient *client,
{ {
NMClientPrivate *priv; NMClientPrivate *priv;
GSimpleAsyncResult *simple; GSimpleAsyncResult *simple;
CheckConnectivityData *ccd;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
priv = NM_CLIENT_GET_PRIVATE (client); priv = NM_CLIENT_GET_PRIVATE (client);
ccd = g_slice_new (CheckConnectivityData);
ccd->client = client;
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_check_connectivity_async); nm_client_check_connectivity_async);
g_simple_async_result_set_op_res_gpointer (simple, ccd, (GDestroyNotify) check_connectivity_data_free); nmdbus_manager_call_check_connectivity (priv->manager_proxy,
cancellable,
if (cancellable) { check_connectivity_cb, simple);
ccd->cancellable = g_object_ref (cancellable);
ccd->cancelled_id = g_signal_connect (cancellable, "cancelled",
G_CALLBACK (check_connectivity_cancelled_cb),
simple);
g_simple_async_result_set_check_cancellable (simple, cancellable);
}
ccd->call = dbus_g_proxy_begin_call (priv->client_proxy, "CheckConnectivity",
check_connectivity_cb, simple, NULL,
G_TYPE_INVALID);
} }
/** /**
@@ -1526,17 +1458,14 @@ nm_client_check_connectivity_finish (NMClient *client,
GError **error) GError **error)
{ {
GSimpleAsyncResult *simple; GSimpleAsyncResult *simple;
CheckConnectivityData *ccd;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN); g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN);
simple = G_SIMPLE_ASYNC_RESULT (result); simple = G_SIMPLE_ASYNC_RESULT (result);
ccd = g_simple_async_result_get_op_res_gpointer (simple);
if (g_simple_async_result_propagate_error (simple, error)) if (g_simple_async_result_propagate_error (simple, error))
return NM_CONNECTIVITY_UNKNOWN; return NM_CONNECTIVITY_UNKNOWN;
return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
return ccd->connectivity;
} }
/****************************************************************/ /****************************************************************/
@@ -1731,6 +1660,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
typedef struct { typedef struct {
NMClient *client; NMClient *client;
GCancellable *cancellable;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
} NMClientInitData; } NMClientInitData;
@@ -1739,22 +1669,23 @@ init_async_complete (NMClientInitData *init_data)
{ {
g_simple_async_result_complete (init_data->result); g_simple_async_result_complete (init_data->result);
g_object_unref (init_data->result); g_object_unref (init_data->result);
g_clear_object (&init_data->cancellable);
g_slice_free (NMClientInitData, init_data); g_slice_free (NMClientInitData, init_data);
} }
static void static void
init_async_got_permissions (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) init_async_got_permissions (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NMClientInitData *init_data = user_data; NMClientInitData *init_data = user_data;
GHashTable *permissions; GVariant *permissions;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, if (nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object),
DBUS_TYPE_G_MAP_OF_STRING, &permissions, &permissions,
G_TYPE_INVALID); result, NULL)) {
update_permissions (init_data->client, error ? NULL : permissions); update_permissions (init_data->client, permissions);
if (error) g_variant_unref (permissions);
g_simple_async_result_take_error (init_data->result, error); } else
update_permissions (init_data->client, NULL);
init_async_complete (init_data); init_async_complete (init_data);
} }
@@ -1777,9 +1708,9 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d
return; return;
} }
dbus_g_proxy_begin_call (priv->client_proxy, "GetPermissions", nmdbus_manager_call_get_permissions (priv->manager_proxy,
init_async_got_permissions, init_data, NULL, init_data->cancellable,
G_TYPE_INVALID); init_async_got_permissions, init_data);
} }
static void static void
@@ -1798,6 +1729,7 @@ init_async (GAsyncInitable *initable, int io_priority,
init_data = g_slice_new0 (NMClientInitData); init_data = g_slice_new0 (NMClientInitData);
init_data->client = NM_CLIENT (initable); init_data->client = NM_CLIENT (initable);
init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback, init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
user_data, init_async); user_data, init_async);
g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE); g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
@@ -1823,9 +1755,9 @@ dispose (GObject *object)
NMClient *client = NM_CLIENT (object); NMClient *client = NM_CLIENT (object);
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
if (priv->perm_call) { if (priv->perm_call_cancellable) {
dbus_g_proxy_cancel_call (priv->client_proxy, priv->perm_call); g_cancellable_cancel (priv->perm_call_cancellable);
priv->perm_call = NULL; g_clear_object (&priv->perm_call_cancellable);
} }
free_devices (client, TRUE); free_devices (client, TRUE);
@@ -1967,6 +1899,7 @@ nm_client_class_init (NMClientClass *client_class)
g_type_class_add_private (client_class, sizeof (NMClientPrivate)); g_type_class_add_private (client_class, sizeof (NMClientPrivate));
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE); _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE);
_nm_dbus_register_proxy_type (NM_DBUS_INTERFACE, NMDBUS_TYPE_MANAGER_PROXY);
/* virtual methods */ /* virtual methods */
object_class->constructor = constructor; object_class->constructor = constructor;

View File

@@ -21,59 +21,100 @@
#include <string.h> #include <string.h>
#include <config.h> #include <config.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-dbus-helpers.h" #include "nm-dbus-helpers.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
static dbus_int32_t priv_slot = -1; #define NM_DBUS_PRIVATE_CONNECTION_TAG "libnm-private-connection"
static DBusBusType nm_bus = DBUS_BUS_SYSTEM; static GBusType nm_bus = G_BUS_TYPE_SYSTEM;
static void GBusType
_ensure_nm_dbus_helpers_inited (void) _nm_dbus_bus_type (void)
{ {
static gsize init_value = 0; static gsize init_value = 0;
if (g_once_init_enter (&init_value)) { if (g_once_init_enter (&init_value)) {
dbus_connection_allocate_data_slot (&priv_slot);
g_assert (priv_slot != -1);
if (g_getenv ("LIBNM_USE_SESSION_BUS")) if (g_getenv ("LIBNM_USE_SESSION_BUS"))
nm_bus = DBUS_BUS_SESSION; nm_bus = G_BUS_TYPE_SESSION;
g_once_init_leave (&init_value, 1); g_once_init_leave (&init_value, 1);
} }
return nm_bus;
} }
DBusGConnection * GDBusConnection *
_nm_dbus_new_connection (GCancellable *cancellable, _nm_dbus_new_connection (GCancellable *cancellable, GError **error)
GError **error)
{ {
DBusGConnection *connection = NULL; GDBusConnection *connection = NULL;
_ensure_nm_dbus_helpers_inited ();
#if HAVE_DBUS_GLIB_100
/* If running as root try the private bus first */ /* If running as root try the private bus first */
if (0 == geteuid () && nm_bus == DBUS_BUS_SYSTEM) { if (0 == geteuid ()) {
connection = dbus_g_connection_open ("unix:path=" NMRUNDIR "/private", error); GError *local = NULL;
if (connection) {
DBusConnection *dbus_connection = dbus_g_connection_get_connection (connection);
connection = g_dbus_connection_new_for_address_sync ("unix:path=" NMRUNDIR "/private",
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL, cancellable, &local);
if (connection) {
/* Mark this connection as private */ /* Mark this connection as private */
dbus_connection_set_data (dbus_connection, priv_slot, GUINT_TO_POINTER (TRUE), NULL); g_object_set_data (G_OBJECT (connection),
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); NM_DBUS_PRIVATE_CONNECTION_TAG,
GUINT_TO_POINTER (TRUE));
return connection; return connection;
} }
/* Fall back to a bus if for some reason private socket isn't available */
g_clear_error (error); if (g_error_matches (local, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_propagate_error (error, local);
return NULL;
}
g_error_free (local);
} }
#endif
if (connection == NULL) return g_bus_get_sync (_nm_dbus_bus_type (), cancellable, error);
connection = dbus_g_bus_get (nm_bus, error); }
return connection; static void
new_connection_async_got_system (GObject *source, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GDBusConnection *connection;
GError *error = NULL;
connection = g_bus_get_finish (result, &error);
if (connection)
g_simple_async_result_set_op_res_gpointer (simple, connection, g_object_unref);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
static void
new_connection_async_got_private (GObject *source, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GDBusConnection *connection;
GError *error = NULL;
connection = g_dbus_connection_new_for_address_finish (result, &error);
if (connection) {
g_simple_async_result_set_op_res_gpointer (simple, connection, g_object_unref);
g_simple_async_result_complete (simple);
g_object_unref (simple);
return;
}
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
return;
}
g_clear_error (&error);
g_bus_get (_nm_dbus_bus_type (),
g_object_get_data (G_OBJECT (simple), "cancellable"),
new_connection_async_got_system, simple);
} }
void void
@@ -82,22 +123,26 @@ _nm_dbus_new_connection_async (GCancellable *cancellable,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple; GSimpleAsyncResult *simple;
DBusGConnection *connection;
GError *error = NULL;
simple = g_simple_async_result_new (NULL, callback, user_data, simple = g_simple_async_result_new (NULL, callback, user_data, _nm_dbus_new_connection_async);
_nm_dbus_new_connection_async);
connection = _nm_dbus_new_connection (cancellable, &error);
if (connection)
g_simple_async_result_set_op_res_gpointer (simple, connection, (GDestroyNotify) dbus_g_connection_unref);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple); /* If running as root try the private bus first */
g_object_unref (simple); if (0 == geteuid ()) {
g_object_set_data_full (G_OBJECT (simple), "cancellable",
g_object_ref (cancellable), g_object_unref);
g_dbus_connection_new_for_address ("unix:path=" NMRUNDIR "/private",
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL,
cancellable,
new_connection_async_got_private, simple);
} else {
g_bus_get (_nm_dbus_bus_type (),
cancellable,
new_connection_async_got_system, simple);
}
} }
DBusGConnection * GDBusConnection *
_nm_dbus_new_connection_finish (GAsyncResult *result, _nm_dbus_new_connection_finish (GAsyncResult *result,
GError **error) GError **error)
{ {
@@ -106,68 +151,195 @@ _nm_dbus_new_connection_finish (GAsyncResult *result,
if (g_simple_async_result_propagate_error (simple, error)) if (g_simple_async_result_propagate_error (simple, error))
return NULL; return NULL;
return dbus_g_connection_ref (g_simple_async_result_get_op_res_gpointer (simple)); return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
} }
gboolean gboolean
_nm_dbus_is_connection_private (DBusGConnection *connection) _nm_dbus_is_connection_private (GDBusConnection *connection)
{ {
if (priv_slot == -1) return !!g_object_get_data (G_OBJECT (connection), NM_DBUS_PRIVATE_CONNECTION_TAG);
return FALSE;
return !!dbus_connection_get_data (dbus_g_connection_get_connection (connection), priv_slot);
} }
DBusGProxy * static GHashTable *proxy_types;
_nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
#undef _nm_dbus_register_proxy_type
void
_nm_dbus_register_proxy_type (const char *interface,
GType proxy_type)
{
if (!proxy_types)
proxy_types = g_hash_table_new (g_str_hash, g_str_equal);
g_assert (g_hash_table_lookup (proxy_types, interface) == NULL);
g_hash_table_insert (proxy_types, (char *) interface, GSIZE_TO_POINTER (proxy_type));
}
/* We don't (currently) use GDBus's property-handling code */
#define NM_DBUS_PROXY_FLAGS (G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | \
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
GDBusProxy *
_nm_dbus_new_proxy_for_connection (GDBusConnection *connection,
const char *path, const char *path,
const char *interface, const char *interface,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
/* Private connections can't use dbus_g_proxy_new_for_name() or GType proxy_type;
* dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't const char *name;
* have either a bus daemon or name owners, both of which those functions
* require.
*/
if (_nm_dbus_is_connection_private (connection))
return dbus_g_proxy_new_for_peer (connection, path, interface);
return dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, interface); proxy_type = GPOINTER_TO_SIZE (g_hash_table_lookup (proxy_types, interface));
if (!proxy_type)
proxy_type = G_TYPE_DBUS_PROXY;
if (_nm_dbus_is_connection_private (connection))
name = NULL;
else
name = NM_DBUS_SERVICE;
return g_initable_new (proxy_type, cancellable, error,
"g-connection", connection,
"g-flags", NM_DBUS_PROXY_FLAGS,
"g-name", name,
"g-object-path", path,
"g-interface-name", interface,
NULL);
} }
void void
_nm_dbus_new_proxy_for_connection_async (DBusGConnection *connection, _nm_dbus_new_proxy_for_connection_async (GDBusConnection *connection,
const char *path, const char *path,
const char *interface, const char *interface,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple; GType proxy_type;
DBusGProxy *proxy; const char *name;
GError *error = NULL;
simple = g_simple_async_result_new (NULL, callback, user_data, proxy_type = GPOINTER_TO_SIZE (g_hash_table_lookup (proxy_types, interface));
_nm_dbus_new_proxy_for_connection_async); if (!proxy_type)
proxy = _nm_dbus_new_proxy_for_connection (connection, path, interface, proxy_type = G_TYPE_DBUS_PROXY;
cancellable, &error);
if (proxy) if (_nm_dbus_is_connection_private (connection))
g_simple_async_result_set_op_res_gpointer (simple, proxy, g_object_unref); name = NULL;
else else
g_simple_async_result_take_error (simple, error); name = NM_DBUS_SERVICE;
g_simple_async_result_complete_in_idle (simple); g_async_initable_new_async (proxy_type, G_PRIORITY_DEFAULT,
g_object_unref (simple); cancellable, callback, user_data,
"g-connection", connection,
"g-flags", NM_DBUS_PROXY_FLAGS,
"g-name", name,
"g-object-path", path,
"g-interface-name", interface,
NULL);
} }
DBusGProxy * GDBusProxy *
_nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result, _nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result,
GError **error) GError **error)
{ {
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); GObject *source, *proxy;
if (g_simple_async_result_propagate_error (simple, error)) source = g_async_result_get_source_object (result);
return NULL; proxy = g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, error);
g_object_unref (source);
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple)); return G_DBUS_PROXY (proxy);
}
void
_nm_dbus_register_error_domain (GQuark domain,
const char *interface,
GType enum_type)
{
GEnumClass *enum_class;
GEnumValue *e;
char *error_name;
int i;
enum_class = g_type_class_ref (enum_type);
for (i = 0; i < enum_class->n_values; i++) {
e = &enum_class->values[i];
error_name = g_strdup_printf ("%s.%s", interface, e->value_nick);
g_dbus_error_register_error (domain, e->value, error_name);
g_free (error_name);
}
g_type_class_unref (enum_class);
}
/* Binds the properties on a generated server-side GDBus object to the
* corresponding properties on the public object.
*/
void
_nm_dbus_bind_properties (gpointer object, gpointer skeleton)
{
GParamSpec **properties;
guint n_properties;
int i;
properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (skeleton), &n_properties);
for (i = 0; i < n_properties; i++) {
if (g_str_has_prefix (properties[i]->name, "g-"))
continue;
g_object_bind_property (object, properties[i]->name,
skeleton, properties[i]->name,
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
}
}
static char *
signal_name_from_method_name (const char *method_name)
{
GString *signal_name;
const char *p;
signal_name = g_string_new ("handle");
for (p = method_name; *p; p++) {
if (g_ascii_isupper (*p))
g_string_append_c (signal_name, '-');
g_string_append_c (signal_name, g_ascii_tolower (*p));
}
return g_string_free (signal_name, FALSE);
}
static void
_nm_dbus_method_meta_marshal (GClosure *closure, GValue *return_value,
guint n_param_values, const GValue *param_values,
gpointer invocation_hint, gpointer marshal_data)
{
closure->marshal (closure, return_value, n_param_values,
param_values, invocation_hint,
((GCClosure *)closure)->callback);
g_value_set_boolean (return_value, TRUE);
}
/* Takes (method_name, handler_func) pairs and connects the handlers to the
* signals on skeleton, with object as the user_data, but swapped so it comes
* first in the argument list, and handling the return value automatically.
*/
void
_nm_dbus_bind_methods (gpointer object, gpointer skeleton, ...)
{
va_list ap;
const char *method_name;
char *signal_name;
GCallback handler;
GClosure *closure;
va_start (ap, skeleton);
while ( (method_name = va_arg (ap, const char *))
&& (handler = va_arg (ap, GCallback))) {
signal_name = signal_name_from_method_name (method_name);
closure = g_cclosure_new_swap (handler, object, NULL);
g_closure_set_meta_marshal (closure, NULL, _nm_dbus_method_meta_marshal);
g_signal_connect_closure (skeleton, signal_name, closure, FALSE);
g_free (signal_name);
}
va_end (ap);
} }

View File

@@ -22,36 +22,61 @@
#define __NM_DBUS_HELPERS_PRIVATE_H__ #define __NM_DBUS_HELPERS_PRIVATE_H__
#include <gio/gio.h> #include <gio/gio.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
DBusGConnection *_nm_dbus_new_connection (GCancellable *cancellable, /* Copied from dbus/dbus-shared.h */
#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
#define DBUS_PATH_LOCAL "/org/freedesktop/DBus/Local"
#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
#define DBUS_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable"
#define DBUS_INTERFACE_PROPERTIES "org.freedesktop.DBus.Properties"
#define DBUS_INTERFACE_PEER "org.freedesktop.DBus.Peer"
GBusType _nm_dbus_bus_type (void);
GDBusConnection *_nm_dbus_new_connection (GCancellable *cancellable,
GError **error); GError **error);
void _nm_dbus_new_connection_async (GCancellable *cancellable, void _nm_dbus_new_connection_async (GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
DBusGConnection *_nm_dbus_new_connection_finish (GAsyncResult *result, GDBusConnection *_nm_dbus_new_connection_finish (GAsyncResult *result,
GError **error); GError **error);
gboolean _nm_dbus_is_connection_private (DBusGConnection *connection); gboolean _nm_dbus_is_connection_private (GDBusConnection *connection);
void _nm_dbus_register_proxy_type (const char *interface, void _nm_dbus_register_proxy_type (const char *interface,
GType proxy_type); GType proxy_type);
/* Guarantee that @interface is a static string */
#define _nm_dbus_register_proxy_type(interface, proxy_type) \
_nm_dbus_register_proxy_type (interface "", proxy_type) \
DBusGProxy *_nm_dbus_new_proxy_for_connection (DBusGConnection *connection, GDBusProxy *_nm_dbus_new_proxy_for_connection (GDBusConnection *connection,
const char *path, const char *path,
const char *interface, const char *interface,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
void _nm_dbus_new_proxy_for_connection_async (DBusGConnection *connection, void _nm_dbus_new_proxy_for_connection_async (GDBusConnection *connection,
const char *path, const char *path,
const char *interface, const char *interface,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
DBusGProxy *_nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result, GDBusProxy *_nm_dbus_new_proxy_for_connection_finish (GAsyncResult *result,
GError **error); GError **error);
void _nm_dbus_register_error_domain (GQuark domain,
const char *interface,
GType enum_type);
void _nm_dbus_bind_properties (gpointer object,
gpointer skeleton);
void _nm_dbus_bind_methods (gpointer object,
gpointer skeleton,
...) G_GNUC_NULL_TERMINATED;
#endif /* __NM_DBUS_HELPERS_PRIVATE_H__ */ #endif /* __NM_DBUS_HELPERS_PRIVATE_H__ */

View File

@@ -33,8 +33,10 @@
#include "nm-device-private.h" #include "nm-device-private.h"
#include "nm-object-private.h" #include "nm-object-private.h"
#include "nm-object-cache.h" #include "nm-object-cache.h"
#include "nm-dbus-glib-types.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-dbus-helpers.h"
#include "nmdbus-device-wifi.h"
G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE) G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
@@ -45,12 +47,13 @@ static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user
typedef struct { typedef struct {
NMDeviceWifi *device; NMDeviceWifi *device;
GCancellable *cancellable;
NMDeviceWifiRequestScanFn callback; NMDeviceWifiRequestScanFn callback;
gpointer user_data; gpointer user_data;
} RequestScanInfo; } RequestScanInfo;
typedef struct { typedef struct {
DBusGProxy *proxy; NMDBusDeviceWifi *proxy;
char *hw_address; char *hw_address;
char *perm_hw_address; char *perm_hw_address;
@@ -60,7 +63,6 @@ typedef struct {
NMDeviceWifiCapabilities wireless_caps; NMDeviceWifiCapabilities wireless_caps;
GPtrArray *aps; GPtrArray *aps;
DBusGProxyCall *scan_call;
RequestScanInfo *scan_info; RequestScanInfo *scan_info;
} NMDeviceWifiPrivate; } NMDeviceWifiPrivate;
@@ -286,24 +288,27 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,
} }
static void static void
request_scan_cb (DBusGProxy *proxy, request_scan_cb (GObject *source,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
RequestScanInfo *info = user_data; RequestScanInfo *info = user_data;
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device);
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); if (info->callback) {
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device);
GError *error = NULL;
nmdbus_device_wifi_call_request_scan_finish (NMDBUS_DEVICE_WIFI (source),
result, &error);
if (info->callback)
info->callback (info->device, error, info->user_data); info->callback (info->device, error, info->user_data);
g_clear_error (&error); g_clear_error (&error);
g_slice_free (RequestScanInfo, info); priv->scan_info = NULL;
}
priv->scan_call = NULL; g_clear_object (&info->cancellable);
priv->scan_info = NULL; g_slice_free (RequestScanInfo, info);
} }
/** /**
@@ -322,29 +327,25 @@ nm_device_wifi_request_scan_simple (NMDeviceWifi *device,
gpointer user_data) gpointer user_data)
{ {
RequestScanInfo *info; RequestScanInfo *info;
GHashTable *options;
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
g_return_if_fail (NM_IS_DEVICE_WIFI (device)); g_return_if_fail (NM_IS_DEVICE_WIFI (device));
/* If a scan is in progress, just return */ /* If a scan is in progress, just return */
if (priv->scan_call) if (priv->scan_info)
return; return;
options = g_hash_table_new (g_str_hash, g_str_equal);
info = g_slice_new0 (RequestScanInfo); info = g_slice_new0 (RequestScanInfo);
info->device = device; info->device = device;
info->cancellable = g_cancellable_new ();
info->callback = callback; info->callback = callback;
info->user_data = user_data; info->user_data = user_data;
priv->scan_info = info; priv->scan_info = info;
priv->scan_call = dbus_g_proxy_begin_call (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, "RequestScan", nmdbus_device_wifi_call_request_scan (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
request_scan_cb, info, NULL, g_variant_new_array (G_VARIANT_TYPE_VARDICT, NULL, 0),
DBUS_TYPE_G_MAP_OF_VARIANT, options, info->cancellable,
G_TYPE_INVALID); request_scan_cb, info);
g_hash_table_unref (options);
} }
static void static void
@@ -594,7 +595,7 @@ init_dbus (NMObject *object)
NM_OBJECT_CLASS (nm_device_wifi_parent_class)->init_dbus (object); NM_OBJECT_CLASS (nm_device_wifi_parent_class)->init_dbus (object);
priv->proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE_WIRELESS); priv->proxy = NMDBUS_DEVICE_WIFI (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE_WIRELESS));
_nm_object_register_properties (object, _nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_WIRELESS, NM_DBUS_INTERFACE_DEVICE_WIRELESS,
property_info); property_info);
@@ -621,19 +622,22 @@ dispose (GObject *object)
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
GError *error = NULL; GError *error = NULL;
if (priv->scan_call) { if (priv->scan_info) {
g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN, RequestScanInfo *scan_info;
"Wi-Fi device was destroyed");
if (priv->scan_info) {
if (priv->scan_info->callback)
priv->scan_info->callback (NULL, error, priv->scan_info->user_data);
g_slice_free (RequestScanInfo, priv->scan_info);
priv->scan_info = NULL;
}
g_clear_error (&error);
dbus_g_proxy_cancel_call (priv->proxy, priv->scan_call); scan_info = priv->scan_info;
priv->scan_call = NULL; priv->scan_info = NULL;
if (scan_info->callback) {
g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN,
"Wi-Fi device was destroyed");
scan_info->callback (NULL, error, scan_info->user_data);
scan_info->callback = NULL;
g_clear_error (&error);
}
g_cancellable_cancel (scan_info->cancellable);
/* request_scan_cb() will free scan_info */
} }
if (priv->aps) if (priv->aps)
@@ -663,6 +667,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
g_type_class_add_private (wifi_class, sizeof (NMDeviceWifiPrivate)); g_type_class_add_private (wifi_class, sizeof (NMDeviceWifiPrivate));
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_WIRELESS); _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_WIRELESS);
_nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_DEVICE_WIRELESS,
NMDBUS_TYPE_DEVICE_WIFI_PROXY);
/* virtual methods */ /* virtual methods */
object_class->get_property = get_property; object_class->get_property = get_property;

View File

@@ -31,7 +31,6 @@
#include "nm-device-wimax.h" #include "nm-device-wimax.h"
#include "nm-object-private.h" #include "nm-object-private.h"
#include "nm-object-cache.h" #include "nm-object-cache.h"
#include "nm-dbus-glib-types.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-device-private.h" #include "nm-device-private.h"

View File

@@ -44,12 +44,13 @@
#include "nm-object-cache.h" #include "nm-object-cache.h"
#include "nm-remote-connection.h" #include "nm-remote-connection.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dbus-helpers.h" #include "nm-dbus-helpers.h"
static GType _nm_device_decide_type (GValue *value); #include "nmdbus-device.h"
static GType _nm_device_decide_type (GVariant *value);
gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error); gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error);
G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT,
@@ -62,7 +63,7 @@ G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT,
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) #define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))
typedef struct { typedef struct {
DBusGProxy *proxy; NMDBusDevice *proxy;
char *iface; char *iface;
char *ip_iface; char *ip_iface;
@@ -159,29 +160,21 @@ nm_device_init (NMDevice *device)
priv->reason = NM_DEVICE_STATE_REASON_NONE; priv->reason = NM_DEVICE_STATE_REASON_NONE;
} }
#define DBUS_G_TYPE_UINT_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID))
static gboolean static gboolean
demarshal_state_reason (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_state_reason (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
guint32 *reason_field = field; guint32 *reason_field = field;
if (!G_VALUE_HOLDS (value, DBUS_G_TYPE_UINT_STRUCT)) g_variant_get (value, "(uu)", NULL, reason_field);
return FALSE;
dbus_g_type_struct_get (value,
1, reason_field,
G_MAXUINT);
_nm_object_queue_notify (object, NM_DEVICE_STATE_REASON); _nm_object_queue_notify (object, NM_DEVICE_STATE_REASON);
return TRUE; return TRUE;
} }
static void static void
device_state_changed (DBusGProxy *proxy, device_state_changed (NMDBusDevice *proxy,
NMDeviceState new_state, guint new_state,
NMDeviceState old_state, guint old_state,
NMDeviceStateReason reason, guint reason,
gpointer user_data); gpointer user_data);
static void static void
@@ -219,26 +212,13 @@ init_dbus (NMObject *object)
NM_OBJECT_CLASS (nm_device_parent_class)->init_dbus (object); NM_OBJECT_CLASS (nm_device_parent_class)->init_dbus (object);
priv->proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE); priv->proxy = NMDBUS_DEVICE (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE));
_nm_object_register_properties (object, _nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE, NM_DBUS_INTERFACE_DEVICE,
property_info); property_info);
dbus_g_object_register_marshaller (g_cclosure_marshal_generic, g_signal_connect (priv->proxy, "state-changed",
G_TYPE_NONE, G_CALLBACK (device_state_changed), object);
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->proxy,
"StateChanged",
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->proxy, "StateChanged",
G_CALLBACK (device_state_changed),
NM_DEVICE (object),
NULL);
} }
typedef struct { typedef struct {
@@ -281,33 +261,33 @@ device_state_change_reloaded (GObject *object,
} }
static void static void
device_state_changed (DBusGProxy *proxy, device_state_changed (NMDBusDevice *proxy,
NMDeviceState new_state, guint new_state,
NMDeviceState old_state, guint old_state,
NMDeviceStateReason reason, guint reason,
gpointer user_data) gpointer user_data)
{ {
NMDevice *self = NM_DEVICE (user_data); NMDevice *self = NM_DEVICE (user_data);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
StateChangeData *data;
if (old_state != new_state) { if (old_state == new_state)
StateChangeData *data; return;
/* Our object-valued properties (eg, ip4_config) will still /* Our object-valued properties (eg, ip4_config) will still
* have their old values at this point, because NMObject is * have their old values at this point, because NMObject is
* in the process of asynchronously reading the new values. * in the process of asynchronously reading the new values.
* Wait for that to finish before emitting the signal. * Wait for that to finish before emitting the signal.
*/ */
priv->last_seen_state = new_state; priv->last_seen_state = new_state;
data = g_slice_new (StateChangeData); data = g_slice_new (StateChangeData);
data->old_state = old_state; data->old_state = old_state;
data->new_state = new_state; data->new_state = new_state;
data->reason = reason; data->reason = reason;
_nm_object_reload_properties_async (NM_OBJECT (user_data), _nm_object_reload_properties_async (NM_OBJECT (user_data),
device_state_change_reloaded, device_state_change_reloaded,
data); data);
}
} }
static GType static GType
@@ -518,6 +498,7 @@ nm_device_class_init (NMDeviceClass *device_class)
g_type_class_add_private (device_class, sizeof (NMDevicePrivate)); g_type_class_add_private (device_class, sizeof (NMDevicePrivate));
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE); _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE);
_nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_DEVICE, NMDBUS_TYPE_DEVICE_PROXY);
/* virtual methods */ /* virtual methods */
object_class->constructed = constructed; object_class->constructed = constructed;
@@ -862,9 +843,9 @@ _nm_device_set_device_type (NMDevice *device, NMDeviceType dtype)
} }
static GType static GType
_nm_device_decide_type (GValue *value) _nm_device_decide_type (GVariant *value)
{ {
return _nm_device_gtype_from_dtype (g_value_get_uint (value)); return _nm_device_gtype_from_dtype (g_variant_get_uint32 (value));
} }
/** /**
@@ -1100,20 +1081,14 @@ nm_device_get_autoconnect (NMDevice *device)
void void
nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect) nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect)
{ {
GValue value = G_VALUE_INIT;
g_return_if_fail (NM_IS_DEVICE (device)); g_return_if_fail (NM_IS_DEVICE (device));
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, autoconnect);
NM_DEVICE_GET_PRIVATE (device)->autoconnect = autoconnect; NM_DEVICE_GET_PRIVATE (device)->autoconnect = autoconnect;
_nm_object_set_property (NM_OBJECT (device), _nm_object_set_property (NM_OBJECT (device),
NM_DBUS_INTERFACE_DEVICE, NM_DBUS_INTERFACE_DEVICE,
"Autoconnect", "Autoconnect",
&value); "b", autoconnect);
} }
/** /**
@@ -1921,28 +1896,24 @@ typedef struct {
NMDevice *device; NMDevice *device;
NMDeviceCallbackFn fn; NMDeviceCallbackFn fn;
gpointer user_data; gpointer user_data;
const char *method;
} DeviceCallbackInfo; } DeviceCallbackInfo;
static void static void
device_operation_cb (DBusGProxy *proxy, device_disconnect_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
DeviceCallbackInfo *info = user_data; DeviceCallbackInfo *info = user_data;
GError *error = NULL; GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, nmdbus_device_call_disconnect_finish (NMDBUS_DEVICE (proxy), result, &error);
G_TYPE_INVALID);
if (info->fn) if (info->fn)
info->fn (info->device, error, info->user_data); info->fn (info->device, error, info->user_data);
else if (error) { else if (error) {
g_warning ("%s: device %s %s failed: (%d) %s", g_warning ("%s: device %s disconnect failed: %s",
__func__, __func__,
nm_object_get_path (NM_OBJECT (info->device)), nm_object_get_path (NM_OBJECT (info->device)),
info->method, error->message);
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
} }
g_clear_error (&error); g_clear_error (&error);
@@ -1973,12 +1944,34 @@ nm_device_disconnect (NMDevice *device,
info = g_slice_new (DeviceCallbackInfo); info = g_slice_new (DeviceCallbackInfo);
info->fn = callback; info->fn = callback;
info->user_data = user_data; info->user_data = user_data;
info->method = "Disconnect";
info->device = g_object_ref (device); info->device = g_object_ref (device);
dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Disconnect", nmdbus_device_call_disconnect (NM_DEVICE_GET_PRIVATE (device)->proxy,
device_operation_cb, info, NULL, NULL,
G_TYPE_INVALID); device_disconnect_cb, info);
}
static void
device_delete_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
DeviceCallbackInfo *info = user_data;
GError *error = NULL;
nmdbus_device_call_delete_finish (NMDBUS_DEVICE (proxy), result, &error);
if (info->fn)
info->fn (info->device, error, info->user_data);
else if (error) {
g_warning ("%s: device %s delete failed: %s",
__func__,
nm_object_get_path (NM_OBJECT (info->device)),
error->message);
}
g_clear_error (&error);
g_object_unref (info->device);
g_slice_free (DeviceCallbackInfo, info);
} }
/** /**
@@ -2002,12 +1995,11 @@ nm_device_delete (NMDevice *device,
info = g_slice_new (DeviceCallbackInfo); info = g_slice_new (DeviceCallbackInfo);
info->fn = callback; info->fn = callback;
info->user_data = user_data; info->user_data = user_data;
info->method = "Delete";
info->device = g_object_ref (device); info->device = g_object_ref (device);
dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Delete", nmdbus_device_call_delete (NM_DEVICE_GET_PRIVATE (device)->proxy,
device_operation_cb, info, NULL, NULL,
G_TYPE_INVALID); device_delete_cb, info);
} }
/** /**

View File

@@ -50,21 +50,19 @@ nm_dhcp4_config_init (NMDhcp4Config *config)
} }
static gboolean static gboolean
demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
GHashTable *new_options; GVariantIter iter;
GHashTableIter iter;
const char *key; const char *key;
GValue *opt; GVariant *opt;
g_hash_table_remove_all (priv->options); g_hash_table_remove_all (priv->options);
new_options = g_value_get_boxed (value); g_variant_iter_init (&iter, value);
if (new_options) { while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
g_hash_table_iter_init (&iter, new_options); g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt)) g_variant_unref (opt);
g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
} }
_nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS); _nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS);

View File

@@ -50,21 +50,19 @@ nm_dhcp6_config_init (NMDhcp6Config *config)
} }
static gboolean static gboolean
demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
GHashTable *new_options; GVariantIter iter;
GHashTableIter iter;
const char *key; const char *key;
GValue *opt; GVariant *opt;
g_hash_table_remove_all (priv->options); g_hash_table_remove_all (priv->options);
new_options = g_value_get_boxed (value); g_variant_iter_init (&iter, value);
if (new_options) { while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
g_hash_table_iter_init (&iter, new_options); g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt)) g_variant_unref (opt);
g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
} }
_nm_object_queue_notify (object, NM_DHCP6_CONFIG_OPTIONS); _nm_object_queue_notify (object, NM_DHCP6_CONFIG_OPTIONS);

View File

@@ -34,8 +34,8 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_OBJECT)
typedef struct { typedef struct {
char *gateway; char *gateway;
GSList *addresses; GPtrArray *addresses;
GSList *routes; GPtrArray *routes;
char **nameservers; char **nameservers;
char **domains; char **domains;
char **searches; char **searches;
@@ -60,6 +60,8 @@ nm_ip4_config_init (NMIP4Config *config)
{ {
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
priv->addresses = g_ptr_array_new ();
priv->routes = g_ptr_array_new ();
priv->nameservers = g_new0 (char *, 1); priv->nameservers = g_new0 (char *, 1);
priv->domains = g_new0 (char *, 1); priv->domains = g_new0 (char *, 1);
priv->searches = g_new0 (char *, 1); priv->searches = g_new0 (char *, 1);
@@ -67,58 +69,39 @@ nm_ip4_config_init (NMIP4Config *config)
} }
static gboolean static gboolean
demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref); g_ptr_array_unref (priv->addresses);
priv->addresses = NULL; priv->addresses = nm_utils_ip4_addresses_from_variant (value);
priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
_nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES); _nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES);
return TRUE; return TRUE;
} }
static gboolean static gboolean
demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
GArray *ip_array;
char ***obj_field; char ***obj_field;
int i;
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY))
return FALSE;
ip_array = g_value_get_boxed (value);
obj_field = field; obj_field = field;
if (*obj_field) if (*obj_field)
g_strfreev (*obj_field); g_strfreev (*obj_field);
*obj_field = g_new (char *, ip_array->len + 1); *obj_field = nm_utils_ip4_dns_from_variant (value);
for (i = 0; i < ip_array->len; i++) {
guint32 ip = g_array_index (ip_array, guint32, i);
const char *str;
str = nm_utils_inet4_ntop (ip, NULL);
(*obj_field)[i] = g_strdup (str);
}
(*obj_field)[i] = NULL;
_nm_object_queue_notify (object, pspec->name); _nm_object_queue_notify (object, pspec->name);
return TRUE; return TRUE;
} }
static gboolean static gboolean
demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref); g_ptr_array_unref (priv->routes);
priv->routes = NULL; priv->routes = nm_utils_ip4_routes_from_variant (value);
priv->routes = nm_utils_ip4_routes_from_gvalue (value);
_nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES); _nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES);
return TRUE; return TRUE;
@@ -153,8 +136,8 @@ finalize (GObject *object)
g_free (priv->gateway); g_free (priv->gateway);
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref); g_ptr_array_unref (priv->addresses);
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref); g_ptr_array_unref (priv->routes);
g_strfreev (priv->nameservers); g_strfreev (priv->nameservers);
g_strfreev (priv->domains); g_strfreev (priv->domains);
@@ -171,21 +154,20 @@ get_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
NMIP4Config *self = NM_IP4_CONFIG (object); NMIP4Config *self = NM_IP4_CONFIG (object);
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
switch (prop_id) { switch (prop_id) {
case PROP_GATEWAY: case PROP_GATEWAY:
g_value_set_string (value, nm_ip4_config_get_gateway (self)); g_value_set_string (value, nm_ip4_config_get_gateway (self));
break; break;
case PROP_ADDRESSES: case PROP_ADDRESSES:
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, g_value_take_boxed (value, _nm_utils_copy_array (nm_ip4_config_get_addresses (self),
(NMUtilsCopyFunc) nm_ip4_address_dup, (NMUtilsCopyFunc) nm_ip4_address_dup,
(GDestroyNotify) nm_ip4_address_unref)); (GDestroyNotify) nm_ip4_address_unref));
break; break;
case PROP_ROUTES: case PROP_ROUTES:
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, g_value_take_boxed (value, _nm_utils_copy_array (nm_ip4_config_get_routes (self),
(NMUtilsCopyFunc) nm_ip4_route_dup, (NMUtilsCopyFunc) nm_ip4_route_dup,
(GDestroyNotify) nm_ip4_route_unref)); (GDestroyNotify) nm_ip4_route_unref));
break; break;
case PROP_NAMESERVERS: case PROP_NAMESERVERS:
g_value_set_boxed (value, (char **) nm_ip4_config_get_nameservers (self)); g_value_set_boxed (value, (char **) nm_ip4_config_get_nameservers (self));
@@ -330,10 +312,11 @@ nm_ip4_config_get_gateway (NMIP4Config *config)
* *
* Gets the IP4 addresses (containing the address, prefix, and gateway). * Gets the IP4 addresses (containing the address, prefix, and gateway).
* *
* Returns: (element-type NMIP4Address) (transfer none): the #GSList containing #NMIP4Address<!-- -->es. * Returns: (element-type NMIP4Address) (transfer none): the #GPtrArray
* This is the internal copy used by the configuration and must not be modified. * containing #NMIP4Address<!-- -->es. This is the internal copy used by the
* configuration and must not be modified.
**/ **/
const GSList * GPtrArray *
nm_ip4_config_get_addresses (NMIP4Config *config) nm_ip4_config_get_addresses (NMIP4Config *config)
{ {
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
@@ -415,11 +398,11 @@ nm_ip4_config_get_wins_servers (NMIP4Config *config)
* *
* Gets the routes. * Gets the routes.
* *
* Returns: (element-type NMIP4Route) (transfer none): the #GSList containing * Returns: (element-type NMIP4Route) (transfer none): the #GPtrArray containing
* #NMIP4Routes. This is the internal copy used by the configuration, * #NMIP4Routes. This is the internal copy used by the configuration, and must
* and must not be modified. * not be modified.
**/ **/
const GSList * GPtrArray *
nm_ip4_config_get_routes (NMIP4Config *config) nm_ip4_config_get_routes (NMIP4Config *config)
{ {
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);

View File

@@ -61,8 +61,8 @@ typedef struct {
GType nm_ip4_config_get_type (void); GType nm_ip4_config_get_type (void);
const char * nm_ip4_config_get_gateway (NMIP4Config *config); const char * nm_ip4_config_get_gateway (NMIP4Config *config);
const GSList * nm_ip4_config_get_addresses (NMIP4Config *config); GPtrArray * nm_ip4_config_get_addresses (NMIP4Config *config);
const GSList * nm_ip4_config_get_routes (NMIP4Config *config); GPtrArray * nm_ip4_config_get_routes (NMIP4Config *config);
const char * const *nm_ip4_config_get_nameservers (NMIP4Config *config); const char * const *nm_ip4_config_get_nameservers (NMIP4Config *config);
const char * const *nm_ip4_config_get_domains (NMIP4Config *config); const char * const *nm_ip4_config_get_domains (NMIP4Config *config);
const char * const *nm_ip4_config_get_searches (NMIP4Config *config); const char * const *nm_ip4_config_get_searches (NMIP4Config *config);

View File

@@ -26,7 +26,6 @@
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
#include "nm-object-private.h" #include "nm-object-private.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT) G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT)
@@ -35,8 +34,8 @@ G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT)
typedef struct { typedef struct {
char *gateway; char *gateway;
GSList *addresses; GPtrArray *addresses;
GSList *routes; GPtrArray *routes;
char **nameservers; char **nameservers;
char **domains; char **domains;
char **searches; char **searches;
@@ -55,58 +54,39 @@ enum {
}; };
static gboolean static gboolean
demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object); NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref); g_ptr_array_unref (priv->addresses);
priv->addresses = NULL; priv->addresses = nm_utils_ip6_addresses_from_variant (value);
priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
_nm_object_queue_notify (object, NM_IP6_CONFIG_ADDRESSES); _nm_object_queue_notify (object, NM_IP6_CONFIG_ADDRESSES);
return TRUE; return TRUE;
} }
static gboolean static gboolean
demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
GPtrArray *ip_array;
char ***obj_field; char ***obj_field;
int i;
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR))
return FALSE;
ip_array = g_value_get_boxed (value);
obj_field = field; obj_field = field;
if (*obj_field) if (*obj_field)
g_strfreev (*obj_field); g_strfreev (*obj_field);
*obj_field = g_new (char *, ip_array ? ip_array->len + 1 : 1); *obj_field = nm_utils_ip6_dns_from_variant (value);
for (i = 0; ip_array && i < ip_array->len; i++) {
GByteArray *ip = g_ptr_array_index (ip_array, i);
const char *str;
str = nm_utils_inet6_ntop ((struct in6_addr *) ip->data, NULL);
(*obj_field)[i] = g_strdup (str);
}
(*obj_field)[i] = NULL;
_nm_object_queue_notify (object, pspec->name); _nm_object_queue_notify (object, pspec->name);
return TRUE; return TRUE;
} }
static gboolean static gboolean
demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{ {
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object); NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref); g_ptr_array_unref (priv->routes);
priv->routes = NULL; priv->routes = nm_utils_ip6_routes_from_variant (value);
priv->routes = nm_utils_ip6_routes_from_gvalue (value);
_nm_object_queue_notify (object, NM_IP6_CONFIG_ROUTES); _nm_object_queue_notify (object, NM_IP6_CONFIG_ROUTES);
return TRUE; return TRUE;
@@ -155,11 +135,11 @@ nm_ip6_config_get_gateway (NMIP6Config *config)
* *
* Gets the IP6 addresses (containing the address, prefix, and gateway). * Gets the IP6 addresses (containing the address, prefix, and gateway).
* *
* Returns: (element-type NMIP6Address) (transfer none): the #GSList containing * Returns: (element-type NMIP6Address) (transfer none): the #GPtrArray
* #NMIP6Address<!-- -->es. This is the internal copy used by the configuration * containing #NMIP6Address<!-- -->es. This is the internal copy used by the
* and must not be modified. * configuration and must not be modified.
**/ **/
const GSList * GPtrArray *
nm_ip6_config_get_addresses (NMIP6Config *config) nm_ip6_config_get_addresses (NMIP6Config *config)
{ {
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
@@ -223,11 +203,11 @@ nm_ip6_config_get_searches (NMIP6Config *config)
* *
* Gets the routes. * Gets the routes.
* *
* Returns: (element-type NMIP6Route): (transfer none): the #GSList containing * Returns: (element-type NMIP6Route) (transfer none): the #GPtrArray containing
* #NMIP6Routes. This is the internal copy used by the configuration, * #NMIP6Routes. This is the internal copy used by the configuration, and must
* and must not be modified. * not be modified.
**/ **/
const GSList * GPtrArray *
nm_ip6_config_get_routes (NMIP6Config *config) nm_ip6_config_get_routes (NMIP6Config *config)
{ {
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
@@ -242,8 +222,8 @@ finalize (GObject *object)
g_free (priv->gateway); g_free (priv->gateway);
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref); g_ptr_array_unref (priv->addresses);
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref); g_ptr_array_unref (priv->routes);
g_strfreev (priv->nameservers); g_strfreev (priv->nameservers);
g_strfreev (priv->domains); g_strfreev (priv->domains);
@@ -259,21 +239,20 @@ get_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
NMIP6Config *self = NM_IP6_CONFIG (object); NMIP6Config *self = NM_IP6_CONFIG (object);
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self);
switch (prop_id) { switch (prop_id) {
case PROP_GATEWAY: case PROP_GATEWAY:
g_value_set_string (value, nm_ip6_config_get_gateway (self)); g_value_set_string (value, nm_ip6_config_get_gateway (self));
break; break;
case PROP_ADDRESSES: case PROP_ADDRESSES:
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses, g_value_take_boxed (value, _nm_utils_copy_array (nm_ip6_config_get_addresses (self),
(NMUtilsCopyFunc) nm_ip6_address_dup, (NMUtilsCopyFunc) nm_ip6_address_dup,
(GDestroyNotify) nm_ip6_address_unref)); (GDestroyNotify) nm_ip6_address_unref));
break; break;
case PROP_ROUTES: case PROP_ROUTES:
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes, g_value_take_boxed (value, _nm_utils_copy_array (nm_ip6_config_get_routes (self),
(NMUtilsCopyFunc) nm_ip6_route_dup, (NMUtilsCopyFunc) nm_ip6_route_dup,
(GDestroyNotify) nm_ip6_route_unref)); (GDestroyNotify) nm_ip6_route_unref));
break; break;
case PROP_NAMESERVERS: case PROP_NAMESERVERS:
g_value_set_boxed (value, (char **) nm_ip6_config_get_nameservers (self)); g_value_set_boxed (value, (char **) nm_ip6_config_get_nameservers (self));
@@ -295,6 +274,8 @@ nm_ip6_config_init (NMIP6Config *config)
{ {
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
priv->addresses = g_ptr_array_new ();
priv->routes = g_ptr_array_new ();
priv->nameservers = g_new0 (char *, 1); priv->nameservers = g_new0 (char *, 1);
priv->domains = g_new0 (char *, 1); priv->domains = g_new0 (char *, 1);
priv->searches = g_new0 (char *, 1); priv->searches = g_new0 (char *, 1);

View File

@@ -60,8 +60,8 @@ typedef struct {
GType nm_ip6_config_get_type (void); GType nm_ip6_config_get_type (void);
const char * nm_ip6_config_get_gateway (NMIP6Config *config); const char * nm_ip6_config_get_gateway (NMIP6Config *config);
const GSList * nm_ip6_config_get_addresses (NMIP6Config *config); GPtrArray * nm_ip6_config_get_addresses (NMIP6Config *config);
const GSList * nm_ip6_config_get_routes (NMIP6Config *config); GPtrArray * nm_ip6_config_get_routes (NMIP6Config *config);
const char * const * nm_ip6_config_get_nameservers (NMIP6Config *config); const char * const * nm_ip6_config_get_nameservers (NMIP6Config *config);
const char * const * nm_ip6_config_get_domains (NMIP6Config *config); const char * const * nm_ip6_config_get_domains (NMIP6Config *config);
const char * const * nm_ip6_config_get_searches (NMIP6Config *config); const char * const * nm_ip6_config_get_searches (NMIP6Config *config);

View File

@@ -24,9 +24,9 @@
#include <gio/gio.h> #include <gio/gio.h>
#include "nm-object.h" #include "nm-object.h"
typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GValue *, gpointer); typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GVariant *, gpointer);
typedef GObject * (*NMObjectCreatorFunc) (DBusGConnection *, const char *); typedef GObject * (*NMObjectCreatorFunc) (GDBusConnection *, const char *);
typedef struct { typedef struct {
const char *name; const char *name;
@@ -62,10 +62,11 @@ void _nm_object_reload_property (NMObject *object,
void _nm_object_set_property (NMObject *object, void _nm_object_set_property (NMObject *object,
const char *interface, const char *interface,
const char *prop_name, const char *prop_name,
GValue *value); const char *format_string,
...);
/* object demarshalling support */ /* object demarshalling support */
typedef GType (*NMObjectDecideTypeFunc) (GValue *); typedef GType (*NMObjectDecideTypeFunc) (GVariant *);
void _nm_object_register_type_func (GType base_type, void _nm_object_register_type_func (GType base_type,
NMObjectDecideTypeFunc type_func, NMObjectDecideTypeFunc type_func,
@@ -77,7 +78,7 @@ gboolean _nm_object_get_nm_running (NMObject *self);
void _nm_object_class_add_interface (NMObjectClass *object_class, void _nm_object_class_add_interface (NMObjectClass *object_class,
const char *interface); const char *interface);
DBusGProxy *_nm_object_get_proxy (NMObject *object, GDBusProxy *_nm_object_get_proxy (NMObject *object,
const char *interface); const char *interface);
#endif /* __NM_OBJECT_PRIVATE_H__ */ #endif /* __NM_OBJECT_PRIVATE_H__ */

View File

@@ -29,7 +29,6 @@
#include "nm-object.h" #include "nm-object.h"
#include "nm-object-cache.h" #include "nm-object-cache.h"
#include "nm-object-private.h" #include "nm-object-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-dbus-helpers.h" #include "nm-dbus-helpers.h"
@@ -72,13 +71,13 @@ typedef struct {
static void reload_complete (NMObject *object); static void reload_complete (NMObject *object);
typedef struct { typedef struct {
DBusGConnection *connection; GDBusConnection *connection;
DBusGProxy *bus_proxy; gboolean private_connection;
gboolean nm_running; gboolean nm_running;
char *path; char *path;
GHashTable *proxies; GHashTable *proxies;
DBusGProxy *properties_proxy; GDBusProxy *properties_proxy;
GSList *property_tables; GSList *property_tables;
NMObject *parent; NMObject *parent;
gboolean suppress_property_updates; gboolean suppress_property_updates;
@@ -125,20 +124,15 @@ nm_object_error_quark (void)
} }
static void static void
proxy_name_owner_changed (DBusGProxy *proxy, on_name_owner_changed (GObject *proxy,
const char *name, GParamSpec *pspec,
const char *old_owner, gpointer user_data)
const char *new_owner,
gpointer user_data)
{ {
NMObject *self = NM_OBJECT (user_data); NMObject *self = NM_OBJECT (user_data);
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
gboolean now_running; gboolean now_running;
if (g_strcmp0 (name, NM_DBUS_SERVICE) != 0) now_running = (g_dbus_proxy_get_name_owner (priv->properties_proxy) != NULL);
return;
now_running = (new_owner && new_owner[0]);
if (now_running != priv->nm_running) { if (now_running != priv->nm_running) {
priv->nm_running = now_running; priv->nm_running = now_running;
g_object_notify (G_OBJECT (self), NM_OBJECT_NM_RUNNING); g_object_notify (G_OBJECT (self), NM_OBJECT_NM_RUNNING);
@@ -161,19 +155,9 @@ init_dbus (NMObject *object)
if (_nm_dbus_is_connection_private (priv->connection)) if (_nm_dbus_is_connection_private (priv->connection))
priv->nm_running = TRUE; priv->nm_running = TRUE;
else { else {
priv->bus_proxy = dbus_g_proxy_new_for_name (priv->connection, priv->nm_running = (g_dbus_proxy_get_name_owner (priv->properties_proxy) != NULL);
DBUS_SERVICE_DBUS, g_signal_connect (priv->properties_proxy, "notify::g-name-owner",
DBUS_PATH_DBUS, G_CALLBACK (on_name_owner_changed), object);
DBUS_INTERFACE_DBUS);
g_assert (priv->bus_proxy);
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->bus_proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
object, NULL);
} }
} }
@@ -198,7 +182,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
/* Create proxies */ /* Create proxies */
for (iter = cpriv->interfaces; iter; iter = iter->next) { for (iter = cpriv->interfaces; iter; iter = iter->next) {
const char *interface = iter->data; const char *interface = iter->data;
DBusGProxy *proxy; GDBusProxy *proxy;
proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, interface, proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, interface,
cancellable, error); cancellable, error);
@@ -216,16 +200,6 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
NM_OBJECT_GET_CLASS (self)->init_dbus (self); NM_OBJECT_GET_CLASS (self)->init_dbus (self);
if (priv->bus_proxy) {
if (!dbus_g_proxy_call (priv->bus_proxy,
"NameHasOwner", error,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->nm_running,
G_TYPE_INVALID))
return FALSE;
}
return _nm_object_reload_properties (self, error); return _nm_object_reload_properties (self, error);
} }
@@ -259,41 +233,18 @@ init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_
init_async_complete (init_data); init_async_complete (init_data);
} }
static void
init_async_get_properties (NMObjectInitData *init_data)
{
_nm_object_reload_properties_async (init_data->object, init_async_got_properties, init_data);
}
static void
init_async_got_nm_running (DBusGProxy *proxy, DBusGProxyCall *call,
gpointer user_data)
{
NMObjectInitData *init_data = user_data;
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (init_data->object);
if (!dbus_g_proxy_end_call (proxy, call, &init_data->error,
G_TYPE_BOOLEAN, &priv->nm_running,
G_TYPE_INVALID)) {
init_async_complete (init_data);
} else if (!priv->nm_running)
init_async_complete (init_data);
else
init_async_get_properties (init_data);
}
static void static void
init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data) init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NMObjectInitData *init_data = user_data; NMObjectInitData *init_data = user_data;
NMObject *self = init_data->object; NMObject *self = init_data->object;
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
DBusGProxy *proxy; GDBusProxy *proxy;
if (!init_data->error) { if (!init_data->error) {
proxy = _nm_dbus_new_proxy_for_connection_finish (result, &init_data->error); proxy = _nm_dbus_new_proxy_for_connection_finish (result, &init_data->error);
if (proxy) { if (proxy) {
const char *interface = dbus_g_proxy_get_interface (proxy); const char *interface = g_dbus_proxy_get_interface_name (proxy);
if (!strcmp (interface, DBUS_INTERFACE_PROPERTIES)) if (!strcmp (interface, DBUS_INTERFACE_PROPERTIES))
priv->properties_proxy = proxy; priv->properties_proxy = proxy;
@@ -313,16 +264,7 @@ init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
NM_OBJECT_GET_CLASS (self)->init_dbus (self); NM_OBJECT_GET_CLASS (self)->init_dbus (self);
if (_nm_dbus_is_connection_private (priv->connection)) { _nm_object_reload_properties_async (init_data->object, init_async_got_properties, init_data);
priv->nm_running = TRUE;
init_async_get_properties (init_data);
} else {
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_nm_running,
init_data, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
} }
static void static void
@@ -356,7 +298,7 @@ init_async_got_bus (GObject *object, GAsyncResult *result, gpointer user_data)
init_async_got_proxy, init_data); init_async_got_proxy, init_data);
init_data->proxies_pending++; init_data->proxies_pending++;
} }
static void static void
init_async (GAsyncInitable *initable, int io_priority, init_async (GAsyncInitable *initable, int io_priority,
GCancellable *cancellable, GAsyncReadyCallback callback, GCancellable *cancellable, GAsyncReadyCallback callback,
@@ -410,12 +352,8 @@ dispose (GObject *object)
g_clear_pointer (&priv->proxies, g_hash_table_unref); g_clear_pointer (&priv->proxies, g_hash_table_unref);
g_clear_object (&priv->properties_proxy); g_clear_object (&priv->properties_proxy);
g_clear_object (&priv->bus_proxy);
if (priv->connection) { g_clear_object (&priv->connection);
dbus_g_connection_unref (priv->connection);
priv->connection = NULL;
}
G_OBJECT_CLASS (nm_object_parent_class)->dispose (object); G_OBJECT_CLASS (nm_object_parent_class)->dispose (object);
} }
@@ -593,11 +531,11 @@ nm_object_get_path (NMObject *object)
* *
* Returns: (transfer none): a D-Bus proxy * Returns: (transfer none): a D-Bus proxy
*/ */
DBusGProxy * GDBusProxy *
_nm_object_get_proxy (NMObject *object, _nm_object_get_proxy (NMObject *object,
const char *interface) const char *interface)
{ {
DBusGProxy *proxy; GDBusProxy *proxy;
g_return_val_if_fail (NM_IS_OBJECT (object), NULL); g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
@@ -682,7 +620,7 @@ _nm_object_register_type_func (GType base_type,
} }
static GObject * static GObject *
_nm_object_create (GType type, DBusGConnection *connection, const char *path) _nm_object_create (GType type, GDBusConnection *connection, const char *path)
{ {
NMObjectTypeFuncData *type_data; NMObjectTypeFuncData *type_data;
GObject *object; GObject *object;
@@ -690,8 +628,8 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path)
type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type)); type_data = g_hash_table_lookup (type_funcs, GSIZE_TO_POINTER (type));
if (type_data) { if (type_data) {
DBusGProxy *proxy; GDBusProxy *proxy;
GValue value = G_VALUE_INIT; GVariant *ret, *value;
proxy = _nm_dbus_new_proxy_for_connection (connection, path, proxy = _nm_dbus_new_proxy_for_connection (connection, path,
DBUS_INTERFACE_PROPERTIES, DBUS_INTERFACE_PROPERTIES,
@@ -702,23 +640,25 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path)
return G_TYPE_INVALID; return G_TYPE_INVALID;
} }
if (!dbus_g_proxy_call (proxy, ret = g_dbus_proxy_call_sync (proxy,
"Get", &error, "Get",
G_TYPE_STRING, type_data->interface, g_variant_new ("(ss)",
G_TYPE_STRING, type_data->property, type_data->interface,
G_TYPE_INVALID, type_data->property),
G_TYPE_VALUE, &value, G_DBUS_CALL_FLAGS_NONE, -1,
G_TYPE_INVALID)) { NULL, &error);
g_object_unref (proxy);
if (!ret) {
g_warning ("Could not fetch property '%s' of interface '%s' on %s: %s\n", g_warning ("Could not fetch property '%s' of interface '%s' on %s: %s\n",
type_data->property, type_data->interface, path, error->message); type_data->property, type_data->interface, path, error->message);
g_error_free (error); g_error_free (error);
g_object_unref (proxy);
return G_TYPE_INVALID; return G_TYPE_INVALID;
} }
g_object_unref (proxy);
type = type_data->type_func (&value); g_variant_get (ret, "(v)", &value);
g_value_unset (&value); type = type_data->type_func (value);
g_variant_unref (value);
g_variant_unref (ret);
} }
if (type == G_TYPE_INVALID) { if (type == G_TYPE_INVALID) {
@@ -813,24 +753,24 @@ create_async_got_type (NMObjectTypeAsyncData *async_data, GType type)
} }
static void static void
create_async_got_property (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) create_async_got_property (GObject *proxy, GAsyncResult *result, gpointer user_data)
{ {
NMObjectTypeAsyncData *async_data = user_data; NMObjectTypeAsyncData *async_data = user_data;
NMObjectTypeFuncData *type_data = async_data->type_data; NMObjectTypeFuncData *type_data = async_data->type_data;
GValue value = G_VALUE_INIT; GVariant *ret, *value;
GError *error = NULL; GError *error = NULL;
GType type; GType type;
if (dbus_g_proxy_end_call (proxy, call, &error, ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
G_TYPE_VALUE, &value, if (ret) {
G_TYPE_INVALID)) { g_variant_get (ret, "(v)", &value);
type = type_data->type_func (&value); type = type_data->type_func (value);
g_value_unset (&value); g_variant_unref (value);
g_variant_unref (ret);
} else { } else {
const char *path = dbus_g_proxy_get_path (proxy);
g_warning ("Could not fetch property '%s' of interface '%s' on %s: %s\n", g_warning ("Could not fetch property '%s' of interface '%s' on %s: %s\n",
type_data->property, type_data->interface, path, error->message); type_data->property, type_data->interface, async_data->path,
error->message);
g_clear_error (&error); g_clear_error (&error);
type = G_TYPE_INVALID; type = G_TYPE_INVALID;
} }
@@ -842,7 +782,7 @@ static void
create_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data) create_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NMObjectTypeAsyncData *async_data = user_data; NMObjectTypeAsyncData *async_data = user_data;
DBusGProxy *proxy; GDBusProxy *proxy;
GError *error = NULL; GError *error = NULL;
proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error); proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error);
@@ -853,15 +793,18 @@ create_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_dat
return; return;
} }
dbus_g_proxy_begin_call (proxy, "Get", g_dbus_proxy_call (proxy,
create_async_got_property, async_data, NULL, "Get",
G_TYPE_STRING, async_data->type_data->interface, g_variant_new ("(ss)",
G_TYPE_STRING, async_data->type_data->property, async_data->type_data->interface,
G_TYPE_INVALID); async_data->type_data->property),
G_DBUS_CALL_FLAGS_NONE, -1,
NULL,
create_async_got_property, async_data);
} }
static void static void
_nm_object_create_async (GType type, DBusGConnection *connection, const char *path, _nm_object_create_async (GType type, GDBusConnection *connection, const char *path,
NMObjectCreateCallbackFunc callback, gpointer user_data) NMObjectCreateCallbackFunc callback, gpointer user_data)
{ {
NMObjectTypeAsyncData *async_data; NMObjectTypeAsyncData *async_data;
@@ -1083,7 +1026,7 @@ object_created (GObject *obj, const char *path, gpointer user_data)
} }
static gboolean static gboolean
handle_object_property (NMObject *self, const char *property_name, GValue *value, handle_object_property (NMObject *self, const char *property_name, GVariant *value,
PropertyInfo *pi, gboolean synchronously) PropertyInfo *pi, gboolean synchronously)
{ {
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
@@ -1102,7 +1045,7 @@ handle_object_property (NMObject *self, const char *property_name, GValue *value
if (priv->reload_results) if (priv->reload_results)
priv->reload_remaining++; priv->reload_remaining++;
path = g_value_get_boxed (value); path = g_variant_get_string (value, NULL);
if (!strcmp (path, "/")) { if (!strcmp (path, "/")) {
object_created (NULL, path, odata); object_created (NULL, path, odata);
@@ -1126,37 +1069,37 @@ handle_object_property (NMObject *self, const char *property_name, GValue *value
} }
static gboolean static gboolean
handle_object_array_property (NMObject *self, const char *property_name, GValue *value, handle_object_array_property (NMObject *self, const char *property_name, GVariant *value,
PropertyInfo *pi, gboolean synchronously) PropertyInfo *pi, gboolean synchronously)
{ {
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
GObject *obj; GObject *obj;
GPtrArray *paths; GVariantIter iter;
gsize npaths;
GPtrArray **array = pi->field; GPtrArray **array = pi->field;
const char *path; const char *path;
ObjectCreatedData *odata; ObjectCreatedData *odata;
int i;
paths = g_value_get_boxed (value); npaths = g_variant_n_children (value);
odata = g_slice_new (ObjectCreatedData); odata = g_slice_new (ObjectCreatedData);
odata->self = g_object_ref (self); odata->self = g_object_ref (self);
odata->pi = pi; odata->pi = pi;
odata->objects = g_new0 (GObject *, paths->len); odata->objects = g_new0 (GObject *, npaths);
odata->length = odata->remaining = paths->len; odata->length = odata->remaining = npaths;
odata->array = TRUE; odata->array = TRUE;
odata->property_name = property_name; odata->property_name = property_name;
if (priv->reload_results) if (priv->reload_results)
priv->reload_remaining++; priv->reload_remaining++;
if (paths->len == 0) { if (npaths == 0) {
object_property_complete (odata); object_property_complete (odata);
return TRUE; return TRUE;
} }
for (i = 0; i < paths->len; i++) { g_variant_iter_init (&iter, value);
path = paths->pdata[i]; while (g_variant_iter_next (&iter, "&o", &path)) {
if (!strcmp (path, "/")) { if (!strcmp (path, "/")) {
/* FIXME: can't happen? */ /* FIXME: can't happen? */
continue; continue;
@@ -1179,11 +1122,12 @@ handle_object_array_property (NMObject *self, const char *property_name, GValue
return TRUE; return TRUE;
} }
return *array && ((*array)->len == paths->len); return *array && ((*array)->len == npaths);
} }
static void static void
handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, gboolean synchronously) handle_property_changed (NMObject *self, const char *dbus_name,
GVariant *value, gboolean synchronously)
{ {
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
char *prop_name; char *prop_name;
@@ -1224,7 +1168,7 @@ handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, g
if (G_UNLIKELY (debug)) { if (G_UNLIKELY (debug)) {
char *s; char *s;
s = g_strdup_value_contents (value); s = g_variant_print (value, FALSE);
dbgmsg ("PC: (%p) %s::%s => '%s' (%s%s%s)", dbgmsg ("PC: (%p) %s::%s => '%s' (%s%s%s)",
self, G_OBJECT_TYPE_NAME (self), self, G_OBJECT_TYPE_NAME (self),
prop_name, prop_name,
@@ -1236,9 +1180,9 @@ handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, g
} }
if (pi->object_type) { if (pi->object_type) {
if (G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH))
success = handle_object_property (self, pspec->name, value, pi, synchronously); success = handle_object_property (self, pspec->name, value, pi, synchronously);
else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)) else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("ao")))
success = handle_object_array_property (self, pspec->name, value, pi, synchronously); success = handle_object_array_property (self, pspec->name, value, pi, synchronously);
else { else {
g_warn_if_reached (); g_warn_if_reached ();
@@ -1259,39 +1203,43 @@ out:
} }
static void static void
process_properties_changed (NMObject *self, GHashTable *properties, gboolean synchronously) process_properties_changed (NMObject *self, GVariant *properties, gboolean synchronously)
{ {
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
GHashTableIter iter; GVariantIter iter;
gpointer name, value; const char *name;
GVariant *value;
if (priv->suppress_property_updates) if (priv->suppress_property_updates)
return; return;
g_hash_table_iter_init (&iter, properties); g_variant_iter_init (&iter, properties);
while (g_hash_table_iter_next (&iter, &name, &value)) { while (g_variant_iter_next (&iter, "{sv}", &name, &value))
if (value) handle_property_changed (self, name, value, synchronously);
handle_property_changed (self, name, value, synchronously);
else {
dbgmsg ("%s:%d %s(): object %s property '%s' value is unexpectedly NULL",
__FILE__, __LINE__, __func__, G_OBJECT_TYPE_NAME (self), (const char *) name);
}
}
} }
static void static void
properties_changed_proxy (DBusGProxy *proxy, property_proxy_signal (GDBusProxy *proxy,
GHashTable *properties, const char *sender_name,
gpointer user_data) const char *signal_name,
GVariant *parameters,
gpointer user_data)
{ {
GVariant *properties;
if (strcmp (signal_name, "PropertiesChanged") != 0)
return;
g_variant_get (parameters, "(@a{sv})", &properties);
process_properties_changed (NM_OBJECT (user_data), properties, FALSE); process_properties_changed (NM_OBJECT (user_data), properties, FALSE);
g_variant_unref (properties);
} }
#define HANDLE_TYPE(ucase, lcase, getter) \ #define HANDLE_TYPE(gtype, vtype, ctype, getter) \
} else if (pspec->value_type == G_TYPE_##ucase) { \ } else if (pspec->value_type == gtype) { \
if (G_VALUE_HOLDS_##ucase (value)) { \ if (g_variant_is_of_type (value, vtype)) { \
g##lcase *param = (g##lcase *) field; \ ctype *param = (ctype *) field; \
*param = g_value_get_##getter (value); \ *param = getter (value); \
} else { \ } else { \
success = FALSE; \ success = FALSE; \
goto done; \ goto done; \
@@ -1300,20 +1248,20 @@ properties_changed_proxy (DBusGProxy *proxy,
static gboolean static gboolean
demarshal_generic (NMObject *object, demarshal_generic (NMObject *object,
GParamSpec *pspec, GParamSpec *pspec,
GValue *value, GVariant *value,
gpointer field) gpointer field)
{ {
gboolean success = TRUE; gboolean success = TRUE;
if (pspec->value_type == G_TYPE_STRING) { if (pspec->value_type == G_TYPE_STRING) {
if (G_VALUE_HOLDS_STRING (value)) { if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) {
char **param = (char **) field; char **param = (char **) field;
g_free (*param); g_free (*param);
*param = g_value_dup_string (value); *param = g_variant_dup_string (value, NULL);
} else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) { } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) {
char **param = (char **) field; char **param = (char **) field;
g_free (*param); g_free (*param);
*param = g_strdup (g_value_get_boxed (value)); *param = g_variant_dup_string (value, NULL);
/* Handle "NULL" object paths */ /* Handle "NULL" object paths */
if (g_strcmp0 (*param, "/") == 0) { if (g_strcmp0 (*param, "/") == 0) {
g_free (*param); g_free (*param);
@@ -1327,24 +1275,28 @@ demarshal_generic (NMObject *object,
char ***param = (char ***)field; char ***param = (char ***)field;
if (*param) if (*param)
g_strfreev (*param); g_strfreev (*param);
*param = g_value_dup_boxed (value); *param = g_variant_dup_strv (value, NULL);
} else if (pspec->value_type == G_TYPE_BYTES) { } else if (pspec->value_type == G_TYPE_BYTES) {
GBytes **param = (GBytes **)field; GBytes **param = (GBytes **)field;
GByteArray *val; gconstpointer val;
gsize length;
if (*param) if (*param)
g_bytes_unref (*param); g_bytes_unref (*param);
val = g_value_get_boxed (value); val = g_variant_get_fixed_array (value, &length, 1);
*param = g_bytes_new (val->data, val->len); if (length)
HANDLE_TYPE(BOOLEAN, boolean, boolean) *param = g_bytes_new (val, length);
HANDLE_TYPE(CHAR, char, schar) else
HANDLE_TYPE(UCHAR, uchar, uchar) *param = NULL;
HANDLE_TYPE(DOUBLE, double, double) HANDLE_TYPE (G_TYPE_BOOLEAN, G_VARIANT_TYPE_BOOLEAN, gboolean, g_variant_get_boolean)
HANDLE_TYPE(INT, int, int) HANDLE_TYPE (G_TYPE_UCHAR, G_VARIANT_TYPE_BYTE, guchar, g_variant_get_byte)
HANDLE_TYPE(UINT, uint, uint) HANDLE_TYPE (G_TYPE_DOUBLE, G_VARIANT_TYPE_DOUBLE, gdouble, g_variant_get_double)
HANDLE_TYPE(INT64, int, int) HANDLE_TYPE (G_TYPE_INT, G_VARIANT_TYPE_INT32, gint, g_variant_get_int32)
HANDLE_TYPE(UINT64, uint, uint) HANDLE_TYPE (G_TYPE_UINT, G_VARIANT_TYPE_UINT32, guint, g_variant_get_uint32)
HANDLE_TYPE(LONG, long, long) HANDLE_TYPE (G_TYPE_INT64, G_VARIANT_TYPE_INT64, gint, g_variant_get_int64)
HANDLE_TYPE(ULONG, ulong, ulong) HANDLE_TYPE (G_TYPE_UINT64, G_VARIANT_TYPE_UINT64, guint, g_variant_get_uint64)
HANDLE_TYPE (G_TYPE_LONG, G_VARIANT_TYPE_INT64, glong, g_variant_get_int64)
HANDLE_TYPE (G_TYPE_ULONG, G_VARIANT_TYPE_UINT64, gulong, g_variant_get_uint64)
} else { } else {
dbgmsg ("%s: %s/%s unhandled type %s.", dbgmsg ("%s: %s/%s unhandled type %s.",
__func__, __func__,
@@ -1371,7 +1323,7 @@ _nm_object_register_properties (NMObject *object,
const NMPropertiesInfo *info) const NMPropertiesInfo *info)
{ {
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
DBusGProxy *proxy; GDBusProxy *proxy;
static gsize dval = 0; static gsize dval = 0;
const char *debugstr; const char *debugstr;
NMPropertiesInfo *tmp; NMPropertiesInfo *tmp;
@@ -1391,12 +1343,8 @@ _nm_object_register_properties (NMObject *object,
proxy = _nm_object_get_proxy (object, interface); proxy = _nm_object_get_proxy (object, interface);
g_return_if_fail (proxy != NULL); g_return_if_fail (proxy != NULL);
dbus_g_proxy_add_signal (proxy, "PropertiesChanged", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); g_signal_connect (proxy, "g-signal",
dbus_g_proxy_connect_signal (proxy, G_CALLBACK (property_proxy_signal), object);
"PropertiesChanged",
G_CALLBACK (properties_changed_proxy),
object,
NULL);
instance = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); instance = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->property_tables = g_slist_prepend (priv->property_tables, instance); priv->property_tables = g_slist_prepend (priv->property_tables, instance);
@@ -1422,25 +1370,28 @@ gboolean
_nm_object_reload_properties (NMObject *object, GError **error) _nm_object_reload_properties (NMObject *object, GError **error)
{ {
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
GHashTable *props = NULL; GVariant *ret, *props;
GHashTableIter iter; GHashTableIter iter;
const char *interface; const char *interface;
DBusGProxy *proxy; GDBusProxy *proxy;
if (!g_hash_table_size (priv->proxies) || !priv->nm_running) if (!g_hash_table_size (priv->proxies) || !priv->nm_running)
return TRUE; return TRUE;
g_hash_table_iter_init (&iter, priv->proxies); g_hash_table_iter_init (&iter, priv->proxies);
while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) { while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) {
if (!dbus_g_proxy_call (priv->properties_proxy, "GetAll", error, ret = g_dbus_proxy_call_sync (priv->properties_proxy,
G_TYPE_STRING, interface, "GetAll",
G_TYPE_INVALID, g_variant_new ("(s)", interface),
DBUS_TYPE_G_MAP_OF_VARIANT, &props, G_DBUS_CALL_FLAGS_NONE, -1,
G_TYPE_INVALID)) NULL, error);
if (!ret)
return FALSE; return FALSE;
g_variant_get (ret, "(@a{sv})", &props);
process_properties_changed (object, props, TRUE); process_properties_changed (object, props, TRUE);
g_hash_table_destroy (props); g_variant_unref (props);
g_variant_unref (ret);
} }
return TRUE; return TRUE;
@@ -1460,7 +1411,7 @@ _nm_object_reload_property (NMObject *object,
const char *interface, const char *interface,
const char *prop_name) const char *prop_name)
{ {
GValue value = G_VALUE_INIT; GVariant *ret, *value;
GError *err = NULL; GError *err = NULL;
g_return_if_fail (NM_IS_OBJECT (object)); g_return_if_fail (NM_IS_OBJECT (object));
@@ -1470,13 +1421,12 @@ _nm_object_reload_property (NMObject *object,
if (!NM_OBJECT_GET_PRIVATE (object)->nm_running) if (!NM_OBJECT_GET_PRIVATE (object)->nm_running)
return; return;
if (!dbus_g_proxy_call_with_timeout (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
"Get", 15000, &err, "Get",
G_TYPE_STRING, interface, g_variant_new ("(ss)", interface, prop_name),
G_TYPE_STRING, prop_name, G_DBUS_CALL_FLAGS_NONE, 15000,
G_TYPE_INVALID, NULL, &err);
G_TYPE_VALUE, &value, if (!ret) {
G_TYPE_INVALID)) {
dbgmsg ("%s: Error getting '%s' for %s: (%d) %s\n", dbgmsg ("%s: Error getting '%s' for %s: (%d) %s\n",
__func__, __func__,
prop_name, prop_name,
@@ -1487,35 +1437,43 @@ _nm_object_reload_property (NMObject *object,
return; return;
} }
handle_property_changed (object, prop_name, &value, TRUE); g_variant_get (ret, "(v)", &value);
g_value_unset (&value); handle_property_changed (object, prop_name, value, TRUE);
g_variant_unref (value);
g_variant_unref (ret);
} }
void void
_nm_object_set_property (NMObject *object, _nm_object_set_property (NMObject *object,
const char *interface, const char *interface,
const char *prop_name, const char *prop_name,
GValue *value) const char *format_string,
...)
{ {
GVariant *val, *ret;
va_list ap;
g_return_if_fail (NM_IS_OBJECT (object)); g_return_if_fail (NM_IS_OBJECT (object));
g_return_if_fail (interface != NULL); g_return_if_fail (interface != NULL);
g_return_if_fail (prop_name != NULL); g_return_if_fail (prop_name != NULL);
g_return_if_fail (G_IS_VALUE (value)); g_return_if_fail (format_string != NULL);
if (!NM_OBJECT_GET_PRIVATE (object)->nm_running) if (!NM_OBJECT_GET_PRIVATE (object)->nm_running)
return; return;
if (!dbus_g_proxy_call_with_timeout (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, va_start (ap, format_string);
"Set", 2000, NULL, val = g_variant_new_va (format_string, NULL, &ap);
G_TYPE_STRING, interface, va_end (ap);
G_TYPE_STRING, prop_name, g_return_if_fail (val != NULL);
G_TYPE_VALUE, value,
G_TYPE_INVALID)) {
/* Ignore errors. dbus_g_proxy_call_with_timeout() is called instead of ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
* dbus_g_proxy_call_no_reply() to give NM chance to authenticate the caller. "Set",
*/ g_variant_new ("(ssv)", interface, prop_name, val),
} G_DBUS_CALL_FLAGS_NONE, 2000,
NULL, NULL);
/* Ignore errors. */
if (ret)
g_variant_unref (ret);
} }
static void static void
@@ -1547,19 +1505,21 @@ reload_complete (NMObject *object)
} }
static void static void
reload_got_properties (DBusGProxy *proxy, DBusGProxyCall *call, reload_got_properties (GObject *proxy,
GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
NMObject *object = user_data; NMObject *object = user_data;
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
GHashTable *props = NULL; GVariant *ret, *props;
GError *error = NULL; GError *error = NULL;
if (dbus_g_proxy_end_call (proxy, call, &error, ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
DBUS_TYPE_G_MAP_OF_VARIANT, &props, if (ret) {
G_TYPE_INVALID)) { g_variant_get (ret, "(@a{sv})", &props);
process_properties_changed (object, props, FALSE); process_properties_changed (object, props, FALSE);
g_hash_table_destroy (props); g_variant_unref (props);
g_variant_unref (ret);
} else { } else {
if (priv->reload_error) if (priv->reload_error)
g_error_free (error); g_error_free (error);
@@ -1578,12 +1538,12 @@ _nm_object_reload_properties_async (NMObject *object, GAsyncReadyCallback callba
GSimpleAsyncResult *simple; GSimpleAsyncResult *simple;
GHashTableIter iter; GHashTableIter iter;
const char *interface; const char *interface;
DBusGProxy *proxy; GDBusProxy *proxy;
simple = g_simple_async_result_new (G_OBJECT (object), callback, simple = g_simple_async_result_new (G_OBJECT (object), callback,
user_data, _nm_object_reload_properties_async); user_data, _nm_object_reload_properties_async);
if (!g_hash_table_size (priv->proxies)) { if (!g_hash_table_size (priv->proxies) || !priv->nm_running) {
g_simple_async_result_complete_in_idle (simple); g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple); g_object_unref (simple);
return; return;
@@ -1601,10 +1561,12 @@ _nm_object_reload_properties_async (NMObject *object, GAsyncReadyCallback callba
g_hash_table_iter_init (&iter, priv->proxies); g_hash_table_iter_init (&iter, priv->proxies);
while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) { while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) {
priv->reload_remaining++; priv->reload_remaining++;
dbus_g_proxy_begin_call (priv->properties_proxy, "GetAll", g_dbus_proxy_call (priv->properties_proxy,
reload_got_properties, object, NULL, "GetAll",
G_TYPE_STRING, interface, g_variant_new ("(s)", interface),
G_TYPE_INVALID); G_DBUS_CALL_FLAGS_NONE, -1,
NULL,
reload_got_properties, object);
} }
} }

View File

@@ -26,9 +26,7 @@
#error "Only <NetworkManager.h> can be included directly." #error "Only <NetworkManager.h> can be included directly."
#endif #endif
#include <glib.h> #include <gio/gio.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <nm-version.h> #include <nm-version.h>

View File

@@ -29,10 +29,10 @@
#include "nm-remote-connection.h" #include "nm-remote-connection.h"
#include "nm-remote-connection-private.h" #include "nm-remote-connection-private.h"
#include "nm-object-private.h" #include "nm-object-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-dbus-helpers.h" #include "nm-dbus-helpers.h"
#include "nm-utils-private.h"
#include "nmdbus-settings-connection.h"
static void nm_remote_connection_connection_iface_init (NMConnectionInterface *iface); static void nm_remote_connection_connection_iface_init (NMConnectionInterface *iface);
static void nm_remote_connection_initable_iface_init (GInitableIface *iface); static void nm_remote_connection_initable_iface_init (GInitableIface *iface);
@@ -55,21 +55,18 @@ enum {
}; };
typedef struct RemoteCall RemoteCall; typedef struct RemoteCall RemoteCall;
typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error); typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, GAsyncResult *result);
struct RemoteCall { struct RemoteCall {
NMRemoteConnection *self; NMRemoteConnection *self;
DBusGProxyCall *call;
RemoteCallFetchResultCb fetch_result_cb; RemoteCallFetchResultCb fetch_result_cb;
GFunc callback; GFunc callback;
gpointer user_data; gpointer user_data;
}; };
typedef struct { typedef struct {
DBusGProxy *proxy; NMDBusSettingsConnection *proxy;
gboolean proxy_is_destroyed;
GSList *calls;
gboolean unsaved; gboolean unsaved;
@@ -98,35 +95,16 @@ nm_remote_connection_error_quark (void)
/****************************************************************/ /****************************************************************/
static void static void
remote_call_dbus_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data) remote_call_dbus_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{ {
RemoteCall *call = user_data; RemoteCall *call = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
GError *error = NULL;
g_assert ( (!proxy && !proxy_call && priv->proxy_is_destroyed) || call->fetch_result_cb (call, result);
( proxy && proxy_call && !priv->proxy_is_destroyed && proxy == priv->proxy) );
if (priv->proxy_is_destroyed) {
error = g_error_new_literal (NM_REMOTE_CONNECTION_ERROR,
NM_REMOTE_CONNECTION_ERROR_DISCONNECTED,
_("Disconnected by D-Bus"));
}
call->fetch_result_cb (call, proxy_call, error);
g_clear_error (&error);
priv->calls = g_slist_remove (priv->calls, call);
g_object_unref (call->self); g_object_unref (call->self);
g_free (call); g_free (call);
} }
static gboolean
remote_call_cleanup_cb (void *user_data)
{
remote_call_dbus_cb (NULL, NULL, user_data);
return G_SOURCE_REMOVE;
}
static RemoteCall * static RemoteCall *
remote_call_new (NMRemoteConnection *self, remote_call_new (NMRemoteConnection *self,
RemoteCallFetchResultCb fetch_result_cb, RemoteCallFetchResultCb fetch_result_cb,
@@ -134,65 +112,31 @@ remote_call_new (NMRemoteConnection *self,
gpointer user_data) gpointer user_data)
{ {
RemoteCall *call; RemoteCall *call;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
g_assert (fetch_result_cb); g_assert (fetch_result_cb);
if (priv->proxy_is_destroyed && !callback)
return NULL;
call = g_malloc0 (sizeof (RemoteCall)); call = g_malloc0 (sizeof (RemoteCall));
call->self = g_object_ref (self); call->self = g_object_ref (self);
call->fetch_result_cb = fetch_result_cb; call->fetch_result_cb = fetch_result_cb;
call->user_data = user_data; call->user_data = user_data;
call->callback = callback; call->callback = callback;
if (priv->proxy_is_destroyed) {
g_idle_add (remote_call_cleanup_cb, call);
return NULL;
}
priv->calls = g_slist_prepend (priv->calls, call);
return call; return call;
} }
static void
proxy_set_destroyed (NMRemoteConnection *self)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
if (priv->proxy_is_destroyed) {
g_assert (!priv->calls);
return;
}
priv->proxy_is_destroyed = TRUE;
priv->calls = g_slist_reverse (priv->calls);
while (priv->calls)
remote_call_dbus_cb (NULL, NULL, priv->calls->data);
}
static void
proxy_destroy_cb (DBusGProxy* proxy, gpointer user_data) {
proxy_set_destroyed (user_data);
}
/****************************************************************/ /****************************************************************/
static void static void
result_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error) update_result_cb (RemoteCall *call, GAsyncResult *result)
{ {
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback; NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
GError *local_error = NULL; GError *error = NULL;
if (!error) { nmdbus_settings_connection_call_update_finish (priv->proxy, result, &error);
dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy,
proxy_call, &local_error, G_TYPE_INVALID);
error = local_error;
}
if (func) if (func)
(*func) (call->self, error, call->user_data); (*func) (call->self, error, call->user_data);
g_clear_error (&local_error); g_clear_error (&error);
} }
/** /**
@@ -212,27 +156,34 @@ nm_remote_connection_commit_changes (NMRemoteConnection *self,
{ {
NMRemoteConnectionPrivate *priv; NMRemoteConnectionPrivate *priv;
RemoteCall *call; RemoteCall *call;
GVariant *settings_dict; GVariant *settings;
GHashTable *settings;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (self)); g_return_if_fail (NM_IS_REMOTE_CONNECTION (self));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
call = remote_call_new (self, result_cb, (GFunc) callback, user_data); call = remote_call_new (self, update_result_cb, (GFunc) callback, user_data);
if (!call) if (!call)
return; return;
settings_dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ALL); settings = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ALL);
settings = _nm_utils_connection_dict_to_hash (settings_dict); nmdbus_settings_connection_call_update (priv->proxy,
g_variant_unref (settings_dict); settings,
NULL,
remote_call_dbus_cb, call);
}
call->call = dbus_g_proxy_begin_call (priv->proxy, "Update", static void
remote_call_dbus_cb, call, NULL, update_unsaved_result_cb (RemoteCall *call, GAsyncResult *result)
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings, {
G_TYPE_INVALID); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
g_assert (call->call); NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
g_hash_table_destroy (settings); GError *error = NULL;
nmdbus_settings_connection_call_update_unsaved_finish (priv->proxy, result, &error);
if (func)
(*func) (call->self, error, call->user_data);
g_clear_error (&error);
} }
/** /**
@@ -253,27 +204,35 @@ nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection,
gpointer user_data) gpointer user_data)
{ {
NMRemoteConnectionPrivate *priv; NMRemoteConnectionPrivate *priv;
GVariant *settings_dict; GVariant *settings;
GHashTable *settings;
RemoteCall *call; RemoteCall *call;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
call = remote_call_new (connection, result_cb, (GFunc) callback, user_data); call = remote_call_new (connection, update_unsaved_result_cb, (GFunc) callback, user_data);
if (!call) if (!call)
return; return;
settings_dict = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL); settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL);
settings = _nm_utils_connection_dict_to_hash (settings_dict); nmdbus_settings_connection_call_update_unsaved (priv->proxy,
g_variant_unref (settings_dict); settings,
call->call = dbus_g_proxy_begin_call (priv->proxy, "UpdateUnsaved", NULL,
remote_call_dbus_cb, call, NULL, remote_call_dbus_cb, call);
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings, }
G_TYPE_INVALID);
g_assert (call->call); static void
g_hash_table_destroy (settings); save_result_cb (RemoteCall *call, GAsyncResult *result)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
GError *error = NULL;
nmdbus_settings_connection_call_save_finish (priv->proxy, result, &error);
if (func)
(*func) (call->self, error, call->user_data);
g_clear_error (&error);
} }
/** /**
@@ -298,12 +257,26 @@ nm_remote_connection_save (NMRemoteConnection *connection,
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
call = remote_call_new (connection, result_cb, (GFunc) callback, user_data); call = remote_call_new (connection, save_result_cb, (GFunc) callback, user_data);
if (!call) if (!call)
return; return;
call->call = dbus_g_proxy_begin_call (priv->proxy, "Save", remote_call_dbus_cb, call, NULL, G_TYPE_INVALID); nmdbus_settings_connection_call_save (priv->proxy,
g_assert (call->call); NULL,
remote_call_dbus_cb, call);
}
static void
delete_result_cb (RemoteCall *call, GAsyncResult *result)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback;
GError *error = NULL;
nmdbus_settings_connection_call_delete_finish (priv->proxy, result, &error);
if (func)
(*func) (call->self, error, call->user_data);
g_clear_error (&error);
} }
/** /**
@@ -326,46 +299,31 @@ nm_remote_connection_delete (NMRemoteConnection *self,
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
call = remote_call_new (self, result_cb, (GFunc) callback, user_data); call = remote_call_new (self, delete_result_cb, (GFunc) callback, user_data);
if (!call) if (!call)
return; return;
call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete", nmdbus_settings_connection_call_delete (priv->proxy,
remote_call_dbus_cb, call, NULL, NULL,
G_TYPE_INVALID); remote_call_dbus_cb, call);
g_assert (call->call);
} }
static void static void
get_secrets_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error) get_secrets_cb (RemoteCall *call, GAsyncResult *result)
{ {
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback; NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback;
GHashTable *secrets = NULL; GVariant *secrets = NULL;
GError *local_error = NULL; GError *error = NULL;
if (!error) { if (!nmdbus_settings_connection_call_get_secrets_finish (priv->proxy, &secrets,
dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, result, &error))
proxy_call, &local_error, secrets = NULL;
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets, if (func)
G_TYPE_INVALID); (*func) (call->self, error ? NULL : secrets, error, call->user_data);
error = local_error; g_clear_error (&error);
}
if (func) {
GVariant *secrets_dict;
if (secrets)
secrets_dict = _nm_utils_connection_hash_to_dict (secrets);
else
secrets_dict = NULL;
(*func) (call->self, error ? NULL : secrets_dict, error, call->user_data);
if (secrets_dict)
g_variant_unref (secrets_dict);
}
g_clear_error (&local_error);
if (secrets) if (secrets)
g_hash_table_destroy (secrets); g_variant_unref (secrets);
} }
@@ -397,11 +355,10 @@ nm_remote_connection_get_secrets (NMRemoteConnection *self,
if (!call) if (!call)
return; return;
call->call = dbus_g_proxy_begin_call (priv->proxy, "GetSecrets", nmdbus_settings_connection_call_get_secrets (priv->proxy,
remote_call_dbus_cb, call, NULL, setting_name,
G_TYPE_STRING, setting_name, NULL,
G_TYPE_INVALID); remote_call_dbus_cb, call);
g_assert (call->call);
} }
/** /**
@@ -447,13 +404,11 @@ nm_remote_connection_get_visible (NMRemoteConnection *connection)
/****************************************************************/ /****************************************************************/
static void static void
replace_settings (NMRemoteConnection *self, GHashTable *new_settings) replace_settings (NMRemoteConnection *self, GVariant *new_settings)
{ {
GError *error = NULL; GError *error = NULL;
GVariant *new_settings_dict;
new_settings_dict = _nm_utils_connection_hash_to_dict (new_settings); if (!nm_connection_replace_settings (NM_CONNECTION (self), new_settings, &error)) {
if (!nm_connection_replace_settings (NM_CONNECTION (self), new_settings_dict, &error)) {
g_warning ("%s: error updating connection %s settings: (%d) %s", g_warning ("%s: error updating connection %s settings: (%d) %s",
__func__, __func__,
nm_connection_get_path (NM_CONNECTION (self)), nm_connection_get_path (NM_CONNECTION (self)),
@@ -461,33 +416,27 @@ replace_settings (NMRemoteConnection *self, GHashTable *new_settings)
(error && error->message) ? error->message : "(unknown)"); (error && error->message) ? error->message : "(unknown)");
g_clear_error (&error); g_clear_error (&error);
} }
g_variant_unref (new_settings_dict);
} }
static void static void
updated_get_settings_cb (DBusGProxy *proxy, updated_get_settings_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
NMRemoteConnection *self = user_data; NMRemoteConnection *self = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
GHashTable *new_settings; GVariant *new_settings;
GError *error = NULL;
gboolean visible; gboolean visible;
dbus_g_proxy_end_call (proxy, call, &error, if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &new_settings,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings, result, NULL)) {
G_TYPE_INVALID);
if (error) {
g_error_free (error);
/* Connection is no longer visible to this user. */ /* Connection is no longer visible to this user. */
nm_connection_clear_settings (NM_CONNECTION (self)); nm_connection_clear_settings (NM_CONNECTION (self));
visible = FALSE; visible = FALSE;
} else { } else {
replace_settings (self, new_settings); replace_settings (self, new_settings);
g_hash_table_destroy (new_settings); g_variant_unref (new_settings);
visible = TRUE; visible = TRUE;
} }
@@ -499,17 +448,15 @@ updated_get_settings_cb (DBusGProxy *proxy,
} }
static void static void
updated_cb (DBusGProxy *proxy, gpointer user_data) updated_cb (NMDBusSettingsConnection *proxy, gpointer user_data)
{ {
NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data); NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
/* The connection got updated; request the replacement settings */ /* The connection got updated; request the replacement settings */
if (!priv->proxy_is_destroyed) { nmdbus_settings_connection_call_get_settings (priv->proxy,
dbus_g_proxy_begin_call (priv->proxy, "GetSettings", NULL,
updated_get_settings_cb, self, NULL, updated_get_settings_cb, self);
G_TYPE_INVALID);
}
} }
/****************************************************************/ /****************************************************************/
@@ -525,18 +472,15 @@ init_dbus (NMObject *object)
NM_OBJECT_CLASS (nm_remote_connection_parent_class)->init_dbus (object); NM_OBJECT_CLASS (nm_remote_connection_parent_class)->init_dbus (object);
priv->proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_SETTINGS_CONNECTION); priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_SETTINGS_CONNECTION));
g_assert (priv->proxy); g_assert (priv->proxy);
dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT);
_nm_object_register_properties (object, _nm_object_register_properties (object,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION, NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
property_info); property_info);
dbus_g_proxy_add_signal (priv->proxy, "Updated", G_TYPE_INVALID); g_signal_connect (priv->proxy, "updated",
dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), object, NULL); G_CALLBACK (updated_cb), object);
g_signal_connect (priv->proxy, "destroy", G_CALLBACK (proxy_destroy_cb), object);
} }
static gboolean static gboolean
@@ -544,25 +488,26 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{ {
NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable); NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
GHashTable *hash; GVariant *settings;
if (!nm_remote_connection_parent_initable_iface->init (initable, cancellable, error)) if (!nm_remote_connection_parent_initable_iface->init (initable, cancellable, error))
return FALSE; return FALSE;
if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error, if (!nmdbus_settings_connection_call_get_settings_sync (priv->proxy,
G_TYPE_INVALID, &settings,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash, cancellable, error))
G_TYPE_INVALID))
return FALSE; return FALSE;
priv->visible = TRUE; priv->visible = TRUE;
replace_settings (self, hash); replace_settings (self, settings);
g_hash_table_destroy (hash); g_variant_unref (settings);
return TRUE; return TRUE;
} }
typedef struct { typedef struct {
NMRemoteConnection *connection; NMRemoteConnection *connection;
GCancellable *cancellable;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
} NMRemoteConnectionInitData; } NMRemoteConnectionInitData;
@@ -576,30 +521,29 @@ init_async_complete (NMRemoteConnectionInitData *init_data, GError *error)
g_simple_async_result_complete (init_data->result); g_simple_async_result_complete (init_data->result);
g_object_unref (init_data->result); g_object_unref (init_data->result);
g_clear_object (&init_data->cancellable);
g_slice_free (NMRemoteConnectionInitData, init_data); g_slice_free (NMRemoteConnectionInitData, init_data);
} }
static void static void
init_get_settings_cb (DBusGProxy *proxy, init_get_settings_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
NMRemoteConnectionInitData *init_data = user_data; NMRemoteConnectionInitData *init_data = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
GHashTable *settings; GVariant *settings;
GError *error = NULL; GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &settings,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings, result, &error)) {
G_TYPE_INVALID);
if (error) {
init_async_complete (init_data, error); init_async_complete (init_data, error);
return; return;
} }
priv->visible = TRUE; priv->visible = TRUE;
replace_settings (init_data->connection, settings); replace_settings (init_data->connection, settings);
g_hash_table_destroy (settings); g_variant_unref (settings);
init_async_complete (init_data, NULL); init_async_complete (init_data, NULL);
} }
@@ -616,9 +560,9 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d
return; return;
} }
dbus_g_proxy_begin_call (priv->proxy, "GetSettings", nmdbus_settings_connection_call_get_settings (priv->proxy,
init_get_settings_cb, init_data, NULL, init_data->cancellable,
G_TYPE_INVALID); init_get_settings_cb, init_data);
} }
static void static void
@@ -630,6 +574,7 @@ init_async (GAsyncInitable *initable, int io_priority,
init_data = g_slice_new0 (NMRemoteConnectionInitData); init_data = g_slice_new0 (NMRemoteConnectionInitData);
init_data->connection = NM_REMOTE_CONNECTION (initable); init_data->connection = NM_REMOTE_CONNECTION (initable);
init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback, init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
user_data, init_async); user_data, init_async);
@@ -677,22 +622,6 @@ constructed (GObject *object)
nm_object_get_path (NM_OBJECT (object))); nm_object_get_path (NM_OBJECT (object)));
} }
static void
dispose (GObject *object)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (object);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
proxy_set_destroyed (self);
if (priv->proxy) {
g_signal_handlers_disconnect_by_func (priv->proxy, proxy_destroy_cb, object);
priv->proxy = NULL;
}
G_OBJECT_CLASS (nm_remote_connection_parent_class)->dispose (object);
}
static void static void
nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
{ {
@@ -702,11 +631,12 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
g_type_class_add_private (object_class, sizeof (NMRemoteConnectionPrivate)); g_type_class_add_private (object_class, sizeof (NMRemoteConnectionPrivate));
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_SETTINGS_CONNECTION); _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_SETTINGS_CONNECTION);
_nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
NMDBUS_TYPE_SETTINGS_CONNECTION_PROXY);
/* virtual methods */ /* virtual methods */
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus; nm_object_class->init_dbus = init_dbus;

View File

@@ -23,7 +23,6 @@
#include <nm-dbus-interface.h> #include <nm-dbus-interface.h>
#include <nm-connection.h> #include <nm-connection.h>
#include "nm-dbus-glib-types.h"
#include "nm-remote-settings.h" #include "nm-remote-settings.h"
#include "nm-remote-connection-private.h" #include "nm-remote-connection-private.h"
#include "nm-object-private.h" #include "nm-object-private.h"
@@ -32,6 +31,8 @@
#include "nm-object-private.h" #include "nm-object-private.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nmdbus-settings.h"
/** /**
* SECTION:nm-remote-settings * SECTION:nm-remote-settings
* @Short_description: A helper for NetworkManager's settings API * @Short_description: A helper for NetworkManager's settings API
@@ -124,7 +125,7 @@ G_DEFINE_TYPE (NMRemoteSettings, nm_remote_settings, NM_TYPE_OBJECT)
#define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate)) #define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate))
typedef struct { typedef struct {
DBusGProxy *proxy; NMDBusSettings *proxy;
GPtrArray *all_connections; GPtrArray *all_connections;
GPtrArray *visible_connections; GPtrArray *visible_connections;
@@ -424,19 +425,19 @@ nm_remote_settings_list_connections (NMRemoteSettings *settings)
} }
static void static void
add_connection_done (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
{ {
AddConnectionInfo *info = user_data; AddConnectionInfo *info = user_data;
GError *error = NULL; GError *error = NULL;
char *path = NULL;
if (dbus_g_proxy_end_call (proxy, call, &error, DBUS_TYPE_G_OBJECT_PATH, &path, G_TYPE_INVALID)) { if (nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy),
info->path = path; &info->path,
result, &error)) {
/* Wait until this connection is fully initialized before calling the callback */ /* Wait until this connection is fully initialized before calling the callback */
} else } else {
add_connection_info_complete (info->self, info, NULL, error); add_connection_info_complete (info->self, info, NULL, error);
g_clear_error (&error);
g_clear_error (&error); }
} }
/** /**
@@ -467,8 +468,7 @@ nm_remote_settings_add_connection (NMRemoteSettings *settings,
{ {
NMRemoteSettingsPrivate *priv; NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info; AddConnectionInfo *info;
GVariant *new_settings_dict; GVariant *new_settings;
GHashTable *new_settings;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
@@ -484,16 +484,11 @@ nm_remote_settings_add_connection (NMRemoteSettings *settings,
info->callback = callback; info->callback = callback;
info->callback_data = user_data; info->callback_data = user_data;
new_settings_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
new_settings = _nm_utils_connection_dict_to_hash (new_settings_dict); nmdbus_settings_call_add_connection (priv->proxy,
dbus_g_proxy_begin_call (priv->proxy, "AddConnection", new_settings,
add_connection_done, NULL,
info, add_connection_done, info);
NULL,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings,
G_TYPE_INVALID);
g_hash_table_destroy (new_settings);
g_variant_unref (new_settings_dict);
priv->add_list = g_slist_append (priv->add_list, info); priv->add_list = g_slist_append (priv->add_list, info);
@@ -523,8 +518,7 @@ nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings,
{ {
NMRemoteSettingsPrivate *priv; NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info; AddConnectionInfo *info;
GVariant *new_settings_dict; GVariant *new_settings;
GHashTable *new_settings;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
@@ -540,16 +534,11 @@ nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings,
info->callback = callback; info->callback = callback;
info->callback_data = user_data; info->callback_data = user_data;
new_settings_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
new_settings = _nm_utils_connection_dict_to_hash (new_settings_dict); nmdbus_settings_call_add_connection_unsaved (priv->proxy,
dbus_g_proxy_begin_call (priv->proxy, "AddConnectionUnsaved", new_settings,
add_connection_done, NULL,
info, add_connection_done, info);
NULL,
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings,
G_TYPE_INVALID);
g_hash_table_destroy (new_settings);
g_variant_unref (new_settings_dict);
priv->add_list = g_slist_append (priv->add_list, info); priv->add_list = g_slist_append (priv->add_list, info);
@@ -586,8 +575,7 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings,
GError **error) GError **error)
{ {
NMRemoteSettingsPrivate *priv; NMRemoteSettingsPrivate *priv;
char **my_failures = NULL; gboolean success;
gboolean ret;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (filenames != NULL, FALSE); g_return_val_if_fail (filenames != NULL, FALSE);
@@ -601,22 +589,14 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings,
return FALSE; return FALSE;
} }
if (!dbus_g_proxy_call (priv->proxy, "LoadConnections", error, if (!nmdbus_settings_call_load_connections_sync (priv->proxy,
G_TYPE_STRV, filenames, (const char * const *) filenames,
G_TYPE_INVALID, &success,
G_TYPE_BOOLEAN, &ret, failures,
G_TYPE_STRV, &my_failures, NULL, error))
G_TYPE_INVALID)) success = FALSE;
ret = FALSE;
if (failures) { return success;
if (my_failures && !*my_failures)
g_clear_pointer (&my_failures, g_free);
*failures = my_failures;
} else
g_strfreev (my_failures);
return ret;
} }
/** /**
@@ -648,11 +628,10 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings,
return FALSE; return FALSE;
} }
if (!dbus_g_proxy_call (priv->proxy, "ReloadConnections", error, if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success,
G_TYPE_INVALID, NULL, error))
G_TYPE_BOOLEAN, &success, success = FALSE;
G_TYPE_INVALID))
return FALSE;
return success; return success;
} }
@@ -663,14 +642,14 @@ typedef struct {
} SaveHostnameInfo; } SaveHostnameInfo;
static void static void
save_hostname_cb (DBusGProxy *proxy, save_hostname_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
SaveHostnameInfo *info = user_data; SaveHostnameInfo *info = user_data;
GError *error = NULL; GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); nmdbus_settings_call_save_hostname_finish (NMDBUS_SETTINGS (proxy), result, &error);
if (info->callback != NULL) if (info->callback != NULL)
info->callback (info->settings, error, info->callback_data); info->callback (info->settings, error, info->callback_data);
g_clear_error (&error); g_clear_error (&error);
@@ -713,12 +692,10 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings,
info->callback = callback; info->callback = callback;
info->callback_data = user_data; info->callback_data = user_data;
dbus_g_proxy_begin_call (priv->proxy, "SaveHostname", nmdbus_settings_call_save_hostname (priv->proxy,
save_hostname_cb, hostname ? hostname : "",
info, NULL,
g_free, save_hostname_cb, info);
G_TYPE_STRING, hostname ? hostname : "",
G_TYPE_INVALID);
return TRUE; return TRUE;
} }
@@ -866,7 +843,7 @@ init_dbus (NMObject *object)
NM_OBJECT_CLASS (nm_remote_settings_parent_class)->init_dbus (object); NM_OBJECT_CLASS (nm_remote_settings_parent_class)->init_dbus (object);
priv->proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_SETTINGS); priv->proxy = NMDBUS_SETTINGS (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_SETTINGS));
_nm_object_register_properties (object, _nm_object_register_properties (object,
NM_DBUS_INTERFACE_SETTINGS, NM_DBUS_INTERFACE_SETTINGS,
property_info); property_info);
@@ -961,6 +938,7 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
g_type_class_add_private (class, sizeof (NMRemoteSettingsPrivate)); g_type_class_add_private (class, sizeof (NMRemoteSettingsPrivate));
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_SETTINGS); _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_SETTINGS);
_nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_SETTINGS, NMDBUS_TYPE_SETTINGS_PROXY);
/* Virtual methods */ /* Virtual methods */
object_class->constructor = constructor; object_class->constructor = constructor;

View File

@@ -20,7 +20,6 @@
#include <config.h> #include <config.h>
#include <string.h> #include <string.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-glib-compat.h" #include "nm-glib-compat.h"
#include "nm-dbus-interface.h" #include "nm-dbus-interface.h"
@@ -28,32 +27,9 @@
#include "nm-enum-types.h" #include "nm-enum-types.h"
#include "nm-dbus-helpers.h" #include "nm-dbus-helpers.h"
#include "nm-simple-connection.h" #include "nm-simple-connection.h"
#include "nm-utils-private.h"
static void impl_secret_agent_get_secrets (NMSecretAgent *self, #include "nmdbus-secret-agent.h"
GHashTable *connection_hash, #include "nmdbus-agent-manager.h"
const char *connection_path,
const char *setting_name,
const char **hints,
guint32 flags,
DBusGMethodInvocation *context);
static void impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
const char *connection_path,
const char *setting_name,
DBusGMethodInvocation *context);
static void impl_secret_agent_save_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
DBusGMethodInvocation *context);
static void impl_secret_agent_delete_secrets (NMSecretAgent *self,
GHashTable *connection_hash,
const char *connection_path,
DBusGMethodInvocation *context);
#include "nm-secret-agent-glue.h"
static void nm_secret_agent_initable_iface_init (GInitableIface *iface); static void nm_secret_agent_initable_iface_init (GInitableIface *iface);
static void nm_secret_agent_async_initable_iface_init (GAsyncInitableIface *iface); static void nm_secret_agent_async_initable_iface_init (GAsyncInitableIface *iface);
@@ -69,17 +45,15 @@ typedef struct {
gboolean registering; gboolean registering;
NMSecretAgentCapabilities capabilities; NMSecretAgentCapabilities capabilities;
DBusGConnection *bus; GDBusConnection *bus;
gboolean private_bus; gboolean private_bus;
gboolean session_bus; gboolean session_bus;
DBusGProxy *dbus_proxy; NMDBusAgentManager *manager_proxy;
DBusGProxy *manager_proxy; NMDBusSecretAgent *dbus_secret_agent;
/* GetSecretsInfo structs of in-flight GetSecrets requests */ /* GetSecretsInfo structs of in-flight GetSecrets requests */
GSList *pending_gets; GSList *pending_gets;
char *nm_owner;
char *identifier; char *identifier;
gboolean auto_register; gboolean auto_register;
gboolean suppress_auto; gboolean suppress_auto;
@@ -109,36 +83,13 @@ nm_secret_agent_error_quark (void)
/*************************************************************/ /*************************************************************/
static const char *
get_nm_owner (NMSecretAgent *self)
{
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GError *error = NULL;
char *owner;
if (!priv->nm_owner) {
if (!dbus_g_proxy_call_with_timeout (priv->dbus_proxy,
"GetNameOwner", 2000, &error,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_STRING, &owner,
G_TYPE_INVALID))
return NULL;
priv->nm_owner = g_strdup (owner);
g_free (owner);
}
return priv->nm_owner;
}
static void static void
_internal_unregister (NMSecretAgent *self) _internal_unregister (NMSecretAgent *self)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
if (priv->registered) { if (priv->registered) {
dbus_g_connection_unregister_g_object (priv->bus, G_OBJECT (self)); g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (priv->dbus_secret_agent));
priv->registered = FALSE; priv->registered = FALSE;
priv->registering = FALSE; priv->registering = FALSE;
g_object_notify (G_OBJECT (self), NM_SECRET_AGENT_REGISTERED); g_object_notify (G_OBJECT (self), NM_SECRET_AGENT_REGISTERED);
@@ -148,7 +99,7 @@ _internal_unregister (NMSecretAgent *self)
typedef struct { typedef struct {
char *path; char *path;
char *setting_name; char *setting_name;
DBusGMethodInvocation *context; GDBusMethodInvocation *context;
} GetSecretsInfo; } GetSecretsInfo;
static void static void
@@ -178,61 +129,44 @@ should_auto_register (NMSecretAgent *self)
} }
static void static void
name_owner_changed (DBusGProxy *proxy, name_owner_changed (GObject *proxy,
const char *name, GParamSpec *pspec,
const char *old_owner,
const char *new_owner,
gpointer user_data) gpointer user_data)
{ {
NMSecretAgent *self = NM_SECRET_AGENT (user_data); NMSecretAgent *self = NM_SECRET_AGENT (user_data);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
gboolean old_owner_good = (old_owner && strlen (old_owner));
gboolean new_owner_good = (new_owner && strlen (new_owner));
GSList *iter; GSList *iter;
if (strcmp (name, NM_DBUS_SERVICE) == 0) { if (g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy)) != NULL) {
g_free (priv->nm_owner); if (should_auto_register (self))
priv->nm_owner = g_strdup (new_owner); nm_secret_agent_register_async (self, NULL, NULL, NULL);
} else {
/* Cancel any pending secrets requests */
for (iter = priv->pending_gets; iter; iter = g_slist_next (iter)) {
GetSecretsInfo *info = iter->data;
if (!old_owner_good && new_owner_good) { NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self,
/* NM appeared */ info->path,
if (should_auto_register (self)) info->setting_name);
nm_secret_agent_register_async (self, NULL, NULL, NULL);
} else if (old_owner_good && !new_owner_good) {
/* Cancel any pending secrets requests */
for (iter = priv->pending_gets; iter; iter = g_slist_next (iter)) {
GetSecretsInfo *info = iter->data;
NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self,
info->path,
info->setting_name);
}
g_slist_free (priv->pending_gets);
priv->pending_gets = NULL;
/* NM disappeared */
_internal_unregister (self);
} else if (old_owner_good && new_owner_good && strcmp (old_owner, new_owner)) {
/* Hmm, NM magically restarted */
_internal_unregister (self);
if (should_auto_register (self))
nm_secret_agent_register_async (self, NULL, NULL, NULL);
} }
g_slist_free (priv->pending_gets);
priv->pending_gets = NULL;
_internal_unregister (self);
} }
} }
static gboolean static gboolean
verify_sender (NMSecretAgent *self, verify_sender (NMSecretAgent *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
GError **error) GError **error)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
DBusConnection *bus;
char *sender;
const char *nm_owner; const char *nm_owner;
DBusError dbus_error; const char *sender;
uid_t sender_uid = G_MAXUINT; guint32 sender_uid;
gboolean allowed = FALSE; GVariant *ret;
GError *local = NULL;
g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (context != NULL, FALSE);
@@ -244,7 +178,7 @@ verify_sender (NMSecretAgent *self,
/* Verify that the sender is the same as NetworkManager's bus name owner. */ /* Verify that the sender is the same as NetworkManager's bus name owner. */
nm_owner = get_nm_owner (self); nm_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->manager_proxy));
if (!nm_owner) { if (!nm_owner) {
g_set_error_literal (error, g_set_error_literal (error,
NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR,
@@ -253,16 +187,7 @@ verify_sender (NMSecretAgent *self,
return FALSE; return FALSE;
} }
bus = dbus_g_connection_get_connection (priv->bus); sender = g_dbus_method_invocation_get_sender (context);
if (!bus) {
g_set_error_literal (error,
NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Failed to get DBus connection.");
return FALSE;
}
sender = dbus_g_method_get_sender (context);
if (!sender) { if (!sender) {
g_set_error_literal (error, g_set_error_literal (error,
NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR,
@@ -277,28 +202,41 @@ verify_sender (NMSecretAgent *self,
NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Request sender does not match NetworkManager bus name owner."); "Request sender does not match NetworkManager bus name owner.");
goto out; return FALSE;
} }
/* If we're connected to the session bus, then this must be a test program, /* If we're connected to the session bus, then this must be a test program,
* so skip the UID check. * so skip the UID check.
*/ */
if (priv->session_bus) { if (priv->session_bus)
allowed = TRUE; return TRUE;
goto out;
}
dbus_error_init (&dbus_error); /* Check the UID of the sender */
sender_uid = dbus_bus_get_unix_user (bus, sender, &dbus_error); ret = g_dbus_connection_call_sync (priv->bus,
if (dbus_error_is_set (&dbus_error)) { DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
"GetConnectionUnixUser",
g_variant_new ("(s)", sender),
G_VARIANT_TYPE ("(u)"),
G_DBUS_CALL_FLAGS_NONE, -1,
NULL, &local);
if (!ret) {
char *remote_error = g_dbus_error_get_remote_error (local);
g_dbus_error_strip_remote_error (local);
g_set_error (error, g_set_error (error,
NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Failed to get request unix user: (%s) %s.", "Failed to request unix user: (%s) %s.",
dbus_error.name, dbus_error.message); remote_error ? remote_error : "",
dbus_error_free (&dbus_error); local->message);
goto out; g_free (remote_error);
g_error_free (local);
return FALSE;
} }
g_variant_get (ret, "(u)", &sender_uid);
g_variant_unref (ret);
/* We only accept requests from NM, which always runs as root */ /* We only accept requests from NM, which always runs as root */
if (0 != sender_uid) { if (0 != sender_uid) {
@@ -306,36 +244,31 @@ verify_sender (NMSecretAgent *self,
NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
"Request sender is not root."); "Request sender is not root.");
goto out; return FALSE;
} }
allowed = TRUE; return TRUE;
out:
g_free (sender);
return allowed;
} }
static gboolean static gboolean
verify_request (NMSecretAgent *self, verify_request (NMSecretAgent *self,
DBusGMethodInvocation *context, GDBusMethodInvocation *context,
GHashTable *connection_hash, GVariant *connection_dict,
const char *connection_path, const char *connection_path,
NMConnection **out_connection, NMConnection **out_connection,
GError **error) GError **error)
{ {
NMConnection *connection = NULL; NMConnection *connection = NULL;
GVariant *connection_dict;
GError *local = NULL; GError *local = NULL;
if (!verify_sender (self, context, error)) if (!verify_sender (self, context, error))
return FALSE; return FALSE;
/* No connection? If the sender verified, then we allow the request */ /* No connection? If the sender verified, then we allow the request */
if (connection_hash == NULL) if (connection_dict == NULL)
return TRUE; return TRUE;
/* If we have a connection hash, we require a path too */ /* If we have a connection dictionary, we require a path too */
if (connection_path == NULL) { if (connection_path == NULL) {
g_set_error_literal (error, g_set_error_literal (error,
NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR,
@@ -346,9 +279,7 @@ verify_request (NMSecretAgent *self,
/* Make sure the given connection is valid */ /* Make sure the given connection is valid */
g_assert (out_connection); g_assert (out_connection);
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash);
connection = nm_simple_connection_new_from_dbus (connection_dict, &local); connection = nm_simple_connection_new_from_dbus (connection_dict, &local);
g_variant_unref (connection_dict);
if (connection) { if (connection) {
nm_connection_set_path (connection, connection_path); nm_connection_set_path (connection, connection_path);
*out_connection = connection; *out_connection = connection;
@@ -375,13 +306,10 @@ get_secrets_cb (NMSecretAgent *self,
GetSecretsInfo *info = user_data; GetSecretsInfo *info = user_data;
if (error) if (error)
dbus_g_method_return_error (info->context, error); g_dbus_method_invocation_return_gerror (info->context, error);
else { else {
GHashTable *secrets_hash; g_dbus_method_invocation_return_value (info->context,
g_variant_new ("(@a{sa{sv}})", secrets));
secrets_hash = _nm_utils_connection_dict_to_hash (secrets);
dbus_g_method_return (info->context, secrets_hash);
g_hash_table_unref (secrets_hash);
} }
/* Remove the request from internal tracking */ /* Remove the request from internal tracking */
@@ -390,12 +318,13 @@ get_secrets_cb (NMSecretAgent *self,
static void static void
impl_secret_agent_get_secrets (NMSecretAgent *self, impl_secret_agent_get_secrets (NMSecretAgent *self,
GHashTable *connection_hash, GDBusMethodInvocation *context,
GVariant *connection_dict,
const char *connection_path, const char *connection_path,
const char *setting_name, const char *setting_name,
const char **hints, const char * const *hints,
guint32 flags, guint flags,
DBusGMethodInvocation *context) gpointer user_data)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GError *error = NULL; GError *error = NULL;
@@ -403,9 +332,8 @@ impl_secret_agent_get_secrets (NMSecretAgent *self,
GetSecretsInfo *info; GetSecretsInfo *info;
/* Make sure the request comes from NetworkManager and is valid */ /* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) { if (!verify_request (self, context, connection_dict, connection_path, &connection, &error)) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
return; return;
} }
@@ -419,7 +347,7 @@ impl_secret_agent_get_secrets (NMSecretAgent *self,
connection, connection,
connection_path, connection_path,
setting_name, setting_name,
hints, (const char **) hints,
flags, flags,
get_secrets_cb, get_secrets_cb,
info); info);
@@ -443,9 +371,10 @@ find_get_secrets_info (GSList *list, const char *path, const char *setting_name)
static void static void
impl_secret_agent_cancel_get_secrets (NMSecretAgent *self, impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
GDBusMethodInvocation *context,
const char *connection_path, const char *connection_path,
const char *setting_name, const char *setting_name,
DBusGMethodInvocation *context) gpointer user_data)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GError *error = NULL; GError *error = NULL;
@@ -453,19 +382,16 @@ impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
/* Make sure the request comes from NetworkManager and is valid */ /* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, NULL, NULL, NULL, &error)) { if (!verify_request (self, context, NULL, NULL, NULL, &error)) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
return; return;
} }
info = find_get_secrets_info (priv->pending_gets, connection_path, setting_name); info = find_get_secrets_info (priv->pending_gets, connection_path, setting_name);
if (!info) { if (!info) {
g_set_error_literal (&error, g_dbus_method_invocation_return_error (context,
NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR,
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
"No secrets request in progress for this connection."); "No secrets request in progress for this connection.");
dbus_g_method_return_error (context, error);
g_clear_error (&error);
return; return;
} }
@@ -473,7 +399,7 @@ impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self, NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self,
info->path, info->path,
info->setting_name); info->setting_name);
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
} }
static void static void
@@ -482,27 +408,27 @@ save_secrets_cb (NMSecretAgent *self,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
DBusGMethodInvocation *context = user_data; GDBusMethodInvocation *context = user_data;
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
else else
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
} }
static void static void
impl_secret_agent_save_secrets (NMSecretAgent *self, impl_secret_agent_save_secrets (NMSecretAgent *self,
GHashTable *connection_hash, GDBusMethodInvocation *context,
GVariant *connection_dict,
const char *connection_path, const char *connection_path,
DBusGMethodInvocation *context) gpointer user_data)
{ {
GError *error = NULL; GError *error = NULL;
NMConnection *connection = NULL; NMConnection *connection = NULL;
/* Make sure the request comes from NetworkManager and is valid */ /* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) { if (!verify_request (self, context, connection_dict, connection_path, &connection, &error)) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
return; return;
} }
@@ -520,27 +446,27 @@ delete_secrets_cb (NMSecretAgent *self,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
DBusGMethodInvocation *context = user_data; GDBusMethodInvocation *context = user_data;
if (error) if (error)
dbus_g_method_return_error (context, error); g_dbus_method_invocation_return_gerror (context, error);
else else
dbus_g_method_return (context); g_dbus_method_invocation_return_value (context, NULL);
} }
static void static void
impl_secret_agent_delete_secrets (NMSecretAgent *self, impl_secret_agent_delete_secrets (NMSecretAgent *self,
GHashTable *connection_hash, GDBusMethodInvocation *context,
GVariant *connection_dict,
const char *connection_path, const char *connection_path,
DBusGMethodInvocation *context) gpointer user_data)
{ {
GError *error = NULL; GError *error = NULL;
NMConnection *connection = NULL; NMConnection *connection = NULL;
/* Make sure the request comes from NetworkManager and is valid */ /* Make sure the request comes from NetworkManager and is valid */
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) { if (!verify_request (self, context, connection_dict, connection_path, &connection, &error)) {
dbus_g_method_return_error (context, error); g_dbus_method_invocation_take_error (context, error);
g_clear_error (&error);
return; return;
} }
@@ -559,7 +485,9 @@ check_nm_running (NMSecretAgent *self, GError **error)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
if (priv->nm_owner || priv->private_bus) if (priv->private_bus)
return TRUE;
if (g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->manager_proxy)))
return TRUE; return TRUE;
g_set_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, g_set_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
@@ -613,29 +541,25 @@ nm_secret_agent_register (NMSecretAgent *self,
priv->suppress_auto = FALSE; priv->suppress_auto = FALSE;
/* Export our secret agent interface before registering with the manager */ /* Export our secret agent interface before registering with the manager */
dbus_g_connection_register_g_object (priv->bus, if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_secret_agent),
NM_DBUS_PATH_SECRET_AGENT, priv->bus,
G_OBJECT (self)); NM_DBUS_PATH_SECRET_AGENT,
error))
return FALSE;
priv->registering = TRUE; priv->registering = TRUE;
if (dbus_g_proxy_call_with_timeout (priv->manager_proxy, if (nmdbus_agent_manager_call_register_with_capabilities_sync (priv->manager_proxy,
"RegisterWithCapabilities", priv->identifier,
5000, NULL, priv->capabilities,
G_TYPE_STRING, priv->identifier, cancellable, NULL))
G_TYPE_UINT, priv->capabilities,
G_TYPE_INVALID,
G_TYPE_INVALID))
goto success; goto success;
/* Might be an old NetworkManager that doesn't support capabilities; /* Might be an old NetworkManager that doesn't support capabilities;
* fall back to old Register() method instead. * fall back to old Register() method instead.
*/ */
if (dbus_g_proxy_call_with_timeout (priv->manager_proxy, if (nmdbus_agent_manager_call_register_sync (priv->manager_proxy,
"Register", priv->identifier,
5000, error, cancellable, NULL))
G_TYPE_STRING, priv->identifier,
G_TYPE_INVALID,
G_TYPE_INVALID))
goto success; goto success;
/* Failure */ /* Failure */
@@ -675,24 +599,27 @@ reg_result (NMSecretAgent *self, GSimpleAsyncResult *simple, GError *error)
} }
static void static void
reg_request_cb (DBusGProxy *proxy, reg_request_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = user_data; GSimpleAsyncResult *simple = user_data;
NMSecretAgent *self; NMSecretAgent *self;
NMSecretAgentPrivate *priv;
GError *error = NULL; GError *error = NULL;
self = NM_SECRET_AGENT (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); self = NM_SECRET_AGENT (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
g_object_unref (self); /* drop extra ref added by get_source_object() */ g_object_unref (self); /* drop extra ref added by get_source_object() */
priv = NM_SECRET_AGENT_GET_PRIVATE (self);
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); nmdbus_agent_manager_call_register_finish (NMDBUS_AGENT_MANAGER (proxy), result, &error);
reg_result (self, simple, error); reg_result (self, simple, error);
g_clear_error (&error);
} }
static void static void
reg_with_caps_cb (DBusGProxy *proxy, reg_with_caps_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple = user_data; GSimpleAsyncResult *simple = user_data;
@@ -703,7 +630,7 @@ reg_with_caps_cb (DBusGProxy *proxy,
g_object_unref (self); /* drop extra ref added by get_source_object() */ g_object_unref (self); /* drop extra ref added by get_source_object() */
priv = NM_SECRET_AGENT_GET_PRIVATE (self); priv = NM_SECRET_AGENT_GET_PRIVATE (self);
if (dbus_g_proxy_end_call (proxy, call, NULL, G_TYPE_INVALID)) { if (nmdbus_agent_manager_call_register_with_capabilities_finish (NMDBUS_AGENT_MANAGER (proxy), result, NULL)) {
reg_result (self, simple, NULL); reg_result (self, simple, NULL);
return; return;
} }
@@ -711,14 +638,9 @@ reg_with_caps_cb (DBusGProxy *proxy,
/* Might be an old NetworkManager that doesn't support capabilities; /* Might be an old NetworkManager that doesn't support capabilities;
* fall back to old Register() method instead. * fall back to old Register() method instead.
*/ */
dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy, nmdbus_agent_manager_call_register (priv->manager_proxy,
"Register", priv->identifier,
reg_request_cb, NULL, reg_request_cb, simple);
self,
NULL,
5000,
G_TYPE_STRING, priv->identifier,
G_TYPE_INVALID);
} }
/** /**
@@ -771,23 +693,25 @@ nm_secret_agent_register_async (NMSecretAgent *self,
return; return;
} }
priv->suppress_auto = FALSE;
/* Export our secret agent interface before registering with the manager */ /* Export our secret agent interface before registering with the manager */
dbus_g_connection_register_g_object (priv->bus, if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_secret_agent),
NM_DBUS_PATH_SECRET_AGENT, priv->bus,
G_OBJECT (self)); NM_DBUS_PATH_SECRET_AGENT,
&error)) {
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
priv->suppress_auto = FALSE;
priv->registering = TRUE; priv->registering = TRUE;
dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy,
"RegisterWithCapabilities", nmdbus_agent_manager_call_register_with_capabilities (priv->manager_proxy,
reg_with_caps_cb, priv->identifier,
simple, priv->capabilities,
NULL, NULL,
5000, reg_with_caps_cb, simple);
G_TYPE_STRING, priv->identifier,
G_TYPE_UINT, priv->capabilities,
G_TYPE_INVALID);
} }
/** /**
@@ -844,25 +768,16 @@ nm_secret_agent_unregister (NMSecretAgent *self,
g_return_val_if_fail (priv->bus != NULL, FALSE); g_return_val_if_fail (priv->bus != NULL, FALSE);
g_return_val_if_fail (priv->manager_proxy != NULL, FALSE); g_return_val_if_fail (priv->manager_proxy != NULL, FALSE);
if (!check_nm_running (self, error))
return FALSE;
priv->suppress_auto = TRUE; priv->suppress_auto = TRUE;
success = dbus_g_proxy_call_with_timeout (priv->manager_proxy, success = nmdbus_agent_manager_call_unregister_sync (priv->manager_proxy, cancellable, error);
"Unregister",
5000, error,
G_TYPE_INVALID,
G_TYPE_INVALID);
_internal_unregister (self); _internal_unregister (self);
return success; return success;
} }
static void static void
unregister_cb (DBusGProxy *proxy, unregister_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
DBusGProxyCall *call,
gpointer user_data)
{ {
GSimpleAsyncResult *simple = user_data; GSimpleAsyncResult *simple = user_data;
NMSecretAgent *self; NMSecretAgent *self;
@@ -873,7 +788,8 @@ unregister_cb (DBusGProxy *proxy,
_internal_unregister (self); _internal_unregister (self);
if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) if (nmdbus_agent_manager_call_unregister_finish (NMDBUS_AGENT_MANAGER (proxy),
result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE); g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else else
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (simple, error);
@@ -926,13 +842,8 @@ nm_secret_agent_unregister_async (NMSecretAgent *self,
priv->suppress_auto = TRUE; priv->suppress_auto = TRUE;
dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy, nmdbus_agent_manager_call_unregister (priv->manager_proxy, cancellable,
"Unregister", unregister_cb, simple);
unregister_cb,
simple,
NULL,
5000,
G_TYPE_INVALID);
} }
/** /**
@@ -1108,42 +1019,30 @@ validate_identifier (const char *identifier)
static void static void
nm_secret_agent_init (NMSecretAgent *self) nm_secret_agent_init (NMSecretAgent *self)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
priv->dbus_secret_agent = nmdbus_secret_agent_skeleton_new ();
_nm_dbus_bind_properties (self, priv->dbus_secret_agent);
_nm_dbus_bind_methods (self, priv->dbus_secret_agent,
"GetSecrets", impl_secret_agent_get_secrets,
"CancelGetSecrets", impl_secret_agent_cancel_get_secrets,
"DeleteSecrets", impl_secret_agent_delete_secrets,
"SaveSecrets", impl_secret_agent_save_secrets,
NULL);
} }
static void static void
init_common (NMSecretAgent *self) init_common (NMSecretAgent *self)
{ {
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
DBusGConnection *session_bus;
session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
if (priv->bus == session_bus)
priv->session_bus = TRUE;
if (session_bus)
dbus_g_connection_unref (session_bus);
priv->private_bus = _nm_dbus_is_connection_private (priv->bus); priv->private_bus = _nm_dbus_is_connection_private (priv->bus);
if (priv->private_bus == FALSE) { if (priv->private_bus == FALSE) {
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus, priv->session_bus = _nm_dbus_bus_type () == G_BUS_TYPE_SESSION;
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->dbus_proxy);
dbus_g_object_register_marshaller (g_cclosure_marshal_generic, g_signal_connect (priv->manager_proxy, "notify::g-name-owner",
G_TYPE_NONE, G_CALLBACK (name_owner_changed), self);
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->dbus_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
self, NULL);
get_nm_owner (self);
} }
} }
@@ -1152,17 +1051,19 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{ {
NMSecretAgent *self = NM_SECRET_AGENT (initable); NMSecretAgent *self = NM_SECRET_AGENT (initable);
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
GDBusProxy *proxy;
priv->bus = _nm_dbus_new_connection (cancellable, error); priv->bus = _nm_dbus_new_connection (cancellable, error);
if (!priv->bus) if (!priv->bus)
return FALSE; return FALSE;
priv->manager_proxy = _nm_dbus_new_proxy_for_connection (priv->bus, proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
NM_DBUS_PATH_AGENT_MANAGER, NM_DBUS_PATH_AGENT_MANAGER,
NM_DBUS_INTERFACE_AGENT_MANAGER, NM_DBUS_INTERFACE_AGENT_MANAGER,
cancellable, error); cancellable, error);
if (!priv->manager_proxy) if (!proxy)
return FALSE; return FALSE;
priv->manager_proxy = NMDBUS_AGENT_MANAGER (proxy);
init_common (self); init_common (self);
@@ -1209,13 +1110,15 @@ init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
{ {
NMSecretAgentInitData *init_data = user_data; NMSecretAgentInitData *init_data = user_data;
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (init_data->self); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (init_data->self);
GDBusProxy *proxy;
GError *error = NULL; GError *error = NULL;
priv->manager_proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error); proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error);
if (!priv->manager_proxy) { if (!proxy) {
init_async_complete (init_data, error); init_async_complete (init_data, error);
return; return;
} }
priv->manager_proxy = NMDBUS_AGENT_MANAGER (proxy);
init_common (init_data->self); init_common (init_data->self);
@@ -1341,21 +1244,17 @@ dispose (GObject *object)
if (priv->registered) if (priv->registered)
nm_secret_agent_unregister_async (self, NULL, NULL, NULL); nm_secret_agent_unregister_async (self, NULL, NULL, NULL);
g_free (priv->identifier); g_clear_pointer (&priv->identifier, g_free);
priv->identifier = NULL;
g_free (priv->nm_owner);
priv->nm_owner = NULL;
while (priv->pending_gets) while (priv->pending_gets)
get_secrets_info_finalize (self, priv->pending_gets->data); get_secrets_info_finalize (self, priv->pending_gets->data);
g_clear_object (&priv->dbus_proxy); g_signal_handlers_disconnect_matched (priv->dbus_secret_agent, G_SIGNAL_MATCH_DATA,
g_clear_object (&priv->manager_proxy); 0, 0, NULL, NULL, self);
g_object_unref (priv->dbus_secret_agent);
if (priv->bus) { g_clear_object (&priv->manager_proxy);
dbus_g_connection_unref (priv->bus); g_clear_object (&priv->bus);
priv->bus = NULL;
}
G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object); G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object);
} }
@@ -1446,12 +1345,12 @@ nm_secret_agent_class_init (NMSecretAgentClass *class)
G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class), _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_AGENT_MANAGER,
&dbus_glib_nm_secret_agent_object_info); NMDBUS_TYPE_AGENT_MANAGER_PROXY);
dbus_g_error_domain_register (NM_SECRET_AGENT_ERROR, _nm_dbus_register_error_domain (NM_SECRET_AGENT_ERROR,
NM_DBUS_INTERFACE_SECRET_AGENT, NM_DBUS_INTERFACE_SECRET_AGENT,
NM_TYPE_SECRET_AGENT_ERROR); NM_TYPE_SECRET_AGENT_ERROR);
} }
static void static void

View File

@@ -25,6 +25,9 @@
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-object-private.h" #include "nm-object-private.h"
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "nm-dbus-helpers.h"
#include "nmdbus-vpn-connection.h"
G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION)
@@ -93,9 +96,9 @@ nm_vpn_connection_get_vpn_state (NMVpnConnection *vpn)
} }
static void static void
vpn_state_changed_proxy (DBusGProxy *proxy, vpn_state_changed_proxy (NMDBusVpnConnection *proxy,
NMVpnConnectionState vpn_state, guint vpn_state,
NMVpnConnectionStateReason reason, guint reason,
gpointer user_data) gpointer user_data)
{ {
NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); NMVpnConnection *connection = NM_VPN_CONNECTION (user_data);
@@ -127,7 +130,7 @@ init_dbus (NMObject *object)
{ NM_VPN_CONNECTION_VPN_STATE, &priv->vpn_state }, { NM_VPN_CONNECTION_VPN_STATE, &priv->vpn_state },
{ NULL }, { NULL },
}; };
DBusGProxy *proxy; GDBusProxy *proxy;
NM_OBJECT_CLASS (nm_vpn_connection_parent_class)->init_dbus (object); NM_OBJECT_CLASS (nm_vpn_connection_parent_class)->init_dbus (object);
@@ -136,16 +139,8 @@ init_dbus (NMObject *object)
property_info); property_info);
proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_VPN_CONNECTION); proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_VPN_CONNECTION);
dbus_g_object_register_marshaller (g_cclosure_marshal_generic, g_signal_connect (proxy, "vpn-state-changed",
G_TYPE_NONE, G_CALLBACK (vpn_state_changed_proxy), object);
G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (proxy, "VpnStateChanged", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (proxy,
"VpnStateChanged",
G_CALLBACK (vpn_state_changed_proxy),
object,
NULL);
} }
static void static void
@@ -188,6 +183,8 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class)
g_type_class_add_private (connection_class, sizeof (NMVpnConnectionPrivate)); g_type_class_add_private (connection_class, sizeof (NMVpnConnectionPrivate));
_nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_VPN_CONNECTION); _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_VPN_CONNECTION);
_nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_VPN_CONNECTION,
NMDBUS_TYPE_VPN_CONNECTION_PROXY);
/* virtual methods */ /* virtual methods */
object_class->get_property = get_property; object_class->get_property = get_property;

View File

@@ -26,7 +26,6 @@
#include "nm-vpn-plugin-utils.h" #include "nm-vpn-plugin-utils.h"
#include "nm-vpn-plugin.h" #include "nm-vpn-plugin.h"
#include "nm-core-internal.h" #include "nm-core-internal.h"
#include "nm-dbus-glib-types.h"
#define DATA_KEY_TAG "DATA_KEY=" #define DATA_KEY_TAG "DATA_KEY="
#define DATA_VAL_TAG "DATA_VAL=" #define DATA_VAL_TAG "DATA_VAL="

View File

@@ -28,48 +28,10 @@
#include "nm-vpn-plugin.h" #include "nm-vpn-plugin.h"
#include "nm-enum-types.h" #include "nm-enum-types.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-utils-private.h"
#include "nm-connection.h" #include "nm-connection.h"
#include "nm-dbus-helpers.h"
static gboolean impl_vpn_plugin_connect (NMVpnPlugin *plugin, #include "nmdbus-vpn-plugin.h"
GHashTable *connection,
GError **error);
static gboolean impl_vpn_plugin_connect_interactive (NMVpnPlugin *plugin,
GHashTable *connection,
GHashTable *details,
GError **error);
static gboolean impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin,
GHashTable *connection,
char **service_name,
GError **err);
static gboolean impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin,
GHashTable *connection,
GError **err);
static gboolean impl_vpn_plugin_disconnect (NMVpnPlugin *plugin,
GError **err);
static gboolean impl_vpn_plugin_set_config (NMVpnPlugin *plugin,
GHashTable *config,
GError **err);
static gboolean impl_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
GHashTable *config,
GError **err);
static gboolean impl_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin,
GHashTable *config,
GError **err);
static gboolean impl_vpn_plugin_set_failure (NMVpnPlugin *plugin,
char *reason,
GError **err);
#include "nm-vpn-plugin-glue.h"
#define NM_VPN_PLUGIN_QUIT_TIMER 20 #define NM_VPN_PLUGIN_QUIT_TIMER 20
@@ -83,7 +45,8 @@ typedef struct {
NMVpnServiceState state; NMVpnServiceState state;
/* DBUS-y stuff */ /* DBUS-y stuff */
DBusGConnection *connection; GDBusConnection *connection;
NMDBusVpnPlugin *dbus_vpn_plugin;
char *dbus_service_name; char *dbus_service_name;
/* Temporary stuff */ /* Temporary stuff */
@@ -97,7 +60,7 @@ typedef struct {
gboolean has_ip6, got_ip6; gboolean has_ip6, got_ip6;
/* Config stuff copied from config to ip4config */ /* Config stuff copied from config to ip4config */
GValue banner, tundev, gateway, mtu; char *banner, *tundev, *gateway, *mtu;
} NMVpnPluginPrivate; } NMVpnPluginPrivate;
#define NM_VPN_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_PLUGIN, NMVpnPluginPrivate)) #define NM_VPN_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_PLUGIN, NMVpnPluginPrivate))
@@ -142,27 +105,31 @@ nm_vpn_plugin_error_quark (void)
static void static void
nm_vpn_plugin_set_connection (NMVpnPlugin *plugin, nm_vpn_plugin_set_connection (NMVpnPlugin *plugin,
DBusGConnection *connection) GDBusConnection *connection)
{ {
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
if (priv->connection) g_clear_object (&priv->connection);
dbus_g_connection_unref (priv->connection);
priv->connection = connection; priv->connection = g_object_ref (connection);
} }
DBusGConnection * /**
* nm_vpn_plugin_get_connection:
*
* Returns: (transfer full):
*/
GDBusConnection *
nm_vpn_plugin_get_connection (NMVpnPlugin *plugin) nm_vpn_plugin_get_connection (NMVpnPlugin *plugin)
{ {
DBusGConnection *connection; GDBusConnection *connection;
g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), NULL); g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), NULL);
connection = NM_VPN_PLUGIN_GET_PRIVATE (plugin)->connection; connection = NM_VPN_PLUGIN_GET_PRIVATE (plugin)->connection;
if (connection) if (connection)
dbus_g_connection_ref (connection); g_object_ref (connection);
return connection; return connection;
} }
@@ -303,60 +270,46 @@ schedule_fail_stop (NMVpnPlugin *plugin)
priv->fail_stop_id = g_idle_add (fail_stop, plugin); priv->fail_stop_id = g_idle_add (fail_stop, plugin);
} }
static void
_g_value_set (GValue *dst, GValue *src)
{
if (src) {
GType type = G_VALUE_TYPE (src);
if (G_IS_VALUE (dst))
g_value_unset (dst);
g_value_init (dst, type);
g_value_copy (src, dst);
} else if (G_IS_VALUE (dst))
g_value_unset (dst);
}
void void
nm_vpn_plugin_set_config (NMVpnPlugin *plugin, nm_vpn_plugin_set_config (NMVpnPlugin *plugin,
GHashTable *config) GVariant *config)
{ {
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
GValue *val;
g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); g_return_if_fail (NM_IS_VPN_PLUGIN (plugin));
g_return_if_fail (config != NULL); g_return_if_fail (config != NULL);
priv->got_config = TRUE; priv->got_config = TRUE;
val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP4); g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP4, "b", &priv->has_ip4);
if (val && g_value_get_boolean (val)) g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP6, "b", &priv->has_ip6);
priv->has_ip4 = TRUE;
val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP6);
if (val && g_value_get_boolean (val))
priv->has_ip6 = TRUE;
g_warn_if_fail (priv->has_ip4 || priv->has_ip6); g_warn_if_fail (priv->has_ip4 || priv->has_ip6);
/* Record the items that need to also be inserted into the /* Record the items that need to also be inserted into the
* ip4config, for compatibility with older daemons. * ip4config, for compatibility with older daemons.
*/ */
_g_value_set (&priv->banner, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER)); g_clear_pointer (&priv->banner, g_free);
_g_value_set (&priv->tundev, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_TUNDEV)); g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER, "&s", &priv->banner);
_g_value_set (&priv->gateway, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY)); g_clear_pointer (&priv->tundev, g_free);
_g_value_set (&priv->mtu, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_MTU)); g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_TUNDEV, "&s", &priv->tundev);
g_clear_pointer (&priv->gateway, g_free);
g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, "&s", &priv->gateway);
g_clear_pointer (&priv->mtu, g_free);
g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_MTU, "&s", &priv->mtu);
g_signal_emit (plugin, signals[CONFIG], 0, config); g_signal_emit (plugin, signals[CONFIG], 0, config);
} }
void void
nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
GHashTable *ip4_config) GVariant *ip4_config)
{ {
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
GHashTable *combined_config; GVariant *combined_config;
GHashTableIter iter; GVariantBuilder builder;
gpointer key, value; GVariantIter iter;
const char *key, *value;
g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); g_return_if_fail (NM_IS_VPN_PLUGIN (plugin));
g_return_if_fail (ip4_config != NULL); g_return_if_fail (ip4_config != NULL);
@@ -376,22 +329,24 @@ nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
* being emitted. So just copy all of that data into the ip4 * being emitted. So just copy all of that data into the ip4
* config too. * config too.
*/ */
combined_config = g_hash_table_new (g_str_hash, g_str_equal); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
g_hash_table_iter_init (&iter, ip4_config); g_variant_iter_init (&iter, ip4_config);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_variant_iter_next (&iter, "{&s&s}", &key, &value))
g_hash_table_insert (combined_config, key, value); g_variant_builder_add (&builder, "{ss}", key, value);
if (G_VALUE_TYPE (&priv->banner) != G_TYPE_INVALID) if (priv->banner)
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_BANNER, &priv->banner); g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_BANNER, &priv->banner);
if (G_VALUE_TYPE (&priv->tundev) != G_TYPE_INVALID) if (priv->tundev)
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, &priv->tundev); g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, &priv->tundev);
if (G_VALUE_TYPE (&priv->gateway) != G_TYPE_INVALID) if (priv->gateway)
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, &priv->gateway); g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, &priv->gateway);
if (G_VALUE_TYPE (&priv->mtu) != G_TYPE_INVALID) if (priv->mtu)
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_MTU, &priv->mtu); g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_MTU, &priv->mtu);
combined_config = g_variant_builder_end (&builder);
g_variant_ref_sink (combined_config);
g_signal_emit (plugin, signals[IP4_CONFIG], 0, combined_config); g_signal_emit (plugin, signals[IP4_CONFIG], 0, combined_config);
g_hash_table_destroy (combined_config); g_variant_unref (combined_config);
if ( priv->has_ip4 == priv->got_ip4 if ( priv->has_ip4 == priv->got_ip4
&& priv->has_ip6 == priv->got_ip6) && priv->has_ip6 == priv->got_ip6)
@@ -400,7 +355,7 @@ nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
void void
nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin,
GHashTable *ip6_config) GVariant *ip6_config)
{ {
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
@@ -433,58 +388,63 @@ connect_timer_start (NMVpnPlugin *plugin)
connect_timer_removed); connect_timer_removed);
} }
static gboolean static void
_connect_generic (NMVpnPlugin *plugin, _connect_generic (NMVpnPlugin *plugin,
GHashTable *properties, GDBusMethodInvocation *context,
GHashTable *details, GVariant *properties,
GError **error) GVariant *details)
{ {
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
NMVpnPluginClass *vpn_class = NM_VPN_PLUGIN_GET_CLASS (plugin); NMVpnPluginClass *vpn_class = NM_VPN_PLUGIN_GET_CLASS (plugin);
GVariant *properties_dict;
NMConnection *connection; NMConnection *connection;
gboolean success = FALSE; gboolean success = FALSE;
GError *local = NULL; GError *error = NULL;
if (priv->state != NM_VPN_SERVICE_STATE_STOPPED && if (priv->state != NM_VPN_SERVICE_STATE_STOPPED &&
priv->state != NM_VPN_SERVICE_STATE_INIT) { priv->state != NM_VPN_SERVICE_STATE_INIT) {
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_WRONG_STATE, g_dbus_method_invocation_return_error (context,
"Could not start connection: wrong plugin state %d", NM_VPN_PLUGIN_ERROR,
priv->state); NM_VPN_PLUGIN_ERROR_WRONG_STATE,
return FALSE; "Could not start connection: wrong plugin state %d",
priv->state);
return;
} }
properties_dict = _nm_utils_connection_hash_to_dict (properties); connection = nm_simple_connection_new_from_dbus (properties, &error);
connection = nm_simple_connection_new_from_dbus (properties_dict, &local);
g_variant_unref (properties_dict);
if (!connection) { if (!connection) {
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, g_dbus_method_invocation_return_error (context,
"Invalid connection: (%d) %s", NM_VPN_PLUGIN_ERROR,
local->code, local->message); NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
g_clear_error (&local); "Invalid connection: (%d) %s",
return FALSE; error->code, error->message);
g_clear_error (&error);
} }
priv->interactive = FALSE; priv->interactive = FALSE;
if (details && !vpn_class->connect_interactive) { if (details && !vpn_class->connect_interactive) {
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, g_dbus_method_invocation_return_error (context,
"Plugin does not implement ConnectInteractive()"); NM_VPN_PLUGIN_ERROR,
return FALSE; NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED,
"Plugin does not implement ConnectInteractive()");
return;
} }
nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING);
if (details) { if (details) {
priv->interactive = TRUE; priv->interactive = TRUE;
success = vpn_class->connect_interactive (plugin, connection, details, error); success = vpn_class->connect_interactive (plugin, connection, details, &error);
} else } else
success = vpn_class->connect (plugin, connection, error); success = vpn_class->connect (plugin, connection, &error);
if (success) { if (success) {
g_dbus_method_invocation_return_value (context, NULL);
/* Add a timer to make sure we do not wait indefinitely for the successful connect. */ /* Add a timer to make sure we do not wait indefinitely for the successful connect. */
connect_timer_start (plugin); connect_timer_start (plugin);
} else { } else {
g_dbus_method_invocation_take_error (context, error);
/* Stop the plugin from an idle handler so that the Connect /* Stop the plugin from an idle handler so that the Connect
* method return gets sent before the STOP StateChanged signal. * method return gets sent before the STOP StateChanged signal.
*/ */
@@ -492,126 +452,125 @@ _connect_generic (NMVpnPlugin *plugin,
} }
g_object_unref (connection); g_object_unref (connection);
return success;
} }
static gboolean static void
impl_vpn_plugin_connect (NMVpnPlugin *plugin, impl_vpn_plugin_connect (NMVpnPlugin *plugin,
GHashTable *connection, GDBusMethodInvocation *context,
GError **error) GVariant *connection,
gpointer user_data)
{ {
return _connect_generic (plugin, connection, NULL, error); _connect_generic (plugin, context, connection, NULL);
} }
static gboolean static void
impl_vpn_plugin_connect_interactive (NMVpnPlugin *plugin, impl_vpn_plugin_connect_interactive (NMVpnPlugin *plugin,
GHashTable *connection, GDBusMethodInvocation *context,
GHashTable *details, GVariant *connection,
GError **error) GVariant *details,
gpointer user_data)
{ {
return _connect_generic (plugin, connection, details, error); _connect_generic (plugin, context, connection, details);
} }
/***************************************************************/ /***************************************************************/
static gboolean static void
impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin, impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin,
GHashTable *properties, GDBusMethodInvocation *context,
char **setting_name, GVariant *properties,
GError **err) gpointer user_data)
{ {
gboolean ret = FALSE;
GVariant *properties_dict;
NMConnection *connection; NMConnection *connection;
char *sn = NULL; char *setting_name;
GError *ns_err = NULL; gboolean needed;
gboolean needed = FALSE; GError *error = NULL;
GError *cnfh_err = NULL;
g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE); connection = nm_simple_connection_new_from_dbus (properties, &error);
g_return_val_if_fail (properties != NULL, FALSE);
properties_dict = _nm_utils_connection_hash_to_dict (properties);
connection = nm_simple_connection_new_from_dbus (properties_dict, &cnfh_err);
g_variant_unref (properties_dict);
if (!connection) { if (!connection) {
g_set_error (err, g_dbus_method_invocation_return_error (context,
NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
"The connection was invalid: '%s' / '%s' invalid: %d.", "The connection was invalid: '%s' / '%s' invalid: %d.",
g_type_name (nm_setting_lookup_type_by_quark (cnfh_err->domain)), g_type_name (nm_setting_lookup_type_by_quark (error->domain)),
cnfh_err->message, cnfh_err->code); error->message, error->code);
g_error_free (cnfh_err); g_error_free (error);
return FALSE; return;
} }
if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets) { if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets) {
*setting_name = ""; g_dbus_method_invocation_return_value (context,
ret = TRUE; g_variant_new ("(s)", ""));
goto out; return;
} }
needed = NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets (plugin, connection, &sn, &ns_err); needed = NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets (plugin, connection, &setting_name, &error);
if (ns_err) { if (error) {
*err = g_error_copy (ns_err); g_dbus_method_invocation_take_error (context, error);
g_error_free (ns_err); return;
goto out;
} }
ret = TRUE;
if (needed) { if (needed) {
g_assert (sn); g_assert (setting_name);
*setting_name = g_strdup (sn); g_dbus_method_invocation_return_value (context,
g_variant_new ("(s)", setting_name));
g_free (setting_name);
} else { } else {
/* No secrets required */ /* No secrets required */
*setting_name = g_strdup (""); g_dbus_method_invocation_return_value (context,
g_variant_new ("(s)", ""));
} }
out:
return ret;
} }
static gboolean static void
impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin,
GHashTable *properties, GDBusMethodInvocation *context,
GError **error) GVariant *properties,
gpointer user_data)
{ {
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
GVariant *properties_dict;
NMConnection *connection; NMConnection *connection;
GError *local = NULL; GError *error = NULL;
gboolean success; gboolean success;
if (priv->state != NM_VPN_SERVICE_STATE_STARTING) { if (priv->state != NM_VPN_SERVICE_STATE_STARTING) {
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_WRONG_STATE, g_dbus_method_invocation_return_error (context,
"Could not accept new secrets: wrong plugin state %d", NM_VPN_PLUGIN_ERROR,
priv->state); NM_VPN_PLUGIN_ERROR_WRONG_STATE,
return FALSE; "Could not accept new secrets: wrong plugin state %d",
priv->state);
return;
} }
properties_dict = _nm_utils_connection_hash_to_dict (properties); connection = nm_simple_connection_new_from_dbus (properties, &error);
connection = nm_simple_connection_new_from_dbus (properties_dict, &local);
g_variant_unref (properties_dict);
if (!connection) { if (!connection) {
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, g_dbus_method_invocation_return_error (context,
"Invalid connection: (%d) %s", NM_VPN_PLUGIN_ERROR,
local->code, local->message); NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
g_clear_error (&local); "Invalid connection: (%d) %s",
return FALSE; error->code, error->message);
g_clear_error (&error);
return;
} }
if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets) { if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets) {
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, g_dbus_method_invocation_return_error (context,
"Could not accept new secrets: plugin cannot process interactive secrets"); NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED,
"Could not accept new secrets: plugin cannot process interactive secrets");
g_object_unref (connection); g_object_unref (connection);
return FALSE; return;
} }
success = NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets (plugin, connection, error); success = NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets (plugin, connection, &error);
if (success) { if (success) {
g_dbus_method_invocation_return_value (context, NULL);
/* Add a timer to make sure we do not wait indefinitely for the successful connect. */ /* Add a timer to make sure we do not wait indefinitely for the successful connect. */
connect_timer_start (plugin); connect_timer_start (plugin);
} else { } else {
g_dbus_method_invocation_take_error (context, error);
/* Stop the plugin from and idle handler so that the NewSecrets /* Stop the plugin from and idle handler so that the NewSecrets
* method return gets sent before the STOP StateChanged signal. * method return gets sent before the STOP StateChanged signal.
*/ */
@@ -619,7 +578,6 @@ impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin,
} }
g_object_unref (connection); g_object_unref (connection);
return success;
} }
/** /**
@@ -660,51 +618,57 @@ nm_vpn_plugin_secrets_required (NMVpnPlugin *plugin,
/***************************************************************/ /***************************************************************/
static gboolean static void
impl_vpn_plugin_disconnect (NMVpnPlugin *plugin, impl_vpn_plugin_disconnect (NMVpnPlugin *plugin,
GError **err) GDBusMethodInvocation *context,
gpointer user_data)
{ {
return nm_vpn_plugin_disconnect (plugin, err); GError *error = NULL;
if (nm_vpn_plugin_disconnect (plugin, &error))
g_dbus_method_invocation_return_value (context, NULL);
else
g_dbus_method_invocation_take_error (context, error);
} }
static gboolean static void
impl_vpn_plugin_set_config (NMVpnPlugin *plugin, impl_vpn_plugin_set_config (NMVpnPlugin *plugin,
GHashTable *config, GDBusMethodInvocation *context,
GError **err) GVariant *config,
gpointer user_data)
{ {
nm_vpn_plugin_set_config (plugin, config); nm_vpn_plugin_set_config (plugin, config);
g_dbus_method_invocation_return_value (context, NULL);
return TRUE;
} }
static gboolean static void
impl_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, impl_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
GHashTable *config, GDBusMethodInvocation *context,
GError **err) GVariant *config,
gpointer user_data)
{ {
nm_vpn_plugin_set_ip4_config (plugin, config); nm_vpn_plugin_set_ip4_config (plugin, config);
g_dbus_method_invocation_return_value (context, NULL);
return TRUE;
} }
static gboolean static void
impl_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, impl_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin,
GHashTable *config, GDBusMethodInvocation *context,
GError **err) GVariant *config,
gpointer user_data)
{ {
nm_vpn_plugin_set_ip6_config (plugin, config); nm_vpn_plugin_set_ip6_config (plugin, config);
g_dbus_method_invocation_return_value (context, NULL);
return TRUE;
} }
static gboolean static void
impl_vpn_plugin_set_failure (NMVpnPlugin *plugin, impl_vpn_plugin_set_failure (NMVpnPlugin *plugin,
GDBusMethodInvocation *context,
char *reason, char *reason,
GError **err) gpointer user_data)
{ {
nm_vpn_plugin_failure (plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG); nm_vpn_plugin_failure (plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG);
g_dbus_method_invocation_return_value (context, NULL);
return TRUE;
} }
/*********************************************************************/ /*********************************************************************/
@@ -750,11 +714,12 @@ nm_vpn_plugin_init (NMVpnPlugin *plugin)
static gboolean static gboolean
init_sync (GInitable *initable, GCancellable *cancellable, GError **error) init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{ {
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (initable); NMVpnPlugin *plugin = NM_VPN_PLUGIN (initable);
NMVpnPlugin *plugin; NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
DBusGConnection *connection; GDBusConnection *connection = NULL;
DBusGProxy *proxy; GDBusProxy *proxy;
guint request_name_result; GVariant *ret;
gboolean success = FALSE;
if (!priv->dbus_service_name) { if (!priv->dbus_service_name) {
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
@@ -762,36 +727,60 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
return FALSE; return FALSE;
} }
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error); connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
if (!connection) if (!connection)
return FALSE; return FALSE;
proxy = dbus_g_proxy_new_for_name (connection, proxy = g_dbus_proxy_new_sync (connection,
DBUS_SERVICE_DBUS, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
DBUS_PATH_DBUS, G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
DBUS_INTERFACE_DBUS); NULL,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
cancellable, error);
if (!proxy)
goto out;
if (!dbus_g_proxy_call (proxy, "RequestName", error, ret = g_dbus_proxy_call_sync (proxy,
G_TYPE_STRING, priv->dbus_service_name, "RequestName",
G_TYPE_UINT, 0, g_variant_new ("(s)", priv->dbus_service_name),
G_TYPE_INVALID, G_DBUS_CALL_FLAGS_NONE, 0,
G_TYPE_UINT, &request_name_result, cancellable, error);
G_TYPE_INVALID)) {
g_object_unref (proxy);
return FALSE;
}
g_object_unref (proxy); g_object_unref (proxy);
if (!ret)
goto out;
g_variant_unref (ret);
dbus_g_connection_register_g_object (connection, priv->dbus_vpn_plugin = nmdbus_vpn_plugin_skeleton_new ();
NM_VPN_DBUS_PLUGIN_PATH, if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_vpn_plugin),
G_OBJECT (initable)); connection,
NM_VPN_DBUS_PLUGIN_PATH,
error))
goto out;
plugin = NM_VPN_PLUGIN (initable); _nm_dbus_bind_properties (plugin, priv->dbus_vpn_plugin);
_nm_dbus_bind_methods (plugin, priv->dbus_vpn_plugin,
"Connect", impl_vpn_plugin_connect,
"ConnectInteractive", impl_vpn_plugin_connect_interactive,
"NeedSecrets", impl_vpn_plugin_need_secrets,
"NewSecrets", impl_vpn_plugin_new_secrets,
"Disconnect", impl_vpn_plugin_disconnect,
"SetConfig", impl_vpn_plugin_set_config,
"SetIp4Config", impl_vpn_plugin_set_ip4_config,
"SetIp6Config", impl_vpn_plugin_set_ip6_config,
"SetFailure", impl_vpn_plugin_set_failure,
NULL);
nm_vpn_plugin_set_connection (plugin, connection); nm_vpn_plugin_set_connection (plugin, connection);
nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_INIT); nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_INIT);
return TRUE; success = TRUE;
out:
g_clear_object (&connection);
return success;
} }
static void static void
@@ -870,14 +859,10 @@ finalize (GObject *object)
nm_vpn_plugin_set_connection (plugin, NULL); nm_vpn_plugin_set_connection (plugin, NULL);
g_free (priv->dbus_service_name); g_free (priv->dbus_service_name);
if (G_IS_VALUE (&priv->banner)) g_clear_pointer (&priv->banner, g_free);
g_value_unset (&priv->banner); g_clear_pointer (&priv->tundev, g_free);
if (G_IS_VALUE (&priv->tundev)) g_clear_pointer (&priv->gateway, g_free);
g_value_unset (&priv->tundev); g_clear_pointer (&priv->mtu, g_free);
if (G_IS_VALUE (&priv->gateway))
g_value_unset (&priv->gateway);
if (G_IS_VALUE (&priv->mtu))
g_value_unset (&priv->mtu);
G_OBJECT_CLASS (nm_vpn_plugin_parent_class)->finalize (object); G_OBJECT_CLASS (nm_vpn_plugin_parent_class)->finalize (object);
} }
@@ -934,9 +919,6 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
g_type_class_add_private (object_class, sizeof (NMVpnPluginPrivate)); g_type_class_add_private (object_class, sizeof (NMVpnPluginPrivate));
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (plugin_class),
&dbus_glib_nm_vpn_plugin_object_info);
/* virtual methods */ /* virtual methods */
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->get_property = get_property; object_class->get_property = get_property;
@@ -981,7 +963,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMVpnPluginClass, state_changed), G_STRUCT_OFFSET (NMVpnPluginClass, state_changed),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__UINT, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_UINT); G_TYPE_UINT);
@@ -999,9 +981,9 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMVpnPluginClass, config), G_STRUCT_OFFSET (NMVpnPluginClass, config),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__BOXED, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
DBUS_TYPE_G_MAP_OF_VARIANT); G_TYPE_VARIANT);
signals[IP4_CONFIG] = signals[IP4_CONFIG] =
g_signal_new ("ip4-config", g_signal_new ("ip4-config",
@@ -1009,9 +991,9 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMVpnPluginClass, ip4_config), G_STRUCT_OFFSET (NMVpnPluginClass, ip4_config),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__BOXED, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
DBUS_TYPE_G_MAP_OF_VARIANT); G_TYPE_VARIANT);
signals[IP6_CONFIG] = signals[IP6_CONFIG] =
g_signal_new ("ip6-config", g_signal_new ("ip6-config",
@@ -1019,9 +1001,9 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMVpnPluginClass, ip6_config), G_STRUCT_OFFSET (NMVpnPluginClass, ip6_config),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__BOXED, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
DBUS_TYPE_G_MAP_OF_VARIANT); G_TYPE_VARIANT);
signals[LOGIN_BANNER] = signals[LOGIN_BANNER] =
g_signal_new ("login-banner", g_signal_new ("login-banner",
@@ -1029,7 +1011,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMVpnPluginClass, login_banner), G_STRUCT_OFFSET (NMVpnPluginClass, login_banner),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__STRING, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_STRING); G_TYPE_STRING);
@@ -1039,7 +1021,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMVpnPluginClass, failure), G_STRUCT_OFFSET (NMVpnPluginClass, failure),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__UINT, NULL,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_UINT); G_TYPE_UINT);
@@ -1049,13 +1031,13 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMVpnPluginClass, quit), G_STRUCT_OFFSET (NMVpnPluginClass, quit),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__VOID, NULL,
G_TYPE_NONE, 0, G_TYPE_NONE, 0,
G_TYPE_NONE); G_TYPE_NONE);
dbus_g_error_domain_register (NM_VPN_PLUGIN_ERROR, _nm_dbus_register_error_domain (NM_VPN_PLUGIN_ERROR,
NM_DBUS_VPN_ERROR_PREFIX, NM_DBUS_VPN_ERROR_PREFIX,
NM_TYPE_VPN_PLUGIN_ERROR); NM_TYPE_VPN_PLUGIN_ERROR);
setup_unix_signal_handler (); setup_unix_signal_handler ();
} }

View File

@@ -26,9 +26,7 @@
#error "Only <NetworkManager.h> can be included directly." #error "Only <NetworkManager.h> can be included directly."
#endif #endif
#include <glib.h> #include <gio/gio.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <nm-vpn-dbus-interface.h> #include <nm-vpn-dbus-interface.h>
#include <nm-connection.h> #include <nm-connection.h>
@@ -98,7 +96,7 @@ typedef struct {
NMVpnServiceState state); NMVpnServiceState state);
void (*ip4_config) (NMVpnPlugin *plugin, void (*ip4_config) (NMVpnPlugin *plugin,
GHashTable *ip4_config); GVariant *ip4_config);
void (*login_banner) (NMVpnPlugin *plugin, void (*login_banner) (NMVpnPlugin *plugin,
const char *banner); const char *banner);
@@ -109,10 +107,10 @@ typedef struct {
void (*quit) (NMVpnPlugin *plugin); void (*quit) (NMVpnPlugin *plugin);
void (*config) (NMVpnPlugin *plugin, void (*config) (NMVpnPlugin *plugin,
GHashTable *config); GVariant *config);
void (*ip6_config) (NMVpnPlugin *plugin, void (*ip6_config) (NMVpnPlugin *plugin,
GHashTable *config); GVariant *config);
/* virtual methods */ /* virtual methods */
gboolean (*connect) (NMVpnPlugin *plugin, gboolean (*connect) (NMVpnPlugin *plugin,
@@ -133,7 +131,7 @@ typedef struct {
gboolean (*connect_interactive) (NMVpnPlugin *plugin, gboolean (*connect_interactive) (NMVpnPlugin *plugin,
NMConnection *connection, NMConnection *connection,
GHashTable *details, GVariant *details,
GError **error); GError **error);
/*< private >*/ /*< private >*/
@@ -143,7 +141,7 @@ typedef struct {
GType nm_vpn_plugin_get_type (void); GType nm_vpn_plugin_get_type (void);
GQuark nm_vpn_plugin_error_quark (void); GQuark nm_vpn_plugin_error_quark (void);
DBusGConnection *nm_vpn_plugin_get_connection (NMVpnPlugin *plugin); GDBusConnection *nm_vpn_plugin_get_connection (NMVpnPlugin *plugin);
NMVpnServiceState nm_vpn_plugin_get_state (NMVpnPlugin *plugin); NMVpnServiceState nm_vpn_plugin_get_state (NMVpnPlugin *plugin);
void nm_vpn_plugin_set_state (NMVpnPlugin *plugin, void nm_vpn_plugin_set_state (NMVpnPlugin *plugin,
NMVpnServiceState state); NMVpnServiceState state);
@@ -159,13 +157,13 @@ void nm_vpn_plugin_failure (NMVpnPlugin *plugin,
NMVpnPluginFailure reason); NMVpnPluginFailure reason);
void nm_vpn_plugin_set_config (NMVpnPlugin *plugin, void nm_vpn_plugin_set_config (NMVpnPlugin *plugin,
GHashTable *config); GVariant *config);
void nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, void nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
GHashTable *ip4_config); GVariant *ip4_config);
void nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, void nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin,
GHashTable *ip6_config); GVariant *ip6_config);
gboolean nm_vpn_plugin_disconnect (NMVpnPlugin *plugin, gboolean nm_vpn_plugin_disconnect (NMVpnPlugin *plugin,
GError **err); GError **err);

View File

@@ -9,13 +9,11 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \ -DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
-DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \ -DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \
$(GLIB_CFLAGS) \ $(GLIB_CFLAGS)
$(DBUS_CFLAGS)
LDADD = \ LDADD = \
$(top_builddir)/libnm/libnm.la \ $(top_builddir)/libnm/libnm.la \
$(GLIB_LIBS) \ $(GLIB_LIBS)
$(DBUS_LIBS)
noinst_PROGRAMS = $(TESTS) noinst_PROGRAMS = $(TESTS)

View File

@@ -32,9 +32,9 @@ name_exists (GDBusConnection *c, const char *name)
gboolean exists = FALSE; gboolean exists = FALSE;
reply = g_dbus_connection_call_sync (c, reply = g_dbus_connection_call_sync (c,
DBUS_SERVICE_DBUS, "org.freedesktop.DBus",
DBUS_PATH_DBUS, "/org/freedesktop/DBus",
DBUS_INTERFACE_DBUS, "org.freedesktop.DBus",
"GetNameOwner", "GetNameOwner",
g_variant_new ("(s)", name), g_variant_new ("(s)", name),
NULL, NULL,

View File

@@ -18,9 +18,6 @@
* *
*/ */
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>

View File

@@ -18,9 +18,6 @@
* *
*/ */
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@@ -34,7 +31,7 @@
static NMTestServiceInfo *sinfo; static NMTestServiceInfo *sinfo;
static NMRemoteSettings *settings = NULL; static NMRemoteSettings *settings = NULL;
DBusGConnection *bus = NULL; GDBusConnection *bus = NULL;
NMRemoteConnection *remote = NULL; NMRemoteConnection *remote = NULL;
/*******************************************************************/ /*******************************************************************/
@@ -88,16 +85,16 @@ test_add_connection (void)
/*******************************************************************/ /*******************************************************************/
static void static void
set_visible_cb (DBusGProxy *proxy, set_visible_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GError *error = NULL; GError *error = NULL;
gboolean success; GVariant *ret;
success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (success == TRUE); g_variant_unref (ret);
} }
static void static void
@@ -129,7 +126,7 @@ test_make_invisible (void)
{ {
time_t start, now; time_t start, now;
GSList *list, *iter; GSList *list, *iter;
DBusGProxy *proxy; GDBusProxy *proxy;
gboolean visible_changed = FALSE, connection_removed = FALSE; gboolean visible_changed = FALSE, connection_removed = FALSE;
gboolean has_settings = FALSE; gboolean has_settings = FALSE;
char *path; char *path;
@@ -141,15 +138,23 @@ test_make_invisible (void)
g_signal_connect (settings, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed); g_signal_connect (settings, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
proxy = dbus_g_proxy_new_for_name (bus, proxy = g_dbus_proxy_new_sync (bus,
NM_DBUS_SERVICE, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
path, NULL,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION); NM_DBUS_SERVICE,
path,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
NULL,
NULL);
g_assert (proxy != NULL); g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */ /* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL, g_dbus_proxy_call (proxy,
G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID); "SetVisible",
g_variant_new ("(b)", FALSE),
G_DBUS_CALL_FLAGS_NONE, -1,
NULL,
set_visible_cb, NULL);
/* Wait for the connection to be removed */ /* Wait for the connection to be removed */
start = time (NULL); start = time (NULL);
@@ -198,7 +203,7 @@ test_make_visible (void)
{ {
time_t start, now; time_t start, now;
GSList *list, *iter; GSList *list, *iter;
DBusGProxy *proxy; GDBusProxy *proxy;
gboolean found = FALSE; gboolean found = FALSE;
char *path; char *path;
NMRemoteConnection *new = NULL; NMRemoteConnection *new = NULL;
@@ -210,16 +215,23 @@ test_make_visible (void)
G_CALLBACK (vis_new_connection_cb), &new); G_CALLBACK (vis_new_connection_cb), &new);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
proxy = dbus_g_proxy_new_for_name (bus, proxy = g_dbus_proxy_new_sync (bus,
NM_DBUS_SERVICE, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
path, NULL,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION); NM_DBUS_SERVICE,
path,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
NULL,
NULL);
g_assert (proxy != NULL); g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */ /* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL, g_dbus_proxy_call (proxy,
G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID); "SetVisible",
g_variant_new ("(b)", TRUE),
G_DBUS_CALL_FLAGS_NONE, -1,
NULL,
set_visible_cb, NULL);
/* Wait for the settings service to announce the connection again */ /* Wait for the settings service to announce the connection again */
start = time (NULL); start = time (NULL);
@@ -255,16 +267,16 @@ test_make_visible (void)
/*******************************************************************/ /*******************************************************************/
static void static void
deleted_cb (DBusGProxy *proxy, deleted_cb (GObject *proxy,
DBusGProxyCall *call, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GError *error = NULL; GError *error = NULL;
gboolean success; GVariant *ret;
success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (success == TRUE); g_variant_unref (ret);
} }
static void static void
@@ -280,7 +292,7 @@ test_remove_connection (void)
NMRemoteConnection *connection; NMRemoteConnection *connection;
time_t start, now; time_t start, now;
GSList *list, *iter; GSList *list, *iter;
DBusGProxy *proxy; GDBusProxy *proxy;
gboolean done = FALSE; gboolean done = FALSE;
char *path; char *path;
@@ -294,14 +306,23 @@ test_remove_connection (void)
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection))); path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
g_signal_connect (settings, "connection-removed", G_CALLBACK (removed_cb), &done); g_signal_connect (settings, "connection-removed", G_CALLBACK (removed_cb), &done);
proxy = dbus_g_proxy_new_for_name (bus, proxy = g_dbus_proxy_new_sync (bus,
NM_DBUS_SERVICE, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
path, NULL,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION); NM_DBUS_SERVICE,
path,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
NULL,
NULL);
g_assert (proxy != NULL); g_assert (proxy != NULL);
/* Bypass the NMRemoteSettings object so we can test it independently */ /* Bypass the NMRemoteSettings object so we can test it independently */
dbus_g_proxy_begin_call (proxy, "Delete", deleted_cb, NULL, NULL, G_TYPE_INVALID); g_dbus_proxy_call (proxy,
"Delete",
NULL,
G_DBUS_CALL_FLAGS_NONE, -1,
NULL,
deleted_cb, NULL);
start = time (NULL); start = time (NULL);
do { do {
@@ -481,7 +502,7 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
sinfo = nm_test_service_init (); sinfo = nm_test_service_init ();
@@ -504,7 +525,7 @@ main (int argc, char **argv)
nm_test_service_cleanup (sinfo); nm_test_service_cleanup (sinfo);
g_object_unref (settings); g_object_unref (settings);
dbus_g_connection_unref (bus); g_object_unref (bus);
return ret; return ret;
} }

View File

@@ -387,6 +387,7 @@ connection_activated_none_cb (NMClient *c,
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
g_assert (error != NULL); g_assert (error != NULL);
g_dbus_error_strip_remote_error (error);
g_assert_cmpstr (error->message, ==, "No secret agent available"); g_assert_cmpstr (error->message, ==, "No secret agent available");
g_main_loop_quit (sadata->loop); g_main_loop_quit (sadata->loop);
@@ -431,6 +432,7 @@ connection_activated_no_secrets_cb (NMClient *c,
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
g_assert (error != NULL); g_assert (error != NULL);
g_dbus_error_strip_remote_error (error);
g_assert_cmpstr (error->message, ==, "No secrets provided"); g_assert_cmpstr (error->message, ==, "No secrets provided");
g_main_loop_quit (sadata->loop); g_main_loop_quit (sadata->loop);
@@ -465,6 +467,7 @@ connection_activated_cancel_cb (NMClient *c,
TestSecretAgentData *sadata = user_data; TestSecretAgentData *sadata = user_data;
g_assert (error != NULL); g_assert (error != NULL);
g_dbus_error_strip_remote_error (error);
g_assert_cmpstr (error->message, ==, "User canceled"); g_assert_cmpstr (error->message, ==, "User canceled");
g_main_loop_quit (sadata->loop); g_main_loop_quit (sadata->loop);
@@ -519,6 +522,7 @@ connection_activated_good_cb (NMClient *c,
* other tests won't get to). * other tests won't get to).
*/ */
g_assert (error != NULL); g_assert (error != NULL);
g_dbus_error_strip_remote_error (error);
g_assert_cmpstr (error->message, ==, "Not yet implemented"); g_assert_cmpstr (error->message, ==, "Not yet implemented");
g_main_loop_quit (sadata->loop); g_main_loop_quit (sadata->loop);

View File

@@ -46,6 +46,7 @@
#include "nm-setting-wireless-security.h" #include "nm-setting-wireless-security.h"
#include "nm-manager-auth.h" #include "nm-manager-auth.h"
#include "nm-posix-signals.h" #include "nm-posix-signals.h"
#include "nm-dbus-glib-types.h"
/* /*
* Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export * Some toolchains (E.G. uClibc 0.9.33 and earlier) don't export
@@ -1840,3 +1841,147 @@ nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid,
memcpy (iid, addr->s6_addr + 8, 8); memcpy (iid, addr->s6_addr + 8, 8);
} }
/**
* nm_utils_connection_hash_to_dict:
* @hash: a hashed #NMConnection
*
* Returns: a (floating) #GVariant equivalent to @hash.
*/
GVariant *
nm_utils_connection_hash_to_dict (GHashTable *hash)
{
GValue val = { 0, };
GVariant *variant;
if (!hash)
return NULL;
g_value_init (&val, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT);
g_value_set_boxed (&val, hash);
variant = dbus_g_value_build_g_variant (&val);
g_value_unset (&val);
return variant;
}
/**
* nm_utils_connection_dict_to_hash:
* @dict: a #GVariant-serialized #NMConnection
*
* Returns: a #GHashTable equivalent to @dict.
*/
GHashTable *
nm_utils_connection_dict_to_hash (GVariant *dict)
{
GValue val = { 0, };
if (!dict)
return NULL;
dbus_g_value_parse_g_variant (dict, &val);
return g_value_get_boxed (&val);
}
GSList *
nm_utils_ip4_routes_from_gvalue (const GValue *value)
{
GPtrArray *routes;
int i;
GSList *list = NULL;
routes = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; routes && (i < routes->len); i++) {
GArray *array = (GArray *) g_ptr_array_index (routes, i);
NMIP4Route *route;
if (array->len < 4) {
g_warning ("Ignoring invalid IP4 route");
continue;
}
route = nm_ip4_route_new ();
nm_ip4_route_set_dest (route, g_array_index (array, guint32, 0));
nm_ip4_route_set_prefix (route, g_array_index (array, guint32, 1));
nm_ip4_route_set_next_hop (route, g_array_index (array, guint32, 2));
nm_ip4_route_set_metric (route, g_array_index (array, guint32, 3));
list = g_slist_prepend (list, route);
}
return g_slist_reverse (list);
}
static gboolean
_nm_utils_gvalue_array_validate (GValueArray *elements, guint n_expected, ...)
{
va_list args;
GValue *tmp;
int i;
gboolean valid = FALSE;
if (n_expected != elements->n_values)
return FALSE;
va_start (args, n_expected);
for (i = 0; i < n_expected; i++) {
tmp = g_value_array_get_nth (elements, i);
if (G_VALUE_TYPE (tmp) != va_arg (args, GType))
goto done;
}
valid = TRUE;
done:
va_end (args);
return valid;
}
GSList *
nm_utils_ip6_routes_from_gvalue (const GValue *value)
{
GPtrArray *routes;
int i;
GSList *list = NULL;
routes = (GPtrArray *) g_value_get_boxed (value);
for (i = 0; routes && (i < routes->len); i++) {
GValueArray *route_values = (GValueArray *) g_ptr_array_index (routes, i);
GByteArray *dest, *next_hop;
guint prefix, metric;
NMIP6Route *route;
if (!_nm_utils_gvalue_array_validate (route_values, 4,
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT,
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT)) {
g_warning ("Ignoring invalid IP6 route");
continue;
}
dest = g_value_get_boxed (g_value_array_get_nth (route_values, 0));
if (dest->len != 16) {
g_warning ("%s: ignoring invalid IP6 dest address of length %d",
__func__, dest->len);
continue;
}
prefix = g_value_get_uint (g_value_array_get_nth (route_values, 1));
next_hop = g_value_get_boxed (g_value_array_get_nth (route_values, 2));
if (next_hop->len != 16) {
g_warning ("%s: ignoring invalid IP6 next_hop address of length %d",
__func__, next_hop->len);
continue;
}
metric = g_value_get_uint (g_value_array_get_nth (route_values, 3));
route = nm_ip6_route_new ();
nm_ip6_route_set_dest (route, (struct in6_addr *)dest->data);
nm_ip6_route_set_prefix (route, prefix);
nm_ip6_route_set_next_hop (route, (struct in6_addr *)next_hop->data);
nm_ip6_route_set_metric (route, metric);
list = g_slist_prepend (list, route);
}
return g_slist_reverse (list);
}

View File

@@ -167,4 +167,10 @@ void nm_utils_ipv6_addr_set_interface_identfier (struct in6_addr *addr,
void nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid, void nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid,
const struct in6_addr *addr); const struct in6_addr *addr);
GVariant *nm_utils_connection_hash_to_dict (GHashTable *hash);
GHashTable *nm_utils_connection_dict_to_hash (GVariant *dict);
GSList *nm_utils_ip4_routes_from_gvalue (const GValue *value);
GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value);
#endif /* __NETWORKMANAGER_UTILS_H__ */ #endif /* __NETWORKMANAGER_UTILS_H__ */

View File

@@ -28,7 +28,6 @@
#include "nm-dispatcher-api.h" #include "nm-dispatcher-api.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-logging.h" #include "nm-logging.h"
#include "nm-dbus-manager.h" #include "nm-dbus-manager.h"
#include "nm-device.h" #include "nm-device.h"
@@ -475,7 +474,7 @@ _dispatcher_call (DispatcherAction action,
GVariant *connection_dict; GVariant *connection_dict;
connection_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_NO_SECRETS); connection_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_NO_SECRETS);
connection_hash = _nm_utils_connection_dict_to_hash (connection_dict); connection_hash = nm_utils_connection_dict_to_hash (connection_dict);
g_variant_unref (connection_dict); g_variant_unref (connection_dict);
connection_props = value_hash_create (); connection_props = value_hash_create ();

View File

@@ -52,7 +52,6 @@
#include "nm-manager-auth.h" #include "nm-manager-auth.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-device-factory.h" #include "nm-device-factory.h"
#include "nm-enum-types.h" #include "nm-enum-types.h"
#include "nm-sleep-monitor.h" #include "nm-sleep-monitor.h"
@@ -3298,7 +3297,7 @@ impl_manager_add_and_activate_connection (NMManager *self,
*/ */
connection = nm_simple_connection_new (); connection = nm_simple_connection_new ();
if (settings && g_hash_table_size (settings)) { if (settings && g_hash_table_size (settings)) {
GVariant *settings_dict = _nm_utils_connection_hash_to_dict (settings); GVariant *settings_dict = nm_utils_connection_hash_to_dict (settings);
nm_connection_replace_settings (connection, settings_dict, NULL); nm_connection_replace_settings (connection, settings_dict, NULL);
g_variant_unref (settings_dict); g_variant_unref (settings_dict);

View File

@@ -40,7 +40,7 @@
#include "nm-dbus-manager.h" #include "nm-dbus-manager.h"
#include "nm-session-monitor.h" #include "nm-session-monitor.h"
#include "nm-simple-connection.h" #include "nm-simple-connection.h"
#include "nm-utils-private.h" #include "NetworkManagerUtils.h"
G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, G_TYPE_OBJECT) G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, G_TYPE_OBJECT)
@@ -914,7 +914,7 @@ get_agent_request_secrets (ConnectionRequest *req, gboolean include_system_secre
if (req->existing_secrets) { if (req->existing_secrets) {
GVariant *secrets_dict; GVariant *secrets_dict;
secrets_dict = _nm_utils_connection_hash_to_dict (req->existing_secrets); secrets_dict = nm_utils_connection_hash_to_dict (req->existing_secrets);
(void) nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, NULL); (void) nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, NULL);
g_variant_unref (secrets_dict); g_variant_unref (secrets_dict);
} }
@@ -1101,7 +1101,7 @@ get_start (gpointer user_data)
tmp = nm_simple_connection_new_clone (req->connection); tmp = nm_simple_connection_new_clone (req->connection);
g_assert (tmp); g_assert (tmp);
secrets_dict = _nm_utils_connection_hash_to_dict (req->existing_secrets); secrets_dict = nm_utils_connection_hash_to_dict (req->existing_secrets);
if (!nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, &error)) { if (!nm_connection_update_secrets (tmp, req->setting_name, secrets_dict, &error)) {
req_complete_error (parent, error); req_complete_error (parent, error);
g_clear_error (&error); g_clear_error (&error);

View File

@@ -35,7 +35,7 @@
#include "nm-logging.h" #include "nm-logging.h"
#include "nm-auth-subject.h" #include "nm-auth-subject.h"
#include "nm-simple-connection.h" #include "nm-simple-connection.h"
#include "nm-utils-private.h" #include "NetworkManagerUtils.h"
G_DEFINE_TYPE (NMSecretAgent, nm_secret_agent, G_TYPE_OBJECT) G_DEFINE_TYPE (NMSecretAgent, nm_secret_agent, G_TYPE_OBJECT)
@@ -296,7 +296,7 @@ nm_secret_agent_get_secrets (NMSecretAgent *self,
g_return_val_if_fail (priv->proxy != NULL, NULL); g_return_val_if_fail (priv->proxy != NULL, NULL);
dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
hash = _nm_utils_connection_dict_to_hash (dict); hash = nm_utils_connection_dict_to_hash (dict);
g_variant_unref (dict); g_variant_unref (dict);
/* Mask off the private ONLY_SYSTEM flag if present */ /* Mask off the private ONLY_SYSTEM flag if present */
@@ -395,7 +395,7 @@ agent_new_save_delete (NMSecretAgent *self,
const char *cpath = nm_connection_get_path (connection); const char *cpath = nm_connection_get_path (connection);
dict = nm_connection_to_dbus (connection, flags); dict = nm_connection_to_dbus (connection, flags);
hash = _nm_utils_connection_dict_to_hash (dict); hash = nm_utils_connection_dict_to_hash (dict);
g_variant_unref (dict); g_variant_unref (dict);
r = request_new (self, cpath, NULL, callback, callback_data); r = request_new (self, cpath, NULL, callback, callback_data);

View File

@@ -29,7 +29,6 @@
#include <nm-setting-vpn.h> #include <nm-setting-vpn.h>
#include <nm-setting-wireless.h> #include <nm-setting-wireless.h>
#include <nm-utils.h> #include <nm-utils.h>
#include "nm-core-internal.h"
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
#include "nm-session-monitor.h" #include "nm-session-monitor.h"
@@ -818,7 +817,7 @@ agent_secrets_done_cb (NMAgentManager *manager,
* will have been authenticated, so those secrets can replace the existing * will have been authenticated, so those secrets can replace the existing
* system secrets. * system secrets.
*/ */
secrets_dict = _nm_utils_connection_hash_to_dict (secrets); secrets_dict = nm_utils_connection_hash_to_dict (secrets);
if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, secrets_dict, &local)) { if (nm_connection_update_secrets (NM_CONNECTION (self), setting_name, secrets_dict, &local)) {
/* Now that all secrets are updated, copy and cache new secrets, /* Now that all secrets are updated, copy and cache new secrets,
* then save them to backing storage. * then save them to backing storage.
@@ -919,7 +918,7 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self,
} }
existing_secrets = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS); existing_secrets = nm_connection_to_dbus (priv->system_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
existing_secrets_hash = _nm_utils_connection_dict_to_hash (existing_secrets); existing_secrets_hash = nm_utils_connection_dict_to_hash (existing_secrets);
call_id = nm_agent_manager_get_secrets (priv->agent_mgr, call_id = nm_agent_manager_get_secrets (priv->agent_mgr,
NM_CONNECTION (self), NM_CONNECTION (self),
subject, subject,
@@ -1178,7 +1177,7 @@ get_settings_auth_cb (NMSettingsConnection *self,
*/ */
settings = nm_connection_to_dbus (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS); settings = nm_connection_to_dbus (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS);
g_assert (settings); g_assert (settings);
settings_hash = _nm_utils_connection_dict_to_hash (settings); settings_hash = nm_utils_connection_dict_to_hash (settings);
dbus_g_method_return (context, settings_hash); dbus_g_method_return (context, settings_hash);
g_hash_table_destroy (settings_hash); g_hash_table_destroy (settings_hash);
g_variant_unref (settings); g_variant_unref (settings);
@@ -1340,7 +1339,7 @@ impl_settings_connection_update_helper (NMSettingsConnection *self,
/* Check if the settings are valid first */ /* Check if the settings are valid first */
if (new_settings) { if (new_settings) {
GVariant *new_settings_dict = _nm_utils_connection_hash_to_dict (new_settings); GVariant *new_settings_dict = nm_utils_connection_hash_to_dict (new_settings);
tmp = nm_simple_connection_new_from_dbus (new_settings_dict, &error); tmp = nm_simple_connection_new_from_dbus (new_settings_dict, &error);
g_variant_unref (new_settings_dict); g_variant_unref (new_settings_dict);
@@ -1513,7 +1512,7 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self,
*/ */
dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS); dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (dict) if (dict)
hash = _nm_utils_connection_dict_to_hash (dict); hash = nm_utils_connection_dict_to_hash (dict);
else else
hash = g_hash_table_new (NULL, NULL); hash = g_hash_table_new (NULL, NULL);
dbus_g_method_return (context, hash); dbus_g_method_return (context, hash);

View File

@@ -1224,7 +1224,7 @@ impl_settings_add_connection_helper (NMSettings *self,
GVariant *dict; GVariant *dict;
GError *error = NULL; GError *error = NULL;
dict = _nm_utils_connection_hash_to_dict (settings); dict = nm_utils_connection_hash_to_dict (settings);
connection = nm_simple_connection_new_from_dbus (dict, &error); connection = nm_simple_connection_new_from_dbus (dict, &error);
g_variant_unref (dict); g_variant_unref (dict);
if (connection) { if (connection) {

View File

@@ -40,7 +40,6 @@
#include "nm-platform.h" #include "nm-platform.h"
#include "nm-logging.h" #include "nm-logging.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "nm-dbus-glib-types.h" #include "nm-dbus-glib-types.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
@@ -1469,7 +1468,7 @@ _hash_with_username (NMConnection *connection, const char *username)
existing = nm_setting_vpn_get_user_name (s_vpn); existing = nm_setting_vpn_get_user_name (s_vpn);
if (username == NULL || existing) { if (username == NULL || existing) {
dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
hash = _nm_utils_connection_dict_to_hash (dict); hash = nm_utils_connection_dict_to_hash (dict);
g_variant_unref (dict); g_variant_unref (dict);
return hash; return hash;
} }
@@ -1482,7 +1481,7 @@ _hash_with_username (NMConnection *connection, const char *username)
dict = nm_connection_to_dbus (dup, NM_CONNECTION_SERIALIZE_ALL); dict = nm_connection_to_dbus (dup, NM_CONNECTION_SERIALIZE_ALL);
g_object_unref (dup); g_object_unref (dup);
hash = _nm_utils_connection_dict_to_hash (dict); hash = nm_utils_connection_dict_to_hash (dict);
g_variant_unref (dict); g_variant_unref (dict);
return hash; return hash;
} }