diff libpurple/protocols/yahoo/libymsg.c @ 31648:fa88dc1dcabb

merged from im.pidgin.pidgin
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sat, 12 Feb 2011 04:17:09 +0900
parents 63b9cb97d356 a8cc50c2279f
children 7281d151e492
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/libymsg.c	Tue Dec 21 21:05:26 2010 +0900
+++ b/libpurple/protocols/yahoo/libymsg.c	Sat Feb 12 04:17:09 2011 +0900
@@ -849,7 +849,7 @@
 
 		if (fed_from != from)
 			g_free(fed_from);
-	
+
 	} else if (!g_ascii_strncasecmp(msg, "GAME", strlen("GAME"))) {
 		PurpleBuddy *bud = purple_find_buddy(account, from);
 
@@ -1012,7 +1012,7 @@
 						break;
 				}
 				purple_debug_info("yahoo", "Message from federated (%d) buddy %s.\n", im->fed, im->fed_from);
-					
+
 			}
 			/* peer session id */
 			if (im && (pair->key == 11)) {
@@ -1217,7 +1217,7 @@
 						  13, 1,
 						  334, 0);
 	}
-		
+
 	yahoo_packet_send_and_free(pkt, yd);
 
 	g_free(add_req->id);
@@ -1314,7 +1314,7 @@
 	PurpleAccount *account;
 	GSList *l = pkt->hash;
 	const char *msg = NULL;
-	
+
 	account = purple_connection_get_account(gc);
 
 	/* Buddy authorized/declined our addition */
@@ -1730,7 +1730,7 @@
 
 	purple_debug_info("yahoo", "yahoo status: %d\n", yd->current_status);
 	pkt = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->current_status, yd->session_id);
-	
+
 	if(yd->cookie_b) { /* send B cookie if we have it */
 		yahoo_packet_hash(pkt, "ssssssssss",
 					1, name,
@@ -1801,7 +1801,7 @@
 	purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage2\n");
 
 	yd->url_datas = g_slist_remove(yd->url_datas, url_data);
-	
+
 	if (error_message != NULL) {
 		purple_debug_error("yahoo", "Login Failed, unable to retrieve stage 2 url: %s\n", error_message);
 		purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message);
@@ -1815,7 +1815,7 @@
 		int response_no = -1;
 		char *crumb = NULL;
 		char *crypt = NULL;
-		
+
 		if(g_strv_length(splits) > 1) {
 			yd->cookie_b = yahoo_auth16_get_cookie_b(splits[0]);
 			split_data = g_strsplit(splits[1], "\r\n", -1);
@@ -2679,14 +2679,15 @@
 	if(!(p2p_data = data))
 		return ;
 
+	yd = p2p_data->gc->proto_data;
+	yd->listen_data = NULL;
+
 	if(listenfd == -1) {
 		purple_debug_warning("yahoo","p2p: error starting p2p server\n");
 		yahoo_p2p_disconnect_destroy_data(data);
 		return;
 	}
 
-	yd = p2p_data->gc->proto_data;
-
 	/* Add an Input Read event to the file descriptor */
 	yd->yahoo_local_p2p_server_fd = listenfd;
 	yd->yahoo_p2p_server_watcher = purple_input_add(listenfd, PURPLE_INPUT_READ, yahoo_p2p_server_send_connected_cb,data);
@@ -2765,8 +2766,15 @@
 	p2p_data->connection_type = YAHOO_P2P_WE_ARE_SERVER;
 	p2p_data->source = -1;
 
-	/* FIXME: Shouldn't this deal with the PurpleNetworkListenData* */
-	purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
+	/* FIXME: If the port is already used, purple_network_listener returns NULL and old listener won't be canceled
+	 * in yahoo_close function. */
+	if (yd->listen_data)
+		purple_debug_warning("yahoo","p2p: Failed to create p2p server - server already exists\n");
+	else {
+		yd->listen_data = purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
+		if (yd->listen_data == NULL)
+			purple_debug_warning("yahoo","p2p: Failed to created p2p server\n");
+	}
 
 	g_free(base64_ip);
 }
@@ -3790,6 +3798,8 @@
 		yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo);
 	if (yd->ycht)
 		ycht_connection_close(yd->ycht);
+	if (yd->listen_data != NULL)
+		purple_network_listen_cancel(yd->listen_data);
 
 	g_free(yd->pending_chat_room);
 	g_free(yd->pending_chat_id);
@@ -4697,7 +4707,7 @@
 			default:
 				break;
 		}
-		
+
 		yahoo_packet_hash(pkt, "ssssss", 49, "TYPING", 1, purple_connection_get_display_name(gc),
                   14, " ", 13, state == PURPLE_TYPING ? "1" : "0",
                   5, fed_who, 1002, "1");
@@ -5103,7 +5113,7 @@
 		yahoo_packet_hash(pkt, "ssis", 1, purple_connection_get_display_name(gc), 7, who+4, 241, fed, 13, "2");
 	else
 		yahoo_packet_hash(pkt, "sss", 1, purple_connection_get_display_name(gc), 7, who, 13, "2");
-	
+
 	yahoo_packet_send_and_free(pkt, yd);
 }