[libsoup] Always use "wss" as an alias for "https"



commit b2f927575ea0b0041289e0c19f53a33e55760fd3
Author: Nirbheek Chauhan <nirbheek centricular com>
Date:   Wed Jul 12 20:01:03 2017 +0530

    Always use "wss" as an alias for "https"
    
    Also fix a bunch of places that were comparing uri->scheme directly
    with SOUP_URI_SCHEME_HTTPS instead of using the private function
    soup_uri_is_https().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784786

 libsoup/soup-auth-negotiate.c |    2 +-
 libsoup/soup-connection.c     |   18 ++++++++++++++----
 libsoup/soup-connection.h     |    1 +
 libsoup/soup-cookie.c         |    2 +-
 libsoup/soup-session.c        |    3 ++-
 libsoup/soup-uri.c            |   12 ++++++++----
 6 files changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/libsoup/soup-auth-negotiate.c b/libsoup/soup-auth-negotiate.c
index 5a49119..1fdf142 100644
--- a/libsoup/soup-auth-negotiate.c
+++ b/libsoup/soup-auth-negotiate.c
@@ -454,7 +454,7 @@ check_auth_trusted_uri (SoupConnectionAuth *auth, SoupMessage *msg)
 
        /* If no trusted URIs are set, we allow all HTTPS URIs */
        if (!trusted_uris)
-               return msg_uri->scheme == SOUP_URI_SCHEME_HTTPS;
+               return soup_uri_is_https (msg_uri, NULL);
 
        matched = g_slist_find_custom (trusted_uris,
                                       msg_uri,
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index 5403704..5fb4d78 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -13,6 +13,7 @@
 #include "soup.h"
 #include "soup-message-queue.h"
 #include "soup-socket-private.h"
+#include "soup-misc-private.h"
 
 typedef struct {
        SoupSocket  *socket;
@@ -44,6 +45,7 @@ enum {
        PROP_REMOTE_URI,
        PROP_SOCKET_PROPERTIES,
        PROP_STATE,
+       PROP_SSL,
 
        LAST_PROP
 };
@@ -98,10 +100,6 @@ soup_connection_set_property (GObject *object, guint prop_id,
        switch (prop_id) {
        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_SOCKET_PROPERTIES:
                priv->socket_props = g_value_dup_boxed (value);
@@ -109,6 +107,9 @@ soup_connection_set_property (GObject *object, guint prop_id,
        case PROP_STATE:
                soup_connection_set_state (SOUP_CONNECTION (object), g_value_get_uint (value));
                break;
+       case PROP_SSL:
+               priv->ssl = g_value_get_boolean (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -131,6 +132,9 @@ soup_connection_get_property (GObject *object, guint prop_id,
        case PROP_STATE:
                g_value_set_enum (value, priv->state);
                break;
+       case PROP_SSL:
+               g_value_set_boolean (value, priv->ssl);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -190,6 +194,12 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
                                   "Current state of connection",
                                   SOUP_TYPE_CONNECTION_STATE, SOUP_CONNECTION_NEW,
                                   G_PARAM_READWRITE));
+       g_object_class_install_property (
+               object_class, PROP_SSL,
+               g_param_spec_boolean (SOUP_CONNECTION_SSL,
+                                     "Connection uses TLS",
+                                     "Whether the connection should use TLS",
+                                     FALSE, G_PARAM_READWRITE));
 }
 
 static void
diff --git a/libsoup/soup-connection.h b/libsoup/soup-connection.h
index 3da217f..fe817de 100644
--- a/libsoup/soup-connection.h
+++ b/libsoup/soup-connection.h
@@ -38,6 +38,7 @@ GType soup_connection_get_type (void);
 #define SOUP_CONNECTION_REMOTE_URI        "remote-uri"
 #define SOUP_CONNECTION_SOCKET_PROPERTIES "socket-properties"
 #define SOUP_CONNECTION_STATE             "state"
+#define SOUP_CONNECTION_SSL               "ssl"
 
 void            soup_connection_connect_async    (SoupConnection       *conn,
                                                  GCancellable         *cancellable,
diff --git a/libsoup/soup-cookie.c b/libsoup/soup-cookie.c
index cbb991a..d97b23f 100644
--- a/libsoup/soup-cookie.c
+++ b/libsoup/soup-cookie.c
@@ -1012,7 +1012,7 @@ soup_cookie_applies_to_uri (SoupCookie *cookie, SoupURI *uri)
 {
        int plen;
 
-       if (cookie->secure && uri->scheme != SOUP_URI_SCHEME_HTTPS)
+       if (cookie->secure && !soup_uri_is_https (uri, NULL))
                return FALSE;
 
        if (cookie->expires && soup_date_is_past (cookie->expires))
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index f7aef68..a010431 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1790,7 +1790,7 @@ get_connection_for_host (SoupSession *session,
        guint num_pending = 0;
 
        if (priv->disposed)
-               return FALSE;
+               return NULL;
 
        if (item->conn) {
                g_return_val_if_fail (soup_connection_get_state (item->conn) != SOUP_CONNECTION_DISCONNECTED, 
FALSE);
@@ -1839,6 +1839,7 @@ get_connection_for_host (SoupSession *session,
        ensure_socket_props (session);
        conn = g_object_new (SOUP_TYPE_CONNECTION,
                             SOUP_CONNECTION_REMOTE_URI, host->uri,
+                            SOUP_CONNECTION_SSL, soup_uri_is_https (host->uri, priv->https_aliases),
                             SOUP_CONNECTION_SOCKET_PROPERTIES, priv->socket_props,
                             NULL);
 
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 32ade29..be778d6 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -1334,9 +1334,11 @@ soup_uri_is_http (SoupURI *uri, char **aliases)
 {
        int i;
 
-       if (uri->scheme == SOUP_URI_SCHEME_HTTP)
+       if (uri->scheme == SOUP_URI_SCHEME_HTTP ||
+           uri->scheme == SOUP_URI_SCHEME_WS)
                return TRUE;
-       else if (uri->scheme == SOUP_URI_SCHEME_HTTPS)
+       else if (uri->scheme == SOUP_URI_SCHEME_HTTPS ||
+                uri->scheme == SOUP_URI_SCHEME_WSS)
                return FALSE;
        else if (!aliases)
                return FALSE;
@@ -1357,9 +1359,11 @@ soup_uri_is_https (SoupURI *uri, char **aliases)
 {
        int i;
 
-       if (uri->scheme == SOUP_URI_SCHEME_HTTPS)
+       if (uri->scheme == SOUP_URI_SCHEME_HTTPS ||
+           uri->scheme == SOUP_URI_SCHEME_WSS)
                return TRUE;
-       else if (uri->scheme == SOUP_URI_SCHEME_HTTP)
+       else if (uri->scheme == SOUP_URI_SCHEME_HTTP ||
+                uri->scheme == SOUP_URI_SCHEME_WS)
                return FALSE;
        else if (!aliases)
                return FALSE;


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