blob: 37ba0a0429ae5be9d6aba003dd8e81d5d4dff07e [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From d39fd6d5f4c0a63cc048b84b0f989cb83f31e5fe Mon Sep 17 00:00:00 2001
2From: Carlos Garcia Campos <cgarcia@igalia.com>
3Date: Tue, 8 Jun 2021 10:57:06 +0200
4Subject: [PATCH 1/2] Use GUri instead of SoupURI
5
6Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/librest/-/merge_requests/6]
7---
8 configure.ac | 2 +-
9 rest-extras/flickr-proxy.c | 19 ++++++++++++++-----
10 rest/oauth-proxy-call.c | 19 ++++++++++++++-----
11 rest/oauth2-proxy.c | 22 +++++++++++-----------
12 4 files changed, 40 insertions(+), 22 deletions(-)
13
14diff --git a/configure.ac b/configure.ac
15index d15e592..d586e69 100644
16--- a/configure.ac
17+++ b/configure.ac
18@@ -40,7 +40,7 @@ AM_PROG_CC_C_O
19 LT_PREREQ([2.2.6])
20 LT_INIT([disable-static])
21
22-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.44)
23+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.67.4)
24 PKG_CHECK_MODULES(SOUP, libsoup-2.4 >= 2.42)
25 PKG_CHECK_MODULES(XML, libxml-2.0)
26 PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
27diff --git a/rest-extras/flickr-proxy.c b/rest-extras/flickr-proxy.c
28index 3342a4d..7726359 100644
29--- a/rest-extras/flickr-proxy.c
30+++ b/rest-extras/flickr-proxy.c
31@@ -304,13 +304,13 @@ flickr_proxy_build_login_url (FlickrProxy *proxy,
32 const char *frob,
33 const char *perms)
34 {
35- SoupURI *uri;
36+ GUri *uri;
37 GHashTable *params;
38 char *sig, *s;
39+ char *query;
40
41 g_return_val_if_fail (FLICKR_IS_PROXY (proxy), NULL);
42
43- uri = soup_uri_new ("http://flickr.com/services/auth/");
44 params = g_hash_table_new (g_str_hash, g_str_equal);
45
46 g_hash_table_insert (params, "api_key", proxy->priv->api_key);
47@@ -321,14 +321,23 @@ flickr_proxy_build_login_url (FlickrProxy *proxy,
48
49 sig = flickr_proxy_sign (proxy, params);
50 g_hash_table_insert (params, "api_sig", sig);
51+ query = soup_form_encode_hash (params);
52
53- soup_uri_set_query_from_form (uri, params);
54+ uri = g_uri_build (G_URI_FLAGS_ENCODED,
55+ "http",
56+ NULL,
57+ "flickr.com",
58+ -1,
59+ "services/auth/",
60+ query,
61+ NULL);
62
63- s = soup_uri_to_string (uri, FALSE);
64+ s = g_uri_to_string (uri);
65
66+ g_free (query);
67 g_free (sig);
68 g_hash_table_destroy (params);
69- soup_uri_free (uri);
70+ g_uri_unref (uri);
71
72 return s;
73 }
74diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c
75index c90c69d..e238c3c 100644
76--- a/rest/oauth-proxy-call.c
77+++ b/rest/oauth-proxy-call.c
78@@ -30,7 +30,7 @@
79
80 G_DEFINE_TYPE (OAuthProxyCall, oauth_proxy_call, REST_TYPE_PROXY_CALL)
81
82-#define OAUTH_ENCODE_STRING(x_) (x_ ? soup_uri_encode( (x_), "!$&'()*+,;=@") : g_strdup (""))
83+#define OAUTH_ENCODE_STRING(x_) (x_ ? g_uri_escape_string( (x_), NULL, TRUE) : g_strdup (""))
84
85 static char *
86 sign_plaintext (OAuthProxyPrivate *priv)
87@@ -136,15 +136,24 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
88 if (priv->oauth_echo) {
89 g_string_append_uri_escaped (text, priv->service_url, NULL, FALSE);
90 } else if (priv->signature_host != NULL) {
91- SoupURI *url = soup_uri_new (url_str);
92+ GUri *url = g_uri_parse (url_str, G_URI_FLAGS_ENCODED, NULL);
93+ GUri *new_url;
94 gchar *signing_url;
95
96- soup_uri_set_host (url, priv->signature_host);
97- signing_url = soup_uri_to_string (url, FALSE);
98+ new_url = g_uri_build (g_uri_get_flags (url),
99+ g_uri_get_scheme (url),
100+ g_uri_get_userinfo (url),
101+ priv->signature_host,
102+ g_uri_get_port (url),
103+ g_uri_get_path (url),
104+ g_uri_get_query (url),
105+ g_uri_get_fragment (url));
106+ signing_url = g_uri_to_string (new_url);
107
108 g_string_append_uri_escaped (text, signing_url, NULL, FALSE);
109
110- soup_uri_free (url);
111+ g_uri_unref (new_url);
112+ g_uri_unref (url);
113 g_free (signing_url);
114 } else {
115 g_string_append_uri_escaped (text, url_str, NULL, FALSE);
116diff --git a/rest/oauth2-proxy.c b/rest/oauth2-proxy.c
117index 24e5da0..3382f8b 100644
118--- a/rest/oauth2-proxy.c
119+++ b/rest/oauth2-proxy.c
120@@ -37,8 +37,6 @@ oauth2_proxy_error_quark (void)
121 return g_quark_from_static_string ("rest-oauth2-proxy");
122 }
123
124-#define EXTRA_CHARS_ENCODE "!$&'()*+,;=@"
125-
126 enum {
127 PROP_0,
128 PROP_CLIENT_ID,
129@@ -242,8 +240,8 @@ append_query_param (gpointer key, gpointer value, gpointer user_data)
130 char *encoded_val, *encoded_key;
131 char *param;
132
133- encoded_val = soup_uri_encode (value, EXTRA_CHARS_ENCODE);
134- encoded_key = soup_uri_encode (key, EXTRA_CHARS_ENCODE);
135+ encoded_val = g_uri_escape_string (value, NULL, TRUE);
136+ encoded_key = g_uri_escape_string (key, NULL, TRUE);
137
138 param = g_strdup_printf ("%s=%s", encoded_key, encoded_val);
139 g_free (encoded_key);
140@@ -295,8 +293,8 @@ oauth2_proxy_build_login_url_full (OAuth2Proxy *proxy,
141 g_hash_table_foreach (extra_params, append_query_param, params);
142 }
143
144- encoded_uri = soup_uri_encode (redirect_uri, EXTRA_CHARS_ENCODE);
145- encoded_id = soup_uri_encode (proxy->priv->client_id, EXTRA_CHARS_ENCODE);
146+ encoded_uri = g_uri_escape_string (redirect_uri, NULL, TRUE);
147+ encoded_id = g_uri_escape_string (proxy->priv->client_id, NULL, TRUE);
148
149 url = g_strdup_printf ("%s?client_id=%s&redirect_uri=%s&type=user_agent",
150 proxy->priv->auth_endpoint, encoded_id,
151@@ -378,20 +376,22 @@ oauth2_proxy_extract_access_token (const char *url)
152 {
153 GHashTable *params;
154 char *token = NULL;
155- SoupURI *soupuri = soup_uri_new (url);
156+ const char *fragment;
157+ GUri *uri = g_uri_parse (url, G_URI_FLAGS_ENCODED, NULL);
158
159- if (soupuri->fragment != NULL) {
160- params = soup_form_decode (soupuri->fragment);
161+ fragment = g_uri_get_fragment (uri);
162+ if (fragment != NULL) {
163+ params = soup_form_decode (fragment);
164
165 if (params) {
166 char *encoded = g_hash_table_lookup (params, "access_token");
167 if (encoded)
168- token = soup_uri_decode (encoded);
169+ token = g_uri_unescape_string (encoded, NULL);
170
171 g_hash_table_destroy (params);
172 }
173 }
174- soup_uri_free (soupuri);
175+ g_uri_unref (uri);
176
177 return token;
178 }
179--
1802.33.1
181