[gnome-online-accounts/gnome-3-18] ewsclient, httpclient, utils: Sanitize SOUP_STATUS_UNAUTHORIZED
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts/gnome-3-18] ewsclient, httpclient, utils: Sanitize SOUP_STATUS_UNAUTHORIZED
- Date: Thu, 1 Oct 2015 16:38:36 +0000 (UTC)
commit 20eea6754b865edf19ce69f80a98be91d6b80722
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Sep 17 18:55:48 2015 +0200
ewsclient, httpclient, utils: Sanitize SOUP_STATUS_UNAUTHORIZED
Let's leverage the fact that "Authentication failed" is already used
elsewhere in the code.
https://bugzilla.gnome.org/show_bug.cgi?id=755168
src/goabackend/goaewsclient.c | 7 ++-----
src/goabackend/goahttpclient.c | 7 ++-----
src/goabackend/goautils.c | 22 ++++++++++++++++++++++
src/goabackend/goautils.h | 3 +++
4 files changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/src/goabackend/goaewsclient.c b/src/goabackend/goaewsclient.c
index b10d20c..63026d1 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -231,11 +231,8 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
}
else if (status != SOUP_STATUS_OK)
{
- g_set_error (&error,
- GOA_ERROR,
- GOA_ERROR_FAILED, /* TODO: more specific */
- _("Code: %u — Unexpected response from server"),
- status);
+ g_warning ("goa_ews_client_autodiscover() failed: %u — %s", msg->status_code, msg->reason_phrase);
+ goa_utils_set_error_soup (&error, msg);
goto out;
}
diff --git a/src/goabackend/goahttpclient.c b/src/goabackend/goahttpclient.c
index e61ef01..92e8f1c 100644
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -168,11 +168,8 @@ http_client_check_response_cb (SoupSession *session, SoupMessage *msg, gpointer
goto out;
else if (msg->status_code != SOUP_STATUS_OK)
{
- g_set_error (&error,
- GOA_ERROR,
- GOA_ERROR_FAILED, /* TODO: more specific */
- _("Code: %u — Unexpected response from server"),
- msg->status_code);
+ g_warning ("goa_http_client_check() failed: %u — %s", msg->status_code, msg->reason_phrase);
+ goa_utils_set_error_soup (&error, msg);
goto out;
}
diff --git a/src/goabackend/goautils.c b/src/goabackend/goautils.c
index f2e7529..2433bec 100644
--- a/src/goabackend/goautils.c
+++ b/src/goabackend/goautils.c
@@ -527,6 +527,28 @@ goa_utils_parse_email_address (const gchar *email, gchar **out_username, gchar *
}
void
+goa_utils_set_error_soup (GError **err, SoupMessage *msg)
+{
+ gchar *error_msg = NULL;
+ gint error_code = GOA_ERROR_FAILED; /* TODO: more specific */
+
+ switch (msg->status_code)
+ {
+ 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);
+ break;
+ }
+
+ g_set_error_literal (err, GOA_ERROR, error_code, error_msg);
+ g_free (error_msg);
+}
+
+void
goa_utils_set_error_ssl (GError **err, GTlsCertificateFlags flags)
{
const gchar *error_msg;
diff --git a/src/goabackend/goautils.h b/src/goabackend/goautils.h
index 4c6a10e..b69265b 100644
--- a/src/goabackend/goautils.h
+++ b/src/goabackend/goautils.h
@@ -26,6 +26,7 @@
#include <gio/gio.h>
#include <glib.h>
#include <gtk/gtk.h>
+#include <libsoup/soup.h>
#include <goabackend/goabackendtypes.h>
G_BEGIN_DECLS
@@ -78,6 +79,8 @@ void goa_utils_keyfile_set_string (GoaAccount *account, const gchar
gboolean goa_utils_parse_email_address (const gchar *email, gchar **out_username, gchar
**out_domain);
+void goa_utils_set_error_soup (GError **err, SoupMessage *msg);
+
void goa_utils_set_error_ssl (GError **err, GTlsCertificateFlags flags);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]