comparison src/protocols/jabber/si.c @ 12909:8e3b85fe4a55

[gaim-migrate @ 15262] Make UPnP truly asynchronous. There are probably still a couple socket calls that should be made nonblocking, but I wanted to commit this before it became even bigger. This contains a number of probable leak fixes in the upnp stuff. The UPnP stuff has been updated to use gaim_url_fetch_request() instead of the specific implementation. To make this all work, I had to make gaim_network_listen() and gaim_network_listen_range() also asynchronous - seems to work just fine apart from the UPnP calls seeming to take longer than they should (I'm planning to look into this). I also triggered a STUN and UPnP discovery on startup so that we hopefully have the information when we need it. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 17 Jan 2006 05:48:51 +0000
parents d5b8f4dc1622
children d9c53c5f5912
comparison
equal deleted inserted replaced
12908:4f2b96f23700 12909:8e3b85fe4a55
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
412 413
413 xfer->watcher = gaim_input_add(acceptfd, GAIM_INPUT_READ, 414 xfer->watcher = gaim_input_add(acceptfd, GAIM_INPUT_READ,
414 jabber_si_xfer_bytestreams_send_read_cb, xfer); 415 jabber_si_xfer_bytestreams_send_read_cb, xfer);
415 } 416 }
416 417
417
418 static void 418 static void
419 jabber_si_xfer_bytestreams_send_init(GaimXfer *xfer) 419 jabber_si_xfer_bytestreams_listen_cb(int sock, gpointer data)
420 { 420 {
421 JabberSIXfer *jsx = xfer->data; 421 GaimXfer *xfer = data;
422 JabberSIXfer *jsx;
422 JabberIq *iq; 423 JabberIq *iq;
423 xmlnode *query, *streamhost; 424 xmlnode *query, *streamhost;
424 char *jid, *port; 425 char *jid, *port;
425 int fd; 426
427 if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) {
428 gaim_xfer_unref(xfer);
429 return;
430 }
431
432 jsx = xfer->data;
433
434 gaim_xfer_unref(xfer);
435
436 if (sock < 0) {
437 gaim_xfer_cancel_local(xfer);
438 return;
439 }
426 440
427 iq = jabber_iq_new_query(jsx->js, JABBER_IQ_SET, 441 iq = jabber_iq_new_query(jsx->js, JABBER_IQ_SET,
428 "http://jabber.org/protocol/bytestreams"); 442 "http://jabber.org/protocol/bytestreams");
429 xmlnode_set_attrib(iq->node, "to", xfer->who); 443 xmlnode_set_attrib(iq->node, "to", xfer->who);
430 query = xmlnode_get_child(iq->node, "query"); 444 query = xmlnode_get_child(iq->node, "query");
431 445
432 xmlnode_set_attrib(query, "sid", jsx->stream_id); 446 xmlnode_set_attrib(query, "sid", jsx->stream_id);
433 447
434 streamhost = xmlnode_new_child(query, "streamhost"); 448 streamhost = xmlnode_new_child(query, "streamhost");
435 jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, jsx->js->user->domain, jsx->js->user->resource); 449 jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node,
450 jsx->js->user->domain, jsx->js->user->resource);
436 xmlnode_set_attrib(streamhost, "jid", jid); 451 xmlnode_set_attrib(streamhost, "jid", jid);
437 g_free(jid); 452 g_free(jid);
438 453
439 if((fd = gaim_network_listen_range(0, 0, SOCK_STREAM)) < 0) { 454 /* XXX: shouldn't we use the public IP or something? here */
440 /* XXX: couldn't open a port, we're fscked */ 455 xmlnode_set_attrib(streamhost, "host",
441 return; 456 gaim_network_get_my_ip(jsx->js->fd));
442 } 457 xfer->local_port = gaim_network_get_port_from_fd(sock);
443
444 xmlnode_set_attrib(streamhost, "host", gaim_network_get_my_ip(jsx->js->fd));
445 xfer->local_port = gaim_network_get_port_from_fd(fd);
446 port = g_strdup_printf("%hu", xfer->local_port); 458 port = g_strdup_printf("%hu", xfer->local_port);
447 xmlnode_set_attrib(streamhost, "port", port); 459 xmlnode_set_attrib(streamhost, "port", port);
448 g_free(port); 460 g_free(port);
449 461
450 xfer->watcher = gaim_input_add(fd, GAIM_INPUT_READ, 462 xfer->watcher = gaim_input_add(sock, GAIM_INPUT_READ,
451 jabber_si_xfer_bytestreams_send_connected_cb, xfer); 463 jabber_si_xfer_bytestreams_send_connected_cb, xfer);
452 464
453 /* XXX: insert proxies here */ 465 /* XXX: insert proxies here */
454 466
455 /* XXX: callback to find out which streamhost they used, or see if they 467 /* XXX: callback to find out which streamhost they used, or see if they
456 * screwed it up */ 468 * screwed it up */
457 jabber_iq_send(iq); 469 jabber_iq_send(iq);
470
471 }
472
473 static void
474 jabber_si_xfer_bytestreams_send_init(GaimXfer *xfer)
475 {
476 gaim_xfer_ref(xfer);
477
478 if(!gaim_network_listen_range(0, 0, SOCK_STREAM,
479 jabber_si_xfer_bytestreams_listen_cb, xfer)) {
480 gaim_xfer_unref(xfer);
481 /* XXX: couldn't open a port, we're fscked */
482 gaim_xfer_cancel_local(xfer);
483 return;
484 }
485
458 } 486 }
459 487
460 static void jabber_si_xfer_send_method_cb(JabberStream *js, xmlnode *packet, 488 static void jabber_si_xfer_send_method_cb(JabberStream *js, xmlnode *packet,
461 gpointer data) 489 gpointer data)
462 { 490 {