Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision 3b4a22a8ca8a88122fa5fbf51218a5e6e65a90c8)
+++ protocols/twitter/twitter_lib.c	(revision e08ae0cff03ff880344cb3dc75cc90576cc314b3)
@@ -37,4 +37,5 @@
 #include "xmltree.h"
 #include "twitter_lib.h"
+#include "json_util.h"
 #include <ctype.h>
 #include <errno.h>
@@ -188,10 +189,10 @@
 }
 
-static struct xt_node *twitter_parse_response(struct im_connection *ic, struct http_request *req)
+static json_value *twitter_parse_response(struct im_connection *ic, struct http_request *req)
 {
 	gboolean logging_in = !(ic->flags & OPT_LOGGED_IN);
 	gboolean periodic;
 	struct twitter_data *td = ic->proto_data;
-	struct xt_node *ret;
+	json_value *ret;
 	char path[64] = "", *s;
 	
@@ -227,5 +228,5 @@
 	}
 
-	if ((ret = xt_from_string(req->reply_body, req->body_size)) == NULL) {
+	if ((ret = json_parse(req->reply_body)) == NULL) {
 		imcb_error(ic, "Could not retrieve %s: %s",
 			   path, "XML parse error");
@@ -251,42 +252,30 @@
 
 /**
- * Function to help fill a list.
- */
-static xt_status twitter_xt_next_cursor(struct xt_node *node, struct twitter_xml_list *txl)
-{
-	char *end = NULL;
-
-	if (node->text)
-		txl->next_cursor = g_ascii_strtoll(node->text, &end, 10);
-	if (end == NULL)
-		txl->next_cursor = -1;
-
-	return XT_HANDLED;
-}
-
-/**
  * Fill a list of ids.
  */
-static xt_status twitter_xt_get_friends_id_list(struct xt_node *node, struct twitter_xml_list *txl)
-{
-	struct xt_node *child;
+static xt_status twitter_xt_get_friends_id_list(json_value *node, struct twitter_xml_list *txl)
+{
+	json_value *c;
+	int i;
 
 	// Set the list type.
 	txl->type = TXL_ID;
 
-	// The root <statuses> node should hold the list of statuses <status>
-	// Walk over the nodes children.
-	for (child = node->children; child; child = child->next) {
-		if (g_strcasecmp("ids", child->name) == 0) {
-			struct xt_node *idc;
-			for (idc = child->children; idc; idc = idc->next)
-				if (g_strcasecmp(idc->name, "id") == 0)
-					txl->list = g_slist_prepend(txl->list,
-						g_memdup(idc->text, idc->text_len + 1));
-		} else if (g_strcasecmp("next_cursor", child->name) == 0) {
-			twitter_xt_next_cursor(child, txl);
-		}
-	}
-
+	c = json_o_get(node, "ids");
+	if (!c || c->type != json_array)
+		return XT_ABORT;
+
+	for (i = 0; i < c->u.array.length; i ++) {
+		txl->list = g_slist_prepend(txl->list,
+			g_strdup_printf("%ld", c->u.array.values[i]->u.integer));
+		
+	}
+	
+	c = json_o_get(node, "next_cursor");
+	if (c && c->type == json_integer)
+		txl->next_cursor = c->u.integer;
+	else
+		txl->next_cursor = -1;
+	
 	return XT_HANDLED;
 }
@@ -300,5 +289,5 @@
 {
 	struct im_connection *ic;
-	struct xt_node *parsed;
+	json_value *parsed;
 	struct twitter_xml_list *txl;
 	struct twitter_data *td;
@@ -322,6 +311,7 @@
 	if (!(parsed = twitter_parse_response(ic, req)))
 		return;
+	
 	twitter_xt_get_friends_id_list(parsed, txl);
-	xt_free_node(parsed);
+	json_value_free(parsed);
 
 	td->follow_ids = txl->list;
@@ -338,5 +328,5 @@
 }
 
-static xt_status twitter_xt_get_users(struct xt_node *node, struct twitter_xml_list *txl);
+static xt_status twitter_xt_get_users(json_value *node, struct twitter_xml_list *txl);
 static void twitter_http_get_users_lookup(struct http_request *req);
 
@@ -379,5 +369,5 @@
 {
 	struct im_connection *ic = req->data;
-	struct xt_node *parsed;
+	json_value *parsed;
 	struct twitter_xml_list *txl;
 	GSList *l = NULL;
@@ -395,5 +385,5 @@
 		return;
 	twitter_xt_get_users(parsed, txl);
-	xt_free_node(parsed);
+	json_value_free(parsed);
 
 	// Add the users as buddies.
@@ -410,46 +400,26 @@
 
 /**
- * Function to fill a twitter_xml_user struct.
- * It sets:
- *  - the name and
- *  - the screen_name.
- */
-static xt_status twitter_xt_get_user(struct xt_node *node, struct twitter_xml_user *txu)
-{
-	struct xt_node *child;
-
-	// Walk over the nodes children.
-	for (child = node->children; child; child = child->next) {
-		if (g_strcasecmp("name", child->name) == 0) {
-			txu->name = g_memdup(child->text, child->text_len + 1);
-		} else if (g_strcasecmp("screen_name", child->name) == 0) {
-			txu->screen_name = g_memdup(child->text, child->text_len + 1);
-		}
-	}
-	return XT_HANDLED;
-}
-
-/**
  * Function to fill a twitter_xml_list struct.
  * It sets:
  *  - all <user>s from the <users> element.
  */
-static xt_status twitter_xt_get_users(struct xt_node *node, struct twitter_xml_list *txl)
+static xt_status twitter_xt_get_users(json_value *node, struct twitter_xml_list *txl)
 {
 	struct twitter_xml_user *txu;
-	struct xt_node *child;
+	int i;
 
 	// Set the type of the list.
 	txl->type = TXL_USER;
 
+	if (!node || node->type != json_array)
+		return XT_ABORT;
+
 	// The root <users> node should hold the list of users <user>
 	// Walk over the nodes children.
-	for (child = node->children; child; child = child->next) {
-		if (g_strcasecmp("user", child->name) == 0) {
-			txu = g_new0(struct twitter_xml_user, 1);
-			twitter_xt_get_user(child, txu);
-			// Put the item in the front of the list.
-			txl->list = g_slist_prepend(txl->list, txu);
-		}
+	for (i = 0; i < node->u.array.length; i ++) {
+		txu = g_new0(struct twitter_xml_user, 1);
+		txu->name = g_strdup(json_o_str(node->u.array.values[i], "name"));
+		txu->screen_name = g_strdup(json_o_str(node->u.array.values[i], "screen_name"));
+		txl->list = g_slist_prepend(txl->list, txu);
 	}
 
@@ -491,5 +461,5 @@
 		} else if (g_strcasecmp("user", child->name) == 0) {
 			txs->user = g_new0(struct twitter_xml_user, 1);
-			twitter_xt_get_user(child, txs->user);
+//			twitter_xt_get_user(child, txs->user);
 		} else if (g_strcasecmp("id", child->name) == 0) {
 			txs->id = g_ascii_strtoull(child->text, NULL, 10);
@@ -579,5 +549,5 @@
 			}
 		} else if (g_strcasecmp("next_cursor", child->name) == 0) {
-			twitter_xt_next_cursor(child, txl);
+//			twitter_xt_next_cursor(child, txl);
 		}
 	}
@@ -921,5 +891,5 @@
 		goto end;
 	twitter_xt_get_status_list(ic, parsed, txl);
-	xt_free_node(parsed);
+//	json_value_free(parsed);
 
 	td->home_timeline_obj = txl;
@@ -954,5 +924,5 @@
 		goto end;
 	twitter_xt_get_status_list(ic, parsed, txl);
-	xt_free_node(parsed);
+//	json_value_free(parsed);
 
 	td->mentions_obj = txl;
