[gnome-online-accounts/carlosgc/libsoup3: 2/2] Port to libsoup3
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/carlosgc/libsoup3: 2/2] Port to libsoup3
- Date: Mon, 7 Jun 2021 16:29:32 +0000 (UTC)
commit ee835824e471359a9ec8ce3374b8a46a11943a5b
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Jun 7 18:28:42 2021 +0200
Port to libsoup3
configure.ac | 6 +-
meson.build | 6 +-
src/goabackend/goaewsclient.c | 178 ++++++++++++++++++++-----------------
src/goabackend/goahttpclient.c | 72 +++++++++------
src/goabackend/goaoauth2provider.c | 6 +-
src/goabackend/goaoauthprovider.c | 6 +-
src/goabackend/goasouplogger.c | 33 ++-----
src/goabackend/goasouplogger.h | 3 -
src/goabackend/goautils.c | 27 +++---
9 files changed, 176 insertions(+), 161 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 35d6c269..f3703a34 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)
diff --git a/meson.build b/meson.build
index 5d109382..7cd21a9b 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')
+ webkit_gtk_dep = dependency('webkit2gtk-4.1', version: '>= 2.33.1')
endif
config_h.set('GOA_BACKEND_ENABLED', enable_goabackend)
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/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/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 2757838b..ac28d73b 100644
--- 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;
}
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index ff0927ef..cb7273af 100644
--- 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;
}
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]