Changeset 259edd4 for protocols/jabber


Ignore:
Timestamp:
2006-10-12T17:48:58Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a4effbf
Parents:
b56b220
Message:

Special message when the XMPP session is ended because of a concurrent
login, and now sending proper error responses to IQ packets we can't
handle.

Location:
protocols/jabber
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/io.c

    rb56b220 r259edd4  
    465465           infinite loop! */
    466466        if( strcmp( type, "conflict" ) == 0 )
     467        {
     468                hide_login_progress( gc, "Account and resource used from a different location" );
    467469                gc->wants_to_die = TRUE;
    468        
    469         s = g_strdup_printf( "Stream error: %s%s%s", type, text ? ": " : "", text ? text : "" );
    470         hide_login_progress_error( gc, s );
    471         g_free( s );
     470        }
     471        else
     472        {
     473                s = g_strdup_printf( "Stream error: %s%s%s", type, text ? ": " : "", text ? text : "" );
     474                hide_login_progress_error( gc, s );
     475                g_free( s );
     476        }
     477       
    472478        signoff( gc );
    473479       
  • protocols/jabber/iq.c

    rb56b220 r259edd4  
    3030        struct xt_node *c, *reply = NULL;
    3131        char *type, *s;
    32         int st;
     32        int st, pack = 1;
    3333       
    3434        type = xt_find_attr( node, "type" );
     
    101101                {
    102102                        xt_free_node( reply );
    103                         reply = NULL;
    104                 }
    105                
    106                 /* If we recognized the xmlns and managed to generate a reply,
    107                    finish and send it. */
    108                 if( reply )
     103                        reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
     104                        pack = 0;
     105                }
     106        }
     107        else if( strcmp( type, "set" ) == 0 )
     108        {
     109                xt_free_node( reply );
     110                reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
     111                pack = 0;
     112        }
     113       
     114        /* If we recognized the xmlns and managed to generate a reply,
     115           finish and send it. */
     116        if( reply )
     117        {
     118                /* Normally we still have to pack it into an iq-result
     119                   packet, but for errors, for example, we don't. */
     120                if( pack )
    109121                {
    110122                        reply = jabber_make_packet( "iq", "result", xt_find_attr( node, "from" ), reply );
    111123                        if( ( s = xt_find_attr( node, "id" ) ) )
    112124                                xt_add_attr( reply, "id", s );
    113                        
    114                         st = jabber_write_packet( gc, reply );
    115                         xt_free_node( reply );
    116                         if( !st )
    117                                 return XT_ABORT;
    118                 }
     125                }
     126               
     127                st = jabber_write_packet( gc, reply );
     128                xt_free_node( reply );
     129                if( !st )
     130                        return XT_ABORT;
    119131        }
    120132       
  • protocols/jabber/jabber.h

    rb56b220 r259edd4  
    127127char *set_eval_tls( set_t *set, char *value );
    128128struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children );
     129struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type );
    129130void jabber_cache_add( struct gaim_connection *gc, struct xt_node *node, jabber_cache_event func );
    130131struct xt_node *jabber_cache_get( struct gaim_connection *gc, char *id );
  • protocols/jabber/jabber_util.c

    rb56b220 r259edd4  
    7979}
    8080
    81 /* Cache a node/packet for later use. Mainly useful for IQ packets if you need
     81struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type )
     82{
     83        struct xt_node *node, *c;
     84        char *to;
     85       
     86        /* Create the "defined-condition" tag. */
     87        c = xt_new_node( err_cond, NULL, NULL );
     88        xt_add_attr( c, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas" );
     89       
     90        /* Put it in an <error> tag. */
     91        c = xt_new_node( "error", NULL, c );
     92        xt_add_attr( c, "type", err_type );
     93       
     94        /* To make the actual error packet, we copy the original packet and
     95           add our <error>/type="error" tag. Including the original packet
     96           is recommended, so let's just do it. */
     97        node = xt_dup( orig );
     98        xt_add_child( node, c );
     99        xt_add_attr( node, "type", "error" );
     100       
     101        /* Return to sender. */
     102        if( ( to = xt_find_attr( node, "from" ) ) )
     103        {
     104                xt_add_attr( node, "to", to );
     105                xt_remove_attr( node, "from" );
     106        }
     107               
     108        return node;
     109}
     110
     111/* Cache a node/epacket for later use. Mainly useful for IQ packets if you need
    82112   them when you receive the response. Use this BEFORE sending the packet so
    83113   it'll get an id= tag, and do NOT free() the packet after writing it! */
  • protocols/jabber/xmltree.c

    rb56b220 r259edd4  
    550550        node->attr[i].value = g_strdup( value );
    551551}
     552
     553int xt_remove_attr( struct xt_node *node, char *key )
     554{
     555        int i, last;
     556       
     557        for( i = 0; node->attr[i].key; i ++ )
     558                if( strcmp( node->attr[i].key, key ) == 0 )
     559                        break;
     560       
     561        /* If we didn't find the attribute... */
     562        if( node->attr[i].key == NULL )
     563                return 0;
     564       
     565        g_free( node->attr[i].key );
     566        g_free( node->attr[i].value );
     567       
     568        /* If it's the last, this is easy: */
     569        if( node->attr[i+1].key == NULL )
     570        {
     571                node->attr[i].key = node->attr[i].value = NULL;
     572        }
     573        else /* It's also pretty easy, actually. */
     574        {
     575                /* Find the last item. */
     576                for( last = i + 1; node->attr[last+1].key; last ++ );
     577               
     578                node->attr[i] = node->attr[last];
     579                node->attr[last].key = NULL;
     580                node->attr[last].value = NULL;
     581        }
     582       
     583        /* Let's not bother with reallocating memory here. It takes time and
     584           most packets don't stay in memory for long anyway. */
     585       
     586        return 1;
     587}
  • protocols/jabber/xmltree.h

    rb56b220 r259edd4  
    9393void xt_add_child( struct xt_node *parent, struct xt_node *child );
    9494void xt_add_attr( struct xt_node *node, char *key, char *value );
     95int xt_remove_attr( struct xt_node *node, char *key );
    9596
    9697#endif
Note: See TracChangeset for help on using the changeset viewer.