blob: 11fc96bc28eeaf9a166bd3013403d79aebc663bf [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From 5a5abbedb171986dbf6f5a37577ec6afa892b66b Mon Sep 17 00:00:00 2001
2From: Carlos Garcia Campos <cgarcia@igalia.com>
3Date: Mon, 7 Jun 2021 16:31:18 +0200
4Subject: [PATCH 1/2] Use GUri instead of SoupURI
5
6In preparation for libsoup3 where SoupURI has been removed in favor of
7GUri.
8
9Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/gnome-online-accounts/-/merge_requests/73]
10Signed-off-by: Khem Raj <raj.khem@gmail.com>
11---
12 configure.ac | 2 +-
13 src/goabackend/goaoauth2provider.c | 11 +--
14 src/goabackend/goaoauthprovider.c | 8 +-
15 src/goabackend/goaowncloudprovider.c | 107 ++++++++++++++++-----------
16 src/goabackend/goawebview.c | 9 +--
17 5 files changed, 80 insertions(+), 57 deletions(-)
18
19diff --git a/configure.ac b/configure.ac
20index 1f88bbd..7c0b39d 100644
21--- a/configure.ac
22+++ b/configure.ac
23@@ -90,7 +90,7 @@ GTK_DOC_CHECK([1.3])
24 # Libraries
25 #
26
27-PKG_CHECK_MODULES(GLIB, [glib-2.0 gio-2.0 gio-unix-2.0 >= 2.52])
28+PKG_CHECK_MODULES(GLIB, [glib-2.0 gio-2.0 gio-unix-2.0 >= 2.67.4])
29 AC_SUBST(GLIB_CFLAGS)
30 AC_SUBST(GLIB_LIBS)
31
32diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
33index 3715431..2757838 100644
34--- a/src/goabackend/goaoauth2provider.c
35+++ b/src/goabackend/goaoauth2provider.c
36@@ -763,7 +763,7 @@ on_web_view_decide_policy (WebKitWebView *web_view,
37 GHashTable *key_value_pairs;
38 WebKitNavigationAction *action;
39 WebKitURIRequest *request;
40- SoupURI *uri;
41+ GUri *uri;
42 const gchar *fragment;
43 const gchar *oauth2_error;
44 const gchar *query;
45@@ -793,9 +793,9 @@ on_web_view_decide_policy (WebKitWebView *web_view,
46 if (!g_str_has_prefix (requested_uri, redirect_uri))
47 goto default_behaviour;
48
49- uri = soup_uri_new (requested_uri);
50- fragment = soup_uri_get_fragment (uri);
51- query = soup_uri_get_query (uri);
52+ uri = g_uri_parse (requested_uri, G_URI_FLAGS_ENCODED, NULL);
53+ fragment = g_uri_get_fragment (uri);
54+ query = g_uri_get_query (uri);
55
56 /* Three cases:
57 * 1) we can either have the backend handle the URI for us, or
58@@ -808,7 +808,7 @@ on_web_view_decide_policy (WebKitWebView *web_view,
59 {
60 gchar *url;
61
62- url = soup_uri_to_string (uri, FALSE);
63+ url = g_uri_to_string (uri);
64 if (!goa_oauth2_provider_process_redirect_url (self, url, &priv->access_token, &priv->error))
65 {
66 g_prefix_error (&priv->error, _("Authorization response: "));
67@@ -889,6 +889,7 @@ on_web_view_decide_policy (WebKitWebView *web_view,
68 goto ignore_request;
69
70 ignore_request:
71+ g_uri_unref (uri);
72 g_assert (response_id != GTK_RESPONSE_NONE);
73 if (response_id < 0)
74 gtk_dialog_response (priv->dialog, response_id);
75diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
76index 0bfab6b..ff0927e 100644
77--- a/src/goabackend/goaoauthprovider.c
78+++ b/src/goabackend/goaoauthprovider.c
79@@ -643,7 +643,7 @@ on_web_view_decide_policy (WebKitWebView *web_view,
80 {
81 GHashTable *key_value_pairs;
82 IdentifyData *data = user_data;
83- SoupURI *uri;
84+ GUri *uri;
85 WebKitNavigationAction *action;
86 WebKitURIRequest *request;
87 const gchar *query;
88@@ -664,8 +664,8 @@ on_web_view_decide_policy (WebKitWebView *web_view,
89 if (!g_str_has_prefix (requested_uri, redirect_uri))
90 goto default_behaviour;
91
92- uri = soup_uri_new (requested_uri);
93- query = soup_uri_get_query (uri);
94+ uri = g_uri_parse (requested_uri, G_URI_FLAGS_ENCODED, NULL);
95+ query = g_uri_get_query (uri);
96
97 if (query != NULL)
98 {
99@@ -678,6 +678,8 @@ on_web_view_decide_policy (WebKitWebView *web_view,
100 g_hash_table_unref (key_value_pairs);
101 }
102
103+ g_uri_unref (uri);
104+
105 if (data->oauth_verifier != NULL)
106 goto ignore_request;
107
108diff --git a/src/goabackend/goaowncloudprovider.c b/src/goabackend/goaowncloudprovider.c
109index d142966..10734be 100644
110--- a/src/goabackend/goaowncloudprovider.c
111+++ b/src/goabackend/goaowncloudprovider.c
112@@ -22,8 +22,6 @@
113
114 #include <glib/gi18n-lib.h>
115
116-#include <libsoup/soup.h>
117-
118 #include "goahttpclient.h"
119 #include "goaprovider.h"
120 #include "goaowncloudprovider.h"
121@@ -78,45 +76,42 @@ get_provider_features (GoaProvider *provider)
122 /* ---------------------------------------------------------------------------------------------------- */
123
124 static char *
125-uri_to_string_with_path (SoupURI *soup_uri, const gchar *path)
126+uri_to_string_with_path (GUri *uri, const gchar *path)
127 {
128 gchar *uri_string;
129 gchar *uri_tmp;
130
131- if (soup_uri == NULL)
132+ if (uri == NULL)
133 return NULL;
134
135- uri_tmp = soup_uri_to_string (soup_uri, FALSE);
136+ uri_tmp = g_uri_to_string (uri);
137 uri_string = g_strconcat (uri_tmp, path, NULL);
138 g_free (uri_tmp);
139
140 return uri_string;
141 }
142
143-static char *get_webdav_uri (SoupURI *soup_uri)
144+static char *get_webdav_uri (GUri *uri)
145 {
146- SoupURI *uri_tmp;
147+ GUri *uri_tmp;
148 gchar *uri_webdav;
149 const gchar *scheme;
150- guint port;
151
152- if (soup_uri == NULL)
153+ if (uri == NULL)
154 return NULL;
155
156- scheme = soup_uri_get_scheme (soup_uri);
157- port = soup_uri_get_port (soup_uri);
158- uri_tmp = soup_uri_copy (soup_uri);
159-
160- if (g_strcmp0 (scheme, SOUP_URI_SCHEME_HTTPS) == 0)
161- soup_uri_set_scheme (uri_tmp, "davs");
162- else
163- soup_uri_set_scheme (uri_tmp, "dav");
164-
165- if (!soup_uri_uses_default_port (soup_uri))
166- soup_uri_set_port (uri_tmp, port);
167+ scheme = g_uri_get_scheme (uri);
168+ uri_tmp = g_uri_build (g_uri_get_flags (uri),
169+ g_strcmp0 (scheme, "https") == 0 ? "davs" : "dav",
170+ g_uri_get_userinfo (uri),
171+ g_uri_get_host (uri),
172+ g_uri_get_port (uri),
173+ g_uri_get_path (uri),
174+ g_uri_get_query (uri),
175+ g_uri_get_fragment (uri));
176
177 uri_webdav = uri_to_string_with_path (uri_tmp, WEBDAV_ENDPOINT);
178- soup_uri_free (uri_tmp);
179+ g_uri_unref (uri_tmp);
180
181 return uri_webdav;
182 }
183@@ -140,7 +135,7 @@ build_object (GoaProvider *provider,
184 gchar *uri_carddav;
185 gchar *uri_webdav;
186 GoaPasswordBased *password_based = NULL;
187- SoupURI *uri = NULL;
188+ GUri *uri = NULL;
189 gboolean accept_ssl_errors;
190 gboolean calendar_enabled;
191 gboolean contacts_enabled;
192@@ -176,9 +171,24 @@ build_object (GoaProvider *provider,
193 account = goa_object_get_account (GOA_OBJECT (object));
194 identity = goa_account_get_identity (account);
195 uri_string = g_key_file_get_string (key_file, group, "Uri", NULL);
196- uri = soup_uri_new (uri_string);
197+ uri = g_uri_parse (uri_string, G_URI_FLAGS_ENCODED, NULL);
198 if (uri != NULL)
199- soup_uri_set_user (uri, identity);
200+ {
201+ GUri *tmp_uri;
202+
203+ tmp_uri = g_uri_build_with_user (g_uri_get_flags (uri),
204+ g_uri_get_scheme (uri),
205+ identity,
206+ g_uri_get_password (uri),
207+ g_uri_get_auth_params (uri),
208+ g_uri_get_host (uri),
209+ g_uri_get_port (uri),
210+ g_uri_get_path (uri),
211+ g_uri_get_query (uri),
212+ g_uri_get_fragment (uri));
213+ g_uri_unref (uri);
214+ uri = tmp_uri;
215+ }
216
217 accept_ssl_errors = g_key_file_get_boolean (key_file, group, "AcceptSslErrors", NULL);
218
219@@ -224,7 +234,7 @@ build_object (GoaProvider *provider,
220
221 out:
222 g_clear_object (&password_based);
223- g_clear_pointer (&uri, soup_uri_free);
224+ g_clear_pointer (&uri, g_uri_unref);
225 g_free (uri_string);
226 return ret;
227 }
228@@ -354,8 +364,11 @@ add_entry (GtkWidget *grid,
229 static gchar *
230 normalize_uri (const gchar *address, gchar **server)
231 {
232- SoupURI *uri = NULL;
233+ GUri *uri = NULL;
234+ GUri *uri_tmp = NULL;
235 const gchar *path;
236+ const gchar *new_scheme;
237+ gchar *new_path = NULL;
238 gchar *ret = NULL;
239 gchar *scheme = NULL;
240 gchar *uri_string = NULL;
241@@ -384,48 +397,56 @@ normalize_uri (const gchar *address, gchar **server)
242 else
243 goto out;
244
245- uri = soup_uri_new (uri_string);
246+ uri = g_uri_parse (uri_string, G_URI_FLAGS_ENCODED, NULL);
247 if (uri == NULL)
248 goto out;
249
250 if (g_strcmp0 (scheme, "dav") == 0)
251- soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP);
252+ new_scheme = "http";
253 else if (g_strcmp0 (scheme, "davs") == 0)
254- soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTPS);
255+ new_scheme = "https";
256+ else
257+ new_scheme = g_uri_get_scheme (uri);
258
259- path = soup_uri_get_path (uri);
260+ path = g_uri_get_path (uri);
261 if (!g_str_has_suffix (path, "/"))
262- {
263- gchar *new_path;
264-
265 new_path = g_strconcat (path, "/", NULL);
266- soup_uri_set_path (uri, new_path);
267- path = soup_uri_get_path (uri);
268- g_free (new_path);
269- }
270+
271+ uri_tmp = g_uri_build (g_uri_get_flags (uri),
272+ new_scheme,
273+ g_uri_get_userinfo (uri),
274+ g_uri_get_host (uri),
275+ g_uri_get_port (uri),
276+ new_path ? new_path : path,
277+ g_uri_get_query (uri),
278+ g_uri_get_fragment (uri));
279+ g_free (new_path);
280+ g_uri_unref (uri);
281+ uri = uri_tmp;
282+ path = g_uri_get_path (uri);
283
284 if (server != NULL)
285 {
286 gchar *port_string;
287 gchar *pretty_path;
288- guint port;
289+ gint port;
290
291- port = soup_uri_get_port (uri);
292- port_string = g_strdup_printf (":%u", port);
293+ port = g_uri_get_port (uri);
294+ port_string = g_strdup_printf (":%d", port);
295
296 pretty_path = g_strdup (path);
297 pretty_path[strlen(pretty_path) - 1] = '\0';
298
299- *server = g_strconcat (soup_uri_get_host (uri), (port == std_port) ? "" : port_string, pretty_path, NULL);
300+ *server = g_strconcat (g_uri_get_host (uri), (port == std_port || port == -1) ? "" : port_string, pretty_path, NULL);
301
302 g_free (port_string);
303 g_free (pretty_path);
304 }
305
306- ret = soup_uri_to_string (uri, FALSE);
307+ ret = g_uri_to_string (uri);
308
309 out:
310- g_clear_pointer (&uri, soup_uri_free);
311+ g_clear_pointer (&uri, g_uri_unref);
312 g_free (scheme);
313 g_free (uri_string);
314 return ret;
315diff --git a/src/goabackend/goawebview.c b/src/goabackend/goawebview.c
316index 2438e0c..3df600e 100644
317--- a/src/goabackend/goawebview.c
318+++ b/src/goabackend/goawebview.c
319@@ -25,7 +25,6 @@
320 #include <glib.h>
321 #include <glib/gi18n-lib.h>
322 #include <jsc/jsc.h>
323-#include <libsoup/soup.h>
324 #include <webkit2/webkit2.h>
325
326 #include "goawebview.h"
327@@ -77,17 +76,17 @@ web_view_clear_notify_progress_cb (gpointer user_data)
328 static char *
329 web_view_create_loading_title (const gchar *url)
330 {
331- SoupURI *uri;
332+ GUri *uri;
333 const gchar *hostname;
334 gchar *title;
335
336 g_return_val_if_fail (url != NULL && url[0] != '\0', NULL);
337
338- uri = soup_uri_new (url);
339- hostname = soup_uri_get_host (uri);
340+ uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL);
341+ hostname = g_uri_get_host (uri);
342 /* translators: %s here is the address of the web page */
343 title = g_strdup_printf (_("Loading ā€œ%sā€ā€¦"), hostname);
344- soup_uri_free (uri);
345+ g_uri_unref (uri);
346
347 return title;
348 }
349--
3502.33.1
351