static void load_integer_value_next_cb (TrackerSparqlCursor *const cursor, GAsyncResult *const result, GTask *const task) { g_autoptr(GError) error = NULL; gboolean const more = tracker_sparql_cursor_next_finish ( cursor, result, &error ); if (!more) { nul_warning ("no more rows to load"); g_task_return_int (task, -1); return; } gint64 const integer = tracker_sparql_cursor_get_integer (cursor, 0); g_task_return_int (task, integer); }
/** * g_tls_interaction_ask_password_async: * @interaction: a #GTlsInteraction object * @password: a #GTlsPassword object * @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 * * Run asynchronous interaction to ask the user for a password. In general, * g_tls_interaction_invoke_ask_password() should be used instead of this * function. * * Derived subclasses usually implement a password prompt, although they may * also choose to provide a password from elsewhere. The @password value will * 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_FAILED will be returned with an error that * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may * not support immediate cancellation. * * 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) { GTlsInteractionClass *klass; GTask *task; g_return_if_fail (G_IS_TLS_INTERACTION (interaction)); g_return_if_fail (G_IS_TLS_PASSWORD (password)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); klass = G_TLS_INTERACTION_GET_CLASS (interaction); if (klass->ask_password_async) { g_return_if_fail (klass->ask_password_finish); (klass->ask_password_async) (interaction, password, cancellable, callback, user_data); } else { task = g_task_new (interaction, cancellable, callback, user_data); g_task_set_source_tag (task, g_tls_interaction_ask_password_async); g_task_return_int (task, G_TLS_INTERACTION_UNHANDLED); g_object_unref (task); } }
static gboolean gvir_input_stream_read_ready(GVirStream *stream, GVirStreamIOCondition cond, void *opaque) { GVirInputStream *input_stream = GVIR_INPUT_STREAM(opaque); GVirInputStreamPrivate *priv = input_stream->priv; GTask *task = priv->task; GCancellable *cancellable = g_task_get_cancellable(task); GError *error = NULL; gssize result; priv->task = NULL; if (!(cond & GVIR_STREAM_IO_CONDITION_READABLE)) { g_warn_if_reached(); g_task_return_new_error(task, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "%s", "Expected stream to be readable"); goto cleanup; } result = gvir_stream_receive(stream, priv->buffer, priv->count, cancellable, &error); if (error != NULL) { if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { g_warn_if_reached(); g_task_return_new_error(task, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "%s", "Expected stream to be readable"); g_error_free (error); } else { g_task_return_error(task, error); } goto cleanup; } g_task_return_int(task, result); cleanup: g_object_unref(task); return FALSE; }
static void ask_password_with_getpass (GTask *task, gpointer object, gpointer task_data, GCancellable *cancellable) { GTlsPassword *password = task_data; GError *error = NULL; g_tls_console_interaction_ask_password (G_TLS_INTERACTION (object), password, cancellable, &error); if (error != NULL) g_task_return_error (task, error); else g_task_return_int (task, G_TLS_INTERACTION_HANDLED); }
static void abrt_p2_task_thread(GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { AbrtP2Task *stask = source_object; GError *error = NULL; gint32 code; ABRT_P2_TASK_ABSTRACT_FUNCTION_CALL(code, run, stask, &error); if (error == NULL) g_task_return_int(task, code); else g_task_return_error(task, error); }
static void write_message_to_stream_thread (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { GOutputStream *output_stream; gssize bytes_written; GError *local_error = NULL; output_stream = task_data; bytes_written = camel_data_wrapper_decode_to_output_stream_sync ( CAMEL_DATA_WRAPPER (source_object), output_stream, cancellable, &local_error); g_output_stream_close (output_stream, cancellable, local_error ? NULL : &local_error); if (local_error != NULL) { g_task_return_error (task, local_error); } else { g_task_return_int (task, bytes_written); } }
static void renew_subscription_thread (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { ipp_attribute_t *attr = NULL; CRSData *subscription_data = task_data; ipp_t *request; ipp_t *response = NULL; gint result = -1; if (g_cancellable_is_cancelled (cancellable)) return; if (subscription_data->id > 0) { request = ippNewRequest (IPP_RENEW_SUBSCRIPTION); ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "/"); ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser ()); ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "notify-subscription-id", subscription_data->id); ippAddInteger (request, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, "notify-lease-duration", subscription_data->lease_duration); response = cupsDoRequest (CUPS_HTTP_DEFAULT, request, "/"); if (response != NULL && ippGetStatusCode (response) <= IPP_OK_CONFLICT) { if ((attr = ippFindAttribute (response, "notify-lease-duration", IPP_TAG_INTEGER)) == NULL) g_debug ("No notify-lease-duration in response!\n"); else if (ippGetInteger (attr, 0) == subscription_data->lease_duration) result = subscription_data->id; } } if (result < 0) { request = ippNewRequest (IPP_CREATE_PRINTER_SUBSCRIPTION); ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, "/"); ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser ()); ippAddStrings (request, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, "notify-events", g_strv_length (subscription_data->events), NULL, (const char * const *) subscription_data->events); ippAddString (request, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, "notify-pull-method", NULL, "ippget"); ippAddString (request, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, "notify-recipient-uri", NULL, "dbus://"); ippAddInteger (request, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, "notify-lease-duration", subscription_data->lease_duration); response = cupsDoRequest (CUPS_HTTP_DEFAULT, request, "/"); if (response != NULL && ippGetStatusCode (response) <= IPP_OK_CONFLICT) { if ((attr = ippFindAttribute (response, "notify-subscription-id", IPP_TAG_INTEGER)) == NULL) g_debug ("No notify-subscription-id in response!\n"); else result = ippGetInteger (attr, 0); } } ippDelete (response); g_task_return_int (task, result); }