Index: bitlbee.c
===================================================================
--- bitlbee.c	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ bitlbee.c	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -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;
 	}
Index: bitlbee.conf
===================================================================
--- bitlbee.conf	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ bitlbee.conf	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -10,8 +10,7 @@
 ##
 ##  Inetd -- Run from inetd (default)
-##  Daemon -- Run as a stand-alone daemon -- EXPERIMENTAL! BitlBee is not yet
-##    stable enough to serve lots of users from one process. Because of this
-##    and other reasons, the use of daemon-mode is *STRONGLY* discouraged,
-##    don't even *think* of reporting bugs when you use this.
+##  Daemon -- Run as a stand-alone daemon, serving all users from one process.
+##    This saves memory if there are more users, the downside is that when one
+##    user hits a crash-bug, all other users will also lose their connection.
 ##  ForkDaemon -- Run as a stand-alone daemon, but keep all clients in separate
 ##    child processes. This should be pretty safe and reliable to use instead
@@ -34,4 +33,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: conf.c
===================================================================
--- conf.c	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ conf.c	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -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;
@@ -83,5 +84,5 @@
 		if( opt == 'i' )
 		{
-			conf->iface = g_strdup( optarg );
+			conf->iface_in = g_strdup( optarg );
 		}
 		else if( opt == 'p' )
@@ -132,5 +133,5 @@
 			        "\n"
 			        "  -I  Classic/InetD mode. (Default)\n"
-			        "  -D  Daemon mode. (Still EXPERIMENTAL!)\n"
+			        "  -D  Daemon mode. (one process serves all)\n"
 			        "  -F  Forking daemon. (one process per client)\n"
 				"  -u  Run daemon as specified user.\n"
@@ -203,6 +204,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 )
@@ -210,4 +211,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 cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ conf.h	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -32,5 +32,5 @@
 typedef struct conf
 {
-	char *iface;
+	char *iface_in, *iface_out;
 	char *port;
 	int nofork;
Index: debian/changelog
===================================================================
--- debian/changelog	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ debian/changelog	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -1,10 +1,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 cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ debian/control	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -12,2 +12,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 cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ debian/rules	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -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/README
===================================================================
--- doc/README	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ doc/README	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -56,4 +56,9 @@
 a package from your distro would've been a better idea. :-P)
 
+Note that the BitlBee code is getting stable enough for daemon mode to be
+useful. Some public servers use it, and it saves a lot of memory by serving
+tens of users from a single process. One crash affects all users, but these
+are becoming quite rare.
+
 
 DEPENDENCIES
@@ -98,32 +103,4 @@
 versions of make, we'd love to hear it, but it seems this just isn't
 possible.
-
-
-RUNNING ON SERVERS WITH MANY USERS
-==================================
-
-BitlBee is not yet bug-free. Sometimes a bug causes the program to get into
-an infinite loop. Something you really don't want on a public server,
-especially when that machine is also used for other (mission-critical) things.
-For now we can't do much about it. We haven't seen that happen for a long
-time already on our own machines, but some people still manage to get
-themselves in nasty situations we haven't seen before.
-
-For now the best we can offer against this problem is bitlbeed, which allows
-you to setrlimit() the child processes to use no more than a specified
-number of CPU seconds. Not the best solution (not really a solution anyway),
-but certainly trashing one busy daemon process is better than trashing your
-whole machine.
-
-We don't believe adding a limit for bitlbee to /etc/security/limits.conf will
-work, because that file is only read by PAM (ie just for real login users,
-not daemons).
-
-See utils/bitlbeed.c for more information about the program.
-
-Just a little note: Now that we reach version 1.0, this shouldn't be that
-much of an issue anymore. However, on a public server, especially if you
-also use it for other things, it can't hurt to protect yourself against
-possible problems.
 
 
Index: doc/bitlbee.8
===================================================================
--- doc/bitlbee.8	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ doc/bitlbee.8	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -44,11 +44,6 @@
 
 \fBbitlbee\fP should be called by
-.BR inetd (8).
-(Or \fBbitlbeed\fP,
-if you can't run and/or configure \fBinetd\fP.) There is an experimental
-daemon mode too, in which BitlBee will serve all clients in one process
-(and does not require inetd), but this mode is still experimental.
-There are still some bugs left in BitlBee, and if they cause a crash,
-that would terminate the BitlBee connection for all clients.
+.BR inetd (8),
+or you can run it as a stand-alone daemon.
 .PP
 .SH OPTIONS
@@ -62,8 +57,7 @@
 Run in daemon mode. In this mode, BitlBee forks to the background and
 waits for new connections. All clients will be served from one process.
-This is still experimental. See the note above for more information.
 .IP "-F"
 Run in ForkDaemon mode. This is similar to ordinary daemon mode, but every
-client gets its own process. Easier to set up than inetd mode, but without
+client gets its own process. Easier to set up than inetd mode, and without
 the possible stability issues.
 .IP "-i \fIaddress\fP"
Index: lib/proxy.c
===================================================================
--- lib/proxy.c	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ lib/proxy.c	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -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/msn/ns.c
===================================================================
--- protocols/msn/ns.c	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ protocols/msn/ns.c	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -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: root_commands.c
===================================================================
--- root_commands.c	(revision cce0450184b4358ef06d91cca985fa3ca389fcd6)
+++ root_commands.c	(revision c821e8ad0d1cf9ab71e6e34c685d0adea2dde923)
@@ -422,4 +422,10 @@
 		else
 			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, '/' ) ) )
