Changes in protocols/jabber/iq.c [f5d87ea:186bd04]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
rf5d87ea r186bd04 91 91 pack = 0; 92 92 } 93 else if( strcmp( s, XMLNS_DISCO _INFO) == 0 )94 { 95 const char *features[] = { XMLNS_DISCO _INFO,93 else if( strcmp( s, XMLNS_DISCOVER ) == 0 ) 94 { 95 const char *features[] = { XMLNS_DISCOVER, 96 96 XMLNS_VERSION, 97 97 XMLNS_TIME, … … 99 99 XMLNS_MUC, 100 100 XMLNS_PING, 101 XMLNS_SI,102 XMLNS_BYTESTREAMS,103 XMLNS_FILETRANSFER,104 101 NULL }; 105 102 const char **f; … … 121 118 { 122 119 xt_free_node( reply ); 123 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" , NULL);120 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); 124 121 pack = 0; 125 122 } … … 127 124 else if( strcmp( type, "set" ) == 0 ) 128 125 { 129 if( ( c = xt_find_node( node->children, "si" ) ) && 130 ( s = xt_find_attr( c, "xmlns" ) ) && 131 ( strcmp( s, XMLNS_SI ) == 0 ) ) 132 { 133 return jabber_si_handle_request( ic, node, c ); 134 } 135 else if( !( c = xt_find_node( node->children, "query" ) ) || 136 !( s = xt_find_attr( c, "xmlns" ) ) ) 126 if( !( c = xt_find_node( node->children, "query" ) ) || 127 !( s = xt_find_attr( c, "xmlns" ) ) ) 137 128 { 138 129 return XT_HANDLED; 139 130 } 140 else if( strcmp( s, XMLNS_ROSTER ) == 0 ) 141 { 131 142 132 /* This is a roster push. XMPP servers send this when someone 143 133 was added to (or removed from) the buddy list. AFAIK they're 144 134 sent even if we added this buddy in our own session. */ 135 if( strcmp( s, XMLNS_ROSTER ) == 0 ) 136 { 145 137 int bare_len = strlen( ic->acc->user ); 146 138 … … 159 151 160 152 xt_free_node( reply ); 161 reply = jabber_make_error_packet( node, "not-allowed", "cancel" , NULL);153 reply = jabber_make_error_packet( node, "not-allowed", "cancel" ); 162 154 pack = 0; 163 155 } 164 156 } 165 else if( strcmp( s, XMLNS_BYTESTREAMS ) == 0 )166 {167 /* Bytestream Request (stage 2 of file transfer) */168 return jabber_bs_recv_request( ic, node, c );169 }170 157 else 171 158 { 172 159 xt_free_node( reply ); 173 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" , NULL);160 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" ); 174 161 pack = 0; 175 162 } … … 382 369 while( ( c = xt_find_node( c, "item" ) ) ) 383 370 { 384 struct xt_node *group = xt_find_node( c->children, "group" );371 struct xt_node *group = xt_find_node( node->children, "group" ); 385 372 char *jid = xt_find_attr( c, "jid" ); 386 373 char *name = xt_find_attr( c, "name" ); … … 391 378 if( ( strcmp( sub, "both" ) == 0 || strcmp( sub, "to" ) == 0 ) ) 392 379 { 393 imcb_add_buddy( ic, jid, ( group && group->text_len ) ? 394 group->text : NULL ); 380 if( initial || imcb_find_buddy( ic, jid ) == NULL ) 381 imcb_add_buddy( ic, jid, ( group && group->text_len ) ? 382 group->text : NULL ); 395 383 396 384 if( name ) … … 588 576 strcmp( s, "result" ) == 0 ) 589 577 { 590 if( bee_user_by_handle( ic->bee,ic, jid ) == NULL )578 if( imcb_find_buddy( ic, jid ) == NULL ) 591 579 imcb_add_buddy( ic, jid, NULL ); 592 580 } … … 620 608 return st; 621 609 } 622 623 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );624 625 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid )626 {627 struct xt_node *node, *query;628 struct jabber_buddy *bud;629 630 if( ( bud = jabber_buddy_by_jid( ic, bare_jid , 0 ) ) == NULL )631 {632 /* Who cares about the unknown... */633 imcb_log( ic, "Couldn't find buddy: %s", bare_jid);634 return XT_HANDLED;635 }636 637 if( bud->features ) /* been here already */638 return XT_HANDLED;639 640 node = xt_new_node( "query", NULL, NULL );641 xt_add_attr( node, "xmlns", XMLNS_DISCO_INFO );642 643 if( !( query = jabber_make_packet( "iq", "get", bare_jid, node ) ) )644 {645 imcb_log( ic, "WARNING: Couldn't generate feature query" );646 xt_free_node( node );647 return XT_HANDLED;648 }649 650 jabber_cache_add( ic, query, jabber_iq_parse_features );651 652 return jabber_write_packet( ic, query ) ? XT_HANDLED : XT_ABORT;653 }654 655 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )656 {657 struct xt_node *c;658 struct jabber_buddy *bud;659 char *feature, *xmlns, *from;660 661 if( !( from = xt_find_attr( node, "from" ) ) ||662 !( c = xt_find_node( node->children, "query" ) ) ||663 !( xmlns = xt_find_attr( c, "xmlns" ) ) ||664 !( strcmp( xmlns, XMLNS_DISCO_INFO ) == 0 ) )665 {666 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );667 return XT_HANDLED;668 }669 if( ( bud = jabber_buddy_by_jid( ic, from, 0 ) ) == NULL )670 {671 /* Who cares about the unknown... */672 imcb_log( ic, "Couldn't find buddy: %s", from );673 return XT_HANDLED;674 }675 676 c = c->children;677 while( ( c = xt_find_node( c, "feature" ) ) )678 {679 feature = xt_find_attr( c, "var" );680 if( feature )681 bud->features = g_slist_append( bud->features, g_strdup( feature ) );682 c = c->next;683 }684 685 return XT_HANDLED;686 }687 688 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );689 690 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns )691 {692 struct xt_node *node, *query;693 struct jabber_data *jd = ic->proto_data;694 695 node = xt_new_node( "query", NULL, NULL );696 xt_add_attr( node, "xmlns", xmlns );697 698 if( !( query = jabber_make_packet( "iq", "get", jid, node ) ) )699 {700 imcb_log( ic, "WARNING: Couldn't generate server query" );701 xt_free_node( node );702 }703 704 jd->have_streamhosts--;705 jabber_cache_add( ic, query, jabber_iq_parse_server_features );706 707 return jabber_write_packet( ic, query ) ? XT_HANDLED : XT_ABORT;708 }709 710 /*711 * Query the server for "items", query each "item" for identities, query each "item" that's a proxy for it's bytestream info712 */713 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )714 {715 struct xt_node *c;716 struct jabber_data *jd = ic->proto_data;717 char *xmlns, *from;718 719 if( !( c = xt_find_node( node->children, "query" ) ) ||720 !( from = xt_find_attr( node, "from" ) ) ||721 !( xmlns = xt_find_attr( c, "xmlns" ) ) )722 {723 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );724 return XT_HANDLED;725 }726 727 jd->have_streamhosts++;728 729 if( strcmp( xmlns, XMLNS_DISCO_ITEMS ) == 0 )730 {731 char *itemjid;732 733 /* answer from server */734 735 c = c->children;736 while( ( c = xt_find_node( c, "item" ) ) )737 {738 itemjid = xt_find_attr( c, "jid" );739 740 if( itemjid )741 jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO );742 743 c = c->next;744 }745 }746 else if( strcmp( xmlns, XMLNS_DISCO_INFO ) == 0 )747 {748 char *category, *type;749 750 /* answer from potential proxy */751 752 c = c->children;753 while( ( c = xt_find_node( c, "identity" ) ) )754 {755 category = xt_find_attr( c, "category" );756 type = xt_find_attr( c, "type" );757 758 if( type && ( strcmp( type, "bytestreams" ) == 0 ) &&759 category && ( strcmp( category, "proxy" ) == 0 ) )760 jabber_iq_query_server( ic, from, XMLNS_BYTESTREAMS );761 762 c = c->next;763 }764 }765 else if( strcmp( xmlns, XMLNS_BYTESTREAMS ) == 0 )766 {767 char *host, *jid, *port_s;768 int port;769 770 /* answer from proxy */771 772 if( ( c = xt_find_node( c->children, "streamhost" ) ) &&773 ( host = xt_find_attr( c, "host" ) ) &&774 ( port_s = xt_find_attr( c, "port" ) ) &&775 ( sscanf( port_s, "%d", &port ) == 1 ) &&776 ( jid = xt_find_attr( c, "jid" ) ) )777 {778 jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 );779 780 sh->jid = g_strdup( jid );781 sh->host = g_strdup( host );782 g_snprintf( sh->port, sizeof( sh->port ), "%u", port );783 784 imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port );785 jd->streamhosts = g_slist_append( jd->streamhosts, sh );786 }787 }788 789 if( jd->have_streamhosts == 0 )790 jd->have_streamhosts++;791 792 return XT_HANDLED;793 }
Note: See TracChangeset
for help on using the changeset viewer.