Пример #1
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);
}
Пример #2
0
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);
}
Пример #3
0
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);
    	}
}
Пример #4
0
static gboolean
hkp_message_propagate_error (SeahorseHKPSource *self,
                             SoupMessage *message,
                             GError **error)
{
    gchar *server;
    g_autofree gchar *text = NULL;

    if (!SOUP_MESSAGE_IS_ERROR (message))
        return FALSE;

    if (message->status_code == SOUP_STATUS_CANCELLED) {
        g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
                             _("The operation was cancelled"));
        return TRUE;
    }

    g_object_get (self, "key-server", &server, NULL);

    /* Make the body lower case, and no tags */
    text = g_strndup (message->response_body->data, message->response_body->length);
    if (text != NULL) {
        dehtmlize (text);
        seahorse_util_string_lower (text);
    }

    if (text && strstr (text, "no keys"))
        return FALSE; /* not found is not an error */

    if (text && strstr (text, "too many")) {
        g_set_error (error, HKP_ERROR_DOMAIN, 0,
                     _("Search was not specific enough. Server “%s” found too many keys."), server);
    } else {
        g_set_error (error, HKP_ERROR_DOMAIN, message->status_code,
                     _("Couldn’t communicate with server “%s”: %s"),
                     server, message->reason_phrase);
    }

    return TRUE;
}