2008-07-17 17:04:13 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
2008-11-03 04:13:42 +00:00
|
|
|
* Copyright (C) 2008 Red Hat, Inc.
|
2008-07-17 17:04:13 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-11-13 10:07:02 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2008-07-17 17:04:13 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2015-04-06 16:42:31 -04:00
|
|
|
#include "nm-glib.h"
|
2014-07-05 16:23:30 -04:00
|
|
|
#include "nm-dbus-interface.h"
|
2008-07-17 17:04:13 +00:00
|
|
|
#include "nm-dhcp4-config.h"
|
|
|
|
|
#include "nm-dhcp4-config-glue.h"
|
|
|
|
|
#include "nm-dbus-glib-types.h"
|
|
|
|
|
#include "nm-utils.h"
|
|
|
|
|
|
2015-04-13 13:31:42 -04:00
|
|
|
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT)
|
2008-07-17 17:04:13 +00:00
|
|
|
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate))
|
2008-07-17 17:04:13 +00:00
|
|
|
|
|
|
|
|
typedef struct {
|
2015-04-07 13:20:20 -04:00
|
|
|
GVariant *options;
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
} NMDhcp4ConfigPrivate;
|
2008-07-17 17:04:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_OPTIONS,
|
|
|
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
NMDhcp4Config *
|
2008-07-17 17:04:13 +00:00
|
|
|
nm_dhcp4_config_new (void)
|
|
|
|
|
{
|
|
|
|
|
return NM_DHCP4_CONFIG (g_object_new (NM_TYPE_DHCP4_CONFIG, NULL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-04-07 13:20:20 -04:00
|
|
|
nm_dhcp4_config_set_options (NMDhcp4Config *self,
|
|
|
|
|
GHashTable *options)
|
2008-07-17 17:04:13 +00:00
|
|
|
{
|
2015-04-07 13:20:20 -04:00
|
|
|
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
const char *key, *value;
|
|
|
|
|
GVariantBuilder builder;
|
2008-07-17 17:04:13 +00:00
|
|
|
|
|
|
|
|
g_return_if_fail (NM_IS_DHCP4_CONFIG (self));
|
2015-04-07 13:20:20 -04:00
|
|
|
g_return_if_fail (options != NULL);
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
g_variant_unref (priv->options);
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
|
|
|
|
|
g_hash_table_iter_init (&iter, options);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
|
|
|
|
|
g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value));
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
priv->options = g_variant_builder_end (&builder);
|
|
|
|
|
g_variant_ref_sink (priv->options);
|
2008-07-17 17:04:13 +00:00
|
|
|
g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
nm_dhcp4_config_get_option (NMDhcp4Config *self, const char *key)
|
2008-07-17 17:04:13 +00:00
|
|
|
{
|
2015-04-07 13:20:20 -04:00
|
|
|
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
|
|
|
|
|
const char *value;
|
2008-07-17 17:04:13 +00:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
|
|
|
|
|
g_return_val_if_fail (key != NULL, NULL);
|
|
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
if (g_variant_lookup (priv->options, key, "&s", &value))
|
|
|
|
|
return value;
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
2008-07-17 17:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
GVariant *
|
|
|
|
|
nm_dhcp4_config_get_options (NMDhcp4Config *self)
|
2011-05-11 16:01:12 -05:00
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
|
|
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
return g_variant_ref (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options);
|
2008-07-17 17:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
nm_dhcp4_config_init (NMDhcp4Config *self)
|
2008-07-17 17:04:13 +00:00
|
|
|
{
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-03 10:08:52 -04:00
|
|
|
nm_exported_object_export (NM_EXPORTED_OBJECT (self));
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
priv->options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
|
|
|
|
|
g_variant_ref_sink (priv->options);
|
2008-07-17 17:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
finalize (GObject *object)
|
|
|
|
|
{
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-07 13:20:20 -04:00
|
|
|
g_variant_unref (priv->options);
|
2009-02-25 13:50:34 -05:00
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object);
|
2008-07-17 17:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
|
2008-07-17 17:04:13 +00:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_OPTIONS:
|
2015-04-07 13:20:20 -04:00
|
|
|
/* dbus_g_value_parse_g_variant() will call g_value_init(), but
|
|
|
|
|
* @value is already inited.
|
|
|
|
|
*/
|
|
|
|
|
g_value_unset (value);
|
|
|
|
|
dbus_g_value_parse_g_variant (priv->options, value);
|
2008-07-17 17:04:13 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class)
|
2008-07-17 17:04:13 +00:00
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
|
2015-04-03 10:08:52 -04:00
|
|
|
NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class);
|
2008-07-17 17:04:13 +00:00
|
|
|
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate));
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-03 10:08:52 -04:00
|
|
|
exported_object_class->export_path = NM_DBUS_PATH "/DHCP4Config/%u";
|
|
|
|
|
|
2008-07-17 17:04:13 +00:00
|
|
|
/* virtual methods */
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->finalize = finalize;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_OPTIONS,
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_boxed (NM_DHCP4_CONFIG_OPTIONS, "", "",
|
2008-07-17 17:04:13 +00:00
|
|
|
DBUS_TYPE_G_MAP_OF_VARIANT,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2015-04-13 13:31:42 -04:00
|
|
|
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
|
2013-05-07 12:18:41 -04:00
|
|
|
&dbus_glib_nm_dhcp4_config_object_info);
|
2008-07-17 17:04:13 +00:00
|
|
|
}
|