[libsoup/wip/soup-uri-removal: 18/21] Simplify scheme comparisons GUri already normalizes their case, we don't need to do case insensitive




commit 8db071ee545f9107f74f9afe9a3b6310811b4a82
Author: Patrick Griffis <pgriffis igalia com>
Date:   Thu Oct 22 11:52:09 2020 -0500

    Simplify scheme comparisons
    GUri already normalizes their case, we don't need to do case insensitive comparisons

 libsoup/auth/soup-auth-digest.c |  2 +-
 libsoup/soup-request-file.c     |  2 +-
 libsoup/soup-session.c          |  4 ++--
 libsoup/soup-uri.c              | 39 +++++++++++++++++----------------------
 4 files changed, 21 insertions(+), 26 deletions(-)
---
diff --git a/libsoup/auth/soup-auth-digest.c b/libsoup/auth/soup-auth-digest.c
index e93f426b..27b55b46 100644
--- a/libsoup/auth/soup-auth-digest.c
+++ b/libsoup/auth/soup-auth-digest.c
@@ -210,7 +210,7 @@ soup_auth_digest_get_protection_space (SoupAuth *auth, GUri *source_uri)
                else {
                        uri = soup_uri_parse_normalized (NULL, d, NULL);
                        if (uri &&
-                            !g_ascii_strcasecmp (g_uri_get_scheme (uri), g_uri_get_scheme (source_uri)) &&
+                            !g_strcmp0 (g_uri_get_scheme (uri), g_uri_get_scheme (source_uri)) &&
                            soup_uri_get_port_with_default (uri) == soup_uri_get_port_with_default 
(source_uri) &&
                            !strcmp (g_uri_get_host (uri), g_uri_get_host (source_uri)))
                                dir = g_strdup (g_uri_get_path (uri));
diff --git a/libsoup/soup-request-file.c b/libsoup/soup-request-file.c
index cc5afa31..4a6f6392 100644
--- a/libsoup/soup-request-file.c
+++ b/libsoup/soup-request-file.c
@@ -141,7 +141,7 @@ soup_request_file_ensure_file (SoupRequestFile  *file,
        windowsify_file_uri_path (decoded_path);
 #endif
 
-       if (!g_ascii_strcasecmp (g_uri_get_scheme (uri), "resource")) {
+       if (!g_strcmp0 (g_uri_get_scheme (uri), "resource")) {
                char *uri_str;
 
                uri_str = g_strdup_printf ("resource://%s", decoded_path);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 23c51373..9fa4442b 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -716,8 +716,8 @@ soup_session_host_new (SoupSession *session, GUri *uri)
         const char *scheme = g_uri_get_scheme (uri);
 
        host = g_slice_new0 (SoupSessionHost);
-       if (g_ascii_strcasecmp (scheme, "http") &&
-           g_ascii_strcasecmp (scheme, "https")) {
+       if (g_strcmp0 (scheme, "http") &&
+           g_strcmp0 (scheme, "https")) {
                SoupSessionPrivate *priv = soup_session_get_instance_private (session);
 
                if (soup_uri_is_https (uri, priv->https_aliases))
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 8d5264ec..7dfa8236 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -19,13 +19,13 @@
 static inline int
 soup_scheme_default_port (const char *scheme)
 {
-        if (!g_ascii_strcasecmp (scheme, "http") ||
-            !g_ascii_strcasecmp (scheme, "ws"))
+        if (!g_strcmp0 (scheme, "http") ||
+            !g_strcmp0 (scheme, "ws"))
                return 80;
-       else if (!g_ascii_strcasecmp (scheme, "https") ||
-                 !g_ascii_strcasecmp (scheme, "wss"))
+       else if (!g_strcmp0 (scheme, "https") ||
+                 !g_strcmp0 (scheme, "wss"))
                return 443;
-       else if (!g_ascii_strcasecmp (scheme, "ftp"))
+       else if (!g_strcmp0 (scheme, "ftp"))
                return 21;
        else
                return -1;
@@ -77,7 +77,7 @@ soup_uri_equal (GUri *uri1, GUri *uri2)
        g_return_val_if_fail (uri1 != NULL, FALSE);
        g_return_val_if_fail (uri2 != NULL, FALSE);
 
-               if (!parts_equal (g_uri_get_scheme (uri1), g_uri_get_scheme (uri2), TRUE)          ||
+               if (g_strcmp0 (g_uri_get_scheme (uri1), g_uri_get_scheme (uri2))                   ||
            soup_uri_get_port_with_default (uri1) != soup_uri_get_port_with_default (uri2) ||
            !parts_equal (g_uri_get_user (uri1), g_uri_get_user (uri2), FALSE)             ||
            !parts_equal (g_uri_get_password (uri1), g_uri_get_password (uri2), FALSE)     ||
@@ -439,7 +439,7 @@ soup_uri_host_equal (gconstpointer v1, gconstpointer v2)
 
         if (one == two)
                 return TRUE;
-       if (g_ascii_strcasecmp (g_uri_get_scheme (one), g_uri_get_scheme (two)) != 0)
+       if (g_strcmp0 (g_uri_get_scheme (one), g_uri_get_scheme (two)) != 0)
                return FALSE;
 
         one_port = g_uri_get_port (one);
@@ -464,8 +464,8 @@ soup_uri_is_https (GUri *uri, char **aliases)
 
         const char *scheme = g_uri_get_scheme (uri);
 
-        if (!g_ascii_strcasecmp (scheme, "https") ||
-            !g_ascii_strcasecmp (scheme, "wss"))
+        if (!g_strcmp0 (scheme, "https") ||
+            !g_strcmp0 (scheme, "wss"))
             return TRUE;
        else if (!aliases)
                return FALSE;
@@ -485,8 +485,8 @@ soup_uri_is_http (GUri *uri, char **aliases)
 
         const char *scheme = g_uri_get_scheme (uri);
 
-        if (!g_ascii_strcasecmp (scheme, "http") ||
-            !g_ascii_strcasecmp (scheme, "ws"))
+        if (!g_strcmp0 (scheme, "http") ||
+            !g_strcmp0 (scheme, "ws"))
             return TRUE;
        else if (!aliases)
                return FALSE;
@@ -509,8 +509,8 @@ soup_uri_valid_for_http (GUri *uri, GError **error)
 
         const char *scheme = g_uri_get_scheme (uri);
         // QUESITON: Accept any scheme?
-        if (G_UNLIKELY (!(!g_ascii_strcasecmp (scheme, "https") ||
-                          !g_ascii_strcasecmp (scheme, "http")))) {
+        if (G_UNLIKELY (!(!g_strcmp0 (scheme, "https") ||
+                          !g_strcmp0 (scheme, "http")))) {
                 g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, "URI has invalid scheme: 
%s", scheme);
                 return FALSE;
         }
@@ -678,13 +678,9 @@ soup_normalize_uri_internal (GUri *uri, SoupNormalizeFlags flags)
         fragment = g_uri_get_fragment (uri);
         port = g_uri_get_port (uri);
 
-        char *normalized_scheme = NULL, *normalized_path = NULL, *normalized_query = NULL, 
*normalized_fragment = NULL;
+        char *normalized_path = NULL, *normalized_query = NULL, *normalized_fragment = NULL;
         int normalized_port = 0;
 
-        if (!is_string_lower (scheme)) {
-                normalized_scheme = g_ascii_strdown (scheme, -1);
-                scheme = normalized_scheme;
-        }
 
         /* If the path isn't escaped we always escape it */
         if (!(g_uri_get_flags (uri) & G_URI_FLAGS_ENCODED_PATH))
@@ -714,13 +710,13 @@ soup_normalize_uri_internal (GUri *uri, SoupNormalizeFlags flags)
                 normalized_fragment = uri_normalized_copy (fragment, strlen (fragment), NULL);
 
         if (flags & SOUP_NORMALISE_FLAG_PORT && scheme != NULL &&
-            port != -1 && port == soup_scheme_default_port (normalized_scheme ? normalized_scheme : scheme))
+            port != -1 && port == soup_scheme_default_port (scheme))
                 normalized_port = -1;
 
-        if (normalized_scheme || normalized_path || normalized_query || normalized_fragment || 
normalized_port) {
+        if (normalized_path || normalized_query || normalized_fragment || normalized_port) {
                 GUri *normalized_uri = g_uri_build_with_user (
                         g_uri_get_flags (uri) | G_URI_FLAGS_ENCODED_PATH | G_URI_FLAGS_ENCODED_QUERY | 
G_URI_FLAGS_ENCODED_FRAGMENT,
-                        normalized_scheme ? normalized_scheme : scheme,
+                        scheme,
                         g_uri_get_user (uri),
                         g_uri_get_password (uri),
                         g_uri_get_auth_params (uri),
@@ -731,7 +727,6 @@ soup_normalize_uri_internal (GUri *uri, SoupNormalizeFlags flags)
                         normalized_fragment ? normalized_fragment : fragment
                 );
 
-                g_free (normalized_scheme);
                 g_free (normalized_path);
                 g_free (normalized_query);
                 g_free (normalized_fragment);


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