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
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2014-11-13 10:07:02 -05:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
#include "nm-dhcp4-config.h"
|
|
|
|
|
|
2008-07-17 17:04:13 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2014-07-05 16:23:30 -04:00
|
|
|
#include "nm-dbus-interface.h"
|
2008-07-17 17:04:13 +00:00
|
|
|
#include "nm-utils.h"
|
2016-09-29 13:49:01 +02:00
|
|
|
#include "nm-exported-object.h"
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2016-11-23 13:14:08 +01:00
|
|
|
#include "introspection/org.freedesktop.NetworkManager.DHCP4Config.h"
|
2015-04-15 14:53:30 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE (NMDhcp4Config,
|
|
|
|
|
PROP_OPTIONS,
|
|
|
|
|
);
|
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
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDhcp4Config {
|
|
|
|
|
NMExportedObject parent;
|
|
|
|
|
NMDhcp4ConfigPrivate _priv;
|
|
|
|
|
};
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDhcp4ConfigClass {
|
|
|
|
|
NMExportedObjectClass parent;
|
2008-07-17 17:04:13 +00:00
|
|
|
};
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT)
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
#define NM_DHCP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDhcp4Config, NM_IS_DHCP4_CONFIG)
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2008-07-17 17:04:13 +00:00
|
|
|
|
|
|
|
|
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);
|
2016-09-29 13:49:01 +02:00
|
|
|
_notify (self, PROP_OPTIONS);
|
2008-07-17 17:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE ((NMDhcp4Config *) object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_OPTIONS:
|
|
|
|
|
g_value_set_variant (value, priv->options);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDhcp4Config *
|
|
|
|
|
nm_dhcp4_config_new (void)
|
|
|
|
|
{
|
|
|
|
|
return NM_DHCP4_CONFIG (g_object_new (NM_TYPE_DHCP4_CONFIG, NULL));
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-17 17:04:13 +00:00
|
|
|
static void
|
|
|
|
|
finalize (GObject *object)
|
|
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE ((NMDhcp4Config *) 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
|
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
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->finalize = finalize;
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2017-01-03 15:27:23 +01:00
|
|
|
exported_object_class->export_path = NM_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP4Config");
|
2015-11-04 14:44:29 +01:00
|
|
|
exported_object_class->export_on_construction = TRUE;
|
2015-04-03 10:08:52 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
obj_properties[PROP_OPTIONS] =
|
|
|
|
|
g_param_spec_variant (NM_DHCP4_CONFIG_OPTIONS, "", "",
|
|
|
|
|
G_VARIANT_TYPE ("a{sv}"),
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2008-07-17 17:04:13 +00:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
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),
|
2015-04-15 14:53:30 -04:00
|
|
|
NMDBUS_TYPE_DHCP4_CONFIG_SKELETON,
|
|
|
|
|
NULL);
|
2008-07-17 17:04:13 +00:00
|
|
|
}
|