[gnome-online-accounts/carlosgc/libsoup3: 1/2] Port to libsoup3
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/carlosgc/libsoup3: 1/2] Port to libsoup3
- Date: Wed, 20 Apr 2022 21:27:39 +0000 (UTC)
commit f9756272c4b3e07c04903b44a58d6faf80584fa2
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Jun 7 18:28:42 2021 +0200
Port to libsoup3
configure.ac | 8 +-
meson.build | 8 +-
src/daemon/goadaemon.c | 2 +-
src/examples/lastfm-shout.c | 3 +-
src/goabackend/goaewsclient.c | 178 +++++++++++++++++---------------
src/goabackend/goafacebookprovider.c | 2 +-
src/goabackend/goaflickrprovider.c | 2 +-
src/goabackend/goafoursquareprovider.c | 2 +-
src/goabackend/goagoogleprovider.c | 2 +-
src/goabackend/goahttpclient.c | 72 ++++++++-----
src/goabackend/goalastfmprovider.c | 26 ++---
src/goabackend/goaoauth2provider.c | 8 +-
src/goabackend/goaoauthprovider.c | 25 +++--
src/goabackend/goaoauthprovider.h | 2 +-
src/goabackend/goarestproxy.h | 4 +-
src/goabackend/goasouplogger.c | 33 ++----
src/goabackend/goasouplogger.h | 3 -
src/goabackend/goautils.c | 27 +++--
src/goabackend/goawindowsliveprovider.c | 2 +-
19 files changed, 214 insertions(+), 195 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 22cdaa40..b49679e3 100644
--- 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)
diff --git a/meson.build b/meson.build
index f123cbc2..f14019f1 100644
--- a/meson.build
+++ b/meson.build
@@ -97,13 +97,13 @@ endif
enable_goabackend = get_option('goabackend')
if enable_goabackend
gtk_dep = dependency('gtk+-3.0', version: '>= 3.19.12')
- javascript_core_gtk_dep = dependency('javascriptcoregtk-4.0', version: '>= 2.12.0')
+ javascript_core_gtk_dep = dependency('javascriptcoregtk-4.1', version: '>= 2.33.1')
json_glib_dep = dependency('json-glib-1.0')
libsecret_dep = dependency('libsecret-1')
- libsoup_dep = dependency('libsoup-2.4', version: '>= 2.42')
+ libsoup_dep = dependency('libsoup-3.0', version: '>= 2.99.8')
libxml_dep = dependency('libxml-2.0')
- rest_dep = dependency('rest-0.7')
- webkit_gtk_dep = dependency('webkit2gtk-4.0', version: '>= 2.26.0')
+ rest_dep = dependency('rest-1.0')
+ webkit_gtk_dep = dependency('webkit2gtk-4.1', version: '>= 2.33.1')
endif
config_h.set('GOA_BACKEND_ENABLED', enable_goabackend)
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 564973e1..e04e0847 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -1494,7 +1494,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;
diff --git a/src/examples/lastfm-shout.c b/src/examples/lastfm-shout.c
index 7b50743a..08cdbfc0 100644
--- a/src/examples/lastfm-shout.c
+++ b/src/examples/lastfm-shout.c
@@ -22,8 +22,7 @@
#include <goa/goa.h>
#include <locale.h>
-#include <rest/rest-proxy.h>
-#include <rest/rest-proxy-call.h>
+#include <rest/rest.h>
int
main (int argc, char **argv)
diff --git a/src/goabackend/goaewsclient.c b/src/goabackend/goaewsclient.c
index 4d1330f5..d6798c71 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -61,6 +61,12 @@ goa_ews_client_new (void)
/* ---------------------------------------------------------------------------------------------------- */
+typedef struct
+{
+ gchar *password;
+ gchar *username;
+} AutodiscoverAuthData;
+
typedef struct
{
GCancellable *cancellable;
@@ -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 (gpointer user_data)
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 *node, const gchar *name)
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 *session,
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 *session, SoupMessage *msg, SoupSocket *
*/
soup_session_abort (data->session);
}
+
+ return FALSE;
}
static void
@@ -192,8 +192,10 @@ ews_client_autodiscover_parse_protocol (xmlNode *node)
}
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 (SoupSession *session, SoupMessage *msg, gpo
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 (SoupSession *session, SoupMessage *msg, gpo
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 (SoupSession *session, SoupMessage *msg, gpo
*/
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 (SoupSession *session, SoupMessage *msg, gpo
/* 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 (SoupSession *session, SoupMessage *msg, gpo
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 (GoaEwsClient *self,
* (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 (GoaEwsClient *self,
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);
diff --git a/src/goabackend/goafacebookprovider.c b/src/goabackend/goafacebookprovider.c
index c6033fbc..d54c2c6a 100644
--- a/src/goabackend/goafacebookprovider.c
+++ b/src/goabackend/goafacebookprovider.c
@@ -19,7 +19,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <rest/rest-proxy.h>
+#include <rest/rest.h>
#include <json-glib/json-glib.h>
#include "goaprovider.h"
diff --git a/src/goabackend/goaflickrprovider.c b/src/goabackend/goaflickrprovider.c
index 702ed1ea..4eb8c115 100644
--- a/src/goabackend/goaflickrprovider.c
+++ b/src/goabackend/goaflickrprovider.c
@@ -20,7 +20,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <rest/oauth-proxy.h>
+#include <rest/rest.h>
#include <json-glib/json-glib.h>
#include "goaprovider.h"
diff --git a/src/goabackend/goafoursquareprovider.c b/src/goabackend/goafoursquareprovider.c
index c1e4146a..34417281 100644
--- a/src/goabackend/goafoursquareprovider.c
+++ b/src/goabackend/goafoursquareprovider.c
@@ -20,7 +20,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <rest/rest-proxy.h>
+#include <rest/rest.h>
#include <json-glib/json-glib.h>
#include "goaprovider.h"
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index d8abf1c8..7d4cd306 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -19,7 +19,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <rest/oauth-proxy.h>
+#include <rest/rest.h>
#include <json-glib/json-glib.h>
#include "goaprovider.h"
diff --git a/src/goabackend/goahttpclient.c b/src/goabackend/goahttpclient.c
index 81aa52d0..3b6857d0 100644
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -82,7 +82,7 @@ http_client_check_data_free (gpointer user_data)
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 (gpointer data, GClosure *closure)
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 *session,
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 *session, SoupMessage *msg, SoupSocket
*/
soup_session_abort (data->session);
}
+
+ return FALSE;
}
static void
@@ -154,21 +155,27 @@ http_client_check_cancelled_cb (GCancellable *cancellable, gpointer user_data)
}
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;
+
+ msg = soup_session_get_async_result_message (session, result);
+
+ g_debug ("goa_http_client_check(): response (%p, %u)", msg, soup_message_get_status (msg));
- g_debug ("goa_http_client_check(): response (%p, %u)", msg, msg->status_code);
+ 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 (SoupSession *session, SoupMessage *msg, gpointer
* 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 *self,
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 *self,
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);
}
diff --git a/src/goabackend/goalastfmprovider.c b/src/goabackend/goalastfmprovider.c
index cb9a6f26..c8e7256e 100644
--- a/src/goabackend/goalastfmprovider.c
+++ b/src/goabackend/goalastfmprovider.c
@@ -19,7 +19,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <rest/rest-proxy.h>
+#include <rest/rest.h>
#include <json-glib/json-glib.h>
#include "goahttpclient.h"
@@ -483,8 +483,7 @@ add_account_cb (GoaManager *manager, GAsyncResult *res, gpointer user_data)
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 (GCancellable *cancellable, RestProxyCall *call)
}
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 *provider,
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 *provider,
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);
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 2757838b..c6323907 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -20,7 +20,7 @@
#include <glib/gi18n-lib.h>
#include <stdlib.h>
-#include <rest/oauth2-proxy.h>
+#include <rest/rest.h>
#include <libsoup/soup.h>
#include <json-glib/json-glib.h>
#include <webkit2/webkit2.h>
@@ -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;
}
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index ff0927ef..8c2e0f27 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -20,7 +20,7 @@
#include <glib/gi18n-lib.h>
#include <stdlib.h>
-#include <rest/oauth-proxy.h>
+#include <rest/rest.h>
#include <libsoup/soup.h>
#include <json-glib/json-glib.h>
#include <webkit2/webkit2.h>
@@ -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 *web_view,
}
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 (GoaOAuthProvider *provider,
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 (GoaOAuthProvider *provider,
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;
diff --git a/src/goabackend/goaoauthprovider.h b/src/goabackend/goaoauthprovider.h
index d4ffa3cd..e42f7a5e 100644
--- a/src/goabackend/goaoauthprovider.h
+++ b/src/goabackend/goaoauthprovider.h
@@ -25,7 +25,7 @@
#include <goabackend/goaprovider.h>
#include <goabackend/goaprovider-priv.h>
-#include <rest/rest-proxy-call.h>
+#include <rest/rest.h>
#include <webkitdom/webkitdom.h>
G_BEGIN_DECLS
diff --git a/src/goabackend/goarestproxy.h b/src/goabackend/goarestproxy.h
index 09fb0762..0241e65e 100644
--- a/src/goabackend/goarestproxy.h
+++ b/src/goabackend/goarestproxy.h
@@ -23,12 +23,10 @@
#ifndef __GOA_REST_PROXY_H__
#define __GOA_REST_PROXY_H__
-#include <rest/rest-proxy.h>
+#include <rest/rest.h>
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);
diff --git a/src/goabackend/goasouplogger.c b/src/goabackend/goasouplogger.c
index 9b0a53d1..330b6a90 100644
--- 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 *logger,
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;
}
diff --git a/src/goabackend/goasouplogger.h b/src/goabackend/goasouplogger.h
index 4a997854..6929dc07 100644
--- 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);
diff --git a/src/goabackend/goautils.c b/src/goabackend/goautils.c
index b23a2585..70d66a6e 100644
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -841,29 +841,26 @@ goa_utils_set_error_soup (GError **err, SoupMessage *msg)
{
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;
}
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index be357465..608767a3 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -20,7 +20,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <rest/rest-proxy.h>
+#include <rest/rest.h>
#include <json-glib/json-glib.h>
#include "goaprovider.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]