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"
30 #include "nm-core-enum-types.h"
33 * SECTION:nm-setting-pppoe
34 * @short_description: Describes PPPoE connection properties
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.
41 G_DEFINE_TYPE_WITH_CODE (NMSettingPppoe, nm_setting_pppoe, NM_TYPE_SETTING,
42 _nm_register_setting (PPPOE, 3))
43 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPPOE)
45 #define NM_SETTING_PPPOE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPPOE, NMSettingPppoePrivate))
51 NMSettingSecretFlags password_flags;
52 } NMSettingPppoePrivate;
65 * nm_setting_pppoe_new:
67 * Creates a new #NMSettingPppoe object with default values.
69 * Returns: (transfer full): the new empty #NMSettingPppoe object
72 nm_setting_pppoe_new (void)
74 return (NMSetting *) g_object_new (NM_TYPE_SETTING_PPPOE, NULL);
78 * nm_setting_pppoe_get_service:
79 * @setting: the #NMSettingPppoe
81 * Returns: the #NMSettingPppoe:service property of the setting
84 nm_setting_pppoe_get_service (NMSettingPppoe *setting)
86 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
88 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->service;
92 * nm_setting_pppoe_get_username:
93 * @setting: the #NMSettingPppoe
95 * Returns: the #NMSettingPppoe:username property of the setting
98 nm_setting_pppoe_get_username (NMSettingPppoe *setting)
100 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
102 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->username;
106 * nm_setting_pppoe_get_password:
107 * @setting: the #NMSettingPppoe
109 * Returns: the #NMSettingPppoe:password property of the setting
112 nm_setting_pppoe_get_password (NMSettingPppoe *setting)
114 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
116 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password;
120 * nm_setting_pppoe_get_password_flags:
121 * @setting: the #NMSettingPppoe
123 * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingPppoe:password
126 nm_setting_pppoe_get_password_flags (NMSettingPppoe *setting)
128 g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NM_SETTING_SECRET_FLAG_NONE);
130 return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password_flags;
134 verify (NMSetting *setting, NMConnection *connection, GError **error)
136 NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
138 if (!priv->username) {
139 g_set_error_literal (error,
141 NM_CONNECTION_ERROR_MISSING_PROPERTY,
142 _("property is missing"));
143 g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_USERNAME);
145 } else if (!strlen (priv->username)) {
146 g_set_error_literal (error,
148 NM_CONNECTION_ERROR_INVALID_PROPERTY,
149 _("property is empty"));
150 g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_USERNAME);
154 if (priv->service && !strlen (priv->service)) {
155 g_set_error_literal (error,
157 NM_CONNECTION_ERROR_INVALID_PROPERTY,
158 _("property is empty"));
159 g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_SERVICE);
167 need_secrets (NMSetting *setting)
169 NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
170 GPtrArray *secrets = NULL;
175 if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
176 secrets = g_ptr_array_sized_new (1);
177 g_ptr_array_add (secrets, NM_SETTING_PPPOE_PASSWORD);
184 nm_setting_pppoe_init (NMSettingPppoe *setting)
189 set_property (GObject *object, guint prop_id,
190 const GValue *value, GParamSpec *pspec)
192 NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (object);
196 g_free (priv->service);
197 priv->service = g_value_dup_string (value);
200 g_free (priv->username);
201 priv->username = g_value_dup_string (value);
204 g_free (priv->password);
205 priv->password = g_value_dup_string (value);
207 case PROP_PASSWORD_FLAGS:
208 priv->password_flags = g_value_get_flags (value);
211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
217 get_property (GObject *object, guint prop_id,
218 GValue *value, GParamSpec *pspec)
220 NMSettingPppoe *setting = NM_SETTING_PPPOE (object);
224 g_value_set_string (value, nm_setting_pppoe_get_service (setting));
227 g_value_set_string (value, nm_setting_pppoe_get_username (setting));
230 g_value_set_string (value, nm_setting_pppoe_get_password (setting));
232 case PROP_PASSWORD_FLAGS:
233 g_value_set_flags (value, nm_setting_pppoe_get_password_flags (setting));
236 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
242 finalize (GObject *object)
244 NMSettingPppoePrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (object);
246 g_free (priv->username);
247 g_free (priv->password);
248 g_free (priv->service);
250 G_OBJECT_CLASS (nm_setting_pppoe_parent_class)->finalize (object);
254 nm_setting_pppoe_class_init (NMSettingPppoeClass *setting_class)
256 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
257 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
259 g_type_class_add_private (setting_class, sizeof (NMSettingPppoePrivate));
261 /* virtual methods */
262 object_class->set_property = set_property;
263 object_class->get_property = get_property;
264 object_class->finalize = finalize;
265 parent_class->verify = verify;
266 parent_class->need_secrets = need_secrets;
270 * NMSettingPppoe:service:
272 * If specified, instruct PPPoE to only initiate sessions with access
273 * concentrators that provide the specified service. For most providers,
274 * this should be left blank. It is only required if there are multiple
275 * access concentrators or a specific service is known to be required.
277 g_object_class_install_property
278 (object_class, PROP_SERVICE,
279 g_param_spec_string (NM_SETTING_PPPOE_SERVICE, "", "",
282 G_PARAM_STATIC_STRINGS));
285 * NMSettingPppoe:username:
287 * Username used to authenticate with the PPPoE service.
289 g_object_class_install_property
290 (object_class, PROP_USERNAME,
291 g_param_spec_string (NM_SETTING_PPPOE_USERNAME, "", "",
294 G_PARAM_STATIC_STRINGS));
297 * NMSettingPppoe:password:
299 * Password used to authenticate with the PPPoE service.
301 g_object_class_install_property
302 (object_class, PROP_PASSWORD,
303 g_param_spec_string (NM_SETTING_PPPOE_PASSWORD, "", "",
306 NM_SETTING_PARAM_SECRET |
307 G_PARAM_STATIC_STRINGS));
310 * NMSettingPppoe:password-flags:
312 * Flags indicating how to handle the #NMSettingPppoe:password property.
314 g_object_class_install_property
315 (object_class, PROP_PASSWORD_FLAGS,
316 g_param_spec_flags (NM_SETTING_PPPOE_PASSWORD_FLAGS, "", "",
317 NM_TYPE_SETTING_SECRET_FLAGS,
318 NM_SETTING_SECRET_FLAG_NONE,
320 G_PARAM_STATIC_STRINGS));