comparison libgaim/protocols/oscar/peer.c @ 14267:645598a4ec04

[gaim-migrate @ 16949] Change gaim_network_listen() and gaim_network_listen_range() to be cancelable. This doesn't actually help anything yet, since the gaim_upnp_functions() are not yet cancelable. But the framework is there, and the PRPLs shouldn't need any additional changes. Still to go: gaim_upnp_everything() gaim_url_fetch() gaim_srv_resolve() Let me know if there are others committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 21 Aug 2006 07:47:03 +0000
parents baff095b146c
children 80b05108652c
comparison
equal deleted inserted replaced
14266:63ef6342db05 14267:645598a4ec04
143 { 143 {
144 gaim_proxy_connect_cancel(conn->connect_data); 144 gaim_proxy_connect_cancel(conn->connect_data);
145 conn->connect_data = NULL; 145 conn->connect_data = NULL;
146 } 146 }
147 147
148 if (conn->listen_data != NULL)
149 {
150 gaim_network_listen_cancel(conn->listen_data);
151 conn->listen_data = NULL;
152 }
153
148 if (conn->connect_timeout_timer != 0) 154 if (conn->connect_timeout_timer != 0)
149 { 155 {
150 gaim_timeout_remove(conn->connect_timeout_timer); 156 gaim_timeout_remove(conn->connect_timeout_timer);
151 conn->connect_timeout_timer = 0; 157 conn->connect_timeout_timer = 0;
152 } 158 }
559 * user an ICBM and ask them to connect to us. 565 * user an ICBM and ask them to connect to us.
560 */ 566 */
561 static void 567 static void
562 peer_connection_establish_listener_cb(int listenerfd, gpointer data) 568 peer_connection_establish_listener_cb(int listenerfd, gpointer data)
563 { 569 {
564 NewPeerConnectionData *new_conn_data;
565 PeerConnection *conn; 570 PeerConnection *conn;
566 OscarData *od; 571 OscarData *od;
567 GaimConnection *gc; 572 GaimConnection *gc;
568 GaimAccount *account; 573 GaimAccount *account;
569 GaimConversation *conv; 574 GaimConversation *conv;
570 char *tmp; 575 char *tmp;
571 FlapConnection *bos_conn; 576 FlapConnection *bos_conn;
572 const char *listener_ip; 577 const char *listener_ip;
573 unsigned short listener_port; 578 unsigned short listener_port;
574 579
575 new_conn_data = data; 580 conn = data;
576 gc = new_conn_data->gc; 581 conn->listen_data = NULL;
577 conn = new_conn_data->conn;
578 g_free(new_conn_data);
579
580 if (!GAIM_CONNECTION_IS_VALID(gc))
581 {
582 if (listenerfd != -1)
583 close(listenerfd);
584 return;
585 }
586 582
587 if (listenerfd == -1) 583 if (listenerfd == -1)
588 { 584 {
589 /* Could not open listener socket */ 585 /* Could not open listener socket */
590 peer_connection_trynext(conn); 586 peer_connection_trynext(conn);
591 return; 587 return;
592 } 588 }
593 589
594 od = conn->od; 590 od = conn->od;
591 gc = od->gc;
595 account = gaim_connection_get_account(gc); 592 account = gaim_connection_get_account(gc);
596 conn->listenerfd = listenerfd; 593 conn->listenerfd = listenerfd;
597 594
598 /* Send the "please connect to me!" ICBM */ 595 /* Send the "please connect to me!" ICBM */
599 bos_conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM); 596 bos_conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM);
755 * our verifiedip and our clientip). 752 * our verifiedip and our clientip).
756 */ 753 */
757 if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_INCOMING) && 754 if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_INCOMING) &&
758 (!conn->use_proxy)) 755 (!conn->use_proxy))
759 { 756 {
760 NewPeerConnectionData *new_conn_data;
761
762 new_conn_data = g_new(NewPeerConnectionData, 1);
763 new_conn_data->gc = conn->od->gc;
764 new_conn_data->conn = conn;
765
766 conn->flags |= PEER_CONNECTION_FLAG_TRIED_INCOMING; 757 conn->flags |= PEER_CONNECTION_FLAG_TRIED_INCOMING;
767 758
768 /* 759 /*
769 * Remote user is connecting to us, so we'll need to verify 760 * Remote user is connecting to us, so we'll need to verify
770 * that the user who connected is our friend. 761 * that the user who connected is our friend.
771 */ 762 */
772 conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING; 763 conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING;
773 764
774 if (gaim_network_listen_range(5190, 5290, SOCK_STREAM, 765 conn->listen_data = gaim_network_listen_range(5190, 5290, SOCK_STREAM,
775 peer_connection_establish_listener_cb, new_conn_data)) 766 peer_connection_establish_listener_cb, conn);
767 if (conn->listen_data != NULL)
776 { 768 {
777 /* Opening listener socket... */ 769 /* Opening listener socket... */
778 return; 770 return;
779 } 771 }
780
781 g_free(new_conn_data);
782 } 772 }
783 773
784 /* 774 /*
785 * 4. Attempt to have both users connect to an intermediate proxy 775 * 4. Attempt to have both users connect to an intermediate proxy
786 * server. 776 * server.