aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-16 21:46:12 +0200
committerMax Kellermann <max@duempel.org>2011-09-16 21:50:05 +0200
commit17927f5c26f0ba5f7f1ecc40b8d0a92700603e89 (patch)
tree5979683a758f26d805b19e2355c17da2e629173b /src
parent754f26a97c816781e80500d98f2515ae97836145 (diff)
downloadmpd-17927f5c26f0ba5f7f1ecc40b8d0a92700603e89.tar.gz
mpd-17927f5c26f0ba5f7f1ecc40b8d0a92700603e89.tar.xz
mpd-17927f5c26f0ba5f7f1ecc40b8d0a92700603e89.zip
input/soup: improve error messages
Copy the reason_phrase from the SoupMessage, and check for transport errors in the session callback.
Diffstat (limited to 'src')
-rw-r--r--src/input/soup_input_plugin.c55
1 files changed, 43 insertions, 12 deletions
diff --git a/src/input/soup_input_plugin.c b/src/input/soup_input_plugin.c
index dc005a58c..0f7d4ea18 100644
--- a/src/input/soup_input_plugin.c
+++ b/src/input/soup_input_plugin.c
@@ -112,9 +112,44 @@ input_soup_finish(void)
soup_uri_free(soup_proxy);
}
+/**
+ * Copy the error from the SoupMessage object to
+ * input_soup::postponed_error.
+ *
+ * @return true if there was no error
+ */
+static bool
+input_soup_copy_error(struct input_soup *s, const SoupMessage *msg)
+{
+ if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code))
+ return true;
+
+ if (msg->status_code == SOUP_STATUS_CANCELLED)
+ /* failure, but don't generate a GError, because this
+ status was caused by _close() */
+ return false;
+
+ if (s->postponed_error != NULL)
+ /* there's already a GError, don't overwrite it */
+ return false;
+
+ if (SOUP_STATUS_IS_TRANSPORT_ERROR(msg->status_code))
+ s->postponed_error =
+ g_error_new(soup_quark(), msg->status_code,
+ "HTTP client error: %s",
+ msg->reason_phrase);
+ else
+ s->postponed_error =
+ g_error_new(soup_quark(), msg->status_code,
+ "got HTTP status: %d %s",
+ msg->status_code, msg->reason_phrase);
+
+ return false;
+}
+
static void
input_soup_session_callback(G_GNUC_UNUSED SoupSession *session,
- G_GNUC_UNUSED SoupMessage *msg, gpointer user_data)
+ SoupMessage *msg, gpointer user_data)
{
struct input_soup *s = user_data;
@@ -123,6 +158,9 @@ input_soup_session_callback(G_GNUC_UNUSED SoupSession *session,
g_mutex_lock(s->base.mutex);
+ if (!s->base.ready)
+ input_soup_copy_error(s, msg);
+
s->base.ready = true;
s->alive = false;
s->completed = true;
@@ -136,15 +174,9 @@ input_soup_got_headers(SoupMessage *msg, gpointer user_data)
{
struct input_soup *s = user_data;
- if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) {
- g_mutex_lock(s->base.mutex);
-
- if (s->postponed_error == NULL)
- s->postponed_error =
- g_error_new(soup_quark(), msg->status_code,
- "got HTTP status %d",
- msg->status_code);
+ g_mutex_lock(s->base.mutex);
+ if (!input_soup_copy_error(s, msg)) {
g_mutex_unlock(s->base.mutex);
soup_session_cancel_message(soup_session, msg,
@@ -152,12 +184,11 @@ input_soup_got_headers(SoupMessage *msg, gpointer user_data)
return;
}
- soup_message_body_set_accumulate(msg->response_body, false);
-
- g_mutex_lock(s->base.mutex);
s->base.ready = true;
g_cond_broadcast(s->base.cond);
g_mutex_unlock(s->base.mutex);
+
+ soup_message_body_set_accumulate(msg->response_body, false);
}
static void