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:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -133,6 +133,8 @@ valgrind-*.log
|
||||
/initscript/*/[Nn]etwork[Mm]anager
|
||||
|
||||
/introspection/all.xml
|
||||
/introspection/nmdbus-*.c
|
||||
/introspection/nmdbus-*.h
|
||||
|
||||
/libgsystem/
|
||||
|
||||
|
@@ -3,11 +3,11 @@ include $(GLIB_MAKEFILE)
|
||||
SUBDIRS = \
|
||||
. \
|
||||
include \
|
||||
introspection \
|
||||
libnm-core \
|
||||
libnm \
|
||||
libnm-util \
|
||||
libnm-glib \
|
||||
introspection \
|
||||
src \
|
||||
callouts \
|
||||
clients \
|
||||
|
@@ -49,8 +49,7 @@ nm_dispatcher_LDADD = \
|
||||
libnmdbus-dispatcher.la \
|
||||
$(GLIB_LIBS)
|
||||
|
||||
# We have to build the gdbus generated code separately, without
|
||||
# -DGLIB_VERSION_MAX_ALLOWED, due to a bug in GLib 2.38
|
||||
# See note about gdbus-codegen in introspection/Makefile.am
|
||||
|
||||
noinst_LTLIBRARIES += libnmdbus-dispatcher.la
|
||||
|
||||
|
@@ -5,7 +5,6 @@ AM_CPPFLAGS = \
|
||||
-I${top_builddir}/libnm-core \
|
||||
-I${top_srcdir}/libnm \
|
||||
-I${top_builddir}/libnm \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(GLIB_CFLAGS) \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||
-DNMLOCALEDIR=\"$(datadir)/locale\"
|
||||
@@ -19,5 +18,4 @@ nm_online_CPPFLAGS = \
|
||||
|
||||
nm_online_LDADD = \
|
||||
$(top_builddir)/libnm/libnm.la \
|
||||
$(DBUS_LIBS) \
|
||||
$(GLIB_LIBS)
|
||||
|
@@ -9,7 +9,6 @@ AM_CPPFLAGS = \
|
||||
-I${top_builddir}/libnm-core \
|
||||
-I${top_srcdir}/libnm \
|
||||
-I${top_builddir}/libnm \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(GLIB_CFLAGS) \
|
||||
-DG_LOG_DOMAIN=\""nmcli"\" \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||
@@ -32,7 +31,6 @@ nmcli_SOURCES = \
|
||||
utils.h
|
||||
|
||||
nmcli_LDADD = \
|
||||
$(DBUS_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(READLINE_LIBS) \
|
||||
$(top_builddir)/libnm/libnm.la
|
||||
|
@@ -677,7 +677,7 @@ do_general (NmCli *nmc, int argc, char **argv)
|
||||
nmc->get_client (nmc); /* create NMClient */
|
||||
nm_client_set_logging (nmc->client, level, domains, &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);
|
||||
else
|
||||
g_string_printf (nmc->return_text, _("Error: %s"), error->message);
|
||||
|
@@ -12,7 +12,6 @@ AM_CPPFLAGS= \
|
||||
-I$(srcdir)/newt \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(NEWT_CFLAGS) \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(GUDEV_CFLAGS) \
|
||||
-DG_LOG_DOMAIN=\""nmtui"\" \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||
@@ -121,7 +120,6 @@ nmtui_LDADD = \
|
||||
$(top_builddir)/libnm/libnm.la \
|
||||
$(builddir)/newt/libnmt-newt.a \
|
||||
$(GUDEV_LIBS) \
|
||||
$(DBUS_LIBS) \
|
||||
$(NEWT_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(NULL)
|
||||
|
@@ -38,11 +38,9 @@ IGNORE_HFILES= \
|
||||
nm-object-private.h \
|
||||
nm-param-spec-dbus.h \
|
||||
nm-remote-connection-private.h \
|
||||
nm-secret-agent-glue.h \
|
||||
nm-setting-private.h \
|
||||
nm-types-private.h \
|
||||
nm-utils-private.h \
|
||||
nm-vpn-plugin-glue.h
|
||||
nm-utils-private.h
|
||||
|
||||
# Images to copy into HTML directory.
|
||||
HTML_IMAGES = libnm.png
|
||||
|
@@ -4,7 +4,6 @@ AM_CPPFLAGS = \
|
||||
-I${top_builddir}/libnm-core \
|
||||
-I${top_srcdir}/libnm \
|
||||
-I${top_builddir}/libnm \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(GLIB_CFLAGS)
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
@@ -25,7 +24,6 @@ add_connection_gdbus_LDADD = \
|
||||
add_connection_libnm_SOURCES = add-connection-libnm.c
|
||||
add_connection_libnm_LDADD = \
|
||||
$(top_builddir)/libnm/libnm.la \
|
||||
$(DBUS_LIBS) \
|
||||
$(GLIB_LIBS)
|
||||
|
||||
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_LDADD = \
|
||||
$(top_builddir)/libnm/libnm.la \
|
||||
$(DBUS_LIBS) \
|
||||
$(GLIB_LIBS)
|
||||
|
||||
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_LDADD = \
|
||||
$(top_builddir)/libnm/libnm.la \
|
||||
$(DBUS_LIBS) \
|
||||
$(GLIB_LIBS)
|
||||
|
||||
monitor_nm_running_gdbus_SOURCES = monitor-nm-running-gdbus.c
|
||||
|
@@ -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 = \
|
||||
all.xml.in \
|
||||
generic-types.xml \
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
|
||||
<interface name="org.freedesktop.NetworkManager.Device.Wired">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="DeviceEthernet"/>
|
||||
|
||||
<property name="HwAddress" type="s" access="read">
|
||||
<tp:docstring>
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
|
||||
<interface name="org.freedesktop.NetworkManager.Device.Wireless">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="DeviceWifi"/>
|
||||
|
||||
<method name="GetAccessPoints">
|
||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_access_points"/>
|
||||
<arg name="access_points" type="ao" direction="out">
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
<node name="/org/freedesktop/NetworkManager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
|
||||
<interface name="org.freedesktop.NetworkManager">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="Manager"/>
|
||||
|
||||
<method name="GetDevices">
|
||||
<tp:docstring>
|
||||
Get the list of network devices.
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
<node name="/">
|
||||
<interface name="org.freedesktop.NetworkManager.PPP">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="PPP_Manager"/>
|
||||
|
||||
<method name="NeedSecrets">
|
||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_need_secrets"/>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
|
||||
<interface name="org.freedesktop.NetworkManager.VPN.Connection">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="VpnConnection"/>
|
||||
|
||||
<tp:docstring>
|
||||
Represents an active connection to a Virtual Private Network.
|
||||
</tp:docstring>
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
|
||||
<interface name="org.freedesktop.NetworkManager.VPN.Plugin">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="VpnPlugin"/>
|
||||
|
||||
<tp:docstring>
|
||||
This interface is provided by plugins providing VPN services to the NetworkManager daemon.
|
||||
</tp:docstring>
|
||||
|
@@ -7,8 +7,7 @@ AM_CPPFLAGS = \
|
||||
-DG_LOG_DOMAIN=\""libnm"\" \
|
||||
-DNETWORKMANAGER_COMPILATION \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(DBUS_CFLAGS)
|
||||
$(GLIB_CFLAGS)
|
||||
|
||||
noinst_LTLIBRARIES = libnm-core.la
|
||||
|
||||
@@ -30,7 +29,6 @@ GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
|
||||
|
||||
libnm_core_la_LIBADD = \
|
||||
$(GLIB_LIBS) \
|
||||
$(DBUS_LIBS) \
|
||||
$(UUID_LIBS)
|
||||
|
||||
if WITH_GNUTLS
|
||||
|
@@ -78,9 +78,4 @@ GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
|
||||
GDestroyNotify free_func);
|
||||
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
|
||||
|
@@ -29,9 +29,6 @@ gboolean _nm_utils_string_in_list (const char *str,
|
||||
gboolean _nm_utils_string_slist_validate (GSList *list,
|
||||
const char **valid_values);
|
||||
|
||||
gboolean _nm_utils_gvalue_array_validate (GValueArray *elements,
|
||||
guint n_expected, ...);
|
||||
|
||||
/* D-Bus transform funcs */
|
||||
|
||||
GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value);
|
||||
|
@@ -30,7 +30,6 @@
|
||||
#include "nm-utils.h"
|
||||
#include "nm-utils-private.h"
|
||||
#include "nm-glib-compat.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-setting-private.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;
|
||||
}
|
||||
|
||||
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
|
||||
_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;
|
||||
}
|
||||
|
||||
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:
|
||||
* @hash: a #GHashTable
|
||||
@@ -564,47 +491,6 @@ _nm_utils_hash_values_to_slist (GHashTable *hash)
|
||||
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 *
|
||||
_nm_utils_strdict_to_dbus (const GValue *prop_value)
|
||||
{
|
||||
@@ -1143,174 +1029,6 @@ nm_utils_wpa_psk_valid (const char *psk)
|
||||
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:
|
||||
* @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 */
|
||||
}
|
||||
|
||||
/**
|
||||
* 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:
|
||||
* @dns: (type utf8): an array of IP address strings
|
||||
|
@@ -49,8 +49,6 @@ gboolean nm_utils_same_ssid (const guint8 *ssid1, gsize len1,
|
||||
gboolean ignore_trailing_null);
|
||||
char * nm_utils_ssid_to_utf8 (const guint8 *ssid, gsize len);
|
||||
|
||||
GHashTable *nm_utils_gvalue_hash_dup (GHashTable *hash);
|
||||
|
||||
/**
|
||||
* NMUtilsSecurityType:
|
||||
* @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_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);
|
||||
char **nm_utils_ip4_dns_from_variant (GVariant *value);
|
||||
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_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);
|
||||
char **nm_utils_ip6_dns_from_variant (GVariant *value);
|
||||
GVariant *nm_utils_ip6_addresses_to_variant (GPtrArray *addresses);
|
||||
|
@@ -4,6 +4,7 @@ SUBDIRS = . tests
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/introspection \
|
||||
-I$(top_srcdir)/libnm-core \
|
||||
-I$(top_builddir)/libnm-core \
|
||||
-I$(top_srcdir)/libnm \
|
||||
@@ -12,7 +13,6 @@ AM_CPPFLAGS = \
|
||||
-DNETWORKMANAGER_COMPILATION \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(GUDEV_CFLAGS) \
|
||||
-DNMRUNDIR=\"$(nmrundir)\"
|
||||
|
||||
@@ -104,25 +104,15 @@ libnm_la_SOURCES = \
|
||||
$(libnm_la_csources) \
|
||||
$(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
|
||||
nm_enum_types_sources = $(libnminclude_HEADERS)
|
||||
GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include <nm-core-enum-types.h>\n'
|
||||
GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
|
||||
|
||||
BUILT_SOURCES = \
|
||||
nm-vpn-plugin-glue.h \
|
||||
nm-secret-agent-glue.h
|
||||
|
||||
libnm_la_LIBADD = \
|
||||
$(top_builddir)/libnm-core/libnm-core.la \
|
||||
$(top_builddir)/introspection/libnmdbus.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(DBUS_LIBS) \
|
||||
$(UUID_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
|
||||
pkgconfig_DATA = libnm.pc
|
||||
@@ -160,8 +150,8 @@ introspection_sources = \
|
||||
$(libnm_la_csources)
|
||||
|
||||
NM-1.0.gir: libnm.la
|
||||
NM_1_0_gir_INCLUDES = Gio-2.0 DBusGLib-1.0
|
||||
NM_1_0_gir_PACKAGES = gio-2.0 dbus-glib-1 gudev-1.0
|
||||
NM_1_0_gir_INCLUDES = Gio-2.0
|
||||
NM_1_0_gir_PACKAGES = gio-2.0 gudev-1.0
|
||||
NM_1_0_gir_EXPORT_PACKAGES = libnm
|
||||
NM_1_0_gir_CFLAGS = $(AM_CPPFLAGS)
|
||||
NM_1_0_gir_LIBS = libnm.la
|
||||
|
@@ -866,7 +866,6 @@ global:
|
||||
nm_utils_deinit;
|
||||
nm_utils_escape_ssid;
|
||||
nm_utils_file_is_pkcs12;
|
||||
nm_utils_gvalue_hash_dup;
|
||||
nm_utils_hex2byte;
|
||||
nm_utils_hexstr2bin;
|
||||
nm_utils_hwaddr_atoba;
|
||||
@@ -879,30 +878,20 @@ global:
|
||||
nm_utils_inet4_ntop;
|
||||
nm_utils_inet6_ntop;
|
||||
nm_utils_init;
|
||||
nm_utils_ip4_addresses_from_gvalue;
|
||||
nm_utils_ip4_addresses_from_variant;
|
||||
nm_utils_ip4_addresses_to_gvalue;
|
||||
nm_utils_ip4_addresses_to_variant;
|
||||
nm_utils_ip4_dns_from_variant;
|
||||
nm_utils_ip4_dns_to_variant;
|
||||
nm_utils_ip4_get_default_prefix;
|
||||
nm_utils_ip4_netmask_to_prefix;
|
||||
nm_utils_ip4_prefix_to_netmask;
|
||||
nm_utils_ip4_routes_from_gvalue;
|
||||
nm_utils_ip4_routes_from_variant;
|
||||
nm_utils_ip4_routes_to_gvalue;
|
||||
nm_utils_ip4_routes_to_variant;
|
||||
nm_utils_ip6_addresses_from_gvalue;
|
||||
nm_utils_ip6_addresses_from_variant;
|
||||
nm_utils_ip6_addresses_to_gvalue;
|
||||
nm_utils_ip6_addresses_to_variant;
|
||||
nm_utils_ip6_dns_from_gvalue;
|
||||
nm_utils_ip6_dns_from_variant;
|
||||
nm_utils_ip6_dns_to_gvalue;
|
||||
nm_utils_ip6_dns_to_variant;
|
||||
nm_utils_ip6_routes_from_gvalue;
|
||||
nm_utils_ip6_routes_from_variant;
|
||||
nm_utils_ip6_routes_to_gvalue;
|
||||
nm_utils_ip6_routes_to_variant;
|
||||
nm_utils_is_empty_ssid;
|
||||
nm_utils_is_uuid;
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include "nm-glib-compat.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,
|
||||
_nm_object_register_type_func (g_define_type_id,
|
||||
@@ -83,10 +83,10 @@ enum {
|
||||
};
|
||||
|
||||
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" */
|
||||
if (g_value_get_boolean (value))
|
||||
if (g_variant_get_boolean (value))
|
||||
return NM_TYPE_VPN_CONNECTION;
|
||||
else
|
||||
return NM_TYPE_ACTIVE_CONNECTION;
|
||||
|
@@ -19,7 +19,6 @@
|
||||
* Copyright 2007 - 2013 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <string.h>
|
||||
#include <nm-utils.h>
|
||||
|
||||
@@ -32,9 +31,10 @@
|
||||
#include "nm-active-connection.h"
|
||||
#include "nm-vpn-connection.h"
|
||||
#include "nm-object-cache.h"
|
||||
#include "nm-dbus-glib-types.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);
|
||||
|
||||
@@ -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))
|
||||
|
||||
typedef struct {
|
||||
DBusGProxy *client_proxy;
|
||||
NMDBusManager *manager_proxy;
|
||||
char *version;
|
||||
NMState state;
|
||||
gboolean startup;
|
||||
@@ -61,7 +61,7 @@ typedef struct {
|
||||
NMActiveConnection *primary_connection;
|
||||
NMActiveConnection *activating_connection;
|
||||
|
||||
DBusGProxyCall *perm_call;
|
||||
GCancellable *perm_call_cancellable;
|
||||
GHashTable *permissions;
|
||||
|
||||
/* 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));
|
||||
}
|
||||
|
||||
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 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);
|
||||
|
||||
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_DBUS_INTERFACE,
|
||||
property_info);
|
||||
|
||||
/* Permissions */
|
||||
dbus_g_proxy_add_signal (priv->client_proxy, "CheckPermissions", G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (priv->client_proxy,
|
||||
"CheckPermissions",
|
||||
G_CALLBACK (client_recheck_permissions),
|
||||
object,
|
||||
NULL);
|
||||
g_signal_connect (priv->manager_proxy, "check-permissions",
|
||||
G_CALLBACK (client_recheck_permissions), object);
|
||||
}
|
||||
|
||||
#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
|
||||
update_permissions (NMClient *self, GHashTable *permissions)
|
||||
update_permissions (NMClient *self, GVariant *permissions)
|
||||
{
|
||||
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
|
||||
GHashTableIter iter;
|
||||
@@ -278,11 +274,14 @@ update_permissions (NMClient *self, GHashTable *permissions)
|
||||
g_hash_table_remove_all (priv->permissions);
|
||||
|
||||
if (permissions) {
|
||||
GVariantIter viter;
|
||||
const char *pkey, *pvalue;
|
||||
|
||||
/* Process new permissions */
|
||||
g_hash_table_iter_init (&iter, permissions);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
||||
perm = nm_permission_to_client ((const char *) key);
|
||||
perm_result = nm_permission_result_to_client ((const char *) value);
|
||||
g_variant_iter_init (&viter, permissions);
|
||||
while (g_variant_iter_next (&viter, "{&s&s}", &pkey, &pvalue)) {
|
||||
perm = nm_permission_to_client (pkey);
|
||||
perm_result = nm_permission_result_to_client (pvalue);
|
||||
if (perm) {
|
||||
g_hash_table_insert (priv->permissions,
|
||||
GUINT_TO_POINTER (perm),
|
||||
@@ -319,48 +318,68 @@ update_permissions (NMClient *self, GHashTable *permissions)
|
||||
static gboolean
|
||||
get_permissions_sync (NMClient *self, GError **error)
|
||||
{
|
||||
gboolean success;
|
||||
GHashTable *permissions = NULL;
|
||||
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
|
||||
GVariant *permissions;
|
||||
|
||||
success = dbus_g_proxy_call_with_timeout (NM_CLIENT_GET_PRIVATE (self)->client_proxy,
|
||||
"GetPermissions", 3000, error,
|
||||
G_TYPE_INVALID,
|
||||
DBUS_TYPE_G_MAP_OF_STRING, &permissions, G_TYPE_INVALID);
|
||||
update_permissions (self, success ? permissions : NULL);
|
||||
if (permissions)
|
||||
g_hash_table_destroy (permissions);
|
||||
|
||||
return success;
|
||||
if (nmdbus_manager_call_get_permissions_sync (priv->manager_proxy,
|
||||
&permissions,
|
||||
NULL, error)) {
|
||||
update_permissions (self, permissions);
|
||||
g_variant_unref (permissions);
|
||||
return TRUE;
|
||||
} else {
|
||||
update_permissions (self, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_permissions_reply (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
get_permissions_reply (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMClient *self = NM_CLIENT (user_data);
|
||||
GHashTable *permissions;
|
||||
NMClient *self;
|
||||
NMClientPrivate *priv;
|
||||
GVariant *permissions = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_MAP_OF_STRING, &permissions,
|
||||
G_TYPE_INVALID);
|
||||
NM_CLIENT_GET_PRIVATE (self)->perm_call = NULL;
|
||||
update_permissions (NM_CLIENT (user_data), error ? NULL : permissions);
|
||||
/* WARNING: this may be called after the client is disposed, so we can't
|
||||
* look at self/priv until after we've determined that that isn't the case.
|
||||
*/
|
||||
|
||||
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_object (&priv->perm_call_cancellable);
|
||||
}
|
||||
|
||||
static void
|
||||
client_recheck_permissions (DBusGProxy *proxy, gpointer user_data)
|
||||
client_recheck_permissions (NMDBusManager *proxy, gpointer user_data)
|
||||
{
|
||||
NMClient *self = NM_CLIENT (user_data);
|
||||
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
|
||||
|
||||
if (!priv->perm_call) {
|
||||
priv->perm_call = dbus_g_proxy_begin_call (NM_CLIENT_GET_PRIVATE (self)->client_proxy, "GetPermissions",
|
||||
get_permissions_reply, self, NULL,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
if (priv->perm_call_cancellable)
|
||||
return;
|
||||
|
||||
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
|
||||
activate_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
activate_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
ActivateInfo *info = user_data;
|
||||
char *path;
|
||||
GError *error = NULL;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_OBJECT_PATH, &path,
|
||||
G_TYPE_INVALID);
|
||||
if (error) {
|
||||
if (nmdbus_manager_call_activate_connection_finish (NMDBUS_MANAGER (object),
|
||||
&info->active_path,
|
||||
result, &error)) {
|
||||
recheck_pending_activations (info->client, NULL, NULL);
|
||||
} else {
|
||||
activate_info_complete (info, NULL, error);
|
||||
activate_info_free (info);
|
||||
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;
|
||||
}
|
||||
|
||||
dbus_g_proxy_begin_call (priv->client_proxy, "ActivateConnection",
|
||||
activate_cb, info, NULL,
|
||||
DBUS_TYPE_G_OBJECT_PATH, connection ? nm_connection_get_path (connection) : "/",
|
||||
DBUS_TYPE_G_OBJECT_PATH, device ? nm_object_get_path (NM_OBJECT (device)) : "/",
|
||||
DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/",
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_manager_call_activate_connection (priv->manager_proxy,
|
||||
connection ? nm_connection_get_path (connection) : "/",
|
||||
device ? nm_object_get_path (NM_OBJECT (device)) : "/",
|
||||
specific_object ? specific_object : "/",
|
||||
NULL,
|
||||
activate_cb, info);
|
||||
}
|
||||
|
||||
static void
|
||||
add_activate_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
add_activate_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
ActivateInfo *info = user_data;
|
||||
char *connection_path;
|
||||
char *active_path;
|
||||
GError *error = NULL;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_OBJECT_PATH, &connection_path,
|
||||
DBUS_TYPE_G_OBJECT_PATH, &active_path,
|
||||
G_TYPE_INVALID);
|
||||
if (error) {
|
||||
if (nmdbus_manager_call_add_and_activate_connection_finish (NMDBUS_MANAGER (object),
|
||||
&info->new_connection_path,
|
||||
&info->active_path,
|
||||
result, &error)) {
|
||||
recheck_pending_activations (info->client, NULL, NULL);
|
||||
} else {
|
||||
activate_info_complete (info, NULL, error);
|
||||
activate_info_free (info);
|
||||
} else {
|
||||
info->new_connection_path = connection_path;
|
||||
info->active_path = active_path;
|
||||
recheck_pending_activations (info->client, NULL, NULL);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,7 +720,7 @@ nm_client_add_and_activate_connection (NMClient *client,
|
||||
{
|
||||
NMClientPrivate *priv;
|
||||
ActivateInfo *info;
|
||||
GHashTable *hash = NULL;
|
||||
GVariant *dict = NULL;
|
||||
|
||||
g_return_if_fail (NM_IS_CLIENT (client));
|
||||
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->client = client;
|
||||
|
||||
if (partial) {
|
||||
GVariant *dict;
|
||||
|
||||
if (partial)
|
||||
dict = nm_connection_to_dbus (partial, NM_CONNECTION_SERIALIZE_ALL);
|
||||
hash = _nm_utils_connection_dict_to_hash (dict);
|
||||
g_variant_unref (dict);
|
||||
}
|
||||
if (!hash)
|
||||
hash = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
if (!dict)
|
||||
dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
|
||||
|
||||
priv = NM_CLIENT_GET_PRIVATE (client);
|
||||
priv->pending_activations = g_slist_prepend (priv->pending_activations, info);
|
||||
|
||||
if (nm_client_get_nm_running (client)) {
|
||||
dbus_g_proxy_begin_call (priv->client_proxy, "AddAndActivateConnection",
|
||||
add_activate_cb, info, NULL,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash,
|
||||
DBUS_TYPE_G_OBJECT_PATH, nm_object_get_path (NM_OBJECT (device)),
|
||||
DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/",
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_manager_call_add_and_activate_connection (priv->manager_proxy,
|
||||
dict,
|
||||
nm_object_get_path (NM_OBJECT (device)),
|
||||
specific_object ? specific_object : "/",
|
||||
NULL,
|
||||
add_activate_cb, info);
|
||||
} else
|
||||
info->idle_id = g_idle_add (activate_nm_not_running, info);
|
||||
|
||||
g_hash_table_unref (hash);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -779,10 +784,9 @@ nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active)
|
||||
return;
|
||||
|
||||
path = nm_object_get_path (NM_OBJECT (active));
|
||||
if (!dbus_g_proxy_call (priv->client_proxy, "DeactivateConnection", &error,
|
||||
DBUS_TYPE_G_OBJECT_PATH, path,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID)) {
|
||||
if (!nmdbus_manager_call_deactivate_connection_sync (priv->manager_proxy,
|
||||
path,
|
||||
NULL, &error)) {
|
||||
g_warning ("Could not deactivate connection '%s': %s", path, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
@@ -838,20 +842,15 @@ nm_client_wireless_get_enabled (NMClient *client)
|
||||
void
|
||||
nm_client_wireless_set_enabled (NMClient *client, gboolean enabled)
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_return_if_fail (NM_IS_CLIENT (client));
|
||||
|
||||
if (!nm_client_get_nm_running (client))
|
||||
return;
|
||||
|
||||
g_value_init (&value, G_TYPE_BOOLEAN);
|
||||
g_value_set_boolean (&value, enabled);
|
||||
|
||||
_nm_object_set_property (NM_OBJECT (client),
|
||||
NM_DBUS_INTERFACE,
|
||||
"WirelessEnabled",
|
||||
&value);
|
||||
"b", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -896,20 +895,15 @@ nm_client_wwan_get_enabled (NMClient *client)
|
||||
void
|
||||
nm_client_wwan_set_enabled (NMClient *client, gboolean enabled)
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_return_if_fail (NM_IS_CLIENT (client));
|
||||
|
||||
if (!nm_client_get_nm_running (client))
|
||||
return;
|
||||
|
||||
g_value_init (&value, G_TYPE_BOOLEAN);
|
||||
g_value_set_boolean (&value, enabled);
|
||||
|
||||
_nm_object_set_property (NM_OBJECT (client),
|
||||
NM_DBUS_INTERFACE,
|
||||
"WwanEnabled",
|
||||
&value);
|
||||
"b", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -954,20 +948,15 @@ nm_client_wimax_get_enabled (NMClient *client)
|
||||
void
|
||||
nm_client_wimax_set_enabled (NMClient *client, gboolean enabled)
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_return_if_fail (NM_IS_CLIENT (client));
|
||||
|
||||
if (!nm_client_get_nm_running (client))
|
||||
return;
|
||||
|
||||
g_value_init (&value, G_TYPE_BOOLEAN);
|
||||
g_value_set_boolean (&value, enabled);
|
||||
|
||||
_nm_object_set_property (NM_OBJECT (client),
|
||||
NM_DBUS_INTERFACE,
|
||||
"WimaxEnabled",
|
||||
&value);
|
||||
"b", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1073,10 +1062,9 @@ nm_client_networking_set_enabled (NMClient *client, gboolean enable)
|
||||
if (!nm_client_get_nm_running (client))
|
||||
return;
|
||||
|
||||
if (!dbus_g_proxy_call (NM_CLIENT_GET_PRIVATE (client)->client_proxy, "Enable", &err,
|
||||
G_TYPE_BOOLEAN, enable,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID)) {
|
||||
if (!nmdbus_manager_call_enable_sync (NM_CLIENT_GET_PRIVATE (client)->manager_proxy,
|
||||
enable,
|
||||
NULL, &err)) {
|
||||
g_warning ("Error enabling/disabling networking: %s", err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
@@ -1154,11 +1142,9 @@ nm_client_get_logging (NMClient *client, char **level, char **domains, GError **
|
||||
if (!level && !domains)
|
||||
return TRUE;
|
||||
|
||||
return dbus_g_proxy_call (priv->client_proxy, "GetLogging", error,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_STRING, level,
|
||||
G_TYPE_STRING, domains,
|
||||
G_TYPE_INVALID);
|
||||
return nmdbus_manager_call_get_logging_sync (priv->manager_proxy,
|
||||
level, domains,
|
||||
NULL, error);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1193,11 +1179,9 @@ nm_client_set_logging (NMClient *client, const char *level, const char *domains,
|
||||
if (!level && !domains)
|
||||
return TRUE;
|
||||
|
||||
return dbus_g_proxy_call (priv->client_proxy, "SetLogging", error,
|
||||
G_TYPE_STRING, level ? level : "",
|
||||
G_TYPE_STRING, domains ? domains : "",
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID);
|
||||
return nmdbus_manager_call_set_logging_sync (priv->manager_proxy,
|
||||
level, domains,
|
||||
NULL, error);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1349,7 +1333,7 @@ nm_running_changed_cb (GObject *object,
|
||||
} else {
|
||||
_nm_object_suppress_property_updates (NM_OBJECT (client), FALSE);
|
||||
_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)
|
||||
{
|
||||
NMClientPrivate *priv;
|
||||
NMConnectivityState connectivity;
|
||||
guint32 connectivity;
|
||||
|
||||
g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
|
||||
priv = NM_CLIENT_GET_PRIVATE (client);
|
||||
|
||||
if (!dbus_g_proxy_call (priv->client_proxy, "CheckConnectivity", error,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_UINT, &connectivity,
|
||||
G_TYPE_INVALID))
|
||||
connectivity = 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);
|
||||
if (nmdbus_manager_call_check_connectivity_sync (priv->manager_proxy,
|
||||
&connectivity,
|
||||
cancellable, error))
|
||||
return connectivity;
|
||||
else
|
||||
return NM_CONNECTIVITY_UNKNOWN;
|
||||
}
|
||||
|
||||
static void
|
||||
check_connectivity_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
check_connectivity_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple = user_data;
|
||||
CheckConnectivityData *ccd = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
guint32 connectivity;
|
||||
GError *error = NULL;
|
||||
|
||||
if (ccd->cancellable) {
|
||||
g_signal_handler_disconnect (ccd->cancellable, ccd->cancelled_id);
|
||||
ccd->cancelled_id = 0;
|
||||
}
|
||||
|
||||
if (!dbus_g_proxy_end_call (proxy, call, &error,
|
||||
G_TYPE_UINT, &ccd->connectivity,
|
||||
G_TYPE_INVALID))
|
||||
if (nmdbus_manager_call_check_connectivity_finish (NMDBUS_MANAGER (object),
|
||||
&connectivity,
|
||||
result, &error))
|
||||
g_simple_async_result_set_op_res_gssize (simple, connectivity);
|
||||
else
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
|
||||
g_simple_async_result_complete (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:
|
||||
* @client: an #NMClient
|
||||
@@ -1484,29 +1430,15 @@ nm_client_check_connectivity_async (NMClient *client,
|
||||
{
|
||||
NMClientPrivate *priv;
|
||||
GSimpleAsyncResult *simple;
|
||||
CheckConnectivityData *ccd;
|
||||
|
||||
g_return_if_fail (NM_IS_CLIENT (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,
|
||||
nm_client_check_connectivity_async);
|
||||
g_simple_async_result_set_op_res_gpointer (simple, ccd, (GDestroyNotify) check_connectivity_data_free);
|
||||
|
||||
if (cancellable) {
|
||||
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);
|
||||
nmdbus_manager_call_check_connectivity (priv->manager_proxy,
|
||||
cancellable,
|
||||
check_connectivity_cb, simple);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1526,17 +1458,14 @@ nm_client_check_connectivity_finish (NMClient *client,
|
||||
GError **error)
|
||||
{
|
||||
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);
|
||||
|
||||
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))
|
||||
return NM_CONNECTIVITY_UNKNOWN;
|
||||
|
||||
return ccd->connectivity;
|
||||
return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
@@ -1731,6 +1660,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
||||
|
||||
typedef struct {
|
||||
NMClient *client;
|
||||
GCancellable *cancellable;
|
||||
GSimpleAsyncResult *result;
|
||||
} NMClientInitData;
|
||||
|
||||
@@ -1739,22 +1669,23 @@ init_async_complete (NMClientInitData *init_data)
|
||||
{
|
||||
g_simple_async_result_complete (init_data->result);
|
||||
g_object_unref (init_data->result);
|
||||
g_clear_object (&init_data->cancellable);
|
||||
g_slice_free (NMClientInitData, init_data);
|
||||
}
|
||||
|
||||
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;
|
||||
GHashTable *permissions;
|
||||
GError *error = NULL;
|
||||
GVariant *permissions;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_MAP_OF_STRING, &permissions,
|
||||
G_TYPE_INVALID);
|
||||
update_permissions (init_data->client, error ? NULL : permissions);
|
||||
if (error)
|
||||
g_simple_async_result_take_error (init_data->result, error);
|
||||
if (nmdbus_manager_call_get_permissions_finish (NMDBUS_MANAGER (object),
|
||||
&permissions,
|
||||
result, NULL)) {
|
||||
update_permissions (init_data->client, permissions);
|
||||
g_variant_unref (permissions);
|
||||
} else
|
||||
update_permissions (init_data->client, NULL);
|
||||
|
||||
init_async_complete (init_data);
|
||||
}
|
||||
@@ -1777,9 +1708,9 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_g_proxy_begin_call (priv->client_proxy, "GetPermissions",
|
||||
init_async_got_permissions, init_data, NULL,
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_manager_call_get_permissions (priv->manager_proxy,
|
||||
init_data->cancellable,
|
||||
init_async_got_permissions, init_data);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1798,6 +1729,7 @@ init_async (GAsyncInitable *initable, int io_priority,
|
||||
|
||||
init_data = g_slice_new0 (NMClientInitData);
|
||||
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,
|
||||
user_data, init_async);
|
||||
g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
|
||||
@@ -1823,9 +1755,9 @@ dispose (GObject *object)
|
||||
NMClient *client = NM_CLIENT (object);
|
||||
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
|
||||
|
||||
if (priv->perm_call) {
|
||||
dbus_g_proxy_cancel_call (priv->client_proxy, priv->perm_call);
|
||||
priv->perm_call = NULL;
|
||||
if (priv->perm_call_cancellable) {
|
||||
g_cancellable_cancel (priv->perm_call_cancellable);
|
||||
g_clear_object (&priv->perm_call_cancellable);
|
||||
}
|
||||
|
||||
free_devices (client, TRUE);
|
||||
@@ -1967,6 +1899,7 @@ nm_client_class_init (NMClientClass *client_class)
|
||||
g_type_class_add_private (client_class, sizeof (NMClientPrivate));
|
||||
|
||||
_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 */
|
||||
object_class->constructor = constructor;
|
||||
|
@@ -21,59 +21,100 @@
|
||||
#include <string.h>
|
||||
#include <config.h>
|
||||
#include <gio/gio.h>
|
||||
#include <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
#include "nm-dbus-helpers.h"
|
||||
#include "nm-dbus-interface.h"
|
||||
|
||||
static dbus_int32_t priv_slot = -1;
|
||||
static DBusBusType nm_bus = DBUS_BUS_SYSTEM;
|
||||
#define NM_DBUS_PRIVATE_CONNECTION_TAG "libnm-private-connection"
|
||||
static GBusType nm_bus = G_BUS_TYPE_SYSTEM;
|
||||
|
||||
static void
|
||||
_ensure_nm_dbus_helpers_inited (void)
|
||||
GBusType
|
||||
_nm_dbus_bus_type (void)
|
||||
{
|
||||
static gsize init_value = 0;
|
||||
|
||||
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"))
|
||||
nm_bus = DBUS_BUS_SESSION;
|
||||
nm_bus = G_BUS_TYPE_SESSION;
|
||||
|
||||
g_once_init_leave (&init_value, 1);
|
||||
}
|
||||
|
||||
return nm_bus;
|
||||
}
|
||||
|
||||
DBusGConnection *
|
||||
_nm_dbus_new_connection (GCancellable *cancellable,
|
||||
GError **error)
|
||||
GDBusConnection *
|
||||
_nm_dbus_new_connection (GCancellable *cancellable, 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 (0 == geteuid () && nm_bus == DBUS_BUS_SYSTEM) {
|
||||
connection = dbus_g_connection_open ("unix:path=" NMRUNDIR "/private", error);
|
||||
if (connection) {
|
||||
DBusConnection *dbus_connection = dbus_g_connection_get_connection (connection);
|
||||
if (0 == geteuid ()) {
|
||||
GError *local = NULL;
|
||||
|
||||
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 */
|
||||
dbus_connection_set_data (dbus_connection, priv_slot, GUINT_TO_POINTER (TRUE), NULL);
|
||||
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
|
||||
g_object_set_data (G_OBJECT (connection),
|
||||
NM_DBUS_PRIVATE_CONNECTION_TAG,
|
||||
GUINT_TO_POINTER (TRUE));
|
||||
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)
|
||||
connection = dbus_g_bus_get (nm_bus, error);
|
||||
return g_bus_get_sync (_nm_dbus_bus_type (), cancellable, 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
|
||||
@@ -82,22 +123,26 @@ _nm_dbus_new_connection_async (GCancellable *cancellable,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
DBusGConnection *connection;
|
||||
GError *error = NULL;
|
||||
|
||||
simple = g_simple_async_result_new (NULL, callback, user_data,
|
||||
_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);
|
||||
simple = g_simple_async_result_new (NULL, callback, user_data, _nm_dbus_new_connection_async);
|
||||
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
/* If running as root try the private bus first */
|
||||
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,
|
||||
GError **error)
|
||||
{
|
||||
@@ -106,68 +151,195 @@ _nm_dbus_new_connection_finish (GAsyncResult *result,
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
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
|
||||
_nm_dbus_is_connection_private (DBusGConnection *connection)
|
||||
_nm_dbus_is_connection_private (GDBusConnection *connection)
|
||||
{
|
||||
if (priv_slot == -1)
|
||||
return FALSE;
|
||||
return !!dbus_connection_get_data (dbus_g_connection_get_connection (connection), priv_slot);
|
||||
return !!g_object_get_data (G_OBJECT (connection), NM_DBUS_PRIVATE_CONNECTION_TAG);
|
||||
}
|
||||
|
||||
DBusGProxy *
|
||||
_nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
|
||||
static GHashTable *proxy_types;
|
||||
|
||||
#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 *interface,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
/* Private connections can't use dbus_g_proxy_new_for_name() or
|
||||
* dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't
|
||||
* 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);
|
||||
GType proxy_type;
|
||||
const char *name;
|
||||
|
||||
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
|
||||
_nm_dbus_new_proxy_for_connection_async (DBusGConnection *connection,
|
||||
_nm_dbus_new_proxy_for_connection_async (GDBusConnection *connection,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
DBusGProxy *proxy;
|
||||
GError *error = NULL;
|
||||
GType proxy_type;
|
||||
const char *name;
|
||||
|
||||
simple = g_simple_async_result_new (NULL, callback, user_data,
|
||||
_nm_dbus_new_proxy_for_connection_async);
|
||||
proxy = _nm_dbus_new_proxy_for_connection (connection, path, interface,
|
||||
cancellable, &error);
|
||||
if (proxy)
|
||||
g_simple_async_result_set_op_res_gpointer (simple, proxy, g_object_unref);
|
||||
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
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
name = NM_DBUS_SERVICE;
|
||||
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_async_initable_new_async (proxy_type, G_PRIORITY_DEFAULT,
|
||||
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,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
GObject *source, *proxy;
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
source = g_async_result_get_source_object (result);
|
||||
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);
|
||||
}
|
||||
|
@@ -22,36 +22,61 @@
|
||||
#define __NM_DBUS_HELPERS_PRIVATE_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);
|
||||
|
||||
void _nm_dbus_new_connection_async (GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
DBusGConnection *_nm_dbus_new_connection_finish (GAsyncResult *result,
|
||||
GDBusConnection *_nm_dbus_new_connection_finish (GAsyncResult *result,
|
||||
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,
|
||||
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 *interface,
|
||||
GCancellable *cancellable,
|
||||
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 *interface,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
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);
|
||||
|
||||
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__ */
|
||||
|
@@ -33,8 +33,10 @@
|
||||
#include "nm-device-private.h"
|
||||
#include "nm-object-private.h"
|
||||
#include "nm-object-cache.h"
|
||||
#include "nm-dbus-glib-types.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)
|
||||
|
||||
@@ -45,12 +47,13 @@ static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user
|
||||
|
||||
typedef struct {
|
||||
NMDeviceWifi *device;
|
||||
GCancellable *cancellable;
|
||||
NMDeviceWifiRequestScanFn callback;
|
||||
gpointer user_data;
|
||||
} RequestScanInfo;
|
||||
|
||||
typedef struct {
|
||||
DBusGProxy *proxy;
|
||||
NMDBusDeviceWifi *proxy;
|
||||
|
||||
char *hw_address;
|
||||
char *perm_hw_address;
|
||||
@@ -60,7 +63,6 @@ typedef struct {
|
||||
NMDeviceWifiCapabilities wireless_caps;
|
||||
GPtrArray *aps;
|
||||
|
||||
DBusGProxyCall *scan_call;
|
||||
RequestScanInfo *scan_info;
|
||||
} NMDeviceWifiPrivate;
|
||||
|
||||
@@ -286,24 +288,27 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,
|
||||
}
|
||||
|
||||
static void
|
||||
request_scan_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
request_scan_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer 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);
|
||||
|
||||
g_clear_error (&error);
|
||||
g_slice_free (RequestScanInfo, info);
|
||||
g_clear_error (&error);
|
||||
priv->scan_info = NULL;
|
||||
}
|
||||
|
||||
priv->scan_call = NULL;
|
||||
priv->scan_info = NULL;
|
||||
g_clear_object (&info->cancellable);
|
||||
g_slice_free (RequestScanInfo, info);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,29 +327,25 @@ nm_device_wifi_request_scan_simple (NMDeviceWifi *device,
|
||||
gpointer user_data)
|
||||
{
|
||||
RequestScanInfo *info;
|
||||
GHashTable *options;
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
|
||||
|
||||
g_return_if_fail (NM_IS_DEVICE_WIFI (device));
|
||||
|
||||
/* If a scan is in progress, just return */
|
||||
if (priv->scan_call)
|
||||
if (priv->scan_info)
|
||||
return;
|
||||
|
||||
options = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
||||
info = g_slice_new0 (RequestScanInfo);
|
||||
info->device = device;
|
||||
info->cancellable = g_cancellable_new ();
|
||||
info->callback = callback;
|
||||
info->user_data = user_data;
|
||||
|
||||
priv->scan_info = info;
|
||||
priv->scan_call = dbus_g_proxy_begin_call (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, "RequestScan",
|
||||
request_scan_cb, info, NULL,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT, options,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
g_hash_table_unref (options);
|
||||
nmdbus_device_wifi_call_request_scan (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
|
||||
g_variant_new_array (G_VARIANT_TYPE_VARDICT, NULL, 0),
|
||||
info->cancellable,
|
||||
request_scan_cb, info);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -594,7 +595,7 @@ init_dbus (NMObject *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_DBUS_INTERFACE_DEVICE_WIRELESS,
|
||||
property_info);
|
||||
@@ -621,19 +622,22 @@ dispose (GObject *object)
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
|
||||
GError *error = NULL;
|
||||
|
||||
if (priv->scan_call) {
|
||||
g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN,
|
||||
"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);
|
||||
if (priv->scan_info) {
|
||||
RequestScanInfo *scan_info;
|
||||
|
||||
dbus_g_proxy_cancel_call (priv->proxy, priv->scan_call);
|
||||
priv->scan_call = NULL;
|
||||
scan_info = priv->scan_info;
|
||||
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)
|
||||
@@ -663,6 +667,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
|
||||
g_type_class_add_private (wifi_class, sizeof (NMDeviceWifiPrivate));
|
||||
|
||||
_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 */
|
||||
object_class->get_property = get_property;
|
||||
|
@@ -31,7 +31,6 @@
|
||||
#include "nm-device-wimax.h"
|
||||
#include "nm-object-private.h"
|
||||
#include "nm-object-cache.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-core-internal.h"
|
||||
#include "nm-device-private.h"
|
||||
|
||||
|
@@ -44,12 +44,13 @@
|
||||
#include "nm-object-cache.h"
|
||||
#include "nm-remote-connection.h"
|
||||
#include "nm-core-internal.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-glib-compat.h"
|
||||
#include "nm-utils.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);
|
||||
|
||||
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))
|
||||
|
||||
typedef struct {
|
||||
DBusGProxy *proxy;
|
||||
NMDBusDevice *proxy;
|
||||
|
||||
char *iface;
|
||||
char *ip_iface;
|
||||
@@ -159,29 +160,21 @@ nm_device_init (NMDevice *device)
|
||||
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
|
||||
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;
|
||||
|
||||
if (!G_VALUE_HOLDS (value, DBUS_G_TYPE_UINT_STRUCT))
|
||||
return FALSE;
|
||||
|
||||
dbus_g_type_struct_get (value,
|
||||
1, reason_field,
|
||||
G_MAXUINT);
|
||||
|
||||
g_variant_get (value, "(uu)", NULL, reason_field);
|
||||
_nm_object_queue_notify (object, NM_DEVICE_STATE_REASON);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
device_state_changed (DBusGProxy *proxy,
|
||||
NMDeviceState new_state,
|
||||
NMDeviceState old_state,
|
||||
NMDeviceStateReason reason,
|
||||
device_state_changed (NMDBusDevice *proxy,
|
||||
guint new_state,
|
||||
guint old_state,
|
||||
guint reason,
|
||||
gpointer user_data);
|
||||
|
||||
static void
|
||||
@@ -219,26 +212,13 @@ init_dbus (NMObject *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_DBUS_INTERFACE_DEVICE,
|
||||
property_info);
|
||||
|
||||
dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
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);
|
||||
|
||||
g_signal_connect (priv->proxy, "state-changed",
|
||||
G_CALLBACK (device_state_changed), object);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
@@ -281,33 +261,33 @@ device_state_change_reloaded (GObject *object,
|
||||
}
|
||||
|
||||
static void
|
||||
device_state_changed (DBusGProxy *proxy,
|
||||
NMDeviceState new_state,
|
||||
NMDeviceState old_state,
|
||||
NMDeviceStateReason reason,
|
||||
device_state_changed (NMDBusDevice *proxy,
|
||||
guint new_state,
|
||||
guint old_state,
|
||||
guint reason,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMDevice *self = NM_DEVICE (user_data);
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
StateChangeData *data;
|
||||
|
||||
if (old_state != new_state) {
|
||||
StateChangeData *data;
|
||||
if (old_state == new_state)
|
||||
return;
|
||||
|
||||
/* Our object-valued properties (eg, ip4_config) will still
|
||||
* have their old values at this point, because NMObject is
|
||||
* in the process of asynchronously reading the new values.
|
||||
* Wait for that to finish before emitting the signal.
|
||||
*/
|
||||
priv->last_seen_state = new_state;
|
||||
/* Our object-valued properties (eg, ip4_config) will still
|
||||
* have their old values at this point, because NMObject is
|
||||
* in the process of asynchronously reading the new values.
|
||||
* Wait for that to finish before emitting the signal.
|
||||
*/
|
||||
priv->last_seen_state = new_state;
|
||||
|
||||
data = g_slice_new (StateChangeData);
|
||||
data->old_state = old_state;
|
||||
data->new_state = new_state;
|
||||
data->reason = reason;
|
||||
_nm_object_reload_properties_async (NM_OBJECT (user_data),
|
||||
device_state_change_reloaded,
|
||||
data);
|
||||
}
|
||||
data = g_slice_new (StateChangeData);
|
||||
data->old_state = old_state;
|
||||
data->new_state = new_state;
|
||||
data->reason = reason;
|
||||
_nm_object_reload_properties_async (NM_OBJECT (user_data),
|
||||
device_state_change_reloaded,
|
||||
data);
|
||||
}
|
||||
|
||||
static GType
|
||||
@@ -518,6 +498,7 @@ nm_device_class_init (NMDeviceClass *device_class)
|
||||
g_type_class_add_private (device_class, sizeof (NMDevicePrivate));
|
||||
|
||||
_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 */
|
||||
object_class->constructed = constructed;
|
||||
@@ -862,9 +843,9 @@ _nm_device_set_device_type (NMDevice *device, NMDeviceType dtype)
|
||||
}
|
||||
|
||||
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
|
||||
nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect)
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
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_object_set_property (NM_OBJECT (device),
|
||||
NM_DBUS_INTERFACE_DEVICE,
|
||||
"Autoconnect",
|
||||
&value);
|
||||
"b", autoconnect);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1921,28 +1896,24 @@ typedef struct {
|
||||
NMDevice *device;
|
||||
NMDeviceCallbackFn fn;
|
||||
gpointer user_data;
|
||||
const char *method;
|
||||
} DeviceCallbackInfo;
|
||||
|
||||
static void
|
||||
device_operation_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
gpointer user_data)
|
||||
device_disconnect_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
DeviceCallbackInfo *info = user_data;
|
||||
GError *error = NULL;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_device_call_disconnect_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 %s failed: (%d) %s",
|
||||
g_warning ("%s: device %s disconnect failed: %s",
|
||||
__func__,
|
||||
nm_object_get_path (NM_OBJECT (info->device)),
|
||||
info->method,
|
||||
error ? error->code : -1,
|
||||
error && error->message ? error->message : "(unknown)");
|
||||
error->message);
|
||||
}
|
||||
g_clear_error (&error);
|
||||
|
||||
@@ -1973,12 +1944,34 @@ nm_device_disconnect (NMDevice *device,
|
||||
info = g_slice_new (DeviceCallbackInfo);
|
||||
info->fn = callback;
|
||||
info->user_data = user_data;
|
||||
info->method = "Disconnect";
|
||||
info->device = g_object_ref (device);
|
||||
|
||||
dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Disconnect",
|
||||
device_operation_cb, info, NULL,
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_device_call_disconnect (NM_DEVICE_GET_PRIVATE (device)->proxy,
|
||||
NULL,
|
||||
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->fn = callback;
|
||||
info->user_data = user_data;
|
||||
info->method = "Delete";
|
||||
info->device = g_object_ref (device);
|
||||
|
||||
dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Delete",
|
||||
device_operation_cb, info, NULL,
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_device_call_delete (NM_DEVICE_GET_PRIVATE (device)->proxy,
|
||||
NULL,
|
||||
device_delete_cb, info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -50,21 +50,19 @@ nm_dhcp4_config_init (NMDhcp4Config *config)
|
||||
}
|
||||
|
||||
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);
|
||||
GHashTable *new_options;
|
||||
GHashTableIter iter;
|
||||
GVariantIter iter;
|
||||
const char *key;
|
||||
GValue *opt;
|
||||
GVariant *opt;
|
||||
|
||||
g_hash_table_remove_all (priv->options);
|
||||
|
||||
new_options = g_value_get_boxed (value);
|
||||
if (new_options) {
|
||||
g_hash_table_iter_init (&iter, new_options);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt))
|
||||
g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
|
||||
g_variant_iter_init (&iter, value);
|
||||
while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
|
||||
g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
|
||||
g_variant_unref (opt);
|
||||
}
|
||||
|
||||
_nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS);
|
||||
|
@@ -50,21 +50,19 @@ nm_dhcp6_config_init (NMDhcp6Config *config)
|
||||
}
|
||||
|
||||
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);
|
||||
GHashTable *new_options;
|
||||
GHashTableIter iter;
|
||||
GVariantIter iter;
|
||||
const char *key;
|
||||
GValue *opt;
|
||||
GVariant *opt;
|
||||
|
||||
g_hash_table_remove_all (priv->options);
|
||||
|
||||
new_options = g_value_get_boxed (value);
|
||||
if (new_options) {
|
||||
g_hash_table_iter_init (&iter, new_options);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt))
|
||||
g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt));
|
||||
g_variant_iter_init (&iter, value);
|
||||
while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
|
||||
g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
|
||||
g_variant_unref (opt);
|
||||
}
|
||||
|
||||
_nm_object_queue_notify (object, NM_DHCP6_CONFIG_OPTIONS);
|
||||
|
@@ -34,8 +34,8 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_OBJECT)
|
||||
|
||||
typedef struct {
|
||||
char *gateway;
|
||||
GSList *addresses;
|
||||
GSList *routes;
|
||||
GPtrArray *addresses;
|
||||
GPtrArray *routes;
|
||||
char **nameservers;
|
||||
char **domains;
|
||||
char **searches;
|
||||
@@ -60,6 +60,8 @@ nm_ip4_config_init (NMIP4Config *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->domains = g_new0 (char *, 1);
|
||||
priv->searches = g_new0 (char *, 1);
|
||||
@@ -67,58 +69,39 @@ nm_ip4_config_init (NMIP4Config *config)
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
|
||||
priv->addresses = NULL;
|
||||
|
||||
priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
|
||||
g_ptr_array_unref (priv->addresses);
|
||||
priv->addresses = nm_utils_ip4_addresses_from_variant (value);
|
||||
_nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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;
|
||||
int i;
|
||||
|
||||
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY))
|
||||
return FALSE;
|
||||
|
||||
ip_array = g_value_get_boxed (value);
|
||||
|
||||
obj_field = field;
|
||||
if (*obj_field)
|
||||
g_strfreev (*obj_field);
|
||||
|
||||
*obj_field = g_new (char *, ip_array->len + 1);
|
||||
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;
|
||||
*obj_field = nm_utils_ip4_dns_from_variant (value);
|
||||
|
||||
_nm_object_queue_notify (object, pspec->name);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
||||
priv->routes = NULL;
|
||||
|
||||
priv->routes = nm_utils_ip4_routes_from_gvalue (value);
|
||||
g_ptr_array_unref (priv->routes);
|
||||
priv->routes = nm_utils_ip4_routes_from_variant (value);
|
||||
_nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES);
|
||||
|
||||
return TRUE;
|
||||
@@ -153,8 +136,8 @@ finalize (GObject *object)
|
||||
|
||||
g_free (priv->gateway);
|
||||
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
|
||||
g_ptr_array_unref (priv->addresses);
|
||||
g_ptr_array_unref (priv->routes);
|
||||
|
||||
g_strfreev (priv->nameservers);
|
||||
g_strfreev (priv->domains);
|
||||
@@ -171,21 +154,20 @@ get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
NMIP4Config *self = NM_IP4_CONFIG (object);
|
||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_GATEWAY:
|
||||
g_value_set_string (value, nm_ip4_config_get_gateway (self));
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses,
|
||||
(NMUtilsCopyFunc) nm_ip4_address_dup,
|
||||
(GDestroyNotify) nm_ip4_address_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_array (nm_ip4_config_get_addresses (self),
|
||||
(NMUtilsCopyFunc) nm_ip4_address_dup,
|
||||
(GDestroyNotify) nm_ip4_address_unref));
|
||||
break;
|
||||
case PROP_ROUTES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes,
|
||||
(NMUtilsCopyFunc) nm_ip4_route_dup,
|
||||
(GDestroyNotify) nm_ip4_route_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_array (nm_ip4_config_get_routes (self),
|
||||
(NMUtilsCopyFunc) nm_ip4_route_dup,
|
||||
(GDestroyNotify) nm_ip4_route_unref));
|
||||
break;
|
||||
case PROP_NAMESERVERS:
|
||||
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).
|
||||
*
|
||||
* Returns: (element-type NMIP4Address) (transfer none): the #GSList containing #NMIP4Address<!-- -->es.
|
||||
* This is the internal copy used by the configuration and must not be modified.
|
||||
* Returns: (element-type NMIP4Address) (transfer none): the #GPtrArray
|
||||
* 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)
|
||||
{
|
||||
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.
|
||||
*
|
||||
* Returns: (element-type NMIP4Route) (transfer none): the #GSList containing
|
||||
* #NMIP4Routes. This is the internal copy used by the configuration,
|
||||
* and must not be modified.
|
||||
* Returns: (element-type NMIP4Route) (transfer none): the #GPtrArray containing
|
||||
* #NMIP4Routes. This is the internal copy used by the configuration, and must
|
||||
* not be modified.
|
||||
**/
|
||||
const GSList *
|
||||
GPtrArray *
|
||||
nm_ip4_config_get_routes (NMIP4Config *config)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
|
||||
|
@@ -61,8 +61,8 @@ typedef struct {
|
||||
GType nm_ip4_config_get_type (void);
|
||||
|
||||
const char * nm_ip4_config_get_gateway (NMIP4Config *config);
|
||||
const GSList * nm_ip4_config_get_addresses (NMIP4Config *config);
|
||||
const GSList * nm_ip4_config_get_routes (NMIP4Config *config);
|
||||
GPtrArray * nm_ip4_config_get_addresses (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_domains (NMIP4Config *config);
|
||||
const char * const *nm_ip4_config_get_searches (NMIP4Config *config);
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "nm-dbus-interface.h"
|
||||
#include "nm-object-private.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
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 {
|
||||
char *gateway;
|
||||
GSList *addresses;
|
||||
GSList *routes;
|
||||
GPtrArray *addresses;
|
||||
GPtrArray *routes;
|
||||
char **nameservers;
|
||||
char **domains;
|
||||
char **searches;
|
||||
@@ -55,58 +54,39 @@ enum {
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
|
||||
priv->addresses = NULL;
|
||||
|
||||
priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
|
||||
g_ptr_array_unref (priv->addresses);
|
||||
priv->addresses = nm_utils_ip6_addresses_from_variant (value);
|
||||
_nm_object_queue_notify (object, NM_IP6_CONFIG_ADDRESSES);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
if (*obj_field)
|
||||
g_strfreev (*obj_field);
|
||||
|
||||
*obj_field = g_new (char *, ip_array ? ip_array->len + 1 : 1);
|
||||
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;
|
||||
*obj_field = nm_utils_ip6_dns_from_variant (value);
|
||||
|
||||
_nm_object_queue_notify (object, pspec->name);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
|
||||
priv->routes = NULL;
|
||||
|
||||
priv->routes = nm_utils_ip6_routes_from_gvalue (value);
|
||||
g_ptr_array_unref (priv->routes);
|
||||
priv->routes = nm_utils_ip6_routes_from_variant (value);
|
||||
_nm_object_queue_notify (object, NM_IP6_CONFIG_ROUTES);
|
||||
|
||||
return TRUE;
|
||||
@@ -155,11 +135,11 @@ nm_ip6_config_get_gateway (NMIP6Config *config)
|
||||
*
|
||||
* Gets the IP6 addresses (containing the address, prefix, and gateway).
|
||||
*
|
||||
* Returns: (element-type NMIP6Address) (transfer none): the #GSList containing
|
||||
* #NMIP6Address<!-- -->es. This is the internal copy used by the configuration
|
||||
* and must not be modified.
|
||||
* Returns: (element-type NMIP6Address) (transfer none): the #GPtrArray
|
||||
* containing #NMIP6Address<!-- -->es. This is the internal copy used by the
|
||||
* configuration and must not be modified.
|
||||
**/
|
||||
const GSList *
|
||||
GPtrArray *
|
||||
nm_ip6_config_get_addresses (NMIP6Config *config)
|
||||
{
|
||||
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.
|
||||
*
|
||||
* Returns: (element-type NMIP6Route): (transfer none): the #GSList containing
|
||||
* #NMIP6Routes. This is the internal copy used by the configuration,
|
||||
* and must not be modified.
|
||||
* Returns: (element-type NMIP6Route) (transfer none): the #GPtrArray containing
|
||||
* #NMIP6Routes. This is the internal copy used by the configuration, and must
|
||||
* not be modified.
|
||||
**/
|
||||
const GSList *
|
||||
GPtrArray *
|
||||
nm_ip6_config_get_routes (NMIP6Config *config)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
|
||||
@@ -242,8 +222,8 @@ finalize (GObject *object)
|
||||
|
||||
g_free (priv->gateway);
|
||||
|
||||
g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
|
||||
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
|
||||
g_ptr_array_unref (priv->addresses);
|
||||
g_ptr_array_unref (priv->routes);
|
||||
|
||||
g_strfreev (priv->nameservers);
|
||||
g_strfreev (priv->domains);
|
||||
@@ -259,21 +239,20 @@ get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
NMIP6Config *self = NM_IP6_CONFIG (object);
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_GATEWAY:
|
||||
g_value_set_string (value, nm_ip6_config_get_gateway (self));
|
||||
break;
|
||||
case PROP_ADDRESSES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->addresses,
|
||||
(NMUtilsCopyFunc) nm_ip6_address_dup,
|
||||
(GDestroyNotify) nm_ip6_address_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_array (nm_ip6_config_get_addresses (self),
|
||||
(NMUtilsCopyFunc) nm_ip6_address_dup,
|
||||
(GDestroyNotify) nm_ip6_address_unref));
|
||||
break;
|
||||
case PROP_ROUTES:
|
||||
g_value_take_boxed (value, _nm_utils_copy_slist_to_array (priv->routes,
|
||||
(NMUtilsCopyFunc) nm_ip6_route_dup,
|
||||
(GDestroyNotify) nm_ip6_route_unref));
|
||||
g_value_take_boxed (value, _nm_utils_copy_array (nm_ip6_config_get_routes (self),
|
||||
(NMUtilsCopyFunc) nm_ip6_route_dup,
|
||||
(GDestroyNotify) nm_ip6_route_unref));
|
||||
break;
|
||||
case PROP_NAMESERVERS:
|
||||
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);
|
||||
|
||||
priv->addresses = g_ptr_array_new ();
|
||||
priv->routes = g_ptr_array_new ();
|
||||
priv->nameservers = g_new0 (char *, 1);
|
||||
priv->domains = g_new0 (char *, 1);
|
||||
priv->searches = g_new0 (char *, 1);
|
||||
|
@@ -60,8 +60,8 @@ typedef struct {
|
||||
GType nm_ip6_config_get_type (void);
|
||||
|
||||
const char * nm_ip6_config_get_gateway (NMIP6Config *config);
|
||||
const GSList * nm_ip6_config_get_addresses (NMIP6Config *config);
|
||||
const GSList * nm_ip6_config_get_routes (NMIP6Config *config);
|
||||
GPtrArray * nm_ip6_config_get_addresses (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_domains (NMIP6Config *config);
|
||||
const char * const * nm_ip6_config_get_searches (NMIP6Config *config);
|
||||
|
@@ -24,9 +24,9 @@
|
||||
#include <gio/gio.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 {
|
||||
const char *name;
|
||||
@@ -62,10 +62,11 @@ void _nm_object_reload_property (NMObject *object,
|
||||
void _nm_object_set_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name,
|
||||
GValue *value);
|
||||
const char *format_string,
|
||||
...);
|
||||
|
||||
/* object demarshalling support */
|
||||
typedef GType (*NMObjectDecideTypeFunc) (GValue *);
|
||||
typedef GType (*NMObjectDecideTypeFunc) (GVariant *);
|
||||
|
||||
void _nm_object_register_type_func (GType base_type,
|
||||
NMObjectDecideTypeFunc type_func,
|
||||
@@ -77,7 +78,7 @@ gboolean _nm_object_get_nm_running (NMObject *self);
|
||||
|
||||
void _nm_object_class_add_interface (NMObjectClass *object_class,
|
||||
const char *interface);
|
||||
DBusGProxy *_nm_object_get_proxy (NMObject *object,
|
||||
GDBusProxy *_nm_object_get_proxy (NMObject *object,
|
||||
const char *interface);
|
||||
|
||||
#endif /* __NM_OBJECT_PRIVATE_H__ */
|
||||
|
@@ -29,7 +29,6 @@
|
||||
#include "nm-object.h"
|
||||
#include "nm-object-cache.h"
|
||||
#include "nm-object-private.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-glib-compat.h"
|
||||
#include "nm-dbus-helpers.h"
|
||||
|
||||
@@ -72,13 +71,13 @@ typedef struct {
|
||||
static void reload_complete (NMObject *object);
|
||||
|
||||
typedef struct {
|
||||
DBusGConnection *connection;
|
||||
DBusGProxy *bus_proxy;
|
||||
GDBusConnection *connection;
|
||||
gboolean private_connection;
|
||||
gboolean nm_running;
|
||||
|
||||
char *path;
|
||||
GHashTable *proxies;
|
||||
DBusGProxy *properties_proxy;
|
||||
GDBusProxy *properties_proxy;
|
||||
GSList *property_tables;
|
||||
NMObject *parent;
|
||||
gboolean suppress_property_updates;
|
||||
@@ -125,20 +124,15 @@ nm_object_error_quark (void)
|
||||
}
|
||||
|
||||
static void
|
||||
proxy_name_owner_changed (DBusGProxy *proxy,
|
||||
const char *name,
|
||||
const char *old_owner,
|
||||
const char *new_owner,
|
||||
gpointer user_data)
|
||||
on_name_owner_changed (GObject *proxy,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMObject *self = NM_OBJECT (user_data);
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
|
||||
gboolean now_running;
|
||||
|
||||
if (g_strcmp0 (name, NM_DBUS_SERVICE) != 0)
|
||||
return;
|
||||
|
||||
now_running = (new_owner && new_owner[0]);
|
||||
now_running = (g_dbus_proxy_get_name_owner (priv->properties_proxy) != NULL);
|
||||
if (now_running != priv->nm_running) {
|
||||
priv->nm_running = now_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))
|
||||
priv->nm_running = TRUE;
|
||||
else {
|
||||
priv->bus_proxy = dbus_g_proxy_new_for_name (priv->connection,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
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);
|
||||
priv->nm_running = (g_dbus_proxy_get_name_owner (priv->properties_proxy) != NULL);
|
||||
g_signal_connect (priv->properties_proxy, "notify::g-name-owner",
|
||||
G_CALLBACK (on_name_owner_changed), object);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +182,7 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
||||
/* Create proxies */
|
||||
for (iter = cpriv->interfaces; iter; iter = iter->next) {
|
||||
const char *interface = iter->data;
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
proxy = _nm_dbus_new_proxy_for_connection (priv->connection, priv->path, interface,
|
||||
cancellable, error);
|
||||
@@ -216,16 +200,6 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -259,41 +233,18 @@ init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_
|
||||
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
|
||||
init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
NMObjectInitData *init_data = user_data;
|
||||
NMObject *self = init_data->object;
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
if (!init_data->error) {
|
||||
proxy = _nm_dbus_new_proxy_for_connection_finish (result, &init_data->error);
|
||||
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))
|
||||
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);
|
||||
|
||||
if (_nm_dbus_is_connection_private (priv->connection)) {
|
||||
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);
|
||||
}
|
||||
_nm_object_reload_properties_async (init_data->object, init_async_got_properties, init_data);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -410,12 +352,8 @@ dispose (GObject *object)
|
||||
|
||||
g_clear_pointer (&priv->proxies, g_hash_table_unref);
|
||||
g_clear_object (&priv->properties_proxy);
|
||||
g_clear_object (&priv->bus_proxy);
|
||||
|
||||
if (priv->connection) {
|
||||
dbus_g_connection_unref (priv->connection);
|
||||
priv->connection = NULL;
|
||||
}
|
||||
g_clear_object (&priv->connection);
|
||||
|
||||
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
|
||||
*/
|
||||
DBusGProxy *
|
||||
GDBusProxy *
|
||||
_nm_object_get_proxy (NMObject *object,
|
||||
const char *interface)
|
||||
{
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
g_return_val_if_fail (NM_IS_OBJECT (object), NULL);
|
||||
|
||||
@@ -682,7 +620,7 @@ _nm_object_register_type_func (GType base_type,
|
||||
}
|
||||
|
||||
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;
|
||||
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));
|
||||
if (type_data) {
|
||||
DBusGProxy *proxy;
|
||||
GValue value = G_VALUE_INIT;
|
||||
GDBusProxy *proxy;
|
||||
GVariant *ret, *value;
|
||||
|
||||
proxy = _nm_dbus_new_proxy_for_connection (connection, path,
|
||||
DBUS_INTERFACE_PROPERTIES,
|
||||
@@ -702,23 +640,25 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path)
|
||||
return G_TYPE_INVALID;
|
||||
}
|
||||
|
||||
if (!dbus_g_proxy_call (proxy,
|
||||
"Get", &error,
|
||||
G_TYPE_STRING, type_data->interface,
|
||||
G_TYPE_STRING, type_data->property,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_VALUE, &value,
|
||||
G_TYPE_INVALID)) {
|
||||
ret = g_dbus_proxy_call_sync (proxy,
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
type_data->interface,
|
||||
type_data->property),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
NULL, &error);
|
||||
g_object_unref (proxy);
|
||||
if (!ret) {
|
||||
g_warning ("Could not fetch property '%s' of interface '%s' on %s: %s\n",
|
||||
type_data->property, type_data->interface, path, error->message);
|
||||
g_error_free (error);
|
||||
g_object_unref (proxy);
|
||||
return G_TYPE_INVALID;
|
||||
}
|
||||
g_object_unref (proxy);
|
||||
|
||||
type = type_data->type_func (&value);
|
||||
g_value_unset (&value);
|
||||
g_variant_get (ret, "(v)", &value);
|
||||
type = type_data->type_func (value);
|
||||
g_variant_unref (value);
|
||||
g_variant_unref (ret);
|
||||
}
|
||||
|
||||
if (type == G_TYPE_INVALID) {
|
||||
@@ -813,24 +753,24 @@ create_async_got_type (NMObjectTypeAsyncData *async_data, GType type)
|
||||
}
|
||||
|
||||
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;
|
||||
NMObjectTypeFuncData *type_data = async_data->type_data;
|
||||
GValue value = G_VALUE_INIT;
|
||||
GVariant *ret, *value;
|
||||
GError *error = NULL;
|
||||
GType type;
|
||||
|
||||
if (dbus_g_proxy_end_call (proxy, call, &error,
|
||||
G_TYPE_VALUE, &value,
|
||||
G_TYPE_INVALID)) {
|
||||
type = type_data->type_func (&value);
|
||||
g_value_unset (&value);
|
||||
ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
|
||||
if (ret) {
|
||||
g_variant_get (ret, "(v)", &value);
|
||||
type = type_data->type_func (value);
|
||||
g_variant_unref (value);
|
||||
g_variant_unref (ret);
|
||||
} else {
|
||||
const char *path = dbus_g_proxy_get_path (proxy);
|
||||
|
||||
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);
|
||||
type = G_TYPE_INVALID;
|
||||
}
|
||||
@@ -842,7 +782,7 @@ static void
|
||||
create_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
NMObjectTypeAsyncData *async_data = user_data;
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
GError *error = NULL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
dbus_g_proxy_begin_call (proxy, "Get",
|
||||
create_async_got_property, async_data, NULL,
|
||||
G_TYPE_STRING, async_data->type_data->interface,
|
||||
G_TYPE_STRING, async_data->type_data->property,
|
||||
G_TYPE_INVALID);
|
||||
g_dbus_proxy_call (proxy,
|
||||
"Get",
|
||||
g_variant_new ("(ss)",
|
||||
async_data->type_data->interface,
|
||||
async_data->type_data->property),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
NULL,
|
||||
create_async_got_property, async_data);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
NMObjectTypeAsyncData *async_data;
|
||||
@@ -1083,7 +1026,7 @@ object_created (GObject *obj, const char *path, gpointer user_data)
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
priv->reload_remaining++;
|
||||
|
||||
path = g_value_get_boxed (value);
|
||||
path = g_variant_get_string (value, NULL);
|
||||
|
||||
if (!strcmp (path, "/")) {
|
||||
object_created (NULL, path, odata);
|
||||
@@ -1126,37 +1069,37 @@ handle_object_property (NMObject *self, const char *property_name, GValue *value
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
|
||||
GObject *obj;
|
||||
GPtrArray *paths;
|
||||
GVariantIter iter;
|
||||
gsize npaths;
|
||||
GPtrArray **array = pi->field;
|
||||
const char *path;
|
||||
ObjectCreatedData *odata;
|
||||
int i;
|
||||
|
||||
paths = g_value_get_boxed (value);
|
||||
npaths = g_variant_n_children (value);
|
||||
|
||||
odata = g_slice_new (ObjectCreatedData);
|
||||
odata->self = g_object_ref (self);
|
||||
odata->pi = pi;
|
||||
odata->objects = g_new0 (GObject *, paths->len);
|
||||
odata->length = odata->remaining = paths->len;
|
||||
odata->objects = g_new0 (GObject *, npaths);
|
||||
odata->length = odata->remaining = npaths;
|
||||
odata->array = TRUE;
|
||||
odata->property_name = property_name;
|
||||
|
||||
if (priv->reload_results)
|
||||
priv->reload_remaining++;
|
||||
|
||||
if (paths->len == 0) {
|
||||
if (npaths == 0) {
|
||||
object_property_complete (odata);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
for (i = 0; i < paths->len; i++) {
|
||||
path = paths->pdata[i];
|
||||
g_variant_iter_init (&iter, value);
|
||||
while (g_variant_iter_next (&iter, "&o", &path)) {
|
||||
if (!strcmp (path, "/")) {
|
||||
/* FIXME: can't happen? */
|
||||
continue;
|
||||
@@ -1179,11 +1122,12 @@ handle_object_array_property (NMObject *self, const char *property_name, GValue
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return *array && ((*array)->len == paths->len);
|
||||
return *array && ((*array)->len == npaths);
|
||||
}
|
||||
|
||||
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);
|
||||
char *prop_name;
|
||||
@@ -1224,7 +1168,7 @@ handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, g
|
||||
|
||||
if (G_UNLIKELY (debug)) {
|
||||
char *s;
|
||||
s = g_strdup_value_contents (value);
|
||||
s = g_variant_print (value, FALSE);
|
||||
dbgmsg ("PC: (%p) %s::%s => '%s' (%s%s%s)",
|
||||
self, G_OBJECT_TYPE_NAME (self),
|
||||
prop_name,
|
||||
@@ -1236,9 +1180,9 @@ handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, g
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
else {
|
||||
g_warn_if_reached ();
|
||||
@@ -1259,39 +1203,43 @@ out:
|
||||
}
|
||||
|
||||
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);
|
||||
GHashTableIter iter;
|
||||
gpointer name, value;
|
||||
GVariantIter iter;
|
||||
const char *name;
|
||||
GVariant *value;
|
||||
|
||||
if (priv->suppress_property_updates)
|
||||
return;
|
||||
|
||||
g_hash_table_iter_init (&iter, properties);
|
||||
while (g_hash_table_iter_next (&iter, &name, &value)) {
|
||||
if (value)
|
||||
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);
|
||||
}
|
||||
}
|
||||
g_variant_iter_init (&iter, properties);
|
||||
while (g_variant_iter_next (&iter, "{sv}", &name, &value))
|
||||
handle_property_changed (self, name, value, synchronously);
|
||||
}
|
||||
|
||||
static void
|
||||
properties_changed_proxy (DBusGProxy *proxy,
|
||||
GHashTable *properties,
|
||||
gpointer user_data)
|
||||
property_proxy_signal (GDBusProxy *proxy,
|
||||
const char *sender_name,
|
||||
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);
|
||||
g_variant_unref (properties);
|
||||
}
|
||||
|
||||
#define HANDLE_TYPE(ucase, lcase, getter) \
|
||||
} else if (pspec->value_type == G_TYPE_##ucase) { \
|
||||
if (G_VALUE_HOLDS_##ucase (value)) { \
|
||||
g##lcase *param = (g##lcase *) field; \
|
||||
*param = g_value_get_##getter (value); \
|
||||
#define HANDLE_TYPE(gtype, vtype, ctype, getter) \
|
||||
} else if (pspec->value_type == gtype) { \
|
||||
if (g_variant_is_of_type (value, vtype)) { \
|
||||
ctype *param = (ctype *) field; \
|
||||
*param = getter (value); \
|
||||
} else { \
|
||||
success = FALSE; \
|
||||
goto done; \
|
||||
@@ -1300,20 +1248,20 @@ properties_changed_proxy (DBusGProxy *proxy,
|
||||
static gboolean
|
||||
demarshal_generic (NMObject *object,
|
||||
GParamSpec *pspec,
|
||||
GValue *value,
|
||||
GVariant *value,
|
||||
gpointer field)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
|
||||
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;
|
||||
g_free (*param);
|
||||
*param = g_value_dup_string (value);
|
||||
} else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) {
|
||||
*param = g_variant_dup_string (value, NULL);
|
||||
} else if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) {
|
||||
char **param = (char **) field;
|
||||
g_free (*param);
|
||||
*param = g_strdup (g_value_get_boxed (value));
|
||||
*param = g_variant_dup_string (value, NULL);
|
||||
/* Handle "NULL" object paths */
|
||||
if (g_strcmp0 (*param, "/") == 0) {
|
||||
g_free (*param);
|
||||
@@ -1327,24 +1275,28 @@ demarshal_generic (NMObject *object,
|
||||
char ***param = (char ***)field;
|
||||
if (*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) {
|
||||
GBytes **param = (GBytes **)field;
|
||||
GByteArray *val;
|
||||
gconstpointer val;
|
||||
gsize length;
|
||||
|
||||
if (*param)
|
||||
g_bytes_unref (*param);
|
||||
val = g_value_get_boxed (value);
|
||||
*param = g_bytes_new (val->data, val->len);
|
||||
HANDLE_TYPE(BOOLEAN, boolean, boolean)
|
||||
HANDLE_TYPE(CHAR, char, schar)
|
||||
HANDLE_TYPE(UCHAR, uchar, uchar)
|
||||
HANDLE_TYPE(DOUBLE, double, double)
|
||||
HANDLE_TYPE(INT, int, int)
|
||||
HANDLE_TYPE(UINT, uint, uint)
|
||||
HANDLE_TYPE(INT64, int, int)
|
||||
HANDLE_TYPE(UINT64, uint, uint)
|
||||
HANDLE_TYPE(LONG, long, long)
|
||||
HANDLE_TYPE(ULONG, ulong, ulong)
|
||||
val = g_variant_get_fixed_array (value, &length, 1);
|
||||
if (length)
|
||||
*param = g_bytes_new (val, length);
|
||||
else
|
||||
*param = NULL;
|
||||
HANDLE_TYPE (G_TYPE_BOOLEAN, G_VARIANT_TYPE_BOOLEAN, gboolean, g_variant_get_boolean)
|
||||
HANDLE_TYPE (G_TYPE_UCHAR, G_VARIANT_TYPE_BYTE, guchar, g_variant_get_byte)
|
||||
HANDLE_TYPE (G_TYPE_DOUBLE, G_VARIANT_TYPE_DOUBLE, gdouble, g_variant_get_double)
|
||||
HANDLE_TYPE (G_TYPE_INT, G_VARIANT_TYPE_INT32, gint, g_variant_get_int32)
|
||||
HANDLE_TYPE (G_TYPE_UINT, G_VARIANT_TYPE_UINT32, guint, g_variant_get_uint32)
|
||||
HANDLE_TYPE (G_TYPE_INT64, G_VARIANT_TYPE_INT64, gint, g_variant_get_int64)
|
||||
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 {
|
||||
dbgmsg ("%s: %s/%s unhandled type %s.",
|
||||
__func__,
|
||||
@@ -1371,7 +1323,7 @@ _nm_object_register_properties (NMObject *object,
|
||||
const NMPropertiesInfo *info)
|
||||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
static gsize dval = 0;
|
||||
const char *debugstr;
|
||||
NMPropertiesInfo *tmp;
|
||||
@@ -1391,12 +1343,8 @@ _nm_object_register_properties (NMObject *object,
|
||||
proxy = _nm_object_get_proxy (object, interface);
|
||||
g_return_if_fail (proxy != NULL);
|
||||
|
||||
dbus_g_proxy_add_signal (proxy, "PropertiesChanged", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (proxy,
|
||||
"PropertiesChanged",
|
||||
G_CALLBACK (properties_changed_proxy),
|
||||
object,
|
||||
NULL);
|
||||
g_signal_connect (proxy, "g-signal",
|
||||
G_CALLBACK (property_proxy_signal), object);
|
||||
|
||||
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);
|
||||
@@ -1422,25 +1370,28 @@ gboolean
|
||||
_nm_object_reload_properties (NMObject *object, GError **error)
|
||||
{
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
GHashTable *props = NULL;
|
||||
GVariant *ret, *props;
|
||||
GHashTableIter iter;
|
||||
const char *interface;
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
if (!g_hash_table_size (priv->proxies) || !priv->nm_running)
|
||||
return TRUE;
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->proxies);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) {
|
||||
if (!dbus_g_proxy_call (priv->properties_proxy, "GetAll", error,
|
||||
G_TYPE_STRING, interface,
|
||||
G_TYPE_INVALID,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT, &props,
|
||||
G_TYPE_INVALID))
|
||||
ret = g_dbus_proxy_call_sync (priv->properties_proxy,
|
||||
"GetAll",
|
||||
g_variant_new ("(s)", interface),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
NULL, error);
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
||||
g_variant_get (ret, "(@a{sv})", &props);
|
||||
process_properties_changed (object, props, TRUE);
|
||||
g_hash_table_destroy (props);
|
||||
g_variant_unref (props);
|
||||
g_variant_unref (ret);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -1460,7 +1411,7 @@ _nm_object_reload_property (NMObject *object,
|
||||
const char *interface,
|
||||
const char *prop_name)
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
GVariant *ret, *value;
|
||||
GError *err = NULL;
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
if (!dbus_g_proxy_call_with_timeout (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
|
||||
"Get", 15000, &err,
|
||||
G_TYPE_STRING, interface,
|
||||
G_TYPE_STRING, prop_name,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_VALUE, &value,
|
||||
G_TYPE_INVALID)) {
|
||||
ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
|
||||
"Get",
|
||||
g_variant_new ("(ss)", interface, prop_name),
|
||||
G_DBUS_CALL_FLAGS_NONE, 15000,
|
||||
NULL, &err);
|
||||
if (!ret) {
|
||||
dbgmsg ("%s: Error getting '%s' for %s: (%d) %s\n",
|
||||
__func__,
|
||||
prop_name,
|
||||
@@ -1487,35 +1437,43 @@ _nm_object_reload_property (NMObject *object,
|
||||
return;
|
||||
}
|
||||
|
||||
handle_property_changed (object, prop_name, &value, TRUE);
|
||||
g_value_unset (&value);
|
||||
g_variant_get (ret, "(v)", &value);
|
||||
handle_property_changed (object, prop_name, value, TRUE);
|
||||
g_variant_unref (value);
|
||||
g_variant_unref (ret);
|
||||
}
|
||||
|
||||
void
|
||||
_nm_object_set_property (NMObject *object,
|
||||
const char *interface,
|
||||
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 (interface != 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)
|
||||
return;
|
||||
|
||||
if (!dbus_g_proxy_call_with_timeout (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
|
||||
"Set", 2000, NULL,
|
||||
G_TYPE_STRING, interface,
|
||||
G_TYPE_STRING, prop_name,
|
||||
G_TYPE_VALUE, value,
|
||||
G_TYPE_INVALID)) {
|
||||
va_start (ap, format_string);
|
||||
val = g_variant_new_va (format_string, NULL, &ap);
|
||||
va_end (ap);
|
||||
g_return_if_fail (val != NULL);
|
||||
|
||||
/* Ignore errors. dbus_g_proxy_call_with_timeout() is called instead of
|
||||
* dbus_g_proxy_call_no_reply() to give NM chance to authenticate the caller.
|
||||
*/
|
||||
}
|
||||
ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
|
||||
"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
|
||||
@@ -1547,19 +1505,21 @@ reload_complete (NMObject *object)
|
||||
}
|
||||
|
||||
static void
|
||||
reload_got_properties (DBusGProxy *proxy, DBusGProxyCall *call,
|
||||
reload_got_properties (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMObject *object = user_data;
|
||||
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
|
||||
GHashTable *props = NULL;
|
||||
GVariant *ret, *props;
|
||||
GError *error = NULL;
|
||||
|
||||
if (dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT, &props,
|
||||
G_TYPE_INVALID)) {
|
||||
ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error);
|
||||
if (ret) {
|
||||
g_variant_get (ret, "(@a{sv})", &props);
|
||||
process_properties_changed (object, props, FALSE);
|
||||
g_hash_table_destroy (props);
|
||||
g_variant_unref (props);
|
||||
g_variant_unref (ret);
|
||||
} else {
|
||||
if (priv->reload_error)
|
||||
g_error_free (error);
|
||||
@@ -1578,12 +1538,12 @@ _nm_object_reload_properties_async (NMObject *object, GAsyncReadyCallback callba
|
||||
GSimpleAsyncResult *simple;
|
||||
GHashTableIter iter;
|
||||
const char *interface;
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (object), callback,
|
||||
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_object_unref (simple);
|
||||
return;
|
||||
@@ -1601,10 +1561,12 @@ _nm_object_reload_properties_async (NMObject *object, GAsyncReadyCallback callba
|
||||
g_hash_table_iter_init (&iter, priv->proxies);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &interface, (gpointer *) &proxy)) {
|
||||
priv->reload_remaining++;
|
||||
dbus_g_proxy_begin_call (priv->properties_proxy, "GetAll",
|
||||
reload_got_properties, object, NULL,
|
||||
G_TYPE_STRING, interface,
|
||||
G_TYPE_INVALID);
|
||||
g_dbus_proxy_call (priv->properties_proxy,
|
||||
"GetAll",
|
||||
g_variant_new ("(s)", interface),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
NULL,
|
||||
reload_got_properties, object);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,9 +26,7 @@
|
||||
#error "Only <NetworkManager.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <nm-version.h>
|
||||
|
||||
|
@@ -29,10 +29,10 @@
|
||||
#include "nm-remote-connection.h"
|
||||
#include "nm-remote-connection-private.h"
|
||||
#include "nm-object-private.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-glib-compat.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_initable_iface_init (GInitableIface *iface);
|
||||
@@ -55,21 +55,18 @@ enum {
|
||||
};
|
||||
|
||||
typedef struct RemoteCall RemoteCall;
|
||||
typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error);
|
||||
typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, GAsyncResult *result);
|
||||
|
||||
|
||||
struct RemoteCall {
|
||||
NMRemoteConnection *self;
|
||||
DBusGProxyCall *call;
|
||||
RemoteCallFetchResultCb fetch_result_cb;
|
||||
GFunc callback;
|
||||
gpointer user_data;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
DBusGProxy *proxy;
|
||||
gboolean proxy_is_destroyed;
|
||||
GSList *calls;
|
||||
NMDBusSettingsConnection *proxy;
|
||||
|
||||
gboolean unsaved;
|
||||
|
||||
@@ -98,35 +95,16 @@ nm_remote_connection_error_quark (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;
|
||||
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self);
|
||||
GError *error = NULL;
|
||||
|
||||
g_assert ( (!proxy && !proxy_call && priv->proxy_is_destroyed) ||
|
||||
( proxy && proxy_call && !priv->proxy_is_destroyed && proxy == priv->proxy) );
|
||||
call->fetch_result_cb (call, result);
|
||||
|
||||
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_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 *
|
||||
remote_call_new (NMRemoteConnection *self,
|
||||
RemoteCallFetchResultCb fetch_result_cb,
|
||||
@@ -134,65 +112,31 @@ remote_call_new (NMRemoteConnection *self,
|
||||
gpointer user_data)
|
||||
{
|
||||
RemoteCall *call;
|
||||
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
|
||||
|
||||
g_assert (fetch_result_cb);
|
||||
|
||||
if (priv->proxy_is_destroyed && !callback)
|
||||
return NULL;
|
||||
|
||||
call = g_malloc0 (sizeof (RemoteCall));
|
||||
call->self = g_object_ref (self);
|
||||
call->fetch_result_cb = fetch_result_cb;
|
||||
call->user_data = user_data;
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
GError *local_error = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!error) {
|
||||
dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy,
|
||||
proxy_call, &local_error, G_TYPE_INVALID);
|
||||
error = local_error;
|
||||
}
|
||||
nmdbus_settings_connection_call_update_finish (priv->proxy, result, &error);
|
||||
if (func)
|
||||
(*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;
|
||||
RemoteCall *call;
|
||||
GVariant *settings_dict;
|
||||
GHashTable *settings;
|
||||
GVariant *settings;
|
||||
|
||||
g_return_if_fail (NM_IS_REMOTE_CONNECTION (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)
|
||||
return;
|
||||
|
||||
settings_dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ALL);
|
||||
settings = _nm_utils_connection_dict_to_hash (settings_dict);
|
||||
g_variant_unref (settings_dict);
|
||||
settings = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ALL);
|
||||
nmdbus_settings_connection_call_update (priv->proxy,
|
||||
settings,
|
||||
NULL,
|
||||
remote_call_dbus_cb, call);
|
||||
}
|
||||
|
||||
call->call = dbus_g_proxy_begin_call (priv->proxy, "Update",
|
||||
remote_call_dbus_cb, call, NULL,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings,
|
||||
G_TYPE_INVALID);
|
||||
g_assert (call->call);
|
||||
g_hash_table_destroy (settings);
|
||||
static void
|
||||
update_unsaved_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_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)
|
||||
{
|
||||
NMRemoteConnectionPrivate *priv;
|
||||
GVariant *settings_dict;
|
||||
GHashTable *settings;
|
||||
GVariant *settings;
|
||||
RemoteCall *call;
|
||||
|
||||
g_return_if_fail (NM_IS_REMOTE_CONNECTION (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)
|
||||
return;
|
||||
|
||||
settings_dict = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL);
|
||||
settings = _nm_utils_connection_dict_to_hash (settings_dict);
|
||||
g_variant_unref (settings_dict);
|
||||
call->call = dbus_g_proxy_begin_call (priv->proxy, "UpdateUnsaved",
|
||||
remote_call_dbus_cb, call, NULL,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings,
|
||||
G_TYPE_INVALID);
|
||||
g_assert (call->call);
|
||||
g_hash_table_destroy (settings);
|
||||
settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL);
|
||||
nmdbus_settings_connection_call_update_unsaved (priv->proxy,
|
||||
settings,
|
||||
NULL,
|
||||
remote_call_dbus_cb, call);
|
||||
}
|
||||
|
||||
static void
|
||||
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);
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
call->call = dbus_g_proxy_begin_call (priv->proxy, "Save", remote_call_dbus_cb, call, NULL, G_TYPE_INVALID);
|
||||
g_assert (call->call);
|
||||
nmdbus_settings_connection_call_save (priv->proxy,
|
||||
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);
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete",
|
||||
remote_call_dbus_cb, call, NULL,
|
||||
G_TYPE_INVALID);
|
||||
g_assert (call->call);
|
||||
nmdbus_settings_connection_call_delete (priv->proxy,
|
||||
NULL,
|
||||
remote_call_dbus_cb, call);
|
||||
}
|
||||
|
||||
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;
|
||||
GHashTable *secrets = NULL;
|
||||
GError *local_error = NULL;
|
||||
GVariant *secrets = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!error) {
|
||||
dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy,
|
||||
proxy_call, &local_error,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets,
|
||||
G_TYPE_INVALID);
|
||||
error = local_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 (!nmdbus_settings_connection_call_get_secrets_finish (priv->proxy, &secrets,
|
||||
result, &error))
|
||||
secrets = NULL;
|
||||
if (func)
|
||||
(*func) (call->self, error ? NULL : secrets, error, call->user_data);
|
||||
g_clear_error (&error);
|
||||
if (secrets)
|
||||
g_hash_table_destroy (secrets);
|
||||
g_variant_unref (secrets);
|
||||
}
|
||||
|
||||
|
||||
@@ -397,11 +355,10 @@ nm_remote_connection_get_secrets (NMRemoteConnection *self,
|
||||
if (!call)
|
||||
return;
|
||||
|
||||
call->call = dbus_g_proxy_begin_call (priv->proxy, "GetSecrets",
|
||||
remote_call_dbus_cb, call, NULL,
|
||||
G_TYPE_STRING, setting_name,
|
||||
G_TYPE_INVALID);
|
||||
g_assert (call->call);
|
||||
nmdbus_settings_connection_call_get_secrets (priv->proxy,
|
||||
setting_name,
|
||||
NULL,
|
||||
remote_call_dbus_cb, call);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,13 +404,11 @@ nm_remote_connection_get_visible (NMRemoteConnection *connection)
|
||||
/****************************************************************/
|
||||
|
||||
static void
|
||||
replace_settings (NMRemoteConnection *self, GHashTable *new_settings)
|
||||
replace_settings (NMRemoteConnection *self, GVariant *new_settings)
|
||||
{
|
||||
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_dict, &error)) {
|
||||
if (!nm_connection_replace_settings (NM_CONNECTION (self), new_settings, &error)) {
|
||||
g_warning ("%s: error updating connection %s settings: (%d) %s",
|
||||
__func__,
|
||||
nm_connection_get_path (NM_CONNECTION (self)),
|
||||
@@ -461,33 +416,27 @@ replace_settings (NMRemoteConnection *self, GHashTable *new_settings)
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_variant_unref (new_settings_dict);
|
||||
}
|
||||
|
||||
static void
|
||||
updated_get_settings_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
updated_get_settings_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMRemoteConnection *self = user_data;
|
||||
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
|
||||
GHashTable *new_settings;
|
||||
GError *error = NULL;
|
||||
GVariant *new_settings;
|
||||
gboolean visible;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings,
|
||||
G_TYPE_INVALID);
|
||||
if (error) {
|
||||
g_error_free (error);
|
||||
|
||||
if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &new_settings,
|
||||
result, NULL)) {
|
||||
/* Connection is no longer visible to this user. */
|
||||
nm_connection_clear_settings (NM_CONNECTION (self));
|
||||
|
||||
visible = FALSE;
|
||||
} else {
|
||||
replace_settings (self, new_settings);
|
||||
g_hash_table_destroy (new_settings);
|
||||
g_variant_unref (new_settings);
|
||||
|
||||
visible = TRUE;
|
||||
}
|
||||
@@ -499,17 +448,15 @@ updated_get_settings_cb (DBusGProxy *proxy,
|
||||
}
|
||||
|
||||
static void
|
||||
updated_cb (DBusGProxy *proxy, gpointer user_data)
|
||||
updated_cb (NMDBusSettingsConnection *proxy, gpointer user_data)
|
||||
{
|
||||
NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data);
|
||||
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
|
||||
|
||||
/* The connection got updated; request the replacement settings */
|
||||
if (!priv->proxy_is_destroyed) {
|
||||
dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
|
||||
updated_get_settings_cb, self, NULL,
|
||||
G_TYPE_INVALID);
|
||||
}
|
||||
nmdbus_settings_connection_call_get_settings (priv->proxy,
|
||||
NULL,
|
||||
updated_get_settings_cb, self);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
@@ -525,18 +472,15 @@ init_dbus (NMObject *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);
|
||||
dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT);
|
||||
|
||||
_nm_object_register_properties (object,
|
||||
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
|
||||
property_info);
|
||||
|
||||
dbus_g_proxy_add_signal (priv->proxy, "Updated", G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), object, NULL);
|
||||
|
||||
g_signal_connect (priv->proxy, "destroy", G_CALLBACK (proxy_destroy_cb), object);
|
||||
g_signal_connect (priv->proxy, "updated",
|
||||
G_CALLBACK (updated_cb), object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -544,25 +488,26 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable);
|
||||
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
|
||||
GHashTable *hash;
|
||||
GVariant *settings;
|
||||
|
||||
if (!nm_remote_connection_parent_initable_iface->init (initable, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error,
|
||||
G_TYPE_INVALID,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash,
|
||||
G_TYPE_INVALID))
|
||||
if (!nmdbus_settings_connection_call_get_settings_sync (priv->proxy,
|
||||
&settings,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
priv->visible = TRUE;
|
||||
replace_settings (self, hash);
|
||||
g_hash_table_destroy (hash);
|
||||
replace_settings (self, settings);
|
||||
g_variant_unref (settings);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
NMRemoteConnection *connection;
|
||||
GCancellable *cancellable;
|
||||
GSimpleAsyncResult *result;
|
||||
} NMRemoteConnectionInitData;
|
||||
|
||||
@@ -576,30 +521,29 @@ init_async_complete (NMRemoteConnectionInitData *init_data, GError *error)
|
||||
|
||||
g_simple_async_result_complete (init_data->result);
|
||||
g_object_unref (init_data->result);
|
||||
g_clear_object (&init_data->cancellable);
|
||||
g_slice_free (NMRemoteConnectionInitData, init_data);
|
||||
}
|
||||
|
||||
static void
|
||||
init_get_settings_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
init_get_settings_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMRemoteConnectionInitData *init_data = user_data;
|
||||
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
|
||||
GHashTable *settings;
|
||||
GVariant *settings;
|
||||
GError *error = NULL;
|
||||
|
||||
dbus_g_proxy_end_call (proxy, call, &error,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings,
|
||||
G_TYPE_INVALID);
|
||||
if (error) {
|
||||
if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &settings,
|
||||
result, &error)) {
|
||||
init_async_complete (init_data, error);
|
||||
return;
|
||||
}
|
||||
|
||||
priv->visible = TRUE;
|
||||
replace_settings (init_data->connection, settings);
|
||||
g_hash_table_destroy (settings);
|
||||
g_variant_unref (settings);
|
||||
|
||||
init_async_complete (init_data, NULL);
|
||||
}
|
||||
@@ -616,9 +560,9 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
|
||||
init_get_settings_cb, init_data, NULL,
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_settings_connection_call_get_settings (priv->proxy,
|
||||
init_data->cancellable,
|
||||
init_get_settings_cb, init_data);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -630,6 +574,7 @@ init_async (GAsyncInitable *initable, int io_priority,
|
||||
|
||||
init_data = g_slice_new0 (NMRemoteConnectionInitData);
|
||||
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,
|
||||
user_data, init_async);
|
||||
|
||||
@@ -677,22 +622,6 @@ constructed (GObject *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
|
||||
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));
|
||||
|
||||
_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 */
|
||||
object_class->constructed = constructed;
|
||||
object_class->get_property = get_property;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
nm_object_class->init_dbus = init_dbus;
|
||||
|
||||
|
@@ -23,7 +23,6 @@
|
||||
#include <nm-dbus-interface.h>
|
||||
#include <nm-connection.h>
|
||||
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-remote-settings.h"
|
||||
#include "nm-remote-connection-private.h"
|
||||
#include "nm-object-private.h"
|
||||
@@ -32,6 +31,8 @@
|
||||
#include "nm-object-private.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
#include "nmdbus-settings.h"
|
||||
|
||||
/**
|
||||
* SECTION:nm-remote-settings
|
||||
* @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))
|
||||
|
||||
typedef struct {
|
||||
DBusGProxy *proxy;
|
||||
NMDBusSettings *proxy;
|
||||
GPtrArray *all_connections;
|
||||
GPtrArray *visible_connections;
|
||||
|
||||
@@ -424,19 +425,19 @@ nm_remote_settings_list_connections (NMRemoteSettings *settings)
|
||||
}
|
||||
|
||||
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;
|
||||
GError *error = NULL;
|
||||
char *path = NULL;
|
||||
|
||||
if (dbus_g_proxy_end_call (proxy, call, &error, DBUS_TYPE_G_OBJECT_PATH, &path, G_TYPE_INVALID)) {
|
||||
info->path = path;
|
||||
if (nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy),
|
||||
&info->path,
|
||||
result, &error)) {
|
||||
/* Wait until this connection is fully initialized before calling the callback */
|
||||
} else
|
||||
} else {
|
||||
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;
|
||||
AddConnectionInfo *info;
|
||||
GVariant *new_settings_dict;
|
||||
GHashTable *new_settings;
|
||||
GVariant *new_settings;
|
||||
|
||||
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), 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_data = user_data;
|
||||
|
||||
new_settings_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
|
||||
new_settings = _nm_utils_connection_dict_to_hash (new_settings_dict);
|
||||
dbus_g_proxy_begin_call (priv->proxy, "AddConnection",
|
||||
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);
|
||||
new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
|
||||
nmdbus_settings_call_add_connection (priv->proxy,
|
||||
new_settings,
|
||||
NULL,
|
||||
add_connection_done, 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;
|
||||
AddConnectionInfo *info;
|
||||
GVariant *new_settings_dict;
|
||||
GHashTable *new_settings;
|
||||
GVariant *new_settings;
|
||||
|
||||
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), 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_data = user_data;
|
||||
|
||||
new_settings_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
|
||||
new_settings = _nm_utils_connection_dict_to_hash (new_settings_dict);
|
||||
dbus_g_proxy_begin_call (priv->proxy, "AddConnectionUnsaved",
|
||||
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);
|
||||
new_settings = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
|
||||
nmdbus_settings_call_add_connection_unsaved (priv->proxy,
|
||||
new_settings,
|
||||
NULL,
|
||||
add_connection_done, info);
|
||||
|
||||
priv->add_list = g_slist_append (priv->add_list, info);
|
||||
|
||||
@@ -586,8 +575,7 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings,
|
||||
GError **error)
|
||||
{
|
||||
NMRemoteSettingsPrivate *priv;
|
||||
char **my_failures = NULL;
|
||||
gboolean ret;
|
||||
gboolean success;
|
||||
|
||||
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
|
||||
g_return_val_if_fail (filenames != NULL, FALSE);
|
||||
@@ -601,22 +589,14 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!dbus_g_proxy_call (priv->proxy, "LoadConnections", error,
|
||||
G_TYPE_STRV, filenames,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_BOOLEAN, &ret,
|
||||
G_TYPE_STRV, &my_failures,
|
||||
G_TYPE_INVALID))
|
||||
ret = FALSE;
|
||||
if (!nmdbus_settings_call_load_connections_sync (priv->proxy,
|
||||
(const char * const *) filenames,
|
||||
&success,
|
||||
failures,
|
||||
NULL, error))
|
||||
success = FALSE;
|
||||
|
||||
if (failures) {
|
||||
if (my_failures && !*my_failures)
|
||||
g_clear_pointer (&my_failures, g_free);
|
||||
*failures = my_failures;
|
||||
} else
|
||||
g_strfreev (my_failures);
|
||||
|
||||
return ret;
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -648,11 +628,10 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!dbus_g_proxy_call (priv->proxy, "ReloadConnections", error,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_BOOLEAN, &success,
|
||||
G_TYPE_INVALID))
|
||||
return FALSE;
|
||||
if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success,
|
||||
NULL, error))
|
||||
success = FALSE;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -663,14 +642,14 @@ typedef struct {
|
||||
} SaveHostnameInfo;
|
||||
|
||||
static void
|
||||
save_hostname_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
save_hostname_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
SaveHostnameInfo *info = user_data;
|
||||
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)
|
||||
info->callback (info->settings, error, info->callback_data);
|
||||
g_clear_error (&error);
|
||||
@@ -713,12 +692,10 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings,
|
||||
info->callback = callback;
|
||||
info->callback_data = user_data;
|
||||
|
||||
dbus_g_proxy_begin_call (priv->proxy, "SaveHostname",
|
||||
save_hostname_cb,
|
||||
info,
|
||||
g_free,
|
||||
G_TYPE_STRING, hostname ? hostname : "",
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_settings_call_save_hostname (priv->proxy,
|
||||
hostname ? hostname : "",
|
||||
NULL,
|
||||
save_hostname_cb, info);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -866,7 +843,7 @@ init_dbus (NMObject *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_DBUS_INTERFACE_SETTINGS,
|
||||
property_info);
|
||||
@@ -961,6 +938,7 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
|
||||
g_type_class_add_private (class, sizeof (NMRemoteSettingsPrivate));
|
||||
|
||||
_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 */
|
||||
object_class->constructor = constructor;
|
||||
|
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
|
||||
#include "nm-glib-compat.h"
|
||||
#include "nm-dbus-interface.h"
|
||||
@@ -28,32 +27,9 @@
|
||||
#include "nm-enum-types.h"
|
||||
#include "nm-dbus-helpers.h"
|
||||
#include "nm-simple-connection.h"
|
||||
#include "nm-utils-private.h"
|
||||
|
||||
static void impl_secret_agent_get_secrets (NMSecretAgent *self,
|
||||
GHashTable *connection_hash,
|
||||
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"
|
||||
#include "nmdbus-secret-agent.h"
|
||||
#include "nmdbus-agent-manager.h"
|
||||
|
||||
static void nm_secret_agent_initable_iface_init (GInitableIface *iface);
|
||||
static void nm_secret_agent_async_initable_iface_init (GAsyncInitableIface *iface);
|
||||
@@ -69,17 +45,15 @@ typedef struct {
|
||||
gboolean registering;
|
||||
NMSecretAgentCapabilities capabilities;
|
||||
|
||||
DBusGConnection *bus;
|
||||
GDBusConnection *bus;
|
||||
gboolean private_bus;
|
||||
gboolean session_bus;
|
||||
DBusGProxy *dbus_proxy;
|
||||
DBusGProxy *manager_proxy;
|
||||
NMDBusAgentManager *manager_proxy;
|
||||
NMDBusSecretAgent *dbus_secret_agent;
|
||||
|
||||
/* GetSecretsInfo structs of in-flight GetSecrets requests */
|
||||
GSList *pending_gets;
|
||||
|
||||
char *nm_owner;
|
||||
|
||||
char *identifier;
|
||||
gboolean auto_register;
|
||||
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
|
||||
_internal_unregister (NMSecretAgent *self)
|
||||
{
|
||||
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
|
||||
|
||||
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->registering = FALSE;
|
||||
g_object_notify (G_OBJECT (self), NM_SECRET_AGENT_REGISTERED);
|
||||
@@ -148,7 +99,7 @@ _internal_unregister (NMSecretAgent *self)
|
||||
typedef struct {
|
||||
char *path;
|
||||
char *setting_name;
|
||||
DBusGMethodInvocation *context;
|
||||
GDBusMethodInvocation *context;
|
||||
} GetSecretsInfo;
|
||||
|
||||
static void
|
||||
@@ -178,61 +129,44 @@ should_auto_register (NMSecretAgent *self)
|
||||
}
|
||||
|
||||
static void
|
||||
name_owner_changed (DBusGProxy *proxy,
|
||||
const char *name,
|
||||
const char *old_owner,
|
||||
const char *new_owner,
|
||||
name_owner_changed (GObject *proxy,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSecretAgent *self = NM_SECRET_AGENT (user_data);
|
||||
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;
|
||||
|
||||
if (strcmp (name, NM_DBUS_SERVICE) == 0) {
|
||||
g_free (priv->nm_owner);
|
||||
priv->nm_owner = g_strdup (new_owner);
|
||||
if (g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy)) != NULL) {
|
||||
if (should_auto_register (self))
|
||||
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 appeared */
|
||||
if (should_auto_register (self))
|
||||
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);
|
||||
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;
|
||||
|
||||
_internal_unregister (self);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify_sender (NMSecretAgent *self,
|
||||
DBusGMethodInvocation *context,
|
||||
GDBusMethodInvocation *context,
|
||||
GError **error)
|
||||
{
|
||||
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
|
||||
DBusConnection *bus;
|
||||
char *sender;
|
||||
const char *nm_owner;
|
||||
DBusError dbus_error;
|
||||
uid_t sender_uid = G_MAXUINT;
|
||||
gboolean allowed = FALSE;
|
||||
const char *sender;
|
||||
guint32 sender_uid;
|
||||
GVariant *ret;
|
||||
GError *local = NULL;
|
||||
|
||||
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. */
|
||||
|
||||
nm_owner = get_nm_owner (self);
|
||||
nm_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->manager_proxy));
|
||||
if (!nm_owner) {
|
||||
g_set_error_literal (error,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
@@ -253,16 +187,7 @@ verify_sender (NMSecretAgent *self,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bus = dbus_g_connection_get_connection (priv->bus);
|
||||
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);
|
||||
sender = g_dbus_method_invocation_get_sender (context);
|
||||
if (!sender) {
|
||||
g_set_error_literal (error,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
@@ -277,28 +202,41 @@ verify_sender (NMSecretAgent *self,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
|
||||
"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,
|
||||
* so skip the UID check.
|
||||
*/
|
||||
if (priv->session_bus) {
|
||||
allowed = TRUE;
|
||||
goto out;
|
||||
}
|
||||
if (priv->session_bus)
|
||||
return TRUE;
|
||||
|
||||
dbus_error_init (&dbus_error);
|
||||
sender_uid = dbus_bus_get_unix_user (bus, sender, &dbus_error);
|
||||
if (dbus_error_is_set (&dbus_error)) {
|
||||
/* Check the UID of the sender */
|
||||
ret = g_dbus_connection_call_sync (priv->bus,
|
||||
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,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
|
||||
"Failed to get request unix user: (%s) %s.",
|
||||
dbus_error.name, dbus_error.message);
|
||||
dbus_error_free (&dbus_error);
|
||||
goto out;
|
||||
"Failed to request unix user: (%s) %s.",
|
||||
remote_error ? remote_error : "",
|
||||
local->message);
|
||||
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 */
|
||||
if (0 != sender_uid) {
|
||||
@@ -306,36 +244,31 @@ verify_sender (NMSecretAgent *self,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED,
|
||||
"Request sender is not root.");
|
||||
goto out;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
allowed = TRUE;
|
||||
|
||||
out:
|
||||
g_free (sender);
|
||||
return allowed;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify_request (NMSecretAgent *self,
|
||||
DBusGMethodInvocation *context,
|
||||
GHashTable *connection_hash,
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *connection_dict,
|
||||
const char *connection_path,
|
||||
NMConnection **out_connection,
|
||||
GError **error)
|
||||
{
|
||||
NMConnection *connection = NULL;
|
||||
GVariant *connection_dict;
|
||||
GError *local = NULL;
|
||||
|
||||
if (!verify_sender (self, context, error))
|
||||
return FALSE;
|
||||
|
||||
/* No connection? If the sender verified, then we allow the request */
|
||||
if (connection_hash == NULL)
|
||||
if (connection_dict == NULL)
|
||||
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) {
|
||||
g_set_error_literal (error,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
@@ -346,9 +279,7 @@ verify_request (NMSecretAgent *self,
|
||||
|
||||
/* Make sure the given connection is valid */
|
||||
g_assert (out_connection);
|
||||
connection_dict = _nm_utils_connection_hash_to_dict (connection_hash);
|
||||
connection = nm_simple_connection_new_from_dbus (connection_dict, &local);
|
||||
g_variant_unref (connection_dict);
|
||||
if (connection) {
|
||||
nm_connection_set_path (connection, connection_path);
|
||||
*out_connection = connection;
|
||||
@@ -375,13 +306,10 @@ get_secrets_cb (NMSecretAgent *self,
|
||||
GetSecretsInfo *info = user_data;
|
||||
|
||||
if (error)
|
||||
dbus_g_method_return_error (info->context, error);
|
||||
g_dbus_method_invocation_return_gerror (info->context, error);
|
||||
else {
|
||||
GHashTable *secrets_hash;
|
||||
|
||||
secrets_hash = _nm_utils_connection_dict_to_hash (secrets);
|
||||
dbus_g_method_return (info->context, secrets_hash);
|
||||
g_hash_table_unref (secrets_hash);
|
||||
g_dbus_method_invocation_return_value (info->context,
|
||||
g_variant_new ("(@a{sa{sv}})", secrets));
|
||||
}
|
||||
|
||||
/* Remove the request from internal tracking */
|
||||
@@ -390,12 +318,13 @@ get_secrets_cb (NMSecretAgent *self,
|
||||
|
||||
static void
|
||||
impl_secret_agent_get_secrets (NMSecretAgent *self,
|
||||
GHashTable *connection_hash,
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *connection_dict,
|
||||
const char *connection_path,
|
||||
const char *setting_name,
|
||||
const char **hints,
|
||||
guint32 flags,
|
||||
DBusGMethodInvocation *context)
|
||||
const char * const *hints,
|
||||
guint flags,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
|
||||
GError *error = NULL;
|
||||
@@ -403,9 +332,8 @@ impl_secret_agent_get_secrets (NMSecretAgent *self,
|
||||
GetSecretsInfo *info;
|
||||
|
||||
/* Make sure the request comes from NetworkManager and is valid */
|
||||
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_clear_error (&error);
|
||||
if (!verify_request (self, context, connection_dict, connection_path, &connection, &error)) {
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -419,7 +347,7 @@ impl_secret_agent_get_secrets (NMSecretAgent *self,
|
||||
connection,
|
||||
connection_path,
|
||||
setting_name,
|
||||
hints,
|
||||
(const char **) hints,
|
||||
flags,
|
||||
get_secrets_cb,
|
||||
info);
|
||||
@@ -443,9 +371,10 @@ find_get_secrets_info (GSList *list, const char *path, const char *setting_name)
|
||||
|
||||
static void
|
||||
impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
|
||||
GDBusMethodInvocation *context,
|
||||
const char *connection_path,
|
||||
const char *setting_name,
|
||||
DBusGMethodInvocation *context)
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
|
||||
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 */
|
||||
if (!verify_request (self, context, NULL, NULL, NULL, &error)) {
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_clear_error (&error);
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return;
|
||||
}
|
||||
|
||||
info = find_get_secrets_info (priv->pending_gets, connection_path, setting_name);
|
||||
if (!info) {
|
||||
g_set_error_literal (&error,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
|
||||
"No secrets request in progress for this connection.");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_clear_error (&error);
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
NM_SECRET_AGENT_ERROR,
|
||||
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
|
||||
"No secrets request in progress for this connection.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -473,7 +399,7 @@ impl_secret_agent_cancel_get_secrets (NMSecretAgent *self,
|
||||
NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self,
|
||||
info->path,
|
||||
info->setting_name);
|
||||
dbus_g_method_return (context);
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -482,27 +408,27 @@ save_secrets_cb (NMSecretAgent *self,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
DBusGMethodInvocation *context = user_data;
|
||||
GDBusMethodInvocation *context = user_data;
|
||||
|
||||
if (error)
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_dbus_method_invocation_return_gerror (context, error);
|
||||
else
|
||||
dbus_g_method_return (context);
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_secret_agent_save_secrets (NMSecretAgent *self,
|
||||
GHashTable *connection_hash,
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *connection_dict,
|
||||
const char *connection_path,
|
||||
DBusGMethodInvocation *context)
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
NMConnection *connection = NULL;
|
||||
|
||||
/* Make sure the request comes from NetworkManager and is valid */
|
||||
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_clear_error (&error);
|
||||
if (!verify_request (self, context, connection_dict, connection_path, &connection, &error)) {
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -520,27 +446,27 @@ delete_secrets_cb (NMSecretAgent *self,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
DBusGMethodInvocation *context = user_data;
|
||||
GDBusMethodInvocation *context = user_data;
|
||||
|
||||
if (error)
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_dbus_method_invocation_return_gerror (context, error);
|
||||
else
|
||||
dbus_g_method_return (context);
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_secret_agent_delete_secrets (NMSecretAgent *self,
|
||||
GHashTable *connection_hash,
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *connection_dict,
|
||||
const char *connection_path,
|
||||
DBusGMethodInvocation *context)
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
NMConnection *connection = NULL;
|
||||
|
||||
/* Make sure the request comes from NetworkManager and is valid */
|
||||
if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) {
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_clear_error (&error);
|
||||
if (!verify_request (self, context, connection_dict, connection_path, &connection, &error)) {
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -559,7 +485,9 @@ check_nm_running (NMSecretAgent *self, GError **error)
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
/* Export our secret agent interface before registering with the manager */
|
||||
dbus_g_connection_register_g_object (priv->bus,
|
||||
NM_DBUS_PATH_SECRET_AGENT,
|
||||
G_OBJECT (self));
|
||||
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_secret_agent),
|
||||
priv->bus,
|
||||
NM_DBUS_PATH_SECRET_AGENT,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
priv->registering = TRUE;
|
||||
if (dbus_g_proxy_call_with_timeout (priv->manager_proxy,
|
||||
"RegisterWithCapabilities",
|
||||
5000, NULL,
|
||||
G_TYPE_STRING, priv->identifier,
|
||||
G_TYPE_UINT, priv->capabilities,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID))
|
||||
if (nmdbus_agent_manager_call_register_with_capabilities_sync (priv->manager_proxy,
|
||||
priv->identifier,
|
||||
priv->capabilities,
|
||||
cancellable, NULL))
|
||||
goto success;
|
||||
|
||||
/* Might be an old NetworkManager that doesn't support capabilities;
|
||||
* fall back to old Register() method instead.
|
||||
*/
|
||||
if (dbus_g_proxy_call_with_timeout (priv->manager_proxy,
|
||||
"Register",
|
||||
5000, error,
|
||||
G_TYPE_STRING, priv->identifier,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID))
|
||||
if (nmdbus_agent_manager_call_register_sync (priv->manager_proxy,
|
||||
priv->identifier,
|
||||
cancellable, NULL))
|
||||
goto success;
|
||||
|
||||
/* Failure */
|
||||
@@ -675,24 +599,27 @@ reg_result (NMSecretAgent *self, GSimpleAsyncResult *simple, GError *error)
|
||||
}
|
||||
|
||||
static void
|
||||
reg_request_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
reg_request_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple = user_data;
|
||||
NMSecretAgent *self;
|
||||
NMSecretAgentPrivate *priv;
|
||||
GError *error = NULL;
|
||||
|
||||
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() */
|
||||
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);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
static void
|
||||
reg_with_caps_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
reg_with_caps_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer 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() */
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@@ -711,14 +638,9 @@ reg_with_caps_cb (DBusGProxy *proxy,
|
||||
/* Might be an old NetworkManager that doesn't support capabilities;
|
||||
* fall back to old Register() method instead.
|
||||
*/
|
||||
dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy,
|
||||
"Register",
|
||||
reg_request_cb,
|
||||
self,
|
||||
NULL,
|
||||
5000,
|
||||
G_TYPE_STRING, priv->identifier,
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_agent_manager_call_register (priv->manager_proxy,
|
||||
priv->identifier,
|
||||
NULL, reg_request_cb, simple);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -771,23 +693,25 @@ nm_secret_agent_register_async (NMSecretAgent *self,
|
||||
return;
|
||||
}
|
||||
|
||||
priv->suppress_auto = FALSE;
|
||||
|
||||
/* Export our secret agent interface before registering with the manager */
|
||||
dbus_g_connection_register_g_object (priv->bus,
|
||||
NM_DBUS_PATH_SECRET_AGENT,
|
||||
G_OBJECT (self));
|
||||
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_secret_agent),
|
||||
priv->bus,
|
||||
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;
|
||||
dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy,
|
||||
"RegisterWithCapabilities",
|
||||
reg_with_caps_cb,
|
||||
simple,
|
||||
NULL,
|
||||
5000,
|
||||
G_TYPE_STRING, priv->identifier,
|
||||
G_TYPE_UINT, priv->capabilities,
|
||||
G_TYPE_INVALID);
|
||||
|
||||
nmdbus_agent_manager_call_register_with_capabilities (priv->manager_proxy,
|
||||
priv->identifier,
|
||||
priv->capabilities,
|
||||
NULL,
|
||||
reg_with_caps_cb, simple);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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->manager_proxy != NULL, FALSE);
|
||||
|
||||
if (!check_nm_running (self, error))
|
||||
return FALSE;
|
||||
|
||||
priv->suppress_auto = TRUE;
|
||||
|
||||
success = dbus_g_proxy_call_with_timeout (priv->manager_proxy,
|
||||
"Unregister",
|
||||
5000, error,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID);
|
||||
success = nmdbus_agent_manager_call_unregister_sync (priv->manager_proxy, cancellable, error);
|
||||
_internal_unregister (self);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
unregister_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
gpointer user_data)
|
||||
unregister_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple = user_data;
|
||||
NMSecretAgent *self;
|
||||
@@ -873,7 +788,8 @@ unregister_cb (DBusGProxy *proxy,
|
||||
|
||||
_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);
|
||||
else
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
@@ -926,13 +842,8 @@ nm_secret_agent_unregister_async (NMSecretAgent *self,
|
||||
|
||||
priv->suppress_auto = TRUE;
|
||||
|
||||
dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy,
|
||||
"Unregister",
|
||||
unregister_cb,
|
||||
simple,
|
||||
NULL,
|
||||
5000,
|
||||
G_TYPE_INVALID);
|
||||
nmdbus_agent_manager_call_unregister (priv->manager_proxy, cancellable,
|
||||
unregister_cb, simple);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1108,42 +1019,30 @@ validate_identifier (const char *identifier)
|
||||
static void
|
||||
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
|
||||
init_common (NMSecretAgent *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);
|
||||
|
||||
if (priv->private_bus == FALSE) {
|
||||
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
DBUS_INTERFACE_DBUS);
|
||||
g_assert (priv->dbus_proxy);
|
||||
priv->session_bus = _nm_dbus_bus_type () == G_BUS_TYPE_SESSION;
|
||||
|
||||
dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
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);
|
||||
g_signal_connect (priv->manager_proxy, "notify::g-name-owner",
|
||||
G_CALLBACK (name_owner_changed), self);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1152,17 +1051,19 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
NMSecretAgent *self = NM_SECRET_AGENT (initable);
|
||||
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self);
|
||||
GDBusProxy *proxy;
|
||||
|
||||
priv->bus = _nm_dbus_new_connection (cancellable, error);
|
||||
if (!priv->bus)
|
||||
return FALSE;
|
||||
|
||||
priv->manager_proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
|
||||
NM_DBUS_PATH_AGENT_MANAGER,
|
||||
NM_DBUS_INTERFACE_AGENT_MANAGER,
|
||||
cancellable, error);
|
||||
if (!priv->manager_proxy)
|
||||
proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
|
||||
NM_DBUS_PATH_AGENT_MANAGER,
|
||||
NM_DBUS_INTERFACE_AGENT_MANAGER,
|
||||
cancellable, error);
|
||||
if (!proxy)
|
||||
return FALSE;
|
||||
priv->manager_proxy = NMDBUS_AGENT_MANAGER (proxy);
|
||||
|
||||
init_common (self);
|
||||
|
||||
@@ -1209,13 +1110,15 @@ init_async_got_proxy (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
NMSecretAgentInitData *init_data = user_data;
|
||||
NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (init_data->self);
|
||||
GDBusProxy *proxy;
|
||||
GError *error = NULL;
|
||||
|
||||
priv->manager_proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error);
|
||||
if (!priv->manager_proxy) {
|
||||
proxy = _nm_dbus_new_proxy_for_connection_finish (result, &error);
|
||||
if (!proxy) {
|
||||
init_async_complete (init_data, error);
|
||||
return;
|
||||
}
|
||||
priv->manager_proxy = NMDBUS_AGENT_MANAGER (proxy);
|
||||
|
||||
init_common (init_data->self);
|
||||
|
||||
@@ -1341,21 +1244,17 @@ dispose (GObject *object)
|
||||
if (priv->registered)
|
||||
nm_secret_agent_unregister_async (self, NULL, NULL, NULL);
|
||||
|
||||
g_free (priv->identifier);
|
||||
priv->identifier = NULL;
|
||||
g_free (priv->nm_owner);
|
||||
priv->nm_owner = NULL;
|
||||
g_clear_pointer (&priv->identifier, g_free);
|
||||
|
||||
while (priv->pending_gets)
|
||||
get_secrets_info_finalize (self, priv->pending_gets->data);
|
||||
|
||||
g_clear_object (&priv->dbus_proxy);
|
||||
g_clear_object (&priv->manager_proxy);
|
||||
g_signal_handlers_disconnect_matched (priv->dbus_secret_agent, G_SIGNAL_MATCH_DATA,
|
||||
0, 0, NULL, NULL, self);
|
||||
g_object_unref (priv->dbus_secret_agent);
|
||||
|
||||
if (priv->bus) {
|
||||
dbus_g_connection_unref (priv->bus);
|
||||
priv->bus = NULL;
|
||||
}
|
||||
g_clear_object (&priv->manager_proxy);
|
||||
g_clear_object (&priv->bus);
|
||||
|
||||
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_STATIC_STRINGS));
|
||||
|
||||
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class),
|
||||
&dbus_glib_nm_secret_agent_object_info);
|
||||
_nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_AGENT_MANAGER,
|
||||
NMDBUS_TYPE_AGENT_MANAGER_PROXY);
|
||||
|
||||
dbus_g_error_domain_register (NM_SECRET_AGENT_ERROR,
|
||||
NM_DBUS_INTERFACE_SECRET_AGENT,
|
||||
NM_TYPE_SECRET_AGENT_ERROR);
|
||||
_nm_dbus_register_error_domain (NM_SECRET_AGENT_ERROR,
|
||||
NM_DBUS_INTERFACE_SECRET_AGENT,
|
||||
NM_TYPE_SECRET_AGENT_ERROR);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -25,6 +25,9 @@
|
||||
#include "nm-utils.h"
|
||||
#include "nm-object-private.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)
|
||||
|
||||
@@ -93,9 +96,9 @@ nm_vpn_connection_get_vpn_state (NMVpnConnection *vpn)
|
||||
}
|
||||
|
||||
static void
|
||||
vpn_state_changed_proxy (DBusGProxy *proxy,
|
||||
NMVpnConnectionState vpn_state,
|
||||
NMVpnConnectionStateReason reason,
|
||||
vpn_state_changed_proxy (NMDBusVpnConnection *proxy,
|
||||
guint vpn_state,
|
||||
guint reason,
|
||||
gpointer 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 },
|
||||
{ NULL },
|
||||
};
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
NM_OBJECT_CLASS (nm_vpn_connection_parent_class)->init_dbus (object);
|
||||
|
||||
@@ -136,16 +139,8 @@ init_dbus (NMObject *object)
|
||||
property_info);
|
||||
|
||||
proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_VPN_CONNECTION);
|
||||
dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
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);
|
||||
g_signal_connect (proxy, "vpn-state-changed",
|
||||
G_CALLBACK (vpn_state_changed_proxy), object);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -188,6 +183,8 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class)
|
||||
g_type_class_add_private (connection_class, sizeof (NMVpnConnectionPrivate));
|
||||
|
||||
_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 */
|
||||
object_class->get_property = get_property;
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "nm-vpn-plugin-utils.h"
|
||||
#include "nm-vpn-plugin.h"
|
||||
#include "nm-core-internal.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
|
||||
#define DATA_KEY_TAG "DATA_KEY="
|
||||
#define DATA_VAL_TAG "DATA_VAL="
|
||||
|
@@ -28,48 +28,10 @@
|
||||
#include "nm-vpn-plugin.h"
|
||||
#include "nm-enum-types.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-utils-private.h"
|
||||
#include "nm-connection.h"
|
||||
#include "nm-dbus-helpers.h"
|
||||
|
||||
static gboolean impl_vpn_plugin_connect (NMVpnPlugin *plugin,
|
||||
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"
|
||||
#include "nmdbus-vpn-plugin.h"
|
||||
|
||||
#define NM_VPN_PLUGIN_QUIT_TIMER 20
|
||||
|
||||
@@ -83,7 +45,8 @@ typedef struct {
|
||||
NMVpnServiceState state;
|
||||
|
||||
/* DBUS-y stuff */
|
||||
DBusGConnection *connection;
|
||||
GDBusConnection *connection;
|
||||
NMDBusVpnPlugin *dbus_vpn_plugin;
|
||||
char *dbus_service_name;
|
||||
|
||||
/* Temporary stuff */
|
||||
@@ -97,7 +60,7 @@ typedef struct {
|
||||
gboolean has_ip6, got_ip6;
|
||||
|
||||
/* Config stuff copied from config to ip4config */
|
||||
GValue banner, tundev, gateway, mtu;
|
||||
char *banner, *tundev, *gateway, *mtu;
|
||||
} 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
|
||||
nm_vpn_plugin_set_connection (NMVpnPlugin *plugin,
|
||||
DBusGConnection *connection)
|
||||
GDBusConnection *connection)
|
||||
{
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
|
||||
|
||||
if (priv->connection)
|
||||
dbus_g_connection_unref (priv->connection);
|
||||
g_clear_object (&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)
|
||||
{
|
||||
DBusGConnection *connection;
|
||||
GDBusConnection *connection;
|
||||
|
||||
g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), NULL);
|
||||
|
||||
connection = NM_VPN_PLUGIN_GET_PRIVATE (plugin)->connection;
|
||||
|
||||
if (connection)
|
||||
dbus_g_connection_ref (connection);
|
||||
g_object_ref (connection);
|
||||
|
||||
return connection;
|
||||
}
|
||||
@@ -303,60 +270,46 @@ schedule_fail_stop (NMVpnPlugin *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
|
||||
nm_vpn_plugin_set_config (NMVpnPlugin *plugin,
|
||||
GHashTable *config)
|
||||
GVariant *config)
|
||||
{
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
|
||||
GValue *val;
|
||||
|
||||
g_return_if_fail (NM_IS_VPN_PLUGIN (plugin));
|
||||
g_return_if_fail (config != NULL);
|
||||
|
||||
priv->got_config = TRUE;
|
||||
|
||||
val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP4);
|
||||
if (val && g_value_get_boolean (val))
|
||||
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_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP4, "b", &priv->has_ip4);
|
||||
g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP6, "b", &priv->has_ip6);
|
||||
|
||||
g_warn_if_fail (priv->has_ip4 || priv->has_ip6);
|
||||
|
||||
/* Record the items that need to also be inserted into the
|
||||
* ip4config, for compatibility with older daemons.
|
||||
*/
|
||||
_g_value_set (&priv->banner, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER));
|
||||
_g_value_set (&priv->tundev, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_TUNDEV));
|
||||
_g_value_set (&priv->gateway, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY));
|
||||
_g_value_set (&priv->mtu, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_MTU));
|
||||
g_clear_pointer (&priv->banner, g_free);
|
||||
g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER, "&s", &priv->banner);
|
||||
g_clear_pointer (&priv->tundev, g_free);
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
|
||||
GHashTable *ip4_config)
|
||||
GVariant *ip4_config)
|
||||
{
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
|
||||
GHashTable *combined_config;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
GVariant *combined_config;
|
||||
GVariantBuilder builder;
|
||||
GVariantIter iter;
|
||||
const char *key, *value;
|
||||
|
||||
g_return_if_fail (NM_IS_VPN_PLUGIN (plugin));
|
||||
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
|
||||
* config too.
|
||||
*/
|
||||
combined_config = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_iter_init (&iter, ip4_config);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
g_hash_table_insert (combined_config, key, value);
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
|
||||
g_variant_iter_init (&iter, ip4_config);
|
||||
while (g_variant_iter_next (&iter, "{&s&s}", &key, &value))
|
||||
g_variant_builder_add (&builder, "{ss}", key, value);
|
||||
|
||||
if (G_VALUE_TYPE (&priv->banner) != G_TYPE_INVALID)
|
||||
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_BANNER, &priv->banner);
|
||||
if (G_VALUE_TYPE (&priv->tundev) != G_TYPE_INVALID)
|
||||
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, &priv->tundev);
|
||||
if (G_VALUE_TYPE (&priv->gateway) != G_TYPE_INVALID)
|
||||
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, &priv->gateway);
|
||||
if (G_VALUE_TYPE (&priv->mtu) != G_TYPE_INVALID)
|
||||
g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_MTU, &priv->mtu);
|
||||
if (priv->banner)
|
||||
g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_BANNER, &priv->banner);
|
||||
if (priv->tundev)
|
||||
g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, &priv->tundev);
|
||||
if (priv->gateway)
|
||||
g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, &priv->gateway);
|
||||
if (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_hash_table_destroy (combined_config);
|
||||
g_variant_unref (combined_config);
|
||||
|
||||
if ( priv->has_ip4 == priv->got_ip4
|
||||
&& priv->has_ip6 == priv->got_ip6)
|
||||
@@ -400,7 +355,7 @@ nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
|
||||
|
||||
void
|
||||
nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin,
|
||||
GHashTable *ip6_config)
|
||||
GVariant *ip6_config)
|
||||
{
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
|
||||
|
||||
@@ -433,58 +388,63 @@ connect_timer_start (NMVpnPlugin *plugin)
|
||||
connect_timer_removed);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
_connect_generic (NMVpnPlugin *plugin,
|
||||
GHashTable *properties,
|
||||
GHashTable *details,
|
||||
GError **error)
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *properties,
|
||||
GVariant *details)
|
||||
{
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
|
||||
NMVpnPluginClass *vpn_class = NM_VPN_PLUGIN_GET_CLASS (plugin);
|
||||
GVariant *properties_dict;
|
||||
NMConnection *connection;
|
||||
gboolean success = FALSE;
|
||||
GError *local = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (priv->state != NM_VPN_SERVICE_STATE_STOPPED &&
|
||||
priv->state != NM_VPN_SERVICE_STATE_INIT) {
|
||||
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_WRONG_STATE,
|
||||
"Could not start connection: wrong plugin state %d",
|
||||
priv->state);
|
||||
return FALSE;
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_WRONG_STATE,
|
||||
"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_dict, &local);
|
||||
g_variant_unref (properties_dict);
|
||||
connection = nm_simple_connection_new_from_dbus (properties, &error);
|
||||
if (!connection) {
|
||||
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
|
||||
"Invalid connection: (%d) %s",
|
||||
local->code, local->message);
|
||||
g_clear_error (&local);
|
||||
return FALSE;
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
|
||||
"Invalid connection: (%d) %s",
|
||||
error->code, error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
|
||||
priv->interactive = FALSE;
|
||||
if (details && !vpn_class->connect_interactive) {
|
||||
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED,
|
||||
"Plugin does not implement ConnectInteractive()");
|
||||
return FALSE;
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED,
|
||||
"Plugin does not implement ConnectInteractive()");
|
||||
return;
|
||||
}
|
||||
|
||||
nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING);
|
||||
|
||||
if (details) {
|
||||
priv->interactive = TRUE;
|
||||
success = vpn_class->connect_interactive (plugin, connection, details, error);
|
||||
success = vpn_class->connect_interactive (plugin, connection, details, &error);
|
||||
} else
|
||||
success = vpn_class->connect (plugin, connection, error);
|
||||
success = vpn_class->connect (plugin, connection, &error);
|
||||
|
||||
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. */
|
||||
connect_timer_start (plugin);
|
||||
} else {
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
|
||||
/* Stop the plugin from an idle handler so that the Connect
|
||||
* method return gets sent before the STOP StateChanged signal.
|
||||
*/
|
||||
@@ -492,126 +452,125 @@ _connect_generic (NMVpnPlugin *plugin,
|
||||
}
|
||||
|
||||
g_object_unref (connection);
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
impl_vpn_plugin_connect (NMVpnPlugin *plugin,
|
||||
GHashTable *connection,
|
||||
GError **error)
|
||||
GDBusMethodInvocation *context,
|
||||
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,
|
||||
GHashTable *connection,
|
||||
GHashTable *details,
|
||||
GError **error)
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *connection,
|
||||
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,
|
||||
GHashTable *properties,
|
||||
char **setting_name,
|
||||
GError **err)
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *properties,
|
||||
gpointer user_data)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GVariant *properties_dict;
|
||||
NMConnection *connection;
|
||||
char *sn = NULL;
|
||||
GError *ns_err = NULL;
|
||||
gboolean needed = FALSE;
|
||||
GError *cnfh_err = NULL;
|
||||
char *setting_name;
|
||||
gboolean needed;
|
||||
GError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE);
|
||||
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);
|
||||
connection = nm_simple_connection_new_from_dbus (properties, &error);
|
||||
if (!connection) {
|
||||
g_set_error (err,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
|
||||
"The connection was invalid: '%s' / '%s' invalid: %d.",
|
||||
g_type_name (nm_setting_lookup_type_by_quark (cnfh_err->domain)),
|
||||
cnfh_err->message, cnfh_err->code);
|
||||
g_error_free (cnfh_err);
|
||||
return FALSE;
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
|
||||
"The connection was invalid: '%s' / '%s' invalid: %d.",
|
||||
g_type_name (nm_setting_lookup_type_by_quark (error->domain)),
|
||||
error->message, error->code);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets) {
|
||||
*setting_name = "";
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
g_dbus_method_invocation_return_value (context,
|
||||
g_variant_new ("(s)", ""));
|
||||
return;
|
||||
}
|
||||
|
||||
needed = NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets (plugin, connection, &sn, &ns_err);
|
||||
if (ns_err) {
|
||||
*err = g_error_copy (ns_err);
|
||||
g_error_free (ns_err);
|
||||
goto out;
|
||||
needed = NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets (plugin, connection, &setting_name, &error);
|
||||
if (error) {
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
if (needed) {
|
||||
g_assert (sn);
|
||||
*setting_name = g_strdup (sn);
|
||||
g_assert (setting_name);
|
||||
g_dbus_method_invocation_return_value (context,
|
||||
g_variant_new ("(s)", setting_name));
|
||||
g_free (setting_name);
|
||||
} else {
|
||||
/* 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,
|
||||
GHashTable *properties,
|
||||
GError **error)
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *properties,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
|
||||
GVariant *properties_dict;
|
||||
NMConnection *connection;
|
||||
GError *local = NULL;
|
||||
GError *error = NULL;
|
||||
gboolean success;
|
||||
|
||||
if (priv->state != NM_VPN_SERVICE_STATE_STARTING) {
|
||||
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_WRONG_STATE,
|
||||
"Could not accept new secrets: wrong plugin state %d",
|
||||
priv->state);
|
||||
return FALSE;
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_WRONG_STATE,
|
||||
"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_dict, &local);
|
||||
g_variant_unref (properties_dict);
|
||||
connection = nm_simple_connection_new_from_dbus (properties, &error);
|
||||
if (!connection) {
|
||||
g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
|
||||
"Invalid connection: (%d) %s",
|
||||
local->code, local->message);
|
||||
g_clear_error (&local);
|
||||
return FALSE;
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
|
||||
"Invalid connection: (%d) %s",
|
||||
error->code, error->message);
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
|
||||
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,
|
||||
"Could not accept new secrets: plugin cannot process interactive secrets");
|
||||
g_dbus_method_invocation_return_error (context,
|
||||
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);
|
||||
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) {
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
|
||||
/* Add a timer to make sure we do not wait indefinitely for the successful connect. */
|
||||
connect_timer_start (plugin);
|
||||
} else {
|
||||
g_dbus_method_invocation_take_error (context, error);
|
||||
|
||||
/* Stop the plugin from and idle handler so that the NewSecrets
|
||||
* method return gets sent before the STOP StateChanged signal.
|
||||
*/
|
||||
@@ -619,7 +578,6 @@ impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin,
|
||||
}
|
||||
|
||||
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,
|
||||
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,
|
||||
GHashTable *config,
|
||||
GError **err)
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *config,
|
||||
gpointer user_data)
|
||||
{
|
||||
nm_vpn_plugin_set_config (plugin, config);
|
||||
|
||||
return TRUE;
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
impl_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
|
||||
GHashTable *config,
|
||||
GError **err)
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *config,
|
||||
gpointer user_data)
|
||||
{
|
||||
nm_vpn_plugin_set_ip4_config (plugin, config);
|
||||
|
||||
return TRUE;
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
impl_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin,
|
||||
GHashTable *config,
|
||||
GError **err)
|
||||
GDBusMethodInvocation *context,
|
||||
GVariant *config,
|
||||
gpointer user_data)
|
||||
{
|
||||
nm_vpn_plugin_set_ip6_config (plugin, config);
|
||||
|
||||
return TRUE;
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
impl_vpn_plugin_set_failure (NMVpnPlugin *plugin,
|
||||
GDBusMethodInvocation *context,
|
||||
char *reason,
|
||||
GError **err)
|
||||
gpointer user_data)
|
||||
{
|
||||
nm_vpn_plugin_failure (plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG);
|
||||
|
||||
return TRUE;
|
||||
g_dbus_method_invocation_return_value (context, NULL);
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
@@ -750,11 +714,12 @@ nm_vpn_plugin_init (NMVpnPlugin *plugin)
|
||||
static gboolean
|
||||
init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (initable);
|
||||
NMVpnPlugin *plugin;
|
||||
DBusGConnection *connection;
|
||||
DBusGProxy *proxy;
|
||||
guint request_name_result;
|
||||
NMVpnPlugin *plugin = NM_VPN_PLUGIN (initable);
|
||||
NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin);
|
||||
GDBusConnection *connection = NULL;
|
||||
GDBusProxy *proxy;
|
||||
GVariant *ret;
|
||||
gboolean success = FALSE;
|
||||
|
||||
if (!priv->dbus_service_name) {
|
||||
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;
|
||||
}
|
||||
|
||||
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
|
||||
if (!connection)
|
||||
return FALSE;
|
||||
|
||||
proxy = dbus_g_proxy_new_for_name (connection,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
DBUS_INTERFACE_DBUS);
|
||||
proxy = g_dbus_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
|
||||
NULL,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
DBUS_INTERFACE_DBUS,
|
||||
cancellable, error);
|
||||
if (!proxy)
|
||||
goto out;
|
||||
|
||||
if (!dbus_g_proxy_call (proxy, "RequestName", error,
|
||||
G_TYPE_STRING, priv->dbus_service_name,
|
||||
G_TYPE_UINT, 0,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_UINT, &request_name_result,
|
||||
G_TYPE_INVALID)) {
|
||||
g_object_unref (proxy);
|
||||
return FALSE;
|
||||
}
|
||||
ret = g_dbus_proxy_call_sync (proxy,
|
||||
"RequestName",
|
||||
g_variant_new ("(s)", priv->dbus_service_name),
|
||||
G_DBUS_CALL_FLAGS_NONE, 0,
|
||||
cancellable, error);
|
||||
g_object_unref (proxy);
|
||||
if (!ret)
|
||||
goto out;
|
||||
g_variant_unref (ret);
|
||||
|
||||
dbus_g_connection_register_g_object (connection,
|
||||
NM_VPN_DBUS_PLUGIN_PATH,
|
||||
G_OBJECT (initable));
|
||||
priv->dbus_vpn_plugin = nmdbus_vpn_plugin_skeleton_new ();
|
||||
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_vpn_plugin),
|
||||
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_state (plugin, NM_VPN_SERVICE_STATE_INIT);
|
||||
|
||||
return TRUE;
|
||||
success = TRUE;
|
||||
|
||||
out:
|
||||
g_clear_object (&connection);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -870,14 +859,10 @@ finalize (GObject *object)
|
||||
nm_vpn_plugin_set_connection (plugin, NULL);
|
||||
g_free (priv->dbus_service_name);
|
||||
|
||||
if (G_IS_VALUE (&priv->banner))
|
||||
g_value_unset (&priv->banner);
|
||||
if (G_IS_VALUE (&priv->tundev))
|
||||
g_value_unset (&priv->tundev);
|
||||
if (G_IS_VALUE (&priv->gateway))
|
||||
g_value_unset (&priv->gateway);
|
||||
if (G_IS_VALUE (&priv->mtu))
|
||||
g_value_unset (&priv->mtu);
|
||||
g_clear_pointer (&priv->banner, g_free);
|
||||
g_clear_pointer (&priv->tundev, g_free);
|
||||
g_clear_pointer (&priv->gateway, g_free);
|
||||
g_clear_pointer (&priv->mtu, g_free);
|
||||
|
||||
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));
|
||||
|
||||
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (plugin_class),
|
||||
&dbus_glib_nm_vpn_plugin_object_info);
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
@@ -981,7 +963,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMVpnPluginClass, state_changed),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__UINT,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_UINT);
|
||||
|
||||
@@ -999,9 +981,9 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMVpnPluginClass, config),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__BOXED,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT);
|
||||
G_TYPE_VARIANT);
|
||||
|
||||
signals[IP4_CONFIG] =
|
||||
g_signal_new ("ip4-config",
|
||||
@@ -1009,9 +991,9 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMVpnPluginClass, ip4_config),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__BOXED,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT);
|
||||
G_TYPE_VARIANT);
|
||||
|
||||
signals[IP6_CONFIG] =
|
||||
g_signal_new ("ip6-config",
|
||||
@@ -1019,9 +1001,9 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMVpnPluginClass, ip6_config),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__BOXED,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
DBUS_TYPE_G_MAP_OF_VARIANT);
|
||||
G_TYPE_VARIANT);
|
||||
|
||||
signals[LOGIN_BANNER] =
|
||||
g_signal_new ("login-banner",
|
||||
@@ -1029,7 +1011,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMVpnPluginClass, login_banner),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__STRING,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_STRING);
|
||||
|
||||
@@ -1039,7 +1021,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMVpnPluginClass, failure),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__UINT,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_UINT);
|
||||
|
||||
@@ -1049,13 +1031,13 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NMVpnPluginClass, quit),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
NULL,
|
||||
G_TYPE_NONE, 0,
|
||||
G_TYPE_NONE);
|
||||
|
||||
dbus_g_error_domain_register (NM_VPN_PLUGIN_ERROR,
|
||||
NM_DBUS_VPN_ERROR_PREFIX,
|
||||
NM_TYPE_VPN_PLUGIN_ERROR);
|
||||
_nm_dbus_register_error_domain (NM_VPN_PLUGIN_ERROR,
|
||||
NM_DBUS_VPN_ERROR_PREFIX,
|
||||
NM_TYPE_VPN_PLUGIN_ERROR);
|
||||
|
||||
setup_unix_signal_handler ();
|
||||
}
|
||||
|
@@ -26,9 +26,7 @@
|
||||
#error "Only <NetworkManager.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <gio/gio.h>
|
||||
#include <nm-vpn-dbus-interface.h>
|
||||
#include <nm-connection.h>
|
||||
|
||||
@@ -98,7 +96,7 @@ typedef struct {
|
||||
NMVpnServiceState state);
|
||||
|
||||
void (*ip4_config) (NMVpnPlugin *plugin,
|
||||
GHashTable *ip4_config);
|
||||
GVariant *ip4_config);
|
||||
|
||||
void (*login_banner) (NMVpnPlugin *plugin,
|
||||
const char *banner);
|
||||
@@ -109,10 +107,10 @@ typedef struct {
|
||||
void (*quit) (NMVpnPlugin *plugin);
|
||||
|
||||
void (*config) (NMVpnPlugin *plugin,
|
||||
GHashTable *config);
|
||||
GVariant *config);
|
||||
|
||||
void (*ip6_config) (NMVpnPlugin *plugin,
|
||||
GHashTable *config);
|
||||
GVariant *config);
|
||||
|
||||
/* virtual methods */
|
||||
gboolean (*connect) (NMVpnPlugin *plugin,
|
||||
@@ -133,7 +131,7 @@ typedef struct {
|
||||
|
||||
gboolean (*connect_interactive) (NMVpnPlugin *plugin,
|
||||
NMConnection *connection,
|
||||
GHashTable *details,
|
||||
GVariant *details,
|
||||
GError **error);
|
||||
|
||||
/*< private >*/
|
||||
@@ -143,7 +141,7 @@ typedef struct {
|
||||
GType nm_vpn_plugin_get_type (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);
|
||||
void nm_vpn_plugin_set_state (NMVpnPlugin *plugin,
|
||||
NMVpnServiceState state);
|
||||
@@ -159,13 +157,13 @@ void nm_vpn_plugin_failure (NMVpnPlugin *plugin,
|
||||
NMVpnPluginFailure reason);
|
||||
|
||||
void nm_vpn_plugin_set_config (NMVpnPlugin *plugin,
|
||||
GHashTable *config);
|
||||
GVariant *config);
|
||||
|
||||
void nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin,
|
||||
GHashTable *ip4_config);
|
||||
GVariant *ip4_config);
|
||||
|
||||
void nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin,
|
||||
GHashTable *ip6_config);
|
||||
GVariant *ip6_config);
|
||||
|
||||
gboolean nm_vpn_plugin_disconnect (NMVpnPlugin *plugin,
|
||||
GError **err);
|
||||
|
@@ -9,13 +9,11 @@ AM_CPPFLAGS = \
|
||||
-DNETWORKMANAGER_COMPILATION \
|
||||
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
|
||||
-DTEST_NM_SERVICE=\"$(abs_top_srcdir)/tools/test-networkmanager-service.py\" \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(DBUS_CFLAGS)
|
||||
$(GLIB_CFLAGS)
|
||||
|
||||
LDADD = \
|
||||
$(top_builddir)/libnm/libnm.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(DBUS_LIBS)
|
||||
$(GLIB_LIBS)
|
||||
|
||||
noinst_PROGRAMS = $(TESTS)
|
||||
|
||||
|
@@ -32,9 +32,9 @@ name_exists (GDBusConnection *c, const char *name)
|
||||
gboolean exists = FALSE;
|
||||
|
||||
reply = g_dbus_connection_call_sync (c,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
DBUS_INTERFACE_DBUS,
|
||||
"org.freedesktop.DBus",
|
||||
"/org/freedesktop/DBus",
|
||||
"org.freedesktop.DBus",
|
||||
"GetNameOwner",
|
||||
g_variant_new ("(s)", name),
|
||||
NULL,
|
||||
|
@@ -18,9 +18,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
@@ -18,9 +18,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
@@ -34,7 +31,7 @@
|
||||
|
||||
static NMTestServiceInfo *sinfo;
|
||||
static NMRemoteSettings *settings = NULL;
|
||||
DBusGConnection *bus = NULL;
|
||||
GDBusConnection *bus = NULL;
|
||||
NMRemoteConnection *remote = NULL;
|
||||
|
||||
/*******************************************************************/
|
||||
@@ -88,16 +85,16 @@ test_add_connection (void)
|
||||
/*******************************************************************/
|
||||
|
||||
static void
|
||||
set_visible_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
set_visible_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
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 (success == TRUE);
|
||||
g_variant_unref (ret);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -129,7 +126,7 @@ test_make_invisible (void)
|
||||
{
|
||||
time_t start, now;
|
||||
GSList *list, *iter;
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
gboolean visible_changed = FALSE, connection_removed = FALSE;
|
||||
gboolean has_settings = FALSE;
|
||||
char *path;
|
||||
@@ -141,15 +138,23 @@ test_make_invisible (void)
|
||||
g_signal_connect (settings, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed);
|
||||
|
||||
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
|
||||
proxy = dbus_g_proxy_new_for_name (bus,
|
||||
NM_DBUS_SERVICE,
|
||||
path,
|
||||
NM_DBUS_INTERFACE_SETTINGS_CONNECTION);
|
||||
proxy = g_dbus_proxy_new_sync (bus,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
NULL,
|
||||
NM_DBUS_SERVICE,
|
||||
path,
|
||||
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
|
||||
NULL,
|
||||
NULL);
|
||||
g_assert (proxy != NULL);
|
||||
|
||||
/* Bypass the NMRemoteSettings object so we can test it independently */
|
||||
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL,
|
||||
G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID);
|
||||
g_dbus_proxy_call (proxy,
|
||||
"SetVisible",
|
||||
g_variant_new ("(b)", FALSE),
|
||||
G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
NULL,
|
||||
set_visible_cb, NULL);
|
||||
|
||||
/* Wait for the connection to be removed */
|
||||
start = time (NULL);
|
||||
@@ -198,7 +203,7 @@ test_make_visible (void)
|
||||
{
|
||||
time_t start, now;
|
||||
GSList *list, *iter;
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
gboolean found = FALSE;
|
||||
char *path;
|
||||
NMRemoteConnection *new = NULL;
|
||||
@@ -210,16 +215,23 @@ test_make_visible (void)
|
||||
G_CALLBACK (vis_new_connection_cb), &new);
|
||||
|
||||
path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote)));
|
||||
proxy = dbus_g_proxy_new_for_name (bus,
|
||||
NM_DBUS_SERVICE,
|
||||
path,
|
||||
NM_DBUS_INTERFACE_SETTINGS_CONNECTION);
|
||||
proxy = g_dbus_proxy_new_sync (bus,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
NULL,
|
||||
NM_DBUS_SERVICE,
|
||||
path,
|
||||
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
|
||||
NULL,
|
||||
NULL);
|
||||
g_assert (proxy != NULL);
|
||||
|
||||
/* Bypass the NMRemoteSettings object so we can test it independently */
|
||||
dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL,
|
||||
G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID);
|
||||
|
||||
g_dbus_proxy_call (proxy,
|
||||
"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 */
|
||||
start = time (NULL);
|
||||
@@ -255,16 +267,16 @@ test_make_visible (void)
|
||||
/*******************************************************************/
|
||||
|
||||
static void
|
||||
deleted_cb (DBusGProxy *proxy,
|
||||
DBusGProxyCall *call,
|
||||
deleted_cb (GObject *proxy,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
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 (success == TRUE);
|
||||
g_variant_unref (ret);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -280,7 +292,7 @@ test_remove_connection (void)
|
||||
NMRemoteConnection *connection;
|
||||
time_t start, now;
|
||||
GSList *list, *iter;
|
||||
DBusGProxy *proxy;
|
||||
GDBusProxy *proxy;
|
||||
gboolean done = FALSE;
|
||||
char *path;
|
||||
|
||||
@@ -294,14 +306,23 @@ test_remove_connection (void)
|
||||
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
|
||||
g_signal_connect (settings, "connection-removed", G_CALLBACK (removed_cb), &done);
|
||||
|
||||
proxy = dbus_g_proxy_new_for_name (bus,
|
||||
NM_DBUS_SERVICE,
|
||||
path,
|
||||
NM_DBUS_INTERFACE_SETTINGS_CONNECTION);
|
||||
proxy = g_dbus_proxy_new_sync (bus,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
NULL,
|
||||
NM_DBUS_SERVICE,
|
||||
path,
|
||||
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
|
||||
NULL,
|
||||
NULL);
|
||||
g_assert (proxy != NULL);
|
||||
|
||||
/* 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);
|
||||
do {
|
||||
@@ -481,7 +502,7 @@ main (int argc, char **argv)
|
||||
|
||||
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);
|
||||
|
||||
sinfo = nm_test_service_init ();
|
||||
@@ -504,7 +525,7 @@ main (int argc, char **argv)
|
||||
|
||||
nm_test_service_cleanup (sinfo);
|
||||
g_object_unref (settings);
|
||||
dbus_g_connection_unref (bus);
|
||||
g_object_unref (bus);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@@ -387,6 +387,7 @@ connection_activated_none_cb (NMClient *c,
|
||||
TestSecretAgentData *sadata = user_data;
|
||||
|
||||
g_assert (error != NULL);
|
||||
g_dbus_error_strip_remote_error (error);
|
||||
g_assert_cmpstr (error->message, ==, "No secret agent available");
|
||||
|
||||
g_main_loop_quit (sadata->loop);
|
||||
@@ -431,6 +432,7 @@ connection_activated_no_secrets_cb (NMClient *c,
|
||||
TestSecretAgentData *sadata = user_data;
|
||||
|
||||
g_assert (error != NULL);
|
||||
g_dbus_error_strip_remote_error (error);
|
||||
g_assert_cmpstr (error->message, ==, "No secrets provided");
|
||||
|
||||
g_main_loop_quit (sadata->loop);
|
||||
@@ -465,6 +467,7 @@ connection_activated_cancel_cb (NMClient *c,
|
||||
TestSecretAgentData *sadata = user_data;
|
||||
|
||||
g_assert (error != NULL);
|
||||
g_dbus_error_strip_remote_error (error);
|
||||
g_assert_cmpstr (error->message, ==, "User canceled");
|
||||
|
||||
g_main_loop_quit (sadata->loop);
|
||||
@@ -519,6 +522,7 @@ connection_activated_good_cb (NMClient *c,
|
||||
* other tests won't get to).
|
||||
*/
|
||||
g_assert (error != NULL);
|
||||
g_dbus_error_strip_remote_error (error);
|
||||
g_assert_cmpstr (error->message, ==, "Not yet implemented");
|
||||
|
||||
g_main_loop_quit (sadata->loop);
|
||||
|
@@ -46,6 +46,7 @@
|
||||
#include "nm-setting-wireless-security.h"
|
||||
#include "nm-manager-auth.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
|
||||
@@ -1840,3 +1841,147 @@ nm_utils_ipv6_interface_identfier_get_from_addr (NMUtilsIPv6IfaceId *iid,
|
||||
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);
|
||||
}
|
||||
|
@@ -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,
|
||||
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__ */
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include "nm-dispatcher-api.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-utils-private.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-device.h"
|
||||
@@ -475,7 +474,7 @@ _dispatcher_call (DispatcherAction action,
|
||||
GVariant *connection_dict;
|
||||
|
||||
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);
|
||||
|
||||
connection_props = value_hash_create ();
|
||||
|
@@ -52,7 +52,6 @@
|
||||
#include "nm-manager-auth.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-utils-private.h"
|
||||
#include "nm-device-factory.h"
|
||||
#include "nm-enum-types.h"
|
||||
#include "nm-sleep-monitor.h"
|
||||
@@ -3298,7 +3297,7 @@ impl_manager_add_and_activate_connection (NMManager *self,
|
||||
*/
|
||||
connection = nm_simple_connection_new ();
|
||||
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);
|
||||
g_variant_unref (settings_dict);
|
||||
|
@@ -40,7 +40,7 @@
|
||||
#include "nm-dbus-manager.h"
|
||||
#include "nm-session-monitor.h"
|
||||
#include "nm-simple-connection.h"
|
||||
#include "nm-utils-private.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
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) {
|
||||
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);
|
||||
g_variant_unref (secrets_dict);
|
||||
}
|
||||
@@ -1101,7 +1101,7 @@ get_start (gpointer user_data)
|
||||
tmp = nm_simple_connection_new_clone (req->connection);
|
||||
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)) {
|
||||
req_complete_error (parent, error);
|
||||
g_clear_error (&error);
|
||||
|
@@ -35,7 +35,7 @@
|
||||
#include "nm-logging.h"
|
||||
#include "nm-auth-subject.h"
|
||||
#include "nm-simple-connection.h"
|
||||
#include "nm-utils-private.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
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);
|
||||
|
||||
r = request_new (self, cpath, NULL, callback, callback_data);
|
||||
|
@@ -29,7 +29,6 @@
|
||||
#include <nm-setting-vpn.h>
|
||||
#include <nm-setting-wireless.h>
|
||||
#include <nm-utils.h>
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
#include "nm-settings-connection.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
|
||||
* 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)) {
|
||||
/* Now that all secrets are updated, copy and cache new secrets,
|
||||
* 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_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,
|
||||
NM_CONNECTION (self),
|
||||
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);
|
||||
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);
|
||||
g_hash_table_destroy (settings_hash);
|
||||
g_variant_unref (settings);
|
||||
@@ -1340,7 +1339,7 @@ impl_settings_connection_update_helper (NMSettingsConnection *self,
|
||||
|
||||
/* Check if the settings are valid first */
|
||||
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);
|
||||
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);
|
||||
if (dict)
|
||||
hash = _nm_utils_connection_dict_to_hash (dict);
|
||||
hash = nm_utils_connection_dict_to_hash (dict);
|
||||
else
|
||||
hash = g_hash_table_new (NULL, NULL);
|
||||
dbus_g_method_return (context, hash);
|
||||
|
@@ -1224,7 +1224,7 @@ impl_settings_add_connection_helper (NMSettings *self,
|
||||
GVariant *dict;
|
||||
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);
|
||||
g_variant_unref (dict);
|
||||
if (connection) {
|
||||
|
@@ -40,7 +40,6 @@
|
||||
#include "nm-platform.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-utils-private.h"
|
||||
#include "nm-active-connection.h"
|
||||
#include "nm-dbus-glib-types.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);
|
||||
if (username == NULL || existing) {
|
||||
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);
|
||||
return hash;
|
||||
}
|
||||
@@ -1482,7 +1481,7 @@ _hash_with_username (NMConnection *connection, const char *username)
|
||||
dict = nm_connection_to_dbus (dup, NM_CONNECTION_SERIALIZE_ALL);
|
||||
g_object_unref (dup);
|
||||
|
||||
hash = _nm_utils_connection_dict_to_hash (dict);
|
||||
hash = nm_utils_connection_dict_to_hash (dict);
|
||||
g_variant_unref (dict);
|
||||
return hash;
|
||||
}
|
||||
|
Reference in New Issue
Block a user