static gboolean soup_request_initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { SoupRequest *request = SOUP_REQUEST (initable); gboolean ok; if (!request->priv->uri) { g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, _("No URI provided")); return FALSE; } ok = SOUP_REQUEST_GET_CLASS (initable)-> check_uri (request, request->priv->uri, error); if (!ok && error && !*error) { char *uri_string = soup_uri_to_string (request->priv->uri, FALSE); g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, _("Invalid '%s' URI: %s"), request->priv->uri->scheme, uri_string); g_free (uri_string); } return ok; }
static gboolean soup_request_file_ensure_file (SoupRequestFile *file, GCancellable *cancellable, GError **error) { SoupURI *uri; char *decoded_path; if (file->priv->gfile) return TRUE; uri = soup_request_get_uri (SOUP_REQUEST (file)); decoded_path = soup_uri_decode (uri->path); #ifdef G_OS_WIN32 windowsify_file_uri_path (decoded_path); #endif if (uri->scheme == SOUP_URI_SCHEME_RESOURCE) { char *uri_str; uri_str = g_strdup_printf ("resource://%s", decoded_path); file->priv->gfile = g_file_new_for_uri (uri_str); g_free (uri_str); } else file->priv->gfile = g_file_new_for_path (decoded_path); g_free (decoded_path); return TRUE; }
static void gdav_request_send (SoupRequestHTTP *request, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; SoupMessage *message; /* This is an internal wrapper for soup_request_send_async(). * The input stream contents are written to the SoupMessage * response body to ensure a SoupLogger sees it. */ task = g_task_new (request, cancellable, callback, user_data); message = soup_request_http_get_message (request); g_task_set_task_data (task, message, g_object_unref); soup_request_send_async ( SOUP_REQUEST (request), cancellable, gdav_request_send_cb, g_object_ref (task)); g_object_unref (task); }
static gboolean soup_request_file_ensure_file (SoupRequestFile *file, GCancellable *cancellable, GError **error) { SoupURI *uri; if (file->priv->gfile) return TRUE; uri = soup_request_get_uri (SOUP_REQUEST (file)); if (uri->scheme == SOUP_URI_SCHEME_FILE) { gchar *decoded_uri = soup_uri_decode (g_strdup (uri->path)); if (decoded_uri) { file->priv->gfile = g_file_new_for_path (decoded_uri); g_free (decoded_uri); } return TRUE; } g_set_error (error, SOUP_REQUESTER_ERROR, SOUP_REQUESTER_ERROR_UNSUPPORTED_URI_SCHEME, _("Unsupported URI scheme '%s'"), uri->scheme); return FALSE; }
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); }
static void soup_request_finalize (GObject *object) { SoupRequest *request = SOUP_REQUEST (object); g_clear_pointer (&request->priv->uri, soup_uri_free); g_clear_object (&request->priv->session); G_OBJECT_CLASS (soup_request_parent_class)->finalize (object); }
void WebSoupRequestManager::send(GTask* task) { WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(task)); SoupRequest* soupRequest = SOUP_REQUEST(request); GUniquePtr<char> uriString(soup_uri_to_string(soup_request_get_uri(soupRequest), FALSE)); uint64_t requestID = generateSoupRequestID(); m_requestMap.set(requestID, adoptPtr(new WebSoupRequestAsyncData(task, request))); uint64_t initiatingPageID = WebCore::ResourceHandle::getSoupRequestInitiatingPageID(soupRequest); m_process->parentProcessConnection()->send(Messages::WebPageProxy::DidReceiveURIRequest(String::fromUTF8(uriString.get()), requestID), initiatingPageID); }
void WebSoupRequestManager::send(GSimpleAsyncResult* result, GCancellable* cancellable) { GRefPtr<WebKitSoupRequestGeneric> request = adoptGRef(WEBKIT_SOUP_REQUEST_GENERIC(g_async_result_get_source_object(G_ASYNC_RESULT(result)))); SoupRequest* soupRequest = SOUP_REQUEST(request.get()); GOwnPtr<char> uriString(soup_uri_to_string(soup_request_get_uri(soupRequest), FALSE)); uint64_t requestID = generateSoupRequestID(); m_requestMap.set(requestID, adoptPtr(new WebSoupRequestAsyncData(result, request.get(), cancellable))); uint64_t initiatingPageID = WebCore::ResourceHandle::getSoupRequestInitiatingPageID(soupRequest); m_process->connection()->send(Messages::WebPageProxy::DidReceiveURIRequest(String::fromUTF8(uriString.get()), requestID), initiatingPageID); }
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); }
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); }
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); }
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); }
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); }
void CustomProtocolManagerImpl::didLoadData(uint64_t customProtocolID, const IPC::DataReference& dataReference) { WebSoupRequestAsyncData* data = m_customProtocolMap.get(customProtocolID); // The data might have been removed from the request map if a previous chunk failed // and a new message was sent by the UI process before being notified about the failure. if (!data) return; if (!data->stream) { GRefPtr<GTask> task = data->releaseTask(); ASSERT(task.get()); goffset soupContentLength = soup_request_get_content_length(SOUP_REQUEST(g_task_get_source_object(task.get()))); uint64_t contentLength = soupContentLength == -1 ? 0 : static_cast<uint64_t>(soupContentLength); if (!dataReference.size()) { // Empty reply, just create and empty GMemoryInputStream. data->stream = g_memory_input_stream_new(); } else if (dataReference.size() == contentLength) { // We don't expect more data, so we can just create a GMemoryInputStream with all the data. data->stream = g_memory_input_stream_new_from_data(g_memdup(dataReference.data(), dataReference.size()), contentLength, g_free); } else { // We expect more data chunks from the UI process. data->stream = webkitSoupRequestInputStreamNew(contentLength); webkitSoupRequestInputStreamAddData(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data->stream.get()), dataReference.data(), dataReference.size()); } g_task_return_pointer(task.get(), data->stream.get(), g_object_unref); return; } if (data->requestFailed()) { // ResourceRequest failed or it was cancelled. It doesn't matter here the error or if it was cancelled, // because that's already handled by the resource handle client, we just want to notify the UI process // to stop reading data from the user input stream. If UI process already sent all the data we simply // finish silently. if (!webkitSoupRequestInputStreamFinished(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data->stream.get()))) m_childProcess->send(Messages::CustomProtocolManagerProxy::StopLoading(customProtocolID), 0); return; } webkitSoupRequestInputStreamAddData(WEBKIT_SOUP_REQUEST_INPUT_STREAM(data->stream.get()), dataReference.data(), dataReference.size()); }
static void soup_request_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { SoupRequest *request = SOUP_REQUEST (object); switch (prop_id) { case PROP_URI: g_value_set_boxed (value, request->priv->uri); break; case PROP_SESSION: g_value_set_object (value, request->priv->session); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void soup_request_file_send_async_thread (GSimpleAsyncResult *res, GObject *object, GCancellable *cancellable) { GInputStream *stream; SoupRequest *request; GError *error = NULL; request = SOUP_REQUEST (object); stream = soup_request_file_send (request, cancellable, &error); if (stream == NULL) { g_simple_async_result_set_from_error (res, error); g_error_free (error); } else { g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref); } }
/* * 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); }
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); }
static gboolean myopen(FetchData *fetch_data, GError **error) { g_return_val_if_fail(fetch_data != NULL, FALSE); g_return_val_if_fail(error == NULL || *error == NULL, FALSE); SoupRequestHTTP *reqh; GError *tmp_error = NULL; reqh = soup_session_request_http_uri (session, "GET", fetch_data->url, NULL); fetch_data->istream = soup_request_send (SOUP_REQUEST (reqh), NULL, &tmp_error); if (tmp_error != NULL) { gchar *url = soup_uri_to_string (fetch_data->url, TRUE); g_propagate_prefixed_error(error, tmp_error, "While connecting to %s: ", url); g_free (url); return FALSE; } g_object_unref (reqh); return TRUE; }
static gboolean send_async_cb (gpointer data) { GSimpleAsyncResult *simple; SoupSession *session; SendAsyncHelper *helper = (SendAsyncHelper *)data; session = soup_request_get_session (SOUP_REQUEST (helper->http)); simple = g_simple_async_result_new (G_OBJECT (helper->http), helper->callback, helper->user_data, soup_request_http_send_async); g_simple_async_result_set_op_res_gpointer (simple, helper->httpstream, g_object_unref); /* Update message status */ soup_message_set_status (helper->http->priv->msg, SOUP_STATUS_OK); /* Issue signals */ soup_message_got_headers (helper->http->priv->msg); if (soup_session_get_feature_for_message (session, SOUP_TYPE_CONTENT_SNIFFER, helper->http->priv->msg)) { const char *content_type = soup_message_headers_get_content_type (helper->http->priv->msg->response_headers, NULL); soup_message_content_sniffed (helper->http->priv->msg, content_type, NULL); } g_simple_async_result_complete (simple); soup_message_finished (helper->http->priv->msg); g_object_unref (simple); g_object_unref (helper->http); g_slice_free (SendAsyncHelper, helper); return FALSE; }
static void soup_request_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { SoupRequest *request = SOUP_REQUEST (object); switch (prop_id) { case PROP_URI: if (request->priv->uri) soup_uri_free (request->priv->uri); request->priv->uri = g_value_dup_boxed (value); break; case PROP_SESSION: if (request->priv->session) g_object_unref (request->priv->session); request->priv->session = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static char * do_request (SoupSession *session, SoupURI *base_uri, const char *method, const char *path, ...) { SoupRequestHTTP *req; SoupMessage *msg; GInputStream *stream; SoupURI *uri; va_list ap; const char *header, *value; char buf[256]; gsize nread; GError *error = NULL; last_request_validated = last_request_hit_network = FALSE; uri = soup_uri_new_with_base (base_uri, path); req = soup_session_request_http_uri (session, method, uri, NULL); soup_uri_free (uri); msg = soup_request_http_get_message (req); va_start (ap, path); while ((header = va_arg (ap, const char *))) { value = va_arg (ap, const char *); soup_message_headers_append (msg->request_headers, header, value); } g_object_unref (msg); stream = soup_test_request_send (SOUP_REQUEST (req), NULL, &error); if (!stream) { debug_printf (1, " could not send request: %s\n", error->message); g_error_free (error); g_object_unref (req); return NULL; } last_request_hit_network = is_network_stream (stream); g_input_stream_read_all (stream, buf, sizeof (buf), &nread, NULL, &error); if (error) { debug_printf (1, " could not read response: %s\n", error->message); g_clear_error (&error); } soup_test_request_close_stream (SOUP_REQUEST (req), stream, NULL, &error); if (error) { debug_printf (1, " could not close stream: %s\n", error->message); g_clear_error (&error); } g_object_unref (stream); g_object_unref (req); /* Cache writes are G_PRIORITY_LOW, so they won't have happened yet... */ soup_cache_flush ((SoupCache *)soup_session_get_feature (session, SOUP_TYPE_CACHE)); return nread ? g_memdup (buf, nread) : g_strdup (""); }
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); }