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 2007 - 2013 Red Hat, Inc.
20 * Copyright 2007 - 2008 Novell, Inc.
23 #include "nm-default.h"
27 #include "nm-setting-pppoe.h"
28 #include "nm-setting-ppp.h"
29 #include "nm-setting-private.h"
32 * SECTION:nm-setting-pppoe
33 * @short_description: Describes PPPoE connection properties
34 * @include: nm-setting-pppoe.h
36 * The #NMSettingPPPOE object is a #NMSetting subclass that describes
37 * properties necessary for connection to networks that require PPPoE connections
38 * to provide IP transport, for example cable or DSL modems.
42 * nm_setting_pppoe_error_quark:
44 * Registers an error quark for #NMSettingPPPOE if necessary.
46 * Returns: the error quark used for #NMSettingPPPOE errors.
49 nm_setting_pppoe_error_quark (void)
53 if (G_UNLIKELY (!quark))
54 quark = g_quark_from_static_string ("nm-setting-pppoe-error-quark");
59 G_DEFINE_TYPE_WITH_CODE (NMSettingPPPOE, nm_setting_pppoe, NM_TYPE_SETTING,
60 _nm_register_setting (NM_SETTING_PPPOE_SETTING_NAME,
63 NM_SETTING_PPPOE_ERROR))
64 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPPOE)
66 #define NM_SETTING_PPPOE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPPOE, NMSettingPPPOEPrivate))
72 NMSettingSecretFlags password_flags;
73 } NMSettingPPPOEPrivate;
86 * nm_setting_pppoe_new:
88 * Creates a new #NMSettingPPPOE object with default values.
90 * Returns: (transfer full): the new empty #NMSettingPPPOE object
93 nm_setting_pppoe_new (void)
95 return (NMSetting *) g_object_new (NM_TYPE_SETTING_PPPOE, NULL);
99 * nm_setting_pppoe_get_service:
100 * @setting: the #NMSettingPPPOE
102 * Returns: the #NMSettingPPPOE:service property of the setting
105 nm_setting_pppoe_get_service (NMSettingPPPOE *setting)
107 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
109 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->service;
113 * nm_setting_pppoe_get_username:
114 * @setting: the #NMSettingPPPOE
116 * Returns: the #NMSettingPPPOE:username property of the setting
119 nm_setting_pppoe_get_username (NMSettingPPPOE *setting)
121 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
123 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->username;
127 * nm_setting_pppoe_get_password:
128 * @setting: the #NMSettingPPPOE
130 * Returns: the #NMSettingPPPOE:password property of the setting
133 nm_setting_pppoe_get_password (NMSettingPPPOE *setting)
135 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
137 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password;
141 * nm_setting_pppoe_get_password_flags:
142 * @setting: the #NMSettingPPPOE
144 * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingPPPOE:password
147 nm_setting_pppoe_get_password_flags (NMSettingPPPOE *setting)
149 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NM_SETTING_SECRET_FLAG_NONE);
151 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password_flags;
155 verify (NMSetting *setting, GSList *all_settings, GError **error)
157 NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
159 if (!priv->username) {
160 g_set_error_literal (error,
161 NM_SETTING_PPPOE_ERROR,
162 NM_SETTING_PPPOE_ERROR_MISSING_PROPERTY,
163 _("property is missing"));
164 g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_USERNAME);
166 } else if (!strlen (priv->username)) {
167 g_set_error_literal (error,
168 NM_SETTING_PPPOE_ERROR,
169 NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY,
170 _("property is empty"));
171 g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_USERNAME);
175 if (priv->service && !strlen (priv->service)) {
176 g_set_error_literal (error,
177 NM_SETTING_PPPOE_ERROR,
178 NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY,
179 _("property is empty"));
180 g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_SERVICE);
188 need_secrets (NMSetting *setting)
190 NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
191 GPtrArray *secrets = NULL;
196 if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
197 secrets = g_ptr_array_sized_new (1);
198 g_ptr_array_add (secrets, NM_SETTING_PPPOE_PASSWORD);
205 nm_setting_pppoe_init (NMSettingPPPOE *setting)
210 set_property (GObject *object, guint prop_id,
211 const GValue *value, GParamSpec *pspec)
213 NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (object);
217 g_free (priv->service);
218 priv->service = g_value_dup_string (value);
221 g_free (priv->username);
222 priv->username = g_value_dup_string (value);
225 g_free (priv->password);
226 priv->password = g_value_dup_string (value);
228 case PROP_PASSWORD_FLAGS:
229 priv->password_flags = g_value_get_uint (value);
232 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
238 get_property (GObject *object, guint prop_id,
239 GValue *value, GParamSpec *pspec)
241 NMSettingPPPOE *setting = NM_SETTING_PPPOE (object);
245 g_value_set_string (value, nm_setting_pppoe_get_service (setting));
248 g_value_set_string (value, nm_setting_pppoe_get_username (setting));
251 g_value_set_string (value, nm_setting_pppoe_get_password (setting));
253 case PROP_PASSWORD_FLAGS:
254 g_value_set_uint (value, nm_setting_pppoe_get_password_flags (setting));
257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
263 finalize (GObject *object)
265 NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (object);
267 g_free (priv->username);
268 g_free (priv->password);
269 g_free (priv->service);
271 G_OBJECT_CLASS (nm_setting_pppoe_parent_class)->finalize (object);
275 nm_setting_pppoe_class_init (NMSettingPPPOEClass *setting_class)
277 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
278 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
280 g_type_class_add_private (setting_class, sizeof (NMSettingPPPOEPrivate));
282 /* virtual methods */
283 object_class->set_property = set_property;
284 object_class->get_property = get_property;
285 object_class->finalize = finalize;
286 parent_class->verify = verify;
287 parent_class->need_secrets = need_secrets;
291 * NMSettingPPPOE:service:
293 * If specified, instruct PPPoE to only initiate sessions with access
294 * concentrators that provide the specified service. For most providers,
295 * this should be left blank. It is only required if there are multiple
296 * access concentrators or a specific service is known to be required.
298 g_object_class_install_property
299 (object_class, PROP_SERVICE,
300 g_param_spec_string (NM_SETTING_PPPOE_SERVICE, "", "",
303 G_PARAM_STATIC_STRINGS));
306 * NMSettingPPPOE:username:
308 * Username used to authenticate with the PPPoE service.
310 g_object_class_install_property
311 (object_class, PROP_USERNAME,
312 g_param_spec_string (NM_SETTING_PPPOE_USERNAME, "", "",
315 G_PARAM_STATIC_STRINGS));
318 * NMSettingPPPOE:password:
320 * Password used to authenticate with the PPPoE service.
322 g_object_class_install_property
323 (object_class, PROP_PASSWORD,
324 g_param_spec_string (NM_SETTING_PPPOE_PASSWORD, "", "",
327 NM_SETTING_PARAM_SECRET |
328 G_PARAM_STATIC_STRINGS));
331 * NMSettingPPPOE:password-flags:
333 * Flags indicating how to handle the #NMSettingPPPOE:password property.
335 g_object_class_install_property
336 (object_class, PROP_PASSWORD_FLAGS,
337 g_param_spec_uint (NM_SETTING_PPPOE_PASSWORD_FLAGS, "", "",
338 NM_SETTING_SECRET_FLAG_NONE,
339 NM_SETTING_SECRET_FLAGS_ALL,
340 NM_SETTING_SECRET_FLAG_NONE,
342 G_PARAM_STATIC_STRINGS));