Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r186bd04 rf5d87ea  
    9191                        pack = 0;
    9292                }
    93                 else if( strcmp( s, XMLNS_DISCOVER ) == 0 )
    94                 {
    95                         const char *features[] = { XMLNS_DISCOVER,
     93                else if( strcmp( s, XMLNS_DISCO_INFO ) == 0 )
     94                {
     95                        const char *features[] = { XMLNS_DISCO_INFO,
    9696                                                   XMLNS_VERSION,
    9797                                                   XMLNS_TIME,
     
    9999                                                   XMLNS_MUC,
    100100                                                   XMLNS_PING,
     101                                                   XMLNS_SI,
     102                                                   XMLNS_BYTESTREAMS,
     103                                                   XMLNS_FILETRANSFER,
    101104                                                   NULL };
    102105                        const char **f;
     
    118121                {
    119122                        xt_free_node( reply );
    120                         reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
     123                        reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel", NULL );
    121124                        pack = 0;
    122125                }
     
    124127        else if( strcmp( type, "set" ) == 0 )
    125128        {
    126                 if( !( c = xt_find_node( node->children, "query" ) ) ||
    127                     !( s = xt_find_attr( c, "xmlns" ) ) )
     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" ) ) )
    128137                {
    129138                        return XT_HANDLED;
    130139                }
    131                
     140                else if( strcmp( s, XMLNS_ROSTER ) == 0 )
     141                {
    132142                /* This is a roster push. XMPP servers send this when someone
    133143                   was added to (or removed from) the buddy list. AFAIK they're
    134144                   sent even if we added this buddy in our own session. */
    135                 if( strcmp( s, XMLNS_ROSTER ) == 0 )
    136                 {
    137145                        int bare_len = strlen( ic->acc->user );
    138146                       
     
    151159                               
    152160                                xt_free_node( reply );
    153                                 reply = jabber_make_error_packet( node, "not-allowed", "cancel" );
     161                                reply = jabber_make_error_packet( node, "not-allowed", "cancel", NULL );
    154162                                pack = 0;
    155163                        }
    156164                }
     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                }
    157170                else
    158171                {
    159172                        xt_free_node( reply );
    160                         reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
     173                        reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel", NULL );
    161174                        pack = 0;
    162175                }
     
    369382        while( ( c = xt_find_node( c, "item" ) ) )
    370383        {
    371                 struct xt_node *group = xt_find_node( node->children, "group" );
     384                struct xt_node *group = xt_find_node( c->children, "group" );
    372385                char *jid = xt_find_attr( c, "jid" );
    373386                char *name = xt_find_attr( c, "name" );
     
    378391                        if( ( strcmp( sub, "both" ) == 0 || strcmp( sub, "to" ) == 0 ) )
    379392                        {
    380                                 if( initial || imcb_find_buddy( ic, jid ) == NULL )
    381                                         imcb_add_buddy( ic, jid, ( group && group->text_len ) ?
    382                                                                    group->text : NULL );
     393                                imcb_add_buddy( ic, jid, ( group && group->text_len ) ?
     394                                                           group->text : NULL );
    383395                               
    384396                                if( name )
     
    576588            strcmp( s, "result" ) == 0 )
    577589        {
    578                 if( imcb_find_buddy( ic, jid ) == NULL )
     590                if( bee_user_by_handle( ic->bee, ic, jid ) == NULL )
    579591                        imcb_add_buddy( ic, jid, NULL );
    580592        }
     
    608620        return st;
    609621}
     622
     623xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
     624
     625xt_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
     655xt_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
     688xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
     689
     690xt_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 info
     712 */
     713xt_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.