Changes in protocols/jabber/iq.c [4306d8b:eded1f7]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
r4306d8b reded1f7 50 50 else if( strcmp( type, "get" ) == 0 ) 51 51 { 52 if( !( c = xt_find_node( node->children, "query" ) ) || 52 if( !( ( c = xt_find_node( node->children, "query" ) ) || 53 ( c = xt_find_node( node->children, "ping" ) ) ) || /* O_o WHAT is wrong with just <query/> ????? */ 53 54 !( s = xt_find_attr( c, "xmlns" ) ) ) 54 55 { … … 81 82 xt_add_child( reply, xt_new_node( "tz", buf, NULL ) ); 82 83 } 83 else if( strcmp( s, XMLNS_DISCOVER ) == 0 ) 84 else if( strcmp( s, XMLNS_PING ) == 0 ) 85 { 86 xt_free_node( reply ); 87 reply = jabber_make_packet( "iq", "result", xt_find_attr( node, "from" ), NULL ); 88 if( ( s = xt_find_attr( node, "id" ) ) ) 89 xt_add_attr( reply, "id", s ); 90 pack = 0; 91 } 92 else if( strcmp( s, XMLNS_DISCO_INFO ) == 0 ) 84 93 { 85 94 const char *features[] = { XMLNS_VERSION, … … 87 96 XMLNS_CHATSTATES, 88 97 XMLNS_MUC, 98 XMLNS_PING, 99 XMLNS_SI, 100 XMLNS_BYTESTREAMS, 101 XMLNS_FILETRANSFER, 89 102 NULL }; 90 103 const char **f; … … 106 119 { 107 120 xt_free_node( reply ); 108 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );121 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel", NULL ); 109 122 pack = 0; 110 123 } … … 112 125 else if( strcmp( type, "set" ) == 0 ) 113 126 { 114 if( !( c = xt_find_node( node->children, "query" ) ) || 127 if( ( c = xt_find_node( node->children, "si" ) ) && 128 ( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_SI ) == 0 ) ) 129 { 130 return jabber_si_handle_request( ic, node, c ); 131 } else if( !( c = xt_find_node( node->children, "query" ) ) || 115 132 !( s = xt_find_attr( c, "xmlns" ) ) ) 116 133 { 117 134 imcb_log( ic, "WARNING: Received incomplete IQ-%s packet", type ); 118 135 return XT_HANDLED; 119 } 120 136 } else if( strcmp( s, XMLNS_ROSTER ) == 0 ) 137 { 121 138 /* This is a roster push. XMPP servers send this when someone 122 139 was added to (or removed from) the buddy list. AFAIK they're 123 140 sent even if we added this buddy in our own session. */ 124 if( strcmp( s, XMLNS_ROSTER ) == 0 )125 {126 141 int bare_len = strlen( ic->acc->user ); 127 142 … … 140 155 141 156 xt_free_node( reply ); 142 reply = jabber_make_error_packet( node, "not-allowed", "cancel" );157 reply = jabber_make_error_packet( node, "not-allowed", "cancel", NULL ); 143 158 pack = 0; 144 159 } 145 } 146 else 160 } else if( strcmp( s, XMLNS_BYTESTREAMS ) == 0 ) 161 { 162 /* Bytestream Request (stage 2 of file transfer) */ 163 return jabber_bs_recv_request( ic, node, c ); 164 } else 147 165 { 148 166 xt_free_node( reply ); 149 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );167 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel", NULL ); 150 168 pack = 0; 151 169 } … … 557 575 return st; 558 576 } 577 578 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); 579 580 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid ) 581 { 582 struct xt_node *node, *query; 583 struct jabber_buddy *bud; 584 585 if( ( bud = jabber_buddy_by_jid( ic, bare_jid , 0 ) ) == NULL ) 586 { 587 /* Who cares about the unknown... */ 588 imcb_log( ic, "Couldnt find the man: %s", bare_jid); 589 return 0; 590 } 591 592 if( bud->features ) /* been here already */ 593 return XT_HANDLED; 594 595 node = xt_new_node( "query", NULL, NULL ); 596 xt_add_attr( node, "xmlns", XMLNS_DISCO_INFO ); 597 598 if( !( query = jabber_make_packet( "iq", "get", bare_jid, node ) ) ) 599 { 600 imcb_log( ic, "WARNING: Couldn't generate feature query" ); 601 xt_free_node( node ); 602 } 603 604 jabber_cache_add( ic, query, jabber_iq_parse_features ); 605 606 return jabber_write_packet( ic, query ); 607 } 608 609 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ) 610 { 611 struct xt_node *c; 612 struct jabber_buddy *bud; 613 char *feature; 614 615 if( !( c = xt_find_node( node->children, "query" ) ) || 616 !( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) ) 617 { 618 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" ); 619 return XT_HANDLED; 620 } 621 if( ( bud = jabber_buddy_by_jid( ic, xt_find_attr( node, "from") , 0 ) ) == NULL ) 622 { 623 /* Who cares about the unknown... */ 624 imcb_log( ic, "Couldnt find the man: %s", xt_find_attr( node, "from")); 625 return 0; 626 } 627 628 c = c->children; 629 while( ( c = xt_find_node( c, "feature" ) ) ) { 630 feature = xt_find_attr( c, "var" ); 631 bud->features = g_slist_append(bud->features, g_strdup(feature) ); 632 c = c->next; 633 } 634 635 return XT_HANDLED; 636 } 637 638 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); 639 640 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns ) 641 { 642 struct xt_node *node, *query; 643 struct jabber_data *jd = ic->proto_data; 644 645 node = xt_new_node( "query", NULL, NULL ); 646 xt_add_attr( node, "xmlns", xmlns ); 647 648 if( !( query = jabber_make_packet( "iq", "get", jid, node ) ) ) 649 { 650 imcb_log( ic, "WARNING: Couldn't generate server query" ); 651 xt_free_node( node ); 652 } 653 654 jd->have_streamhosts--; 655 jabber_cache_add( ic, query, jabber_iq_parse_server_features ); 656 657 return jabber_write_packet( ic, query ); 658 } 659 660 /* 661 * Query the server for "items", query each "item" for identities, query each "item" that's a proxy for it's bytestream info 662 */ 663 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ) 664 { 665 struct xt_node *c; 666 struct jabber_data *jd = ic->proto_data; 667 668 if( !( c = xt_find_node( node->children, "query" ) ) || 669 !xt_find_attr( node, "from" ) ) 670 { 671 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" ); 672 return XT_HANDLED; 673 } 674 675 jd->have_streamhosts++; 676 677 if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_ITEMS ) == 0 ) 678 { 679 char *item, *itemjid; 680 681 /* answer from server */ 682 683 c = c->children; 684 while( ( c = xt_find_node( c, "item" ) ) ) 685 { 686 item = xt_find_attr( c, "name" ); 687 itemjid = xt_find_attr( c, "jid" ); 688 689 jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO ); 690 691 c = c->next; 692 } 693 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) 694 { 695 char *category, *type; 696 697 /* answer from potential proxy */ 698 699 c = c->children; 700 while( ( c = xt_find_node( c, "identity" ) ) ) 701 { 702 category = xt_find_attr( c, "category" ); 703 type = xt_find_attr( c, "type" ); 704 705 if( type && ( strcmp( type, "bytestreams" ) == 0 ) && 706 category && ( strcmp( category, "proxy" ) == 0 ) ) 707 jabber_iq_query_server( ic, xt_find_attr( node, "from" ), XMLNS_BYTESTREAMS ); 708 709 c = c->next; 710 } 711 } else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_BYTESTREAMS ) == 0 ) 712 { 713 char *host, *jid; 714 int port; 715 716 /* answer from proxy */ 717 718 if( ( c = xt_find_node( c->children, "streamhost" ) ) && 719 ( host = xt_find_attr( c, "host" ) ) && 720 ( port = atoi( xt_find_attr( c, "port" ) ) ) && 721 ( jid = xt_find_attr( c, "jid" ) ) ) 722 { 723 jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 ); 724 sh->jid = g_strdup( jid ); 725 sh->host = g_strdup( host ); 726 sprintf( sh->port, "%u", port ); 727 728 imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port ); 729 jd->streamhosts = g_slist_append( jd->streamhosts, sh ); 730 } 731 } 732 733 if( jd->have_streamhosts == 0 ) 734 jd->have_streamhosts++; 735 return XT_HANDLED; 736 }
Note: See TracChangeset
for help on using the changeset viewer.