summaryrefslogtreecommitdiff
path: root/gio/gtlsinteraction.c
diff options
context:
space:
mode:
Diffstat (limited to 'gio/gtlsinteraction.c')
-rw-r--r--gio/gtlsinteraction.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/gio/gtlsinteraction.c b/gio/gtlsinteraction.c
index 12aaab3a1..3c8be535a 100644
--- a/gio/gtlsinteraction.c
+++ b/gio/gtlsinteraction.c
@@ -27,6 +27,7 @@
#include "gtlsinteraction.h"
#include "gtlspassword.h"
#include "gasyncresult.h"
+#include "gcancellable.h"
#include "gsimpleasyncresult.h"
#include "gioenumtypes.h"
#include "glibintl.h"
@@ -70,31 +71,45 @@ G_DEFINE_TYPE (GTlsInteraction, g_tls_interaction, G_TYPE_OBJECT);
static GTlsInteractionResult
g_tls_interaction_default_ask_password (GTlsInteraction *interaction,
- GTlsPassword *password)
+ GTlsPassword *password,
+ GCancellable *cancellable,
+ GError **error)
{
- return G_TLS_INTERACTION_UNHANDLED;
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return G_TLS_INTERACTION_FAILED;
+ else
+ return G_TLS_INTERACTION_UNHANDLED;
}
static void
g_tls_interaction_default_ask_password_async (GTlsInteraction *interaction,
GTlsPassword *password,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *res;
+ GError *error = NULL;
res = g_simple_async_result_new (G_OBJECT (interaction), callback, user_data,
g_tls_interaction_default_ask_password);
+ if (g_cancellable_set_error_if_cancelled (cancellable, &error))
+ g_simple_async_result_take_error (res, error);
g_simple_async_result_complete_in_idle (res);
g_object_unref (res);
}
static GTlsInteractionResult
g_tls_interaction_default_ask_password_finish (GTlsInteraction *interaction,
- GAsyncResult *result)
+ GAsyncResult *result,
+ GError **error)
{
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (interaction),
g_tls_interaction_default_ask_password), G_TLS_INTERACTION_UNHANDLED);
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
+ return G_TLS_INTERACTION_FAILED;
+
return G_TLS_INTERACTION_UNHANDLED;
}
@@ -115,6 +130,8 @@ g_tls_interaction_class_init (GTlsInteractionClass *klass)
* g_tls_interaction_ask_password:
* @interaction: a #GTlsInteraction object
* @password: a #GTlsPassword object
+ * @cancellable: an optional #GCancellable cancellation object
+ * @error: an optional location to place an error on failure
*
* This function is normally called by #GTlsConnection or #GTlsDatabase to
* ask the user for a password.
@@ -124,24 +141,35 @@ g_tls_interaction_class_init (GTlsInteractionClass *klass)
* be filled in and then @callback will be called. Alternatively the user may
* abort this password request, which will usually abort the TLS connection.
*
+ * If the interaction is cancelled by the cancellation object, or by the
+ * user then %G_TLS_INTERACTION_ABORTED will be returned. Certain
+ * implementations may not support immediate cancellation.
+ *
* Returns: The status of the ask password interaction.
*
* Since: 2.30
*/
GTlsInteractionResult
g_tls_interaction_ask_password (GTlsInteraction *interaction,
- GTlsPassword *password)
+ GTlsPassword *password,
+ GCancellable *cancellable,
+ GError **error)
{
g_return_val_if_fail (G_IS_TLS_INTERACTION (interaction), G_TLS_INTERACTION_UNHANDLED);
g_return_val_if_fail (G_IS_TLS_PASSWORD (password), G_TLS_INTERACTION_UNHANDLED);
- return G_TLS_INTERACTION_GET_CLASS (interaction)->ask_password (interaction, password);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), G_TLS_INTERACTION_UNHANDLED);
+ return G_TLS_INTERACTION_GET_CLASS (interaction)->ask_password (interaction,
+ password,
+ cancellable,
+ error);
}
/**
* g_tls_interaction_ask_password_async:
* @interaction: a #GTlsInteraction object
* @password: a #GTlsPassword object
- * @callback: will be called when the interaction completes
+ * @cancellable: an optional #GCancellable cancellation object
+ * @callback: (allow-none): will be called when the interaction completes
* @user_data: (allow-none): data to pass to the @callback
*
* This function is normally called by #GTlsConnection or #GTlsDatabase to
@@ -157,18 +185,22 @@ g_tls_interaction_ask_password (GTlsInteraction *interaction,
* g_tls_interaction_ask_password_finish() to get the status of the user
* interaction.
*
+ * Certain implementations may not support immediate cancellation.
+ *
* Since: 2.30
*/
void
g_tls_interaction_ask_password_async (GTlsInteraction *interaction,
GTlsPassword *password,
+ GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (G_IS_TLS_INTERACTION (interaction));
g_return_if_fail (G_IS_TLS_PASSWORD (password));
- g_return_if_fail (callback != NULL);
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
G_TLS_INTERACTION_GET_CLASS (interaction)->ask_password_async (interaction, password,
+ cancellable,
callback, user_data);
}
@@ -176,6 +208,7 @@ g_tls_interaction_ask_password_async (GTlsInteraction *interaction,
* g_tls_interaction_ask_password_finish:
* @interaction: a #GTlsInteraction object
* @result: the result passed to the callback
+ * @error: an optional location to place an error on failure
*
* Complete an ask password user interaction request. This should be once
* the g_tls_interaction_ask_password() completion callback is called.
@@ -183,15 +216,21 @@ g_tls_interaction_ask_password_async (GTlsInteraction *interaction,
* If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsPassword passed
* to g_tls_interaction_ask_password() will have its password filled in.
*
+ * If the interaction is cancelled by the cancellation object, or by the
+ * user then %G_TLS_INTERACTION_ABORTED will be returned.
+ *
* Returns: The status of the ask password interaction.
*
* Since: 2.30
*/
GTlsInteractionResult
g_tls_interaction_ask_password_finish (GTlsInteraction *interaction,
- GAsyncResult *result)
+ GAsyncResult *result,
+ GError **error)
{
g_return_val_if_fail (G_IS_TLS_INTERACTION (interaction), G_TLS_INTERACTION_UNHANDLED);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), G_TLS_INTERACTION_UNHANDLED);
- return G_TLS_INTERACTION_GET_CLASS (interaction)->ask_password_finish (interaction, result);
+ return G_TLS_INTERACTION_GET_CLASS (interaction)->ask_password_finish (interaction,
+ result,
+ error);
}