comparison libpurple/protocols/yahoo/yahoo.c @ 25062:6da23dc3000d

Changed user_data to more apt p2p_data, change in variable name.
author Sulabh Mahajan <sulabh@soc.pidgin.im>
date Wed, 02 Jul 2008 07:22:58 +0000
parents 048a53891afd
children 860d8ed4f7a6
comparison
equal deleted inserted replaced
25061:048a53891afd 25062:6da23dc3000d
2234 } 2234 }
2235 2235
2236 /*destroy p2p_data associated with a peer and close p2p connection*/ 2236 /*destroy p2p_data associated with a peer and close p2p connection*/
2237 static void yahoo_p2p_disconnect_destroy_data(gpointer data) 2237 static void yahoo_p2p_disconnect_destroy_data(gpointer data)
2238 { 2238 {
2239 struct yahoo_p2p_data *user_data; 2239 struct yahoo_p2p_data *p2p_data;
2240 YahooFriend *f; 2240 YahooFriend *f;
2241 2241
2242 if(!(user_data = data)) 2242 if(!(p2p_data = data))
2243 return ; 2243 return ;
2244 2244
2245 /*If friend, set him not connected*/ 2245 /*If friend, set him not connected*/
2246 f = yahoo_friend_find(user_data->gc, user_data->host_username); 2246 f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username);
2247 if (f) 2247 if (f)
2248 yahoo_friend_set_p2p_status(f, NOT_CONNECTED); 2248 yahoo_friend_set_p2p_status(f, NOT_CONNECTED);
2249 2249
2250 if(user_data->source) 2250 if(p2p_data->source)
2251 close(user_data->source); 2251 close(p2p_data->source);
2252 purple_input_remove(user_data->input_event); 2252 purple_input_remove(p2p_data->input_event);
2253 g_free(user_data->host_ip); 2253 g_free(p2p_data->host_ip);
2254 g_free(user_data->host_username); 2254 g_free(p2p_data->host_username);
2255 g_free(user_data); 2255 g_free(p2p_data);
2256 } 2256 }
2257 2257
2258 /*write pkt to the source*/ 2258 /*write pkt to the source*/
2259 static void yahoo_p2p_write_pkt(gint source, struct yahoo_packet *pkt) 2259 static void yahoo_p2p_write_pkt(gint source, struct yahoo_packet *pkt)
2260 { 2260 {
2269 } 2269 }
2270 2270
2271 /*exchange of initial p2pfilexfer packets, service type YAHOO_SERVICE_P2PFILEXFER*/ 2271 /*exchange of initial p2pfilexfer packets, service type YAHOO_SERVICE_P2PFILEXFER*/
2272 static void yahoo_p2p_process_p2pfilexfer(gpointer data, gint source, struct yahoo_packet *pkt) 2272 static void yahoo_p2p_process_p2pfilexfer(gpointer data, gint source, struct yahoo_packet *pkt)
2273 { 2273 {
2274 struct yahoo_p2p_data *user_data; 2274 struct yahoo_p2p_data *p2p_data;
2275 char *who = NULL; 2275 char *who = NULL;
2276 GSList *l = pkt->hash; 2276 GSList *l = pkt->hash;
2277 struct yahoo_packet *pkt_to_send; 2277 struct yahoo_packet *pkt_to_send;
2278 PurpleAccount *account; 2278 PurpleAccount *account;
2279 int val_13_to_send = 0; 2279 int val_13_to_send = 0;
2280 struct yahoo_data *yd; 2280 struct yahoo_data *yd;
2281 2281
2282 if(!(user_data = data)) 2282 if(!(p2p_data = data))
2283 return ; 2283 return ;
2284 2284
2285 yd = user_data->gc->proto_data; 2285 yd = p2p_data->gc->proto_data;
2286 2286
2287 /* lets see whats in the packet */ 2287 /* lets see whats in the packet */
2288 while (l) { 2288 while (l) {
2289 struct yahoo_pair *pair = l->data; 2289 struct yahoo_pair *pair = l->data;
2290 2290
2291 switch (pair->key) { 2291 switch (pair->key) {
2292 case 4: 2292 case 4:
2293 who = pair->value; 2293 who = pair->value;
2294 if(strncmp(who, user_data->host_username, strlen(user_data->host_username)) != 0) { 2294 if(strncmp(who, p2p_data->host_username, strlen(p2p_data->host_username)) != 0) {
2295 /* from whom are we receiving the packets ?? */ 2295 /* from whom are we receiving the packets ?? */
2296 purple_debug_warning("yahoo","p2p: received data from wrong user\n"); 2296 purple_debug_warning("yahoo","p2p: received data from wrong user\n");
2297 return; 2297 return;
2298 } 2298 }
2299 break; 2299 break;
2300 case 13: 2300 case 13:
2301 user_data->val_13 = strtol(pair->value, NULL, 10); /*Value should be 5-7*/ 2301 p2p_data->val_13 = strtol(pair->value, NULL, 10); /*Value should be 5-7*/
2302 break; 2302 break;
2303 /*case 5, 49 look laters, no use right now*/ 2303 /*case 5, 49 look laters, no use right now*/
2304 } 2304 }
2305 l = l->next; 2305 l = l->next;
2306 } 2306 }
2307 2307
2308 account = purple_connection_get_account(user_data->gc); 2308 account = purple_connection_get_account(p2p_data->gc);
2309 2309
2310 /*key_13: sort of a counter. 2310 /*key_13: sort of a counter.
2311 *WHEN WE ARE CLIENT: yahoo server sends val_13 = 0, we send to peer val_13 = 1, receive back val_13 = 5, 2311 *WHEN WE ARE CLIENT: yahoo server sends val_13 = 0, we send to peer val_13 = 1, receive back val_13 = 5,
2312 *we send val_13=6, receive val_13=7, we send val_13=7, HALT. Keep sending val_13 = 7 as keep alive. 2312 *we send val_13=6, receive val_13=7, we send val_13=7, HALT. Keep sending val_13 = 7 as keep alive.
2313 *WHEN WE ARE SERVER: we send val_13 = 0 to yahoo server, peer sends us val_13 = 1, we send val_13 = 5, 2313 *WHEN WE ARE SERVER: we send val_13 = 0 to yahoo server, peer sends us val_13 = 1, we send val_13 = 5,
2314 *receive val_13 = 6, send val_13 = 7, receive val_13 = 7. HALT. Keep sending val_13 = 7 as keep alive.*/ 2314 *receive val_13 = 6, send val_13 = 7, receive val_13 = 7. HALT. Keep sending val_13 = 7 as keep alive.*/
2315 2315
2316 switch(user_data->val_13) { 2316 switch(p2p_data->val_13) {
2317 case 1 : val_13_to_send = 5; break; 2317 case 1 : val_13_to_send = 5; break;
2318 case 5 : val_13_to_send = 6; break; 2318 case 5 : val_13_to_send = 6; break;
2319 case 6 : val_13_to_send = 7; break; 2319 case 6 : val_13_to_send = 7; break;
2320 case 7 : val_13_to_send = 7; break; 2320 case 7 : val_13_to_send = 7; break;
2321 default: purple_debug_warning("yahoo","p2p:Unknown value for key 13\n"); 2321 default: purple_debug_warning("yahoo","p2p:Unknown value for key 13\n");
2324 2324
2325 /*Build the yahoo packet*/ 2325 /*Build the yahoo packet*/
2326 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, yd->session_id); 2326 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, yd->session_id);
2327 yahoo_packet_hash(pkt_to_send, "ssisi", 2327 yahoo_packet_hash(pkt_to_send, "ssisi",
2328 4, purple_normalize(account, purple_account_get_username(account)), 2328 4, purple_normalize(account, purple_account_get_username(account)),
2329 5, user_data->host_username, 2329 5, p2p_data->host_username,
2330 241, 0, /*Protocol identifier*/ 2330 241, 0, /*Protocol identifier*/
2331 49, "PEERTOPEER", 2331 49, "PEERTOPEER",
2332 13, val_13_to_send); 2332 13, val_13_to_send);
2333 2333
2334 /*build the raw packet and send it to the host*/ 2334 /*build the raw packet and send it to the host*/
2343 int len; 2343 int len;
2344 int pos = 0; 2344 int pos = 0;
2345 int pktlen; 2345 int pktlen;
2346 struct yahoo_packet *pkt; 2346 struct yahoo_packet *pkt;
2347 guchar *start = NULL; 2347 guchar *start = NULL;
2348 struct yahoo_p2p_data *user_data; 2348 struct yahoo_p2p_data *p2p_data;
2349 struct yahoo_data *yd; 2349 struct yahoo_data *yd;
2350 2350
2351 if(!(user_data = data)) 2351 if(!(p2p_data = data))
2352 return ; 2352 return ;
2353 yd = user_data->gc->proto_data; 2353 yd = p2p_data->gc->proto_data;
2354 2354
2355 len = read(source, buf, sizeof(buf)); 2355 len = read(source, buf, sizeof(buf));
2356 if ((len < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) 2356 if ((len < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK)))
2357 return ; /* No Worries*/ 2357 return ; /* No Worries*/
2358 else if (len <= 0) 2358 else if (len <= 0)
2359 { 2359 {
2360 purple_debug_warning("yahoo","p2p: Error in connection, or host disconnected\n"); 2360 purple_debug_warning("yahoo","p2p: Error in connection, or host disconnected\n");
2361 /*remove from p2p connection lists, also calls yahoo_p2p_disconnect_destroy_data*/ 2361 /*remove from p2p connection lists, also calls yahoo_p2p_disconnect_destroy_data*/
2362 g_hash_table_remove(yd->peers,user_data->host_username); 2362 g_hash_table_remove(yd->peers,p2p_data->host_username);
2363 return; 2363 return;
2364 } 2364 }
2365 2365
2366 if(len < YAHOO_PACKET_HDRLEN) 2366 if(len < YAHOO_PACKET_HDRLEN)
2367 return; 2367 return;
2399 switch(pkt->service) { 2399 switch(pkt->service) {
2400 case YAHOO_SERVICE_P2PFILEXFER: 2400 case YAHOO_SERVICE_P2PFILEXFER:
2401 yahoo_p2p_process_p2pfilexfer(data, source, pkt); 2401 yahoo_p2p_process_p2pfilexfer(data, source, pkt);
2402 break; 2402 break;
2403 case YAHOO_SERVICE_MESSAGE: 2403 case YAHOO_SERVICE_MESSAGE:
2404 yahoo_process_message(user_data->gc, pkt); 2404 yahoo_process_message(p2p_data->gc, pkt);
2405 break; 2405 break;
2406 case YAHOO_SERVICE_NOTIFY: 2406 case YAHOO_SERVICE_NOTIFY:
2407 yahoo_process_notify(user_data->gc, pkt); 2407 yahoo_process_notify(p2p_data->gc, pkt);
2408 break; 2408 break;
2409 default: 2409 default:
2410 purple_debug_warning("yahoo","p2p: p2p service %d Unhandled\n",pkt->service); 2410 purple_debug_warning("yahoo","p2p: p2p service %d Unhandled\n",pkt->service);
2411 } 2411 }
2412 2412
2414 } 2414 }
2415 2415
2416 static void yahoo_p2p_server_send_connected_cb(gpointer data, gint source, PurpleInputCondition cond) 2416 static void yahoo_p2p_server_send_connected_cb(gpointer data, gint source, PurpleInputCondition cond)
2417 { 2417 {
2418 int acceptfd; 2418 int acceptfd;
2419 struct yahoo_p2p_data *user_data; 2419 struct yahoo_p2p_data *p2p_data;
2420 YahooFriend *f; 2420 YahooFriend *f;
2421 struct yahoo_data *yd; 2421 struct yahoo_data *yd;
2422 2422
2423 if(!(user_data = data)) 2423 if(!(p2p_data = data))
2424 return ; 2424 return ;
2425 yd = user_data->gc->proto_data; 2425 yd = p2p_data->gc->proto_data;
2426 2426
2427 acceptfd = accept(source, NULL, 0); 2427 acceptfd = accept(source, NULL, 0);
2428 if(acceptfd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) 2428 if(acceptfd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
2429 return; 2429 return;
2430 else if(acceptfd == -1) { 2430 else if(acceptfd == -1) {
2436 /*remove watcher and close p2p server*/ 2436 /*remove watcher and close p2p server*/
2437 purple_input_remove(yd->yahoo_p2p_server_watcher); 2437 purple_input_remove(yd->yahoo_p2p_server_watcher);
2438 close(yd->yahoo_local_p2p_server_fd); 2438 close(yd->yahoo_local_p2p_server_fd);
2439 yd->yahoo_local_p2p_server_fd = -1; 2439 yd->yahoo_local_p2p_server_fd = -1;
2440 2440
2441 if( (f = yahoo_friend_find(user_data->gc, user_data->host_username)) ) { 2441 if( (f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username)) ) {
2442 /*To-Do: we should disconnect if not a friend*/ 2442 /*To-Do: we should disconnect if not a friend*/
2443 user_data->val_11 = f->val_11; 2443 p2p_data->val_11 = f->val_11;
2444 yahoo_friend_set_p2p_status(f, CONNECTED_AS_SERVER); 2444 yahoo_friend_set_p2p_status(f, CONNECTED_AS_SERVER);
2445 } 2445 }
2446 2446
2447 /*Add an Input Read event to the file descriptor*/ 2447 /*Add an Input Read event to the file descriptor*/
2448 user_data->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); 2448 p2p_data->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data);
2449 user_data->source = acceptfd; 2449 p2p_data->source = acceptfd;
2450 2450
2451 g_hash_table_insert(yd->peers, g_strdup(user_data->host_username), user_data); 2451 g_hash_table_insert(yd->peers, g_strdup(p2p_data->host_username), p2p_data);
2452 } 2452 }
2453 2453
2454 static void yahoo_p2p_server_listen_cb(int listenfd, gpointer data) 2454 static void yahoo_p2p_server_listen_cb(int listenfd, gpointer data)
2455 { 2455 {
2456 struct yahoo_p2p_data *user_data; 2456 struct yahoo_p2p_data *p2p_data;
2457 struct yahoo_data *yd; 2457 struct yahoo_data *yd;
2458 2458
2459 if(!(user_data = data)) 2459 if(!(p2p_data = data))
2460 return ; 2460 return ;
2461 2461
2462 if(listenfd == -1) { 2462 if(listenfd == -1) {
2463 purple_debug_warning("yahoo","p2p: error starting p2p server\n"); 2463 purple_debug_warning("yahoo","p2p: error starting p2p server\n");
2464 yahoo_p2p_disconnect_destroy_data(data); 2464 yahoo_p2p_disconnect_destroy_data(data);
2465 return; 2465 return;
2466 } 2466 }
2467 2467
2468 yd = user_data->gc->proto_data; 2468 yd = p2p_data->gc->proto_data;
2469 2469
2470 /*Add an Input Read event to the file descriptor*/ 2470 /*Add an Input Read event to the file descriptor*/
2471 yd->yahoo_local_p2p_server_fd = listenfd; 2471 yd->yahoo_local_p2p_server_fd = listenfd;
2472 yd->yahoo_p2p_server_watcher = purple_input_add(listenfd, PURPLE_INPUT_READ, yahoo_p2p_server_send_connected_cb,data); 2472 yd->yahoo_p2p_server_watcher = purple_input_add(listenfd, PURPLE_INPUT_READ, yahoo_p2p_server_send_connected_cb,data);
2473 } 2473 }
2482 gchar *base64_ip = NULL; 2482 gchar *base64_ip = NULL;
2483 YahooFriend *f; 2483 YahooFriend *f;
2484 struct yahoo_packet *pkt; 2484 struct yahoo_packet *pkt;
2485 PurpleAccount *account; 2485 PurpleAccount *account;
2486 struct yahoo_data *yd = gc->proto_data; 2486 struct yahoo_data *yd = gc->proto_data;
2487 struct yahoo_p2p_data *user_data = g_new0(struct yahoo_p2p_data, 1); 2487 struct yahoo_p2p_data *p2p_data = g_new0(struct yahoo_p2p_data, 1);
2488 2488
2489 public_ip = purple_network_get_public_ip(); 2489 public_ip = purple_network_get_public_ip();
2490 if( (sscanf(public_ip, "%u.%u.%u.%u", &temp[0], &temp[1], &temp[2], &temp[3])) !=4 ) 2490 if( (sscanf(public_ip, "%u.%u.%u.%u", &temp[0], &temp[1], &temp[2], &temp[3])) !=4 )
2491 return ; 2491 return ;
2492 2492
2513 49, "PEERTOPEER"); 2513 49, "PEERTOPEER");
2514 yahoo_packet_send_and_free(pkt, yd); 2514 yahoo_packet_send_and_free(pkt, yd);
2515 2515
2516 f->p2p_packet_sent = 1; /*set p2p_packet_sent to sent*/ 2516 f->p2p_packet_sent = 1; /*set p2p_packet_sent to sent*/
2517 2517
2518 user_data->gc = gc; 2518 p2p_data->gc = gc;
2519 user_data->host_ip = NULL; 2519 p2p_data->host_ip = NULL;
2520 user_data->host_username = (char *)g_malloc(strlen(who)); 2520 p2p_data->host_username = (char *)g_malloc(strlen(who));
2521 strcpy(user_data->host_username, who); 2521 strcpy(p2p_data->host_username, who);
2522 user_data->val_13 = val_13; 2522 p2p_data->val_13 = val_13;
2523 user_data->connection_type = 1; /*0:we are server*/ 2523 p2p_data->connection_type = 1; /*0:we are server*/
2524 2524
2525 purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, user_data); 2525 purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
2526 2526
2527 g_free(base64_ip); 2527 g_free(base64_ip);
2528 } 2528 }
2529 2529
2530 /*function called when connection to p2p host is setup*/ 2530 /*function called when connection to p2p host is setup*/
2531 static void yahoo_p2p_init_cb(gpointer data, gint source, const gchar *error_message) 2531 static void yahoo_p2p_init_cb(gpointer data, gint source, const gchar *error_message)
2532 { 2532 {
2533 struct yahoo_p2p_data *user_data; 2533 struct yahoo_p2p_data *p2p_data;
2534 struct yahoo_packet *pkt_to_send; 2534 struct yahoo_packet *pkt_to_send;
2535 PurpleAccount *account; 2535 PurpleAccount *account;
2536 YahooFriend *f; 2536 YahooFriend *f;
2537 struct yahoo_data *yd; 2537 struct yahoo_data *yd;
2538 2538
2539 if(!(user_data = data)) 2539 if(!(p2p_data = data))
2540 return ; 2540 return ;
2541 yd = user_data->gc->proto_data; 2541 yd = p2p_data->gc->proto_data;
2542 2542
2543 if(error_message != NULL) { 2543 if(error_message != NULL) {
2544 purple_debug_warning("yahoo","p2p: %s\n",error_message); 2544 purple_debug_warning("yahoo","p2p: %s\n",error_message);
2545 yahoo_send_p2p_pkt(user_data->gc, user_data->host_username, 2);/*send p2p init packet with val_13=2*/ 2545 yahoo_send_p2p_pkt(p2p_data->gc, p2p_data->host_username, 2);/*send p2p init packet with val_13=2*/
2546 2546
2547 yahoo_p2p_disconnect_destroy_data(user_data); 2547 yahoo_p2p_disconnect_destroy_data(p2p_data);
2548 return; 2548 return;
2549 } 2549 }
2550 2550
2551 /*Add an Input Read event to the file descriptor*/ 2551 /*Add an Input Read event to the file descriptor*/
2552 user_data->input_event = purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); 2552 p2p_data->input_event = purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data);
2553 user_data->source = source; 2553 p2p_data->source = source;
2554 2554
2555 g_hash_table_insert(yd->peers, g_strdup(user_data->host_username), user_data); 2555 g_hash_table_insert(yd->peers, g_strdup(p2p_data->host_username), p2p_data);
2556 2556
2557 /*If the peer is a friend, set him connected*/ 2557 /*If the peer is a friend, set him connected*/
2558 f = yahoo_friend_find(user_data->gc, user_data->host_username); 2558 f = yahoo_friend_find(p2p_data->gc, p2p_data->host_username);
2559 if (f) 2559 if (f)
2560 yahoo_friend_set_p2p_status(f, CONNECTED_AS_CLIENT); 2560 yahoo_friend_set_p2p_status(f, CONNECTED_AS_CLIENT);
2561 2561
2562 account = purple_connection_get_account(user_data->gc); 2562 account = purple_connection_get_account(p2p_data->gc);
2563 2563
2564 /*Build the yahoo packet*/ 2564 /*Build the yahoo packet*/
2565 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, yd->session_id); 2565 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, yd->session_id);
2566 yahoo_packet_hash(pkt_to_send, "ssisi", 2566 yahoo_packet_hash(pkt_to_send, "ssisi",
2567 4, purple_normalize(account, purple_account_get_username(account)), 2567 4, purple_normalize(account, purple_account_get_username(account)),
2568 5, user_data->host_username, 2568 5, p2p_data->host_username,
2569 241, 0, /*Protocol identifier*/ 2569 241, 0, /*Protocol identifier*/
2570 49, "PEERTOPEER", 2570 49, "PEERTOPEER",
2571 13, 1); /*we receive key13= 0 or 2, we send key13=1*/ 2571 13, 1); /*we receive key13= 0 or 2, we send key13=1*/
2572 2572
2573 yahoo_p2p_write_pkt(source, pkt_to_send); /*build raw packet and send*/ 2573 yahoo_p2p_write_pkt(source, pkt_to_send); /*build raw packet and send*/
2629 if (base64) { 2629 if (base64) {
2630 guint32 ip; 2630 guint32 ip;
2631 char *tmp2; 2631 char *tmp2;
2632 YahooFriend *f; 2632 YahooFriend *f;
2633 char *host_ip; 2633 char *host_ip;
2634 struct yahoo_p2p_data *user_data = g_new0(struct yahoo_p2p_data, 1); 2634 struct yahoo_p2p_data *p2p_data = g_new0(struct yahoo_p2p_data, 1);
2635 2635
2636 decoded = purple_base64_decode(base64, &len); 2636 decoded = purple_base64_decode(base64, &len);
2637 if (len) { 2637 if (len) {
2638 char *tmp = purple_str_binary_to_ascii(decoded, len); 2638 char *tmp = purple_str_binary_to_ascii(decoded, len);
2639 purple_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, tmp); 2639 purple_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, tmp);
2658 return; 2658 return;
2659 else 2659 else
2660 val_11 = f->val_11; 2660 val_11 = f->val_11;
2661 } 2661 }
2662 2662
2663 user_data->host_username = (char *)g_malloc(strlen(who)); 2663 p2p_data->host_username = (char *)g_malloc(strlen(who));
2664 strcpy(user_data->host_username, who); 2664 strcpy(p2p_data->host_username, who);
2665 user_data->val_13 = val_13; 2665 p2p_data->val_13 = val_13;
2666 user_data->val_11 = val_11; 2666 p2p_data->val_11 = val_11;
2667 user_data->host_ip = host_ip; 2667 p2p_data->host_ip = host_ip;
2668 user_data->gc = gc; 2668 p2p_data->gc = gc;
2669 user_data->connection_type = 0; /*0:peer is server*/ 2669 p2p_data->connection_type = 0; /*0:peer is server*/
2670 2670
2671 /*connect to host*/ 2671 /*connect to host*/
2672 if((purple_proxy_connect(NULL, account, host_ip, YAHOO_PAGER_PORT_P2P, yahoo_p2p_init_cb, user_data))==NULL) { 2672 if((purple_proxy_connect(NULL, account, host_ip, YAHOO_PAGER_PORT_P2P, yahoo_p2p_init_cb, p2p_data))==NULL) {
2673 yahoo_p2p_disconnect_destroy_data(user_data); 2673 yahoo_p2p_disconnect_destroy_data(p2p_data);
2674 purple_debug_info("yahoo","p2p: Connection to %s failed\n", host_ip); 2674 purple_debug_info("yahoo","p2p: Connection to %s failed\n", host_ip);
2675 } 2675 }
2676 } 2676 }
2677 } 2677 }
2678 2678
4015 char *msg2; 4015 char *msg2;
4016 gboolean utf8 = TRUE; 4016 gboolean utf8 = TRUE;
4017 PurpleWhiteboard *wb; 4017 PurpleWhiteboard *wb;
4018 int ret = 1; 4018 int ret = 1;
4019 YahooFriend *f = NULL; 4019 YahooFriend *f = NULL;
4020 struct yahoo_p2p_data *user_data; 4020 struct yahoo_p2p_data *p2p_data;
4021 4021
4022 msg2 = yahoo_string_encode(gc, msg, &utf8); 4022 msg2 = yahoo_string_encode(gc, msg, &utf8);
4023 4023
4024 yahoo_packet_hash(pkt, "ss", 1, purple_connection_get_display_name(gc), 5, who); 4024 yahoo_packet_hash(pkt, "ss", 1, purple_connection_get_display_name(gc), 5, who);
4025 if ((f = yahoo_friend_find(gc, who)) && f->protocol) 4025 if ((f = yahoo_friend_find(gc, who)) && f->protocol)
4062 yahoo_packet_hash_str(pkt, 206, "2"); 4062 yahoo_packet_hash_str(pkt, 206, "2");
4063 4063
4064 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */ 4064 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */
4065 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000) { 4065 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000) {
4066 /*if p2p link exists, send through it. To-do: key 15, time value to be sent in case of p2p*/ 4066 /*if p2p link exists, send through it. To-do: key 15, time value to be sent in case of p2p*/
4067 if( (user_data = g_hash_table_lookup(yd->peers, who)) ) { 4067 if( (p2p_data = g_hash_table_lookup(yd->peers, who)) ) {
4068 yahoo_packet_hash_int(pkt, 11, user_data->val_11); 4068 yahoo_packet_hash_int(pkt, 11, p2p_data->val_11);
4069 yahoo_p2p_write_pkt(user_data->source, pkt); 4069 yahoo_p2p_write_pkt(p2p_data->source, pkt);
4070 } 4070 }
4071 else { 4071 else {
4072 yahoo_packet_send(pkt, yd); 4072 yahoo_packet_send(pkt, yd);
4073 yahoo_send_p2p_pkt(gc, who, 0); /*send p2p packet, with val_13=0*/ 4073 yahoo_send_p2p_pkt(gc, who, 0); /*send p2p packet, with val_13=0*/
4074 } 4074 }
4085 } 4085 }
4086 4086
4087 static unsigned int yahoo_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) 4087 static unsigned int yahoo_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state)
4088 { 4088 {
4089 struct yahoo_data *yd = gc->proto_data; 4089 struct yahoo_data *yd = gc->proto_data;
4090 struct yahoo_p2p_data *user_data; 4090 struct yahoo_p2p_data *p2p_data;
4091 4091
4092 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0); 4092 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_NOTIFY, YAHOO_STATUS_TYPING, 0);
4093 4093
4094 /*check to see if p2p link exists, send through it*/ 4094 /*check to see if p2p link exists, send through it*/
4095 if( (user_data = g_hash_table_lookup(yd->peers, who)) ) { 4095 if( (p2p_data = g_hash_table_lookup(yd->peers, who)) ) {
4096 yahoo_packet_hash(pkt, "sssssis", 49, "TYPING", 1, purple_connection_get_display_name(gc), 4096 yahoo_packet_hash(pkt, "sssssis", 49, "TYPING", 1, purple_connection_get_display_name(gc),
4097 14, " ", 13, state == PURPLE_TYPING ? "1" : "0", 4097 14, " ", 13, state == PURPLE_TYPING ? "1" : "0",
4098 5, who, 11, user_data->val_11, 1002, "1"); /*To-do: key 15 to be sent in case of p2p*/ 4098 5, who, 11, p2p_data->val_11, 1002, "1"); /*To-do: key 15 to be sent in case of p2p*/
4099 yahoo_p2p_write_pkt(user_data->source, pkt); 4099 yahoo_p2p_write_pkt(p2p_data->source, pkt);
4100 yahoo_packet_free(pkt); 4100 yahoo_packet_free(pkt);
4101 } 4101 }
4102 else { /*send through yahoo server*/ 4102 else { /*send through yahoo server*/
4103 yahoo_packet_hash(pkt, "ssssss", 49, "TYPING", 1, purple_connection_get_display_name(gc), 4103 yahoo_packet_hash(pkt, "ssssss", 49, "TYPING", 1, purple_connection_get_display_name(gc),
4104 14, " ", 13, state == PURPLE_TYPING ? "1" : "0", 4104 14, " ", 13, state == PURPLE_TYPING ? "1" : "0",