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"
32 * SECTION:nm-setting-adsl
33 * @short_description: Describes ADSL-based properties
34 * @include: nm-setting-adsl.h
36 * The #NMSettingAdsl object is a #NMSetting subclass that describes
37 * properties of ADSL connections.
41 * nm_setting_adsl_error_quark:
43 * Registers an error quark for #NMSettingAdsl if necessary.
45 * Returns: the error quark used for #NMSettingAdsl errors.
48 nm_setting_adsl_error_quark (void)
52 if (G_UNLIKELY (!quark))
53 quark = g_quark_from_static_string ("nm-setting-adsl-error-quark");
57 G_DEFINE_TYPE_WITH_CODE (NMSettingAdsl, nm_setting_adsl, NM_TYPE_SETTING,
58 _nm_register_setting (NM_SETTING_ADSL_SETTING_NAME,
61 NM_SETTING_ADSL_ERROR))
62 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_ADSL)
64 #define NM_SETTING_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_ADSL, NMSettingAdslPrivate))
69 NMSettingSecretFlags password_flags;
74 } NMSettingAdslPrivate;
90 * nm_setting_adsl_new:
92 * Creates a new #NMSettingAdsl object with default values.
94 * Returns: the new empty #NMSettingAdsl object
97 nm_setting_adsl_new (void)
99 return (NMSetting *) g_object_new (NM_TYPE_SETTING_ADSL, NULL);
103 * nm_setting_adsl_get_username:
104 * @setting: the #NMSettingAdsl
106 * Returns: the #NMSettingAdsl:username property of the setting
109 nm_setting_adsl_get_username (NMSettingAdsl *setting)
111 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
113 return NM_SETTING_ADSL_GET_PRIVATE (setting)->username;
117 * nm_setting_adsl_get_password:
118 * @setting: the #NMSettingAdsl
120 * Returns: the #NMSettingAdsl:password property of the setting
123 nm_setting_adsl_get_password (NMSettingAdsl *setting)
125 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
127 return NM_SETTING_ADSL_GET_PRIVATE (setting)->password;
131 * nm_setting_adsl_get_password_flags:
132 * @setting: the #NMSettingAdsl
134 * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingAdsl:password
137 nm_setting_adsl_get_password_flags (NMSettingAdsl *setting)
139 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NM_SETTING_SECRET_FLAG_NONE);
141 return NM_SETTING_ADSL_GET_PRIVATE (setting)->password_flags;
145 * nm_setting_adsl_get_protocol:
146 * @setting: the #NMSettingAdsl
148 * Returns: the #NMSettingAdsl:protocol property of the setting
151 nm_setting_adsl_get_protocol (NMSettingAdsl *setting)
153 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
155 return NM_SETTING_ADSL_GET_PRIVATE (setting)->protocol;
159 * nm_setting_adsl_get_encapsulation:
160 * @setting: the #NMSettingAdsl
162 * Returns: the #NMSettingAdsl:encapsulation property of the setting
165 nm_setting_adsl_get_encapsulation (NMSettingAdsl *setting)
167 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
169 return NM_SETTING_ADSL_GET_PRIVATE (setting)->encapsulation;
173 * nm_setting_adsl_get_vpi:
174 * @setting: the #NMSettingAdsl
176 * Returns: the #NMSettingAdsl:vpi property of the setting
179 nm_setting_adsl_get_vpi (NMSettingAdsl *setting)
181 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), 0);
183 return NM_SETTING_ADSL_GET_PRIVATE (setting)->vpi;
187 * nm_setting_adsl_get_vci:
188 * @setting: the #NMSettingAdsl
190 * Returns: the #NMSettingAdsl:vci property of the setting
193 nm_setting_adsl_get_vci (NMSettingAdsl *setting)
195 g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), 0);
197 return NM_SETTING_ADSL_GET_PRIVATE (setting)->vci;
201 verify (NMSetting *setting, GSList *all_settings, GError **error)
203 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (setting);
205 if (!priv->username) {
206 g_set_error_literal (error,
207 NM_SETTING_ADSL_ERROR,
208 NM_SETTING_ADSL_ERROR_MISSING_PROPERTY,
209 _("property is missing"));
210 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_USERNAME);
212 } else if (!strlen (priv->username)) {
213 g_set_error_literal (error,
214 NM_SETTING_ADSL_ERROR,
215 NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
216 _("property is empty"));
217 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_USERNAME);
222 || ( strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA)
223 && strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)
224 && strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_IPOATM))){
226 NM_SETTING_ADSL_ERROR,
227 NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
228 _("'%s' is not a valid value for the property"),
229 priv->protocol ? priv->protocol : "(null)");
230 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_PROTOCOL);
234 if ( priv->encapsulation
235 && ( strcmp (priv->encapsulation, NM_SETTING_ADSL_ENCAPSULATION_VCMUX)
236 && strcmp (priv->encapsulation, NM_SETTING_ADSL_ENCAPSULATION_LLC) )) {
238 NM_SETTING_ADSL_ERROR,
239 NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
240 _("'%s' is not a valid value for the property"),
241 priv->encapsulation);
242 g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_ENCAPSULATION);
250 need_secrets (NMSetting *setting)
252 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (setting);
253 GPtrArray *secrets = NULL;
255 if (priv->password && *priv->password)
258 if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
259 secrets = g_ptr_array_sized_new (1);
260 g_ptr_array_add (secrets, NM_SETTING_ADSL_PASSWORD);
267 nm_setting_adsl_init (NMSettingAdsl *setting)
272 finalize (GObject *object)
274 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (object);
276 g_free (priv->username);
277 g_free (priv->password);
278 g_free (priv->protocol);
279 g_free (priv->encapsulation);
281 G_OBJECT_CLASS (nm_setting_adsl_parent_class)->finalize (object);
285 set_property (GObject *object, guint prop_id,
286 const GValue *value, GParamSpec *pspec)
288 NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (object);
293 g_free (priv->username);
294 priv->username = g_value_dup_string (value);
297 g_free (priv->password);
298 priv->password = g_value_dup_string (value);
300 case PROP_PASSWORD_FLAGS:
301 priv->password_flags = g_value_get_uint (value);
304 g_free (priv->protocol);
305 str = g_value_get_string (value);
306 priv->protocol = str ? g_ascii_strdown (str, -1) : NULL;
308 case PROP_ENCAPSULATION:
309 g_free (priv->encapsulation);
310 str = g_value_get_string (value);
311 priv->encapsulation = str ? g_ascii_strdown (str, -1) : NULL;
314 priv->vpi = g_value_get_uint (value);
317 priv->vci = g_value_get_uint (value);
320 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
326 get_property (GObject *object, guint prop_id,
327 GValue *value, GParamSpec *pspec)
329 NMSettingAdsl *setting = NM_SETTING_ADSL (object);
333 g_value_set_string (value, nm_setting_adsl_get_username (setting));
336 g_value_set_string (value, nm_setting_adsl_get_password (setting));
338 case PROP_PASSWORD_FLAGS:
339 g_value_set_uint (value, nm_setting_adsl_get_password_flags (setting));
342 g_value_set_string (value, nm_setting_adsl_get_protocol (setting));
344 case PROP_ENCAPSULATION:
345 g_value_set_string (value, nm_setting_adsl_get_encapsulation (setting));
348 g_value_set_uint (value, nm_setting_adsl_get_vpi (setting));
351 g_value_set_uint (value, nm_setting_adsl_get_vci (setting));
354 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
360 nm_setting_adsl_class_init (NMSettingAdslClass *setting_class)
362 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
363 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
365 g_type_class_add_private (setting_class, sizeof (NMSettingAdslPrivate));
367 /* virtual methods */
368 object_class->set_property = set_property;
369 object_class->get_property = get_property;
370 object_class->finalize = finalize;
371 parent_class->verify = verify;
372 parent_class->need_secrets = need_secrets;
377 * NMSettingAdsl:username:
379 * Username used to authenticate with the ADSL service.
381 g_object_class_install_property
382 (object_class, PROP_USERNAME,
383 g_param_spec_string (NM_SETTING_ADSL_USERNAME, "", "",
386 G_PARAM_STATIC_STRINGS));
389 * NMSettingAdsl:password:
391 * Password used to authenticate with the ADSL service.
393 g_object_class_install_property
394 (object_class, PROP_PASSWORD,
395 g_param_spec_string (NM_SETTING_ADSL_PASSWORD, "", "",
398 NM_SETTING_PARAM_SECRET |
399 G_PARAM_STATIC_STRINGS));
402 * NMSettingAdsl:password-flags:
404 * Flags indicating how to handle the #NMSettingAdsl:password property.
406 g_object_class_install_property
407 (object_class, PROP_PASSWORD_FLAGS,
408 g_param_spec_uint (NM_SETTING_ADSL_PASSWORD_FLAGS, "", "",
409 NM_SETTING_SECRET_FLAG_NONE,
410 NM_SETTING_SECRET_FLAGS_ALL,
411 NM_SETTING_SECRET_FLAG_NONE,
413 G_PARAM_STATIC_STRINGS));
416 * NMSettingAdsl:protocol:
418 * ADSL connection protocol. Can be "pppoa", "pppoe" or "ipoatm".
420 g_object_class_install_property
421 (object_class, PROP_PROTOCOL,
422 g_param_spec_string (NM_SETTING_ADSL_PROTOCOL, "", "",
425 G_PARAM_STATIC_STRINGS));
428 * NMSettingAdsl:encapsulation:
430 * Encapsulation of ADSL connection. Can be "vcmux" or "llc".
432 g_object_class_install_property
433 (object_class, PROP_ENCAPSULATION,
434 g_param_spec_string (NM_SETTING_ADSL_ENCAPSULATION, "", "",
437 G_PARAM_STATIC_STRINGS));
442 * VPI of ADSL connection
444 g_object_class_install_property
445 (object_class, PROP_VPI,
446 g_param_spec_uint (NM_SETTING_ADSL_VPI, "", "",
449 G_PARAM_STATIC_STRINGS));
454 * VCI of ADSL connection
456 g_object_class_install_property
457 (object_class, PROP_VCI,
458 g_param_spec_uint (NM_SETTING_ADSL_VCI, "", "",
461 G_PARAM_STATIC_STRINGS));