Changeset dc0ba9c for protocols/jabber
- Timestamp:
- 2007-12-18T02:07:59Z (17 years ago)
- Branches:
- master
- Children:
- eded1f7
- Parents:
- 8076ec0
- Location:
- protocols/jabber
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
r8076ec0 rdc0ba9c 81 81 xt_add_child( reply, xt_new_node( "tz", buf, NULL ) ); 82 82 } 83 else if( strcmp( s, XMLNS_DISCO VER) == 0 )83 else if( strcmp( s, XMLNS_DISCO_INFO ) == 0 ) 84 84 { 85 85 const char *features[] = { XMLNS_VERSION, … … 565 565 return st; 566 566 } 567 568 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); 569 570 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid ) 571 { 572 struct xt_node *node, *query; 573 struct jabber_buddy *bud; 574 575 if( ( bud = jabber_buddy_by_jid( ic, bare_jid , 0 ) ) == NULL ) 576 { 577 /* Who cares about the unknown... */ 578 imcb_log( ic, "Couldnt find the man: %s", bare_jid); 579 return 0; 580 } 581 582 if( bud->features ) /* been here already */ 583 return XT_HANDLED; 584 585 node = xt_new_node( "query", NULL, NULL ); 586 xt_add_attr( node, "xmlns", XMLNS_DISCO_INFO ); 587 588 if( !( query = jabber_make_packet( "iq", "get", bare_jid, node ) ) ) 589 { 590 imcb_log( ic, "WARNING: Couldn't generate feature query" ); 591 xt_free_node( node ); 592 } 593 594 jabber_cache_add( ic, query, jabber_iq_parse_features ); 595 596 return jabber_write_packet( ic, query ); 597 } 598 599 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ) 600 { 601 struct xt_node *c; 602 struct jabber_buddy *bud; 603 char *feature; 604 605 if( !( c = xt_find_node( node->children, "query" ) ) || 606 !( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) ) 607 { 608 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" ); 609 return XT_HANDLED; 610 } 611 if( ( bud = jabber_buddy_by_jid( ic, xt_find_attr( node, "from") , 0 ) ) == NULL ) 612 { 613 /* Who cares about the unknown... */ 614 imcb_log( ic, "Couldnt find the man: %s", xt_find_attr( node, "from")); 615 return 0; 616 } 617 618 c = c->children; 619 while( ( c = xt_find_node( c, "feature" ) ) ) { 620 feature = xt_find_attr( c, "var" ); 621 bud->features = g_slist_append(bud->features, g_strdup(feature) ); 622 c = c->next; 623 } 624 625 return XT_HANDLED; 626 } 627 628 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); 629 630 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns ) 631 { 632 struct xt_node *node, *query; 633 struct jabber_data *jd = ic->proto_data; 634 635 node = xt_new_node( "query", NULL, NULL ); 636 xt_add_attr( node, "xmlns", xmlns ); 637 638 if( !( query = jabber_make_packet( "iq", "get", jid, node ) ) ) 639 { 640 imcb_log( ic, "WARNING: Couldn't generate server query" ); 641 xt_free_node( node ); 642 } 643 644 jd->have_streamhosts--; 645 jabber_cache_add( ic, query, jabber_iq_parse_server_features ); 646 647 return jabber_write_packet( ic, query ); 648 } 649 650 /* 651 * Query the server for "items", query each "item" for identities, query each "item" that's a proxy for it's bytestream info 652 */ 653 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ) 654 { 655 struct xt_node *c; 656 struct jabber_data *jd = ic->proto_data; 657 658 if( !( c = xt_find_node( node->children, "query" ) ) || 659 !xt_find_attr( node, "from" ) ) 660 { 661 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" ); 662 return XT_HANDLED; 663 } 664 665 jd->have_streamhosts++; 666 667 if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_ITEMS ) == 0 ) 668 { 669 char *item, *itemjid; 670 671 /* answer from server */ 672 673 c = c->children; 674 while( ( c = xt_find_node( c, "item" ) ) ) 675 { 676 item = xt_find_attr( c, "name" ); 677 itemjid = xt_find_attr( c, "jid" ); 678 679 jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO ); 680 681 c = c->next; 682 } 683 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) 684 { 685 char *category, *type; 686 687 /* answer from potential proxy */ 688 689 c = c->children; 690 while( ( c = xt_find_node( c, "identity" ) ) ) 691 { 692 category = xt_find_attr( c, "category" ); 693 type = xt_find_attr( c, "type" ); 694 695 if( type && ( strcmp( type, "bytestreams" ) == 0 ) && 696 category && ( strcmp( category, "proxy" ) == 0 ) ) 697 jabber_iq_query_server( ic, xt_find_attr( node, "from" ), XMLNS_BYTESTREAMS ); 698 699 c = c->next; 700 } 701 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_BYTESTREAMS ) == 0 ) 702 { 703 char *host, *jid; 704 int port; 705 706 /* answer from proxy */ 707 708 if( ( c = xt_find_node( c->children, "streamhost" ) ) && 709 ( host = xt_find_attr( c, "host" ) ) && 710 ( port = atoi( xt_find_attr( c, "port" ) ) ) && 711 ( jid = xt_find_attr( c, "jid" ) ) ) 712 { 713 jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 ); 714 sh->jid = g_strdup( jid ); 715 sh->host = g_strdup( host ); 716 sprintf( sh->port, "%u", port ); 717 718 imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port ); 719 jd->streamhosts = g_slist_append( jd->streamhosts, sh ); 720 } 721 } 722 723 if( jd->have_streamhosts == 0 ) 724 jd->have_streamhosts++; 725 return XT_HANDLED; 726 } -
protocols/jabber/jabber.h
r8076ec0 rdc0ba9c 57 57 } jabber_buddy_flags_t; 58 58 59 /* Stores a streamhost's(a.k.a. proxy) data */ 60 typedef struct 61 { 62 char *jid; 63 char *host; 64 char port[6]; 65 } jabber_streamhost_t; 66 59 67 struct jabber_data 60 68 { … … 83 91 84 92 GSList *filetransfers; 93 GSList *streamhosts; 94 int have_streamhosts; 85 95 }; 86 96 … … 111 121 struct jabber_away_state *away_state; 112 122 char *away_message; 123 GSList *features; 113 124 114 125 time_t last_act; … … 182 193 #define XMLNS_XDATA "jabber:x:data" /* XEP-0004 */ 183 194 #define XMLNS_CHATSTATES "http://jabber.org/protocol/chatstates" /* XEP-0085 */ 184 #define XMLNS_DISCOVER "http://jabber.org/protocol/disco#info" /* XEP-0030 */ 195 #define XMLNS_DISCO_INFO "http://jabber.org/protocol/disco#info" /* XEP-0030 */ 196 #define XMLNS_DISCO_ITEMS "http://jabber.org/protocol/disco#items" /* XEP-0030 */ 185 197 #define XMLNS_MUC "http://jabber.org/protocol/muc" /* XEP-0045 */ 186 198 #define XMLNS_MUC_USER "http://jabber.org/protocol/muc#user" /* XEP-0045 */ … … 199 211 int jabber_add_to_roster( struct im_connection *ic, char *handle, char *name ); 200 212 int jabber_remove_from_roster( struct im_connection *ic, char *handle ); 213 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid ); 214 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns ); 201 215 202 216 /* si.c */ -
protocols/jabber/s5bytestream.c
r8076ec0 rdc0ba9c 30 30 struct jabber_transfer *tf; 31 31 32 /* <query> element and <streamhost> elements */33 struct xt_node *qnode, *shnode;32 jabber_streamhost_t *sh; 33 GSList *streamhosts; 34 34 35 35 enum … … 74 74 gboolean jabber_bs_abort( struct bs_transfer *bt, char *format, ... ); 75 75 void jabber_bs_canceled( file_transfer_t *ft , char *reason ); 76 void jabber_bs_free_transfer( file_transfer_t *ft );76 void jabber_bs_free_transfer( file_transfer_t *ft ); 77 77 gboolean jabber_bs_connect_timeout( gpointer data, gint fd, b_input_condition cond ); 78 78 gboolean jabber_bs_poll( struct bs_transfer *bt, int fd, short *revents ); … … 84 84 gboolean jabber_bs_recv_handshake( gpointer data, gint fd, b_input_condition cond ); 85 85 gboolean jabber_bs_recv_handshake_abort( struct bs_transfer *bt, char *error ); 86 int jabber_bs_recv_request( struct im_connection *ic, struct xt_node *node, struct xt_node *qnode );86 int jabber_bs_recv_request( struct im_connection *ic, struct xt_node *node, struct xt_node *qnode ); 87 87 88 88 gboolean jabber_bs_send_handshake_abort( struct bs_transfer *bt, char *error ); 89 gboolean jabber_bs_send_request( struct jabber_transfer *tf, char *host, char *port);89 gboolean jabber_bs_send_request( struct jabber_transfer *tf, GSList *streamhosts ); 90 90 gboolean jabber_bs_send_handshake( gpointer data, gint fd, b_input_condition cond ); 91 91 gboolean jabber_bs_send_listen( struct bs_transfer *bt, struct sockaddr_storage *saddr, char *host, char *port ); 92 static xt_status jabber_bs_send_handle_activate( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); 93 void jabber_bs_send_activate( struct bs_transfer *bt ); 92 94 93 95 /* … … 97 99 struct jabber_transfer *tf = ft->data; 98 100 struct bs_transfer *bt = tf->streamhandle; 101 jabber_streamhost_t *sh; 99 102 100 103 if ( tf->watch_in ) … … 105 108 106 109 g_free( bt->pseudoadr ); 107 xt_free_node( bt->qnode ); 110 111 while( bt->streamhosts ) 112 { 113 sh = bt->streamhosts->data; 114 bt->streamhosts = g_slist_remove( bt->streamhosts, sh ); 115 g_free( sh->jid ); 116 g_free( sh->host ); 117 g_free( sh ); 118 } 119 108 120 g_free( bt ); 109 121 … … 111 123 } 112 124 125 /* 126 * Checks if buflen data is available on the socket and 127 * writes it to buffer if that's the case. 128 */ 113 129 gboolean jabber_bs_peek( struct bs_transfer *bt, void *buffer, int buflen ) 114 130 { … … 147 163 } 148 164 165 /* 166 * Polls the socket, checks for errors and removes a connect timer 167 * if there is one. 168 */ 149 169 gboolean jabber_bs_poll( struct bs_transfer *bt, int fd, short *revents ) 150 170 { … … 181 201 } 182 202 203 /* 204 * Used for receive and send path. 205 */ 183 206 gboolean jabber_bs_abort( struct bs_transfer *bt, char *format, ... ) 184 207 { … … 191 214 va_end( params ); 192 215 if( bt->tf->ft->sending ) 216 return jabber_bs_send_handshake_abort( bt, error ); 217 else 193 218 return jabber_bs_recv_handshake_abort( bt, error ); 194 else195 return jabber_bs_send_handshake_abort( bt, error );196 219 } 197 220 … … 214 237 GSList *tflist; 215 238 struct bs_transfer *bt; 239 GSList *shlist=NULL; 240 struct xt_node *shnode; 216 241 217 242 sha1_state_t sha; … … 233 258 { 234 259 imcb_log( ic, "WARNING: Received SI Request for unsupported bytestream mode %s", xt_find_attr( qnode, "mode" ) ); 260 return XT_HANDLED; 261 } 262 263 shnode = qnode->children; 264 while( ( shnode = xt_find_node( shnode, "streamhost" ) ) ) 265 { 266 char *jid, *host; 267 int port; 268 if( ( jid = xt_find_attr( shnode, "jid" ) ) && 269 ( host = xt_find_attr( shnode, "host" ) ) && 270 ( ( port = atoi( xt_find_attr( shnode, "port" ) ) ) ) ) 271 { 272 jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 ); 273 sh->jid = g_strdup(jid); 274 sh->host = g_strdup(host); 275 sprintf( sh->port, "%u", port ); 276 shlist = g_slist_append( shlist, sh ); 277 } 278 shnode = shnode->next; 279 } 280 281 if( !shlist ) 282 { 283 imcb_log( ic, "WARNING: Received incomplete SI bytestream request, no parseable streamhost entries"); 235 284 return XT_HANDLED; 236 285 } … … 274 323 bt = g_new0( struct bs_transfer, 1 ); 275 324 bt->tf = tf; 276 bt-> qnode = xt_dup( qnode );277 bt->sh node = bt->qnode->children;325 bt->streamhosts = shlist; 326 bt->sh = shlist->data; 278 327 bt->phase = BS_PHASE_CONNECT; 279 328 bt->pseudoadr = g_strdup( hash_hex ); … … 285 334 return XT_HANDLED; 286 335 } 336 287 337 /* 288 338 * This is what a protocol handshake can look like in cooperative multitasking :) … … 305 355 case BS_PHASE_CONNECT: 306 356 { 307 struct xt_node *c;308 char *host, *port;309 357 struct addrinfo hints, *rp; 310 358 311 if( ( c = bt->shnode = xt_find_node( bt->shnode, "streamhost" ) ) && 312 ( port = xt_find_attr( c, "port" ) ) && 313 ( host = xt_find_attr( c, "host" ) ) && 314 xt_find_attr( c, "jid" ) ) 315 { 316 memset( &hints, 0, sizeof( struct addrinfo ) ); 317 hints.ai_socktype = SOCK_STREAM; 318 319 if ( getaddrinfo( host, port, &hints, &rp ) != 0 ) 320 return jabber_bs_abort( bt, "getaddrinfo() failed: %s", strerror( errno ) ); 321 322 ASSERTSOCKOP( bt->tf->fd = fd = socket( rp->ai_family, rp->ai_socktype, 0 ), "Opening socket" ); 323 324 sock_make_nonblocking( fd ); 325 326 imcb_log( bt->tf->ic, "File %s: Connecting to streamhost %s:%s", bt->tf->ft->file_name, host, port ); 327 328 if( ( connect( fd, rp->ai_addr, rp->ai_addrlen ) == -1 ) && 329 ( errno != EINPROGRESS ) ) 330 return jabber_bs_abort( bt , "connect() failed: %s", strerror( errno ) ); 331 332 freeaddrinfo( rp ); 333 334 bt->phase = BS_PHASE_CONNECTED; 335 336 bt->tf->watch_out = b_input_add( fd, GAIM_INPUT_WRITE, jabber_bs_recv_handshake, bt ); 337 338 /* since it takes forever(3mins?) till connect() fails on itself we schedule a timeout */ 339 bt->connect_timeout = b_timeout_add( JABBER_BS_CONTIMEOUT * 1000, jabber_bs_connect_timeout, bt ); 340 341 bt->tf->watch_in = 0; 342 return FALSE; 343 } else 344 return jabber_bs_abort( bt, c ? "incomplete streamhost entry: host=%s port=%s jid=%s" : NULL, 345 host, port, xt_find_attr( c, "jid" ) ); 359 memset( &hints, 0, sizeof( struct addrinfo ) ); 360 hints.ai_socktype = SOCK_STREAM; 361 362 if ( getaddrinfo( bt->sh->host, bt->sh->port, &hints, &rp ) != 0 ) 363 return jabber_bs_abort( bt, "getaddrinfo() failed: %s", strerror( errno ) ); 364 365 ASSERTSOCKOP( bt->tf->fd = fd = socket( rp->ai_family, rp->ai_socktype, 0 ), "Opening socket" ); 366 367 sock_make_nonblocking( fd ); 368 369 imcb_log( bt->tf->ic, "File %s: Connecting to streamhost %s:%s", bt->tf->ft->file_name, bt->sh->host, bt->sh->port ); 370 371 if( ( connect( fd, rp->ai_addr, rp->ai_addrlen ) == -1 ) && 372 ( errno != EINPROGRESS ) ) 373 return jabber_bs_abort( bt , "connect() failed: %s", strerror( errno ) ); 374 375 freeaddrinfo( rp ); 376 377 bt->phase = BS_PHASE_CONNECTED; 378 379 bt->tf->watch_out = b_input_add( fd, GAIM_INPUT_WRITE, jabber_bs_recv_handshake, bt ); 380 381 /* since it takes forever(3mins?) till connect() fails on itself we schedule a timeout */ 382 bt->connect_timeout = b_timeout_add( JABBER_BS_CONTIMEOUT * 1000, jabber_bs_connect_timeout, bt ); 383 384 bt->tf->watch_in = 0; 385 return FALSE; 346 386 } 347 387 case BS_PHASE_CONNECTED: … … 422 462 socks5_reply.addrlen); 423 463 424 jabber_bs_recv_answer_request( bt ); 464 if( bt->tf->ft->sending ) 465 jabber_bs_send_activate( bt ); 466 else 467 jabber_bs_recv_answer_request( bt ); 425 468 426 469 return FALSE; … … 447 490 struct jabber_transfer *tf = bt->tf; 448 491 struct xt_node *reply, *iqnode; 449 450 if( bt->shnode ) 451 {452 imcb_log( tf->ic, "Transferring file %s: connection to streamhost %s:%s failed (%s)",453 tf->ft->file_name,454 xt_find_attr( bt->shnode, "host" ),455 xt_find_attr( bt->shnode, "port" ),456 error ); 457 458 /* Alright, this streamhost failed, let's try the next... */459 bt->phase = BS_PHASE_CONNECT;460 bt->shnode = bt->shnode->next;461 462 /* the if is not neccessary but saves us one recursion */463 if( bt->shnode )464 return jabber_bs_recv_handshake( bt, 0, 0 );465 } 492 GSList *shlist; 493 494 imcb_log( tf->ic, "Transferring file %s: connection to streamhost %s:%s failed (%s)", 495 tf->ft->file_name, 496 bt->sh->host, 497 bt->sh->port, 498 error ); 499 500 /* Alright, this streamhost failed, let's try the next... */ 501 bt->phase = BS_PHASE_CONNECT; 502 shlist = g_slist_find( bt->streamhosts, bt->sh ); 503 if( shlist && shlist->next ) 504 { 505 bt->sh = shlist->next->data; 506 return jabber_bs_recv_handshake( bt, 0, 0 ); 507 } 508 466 509 467 510 /* out of stream hosts */ … … 495 538 imcb_log( tf->ic, "File %s: established SOCKS5 connection to %s:%s", 496 539 tf->ft->file_name, 497 xt_find_attr( bt->shnode, "host" ),498 xt_find_attr( bt->shnode, "port" ));540 bt->sh->host, 541 bt->sh->port ); 499 542 500 543 tf->ft->data = tf; 501 tf->ft->started = time( NULL );502 544 tf->watch_in = b_input_add( tf->fd, GAIM_INPUT_READ, jabber_bs_recv_read, bt ); 503 545 tf->ft->write_request = jabber_bs_recv_write_request; 504 546 505 547 reply = xt_new_node( "streamhost-used", NULL, NULL ); 506 xt_add_attr( reply, "jid", xt_find_attr( bt->shnode, "jid" ));548 xt_add_attr( reply, "jid", bt->sh->jid ); 507 549 508 550 reply = xt_new_node( "query", NULL, reply ); … … 551 593 return jabber_bs_abort( bt, "Remote end closed connection" ); 552 594 595 if( tf->bytesread == 0 ) 596 tf->ft->started = time( NULL ); 597 553 598 tf->bytesread += ret; 554 599 … … 603 648 return jabber_bs_abort( bt, "BUG: write() called while watching " ); 604 649 650 /* TODO: catch broken pipe */ 605 651 ASSERTSOCKOP( ret = send( tf->fd, buffer, len, 0 ), "Sending" ); 652 653 if( tf->byteswritten == 0 ) 654 tf->ft->started = time( NULL ); 606 655 607 656 tf->byteswritten += ret; … … 665 714 tf->accepted = TRUE; 666 715 667 if( bt->phase == BS_PHASE_REPLY ) 668 { 669 /* handshake went through, let's start transferring */ 670 tf->ft->started = time( NULL ); 671 tf->ft->write_request( tf->ft ); 716 if( strcmp( jid, tf->ini_jid ) == 0 ) 717 { 718 /* we're streamhost and target */ 719 if( bt->phase == BS_PHASE_REPLY ) 720 { 721 /* handshake went through, let's start transferring */ 722 tf->ft->write_request( tf->ft ); 723 } 724 } else 725 { 726 /* using a proxy */ 727 GSList *shlist; 728 for( shlist = jd->streamhosts ; shlist ; shlist = g_slist_next( shlist ) ) 729 { 730 jabber_streamhost_t *sh = shlist->data; 731 if( strcmp( sh->jid, jid ) == 0 ) 732 { 733 bt->sh = sh; 734 jabber_bs_recv_handshake( bt, 0, 0 ); 735 return XT_HANDLED; 736 } 737 } 738 739 imcb_log( ic, "WARNING: Received SOCKS5 bytestream reply with unknown streamhost %s", jid ); 672 740 } 673 741 … … 675 743 } 676 744 745 /* 746 * Tell the proxy to activate the stream. Looks like this: 747 * 748 * <iq type=set> 749 * <query xmlns=bs sid=sid> 750 * <activate>tgt_jid</activate> 751 * </query> 752 * </iq> 753 */ 754 void jabber_bs_send_activate( struct bs_transfer *bt ) 755 { 756 struct xt_node *node; 757 758 node = xt_new_node( "activate", bt->tf->tgt_jid, NULL ); 759 node = xt_new_node( "query", NULL, node ); 760 xt_add_attr( node, "xmlns", XMLNS_BYTESTREAMS ); 761 xt_add_attr( node, "sid", bt->tf->sid ); 762 node = jabber_make_packet( "iq", "set", bt->sh->jid, node ); 763 764 jabber_cache_add( bt->tf->ic, node, jabber_bs_send_handle_activate ); 765 766 jabber_write_packet( bt->tf->ic, node ); 767 } 768 769 /* 770 * The proxy has activated the bytestream. 771 * We can finally start pushing some data out. 772 */ 773 static xt_status jabber_bs_send_handle_activate( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ) 774 { 775 char *sid; 776 GSList *tflist; 777 struct jabber_transfer *tf; 778 struct xt_node *query; 779 struct jabber_data *jd = ic->proto_data; 780 781 query = xt_find_node( orig->children, "query" ); 782 sid = xt_find_attr( query, "sid" ); 783 784 for( tflist = jd->filetransfers ; tflist; tflist = g_slist_next(tflist) ) 785 { 786 struct jabber_transfer *tft = tflist->data; 787 if( ( strcmp( tft->sid, sid ) == 0 ) ) 788 { 789 tf = tft; 790 break; 791 } 792 } 793 794 if( !tf ) 795 { 796 imcb_log( ic, "WARNING: Received SOCKS5 bytestream activation for unknown stream" ); 797 return XT_HANDLED; 798 } 799 800 /* handshake went through, let's start transferring */ 801 tf->ft->write_request( tf->ft ); 802 803 return XT_HANDLED; 804 } 805 806 /* 807 * Starts a bytestream. 808 */ 677 809 gboolean jabber_bs_send_start( struct jabber_transfer *tf ) 678 810 { 679 char host[INET6_ADDRSTRLEN] , port[6];811 char host[INET6_ADDRSTRLEN]; 680 812 struct bs_transfer *bt; 681 813 sha1_state_t sha; 682 814 char hash_hex[41]; 683 815 unsigned char hash[20]; 684 int i; 816 int i,ret; 817 struct jabber_data *jd = tf->ic->proto_data; 818 jabber_streamhost_t sh; 819 GSList *streamhosts = jd->streamhosts; 685 820 686 821 /* SHA1( SID + Initiator JID + Target JID ) is given to the streamhost which it will match against the initiator's value */ … … 702 837 tf->ft->canceled = jabber_bs_canceled; 703 838 704 if ( !jabber_bs_send_listen( bt, &tf->saddr, host,port ) )839 if ( !jabber_bs_send_listen( bt, &tf->saddr, sh.host = host, sh.port ) ) 705 840 return FALSE; 706 841 707 842 bt->tf->watch_in = b_input_add( tf->fd, GAIM_INPUT_READ, jabber_bs_send_handshake, bt ); 708 843 bt->connect_timeout = b_timeout_add( JABBER_BS_LISTEN_TIMEOUT * 1000, jabber_bs_connect_timeout, bt ); 709 return jabber_bs_send_request( tf, host, port ); 710 } 711 712 gboolean jabber_bs_send_request( struct jabber_transfer *tf, char *host, char *port ) 713 { 714 struct xt_node *sh, *query, *iq; 715 716 sh = xt_new_node( "streamhost", NULL, NULL ); 717 xt_add_attr( sh, "jid", tf->ini_jid ); 718 xt_add_attr( sh, "host", host ); 719 xt_add_attr( sh, "port", port ); 844 845 sh.jid = tf->ini_jid; 846 847 /* temporarily add listen address to streamhosts, send the request and remove it */ 848 streamhosts = g_slist_prepend( streamhosts, &sh ); 849 ret = jabber_bs_send_request( tf, streamhosts); 850 streamhosts = g_slist_remove( streamhosts, &sh ); 851 852 return ret; 853 } 854 855 gboolean jabber_bs_send_request( struct jabber_transfer *tf, GSList *streamhosts ) 856 { 857 struct xt_node *shnode, *query, *iq; 720 858 721 859 query = xt_new_node( "query", NULL, NULL ); … … 723 861 xt_add_attr( query, "sid", tf->sid ); 724 862 xt_add_attr( query, "mode", "tcp" ); 725 xt_add_child( query, sh ); 863 864 while( streamhosts ) { 865 jabber_streamhost_t *sh = streamhosts->data; 866 shnode = xt_new_node( "streamhost", NULL, NULL ); 867 xt_add_attr( shnode, "jid", sh->jid ); 868 xt_add_attr( shnode, "host", sh->host ); 869 xt_add_attr( shnode, "port", sh->port ); 870 871 xt_add_child( query, shnode ); 872 873 streamhosts = g_slist_next( streamhosts ); 874 } 875 726 876 727 877 iq = jabber_make_packet( "iq", "set", tf->tgt_jid, query ); … … 739 889 struct jabber_transfer *tf = bt->tf; 740 890 891 /* TODO: did the receiver get here somehow??? */ 741 892 imcb_log( tf->ic, "Transferring file %s: SOCKS5 handshake failed: %s", 742 893 tf->ft->file_name, … … 901 1052 { 902 1053 /* streamhost-used message came already in(possible?), let's start sending */ 903 tf->ft->started = time( NULL );904 1054 tf->ft->write_request( tf->ft ); 905 1055 } -
protocols/jabber/si.c
r8076ec0 rdc0ba9c 83 83 struct jabber_transfer *tf; 84 84 struct jabber_data *jd = ic->proto_data; 85 char *server = jd->server; 85 86 86 87 imcb_log( ic, "Trying to send %s(%zd bytes) to %s", ft->file_name, ft->file_size, who ); … … 97 98 jd->filetransfers = g_slist_prepend( jd->filetransfers, tf ); 98 99 100 /* query the buddy's features */ 101 jabber_iq_query_features( ic, who ); 102 103 /* query proxies from the server */ 104 if( !jd->have_streamhosts ) 105 jabber_iq_query_server( ic, server, XMLNS_DISCO_ITEMS ); 106 107 /* send the request to our buddy */ 99 108 jabber_si_send_request( ic, who, tf ); 100 109 110 /* and start the receive logic */ 101 111 imcb_file_recv_start( ft ); 102 112 }
Note: See TracChangeset
for help on using the changeset viewer.