diff options
43 files changed, 622 insertions, 797 deletions
@@ -9,19 +9,11 @@ -include Makefile.settings # Program variables -objects = bitlbee.o dcc.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o irc_util.o nick.o $(OTR_BI) query.o root_commands.o set.o storage.o $(STORAGE_OBJS) -headers = bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/json.h lib/json_util.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/account.h protocols/bee.h protocols/ft.h protocols/nogaim.h +objects = bitlbee.o dcc.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o irc_util.o nick.o $(OTR_BI) query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o conf.o log.o +headers = $(wildcard $(_SRCDIR_)*.h $(_SRCDIR_)lib/*.h $(_SRCDIR_)protocols/*.h) subdirs = lib protocols -ifeq ($(TARGET),i586-mingw32msvc) -objects += win32.o -LDFLAGS+=-lws2_32 -EFLAGS+=-lsecur32 -OUTFILE=bitlbee.exe -else -objects += unix.o conf.o log.o -OUTFILE=bitlbee -endif +OUTFILE = bitlbee # Expansion of variables subdirobjs = $(foreach dir,$(subdirs),$(dir)/$(dir).o) @@ -101,7 +93,7 @@ uninstall-bin: install-dev: mkdir -p $(DESTDIR)$(INCLUDEDIR) $(INSTALL) -m 0644 config.h $(DESTDIR)$(INCLUDEDIR) - for i in $(headers); do $(INSTALL) -m 0644 $(_SRCDIR_)$$i $(DESTDIR)$(INCLUDEDIR); done + for i in $(headers); do $(INSTALL) -m 0644 $$i $(DESTDIR)$(INCLUDEDIR); done mkdir -p $(DESTDIR)$(PCDIR) $(INSTALL) -m 0644 bitlbee.pc $(DESTDIR)$(PCDIR) @@ -148,14 +140,12 @@ endif install-systemd: systemd ifdef SYSTEMDSYSTEMUNITDIR -ifeq ($(shell id -u),0) mkdir -p $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR) $(INSTALL) -m 0644 init/bitlbee.service $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR) $(INSTALL) -m 0644 init/bitlbee@.service $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR) $(INSTALL) -m 0644 $(_SRCDIR_)init/bitlbee.socket $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR) else - @echo Not root, so not installing systemd files. -endif + @echo SYSTEMDSYSTEMUNITDIR not set, not installing systemd unit files. endif tar: @@ -126,7 +126,6 @@ int bitlbee_daemon_init() global.listen_watch_source_id = b_input_add( global.listen_socket, B_EV_IO_READ, bitlbee_io_new_client, NULL ); -#ifndef _WIN32 if( !global.conf->nofork ) { i = fork(); @@ -150,7 +149,6 @@ int bitlbee_daemon_init() open( "/dev/null", O_WRONLY ); } } -#endif if( global.conf->runmode == RUNMODE_FORKDAEMON ) ipc_master_load_state( getenv( "_BITLBEE_RESTART_STATE" ) ); @@ -158,7 +156,6 @@ int bitlbee_daemon_init() 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() ); @@ -168,7 +165,6 @@ int bitlbee_daemon_init() { log_message( LOGLVL_WARNING, "Warning: Couldn't write PID to `%s'", global.conf->pidfile ); } -#endif if( !global.conf->nofork ) { @@ -294,7 +290,6 @@ 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; @@ -356,7 +351,6 @@ 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 ); @@ -34,9 +34,6 @@ extern "C" { #define _GNU_SOURCE /* Stupid GNU :-P */ #endif -/* Depend on Windows 2000 for now since we need getaddrinfo() */ -#define _WIN32_WINNT 0x0501 - #define PACKAGE "BitlBee" #define BITLBEE_VERSION "3.2.2" #define VERSION BITLBEE_VERSION @@ -59,11 +56,7 @@ extern "C" { #include <stdio.h> #include <ctype.h> #include <errno.h> - -#ifndef _WIN32 #include <syslog.h> -#endif - #include <glib.h> #include <gmodule.h> @@ -340,16 +340,52 @@ RESOLV_TESTCODE=' int main() { + + res_query( NULL, 0, 0, NULL, 0); + dn_expand( NULL, NULL, NULL, NULL, 0); + dn_skipname( NULL, NULL); +} +' +RESOLV_NS_TESTCODE=' +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/nameser.h> +#include <resolv.h> + +int main() +{ ns_initparse( NULL, 0, NULL ); ns_parserr( NULL, ns_s_an, 0, NULL ); } ' +RESOLV_NS_TYPES_TESTCODE=' +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/nameser.h> + +int main() +{ + ns_msg nsh; + ns_rr rr; + + /* Not all platforms we want to work on have + ns_* routines, so use this to make sure + the compiler uses it.*/ + return (int)(sizeof(nsh) + sizeof(rr)); +} +' detect_resolv_dynamic() { case "$arch" in + OpenBSD ) + # In FreeBSD res_*/dn_* routines are present in libc.so + LIBRESOLV=;; FreeBSD ) - # In FreeBSD res_* routines are present in libc.so + # In FreeBSD res_*/dn_* routines are present in libc.so + LIBRESOLV=;; + CYGWIN* ) + # In Cygwin res_*/dn_* routines are present in libc.so LIBRESOLV=;; * ) LIBRESOLV=-lresolv;; @@ -384,6 +420,58 @@ detect_resolv_static() return $ret } +detect_resolv_ns_dynamic() +{ + case "$arch" in + FreeBSD ) + # In FreeBSD ns_ routines are present in libc.so + LIBRESOLV=;; + * ) + LIBRESOLV=-lresolv;; + esac + TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX) + ret=1 + echo "$RESOLV_NS_TESTCODE" | $CC -o $TMPFILE -x c - $LIBRESOLV >/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + ret=0 + fi + + rm -f $TMPFILE + return $ret +} + +detect_resolv_ns_static() +{ + TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX) + ret=1 + for i in $systemlibdirs; do + if [ -f $i/libresolv.a ]; then + echo "$RESOLV_NS_TESTCODE" | $CC -o $TMPFILE -x c - -Wl,$i/libresolv.a >/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + ret=0 + fi + fi + done + + rm -f $TMPFILE + return $ret +} + +detect_nameser_has_ns_types() +{ + TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX) + ret=1 + # since we aren't actually linking with ns_* routines + # we can just compile the test code + echo "$RESOLV_NS_TYPES_TESTCODE" | $CC -o $TMPFILE -x c - >/dev/null 2>/dev/null + if [ "$?" = "0" ]; then + ret=0 + fi + + rm -f $TMPFILE + return $ret +} + if [ "$ssl" = "auto" ]; then detect_gnutls if [ "$ret" = "0" ]; then @@ -395,8 +483,6 @@ 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' @@ -439,10 +525,19 @@ fi; echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings +if detect_nameser_has_ns_types; then + echo '#define NAMESER_HAS_NS_TYPES' >> config.h +fi if detect_resolv_dynamic || detect_resolv_static; then echo '#define HAVE_RESOLV_A' >> config.h + if detect_resolv_ns_dynamic || detect_resolv_ns_static; then + echo '#define HAVE_RESOLV_A_WITH_NS' >> config.h + fi +else + echo 'Insufficient resolv routines. Jabber server must be set explicitly' fi + STORAGES="xml" for i in $STORAGES; do @@ -510,7 +605,7 @@ fi if [ "$otr" = 1 ]; then # BI == built-in echo '#define OTR_BI' >> config.h - echo "EFLAGS+=-L${otrprefix}/lib -lotr" >> Makefile.settings + echo "EFLAGS+=-L${otrprefix}/lib -lotr -lgcrypt" >> Makefile.settings echo "CFLAGS+=-I${otrprefix}/include" >> Makefile.settings echo 'OTR_BI=otr.o' >> Makefile.settings elif [ "$otr" = "plugin" ]; then @@ -708,9 +803,9 @@ AIX ) echo 'EFLAGS+=-Wl,-brtl' >> Makefile.settings ;; CYGWIN* ) - echo 'Cygwin is not officially supported.' ;; Windows ) + echo 'Native windows compilation is not supported anymore, use cygwin instead.' ;; * ) echo 'We haven'\''t tested BitlBee on many platforms yet, yours is untested. YMMV.' diff --git a/debian/rules b/debian/rules index a4c8c1f3..e0ffb898 100755 --- a/debian/rules +++ b/debian/rules @@ -33,17 +33,23 @@ ifneq ($(BITLBEE_SKYPE),plugin) DH_OPTIONS += -Nbitlbee-plugin-skype -Nskyped endif +CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS) +CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) +LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) + +CONFIGURE_OVERRIDES:=CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" + build: build-stamp build-stamp: dh_testdir mkdir -p debian/build-native - ROOT=$$PWD; cd debian/build-native; $(BITLBEE_CONFIGURE_VERSION) $(shell dpkg-buildflags --export=configure) $$ROOT/configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --events=libevent --otr=$(BITLBEE_OTR) --skype=$(BITLBEE_SKYPE) $(BITLBEE_CONFIGURE_FLAGS) + ROOT=$$PWD; cd debian/build-native; $(BITLBEE_CONFIGURE_VERSION) $(CONFIGURE_OVERRIDES) $$ROOT/configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --events=libevent --otr=$(BITLBEE_OTR) --skype=$(BITLBEE_SKYPE) $(BITLBEE_CONFIGURE_FLAGS) $(MAKE) -C debian/build-native ifeq ($(BITLBEE_LIBPURPLE),1) mkdir -p debian/build-libpurple - ROOT=$$PWD; cd debian/build-libpurple; $(BITLBEE_CONFIGURE_VERSION) $(shell dpkg-buildflags --export=configure) $$ROOT/configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --purple=1 $(BITLBEE_CONFIGURE_FLAGS) + ROOT=$$PWD; cd debian/build-libpurple; $(BITLBEE_CONFIGURE_VERSION) $(CONFIGURE_OVERRIDES) $$ROOT/configure --debug=$(DEBUG) --prefix=/usr --etcdir=/etc/bitlbee --purple=1 $(BITLBEE_CONFIGURE_FLAGS) $(MAKE) -C debian/build-libpurple endif diff --git a/doc/BUILD.win32 b/doc/BUILD.win32 deleted file mode 100644 index e1afe600..00000000 --- a/doc/BUILD.win32 +++ /dev/null @@ -1,10 +0,0 @@ -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/user-guide/Makefile b/doc/user-guide/Makefile index 0215ede8..af4180a1 100644 --- a/doc/user-guide/Makefile +++ b/doc/user-guide/Makefile @@ -16,7 +16,7 @@ all: user-guide.txt user-guide.html help.txt # user-guide.pdf user-guide.ps user mv $*.db.txt $@ %.html: %.db.xml - xsltproc --output $@ http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl $< + xsltproc --param generate.consistent.ids 1 --output $@ http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl $< %.pdf: %.db.xml xmlto --skip-validation pdf $< diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml index 45a6674f..e7d56ba1 100644 --- a/doc/user-guide/commands.xml +++ b/doc/user-guide/commands.xml @@ -1789,13 +1789,17 @@ </bitlbee-command> <bitlbee-command name="blist"> - <syntax>blist [all|online|offline|away]</syntax> + <syntax>blist [all|online|offline|away] [<pattern>]</syntax> <short-description>List all the buddies in the current channel</short-description> <description> <para> You can get a more readable buddy list using the <emphasis>blist</emphasis> command. If you want a complete list (including the offline users) you can use the <emphasis>all</emphasis> argument. </para> + + <para> + A perl-compatible regular expression can be supplied as <emphasis>pattern</emphasis> to filter the results (case-insensitive). + </para> </description> </bitlbee-command> @@ -41,11 +41,7 @@ help_t *help_init( help_t **help, const char *helpfile ) *help = h = g_new0 ( help_t, 1 ); - h->fd = open( helpfile, O_RDONLY -#ifdef _WIN32 - | O_BINARY -#endif - ); + h->fd = open( helpfile, O_RDONLY ); if( h->fd == -1 ) { @@ -27,10 +27,8 @@ #include "bitlbee.h" #include "ipc.h" #include "commands.h" -#ifndef _WIN32 #include <sys/uio.h> #include <sys/un.h> -#endif GSList *child_list = NULL; static int ipc_child_recv_fd = -1; @@ -842,7 +840,6 @@ void ipc_child_disable() global.listen_socket = -1; } -#ifndef _WIN32 char *ipc_master_save_state() { char *fn = g_strdup( "/tmp/bee-restart.XXXXXX" ); @@ -941,13 +938,6 @@ 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( char *statefile ) { @@ -26,6 +26,7 @@ #include "bitlbee.h" #include "ipc.h" #include "dcc.h" +#include "lib/ssl_client.h" GSList *irc_connection_list; GSList *irc_plugins; @@ -170,6 +171,11 @@ irc_t *irc_new( int fd ) #ifdef WITH_PURPLE nogaim_init(); #endif + + /* SSL library initialization also should be done after the fork, to + avoid shared CSPRNG state. This is required by NSS, which refuses to + work if a fork is detected */ + ssl_init(); for( l = irc_plugins; l; l = l->next ) { diff --git a/irc_commands.c b/irc_commands.c index 19930121..73b781fc 100644 --- a/irc_commands.c +++ b/irc_commands.c @@ -364,7 +364,7 @@ static void irc_cmd_privmsg( irc_t *irc, char **cmd ) if( cmd[2][strlen(cmd[2])-1] == '\001' ) cmd[2][strlen(cmd[2])-1] = '\0'; - ctcp = split_command_parts( cmd[2] + 1 ); + ctcp = split_command_parts( cmd[2] + 1, 0 ); iu->f->ctcp( iu, ctcp ); } else if( iu->f->privmsg ) @@ -636,6 +636,7 @@ static gboolean bee_irc_chat_msg( bee_t *bee, struct groupchat *c, bee_user_t *b wrapped = word_wrap( msg, 425 ); irc_send_msg( iu, "PRIVMSG", ic->name, wrapped, ts ); g_free( ts ); + g_free( wrapped ); return TRUE; } diff --git a/lib/Makefile b/lib/Makefile index f20b3797..40c03215 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -12,7 +12,7 @@ _SRCDIR_ := $(_SRCDIR_)lib/ endif # [SH] Program variables -objects = arc.o base64.o $(EVENT_HANDLER) ftutil.o http_client.o ini.o json.o json_util.o md5.o misc.o oauth.o oauth2.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o +objects = arc.o base64.o $(EVENT_HANDLER) ftutil.o http_client.o ini.o json.o json_util.o md5.o misc.o oauth.o oauth2.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o ns_parse.o LFLAGS += -r diff --git a/lib/events.h b/lib/events.h index 66c4c6b4..e31ddba4 100644 --- a/lib/events.h +++ b/lib/events.h @@ -36,11 +36,9 @@ #define _EVENTS_H_ #include <sys/types.h> -#ifndef _WIN32 #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> -#endif #include <glib.h> #include <gmodule.h> diff --git a/lib/events_glib.c b/lib/events_glib.c index 8f53fbbf..369d47f2 100644 --- a/lib/events_glib.c +++ b/lib/events_glib.c @@ -30,17 +30,11 @@ #include <stdlib.h> #include <string.h> #include <sys/types.h> -#ifndef _WIN32 #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> -#else -#include "sock.h" -#define ETIMEDOUT WSAETIMEDOUT -#define EINPROGRESS WSAEINPROGRESS -#endif #include <fcntl.h> #include <errno.h> #include "proxy.h" diff --git a/lib/http_client.c b/lib/http_client.c index b509c839..18c393f8 100644 --- a/lib/http_client.c +++ b/lib/http_client.c @@ -291,6 +291,9 @@ eof: } cleanup: + /* Avoid g_source_remove warnings */ + req->inpa = 0; + if( req->ssl ) ssl_disconnect( req->ssl ); else @@ -419,7 +419,6 @@ 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? */ @@ -469,7 +468,6 @@ void random_bytes( unsigned char *buf, int count ) } if( !use_dev ) -#endif { int i; @@ -524,7 +522,7 @@ struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain ) const unsigned char *buf; ns_msg nsh; ns_rr rr; - int i, n, len, size; + int n, len, size; g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain ); @@ -537,27 +535,20 @@ struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain ) n = 0; while( ns_parserr( &nsh, ns_s_an, n, &rr ) == 0 ) { - size = ns_rr_rdlen( rr ); + char name[NS_MAXDNAME]; + + if( ns_rr_rdlen( rr ) < 7) + break; + buf = ns_rr_rdata( rr ); - len = 0; - for( i = 6; i < size && buf[i]; i += buf[i] + 1 ) - len += buf[i] + 1; - - if( i > size ) + if( dn_expand(querybuf, querybuf + size, &buf[6], name, NS_MAXDNAME) == -1 ) break; + + len = strlen(name) + 1; reply = g_malloc( sizeof( struct ns_srv_reply ) + len ); - memcpy( reply->name, buf + 7, len ); - - for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 ) - reply->name[i] = '.'; - - if( i > len ) - { - g_free( reply ); - break; - } + memcpy( reply->name, name, len ); reply->prio = ( buf[0] << 8 ) | buf[1]; reply->weight = ( buf[2] << 8 ) | buf[3]; @@ -681,7 +672,7 @@ int md5_verify_password( char *password, char *hash ) /* Split commands (root-style, *not* IRC-style). Handles "quoting of" white\ space in 'various ways'. Returns a NULL-terminated static char** so watch out with nested use! Definitely not thread-safe. */ -char **split_command_parts( char *command ) +char **split_command_parts( char *command, int limit ) { static char *cmd[IRC_MAX_ARGS+1]; char *s, q = 0; @@ -691,11 +682,12 @@ char **split_command_parts( char *command ) cmd[0] = command; k = 1; for( s = command; *s && k < IRC_MAX_ARGS; s ++ ) + { if( *s == ' ' && !q ) { *s = 0; while( *++s == ' ' ); - if( *s == '"' || *s == '\'' ) + if( k != limit && (*s == '"' || *s == '\'') ) { q = *s; s ++; @@ -703,6 +695,9 @@ char **split_command_parts( char *command ) if( *s ) { cmd[k++] = s; + if (limit && k > limit) { + break; + } s --; } else @@ -721,6 +716,7 @@ char **split_command_parts( char *command ) { q = *s = 0; } + } /* Full zero-padding for easier argc checking. */ while( k <= IRC_MAX_ARGS ) @@ -37,6 +37,87 @@ struct ns_srv_reply char name[]; }; +#ifndef NAMESER_HAS_NS_TYPES + +#define NS_MAXDNAME 1025 +#define NS_INT16SZ 2 +#define NS_INT32SZ 4 + +#define NS_GET16(s, cp) do { \ + register const unsigned char *t_cp = (const unsigned char*)(cp); \ + (s) = ((guint16)t_cp[0] << 8) \ + | ((guint16)t_cp[1]) \ + ; \ + (cp) += NS_INT16SZ; \ +} while(0) + +#define NS_GET32(s, cp) do { \ + register const unsigned char *t_cp = (const unsigned char*)(cp); \ + (s) = ((guint16)t_cp[0] << 24) \ + | ((guint16)t_cp[1] << 16) \ + | ((guint16)t_cp[2] << 8) \ + | ((guint16)t_cp[3]) \ + ; \ + (cp) += NS_INT32SZ; \ +} while(0) + +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_rdata(rr) ((rr).rdata + 0) + +struct _ns_flagdata { int mask, shift; }; + +typedef struct __ns_rr { + char name[NS_MAXDNAME]; + guint16 type; + guint16 rr_class; + guint32 ttl; + guint16 rdlength; + const unsigned char* rdata; +} ns_rr; + +typedef enum __ns_sect { + ns_s_qd = 0, + ns_s_zn = 0, + ns_s_an = 1, + ns_s_pr = 1, + ns_s_ns = 2, + ns_s_ud = 2, + ns_s_ar = 3, + ns_s_max =4 +} ns_sect; + +typedef struct __ns_msg +{ + const unsigned char* _msg; + const unsigned char* _eom; + guint16 _id; + guint16 _flags; + guint16 _counts[ns_s_max]; + const unsigned char* _sections[ns_s_max]; + ns_sect _sect; + int _rrnum; + const unsigned char* _msg_ptr; +} ns_msg; + +typedef enum __ns_class { + ns_c_invalid = 0, + ns_c_in = 1, + ns_c_2 = 2, + ns_c_chaos = 3, + ns_c_hs = 4, + ns_c_none = 254, + ns_c_any = 255, + ns_c_max = 65536 +} ns_class; + + +/* TODO : fill out the rest */ +typedef enum __ns_type { + ns_t_srv = 33 +} ns_type; + +#endif /* NAMESER_HAS_NS_INITPARSE */ + G_MODULE_EXPORT void strip_linefeed( gchar *text ); G_MODULE_EXPORT char *add_cr( char *text ); G_MODULE_EXPORT char *strip_newlines(char *source); @@ -66,7 +147,7 @@ G_MODULE_EXPORT void srv_free( struct ns_srv_reply **srv ); G_MODULE_EXPORT char *word_wrap( const char *msg, int line_len ); G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl ); G_MODULE_EXPORT int md5_verify_password( char *password, char *hash ); -G_MODULE_EXPORT char **split_command_parts( char *command ); +G_MODULE_EXPORT char **split_command_parts( char *command, int limit ); G_MODULE_EXPORT char *get_rfc822_header( const char *text, const char *header, int len ); #endif diff --git a/lib/ns_parse.c b/lib/ns_parse.c new file mode 100644 index 00000000..ba45d513 --- /dev/null +++ b/lib/ns_parse.c @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996,1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "bitlbee.h" + +#ifndef lint +static const char rcsid[] = "$Id: ns_parse.c,v 1.10 2009/01/23 19:59:16 each Exp $"; +#endif + +#ifdef HAVE_RESOLV_A +#ifndef HAVE_RESOLV_A_WITH_NS +/* Import. */ + + +#include <sys/types.h> + +#include <netinet/in.h> +#include <arpa/nameser.h> + +#include <errno.h> +#include <resolv.h> +#include <string.h> + + +/* Forward. */ + +static void setsection(ns_msg *msg, ns_sect sect); + +/* Macros. */ + +#if !defined(SOLARIS2) || defined(__COVERITY__) +#define RETERR(err) do { errno = (err); return (-1); } while (0) +#else +#define RETERR(err) \ + do { errno = (err); if (errno == errno) return (-1); } while (0) +#endif + +#define PARSE_FMT_PRESO 0 /* Parse using presentation-format names */ +#define PARSE_FMT_WIRE 1 /* Parse using network-format names */ + +/* Public. */ + +/* These need to be in the same order as the nres.h:ns_flag enum. */ +struct _ns_flagdata _ns_flagdata[16] = { + { 0x8000, 15 }, /*%< qr. */ + { 0x7800, 11 }, /*%< opcode. */ + { 0x0400, 10 }, /*%< aa. */ + { 0x0200, 9 }, /*%< tc. */ + { 0x0100, 8 }, /*%< rd. */ + { 0x0080, 7 }, /*%< ra. */ + { 0x0040, 6 }, /*%< z. */ + { 0x0020, 5 }, /*%< ad. */ + { 0x0010, 4 }, /*%< cd. */ + { 0x000f, 0 }, /*%< rcode. */ + { 0x0000, 0 }, /*%< expansion (1/6). */ + { 0x0000, 0 }, /*%< expansion (2/6). */ + { 0x0000, 0 }, /*%< expansion (3/6). */ + { 0x0000, 0 }, /*%< expansion (4/6). */ + { 0x0000, 0 }, /*%< expansion (5/6). */ + { 0x0000, 0 }, /*%< expansion (6/6). */ +}; + +int ns_msg_getflag(ns_msg handle, int flag) { + return(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift); +} + +int +ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) { + const u_char *optr = ptr; + + for ((void)NULL; count > 0; count--) { + int b, rdlength; + + b = dn_skipname(ptr, eom); + if (b < 0) + RETERR(EMSGSIZE); + ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/; + if (section != ns_s_qd) { + if (ptr + NS_INT32SZ + NS_INT16SZ > eom) + RETERR(EMSGSIZE); + ptr += NS_INT32SZ/*TTL*/; + NS_GET16(rdlength, ptr); + ptr += rdlength/*RData*/; + } + } + if (ptr > eom) + RETERR(EMSGSIZE); + return (ptr - optr); +} + +int +ns_initparse(const u_char *msg, int msglen, ns_msg *handle) { + const u_char *eom = msg + msglen; + int i; + + handle->_msg = msg; + handle->_eom = eom; + if (msg + NS_INT16SZ > eom) + RETERR(EMSGSIZE); + NS_GET16(handle->_id, msg); + if (msg + NS_INT16SZ > eom) + RETERR(EMSGSIZE); + NS_GET16(handle->_flags, msg); + for (i = 0; i < ns_s_max; i++) { + if (msg + NS_INT16SZ > eom) + RETERR(EMSGSIZE); + NS_GET16(handle->_counts[i], msg); + } + for (i = 0; i < ns_s_max; i++) + if (handle->_counts[i] == 0) + handle->_sections[i] = NULL; + else { + int b = ns_skiprr(msg, eom, (ns_sect)i, + handle->_counts[i]); + + if (b < 0) + return (-1); + handle->_sections[i] = msg; + msg += b; + } + if (msg != eom) + RETERR(EMSGSIZE); + setsection(handle, ns_s_max); + return (0); +} + +int +ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { + int b; + int tmp; + + /* Make section right. */ + tmp = section; + if (tmp < 0 || section >= ns_s_max) + RETERR(ENODEV); + if (section != handle->_sect) + setsection(handle, section); + + /* Make rrnum right. */ + if (rrnum == -1) + rrnum = handle->_rrnum; + if (rrnum < 0 || rrnum >= handle->_counts[(int)section]) + RETERR(ENODEV); + if (rrnum < handle->_rrnum) + setsection(handle, section); + if (rrnum > handle->_rrnum) { + b = ns_skiprr(handle->_msg_ptr, handle->_eom, section, + rrnum - handle->_rrnum); + + if (b < 0) + return (-1); + handle->_msg_ptr += b; + handle->_rrnum = rrnum; + } + + /* Do the parse. */ + b = dn_expand(handle->_msg, handle->_eom, + handle->_msg_ptr, rr->name, NS_MAXDNAME); + if (b < 0) + return (-1); + handle->_msg_ptr += b; + if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom) + RETERR(EMSGSIZE); + NS_GET16(rr->type, handle->_msg_ptr); + NS_GET16(rr->rr_class, handle->_msg_ptr); + if (section == ns_s_qd) { + rr->ttl = 0; + rr->rdlength = 0; + rr->rdata = NULL; + } else { + if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) + RETERR(EMSGSIZE); + NS_GET32(rr->ttl, handle->_msg_ptr); + NS_GET16(rr->rdlength, handle->_msg_ptr); + if (handle->_msg_ptr + rr->rdlength > handle->_eom) + RETERR(EMSGSIZE); + rr->rdata = handle->_msg_ptr; + handle->_msg_ptr += rr->rdlength; + } + if (++handle->_rrnum > handle->_counts[(int)section]) + setsection(handle, (ns_sect)((int)section + 1)); + + /* All done. */ + return (0); +} + +/* Private. */ + +static void +setsection(ns_msg *msg, ns_sect sect) { + msg->_sect = sect; + if (sect == ns_s_max) { + msg->_rrnum = -1; + msg->_msg_ptr = NULL; + } else { + msg->_rrnum = 0; + msg->_msg_ptr = msg->_sections[(int)sect]; + } +} + +/*! \file */ +#endif +#endif diff --git a/lib/proxy.c b/lib/proxy.c index b6b02d72..6ada4917 100644 --- a/lib/proxy.c +++ b/lib/proxy.c @@ -25,17 +25,11 @@ #include <stdlib.h> #include <string.h> #include <sys/types.h> -#ifndef _WIN32 #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> -#else -#include "sock.h" -#define ETIMEDOUT WSAETIMEDOUT -#define EINPROGRESS WSAEINPROGRESS -#endif #include <fcntl.h> #include <errno.h> #include "nogaim.h" @@ -75,7 +69,6 @@ static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition int error = ETIMEDOUT; len = sizeof(error); -#ifndef _WIN32 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) { if ((phb->gai_cur = phb->gai_cur->ai_next)) { int new_fd; @@ -100,7 +93,6 @@ static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition } return FALSE; } -#endif freeaddrinfo(phb->gai); sock_make_blocking(source); b_event_remove(phb->inpa); diff --git a/lib/proxy.h b/lib/proxy.h index 680790a5..b3be0a66 100644 --- a/lib/proxy.h +++ b/lib/proxy.h @@ -27,11 +27,9 @@ #define _PROXY_H_ #include <sys/types.h> -#ifndef _WIN32 #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> -#endif #include <glib.h> #include <gmodule.h> diff --git a/lib/ssl_gnutls.c b/lib/ssl_gnutls.c index b698e630..f6bdd6b2 100644 --- a/lib/ssl_gnutls.c +++ b/lib/ssl_gnutls.c @@ -235,7 +235,7 @@ struct ssl_session static void ssl_cache_add( struct scd *conn ) { - size_t data_size; + size_t data_size = 0; struct ssl_session *data; char *hostname; @@ -244,7 +244,7 @@ static void ssl_cache_add( struct scd *conn ) return; data = g_malloc( sizeof( struct ssl_session ) + data_size ); - if( gnutls_session_get_data( conn->session, data->data, &data->size ) != 0 ) + if( gnutls_session_get_data( conn->session, data->data, &data_size ) != 0 ) { g_free( data ); return; @@ -334,6 +334,9 @@ static gboolean ssl_handshake( gpointer data, gint source, b_input_condition con struct scd *conn = data; int st, stver; + /* This function returns false, so avoid calling b_event_remove again */ + conn->inpa = -1; + if( ( st = gnutls_handshake( conn->session ) ) < 0 ) { if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED ) diff --git a/lib/ssl_sspi.c b/lib/ssl_sspi.c deleted file mode 100644 index e14c451e..00000000 --- a/lib/ssl_sspi.c +++ /dev/null @@ -1,278 +0,0 @@ - /********************************************************************\ - * 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 B_EV_IO_WRITE; /* FIXME: or B_EV_IO_READ */ -} diff --git a/protocols/account.c b/protocols/account.c index b90a60ee..83c214b1 100644 --- a/protocols/account.c +++ b/protocols/account.c @@ -27,6 +27,10 @@ #include "bitlbee.h" #include "account.h" +static const char* account_protocols_local[] = { + "gg", NULL +}; + static char *set_eval_nick_source( set_t *set, char *value ); account_t *account_add( bee_t *bee, struct prpl *prpl, char *user, char *pass ) @@ -346,6 +350,9 @@ static gboolean account_on_timeout( gpointer d, gint fd, b_input_condition cond void account_on( bee_t *bee, account_t *a ) { + GHashTableIter nicks; + gpointer k, v; + if( a->ic ) { /* Trying to enable an already-enabled account */ @@ -359,6 +366,15 @@ void account_on( bee_t *bee, account_t *a ) if( a->ic && !( a->ic->flags & ( OPT_SLOW_LOGIN | OPT_LOGGED_IN ) ) ) a->ic->keepalive = b_timeout_add( 120000, account_on_timeout, a->ic ); + + if( a->flags & ACC_FLAG_LOCAL ) + { + g_hash_table_iter_init(&nicks, a->nicks); + while( g_hash_table_iter_next( &nicks, &k, &v ) ) + { + a->prpl->add_buddy( a->ic, (char*) k, NULL ); + } + } } void account_off( bee_t *bee, account_t *a ) @@ -464,3 +480,13 @@ int account_reconnect_delay( account_t *a ) return a->auto_reconnect_delay; } + +int protocol_account_islocal( const char* protocol ) +{ + const char** p = account_protocols_local; + do { + if( strcmp( *p, protocol ) == 0 ) + return 1; + } while( *( ++p ) ); + return 0; +} diff --git a/protocols/account.h b/protocols/account.h index ed3ca531..14633fad 100644 --- a/protocols/account.h +++ b/protocols/account.h @@ -58,6 +58,8 @@ char *set_eval_account( set_t *set, char *value ); char *set_eval_account_reconnect_delay( set_t *set, char *value ); int account_reconnect_delay( account_t *a ); +int protocol_account_islocal( const char* protocol ); + typedef enum { ACC_SET_OFFLINE_ONLY = 0x02, /* Allow changes only if the acct is offline. */ @@ -69,6 +71,7 @@ typedef enum ACC_FLAG_AWAY_MESSAGE = 0x01, /* Supports away messages instead of just states. */ ACC_FLAG_STATUS_MESSAGE = 0x02, /* Supports status messages (without being away). */ ACC_FLAG_HANDLE_DOMAINS = 0x04, /* Contact handles need a domain portion. */ + ACC_FLAG_LOCAL = 0x08, /* Contact list is local. */ } account_flag_t; #endif diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 31b92049..61417bcc 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -351,7 +351,7 @@ xt_status jabber_pkt_bind_sess( struct im_connection *ic, struct xt_node *node, { /* Server is crap, but this is no disaster. */ } - else if( strncmp( jd->me, c->text, strlen( jd->me ) ) != 0 ) + else if( jabber_compare_jid( jd->me, c->text ) == 0 ) { s = strchr( c->text, '/' ); if( s ) diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 006da9a3..21769a3b 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -288,6 +288,7 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node * const struct jabber_away_state *jabber_away_state_by_code( char *code ); const struct jabber_away_state *jabber_away_state_by_name( char *name ); void jabber_buddy_ask( struct im_connection *ic, char *handle ); +int jabber_compare_jid( const char *jid1, const char *jid2 ); char *jabber_normalize( const char *orig ); typedef enum diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 67aa378a..0fcc8338 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -307,6 +307,28 @@ void jabber_buddy_ask( struct im_connection *ic, char *handle ) g_free( buf ); } +/* Compares just the bare portions of two Jabber IDs. */ +int jabber_compare_jid( const char *jid1, const char *jid2 ) +{ + int i; + + for( i = 0; ; i ++ ) + { + if( jid1[i] == '\0' || jid1[i] == '/' || jid2[i] == '\0' || jid2[i] == '/' ) + { + if( ( jid1[i] == '\0' || jid1[i] == '/' ) && ( jid2[i] == '\0' || jid2[i] == '/' ) ) + break; + return FALSE; + } + if( tolower( jid1[i] ) != tolower( jid2[i] ) ) + { + return FALSE; + } + } + + return TRUE; +} + /* Returns a new string. Don't leak it! */ char *jabber_normalize( const char *orig ) { diff --git a/protocols/msn/soap.h b/protocols/msn/soap.h index cb731ea7..1fd1f32b 100644 --- a/protocols/msn/soap.h +++ b/protocols/msn/soap.h @@ -35,12 +35,10 @@ #include <stdlib.h> #include <string.h> #include <sys/types.h> -#ifndef _WIN32 #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> -#endif #include "nogaim.h" diff --git a/protocols/oscar/rxqueue.c b/protocols/oscar/rxqueue.c index 081e967c..9ac8466e 100644 --- a/protocols/oscar/rxqueue.c +++ b/protocols/oscar/rxqueue.c @@ -8,9 +8,7 @@ #include <aim.h> -#ifndef _WIN32 #include <sys/socket.h> -#endif /* * diff --git a/protocols/oscar/txqueue.c b/protocols/oscar/txqueue.c index d38986d0..e48511fa 100644 --- a/protocols/oscar/txqueue.c +++ b/protocols/oscar/txqueue.c @@ -8,9 +8,7 @@ #include <aim.h> #include "im.h" -#ifndef _WIN32 #include <sys/socket.h> -#endif /* * Allocate a new tx frame. diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 70e11067..2a6ae88f 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -322,7 +322,7 @@ static void twitter_init(account_t * acc) s = set_add(&acc->set, "show_ids", "true", set_eval_bool, acc); - s = set_add(&acc->set, "show_old_mentions", "20", set_eval_int, acc); + s = set_add(&acc->set, "show_old_mentions", "0", set_eval_int, acc); s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc); @@ -601,7 +601,7 @@ static void twitter_handle_command(struct im_connection *ic, char *message) bee_user_t *bu = NULL; cmds = g_strdup(message); - cmd = split_command_parts(cmds); + cmd = split_command_parts(cmds, 2); if (cmd[0] == NULL) { goto eof; @@ -616,7 +616,9 @@ static void twitter_handle_command(struct im_connection *ic, char *message) twitter_log(ic, "Could not undo last action"); goto eof; - } else if (g_strcasecmp(cmd[0], "favourite") == 0 && cmd[1]) { + } else if ((g_strcasecmp(cmd[0], "favourite") == 0 || + g_strcasecmp(cmd[0], "favorite") == 0 || + g_strcasecmp(cmd[0], "fav") == 0) && cmd[1]) { if ((id = twitter_message_id_from_command_arg(ic, cmd[1], NULL))) { twitter_favourite_tweet(ic, id); } else { @@ -661,7 +663,7 @@ static void twitter_handle_command(struct im_connection *ic, char *message) "post any statuses recently", cmd[1]); goto eof; } - message = new = g_strdup_printf("@%s %s", bu->handle, message + (cmd[2] - cmd[0])); + message = new = g_strdup_printf("@%s %s", bu->handle, cmd[2]); in_reply_to = id; allow_post = TRUE; } else if (g_strcasecmp(cmd[0], "post") == 0) { diff --git a/protocols/yahoo/libyahoo2.c b/protocols/yahoo/libyahoo2.c index da427279..972ee134 100644 --- a/protocols/yahoo/libyahoo2.c +++ b/protocols/yahoo/libyahoo2.c @@ -47,9 +47,7 @@ * */ -#ifndef _WIN32 #include <unistd.h> -#endif #include <errno.h> #include <stdio.h> #include <stdarg.h> diff --git a/protocols/yahoo/yahoo_httplib.c b/protocols/yahoo/yahoo_httplib.c index fd63d507..93fdb263 100644 --- a/protocols/yahoo/yahoo_httplib.c +++ b/protocols/yahoo/yahoo_httplib.c @@ -37,9 +37,7 @@ char *strchr(), *strrchr(); #endif #include <errno.h> -#ifndef _WIN32 #include <unistd.h> -#endif #include <ctype.h> #include "yahoo2.h" #include "yahoo2_callbacks.h" diff --git a/protocols/yahoo/yahoo_util.h b/protocols/yahoo/yahoo_util.h index 8cb721c1..6b4da304 100644 --- a/protocols/yahoo/yahoo_util.h +++ b/protocols/yahoo/yahoo_util.h @@ -64,7 +64,6 @@ void *y_memdup(const void *addr, int n); char **y_strsplit(char *str, char *sep, int nelem); void y_strfreev(char **vector); -#ifndef _WIN32 int strncasecmp(const char *s1, const char *s2, size_t n); int strcasecmp(const char *s1, const char *s2); @@ -72,7 +71,6 @@ char *strdup(const char *s); int snprintf(char *str, size_t size, const char *format, ...); int vsnprintf(char *str, size_t size, const char *format, va_list ap); -#endif #endif diff --git a/root_commands.c b/root_commands.c index 2c153f0e..6b8add80 100644 --- a/root_commands.c +++ b/root_commands.c @@ -31,7 +31,7 @@ void root_command_string( irc_t *irc, char *command ) { - root_command( irc, split_command_parts( command ) ); + root_command( irc, split_command_parts( command, 0 ) ); } #define MIN_ARGS( x, y... ) \ @@ -1084,8 +1084,10 @@ static void cmd_set( irc_t *irc, char **cmd ) static void cmd_blist( irc_t *irc, char **cmd ) { - int online = 0, away = 0, offline = 0; + int online = 0, away = 0, offline = 0, ismatch = 0; GSList *l; + GRegex *regex = NULL; + GError *error = NULL; char s[256]; char *format; int n_online = 0, n_away = 0, n_offline = 0; @@ -1101,6 +1103,15 @@ static void cmd_blist( irc_t *irc, char **cmd ) else online = away = 1; + if( cmd[2] ) + regex = g_regex_new( cmd[2], G_REGEX_CASELESS, 0, &error ); + + if( error ) + { + irc_rootmsg( irc, error->message ); + g_error_free( error ); + } + if( strchr( irc->umode, 'b' ) != NULL ) format = "%s\t%s\t%s"; else @@ -1117,59 +1128,55 @@ static void cmd_blist( irc_t *irc, char **cmd ) irc_user_t *iu = l->data; bee_user_t *bu = iu->bu; - if( !bu || ( irc->root->last_channel && !irc_channel_wants_user( irc->root->last_channel, iu ) ) || - ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE ) + if( !regex || g_regex_match( regex, iu->nick, 0, NULL ) ) + ismatch = 1; + else + ismatch = 0; + + if( !bu || ( irc->root->last_channel && !irc_channel_wants_user( irc->root->last_channel, iu ) ) ) continue; - if( online == 1 ) + if( ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) == BEE_USER_ONLINE ) { - char st[256] = "Online"; - - if( bu->status_msg ) - g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg ); + if( ismatch == 1 && online == 1 ) + { + char st[256] = "Online"; + + if( bu->status_msg ) + g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg ); + + g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag ); + irc_rootmsg( irc, format, iu->nick, s, st ); + } - g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag ); - irc_rootmsg( irc, format, iu->nick, s, st ); + n_online ++; } - n_online ++; - } - - for( l = irc->users; l; l = l->next ) - { - irc_user_t *iu = l->data; - bee_user_t *bu = iu->bu; - - if( !bu || ( irc->root->last_channel && !irc_channel_wants_user( irc->root->last_channel, iu ) ) || - !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) ) - continue; - - if( away == 1 ) + if( ( bu->flags & BEE_USER_ONLINE ) && ( bu->flags & BEE_USER_AWAY ) ) { - g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag ); - irc_rootmsg( irc, format, iu->nick, s, irc_user_get_away( iu ) ); + if( ismatch == 1 && away == 1 ) + { + g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag ); + irc_rootmsg( irc, format, iu->nick, s, irc_user_get_away( iu ) ); + } + n_away ++; } - n_away ++; - } - - for( l = irc->users; l; l = l->next ) - { - irc_user_t *iu = l->data; - bee_user_t *bu = iu->bu; - - if( !bu || ( irc->root->last_channel && !irc_channel_wants_user( irc->root->last_channel, iu ) ) || - bu->flags & BEE_USER_ONLINE ) - continue; - if( offline == 1 ) + if( !(bu->flags & BEE_USER_ONLINE) ) { - g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag ); - irc_rootmsg( irc, format, iu->nick, s, "Offline" ); + if( ismatch == 1 && offline == 1 ) + { + g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag ); + irc_rootmsg( irc, format, iu->nick, s, "Offline" ); + } + n_offline ++; } - n_offline ++; } irc_rootmsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); + + if( regex ) + g_regex_unref( regex ); } static void cmd_qlist( irc_t *irc, char **cmd ) @@ -1,7 +1,6 @@ #include <errno.h> #include <fcntl.h> -#ifndef _WIN32 #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> @@ -11,16 +10,3 @@ #define sock_make_blocking(fd) fcntl(fd, F_SETFL, 0) #define sockerr_again() (errno == EINPROGRESS || errno == EINTR) void closesocket( int fd ); -#else -# include <winsock2.h> -# include <ws2tcpip.h> -# if !defined(BITLBEE_CORE) && defined(_MSC_VER) -# pragma comment(lib,"bitlbee.lib") -# endif -# include <io.h> -# 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) -# define ETIMEDOUT WSAETIMEDOUT -# define sleep(a) Sleep(a*1000) -#endif diff --git a/storage_xml.c b/storage_xml.c index d32ed25f..ddd09938 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -86,7 +86,7 @@ static xt_status handle_account( struct xt_node *node, gpointer data ) char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag; char *pass_b64 = NULL; unsigned char *pass_cr = NULL; - int pass_len; + int pass_len, local = 0; struct prpl *prpl = NULL; account_t *acc; struct xt_node *c; @@ -99,7 +99,10 @@ static xt_status handle_account( struct xt_node *node, gpointer data ) protocol = xt_find_attr( node, "protocol" ); if( protocol ) + { prpl = find_protocol( protocol ); + local = protocol_account_islocal( protocol ); + } if( !handle || !pass_b64 || !protocol || !prpl ) return XT_ABORT; @@ -113,6 +116,8 @@ static xt_status handle_account( struct xt_node *node, gpointer data ) set_setstr( &acc->set, "auto_connect", autoconnect ); if( tag ) set_setstr( &acc->set, "tag", tag ); + if( local ) + acc->flags |= ACC_FLAG_LOCAL; } else return XT_ABORT; diff --git a/tests/check_jabber_util.c b/tests/check_jabber_util.c index bf6d3e60..966b5230 100644 --- a/tests/check_jabber_util.c +++ b/tests/check_jabber_util.c @@ -94,6 +94,16 @@ static void check_buddy_add(int l) fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/C" ) ); } +static void check_compareJID(int l) +{ + fail_unless( jabber_compare_jid( "bugtest@google.com/B", "bugtest@google.com/A" ) ); + fail_if( jabber_compare_jid( "bugtest1@google.com/B", "bugtest@google.com/A" ) ); + fail_if( jabber_compare_jid( "bugtest@google.com/B", "bugtest1@google.com/A" ) ); + fail_if( jabber_compare_jid( "bugtest1@google.com/B", "bugtest2@google.com/A" ) ); + fail_unless( jabber_compare_jid( "bugtest@google.com/A", "bugtest@google.com/A" ) ); + fail_if( jabber_compare_jid( "", "bugtest@google.com/A" ) ); +} + Suite *jabber_util_suite (void) { Suite *s = suite_create("jabber/util"); @@ -109,5 +119,6 @@ Suite *jabber_util_suite (void) suite_add_tcase (s, tc_core); tcase_add_test (tc_core, check_buddy_add); + tcase_add_test (tc_core, check_compareJID); return s; } diff --git a/tests/check_util.c b/tests/check_util.c index c323241e..dc73d644 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -168,6 +168,50 @@ START_TEST(test_http_encode) fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0 ); END_TEST +struct { + int limit; + char *command; + char *expected[IRC_MAX_ARGS+1]; +} split_tests[] = { + { + 0, "account add etc \"user name with spaces\" 'pass\\ word'", + {"account", "add", "etc", "user name with spaces", "pass\\ word", NULL}, + }, + { + 0, "channel set group Close\\ friends", + {"channel", "set", "group", "Close friends", NULL}, + }, + { + 2, "reply wilmer \"testing in C is a PITA\", you said.", + {"reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL}, + }, + { + 4, "one space two spaces limit limit", + {"one", "space", "two", "spaces", "limit limit", NULL}, + }, + { + 0, NULL, + {NULL} + }, +}; + +START_TEST(test_split_command_parts) + int i; + for (i = 0; split_tests[i].command; i++) { + char *cmd = g_strdup(split_tests[i].command); + char **split = split_command_parts(cmd, split_tests[i].limit); + char **expected = split_tests[i].expected; + + int j; + for (j = 0; split[j] && expected[j]; j++) { + fail_unless (strcmp(split[j], expected[j]) == 0, + "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)", + i, split_tests[i].command, j, split[j], expected[j]); + } + g_free(cmd); + } +END_TEST + Suite *util_suite (void) { Suite *s = suite_create("Util"); @@ -182,5 +226,6 @@ Suite *util_suite (void) tcase_add_test (tc_core, test_set_url_username_pwd); tcase_add_test (tc_core, test_word_wrap); tcase_add_test (tc_core, test_http_encode); + tcase_add_test (tc_core, test_split_command_parts); return s; } @@ -31,7 +31,6 @@ #include "protocols/nogaim.h" #include "help.h" #include "ipc.h" -#include "lib/ssl_client.h" #include "md5.h" #include "misc.h" #include <signal.h> @@ -81,17 +80,9 @@ int main( int argc, char *argv[] ) nogaim_init(); #endif - /* Ugly Note: libotr and gnutls both use libgcrypt. libgcrypt - has a process-global config state whose initialization happpens - twice if libotr and gnutls are used together. libotr installs custom - memory management functions for libgcrypt while our gnutls module - uses the defaults. Therefore we initialize OTR after SSL. *sigh* */ - ssl_init(); #ifdef OTR_BI otr_init(); #endif - /* And in case OTR is loaded as a plugin, it'll also get loaded after - this point. */ srand( time( NULL ) ^ getpid() ); diff --git a/win32.c b/win32.c deleted file mode 100644 index 99d2a8ca..00000000 --- a/win32.c +++ /dev/null @@ -1,331 +0,0 @@ - /********************************************************************\ - * 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 "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; -} |