Changeset 4eb4c0f for protocols/jabber


Ignore:
Timestamp:
2008-02-16T17:15:31Z (17 years ago)
Author:
Sven Moritz Hallberg <sm@…>
Branches:
master
Children:
fd9fa52
Parents:
8961950 (diff), ca60550 (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:

merge in upstream changes

Location:
protocols/jabber
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/Makefile

    r8961950 r4eb4c0f  
    1818all: jabber_mod.o
    1919check: all
    20 lcov:
     20lcov: check
    2121gcov:
    2222        gcov *.c
  • protocols/jabber/conference.c

    r8961950 r4eb4c0f  
    3737        xt_add_attr( node, "xmlns", XMLNS_MUC );
    3838        node = jabber_make_packet( "presence", NULL, roomjid, node );
     39        if( password )
     40                xt_add_child( node, xt_new_node( "password", password, NULL ) );
    3941        jabber_cache_add( ic, node, jabber_chat_join_failed );
    4042       
     
    122124        struct jabber_chat *jc = c->data;
    123125        struct xt_node *node;
     126       
     127        jc->flags |= JCFLAG_MESSAGE_SENT;
    124128       
    125129        node = xt_new_node( "body", message, NULL );
     
    295299        struct xt_node *subject = xt_find_node( node->children, "subject" );
    296300        struct xt_node *body = xt_find_node( node->children, "body" );
    297         struct groupchat *chat = NULL;
     301        struct groupchat *chat = bud ? jabber_chat_by_jid( ic, bud->bare_jid ) : NULL;
     302        struct jabber_chat *jc = chat ? chat->data : NULL;
    298303        char *s;
    299304       
    300         if( bud == NULL )
     305        if( bud == NULL || ( jc && ~jc->flags & JCFLAG_MESSAGE_SENT && bud == jc->me ) )
    301306        {
    302307                char *nick;
     
    346351                return;
    347352        }
    348         else if( ( chat = jabber_chat_by_jid( ic, bud->bare_jid ) ) == NULL )
     353        else if( chat == NULL )
    349354        {
    350355                /* How could this happen?? We could do kill( self, 11 )
  • protocols/jabber/iq.c

    r8961950 r4eb4c0f  
    9292                else if( strcmp( s, XMLNS_DISCOVER ) == 0 )
    9393                {
    94                         const char *features[] = { XMLNS_VERSION,
     94                        const char *features[] = { XMLNS_DISCOVER,
     95                                                   XMLNS_VERSION,
    9596                                                   XMLNS_TIME,
    9697                                                   XMLNS_CHATSTATES,
  • protocols/jabber/jabber.h

    r8961950 r4eb4c0f  
    4949typedef enum
    5050{
    51         JBFLAG_PROBED_XEP85 = 1,        /* Set this when we sent our probe packet to make
     51        JBFLAG_PROBED_XEP85 = 1,        /* Set this when we sent our probe packet to make
    5252                                           sure it gets sent only once. */
    53         JBFLAG_DOES_XEP85 = 2,          /* Set this when the resource seems to support
     53        JBFLAG_DOES_XEP85 = 2,          /* Set this when the resource seems to support
    5454                                           XEP85 (typing notification shite). */
    55         JBFLAG_IS_CHATROOM = 4,         /* It's convenient to use this JID thingy for
     55        JBFLAG_IS_CHATROOM = 4,         /* It's convenient to use this JID thingy for
    5656                                           groupchat state info too. */
    57         JBFLAG_IS_ANONYMOUS = 8,        /* For anonymous chatrooms, when we don't have
     57        JBFLAG_IS_ANONYMOUS = 8,        /* For anonymous chatrooms, when we don't have
    5858                                           have a real JID. */
    5959} jabber_buddy_flags_t;
     60
     61typedef enum
     62{
     63        JCFLAG_MESSAGE_SENT = 1,        /* Set this after sending the first message, so
     64                                           we can detect echoes/backlogs. */
     65} jabber_chat_flags_t;
    6066
    6167struct jabber_data
     
    95101struct jabber_cache_entry
    96102{
     103        time_t saved_at;
    97104        struct xt_node *node;
    98105        jabber_cache_event func;
     
    140147#define JABBER_PACKET_ID "BeeP"
    141148#define JABBER_CACHED_ID "BeeC"
     149
     150/* The number of seconds to keep cached packets before garbage collecting
     151   them. This gc is done on every keepalive (every minute). */
     152#define JABBER_CACHE_MAX_AGE 600
    142153
    143154/* RFC 392[01] stuff */
     
    161172#define XMLNS_MUC          "http://jabber.org/protocol/muc"     /* XEP-0045 */
    162173#define XMLNS_MUC_USER     "http://jabber.org/protocol/muc#user"/* XEP-0045 */
     174#define XMLNS_CAPS         "http://jabber.org/protocol/caps"    /* XEP-0115 */
    163175
    164176/* iq.c */
  • protocols/jabber/jabber_util.c

    r8961950 r4eb4c0f  
    142142        entry->node = node;
    143143        entry->func = func;
     144        entry->saved_at = time( NULL );
    144145        g_hash_table_insert( jd->node_cache, xt_find_attr( node, "id" ), entry );
    145146}
     
    163164{
    164165        struct jabber_data *jd = ic->proto_data;
    165        
    166         g_hash_table_foreach_remove( jd->node_cache, jabber_cache_clean_entry, NULL );
    167 }
    168 
    169 gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer nullpointer )
     166        time_t threshold = time( NULL ) - JABBER_CACHE_MAX_AGE;
     167       
     168        g_hash_table_foreach_remove( jd->node_cache, jabber_cache_clean_entry, &threshold );
     169}
     170
     171gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer threshold_ )
    170172{
    171173        struct jabber_cache_entry *entry = entry_;
    172         struct xt_node *node = entry->node;
    173        
    174         if( node->flags & XT_SEEN )
    175                 return TRUE;
    176         else
    177         {
    178                 node->flags |= XT_SEEN;
    179                 return FALSE;
    180         }
     174        time_t *threshold = threshold_;
     175       
     176        return entry->saved_at < *threshold;
    181177}
    182178
  • protocols/jabber/presence.c

    r8961950 r4eb4c0f  
    2929        char *from = xt_find_attr( node, "from" );
    3030        char *type = xt_find_attr( node, "type" );      /* NULL should mean the person is online. */
    31         struct xt_node *c;
     31        struct xt_node *c, *cap;
    3232        struct jabber_buddy *bud, *send_presence = NULL;
    3333        int is_chat = 0;
     
    7676                else
    7777                        bud->priority = 0;
     78               
     79                if( bud && ( cap = xt_find_node( node->children, "c" ) ) &&
     80                    ( s = xt_find_attr( cap, "xmlns" ) ) && strcmp( s, XMLNS_CAPS ) == 0 )
     81                {
     82                        /* This <presence> stanza includes an XEP-0115
     83                           capabilities part. Not too interesting, but we can
     84                           see if it has an ext= attribute. */
     85                        s = xt_find_attr( cap, "ext" );
     86                        if( s && ( strstr( s, "cstates" ) || strstr( s, "chatstate" ) ) )
     87                                bud->flags |= JBFLAG_DOES_XEP85;
     88                       
     89                        /* This field can contain more information like xhtml
     90                           support, but we don't support that ourselves.
     91                           Officially the ext= tag was deprecated, but enough
     92                           clients do send it.
     93                           
     94                           (I'm aware that this is not the right way to use
     95                           this field.) See for an explanation of ext=:
     96                           http://www.xmpp.org/extensions/attic/xep-0115-1.3.html*/
     97                }
    7898               
    7999                if( is_chat )
     
    186206{
    187207        struct jabber_data *jd = ic->proto_data;
    188         struct xt_node *node;
     208        struct xt_node *node, *cap;
    189209        char *show = jd->away_state->code;
    190210        char *status = jd->away_message;
     
    199219                xt_add_child( node, xt_new_node( "status", status, NULL ) );
    200220       
     221        /* This makes the packet slightly bigger, but clients interested in
     222           capabilities can now cache the discovery info. This reduces the
     223           usual post-login iq-flood. See XEP-0115. At least libpurple and
     224           Trillian seem to do this right. */
     225        cap = xt_new_node( "c", NULL, NULL );
     226        xt_add_attr( cap, "xmlns", XMLNS_CAPS );
     227        xt_add_attr( cap, "node", "http://bitlbee.org/xmpp/caps" );
     228        xt_add_attr( cap, "ver", BITLBEE_VERSION ); /* The XEP wants this hashed, but nobody's doing that. */
     229        xt_add_child( node, cap );
     230       
    201231        st = jabber_write_packet( ic, node );
    202232       
  • protocols/jabber/sasl.c

    r8961950 r4eb4c0f  
    2121*                                                                           *
    2222\***************************************************************************/
     23
     24#include <ctype.h>
    2325
    2426#include "jabber.h"
     
    107109}
    108110
    109 static char *sasl_get_part( char *data, char *field )
     111/* Non-static function, but not mentioned in jabber.h because it's for internal
     112   use, just that the unittest should be able to reach it... */
     113char *sasl_get_part( char *data, char *field )
    110114{
    111115        int i, len;
    112116       
    113117        len = strlen( field );
     118       
     119        while( isspace( *data ) || *data == ',' )
     120                data ++;
    114121       
    115122        if( g_strncasecmp( data, field, len ) == 0 && data[len] == '=' )
     
    129136                        }
    130137                       
    131                         /* If we got a comma, we got a new field. Check it. */
    132                         if( data[i] == ',' &&
    133                             g_strncasecmp( data + i + 1, field, len ) == 0 &&
    134                             data[i+len+1] == '=' )
     138                        /* If we got a comma, we got a new field. Check it,
     139                           find the next key after it. */
     140                        if( data[i] == ',' )
    135141                        {
    136                                 i += len + 2;
    137                                 break;
     142                                while( isspace( data[i] ) || data[i] == ',' )
     143                                        i ++;
     144                               
     145                                if( g_strncasecmp( data + i, field, len ) == 0 &&
     146                                    data[i+len] == '=' )
     147                                {
     148                                        i += len + 1;
     149                                        break;
     150                                }
    138151                        }
    139152                }
Note: See TracChangeset for help on using the changeset viewer.