Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision 7d53efb7ec5310b2710757cef03d7f53c94a7797)
+++ protocols/twitter/twitter_lib.c	(revision 1fdb0a48438d6dc4a4795d195737890ed3e46a96)
@@ -117,4 +117,35 @@
 }
 
+/* Warning: May return a malloc()ed value, which will be free()d on the next
+   call. Only for short-term use. */
+static char *twitter_parse_error(struct http_request *req)
+{
+	static char *ret = NULL;
+	struct xt_parser *xp = NULL;
+	struct xt_node *node;
+	
+	g_free(ret);
+	ret = NULL;
+	
+	if (req->body_size > 0)
+	{
+		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 req->status_string;
+}
+
 static void twitter_http_get_friends_ids(struct http_request *req);
 
@@ -124,11 +155,9 @@
 void twitter_get_friends_ids(struct im_connection *ic, int next_cursor)
 {
-	struct twitter_data *td = ic->proto_data;
-
 	// Primitive, but hey! It works...	
 	char* args[2];
 	args[0] = "cursor";
 	args[1] = g_strdup_printf ("%d", next_cursor);
-	twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
+	twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2);
 
 	g_free(args[1]);
@@ -196,5 +225,5 @@
 		// It didn't go well, output the error and return.
 		if (++td->http_fails >= 5)
-			imcb_error(ic, "Could not retrieve friends. HTTP STATUS: %d", req->status_code);
+			imcb_error(ic, "Could not retrieve friends: %s", twitter_parse_error(req));
 		
 		return;
@@ -396,5 +425,5 @@
 	}
 
-	twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth_info, args, td->home_timeline_id ? 4 : 2);
+	twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args, td->home_timeline_id ? 4 : 2);
 
 	g_free(args[1]);
@@ -434,4 +463,6 @@
 		twitter_add_buddy(ic, status->user->screen_name, status->user->name);
 		
+		strip_html(status->text);
+		
 		// Say it!
 		if (g_strcasecmp(td->user, status->user->screen_name) == 0)
@@ -471,4 +502,5 @@
 		status = l->data;
 		
+		strip_html( status->text );
 		if( mode_one )
 			text = g_strdup_printf( "\002<\002%s\002>\002 %s",
@@ -523,5 +555,5 @@
 		// It didn't go well, output the error and return.
 		if (++td->http_fails >= 5)
-			imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ". HTTP STATUS: %d", req->status_code);
+			imcb_error(ic, "Could not retrieve " TWITTER_HOME_TIMELINE_URL ": %s", twitter_parse_error(req));
 		
 		return;
@@ -575,5 +607,5 @@
 		// It didn't go well, output the error and return.
 		if (++td->http_fails >= 5)
-			imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL " HTTP STATUS: %d", req->status_code);
+			imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
 		
 		return;
@@ -614,11 +646,9 @@
 void twitter_get_statuses_friends(struct im_connection *ic, int next_cursor)
 {
-	struct twitter_data *td = ic->proto_data;
-
 	char* args[2];
 	args[0] = "cursor";
 	args[1] = g_strdup_printf ("%d", next_cursor);
 
-	twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
+	twitter_http(ic, TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, args, 2);
 
 	g_free(args[1]);
@@ -639,5 +669,5 @@
 	if (req->status_code != 200) {
 		// It didn't go well, output the error and return.
-		imcb_error(ic, "HTTP Error... STATUS: %d", req->status_code);
+		imcb_error(ic, "HTTP error: %s", twitter_parse_error(req));
 		return;
 	}
@@ -649,10 +679,8 @@
 void twitter_post_status(struct im_connection *ic, char* msg)
 {
-	struct twitter_data *td = ic->proto_data;
-
 	char* args[2];
 	args[0] = "status";
 	args[1] = msg;
-	twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 2);
+	twitter_http(ic, TWITTER_STATUS_UPDATE_URL, twitter_http_post, ic, 1, args, 2);
 //	g_free(args[1]);
 }
@@ -664,6 +692,4 @@
 void twitter_direct_messages_new(struct im_connection *ic, char *who, char *msg)
 {
-	struct twitter_data *td = ic->proto_data;
-
 	char* args[4];
 	args[0] = "screen_name";
@@ -672,5 +698,5 @@
 	args[3] = msg;
 	// Use the same callback as for twitter_post_status, since it does basically the same.
-	twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 4);
+	twitter_http(ic, TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post, ic, 1, args, 4);
 //	g_free(args[1]);
 //	g_free(args[3]);
@@ -679,12 +705,7 @@
 void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create)
 {
-	struct twitter_data *td = ic->proto_data;
-
 	char* args[2];
 	args[0] = "screen_name";
 	args[1] = who;
-	twitter_http(create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL, twitter_http_post, ic, 1, td->user, td->pass, td->oauth_info, args, 2);
-}
-
-
-
+	twitter_http(ic, create ? TWITTER_FRIENDSHIPS_CREATE_URL : TWITTER_FRIENDSHIPS_DESTROY_URL, twitter_http_post, ic, 1, args, 2);
+}
