adium.1-4: 23cc9cb7: pidgin-facebookchat at r647.

zacw at adiumx.com zacw at adiumx.com
Fri Aug 21 15:45:50 EDT 2009


-----------------------------------------------------------------
Revision: 23cc9cb7bd97b596706c5d37a73b034328cb6ed1
Ancestor: 48c7a497246d17bda6d936206716efddb3e5a606
Author: zacw at adiumx.com
Date: 2009-08-21T19:40:17
Branch: im.pidgin.adium.1-4
URL: http://d.pidgin.im/viewmtn/revision/info/23cc9cb7bd97b596706c5d37a73b034328cb6ed1

Added files:
        libpurple/protocols/facebook/fb_json.c
        libpurple/protocols/facebook/fb_json.h
Modified files:
        libpurple/protocols/facebook/Makefile.am
        libpurple/protocols/facebook/fb_blist.c
        libpurple/protocols/facebook/fb_connection.c
        libpurple/protocols/facebook/fb_conversation.c
        libpurple/protocols/facebook/fb_friendlist.c
        libpurple/protocols/facebook/fb_friendlist.h
        libpurple/protocols/facebook/fb_managefriends.c
        libpurple/protocols/facebook/fb_messages.c
        libpurple/protocols/facebook/fb_notifications.c
        libpurple/protocols/facebook/fb_util.c
        libpurple/protocols/facebook/fb_util.h
        libpurple/protocols/facebook/libfacebook.c
        libpurple/protocols/facebook/libfacebook.h

ChangeLog: 

pidgin-facebookchat at r647.


-------------- next part --------------
============================================================
--- libpurple/protocols/facebook/fb_json.c	8f00941d8e1906a3108dfedc7e4eed52e262240e
+++ libpurple/protocols/facebook/fb_json.c	8f00941d8e1906a3108dfedc7e4eed52e262240e
@@ -0,0 +1,87 @@
+/*
+ * libfacebook
+ *
+ * libfacebook is the property of its developers.  See the COPYRIGHT file
+ * for more details.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fb_json.h"
+
+#ifdef USE_JSONC
+
+JsonParser *
+json_parser_new(void)
+{
+	JsonParser *parser;
+	
+	parser = g_new0(JsonParser, 1);
+	parser->tok = json_tokener_new();
+	
+	return parser;
+}
+
+gboolean 
+json_parser_load_from_data(JsonParser *parser, const gchar *data,
+                           gssize length, GError **error)
+{
+	if (parser->tok == NULL)
+		return FALSE;
+
+	parser->root = json_tokener_parse_ex(parser->tok, (char*)data, (int)length);
+	
+	if (parser->tok->err != json_tokener_success)
+	{
+		json_object_put(parser->root);
+		parser->root = NULL;
+		return FALSE;
+	}
+	
+	return TRUE;
+}
+
+void
+json_parser_free(JsonParser *parser)
+{
+	json_tokener_free(parser->tok);
+	json_object_put(parser->root);
+	g_free(parser);
+}
+
+JsonNode *
+json_parser_get_root(JsonParser *parser)
+{
+	return parser->root;
+}
+
+GList *
+json_object_get_members(JsonObject *obj)
+{
+	GList *keys = NULL;
+	struct lh_entry *entry;	
+
+	for (entry = json_object_get_object(obj)->head;
+		entry;
+		entry = entry->next)
+	{
+		keys = g_list_prepend(keys, entry->k);
+	}
+	
+	keys = g_list_reverse(keys);
+	
+	return keys;
+}
+
+#endif
============================================================
--- libpurple/protocols/facebook/fb_json.h	373c5e457a7ce6b4dabf392d453de5647fa6de86
+++ libpurple/protocols/facebook/fb_json.h	373c5e457a7ce6b4dabf392d453de5647fa6de86
@@ -0,0 +1,64 @@
+/*
+ * libfacebook
+ *
+ * libfacebook is the property of its developers.  See the COPYRIGHT file
+ * for more details.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef FACEBOOK_JSON_H
+#define FACEBOOK_JSON_H
+
+#ifndef USE_JSONC
+#	include <json-glib/json-glib.h>
+#define json_parser_free(parser) g_object_unref(parser)
+#else /* USE_JSONC */
+#	include <glib.h>
+#	include <json/json.h>
+typedef struct json_object JsonNode;
+typedef struct json_object JsonObject;
+typedef struct json_object JsonArray;
+typedef struct {
+	struct json_tokener *tok;
+	struct json_object *root;
+} JsonParser;
+
+gboolean json_parser_load_from_data(JsonParser *parser,
+									const gchar *data,
+                                    gssize length,
+                                    GError **error);
+
+JsonNode* json_parser_get_root(JsonParser *parser);
+JsonParser* json_parser_new(void);
+void json_parser_free(JsonParser *parser);
+
+#define json_object_has_member(obj, key) ((gboolean)json_object_object_get(obj, key))
+#define json_object_get_member(obj, key) json_object_object_get(obj, key)
+GList* json_object_get_members(JsonObject *object);
+
+#define json_node_get_array(node) (node)
+#define json_node_get_object(node) (node)
+#define json_node_get_boolean(node) json_object_get_boolean(node)
+#define json_node_get_double(node) json_object_get_double(node)
+#define json_node_get_int(node) json_object_get_int(node)
+#define json_node_get_string(node) json_object_get_string(node)
+
+#define json_array_get_element(array, index) json_object_array_get_idx(array, index)
+#define json_array_get_length(array) json_object_array_length(array)
+
+#endif /* USE_JSONC */
+
+#endif /* FACEBOOK_JSON_H */
+
============================================================
--- libpurple/protocols/facebook/Makefile.am	d0ee40a9e8032bf4f2e5329a45bcf4151ad30d19
+++ libpurple/protocols/facebook/Makefile.am	39a629e613b6031db6cc07318b3375b3079a131c
@@ -16,6 +16,8 @@ FACEBOOK_SOURCES = \
 	fb_friendlist.c \
 	fb_info.h \
 	fb_info.c \
+	fb_json.h \
+	fb_json.c \
 	fb_managefriends.h \
 	fb_managefriends.c \
 	fb_messages.h \
============================================================
--- libpurple/protocols/facebook/fb_blist.c	4bba8ded502f2a2210836c692c63af63ba0abcd0
+++ libpurple/protocols/facebook/fb_blist.c	13096220516c9de76237d53a5a0b21d9663f6bd5
@@ -125,7 +125,7 @@ static gboolean process_buddy_status(Fac
 		const gchar *status_time_text;
 
 		status_time_text = json_node_get_string(
-			json_object_get_member(userInfo, "statusTimeRel"));
+				json_object_get_member(userInfo, "statusTimeRel"));
 		status_text = fb_strdup_withhtml(json_node_get_string(
 				json_object_get_member(userInfo, "status")));
 
@@ -177,8 +177,8 @@ static void process_buddy_icon(FacebookA
 	fbuddy = buddy->proto_data;
 	
 	/* Set the buddy icon (if it hasn't changed) */
-	buddy_icon_url = json_node_dup_string(json_object_get_member(
-			userInfo, "thumbSrc"));
+	buddy_icon_url = g_strdup(json_node_get_string(json_object_get_member(
+			userInfo, "thumbSrc")));
 	if (fbuddy->thumb_url == NULL ||
 	    !g_str_equal(fbuddy->thumb_url, buddy_icon_url))
 	{
@@ -350,33 +350,37 @@ static void got_buddy_list_cb(FacebookAc
 				fba->pc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
 				error);
-			g_object_unref(parser);
+			json_parser_free(parser);
 			return;
 	}
 	
 	/* look for "userInfos":{ ... }, */
 	if (!json_object_has_member(objnode, "payload"))
 	{
-		g_object_unref(parser);
+		json_parser_free(parser);
 		return;
 	}
 	objnode = json_node_get_object(json_object_get_member(
 			objnode, "payload"));
 	if (!json_object_has_member(objnode, "buddy_list"))
 	{
-		g_object_unref(parser);
+		json_parser_free(parser);
 		return;
 	}
 	JsonObject *buddy_list = json_node_get_object(json_object_get_member(
 			objnode, "buddy_list"));
 	if (!json_object_has_member(buddy_list, "userInfos"))
 	{
-		g_object_unref(parser);
+		json_parser_free(parser);
 		return;
 	}
-
-	fb_process_friend_lists(fba, buddy_list);
-
+	
+	if (purple_account_get_bool(fba->account, "facebook_use_groups", TRUE))
+	{
+		//Only process if we have the setting
+		fb_process_friend_lists(fba, buddy_list);
+	}
+	
 	// Iterate through the list of buddy infos sent to us.	
 	JsonObject *userInfos;
 	JsonObject *nowAvailableList;
@@ -422,7 +426,7 @@ static void got_buddy_list_cb(FacebookAc
 	process_notifications(fba, json_node_get_object(
 		json_object_get_member(objnode, "notifications")));
 
-	g_object_unref(parser);
+	json_parser_free(parser);
 }
 
 gboolean fb_get_buddy_list(gpointer data)
============================================================
--- libpurple/protocols/facebook/fb_connection.c	557b8518d7576ae548b710f016cbca9d3f76f606
+++ libpurple/protocols/facebook/fb_connection.c	df49a2d2b12155149fe59498282cc0a17adbe6f9
@@ -23,6 +23,7 @@ static void fb_attempt_connection(Facebo
 static void fb_attempt_connection(FacebookConnection *);
 
 #ifdef HAVE_ZLIB
+#include <zlib.h>
 
 static gchar *fb_gunzip(const guchar *gzip_data, ssize_t *len_ptr)
 {
============================================================
--- libpurple/protocols/facebook/fb_conversation.c	c7a209ce60af9d7660eeceecb1941275fe47bbe1
+++ libpurple/protocols/facebook/fb_conversation.c	8c4a8888a113ce29b70b943c33512e4f54983d97
@@ -21,9 +21,8 @@
 #include "fb_conversation.h"
 #include "fb_connection.h"
 #include "fb_util.h"
+#include "fb_json.h"
 
-#include <json-glib/json-glib.h>
-
 #include "conversation.h"
 #include "signals.h"
 
@@ -141,9 +140,9 @@ static void fb_history_fetch_cb(Facebook
 			gchar *to;
 			JsonObject *text_obj;
 
-			from = g_strdup_printf("%d", json_node_get_int(
+			from = g_strdup_printf("%" G_GINT64_FORMAT, json_node_get_int(
 				json_object_get_member(message_obj, "from")));
-			to = g_strdup_printf("%d", json_node_get_int(
+			to = g_strdup_printf("%" G_GINT64_FORMAT, json_node_get_int(
 				json_object_get_member(message_obj, "to")));
 
 			text_obj = json_node_get_object(
@@ -168,7 +167,7 @@ static void fb_history_fetch_cb(Facebook
 		}
 	}
 	
-	g_object_unref(parser);
+	json_parser_free(parser);
 }
 
 void fb_history_fetch(FacebookAccount *fba, const char *who,
============================================================
--- libpurple/protocols/facebook/fb_friendlist.c	75b0969a59d34b7145d1fe3c6e4121ab9f2d9ed3
+++ libpurple/protocols/facebook/fb_friendlist.c	06b923d6224e80cb54759ba438f657d897bd4d3a
@@ -48,8 +48,8 @@ static void handle_move_request(Facebook
 	old_list_id = fb_get_list_id(fba, request->old_group);
 	new_list_id = fb_get_list_id(fba, request->new_group);
 
-	remove_flist = !new_list_id || !strcmp(new_list_id, "-1");
-	no_original_list = !old_list_id || !strcmp(old_list_id, "-1");
+	remove_flist = !new_list_id || g_str_equal(new_list_id, "-1");
+	no_original_list = !old_list_id || g_str_equal(old_list_id, "-1");
 
 	if (remove_flist) {
 		command = "&remove_fl=true";
@@ -101,7 +101,7 @@ static void create_list_cb(FacebookAccou
 	if (!objnode ||
 	    !json_object_has_member(objnode, "payload"))
 	{
-		g_object_unref(parser);
+		json_parser_free(parser);
 		return;
 	}
 
@@ -109,7 +109,7 @@ static void create_list_cb(FacebookAccou
 			objnode, "payload"));
 	fb_process_friend_lists(fba, objnode);
 
-	g_object_unref(parser);
+	json_parser_free(parser);
 
 	// Move Friend
 	request = (MoveRequest *) userdata;
@@ -149,13 +149,19 @@ void fb_group_buddy_move(PurpleConnectio
 	MoveRequest *request;
 	const gchar *new_list_id;
 	
+	if (!purple_account_get_bool(pc->account, "facebook_use_groups", TRUE))
+	{
+		//Dont do anything if we're ignoring groups
+		return;
+	}
+	
 	fba = pc->proto_data;
 
 	purple_debug_info("facebook", "handling move of %s from %s to %s\n",
 		who, old_group, new_group);
 
 	// Don't do anything if groups are not actually changing.
-	if (!strcmp(old_group, new_group)) {
+	if (!purple_utf8_strcasecmp(old_group, new_group)) {
 		purple_debug_info("facebook", "groups are same, not moving\n");
 		return;
 	}
@@ -169,8 +175,8 @@ void fb_group_buddy_move(PurpleConnectio
 	}
 
 	request = g_new0(MoveRequest, 1);
-	request->old_group = g_strdup(old_group);
-	request->new_group = g_strdup(new_group);
+	request->old_group = g_utf8_strdown(old_group, -1);
+	request->new_group = g_utf8_strdown(new_group, -1);
 	request->who = g_strdup(who);
 
 	new_list_id = fb_get_list_id(fba, request->new_group);
@@ -195,6 +201,12 @@ void fb_buddy_remove(PurpleConnection *p
 	// If the plugin is ever to perform an actual defriending, it needs
 	// to provide a dialog and user prompt at the absolute bare minimum.
 	FacebookAccount *fba;
+	
+	if (!purple_account_get_bool(pc->account, "facebook_use_groups", TRUE))
+	{
+		//Dont do anything if we're ignoring groups
+		return;
+	}
 
 	purple_debug_info("facebook", "handing removal of buddy %s\n",
 		buddy->name);
@@ -208,6 +220,13 @@ void fb_group_rename(PurpleConnection *p
 void fb_group_rename(PurpleConnection *pc, const char *old_name,
 	PurpleGroup *group, GList *moved_buddies)
 {
+	
+	if (!purple_account_get_bool(pc->account, "facebook_use_groups", TRUE))
+	{
+		//Dont do anything if we're ignoring groups
+		return;
+	}
+	
 	purple_debug_info("facebook",
 		"handling group rename of %s to %s\n",
 		old_name, purple_group_get_name(group));
@@ -234,6 +253,12 @@ void fb_group_remove(PurpleConnection *p
 
 void fb_group_remove(PurpleConnection *pc, PurpleGroup *group)
 {
+	if (!purple_account_get_bool(pc->account, "facebook_use_groups", TRUE))
+	{
+		//Dont do anything if we're ignoring groups
+		return;
+	}
+	
 	purple_debug_info("facebook", "got group removal of %s\n",
 		purple_group_get_name(group));
 
@@ -251,11 +276,11 @@ const gchar *fb_get_list_id(FacebookAcco
 
 const gchar *fb_get_list_id(FacebookAccount *fba, const gchar *list_name)
 {
-	if (!strcmp(list_name, DEFAULT_GROUP_NAME)) {
+	if (!purple_utf8_strcasecmp(list_name, DEFAULT_GROUP_NAME)) {
 		return "-1";
 	}
 
-	return g_hash_table_lookup(fba->friend_lists_reverse, list_name);
+	return g_hash_table_lookup(fba->friend_lists_reverse, purple_normalize_nocase(NULL, list_name));
 }
 
 gboolean fb_process_friend_lists(FacebookAccount *fba,
@@ -278,7 +303,7 @@ gboolean fb_process_friend_lists(Faceboo
 	friend_list_ids = json_object_get_members(fl_obj);
 	for (cur = friend_list_ids; cur != NULL; cur = cur->next)
 	{
-		const gchar *id;
+		gchar *id;
 		const gchar *name;
 		JsonObject *data;
 
@@ -290,16 +315,16 @@ gboolean fb_process_friend_lists(Faceboo
 		if (name) {
 			// Either -1 isnt a valid JSON string or JSON-glib does
 			// this wrong.  I'm too tired to tell the difference.
-			if (!strcmp(id, "_1")) {
+			if (g_str_equal(id, "_1")) {
 				id = "-1";
 			}
 			purple_debug_info("facebook",
 					"got friend list %s with id %s\n",
 					name, id);
 			g_hash_table_insert(fba->friend_lists,
-					g_strdup(id), g_strdup(name));
+					g_strdup(id), g_utf8_strdown(name, -1));
 			g_hash_table_insert(fba->friend_lists_reverse,
-					g_strdup(name), g_strdup(id));
+					g_utf8_strdown(name, -1), g_strdup(id));
 		}
 	}
 
@@ -336,8 +361,8 @@ static PurpleBuddy *add_buddy(FacebookAc
 	PurpleGroup *fb_group;
 	PurpleBuddy *buddy;
 
-	group_name = g_hash_table_lookup(fba->friend_lists, friend_list_id);
-	if (!group_name || !strcmp(group_name, "")) {
+	group_name = g_hash_table_lookup(fba->friend_lists, purple_normalize_nocase(NULL, friend_list_id));
+	if (!group_name || group_name[0] == '\0') {
 		purple_debug_info("facebook",
 				"did not find name of list %s\n",
 				friend_list_id);
@@ -354,13 +379,13 @@ static PurpleBuddy *add_buddy(FacebookAc
 		purple_blist_add_group(fb_group, NULL);
 	} 
 
-	buddy = (PurpleBuddy *)g_hash_table_lookup(cur_groups, group_name);
+	buddy = (PurpleBuddy *)g_hash_table_lookup(cur_groups, purple_normalize_nocase(NULL, group_name));
 	if (!buddy) {
 		purple_debug_info("facebook", "adding %s to %s\n",
 				uid, group_name);
 		buddy = purple_buddy_new(fba->account, uid, NULL);
 		purple_blist_add_buddy(buddy, NULL, fb_group, NULL);
-		g_hash_table_remove(cur_groups, group_name);
+		g_hash_table_remove(cur_groups, purple_normalize_nocase(NULL, group_name));
 	}
 
 	return buddy;
@@ -375,6 +400,8 @@ GList *fb_get_buddies_friend_list (Faceb
 	GHashTable *cur_groups;
 	int i;
 	GList *final_buddies, *cur_buddy;
+	PurpleGroup *fb_group;
+	PurpleBuddy *buddy;
 
 	final_buddies = NULL;
 	buddies = purple_find_buddies(fba->account, uid);
@@ -392,7 +419,33 @@ GList *fb_get_buddies_friend_list (Faceb
 		g_slist_free(buddies);
 		return final_buddies;
 	}
-
+	
+	//Do we want to ignore groups?
+	if (!purple_account_get_bool(fba->account, "facebook_use_groups", TRUE))
+	{
+		if (buddies != NULL) {
+			//Copy the slist into the list
+			for (cur = buddies; cur != NULL; cur = cur->next)
+			{
+				final_buddies = g_list_append(
+					final_buddies, cur->data);
+			}
+			g_slist_free(buddies);
+			return final_buddies;
+		} else {
+			buddy = purple_buddy_new(fba->account, uid, NULL);
+			fb_group = purple_find_group(DEFAULT_GROUP_NAME);
+			if (fb_group == NULL)
+			{
+				fb_group = purple_group_new(DEFAULT_GROUP_NAME);
+				purple_blist_add_group(fb_group, NULL);
+			}
+			purple_blist_add_buddy(buddy, NULL, fb_group, NULL);
+			final_buddies = g_list_append(final_buddies, buddy);
+			return final_buddies;
+		}
+	}
+	
 	// Determine what buddies exist and what groups they are in.
 	cur_groups = g_hash_table_new_full(g_str_hash, g_str_equal,
 		g_free, NULL);
@@ -403,7 +456,7 @@ GList *fb_get_buddies_friend_list (Faceb
 		group_name = purple_group_get_name(purple_buddy_get_group(
 					(PurpleBuddy *)cur->data));
 
-		g_hash_table_insert(cur_groups, g_strdup(group_name), cur->data);
+		g_hash_table_insert(cur_groups, g_utf8_strdown(group_name, -1), cur->data);
 	}
 	g_slist_free(buddies);
 
@@ -412,7 +465,6 @@ GList *fb_get_buddies_friend_list (Faceb
 		for (i = 0; i < json_array_get_length(friend_list_ids); i++)
 		{
 			const gchar *friend_list_id;
-			PurpleBuddy *buddy;
 
 			friend_list_id = json_node_get_string(
 				json_array_get_element(friend_list_ids, i));
@@ -431,9 +483,9 @@ GList *fb_get_buddies_friend_list (Faceb
 	for (cur_buddy = final_buddies; cur_buddy != NULL;
 	     cur_buddy = cur_buddy->next)
 	{
-		g_hash_table_remove(cur_groups, purple_group_get_name(
-			purple_buddy_get_group(
-				(PurpleBuddy *)cur_buddy->data)));
+		g_hash_table_remove(cur_groups, purple_normalize_nocase(NULL, 
+			purple_group_get_name(purple_buddy_get_group(
+				(PurpleBuddy *)cur_buddy->data))));
 	}
 
 	// Delete remaining buddies to maintain sync state with server.
============================================================
--- libpurple/protocols/facebook/fb_friendlist.h	4245e211978d4e907a4e22578faaee53bed74f7c
+++ libpurple/protocols/facebook/fb_friendlist.h	0c755491d5b060bfc1eb798339315627c75d4bb6
@@ -22,9 +22,8 @@
 #define FACEBOOK_FRIENDLIST_H
 
 #include "libfacebook.h"
+#include "fb_json.h"
 
-#include <json-glib/json-glib.h>
-
 #define DEFAULT_GROUP_NAME "Facebook"
 
 /* Friend list modification methods */
============================================================
--- libpurple/protocols/facebook/fb_managefriends.c	1d9f2f9e32feef9aa049321c952ab8cb205f1162
+++ libpurple/protocols/facebook/fb_managefriends.c	372e3781799c1dbca5671830f39567e0b1283b6d
@@ -76,7 +76,7 @@ static void fb_check_friend_request_cb(F
 static void fb_check_friend_request_cb(FacebookAccount *fba, gchar *data,
 		gsize data_len, gpointer user_data)
 {
-	const char *uid_pre_text = "class=\"confirm\" id=\"friend_add_";
+	const char *uid_pre_text = "class=\"confirm\" id=\"friend_connect_";
 	const char *name_pre_text = "<td class=\"info\"><a ";
 	const char *msg_pre_text = "<div class=\"personal_msg\"><span>";
 	gchar *uid;
============================================================
--- libpurple/protocols/facebook/fb_messages.c	09b6b82775e77886d5aff74654063c9f70e7e7fb
+++ libpurple/protocols/facebook/fb_messages.c	5e169ad1f7317b6d6d259a02cae23575f5600247
@@ -102,8 +102,8 @@ static void parse_new_messages(PurpleCon
 		JsonObject *object = json_node_get_object(json_array_get_element(messages, i));
 		type = json_node_get_string(json_object_get_member(object, "type"));
 
-		from = g_strdup_printf("%d", json_node_get_int(json_object_get_member(object, "from")));
-		to = g_strdup_printf("%d", json_node_get_int(json_object_get_member(object, "to")));
+		from = g_strdup_printf("%" G_GINT64_FORMAT, json_node_get_int(json_object_get_member(object, "from")));
+		to = g_strdup_printf("%" G_GINT64_FORMAT, json_node_get_int(json_object_get_member(object, "to")));
 		
 		/* Use the in-line buddy name if the buddy list hasn't been downloaded yet */
 		buddy = purple_find_buddy(pc->account, from);
@@ -232,7 +232,7 @@ static void got_new_messages(FacebookAcc
 
 			/* refresh means that the channel is invalid */
 			fb_reconnect(fba);
-			g_object_unref(parser);
+			json_parser_free(parser);
 			return;
 		} else if (g_str_equal(command, "continue")) {
 			/* continue means that the server wants us to remake the connection.
@@ -243,7 +243,7 @@ static void got_new_messages(FacebookAcc
 		}
 	}
 
-	g_object_unref(parser);
+	json_parser_free(parser);
 
 	/* Continue looping, waiting for more messages */
 	fb_get_new_messages(fba);
@@ -329,7 +329,7 @@ static void fb_send_im_cb(FacebookAccoun
 		{
 			msg->resend_timer = purple_timeout_add_seconds(1, (GSourceFunc)fb_resend_im_fom, msg);
 			fba->resending_messages = g_slist_prepend(fba->resending_messages, msg);
-			g_object_unref(parser);
+			json_parser_free(parser);
 			return;
 		}
 		else
@@ -343,7 +343,7 @@ static void fb_send_im_cb(FacebookAccoun
 		g_hash_table_remove(fba->sent_messages_hash, msg->message);
 	}
 
-	g_object_unref(parser);
+	json_parser_free(parser);
 	fb_msg_destroy(msg);
 }
 
@@ -433,7 +433,7 @@ void got_reconnect_json(FacebookAccount 
 		purple_connection_error_reason(fba->pc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
 				_("Error fetching channel; did you log in elsewhere?"));
-		g_object_unref(parser);
+		json_parser_free(parser);
 		return;
 	}
 	
@@ -449,7 +449,7 @@ void got_reconnect_json(FacebookAccount 
 	 * waiting for messages
 	 */
 	fb_get_new_messages(fba);
-	g_object_unref(parser);
+	json_parser_free(parser);
 }
 
 gboolean fb_reconnect(FacebookAccount *fba)
============================================================
--- libpurple/protocols/facebook/fb_notifications.c	ca23fe8908d98aa815fb521ef82a9c2937652dae
+++ libpurple/protocols/facebook/fb_notifications.c	4dfffc8a8452bc56f856c94b2dec1e27d6287ca4
@@ -23,6 +23,7 @@ static void fb_got_notifications_cb(Face
 
 static void fb_got_notifications_cb(FacebookAccount *fba, gchar *url_text, gsize len, gpointer userdata)
 {
+	gchar *salvaged;
 	time_t last_fetch_time;
 	time_t time_of_message;
 	time_t newest_message = 0;
@@ -41,18 +42,26 @@ static void fb_got_notifications_cb(Face
 	last_fetch_time = purple_account_get_int(fba->account, "facebook_notifications_last_fetch", 0);
 	/* purple_debug_info("facebook", "last fetch time: %zu\n", last_fetch_time); */
 
-	xmlnode *rss_root = xmlnode_from_str(url_text, len);
+	salvaged = purple_utf8_salvage(url_text);
+	xmlnode *rss_root = xmlnode_from_str(salvaged, -1);
+	g_free(salvaged);
 	if (rss_root == NULL)
 	{
+		purple_debug_error("facebook", "Could not load RSS file\n");
 		return;
 	}
 	xmlnode *channel = xmlnode_get_child(rss_root, "channel");
 	if (channel == NULL)
 	{
+		purple_debug_warning("facebook", "Invalid RSS feed\n");
 		xmlnode_free(rss_root);
 		return;
 	}
 	xmlnode *item = xmlnode_get_child(channel, "item");
+	if (item == NULL)
+	{
+		purple_debug_info("facebook", "No new notifications\n");
+	}
 	for (; item != NULL; item = xmlnode_get_next_twin(item))
 	{
 		xmlnode *pubDate = xmlnode_get_child(item, "pubDate");
============================================================
--- libpurple/protocols/facebook/fb_util.c	094060765df4b0671d66097a7ad6bfc0e1e87650
+++ libpurple/protocols/facebook/fb_util.c	bf2bb95104968587af70443bf50a423a9e63ce67
@@ -112,9 +112,43 @@ gchar *fb_strdup_withhtml(const gchar *s
 	return dest;
 }
 
-gint64 fb_time_kludge(gint initial_time)
+static gboolean is_json_64bit_safe()
 {
+	//Cache the result to try make this function quick
+	static gint result = -1;
+	
+	if (result == 1)
+		return TRUE;
+	if (result == 0)
+		return FALSE;
+	
 	if (sizeof(gint) >= sizeof(gint64))
+	{
+		result = 1;
+		return TRUE;
+	}
+
+#ifndef USE_JSONC
+	JsonNode *node;
+	GType type;
+
+	node = json_node_new(NSON_NODE_VALUE);
+	json_node_set_int(node, 1);
+	type = json_node_get_value_type(node);
+	if (G_VALUE_TYPE(type) == G_TYPE_INT64)
+	{
+		result = 1;
+		return TRUE;
+	}
+#endif /* !USE_JSONC */
+	
+	result = 0;
+	return FALSE;
+}
+
+gint64 fb_time_kludge(gint64 initial_time)
+{
+	if (is_json_64bit_safe())
 		return initial_time;
 	
 	gint64 now_millis = (gint64) time(NULL);
@@ -142,7 +176,7 @@ JsonParser *fb_get_parser(const gchar *d
 
 	parser = json_parser_new();
 	if (!json_parser_load_from_data(parser, data, -1, NULL)) {
-		g_object_unref(parser);
+		json_parser_free(parser);
 		return NULL;
 	}
 
============================================================
--- libpurple/protocols/facebook/fb_util.h	53baf5d5d5678ff04dc221e8d629b56d3f3a67f5
+++ libpurple/protocols/facebook/fb_util.h	9020d025525bf359be4dd1dc66478bf14a9250c7
@@ -22,7 +22,7 @@
 #define FACEBOOK_UTIL_H
 
 #include "libfacebook.h"
-#include <json-glib/json-glib.h>
+#include "fb_json.h"
 
 JsonParser *fb_get_parser(const gchar *data, gsize data_len);
 JsonObject *fb_get_json_object(JsonParser *parser, char **error_message);
============================================================
--- libpurple/protocols/facebook/libfacebook.c	83c57c5d42dc61b5fafa9b38bd25fd3e2773b20c
+++ libpurple/protocols/facebook/libfacebook.c	447422b0f0485ea215b57f80293182de67dfcc2e
@@ -667,7 +667,14 @@ static void plugin_init(PurplePlugin *pl
 	prpl_info->protocol_options = g_list_append(
 		prpl_info->protocol_options, option);
 
+	
 	option = purple_account_option_bool_new(
+		_("Use Facebook friend-lists as Pidgin groups"),
+		"facebook_use_groups", TRUE);
+	prpl_info->protocol_options = g_list_append(
+		prpl_info->protocol_options, option);
+	
+	option = purple_account_option_bool_new(
 		_("Hide myself in the Buddy List"),
 		"facebook_hide_self", TRUE);
 	prpl_info->protocol_options = g_list_append(
@@ -684,6 +691,12 @@ static void plugin_init(PurplePlugin *pl
 		"facebook_get_notifications", TRUE);
 	prpl_info->protocol_options = g_list_append(
 		prpl_info->protocol_options, option);
+	
+	option = purple_account_option_string_new(
+		_("Notifications RSS Feed URL"),
+		"notifications_feed_url", "");
+	prpl_info->protocol_options = g_list_append(
+		prpl_info->protocol_options, option);
 
 	option = purple_account_option_bool_new(
 		_("Edit Facebook friends from Pidgin"),
============================================================
--- libpurple/protocols/facebook/libfacebook.h	dbc2bfd413ba1089196a55882771e37b6da1bc35
+++ libpurple/protocols/facebook/libfacebook.h	b7634eccfe4ac79928e153d73436504d5c15b020
@@ -67,10 +67,6 @@
 #include "sslconn.h"
 #include "version.h"
 
-#ifdef HAVE_ZLIB
-#	include <zlib.h>
-#endif
-
 #if GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 12
 #	define atoll(a) g_ascii_strtoll(a, NULL, 0)
 #endif


More information about the Commits mailing list