Changeset 6738a67 for protocols/jabber


Ignore:
Timestamp:
2008-07-16T23:22:52Z (17 years ago)
Author:
Sven Moritz Hallberg <pesco@…>
Branches:
master
Children:
9b55485
Parents:
9730d72 (diff), 6a78c0e (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 latest trunk

Location:
protocols/jabber
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/Makefile

    r9730d72 r6738a67  
    1010
    1111# [SH] Program variables
    12 objects = conference.o io.o iq.o jabber.o jabber_util.o message.o presence.o sasl.o xmltree.o
     12objects = conference.o io.o iq.o jabber.o jabber_util.o message.o presence.o sasl.o
    1313
    1414CFLAGS += -Wall
  • protocols/jabber/io.c

    r9730d72 r6738a67  
    241241        }
    242242       
    243         /* EAGAIN/etc or a successful read. */
    244         return TRUE;
     243        if( ssl_pending( jd->ssl ) )
     244                /* OpenSSL empties the TCP buffers completely but may keep some
     245                   data in its internap buffers. select() won't see that, but
     246                   ssl_pending() does. */
     247                return jabber_read_callback( data, fd, cond );
     248        else
     249                return TRUE;
    245250}
    246251
     
    521526           from the server too. */
    522527        xt_free( jd->xt );      /* In case we're RE-starting. */
    523         jd->xt = xt_new( ic );
    524         jd->xt->handlers = (struct xt_handler_entry*) jabber_handlers;
     528        jd->xt = xt_new( jabber_handlers, ic );
    525529       
    526530        if( jd->r_inpa <= 0 )
  • protocols/jabber/jabber.c

    r9730d72 r6738a67  
    3333#include "jabber.h"
    3434#include "md5.h"
    35 #include "base64.h"
    3635
    3736GSList *jabber_connections;
    3837
     38/* First enty is the default */
     39static const int jabber_port_list[] = {
     40        5222,
     41        5223,
     42        5220,
     43        5221,
     44        5224,
     45        5225,
     46        5226,
     47        5227,
     48        5228,
     49        5229,
     50        80,
     51        443,
     52        0
     53};
     54
    3955static void jabber_init( account_t *acc )
    4056{
    4157        set_t *s;
    42        
    43         s = set_add( &acc->set, "port", JABBER_PORT_DEFAULT, set_eval_int, acc );
     58        char str[16];
     59       
     60        g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] );
     61        s = set_add( &acc->set, "port", str, set_eval_int, acc );
    4462        s->flags |= ACC_SET_OFFLINE_ONLY;
    4563       
     
    7290        struct ns_srv_reply *srv = NULL;
    7391        char *connect_to, *s;
     92        int i;
    7493       
    7594        /* For now this is needed in the _connected() handlers if using
     
    177196        imcb_log( ic, "Connecting" );
    178197       
    179         if( set_getint( &acc->set, "port" ) < JABBER_PORT_MIN ||
    180             set_getint( &acc->set, "port" ) > JABBER_PORT_MAX )
    181         {
    182                 imcb_log( ic, "Incorrect port number, must be in the %d-%d range",
    183                                JABBER_PORT_MIN, JABBER_PORT_MAX );
     198        for( i = 0; jabber_port_list[i] > 0; i ++ )
     199                if( set_getint( &acc->set, "port" ) == jabber_port_list[i] )
     200                        break;
     201
     202        if( jabber_port_list[i] == 0 )
     203        {
     204                imcb_log( ic, "Illegal port number" );
    184205                imc_logout( ic, FALSE );
    185206                return;
     
    219240}
    220241
     242/* This generates an unfinished md5_state_t variable. Every time we generate
     243   an ID, we finish the state by adding a sequence number and take the hash. */
    221244static void jabber_generate_id_hash( struct jabber_data *jd )
    222245{
    223         md5_state_t id_hash;
    224         md5_byte_t binbuf[16];
     246        md5_byte_t binbuf[4];
    225247        char *s;
    226248       
    227         md5_init( &id_hash );
    228         md5_append( &id_hash, (unsigned char *) jd->username, strlen( jd->username ) );
    229         md5_append( &id_hash, (unsigned char *) jd->server, strlen( jd->server ) );
     249        md5_init( &jd->cached_id_prefix );
     250        md5_append( &jd->cached_id_prefix, (unsigned char *) jd->username, strlen( jd->username ) );
     251        md5_append( &jd->cached_id_prefix, (unsigned char *) jd->server, strlen( jd->server ) );
    230252        s = set_getstr( &jd->ic->acc->set, "resource" );
    231         md5_append( &id_hash, (unsigned char *) s, strlen( s ) );
    232         random_bytes( binbuf, 16 );
    233         md5_append( &id_hash, binbuf, 16 );
    234         md5_finish( &id_hash, binbuf );
    235        
    236         s = base64_encode( binbuf, 9 );
    237         jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s );
    238         g_free( s );
     253        md5_append( &jd->cached_id_prefix, (unsigned char *) s, strlen( s ) );
     254        random_bytes( binbuf, 4 );
     255        md5_append( &jd->cached_id_prefix, binbuf, 4 );
    239256}
    240257
  • protocols/jabber/jabber.h

    r9730d72 r6738a67  
    8686        char *away_message;
    8787       
    88         char *cached_id_prefix;
     88        md5_state_t cached_id_prefix;
    8989        GHashTable *node_cache;
    9090        GHashTable *buddies;
     
    134134
    135135#define JABBER_XMLCONSOLE_HANDLE "xmlconsole"
    136 
    137 #define JABBER_PORT_DEFAULT "5222"
    138 #define JABBER_PORT_MIN 5220
    139 #define JABBER_PORT_MAX 5229
    140136
    141137/* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the
  • protocols/jabber/jabber_util.c

    r9730d72 r6738a67  
    2323
    2424#include "jabber.h"
     25#include "md5.h"
     26#include "base64.h"
    2527
    2628static unsigned int next_id = 1;
     
    134136        struct jabber_data *jd = ic->proto_data;
    135137        struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 );
    136         char *id;
    137        
    138         id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff );
     138        md5_state_t id_hash;
     139        md5_byte_t id_sum[16];
     140        char *id, *asc_hash;
     141       
     142        next_id ++;
     143       
     144        id_hash = jd->cached_id_prefix;
     145        md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) );
     146        md5_finish( &id_hash, id_sum );
     147        asc_hash = base64_encode( id_sum, 12 );
     148       
     149        id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash );
    139150        xt_add_attr( node, "id", id );
    140151        g_free( id );
     152        g_free( asc_hash );
    141153       
    142154        entry->node = node;
     
    184196       
    185197        if( ( s = xt_find_attr( node, "id" ) ) == NULL ||
    186             strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 )
     198            strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )
    187199        {
    188200                /* Silently ignore it, without an ID (or a non-cache
     
    196208        if( entry == NULL )
    197209        {
     210                /*
     211                There's no longer an easy way to see if we generated this
     212                one or someone else, and there's a ten-minute timeout anyway,
     213                so meh.
     214               
    198215                imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!",
    199216                              node->name, xt_find_attr( node, "type" ) ? : "(no type)", s );
     217                */
    200218        }
    201219        else if( entry->func )
     
    246264};
    247265
    248 static void jabber_buddy_ask_yes( gpointer w, struct jabber_buddy_ask_data *bla )
    249 {
     266static void jabber_buddy_ask_yes( void *data )
     267{
     268        struct jabber_buddy_ask_data *bla = data;
     269       
    250270        presence_send_request( bla->ic, bla->handle, "subscribed" );
    251271       
     
    257277}
    258278
    259 static void jabber_buddy_ask_no( gpointer w, struct jabber_buddy_ask_data *bla )
    260 {
     279static void jabber_buddy_ask_no( void *data )
     280{
     281        struct jabber_buddy_ask_data *bla = data;
     282       
    261283        presence_send_request( bla->ic, bla->handle, "subscribed" );
    262284       
     
    286308        len = strlen( orig );
    287309        new = g_new( char, len + 1 );
    288         for( i = 0; i < len; i ++ )
     310       
     311        /* So it turns out the /resource part is case sensitive. Yeah, and
     312           it's Unicode but feck Unicode. :-P So stop once we see a slash. */
     313        for( i = 0; i < len && orig[i] != '/' ; i ++ )
    289314                new[i] = tolower( orig[i] );
     315        for( ; orig[i]; i ++ )
     316                new[i] = orig[i];
    290317       
    291318        new[i] = 0;
     
    330357                {
    331358                        /* Check for dupes. */
    332                         if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     359                        if( strcmp( bi->resource, s + 1 ) == 0 )
    333360                        {
    334361                                *s = '/';
     
    383410        if( ( s = strchr( jid, '/' ) ) )
    384411        {
    385                 int none_found = 0;
     412                int bare_exists = 0;
    386413               
    387414                *s = 0;
     
    406433                        /* See if there's an exact match. */
    407434                        for( ; bud; bud = bud->next )
    408                                 if( g_strcasecmp( bud->resource, s + 1 ) == 0 )
     435                                if( strcmp( bud->resource, s + 1 ) == 0 )
    409436                                        break;
    410437                }
    411438                else
    412439                {
    413                         /* This hack is there to make sure that O_CREAT will
    414                            work if there's already another resouce present
    415                            for this JID, even if it's an unknown buddy. This
    416                            is done to handle conferences properly. */
    417                         none_found = 1;
    418                         /* TODO(wilmer): Find out what I was thinking when I
    419                            wrote this??? And then fix it. This makes me sad... */
    420                 }
    421                
    422                 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) )
     440                        /* This variable tells the if down here that the bare
     441                           JID already exists and we should feel free to add
     442                           more resources, if the caller asked for that. */
     443                        bare_exists = 1;
     444                }
     445               
     446                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
     447                    ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
    423448                {
    424449                        *s = '/';
     
    445470                        /* We want an exact match, so in thise case there shouldn't be a /resource. */
    446471                        return NULL;
    447                 else if( ( bud->resource == NULL || bud->next == NULL ) )
     472                else if( bud->resource == NULL || bud->next == NULL )
    448473                        /* No need for selection if there's only one option. */
    449474                        return bud;
     
    521546                   matches), removing it is simple. (And the hash reference
    522547                   should be removed too!) */
    523                 if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) )
     548                if( bud->next == NULL &&
     549                    ( ( s == NULL && bud->resource == NULL ) ||
     550                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    524551                {
    525552                        g_hash_table_remove( jd->buddies, bud->bare_jid );
     
    544571                {
    545572                        for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next )
    546                                 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     573                                if( strcmp( bi->resource, s + 1 ) == 0 )
    547574                                        break;
    548575                       
  • protocols/jabber/message.c

    r9730d72 r6738a67  
    4949        {
    5050                GString *fullmsg = g_string_new( "" );
     51
     52                for( c = node->children; ( c = xt_find_node( c, "x" ) ); c = c->next )
     53                {
     54                        char *ns = xt_find_attr( c, "xmlns" ), *room;
     55                        struct xt_node *inv, *reason;
     56                       
     57                        if( strcmp( ns, XMLNS_MUC_USER ) == 0 &&
     58                            ( inv = xt_find_node( c->children, "invite" ) ) )
     59                        {
     60                                room = from;
     61                                from = xt_find_attr( inv, "from" ) ? : from;
     62
     63                                g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Invitation to chatroom %s >>\n", room );
     64                                if( ( reason = xt_find_node( inv->children, "reason" ) ) && reason->text_len > 0 )
     65                                        g_string_append( fullmsg, reason->text );
     66                        }
     67                }
    5168               
    5269                if( ( s = strchr( from, '/' ) ) )
Note: See TracChangeset for help on using the changeset viewer.