Changeset eda54e4


Ignore:
Timestamp:
2007-10-12T00:08:58Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a6df0b5
Parents:
82135c7 (diff), d444c09 (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 from devel.

Files:
1 added
20 edited
2 moved

Legend:

Unmodified
Added
Removed
  • Makefile

    r82135c7 reda54e4  
    1111# Program variables
    1212objects = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o
    13 headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ini.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h url.h user.h protocols/http_client.h protocols/md5.h protocols/nogaim.h protocols/proxy.h protocols/sha.h protocols/ssl_client.h
     13headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha.h lib/ssl_client.h lib/url.h protocols/nogaim.h
    1414subdirs = lib protocols
    1515
  • configure

    r82135c7 reda54e4  
    2929strip=1
    3030gcov=0
     31plugins=1
    3132ipv6=1
    3233
     
    6970--strip=0/1     Disable/enable binary stripping         $strip
    7071--gcov=0/1      Disable/enable test coverage reporting  $gcov
     72--plugins=0/1   Disable/enable plugins support          $plugins
    7173
    7274--ipv6=0/1      IPv6 socket support                     $ipv6
    73 
    74 --ldap=0/1/auto LDAP support                            $ldap
    7575
    7676--events=...    Event handler (glib, libevent)          $events
     
    140140
    141141if [ "$debug" = "1" ]; then
    142         echo 'CFLAGS=-g' >> Makefile.settings
     142        [ -z "$CFLAGS" ] && CFLAGS=-g
    143143        echo 'DEBUG=1' >> Makefile.settings
    144144        echo '#define DEBUG' >> config.h
    145145else
    146         echo 'CFLAGS=-O3' >> Makefile.settings
    147 fi
    148 
     146        [ -z "$CFLAGS" ] && CFLAGS=-O3
     147fi
     148
     149echo CFLAGS=$CFLAGS >> Makefile.settings
    149150echo CFLAGS+=-I`pwd` -I`pwd`/lib -I`pwd`/protocols -I. >> Makefile.settings
    150151
     
    385386fi
    386387
     388if [ "$plugins" = 0 ]; then
     389        echo '#undef WITH_PLUGINS' >> config.h
     390else
     391        echo '#define WITH_PLUGINS' >> config.h
     392fi
     393
    387394echo
    388395if [ -z "$BITLBEE_VERSION" -a -d .bzr ] && type bzr > /dev/null 2> /dev/null; then
  • doc/CHANGES

    r82135c7 reda54e4  
    1 Version 1.1dev:
     1Version 1.2:
    22- First BitlBee development/testing RELEASE. This should be quite stable
    33  though (and for most people more stable than 1.0.x). It just has a couple
     
    6565    resources available for that buddy. (Of course this only works if the
    6666    buddy is in your contact list.)
     67
     68Finished ???
     69
     70Version 1.0.4:
     71- Removed sethostent(), which causes problems for many people, especially on
     72  *BSD. This is basically the reason for this release.
     73- "allow" command actually displays the allow list, not the block list.
     74- Yahoo away state/msg fix.
     75- Don't display "Gender: Male" by default if nothing's filled in (OSCAR
     76  "info" command)
     77- Fixed account cleanup (possible infinite loop) in irc_free().
     78- Fixed configdir error message to not always display the compile-time
     79  setting.
     80
     81Finished 20 Aug 2007
    6782
    6883Version 1.0.3:
  • doc/user-guide/commands.xml

    r82135c7 reda54e4  
    596596        </bitlbee-setting>
    597597
     598        <bitlbee-setting name="simulate_netsplit" type="boolean" scope="global">
     599                <default>true</default>
     600
     601                <description>
     602                        <para>
     603                                Some IRC clients parse quit messages sent by the IRC server to see if someone really left or just disappeared because of a netsplit. By default, BitlBee tries to simulate netsplit-like quit messages to keep the control channel window clean. If you don't like this (or if your IRC client doesn't support this) you can disable this setting.
     604                        </para>
     605                </description>
     606        </bitlbee-setting>
     607
    598608        <bitlbee-setting name="ssl" type="boolean" scope="account">
    599609                <default>false</default>
  • irc.c

    r82135c7 reda54e4  
    132132        set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
    133133        set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
    134         set_add( &irc->set, "charset", "iso8859-1", set_eval_charset, irc );
     134        set_add( &irc->set, "charset", "utf-8", set_eval_charset, irc );
    135135        set_add( &irc->set, "debug", "false", set_eval_bool, irc );
    136136        set_add( &irc->set, "default_target", "root", NULL, irc );
     
    143143        set_add( &irc->set, "query_order", "lifo", NULL, irc );
    144144        set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc );
     145        set_add( &irc->set, "simulate_netsplit", "true", set_eval_bool, irc );
    145146        set_add( &irc->set, "strip_html", "true", NULL, irc );
    146147        set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
     
    910911        char reason[128];
    911912       
    912         if( u->ic && u->ic->flags & OPT_LOGGING_OUT )
     913        if( u->ic && u->ic->flags & OPT_LOGGING_OUT && set_getbool( &irc->set, "simulate_netsplit" ) )
    913914        {
    914915                if( u->ic->acc->server )
  • lib/Makefile

    r82135c7 reda54e4  
    1010
    1111# [SH] Program variables
    12 objects = base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o rc4.o sha.o $(SSL_CLIENT) url.o
     12objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o sha.o $(SSL_CLIENT) url.o
    1313
    1414CFLAGS += -Wall
  • lib/arc.c

    r82135c7 reda54e4  
    22*                                                                           *
    33*  BitlBee - An IRC to IM gateway                                           *
    4 *  Simple (but secure) RC4 implementation for safer password storage.       *
     4*  Simple (but secure) ArcFour implementation for safer password storage.   *
    55*                                                                           *
    66*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
     
    2323
    2424/*
    25    This file implements RC4-encryption, which will mainly be used to save IM
    26    passwords safely in the new XML-format. Possibly other uses will come up
    27    later. It's supposed to be quite reliable (thanks to the use of a 6-byte
    28    IV/seed), certainly compared to the old format. The only realistic way to
    29    crack BitlBee passwords now is to use a sniffer to get your hands on the
    30    user's password.
     25   This file implements ArcFour-encryption, which will mainly be used to
     26   save IM passwords safely in the new XML-format. Possibly other uses will
     27   come up later. It's supposed to be quite reliable (thanks to the use of a
     28   6-byte IV/seed), certainly compared to the old format. The only realistic
     29   way to crack BitlBee passwords now is to use a sniffer to get your hands
     30   on the user's password.
    3131   
    3232   If you see that something's wrong in this implementation (I asked a
    3333   couple of people to look at it already, but who knows), please tell me.
    3434   
    35    The reason I chose for RC4 is because it's pretty simple but effective,
     35   The reason I picked ArcFour is because it's pretty simple but effective,
    3636   so it will work without adding several KBs or an extra library dependency.
     37   
     38   (ArcFour is an RC4-compatible cipher. See for details:
     39   http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt)
    3740*/
    3841
     
    4346#include <string.h>
    4447#include "misc.h"
    45 #include "rc4.h"
     48#include "arc.h"
    4649
    4750/* Add some seed to the password, to make sure we *never* use the same key.
    4851   This defines how many bytes we use as a seed. */
    49 #define RC4_IV_LEN 6
     52#define ARC_IV_LEN 6
    5053
    5154/* To defend against a "Fluhrer, Mantin and Shamir attack", it is recommended
    5255   to shuffle S[] just a bit more before you start to use it. This defines how
    5356   many bytes we'll request before we'll really use them for encryption. */
    54 #define RC4_CYCLES 1024
    55 
    56 struct rc4_state *rc4_keymaker( unsigned char *key, int kl, int cycles )
    57 {
    58         struct rc4_state *st;
     57#define ARC_CYCLES 1024
     58
     59struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles )
     60{
     61        struct arc_state *st;
    5962        int i, j, tmp;
    60        
    61         st = g_malloc( sizeof( struct rc4_state ) );
     63        unsigned char S2[256];
     64       
     65        st = g_malloc( sizeof( struct arc_state ) );
    6266        st->i = st->j = 0;
    63         for( i = 0; i < 256; i ++ )
    64                 st->S[i] = i;
    65        
    6667        if( kl <= 0 )
    6768                kl = strlen( (char*) key );
    6869       
     70        for( i = 0; i < 256; i ++ )
     71        {
     72                st->S[i] = i;
     73                S2[i] = key[i%kl];
     74        }
     75       
    6976        for( i = j = 0; i < 256; i ++ )
    7077        {
    71                 j = ( j + st->S[i] + key[i%kl] ) & 0xff;
     78                j = ( j + st->S[i] + S2[i] ) & 0xff;
    7279                tmp = st->S[i];
    7380                st->S[i] = st->S[j];
     
    7582        }
    7683       
     84        memset( S2, 0, 256 );
     85        i = j = 0;
     86       
    7787        for( i = 0; i < cycles; i ++ )
    78                 rc4_getbyte( st );
     88                arc_getbyte( st );
    7989       
    8090        return st;
     
    8292
    8393/*
    84    For those who don't know, RC4 is basically an algorithm that generates a
    85    stream of bytes after you give it a key. Just get a byte from it and xor
    86    it with your cleartext. To decrypt, just give it the same key again and
    87    start xorring.
    88    
    89    The function above initializes the RC4 byte generator, the next function
    90    can be used to get bytes from the generator (and shuffle things a bit).
     94   For those who don't know, ArcFour is basically an algorithm that generates
     95   a stream of bytes after you give it a key. Just get a byte from it and
     96   xor it with your cleartext. To decrypt, just give it the same key again
     97   and start xorring.
     98   
     99   The function above initializes the byte generator, the next function can
     100   be used to get bytes from the generator (and shuffle things a bit).
    91101*/
    92102
    93 unsigned char rc4_getbyte( struct rc4_state *st )
     103unsigned char arc_getbyte( struct arc_state *st )
    94104{
    95105        unsigned char tmp;
     
    101111        st->S[st->i] = st->S[st->j];
    102112        st->S[st->j] = tmp;
    103        
    104         return st->S[(st->S[st->i] + st->S[st->j]) & 0xff];
     113        tmp = (st->S[st->i] + st->S[st->j]) & 0xff;
     114       
     115        return st->S[tmp];
    105116}
    106117
     
    108119   The following two functions can be used for reliable encryption and
    109120   decryption. Known plaintext attacks are prevented by adding some (6,
    110    by default) random bytes to the password before setting up the RC4
     121   by default) random bytes to the password before setting up the state
    111122   structures. These 6 bytes are also saved in the results, because of
    112    course we'll need them in rc4_decode().
     123   course we'll need them in arc_decode().
    113124   
    114125   Because the length of the resulting string is unknown to the caller,
     
    122133*/
    123134
    124 int rc4_encode( unsigned char *clear, int clear_len, unsigned char **crypt, char *password )
    125 {
    126         struct rc4_state *st;
     135int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password )
     136{
     137        struct arc_state *st;
    127138        unsigned char *key;
    128139        int key_len, i;
    129140       
    130         key_len = strlen( password ) + RC4_IV_LEN;
     141        key_len = strlen( password ) + ARC_IV_LEN;
    131142        if( clear_len <= 0 )
    132                 clear_len = strlen( (char*) clear );
     143                clear_len = strlen( clear );
    133144       
    134145        /* Prepare buffers and the key + IV */
    135         *crypt = g_malloc( clear_len + RC4_IV_LEN );
     146        *crypt = g_malloc( clear_len + ARC_IV_LEN );
    136147        key = g_malloc( key_len );
    137148        strcpy( (char*) key, password );
     
    139150        /* Add the salt. Save it for later (when decrypting) and, of course,
    140151           add it to the encryption key. */
    141         random_bytes( crypt[0], RC4_IV_LEN );
    142         memcpy( key + key_len - RC4_IV_LEN, crypt[0], RC4_IV_LEN );
     152        random_bytes( crypt[0], ARC_IV_LEN );
     153        memcpy( key + key_len - ARC_IV_LEN, crypt[0], ARC_IV_LEN );
    143154       
    144155        /* Generate the initial S[] from the IVed key. */
    145         st = rc4_keymaker( key, key_len, RC4_CYCLES );
     156        st = arc_keymaker( key, key_len, ARC_CYCLES );
    146157        g_free( key );
    147158       
    148159        for( i = 0; i < clear_len; i ++ )
    149                 crypt[0][i+RC4_IV_LEN] = clear[i] ^ rc4_getbyte( st );
     160                crypt[0][i+ARC_IV_LEN] = clear[i] ^ arc_getbyte( st );
    150161       
    151162        g_free( st );
    152163       
    153         return clear_len + RC4_IV_LEN;
    154 }
    155 
    156 int rc4_decode( unsigned char *crypt, int crypt_len, unsigned char **clear, char *password )
    157 {
    158         struct rc4_state *st;
     164        return clear_len + ARC_IV_LEN;
     165}
     166
     167int arc_decode( unsigned char *crypt, int crypt_len, char **clear, char *password )
     168{
     169        struct arc_state *st;
    159170        unsigned char *key;
    160171        int key_len, clear_len, i;
    161172       
    162         key_len = strlen( password ) + RC4_IV_LEN;
    163         clear_len = crypt_len - RC4_IV_LEN;
     173        key_len = strlen( password ) + ARC_IV_LEN;
     174        clear_len = crypt_len - ARC_IV_LEN;
    164175       
    165176        if( clear_len < 0 )
    166177        {
    167                 *clear = (unsigned char*) g_strdup( "" );
     178                *clear = g_strdup( "" );
    168179                return 0;
    169180        }
     
    173184        key = g_malloc( key_len );
    174185        strcpy( (char*) key, password );
    175         for( i = 0; i < RC4_IV_LEN; i ++ )
    176                 key[key_len-RC4_IV_LEN+i] = crypt[i];
     186        for( i = 0; i < ARC_IV_LEN; i ++ )
     187                key[key_len-ARC_IV_LEN+i] = crypt[i];
    177188       
    178189        /* Generate the initial S[] from the IVed key. */
    179         st = rc4_keymaker( key, key_len, RC4_CYCLES );
     190        st = arc_keymaker( key, key_len, ARC_CYCLES );
    180191        g_free( key );
    181192       
    182193        for( i = 0; i < clear_len; i ++ )
    183                 clear[0][i] = crypt[i+RC4_IV_LEN] ^ rc4_getbyte( st );
     194                clear[0][i] = crypt[i+ARC_IV_LEN] ^ arc_getbyte( st );
    184195        clear[0][i] = 0; /* Nice to have for plaintexts. */
    185196       
  • lib/arc.h

    r82135c7 reda54e4  
    22*                                                                           *
    33*  BitlBee - An IRC to IM gateway                                           *
    4 *  Simple (but secure) RC4 implementation for safer password storage.       *
     4*  Simple (but secure) ArcFour implementation for safer password storage.   *
    55*                                                                           *
    6 *  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
     6*  Copyright 2007 Wilmer van der Gaast <wilmer@gaast.net>                   *
    77*                                                                           *
    88*  This program is free software; you can redistribute it and/or modify     *
     
    2323
    2424
    25 /* See rc4.c for more information. */
     25/* See arc.c for more information. */
    2626
    27 struct rc4_state
     27struct arc_state
    2828{
    2929        unsigned char S[256];
     
    3131};
    3232
    33 struct rc4_state *rc4_keymaker( unsigned char *key, int kl, int cycles );
    34 unsigned char rc4_getbyte( struct rc4_state *st );
    35 int rc4_encode( unsigned char *clear, int clear_len, unsigned char **crypt, char *password );
    36 int rc4_decode( unsigned char *crypt, int crypt_len, unsigned char **clear, char *password );
     33struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles );
     34unsigned char arc_getbyte( struct arc_state *st );
     35int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password );
     36int arc_decode( unsigned char *crypt, int crypt_len, char **clear, char *password );
  • lib/base64.c

    r82135c7 reda54e4  
    3131char *tobase64(const char *text)
    3232{
    33         return base64_encode(text, strlen(text));
     33        return base64_encode((const unsigned char *)text, strlen(text));
    3434}
    3535
    36 char *base64_encode(const char *in, int len)
     36char *base64_encode(const unsigned char *in, int len)
    3737{
    3838        char *out;
  • lib/base64.h

    r82135c7 reda54e4  
    2727
    2828G_MODULE_EXPORT char *tobase64( const char *text );
    29 G_MODULE_EXPORT char *base64_encode( const char *in, int len );
     29G_MODULE_EXPORT char *base64_encode( const unsigned char *in, int len );
    3030G_MODULE_EXPORT int base64_encode_real( const unsigned char *in, int inlen, unsigned char *out, const char *b64digits );
    3131G_MODULE_EXPORT char *frombase64( const char *in );
  • lib/misc.c

    r82135c7 reda54e4  
    545545        return reply;
    546546}
     547
     548/* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */
     549char *word_wrap( char *msg, int line_len )
     550{
     551        GString *ret = g_string_sized_new( strlen( msg ) + 16 );
     552       
     553        while( strlen( msg ) > line_len )
     554        {
     555                int i;
     556               
     557                /* First try to find out if there's a newline already. Don't
     558                   want to add more splits than necessary. */
     559                for( i = line_len; i > 0 && msg[i] != '\n'; i -- );
     560                if( msg[i] == '\n' )
     561                {
     562                        g_string_append_len( ret, msg, i + 1 );
     563                        msg += i + 1;
     564                        continue;
     565                }
     566               
     567                for( i = line_len; i > 0; i -- )
     568                {
     569                        if( msg[i] == '-' )
     570                        {
     571                                g_string_append_len( ret, msg, i + 1 );
     572                                g_string_append_c( ret, '\n' );
     573                                msg += i + 1;
     574                                break;
     575                        }
     576                        else if( msg[i] == ' ' )
     577                        {
     578                                g_string_append_len( ret, msg, i );
     579                                g_string_append_c( ret, '\n' );
     580                                msg += i + 1;
     581                                break;
     582                        }
     583                }
     584                if( i == 0 )
     585                {
     586                        g_string_append_len( ret, msg, line_len );
     587                        g_string_append_c( ret, '\n' );
     588                        msg += line_len;
     589                }
     590        }
     591        g_string_append( ret, msg );
     592       
     593        return g_string_free( ret, FALSE );
     594}
  • lib/misc.h

    r82135c7 reda54e4  
    6464G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain );
    6565
     66G_MODULE_EXPORT char *word_wrap( char *msg, int line_len );
     67
    6668#endif
  • lib/ssl_bogus.c

    r82135c7 reda54e4  
    5252}
    5353
     54void *ssl_starttls( int fd, ssl_input_function func, gpointer data )
     55{
     56        return NULL;
     57}
     58
    5459b_input_condition ssl_getdirection( void *conn )
    5560{
  • protocols/jabber/sasl.c

    r82135c7 reda54e4  
    8989                strcpy( s + 1, jd->username );
    9090                strcpy( s + 2 + strlen( jd->username ), ic->acc->pass );
    91                 reply->text = base64_encode( s, len );
     91                reply->text = base64_encode( (unsigned char *)s, len );
    9292                reply->text_len = strlen( reply->text );
    9393                g_free( s );
     
    185185        struct jabber_data *jd = ic->proto_data;
    186186        struct xt_node *reply = NULL;
    187         char *nonce = NULL, *realm = NULL, *cnonce = NULL, cnonce_bin[30];
     187        char *nonce = NULL, *realm = NULL, *cnonce = NULL;
     188        unsigned char cnonce_bin[30];
    188189        char *digest_uri = NULL;
    189190        char *dec = NULL;
     
    216217                        realm = g_strdup( jd->server );
    217218               
    218                 random_bytes( (unsigned char *) cnonce_bin, sizeof( cnonce_bin ) );
     219                random_bytes( cnonce_bin, sizeof( cnonce_bin ) );
    219220                cnonce = base64_encode( cnonce_bin, sizeof( cnonce_bin ) );
    220221                digest_uri = g_strdup_printf( "%s/%s", "xmpp", jd->server );
  • protocols/nogaim.c

    r82135c7 reda54e4  
    4848
    4949        if(!mod) {
    50                 log_message(LOGLVL_ERROR, "Can't find `%s', not loading", path);
     50                log_message(LOGLVL_ERROR, "Can't find `%s', not loading (%s)\n", path, g_module_error());
    5151                return FALSE;
    5252        }
     
    608608              ( ( u->online == oo ) && ( oa == !u->away ) ) ) )         /* (De)voice people changing state */
    609609        {
    610                 irc_write( ic->irc, ":%s MODE %s %cv %s", ic->irc->myhost,
    611                                                           ic->irc->channel, u->away?'-':'+', u->nick );
     610                char *from;
     611               
     612                if( set_getbool( &ic->irc->set, "simulate_netsplit" ) )
     613                {
     614                        from = g_strdup( ic->irc->myhost );
     615                }
     616                else
     617                {
     618                        from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick,
     619                                                            ic->irc->myhost );
     620                }
     621                irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
     622                                                          u->away?'-':'+', u->nick );
     623                g_free( from );
    612624        }
    613625}
     
    616628{
    617629        irc_t *irc = ic->irc;
     630        char *wrapped;
    618631        user_t *u;
    619632       
     
    658671                strip_html( msg );
    659672
    660         while( strlen( msg ) > 425 )
    661         {
    662                 char tmp, *nl;
    663                
    664                 tmp = msg[425];
    665                 msg[425] = 0;
    666                
    667                 /* If there's a newline/space in this string, split up there,
    668                    looks a bit prettier. */
    669                 if( ( nl = strrchr( msg, '\n' ) ) || ( nl = strrchr( msg, ' ' ) ) )
    670                 {
    671                         msg[425] = tmp;
    672                         tmp = *nl;
    673                         *nl = 0;
    674                 }
    675                
    676                 irc_msgfrom( irc, u->nick, msg );
    677                
    678                 /* Move on. */
    679                 if( nl )
    680                 {
    681                         *nl = tmp;
    682                         msg = nl + 1;
    683                 }
    684                 else
    685                 {
    686                         msg[425] = tmp;
    687                         msg += 425;
    688                 }
    689         }
    690         irc_msgfrom( irc, u->nick, msg );
     673        wrapped = word_wrap( msg, 425 );
     674        irc_msgfrom( irc, u->nick, wrapped );
     675        g_free( wrapped );
    691676}
    692677
     
    750735{
    751736        struct im_connection *ic = c->ic;
     737        char *wrapped;
    752738        user_t *u;
    753739       
     
    762748                strip_html( msg );
    763749       
     750        wrapped = word_wrap( msg, 425 );
    764751        if( c && u )
    765                 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", msg );
     752        {
     753                irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped );
     754        }
    766755        else
    767                 imcb_log( ic, "Message from/to conversation %s@0x%x (unknown conv/user): %s", who, (int) c, msg );
     756        {
     757                imcb_log( ic, "Message from/to conversation %s@0x%x (unknown conv/user): %s", who, (int) c, wrapped );
     758        }
     759        g_free( wrapped );
    768760}
    769761
  • protocols/nogaim.h

    r82135c7 reda54e4  
    9898        struct im_connection *ic;
    9999
     100        /* stuff used just for chat */
     101        /* The in_room variable is a list of handles (not nicks!), kind of
     102         * "nick list". This is how you can check who is in the group chat
     103         * already, for example to avoid adding somebody two times. */
    100104        GList *in_room;
    101105        GList *ignored;
     
    103107        struct groupchat *next;
    104108        char *channel;
     109        /* The title variable contains the ID you gave when you created the
     110         * chat using imcb_chat_new(). */
    105111        char *title;
    106112        char joined;
     113        /* This is for you, you can add your own structure here to extend this
     114         * structure for your protocol's needs. */
    107115        void *data;
    108116};
     
    123131struct prpl {
    124132        int options;
     133        /* You should set this to the name of your protocol.
     134         * - The user sees this name ie. when imcb_log() is used. */
    125135        const char *name;
    126136
    127137        /* Added this one to be able to add per-account settings, don't think
    128            it should be used for anything else. */
     138         * it should be used for anything else. You are supposed to use the
     139         * set_add() function to add new settings. */
    129140        void (* init)           (account_t *);
    130         /* These should all be pretty obvious. */
     141        /* The typical usage of the login() function:
     142         * - Create an im_connection using imcb_new() from the account_t parameter.
     143         * - Initialize your myproto_data struct - you should store all your protocol-specific data there.
     144         * - Save your custom structure to im_connection->proto_data.
     145         * - Use proxy_connect() to connect to the server.
     146         */
    131147        void (* login)          (account_t *);
     148        /* Implementing this function is optional. */
    132149        void (* keepalive)      (struct im_connection *);
     150        /* In this function you should:
     151         * - Tell the server about you are logging out.
     152         * - g_free() your myproto_data struct as BitlBee does not know how to
     153         *   properly do so.
     154         */
    133155        void (* logout)         (struct im_connection *);
    134156       
     157        /* This function is called when the user wants to send a message to a handle.
     158         * - 'to' is a handle, not a nick
     159         * - 'flags' may be ignored
     160         */
    135161        int  (* buddy_msg)      (struct im_connection *, char *to, char *message, int flags);
     162        /* This function is called then the user uses the /away IRC command.
     163         * - 'state' contains the away reason.
     164         * - 'message' may be ignored if your protocol does not support it.
     165         */
    136166        void (* set_away)       (struct im_connection *, char *state, char *message);
     167        /* Implementing this function is optional. */
    137168        void (* get_away)       (struct im_connection *, char *who);
     169        /* Implementing this function is optional. */
    138170        int  (* send_typing)    (struct im_connection *, char *who, int flags);
    139171       
    140         /* For now BitlBee doesn't really handle groups, just set it to NULL. */
     172        /* 'name' is a handle to add/remove. For now BitlBee doesn't really
     173         * handle groups, just set it to NULL, so you can ignore that
     174         * parameter. */
    141175        void (* add_buddy)      (struct im_connection *, char *name, char *group);
    142176        void (* remove_buddy)   (struct im_connection *, char *name, char *group);
    143177       
    144         /* Block list stuff. */
     178        /* Block list stuff. Implementing these are optional. */
    145179        void (* add_permit)     (struct im_connection *, char *who);
    146180        void (* add_deny)       (struct im_connection *, char *who);
     
    151185       
    152186        /* Request profile info. Free-formatted stuff, the IM module gives back
    153            this info via imcb_log(). */
     187           this info via imcb_log(). Implementing these are optional. */
    154188        void (* get_info)       (struct im_connection *, char *who);
    155189        void (* set_my_name)    (struct im_connection *, char *name);
     
    157191       
    158192        /* Group chat stuff. */
     193        /* This is called when the user uses the /invite IRC command.
     194         * - 'who' may be ignored
     195         * - 'message' is a handle to invite
     196         */
    159197        void (* chat_invite)    (struct groupchat *, char *who, char *message);
     198        /* This is called when the user uses the /part IRC command in a group
     199         * chat. You just should tell the user about it, nothing more. */
    160200        void (* chat_leave)     (struct groupchat *);
     201        /* This is called when the user sends a message to the groupchat.
     202         * 'flags' may be ignored. */
    161203        void (* chat_msg)       (struct groupchat *, char *message, int flags);
     204        /* This is called when the user uses the /join #nick IRC command.
     205         * - 'who' is the handle of the nick
     206         */
    162207        struct groupchat *
    163208             (* chat_with)      (struct im_connection *, char *who);
     209        /* This is used when the user uses the /join #channel IRC command.  If
     210         * your protocol does not support publicly named group chats, then do
     211         * not implement this. */
    164212        struct groupchat *
    165213             (* chat_join)      (struct im_connection *, char *room, char *nick, char *password);
    166214       
     215        /* You can tell what away states your protocol supports, so that
     216         * BitlBee will try to map the IRC away reasons to them, or use
     217         * GAIM_AWAY_CUSTOM when calling skype_set_away(). */
    167218        GList *(* away_states)(struct im_connection *ic);
    168219       
    169         /* Mainly for AOL, since they think "Bung hole" == "Bu ngho le". *sigh* */
     220        /* Mainly for AOL, since they think "Bung hole" == "Bu ngho le". *sigh*
     221         * - Most protocols will just want to set this to g_strcasecmp().*/
    170222        int (* handle_cmp) (const char *who1, const char *who2);
    171223};
     
    175227G_MODULE_EXPORT GSList *get_connections();
    176228G_MODULE_EXPORT struct prpl *find_protocol( const char *name );
     229/* When registering a new protocol, you should allocate space for a new prpl
     230 * struct, initialize it (set the function pointers to point to your
     231 * functions), finally call this function. */
    177232G_MODULE_EXPORT void register_protocol( struct prpl * );
    178233
    179234/* Connection management. */
     235/* You will need this function in prpl->login() to get an im_connection from
     236 * the account_t parameter. */
    180237G_MODULE_EXPORT struct im_connection *imcb_new( account_t *acc );
    181238G_MODULE_EXPORT void imcb_free( struct im_connection *ic );
     239/* Once you're connected, you should call this function, so that the user will
     240 * see the success. */
    182241G_MODULE_EXPORT void imcb_connected( struct im_connection *ic );
     242/* This can be used to disconnect when something went wrong (ie. read error
     243 * from the server). You probably want to set the second parameter to TRUE. */
    183244G_MODULE_EXPORT void imc_logout( struct im_connection *ic, int allow_reconnect );
    184245
    185246/* Communicating with the user. */
     247/* A printf()-like function to tell the user anything you want. */
    186248G_MODULE_EXPORT void imcb_log( struct im_connection *ic, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
     249/* To tell the user an error, ie. before logging out when an error occurs. */
    187250G_MODULE_EXPORT void imcb_error( struct im_connection *ic, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
     251/* To ask a your about something.
     252 * - 'msg' is the question.
     253 * - 'data' can be your custom struct - it will be passed to the callbacks.
     254 * - 'doit' or 'dont' will be called depending of the answer of the user.
     255 */
    188256G_MODULE_EXPORT void imcb_ask( struct im_connection *ic, char *msg, void *data, void *doit, void *dont );
    189257G_MODULE_EXPORT void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname );
    190258
    191259/* Buddy management */
     260/* This function should be called for each handle which are visible to the
     261 * user, usually after a login, or if the user added a buddy and the IM
     262 * server confirms that the add was successful. Don't forget to do this! */
    192263G_MODULE_EXPORT void imcb_add_buddy( struct im_connection *ic, char *handle, char *group );
    193264G_MODULE_EXPORT void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group );
     
    197268
    198269/* Buddy activity */
     270/* To manipulate the status of a handle.
     271 * - flags can be |='d with OPT_* constants. You will need at least:
     272 *   OPT_LOGGED_IN and OPT_AWAY.
     273 * - 'state' and 'message' can be NULL */
    199274G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message );
    200275/* Not implemented yet! */ G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle );
     276/* Call when a handle says something. 'flags' and 'sent_at may be just 0. */
    201277G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, u_int32_t flags, time_t sent_at );
    202278G_MODULE_EXPORT void imcb_buddy_typing( struct im_connection *ic, char *handle, u_int32_t flags );
     
    205281/* Groupchats */
    206282G_MODULE_EXPORT void imcb_chat_invited( struct im_connection *ic, char *handle, char *who, char *msg, GList *data );
     283/* These two functions are to create a group chat.
     284 * - imcb_chat_new(): the 'handle' parameter identifies the chat, like the
     285 *   channel name on IRC.
     286 * - After you have a groupchat pointer, you should add the handles, finally
     287 *   the user her/himself. At that point the group chat will be visible to the
     288 *   user, too. */
    207289G_MODULE_EXPORT struct groupchat *imcb_chat_new( struct im_connection *ic, char *handle );
    208290G_MODULE_EXPORT void imcb_chat_add_buddy( struct groupchat *b, char *handle );
     291/* To remove a handle from a group chat. Reason can be NULL. */
    209292G_MODULE_EXPORT void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason );
     293/* To tell BitlBee 'who' said 'msg' in 'c'. 'flags' and 'sent_at' can be 0. */
    210294G_MODULE_EXPORT void imcb_chat_msg( struct groupchat *c, char *who, char *msg, u_int32_t flags, time_t sent_at );
    211295G_MODULE_EXPORT void imcb_chat_free( struct groupchat *c );
  • root_commands.c

    r82135c7 reda54e4  
    383383                }
    384384               
    385                 if( cmd[3] )
     385                if( cmd[3] && set_name )
    386386                {
    387387                        set_t *s = set_find( &a->set, set_name );
  • storage_xml.c

    r82135c7 reda54e4  
    2727#include "bitlbee.h"
    2828#include "base64.h"
    29 #include "rc4.h"
     29#include "arc.h"
    3030#include "md5.h"
    3131
     
    132132        {
    133133                char *protocol, *handle, *server, *password = NULL, *autoconnect;
    134                 char *pass_b64 = NULL, *pass_rc4 = NULL;
     134                char *pass_b64 = NULL;
     135                unsigned char *pass_cr = NULL;
    135136                int pass_len;
    136137                struct prpl *prpl = NULL;
     
    151152                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
    152153                                     "Unknown protocol: %s", protocol );
    153                 else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_rc4 ) ) &&
    154                                 rc4_decode( (unsigned char*) pass_rc4, pass_len,
    155                                             (unsigned char**) &password, xd->given_pass ) )
     154                else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&
     155                                         arc_decode( pass_cr, pass_len, &password, xd->given_pass ) )
    156156                {
    157157                        xd->current_account = account_add( irc, prpl, handle, password );
     
    169169                }
    170170               
    171                 g_free( pass_rc4 );
     171                g_free( pass_cr );
    172172                g_free( password );
    173173        }
     
    410410        md5_finish( &md5_state, pass_md5 );
    411411        /* Save the hash in base64-encoded form. */
    412         pass_buf = base64_encode( (char*) pass_md5, 21 );
     412        pass_buf = base64_encode( pass_md5, 21 );
    413413       
    414414        if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->nick, pass_buf, XML_FORMAT_VERSION ) )
     
    424424        for( acc = irc->accounts; acc; acc = acc->next )
    425425        {
    426                 char *pass_rc4, *pass_b64;
     426                unsigned char *pass_cr;
     427                char *pass_b64;
    427428                int pass_len;
    428429               
    429                 pass_len = rc4_encode( (unsigned char*) acc->pass, strlen( acc->pass ), (unsigned char**) &pass_rc4, irc->password );
    430                 pass_b64 = base64_encode( pass_rc4, pass_len );
    431                 g_free( pass_rc4 );
     430                pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password );
     431                pass_b64 = base64_encode( pass_cr, pass_len );
     432                g_free( pass_cr );
    432433               
    433434                if( !xml_printf( fd, 1, "<account protocol=\"%s\" handle=\"%s\" password=\"%s\" autoconnect=\"%d\"", acc->prpl->name, acc->user, pass_b64, acc->auto_connect ) )
  • tests/Makefile

    r82135c7 reda54e4  
    1313main_objs = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o storage_text.o user.o
    1414
    15 test_objs = check.o check_util.o check_nick.o check_md5.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o
     15test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o
    1616
    1717check: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o
  • tests/check.c

    r82135c7 reda54e4  
    4747/* From check_md5.c */
    4848Suite *md5_suite(void);
     49
     50/* From check_arc.c */
     51Suite *arc_suite(void);
    4952
    5053/* From check_irc.c */
     
    102105        srunner_add_suite(sr, nick_suite());
    103106        srunner_add_suite(sr, md5_suite());
     107        srunner_add_suite(sr, arc_suite());
    104108        srunner_add_suite(sr, irc_suite());
    105109        srunner_add_suite(sr, help_suite());
  • tests/check_util.c

    r82135c7 reda54e4  
    104104END_TEST
    105105
     106struct
     107{
     108        char *orig;
     109        int line_len;
     110        char *wrapped;
     111} word_wrap_tests[] = {
     112        {
     113                "Line-wrapping is not as easy as it seems?",
     114                16,
     115                "Line-wrapping is\nnot as easy as\nit seems?"
     116        },
     117        {
     118                "Line-wrapping is not as easy as it seems?",
     119                8,
     120                "Line-\nwrapping\nis not\nas easy\nas it\nseems?"
     121        },
     122        {
     123                "Line-wrapping is\nnot as easy as it seems?",
     124                8,
     125                "Line-\nwrapping\nis\nnot as\neasy as\nit\nseems?"
     126        },
     127        {
     128                "a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa",
     129                5,
     130                "a aa\naaa\naaaa\naaaaa\naaaaa\na\naaaaa\naa\naaaaa\naaa",
     131        },
     132        {
     133                "aaaaaaaa aaaaaaa aaaaaa aaaaa aaaa aaa aa a",
     134                5,
     135                "aaaaa\naaa\naaaaa\naa\naaaaa\na\naaaaa\naaaa\naaa\naa a",
     136        },
     137        {
     138                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
     139                5,
     140                "aaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\na",
     141        },
     142        {
     143                NULL
     144        }
     145};
     146
     147START_TEST(test_word_wrap)
     148        int i;
     149       
     150        for( i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i ++ )
     151        {
     152                char *wrapped = word_wrap( word_wrap_tests[i].orig, word_wrap_tests[i].line_len );
     153               
     154                fail_unless( strcmp( word_wrap_tests[i].wrapped, wrapped ) == 0,
     155                             "%s (line_len = %d) should wrap to `%s', not to `%s'",
     156                             word_wrap_tests[i].orig, word_wrap_tests[i].line_len,
     157                             word_wrap_tests[i].wrapped, wrapped );
     158               
     159                g_free( wrapped );
     160        }
     161END_TEST
     162
    106163Suite *util_suite (void)
    107164{
     
    116173        tcase_add_test (tc_core, test_set_url_username);
    117174        tcase_add_test (tc_core, test_set_url_username_pwd);
     175        tcase_add_test (tc_core, test_word_wrap);
    118176        return s;
    119177}
  • unix.c

    r82135c7 reda54e4  
    4747        memset( &global, 0, sizeof( global_t ) );
    4848       
    49         b_main_init();
    5049        log_init();
    51         nogaim_init();
    52        
    53         srand( time( NULL ) ^ getpid() );
    54        
    5550        CONF_FILE = g_strdup( CONF_FILE_DEF );
    56         global.helpfile = g_strdup( HELP_FILE );
    57        
    5851        global.conf = conf_load( argc, argv );
    5952        if( global.conf == NULL )
    6053                return( 1 );
     54       
     55        b_main_init();
     56        nogaim_init();
     57       
     58        srand( time( NULL ) ^ getpid() );
     59        global.helpfile = g_strdup( HELP_FILE );
    6160       
    6261        if( global.conf->runmode == RUNMODE_INETD )
Note: See TracChangeset for help on using the changeset viewer.