diff options
author | Dan Winship <danw@gnome.org> | 2014-10-22 13:48:18 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-11-07 07:49:40 -0500 |
commit | ca18b2d44290c938894dc63f7b03d04a3be271bc (patch) | |
tree | 9fdf5a36bd0de1c788fa810864801f5c4495f2cc | |
parent | d34910b12860eb080b1a519f441946cbc378f769 (diff) | |
download | NetworkManager-ca18b2d44290c938894dc63f7b03d04a3be271bc.tar.gz |
libnm: create NMDhcpConfig as parent of NMDhcp4Config and NMDhcp6Config
As with NMIP4Config and NMIP6Config, merge the two DHCP config classes
into one in the public API.
-rw-r--r-- | clients/cli/common.c | 8 | ||||
-rw-r--r-- | clients/cli/common.h | 4 | ||||
-rw-r--r-- | clients/cli/connections.c | 4 | ||||
-rw-r--r-- | clients/cli/devices.c | 3 | ||||
-rw-r--r-- | docs/libnm/Makefile.am | 2 | ||||
-rw-r--r-- | docs/libnm/libnm-docs.xml | 3 | ||||
-rw-r--r-- | libnm/Makefile.am | 6 | ||||
-rw-r--r-- | libnm/NetworkManager.h | 3 | ||||
-rw-r--r-- | libnm/libnm.ver | 10 | ||||
-rw-r--r-- | libnm/nm-active-connection.c | 32 | ||||
-rw-r--r-- | libnm/nm-active-connection.h | 4 | ||||
-rw-r--r-- | libnm/nm-device.c | 38 | ||||
-rw-r--r-- | libnm/nm-device.h | 4 | ||||
-rw-r--r-- | libnm/nm-dhcp-config.c | 217 | ||||
-rw-r--r-- | libnm/nm-dhcp-config.h | 62 | ||||
-rw-r--r-- | libnm/nm-dhcp4-config.c | 150 | ||||
-rw-r--r-- | libnm/nm-dhcp4-config.h | 23 | ||||
-rw-r--r-- | libnm/nm-dhcp6-config.c | 148 | ||||
-rw-r--r-- | libnm/nm-dhcp6-config.h | 23 | ||||
-rw-r--r-- | libnm/nm-types.h | 3 |
20 files changed, 354 insertions, 393 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c index 5493b166d7..2003934993 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -251,7 +251,7 @@ print_ip6_config (NMIPConfig *cfg6, } gboolean -print_dhcp4_config (NMDhcp4Config *dhcp4, +print_dhcp4_config (NMDhcpConfig *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field) @@ -263,7 +263,7 @@ print_dhcp4_config (NMDhcp4Config *dhcp4, if (dhcp4 == NULL) return FALSE; - table = nm_dhcp4_config_get_options (dhcp4); + table = nm_dhcp_config_get_options (dhcp4); if (table) { GHashTableIter table_iter; gpointer key, value; @@ -299,7 +299,7 @@ print_dhcp4_config (NMDhcp4Config *dhcp4, } gboolean -print_dhcp6_config (NMDhcp6Config *dhcp6, +print_dhcp6_config (NMDhcpConfig *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field) @@ -311,7 +311,7 @@ print_dhcp6_config (NMDhcp6Config *dhcp6, if (dhcp6 == NULL) return FALSE; - table = nm_dhcp6_config_get_options (dhcp6); + table = nm_dhcp_config_get_options (dhcp6); if (table) { GHashTableIter table_iter; gpointer key, value; diff --git a/clients/cli/common.h b/clients/cli/common.h index 2787b1935b..6ae74f4f4a 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -26,8 +26,8 @@ gboolean print_ip4_config (NMIPConfig *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field); gboolean print_ip6_config (NMIPConfig *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field); -gboolean print_dhcp4_config (NMDhcp4Config *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field); -gboolean print_dhcp6_config (NMDhcp6Config *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field); +gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field); +gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field); NMIPAddress *nmc_parse_and_build_address (int family, const char *ip_str, GError **error); NMIPRoute *nmc_parse_and_build_route (int family, const char *first, const char *second, const char *third, GError **error); diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 35e88b4378..3f921a4003 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -1137,7 +1137,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) /* DHCP4 */ if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[2].name) == 0) { gboolean b1 = FALSE; - NMDhcp4Config *dhcp4 = nm_active_connection_get_dhcp4_config (acon); + NMDhcpConfig *dhcp4 = nm_active_connection_get_dhcp4_config (acon); b1 = print_dhcp4_config (dhcp4, nmc, "DHCP4", group_fld); was_output = was_output || b1; @@ -1155,7 +1155,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) /* DHCP6 */ if (strcasecmp (nmc_fields_con_active_details_groups[group_idx].name, nmc_fields_con_active_details_groups[4].name) == 0) { gboolean b1 = FALSE; - NMDhcp6Config *dhcp6 = nm_active_connection_get_dhcp6_config (acon); + NMDhcpConfig *dhcp6 = nm_active_connection_get_dhcp6_config (acon); b1 = print_dhcp6_config (dhcp6, nmc, "DHCP6", group_fld); was_output = was_output || b1; diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 371c05bf13..ae8664e987 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -768,8 +768,7 @@ show_device_info (NMDevice *device, NmCli *nmc) size_t tmpl_len; gboolean was_output = FALSE; NMIPConfig *cfg4, *cfg6; - NMDhcp4Config *dhcp4; - NMDhcp6Config *dhcp6; + NMDhcpConfig *dhcp4, *dhcp6; const char *base_hdr = _("Device details"); GPtrArray *fields_in_section = NULL; diff --git a/docs/libnm/Makefile.am b/docs/libnm/Makefile.am index 0c82e751a9..2d1200b485 100644 --- a/docs/libnm/Makefile.am +++ b/docs/libnm/Makefile.am @@ -34,6 +34,8 @@ IGNORE_HFILES= \ nm-dbus-helpers-private.h \ nm-core-internal.h \ nm-device-private.h \ + nm-dhcp4-config.h \ + nm-dhcp6-config.h \ nm-ip4-config.h \ nm-ip6-config.h \ nm-manager.h \ diff --git a/docs/libnm/libnm-docs.xml b/docs/libnm/libnm-docs.xml index c60b4727e6..e722a30964 100644 --- a/docs/libnm/libnm-docs.xml +++ b/docs/libnm/libnm-docs.xml @@ -129,8 +129,7 @@ <xi:include href="xml/nm-access-point.xml"/> <xi:include href="xml/nm-wimax-nsp.xml"/> <xi:include href="xml/nm-ip-config.xml"/> - <xi:include href="xml/nm-dhcp4-config.xml"/> - <xi:include href="xml/nm-dhcp6-config.xml"/> + <xi:include href="xml/nm-dhcp-config.xml"/> </chapter> <chapter> diff --git a/libnm/Makefile.am b/libnm/Makefile.am index 3656cddfe0..26e0a4c737 100644 --- a/libnm/Makefile.am +++ b/libnm/Makefile.am @@ -43,8 +43,7 @@ libnminclude_hfiles = \ nm-device-wifi.h \ nm-device-wimax.h \ nm-device.h \ - nm-dhcp4-config.h \ - nm-dhcp6-config.h \ + nm-dhcp-config.h \ nm-enum-types.h \ nm-ip-config.h \ nm-object.h \ @@ -65,6 +64,8 @@ libnminclude_HEADERS = \ libnm_la_private_headers = \ nm-dbus-helpers.h \ nm-device-private.h \ + nm-dhcp4-config.h \ + nm-dhcp6-config.h \ nm-ip4-config.h \ nm-ip6-config.h \ nm-manager.h \ @@ -92,6 +93,7 @@ libnm_la_csources = \ nm-device-wifi.c \ nm-device-wimax.c \ nm-device.c \ + nm-dhcp-config.c \ nm-dhcp4-config.c \ nm-dhcp6-config.c \ nm-enum-types.c \ diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h index 7604e77df5..39212fda1d 100644 --- a/libnm/NetworkManager.h +++ b/libnm/NetworkManager.h @@ -43,8 +43,7 @@ #include <nm-device-wifi.h> #include <nm-device-wimax.h> #include <nm-device.h> -#include <nm-dhcp4-config.h> -#include <nm-dhcp6-config.h> +#include <nm-dhcp-config.h> #include <nm-enum-types.h> #include <nm-ip-config.h> #include <nm-object.h> diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 50ee710961..e4e347aaab 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -262,12 +262,10 @@ global: nm_device_wimax_get_rssi; nm_device_wimax_get_tx_power; nm_device_wimax_get_type; - nm_dhcp4_config_get_one_option; - nm_dhcp4_config_get_options; - nm_dhcp4_config_get_type; - nm_dhcp6_config_get_one_option; - nm_dhcp6_config_get_options; - nm_dhcp6_config_get_type; + nm_dhcp_config_get_family; + nm_dhcp_config_get_one_option; + nm_dhcp_config_get_options; + nm_dhcp_config_get_type; nm_ip_address_equal; nm_ip_address_get_address; nm_ip_address_get_address_binary; diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c index 3551afeb94..6988f44c67 100644 --- a/libnm/nm-active-connection.c +++ b/libnm/nm-active-connection.c @@ -58,10 +58,10 @@ typedef struct { NMActiveConnectionState state; gboolean is_default; NMIPConfig *ip4_config; - NMDhcp4Config *dhcp4_config; + NMDhcpConfig *dhcp4_config; gboolean is_default6; NMIPConfig *ip6_config; - NMDhcp6Config *dhcp6_config; + NMDhcpConfig *dhcp6_config; gboolean is_vpn; NMDevice *master; } NMActiveConnectionPrivate; @@ -259,14 +259,14 @@ nm_active_connection_get_ip4_config (NMActiveConnection *connection) * nm_active_connection_get_dhcp4_config: * @connection: an #NMActiveConnection * - * Gets the current #NMDhcp4Config (if any) associated with the + * Gets the current IPv4 #NMDhcpConfig (if any) associated with the * #NMActiveConnection. * - * Returns: (transfer none): the #NMDhcp4Config, or %NULL if the - * connection does not use DHCP, or is not in the - * %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state. + * Returns: (transfer none): the IPv4 #NMDhcpConfig, or %NULL if the connection + * does not use DHCP, or is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED + * state. **/ -NMDhcp4Config * +NMDhcpConfig * nm_active_connection_get_dhcp4_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); @@ -312,14 +312,14 @@ nm_active_connection_get_ip6_config (NMActiveConnection *connection) * nm_active_connection_get_dhcp6_config: * @connection: an #NMActiveConnection * - * Gets the current #NMDhcp6Config (if any) associated with the + * Gets the current IPv6 #NMDhcpConfig (if any) associated with the * #NMActiveConnection. * - * Returns: (transfer none): the #NMDhcp6Config, or %NULL if the - * connection does not use DHCPv6, or is not in the - * %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state. + * Returns: (transfer none): the IPv6 #NMDhcpConfig, or %NULL if the connection + * does not use DHCPv6, or is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED + * state. **/ -NMDhcp6Config * +NMDhcpConfig * nm_active_connection_get_dhcp6_config (NMActiveConnection *connection) { g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); @@ -641,12 +641,12 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) /** * NMActiveConnection:dhcp4-config: * - * The #NMDhcp4Config of the connection. + * The IPv4 #NMDhcpConfig of the connection. **/ g_object_class_install_property (object_class, PROP_DHCP4_CONFIG, g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", - NM_TYPE_DHCP4_CONFIG, + NM_TYPE_DHCP_CONFIG, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -677,12 +677,12 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) /** * NMActiveConnection:dhcp6-config: * - * The #NMDhcp6Config of the connection. + * The IPv6 #NMDhcpConfig of the connection. **/ g_object_class_install_property (object_class, PROP_DHCP6_CONFIG, g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", - NM_TYPE_DHCP6_CONFIG, + NM_TYPE_DHCP_CONFIG, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); diff --git a/libnm/nm-active-connection.h b/libnm/nm-active-connection.h index b6b31d9c0a..4bc8414828 100644 --- a/libnm/nm-active-connection.h +++ b/libnm/nm-active-connection.h @@ -76,10 +76,10 @@ NMActiveConnectionState nm_active_connection_get_state (NMActive NMDevice *nm_active_connection_get_master (NMActiveConnection *connection); gboolean nm_active_connection_get_default (NMActiveConnection *connection); NMIPConfig *nm_active_connection_get_ip4_config (NMActiveConnection *connection); -NMDhcp4Config *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection); +NMDhcpConfig *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection); gboolean nm_active_connection_get_default6 (NMActiveConnection *connection); NMIPConfig *nm_active_connection_get_ip6_config (NMActiveConnection *connection); -NMDhcp6Config *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection); +NMDhcpConfig *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection); gboolean nm_active_connection_get_vpn (NMActiveConnection *connection); G_END_DECLS diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 16f88d9308..29f5db8d33 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -84,9 +84,9 @@ typedef struct { gboolean firmware_missing; gboolean autoconnect; NMIPConfig *ip4_config; - NMDhcp4Config *dhcp4_config; + NMDhcpConfig *dhcp4_config; NMIPConfig *ip6_config; - NMDhcp6Config *dhcp6_config; + NMDhcpConfig *dhcp6_config; NMDeviceState state; NMDeviceState last_seen_state; NMDeviceStateReason reason; @@ -658,12 +658,12 @@ nm_device_class_init (NMDeviceClass *device_class) /** * NMDevice:dhcp4-config: * - * The #NMDhcp4Config of the device. + * The IPv4 #NMDhcpConfig of the device. **/ g_object_class_install_property (object_class, PROP_DHCP4_CONFIG, g_param_spec_object (NM_DEVICE_DHCP4_CONFIG, "", "", - NM_TYPE_DHCP4_CONFIG, + NM_TYPE_DHCP_CONFIG, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -682,12 +682,12 @@ nm_device_class_init (NMDeviceClass *device_class) /** * NMDevice:dhcp6-config: * - * The #NMDhcp6Config of the device. + * The IPv6 #NMDhcpConfig of the device. **/ g_object_class_install_property (object_class, PROP_DHCP6_CONFIG, g_param_spec_object (NM_DEVICE_DHCP6_CONFIG, "", "", - NM_TYPE_DHCP6_CONFIG, + NM_TYPE_DHCP_CONFIG, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -1126,16 +1126,15 @@ nm_device_get_ip4_config (NMDevice *device) * nm_device_get_dhcp4_config: * @device: a #NMDevice * - * Gets the current #NMDhcp4Config associated with the #NMDevice. + * Gets the current IPv4 #NMDhcpConfig associated with the #NMDevice. * - * Note that as of NetworkManager 0.9.10, you can alternatively use - * nm_active_connection_get_dhcp4_config(), which also works with VPN - * connections. + * You can alternatively use nm_active_connection_get_dhcp4_config(), which also + * works with VPN connections. * - * Returns: (transfer none): the #NMDhcp4Config or %NULL if the device is not activated or not - * using DHCP. + * Returns: (transfer none): the IPv4 #NMDhcpConfig, or %NULL if the device is + * not activated or not using DHCP. **/ -NMDhcp4Config * +NMDhcpConfig * nm_device_get_dhcp4_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); @@ -1166,16 +1165,15 @@ nm_device_get_ip6_config (NMDevice *device) * nm_device_get_dhcp6_config: * @device: a #NMDevice * - * Gets the current #NMDhcp6Config associated with the #NMDevice. + * Gets the current IPv6 #NMDhcpConfig associated with the #NMDevice. * - * Note that as of NetworkManager 0.9.10, you can alternatively use - * nm_active_connection_get_dhcp6_config(), which also works with VPN - * connections. + * You can alternatively use nm_active_connection_get_dhcp6_config(), which also + * works with VPN connections. * - * Returns: (transfer none): the #NMDhcp6Config or %NULL if the device is not activated or not - * using DHCP. + * Returns: (transfer none): the IPv6 #NMDhcpConfig, or %NULL if the device is + * not activated or not using DHCPv6. **/ -NMDhcp6Config * +NMDhcpConfig * nm_device_get_dhcp6_config (NMDevice *device) { g_return_val_if_fail (NM_IS_DEVICE (device), NULL); diff --git a/libnm/nm-device.h b/libnm/nm-device.h index 2b103e5486..5cc3735695 100644 --- a/libnm/nm-device.h +++ b/libnm/nm-device.h @@ -105,9 +105,9 @@ gboolean nm_device_get_autoconnect (NMDevice *device); void nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect); gboolean nm_device_get_firmware_missing (NMDevice *device); NMIPConfig * nm_device_get_ip4_config (NMDevice *device); -NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *device); +NMDhcpConfig * nm_device_get_dhcp4_config (NMDevice *device); NMIPConfig * nm_device_get_ip6_config (NMDevice *device); -NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *device); +NMDhcpConfig * nm_device_get_dhcp6_config (NMDevice *device); NMDeviceState nm_device_get_state (NMDevice *device); NMDeviceStateReason nm_device_get_state_reason (NMDevice *device); NMActiveConnection * nm_device_get_active_connection(NMDevice *device); diff --git a/libnm/nm-dhcp-config.c b/libnm/nm-dhcp-config.c new file mode 100644 index 0000000000..5b72fbc10f --- /dev/null +++ b/libnm/nm-dhcp-config.c @@ -0,0 +1,217 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2008 - 2014 Red Hat, Inc. + * Copyright 2008 Novell, Inc. + */ + +#include <string.h> + +#include "nm-dhcp-config.h" +#include "nm-dhcp4-config.h" +#include "nm-dhcp6-config.h" +#include "nm-dbus-interface.h" +#include "nm-object-private.h" +#include "nm-utils.h" + +G_DEFINE_ABSTRACT_TYPE (NMDhcpConfig, nm_dhcp_config, NM_TYPE_OBJECT) + +#define NM_DHCP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP_CONFIG, NMDhcpConfigPrivate)) + +typedef struct { + GHashTable *options; +} NMDhcpConfigPrivate; + +enum { + PROP_0, + PROP_FAMILY, + PROP_OPTIONS, + + LAST_PROP +}; + +static void +nm_dhcp_config_init (NMDhcpConfig *config) +{ + NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (config); + + priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); +} + +static gboolean +demarshal_dhcp_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) +{ + NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object); + GVariantIter iter; + const char *key; + GVariant *opt; + + g_hash_table_remove_all (priv->options); + + 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_DHCP_CONFIG_OPTIONS); + return TRUE; +} + +static void +init_dbus (NMObject *object) +{ + NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object); + const NMPropertiesInfo property_info[] = { + { NM_DHCP_CONFIG_OPTIONS, &priv->options, demarshal_dhcp_options }, + { NULL }, + }; + + NM_OBJECT_CLASS (nm_dhcp_config_parent_class)->init_dbus (object); + + _nm_object_register_properties (object, + (NM_IS_DHCP4_CONFIG (object) ? + NM_DBUS_INTERFACE_DHCP4_CONFIG : + NM_DBUS_INTERFACE_DHCP6_CONFIG), + property_info); +} + +static void +finalize (GObject *object) +{ + NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object); + + if (priv->options) + g_hash_table_destroy (priv->options); + + G_OBJECT_CLASS (nm_dhcp_config_parent_class)->finalize (object); +} + +static void +get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + NMDhcpConfig *self = NM_DHCP_CONFIG (object); + + switch (prop_id) { + case PROP_FAMILY: + g_value_set_int (value, nm_dhcp_config_get_family (self)); + case PROP_OPTIONS: + g_value_set_boxed (value, nm_dhcp_config_get_options (self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_dhcp_config_class_init (NMDhcpConfigClass *config_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (config_class); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); + + g_type_class_add_private (config_class, sizeof (NMDhcpConfigPrivate)); + + /* virtual methods */ + object_class->get_property = get_property; + object_class->finalize = finalize; + + nm_object_class->init_dbus = init_dbus; + + /* properties */ + + /** + * NMDhcpConfig:family: + * + * The IP address family of the configuration; either %AF_INET or %AF_INET6. + **/ + g_object_class_install_property + (object_class, PROP_FAMILY, + g_param_spec_int (NM_DHCP_CONFIG_FAMILY, "", "", + 0, 255, AF_UNSPEC, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + /** + * NMDhcpConfig:options: + * + * The #GHashTable containing options of the configuration. + * + * Type: GLib.HashTable(utf8,utf8) + **/ + g_object_class_install_property + (object_class, PROP_OPTIONS, + g_param_spec_boxed (NM_DHCP_CONFIG_OPTIONS, "", "", + G_TYPE_HASH_TABLE, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); +} + +/** + * nm_dhcp_config_get_family: + * @config: a #NMDhcpConfig + * + * Gets the IP address family of the configuration + * + * Returns: the IP address family; either %AF_INET or %AF_INET6 + **/ +int +nm_dhcp_config_get_family (NMDhcpConfig *config) +{ + g_return_val_if_fail (NM_IS_DHCP_CONFIG (config), AF_UNSPEC); + + return NM_IS_DHCP4_CONFIG (config) ? AF_INET : AF_INET6; +} + +/** + * nm_dhcp_config_get_options: + * @config: a #NMDhcpConfig + * + * Gets all the options contained in the configuration. + * + * Returns: (transfer none) (element-type utf8 utf8): the #GHashTable containing + * strings for keys and values. This is the internal copy used by the + * configuration, and must not be modified. + **/ +GHashTable * +nm_dhcp_config_get_options (NMDhcpConfig *config) +{ + g_return_val_if_fail (NM_IS_DHCP_CONFIG (config), NULL); + + return NM_DHCP_CONFIG_GET_PRIVATE (config)->options; +} + +/** + * nm_dhcp_config_get_one_option: + * @config: a #NMDhcpConfig + * @option: the option to retrieve + * + * Gets one option by option name. + * + * Returns: the configuration option's value. This is the internal string used by the + * configuration, and must not be modified. + **/ +const char * +nm_dhcp_config_get_one_option (NMDhcpConfig *config, const char *option) +{ + g_return_val_if_fail (NM_IS_DHCP_CONFIG (config), NULL); + + return g_hash_table_lookup (nm_dhcp_config_get_options (config), option); +} diff --git a/libnm/nm-dhcp-config.h b/libnm/nm-dhcp-config.h new file mode 100644 index 0000000000..85aa3bd2c1 --- /dev/null +++ b/libnm/nm-dhcp-config.h @@ -0,0 +1,62 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2008 Red Hat, Inc. + * Copyright 2008 Novell, Inc. + */ + +#ifndef __NM_DHCP_CONFIG_H__ +#define __NM_DHCP_CONFIG_H__ + +#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION) +#error "Only <NetworkManager.h> can be included directly." +#endif + +#include <nm-object.h> + +G_BEGIN_DECLS + +#define NM_TYPE_DHCP_CONFIG (nm_dhcp_config_get_type ()) +#define NM_DHCP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_CONFIG, NMDhcpConfig)) +#define NM_DHCP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP_CONFIG, NMDhcpConfigClass)) +#define NM_IS_DHCP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP_CONFIG)) +#define NM_IS_DHCP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_CONFIG)) + +struct _NMDhcpConfig { + NMObject parent; +}; + +typedef struct { + NMObjectClass parent; + + /*< private >*/ + gpointer padding[8]; +} NMDhcpConfigClass; + +#define NM_DHCP_CONFIG_FAMILY "family" +#define NM_DHCP_CONFIG_OPTIONS "options" + +GType nm_dhcp_config_get_type (void); + +int nm_dhcp_config_get_family (NMDhcpConfig *config); + +GHashTable *nm_dhcp_config_get_options (NMDhcpConfig *config); +const char *nm_dhcp_config_get_one_option (NMDhcpConfig *config, const char *option); + +G_END_DECLS + +#endif /* __NM_DHCP_CONFIG_H__ */ diff --git a/libnm/nm-dhcp4-config.c b/libnm/nm-dhcp4-config.c index 2bf84fa408..6bbd8d6b54 100644 --- a/libnm/nm-dhcp4-config.c +++ b/libnm/nm-dhcp4-config.c @@ -15,169 +15,23 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright 2008 - 2011 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright 2014 Red Hat, Inc. */ -#include <string.h> - #include "nm-dhcp4-config.h" -#include "nm-dbus-interface.h" #include "nm-object-private.h" -#include "nm-utils.h" - -G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_OBJECT) - -#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate)) -typedef struct { - GHashTable *options; -} NMDhcp4ConfigPrivate; - -enum { - PROP_0, - PROP_OPTIONS, - - LAST_PROP -}; +G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_DHCP_CONFIG) static void nm_dhcp4_config_init (NMDhcp4Config *config) { - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (config); - - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); -} - -static gboolean -demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - GVariantIter iter; - const char *key; - GVariant *opt; - - g_hash_table_remove_all (priv->options); - - 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); - return TRUE; -} - -static void -init_dbus (NMObject *object) -{ - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DHCP4_CONFIG_OPTIONS, &priv->options, demarshal_dhcp4_options }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_dhcp4_config_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DHCP4_CONFIG, - property_info); -} - -static void -finalize (GObject *object) -{ - NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - - if (priv->options) - g_hash_table_destroy (priv->options); - - G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object); -} - -static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - NMDhcp4Config *self = NM_DHCP4_CONFIG (object); - - switch (prop_id) { - case PROP_OPTIONS: - g_value_set_boxed (value, nm_dhcp4_config_get_options (self)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } } static void nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class) { - GObjectClass *object_class = G_OBJECT_CLASS (config_class); NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); - g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DHCP4_CONFIG); - - /* virtual methods */ - object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ - - /** - * NMDhcp4Config:options: - * - * The #GHashTable containing options of the configuration. - * - * Type: GLib.HashTable(utf8,utf8) - **/ - g_object_class_install_property - (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "", - G_TYPE_HASH_TABLE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); -} - -/** - * nm_dhcp4_config_get_options: - * @config: a #NMDhcp4Config - * - * Gets all the options contained in the configuration. - * - * Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values. - * This is the internal copy used by the configuration, and must not be modified. - **/ -GHashTable * -nm_dhcp4_config_get_options (NMDhcp4Config *config) -{ - g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL); - - return NM_DHCP4_CONFIG_GET_PRIVATE (config)->options; -} - -/** - * nm_dhcp4_config_get_one_option: - * @config: a #NMDhcp4Config - * @option: the option to retrieve - * - * Gets one option by option name. - * - * Returns: the configuration option's value. This is the internal string used by the - * configuration, and must not be modified. - **/ -const char * -nm_dhcp4_config_get_one_option (NMDhcp4Config *config, const char *option) -{ - g_return_val_if_fail (NM_IS_DHCP4_CONFIG (config), NULL); - - return g_hash_table_lookup (nm_dhcp4_config_get_options (config), option); } diff --git a/libnm/nm-dhcp4-config.h b/libnm/nm-dhcp4-config.h index 90152c8f63..3423740db8 100644 --- a/libnm/nm-dhcp4-config.h +++ b/libnm/nm-dhcp4-config.h @@ -15,18 +15,13 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright 2008 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright 2014 Red Hat, Inc. */ #ifndef __NM_DHCP4_CONFIG_H__ #define __NM_DHCP4_CONFIG_H__ -#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION) -#error "Only <NetworkManager.h> can be included directly." -#endif - -#include <nm-object.h> +#include <nm-dhcp-config.h> G_BEGIN_DECLS @@ -36,25 +31,19 @@ G_BEGIN_DECLS #define NM_IS_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP4_CONFIG)) #define NM_IS_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP4_CONFIG)) -struct _NMDhcp4Config { - NMObject parent; -}; +typedef struct { + NMDhcpConfig parent; +} NMDhcp4Config; typedef struct { - NMObjectClass parent; + NMDhcpConfigClass parent; /*< private >*/ gpointer padding[4]; } NMDhcp4ConfigClass; -#define NM_DHCP4_CONFIG_OPTIONS "options" - GType nm_dhcp4_config_get_type (void); -GHashTable * nm_dhcp4_config_get_options (NMDhcp4Config *config); - -const char * nm_dhcp4_config_get_one_option (NMDhcp4Config *config, const char *option); - G_END_DECLS #endif /* __NM_DHCP4_CONFIG_H__ */ diff --git a/libnm/nm-dhcp6-config.c b/libnm/nm-dhcp6-config.c index 498f1d3b4c..c332dcaa8a 100644 --- a/libnm/nm-dhcp6-config.c +++ b/libnm/nm-dhcp6-config.c @@ -15,169 +15,23 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright 2008 - 2011 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright 2014 Red Hat, Inc. */ -#include <string.h> - #include "nm-dhcp6-config.h" -#include "nm-dbus-interface.h" #include "nm-object-private.h" -#include "nm-utils.h" G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_OBJECT) -#define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate)) - -typedef struct { - GHashTable *options; -} NMDhcp6ConfigPrivate; - -enum { - PROP_0, - PROP_OPTIONS, - - LAST_PROP -}; - static void nm_dhcp6_config_init (NMDhcp6Config *config) { - NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (config); - - priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); -} - -static gboolean -demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) -{ - NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); - GVariantIter iter; - const char *key; - GVariant *opt; - - g_hash_table_remove_all (priv->options); - - 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); - return TRUE; -} - -static void -init_dbus (NMObject *object) -{ - NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); - const NMPropertiesInfo property_info[] = { - { NM_DHCP6_CONFIG_OPTIONS, &priv->options, demarshal_dhcp6_options }, - { NULL }, - }; - - NM_OBJECT_CLASS (nm_dhcp6_config_parent_class)->init_dbus (object); - - _nm_object_register_properties (object, - NM_DBUS_INTERFACE_DHCP6_CONFIG, - property_info); -} - -static void -finalize (GObject *object) -{ - NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); - - if (priv->options) - g_hash_table_destroy (priv->options); - - G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->finalize (object); -} - -static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - NMDhcp6Config *self = NM_DHCP6_CONFIG (object); - - switch (prop_id) { - case PROP_OPTIONS: - g_value_set_boxed (value, nm_dhcp6_config_get_options (self)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } } static void nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class) { - GObjectClass *object_class = G_OBJECT_CLASS (config_class); NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class); - g_type_class_add_private (config_class, sizeof (NMDhcp6ConfigPrivate)); - _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DHCP6_CONFIG); - - /* virtual methods */ - object_class->get_property = get_property; - object_class->finalize = finalize; - - nm_object_class->init_dbus = init_dbus; - - /* properties */ - - /** - * NMDhcp6Config:options: - * - * The #GHashTable containing options of the configuration. - * - * Type: GLib.HashTable(utf8,utf8) - **/ - g_object_class_install_property - (object_class, PROP_OPTIONS, - g_param_spec_boxed (NM_DHCP6_CONFIG_OPTIONS, "", "", - G_TYPE_HASH_TABLE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); -} - -/** - * nm_dhcp6_config_get_options: - * @config: a #NMDhcp6Config - * - * Gets all the options contained in the configuration. - * - * Returns: (transfer none) (element-type utf8 GObject.Value): the #GHashTable containing strings for keys and values. - * This is the internal copy used by the configuration, and must not be modified. - **/ -GHashTable * -nm_dhcp6_config_get_options (NMDhcp6Config *config) -{ - g_return_val_if_fail (NM_IS_DHCP6_CONFIG (config), NULL); - - return NM_DHCP6_CONFIG_GET_PRIVATE (config)->options; -} - -/** - * nm_dhcp6_config_get_one_option: - * @config: a #NMDhcp6Config - * @option: the option to retrieve - * - * Gets one option by option name. - * - * Returns: the configuration option's value. This is the internal string used by the - * configuration, and must not be modified. - **/ -const char * -nm_dhcp6_config_get_one_option (NMDhcp6Config *config, const char *option) -{ - g_return_val_if_fail (NM_IS_DHCP6_CONFIG (config), NULL); - - return g_hash_table_lookup (nm_dhcp6_config_get_options (config), option); } diff --git a/libnm/nm-dhcp6-config.h b/libnm/nm-dhcp6-config.h index 53bd45eeb7..abb24adfd6 100644 --- a/libnm/nm-dhcp6-config.h +++ b/libnm/nm-dhcp6-config.h @@ -15,18 +15,13 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright 2008 - 2010 Red Hat, Inc. - * Copyright 2008 Novell, Inc. + * Copyright 2014 Red Hat, Inc. */ #ifndef __NM_DHCP6_CONFIG_H__ #define __NM_DHCP6_CONFIG_H__ -#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION) -#error "Only <NetworkManager.h> can be included directly." -#endif - -#include <nm-object.h> +#include <nm-dhcp-config.h> G_BEGIN_DECLS @@ -36,25 +31,19 @@ G_BEGIN_DECLS #define NM_IS_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP6_CONFIG)) #define NM_IS_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP6_CONFIG)) -struct _NMDhcp6Config { - NMObject parent; -}; +typedef struct { + NMDhcpConfig parent; +} NMDhcp6Config; typedef struct { - NMObjectClass parent; + NMDhcpConfigClass parent; /*< private >*/ gpointer padding[4]; } NMDhcp6ConfigClass; -#define NM_DHCP6_CONFIG_OPTIONS "options" - GType nm_dhcp6_config_get_type (void); -GHashTable * nm_dhcp6_config_get_options (NMDhcp6Config *config); - -const char * nm_dhcp6_config_get_one_option (NMDhcp6Config *config, const char *option); - G_END_DECLS #endif /* __NM_DHCP6_CONFIG_H__ */ diff --git a/libnm/nm-types.h b/libnm/nm-types.h index eb922036d0..3602878a6a 100644 --- a/libnm/nm-types.h +++ b/libnm/nm-types.h @@ -43,8 +43,7 @@ typedef struct _NMDeviceTeam NMDeviceTeam; typedef struct _NMDeviceVlan NMDeviceVlan; typedef struct _NMDeviceWifi NMDeviceWifi; typedef struct _NMDeviceWimax NMDeviceWimax; -typedef struct _NMDhcp4Config NMDhcp4Config; -typedef struct _NMDhcp6Config NMDhcp6Config; +typedef struct _NMDhcpConfig NMDhcpConfig; typedef struct _NMIPConfig NMIPConfig; typedef struct _NMObject NMObject; typedef struct _NMRemoteConnection NMRemoteConnection; |