Ejemplo n.º 1
0
static void
multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
{
    GMainLoop *loop = (GMainLoop*)data;
    SoupRequest *request = SOUP_REQUEST (source);
    GError *error = NULL;
    GInputStream *in;
    SoupMessage *message;

    in = soup_request_send_finish (request, res, &error);
    message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    multipart = soup_multipart_input_stream_new (message, in);
    g_object_unref (message);
    g_object_unref (in);

    if (error) {
        debug_printf (1, "  failed send: %s\n", error->message);
        errors++;

        g_main_loop_quit (loop);
        return;
    }

    if (g_object_get_data (source, "multipart-small-reads"))
        g_object_set_data (G_OBJECT (multipart), "multipart-small-reads", GINT_TO_POINTER(1));

    soup_multipart_input_stream_next_part_async (multipart, G_PRIORITY_DEFAULT, NULL,
            multipart_next_part_cb, data);
}
Ejemplo n.º 2
0
static void
ear_one_completed (GObject *source, GAsyncResult *result, gpointer user_data)
{
	GError *error = NULL;

	debug_printf (2, "  Request 1 completed\n");
	if (soup_request_send_finish (SOUP_REQUEST (source), result, &error)) {
		debug_printf (1, "  Request 1 succeeded?\n");
		errors++;
	} else if (!g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_CANCELLED)) {
		debug_printf (1, "  Unexpected error on Request 1: %s\n",
			      error->message);
		errors++;
	}
	g_clear_error (&error);
}
Ejemplo n.º 3
0
static void
ear_three_completed (GObject *source, GAsyncResult *result, gpointer loop)
{
	GError *error = NULL;

	debug_printf (2, "  Request 3 completed\n");
	if (soup_request_send_finish (SOUP_REQUEST (source), result, &error)) {
		debug_printf (1, "  Request 3 succeeded?\n");
		errors++;
	} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
		debug_printf (1, "  Unexpected error on Request 3: %s\n",
			      error->message);
		errors++;
	}
	g_clear_error (&error);

	g_main_loop_quit (loop);
}
Ejemplo n.º 4
0
static void
gdav_request_send_cb (GObject *source_object,
                      GAsyncResult *result,
                      gpointer user_data)
{
	GInputStream *input_stream;
	GOutputStream *output_stream;
	GTask *task = G_TASK (user_data);
	GError *local_error = NULL;

	input_stream = soup_request_send_finish (
		SOUP_REQUEST (source_object), result, &local_error);

	/* Sanity check */
	g_warn_if_fail (
		((input_stream != NULL) && (local_error == NULL)) ||
		((input_stream == NULL) && (local_error != NULL)));

	if (input_stream != NULL) {
		GCancellable *cancellable;
		GOutputStream *output_stream;

		cancellable = g_task_get_cancellable (task);

		output_stream = g_memory_output_stream_new_resizable ();

		/* Don't close the input stream here, we'll
		 * need to perform some post-processing first. */
		g_output_stream_splice_async (
			output_stream, input_stream,
			G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
			G_PRIORITY_DEFAULT, cancellable,
			gdav_request_splice_cb,
			g_object_ref (task));

		g_object_unref (output_stream);
	}

	if (local_error != NULL) {
		g_task_return_error (task, local_error);
	}

	g_object_unref (task);
}
Ejemplo n.º 5
0
static void
cur_two_completed (GObject *source, GAsyncResult *result, gpointer loop)
{
	SoupRequest *two = SOUP_REQUEST (source);
	GError *error = NULL;

	debug_printf (2, "  Request 2 completed\n");
	if (soup_request_send_finish (two, result, &error)) {
		debug_printf (1, "  Request 2 succeeded?\n");
		errors++;
	} else if (!g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_CONNECT)) {
		debug_printf (1, "  Unexpected error on Request 2: %s\n",
			      error->message);
		errors++;
	}
	g_clear_error (&error);

	g_idle_add (cur_idle_quit, loop); 
}
Ejemplo n.º 6
0
static void
cur_one_completed (GObject *source, GAsyncResult *result, gpointer session)
{
	SoupRequest *one = SOUP_REQUEST (source);
	GError *error = NULL;

	debug_printf (2, "  Request 1 completed\n");
	if (soup_request_send_finish (one, result, &error)) {
		debug_printf (1, "  Request 1 succeeded?\n");
		errors++;
	} else if (!g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_CONNECT)) {
		debug_printf (1, "  Unexpected error on Request 1: %s\n",
			      error->message);
		errors++;
	}
	g_clear_error (&error);

	g_object_unref (session);
}
Ejemplo n.º 7
0
/*
 * our multipart handler callback
 * If we make an invalid request (like trying to cancel when no recipe is running)
 * then status_code will not be 200 and we will exit out after propagating the error
 * to our own GError
 */
static void
request_sent_cb (GObject *source, GAsyncResult *async_result, gpointer user_data)
{

    //g_print ("request_sent_cb\n");
    MultiPartData *multipart_data = (MultiPartData *) user_data;

    SoupRequest *request = SOUP_REQUEST (source);
    GInputStream *in = soup_request_send_finish (request,
                                                 async_result,
                                                 &multipart_data->error);
    if (multipart_data->error) {
        g_object_unref(request);
        multipart_destroy (multipart_data);
        return;
    }

    SoupMessage *message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    g_object_unref(request);

    if (message->status_code != SOUP_STATUS_OK) {
        g_set_error_literal(&multipart_data->error,
                            RESTRAINT_ERROR,
                            message->status_code,
                            message->reason_phrase);
        multipart_destroy (multipart_data);
        return;
    }

    multipart_data->multipart = soup_multipart_input_stream_new (message,
                                                                 in);
    g_object_unref (message);
    g_object_unref (in);

    soup_multipart_input_stream_next_part_async (multipart_data->multipart,
                                                 G_PRIORITY_DEFAULT,
                                                 multipart_data->cancellable,
                                                 next_part_cb,
                                                 user_data);
}
Ejemplo n.º 8
0
static void
no_multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
{
    GMainLoop *loop = (GMainLoop*)data;
    SoupRequest *request = SOUP_REQUEST (source);
    GError *error = NULL;
    GInputStream* in;

    in = soup_request_send_finish (request, res, &error);

    if (error) {
        debug_printf (1, "  failed send: %s\n", error->message);
        errors++;

        g_main_loop_quit (loop);
        return;
    }

    g_input_stream_read_async (in, buffer, READ_BUFFER_SIZE,
                               G_PRIORITY_DEFAULT, NULL,
                               read_cb, data);
}
Ejemplo n.º 9
0
GInputStream *
soup_test_request_send (SoupRequest   *req,
			GCancellable  *cancellable,
			GError       **error)
{
	AsyncAsSyncData data;
	GInputStream *stream;

	if (SOUP_IS_SESSION_SYNC (soup_request_get_session (req)))
		return soup_request_send (req, cancellable, error);

	data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);

	soup_request_send_async (req, cancellable, async_as_sync_callback, &data);
	g_main_loop_run (data.loop);

	stream = soup_request_send_finish (req, data.result, error);

	g_main_loop_unref (data.loop);
	g_object_unref (data.result);

	return stream;
}
Ejemplo n.º 10
0
static void
reply_cb (GObject *source,
          GAsyncResult *res,
          gpointer user_data)
{
  GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
  struct request_res *rr = g_simple_async_result_get_op_res_gpointer (result);

  GError *error = NULL;
  GInputStream *in = soup_request_send_finish (rr->request, res, &error);

  if (error) {
    g_simple_async_result_set_error (result, GRL_NET_WC_ERROR,
                                     GRL_NET_WC_ERROR_UNAVAILABLE,
                                     _("Data not available"));
    g_error_free (error);

    g_simple_async_result_complete (result);
    g_object_unref (result);
    return;
  }

  rr->length = soup_request_get_content_length (rr->request) + 1;
  if (rr->length == 1)
    rr->length = 50 * 1024;

  rr->buffer = g_new (gchar, rr->length);

  g_input_stream_read_async (in,
                             rr->buffer,
                             rr->length,
                             G_PRIORITY_DEFAULT,
                             NULL,
                             read_async_cb,
                             user_data);
}
Ejemplo n.º 11
0
static void
sync_multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
{
    GMainLoop *loop = (GMainLoop*)data;
    SoupRequest *request = SOUP_REQUEST (source);
    GError *error = NULL;
    GInputStream *in;
    SoupMessage *message;
    char buffer[READ_BUFFER_SIZE];
    gsize bytes_read;

    in = soup_request_send_finish (request, res, &error);
    message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
    multipart = soup_multipart_input_stream_new (message, in);
    g_object_unref (message);
    g_object_unref (in);

    if (error) {
        debug_printf (1, "  failed send: %s\n", error->message);
        errors++;

        g_main_loop_quit (loop);
        return;
    }

    while (TRUE) {
        in = soup_multipart_input_stream_next_part (multipart, NULL, &error);

        if (error) {
            debug_printf (1, "  failed sync next part: %s\n", error->message);
            errors++;
            g_clear_error (&error);
            break;
        }

        if (!in)
            break;

        check_headers (multipart, passes);

        g_input_stream_read_all (in, (void*)buffer, sizeof (buffer), &bytes_read, NULL, &error);

        if (error) {
            debug_printf (1, "  failed sync read: %s\n", error->message);
            errors++;
            g_clear_error (&error);
            g_object_unref (in);
            break;
        }

        check_read (bytes_read, passes);

        passes++;
        g_object_unref (in);
    }

    if (passes != 4) {
        debug_printf (1, "  expected 4 parts, got %u\n", passes);
        errors++;
    }

    g_main_loop_quit (loop);
    g_object_unref (multipart);
}