1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Copyright 2011 - 2013 Red Hat, Inc.
22 #include "nm-default.h"
26 #include "nm-setting-adsl.h"
27 #include "nm-setting-ppp.h"
28 #include "nm-setting-private.h"
30 #include "nm-core-enum-types.h"
33 * SECTION:nm-setting-adsl
34 * @short_description: Describes ADSL-based properties
36 * The #NMSettingAdsl object is a #NMSetting subclass that describes
37 * properties of ADSL connections.
40 G_DEFINE_TYPE_WITH_CODE (NMSettingAdsl, nm_setting_adsl, NM_TYPE_SETTING,
41 _nm_register_setting (ADSL, 1))
42 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_ADSL)
44 #define NM_SETTING_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_ADSL, NMSettingAdslPrivate))
49 NMSettingSecretFlags password_flags;
54 } NMSettingAdslPrivate;
70 * nm_setting_adsl_new:
72 * Creates a new #NMSettingAdsl object with default values.
74 * Returns: the new empty #NMSettingAdsl object
77 nm_setting_adsl_new (void)
79 return (NMSetting *) g_object_new (NM_TYPE_SETTING_ADSL, NULL);
83 * nm_setting_adsl_get_username:
84 * @setting: the #NMSettingAdsl
86 * Returns: the #NMSettingAdsl:username property of the setting
89 nm_setting_adsl_get_username (NMSettingAdsl *setting)
91 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
93 return NM_SETTING_ADSL_GET_PRIVATE (setting)->username;
97 * nm_setting_adsl_get_password:
98 * @setting: the #NMSettingAdsl
100 * Returns: the #NMSettingAdsl:password property of the setting
103 nm_setting_adsl_get_password (NMSettingAdsl *setting)
105 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
107 return NM_SETTING_ADSL_GET_PRIVATE (setting)->password;
111 * nm_setting_adsl_get_password_flags:
112 * @setting: the #NMSettingAdsl
114 * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingAdsl:password
117 nm_setting_adsl_get_password_flags (NMSettingAdsl *setting)
119 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NM_SETTING_SECRET_FLAG_NONE);
121 return NM_SETTING_ADSL_GET_PRIVATE (setting)->password_flags;
125 * nm_setting_adsl_get_protocol:
126 * @setting: the #NMSettingAdsl
128 * Returns: the #NMSettingAdsl:protocol property of the setting
131 nm_setting_adsl_get_protocol (NMSettingAdsl *setting)
133 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
135 return NM_SETTING_ADSL_GET_PRIVATE (setting)->protocol;
139 * nm_setting_adsl_get_encapsulation:
140 * @setting: the #NMSettingAdsl
142 * Returns: the #NMSettingAdsl:encapsulation property of the setting
145 nm_setting_adsl_get_encapsulation (NMSettingAdsl *setting)
147 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
149 return NM_SETTING_ADSL_GET_PRIVATE (setting)->encapsulation;
153 * nm_setting_adsl_get_vpi:
154 * @setting: the #NMSettingAdsl
156 * Returns: the #NMSettingAdsl:vpi property of the setting
159 nm_setting_adsl_get_vpi (NMSettingAdsl *setting)
161 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), 0);
163 return NM_SETTING_ADSL_GET_PRIVATE (setting)->vpi;
167 * nm_setting_adsl_get_vci:
168 * @setting: the #NMSettingAdsl
170 * Returns: the #NMSettingAdsl:vci property of the setting
173 nm_setting_adsl_get_vci (NMSettingAdsl *setting)
175 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), 0);
177 return NM_SETTING_ADSL_GET_PRIVATE (setting)->vci;
181 verify (NMSetting *setting, NMConnection *connection, GError **error)
183 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (setting);
185 if (!priv->username) {
186 g_set_error_literal (error,
188 NM_CONNECTION_ERROR_MISSING_PROPERTY,
189 _("property is missing"));
190 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_USERNAME);
192 } else if (!strlen (priv->username)) {
193 g_set_error_literal (error,
195 NM_CONNECTION_ERROR_INVALID_PROPERTY,
196 _("property is empty"));
197 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_USERNAME);
202 || ( strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA)
203 && strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)
204 && strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_IPOATM))){
207 NM_CONNECTION_ERROR_INVALID_PROPERTY,
208 _("'%s' is not a valid value for the property"),
209 priv->protocol ? priv->protocol : "(null)");
210 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_PROTOCOL);
214 if ( priv->encapsulation
215 && ( strcmp (priv->encapsulation, NM_SETTING_ADSL_ENCAPSULATION_VCMUX)
216 && strcmp (priv->encapsulation, NM_SETTING_ADSL_ENCAPSULATION_LLC) )) {
219 NM_CONNECTION_ERROR_INVALID_PROPERTY,
220 _("'%s' is not a valid value for the property"),
221 priv->encapsulation);
222 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_ENCAPSULATION);
230 verify_secrets (NMSetting *setting, NMConnection *connection, GError **error)
232 return _nm_setting_verify_secret_string (NM_SETTING_ADSL_GET_PRIVATE (setting)->password,
233 NM_SETTING_ADSL_SETTING_NAME,
234 NM_SETTING_ADSL_PASSWORD,
239 need_secrets (NMSetting *setting)
241 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (setting);
242 GPtrArray *secrets = NULL;
244 if (priv->password && *priv->password)
247 if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
248 secrets = g_ptr_array_sized_new (1);
249 g_ptr_array_add (secrets, NM_SETTING_ADSL_PASSWORD);
256 nm_setting_adsl_init (NMSettingAdsl *setting)
261 finalize (GObject *object)
263 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (object);
265 g_free (priv->username);
266 g_free (priv->password);
267 g_free (priv->protocol);
268 g_free (priv->encapsulation);
270 G_OBJECT_CLASS (nm_setting_adsl_parent_class)->finalize (object);
274 set_property (GObject *object, guint prop_id,
275 const GValue *value, GParamSpec *pspec)
277 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (object);
282 g_free (priv->username);
283 priv->username = g_value_dup_string (value);
286 g_free (priv->password);
287 priv->password = g_value_dup_string (value);
289 case PROP_PASSWORD_FLAGS:
290 priv->password_flags = g_value_get_flags (value);
293 g_free (priv->protocol);
294 str = g_value_get_string (value);
295 priv->protocol = str ? g_ascii_strdown (str, -1) : NULL;
297 case PROP_ENCAPSULATION:
298 g_free (priv->encapsulation);
299 str = g_value_get_string (value);
300 priv->encapsulation = str ? g_ascii_strdown (str, -1) : NULL;
303 priv->vpi = g_value_get_uint (value);
306 priv->vci = g_value_get_uint (value);
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
315 get_property (GObject *object, guint prop_id,
316 GValue *value, GParamSpec *pspec)
318 NMSettingAdsl *setting = NM_SETTING_ADSL (object);
322 g_value_set_string (value, nm_setting_adsl_get_username (setting));
325 g_value_set_string (value, nm_setting_adsl_get_password (setting));
327 case PROP_PASSWORD_FLAGS:
328 g_value_set_flags (value, nm_setting_adsl_get_password_flags (setting));
331 g_value_set_string (value, nm_setting_adsl_get_protocol (setting));
333 case PROP_ENCAPSULATION:
334 g_value_set_string (value, nm_setting_adsl_get_encapsulation (setting));
337 g_value_set_uint (value, nm_setting_adsl_get_vpi (setting));
340 g_value_set_uint (value, nm_setting_adsl_get_vci (setting));
343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
349 nm_setting_adsl_class_init (NMSettingAdslClass *setting_class)
351 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
352 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
354 g_type_class_add_private (setting_class, sizeof (NMSettingAdslPrivate));
356 /* virtual methods */
357 object_class->set_property = set_property;
358 object_class->get_property = get_property;
359 object_class->finalize = finalize;
360 parent_class->verify = verify;
361 parent_class->verify_secrets = verify_secrets;
362 parent_class->need_secrets = need_secrets;
367 * NMSettingAdsl:username:
369 * Username used to authenticate with the ADSL service.
371 g_object_class_install_property
372 (object_class, PROP_USERNAME,
373 g_param_spec_string (NM_SETTING_ADSL_USERNAME, "", "",
376 G_PARAM_STATIC_STRINGS));
379 * NMSettingAdsl:password:
381 * Password used to authenticate with the ADSL service.
383 g_object_class_install_property
384 (object_class, PROP_PASSWORD,
385 g_param_spec_string (NM_SETTING_ADSL_PASSWORD, "", "",
388 NM_SETTING_PARAM_SECRET |
389 G_PARAM_STATIC_STRINGS));
392 * NMSettingAdsl:password-flags:
394 * Flags indicating how to handle the #NMSettingAdsl:password property.
396 g_object_class_install_property
397 (object_class, PROP_PASSWORD_FLAGS,
398 g_param_spec_flags (NM_SETTING_ADSL_PASSWORD_FLAGS, "", "",
399 NM_TYPE_SETTING_SECRET_FLAGS,
400 NM_SETTING_SECRET_FLAG_NONE,
402 G_PARAM_STATIC_STRINGS));
405 * NMSettingAdsl:protocol:
407 * ADSL connection protocol. Can be "pppoa", "pppoe" or "ipoatm".
409 g_object_class_install_property
410 (object_class, PROP_PROTOCOL,
411 g_param_spec_string (NM_SETTING_ADSL_PROTOCOL, "", "",
414 G_PARAM_STATIC_STRINGS));
417 * NMSettingAdsl:encapsulation:
419 * Encapsulation of ADSL connection. Can be "vcmux" or "llc".
421 g_object_class_install_property
422 (object_class, PROP_ENCAPSULATION,
423 g_param_spec_string (NM_SETTING_ADSL_ENCAPSULATION, "", "",
426 G_PARAM_STATIC_STRINGS));
431 * VPI of ADSL connection
433 g_object_class_install_property
434 (object_class, PROP_VPI,
435 g_param_spec_uint (NM_SETTING_ADSL_VPI, "", "",
438 G_PARAM_STATIC_STRINGS));
443 * VCI of ADSL connection
445 g_object_class_install_property
446 (object_class, PROP_VCI,
447 g_param_spec_uint (NM_SETTING_ADSL_VCI, "", "",
450 G_PARAM_STATIC_STRINGS));