Changeset dfa41a4


Ignore:
Timestamp:
2006-10-20T19:12:14Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
3b3cd693
Parents:
f920d9e
Message:

Now all IQ packets get an ID and cached packets get a "special" ID. This
makes it easier to find out if an event handler has to be called for a
reply packet.

Location:
protocols/jabber
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    rf920d9e rdfa41a4  
    4545                struct jabber_cache_entry *entry;
    4646               
    47                 if( ( s = xt_find_attr( node, "id" ) ) == NULL )
    48                 {
    49                         /* Silently ignore it, without an ID we don't know
    50                            how to handle the packet, but it doesn't have
    51                            to be a serious problem. */
     47                if( ( s = xt_find_attr( node, "id" ) ) == NULL ||
     48                    strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )
     49                {
     50                        /* Silently ignore it, without an ID (or an non-cache
     51                           ID) we don't know how to handle the packet and we
     52                           probably don't have to. */
    5253                        return XT_HANDLED;
    5354                }
     
    6566                    !( s = xt_find_attr( c, "xmlns" ) ) )
    6667                {
    67                         serv_got_crap( gc, "WARNING: Received incomplete IQ-get packet" );
     68                        serv_got_crap( gc, "WARNING: Received incomplete IQ-%s packet", type );
    6869                        return XT_HANDLED;
    6970                }
     
    125126        else if( strcmp( type, "set" ) == 0 )
    126127        {
    127                 xt_free_node( reply );
    128                 reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
    129                 pack = 0;
     128                if( !( c = xt_find_node( node->children, "query" ) ) ||
     129                    !( s = xt_find_attr( c, "xmlns" ) ) )
     130                {
     131                        serv_got_crap( gc, "WARNING: Received incomplete IQ-%s packet", type );
     132                        return XT_HANDLED;
     133                }
     134               
     135                if( strcmp( s, "jabber:iq:roster" ) == 0 )
     136                {
     137                        /* This is a roster push packet, probably. Here we
     138                           should check if the packet is legitimate by
     139                           checking if it really comes from the user's JID
     140                           and, if so, process it. */
     141                }
     142                else
     143                {
     144                        xt_free_node( reply );
     145                        reply = jabber_make_error_packet( node, "feature-not-implemented", "cancel" );
     146                        pack = 0;
     147                }
    130148        }
    131149       
  • protocols/jabber/jabber.h

    rf920d9e rdfa41a4  
    102102       
    103103        time_t last_act;
    104         int flags;
     104        jabber_buddy_flag_t flags;
    105105       
    106106        struct jabber_buddy *next;
    107107};
     108
     109/* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the
     110   first one should be used, but when storing a packet in the cache, a
     111   "special" kind of ID is assigned to make it easier later to figure out
     112   if we have to do call an event handler for the response packet. */
     113#define JABBER_PACKET_ID "BeeP"
     114#define JABBER_CACHED_ID "BeeC"
    108115
    109116/* iq.c */
  • protocols/jabber/jabber_util.c

    rf920d9e rdfa41a4  
    2424#include "jabber.h"
    2525
    26 static int next_id = 1;
     26static unsigned int next_id = 1;
    2727
    2828char *set_eval_priority( set_t *set, char *value )
     
    8383                xt_add_attr( node, "to", to );
    8484       
     85        /* IQ packets should always have an ID, so let's generate one. It
     86           might get overwritten by jabber_cache_add() if this packet has
     87           to be saved until we receive a response. Cached packets get
     88           slightly different IDs so we can recognize them. */
     89        if( strcmp( name, "iq" ) == 0 )
     90        {
     91                char *id = g_strdup_printf( "%s%05x", JABBER_PACKET_ID, ( next_id++ ) & 0xfffff );
     92                xt_add_attr( node, "id", id );
     93                g_free( id );
     94        }
     95       
    8596        return node;
    8697}
     
    116127}
    117128
    118 /* Cache a node/epacket for later use. Mainly useful for IQ packets if you need
     129/* Cache a node/packet for later use. Mainly useful for IQ packets if you need
    119130   them when you receive the response. Use this BEFORE sending the packet so
    120    it'll get an id= tag, and do NOT free() the packet after writing it! */
     131   it'll get a new id= tag, and do NOT free() the packet after writing it! */
    121132void jabber_cache_add( struct gaim_connection *gc, struct xt_node *node, jabber_cache_event func )
    122133{
    123134        struct jabber_data *jd = gc->proto_data;
    124         char *id = g_strdup_printf( "BeeX%04x", next_id++ );
     135        char *id = g_strdup_printf( "%s%05x", JABBER_CACHED_ID, ( next_id++ ) & 0xfffff );
    125136        struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 );
    126137       
Note: See TracChangeset for help on using the changeset viewer.