diff options
| author | ulim <a.sporto+bee@gmail.com> | 2008-08-04 16:45:24 +0200 | 
|---|---|---|
| committer | ulim <a.sporto+bee@gmail.com> | 2008-08-04 16:45:24 +0200 | 
| commit | 8661caad555f4306cf36ee37979a7637b05d5cd4 (patch) | |
| tree | 7e4a7c3d6a700610dd31d109508b07caa3253902 | |
| parent | 4ac647dbcef152bebde7209f7c9cbbf8a5e0fc37 (diff) | |
| parent | 718e05f842c1af043eb4efded8b0afe429377f70 (diff) | |
merged in upstream r410.
Only conflict was the correction of jabber normalization which I had already done.
41 files changed, 1108 insertions, 233 deletions
| @@ -16,3 +16,6 @@ tests/check  *.gcov  *.gcno  *.o +coverage +bitlbee.info +bitlbee.exe @@ -9,10 +9,20 @@  -include Makefile.settings  # Program variables -objects = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o dcc.o -headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h dcc.h lib/events.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/nogaim.h protocols/ft.h +objects = account.o bitlbee.o crypting.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 dcc.o +headers = account.h bitlbee.h commands.h conf.h config.h crypting.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/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/nogaim.h protocols/ft.h  subdirs = lib protocols +ifeq ($(TARGET),i586-mingw32msvc) +objects += win32.o +LFLAGS+=-lws2_32 +EFLAGS+=-lsecur32 +OUTFILE=bitlbee.exe +else +objects += unix.o conf.o log.o +OUTFILE=bitlbee +endif +  # Expansion of variables  subdirobjs = $(foreach dir,$(subdirs),$(dir)/$(dir).o)  CFLAGS += -Wall @@ -117,11 +117,12 @@ int bitlbee_daemon_init()  #endif  	if( global.conf->runmode == RUNMODE_FORKDAEMON ) -		ipc_master_load_state(); +		ipc_master_load_state( getenv( "_BITLBEE_RESTART_STATE" ) );  	if( global.conf->runmode == RUNMODE_DAEMON || global.conf->runmode == RUNMODE_FORKDAEMON )  		ipc_master_listen_socket(); +#ifndef _WIN32  	if( ( fp = fopen( global.conf->pidfile, "w" ) ) )  	{  		fprintf( fp, "%d\n", (int) getpid() ); @@ -131,6 +132,7 @@ int bitlbee_daemon_init()  	{  		log_message( LOGLVL_WARNING, "Warning: Couldn't write PID to `%s'", global.conf->pidfile );  	} +#endif  	return( 0 );  } @@ -140,9 +142,6 @@ int bitlbee_inetd_init()  	if( !irc_new( 0 ) )  		return( 1 ); -	log_link( LOGLVL_ERROR, LOGOUTPUT_IRC ); -	log_link( LOGLVL_WARNING, LOGOUTPUT_IRC ); -	  	return( 0 );  } @@ -253,7 +252,6 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition  	socklen_t size = sizeof( struct sockaddr_in );  	struct sockaddr_in conn_info;  	int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size ); -	pid_t client_pid = 0;  	if( new_socket == -1 )  	{ @@ -261,8 +259,10 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition  		return TRUE;  	} +#ifndef _WIN32  	if( global.conf->runmode == RUNMODE_FORKDAEMON )  	{ +		pid_t client_pid = 0;  		int fds[2];  		if( socketpair( AF_UNIX, SOCK_STREAM, 0, fds ) == -1 ) @@ -319,6 +319,7 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition  		}  	}  	else +#endif  	{  		log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );  		irc_new( new_socket ); @@ -28,8 +28,11 @@  #define _GNU_SOURCE /* Stupid GNU :-P */ +/* Depend on Windows 2000 for now since we need getaddrinfo() */ +#define _WIN32_WINNT 0x0501 +  #define PACKAGE "BitlBee" -#define BITLBEE_VERSION "1.2" +#define BITLBEE_VERSION "1.2.1"  #define VERSION BITLBEE_VERSION  #define MAX_STRING 511 @@ -47,9 +50,10 @@  #include <stdarg.h>  #include <stdio.h>  #include <ctype.h> +#include <errno.h> +  #ifndef _WIN32  #include <syslog.h> -#include <errno.h>  #endif  #include <glib.h> @@ -94,10 +98,6 @@  #undef g_main_quit  #define g_main_quit		__PLEASE_USE_B_MAIN_QUIT__ -#ifndef F_OK -#define F_OK 0 -#endif -  #ifndef G_GNUC_MALLOC  /* Doesn't exist in GLib <=2.4 while everything else in BitlBee should     work with it, so let's fake this one. */ @@ -78,7 +78,7 @@ conf_t *conf_load( int argc, char *argv[] )  		   at a *valid* configuration file. */  	} -	while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:" ) ) >= 0 ) +	while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hu:" ) ) >= 0 )  	/*     ^^^^ Just to make sure we skip this step from the REHASH handler. */  	{  		if( opt == 'i' ) @@ -146,14 +146,6 @@ conf_t *conf_load( int argc, char *argv[] )  			        "  -h  Show this help page.\n" );  			return NULL;  		} -		else if( opt == 'R' ) -		{ -			/* We can't load the statefile yet (and should make very sure we do this -			   only once), so set the filename here and load the state information -			   when initializing ForkDaemon. (This option only makes sense in that -			   mode anyway!) */ -			ipc_master_set_statefile( optarg ); -		}  		else if( opt == 'u' )  		{  			g_free( conf->user ); @@ -19,6 +19,7 @@ libevent='/usr/'  pidfile='/var/run/bitlbee.pid'  ipcsocket='/var/run/bitlbee.sock'  pcdir='$prefix/lib/pkgconfig' +systemlibdirs="/lib /usr/lib /usr/local/lib"  msn=1  jabber=1 @@ -73,6 +74,8 @@ Option		Description				Default  --events=...	Event handler (glib, libevent)		$events  --ssl=...	SSL library to use (gnutls, nss, openssl, bogus, auto)  							$ssl + +--target=...	Cross compilation target 		same as host  EOF  		exit;  	fi @@ -106,9 +109,9 @@ CONFIG=$config  INCLUDEDIR=$includedir  PCDIR=$pcdir +TARGET=$target  ARCH=$arch  CPU=$cpu -OUTFILE=bitlbee  DESTDIR=  LFLAGS= @@ -131,6 +134,18 @@ cat<<EOF>config.h  #define CPU "$cpu"  EOF + + +if [ -n "$target" ]; then +	PKG_CONFIG_LIBDIR=/usr/$target/lib/pkgconfig +	export PKG_CONFIG_LIBDIR +	PATH=/usr/$target/bin:$PATH +	CC=$target-cc +	LD=$target-ld +	systemlibdirs="/usr/$target/lib" +fi + +  if [ "$debug" = "1" ]; then  	[ -z "$CFLAGS" ] && CFLAGS=-g  	echo 'DEBUG=1' >> Makefile.settings @@ -157,15 +172,17 @@ fi  echo "CC=$CC" >> Makefile.settings; -if [ -n "$LD" ]; then -	echo "LD=$LD" >> Makefile.settings; -elif type ld > /dev/null 2> /dev/null; then -	echo "LD=ld" >> Makefile.settings; -else -	echo 'Cannot find ld, aborting.' -	exit 1; +if [ -z "$LD" ]; then +	if type ld > /dev/null 2> /dev/null; then +		LD=ld +	else +		echo 'Cannot find ld, aborting.' +		exit 1; +	fi  fi +echo "LD=$LD" >> Makefile.settings +  if [ -z "$PKG_CONFIG" ]; then  	PKG_CONFIG=pkg-config  fi @@ -212,7 +229,14 @@ echo 'EVENT_HANDLER=events_'$events'.o' >> Makefile.settings  detect_gnutls()  { -	if libgnutls-config --version > /dev/null 2> /dev/null; then +	if $PKG_CONFIG --exists gnutls; then +		cat <<EOF>>Makefile.settings +EFLAGS+=`$PKG_CONFIG --libs gnutls` +CFLAGS+=`$PKG_CONFIG --cflags gnutls` +EOF +		ssl=gnutls +		ret=1 +	elif libgnutls-config --version > /dev/null 2> /dev/null; then  		cat <<EOF>>Makefile.settings  EFLAGS+=`libgnutls-config --libs`  CFLAGS+=`libgnutls-config --cflags` @@ -266,6 +290,8 @@ elif [ "$ssl" = "gnutls" ]; then  	detect_gnutls  elif [ "$ssl" = "nss" ]; then  	detect_nss +elif [ "$ssl" = "sspi" ]; then +	echo  elif [ "$ssl" = "openssl" ]; then  	echo  	echo 'No detection code exists for OpenSSL. Make sure that you have a complete' @@ -322,7 +348,7 @@ fi;  echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings -for i in /lib /usr/lib /usr/local/lib; do +for i in $systemlibdirs; do  	if [ -f $i/libresolv.a ]; then  		echo '#define HAVE_RESOLV_A' >> config.h  		echo 'EFLAGS+='$i'/libresolv.a' >> Makefile.settings @@ -374,8 +400,8 @@ else  fi  if [ "$gcov" = "1" ]; then -	echo "CFLAGS+=-ftest-coverage -fprofile-arcs" >> Makefile.settings -	echo "EFLAGS+=-lgcov" >> Makefile.settings +	echo "CFLAGS+=--coverage" >> Makefile.settings +	echo "EFLAGS+=--coverage" >> Makefile.settings  fi  if [ "$plugins" = 0 ]; then @@ -482,12 +508,18 @@ AIX )  CYGWIN* )  	echo 'Cygwin is not officially supported.'  ;; +Windows ) +;;  * )  	echo 'We haven'\''t tested BitlBee on many platforms yet, yours is untested. YMMV.'  	echo 'Please report any problems at http://bugs.bitlbee.org/.'  ;;  esac +if [ -n "$target" ]; then +	echo "Cross-compiling for: $target" +fi +  echo  echo 'Configuration done:' diff --git a/debian/bitlbee.init b/debian/bitlbee.init index 904ae5ea..f8fac49c 100755 --- a/debian/bitlbee.init +++ b/debian/bitlbee.init @@ -43,7 +43,6 @@ d_start() {  	chown bitlbee /var/run/bitlbee.pid  	start-stop-daemon --start --quiet --pidfile $PIDFILE \ -		-c bitlbee: \  		--exec $DAEMON -- -p $BITLBEE_PORT -P $PIDFILE $BITLBEE_OPTS  } diff --git a/debian/changelog b/debian/changelog index f4b71762..a569f4f8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +bitlbee (1.2-6) UNRELEASED; urgency=low + +  * Add Homepage and Vcs-Bzr fields. + + -- Jelmer Vernooij <jelmer@samba.org>  Sun, 11 May 2008 14:18:16 +0200 + +bitlbee (1.2-5) unstable; urgency=low + +  * Add myself to uploaders. +  * Bump standards version to 3.8.0. +  * Fix FSF address. +  * Avoid changing uid from init script. (Closes: #474589) + + -- Jelmer Vernooij <jelmer@samba.org>  Mon, 16 Jun 2008 00:53:20 +0200 +  bitlbee (1.2-4) unstable; urgency=low    * Fixed init script to use the BITLBEE_OPTS variable, not an undefined diff --git a/debian/control b/debian/control index 8faa27b8..e6302c13 100644 --- a/debian/control +++ b/debian/control @@ -2,8 +2,12 @@ Source: bitlbee  Section: net  Priority: optional  Maintainer: Wilmer van der Gaast <wilmer@gaast.net> -Standards-Version: 3.5.9 +Uploaders: Jelmer Vernooij <jelmer@samba.org> +Standards-Version: 3.8.0  Build-Depends: libglib2.0-dev (>= 2.4), libevent-dev, libgnutls-dev | libnss-dev (>= 1.6), debconf-2.0, po-debconf +Homepage: http://www.bitlbee.org/ +Vcs-Bzr: http://code.bitlbee.org/bitlbee/ +DM-Upload-Allowed: yes  Package: bitlbee  Architecture: any diff --git a/debian/copyright b/debian/copyright index 40a777a9..03db5c7a 100644 --- a/debian/copyright +++ b/debian/copyright @@ -25,8 +25,8 @@ BitlBee License:    You should have received a copy of the GNU General Public License with    the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL; -  if not, write to the Free Software Foundation, Inc., 59 Temple Place, -  Suite 330, Boston, MA  02111-1307  USA +  if not, write to the Free Software Foundation, Inc., 51 Franklin St,  +  Fifth Floor, Boston, MA 02110-1301, USA.  ============================================================================ @@ -39,7 +39,7 @@ The SGML-formatted documentation is written by Jelmer Vernooij  		   Version 1.1, March 2000   Copyright (C) 2000  Free Software Foundation, Inc. -     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + 	51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.   Everyone is permitted to copy and distribute verbatim copies   of this license document, but changing it is not allowed. diff --git a/debian/rules b/debian/rules index 67cb79a3..661cf30e 100755 --- a/debian/rules +++ b/debian/rules @@ -21,7 +21,7 @@ build-arch-stamp:  clean:  	[ "`whoami`" = "root" -a -d debian ]  	rm -rf build-arch-stamp debian/bitlbee debian/*.substvars debian/files debian/bitlbee-dev -	-$(MAKE) distclean +	$(MAKE) distclean  #	-$(MAKE) -C doc/ clean diff --git a/doc/BUILD.win32 b/doc/BUILD.win32 new file mode 100644 index 00000000..e1afe600 --- /dev/null +++ b/doc/BUILD.win32 @@ -0,0 +1,10 @@ +Instructions for building BitlBee for Windows
 +=============================================
 +
 +1) Install the mingw32 compiler
 +
 +2) Compile GLib2 for the target i586-mingw32msvc
 +
 +3) Cross-compile BitlBee:
 +
 +$ ./configure --target=i586-mingw32msvc --ssl=bogus --arch=Windows
 diff --git a/doc/CHANGES b/doc/CHANGES index 93ad35e2..ac1f1f02 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -1,3 +1,8 @@ +This ChangeLog mostly lists changes relevant to users. A full log can be +found in the bzr commit logs, for example you can try: + +http://bugs.bitlbee.org/bitlbee/timeline?daysback=90&changeset=on +  Version 1.2.1:  - Fixed proxy support.  - Fixed stalling issues while connecting to Jabber when using the OpenSSL @@ -9,8 +14,22 @@ Version 1.2.1:  - You can now automatically identify yourself to BitlBee by setting a server    password in your IRC client.  - Compatible with all crazy kinds of line endings that clients can send. - -Finished ... +- Changed root nicknames are now saved. +- Added ClientInterface setting to bind() outgoing connections to a specific +  network interface. +- Support for receiving Jabber chatroom invitations. +- Relaxed port restriction of the Jabber module: added ports 80 and 443. +- Preserving case in Jabber resources of buddies, since these should +  officially be treated as case sensitive. +- Fully stripping spaces from AIM screennames, this didn't happen completely +  which severly breaks the IRC protocol. +- Removed all the yellow tape around daemon mode, it's pretty mature by now: +  testing.bitlbee.org serves all (~30) SSL users from one daemon mode +  process without any serious stability issues. +- Fixed GLib <2.6 compatibility issue. +- Misc. memory leak/crash fixes. + +Finished 24 Jun 2008  Version 1.2:  - Added ForkDaemon mode next to the existing Daemon- and inetd modes. With @@ -32,7 +32,6 @@  #endif  GSList *child_list = NULL; -static char *statefile = NULL;  static void ipc_master_cmd_client( irc_t *data, char **cmd )  { @@ -62,6 +61,25 @@ static void ipc_master_cmd_die( irc_t *data, char **cmd )  	bitlbee_shutdown( NULL, -1, 0 );  } +static void ipc_master_cmd_deaf( irc_t *data, char **cmd ) +{ +	if( global.conf->runmode == RUNMODE_DAEMON ) +	{ +		b_event_remove( global.listen_watch_source_id ); +		close( global.listen_socket ); +		 +		global.listen_socket = global.listen_watch_source_id = -1; +	 +		ipc_to_children_str( "OPERMSG :Closed listening socket, waiting " +		                     "for all users to disconnect." ); +	} +	else +	{ +		ipc_to_children_str( "OPERMSG :The DEAF command only works in " +		                     "normal daemon mode. Try DIE instead." ); +	} +} +  void ipc_master_cmd_rehash( irc_t *data, char **cmd )  {  	runmode_t oldmode; @@ -97,6 +115,7 @@ static const command_t ipc_master_commands[] = {  	{ "client",     3, ipc_master_cmd_client,     0 },  	{ "hello",      0, ipc_master_cmd_client,     0 },  	{ "die",        0, ipc_master_cmd_die,        0 }, +	{ "deaf",       0, ipc_master_cmd_deaf,       0 },  	{ "wallops",    1, NULL,                      IPC_CMD_TO_CHILDREN },  	{ "wall",       1, NULL,                      IPC_CMD_TO_CHILDREN },  	{ "opermsg",    1, NULL,                      IPC_CMD_TO_CHILDREN }, @@ -208,19 +227,19 @@ static void ipc_command_exec( void *data, char **cmd, const command_t *commands  		}  } +/* Return just one line. Returns NULL if something broke, an empty string +   on temporary "errors" (EAGAIN and friends). */  static char *ipc_readline( int fd )  { -	char *buf, *eol; +	char buf[513], *eol;  	int size; -	buf = g_new0( char, 513 ); -	  	/* Because this is internal communication, it should be pretty safe  	   to just peek at the message, find its length (by searching for the  	   end-of-line) and then just read that message. With internal  	   sockets and limites message length, messages should always be  	   complete. Saves us quite a lot of code and buffering. */ -	size = recv( fd, buf, 512, MSG_PEEK ); +	size = recv( fd, buf, sizeof( buf ) - 1, MSG_PEEK );  	if( size == 0 || ( size < 0 && !sockerr_again() ) )  		return NULL;  	else if( size < 0 ) /* && sockerr_again() */ @@ -228,21 +247,15 @@ static char *ipc_readline( int fd )  	else  		buf[size] = 0; -	eol = strstr( buf, "\r\n" ); -	if( eol == NULL ) +	if( ( eol = strstr( buf, "\r\n" ) ) == NULL )  		return NULL;  	else  		size = eol - buf + 2; -	g_free( buf ); -	buf = g_new0( char, size + 1 ); -	  	if( recv( fd, buf, size, 0 ) != size )  		return NULL;  	else -		buf[size-2] = 0; -	 -	return buf; +		return g_strndup( buf, size - 2 );  }  gboolean ipc_master_read( gpointer data, gint source, b_input_condition cond ) @@ -253,7 +266,11 @@ gboolean ipc_master_read( gpointer data, gint source, b_input_condition cond )  	{  		cmd = irc_parse_line( buf );  		if( cmd ) +		{  			ipc_command_exec( data, cmd, ipc_master_commands ); +			g_free( cmd ); +		} +		g_free( buf );  	}  	else  	{ @@ -271,7 +288,11 @@ gboolean ipc_child_read( gpointer data, gint source, b_input_condition cond )  	{  		cmd = irc_parse_line( buf );  		if( cmd ) +		{  			ipc_command_exec( data, cmd, ipc_child_commands ); +			g_free( cmd ); +		} +		g_free( buf );  	}  	else  	{ @@ -438,6 +459,7 @@ void ipc_child_disable()  	global.listen_socket = -1;  } +#ifndef _WIN32  char *ipc_master_save_state()  {  	char *fn = g_strdup( "/tmp/bee-restart.XXXXXX" ); @@ -478,11 +500,6 @@ char *ipc_master_save_state()  	}  } -void ipc_master_set_statefile( char *fn ) -{ -	statefile = g_strdup( fn ); -} -  static gboolean new_ipc_client( gpointer data, gint serversock, b_input_condition cond )  { @@ -503,7 +520,6 @@ static gboolean new_ipc_client( gpointer data, gint serversock, b_input_conditio  	return TRUE;  } -#ifndef _WIN32  int ipc_master_listen_socket()  {  	struct sockaddr_un un_addr; @@ -540,10 +556,14 @@ int ipc_master_listen_socket()  	return 1;  }  #else +int ipc_master_listen_socket() +{  	/* FIXME: Open named pipe \\.\BITLBEE */ +	return 0; +}  #endif -int ipc_master_load_state() +int ipc_master_load_state( char *statefile )  {  	struct bitlbee_child *child;  	FILE *fp; @@ -551,6 +571,7 @@ int ipc_master_load_state()  	if( statefile == NULL )  		return 0; +	  	fp = fopen( statefile, "r" );  	unlink( statefile );	/* Why do it later? :-) */  	if( fp == NULL ) @@ -57,8 +57,7 @@ void ipc_to_children_str( char *format, ... ) G_GNUC_PRINTF( 1, 2 );  void ipc_master_cmd_rehash( irc_t *data, char **cmd );  char *ipc_master_save_state(); -void ipc_master_set_statefile( char *fn ); -int ipc_master_load_state(); +int ipc_master_load_state( char *statefile );  int ipc_master_listen_socket();  extern GSList *child_list; @@ -25,6 +25,7 @@  #define BITLBEE_CORE  #include "bitlbee.h" +#include "sock.h"  #include "crypting.h"  #include "ipc.h"  #include "dcc.h" @@ -314,7 +315,11 @@ void irc_free( irc_t * irc )  	g_free( irc ); -	if( global.conf->runmode == RUNMODE_INETD || global.conf->runmode == RUNMODE_FORKDAEMON ) +	if( global.conf->runmode == RUNMODE_INETD || +	    global.conf->runmode == RUNMODE_FORKDAEMON || +	    ( global.conf->runmode == RUNMODE_DAEMON && +	      global.listen_socket == -1 && +	      irc_connection_list == NULL ) )  		b_main_quit();  } diff --git a/irc_commands.c b/irc_commands.c index 6a47007a..fb2bc7cf 100644 --- a/irc_commands.c +++ b/irc_commands.c @@ -625,6 +625,7 @@ static const command_t irc_commands[] = {  	{ "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 }, +	{ "deaf",        0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },  	{ "wallops",     1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },  	{ "wall",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },  	{ "rehash",      0, irc_cmd_rehash,      IRC_CMD_OPER_ONLY }, @@ -61,31 +61,6 @@ void strip_linefeed(gchar *text)  	g_free(text2);  } -char *normalize(const char *s) -{ -	static char buf[BUF_LEN]; -	char *t, *u; -	int x = 0; - -	g_return_val_if_fail((s != NULL), NULL); - -	u = t = g_strdup(s); - -	strcpy(t, s); -	g_strdown(t); - -	while (*t && (x < BUF_LEN - 1)) { -		if (*t != ' ') { -			buf[x] = *t; -			x++; -		} -		t++; -	} -	buf[x] = '\0'; -	g_free(u); -	return buf; -} -  time_t get_time(int year, int month, int day, int hour, int min, int sec)  {  	struct tm tm; @@ -397,6 +372,7 @@ signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t si     lack of entropy won't halt BitlBee. */  void random_bytes( unsigned char *buf, int count )  { +#ifndef _WIN32  	static int use_dev = -1;  	/* Actually this probing code isn't really necessary, is it? */ @@ -446,6 +422,7 @@ void random_bytes( unsigned char *buf, int count )  	}  	if( !use_dev ) +#endif  	{  		int i; @@ -606,13 +583,9 @@ int md5_verify_password( char *password, char *hash )  	md5_byte_t *pass_dec = NULL;  	md5_byte_t pass_md5[16];  	md5_state_t md5_state; -	int ret, i; +	int ret = -1, i; -	if( base64_decode( hash, &pass_dec ) != 21 ) -	{ -		ret = -1; -	} -	else +	if( base64_decode( hash, &pass_dec ) == 21 )  	{  		md5_init( &md5_state );  		md5_append( &md5_state, (md5_byte_t*) password, strlen( password ) ); @@ -40,7 +40,6 @@ struct ns_srv_reply  G_MODULE_EXPORT void strip_linefeed( gchar *text );  G_MODULE_EXPORT char *add_cr( char *text );  G_MODULE_EXPORT char *strip_newlines(char *source); -G_MODULE_EXPORT char *normalize( const char *s );  G_MODULE_EXPORT time_t get_time( int year, int month, int day, int hour, int min, int sec );  double gettime( void ); diff --git a/lib/ssl_bogus.c b/lib/ssl_bogus.c index 5bae3496..a07ea752 100644 --- a/lib/ssl_bogus.c +++ b/lib/ssl_bogus.c @@ -60,3 +60,8 @@ b_input_condition ssl_getdirection( void *conn )  {  	return GAIM_INPUT_READ;  } + +int ssl_pending( void *conn ) +{ +	return 0; +} diff --git a/lib/ssl_sspi.c b/lib/ssl_sspi.c new file mode 100644 index 00000000..a16423b1 --- /dev/null +++ b/lib/ssl_sspi.c @@ -0,0 +1,278 @@ +  /********************************************************************\ +  * BitlBee -- An IRC to other IM-networks gateway                     * +  *                                                                    * +  * Copyright 2002-2004 Wilmer van der Gaast and others                * +  \********************************************************************/ + +/* SSL module - SSPI backend */ + +/* Copyright (C) 2005 Jelmer Vernooij <jelmer@samba.org> */ + +/* +  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 "ssl_client.h" +#include <windows.h> +#define SECURITY_WIN32 +#include <security.h> +#include <sspi.h> +#include <schannel.h> +#include "sock.h" + +static gboolean initialized = FALSE; +int ssl_errno; + +struct scd +{ +	int fd; +	ssl_input_function func; +	gpointer data; +	gboolean established; +  	CredHandle cred;		/* SSL credentials */ +	CtxtHandle context;		/* SSL context */ +	SecPkgContext_StreamSizes sizes; + +	char *host; + +	char *pending_raw_data; +	gsize pending_raw_data_len; +	char *pending_data; +	gsize pending_data_len; +}; + +static void ssl_connected(gpointer, gint, GaimInputCondition); + +void sspi_global_init(void) +{ +	/* FIXME */ +} + +void sspi_global_deinit(void) +{ +	/* FIXME */ +} + +void *ssl_connect(char *host, int port, ssl_input_function func, gpointer data) +{ +	struct scd *conn = g_new0(struct scd, 1); +		 +	conn->fd = proxy_connect(host, port, ssl_connected, conn); +	sock_make_nonblocking(conn->fd); +	conn->func = func; +	conn->data = data; +	conn->host = g_strdup(host); +	 +	if (conn->fd < 0) +	{ +		g_free(conn); +		return NULL; +	} +	 +	if (!initialized) +	{ +		sspi_global_init(); +		initialized = TRUE; +		atexit(sspi_global_deinit); +	} + +	return conn; +} + +static void ssl_connected(gpointer _conn, gint fd, GaimInputCondition cond) +{ +	struct scd *conn = _conn; +	SCHANNEL_CRED ssl_cred; +	TimeStamp timestamp; +	SecBuffer ibuf[2],obuf[1]; +	SecBufferDesc ibufs,obufs; +	ULONG req = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | +    	ISC_REQ_CONFIDENTIALITY | ISC_REQ_USE_SESSION_KEY | +      	ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM | ISC_REQ_EXTENDED_ERROR | +		ISC_REQ_MANUAL_CRED_VALIDATION; +	ULONG a; +	gsize size = 0; +	gchar *data = NULL; + +	memset(&ssl_cred, 0, sizeof(SCHANNEL_CRED)); +	ssl_cred.dwVersion = SCHANNEL_CRED_VERSION; +	ssl_cred.grbitEnabledProtocols = SP_PROT_SSL3_CLIENT; + +	SECURITY_STATUS st = AcquireCredentialsHandle(NULL, UNISP_NAME, SECPKG_CRED_OUTBOUND, NULL, &ssl_cred, NULL, NULL, &conn->cred, ×tamp); + +	if (st != SEC_E_OK) { +		conn->func(conn->data, NULL, cond); +		return; +	} +	 +	do { +		/* initialize buffers */ +	    ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = data; +	    ibuf[1].cbBuffer = 0; ibuf[1].pvBuffer = NULL; +	    obuf[0].cbBuffer = 0; obuf[0].pvBuffer = NULL; +    	ibuf[0].BufferType = obuf[0].BufferType = SECBUFFER_TOKEN; +	    ibuf[1].BufferType = SECBUFFER_EMPTY; + +		/* initialize buffer descriptors */ +	    ibufs.ulVersion = obufs.ulVersion = SECBUFFER_VERSION; +	    ibufs.cBuffers = 2; obufs.cBuffers = 1; +	    ibufs.pBuffers = ibuf; obufs.pBuffers = obuf; + +		st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, conn->host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, ×tamp);   +    	if (obuf[0].pvBuffer && obuf[0].cbBuffer) { +			/* FIXME: Check return value */ +			send(conn->fd, obuf[0].pvBuffer, obuf[0].cbBuffer, 0); +		} + +		switch (st) { +		case SEC_I_INCOMPLETE_CREDENTIALS: +			break; +		case SEC_I_CONTINUE_NEEDED: +			break; +		case SEC_E_INCOMPLETE_MESSAGE: +			break; +		case SEC_E_OK: +			break; +		} +	 +		QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); +	} while (1); + +	conn->func(conn->data, conn, cond); +} + +int ssl_read(void *conn, char *retdata, int len) +{ +	struct scd *scd = conn; +	SecBufferDesc msg; +	SecBuffer buf[4]; +	int ret = -1, i; +	char *data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); + +	/* FIXME: Try to read some data */ + +  	msg.ulVersion = SECBUFFER_VERSION; +	msg.cBuffers = 4; +	msg.pBuffers = buf; +	 +	buf[0].BufferType = SECBUFFER_DATA; +	buf[0].cbBuffer = len; +	buf[0].pvBuffer = data; + +	buf[1].BufferType = SECBUFFER_EMPTY; +	buf[2].BufferType = SECBUFFER_EMPTY; +	buf[3].BufferType = SECBUFFER_EMPTY; + +	SECURITY_STATUS st = DecryptMessage(&scd->context, &msg, 0, NULL); + +	if (st != SEC_E_OK) { +		/* FIXME */ +		return -1; +	} + +	for (i = 0; i < 4; i++) { +		if (buf[i].BufferType == SECBUFFER_DATA) { +			memcpy(retdata, buf[i].pvBuffer, len); +			ret = len; +		}	 +	} + +	g_free(data); +	return -1; +} + +int ssl_write(void *conn, const char *userdata, int len) +{ +	struct scd *scd = conn; +	SecBuffer buf[4]; +	SecBufferDesc msg; +	char *data; +	int ret; + +	msg.ulVersion = SECBUFFER_VERSION; +	msg.cBuffers = 4; +	msg.pBuffers = buf; + +	data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); +	memcpy(data + scd->sizes.cbHeader, userdata, len); + +	buf[0].BufferType = SECBUFFER_STREAM_HEADER; +	buf[0].cbBuffer = scd->sizes.cbHeader; +	buf[0].pvBuffer = data; + +	buf[1].BufferType = SECBUFFER_DATA; +	buf[1].cbBuffer = len; +	buf[1].pvBuffer = data + scd->sizes.cbHeader; + +	buf[2].BufferType = SECBUFFER_STREAM_TRAILER; +	buf[2].cbBuffer = scd->sizes.cbTrailer; +	buf[2].pvBuffer = data + scd->sizes.cbHeader + len; +	buf[3].BufferType = SECBUFFER_EMPTY; + +	SECURITY_STATUS st = EncryptMessage(&scd->context, 0, &msg, 0); + +	ret = send(scd->fd, data,  +				buf[0].cbBuffer + buf[1].cbBuffer + buf[2].cbBuffer, 0); + +	g_free(data); + +	return ret; +} + +void ssl_disconnect(void *conn) +{ +	struct scd *scd = conn; + +	SecBufferDesc msg; +	SecBuffer buf; +	DWORD dw; + +	dw = SCHANNEL_SHUTDOWN; +	buf.cbBuffer = sizeof(dw); +	buf.BufferType = SECBUFFER_TOKEN; +	buf.pvBuffer = &dw; +	 +	msg.ulVersion = SECBUFFER_VERSION; +	msg.cBuffers = 1; +	msg.pBuffers = &buf; + +	SECURITY_STATUS st = ApplyControlToken(&scd->context, &msg); + +	if (st != SEC_E_OK) { +		/* FIXME */ +	} +	 +	/* FIXME: call InitializeSecurityContext(Schannel), passing  +	 * in empty buffers*/ + +	DeleteSecurityContext(&scd->context); + +	FreeCredentialsHandle(&scd->cred); + +	closesocket(scd->fd); +	g_free(scd->host); +	g_free(scd); +} + +int ssl_getfd(void *conn) +{ +	return ((struct scd*)conn)->fd; +} + +GaimInputCondition ssl_getdirection( void *conn ) +{ +	return GAIM_INPUT_WRITE; /* FIXME: or GAIM_INPUT_READ */ +} @@ -46,6 +46,7 @@ void nick_set( account_t *acc, const char *handle, const char *nick )  	char *store_handle, *store_nick = g_malloc( MAX_NICK_LENGTH + 1 );  	store_handle = clean_handle( handle ); +	store_nick[MAX_NICK_LENGTH] = 0;  	strncpy( store_nick, nick, MAX_NICK_LENGTH );  	nick_strip( store_nick ); diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 987ef96e..48f71ff1 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -32,15 +32,33 @@  #include "bitlbee.h"  #include "jabber.h"  #include "md5.h" -#include "base64.h"  GSList *jabber_connections; +/* First enty is the default */ +static const int jabber_port_list[] = { +	5222, +	5223, +	5220, +	5221, +	5224, +	5225, +	5226, +	5227, +	5228, +	5229, +	80, +	443, +	0 +}; +  static void jabber_init( account_t *acc )  {  	set_t *s; +	char str[16]; -	s = set_add( &acc->set, "port", JABBER_PORT_DEFAULT, set_eval_int, acc ); +	g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] ); +	s = set_add( &acc->set, "port", str, set_eval_int, acc );  	s->flags |= ACC_SET_OFFLINE_ONLY;  	s = set_add( &acc->set, "priority", "0", set_eval_priority, acc ); @@ -73,6 +91,7 @@ static void jabber_login( account_t *acc )  	struct jabber_data *jd = g_new0( struct jabber_data, 1 );  	struct ns_srv_reply *srv = NULL;  	char *connect_to, *s; +	int i;  	/* For now this is needed in the _connected() handlers if using  	   GLib event handling, to make sure we're not handling events @@ -178,11 +197,13 @@ static void jabber_login( account_t *acc )  	imcb_log( ic, "Connecting" ); -	if( set_getint( &acc->set, "port" ) < JABBER_PORT_MIN || -	    set_getint( &acc->set, "port" ) > JABBER_PORT_MAX ) +	for( i = 0; jabber_port_list[i] > 0; i ++ ) +		if( set_getint( &acc->set, "port" ) == jabber_port_list[i] ) +			break; + +	if( jabber_port_list[i] == 0 )  	{ -		imcb_log( ic, "Incorrect port number, must be in the %d-%d range", -		               JABBER_PORT_MIN, JABBER_PORT_MAX ); +		imcb_log( ic, "Illegal port number" );  		imc_logout( ic, FALSE );  		return;  	} @@ -220,24 +241,20 @@ static void jabber_login( account_t *acc )  	jabber_generate_id_hash( jd );  } +/* This generates an unfinished md5_state_t variable. Every time we generate +   an ID, we finish the state by adding a sequence number and take the hash. */  static void jabber_generate_id_hash( struct jabber_data *jd )  { -	md5_state_t id_hash; -	md5_byte_t binbuf[16]; +	md5_byte_t binbuf[4];  	char *s; -	md5_init( &id_hash ); -	md5_append( &id_hash, (unsigned char *) jd->username, strlen( jd->username ) ); -	md5_append( &id_hash, (unsigned char *) jd->server, strlen( jd->server ) ); +	md5_init( &jd->cached_id_prefix ); +	md5_append( &jd->cached_id_prefix, (unsigned char *) jd->username, strlen( jd->username ) ); +	md5_append( &jd->cached_id_prefix, (unsigned char *) jd->server, strlen( jd->server ) );  	s = set_getstr( &jd->ic->acc->set, "resource" ); -	md5_append( &id_hash, (unsigned char *) s, strlen( s ) ); -	random_bytes( binbuf, 16 ); -	md5_append( &id_hash, binbuf, 16 ); -	md5_finish( &id_hash, binbuf ); -	 -	s = base64_encode( binbuf, 9 ); -	jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s ); -	g_free( s ); +	md5_append( &jd->cached_id_prefix, (unsigned char *) s, strlen( s ) ); +	random_bytes( binbuf, 4 ); +	md5_append( &jd->cached_id_prefix, binbuf, 4 );  }  static void jabber_logout( struct im_connection *ic ) @@ -280,7 +297,6 @@ static void jabber_logout( struct im_connection *ic )  	xt_free( jd->xt ); -	g_free( jd->cached_id_prefix );  	g_free( jd->away_message );  	g_free( jd->username );  	g_free( jd ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index bc848170..cc12bdbb 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -93,7 +93,7 @@ struct jabber_data  	struct jabber_away_state *away_state;  	char *away_message; -	char *cached_id_prefix; +	md5_state_t cached_id_prefix;  	GHashTable *node_cache;  	GHashTable *buddies; @@ -177,10 +177,6 @@ struct jabber_transfer  #define JABBER_XMLCONSOLE_HANDLE "xmlconsole" -#define JABBER_PORT_DEFAULT "5222" -#define JABBER_PORT_MIN 5220 -#define JABBER_PORT_MAX 5229 -  /* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the     first one should be used, but when storing a packet in the cache, a     "special" kind of ID is assigned to make it easier later to figure out diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 23a3010f..9579a848 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -22,6 +22,8 @@  \***************************************************************************/  #include "jabber.h" +#include "md5.h" +#include "base64.h"  static unsigned int next_id = 1; @@ -137,11 +139,21 @@ void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_ca  {  	struct jabber_data *jd = ic->proto_data;  	struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 ); -	char *id; +	md5_state_t id_hash; +	md5_byte_t id_sum[16]; +	char *id, *asc_hash; -	id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff ); +	next_id ++; +	 +	id_hash = jd->cached_id_prefix; +	md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) ); +	md5_finish( &id_hash, id_sum ); +	asc_hash = base64_encode( id_sum, 12 ); +	 +	id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash );  	xt_add_attr( node, "id", id );  	g_free( id ); +	g_free( asc_hash );  	entry->node = node;  	entry->func = func; @@ -187,7 +199,7 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *  	char *s;  	if( ( s = xt_find_attr( node, "id" ) ) == NULL || -	    strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 ) +	    strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )  	{  		/* Silently ignore it, without an ID (or a non-cache  		   ID) we don't know how to handle the packet and we @@ -199,8 +211,14 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *  	if( entry == NULL )  	{ +		/* +		There's no longer an easy way to see if we generated this +		one or someone else, and there's a ten-minute timeout anyway, +		so meh. +		  		imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!",  		              node->name, xt_find_attr( node, "type" ) ? : "(no type)", s ); +		*/  	}  	else if( entry->func )  	{ @@ -293,14 +311,12 @@ char *jabber_normalize( const char *orig )  	len = strlen( orig );  	new = g_new( char, len + 1 ); -	for( i = 0; i < len; i ++ ) -	{ -		/* don't normalize the resource */ -		if( orig[i] == '/' ) -			break; +	 +	/* So it turns out the /resource part is case sensitive. Yeah, and +	   it's Unicode but feck Unicode. :-P So stop once we see a slash. */ +	for( i = 0; i < len && orig[i] != '/' ; i ++ )  		new[i] = tolower( orig[i] ); -	} -	for( ; i < len; i ++ ) +	for( ; orig[i]; i ++ )  		new[i] = orig[i];  	new[i] = 0; @@ -344,7 +360,7 @@ struct jabber_buddy *jabber_buddy_add( struct im_connection *ic, char *full_jid_  		for( bi = bud; bi; bi = bi->next )  		{  			/* Check for dupes. */ -			if( g_strcasecmp( bi->resource, s + 1 ) == 0 ) +			if( strcmp( bi->resource, s + 1 ) == 0 )  			{  				*s = '/';  				g_free( new ); @@ -397,7 +413,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,  	if( ( s = strchr( jid, '/' ) ) )  	{ -		int none_found = 0; +		int bare_exists = 0;  		*s = 0;  		if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) @@ -420,21 +436,19 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,  			/* See if there's an exact match. */  			for( ; bud; bud = bud->next ) -				if( g_strcasecmp( bud->resource, s + 1 ) == 0 ) +				if( strcmp( bud->resource, s + 1 ) == 0 )  					break;  		}  		else  		{ -			/* This hack is there to make sure that O_CREAT will -			   work if there's already another resouce present -			   for this JID, even if it's an unknown buddy. This -			   is done to handle conferences properly. */ -			none_found = 1; -			/* TODO(wilmer): Find out what I was thinking when I -			   wrote this??? And then fix it. This makes me sad... */ +			/* This variable tells the if down here that the bare +			   JID already exists and we should feel free to add +			   more resources, if the caller asked for that. */ +			bare_exists = 1;  		} -		if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) ) +		if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && +		    ( !bare_exists || imcb_find_buddy( ic, jid ) ) )  		{  			*s = '/';  			bud = jabber_buddy_add( ic, jid ); @@ -459,7 +473,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,  		else if( bud->resource && ( flags & GET_BUDDY_EXACT ) )  			/* We want an exact match, so in thise case there shouldn't be a /resource. */  			return NULL; -		else if( ( bud->resource == NULL || bud->next == NULL ) ) +		else if( bud->resource == NULL || bud->next == NULL )  			/* No need for selection if there's only one option. */  			return bud;  		else if( flags & GET_BUDDY_FIRST ) @@ -535,7 +549,9 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  		/* If there's only one item in the list (and if the resource  		   matches), removing it is simple. (And the hash reference  		   should be removed too!) */ -		if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) +		if( bud->next == NULL && +		    ( ( s == NULL && bud->resource == NULL ) || +		      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )  		{  			g_hash_table_remove( jd->buddies, bud->bare_jid );  			g_free( bud->bare_jid ); @@ -558,7 +574,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  		else  		{  			for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next ) -				if( g_strcasecmp( bi->resource, s + 1 ) == 0 ) +				if( strcmp( bi->resource, s + 1 ) == 0 )  					break;  			g_free( full_jid ); diff --git a/protocols/jabber/message.c b/protocols/jabber/message.c index fab62a91..6cb67d42 100644 --- a/protocols/jabber/message.c +++ b/protocols/jabber/message.c @@ -48,6 +48,23 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data )  	else /* "chat", "normal", "headline", no-type or whatever. Should all be pretty similar. */  	{  		GString *fullmsg = g_string_new( "" ); + +		for( c = node->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) +		{ +			char *ns = xt_find_attr( c, "xmlns" ), *room; +			struct xt_node *inv, *reason; +			 +			if( strcmp( ns, XMLNS_MUC_USER ) == 0 && +			    ( inv = xt_find_node( c->children, "invite" ) ) ) +			{ +				room = from; +				from = xt_find_attr( inv, "from" ) ? : from; + +				g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Invitation to chatroom %s >>\n", room ); +				if( ( reason = xt_find_node( inv->children, "reason" ) ) && reason->text_len > 0 ) +					g_string_append( fullmsg, reason->text ); +			} +		}  		if( ( s = strchr( from, '/' ) ) )  		{ diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index ffaa90a7..fe48f96d 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -277,11 +277,25 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts )  	{  		if( num_parts == 5 )  		{ -			md->buddycount = atoi( cmd[3] ); -			md->groupcount = atoi( cmd[4] ); -			if( md->groupcount > 0 ) +			int i, groupcount; +			 +			groupcount = atoi( cmd[4] ); +			if( groupcount > 0 ) +			{ +				/* valgrind says this is leaking memory, I'm guessing +				   that this happens during server redirects. */ +				if( md->grouplist ) +				{ +					for( i = 0; i < md->groupcount; i ++ ) +						g_free( md->grouplist[i] ); +					g_free( md->grouplist ); +				} +				 +				md->groupcount = groupcount;  				md->grouplist = g_new0( char *, md->groupcount ); +			} +			md->buddycount = atoi( cmd[3] );  			if( !*cmd[3] || md->buddycount == 0 )  				msn_logged_in( ic );  		} @@ -664,6 +678,9 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int  				{  					imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );  				} +				 +				g_free( inbox ); +				g_free( folders );  			}  			else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )  			{ diff --git a/protocols/nogaim.h b/protocols/nogaim.h index 17da2b36..5b094b3f 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -45,11 +45,6 @@  #include "md5.h"  #include "ft.h" -#define BUF_LEN MSG_LEN -#define BUF_LONG ( BUF_LEN * 2 ) -#define MSG_LEN 2048 -#define BUF_LEN MSG_LEN -  #define BUDDY_ALIAS_MAXLEN 388   /* because MSN names can be 387 characters */  #define WEBSITE "http://www.bitlbee.org/" diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 7738c31f..36e03166 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -60,6 +60,9 @@  #define OSCAR_GROUP "Friends" +#define BUF_LEN 2048 +#define BUF_LONG ( BUF_LEN * 2 ) +  /* Don't know if support for UTF8 is really working. For now it's UTF16 here.     static int gaim_caps = AIM_CAPS_UTF8; */ @@ -240,6 +243,32 @@ static char *msgerrreason[] = {  };  static int msgerrreasonlen = 25; +/* Hurray, this function is NOT thread-safe \o/ */ +static char *normalize(const char *s) +{ +	static char buf[BUF_LEN]; +	char *t, *u; +	int x = 0; + +	g_return_val_if_fail((s != NULL), NULL); + +	u = t = g_strdup(s); + +	strcpy(t, s); +	g_strdown(t); + +	while (*t && (x < BUF_LEN - 1)) { +		if (*t != ' ' && *t != '!') { +			buf[x] = *t; +			x++; +		} +		t++; +	} +	buf[x] = '\0'; +	g_free(u); +	return buf; +} +  static gboolean oscar_callback(gpointer data, gint source,  				b_input_condition condition) {  	aim_conn_t *conn = (aim_conn_t *)data; @@ -1001,13 +1030,13 @@ static int gaim_parse_oncoming(aim_session_t *sess, aim_frame_t *fr, ...) {  			g_hash_table_insert(od->ips, uin, (gpointer) (long) info->icqinfo.ipaddr);  	} -	tmp = g_strdup(normalize(ic->acc->user)); -	if (!strcmp(tmp, normalize(info->sn))) +	if (!aim_sncmp(ic->acc->user, info->sn))  		g_snprintf(ic->displayname, sizeof(ic->displayname), "%s", info->sn); -	g_free(tmp); -	imcb_buddy_status(ic, info->sn, flags, state_string, NULL); -	/* imcb_buddy_times(ic, info->sn, signon, time_idle); */ +	tmp = normalize(info->sn); +	imcb_buddy_status(ic, tmp, flags, state_string, NULL); +	/* imcb_buddy_times(ic, tmp, signon, time_idle); */ +  	return 1;  } @@ -1021,7 +1050,7 @@ static int gaim_parse_offgoing(aim_session_t *sess, aim_frame_t *fr, ...) {  	info = va_arg(ap, aim_userinfo_t *);  	va_end(ap); -	imcb_buddy_status(ic, info->sn, 0, NULL, NULL ); +	imcb_buddy_status(ic, normalize(info->sn), 0, NULL, NULL );  	return 1;  } @@ -1077,7 +1106,7 @@ static int incomingim_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_  	}  	strip_linefeed(tmp); -	imcb_buddy_msg(ic, userinfo->sn, tmp, flags, 0); +	imcb_buddy_msg(ic, normalize(userinfo->sn), tmp, flags, 0);  	g_free(tmp);  	return 1; @@ -1176,7 +1205,7 @@ static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_  			uin = g_strdup_printf("%u", args->uin);  			message = g_strdup(args->msg);  			strip_linefeed(message); -			imcb_buddy_msg(ic, uin, message, 0, 0); +			imcb_buddy_msg(ic, normalize(uin), message, 0, 0);  			g_free(uin);  			g_free(message);  		} break; @@ -1195,7 +1224,7 @@ static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_  			}  			strip_linefeed(message); -			imcb_buddy_msg(ic, uin, message, 0, 0); +			imcb_buddy_msg(ic, normalize(uin), message, 0, 0);  			g_free(uin);  			g_free(m);  			g_free(message); @@ -1470,7 +1499,7 @@ static int gaim_chat_join(aim_session_t *sess, aim_frame_t *fr, ...) {  		return 1;  	for (i = 0; i < count; i++) -		imcb_chat_add_buddy(c->cnv, info[i].sn); +		imcb_chat_add_buddy(c->cnv, normalize(info[i].sn));  	return 1;  } @@ -1493,7 +1522,7 @@ static int gaim_chat_leave(aim_session_t *sess, aim_frame_t *fr, ...) {  		return 1;  	for (i = 0; i < count; i++) -		imcb_chat_remove_buddy(c->cnv, info[i].sn, NULL); +		imcb_chat_remove_buddy(c->cnv, normalize(info[i].sn), NULL);  	return 1;  } @@ -1544,7 +1573,7 @@ static int gaim_chat_incoming_msg(aim_session_t *sess, aim_frame_t *fr, ...) {  	tmp = g_malloc(BUF_LONG);  	g_snprintf(tmp, BUF_LONG, "%s", msg); -	imcb_chat_msg(ccon->cnv, info->sn, tmp, 0, 0); +	imcb_chat_msg(ccon->cnv, normalize(info->sn), tmp, 0, 0);  	g_free(tmp);  	return 1; @@ -1757,7 +1786,7 @@ static int gaim_offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...) {  			time_t t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0);  			g_snprintf(sender, sizeof(sender), "%u", msg->sender);  			strip_linefeed(dialog_msg); -			imcb_buddy_msg(ic, sender, dialog_msg, 0, t); +			imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t);  			g_free(dialog_msg);  		} break; @@ -1778,7 +1807,7 @@ static int gaim_offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...) {  			}  			strip_linefeed(dialog_msg); -			imcb_buddy_msg(ic, sender, dialog_msg, 0, t); +			imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t);  			g_free(dialog_msg);  			g_free(m);  		} break; @@ -2016,23 +2045,26 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) {  	struct im_connection *ic = sess->aux_data;  	struct aim_ssi_item *curitem;  	int tmp; +	char *nrm;  	/* Add from server list to local list */  	tmp = 0;  	for (curitem=sess->ssi.items; curitem; curitem=curitem->next) { +		nrm = curitem->name ? normalize(curitem->name) : NULL; +		  		switch (curitem->type) {  			case 0x0000: /* Buddy */ -				if ((curitem->name) && (!imcb_find_buddy(ic, curitem->name))) { +				if ((curitem->name) && (!imcb_find_buddy(ic, nrm))) {  					char *realname = NULL;  					if (curitem->data && aim_gettlv(curitem->data, 0x0131, 1))  						    realname = aim_gettlv_str(curitem->data, 0x0131, 1); -					imcb_add_buddy(ic, curitem->name, NULL); +					imcb_add_buddy(ic, nrm, NULL);  					if (realname) { -						imcb_buddy_nick_hint(ic, curitem->name, realname); -						imcb_rename_buddy(ic, curitem->name, realname); +						imcb_buddy_nick_hint(ic, nrm, realname); +						imcb_rename_buddy(ic, nrm, realname);  						g_free(realname);  					}  				} @@ -2044,7 +2076,7 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) {  					for (list=ic->permit; (list && aim_sncmp(curitem->name, list->data)); list=list->next);  					if (!list) {  						char *name; -						name = g_strdup(normalize(curitem->name)); +						name = g_strdup(nrm);  						ic->permit = g_slist_append(ic->permit, name);  						tmp++;  					} @@ -2057,7 +2089,7 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) {  					for (list=ic->deny; (list && aim_sncmp(curitem->name, list->data)); list=list->next);  					if (!list) {  						char *name; -						name = g_strdup(normalize(curitem->name)); +						name = g_strdup(nrm);  						ic->deny = g_slist_append(ic->deny, name);  						tmp++;  					} @@ -2119,7 +2151,7 @@ static int gaim_ssi_parseack( aim_session_t *sess, aim_frame_t *fr, ... )  			st = aimbs_get16( &fr->data );  			if( st == 0x00 )  			{ -				imcb_add_buddy( sess->aux_data, list, NULL ); +				imcb_add_buddy( sess->aux_data, normalize(list), NULL );  			}  			else if( st == 0x0E )  			{ @@ -2449,15 +2481,15 @@ int gaim_parsemtn(aim_session_t *sess, aim_frame_t *fr, ...)  	if(type2 == 0x0002) {  		/* User is typing */ -		imcb_buddy_typing(ic, sn, OPT_TYPING); +		imcb_buddy_typing(ic, normalize(sn), OPT_TYPING);  	}   	else if (type2 == 0x0001) {  		/* User has typed something, but is not actively typing (stale) */ -		imcb_buddy_typing(ic, sn, OPT_THINKING); +		imcb_buddy_typing(ic, normalize(sn), OPT_THINKING);  	}  	else {  		/* User has stopped typing */ -		imcb_buddy_typing(ic, sn, 0); +		imcb_buddy_typing(ic, normalize(sn), 0);  	}  	return 1; diff --git a/protocols/yahoo/libyahoo2.c b/protocols/yahoo/libyahoo2.c index 80d88a85..a61955c4 100644 --- a/protocols/yahoo/libyahoo2.c +++ b/protocols/yahoo/libyahoo2.c @@ -68,8 +68,6 @@ char *strchr (), *strrchr ();  #ifdef __MINGW32__  # include <winsock2.h> -# define write(a,b,c) send(a,b,c,0) -# define read(a,b,c)  recv(a,b,c,0)  #endif  #include <stdlib.h> @@ -380,7 +378,6 @@ static void del_from_list(struct yahoo_data *yd)  }  /* call repeatedly to get the next one */ -/*  static struct yahoo_input_data * find_input_by_id(int id)  {  	YList *l; @@ -391,7 +388,6 @@ static struct yahoo_input_data * find_input_by_id(int id)  	}  	return NULL;  } -*/  static struct yahoo_input_data * find_input_by_id_and_webcam_user(int id, const char * who)  { @@ -796,6 +792,7 @@ static int yahoo_send_data(int fd, void *data, int len)  void yahoo_close(int id)   {  	struct yahoo_data *yd = find_conn_by_id(id); +	  	if(!yd)  		return; @@ -3165,7 +3162,7 @@ int yahoo_write_ready(int id, int fd, void *data)  	struct data_queue *tx;  	LOG(("write callback: id=%d fd=%d data=%p", id, fd, data)); -	if(!yid || !yid->txqueues) +	if(!yid || !yid->txqueues || !find_conn_by_id(id))  		return -2;  	tx = yid->txqueues->data; @@ -3841,11 +3838,9 @@ void yahoo_logoff(int id)  		}  	} -	 -/*	do { +	do {  		yahoo_input_close(yid); -	} while((yid = find_input_by_id(id)));*/ -	 +	} while((yid = find_input_by_id(id)));  }  void yahoo_get_list(int id) diff --git a/protocols/yahoo/yahoo.c b/protocols/yahoo/yahoo.c index ab30df4d..8d9e95d8 100644 --- a/protocols/yahoo/yahoo.c +++ b/protocols/yahoo/yahoo.c @@ -162,10 +162,7 @@ static void byahoo_logout( struct im_connection *ic )  	}  	g_slist_free( yd->buddygroups ); -	if( yd->logged_in ) -		yahoo_logoff( yd->y2_id ); -	else -		yahoo_close( yd->y2_id ); +	yahoo_logoff( yd->y2_id );  	g_free( yd );  } @@ -453,10 +450,6 @@ gboolean byahoo_write_ready_callback( gpointer data, gint source, b_input_condit  {  	struct byahoo_write_ready_data *d = data; -	if( !byahoo_get_ic_by_id( d->id ) ) -		/* WTF doesn't libyahoo clean this up? */ -		return FALSE; -	  	yahoo_write_ready( d->id, d->fd, d->data );  	return FALSE; @@ -671,9 +664,6 @@ void ext_yahoo_error( int id, const char *err, int fatal, int num )  	struct im_connection *ic = byahoo_get_ic_by_id( id );  	imcb_error( ic, "%s", err ); -	 -	if( fatal ) -		imc_logout( ic, TRUE );  }  /* TODO: Clear up the mess of inp and d structures */ diff --git a/protocols/yahoo/yahoo_httplib.c b/protocols/yahoo/yahoo_httplib.c index dbbe2a84..1b084992 100644 --- a/protocols/yahoo/yahoo_httplib.c +++ b/protocols/yahoo/yahoo_httplib.c @@ -50,8 +50,6 @@ char *strchr (), *strrchr ();  #include "yahoo_debug.h"  #ifdef __MINGW32__  # include <winsock2.h> -# define write(a,b,c) send(a,b,c,0) -# define read(a,b,c)  recv(a,b,c,0)  # define snprintf _snprintf  #endif @@ -15,17 +15,11 @@  #endif  #else  # include <winsock2.h> -# ifndef _MSC_VER -#  include <ws2tcpip.h> -# endif +# include <ws2tcpip.h>  # if !defined(BITLBEE_CORE) && defined(_MSC_VER)  #   pragma comment(lib,"bitlbee.lib")  # endif  # include <io.h> -# define read(a,b,c) recv(a,b,c,0) -# define write(a,b,c) send(a,b,c,0) -# define umask _umask -# define mode_t int  # define sock_make_nonblocking(fd) { int non_block = 1; ioctlsocket(fd, FIONBIO, &non_block); }  # define sock_make_blocking(fd) { int non_block = 0; ioctlsocket(fd, FIONBIO, &non_block); }  # define sockerr_again() (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK) diff --git a/storage_text.c b/storage_text.c index 5ee6438d..78f7e3bd 100644 --- a/storage_text.c +++ b/storage_text.c @@ -26,6 +26,14 @@  #define BITLBEE_CORE  #include "bitlbee.h"  #include "crypting.h" +#ifdef _WIN32 +# define umask _umask +# define mode_t int +#endif + +#ifndef F_OK +#define F_OK 0 +#endif  static void text_init (void)  { diff --git a/storage_xml.c b/storage_xml.c index f37fce44..240206f1 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -28,6 +28,12 @@  #include "base64.h"  #include "arc.h"  #include "md5.h" +#include <glib/gstdio.h> + +#if !GLIB_CHECK_VERSION(2,8,0) +/* GLib < 2.8.0 doesn't have g_access, so just use the system access(). */ +#define g_access access +#endif  typedef enum  { @@ -242,9 +248,10 @@ GMarkupParser xml_parser =  static void xml_init( void )  { -	if( access( global.conf->configdir, F_OK ) != 0 ) +	if( g_access( global.conf->configdir, F_OK ) != 0 )  		log_message( LOGLVL_WARNING, "The configuration directory `%s' does not exist. Configuration won't be saved.", global.conf->configdir ); -	else if( access( global.conf->configdir, R_OK ) != 0 || access( global.conf->configdir, W_OK ) != 0 ) +	else if( g_access( global.conf->configdir, F_OK ) != 0 ||  +	         g_access( global.conf->configdir, W_OK ) != 0 )  		log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to `%s'.", global.conf->configdir );  } @@ -371,7 +378,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )  	g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, path2, ".xml" );  	g_free( path2 ); -	if( !overwrite && access( path, F_OK ) != -1 ) +	if( !overwrite && g_access( path, F_OK ) == 0 )  		return STORAGE_ALREADY_EXISTS;  	strcat( path, "~" ); @@ -479,14 +486,18 @@ static gboolean xml_save_nick( gpointer key, gpointer value, gpointer data )  static storage_status_t xml_remove( const char *nick, const char *password )  { -	char s[512]; +	char s[512], *lc;  	storage_status_t status;  	status = xml_check_pass( nick, password );  	if( status != STORAGE_OK )  		return status; -	g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".xml" ); +	lc = g_strdup( nick ); +	nick_lc( lc ); +	g_snprintf( s, 511, "%s%s%s", global.conf->configdir, lc, ".xml" ); +	g_free( lc ); +	  	if( unlink( s ) == -1 )  		return STORAGE_OTHER_ERROR; diff --git a/tests/Makefile b/tests/Makefile index ae76fef5..db145503 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -12,7 +12,7 @@ distclean: clean  main_objs = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o storage_text.o user.o -test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o check_jabber_sasl.o +test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o check_jabber_sasl.o check_jabber_util.o  check: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o  	@echo '*' Linking $@ diff --git a/tests/check.c b/tests/check.c index b3ffb957..874acdd2 100644 --- a/tests/check.c +++ b/tests/check.c @@ -68,6 +68,9 @@ Suite *set_suite(void);  /* From check_jabber_sasl.c */  Suite *jabber_sasl_suite(void); +/* From check_jabber_sasl.c */ +Suite *jabber_util_suite(void); +  int main (int argc, char **argv)  {  	int nf; @@ -114,6 +117,7 @@ int main (int argc, char **argv)  	srunner_add_suite(sr, crypting_suite());  	srunner_add_suite(sr, set_suite());  	srunner_add_suite(sr, jabber_sasl_suite()); +	srunner_add_suite(sr, jabber_util_suite());  	if (no_fork)  		srunner_set_fork_status(sr, CK_NOFORK);  	srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL); diff --git a/tests/check_jabber_sasl.c b/tests/check_jabber_sasl.c index 6bceeb88..63118d39 100644 --- a/tests/check_jabber_sasl.c +++ b/tests/check_jabber_sasl.c @@ -4,7 +4,6 @@  #include <check.h>  #include <string.h>  #include <stdio.h> -#include "arc.h"  char *sasl_get_part( char *data, char *field ); diff --git a/tests/check_jabber_util.c b/tests/check_jabber_util.c new file mode 100644 index 00000000..4728c5ee --- /dev/null +++ b/tests/check_jabber_util.c @@ -0,0 +1,91 @@ +#include <stdlib.h> +#include <glib.h> +#include <gmodule.h> +#include <check.h> +#include <string.h> +#include <stdio.h> +#include "jabber/jabber.h" + +static struct im_connection *ic; + +static void check_buddy_add(int l) +{ +	struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud; +	 +	budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" ); +	budw1->last_act = time( NULL ) - 100; +	budw2 = jabber_buddy_add( ic, "WILMER@gaast.net/Telepathy" ); +	budw2->priority = 2; +	budw2->last_act = time( NULL ); +	budw3 = jabber_buddy_add( ic, "wilmer@GAAST.NET/bitlbee" ); +	budw3->last_act = time( NULL ) - 200; +	budw3->priority = 4; +	/* TODO(wilmer): Shouldn't this just return budw3? */ +	fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ) != NULL ); +	 +	budn = jabber_buddy_add( ic, "nekkid@lamejab.net" ); +	/* Shouldn't be allowed if there's already a bare JID. */ +	fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ) ); +	 +	/* Case sensitivity: Case only matters after the / */ +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == +	         jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", 0 ) ); +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/telepathy", 0 ) ); +	 +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 ); +	fail_unless( jabber_buddy_by_jid( ic, "WILMER@GAAST.NET/BitlBee", GET_BUDDY_EXACT ) == budw1 ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/BitlBee", GET_BUDDY_CREAT ) == budw1 ); + +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) ); +	fail_unless( jabber_buddy_by_jid( ic, "WILMER@gaast.net", 0 ) == budw3 ); + +	/* Check O_FIRST and see if it's indeed the first item from the list. */ +	fail_unless( ( bud = jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) ) == budw1 ); +	fail_unless( bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL ); +	 +	/* Change the resource_select setting, now we should get a different resource. */ +	set_setstr( &ic->acc->set, "resource_select", "activity" ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET", 0 ) == budw2 ); +	 +	/* Some testing of bare JID handling (which is horrible). */ +	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ) ); +	fail_if( jabber_buddy_by_jid( ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT ) ); +	fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn ); +	fail_unless( jabber_buddy_by_jid( ic, "NEKKID@lamejab.net", GET_BUDDY_EXACT ) == budn ); +	fail_unless( jabber_buddy_by_jid( ic, "nekkid@LAMEJAB.NET", GET_BUDDY_CREAT ) == budn ); +	 +	/* More case sensitivity testing, and see if remove works properly. */ +	fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) ); +	fail_if( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/telepathy", GET_BUDDY_CREAT ) == budw2 ); +	fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/Telepathy" ) ); +	fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); +	 +	fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); +	 +	/* Check if remove_bare() indeed gets rid of all. */ +	fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) ); +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) ); + +	fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ) ); +	fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ) ); +	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) ); +} + +Suite *jabber_util_suite (void) +{ +	Suite *s = suite_create("jabber/util"); +	TCase *tc_core = tcase_create("Buddy"); +	struct jabber_data *jd; +	 +	ic = g_new0( struct im_connection, 1 ); +	ic->acc = g_new0( account_t, 1 ); +	ic->proto_data = jd = g_new0( struct jabber_data, 1 ); +	jd->buddies = g_hash_table_new( g_str_hash, g_str_equal ); +	set_add( &ic->acc->set, "resource_select", "priority", NULL, ic->acc ); +	 +	suite_add_tcase (s, tc_core); +	tcase_add_test (tc_core, check_buddy_add); +	return s; +} @@ -39,7 +39,7 @@ global_t global;	/* Against global namespace pollution */  static void sighandler( int signal ); -int main( int argc, char *argv[], char **envp ) +int main( int argc, char *argv[] )  {  	int i = 0;  	char *old_cwd = NULL; @@ -59,12 +59,18 @@ int main( int argc, char *argv[], char **envp )  	if( global.conf->runmode == RUNMODE_INETD )  	{ +		log_link( LOGLVL_ERROR, LOGOUTPUT_IRC ); +		log_link( LOGLVL_WARNING, LOGOUTPUT_IRC ); +	  		i = bitlbee_inetd_init();  		log_message( LOGLVL_INFO, "Bitlbee %s starting in inetd mode.", BITLBEE_VERSION );  	}  	else if( global.conf->runmode == RUNMODE_DAEMON )  	{ +		log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); +		log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); +  		i = bitlbee_daemon_init();  		log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION );  	} @@ -134,30 +140,19 @@ int main( int argc, char *argv[], char **envp )  	if( global.restart )  	{  		char *fn = ipc_master_save_state(); -		char **args; -		int n, i;  		chdir( old_cwd ); -		n = 0; -		args = g_new0( char *, argc + 3 ); -		args[n++] = argv[0]; -		if( fn ) -		{ -			args[n++] = "-R"; -			args[n++] = fn; -		} -		for( i = 1; argv[i] && i < argc; i ++ ) -		{ -			if( strcmp( argv[i], "-R" ) == 0 ) -				i += 2; -			 -			args[n++] = argv[i]; -		} +		setenv( "_BITLBEE_RESTART_STATE", fn, 1 ); +		g_free( fn );  		close( global.listen_socket ); -		execve( args[0], args, envp ); +		if( execv( argv[0], argv ) == -1 ) +			/* Apparently the execve() failed, so let's just +			   jump back into our own/current main(). */ +			/* Need more cleanup code to make this work. */ +			return 1; /* main( argc, argv ); */  	}  	return( 0 ); @@ -218,3 +213,5 @@ double gettime()  	gettimeofday( time, 0 );  	return( (double) time->tv_sec + (double) time->tv_usec / 1000000 );  } + + diff --git a/win32.c b/win32.c new file mode 100644 index 00000000..4ab1d522 --- /dev/null +++ b/win32.c @@ -0,0 +1,332 @@ +  /********************************************************************\ +  * BitlBee -- An IRC to other IM-networks gateway					 * +  *																	* +  * Copyright 2002-2004 Wilmer van der Gaast and others				* +  \********************************************************************/ + +/* Main file (Windows specific part)								   */ + +/* +  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 "commands.h" +#include "crypting.h" +#include "protocols/nogaim.h" +#include "help.h" +#include <signal.h> +#include <windows.h> + +global_t global;	/* Against global namespace pollution */ + +static void WINAPI service_ctrl (DWORD dwControl) +{ +	switch (dwControl) +	{ +		case SERVICE_CONTROL_STOP: +			/* FIXME */ +			break; + +		case SERVICE_CONTROL_INTERROGATE: +			break; + +		default: +			break; + +	} +} + +static void bitlbee_init(int argc, char **argv) +{ +	int i = -1; +	memset( &global, 0, sizeof( global_t ) ); + +	b_main_init(); +	 +	global.conf = conf_load( argc, argv ); +	if( global.conf == NULL ) +		return; +	 +	if( global.conf->runmode == RUNMODE_INETD ) +	{ +		i = bitlbee_inetd_init(); +		log_message( LOGLVL_INFO, "Bitlbee %s starting in inetd mode.", BITLBEE_VERSION ); + +	} +	else if( global.conf->runmode == RUNMODE_DAEMON ) +	{ +		i = bitlbee_daemon_init(); +		log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION ); +	}  +	else  +	{ +		log_message( LOGLVL_INFO, "No bitlbee mode specified..."); +	} +	 +	if( i != 0 ) +		return; + 	 +	if( access( global.conf->configdir, F_OK ) != 0 ) +		log_message( LOGLVL_WARNING, "The configuration directory %s does not exist. Configuration won't be saved.", global.conf->configdir ); +	else if( access( global.conf->configdir, 06 ) != 0 ) +		log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to %s.", global.conf->configdir ); +	if( help_init( &(global.help), HELP_FILE ) == NULL ) +		log_message( LOGLVL_WARNING, "Error opening helpfile %s.", global.helpfile ); +} + +void service_main (DWORD argc, LPTSTR *argv) +{ +	SERVICE_STATUS_HANDLE handle; +	SERVICE_STATUS status; + +	handle = RegisterServiceCtrlHandler("bitlbee", service_ctrl); + +	if (!handle) +		return; + +	status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; +	status.dwServiceSpecificExitCode = 0; + +	bitlbee_init(argc, argv); + +	SetServiceStatus(handle, &status); +	 +	b_main_run( ); +} + +SERVICE_TABLE_ENTRY dispatch_table[] = +{ +   { TEXT("bitlbee"), (LPSERVICE_MAIN_FUNCTION)service_main }, +   { NULL, NULL } +}; + +static int debug = 0; + +static void usage() +{ +	printf("Options:\n"); +	printf("-h   Show this help message\n"); +	printf("-d   Debug mode (simple console program)\n"); +} + +int main( int argc, char **argv) +{	 +	int i; +	WSADATA WSAData; + +	nogaim_init( ); + +	for (i = 1; i < argc; i++) { +		if (!strcmp(argv[i], "-d")) debug = 1; +		if (!strcmp(argv[i], "-h")) { +			usage(); +			return 0; +		} +	} + +	WSAStartup(MAKEWORD(1,1), &WSAData); + +	if (!debug) { +		if (!StartServiceCtrlDispatcher(dispatch_table)) +			log_message( LOGLVL_ERROR, "StartServiceCtrlDispatcher failed."); +	} else { +			bitlbee_init(argc, argv); + 			b_main_run(); +	} +	 +	return 0; +} + +double gettime() +{ +	return (GetTickCount() / 1000); +} + +void conf_get_string(HKEY section, const char *name, const char *def, char **dest) +{ +	char buf[4096]; +	long x; +	if (RegQueryValue(section, name, buf, &x) == ERROR_SUCCESS) { +		*dest = g_strdup(buf); +	} else if (!def) { +		*dest = NULL; +	} else { +		*dest = g_strdup(def); +	} +} + + +void conf_get_int(HKEY section, const char *name, int def, int *dest) +{ +	char buf[20]; +	long x; +	DWORD y; +	if (RegQueryValue(section, name, buf, &x) == ERROR_SUCCESS) { +		memcpy(&y, buf, sizeof(DWORD)); +		*dest = y; +	} else { +		*dest = def; +	} +} + +conf_t *conf_load( int argc, char *argv[] )  +{ +	conf_t *conf; +	HKEY key, key_main, key_proxy; +	char *tmp; + +	RegOpenKey(HKEY_CURRENT_USER, "SOFTWARE\\Bitlbee", &key); +	RegOpenKey(key, "main", &key_main); +	RegOpenKey(key, "proxy", &key_proxy); +	 +	memset( &global, 0, sizeof( global_t ) ); +	b_main_init(); + +	conf = g_new0( conf_t,1 ); +	global.conf = conf; +	conf_get_string(key_main, "interface_in", "0.0.0.0", &global.conf->iface_in); +	conf_get_string(key_main, "interface_out", "0.0.0.0", &global.conf->iface_out); +	conf_get_string(key_main, "port", "6667", &global.conf->port); +	conf_get_int(key_main, "verbose", 0, &global.conf->verbose); +	conf_get_string(key_main, "auth_pass", "", &global.conf->auth_pass); +	conf_get_string(key_main, "oper_pass", "", &global.conf->oper_pass); +	conf_get_int(key_main, "ping_interval_timeout", 60, &global.conf->ping_interval); +	conf_get_string(key_main, "hostname", "localhost", &global.conf->hostname); +	conf_get_string(key_main, "configdir", NULL, &global.conf->configdir); +	conf_get_string(key_main, "motdfile", NULL, &global.conf->motdfile); +	conf_get_string(key_main, "helpfile", NULL, &global.helpfile); +	global.conf->runmode = RUNMODE_DAEMON; +	conf_get_int(key_main, "AuthMode", AUTHMODE_OPEN, (int *)&global.conf->authmode); +	conf_get_string(key_proxy, "host", "", &tmp); strcpy(proxyhost, tmp); +	conf_get_string(key_proxy, "user", "", &tmp); strcpy(proxyuser, tmp); +	conf_get_string(key_proxy, "password", "", &tmp); strcpy(proxypass, tmp); +	conf_get_int(key_proxy, "type", PROXY_NONE, &proxytype); +	conf_get_int(key_proxy, "port", 3128, &proxyport); + +	RegCloseKey(key); +	RegCloseKey(key_main); +	RegCloseKey(key_proxy); + +	return conf; +} + +void conf_loaddefaults( irc_t *irc ) +{ +	HKEY key_defaults; +	int i; +	char name[4096], data[4096]; +	DWORD namelen = sizeof(name), datalen = sizeof(data); +	DWORD type; +	if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Bitlbee\\defaults", &key_defaults) != ERROR_SUCCESS) { +		return; +	} + +	for (i = 0; RegEnumValue(key_defaults, i, name, &namelen, NULL, &type, data, &datalen) == ERROR_SUCCESS; i++) { +		set_t *s = set_find( &irc->set, name ); +			 +		if( s ) +		{ +			if( s->def ) g_free( s->def ); +			s->def = g_strdup( data ); +		} + +		namelen = sizeof(name); +		datalen = sizeof(data); +	} + +	RegCloseKey(key_defaults); +} + +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + +int +inet_aton(const char *cp, struct in_addr *addr) +{ +  addr->s_addr = inet_addr(cp); +  return (addr->s_addr == INADDR_NONE) ? 0 : 1; +} + +void log_error(char *msg) +{ +	log_message(LOGLVL_ERROR, "%s", msg); +} + +void log_message(int level, char *message, ...) +{ +	HANDLE  hEventSource; +	LPTSTR  lpszStrings[2]; +	WORD elevel; +	va_list ap; + +	va_start(ap, message); + +	if (debug) { +		vprintf(message, ap); +		putchar('\n'); +		va_end(ap); +		return; +	} + +	hEventSource = RegisterEventSource(NULL, TEXT("bitlbee")); + +	lpszStrings[0] = TEXT("bitlbee"); +	lpszStrings[1] = g_strdup_vprintf(message, ap); +	va_end(ap); + +	switch (level) { +	case LOGLVL_ERROR: elevel = EVENTLOG_ERROR_TYPE; break; +	case LOGLVL_WARNING: elevel = EVENTLOG_WARNING_TYPE; break; +	case LOGLVL_INFO: elevel = EVENTLOG_INFORMATION_TYPE; break; +#ifdef DEBUG +	case LOGLVL_DEBUG: elevel = EVENTLOG_AUDIT_SUCCESS; break; +#endif +	} + +	if (hEventSource != NULL) { +		ReportEvent(hEventSource,  +		elevel, +		0,					 +		0,					 +		NULL,				  +		2,					 +		0,					 +		lpszStrings,		   +		NULL);				 + +		DeregisterEventSource(hEventSource); +	} + +	g_free(lpszStrings[1]); +} + +void log_link(int level, int output) { /* FIXME */ } + +struct tm * +gmtime_r (const time_t *timer, struct tm *result) +{ +	struct tm *local_result; +	local_result = gmtime (timer); + +	if (local_result == NULL || result == NULL) +		return NULL; + +	memcpy (result, local_result, sizeof (result)); +	return result; +}  | 
