/** * soup_session_abort: * @session: the session * * Cancels all pending requests in @session. **/ void soup_session_abort (SoupSession *session) { SoupSessionPrivate *priv; SoupMessageQueueItem *item; GSList *conns, *c; g_return_if_fail (SOUP_IS_SESSION (session)); priv = SOUP_SESSION_GET_PRIVATE (session); for (item = soup_message_queue_first (priv->queue); item; item = soup_message_queue_next (priv->queue, item)) { soup_session_cancel_message (session, item->msg, SOUP_STATUS_CANCELLED); } /* Close all connections */ g_mutex_lock (priv->host_lock); conns = NULL; g_hash_table_foreach (priv->conns, gather_conns, &conns); g_mutex_unlock (priv->host_lock); for (c = conns; c; c = c->next) { soup_connection_disconnect (c->data); g_object_unref (c->data); } g_slist_free (conns); }
GDavMultiStatus * gdav_propfind_sync (SoupSession *session, SoupURI *uri, GDavPropFindType type, GDavPropertySet *prop, GDavDepth depth, SoupMessage **out_message, GCancellable *cancellable, GError **error) { GDavAsyncClosure *closure; GAsyncResult *result; GDavMultiStatus *multi_status; g_return_val_if_fail (SOUP_IS_SESSION (session), NULL); g_return_val_if_fail (uri != NULL, NULL); closure = gdav_async_closure_new (); gdav_propfind ( session, uri, type, prop, depth, cancellable, gdav_async_closure_callback, closure); result = gdav_async_closure_wait (closure); multi_status = gdav_propfind_finish ( session, result, out_message, error); gdav_async_closure_free (closure); return multi_status; }
gboolean gdav_options_sync (SoupSession *session, SoupURI *uri, GDavAllow *out_allow, GDavOptions *out_options, SoupMessage **out_message, GCancellable *cancellable, GError **error) { GDavAsyncClosure *closure; GAsyncResult *result; gboolean success; g_return_val_if_fail (SOUP_IS_SESSION (session), FALSE); g_return_val_if_fail (uri != NULL, FALSE); closure = gdav_async_closure_new (); gdav_options ( session, uri, cancellable, gdav_async_closure_callback, closure); result = gdav_async_closure_wait (closure); success = gdav_options_finish ( session, result, out_allow, out_options, out_message, error); gdav_async_closure_free (closure); return success; }
static void soup_logger_request_started (SoupSessionFeature *feature, SoupSession *session, SoupMessage *msg, SoupSocket *socket) { SoupLogger *logger = SOUP_LOGGER (feature); gboolean restarted; guint msg_id; g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (SOUP_IS_MESSAGE (msg)); g_return_if_fail (SOUP_IS_SOCKET (socket)); msg_id = soup_logger_get_id (logger, msg); if (msg_id) restarted = TRUE; else { soup_logger_set_id (logger, msg); restarted = FALSE; } if (!soup_logger_get_id (logger, session)) soup_logger_set_id (logger, session); if (!soup_logger_get_id (logger, socket)) soup_logger_set_id (logger, socket); print_request (logger, msg, session, socket, restarted); soup_logger_print (logger, SOUP_LOGGER_LOG_MINIMAL, ' ', ""); }
/** * soup_session_send_message: * @session: a #SoupSession * @msg: the message to send * * Synchronously send @msg. This call will not return until the * transfer is finished successfully or there is an unrecoverable * error. * * @msg is not freed upon return. * * Return value: the HTTP status code of the response */ guint soup_session_send_message (SoupSession *session, SoupMessage *msg) { g_return_val_if_fail (SOUP_IS_SESSION (session), SOUP_STATUS_MALFORMED); g_return_val_if_fail (SOUP_IS_MESSAGE (msg), SOUP_STATUS_MALFORMED); return SOUP_SESSION_GET_CLASS (session)->send_message (session, msg); }
/** * soup_session_requeue_message: * @session: a #SoupSession * @msg: the message to requeue * * This causes @msg to be placed back on the queue to be attempted * again. **/ void soup_session_requeue_message (SoupSession *session, SoupMessage *msg) { g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (SOUP_IS_MESSAGE (msg)); SOUP_SESSION_GET_CLASS (session)->requeue_message (session, msg); }
JNIEXPORT jboolean JNICALL WebKitGTK_NATIVE(_1SOUP_1IS_1SESSION) (JNIEnv *env, jclass that, jintLong arg0) { jboolean rc = 0; WebKitGTK_NATIVE_ENTER(env, that, _1SOUP_1IS_1SESSION_FUNC); rc = (jboolean)SOUP_IS_SESSION(arg0); WebKitGTK_NATIVE_EXIT(env, that, _1SOUP_1IS_1SESSION_FUNC); return rc; }
/** * soup_session_unpause_message: * @session: a #SoupSession * @msg: a #SoupMessage currently running on @session * * Resumes HTTP I/O on @msg. Use this to resume after calling * soup_sessino_pause_message(). * * If @msg is being sent via blocking I/O, this will resume reading or * writing immediately. If @msg is using non-blocking I/O, then * reading or writing won't resume until you return to the main loop. **/ void soup_session_unpause_message (SoupSession *session, SoupMessage *msg) { g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (SOUP_IS_MESSAGE (msg)); soup_message_io_unpause (msg); }
/** * soup_session_queue_message: * @session: a #SoupSession * @msg: the message to queue * @callback: a #SoupSessionCallback which will be called after the * message completes or when an unrecoverable error occurs. * @user_data: a pointer passed to @callback. * * Queues the message @msg for sending. All messages are processed * while the glib main loop runs. If @msg has been processed before, * any resources related to the time it was last sent are freed. * * Upon message completion, the callback specified in @callback will * be invoked (in the thread associated with @session's async * context). If after returning from this callback the message has not * been requeued, @msg will be unreffed. */ void soup_session_queue_message (SoupSession *session, SoupMessage *msg, SoupSessionCallback callback, gpointer user_data) { g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (SOUP_IS_MESSAGE (msg)); SOUP_SESSION_GET_CLASS (session)->queue_message (session, msg, callback, user_data); }
/** * soup_session_get_async_context: * @session: a #SoupSession * * Gets @session's async_context. This does not add a ref to the * context, so you will need to ref it yourself if you want it to * outlive its session. * * Return value: @session's #GMainContext, which may be %NULL **/ GMainContext * soup_session_get_async_context (SoupSession *session) { SoupSessionPrivate *priv; g_return_val_if_fail (SOUP_IS_SESSION (session), NULL); priv = SOUP_SESSION_GET_PRIVATE (session); return priv->async_context; }
gboolean abort_soup_sess(gpointer key, gpointer value, gpointer user_data) { if (key && SOUP_IS_SESSION(key)) { soup_session_abort(key); g_hash_table_foreach_remove(rf->key_session, remove_if_match, user_data); } return TRUE; }
/** * soup_session_add_feature_by_type: * @session: a #SoupSession * @feature_type: the #GType of a class that implements #SoupSessionFeature * * Creates a new feature of type @feature_type and adds it to * @session. You can use this instead of soup_session_add_feature() in * the case wher you don't need to customize the new feature in any * way. You can also add a feature to the session at construct time by * using the %SOUP_SESSION_ADD_FEATURE_BY_TYPE property. * * Since: 2.24 **/ void soup_session_add_feature_by_type (SoupSession *session, GType feature_type) { SoupSessionFeature *feature; g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (g_type_is_a (feature_type, SOUP_TYPE_SESSION_FEATURE)); feature = g_object_new (feature_type, NULL); soup_session_add_feature (session, feature); g_object_unref (feature); }
/** * soup_session_cancel_message: * @session: a #SoupSession * @msg: the message to cancel * @status_code: status code to set on @msg (generally * %SOUP_STATUS_CANCELLED) * * Causes @session to immediately finish processing @msg (regardless * of its current state) with a final status_code of @status_code. You * may call this at any time after handing @msg off to @session; if * @session has started sending the request but has not yet received * the complete response, then it will close the request's connection. * Note that with non-idempotent requests (eg, %POST, %PUT, %DELETE) * it is possible that you might cancel the request after the server * acts on it, but before it returns a response, leaving the remote * resource in an unknown state. * * If the message is cancelled while its response body is being read, * then the response body in @msg will be left partially-filled-in. * The response headers, on the other hand, will always be either * empty or complete. * * For messages queued with soup_session_queue_message() (and * cancelled from the same thread), the callback will be invoked * before soup_session_cancel_message() returns. **/ void soup_session_cancel_message (SoupSession *session, SoupMessage *msg, guint status_code) { g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (SOUP_IS_MESSAGE (msg)); /* If the message is already ending, don't do anything */ if (soup_message_get_io_status (msg) == SOUP_MESSAGE_IO_STATUS_FINISHED) return; SOUP_SESSION_GET_CLASS (session)->cancel_message (session, msg, status_code); }
void gdav_propfind (SoupSession *session, SoupURI *uri, GDavPropFindType type, GDavPropertySet *prop, GDavDepth depth, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; SoupRequestHTTP *request; AsyncContext *async_context; GError *local_error = NULL; g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (uri != NULL); async_context = g_slice_new0 (AsyncContext); task = g_task_new (session, cancellable, callback, user_data); g_task_set_source_tag (task, gdav_propfind); g_task_set_task_data ( task, async_context, (GDestroyNotify) async_context_free); request = gdav_request_propfind_uri ( session, uri, type, prop, depth, &local_error); /* Sanity check */ g_warn_if_fail ( ((request != NULL) && (local_error == NULL)) || ((request == NULL) && (local_error != NULL))); if (request != NULL) { async_context->message = soup_request_http_get_message (request); gdav_request_send ( request, cancellable, gdav_propfind_request_cb, g_object_ref (task)); g_object_unref (request); } else { g_task_return_error (task, local_error); } g_object_unref (task); }
/** * soup_session_get_feature: * @session: a #SoupSession * @feature_type: the #GType of the feature to get * * Gets the first feature in @session of type @feature_type. For * features where there may be more than one feature of a given type, * use soup_session_get_features(). * * Return value: a #SoupSessionFeature, or %NULL. The feature is owned * by @session. * * Since: 2.26 **/ SoupSessionFeature * soup_session_get_feature (SoupSession *session, GType feature_type) { SoupSessionPrivate *priv; GSList *f; g_return_val_if_fail (SOUP_IS_SESSION (session), NULL); priv = SOUP_SESSION_GET_PRIVATE (session); for (f = priv->features; f; f = f->next) { if (G_TYPE_CHECK_INSTANCE_TYPE (f->data, feature_type)) return f->data; } return NULL; }
/** * soup_session_get_features: * @session: a #SoupSession * @feature_type: the #GType of the class of features to get * * Generates a list of @session's features of type @feature_type. (If * you want to see all features, you can pass %G_TYPE_SESSION_FEATURE * for @feature_type.) * * Return value: a list of features. You must free the list, but not * its contents * * Since: 2.26 **/ GSList * soup_session_get_features (SoupSession *session, GType feature_type) { SoupSessionPrivate *priv; GSList *f, *ret; g_return_val_if_fail (SOUP_IS_SESSION (session), NULL); priv = SOUP_SESSION_GET_PRIVATE (session); for (f = priv->features, ret = NULL; f; f = f->next) { if (G_TYPE_CHECK_INSTANCE_TYPE (f->data, feature_type)) ret = g_slist_prepend (ret, f->data); } return g_slist_reverse (ret); }
/** * soup_session_add_feature: * @session: a #SoupSession * @feature: an object that implements #SoupSessionFeature * * Adds @feature's functionality to @session. You can also add a * feature to the session at construct time by using the * %SOUP_SESSION_ADD_FEATURE property. * * Since: 2.24 **/ void soup_session_add_feature (SoupSession *session, SoupSessionFeature *feature) { SoupSessionPrivate *priv; g_return_if_fail (SOUP_IS_SESSION (session)); g_return_if_fail (SOUP_IS_SESSION_FEATURE (feature)); priv = SOUP_SESSION_GET_PRIVATE (session); priv->features = g_slist_prepend (priv->features, g_object_ref (feature)); soup_session_feature_attach (feature, session); if (SOUP_IS_PROXY_URI_RESOLVER (feature)) priv->proxy_resolver = SOUP_PROXY_URI_RESOLVER (feature); }
/** * soup_session_remove_feature_by_type: * @session: a #SoupSession * @feature_type: the #GType of a class that implements #SoupSessionFeature * * Removes all features of type @feature_type (or any subclass of * @feature_type) from @session. You can also remove standard features * from the session at construct time by using the * %SOUP_SESSION_REMOVE_FEATURE_BY_TYPE property. * * Since: 2.24 **/ void soup_session_remove_feature_by_type (SoupSession *session, GType feature_type) { SoupSessionPrivate *priv; GSList *f; g_return_if_fail (SOUP_IS_SESSION (session)); priv = SOUP_SESSION_GET_PRIVATE (session); restart: for (f = priv->features; f; f = f->next) { if (G_TYPE_CHECK_INSTANCE_TYPE (f->data, feature_type)) { soup_session_remove_feature (session, f->data); goto restart; } } }
/** * soup_session_remove_feature: * @session: a #SoupSession * @feature: a feature that has previously been added to @session * * Removes @feature's functionality from @session. * * Since: 2.24 **/ void soup_session_remove_feature (SoupSession *session, SoupSessionFeature *feature) { SoupSessionPrivate *priv; g_return_if_fail (SOUP_IS_SESSION (session)); priv = SOUP_SESSION_GET_PRIVATE (session); if (g_slist_find (priv->features, feature)) { priv->features = g_slist_remove (priv->features, feature); soup_session_feature_detach (feature, session); g_object_unref (feature); if (feature == (SoupSessionFeature *)priv->proxy_resolver) priv->proxy_resolver = NULL; } }
static void send_message_cb(GObject* source, GAsyncResult* res, gpointer udata) { RETURN_IF_FAIL(SOUP_IS_SESSION(source)); RETURN_IF_FAIL(G_IS_ASYNC_RESULT(res)); RETURN_IF_FAIL(udata != NULL); ResourceData* data = udata; GtResourceDownloader* self = GT_RESOURCE_DOWNLOADER(data->self); GtResourceDownloaderPrivate* priv = gt_resource_downloader_get_instance_private(self); g_autoptr(GError) err = NULL; data->istream = soup_session_send_finish(SOUP_SESSION(source), res, &err); if (!err) g_thread_pool_push(dl_pool, data, NULL); else { data->cb(NULL, data->udata, g_steal_pointer(&err)); resource_data_free(data); } }
static void push_gcm_client_deliver_cb (SoupSession *session, SoupMessage *message, gpointer user_data) { GSimpleAsyncResult *simple = user_data; const gchar *str; JsonObject *obj; JsonParser *p = NULL; JsonArray *ar; JsonNode *root; JsonNode *node; gboolean removed; GError *error = NULL; GList *list; gsize length; guint i; ENTRY; g_assert(SOUP_IS_SESSION(session)); g_assert(SOUP_IS_MESSAGE(message)); g_assert(G_IS_SIMPLE_ASYNC_RESULT(simple)); switch (message->status_code) { case SOUP_STATUS_OK: break; case SOUP_STATUS_BAD_REQUEST: /* * TODO: Log that there was a JSON encoding error likely. */ break; case SOUP_STATUS_UNAUTHORIZED: g_simple_async_result_set_error(simple, SOUP_HTTP_ERROR, message->status_code, _("GCM request unauthorized.")); GOTO(failure); default: if (SOUP_STATUS_IS_SERVER_ERROR(message->status_code) && (str = soup_message_headers_get_one(message->response_headers, "Retry-After"))) { /* * TODO: Implement exponential back-off. */ } g_simple_async_result_set_error(simple, SOUP_HTTP_ERROR, message->status_code, _("Unknown failure occurred.")); break; } if (!message->response_body->data || !message->response_body->length) { g_simple_async_result_set_error(simple, SOUP_HTTP_ERROR, SOUP_STATUS_IO_ERROR, _("No data was received from GCM.")); GOTO(failure); } p = json_parser_new(); if (!json_parser_load_from_data(p, message->response_body->data, message->response_body->length, &error)) { g_simple_async_result_take_error(simple, error); GOTO(failure); } list = g_object_get_data(G_OBJECT(simple), "identities"); if ((root = json_parser_get_root(p)) && JSON_NODE_HOLDS_OBJECT(root) && (obj = json_node_get_object(root)) && json_object_has_member(obj, "results") && (node = json_object_get_member(obj, "results")) && JSON_NODE_HOLDS_ARRAY(node) && (ar = json_node_get_array(node))) { length = json_array_get_length(ar); for (i = 0; i < length && list; i++, list = list->next) { /* * TODO: Handle the case that the device_token has been renamed. */ removed = FALSE; if ((obj = json_array_get_object_element(ar, i)) && json_object_has_member(obj, "error") && (node = json_object_get_member(obj, "error")) && JSON_NODE_HOLDS_VALUE(node) && (str = json_node_get_string(node))) { if (!g_strcmp0(str, "MissingRegistration")) { removed = TRUE; } else if (!g_strcmp0(str, "InvalidRegistration")) { removed = TRUE; } else if (!g_strcmp0(str, "MismatchSenderId")) { } else if (!g_strcmp0(str, "NotRegistered")) { removed = TRUE; } else if (!g_strcmp0(str, "MessageTooBig")) { } else if (!g_strcmp0(str, "InvalidDataKey")) { } else if (!g_strcmp0(str, "InvalidTtl")) { } if (removed) { g_assert(PUSH_IS_GCM_IDENTITY(list->data)); g_signal_emit(session, gSignals[IDENTITY_REMOVED], 0, list->data); } } } } g_simple_async_result_set_op_res_gboolean(simple, TRUE); failure: g_simple_async_result_complete_in_idle(simple); g_object_unref(simple); if (p) { g_object_unref(p); } EXIT; }