comparison libpurple/protocols/yahoo/yahoo.c @ 25014:11e2d8a878b0

Close p2p connection when read() does not return anything.
author Sulabh Mahajan <sulabh@soc.pidgin.im>
date Fri, 13 Jun 2008 11:04:13 +0000
parents 193093790ada
children f1de4ccc433e
comparison
equal deleted inserted replaced
25013:ef47df3e5dd4 25014:11e2d8a878b0
244 244
245 f->away = strtol(pair->value, NULL, 10); 245 f->away = strtol(pair->value, NULL, 10);
246 if (f->away == 2) { 246 if (f->away == 2) {
247 /* Idle may have already been set in a more precise way in case 137 */ 247 /* Idle may have already been set in a more precise way in case 137 */
248 if (f->idle == 0) 248 if (f->idle == 0)
249 f->idle = time(NULL); 249 f->idle = time(NULL) - 60; /*start idle at 1 min*/
250 } 250 }
251 251
252 break; 252 break;
253 case 138: /* either we're not idle, or we are but won't say how long */ 253 case 138: /* either we're not idle, or we are but won't say how long */
254 if (!f) 254 if (!f)
2294 int pktlen; 2294 int pktlen;
2295 struct yahoo_packet *pkt; 2295 struct yahoo_packet *pkt;
2296 guchar *start = NULL; 2296 guchar *start = NULL;
2297 struct yahoo_p2p_data *user_data; 2297 struct yahoo_p2p_data *user_data;
2298 2298
2299 user_data = data; 2299 if(!(user_data = data))
2300 2300 return ;
2301 if((len = read(source, buf, sizeof(buf))) <= 0 ) 2301
2302 purple_debug_warning("yahoo","p2p: Error in connection to p2p host\n"); 2302 if((len = read(source, buf, sizeof(buf))) <= 0 ) {
2303 purple_debug_warning("yahoo","p2p: Error in connection to p2p host or host disconnected\n");
2304 purple_input_remove(user_data->input_event);
2305 close(source);
2306 /*free user data*/
2307 g_free(user_data->host_ip);
2308 g_free(user_data->host_username);
2309 g_free(user_data);
2310 }
2303 2311
2304 if(len < YAHOO_PACKET_HDRLEN) 2312 if(len < YAHOO_PACKET_HDRLEN)
2305 return; 2313 return;
2314
2306 if(strncmp((char *)buf, "YMSG", MIN(4, len)) != 0) { 2315 if(strncmp((char *)buf, "YMSG", MIN(4, len)) != 0) {
2307 /* Not a YMSG packet */ 2316 /* Not a YMSG packet */
2308 purple_debug_warning("yahoo","p2p: Got something other than YMSG packet\n"); 2317 purple_debug_warning("yahoo","p2p: Got something other than YMSG packet\n");
2309 2318
2310 start = memchr(buf + 1, 'Y', len - 1); 2319 start = memchr(buf + 1, 'Y', len - 1);
2359 2368
2360 if(error_message != NULL) { 2369 if(error_message != NULL) {
2361 purple_debug_warning("yahoo","p2p: %s\n",error_message); 2370 purple_debug_warning("yahoo","p2p: %s\n",error_message);
2362 return; 2371 return;
2363 } 2372 }
2364 /*Add an Input Read event to the file descriptor*/
2365 purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data);
2366
2367 if(!(user_data = data)) 2373 if(!(user_data = data))
2368 return ; 2374 return ;
2375
2376 /*Add an Input Read event to the file descriptor*/
2377 user_data->input_event = purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data);
2369 2378
2370 account = purple_connection_get_account(user_data->gc); 2379 account = purple_connection_get_account(user_data->gc);
2371 2380
2372 /*Build the yahoo packet*/ 2381 /*Build the yahoo packet*/
2373 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, user_data->session_id); 2382 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, user_data->session_id);