diff options
Diffstat (limited to 'src/ppp-manager/nm-ppp-manager.c')
-rw-r--r-- | src/ppp-manager/nm-ppp-manager.c | 157 |
1 files changed, 77 insertions, 80 deletions
diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index 0b8481d419..9a0da46a9c 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -54,23 +54,7 @@ #include "nm-logging.h" #include "nm-posix-signals.h" #include "nm-platform.h" - -static void impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context); - -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err); - -static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -static gboolean impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -#include "nm-ppp-manager-glue.h" +#include "nmdbus-ppp-manager.h" static void _ppp_cleanup (NMPPPManager *manager); @@ -84,7 +68,7 @@ typedef struct { char *parent_iface; NMActRequest *act_req; - DBusGMethodInvocation *pending_secrets_context; + GDBusMethodInvocation *pending_secrets_context; guint32 secrets_id; const char *secrets_setting_name; @@ -99,7 +83,10 @@ typedef struct { #define NM_PPP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPP_MANAGER, NMPPPManagerPrivate)) -G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, G_TYPE_OBJECT) +static void nm_ppp_manager_dbus_iface_init (NMDBusPPPManagerIface *iface, gpointer iface_data); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMPPPManager, nm_ppp_manager, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (NMDBUS_TYPE_PPP_MANAGER, nm_ppp_manager_dbus_iface_init)) enum { STATE_CHANGED, @@ -143,12 +130,11 @@ static void constructed (GObject *object) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); - DBusGConnection *connection; static guint32 counter = 0; priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/PPP/%d", counter++); - connection = nm_dbus_manager_get_connection (nm_dbus_manager_get ()); - dbus_g_connection_register_g_object (connection, priv->dbus_path, object); + nm_dbus_manager_register_object (nm_dbus_manager_get (), + priv->dbus_path, object); G_OBJECT_CLASS (nm_ppp_manager_parent_class)->constructed (object); } @@ -266,9 +252,6 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); - - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class), - &dbus_glib_nm_ppp_manager_object_info); } NMPPPManager * @@ -429,14 +412,13 @@ ppp_secrets_cb (NMActRequest *req, if (error) { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); + g_dbus_method_invocation_return_gerror (priv->pending_secrets_context, error); goto out; } if (!extract_details_from_connection (connection, priv->secrets_setting_name, &username, &password, &local)) { nm_log_warn (LOGD_PPP, "%s", local->message); - dbus_g_method_return_error (priv->pending_secrets_context, local); - g_clear_error (&local); + g_dbus_method_invocation_take_error (priv->pending_secrets_context, local); goto out; } @@ -446,7 +428,8 @@ ppp_secrets_cb (NMActRequest *req, * against libnm just to parse this. So instead, let's just send what * it needs. */ - dbus_g_method_return (priv->pending_secrets_context, username, password); + g_dbus_method_invocation_return_value (priv->pending_secrets_context, + g_variant_new ("(ss)", username, password)); out: priv->pending_secrets_context = NULL; @@ -454,10 +437,11 @@ ppp_secrets_cb (NMActRequest *req, priv->secrets_setting_name = NULL; } -static void -impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context) +static gboolean +handle_ppp_manager_need_secrets (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context) { + NMPPPManager *manager = NM_PPP_MANAGER (dbus_ppp_manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMConnection *connection; const char *username = NULL; @@ -479,10 +463,9 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, ppp_secrets_cb (priv->act_req, priv->secrets_id, connection, NULL, manager); } else { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); } - return; + return TRUE; } /* Only ask for completely new secrets after retrying them once; some devices @@ -504,35 +487,38 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, if (hints) g_ptr_array_free (hints, TRUE); + + return TRUE; } -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err) +static gboolean +handle_ppp_manager_set_state (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context, + guint32 state) { - g_signal_emit (manager, signals[STATE_CHANGED], 0, state); + g_signal_emit_by_name (dbus_ppp_manager, "state-changed", 0, state); + g_dbus_method_invocation_return_value (context, NULL); return TRUE; } static gboolean set_ip_config_common (NMPPPManager *self, - GHashTable *hash, + GVariant *dict, const char *iface_prop, guint32 *out_mtu) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); NMConnection *connection; NMSettingPpp *s_ppp; - GValue *val; + const char *ip_iface; - val = g_hash_table_lookup (hash, iface_prop); - if (!val || !G_VALUE_HOLDS_STRING (val)) { + if (!g_variant_lookup (dict, iface_prop, "&s", &ip_iface)) { nm_log_err (LOGD_PPP, "no interface received!"); return FALSE; } if (priv->ip_iface == NULL) - priv->ip_iface = g_value_dup_string (val); + priv->ip_iface = g_strdup (ip_iface); /* Got successful IP config; obviously the secrets worked */ connection = nm_act_request_get_connection (priv->act_req); @@ -549,16 +535,18 @@ set_ip_config_common (NMPPPManager *self, } static gboolean -impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config_hash, - GError **err) +handle_ppp_manager_set_ip4_config (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context, + GVariant *config_dict) { + NMPPPManager *manager = NM_PPP_MANAGER (dbus_ppp_manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP4Config *config; NMPlatformIP4Address address; - GValue *val; + GVariant *val; int i; guint32 mtu = 0; + guint32 uval; nm_log_info (LOGD_PPP, "PPP manager (IPv4 Config Get) reply received."); @@ -568,19 +556,16 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, memset (&address, 0, sizeof (address)); address.plen = 32; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY); - if (val) { - nm_ip4_config_set_gateway (config, g_value_get_uint (val)); - address.peer_address = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_GATEWAY, "u", &uval)) { + nm_ip4_config_set_gateway (config, uval); + address.peer_address = uval; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS); - if (val) - address.address = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_ADDRESS, "u", &uval)) + address.address = uval; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_PREFIX); - if (val) - address.plen = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &uval)) + address.plen = uval; if (address.address && address.plen) { address.source = NM_PLATFORM_SOURCE_PPP; @@ -590,23 +575,25 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, goto out; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS); - if (val) { - GArray *dns = (GArray *) g_value_get_boxed (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_DNS, "@au", &val)) { + const guint32 *array; + gsize length; - for (i = 0; i < dns->len; i++) - nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i)); + array = g_variant_get_fixed_array (val, &length, sizeof (guint32)); + for (i = 0; i < length; i++) + nm_ip4_config_add_nameserver (config, array[i]); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_WINS); - if (val) { - GArray *wins = (GArray *) g_value_get_boxed (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_WINS, "@au", &val)) { + const guint32 *array; + gsize length; - for (i = 0; i < wins->len; i++) - nm_ip4_config_add_wins (config, g_array_index (wins, guint, i)); + array = g_variant_get_fixed_array (val, &length, sizeof (guint32)); + for (i = 0; i < length; i++) + nm_ip4_config_add_wins (config, array[i]); } - if (!set_ip_config_common (manager, config_hash, NM_PPP_IP4_CONFIG_INTERFACE, &mtu)) + if (!set_ip_config_common (manager, config_dict, NM_PPP_IP4_CONFIG_INTERFACE, &mtu)) goto out; if (mtu) @@ -617,6 +604,7 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, out: g_object_unref (config); + g_dbus_method_invocation_return_value (context, NULL); return TRUE; } @@ -624,21 +612,18 @@ out: * returns the IID. */ static gboolean -iid_value_to_ll6_addr (GHashTable *hash, +iid_value_to_ll6_addr (GVariant *dict, const char *prop, struct in6_addr *out_addr, NMUtilsIPv6IfaceId *out_iid) { - GValue *val; guint64 iid; - val = g_hash_table_lookup (hash, prop); - if (!val || !G_VALUE_HOLDS (val, G_TYPE_UINT64)) { + if (!g_variant_lookup (dict, prop, "t", &iid)) { nm_log_dbg (LOGD_PPP, "pppd plugin property '%s' missing or not a uint64", prop); return FALSE; } - iid = g_value_get_uint64 (val); g_return_val_if_fail (iid != 0, FALSE); /* Construct an IPv6 LL address from the interface identifier. See @@ -654,10 +639,11 @@ iid_value_to_ll6_addr (GHashTable *hash, } static gboolean -impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *hash, - GError **err) +handle_ppp_manager_set_ip6_config (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context, + GVariant *config_dict) { + NMPPPManager *manager = NM_PPP_MANAGER (dbus_ppp_manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP6Config *config; NMPlatformIP6Address addr; @@ -673,15 +659,15 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, memset (&addr, 0, sizeof (addr)); addr.plen = 64; - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { nm_ip6_config_set_gateway (config, &a); addr.peer_address = a; } - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { nm_ip6_config_add_address (config, &addr); - if (set_ip_config_common (manager, hash, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { + if (set_ip_config_common (manager, config_dict, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { /* Push the IPv6 config and interface identifier up to the device */ g_signal_emit (manager, signals[IP6_CONFIG], 0, priv->ip_iface, &iid, config); } @@ -689,6 +675,7 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, nm_log_err (LOGD_PPP, "invalid IPv6 address received!"); g_object_unref (config); + g_dbus_method_invocation_return_value (context, NULL); return TRUE; } @@ -1216,3 +1203,13 @@ _ppp_cleanup (NMPPPManager *manager) priv->pid = 0; } } + + +static void +nm_ppp_manager_dbus_iface_init (NMDBusPPPManagerIface *iface, gpointer iface_data) +{ + iface->handle_need_secrets = handle_ppp_manager_need_secrets; + iface->handle_set_state = handle_ppp_manager_set_state; + iface->handle_set_ip4_config = handle_ppp_manager_set_ip4_config; + iface->handle_set_ip6_config = handle_ppp_manager_set_ip6_config; +} |