diff options
-rw-r--r-- | bitlbee.c | 55 | ||||
-rw-r--r-- | bitlbee.h | 5 | ||||
-rw-r--r-- | ipc.c | 29 | ||||
-rw-r--r-- | irc.c | 28 | ||||
-rw-r--r-- | irc.h | 1 |
5 files changed, 49 insertions, 69 deletions
@@ -33,7 +33,7 @@ #include <stdio.h> #include <errno.h> -gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data ); +void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ); int bitlbee_daemon_init() { @@ -43,7 +43,6 @@ int bitlbee_daemon_init() struct sockaddr_in listen_addr; #endif int i; - GIOChannel *ch; FILE *fp; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); @@ -90,8 +89,7 @@ int bitlbee_daemon_init() return( -1 ); } - ch = g_io_channel_unix_new( global.listen_socket ); - global.listen_watch_source_id = g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL ); + global.listen_watch_source_id = gaim_input_add( global.listen_socket, GAIM_INPUT_READ, bitlbee_io_new_client, NULL ); #ifndef _WIN32 if( !global.conf->nofork ) @@ -146,34 +144,28 @@ int bitlbee_inetd_init() return( 0 ); } -gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data ) +void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition cond ) { irc_t *irc = data; char line[513]; int st; - if( condition & G_IO_ERR || condition & G_IO_HUP ) - { - irc_abort( irc, 1, "Read error" ); - return FALSE; - } - st = read( irc->fd, line, sizeof( line ) - 1 ); if( st == 0 ) { irc_abort( irc, 1, "Connection reset by peer" ); - return FALSE; + goto no_more_events; } else if( st < 0 ) { if( sockerr_again() ) { - return TRUE; + return; } else { irc_abort( irc, 1, "Read error: %s", strerror( errno ) ); - return FALSE; + goto no_more_events; } } @@ -194,27 +186,31 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit if( !g_slist_find( irc_connection_list, irc ) ) { log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd ); - return FALSE; + goto no_more_events; } /* Very naughty, go read the RFCs! >:) */ if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) ) { irc_abort( irc, 0, "Maximum line length exceeded" ); - return FALSE; + goto no_more_events; } - return TRUE; + return; + +no_more_events: + gaim_input_remove( irc->r_watch_source_id ); + irc->r_watch_source_id = 0; } -gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data ) +void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond ) { irc_t *irc = data; int st, size; char *temp; if( irc->sendbuffer == NULL ) - return( FALSE ); + goto no_more_events; size = strlen( irc->sendbuffer ); st = write( irc->fd, irc->sendbuffer, size ); @@ -222,23 +218,22 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi if( st == 0 || ( st < 0 && !sockerr_again() ) ) { irc_abort( irc, 1, "Write error: %s", strerror( errno ) ); - return FALSE; + goto no_more_events; } else if( st < 0 ) /* && sockerr_again() */ { - return TRUE; + return; } if( st == size ) { g_free( irc->sendbuffer ); irc->sendbuffer = NULL; - irc->w_watch_source_id = 0; if( irc->status == USTATUS_SHUTDOWN ) irc_free( irc ); - return( FALSE ); + goto no_more_events; } else { @@ -246,13 +241,17 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi g_free( irc->sendbuffer ); irc->sendbuffer = temp; - return( TRUE ); + return; } + +no_more_events: + gaim_input_remove( irc->w_watch_source_id ); + irc->w_watch_source_id = 0; } -gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data ) +void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ) { - size_t size = sizeof( struct sockaddr_in ); + socklen_t size = sizeof( struct sockaddr_in ); struct sockaddr_in conn_info; int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size ); pid_t client_pid = 0; @@ -260,7 +259,7 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi if( new_socket == -1 ) { log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) ); - return TRUE; + return; } if( global.conf->runmode == RUNMODE_FORKDAEMON ) @@ -319,8 +318,6 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket ); irc_new( new_socket ); } - - return TRUE; } void bitlbee_shutdown( gpointer data ) @@ -111,6 +111,7 @@ extern char *CONF_FILE; #include "query.h" #include "sock.h" #include "util.h" +#include "proxy.h" typedef struct global { /* In forked mode, child processes store the fd of the IPC socket here. */ @@ -127,8 +128,8 @@ typedef struct global { int bitlbee_daemon_init( void ); int bitlbee_inetd_init( void ); -gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data ); -gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data ); +void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition cond ); +void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond ); void root_command_string( irc_t *irc, user_t *u, char *command, int flags ); void root_command( irc_t *irc, char *command[] ); @@ -462,25 +462,21 @@ void ipc_master_set_statefile( char *fn ) } -static gboolean new_ipc_client (GIOChannel *gio, GIOCondition cond, gpointer data) +static void new_ipc_client( gpointer data, gint serversock, GaimInputCondition cond ) { struct bitlbee_child *child = g_new0( struct bitlbee_child, 1 ); - int serversock; - - serversock = g_io_channel_unix_get_fd(gio); - - child->ipc_fd = accept(serversock, NULL, 0); - - if (child->ipc_fd == -1) { + + child->ipc_fd = accept( serversock, NULL, 0 ); + + if( child->ipc_fd == -1 ) + { log_message( LOGLVL_WARNING, "Unable to accept connection on UNIX domain socket: %s", strerror(errno) ); - return TRUE; + return; } child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); - + child_list = g_slist_append( child_list, child ); - - return TRUE; } #ifndef _WIN32 @@ -488,7 +484,6 @@ int ipc_master_listen_socket() { struct sockaddr_un un_addr; int serversock; - GIOChannel *gio; /* Clean up old socket files that were hanging around.. */ if (unlink(IPCSOCKET) == -1 && errno != ENOENT) { @@ -516,14 +511,8 @@ int ipc_master_listen_socket() return 0; } - gio = g_io_channel_unix_new(serversock); + gaim_input_add( serversock, GAIM_INPUT_READ, new_ipc_client, NULL ); - if (gio == NULL) { - log_message( LOGLVL_WARNING, "Unable to create IO channel for unix socket" ); - return 0; - } - - g_io_add_watch(gio, G_IO_IN, new_ipc_client, NULL); return 1; } #else @@ -53,15 +53,9 @@ irc_t *irc_new( int fd ) irc = g_new0( irc_t, 1 ); irc->fd = fd; - irc->io_channel = g_io_channel_unix_new( fd ); -#ifdef GLIB2 - g_io_channel_set_encoding (irc->io_channel, NULL, NULL); - g_io_channel_set_buffered (irc->io_channel, FALSE); - g_io_channel_set_flags( irc->io_channel, G_IO_FLAG_NONBLOCK, NULL ); -#else - fcntl( irc->fd, F_SETFL, O_NONBLOCK); -#endif - irc->r_watch_source_id = g_io_add_watch( irc->io_channel, G_IO_IN | G_IO_ERR | G_IO_HUP, bitlbee_io_current_client_read, irc ); + sock_make_nonblocking( irc->fd ); + + irc->r_watch_source_id = gaim_input_add( irc->fd, GAIM_INPUT_READ, bitlbee_io_current_client_read, irc ); irc->status = USTATUS_OFFLINE; irc->last_pong = gettime(); @@ -228,7 +222,6 @@ void irc_free(irc_t * irc) if( irc->w_watch_source_id > 0 ) g_source_remove( irc->w_watch_source_id ); - g_io_channel_unref( irc->io_channel ); irc_connection_list = g_slist_remove( irc_connection_list, irc ); for (account = irc->accounts; account; account = account->next) { @@ -599,19 +592,20 @@ void irc_vawrite( irc_t *irc, char *format, va_list params ) } strcat( line, "\r\n" ); - if( irc->sendbuffer != NULL ) { + if( irc->sendbuffer != NULL ) + { size = strlen( irc->sendbuffer ) + strlen( line ); irc->sendbuffer = g_renew ( char, irc->sendbuffer, size + 1 ); strcpy( ( irc->sendbuffer + strlen( irc->sendbuffer ) ), line ); } - else - irc->sendbuffer = g_strdup(line); - - if( irc->w_watch_source_id == 0 ) + else { - irc->w_watch_source_id = g_io_add_watch( irc->io_channel, G_IO_OUT, bitlbee_io_current_client_write, irc ); + irc->sendbuffer = g_strdup(line); } + if( irc->w_watch_source_id == 0 ) + irc->w_watch_source_id = gaim_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc ); + return; } @@ -635,7 +629,7 @@ void irc_write_all( int now, char *format, ... ) irc_vawrite( temp->data, format, params ); if( now ) { - bitlbee_io_current_client_write( irc->io_channel, G_IO_OUT, irc ); + bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE ); } temp = temp->next; } @@ -92,7 +92,6 @@ typedef struct irc struct help *help; struct set *set; - GIOChannel *io_channel; gint r_watch_source_id; gint w_watch_source_id; gint ping_source_id; |