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.
22 #include "nm-default.h"
26 #include "nm-setting-cdma.h"
28 #include "nm-setting-private.h"
29 #include "nm-core-enum-types.h"
32 * SECTION:nm-setting-cdma
33 * @short_description: Describes CDMA-based mobile broadband properties
35 * The #NMSettingCdma object is a #NMSetting subclass that describes
36 * properties that allow connections to IS-95-based mobile broadband
37 * networks, including those using CDMA2000/EVDO technology.
40 G_DEFINE_TYPE_WITH_CODE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING,
41 _nm_register_setting (CDMA, 1))
42 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CDMA)
44 #define NM_SETTING_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CDMA, NMSettingCdmaPrivate))
47 char *number; /* For dialing, duh */
50 NMSettingSecretFlags password_flags;
51 } NMSettingCdmaPrivate;
64 * nm_setting_cdma_new:
66 * Creates a new #NMSettingCdma object with default values.
68 * Returns: the new empty #NMSettingCdma object
71 nm_setting_cdma_new (void)
73 return (NMSetting *) g_object_new (NM_TYPE_SETTING_CDMA, NULL);
77 * nm_setting_cdma_get_number:
78 * @setting: the #NMSettingCdma
80 * Returns: the #NMSettingCdma:number property of the setting
83 nm_setting_cdma_get_number (NMSettingCdma *setting)
85 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
87 return NM_SETTING_CDMA_GET_PRIVATE (setting)->number;
91 * nm_setting_cdma_get_username:
92 * @setting: the #NMSettingCdma
94 * Returns: the #NMSettingCdma:username property of the setting
97 nm_setting_cdma_get_username (NMSettingCdma *setting)
99 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
101 return NM_SETTING_CDMA_GET_PRIVATE (setting)->username;
105 * nm_setting_cdma_get_password:
106 * @setting: the #NMSettingCdma
108 * Returns: the #NMSettingCdma:password property of the setting
111 nm_setting_cdma_get_password (NMSettingCdma *setting)
113 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
115 return NM_SETTING_CDMA_GET_PRIVATE (setting)->password;
119 * nm_setting_cdma_get_password_flags:
120 * @setting: the #NMSettingCdma
122 * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingCdma:password
125 nm_setting_cdma_get_password_flags (NMSettingCdma *setting)
127 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NM_SETTING_SECRET_FLAG_NONE);
129 return NM_SETTING_CDMA_GET_PRIVATE (setting)->password_flags;
133 verify (NMSetting *setting, NMConnection *connection, GError **error)
135 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (setting);
138 g_set_error_literal (error,
140 NM_CONNECTION_ERROR_MISSING_PROPERTY,
141 _("property is missing"));
142 g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_NUMBER);
144 } else if (!strlen (priv->number)) {
145 g_set_error_literal (error,
147 NM_CONNECTION_ERROR_INVALID_PROPERTY,
148 _("property is empty"));
149 g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_NUMBER);
153 if (priv->username && !strlen (priv->username)) {
154 g_set_error_literal (error,
156 NM_CONNECTION_ERROR_INVALID_PROPERTY,
157 _("property is empty"));
158 g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_USERNAME);
166 verify_secrets (NMSetting *setting, NMConnection *connection, GError **error)
168 return _nm_setting_verify_secret_string (NM_SETTING_CDMA_GET_PRIVATE (setting)->password,
169 NM_SETTING_CDMA_SETTING_NAME,
170 NM_SETTING_CDMA_PASSWORD,
175 need_secrets (NMSetting *setting)
177 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (setting);
178 GPtrArray *secrets = NULL;
180 if (priv->password && *priv->password)
183 if (priv->username) {
184 if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
185 secrets = g_ptr_array_sized_new (1);
186 g_ptr_array_add (secrets, NM_SETTING_CDMA_PASSWORD);
194 nm_setting_cdma_init (NMSettingCdma *setting)
199 finalize (GObject *object)
201 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (object);
203 g_free (priv->number);
204 g_free (priv->username);
205 g_free (priv->password);
207 G_OBJECT_CLASS (nm_setting_cdma_parent_class)->finalize (object);
211 set_property (GObject *object, guint prop_id,
212 const GValue *value, GParamSpec *pspec)
214 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (object);
218 g_free (priv->number);
219 priv->number = g_value_dup_string (value);
222 g_free (priv->username);
223 priv->username = g_value_dup_string (value);
226 g_free (priv->password);
227 priv->password = g_value_dup_string (value);
229 case PROP_PASSWORD_FLAGS:
230 priv->password_flags = g_value_get_flags (value);
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 get_property (GObject *object, guint prop_id,
240 GValue *value, GParamSpec *pspec)
242 NMSettingCdma *setting = NM_SETTING_CDMA (object);
246 g_value_set_string (value, nm_setting_cdma_get_number (setting));
249 g_value_set_string (value, nm_setting_cdma_get_username (setting));
252 g_value_set_string (value, nm_setting_cdma_get_password (setting));
254 case PROP_PASSWORD_FLAGS:
255 g_value_set_flags (value, nm_setting_cdma_get_password_flags (setting));
258 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
264 nm_setting_cdma_class_init (NMSettingCdmaClass *setting_class)
266 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
267 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
269 g_type_class_add_private (setting_class, sizeof (NMSettingCdmaPrivate));
271 /* virtual methods */
272 object_class->set_property = set_property;
273 object_class->get_property = get_property;
274 object_class->finalize = finalize;
275 parent_class->verify = verify;
276 parent_class->verify_secrets = verify_secrets;
277 parent_class->need_secrets = need_secrets;
282 * NMSettingCdma:number:
284 * The number to dial to establish the connection to the CDMA-based mobile
285 * broadband network, if any. If not specified, the default number (#777)
286 * is used when required.
288 g_object_class_install_property
289 (object_class, PROP_NUMBER,
290 g_param_spec_string (NM_SETTING_CDMA_NUMBER, "", "",
293 G_PARAM_STATIC_STRINGS));
296 * NMSettingCdma:username:
298 * The username used to authenticate with the network, if required. Many
299 * providers do not require a username, or accept any username. But if a
300 * username is required, it is specified here.
302 g_object_class_install_property
303 (object_class, PROP_USERNAME,
304 g_param_spec_string (NM_SETTING_CDMA_USERNAME, "", "",
307 G_PARAM_STATIC_STRINGS));
310 * NMSettingCdma:password:
312 * The password used to authenticate with the network, if required. Many
313 * providers do not require a password, or accept any password. But if a
314 * password is required, it is specified here.
316 g_object_class_install_property
317 (object_class, PROP_PASSWORD,
318 g_param_spec_string (NM_SETTING_CDMA_PASSWORD, "", "",
321 NM_SETTING_PARAM_SECRET |
322 G_PARAM_STATIC_STRINGS));
325 * NMSettingCdma:password-flags:
327 * Flags indicating how to handle the #NMSettingCdma:password property.
329 g_object_class_install_property
330 (object_class, PROP_PASSWORD_FLAGS,
331 g_param_spec_flags (NM_SETTING_CDMA_PASSWORD_FLAGS, "", "",
332 NM_TYPE_SETTING_SECRET_FLAGS,
333 NM_SETTING_SECRET_FLAG_NONE,
335 G_PARAM_STATIC_STRINGS));