Changes in / [2face62:4c266f2]


Ignore:
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.c

    r2face62 r4c266f2  
    282282                       
    283283                        close( fds[0] );
    284                        
    285                         ipc_master_free_all();
    286284                }
    287285        }
  • ipc.c

    r2face62 r4c266f2  
    3232
    3333
    34 static int ipc_master_cmd_client( irc_t *data, char **cmd )
    35 {
    36         struct bitlbee_child *child = (void*) data;
    37        
    38         child->host = g_strdup( cmd[1] );
    39         child->nick = g_strdup( cmd[2] );
    40         child->realname = g_strdup( cmd[3] );
    41        
    42         ipc_to_children_str( "OPERMSG :Client connecting (PID=%d): %s@%s (%s)\r\n",
    43                              child->pid, child->nick, child->host, child->realname );
    44        
    45         return 1;
    46 }
    47 
    48 static int ipc_master_cmd_die( irc_t *data, char **cmd )
     34static int ipc_master_cmd_die( irc_t *irc, char **cmd )
    4935{
    5036        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     
    5642}
    5743
    58 static int ipc_master_cmd_rehash( irc_t *data, char **cmd )
     44static int ipc_master_cmd_rehash( irc_t *irc, char **cmd )
    5945{
    6046        runmode_t oldmode;
     
    7864
    7965static const command_t ipc_master_commands[] = {
    80         { "client",     3, ipc_master_cmd_client,     0 },
    8166        { "die",        0, ipc_master_cmd_die,        0 },
    8267        { "wallops",    1, NULL,                      IPC_CMD_TO_CHILDREN },
    8368        { "lilo",       1, NULL,                      IPC_CMD_TO_CHILDREN },
    84         { "opermsg",    1, NULL,                      IPC_CMD_TO_CHILDREN },
    8569        { "rehash",     0, ipc_master_cmd_rehash,     0 },
    8670        { "kill",       2, NULL,                      IPC_CMD_TO_CHILDREN },
     
    9175static int ipc_child_cmd_die( irc_t *irc, char **cmd )
    9276{
    93         if( irc->status >= USTATUS_LOGGED_IN )
    94                 irc_write( irc, "ERROR :Operator requested server shutdown, bye bye!" );
    95        
    96         irc_abort( irc );
     77        bitlbee_shutdown( NULL );
    9778       
    9879        return 1;
     
    11798        if( strchr( irc->umode, 's' ) )
    11899                irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] );
    119        
    120         return 1;
    121 }
    122 
    123 static int ipc_child_cmd_opermsg( irc_t *irc, char **cmd )
    124 {
    125         if( irc->status < USTATUS_LOGGED_IN )
    126                 return 1;
    127        
    128         if( strchr( irc->umode, 'o' ) )
    129                 irc_write( irc, ":%s NOTICE %s :*** OperMsg *** %s", irc->myhost, irc->nick, cmd[1] );
    130100       
    131101        return 1;
     
    165135        { "wallops",    1, ipc_child_cmd_wallops,     0 },
    166136        { "lilo",       1, ipc_child_cmd_lilo,        0 },
    167         { "opermsg",    1, ipc_child_cmd_opermsg,     0 },
    168137        { "rehash",     0, ipc_child_cmd_rehash,      0 },
    169138        { "kill",       2, ipc_child_cmd_kill,        0 },
     
    248217                        if( c->ipc_fd == source )
    249218                        {
    250                                 ipc_master_free_one( c );
    251                                 child_list = g_slist_remove( child_list, c );
     219                                close( c->ipc_fd );
     220                                gaim_input_remove( c->ipc_inpa );
     221                                g_free( c );
     222                               
     223                                child_list = g_slist_remove( child_list, l );
     224                               
    252225                                break;
    253226                        }
     
    280253        {
    281254                char *s = irc_build_line( cmd );
    282                 ipc_to_master_str( "%s", s );
     255                ipc_to_master_str( s );
    283256                g_free( s );
    284257        }
     
    289262}
    290263
    291 void ipc_to_master_str( char *format, ... )
    292 {
    293         char *msg_buf;
    294         va_list params;
    295 
    296         va_start( params, format );
    297         msg_buf = g_strdup_vprintf( format, params );
    298         va_end( params );
    299        
    300         if( strlen( msg_buf ) > 512 )
    301         {
    302                 /* Don't send it, it's too long... */
    303         }
    304         else if( global.conf->runmode == RUNMODE_FORKDAEMON )
     264void ipc_to_master_str( char *msg_buf )
     265{
     266        if( global.conf->runmode == RUNMODE_FORKDAEMON )
    305267        {
    306268                write( global.listen_socket, msg_buf, strlen( msg_buf ) );
     
    308270        else if( global.conf->runmode == RUNMODE_DAEMON )
    309271        {
    310                 char **cmd;
    311                
    312                 cmd = irc_parse_line( msg_buf );
     272                char *s, **cmd;
     273               
     274                /* irc_parse_line() wants a read-write string, so get it one: */
     275                s = g_strdup( msg_buf );
     276                cmd = irc_parse_line( s );
     277               
    313278                ipc_command_exec( NULL, cmd, ipc_master_commands );
     279               
    314280                g_free( cmd );
    315         }
    316        
    317         g_free( msg_buf );
     281                g_free( s );
     282        }
    318283}
    319284
     
    323288        {
    324289                char *msg_buf = irc_build_line( cmd );
    325                 ipc_to_children_str( "%s", msg_buf );
     290                ipc_to_children_str( msg_buf );
    326291                g_free( msg_buf );
    327292        }
     
    335300}
    336301
    337 void ipc_to_children_str( char *format, ... )
    338 {
    339         char *msg_buf;
    340         va_list params;
    341 
    342         va_start( params, format );
    343         msg_buf = g_strdup_vprintf( format, params );
    344         va_end( params );
    345        
    346         if( strlen( msg_buf ) > 512 )
    347         {
    348                 /* Don't send it, it's too long... */
    349         }
    350         else if( global.conf->runmode == RUNMODE_FORKDAEMON )
     302void ipc_to_children_str( char *msg_buf )
     303{
     304        if( global.conf->runmode == RUNMODE_FORKDAEMON )
    351305        {
    352306                int msg_len = strlen( msg_buf );
     
    361315        else if( global.conf->runmode == RUNMODE_DAEMON )
    362316        {
    363                 char **cmd;
    364                
    365                 cmd = irc_parse_line( msg_buf );
     317                char *s, **cmd;
     318               
     319                /* irc_parse_line() wants a read-write string, so get it one: */
     320                s = g_strdup( msg_buf );
     321                cmd = irc_parse_line( s );
     322               
    366323                ipc_to_children( cmd );
     324               
    367325                g_free( cmd );
    368         }
    369        
    370         g_free( msg_buf );
    371 }
    372 
    373 void ipc_master_free_one( struct bitlbee_child *c )
    374 {
    375         gaim_input_remove( c->ipc_inpa );
    376         closesocket( c->ipc_fd );
    377        
    378         g_free( c->host );
    379         g_free( c->nick );
    380         g_free( c->realname );
    381         g_free( c );
    382 }
    383 
    384 void ipc_master_free_all()
    385 {
    386         GSList *l;
    387        
    388         for( l = child_list; l; l = l->next )
    389                 ipc_master_free_one( l->data );
    390        
    391         g_slist_free( child_list );
    392         child_list = NULL;
    393 }
     326                g_free( s );
     327        }
     328}
  • ipc.h

    r2face62 r4c266f2  
    2727#include "bitlbee.h"
    2828
     29void ipc_master_read( gpointer data, gint source, GaimInputCondition cond );
     30void ipc_child_read( gpointer data, gint source, GaimInputCondition cond );
     31
     32void ipc_to_master( char **cmd );
     33void ipc_to_master_str( char *msg_buf );
     34void ipc_to_children( char **cmd );
     35void ipc_to_children_str( char *msg_buf );
     36
    2937struct bitlbee_child
    3038{
     
    3240        int ipc_fd;
    3341        gint ipc_inpa;
    34        
    35         char *host;
    36         char *nick;
    37         char *realname;
    3842};
    3943
    40 void ipc_master_read( gpointer data, gint source, GaimInputCondition cond );
    41 void ipc_child_read( gpointer data, gint source, GaimInputCondition cond );
    42 
    43 void ipc_master_free_one( struct bitlbee_child *child );
    44 void ipc_master_free_all();
    45 
    46 void ipc_to_master( char **cmd );
    47 void ipc_to_master_str( char *format, ... );
    48 void ipc_to_children( char **cmd );
    49 void ipc_to_children_str( char *format, ... );
    50 
    5144extern GSList *child_list;
  • irc.c

    r2face62 r4c266f2  
    2727#include "bitlbee.h"
    2828#include "crypting.h"
    29 #include "ipc.h"
    3029
    3130static gboolean irc_userping( gpointer _irc );
     
    690689        u->realname = g_strdup( irc->realname );
    691690        u->online = 1;
     691//      u->send_handler = msg_echo;
    692692        irc_spawn( irc, u );
    693693       
    694694        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." );
    695        
    696         if( global.conf->runmode == RUNMODE_FORKDAEMON )
    697                 ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
    698695       
    699696        irc->status = USTATUS_LOGGED_IN;
Note: See TracChangeset for help on using the changeset viewer.