Ignore:
Timestamp:
2007-12-19T00:24:32Z (16 years ago)
Author:
ulim <a.sporto+bee@…>
Branches:
master
Children:
1ba7e8f
Parents:
793cc25 (diff), 2379566 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Now with sending via a proxy. The proxy is automatically discovered from your
jabber server.

Also merged in revs 279..288 from upstream (e.g. PING)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r793cc25 r0fbd3a6d  
    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,
    8999                                                   XMLNS_SI,
    90100                                                   XMLNS_BYTESTREAMS,
     
    565575        return st;
    566576}
     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.