1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
27 #include "gmountoperation.h"
28 #include "gio-marshal.h"
32 * SECTION:gmountoperation
33 * @short_description: Authentication methods for mountable locations
35 * #GMountOperation provides a mechanism for authenticating mountable
36 * operations, such as loop mounting files, hard drive partitions or
39 * Mountable GIO backends should implement #GMountOperation if they
40 * require any priviledges or authentication for their volumes to be
41 * mounted (e.g. a hard disk partition or an encrypted filesystem), or
42 * if they are implementing a remote server protocol which requires user
43 * credentials such as FTP or WebDAV.
46 G_DEFINE_TYPE (GMountOperation, g_mount_operation, G_TYPE_OBJECT);
55 static guint signals[LAST_SIGNAL] = { 0 };
57 struct _GMountOperationPrivate {
62 GPasswordSave password_save;
67 g_mount_operation_finalize (GObject *object)
69 GMountOperation *operation;
70 GMountOperationPrivate *priv;
72 operation = G_MOUNT_OPERATION (object);
74 priv = operation->priv;
76 g_free (priv->password);
78 g_free (priv->domain);
80 if (G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize)
81 (*G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize) (object);
85 boolean_handled_accumulator (GSignalInvocationHint *ihint,
87 const GValue *handler_return,
90 gboolean continue_emission;
91 gboolean signal_handled;
93 signal_handled = g_value_get_boolean (handler_return);
94 g_value_set_boolean (return_accu, signal_handled);
95 continue_emission = !signal_handled;
97 return continue_emission;
101 ask_password (GMountOperation *op,
103 const char *default_user,
104 const char *default_domain,
105 GPasswordFlags flags)
111 ask_question (GMountOperation *op,
113 const char *choices[])
119 g_mount_operation_class_init (GMountOperationClass *klass)
121 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
123 g_type_class_add_private (klass, sizeof (GMountOperationPrivate));
125 gobject_class->finalize = g_mount_operation_finalize;
127 klass->ask_password = ask_password;
128 klass->ask_question = ask_question;
131 * GMountOperation::ask-password:
132 * @op: a #GMountOperation requesting a password.
133 * @message: string containing a message to display to the user.
134 * @default_user: string containing the default user name.
135 * @default_domain: string containing the default domain.
136 * @flags: a set of #GPasswordFlags.
138 * Emitted when a mount operation asks the user for a password.
140 signals[ASK_PASSWORD] =
141 g_signal_new (I_("ask_password"),
142 G_TYPE_FROM_CLASS (gobject_class),
144 G_STRUCT_OFFSET (GMountOperationClass, ask_password),
145 boolean_handled_accumulator, NULL,
146 _gio_marshal_BOOLEAN__STRING_STRING_STRING_INT,
148 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
151 * GMountOperation::ask-question:
152 * @op: a #GMountOperation asking a question.
153 * @message: string containing a message to display to the user.
154 * @choices: an array of strings for each possible choice.
156 * Emitted when asking the user a question and gives a list of choices for the
157 * user to choose from.
159 signals[ASK_QUESTION] =
160 g_signal_new (I_("ask_question"),
161 G_TYPE_FROM_CLASS (gobject_class),
163 G_STRUCT_OFFSET (GMountOperationClass, ask_question),
164 boolean_handled_accumulator, NULL,
165 _gio_marshal_BOOLEAN__STRING_POINTER,
167 G_TYPE_STRING, G_TYPE_POINTER);
170 * GMountOperation::reply:
171 * @op: a #GMountOperation.
172 * @abort: a gboolean indicating %TRUE if the operation was aborted.
174 * Emitted when the user has replied to the mount operation.
177 g_signal_new (I_("reply"),
178 G_TYPE_FROM_CLASS (gobject_class),
180 G_STRUCT_OFFSET (GMountOperationClass, reply),
182 g_cclosure_marshal_VOID__BOOLEAN,
188 g_mount_operation_init (GMountOperation *operation)
190 operation->priv = G_TYPE_INSTANCE_GET_PRIVATE (operation,
191 G_TYPE_MOUNT_OPERATION,
192 GMountOperationPrivate);
196 * g_mount_operation_new:
198 * Creates a new mount operation.
200 * Returns: a #GMountOperation.
203 g_mount_operation_new (void)
205 return g_object_new (G_TYPE_MOUNT_OPERATION, NULL);
209 * g_mount_operation_get_username
210 * @op: a #GMountOperation.
212 * Get the user name from the mount operation.
214 * Returns: a string containing the user name.
217 g_mount_operation_get_username (GMountOperation *op)
219 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
220 return op->priv->user;
224 * g_mount_operation_set_username:
225 * @op: a #GMountOperation.
226 * @username: input username.
228 * Sets the user name within @op to @username.
232 g_mount_operation_set_username (GMountOperation *op,
233 const char *username)
235 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
236 g_free (op->priv->user);
237 op->priv->user = g_strdup (username);
241 * g_mount_operation_get_password:
242 * @op: a #GMountOperation.
244 * Gets a password from the mount operation.
246 * Returns: a string containing the password within @op.
249 g_mount_operation_get_password (GMountOperation *op)
251 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
252 return op->priv->password;
256 * g_mount_operation_set_password:
257 * @op: a #GMountOperation.
258 * @password: password to set.
260 * Sets the mount operation's password to @password.
264 g_mount_operation_set_password (GMountOperation *op,
265 const char *password)
267 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
268 g_free (op->priv->password);
269 op->priv->password = g_strdup (password);
273 * g_mount_operation_get_anonymous:
274 * @op: a #GMountOperation.
276 * Check to see whether the mount operation is being used
277 * for an anonymous user.
279 * Returns: %TRUE if mount operation is anonymous.
282 g_mount_operation_get_anonymous (GMountOperation *op)
284 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
285 return op->priv->anonymous;
289 * g_mount_operation_set_anonymous:
290 * @op: a #GMountOperation.
291 * @anonymous: boolean value.
293 * Sets the mount operation to use an anonymous user if @anonymous is %TRUE.
296 g_mount_operation_set_anonymous (GMountOperation *op,
299 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
300 op->priv->anonymous = anonymous;
304 * g_mount_operation_get_domain:
305 * @op: a #GMountOperation.
307 * Gets the domain of the mount operation.
309 * Returns: a string set to the domain.
312 g_mount_operation_get_domain (GMountOperation *op)
314 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
315 return op->priv->domain;
319 * g_mount_operation_set_domain:
320 * @op: a #GMountOperation.
321 * @domain: the domain to set.
323 * Sets the mount operation's domain.
326 g_mount_operation_set_domain (GMountOperation *op,
329 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
330 g_free (op->priv->domain);
331 op->priv->domain = g_strdup (domain);
335 * g_mount_operation_get_password_save:
336 * @op: a #GMountOperation.
338 * Gets the state of saving passwords for the mount operation.
340 * Returns: a #GPasswordSave flag.
344 g_mount_operation_get_password_save (GMountOperation *op)
346 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), G_PASSWORD_SAVE_NEVER);
347 return op->priv->password_save;
351 * g_mount_operation_set_password_save:
352 * @op: a #GMountOperation.
353 * @save: a set of #GPasswordSave flags.
355 * Sets the state of saving passwords for the mount operation.
359 g_mount_operation_set_password_save (GMountOperation *op,
362 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
363 op->priv->password_save = save;
367 * g_mount_operation_get_choice:
368 * @op: a #GMountOperation.
370 * Gets a choice from the mount operation.
372 * Returns: an integer containing an index of the user's choice from
373 * the choice's list, or %0.
376 g_mount_operation_get_choice (GMountOperation *op)
378 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
379 return op->priv->choice;
383 * g_mount_operation_set_choice:
384 * @op: a #GMountOperation.
385 * @choice: an integer.
387 * Sets a default choice for the mount operation.
390 g_mount_operation_set_choice (GMountOperation *op,
393 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
394 op->priv->choice = choice;
398 * g_mount_operation_reply:
399 * @op: a #GMountOperation.
402 * Emits the #GMountOperation::reply signal.
405 g_mount_operation_reply (GMountOperation *op,
408 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
409 g_signal_emit (op, signals[REPLY], 0, abort);