changeset 27783:b31b72cd273d

propagate from branch 'im.pidgin.pidgin' (head e4cc3b79eb04e4937c5fa764f6839a8e07397651) to branch 'im.pidgin.pidgin.yaz' (head 480885df34dae64acc001d1e6fea97379e067bb4)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 05 Mar 2008 15:00:54 +0000
parents 9cd7892b2c8b (current diff) 316c8565f562 (diff)
children 0966717651b0
files libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo.h
diffstat 5 files changed, 114 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/buddyicon.c	Tue Mar 04 18:12:32 2008 +0000
+++ b/libpurple/buddyicon.c	Wed Mar 05 15:00:54 2008 +0000
@@ -121,13 +121,8 @@
 		}
 	}
 
-	if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
-		purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img),
-							purple_imgstore_get_size(img));	
-	} else 	{
-		purple_debug_error("buddyicon", "Unable to create file %s: %s\n",
-		                   path, "File already exists.");
-	}
+	purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img),
+											purple_imgstore_get_size(img));	
 	g_free(path);
 }
 
--- a/libpurple/protocols/jabber/buddy.c	Tue Mar 04 18:12:32 2008 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Wed Mar 05 15:00:54 2008 +0000
@@ -101,8 +101,36 @@
 		if(!jbr && !resource) {
 			jbr = l->data;
 		} else if(!resource) {
-			if(((JabberBuddyResource *)l->data)->priority >= jbr->priority)
+			if(((JabberBuddyResource *)l->data)->priority > jbr->priority)
 				jbr = l->data;
+			else if(((JabberBuddyResource *)l->data)->priority == jbr->priority) {
+				/* Determine if this resource is more available than the one we've currently chosen */
+				switch(((JabberBuddyResource *)l->data)->state) {
+					case JABBER_BUDDY_STATE_ONLINE:
+					case JABBER_BUDDY_STATE_CHAT:
+						/* This resource is online/chatty. Prefer to one which isn't either. */
+						if ((jbr->state != JABBER_BUDDY_STATE_ONLINE) && (jbr->state != JABBER_BUDDY_STATE_CHAT))
+							jbr = l->data;
+						break;
+					case JABBER_BUDDY_STATE_AWAY:
+					case JABBER_BUDDY_STATE_DND:
+					case JABBER_BUDDY_STATE_UNAVAILABLE:
+						/* This resource is away/dnd/unavailable. Prefer to one which is extended away or unknown. */
+						if ((jbr->state == JABBER_BUDDY_STATE_XA) || 
+							(jbr->state == JABBER_BUDDY_STATE_UNKNOWN) || (jbr->state == JABBER_BUDDY_STATE_ERROR))
+							jbr = l->data;
+						break;
+					case JABBER_BUDDY_STATE_XA:
+						/* This resource is extended away. That's better than unknown. */
+						if ((jbr->state == JABBER_BUDDY_STATE_UNKNOWN) || (jbr->state == JABBER_BUDDY_STATE_ERROR))
+							jbr = l->data;
+						break;
+					case JABBER_BUDDY_STATE_UNKNOWN:
+					case JABBER_BUDDY_STATE_ERROR:
+						/* These are never preferable. */
+						break;
+				}
+			}
 		} else if(((JabberBuddyResource *)l->data)->name) {
 			if(!strcmp(((JabberBuddyResource *)l->data)->name, resource)) {
 				jbr = l->data;
--- a/libpurple/protocols/yahoo/yahoo.c	Tue Mar 04 18:12:32 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Wed Mar 05 15:00:54 2008 +0000
@@ -464,7 +464,6 @@
 	PurpleAccount *account = purple_connection_get_account(gc);
 	struct yahoo_data *yd = gc->proto_data;
 	GHashTable *ht;
-	char *grp = NULL;
 	char *norm_bud = NULL;
 	YahooFriend *f = NULL; /* It's your friends. They're going to want you to share your StarBursts. */
 	                       /* But what if you had no friends? */
@@ -487,8 +486,8 @@
 			 */
 			if (pair->value && !strcmp(pair->value, "320")) {
 				/* No longer in any group; this indicates the start of the ignore list. */
-				g_free(grp);
-				grp = NULL;
+				g_free(yd->current_list15_grp);
+				yd->current_list15_grp = NULL;
 			}
 
 			break;
@@ -497,28 +496,30 @@
 		case 300: /* This is 318 before a group, 319 before any s/n in a group, and 320 before any ignored s/n. */
 			break;
 		case 65: /* This is the group */
-			g_free(grp);
-			grp = yahoo_string_decode(gc, pair->value, FALSE);
+			g_free(yd->current_list15_grp);
+			yd->current_list15_grp = yahoo_string_decode(gc, pair->value, FALSE);
 			break;
 		case 7: /* buddy's s/n */
 			g_free(norm_bud);
 			norm_bud = g_strdup(purple_normalize(account, pair->value));
 
-			if (grp) {
+			if (yd->current_list15_grp) {
 				/* This buddy is in a group */
 				f = yahoo_friend_find_or_new(gc, norm_bud);
 				if (!(b = purple_find_buddy(account, norm_bud))) {
-					if (!(g = purple_find_group(grp))) {
-						g = purple_group_new(grp);
+					if (!(g = purple_find_group(yd->current_list15_grp))) {
+						g = purple_group_new(yd->current_list15_grp);
 						purple_blist_add_group(g, NULL);
 					}
 					b = purple_buddy_new(account, norm_bud, NULL);
 					purple_blist_add_buddy(b, NULL, g, NULL);
 				}
-				yahoo_do_group_check(account, ht, norm_bud, grp);
+				yahoo_do_group_check(account, ht, norm_bud, yd->current_list15_grp);
 
 			} else {
 				/* This buddy is on the ignore list (and therefore in no group) */
+				purple_debug_info("yahoo", "%s adding %s to the deny list because of the ignore list / no group was found",
+								  account->username, norm_bud);
 				purple_privacy_deny_add(account, norm_bud, 1);
 			}
 			break;
@@ -543,7 +544,6 @@
 
 	g_hash_table_foreach(ht, yahoo_do_group_cleanup, NULL);
 	g_hash_table_destroy(ht);
-	g_free(grp);
 	g_free(norm_bud);
 }
 
@@ -3085,6 +3085,8 @@
 	g_free(yd->pending_chat_topic);
 	g_free(yd->pending_chat_goto);
 
+	g_free(yd->current_list15_grp);
+
 	g_free(yd);
 	gc->proto_data = NULL;
 }
--- a/libpurple/protocols/yahoo/yahoo.h	Tue Mar 04 18:12:32 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.h	Wed Mar 05 15:00:54 2008 +0000
@@ -176,6 +176,12 @@
 	GSList *url_datas;
 	GHashTable *xfer_peer_idstring_map;/*Hey, i dont know, but putting this HashTable next to friends gives a run time fault...*/
 	GSList *cookies;/*contains all cookies, including _y and _t*/
+	
+	/**
+	 * We may receive a list15 in multiple packets with no prior warning as to how many we'll be getting;
+	 * the server expects us to keep track of the group for which it is sending us contact names.
+	 */
+	char *current_list15_grp;
 };
 
 #define YAHOO_MAX_STATUS_MESSAGE_LENGTH (255)
--- a/libpurple/proxy.c	Tue Mar 04 18:12:32 2008 +0000
+++ b/libpurple/proxy.c	Wed Mar 05 15:00:54 2008 +0000
@@ -211,67 +211,78 @@
 purple_gnome_proxy_get_info(void)
 {
 	static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
-	gchar *path;
-	if ((path = g_find_program_in_path("gconftool-2"))) {
-		gchar *tmp;
-
-		g_free(path);
+	gchar *tmp;
 
-		/* See whether to use a proxy. */
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", &tmp,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		if (!strcmp(tmp, "none\n")) {
-			info.type = PURPLE_PROXY_NONE;
-			g_free(tmp);
-			return &info;
-		} else if (strcmp(tmp, "manual\n")) {
-			g_free(tmp);
-			return purple_global_proxy_get_info();
-		}
+	tmp = g_find_program_in_path("gconftool-2");
+	if (tmp == NULL)
+		return purple_global_proxy_get_info();
 
-		g_free(tmp);
-		info.type = PURPLE_PROXY_HTTP;
+	g_free(tmp);
 
-		/* Free the old fields */
-		if (info.host) {
-			g_free(info.host);
-			info.host = NULL;
-		}
-		if (info.username) {
-			g_free(info.username);
-			info.username = NULL;
-		}
-		if (info.password) {
-			g_free(info.password);
-			info.password = NULL;
-		}
+	/* Check whether to use a proxy. */
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode",
+			&tmp, NULL, NULL, NULL))
+		return purple_global_proxy_get_info();
 
-		/* Get the new ones */
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		g_strchomp(info.host);
-
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		g_strchomp(info.username);
-
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		g_strchomp(info.password);
-
-		if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp,
-					       NULL, NULL, NULL))
-			return purple_global_proxy_get_info();
-		info.port = atoi(tmp);
+	if (!strcmp(tmp, "none\n")) {
+		info.type = PURPLE_PROXY_NONE;
 		g_free(tmp);
-
 		return &info;
 	}
-	return purple_global_proxy_get_info();
+
+	if (strcmp(tmp, "manual\n")) {
+		/* Unknown setting.  Fallback to using our global proxy settings. */
+		g_free(tmp);
+		return purple_global_proxy_get_info();
+	}
+
+	g_free(tmp);
+
+	/* If we get this far then we know we're using an HTTP proxy */
+	info.type = PURPLE_PROXY_HTTP;
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host",
+			&info.host, NULL, NULL, NULL))
+		return purple_global_proxy_get_info();
+	g_strchomp(info.host);
+	if (*info.host == '\0')
+	{
+		purple_debug_info("proxy", "Gnome proxy settings are set to "
+				"'manual' but no proxy server is specified.  Using "
+				"Pidgin's proxy settings instead.\n");
+		g_free(info.host);
+		return purple_global_proxy_get_info();
+	}
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user",
+			&info.username, NULL, NULL, NULL))
+	{
+		g_free(info.host);
+		return purple_global_proxy_get_info();
+	}
+	g_strchomp(info.username);
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password",
+			&info.password, NULL, NULL, NULL))
+	{
+		g_free(info.host);
+		g_free(info.username);
+		return purple_global_proxy_get_info();
+	}
+	g_strchomp(info.password);
+
+	if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port",
+			&tmp, NULL, NULL, NULL))
+	{
+		g_free(info.host);
+		g_free(info.username);
+		g_free(info.password);
+		return purple_global_proxy_get_info();
+	}
+	info.port = atoi(tmp);
+	g_free(tmp);
+
+	return &info;
 }
 /**************************************************************************
  * Proxy API