From d783e48a831cf5058e2307a382e7e95a06680289 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 31 Mar 2006 10:53:53 +0200 Subject: irc_vawrite() does charset conversion now. Next step: Do it for incoming IRC traffic, and get rid of most other iconv() calls. --- irc.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index 096f9d99..b6185d85 100644 --- a/irc.c +++ b/irc.c @@ -562,16 +562,25 @@ void irc_write( irc_t *irc, char *format, ... ) void irc_vawrite( irc_t *irc, char *format, va_list params ) { int size; - char line[IRC_MAX_LINE]; - + char line[IRC_MAX_LINE+1], *cs; + if( irc->quit ) return; - - g_vsnprintf( line, IRC_MAX_LINE - 3, format, params ); - + + line[IRC_MAX_LINE] = 0; + g_vsnprintf( line, IRC_MAX_LINE - 2, format, params ); + strip_newlines( line ); + if( ( cs = set_getstr( irc, "charset" ) ) ) + { + char conv[IRC_MAX_LINE+1]; + + conv[IRC_MAX_LINE] = 0; + if( do_iconv( "UTF-8", cs, line, conv, 0, IRC_MAX_LINE - 2 ) != -1 ) + strcpy( line, conv ); + } strcat( line, "\r\n" ); - + if( irc->sendbuffer != NULL ) { size = strlen( irc->sendbuffer ) + strlen( line ); irc->sendbuffer = g_renew ( char, irc->sendbuffer, size + 1 ); -- cgit v1.2.3 From e27661d09e8c3fc85c979d4769ba20d1d3c289e2 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 31 Mar 2006 19:55:47 +0200 Subject: Finished the iconv() fix. Instead of doing it every time something goes from or to the IM-modules, it's now just done with everything that goes between BitlBee and the user. Incomparably more efficient/reliable. Plus some more cleanups. It compiles, can't test it for real yet. ;-) --- irc.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index b6185d85..0d308912 100644 --- a/irc.c +++ b/irc.c @@ -345,7 +345,7 @@ void irc_setpass (irc_t *irc, const char *pass) void irc_process( irc_t *irc ) { - char **lines, *temp, **cmd; + char **lines, *temp, **cmd, *cs; int i; if( irc->readbuffer != NULL ) @@ -354,6 +354,9 @@ void irc_process( irc_t *irc ) for( i = 0; *lines[i] != '\0'; i ++ ) { + /* [WvG] Because irc_tokenize splits at every newline, the lines[] list + should end with an empty string. This is why this actually works. + Took me a while to figure out, Maurits. :-P */ if( lines[i+1] == NULL ) { temp = g_strdup( lines[i] ); @@ -361,7 +364,16 @@ void irc_process( irc_t *irc ) irc->readbuffer = temp; i ++; break; - } + } + + if( ( cs = set_getstr( irc, "charset" ) ) ) + { + char conv[IRC_MAX_LINE+1]; + + conv[IRC_MAX_LINE] = 0; + if( do_iconv( cs, "UTF-8", lines[i], conv, 0, IRC_MAX_LINE - 2 ) != -1 ) + strcpy( lines[i], conv ); + } if( ( cmd = irc_parse_line( lines[i] ) ) == NULL ) continue; @@ -387,6 +399,8 @@ void irc_process( irc_t *irc ) } } +/* Splits a long string into separate lines. The array is NULL-terminated and, unless the string + contains an incomplete line at the end, ends with an empty string. */ char **irc_tokenize( char *buffer ) { int i, j; @@ -427,6 +441,7 @@ char **irc_tokenize( char *buffer ) return( lines ); } +/* Split an IRC-style line into little parts/arguments. */ char **irc_parse_line( char *line ) { int i, j; @@ -486,6 +501,7 @@ char **irc_parse_line( char *line ) return cmd; } +/* Converts such an array back into a command string. Mainly used for the IPC code right now. */ char *irc_build_line( char **cmd ) { int i, len; -- cgit v1.2.3 From 7d31002c391868a24693eadaf1c9c6024e1a30cb Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 31 Mar 2006 23:09:36 +0200 Subject: Tested and fixed one issue, and got rid of one more superfluous iconv call. --- irc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index 0d308912..f6a1f505 100644 --- a/irc.c +++ b/irc.c @@ -354,6 +354,8 @@ void irc_process( irc_t *irc ) for( i = 0; *lines[i] != '\0'; i ++ ) { + char conv[IRC_MAX_LINE+1]; + /* [WvG] Because irc_tokenize splits at every newline, the lines[] list should end with an empty string. This is why this actually works. Took me a while to figure out, Maurits. :-P */ @@ -366,13 +368,11 @@ void irc_process( irc_t *irc ) break; } - if( ( cs = set_getstr( irc, "charset" ) ) ) + if( ( cs = set_getstr( irc, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) ) { - char conv[IRC_MAX_LINE+1]; - conv[IRC_MAX_LINE] = 0; if( do_iconv( cs, "UTF-8", lines[i], conv, 0, IRC_MAX_LINE - 2 ) != -1 ) - strcpy( lines[i], conv ); + lines[i] = conv; } if( ( cmd = irc_parse_line( lines[i] ) ) == NULL ) @@ -587,7 +587,7 @@ void irc_vawrite( irc_t *irc, char *format, va_list params ) g_vsnprintf( line, IRC_MAX_LINE - 2, format, params ); strip_newlines( line ); - if( ( cs = set_getstr( irc, "charset" ) ) ) + if( ( cs = set_getstr( irc, "charset" ) ) && ( g_strcasecmp( cs, "utf-8" ) != 0 ) ) { char conv[IRC_MAX_LINE+1]; -- cgit v1.2.3 From 6adcb6c6bcd96478ec3ab89efcc43bf15d6b12e0 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 1 Apr 2006 20:18:55 +0200 Subject: Complete fix for #113: a->reconnect does *not* contain a GLib source ID, oops... --- irc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index f6a1f505..a8d317d0 100644 --- a/irc.c +++ b/irc.c @@ -235,7 +235,7 @@ void irc_free(irc_t * irc) if (account->gc) account_offline(account->gc); else if (account->reconnect) - g_source_remove(account->reconnect); + cancel_auto_reconnect(account); } g_free(irc->sendbuffer); -- cgit v1.2.3 From 36fa9bd3e3b918b282421b38735b4d1c024d799a Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 7 Apr 2006 11:22:21 +0200 Subject: Renamed irc_free_userhash(). --- irc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index a8d317d0..60188c3b 100644 --- a/irc.c +++ b/irc.c @@ -198,7 +198,7 @@ void irc_abort( irc_t *irc, int immed, char *format, ... ) } } -static gboolean irc_free_userhash( gpointer key, gpointer value, gpointer data ) +static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data ) { g_free( key ); @@ -284,10 +284,10 @@ void irc_free(irc_t * irc) } } - g_hash_table_foreach_remove(irc->userhash, irc_free_userhash, NULL); + g_hash_table_foreach_remove(irc->userhash, irc_free_hashkey, NULL); g_hash_table_destroy(irc->userhash); - g_hash_table_foreach_remove(irc->watches, irc_free_userhash, NULL); + g_hash_table_foreach_remove(irc->watches, irc_free_hashkey, NULL); g_hash_table_destroy(irc->watches); if (irc->nicks != NULL) { -- cgit v1.2.3 From c99af3a10749850864e230b660060f6a0719925a Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 13 Apr 2006 09:30:11 +0200 Subject: Removed account_offline(), we have signoff() already. --- irc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index 60188c3b..44fc9ad3 100644 --- a/irc.c +++ b/irc.c @@ -232,10 +232,12 @@ void irc_free(irc_t * irc) irc_connection_list = g_slist_remove( irc_connection_list, irc ); for (account = irc->accounts; account; account = account->next) { - if (account->gc) - account_offline(account->gc); - else if (account->reconnect) + if (account->gc) { + account->gc->wants_to_die = TRUE; + signoff(account->gc); + } else if (account->reconnect) { cancel_auto_reconnect(account); + } } g_free(irc->sendbuffer); -- cgit v1.2.3 From dd89a55a9b54e29da43d6adea00fc2c42e3e7ebd Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 15 May 2006 19:57:12 +0200 Subject: Fixed various memory leaks/other possible problems after code review. --- irc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index 44fc9ad3..3cdd03cb 100644 --- a/irc.c +++ b/irc.c @@ -556,7 +556,7 @@ int irc_usermsg( irc_t *irc, char *format, ... ) user_t *u; u = user_find( irc, irc->mynick ); - if( u ) is_private = u->is_private; + is_private = u->is_private; va_start( params, format ); g_vsnprintf( text, sizeof( text ), format, params ); -- cgit v1.2.3 From 226fce105c1189bde1aa321b494494d49b463e90 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 23 May 2006 09:45:14 +0200 Subject: Some changes for im_api. (bim_* functions) --- irc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index 3cdd03cb..2d35bbb6 100644 --- a/irc.c +++ b/irc.c @@ -1010,7 +1010,7 @@ 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 ); @@ -1020,8 +1020,12 @@ gboolean buddy_send_handler_delayed( gpointer data ) { 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 +1033,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,7 +1046,7 @@ 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 + /* Flush the buffer */ g_source_remove( u->sendbuf_timer ); buddy_send_handler_delayed( u ); } @@ -1050,14 +1054,14 @@ void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags ) 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 ); @@ -1073,7 +1077,7 @@ void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags ) } else { - serv_send_im( irc, u, msg, flags ); + bim_buddy_msg( u->gc, u->handle, msg, flags ); } } -- cgit v1.2.3 From fc630f9fb47690c30feaf4738727a213d633afc9 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 23 May 2006 10:31:04 +0200 Subject: Silenced all compiler warnings that appeared after previous commit. --- irc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index 2d35bbb6..fb85de62 100644 --- a/irc.c +++ b/irc.c @@ -829,7 +829,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 +885,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 +910,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 ); } -- cgit v1.2.3 From 574af7e01a0cc738b4bbe7e903572943a85b9691 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 26 May 2006 01:20:54 +0200 Subject: Require GLib 2 --- irc.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index fb85de62..db9f7aad 100644 --- a/irc.c +++ b/irc.c @@ -54,13 +54,9 @@ irc_t *irc_new( int fd ) 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 ); irc->status = USTATUS_OFFLINE; -- cgit v1.2.3 From fb62f81f947c74e274b05e32d2e88e3a4d7e2613 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 3 Jun 2006 21:51:16 +0200 Subject: Implemented netsplits for "account off". --- irc.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index db9f7aad..3d3baca6 100644 --- a/irc.c +++ b/irc.c @@ -898,9 +898,31 @@ void irc_kick( irc_t *irc, user_t *u, char *channel, user_t *kicker ) void irc_kill( irc_t *irc, user_t *u ) { - char *nick; + char *nick, *s; + char reason[64]; + + if( u->gc && u->gc->flags & OPT_LOGGING_OUT ) + { + if( u->gc->user->proto_opt[0][0] ) + g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost, + u->gc->user->proto_opt[0] ); + else if( ( s = strchr( u->gc->username, '@' ) ) ) + g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost, + s + 1 ); + else + g_snprintf( reason, sizeof( reason ), "%s %s.%s", irc->myhost, + u->gc->prpl->name, irc->myhost ); + + /* proto_opt might contain garbage after the : */ + if( ( s = strchr( reason, ':' ) ) ) + *s = 0; + } + else + { + strcpy( reason, "Leaving..." ); + } - irc_write( irc, ":%s!%s@%s QUIT :%s", u->nick, u->user, u->host, "Leaving..." ); + irc_write( irc, ":%s!%s@%s QUIT :%s", u->nick, u->user, u->host, reason ); nick = g_strdup( u->nick ); nick_lc( nick ); -- cgit v1.2.3