diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-05-23 15:52:41 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-05-23 15:52:41 +0100 |
commit | 3d93aed32d49bae6c608a71858f00127dccd28e9 (patch) | |
tree | 66f082f490d9ba2339c76e845207a5d7f2a7708d | |
parent | 228fc188af4cc292a14672abe519d557d57bb1e6 (diff) |
Restructure Twitter error parser a bit, it fed a NULL pointer to the XML
parser sometimes (which fails safely but is a bad idea anyway).
-rw-r--r-- | protocols/twitter/twitter_lib.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index ad09bbc5..e4dfc595 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -121,31 +121,30 @@ static void twitter_add_buddy(struct im_connection *ic, char *name, const char * static char *twitter_parse_error(struct http_request *req) { static char *ret = NULL; - struct xt_parser *xp; + struct xt_parser *xp = NULL; struct xt_node *node; - char *err_s = NULL; g_free(ret); ret = NULL; - xp = xt_new(NULL, NULL); - xt_feed(xp, req->reply_body, req->body_size); - - if ((node = xt_find_node(xp->root, "hash")) && - (node = xt_find_node(node->children, "error")) && - node->text_len > 0) - err_s = node->text; - - if (err_s) + if (req->body_size > 0) { - ret = g_strdup_printf("%s (%s)", req->status_string, err_s); + xp = xt_new(NULL, NULL); + xt_feed(xp, req->reply_body, req->body_size); + + if ((node = xt_find_node(xp->root, "hash")) && + (node = xt_find_node(node->children, "error")) && + node->text_len > 0) + { + ret = g_strdup_printf("%s (%s)", req->status_string, node->text); + xt_free(xp); + return ret; + } + xt_free(xp); - return ret; - } - else - { - return req->status_string; } + + return req->status_string; } static void twitter_http_get_friends_ids(struct http_request *req); |