Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 1 | From 7d8c5208d095ce8e7123935263ef7a02f0381ae5 Mon Sep 17 00:00:00 2001 |
| 2 | From: Carlos Garcia Campos <cgarcia@igalia.com> |
| 3 | Date: Mon, 7 Jun 2021 18:28:42 +0200 |
| 4 | Subject: [PATCH 2/2] Port to libsoup3 |
| 5 | |
| 6 | Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/gnome-online-accounts/-/merge_requests/73] |
| 7 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 8 | --- |
| 9 | configure.ac | 8 +- |
| 10 | src/daemon/goadaemon.c | 2 +- |
| 11 | src/goabackend/goaewsclient.c | 178 +++++++++++++++-------------- |
| 12 | src/goabackend/goahttpclient.c | 72 +++++++----- |
| 13 | src/goabackend/goalastfmprovider.c | 24 ++-- |
| 14 | src/goabackend/goaoauth2provider.c | 6 +- |
| 15 | src/goabackend/goaoauthprovider.c | 23 ++-- |
| 16 | src/goabackend/goarestproxy.h | 2 - |
| 17 | src/goabackend/goasouplogger.c | 33 ++---- |
| 18 | src/goabackend/goasouplogger.h | 3 - |
| 19 | src/goabackend/goautils.c | 27 ++--- |
| 20 | 11 files changed, 199 insertions(+), 179 deletions(-) |
| 21 | |
| 22 | --- a/configure.ac |
| 23 | +++ b/configure.ac |
| 24 | @@ -113,15 +113,15 @@ if test "$enable_backend" != "no"; then |
| 25 | AC_SUBST(GTK_CFLAGS) |
| 26 | AC_SUBST(GTK_LIBS) |
| 27 | |
| 28 | - PKG_CHECK_MODULES(JAVASCRIPT_CORE_GTK, [javascriptcoregtk-4.0 >= 2.12.0]) |
| 29 | + PKG_CHECK_MODULES(JAVASCRIPT_CORE_GTK, [javascriptcoregtk-4.1 >= 2.33.1]) |
| 30 | AC_SUBST(JAVASCRIPT_CORE_GTK_CFLAGS) |
| 31 | AC_SUBST(JAVASCRIPT_CORE_GTK_LIBS) |
| 32 | |
| 33 | - PKG_CHECK_MODULES(WEBKIT_GTK, [webkit2gtk-4.0 >= 2.26.0]) |
| 34 | + PKG_CHECK_MODULES(WEBKIT_GTK, [webkit2gtk-4.1 >= 2.33.1]) |
| 35 | AC_SUBST(WEBKIT_GTK_CFLAGS) |
| 36 | AC_SUBST(WEBKIT_GTK_LIBS) |
| 37 | |
| 38 | - PKG_CHECK_MODULES(LIBSOUP, [libsoup-2.4 >= 2.42]) |
| 39 | + PKG_CHECK_MODULES(LIBSOUP, [libsoup-3.0 >= 2.99.8]) |
| 40 | AC_SUBST(LIBSOUP_CFLAGS) |
| 41 | AC_SUBST(LIBSOUP_LIBS) |
| 42 | |
| 43 | @@ -129,7 +129,7 @@ if test "$enable_backend" != "no"; then |
| 44 | AC_SUBST(JSON_GLIB_CFLAGS) |
| 45 | AC_SUBST(JSON_GLIB_LIBS) |
| 46 | |
| 47 | - PKG_CHECK_MODULES(REST, [rest-0.7]) |
| 48 | + PKG_CHECK_MODULES(REST, [rest-1.0]) |
| 49 | AC_SUBST(REST_CFLAGS) |
| 50 | AC_SUBST(REST_LIBS) |
| 51 | |
| 52 | --- a/src/daemon/goadaemon.c |
| 53 | +++ b/src/daemon/goadaemon.c |
| 54 | @@ -1496,7 +1496,7 @@ is_authorization_error (GError *error) |
| 55 | g_return_val_if_fail (error != NULL, FALSE); |
| 56 | |
| 57 | ret = FALSE; |
| 58 | - if (error->domain == REST_PROXY_ERROR || error->domain == SOUP_HTTP_ERROR) |
| 59 | + if (error->domain == REST_PROXY_ERROR) |
| 60 | { |
| 61 | if (SOUP_STATUS_IS_CLIENT_ERROR (error->code)) |
| 62 | ret = TRUE; |
| 63 | --- a/src/goabackend/goaewsclient.c |
| 64 | +++ b/src/goabackend/goaewsclient.c |
| 65 | @@ -63,6 +63,12 @@ goa_ews_client_new (void) |
| 66 | |
| 67 | typedef struct |
| 68 | { |
| 69 | + gchar *password; |
| 70 | + gchar *username; |
| 71 | +} AutodiscoverAuthData; |
| 72 | + |
| 73 | +typedef struct |
| 74 | +{ |
| 75 | GCancellable *cancellable; |
| 76 | GError *error; |
| 77 | SoupMessage *msgs[2]; |
| 78 | @@ -71,13 +77,16 @@ typedef struct |
| 79 | guint pending; |
| 80 | gulong cancellable_id; |
| 81 | xmlOutputBuffer *buf; |
| 82 | + AutodiscoverAuthData *auth; |
| 83 | } AutodiscoverData; |
| 84 | |
| 85 | -typedef struct |
| 86 | +static void |
| 87 | +ews_client_autodiscover_auth_data_free (AutodiscoverAuthData *auth) |
| 88 | { |
| 89 | - gchar *password; |
| 90 | - gchar *username; |
| 91 | -} AutodiscoverAuthData; |
| 92 | + g_free (auth->password); |
| 93 | + g_free (auth->username); |
| 94 | + g_slice_free (AutodiscoverAuthData, auth); |
| 95 | +} |
| 96 | |
| 97 | static void |
| 98 | ews_client_autodiscover_data_free (gpointer user_data) |
| 99 | @@ -92,22 +101,12 @@ ews_client_autodiscover_data_free (gpoin |
| 100 | |
| 101 | g_clear_error (&data->error); |
| 102 | |
| 103 | - /* soup_session_queue_message stole the references to data->msgs */ |
| 104 | xmlOutputBufferClose (data->buf); |
| 105 | + g_clear_pointer (&data->auth, ews_client_autodiscover_auth_data_free); |
| 106 | g_object_unref (data->session); |
| 107 | g_slice_free (AutodiscoverData, data); |
| 108 | } |
| 109 | |
| 110 | -static void |
| 111 | -ews_client_autodiscover_auth_data_free (gpointer data, GClosure *closure) |
| 112 | -{ |
| 113 | - AutodiscoverAuthData *auth = data; |
| 114 | - |
| 115 | - g_free (auth->password); |
| 116 | - g_free (auth->username); |
| 117 | - g_slice_free (AutodiscoverAuthData, auth); |
| 118 | -} |
| 119 | - |
| 120 | static gboolean |
| 121 | ews_client_check_node (const xmlNode *node, const gchar *name) |
| 122 | { |
| 123 | @@ -115,9 +114,8 @@ ews_client_check_node (const xmlNode *no |
| 124 | return node->type == XML_ELEMENT_NODE && !g_strcmp0 ((gchar *) node->name, name); |
| 125 | } |
| 126 | |
| 127 | -static void |
| 128 | -ews_client_authenticate (SoupSession *session, |
| 129 | - SoupMessage *msg, |
| 130 | +static gboolean |
| 131 | +ews_client_authenticate (SoupMessage *msg, |
| 132 | SoupAuth *auth, |
| 133 | gboolean retrying, |
| 134 | gpointer user_data) |
| 135 | @@ -125,26 +123,26 @@ ews_client_authenticate (SoupSession *se |
| 136 | AutodiscoverAuthData *data = user_data; |
| 137 | |
| 138 | if (retrying) |
| 139 | - return; |
| 140 | + return FALSE; |
| 141 | |
| 142 | soup_auth_authenticate (auth, data->username, data->password); |
| 143 | + return TRUE; |
| 144 | } |
| 145 | |
| 146 | -static void |
| 147 | -ews_client_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *socket, gpointer user_data) |
| 148 | +static gboolean |
| 149 | +ews_client_accept_certificate (SoupMessage *msg, GTlsCertificate *cert, GTlsCertificateFlags cert_flags, gpointer user_data) |
| 150 | { |
| 151 | AutodiscoverData *data; |
| 152 | GTask *task = G_TASK (user_data); |
| 153 | - GTlsCertificateFlags cert_flags; |
| 154 | |
| 155 | - g_debug ("goa_ews_client_autodiscover(): request started (%p)", msg); |
| 156 | + g_debug ("goa_ews_client_autodiscover(): accept certificate for request (%p)", msg); |
| 157 | |
| 158 | data = (AutodiscoverData *) g_task_get_task_data (task); |
| 159 | |
| 160 | - if (!data->accept_ssl_errors |
| 161 | - && soup_message_get_https_status (msg, NULL, &cert_flags) |
| 162 | - && cert_flags != 0 |
| 163 | - && data->error == NULL) |
| 164 | + if (data->accept_ssl_errors || cert_flags == 0) |
| 165 | + return TRUE; |
| 166 | + |
| 167 | + if (data->error == NULL) |
| 168 | { |
| 169 | goa_utils_set_error_ssl (&data->error, cert_flags); |
| 170 | |
| 171 | @@ -153,6 +151,8 @@ ews_client_request_started (SoupSession |
| 172 | */ |
| 173 | soup_session_abort (data->session); |
| 174 | } |
| 175 | + |
| 176 | + return FALSE; |
| 177 | } |
| 178 | |
| 179 | static void |
| 180 | @@ -192,8 +192,10 @@ ews_client_autodiscover_parse_protocol ( |
| 181 | } |
| 182 | |
| 183 | static void |
| 184 | -ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) |
| 185 | +ews_client_autodiscover_response_cb (SoupSession *session, GAsyncResult *result, gpointer user_data) |
| 186 | { |
| 187 | + SoupMessage *msg; |
| 188 | + GBytes *body; |
| 189 | GError *error = NULL; |
| 190 | AutodiscoverData *data; |
| 191 | GTask *task = G_TASK (user_data); |
| 192 | @@ -204,7 +206,11 @@ ews_client_autodiscover_response_cb (Sou |
| 193 | xmlDoc *doc; |
| 194 | xmlNode *node; |
| 195 | |
| 196 | - g_debug ("goa_ews_client_autodiscover(): response (%p, %u)", msg, msg->status_code); |
| 197 | + msg = soup_session_get_async_result_message (session, result); |
| 198 | + |
| 199 | + g_debug ("goa_ews_client_autodiscover(): response (%p, %u)", msg, soup_message_get_status (msg)); |
| 200 | + |
| 201 | + body = soup_session_send_and_read_finish (session, result, &error); |
| 202 | |
| 203 | data = (AutodiscoverData *) g_task_get_task_data (task); |
| 204 | size = sizeof (data->msgs) / sizeof (data->msgs[0]); |
| 205 | @@ -215,16 +221,19 @@ ews_client_autodiscover_response_cb (Sou |
| 206 | break; |
| 207 | } |
| 208 | if (idx == size || data->pending == 0) |
| 209 | - return; |
| 210 | + { |
| 211 | + g_bytes_unref (body); |
| 212 | + g_clear_object (&error); |
| 213 | + g_object_unref (msg); |
| 214 | + return; |
| 215 | + } |
| 216 | |
| 217 | data->msgs[idx] = NULL; |
| 218 | - status = msg->status_code; |
| 219 | - |
| 220 | - /* status == SOUP_STATUS_CANCELLED, if we are being aborted by the |
| 221 | + /* G_IO_ERROR_CANCELLED, if we are being aborted by the |
| 222 | * GCancellable, an SSL error or another message that was |
| 223 | * successful. |
| 224 | */ |
| 225 | - if (status == SOUP_STATUS_CANCELLED) |
| 226 | + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) |
| 227 | { |
| 228 | /* If we are being aborted by the GCancellable, then the |
| 229 | * GTask is responsible for setting the GError automatically. |
| 230 | @@ -235,21 +244,23 @@ ews_client_autodiscover_response_cb (Sou |
| 231 | */ |
| 232 | goto out; |
| 233 | } |
| 234 | - else if (status != SOUP_STATUS_OK) |
| 235 | + |
| 236 | + status = soup_message_get_status (msg); |
| 237 | + if (status != SOUP_STATUS_OK || error) |
| 238 | { |
| 239 | - g_warning ("goa_ews_client_autodiscover() failed: %u — %s", msg->status_code, msg->reason_phrase); |
| 240 | + g_warning ("goa_ews_client_autodiscover() failed: %u — %s", status, soup_message_get_reason_phrase (msg)); |
| 241 | g_return_if_fail (data->error == NULL); |
| 242 | |
| 243 | - goa_utils_set_error_soup (&error, msg); |
| 244 | + if (!error) |
| 245 | + goa_utils_set_error_soup (&error, msg); |
| 246 | goto out; |
| 247 | } |
| 248 | |
| 249 | - soup_buffer_free (soup_message_body_flatten (SOUP_MESSAGE (msg)->response_body)); |
| 250 | g_debug ("The response headers"); |
| 251 | g_debug ("==================="); |
| 252 | - g_debug ("%s", SOUP_MESSAGE (msg)->response_body->data); |
| 253 | + g_debug ("%s", (char *)g_bytes_get_data (body, NULL)); |
| 254 | |
| 255 | - doc = xmlReadMemory (msg->response_body->data, msg->response_body->length, "autodiscover.xml", NULL, 0); |
| 256 | + doc = xmlReadMemory (g_bytes_get_data (body, NULL), g_bytes_get_size (body), "autodiscover.xml", NULL, 0); |
| 257 | if (doc == NULL) |
| 258 | { |
| 259 | g_set_error (&error, |
| 260 | @@ -333,7 +344,7 @@ ews_client_autodiscover_response_cb (Sou |
| 261 | /* The callback (ie. this function) will be invoked after we |
| 262 | * have returned to the main loop. |
| 263 | */ |
| 264 | - soup_session_cancel_message (data->session, data->msgs[idx], SOUP_STATUS_CANCELLED); |
| 265 | + g_cancellable_cancel (data->cancellable); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | @@ -368,6 +379,7 @@ ews_client_autodiscover_response_cb (Sou |
| 270 | |
| 271 | g_clear_error (&error); |
| 272 | g_object_unref (task); |
| 273 | + g_object_unref (msg); |
| 274 | } |
| 275 | |
| 276 | static xmlDoc * |
| 277 | @@ -399,52 +411,54 @@ static void |
| 278 | ews_client_post_restarted_cb (SoupMessage *msg, gpointer data) |
| 279 | { |
| 280 | xmlOutputBuffer *buf = data; |
| 281 | + GBytes *body; |
| 282 | |
| 283 | /* In violation of RFC2616, libsoup will change a POST request to |
| 284 | * a GET on receiving a 302 redirect. |
| 285 | */ |
| 286 | g_debug ("Working around libsoup bug with redirect"); |
| 287 | - g_object_set (msg, SOUP_MESSAGE_METHOD, "POST", NULL); |
| 288 | + g_object_set (msg, "method", "POST", NULL); |
| 289 | |
| 290 | - soup_message_set_request(msg, |
| 291 | - "text/xml; charset=utf-8", |
| 292 | - SOUP_MEMORY_COPY, |
| 293 | #ifdef LIBXML2_NEW_BUFFER |
| 294 | - (gchar *) xmlOutputBufferGetContent(buf), |
| 295 | - xmlOutputBufferGetSize(buf)); |
| 296 | + body = g_bytes_new (xmlOutputBufferGetContent (buf), xmlOutputBufferGetSize (buf)); |
| 297 | #else |
| 298 | - (gchar *) buf->buffer->content, |
| 299 | - buf->buffer->use); |
| 300 | + body = g_bytes_new (buf->buffer->content, buf->buffer->use); |
| 301 | #endif |
| 302 | + soup_message_set_request_body_from_bytes (msg, "text/xml; charset=utf-8", body); |
| 303 | + g_bytes_unref (body); |
| 304 | } |
| 305 | |
| 306 | static SoupMessage * |
| 307 | -ews_client_create_msg_for_url (const gchar *url, xmlOutputBuffer *buf) |
| 308 | +ews_client_create_msg_for_url (const gchar *url, xmlOutputBuffer *buf, AutodiscoverAuthData *auth, GTask *task) |
| 309 | { |
| 310 | SoupMessage *msg; |
| 311 | + GBytes *body = NULL; |
| 312 | |
| 313 | msg = soup_message_new (buf != NULL ? "POST" : "GET", url); |
| 314 | - soup_message_headers_append (msg->request_headers, "User-Agent", "libews/0.1"); |
| 315 | + soup_message_headers_append (soup_message_get_request_headers (msg), |
| 316 | + "User-Agent", "libews/0.1"); |
| 317 | + |
| 318 | + g_signal_connect (msg, "authenticate", |
| 319 | + G_CALLBACK (ews_client_authenticate), |
| 320 | + auth); |
| 321 | + g_signal_connect (msg, "accept-certificate", |
| 322 | + G_CALLBACK (ews_client_accept_certificate), |
| 323 | + task); |
| 324 | |
| 325 | if (buf != NULL) |
| 326 | { |
| 327 | - soup_message_set_request (msg, |
| 328 | - "text/xml; charset=utf-8", |
| 329 | - SOUP_MEMORY_COPY, |
| 330 | #ifdef LIBXML2_NEW_BUFFER |
| 331 | - (gchar *) xmlOutputBufferGetContent(buf), |
| 332 | - xmlOutputBufferGetSize(buf)); |
| 333 | + body = g_bytes_new (xmlOutputBufferGetContent (buf), xmlOutputBufferGetSize (buf)); |
| 334 | #else |
| 335 | - (gchar *) buf->buffer->content, |
| 336 | - buf->buffer->use); |
| 337 | + body = g_bytes_new (buf->buffer->content, buf->buffer->use); |
| 338 | #endif |
| 339 | + soup_message_set_request_body_from_bytes (msg, "text/xml; charset=utf-8", body); |
| 340 | g_signal_connect (msg, "restarted", G_CALLBACK (ews_client_post_restarted_cb), buf); |
| 341 | } |
| 342 | |
| 343 | - soup_buffer_free (soup_message_body_flatten (SOUP_MESSAGE (msg)->request_body)); |
| 344 | g_debug ("The request headers"); |
| 345 | g_debug ("==================="); |
| 346 | - g_debug ("%s", SOUP_MESSAGE (msg)->request_body->data); |
| 347 | + g_debug ("%s", body ? (char *)g_bytes_get_data (body, NULL) : ""); |
| 348 | |
| 349 | return msg; |
| 350 | } |
| 351 | @@ -497,12 +511,15 @@ goa_ews_client_autodiscover (GoaEwsClien |
| 352 | * (successful) one win. |
| 353 | */ |
| 354 | |
| 355 | + auth = g_slice_new0 (AutodiscoverAuthData); |
| 356 | + auth->username = g_strdup (username); |
| 357 | + auth->password = g_strdup (password); |
| 358 | + data->auth = auth; |
| 359 | data->buf = buf; |
| 360 | - data->msgs[0] = ews_client_create_msg_for_url (url1, buf); |
| 361 | - data->msgs[1] = ews_client_create_msg_for_url (url2, buf); |
| 362 | + data->msgs[0] = ews_client_create_msg_for_url (url1, buf, auth, task); |
| 363 | + data->msgs[1] = ews_client_create_msg_for_url (url2, buf, auth, task); |
| 364 | data->pending = sizeof (data->msgs) / sizeof (data->msgs[0]); |
| 365 | - data->session = soup_session_new_with_options (SOUP_SESSION_SSL_STRICT, FALSE, |
| 366 | - NULL); |
| 367 | + data->session = soup_session_new (); |
| 368 | soup_session_add_feature_by_type (data->session, SOUP_TYPE_AUTH_NTLM); |
| 369 | data->accept_ssl_errors = accept_ssl_errors; |
| 370 | |
| 371 | @@ -515,26 +532,19 @@ goa_ews_client_autodiscover (GoaEwsClien |
| 372 | NULL); |
| 373 | } |
| 374 | |
| 375 | - auth = g_slice_new0 (AutodiscoverAuthData); |
| 376 | - auth->username = g_strdup (username); |
| 377 | - auth->password = g_strdup (password); |
| 378 | - g_signal_connect_data (data->session, |
| 379 | - "authenticate", |
| 380 | - G_CALLBACK (ews_client_authenticate), |
| 381 | - auth, |
| 382 | - ews_client_autodiscover_auth_data_free, |
| 383 | - 0); |
| 384 | - |
| 385 | - g_signal_connect (data->session, "request-started", G_CALLBACK (ews_client_request_started), task); |
| 386 | - |
| 387 | - soup_session_queue_message (data->session, |
| 388 | - data->msgs[0], |
| 389 | - ews_client_autodiscover_response_cb, |
| 390 | - g_object_ref (task)); |
| 391 | - soup_session_queue_message (data->session, |
| 392 | - data->msgs[1], |
| 393 | - ews_client_autodiscover_response_cb, |
| 394 | - g_object_ref (task)); |
| 395 | + |
| 396 | + soup_session_send_and_read_async (data->session, |
| 397 | + data->msgs[0], |
| 398 | + G_PRIORITY_DEFAULT, |
| 399 | + data->cancellable, |
| 400 | + (GAsyncReadyCallback)ews_client_autodiscover_response_cb, |
| 401 | + g_object_ref (task)); |
| 402 | + soup_session_send_and_read_async (data->session, |
| 403 | + data->msgs[1], |
| 404 | + G_PRIORITY_DEFAULT, |
| 405 | + data->cancellable, |
| 406 | + (GAsyncReadyCallback)ews_client_autodiscover_response_cb, |
| 407 | + g_object_ref (task)); |
| 408 | |
| 409 | g_free (url2); |
| 410 | g_free (url1); |
| 411 | --- a/src/goabackend/goahttpclient.c |
| 412 | +++ b/src/goabackend/goahttpclient.c |
| 413 | @@ -82,7 +82,7 @@ http_client_check_data_free (gpointer us |
| 414 | |
| 415 | g_clear_error (&data->error); |
| 416 | |
| 417 | - /* soup_session_queue_message stole the references to data->msg */ |
| 418 | + g_object_unref (data->msg); |
| 419 | g_object_unref (data->session); |
| 420 | g_slice_free (CheckData, data); |
| 421 | } |
| 422 | @@ -97,9 +97,8 @@ http_client_check_auth_data_free (gpoint |
| 423 | g_slice_free (CheckAuthData, auth); |
| 424 | } |
| 425 | |
| 426 | -static void |
| 427 | -http_client_authenticate (SoupSession *session, |
| 428 | - SoupMessage *msg, |
| 429 | +static gboolean |
| 430 | +http_client_authenticate (SoupMessage *msg, |
| 431 | SoupAuth *auth, |
| 432 | gboolean retrying, |
| 433 | gpointer user_data) |
| 434 | @@ -107,26 +106,26 @@ http_client_authenticate (SoupSession *s |
| 435 | CheckAuthData *data = user_data; |
| 436 | |
| 437 | if (retrying) |
| 438 | - return; |
| 439 | + return FALSE; |
| 440 | |
| 441 | soup_auth_authenticate (auth, data->username, data->password); |
| 442 | + return TRUE; |
| 443 | } |
| 444 | |
| 445 | -static void |
| 446 | -http_client_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *socket, gpointer user_data) |
| 447 | +static gboolean |
| 448 | +http_client_accept_certificate (SoupMessage *msg, GTlsCertificate *cert, GTlsCertificateFlags cert_flags, gpointer user_data) |
| 449 | { |
| 450 | CheckData *data; |
| 451 | GTask *task = G_TASK (user_data); |
| 452 | - GTlsCertificateFlags cert_flags; |
| 453 | |
| 454 | g_debug ("goa_http_client_check(): request started (%p)", msg); |
| 455 | |
| 456 | data = (CheckData *) g_task_get_task_data (task); |
| 457 | |
| 458 | - if (!data->accept_ssl_errors |
| 459 | - && soup_message_get_https_status (msg, NULL, &cert_flags) |
| 460 | - && cert_flags != 0 |
| 461 | - && data->error == NULL) |
| 462 | + if (data->accept_ssl_errors || cert_flags == 0) |
| 463 | + return TRUE; |
| 464 | + |
| 465 | + if (data->error == NULL) |
| 466 | { |
| 467 | goa_utils_set_error_ssl (&data->error, cert_flags); |
| 468 | |
| 469 | @@ -135,6 +134,8 @@ http_client_request_started (SoupSession |
| 470 | */ |
| 471 | soup_session_abort (data->session); |
| 472 | } |
| 473 | + |
| 474 | + return FALSE; |
| 475 | } |
| 476 | |
| 477 | static void |
| 478 | @@ -154,21 +155,27 @@ http_client_check_cancelled_cb (GCancell |
| 479 | } |
| 480 | |
| 481 | static void |
| 482 | -http_client_check_response_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) |
| 483 | +http_client_check_response_cb (SoupSession *session, GAsyncResult *result, gpointer user_data) |
| 484 | { |
| 485 | + SoupMessage *msg; |
| 486 | CheckData *data; |
| 487 | - GCancellable *cancellable; |
| 488 | GTask *task = G_TASK (user_data); |
| 489 | + guint status; |
| 490 | + GBytes *body; |
| 491 | + GError *error = NULL; |
| 492 | |
| 493 | - g_debug ("goa_http_client_check(): response (%p, %u)", msg, msg->status_code); |
| 494 | + msg = soup_session_get_async_result_message (session, result); |
| 495 | + |
| 496 | + g_debug ("goa_http_client_check(): response (%p, %u)", msg, soup_message_get_status (msg)); |
| 497 | + |
| 498 | + body = soup_session_send_and_read_finish (session, result, &error); |
| 499 | |
| 500 | data = (CheckData *) g_task_get_task_data (task); |
| 501 | - cancellable = g_task_get_cancellable (task); |
| 502 | |
| 503 | - /* status == SOUP_STATUS_CANCELLED, if we are being aborted by the |
| 504 | + /* G_IO_ERROR_CANCELLED, if we are being aborted by the |
| 505 | * GCancellable or due to an SSL error. |
| 506 | */ |
| 507 | - if (msg->status_code == SOUP_STATUS_CANCELLED) |
| 508 | + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) |
| 509 | { |
| 510 | /* If we are being aborted by the GCancellable then there might |
| 511 | * or might not be an error. The GCancellable can be triggered |
| 512 | @@ -176,20 +183,27 @@ http_client_check_response_cb (SoupSessi |
| 513 | * of events across threads. |
| 514 | */ |
| 515 | if (data->error == NULL) |
| 516 | - g_cancellable_set_error_if_cancelled (cancellable, &data->error); |
| 517 | + g_propagate_error (&data->error, g_steal_pointer (&error)); |
| 518 | |
| 519 | goto out; |
| 520 | } |
| 521 | - else if (msg->status_code != SOUP_STATUS_OK) |
| 522 | + |
| 523 | + status = soup_message_get_status (msg); |
| 524 | + if (status != SOUP_STATUS_OK || error) |
| 525 | { |
| 526 | - g_warning ("goa_http_client_check() failed: %u — %s", msg->status_code, msg->reason_phrase); |
| 527 | + g_warning ("goa_http_client_check() failed: %u — %s", status, soup_message_get_reason_phrase (msg)); |
| 528 | g_return_if_fail (data->error == NULL); |
| 529 | |
| 530 | - goa_utils_set_error_soup (&data->error, msg); |
| 531 | + if (error) |
| 532 | + g_propagate_error (&data->error, g_steal_pointer (&error)); |
| 533 | + else |
| 534 | + goa_utils_set_error_soup (&data->error, msg); |
| 535 | goto out; |
| 536 | } |
| 537 | |
| 538 | out: |
| 539 | + g_clear_error (&error); |
| 540 | + g_clear_pointer (&body, g_bytes_unref); |
| 541 | if (data->error != NULL) |
| 542 | g_task_return_error (task, g_steal_pointer (&data->error)); |
| 543 | else |
| 544 | @@ -225,7 +239,7 @@ goa_http_client_check (GoaHttpClient |
| 545 | data = g_slice_new0 (CheckData); |
| 546 | g_task_set_task_data (task, data, http_client_check_data_free); |
| 547 | |
| 548 | - data->session = soup_session_new_with_options (SOUP_SESSION_SSL_STRICT, FALSE, NULL); |
| 549 | + data->session = soup_session_new (); |
| 550 | |
| 551 | logger = goa_soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); |
| 552 | soup_session_add_feature (data->session, SOUP_SESSION_FEATURE (logger)); |
| 553 | @@ -246,15 +260,21 @@ goa_http_client_check (GoaHttpClient |
| 554 | auth = g_slice_new0 (CheckAuthData); |
| 555 | auth->username = g_strdup (username); |
| 556 | auth->password = g_strdup (password); |
| 557 | - g_signal_connect_data (data->session, |
| 558 | + g_signal_connect_data (data->msg, |
| 559 | "authenticate", |
| 560 | G_CALLBACK (http_client_authenticate), |
| 561 | auth, |
| 562 | http_client_check_auth_data_free, |
| 563 | 0); |
| 564 | |
| 565 | - g_signal_connect (data->session, "request-started", G_CALLBACK (http_client_request_started), task); |
| 566 | - soup_session_queue_message (data->session, data->msg, http_client_check_response_cb, g_object_ref (task)); |
| 567 | + g_signal_connect (data->msg, "accept-certificate", G_CALLBACK (http_client_accept_certificate), task); |
| 568 | + |
| 569 | + soup_session_send_and_read_async (data->session, |
| 570 | + data->msg, |
| 571 | + G_PRIORITY_DEFAULT, |
| 572 | + data->cancellable, |
| 573 | + (GAsyncReadyCallback)http_client_check_response_cb, |
| 574 | + g_object_ref (task)); |
| 575 | |
| 576 | g_object_unref (task); |
| 577 | } |
| 578 | --- a/src/goabackend/goalastfmprovider.c |
| 579 | +++ b/src/goabackend/goalastfmprovider.c |
| 580 | @@ -483,8 +483,7 @@ add_account_cb (GoaManager *manager, GAs |
| 581 | |
| 582 | static void |
| 583 | check_cb (RestProxyCall *call, |
| 584 | - const GError *error, |
| 585 | - GObject *weak_object, |
| 586 | + GAsyncResult *result, |
| 587 | gpointer user_data) |
| 588 | { |
| 589 | AddAccountData *data = user_data; |
| 590 | @@ -494,6 +493,9 @@ check_cb (RestProxyCall *call, |
| 591 | JsonObject *session_obj; |
| 592 | const gchar *payload; |
| 593 | |
| 594 | + if (!rest_proxy_call_invoke_finish (call, result, &data->error)) |
| 595 | + goto out; |
| 596 | + |
| 597 | parser = NULL; |
| 598 | |
| 599 | parser = json_parser_new (); |
| 600 | @@ -562,12 +564,12 @@ on_rest_proxy_call_cancelled_cb (GCancel |
| 601 | } |
| 602 | |
| 603 | static void |
| 604 | -lastfm_login (GoaProvider *provider, |
| 605 | - const gchar *username, |
| 606 | - const gchar *password, |
| 607 | - GCancellable *cancellable, |
| 608 | - RestProxyCallAsyncCallback callback, |
| 609 | - gpointer user_data) |
| 610 | +lastfm_login (GoaProvider *provider, |
| 611 | + const gchar *username, |
| 612 | + const gchar *password, |
| 613 | + GCancellable *cancellable, |
| 614 | + GAsyncReadyCallback callback, |
| 615 | + gpointer user_data) |
| 616 | { |
| 617 | AddAccountData *data = user_data; |
| 618 | RestProxyCall *call; |
| 619 | @@ -598,7 +600,7 @@ lastfm_login (GoaProvider |
| 620 | rest_proxy_call_add_param (call, "api_sig", sig_md5); |
| 621 | rest_proxy_call_add_param (call, "format", "json"); |
| 622 | |
| 623 | - rest_proxy_call_async (call, callback, NULL, data, &data->error); |
| 624 | + rest_proxy_call_invoke_async (call, NULL, callback, data); |
| 625 | |
| 626 | g_signal_connect (cancellable, "cancelled", G_CALLBACK (on_rest_proxy_call_cancelled_cb), call); |
| 627 | |
| 628 | @@ -665,7 +667,7 @@ add_account (GoaProvider *provider, |
| 629 | username, |
| 630 | password, |
| 631 | data.cancellable, |
| 632 | - (RestProxyCallAsyncCallback) check_cb, |
| 633 | + (GAsyncReadyCallback) check_cb, |
| 634 | &data); |
| 635 | |
| 636 | gtk_widget_set_sensitive (data.connect_button, FALSE); |
| 637 | @@ -819,7 +821,7 @@ refresh_account (GoaProvider *provide |
| 638 | username, |
| 639 | password, |
| 640 | data.cancellable, |
| 641 | - (RestProxyCallAsyncCallback) check_cb, |
| 642 | + (GAsyncReadyCallback) check_cb, |
| 643 | &data); |
| 644 | gtk_widget_set_sensitive (data.connect_button, FALSE); |
| 645 | gtk_widget_show (data.progress_grid); |
| 646 | --- a/src/goabackend/goaoauth2provider.c |
| 647 | +++ b/src/goabackend/goaoauth2provider.c |
| 648 | @@ -95,11 +95,15 @@ is_authorization_error (GError *error) |
| 649 | g_return_val_if_fail (error != NULL, FALSE); |
| 650 | |
| 651 | ret = FALSE; |
| 652 | - if (error->domain == REST_PROXY_ERROR || error->domain == SOUP_HTTP_ERROR) |
| 653 | + if (error->domain == REST_PROXY_ERROR) |
| 654 | { |
| 655 | if (SOUP_STATUS_IS_CLIENT_ERROR (error->code)) |
| 656 | ret = TRUE; |
| 657 | } |
| 658 | + else if (g_error_matches (error, GOA_ERROR, GOA_ERROR_NOT_AUTHORIZED)) |
| 659 | + { |
| 660 | + ret = TRUE; |
| 661 | + } |
| 662 | return ret; |
| 663 | } |
| 664 | |
| 665 | --- a/src/goabackend/goaoauthprovider.c |
| 666 | +++ b/src/goabackend/goaoauthprovider.c |
| 667 | @@ -77,11 +77,15 @@ is_authorization_error (GError *error) |
| 668 | g_return_val_if_fail (error != NULL, FALSE); |
| 669 | |
| 670 | ret = FALSE; |
| 671 | - if (error->domain == REST_PROXY_ERROR || error->domain == SOUP_HTTP_ERROR) |
| 672 | + if (error->domain == REST_PROXY_ERROR) |
| 673 | { |
| 674 | if (SOUP_STATUS_IS_CLIENT_ERROR (error->code)) |
| 675 | ret = TRUE; |
| 676 | } |
| 677 | + else if (g_error_matches (error, GOA_ERROR, GOA_ERROR_NOT_AUTHORIZED)) |
| 678 | + { |
| 679 | + ret = TRUE; |
| 680 | + } |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | @@ -701,9 +705,15 @@ on_web_view_decide_policy (WebKitWebView |
| 685 | } |
| 686 | |
| 687 | static void |
| 688 | -rest_proxy_call_cb (RestProxyCall *call, const GError *error, GObject *weak_object, gpointer user_data) |
| 689 | +rest_proxy_call_cb (GObject *source, GAsyncResult *result, gpointer user_data) |
| 690 | { |
| 691 | + RestProxyCall *call = REST_PROXY_CALL (source); |
| 692 | IdentifyData *data = user_data; |
| 693 | + |
| 694 | + if (!rest_proxy_call_invoke_finish (call, result, &data->error)) |
| 695 | + { |
| 696 | + g_prefix_error (&data->error, _("Error getting a Request Token: ")); |
| 697 | + } |
| 698 | g_main_loop_quit (data->loop); |
| 699 | } |
| 700 | |
| 701 | @@ -770,11 +780,7 @@ get_tokens_and_identity (GoaOAuthProvide |
| 702 | for (n = 0; request_params[n] != NULL; n += 2) |
| 703 | rest_proxy_call_add_param (call, request_params[n], request_params[n+1]); |
| 704 | } |
| 705 | - if (!rest_proxy_call_async (call, rest_proxy_call_cb, NULL, &data, &data.error)) |
| 706 | - { |
| 707 | - g_prefix_error (&data.error, _("Error getting a Request Token: ")); |
| 708 | - goto out; |
| 709 | - } |
| 710 | + rest_proxy_call_invoke_async (call, NULL, rest_proxy_call_cb, &data); |
| 711 | |
| 712 | goa_utils_set_dialog_title (GOA_PROVIDER (provider), dialog, add_account); |
| 713 | |
| 714 | @@ -796,6 +802,9 @@ get_tokens_and_identity (GoaOAuthProvide |
| 715 | g_main_loop_run (data.loop); |
| 716 | gtk_container_remove (GTK_CONTAINER (grid), spinner); |
| 717 | |
| 718 | + if (data.error) |
| 719 | + goto out; |
| 720 | + |
| 721 | if (rest_proxy_call_get_status_code (call) != 200) |
| 722 | { |
| 723 | gchar *msg; |
| 724 | --- a/src/goabackend/goarestproxy.h |
| 725 | +++ b/src/goabackend/goarestproxy.h |
| 726 | @@ -27,8 +27,6 @@ |
| 727 | |
| 728 | G_BEGIN_DECLS |
| 729 | |
| 730 | -G_DEFINE_AUTOPTR_CLEANUP_FUNC (RestProxy, g_object_unref); |
| 731 | - |
| 732 | #define GOA_TYPE_REST_PROXY (goa_rest_proxy_get_type ()) |
| 733 | G_DECLARE_FINAL_TYPE (GoaRestProxy, goa_rest_proxy, GOA, REST_PROXY, RestProxy); |
| 734 | |
| 735 | --- a/src/goabackend/goasouplogger.c |
| 736 | +++ b/src/goabackend/goasouplogger.c |
| 737 | @@ -22,15 +22,6 @@ |
| 738 | |
| 739 | #include "goasouplogger.h" |
| 740 | |
| 741 | -struct _GoaSoupLogger |
| 742 | -{ |
| 743 | - SoupLogger parent_instance; |
| 744 | -}; |
| 745 | - |
| 746 | -G_DEFINE_TYPE (GoaSoupLogger, goa_soup_logger, SOUP_TYPE_LOGGER); |
| 747 | - |
| 748 | -/* ---------------------------------------------------------------------------------------------------- */ |
| 749 | - |
| 750 | static void |
| 751 | goa_soup_logger_printer (SoupLogger *logger, |
| 752 | SoupLoggerLogLevel level, |
| 753 | @@ -45,24 +36,16 @@ goa_soup_logger_printer (SoupLogger |
| 754 | g_free (message); |
| 755 | } |
| 756 | |
| 757 | -/* ---------------------------------------------------------------------------------------------------- */ |
| 758 | - |
| 759 | -static void |
| 760 | -goa_soup_logger_init (GoaSoupLogger *self) |
| 761 | -{ |
| 762 | - soup_logger_set_printer (SOUP_LOGGER (self), goa_soup_logger_printer, NULL, NULL); |
| 763 | -} |
| 764 | - |
| 765 | -static void |
| 766 | -goa_soup_logger_class_init (GoaSoupLoggerClass *klass) |
| 767 | -{ |
| 768 | -} |
| 769 | - |
| 770 | -/* ---------------------------------------------------------------------------------------------------- */ |
| 771 | - |
| 772 | SoupLogger * |
| 773 | goa_soup_logger_new (SoupLoggerLogLevel level, |
| 774 | gint max_body_size) |
| 775 | { |
| 776 | - return g_object_new (GOA_TYPE_SOUP_LOGGER, "level", level, "max-body-size", max_body_size, NULL); |
| 777 | + SoupLogger *logger; |
| 778 | + |
| 779 | + logger = soup_logger_new (level); |
| 780 | + if (max_body_size != -1) |
| 781 | + soup_logger_set_max_body_size (logger, max_body_size); |
| 782 | + soup_logger_set_printer (logger, goa_soup_logger_printer, NULL, NULL); |
| 783 | + |
| 784 | + return logger; |
| 785 | } |
| 786 | --- a/src/goabackend/goasouplogger.h |
| 787 | +++ b/src/goabackend/goasouplogger.h |
| 788 | @@ -27,9 +27,6 @@ |
| 789 | |
| 790 | G_BEGIN_DECLS |
| 791 | |
| 792 | -#define GOA_TYPE_SOUP_LOGGER (goa_soup_logger_get_type ()) |
| 793 | -G_DECLARE_FINAL_TYPE (GoaSoupLogger, goa_soup_logger, GOA, SOUP_LOGGER, SoupLogger); |
| 794 | - |
| 795 | SoupLogger *goa_soup_logger_new (SoupLoggerLogLevel level, |
| 796 | gint max_body_size); |
| 797 | |
| 798 | --- a/src/goabackend/goautils.c |
| 799 | +++ b/src/goabackend/goautils.c |
| 800 | @@ -841,29 +841,26 @@ goa_utils_set_error_soup (GError **err, |
| 801 | { |
| 802 | gchar *error_msg = NULL; |
| 803 | gint error_code = GOA_ERROR_FAILED; /* TODO: more specific */ |
| 804 | + guint status_code; |
| 805 | |
| 806 | - switch (msg->status_code) |
| 807 | + status_code = soup_message_get_status (msg); |
| 808 | + switch (status_code) |
| 809 | { |
| 810 | - case SOUP_STATUS_CANT_RESOLVE: |
| 811 | - error_msg = g_strdup (_("Cannot resolve hostname")); |
| 812 | - break; |
| 813 | - |
| 814 | - case SOUP_STATUS_CANT_RESOLVE_PROXY: |
| 815 | - error_msg = g_strdup (_("Cannot resolve proxy hostname")); |
| 816 | - break; |
| 817 | - |
| 818 | case SOUP_STATUS_INTERNAL_SERVER_ERROR: |
| 819 | case SOUP_STATUS_NOT_FOUND: |
| 820 | error_msg = g_strdup (_("Cannot find WebDAV endpoint")); |
| 821 | break; |
| 822 | |
| 823 | - case SOUP_STATUS_UNAUTHORIZED: |
| 824 | - error_msg = g_strdup (_("Authentication failed")); |
| 825 | - error_code = GOA_ERROR_NOT_AUTHORIZED; |
| 826 | - break; |
| 827 | - |
| 828 | default: |
| 829 | - error_msg = g_strdup_printf (_("Code: %u — Unexpected response from server"), msg->status_code); |
| 830 | + if (SOUP_STATUS_IS_CLIENT_ERROR (status_code)) |
| 831 | + { |
| 832 | + error_msg = g_strdup (_("Authentication failed")); |
| 833 | + error_code = GOA_ERROR_NOT_AUTHORIZED; |
| 834 | + } |
| 835 | + else |
| 836 | + { |
| 837 | + error_msg = g_strdup_printf (_("Code: %u — Unexpected response from server"), status_code); |
| 838 | + } |
| 839 | break; |
| 840 | } |
| 841 | |