[libsoup/wip/proxy-connect: 12/16] soup-session, soup-connection: update handling of "ssl" flag



commit ad8c36d0ac3e52f2c0d6ff4db0d90c8eeb009acf
Author: Dan Winship <danw gnome org>
Date:   Sat Mar 15 09:23:32 2014 -0400

    soup-session, soup-connection: update handling of "ssl" flag
    
    Store all SoupSessionHosts with a URI using either "http" or "https"
    as the scheme. Then we don't need to explicitly tell SoupConnection
    whether the connection is SSL or not, since it can figure it out from
    the URI.

 libsoup/soup-connection.c |   18 ++++--------------
 libsoup/soup-connection.h |    1 -
 libsoup/soup-session.c    |   15 ++++++++++++---
 3 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index 883bb5d..6961038 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -51,7 +51,6 @@ enum {
        PROP_LOCAL_ADDRESS,
        PROP_REMOTE_URI,
        PROP_PROXY_RESOLVER,
-       PROP_SSL,
        PROP_SSL_CREDS,
        PROP_SSL_STRICT,
        PROP_SSL_FALLBACK,
@@ -119,13 +118,14 @@ soup_connection_set_property (GObject *object, guint prop_id,
                break;
        case PROP_REMOTE_URI:
                priv->remote_uri = g_value_dup_boxed (value);
+               if (priv->remote_uri)
+                       priv->ssl = (priv->remote_uri->scheme == SOUP_URI_SCHEME_HTTPS);
+               else
+                       priv->ssl = FALSE;
                break;
        case PROP_PROXY_RESOLVER:
                priv->proxy_resolver = g_value_dup_object (value);
                break;
-       case PROP_SSL:
-               priv->ssl = g_value_get_boolean (value);
-               break;
        case PROP_SSL_CREDS:
                if (priv->tlsdb)
                        g_object_unref (priv->tlsdb);
@@ -173,9 +173,6 @@ soup_connection_get_property (GObject *object, guint prop_id,
        case PROP_REMOTE_URI:
                g_value_set_boxed (value, priv->remote_uri);
                break;
-       case PROP_SSL:
-               g_value_set_boolean (value, priv->ssl);
-               break;
        case PROP_SSL_CREDS:
                g_value_set_object (value, priv->tlsdb);
                break;
@@ -262,13 +259,6 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
                                     G_TYPE_PROXY_RESOLVER,
                                     G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (
-               object_class, PROP_SSL,
-               g_param_spec_boolean (SOUP_CONNECTION_SSL,
-                                     "SSL",
-                                     "Whether this is an SSL connection",
-                                     FALSE,
-                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-       g_object_class_install_property (
                object_class, PROP_SSL_CREDS,
                g_param_spec_object (SOUP_CONNECTION_SSL_CREDENTIALS,
                                     "SSL credentials",
diff --git a/libsoup/soup-connection.h b/libsoup/soup-connection.h
index b70a8a3..454432d 100644
--- a/libsoup/soup-connection.h
+++ b/libsoup/soup-connection.h
@@ -38,7 +38,6 @@ GType soup_connection_get_type (void);
 #define SOUP_CONNECTION_LOCAL_ADDRESS   "local-address"
 #define SOUP_CONNECTION_REMOTE_URI      "remote-uri"
 #define SOUP_CONNECTION_PROXY_RESOLVER  "proxy-resolver"
-#define SOUP_CONNECTION_SSL             "ssl"
 #define SOUP_CONNECTION_SSL_CREDENTIALS "ssl-creds"
 #define SOUP_CONNECTION_SSL_STRICT      "ssl-strict"
 #define SOUP_CONNECTION_SSL_FALLBACK    "ssl-fallback"
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 153d0ec..ca190d1 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -959,17 +959,27 @@ get_host_for_uri (SoupSession *session, SoupURI *uri)
 {
        SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
        SoupSessionHost *host;
+       gboolean https;
+       SoupURI *uri_tmp = NULL;
 
-       if (soup_uri_is_https (uri, priv->https_aliases))
+       https = soup_uri_is_https (uri, priv->https_aliases);
+       if (https)
                host = g_hash_table_lookup (priv->https_hosts, uri);
        else
                host = g_hash_table_lookup (priv->http_hosts, uri);
        if (host)
                return host;
 
+       if (uri->scheme != SOUP_URI_SCHEME_HTTP &&
+           uri->scheme != SOUP_URI_SCHEME_HTTPS) {
+               uri = uri_tmp = soup_uri_copy (uri);
+               uri->scheme = https ? SOUP_URI_SCHEME_HTTPS : SOUP_URI_SCHEME_HTTP;
+       }
        host = soup_session_host_new (session, uri);
+       if (uri_tmp)
+               soup_uri_free (uri_tmp);
 
-       if (soup_uri_is_https (uri, priv->https_aliases))
+       if (https)
                g_hash_table_insert (priv->https_hosts, host->uri, host);
        else
                g_hash_table_insert (priv->http_hosts, host->uri, host);
@@ -1774,7 +1784,6 @@ get_connection_for_host (SoupSession *session,
                SOUP_TYPE_CONNECTION,
                SOUP_CONNECTION_REMOTE_URI, host->uri,
                SOUP_CONNECTION_PROXY_RESOLVER, proxy_resolver,
-               SOUP_CONNECTION_SSL, soup_uri_is_https (soup_message_get_uri (item->msg), 
priv->https_aliases),
                SOUP_CONNECTION_SSL_CREDENTIALS, tlsdb,
                SOUP_CONNECTION_SSL_STRICT, priv->ssl_strict && (tlsdb != NULL || SOUP_IS_PLAIN_SESSION 
(session)),
                SOUP_CONNECTION_ASYNC_CONTEXT, priv->async_context,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]