Changeset 5ebe625


Ignore:
Timestamp:
2006-02-12T07:26:20Z (18 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
f665dab
Parents:
a323a22 (diff), 58bc4e6 (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

Files:
3 added
1 deleted
36 edited
2 moved

Legend:

Unmodified
Added
Removed
  • Makefile

    ra323a22 r5ebe625  
    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 storage.o storage_text.o unix.o url.o user.o
     12objects = account.o bitlbee.o conf.o crypting.o help.o ini.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_text.o unix.o url.o user.o util.o
    1313subdirs = protocols
    1414
  • bitlbee.c

    ra323a22 r5ebe625  
    2929#include "protocols/nogaim.h"
    3030#include "help.h"
     31#include "ipc.h"
    3132#include <signal.h>
    3233#include <stdio.h>
    3334#include <errno.h>
    3435
    35 gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data )
    36 {
    37         size_t size = sizeof( struct sockaddr_in );
    38         struct sockaddr_in conn_info;
    39         int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info,
    40                                      &size );
    41        
    42         log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );
    43         irc_new( new_socket );
    44 
    45         return TRUE;
    46 }
    47  
    48 
     36gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data );
    4937
    5038int bitlbee_daemon_init()
    5139{
     40#ifdef IPV6
     41        struct sockaddr_in6 listen_addr;
     42#else
    5243        struct sockaddr_in listen_addr;
     44#endif
    5345        int i;
    5446        GIOChannel *ch;
     47        FILE *fp;
    5548       
    5649        log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG );
    5750        log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG );
    5851       
    59         global.listen_socket = socket( AF_INET, SOCK_STREAM, 0 );
     52        global.listen_socket = socket( AF_INETx, SOCK_STREAM, 0 );
    6053        if( global.listen_socket == -1 )
    6154        {
     
    6356                return( -1 );
    6457        }
    65         listen_addr.sin_family = AF_INET;
     58       
     59        /* TIME_WAIT (?) sucks.. */
     60        i = 1;
     61        setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i, sizeof( i ) );
     62       
     63#ifdef IPV6
     64        listen_addr.sin6_family = AF_INETx;
     65        listen_addr.sin6_port = htons( global.conf->port );
     66        i = inet_pton( AF_INETx, ipv6_wrap( global.conf->iface ), &listen_addr.sin6_addr );
     67#else
     68        listen_addr.sin_family = AF_INETx;
    6669        listen_addr.sin_port = htons( global.conf->port );
    67         listen_addr.sin_addr.s_addr = inet_addr( global.conf->iface );
    68 
    69         i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( struct sockaddr ) );
     70        i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin_addr );
     71#endif
     72       
     73        if( i != 1 )
     74        {
     75                log_message( LOGLVL_ERROR, "Couldn't parse address `%s'", global.conf->iface );
     76                return( -1 );
     77        }
     78       
     79        i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) );
    7080        if( i == -1 )
    7181        {
     
    7383                return( -1 );
    7484        }
    75 
     85       
    7686        i = listen( global.listen_socket, 10 );
    7787        if( i == -1 )
     
    8090                return( -1 );
    8191        }
    82 
     92       
    8393        ch = g_io_channel_unix_new( global.listen_socket );
    84         g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL );
    85 
     94        global.listen_watch_source_id = g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL );
     95       
    8696#ifndef _WIN32
    8797        if( !global.conf->nofork )
     
    95105                else if( i != 0 )
    96106                        exit( 0 );
    97                 close( 0 );
    98                 close( 1 );
    99                 close( 2 );
     107               
    100108                chdir( "/" );
     109               
     110                /* Sometimes std* are already closed (for example when we're in a RESTARTed
     111                   BitlBee process. So let's only close TTY-fds. */
     112                if( isatty( 0 ) ) close( 0 );
     113                if( isatty( 0 ) ) close( 1 );
     114                if( isatty( 0 ) ) close( 2 );
    101115        }
    102116#endif
     117       
     118        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     119                ipc_master_load_state();
     120       
     121        if( ( fp = fopen( global.conf->pidfile, "w" ) ) )
     122        {
     123                fprintf( fp, "%d\n", (int) getpid() );
     124                fclose( fp );
     125        }
     126        else
     127        {
     128                log_message( LOGLVL_WARNING, "Warning: Couldn't write PID to `%s'", global.conf->pidfile );
     129        }
    103130       
    104131        return( 0 );
     
    124151        if( condition & G_IO_ERR || condition & G_IO_HUP )
    125152        {
    126                 irc_free( irc );
     153                irc_abort( irc, 1, "Read error" );
    127154                return FALSE;
    128155        }
     
    131158        if( st == 0 )
    132159        {
    133                 irc_free( irc );
     160                irc_abort( irc, 1, "Connection reset by peer" );
    134161                return FALSE;
    135162        }
     
    142169                else
    143170                {
    144                         irc_free( irc );
     171                        irc_abort( irc, 1, "Read error: %s", strerror( errno ) );
    145172                        return FALSE;
    146173                }
     
    158185        }
    159186       
    160         if( !irc_process( irc ) )
    161         {
    162                 log_message( LOGLVL_INFO, "Destroying connection with fd %d.", irc->fd );
    163                 irc_free( irc );
     187        irc_process( irc );
     188       
     189        /* Normally, irc_process() shouldn't call irc_free() but irc_abort(). Just in case: */
     190        if( !g_slist_find( irc_connection_list, irc ) )
     191        {
     192                log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd );
    164193                return FALSE;
    165194        }
     
    168197        if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) )
    169198        {
    170                 log_message( LOGLVL_ERROR, "Maximum line length exceeded." );
    171                 irc_free( irc );
     199                irc_abort( irc, 0, "Maximum line length exceeded" );
    172200                return FALSE;
    173201        }
     
    181209        int st, size;
    182210        char *temp;
    183 #ifdef FLOOD_SEND
    184         time_t newtime;
    185 #endif
    186 
    187 #ifdef FLOOD_SEND       
    188         newtime = time( NULL );
    189         if( ( newtime - irc->oldtime ) > FLOOD_SEND_INTERVAL )
    190         {
    191                 irc->sentbytes = 0;
    192                 irc->oldtime = newtime;
    193         }
    194 #endif
    195        
     211
    196212        if( irc->sendbuffer == NULL )
    197213                return( FALSE );
    198214       
    199215        size = strlen( irc->sendbuffer );
    200        
    201 #ifdef FLOOD_SEND
    202         if( ( FLOOD_SEND_BYTES - irc->sentbytes ) > size )
    203                 st = write( irc->fd, irc->sendbuffer, size );
    204         else
    205                 st = write( irc->fd, irc->sendbuffer, ( FLOOD_SEND_BYTES - irc->sentbytes ) );
    206 #else
    207216        st = write( irc->fd, irc->sendbuffer, size );
    208 #endif
    209        
    210         if( st <= 0 )
    211         {
    212                 if( sockerr_again() )
    213                 {
    214                         return TRUE;
    215                 }
    216                 else
    217                 {
    218                         irc_free( irc );
    219                         return FALSE;
    220                 }
    221         }
    222        
    223 #ifdef FLOOD_SEND
    224         irc->sentbytes += st;
    225 #endif         
     217       
     218        if( st == 0 || ( st < 0 && !sockerr_again() ) )
     219        {
     220                irc_abort( irc, 1, "Write error: %s", strerror( errno ) );
     221                return FALSE;
     222        }
     223        else if( st < 0 ) /* && sockerr_again() */
     224        {
     225                return TRUE;
     226        }
    226227       
    227228        if( st == size )
     
    229230                g_free( irc->sendbuffer );
    230231                irc->sendbuffer = NULL;
    231                
    232232                irc->w_watch_source_id = 0;
     233               
     234                if( irc->status == USTATUS_SHUTDOWN )
     235                        irc_free( irc );
     236               
    233237                return( FALSE );
    234238        }
     
    243247}
    244248
     249gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data )
     250{
     251        size_t size = sizeof( struct sockaddr_in );
     252        struct sockaddr_in conn_info;
     253        int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size );
     254        pid_t client_pid = 0;
     255       
     256        if( new_socket == -1 )
     257        {
     258                log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) );
     259                return TRUE;
     260        }
     261       
     262        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     263        {
     264                int fds[2];
     265               
     266                if( socketpair( AF_UNIX, SOCK_STREAM, 0, fds ) == -1 )
     267                {
     268                        log_message( LOGLVL_WARNING, "Could not create IPC socket for client: %s", strerror( errno ) );
     269                        fds[0] = fds[1] = -1;
     270                }
     271               
     272                sock_make_nonblocking( fds[0] );
     273                sock_make_nonblocking( fds[1] );
     274               
     275                client_pid = fork();
     276               
     277                if( client_pid > 0 && fds[0] != -1 )
     278                {
     279                        struct bitlbee_child *child;
     280                       
     281                        child = g_new0( struct bitlbee_child, 1 );
     282                        child->pid = client_pid;
     283                        child->ipc_fd = fds[0];
     284                        child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child );
     285                        child_list = g_slist_append( child_list, child );
     286                       
     287                        log_message( LOGLVL_INFO, "Creating new subprocess with pid %d.", client_pid );
     288                       
     289                        /* Close some things we don't need in the parent process. */
     290                        close( new_socket );
     291                        close( fds[1] );
     292                }
     293                else if( client_pid == 0 )
     294                {
     295                        irc_t *irc;
     296                       
     297                        /* Close the listening socket, we're a client. */
     298                        close( global.listen_socket );
     299                        g_source_remove( global.listen_watch_source_id );
     300                       
     301                        /* Make the connection. */
     302                        irc = irc_new( new_socket );
     303                       
     304                        /* We can store the IPC fd there now. */
     305                        global.listen_socket = fds[1];
     306                        global.listen_watch_source_id = gaim_input_add( fds[1], GAIM_INPUT_READ, ipc_child_read, irc );
     307                       
     308                        close( fds[0] );
     309                       
     310                        ipc_master_free_all();
     311                }
     312        }
     313        else
     314        {
     315                log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );
     316                irc_new( new_socket );
     317        }
     318       
     319        return TRUE;
     320}
     321
    245322void bitlbee_shutdown( gpointer data )
    246323{
     
    252329        g_main_quit( global.loop );
    253330}
    254 
    255 int root_command_string( irc_t *irc, user_t *u, char *command, int flags )
    256 {
    257         char *cmd[IRC_MAX_ARGS];
    258         char *s;
    259         int k;
    260         char q = 0;
    261        
    262         memset( cmd, 0, sizeof( cmd ) );
    263         cmd[0] = command;
    264         k = 1;
    265         for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
    266                 if( *s == ' ' && !q )
    267                 {
    268                         *s = 0;
    269                         while( *++s == ' ' );
    270                         if( *s == '"' || *s == '\'' )
    271                         {
    272                                 q = *s;
    273                                 s ++;
    274                         }
    275                         if( *s )
    276                         {
    277                                 cmd[k++] = s;
    278                                 s --;
    279                         }
    280                 }
    281                 else if( *s == q )
    282                 {
    283                         q = *s = 0;
    284                 }
    285         cmd[k] = NULL;
    286        
    287         return( root_command( irc, cmd ) );
    288 }
    289 
    290 int root_command( irc_t *irc, char *cmd[] )
    291 {       
    292         int i;
    293        
    294         if( !cmd[0] )
    295                 return( 0 );
    296        
    297         for( i = 0; commands[i].command; i++ )
    298                 if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
    299                 {
    300                         if( !cmd[commands[i].required_parameters] )
    301                         {
    302                                 irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
    303                                 return( 0 );
    304                         }
    305                         commands[i].execute( irc, cmd );
    306                         return( 1 );
    307                 }
    308        
    309         irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] );
    310        
    311         return( 1 );
    312 }
    313 
    314 /* Decode%20a%20file%20name                                             */
    315 void http_decode( char *s )
    316 {
    317         char *t;
    318         int i, j, k;
    319        
    320         t = g_new( char, strlen( s ) + 1 );
    321        
    322         for( i = j = 0; s[i]; i ++, j ++ )
    323         {
    324                 if( s[i] == '%' )
    325                 {
    326                         if( sscanf( s + i + 1, "%2x", &k ) )
    327                         {
    328                                 t[j] = k;
    329                                 i += 2;
    330                         }
    331                         else
    332                         {
    333                                 *t = 0;
    334                                 break;
    335                         }
    336                 }
    337                 else
    338                 {
    339                         t[j] = s[i];
    340                 }
    341         }
    342         t[j] = 0;
    343        
    344         strcpy( s, t );
    345         g_free( t );
    346 }
    347 
    348 /* Warning: This one explodes the string. Worst-cases can make the string 3x its original size! */
    349 /* This fuction is safe, but make sure you call it safely as well! */
    350 void http_encode( char *s )
    351 {
    352         char *t;
    353         int i, j;
    354        
    355         t = g_strdup( s );
    356        
    357         for( i = j = 0; t[i]; i ++, j ++ )
    358         {
    359                 if( t[i] <= ' ' || ((unsigned char *)t)[i] >= 128 || t[i] == '%' )
    360                 {
    361                         sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] );
    362                         j += 2;
    363                 }
    364                 else
    365                 {
    366                         s[j] = t[i];
    367                 }
    368         }
    369         s[j] = 0;
    370        
    371         g_free( t );
    372 }
    373 
    374 /* Strip newlines from a string. Modifies the string passed to it. */
    375 char *strip_newlines( char *source )
    376 {
    377         int i; 
    378 
    379         for( i = 0; source[i] != '\0'; i ++ )
    380                 if( source[i] == '\n' || source[i] == '\r' )
    381                         source[i] = 32;
    382        
    383         return source;
    384 }
  • bitlbee.conf

    ra323a22 r5ebe625  
    1414##    and other reasons, the use of daemon-mode is *STRONGLY* discouraged,
    1515##    don't even *think* of reporting bugs when you use this.
     16##  ForkDaemon -- Run as a stand-alone daemon, but keep all clients in separate
     17##    child processes. This should be pretty safe and reliable to use instead
     18##    of inetd mode.
    1619##
    1720# RunMode = Inetd
     
    1922## DaemonPort/DaemonInterface:
    2023##
    21 ## For RunMode=Daemon, here you can specify on what interface and port the
    22 ## daemon should be listening for connections.
     24## For daemon mode, you can specify on what interface and port the daemon
     25## should be listening for connections.
    2326##
    2427# DaemonInterface = 0.0.0.0
     
    4245# AuthPassword = ItllBeBitlBee   ## Heh.. Our slogan. ;-)
    4346
     47## OperPassword
     48##
     49## Password that unlocks access to special operator commands.
     50##
     51# OperPassword = ChangeMe!
     52
    4453## HostName
    4554##
    4655## Normally, BitlBee gets a hostname using getsockname(). If you have a nicer
    4756## alias for your BitlBee daemon, you can set it here and BitlBee will identify
    48 ## itself with that name instead. Leave it commented out if you want BitlBee to
    49 ## use getsockname() to get a hostname.
     57## itself with that name instead.
    5058##
    5159# HostName = localhost
  • bitlbee.h

    ra323a22 r5ebe625  
    112112#include "sock.h"
    113113
    114 typedef struct global_t {
     114typedef struct global {
     115        /* In forked mode, child processes store the fd of the IPC socket here. */
    115116        int listen_socket;
     117        gint listen_watch_source_id;
    116118        help_t *help;
    117119        conf_t *conf;
     
    119121        char *helpfile;
    120122        GMainLoop *loop;
     123        int restart;
    121124} global_t;
    122125
     
    127130gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data );
    128131
    129 int root_command_string( irc_t *irc, user_t *u, char *command, int flags );
    130 int root_command( irc_t *irc, char *command[] );
     132void root_command_string( irc_t *irc, user_t *u, char *command, int flags );
     133void root_command( irc_t *irc, char *command[] );
    131134void bitlbee_shutdown( gpointer data );
    132135double gettime( void );
  • commands.h

    ra323a22 r5ebe625  
    2929#include "bitlbee.h"
    3030
    31 /* Hmm... Linked list? Plleeeeaaase?? ;-) */
    32 
    33 typedef struct command_t
     31typedef struct command
    3432{
    3533        char *command;
    3634        int required_parameters;
    37         int (*execute)(irc_t *, char **args);
     35        void (*execute)(irc_t *, char **args);
     36        int flags;
    3837} command_t;
    3938
    40 int cmd_account( irc_t *irc, char **cmd );
    41 int cmd_help( irc_t *irc, char **args);
    42 int cmd_info( irc_t *irc, char **args);
    43 int cmd_add( irc_t *irc, char **args) ;
    44 int cmd_rename( irc_t *irc, char **args );
    45 int cmd_remove( irc_t *irc, char **args );
    46 int cmd_block( irc_t *irc, char **args );
    47 int cmd_allow( irc_t *irc, char **args );
    48 int cmd_save( irc_t *irc, char **args );
    49 int cmd_set( irc_t *irc, char **args );
    50 int cmd_yesno( irc_t *irc, char **args );
    51 int cmd_identify( irc_t *irc, char **args );
    52 int cmd_register( irc_t *irc, char **args );
    53 int cmd_drop( irc_t *irc, char **args );
    54 int cmd_blist( irc_t *irc, char **cmd );
    55 int cmd_nick( irc_t *irc, char **cmd );
    56 int cmd_qlist( irc_t *irc, char **cmd );
    57 int cmd_import_buddies( irc_t *irc, char **cmd );
    58 int cmd_dump( irc_t *irc, char **cmd );
     39extern const command_t commands[];
    5940
     41#define IRC_CMD_PRE_LOGIN       1
     42#define IRC_CMD_LOGGED_IN       2
     43#define IRC_CMD_OPER_ONLY       4
     44#define IRC_CMD_TO_MASTER       8
    6045
    61 
    62 extern command_t commands[];
     46#define IPC_CMD_TO_CHILDREN     1
    6347
    6448#endif
  • conf.c

    ra323a22 r5ebe625  
    3232#include "ini.h"
    3333#include "url.h"
     34#include "ipc.h"
    3435
    3536#include "protocols/proxy.h"
     
    4647        conf = g_new0( conf_t, 1 );
    4748       
     49#ifdef IPV6
     50        conf->iface = "::";
     51#else
    4852        conf->iface = "0.0.0.0";
     53#endif
    4954        conf->port = 6667;
    5055        conf->nofork = 0;
     
    5358        conf->runmode = RUNMODE_INETD;
    5459        conf->authmode = AUTHMODE_OPEN;
    55         conf->password = NULL;
     60        conf->auth_pass = NULL;
     61        conf->oper_pass = NULL;
    5662        conf->configdir = g_strdup( CONFIG );
    5763        conf->plugindir = g_strdup( PLUGINDIR );
     64        conf->pidfile = g_strdup( "/var/run/bitlbee.pid" );
    5865        conf->motdfile = g_strdup( ETCDIR "/motd.txt" );
    5966        conf->ping_interval = 180;
    6067        conf->ping_timeout = 300;
     68        proxytype = 0;
    6169       
    6270        i = conf_loadini( conf, CONF_FILE );
     
    7179        }
    7280       
    73         while( ( opt = getopt( argc, argv, "i:p:nvIDc:d:h" ) ) >= 0 )
     81        while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:" ) ) >= 0 )
     82        /*     ^^^^ Just to make sure we skip this step from the REHASH handler. */
    7483        {
    7584                if( opt == 'i' )
     
    8695                        conf->port = i;
    8796                }
     97                else if( opt == 'p' )
     98                {
     99                        g_free( conf->pidfile );
     100                        conf->pidfile = g_strdup( optarg );
     101                }
    88102                else if( opt == 'n' )
    89                         conf->nofork=1;
     103                        conf->nofork = 1;
    90104                else if( opt == 'v' )
    91                         conf->verbose=1;
     105                        conf->verbose = 1;
    92106                else if( opt == 'I' )
    93                         conf->runmode=RUNMODE_INETD;
     107                        conf->runmode = RUNMODE_INETD;
    94108                else if( opt == 'D' )
    95                         conf->runmode=RUNMODE_DAEMON;
     109                        conf->runmode = RUNMODE_DAEMON;
     110                else if( opt == 'F' )
     111                        conf->runmode = RUNMODE_FORKDAEMON;
    96112                else if( opt == 'c' )
    97113                {
     
    101117                                CONF_FILE = g_strdup( optarg );
    102118                                g_free( conf );
     119                                /* Re-evaluate arguments. Don't use this option twice,
     120                                   you'll end up in an infinite loop! Hope this trick
     121                                   works with all libcs BTW.. */
     122                                optind = 1;
    103123                                return( conf_load( argc, argv ) );
    104124                        }
     
    118138                                "  -I  Classic/InetD mode. (Default)\n"
    119139                                "  -D  Daemon mode. (Still EXPERIMENTAL!)\n"
     140                                "  -F  Forking daemon. (one process per client)\n"
    120141                                "  -i  Specify the interface (by IP address) to listen on.\n"
    121142                                "      (Default: 0.0.0.0 (any interface))\n"
     
    128149                        return( NULL );
    129150                }
     151                else if( opt == 'R' )
     152                {
     153                        /* We can't load the statefile yet (and should make very sure we do this
     154                           only once), so set the filename here and load the state information
     155                           when initializing ForkDaemon. (This option only makes sense in that
     156                           mode anyway!) */
     157                        ipc_master_set_statefile( optarg );
     158                }
    130159        }
    131160       
     
    157186                                if( g_strcasecmp( ini->value, "daemon" ) == 0 )
    158187                                        conf->runmode = RUNMODE_DAEMON;
     188                                else if( g_strcasecmp( ini->value, "forkdaemon" ) == 0 )
     189                                        conf->runmode = RUNMODE_FORKDAEMON;
    159190                                else
    160191                                        conf->runmode = RUNMODE_INETD;
     192                        }
     193                        else if( g_strcasecmp( ini->key, "pidfile" ) == 0 )
     194                        {
     195                                g_free( conf->pidfile );
     196                                conf->pidfile = g_strdup( ini->value );
    161197                        }
    162198                        else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 )
     
    184220                        else if( g_strcasecmp( ini->key, "authpassword" ) == 0 )
    185221                        {
    186                                 conf->password = g_strdup( ini->value );
     222                                conf->auth_pass = g_strdup( ini->value );
     223                        }
     224                        else if( g_strcasecmp( ini->key, "operpassword" ) == 0 )
     225                        {
     226                                conf->oper_pass = g_strdup( ini->value );
    187227                        }
    188228                        else if( g_strcasecmp( ini->key, "hostname" ) == 0 )
  • conf.h

    ra323a22 r5ebe625  
    2727#define __CONF_H
    2828
    29 typedef enum runmode { RUNMODE_DAEMON, RUNMODE_INETD } runmode_t;
     29typedef enum runmode { RUNMODE_DAEMON, RUNMODE_FORKDAEMON, RUNMODE_INETD } runmode_t;
    3030typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED } authmode_t;
    3131
     
    3838        runmode_t runmode;
    3939        authmode_t authmode;
    40         char *password;
     40        char *auth_pass;
     41        char *oper_pass;
    4142        char *hostname;
    4243        char *configdir;
    4344        char *plugindir;
     45        char *pidfile;
    4446        char *motdfile;
    4547        char *primary_storage;
  • configure

    ra323a22 r5ebe625  
    1414datadir='$prefix/share/bitlbee/'
    1515config='/var/lib/bitlbee/'
     16pidfile='/var/run/bitlbee.pid'
    1617plugindir='$prefix/lib/bitlbee'
    1718
     
    2324debug=0
    2425strip=1
    25 flood=0
    2626ipv6=1
    2727ssl=auto
     
    4747--datadir=...                                           $datadir
    4848--plugindir=...                                         $plugindir
     49--pidfile=...                                           $pidfile
    4950--config=...                                            $config
    5051
     
    7576config=`eval echo "$config/" | sed 's/\/\{1,\}/\//g'`
    7677plugindir=`eval echo "$plugindir/" | sed 's/\/\{1,\}/\//g'`
     78pidfile=`eval echo "$pidfile/" | sed 's/\/\{1,\}/\//g'`
    7779
    7880cat<<EOF>Makefile.settings
     
    8486DATADIR=$datadir
    8587PLUGINDIR=$plugindir
     88PIDFILE=$pidfile
    8689CONFIG=$config
    8790
     
    105108#define VARDIR "$datadir"
    106109#define PLUGINDIR "$plugindir"
     110#define PIDFILE "$pidfile"
    107111#define ARCH "$arch"
    108112#define CPU "$cpu"
     
    289293fi
    290294
    291 if [ "$flood" = 1 ]; then
    292         # echo '#define FLOOD_SEND' >> config.h
    293         echo 'Flood protection is disabled in this release because of too many bugs.' 2> /dev/stderr
    294         rm config.h
    295         rm Makefile.settings
    296         exit 1
     295echo
     296if [ -z "$BITLBEE_VERSION" -a -d .bzr -a -x "`which bzr`" ]; then
     297        rev=`bzr revno`
     298        echo 'Using bzr revision #'$rev' as version number'
     299        BITLBEE_VERSION=\"bzr-$rev\"
    297300fi
    298301
    299302if [ -n "$BITLBEE_VERSION" ]; then
    300         echo
    301303        echo 'Spoofing version number: '$BITLBEE_VERSION
    302304        echo '#undef BITLBEE_VERSION' >> config.h
    303         echo '#define BITLBEE_VERSION '$BITLBEE_VERSION >> config.h;
     305        echo '#define BITLBEE_VERSION '$BITLBEE_VERSION >> config.h
     306        echo
    304307fi
    305308
     
    340343
    341344if [ "$protocols" = "PROTOCOLS = " ]; then
    342         echo
    343345        echo "WARNING: You haven't selected any communication protocol to compile!"
    344346        echo "         Bitlbee will run, but you will be unable to connect to IM servers!"
     
    348350echo "PROTOOBJS = $protoobjs" >> Makefile.settings
    349351
    350 echo
    351352echo Architecture: $arch
    352353case "$arch" in
  • doc/README

    ra323a22 r5ebe625  
    5050
    5151These days, MSN Messenger clients have to connect to the MS Passport servers
    52 through HTTPS. BitlBee can use serveral SSL libraries for this: GnuTLS, NSS
     52through HTTPS. BitlBee can use several SSL libraries for this: GnuTLS, NSS
    5353(which comes with Mozilla) and OpenSSL. OpenSSL is not GPL-compatible in some
    5454situations, so using GnuTLS or NSS is preferred. However, especially on *BSD,
  • irc.c

    ra323a22 r5ebe625  
    2727#include "bitlbee.h"
    2828#include "crypting.h"
     29#include "ipc.h"
    2930
    3031static gboolean irc_userping( gpointer _irc );
     
    4041irc_t *irc_new( int fd )
    4142{
    42         irc_t *irc = g_new0( irc_t, 1 );
    43        
     43        irc_t *irc;
     44        struct hostent *peer;
     45        unsigned int i;
     46        char buf[128];
     47#ifdef IPV6
     48        struct sockaddr_in6 sock[1];
     49#else
    4450        struct sockaddr_in sock[1];
    45 #ifdef IPV6
    46         struct sockaddr_in6 sock6[1];
    4751#endif
    48         struct hostent *peer;
    49         unsigned int i, j;
     52       
     53        irc = g_new0( irc_t, 1 );
    5054       
    5155        irc->fd = fd;
     
    7175       
    7276        i = sizeof( *sock );
    73 #ifdef IPV6
    74         j = sizeof( *sock6 );
    75 #endif
     77       
    7678        if( global.conf->hostname )
    7779                irc->myhost = g_strdup( global.conf->hostname );
    78         else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
    79         {
    80                 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
     80#ifdef IPV6
     81        else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
     82        {
     83                if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
    8184                        irc->myhost = g_strdup( peer->h_name );
    82         }
    83 #ifdef IPV6
    84         else if( getsockname( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 )
    85         {
    86                 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
     85                else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     86                        irc->myhost = g_strdup( ipv6_unwrap( buf ) );
     87        }
     88#else
     89        else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
     90        {
     91                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
    8792                        irc->myhost = g_strdup( peer->h_name );
     93                else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     94                        irc->myhost = g_strdup( buf );
    8895        }
    8996#endif
     
    9198        i = sizeof( *sock );
    9299#ifdef IPV6
    93         j = sizeof( *sock6 );
     100        if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
     101        {
     102                if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
     103                        irc->host = g_strdup( peer->h_name );
     104                else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
     105                        irc->host = g_strdup( ipv6_unwrap( buf ) );
     106        }
     107#else
     108        if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
     109        {
     110                if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
     111                        irc->host = g_strdup( peer->h_name );
     112                else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
     113                        irc->host = g_strdup( buf );
     114        }
    94115#endif
    95         if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
    96         {
    97                 if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
    98                         irc->host = g_strdup( peer->h_name );
    99         }
    100 #ifdef IPV6
    101         else if( getpeername( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 )
    102         {
    103                 if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
    104                         irc->host = g_strdup( peer->h_name );
    105         }
    106 #endif
    107        
     116       
     117        /* Rare, but possible. */
    108118        if( !irc->host ) irc->host = g_strdup( "localhost." );
    109119        if( !irc->myhost ) irc->myhost = g_strdup( "localhost." );
     
    142152}
    143153
     154/* immed=1 makes this function pretty much equal to irc_free(), except that
     155   this one will "log". In case the connection is already broken and we
     156   shouldn't try to write to it. */
     157void irc_abort( irc_t *irc, int immed, char *format, ... )
     158{
     159        if( format != NULL )
     160        {
     161                va_list params;
     162                char *reason;
     163               
     164                va_start( params, format );
     165                reason = g_strdup_vprintf( format, params );
     166                va_end( params );
     167               
     168                if( !immed )
     169                        irc_write( irc, "ERROR :Closing link: %s", reason );
     170               
     171                ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
     172                                   irc->nick ? irc->nick : "(NONE)", irc->host, reason );
     173               
     174                g_free( reason );
     175        }
     176        else
     177        {
     178                if( !immed )
     179                        irc_write( irc, "ERROR :Closing link" );
     180               
     181                ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
     182                                   irc->nick ? irc->nick : "(NONE)", irc->host, "No reason given" );
     183        }
     184       
     185        irc->status = USTATUS_SHUTDOWN;
     186        if( irc->sendbuffer && !immed )
     187        {
     188                /* We won't read from this socket anymore. Instead, we'll connect a timer
     189                   to it that should shut down the connection in a second, just in case
     190                   bitlbee_.._write doesn't do it first. */
     191               
     192                g_source_remove( irc->r_watch_source_id );
     193                irc->r_watch_source_id = g_timeout_add_full( G_PRIORITY_HIGH, 1000, (GSourceFunc) irc_free, irc, NULL );
     194        }
     195        else
     196        {
     197                irc_free( irc );
     198        }
     199}
     200
    144201static gboolean irc_free_userhash( gpointer key, gpointer value, gpointer data )
    145202{
     
    163220                if( storage_save( irc, TRUE ) != STORAGE_OK )
    164221                        irc_usermsg( irc, "Error while saving settings!" );
     222       
     223        closesocket( irc->fd );
    165224       
    166225        if( irc->ping_source_id > 0 )
     
    264323        g_free(irc);
    265324       
    266         if( global.conf->runmode == RUNMODE_INETD )
     325        if( global.conf->runmode == RUNMODE_INETD || global.conf->runmode == RUNMODE_FORKDAEMON )
    267326                g_main_quit( global.loop );
    268327}
     
    282341}
    283342
    284 int irc_process( irc_t *irc )
    285 {
    286         char **lines, *temp;   
     343void irc_process( irc_t *irc )
     344{
     345        char **lines, *temp, **cmd;
    287346        int i;
    288347
    289         if( irc->readbuffer != NULL ) {
    290                 lines = irc_tokenize(irc->readbuffer );
    291                 for( i = 0; *lines[i] != '\0'; i++ ) {
    292                         if( lines[i+1] == NULL ) {
     348        if( irc->readbuffer != NULL )
     349        {
     350                lines = irc_tokenize( irc->readbuffer );
     351               
     352                for( i = 0; *lines[i] != '\0'; i ++ )
     353                {
     354                        if( lines[i+1] == NULL )
     355                        {
    293356                                temp = g_strdup( lines[i] );
    294357                                g_free( irc->readbuffer );
    295358                                irc->readbuffer = temp;
    296                                 i++;
     359                                i ++;
    297360                                break;
    298361                        }                       
    299                         if (!irc_process_line(irc, lines[i])) {
     362                       
     363                        if( ( cmd = irc_parse_line( lines[i] ) ) == NULL )
     364                                continue;
     365                        irc_exec( irc, cmd );
     366                       
     367                        g_free( cmd );
     368                       
     369                        /* Shouldn't really happen, but just in case... */
     370                        if( !g_slist_find( irc_connection_list, irc ) )
     371                        {
    300372                                g_free( lines );
    301                                 return 0;
     373                                return;
    302374                        }
    303375                }
    304                 if(lines[i]!=NULL) {
    305                         g_free(irc->readbuffer);
    306                         irc->readbuffer=NULL;   
    307                 }
     376               
     377                if( lines[i] != NULL )
     378                {
     379                        g_free( irc->readbuffer );
     380                        irc->readbuffer = NULL;
     381                }
     382               
    308383                g_free( lines );
    309384        }
    310         return 1;       
    311385}
    312386
     
    317391
    318392        /* Count the number of elements we're gonna need. */
    319         for(i=0, j=1; buffer[i]!='\0'; i++ ) {
    320                 if(buffer[i]=='\n' )
    321                         if(buffer[i+1]!='\r' && buffer[i+1]!='\n')
    322                                 j++;
     393        for( i = 0, j = 1; buffer[i] != '\0'; i ++ )
     394        {
     395                if( buffer[i] == '\n' )
     396                        if( buffer[i+1] != '\r' && buffer[i+1] != '\n' )
     397                                j ++;
    323398        }
    324399       
    325400        /* Allocate j+1 elements. */
    326         lines=g_new (char *, j+1);
     401        lines = g_new( char *, j + 1 );
    327402       
    328403        /* NULL terminate our list. */
    329         lines[j]=NULL;
    330        
    331         lines[0]=buffer;
     404        lines[j] = NULL;
     405       
     406        lines[0] = buffer;
    332407       
    333408        /* Split the buffer in several strings, using \r\n as our seperator, where \r is optional.
    334409         * Although this is not in the RFC, some braindead ircds (newnet's) use this, so some clients might too.
    335410         */
    336         for( i=0, j=0; buffer[i]!='\0'; i++) {
    337                 if(buffer[i]=='\n') {
    338                         buffer[i]='\0';
    339 
    340                         /* We dont want to read 1 byte before our buffer
    341                          * and (in rare cases) generate a SIGSEGV.
    342                          */
    343                         if(i!=0)
    344                                 if(buffer[i-1]=='\r')
    345                                         buffer[i-1]='\0';
    346                         if(buffer[i+1]!='\r'&&buffer[i+1]!='\n')
    347                                 lines[++j]=buffer+i+1;
    348                 }
    349         }
    350 
    351         return(lines);
    352 }
    353 
    354 int irc_process_line( irc_t *irc, char *line )
     411        for( i = 0, j = 0; buffer[i] != '\0'; i ++)
     412        {
     413                if( buffer[i] == '\n' )
     414                {
     415                        buffer[i] = '\0';
     416                       
     417                        if( i > 0 && buffer[i-1] == '\r' )
     418                                buffer[i-1] = '\0';
     419                        if( buffer[i+1] != '\r' && buffer[i+1] != '\n' )
     420                                lines[++j] = buffer + i + 1;
     421                }
     422        }
     423       
     424        return( lines );
     425}
     426
     427char **irc_parse_line( char *line )
    355428{
    356429        int i, j;
     
    358431       
    359432        /* Move the line pointer to the start of the command, skipping spaces and the optional prefix. */
    360         if(line[0]==':') {
    361                 for(i=0; line[i]!=32; i++);
    362                 line=line+i;
    363         }
    364         for(i=0; line[i]==32; i++);
    365         line=line+i;
    366 
     433        if( line[0] == ':' )
     434        {
     435                for( i = 0; line[i] != ' '; i ++ );
     436                line = line + i;
     437        }
     438        for( i = 0; line[i] == ' '; i ++ );
     439        line = line + i;
     440       
    367441        /* If we're already at the end of the line, return. If not, we're going to need at least one element. */
    368         if(line[0]=='\0')
    369                 return 1;
    370         else
    371                 j=1;   
    372        
    373         /* Count the number of char **cmd elements we're going to need. */     
    374         for(i=0; line[i]!='\0'; i++) {
    375                 if((line[i]==32) && (line[i+1]!=32) && (line[i+1]!='\0') && (line[i+1]!=':'))           
    376                         j++;
    377                 else if((line[i]==':') && (line[i+1]!='\0') && (line[i-1]==32)) {
    378                         j++;
    379                         break;
    380                 }
     442        if( line[0] == '\0')
     443                return NULL;
     444       
     445        /* Count the number of char **cmd elements we're going to need. */
     446        j = 1;
     447        for( i = 0; line[i] != '\0'; i ++ )
     448        {
     449                if( line[i] == ' ' )
     450                {
     451                        j ++;
    381452                       
     453                        if( line[i+1] == ':' )
     454                                break;
     455                }
    382456        }       
    383457
    384458        /* Allocate the space we need. */
    385         cmd=g_new(char *, j+1);
    386         cmd[j]=NULL;
     459        cmd = g_new( char *, j + 1 );
     460        cmd[j] = NULL;
    387461       
    388462        /* Do the actual line splitting, format is:
     
    391465         */
    392466
    393         cmd[0]=line;
    394         for(i=0, j=0; line[i]!='\0'; i++) {
    395                 if((line[i]==32)) {
    396                         line[i]='\0';
    397                         if((line[i+1]!=32) && (line[i+1]!='\0') && (line[i+1]!=':'))           
    398                                 cmd[++j]=line+i+1;
    399                 }
    400                 else if((line[i]==':') && (line[i+1]!='\0') && (line[i-1]=='\0')) {
    401                         cmd[++j]=line+i+1;
    402                         break;
    403                 }
    404         }
    405        
    406         i=irc_exec(irc, cmd);
    407         g_free(cmd);
    408 
    409         return(i);     
    410 }
    411 
    412 int irc_exec( irc_t *irc, char **cmd )
    413 {       
    414         int i;
    415 
    416         if( (global.conf)->authmode == AUTHMODE_CLOSED && irc->status < USTATUS_AUTHORIZED )
    417         {
    418                 if( g_strcasecmp( cmd[0], "PASS" ) == 0 )
    419                 {
    420                         if( !cmd[1] )
     467        cmd[0] = line;
     468        for( i = 0, j = 0; line[i] != '\0'; i ++ )
     469        {
     470                if( line[i] == ' ' )
     471                {
     472                        line[i] = '\0';
     473                        cmd[++j] = line + i + 1;
     474                       
     475                        if( line[i+1] == ':' )
    421476                        {
    422                                 irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
     477                                cmd[j] ++;
     478                                break;
    423479                        }
    424                         else if( strcmp( cmd[1], (global.conf)->password ) == 0 )
    425                         {
    426                                 irc->status = USTATUS_AUTHORIZED;
    427                         }
    428                         else
    429                         {
    430                                 irc_reply( irc, 464, ":Nope, maybe you should try it again..." );
    431                         }
    432                 }
    433                 else
    434                 {
    435                         irc_reply( irc, 464, ":Uhh, fine, but I want the password first." );
    436                 }
    437                
    438                 return( 1 );
    439         }
    440        
    441         if( g_strcasecmp( cmd[0], "USER" ) == 0 )
    442         {
    443                 if( !( cmd[1] && cmd[2] && cmd[3] && cmd[4] ) )
    444                 {
    445                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    446                 }
    447                 else if( irc->user )
    448                 {
    449                         irc_reply( irc, 462, ":You can't change your nick/userinfo" );
    450                 }
    451                 else
    452                 {
    453                         irc->user = g_strdup( cmd[1] );
    454                         irc->realname = g_strdup( cmd[4] );
    455                         if( irc->nick ) irc_login( irc );
    456                 }
    457                 return( 1 );
    458         }
    459         else if( g_strcasecmp( cmd[0], "NICK" ) == 0 )
    460         {
    461                 if( !cmd[1] )
    462                 {
    463                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    464                 }
    465                 else if( irc->nick )
    466                 {
    467                         irc_reply( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" );
    468                 }
    469                 /* This is not clean, but for now it'll have to be like this... */
    470                 else if( ( nick_cmp( cmd[1], irc->mynick ) == 0 ) || ( nick_cmp( cmd[1], NS_NICK ) == 0 ) )
    471                 {
    472                         irc_reply( irc, 433, ":This nick is already in use" );
    473                 }
    474                 else if( !nick_ok( cmd[1] ) )
    475                 {
    476                         /* [SH] Invalid characters. */
    477                         irc_reply( irc, 432, ":This nick contains invalid characters" );
    478                 }
    479                 else
    480                 {
    481                         irc->nick = g_strdup( cmd[1] );
    482                         if( irc->user ) irc_login( irc );
    483                 }
    484                 return( 1 );
    485         }
    486         else if( g_strcasecmp( cmd[0], "QUIT" ) == 0 )
    487         {
    488                 irc_write( irc, "ERROR :%s%s", cmd[1]?"Quit: ":"", cmd[1]?cmd[1]:"Client Quit" );
    489                 g_io_channel_close( irc->io_channel );
    490                 return( 0 );
    491         }
    492        
    493         if( !irc->user || !irc->nick )
    494         {
    495                 irc_reply( irc, 451, ":Register first" );
    496                 return( 1 );
    497         }
    498        
    499         if( g_strcasecmp( cmd[0], "PING" ) == 0 )
    500         {
    501                 irc_write( irc, ":%s PONG %s :%s", irc->myhost, irc->myhost, cmd[1]?cmd[1]:irc->myhost );
    502         }
    503         else if( g_strcasecmp( cmd[0], "MODE" ) == 0 )
    504         {
    505                 if( !cmd[1] )
    506                 {
    507                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    508                 }
    509                 else if( *cmd[1] == '#' || *cmd[1] == '&' )
    510                 {
    511                         if( cmd[2] )
    512                         {
    513                                 if( *cmd[2] == '+' || *cmd[2] == '-' )
    514                                         irc_reply( irc, 477, "%s :Can't change channel modes", cmd[1] );
    515                                 else if( *cmd[2] == 'b' )
    516                                         irc_reply( irc, 368, "%s :No bans possible", cmd[1] );
    517                         }
    518                         else
    519                                 irc_reply( irc, 324, "%s +%s", cmd[1], CMODE );
    520                 }
    521                 else
    522                 {
    523                         if( nick_cmp( cmd[1], irc->nick ) == 0 )
    524                         {
    525                                 if( cmd[2] )
    526                                         irc_umode_set( irc, irc->nick, cmd[2] );
    527                         }
    528                         else
    529                                 irc_reply( irc, 502, ":Don't touch their modes" );
    530                 }
    531         }
    532         else if( g_strcasecmp( cmd[0], "NAMES" ) == 0 )
    533         {
    534                 irc_names( irc, cmd[1]?cmd[1]:irc->channel );
    535         }
    536         else if( g_strcasecmp( cmd[0], "PART" ) == 0 )
    537         {
    538                 struct conversation *c;
    539                
    540                 if( !cmd[1] )
    541                 {
    542                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    543                 }
    544                 else if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
    545                 {
    546                         user_t *u = user_find( irc, irc->nick );
    547                        
    548                         /* Not allowed to leave control channel */
    549                         irc_part( irc, u, irc->channel );
    550                         irc_join( irc, u, irc->channel );
    551                 }
    552                 else if( ( c = conv_findchannel( cmd[1] ) ) )
    553                 {
    554                         user_t *u = user_find( irc, irc->nick );
    555                        
    556                         irc_part( irc, u, c->channel );
    557                        
    558                         if( c->gc && c->gc->prpl )
    559                         {
    560                                 c->joined = 0;
    561                                 c->gc->prpl->chat_leave( c->gc, c->id );
    562                         }
    563                 }
    564                 else
    565                 {
    566                         irc_reply( irc, 403, "%s :No such channel", cmd[1] );
    567                 }
    568         }
    569         else if( g_strcasecmp( cmd[0], "JOIN" ) == 0 )
    570         {
    571                 if( !cmd[1] )
    572                 {
    573                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    574                 }
    575                 else if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
    576                         ; /* Dude, you're already there...
    577                              RFC doesn't have any reply for that though? */
    578                 else if( cmd[1] )
    579                 {
    580                         if( ( cmd[1][0] == '#' || cmd[1][0] == '&' ) && cmd[1][1] )
    581                         {
    582                                 user_t *u = user_find( irc, cmd[1] + 1 );
    583                                
    584                                 if( u && u->gc && u->gc->prpl && u->gc->prpl->chat_open )
    585                                 {
    586                                         irc_reply( irc, 403, "%s :Initializing groupchat in a different channel", cmd[1] );
    587                                        
    588                                         if( !u->gc->prpl->chat_open( u->gc, u->handle ) )
    589                                         {
    590                                                 irc_usermsg( irc, "Could not open a groupchat with %s, maybe you don't have a connection to him/her yet?", u->nick );
    591                                         }
    592                                 }
    593                                 else
    594                                 {
    595                                         irc_reply( irc, 403, "%s :Groupchats are not possible with %s", cmd[1], cmd[1]+1 );
    596                                 }
    597                         }
    598                         else
    599                         {
    600                                 irc_reply( irc, 403, "%s :No such channel", cmd[1] );
    601                         }
    602                 }
    603         }
    604         else if( g_strcasecmp( cmd[0], "INVITE" ) == 0 )
    605         {
    606                 if( cmd[1] && cmd[2] )
    607                         irc_invite( irc, cmd[1], cmd[2] );
    608                 else
    609                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    610         }
    611         else if( g_strcasecmp( cmd[0], "PRIVMSG" ) == 0 || g_strcasecmp( cmd[0], "NOTICE" ) == 0 )
    612         {
    613                 if( !cmd[1] )
    614                 {
    615                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    616                 }
    617                 else if ( !cmd[2] )
    618                 {
    619                         irc_reply( irc, 412, ":No text to send" );
    620                 }
    621                 else if ( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 )
    622                 {
    623                         irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] );
    624                 }
    625                 else
    626                 {
    627                         if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
    628                         {
    629                                 unsigned int i;
    630                                 char *t = set_getstr( irc, "default_target" );
    631                                
    632                                 if( g_strcasecmp( t, "last" ) == 0 && irc->last_target )
    633                                         cmd[1] = irc->last_target;
    634                                 else if( g_strcasecmp( t, "root" ) == 0 )
    635                                         cmd[1] = irc->mynick;
    636                                
    637                                 for( i = 0; i < strlen( cmd[2] ); i ++ )
    638                                 {
    639                                         if( cmd[2][i] == ' ' ) break;
    640                                         if( cmd[2][i] == ':' || cmd[2][i] == ',' )
    641                                         {
    642                                                 cmd[1] = cmd[2];
    643                                                 cmd[2] += i;
    644                                                 *cmd[2] = 0;
    645                                                 while( *(++cmd[2]) == ' ' );
    646                                                 break;
    647                                         }
    648                                 }
    649                                
    650                                 irc->is_private = 0;
    651                                
    652                                 if( cmd[1] != irc->last_target )
    653                                 {
    654                                         if( irc->last_target )
    655                                                 g_free( irc->last_target );
    656                                         irc->last_target = g_strdup( cmd[1] );
    657                                 }
    658                         }
    659                         else
    660                         {
    661                                 irc->is_private = 1;
    662                         }
    663                         irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? IM_FLAG_AWAY : 0 );
    664                 }
    665         }
    666         else if( g_strcasecmp( cmd[0], "WHO" ) == 0 )
    667         {
    668                 irc_who( irc, cmd[1] );
    669         }
    670         else if( g_strcasecmp( cmd[0], "USERHOST" ) == 0 )
    671         {
    672                 user_t *u;
    673                
    674                 if( !cmd[1] )
    675                 {
    676                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    677                 }
    678                 /* [TV] Usable USERHOST-implementation according to
    679                         RFC1459. Without this, mIRC shows an error
    680                         while connecting, and the used way of rejecting
    681                         breaks standards.
    682                 */
    683                
    684                 for( i = 1; cmd[i]; i ++ )
    685                         if( ( u = user_find( irc, cmd[i] ) ) )
    686                         {
    687                                 if( u->online && u->away )
    688                                         irc_reply( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host );
    689                                 else
    690                                         irc_reply( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host );
    691                         }
    692         }
    693         else if( g_strcasecmp( cmd[0], "ISON" ) == 0 )
    694         {
    695                 user_t *u;
    696                 char buff[IRC_MAX_LINE];
    697                 int lenleft;
    698                
    699                 buff[0] = '\0';
    700                
    701                 /* [SH] Leave room for : and \0 */
    702                 lenleft = IRC_MAX_LINE - 2;
    703                
    704                 for( i = 1; cmd[i]; i ++ )
    705                 {
    706                         if( ( u = user_find( irc, cmd[i] ) ) && u->online )
    707                         {
    708                                 /* [SH] Make sure we don't use too much buffer space. */
    709                                 lenleft -= strlen( u->nick ) + 1;
    710                                
    711                                 if( lenleft < 0 )
    712                                 {
    713                                         break;
    714                                 }
    715                                
    716                                 /* [SH] Add the nick to the buffer. Note
    717                                  * that an extra space is always added. Even
    718                                  * if it's the last nick in the list. Who
    719                                  * cares?
    720                                  */
    721                                
    722                                 strcat( buff, u->nick );
    723                                 strcat( buff, " " );
    724                         }
    725                 }
    726                
    727                 /* [WvG] Well, maybe someone cares, so why not remove it? */
    728                 if( strlen( buff ) > 0 )
    729                         buff[strlen(buff)-1] = '\0';
    730                
    731                 /* [SH] By the way, that really *was* WvG talking. */
    732                 /* [WvG] Really? */
    733                 /* [SH] Yeah... But *this* is WvG talking too. ;-P */
    734                 /* [WvG] *sigh* */
    735                
    736                 irc_reply( irc, 303, ":%s", buff );
    737         }
    738         else if( g_strcasecmp( cmd[0], "WATCH" ) == 0 )
    739         {
    740                 /* Obviously we could also mark a user structure as being
    741                    watched, but what if the WATCH command is sent right
    742                    after connecting? The user won't exist yet then... */
    743                 for( i = 1; cmd[i]; i ++ )
    744                 {
    745                         char *nick;
    746                         user_t *u;
    747                        
    748                         if( !cmd[i][0] || !cmd[i][1] )
    749                                 break;
    750                        
    751                         nick = g_strdup( cmd[i] + 1 );
    752                         nick_lc( nick );
    753                        
    754                         u = user_find( irc, nick );
    755                        
    756                         if( cmd[i][0] == '+' )
    757                         {
    758                                 if( !g_hash_table_lookup( irc->watches, nick ) )
    759                                         g_hash_table_insert( irc->watches, nick, nick );
    760                                
    761                                 if( u && u->online )
    762                                         irc_reply( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, time( NULL ), "is online" );
    763                                 else
    764                                         irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", time( NULL ), "is offline" );
    765                         }
    766                         else if( cmd[i][0] == '-' )
    767                         {
    768                                 gpointer okey, ovalue;
    769                                
    770                                 if( g_hash_table_lookup_extended( irc->watches, nick, &okey, &ovalue ) )
    771                                 {
    772                                         g_free( okey );
    773                                         g_hash_table_remove( irc->watches, okey );
    774                                        
    775                                         irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
    776                                 }
    777                         }
    778                 }
    779         }
    780         else if( g_strcasecmp( cmd[0], "TOPIC" ) == 0 )
    781         {
    782                 if( cmd[1] && cmd[2] )
    783                         irc_reply( irc, 482, "%s :Cannot change topic", cmd[1] );
    784                 else if( cmd[1] )
    785                         irc_topic( irc, cmd[1] );
    786                 else
    787                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    788         }
    789         else if( g_strcasecmp( cmd[0], "AWAY" ) == 0 )
    790         {
    791                 irc_away( irc, cmd[1] );
    792         }
    793         else if( g_strcasecmp( cmd[0], "WHOIS" ) == 0 )
    794         {
    795                 if( cmd[1] )
    796                 {
    797                         irc_whois( irc, cmd[1] );
    798                 }
    799                 else
    800                 {
    801                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    802                 }
    803         }
    804         else if( g_strcasecmp( cmd[0], "WHOWAS" ) == 0 )
    805         {
    806                 /* For some reason irssi tries a whowas when whois fails. We can
    807                    ignore this, but then the user never gets a "user not found"
    808                    message from irssi which is a bit annoying. So just respond
    809                    with not-found and irssi users will get better error messages */
    810                
    811                 if( cmd[1] )
    812                 {
    813                         irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] );
    814                         irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] );
    815                 }
    816                 else
    817                 {
    818                         irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    819                 }
    820         }
    821         else if( ( g_strcasecmp( cmd[0], "NICKSERV" ) == 0 ) || ( g_strcasecmp( cmd[0], "NS" ) == 0 ) )
    822         {
    823                 /* [SH] This aliases the NickServ command to PRIVMSG root */
    824                 /* [TV] This aliases the NS command to PRIVMSG root as well */
    825                 root_command( irc, cmd + 1 );
    826         }
    827         else if( g_strcasecmp( cmd[0], "MOTD" ) == 0 )
    828         {
    829                 irc_motd( irc );
    830         }
    831         else if( g_strcasecmp( cmd[0], "PONG" ) == 0 )
    832         {
    833                 /* We could check the value we get back from the user, but in
    834                    fact we don't care, we're just happy he's still alive. */
    835                 irc->last_pong = gettime();
    836                 irc->pinging = 0;
    837         }
    838         else if( g_strcasecmp( cmd[0], "COMPLETIONS" ) == 0 )
    839         {
    840                 user_t *u = user_find( irc, irc->mynick );
    841                 help_t *h;
    842                 set_t *s;
    843                 int i;
    844                
    845                 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "OK" );
    846                
    847                 for( i = 0; commands[i].command; i ++ )
    848                         irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", commands[i].command );
    849                
    850                 for( h = global.help; h; h = h->next )
    851                         irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->string );
    852                
    853                 for( s = irc->set; s; s = s->next )
    854                         irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS set ", s->key );
    855                
    856                 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" );
    857         }
    858         else if( set_getint( irc, "debug" ) )
    859         {
    860                 irc_usermsg( irc, "\002--- Unknown command:" );
    861                 for( i = 0; cmd[i]; i ++ ) irc_usermsg( irc, "%s", cmd[i] );
    862                 irc_usermsg( irc, "\002--------------------" );
    863         }
    864        
    865         return( 1 );
     480                }
     481        }
     482       
     483        return cmd;
     484}
     485
     486char *irc_build_line( char **cmd )
     487{
     488        int i, len;
     489        char *s;
     490       
     491        if( cmd[0] == NULL )
     492                return NULL;
     493       
     494        len = 1;
     495        for( i = 0; cmd[i]; i ++ )
     496                len += strlen( cmd[i] ) + 1;
     497       
     498        if( strchr( cmd[i-1], ' ' ) != NULL )
     499                len ++;
     500       
     501        s = g_new0( char, len + 1 );
     502        for( i = 0; cmd[i]; i ++ )
     503        {
     504                if( cmd[i+1] == NULL && strchr( cmd[i], ' ' ) != NULL )
     505                        strcat( s, ":" );
     506               
     507                strcat( s, cmd[i] );
     508               
     509                if( cmd[i+1] )
     510                        strcat( s, " " );
     511        }
     512        strcat( s, "\r\n" );
     513       
     514        return s;
    866515}
    867516
     
    923572        if( irc->sendbuffer != NULL ) {
    924573                size = strlen( irc->sendbuffer ) + strlen( line );
    925 #ifdef FLOOD_SEND
    926                 if( size > FLOOD_SEND_MAXBUFFER ) {
    927                         /* Die flooder, die! >:) */
    928 
    929                         g_free(irc->sendbuffer);
    930                        
    931                         /* We need the \r\n at the start because else we might append our string to a half
    932                          * sent line. A bit hackish, but it works.
    933                          */
    934                         irc->sendbuffer = g_strdup( "\r\nERROR :Sendq Exceeded\r\n" );
    935                         irc->quit = 1;
    936                        
    937                         return;
    938                 }
    939 #endif
    940574                irc->sendbuffer = g_renew ( char, irc->sendbuffer, size + 1 );
    941575                strcpy( ( irc->sendbuffer + strlen( irc->sendbuffer ) ), line );
     
    1037671}
    1038672
    1039 void irc_who( irc_t *irc, char *channel )
    1040 {
    1041         user_t *u = irc->users;
    1042         struct conversation *c;
    1043         GList *l;
    1044        
    1045         if( !channel || *channel == '0' || *channel == '*' || !*channel )
    1046                 while( u )
    1047                 {
    1048                         irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", u->online ? irc->channel : "*", u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
    1049                         u = u->next;
    1050                 }
    1051         else if( g_strcasecmp( channel, irc->channel ) == 0 )
    1052                 while( u )
    1053                 {
    1054                         if( u->online )
    1055                                 irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
    1056                         u = u->next;
    1057                 }
    1058         else if( ( c = conv_findchannel( channel ) ) )
    1059                 for( l = c->in_room; l; l = l->next )
    1060                 {
    1061                         if( ( u = user_findhandle( c->gc, l->data ) ) )
    1062                                 irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
    1063                 }
    1064         else if( ( u = user_find( irc, channel ) ) )
    1065                 irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
    1066        
    1067         irc_reply( irc, 315, "%s :End of /WHO list.", channel?channel:"**" );
     673int irc_check_login( irc_t *irc )
     674{
     675        if( irc->user && irc->nick )
     676        {
     677                if( global.conf->authmode == AUTHMODE_CLOSED && irc->status < USTATUS_AUTHORIZED )
     678                {
     679                        irc_reply( irc, 464, ":This server is password-protected." );
     680                        return 0;
     681                }
     682                else
     683                {
     684                        irc_login( irc );
     685                        return 1;
     686                }
     687        }
     688        else
     689        {
     690                /* More information needed. */
     691                return 0;
     692        }
    1068693}
    1069694
     
    1075700        irc_reply( irc,   2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->myhost );
    1076701        irc_reply( irc,   3, ":%s", IRCD_INFO );
    1077         irc_reply( irc,   4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES, CMODES );
     702        irc_reply( irc,   4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES );
    1078703        irc_reply( irc,   5, "PREFIX=(ov)@+ CHANTYPES=#& CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", CMODES, MAX_NICK_LENGTH - 1 );
    1079704        irc_motd( irc );
    1080         irc_umode_set( irc, irc->myhost, "+" UMODE );
     705        irc_umode_set( irc, "+" UMODE, 1 );
    1081706
    1082707        u = user_add( irc, irc->mynick );
     
    1100725        u->realname = g_strdup( irc->realname );
    1101726        u->online = 1;
    1102 //      u->send_handler = msg_echo;
    1103727        irc_spawn( irc, u );
    1104728       
    1105729        irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\nIf you've never used BitlBee before, please do read the help information using the \x02help\x02 command. Lots of FAQ's are answered there." );
     730       
     731        if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
     732                ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
    1106733       
    1107734        irc->status = USTATUS_LOGGED_IN;
     
    1156783                }
    1157784                irc_reply( irc, 376, ":End of MOTD" );
    1158                 closesocket( fd );
     785                close( fd );
    1159786        }
    1160787}
     
    1177804}
    1178805
    1179 void irc_whois( irc_t *irc, char *nick )
    1180 {
    1181         user_t *u = user_find( irc, nick );
    1182        
    1183         if( u )
    1184         {
    1185                 irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
    1186                
    1187                 if( u->gc )
    1188                         irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->gc->user->username,
    1189                                    *u->gc->user->proto_opt[0] ? u->gc->user->proto_opt[0] : "", u->gc->prpl->name );
    1190                 else
    1191                         irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
    1192                
    1193                 if( !u->online )
    1194                         irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" );
    1195                 else if( u->away )
    1196                         irc_reply( irc, 301, "%s :%s", u->nick, u->away );
    1197                
    1198                 irc_reply( irc, 318, "%s :End of /WHOIS list", nick );
    1199         }
    1200         else
    1201         {
    1202                 irc_reply( irc, 401, "%s :Nick does not exist", nick );
    1203         }
    1204 }
    1205 
    1206 
    1207 void irc_umode_set( irc_t *irc, char *who, char *s )
    1208 {
     806void irc_umode_set( irc_t *irc, char *s, int allow_priv )
     807{
     808        /* allow_priv: Set to 0 if s contains user input, 1 if you want
     809           to set a "privileged" mode (+o, +R, etc). */
    1209810        char m[256], st = 1, *t;
    1210811        int i;
     
    1219820                if( *t == '+' || *t == '-' )
    1220821                        st = *t == '+';
    1221                 else
     822                else if( st == 0 || ( strchr( UMODES, *t ) || ( allow_priv && strchr( UMODES_PRIV, *t ) ) ) )
    1222823                        m[(int)*t] = st;
    1223824        }
     
    1226827       
    1227828        for( i = 0; i < 256 && strlen( irc->umode ) < ( sizeof( irc->umode ) - 1 ); i ++ )
    1228                 if( m[i] && strchr( UMODES, i ) )
     829                if( m[i] )
    1229830                        irc->umode[strlen(irc->umode)] = i;
    1230831       
    1231832        irc_reply( irc, 221, "+%s", irc->umode );
    1232 }
    1233 
    1234 int irc_away( irc_t *irc, char *away )
    1235 {
    1236         user_t *u = user_find( irc, irc->nick );
    1237         GSList *c = get_connections();
    1238        
    1239         if( !u ) return( 0 );
    1240        
    1241         if( away && *away )
    1242         {
    1243                 int i, j;
    1244                
    1245                 /* Copy away string, but skip control chars. Mainly because
    1246                    Jabber really doesn't like them. */
    1247                 u->away = g_malloc( strlen( away ) + 1 );
    1248                 for( i = j = 0; away[i]; i ++ )
    1249                         if( ( u->away[j] = away[i] ) >= ' ' )
    1250                                 j ++;
    1251                 u->away[j] = 0;
    1252                
    1253                 irc_reply( irc, 306, ":You're now away: %s", u->away );
    1254                 /* irc_umode_set( irc, irc->myhost, "+a" ); */
    1255         }
    1256         else
    1257         {
    1258                 if( u->away ) g_free( u->away );
    1259                 u->away = NULL;
    1260                 /* irc_umode_set( irc, irc->myhost, "-a" ); */
    1261                 irc_reply( irc, 305, ":Welcome back" );
    1262         }
    1263        
    1264         while( c )
    1265         {
    1266                 if( ((struct gaim_connection *)c->data)->flags & OPT_LOGGED_IN )
    1267                         proto_away( c->data, u->away );
    1268                
    1269                 c = c->next;
    1270         }
    1271        
    1272         return( 1 );
    1273833}
    1274834
     
    1324884        }
    1325885        g_free( nick );
    1326 }
    1327 
    1328 void irc_invite( irc_t *irc, char *nick, char *channel )
    1329 {
    1330         struct conversation *c = conv_findchannel( channel );
    1331         user_t *u = user_find( irc, nick );
    1332        
    1333         if( u && c && ( u->gc == c->gc ) )
    1334                 if( c->gc && c->gc->prpl && c->gc->prpl->chat_invite )
    1335                 {
    1336                         c->gc->prpl->chat_invite( c->gc, c->id, "", u->handle );
    1337                         irc_reply( irc, 341, "%s %s", nick, channel );
    1338                         return;
    1339                 }
    1340        
    1341         irc_reply( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
    1342886}
    1343887
     
    1430974               
    1431975                if( u->send_handler )
    1432                         return( u->send_handler( irc, u, s, flags ) );
     976                {
     977                        u->send_handler( irc, u, s, flags );
     978                        return 1;
     979                }
    1433980        }
    1434981        else if( c && c->gc && c->gc->prpl )
     
    14561003}
    14571004
    1458 int buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
    1459 {
    1460         if( !u || !u->gc ) return( 0 );
     1005void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
     1006{
     1007        if( !u || !u->gc ) return;
    14611008       
    14621009        if( set_getint( irc, "buddy_sendbuffer" ) && set_getint( irc, "buddy_sendbuffer_delay" ) > 0 )
     
    14941041                        g_source_remove( u->sendbuf_timer );
    14951042                u->sendbuf_timer = g_timeout_add( delay, buddy_send_handler_delayed, u );
    1496                
    1497                 return( 1 );
    14981043        }
    14991044        else
    15001045        {
    1501                 return( serv_send_im( irc, u, msg, flags ) );
     1046                serv_send_im( irc, u, msg, flags );
    15021047        }
    15031048}
     
    16041149        if( rv > 0 )
    16051150        {
    1606                 irc_write( irc, "ERROR :Closing Link: Ping Timeout: %d seconds", rv );
    1607                 irc_free( irc );
     1151                irc_abort( irc, 0, "Ping Timeout: %d seconds", rv );
    16081152                return FALSE;
    16091153        }
  • irc.h

    ra323a22 r5ebe625  
    3333#define IRC_PING_STRING "PinglBee"
    3434
    35 /* #define FLOOD_SEND
    36  * Not yet enabled by default due to some problems.
    37  */
    38 #define FLOOD_SEND_INTERVAL 30
    39 #define FLOOD_SEND_BYTES (1024*10)
    40 #define FLOOD_SEND_MAXBUFFER (1024*20)
    41 
    42 #define UMODES "ais"
     35#define UMODES "iasw"
     36#define UMODES_PRIV "Ro"
    4337#define CMODES "nt"
    4438#define CMODE "t"
     
    4741typedef enum
    4842{
    49         USTATUS_OFFLINE,
     43        USTATUS_OFFLINE = 0,
    5044        USTATUS_AUTHORIZED,
    5145        USTATUS_LOGGED_IN,
    52         USTATUS_IDENTIFIED
     46        USTATUS_IDENTIFIED,
     47        USTATUS_SHUTDOWN = -1
    5348} irc_status_t;
    5449
     
    110105
    111106irc_t *irc_new( int fd );
     107void irc_abort( irc_t *irc, int immed, char *format, ... );
    112108void irc_free( irc_t *irc );
    113109
    114 int irc_exec( irc_t *irc, char **cmd );
    115 int irc_process( irc_t *irc );
    116 int irc_process_line( irc_t *irc, char *line );
     110void irc_exec( irc_t *irc, char **cmd );
     111void irc_process( irc_t *irc );
     112char **irc_parse_line( char *line );
     113char *irc_build_line( char **cmd );
    117114
    118115void irc_vawrite( irc_t *irc, char *format, va_list params );
     
    124121
    125122void irc_login( irc_t *irc );
     123int irc_check_login( irc_t *irc );
    126124void irc_motd( irc_t *irc );
    127125void irc_names( irc_t *irc, char *channel );
    128126void irc_topic( irc_t *irc, char *channel );
    129 void irc_umode_set( irc_t *irc, char *who, char *s );
     127void irc_umode_set( irc_t *irc, char *s, int allow_priv );
    130128void irc_who( irc_t *irc, char *channel );
    131129void irc_spawn( irc_t *irc, user_t *u );
     
    136134void irc_invite( irc_t *irc, char *nick, char *channel );
    137135void irc_whois( irc_t *irc, char *nick );
    138 int irc_away( irc_t *irc, char *away );
    139136void irc_setpass( irc_t *irc, const char *pass ); /* USE WITH CAUTION! */
    140137
     
    144141int irc_noticefrom( irc_t *irc, char *nick, char *msg );
    145142
    146 int buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags );
     143void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags );
    147144
    148145#endif
  • log.c

    ra323a22 r5ebe625  
    3838        openlog("bitlbee", LOG_PID, LOG_DAEMON);       
    3939
    40         logoutput.informational=&log_null;
    41         logoutput.warning=&log_null;
    42         logoutput.error=&log_null;
     40        logoutput.informational = &log_null;
     41        logoutput.warning = &log_null;
     42        logoutput.error = &log_null;
    4343#ifdef DEBUG
    44         logoutput.debug=&log_null;
     44        logoutput.debug = &log_null;
    4545#endif
    4646
     
    5151        /* I know it's ugly, but it works and I didn't feel like messing with pointer to function pointers */
    5252
    53         if(level==LOGLVL_INFO) {
    54                 if(output==LOGOUTPUT_NULL)
    55                         logoutput.informational=&log_null;     
    56                 else if(output==LOGOUTPUT_IRC)
    57                         logoutput.informational=&log_irc;       
    58                 else if(output==LOGOUTPUT_SYSLOG)
    59                         logoutput.informational=&log_syslog;   
    60                 else if(output==LOGOUTPUT_CONSOLE)
    61                         logoutput.informational=&log_console;   
     53        if(level == LOGLVL_INFO) {
     54                if(output == LOGOUTPUT_NULL)
     55                        logoutput.informational = &log_null;   
     56                else if(output == LOGOUTPUT_IRC)
     57                        logoutput.informational = &log_irc;     
     58                else if(output == LOGOUTPUT_SYSLOG)
     59                        logoutput.informational = &log_syslog; 
     60                else if(output == LOGOUTPUT_CONSOLE)
     61                        logoutput.informational = &log_console;
    6262        }
    63         else if(level==LOGLVL_WARNING) {
    64                 if(output==LOGOUTPUT_NULL)
    65                         logoutput.warning=&log_null;
    66                 else if(output==LOGOUTPUT_IRC)
    67                         logoutput.warning=&log_irc;
    68                 else if(output==LOGOUTPUT_SYSLOG)
    69                         logoutput.warning=&log_syslog;
    70                 else if(output==LOGOUTPUT_CONSOLE)
    71                         logoutput.warning=&log_console;
     63        else if(level == LOGLVL_WARNING) {
     64                if(output == LOGOUTPUT_NULL)
     65                        logoutput.warning = &log_null;
     66                else if(output == LOGOUTPUT_IRC)
     67                        logoutput.warning = &log_irc;
     68                else if(output == LOGOUTPUT_SYSLOG)
     69                        logoutput.warning = &log_syslog;
     70                else if(output == LOGOUTPUT_CONSOLE)
     71                        logoutput.warning = &log_console;
    7272        }
    73         else if(level==LOGLVL_ERROR) {
    74                 if(output==LOGOUTPUT_NULL)
    75                         logoutput.error=&log_null;
    76                 else if(output==LOGOUTPUT_IRC)
    77                         logoutput.error=&log_irc;
    78                 else if(output==LOGOUTPUT_SYSLOG)
    79                         logoutput.error=&log_syslog;
    80                 else if(output==LOGOUTPUT_CONSOLE)
    81                         logoutput.error=&log_console;
     73        else if(level == LOGLVL_ERROR) {
     74                if(output == LOGOUTPUT_NULL)
     75                        logoutput.error = &log_null;
     76                else if(output == LOGOUTPUT_IRC)
     77                        logoutput.error = &log_irc;
     78                else if(output == LOGOUTPUT_SYSLOG)
     79                        logoutput.error = &log_syslog;
     80                else if(output == LOGOUTPUT_CONSOLE)
     81                        logoutput.error = &log_console;
    8282        }
    8383#ifdef DEBUG
    84         else if(level==LOGLVL_DEBUG) {
    85                 if(output==LOGOUTPUT_NULL)
    86                         logoutput.debug=&log_null;
    87                 else if(output==LOGOUTPUT_IRC)
    88                         logoutput.debug=&log_irc;
    89                 else if(output==LOGOUTPUT_SYSLOG)
    90                         logoutput.debug=&log_syslog;
    91                 else if(output==LOGOUTPUT_CONSOLE)
    92                         logoutput.debug=&log_console;
     84        else if(level == LOGLVL_DEBUG) {
     85                if(output == LOGOUTPUT_NULL)
     86                        logoutput.debug = &log_null;
     87                else if(output == LOGOUTPUT_IRC)
     88                        logoutput.debug = &log_irc;
     89                else if(output == LOGOUTPUT_SYSLOG)
     90                        logoutput.debug = &log_syslog;
     91                else if(output == LOGOUTPUT_CONSOLE)
     92                        logoutput.debug = &log_console;
    9393        }
    9494#endif
     
    106106        va_end(ap);
    107107
    108         if(level==LOGLVL_INFO)
     108        if(level == LOGLVL_INFO)
    109109                (*(logoutput.informational))(level, msgstring);
    110         if(level==LOGLVL_WARNING)
     110        if(level == LOGLVL_WARNING)
    111111                (*(logoutput.warning))(level, msgstring);
    112         if(level==LOGLVL_ERROR)
     112        if(level == LOGLVL_ERROR)
    113113                (*(logoutput.error))(level, msgstring);
    114114#ifdef DEBUG
    115         if(level==LOGLVL_DEBUG)
     115        if(level == LOGLVL_DEBUG)
    116116                (*(logoutput.debug))(level, msgstring);
    117117#endif
     
    133133
    134134static void log_irc(int level, char *message) {
    135         if(level==LOGLVL_ERROR)
     135        if(level == LOGLVL_ERROR)
    136136                irc_write_all(1, "ERROR :Error: %s", message);
    137         if(level==LOGLVL_WARNING)
     137        if(level == LOGLVL_WARNING)
    138138                irc_write_all(0, "ERROR :Warning: %s", message);
    139         if(level==LOGLVL_INFO)
     139        if(level == LOGLVL_INFO)
    140140                irc_write_all(0, "ERROR :Informational: %s", message); 
    141141#ifdef DEBUG
    142         if(level==LOGLVL_DEBUG)
     142        if(level == LOGLVL_DEBUG)
    143143                irc_write_all(0, "ERROR :Debug: %s", message); 
    144144#endif 
     
    148148
    149149static void log_syslog(int level, char *message) {
    150         if(level==LOGLVL_ERROR)
     150        if(level == LOGLVL_ERROR)
    151151                syslog(LOG_ERR, "%s", message);
    152         if(level==LOGLVL_WARNING)
     152        if(level == LOGLVL_WARNING)
    153153                syslog(LOG_WARNING, "%s", message);
    154         if(level==LOGLVL_INFO)
     154        if(level == LOGLVL_INFO)
    155155                syslog(LOG_INFO, "%s", message);
    156156#ifdef DEBUG
    157         if(level==LOGLVL_DEBUG)
     157        if(level == LOGLVL_DEBUG)
    158158                syslog(LOG_DEBUG, "%s", message);
    159159#endif
     
    162162
    163163static void log_console(int level, char *message) {
    164         if(level==LOGLVL_ERROR)
     164        if(level == LOGLVL_ERROR)
    165165                fprintf(stderr, "Error: %s\n", message);
    166         if(level==LOGLVL_WARNING)
     166        if(level == LOGLVL_WARNING)
    167167                fprintf(stderr, "Warning: %s\n", message);
    168         if(level==LOGLVL_INFO)
     168        if(level == LOGLVL_INFO)
    169169                fprintf(stdout, "Informational: %s\n", message);
    170170#ifdef DEBUG
    171         if(level==LOGLVL_DEBUG)
     171        if(level == LOGLVL_DEBUG)
    172172                fprintf(stdout, "Debug: %s\n", message);
    173173#endif
  • protocols/Makefile

    ra323a22 r5ebe625  
    1010
    1111# [SH] Program variables
    12 objects = http_client.o md5.o nogaim.o proxy.o sha.o $(SSL_CLIENT) util.o
     12objects = http_client.o md5.o nogaim.o proxy.o sha.o $(SSL_CLIENT)
    1313
    1414# [SH] The next two lines should contain the directory name (in $(subdirs))
  • protocols/http_client.c

    ra323a22 r5ebe625  
    2727#include <stdio.h>
    2828
    29 #include "sock.h"
    3029#include "http_client.h"
    3130#include "url.h"
     31#include "sock.h"
    3232
    3333
  • protocols/jabber/jabber.c

    ra323a22 r5ebe625  
    413413                if (jd->die)
    414414                        signoff(GJ_GC(gjc));
    415         } else if (len < 0 || errno != EAGAIN) {
     415        } else if (len == 0 || (len < 0 && (!sockerr_again() || gjc->ssl))) {
    416416                STATE_EVT(JCONN_STATE_OFF)
    417417        }
     
    18561856                        xmlnode_insert_cdata(y, "away", -1);
    18571857                        y = xmlnode_insert_tag(x, "status");
    1858                         {
    1859                                 char *utf8 = str_to_utf8(message);
    1860                                 xmlnode_insert_cdata(y, utf8, -1);
    1861                                 g_free(utf8);
    1862                         }
     1858                        xmlnode_insert_cdata(y, message, -1);
    18631859                        gc->away = "";
    18641860                } else {
  • protocols/msn/msn.c

    ra323a22 r5ebe625  
    8484                {
    8585                        m = l->data;
     86               
     87                        serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who );
    8688                        g_free( m->who );
    8789                        g_free( m->text );
     
    8991                }
    9092                g_slist_free( md->msgq );
    91                
    92                 serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message(s), you'll have to resend them." );
    9393        }
    9494       
     
    170170       
    171171        for( i = 0; msn_away_state_list[i].number > -1; i ++ )
    172                 l = g_list_append( l, msn_away_state_list[i].name );
     172                l = g_list_append( l, (void*) msn_away_state_list[i].name );
    173173       
    174174        return( l );
     
    177177static char *msn_get_status_string( struct gaim_connection *gc, int number )
    178178{
    179         struct msn_away_state *st = msn_away_state_by_number( number );
     179        const struct msn_away_state *st = msn_away_state_by_number( number );
    180180       
    181181        if( st )
    182                 return( st->name );
     182                return( (char*) st->name );
    183183        else
    184184                return( "" );
     
    189189        char buf[1024];
    190190        struct msn_data *md = gc->proto_data;
    191         struct msn_away_state *st;
     191        const struct msn_away_state *st;
    192192       
    193193        if( strcmp( state, GAIM_AWAY_CUSTOM ) == 0 )
  • protocols/msn/msn.h

    ra323a22 r5ebe625  
    6767        GSList *switchboards;
    6868        int buddycount;
    69         struct msn_away_state *away_state;
     69        const struct msn_away_state *away_state;
    7070};
    7171
     
    131131
    132132int msn_chat_id;
    133 extern struct msn_away_state msn_away_state_list[];
    134 extern struct msn_status_code msn_status_code_list[];
     133extern const struct msn_away_state msn_away_state_list[];
     134extern const struct msn_status_code msn_status_code_list[];
    135135
    136136/* Keep a list of all the active connections. We need these lists because
     
    156156
    157157/* tables.c */
    158 struct msn_away_state *msn_away_state_by_number( int number );
    159 struct msn_away_state *msn_away_state_by_code( char *code );
    160 struct msn_away_state *msn_away_state_by_name( char *name );
    161 struct msn_status_code *msn_status_by_number( int number );
     158const struct msn_away_state *msn_away_state_by_number( int number );
     159const struct msn_away_state *msn_away_state_by_code( char *code );
     160const struct msn_away_state *msn_away_state_by_name( char *name );
     161const struct msn_status_code *msn_status_by_number( int number );
    162162
    163163/* sb.c */
  • protocols/msn/ns.c

    ra323a22 r5ebe625  
    365365        else if( strcmp( cmd[0], "ILN" ) == 0 )
    366366        {
    367                 struct msn_away_state *st;
     367                const struct msn_away_state *st;
    368368               
    369369                if( num_parts != 6 )
     
    393393        else if( strcmp( cmd[0], "NLN" ) == 0 )
    394394        {
    395                 struct msn_away_state *st;
     395                const struct msn_away_state *st;
    396396               
    397397                if( num_parts != 5 )
     
    539539        {
    540540                int num = atoi( cmd[0] );
    541                 struct msn_status_code *err = msn_status_by_number( num );
     541                const struct msn_status_code *err = msn_status_by_number( num );
    542542               
    543543                g_snprintf( buf, sizeof( buf ), "Error reported by MSN server: %s", err->text );
  • protocols/msn/sb.c

    ra323a22 r5ebe625  
    213213                {
    214214                        m = l->data;
     215
    215216                        g_free( m->who );
    216217                        g_free( m->text );
     
    219220                g_slist_free( sb->msgq );
    220221               
    221                 serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with unsent message(s), you'll have to resend them." );
     222                serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with "
     223                                   "unsent message to %s, you'll have to resend it.",
     224                                   m->who ? m->who : "(unknown)" );
    222225        }
    223226       
     
    512515        {
    513516                int num = atoi( cmd[0] );
    514                 struct msn_status_code *err = msn_status_by_number( num );
     517                const struct msn_status_code *err = msn_status_by_number( num );
    515518               
    516519                g_snprintf( buf, sizeof( buf ), "Error reported by switchboard server: %s", err->text );
  • protocols/msn/tables.c

    ra323a22 r5ebe625  
    2727#include "msn.h"
    2828
    29 struct msn_away_state msn_away_state_list[] =
     29const struct msn_away_state msn_away_state_list[] =
    3030{
    3131        {  0, "NLN", "Available" },
     
    4040};
    4141
    42 struct msn_away_state *msn_away_state_by_number( int number )
     42const struct msn_away_state *msn_away_state_by_number( int number )
    4343{
    4444        int i;
     
    5151}
    5252
    53 struct msn_away_state *msn_away_state_by_code( char *code )
     53const struct msn_away_state *msn_away_state_by_code( char *code )
    5454{
    5555        int i;
     
    6262}
    6363
    64 struct msn_away_state *msn_away_state_by_name( char *name )
     64const struct msn_away_state *msn_away_state_by_name( char *name )
    6565{
    6666        int i;
     
    7373}
    7474
    75 struct msn_status_code msn_status_code_list[] =
     75const struct msn_status_code msn_status_code_list[] =
    7676{
    7777        { 200, "Invalid syntax",                                        0 },
     
    144144};
    145145
    146 struct msn_status_code *msn_status_by_number( int number )
     146const struct msn_status_code *msn_status_by_number( int number )
    147147{
    148148        static struct msn_status_code *unknown = NULL;
  • protocols/nogaim.h

    ra323a22 r5ebe625  
    288288G_MODULE_EXPORT void serv_got_chat_in( struct gaim_connection *gc, int id, char *who, int whisper, char *msg, time_t mtime );
    289289G_MODULE_EXPORT void serv_got_chat_left( struct gaim_connection *gc, int id );
    290 /* void serv_finish_login( struct gaim_connection *gc ); */
    291290
    292291/* util.c */
    293 G_MODULE_EXPORT char *utf8_to_str( const char *in );
    294 G_MODULE_EXPORT char *str_to_utf8( const char *in );
    295292G_MODULE_EXPORT void strip_linefeed( gchar *text );
    296293G_MODULE_EXPORT char *add_cr( char *text );
     
    299296G_MODULE_EXPORT time_t get_time( int year, int month, int day, int hour, int min, int sec );
    300297G_MODULE_EXPORT void strip_html( char *msg );
    301 G_MODULE_EXPORT char * escape_html(const char *html);
     298G_MODULE_EXPORT char *escape_html( const char *html );
    302299G_MODULE_EXPORT void info_string_append(GString *str, char *newline, char *name, char *value);
     300G_MODULE_EXPORT char *ipv6_wrap( char *src );
     301G_MODULE_EXPORT char *ipv6_unwrap( char *src );
    303302
    304303/* prefs.c */
  • protocols/oscar/oscar.c

    ra323a22 r5ebe625  
    2121 */
    2222
    23 #include "sock.h"
    2423#include <errno.h>
    2524#include <ctype.h>
     
    3332#include "bitlbee.h"
    3433#include "proxy.h"
     34#include "sock.h"
    3535
    3636#include "aim.h"
     
    608608                return;
    609609        }
     610        /* [WvG] Wheeeee! Who needs error checking anyway? ;-) */
    610611        read(pos->fd, m, 16);
    611612        m[16] = '\0';
  • protocols/oscar/rxqueue.c

    ra323a22 r5ebe625  
    353353                return -1; /* its a aim_conn_close()'d connection */
    354354
    355         if (conn->fd < 3)  /* can happen when people abuse the interface */
     355        /* KIDS, THIS IS WHAT HAPPENS IF YOU USE CODE WRITTEN FOR GUIS IN A DAEMON!
     356           
     357           And wouldn't it make sense to return something that prevents this function
     358           from being called again IMMEDIATELY (and making the program suck up all
     359           CPU time)?...
     360           
     361        if (conn->fd < 3)
    356362                return 0;
     363        */
    357364
    358365        if (conn->status & AIM_CONN_STATUS_INPROGRESS)
  • protocols/oscar/service.c

    ra323a22 r5ebe625  
    736736
    737737        tlvlen = aim_addtlvtochain32(&tl, 0x0006, data);
    738 
    739         printf("%d\n", tlvlen);
    740738
    741739        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 8)))
  • protocols/ssl_bogus.c

    ra323a22 r5ebe625  
    5151        return( -1 );
    5252}
     53
     54GaimInputCondition ssl_getdirection( void *conn )
     55{
     56        return GAIM_INPUT_READ;
     57}
  • protocols/ssl_openssl.c

    ra323a22 r5ebe625  
    55  \********************************************************************/
    66
    7 /* SSL module - GnuTLS version                                          */
     7/* SSL module - OpenTLS version                                          */
    88
    99/*
     
    4141struct scd
    4242{
    43         ssl_input_function func;
     43        SslInputFunction func;
    4444        gpointer data;
    4545        int fd;
    4646        gboolean established;
    4747       
    48         int inpa;
    49         int lasterr;            /* Necessary for SSL_get_error */
    5048        SSL *ssl;
    5149        SSL_CTX *ssl_ctx;
     
    5654
    5755
    58 void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data )
     56void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )
    5957{
    6058        struct scd *conn = g_new0( struct scd, 1 );
     
    9593}
    9694
    97 static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond );
    98 
    9995static void ssl_connected( gpointer data, gint source, GaimInputCondition cond )
    10096{
     
    10298       
    10399        if( source == -1 )
    104                 return ssl_handshake( data, -1, cond );
     100                goto ssl_connected_failure;
    105101       
    106         /* Make it non-blocking at least during the handshake... */
    107         sock_make_nonblocking( conn->fd );
    108102        SSL_set_fd( conn->ssl, conn->fd );
    109103       
    110         return ssl_handshake( data, source, cond );
    111 }       
    112 
    113 static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond )
    114 {
    115         struct scd *conn = data;
    116         int st;
    117        
    118         if( conn->inpa != -1 )
    119         {
    120                 gaim_input_remove( conn->inpa );
    121                 conn->inpa = -1;
    122         }
    123        
    124         if( ( st = SSL_connect( conn->ssl ) ) < 0 )
    125         {
    126                 conn->lasterr = SSL_get_error( conn->ssl, st );
    127                 if( conn->lasterr != SSL_ERROR_WANT_READ && conn->lasterr != SSL_ERROR_WANT_WRITE )
    128                         goto ssl_connected_failure;
    129                
    130                 conn->inpa = gaim_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data );
    131                 return;
    132         }
     104        if( SSL_connect( conn->ssl ) < 0 )
     105                goto ssl_connected_failure;
    133106       
    134107        conn->established = TRUE;
    135         sock_make_blocking( conn->fd );         /* For now... */
    136108        conn->func( conn->data, conn, cond );
    137109        return;
     
    155127int ssl_read( void *conn, char *buf, int len )
    156128{
    157         int st;
     129        if( !((struct scd*)conn)->established )
     130                return( 0 );
    158131       
    159         if( !((struct scd*)conn)->established )
    160         {
    161                 ssl_errno = SSL_NOHANDSHAKE;
    162                 return -1;
    163         }
    164        
    165         st = SSL_read( ((struct scd*)conn)->ssl, buf, len );
    166        
    167         ssl_errno = SSL_OK;
    168         if( st <= 0 )
    169         {
    170                 ((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st );
    171                 if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE )
    172                         ssl_errno = SSL_AGAIN;
    173         }
    174        
    175         return st;
     132        return( SSL_read( ((struct scd*)conn)->ssl, buf, len ) );
    176133}
    177134
    178135int ssl_write( void *conn, const char *buf, int len )
    179136{
    180         int st;
     137        if( !((struct scd*)conn)->established )
     138                return( 0 );
    181139       
    182         if( !((struct scd*)conn)->established )
    183         {
    184                 ssl_errno = SSL_NOHANDSHAKE;
    185                 return -1;
    186         }
    187        
    188         st = SSL_write( ((struct scd*)conn)->ssl, buf, len );
    189        
    190         ssl_errno = SSL_OK;
    191         if( st <= 0 )
    192         {
    193                 ((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st );
    194                 if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE )
    195                         ssl_errno = SSL_AGAIN;
    196         }
    197        
    198         return st;
     140        return( SSL_write( ((struct scd*)conn)->ssl, buf, len ) );
    199141}
    200142
     
    202144{
    203145        struct scd *conn = conn_;
    204        
    205         if( conn->inpa != -1 )
    206                 gaim_input_remove( conn->inpa );
    207146       
    208147        if( conn->established )
     
    220159        return( ((struct scd*)conn)->fd );
    221160}
    222 
    223 GaimInputCondition ssl_getdirection( void *conn )
    224 {
    225         return( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ? GAIM_INPUT_WRITE : GAIM_INPUT_READ );
    226 }
  • protocols/yahoo/Makefile

    ra323a22 r5ebe625  
    1010
    1111# [SH] Program variables
    12 objects = yahoo.o crypt.o libyahoo2.o yahoo_fn.o yahoo_httplib.o yahoo_list.o yahoo_util.o
     12objects = yahoo.o crypt.o libyahoo2.o yahoo_fn.o yahoo_httplib.o yahoo_util.o
    1313
    1414CFLAGS += -Wall -DSTDC_HEADERS -DHAVE_STRING_H -DHAVE_STRCHR -DHAVE_MEMCPY -DHAVE_GLIB
  • protocols/yahoo/yahoo.c

    ra323a22 r5ebe625  
    189189{
    190190        struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
    191 
     191       
    192192        gc->away = NULL;
    193 
    194         if (msg)
     193       
     194        if( msg )
    195195        {
    196196                yd->current_status = YAHOO_STATUS_CUSTOM;
    197197                gc->away = "";
    198198        }
    199         else if (state)
     199        if( state )
    200200        {
    201201                gc->away = "";
    202                 if( g_strcasecmp(state, "Available" ) == 0 )
     202                if( g_strcasecmp( state, "Available" ) == 0 )
    203203                {
    204204                        yd->current_status = YAHOO_STATUS_AVAILABLE;
     
    235235                }
    236236        }
    237         else if ( gc->is_idle )
     237        else if( gc->is_idle )
    238238                yd->current_status = YAHOO_STATUS_IDLE;
    239239        else
    240240                yd->current_status = YAHOO_STATUS_AVAILABLE;
    241241       
    242         yahoo_set_away( yd->y2_id, yd->current_status, msg, gc->away != NULL );
     242        if( yd->current_status == YAHOO_STATUS_INVISIBLE )
     243                yahoo_set_away( yd->y2_id, yd->current_status, NULL, gc->away != NULL );
     244        else
     245                yahoo_set_away( yd->y2_id, yd->current_status, msg, gc->away != NULL );
    243246}
    244247
  • protocols/yahoo/yahoo_fn.c

    ra323a22 r5ebe625  
    2525#include "yahoo_fn.h"
    2626
    27 unsigned char table_0[256] = {
     27static const unsigned char table_0[256] = {
    2828   0x5A, 0x41, 0x11, 0x77, 0x29, 0x9C, 0x31, 0xAD,
    2929   0x4A, 0x32, 0x1A, 0x6D, 0x56, 0x9F, 0x39, 0xA6,
     
    5959   0x7B, 0xBE, 0xF9, 0xAF, 0x82, 0x63, 0x47, 0x23 };
    6060
    61 unsigned char table_1[256] = {
     61static const unsigned char table_1[256] = {
    6262   0x08, 0xCB, 0x54, 0xCF, 0x97, 0x53, 0x59, 0xF1,
    6363   0x66, 0xEC, 0xDB, 0x1B, 0xB1, 0xE2, 0x36, 0xEB,
     
    9393   0x05, 0x95, 0xBB, 0x79, 0x61, 0x3E, 0x81, 0xF7 };
    9494
    95 unsigned char table_2[32] = {
     95static const unsigned char table_2[32] = {
    9696   0x19, 0x05, 0x09, 0x1C, 0x0B, 0x1A, 0x12, 0x03,
    9797   0x06, 0x04, 0x0D, 0x1D, 0x15, 0x0E, 0x1B, 0x18,
     
    9999   0x16, 0x0A, 0x10, 0x0F, 0x01, 0x14, 0x11, 0x17 };
    100100
    101 unsigned char table_3[256] = {
     101static const unsigned char table_3[256] = {
    102102   0xBC, 0x1B, 0xCC, 0x1E, 0x5B, 0x59, 0x4F, 0xA8,
    103103   0x62, 0xC6, 0xC1, 0xBB, 0x83, 0x2D, 0xA3, 0xA6,
     
    133133   0x7C, 0xEF, 0xE0, 0x99, 0x09, 0xA0, 0x01, 0x7E };
    134134
    135 unsigned char table_4[32] = {
     135static const unsigned char table_4[32] = {
    136136   0x1F, 0x0B, 0x00, 0x1E, 0x03, 0x0E, 0x15, 0x01,
    137137   0x1A, 0x17, 0x1D, 0x1B, 0x11, 0x0F, 0x0A, 0x12,
     
    139139   0x08, 0x05, 0x10, 0x19, 0x0C, 0x14, 0x16, 0x1C };
    140140
    141 unsigned char table_5[256] = {
     141static const unsigned char table_5[256] = {
    142142   0x9A, 0xAB, 0x61, 0x28, 0x0A, 0x23, 0xFC, 0xBA,
    143143   0x90, 0x22, 0xB7, 0x62, 0xD9, 0x09, 0x91, 0xF4,
     
    173173   0x46, 0x73, 0x69, 0xD5, 0x10, 0xEE, 0x02, 0xEF };
    174174
    175 unsigned char table_6[32] = {
     175static const unsigned char table_6[32] = {
    176176   0x1A, 0x1C, 0x0F, 0x0C, 0x00, 0x02, 0x13, 0x09,
    177177   0x11, 0x05, 0x0D, 0x12, 0x18, 0x0B, 0x04, 0x10,
     
    179179   0x19, 0x1F, 0x01, 0x0E, 0x15, 0x06, 0x0A, 0x1D };
    180180
    181 unsigned char table_7[256] = {
     181static const unsigned char table_7[256] = {
    182182   0x52, 0x11, 0x72, 0xD0, 0x76, 0xD7, 0xAE, 0x03,
    183183   0x7F, 0x19, 0xF4, 0xB8, 0xB3, 0x5D, 0xCA, 0x2D,
     
    213213   0x88, 0x9E, 0x9C, 0x5B, 0x4D, 0x3A, 0x39, 0xEF };
    214214
    215 unsigned char table_8[32] = {
     215static const unsigned char table_8[32] = {
    216216   0x13, 0x08, 0x1E, 0x1D, 0x17, 0x16, 0x07, 0x1F,
    217217   0x0E, 0x03, 0x1A, 0x19, 0x01, 0x12, 0x11, 0x10,
     
    219219   0x1C, 0x18, 0x0A, 0x15, 0x02, 0x1B, 0x06, 0x0D };
    220220
    221 unsigned char table_9[256] = {
     221static const unsigned char table_9[256] = {
    222222   0x20, 0x2A, 0xDA, 0xFE, 0x76, 0x0D, 0xED, 0x39,
    223223   0x51, 0x4C, 0x46, 0x9A, 0xF1, 0xB0, 0x10, 0xC7,
     
    253253   0xF9, 0xF0, 0x2C, 0x74, 0xE9, 0x71, 0xC0, 0x2D };
    254254
    255 unsigned char table_10[32] = {
     255static const unsigned char table_10[32] = {
    256256   0x1D, 0x12, 0x11, 0x0D, 0x1E, 0x19, 0x16, 0x1B,
    257257   0x18, 0x13, 0x07, 0x17, 0x0C, 0x02, 0x00, 0x15,
     
    259259   0x1F, 0x1A, 0x0B, 0x09, 0x0A, 0x14, 0x1C, 0x03 };
    260260
    261 unsigned char table_11[256] = {
     261static const unsigned char table_11[256] = {
    262262   0x6B, 0x1D, 0xC6, 0x0A, 0xB7, 0xAC, 0xB2, 0x11,
    263263   0x29, 0xD3, 0xA2, 0x4D, 0xCB, 0x03, 0xEF, 0xA6,
     
    293293   0x64, 0x76, 0xFF, 0x9F, 0x2E, 0x02, 0xCC, 0x57 };
    294294
    295 unsigned char table_12[32] = {
     295static const unsigned char table_12[32] = {
    296296   0x14, 0x1B, 0x18, 0x00, 0x1F, 0x15, 0x17, 0x07,
    297297   0x11, 0x1A, 0x0E, 0x13, 0x12, 0x06, 0x01, 0x03,
     
    299299   0x0D, 0x1E, 0x04, 0x05, 0x08, 0x16, 0x0A, 0x02 };
    300300
    301 unsigned char table_13[256] = {
     301static const unsigned char table_13[256] = {
    302302   0x37, 0x8A, 0x1B, 0x91, 0xA5, 0x2B, 0x2D, 0x88,
    303303   0x8E, 0xFE, 0x0E, 0xD3, 0xF3, 0xE9, 0x7D, 0xD1,
     
    333333   0x97, 0x4A, 0xB8, 0x7A, 0xF4, 0xFB, 0x04, 0xA8 };
    334334
    335 unsigned char table_14[32] = {
     335static const unsigned char table_14[32] = {
    336336   0x04, 0x14, 0x13, 0x15, 0x1A, 0x1B, 0x0F, 0x16,
    337337   0x02, 0x0D, 0x0C, 0x06, 0x10, 0x17, 0x01, 0x0B,
     
    339339   0x11, 0x09, 0x1D, 0x07, 0x0E, 0x12, 0x03, 0x00 };
    340340
    341 unsigned char table_15[256] = {
     341static const unsigned char table_15[256] = {
    342342   0x61, 0x48, 0x58, 0x41, 0x7F, 0x88, 0x43, 0x42,
    343343   0xD9, 0x80, 0x81, 0xFE, 0xC6, 0x49, 0xD7, 0x2C,
     
    373373   0xAB, 0x8D, 0x02, 0x74, 0xBD, 0x3D, 0x8E, 0xDD };
    374374
    375 unsigned char table_16[256] = {
     375static const unsigned char table_16[256] = {
    376376   0x3F, 0x9C, 0x17, 0xC1, 0x59, 0xC6, 0x23, 0x93,
    377377   0x4B, 0xDF, 0xCB, 0x55, 0x2B, 0xDE, 0xCD, 0xAD,
     
    407407   0xF4, 0xBE, 0xEA, 0x19, 0x43, 0x01, 0xB1, 0x96 };
    408408
    409 unsigned char table_17[256] = {
     409static const unsigned char table_17[256] = {
    410410   0x7E, 0xF1, 0xD3, 0x75, 0x87, 0xA6, 0xED, 0x9E,
    411411   0xA9, 0xD5, 0xC6, 0xBF, 0xE6, 0x6A, 0xEE, 0x4B,
     
    441441   0x9F, 0x99, 0x62, 0xAA, 0xFA, 0x11, 0x0C, 0x52 };
    442442
    443 unsigned char table_18[256] = {
     443static const unsigned char table_18[256] = {
    444444   0x0F, 0x42, 0x3D, 0x86, 0x3E, 0x66, 0xFE, 0x5C,
    445445   0x52, 0xE2, 0xA3, 0xB3, 0xCE, 0x16, 0xCC, 0x95,
     
    475475   0xFA, 0x4E, 0xEF, 0x54, 0xE6, 0x7F, 0xC0, 0x67 };
    476476
    477 unsigned char table_19[256] = {
     477static const unsigned char table_19[256] = {
    478478   0xEA, 0xE7, 0x13, 0x14, 0xB9, 0xC0, 0xC4, 0x42,
    479479   0x49, 0x6E, 0x2A, 0xA6, 0x65, 0x3C, 0x6A, 0x40,
     
    509509   0x1E, 0x0D, 0xAE, 0x7B, 0x5E, 0x61, 0xE9, 0x63 };
    510510
    511 unsigned char table_20[32] = {
     511static const unsigned char table_20[32] = {
    512512   0x0D, 0x0B, 0x11, 0x02, 0x05, 0x1B, 0x08, 0x1D,
    513513   0x04, 0x14, 0x01, 0x09, 0x00, 0x19, 0x1E, 0x15,
     
    515515   0x13, 0x1A, 0x06, 0x17, 0x0E, 0x12, 0x18, 0x03 };
    516516
    517 unsigned char table_21[256] = {
     517static const unsigned char table_21[256] = {
    518518   0x4C, 0x94, 0xAD, 0x66, 0x9E, 0x69, 0x04, 0xA8,
    519519   0x61, 0xE0, 0xE1, 0x3D, 0xFD, 0x9C, 0xFB, 0x19,
     
    549549   0xFF, 0xD8, 0xE7, 0xDD, 0xBB, 0x78, 0xD5, 0x81 };
    550550
    551 unsigned char table_22[32] = {
     551static const unsigned char table_22[32] = {
    552552   0x0B, 0x15, 0x1C, 0x0C, 0x06, 0x0A, 0x1D, 0x16,
    553553   0x12, 0x0E, 0x04, 0x11, 0x1F, 0x0F, 0x07, 0x02,
     
    555555   0x03, 0x00, 0x01, 0x08, 0x09, 0x14, 0x1B, 0x1E };
    556556
    557 unsigned char table_23[256] = {
     557static const unsigned char table_23[256] = {
    558558   0x36, 0x53, 0x2D, 0xD0, 0x7A, 0xF0, 0xD5, 0x1C,
    559559   0x50, 0x61, 0x9A, 0x90, 0x0B, 0x29, 0x20, 0x77,
     
    589589   0x1D, 0x15, 0xC6, 0xBF, 0xA9, 0x43, 0xC0, 0x49 };
    590590
    591 unsigned char table_24[256] = {
     591static const unsigned char table_24[256] = {
    592592   0xDC, 0x5A, 0xE6, 0x59, 0x64, 0xDA, 0x58, 0x40,
    593593   0x95, 0xF8, 0x2A, 0xE0, 0x39, 0x7E, 0x32, 0x89,
     
    623623   0xEA, 0x8D, 0x2D, 0x5F, 0xF6, 0xA7, 0x80, 0x3A };
    624624
    625 unsigned char table_25[32] = {
     625static const unsigned char table_25[32] = {
    626626   0x0A, 0x11, 0x17, 0x03, 0x05, 0x0B, 0x18, 0x13,
    627627   0x09, 0x02, 0x00, 0x1C, 0x0C, 0x08, 0x1B, 0x14,
     
    629629   0x0F, 0x1A, 0x10, 0x04, 0x12, 0x15, 0x07, 0x1F };
    630630
    631 unsigned char table_26[32] = {
     631static const unsigned char table_26[32] = {
    632632   0x19, 0x13, 0x1B, 0x01, 0x1C, 0x0D, 0x0C, 0x15,
    633633   0x0B, 0x00, 0x1A, 0x0F, 0x12, 0x16, 0x08, 0x0A,
     
    635635   0x1F, 0x07, 0x17, 0x05, 0x02, 0x0E, 0x1E, 0x09 };
    636636
    637 unsigned char table_27[256] = {
     637static const unsigned char table_27[256] = {
    638638   0x72, 0xF0, 0x14, 0xCB, 0x61, 0xA5, 0xB2, 0x02,
    639639   0x75, 0x22, 0xC3, 0x9D, 0x5A, 0x63, 0xFA, 0x5F,
     
    669669   0x5E, 0x6F, 0x47, 0x64, 0xBC, 0x9A, 0x60, 0x7E };
    670670
    671 unsigned char table_28[32] = {
     671static const unsigned char table_28[32] = {
    672672   0x15, 0x05, 0x08, 0x19, 0x02, 0x18, 0x1E, 0x07,
    673673   0x0D, 0x0C, 0x1A, 0x06, 0x17, 0x03, 0x10, 0x09,
     
    675675   0x1B, 0x13, 0x0A, 0x16, 0x0E, 0x00, 0x1D, 0x14 };
    676676
    677 unsigned char table_29[256] = {
     677static const unsigned char table_29[256] = {
    678678   0x34, 0x59, 0x05, 0x13, 0x09, 0x1D, 0xDF, 0x77,
    679679   0x11, 0xA5, 0x92, 0x27, 0xCD, 0x7B, 0x5E, 0x80,
     
    709709   0x46, 0x62, 0xB6, 0xB0, 0x15, 0x04, 0x95, 0x4D };
    710710
    711 unsigned char table_30[32] = {
     711static const unsigned char table_30[32] = {
    712712   0x00, 0x1C, 0x0E, 0x0C, 0x06, 0x16, 0x09, 0x12,
    713713   0x01, 0x13, 0x0B, 0x14, 0x11, 0x08, 0x04, 0x18,
     
    715715   0x1E, 0x1F, 0x0F, 0x07, 0x0D, 0x05, 0x1D, 0x0A };
    716716
    717 unsigned char table_31[256] = {
     717static const unsigned char table_31[256] = {
    718718   0xDF, 0xD8, 0x3F, 0xBC, 0x5F, 0xC9, 0x8E, 0x4C,
    719719   0x0B, 0x3C, 0xE5, 0xBF, 0x39, 0xD5, 0x30, 0xDD,
     
    749749   0x92, 0x48, 0xF7, 0x0A, 0xF6, 0xE2, 0x4B, 0x56 };
    750750
    751 unsigned char table_32[256] = {
     751static const unsigned char table_32[256] = {
    752752   0x7B, 0x0F, 0x56, 0x2F, 0x1E, 0x2A, 0x7A, 0xD1,
    753753   0x02, 0x91, 0x4E, 0x37, 0x6C, 0x10, 0xA7, 0xF2,
     
    783783   0x47, 0x6B, 0x8A, 0xA2, 0x9A, 0xA3, 0x45, 0x41 };
    784784
    785 unsigned char table_33[256] = {
     785static const unsigned char table_33[256] = {
    786786   0xDE, 0xD3, 0x79, 0x67, 0x13, 0x5C, 0x04, 0xF2,
    787787   0xD9, 0x9F, 0x65, 0x56, 0xCC, 0x3B, 0xA4, 0x9A,
     
    817817   0x80, 0x3C, 0xEE, 0x47, 0xC6, 0x3A, 0x53, 0xF6 };
    818818
    819 unsigned char table_34[256] = {
     819static const unsigned char table_34[256] = {
    820820   0xF0, 0xE9, 0x3E, 0xD6, 0x89, 0xC8, 0xC7, 0x23,
    821821   0x75, 0x26, 0x5F, 0x9C, 0x57, 0xB8, 0x2A, 0x29,
     
    851851   0x03, 0x05, 0xBF, 0x06, 0x1B, 0xC0, 0x1A, 0x60 };
    852852
    853 unsigned char table_35[256] = {
     853static const unsigned char table_35[256] = {
    854854   0xCC, 0x40, 0xEF, 0x1F, 0xDB, 0xE5, 0x71, 0x51,
    855855   0x3B, 0x0F, 0x7D, 0x9C, 0x83, 0x17, 0x6F, 0x8F,
     
    885885   0x59, 0xC4, 0x9F, 0xD0, 0x66, 0x7B, 0x33, 0xB5 };
    886886
    887 unsigned char table_36[256] = {
     887static const unsigned char table_36[256] = {
    888888   0xDB, 0x6F, 0xFE, 0xB3, 0x5C, 0x1F, 0xB8, 0xBF,
    889889   0xA3, 0x71, 0x11, 0x56, 0x90, 0xE2, 0x63, 0x18,
     
    919919   0x4B, 0xB6, 0x7B, 0x4D, 0xCF, 0x7E, 0x48, 0xE3 };
    920920
    921 unsigned char table_37[256] = {
     921static const unsigned char table_37[256] = {
    922922   0x1F, 0xD6, 0xB1, 0xB3, 0x40, 0xAD, 0xDE, 0xB7,
    923923   0x19, 0xB4, 0xE7, 0x0B, 0x9C, 0x2D, 0xE0, 0xF5,
     
    953953   0x73, 0xC8, 0x86, 0x47, 0xDB, 0xAB, 0x6F, 0x8C };
    954954
    955 unsigned char table_38[256] = {
     955static const unsigned char table_38[256] = {
    956956   0xAA, 0x8D, 0x37, 0x94, 0x99, 0xDD, 0x70, 0x77,
    957957   0x78, 0xC9, 0x0F, 0xFA, 0xE2, 0x05, 0xC2, 0x16,
     
    987987   0x09, 0x76, 0x00, 0x46, 0x4E, 0x53, 0xCE, 0x4A };
    988988
    989 unsigned char table_39[32] = {
     989static const unsigned char table_39[32] = {
    990990   0x12, 0x18, 0x0E, 0x08, 0x16, 0x05, 0x06, 0x00,
    991991   0x11, 0x17, 0x15, 0x1B, 0x14, 0x01, 0x1F, 0x19,
     
    993993   0x0B, 0x13, 0x0C, 0x09, 0x1E, 0x02, 0x1A, 0x1C };
    994994
    995 unsigned char table_40[32] = {
     995static const unsigned char table_40[32] = {
    996996   0x16, 0x02, 0x06, 0x0E, 0x0D, 0x1C, 0x08, 0x0A,
    997997   0x0F, 0x13, 0x0B, 0x18, 0x07, 0x04, 0x14, 0x01,
     
    999999   0x12, 0x19, 0x1D, 0x03, 0x0C, 0x00, 0x09, 0x15 };
    10001000
    1001 unsigned char table_41[32] = {
     1001static const unsigned char table_41[32] = {
    10021002   0x13, 0x18, 0x04, 0x1F, 0x1D, 0x11, 0x03, 0x00,
    10031003   0x10, 0x12, 0x06, 0x0A, 0x1C, 0x07, 0x15, 0x0E,
     
    10051005   0x1A, 0x17, 0x14, 0x1E, 0x0D, 0x0F, 0x19, 0x1B };
    10061006
    1007 unsigned char table_42[32] = {
     1007static const unsigned char table_42[32] = {
    10081008   0x00, 0x08, 0x15, 0x1D, 0x05, 0x18, 0x06, 0x07,
    10091009   0x1F, 0x01, 0x0B, 0x03, 0x19, 0x13, 0x02, 0x1C,
     
    10111011   0x1B, 0x16, 0x10, 0x0D, 0x0A, 0x14, 0x12, 0x04 };
    10121012
    1013 unsigned char table_43[256] = {
     1013static const unsigned char table_43[256] = {
    10141014   0x34, 0xB7, 0x36, 0x85, 0x5F, 0x93, 0x98, 0x70,
    10151015   0x1E, 0x59, 0x83, 0x60, 0x6F, 0xBF, 0xF9, 0xD0,
     
    10451045   0x73, 0x76, 0x3A, 0x21, 0x53, 0xA4, 0x50, 0x6A };
    10461046
    1047 unsigned char table_44[32] = {
     1047static const unsigned char table_44[32] = {
    10481048   0x1A, 0x0E, 0x0A, 0x17, 0x1F, 0x08, 0x10, 0x14,
    10491049   0x0C, 0x0F, 0x09, 0x1C, 0x06, 0x18, 0x1E, 0x12,
     
    10511051   0x16, 0x19, 0x05, 0x1D, 0x02, 0x07, 0x04, 0x1B };
    10521052
    1053 unsigned char table_45[256] = {
     1053static const unsigned char table_45[256] = {
    10541054   0x5E, 0xD6, 0xE2, 0x54, 0x35, 0xC2, 0xAC, 0x9D,
    10551055   0x92, 0x64, 0x57, 0x65, 0xC8, 0xAE, 0x21, 0xA9,
     
    10851085   0xF9, 0x2B, 0x32, 0x8F, 0xFB, 0xC7, 0x07, 0x82 };
    10861086
    1087 unsigned char table_46[256] = {
     1087static const unsigned char table_46[256] = {
    10881088   0x85, 0x78, 0xFE, 0x6C, 0x61, 0xA0, 0x71, 0xCC,
    10891089   0x45, 0x54, 0x7A, 0xE6, 0x82, 0x1D, 0xA6, 0x02,
     
    11191119   0xC7, 0xE4, 0x37, 0xE5, 0xFC, 0xBD, 0x99, 0x41 };
    11201120
    1121 unsigned char table_47[32] = {
     1121static const unsigned char table_47[32] = {
    11221122   0x18, 0x1D, 0x16, 0x10, 0x11, 0x04, 0x1E, 0x08,
    11231123   0x19, 0x0E, 0x0F, 0x02, 0x14, 0x1C, 0x07, 0x17,
     
    11251125   0x13, 0x15, 0x0C, 0x00, 0x06, 0x1F, 0x03, 0x1B };
    11261126
    1127 unsigned char table_48[32] = {
     1127static const unsigned char table_48[32] = {
    11281128   0x13, 0x08, 0x15, 0x01, 0x17, 0x10, 0x0F, 0x1F,
    11291129   0x1D, 0x0D, 0x12, 0x03, 0x06, 0x0A, 0x1C, 0x19,
     
    11311131   0x14, 0x09, 0x0C, 0x18, 0x05, 0x07, 0x0E, 0x0B };
    11321132
    1133 unsigned char table_49[32] = {
     1133static const unsigned char table_49[32] = {
    11341134   0x1F, 0x0F, 0x19, 0x07, 0x18, 0x05, 0x1E, 0x1D,
    11351135   0x15, 0x08, 0x17, 0x10, 0x0A, 0x0E, 0x0C, 0x1B,
     
    11371137   0x12, 0x1C, 0x0B, 0x16, 0x14, 0x01, 0x11, 0x00 };
    11381138
    1139 unsigned char table_50[32] = {
     1139static const unsigned char table_50[32] = {
    11401140   0x16, 0x18, 0x1C, 0x0E, 0x12, 0x00, 0x04, 0x1B,
    11411141   0x1F, 0x13, 0x17, 0x0A, 0x1E, 0x03, 0x0C, 0x01,
     
    11431143   0x06, 0x0D, 0x0B, 0x1D, 0x05, 0x07, 0x11, 0x1A };
    11441144
    1145 unsigned char table_51[32] = {
     1145static const unsigned char table_51[32] = {
    11461146   0x1C, 0x0D, 0x1B, 0x07, 0x17, 0x0E, 0x06, 0x01,
    11471147   0x12, 0x19, 0x03, 0x0B, 0x10, 0x08, 0x00, 0x1E,
     
    11491149   0x0F, 0x11, 0x05, 0x09, 0x15, 0x16, 0x1F, 0x14 };
    11501150
    1151 unsigned char table_52[256] = {
     1151static const unsigned char table_52[256] = {
    11521152   0x34, 0x0B, 0x47, 0xA3, 0x56, 0x30, 0x73, 0xD4,
    11531153   0x4B, 0xF6, 0xA6, 0x80, 0x22, 0x95, 0xA5, 0xBB,
     
    11831183   0x01, 0x0C, 0x5D, 0x7D, 0xB8, 0xBE, 0x6A, 0x16 };
    11841184
    1185 unsigned char table_53[256] = {
     1185static const unsigned char table_53[256] = {
    11861186   0xE3, 0xF4, 0x8D, 0x72, 0x45, 0x32, 0x9D, 0xCE,
    11871187   0x1F, 0x6B, 0xBC, 0xDC, 0xF1, 0xEC, 0x5A, 0x3B,
     
    12171217   0xAB, 0x64, 0xE0, 0xBE, 0xDA, 0xBD, 0x96, 0x94 };
    12181218
    1219 unsigned char table_54[32] = {
     1219static const unsigned char table_54[32] = {
    12201220   0x01, 0x02, 0x1D, 0x10, 0x0E, 0x11, 0x08, 0x14,
    12211221   0x12, 0x09, 0x15, 0x17, 0x16, 0x04, 0x06, 0x1B,
     
    12231223   0x0C, 0x0B, 0x0D, 0x05, 0x0F, 0x00, 0x19, 0x03 };
    12241224
    1225 unsigned char table_55[32] = {
     1225static const unsigned char table_55[32] = {
    12261226   0x01, 0x12, 0x13, 0x09, 0x0B, 0x19, 0x03, 0x0E,
    12271227   0x02, 0x1F, 0x1D, 0x1B, 0x1E, 0x11, 0x06, 0x05,
     
    12291229   0x18, 0x10, 0x0F, 0x17, 0x1C, 0x0A, 0x04, 0x14 };
    12301230
    1231 unsigned char table_56[256] = {
     1231static const unsigned char table_56[256] = {
    12321232   0xEF, 0x06, 0x5F, 0x11, 0x4B, 0x60, 0x13, 0xBB,
    12331233   0x79, 0xD7, 0xE4, 0x6D, 0x22, 0xB4, 0x15, 0x50,
     
    12631263   0x96, 0xD5, 0xEB, 0x64, 0x8A, 0xC8, 0x7A, 0xBE };
    12641264
    1265 unsigned char table_57[256] = {
     1265static const unsigned char table_57[256] = {
    12661266   0xD1, 0x9B, 0x15, 0x06, 0xB4, 0xF6, 0x97, 0xF0,
    12671267   0xC6, 0x5B, 0x88, 0x12, 0x25, 0xFA, 0x7B, 0x79,
     
    12971297   0x4E, 0x3C, 0x84, 0x14, 0x28, 0x3A, 0xE9, 0xC0 };
    12981298
    1299 unsigned char table_58[256] = {
     1299static const unsigned char table_58[256] = {
    13001300   0xE9, 0x81, 0x60, 0xA7, 0x18, 0xA0, 0x0F, 0x55,
    13011301   0x2B, 0x52, 0xE0, 0x8B, 0x9D, 0x85, 0xD2, 0xA3,
     
    13311331   0x68, 0x1E, 0xF6, 0xA6, 0x6C, 0xB2, 0xD1, 0x58 };
    13321332
    1333 unsigned char table_59[256] = {
     1333static const unsigned char table_59[256] = {
    13341334   0x4C, 0x85, 0x2B, 0x14, 0xCC, 0x4D, 0x5F, 0xD7,
    13351335   0xCE, 0x28, 0xC5, 0x0B, 0xA1, 0x99, 0x08, 0xDE,
     
    13651365   0x5D, 0x1A, 0x8D, 0xC1, 0x58, 0x48, 0xAD, 0x0F };
    13661366
    1367 unsigned char table_60[32] = {
     1367static const unsigned char table_60[32] = {
    13681368   0x1C, 0x06, 0x1E, 0x10, 0x1D, 0x05, 0x00, 0x0E,
    13691369   0x0C, 0x02, 0x11, 0x19, 0x15, 0x18, 0x16, 0x07,
     
    13711371   0x03, 0x08, 0x12, 0x04, 0x1B, 0x0A, 0x17, 0x1A };
    13721372
    1373 unsigned char table_61[256] = {
     1373static const unsigned char table_61[256] = {
    13741374   0xC5, 0xA6, 0xF2, 0x6B, 0x4B, 0x58, 0xE0, 0x41,
    13751375   0xC6, 0x2F, 0x13, 0xFE, 0xC1, 0x34, 0x3F, 0x24,
     
    14051405   0xCF, 0x60, 0xAA, 0xA4, 0xEB, 0xC4, 0x4E, 0xC2 };
    14061406
    1407 unsigned char table_62[256] = {
     1407static const unsigned char table_62[256] = {
    14081408   0x01, 0x59, 0xEC, 0xFC, 0x51, 0xD2, 0xE4, 0x9D,
    14091409   0xAA, 0x61, 0xD5, 0xCA, 0x63, 0x5D, 0xCE, 0x36,
     
    14391439   0xCF, 0xE9, 0xDB, 0xD3, 0x02, 0x9A, 0x0E, 0x5F };
    14401440
    1441 unsigned char table_63[256] = {
     1441static const unsigned char table_63[256] = {
    14421442   0x0C, 0x02, 0xEE, 0x94, 0x2D, 0x76, 0x96, 0x75,
    14431443   0x21, 0xDC, 0x37, 0x03, 0xC0, 0xF7, 0xDF, 0xEF,
     
    14731473   0x8C, 0xE2, 0x83, 0xA7, 0xD6, 0x0E, 0xB3, 0xDD };
    14741474
    1475 unsigned char table_64[32] = {
     1475static const unsigned char table_64[32] = {
    14761476   0x03, 0x05, 0x0D, 0x09, 0x1A, 0x16, 0x08, 0x10,
    14771477   0x06, 0x1E, 0x1C, 0x15, 0x02, 0x04, 0x17, 0x0C,
     
    14791479   0x0E, 0x00, 0x1D, 0x1F, 0x01, 0x0F, 0x07, 0x12 };
    14801480
    1481 unsigned char table_65[32] = {
     1481static const unsigned char table_65[32] = {
    14821482   0x01, 0x0A, 0x1E, 0x14, 0x10, 0x1D, 0x0D, 0x17,
    14831483   0x0E, 0x0C, 0x0F, 0x12, 0x04, 0x1A, 0x05, 0x02,
     
    14851485   0x11, 0x00, 0x16, 0x06, 0x03, 0x18, 0x15, 0x07 };
    14861486
    1487 unsigned char table_66[32] = {
     1487static const unsigned char table_66[32] = {
    14881488   0x1C, 0x18, 0x0C, 0x09, 0x05, 0x03, 0x15, 0x12,
    14891489   0x0D, 0x02, 0x08, 0x0E, 0x19, 0x07, 0x13, 0x17,
     
    14911491   0x0F, 0x10, 0x01, 0x1B, 0x00, 0x04, 0x1A, 0x16 };
    14921492
    1493 unsigned char table_67[256] = {
     1493static const unsigned char table_67[256] = {
    14941494   0x6B, 0x49, 0xC8, 0x86, 0xFF, 0xC0, 0x5D, 0xEF,
    14951495   0xF7, 0x06, 0xE0, 0x98, 0xA9, 0x72, 0x71, 0xD5,
     
    15251525   0x24, 0x43, 0x21, 0x83, 0xFB, 0xFD, 0x8B, 0x96 };
    15261526
    1527 unsigned char table_68[256] = {
     1527static const unsigned char table_68[256] = {
    15281528   0x93, 0xFF, 0x83, 0x70, 0x12, 0x2D, 0x1C, 0xD6,
    15291529   0xF9, 0xEE, 0xCF, 0x94, 0x7B, 0xB5, 0xA4, 0x84,
     
    15591559   0x8C, 0x6D, 0x91, 0x63, 0x3A, 0x4D, 0xC1, 0x01 };
    15601560
    1561 unsigned char table_69[256] = {
     1561static const unsigned char table_69[256] = {
    15621562   0x21, 0x6B, 0x9B, 0xAE, 0x11, 0x5A, 0x91, 0xC2,
    15631563   0x47, 0x8E, 0x87, 0x86, 0x4F, 0xFC, 0x8F, 0x66,
     
    15931593   0x73, 0xDB, 0xB6, 0x83, 0xCE, 0x1E, 0xC1, 0x3C };
    15941594
    1595 unsigned char table_70[256] = {
     1595static const unsigned char table_70[256] = {
    15961596   0x54, 0x23, 0xF1, 0x09, 0x9D, 0xEB, 0x26, 0xD9,
    15971597   0x6C, 0xC1, 0xBC, 0x3D, 0x6E, 0xB0, 0x5F, 0xE2,
     
    16271627   0x49, 0x84, 0x38, 0xC7, 0xE3, 0xD4, 0x1A, 0xBF };
    16281628
    1629 unsigned char table_71[32] = {
     1629static const unsigned char table_71[32] = {
    16301630   0x17, 0x13, 0x0E, 0x1A, 0x0D, 0x18, 0x19, 0x10,
    16311631   0x14, 0x11, 0x16, 0x05, 0x04, 0x00, 0x12, 0x0A,
     
    16331633   0x0C, 0x06, 0x1B, 0x08, 0x1D, 0x01, 0x15, 0x1E };
    16341634
    1635 unsigned char table_72[256] = {
     1635static const unsigned char table_72[256] = {
    16361636   0xC9, 0xA7, 0x1B, 0xEC, 0x2B, 0x8B, 0xB0, 0xEB,
    16371637   0x7F, 0x39, 0x25, 0xD9, 0x1D, 0xD5, 0x67, 0xA0,
     
    16671667   0x08, 0x53, 0xF2, 0xB9, 0x5A, 0x3E, 0xE9, 0xD2 };
    16681668
    1669 unsigned char table_73[256] = {
     1669static const unsigned char table_73[256] = {
    16701670   0x36, 0x37, 0xED, 0xD8, 0xBF, 0xD7, 0x12, 0xB7,
    16711671   0x40, 0x32, 0x19, 0x4A, 0x44, 0x2A, 0xCE, 0xA5,
     
    17011701   0xFF, 0x90, 0x6B, 0xBC, 0x54, 0x95, 0xBD, 0x07 };
    17021702
    1703 unsigned char table_74[256] = {
     1703static const unsigned char table_74[256] = {
    17041704   0xA7, 0xCF, 0x99, 0x1A, 0x13, 0xC7, 0xE9, 0xC4,
    17051705   0xB6, 0x0E, 0x15, 0x09, 0xFF, 0xDF, 0xBE, 0x03,
     
    17351735   0x2F, 0xD8, 0xC3, 0x7C, 0x9C, 0x98, 0xEA, 0x71 };
    17361736
    1737 unsigned char table_75[256] = {
     1737static const unsigned char table_75[256] = {
    17381738   0xE7, 0xA5, 0x30, 0xE1, 0x9D, 0x81, 0xBE, 0x83,
    17391739   0xB2, 0x1E, 0xE4, 0x69, 0x2F, 0x2B, 0x0D, 0xEB,
     
    17691769   0x89, 0x46, 0x78, 0xDC, 0x32, 0x8B, 0x67, 0x36 };
    17701770
    1771 unsigned char table_76[256] = {
     1771static const unsigned char table_76[256] = {
    17721772   0x3D, 0x66, 0x40, 0xC5, 0x1D, 0xF5, 0xE7, 0xB7,
    17731773   0x2C, 0x23, 0x09, 0xC2, 0x68, 0xE6, 0xD3, 0x8D,
     
    18031803   0xD1, 0x95, 0xC3, 0xA0, 0x0F, 0xCA, 0xAC, 0xFC };
    18041804
    1805 unsigned char table_77[32] = {
     1805static const unsigned char table_77[32] = {
    18061806   0x1C, 0x0D, 0x1E, 0x01, 0x06, 0x16, 0x18, 0x17,
    18071807   0x0B, 0x1F, 0x04, 0x0F, 0x00, 0x19, 0x08, 0x0A,
     
    18091809   0x1A, 0x12, 0x13, 0x0E, 0x1D, 0x10, 0x02, 0x1B };
    18101810
    1811 unsigned char table_78[32] = {
     1811static const unsigned char table_78[32] = {
    18121812   0x0E, 0x02, 0x17, 0x12, 0x1E, 0x09, 0x15, 0x03,
    18131813   0x01, 0x0B, 0x0F, 0x11, 0x10, 0x0A, 0x16, 0x06,
     
    18151815   0x13, 0x0D, 0x1B, 0x08, 0x19, 0x14, 0x05, 0x1A };
    18161816
    1817 unsigned char table_79[32] = {
     1817static const unsigned char table_79[32] = {
    18181818   0x12, 0x0B, 0x11, 0x01, 0x07, 0x0E, 0x1A, 0x0D,
    18191819   0x1E, 0x18, 0x14, 0x1F, 0x0A, 0x17, 0x19, 0x1B,
     
    18211821   0x09, 0x06, 0x04, 0x16, 0x15, 0x1C, 0x05, 0x03 };
    18221822
    1823 unsigned char table_80[256] = {
     1823static const unsigned char table_80[256] = {
    18241824   0x14, 0xE7, 0x31, 0x0F, 0xD1, 0x5F, 0xED, 0x1E,
    18251825   0xA6, 0x77, 0x20, 0x57, 0x34, 0x64, 0x33, 0x0B,
     
    18551855   0x39, 0xB9, 0xC0, 0x22, 0xF1, 0x4D, 0x90, 0xFC };
    18561856
    1857 unsigned char table_81[32] = {
     1857static const unsigned char table_81[32] = {
    18581858   0x03, 0x02, 0x1D, 0x0E, 0x09, 0x1A, 0x0C, 0x11,
    18591859   0x1C, 0x0D, 0x08, 0x12, 0x19, 0x10, 0x04, 0x17,
     
    18611861   0x1E, 0x0B, 0x0F, 0x01, 0x07, 0x14, 0x1F, 0x06 };
    18621862
    1863 unsigned char table_82[256] = {
     1863static const unsigned char table_82[256] = {
    18641864   0x53, 0xD3, 0x64, 0x89, 0x7D, 0xA5, 0x66, 0xA4,
    18651865   0x09, 0x46, 0x17, 0x2C, 0xAF, 0x8C, 0x21, 0x5F,
     
    18951895   0x6A, 0x78, 0xB5, 0x71, 0x56, 0x87, 0x7F, 0x86 };
    18961896
    1897 unsigned char table_83[32] = {
     1897static const unsigned char table_83[32] = {
    18981898   0x1B, 0x0A, 0x1F, 0x01, 0x10, 0x08, 0x0E, 0x18,
    18991899   0x06, 0x04, 0x00, 0x1C, 0x0C, 0x19, 0x0D, 0x16,
     
    19011901   0x17, 0x1E, 0x1A, 0x1D, 0x0B, 0x11, 0x14, 0x15 };
    19021902
    1903 unsigned char table_84[32] = {
     1903static const unsigned char table_84[32] = {
    19041904   0x02, 0x1A, 0x0D, 0x15, 0x01, 0x16, 0x1E, 0x00,
    19051905   0x08, 0x1B, 0x04, 0x10, 0x1C, 0x18, 0x19, 0x14,
     
    19071907   0x1D, 0x17, 0x13, 0x06, 0x0F, 0x05, 0x09, 0x1F };
    19081908
    1909 unsigned char table_85[256] = {
     1909static const unsigned char table_85[256] = {
    19101910   0xC6, 0x7C, 0xCE, 0xBD, 0x84, 0x3E, 0x0B, 0xD8,
    19111911   0xFE, 0xCC, 0x46, 0x50, 0xD1, 0xFB, 0xA0, 0x6D,
     
    19411941   0x2D, 0x57, 0xE7, 0x82, 0x1E, 0x37, 0x63, 0x43 };
    19421942
    1943 unsigned char table_86[32] = {
     1943static const unsigned char table_86[32] = {
    19441944   0x11, 0x07, 0x0F, 0x0A, 0x19, 0x1D, 0x0B, 0x09,
    19451945   0x1C, 0x1E, 0x14, 0x06, 0x0C, 0x16, 0x13, 0x04,
     
    19471947   0x10, 0x1A, 0x1F, 0x01, 0x17, 0x0E, 0x03, 0x1B };
    19481948
    1949 unsigned char table_87[32] = {
     1949static const unsigned char table_87[32] = {
    19501950   0x17, 0x0E, 0x1D, 0x13, 0x0B, 0x19, 0x03, 0x06,
    19511951   0x09, 0x01, 0x0D, 0x15, 0x1C, 0x16, 0x18, 0x1B,
     
    19531953   0x02, 0x04, 0x07, 0x1A, 0x14, 0x0A, 0x0C, 0x05 };
    19541954
    1955 unsigned char table_88[32] = {
     1955static const unsigned char table_88[32] = {
    19561956   0x09, 0x08, 0x17, 0x10, 0x0A, 0x07, 0x1C, 0x1F,
    19571957   0x04, 0x0E, 0x01, 0x0C, 0x0D, 0x1B, 0x03, 0x15,
     
    19591959   0x05, 0x11, 0x14, 0x00, 0x16, 0x1D, 0x12, 0x13 };
    19601960
    1961 unsigned char table_89[32] = {
     1961static const unsigned char table_89[32] = {
    19621962   0x15, 0x1C, 0x1D, 0x14, 0x0F, 0x1A, 0x05, 0x02,
    19631963   0x07, 0x09, 0x06, 0x08, 0x1F, 0x00, 0x10, 0x13,
     
    19651965   0x12, 0x04, 0x11, 0x0A, 0x01, 0x0B, 0x17, 0x19 };
    19661966
    1967 unsigned char table_90[256] = {
     1967static const unsigned char table_90[256] = {
    19681968   0x62, 0x36, 0x64, 0x0E, 0x4C, 0x6C, 0xBE, 0xCF,
    19691969   0x25, 0x5A, 0x3D, 0x12, 0x54, 0x9F, 0xE7, 0xA5,
     
    19991999   0x20, 0x94, 0x45, 0xED, 0xDC, 0xBD, 0x7E, 0x50 };
    20002000
    2001 unsigned char table_91[32] = {
     2001static const unsigned char table_91[32] = {
    20022002   0x03, 0x04, 0x0C, 0x18, 0x10, 0x0D, 0x13, 0x1B,
    20032003   0x1F, 0x07, 0x11, 0x17, 0x1C, 0x1D, 0x05, 0x06,
     
    20052005   0x14, 0x16, 0x00, 0x15, 0x19, 0x09, 0x0F, 0x1E };
    20062006
    2007 unsigned char table_92[32] = {
     2007static const unsigned char table_92[32] = {
    20082008   0x1E, 0x10, 0x01, 0x07, 0x11, 0x16, 0x15, 0x17,
    20092009   0x1F, 0x14, 0x0C, 0x1C, 0x06, 0x03, 0x00, 0x18,
     
    20112011   0x0F, 0x12, 0x0B, 0x13, 0x0A, 0x04, 0x1D, 0x1A };
    20122012
    2013 unsigned char table_93[256] = {
     2013static const unsigned char table_93[256] = {
    20142014   0x76, 0x78, 0xA2, 0x94, 0x0E, 0x7F, 0xDF, 0xC1,
    20152015   0xB9, 0xE1, 0x3D, 0x59, 0x6F, 0x1E, 0x53, 0x99,
     
    20452045   0x24, 0x34, 0xE2, 0xEC, 0x85, 0x47, 0xF4, 0xB2 };
    20462046
    2047 unsigned char table_94[32] = {
     2047static const unsigned char table_94[32] = {
    20482048   0x1C, 0x07, 0x05, 0x1A, 0x10, 0x1D, 0x14, 0x12,
    20492049   0x08, 0x0F, 0x0C, 0x01, 0x04, 0x1B, 0x16, 0x0A,
     
    20512051   0x0E, 0x09, 0x15, 0x19, 0x03, 0x18, 0x00, 0x0B };
    20522052
    2053 unsigned char table_95[32] = {
     2053static const unsigned char table_95[32] = {
    20542054   0x12, 0x10, 0x11, 0x15, 0x03, 0x0A, 0x14, 0x05,
    20552055   0x1D, 0x07, 0x17, 0x0D, 0x09, 0x08, 0x1B, 0x1F,
     
    20572057   0x1E, 0x1C, 0x01, 0x0C, 0x1A, 0x0F, 0x13, 0x16 };
    20582058
    2059 unsigned char table_96[256] = {
     2059static const unsigned char table_96[256] = {
    20602060   0x1C, 0x6E, 0xCD, 0xB4, 0xB3, 0x93, 0xA8, 0x2E,
    20612061   0x4F, 0x09, 0xE3, 0x72, 0x64, 0x13, 0x21, 0xF5,
     
    20912091   0x59, 0xCE, 0xE1, 0x57, 0x20, 0x58, 0x51, 0xD8 };
    20922092
    2093 unsigned char table_97[256] = {
     2093static const unsigned char table_97[256] = {
    20942094   0x15, 0x2D, 0xAF, 0x36, 0xCF, 0xD3, 0xD0, 0xED,
    20952095   0xB2, 0x1B, 0xFE, 0x92, 0xBD, 0xAD, 0x58, 0x0F,
     
    21252125   0x83, 0x25, 0x9F, 0xD9, 0x99, 0xC1, 0xFD, 0xB3 };
    21262126
    2127 unsigned char table_98[256] = {
     2127static const unsigned char table_98[256] = {
    21282128   0xC8, 0xE6, 0x38, 0x93, 0xE5, 0x03, 0x18, 0x1F,
    21292129   0xE9, 0x5A, 0xB6, 0xAF, 0xC3, 0x95, 0x00, 0x51,
     
    21592159   0x54, 0x3A, 0x13, 0x09, 0x2C, 0xB5, 0xC7, 0x63 };
    21602160
    2161 unsigned char table_99[32] = {
     2161static const unsigned char table_99[32] = {
    21622162   0x19, 0x00, 0x10, 0x18, 0x09, 0x11, 0x13, 0x1D,
    21632163   0x08, 0x1A, 0x02, 0x05, 0x03, 0x17, 0x12, 0x01,
     
    21652165   0x0E, 0x16, 0x1E, 0x04, 0x1B, 0x0A, 0x0C, 0x1C };
    21662166
    2167 unsigned char table_100[256] = {
     2167static const unsigned char table_100[256] = {
    21682168   0x9B, 0x3A, 0xAE, 0x60, 0x27, 0x67, 0x1E, 0x4E,
    21692169   0x91, 0xDA, 0x85, 0x43, 0x5C, 0xCC, 0x89, 0x55,
     
    21992199   0x30, 0x0C, 0xB2, 0x7B, 0xBE, 0xFB, 0x23, 0x2C };
    22002200
    2201 unsigned char table_101[32] = {
     2201static const unsigned char table_101[32] = {
    22022202   0x18, 0x08, 0x14, 0x17, 0x03, 0x10, 0x19, 0x04,
    22032203   0x0D, 0x1C, 0x06, 0x1D, 0x1E, 0x12, 0x11, 0x0B,
     
    22052205   0x15, 0x0A, 0x0C, 0x1A, 0x00, 0x01, 0x1F, 0x09 };
    22062206
    2207 unsigned char table_102[32] = {
     2207static const unsigned char table_102[32] = {
    22082208   0x17, 0x1F, 0x0E, 0x05, 0x13, 0x0C, 0x14, 0x1A,
    22092209   0x0F, 0x01, 0x12, 0x1C, 0x00, 0x07, 0x0D, 0x02,
     
    22112211   0x06, 0x15, 0x0A, 0x19, 0x09, 0x08, 0x1B, 0x0B };
    22122212
    2213 unsigned char table_103[32] = {
     2213static const unsigned char table_103[32] = {
    22142214   0x0F, 0x09, 0x1E, 0x11, 0x0D, 0x08, 0x10, 0x00,
    22152215   0x01, 0x1F, 0x1D, 0x1C, 0x12, 0x04, 0x07, 0x05,
     
    22172217   0x18, 0x0B, 0x0A, 0x13, 0x0C, 0x0E, 0x03, 0x06 };
    22182218
    2219 unsigned char table_104[256] = {
     2219static const unsigned char table_104[256] = {
    22202220   0xA4, 0x9F, 0x78, 0x39, 0x3D, 0x81, 0x51, 0x24,
    22212221   0x46, 0x2A, 0x56, 0xE8, 0xDF, 0x73, 0xA8, 0xA2,
     
    22512251   0x97, 0xBB, 0x37, 0x8C, 0x54, 0x53, 0x9E, 0x8F };
    22522252
    2253 unsigned char table_105[256] = {
     2253static const unsigned char table_105[256] = {
    22542254   0x7B, 0x35, 0x11, 0x79, 0x07, 0x2F, 0xF6, 0x82,
    22552255   0x8E, 0xB4, 0x6E, 0xD2, 0x6D, 0xC5, 0x8C, 0x1C,
     
    22852285   0xBA, 0x1E, 0x44, 0x87, 0x45, 0x9F, 0xC9, 0x94 };
    22862286
    2287 unsigned char table_106[32] = {
     2287static const unsigned char table_106[32] = {
    22882288   0x03, 0x11, 0x07, 0x1B, 0x0F, 0x14, 0x0C, 0x01,
    22892289   0x04, 0x02, 0x09, 0x0A, 0x05, 0x12, 0x06, 0x1F,
     
    22912291   0x1E, 0x1D, 0x17, 0x19, 0x13, 0x16, 0x0B, 0x1A };
    22922292
    2293 unsigned char table_107[32] = {
     2293static const unsigned char table_107[32] = {
    22942294   0x13, 0x1B, 0x06, 0x11, 0x1C, 0x07, 0x08, 0x0E,
    22952295   0x10, 0x05, 0x09, 0x18, 0x04, 0x15, 0x1E, 0x0F,
     
    22972297   0x03, 0x0C, 0x0A, 0x1D, 0x14, 0x01, 0x16, 0x0B };
    22982298
    2299 unsigned char table_108[256] = {
     2299static const unsigned char table_108[256] = {
    23002300   0x99, 0xA3, 0x48, 0xE8, 0x5A, 0x7D, 0x97, 0xCA,
    23012301   0x7F, 0x06, 0x9B, 0x04, 0xE0, 0xF3, 0x18, 0xAE,
     
    23312331   0xCC, 0xE2, 0x44, 0x73, 0xBE, 0x26, 0x8C, 0x5B };
    23322332
    2333 unsigned char table_109[256] = {
     2333static const unsigned char table_109[256] = {
    23342334   0xE3, 0x95, 0xDB, 0x09, 0x82, 0x0A, 0x8F, 0x9E,
    23352335   0xC9, 0xDC, 0x28, 0x35, 0x0F, 0x8B, 0xA8, 0xA5,
     
    23652365   0x1E, 0xF4, 0xD5, 0xB1, 0x5C, 0x25, 0xE8, 0x1C };
    23662366
    2367 unsigned char table_110[256] = {
     2367static const unsigned char table_110[256] = {
    23682368   0xC3, 0x06, 0x3C, 0xCB, 0xD2, 0x44, 0x9D, 0x48,
    23692369   0x28, 0xAA, 0xA9, 0xD0, 0x64, 0x25, 0x56, 0xCA,
     
    23992399   0x4B, 0xCF, 0xB4, 0x2F, 0xBB, 0xEF, 0xDB, 0x33 };
    24002400
    2401 unsigned char table_111[32] = {
     2401static const unsigned char table_111[32] = {
    24022402   0x09, 0x0F, 0x00, 0x15, 0x12, 0x17, 0x1A, 0x0D,
    24032403   0x1C, 0x0B, 0x01, 0x0A, 0x05, 0x1E, 0x1D, 0x0C,
     
    24052405   0x10, 0x16, 0x11, 0x1F, 0x04, 0x06, 0x02, 0x13 };
    24062406
    2407 unsigned char table_112[256] = {
     2407static const unsigned char table_112[256] = {
    24082408   0xF9, 0x7D, 0xBE, 0xD5, 0x9F, 0xB8, 0x95, 0x43,
    24092409   0xDB, 0xAE, 0x7E, 0xEC, 0x5B, 0x58, 0x18, 0x49,
     
    24392439   0xA1, 0xCC, 0xDF, 0x60, 0xD8, 0x5A, 0xE6, 0xD4 };
    24402440
    2441 unsigned char table_113[256] = {
     2441static const unsigned char table_113[256] = {
    24422442   0x46, 0x9D, 0x39, 0xB2, 0x8D, 0x3B, 0x59, 0x5A,
    24432443   0xD0, 0x9C, 0xE4, 0x04, 0x01, 0xE2, 0xB3, 0xD2,
     
    24732473   0xFE, 0x7B, 0x67, 0xFF, 0x10, 0xEC, 0xC6, 0x86 };
    24742474
    2475 unsigned char table_114[32] = {
     2475static const unsigned char table_114[32] = {
    24762476   0x11, 0x10, 0x04, 0x1D, 0x08, 0x15, 0x1A, 0x1B,
    24772477   0x14, 0x18, 0x0F, 0x17, 0x16, 0x07, 0x1E, 0x0E,
     
    24792479   0x1F, 0x19, 0x09, 0x1C, 0x01, 0x0D, 0x03, 0x05 };
    24802480
    2481 unsigned char table_115[256] = {
     2481static const unsigned char table_115[256] = {
    24822482   0xB7, 0xBB, 0x63, 0x0D, 0xF0, 0x33, 0x5A, 0x05,
    24832483   0xF2, 0x7F, 0x64, 0xDB, 0x51, 0xC9, 0x2C, 0x85,
     
    25132513   0x8C, 0x17, 0xB5, 0xEB, 0xD5, 0xF3, 0x0B, 0x3C };
    25142514
    2515 unsigned char table_116[32] = {
     2515static const unsigned char table_116[32] = {
    25162516   0x00, 0x05, 0x10, 0x1C, 0x0C, 0x1A, 0x04, 0x1B,
    25172517   0x0A, 0x0D, 0x14, 0x0B, 0x07, 0x03, 0x12, 0x1E,
     
    25192519   0x19, 0x18, 0x16, 0x02, 0x13, 0x0E, 0x17, 0x1D };
    25202520
    2521 unsigned char table_117[256] = {
     2521static const unsigned char table_117[256] = {
    25222522   0xD0, 0x9A, 0xAB, 0xA8, 0xA7, 0xDF, 0x28, 0xCE,
    25232523   0x3E, 0x51, 0xBF, 0x76, 0x03, 0xA0, 0x53, 0x3F,
     
    25532553   0xC1, 0xFD, 0x92, 0xA1, 0xF7, 0xAE, 0xDC, 0x58 };
    25542554
    2555 unsigned char table_118[256] = {
     2555static const unsigned char table_118[256] = {
    25562556   0x38, 0xA0, 0xA6, 0xFC, 0x7C, 0x5A, 0x97, 0x1D,
    25572557   0xFD, 0x00, 0x20, 0xA2, 0x72, 0x10, 0x1F, 0x48,
     
    25872587   0xD9, 0x2F, 0x02, 0xAC, 0x30, 0x6A, 0xD6, 0x95 };
    25882588
    2589 unsigned char table_119[32] = {
     2589static const unsigned char table_119[32] = {
    25902590   0x14, 0x0A, 0x1C, 0x00, 0x0C, 0x1F, 0x1E, 0x0B,
    25912591   0x12, 0x1D, 0x17, 0x08, 0x07, 0x04, 0x09, 0x10,
     
    25932593   0x18, 0x02, 0x06, 0x01, 0x19, 0x16, 0x13, 0x0F };
    25942594
    2595 unsigned char table_120[256] = {
     2595static const unsigned char table_120[256] = {
    25962596   0xCE, 0x89, 0xB2, 0x72, 0x04, 0x77, 0x64, 0xAE,
    25972597   0x80, 0x99, 0xB5, 0x00, 0x7B, 0x50, 0x9D, 0xE3,
     
    26272627   0x5E, 0xCA, 0xFD, 0x11, 0xA3, 0xC7, 0xC0, 0x91 };
    26282628
    2629 unsigned char table_121[32] = {
     2629static const unsigned char table_121[32] = {
    26302630   0x1E, 0x12, 0x06, 0x1D, 0x15, 0x1F, 0x13, 0x0B,
    26312631   0x10, 0x0D, 0x1C, 0x01, 0x0A, 0x0E, 0x02, 0x19,
     
    26332633   0x14, 0x08, 0x18, 0x05, 0x09, 0x0F, 0x1B, 0x07 };
    26342634
    2635 unsigned char table_122[256] = {
     2635static const unsigned char table_122[256] = {
    26362636   0x85, 0xDF, 0x7F, 0x7C, 0x56, 0xF0, 0x0C, 0x7D,
    26372637   0x76, 0xA8, 0x58, 0x31, 0x25, 0x8A, 0x0D, 0x23,
     
    26672667   0xCE, 0x2D, 0x4E, 0x83, 0xC3, 0x69, 0xEE, 0xB2 };
    26682668
    2669 unsigned char table_123[256] = {
     2669static const unsigned char table_123[256] = {
    26702670   0x9D, 0xFB, 0x3C, 0x81, 0xAA, 0x05, 0xB2, 0xBE,
    26712671   0xD1, 0x5F, 0x4C, 0xE0, 0xA3, 0xF4, 0xDE, 0x35,
     
    27012701   0x48, 0x77, 0xD0, 0x0A, 0x8A, 0x3A, 0x43, 0x79 };
    27022702
    2703 unsigned char table_124[256] = {
     2703static const unsigned char table_124[256] = {
    27042704   0x6C, 0xC3, 0x28, 0x2F, 0x42, 0x4B, 0x7C, 0x3C,
    27052705   0xCE, 0x24, 0xC8, 0x51, 0x25, 0x3F, 0x49, 0x8D,
     
    27352735   0x62, 0x1B, 0xDE, 0x91, 0x87, 0x97, 0x05, 0x2E };
    27362736
    2737 unsigned char table_125[32] = {
     2737static const unsigned char table_125[32] = {
    27382738   0x1A, 0x18, 0x12, 0x15, 0x00, 0x1C, 0x01, 0x0B,
    27392739   0x19, 0x1B, 0x1F, 0x11, 0x07, 0x10, 0x1E, 0x06,
     
    27412741   0x02, 0x03, 0x13, 0x14, 0x09, 0x1D, 0x05, 0x0F };
    27422742
    2743 unsigned char table_126[32] = {
     2743static const unsigned char table_126[32] = {
    27442744   0x1C, 0x1D, 0x07, 0x12, 0x18, 0x1A, 0x19, 0x09,
    27452745   0x0F, 0x14, 0x1F, 0x0B, 0x13, 0x04, 0x0E, 0x1E,
     
    27472747   0x15, 0x10, 0x11, 0x08, 0x00, 0x03, 0x06, 0x02 };
    27482748
    2749 unsigned char table_127[256] = {
     2749static const unsigned char table_127[256] = {
    27502750   0xA0, 0x66, 0xD8, 0x08, 0xEA, 0x39, 0x78, 0xAB,
    27512751   0x61, 0x4E, 0xC7, 0xD1, 0xA3, 0x1C, 0x9F, 0xCB,
     
    27812781   0x70, 0xF8, 0x17, 0xCD, 0xB0, 0xCC, 0x82, 0x2D };
    27822782
    2783 unsigned char table_128[32] = {
     2783static const unsigned char table_128[32] = {
    27842784   0x1A, 0x1C, 0x09, 0x17, 0x1B, 0x0B, 0x16, 0x1E,
    27852785   0x14, 0x0C, 0x12, 0x0E, 0x05, 0x03, 0x1F, 0x15,
     
    27872787   0x02, 0x08, 0x0F, 0x18, 0x07, 0x04, 0x1D, 0x06 };
    27882788
    2789 unsigned char table_129[256] = {
     2789static const unsigned char table_129[256] = {
    27902790   0x9D, 0x5F, 0xE8, 0x99, 0x57, 0x07, 0x16, 0xA6,
    27912791   0x9F, 0xB6, 0xDE, 0xED, 0x2D, 0xB3, 0xC0, 0x8E,
     
    28212821   0x09, 0x45, 0x6B, 0xD7, 0x0B, 0x89, 0x4F, 0x2A };
    28222822
    2823 unsigned char table_130[32] = {
     2823static const unsigned char table_130[32] = {
    28242824   0x07, 0x03, 0x15, 0x0B, 0x02, 0x11, 0x17, 0x14,
    28252825   0x05, 0x10, 0x0A, 0x0F, 0x01, 0x1C, 0x1D, 0x0E,
     
    28272827   0x1B, 0x00, 0x08, 0x0D, 0x0C, 0x1E, 0x04, 0x1F };
    28282828
    2829 unsigned char table_131[32] = {
     2829static const unsigned char table_131[32] = {
    28302830   0x1D, 0x13, 0x1B, 0x10, 0x07, 0x03, 0x0A, 0x02,
    28312831   0x00, 0x0C, 0x0E, 0x0B, 0x0D, 0x18, 0x12, 0x1F,
     
    28332833   0x19, 0x05, 0x0F, 0x17, 0x06, 0x01, 0x09, 0x16 };
    28342834
    2835 unsigned char table_132[256] = {
     2835static const unsigned char table_132[256] = {
    28362836   0x33, 0x8D, 0x45, 0x6F, 0xFF, 0xF5, 0xB6, 0x53,
    28372837   0x3B, 0xF3, 0x07, 0xA4, 0x97, 0xEB, 0x6B, 0xA5,
     
    28672867   0xC4, 0x7F, 0xA0, 0xD8, 0xEF, 0x03, 0x70, 0xF6 };
    28682868
    2869 unsigned char table_133[256] = {
     2869static const unsigned char table_133[256] = {
    28702870   0x02, 0xF0, 0xED, 0xC4, 0xE4, 0x67, 0x60, 0x8B,
    28712871   0xF3, 0x77, 0x92, 0xE0, 0x85, 0x93, 0x1E, 0x8E,
     
    29012901   0x5A, 0x35, 0xB0, 0xAE, 0x82, 0x79, 0x1D, 0x52 };
    29022902
    2903 unsigned char table_134[32] = {
     2903static const unsigned char table_134[32] = {
    29042904   0x09, 0x0F, 0x10, 0x0C, 0x03, 0x15, 0x07, 0x17,
    29052905   0x0E, 0x0B, 0x1D, 0x08, 0x19, 0x11, 0x00, 0x0A,
     
    29072907   0x02, 0x1B, 0x1A, 0x04, 0x05, 0x1F, 0x1C, 0x1E };
    29082908
    2909 unsigned char table_135[256] = {
     2909static const unsigned char table_135[256] = {
    29102910   0x14, 0x34, 0xEA, 0x02, 0x2B, 0x5A, 0x10, 0x51,
    29112911   0xF3, 0x8F, 0x28, 0xB2, 0x50, 0x8B, 0x01, 0xCC,
     
    29412941   0x00, 0x63, 0xD9, 0xBE, 0xF2, 0x60, 0x25, 0x62 };
    29422942
    2943 unsigned char table_136[256] = {
     2943static const unsigned char table_136[256] = {
    29442944   0xD3, 0x1A, 0x00, 0xED, 0x59, 0x24, 0xA3, 0xF2,
    29452945   0xBA, 0x58, 0x4C, 0x5C, 0x75, 0x48, 0x98, 0xB0,
     
    29752975   0x93, 0x1D, 0x9B, 0x5B, 0x40, 0xEE, 0x42, 0x19 };
    29762976
    2977 unsigned char table_137[32] = {
     2977static const unsigned char table_137[32] = {
    29782978   0x0F, 0x09, 0x02, 0x06, 0x18, 0x0B, 0x1E, 0x05,
    29792979   0x11, 0x1D, 0x16, 0x01, 0x13, 0x10, 0x0E, 0x1A,
     
    29812981   0x03, 0x1F, 0x0A, 0x12, 0x0C, 0x07, 0x04, 0x1C };
    29822982
    2983 unsigned char table_138[32] = {
     2983static const unsigned char table_138[32] = {
    29842984   0x0D, 0x1C, 0x1F, 0x15, 0x0F, 0x14, 0x1B, 0x12,
    29852985   0x09, 0x0B, 0x19, 0x07, 0x11, 0x16, 0x0C, 0x04,
     
    29872987   0x01, 0x06, 0x18, 0x17, 0x10, 0x1A, 0x02, 0x00 };
    29882988
    2989 unsigned char table_139[32] = {
     2989static const unsigned char table_139[32] = {
    29902990   0x05, 0x15, 0x1D, 0x02, 0x0F, 0x03, 0x17, 0x1A,
    29912991   0x0A, 0x00, 0x1F, 0x12, 0x0E, 0x11, 0x1B, 0x13,
     
    29932993   0x0C, 0x04, 0x16, 0x19, 0x1C, 0x06, 0x10, 0x01 };
    29942994
    2995 unsigned char table_140[32] = {
     2995static const unsigned char table_140[32] = {
    29962996   0x06, 0x1E, 0x0C, 0x11, 0x13, 0x08, 0x15, 0x01,
    29972997   0x1D, 0x03, 0x0F, 0x19, 0x18, 0x04, 0x00, 0x14,
     
    29992999   0x1F, 0x17, 0x09, 0x0A, 0x0D, 0x16, 0x10, 0x1C };
    30003000
    3001 unsigned char table_141[256] = {
     3001static const unsigned char table_141[256] = {
    30023002   0xE1, 0x0A, 0x28, 0xCD, 0x8A, 0x1E, 0x26, 0x10,
    30033003   0xC0, 0x6F, 0x06, 0x2C, 0xF8, 0x51, 0x6C, 0x8F,
     
    30333033   0x98, 0x54, 0xB8, 0xDC, 0x46, 0xDF, 0x87, 0xE5 };
    30343034
    3035 unsigned char table_142[256] = {
     3035static const unsigned char table_142[256] = {
    30363036   0x90, 0x94, 0xBE, 0x14, 0x99, 0xEB, 0x45, 0x0F,
    30373037   0x34, 0x4A, 0xE3, 0x79, 0xD2, 0x64, 0x4D, 0x69,
     
    30673067   0xCC, 0x1E, 0x87, 0xD7, 0x01, 0x1F, 0x51, 0x95 };
    30683068
    3069 unsigned char table_143[32] = {
     3069static const unsigned char table_143[32] = {
    30703070   0x0E, 0x16, 0x18, 0x11, 0x0C, 0x01, 0x12, 0x1F,
    30713071   0x08, 0x15, 0x0A, 0x06, 0x1C, 0x1E, 0x02, 0x1A,
     
    30733073   0x0D, 0x14, 0x09, 0x0B, 0x1B, 0x00, 0x1D, 0x04 };
    30743074
    3075 unsigned char table_144[32] = {
     3075static const unsigned char table_144[32] = {
    30763076   0x00, 0x1B, 0x17, 0x19, 0x1D, 0x11, 0x0D, 0x1A,
    30773077   0x13, 0x03, 0x1E, 0x09, 0x10, 0x0E, 0x15, 0x05,
     
    30793079   0x16, 0x14, 0x02, 0x04, 0x07, 0x18, 0x12, 0x0C };
    30803080
    3081 unsigned char table_145[256] = {
     3081static const unsigned char table_145[256] = {
    30823082   0xF9, 0x2C, 0x38, 0x74, 0xDA, 0x65, 0x85, 0x0E,
    30833083   0xBA, 0x64, 0xDB, 0xE3, 0xB6, 0x8B, 0x0B, 0x5E,
     
    31133113   0x69, 0xF6, 0xEF, 0xC2, 0xAD, 0x03, 0xB3, 0x1E };
    31143114
    3115 unsigned char table_146[256] = {
     3115static const unsigned char table_146[256] = {
    31163116   0x1C, 0xF5, 0x16, 0xD2, 0xCC, 0xDC, 0x1E, 0x29,
    31173117   0xE3, 0x17, 0x3B, 0x66, 0x6A, 0xF7, 0x03, 0xB2,
     
    31473147   0x7D, 0x96, 0x76, 0x99, 0xB5, 0x48, 0x98, 0x10 };
    31483148
    3149 unsigned char table_147[32] = {
     3149static const unsigned char table_147[32] = {
    31503150   0x17, 0x07, 0x0D, 0x16, 0x00, 0x1B, 0x1F, 0x09,
    31513151   0x10, 0x11, 0x14, 0x0A, 0x02, 0x06, 0x13, 0x0C,
     
    31533153   0x1C, 0x1A, 0x03, 0x18, 0x04, 0x0B, 0x1D, 0x0E };
    31543154
    3155 unsigned char table_148[256] = {
     3155static const unsigned char table_148[256] = {
    31563156   0xFB, 0x23, 0xBC, 0x5A, 0x8C, 0x02, 0x42, 0x3B,
    31573157   0x95, 0x0C, 0x21, 0x0E, 0x14, 0xDF, 0x11, 0xC0,
     
    31873187   0x09, 0x43, 0xBF, 0xD0, 0x55, 0xDD, 0x3F, 0x24 };
    31883188
    3189 unsigned char table_149[32] = {
     3189static const unsigned char table_149[32] = {
    31903190   0x1B, 0x0B, 0x0C, 0x06, 0x1F, 0x17, 0x04, 0x1A,
    31913191   0x1E, 0x02, 0x0F, 0x16, 0x0E, 0x09, 0x10, 0x01,
     
    31933193   0x18, 0x1D, 0x14, 0x0D, 0x07, 0x08, 0x15, 0x12 };
    31943194
    3195 unsigned char table_150[256] = {
     3195static const unsigned char table_150[256] = {
    31963196   0x57, 0xBC, 0x9D, 0x46, 0x14, 0xD0, 0x94, 0x95,
    31973197   0x1B, 0x12, 0xB8, 0xD4, 0x53, 0x73, 0x83, 0xE6,
     
    32273227   0x97, 0xC9, 0xF3, 0x04, 0xD8, 0xF4, 0x80, 0x44 };
    32283228
    3229 unsigned char table_151[256] = {
     3229static const unsigned char table_151[256] = {
    32303230   0x78, 0x6C, 0xC5, 0x0C, 0x2D, 0xA7, 0x97, 0x9C,
    32313231   0x22, 0x76, 0x3E, 0x81, 0x51, 0x47, 0x59, 0x71,
     
    32613261   0x43, 0x3A, 0x53, 0x9E, 0x80, 0x88, 0x07, 0x9D };
    32623262
    3263 unsigned char table_152[32] = {
     3263static const unsigned char table_152[32] = {
    32643264   0x02, 0x1A, 0x17, 0x1D, 0x01, 0x03, 0x13, 0x1E,
    32653265   0x05, 0x18, 0x06, 0x0A, 0x0C, 0x04, 0x1B, 0x00,
     
    32673267   0x14, 0x12, 0x0D, 0x10, 0x19, 0x11, 0x08, 0x15 };
    32683268
    3269 unsigned char table_153[32] = {
     3269static const unsigned char table_153[32] = {
    32703270   0x0E, 0x14, 0x12, 0x1E, 0x1C, 0x02, 0x06, 0x16,
    32713271   0x18, 0x0D, 0x17, 0x0C, 0x1D, 0x11, 0x08, 0x19,
     
    32733273   0x1A, 0x0A, 0x05, 0x10, 0x00, 0x01, 0x15, 0x09 };
    32743274
    3275 unsigned char table_154[256] = {
     3275static const unsigned char table_154[256] = {
    32763276   0x27, 0x5A, 0x08, 0x5B, 0xF4, 0x39, 0x13, 0x6F,
    32773277   0x67, 0xEA, 0x22, 0xCA, 0x5C, 0xCF, 0x18, 0x7C,
     
    33073307   0x53, 0xE1, 0xDD, 0x72, 0x95, 0x52, 0x34, 0xB5 };
    33083308
    3309 unsigned char table_155[256] = {
     3309static const unsigned char table_155[256] = {
    33103310   0x75, 0x58, 0xC5, 0xA5, 0x83, 0x16, 0xF3, 0x7F,
    33113311   0x94, 0xDE, 0xA0, 0xF6, 0xFD, 0x89, 0xA8, 0x06,
     
    33413341   0x8B, 0x33, 0xFC, 0xBB, 0x00, 0xA2, 0xDF, 0xDA };
    33423342
    3343 unsigned char table_156[256] = {
     3343static const unsigned char table_156[256] = {
    33443344   0x31, 0x25, 0xB1, 0xD3, 0xAF, 0xAE, 0x84, 0x2C,
    33453345   0x71, 0x5E, 0xD8, 0x80, 0x6F, 0x3E, 0x48, 0x86,
     
    33753375   0xF1, 0x68, 0xBE, 0x35, 0x40, 0x8C, 0xD4, 0x47 };
    33763376
    3377 unsigned char table_157[32] = {
     3377static const unsigned char table_157[32] = {
    33783378   0x00, 0x0D, 0x03, 0x02, 0x11, 0x04, 0x18, 0x0B,
    33793379   0x14, 0x1D, 0x1C, 0x13, 0x1B, 0x17, 0x10, 0x15,
     
    33813381   0x08, 0x06, 0x0C, 0x0E, 0x1F, 0x0F, 0x0A, 0x05 };
    33823382
    3383 unsigned char table_158[256] = {
     3383static const unsigned char table_158[256] = {
    33843384   0x68, 0x26, 0x80, 0x0B, 0xB8, 0xD5, 0x8C, 0xB7,
    33853385   0x65, 0xEF, 0xBC, 0x94, 0x28, 0xB9, 0xB2, 0xD2,
     
    34153415   0x9A, 0x57, 0xA2, 0x74, 0xC6, 0xFE, 0x9B, 0x58 };
    34163416
    3417 unsigned char table_159[256] = {
     3417static const unsigned char table_159[256] = {
    34183418   0xE5, 0xBF, 0x84, 0x56, 0xD6, 0x43, 0x3E, 0xA5,
    34193419   0x64, 0x87, 0x44, 0x63, 0x4A, 0x4C, 0x8D, 0x24,
     
    34493449   0xCB, 0x9B, 0x13, 0x8F, 0xA4, 0x28, 0x23, 0x85 };
    34503450
    3451 unsigned char table_160[256] = {
     3451static const unsigned char table_160[256] = {
    34523452   0x35, 0x44, 0x0E, 0x92, 0x75, 0x83, 0x9D, 0x53,
    34533453   0xA5, 0x90, 0xF8, 0xF7, 0x54, 0x74, 0xDF, 0x3D,
     
    34833483   0xBB, 0x2C, 0xE5, 0xC3, 0x67, 0xA1, 0x10, 0xB9 };
    34843484
    3485 unsigned char table_161[256] = {
     3485static const unsigned char table_161[256] = {
    34863486   0x8F, 0x1A, 0x81, 0xA2, 0x2C, 0x56, 0x6D, 0xCD,
    34873487   0x4A, 0x33, 0x50, 0xE9, 0xE0, 0x12, 0x5A, 0x43,
     
    35173517   0xBE, 0x0A, 0x36, 0x41, 0xC0, 0x8C, 0xE4, 0xAA };
    35183518
    3519 unsigned char table_162[256] = {
     3519static const unsigned char table_162[256] = {
    35203520   0xF7, 0x1B, 0xC0, 0x31, 0x5A, 0x23, 0xEA, 0xE9,
    35213521   0xFB, 0x14, 0x6A, 0xE8, 0x04, 0x65, 0x5B, 0x2C,
     
    35513551   0x38, 0xCC, 0x58, 0x44, 0xBF, 0x93, 0x5D, 0xC7 };
    35523552
    3553 unsigned char table_163[32] = {
     3553static const unsigned char table_163[32] = {
    35543554   0x1B, 0x14, 0x12, 0x15, 0x11, 0x1D, 0x17, 0x19,
    35553555   0x10, 0x09, 0x08, 0x06, 0x1A, 0x16, 0x07, 0x13,
     
    35573557   0x04, 0x01, 0x03, 0x0C, 0x0D, 0x1E, 0x02, 0x0F };
    35583558
    3559 unsigned char table_164[32] = {
     3559static const unsigned char table_164[32] = {
    35603560   0x15, 0x00, 0x10, 0x0B, 0x1D, 0x0A, 0x06, 0x1C,
    35613561   0x0D, 0x1F, 0x17, 0x0F, 0x03, 0x14, 0x13, 0x12,
     
    35633563   0x02, 0x0C, 0x0E, 0x01, 0x07, 0x19, 0x11, 0x05 };
    35643564
    3565 unsigned char table_165[256] = {
     3565static const unsigned char table_165[256] = {
    35663566   0x98, 0xF5, 0x1D, 0xFB, 0x13, 0x20, 0x41, 0xA3,
    35673567   0xE3, 0x76, 0x49, 0x7E, 0x60, 0xD8, 0x68, 0x30,
     
    35973597   0x1A, 0x26, 0xCC, 0xB1, 0xF9, 0xFA, 0x97, 0xE9 };
    35983598
    3599 unsigned char table_166[256] = {
     3599static const unsigned char table_166[256] = {
    36003600   0xCB, 0xEA, 0x2A, 0x36, 0x6D, 0x93, 0x4E, 0xD5,
    36013601   0xBC, 0x6A, 0xD4, 0x68, 0xF7, 0x18, 0xAB, 0x8B,
     
    36313631   0x1C, 0xE0, 0x51, 0x16, 0x43, 0x07, 0x0A, 0x3F };
    36323632
    3633 unsigned char table_167[256] = {
     3633static const unsigned char table_167[256] = {
    36343634   0x91, 0xEA, 0x4F, 0x6A, 0x6E, 0x2D, 0x27, 0x22,
    36353635   0x44, 0xA5, 0x6D, 0xE3, 0x45, 0x06, 0xE2, 0x87,
     
    36653665   0x14, 0x15, 0x25, 0x32, 0x6C, 0x69, 0x1A, 0xCF };
    36663666
    3667 unsigned char table_168[256] = {
     3667static const unsigned char table_168[256] = {
    36683668   0x28, 0xEE, 0xB1, 0xFD, 0xB3, 0xEF, 0x36, 0x8E,
    36693669   0x85, 0x5D, 0x1C, 0x53, 0x1E, 0xDA, 0xBA, 0x3C,
     
    36993699   0x66, 0x2E, 0x08, 0x32, 0x4C, 0x33, 0x7E, 0xE1 };
    37003700
    3701 unsigned char table_169[256] = {
     3701static const unsigned char table_169[256] = {
    37023702   0xA4, 0x31, 0xA9, 0x3F, 0x13, 0x4D, 0x1B, 0x29,
    37033703   0x73, 0x43, 0xF1, 0xE7, 0x9C, 0xC2, 0xF6, 0xCD,
     
    37333733   0x6B, 0x0A, 0x59, 0x9E, 0x5E, 0x38, 0x45, 0x80 };
    37343734
    3735 unsigned char table_170[256] = {
     3735static const unsigned char table_170[256] = {
    37363736   0xE3, 0x00, 0x99, 0x03, 0xF6, 0xDD, 0xD1, 0x41,
    37373737   0x58, 0x7E, 0xD9, 0x46, 0x04, 0xAF, 0x5C, 0x43,
     
    37673767   0x48, 0x30, 0x87, 0x83, 0x12, 0x4D, 0x65, 0xDF };
    37683768
    3769 unsigned char table_171[32] = {
     3769static const unsigned char table_171[32] = {
    37703770   0x07, 0x06, 0x11, 0x08, 0x0C, 0x1F, 0x19, 0x02,
    37713771   0x14, 0x04, 0x0D, 0x18, 0x1A, 0x05, 0x17, 0x13,
     
    37733773   0x1D, 0x10, 0x00, 0x12, 0x0B, 0x0E, 0x09, 0x0A };
    37743774
    3775 unsigned char table_172[32] = {
     3775static const unsigned char table_172[32] = {
    37763776   0x11, 0x01, 0x1F, 0x06, 0x1A, 0x04, 0x02, 0x09,
    37773777   0x05, 0x0D, 0x0B, 0x18, 0x0E, 0x12, 0x1B, 0x17,
     
    37793779   0x03, 0x0C, 0x00, 0x10, 0x0A, 0x1C, 0x0F, 0x13 };
    37803780
    3781 unsigned char table_173[32] = {
     3781static const unsigned char table_173[32] = {
    37823782   0x1F, 0x0B, 0x13, 0x00, 0x16, 0x15, 0x14, 0x0A,
    37833783   0x1D, 0x05, 0x1E, 0x1A, 0x0F, 0x04, 0x0E, 0x01,
     
    37853785   0x03, 0x11, 0x18, 0x10, 0x1C, 0x1B, 0x06, 0x0D };
    37863786
    3787 unsigned char table_174[32] = {
     3787static const unsigned char table_174[32] = {
    37883788   0x02, 0x1B, 0x0C, 0x17, 0x1F, 0x05, 0x15, 0x1E,
    37893789   0x16, 0x09, 0x1A, 0x12, 0x0F, 0x1C, 0x18, 0x0A,
     
    37913791   0x1D, 0x0E, 0x06, 0x00, 0x01, 0x07, 0x0B, 0x03 };
    37923792
    3793 unsigned char table_175[32] = {
     3793static const unsigned char table_175[32] = {
    37943794   0x00, 0x06, 0x0B, 0x08, 0x0C, 0x04, 0x1A, 0x1C,
    37953795   0x05, 0x1E, 0x14, 0x03, 0x0A, 0x18, 0x12, 0x1D,
     
    37973797   0x11, 0x19, 0x10, 0x0D, 0x1B, 0x02, 0x01, 0x15 };
    37983798
    3799 unsigned char table_176[32] = {
     3799static const unsigned char table_176[32] = {
    38003800   0x12, 0x03, 0x1A, 0x15, 0x04, 0x19, 0x0B, 0x1B,
    38013801   0x17, 0x1E, 0x0D, 0x05, 0x11, 0x14, 0x1C, 0x00,
     
    38033803   0x13, 0x09, 0x16, 0x1D, 0x0F, 0x0C, 0x01, 0x1F };
    38043804
    3805 unsigned char table_177[256] = {
     3805static const unsigned char table_177[256] = {
    38063806   0x5E, 0x4D, 0x76, 0xFE, 0xB5, 0x50, 0x83, 0x23,
    38073807   0x72, 0xDD, 0x93, 0x08, 0x69, 0xAD, 0xEC, 0x3B,
     
    38373837   0x5A, 0xC5, 0xE0, 0x58, 0x41, 0x4E, 0x4A, 0xAF };
    38383838
    3839 unsigned char table_178[256] = {
     3839static const unsigned char table_178[256] = {
    38403840   0x33, 0xBA, 0x98, 0xDA, 0x07, 0x2C, 0x22, 0x9B,
    38413841   0xE0, 0xED, 0xB7, 0xA1, 0x93, 0xEB, 0xDC, 0x49,
     
    38713871   0x95, 0x9E, 0xBF, 0xEF, 0xF8, 0x45, 0x00, 0xB4 };
    38723872
    3873 unsigned char table_179[256] = {
     3873static const unsigned char table_179[256] = {
    38743874   0x50, 0x3D, 0x41, 0x42, 0x06, 0x5B, 0xD6, 0x34,
    38753875   0x9D, 0x3C, 0x7B, 0x14, 0xE2, 0x9B, 0x80, 0x15,
     
    39053905   0x2A, 0x04, 0x18, 0xA5, 0xA2, 0x6E, 0x07, 0xE3 };
    39063906
    3907 unsigned char table_180[256] = {
     3907static const unsigned char table_180[256] = {
    39083908   0xDA, 0xCC, 0x72, 0xA6, 0xE7, 0x07, 0xFD, 0x25,
    39093909   0x92, 0x39, 0x49, 0x02, 0xD6, 0x09, 0xA8, 0x65,
     
    39393939   0x62, 0x4F, 0xCF, 0xB2, 0xC2, 0x59, 0xDB, 0x67 };
    39403940
    3941 unsigned char table_181[256] = {
     3941static const unsigned char table_181[256] = {
    39423942   0x2B, 0xED, 0x14, 0x05, 0x80, 0xCC, 0x5A, 0xF8,
    39433943   0x43, 0xB7, 0x86, 0xC6, 0xEE, 0xA6, 0xD7, 0xD6,
     
    39733973   0x32, 0x24, 0x7D, 0x9B, 0xD2, 0x83, 0x35, 0xCD };
    39743974
    3975 unsigned char table_182[256] = {
     3975static const unsigned char table_182[256] = {
    39763976   0x06, 0x7F, 0x66, 0xB5, 0xBA, 0x1E, 0xFD, 0x51,
    39773977   0x81, 0x8D, 0x28, 0xA3, 0x15, 0x37, 0xDC, 0x58,
     
    40074007   0x7B, 0x17, 0x0B, 0x0A, 0x41, 0x03, 0xD4, 0x4B };
    40084008
    4009 unsigned char table_183[32] = {
     4009static const unsigned char table_183[32] = {
    40104010   0x1E, 0x1B, 0x11, 0x07, 0x08, 0x06, 0x18, 0x17,
    40114011   0x0D, 0x0F, 0x12, 0x03, 0x1D, 0x04, 0x0A, 0x1A,
     
    40134013   0x16, 0x05, 0x1C, 0x0E, 0x02, 0x00, 0x09, 0x15 };
    40144014
    4015 unsigned char table_184[32] = {
     4015static const unsigned char table_184[32] = {
    40164016   0x0F, 0x1D, 0x17, 0x16, 0x0D, 0x05, 0x13, 0x1F,
    40174017   0x1B, 0x09, 0x1C, 0x1E, 0x15, 0x01, 0x06, 0x08,
     
    40194019   0x18, 0x0E, 0x03, 0x11, 0x12, 0x14, 0x19, 0x00 };
    40204020
    4021 unsigned char table_185[256] = {
     4021static const unsigned char table_185[256] = {
    40224022   0xA5, 0xEE, 0x2E, 0x28, 0xA7, 0xAC, 0xD9, 0xB2,
    40234023   0x6E, 0x04, 0xB4, 0x03, 0xE8, 0x92, 0x5F, 0x4D,
     
    40534053   0x2B, 0xC5, 0x98, 0x18, 0x66, 0x15, 0x9C, 0xBC };
    40544054
    4055 unsigned char table_186[256] = {
     4055static const unsigned char table_186[256] = {
    40564056   0xB7, 0xFA, 0x03, 0x7C, 0x76, 0x43, 0xA7, 0x15,
    40574057   0x4B, 0x4F, 0x04, 0xAA, 0x4E, 0xD2, 0x52, 0xC8,
     
    40874087   0x11, 0x3B, 0x94, 0xE8, 0x7D, 0x7B, 0xD9, 0x5A };
    40884088
    4089 unsigned char table_187[32] = {
     4089static const unsigned char table_187[32] = {
    40904090   0x0F, 0x04, 0x1D, 0x1B, 0x15, 0x10, 0x01, 0x0B,
    40914091   0x00, 0x17, 0x13, 0x07, 0x1E, 0x1F, 0x08, 0x0A,
     
    40934093   0x0E, 0x18, 0x03, 0x1C, 0x12, 0x11, 0x0D, 0x02 };
    40944094
    4095 struct yahoo_fn yahoo_fntable[5][96] =
     4095static const struct yahoo_fn yahoo_fntable[5][96] =
    40964096   {{{ IDENT, 0, 0 },
    40974097     { IDENT, 0, 0 },
     
    45824582int yahoo_xfrm( int table, int depth, int seed )
    45834583{
    4584    struct yahoo_fn *xfrm;
     4584   const struct yahoo_fn *xfrm;
    45854585   int i, j, z;
    45864586   unsigned int n = seed;
  • protocols/yahoo/yahoo_list.h

    ra323a22 r5ebe625  
    2121 */
    2222
    23 /*
    24  * This is a replacement for the GList.  It only provides functions that
    25  * we use in Ayttm.  Thanks to Meredyyd from everybuddy dev for doing
    26  * most of it.
    27  */
    28 
    2923#ifndef __YLIST_H__
    3024#define __YLIST_H__
    3125
    32 #ifdef __cplusplus
    33 extern "C" {
     26/* GLib has linked list already, so I don't see why libyahoo2 has to copy this... */
     27
     28typedef GList YList;
     29
     30#define y_list_append g_list_append
     31#define y_list_concat g_list_concat
     32#define y_list_copy g_list_copy
     33#define y_list_empty g_list_empty
     34#define y_list_find g_list_find
     35#define y_list_find_custom g_list_find_custom
     36#define y_list_foreach g_list_foreach
     37#define y_list_free g_list_free
     38#define y_list_free_1 g_list_free_1
     39#define y_list_insert_sorted g_list_insert_sorted
     40#define y_list_length g_list_length
     41#define y_list_next g_list_next
     42#define y_list_nth g_list_nth
     43#define y_list_prepend g_list_prepend
     44#define y_list_remove g_list_remove
     45#define y_list_remove_link g_list_remove_link
     46#define y_list_singleton g_list_singleton
     47
    3448#endif
    35 
    36 typedef struct _YList {
    37         struct _YList *next;
    38         struct _YList *prev;
    39         void *data;
    40 } YList;
    41 
    42 typedef int (*YListCompFunc) (const void *, const void *);
    43 typedef void (*YListFunc) (void *, void *);
    44 
    45 YList *y_list_append(YList * list, void *data);
    46 YList *y_list_prepend(YList * list, void *data);
    47 YList *y_list_remove_link(YList * list, const YList * link);
    48 YList *y_list_remove(YList * list, void *data);
    49 
    50 YList *y_list_insert_sorted(YList * list, void * data, YListCompFunc comp);
    51 
    52 YList *y_list_copy(YList * list);
    53 
    54 YList *y_list_concat(YList * list, YList * add);
    55 
    56 YList *y_list_find(YList * list, const void *data);
    57 YList *y_list_find_custom(YList * list, const void *data, YListCompFunc comp);
    58 
    59 YList *y_list_nth(YList * list, int n);
    60 
    61 void y_list_foreach(YList * list, YListFunc fn, void *user_data);
    62 
    63 void y_list_free_1(YList * list);
    64 void y_list_free(YList * list);
    65 int  y_list_length(const YList * list);
    66 int  y_list_empty(const YList * list);
    67 int  y_list_singleton(const YList * list);
    68 
    69 #define y_list_next(list)       list->next
    70 
    71 #ifdef __cplusplus
    72 }
    73 #endif
    74 #endif
  • protocols/yahoo/yahoo_util.c

    ra323a22 r5ebe625  
    5050
    5151        return new_string;
    52 }
    53 
    54 char * y_str_to_utf8(const char *in)
    55 {
    56         unsigned int n, i = 0;
    57         char *result = NULL;
    58 
    59         if(in == NULL || *in == '\0')
    60                 return "";
    61        
    62         result = y_new(char, strlen(in) * 2 + 1);
    63 
    64         /* convert a string to UTF-8 Format */
    65         for (n = 0; n < strlen(in); n++) {
    66                 unsigned char c = (unsigned char)in[n];
    67 
    68                 if (c < 128) {
    69                         result[i++] = (char) c;
    70                 } else {
    71                         result[i++] = (char) ((c >> 6) | 192);
    72                         result[i++] = (char) ((c & 63) | 128);
    73                 }
    74         }
    75         result[i] = '\0';
    76         return result;
    77 }
    78 
    79 char * y_utf8_to_str(const char *in)
    80 {
    81         int i = 0;
    82         unsigned int n;
    83         char *result = NULL;
    84 
    85         if(in == NULL || *in == '\0')
    86                 return "";
    87        
    88         result = y_new(char, strlen(in) + 1);
    89 
    90         /* convert a string from UTF-8 Format */
    91         for (n = 0; n < strlen(in); n++) {
    92                 unsigned char c = in[n];
    93 
    94                 if (c < 128) {
    95                         result[i++] = (char) c;
    96                 } else {
    97                         result[i++] = (c << 6) | (in[++n] & 63);
    98                 }
    99         }
    100         result[i] = '\0';
    101         return result;
    10252}
    10353
  • root_commands.c

    ra323a22 r5ebe625  
    3232#include <string.h>
    3333
    34 command_t commands[] = {
    35         { "help",           0, cmd_help },
    36         { "identify",       1, cmd_identify },
    37         { "register",       1, cmd_register },
    38         { "drop",           1, cmd_drop },
    39         { "account",        1, cmd_account },
    40         { "add",            2, cmd_add },
    41         { "info",           1, cmd_info },
    42         { "rename",         2, cmd_rename },
    43         { "remove",         1, cmd_remove },
    44         { "block",          1, cmd_block },
    45         { "allow",          1, cmd_allow },
    46         { "save",           0, cmd_save },
    47         { "set",            0, cmd_set },
    48         { "yes",            0, cmd_yesno },
    49         { "no",             0, cmd_yesno },
    50         { "blist",          0, cmd_blist },
    51         { "nick",           1, cmd_nick },
    52         { "import_buddies", 1, cmd_import_buddies },
    53         { "qlist",          0, cmd_qlist },
    54         { NULL }
    55 };
    56 
    57 int cmd_help( irc_t *irc, char **cmd )
     34void root_command_string( irc_t *irc, user_t *u, char *command, int flags )
     35{
     36        char *cmd[IRC_MAX_ARGS];
     37        char *s;
     38        int k;
     39        char q = 0;
     40       
     41        memset( cmd, 0, sizeof( cmd ) );
     42        cmd[0] = command;
     43        k = 1;
     44        for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
     45                if( *s == ' ' && !q )
     46                {
     47                        *s = 0;
     48                        while( *++s == ' ' );
     49                        if( *s == '"' || *s == '\'' )
     50                        {
     51                                q = *s;
     52                                s ++;
     53                        }
     54                        if( *s )
     55                        {
     56                                cmd[k++] = s;
     57                                s --;
     58                        }
     59                }
     60                else if( *s == q )
     61                {
     62                        q = *s = 0;
     63                }
     64        cmd[k] = NULL;
     65       
     66        root_command( irc, cmd );
     67}
     68
     69void root_command( irc_t *irc, char *cmd[] )
     70{       
     71        int i;
     72       
     73        if( !cmd[0] )
     74                return;
     75       
     76        for( i = 0; commands[i].command; i++ )
     77                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
     78                {
     79                        if( !cmd[commands[i].required_parameters] )
     80                        {
     81                                irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
     82                                return;
     83                        }
     84                        commands[i].execute( irc, cmd );
     85                        return;
     86                }
     87       
     88        irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] );
     89}
     90
     91static void cmd_help( irc_t *irc, char **cmd )
    5892{
    5993        char param[80];
     
    75109                irc_usermsg( irc, "%s", s );
    76110                g_free( s );
    77                 return( 1 );
    78111        }
    79112        else
    80113        {
    81114                irc_usermsg( irc, "Error opening helpfile." );
    82                 return( 0 );
    83         }
    84 }
    85 
    86 int cmd_identify( irc_t *irc, char **cmd )
     115        }
     116}
     117
     118static void cmd_identify( irc_t *irc, char **cmd )
    87119{
    88120        storage_status_t status = storage_load( irc->nick, cmd[1], irc );
     
    97129        case STORAGE_OK:
    98130                irc_usermsg( irc, "Password accepted" );
     131                irc_umode_set( irc, "+R", 1 );
    99132                break;
    100133        default:
     
    102135                break;
    103136        }
    104 
    105         return( 0 );
    106 }
    107 
    108 int cmd_register( irc_t *irc, char **cmd )
     137}
     138
     139static void cmd_register( irc_t *irc, char **cmd )
    109140{
    110141        if( global.conf->authmode == AUTHMODE_REGISTERED )
    111142        {
    112143                irc_usermsg( irc, "This server does not allow registering new accounts" );
    113                 return( 0 );
     144                return;
    114145        }
    115146
     
    122153                case STORAGE_OK:
    123154                        irc->status = USTATUS_IDENTIFIED;
     155                        irc_umode_set( irc, "+R", 1 );
    124156                        break;
    125157
     
    128160                        break;
    129161        }
    130        
    131         return( 0 );
    132 }
    133 
    134 int cmd_drop( irc_t *irc, char **cmd )
     162}
     163
     164static void cmd_drop( irc_t *irc, char **cmd )
    135165{
    136166        storage_status_t status;
     
    140170        case STORAGE_NO_SUCH_USER:
    141171                irc_usermsg( irc, "That account does not exist" );
    142                 return( 0 );
     172                break;
    143173        case STORAGE_INVALID_PASSWORD:
    144174                irc_usermsg( irc, "Password invalid" );
    145                 return( 0 );
     175                break;
    146176        case STORAGE_OK:
    147177                irc_setpass( irc, NULL );
     178                irc->status = USTATUS_LOGGED_IN;
     179                irc_umode_set( irc, "-R", 1 );
    148180                irc_usermsg( irc, "Account `%s' removed", irc->nick );
    149                 return( 0 );
     181                break;
    150182        default:
    151183                irc_usermsg( irc, "Error: '%d'", status );
    152                 return( 0 );
    153         }
    154 }
    155 
    156 int cmd_account( irc_t *irc, char **cmd )
     184                break;
     185        }
     186}
     187
     188static void cmd_account( irc_t *irc, char **cmd )
    157189{
    158190        account_t *a;
     
    161193        {
    162194                irc_usermsg( irc, "This server only accepts registered users" );
    163                 return( 0 );
     195                return;
    164196        }
    165197       
     
    171203                {
    172204                        irc_usermsg( irc, "Not enough parameters" );
    173                         return( 0 );
     205                        return;
    174206                }
    175207               
     
    179211                {
    180212                        irc_usermsg( irc, "Unknown protocol" );
    181                         return( 0 );
     213                        return;
    182214                }
    183215
     
    241273                                {
    242274                                        irc_usermsg( irc, "Account already online" );
    243                                         return( 0 );
     275                                        return;
    244276                                }
    245277                                else
     
    251283                        {
    252284                                irc_usermsg( irc, "Invalid account" );
    253                                 return( 0 );
     285                                return;
    254286                        }
    255287                }
     
    297329                        {
    298330                                irc_usermsg( irc, "Account already offline" );
    299                                 return( 0 );
     331                                return;
    300332                        }
    301333                }
     
    303335                {
    304336                        irc_usermsg( irc, "Invalid account" );
    305                         return( 0 );
     337                        return;
    306338                }
    307339        }
     
    310342                irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] );
    311343        }
    312        
    313         return( 1 );
    314 }
    315 
    316 int cmd_add( irc_t *irc, char **cmd )
     344}
     345
     346static void cmd_add( irc_t *irc, char **cmd )
    317347{
    318348        account_t *a;
     
    321351        {
    322352                irc_usermsg( irc, "Invalid account" );
    323                 return( 1 );
     353                return;
    324354        }
    325355        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
    326356        {
    327357                irc_usermsg( irc, "That account is not on-line" );
    328                 return( 1 );
     358                return;
    329359        }
    330360       
     
    334364                {
    335365                        irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] );
    336                         return( 0 );
     366                        return;
    337367                }
    338368                else if( user_find( irc, cmd[3] ) )
    339369                {
    340370                        irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] );
    341                         return( 0 );
     371                        return;
    342372                }
    343373                else
     
    350380       
    351381        irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick );
    352        
    353         return( 0 );
    354 }
    355 
    356 int cmd_info( irc_t *irc, char **cmd )
     382}
     383
     384static void cmd_info( irc_t *irc, char **cmd )
    357385{
    358386        struct gaim_connection *gc;
     
    365393                {
    366394                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    367                         return( 1 );
     395                        return;
    368396                }
    369397                gc = u->gc;
     
    373401        {
    374402                irc_usermsg( irc, "Invalid account" );
    375                 return( 1 );
     403                return;
    376404        }
    377405        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
    378406        {
    379407                irc_usermsg( irc, "That account is not on-line" );
    380                 return( 1 );
     408                return;
    381409        }
    382410       
     
    384412        {
    385413                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
    386                 return( 1 );
    387         }
    388         gc->prpl->get_info( gc, cmd[2] );
    389        
    390         return( 0 );
    391 }
    392 
    393 int cmd_rename( irc_t *irc, char **cmd )
     414        }
     415        else
     416        {
     417                gc->prpl->get_info( gc, cmd[2] );
     418        }
     419}
     420
     421static void cmd_rename( irc_t *irc, char **cmd )
    394422{
    395423        user_t *u;
     
    398426        {
    399427                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
    400                 return( 1 );
    401         }
    402         if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
     428        }
     429        else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
    403430        {
    404431                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
    405                 return( 1 );
    406         }
    407         if( !nick_ok( cmd[2] ) )
     432        }
     433        else if( !nick_ok( cmd[2] ) )
    408434        {
    409435                irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
    410                 return( 1 );
    411         }
    412         if( !( u = user_find( irc, cmd[1] ) ) )
     436        }
     437        else if( !( u = user_find( irc, cmd[1] ) ) )
    413438        {
    414439                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    415                 return( 1 );
    416         }
    417         user_rename( irc, cmd[1], cmd[2] );
    418         irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
    419         if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
    420         {
    421                 g_free( irc->mynick );
    422                 irc->mynick = g_strdup( cmd[2] );
    423         }
    424         else if( u->send_handler == buddy_send_handler )
    425         {
    426                 nick_set( irc, u->handle, u->gc->prpl, cmd[2] );
    427         }
    428        
    429         irc_usermsg( irc, "Nick successfully changed" );
    430        
    431         return( 0 );
    432 }
    433 
    434 int cmd_remove( irc_t *irc, char **cmd )
     440        }
     441        else
     442        {
     443                user_rename( irc, cmd[1], cmd[2] );
     444                irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
     445                if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
     446                {
     447                        g_free( irc->mynick );
     448                        irc->mynick = g_strdup( cmd[2] );
     449                }
     450                else if( u->send_handler == buddy_send_handler )
     451                {
     452                        nick_set( irc, u->handle, u->gc->prpl, cmd[2] );
     453                }
     454               
     455                irc_usermsg( irc, "Nick successfully changed" );
     456        }
     457}
     458
     459static void cmd_remove( irc_t *irc, char **cmd )
    435460{
    436461        user_t *u;
     
    440465        {
    441466                irc_usermsg( irc, "Buddy `%s' not found", cmd[1] );
    442                 return( 1 );
     467                return;
    443468        }
    444469        s = g_strdup( u->handle );
     
    451476        g_free( s );
    452477       
    453         return( 0 );
    454 }
    455 
    456 int cmd_block( irc_t *irc, char **cmd )
     478        return;
     479}
     480
     481static void cmd_block( irc_t *irc, char **cmd )
    457482{
    458483        struct gaim_connection *gc;
     
    465490                {
    466491                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    467                         return( 1 );
     492                        return;
    468493                }
    469494                gc = u->gc;
     
    473498        {
    474499                irc_usermsg( irc, "Invalid account" );
    475                 return( 1 );
     500                return;
    476501        }
    477502        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
    478503        {
    479504                irc_usermsg( irc, "That account is not on-line" );
    480                 return( 1 );
     505                return;
    481506        }
    482507       
     
    491516                irc_usermsg( irc, "Buddy `%s' moved from your permit- to your deny-list", cmd[2] );
    492517        }
    493        
    494         return( 0 );
    495 }
    496 
    497 int cmd_allow( irc_t *irc, char **cmd )
     518}
     519
     520static void cmd_allow( irc_t *irc, char **cmd )
    498521{
    499522        struct gaim_connection *gc;
     
    506529                {
    507530                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
    508                         return( 1 );
     531                        return;
    509532                }
    510533                gc = u->gc;
     
    514537        {
    515538                irc_usermsg( irc, "Invalid account" );
    516                 return( 1 );
     539                return;
    517540        }
    518541        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
    519542        {
    520543                irc_usermsg( irc, "That account is not on-line" );
    521                 return( 1 );
     544                return;
    522545        }
    523546       
     
    533556                irc_usermsg( irc, "Buddy `%s' moved from your deny- to your permit-list", cmd[2] );
    534557        }
    535        
    536         return( 0 );
    537 }
    538 
    539 int cmd_yesno( irc_t *irc, char **cmd )
     558}
     559
     560static void cmd_yesno( irc_t *irc, char **cmd )
    540561{
    541562        query_t *q = NULL;
     
    545566        {
    546567                irc_usermsg( irc, "Did I ask you something?" );
    547                 return( 0 );
     568                return;
    548569        }
    549570       
     
    555576                {
    556577                        irc_usermsg( irc, "Invalid query number" );
    557                         return( 0 );
     578                        return;
    558579                }
    559580               
     
    565586                {
    566587                        irc_usermsg( irc, "Uhm, I never asked you something like that..." );
    567                         return( 0 );
     588                        return;
    568589                }
    569590        }
     
    573594        else if( g_strcasecmp( cmd[0], "no" ) == 0 )
    574595                query_answer( irc, q, 0 );
    575        
    576         return( 1 );
    577 }
    578 
    579 int cmd_set( irc_t *irc, char **cmd )
     596}
     597
     598static void cmd_set( irc_t *irc, char **cmd )
    580599{
    581600        if( cmd[1] && cmd[2] )
    582601        {
    583602                set_setstr( irc, cmd[1], cmd[2] );
     603               
     604                if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] )
     605                        irc_usermsg( irc, "Warning: Correct syntax: \002set <variable> <value>\002 (without =)" );
    584606        }
    585607        if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */
     
    599621                }
    600622        }
    601        
    602         return( 0 );
    603 }
    604 
    605 int cmd_save( irc_t *irc, char **cmd )
     623}
     624
     625static void cmd_save( irc_t *irc, char **cmd )
    606626{
    607627        if( storage_save( irc, TRUE ) == STORAGE_OK )
     
    609629        else
    610630                irc_usermsg( irc, "Configuration could not be saved!" );
    611        
    612         return( 0 );
    613 }
    614 
    615 int cmd_blist( irc_t *irc, char **cmd )
     631}
     632
     633static void cmd_blist( irc_t *irc, char **cmd )
    616634{
    617635        int online = 0, away = 0, offline = 0;
     
    655673       
    656674        irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
    657        
    658         return( 0 );
    659 }
    660 
    661 int cmd_nick( irc_t *irc, char **cmd )
     675}
     676
     677static void cmd_nick( irc_t *irc, char **cmd )
    662678{
    663679        account_t *a;
     
    691707                        a->gc->prpl->set_info( a->gc, cmd[2] );
    692708        }
    693        
    694         return( 1 );
    695 }
    696 
    697 int cmd_qlist( irc_t *irc, char **cmd )
     709}
     710
     711static void cmd_qlist( irc_t *irc, char **cmd )
    698712{
    699713        query_t *q = irc->queries;
     
    703717        {
    704718                irc_usermsg( irc, "There are no pending questions." );
    705                 return( 0 );
     719                return;
    706720        }
    707721       
     
    713727                else
    714728                        irc_usermsg( irc, "%d, BitlBee: %s", num, q->question );
    715        
    716         return( 0 );
    717 }
    718 
    719 int cmd_import_buddies( irc_t *irc, char **cmd )
     729}
     730
     731static void cmd_import_buddies( irc_t *irc, char **cmd )
    720732{
    721733        struct gaim_connection *gc;
     
    726738        {
    727739                irc_usermsg( irc, "Invalid account" );
    728                 return( 0 );
     740                return;
    729741        }
    730742        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
    731743        {
    732744                irc_usermsg( irc, "That account is not on-line" );
    733                 return( 0 );
     745                return;
    734746        }
    735747       
     
    752764                {
    753765                        irc_usermsg( irc, "Invalid argument: %s", cmd[2] );
    754                         return( 0 );
     766                        return;
    755767                }
    756768        }
     
    766778       
    767779        irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." );
    768        
    769         return( 0 );
    770 }
     780}
     781
     782const command_t commands[] = {
     783        { "help",           0, cmd_help,           0 },
     784        { "identify",       1, cmd_identify,       0 },
     785        { "register",       1, cmd_register,       0 },
     786        { "drop",           1, cmd_drop,           0 },
     787        { "account",        1, cmd_account,        0 },
     788        { "add",            2, cmd_add,            0 },
     789        { "info",           1, cmd_info,           0 },
     790        { "rename",         2, cmd_rename,         0 },
     791        { "remove",         1, cmd_remove,         0 },
     792        { "block",          1, cmd_block,          0 },
     793        { "allow",          1, cmd_allow,          0 },
     794        { "save",           0, cmd_save,           0 },
     795        { "set",            0, cmd_set,            0 },
     796        { "yes",            0, cmd_yesno,          0 },
     797        { "no",             0, cmd_yesno,          0 },
     798        { "blist",          0, cmd_blist,          0 },
     799        { "nick",           1, cmd_nick,           0 },
     800        { "import_buddies", 1, cmd_import_buddies, 0 },
     801        { "qlist",          0, cmd_qlist,          0 },
     802        { NULL }
     803};
  • sock.h

    ra323a22 r5ebe625  
    11#include <errno.h>
    22#include <fcntl.h>
     3
     4/* To cut down on the ifdef stuff a little bit in other places */
     5#ifdef IPV6
     6#define AF_INETx AF_INET6
     7#else
     8#define AF_INETx AF_INET
     9#endif
    310
    411#ifndef _WIN32
  • storage_text.c

    ra323a22 r5ebe625  
    7171        user_t *ru = user_find( irc, ROOT_NICK );
    7272       
    73         if( irc->status == USTATUS_IDENTIFIED )
     73        if( irc->status >= USTATUS_IDENTIFIED )
    7474                return( 1 );
    7575       
  • unix.c

    ra323a22 r5ebe625  
    2929#include "protocols/nogaim.h"
    3030#include "help.h"
     31#include "ipc.h"
    3132#include <signal.h>
    3233#include <unistd.h>
    3334#include <sys/time.h>
     35#include <sys/wait.h>
    3436
    3537global_t global;        /* Against global namespace pollution */
     
    3739static void sighandler( int signal );
    3840
    39 int main( int argc, char *argv[] )
     41int main( int argc, char *argv[], char **envp )
    4042{
    4143        int i = 0;
     44        char *old_cwd = NULL;
    4245        struct sigaction sig, old;
    4346       
     
    4649        global.loop = g_main_new( FALSE );
    4750       
    48         log_init( );
     51        log_init();
    4952
    5053        nogaim_init();
     
    7073                log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION );
    7174        }
     75        else if( global.conf->runmode == RUNMODE_FORKDAEMON )
     76        {
     77                /* In case the operator requests a restart, we need this. */
     78                old_cwd = g_malloc( 256 );
     79                if( getcwd( old_cwd, 255 ) == NULL )
     80                {
     81                        log_message( LOGLVL_WARNING, "Could not save current directory: %s", strerror( errno ) );
     82                        g_free( old_cwd );
     83                        old_cwd = NULL;
     84                }
     85               
     86                i = bitlbee_daemon_init();
     87                log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION );
     88        }
    7289        if( i != 0 )
    7390                return( i );
    7491
    75         global.storage = storage_init( global.conf->primary_storage,
    76                                                                    global.conf->migrate_storage );
     92        global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );
    7793        if ( global.storage == NULL) {
    7894                log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
     
    84100        memset( &sig, 0, sizeof( sig ) );
    85101        sig.sa_handler = sighandler;
     102        sigaction( SIGCHLD, &sig, &old );
    86103        sigaction( SIGPIPE, &sig, &old );
    87104        sig.sa_flags = SA_RESETHAND;
     
    102119        g_main_run( global.loop );
    103120       
     121        if( global.restart )
     122        {
     123                char *fn = ipc_master_save_state();
     124                char **args;
     125                int n, i;
     126               
     127                chdir( old_cwd );
     128               
     129                n = 0;
     130                args = g_new0( char *, argc + 3 );
     131                args[n++] = argv[0];
     132                if( fn )
     133                {
     134                        args[n++] = "-R";
     135                        args[n++] = fn;
     136                }
     137                for( i = 1; argv[i] && i < argc; i ++ )
     138                {
     139                        if( strcmp( argv[i], "-R" ) == 0 )
     140                                i += 2;
     141                       
     142                        args[n++] = argv[i];
     143                }
     144               
     145                close( global.listen_socket );
     146               
     147                execve( args[0], args, envp );
     148        }
     149       
    104150        return( 0 );
    105151}
     
    107153static void sighandler( int signal )
    108154{
    109         /* FIXME: In fact, calling log_message() here can be dangerous. But well, let's take the risk for now. */
     155        /* FIXME: Calling log_message() here is not a very good idea! */
    110156       
    111157        if( signal == SIGTERM )
     
    133179                }
    134180        }
     181        else if( signal == SIGCHLD )
     182        {
     183                pid_t pid;
     184                int st;
     185               
     186                while( ( pid = waitpid( 0, &st, WNOHANG ) ) > 0 )
     187                {
     188                        if( WIFSIGNALED( st ) )
     189                                log_message( LOGLVL_INFO, "Client %d terminated normally. (status = %d)", pid, WEXITSTATUS( st ) );
     190                        else if( WIFEXITED( st ) )
     191                                log_message( LOGLVL_INFO, "Client %d killed by signal %d.", pid, WTERMSIG( st ) );
     192                }
     193        }
    135194        else if( signal != SIGPIPE )
    136195        {
  • url.c

    ra323a22 r5ebe625  
    4040        else
    4141        {
    42                 if( g_strncasecmp( set_url, "https", i - set_url ) == 0 )
     42                if( g_strncasecmp( set_url, "http", i - set_url ) == 0 )
     43                        url->proto = PROTO_HTTP;
     44                else if( g_strncasecmp( set_url, "https", i - set_url ) == 0 )
    4345                        url->proto = PROTO_HTTPS;
    44                 else if( g_strncasecmp( set_url, "http", i - set_url ) == 0 )
    45                         url->proto = PROTO_HTTP;
    4646                else if( g_strncasecmp( set_url, "socks4", i - set_url ) == 0 )
    4747                        url->proto = PROTO_SOCKS4;
  • user.h

    ra323a22 r5ebe625  
    4545        int sendbuf_flags;
    4646       
    47         int (*send_handler) ( irc_t *irc, struct __USER *u, char *msg, int flags );
     47        void (*send_handler) ( irc_t *irc, struct __USER *u, char *msg, int flags );
    4848       
    4949        struct __USER *next;
  • util.c

    ra323a22 r5ebe625  
    66
    77/*
    8  * nogaim
    9  *
    10  * Gaim without gaim - for BitlBee
     8 * Various utility functions. Some are copied from Gaim to support the
     9 * IM-modules, most are from BitlBee.
    1110 *
    1211 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
    1312 *                          (and possibly other members of the Gaim team)
    14  * Copyright 2002-2004 Wilmer van der Gaast <lintux@lintux.cx>
     13 * Copyright 2002-2005 Wilmer van der Gaast <wilmer@gaast.net>
    1514 */
    1615
     
    3231*/
    3332
    34 /* Parts from util.c from gaim needed by nogaim */
    3533#define BITLBEE_CORE
    3634#include "nogaim.h"
     
    3836#include <stdlib.h>
    3937#include <string.h>
     38#include <ctype.h>
    4039#include <glib.h>
    4140#include <time.h>
    42 
    43 char *utf8_to_str(const char *in)
    44 {
    45         int n = 0, i = 0;
    46         int inlen;
    47         char *result;
    48 
    49         if (!in)
    50                 return NULL;
    51 
    52         inlen = strlen(in);
    53 
    54         result = g_malloc(inlen + 1);
    55 
    56         while (n <= inlen - 1) {
    57                 long c = (long)in[n];
    58                 if (c < 0x80)
    59                         result[i++] = (char)c;
    60                 else {
    61                         if ((c & 0xC0) == 0xC0)
    62                                 result[i++] =
    63                                     (char)(((c & 0x03) << 6) | (((unsigned char)in[++n]) & 0x3F));
    64                         else if ((c & 0xE0) == 0xE0) {
    65                                 if (n + 2 <= inlen) {
    66                                         result[i] =
    67                                             (char)(((c & 0xF) << 4) | (((unsigned char)in[++n]) & 0x3F));
    68                                         result[i] =
    69                                             (char)(((unsigned char)result[i]) |
    70                                                    (((unsigned char)in[++n]) & 0x3F));
    71                                         i++;
    72                                 } else
    73                                         n += 2;
    74                         } else if ((c & 0xF0) == 0xF0)
    75                                 n += 3;
    76                         else if ((c & 0xF8) == 0xF8)
    77                                 n += 4;
    78                         else if ((c & 0xFC) == 0xFC)
    79                                 n += 5;
    80                 }
    81                 n++;
    82         }
    83         result[i] = '\0';
    84 
    85         return result;
    86 }
    87 
    88 char *str_to_utf8(const char *in)
    89 {
    90         int n = 0, i = 0;
    91         int inlen;
    92         char *result = NULL;
    93 
    94         if (!in)
    95                 return NULL;
    96 
    97         inlen = strlen(in);
    98 
    99         result = g_malloc(inlen * 2 + 1);
    100 
    101         while (n < inlen) {
    102                 long c = (long)in[n];
    103                 if (c == 27) {
    104                         n += 2;
    105                         if (in[n] == 'x')
    106                                 n++;
    107                         if (in[n] == '3')
    108                                 n++;
    109                         n += 2;
    110                         continue;
    111                 }
    112                 /* why are we removing newlines and carriage returns?
    113                 if ((c == 0x0D) || (c == 0x0A)) {
    114                         n++;
    115                         continue;
    116                 }
    117                 */
    118                 if (c < 128)
    119                         result[i++] = (char)c;
    120                 else {
    121                         result[i++] = (char)((c >> 6) | 192);
    122                         result[i++] = (char)((c & 63) | 128);
    123                 }
    124                 n++;
    125         }
    126         result[i] = '\0';
    127 
    128         return result;
    129 }
    13041
    13142void strip_linefeed(gchar *text)
     
    271182{
    272183        char code[8];
    273         char is;
     184        char is[4];
    274185} htmlentity_t;
    275186
    276187/* FIXME: This is ISO8859-1(5) centric, so might cause problems with other charsets. */
    277188
    278 static htmlentity_t ent[] =
    279 {
    280         { "lt",     '<' },
    281         { "gt",     '>' },
    282         { "amp",    '&' },
    283         { "quot",   '"' },
    284         { "aacute", 'á' },
    285         { "eacute", 'é' },
    286         { "iacute", 'é' },
    287         { "oacute", 'ó' },
    288         { "uacute", 'ú' },
    289         { "agrave", 'à' },
    290         { "egrave", 'è' },
    291         { "igrave", 'ì' },
    292         { "ograve", 'ò' },
    293         { "ugrave", 'ù' },
    294         { "acirc",  'â' },
    295         { "ecirc",  'ê' },
    296         { "icirc",  'î' },
    297         { "ocirc",  'ô' },
    298         { "ucirc",  'û' },
    299         { "nbsp",   ' ' },
    300         { "",        0  }
     189static const htmlentity_t ent[] =
     190{
     191        { "lt",     "<" },
     192        { "gt",     ">" },
     193        { "amp",    "&" },
     194        { "quot",   "\"" },
     195        { "aacute", "á" },
     196        { "eacute", "é" },
     197        { "iacute", "é" },
     198        { "oacute", "ó" },
     199        { "uacute", "ú" },
     200        { "agrave", "à" },
     201        { "egrave", "è" },
     202        { "igrave", "ì" },
     203        { "ograve", "ò" },
     204        { "ugrave", "ù" },
     205        { "acirc",  "â" },
     206        { "ecirc",  "ê" },
     207        { "icirc",  "î" },
     208        { "ocirc",  "ô" },
     209        { "ucirc",  "û" },
     210        { "auml",   "ä" },
     211        { "euml",   "ë" },
     212        { "iuml",   "ï" },
     213        { "ouml",   "ö" },
     214        { "uuml",   "ü" },
     215        { "nbsp",   " " },
     216        { "",        ""  }
    301217};
    302218
     
    347263                                if( g_strncasecmp( ent[i].code, cs, strlen( ent[i].code ) ) == 0 )
    348264                                {
    349                                         *(s++) = ent[i].is;
     265                                        int j;
     266                                       
     267                                        for( j = 0; ent[i].is[j]; j ++ )
     268                                                *(s++) = ent[i].is[j];
     269                                       
    350270                                        matched = 1;
    351271                                        break;
     
    412332                g_string_sprintfa( str, "%s%s: %s", newline, name, value );
    413333}
     334
     335/* Decode%20a%20file%20name                                             */
     336void http_decode( char *s )
     337{
     338        char *t;
     339        int i, j, k;
     340       
     341        t = g_new( char, strlen( s ) + 1 );
     342       
     343        for( i = j = 0; s[i]; i ++, j ++ )
     344        {
     345                if( s[i] == '%' )
     346                {
     347                        if( sscanf( s + i + 1, "%2x", &k ) )
     348                        {
     349                                t[j] = k;
     350                                i += 2;
     351                        }
     352                        else
     353                        {
     354                                *t = 0;
     355                                break;
     356                        }
     357                }
     358                else
     359                {
     360                        t[j] = s[i];
     361                }
     362        }
     363        t[j] = 0;
     364       
     365        strcpy( s, t );
     366        g_free( t );
     367}
     368
     369/* Warning: This one explodes the string. Worst-cases can make the string 3x its original size! */
     370/* This fuction is safe, but make sure you call it safely as well! */
     371void http_encode( char *s )
     372{
     373        char *t;
     374        int i, j;
     375       
     376        t = g_strdup( s );
     377       
     378        for( i = j = 0; t[i]; i ++, j ++ )
     379        {
     380                /* if( t[i] <= ' ' || ((unsigned char *)t)[i] >= 128 || t[i] == '%' ) */
     381                if( !isalnum( t[i] ) )
     382                {
     383                        sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] );
     384                        j += 2;
     385                }
     386                else
     387                {
     388                        s[j] = t[i];
     389                }
     390        }
     391        s[j] = 0;
     392       
     393        g_free( t );
     394}
     395
     396/* Strip newlines from a string. Modifies the string passed to it. */
     397char *strip_newlines( char *source )
     398{
     399        int i; 
     400
     401        for( i = 0; source[i] != '\0'; i ++ )
     402                if( source[i] == '\n' || source[i] == '\r' )
     403                        source[i] = ' ';
     404       
     405        return source;
     406}
     407
     408#ifdef IPV6
     409/* Wrap an IPv4 address into IPv6 space. Not thread-safe... */
     410char *ipv6_wrap( char *src )
     411{
     412        static char dst[64];
     413        int i;
     414       
     415        for( i = 0; src[i]; i ++ )
     416                if( ( src[i] < '0' || src[i] > '9' ) && src[i] != '.' )
     417                        break;
     418       
     419        /* Hmm, it's not even an IP... */
     420        if( src[i] )
     421                return src;
     422       
     423        g_snprintf( dst, sizeof( dst ), "::ffff:%s", src );
     424       
     425        return dst;
     426}
     427
     428/* Unwrap an IPv4 address into IPv6 space. Thread-safe, because it's very simple. :-) */
     429char *ipv6_unwrap( char *src )
     430{
     431        int i;
     432       
     433        if( g_strncasecmp( src, "::ffff:", 7 ) != 0 )
     434                return src;
     435       
     436        for( i = 7; src[i]; i ++ )
     437                if( ( src[i] < '0' || src[i] > '9' ) && src[i] != '.' )
     438                        break;
     439       
     440        /* Hmm, it's not even an IP... */
     441        if( src[i] )
     442                return src;
     443       
     444        return ( src + 7 );
     445}
     446#endif
Note: See TracChangeset for help on using the changeset viewer.