adium.1-3: 6adbe0b8: pidgin-facebook 1.5.0+ at r 467. This (r...

evands at pidgin.im evands at pidgin.im
Wed May 6 08:50:31 EDT 2009


-----------------------------------------------------------------
Revision: 6adbe0b88ec4cc63fa19232e6853c5c183e99634
Ancestor: 6241ee8a8aa0e9c6ad8ddf93a43a62e2f3da5fd7
Author: evands at pidgin.im
Date: 2009-05-06T12:45:31
Branch: im.pidgin.adium.1-3
URL: http://d.pidgin.im/viewmtn/revision/info/6adbe0b88ec4cc63fa19232e6853c5c183e99634

Modified files:
        libpurple/protocols/facebook/fb_connection.c
        libpurple/protocols/facebook/fb_messages.c
        libpurple/protocols/facebook/fb_messages.h
        libpurple/protocols/facebook/libfacebook.c
        libpurple/protocols/facebook/libfacebook.h

ChangeLog: 

pidgin-facebook 1.5.0+ at r 467. This (re)applies my patch for the timer disconnect crash and improves proxy support.

-------------- next part --------------
============================================================
--- libpurple/protocols/facebook/fb_connection.c	9a80b89fd6fe38724437f7ac53723b107442e459
+++ libpurple/protocols/facebook/fb_connection.c	47f7c43df1f9af82cbaf76849d65aeb1671b7f4d
@@ -427,6 +427,9 @@ void fb_post_or_get(FacebookAccount *fba
 	const gchar *user_agent;
 	const gchar* const *languages;
 	gchar *language_names;
+	PurpleProxyInfo *proxy_info = NULL;
+	gchar *proxy_auth;
+	gchar *proxy_auth_base64;
 
 	/* TODO: Fix keepalive and use it as much as possible */
 	keepalive = FALSE;
@@ -434,15 +437,19 @@ void fb_post_or_get(FacebookAccount *fba
 	if (host == NULL)
 		host = "www.facebook.com";
 
-	if (fba && fba->account && fba->account->proxy_info &&
-		(fba->account->proxy_info->type == PURPLE_PROXY_HTTP ||
-		(fba->account->proxy_info->type == PURPLE_PROXY_USE_GLOBAL &&
-			purple_global_proxy_get_info() &&
-			purple_global_proxy_get_info()->type ==
-					PURPLE_PROXY_HTTP)))
+	if (fba && fba->account && !(method & FB_METHOD_SSL))
 	{
+		proxy_info = purple_proxy_get_setup(fba->account);
+		if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_USE_GLOBAL)
+			proxy_info = purple_global_proxy_get_info();
+		if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_HTTP)
+		{
+			is_proxy = TRUE;
+		}	
+	}
+	if (is_proxy == TRUE)
+	{
 		real_url = g_strdup_printf("http://%s%s", host, url);
-		is_proxy = TRUE;
 	} else {
 		real_url = g_strdup(url);
 	}
@@ -455,7 +462,8 @@ void fb_post_or_get(FacebookAccount *fba
 	g_string_append_printf(request, "%s %s HTTP/1.0\r\n",
 			(method & FB_METHOD_POST) ? "POST" : "GET",
 			real_url);
-	g_string_append_printf(request, "Host: %s\r\n", host);
+	if (is_proxy == FALSE)
+		g_string_append_printf(request, "Host: %s\r\n", host);
 	g_string_append_printf(request, "Connection: %s\r\n",
 			(keepalive ? "Keep-Alive" : "close"));
 	g_string_append_printf(request, "User-Agent: %s\r\n", user_agent);
@@ -471,6 +479,18 @@ void fb_post_or_get(FacebookAccount *fba
 	if (zlib_inflate != NULL)
 		g_string_append_printf(request, "Accept-Encoding: gzip\r\n");
 #endif
+	if (is_proxy == TRUE)
+	{
+		if (purple_proxy_info_get_username(proxy_info) &&
+			purple_proxy_info_get_password(proxy_info))
+		{
+			proxy_auth = g_strdup_printf("%s:%s", purple_proxy_info_get_username(proxy_info), purple_proxy_info_get_password(proxy_info));
+			proxy_auth_base64 = purple_base64_encode(proxy_auth, strlen(proxy_auth));
+			g_string_append_printf(request, "Proxy-Authorization: Basic %s\r\n", proxy_auth_base64);
+			g_free(proxy_auth_base64);
+			g_free(proxy_auth);
+		}
+	}
 
 	/* Tell the server what language we accept, so that we get error messages in our language (rather than our IP's) */
 	languages = g_get_language_names();
============================================================
--- libpurple/protocols/facebook/fb_messages.c	09af6820f46c993c5874e2765e3d40831096b7ee
+++ libpurple/protocols/facebook/fb_messages.c	1d28c3f65c157319609995aea0eadb7ac6e9ab79
@@ -30,11 +30,42 @@ struct _FacebookOutgoingMessage {
 	gchar *message;
 	gint msg_id;
 	guint retry_count;
+	guint resend_timer;
 };
 
 static gboolean fb_send_im_fom(FacebookOutgoingMessage *msg);
+static gboolean fb_resend_im_fom(FacebookOutgoingMessage *msg);
 static gboolean fb_get_new_messages(FacebookAccount *fba);
 
+static FacebookOutgoingMessage *fb_msg_create(FacebookAccount *fba)
+{
+	FacebookOutgoingMessage *msg;
+	
+	msg = g_new0(FacebookOutgoingMessage, 1);
+	msg->fba = fba;
+	
+	return msg;
+}
+
+static void fb_msg_destroy(FacebookOutgoingMessage *msg)
+{
+	if (msg->resend_timer) {
+		purple_timeout_remove(msg->resend_timer);
+	}
+	g_free(msg->who);
+	g_free(msg->message);
+	g_free(msg);	
+}
+
+void fb_cancel_resending_messages(FacebookAccount *fba)
+{
+	while (fba->resending_messages != NULL) {
+		FacebookOutgoingMessage *msg = fba->resending_messages->data;
+		fba->resending_messages = g_slist_remove(fba->resending_messages, msg);
+		fb_msg_destroy(msg);
+	}	
+}
+								  
 static void got_new_messages(FacebookAccount *fba, gchar *data,
 		gsize data_len, gpointer userdata)
 {
@@ -113,7 +144,8 @@ static void got_new_messages(FacebookAcc
 	/* refresh means that the session or post_form_id is invalid */
 	if (g_str_equal(data, "for (;;);{\"t\":\"refresh\"}"))
 	{
-		purple_timeout_add_seconds(1, (GSourceFunc)fb_get_post_form_id, fba);
+		if (fba->post_form_id_refresh_timer == 0)
+			fba->post_form_id_refresh_timer = purple_timeout_add_seconds(1, (GSourceFunc)fb_get_post_form_id, fba);
 		return;
 	}
 
@@ -399,7 +431,8 @@ static void fb_send_im_cb(FacebookAccoun
 				/* there was an error, either report it or retry */
 				if (msg->retry_count++ < FB_MAX_MSG_RETRY)
 				{
-					purple_timeout_add_seconds(1, (GSourceFunc)fb_send_im_fom, msg);
+					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_free(error_summary);
 					return;
 				}
@@ -416,9 +449,7 @@ static void fb_send_im_cb(FacebookAccoun
 	}
 
 	g_free(error_summary);
-	g_free(msg->who);
-	g_free(msg->message);
-	g_free(msg);
+	fb_msg_destroy(msg);
 }
 
 static gboolean fb_send_im_fom(FacebookOutgoingMessage *msg)
@@ -439,19 +470,24 @@ static gboolean fb_send_im_fom(FacebookO
 	return FALSE;
 }
 
+static gboolean fb_resend_im_fom(FacebookOutgoingMessage *msg)
+{
+	msg->fba->resending_messages = g_slist_remove(msg->fba->resending_messages, msg);
+
+	return fb_send_im_fom(msg);
+}
+
 int fb_send_im(PurpleConnection *pc, const gchar *who, const gchar *message, PurpleMessageFlags flags)
 {
 	FacebookOutgoingMessage *msg;
 
-	msg = g_new0(FacebookOutgoingMessage, 1);
-	msg->fba = pc->proto_data;
+	msg = fb_msg_create(pc->proto_data);
 
 	/* convert html to plaintext, removing trailing spaces */
 	msg->message = purple_markup_strip_html(message);
 	if (strlen(msg->message) > 999)
 	{
-		g_free(msg->message);
-		g_free(msg);
+		fb_msg_destroy(msg);
 		return -E2BIG;
 	}
 
@@ -532,6 +568,7 @@ gboolean fb_get_post_form_id(FacebookAcc
 
 gboolean fb_get_post_form_id(FacebookAccount *fba)
 {
+	fba->post_form_id_refresh_timer = 0;
 	fb_post_or_get(fba, FB_METHOD_GET, NULL, "/presence/popout.php", NULL, got_form_id_page, NULL, FALSE);
 	return FALSE;
 }
============================================================
--- libpurple/protocols/facebook/fb_messages.h	44345656bb5ce15bc8a1a50d66aaa6ed88426dff
+++ libpurple/protocols/facebook/fb_messages.h	79be7f4f904b524f43c1c45564065564b4cc1e96
@@ -27,4 +27,6 @@ int fb_send_im(PurpleConnection *pc, con
 int fb_send_im(PurpleConnection *pc, const gchar *who, const gchar *message,
 		PurpleMessageFlags flags);
 
+void fb_cancel_resending_messages(FacebookAccount *fba);
+
 #endif /* FACEBOOK_MESSAGES_H */
============================================================
--- libpurple/protocols/facebook/libfacebook.c	171834be239f664301869ffb3a517a1cc548fa56
+++ libpurple/protocols/facebook/libfacebook.c	4fb06c08fe0cadc12262920cccb69c59cdd6edd8
@@ -369,6 +369,9 @@ static void fb_close(PurpleConnection *p
 	if (fba->perpetual_messages_timer) {
 		purple_timeout_remove(fba->perpetual_messages_timer);
 	}
+	if (fba->post_form_id_refresh_timer) {
+		purple_timeout_remove(fba->post_form_id_refresh_timer);
+	}
 
 	purple_debug_info("facebook", "destroying %d incomplete connections\n",
 			g_slist_length(fba->conns));
@@ -383,6 +386,10 @@ static void fb_close(PurpleConnection *p
 		fba->dns_queries = g_slist_remove(fba->dns_queries, dns_query);
 		purple_dnsquery_destroy(dns_query);
 	}
+	
+	if (fba->resending_messages != NULL) {
+		fb_cancel_resending_messages(fba);
+	}
 
 	g_hash_table_destroy(fba->cookie_table);
 	g_hash_table_destroy(fba->hostname_ip_cache);
============================================================
--- libpurple/protocols/facebook/libfacebook.h	bb3ffbaac4c4edba105d1b79dd840c5744838ebf
+++ libpurple/protocols/facebook/libfacebook.h	3cd12690865ac9977b9e55a244d43fe3684dfb86
@@ -90,6 +90,7 @@ struct _FacebookAccount {
 	GSList *dns_queries;
 	GHashTable *cookie_table;
 	gchar *post_form_id;
+	guint post_form_id_refresh_timer;
 	gint32 uid;
 	guint buddy_list_timer;
 	guint friend_request_timer;
@@ -97,6 +98,7 @@ struct _FacebookAccount {
 	guint message_fetch_sequence;
 	gint64 last_messages[FB_LAST_MESSAGE_MAX];
 	guint16 next_message_pointer;
+	GSList *resending_messages;
 	GSList *auth_buddies;
 	GHashTable *hostname_ip_cache;
 	guint notifications_timer;


More information about the Commits mailing list