#include <string.h>
#include <stdlib.h>
+#include "soup-address.h"
#include "soup-auth.h"
#include "soup-auth-basic.h"
#include "soup-auth-digest.h"
**/
typedef struct {
- SoupURI *root_uri;
+ SoupAddress *addr;
- GSList *connections; /* CONTAINS: SoupConnection */
- guint num_conns;
-
- GHashTable *auth_realms; /* path -> scheme:realm */
- GHashTable *auths; /* scheme:realm -> SoupAuth */
+ GSList *connections; /* CONTAINS: SoupConnection */
+ guint num_conns;
} SoupSessionHost;
typedef struct {
SoupURI *proxy_uri;
+ SoupAddress *proxy_addr;
SoupAuth *proxy_auth;
char *ssl_ca_file;
GSList *features;
SoupAuthManager *auth_manager;
- GHashTable *hosts; /* SoupURI -> SoupSessionHost */
+ GHashTable *hosts; /* SoupAddress -> SoupSessionHost */
GHashTable *conns; /* SoupConnection -> SoupSessionHost */
guint num_conns;
guint max_conns, max_conns_per_host;
SoupMessage *msg, SoupAuth *auth,
gboolean retrying, gpointer user_data);
-/* temporary until we fix this to index hosts by SoupAddress */
-extern guint soup_uri_host_hash (gconstpointer key);
-extern gboolean soup_uri_host_equal (gconstpointer v1,
- gconstpointer v2);
-extern SoupURI *soup_uri_copy_root (SoupURI *uri);
-
#define SOUP_SESSION_MAX_CONNS_DEFAULT 10
#define SOUP_SESSION_MAX_CONNS_PER_HOST_DEFAULT 2
{
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
- priv->queue = soup_message_queue_new ();
+ priv->queue = soup_message_queue_new (session);
priv->host_lock = g_mutex_new ();
- priv->hosts = g_hash_table_new (soup_uri_host_hash,
- soup_uri_host_equal);
+ priv->hosts = g_hash_table_new (soup_address_hash_by_ip,
+ soup_address_equal_by_ip);
priv->conns = g_hash_table_new (NULL, NULL);
priv->max_conns = SOUP_SESSION_MAX_CONNS_DEFAULT;
g_mutex_lock (priv->host_lock);
old_hosts = priv->hosts;
- priv->hosts = g_hash_table_new (soup_uri_host_hash,
- soup_uri_host_equal);
+ priv->hosts = g_hash_table_new (soup_address_hash_by_ip,
+ soup_address_equal_by_ip);
g_mutex_unlock (priv->host_lock);
g_hash_table_foreach_remove (old_hosts, foreach_free_host, NULL);
if (priv->proxy_uri)
soup_uri_free (priv->proxy_uri);
+ if (priv->proxy_addr)
+ g_object_unref (priv->proxy_addr);
if (priv->ssl_creds)
soup_ssl_free_client_credentials (priv->ssl_creds);
if (priv->proxy_uri)
soup_uri_free (priv->proxy_uri);
+ if (priv->proxy_addr)
+ g_object_unref (priv->proxy_addr);
priv->proxy_uri = uri ? soup_uri_copy (uri) : NULL;
+ priv->proxy_addr = uri ?
+ soup_address_new (uri->host, uri->port) :
+ NULL;
if (need_abort) {
soup_session_abort (session);
/* Hosts */
static SoupSessionHost *
-soup_session_host_new (SoupSession *session, SoupURI *source_uri)
+soup_session_host_new (SoupSession *session, SoupAddress *addr)
{
- SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
SoupSessionHost *host;
host = g_slice_new0 (SoupSessionHost);
- host->root_uri = soup_uri_copy_root (source_uri);
-
- if (host->root_uri->scheme == SOUP_URI_SCHEME_HTTPS &&
- !priv->ssl_creds) {
- priv->ssl_creds =
- soup_ssl_get_client_credentials (priv->ssl_ca_file);
- }
-
+ host->addr = g_object_ref (addr);
return host;
}
{
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
SoupSessionHost *host;
- SoupURI *source = soup_message_get_uri (msg);
+ SoupAddress *addr = soup_message_get_address (msg);
- host = g_hash_table_lookup (priv->hosts, source);
+ host = g_hash_table_lookup (priv->hosts, addr);
if (host)
return host;
- host = soup_session_host_new (session, source);
- g_hash_table_insert (priv->hosts, host->root_uri, host);
+ host = soup_session_host_new (session, addr);
+ g_hash_table_insert (priv->hosts, host->addr, host);
return host;
}
soup_connection_disconnect (conn);
}
- soup_uri_free (host->root_uri);
+ g_object_unref (host->addr);
g_slice_free (SoupSessionHost, host);
}
g_signal_emit (session, signals[AUTHENTICATE], 0, msg, auth, retrying);
}
+#define SOUP_METHOD_IS_SAFE(method) (method == SOUP_METHOD_GET || \
+ method == SOUP_METHOD_HEAD || \
+ method == SOUP_METHOD_OPTIONS || \
+ method == SOUP_METHOD_PROPFIND)
+
static void
redirect_handler (SoupMessage *msg, gpointer user_data)
{
new_loc = soup_message_headers_get (msg->response_headers, "Location");
g_return_if_fail (new_loc != NULL);
- if (msg->status_code == SOUP_STATUS_MOVED_PERMANENTLY ||
- msg->status_code == SOUP_STATUS_TEMPORARY_REDIRECT) {
- /* Don't redirect non-safe methods */
- if (msg->method != SOUP_METHOD_GET &&
- msg->method != SOUP_METHOD_HEAD &&
- msg->method != SOUP_METHOD_OPTIONS &&
- msg->method != SOUP_METHOD_PROPFIND)
- return;
- } else if (msg->status_code == SOUP_STATUS_SEE_OTHER ||
- msg->status_code == SOUP_STATUS_FOUND) {
+ if (msg->status_code == SOUP_STATUS_SEE_OTHER ||
+ (msg->status_code == SOUP_STATUS_FOUND &&
+ !SOUP_METHOD_IS_SAFE (msg->method))) {
/* Redirect using a GET */
g_object_set (msg,
SOUP_MESSAGE_METHOD, SOUP_METHOD_GET,
SOUP_MEMORY_STATIC, NULL, 0);
soup_message_headers_set_encoding (msg->request_headers,
SOUP_ENCODING_NONE);
+ } else if (msg->status_code == SOUP_STATUS_MOVED_PERMANENTLY ||
+ msg->status_code == SOUP_STATUS_TEMPORARY_REDIRECT ||
+ msg->status_code == SOUP_STATUS_FOUND) {
+ /* Don't redirect non-safe methods */
+ if (!SOUP_METHOD_IS_SAFE (msg->method))
+ return;
} else {
/* Three possibilities:
*
* are lame, so we use soup_uri_new_with_base().
*/
new_uri = soup_uri_new_with_base (soup_message_get_uri (msg), new_loc);
- if (!SOUP_URI_VALID_FOR_HTTP (new_uri)) {
- if (new_uri)
- soup_uri_free (new_uri);
+ if (!new_uri) {
soup_message_set_status_full (msg,
SOUP_STATUS_MALFORMED,
"Invalid Redirect URL");
SoupSession *session = user_data;
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
SoupSessionHost *host;
- SoupMessageQueueIter iter;
+ SoupMessageQueueItem *item;
SoupMessage *msg;
g_mutex_lock (priv->host_lock);
* any messages waiting for this host, since they're out
* of luck.
*/
- for (msg = soup_message_queue_first (priv->queue, &iter); msg; msg = soup_message_queue_next (priv->queue, &iter)) {
+ g_object_ref (session);
+ for (item = soup_message_queue_first (priv->queue); item; item = soup_message_queue_next (priv->queue, item)) {
+ msg = item->msg;
if (get_host_for_message (session, msg) == host) {
if (status == SOUP_STATUS_TRY_AGAIN) {
if (soup_message_get_io_status (msg) == SOUP_MESSAGE_IO_STATUS_CONNECTING)
}
}
}
+ g_object_unref (session);
}
/**
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
SoupConnection *conn;
SoupSessionHost *host;
+ SoupSSLCredentials *ssl_creds;
GSList *conns;
+ SoupURI *uri;
g_mutex_lock (priv->host_lock);
return NULL;
}
+ uri = soup_message_get_uri (msg);
+ if (uri->scheme == SOUP_URI_SCHEME_HTTPS) {
+ if (!priv->ssl_creds)
+ priv->ssl_creds = soup_ssl_get_client_credentials (priv->ssl_ca_file);
+ ssl_creds = priv->ssl_creds;
+ } else
+ ssl_creds = NULL;
+
conn = soup_connection_new (
- SOUP_CONNECTION_ORIGIN_URI, host->root_uri,
- SOUP_CONNECTION_PROXY_URI, priv->proxy_uri,
- SOUP_CONNECTION_SSL_CREDENTIALS, priv->ssl_creds,
+ SOUP_CONNECTION_SERVER_ADDRESS, host->addr,
+ SOUP_CONNECTION_PROXY_ADDRESS, priv->proxy_addr,
+ SOUP_CONNECTION_SSL_CREDENTIALS, ssl_creds,
SOUP_CONNECTION_ASYNC_CONTEXT, priv->async_context,
SOUP_CONNECTION_TIMEOUT, priv->io_timeout,
SOUP_CONNECTION_IDLE_TIMEOUT, priv->idle_timeout,
static void
message_finished (SoupMessage *msg, gpointer user_data)
{
- SoupSession *session = user_data;
+ SoupMessageQueueItem *item = user_data;
+ SoupSession *session = item->session;
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
if (!SOUP_MESSAGE_IS_STARTING (msg)) {
- soup_message_queue_remove_message (priv->queue, msg);
+ soup_message_queue_remove (priv->queue, item);
g_signal_handlers_disconnect_by_func (msg, message_finished, session);
g_signal_handlers_disconnect_by_func (msg, redirect_handler, session);
g_signal_emit (session, signals[REQUEST_UNQUEUED], 0, msg);
+ soup_message_queue_item_unref (item);
}
}
SoupSessionCallback callback, gpointer user_data)
{
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
+ SoupMessageQueueItem *item;
+
+ item = soup_message_queue_append (priv->queue, msg, callback, user_data);
+ soup_message_set_io_status (msg, SOUP_MESSAGE_IO_STATUS_QUEUED);
g_signal_connect_after (msg, "finished",
- G_CALLBACK (message_finished), session);
+ G_CALLBACK (message_finished), item);
if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_NO_REDIRECT)) {
soup_message_add_header_handler (
G_CALLBACK (redirect_handler), session);
}
- soup_message_set_io_status (msg, SOUP_MESSAGE_IO_STATUS_QUEUED);
- soup_message_queue_append (priv->queue, msg);
-
g_signal_emit (session, signals[REQUEST_QUEUED], 0, msg);
}
cancel_message (SoupSession *session, SoupMessage *msg, guint status_code)
{
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
+ SoupMessageQueueItem *item;
+
+ item = soup_message_queue_lookup (priv->queue, msg);
+ if (item) {
+ soup_message_queue_remove (priv->queue, item);
+ if (item->cancellable)
+ g_cancellable_cancel (item->cancellable);
+ soup_message_queue_item_unref (item);
+ }
- soup_message_queue_remove_message (priv->queue, msg);
soup_message_io_stop (msg);
soup_message_set_status (msg, status_code);
soup_message_finished (msg);
SoupConnection *conn = key;
GSList **conns = data;
- *conns = g_slist_prepend (*conns, conn);
+ *conns = g_slist_prepend (*conns, g_object_ref (conn));
}
/**
soup_session_abort (SoupSession *session)
{
SoupSessionPrivate *priv;
- SoupMessageQueueIter iter;
- SoupMessage *msg;
+ SoupMessageQueueItem *item;
GSList *conns, *c;
g_return_if_fail (SOUP_IS_SESSION (session));
priv = SOUP_SESSION_GET_PRIVATE (session);
- for (msg = soup_message_queue_first (priv->queue, &iter);
- msg;
- msg = soup_message_queue_next (priv->queue, &iter)) {
- soup_session_cancel_message (session, msg,
+ 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);
}
conns = NULL;
g_hash_table_foreach (priv->conns, gather_conns, &conns);
- for (c = conns; c; c = c->next)
- g_object_ref (c->data);
g_mutex_unlock (priv->host_lock);
for (c = conns; c; c = c->next) {
soup_connection_disconnect (c->data);
g_slist_free (conns);
}
+/**
+ * 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.
+ **/
void
soup_session_add_feature (SoupSession *session, SoupSessionFeature *feature)
{
soup_session_feature_attach (feature, session);
}
+/**
+ * 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.
+ **/
void
soup_session_add_feature_by_type (SoupSession *session, GType feature_type)
{
g_object_unref (feature);
}
+/**
+ * soup_session_remove_feature:
+ * @session: a #SoupSession
+ * @feature: a feature that has previously been added to @session
+ *
+ * Removes @feature's functionality from @session.
+ **/
void
soup_session_remove_feature (SoupSession *session, SoupSessionFeature *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.
+ **/
void
soup_session_remove_feature_by_type (SoupSession *session, GType feature_type)
{