[gnome-online-accounts/carlosgc/libsoup3: 12/13] Use GUri instead of SoupURI




commit 1e038e8fba1485f14a960b5a916acdf1f0f514c8
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Mon Jun 7 16:31:18 2021 +0200

    Use GUri instead of SoupURI
    
    In preparation for libsoup3 where SoupURI has been removed in favor of
    GUri.

 configure.ac                         |   2 +-
 meson.build                          |   2 +-
 src/goabackend/goaoauth2provider.c   |  11 ++--
 src/goabackend/goaoauthprovider.c    |   8 ++-
 src/goabackend/goaowncloudprovider.c | 107 +++++++++++++++++++++--------------
 src/goabackend/goawebview.c          |   9 ++-
 6 files changed, 81 insertions(+), 58 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9dc412a4..22cdaa40 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,7 +90,7 @@ GTK_DOC_CHECK([1.3])
 # Libraries
 #
 
-PKG_CHECK_MODULES(GLIB, [glib-2.0 gio-2.0 gio-unix-2.0 >= 2.52])
+PKG_CHECK_MODULES(GLIB, [glib-2.0 gio-2.0 gio-unix-2.0 >= 2.67.4])
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 
diff --git a/meson.build b/meson.build
index cd3fffec..f123cbc2 100644
--- a/meson.build
+++ b/meson.build
@@ -76,7 +76,7 @@ endif
 
 add_project_arguments(compiler_flags, language: 'c')
 
-glib_req_version = '>= 2.52'
+glib_req_version = '>= 2.67.4'
 
 gio_dep = dependency('gio-2.0', version: glib_req_version)
 gio_unix_dep = dependency('gio-unix-2.0', version: glib_req_version)
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 3715431d..2757838b 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -763,7 +763,7 @@ on_web_view_decide_policy (WebKitWebView            *web_view,
   GHashTable *key_value_pairs;
   WebKitNavigationAction *action;
   WebKitURIRequest *request;
-  SoupURI *uri;
+  GUri *uri;
   const gchar *fragment;
   const gchar *oauth2_error;
   const gchar *query;
@@ -793,9 +793,9 @@ on_web_view_decide_policy (WebKitWebView            *web_view,
   if (!g_str_has_prefix (requested_uri, redirect_uri))
     goto default_behaviour;
 
-  uri = soup_uri_new (requested_uri);
-  fragment = soup_uri_get_fragment (uri);
-  query = soup_uri_get_query (uri);
+  uri = g_uri_parse (requested_uri, G_URI_FLAGS_ENCODED, NULL);
+  fragment = g_uri_get_fragment (uri);
+  query = g_uri_get_query (uri);
 
   /* Three cases:
    * 1) we can either have the backend handle the URI for us, or
@@ -808,7 +808,7 @@ on_web_view_decide_policy (WebKitWebView            *web_view,
     {
       gchar *url;
 
-      url = soup_uri_to_string (uri, FALSE);
+      url = g_uri_to_string (uri);
       if (!goa_oauth2_provider_process_redirect_url (self, url, &priv->access_token, &priv->error))
         {
           g_prefix_error (&priv->error, _("Authorization response: "));
@@ -889,6 +889,7 @@ on_web_view_decide_policy (WebKitWebView            *web_view,
   goto ignore_request;
 
  ignore_request:
+  g_uri_unref (uri);
   g_assert (response_id != GTK_RESPONSE_NONE);
   if (response_id < 0)
     gtk_dialog_response (priv->dialog, response_id);
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index 0bfab6b1..ff0927ef 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -643,7 +643,7 @@ on_web_view_decide_policy (WebKitWebView            *web_view,
 {
   GHashTable *key_value_pairs;
   IdentifyData *data = user_data;
-  SoupURI *uri;
+  GUri *uri;
   WebKitNavigationAction *action;
   WebKitURIRequest *request;
   const gchar *query;
@@ -664,8 +664,8 @@ on_web_view_decide_policy (WebKitWebView            *web_view,
   if (!g_str_has_prefix (requested_uri, redirect_uri))
     goto default_behaviour;
 
-  uri = soup_uri_new (requested_uri);
-  query = soup_uri_get_query (uri);
+  uri = g_uri_parse (requested_uri, G_URI_FLAGS_ENCODED, NULL);
+  query = g_uri_get_query (uri);
 
   if (query != NULL)
     {
@@ -678,6 +678,8 @@ on_web_view_decide_policy (WebKitWebView            *web_view,
       g_hash_table_unref (key_value_pairs);
     }
 
+  g_uri_unref (uri);
+
   if (data->oauth_verifier != NULL)
     goto ignore_request;
 
diff --git a/src/goabackend/goaowncloudprovider.c b/src/goabackend/goaowncloudprovider.c
index d1429661..10734beb 100644
--- a/src/goabackend/goaowncloudprovider.c
+++ b/src/goabackend/goaowncloudprovider.c
@@ -22,8 +22,6 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <libsoup/soup.h>
-
 #include "goahttpclient.h"
 #include "goaprovider.h"
 #include "goaowncloudprovider.h"
@@ -78,45 +76,42 @@ get_provider_features (GoaProvider *provider)
 /* ---------------------------------------------------------------------------------------------------- */
 
 static char *
-uri_to_string_with_path (SoupURI *soup_uri, const gchar *path)
+uri_to_string_with_path (GUri *uri, const gchar *path)
 {
   gchar *uri_string;
   gchar *uri_tmp;
 
-  if (soup_uri == NULL)
+  if (uri == NULL)
     return NULL;
 
-  uri_tmp = soup_uri_to_string (soup_uri, FALSE);
+  uri_tmp = g_uri_to_string (uri);
   uri_string = g_strconcat (uri_tmp, path, NULL);
   g_free (uri_tmp);
 
   return uri_string;
 }
 
-static char *get_webdav_uri (SoupURI *soup_uri)
+static char *get_webdav_uri (GUri *uri)
 {
-  SoupURI *uri_tmp;
+  GUri *uri_tmp;
   gchar *uri_webdav;
   const gchar *scheme;
-  guint port;
 
-  if (soup_uri == NULL)
+  if (uri == NULL)
     return NULL;
 
-  scheme = soup_uri_get_scheme (soup_uri);
-  port = soup_uri_get_port (soup_uri);
-  uri_tmp = soup_uri_copy (soup_uri);
-
-  if (g_strcmp0 (scheme, SOUP_URI_SCHEME_HTTPS) == 0)
-    soup_uri_set_scheme (uri_tmp, "davs");
-  else
-    soup_uri_set_scheme (uri_tmp, "dav");
-
-  if (!soup_uri_uses_default_port (soup_uri))
-    soup_uri_set_port (uri_tmp, port);
+  scheme = g_uri_get_scheme (uri);
+  uri_tmp = g_uri_build (g_uri_get_flags (uri),
+                         g_strcmp0 (scheme, "https") == 0 ? "davs" : "dav",
+                         g_uri_get_userinfo (uri),
+                         g_uri_get_host (uri),
+                         g_uri_get_port (uri),
+                         g_uri_get_path (uri),
+                         g_uri_get_query (uri),
+                         g_uri_get_fragment (uri));
 
   uri_webdav = uri_to_string_with_path (uri_tmp, WEBDAV_ENDPOINT);
-  soup_uri_free (uri_tmp);
+  g_uri_unref (uri_tmp);
 
   return uri_webdav;
 }
@@ -140,7 +135,7 @@ build_object (GoaProvider         *provider,
   gchar *uri_carddav;
   gchar *uri_webdav;
   GoaPasswordBased *password_based = NULL;
-  SoupURI *uri = NULL;
+  GUri *uri = NULL;
   gboolean accept_ssl_errors;
   gboolean calendar_enabled;
   gboolean contacts_enabled;
@@ -176,9 +171,24 @@ build_object (GoaProvider         *provider,
   account = goa_object_get_account (GOA_OBJECT (object));
   identity = goa_account_get_identity (account);
   uri_string = g_key_file_get_string (key_file, group, "Uri", NULL);
-  uri = soup_uri_new (uri_string);
+  uri = g_uri_parse (uri_string, G_URI_FLAGS_ENCODED, NULL);
   if (uri != NULL)
-    soup_uri_set_user (uri, identity);
+    {
+      GUri *tmp_uri;
+
+      tmp_uri = g_uri_build_with_user (g_uri_get_flags (uri),
+                                       g_uri_get_scheme (uri),
+                                       identity,
+                                       g_uri_get_password (uri),
+                                       g_uri_get_auth_params (uri),
+                                       g_uri_get_host (uri),
+                                       g_uri_get_port (uri),
+                                       g_uri_get_path (uri),
+                                       g_uri_get_query (uri),
+                                       g_uri_get_fragment (uri));
+      g_uri_unref (uri);
+      uri = tmp_uri;
+    }
 
   accept_ssl_errors = g_key_file_get_boolean (key_file, group, "AcceptSslErrors", NULL);
 
@@ -224,7 +234,7 @@ build_object (GoaProvider         *provider,
 
  out:
   g_clear_object (&password_based);
-  g_clear_pointer (&uri, soup_uri_free);
+  g_clear_pointer (&uri, g_uri_unref);
   g_free (uri_string);
   return ret;
 }
@@ -354,8 +364,11 @@ add_entry (GtkWidget     *grid,
 static gchar *
 normalize_uri (const gchar *address, gchar **server)
 {
-  SoupURI *uri = NULL;
+  GUri *uri = NULL;
+  GUri *uri_tmp = NULL;
   const gchar *path;
+  const gchar *new_scheme;
+  gchar *new_path = NULL;
   gchar *ret = NULL;
   gchar *scheme = NULL;
   gchar *uri_string = NULL;
@@ -384,48 +397,56 @@ normalize_uri (const gchar *address, gchar **server)
   else
     goto out;
 
-  uri = soup_uri_new (uri_string);
+  uri = g_uri_parse (uri_string, G_URI_FLAGS_ENCODED, NULL);
   if (uri == NULL)
     goto out;
 
   if (g_strcmp0 (scheme, "dav") == 0)
-    soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP);
+    new_scheme = "http";
   else if (g_strcmp0 (scheme, "davs") == 0)
-    soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTPS);
+    new_scheme = "https";
+  else
+    new_scheme = g_uri_get_scheme (uri);
 
-  path = soup_uri_get_path (uri);
+  path = g_uri_get_path (uri);
   if (!g_str_has_suffix (path, "/"))
-    {
-      gchar *new_path;
-
       new_path = g_strconcat (path, "/", NULL);
-      soup_uri_set_path (uri, new_path);
-      path = soup_uri_get_path (uri);
-      g_free (new_path);
-    }
+
+  uri_tmp = g_uri_build (g_uri_get_flags (uri),
+                         new_scheme,
+                         g_uri_get_userinfo (uri),
+                         g_uri_get_host (uri),
+                         g_uri_get_port (uri),
+                         new_path ? new_path : path,
+                         g_uri_get_query (uri),
+                         g_uri_get_fragment (uri));
+  g_free (new_path);
+  g_uri_unref (uri);
+  uri = uri_tmp;
+  path = g_uri_get_path (uri);
 
   if (server != NULL)
     {
       gchar *port_string;
       gchar *pretty_path;
-      guint port;
+      gint port;
 
-      port = soup_uri_get_port (uri);
-      port_string = g_strdup_printf (":%u", port);
+      port = g_uri_get_port (uri);
+      port_string = g_strdup_printf (":%d", port);
 
       pretty_path = g_strdup (path);
       pretty_path[strlen(pretty_path) - 1] = '\0';
 
-      *server = g_strconcat (soup_uri_get_host (uri), (port == std_port) ? "" : port_string, pretty_path, 
NULL);
+      *server = g_strconcat (g_uri_get_host (uri), (port == std_port || port == -1) ? "" : port_string, 
pretty_path, NULL);
 
       g_free (port_string);
       g_free (pretty_path);
     }
 
-  ret = soup_uri_to_string (uri, FALSE);
+  ret = g_uri_to_string (uri);
 
  out:
-  g_clear_pointer (&uri, soup_uri_free);
+  g_clear_pointer (&uri, g_uri_unref);
   g_free (scheme);
   g_free (uri_string);
   return ret;
diff --git a/src/goabackend/goawebview.c b/src/goabackend/goawebview.c
index 2438e0cd..3df600ea 100644
--- a/src/goabackend/goawebview.c
+++ b/src/goabackend/goawebview.c
@@ -25,7 +25,6 @@
 #include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <jsc/jsc.h>
-#include <libsoup/soup.h>
 #include <webkit2/webkit2.h>
 
 #include "goawebview.h"
@@ -77,17 +76,17 @@ web_view_clear_notify_progress_cb (gpointer user_data)
 static char *
 web_view_create_loading_title (const gchar *url)
 {
-  SoupURI *uri;
+  GUri *uri;
   const gchar *hostname;
   gchar *title;
 
   g_return_val_if_fail (url != NULL && url[0] != '\0', NULL);
 
-  uri = soup_uri_new (url);
-  hostname = soup_uri_get_host (uri);
+  uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL);
+  hostname = g_uri_get_host (uri);
   /* translators: %s here is the address of the web page */
   title = g_strdup_printf (_("Loading ā€œ%sā€ā€¦"), hostname);
-  soup_uri_free (uri);
+  g_uri_unref (uri);
 
   return title;
 }


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