Mercurial > pidgin
comparison libpurple/protocols/yahoo/yahoo.c @ 26139:1cf212ba3926
Remove some bugs related to inserting some data into hash table, data for connected peers
author | Sulabh Mahajan <sulabh@soc.pidgin.im> |
---|---|
date | Mon, 21 Jul 2008 09:07:42 +0000 |
parents | 2666b864dc89 |
children | c031f88aa026 |
comparison
equal
deleted
inserted
replaced
26138:9a5da524fba9 | 26139:1cf212ba3926 |
---|---|
2375 GSList *l = pkt->hash; | 2375 GSList *l = pkt->hash; |
2376 struct yahoo_packet *pkt_to_send; | 2376 struct yahoo_packet *pkt_to_send; |
2377 PurpleAccount *account; | 2377 PurpleAccount *account; |
2378 int val_13_to_send = 0; | 2378 int val_13_to_send = 0; |
2379 struct yahoo_data *yd; | 2379 struct yahoo_data *yd; |
2380 YahooFriend *f; | |
2380 | 2381 |
2381 if(!(p2p_data = data)) | 2382 if(!(p2p_data = data)) |
2382 return ; | 2383 return ; |
2383 | 2384 |
2384 yd = p2p_data->gc->proto_data; | 2385 yd = p2p_data->gc->proto_data; |
2431 13, val_13_to_send); | 2432 13, val_13_to_send); |
2432 | 2433 |
2433 /* build the raw packet and send it to the host */ | 2434 /* build the raw packet and send it to the host */ |
2434 yahoo_p2p_write_pkt(source, pkt_to_send); | 2435 yahoo_p2p_write_pkt(source, pkt_to_send); |
2435 yahoo_packet_free(pkt_to_send); | 2436 yahoo_packet_free(pkt_to_send); |
2437 | |
2438 if( val_13_to_send == 7 ) | |
2439 if( !g_hash_table_lookup(yd->peers, p2p_data->host_username) ) { | |
2440 g_hash_table_insert(yd->peers, g_strdup(p2p_data->host_username), p2p_data); | |
2441 /* If the peer is a friend, set him connected */ | |
2442 f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username); | |
2443 if (f) { | |
2444 if(p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER) { | |
2445 p2p_data->session_id = f->session_id; | |
2446 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_SERVER); | |
2447 } | |
2448 else | |
2449 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_CLIENT); | |
2450 } | |
2451 } | |
2436 } | 2452 } |
2437 | 2453 |
2438 /* callback function associated with receiving of data, not considering receipt of multiple YMSG packets in a single TCP packet */ | 2454 /* callback function associated with receiving of data, not considering receipt of multiple YMSG packets in a single TCP packet */ |
2439 static void yahoo_p2p_read_pkt_cb(gpointer data, gint source, PurpleInputCondition cond) | 2455 static void yahoo_p2p_read_pkt_cb(gpointer data, gint source, PurpleInputCondition cond) |
2440 { | 2456 { |
2456 return ; /* No Worries*/ | 2472 return ; /* No Worries*/ |
2457 else if (len <= 0) | 2473 else if (len <= 0) |
2458 { | 2474 { |
2459 purple_debug_warning("yahoo","p2p: Error in connection, or host disconnected\n"); | 2475 purple_debug_warning("yahoo","p2p: Error in connection, or host disconnected\n"); |
2460 /* remove from p2p connection lists, also calls yahoo_p2p_disconnect_destroy_data */ | 2476 /* remove from p2p connection lists, also calls yahoo_p2p_disconnect_destroy_data */ |
2461 g_hash_table_remove(yd->peers,p2p_data->host_username); | 2477 if( g_hash_table_lookup(yd->peers, p2p_data->host_username) ) |
2478 g_hash_table_remove(yd->peers,p2p_data->host_username); | |
2479 else | |
2480 yahoo_p2p_disconnect_destroy_data(data); | |
2462 return; | 2481 return; |
2463 } | 2482 } |
2464 | 2483 |
2465 if(len < YAHOO_PACKET_HDRLEN) | 2484 if(len < YAHOO_PACKET_HDRLEN) |
2466 return; | 2485 return; |
2514 | 2533 |
2515 static void yahoo_p2p_server_send_connected_cb(gpointer data, gint source, PurpleInputCondition cond) | 2534 static void yahoo_p2p_server_send_connected_cb(gpointer data, gint source, PurpleInputCondition cond) |
2516 { | 2535 { |
2517 int acceptfd; | 2536 int acceptfd; |
2518 struct yahoo_p2p_data *p2p_data; | 2537 struct yahoo_p2p_data *p2p_data; |
2519 YahooFriend *f; | |
2520 struct yahoo_data *yd; | 2538 struct yahoo_data *yd; |
2521 | 2539 |
2522 if(!(p2p_data = data)) | 2540 if(!(p2p_data = data)) |
2523 return ; | 2541 return ; |
2524 yd = p2p_data->gc->proto_data; | 2542 yd = p2p_data->gc->proto_data; |
2535 /* remove watcher and close p2p server */ | 2553 /* remove watcher and close p2p server */ |
2536 purple_input_remove(yd->yahoo_p2p_server_watcher); | 2554 purple_input_remove(yd->yahoo_p2p_server_watcher); |
2537 close(yd->yahoo_local_p2p_server_fd); | 2555 close(yd->yahoo_local_p2p_server_fd); |
2538 yd->yahoo_local_p2p_server_fd = -1; | 2556 yd->yahoo_local_p2p_server_fd = -1; |
2539 | 2557 |
2540 if( (f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username)) ) { | |
2541 p2p_data->session_id = f->session_id; | |
2542 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_SERVER); | |
2543 } | |
2544 | |
2545 /* Add an Input Read event to the file descriptor */ | 2558 /* Add an Input Read event to the file descriptor */ |
2546 p2p_data->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); | 2559 p2p_data->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); |
2547 p2p_data->source = acceptfd; | 2560 p2p_data->source = acceptfd; |
2548 | |
2549 g_hash_table_insert(yd->peers, g_strdup(p2p_data->host_username), p2p_data); | |
2550 } | 2561 } |
2551 | 2562 |
2552 static void yahoo_p2p_server_listen_cb(int listenfd, gpointer data) | 2563 static void yahoo_p2p_server_listen_cb(int listenfd, gpointer data) |
2553 { | 2564 { |
2554 struct yahoo_p2p_data *p2p_data; | 2565 struct yahoo_p2p_data *p2p_data; |
2580 gchar *base64_ip = NULL; | 2591 gchar *base64_ip = NULL; |
2581 YahooFriend *f; | 2592 YahooFriend *f; |
2582 struct yahoo_packet *pkt; | 2593 struct yahoo_packet *pkt; |
2583 PurpleAccount *account; | 2594 PurpleAccount *account; |
2584 struct yahoo_data *yd = gc->proto_data; | 2595 struct yahoo_data *yd = gc->proto_data; |
2585 struct yahoo_p2p_data *p2p_data = g_new0(struct yahoo_p2p_data, 1); | 2596 struct yahoo_p2p_data *p2p_data; |
2597 | |
2598 f = yahoo_friend_find(gc, who); | |
2599 account = purple_connection_get_account(gc); | |
2600 /* send packet to only those friends who arent p2p connected and to whom we havent already sent. Do not send if this condition doesn't hold good */ | |
2601 if( !( f && (yahoo_friend_get_p2p_status(f) == YAHOO_P2PSTATUS_NOT_CONNECTED) && (f->p2p_packet_sent == 0)) ) | |
2602 return; | |
2586 | 2603 |
2587 public_ip = purple_network_get_public_ip(); | 2604 public_ip = purple_network_get_public_ip(); |
2588 if( (sscanf(public_ip, "%u.%u.%u.%u", &temp[0], &temp[1], &temp[2], &temp[3])) !=4 ) | 2605 if( (sscanf(public_ip, "%u.%u.%u.%u", &temp[0], &temp[1], &temp[2], &temp[3])) !=4 ) |
2589 return ; | 2606 return ; |
2590 | 2607 |
2591 ip = (temp[3] << 24) | (temp[2] <<16) | (temp[1] << 8) | temp[0]; | 2608 ip = (temp[3] << 24) | (temp[2] <<16) | (temp[1] << 8) | temp[0]; |
2592 sprintf(temp_str, "%d", ip); | 2609 sprintf(temp_str, "%d", ip); |
2593 base64_ip = purple_base64_encode( (guchar *)temp_str, strlen(temp_str) ); | 2610 base64_ip = purple_base64_encode( (guchar *)temp_str, strlen(temp_str) ); |
2594 | |
2595 f = yahoo_friend_find(gc, who); | |
2596 account = purple_connection_get_account(gc); | |
2597 | |
2598 /* send packet to only those friends who arent p2p connected and to whom we havent already sent. Do not send if this condition doesn't hold good */ | |
2599 if( !( f && (yahoo_friend_get_p2p_status(f) == YAHOO_P2PSTATUS_NOT_CONNECTED) && (f->p2p_packet_sent == 0)) ) | |
2600 return; | |
2601 | 2611 |
2602 pkt = yahoo_packet_new(YAHOO_SERVICE_PEERTOPEER, YAHOO_STATUS_AVAILABLE, 0); | 2612 pkt = yahoo_packet_new(YAHOO_SERVICE_PEERTOPEER, YAHOO_STATUS_AVAILABLE, 0); |
2603 yahoo_packet_hash(pkt, "sssissis", | 2613 yahoo_packet_hash(pkt, "sssissis", |
2604 1, purple_normalize(account, purple_account_get_username(account)), | 2614 1, purple_normalize(account, purple_account_get_username(account)), |
2605 4, purple_normalize(account, purple_account_get_username(account)), | 2615 4, purple_normalize(account, purple_account_get_username(account)), |
2611 49, "PEERTOPEER"); | 2621 49, "PEERTOPEER"); |
2612 yahoo_packet_send_and_free(pkt, yd); | 2622 yahoo_packet_send_and_free(pkt, yd); |
2613 | 2623 |
2614 f->p2p_packet_sent = 1; /* set p2p_packet_sent to sent */ | 2624 f->p2p_packet_sent = 1; /* set p2p_packet_sent to sent */ |
2615 | 2625 |
2626 p2p_data = g_new0(struct yahoo_p2p_data, 1); | |
2627 | |
2616 p2p_data->gc = gc; | 2628 p2p_data->gc = gc; |
2617 p2p_data->host_ip = NULL; | 2629 p2p_data->host_ip = NULL; |
2618 p2p_data->host_username = (char *)g_malloc(strlen(who)); | 2630 p2p_data->host_username = (char *)g_malloc(strlen(who)); |
2619 strcpy(p2p_data->host_username, who); | 2631 strcpy(p2p_data->host_username, who); |
2620 p2p_data->val_13 = val_13; | 2632 p2p_data->val_13 = val_13; |
2629 static void yahoo_p2p_init_cb(gpointer data, gint source, const gchar *error_message) | 2641 static void yahoo_p2p_init_cb(gpointer data, gint source, const gchar *error_message) |
2630 { | 2642 { |
2631 struct yahoo_p2p_data *p2p_data; | 2643 struct yahoo_p2p_data *p2p_data; |
2632 struct yahoo_packet *pkt_to_send; | 2644 struct yahoo_packet *pkt_to_send; |
2633 PurpleAccount *account; | 2645 PurpleAccount *account; |
2634 YahooFriend *f; | |
2635 struct yahoo_data *yd; | 2646 struct yahoo_data *yd; |
2636 | 2647 |
2637 if(!(p2p_data = data)) | 2648 if(!(p2p_data = data)) |
2638 return ; | 2649 return ; |
2639 yd = p2p_data->gc->proto_data; | 2650 yd = p2p_data->gc->proto_data; |
2647 } | 2658 } |
2648 | 2659 |
2649 /* Add an Input Read event to the file descriptor */ | 2660 /* Add an Input Read event to the file descriptor */ |
2650 p2p_data->input_event = purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); | 2661 p2p_data->input_event = purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); |
2651 p2p_data->source = source; | 2662 p2p_data->source = source; |
2652 | |
2653 g_hash_table_insert(yd->peers, g_strdup(p2p_data->host_username), p2p_data); | |
2654 | |
2655 /* If the peer is a friend, set him connected */ | |
2656 f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username); | |
2657 if (f) | |
2658 yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_WE_ARE_CLIENT); | |
2659 | 2663 |
2660 account = purple_connection_get_account(p2p_data->gc); | 2664 account = purple_connection_get_account(p2p_data->gc); |
2661 | 2665 |
2662 /* Build the yahoo packet */ | 2666 /* Build the yahoo packet */ |
2663 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, yd->session_id); | 2667 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, yd->session_id); |
2681 gsize len; | 2685 gsize len; |
2682 gint val_13 = 0; | 2686 gint val_13 = 0; |
2683 gint val_11 = 0; | 2687 gint val_11 = 0; |
2684 PurpleAccount *account; | 2688 PurpleAccount *account; |
2685 YahooFriend *f; | 2689 YahooFriend *f; |
2690 | |
2691 /* if status is YAHOO_STATUS_BUSY, don't do anything, peer wont connect */ | |
2692 if(pkt->status == YAHOO_STATUS_BUSY) | |
2693 return ; | |
2686 | 2694 |
2687 while (l) { | 2695 while (l) { |
2688 struct yahoo_pair *pair = l->data; | 2696 struct yahoo_pair *pair = l->data; |
2689 | 2697 |
2690 switch (pair->key) { | 2698 switch (pair->key) { |