aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--bitlbee.h3
-rw-r--r--conf.c2
-rw-r--r--dcc.c69
-rw-r--r--dcc.h9
-rw-r--r--ipc.c12
-rw-r--r--irc.c957
-rw-r--r--irc.h180
-rw-r--r--irc_channel.c160
-rw-r--r--irc_commands.c403
-rw-r--r--irc_im.c215
-rw-r--r--irc_send.c318
-rw-r--r--irc_user.c164
-rw-r--r--nick.c25
-rw-r--r--protocols/Makefile3
-rw-r--r--protocols/account.c (renamed from account.c)37
-rw-r--r--protocols/account.h (renamed from account.h)12
-rw-r--r--protocols/bee.c47
-rw-r--r--protocols/bee.h102
-rw-r--r--protocols/bee_ft.c66
-rw-r--r--protocols/bee_user.c197
-rw-r--r--protocols/chat.c (renamed from chat.c)0
-rw-r--r--protocols/chat.h (renamed from chat.h)0
-rw-r--r--protocols/ft.h6
-rw-r--r--protocols/jabber/iq.c4
-rw-r--r--protocols/jabber/jabber.c2
-rw-r--r--protocols/jabber/jabber_util.c8
-rw-r--r--protocols/jabber/s5bytestream.c14
-rw-r--r--protocols/jabber/si.c10
-rw-r--r--protocols/msn/Makefile2
-rw-r--r--protocols/msn/msn.c4
-rw-r--r--protocols/msn/msn_util.c3
-rw-r--r--protocols/msn/sb.c3
-rw-r--r--protocols/nogaim.c408
-rw-r--r--protocols/nogaim.h15
-rw-r--r--protocols/oscar/oscar.c7
-rw-r--r--root_commands.c159
-rw-r--r--set.c2
-rw-r--r--storage_xml.c18
-rw-r--r--user.c231
-rw-r--r--user.h62
41 files changed, 2049 insertions, 1893 deletions
diff --git a/Makefile b/Makefile
index ef34f123..8a3b3ef6 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,8 @@
-include Makefile.settings
# Program variables
-objects = account.o bitlbee.o chat.o dcc.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) user.o
+#objects = bitlbee.o chat.o dcc.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS)
+objects = bitlbee.o dcc.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o root_commands.o set.o storage.o $(STORAGE_OBJS)
headers = account.h bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/ft.h protocols/nogaim.h
subdirs = lib protocols
diff --git a/bitlbee.h b/bitlbee.h
index 5f98deef..24d09e2e 100644
--- a/bitlbee.h
+++ b/bitlbee.h
@@ -123,6 +123,7 @@
#define HELP_FILE VARDIR "help.txt"
#define CONF_FILE_DEF ETCDIR "bitlbee.conf"
+#include "bee.h"
#include "irc.h"
#include "storage.h"
#include "set.h"
@@ -157,7 +158,7 @@ int bitlbee_inetd_init( void );
gboolean bitlbee_io_current_client_read( gpointer data, gint source, b_input_condition cond );
gboolean bitlbee_io_current_client_write( gpointer data, gint source, b_input_condition cond );
-void root_command_string( irc_t *irc, user_t *u, char *command, int flags );
+void root_command_string( irc_t *irc, char *command );
void root_command( irc_t *irc, char *command[] );
gboolean bitlbee_shutdown( gpointer data, gint fd, b_input_condition cond );
diff --git a/conf.c b/conf.c
index 8687afea..d4e482cb 100644
--- a/conf.c
+++ b/conf.c
@@ -368,7 +368,7 @@ void conf_loaddefaults( irc_t *irc )
{
if( g_strcasecmp( ini->section, "defaults" ) == 0 )
{
- set_t *s = set_find( &irc->set, ini->key );
+ set_t *s = set_find( &irc->b->set, ini->key );
if( s )
{
diff --git a/dcc.c b/dcc.c
index 558d923a..e97b822f 100644
--- a/dcc.c
+++ b/dcc.c
@@ -60,55 +60,16 @@ unsigned int local_transfer_id=1;
*/
unsigned int receivedchunks=0, receiveddata=0;
-static void dcc_finish( file_transfer_t *file );
-static void dcc_close( file_transfer_t *file );
+void dcc_finish( file_transfer_t *file );
+void dcc_close( file_transfer_t *file );
gboolean dccs_send_proto( gpointer data, gint fd, b_input_condition cond );
-int dccs_send_request( struct dcc_file_transfer *df, char *user_nick, struct sockaddr_storage *saddr );
-gboolean dccs_recv_start( file_transfer_t *ft );
+int dccs_send_request( struct dcc_file_transfer *df, irc_user_t *iu, struct sockaddr_storage *saddr );
gboolean dccs_recv_proto( gpointer data, gint fd, b_input_condition cond);
gboolean dccs_recv_write_request( file_transfer_t *ft );
gboolean dcc_progress( gpointer data, gint fd, b_input_condition cond );
gboolean dcc_abort( dcc_file_transfer_t *df, char *reason, ... );
-/* As defined in ft.h */
-file_transfer_t *imcb_file_send_start( struct im_connection *ic, char *handle, char *file_name, size_t file_size )
-{
- user_t *u = user_findhandle( ic, handle );
- /* one could handle this more intelligent like imcb_buddy_msg.
- * can't call it directly though cause it does some wrapping.
- * Maybe give imcb_buddy_msg a parameter NO_WRAPPING? */
- if (!u) return NULL;
-
- return dccs_send_start( ic, u->nick, file_name, file_size );
-};
-
-/* As defined in ft.h */
-void imcb_file_canceled( file_transfer_t *file, char *reason )
-{
- if( file->canceled )
- file->canceled( file, reason );
-
- dcc_close( file );
-}
-
-/* As defined in ft.h */
-gboolean imcb_file_recv_start( file_transfer_t *ft )
-{
- return dccs_recv_start( ft );
-}
-
-/* As defined in ft.h */
-void imcb_file_finished( file_transfer_t *file )
-{
- dcc_file_transfer_t *df = file->priv;
-
- if( file->bytes_transferred >= file->file_size )
- dcc_finish( file );
- else
- df->proto_finished = TRUE;
-}
-
-dcc_file_transfer_t *dcc_alloc_transfer( char *file_name, size_t file_size, struct im_connection *ic )
+dcc_file_transfer_t *dcc_alloc_transfer( const char *file_name, size_t file_size, struct im_connection *ic )
{
file_transfer_t *file = g_new0( file_transfer_t, 1 );
dcc_file_transfer_t *df = file->priv = g_new0( dcc_file_transfer_t, 1 );
@@ -123,10 +84,11 @@ dcc_file_transfer_t *dcc_alloc_transfer( char *file_name, size_t file_size, stru
}
/* This is where the sending magic starts... */
-file_transfer_t *dccs_send_start( struct im_connection *ic, char *user_nick, char *file_name, size_t file_size )
+file_transfer_t *dccs_send_start( struct im_connection *ic, irc_user_t *iu, const char *file_name, size_t file_size )
{
file_transfer_t *file;
dcc_file_transfer_t *df;
+ irc_t *irc = (irc_t *) ic->bee->ui_data;
struct sockaddr_storage saddr;
char *errmsg;
char host[HOST_NAME_MAX];
@@ -149,20 +111,20 @@ file_transfer_t *dccs_send_start( struct im_connection *ic, char *user_nick, cha
file->status = FT_STATUS_LISTENING;
- if( !dccs_send_request( df, user_nick, &saddr ) )
+ if( !dccs_send_request( df, iu, &saddr ) )
return NULL;
/* watch */
df->watch_in = b_input_add( df->fd, GAIM_INPUT_READ, dccs_send_proto, df );
- df->ic->irc->file_transfers = g_slist_prepend( df->ic->irc->file_transfers, file );
+ irc->file_transfers = g_slist_prepend( irc->file_transfers, file );
df->progress_timeout = b_timeout_add( DCC_MAX_STALL * 1000, dcc_progress, df );
imcb_log( ic, "File transfer request from %s for %s (%zd kb).\n"
"Accept the file transfer if you'd like the file. If you don't, "
"issue the 'transfers reject' command.",
- user_nick, file_name, file_size / 1024 );
+ iu->nick, file_name, file_size / 1024 );
return file;
}
@@ -215,7 +177,7 @@ gboolean dcc_progress( gpointer data, gint fd, b_input_condition cond )
return dcc_abort( df , msg ": %s", strerror( errno ) );
/* Creates the "DCC SEND" line and sends it to the server */
-int dccs_send_request( struct dcc_file_transfer *df, char *user_nick, struct sockaddr_storage *saddr )
+int dccs_send_request( struct dcc_file_transfer *df, irc_user_t *iu, struct sockaddr_storage *saddr )
{
char ipaddr[INET6_ADDRSTRLEN];
const void *netaddr;
@@ -249,8 +211,7 @@ int dccs_send_request( struct dcc_file_transfer *df, char *user_nick, struct soc
cmd = g_strdup_printf( "\001DCC SEND %s %s %u %zu\001",
df->ft->file_name, ipaddr, port, df->ft->file_size );
- if ( !irc_msgfrom( df->ic->irc, user_nick, cmd ) )
- return dcc_abort( df, "Couldn't send `DCC SEND' message to %s.", user_nick );
+ irc_send_msg_raw( iu, "PRIVMSG", iu->irc->user->nick, cmd );
g_free( cmd );
@@ -495,9 +456,10 @@ gboolean dccs_send_write( file_transfer_t *file, char *data, unsigned int data_l
/*
* Cleans up after a transfer.
*/
-static void dcc_close( file_transfer_t *file )
+void dcc_close( file_transfer_t *file )
{
dcc_file_transfer_t *df = file->priv;
+ irc_t *irc = (irc_t *) df->ic->bee->ui_data;
if( file->free )
file->free( file );
@@ -513,7 +475,7 @@ static void dcc_close( file_transfer_t *file )
if( df->progress_timeout )
b_event_remove( df->progress_timeout );
- df->ic->irc->file_transfers = g_slist_remove( df->ic->irc->file_transfers, file );
+ irc->file_transfers = g_slist_remove( irc->file_transfers, file );
g_free( df );
g_free( file->file_name );
@@ -543,6 +505,7 @@ void dcc_finish( file_transfer_t *file )
*/
file_transfer_t *dcc_request( struct im_connection *ic, char *line )
{
+ irc_t *irc = (irc_t *) ic->bee->ui_data;
char *pattern = "SEND"
" (([^\"][^ ]*)|\"(([^\"]|\\\")*)\")"
" (([0-9]*)|([^ ]*))"
@@ -626,7 +589,7 @@ file_transfer_t *dcc_request( struct im_connection *ic, char *line )
freeaddrinfo( rp );
g_free( input );
- df->ic->irc->file_transfers = g_slist_prepend( df->ic->irc->file_transfers, ft );
+ irc->file_transfers = g_slist_prepend( irc->file_transfers, ft );
return ft;
}
diff --git a/dcc.h b/dcc.h
index cc784478..c0cf6ccc 100644
--- a/dcc.h
+++ b/dcc.h
@@ -94,11 +94,12 @@ typedef struct dcc_file_transfer {
int proto_finished;
} dcc_file_transfer_t;
-file_transfer_t *dccs_send_start( struct im_connection *ic, char *user_nick, char *file_name, size_t file_size );
-
+file_transfer_t *dccs_send_start( struct im_connection *ic, irc_user_t *iu, const char *file_name, size_t file_size );
void dcc_canceled( file_transfer_t *file, char *reason );
-
gboolean dccs_send_write( file_transfer_t *file, char *data, unsigned int data_size );
-
file_transfer_t *dcc_request( struct im_connection *ic, char *line );
+void dcc_finish( file_transfer_t *file );
+void dcc_close( file_transfer_t *file );
+gboolean dccs_recv_start( file_transfer_t *ft );
+
#endif
diff --git a/ipc.c b/ipc.c
index d6b850f1..2d833354 100644
--- a/ipc.c
+++ b/ipc.c
@@ -137,7 +137,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd )
return;
if( strchr( irc->umode, 'w' ) )
- irc_write( irc, ":%s WALLOPS :%s", irc->myhost, cmd[1] );
+ irc_write( irc, ":%s WALLOPS :%s", irc->root->host, cmd[1] );
}
static void ipc_child_cmd_wall( irc_t *irc, char **cmd )
@@ -146,7 +146,7 @@ static void ipc_child_cmd_wall( irc_t *irc, char **cmd )
return;
if( strchr( irc->umode, 's' ) )
- irc_write( irc, ":%s NOTICE %s :%s", irc->myhost, irc->nick, cmd[1] );
+ irc_write( irc, ":%s NOTICE %s :%s", irc->root->host, irc->user->nick, cmd[1] );
}
static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd )
@@ -155,7 +155,7 @@ static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd )
return;
if( strchr( irc->umode, 'o' ) )
- irc_write( irc, ":%s NOTICE %s :*** OperMsg *** %s", irc->myhost, irc->nick, cmd[1] );
+ irc_write( irc, ":%s NOTICE %s :*** OperMsg *** %s", irc->root->host, irc->user->nick, cmd[1] );
}
static void ipc_child_cmd_rehash( irc_t *irc, char **cmd )
@@ -175,10 +175,10 @@ static void ipc_child_cmd_kill( irc_t *irc, char **cmd )
if( !( irc->status & USTATUS_LOGGED_IN ) )
return;
- if( nick_cmp( cmd[1], irc->nick ) != 0 )
+ if( nick_cmp( cmd[1], irc->user->nick ) != 0 )
return; /* It's not for us. */
- irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->mynick, irc->mynick, irc->myhost, irc->nick, cmd[2] );
+ irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->root->nick, irc->root->nick, irc->root->host, irc->user->nick, cmd[2] );
irc_abort( irc, 0, "Killed by operator: %s", cmd[2] );
}
@@ -187,7 +187,7 @@ static void ipc_child_cmd_hello( irc_t *irc, char **cmd )
if( !( irc->status & USTATUS_LOGGED_IN ) )
ipc_to_master_str( "HELLO\r\n" );
else
- ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
+ ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname );
}
static const command_t ipc_child_commands[] = {
diff --git a/irc.c b/irc.c
index edb42dde..4824d0ac 100644
--- a/irc.c
+++ b/irc.c
@@ -4,7 +4,7 @@
* Copyright 2002-2004 Wilmer van der Gaast and others *
\********************************************************************/
-/* The big hairy IRCd part of the project */
+/* The IRC-based UI (for now the only one) */
/*
This program is free software; you can redistribute it and/or modify
@@ -23,85 +23,23 @@
Suite 330, Boston, MA 02111-1307 USA
*/
-#define BITLBEE_CORE
#include "bitlbee.h"
-#include "sock.h"
#include "ipc.h"
-#include "dcc.h"
-static gboolean irc_userping( gpointer _irc, int fd, b_input_condition cond );
+GSList *irc_connection_list;
-GSList *irc_connection_list = NULL;
-
-static char *set_eval_password( set_t *set, char *value )
-{
- irc_t *irc = set->data;
-
- if( irc->status & USTATUS_IDENTIFIED && value )
- {
- irc_setpass( irc, value );
- return NULL;
- }
- else
- {
- return SET_INVALID;
- }
-}
-
-static char *set_eval_charset( set_t *set, char *value )
-{
- irc_t *irc = set->data;
- GIConv ic, oc;
-
- if( g_strcasecmp( value, "none" ) == 0 )
- value = g_strdup( "utf-8" );
-
- if( ( ic = g_iconv_open( "utf-8", value ) ) == (GIConv) -1 )
- {
- return NULL;
- }
- if( ( oc = g_iconv_open( value, "utf-8" ) ) == (GIConv) -1 )
- {
- g_iconv_close( ic );
- return NULL;
- }
-
- if( irc->iconv != (GIConv) -1 )
- g_iconv_close( irc->iconv );
- if( irc->oconv != (GIConv) -1 )
- g_iconv_close( irc->oconv );
-
- irc->iconv = ic;
- irc->oconv = oc;
-
- return value;
-}
-
-static char *set_eval_away_status( set_t *set, char *value )
-{
- irc_t *irc = set->data;
- account_t *a;
-
- g_free( set->value );
- set->value = g_strdup( value );
-
- for( a = irc->accounts; a; a = a->next )
- {
- struct im_connection *ic = a->ic;
-
- if( ic && ic->flags & OPT_LOGGED_IN )
- imc_away_send_update( ic );
- }
-
- return value;
-}
+static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond );
+static char *set_eval_charset( set_t *set, char *value );
irc_t *irc_new( int fd )
{
irc_t *irc;
struct sockaddr_storage sock;
socklen_t socklen = sizeof( sock );
+ char *host = NULL, *myhost = NULL;
+ irc_user_t *iu;
set_t *s;
+ bee_t *b;
irc = g_new0( irc_t, 1 );
@@ -113,19 +51,15 @@ irc_t *irc_new( int fd )
irc->status = USTATUS_OFFLINE;
irc->last_pong = gettime();
- irc->userhash = g_hash_table_new( g_str_hash, g_str_equal );
+ irc->nick_user_hash = g_hash_table_new( g_str_hash, g_str_equal );
irc->watches = g_hash_table_new( g_str_hash, g_str_equal );
- strcpy( irc->umode, UMODE );
- irc->mynick = g_strdup( ROOT_NICK );
- irc->channel = g_strdup( ROOT_CHAN );
-
irc->iconv = (GIConv) -1;
irc->oconv = (GIConv) -1;
if( global.conf->hostname )
{
- irc->myhost = g_strdup( global.conf->hostname );
+ myhost = g_strdup( global.conf->hostname );
}
else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
{
@@ -134,7 +68,7 @@ irc_t *irc_new( int fd )
if( getnameinfo( (struct sockaddr *) &sock, socklen, buf,
NI_MAXHOST, NULL, 0, 0 ) == 0 )
{
- irc->myhost = g_strdup( ipv6_unwrap( buf ) );
+ myhost = g_strdup( ipv6_unwrap( buf ) );
}
}
@@ -145,57 +79,65 @@ irc_t *irc_new( int fd )
if( getnameinfo( (struct sockaddr *)&sock, socklen, buf,
NI_MAXHOST, NULL, 0, 0 ) == 0 )
{
- irc->host = g_strdup( ipv6_unwrap( buf ) );
+ host = g_strdup( ipv6_unwrap( buf ) );
}
}
- if( irc->host == NULL )
- irc->host = g_strdup( "localhost.localdomain" );
- if( irc->myhost == NULL )
- irc->myhost = g_strdup( "localhost.localdomain" );
+ if( host == NULL )
+ host = g_strdup( "localhost.localdomain" );
+ if( myhost == NULL )
+ myhost = g_strdup( "localhost.localdomain" );
if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
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" );
irc_connection_list = g_slist_append( irc_connection_list, irc );
- s = set_add( &irc->set, "away", NULL, set_eval_away_status, irc );
- s->flags |= SET_NULL_OK;
- s = set_add( &irc->set, "away_devoice", "true", set_eval_away_devoice, irc );
- s = set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
- s = set_add( &irc->set, "auto_reconnect", "true", set_eval_bool, irc );
- s = set_add( &irc->set, "auto_reconnect_delay", "5*3<900", set_eval_account_reconnect_delay, irc );
- s = set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
- s = set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
- s = set_add( &irc->set, "charset", "utf-8", set_eval_charset, irc );
- s = set_add( &irc->set, "control_channel", irc->channel, set_eval_control_channel, irc );
- s = set_add( &irc->set, "debug", "false", set_eval_bool, irc );
- s = set_add( &irc->set, "default_target", "root", NULL, irc );
- s = set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc );
- s = set_add( &irc->set, "handle_unknown", "root", NULL, irc );
- s = set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc );
- s = set_add( &irc->set, "ops", "both", set_eval_ops, irc );
- s = set_add( &irc->set, "password", NULL, set_eval_password, irc );
- s->flags |= SET_NULL_OK;
- s = set_add( &irc->set, "private", "true", set_eval_bool, irc );
- s = set_add( &irc->set, "query_order", "lifo", NULL, irc );
- s = set_add( &irc->set, "root_nick", irc->mynick, set_eval_root_nick, irc );
- s = set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc );
- s = set_add( &irc->set, "simulate_netsplit", "true", set_eval_bool, irc );
- s = set_add( &irc->set, "status", NULL, set_eval_away_status, irc );
- s->flags |= SET_NULL_OK;
- s = set_add( &irc->set, "strip_html", "true", NULL, irc );
- s = set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
- s = set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc );
+ b = irc->b = bee_new();
+ b->ui_data = irc;
+ b->ui = &irc_ui_funcs;
+
+ s = set_add( &b->set, "away_devoice", "true", NULL/*set_eval_away_devoice*/, irc );
+ s = set_add( &b->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
+ s = set_add( &b->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
+ s = set_add( &b->set, "charset", "utf-8", set_eval_charset, irc );
+ //s = set_add( &b->set, "control_channel", irc->channel, NULL/*set_eval_control_channel*/, irc );
+ s = set_add( &b->set, "default_target", "root", NULL, irc );
+ s = set_add( &b->set, "display_namechanges", "false", set_eval_bool, irc );
+ s = set_add( &b->set, "handle_unknown", "root", NULL, irc );
+ s = set_add( &b->set, "lcnicks", "true", set_eval_bool, irc );
+ s = set_add( &b->set, "ops", "both", NULL/*set_eval_ops*/, irc );
+ s = set_add( &b->set, "private", "true", set_eval_bool, irc );
+ s = set_add( &b->set, "query_order", "lifo", NULL, irc );
+ s = set_add( &b->set, "root_nick", ROOT_NICK, NULL/*set_eval_root_nick*/, irc );
+ s = set_add( &b->set, "simulate_netsplit", "true", set_eval_bool, irc );
+ s = set_add( &b->set, "to_char", ": ", set_eval_to_char, irc );
+ s = set_add( &b->set, "typing_notice", "false", set_eval_bool, irc );
+
+ irc->root = iu = irc_user_new( irc, ROOT_NICK );
+ iu->host = g_strdup( myhost );
+ iu->fullname = g_strdup( ROOT_FN );
+ iu->f = &irc_user_root_funcs;
+
+ iu = irc_user_new( irc, NS_NICK );
+ iu->host = g_strdup( myhost );
+ iu->fullname = g_strdup( ROOT_FN );
+ iu->f = &irc_user_root_funcs;
+
+ irc->user = g_new0( irc_user_t, 1 );
+ irc->user->host = g_strdup( host );
conf_loaddefaults( irc );
/* Evaluator sets the iconv/oconv structures. */
- set_eval_charset( set_find( &irc->set, "charset" ), set_getstr( &irc->set, "charset" ) );
+ set_eval_charset( set_find( &b->set, "charset" ), set_getstr( &b->set, "charset" ) );
- return( irc );
+ irc_write( irc, ":%s NOTICE AUTH :%s", irc->root->host, "BitlBee-IRCd initialized, please go on" );
+
+ g_free( myhost );
+ g_free( host );
+
+ return irc;
}
/* immed=1 makes this function pretty much equal to irc_free(), except that
@@ -216,7 +158,7 @@ void irc_abort( irc_t *irc, int immed, char *format, ... )
irc_write( irc, "ERROR :Closing link: %s", reason );
ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
- irc->nick ? irc->nick : "(NONE)", irc->host, reason );
+ irc->user->nick ? irc->user->nick : "(NONE)", irc->root->host, reason );
g_free( reason );
}
@@ -226,7 +168,7 @@ void irc_abort( irc_t *irc, int immed, char *format, ... )
irc_write( irc, "ERROR :Closing link" );
ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n",
- irc->nick ? irc->nick : "(NONE)", irc->host, "No reason given" );
+ irc->user->nick ? irc->user->nick : "(NONE)", irc->root->host, "No reason given" );
}
irc->status |= USTATUS_SHUTDOWN;
@@ -247,66 +189,34 @@ void irc_abort( irc_t *irc, int immed, char *format, ... )
}
}
-static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data )
-{
- g_free( key );
-
- return( TRUE );
-}
+static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data );
-/* Because we have no garbage collection, this is quite annoying */
void irc_free( irc_t * irc )
{
- user_t *user, *usertmp;
-
log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
- if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->set, "save_on_quit" ) )
+ /*
+ if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->b->set, "save_on_quit" ) )
if( storage_save( irc, NULL, TRUE ) != STORAGE_OK )
irc_usermsg( irc, "Error while saving settings!" );
+ */
irc_connection_list = g_slist_remove( irc_connection_list, irc );
- while( irc->accounts )
- {
- if( irc->accounts->ic )
- imc_logout( irc->accounts->ic, FALSE );
- else if( irc->accounts->reconnect )
- cancel_auto_reconnect( irc->accounts );
-
- if( irc->accounts->ic == NULL )
- account_del( irc, irc->accounts );
- else
- /* Nasty hack, but account_del() doesn't work in this
- case and we don't want infinite loops, do we? ;-) */
- irc->accounts = irc->accounts->next;
- }
-
+ /*
while( irc->queries != NULL )
query_del( irc, irc->queries );
+ */
- while( irc->set )
- set_del( &irc->set, irc->set->key );
-
- if (irc->users != NULL)
+ while( irc->users )
{
- user = irc->users;
- while( user != NULL )
- {
- g_free( user->nick );
- g_free( user->away );
- g_free( user->handle );
- 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 );
- b_event_remove( user->sendbuf_timer );
-
- usertmp = user;
- user = user->next;
- g_free( usertmp );
- }
+ irc_user_t *iu = irc->users->data;
+ irc_user_free( irc, iu->nick );
}
+ while( irc->channels )
+ irc_channel_free( irc->channels->data );
+
if( irc->ping_source_id > 0 )
b_event_remove( irc->ping_source_id );
if( irc->r_watch_source_id > 0 )
@@ -317,8 +227,8 @@ void irc_free( irc_t * irc )
closesocket( irc->fd );
irc->fd = -1;
- g_hash_table_foreach_remove( irc->userhash, irc_free_hashkey, NULL );
- g_hash_table_destroy( irc->userhash );
+ g_hash_table_foreach_remove( irc->nick_user_hash, irc_free_hashkey, NULL );
+ g_hash_table_destroy( irc->nick_user_hash );
g_hash_table_foreach_remove( irc->watches, irc_free_hashkey, NULL );
g_hash_table_destroy( irc->watches );
@@ -331,19 +241,8 @@ void irc_free( irc_t * irc )
g_free( irc->sendbuffer );
g_free( irc->readbuffer );
- g_free( irc->nick );
- g_free( irc->user );
- g_free( irc->host );
- g_free( irc->realname );
g_free( irc->password );
- g_free( irc->myhost );
- g_free( irc->mynick );
-
- g_free( irc->channel );
-
- g_free( irc->last_target );
-
g_free( irc );
if( global.conf->runmode == RUNMODE_INETD ||
@@ -354,9 +253,16 @@ void irc_free( irc_t * irc )
b_main_quit();
}
+static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data )
+{
+ g_free( key );
+
+ return( TRUE );
+}
+
/* USE WITH CAUTION!
Sets pass without checking */
-void irc_setpass (irc_t *irc, const char *pass)
+void irc_setpass (irc_t *irc, const char *pass)
{
g_free (irc->password);
@@ -367,6 +273,8 @@ void irc_setpass (irc_t *irc, const char *pass)
}
}
+static char **irc_splitlines( char *buffer );
+
void irc_process( irc_t *irc )
{
char **lines, *temp, **cmd;
@@ -374,7 +282,7 @@ void irc_process( irc_t *irc )
if( irc->readbuffer != NULL )
{
- lines = irc_tokenize( irc->readbuffer );
+ lines = irc_splitlines( irc->readbuffer );
for( i = 0; *lines[i] != '\0'; i ++ )
{
@@ -411,14 +319,14 @@ void irc_process( irc_t *irc )
"expect by changing the charset setting. See "
"`help set charset' for more information. Your "
"message was ignored.",
- set_getstr( &irc->set, "charset" ) );
+ set_getstr( &irc->b->set, "charset" ) );
g_free( conv );
conv = NULL;
}
else
{
- irc_write( irc, ":%s NOTICE AUTH :%s", irc->myhost,
+ irc_write( irc, ":%s NOTICE AUTH :%s", irc->root->host,
"Warning: invalid characters received at login time." );
conv = g_strdup( lines[i] );
@@ -456,9 +364,11 @@ 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 )
+/* 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. Could use g_strsplit() but this one does it in-place.
+ (So yes, it's destructive.) */
+static char **irc_splitlines( char *buffer )
{
int i, j, n = 3;
char **lines;
@@ -589,46 +499,45 @@ char *irc_build_line( char **cmd )
return s;
}
-void irc_reply( irc_t *irc, int code, char *format, ... )
+void irc_write( irc_t *irc, char *format, ... )
{
- char text[IRC_MAX_LINE];
va_list params;
-
+
va_start( params, format );
- g_vsnprintf( text, IRC_MAX_LINE, format, params );
+ irc_vawrite( irc, format, params );
va_end( params );
- irc_write( irc, ":%s %03d %s %s", irc->myhost, code, irc->nick?irc->nick:"*", text );
-
+
return;
}
-int irc_usermsg( irc_t *irc, char *format, ... )
+void irc_write_all( int now, char *format, ... )
{
- char text[1024];
va_list params;
- char is_private = 0;
- user_t *u;
-
- u = user_find( irc, irc->mynick );
- is_private = u->is_private;
+ GSList *temp;
va_start( params, format );
- g_vsnprintf( text, sizeof( text ), format, params );
- va_end( params );
- return( irc_msgfrom( irc, u->nick, text ) );
-}
-
-void irc_write( irc_t *irc, char *format, ... )
-{
- va_list params;
-
- va_start( params, format );
- irc_vawrite( irc, format, params );
+ temp = irc_connection_list;
+ while( temp != NULL )
+ {
+ irc_t *irc = temp->data;
+
+ if( now )
+ {
+ g_free( irc->sendbuffer );
+ irc->sendbuffer = g_strdup( "\r\n" );
+ }
+ irc_vawrite( temp->data, format, params );
+ if( now )
+ {
+ bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE );
+ }
+ temp = temp->next;
+ }
+
va_end( params );
-
return;
-}
+}
void irc_vawrite( irc_t *irc, char *format, va_list params )
{
@@ -685,105 +594,54 @@ void irc_vawrite( irc_t *irc, char *format, va_list params )
return;
}
-void irc_write_all( int now, char *format, ... )
+int irc_check_login( irc_t *irc )
{
- va_list params;
- GSList *temp;
-
- va_start( params, format );
-
- temp = irc_connection_list;
- while( temp != NULL )
+ if( irc->user->user && irc->user->nick )
{
- irc_t *irc = temp->data;
-
- if( now )
- {
- g_free( irc->sendbuffer );
- irc->sendbuffer = g_strdup( "\r\n" );
- }
- irc_vawrite( temp->data, format, params );
- if( now )
+ if( global.conf->authmode == AUTHMODE_CLOSED && !( irc->status & USTATUS_AUTHORIZED ) )
{
- bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE );
+ irc_send_num( irc, 464, ":This server is password-protected." );
+ return 0;
}
- temp = temp->next;
- }
-
- va_end( params );
- return;
-}
-
-void irc_names( irc_t *irc, char *channel )
-{
- user_t *u;
- char namelist[385] = "";
- struct groupchat *c = NULL;
- char *ops = set_getstr( &irc->set, "ops" );
-
- /* RFCs say there is no error reply allowed on NAMES, so when the
- channel is invalid, just give an empty reply. */
-
- if( g_strcasecmp( channel, irc->channel ) == 0 )
- {
- for( u = irc->users; u; u = u->next ) if( u->online )
+ else
{
- if( strlen( namelist ) + strlen( u->nick ) > sizeof( namelist ) - 4 )
- {
- irc_reply( irc, 353, "= %s :%s", channel, namelist );
- *namelist = 0;
- }
+ irc_channel_t *ic;
+ irc_user_t *iu = irc->user;
- if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) )
- strcat( namelist, "+" );
- else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
- ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) )
- strcat( namelist, "@" );
+ irc->user = irc_user_new( irc, iu->nick );
+ irc->user->user = iu->user;
+ irc->user->host = iu->host;
+ irc->user->fullname = iu->fullname;
+ irc->user->f = &irc_user_self_funcs;
+ g_free( iu->nick );
+ g_free( iu );
- strcat( namelist, u->nick );
- strcat( namelist, " " );
- }
- }
- else if( ( c = irc_chat_by_channel( irc, channel ) ) )
- {
- GList *l;
-
- /* root and the user aren't in the channel userlist but should
- show up in /NAMES, so list them first: */
- sprintf( namelist, "%s%s %s%s ", strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->mynick,
- strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) ? "@" : "", irc->nick );
-
- for( l = c->in_room; l; l = l->next ) if( ( u = user_findhandle( c->ic, l->data ) ) )
- {
- if( strlen( namelist ) + strlen( u->nick ) > sizeof( namelist ) - 4 )
+ if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
+ ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname );
+
+ irc->status |= USTATUS_LOGGED_IN;
+
+ /* This is for bug #209 (use PASS to identify to NickServ). */
+ if( irc->password != NULL )
{
- irc_reply( irc, 353, "= %s :%s", channel, namelist );
- *namelist = 0;
+ char *send_cmd[] = { "identify", g_strdup( irc->password ), NULL };
+
+ /*irc_setpass( irc, NULL );*/
+ /*root_command( irc, send_cmd );*/
+ g_free( send_cmd[1] );
}
- strcat( namelist, u->nick );
- strcat( namelist, " " );
- }
- }
-
- if( *namelist )
- irc_reply( irc, 353, "= %s :%s", channel, namelist );
-
- irc_reply( irc, 366, "%s :End of /NAMES list", channel );
-}
-
-int irc_check_login( irc_t *irc )
-{
- if( irc->user && irc->nick )
- {
- if( global.conf->authmode == AUTHMODE_CLOSED && !( irc->status & USTATUS_AUTHORIZED ) )
- {
- irc_reply( irc, 464, ":This server is password-protected." );
- return 0;
- }
- else
- {
- irc_login( irc );
+ irc_send_login( irc );
+
+ irc->umode[0] = '\0';
+ irc_umode_set( irc, "+" UMODE, TRUE );
+
+ ic = irc_channel_new( irc, ROOT_CHAN );
+ irc_channel_set_topic( ic, CONTROL_TOPIC, irc->root );
+ irc_channel_add_user( ic, irc->user );
+
+ irc->last_root_cmd = g_strdup( ROOT_CHAN );
+
return 1;
}
}
@@ -794,135 +652,12 @@ int irc_check_login( irc_t *irc )
}
}
-void irc_login( irc_t *irc )
-{
- user_t *u;
-
- irc_reply( irc, 1, ":Welcome to the BitlBee gateway, %s", irc->nick );
- irc_reply( irc, 2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->myhost );
- irc_reply( irc, 3, ":%s", IRCD_INFO );
- irc_reply( irc, 4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES );
- irc_reply( irc, 5, "PREFIX=(ov)@+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee "
- "CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server",
- CTYPES, CMODES, MAX_NICK_LENGTH - 1 );
- irc_motd( irc );
- irc->umode[0] = '\0';
- irc_umode_set( irc, "+" UMODE, 1 );
-
- u = user_add( irc, irc->mynick );
- u->host = g_strdup( irc->myhost );
- u->realname = g_strdup( ROOT_FN );
- u->online = 1;
- u->send_handler = root_command_string;
- u->is_private = 0; /* [SH] The channel is root's personal playground. */
- irc_spawn( irc, u );
-
- u = user_add( irc, NS_NICK );
- u->host = g_strdup( irc->myhost );
- u->realname = g_strdup( ROOT_FN );
- u->online = 0;
- u->send_handler = root_command_string;
- u->is_private = 1; /* [SH] NickServ is not in the channel, so should always /query. */
-
- u = user_add( irc, irc->nick );
- u->user = g_strdup( irc->user );
- u->host = g_strdup( irc->host );
- u->realname = g_strdup( irc->realname );
- u->online = 1;
- irc_spawn( irc, u );
-
- irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\n"
- "If you've never used BitlBee before, please do read the help "
- "information using the \x02help\x02 command. Lots of FAQs are "
- "answered there.\n"
- "If you already have an account on this server, just use the "
- "\x02identify\x02 command to identify yourself." );
-
- if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
- ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
-
- irc->status |= USTATUS_LOGGED_IN;
-
- /* This is for bug #209 (use PASS to identify to NickServ). */
- if( irc->password != NULL )
- {
- char *send_cmd[] = { "identify", g_strdup( irc->password ), NULL };
-
- irc_setpass( irc, NULL );
- root_command( irc, send_cmd );
- g_free( send_cmd[1] );
- }
-}
-
-void irc_motd( irc_t *irc )
-{
- int fd;
-
- fd = open( global.conf->motdfile, O_RDONLY );
- if( fd == -1 )
- {
- irc_reply( irc, 422, ":We don't need MOTDs." );
- }
- else
- {
- char linebuf[80]; /* Max. line length for MOTD's is 79 chars. It's what most IRC networks seem to do. */
- char *add, max;
- int len;
-
- linebuf[79] = len = 0;
- max = sizeof( linebuf ) - 1;
-
- irc_reply( irc, 375, ":- %s Message Of The Day - ", irc->myhost );
- while( read( fd, linebuf + len, 1 ) == 1 )
- {
- if( linebuf[len] == '\n' || len == max )
- {
- linebuf[len] = 0;
- irc_reply( irc, 372, ":- %s", linebuf );
- len = 0;
- }
- else if( linebuf[len] == '%' )
- {
- read( fd, linebuf + len, 1 );
- if( linebuf[len] == 'h' )
- add = irc->myhost;
- else if( linebuf[len] == 'v' )
- add = BITLBEE_VERSION;
- else if( linebuf[len] == 'n' )
- add = irc->nick;
- else
- add = "%";
-
- strncpy( linebuf + len, add, max - len );
- while( linebuf[++len] );
- }
- else if( len < max )
- {
- len ++;
- }
- }
- irc_reply( irc, 376, ":End of MOTD" );
- close( fd );
- }
-}
-
-void irc_topic( irc_t *irc, char *channel )
-{
- struct groupchat *c = irc_chat_by_channel( irc, channel );
-
- if( c && c->topic )
- irc_reply( irc, 332, "%s :%s", channel, c->topic );
- else if( g_strcasecmp( channel, irc->channel ) == 0 )
- irc_reply( irc, 332, "%s :%s", channel, CONTROL_TOPIC );
- else
- irc_reply( irc, 331, "%s :No topic for this channel", channel );
-}
-
-void irc_umode_set( irc_t *irc, char *s, int allow_priv )
+void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv )
{
/* allow_priv: Set to 0 if s contains user input, 1 if you want
to set a "privileged" mode (+o, +R, etc). */
- char m[256], st = 1, *t;
+ char m[128], st = 1;
+ const char *t;
int i;
char changes[512], *p, st2 = 2;
char badflag = 0;
@@ -930,14 +665,17 @@ void irc_umode_set( irc_t *irc, char *s, int allow_priv )
memset( m, 0, sizeof( m ) );
for( t = irc->umode; *t; t ++ )
- m[(int)*t] = 1;
-
+ if( *t < sizeof( m ) )
+ m[(int)*t] = 1;
+
p = changes;
for( t = s; *t; t ++ )
{
if( *t == '+' || *t == '-' )
st = *t == '+';
- else if( st == 0 || ( strchr( UMODES, *t ) || ( allow_priv && strchr( UMODES_PRIV, *t ) ) ) )
+ else if( ( st == 0 && ( !strchr( UMODES_KEEP, *t ) || allow_priv ) ) ||
+ ( st == 1 && strchr( UMODES, *t ) ) ||
+ ( st == 1 && allow_priv && strchr( UMODES_PRIV, *t ) ) )
{
if( m[(int)*t] != st)
{
@@ -954,339 +692,18 @@ void irc_umode_set( irc_t *irc, char *s, int allow_priv )
memset( irc->umode, 0, sizeof( irc->umode ) );
- for( i = 0; i < 256 && strlen( irc->umode ) < ( sizeof( irc->umode ) - 1 ); i ++ )
+ for( i = 'A'; i <= 'z' && strlen( irc->umode ) < ( sizeof( irc->umode ) - 1 ); i ++ )
if( m[i] )
irc->umode[strlen(irc->umode)] = i;
if( badflag )
- irc_reply( irc, 501, ":Unknown MODE flag" );
- /* Deliberately no !user@host on the prefix here */
+ irc_send_num( irc, 501, ":Unknown MODE flag" );
if( *changes )
- irc_write( irc, ":%s MODE %s %s", irc->nick, irc->nick, changes );
-}
-
-void irc_spawn( irc_t *irc, user_t *u )
-{
- irc_join( irc, u, irc->channel );
-}
-
-void irc_join( irc_t *irc, user_t *u, char *channel )
-{
- char *nick;
-
- if( ( g_strcasecmp( channel, irc->channel ) != 0 ) || user_find( irc, irc->nick ) )
- irc_write( irc, ":%s!%s@%s JOIN :%s", u->nick, u->user, u->host, channel );
-
- if( nick_cmp( u->nick, irc->nick ) == 0 )
- {
- irc_write( irc, ":%s MODE %s +%s", irc->myhost, channel, CMODE );
- irc_names( irc, channel );
- irc_topic( irc, channel );
- }
-
- nick = g_strdup( u->nick );
- 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, (int) time( NULL ), "logged online" );
- }
- g_free( nick );
-}
-
-void irc_part( irc_t *irc, user_t *u, char *channel )
-{
- irc_write( irc, ":%s!%s@%s PART %s :%s", u->nick, u->user, u->host, channel, "" );
-}
-
-void irc_kick( irc_t *irc, user_t *u, char *channel, user_t *kicker )
-{
- irc_write( irc, ":%s!%s@%s KICK %s %s :%s", kicker->nick, kicker->user, kicker->host, channel, u->nick, "" );
-}
-
-void irc_kill( irc_t *irc, user_t *u )
-{
- char *nick, *s;
- char reason[128];
-
- if( u->ic && u->ic->flags & OPT_LOGGING_OUT && set_getbool( &irc->set, "simulate_netsplit" ) )
- {
- if( u->ic->acc->server )
- g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost,
- u->ic->acc->server );
- else if( ( s = strchr( u->ic->acc->user, '@' ) ) )
- g_snprintf( reason, sizeof( reason ), "%s %s", irc->myhost,
- s + 1 );
- else
- g_snprintf( reason, sizeof( reason ), "%s %s.%s", irc->myhost,
- u->ic->acc->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, reason );
-
- nick = g_strdup( u->nick );
- 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, (int) time( NULL ), "logged offline" );
- }
- g_free( nick );
-}
-
-int irc_send( irc_t *irc, char *nick, char *s, int flags )
-{
- struct groupchat *c = NULL;
- user_t *u = NULL;
-
- if( strchr( CTYPES, *nick ) )
- {
- if( !( c = irc_chat_by_channel( irc, nick ) ) )
- {
- irc_reply( irc, 403, "%s :Channel does not exist", nick );
- return( 0 );
- }
- }
- else
- {
- u = user_find( irc, nick );
-
- if( !u )
- {
- if( irc->is_private )
- irc_reply( irc, 401, "%s :Nick does not exist", nick );
- else
- irc_usermsg( irc, "Nick `%s' does not exist!", nick );
- return( 0 );
- }
- }
-
- if( *s == 1 && s[strlen(s)-1] == 1 )
- {
- if( g_strncasecmp( s + 1, "ACTION", 6 ) == 0 )
- {
- if( s[7] == ' ' ) s ++;
- s += 3;
- *(s++) = '/';
- *(s++) = 'm';
- *(s++) = 'e';
- *(s++) = ' ';
- s -= 4;
- s[strlen(s)-1] = 0;
- }
- else if( g_strncasecmp( s + 1, "VERSION", 7 ) == 0 )
- {
- u = user_find( irc, irc->mynick );
- irc_privmsg( irc, u, "NOTICE", irc->nick, "", "\001VERSION BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\001" );
- return( 1 );
- }
- else if( g_strncasecmp( s + 1, "PING", 4 ) == 0 )
- {
- u = user_find( irc, irc->mynick );
- irc_privmsg( irc, u, "NOTICE", irc->nick, "", s );
- return( 1 );
- }
- else if( g_strncasecmp( s + 1, "TYPING", 6 ) == 0 )
- {
- if( u && u->ic && u->ic->acc->prpl->send_typing && strlen( s ) >= 10 )
- {
- time_t current_typing_notice = time( NULL );
-
- if( current_typing_notice - u->last_typing_notice >= 5 )
- {
- u->ic->acc->prpl->send_typing( u->ic, u->handle, ( s[8] - '0' ) << 8 );
- u->last_typing_notice = current_typing_notice;
- }
- }
- return( 1 );
- }
- else if( g_strncasecmp( s + 1, "DCC", 3 ) == 0 )
- {
- if( u && u->ic && u->ic->acc->prpl->transfer_request )
- {
- file_transfer_t *ft = dcc_request( u->ic, s + 5 );
- if ( ft )
- u->ic->acc->prpl->transfer_request( u->ic, ft, u->handle );
- }
- return( 1 );
- }
- else
- {
- irc_usermsg( irc, "Supported CTCPs are ACTION, VERSION, PING, TYPING, DCC" );
- return( 0 );
- }
- }
-
- if( u )
- {
- /* For the next message, we probably do have to send new notices... */
- u->last_typing_notice = 0;
- u->is_private = irc->is_private;
-
- if( u->is_private )
- {
- if( !u->online )
- irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" );
- else if( u->away )
- irc_reply( irc, 301, "%s :%s", u->nick, u->away );
- }
-
- if( u->send_handler )
- {
- u->send_handler( irc, u, s, flags );
- return 1;
- }
- }
- else if( c && c->ic && c->ic->acc && c->ic->acc->prpl )
- {
- return( imc_chat_msg( c, s, 0 ) );
- }
-
- return( 0 );
-}
-
-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 */
- imc_buddy_msg( u->ic, u->handle, u->sendbuf, u->sendbuf_flags );
-
- g_free( u->sendbuf );
- u->sendbuf = NULL;
- u->sendbuf_len = 0;
- u->sendbuf_timer = 0;
- u->sendbuf_flags = 0;
-
- return FALSE;
-}
-
-void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags )
-{
- if( !u || !u->ic ) return;
-
- if( set_getbool( &irc->set, "buddy_sendbuffer" ) && set_getint( &irc->set, "buddy_sendbuffer_delay" ) > 0 )
- {
- int delay;
-
- if( u->sendbuf_len > 0 && u->sendbuf_flags != flags)
- {
- /* 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[0] = 0;
- u->sendbuf_flags = flags;
- }
- else
- {
- u->sendbuf_len += strlen( msg ) + 1;
- u->sendbuf = g_renew( char, u->sendbuf, u->sendbuf_len );
- }
-
- strcat( u->sendbuf, msg );
- strcat( u->sendbuf, "\n" );
-
- delay = set_getint( &irc->set, "buddy_sendbuffer_delay" );
- if( delay <= 5 )
- delay *= 1000;
-
- if( u->sendbuf_timer > 0 )
- b_event_remove( u->sendbuf_timer );
- u->sendbuf_timer = b_timeout_add( delay, buddy_send_handler_delayed, u );
- }
- else
- {
- imc_buddy_msg( u->ic, u->handle, msg, flags );
- }
-}
-
-int irc_privmsg( irc_t *irc, user_t *u, char *type, char *to, char *prefix, char *msg )
-{
- char last = 0;
- char *s = msg, *line = msg;
-
- /* The almighty linesplitter .. woohoo!! */
- while( !last )
- {
- if( *s == '\r' && *(s+1) == '\n' )
- *(s++) = 0;
- if( *s == '\n' )
- {
- last = s[1] == 0;
- *s = 0;
- }
- else
- {
- last = s[0] == 0;
- }
- if( *s == 0 )
- {
- if( g_strncasecmp( line, "/me ", 4 ) == 0 && ( !prefix || !*prefix ) && g_strcasecmp( type, "PRIVMSG" ) == 0 )
- {
- irc_write( irc, ":%s!%s@%s %s %s :\001ACTION %s\001", u->nick, u->user, u->host,
- type, to, line + 4 );
- }
- else
- {
- irc_write( irc, ":%s!%s@%s %s %s :%s%s", u->nick, u->user, u->host,
- type, to, prefix ? prefix : "", line );
- }
- line = s + 1;
- }
- s ++;
- }
-
- return( 1 );
+ irc_write( irc, ":%s!%s@%s MODE %s :%s", irc->user->nick,
+ irc->user->user, irc->user->host, irc->user->nick,
+ changes );
}
-int irc_msgfrom( irc_t *irc, char *nick, char *msg )
-{
- user_t *u = user_find( irc, nick );
- static char *prefix = NULL;
-
- if( !u ) return( 0 );
- if( prefix && *prefix ) g_free( prefix );
-
- if( !u->is_private && nick_cmp( u->nick, irc->mynick ) != 0 )
- {
- int len = strlen( irc->nick) + 3;
- prefix = g_new (char, len );
- g_snprintf( prefix, len, "%s%s", irc->nick, set_getstr( &irc->set, "to_char" ) );
- prefix[len-1] = 0;
- }
- else
- {
- prefix = "";
- }
-
- return( irc_privmsg( irc, u, "PRIVMSG", u->is_private ? irc->nick : irc->channel, prefix, msg ) );
-}
-
-int irc_noticefrom( irc_t *irc, char *nick, char *msg )
-{
- user_t *u = user_find( irc, nick );
-
- if( u )
- return( irc_privmsg( irc, u, "NOTICE", irc->nick, "", msg ) );
- else
- return( 0 );
-}
/* Returns 0 if everything seems to be okay, a number >0 when there was a
timeout. The number returned is the number of seconds we received no
@@ -1324,26 +741,32 @@ static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
return TRUE;
}
-struct groupchat *irc_chat_by_channel( irc_t *irc, char *channel )
+
+static char *set_eval_charset( set_t *set, char *value )
{
- struct groupchat *c;
- account_t *a;
-
- /* This finds the connection which has a conversation which belongs to this channel */
- for( a = irc->accounts; a; a = a->next )
+ irc_t *irc = set->data;
+ GIConv ic, oc;
+
+ if( g_strcasecmp( value, "none" ) == 0 )
+ value = g_strdup( "utf-8" );
+
+ if( ( ic = g_iconv_open( "utf-8", value ) ) == (GIConv) -1 )
{
- if( a->ic == NULL )
- continue;
-
- c = a->ic->groupchats;
- while( c )
- {
- if( c->channel && g_strcasecmp( c->channel, channel ) == 0 )
- return c;
-
- c = c->next;
- }
+ return NULL;
+ }
+ if( ( oc = g_iconv_open( value, "utf-8" ) ) == (GIConv) -1 )
+ {
+ g_iconv_close( ic );
+ return NULL;
}
- return NULL;
+ if( irc->iconv != (GIConv) -1 )
+ g_iconv_close( irc->iconv );
+ if( irc->oconv != (GIConv) -1 )
+ g_iconv_close( irc->oconv );
+
+ irc->iconv = ic;
+ irc->oconv = oc;
+
+ return value;
}
diff --git a/irc.h b/irc.h
index a865bde3..8a40541c 100644
--- a/irc.h
+++ b/irc.h
@@ -4,7 +4,7 @@
* Copyright 2002-2004 Wilmer van der Gaast and others *
\********************************************************************/
-/* The big hairy IRCd part of the project */
+/* The IRC-based UI (for now the only one) */
/*
This program is free software; you can redistribute it and/or modify
@@ -32,12 +32,14 @@
#define IRC_LOGIN_TIMEOUT 60
#define IRC_PING_STRING "PinglBee"
-#define UMODES "abisw"
-#define UMODES_PRIV "Ro"
-#define CMODES "nt"
-#define CMODE "t"
-#define UMODE "s"
-#define CTYPES "&#"
+#define UMODES "abisw" /* Allowed umodes (although they mostly do nothing) */
+#define UMODES_PRIV "Ro" /* Allowed, but not by user directly */
+#define UMODES_KEEP "R" /* Don't allow unsetting using /MODE */
+#define CMODES "nt" /* Allowed modes */
+#define CMODE "t" /* Default mode */
+#define UMODE "s" /* Default mode */
+
+#define CTYPES "&#" /* Valid channel name prefixes */
typedef enum
{
@@ -48,6 +50,8 @@ typedef enum
USTATUS_SHUTDOWN = 8
} irc_status_t;
+struct irc_user;
+
typedef struct irc
{
int fd;
@@ -58,86 +62,150 @@ typedef struct irc
char *readbuffer;
GIConv iconv, oconv;
- int sentbytes;
- time_t oldtime;
+ struct irc_user *root;
+ struct irc_user *user;
+
+ char *last_root_cmd;
- char *nick;
- char *user;
- char *host;
- char *realname;
char *password; /* HACK: Used to save the user's password, but before
logging in, this may contain a password we should
send to identify after USER/NICK are received. */
char umode[8];
- char *myhost;
- char *mynick;
-
- char *channel;
- int c_id;
-
- char is_private; /* Not too nice... */
- char *last_target;
-
struct query *queries;
- struct account *accounts;
GSList *file_transfers;
- struct chat *chatrooms;
- struct __USER *users;
- GHashTable *userhash;
+ GSList *users, *channels;
+ GHashTable *nick_user_hash;
GHashTable *watches;
- struct __NICK *nicks;
- struct set *set;
gint r_watch_source_id;
gint w_watch_source_id;
gint ping_source_id;
+
+ struct bee *b;
} irc_t;
-#include "user.h"
+typedef enum
+{
+ IRC_USER_PRIVATE = 1,
+} irc_user_flags_t;
+
+typedef struct irc_user
+{
+ irc_t *irc;
+
+ char *nick;
+ char *user;
+ char *host;
+ char *fullname;
+
+ /* Nickname in lowercase for case sensitive searches */
+ char *key;
+
+ irc_user_flags_t flags;
+
+ char *sendbuf;
+ int sendbuf_len;
+ guint sendbuf_timer;
+ //int sendbuf_flags;
+
+ struct bee_user *bu;
+
+ const struct irc_user_funcs *f;
+} irc_user_t;
+struct irc_user_funcs
+{
+ gboolean (*privmsg)( irc_user_t *iu, const char *msg );
+};
+
+extern const struct irc_user_funcs irc_user_root_funcs;
+extern const struct irc_user_funcs irc_user_self_funcs;
+
+typedef enum
+{
+ IRC_CHANNEL_JOINED = 1,
+} irc_channel_flags_t;
+
+typedef struct irc_channel
+{
+ irc_t *irc;
+ char *name;
+ char mode[8];
+ int flags;
+
+ char *topic;
+ char *topic_who;
+ time_t topic_time;
+
+ GSList *users;
+ struct set *set;
+
+ const struct irc_channel_funcs *f;
+} irc_channel_t;
+
+struct irc_channel_funcs
+{
+ gboolean (*privmsg)( irc_channel_t *iu, const char *msg );
+};
+
+extern const struct bee_ui_funcs irc_ui_funcs;
+
+/* irc.c */
extern GSList *irc_connection_list;
irc_t *irc_new( int fd );
void irc_abort( irc_t *irc, int immed, char *format, ... ) G_GNUC_PRINTF( 3, 4 );
void irc_free( irc_t *irc );
+void irc_setpass (irc_t *irc, const char *pass);
-void irc_exec( irc_t *irc, char **cmd );
void irc_process( irc_t *irc );
char **irc_parse_line( char *line );
char *irc_build_line( char **cmd );
-void irc_vawrite( irc_t *irc, char *format, va_list params );
void irc_write( irc_t *irc, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
void irc_write_all( int now, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
-void irc_reply( irc_t *irc, int code, char *format, ... ) G_GNUC_PRINTF( 3, 4 );
-G_MODULE_EXPORT int irc_usermsg( irc_t *irc, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
-char **irc_tokenize( char *buffer );
+void irc_vawrite( irc_t *irc, char *format, va_list params );
-void irc_login( irc_t *irc );
int irc_check_login( irc_t *irc );
-void irc_motd( irc_t *irc );
-void irc_names( irc_t *irc, char *channel );
-void irc_topic( irc_t *irc, char *channel );
-void irc_umode_set( irc_t *irc, char *s, int allow_priv );
-void irc_who( irc_t *irc, char *channel );
-void irc_spawn( irc_t *irc, user_t *u );
-void irc_join( irc_t *irc, user_t *u, char *channel );
-void irc_part( irc_t *irc, user_t *u, char *channel );
-void irc_kick( irc_t *irc, user_t *u, char *channel, user_t *kicker );
-void irc_kill( irc_t *irc, user_t *u );
-void irc_invite( irc_t *irc, char *nick, char *channel );
-void irc_whois( irc_t *irc, char *nick );
-void irc_setpass( irc_t *irc, const char *pass ); /* USE WITH CAUTION! */
-
-int irc_send( irc_t *irc, char *nick, char *s, int flags );
-int irc_privmsg( irc_t *irc, user_t *u, char *type, char *to, char *prefix, char *msg );
-int irc_msgfrom( irc_t *irc, char *nick, char *msg );
-int irc_noticefrom( irc_t *irc, char *nick, char *msg );
-
-void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags );
-struct groupchat *irc_chat_by_channel( irc_t *irc, char *channel );
+
+void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv );
+
+/* irc_channel.c */
+irc_channel_t *irc_channel_new( irc_t *irc, const char *name );
+irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name );
+int irc_channel_free( irc_channel_t *ic );
+int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu );
+int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu );
+gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu );
+int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who );
+gboolean irc_channel_name_ok( const char *name );
+
+/* irc_commands.c */
+void irc_exec( irc_t *irc, char **cmd );
+
+/* irc_send.c */
+void irc_send_num( irc_t *irc, int code, char *format, ... ) G_GNUC_PRINTF( 3, 4 );
+void irc_send_login( irc_t *irc );
+void irc_send_motd( irc_t *irc );
+void irc_usermsg( irc_t *irc, char *format, ... );
+void irc_send_join( irc_channel_t *ic, irc_user_t *iu );
+void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason );
+void irc_send_names( irc_channel_t *ic );
+void irc_send_topic( irc_channel_t *ic, gboolean topic_change );
+void irc_send_whois( irc_user_t *iu );
+void irc_send_who( irc_t *irc, GSList *l, const char *channel );
+void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix );
+void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg );
+void irc_send_nick( irc_user_t *iu, const char *new );
+
+/* irc_user.c */
+irc_user_t *irc_user_new( irc_t *irc, const char *nick );
+int irc_user_free( irc_t *irc, const char *nick );
+irc_user_t *irc_user_by_name( irc_t *irc, const char *nick );
+int irc_user_set_nick( irc_user_t *iu, const char *new );
+gint irc_user_cmp( gconstpointer a_, gconstpointer b_ );
#endif
diff --git a/irc_channel.c b/irc_channel.c
new file mode 100644
index 00000000..27f33619
--- /dev/null
+++ b/irc_channel.c
@@ -0,0 +1,160 @@
+ /********************************************************************\
+ * BitlBee -- An IRC to other IM-networks gateway *
+ * *
+ * Copyright 2002-2010 Wilmer van der Gaast and others *
+ \********************************************************************/
+
+/* The IRC-based UI - Representing (virtual) channels. */
+
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License with
+ the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "bitlbee.h"
+
+static const struct irc_channel_funcs control_channel_funcs;
+
+irc_channel_t *irc_channel_new( irc_t *irc, const char *name )
+{
+ irc_channel_t *ic;
+
+ if( strchr( CTYPES, name[0] ) == NULL || !nick_ok( name + 1 ) )
+ return NULL;
+
+ ic = g_new0( irc_channel_t, 1 );
+ ic->f = &control_channel_funcs;
+ ic->irc = irc;
+ ic->name = g_strdup( name );
+ strcpy( ic->mode, CMODE );
+
+ irc_channel_add_user( ic, irc->root );
+
+ irc->channels = g_slist_prepend( irc->channels, ic );
+
+ return ic;
+}
+
+irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name )
+{
+ GSList *l;
+
+ for( l = irc->channels; l; l = l->next )
+ {
+ irc_channel_t *ic = l->data;
+
+ if( name[0] == ic->name[0] && nick_cmp( name + 1, ic->name + 1 ) == 0 )
+ return ic;
+ }
+
+ return NULL;
+}
+
+int irc_channel_free( irc_channel_t *ic )
+{
+ irc_t *irc = ic->irc;
+
+ if( ic->flags & IRC_CHANNEL_JOINED )
+ irc_channel_del_user( ic, irc->user );
+
+ irc->channels = g_slist_remove( irc->channels, ic );
+ g_slist_free( ic->users );
+
+ g_free( ic->name );
+ g_free( ic->topic );
+ g_free( ic );
+
+ return 1;
+}
+
+int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
+{
+ if( irc_channel_has_user( ic, iu ) )
+ return 0;
+
+ ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp );
+
+ if( iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED )
+ {
+ ic->flags |= IRC_CHANNEL_JOINED;
+ irc_send_join( ic, iu );
+ }
+
+ return 1;
+}
+
+int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu )
+{
+ if( !irc_channel_has_user( ic, iu ) )
+ return 0;
+
+ ic->users = g_slist_remove( ic->users, iu );
+
+ if( ic->flags & IRC_CHANNEL_JOINED )
+ irc_send_part( ic, iu, "" );
+
+ if( iu == ic->irc->user )
+ ic->flags &= ~IRC_CHANNEL_JOINED;
+
+ return 1;
+}
+
+/* Currently a fairly stupid one-liner but I fear it's going to get worse. :-) */
+gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu )
+{
+ return g_slist_find( ic->users, iu ) != NULL;
+}
+
+int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *iu )
+{
+ g_free( ic->topic );
+ ic->topic = g_strdup( topic );
+
+ g_free( ic->topic_who );
+ if( iu )
+ ic->topic_who = g_strdup_printf( "%s!%s@%s", iu->nick, iu->user, iu->host );
+ else
+ ic->topic_who = NULL;
+
+ ic->topic_time = time( NULL );
+
+ if( ic->flags & IRC_CHANNEL_JOINED )
+ irc_send_topic( ic, TRUE );
+
+ return 1;
+}
+
+gboolean irc_channel_name_ok( const char *name )
+{
+ return strchr( CTYPES, name[0] ) != NULL && nick_ok( name + 1 );
+}
+
+/* Channel-type dependent functions, for control channels: */
+static gboolean control_channel_privmsg( irc_channel_t *ic, const char *msg )
+{
+ char cmd[strlen(msg)+1];
+
+ g_free( ic->irc->last_root_cmd );
+ ic->irc->last_root_cmd = g_strdup( ic->name );
+
+ strcpy( cmd, msg );
+ root_command_string( ic->irc, cmd );
+
+ return TRUE;
+}
+
+static const struct irc_channel_funcs control_channel_funcs = {
+ control_channel_privmsg,
+};
diff --git a/irc_commands.c b/irc_commands.c
index a417e0d9..57268d07 100644
--- a/irc_commands.c
+++ b/irc_commands.c
@@ -1,7 +1,7 @@
/********************************************************************\
* BitlBee -- An IRC to other IM-networks gateway *
* *
- * Copyright 2002-2006 Wilmer van der Gaast and others *
+ * Copyright 2002-2010 Wilmer van der Gaast and others *
\********************************************************************/
/* IRC commands */
@@ -52,43 +52,42 @@ static void irc_cmd_pass( irc_t *irc, char **cmd )
}
else if( global.conf->auth_pass )
{
- irc_reply( irc, 464, ":Incorrect password" );
+ irc_send_num( irc, 464, ":Incorrect password" );
}
else
{
/* Remember the password and try to identify after USER/NICK. */
- irc_setpass( irc, cmd[1] );
+ /*irc_setpass( irc, cmd[1] ); */
irc_check_login( irc );
}
}
static void irc_cmd_user( irc_t *irc, char **cmd )
{
- irc->user = g_strdup( cmd[1] );
- irc->realname = g_strdup( cmd[4] );
+ irc->user->user = g_strdup( cmd[1] );
+ irc->user->fullname = g_strdup( cmd[4] );
irc_check_login( irc );
}
static void irc_cmd_nick( irc_t *irc, char **cmd )
{
- if( irc->nick )
+ if( irc->user->nick )
{
- irc_reply( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" );
+ irc_send_num( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" );
}
- /* This is not clean, but for now it'll have to be like this... */
- else if( ( nick_cmp( cmd[1], irc->mynick ) == 0 ) || ( nick_cmp( cmd[1], NS_NICK ) == 0 ) )
+ else if( irc_user_by_name( irc, cmd[1] ) )
{
- irc_reply( irc, 433, ":This nick is already in use" );
+ irc_send_num( irc, 433, ":This nick is already in use" );
}
else if( !nick_ok( cmd[1] ) )
{
/* [SH] Invalid characters. */
- irc_reply( irc, 432, ":This nick contains invalid characters" );
+ irc_send_num( irc, 432, ":This nick contains invalid characters" );
}
else
{
- irc->nick = g_strdup( cmd[1] );
+ irc->user->nick = g_strdup( cmd[1] );
irc_check_login( irc );
}
@@ -104,132 +103,168 @@ static void irc_cmd_quit( irc_t *irc, char **cmd )
static void irc_cmd_ping( irc_t *irc, char **cmd )
{
- irc_write( irc, ":%s PONG %s :%s", irc->myhost, irc->myhost, cmd[1]?cmd[1]:irc->myhost );
+ irc_write( irc, ":%s PONG %s :%s", irc->root->host,
+ irc->root->host, cmd[1]?cmd[1]:irc->root->host );
}
-static void irc_cmd_oper( irc_t *irc, char **cmd )
+static void irc_cmd_pong( irc_t *irc, char **cmd )
{
- if( global.conf->oper_pass &&
- ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
- md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
- strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
+ /* We could check the value we get back from the user, but in
+ fact we don't care, we're just happy s/he's still alive. */
+ irc->last_pong = gettime();
+ irc->pinging = 0;
+}
+
+static void irc_cmd_join( irc_t *irc, char **cmd )
+{
+ irc_channel_t *ic;
+
+ if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL )
+ ic = irc_channel_new( irc, cmd[1] );
+
+ if( ic == NULL )
+ irc_send_num( irc, 479, "%s :Invalid channel name", cmd[1] );
+
+ if( ic->flags & IRC_CHANNEL_JOINED )
+ return; /* Dude, you're already there...
+ RFC doesn't have any reply for that though? */
+
+ irc_channel_add_user( ic, irc->user );
+}
+
+static void irc_cmd_names( irc_t *irc, char **cmd )
+{
+ irc_channel_t *ic;
+
+ if( cmd[1] && ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
+ irc_send_names( ic );
+ /* With no args, we should show /names of all chans. Make the code
+ below work well if necessary.
+ else
{
- irc_umode_set( irc, "+o", 1 );
- irc_reply( irc, 381, ":Password accepted" );
+ GSList *l;
+
+ for( l = irc->channels; l; l = l->next )
+ irc_send_names( l->data );
}
- else
+ */
+}
+
+static void irc_cmd_part( irc_t *irc, char **cmd )
+{
+ irc_channel_t *ic;
+
+ if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL )
{
- irc_reply( irc, 432, ":Incorrect password" );
+ irc_send_num( irc, 403, "%s :No such channel", cmd[1] );
}
+ else if( !irc_channel_del_user( ic, irc->user ) )
+ {
+ irc_send_num( irc, 442, "%s :You're not on that channel", cmd[1] );
+ }
+}
+
+static void irc_cmd_whois( irc_t *irc, char **cmd )
+{
+ char *nick = cmd[1];
+ irc_user_t *iu = irc_user_by_name( irc, nick );
+
+ if( iu )
+ irc_send_whois( iu );
+ else
+ irc_send_num( irc, 401, "%s :Nick does not exist", nick );
+}
+
+static void irc_cmd_whowas( irc_t *irc, char **cmd )
+{
+ /* For some reason irssi tries a whowas when whois fails. We can
+ ignore this, but then the user never gets a "user not found"
+ message from irssi which is a bit annoying. So just respond
+ with not-found and irssi users will get better error messages */
+
+ irc_send_num( irc, 406, "%s :Nick does not exist", cmd[1] );
+ irc_send_num( irc, 369, "%s :End of WHOWAS", cmd[1] );
+}
+
+static void irc_cmd_motd( irc_t *irc, char **cmd )
+{
+ irc_send_motd( irc );
}
static void irc_cmd_mode( irc_t *irc, char **cmd )
{
- if( strchr( CTYPES, *cmd[1] ) )
+ if( irc_channel_name_ok( cmd[1] ) )
{
- if( cmd[2] )
+ irc_channel_t *ic;
+
+ if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL )
+ irc_send_num( irc, 403, "%s :No such channel", cmd[1] );
+ else if( cmd[2] )
{
if( *cmd[2] == '+' || *cmd[2] == '-' )
- irc_reply( irc, 477, "%s :Can't change channel modes", cmd[1] );
+ irc_send_num( irc, 477, "%s :Can't change channel modes", cmd[1] );
else if( *cmd[2] == 'b' )
- irc_reply( irc, 368, "%s :No bans possible", cmd[1] );
+ irc_send_num( irc, 368, "%s :No bans possible", cmd[1] );
}
else
- irc_reply( irc, 324, "%s +%s", cmd[1], CMODE );
+ irc_send_num( irc, 324, "%s +%s", cmd[1], ic->mode );
}
else
{
- if( nick_cmp( cmd[1], irc->nick ) == 0 )
+ if( nick_cmp( cmd[1], irc->user->nick ) == 0 )
{
if( cmd[2] )
irc_umode_set( irc, cmd[2], 0 );
else
- irc_reply( irc, 221, "+%s", irc->umode );
+ irc_send_num( irc, 221, "+%s", irc->umode );
}
else
- irc_reply( irc, 502, ":Don't touch their modes" );
+ irc_send_num( irc, 502, ":Don't touch their modes" );
}
}
-static void irc_cmd_names( irc_t *irc, char **cmd )
+static void irc_cmd_who( irc_t *irc, char **cmd )
{
- irc_names( irc, cmd[1]?cmd[1]:irc->channel );
+ char *channel = cmd[1];
+ irc_channel_t *ic;
+
+ if( !channel || *channel == '0' || *channel == '*' || !*channel )
+ irc_send_who( irc, irc->users, "**" );
+ else if( ( ic = irc_channel_by_name( irc, channel ) ) )
+ irc_send_who( irc, ic->users, channel );
+ else
+ irc_send_num( irc, 403, "%s :No such channel", channel );
}
-static void irc_cmd_part( irc_t *irc, char **cmd )
+static void irc_cmd_privmsg( irc_t *irc, char **cmd )
{
- struct groupchat *c;
+ irc_channel_t *ic;
+ irc_user_t *iu;
- if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
+ if( !cmd[2] )
{
- user_t *u = user_find( irc, irc->nick );
-
- /* Not allowed to leave control channel */
- irc_part( irc, u, irc->channel );
- irc_join( irc, u, irc->channel );
+ irc_send_num( irc, 412, ":No text to send" );
}
- else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) )
+ else if( irc_channel_name_ok( cmd[1] ) &&
+ ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
{
- user_t *u = user_find( irc, irc->nick );
-
- irc_part( irc, u, c->channel );
-
- if( c->ic )
- {
- c->joined = 0;
- c->ic->acc->prpl->chat_leave( c );
- }
+ if( ic->f->privmsg )
+ ic->f->privmsg( ic, cmd[2] );
}
- else
+ else if( ( iu = irc_user_by_name( irc, cmd[1] ) ) )
{
- irc_reply( irc, 403, "%s :No such channel", cmd[1] );
+ if( iu->f->privmsg )
+ iu->f->privmsg( iu, cmd[2] );
}
-}
-
-static void irc_cmd_join( irc_t *irc, char **cmd )
-{
- if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
- ; /* Dude, you're already there...
- RFC doesn't have any reply for that though? */
- else if( cmd[1] )
+ else
{
- struct chat *c;
-
- if( strchr( CTYPES, cmd[1][0] ) == NULL || cmd[1][1] == 0 )
- irc_reply( irc, 479, "%s :Invalid channel name", cmd[1] );
- else if( ( c = chat_bychannel( irc, cmd[1] ) ) && c->acc && c->acc->ic )
- chat_join( irc, c, cmd[2] );
- else
- irc_reply( irc, 403, "%s :No such channel", cmd[1] );
+ irc_send_num( irc, 401, "%s :No such nick/channel", cmd[1] );
}
-}
-static void irc_cmd_invite( irc_t *irc, char **cmd )
-{
- char *nick = cmd[1], *channel = cmd[2];
- struct groupchat *c = irc_chat_by_channel( irc, channel );
- user_t *u = user_find( irc, nick );
-
- if( u && c && ( u->ic == c->ic ) )
- if( c->ic && c->ic->acc->prpl->chat_invite )
- {
- c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
- irc_reply( irc, 341, "%s %s", nick, channel );
- return;
- }
-
- irc_reply( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
-}
-static void irc_cmd_privmsg( irc_t *irc, char **cmd )
-{
- if ( !cmd[2] )
+#if 0
+ else if( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 )
{
- irc_reply( irc, 412, ":No text to send" );
- }
- else if ( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 )
- {
- irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] );
}
else
{
@@ -270,38 +305,51 @@ static void irc_cmd_privmsg( irc_t *irc, char **cmd )
}
irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 );
}
+#endif
}
-static void irc_cmd_who( irc_t *irc, char **cmd )
+static void irc_cmd_nickserv( irc_t *irc, char **cmd )
{
- char *channel = cmd[1];
- user_t *u = irc->users;
- struct groupchat *c;
- GList *l;
+ /* [SH] This aliases the NickServ command to PRIVMSG root */
+ /* [TV] This aliases the NS command to PRIVMSG root as well */
+ root_command( irc, cmd + 1 );
+}
+
+
+
+#if 0
+//#if 0
+static void irc_cmd_oper( irc_t *irc, char **cmd )
+{
+ if( global.conf->oper_pass &&
+ ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
+ md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
+ strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
+ {
+ irc_umode_set( irc, "+o", 1 );
+ irc_send_num( irc, 381, ":Password accepted" );
+ }
+ else
+ {
+ irc_send_num( irc, 432, ":Incorrect password" );
+ }
+}
+
+static void irc_cmd_invite( irc_t *irc, char **cmd )
+{
+ char *nick = cmd[1], *channel = cmd[2];
+ struct groupchat *c = irc_chat_by_channel( irc, channel );
+ user_t *u = user_find( irc, nick );
- if( !channel || *channel == '0' || *channel == '*' || !*channel )
- while( u )
- {
- irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", u->online ? irc->channel : "*", u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
- u = u->next;
- }
- else if( g_strcasecmp( channel, irc->channel ) == 0 )
- while( u )
- {
- if( u->online )
- irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
- u = u->next;
- }
- else if( ( c = irc_chat_by_channel( irc, channel ) ) )
- for( l = c->in_room; l; l = l->next )
+ if( u && c && ( u->ic == c->ic ) )
+ if( c->ic && c->ic->acc->prpl->chat_invite )
{
- if( ( u = user_findhandle( c->ic, l->data ) ) )
- irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
+ c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
+ irc_send_num( irc, 341, "%s %s", nick, channel );
+ return;
}
- else if( ( u = user_find( irc, channel ) ) )
- irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
- irc_reply( irc, 315, "%s :End of /WHO list", channel?channel:"**" );
+ irc_send_num( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
}
static void irc_cmd_userhost( irc_t *irc, char **cmd )
@@ -319,9 +367,9 @@ static void irc_cmd_userhost( irc_t *irc, char **cmd )
if( ( u = user_find( irc, cmd[i] ) ) )
{
if( u->online && u->away )
- irc_reply( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host );
+ irc_send_num( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host );
else
- irc_reply( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host );
+ irc_send_num( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host );
}
}
@@ -376,7 +424,7 @@ static void irc_cmd_ison( irc_t *irc, char **cmd )
if( strlen( buff ) > 0 )
buff[strlen(buff)-1] = '\0';
- irc_reply( irc, 303, ":%s", buff );
+ irc_send_num( irc, 303, ":%s", buff );
}
static void irc_cmd_watch( irc_t *irc, char **cmd )
@@ -405,9 +453,9 @@ static void irc_cmd_watch( irc_t *irc, char **cmd )
g_hash_table_insert( irc->watches, nick, nick );
if( u && u->online )
- irc_reply( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "is online" );
+ irc_send_num( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "is online" );
else
- irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" );
+ irc_send_num( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" );
}
else if( cmd[i][0] == '-' )
{
@@ -418,7 +466,7 @@ static void irc_cmd_watch( irc_t *irc, char **cmd )
g_hash_table_remove( irc->watches, okey );
g_free( okey );
- irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
+ irc_send_num( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
}
}
}
@@ -462,7 +510,7 @@ static void irc_cmd_away( irc_t *irc, char **cmd )
j ++;
u->away[j] = 0;
- irc_reply( irc, 306, ":You're now away: %s", u->away );
+ irc_send_num( irc, 306, ":You're now away: %s", u->away );
/* irc_umode_set( irc, irc->myhost, "+a" ); */
}
else
@@ -470,77 +518,15 @@ static void irc_cmd_away( irc_t *irc, char **cmd )
if( u->away ) g_free( u->away );
u->away = NULL;
/* irc_umode_set( irc, irc->myhost, "-a" ); */
- irc_reply( irc, 305, ":Welcome back" );
+ irc_send_num( irc, 305, ":Welcome back" );
}
set_setstr( &irc->set, "away", u->away );
}
-static void irc_cmd_whois( irc_t *irc, char **cmd )
-{
- char *nick = cmd[1];
- user_t *u = user_find( irc, nick );
-
- if( u )
- {
- irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
-
- if( u->ic )
- irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
- u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "",
- u->ic->acc->prpl->name );
- else
- irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
-
- if( !u->online )
- irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" );
- else if( u->away )
- irc_reply( irc, 301, "%s :%s", u->nick, u->away );
- if( u->status_msg )
- irc_reply( irc, 333, "%s :Status: %s", u->nick, u->status_msg );
-
- irc_reply( irc, 318, "%s :End of /WHOIS list", nick );
- }
- else
- {
- irc_reply( irc, 401, "%s :Nick does not exist", nick );
- }
-}
-
-static void irc_cmd_whowas( irc_t *irc, char **cmd )
-{
- /* For some reason irssi tries a whowas when whois fails. We can
- ignore this, but then the user never gets a "user not found"
- message from irssi which is a bit annoying. So just respond
- with not-found and irssi users will get better error messages */
-
- irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] );
- irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] );
-}
-
-static void irc_cmd_nickserv( irc_t *irc, char **cmd )
-{
- /* [SH] This aliases the NickServ command to PRIVMSG root */
- /* [TV] This aliases the NS command to PRIVMSG root as well */
- root_command( irc, cmd + 1 );
-}
-
-static void irc_cmd_motd( irc_t *irc, char **cmd )
-{
- irc_motd( irc );
-}
-
-static void irc_cmd_pong( irc_t *irc, char **cmd )
-{
- /* We could check the value we get back from the user, but in
- fact we don't care, we're just happy he's still alive. */
- irc->last_pong = gettime();
- irc->pinging = 0;
-}
-
static void irc_cmd_version( irc_t *irc, char **cmd )
{
- irc_reply( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU );
+ irc_send_num( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU );
}
static void irc_cmd_completions( irc_t *irc, char **cmd )
@@ -571,8 +557,9 @@ static void irc_cmd_rehash( irc_t *irc, char **cmd )
else
ipc_to_master( cmd );
- irc_reply( irc, 382, "%s :Rehashing", global.conf_file );
+ irc_send_num( irc, 382, "%s :Rehashing", global.conf_file );
}
+#endif
static const command_t irc_commands[] = {
{ "pass", 1, irc_cmd_pass, 0 },
@@ -580,26 +567,27 @@ static const command_t irc_commands[] = {
{ "nick", 1, irc_cmd_nick, 0 },
{ "quit", 0, irc_cmd_quit, 0 },
{ "ping", 0, irc_cmd_ping, 0 },
- { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN },
- { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN },
- { "names", 0, irc_cmd_names, IRC_CMD_LOGGED_IN },
- { "part", 1, irc_cmd_part, IRC_CMD_LOGGED_IN },
+ { "pong", 0, irc_cmd_pong, IRC_CMD_LOGGED_IN },
{ "join", 1, irc_cmd_join, IRC_CMD_LOGGED_IN },
- { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN },
+ { "names", 1, irc_cmd_names, IRC_CMD_LOGGED_IN },
+ { "part", 1, irc_cmd_part, IRC_CMD_LOGGED_IN },
+ { "whois", 1, irc_cmd_whois, IRC_CMD_LOGGED_IN },
+ { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN },
+ { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN },
+ { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN },
+ { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN },
{ "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN },
+ { "nickserv", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN },
+ { "ns", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN },
+#if 0
+ { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN },
+ { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN },
{ "notice", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN },
- { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN },
{ "userhost", 1, irc_cmd_userhost, IRC_CMD_LOGGED_IN },
{ "ison", 1, irc_cmd_ison, IRC_CMD_LOGGED_IN },
{ "watch", 1, irc_cmd_watch, IRC_CMD_LOGGED_IN },
{ "topic", 1, irc_cmd_topic, IRC_CMD_LOGGED_IN },
{ "away", 0, irc_cmd_away, IRC_CMD_LOGGED_IN },
- { "whois", 1, irc_cmd_whois, IRC_CMD_LOGGED_IN },
- { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN },
- { "nickserv", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN },
- { "ns", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN },
- { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN },
- { "pong", 0, irc_cmd_pong, IRC_CMD_LOGGED_IN },
{ "version", 0, irc_cmd_version, IRC_CMD_LOGGED_IN },
{ "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN },
{ "die", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
@@ -609,6 +597,7 @@ static const command_t irc_commands[] = {
{ "rehash", 0, irc_cmd_rehash, IRC_CMD_OPER_ONLY },
{ "restart", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
{ "kill", 2, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
+#endif
{ NULL }
};
@@ -627,19 +616,19 @@ void irc_exec( irc_t *irc, char *cmd[] )
if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
{
- irc_reply( irc, 462, ":Only allowed before logging in" );
+ irc_send_num( irc, 462, ":Only allowed before logging in" );
}
else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
{
- irc_reply( irc, 451, ":Register first" );
+ irc_send_num( irc, 451, ":Register first" );
}
else if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) )
{
- irc_reply( irc, 481, ":Permission denied - You're not an IRC operator" );
+ irc_send_num( irc, 481, ":Permission denied - You're not an IRC operator" );
}
else if( n_arg < irc_commands[i].required_parameters )
{
- irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
+ irc_send_num( irc, 461, "%s :Need more parameters", cmd[0] );
}
else if( irc_commands[i].flags & IRC_CMD_TO_MASTER )
{
@@ -656,5 +645,5 @@ void irc_exec( irc_t *irc, char *cmd[] )
}
if( irc->status >= USTATUS_LOGGED_IN )
- irc_reply( irc, 421, "%s :Unknown command", cmd[0] );
+ irc_send_num( irc, 421, "%s :Unknown command", cmd[0] );
}
diff --git a/irc_im.c b/irc_im.c
new file mode 100644
index 00000000..26d826bd
--- /dev/null
+++ b/irc_im.c
@@ -0,0 +1,215 @@
+ /********************************************************************\
+ * BitlBee -- An IRC to other IM-networks gateway *
+ * *
+ * Copyright 2002-2010 Wilmer van der Gaast and others *
+ \********************************************************************/
+
+/* Some glue to put the IRC and the IM stuff together. */
+
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License with
+ the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "bitlbee.h"
+#include "dcc.h"
+
+/* IM->IRC callbacks */
+
+static const struct irc_user_funcs irc_user_im_funcs;
+
+static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu )
+{
+ irc_user_t *iu;
+ char nick[MAX_NICK_LENGTH+1], *s;
+
+ memset( nick, 0, MAX_NICK_LENGTH + 1 );
+ strcpy( nick, nick_get( bu->ic->acc, bu->handle ) );
+
+ bu->ui_data = iu = irc_user_new( (irc_t*) bee->ui_data, nick );
+ iu->bu = bu;
+
+ if( ( s = strchr( bu->handle, '@' ) ) )
+ {
+ iu->host = g_strdup( s + 1 );
+ iu->user = g_strndup( bu->handle, s - bu->handle );
+ }
+ else if( bu->ic->acc->server )
+ {
+ iu->host = g_strdup( bu->ic->acc->server );
+ iu->user = g_strdup( bu->handle );
+
+ /* s/ /_/ ... important for AOL screennames */
+ for( s = iu->user; *s; s ++ )
+ if( *s == ' ' )
+ *s = '_';
+ }
+ else
+ {
+ iu->host = g_strdup( bu->ic->acc->prpl->name );
+ iu->user = g_strdup( bu->handle );
+ }
+
+ if( set_getbool( &bee->set, "private" ) )
+ iu->flags |= IRC_USER_PRIVATE;
+
+ iu->f = &irc_user_im_funcs;
+ //iu->last_typing_notice = 0;
+
+ return TRUE;
+}
+
+static gboolean bee_irc_user_free( bee_t *bee, bee_user_t *bu )
+{
+ return irc_user_free( bee->ui_data, bu->ui_data );
+}
+
+static gboolean bee_irc_user_status( bee_t *bee, bee_user_t *bu, bee_user_t *old )
+{
+ irc_t *irc = bee->ui_data;
+ irc_channel_t *ic = irc->channels->data; /* For now, just pick the first channel. */
+
+ if( ( bu->flags & BEE_USER_ONLINE ) != ( old->flags & BEE_USER_ONLINE ) )
+ {
+ if( bu->flags & BEE_USER_ONLINE )
+ irc_channel_add_user( ic, (irc_user_t*) bu->ui_data );
+ else
+ irc_channel_del_user( ic, (irc_user_t*) bu->ui_data );
+ }
+
+ return TRUE;
+}
+
+static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at )
+{
+ irc_t *irc = bee->ui_data;
+ irc_channel_t *ic = irc->channels->data;
+ irc_user_t *iu = (irc_user_t *) bu->ui_data;
+ char *dst, *prefix = NULL;
+ char *wrapped;
+
+ if( iu->flags & IRC_USER_PRIVATE )
+ {
+ dst = irc->user->nick;
+ }
+ else
+ {
+ dst = ic->name;
+ prefix = g_strdup_printf( "%s%s", irc->user->nick, set_getstr( &bee->set, "to_char" ) );
+ }
+
+ wrapped = word_wrap( msg, 425 );
+ irc_send_msg( iu, "PRIVMSG", dst, wrapped, prefix );
+
+ g_free( wrapped );
+ g_free( prefix );
+
+ return TRUE;
+}
+
+static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu )
+{
+ irc_user_t *iu = (irc_user_t *) bu->ui_data;
+ irc_t *irc = (irc_t *) bee->ui_data;
+ char *s;
+
+ if( iu->fullname != iu->nick )
+ g_free( iu->fullname );
+ iu->fullname = g_strdup( bu->fullname );
+
+ /* Strip newlines (unlikely, but IRC-unfriendly so they must go)
+ TODO(wilmer): Do the same with away msgs again! */
+ for( s = iu->fullname; *s; s ++ )
+ if( isspace( *s ) ) *s = ' ';
+
+ if( ( bu->ic->flags & OPT_LOGGED_IN ) && set_getbool( &bee->set, "display_namechanges" ) )
+ {
+ char *msg = g_strdup_printf( "<< \002BitlBee\002 - Changed name to `%s' >>", iu->fullname );
+ irc_send_msg( iu, "NOTICE", irc->user->nick, msg, NULL );
+ }
+
+ s = set_getstr( &bu->ic->acc->set, "nick_source" );
+ if( strcmp( s, "handle" ) != 0 )
+ {
+ char *name = g_strdup( bu->fullname );
+
+ if( strcmp( s, "first_name" ) == 0 )
+ {
+ int i;
+ for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
+ name[i] = '\0';
+ }
+
+ imcb_buddy_nick_hint( bu->ic, bu->handle, name );
+
+ g_free( name );
+ }
+
+ return TRUE;
+}
+
+/* File transfers */
+static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size )
+{
+ return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size );
+}
+
+gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft )
+{
+ return dccs_recv_start( ft );
+}
+
+void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft )
+{
+ return dcc_close( ft );
+}
+
+void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file )
+{
+ dcc_file_transfer_t *df = file->priv;
+
+ if( file->bytes_transferred >= file->file_size )
+ dcc_finish( file );
+ else
+ df->proto_finished = TRUE;
+}
+
+const struct bee_ui_funcs irc_ui_funcs = {
+ bee_irc_user_new,
+ bee_irc_user_free,
+ bee_irc_user_fullname,
+ bee_irc_user_status,
+ bee_irc_user_msg,
+
+ bee_irc_ft_in_start,
+ bee_irc_ft_out_start,
+ bee_irc_ft_close,
+ bee_irc_ft_finished,
+};
+
+
+/* IRC->IM calls */
+
+static gboolean bee_irc_user_privmsg( irc_user_t *iu, const char *msg )
+{
+ if( iu->bu )
+ return bee_user_msg( iu->irc->b, iu->bu, msg, 0 );
+ else
+ return FALSE;
+}
+
+static const struct irc_user_funcs irc_user_im_funcs = {
+ bee_irc_user_privmsg,
+};
diff --git a/irc_send.c b/irc_send.c
new file mode 100644
index 00000000..89b10020
--- /dev/null
+++ b/irc_send.c
@@ -0,0 +1,318 @@
+ /********************************************************************\
+ * BitlBee -- An IRC to other IM-networks gateway *
+ * *
+ * Copyright 2002-2010 Wilmer van der Gaast and others *
+ \********************************************************************/
+
+/* The IRC-based UI - Sending responses to commands/etc. */
+
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License with
+ the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "bitlbee.h"
+
+void irc_send_num( irc_t *irc, int code, char *format, ... )
+{
+ char text[IRC_MAX_LINE];
+ va_list params;
+
+ va_start( params, format );
+ g_vsnprintf( text, IRC_MAX_LINE, format, params );
+ va_end( params );
+
+ irc_write( irc, ":%s %03d %s %s", irc->root->host, code, irc->user->nick ? : "*", text );
+}
+
+void irc_send_login( irc_t *irc )
+{
+ irc_send_num( irc, 1, ":Welcome to the BitlBee gateway, %s", irc->user->nick );
+ irc_send_num( irc, 2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->root->host );
+ irc_send_num( irc, 3, ":%s", IRCD_INFO );
+ irc_send_num( irc, 4, "%s %s %s %s", irc->root->host, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES );
+ irc_send_num( irc, 5, "PREFIX=(ov)@+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee "
+ "CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server",
+ CTYPES, CMODES, MAX_NICK_LENGTH - 1 );
+ irc_send_motd( irc );
+
+ irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\n"
+ "If you've never used BitlBee before, please do read the help "
+ "information using the \x02help\x02 command. Lots of FAQs are "
+ "answered there.\n"
+ "If you already have an account on this server, just use the "
+ "\x02identify\x02 command to identify yourself." );
+}
+
+void irc_send_motd( irc_t *irc )
+{
+ int fd;
+
+ fd = open( global.conf->motdfile, O_RDONLY );
+ if( fd == -1 )
+ {
+ irc_send_num( irc, 422, ":We don't need MOTDs." );
+ }
+ else
+ {
+ char linebuf[80]; /* Max. line length for MOTD's is 79 chars. It's what most IRC networks seem to do. */
+ char *add, max;
+ int len;
+
+ linebuf[79] = len = 0;
+ max = sizeof( linebuf ) - 1;
+
+ irc_send_num( irc, 375, ":- %s Message Of The Day - ", irc->root->host );
+ while( read( fd, linebuf + len, 1 ) == 1 )
+ {
+ if( linebuf[len] == '\n' || len == max )
+ {
+ linebuf[len] = 0;
+ irc_send_num( irc, 372, ":- %s", linebuf );
+ len = 0;
+ }
+ else if( linebuf[len] == '%' )
+ {
+ read( fd, linebuf + len, 1 );
+ if( linebuf[len] == 'h' )
+ add = irc->root->host;
+ else if( linebuf[len] == 'v' )
+ add = BITLBEE_VERSION;
+ else if( linebuf[len] == 'n' )
+ add = irc->user->nick;
+ else
+ add = "%";
+
+ strncpy( linebuf + len, add, max - len );
+ while( linebuf[++len] );
+ }
+ else if( len < max )
+ {
+ len ++;
+ }
+ }
+ irc_send_num( irc, 376, ":End of MOTD" );
+ close( fd );
+ }
+}
+
+void irc_usermsg( irc_t *irc, char *format, ... )
+{
+ irc_channel_t *ic;
+ irc_user_t *iu;
+ char text[1024];
+ va_list params;
+
+ va_start( params, format );
+ g_vsnprintf( text, sizeof( text ), format, params );
+ va_end( params );
+
+ if( irc->last_root_cmd &&
+ irc_channel_name_ok( irc->last_root_cmd ) &&
+ ( ic = irc_channel_by_name( irc, irc->last_root_cmd ) ) &&
+ ic->flags & IRC_CHANNEL_JOINED )
+ irc_send_msg( irc->root, "PRIVMSG", irc->last_root_cmd, text, NULL );
+ else if( irc->last_root_cmd &&
+ ( iu = irc_user_by_name( irc, irc->last_root_cmd ) ) &&
+ iu->f == &irc_user_root_funcs )
+ irc_send_msg( iu, "PRIVMSG", irc->user->nick, text, NULL );
+ else
+ {
+ g_free( irc->last_root_cmd );
+ irc->last_root_cmd = NULL;
+
+ irc_send_msg( irc->root, "PRIVMSG", irc->user->nick, text, NULL );
+ }
+
+ /*return( irc_msgfrom( irc, u->nick, text ) );*/
+}
+
+void irc_send_join( irc_channel_t *ic, irc_user_t *iu )
+{
+ irc_t *irc = ic->irc;
+
+ irc_write( irc, ":%s!%s@%s JOIN :%s", iu->nick, iu->user, iu->host, ic->name );
+
+ if( iu == irc->user )
+ {
+ irc_write( irc, ":%s MODE %s +%s", irc->root->host, ic->name, ic->mode );
+ irc_send_names( ic );
+ irc_send_topic( ic, FALSE );
+ }
+}
+
+void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason )
+{
+ irc_write( ic->irc, ":%s!%s@%s PART %s :%s", iu->nick, iu->user, iu->host, ic->name, reason );
+}
+
+void irc_send_names( irc_channel_t *ic )
+{
+ GSList *l;
+ char namelist[385] = "";
+ //char *ops = set_getstr( &ic->irc->b->set, "ops" );
+
+ /* RFCs say there is no error reply allowed on NAMES, so when the
+ channel is invalid, just give an empty reply. */
+ for( l = ic->users; l; l = l->next )
+ {
+ irc_user_t *iu = l->data;
+
+ if( strlen( namelist ) + strlen( iu->nick ) > sizeof( namelist ) - 4 )
+ {
+ irc_send_num( ic->irc, 353, "= %s :%s", ic->name, namelist );
+ *namelist = 0;
+ }
+
+ /*
+ if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) )
+ strcat( namelist, "+" );
+ else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
+ ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) )
+ strcat( namelist, "@" );
+ */
+
+ strcat( namelist, iu->nick );
+ strcat( namelist, " " );
+ }
+
+ if( *namelist )
+ irc_send_num( ic->irc, 353, "= %s :%s", ic->name, namelist );
+
+ irc_send_num( ic->irc, 366, "%s :End of /NAMES list", ic->name );
+}
+
+void irc_send_topic( irc_channel_t *ic, gboolean topic_change )
+{
+ if( topic_change && ic->topic_who )
+ {
+ irc_write( ic->irc, ":%s TOPIC %s :%s", ic->topic_who,
+ ic->name, ic->topic && *ic->topic ? ic->topic : "" );
+ }
+ else if( ic->topic )
+ {
+ irc_send_num( ic->irc, 332, "%s :%s", ic->name, ic->topic );
+ if( ic->topic_who )
+ irc_send_num( ic->irc, 333, "%s %s %d",
+ ic->name, ic->topic_who, (int) ic->topic_time );
+ }
+ else
+ irc_send_num( ic->irc, 331, "%s :No topic for this channel", ic->name );
+}
+
+void irc_send_whois( irc_user_t *iu )
+{
+ irc_t *irc = iu->irc;
+
+ irc_send_num( irc, 311, "%s %s %s * :%s",
+ iu->nick, iu->user, iu->host, iu->fullname );
+
+ if( iu->bu )
+ {
+ bee_user_t *bu = iu->bu;
+
+ irc_send_num( irc, 312, "%s %s.%s :%s network", iu->nick, bu->ic->acc->user,
+ bu->ic->acc->server && *bu->ic->acc->server ? bu->ic->acc->server : "",
+ bu->ic->acc->prpl->name );
+
+ if( bu->status )
+ {
+ if( bu->status_msg )
+ irc_send_num( irc, 301, "%s :%s (%s)", iu->nick, bu->status, bu->status_msg );
+ else
+ irc_send_num( irc, 301, "%s :%s", iu->nick, bu->status );
+ }
+
+ /*
+ if( u->status_msg )
+ irc_send_num( irc, 333, "%s :Status: %s", u->nick, u->status_msg );
+ */
+ }
+ else
+ {
+ irc_send_num( irc, 312, "%s %s :%s", iu->nick, irc->root->host, IRCD_INFO " " BITLBEE_VERSION );
+ }
+
+ irc_send_num( irc, 318, "%s :End of /WHOIS list", iu->nick );
+}
+
+void irc_send_who( irc_t *irc, GSList *l, const char *channel )
+{
+ while( l )
+ {
+ irc_user_t *iu = l->data;
+ /* TODO(wilmer): Restore away/channel information here */
+ irc_send_num( irc, 352, "%s %s %s %s %s %c :0 %s",
+ channel ? : "*", iu->user, iu->host, irc->root->host,
+ iu->nick, 'H', iu->fullname );
+ l = l->next;
+ }
+
+ irc_send_num( irc, 315, "%s :End of /WHO list", channel );
+}
+
+void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix )
+{
+ char last = 0;
+ const char *s = msg, *line = msg;
+ char raw_msg[strlen(msg)+1024];
+
+ while( !last )
+ {
+ if( *s == '\r' && *(s+1) == '\n' )
+ s++;
+ if( *s == '\n' )
+ {
+ last = s[1] == 0;
+ }
+ else
+ {
+ last = s[0] == 0;
+ }
+ if( *s == 0 || *s == '\n' )
+ {
+ if( g_strncasecmp( line, "/me ", 4 ) == 0 && ( !prefix || !*prefix ) &&
+ g_strcasecmp( type, "PRIVMSG" ) == 0 )
+ {
+ strcpy( raw_msg, "\001ACTION " );
+ strncat( raw_msg, line + 4, s - line - 4 );
+ strcat( raw_msg, "\001" );
+ irc_send_msg_raw( iu, type, dst, raw_msg );
+ }
+ else
+ {
+ *raw_msg = '\0';
+ if( prefix && *prefix )
+ strcpy( raw_msg, prefix );
+ strncat( raw_msg, line, s - line );
+ irc_send_msg_raw( iu, type, dst, raw_msg );
+ }
+ line = s + 1;
+ }
+ s ++;
+ }
+}
+
+void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg )
+{
+ irc_write( iu->irc, ":%s!%s@%s %s %s :%s",
+ iu->nick, iu->user, iu->host, type, dst, msg );
+}
+
+void irc_send_nick( irc_user_t *iu, const char *new )
+{
+ irc_write( iu->irc, ":%s!%s@%s NICK %s",
+ iu->nick, iu->user, iu->host, new );
+}
diff --git a/irc_user.c b/irc_user.c
new file mode 100644
index 00000000..8ad20b54
--- /dev/null
+++ b/irc_user.c
@@ -0,0 +1,164 @@
+ /********************************************************************\
+ * BitlBee -- An IRC to other IM-networks gateway *
+ * *
+ * Copyright 2002-2004 Wilmer van der Gaast and others *
+ \********************************************************************/
+
+/* Stuff to handle, save and search IRC buddies */
+
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License with
+ the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "bitlbee.h"
+
+irc_user_t *irc_user_new( irc_t *irc, const char *nick )
+{
+ irc_user_t *iu = g_new0( irc_user_t, 1 );
+
+ iu->irc = irc;
+ iu->nick = g_strdup( nick );
+ iu->user = iu->host = iu->fullname = iu->nick;
+
+ iu->flags = set_getbool( &irc->b->set, "private" ) ? IRC_USER_PRIVATE : 0;
+
+ iu->key = g_strdup( nick );
+ nick_lc( iu->key );
+ /* Using the hash table for speed and irc->users for easy iteration
+ through the list (since the GLib API doesn't have anything sane
+ for that.) */
+ g_hash_table_insert( irc->nick_user_hash, iu->key, iu );
+ irc->users = g_slist_insert_sorted( irc->users, iu, irc_user_cmp );
+
+ return iu;
+}
+
+int irc_user_free( irc_t *irc, const char *nick )
+{
+ irc_user_t *iu;
+ GSList *l;
+
+ if( !( iu = irc_user_by_name( irc, nick ) ) )
+ return 0;
+
+ irc->users = g_slist_remove( irc->users, iu );
+ g_hash_table_remove( irc->nick_user_hash, iu->key );
+
+ for( l = irc->channels; l; l = l->next )
+ irc_channel_del_user( (irc_channel_t*) l->data, iu );
+
+ g_free( iu->nick );
+ if( iu->nick != iu->user ) g_free( iu->user );
+ if( iu->nick != iu->host ) g_free( iu->host );
+ if( iu->nick != iu->fullname ) g_free( iu->fullname );
+ g_free( iu->sendbuf );
+ if( iu->sendbuf_timer ) b_event_remove( iu->sendbuf_timer );
+ g_free( iu->key );
+
+ return 1;
+}
+
+irc_user_t *irc_user_by_name( irc_t *irc, const char *nick )
+{
+ char key[strlen(nick)+1];
+
+ strcpy( key, nick );
+ if( nick_lc( key ) )
+ return g_hash_table_lookup( irc->nick_user_hash, key );
+ else
+ return NULL;
+}
+
+int irc_user_set_nick( irc_user_t *iu, const char *new )
+{
+ irc_t *irc = iu->irc;
+ char key[strlen(new)+1];
+ GSList *cl;
+
+ strcpy( key, new );
+ if( iu == NULL || !nick_lc( key ) || irc_user_by_name( irc, new ) )
+ return 0;
+
+ for( cl = irc->channels; cl; cl = cl->next )
+ {
+ irc_channel_t *ic = cl->data;
+
+ /* Send a NICK update if we're renaming our user, or someone
+ who's in the same channel like our user. */
+ if( iu == irc->user ||
+ ( ( ic->flags & IRC_CHANNEL_JOINED ) &&
+ irc_channel_has_user( ic, iu ) ) )
+ {
+ irc_send_nick( iu, new );
+ break;
+ }
+ }
+
+ irc->users = g_slist_remove( irc->users, iu );
+ g_hash_table_remove( irc->nick_user_hash, iu->key );
+
+ if( iu->nick == iu->user ) iu->user = NULL;
+ if( iu->nick == iu->host ) iu->host = NULL;
+ if( iu->nick == iu->fullname ) iu->fullname = NULL;
+ g_free( iu->nick );
+ iu->nick = g_strdup( new );
+ if( iu->user == NULL ) iu->user = g_strdup( iu->nick );
+ if( iu->host == NULL ) iu->host = g_strdup( iu->nick );
+ if( iu->fullname == NULL ) iu->fullname = g_strdup( iu->nick );
+
+ iu->key = g_strdup( key );
+ g_hash_table_insert( irc->nick_user_hash, iu->key, iu );
+ irc->users = g_slist_insert_sorted( irc->users, iu, irc_user_cmp );
+
+ return 1;
+}
+
+gint irc_user_cmp( gconstpointer a_, gconstpointer b_ )
+{
+ const irc_user_t *a = a_, *b = b_;
+
+ return strcmp( a->key, b->key );
+}
+
+/* User-type dependent functions, for root/NickServ: */
+static gboolean root_privmsg( irc_user_t *iu, const char *msg )
+{
+ char cmd[strlen(msg)+1];
+
+ g_free( iu->irc->last_root_cmd );
+ iu->irc->last_root_cmd = g_strdup( iu->nick );
+
+ strcpy( cmd, msg );
+ root_command_string( iu->irc, cmd );
+
+ return TRUE;
+}
+
+const struct irc_user_funcs irc_user_root_funcs = {
+ root_privmsg,
+};
+
+/* Echo to yourself: */
+static gboolean self_privmsg( irc_user_t *iu, const char *msg )
+{
+ irc_send_msg_raw( iu, "PRIVMSG", iu->nick, msg );
+
+ return TRUE;
+}
+
+const struct irc_user_funcs irc_user_self_funcs = {
+ self_privmsg,
+};
diff --git a/nick.c b/nick.c
index 5d7dc8a9..7188df14 100644
--- a/nick.c
+++ b/nick.c
@@ -77,7 +77,7 @@ char *nick_get( account_t *acc, const char *handle )
*(s++) = 0;
nick_strip( nick );
- if( set_getbool( &acc->irc->set, "lcnicks" ) )
+ if( set_getbool( &acc->bee->set, "lcnicks" ) )
nick_lc( nick );
}
g_free( store_handle );
@@ -91,11 +91,12 @@ char *nick_get( account_t *acc, const char *handle )
void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+1] )
{
+ irc_t *irc = (irc_t*) acc->bee->ui_data;
int inf_protection = 256;
/* Now, find out if the nick is already in use at the moment, and make
subtle changes to make it unique. */
- while( !nick_ok( nick ) || user_find( acc->irc, nick ) )
+ while( !nick_ok( nick ) || irc_user_by_name( irc, nick ) )
{
if( strlen( nick ) < ( MAX_NICK_LENGTH - 1 ) )
{
@@ -111,19 +112,19 @@ void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+
{
int i;
- irc_usermsg( acc->irc, "Warning: Almost had an infinite loop in nick_get()! "
- "This used to be a fatal BitlBee bug, but we tried to fix it. "
- "This message should *never* appear anymore. "
- "If it does, please *do* send us a bug report! "
- "Please send all the following lines in your report:" );
+ irc_usermsg( irc, "Warning: Almost had an infinite loop in nick_get()! "
+ "This used to be a fatal BitlBee bug, but we tried to fix it. "
+ "This message should *never* appear anymore. "
+ "If it does, please *do* send us a bug report! "
+ "Please send all the following lines in your report:" );
- irc_usermsg( acc->irc, "Trying to get a sane nick for handle %s", handle );
+ irc_usermsg( irc, "Trying to get a sane nick for handle %s", handle );
for( i = 0; i < MAX_NICK_LENGTH; i ++ )
- irc_usermsg( acc->irc, "Char %d: %c/%d", i, nick[i], nick[i] );
+ irc_usermsg( irc, "Char %d: %c/%d", i, nick[i], nick[i] );
- irc_usermsg( acc->irc, "FAILED. Returning an insane nick now. Things might break. "
- "Good luck, and please don't forget to paste the lines up here "
- "in #bitlbee on OFTC or in a mail to wilmer@gaast.net" );
+ irc_usermsg( irc, "FAILED. Returning an insane nick now. Things might break. "
+ "Good luck, and please don't forget to paste the lines up here "
+ "in #bitlbee on OFTC or in a mail to wilmer@gaast.net" );
g_snprintf( nick, MAX_NICK_LENGTH + 1, "xx%x", rand() );
diff --git a/protocols/Makefile b/protocols/Makefile
index 18d79e8d..46c73559 100644
--- a/protocols/Makefile
+++ b/protocols/Makefile
@@ -9,7 +9,8 @@
-include ../Makefile.settings
# [SH] Program variables
-objects = nogaim.o
+objects = account.o bee.o bee_ft.o bee_user.o nogaim.o
+
# [SH] The next two lines should contain the directory name (in $(subdirs))
# and the name of the object file, which should be linked into
diff --git a/account.c b/protocols/account.c
index a844d229..0bacea74 100644
--- a/account.c
+++ b/protocols/account.c
@@ -28,26 +28,26 @@
#include "account.h"
#include "chat.h"
-account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass )
+account_t *account_add( bee_t *bee, struct prpl *prpl, char *user, char *pass )
{
account_t *a;
set_t *s;
- if( irc->accounts )
+ if( bee->accounts )
{
- for( a = irc->accounts; a->next; a = a->next );
+ for( a = bee->accounts; a->next; a = a->next );
a = a->next = g_new0( account_t, 1 );
}
else
{
- irc->accounts = a = g_new0 ( account_t, 1 );
+ bee->accounts = a = g_new0 ( account_t, 1 );
}
a->prpl = prpl;
a->user = g_strdup( user );
a->pass = g_strdup( pass );
a->auto_connect = 1;
- a->irc = irc;
+ a->bee = bee;
s = set_add( &a->set, "auto_connect", "true", set_eval_account, a );
s->flags |= ACC_SET_NOSAVE;
@@ -152,7 +152,7 @@ char *set_eval_account( set_t *set, char *value )
return SET_INVALID;
}
-account_t *account_get( irc_t *irc, char *id )
+account_t *account_get( bee_t *bee, char *id )
{
account_t *a, *ret = NULL;
char *handle, *s;
@@ -168,7 +168,7 @@ account_t *account_get( irc_t *irc, char *id )
if( ( proto = find_protocol( id ) ) )
{
- for( a = irc->accounts; a; a = a->next )
+ for( a = bee->accounts; a; a = a->next )
if( a->prpl == proto &&
a->prpl->handle_cmp( handle, a->user ) == 0 )
ret = a;
@@ -185,14 +185,14 @@ account_t *account_get( irc_t *irc, char *id )
if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 )
{
- for( a = irc->accounts; a; a = a->next )
+ for( a = bee->accounts; a; a = a->next )
if( ( nr-- ) == 0 )
return( a );
return( NULL );
}
- for( a = irc->accounts; a; a = a->next )
+ for( a = bee->accounts; a; a = a->next )
{
if( g_strcasecmp( id, a->prpl->name ) == 0 )
{
@@ -213,29 +213,30 @@ account_t *account_get( irc_t *irc, char *id )
return( ret );
}
-void account_del( irc_t *irc, account_t *acc )
+void account_del( bee_t *bee, account_t *acc )
{
account_t *a, *l = NULL;
- struct chat *c, *nc;
if( acc->ic )
/* Caller should have checked, accounts still in use can't be deleted. */
return;
- for( a = irc->accounts; a; a = (l=a)->next )
+ for( a = bee->accounts; a; a = (l=a)->next )
if( a == acc )
{
if( l )
l->next = a->next;
else
- irc->accounts = a->next;
+ bee->accounts = a->next;
- for( c = irc->chatrooms; c; c = nc )
+ /** FIXME
+ for( c = bee->chatrooms; c; c = nc )
{
nc = c->next;
if( acc == c->acc )
- chat_del( irc, c );
+ chat_del( bee, c );
}
+ */
while( a->set )
set_del( &a->set, a->set->key );
@@ -253,7 +254,7 @@ void account_del( irc_t *irc, account_t *acc )
}
}
-void account_on( irc_t *irc, account_t *a )
+void account_on( bee_t *bee, account_t *a )
{
if( a->ic )
{
@@ -267,7 +268,7 @@ void account_on( irc_t *irc, account_t *a )
a->prpl->login( a );
}
-void account_off( irc_t *irc, account_t *a )
+void account_off( bee_t *bee, account_t *a )
{
imc_logout( a->ic, FALSE );
a->ic = NULL;
@@ -335,7 +336,7 @@ char *set_eval_account_reconnect_delay( set_t *set, char *value )
int account_reconnect_delay( account_t *a )
{
- char *setting = set_getstr( &a->irc->set, "auto_reconnect_delay" );
+ char *setting = set_getstr( &a->bee->set, "auto_reconnect_delay" );
struct account_reconnect_delay p;
if( account_reconnect_delay_parse( setting, &p ) )
diff --git a/account.h b/protocols/account.h
index 984dcfe6..be27542e 100644
--- a/account.h
+++ b/protocols/account.h
@@ -41,16 +41,16 @@ typedef struct account
set_t *set;
GHashTable *nicks;
- struct irc *irc;
+ struct bee *bee;
struct im_connection *ic;
struct account *next;
} account_t;
-account_t *account_add( irc_t *irc, struct prpl *prpl, char *user, char *pass );
-account_t *account_get( irc_t *irc, char *id );
-void account_del( irc_t *irc, account_t *acc );
-void account_on( irc_t *irc, account_t *a );
-void account_off( irc_t *irc, account_t *a );
+account_t *account_add( bee_t *bee, struct prpl *prpl, char *user, char *pass );
+account_t *account_get( bee_t *bee, char *id );
+void account_del( bee_t *bee, account_t *acc );
+void account_on( bee_t *bee, account_t *a );
+void account_off( bee_t *bee, account_t *a );
char *set_eval_account( set_t *set, char *value );
char *set_eval_account_reconnect_delay( set_t *set, char *value );
diff --git a/protocols/bee.c b/protocols/bee.c
new file mode 100644
index 00000000..3f576b0b
--- /dev/null
+++ b/protocols/bee.c
@@ -0,0 +1,47 @@
+#include "bitlbee.h"
+
+bee_t *bee_new()
+{
+ bee_t *b = g_new0( bee_t, 1 );
+ set_t *s;
+
+ s = set_add( &b->set, "away", NULL, NULL/*set_eval_away_status*/, b );
+ s->flags |= SET_NULL_OK;
+ s = set_add( &b->set, "auto_connect", "true", set_eval_bool, b );
+ s = set_add( &b->set, "auto_reconnect", "true", set_eval_bool, b );
+ s = set_add( &b->set, "auto_reconnect_delay", "5*3<900", NULL/*set_eval_account_reconnect_delay*/, b );
+ s = set_add( &b->set, "debug", "false", set_eval_bool, b );
+ s = set_add( &b->set, "password", NULL, NULL/*set_eval_password*/, b );
+ s->flags |= SET_NULL_OK;
+ s = set_add( &b->set, "save_on_quit", "true", set_eval_bool, b );
+ s = set_add( &b->set, "status", NULL, NULL/*set_eval_away_status*/, b );
+ s->flags |= SET_NULL_OK;
+ s = set_add( &b->set, "strip_html", "true", NULL, b );
+
+ return b;
+}
+
+void bee_free( bee_t *b )
+{
+ account_t *acc = b->accounts;
+
+ while( acc )
+ {
+ if( acc->ic )
+ imc_logout( acc->ic, FALSE );
+ else if( acc->reconnect )
+ cancel_auto_reconnect( acc );
+
+ if( acc->ic == NULL )
+ account_del( b, acc );
+ else
+ /* Nasty hack, but account_del() doesn't work in this
+ case and we don't want infinite loops, do we? ;-) */
+ acc = acc->next;
+ }
+
+ while( b->set )
+ set_del( &b->set, b->set->key );
+
+ g_free( b );
+}
diff --git a/protocols/bee.h b/protocols/bee.h
new file mode 100644
index 00000000..6f896c51
--- /dev/null
+++ b/protocols/bee.h
@@ -0,0 +1,102 @@
+ /********************************************************************\
+ * BitlBee -- An IRC to other IM-networks gateway *
+ * *
+ * Copyright 2002-2010 Wilmer van der Gaast and others *
+ \********************************************************************/
+
+/* Stuff to handle, save and search buddies */
+
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License with
+ the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef __BEE_H__
+#define __BEE_H__
+
+struct bee_ui_funcs;
+
+typedef struct bee
+{
+ struct set *set;
+
+ GSList *users;
+ struct account *accounts; /* TODO(wilmer): Use GSList here too? */
+
+ const struct bee_ui_funcs *ui;
+ void *ui_data;
+} bee_t;
+
+bee_t *bee_new();
+void bee_free( bee_t *b );
+
+typedef enum
+{
+ BEE_USER_ONLINE = 1, /* Compatibility with old OPT_LOGGED_IN flag */
+ BEE_USER_AWAY = 4, /* Compatibility with old OPT_AWAY flag */
+} bee_user_flags_t;
+
+typedef struct bee_user
+{
+ struct im_connection *ic;
+ char *handle;
+ char *fullname;
+ char *group;
+
+ bee_user_flags_t flags;
+ char *status;
+ char *status_msg;
+
+ bee_t *bee;
+ void *ui_data;
+} bee_user_t;
+
+typedef struct bee_ui_funcs
+{
+ gboolean (*user_new)( bee_t *bee, struct bee_user *bu );
+ gboolean (*user_free)( bee_t *bee, struct bee_user *bu );
+ gboolean (*user_fullname)( bee_t *bee, bee_user_t *bu );
+ gboolean (*user_status)( bee_t *bee, struct bee_user *bu, struct bee_user *old );
+ gboolean (*user_msg)( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at );
+
+ struct file_transfer* (*ft_in_start)( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size );
+ gboolean (*ft_out_start)( struct im_connection *ic, struct file_transfer *ft );
+ void (*ft_close)( struct im_connection *ic, struct file_transfer *ft );
+ void (*ft_finished)( struct im_connection *ic, struct file_transfer *ft );
+} bee_ui_funcs_t;
+
+
+/* bee.c */
+bee_t *bee_new();
+void bee_free( bee_t *b );
+
+/* bee_user.c */
+bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle );
+int bee_user_free( bee_t *bee, struct im_connection *ic, const char *handle );
+bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle );
+int bee_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, int flags );
+
+/* Callbacks from IM modules to core: */
+/* Buddy activity */
+/* To manipulate the status of a handle.
+ * - flags can be |='d with OPT_* constants. You will need at least:
+ * OPT_LOGGED_IN and OPT_AWAY.
+ * - 'state' and 'message' can be NULL */
+G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message );
+/* Not implemented yet! */ G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle );
+/* Call when a handle says something. 'flags' and 'sent_at may be just 0. */
+G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, guint32 flags, time_t sent_at );
+
+#endif /* __BEE_H__ */
diff --git a/protocols/bee_ft.c b/protocols/bee_ft.c
new file mode 100644
index 00000000..1026eab3
--- /dev/null
+++ b/protocols/bee_ft.c
@@ -0,0 +1,66 @@
+/********************************************************************\
+* BitlBee -- An IRC to other IM-networks gateway *
+* *
+* Copyright 2010 Wilmer van der Gaast <wilmer@gaast.net> *
+\********************************************************************/
+
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License with
+ the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#define BITLBEE_CORE
+#include "bitlbee.h"
+#include "ft.h"
+
+file_transfer_t *imcb_file_send_start( struct im_connection *ic, char *handle, char *file_name, size_t file_size )
+{
+ bee_t *bee = ic->bee;
+ bee_user_t *bu = bee_user_by_handle( bee, ic, handle );
+
+ if( bee->ui->ft_in_start )
+ return bee->ui->ft_in_start( bee, bu, file_name, file_size );
+ else
+ return NULL;
+}
+
+gboolean imcb_file_recv_start( struct im_connection *ic, file_transfer_t *ft )
+{
+ bee_t *bee = ic->bee;
+
+ if( bee->ui->ft_out_start )
+ return bee->ui->ft_out_start( ic, ft );
+ else
+ return FALSE;
+}
+
+void imcb_file_canceled( struct im_connection *ic, file_transfer_t *file, char *reason )
+{
+ bee_t *bee = ic->bee;
+
+ if( file->canceled )
+ file->canceled( file, reason );
+
+ if( bee->ui->ft_close )
+ bee->ui->ft_close( ic, file );
+}
+
+void imcb_file_finished( struct im_connection *ic, file_transfer_t *file )
+{
+ bee_t *bee = ic->bee;
+
+ if( bee->ui->ft_finished )
+ bee->ui->ft_finished( ic, file );
+}
diff --git a/protocols/bee_user.c b/protocols/bee_user.c
new file mode 100644
index 00000000..20c760a9
--- /dev/null
+++ b/protocols/bee_user.c
@@ -0,0 +1,197 @@
+ /********************************************************************\
+ * BitlBee -- An IRC to other IM-networks gateway *
+ * *
+ * Copyright 2002-2010 Wilmer van der Gaast and others *
+ \********************************************************************/
+
+/* Stuff to handle, save and search buddies */
+
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License with
+ the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#define BITLBEE_CORE
+#include "bitlbee.h"
+
+bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *handle )
+{
+ bee_user_t *bu;
+
+ if( bee_user_by_handle( bee, ic, handle ) != NULL )
+ return NULL;
+
+ bu = g_new0( bee_user_t, 1 );
+ bu->bee = bee;
+ bu->ic = ic;
+ bu->handle = g_strdup( handle );
+ bee->users = g_slist_prepend( bee->users, bu );
+
+ if( bee->ui->user_new )
+ bee->ui->user_new( bee, bu );
+
+ return bu;
+}
+
+int bee_user_free( bee_t *bee, struct im_connection *ic, const char *handle )
+{
+ bee_user_t *bu;
+
+ if( ( bu = bee_user_by_handle( bee, ic, handle ) ) == NULL )
+ return 0;
+
+ if( bee->ui->user_free )
+ bee->ui->user_free( bee, bu );
+
+ g_free( bu->handle );
+ g_free( bu->fullname );
+ g_free( bu->group );
+ g_free( bu->status );
+ g_free( bu->status_msg );
+
+ bee->users = g_slist_remove( bee->users, bu );
+
+ return 1;
+}
+
+bee_user_t *bee_user_by_handle( bee_t *bee, struct im_connection *ic, const char *handle )
+{
+ GSList *l;
+
+ for( l = bee->users; l; l = l->next )
+ {
+ bee_user_t *bu = l->data;
+
+ if( bu->ic == ic && ic->acc->prpl->handle_cmp( bu->handle, handle ) == 0 )
+ return bu;
+ }
+
+ return NULL;
+}
+
+int bee_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, int flags )
+{
+ char *buf = NULL;
+ int st;
+
+ if( ( bu->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
+ {
+ buf = escape_html( msg );
+ msg = buf;
+ }
+ else
+ buf = g_strdup( msg );
+
+ st = bu->ic->acc->prpl->buddy_msg( bu->ic, bu->handle, buf, flags );
+ g_free( buf );
+
+ return st;
+}
+
+
+/* IM->UI callbacks */
+void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message )
+{
+ bee_t *bee = ic->bee;
+ bee_user_t *bu, *old;
+
+ if( !( bu = bee_user_by_handle( bee, ic, handle ) ) )
+ {
+ if( g_strcasecmp( set_getstr( &ic->bee->set, "handle_unknown" ), "add" ) == 0 )
+ {
+ bu = bee_user_new( bee, ic, handle );
+ }
+ else
+ {
+ if( g_strcasecmp( set_getstr( &ic->bee->set, "handle_unknown" ), "ignore" ) != 0 )
+ {
+ imcb_log( ic, "imcb_buddy_status() for unknown handle %s:\n"
+ "flags = %d, state = %s, message = %s", handle, flags,
+ state ? state : "NULL", message ? message : "NULL" );
+ }
+
+ return;
+ }
+ }
+
+ /* May be nice to give the UI something to compare against. */
+ old = g_memdup( bu, sizeof( bee_user_t ) );
+
+ /* TODO(wilmer): OPT_AWAY, or just state == NULL ? */
+ bu->flags = flags;
+ bu->status = g_strdup( ( flags & OPT_AWAY ) && state == NULL ? "Away" : state );
+ bu->status_msg = g_strdup( message );
+
+ if( bee->ui->user_status )
+ bee->ui->user_status( bee, bu, old );
+
+ g_free( old->status_msg );
+ g_free( old->status );
+ g_free( old );
+#if 0
+ /* LISPy... */
+ if( ( set_getbool( &ic->bee->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */
+ ( u->online ) && /* Don't touch offline people */
+ ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */
+ ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */
+ {
+ char *from;
+
+ if( set_getbool( &ic->bee->set, "simulate_netsplit" ) )
+ {
+ from = g_strdup( ic->irc->myhost );
+ }
+ else
+ {
+ from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick,
+ ic->irc->myhost );
+ }
+ irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
+ u->away?'-':'+', u->nick );
+ g_free( from );
+ }
+#endif
+}
+
+void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
+{
+ bee_t *bee = ic->bee;
+ bee_user_t *bu;
+
+ bu = bee_user_by_handle( bee, ic, handle );
+
+ if( !bu )
+ {
+ char *h = set_getstr( &bee->set, "handle_unknown" );
+
+ if( g_strcasecmp( h, "ignore" ) == 0 )
+ {
+ return;
+ }
+ else if( g_strncasecmp( h, "add", 3 ) == 0 )
+ {
+ bu = bee_user_new( bee, ic, handle );
+ }
+ }
+
+ if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||
+ ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )
+ strip_html( msg );
+
+ if( bee->ui->user_msg && bu )
+ bee->ui->user_msg( bee, bu, msg, sent_at );
+ else
+ imcb_log( ic, "Message from unknown handle %s:\n%s", handle, msg );
+}
diff --git a/chat.c b/protocols/chat.c
index 8c5ce0bc..8c5ce0bc 100644
--- a/chat.c
+++ b/protocols/chat.c
diff --git a/chat.h b/protocols/chat.h
index 7196aea8..7196aea8 100644
--- a/chat.h
+++ b/protocols/chat.h
diff --git a/protocols/ft.h b/protocols/ft.h
index 1155f06f..c1ee2b49 100644
--- a/protocols/ft.h
+++ b/protocols/ft.h
@@ -167,9 +167,9 @@ file_transfer_t *imcb_file_send_start( struct im_connection *ic, char *user_nick
* This should be called by a protocol when the transfer is canceled. Note that
* the canceled() and free() callbacks given in file will be called by this function.
*/
-void imcb_file_canceled( file_transfer_t *file, char *reason );
+void imcb_file_canceled( struct im_connection *ic, file_transfer_t *file, char *reason );
-gboolean imcb_file_recv_start( file_transfer_t *ft );
+gboolean imcb_file_recv_start( struct im_connection *ic, file_transfer_t *ft );
-void imcb_file_finished( file_transfer_t *file );
+void imcb_file_finished( struct im_connection *ic, file_transfer_t *file );
#endif
diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c
index f5fbdc13..bdedeb08 100644
--- a/protocols/jabber/iq.c
+++ b/protocols/jabber/iq.c
@@ -391,7 +391,7 @@ static xt_status jabber_parse_roster( struct im_connection *ic, struct xt_node *
{
if( ( strcmp( sub, "both" ) == 0 || strcmp( sub, "to" ) == 0 ) )
{
- if( initial || imcb_find_buddy( ic, jid ) == NULL )
+ if( initial || bee_user_by_handle( ic->bee, ic, jid ) == NULL )
imcb_add_buddy( ic, jid, ( group && group->text_len ) ?
group->text : NULL );
@@ -589,7 +589,7 @@ static xt_status jabber_add_to_roster_callback( struct im_connection *ic, struct
( s = xt_find_attr( node, "type" ) ) &&
strcmp( s, "result" ) == 0 )
{
- if( imcb_find_buddy( ic, jid ) == NULL )
+ if( bee_user_by_handle( ic->bee, ic, jid ) == NULL )
imcb_add_buddy( ic, jid, NULL );
}
else
diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c
index 956769b7..acad525e 100644
--- a/protocols/jabber/jabber.c
+++ b/protocols/jabber/jabber.c
@@ -266,7 +266,7 @@ static void jabber_logout( struct im_connection *ic )
struct jabber_data *jd = ic->proto_data;
while( jd->filetransfers )
- imcb_file_canceled( ( ( struct jabber_transfer *) jd->filetransfers->data )->ft, "Logging out" );
+ imcb_file_canceled( ic, ( ( struct jabber_transfer *) jd->filetransfers->data )->ft, "Logging out" );
while( jd->streamhosts )
{
diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c
index bd2fbe8c..6f58f124 100644
--- a/protocols/jabber/jabber_util.c
+++ b/protocols/jabber/jabber_util.c
@@ -278,8 +278,7 @@ static void jabber_buddy_ask_yes( void *data )
presence_send_request( bla->ic, bla->handle, "subscribed" );
- if( imcb_find_buddy( bla->ic, bla->handle ) == NULL )
- imcb_ask_add( bla->ic, bla->handle, NULL );
+ imcb_ask_add( bla->ic, bla->handle, NULL );
g_free( bla->handle );
g_free( bla );
@@ -461,7 +460,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,
}
if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
- ( bare_exists || imcb_find_buddy( ic, jid ) ) )
+ ( bare_exists || bee_user_by_handle( ic->bee, ic, jid ) ) )
{
*s = '/';
bud = jabber_buddy_add( ic, jid );
@@ -482,7 +481,8 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,
if( bud == NULL )
/* No match. Create it now? */
- return ( ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid_ ) ) ?
+ return ( ( flags & GET_BUDDY_CREAT ) &&
+ bee_user_by_handle( ic->bee, ic, jid_ ) ) ?
jabber_buddy_add( ic, jid_ ) : NULL;
else if( bud->resource && ( flags & GET_BUDDY_EXACT ) )
/* We want an exact match, so in thise case there shouldn't be a /resource. */
diff --git a/protocols/jabber/s5bytestream.c b/protocols/jabber/s5bytestream.c
index 36a2e438..7d993529 100644
--- a/protocols/jabber/s5bytestream.c
+++ b/protocols/jabber/s5bytestream.c
@@ -566,7 +566,7 @@ gboolean jabber_bs_recv_handshake_abort( struct bs_transfer *bt, char *error )
imcb_log( tf->ic, "WARNING: Error transmitting bytestream response" );
xt_free_node( reply );
- imcb_file_canceled( tf->ft, "couldn't connect to any streamhosts" );
+ imcb_file_canceled( tf->ic, tf->ft, "couldn't connect to any streamhosts" );
bt->tf->watch_in = 0;
/* MUST always return FALSE! */
@@ -603,7 +603,7 @@ void jabber_bs_recv_answer_request( struct bs_transfer *bt )
xt_add_attr( reply, "id", tf->iq_id );
if( !jabber_write_packet( tf->ic, reply ) )
- imcb_file_canceled( tf->ft, "Error transmitting bytestream response" );
+ imcb_file_canceled( tf->ic, tf->ft, "Error transmitting bytestream response" );
xt_free_node( reply );
}
@@ -643,7 +643,7 @@ gboolean jabber_bs_recv_read( gpointer data, gint fd, b_input_condition cond )
tf->bytesread += ret;
if( tf->bytesread >= tf->ft->file_size )
- imcb_file_finished( tf->ft );
+ imcb_file_finished( tf->ic, tf->ft );
tf->ft->write( tf->ft, tf->ft->buffer, ret );
@@ -659,7 +659,7 @@ gboolean jabber_bs_recv_write_request( file_transfer_t *ft )
if( tf->watch_in )
{
- imcb_file_canceled( ft, "BUG in jabber file transfer: write_request called when already watching for input" );
+ imcb_file_canceled( tf->ic, ft, "BUG in jabber file transfer: write_request called when already watching for input" );
return FALSE;
}
@@ -705,7 +705,7 @@ gboolean jabber_bs_send_write( file_transfer_t *ft, char *buffer, unsigned int l
return jabber_bs_abort( bt, "send() sent %d instead of %d (send buffer too big!)", ret, len );
if( tf->byteswritten >= ft->file_size )
- imcb_file_finished( ft );
+ imcb_file_finished( tf->ic, ft );
else
bt->tf->watch_out = b_input_add( tf->fd, GAIM_INPUT_WRITE, jabber_bs_send_can_write, bt );
@@ -1005,7 +1005,7 @@ gboolean jabber_bs_send_request( struct jabber_transfer *tf, GSList *streamhosts
jabber_cache_add( tf->ic, iq, jabber_bs_send_handle_reply );
if( !jabber_write_packet( tf->ic, iq ) )
- imcb_file_canceled( tf->ft, "Error transmitting bytestream request" );
+ imcb_file_canceled( tf->ic, tf->ft, "Error transmitting bytestream request" );
return TRUE;
}
@@ -1020,7 +1020,7 @@ gboolean jabber_bs_send_handshake_abort(struct bs_transfer *bt, char *error )
error );
if( jd->streamhosts==NULL ) /* we're done here unless we have a proxy to try */
- imcb_file_canceled( tf->ft, error );
+ imcb_file_canceled( tf->ic, tf->ft, error );
/* MUST always return FALSE! */
return FALSE;
diff --git a/protocols/jabber/si.c b/protocols/jabber/si.c
index bfb64f11..58c0e17f 100644
--- a/protocols/jabber/si.c
+++ b/protocols/jabber/si.c
@@ -90,11 +90,11 @@ int jabber_si_check_features( struct jabber_transfer *tf, GSList *features ) {
}
if( !foundft )
- imcb_file_canceled( tf->ft, "Buddy's client doesn't feature file transfers" );
+ imcb_file_canceled( tf->ic, tf->ft, "Buddy's client doesn't feature file transfers" );
else if( !foundbt )
- imcb_file_canceled( tf->ft, "Buddy's client doesn't feature byte streams (required)" );
+ imcb_file_canceled( tf->ic, tf->ft, "Buddy's client doesn't feature byte streams (required)" );
else if( !foundsi )
- imcb_file_canceled( tf->ft, "Buddy's client doesn't feature stream initiation (required)" );
+ imcb_file_canceled( tf->ic, tf->ft, "Buddy's client doesn't feature stream initiation (required)" );
return foundft && foundbt && foundsi;
}
@@ -108,7 +108,7 @@ void jabber_si_transfer_start( struct jabber_transfer *tf ) {
jabber_si_send_request( tf->ic, tf->bud->full_jid, tf );
/* and start the receive logic */
- imcb_file_recv_start( tf->ft );
+ imcb_file_recv_start( tf->ic, tf->ft );
}
@@ -155,7 +155,7 @@ void jabber_si_transfer_request( struct im_connection *ic, file_transfer_t *ft,
if( bud == NULL )
{
- imcb_file_canceled( ft, "Couldn't find buddy (BUG?)" );
+ imcb_file_canceled( ic, ft, "Couldn't find buddy (BUG?)" );
return;
}
diff --git a/protocols/msn/Makefile b/protocols/msn/Makefile
index 5d199b9e..6a588613 100644
--- a/protocols/msn/Makefile
+++ b/protocols/msn/Makefile
@@ -9,7 +9,7 @@
-include ../../Makefile.settings
# [SH] Program variables
-objects = invitation.o msn.o msn_util.o ns.o passport.o sb.o tables.o
+objects = msn.o msn_util.o ns.o passport.o sb.o tables.o
CFLAGS += -Wall
LFLAGS += -r
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c
index 3a8b8f7b..8b73f103 100644
--- a/protocols/msn/msn.c
+++ b/protocols/msn/msn.c
@@ -80,9 +80,11 @@ static void msn_logout( struct im_connection *ic )
if( md )
{
+ /** Disabling MSN ft support for now.
while( md->filetransfers ) {
imcb_file_canceled( md->filetransfers->data, "Closing connection" );
}
+ */
if( md->fd >= 0 )
closesocket( md->fd );
@@ -343,7 +345,7 @@ void msn_initmodule()
ret->rem_deny = msn_rem_deny;
ret->send_typing = msn_send_typing;
ret->handle_cmp = g_strcasecmp;
- ret->transfer_request = msn_ftp_transfer_request;
+ //ret->transfer_request = msn_ftp_transfer_request;
register_protocol(ret);
}
diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c
index 668a8b8a..f85981e5 100644
--- a/protocols/msn/msn_util.c
+++ b/protocols/msn/msn_util.c
@@ -95,8 +95,7 @@ static void msn_buddy_ask_yes( void *data )
msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname );
- if( imcb_find_buddy( bla->ic, bla->handle ) == NULL )
- imcb_ask_add( bla->ic, bla->handle, NULL );
+ imcb_ask_add( bla->ic, bla->handle, NULL );
g_free( bla->handle );
g_free( bla->realname );
diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c
index c3302e57..a935ce97 100644
--- a/protocols/msn/sb.c
+++ b/protocols/msn/sb.c
@@ -690,6 +690,8 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int
/* PANIC! */
}
}
+#if 0
+ // Disable MSN ft support for now.
else if( g_strncasecmp( ct, "text/x-msmsgsinvite", 19 ) == 0 )
{
char *command = msn_findheader( body, "Invitation-Command:", blen );
@@ -722,6 +724,7 @@ static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int
g_free( command );
}
+#endif
else if( g_strncasecmp( ct, "application/x-msnmsgrp2p", 24 ) == 0 )
{
imcb_error( sb->ic, "Cannot receive file from %s: BitlBee does not "
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index c326e378..4521eb32 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -37,8 +37,6 @@
#include "nogaim.h"
#include "chat.h"
-static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
-
GSList *connections;
#ifdef WITH_PLUGINS
@@ -91,8 +89,6 @@ void load_plugins(void)
}
#endif
-/* nogaim.c */
-
GList *protocols = NULL;
void register_protocol (struct prpl *p)
@@ -124,7 +120,6 @@ struct prpl *find_protocol(const char *name)
return NULL;
}
-/* nogaim.c */
void nogaim_init()
{
extern void msn_initmodule();
@@ -155,15 +150,13 @@ void nogaim_init()
GSList *get_connections() { return connections; }
-/* multi.c */
-
struct im_connection *imcb_new( account_t *acc )
{
struct im_connection *ic;
ic = g_new0( struct im_connection, 1 );
- ic->irc = acc->irc;
+ ic->bee = acc->bee;
ic->acc = acc;
acc->ic = ic;
@@ -177,7 +170,7 @@ void imc_free( struct im_connection *ic )
account_t *a;
/* Destroy the pointer to this connection from the account list */
- for( a = ic->irc->accounts; a; a = a->next )
+ for( a = ic->bee->accounts; a; a = a->next )
if( a->ic == ic )
{
a->ic = NULL;
@@ -198,20 +191,21 @@ static void serv_got_crap( struct im_connection *ic, char *format, ... )
text = g_strdup_vprintf( format, params );
va_end( params );
- if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
- ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
+ if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||
+ ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )
strip_html( text );
/* Try to find a different connection on the same protocol. */
- for( a = ic->irc->accounts; a; a = a->next )
+ for( a = ic->bee->accounts; a; a = a->next )
if( a->prpl == ic->acc->prpl && a->ic != ic )
break;
/* If we found one, include the screenname in the message. */
if( a )
- irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text );
+ /* FIXME(wilmer): ui_log callback or so */
+ irc_usermsg( ic->bee->ui_data, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text );
else
- irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text );
+ irc_usermsg( ic->bee->ui_data, "%s - %s", ic->acc->prpl->name, text );
g_free( text );
}
@@ -262,18 +256,12 @@ static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond )
void imcb_connected( struct im_connection *ic )
{
- irc_t *irc = ic->irc;
- struct chat *c;
- user_t *u;
-
/* MSN servers sometimes redirect you to a different server and do
the whole login sequence again, so these "late" calls to this
function should be handled correctly. (IOW, ignored) */
if( ic->flags & OPT_LOGGED_IN )
return;
- u = user_find( ic->irc, ic->irc->nick );
-
imcb_log( ic, "Logged in" );
ic->keepalive = b_timeout_add( 60000, send_keepalive, ic );
@@ -286,6 +274,7 @@ void imcb_connected( struct im_connection *ic )
exponential backoff timer. */
ic->acc->auto_reconnect_delay = 0;
+ /*
for( c = irc->chatrooms; c; c = c->next )
{
if( c->acc != ic->acc )
@@ -294,6 +283,7 @@ void imcb_connected( struct im_connection *ic )
if( set_getbool( &c->set, "auto_join" ) )
chat_join( irc, c, NULL );
}
+ */
}
gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond )
@@ -301,7 +291,7 @@ gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond )
account_t *a = data;
a->reconnect = 0;
- account_on( a->irc, a );
+ account_on( a->bee, a );
return( FALSE ); /* Only have to run the timeout once */
}
@@ -314,9 +304,9 @@ void cancel_auto_reconnect( account_t *a )
void imc_logout( struct im_connection *ic, int allow_reconnect )
{
- irc_t *irc = ic->irc;
- user_t *t, *u;
+ bee_t *bee = ic->bee;
account_t *a;
+ GSList *l;
int delay;
/* Nested calls might happen sometimes, this is probably the best
@@ -336,22 +326,17 @@ void imc_logout( struct im_connection *ic, int allow_reconnect )
g_free( ic->away );
ic->away = NULL;
- u = irc->users;
- while( u )
+ for( l = bee->users; l; l = l->next )
{
- if( u->ic == ic )
- {
- t = u->next;
- user_del( irc, u->nick );
- u = t;
- }
- else
- u = u->next;
+ bee_user_t *bu = l->data;
+
+ if( bu->ic == ic )
+ bee_user_free( bee, ic, bu->handle );
}
- query_del_by_conn( ic->irc, ic );
+ //query_del_by_conn( ic->irc, ic );
- for( a = irc->accounts; a; a = a->next )
+ for( a = bee->accounts; a; a = a->next )
if( a->ic == ic )
break;
@@ -359,7 +344,7 @@ void imc_logout( struct im_connection *ic, int allow_reconnect )
{
/* Uhm... This is very sick. */
}
- else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) &&
+ else if( allow_reconnect && set_getbool( &bee->set, "auto_reconnect" ) &&
set_getbool( &a->set, "auto_reconnect" ) &&
( delay = account_reconnect_delay( a ) ) > 0 )
{
@@ -370,27 +355,20 @@ void imc_logout( struct im_connection *ic, int allow_reconnect )
imc_free( ic );
}
-
-/* dialogs.c */
-
void imcb_ask( struct im_connection *ic, char *msg, void *data,
query_callback doit, query_callback dont )
{
- query_add( ic->irc, ic, msg, doit, dont, data );
+ //query_add( ic->irc, ic, msg, doit, dont, data );
}
-
-/* list.c */
-
void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group )
{
- user_t *u;
- char nick[MAX_NICK_LENGTH+1], *s;
- irc_t *irc = ic->irc;
+ bee_user_t *bu;
+ bee_t *bee = ic->bee;
- if( user_findhandle( ic, handle ) )
+ if( bee_user_by_handle( bee, ic, handle ) )
{
- if( set_getbool( &irc->set, "debug" ) )
+ if( set_getbool( &bee->set, "debug" ) )
imcb_log( ic, "User already exists, ignoring add request: %s", handle );
return;
@@ -401,108 +379,37 @@ void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *g
even support groups so let's silently ignore this for now. */
}
- memset( nick, 0, MAX_NICK_LENGTH + 1 );
- strcpy( nick, nick_get( ic->acc, handle ) );
-
- u = user_add( ic->irc, nick );
-
-// if( !realname || !*realname ) realname = nick;
-// u->realname = g_strdup( realname );
-
- if( ( s = strchr( handle, '@' ) ) )
- {
- u->host = g_strdup( s + 1 );
- u->user = g_strndup( handle, s - handle );
- }
- else if( ic->acc->server )
- {
- u->host = g_strdup( ic->acc->server );
- u->user = g_strdup( handle );
-
- /* s/ /_/ ... important for AOL screennames */
- for( s = u->user; *s; s ++ )
- if( *s == ' ' )
- *s = '_';
- }
- else
- {
- u->host = g_strdup( ic->acc->prpl->name );
- u->user = g_strdup( handle );
- }
-
- u->ic = ic;
- u->handle = g_strdup( handle );
- if( group ) u->group = g_strdup( group );
- u->send_handler = buddy_send_handler;
- u->last_typing_notice = 0;
+ bu = bee_user_new( bee, ic, handle );
+ bu->group = g_strdup( group );
}
-struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle )
+void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *fullname )
{
- static struct buddy b[1];
- user_t *u;
-
- u = user_findhandle( ic, handle );
-
- if( !u )
- return( NULL );
+ bee_t *bee = ic->bee;
+ bee_user_t *bu = bee_user_by_handle( bee, ic, handle );
- memset( b, 0, sizeof( b ) );
- strncpy( b->name, handle, 80 );
- strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN );
- b->present = u->online;
- b->ic = u->ic;
+ if( !bu || !fullname ) return;
- return( b );
-}
-
-void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname )
-{
- user_t *u = user_findhandle( ic, handle );
- char *set;
-
- if( !u || !realname ) return;
-
- if( g_strcasecmp( u->realname, realname ) != 0 )
+ if( !bu->fullname || strcmp( bu->fullname, fullname ) != 0 )
{
- if( u->realname != u->nick ) g_free( u->realname );
-
- u->realname = g_strdup( realname );
+ g_free( bu->fullname );
+ bu->fullname = g_strdup( fullname );
- if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) )
- imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );
- }
-
- set = set_getstr( &ic->acc->set, "nick_source" );
- if( strcmp( set, "handle" ) != 0 )
- {
- char *name = g_strdup( realname );
-
- if( strcmp( set, "first_name" ) == 0 )
- {
- int i;
- for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
- name[i] = '\0';
- }
-
- imcb_buddy_nick_hint( ic, handle, name );
-
- g_free( name );
+ if( bee->ui->user_fullname )
+ bee->ui->user_fullname( bee, bu );
}
}
void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group )
{
- user_t *u;
-
- if( ( u = user_findhandle( ic, handle ) ) )
- user_del( ic->irc, u->nick );
+ bee_user_free( ic->bee, ic, handle );
}
/* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM
modules to suggest a nickname for a handle. */
void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick )
{
+#if 0
user_t *u = user_findhandle( ic, handle );
char newnick[MAX_NICK_LENGTH+1], *orig_nick;
@@ -517,7 +424,7 @@ void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const c
/* Some processing to make sure this string is a valid IRC nickname. */
nick_strip( newnick );
- if( set_getbool( &ic->irc->set, "lcnicks" ) )
+ if( set_getbool( &ic->bee->set, "lcnicks" ) )
nick_lc( newnick );
if( strcmp( u->nick, newnick ) != 0 )
@@ -534,6 +441,7 @@ void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const c
g_free( orig_nick );
}
}
+#endif
}
@@ -543,6 +451,7 @@ struct imcb_ask_cb_data
char *handle;
};
+#if 0
static void imcb_ask_auth_cb_no( void *data )
{
struct imcb_ask_cb_data *cbd = data;
@@ -562,9 +471,11 @@ static void imcb_ask_auth_cb_yes( void *data )
g_free( cbd->handle );
g_free( cbd );
}
+#endif
void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname )
{
+#if 0
struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
char *s, *realname_ = NULL;
@@ -579,9 +490,11 @@ void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *re
data->ic = ic;
data->handle = g_strdup( handle );
query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data );
+#endif
}
+#if 0
static void imcb_ask_add_cb_no( void *data )
{
g_free( ((struct imcb_ask_cb_data*)data)->handle );
@@ -596,9 +509,11 @@ static void imcb_ask_add_cb_yes( void *data )
return imcb_ask_add_cb_no( data );
}
+#endif
void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname )
{
+#if 0
struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
char *s;
@@ -611,165 +526,15 @@ void imcb_ask_add( struct im_connection *ic, const char *handle, const char *rea
data->ic = ic;
data->handle = g_strdup( handle );
query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );
-}
-
-
-/* server.c */
-
-void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message )
-{
- user_t *u;
- int oa, oo;
-
- u = user_findhandle( ic, (char*) handle );
-
- if( !u )
- {
- if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 )
- {
- imcb_add_buddy( ic, (char*) handle, NULL );
- u = user_findhandle( ic, (char*) handle );
- }
- else
- {
- if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 )
- {
- imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle );
- imcb_log( ic, "flags = %d, state = %s, message = %s", flags,
- state ? state : "NULL", message ? message : "NULL" );
- }
-
- return;
- }
- }
-
- oa = u->away != NULL;
- oo = u->online;
-
- g_free( u->away );
- g_free( u->status_msg );
- u->away = u->status_msg = NULL;
-
- if( ( flags & OPT_LOGGED_IN ) && !u->online )
- {
- irc_spawn( ic->irc, u );
- u->online = 1;
- }
- else if( !( flags & OPT_LOGGED_IN ) && u->online )
- {
- struct groupchat *c;
-
- irc_kill( ic->irc, u );
- u->online = 0;
-
- /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */
- for( c = ic->groupchats; c; c = c->next )
- remove_chat_buddy_silent( c, handle );
- }
-
- if( flags & OPT_AWAY )
- {
- if( state && message )
- {
- u->away = g_strdup_printf( "%s (%s)", state, message );
- }
- else if( state )
- {
- u->away = g_strdup( state );
- }
- else if( message )
- {
- u->away = g_strdup( message );
- }
- else
- {
- u->away = g_strdup( "Away" );
- }
- }
- else
- {
- u->status_msg = g_strdup( message );
- }
-
- /* LISPy... */
- if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */
- ( u->online ) && /* Don't touch offline people */
- ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */
- ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */
- {
- char *from;
-
- if( set_getbool( &ic->irc->set, "simulate_netsplit" ) )
- {
- from = g_strdup( ic->irc->myhost );
- }
- else
- {
- from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick,
- ic->irc->myhost );
- }
- irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
- u->away?'-':'+', u->nick );
- g_free( from );
- }
-}
-
-void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
-{
- irc_t *irc = ic->irc;
- char *wrapped;
- user_t *u;
-
- u = user_findhandle( ic, handle );
-
- if( !u )
- {
- char *h = set_getstr( &irc->set, "handle_unknown" );
-
- if( g_strcasecmp( h, "ignore" ) == 0 )
- {
- if( set_getbool( &irc->set, "debug" ) )
- imcb_log( ic, "Ignoring message from unknown handle %s", handle );
-
- return;
- }
- else if( g_strncasecmp( h, "add", 3 ) == 0 )
- {
- int private = set_getbool( &irc->set, "private" );
-
- if( h[3] )
- {
- if( g_strcasecmp( h + 3, "_private" ) == 0 )
- private = 1;
- else if( g_strcasecmp( h + 3, "_channel" ) == 0 )
- private = 0;
- }
-
- imcb_add_buddy( ic, handle, NULL );
- u = user_findhandle( ic, handle );
- u->is_private = private;
- }
- else
- {
- imcb_log( ic, "Message from unknown handle %s:", handle );
- u = user_find( irc, irc->mynick );
- }
- }
-
- if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
- ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
- strip_html( msg );
-
- wrapped = word_wrap( msg, 425 );
- irc_msgfrom( irc, u->nick, wrapped );
- g_free( wrapped );
+#endif
}
void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags )
{
+#if 0
user_t *u;
- if( !set_getbool( &ic->irc->set, "typing_notice" ) )
+ if( !set_getbool( &ic->bee->set, "typing_notice" ) )
return;
if( ( u = user_findhandle( ic, handle ) ) )
@@ -779,10 +544,17 @@ void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags )
g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 );
irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf );
}
+#endif
+}
+
+struct bee_user *imcb_buddy_by_handle( struct im_connection *ic, const char *handle )
+{
+ return bee_user_by_handle( ic->bee, ic, handle );
}
struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle )
{
+#if 0
struct groupchat *c;
/* This one just creates the conversation structure, user won't see anything yet */
@@ -800,19 +572,22 @@ struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle )
c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ );
c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title );
- if( set_getbool( &ic->irc->set, "debug" ) )
+ if( set_getbool( &ic->bee->set, "debug" ) )
imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle );
return c;
+#endif
+ return NULL;
}
void imcb_chat_free( struct groupchat *c )
{
+#if 0
struct im_connection *ic = c->ic;
struct groupchat *l;
GList *ir;
- if( set_getbool( &ic->irc->set, "debug" ) )
+ if( set_getbool( &ic->bee->set, "debug" ) )
imcb_log( ic, "You were removed from conversation %p", c );
if( c )
@@ -845,10 +620,12 @@ void imcb_chat_free( struct groupchat *c )
g_free( c->topic );
g_free( c );
}
+#endif
}
void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at )
{
+#if 0
struct im_connection *ic = c->ic;
char *wrapped;
user_t *u;
@@ -859,8 +636,8 @@ void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t fl
u = user_findhandle( ic, who );
- if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
- ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
+ if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||
+ ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )
strip_html( msg );
wrapped = word_wrap( msg, 425 );
@@ -873,10 +650,12 @@ void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t fl
imcb_log( ic, "Message from/to conversation %s@%p (unknown conv/user): %s", who, c, wrapped );
}
g_free( wrapped );
+#endif
}
void imcb_chat_log( struct groupchat *c, char *format, ... )
{
+#if 0
irc_t *irc = c->ic->irc;
va_list params;
char *text;
@@ -891,10 +670,12 @@ void imcb_chat_log( struct groupchat *c, char *format, ... )
irc_privmsg( irc, u, "PRIVMSG", c->channel, "System message: ", text );
g_free( text );
+#endif
}
void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at )
{
+#if 0
struct im_connection *ic = c->ic;
user_t *u = NULL;
@@ -905,8 +686,8 @@ void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at
else
u = user_findhandle( ic, who );
- if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
- ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
+ if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) ||
+ ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) )
strip_html( topic );
g_free( c->topic );
@@ -914,17 +695,16 @@ void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at
if( c->joined && u )
irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic );
+#endif
}
-
-/* buddy_chat.c */
-
void imcb_chat_add_buddy( struct groupchat *b, const char *handle )
{
+#if 0
user_t *u = user_findhandle( b->ic, handle );
int me = 0;
- if( set_getbool( &b->ic->irc->set, "debug" ) )
+ if( set_getbool( &b->ic->bee->set, "debug" ) )
imcb_log( b->ic, "User %s added to conversation %p", handle, b );
/* It might be yourself! */
@@ -951,15 +731,17 @@ void imcb_chat_add_buddy( struct groupchat *b, const char *handle )
irc_join( b->ic->irc, u, b->channel );
b->in_room = g_list_append( b->in_room, g_strdup( handle ) );
}
+#endif
}
/* This function is one BIG hack... :-( EREWRITE */
void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason )
{
+#if 0
user_t *u;
int me = 0;
- if( set_getbool( &b->ic->irc->set, "debug" ) )
+ if( set_getbool( &b->ic->bee->set, "debug" ) )
imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" );
/* It might be yourself! */
@@ -979,8 +761,10 @@ void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char
if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) )
irc_part( b->ic->irc, u, b->channel );
+#endif
}
+#if 0
static int remove_chat_buddy_silent( struct groupchat *b, const char *handle )
{
GList *i;
@@ -999,12 +783,13 @@ static int remove_chat_buddy_silent( struct groupchat *b, const char *handle )
i = i->next;
}
- return( 0 );
+ return 0;
}
+#endif
/* Misc. BitlBee stuff which shouldn't really be here */
-
+#if 0
char *set_eval_away_devoice( set_t *set, char *value )
{
irc_t *irc = set->data;
@@ -1017,7 +802,7 @@ char *set_eval_away_devoice( set_t *set, char *value )
/* Horror.... */
- if( st != set_getbool( &irc->set, "away_devoice" ) )
+ if( st != set_getbool( &irc->b->set, "away_devoice" ) )
{
char list[80] = "";
user_t *u = irc->users;
@@ -1059,30 +844,13 @@ char *set_eval_away_devoice( set_t *set, char *value )
return value;
}
-
+#endif
/* The plan is to not allow straight calls to prpl functions anymore, but do
them all from some wrappers. We'll start to define some down here: */
-int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags )
-{
- char *buf = NULL;
- int st;
-
- if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
- {
- buf = escape_html( msg );
- msg = buf;
- }
-
- st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags );
- g_free( buf );
-
- return st;
-}
-
int imc_chat_msg( struct groupchat *c, char *msg, int flags )
{
char *buf = NULL;
@@ -1106,7 +874,7 @@ int imc_away_send_update( struct im_connection *ic )
char *away, *msg = NULL;
away = set_getstr( &ic->acc->set, "away" ) ?
- : set_getstr( &ic->irc->set, "away" );
+ : set_getstr( &ic->bee->set, "away" );
if( away && *away )
{
GList *m = ic->acc->prpl->away_states( ic );
@@ -1117,7 +885,7 @@ int imc_away_send_update( struct im_connection *ic )
{
away = NULL;
msg = set_getstr( &ic->acc->set, "status" ) ?
- : set_getstr( &ic->irc->set, "status" );
+ : set_getstr( &ic->bee->set, "status" );
}
ic->acc->prpl->set_away( ic, away, msg );
diff --git a/protocols/nogaim.h b/protocols/nogaim.h
index 324a2b46..a93dc5d2 100644
--- a/protocols/nogaim.h
+++ b/protocols/nogaim.h
@@ -1,7 +1,7 @@
/********************************************************************\
* BitlBee -- An IRC to other IM-networks gateway *
* *
- * Copyright 2002-2004 Wilmer van der Gaast and others *
+ * Copyright 2002-2010 Wilmer van der Gaast and others *
\********************************************************************/
/*
@@ -86,7 +86,7 @@ struct im_connection
int evil;
/* BitlBee */
- irc_t *irc;
+ bee_t *bee;
struct groupchat *groupchats;
};
@@ -285,16 +285,8 @@ G_MODULE_EXPORT struct buddy *imcb_find_buddy( struct im_connection *ic, char *h
G_MODULE_EXPORT void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname );
G_MODULE_EXPORT void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick );
-/* Buddy activity */
-/* To manipulate the status of a handle.
- * - flags can be |='d with OPT_* constants. You will need at least:
- * OPT_LOGGED_IN and OPT_AWAY.
- * - 'state' and 'message' can be NULL */
-G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message );
-/* Not implemented yet! */ G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle );
-/* Call when a handle says something. 'flags' and 'sent_at may be just 0. */
-G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at );
G_MODULE_EXPORT void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags );
+G_MODULE_EXPORT struct bee_user *imcb_buddy_by_handle( struct im_connection *ic, const char *handle );
G_MODULE_EXPORT void imcb_clean_handle( struct im_connection *ic, char *handle );
/* Groupchats */
@@ -319,7 +311,6 @@ G_MODULE_EXPORT void imcb_chat_free( struct groupchat *c );
/* Actions, or whatever. */
int imc_away_send_update( struct im_connection *ic );
-int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags );
int imc_chat_msg( struct groupchat *c, char *msg, int flags );
void imc_add_allow( struct im_connection *ic, char *handle );
diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c
index e0c32257..a5ca1ac8 100644
--- a/protocols/oscar/oscar.c
+++ b/protocols/oscar/oscar.c
@@ -1189,8 +1189,7 @@ static void gaim_icq_authgrant(void *data_) {
message = 0;
aim_ssi_auth_reply(od->sess, od->conn, uin, 1, "");
// aim_send_im_ch4(od->sess, uin, AIM_ICQMSG_AUTHGRANTED, &message);
- if(imcb_find_buddy(data->ic, uin) == NULL)
- imcb_ask_add(data->ic, uin, NULL);
+ imcb_ask_add(data->ic, uin, NULL);
g_free(uin);
g_free(data);
@@ -1951,11 +1950,13 @@ static void oscar_get_info(struct im_connection *g, char *name) {
static void oscar_get_away(struct im_connection *g, char *who) {
struct oscar_data *odata = (struct oscar_data *)g->proto_data;
if (odata->icq) {
+ /** FIXME(wilmer): Hmm, lost the ability to get away msgs here, do we care to get that back?
struct buddy *budlight = imcb_find_buddy(g, who);
if (budlight)
if ((budlight->uc & 0xff80) >> 7)
if (budlight->caps & AIM_CAPS_ICQSERVERRELAY)
aim_send_im_ch2_geticqmessage(odata->sess, who, (budlight->uc & 0xff80) >> 7);
+ */
} else
aim_getinfo(odata->sess, odata->conn, who, AIM_GETINFO_AWAYMESSAGE);
}
@@ -2093,7 +2094,7 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) {
switch (curitem->type) {
case 0x0000: /* Buddy */
- if ((curitem->name) && (!imcb_find_buddy(ic, nrm))) {
+ if ((curitem->name) && (!imcb_buddy_by_handle(ic, nrm))) {
char *realname = NULL;
if (curitem->data && aim_gettlv(curitem->data, 0x0131, 1))
diff --git a/root_commands.c b/root_commands.c
index d3b0c7d3..73670d3a 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -31,7 +31,7 @@
#include <string.h>
-void root_command_string( irc_t *irc, user_t *u, char *command, int flags )
+void root_command_string( irc_t *irc, char *command )
{
char *cmd[IRC_MAX_ARGS];
char *s;
@@ -160,7 +160,7 @@ static void cmd_identify( irc_t *irc, char **cmd )
irc_setpass( irc, cmd[1] );
irc->status |= USTATUS_IDENTIFIED;
irc_umode_set( irc, "+R", 1 );
- if( set_getbool( &irc->set, "auto_connect" ) )
+ if( set_getbool( &irc->b->set, "auto_connect" ) )
cmd_account( irc, account_on );
break;
case STORAGE_OTHER_ERROR:
@@ -200,7 +200,7 @@ static void cmd_drop( irc_t *irc, char **cmd )
{
storage_status_t status;
- status = storage_remove (irc->nick, cmd[1]);
+ status = storage_remove (irc->user->nick, cmd[1]);
switch (status) {
case STORAGE_NO_SUCH_USER:
irc_usermsg( irc, "That account does not exist" );
@@ -212,7 +212,7 @@ static void cmd_drop( irc_t *irc, char **cmd )
irc_setpass( irc, NULL );
irc->status &= ~USTATUS_IDENTIFIED;
irc_umode_set( irc, "-R", 1 );
- irc_usermsg( irc, "Account `%s' removed", irc->nick );
+ irc_usermsg( irc, "Account `%s' removed", irc->user->nick );
break;
default:
irc_usermsg( irc, "Error: `%d'", status );
@@ -220,6 +220,16 @@ static void cmd_drop( irc_t *irc, char **cmd )
}
}
+static void cmd_save( irc_t *irc, char **cmd )
+{
+ if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
+ irc_usermsg( irc, "Please create an account first" );
+ else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
+ irc_usermsg( irc, "Configuration saved" );
+ else
+ irc_usermsg( irc, "Configuration could not be saved!" );
+}
+
struct cmd_account_del_data
{
account_t *a;
@@ -231,7 +241,7 @@ void cmd_account_del_yes( void *data )
struct cmd_account_del_data *cad = data;
account_t *a;
- for( a = cad->irc->accounts; a && a != cad->a; a = a->next );
+ for( a = cad->irc->b->accounts; a && a != cad->a; a = a->next );
if( a == NULL )
{
@@ -243,7 +253,7 @@ void cmd_account_del_yes( void *data )
}
else
{
- account_del( cad->irc, a );
+ account_del( cad->irc->b, a );
irc_usermsg( cad->irc, "Account deleted" );
}
g_free( data );
@@ -284,7 +294,7 @@ static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead, cmd_
{
set_name = set_full;
- head = &irc->set;
+ head = &irc->b->set;
}
else
{
@@ -355,7 +365,7 @@ static set_t **cmd_account_set_findhead( irc_t *irc, char *id )
{
account_t *a;
- if( ( a = account_get( irc, id ) ) )
+ if( ( a = account_get( irc->b, id ) ) )
return &a->set;
else
return NULL;
@@ -403,7 +413,7 @@ static void cmd_account( irc_t *irc, char **cmd )
return;
}
- a = account_add( irc, prpl, cmd[3], cmd[4] );
+ a = account_add( irc->b, prpl, cmd[3], cmd[4] );
if( cmd[5] )
{
irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' "
@@ -417,7 +427,7 @@ static void cmd_account( irc_t *irc, char **cmd )
{
MIN_ARGS( 2 );
- if( !( a = account_get( irc, cmd[2] ) ) )
+ if( !( a = account_get( irc->b, cmd[2] ) ) )
{
irc_usermsg( irc, "Invalid account" );
}
@@ -439,7 +449,7 @@ static void cmd_account( irc_t *irc, char **cmd )
"to change your username/password, use the `account "
"set' command. Are you sure you want to delete this "
"account?", a->prpl->name, a->user );
- query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad );
+ //query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad );
g_free( msg );
}
}
@@ -450,7 +460,7 @@ static void cmd_account( irc_t *irc, char **cmd )
if( strchr( irc->umode, 'b' ) )
irc_usermsg( irc, "Account list:" );
- for( a = irc->accounts; a; a = a->next )
+ for( a = irc->b->accounts; a; a = a->next )
{
char *con;
@@ -473,7 +483,7 @@ static void cmd_account( irc_t *irc, char **cmd )
{
if( cmd[2] )
{
- if( ( a = account_get( irc, cmd[2] ) ) )
+ if( ( a = account_get( irc->b, cmd[2] ) ) )
{
if( a->ic )
{
@@ -482,7 +492,7 @@ static void cmd_account( irc_t *irc, char **cmd )
}
else
{
- account_on( irc, a );
+ account_on( irc->b, a );
}
}
else
@@ -493,12 +503,13 @@ static void cmd_account( irc_t *irc, char **cmd )
}
else
{
- if ( irc->accounts ) {
+ if ( irc->b->accounts )
+ {
irc_usermsg( irc, "Trying to get all accounts connected..." );
- for( a = irc->accounts; a; a = a->next )
+ for( a = irc->b->accounts; a; a = a->next )
if( !a->ic && a->auto_connect )
- account_on( irc, a );
+ account_on( irc->b, a );
}
else
{
@@ -512,19 +523,19 @@ static void cmd_account( irc_t *irc, char **cmd )
{
irc_usermsg( irc, "Deactivating all active (re)connections..." );
- for( a = irc->accounts; a; a = a->next )
+ for( a = irc->b->accounts; a; a = a->next )
{
if( a->ic )
- account_off( irc, a );
+ account_off( irc->b, a );
else if( a->reconnect )
cancel_auto_reconnect( a );
}
}
- else if( ( a = account_get( irc, cmd[2] ) ) )
+ else if( ( a = account_get( irc->b, cmd[2] ) ) )
{
if( a->ic )
{
- account_off( irc, a );
+ account_off( irc->b, a );
}
else if( a->reconnect )
{
@@ -555,6 +566,7 @@ static void cmd_account( irc_t *irc, char **cmd )
}
}
+#if 0
static void cmd_add( irc_t *irc, char **cmd )
{
account_t *a;
@@ -643,65 +655,55 @@ static void cmd_info( irc_t *irc, char **cmd )
ic->acc->prpl->get_info( ic, cmd[2] );
}
}
+#endif
static void cmd_rename( irc_t *irc, char **cmd )
{
- user_t *u;
+ irc_user_t *iu;
- if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
- {
- irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
- }
- else if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
+ iu = irc_user_by_name( irc, cmd[1] );
+
+ if( iu == NULL )
{
- if( strchr( CTYPES, cmd[2][0] ) && nick_ok( cmd[2] + 1 ) )
- {
- u = user_find( irc, irc->nick );
-
- irc_part( irc, u, irc->channel );
- g_free( irc->channel );
- irc->channel = g_strdup( cmd[2] );
- irc_join( irc, u, irc->channel );
-
- if( strcmp( cmd[0], "set_rename" ) != 0 )
- set_setstr( &irc->set, "control_channel", cmd[2] );
- }
+ irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
}
- else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
+ else if( iu == irc->user )
{
- irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
+ irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
}
else if( !nick_ok( cmd[2] ) )
{
irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
}
- else if( !( u = user_find( irc, cmd[1] ) ) )
+ else if( irc_user_by_name( irc, cmd[2] ) )
{
- irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
+ irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
}
else
{
- user_rename( irc, cmd[1], cmd[2] );
- irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
- if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
+ if( !irc_user_set_nick( iu, cmd[2] ) )
+ {
+ irc_usermsg( irc, "Error while changing nick" );
+ return;
+ }
+
+ if( iu == irc->root )
{
- g_free( irc->mynick );
- irc->mynick = g_strdup( cmd[2] );
-
/* If we're called internally (user did "set root_nick"),
let's not go O(INF). :-) */
if( strcmp( cmd[0], "set_rename" ) != 0 )
- set_setstr( &irc->set, "root_nick", cmd[2] );
+ set_setstr( &irc->b->set, "root_nick", cmd[2] );
}
- else if( u->send_handler == buddy_send_handler )
+ else if( iu->bu )
{
- nick_set( u->ic->acc, u->handle, cmd[2] );
+ nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] );
}
irc_usermsg( irc, "Nick successfully changed" );
}
}
+#if 0
char *set_eval_root_nick( set_t *set, char *new_nick )
{
irc_t *irc = set->data;
@@ -914,16 +916,6 @@ static void cmd_set( irc_t *irc, char **cmd )
cmd_set_real( irc, cmd, NULL, NULL );
}
-static void cmd_save( irc_t *irc, char **cmd )
-{
- if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
- irc_usermsg( irc, "Please create an account first" );
- else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
- irc_usermsg( irc, "Configuration saved" );
- else
- irc_usermsg( irc, "Configuration could not be saved!" );
-}
-
static void cmd_blist( irc_t *irc, char **cmd )
{
int online = 0, away = 0, offline = 0;
@@ -989,34 +981,6 @@ static void cmd_blist( irc_t *irc, char **cmd )
irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
}
-static void cmd_nick( irc_t *irc, char **cmd )
-{
- account_t *a;
-
- if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )
- {
- irc_usermsg( irc, "Invalid account");
- }
- else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) )
- {
- irc_usermsg( irc, "That account is not on-line" );
- }
- else if ( !cmd[2] )
- {
- irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" );
- }
- else if ( !a->prpl->set_my_name )
- {
- irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
- }
- else
- {
- irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );
-
- a->prpl->set_my_name( a->ic, cmd[2] );
- }
-}
-
static void cmd_qlist( irc_t *irc, char **cmd )
{
query_t *q = irc->queries;
@@ -1037,12 +1001,6 @@ static void cmd_qlist( irc_t *irc, char **cmd )
irc_usermsg( irc, "%d, BitlBee: %s", num, q->question );
}
-static void cmd_join_chat( irc_t *irc, char **cmd )
-{
- irc_usermsg( irc, "This command is now obsolete. "
- "Please try the `chat' command instead." );
-}
-
static set_t **cmd_chat_set_findhead( irc_t *irc, char *id )
{
struct chat *c;
@@ -1216,20 +1174,24 @@ static void cmd_transfer( irc_t *irc, char **cmd )
}
}
}
+#endif
const command_t commands[] = {
{ "help", 0, cmd_help, 0 },
+ { "account", 1, cmd_account, 0 },
{ "identify", 1, cmd_identify, 0 },
{ "register", 1, cmd_register, 0 },
{ "drop", 1, cmd_drop, 0 },
- { "account", 1, cmd_account, 0 },
+ { "save", 0, cmd_save, 0 },
+#if 0
{ "add", 2, cmd_add, 0 },
{ "info", 1, cmd_info, 0 },
+#endif
{ "rename", 2, cmd_rename, 0 },
+#if 0
{ "remove", 1, cmd_remove, 0 },
{ "block", 1, cmd_block, 0 },
{ "allow", 1, cmd_allow, 0 },
- { "save", 0, cmd_save, 0 },
{ "set", 0, cmd_set, 0 },
{ "yes", 0, cmd_yesno, 0 },
{ "no", 0, cmd_yesno, 0 },
@@ -1239,5 +1201,6 @@ const command_t commands[] = {
{ "join_chat", 2, cmd_join_chat, 0 },
{ "chat", 1, cmd_chat, 0 },
{ "transfer", 0, cmd_transfer, 0 },
+#endif
{ NULL }
};
diff --git a/set.c b/set.c
index 18d5a50d..8ecc9690 100644
--- a/set.c
+++ b/set.c
@@ -224,6 +224,7 @@ char *set_eval_to_char( set_t *set, char *value )
return s;
}
+/*
char *set_eval_ops( set_t *set, char *value )
{
irc_t *irc = set->data;
@@ -245,3 +246,4 @@ char *set_eval_ops( set_t *set, char *value )
return value;
}
+*/
diff --git a/storage_xml.c b/storage_xml.c
index b6745c75..b81e1d0c 100644
--- a/storage_xml.c
+++ b/storage_xml.c
@@ -146,7 +146,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na
else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&
arc_decode( pass_cr, pass_len, &password, xd->given_pass ) )
{
- xd->current_account = account_add( irc, prpl, handle, password );
+ xd->current_account = account_add( irc->b, prpl, handle, password );
if( server )
set_setstr( &xd->current_account->set, "server", server );
if( autoconnect )
@@ -180,7 +180,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na
else if( xd->current_account != NULL )
xd->current_set_head = &xd->current_account->set;
else
- xd->current_set_head = &xd->irc->set;
+ xd->current_set_head = &xd->irc->b->set;
xd->current_setting = g_strdup( setting );
}
@@ -214,7 +214,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na
if( xd->current_account && handle && channel )
{
- xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel );
+ //xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel );
}
else
{
@@ -352,7 +352,7 @@ static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const ch
static storage_status_t xml_load( irc_t *irc, const char *password )
{
- return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN );
+ return xml_load_real( irc, irc->user->nick, password, XML_PASS_UNKNOWN );
}
static storage_status_t xml_check_pass( const char *my_nick, const char *password )
@@ -395,7 +395,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
md5_byte_t pass_md5[21];
md5_state_t md5_state;
- path2 = g_strdup( irc->nick );
+ path2 = g_strdup( irc->user->nick );
nick_lc( path2 );
g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, path2, ".xml" );
g_free( path2 );
@@ -421,17 +421,17 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
/* Save the hash in base64-encoded form. */
pass_buf = base64_encode( pass_md5, 21 );
- if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->nick, pass_buf, XML_FORMAT_VERSION ) )
+ if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->user->nick, pass_buf, XML_FORMAT_VERSION ) )
goto write_error;
g_free( pass_buf );
- for( set = irc->set; set; set = set->next )
+ for( set = irc->b->set; set; set = set->next )
if( set->value )
if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
goto write_error;
- for( acc = irc->accounts; acc; acc = acc->next )
+ for( acc = irc->b->accounts; acc; acc = acc->next )
{
unsigned char *pass_cr;
char *pass_b64;
@@ -469,6 +469,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
if( g_hash_table_find( acc->nicks, xml_save_nick, & fd ) )
goto write_error;
+#if 0
for( c = irc->chatrooms; c; c = c->next )
{
if( c->acc != acc )
@@ -487,6 +488,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
if( !xml_printf( fd, 2, "</chat>\n" ) )
goto write_error;
}
+#endif
if( !xml_printf( fd, 1, "</account>\n" ) )
goto write_error;
diff --git a/user.c b/user.c
deleted file mode 100644
index 4d58f56b..00000000
--- a/user.c
+++ /dev/null
@@ -1,231 +0,0 @@
- /********************************************************************\
- * BitlBee -- An IRC to other IM-networks gateway *
- * *
- * Copyright 2002-2004 Wilmer van der Gaast and others *
- \********************************************************************/
-
-/* Stuff to handle, save and search buddies */
-
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License with
- the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
- if not, write to the Free Software Foundation, Inc., 59 Temple Place,
- Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#define BITLBEE_CORE
-#include "bitlbee.h"
-
-user_t *user_add( irc_t *irc, char *nick )
-{
- user_t *u, *lu = NULL;
- char *key;
-
- if( !nick_ok( nick ) )
- return( NULL );
-
- if( user_find( irc, nick ) != NULL )
- return( NULL );
-
- if( ( u = irc->users ) )
- {
- while( u )
- {
- if( nick_cmp( nick, u->nick ) < 0 )
- break;
-
- lu = u;
- u = u->next;
- }
-
- u = g_new0( user_t, 1 );
- if( lu )
- {
- u->next = lu->next;
- lu->next = u;
- }
- else
- {
- u->next = irc->users;
- irc->users = u;
- }
- }
- else
- {
- irc->users = u = g_new0( user_t, 1 );
- }
-
- u->user = u->realname = u->host = u->nick = g_strdup( nick );
- u->is_private = set_getbool( &irc->set, "private" );
-
- key = g_strdup( nick );
- nick_lc( key );
- g_hash_table_insert( irc->userhash, key, u );
-
- return( u );
-}
-
-int user_del( irc_t *irc, char *nick )
-{
- user_t *u, *t;
- char *key;
- gpointer okey, ovalue;
-
- if( !nick_ok( nick ) )
- return( 0 );
-
- u = irc->users;
- t = NULL;
- while( u )
- {
- if( nick_cmp( u->nick, nick ) == 0 )
- {
- /* Get this key now already, since "nick" might be free()d
- at the time we start playing with the hash... */
- key = g_strdup( nick );
- nick_lc( key );
-
- if( t )
- t->next = u->next;
- else
- irc->users = u->next;
- if( u->online )
- irc_kill( irc, u );
- g_free( u->nick );
- if( u->nick != u->user ) g_free( u->user );
- if( u->nick != u->host ) g_free( u->host );
- if( u->nick != u->realname ) g_free( u->realname );
- g_free( u->group );
- g_free( u->away );
- g_free( u->handle );
- g_free( u->sendbuf );
- if( u->sendbuf_timer ) b_event_remove( u->sendbuf_timer );
- g_free( u );
-
- if( !g_hash_table_lookup_extended( irc->userhash, key, &okey, &ovalue ) || ovalue != u )
- {
- g_free( key );
- return( 1 ); /* Although this is a severe error, the user is removed from the list... */
- }
- g_hash_table_remove( irc->userhash, key );
- g_free( key );
- g_free( okey );
-
- return( 1 );
- }
- u = (t=u)->next;
- }
-
- return( 0 );
-}
-
-user_t *user_find( irc_t *irc, char *nick )
-{
- char key[512] = "";
-
- strncpy( key, nick, sizeof( key ) - 1 );
- if( nick_lc( key ) )
- return( g_hash_table_lookup( irc->userhash, key ) );
- else
- return( NULL );
-}
-
-user_t *user_findhandle( struct im_connection *ic, const char *handle )
-{
- user_t *u;
- char *nick;
-
- /* First, let's try a hash lookup. If it works, it's probably faster. */
- if( ( nick = g_hash_table_lookup( ic->acc->nicks, handle ) ) &&
- ( u = user_find( ic->irc, nick ) ) &&
- ( ic->acc->prpl->handle_cmp( handle, u->handle ) == 0 ) )
- return u;
-
- /* However, it doesn't always work, so in that case we'll have to dig
- through the whole userlist. :-( */
- for( u = ic->irc->users; u; u = u->next )
- if( u->ic == ic && u->handle && ic->acc->prpl->handle_cmp( u->handle, handle ) == 0 )
- return u;
-
- return NULL;
-}
-
-/* DO NOT PASS u->nick FOR oldnick !!! */
-void user_rename( irc_t *irc, char *oldnick, char *newnick )
-{
- user_t *u = user_find( irc, oldnick );
- gpointer okey, ovalue;
- char *key;
-
- if( !u ) return; /* Should've been checked by the caller... */
-
- g_free( u->nick );
- if( u->nick == u->user ) u->user = NULL;
- if( u->nick == u->host ) u->host = NULL;
- if( u->nick == u->realname ) u->realname = NULL;
- u->nick = g_strdup( newnick );
- if( !u->user ) u->user = u->nick;
- if( !u->host ) u->host = u->nick;
- if( !u->realname ) u->realname = u->nick;
-
- /* Remove the old reference to this user from the hash and create a
- new one with the new nick. This is indeed a bit messy. */
- key = g_strdup( oldnick );
- nick_lc( key );
- if( !g_hash_table_lookup_extended( irc->userhash, key, &okey, &ovalue ) || ovalue != u )
- {
- g_free( key );
- return; /* This really shouldn't happen! */
- }
- g_hash_table_remove( irc->userhash, key );
- g_free( key );
- g_free( okey );
-
- key = g_strdup( newnick );
- nick_lc( key );
- g_hash_table_insert( irc->userhash, key, u );
-
- /* Also, let's try to keep the linked list nicely sorted. Fear this
- code. If my teacher would see this, she would cry. ;-) */
- {
- user_t *u1, *lu1;
-
- /* Remove the user from the old position in the chain. */
- if( u == irc->users )
- {
- irc->users = u->next;
- }
- else
- {
- u1 = u;
- for( lu1 = irc->users; lu1->next != u1; lu1 = lu1->next );
- lu1->next = u1->next;
- }
-
- /* Search for the new position. */
- for( lu1 = NULL, u1 = irc->users; u1; u1 = u1->next )
- {
- if( nick_cmp( newnick, u1->nick ) < 0 )
- break;
-
- lu1 = u1;
- }
-
- /* Insert it at this new position. */
- u->next = u1;
- if( lu1 )
- lu1->next = u;
- else
- irc->users = u;
- }
-}
diff --git a/user.h b/user.h
deleted file mode 100644
index 8c4f9c44..00000000
--- a/user.h
+++ /dev/null
@@ -1,62 +0,0 @@
- /********************************************************************\
- * BitlBee -- An IRC to other IM-networks gateway *
- * *
- * Copyright 2002-2004 Wilmer van der Gaast and others *
- \********************************************************************/
-
-/* Stuff to handle, save and search buddies */
-
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License with
- the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
- if not, write to the Free Software Foundation, Inc., 59 Temple Place,
- Suite 330, Boston, MA 02111-1307 USA
-*/
-#ifndef __USER_H__
-#define __USER_H__
-
-typedef struct __USER
-{
- char *nick;
- char *user;
- char *host;
- char *realname;
-
- char *away;
- char *status_msg; /* Non-IRC extension, but nice on IM. */
-
- char is_private;
- char online;
-
- char *handle;
- char *group;
- struct im_connection *ic;
-
- char *sendbuf;
- time_t last_typing_notice;
- int sendbuf_len;
- guint sendbuf_timer;
- int sendbuf_flags;
-
- void (*send_handler) ( irc_t *irc, struct __USER *u, char *msg, int flags );
-
- struct __USER *next;
-} user_t;
-
-user_t *user_add( struct irc *irc, char *nick );
-int user_del( irc_t *irc, char *nick );
-G_MODULE_EXPORT user_t *user_find( irc_t *irc, char *nick );
-G_MODULE_EXPORT user_t *user_findhandle( struct im_connection *ic, const char *handle );
-void user_rename( irc_t *irc, char *oldnick, char *newnick );
-
-#endif /* __USER_H__ */