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"
34 * SECTION:gmountoperation
35 * @short_description: Authentication methods for mountable locations
37 * #GMountOperation provides a mechanism for authenticating mountable
38 * operations, such as loop mounting files, hard drive partitions or
41 * Mountable GIO backends should implement #GMountOperation if they
42 * require any priviledges or authentication for their volumes to be
43 * mounted (e.g. a hard disk partition or an encrypted filesystem), or
44 * if they are implementing a remote server protocol which requires user
45 * credentials such as FTP or WebDAV.
48 G_DEFINE_TYPE (GMountOperation, g_mount_operation, G_TYPE_OBJECT);
57 static guint signals[LAST_SIGNAL] = { 0 };
59 struct _GMountOperationPrivate {
64 GPasswordSave password_save;
69 g_mount_operation_finalize (GObject *object)
71 GMountOperation *operation;
72 GMountOperationPrivate *priv;
74 operation = G_MOUNT_OPERATION (object);
76 priv = operation->priv;
78 g_free (priv->password);
80 g_free (priv->domain);
82 if (G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize)
83 (*G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize) (object);
87 boolean_handled_accumulator (GSignalInvocationHint *ihint,
89 const GValue *handler_return,
92 gboolean continue_emission;
93 gboolean signal_handled;
95 signal_handled = g_value_get_boolean (handler_return);
96 g_value_set_boolean (return_accu, signal_handled);
97 continue_emission = !signal_handled;
99 return continue_emission;
103 ask_password (GMountOperation *op,
105 const char *default_user,
106 const char *default_domain,
107 GPasswordFlags flags)
113 ask_question (GMountOperation *op,
115 const char *choices[])
121 g_mount_operation_class_init (GMountOperationClass *klass)
123 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
125 g_type_class_add_private (klass, sizeof (GMountOperationPrivate));
127 gobject_class->finalize = g_mount_operation_finalize;
129 klass->ask_password = ask_password;
130 klass->ask_question = ask_question;
133 * GMountOperation::ask-password:
134 * @op: a #GMountOperation requesting a password.
135 * @message: string containing a message to display to the user.
136 * @default_user: string containing the default user name.
137 * @default_domain: string containing the default domain.
138 * @flags: a set of #GPasswordFlags.
140 * Emitted when a mount operation asks the user for a password.
142 signals[ASK_PASSWORD] =
143 g_signal_new (I_("ask_password"),
144 G_TYPE_FROM_CLASS (gobject_class),
146 G_STRUCT_OFFSET (GMountOperationClass, ask_password),
147 boolean_handled_accumulator, NULL,
148 _gio_marshal_BOOLEAN__STRING_STRING_STRING_INT,
150 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
153 * GMountOperation::ask-question:
154 * @op: a #GMountOperation asking a question.
155 * @message: string containing a message to display to the user.
156 * @choices: an array of strings for each possible choice.
158 * Emitted when asking the user a question and gives a list of choices for the
159 * user to choose from.
161 signals[ASK_QUESTION] =
162 g_signal_new (I_("ask_question"),
163 G_TYPE_FROM_CLASS (gobject_class),
165 G_STRUCT_OFFSET (GMountOperationClass, ask_question),
166 boolean_handled_accumulator, NULL,
167 _gio_marshal_BOOLEAN__STRING_POINTER,
169 G_TYPE_STRING, G_TYPE_POINTER);
172 * GMountOperation::reply:
173 * @op: a #GMountOperation.
174 * @abort: a gboolean indicating %TRUE if the operation was aborted.
176 * Emitted when the user has replied to the mount operation.
179 g_signal_new (I_("reply"),
180 G_TYPE_FROM_CLASS (gobject_class),
182 G_STRUCT_OFFSET (GMountOperationClass, reply),
184 g_cclosure_marshal_VOID__BOOLEAN,
190 g_mount_operation_init (GMountOperation *operation)
192 operation->priv = G_TYPE_INSTANCE_GET_PRIVATE (operation,
193 G_TYPE_MOUNT_OPERATION,
194 GMountOperationPrivate);
198 * g_mount_operation_new:
200 * Creates a new mount operation.
202 * Returns: a #GMountOperation.
205 g_mount_operation_new (void)
207 return g_object_new (G_TYPE_MOUNT_OPERATION, NULL);
211 * g_mount_operation_get_username
212 * @op: a #GMountOperation.
214 * Get the user name from the mount operation.
216 * Returns: a string containing the user name.
219 g_mount_operation_get_username (GMountOperation *op)
221 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
222 return op->priv->user;
226 * g_mount_operation_set_username:
227 * @op: a #GMountOperation.
228 * @username: input username.
230 * Sets the user name within @op to @username.
234 g_mount_operation_set_username (GMountOperation *op,
235 const char *username)
237 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
238 g_free (op->priv->user);
239 op->priv->user = g_strdup (username);
243 * g_mount_operation_get_password:
244 * @op: a #GMountOperation.
246 * Gets a password from the mount operation.
248 * Returns: a string containing the password within @op.
251 g_mount_operation_get_password (GMountOperation *op)
253 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
254 return op->priv->password;
258 * g_mount_operation_set_password:
259 * @op: a #GMountOperation.
260 * @password: password to set.
262 * Sets the mount operation's password to @password.
266 g_mount_operation_set_password (GMountOperation *op,
267 const char *password)
269 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
270 g_free (op->priv->password);
271 op->priv->password = g_strdup (password);
275 * g_mount_operation_get_anonymous:
276 * @op: a #GMountOperation.
278 * Check to see whether the mount operation is being used
279 * for an anonymous user.
281 * Returns: %TRUE if mount operation is anonymous.
284 g_mount_operation_get_anonymous (GMountOperation *op)
286 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
287 return op->priv->anonymous;
291 * g_mount_operation_set_anonymous:
292 * @op: a #GMountOperation.
293 * @anonymous: boolean value.
295 * Sets the mount operation to use an anonymous user if @anonymous is %TRUE.
298 g_mount_operation_set_anonymous (GMountOperation *op,
301 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
302 op->priv->anonymous = anonymous;
306 * g_mount_operation_get_domain:
307 * @op: a #GMountOperation.
309 * Gets the domain of the mount operation.
311 * Returns: a string set to the domain.
314 g_mount_operation_get_domain (GMountOperation *op)
316 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
317 return op->priv->domain;
321 * g_mount_operation_set_domain:
322 * @op: a #GMountOperation.
323 * @domain: the domain to set.
325 * Sets the mount operation's domain.
328 g_mount_operation_set_domain (GMountOperation *op,
331 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
332 g_free (op->priv->domain);
333 op->priv->domain = g_strdup (domain);
337 * g_mount_operation_get_password_save:
338 * @op: a #GMountOperation.
340 * Gets the state of saving passwords for the mount operation.
342 * Returns: a #GPasswordSave flag.
346 g_mount_operation_get_password_save (GMountOperation *op)
348 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), G_PASSWORD_SAVE_NEVER);
349 return op->priv->password_save;
353 * g_mount_operation_set_password_save:
354 * @op: a #GMountOperation.
355 * @save: a set of #GPasswordSave flags.
357 * Sets the state of saving passwords for the mount operation.
361 g_mount_operation_set_password_save (GMountOperation *op,
364 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
365 op->priv->password_save = save;
369 * g_mount_operation_get_choice:
370 * @op: a #GMountOperation.
372 * Gets a choice from the mount operation.
374 * Returns: an integer containing an index of the user's choice from
375 * the choice's list, or %0.
378 g_mount_operation_get_choice (GMountOperation *op)
380 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
381 return op->priv->choice;
385 * g_mount_operation_set_choice:
386 * @op: a #GMountOperation.
387 * @choice: an integer.
389 * Sets a default choice for the mount operation.
392 g_mount_operation_set_choice (GMountOperation *op,
395 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
396 op->priv->choice = choice;
400 * g_mount_operation_reply:
401 * @op: a #GMountOperation.
404 * Emits the #GMountOperation::reply signal.
407 g_mount_operation_reply (GMountOperation *op,
410 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
411 g_signal_emit (op, signals[REPLY], 0, abort);
414 #define __G_MOUNT_OPERATION_C__
415 #include "gioaliasdef.c"