Changeset 2face62


Ignore:
Timestamp:
2006-01-19T16:34:41Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
bd9b00f
Parents:
4c266f2 (diff), 4c266f2 (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:

A bit too much for one commit, but well: Client processes didn't clean up
some master structs (bitlbee_child list) yet, and added the IPC CLIENT
command to inform the master process about host- and nickname. Can be useful
later.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.c

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

    r4c266f2 r2face62  
    3232
    3333
    34 static int ipc_master_cmd_die( irc_t *irc, char **cmd )
     34static 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
     48static int ipc_master_cmd_die( irc_t *data, char **cmd )
    3549{
    3650        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     
    4256}
    4357
    44 static int ipc_master_cmd_rehash( irc_t *irc, char **cmd )
     58static int ipc_master_cmd_rehash( irc_t *data, char **cmd )
    4559{
    4660        runmode_t oldmode;
     
    6478
    6579static const command_t ipc_master_commands[] = {
     80        { "client",     3, ipc_master_cmd_client,     0 },
    6681        { "die",        0, ipc_master_cmd_die,        0 },
    6782        { "wallops",    1, NULL,                      IPC_CMD_TO_CHILDREN },
    6883        { "lilo",       1, NULL,                      IPC_CMD_TO_CHILDREN },
     84        { "opermsg",    1, NULL,                      IPC_CMD_TO_CHILDREN },
    6985        { "rehash",     0, ipc_master_cmd_rehash,     0 },
    7086        { "kill",       2, NULL,                      IPC_CMD_TO_CHILDREN },
     
    7591static int ipc_child_cmd_die( irc_t *irc, char **cmd )
    7692{
    77         bitlbee_shutdown( NULL );
     93        if( irc->status >= USTATUS_LOGGED_IN )
     94                irc_write( irc, "ERROR :Operator requested server shutdown, bye bye!" );
     95       
     96        irc_abort( irc );
    7897       
    7998        return 1;
     
    98117        if( strchr( irc->umode, 's' ) )
    99118                irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] );
     119       
     120        return 1;
     121}
     122
     123static 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] );
    100130       
    101131        return 1;
     
    135165        { "wallops",    1, ipc_child_cmd_wallops,     0 },
    136166        { "lilo",       1, ipc_child_cmd_lilo,        0 },
     167        { "opermsg",    1, ipc_child_cmd_opermsg,     0 },
    137168        { "rehash",     0, ipc_child_cmd_rehash,      0 },
    138169        { "kill",       2, ipc_child_cmd_kill,        0 },
     
    217248                        if( c->ipc_fd == source )
    218249                        {
    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                                
     250                                ipc_master_free_one( c );
     251                                child_list = g_slist_remove( child_list, c );
    225252                                break;
    226253                        }
     
    253280        {
    254281                char *s = irc_build_line( cmd );
    255                 ipc_to_master_str( s );
     282                ipc_to_master_str( "%s", s );
    256283                g_free( s );
    257284        }
     
    262289}
    263290
    264 void ipc_to_master_str( char *msg_buf )
     291void 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 )
     305        {
     306                write( global.listen_socket, msg_buf, strlen( msg_buf ) );
     307        }
     308        else if( global.conf->runmode == RUNMODE_DAEMON )
     309        {
     310                char **cmd;
     311               
     312                cmd = irc_parse_line( msg_buf );
     313                ipc_command_exec( NULL, cmd, ipc_master_commands );
     314                g_free( cmd );
     315        }
     316       
     317        g_free( msg_buf );
     318}
     319
     320void ipc_to_children( char **cmd )
    265321{
    266322        if( global.conf->runmode == RUNMODE_FORKDAEMON )
    267323        {
    268                 write( global.listen_socket, msg_buf, strlen( msg_buf ) );
    269         }
    270         else if( global.conf->runmode == RUNMODE_DAEMON )
    271         {
    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                
    278                 ipc_command_exec( NULL, cmd, ipc_master_commands );
    279                
    280                 g_free( cmd );
    281                 g_free( s );
    282         }
    283 }
    284 
    285 void ipc_to_children( char **cmd )
    286 {
    287         if( global.conf->runmode == RUNMODE_FORKDAEMON )
    288         {
    289324                char *msg_buf = irc_build_line( cmd );
    290                 ipc_to_children_str( msg_buf );
     325                ipc_to_children_str( "%s", msg_buf );
    291326                g_free( msg_buf );
    292327        }
     
    300335}
    301336
    302 void ipc_to_children_str( char *msg_buf )
    303 {
    304         if( global.conf->runmode == RUNMODE_FORKDAEMON )
     337void 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 )
    305351        {
    306352                int msg_len = strlen( msg_buf );
     
    315361        else if( global.conf->runmode == RUNMODE_DAEMON )
    316362        {
    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                
     363                char **cmd;
     364               
     365                cmd = irc_parse_line( msg_buf );
    323366                ipc_to_children( cmd );
    324                
    325367                g_free( cmd );
    326                 g_free( s );
    327         }
    328 }
     368        }
     369       
     370        g_free( msg_buf );
     371}
     372
     373void 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
     384void 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}
  • ipc.h

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

    r4c266f2 r2face62  
    2727#include "bitlbee.h"
    2828#include "crypting.h"
     29#include "ipc.h"
    2930
    3031static gboolean irc_userping( gpointer _irc );
     
    689690        u->realname = g_strdup( irc->realname );
    690691        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 );
    695698       
    696699        irc->status = USTATUS_LOGGED_IN;
Note: See TracChangeset for help on using the changeset viewer.