void seahorse_operation_mark_progress_full (SeahorseOperation *op, const gchar *message, gdouble current, gdouble total) { if (current > total) current = total; seahorse_operation_mark_progress (op, message, total <= 0 ? -1 : current / 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 SeahorseOperation* seahorse_hkp_source_search (SeahorseSource *src, const gchar *match) { SeahorseHKPOperation *hop; SoupMessage *message; GHashTable *form; gchar *t; SoupURI *uri; gchar hexfpr[11]; g_assert (SEAHORSE_IS_SOURCE (src)); g_assert (SEAHORSE_IS_HKP_SOURCE (src)); hop = setup_hkp_operation (SEAHORSE_HKP_SOURCE (src)); uri = get_http_server_uri (src, "/pks/lookup"); g_return_val_if_fail (uri, FALSE); form = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert (form, "op", "index"); if (is_hex_keyid (match)) { strncpy (hexfpr, "0x", 3); strncpy (hexfpr + 2, match, 9); g_hash_table_insert (form, "search", hexfpr); } else g_hash_table_insert (form, "search", (char *)match); soup_uri_set_query_from_form (uri, form); g_hash_table_destroy (form); message = soup_message_new_from_uri ("GET", uri); soup_session_queue_message (hop->session, message, (SoupSessionCallback)refresh_callback, hop); hop->total = hop->requests = 1; t = g_strdup_printf (_("Searching for keys on: %s"), uri->host); seahorse_operation_mark_progress (SEAHORSE_OPERATION (hop), t, -1); g_free (t); soup_uri_free (uri); seahorse_server_source_take_operation (SEAHORSE_SERVER_SOURCE (src), SEAHORSE_OPERATION (hop)); g_object_ref (hop); return SEAHORSE_OPERATION (hop); }
static void process_line (SeahorseOperation *op, const gchar *line) { gchar **args = g_strsplit_set (line, "\n ", 3); gdouble fract; gchar *e, *message = NULL; if (!args[0]) g_warning ("invalid progress line"); else if (g_ascii_strcasecmp (args[0], CMD_BLOCK) == 0) progress_block = TRUE; else if (g_ascii_strcasecmp (args[0], CMD_UNBLOCK) == 0) { progress_block = FALSE; g_timeout_add (PROGRESS_DELAY, (GSourceFunc)progress_show, op); } else if (g_ascii_strcasecmp (args[0], CMD_PROGRESS) == 0) { if (args[1]) { fract = strtod (args[1], &e); if(*e || fract < -1 || fract > 1.0) g_warning ("invalid progress format"); else { if (args[2]) { message = args[2]; g_strstrip (message); } seahorse_operation_mark_progress (op, message && message[0] ? message : NULL, fract); } } } else g_warning ("invalid progress command"); g_strfreev (args); }
static gboolean import_start (SeahorseToolMode *mode, const gchar *uri, gpgme_data_t uridata, SeahorsePGPOperation *pop, GError **err) { size_t size; SeahorseOperation *op; gpgme_error_t gerr; /* Start actual import */ op = SEAHORSE_OPERATION (pop); init_crypt(); buffer = g_malloc0(IMPORT_BUFFER_SIZE); /* Allocate memory for key data */ size = gpgme_data_read (uridata, (void*) buffer, IMPORT_BUFFER_SIZE); if (size > 0) { import_proxy_call = dbus_g_proxy_begin_call (dbus_key_proxy, "ImportKeys", proxy_call_notification, pop, NULL, G_TYPE_STRING, "openpgp", G_TYPE_STRING, buffer, G_TYPE_INVALID); seahorse_operation_mark_start (op); seahorse_operation_mark_progress (op, _("Importing keys ..."), 0.5); } else { g_free (buffer); gerr = gpgme_err_code_from_errno (errno); seahorse_util_gpgme_to_error (gerr, err); return FALSE; } return TRUE; }
static SeahorseOperation* seahorse_hkp_source_export_raw (SeahorseSource *sksrc, GSList *keyids, GOutputStream *output) { SeahorseHKPOperation *hop; SeahorseHKPSource *hsrc; SoupMessage *message; gchar *t; SoupURI *uri; const gchar *fpr; gchar hexfpr[11]; GHashTable *form; guint len; GSList *l; g_return_val_if_fail (SEAHORSE_IS_HKP_SOURCE (sksrc), NULL); g_return_val_if_fail (output == NULL || G_IS_OUTPUT_STREAM (output), NULL); hsrc = SEAHORSE_HKP_SOURCE (sksrc); if (g_slist_length (keyids) == 0) return seahorse_operation_new_complete (NULL); uri = get_http_server_uri (sksrc, "/pks/lookup"); g_return_val_if_fail (uri, FALSE); /* New operation started */ hop = setup_hkp_operation (hsrc); g_object_ref (output); seahorse_operation_mark_result (SEAHORSE_OPERATION (hop), output, g_object_unref); /* prepend the hex prefix (0x) to make keyservers happy */ strncpy(hexfpr, "0x", 3); form = g_hash_table_new (g_str_hash, g_str_equal); for (l = keyids; l; l = g_slist_next (l)) { /* Get the key id and limit it to 8 characters */ fpr = seahorse_pgp_key_calc_rawid (GPOINTER_TO_UINT (l->data)); len = strlen (fpr); if (len > 8) fpr += (len - 8); strncpy(hexfpr + 2, fpr, 9); /* The get key URI */ g_hash_table_insert (form, "op", "get"); g_hash_table_insert (form, "search", (char *)hexfpr); soup_uri_set_query_from_form (uri, form); message = soup_message_new_from_uri ("GET", uri); soup_session_queue_message (hop->session, message, (SoupSessionCallback)get_callback, hop); hop->requests++; } g_hash_table_destroy (form); hop->total = hop->requests; t = g_strdup_printf (_("Connecting to: %s"), uri->host); seahorse_operation_mark_progress (SEAHORSE_OPERATION (hop), t, -1); g_free (t); soup_uri_free (uri); return SEAHORSE_OPERATION (hop); }
static SeahorseOperation* seahorse_hkp_source_import (SeahorseSource *sksrc, GInputStream *input) { SeahorseHKPOperation *hop; SeahorseHKPSource *hsrc; SoupMessage *message; GSList *keydata = NULL; GString *buf = NULL; GHashTable *form; gchar *key, *t; SoupURI *uri; GSList *l; guint len; g_return_val_if_fail (SEAHORSE_IS_HKP_SOURCE (sksrc), NULL); hsrc = SEAHORSE_HKP_SOURCE (sksrc); g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL); g_object_ref (input); for (;;) { buf = g_string_sized_new (2048); len = seahorse_util_read_data_block (buf, input, "-----BEGIN PGP PUBLIC KEY BLOCK-----", "-----END PGP PUBLIC KEY BLOCK-----"); if (len > 0) { keydata = g_slist_prepend (keydata, g_string_free (buf, FALSE)); } else { g_string_free (buf, TRUE); break; } } if (g_slist_length (keydata) == 0) { g_object_unref (input); return seahorse_operation_new_complete (NULL); } /* Figure out the URI we're sending to */ uri = get_http_server_uri (sksrc, "/pks/add"); g_return_val_if_fail (uri, FALSE); /* New operation and away we go */ keydata = g_slist_reverse (keydata); hop = setup_hkp_operation (hsrc); form = g_hash_table_new (g_str_hash, g_str_equal); for (l = keydata; l; l = g_slist_next (l)) { g_assert (l->data != NULL); g_hash_table_insert (form, "keytext", l->data); key = soup_form_encode_urlencoded (form); message = soup_message_new_from_uri ("POST", uri); soup_message_set_request (message, "application/x-www-form-urlencoded", SOUP_MEMORY_TAKE, key, strlen (key)); soup_session_queue_message (hop->session, message, (SoupSessionCallback)send_callback, hop); hop->requests++; } g_hash_table_destroy (form); hop->total = hop->requests; t = g_strdup_printf (_("Connecting to: %s"), uri->host); seahorse_operation_mark_progress (SEAHORSE_OPERATION (hop), t, -1); g_free (t); soup_uri_free (uri); seahorse_util_string_slist_free (keydata); g_object_unref (input); return SEAHORSE_OPERATION (hop); }