Changes in protocols/jabber/iq.c [46d215d:4eef271]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/iq.c
r46d215d r4eef271 65 65 if( strcmp( s, XMLNS_VERSION ) == 0 ) 66 66 { 67 xt_add_child( reply, xt_new_node( "name", "BitlBee", NULL ) );67 xt_add_child( reply, xt_new_node( "name", set_getstr( &ic->acc->set, "user_agent" ), NULL ) ); 68 68 xt_add_child( reply, xt_new_node( "version", BITLBEE_VERSION, NULL ) ); 69 69 xt_add_child( reply, xt_new_node( "os", ARCH, NULL ) ); … … 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; … … 108 105 xt_add_attr( c, "category", "client" ); 109 106 xt_add_attr( c, "type", "pc" ); 110 xt_add_attr( c, "name", "BitlBee");107 xt_add_attr( c, "name", set_getstr( &ic->acc->set, "user_agent" ) ); 111 108 xt_add_child( reply, c ); 112 109 … … 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 ) … … 555 543 static xt_status jabber_add_to_roster_callback( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); 556 544 557 int jabber_add_to_roster( struct im_connection *ic, c onst char *handle, const char *name, const char *group)545 int jabber_add_to_roster( struct im_connection *ic, char *handle, char *name ) 558 546 { 559 547 struct xt_node *node; … … 565 553 if( name ) 566 554 xt_add_attr( node, "name", name ); 567 if( group )568 xt_add_child( node, xt_new_node( "group", group, NULL ) );569 555 570 556 /* And pack it into a roster-add packet */ … … 590 576 strcmp( s, "result" ) == 0 ) 591 577 { 592 if( bee_user_by_handle( ic->bee,ic, jid ) == NULL )578 if( imcb_find_buddy( ic, jid ) == NULL ) 593 579 imcb_add_buddy( ic, jid, NULL ); 594 580 } … … 622 608 return st; 623 609 } 624 625 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );626 627 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid )628 {629 struct xt_node *node, *query;630 struct jabber_buddy *bud;631 632 if( ( bud = jabber_buddy_by_jid( ic, bare_jid , 0 ) ) == NULL )633 {634 /* Who cares about the unknown... */635 imcb_log( ic, "Couldn't find buddy: %s", bare_jid);636 return XT_HANDLED;637 }638 639 if( bud->features ) /* been here already */640 return XT_HANDLED;641 642 node = xt_new_node( "query", NULL, NULL );643 xt_add_attr( node, "xmlns", XMLNS_DISCO_INFO );644 645 if( !( query = jabber_make_packet( "iq", "get", bare_jid, node ) ) )646 {647 imcb_log( ic, "WARNING: Couldn't generate feature query" );648 xt_free_node( node );649 return XT_HANDLED;650 }651 652 jabber_cache_add( ic, query, jabber_iq_parse_features );653 654 return jabber_write_packet( ic, query ) ? XT_HANDLED : XT_ABORT;655 }656 657 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )658 {659 struct xt_node *c;660 struct jabber_buddy *bud;661 char *feature, *xmlns, *from;662 663 if( !( from = xt_find_attr( node, "from" ) ) ||664 !( c = xt_find_node( node->children, "query" ) ) ||665 !( xmlns = xt_find_attr( c, "xmlns" ) ) ||666 !( strcmp( xmlns, XMLNS_DISCO_INFO ) == 0 ) )667 {668 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );669 return XT_HANDLED;670 }671 if( ( bud = jabber_buddy_by_jid( ic, from, 0 ) ) == NULL )672 {673 /* Who cares about the unknown... */674 imcb_log( ic, "Couldn't find buddy: %s", from );675 return XT_HANDLED;676 }677 678 c = c->children;679 while( ( c = xt_find_node( c, "feature" ) ) )680 {681 feature = xt_find_attr( c, "var" );682 if( feature )683 bud->features = g_slist_append( bud->features, g_strdup( feature ) );684 c = c->next;685 }686 687 return XT_HANDLED;688 }689 690 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );691 692 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns )693 {694 struct xt_node *node, *query;695 struct jabber_data *jd = ic->proto_data;696 697 node = xt_new_node( "query", NULL, NULL );698 xt_add_attr( node, "xmlns", xmlns );699 700 if( !( query = jabber_make_packet( "iq", "get", jid, node ) ) )701 {702 imcb_log( ic, "WARNING: Couldn't generate server query" );703 xt_free_node( node );704 }705 706 jd->have_streamhosts--;707 jabber_cache_add( ic, query, jabber_iq_parse_server_features );708 709 return jabber_write_packet( ic, query ) ? XT_HANDLED : XT_ABORT;710 }711 712 /*713 * Query the server for "items", query each "item" for identities, query each "item" that's a proxy for it's bytestream info714 */715 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )716 {717 struct xt_node *c;718 struct jabber_data *jd = ic->proto_data;719 char *xmlns, *from;720 721 if( !( c = xt_find_node( node->children, "query" ) ) ||722 !( from = xt_find_attr( node, "from" ) ) ||723 !( xmlns = xt_find_attr( c, "xmlns" ) ) )724 {725 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );726 return XT_HANDLED;727 }728 729 jd->have_streamhosts++;730 731 if( strcmp( xmlns, XMLNS_DISCO_ITEMS ) == 0 )732 {733 char *itemjid;734 735 /* answer from server */736 737 c = c->children;738 while( ( c = xt_find_node( c, "item" ) ) )739 {740 itemjid = xt_find_attr( c, "jid" );741 742 if( itemjid )743 jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO );744 745 c = c->next;746 }747 }748 else if( strcmp( xmlns, XMLNS_DISCO_INFO ) == 0 )749 {750 char *category, *type;751 752 /* answer from potential proxy */753 754 c = c->children;755 while( ( c = xt_find_node( c, "identity" ) ) )756 {757 category = xt_find_attr( c, "category" );758 type = xt_find_attr( c, "type" );759 760 if( type && ( strcmp( type, "bytestreams" ) == 0 ) &&761 category && ( strcmp( category, "proxy" ) == 0 ) )762 jabber_iq_query_server( ic, from, XMLNS_BYTESTREAMS );763 764 c = c->next;765 }766 }767 else if( strcmp( xmlns, XMLNS_BYTESTREAMS ) == 0 )768 {769 char *host, *jid, *port_s;770 int port;771 772 /* answer from proxy */773 774 if( ( c = xt_find_node( c->children, "streamhost" ) ) &&775 ( host = xt_find_attr( c, "host" ) ) &&776 ( port_s = xt_find_attr( c, "port" ) ) &&777 ( sscanf( port_s, "%d", &port ) == 1 ) &&778 ( jid = xt_find_attr( c, "jid" ) ) )779 {780 jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 );781 782 sh->jid = g_strdup( jid );783 sh->host = g_strdup( host );784 g_snprintf( sh->port, sizeof( sh->port ), "%u", port );785 786 imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port );787 jd->streamhosts = g_slist_append( jd->streamhosts, sh );788 }789 }790 791 if( jd->have_streamhosts == 0 )792 jd->have_streamhosts++;793 794 return XT_HANDLED;795 }
Note: See TracChangeset
for help on using the changeset viewer.