blob: 0f959084a2ff3282072c308e6e363887b8996e8e [file] [log] [blame]
From 7d8c5208d095ce8e7123935263ef7a02f0381ae5 Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <cgarcia@igalia.com>
Date: Mon, 7 Jun 2021 18:28:42 +0200
Subject: [PATCH 2/2] Port to libsoup3
Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/gnome-online-accounts/-/merge_requests/73]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
configure.ac | 8 +-
src/daemon/goadaemon.c | 2 +-
src/goabackend/goaewsclient.c | 178 +++++++++++++++--------------
src/goabackend/goahttpclient.c | 72 +++++++-----
src/goabackend/goalastfmprovider.c | 24 ++--
src/goabackend/goaoauth2provider.c | 6 +-
src/goabackend/goaoauthprovider.c | 23 ++--
src/goabackend/goarestproxy.h | 2 -
src/goabackend/goasouplogger.c | 33 ++----
src/goabackend/goasouplogger.h | 3 -
src/goabackend/goautils.c | 27 ++---
11 files changed, 199 insertions(+), 179 deletions(-)
--- a/configure.ac
+++ b/configure.ac
@@ -113,15 +113,15 @@ if test "$enable_backend" != "no"; then
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
- PKG_CHECK_MODULES(JAVASCRIPT_CORE_GTK, [javascriptcoregtk-4.0 >= 2.12.0])
+ PKG_CHECK_MODULES(JAVASCRIPT_CORE_GTK, [javascriptcoregtk-4.1 >= 2.33.1])
AC_SUBST(JAVASCRIPT_CORE_GTK_CFLAGS)
AC_SUBST(JAVASCRIPT_CORE_GTK_LIBS)
- PKG_CHECK_MODULES(WEBKIT_GTK, [webkit2gtk-4.0 >= 2.26.0])
+ PKG_CHECK_MODULES(WEBKIT_GTK, [webkit2gtk-4.1 >= 2.33.1])
AC_SUBST(WEBKIT_GTK_CFLAGS)
AC_SUBST(WEBKIT_GTK_LIBS)
- PKG_CHECK_MODULES(LIBSOUP, [libsoup-2.4 >= 2.42])
+ PKG_CHECK_MODULES(LIBSOUP, [libsoup-3.0 >= 2.99.8])
AC_SUBST(LIBSOUP_CFLAGS)
AC_SUBST(LIBSOUP_LIBS)
@@ -129,7 +129,7 @@ if test "$enable_backend" != "no"; then
AC_SUBST(JSON_GLIB_CFLAGS)
AC_SUBST(JSON_GLIB_LIBS)
- PKG_CHECK_MODULES(REST, [rest-0.7])
+ PKG_CHECK_MODULES(REST, [rest-1.0])
AC_SUBST(REST_CFLAGS)
AC_SUBST(REST_LIBS)
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -1496,7 +1496,7 @@ is_authorization_error (GError *error)
g_return_val_if_fail (error != NULL, FALSE);
ret = FALSE;
- if (error->domain == REST_PROXY_ERROR || error->domain == SOUP_HTTP_ERROR)
+ if (error->domain == REST_PROXY_ERROR)
{
if (SOUP_STATUS_IS_CLIENT_ERROR (error->code))
ret = TRUE;
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -63,6 +63,12 @@ goa_ews_client_new (void)
typedef struct
{
+ gchar *password;
+ gchar *username;
+} AutodiscoverAuthData;
+
+typedef struct
+{
GCancellable *cancellable;
GError *error;
SoupMessage *msgs[2];
@@ -71,13 +77,16 @@ typedef struct
guint pending;
gulong cancellable_id;
xmlOutputBuffer *buf;
+ AutodiscoverAuthData *auth;
} AutodiscoverData;
-typedef struct
+static void
+ews_client_autodiscover_auth_data_free (AutodiscoverAuthData *auth)
{
- gchar *password;
- gchar *username;
-} AutodiscoverAuthData;
+ g_free (auth->password);
+ g_free (auth->username);
+ g_slice_free (AutodiscoverAuthData, auth);
+}
static void
ews_client_autodiscover_data_free (gpointer user_data)
@@ -92,22 +101,12 @@ ews_client_autodiscover_data_free (gpoin
g_clear_error (&data->error);
- /* soup_session_queue_message stole the references to data->msgs */
xmlOutputBufferClose (data->buf);
+ g_clear_pointer (&data->auth, ews_client_autodiscover_auth_data_free);
g_object_unref (data->session);
g_slice_free (AutodiscoverData, data);
}
-static void
-ews_client_autodiscover_auth_data_free (gpointer data, GClosure *closure)
-{
- AutodiscoverAuthData *auth = data;
-
- g_free (auth->password);
- g_free (auth->username);
- g_slice_free (AutodiscoverAuthData, auth);
-}
-
static gboolean
ews_client_check_node (const xmlNode *node, const gchar *name)
{
@@ -115,9 +114,8 @@ ews_client_check_node (const xmlNode *no
return node->type == XML_ELEMENT_NODE && !g_strcmp0 ((gchar *) node->name, name);
}
-static void
-ews_client_authenticate (SoupSession *session,
- SoupMessage *msg,
+static gboolean
+ews_client_authenticate (SoupMessage *msg,
SoupAuth *auth,
gboolean retrying,
gpointer user_data)
@@ -125,26 +123,26 @@ ews_client_authenticate (SoupSession *se
AutodiscoverAuthData *data = user_data;
if (retrying)
- return;
+ return FALSE;
soup_auth_authenticate (auth, data->username, data->password);
+ return TRUE;
}
-static void
-ews_client_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *socket, gpointer user_data)
+static gboolean
+ews_client_accept_certificate (SoupMessage *msg, GTlsCertificate *cert, GTlsCertificateFlags cert_flags, gpointer user_data)
{
AutodiscoverData *data;
GTask *task = G_TASK (user_data);
- GTlsCertificateFlags cert_flags;
- g_debug ("goa_ews_client_autodiscover(): request started (%p)", msg);
+ g_debug ("goa_ews_client_autodiscover(): accept certificate for request (%p)", msg);
data = (AutodiscoverData *) g_task_get_task_data (task);
- if (!data->accept_ssl_errors
- && soup_message_get_https_status (msg, NULL, &cert_flags)
- && cert_flags != 0
- && data->error == NULL)
+ if (data->accept_ssl_errors || cert_flags == 0)
+ return TRUE;
+
+ if (data->error == NULL)
{
goa_utils_set_error_ssl (&data->error, cert_flags);
@@ -153,6 +151,8 @@ ews_client_request_started (SoupSession
*/
soup_session_abort (data->session);
}
+
+ return FALSE;
}
static void
@@ -192,8 +192,10 @@ ews_client_autodiscover_parse_protocol (
}
static void
-ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
+ews_client_autodiscover_response_cb (SoupSession *session, GAsyncResult *result, gpointer user_data)
{
+ SoupMessage *msg;
+ GBytes *body;
GError *error = NULL;
AutodiscoverData *data;
GTask *task = G_TASK (user_data);
@@ -204,7 +206,11 @@ ews_client_autodiscover_response_cb (Sou
xmlDoc *doc;
xmlNode *node;
- g_debug ("goa_ews_client_autodiscover(): response (%p, %u)", msg, msg->status_code);
+ msg = soup_session_get_async_result_message (session, result);
+
+ g_debug ("goa_ews_client_autodiscover(): response (%p, %u)", msg, soup_message_get_status (msg));
+
+ body = soup_session_send_and_read_finish (session, result, &error);
data = (AutodiscoverData *) g_task_get_task_data (task);
size = sizeof (data->msgs) / sizeof (data->msgs[0]);
@@ -215,16 +221,19 @@ ews_client_autodiscover_response_cb (Sou
break;
}
if (idx == size || data->pending == 0)
- return;
+ {
+ g_bytes_unref (body);
+ g_clear_object (&error);
+ g_object_unref (msg);
+ return;
+ }
data->msgs[idx] = NULL;
- status = msg->status_code;
-
- /* status == SOUP_STATUS_CANCELLED, if we are being aborted by the
+ /* G_IO_ERROR_CANCELLED, if we are being aborted by the
* GCancellable, an SSL error or another message that was
* successful.
*/
- if (status == SOUP_STATUS_CANCELLED)
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
/* If we are being aborted by the GCancellable, then the
* GTask is responsible for setting the GError automatically.
@@ -235,21 +244,23 @@ ews_client_autodiscover_response_cb (Sou
*/
goto out;
}
- else if (status != SOUP_STATUS_OK)
+
+ status = soup_message_get_status (msg);
+ if (status != SOUP_STATUS_OK || error)
{
- g_warning ("goa_ews_client_autodiscover() failed: %u — %s", msg->status_code, msg->reason_phrase);
+ g_warning ("goa_ews_client_autodiscover() failed: %u — %s", status, soup_message_get_reason_phrase (msg));
g_return_if_fail (data->error == NULL);
- goa_utils_set_error_soup (&error, msg);
+ if (!error)
+ goa_utils_set_error_soup (&error, msg);
goto out;
}
- soup_buffer_free (soup_message_body_flatten (SOUP_MESSAGE (msg)->response_body));
g_debug ("The response headers");
g_debug ("===================");
- g_debug ("%s", SOUP_MESSAGE (msg)->response_body->data);
+ g_debug ("%s", (char *)g_bytes_get_data (body, NULL));
- doc = xmlReadMemory (msg->response_body->data, msg->response_body->length, "autodiscover.xml", NULL, 0);
+ doc = xmlReadMemory (g_bytes_get_data (body, NULL), g_bytes_get_size (body), "autodiscover.xml", NULL, 0);
if (doc == NULL)
{
g_set_error (&error,
@@ -333,7 +344,7 @@ ews_client_autodiscover_response_cb (Sou
/* The callback (ie. this function) will be invoked after we
* have returned to the main loop.
*/
- soup_session_cancel_message (data->session, data->msgs[idx], SOUP_STATUS_CANCELLED);
+ g_cancellable_cancel (data->cancellable);
}
}
@@ -368,6 +379,7 @@ ews_client_autodiscover_response_cb (Sou
g_clear_error (&error);
g_object_unref (task);
+ g_object_unref (msg);
}
static xmlDoc *
@@ -399,52 +411,54 @@ static void
ews_client_post_restarted_cb (SoupMessage *msg, gpointer data)
{
xmlOutputBuffer *buf = data;
+ GBytes *body;
/* In violation of RFC2616, libsoup will change a POST request to
* a GET on receiving a 302 redirect.
*/
g_debug ("Working around libsoup bug with redirect");
- g_object_set (msg, SOUP_MESSAGE_METHOD, "POST", NULL);
+ g_object_set (msg, "method", "POST", NULL);
- soup_message_set_request(msg,
- "text/xml; charset=utf-8",
- SOUP_MEMORY_COPY,
#ifdef LIBXML2_NEW_BUFFER
- (gchar *) xmlOutputBufferGetContent(buf),
- xmlOutputBufferGetSize(buf));
+ body = g_bytes_new (xmlOutputBufferGetContent (buf), xmlOutputBufferGetSize (buf));
#else
- (gchar *) buf->buffer->content,
- buf->buffer->use);
+ body = g_bytes_new (buf->buffer->content, buf->buffer->use);
#endif
+ soup_message_set_request_body_from_bytes (msg, "text/xml; charset=utf-8", body);
+ g_bytes_unref (body);
}
static SoupMessage *
-ews_client_create_msg_for_url (const gchar *url, xmlOutputBuffer *buf)
+ews_client_create_msg_for_url (const gchar *url, xmlOutputBuffer *buf, AutodiscoverAuthData *auth, GTask *task)
{
SoupMessage *msg;
+ GBytes *body = NULL;
msg = soup_message_new (buf != NULL ? "POST" : "GET", url);
- soup_message_headers_append (msg->request_headers, "User-Agent", "libews/0.1");
+ soup_message_headers_append (soup_message_get_request_headers (msg),
+ "User-Agent", "libews/0.1");
+
+ g_signal_connect (msg, "authenticate",
+ G_CALLBACK (ews_client_authenticate),
+ auth);
+ g_signal_connect (msg, "accept-certificate",
+ G_CALLBACK (ews_client_accept_certificate),
+ task);
if (buf != NULL)
{
- soup_message_set_request (msg,
- "text/xml; charset=utf-8",
- SOUP_MEMORY_COPY,
#ifdef LIBXML2_NEW_BUFFER
- (gchar *) xmlOutputBufferGetContent(buf),
- xmlOutputBufferGetSize(buf));
+ body = g_bytes_new (xmlOutputBufferGetContent (buf), xmlOutputBufferGetSize (buf));
#else
- (gchar *) buf->buffer->content,
- buf->buffer->use);
+ body = g_bytes_new (buf->buffer->content, buf->buffer->use);
#endif
+ soup_message_set_request_body_from_bytes (msg, "text/xml; charset=utf-8", body);
g_signal_connect (msg, "restarted", G_CALLBACK (ews_client_post_restarted_cb), buf);
}
- soup_buffer_free (soup_message_body_flatten (SOUP_MESSAGE (msg)->request_body));
g_debug ("The request headers");
g_debug ("===================");
- g_debug ("%s", SOUP_MESSAGE (msg)->request_body->data);
+ g_debug ("%s", body ? (char *)g_bytes_get_data (body, NULL) : "");
return msg;
}
@@ -497,12 +511,15 @@ goa_ews_client_autodiscover (GoaEwsClien
* (successful) one win.
*/
+ auth = g_slice_new0 (AutodiscoverAuthData);
+ auth->username = g_strdup (username);
+ auth->password = g_strdup (password);
+ data->auth = auth;
data->buf = buf;
- data->msgs[0] = ews_client_create_msg_for_url (url1, buf);
- data->msgs[1] = ews_client_create_msg_for_url (url2, buf);
+ data->msgs[0] = ews_client_create_msg_for_url (url1, buf, auth, task);
+ data->msgs[1] = ews_client_create_msg_for_url (url2, buf, auth, task);
data->pending = sizeof (data->msgs) / sizeof (data->msgs[0]);
- data->session = soup_session_new_with_options (SOUP_SESSION_SSL_STRICT, FALSE,
- NULL);
+ data->session = soup_session_new ();
soup_session_add_feature_by_type (data->session, SOUP_TYPE_AUTH_NTLM);
data->accept_ssl_errors = accept_ssl_errors;
@@ -515,26 +532,19 @@ goa_ews_client_autodiscover (GoaEwsClien
NULL);
}
- auth = g_slice_new0 (AutodiscoverAuthData);
- auth->username = g_strdup (username);
- auth->password = g_strdup (password);
- g_signal_connect_data (data->session,
- "authenticate",
- G_CALLBACK (ews_client_authenticate),
- auth,
- ews_client_autodiscover_auth_data_free,
- 0);
-
- g_signal_connect (data->session, "request-started", G_CALLBACK (ews_client_request_started), task);
-
- soup_session_queue_message (data->session,
- data->msgs[0],
- ews_client_autodiscover_response_cb,
- g_object_ref (task));
- soup_session_queue_message (data->session,
- data->msgs[1],
- ews_client_autodiscover_response_cb,
- g_object_ref (task));
+
+ soup_session_send_and_read_async (data->session,
+ data->msgs[0],
+ G_PRIORITY_DEFAULT,
+ data->cancellable,
+ (GAsyncReadyCallback)ews_client_autodiscover_response_cb,
+ g_object_ref (task));
+ soup_session_send_and_read_async (data->session,
+ data->msgs[1],
+ G_PRIORITY_DEFAULT,
+ data->cancellable,
+ (GAsyncReadyCallback)ews_client_autodiscover_response_cb,
+ g_object_ref (task));
g_free (url2);
g_free (url1);
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -82,7 +82,7 @@ http_client_check_data_free (gpointer us
g_clear_error (&data->error);
- /* soup_session_queue_message stole the references to data->msg */
+ g_object_unref (data->msg);
g_object_unref (data->session);
g_slice_free (CheckData, data);
}
@@ -97,9 +97,8 @@ http_client_check_auth_data_free (gpoint
g_slice_free (CheckAuthData, auth);
}
-static void
-http_client_authenticate (SoupSession *session,
- SoupMessage *msg,
+static gboolean
+http_client_authenticate (SoupMessage *msg,
SoupAuth *auth,
gboolean retrying,
gpointer user_data)
@@ -107,26 +106,26 @@ http_client_authenticate (SoupSession *s
CheckAuthData *data = user_data;
if (retrying)
- return;
+ return FALSE;
soup_auth_authenticate (auth, data->username, data->password);
+ return TRUE;
}
-static void
-http_client_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *socket, gpointer user_data)
+static gboolean
+http_client_accept_certificate (SoupMessage *msg, GTlsCertificate *cert, GTlsCertificateFlags cert_flags, gpointer user_data)
{
CheckData *data;
GTask *task = G_TASK (user_data);
- GTlsCertificateFlags cert_flags;
g_debug ("goa_http_client_check(): request started (%p)", msg);
data = (CheckData *) g_task_get_task_data (task);
- if (!data->accept_ssl_errors
- && soup_message_get_https_status (msg, NULL, &cert_flags)
- && cert_flags != 0
- && data->error == NULL)
+ if (data->accept_ssl_errors || cert_flags == 0)
+ return TRUE;
+
+ if (data->error == NULL)
{
goa_utils_set_error_ssl (&data->error, cert_flags);
@@ -135,6 +134,8 @@ http_client_request_started (SoupSession
*/
soup_session_abort (data->session);
}
+
+ return FALSE;
}
static void
@@ -154,21 +155,27 @@ http_client_check_cancelled_cb (GCancell
}
static void
-http_client_check_response_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
+http_client_check_response_cb (SoupSession *session, GAsyncResult *result, gpointer user_data)
{
+ SoupMessage *msg;
CheckData *data;
- GCancellable *cancellable;
GTask *task = G_TASK (user_data);
+ guint status;
+ GBytes *body;
+ GError *error = NULL;
- g_debug ("goa_http_client_check(): response (%p, %u)", msg, msg->status_code);
+ msg = soup_session_get_async_result_message (session, result);
+
+ g_debug ("goa_http_client_check(): response (%p, %u)", msg, soup_message_get_status (msg));
+
+ body = soup_session_send_and_read_finish (session, result, &error);
data = (CheckData *) g_task_get_task_data (task);
- cancellable = g_task_get_cancellable (task);
- /* status == SOUP_STATUS_CANCELLED, if we are being aborted by the
+ /* G_IO_ERROR_CANCELLED, if we are being aborted by the
* GCancellable or due to an SSL error.
*/
- if (msg->status_code == SOUP_STATUS_CANCELLED)
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
/* If we are being aborted by the GCancellable then there might
* or might not be an error. The GCancellable can be triggered
@@ -176,20 +183,27 @@ http_client_check_response_cb (SoupSessi
* of events across threads.
*/
if (data->error == NULL)
- g_cancellable_set_error_if_cancelled (cancellable, &data->error);
+ g_propagate_error (&data->error, g_steal_pointer (&error));
goto out;
}
- else if (msg->status_code != SOUP_STATUS_OK)
+
+ status = soup_message_get_status (msg);
+ if (status != SOUP_STATUS_OK || error)
{
- g_warning ("goa_http_client_check() failed: %u — %s", msg->status_code, msg->reason_phrase);
+ g_warning ("goa_http_client_check() failed: %u — %s", status, soup_message_get_reason_phrase (msg));
g_return_if_fail (data->error == NULL);
- goa_utils_set_error_soup (&data->error, msg);
+ if (error)
+ g_propagate_error (&data->error, g_steal_pointer (&error));
+ else
+ goa_utils_set_error_soup (&data->error, msg);
goto out;
}
out:
+ g_clear_error (&error);
+ g_clear_pointer (&body, g_bytes_unref);
if (data->error != NULL)
g_task_return_error (task, g_steal_pointer (&data->error));
else
@@ -225,7 +239,7 @@ goa_http_client_check (GoaHttpClient
data = g_slice_new0 (CheckData);
g_task_set_task_data (task, data, http_client_check_data_free);
- data->session = soup_session_new_with_options (SOUP_SESSION_SSL_STRICT, FALSE, NULL);
+ data->session = soup_session_new ();
logger = goa_soup_logger_new (SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature (data->session, SOUP_SESSION_FEATURE (logger));
@@ -246,15 +260,21 @@ goa_http_client_check (GoaHttpClient
auth = g_slice_new0 (CheckAuthData);
auth->username = g_strdup (username);
auth->password = g_strdup (password);
- g_signal_connect_data (data->session,
+ g_signal_connect_data (data->msg,
"authenticate",
G_CALLBACK (http_client_authenticate),
auth,
http_client_check_auth_data_free,
0);
- g_signal_connect (data->session, "request-started", G_CALLBACK (http_client_request_started), task);
- soup_session_queue_message (data->session, data->msg, http_client_check_response_cb, g_object_ref (task));
+ g_signal_connect (data->msg, "accept-certificate", G_CALLBACK (http_client_accept_certificate), task);
+
+ soup_session_send_and_read_async (data->session,
+ data->msg,
+ G_PRIORITY_DEFAULT,
+ data->cancellable,
+ (GAsyncReadyCallback)http_client_check_response_cb,
+ g_object_ref (task));
g_object_unref (task);
}
--- a/src/goabackend/goalastfmprovider.c
+++ b/src/goabackend/goalastfmprovider.c
@@ -483,8 +483,7 @@ add_account_cb (GoaManager *manager, GAs
static void
check_cb (RestProxyCall *call,
- const GError *error,
- GObject *weak_object,
+ GAsyncResult *result,
gpointer user_data)
{
AddAccountData *data = user_data;
@@ -494,6 +493,9 @@ check_cb (RestProxyCall *call,
JsonObject *session_obj;
const gchar *payload;
+ if (!rest_proxy_call_invoke_finish (call, result, &data->error))
+ goto out;
+
parser = NULL;
parser = json_parser_new ();
@@ -562,12 +564,12 @@ on_rest_proxy_call_cancelled_cb (GCancel
}
static void
-lastfm_login (GoaProvider *provider,
- const gchar *username,
- const gchar *password,
- GCancellable *cancellable,
- RestProxyCallAsyncCallback callback,
- gpointer user_data)
+lastfm_login (GoaProvider *provider,
+ const gchar *username,
+ const gchar *password,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
AddAccountData *data = user_data;
RestProxyCall *call;
@@ -598,7 +600,7 @@ lastfm_login (GoaProvider
rest_proxy_call_add_param (call, "api_sig", sig_md5);
rest_proxy_call_add_param (call, "format", "json");
- rest_proxy_call_async (call, callback, NULL, data, &data->error);
+ rest_proxy_call_invoke_async (call, NULL, callback, data);
g_signal_connect (cancellable, "cancelled", G_CALLBACK (on_rest_proxy_call_cancelled_cb), call);
@@ -665,7 +667,7 @@ add_account (GoaProvider *provider,
username,
password,
data.cancellable,
- (RestProxyCallAsyncCallback) check_cb,
+ (GAsyncReadyCallback) check_cb,
&data);
gtk_widget_set_sensitive (data.connect_button, FALSE);
@@ -819,7 +821,7 @@ refresh_account (GoaProvider *provide
username,
password,
data.cancellable,
- (RestProxyCallAsyncCallback) check_cb,
+ (GAsyncReadyCallback) check_cb,
&data);
gtk_widget_set_sensitive (data.connect_button, FALSE);
gtk_widget_show (data.progress_grid);
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -95,11 +95,15 @@ is_authorization_error (GError *error)
g_return_val_if_fail (error != NULL, FALSE);
ret = FALSE;
- if (error->domain == REST_PROXY_ERROR || error->domain == SOUP_HTTP_ERROR)
+ if (error->domain == REST_PROXY_ERROR)
{
if (SOUP_STATUS_IS_CLIENT_ERROR (error->code))
ret = TRUE;
}
+ else if (g_error_matches (error, GOA_ERROR, GOA_ERROR_NOT_AUTHORIZED))
+ {
+ ret = TRUE;
+ }
return ret;
}
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -77,11 +77,15 @@ is_authorization_error (GError *error)
g_return_val_if_fail (error != NULL, FALSE);
ret = FALSE;
- if (error->domain == REST_PROXY_ERROR || error->domain == SOUP_HTTP_ERROR)
+ if (error->domain == REST_PROXY_ERROR)
{
if (SOUP_STATUS_IS_CLIENT_ERROR (error->code))
ret = TRUE;
}
+ else if (g_error_matches (error, GOA_ERROR, GOA_ERROR_NOT_AUTHORIZED))
+ {
+ ret = TRUE;
+ }
return ret;
}
@@ -701,9 +705,15 @@ on_web_view_decide_policy (WebKitWebView
}
static void
-rest_proxy_call_cb (RestProxyCall *call, const GError *error, GObject *weak_object, gpointer user_data)
+rest_proxy_call_cb (GObject *source, GAsyncResult *result, gpointer user_data)
{
+ RestProxyCall *call = REST_PROXY_CALL (source);
IdentifyData *data = user_data;
+
+ if (!rest_proxy_call_invoke_finish (call, result, &data->error))
+ {
+ g_prefix_error (&data->error, _("Error getting a Request Token: "));
+ }
g_main_loop_quit (data->loop);
}
@@ -770,11 +780,7 @@ get_tokens_and_identity (GoaOAuthProvide
for (n = 0; request_params[n] != NULL; n += 2)
rest_proxy_call_add_param (call, request_params[n], request_params[n+1]);
}
- if (!rest_proxy_call_async (call, rest_proxy_call_cb, NULL, &data, &data.error))
- {
- g_prefix_error (&data.error, _("Error getting a Request Token: "));
- goto out;
- }
+ rest_proxy_call_invoke_async (call, NULL, rest_proxy_call_cb, &data);
goa_utils_set_dialog_title (GOA_PROVIDER (provider), dialog, add_account);
@@ -796,6 +802,9 @@ get_tokens_and_identity (GoaOAuthProvide
g_main_loop_run (data.loop);
gtk_container_remove (GTK_CONTAINER (grid), spinner);
+ if (data.error)
+ goto out;
+
if (rest_proxy_call_get_status_code (call) != 200)
{
gchar *msg;
--- a/src/goabackend/goarestproxy.h
+++ b/src/goabackend/goarestproxy.h
@@ -27,8 +27,6 @@
G_BEGIN_DECLS
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (RestProxy, g_object_unref);
-
#define GOA_TYPE_REST_PROXY (goa_rest_proxy_get_type ())
G_DECLARE_FINAL_TYPE (GoaRestProxy, goa_rest_proxy, GOA, REST_PROXY, RestProxy);
--- a/src/goabackend/goasouplogger.c
+++ b/src/goabackend/goasouplogger.c
@@ -22,15 +22,6 @@
#include "goasouplogger.h"
-struct _GoaSoupLogger
-{
- SoupLogger parent_instance;
-};
-
-G_DEFINE_TYPE (GoaSoupLogger, goa_soup_logger, SOUP_TYPE_LOGGER);
-
-/* ---------------------------------------------------------------------------------------------------- */
-
static void
goa_soup_logger_printer (SoupLogger *logger,
SoupLoggerLogLevel level,
@@ -45,24 +36,16 @@ goa_soup_logger_printer (SoupLogger
g_free (message);
}
-/* ---------------------------------------------------------------------------------------------------- */
-
-static void
-goa_soup_logger_init (GoaSoupLogger *self)
-{
- soup_logger_set_printer (SOUP_LOGGER (self), goa_soup_logger_printer, NULL, NULL);
-}
-
-static void
-goa_soup_logger_class_init (GoaSoupLoggerClass *klass)
-{
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
SoupLogger *
goa_soup_logger_new (SoupLoggerLogLevel level,
gint max_body_size)
{
- return g_object_new (GOA_TYPE_SOUP_LOGGER, "level", level, "max-body-size", max_body_size, NULL);
+ SoupLogger *logger;
+
+ logger = soup_logger_new (level);
+ if (max_body_size != -1)
+ soup_logger_set_max_body_size (logger, max_body_size);
+ soup_logger_set_printer (logger, goa_soup_logger_printer, NULL, NULL);
+
+ return logger;
}
--- a/src/goabackend/goasouplogger.h
+++ b/src/goabackend/goasouplogger.h
@@ -27,9 +27,6 @@
G_BEGIN_DECLS
-#define GOA_TYPE_SOUP_LOGGER (goa_soup_logger_get_type ())
-G_DECLARE_FINAL_TYPE (GoaSoupLogger, goa_soup_logger, GOA, SOUP_LOGGER, SoupLogger);
-
SoupLogger *goa_soup_logger_new (SoupLoggerLogLevel level,
gint max_body_size);
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -841,29 +841,26 @@ goa_utils_set_error_soup (GError **err,
{
gchar *error_msg = NULL;
gint error_code = GOA_ERROR_FAILED; /* TODO: more specific */
+ guint status_code;
- switch (msg->status_code)
+ status_code = soup_message_get_status (msg);
+ switch (status_code)
{
- case SOUP_STATUS_CANT_RESOLVE:
- error_msg = g_strdup (_("Cannot resolve hostname"));
- break;
-
- case SOUP_STATUS_CANT_RESOLVE_PROXY:
- error_msg = g_strdup (_("Cannot resolve proxy hostname"));
- break;
-
case SOUP_STATUS_INTERNAL_SERVER_ERROR:
case SOUP_STATUS_NOT_FOUND:
error_msg = g_strdup (_("Cannot find WebDAV endpoint"));
break;
- case SOUP_STATUS_UNAUTHORIZED:
- error_msg = g_strdup (_("Authentication failed"));
- error_code = GOA_ERROR_NOT_AUTHORIZED;
- break;
-
default:
- error_msg = g_strdup_printf (_("Code: %u — Unexpected response from server"), msg->status_code);
+ if (SOUP_STATUS_IS_CLIENT_ERROR (status_code))
+ {
+ error_msg = g_strdup (_("Authentication failed"));
+ error_code = GOA_ERROR_NOT_AUTHORIZED;
+ }
+ else
+ {
+ error_msg = g_strdup_printf (_("Code: %u — Unexpected response from server"), status_code);
+ }
break;
}