Changes in / [568aaf7:703f0f7]


Ignore:
Files:
3 added
25 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r568aaf7 r703f0f7  
    88build-arch-stamp
    99tags
     10decode
     11encode
  • Makefile

    r568aaf7 r703f0f7  
    1010
    1111# Program variables
    12 objects = account.o bitlbee.o commands.o conf.o crypting.o help.o ini.o irc.o log.o nick.o query.o set.o unix.o url.o user.o
     12objects = account.o bitlbee.o commands.o conf.o crypting.o help.o ini.o irc.o log.o nick.o query.o set.o unix.o url.o user.o storage_text.o storage.o
    1313subdirs = protocols
    1414
  • bitlbee.c

    r568aaf7 r703f0f7  
    2727#include "bitlbee.h"
    2828#include "commands.h"
    29 #include "crypting.h"
    3029#include "protocols/nogaim.h"
    3130#include "help.h"
     
    244243}
    245244
    246 /* DO NOT USE THIS FUNCTION IN NEW CODE. This
    247  * function is here merely because the save/load code still uses
    248  * ids rather then names */
    249 static struct prpl *find_protocol_by_id(int id)
    250 {
    251         switch (id) {
    252         case 1: return find_protocol("oscar");
    253         case 4: return find_protocol("msn");
    254         case 2: return find_protocol("yahoo");
    255         case 8: return find_protocol("jabber");
    256         default: break;
    257         }
    258         return NULL;
    259 }
    260 
    261 static int find_protocol_id(const char *name)
    262 {
    263         if (!strcmp(name, "oscar")) return 1;
    264         if (!strcmp(name, "msn")) return 4;
    265         if (!strcmp(name, "yahoo")) return 2;
    266         if (!strcmp(name, "jabber")) return 8;
    267 
    268         return -1;
    269 }
    270 
    271 int bitlbee_load( irc_t *irc, char* password )
    272 {
    273         char s[512];
    274         char *line;
    275         int proto;
    276         char nick[MAX_NICK_LENGTH+1];
    277         FILE *fp;
    278         user_t *ru = user_find( irc, ROOT_NICK );
    279        
    280         if( irc->status == USTATUS_IDENTIFIED )
    281                 return( 1 );
    282        
    283         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    284         fp = fopen( s, "r" );
    285         if( !fp ) return( 0 );
    286        
    287         fscanf( fp, "%32[^\n]s", s );
    288         if( setpass( irc, password, s ) < 0 )
    289         {
    290                 fclose( fp );
    291                 return( -1 );
    292         }
    293        
    294         /* Do this now. If the user runs with AuthMode = Registered, the
    295            account command will not work otherwise. */
    296         irc->status = USTATUS_IDENTIFIED;
    297        
    298         while( fscanf( fp, "%511[^\n]s", s ) > 0 )
    299         {
    300                 fgetc( fp );
    301                 line = deobfucrypt( irc, s );
    302                 root_command_string( irc, ru, line, 0 );
    303                 g_free( line );
    304         }
    305         fclose( fp );
    306        
    307         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
    308         fp = fopen( s, "r" );
    309         if( !fp ) return( 0 );
    310         while( fscanf( fp, "%s %d %s", s, &proto, nick ) > 0 )
    311         {
    312                 struct prpl *prpl;
    313 
    314                 prpl = find_protocol_by_id(proto);
    315 
    316                 if (!prpl)
    317                         continue;
    318 
    319                 http_decode( s );
    320                 nick_set( irc, s, prpl, nick );
    321         }
    322         fclose( fp );
    323        
    324         if( set_getint( irc, "auto_connect" ) )
    325         {
    326                 strcpy( s, "account on" );      /* Can't do this directly because r_c_s alters the string */
    327                 root_command_string( irc, ru, s, 0 );
    328         }
    329        
    330         return( 1 );
    331 }
    332 
    333 int bitlbee_save( irc_t *irc )
    334 {
    335         char s[512];
    336         char path[512], new_path[512];
    337         char *line;
    338         nick_t *n;
    339         set_t *set;
    340         mode_t ou = umask( 0077 );
    341         account_t *a;
    342         FILE *fp;
    343         char *hash;
    344        
    345         /*\
    346          *  [SH] Nothing should be saved if no password is set, because the
    347          *  password is not set if it was wrong, or if one is not identified
    348          *  yet. This means that a malicious user could easily overwrite
    349          *  files owned by someone else:
    350          *  a Bad Thing, methinks
    351         \*/
    352 
    353         /* [WVG] No? Really? */
    354 
    355         /*\
    356          *  [SH] Okay, okay, it wasn't really Wilmer who said that, it was
    357          *  me. I just thought it was funny.
    358         \*/
    359        
    360         hash = hashpass( irc );
    361         if( hash == NULL )
    362         {
    363                 irc_usermsg( irc, "Please register yourself if you want to save your settings." );
    364                 return( 0 );
    365         }
    366        
    367         g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks~" );
    368         fp = fopen( path, "w" );
    369         if( !fp ) return( 0 );
    370         for( n = irc->nicks; n; n = n->next )
    371         {
    372                 strcpy( s, n->handle );
    373                 s[169] = 0; /* Prevent any overflow (169 ~ 512 / 3) */
    374                 http_encode( s );
    375                 g_snprintf( s + strlen( s ), 510 - strlen( s ), " %d %s", find_protocol_id(n->proto->name), n->nick );
    376                 if( fprintf( fp, "%s\n", s ) != strlen( s ) + 1 )
    377                 {
    378                         irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );
    379                         fclose( fp );
    380                         return( 0 );
    381                 }
    382         }
    383         if( fclose( fp ) != 0 )
    384         {
    385                 irc_usermsg( irc, "fclose() reported an error. Disk full?" );
    386                 return( 0 );
    387         }
    388  
    389         g_snprintf( new_path, 512, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
    390         if( unlink( new_path ) != 0 )
    391         {
    392                 if( errno != ENOENT )
    393                 {
    394                         irc_usermsg( irc, "Error while removing old .nicks file" );
    395                         return( 0 );
    396                 }
    397         }
    398         if( rename( path, new_path ) != 0 )
    399         {
    400                 irc_usermsg( irc, "Error while renaming new .nicks file" );
    401                 return( 0 );
    402         }
    403        
    404         g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts~" );
    405         fp = fopen( path, "w" );
    406         if( !fp ) return( 0 );
    407         if( fprintf( fp, "%s", hash ) != strlen( hash ) )
    408         {
    409                 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );
    410                 fclose( fp );
    411                 return( 0 );
    412         }
    413         g_free( hash );
    414 
    415         for( a = irc->accounts; a; a = a->next )
    416         {
    417                 if( !strcmp( a->prpl->name, "oscar" ) )
    418                         g_snprintf( s, sizeof( s ), "account add oscar \"%s\" \"%s\" %s", a->user, a->pass, a->server );
    419                 else
    420                         g_snprintf( s, sizeof( s ), "account add %s \"%s\" \"%s\" \"%s\"",
    421                                     a->prpl->name, a->user, a->pass, a->server ? a->server : "" );
    422                
    423                 line = obfucrypt( irc, s );
    424                 if( *line )
    425                 {
    426                         if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )
    427                         {
    428                                 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );
    429                                 fclose( fp );
    430                                 return( 0 );
    431                         }
    432                 }
    433                 g_free( line );
    434         }
    435        
    436         for( set = irc->set; set; set = set->next )
    437         {
    438                 if( set->value && set->def )
    439                 {
    440                         g_snprintf( s, sizeof( s ), "set %s \"%s\"", set->key, set->value );
    441                         line = obfucrypt( irc, s );
    442                         if( *line )
    443                         {
    444                                 if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )
    445                                 {
    446                                         irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );
    447                                         fclose( fp );
    448                                         return( 0 );
    449                                 }
    450                         }
    451                         g_free( line );
    452                 }
    453         }
    454        
    455         if( strcmp( irc->mynick, ROOT_NICK ) != 0 )
    456         {
    457                 g_snprintf( s, sizeof( s ), "rename %s %s", ROOT_NICK, irc->mynick );
    458                 line = obfucrypt( irc, s );
    459                 if( *line )
    460                 {
    461                         if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )
    462                         {
    463                                 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );
    464                                 fclose( fp );
    465                                 return( 0 );
    466                         }
    467                 }
    468                 g_free( line );
    469         }
    470         if( fclose( fp ) != 0 )
    471         {
    472                 irc_usermsg( irc, "fclose() reported an error. Disk full?" );
    473                 return( 0 );
    474         }
    475        
    476         g_snprintf( new_path, 512, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    477         if( unlink( new_path ) != 0 )
    478         {
    479                 if( errno != ENOENT )
    480                 {
    481                         irc_usermsg( irc, "Error while removing old .accounts file" );
    482                         return( 0 );
    483                 }
    484         }
    485         if( rename( path, new_path ) != 0 )
    486         {
    487                 irc_usermsg( irc, "Error while renaming new .accounts file" );
    488                 return( 0 );
    489         }
    490        
    491         umask( ou );
    492        
    493         return( 1 );
    494 }
    495 
    496245void bitlbee_shutdown( gpointer data )
    497246{
  • bitlbee.h

    r568aaf7 r703f0f7  
    3030
    3131#define PACKAGE "BitlBee"
    32 #define BITLBEE_VERSION "1.0"
     32#define BITLBEE_VERSION "BZR"
    3333#define VERSION BITLBEE_VERSION
    3434
     
    100100
    101101#include "irc.h"
     102#include "storage.h"
    102103#include "set.h"
    103104#include "protocols/nogaim.h"
     
    115116        help_t *help;
    116117        conf_t *conf;
     118        GList *storage; /* The first backend in the list will be used for saving */
    117119        char *helpfile;
    118120        GMainLoop *loop;
     
    127129int root_command_string( irc_t *irc, user_t *u, char *command, int flags );
    128130int root_command( irc_t *irc, char *command[] );
    129 int bitlbee_load( irc_t *irc, char *password );
    130 int bitlbee_save( irc_t *irc );
    131131void bitlbee_shutdown( gpointer data );
    132132double gettime( void );
  • commands.c

    r568aaf7 r703f0f7  
    8686int cmd_identify( irc_t *irc, char **cmd )
    8787{
    88         int checkie = bitlbee_load( irc, cmd[1] );
    89        
    90         if( checkie == -1 )
    91         {
     88        storage_status_t status = storage_load( irc->nick, cmd[1], irc );
     89       
     90        switch (status) {
     91        case STORAGE_INVALID_PASSWORD:
    9292                irc_usermsg( irc, "Incorrect password" );
    93         }
    94         else if( checkie == 0 )
    95         {
     93                break;
     94        case STORAGE_NO_SUCH_USER:
    9695                irc_usermsg( irc, "The nick is (probably) not registered" );
    97         }
    98         else if( checkie == 1 )
    99         {
     96                break;
     97        case STORAGE_OK:
    10098                irc_usermsg( irc, "Password accepted" );
    101         }
    102         else
    103         {
     99                break;
     100        default:
    104101                irc_usermsg( irc, "Something very weird happened" );
    105         }
    106        
     102                break;
     103        }
     104
    107105        return( 0 );
    108106}
     
    110108int cmd_register( irc_t *irc, char **cmd )
    111109{
    112         int checkie;
    113         char path[512];
    114        
    115110        if( global.conf->authmode == AUTHMODE_REGISTERED )
    116111        {
     
    118113                return( 0 );
    119114        }
    120        
    121         g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    122         checkie = access( path, F_OK );
    123        
    124         g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
    125         checkie += access( path, F_OK );
    126        
    127         if( checkie == -2 )
    128         {
    129                 setpassnc( irc, cmd[1] );
    130                 root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 );
    131                 irc->status = USTATUS_IDENTIFIED;
    132         }
    133         else
    134         {
    135                 irc_usermsg( irc, "Nick is already registered" );
     115
     116        irc_setpass( irc, cmd[1] );
     117        switch( storage_save( irc, FALSE )) {
     118                case STORAGE_ALREADY_EXISTS:
     119                        irc_usermsg( irc, "Nick is already registered" );
     120                        break;
     121                       
     122                case STORAGE_OK:
     123                        irc->status = USTATUS_IDENTIFIED;
     124                        break;
     125
     126                default:
     127                        irc_usermsg( irc, "Error registering" );
     128                        break;
    136129        }
    137130       
     
    141134int cmd_drop( irc_t *irc, char **cmd )
    142135{
    143         char s[512];
    144         FILE *fp;
    145        
    146         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    147         fp = fopen( s, "r" );
    148         if( !fp )
    149         {
     136        storage_status_t status;
     137       
     138        status = storage_remove (irc->nick, cmd[1]);
     139        switch (status) {
     140        case STORAGE_NO_SUCH_USER:
    150141                irc_usermsg( irc, "That account does not exist" );
    151142                return( 0 );
    152         }
    153        
    154         fscanf( fp, "%32[^\n]s", s );
    155         fclose( fp );
    156         if( setpass( irc, cmd[1], s ) < 0 )
    157         {
    158                 irc_usermsg( irc, "Incorrect password" );
    159                 return( 0 );
    160         }
    161        
    162         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    163         unlink( s );
    164        
    165         g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
    166         unlink( s );
    167        
    168         setpassnc( irc, NULL );
    169         irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick );
    170        
    171         return( 0 );
     143        case STORAGE_INVALID_PASSWORD:
     144                irc_usermsg( irc, "Password invalid" );
     145                return( 0 );
     146        case STORAGE_OK:
     147                irc_setpass( irc, NULL );
     148                irc_usermsg( irc, "Account `%s' removed", irc->nick );
     149                return( 0 );
     150        default:
     151                irc_usermsg( irc, "Error: '%d'", status );
     152                return( 0 );
     153        }
    172154}
    173155
     
    623605int cmd_save( irc_t *irc, char **cmd )
    624606{
    625         if( bitlbee_save( irc ) )
     607        if( storage_save( irc, TRUE ) == STORAGE_OK )
    626608                irc_usermsg( irc, "Configuration saved" );
    627609        else
  • conf.c

    r568aaf7 r703f0f7  
    5050        conf->nofork = 0;
    5151        conf->verbose = 0;
     52        conf->primary_storage = "text";
    5253        conf->runmode = RUNMODE_INETD;
    5354        conf->authmode = AUTHMODE_OPEN;
     
    198199                                conf->motdfile = g_strdup( ini->value );
    199200                        }
     201                        else if( g_strcasecmp( ini->key, "account_storage" ) == 0 )
     202                        {
     203                                g_free( conf->primary_storage );
     204                                conf->primary_storage = g_strdup( ini->value );
     205                        }
     206                        else if( g_strcasecmp( ini->key, "account_storage_migrate" ) == 0 )
     207                        {
     208                                g_strfreev( conf->migrate_storage );
     209                                conf->migrate_storage = g_strsplit( ini->value, " \t,;", -1 );
     210                        }
    200211                        else if( g_strcasecmp( ini->key, "pinginterval" ) == 0 )
    201212                        {
  • conf.h

    r568aaf7 r703f0f7  
    4242        char *configdir;
    4343        char *motdfile;
     44        char *primary_storage;
     45        char **migrate_storage;
    4446        int ping_interval;
    4547        int ping_timeout;
  • crypting.c

    r568aaf7 r703f0f7  
    2929   the programs will be built. */
    3030
    31 #ifndef CRYPTING_MAIN
    32 #define BITLBEE_CORE
    33 #include "bitlbee.h"
    34 #include "irc.h"
    3531#include "md5.h"
    3632#include "crypting.h"
     
    3834#include <stdio.h>
    3935#include <stdlib.h>
    40 
    41 #else
    42 
    43 typedef struct irc
    44 {
    45         char *password;
    46 } irc_t;
    47 
    48 #define set_add( a, b, c, d )
    49 #define set_find( a, b ) NULL
    50 
    51 #include "md5.h"
    52 #include "crypting.h"
    53 #include <string.h>
    54 #include <stdio.h>
    55 #include <stdlib.h>
    56 
    57 #define irc_usermsg
    58 
    59 #endif
    6036
    6137/*\
     
    6541\*/
    6642
    67 /* USE WITH CAUTION!
    68    Sets pass without checking */
    69 void setpassnc (irc_t *irc, char *pass) {
    70         if (!set_find (irc, "password"))
    71                 set_add (irc, "password", NULL, passchange);
    72        
    73         if (irc->password) g_free (irc->password);
    74        
    75         if (pass) {
    76                 irc->password = g_strdup (pass);
    77                 irc_usermsg (irc, "Password successfully changed");
    78         } else {
    79                 irc->password = NULL;
    80         }
    81 }
    82 
    83 char *passchange (irc_t *irc, void *set, char *value) {
    84         setpassnc (irc, value);
    85         return (NULL);
    86 }
    87 
    88 int setpass (irc_t *irc, char *pass, char* md5sum) {
     43int checkpass (const char *pass, const char *md5sum)
     44{
    8945        md5_state_t md5state;
    9046        md5_byte_t digest[16];
     
    10359                if (digits[1] != md5sum[j + 1]) return (-1);
    10460        }
    105        
    106         /* If pass is correct, we end up here and we set the pass */
    107         setpassnc (irc, pass);
    108        
    109         return (0);
     61
     62        return( 0 );
    11063}
    11164
    112 char *hashpass (irc_t *irc) {
     65
     66char *hashpass (const char *password)
     67{
    11368        md5_state_t md5state;
    11469        md5_byte_t digest[16];
     
    11772        char *rv;
    11873       
    119         if (irc->password == NULL) return (NULL);
     74        if (password == NULL) return (NULL);
    12075       
    121         rv = (char *)g_malloc (33);
    122         memset (rv, 0, 33);
     76        rv = g_new0 (char, 33);
    12377       
    12478        md5_init (&md5state);
    125         md5_append (&md5state, (unsigned char *)irc->password, strlen (irc->password));
     79        md5_append (&md5state, (const unsigned char *)password, strlen (password));
    12680        md5_finish (&md5state, digest);
    12781       
     
    13589}
    13690
    137 char *obfucrypt (irc_t *irc, char *line) {
     91char *obfucrypt (char *line, const char *password)
     92{
    13893        int i, j;
    13994        char *rv;
    14095       
    141         if (irc->password == NULL) return (NULL);
     96        if (password == NULL) return (NULL);
    14297       
    143         rv = (char *)g_malloc (strlen (line) + 1);
    144         memset (rv, '\0', strlen (line) + 1);
     98        rv = g_new0 (char, strlen (line) + 1);
    14599       
    146100        i = j = 0;
     
    148102                /* Encrypt/obfuscate the line, using the password */
    149103                if (*(signed char*)line < 0) *line = - (*line);
    150                 if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i];
    151104               
    152                 rv[j] = *line + irc->password[i]; /* Overflow intended */
     105                rv[j] = *line + password[i]; /* Overflow intended */
    153106               
    154107                line++;
    155                 if (!irc->password[++i]) i = 0;
     108                if (!password[++i]) i = 0;
    156109                j++;
    157110        }
     
    160113}
    161114
    162 char *deobfucrypt (irc_t *irc, char *line) {
     115char *deobfucrypt (char *line, const char *password)
     116{
    163117        int i, j;
    164118        char *rv;
    165119       
    166         if (irc->password == NULL) return (NULL);
     120        if (password == NULL) return (NULL);
    167121       
    168         rv = (char *)g_malloc (strlen (line) + 1);
    169         memset (rv, '\0', strlen (line) + 1);
     122        rv = g_new0 (char, strlen (line) + 1);
    170123       
    171124        i = j = 0;
    172125        while (*line) {
    173126                /* Decrypt/deobfuscate the line, using the pass */
    174                 rv[j] = *line - irc->password[i]; /* Overflow intended */
     127                rv[j] = *line - password[i]; /* Overflow intended */
    175128               
    176129                line++;
    177                 if (!irc->password[++i]) i = 0;
     130                if (!password[++i]) i = 0;
    178131                j++;
    179132        }
     
    189142int main( int argc, char *argv[] )
    190143{
    191         irc_t *irc = g_malloc( sizeof( irc_t ) );
    192144        char *hash, *action, line[256];
    193         char* (*func)( irc_t *, char * );
     145        char* (*func)( char *, const char * );
    194146       
    195147        if( argc < 2 )
     
    201153        }
    202154       
    203         memset( irc, 0, sizeof( irc_t ) );
    204         irc->password = g_strdup( argv[1] );
    205        
    206         hash = hashpass( irc );
     155        hash = hashpass( argv[1] );
    207156        action = argv[0] + strlen( argv[0] ) - strlen( "encode" );
    208157       
     
    236185                fgetc( stdin );
    237186               
    238                 out = func( irc, line );
     187                out = func( line, argv[1] );
    239188                printf( "%s\n", out );
    240189                g_free( out );
  • crypting.h

    r568aaf7 r703f0f7  
    2424*/
    2525
    26 void setpassnc (irc_t *irc, char *pass); /* USE WITH CAUTION! */
    27 char *passchange (irc_t *irc, void *set, char *value);
    28 int setpass (irc_t *irc, char *pass, char* md5sum);
    29 char *hashpass (irc_t *irc);
    30 char *obfucrypt (irc_t *irc, char *line);
    31 char *deobfucrypt (irc_t *irc, char *line);
     26int checkpass (const char *password, const char *md5sum);
     27char *hashpass (const char *password);
     28char *obfucrypt (char *line, const char *password);
     29char *deobfucrypt (char *line, const char *password);
  • irc.c

    r568aaf7 r703f0f7  
    3131
    3232GSList *irc_connection_list = NULL;
     33
     34static char *passchange (irc_t *irc, void *set, char *value)
     35{
     36        irc_setpass (irc, value);
     37        return (NULL);
     38}
    3339
    3440irc_t *irc_new( int fd )
     
    129135        set_add( irc, "to_char", ": ", set_eval_to_char );
    130136        set_add( irc, "typing_notice", "false", set_eval_bool );
     137        set_add( irc, "password", NULL, passchange);
    131138       
    132139        conf_loaddefaults( irc );
     
    154161       
    155162        if( irc->status >= USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) )
    156                 if( !bitlbee_save( irc ) )
     163                if( storage_save( irc, TRUE ) != STORAGE_OK )
    157164                        irc_usermsg( irc, "Error while saving settings!" );
    158165       
     
    259266        if( global.conf->runmode == RUNMODE_INETD )
    260267                g_main_quit( global.loop );
     268}
     269
     270/* USE WITH CAUTION!
     271   Sets pass without checking */
     272void irc_setpass (irc_t *irc, const char *pass)
     273{
     274        if (irc->password) g_free (irc->password);
     275       
     276        if (pass) {
     277                irc->password = g_strdup (pass);
     278                irc_usermsg (irc, "Password successfully changed");
     279        } else {
     280                irc->password = NULL;
     281        }
    261282}
    262283
  • irc.h

    r568aaf7 r703f0f7  
    137137void irc_whois( irc_t *irc, char *nick );
    138138int irc_away( irc_t *irc, char *away );
     139void irc_setpass( irc_t *irc, const char *pass ); /* USE WITH CAUTION! */
    139140
    140141int irc_send( irc_t *irc, char *nick, char *s, int flags );
  • nick.c

    r568aaf7 r703f0f7  
    2727#include "bitlbee.h"
    2828
    29 void nick_set( irc_t *irc, char *handle, struct prpl *proto, char *nick )
     29void nick_set( irc_t *irc, const char *handle, struct prpl *proto, const char *nick )
    3030{
    3131        nick_t *m = NULL, *n = irc->nicks;
     
    5656}
    5757
    58 char *nick_get( irc_t *irc, char *handle, struct prpl *proto, const char *realname )
     58char *nick_get( irc_t *irc, const char *handle, struct prpl *proto, const char *realname )
    5959{
    6060        static char nick[MAX_NICK_LENGTH+1];
     
    129129}
    130130
    131 void nick_del( irc_t *irc, char *nick )
     131void nick_del( irc_t *irc, const char *nick )
    132132{
    133133        nick_t *l = NULL, *n = irc->nicks;
     
    176176}
    177177
    178 int nick_ok( char *nick )
    179 {
    180         char *s;
     178int nick_ok( const char *nick )
     179{
     180        const char *s;
    181181       
    182182        /* Empty/long nicks are not allowed */
     
    237237}
    238238
    239 int nick_cmp( char *a, char *b )
     239int nick_cmp( const char *a, const char *b )
    240240{
    241241        char aa[1024] = "", bb[1024] = "";
     
    253253}
    254254
    255 char *nick_dup( char *nick )
    256 {
    257         char *cp;
    258        
    259         cp = g_new0 ( char, MAX_NICK_LENGTH + 1 );
    260         strncpy( cp, nick, MAX_NICK_LENGTH );
    261        
    262         return( cp );
    263 }
     255char *nick_dup( const char *nick )
     256{
     257        return g_strndup( nick, MAX_NICK_LENGTH );
     258}
  • nick.h

    r568aaf7 r703f0f7  
    3232} nick_t;
    3333
    34 void nick_set( irc_t *irc, char *handle, struct prpl *proto, char *nick );
    35 char *nick_get( irc_t *irc, char *handle, struct prpl *proto, const char *realname );
    36 void nick_del( irc_t *irc, char *nick );
     34void nick_set( irc_t *irc, const char *handle, struct prpl *proto, const char *nick );
     35char *nick_get( irc_t *irc, const char *handle, struct prpl *proto, const char *realname );
     36void nick_del( irc_t *irc, const char *nick );
    3737void nick_strip( char *nick );
    3838
    39 int nick_ok( char *nick );
     39int nick_ok( const char *nick );
    4040int nick_lc( char *nick );
    4141int nick_uc( char *nick );
    42 int nick_cmp( char *a, char *b );
    43 char *nick_dup( char *nick );
     42int nick_cmp( const char *a, const char *b );
     43char *nick_dup( const char *nick );
  • protocols/msn/sb.c

    r568aaf7 r703f0f7  
    644644                        if( who )
    645645                        {
    646                                 serv_got_typing( gc, who, 5 );
     646                                serv_got_typing( gc, who, 5, 1 );
    647647                                g_free( who );
    648648                        }
  • protocols/nogaim.c

    r568aaf7 r703f0f7  
    768768}
    769769
    770 void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout )
     770void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout, int type )
    771771{
    772772        user_t *u;
     
    775775                return;
    776776       
    777         if( ( u = user_findhandle( gc, handle ) ) )
    778                 irc_privmsg( gc->irc, u, "PRIVMSG", gc->irc->nick, NULL, "\1TYPING 1\1" );
     777        if( ( u = user_findhandle( gc, handle ) ) ) {
     778                /* If type is:
     779                 * 0: user has stopped typing
     780                 * 1: user is actively typing
     781                 * 2: user has entered text, but is not actively typing
     782                 */
     783                if (type == 0 || type == 1 || type == 2) {
     784                        char buf[256];
     785                        g_snprintf(buf, 256, "\1TYPING %d\1", type);
     786                        irc_privmsg( gc->irc, u, "PRIVMSG", gc->irc->nick, NULL, buf );
     787                }
     788        }
    779789}
    780790
  • protocols/nogaim.h

    r568aaf7 r703f0f7  
    283283G_MODULE_EXPORT void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, int evil, time_t signon, time_t idle, int type, guint caps );
    284284G_MODULE_EXPORT void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 flags, time_t mtime, gint len );
    285 G_MODULE_EXPORT void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout );
     285G_MODULE_EXPORT void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout, int type );
    286286G_MODULE_EXPORT void serv_got_chat_invite( struct gaim_connection *gc, char *handle, char *who, char *msg, GList *data );
    287287G_MODULE_EXPORT struct conversation *serv_got_joined_chat( struct gaim_connection *gc, int id, char *handle );
  • protocols/oscar/aim.h

    r568aaf7 r703f0f7  
    466466int aim_addtlvtochain_caps(aim_tlvlist_t **list, const guint16 t, const guint32 caps);
    467467int aim_addtlvtochain_noval(aim_tlvlist_t **list, const guint16 type);
     468int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance);
    468469int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, guint16 type, aim_userinfo_t *ui);
    469470int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, guint16 type, aim_tlvlist_t **tl);
     
    572573};
    573574
     575struct aim_chat_invitation {
     576        struct gaim_connection * gc;
     577        char * name;
     578        guint8 exchange;
     579};
    574580
    575581#define AIM_VISIBILITYCHANGE_PERMITADD    0x05
  • protocols/oscar/chat.c

    r568aaf7 r703f0f7  
    180180       
    181181        aim_tx_enqueue(sess, fr);
    182 
    183         return 0;
    184 }
    185 
    186 static int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance)
    187 {
    188         guint8 *buf;
    189         int buflen;
    190         aim_bstream_t bs;
    191 
    192         buflen = 2 + 1 + strlen(roomname) + 2;
    193        
    194         if (!(buf = g_malloc(buflen)))
    195                 return 0;
    196 
    197         aim_bstream_init(&bs, buf, buflen);
    198 
    199         aimbs_put16(&bs, exchange);
    200         aimbs_put8(&bs, strlen(roomname));
    201         aimbs_putraw(&bs, (guint8 *)roomname, strlen(roomname));
    202         aimbs_put16(&bs, instance);
    203 
    204         aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf);
    205 
    206         g_free(buf);
    207182
    208183        return 0;
  • protocols/oscar/im.c

    r568aaf7 r703f0f7  
    13691369}
    13701370
     1371
     1372static void incomingim_ch2_chat_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args)
     1373{
     1374
     1375        /* XXX aim_chat_roominfo_free() */
     1376        g_free(args->info.chat.roominfo.name);
     1377
     1378        return;
     1379}
     1380
     1381static void incomingim_ch2_chat(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args, aim_bstream_t *servdata)
     1382{
     1383
     1384        /*
     1385         * Chat room info.
     1386         */
     1387        if (servdata)
     1388                aim_chat_readroominfo(servdata, &args->info.chat.roominfo);
     1389
     1390        args->destructor = (void *)incomingim_ch2_chat_free;
     1391
     1392        return;
     1393}
     1394
    13711395static void incomingim_ch2_icqserverrelay_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args)
    13721396{
     
    16171641        if (args.reqclass & AIM_CAPS_ICQSERVERRELAY)
    16181642                incomingim_ch2_icqserverrelay(sess, mod, rx, snac, userinfo, &args, sdbsptr);
     1643        else if (args.reqclass & AIM_CAPS_CHAT)
     1644                incomingim_ch2_chat(sess, mod, rx, snac, userinfo, &args, sdbsptr);
    16191645
    16201646
  • protocols/oscar/oscar.c

    r568aaf7 r703f0f7  
    6262   static int gaim_caps = AIM_CAPS_UTF8; */
    6363
    64 static int gaim_caps = AIM_CAPS_INTEROP | AIM_CAPS_ICHAT | AIM_CAPS_ICQSERVERRELAY;
     64static int gaim_caps = AIM_CAPS_INTEROP | AIM_CAPS_ICHAT | AIM_CAPS_ICQSERVERRELAY | AIM_CAPS_CHAT;
    6565static guint8 gaim_features[] = {0x01, 0x01, 0x01, 0x02};
    6666
     
    156156}
    157157
    158 #if 0
    159158static struct chat_connection *find_oscar_chat(struct gaim_connection *gc, int id) {
    160159        GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats;
     
    171170        return c;
    172171}
    173 #endif
     172
    174173
    175174static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc,
     
    10741073}
    10751074
     1075void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv);
     1076void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv);
     1077       
    10761078static int incomingim_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args) {
    1077 #if 0
    10781079        struct gaim_connection *gc = sess->aux_data;
    1079 #endif
    10801080
    10811081        if (args->status != AIM_RENDEZVOUS_PROPOSE)
    10821082                return 1;
    1083 #if 0
     1083
    10841084        if (args->reqclass & AIM_CAPS_CHAT) {
    10851085                char *name = extract_name(args->info.chat.roominfo.name);
     
    10891089                *exch = args->info.chat.roominfo.exchange;
    10901090                m = g_list_append(m, exch);
    1091                 serv_got_chat_invite(gc,
    1092                                      name ? name : args->info.chat.roominfo.name,
    1093                                      userinfo->sn,
    1094                                      (char *)args->msg,
    1095                                      m);
     1091
     1092                char txt[1024];
     1093
     1094                g_snprintf( txt, 1024, "Got an invitation to chatroom %s from %s: %s", name, userinfo->sn, args->msg );
     1095
     1096                struct aim_chat_invitation * inv = g_new0(struct aim_chat_invitation, 1);
     1097
     1098                inv->gc = gc;
     1099                inv->exchange = *exch;
     1100                inv->name = g_strdup(name);
     1101               
     1102                do_ask_dialog( gc, txt, inv, oscar_accept_chat, oscar_reject_chat);
     1103       
    10961104                if (name)
    10971105                        g_free(name);
    10981106        }
    1099 #endif
     1107
    11001108        return 1;
    11011109}
     
    24412449        type2 = va_arg(ap, int);
    24422450        va_end(ap);
    2443 
    2444         if(type2 == 0x0001 || type2 == 0x0002)
    2445                 serv_got_typing(gc, sn, 0);
    2446 
     2451   
     2452        if(type2 == 0x0002) {
     2453                /* User is typing */
     2454                serv_got_typing(gc, sn, 0, 1);
     2455        }
     2456        else if (type2 == 0x0001) {
     2457                /* User has typed something, but is not actively typing (stale) */
     2458                serv_got_typing(gc, sn, 0, 2);
     2459        }
     2460        else {
     2461                /* User has stopped typing */
     2462                serv_got_typing(gc, sn, 0, 0);
     2463        }       
     2464       
    24472465        return 1;
    24482466}
     
    24822500}
    24832501
     2502int oscar_chat_send(struct gaim_connection * gc, int id, char *message)
     2503{
     2504        struct oscar_data * od = (struct oscar_data*)gc->proto_data;
     2505        struct chat_connection * ccon;
     2506       
     2507        if(!(ccon = find_oscar_chat(gc, id)))
     2508                return -1;
     2509       
     2510        int ret;
     2511        guint8 len = strlen(message);
     2512        char *s;
     2513               
     2514        for (s = message; *s; s++)
     2515                if (*s & 128)
     2516                        break;
     2517               
     2518        /* Message contains high ASCII chars, time for some translation! */
     2519        if (*s) {
     2520                s = g_malloc(BUF_LONG);
     2521                /* Try if we can put it in an ISO8859-1 string first.
     2522                   If we can't, fall back to UTF16. */
     2523                if ((ret = do_iconv("UTF-8", "ISO8859-1", message, s, len, BUF_LONG)) >= 0) {
     2524                        len = ret;
     2525                } else if ((ret = do_iconv("UTF-8", "UNICODEBIG", message, s, len, BUF_LONG)) >= 0) {
     2526                        len = ret;
     2527                } else {
     2528                        /* OOF, translation failed... Oh well.. */
     2529                        g_free( s );
     2530                        s = message;
     2531                }
     2532        } else {
     2533                s = message;
     2534        }
     2535               
     2536        ret = aim_chat_send_im(od->sess, ccon->conn, AIM_CHATFLAGS_NOREFLECT, s, len);
     2537               
     2538        if (s != message) {     
     2539                g_free(s);
     2540  }
     2541 
     2542  return (ret >= 0);
     2543}
     2544
     2545void oscar_chat_invite(struct gaim_connection * gc, int id, char *message, char *who)
     2546{
     2547        struct oscar_data * od = (struct oscar_data *)gc->proto_data;
     2548        struct chat_connection *ccon = find_oscar_chat(gc, id);
     2549       
     2550        if (ccon == NULL)
     2551                return;
     2552       
     2553        aim_chat_invite(od->sess, od->conn, who, message ? message : "",
     2554                                        ccon->exchange, ccon->name, 0x0);
     2555}
     2556
     2557void oscar_chat_kill(struct gaim_connection *gc, struct chat_connection *cc)
     2558{
     2559        struct oscar_data *od = (struct oscar_data *)gc->proto_data;
     2560
     2561        /* Notify the conversation window that we've left the chat */
     2562        serv_got_chat_left(gc, cc->id);
     2563
     2564        /* Destroy the chat_connection */
     2565        od->oscar_chats = g_slist_remove(od->oscar_chats, cc);
     2566        if (cc->inpa > 0)
     2567                gaim_input_remove(cc->inpa);
     2568        aim_conn_kill(od->sess, &cc->conn);
     2569        g_free(cc->name);
     2570        g_free(cc->show);
     2571        g_free(cc);
     2572}
     2573
     2574void oscar_chat_leave(struct gaim_connection * gc, int id)
     2575{
     2576        struct chat_connection * ccon = find_oscar_chat(gc, id);
     2577
     2578        if(ccon == NULL)
     2579                return;
     2580
     2581        oscar_chat_kill(gc, ccon);
     2582}
     2583
     2584int oscar_chat_join(struct gaim_connection * gc, char * name)
     2585{
     2586    struct oscar_data * od = (struct oscar_data *)gc->proto_data;
     2587       
     2588        aim_conn_t * cur;
     2589
     2590        if((cur = aim_getconn_type(od->sess, AIM_CONN_TYPE_CHATNAV))) {
     2591       
     2592                return (aim_chatnav_createroom(od->sess, cur, name, 4) == 0);
     2593       
     2594        } else {
     2595                struct create_room * cr = g_new0(struct create_room, 1);
     2596                cr->exchange = 4;
     2597                cr->name = g_strdup(name);
     2598                od->create_rooms = g_slist_append(od->create_rooms, cr);
     2599                aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_CHATNAV);
     2600                return 1;
     2601        }
     2602}
     2603
     2604int oscar_chat_open(struct gaim_connection * gc, char *who)
     2605{
     2606        struct oscar_data * od = (struct oscar_data *)gc->proto_data;
     2607
     2608        static int chat_id = 0;
     2609        char * chatname = g_new0(char, strlen(gc->username)+4);
     2610        g_snprintf(chatname, strlen(gc->username) + 4, "%s%d", gc->username, chat_id++);
     2611 
     2612        int ret = oscar_chat_join(gc, chatname);
     2613
     2614        aim_chat_invite(od->sess, od->conn, who, "", 4, chatname, 0x0);
     2615
     2616        g_free(chatname);
     2617       
     2618        return ret;
     2619}
     2620
     2621void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv)
     2622{
     2623        oscar_chat_join(inv->gc, inv->name);
     2624        g_free(inv->name);
     2625        g_free(inv);
     2626}
     2627
     2628void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv)
     2629{
     2630        g_free(inv->name);
     2631        g_free(inv);
     2632}
     2633
    24842634void oscar_init()
    24852635{
     
    24952645        ret->add_buddy = oscar_add_buddy;
    24962646        ret->remove_buddy = oscar_remove_buddy;
     2647        ret->chat_send = oscar_chat_send;
     2648        ret->chat_invite = oscar_chat_invite;
     2649        ret->chat_leave = oscar_chat_leave;
     2650        ret->chat_open = oscar_chat_open;
    24972651        ret->add_permit = oscar_add_permit;
    24982652        ret->add_deny = oscar_add_deny;
  • protocols/oscar/tlv.c

    r568aaf7 r703f0f7  
    340340}
    341341
     342int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance)
     343{
     344        guint8 *buf;
     345        int buflen;
     346        aim_bstream_t bs;
     347
     348        buflen = 2 + 1 + strlen(roomname) + 2;
     349       
     350        if (!(buf = g_malloc(buflen)))
     351                return 0;
     352
     353        aim_bstream_init(&bs, buf, buflen);
     354
     355        aimbs_put16(&bs, exchange);
     356        aimbs_put8(&bs, strlen(roomname));
     357        aimbs_putraw(&bs, (guint8 *)roomname, strlen(roomname));
     358        aimbs_put16(&bs, instance);
     359
     360        aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf);
     361
     362        g_free(buf);
     363
     364        return 0;
     365}
     366
    342367/**
    343368 * aim_writetlvchain - Write a TLV chain into a data buffer.
  • protocols/proxy.c

    r568aaf7 r703f0f7  
    7373
    7474
    75 static struct sockaddr_in *gaim_gethostbyname(char *host, int port)
     75static struct sockaddr_in *gaim_gethostbyname(const char *host, int port)
    7676{
    7777        static struct sockaddr_in sin;
     
    144144}
    145145
    146 static int proxy_connect_none(char *host, unsigned short port, struct PHB *phb)
     146static int proxy_connect_none(const char *host, unsigned short port, struct PHB *phb)
    147147{
    148148        struct sockaddr_in *sin;
     
    271271}
    272272
    273 static int proxy_connect_http(char *host, unsigned short port, struct PHB *phb)
     273static int proxy_connect_http(const char *host, unsigned short port, struct PHB *phb)
    274274{
    275275        phb->host = g_strdup(host);
     
    355355}
    356356
    357 static int proxy_connect_socks4(char *host, unsigned short port, struct PHB *phb)
     357static int proxy_connect_socks4(const char *host, unsigned short port, struct PHB *phb)
    358358{
    359359        phb->host = g_strdup(host);
     
    537537}
    538538
    539 static int proxy_connect_socks5(char *host, unsigned short port, struct PHB *phb)
     539static int proxy_connect_socks5(const char *host, unsigned short port, struct PHB *phb)
    540540{
    541541        phb->host = g_strdup(host);
     
    578578}
    579579
    580 int proxy_connect(char *host, int port, GaimInputFunction func, gpointer data)
     580int proxy_connect(const char *host, int port, GaimInputFunction func, gpointer data)
    581581{
    582582        struct PHB *phb;
  • protocols/proxy.h

    r568aaf7 r703f0f7  
    5656G_MODULE_EXPORT void gaim_input_remove(gint);
    5757
    58 G_MODULE_EXPORT int proxy_connect(char *host, int port, GaimInputFunction func, gpointer data);
     58G_MODULE_EXPORT int proxy_connect(const char *host, int port, GaimInputFunction func, gpointer data);
    5959
    6060#endif /* _PROXY_H_ */
  • protocols/yahoo/yahoo.c

    r568aaf7 r703f0f7  
    635635{
    636636        struct gaim_connection *gc = byahoo_get_gc_by_id( id );
    637        
    638         serv_got_typing( gc, who, 1 );
     637        if (stat == 1) {
     638                /* User is typing */
     639                serv_got_typing( gc, who, 1, 1 );
     640        }
     641        else {
     642                /* User stopped typing */
     643                serv_got_typing( gc, who, 1, 0 );
     644        }
    639645}
    640646
  • unix.c

    r568aaf7 r703f0f7  
    5353       
    5454        global.helpfile = g_strdup( HELP_FILE );
    55        
     55
    5656        global.conf = conf_load( argc, argv );
    5757        if( global.conf == NULL )
    5858                return( 1 );
    59        
     59
     60
    6061        if( global.conf->runmode == RUNMODE_INETD )
    6162        {
     
    7172        if( i != 0 )
    7273                return( i );
     74
     75        global.storage = storage_init( global.conf->primary_storage,
     76                                                                   global.conf->migrate_storage );
     77        if ( global.storage == NULL) {
     78                log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
     79                return( 1 );
     80        }
     81       
    7382       
    7483        /* Catch some signals to tell the user what's happening before quitting */
     
    8897        if( !getuid() || !geteuid() )
    8998                log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" );
    90         if( access( global.conf->configdir, F_OK ) != 0 )
    91                 log_message( LOGLVL_WARNING, "The configuration directory %s does not exist. Configuration won't be saved.", CONFIG );
    92         else if( access( global.conf->configdir, R_OK ) != 0 || access( global.conf->configdir, W_OK ) != 0 )
    93                 log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to %s.", global.conf->configdir );
    9499        if( help_init( &(global.help) ) == NULL )
    95100                log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE );
Note: See TracChangeset for help on using the changeset viewer.