Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    raed152f r186bd04  
    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                     ( 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" ) ) )
    137                 {
    138                         imcb_log( ic, "Warning: Received incomplete IQ-%s packet", type );
     126                if( !( c = xt_find_node( node->children, "query" ) ) ||
     127                    !( s = xt_find_attr( c, "xmlns" ) ) )
     128                {
    139129                        return XT_HANDLED;
    140130                }
    141                 else if( strcmp( s, XMLNS_ROSTER ) == 0 )
    142                 {
     131               
    143132                /* This is a roster push. XMPP servers send this when someone
    144133                   was added to (or removed from) the buddy list. AFAIK they're
    145134                   sent even if we added this buddy in our own session. */
     135                if( strcmp( s, XMLNS_ROSTER ) == 0 )
     136                {
    146137                        int bare_len = strlen( ic->acc->user );
    147138                       
     
    160151                               
    161152                                xt_free_node( reply );
    162                                 reply = jabber_make_error_packet( node, "not-allowed", "cancel", NULL );
     153                                reply = jabber_make_error_packet( node, "not-allowed", "cancel" );
    163154                                pack = 0;
    164155                        }
    165156                }
    166                 else if( strcmp( s, XMLNS_BYTESTREAMS ) == 0 )
    167                 {
    168                         /* Bytestream Request (stage 2 of file transfer) */
    169                         return jabber_bs_recv_request( ic, node, c );
    170                 }
    171157                else
    172158                {
    173159                        xt_free_node( reply );
    174                         reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel", NULL );
     160                        reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
    175161                        pack = 0;
    176162                }
     
    622608        return st;
    623609}
    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 info
    714  */
    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.