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"
31 * SECTION:nm-setting-cdma
32 * @short_description: Describes CDMA-based mobile broadband properties
33 * @include: nm-setting-cdma.h
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.
41 * nm_setting_cdma_error_quark:
43 * Registers an error quark for #NMSettingCdma if necessary.
45 * Returns: the error quark used for #NMSettingCdma errors.
48 nm_setting_cdma_error_quark (void)
52 if (G_UNLIKELY (!quark))
53 quark = g_quark_from_static_string ("nm-setting-cdma-error-quark");
58 G_DEFINE_TYPE_WITH_CODE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING,
59 _nm_register_setting (NM_SETTING_CDMA_SETTING_NAME,
62 NM_SETTING_CDMA_ERROR))
63 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CDMA)
65 #define NM_SETTING_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CDMA, NMSettingCdmaPrivate))
68 char *number; /* For dialing, duh */
71 NMSettingSecretFlags password_flags;
72 } NMSettingCdmaPrivate;
85 * nm_setting_cdma_new:
87 * Creates a new #NMSettingCdma object with default values.
89 * Returns: the new empty #NMSettingCdma object
92 nm_setting_cdma_new (void)
94 return (NMSetting *) g_object_new (NM_TYPE_SETTING_CDMA, NULL);
98 * nm_setting_cdma_get_number:
99 * @setting: the #NMSettingCdma
101 * Returns: the #NMSettingCdma:number property of the setting
104 nm_setting_cdma_get_number (NMSettingCdma *setting)
106 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
108 return NM_SETTING_CDMA_GET_PRIVATE (setting)->number;
112 * nm_setting_cdma_get_username:
113 * @setting: the #NMSettingCdma
115 * Returns: the #NMSettingCdma:username property of the setting
118 nm_setting_cdma_get_username (NMSettingCdma *setting)
120 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
122 return NM_SETTING_CDMA_GET_PRIVATE (setting)->username;
126 * nm_setting_cdma_get_password:
127 * @setting: the #NMSettingCdma
129 * Returns: the #NMSettingCdma:password property of the setting
132 nm_setting_cdma_get_password (NMSettingCdma *setting)
134 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
136 return NM_SETTING_CDMA_GET_PRIVATE (setting)->password;
140 * nm_setting_cdma_get_password_flags:
141 * @setting: the #NMSettingCdma
143 * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingCdma:password
146 nm_setting_cdma_get_password_flags (NMSettingCdma *setting)
148 g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NM_SETTING_SECRET_FLAG_NONE);
150 return NM_SETTING_CDMA_GET_PRIVATE (setting)->password_flags;
154 verify (NMSetting *setting, GSList *all_settings, GError **error)
156 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (setting);
159 g_set_error_literal (error,
160 NM_SETTING_CDMA_ERROR,
161 NM_SETTING_CDMA_ERROR_MISSING_PROPERTY,
162 _("property is missing"));
163 g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_NUMBER);
165 } else if (!strlen (priv->number)) {
166 g_set_error_literal (error,
167 NM_SETTING_CDMA_ERROR,
168 NM_SETTING_CDMA_ERROR_INVALID_PROPERTY,
169 _("property is empty"));
170 g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_NUMBER);
174 if (priv->username && !strlen (priv->username)) {
175 g_set_error_literal (error,
176 NM_SETTING_CDMA_ERROR,
177 NM_SETTING_CDMA_ERROR_INVALID_PROPERTY,
178 _("property is empty"));
179 g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_USERNAME);
187 need_secrets (NMSetting *setting)
189 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (setting);
190 GPtrArray *secrets = NULL;
192 if (priv->password && *priv->password)
195 if (priv->username) {
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_CDMA_PASSWORD);
206 nm_setting_cdma_init (NMSettingCdma *setting)
211 finalize (GObject *object)
213 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (object);
215 g_free (priv->number);
216 g_free (priv->username);
217 g_free (priv->password);
219 G_OBJECT_CLASS (nm_setting_cdma_parent_class)->finalize (object);
223 set_property (GObject *object, guint prop_id,
224 const GValue *value, GParamSpec *pspec)
226 NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (object);
230 g_free (priv->number);
231 priv->number = g_value_dup_string (value);
234 g_free (priv->username);
235 priv->username = g_value_dup_string (value);
238 g_free (priv->password);
239 priv->password = g_value_dup_string (value);
241 case PROP_PASSWORD_FLAGS:
242 priv->password_flags = g_value_get_uint (value);
245 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
251 get_property (GObject *object, guint prop_id,
252 GValue *value, GParamSpec *pspec)
254 NMSettingCdma *setting = NM_SETTING_CDMA (object);
258 g_value_set_string (value, nm_setting_cdma_get_number (setting));
261 g_value_set_string (value, nm_setting_cdma_get_username (setting));
264 g_value_set_string (value, nm_setting_cdma_get_password (setting));
266 case PROP_PASSWORD_FLAGS:
267 g_value_set_uint (value, nm_setting_cdma_get_password_flags (setting));
270 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
276 nm_setting_cdma_class_init (NMSettingCdmaClass *setting_class)
278 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
279 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
281 g_type_class_add_private (setting_class, sizeof (NMSettingCdmaPrivate));
283 /* virtual methods */
284 object_class->set_property = set_property;
285 object_class->get_property = get_property;
286 object_class->finalize = finalize;
287 parent_class->verify = verify;
288 parent_class->need_secrets = need_secrets;
293 * NMSettingCdma:number:
295 * The number to dial to establish the connection to the CDMA-based mobile
296 * broadband network, if any. If not specified, the default number (#777)
297 * is used when required.
299 g_object_class_install_property
300 (object_class, PROP_NUMBER,
301 g_param_spec_string (NM_SETTING_CDMA_NUMBER, "", "",
304 G_PARAM_STATIC_STRINGS));
307 * NMSettingCdma:username:
309 * The username used to authenticate with the network, if required. Many
310 * providers do not require a username, or accept any username. But if a
311 * username is required, it is specified here.
313 g_object_class_install_property
314 (object_class, PROP_USERNAME,
315 g_param_spec_string (NM_SETTING_CDMA_USERNAME, "", "",
318 G_PARAM_STATIC_STRINGS));
321 * NMSettingCdma:password:
323 * The password used to authenticate with the network, if required. Many
324 * providers do not require a password, or accept any password. But if a
325 * password is required, it is specified here.
327 g_object_class_install_property
328 (object_class, PROP_PASSWORD,
329 g_param_spec_string (NM_SETTING_CDMA_PASSWORD, "", "",
332 NM_SETTING_PARAM_SECRET |
333 G_PARAM_STATIC_STRINGS));
336 * NMSettingCdma:password-flags:
338 * Flags indicating how to handle the #NMSettingCdma:password property.
340 g_object_class_install_property
341 (object_class, PROP_PASSWORD_FLAGS,
342 g_param_spec_uint (NM_SETTING_CDMA_PASSWORD_FLAGS, "", "",
343 NM_SETTING_SECRET_FLAG_NONE,
344 NM_SETTING_SECRET_FLAGS_ALL,
345 NM_SETTING_SECRET_FLAG_NONE,
347 G_PARAM_STATIC_STRINGS));