Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r4306d8b reded1f7  
    5050        else if( strcmp( type, "get" ) == 0 )
    5151        {
    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/> ????? */
    5354                    !( s = xt_find_attr( c, "xmlns" ) ) )
    5455                {
     
    8182                        xt_add_child( reply, xt_new_node( "tz", buf, NULL ) );
    8283                }
    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 )
    8493                {
    8594                        const char *features[] = { XMLNS_VERSION,
     
    8796                                                   XMLNS_CHATSTATES,
    8897                                                   XMLNS_MUC,
     98                                                   XMLNS_PING,
     99                                                   XMLNS_SI,
     100                                                   XMLNS_BYTESTREAMS,
     101                                                   XMLNS_FILETRANSFER,
    89102                                                   NULL };
    90103                        const char **f;
     
    106119                {
    107120                        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 );
    109122                        pack = 0;
    110123                }
     
    112125        else if( strcmp( type, "set" ) == 0 )
    113126        {
    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" ) ) ||
    115132                    !( s = xt_find_attr( c, "xmlns" ) ) )
    116133                {
    117134                        imcb_log( ic, "WARNING: Received incomplete IQ-%s packet", type );
    118135                        return XT_HANDLED;
    119                 }
    120                
     136                } else if( strcmp( s, XMLNS_ROSTER ) == 0 )
     137                {
    121138                /* This is a roster push. XMPP servers send this when someone
    122139                   was added to (or removed from) the buddy list. AFAIK they're
    123140                   sent even if we added this buddy in our own session. */
    124                 if( strcmp( s, XMLNS_ROSTER ) == 0 )
    125                 {
    126141                        int bare_len = strlen( ic->acc->user );
    127142                       
     
    140155                               
    141156                                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 );
    143158                                pack = 0;
    144159                        }
    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
    147165                {
    148166                        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 );
    150168                        pack = 0;
    151169                }
     
    557575        return st;
    558576}
     577
     578xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
     579
     580xt_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
     609xt_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
     638xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
     639
     640xt_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 */
     663xt_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.