aboutsummaryrefslogtreecommitdiffstats
path: root/irc.c
diff options
context:
space:
mode:
Diffstat (limited to 'irc.c')
-rw-r--r--irc.c88
1 files changed, 47 insertions, 41 deletions
diff --git a/irc.c b/irc.c
index 3cdd03cb..97365f4d 100644
--- a/irc.c
+++ b/irc.c
@@ -28,7 +28,7 @@
#include "crypting.h"
#include "ipc.h"
-static gboolean irc_userping( gpointer _irc );
+static gboolean irc_userping( gpointer _irc, int fd, b_input_condition cond );
GSList *irc_connection_list = NULL;
@@ -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 = b_input_add( irc->fd, GAIM_INPUT_READ, bitlbee_io_current_client_read, irc );
irc->status = USTATUS_OFFLINE;
irc->last_pong = gettime();
@@ -119,7 +113,7 @@ irc_t *irc_new( int fd )
if( !irc->myhost ) irc->myhost = g_strdup( "localhost." );
if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
- irc->ping_source_id = g_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
+ irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
irc_write( irc, ":%s NOTICE AUTH :%s", irc->myhost, "BitlBee-IRCd initialized, please go on" );
@@ -189,8 +183,8 @@ void irc_abort( irc_t *irc, int immed, char *format, ... )
to it that should shut down the connection in a second, just in case
bitlbee_.._write doesn't do it first. */
- g_source_remove( irc->r_watch_source_id );
- irc->r_watch_source_id = g_timeout_add_full( G_PRIORITY_HIGH, 1000, (GSourceFunc) irc_free, irc, NULL );
+ b_event_remove( irc->r_watch_source_id );
+ irc->r_watch_source_id = b_timeout_add( 1000, (b_event_handler) irc_free, irc );
}
else
{
@@ -223,12 +217,11 @@ void irc_free(irc_t * irc)
closesocket( irc->fd );
if( irc->ping_source_id > 0 )
- g_source_remove( irc->ping_source_id );
- g_source_remove( irc->r_watch_source_id );
+ b_event_remove( irc->ping_source_id );
+ b_event_remove( irc->r_watch_source_id );
if( irc->w_watch_source_id > 0 )
- g_source_remove( irc->w_watch_source_id );
+ b_event_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) {
@@ -278,7 +271,7 @@ void irc_free(irc_t * irc)
if(user->user!=user->nick) g_free(user->user);
if(user->host!=user->nick) g_free(user->host);
if(user->realname!=user->nick) g_free(user->realname);
- gaim_input_remove(user->sendbuf_timer);
+ b_event_remove(user->sendbuf_timer);
usertmp = user;
user = user->next;
@@ -328,7 +321,7 @@ void irc_free(irc_t * irc)
g_free(irc);
if( global.conf->runmode == RUNMODE_INETD || global.conf->runmode == RUNMODE_FORKDAEMON )
- g_main_quit( global.loop );
+ b_main_quit();
}
/* USE WITH CAUTION!
@@ -582,7 +575,8 @@ void irc_vawrite( irc_t *irc, char *format, va_list params )
int size;
char line[IRC_MAX_LINE+1], *cs;
- if( irc->quit )
+ /* Don't try to write anything new anymore when shutting down. */
+ if( irc->status == USTATUS_SHUTDOWN )
return;
line[IRC_MAX_LINE] = 0;
@@ -599,17 +593,25 @@ 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);
+ else
+ {
+ irc->sendbuffer = g_strdup(line);
+ }
if( irc->w_watch_source_id == 0 )
{
- irc->w_watch_source_id = g_io_add_watch( irc->io_channel, G_IO_OUT, bitlbee_io_current_client_write, irc );
+ /* If the buffer is empty we can probably write, so call the write event handler
+ immediately. If it returns TRUE, it should be called again, so add the event to
+ the queue. If it's FALSE, we emptied the buffer and saved ourselves some work
+ in the event queue. */
+ if( bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE ) )
+ irc->w_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc );
}
return;
@@ -635,7 +637,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;
}
@@ -829,7 +831,7 @@ void irc_topic( irc_t *irc, char *channel )
if( c )
irc_reply( irc, 332, "%s :BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", channel, c->title );
else
- irc_reply( irc, 331, "%s :No topic for this channel" );
+ irc_reply( irc, 331, "%s :No topic for this channel", channel );
}
}
@@ -885,7 +887,7 @@ void irc_join( irc_t *irc, user_t *u, char *channel )
nick_lc( nick );
if( g_hash_table_lookup( irc->watches, nick ) )
{
- irc_reply( irc, 600, "%s %s %s %d :%s", u->nick, u->user, u->host, time( NULL ), "logged online" );
+ irc_reply( irc, 600, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "logged online" );
}
g_free( nick );
}
@@ -910,7 +912,7 @@ void irc_kill( irc_t *irc, user_t *u )
nick_lc( nick );
if( g_hash_table_lookup( irc->watches, nick ) )
{
- irc_reply( irc, 601, "%s %s %s %d :%s", u->nick, u->user, u->host, time( NULL ), "logged offline" );
+ irc_reply( irc, 601, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "logged offline" );
}
g_free( nick );
}
@@ -1010,18 +1012,22 @@ int irc_send( irc_t *irc, char *nick, char *s, int flags )
}
else if( c && c->gc && c->gc->prpl )
{
- return( serv_send_chat( irc, c->gc, c->id, s ) );
+ return( bim_chat_msg( c->gc, c->id, s ) );
}
return( 0 );
}
-gboolean buddy_send_handler_delayed( gpointer data )
+static gboolean buddy_send_handler_delayed( gpointer data, gint fd, b_input_condition cond )
{
user_t *u = data;
+ /* Shouldn't happen, but just to be sure. */
+ if( u->sendbuf_len < 2 )
+ return FALSE;
+
u->sendbuf[u->sendbuf_len-2] = 0; /* Cut off the last newline */
- serv_send_im( u->gc->irc, u, u->sendbuf, u->sendbuf_flags );
+ bim_buddy_msg( u->gc, u->handle, u->sendbuf, u->sendbuf_flags );
g_free( u->sendbuf );
u->sendbuf = NULL;
@@ -1029,7 +1035,7 @@ gboolean buddy_send_handler_delayed( gpointer data )
u->sendbuf_timer = 0;
u->sendbuf_flags = 0;
- return( FALSE );
+ return FALSE;
}
void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
@@ -1042,22 +1048,22 @@ void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
if( u->sendbuf_len > 0 && u->sendbuf_flags != flags)
{
- //Flush the buffer
- g_source_remove( u->sendbuf_timer );
- buddy_send_handler_delayed( u );
+ /* Flush the buffer */
+ b_event_remove( u->sendbuf_timer );
+ buddy_send_handler_delayed( u, -1, 0 );
}
if( u->sendbuf_len == 0 )
{
u->sendbuf_len = strlen( msg ) + 2;
- u->sendbuf = g_new (char, u->sendbuf_len );
+ u->sendbuf = g_new( char, u->sendbuf_len );
u->sendbuf[0] = 0;
u->sendbuf_flags = flags;
}
else
{
u->sendbuf_len += strlen( msg ) + 1;
- u->sendbuf = g_renew ( char, u->sendbuf, u->sendbuf_len );
+ u->sendbuf = g_renew( char, u->sendbuf, u->sendbuf_len );
}
strcat( u->sendbuf, msg );
@@ -1068,12 +1074,12 @@ void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
delay *= 1000;
if( u->sendbuf_timer > 0 )
- g_source_remove( u->sendbuf_timer );
- u->sendbuf_timer = g_timeout_add( delay, buddy_send_handler_delayed, u );
+ b_event_remove( u->sendbuf_timer );
+ u->sendbuf_timer = b_timeout_add( delay, buddy_send_handler_delayed, u );
}
else
{
- serv_send_im( irc, u, msg, flags );
+ bim_buddy_msg( u->gc, u->handle, msg, flags );
}
}
@@ -1153,7 +1159,7 @@ int irc_noticefrom( irc_t *irc, char *nick, char *msg )
timeout. The number returned is the number of seconds we received no
pongs from the user. When not connected yet, we don't ping but drop the
connection when the user fails to connect in IRC_LOGIN_TIMEOUT secs. */
-static gboolean irc_userping( gpointer _irc )
+static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
{
irc_t *irc = _irc;
int rv = 0;