Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r1c3008a r315dd4c  
    9191                        pack = 0;
    9292                }
    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,
    9696                                                   XMLNS_VERSION,
    9797                                                   XMLNS_TIME,
     
    9999                                                   XMLNS_MUC,
    100100                                                   XMLNS_PING,
    101                                                    XMLNS_SI,
    102                                                    XMLNS_BYTESTREAMS,
    103                                                    XMLNS_FILETRANSFER,
    104101                                                   NULL };
    105102                        const char **f;
     
    121118                {
    122119                        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" );
    124121                        pack = 0;
    125122                }
     
    127124        else if( strcmp( type, "set" ) == 0 )
    128125        {
    129                 if( ( c = xt_find_node( node->children, "si" ) ) &&
    130                     ( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_SI ) == 0 ) )
    131                 {
    132                         return jabber_si_handle_request( ic, node, c );
    133                 }
    134                 else if( !( c = xt_find_node( node->children, "query" ) ) ||
    135                          !( s = xt_find_attr( c, "xmlns" ) ) )
     126                if( !( c = xt_find_node( node->children, "query" ) ) ||
     127                    !( s = xt_find_attr( c, "xmlns" ) ) )
    136128                {
    137129                        imcb_log( ic, "Warning: Received incomplete IQ-%s packet", type );
    138130                        return XT_HANDLED;
    139131                }
    140                 else if( strcmp( s, XMLNS_ROSTER ) == 0 )
    141                 {
     132               
    142133                /* This is a roster push. XMPP servers send this when someone
    143134                   was added to (or removed from) the buddy list. AFAIK they're
    144135                   sent even if we added this buddy in our own session. */
     136                if( strcmp( s, XMLNS_ROSTER ) == 0 )
     137                {
    145138                        int bare_len = strlen( ic->acc->user );
    146139                       
     
    159152                               
    160153                                xt_free_node( reply );
    161                                 reply = jabber_make_error_packet( node, "not-allowed", "cancel", NULL );
     154                                reply = jabber_make_error_packet( node, "not-allowed", "cancel" );
    162155                                pack = 0;
    163156                        }
    164157                }
    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                 }
    170158                else
    171159                {
    172160                        xt_free_node( reply );
    173                         reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel", NULL );
     161                        reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
    174162                        pack = 0;
    175163                }
     
    310298{
    311299        struct jabber_data *jd = ic->proto_data;
    312         struct xt_node *c;
     300        struct xt_node *c, *reply = NULL;
    313301        char *s;
    314302       
    315         if( ( c = xt_find_node( node->children, "bind" ) ) )
     303        if( node && ( c = xt_find_node( node->children, "bind" ) ) )
    316304        {
    317305                c = xt_find_node( c->children, "jid" );
     
    319307                    strcmp( s + 1, set_getstr( &ic->acc->set, "resource" ) ) != 0 )
    320308                        imcb_log( ic, "Server changed session resource string to `%s'", s + 1 );
    321                
    322                 jd->flags &= ~JFLAG_WAIT_BIND;
    323         }
    324         else
    325         {
    326                 jd->flags &= ~JFLAG_WAIT_SESSION;
    327         }
    328        
    329         if( ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 )
     309        }
     310       
     311        if( jd->flags & JFLAG_WANT_BIND )
     312        {
     313                reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) );
     314                xt_add_attr( reply, "xmlns", XMLNS_BIND );
     315                jd->flags &= ~JFLAG_WANT_BIND;
     316        }
     317        else if( jd->flags & JFLAG_WANT_SESSION )
     318        {
     319                reply = xt_new_node( "session", NULL, NULL );
     320                xt_add_attr( reply, "xmlns", XMLNS_SESSION );
     321                jd->flags &= ~JFLAG_WANT_SESSION;
     322        }
     323       
     324        if( reply != NULL )
     325        {
     326                reply = jabber_make_packet( "iq", "set", NULL, reply );
     327                jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
     328               
     329                if( !jabber_write_packet( ic, reply ) )
     330                        return XT_ABORT;
     331        }
     332        else if( ( jd->flags & ( JFLAG_WANT_BIND | JFLAG_WANT_SESSION ) ) == 0 )
    330333        {
    331334                if( !jabber_get_roster( ic ) )
     
    606609        return st;
    607610}
    608 
    609 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
    610 
    611 xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid )
    612 {
    613         struct xt_node *node, *query;
    614         struct jabber_buddy *bud;
    615        
    616         if( ( bud = jabber_buddy_by_jid( ic, bare_jid , 0 ) ) == NULL )
    617         {
    618                 /* Who cares about the unknown... */
    619                 imcb_log( ic, "Couldn't find buddy: %s", bare_jid);
    620                 return 0;
    621         }
    622        
    623         if( bud->features ) /* been here already */
    624                 return XT_HANDLED;
    625        
    626         node = xt_new_node( "query", NULL, NULL );
    627         xt_add_attr( node, "xmlns", XMLNS_DISCO_INFO );
    628        
    629         if( !( query = jabber_make_packet( "iq", "get", bare_jid, node ) ) )
    630         {
    631                 imcb_log( ic, "WARNING: Couldn't generate feature query" );
    632                 xt_free_node( node );
    633                 return 0;
    634         }
    635 
    636         jabber_cache_add( ic, query, jabber_iq_parse_features );
    637 
    638         return jabber_write_packet( ic, query );
    639 }
    640 
    641 xt_status jabber_iq_parse_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )
    642 {
    643         struct xt_node *c;
    644         struct jabber_buddy *bud;
    645         char *feature;
    646 
    647         if( !( c = xt_find_node( node->children, "query" ) ) ||
    648             !( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 ) )
    649         {
    650                 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );
    651                 return XT_HANDLED;
    652         }
    653         if( ( bud = jabber_buddy_by_jid( ic, xt_find_attr( node, "from") , 0 ) ) == NULL )
    654         {
    655                 /* Who cares about the unknown... */
    656                 imcb_log( ic, "Couldn't find buddy: %s", xt_find_attr( node, "from"));
    657                 return 0;
    658         }
    659        
    660         c = c->children;
    661         while( ( c = xt_find_node( c, "feature" ) ) )
    662         {
    663                 feature = xt_find_attr( c, "var" );
    664                 bud->features = g_slist_append( bud->features, g_strdup( feature ) );
    665                 c = c->next;
    666         }
    667 
    668         return XT_HANDLED;
    669 }
    670 
    671 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
    672 
    673 xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns )
    674 {
    675         struct xt_node *node, *query;
    676         struct jabber_data *jd = ic->proto_data;
    677        
    678         node = xt_new_node( "query", NULL, NULL );
    679         xt_add_attr( node, "xmlns", xmlns );
    680        
    681         if( !( query = jabber_make_packet( "iq", "get", jid, node ) ) )
    682         {
    683                 imcb_log( ic, "WARNING: Couldn't generate server query" );
    684                 xt_free_node( node );
    685         }
    686 
    687         jd->have_streamhosts--;
    688         jabber_cache_add( ic, query, jabber_iq_parse_server_features );
    689 
    690         return jabber_write_packet( ic, query );
    691 }
    692 
    693 /*
    694  * Query the server for "items", query each "item" for identities, query each "item" that's a proxy for it's bytestream info
    695  */
    696 xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_node *node, struct xt_node *orig )
    697 {
    698         struct xt_node *c;
    699         struct jabber_data *jd = ic->proto_data;
    700 
    701         if( !( c = xt_find_node( node->children, "query" ) ) ||
    702             !xt_find_attr( node, "from" ) )
    703         {
    704                 imcb_log( ic, "WARNING: Received incomplete IQ-result packet for discover" );
    705                 return XT_HANDLED;
    706         }
    707 
    708         jd->have_streamhosts++;
    709 
    710         if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_ITEMS ) == 0 )
    711         {
    712                 char *item, *itemjid;
    713 
    714                 /* answer from server */
    715        
    716                 c = c->children;
    717                 while( ( c = xt_find_node( c, "item" ) ) )
    718                 {
    719                         item = xt_find_attr( c, "name" );
    720                         itemjid = xt_find_attr( c, "jid" );
    721 
    722                         jabber_iq_query_server( ic, itemjid, XMLNS_DISCO_INFO );
    723 
    724                         c = c->next;
    725                 }
    726         }
    727         else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_DISCO_INFO ) == 0 )
    728         {
    729                 char *category, *type;
    730 
    731                 /* answer from potential proxy */
    732 
    733                 c = c->children;
    734                 while( ( c = xt_find_node( c, "identity" ) ) )
    735                 {
    736                         category = xt_find_attr( c, "category" );
    737                         type = xt_find_attr( c, "type" );
    738 
    739                         if( type && ( strcmp( type, "bytestreams" ) == 0 ) &&
    740                             category && ( strcmp( category, "proxy" ) == 0 ) )
    741                                 jabber_iq_query_server( ic, xt_find_attr( node, "from" ), XMLNS_BYTESTREAMS );
    742 
    743                         c = c->next;
    744                 }
    745         }
    746         else if( strcmp( xt_find_attr( c, "xmlns" ), XMLNS_BYTESTREAMS ) == 0 )
    747         {
    748                 char *host, *jid;
    749                 int port;
    750 
    751                 /* answer from proxy */
    752 
    753                 if( ( c = xt_find_node( c->children, "streamhost" ) ) &&
    754                     ( host = xt_find_attr( c, "host" ) ) &&
    755                     ( port = atoi( xt_find_attr( c, "port" ) ) ) &&
    756                     ( jid = xt_find_attr( c, "jid" ) ) )
    757                 {
    758                         jabber_streamhost_t *sh = g_new0( jabber_streamhost_t, 1 );
    759                         sh->jid = g_strdup( jid );
    760                         sh->host = g_strdup( host );
    761                         sprintf( sh->port, "%u", port );
    762 
    763                         imcb_log( ic, "Proxy found: jid %s host %s port %u", jid, host, port );
    764                         jd->streamhosts = g_slist_append( jd->streamhosts, sh );
    765                 }
    766         }
    767 
    768         if( jd->have_streamhosts == 0 )
    769                 jd->have_streamhosts++;
    770 
    771         return XT_HANDLED;
    772 }
Note: See TracChangeset for help on using the changeset viewer.