diff options
author | eionrobb <eionrobb@8ca6c67d-4297-256d-f884-781da6d5760b> | 2014-01-14 09:02:23 +0400 |
---|---|---|
committer | eionrobb <eionrobb@8ca6c67d-4297-256d-f884-781da6d5760b> | 2014-01-14 09:02:23 +0400 |
commit | f42cc3b7ed88ba488f8a8abda5c4b692842306e0 (patch) | |
tree | 4e467b0c657e8668a375dd91208af89fb9b7de89 | |
parent | 763a21853c4882ab918650c896cdae3df75f5595 (diff) |
Allow setting an error callback for unexpected HTTP responses (eg a 401 Not Authorized when logging in with a bad access_token)
-rw-r--r-- | steam-mobile/steam_connection.c | 11 | ||||
-rw-r--r-- | steam-mobile/steam_connection.h | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/steam-mobile/steam_connection.c b/steam-mobile/steam_connection.c index 680ee6e..f3c4cc6 100644 --- a/steam-mobile/steam_connection.c +++ b/steam-mobile/steam_connection.c @@ -210,7 +210,11 @@ static void steam_connection_process_data(SteamConnection *steamcon) JsonParser *parser = json_parser_new(); if (!json_parser_load_from_data(parser, tmp, len, NULL)) { - purple_debug_error("steam", "Error parsing response: %s\n", tmp); + if (steamcon->error_callback != NULL) { + steamcon->error_callback(steamcon->sa, tmp, len, steamcon->user_data); + } else { + purple_debug_error("steam", "Error parsing response: %s\n", tmp); + } } else { JsonNode *root = json_parser_get_root(parser); JsonObject *jsonobj = json_node_get_object(root); @@ -488,7 +492,8 @@ static void steam_ssl_connection_error(PurpleSslConnection *ssl, } } -void steam_post_or_get(SteamAccount *sa, SteamMethod method, +SteamConnection * +steam_post_or_get(SteamAccount *sa, SteamMethod method, const gchar *host, const gchar *url, const gchar *postdata, SteamProxyCallbackFunc callback_func, gpointer user_data, gboolean keepalive) @@ -610,6 +615,8 @@ void steam_post_or_get(SteamAccount *sa, SteamMethod method, g_queue_push_head(sa->waiting_conns, steamcon); steam_next_connection(sa); + + return steamcon; } static void steam_next_connection(SteamAccount *sa) diff --git a/steam-mobile/steam_connection.h b/steam-mobile/steam_connection.h index 00a2605..844de63 100644 --- a/steam-mobile/steam_connection.h +++ b/steam-mobile/steam_connection.h @@ -5,6 +5,7 @@ #include "libsteam.h" typedef void (*SteamProxyCallbackFunc)(SteamAccount *sa, JsonObject *obj, gpointer user_data); +typedef void (*SteamProxyCallbackErrorFunc)(SteamAccount *sa, const gchar *data, gssize data_len, gpointer user_data); /* * This is a bitmask. @@ -35,11 +36,12 @@ struct _SteamConnection { time_t request_time; guint retry_count; guint timeout_watcher; + SteamProxyCallbackErrorFunc error_callback; }; void steam_connection_destroy(SteamConnection *steamcon); void steam_connection_close(SteamConnection *steamcon); -void steam_post_or_get(SteamAccount *sa, SteamMethod method, +SteamConnection *steam_post_or_get(SteamAccount *sa, SteamMethod method, const gchar *host, const gchar *url, const gchar *postdata, SteamProxyCallbackFunc callback_func, gpointer user_data, gboolean keepalive); |