static void get_callback (SoupSession *session, SoupMessage *msg, SeahorseHKPOperation *hop) { GError *err = NULL; const gchar *start; const gchar *end; GOutputStream *output; const gchar *text; gboolean ret; guint len; gsize written; if (hop->cancelling) return; if (SOUP_MESSAGE_IS_ERROR (msg)) { fail_hkp_operation (hop, msg, NULL); return; } end = text = msg->response_body->data; len = msg->response_body->length; for (;;) { len -= end - text; text = end; if(!detect_key (text, len, &start, &end)) break; /* Any key blocks get written to our result data */ output = seahorse_operation_get_result (SEAHORSE_OPERATION (hop)); g_return_if_fail (G_IS_OUTPUT_STREAM (output)); ret = g_output_stream_write_all (output, start, end - start, &written, NULL, &err) && g_output_stream_write_all (output, "\n", 1, &written, NULL, &err) && g_output_stream_flush (output, NULL, &err); if (!ret) { seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, err); return; } } if (--hop->requests <= 0) { output = seahorse_operation_get_result (SEAHORSE_OPERATION (hop)); g_return_if_fail (G_IS_OUTPUT_STREAM (output)); g_output_stream_close (output, NULL, &err); seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, err); } else { seahorse_operation_mark_progress_full (SEAHORSE_OPERATION (hop), _("Retrieving keys..."), hop->requests, hop->total); } }
static void seahorse_pkcs11_mark_complete (SeahorseOperation *self, GError *error) { SeahorseOperation *operation = SEAHORSE_OPERATION (self); if (error == NULL) seahorse_operation_mark_done (operation, FALSE, NULL); else if (error->code == CKR_FUNCTION_CANCELED) seahorse_operation_mark_done (operation, TRUE, NULL); else seahorse_operation_mark_done (operation, FALSE, error); g_clear_error (&error); }
static int progress_main (int argc, char* argv[]) { SeahorseOperation *op; GIOChannel *io; gtk_init (&argc, &argv); op = g_object_new (SEAHORSE_TYPE_OPERATION, NULL); seahorse_operation_mark_start (op); /* Watch for done (ie: in this case only cancel) */ g_signal_connect (op, "done", G_CALLBACK (done_handler), NULL); /* Hook up an IO channel to stdin */ io = g_io_channel_unix_new (0); g_io_channel_set_encoding (io, NULL, NULL); g_io_add_watch (io, G_IO_IN | G_IO_HUP, (GIOFunc)io_handler, op); progress_visible = FALSE; progress_title = argc > 2 ? argv[2] : NULL; g_timeout_add (PROGRESS_DELAY, (GSourceFunc)progress_show, op); gtk_main (); if (seahorse_operation_is_running (op)) seahorse_operation_mark_done (op, FALSE, NULL); return 0; }
static void send_callback (SoupSession *session, SoupMessage *msg, SeahorseHKPOperation *hop) { gchar *errmsg; if (hop->cancelling) return; if (SOUP_MESSAGE_IS_ERROR (msg)) { fail_hkp_operation (hop, msg, NULL); return; } errmsg = get_send_result (msg->response_body->data); if (errmsg) { fail_hkp_operation (hop, NULL, errmsg); g_free (errmsg); return; } /* A successful status from the server is all we want in this case */ if (--hop->requests <= 0) seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, NULL); else seahorse_operation_mark_progress_full (SEAHORSE_OPERATION (hop), _("Uploading keys..."), hop->requests, hop->total); }
static void refresh_callback (SoupSession *session, SoupMessage *msg, SeahorseHKPOperation *hop) { GList *keys, *k; if (hop->cancelling) return; if (SOUP_MESSAGE_IS_ERROR (msg)) { fail_hkp_operation (hop, msg, NULL); return; } keys = parse_hkp_index (msg->response_body->data); for (k = keys; k; k = g_list_next (k)) add_key (hop->hsrc, SEAHORSE_PGP_KEY (k->data)); seahorse_object_list_free (keys); if (--hop->requests <= 0) seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, NULL); else seahorse_operation_mark_progress_full (SEAHORSE_OPERATION (hop), _("Searching for keys..."), hop->requests, hop->total); }
static void proxy_call_notification (DBusGProxy *proxy, DBusGProxyCall *call_id, void *data) { SeahorseOperation *op; op = SEAHORSE_OPERATION (data); seahorse_operation_mark_progress (op, _("Import is complete"), 1); seahorse_operation_mark_done (op, FALSE, NULL); g_free (buffer); }
static void seahorse_hkp_operation_cancel (SeahorseOperation *operation) { SeahorseHKPOperation *hop; g_assert (SEAHORSE_IS_HKP_OPERATION (operation)); hop = SEAHORSE_HKP_OPERATION (operation); g_return_if_fail (seahorse_operation_is_running (operation)); hop->cancelling = TRUE; if (hop->session != NULL) soup_session_abort (hop->session); seahorse_operation_mark_done (operation, TRUE, NULL); }
void seahorse_operation_cancel (SeahorseOperation *op) { SeahorseOperationClass *klass; g_return_if_fail (SEAHORSE_IS_OPERATION (op)); g_return_if_fail (op->is_running); g_object_ref (op); klass = SEAHORSE_OPERATION_GET_CLASS (op); /* A derived operation exists */ if (klass->cancel) (*klass->cancel) (op); /* No derived operation exists */ else seahorse_operation_mark_done (op, TRUE, NULL); g_object_unref (op); }
/* Cancels operation and marks the HKP operation as failed */ static void fail_hkp_operation (SeahorseHKPOperation *hop, SoupMessage *msg, const gchar *text) { gchar *t, *server; GError *error = NULL; if (!seahorse_operation_is_running (SEAHORSE_OPERATION (hop))) return; g_object_get (hop->hsrc, "key-server", &server, NULL); if (text) { error = g_error_new (HKP_ERROR_DOMAIN, msg ? msg->status_code : 0, "%s", text); } else if (msg) { /* Make the body lower case, and no tags */ t = g_strndup (msg->response_body->data, msg->response_body->length); if (t != NULL) { dehtmlize (t); seahorse_util_string_lower (t); } if (t && strstr (t, "no keys")) error = NULL; /* not found is not an error */ else if (t && strstr (t, "too many")) error = g_error_new (HKP_ERROR_DOMAIN, 0, _("Search was not specific enough. Server '%s' found too many keys."), server); else error = g_error_new (HKP_ERROR_DOMAIN, msg->status_code, _("Couldn't communicate with server '%s': %s"), server, msg->reason_phrase); g_free (t); } else { /* We should always have msg or text */ g_assert (FALSE); } seahorse_operation_mark_done (SEAHORSE_OPERATION (hop), FALSE, error); g_free (server); }