Index: bitlbee.c
===================================================================
--- bitlbee.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ bitlbee.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -54,9 +54,9 @@
 	;
 
-	i = getaddrinfo( global.conf->iface, global.conf->port, &hints, &addrinfo_bind );
+	i = getaddrinfo( global.conf->iface_in, global.conf->port, &hints, &addrinfo_bind );
 	if( i )
 	{
 		log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s",
-		                           global.conf->iface, gai_strerror(i) );
+		                           global.conf->iface_in, gai_strerror(i) );
 		return -1;
 	}
@@ -226,10 +226,14 @@
 	if( st == size )
 	{
-		g_free( irc->sendbuffer );
-		irc->sendbuffer = NULL;
-		irc->w_watch_source_id = 0;
-		
 		if( irc->status & USTATUS_SHUTDOWN )
+		{
 			irc_free( irc );
+		}
+		else
+		{
+			g_free( irc->sendbuffer );
+			irc->sendbuffer = NULL;
+			irc->w_watch_source_id = 0;
+		}
 		
 		return FALSE;
Index: bitlbee.conf
===================================================================
--- bitlbee.conf	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ bitlbee.conf	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -34,4 +34,11 @@
 # DaemonInterface = 0.0.0.0
 # DaemonPort = 6667
+
+## ClientInterface:
+##
+## If for any reason, you want BitlBee to use a specific address/interface
+## for outgoing traffic (IM connections, HTTP(S), etc.), set it here.
+##
+# ClientInterface = 0.0.0.0
 
 ## AuthMode
Index: bitlbee.h
===================================================================
--- bitlbee.h	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ bitlbee.h	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -156,4 +156,6 @@
 gboolean bitlbee_shutdown( gpointer data, gint fd, b_input_condition cond );
 
+char *set_eval_root_nick( set_t *set, char *new_nick );
+
 extern global_t global;
 
Index: conf.c
===================================================================
--- conf.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ conf.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -45,5 +45,6 @@
 	conf = g_new0( conf_t, 1 );
 	
-	conf->iface = NULL;
+	conf->iface_in = NULL;
+	conf->iface_out = NULL;
 	conf->port = g_strdup( "6667" );
 	conf->nofork = 0;
@@ -82,5 +83,5 @@
 		if( opt == 'i' )
 		{
-			conf->iface = g_strdup( optarg );
+			conf->iface_in = g_strdup( optarg );
 		}
 		else if( opt == 'p' )
@@ -202,6 +203,6 @@
 			else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 )
 			{
-				g_free( conf->iface );
-				conf->iface = g_strdup( ini->value );
+				g_free( conf->iface_in );
+				conf->iface_in = g_strdup( ini->value );
 			}
 			else if( g_strcasecmp( ini->key, "daemonport" ) == 0 )
@@ -209,4 +210,9 @@
 				g_free( conf->port );
 				conf->port = g_strdup( ini->value );
+			}
+			else if( g_strcasecmp( ini->key, "clientinterface" ) == 0 )
+			{
+				g_free( conf->iface_out );
+				conf->iface_out = g_strdup( ini->value );
 			}
 			else if( g_strcasecmp( ini->key, "authmode" ) == 0 )
Index: conf.h
===================================================================
--- conf.h	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ conf.h	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -32,5 +32,5 @@
 typedef struct conf
 {
-	char *iface;
+	char *iface_in, *iface_out;
 	char *port;
 	int nofork;
Index: debian/changelog
===================================================================
--- debian/changelog	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ debian/changelog	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -7,10 +7,11 @@
 bitlbee (1.2-4) unstable; urgency=low
 
-  * Not a real release, just a placeholder for the changelog.
   * Fixed init script to use the BITLBEE_OPTS variable, not an undefined
-    DAEMON_OPT.
+    DAEMON_OPT. (Closes: #474583)
   * Added dependency information to the init script. (Closes: #472567)
-
- -- Wilmer van der Gaast <wilmer@gaast.net>  Sat, 29 Mar 2008 21:10:33 +0000
+  * Added bitlbee-dev package. Patch from RISKO Gergely <risko@debian.org>
+    with some small modifications. (Closes: #473480)
+
+ -- Wilmer van der Gaast <wilmer@gaast.net>  Wed, 07 May 2008 22:40:40 -0700
 
 bitlbee (1.2-3) unstable; urgency=low
Index: debian/control
===================================================================
--- debian/control	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ debian/control	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -14,2 +14,11 @@
  This program can be used as an IRC server which forwards everything you
  say to people on other chat networks: Jabber, ICQ, AIM, MSN and Yahoo.
+
+Package: bitlbee-dev
+Architecture: all
+Depends: bitlbee (= ${binary:Version})
+Description: An IRC to other chat networks gateway
+ This program can be used as an IRC server which forwards everything you
+ say to people on other chat networks: Jabber, ICQ, AIM, MSN and Yahoo.
+ .
+ This package holds development stuff for compiling plug-ins.
Index: debian/rules
===================================================================
--- debian/rules	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ debian/rules	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -13,5 +13,5 @@
 build-arch: build-arch-stamp
 build-arch-stamp:
-	if [ ! -d debian ]; then exit 1; fi
+	[ -d debian ]
 	./configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --events=libevent
 	$(MAKE)
@@ -20,6 +20,6 @@
 
 clean:
-	if [ "`whoami`" != "root" -o ! -d debian ]; then exit 1; fi
-	rm -rf build-arch-stamp debian/bitlbee debian/*.substvars debian/files
+	[ "`whoami`" = "root" -a -d debian ]
+	rm -rf build-arch-stamp debian/bitlbee debian/*.substvars debian/files debian/bitlbee-dev
 	-$(MAKE) distclean
 #	-$(MAKE) -C doc/ clean
@@ -27,5 +27,5 @@
 
 install-arch: build-arch
-	if [ "`whoami`" != "root" -o ! -d debian ]; then exit 1; fi
+	[ "`whoami`" = "root" -a -d debian ]
 	mkdir -p debian/bitlbee/DEBIAN/
 	$(MAKE) install install-etc DESTDIR=`pwd`/debian/bitlbee
@@ -35,6 +35,13 @@
 	cp doc/user-guide/user-guide.html debian/bitlbee/usr/share/doc/bitlbee/
 
+install-indep: install-arch
+	[ "`whoami`" = "root" -a -d debian ]
+	mkdir -p debian/bitlbee-dev/DEBIAN/
+	$(MAKE) install-dev DESTDIR=`pwd`/debian/bitlbee-dev
+
+	mkdir -p debian/bitlbee-dev/usr/share/doc/bitlbee-dev/
+
 binary-arch: build-arch install-arch
-	if [ "`whoami`" != "root" -o ! -d debian ]; then exit 1; fi
+	[ "`whoami`" = "root" -a -d debian ]
 
 	chmod 755 debian/post* debian/pre* debian/config debian/bitlbee.init
@@ -52,5 +59,5 @@
 		        doc/bitlbee/examples/* man/man8/bitlbee.8 man/man5/bitlbee.conf.5
 	
-	chown -R root.root debian/bitlbee/
+	chown -R root:root debian/bitlbee/
 	find debian/bitlbee/usr/share/ -type d -exec chmod 755 {} \;
 	find debian/bitlbee/usr/share/ -type f -exec chmod 644 {} \;
@@ -77,10 +84,25 @@
 	dpkg --build debian/bitlbee ..
 
-debug-build:
-	BITLBEE_VERSION=\"`date +%Y%m%d`-`hostname`-debug\" debian/rules clean binary DEBUG=1
+binary-indep: install-indep
+	[ "`whoami`" = "root" -a -d debian ]
 
-binary: binary-arch
+	chown -R root.root debian/bitlbee-dev/
+	find debian/bitlbee-dev/usr/share/ -type d -exec chmod 755 {} \;
+	find debian/bitlbee-dev/usr/share/ -type f -exec chmod 644 {} \;
+
+	cp debian/changelog debian/bitlbee-dev/usr/share/doc/bitlbee-dev/changelog.Debian
+	gzip -9 debian/bitlbee-dev/usr/share/doc/bitlbee-dev/changelog.Debian
+	cp debian/copyright debian/bitlbee-dev/usr/share/doc/bitlbee-dev/copyright
+
+	cd debian/bitlbee-dev; \
+		find usr -type f -exec md5sum {} \; > DEBIAN/md5sums
+
+	dpkg-gencontrol -ldebian/changelog -isp -pbitlbee-dev -Pdebian/bitlbee-dev
+
+	dpkg --build debian/bitlbee-dev ..
+
+binary: binary-arch binary-indep
 build: build-arch
-install: install-arch
+install: install-arch install-indep
 
-.PHONY: build-arch build clean binary-arch binary install-arch install
+.PHONY: build-arch build clean binary-arch binary install-arch install binary-indep install-indep
Index: doc/user-guide/commands.xml
===================================================================
--- doc/user-guide/commands.xml	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ doc/user-guide/commands.xml	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -589,4 +589,14 @@
 	</bitlbee-setting>
 
+	<bitlbee-setting name="root_nick" type="string" scope="global">
+		<default>root</default>
+
+		<description>
+			<para>
+				Normally the "bot" that takes all your BitlBee commands is called "root". If you don't like this name, you can rename it to anything else using the <emphasis>rename</emphasis> command, or by changing this setting.
+			</para>
+		</description>
+	</bitlbee-setting>
+
 	<bitlbee-setting name="save_on_quit" type="boolean" scope="global">
 		<default>true</default>
Index: irc.c
===================================================================
--- irc.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ irc.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -151,4 +151,5 @@
 	set_add( &irc->set, "private", "true", set_eval_bool, irc );
 	set_add( &irc->set, "query_order", "lifo", NULL, irc );
+	set_add( &irc->set, "root_nick", irc->mynick, set_eval_root_nick, irc );
 	set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc );
 	set_add( &irc->set, "simulate_netsplit", "true", set_eval_bool, irc );
@@ -199,10 +200,12 @@
 	if( irc->sendbuffer && !immed )
 	{
-		/* We won't read from this socket anymore. Instead, we'll connect a timer
-		   to it that should shut down the connection in a second, just in case
-		   bitlbee_.._write doesn't do it first. */
+		/* Set up a timeout event that should shut down the connection
+		   in a second, just in case ..._write doesn't do it first. */
 		
 		b_event_remove( irc->r_watch_source_id );
-		irc->r_watch_source_id = b_timeout_add( 1000, (b_event_handler) irc_free, irc );
+		irc->r_watch_source_id = 0;
+		
+		b_event_remove( irc->ping_source_id );
+		irc->ping_source_id = b_timeout_add( 1000, (b_event_handler) irc_free, irc );
 	}
 	else
@@ -274,5 +277,6 @@
 	if( irc->ping_source_id > 0 )
 		b_event_remove( irc->ping_source_id );
-	b_event_remove( irc->r_watch_source_id );
+	if( irc->r_watch_source_id > 0 )
+		b_event_remove( irc->r_watch_source_id );
 	if( irc->w_watch_source_id > 0 )
 		b_event_remove( irc->w_watch_source_id );
Index: lib/arc.h
===================================================================
--- lib/arc.h	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ lib/arc.h	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -31,4 +31,8 @@
 };
 
+#ifndef G_GNUC_MALLOC
+#define G_GNUC_MALLOC
+#endif
+
 G_GNUC_MALLOC struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles );
 unsigned char arc_getbyte( struct arc_state *st );
Index: lib/proxy.c
===================================================================
--- lib/proxy.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ lib/proxy.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -114,4 +114,5 @@
 {
 	struct sockaddr_in *sin;
+	struct sockaddr_in me;
 	int fd = -1;
 
@@ -127,4 +128,14 @@
 
 	sock_make_nonblocking(fd);
+	
+	if( global.conf->iface_out )
+	{
+		me.sin_family = AF_INET;
+		me.sin_port = 0;
+		me.sin_addr.s_addr = inet_addr( global.conf->iface_out );
+		
+		if( bind( fd, (struct sockaddr *) &me, sizeof( me ) ) != 0 )
+			event_debug( "bind( %d, \"%s\" ) failure\n", fd, global.conf->iface_out );
+	}
 	
 	event_debug("proxy_connect_none( \"%s\", %d ) = %d\n", host, port, fd);
Index: protocols/jabber/jabber_util.c
===================================================================
--- protocols/jabber/jabber_util.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/jabber/jabber_util.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -246,6 +246,8 @@
 };
 
-static void jabber_buddy_ask_yes( gpointer w, struct jabber_buddy_ask_data *bla )
-{
+static void jabber_buddy_ask_yes( void *data )
+{
+	struct jabber_buddy_ask_data *bla = data;
+	
 	presence_send_request( bla->ic, bla->handle, "subscribed" );
 	
@@ -257,6 +259,8 @@
 }
 
-static void jabber_buddy_ask_no( gpointer w, struct jabber_buddy_ask_data *bla )
-{
+static void jabber_buddy_ask_no( void *data )
+{
+	struct jabber_buddy_ask_data *bla = data;
+	
 	presence_send_request( bla->ic, bla->handle, "subscribed" );
 	
Index: protocols/msn/msn.h
===================================================================
--- protocols/msn/msn.h	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/msn/msn.h	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -29,5 +29,5 @@
 #define GROUPCHAT_SWITCHBOARD_MESSAGE "\r\r\rME WANT TALK TO MANY PEOPLE\r\r\r"
 
-#ifdef DEBUG
+#ifdef DEBUG_MSN
 #define debug( text... ) imcb_log( ic, text );
 #else
Index: protocols/msn/msn_util.c
===================================================================
--- protocols/msn/msn_util.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/msn/msn_util.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -90,6 +90,8 @@
 };
 
-static void msn_buddy_ask_yes( gpointer w, struct msn_buddy_ask_data *bla )
-{
+static void msn_buddy_ask_yes( void *data )
+{
+	struct msn_buddy_ask_data *bla = data;
+	
 	msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname );
 	
@@ -102,6 +104,8 @@
 }
 
-static void msn_buddy_ask_no( gpointer w, struct msn_buddy_ask_data *bla )
-{
+static void msn_buddy_ask_no( void *data )
+{
+	struct msn_buddy_ask_data *bla = data;
+	
 	msn_buddy_list_add( bla->ic, "BL", bla->handle, bla->realname );
 	
Index: protocols/msn/ns.c
===================================================================
--- protocols/msn/ns.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/msn/ns.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -178,5 +178,13 @@
 			
 			debug( "Connecting to a new switchboard with key %s", cmd[5] );
-			sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW );
+
+			if( ( sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ) ) == NULL )
+			{
+				/* Although this isn't strictly fatal for the NS connection, it's
+				   definitely something serious (we ran out of file descriptors?). */
+				imcb_error( ic, "Could not create new switchboard" );
+				imc_logout( ic, TRUE );
+				return( 0 );
+			}
 			
 			if( md->msgq )
@@ -468,6 +476,16 @@
 		debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] );
 		
-		sb = msn_sb_create( ic, server, port, cmd[4], session );
-		sb->who = g_strdup( cmd[5] );
+		if( ( sb = msn_sb_create( ic, server, port, cmd[4], session ) ) == NULL )
+		{
+			/* Although this isn't strictly fatal for the NS connection, it's
+			   definitely something serious (we ran out of file descriptors?). */
+			imcb_error( ic, "Could not create new switchboard" );
+			imc_logout( ic, TRUE );
+			return( 0 );
+		}
+		else
+		{
+			sb->who = g_strdup( cmd[5] );
+		}
 	}
 	else if( strcmp( cmd[0], "ADD" ) == 0 )
Index: protocols/nogaim.c
===================================================================
--- protocols/nogaim.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/nogaim.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -343,5 +343,6 @@
 /* dialogs.c */
 
-void imcb_ask( struct im_connection *ic, char *msg, void *data, void *doit, void *dont )
+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 );
@@ -495,16 +496,18 @@
 };
 
-void show_got_added_no( gpointer w, struct show_got_added_data *data )
-{
-	g_free( data->handle );
+void show_got_added_no( void *data )
+{
+	g_free( ((struct show_got_added_data*)data)->handle );
 	g_free( data );
 }
 
-void show_got_added_yes( gpointer w, struct show_got_added_data *data )
-{
-	data->ic->acc->prpl->add_buddy( data->ic, data->handle, NULL );
-	/* imcb_add_buddy( data->ic, NULL, data->handle, data->handle ); */
-	
-	return show_got_added_no( w, data );
+void show_got_added_yes( void *data )
+{
+	struct show_got_added_data *sga = data;
+	
+	sga->ic->acc->prpl->add_buddy( sga->ic, sga->handle, NULL );
+	/* imcb_add_buddy( sga->ic, NULL, sga->handle, sga->handle ); */
+	
+	return show_got_added_no( data );
 }
 
Index: protocols/nogaim.h
===================================================================
--- protocols/nogaim.h	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/nogaim.h	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -42,4 +42,5 @@
 #include "account.h"
 #include "proxy.h"
+#include "query.h"
 #include "md5.h"
 
@@ -261,5 +262,5 @@
  * - 'doit' or 'dont' will be called depending of the answer of the user.
  */
-G_MODULE_EXPORT void imcb_ask( struct im_connection *ic, char *msg, void *data, void *doit, void *dont );
+G_MODULE_EXPORT void imcb_ask( struct im_connection *ic, char *msg, void *data, query_callback doit, query_callback dont );
 G_MODULE_EXPORT void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname );
 
Index: protocols/oscar/oscar.c
===================================================================
--- protocols/oscar/oscar.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/oscar/oscar.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -1084,6 +1084,6 @@
 }
 
-void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv);
-void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv);
+void oscar_accept_chat(void *data);
+void oscar_reject_chat(void *data);
 	
 static int incomingim_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args) {
@@ -1119,5 +1119,6 @@
 }
 
-static void gaim_icq_authgrant(gpointer w, struct icq_auth *data) {
+static void gaim_icq_authgrant(void *data_) {
+	struct icq_auth *data = data_;
 	char *uin, message;
 	struct oscar_data *od = (struct oscar_data *)data->ic->proto_data;
@@ -1134,5 +1135,6 @@
 }
 
-static void gaim_icq_authdeny(gpointer w, struct icq_auth *data) {
+static void gaim_icq_authdeny(void *data_) {
+	struct icq_auth *data = data_;
 	char *uin, *message;
 	struct oscar_data *od = (struct oscar_data *)data->ic->proto_data;
@@ -2588,6 +2590,8 @@
 }
 
-void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv)
+void oscar_accept_chat(void *data)
 {
+	struct aim_chat_invitation * inv = data;
+	
 	oscar_chat_join(inv->ic, inv->name, NULL, NULL);
 	g_free(inv->name);
@@ -2595,6 +2599,8 @@
 }
 
-void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv)
+void oscar_reject_chat(void *data)
 {
+	struct aim_chat_invitation * inv = data;
+	
 	g_free(inv->name);
 	g_free(inv);
Index: protocols/yahoo/yahoo.c
===================================================================
--- protocols/yahoo/yahoo.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ protocols/yahoo/yahoo.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -797,6 +797,8 @@
 }
 
-static void byahoo_accept_conf( gpointer w, struct byahoo_conf_invitation *inv )
-{
+static void byahoo_accept_conf( void *data )
+{
+	struct byahoo_conf_invitation *inv = data;
+	
 	yahoo_conference_logon( inv->yid, NULL, inv->members, inv->name );
 	imcb_chat_add_buddy( inv->c, inv->ic->acc->user );
@@ -805,6 +807,8 @@
 }
 
-static void byahoo_reject_conf( gpointer w, struct byahoo_conf_invitation *inv )
-{
+static void byahoo_reject_conf( void *data )
+{
+	struct byahoo_conf_invitation *inv = data;
+	
 	yahoo_conference_decline( inv->yid, NULL, inv->members, inv->name, "User rejected groupchat" );
 	imcb_chat_free( inv->c );
Index: query.c
===================================================================
--- query.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ query.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -30,5 +30,6 @@
 static query_t *query_default( irc_t *irc );
 
-query_t *query_add( irc_t *irc, struct im_connection *ic, char *question, void *yes, void *no, void *data )
+query_t *query_add( irc_t *irc, struct im_connection *ic, char *question,
+                    query_callback yes, query_callback no, void *data )
 {
 	query_t *q = g_new0( query_t, 1 );
@@ -144,5 +145,5 @@
 		else
 			irc_usermsg( irc, "Accepted: %s", q->question );
-		q->yes( NULL, q->data );
+		q->yes( q->data );
 	}
 	else
@@ -152,5 +153,5 @@
 		else
 			irc_usermsg( irc, "Rejected: %s", q->question );
-		q->no( NULL, q->data );
+		q->no( q->data );
 	}
 	q->data = NULL;
Index: query.h
===================================================================
--- query.h	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ query.h	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -27,15 +27,17 @@
 #define _QUERY_H
 
+typedef void (*query_callback) ( void *data );
+
 typedef struct query
 {
 	struct im_connection *ic;
 	char *question;
-	void (* yes) ( gpointer w, void *data );
-	void (* no) ( gpointer w, void *data );
+	query_callback yes, no;
 	void *data;
 	struct query *next;
 } query_t;
 
-query_t *query_add( irc_t *irc, struct im_connection *ic, char *question, void *yes, void *no, void *data );
+query_t *query_add( irc_t *irc, struct im_connection *ic, char *question,
+                    query_callback yes, query_callback no, void *data );
 void query_del( irc_t *irc, query_t *q );
 void query_del_by_conn( irc_t *irc, struct im_connection *ic );
Index: root_commands.c
===================================================================
--- root_commands.c	(revision 51bbec0b0e280be629f7b1086160b7730ebfdb74)
+++ root_commands.c	(revision 783e9b76de9a8ec16e8229d7c476b16ba8011554)
@@ -204,22 +204,36 @@
 }
 
-void cmd_account_del_yes( gpointer w, void *data )
-{
-	account_t *a = data;
-	irc_t *irc = a->irc;
-	
-	if( a->ic )
-	{
-		irc_usermsg( irc, "Account is still logged in, can't delete" );
-	}
-	else
-	{
-		account_del( irc, a );
-		irc_usermsg( irc, "Account deleted" );
-	}
-}
-
-void cmd_account_del_no( gpointer w, void *data )
-{
+struct cmd_account_del_data
+{
+	account_t *a;
+	irc_t *irc;
+};
+
+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 );
+	
+	if( a == NULL )
+	{
+		irc_usermsg( cad->irc, "Account already deleted" );
+	}
+	else if( a->ic )
+	{
+		irc_usermsg( cad->irc, "Account is still logged in, can't delete" );
+	}
+	else
+	{
+		account_del( cad->irc, a );
+		irc_usermsg( cad->irc, "Account deleted" );
+	}
+	g_free( data );
+}
+
+void cmd_account_del_no( void *data )
+{
+	g_free( data );
 }
 
@@ -278,5 +292,10 @@
 		else
 		{
+			struct cmd_account_del_data *cad;
 			char *msg;
+			
+			cad = g_malloc( sizeof( struct cmd_account_del_data ) );
+			cad->a = a;
+			cad->irc = irc;
 			
 			msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will "
@@ -285,5 +304,5 @@
 			                       "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, a );
+			query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad );
 			g_free( msg );
 		}
@@ -404,4 +423,10 @@
 			acc_handle = g_strdup( cmd[2] );
 		
+		if( !acc_handle )
+		{
+			irc_usermsg( irc, "Not enough parameters given (need %d)", 3 );
+			return;
+		}
+		
 		if( ( tmp = strchr( acc_handle, '/' ) ) )
 		{
@@ -584,4 +609,7 @@
 			g_free( irc->mynick );
 			irc->mynick = g_strdup( cmd[2] );
+			
+			if( strcmp( cmd[0], "set_rename" ) != 0 )
+				set_setstr( &irc->set, "root_nick", cmd[2] );
 		}
 		else if( u->send_handler == buddy_send_handler )
@@ -592,4 +620,18 @@
 		irc_usermsg( irc, "Nick successfully changed" );
 	}
+}
+
+char *set_eval_root_nick( set_t *set, char *new_nick )
+{
+	irc_t *irc = set->data;
+	
+	if( strcmp( irc->mynick, new_nick ) != 0 )
+	{
+		char *cmd[] = { "set_rename", irc->mynick, new_nick, NULL };
+		
+		cmd_rename( irc, cmd );
+	}
+	
+	return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : NULL;
 }
 
