+androsyn 2008/11/11 00:00:12 UTC (20081111_0-26180)
+ Log:
+ fix build errors on os x leopard
+
+ Modified:
+ libratbox/trunk/src/unix.c (File Modified)
+
+
+androsyn 2008/11/07 02:10:19 UTC (20081107_0-26178)
+ Log:
+ untested fix for building on os x -- environ is not accessible to shared libraries...
+
+ Modified:
+ libratbox/trunk/src/unix.c (File Modified)
+
+
+androsyn 2008/10/26 20:59:07 UTC (20081026_2-26170)
+ Log:
+ add rb_basename and rb_dirname
+
+ Modified:
+ libratbox/trunk/include/rb_tools.h (File Modified)
+ libratbox/trunk/src/export-syms.txt (File Modified)
+ libratbox/trunk/src/tools.c (File Modified)
+
+
+androsyn 2008/10/26 20:58:40 UTC (20081026_1-26168)
+ Log:
+ remove -O0 from configure.ac and configure
+
+ Modified:
+ libratbox/trunk/configure (File Modified)
+ libratbox/trunk/configure.ac (File Modified)
+
+
+androsyn 2008/10/26 20:48:56 UTC (20081026_0-26166)
+ Log:
+ do an ERR_get_error() if opening the dhparams file fails
+
+ Modified:
+ libratbox/trunk/src/openssl.c (File Modified)
+
+
+androsyn 2008/10/03 18:02:13 UTC (20081003_0-26126)
+ Log:
+ fix up the timerfd autoconf stuff a bit better
+
+ Modified:
+ libratbox/trunk/acinclude.m4 (File Modified)
+ libratbox/trunk/configure (File Modified)
+
+
+androsyn 2008/09/29 22:58:42 UTC (20080929_0-26122)
+ Log:
+ fix the timerfd_create check
+
+ Modified:
+ libratbox/trunk/acinclude.m4 (File Modified)
+ libratbox/trunk/configure (File Modified)
+
+
+androsyn 2008/09/20 01:27:19 UTC (20080920_1-26100)
+ Log:
+ properly cast a few things when doing pointer math and the like
+
+ Modified:
+ libratbox/trunk/src/balloc.c (File Modified)
+ libratbox/trunk/src/openssl.c (File Modified)
+
+
+androsyn 2008/09/20 01:05:42 UTC (20080920_0-26096)
+ Log:
+ make rb_close_all be a no-op on win32, its not too useful there either as windows doesn't inherit sockets/files by default
+
+ Modified:
+ libratbox/trunk/src/commio.c (File Modified)
+
+
+androsyn 2008/09/19 15:13:52 UTC (20080919_0-26092)
+ Log:
+ update indent.pro and rerun through indent
+
+ Modified:
+ libratbox/trunk/.indent.pro (File Modified)
+ libratbox/trunk/include/arc4random.h (File Modified)
+ libratbox/trunk/include/commio-int.h (File Modified)
+ libratbox/trunk/include/commio-ssl.h (File Modified)
+ libratbox/trunk/include/rb_balloc.h (File Modified)
+ libratbox/trunk/include/rb_commio.h (File Modified)
+ libratbox/trunk/include/rb_event.h (File Modified)
+ libratbox/trunk/include/rb_helper.h (File Modified)
+ libratbox/trunk/include/rb_linebuf.h (File Modified)
+ libratbox/trunk/include/rb_memory.h (File Modified)
+ libratbox/trunk/include/rb_patricia.h (File Modified)
+ libratbox/trunk/include/rb_rawbuf.h (File Modified)
+ libratbox/trunk/include/rb_snprintf.h (File Modified)
+ libratbox/trunk/include/rb_tools.h (File Modified)
+ libratbox/trunk/src/arc4random.c (File Modified)
+ libratbox/trunk/src/balloc.c (File Modified)
+ libratbox/trunk/src/commio.c (File Modified)
+ libratbox/trunk/src/crypt.c (File Modified)
+ libratbox/trunk/src/devpoll.c (File Modified)
+ libratbox/trunk/src/epoll.c (File Modified)
+ libratbox/trunk/src/event.c (File Modified)
+ libratbox/trunk/src/gnutls.c (File Modified)
+ libratbox/trunk/src/helper.c (File Modified)
+ libratbox/trunk/src/kqueue.c (File Modified)
+ libratbox/trunk/src/linebuf.c (File Modified)
+ libratbox/trunk/src/nossl.c (File Modified)
+ libratbox/trunk/src/openssl.c (File Modified)
+ libratbox/trunk/src/patricia.c (File Modified)
+ libratbox/trunk/src/poll.c (File Modified)
+ libratbox/trunk/src/ports.c (File Modified)
+ libratbox/trunk/src/ratbox_lib.c (File Modified)
+ libratbox/trunk/src/rawbuf.c (File Modified)
+ libratbox/trunk/src/rb_memory.c (File Modified)
+ libratbox/trunk/src/select.c (File Modified)
+ libratbox/trunk/src/sigio.c (File Modified)
+ libratbox/trunk/src/snprintf.c (File Modified)
+ libratbox/trunk/src/tools.c (File Modified)
+ libratbox/trunk/src/unix.c (File Modified)
+ libratbox/trunk/src/win32.c (File Modified)
+
+
+androsyn 2008/09/18 18:56:55 UTC (20080918_1-26088)
+ Log:
+ on win32 add randomness from RtlGenRandom if its available
+
+ Modified:
+ libratbox/trunk/src/arc4random.c (File Modified)
+
+
+androsyn 2008/09/18 18:41:19 UTC (20080918_0-26086)
+ Log:
+ add timerfd_create support on linux with glibc 2.8
+
+ Modified:
+ libratbox/trunk/acinclude.m4 (File Modified)
+ libratbox/trunk/configure (File Modified)
+ libratbox/trunk/configure.ac (File Modified)
+ libratbox/trunk/include/libratbox_config.h.in (File Modified)
+ libratbox/trunk/src/Makefile.in (File Modified)
+ libratbox/trunk/src/epoll.c (File Modified)
+ libratbox/trunk/src/version.c.SH (File Modified)
+
+
+androsyn 2008/09/15 15:47:42 UTC (20080915_0-26082)
+ Log:
+ cast svptr a bit harder to deal with 32bit systems. Also use sizeof our_signalfd_siginfo.
+
+ Modified:
+ libratbox/trunk/src/epoll.c (File Modified)
+
+
+jilles 2008/09/14 22:24:27 UTC (20080914_0-26078)
+ Log:
+ Fix infinite recursion crash on non-win32.
+
+
+ Modified:
+ libratbox/trunk/src/unix.c (File Modified)
+
+
+androsyn 2008/09/10 01:45:22 UTC (20080910_1-26072)
+ Log:
+ fix a typo
+
+ Modified:
+ libratbox/trunk/src/select.c (File Modified)
+
+
+androsyn 2008/09/10 00:23:41 UTC (20080910_0-26068)
+ Log:
+ attempt to override FD_SETSIZE for select and if rb_maxconnections is greater than FD_SETSIZE, lower rb_maxconnections. Also prefer select to win32
+
+ Modified:
+ libratbox/trunk/src/commio.c (File Modified)
+ libratbox/trunk/src/select.c (File Modified)
+
+
+androsyn 2008/09/09 22:58:11 UTC (20080909_8-26066)
+ Log:
+ actually make that use BIO_new_file
+
+ Modified:
+ libratbox/trunk/src/openssl.c (File Modified)
+
+
+androsyn 2008/09/09 22:19:14 UTC (20080909_7-26064)
+ Log:
+ avoid using FILE with openssl as this causes openssl to need OPENSSL_applink on some platforms which is annoying
+
+ Modified:
+ libratbox/trunk/src/openssl.c (File Modified)
+
+
+androsyn 2008/09/09 17:08:10 UTC (20080909_6-26060)
+ Log:
+ those symbols don't exist..oops
+
+ Modified:
+ libratbox/trunk/src/export-syms.txt (File Modified)
+
+
+androsyn 2008/09/09 17:05:19 UTC (20080909_5-26058)
+ Log:
+ move that down a little
+
+ Modified:
+ libratbox/trunk/src/unix.c (File Modified)
+
+
+androsyn 2008/09/09 16:47:03 UTC (20080909_4-26052)
+ Log:
+ change ifdef WIN32 to _WIN32
+
+ Modified:
+ libratbox/trunk/include/commio-int.h (File Modified)
+ libratbox/trunk/include/ratbox_lib.h (File Modified)
+ libratbox/trunk/include/rb_commio.h (File Modified)
+ libratbox/trunk/src/balloc.c (File Modified)
+ libratbox/trunk/src/commio.c (File Modified)
+ libratbox/trunk/src/helper.c (File Modified)
+ libratbox/trunk/src/openssl.c (File Modified)
+ libratbox/trunk/src/unix.c (File Modified)
+ libratbox/trunk/src/win32.c (File Modified)
+
+
+androsyn 2008/09/09 16:40:19 UTC (20080909_3-26048)
+ Log:
+ - Implement fd passing for win32 so that ssld will work on there.
+ - Add a few symbols to the library for portability issues
+ Note that this commit changes the API for rb_send_fd_buf as it now
+ also takes a pid option as this is needed on windows. This process
+ id should be the target process. Note that unix will just ignore
+ this.
+
+
+
+ Modified:
+ libratbox/trunk/Makefile.in (File Modified)
+ libratbox/trunk/include/ratbox_lib.h (File Modified)
+ libratbox/trunk/include/rb_commio.h (File Modified)
+ libratbox/trunk/src/commio.c (File Modified)
+ libratbox/trunk/src/export-syms.txt (File Modified)
+ libratbox/trunk/src/helper.c (File Modified)
+ libratbox/trunk/src/unix.c (File Modified)
+ libratbox/trunk/src/win32.c (File Modified)
+
+
+androsyn 2008/09/09 16:37:30 UTC (20080909_2-26046)
+ Log:
+ pass libraries to LDFLAGS as well
+
+ Modified:
+ libratbox/trunk/src/Makefile.am (File Modified)
+ libratbox/trunk/src/Makefile.in (File Modified)
+
+
+androsyn 2008/09/09 16:36:15 UTC (20080909_1-26044)
+ Log:
+ make SSL_LIBS actually pass the path to the openssl libraries
+
+ Modified:
+ libratbox/trunk/configure (File Modified)
+ libratbox/trunk/configure.ac (File Modified)
+
+
+androsyn 2008/09/09 14:40:41 UTC (20080909_0-26036)
+ Log:
+ make that an ifdef
+
+ Modified:
+ libratbox/trunk/src/commio.c (File Modified)
+
+
+androsyn 2008/09/08 16:54:58 UTC (20080908_1-26034)
+ Log:
+ add a datagram socketpair for platforms that don't have it..mostly based on what is in perl for this
+
+ Modified:
+ libratbox/trunk/src/commio.c (File Modified)
+
+
+androsyn 2008/09/08 16:53:53 UTC (20080908_0-26032)
+ Log:
+ make rb_strerror be char instead of const char
+
+ Modified:
+ libratbox/trunk/include/ratbox_lib.h (File Modified)
+
+
+androsyn 2008/09/05 23:44:06 UTC (20080905_1-26022)
+ Log:
+ fix the define of the fake rb_sockaddr_storage so that m4 does not eat up our [ ]
+
+ Modified:
+ libratbox/trunk/configure (File Modified)
+ libratbox/trunk/configure.ac (File Modified)
+
+
+androsyn 2008/09/05 18:19:25 UTC (20080905_0-26012)
+ Log:
+ revert part of r25994
+
+ Modified:
+ libratbox/trunk/configure (File Modified)
+ libratbox/trunk/configure.ac (File Modified)
+
+
+androsyn 2008/09/04 21:43:03 UTC (20080904_3-26008)
+ Log:
+ change hard asserts to call both the soft assert code and the C library assert so that it gets in the ircd log files as well
+
+ Modified:
+ libratbox/trunk/include/ratbox_lib.h (File Modified)
+
+
+androsyn 2008/09/04 19:32:55 UTC (20080904_2-26000)
+ Log:
+ If somebody really wants to do profiling work..they can change rb_close_all the hard way. Also stop doing the weird stderr.log hack in libratbox let callers deal with stderr on their own
+
+ Modified:
+ libratbox/trunk/src/commio.c (File Modified)
+
+
+androsyn 2008/09/04 16:08:27 UTC (20080904_1-25998)
+ Log:
+ add missing rb_strerror prototypes
+
+ Modified:
+ libratbox/trunk/include/ratbox_lib.h (File Modified)
+ libratbox/trunk/src/unix.c (File Modified)
+ libratbox/trunk/src/win32.c (File Modified)
+
+
+androsyn 2008/09/04 15:06:21 UTC (20080904_0-25994)
+ Log:
+ some portability cleanups
+
+ Modified:
+ libratbox/trunk/aclocal.m4 (File Modified)
+ libratbox/trunk/config.guess (File Modified)
+ libratbox/trunk/config.sub (File Modified)
+ libratbox/trunk/configure (File Modified)
+ libratbox/trunk/configure.ac (File Modified)
+ libratbox/trunk/include/arc4random.h (File Modified)
+ libratbox/trunk/include/libratbox_config.h.in (File Modified)
+ libratbox/trunk/include/ratbox_lib.h (File Modified)
+ libratbox/trunk/ltmain.sh (File Modified)
+ libratbox/trunk/src/Makefile.in (File Modified)
+ libratbox/trunk/src/commio.c (File Modified)
+ libratbox/trunk/src/export-syms.txt (File Modified)
+ libratbox/trunk/src/helper.c (File Modified)
+ libratbox/trunk/src/nossl.c (File Modified)
+ libratbox/trunk/src/unix.c (File Modified)
+ libratbox/trunk/src/win32.c (File Modified)
+
+
+androsyn 2008/09/03 00:20:22 UTC (20080903_0-25992)
+ Log:
+ change the event stuff to just strndup the event name
+
+ Modified:
+ libratbox/trunk/include/event-int.h (File Modified)
+ libratbox/trunk/src/event.c (File Modified)
+
+
+androsyn 2008/09/02 21:40:49 UTC (20080902_0-25990)
+ Log:
+ fix makefile on bsd make
+
+ Modified:
+ libratbox/trunk/src/Makefile.am (File Modified)
+ libratbox/trunk/src/Makefile.in (File Modified)
+
+
+androsyn 2008/09/01 05:00:31 UTC (20080901_3-25984)
+ Log:
+ make extern not nested
+
+ Modified:
+ libratbox/trunk/src/ratbox_lib.c (File Modified)
+
+
+androsyn 2008/09/01 04:59:19 UTC (20080901_2-25982)
+ Log:
+ and add version.c.SH too
+
+ Modified:
+ libratbox/trunk/src/version.c.SH (File Added)
+
+
+androsyn 2008/09/01 04:58:51 UTC (20080901_1-25980)
+ Log:
+ fix up version output stuff
+
+ Modified:
+ libratbox/trunk/src/Makefile.am (File Modified)
+ libratbox/trunk/src/Makefile.in (File Modified)
+ libratbox/trunk/src/ratbox_lib.c (File Modified)
+
+
+androsyn 2008/09/01 04:50:17 UTC (20080901_0-25978)
+ Log:
+ test commit
+
+ Modified:
+ libratbox/trunk/README (File Modified)
+
+
+androsyn 2008/09/01 03:18:34 UTC (25975)
+ Log:
+ remove NOBALLOC code from linebuf.c and fill in the rb_bh_usage stuff for NOBALLOC
+
+ Modified:
+ libratbox/trunk/src/balloc.c (File Modified)
+ libratbox/trunk/src/linebuf.c (File Modified)
+
+
+androsyn 2008/09/01 03:12:32 UTC (25973)
+ Log:
+ remove an #if 0
+
+ Modified:
+ libratbox/trunk/src/event.c (File Modified)
+
+
+androsyn 2008/09/01 03:07:46 UTC (25971)
+ Log:
+ change u_char to uint8_t
+
+ Modified:
+ libratbox/trunk/src/crypt.c (File Modified)
+
+
+androsyn 2008/08/27 19:28:26 UTC (25963)
+ Log:
+ deal with rb_vsnprintf_append having a string passed to it that is longer than len, in such case we truncate the string..
+
+ Modified:
+ libratbox/trunk/src/snprintf.c (File Modified)
+
+
+androsyn 2008/08/27 14:59:09 UTC (25961)
+ Log:
+ the way ev->name was assigned was pretty bogus and pretty much only worked because we always used strings that always were statically allocated in the executable. fix this and do it correctly
+
+ Modified:
+ libratbox/trunk/include/event-int.h (File Modified)
+ libratbox/trunk/src/event.c (File Modified)
+
+
+androsyn 2008/08/25 19:19:35 UTC (25955)
+ Log:
+ make that a %s instead of a %d
+
+ Modified:
+ libratbox/trunk/src/commio.c (File Modified)
+
+
+androsyn 2008/08/15 16:29:35 UTC (25897)
+ Log:
+ order of operations in C can be a real bitch sometimes
+
+ Modified:
+ libratbox/trunk/src/balloc.c (File Modified)
+
+
+androsyn 2008/08/14 18:23:23 UTC (25885)
+ Log:
+ fix block heap garbage collection properly
+
+ Modified:
+ libratbox/trunk/src/balloc.c (File Modified)
+
+
+androsyn 2008/08/12 15:43:58 UTC (25871)
+ Log:
+ fix a crash in the rb_bh_gc code
+
+ Modified:
+ libratbox/trunk/src/balloc.c (File Modified)
+
+
androsyn 2008/08/06 19:51:44 UTC (25861)
Log:
put back in the pad to even pointer boundaries stuff
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LD = @LD@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
-subdirs = @subdirs@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
discard. For some non-irc purposes, this can be a problem, but for
ircd stuff its fine.
3. The helper code when transmitting data between helpers, the same 512 byte
- limit applies there as we recycle the linebuf code for this.
-
+ limit applies there as we recycle the linebuf code for this.
esac
])
+
+
+AC_DEFUN([RB_CHECK_TIMERFD_CREATE],
+ [AC_CACHE_CHECK([for a working timerfd_create(CLOCK_REALTIME)],
+ [rb__cv_timerfd_create_works],
+ [AC_TRY_RUN([
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TIMERFD_H
+#include <sys/timerfd.h>
+#endif
+int main(int argc, char *argv[])
+{
+#if defined(HAVE_TIMERFD_CREATE) && defined(HAVE_SYS_TIMERFD_H)
+ if (timerfd_create(CLOCK_REALTIME, 0) < 0) {
+ return 1;
+ }
+#else
+ return 1;
+#endif
+ return 0;
+}
+ ],
+ [rb__cv_timerfd_create_works=yes],
+ [rb__cv_timerfd_create_works=no])
+ ])
+case $rb__cv_timerfd_create_works in
+ yes) AC_DEFINE([USE_TIMERFD_CREATE], 1,
+ [Define to 1 if we can use timerfd_create(CLOCK_REALTIME,...)]);;
+esac
+])
+
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
-# Inc.
+# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+# Free Software Foundation, Inc.
-timestamp='2007-07-22'
+timestamp='2008-01-23'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
GNU config.guess ($timestamp)
Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
-Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
echo rs6000-ibm-aix3.2
fi
exit ;;
- *:AIX:*:[45])
+ *:AIX:*:[456])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000
EM64T | authenticamd)
echo x86_64-unknown-interix${UNAME_RELEASE}
exit ;;
+ IA64)
+ echo ia64-unknown-interix${UNAME_RELEASE}
+ exit ;;
esac ;;
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
echo i${UNAME_MACHINE}-pc-mks
echo ${UNAME_MACHINE}-pc-minix
exit ;;
arm*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
+ eval $set_cc_for_build
+ if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+ | grep -q __ARM_EABI__
+ then
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ else
+ echo ${UNAME_MACHINE}-unknown-linux-gnueabi
+ fi
exit ;;
avr32*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
x86_64:Linux:*:*)
echo x86_64-unknown-linux-gnu
exit ;;
- xtensa:Linux:*:*)
- echo xtensa-unknown-linux-gnu
+ xtensa*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
i*86:Linux:*:*)
# The BFD linker knows what the default object file format is, so
the operating system you are using. It is advised that you
download the most up to date version of the config scripts from
- http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
and
- http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
If the version you run ($0) is already up to date, please
send the following data and any information you think might be
#! /bin/sh
# Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
-# Inc.
+# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+# Free Software Foundation, Inc.
-timestamp='2007-06-28'
+timestamp='2008-01-16'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
version="\
GNU config.sub ($timestamp)
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
-Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
| v850-* | v850e-* | vax-* \
| we32k-* \
| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
- | xstormy16-* | xtensa-* \
+ | xstormy16-* | xtensa*-* \
| ymp-* \
| z8k-*)
;;
+ # Recognize the basic CPU types without company name, with glob match.
+ xtensa*)
+ basic_machine=$basic_machine-unknown
+ ;;
# Recognize the various machine names and aliases which stand
# for a CPU type and a company and sometimes even an OS.
386bsd)
basic_machine=ns32k-sequent
os=-dynix
;;
+ blackfin)
+ basic_machine=bfin-unknown
+ os=-linux
+ ;;
+ blackfin-*)
+ basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=-linux
+ ;;
c90)
basic_machine=c90-cray
os=-unicos
basic_machine=m68k-isi
os=-sysv
;;
+ m68knommu)
+ basic_machine=m68k-unknown
+ os=-linux
+ ;;
+ m68knommu-*)
+ basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=-linux
+ ;;
m88k-omron*)
basic_machine=m88k-omron
;;
basic_machine=i860-intel
os=-osf
;;
+ parisc)
+ basic_machine=hppa-unknown
+ os=-linux
+ ;;
+ parisc-*)
+ basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=-linux
+ ;;
pbd)
basic_machine=sparc-tti
;;
basic_machine=tic6x-unknown
os=-coff
;;
+ tile*)
+ basic_machine=tile-unknown
+ os=-linux-gnu
+ ;;
tx39)
basic_machine=mipstx39-unknown
;;
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for libratbox devel.
#
-# $Id: configure.ac 25689 2008-07-10 17:13:27Z androsyn $
+# $Id: configure.ac 26168 2008-10-26 20:58:40Z androsyn $
#
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
CP
MV
LN
-AR
-LD
-RANLIB
TOUCH
build
build_cpu
host_os
LN_S
ECHO
+AR
+RANLIB
DSYMUTIL
NMEDIT
CPP
FFLAGS
ac_ct_F77
LIBTOOL
-subdirs
MINGW_TRUE
MINGW_FALSE
NEED_CRYPT_TRUE
PKG_CONFIG
GNUTLS_CFLAGS
GNUTLS_LIBS'
-ac_subdirs_all='libltdl'
+
# Initialize some variables set by options.
ac_init_help=
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
-$Id: configure.ac 25689 2008-07-10 17:13:27Z androsyn $
+$Id: configure.ac 26168 2008-10-26 20:58:40Z androsyn $
_ACEOF
exit
fi
fi
-# Extract the first word of "ar", so it can be a program name with args.
-set dummy ar; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_path_AR+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- case $AR in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_AR="$AR" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
- ac_cv_path_AR="$as_dir/$ac_word$ac_exec_ext"
- echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
-done
-IFS=$as_save_IFS
-
- ;;
-esac
-fi
-AR=$ac_cv_path_AR
-if test -n "$AR"; then
- { echo "$as_me:$LINENO: result: $AR" >&5
-echo "${ECHO_T}$AR" >&6; }
-else
- { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
-
-# Extract the first word of "ld", so it can be a program name with args.
-set dummy ld; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_path_LD+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- case $LD in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_LD="$LD" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
- ac_cv_path_LD="$as_dir/$ac_word$ac_exec_ext"
- echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
-done
-IFS=$as_save_IFS
-
- ;;
-esac
-fi
-LD=$ac_cv_path_LD
-if test -n "$LD"; then
- { echo "$as_me:$LINENO: result: $LD" >&5
-echo "${ECHO_T}$LD" >&6; }
-else
- { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
-
-# Extract the first word of "ranlib", so it can be a program name with args.
-set dummy ranlib; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_path_RANLIB+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- case $RANLIB in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_RANLIB="$RANLIB" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
- ac_cv_path_RANLIB="$as_dir/$ac_word$ac_exec_ext"
- echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
-done
-IFS=$as_save_IFS
-
- ;;
-esac
-fi
-RANLIB=$ac_cv_path_RANLIB
-if test -n "$RANLIB"; then
- { echo "$as_me:$LINENO: result: $RANLIB" >&5
-echo "${ECHO_T}$RANLIB" >&6; }
-else
- { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
-
# Extract the first word of "touch", so it can be a program name with args.
set dummy touch; ac_word=$2
{ echo "$as_me:$LINENO: checking for $ac_word" >&5
;;
*-*-irix6*)
# Find out which ABI we are using.
- echo '#line 5620 "configure"' > conftest.$ac_ext
+ echo '#line 5498 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:8672: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8550: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:8676: \$? = $ac_status" >&5
+ echo "$as_me:8554: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:8962: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8840: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:8966: \$? = $ac_status" >&5
+ echo "$as_me:8844: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:9066: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8944: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:9070: \$? = $ac_status" >&5
+ echo "$as_me:8948: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
-#line 11443 "configure"
+#line 11321 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
-#line 11543 "configure"
+#line 11421 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:13944: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:13822: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:13948: \$? = $ac_status" >&5
+ echo "$as_me:13826: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14048: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:13926: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:14052: \$? = $ac_status" >&5
+ echo "$as_me:13930: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:15646: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:15524: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:15650: \$? = $ac_status" >&5
+ echo "$as_me:15528: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:15750: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:15628: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:15754: \$? = $ac_status" >&5
+ echo "$as_me:15632: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:17970: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:17848: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:17974: \$? = $ac_status" >&5
+ echo "$as_me:17852: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:18260: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:18138: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:18264: \$? = $ac_status" >&5
+ echo "$as_me:18142: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:18364: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:18242: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:18368: \$? = $ac_status" >&5
+ echo "$as_me:18246: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
LIBTOOL="$LIBTOOL --silent"
-subdirs="$subdirs libltdl"
-
-
-
case "$host_os" in
*cygwin*)
fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_WINSOCK2_H 1
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_WINSOCK_H 1
+_ACEOF
+
LIBS="$LIBS -lws2_32 -liphlpapi"
is_mingw="yes"
;;
# backwards support for IRC_CFLAGS
-CFLAGS="$IRC_CFLAGS $CFLAGS -O0 -Wall"
+CFLAGS="$IRC_CFLAGS $CFLAGS -Wall"
if test "$libexecdir" = '${exec_prefix}/libexec' &&
test "$localstatedir" = '${prefix}/var'; then
-for ac_header in crypt.h unistd.h sys/socket.h sys/stat.h sys/time.h time.h netinet/in.h arpa/inet.h errno.h sys/uio.h spawn.h sys/poll.h sys/epoll.h sys/select.h sys/devpoll.h sys/event.h port.h signal.h sys/signalfd.h
+
+for ac_header in crypt.h unistd.h sys/socket.h sys/stat.h sys/time.h time.h netinet/in.h arpa/inet.h errno.h sys/uio.h spawn.h sys/poll.h sys/epoll.h sys/select.h sys/devpoll.h sys/event.h port.h signal.h sys/signalfd.h sys/timerfd.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
-
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
int getpeername (int, $arg2 *, $t *);
int
done
if test "x$rb_socklen_t" = x; then
- { { echo "$as_me:$LINENO: error: Cannot find a type to use in place of socklen_t" >&5
-echo "$as_me: error: Cannot find a type to use in place of socklen_t" >&2;}
- { (exit 1); exit 1; }; }
+ { echo "$as_me:$LINENO: WARNING: Cannot find a type to use in place of socklen_t using int" >&5
+echo "$as_me: WARNING: Cannot find a type to use in place of socklen_t using int" >&2;}
+ rb_socklen_t=int
fi
fi
-for ac_func in socketpair gettimeofday writev sendmsg gmtime_r strtok_r usleep posix_spawn strlcpy strlcat strnlen fstat signalfd select poll kevent port_create epoll_ctl arc4random getrusage
+
+for ac_func in socketpair gettimeofday writev sendmsg gmtime_r strtok_r usleep posix_spawn strlcpy strlcat strnlen fstat signalfd select poll kevent port_create epoll_ctl arc4random getrusage timerfd_create
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
;;
esac
+{ echo "$as_me:$LINENO: checking for a working timerfd_create(CLOCK_REALTIME)" >&5
+echo $ECHO_N "checking for a working timerfd_create(CLOCK_REALTIME)... $ECHO_C" >&6; }
+if test "${rb__cv_timerfd_create_works+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test "$cross_compiling" = yes; then
+ { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TIMERFD_H
+#include <sys/timerfd.h>
+#endif
+int main(int argc, char *argv[])
+{
+#if defined(HAVE_TIMERFD_CREATE) && defined(HAVE_SYS_TIMERFD_H)
+ if (timerfd_create(CLOCK_REALTIME, 0) < 0) {
+ return 1;
+ }
+#else
+ return 1;
+#endif
+ return 0;
+}
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ rb__cv_timerfd_create_works=yes
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+rb__cv_timerfd_create_works=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
+fi
+{ echo "$as_me:$LINENO: result: $rb__cv_timerfd_create_works" >&5
+echo "${ECHO_T}$rb__cv_timerfd_create_works" >&6; }
+case $rb__cv_timerfd_create_works in
+ yes)
+cat >>confdefs.h <<\_ACEOF
+#define USE_TIMERFD_CREATE 1
+_ACEOF
+;;
+esac
+
# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
# for constant arguments. Useless!
fi
-
if test "$cf_enable_openssl" != no; then
CPPFLAGS="$CPPFLAGS $SSL_LIBS"
{ echo "$as_me:$LINENO: checking for SSL_read in -lssl" >&5
{ echo "$as_me:$LINENO: result: $ac_cv_lib_ssl_SSL_read" >&5
echo "${ECHO_T}$ac_cv_lib_ssl_SSL_read" >&6; }
if test $ac_cv_lib_ssl_SSL_read = yes; then
- SSL_LIBS="-lssl -lcrypto"
+ SSL_LIBS="$SSL_LIBS -lssl -lcrypto"
else
cf_enable_openssl=no
fi
CP!$CP$ac_delim
MV!$MV$ac_delim
LN!$LN$ac_delim
-AR!$AR$ac_delim
-LD!$LD$ac_delim
-RANLIB!$RANLIB$ac_delim
TOUCH!$TOUCH$ac_delim
build!$build$ac_delim
build_cpu!$build_cpu$ac_delim
host!$host$ac_delim
host_cpu!$host_cpu$ac_delim
host_vendor!$host_vendor$ac_delim
+host_os!$host_os$ac_delim
+LN_S!$LN_S$ac_delim
+ECHO!$ECHO$ac_delim
_ACEOF
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
ac_delim='%!_!# '
for ac_last_try in false false false false false :; do
cat >conf$$subs.sed <<_ACEOF
-host_os!$host_os$ac_delim
-LN_S!$LN_S$ac_delim
-ECHO!$ECHO$ac_delim
+AR!$AR$ac_delim
+RANLIB!$RANLIB$ac_delim
DSYMUTIL!$DSYMUTIL$ac_delim
NMEDIT!$NMEDIT$ac_delim
CPP!$CPP$ac_delim
FFLAGS!$FFLAGS$ac_delim
ac_ct_F77!$ac_ct_F77$ac_delim
LIBTOOL!$LIBTOOL$ac_delim
-subdirs!$subdirs$ac_delim
MINGW_TRUE!$MINGW_TRUE$ac_delim
MINGW_FALSE!$MINGW_FALSE$ac_delim
NEED_CRYPT_TRUE!$NEED_CRYPT_TRUE$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 34; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 32; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
if test "x$rb_sockaddr_storage" = "xyes"; then
echo '#define rb_sockaddr_storage sockaddr_storage' >> $outfile
else
- echo 'struct rb_sockaddr_storage { uint8_t _padding128; };' >> $outfile
+ echo 'struct rb_sockaddr_storage { uint8_t _padding[128]; };' >> $outfile
fi
cat >> $outfile <<\_______EOF
$ac_cs_success || { (exit 1); exit 1; }
fi
-#
-# CONFIG_SUBDIRS section.
-#
-if test "$no_recursion" != yes; then
-
- # Remove --cache-file and --srcdir arguments so they do not pile up.
- ac_sub_configure_args=
- ac_prev=
- eval "set x $ac_configure_args"
- shift
- for ac_arg
- do
- if test -n "$ac_prev"; then
- ac_prev=
- continue
- fi
- case $ac_arg in
- -cache-file | --cache-file | --cache-fil | --cache-fi \
- | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
- ac_prev=cache_file ;;
- -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
- | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \
- | --c=*)
- ;;
- --config-cache | -C)
- ;;
- -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
- ac_prev=srcdir ;;
- -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
- ;;
- -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
- ac_prev=prefix ;;
- -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
- ;;
- *)
- case $ac_arg in
- *\'*) ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
- esac
- ac_sub_configure_args="$ac_sub_configure_args '$ac_arg'" ;;
- esac
- done
-
- # Always prepend --prefix to ensure using the same prefix
- # in subdir configurations.
- ac_arg="--prefix=$prefix"
- case $ac_arg in
- *\'*) ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
- esac
- ac_sub_configure_args="'$ac_arg' $ac_sub_configure_args"
-
- # Pass --silent
- if test "$silent" = yes; then
- ac_sub_configure_args="--silent $ac_sub_configure_args"
- fi
-
- ac_popdir=`pwd`
- for ac_dir in : $subdirs; do test "x$ac_dir" = x: && continue
-
- # Do not complain, so a configure script can configure whichever
- # parts of a large source tree are present.
- test -d "$srcdir/$ac_dir" || continue
-
- ac_msg="=== configuring in $ac_dir (`pwd`/$ac_dir)"
- echo "$as_me:$LINENO: $ac_msg" >&5
- echo "$ac_msg" >&6
- { as_dir="$ac_dir"
- case $as_dir in #(
- -*) as_dir=./$as_dir;;
- esac
- test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || {
- as_dirs=
- while :; do
- case $as_dir in #(
- *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #(
- *) as_qdir=$as_dir;;
- esac
- as_dirs="'$as_qdir' $as_dirs"
- as_dir=`$as_dirname -- "$as_dir" ||
-$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
- X"$as_dir" : 'X\(//\)[^/]' \| \
- X"$as_dir" : 'X\(//\)$' \| \
- X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
-echo X"$as_dir" |
- sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
- s//\1/
- q
- }
- /^X\(\/\/\)[^/].*/{
- s//\1/
- q
- }
- /^X\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`
- test -d "$as_dir" && break
- done
- test -z "$as_dirs" || eval "mkdir $as_dirs"
- } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5
-echo "$as_me: error: cannot create directory $as_dir" >&2;}
- { (exit 1); exit 1; }; }; }
- ac_builddir=.
-
-case "$ac_dir" in
-.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
-*)
- ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
- # A ".." for each directory in $ac_dir_suffix.
- ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'`
- case $ac_top_builddir_sub in
- "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
- *) ac_top_build_prefix=$ac_top_builddir_sub/ ;;
- esac ;;
-esac
-ac_abs_top_builddir=$ac_pwd
-ac_abs_builddir=$ac_pwd$ac_dir_suffix
-# for backward compatibility:
-ac_top_builddir=$ac_top_build_prefix
-
-case $srcdir in
- .) # We are building in place.
- ac_srcdir=.
- ac_top_srcdir=$ac_top_builddir_sub
- ac_abs_top_srcdir=$ac_pwd ;;
- [\\/]* | ?:[\\/]* ) # Absolute name.
- ac_srcdir=$srcdir$ac_dir_suffix;
- ac_top_srcdir=$srcdir
- ac_abs_top_srcdir=$srcdir ;;
- *) # Relative name.
- ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
- ac_top_srcdir=$ac_top_build_prefix$srcdir
- ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
-esac
-ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
-
-
- cd "$ac_dir"
-
- # Check for guested configure; otherwise get Cygnus style configure.
- if test -f "$ac_srcdir/configure.gnu"; then
- ac_sub_configure=$ac_srcdir/configure.gnu
- elif test -f "$ac_srcdir/configure"; then
- ac_sub_configure=$ac_srcdir/configure
- elif test -f "$ac_srcdir/configure.in"; then
- # This should be Cygnus configure.
- ac_sub_configure=$ac_aux_dir/configure
- else
- { echo "$as_me:$LINENO: WARNING: no configuration information is in $ac_dir" >&5
-echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2;}
- ac_sub_configure=
- fi
-
- # The recursion is here.
- if test -n "$ac_sub_configure"; then
- # Make the cache file name correct relative to the subdirectory.
- case $cache_file in
- [\\/]* | ?:[\\/]* ) ac_sub_cache_file=$cache_file ;;
- *) # Relative name.
- ac_sub_cache_file=$ac_top_build_prefix$cache_file ;;
- esac
-
- { echo "$as_me:$LINENO: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&5
-echo "$as_me: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&6;}
- # The eval makes quoting arguments work.
- eval "\$SHELL \"\$ac_sub_configure\" $ac_sub_configure_args \
- --cache-file=\"\$ac_sub_cache_file\" --srcdir=\"\$ac_srcdir\"" ||
- { { echo "$as_me:$LINENO: error: $ac_sub_configure failed for $ac_dir" >&5
-echo "$as_me: error: $ac_sub_configure failed for $ac_dir" >&2;}
- { (exit 1); exit 1; }; }
- fi
-
- cd "$ac_popdir"
- done
-fi
-
echo
-dnl $Id: configure.ac 25689 2008-07-10 17:13:27Z androsyn $
+dnl $Id: configure.ac 26168 2008-10-26 20:58:40Z androsyn $
dnl Process this file with autoconf to produce a configure script.
dnl TODO: clean up all the OpenSSL and shared module checking stuff;
dnl the most major changes have already been made and it looks like
dnl said functions need to be just about as complex as they already are.
-AC_PREREQ(2.60)
+AC_PREREQ(2.61)
AUTOMAKE_OPTIONS = 1.10
dnl Sneaky way to get an Id tag into the configure script
-AC_COPYRIGHT([$Id: configure.ac 25689 2008-07-10 17:13:27Z androsyn $])
+AC_COPYRIGHT([$Id: configure.ac 26168 2008-10-26 20:58:40Z androsyn $])
AC_INIT([libratbox],[devel])
AM_INIT_AUTOMAKE(AC_PACKAGE_TARNAME, AC_PACKAGE_VERSION, -)
AC_PATH_PROG(CP, cp)
AC_PATH_PROG(MV, mv)
AC_PATH_PROG(LN, ln)
-AC_PATH_PROG(AR, ar)
-AC_PATH_PROG(LD, ld)
-AC_PATH_PROG(RANLIB, ranlib)
AC_PATH_PROG(TOUCH, touch)
AC_LANG(C)
LIBTOOL="$LIBTOOL --silent"
-AC_CONFIG_SUBDIRS(libltdl)
-
-
case "$host_os" in
*cygwin*)
AC_DEFINE_UNQUOTED(CYGWIN,1,[This is a Cygwin system])
AC_DEFINE_UNQUOTED(WINDOWS,1,[This is a Windows system])
AC_CHECK_HEADER(windows.h, , [AC_MSG_ERROR([** MinGW and no windows.h. I give up.])])
AC_CHECK_HEADER(winsock2.h, , [AC_MSG_ERROR([** MinGW and no winsock2.h. I give up.])])
+ AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1, [Have WINSOCK2_H])
+ AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1, [Have WINSOCK_H])
LIBS="$LIBS -lws2_32 -liphlpapi"
is_mingw="yes"
;;
# backwards support for IRC_CFLAGS
-CFLAGS="$IRC_CFLAGS $CFLAGS -O0 -Wall"
+CFLAGS="$IRC_CFLAGS $CFLAGS -Wall"
dnl use directory structure of cached as default (hack)
if test "$libexecdir" = '${exec_prefix}/libexec' &&
dnl Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([crypt.h unistd.h sys/socket.h sys/stat.h sys/time.h time.h netinet/in.h arpa/inet.h errno.h sys/uio.h spawn.h sys/poll.h sys/epoll.h sys/select.h sys/devpoll.h sys/event.h port.h signal.h sys/signalfd.h])
+AC_CHECK_HEADERS([crypt.h unistd.h sys/socket.h sys/stat.h sys/time.h time.h netinet/in.h arpa/inet.h errno.h sys/uio.h spawn.h sys/poll.h sys/epoll.h sys/select.h sys/devpoll.h sys/event.h port.h signal.h sys/signalfd.h sys/timerfd.h])
AC_HEADER_TIME
dnl Networking Functions
for arg2 in "struct sockaddr" void; do
for t in int size_t unsigned long "unsigned long"; do
AC_TRY_COMPILE([
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
-
+#endif
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
int getpeername (int, $arg2 *, $t *);
],[
$t len;
done
if test "x$rb_socklen_t" = x; then
- AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
+ AC_MSG_WARN([Cannot find a type to use in place of socklen_t using int])
+ rb_socklen_t=int
fi
])
AC_MSG_RESULT($rb_socklen_t)],
dnl check for various functions...
-AC_CHECK_FUNCS([socketpair gettimeofday writev sendmsg gmtime_r strtok_r usleep posix_spawn strlcpy strlcat strnlen fstat signalfd select poll kevent port_create epoll_ctl arc4random getrusage])
+AC_CHECK_FUNCS([socketpair gettimeofday writev sendmsg gmtime_r strtok_r usleep posix_spawn strlcpy strlcat strnlen fstat signalfd select poll kevent port_create epoll_ctl arc4random getrusage timerfd_create])
AC_SEARCH_LIBS(nanosleep, rt posix4, AC_DEFINE(HAVE_NANOSLEEP, 1, [Define if you have nanosleep]))
AC_SEARCH_LIBS(timer_create, rt, AC_DEFINE(HAVE_TIMER_CREATE, 1, [Define if you have timer_create]))
RB_CHECK_TIMER_CREATE
+RB_CHECK_TIMERFD_CREATE
AC_FUNC_ALLOCA
AC_FUNC_VFORK
[cf_enable_openssl=no])
fi
-
if test "$cf_enable_openssl" != no; then
CPPFLAGS="$CPPFLAGS $SSL_LIBS"
AC_CHECK_LIB(ssl, SSL_read,
- [SSL_LIBS="-lssl -lcrypto"],
+ [SSL_LIBS="$SSL_LIBS -lssl -lcrypto"],
[cf_enable_openssl=no], [-lcrypto])
fi
if test "x$rb_sockaddr_storage" = "xyes"; then
echo '#define rb_sockaddr_storage sockaddr_storage' >> $outfile
else
- echo 'struct rb_sockaddr_storage { uint8_t _padding[128]; };' >> $outfile
+ echo 'struct rb_sockaddr_storage { uint8_t _padding[[128]]; };' >> $outfile
fi
cat >> $outfile <<\_______EOF
AC_CONFIG_FILES( \
src/Makefile \
Makefile \
- libratbox.pc \
+ libratbox.pc \
)
AC_OUTPUT
void arc4random_stir(void);
uint32_t arc4random(void);
void arc4random_addrandom(uint8_t *dat, int datlen);
-#endif
\ No newline at end of file
+#endif
#define FD_DESC_SZ 128 /* hostlen + comment */
-#ifdef WIN32
+#ifdef _WIN32
#define rb_get_errno() do { errno = WSAGetLastError(); WSASetLastError(errno); } while(0)
#else
#define rb_get_errno()
#define rb_hash_fd(x) ((x ^ (x >> RB_FD_HASH_BITS) ^ (x >> (RB_FD_HASH_BITS * 2))) & RB_FD_HASH_MASK)
#ifdef HAVE_WRITEV
- #ifndef UIO_MAXIOV
- # if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+#ifndef UIO_MAXIOV
+# if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)
/* FreeBSD 4.7 defines it in sys/uio.h only if _KERNEL is specified */
- # define RB_UIO_MAXIOV 1024
- # elif defined(__sgi)
+# define RB_UIO_MAXIOV 1024
+# elif defined(__sgi)
/* IRIX 6.5 has sysconf(_SC_IOV_MAX) which might return 512 or bigger */
- # define RB_UIO_MAXIOV 512
- # elif defined(__sun)
+# define RB_UIO_MAXIOV 512
+# elif defined(__sun)
/* Solaris (and SunOS?) defines IOV_MAX instead */
- # ifndef IOV_MAX
- # define RB_UIO_MAXIOV 16
- # else
- # define RB_UIO_MAXIOV IOV_MAX
- # endif
-
- # elif defined(IOV_MAX)
- # define RB_UIO_MAXIOV IOV_MAX
- # else
- # define RB_UIO_MAXIOV 16
- # endif
- #else
- #define RB_UIO_MAXIOV UIO_MAXIOV
- #endif
+# ifndef IOV_MAX
+# define RB_UIO_MAXIOV 16
+# else
+# define RB_UIO_MAXIOV IOV_MAX
+# endif
+
+# elif defined(IOV_MAX)
+# define RB_UIO_MAXIOV IOV_MAX
+# else
+# define RB_UIO_MAXIOV 16
+# endif
#else
- #define RB_UIO_MAXIOV 16
+#define RB_UIO_MAXIOV UIO_MAXIOV
+#endif
+#else
+#define RB_UIO_MAXIOV 16
#endif
struct conndata
{
struct rb_sockaddr_storage S;
rb_socklen_t addrlen;
ACCB *callback;
- ACPRE *precb;
+ ACPRE *precb;
void *data;
};
unsigned long ssl_errno;
};
-typedef void (*comm_event_cb_t)(void *);
+typedef void (*comm_event_cb_t) (void *);
#ifdef USE_TIMER_CREATE
-typedef struct timer_data {
- timer_t td_timer_id;
- comm_event_cb_t td_cb;
+typedef struct timer_data
+{
+ timer_t td_timer_id;
+ comm_event_cb_t td_cb;
void *td_udata;
int td_repeat;
} *comm_event_id;
{
rb_dlink_list *hlist;
rb_dlink_node *ptr;
-
+
if(rb_unlikely(fd < 0))
return NULL;
rb_fde_t *F = ptr->data;
if(F->fd == fd)
return F;
- }
+ }
return NULL;
}
int rb_io_sched_event(struct ev_entry *ev, int when);
-void rb_io_unsched_event(struct ev_entry *ev);
+void rb_io_unsched_event(struct ev_entry *ev);
int rb_io_supports_event(void);
void rb_io_init_event(void);
int rb_epoll_sched_event(struct ev_entry *event, int when);
void rb_epoll_unsched_event(struct ev_entry *event);
int rb_epoll_supports_event(void);
-
+
/* poll versions */
void rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data);
int rb_init_netio_win32(void);
int rb_select_win32(long);
int rb_setup_fd_win32(rb_fde_t *F);
-
int rb_get_random(void *buf, size_t length);
const char *rb_get_ssl_strerror(rb_fde_t *F);
-void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB *cb, void *data, int timeout);
-void rb_ssl_start_connected(rb_fde_t *F, CNCB *callback, void *data, int timeout);
-void rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest, struct sockaddr *clocal, int socklen, CNCB *callback, void *data, int timeout);
+void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout);
+void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout);
+void rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest, struct sockaddr *clocal, int socklen,
+ CNCB * callback, void *data, int timeout);
void rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen);
void rb_ssl_shutdown(rb_fde_t *F);
ssize_t rb_ssl_read(rb_fde_t *F, void *buf, size_t count);
ssize_t rb_ssl_write(rb_fde_t *F, const void *buf, size_t count);
-
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: event-int.h 24840 2008-01-03 19:42:17Z androsyn $
+ * $Id: event-int.h 25992 2008-09-03 00:20:22Z androsyn $
*/
-
struct ev_entry
{
rb_dlink_node node;
EVH *func;
void *arg;
- const char *name;
+ char *name;
time_t frequency;
time_t when;
void *data;
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
+/* Define to 1 if you have the <sys/timerfd.h> header file. */
+#undef HAVE_SYS_TIMERFD_H
+
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/uio.h> header file. */
#undef HAVE_SYS_UIO_H
+/* Define to 1 if you have the `timerfd_create' function. */
+#undef HAVE_TIMERFD_CREATE
+
/* Define if you have timer_create */
#undef HAVE_TIMER_CREATE
/* Define to 1 if you are on windows */
#undef HAVE_WIN32
+/* Have WINSOCK2_H */
+#undef HAVE_WINSOCK2_H
+
+/* Have WINSOCK_H */
+#undef HAVE_WINSOCK_H
+
/* Define to 1 if `fork' works. */
#undef HAVE_WORKING_FORK
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
+/* Define to 1 if we can use timerfd_create(CLOCK_REALTIME,...) */
+#undef USE_TIMERFD_CREATE
+
/* Define to 1 if we can use timer_create(CLOCK_REALTIME,...) */
#undef USE_TIMER_CREATE
/*
- * $Id: ratbox_lib.h 25375 2008-05-16 15:19:51Z androsyn $
+ * $Id: ratbox_lib.h 26052 2008-09-09 16:47:03Z androsyn $
*/
#ifndef RB_LIB_H
-#ifdef WIN32
+#ifdef _WIN32
#include <process.h>
#ifndef MAXPATHLEN
#define MAXPATHLEN 128
#endif
-
#ifdef strerror
#undef strerror
#endif
-#define strerror(x) wsock_strerror(x)
-const char *wsock_strerror(int error);
+#define strerror(x) rb_strerror(x)
+char *rb_strerror(int error);
#define ENOBUFS WSAENOBUFS
#define pipe(x) _pipe(x, 1024, O_BINARY)
#define ioctl(x,y,z) ioctlsocket(x,y, (u_long *)z)
-int setenv(const char *, const char *, int);
-int kill(int pid, int sig);
#define WNOHANG 1
-pid_t waitpid(pid_t pid, int *status, int options);
-pid_t getpid(void);
-unsigned int geteuid(void);
#ifndef SIGKILL
#define SIGKILL SIGTERM
#endif
-#endif /* WIN32 */
+#endif /* _WIN32 */
#define HOSTIPLEN 53
#endif
-#ifdef SOFT_ASSERT
#ifdef __GNUC__
-#define lrb_assert(expr) do \
+#define slrb_assert(expr) do \
if(rb_unlikely(!(expr))) { \
rb_lib_log( \
"file: %s line: %d (%s): Assertion failed: (%s)", \
} \
while(0)
#else
-#define lrb_assert(expr) do \
+#define slrb_assert(expr) do \
if(rb_unlikely(!(expr))) { \
rb_lib_log(L_MAIN, \
"file: %s line: %d: Assertion failed: (%s)", \
} \
while(0)
#endif
+
+#ifdef SOFT_ASSERT
+#define lrb_assert(expr) slrb_assert(expr)
#else
-#define lrb_assert(expr) assert(expr)
+#define lrb_assert(expr) do { slrb_assert(expr); assert(expr); } while(0)
#endif
#ifdef RB_SOCKADDR_HAS_SA_LEN
#define ss_len sa_len
#endif
-#define GET_SS_FAMILY(x) (((struct sockaddr *)(x))->sa_family)
-
+#define GET_SS_FAMILY(x) (((const struct sockaddr *)(x))->sa_family)
+#define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y)
#ifdef RB_SOCKADDR_HAS_SA_LEN
#define SET_SS_LEN(x, y) do { \
struct sockaddr *storage; \
unsigned char *rb_base64_encode(const unsigned char *str, int length);
unsigned char *rb_base64_decode(const unsigned char *str, int length, int *ret);
+int rb_kill(pid_t, int);
+char *rb_strerror(int);
+int rb_setenv(const char *, const char *, int);
+int rb_kill(int pid, int sig);
+pid_t rb_waitpid(pid_t pid, int *status, int options);
+pid_t rb_getpid(void);
+//unsigned int rb_geteuid(void);
#include <rb_tools.h>
#include <rb_memory.h>
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_balloc.h 24324 2007-08-31 22:05:45Z androsyn $
+ * $Id: rb_balloc.h 26092 2008-09-19 15:13:52Z androsyn $
*/
#ifndef RB_LIB_H
struct rb_bh;
typedef struct rb_bh rb_bh;
-typedef void rb_bh_usage_cb(size_t bused, size_t bfree, size_t bmemusage, size_t heapalloc, const char *desc, void *data);
+typedef void rb_bh_usage_cb (size_t bused, size_t bfree, size_t bmemusage, size_t heapalloc,
+ const char *desc, void *data);
int rb_bh_free(rb_bh *, void *);
void *rb_bh_alloc(rb_bh *);
rb_bh *rb_bh_create(size_t elemsize, int elemsperblock, const char *desc);
-int rb_bh_destroy(rb_bh * bh);
+int rb_bh_destroy(rb_bh *bh);
int rb_bh_gc(rb_bh *bh);
void rb_init_bh(void);
-void rb_bh_usage(rb_bh * bh, size_t * bused, size_t * bfree, size_t * bmemusage, const char **desc);
+void rb_bh_usage(rb_bh *bh, size_t *bused, size_t *bfree, size_t *bmemusage, const char **desc);
void rb_bh_usage_all(rb_bh_usage_cb *cb, void *data);
void rb_bh_total_usage(size_t *total_alloc, size_t *total_used);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_commio.h 25693 2008-07-10 18:27:23Z androsyn $
+ * $Id: rb_commio.h 26092 2008-09-19 15:13:52Z androsyn $
*/
-
+
#ifndef RB_LIB_H
-# error "Do not use commio.h directly"
+# error "Do not use commio.h directly"
#endif
#ifndef INCLUDED_commio_h
#define INCLUDED_commio_h
-struct sockaddr;
+struct sockaddr;
struct _fde;
typedef struct _fde rb_fde_t;
#define RB_FD_NONE 0x01
#define RB_FD_FILE 0x02
#define RB_FD_SOCKET 0x04
-#ifndef WIN32
+#ifndef _WIN32
#define RB_FD_PIPE 0x08
#else
#define RB_FD_PIPE RB_FD_SOCKET
void rb_fdlist_init(int closeall, int maxfds, size_t heapsize);
-rb_fde_t * rb_open(int, uint8_t, const char *);
+rb_fde_t *rb_open(int, uint8_t, const char *);
void rb_close(rb_fde_t *);
void rb_dump_fd(DUMPCB *, void *xdata);
void rb_note(rb_fde_t *, const char *);
void rb_settimeout(rb_fde_t *, time_t, PF *, void *);
void rb_checktimeouts(void *);
-void rb_connect_tcp(rb_fde_t *, struct sockaddr *,
- struct sockaddr *, int, CNCB *, void *, int);
-void rb_connect_tcp_ssl(rb_fde_t *, struct sockaddr *,
- struct sockaddr *, int, CNCB *, void *, int);
+void rb_connect_tcp(rb_fde_t *, struct sockaddr *, struct sockaddr *, int, CNCB *, void *, int);
+void rb_connect_tcp_ssl(rb_fde_t *, struct sockaddr *, struct sockaddr *, int, CNCB *, void *, int);
int rb_connect_sockaddr(rb_fde_t *, struct sockaddr *addr, int len);
const char *rb_errstr(int status);
rb_fde_t *rb_socket(int family, int sock_type, int proto, const char *note);
-int rb_socketpair(int family, int sock_type, int proto, rb_fde_t **F1, rb_fde_t **F2, const char *note);
+int rb_socketpair(int family, int sock_type, int proto, rb_fde_t **F1, rb_fde_t **F2,
+ const char *note);
-void rb_accept_tcp(rb_fde_t *, ACPRE *precb, ACCB *callback, void *data);
+void rb_accept_tcp(rb_fde_t *, ACPRE * precb, ACCB * callback, void *data);
ssize_t rb_write(rb_fde_t *, const void *buf, int count);
ssize_t rb_writev(rb_fde_t *, struct rb_iovec *vector, int count);
rb_fde_t *rb_get_fde(int fd);
-int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize);
+int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid);
int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int count);
void rb_set_type(rb_fde_t *F, uint8_t type);
const char *rb_get_iotype(void);
-typedef enum {
+typedef enum
+{
RB_PRNG_EGD,
RB_PRNG_FILE,
-#ifdef WIN32
+#ifdef _WIN32
RB_PRNGWIN32,
#endif
RB_PRNG_DEFAULT,
int rb_init_prng(const char *path, prng_seed_t seed_type);
int rb_get_random(void *buf, size_t len);
int rb_get_pseudo_random(void *buf, size_t len);
-void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB *cb, void *data, int timeout);
-void rb_ssl_start_connected(rb_fde_t *F, CNCB *callback, void *data, int timeout);
+void rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout);
+void rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout);
int rb_supports_ssl(void);
unsigned int rb_ssl_handshake_count(rb_fde_t *F);
void rb_ssl_clear_handshake_count(rb_fde_t *F);
-
+
+
+int rb_pass_fd_to_process(rb_fde_t *, pid_t, rb_fde_t *);
+rb_fde_t *rb_recv_fd(rb_fde_t *);
+
#endif /* INCLUDED_commio_h */
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_event.h 25151 2008-03-28 17:19:12Z androsyn $
+ * $Id: rb_event.h 26092 2008-09-19 15:13:52Z androsyn $
*/
#ifndef RB_LIB_H
-# error "Do not use event.h directly"
+# error "Do not use event.h directly"
#endif
#ifndef INCLUDED_event_h
void rb_event_find_delete(EVH * func, void *);
void rb_event_update(struct ev_entry *, time_t freq);
void rb_set_back_events(time_t);
-void rb_dump_events(void (*func)(char *, void *), void *ptr);
+void rb_dump_events(void (*func) (char *, void *), void *ptr);
void rb_run_event(struct ev_entry *);
time_t rb_event_next(void);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_helper.h 24936 2008-01-14 20:43:23Z androsyn $
+ * $Id: rb_helper.h 26092 2008-09-19 15:13:52Z androsyn $
*/
#ifndef RB_LIB_H
-rb_helper *rb_helper_start(const char *name, const char *fullpath, rb_helper_cb *read_cb, rb_helper_cb *error_cb);
+rb_helper *rb_helper_start(const char *name, const char *fullpath, rb_helper_cb * read_cb,
+ rb_helper_cb * error_cb);
-rb_helper *rb_helper_child(rb_helper_cb *read_cb, rb_helper_cb *error_cb,
- log_cb *ilog, restart_cb *irestart, die_cb *idie,
- int maxcon, size_t lb_heap_size, size_t dh_size, size_t fd_heap_size);
+rb_helper *rb_helper_child(rb_helper_cb * read_cb, rb_helper_cb * error_cb,
+ log_cb * ilog, restart_cb * irestart, die_cb * idie,
+ int maxcon, size_t lb_heap_size, size_t dh_size, size_t fd_heap_size);
void rb_helper_restart(rb_helper *helper);
#ifdef __GNUC__
-void rb_helper_write(rb_helper *helper, const char *format, ...) __attribute((format(printf, 2, 3)));
-void rb_helper_write_queue(rb_helper *helper, const char *format, ...) __attribute((format(printf, 2, 3)));
+void
+rb_helper_write(rb_helper *helper, const char *format, ...)
+__attribute((format(printf, 2, 3)));
+ void rb_helper_write_queue(rb_helper *helper, const char *format, ...)
+ __attribute((format(printf, 2, 3)));
#else
void rb_helper_write(rb_helper *helper, const char *format, ...);
void rb_helper_write_queue(rb_helper *helper, const char *format, ...);
#endif
void rb_helper_write_flush(rb_helper *helper);
-
+
void rb_helper_run(rb_helper *helper);
void rb_helper_close(rb_helper *helper);
int rb_helper_read(rb_helper *helper, void *buf, size_t bufsize);
void rb_helper_loop(rb_helper *helper, long delay);
#endif
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_linebuf.h 25675 2008-07-06 04:13:05Z androsyn $
+ * $Id: rb_linebuf.h 26092 2008-09-19 15:13:52Z androsyn $
*/
#ifndef RB_LIB_H
-# error "Do not use linebuf.h directly"
+# error "Do not use linebuf.h directly"
#endif
#ifndef __LINEBUF_H__
{
char buf[BUF_DATA_SIZE + 2];
uint8_t terminated; /* Whether we've terminated the buffer */
- uint8_t raw; /* Whether this linebuf may hold 8-bit data */
+ uint8_t raw; /* Whether this linebuf may hold 8-bit data */
int len; /* How much data we've got */
int refcount; /* how many linked lists are we in? */
} buf_line_t;
int rb_linebuf_get(buf_head_t *, char *, int, int, int);
void rb_linebuf_putmsg(buf_head_t *, const char *, va_list *, const char *, ...);
void rb_linebuf_put(buf_head_t *, const char *, ...);
-void rb_linebuf_putbuf(buf_head_t *bufhead, const char *buffer);
+void rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer);
void rb_linebuf_attach(buf_head_t *, buf_head_t *);
void rb_count_rb_linebuf_memory(size_t *, size_t *);
int rb_linebuf_flush(rb_fde_t *F, buf_head_t *);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_memory.h 25375 2008-05-16 15:19:51Z androsyn $
+ * $Id: rb_memory.h 26092 2008-09-19 15:13:52Z androsyn $
*/
#ifndef RB_LIB_H
if(rb_unlikely(ret == NULL))
rb_outofmemory();
rb_strlcpy(ret, x, y);
- return(ret);
+ return (ret);
}
static inline char *
if(rb_unlikely(ret == NULL))
rb_outofmemory();
strcpy(ret, x);
- return(ret);
+ return (ret);
}
static inline void
rb_free(void *ptr)
{
- if(rb_likely(ptr != NULL))
- free(ptr);
+ if(rb_likely(ptr != NULL))
+ free(ptr);
}
#endif /* _I_MEMORY_H */
-
typedef struct _rb_prefix_t
{
- unsigned short family; /* AF_INET | AF_INET6 */
- unsigned short bitlen; /* same as mask? */
+ unsigned short family; /* AF_INET | AF_INET6 */
+ unsigned short bitlen; /* same as mask? */
int ref_count; /* reference count */
union
{
typedef struct _rb_patricia_node_t
{
- unsigned int bit; /* flag if this node used */
+ unsigned int bit; /* flag if this node used */
rb_prefix_t *prefix; /* who we are in patricia tree */
struct _rb_patricia_node_t *l, *r; /* left and right children */
struct _rb_patricia_node_t *parent; /* may be used */
typedef struct _rb_patricia_tree_t
{
rb_patricia_node_t *head;
- unsigned int maxbits; /* for IP, 32 bit addresses */
+ unsigned int maxbits; /* for IP, 32 bit addresses */
int num_active_node; /* for debug purpose */
}
rb_patricia_tree_t;
-rb_patricia_node_t *rb_match_ip(rb_patricia_tree_t * tree, struct sockaddr *ip);
-rb_patricia_node_t *rb_match_ip_exact(rb_patricia_tree_t * tree, struct sockaddr *ip, unsigned int len);
-rb_patricia_node_t *rb_match_string(rb_patricia_tree_t * tree, const char *string);
-rb_patricia_node_t *rb_match_exact_string(rb_patricia_tree_t * tree, const char *string);
-rb_patricia_node_t *rb_patricia_search_exact(rb_patricia_tree_t * patricia, rb_prefix_t * prefix);
-rb_patricia_node_t *rb_patricia_search_best(rb_patricia_tree_t * patricia, rb_prefix_t * prefix);
-rb_patricia_node_t *rb_patricia_search_best2(rb_patricia_tree_t * patricia,
- rb_prefix_t * prefix, int inclusive);
-rb_patricia_node_t *rb_patricia_lookup(rb_patricia_tree_t * patricia, rb_prefix_t * prefix);
+rb_patricia_node_t *rb_match_ip(rb_patricia_tree_t *tree, struct sockaddr *ip);
+rb_patricia_node_t *rb_match_ip_exact(rb_patricia_tree_t *tree, struct sockaddr *ip,
+ unsigned int len);
+rb_patricia_node_t *rb_match_string(rb_patricia_tree_t *tree, const char *string);
+rb_patricia_node_t *rb_match_exact_string(rb_patricia_tree_t *tree, const char *string);
+rb_patricia_node_t *rb_patricia_search_exact(rb_patricia_tree_t *patricia, rb_prefix_t *prefix);
+rb_patricia_node_t *rb_patricia_search_best(rb_patricia_tree_t *patricia, rb_prefix_t *prefix);
+rb_patricia_node_t *rb_patricia_search_best2(rb_patricia_tree_t *patricia,
+ rb_prefix_t *prefix, int inclusive);
+rb_patricia_node_t *rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix);
-void rb_patricia_remove(rb_patricia_tree_t * patricia, rb_patricia_node_t * node);
+void rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node);
rb_patricia_tree_t *rb_new_patricia(int maxbits);
-void rb_clear_patricia(rb_patricia_tree_t * patricia, void (*func)(void *));
-void rb_destroy_patricia(rb_patricia_tree_t * patricia, void (*func)(void *));
-void rb_patricia_process(rb_patricia_tree_t * patricia, void (*func)(rb_prefix_t *, void *));
+void rb_clear_patricia(rb_patricia_tree_t *patricia, void (*func) (void *));
+void rb_destroy_patricia(rb_patricia_tree_t *patricia, void (*func) (void *));
+void rb_patricia_process(rb_patricia_tree_t *patricia, void (*func) (rb_prefix_t *, void *));
void rb_init_patricia(void);
#if 0
rb_prefix_t *ascii2prefix(int family, char *string);
#endif
-rb_patricia_node_t *make_and_lookup(rb_patricia_tree_t * tree, const char *string);
-rb_patricia_node_t *make_and_lookup_ip(rb_patricia_tree_t * tree, struct sockaddr *, int bitlen);
+rb_patricia_node_t *make_and_lookup(rb_patricia_tree_t *tree, const char *string);
+rb_patricia_node_t *make_and_lookup_ip(rb_patricia_tree_t *tree, struct sockaddr *, int bitlen);
#define RB_PATRICIA_MAXBITS 128
*/
#ifndef RB_LIB_H
-# error "Do not use rawbuf.h directly"
+# error "Do not use rawbuf.h directly"
#endif
#ifndef INCLUDED_RAWBUF_H__
int rb_rawbuf_get(rawbuf_head_t *, void *data, int len);
void rb_rawbuf_append(rawbuf_head_t *, void *data, int len);
int rb_rawbuf_flush(rawbuf_head_t *, rb_fde_t *F);
-int rb_rawbuf_length(rawbuf_head_t *rb);
+int rb_rawbuf_length(rawbuf_head_t * rb);
#endif
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_snprintf.h 24324 2007-08-31 22:05:45Z androsyn $
+ * $Id: rb_snprintf.h 26092 2008-09-19 15:13:52Z androsyn $
*/
#ifndef RB_LIB_H
-# error "Do not use snprintf.h directly"
+# error "Do not use snprintf.h directly"
#endif
#ifndef SPRINTF_IRC
* rb_sprintf - optimized sprintf
*/
#ifdef __GNUC__
-int rb_sprintf(char *str, const char *fmt, ...) __attribute((format(printf, 2, 3)));
-int rb_snprintf(char *str, const size_t size, const char *, ...) __attribute__ ((format(printf, 3, 4)));
-int rb_sprintf_append(char *str, const char *format, ...) __attribute((format(printf, 2, 3)));
-int rb_snprintf_append(char *str, size_t len, const char *format, ...) __attribute__ ((format(printf, 3, 4)));
+int
+rb_sprintf(char *str, const char *fmt, ...)
+__attribute((format(printf, 2, 3)));
+ int rb_snprintf(char *str, const size_t size, const char *, ...)
+ __attribute__ ((format(printf, 3, 4)));
+ int rb_sprintf_append(char *str, const char *format, ...) __attribute((format(printf, 2, 3)));
+ int rb_snprintf_append(char *str, size_t len, const char *format, ...)
+ __attribute__ ((format(printf, 3, 4)));
#else
int rb_sprintf(char *str, const char *format, ...);
int rb_snprintf(char *str, const size_t size, const char *, ...);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_tools.h 25042 2008-01-23 16:14:08Z androsyn $
+ * $Id: rb_tools.h 26170 2008-10-26 20:59:07Z androsyn $
*/
#ifndef RB_LIB_H
-# error "Do not use tools.h directly"
+# error "Do not use tools.h directly"
#endif
#ifndef __TOOLS_H__
size_t rb_strlcpy(char *dst, const char *src, size_t siz);
size_t rb_strlcat(char *dst, const char *src, size_t siz);
size_t rb_strnlen(const char *s, size_t count);
+char *rb_basename(const char *);
+char *rb_dirname(const char *);
int rb_string_to_array(char *string, char **parv, int maxpara);
};
rb_dlink_node *rb_make_rb_dlink_node(void);
-void rb_free_rb_dlink_node(rb_dlink_node * lp);
+void rb_free_rb_dlink_node(rb_dlink_node *lp);
void rb_init_rb_dlink_nodes(size_t dh_size);
/* This macros are basically swiped from the linux kernel
*/
static inline void
-rb_dlinkMoveNode(rb_dlink_node * m, rb_dlink_list * oldlist, rb_dlink_list * newlist)
+rb_dlinkMoveNode(rb_dlink_node *m, rb_dlink_list *oldlist, rb_dlink_list *newlist)
{
/* Assumption: If m->next == NULL, then list->tail == m
* and: If m->prev == NULL, then list->head == m
}
static inline void
-rb_dlinkAdd(void *data, rb_dlink_node * m, rb_dlink_list * list)
+rb_dlinkAdd(void *data, rb_dlink_node *m, rb_dlink_list *list)
{
assert(data != NULL);
assert(m != NULL);
}
static inline void
-rb_dlinkAddBefore(rb_dlink_node * b, void *data, rb_dlink_node * m, rb_dlink_list * list)
+rb_dlinkAddBefore(rb_dlink_node *b, void *data, rb_dlink_node *m, rb_dlink_list *list)
{
assert(b != NULL);
assert(data != NULL);
{
if(list->tail == m)
return;
-
+
/* From here assume that m->next != NULL as that can only
* be at the tail and assume that the node is on the list
*/
-
+
m->next->prev = m->prev;
if(m->prev != NULL)
}
static inline void
-rb_dlinkAddTail(void *data, rb_dlink_node * m, rb_dlink_list * list)
+rb_dlinkAddTail(void *data, rb_dlink_node *m, rb_dlink_list *list)
{
assert(m != NULL);
assert(list != NULL);
* often of all non-spontaneous functions. So it had better be
* efficient. */
static inline void
-rb_dlinkDelete(rb_dlink_node * m, rb_dlink_list * list)
+rb_dlinkDelete(rb_dlink_node *m, rb_dlink_list *list)
{
assert(m != NULL);
assert(list != NULL);
rb_dlink_node *ptr;
assert(list != NULL);
assert(data != NULL);
-
+
RB_DLINK_FOREACH(ptr, list->head)
{
if(ptr->data == data)
}
static inline void
-rb_dlinkMoveList(rb_dlink_list * from, rb_dlink_list * to)
+rb_dlinkMoveList(rb_dlink_list *from, rb_dlink_list *to)
{
assert(from != NULL);
assert(to != NULL);
# NOTE: Changing this file will not affect anything until you rerun configure.
#
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
-# 2007 Free Software Foundation, Inc.
+# 2007, 2008 Free Software Foundation, Inc.
# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
# This program is free software; you can redistribute it and/or modify
PROGRAM=ltmain.sh
PACKAGE=libtool
-VERSION="1.5.24 Debian 1.5.24-1"
-TIMESTAMP=" (1.1220.2.456 2007/06/24 02:25:32)"
+VERSION="1.5.26 Debian 1.5.26-4"
+TIMESTAMP=" (1.1220.2.493 2008/02/01 16:58:18)"
# Be Bourne compatible (taken from Autoconf:_AS_BOURNE_COMPATIBLE).
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
# These must not be set unconditionally because not all systems understand
# e.g. LANG=C (notably SCO).
# We save the old values to restore during execute mode.
-for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+lt_env=
+for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
do
eval "if test \"\${$lt_var+set}\" = set; then
save_$lt_var=\$$lt_var
+ lt_env=\"$lt_var=\$$lt_var \$lt_env\"
$lt_var=C
export $lt_var
fi"
done
+if test -n "$lt_env"; then
+ lt_env="env $lt_env"
+fi
+
# Make sure IFS has a sensible default
lt_nl='
'
echo "\
$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP
-Copyright (C) 2007 Free Software Foundation, Inc.
+Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
exit $?
*.for) xform=for ;;
*.java) xform=java ;;
*.obj) xform=obj ;;
+ *.sx) xform=sx ;;
esac
libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"`
$run $rm "$lobj" "$output_obj"
$show "$command"
- if $run eval "$command"; then :
+ if $run eval $lt_env "$command"; then :
else
test -n "$output_obj" && $run $rm $removelist
exit $EXIT_FAILURE
command="$command$suppress_output"
$run $rm "$obj" "$output_obj"
$show "$command"
- if $run eval "$command"; then :
+ if $run eval $lt_env "$command"; then :
else
$run $rm $removelist
exit $EXIT_FAILURE
thread_safe=no
vinfo=
vinfo_number=no
+ single_module="${wl}-single_module"
func_infer_tag $base_compile
continue
;;
+ -multi_module)
+ single_module="${wl}-multi_module"
+ continue
+ ;;
+
-module)
module=yes
continue
continue
fi
name=`$echo "X$deplib" | $Xsed -e 's/^-l//'`
- for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do
+ if test "$linkmode" = lib; then
+ searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
+ else
+ searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
+ fi
+ for searchdir in $searchdirs; do
for search_ext in .la $std_shrext .so .a; do
# Search the libtool library
lib="$searchdir/lib${name}${search_ext}"
# we do not want to link against static libs,
# but need to link against shared
eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
+ eval deplibdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
if test -n "$deplibrary_names" ; then
for tmp in $deplibrary_names ; do
depdepl=$tmp
done
- if test -f "$path/$depdepl" ; then
+ if test -f "$deplibdir/$depdepl" ; then
+ depdepl="$deplibdir/$depdepl"
+ elif test -f "$path/$depdepl" ; then
depdepl="$path/$depdepl"
+ else
+ # Can't find it, oh well...
+ depdepl=
fi
# do not add paths which are already there
case " $newlib_search_path " in
case $linkmode in
oldlib)
- if test -n "$deplibs"; then
- $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2
- fi
+ case " $deplibs" in
+ *\ -l* | *\ -L*)
+ $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 ;;
+ esac
if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
$echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2
;;
obj)
- if test -n "$deplibs"; then
- $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2
- fi
+ case " $deplibs" in
+ *\ -l* | *\ -L*)
+ $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 ;;
+ esac
if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
$echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2
fi
# Restore saved environment variables
- for lt_var in LANG LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+ for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
do
eval "if test \"\${save_$lt_var+set}\" = set; then
$lt_var=\$save_$lt_var; export $lt_var
-# $Id: Makefile.am 25689 2008-07-10 17:13:27Z androsyn $
+# $Id: Makefile.am 26046 2008-09-09 16:37:30Z androsyn $
AUTOMAKE_OPTIONS = foreign
INCLUDES = -I. -I../include @SSL_CFLAGS@ @GNUTLS_CFLAGS@
+BUILT_SOURCES = version.c
+
+version.c: version.c.SH ../CREDITS
+ $(SHELL) ./version.c.SH
+ $(CP) version.c version.c.last
+
+version.lo: version.c ../include/serno.h
+ $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
+
libratbox_la_SOURCES = \
unix.c \
win32.c \
kqueue.c \
rawbuf.c \
patricia.c \
- arc4random.c
+ arc4random.c \
+ version.c
-libratbox_la_LDFLAGS = -avoid-version -no-undefined -export-symbols export-syms.txt
+libratbox_la_LDFLAGS = @CRYPT_LIB@ @SSL_LIBS@ @GNUTLS_LIBS@ -avoid-version -no-undefined -export-symbols export-syms.txt
libratbox_la_LIBADD = @CRYPT_LIB@ @SSL_LIBS@ @GNUTLS_LIBS@
lib_LTLIBRARIES = libratbox.la
@SET_MAKE@
-# $Id: Makefile.am 25689 2008-07-10 17:13:27Z androsyn $
+# $Id: Makefile.am 26046 2008-09-09 16:37:30Z androsyn $
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
commio.lo openssl.lo gnutls.lo nossl.lo event.lo ratbox_lib.lo \
rb_memory.lo linebuf.lo snprintf.lo tools.lo helper.lo \
devpoll.lo epoll.lo poll.lo ports.lo sigio.lo select.lo \
- kqueue.lo rawbuf.lo patricia.lo arc4random.lo
+ kqueue.lo rawbuf.lo patricia.lo arc4random.lo version.lo
libratbox_la_OBJECTS = $(am_libratbox_la_OBJECTS)
libratbox_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-LD = @LD@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
-subdirs = @subdirs@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = foreign
INCLUDES = -I. -I../include @SSL_CFLAGS@ @GNUTLS_CFLAGS@
+BUILT_SOURCES = version.c
libratbox_la_SOURCES = \
unix.c \
win32.c \
kqueue.c \
rawbuf.c \
patricia.c \
- arc4random.c
+ arc4random.c \
+ version.c
-libratbox_la_LDFLAGS = -avoid-version -no-undefined -export-symbols export-syms.txt
+libratbox_la_LDFLAGS = @CRYPT_LIB@ @SSL_LIBS@ @GNUTLS_LIBS@ -avoid-version -no-undefined -export-symbols export-syms.txt
libratbox_la_LIBADD = @CRYPT_LIB@ @SSL_LIBS@ @GNUTLS_LIBS@
lib_LTLIBRARIES = libratbox.la
-all: all-am
+all: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snprintf.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tools.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unix.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/version.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/win32.Plo@am__quote@
.c.o:
fi; \
done
check-am: all-am
-check: check-am
+check: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) check-am
all-am: Makefile $(LTLIBRARIES)
installdirs:
for dir in "$(DESTDIR)$(libdir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
-install: install-am
+install: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
+ -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-libLTLIBRARIES
+
+version.c: version.c.SH ../CREDITS
+ $(SHELL) ./version.c.SH
+ $(CP) version.c version.c.last
+
+version.lo: version.c ../include/serno.h
+ $(LIBTOOL) --mode=compile $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
-/* $Id: arc4random.c 25705 2008-07-11 18:21:57Z androsyn $ */
+/* $Id: arc4random.c 26092 2008-09-19 15:13:52Z androsyn $ */
/* $$$: arc4random.c 2005/02/08 robert */
/* $NetBSD: arc4random.c,v 1.5.2.1 2004/03/26 22:52:50 jmc Exp $ */
/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
-struct arc4_stream {
+struct arc4_stream
+{
uint8_t i;
uint8_t j;
uint8_t s[256];
};
-static int rs_initialized;
+static int rs_initialized;
static struct arc4_stream rs;
static inline void arc4_init(struct arc4_stream *);
static inline void
arc4_init(struct arc4_stream *as)
{
- int n;
+ int n;
- for (n = 0; n < 256; n++)
+ for(n = 0; n < 256; n++)
as->s[n] = n;
as->i = 0;
as->j = 0;
static inline void
arc4_addrandom(struct arc4_stream *as, uint8_t *dat, int datlen)
{
- int n;
+ int n;
uint8_t si;
as->i--;
- for (n = 0; n < 256; n++) {
+ for(n = 0; n < 256; n++)
+ {
as->i = (as->i + 1);
si = as->s[as->i];
as->j = (as->j + si + dat[n % datlen]);
/* XXX this doesn't support egd sources or similiar */
pid = getpid();
- arc4_addrandom(as, (void *)&pid, sizeof(pid));
+ arc4_addrandom(as, (void *)&pid, sizeof(pid));
rb_gettimeofday(&tv, NULL);
arc4_addrandom(as, (void *)&tv.tv_sec, sizeof(&tv.tv_sec));
arc4_addrandom(as, (void *)&tv.tv_usec, sizeof(&tv.tv_usec));
rb_gettimeofday(&tv, NULL);
arc4_addrandom(as, (void *)&tv.tv_usec, sizeof(&tv.tv_usec));
-
+
#if defined(HAVE_GETRUSAGE) && RUSAGE_SELF
{
struct rusage buf;
getrusage(RUSAGE_SELF, &buf);
arc4_addrandom(as, (void *)&buf, sizeof(buf));
- memset(&buf, 0, sizeof(buf))
- }
-#endif
+ memset(&buf, 0, sizeof(buf))}
+#endif
-#if !defined(WIN32)
+#if !defined(_WIN32)
{
uint8_t rnd[128];
int fd;
fd = open("/dev/urandom", O_RDONLY);
- if (fd != -1)
+ if(fd != -1)
{
read(fd, rnd, sizeof(rnd));
close(fd);
arc4_addrandom(as, (void *)rnd, sizeof(rnd));
+ memset(&rnd, 0, sizeof(rnd));
}
+
}
#else
{
LARGE_INTEGER performanceCount;
- if (QueryPerformanceCounter (&performanceCount))
+ if(QueryPerformanceCounter(&performanceCount))
{
arc4_addrandom(as, (void *)&performanceCount, sizeof(performanceCount));
}
+ HMODULE lib = LoadLibrary("ADVAPI32.DLL");
+ if(lib)
+ {
+ uint8_t rnd[128];
+ BOOLEAN(APIENTRY * pfn) (void *, ULONG) =
+ (BOOLEAN(APIENTRY *) (void *, ULONG))GetProcAddress(lib,
+ "SystemFunction036");
+ if(pfn)
+ {
+ if(pfn(rnd, sizeof(rnd)) == TRUE)
+ arc4_addrandom(as, (void *)rnd, sizeof(rnd));
+ memset(&rnd, 0, sizeof(rnd));
+ }
+ }
}
#endif
* http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
* N = 256 in our case.
*/
- for (n = 0; n < 256 * 4; n++)
+ for(n = 0; n < 256 * 4; n++)
arc4_getbyte(as);
}
void
arc4random_stir(void)
{
- if (!rs_initialized) {
+ if(!rs_initialized)
+ {
arc4_init(&rs);
rs_initialized = 1;
}
void
arc4random_addrandom(uint8_t *dat, int datlen)
{
- if (!rs_initialized)
+ if(!rs_initialized)
arc4random_stir();
arc4_addrandom(&rs, dat, datlen);
}
uint32_t
arc4random(void)
{
- if (!rs_initialized)
+ if(!rs_initialized)
arc4random_stir();
return arc4_getword(&rs);
}
#endif
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: balloc.c 25861 2008-08-06 19:51:44Z androsyn $
+ * $Id: balloc.c 26100 2008-09-20 01:27:19Z androsyn $
*/
/*
#include <libratbox_config.h>
#include <ratbox_lib.h>
+#ifndef NOBALLOC
#ifdef HAVE_MMAP /* We've got mmap() that is good */
#include <sys/mman.h>
/* HP-UX sucks */
#endif
#endif
#endif
+#endif
static uintptr_t offset_pad;
};
#ifndef NOBALLOC
-static int newblock(rb_bh * bh);
+static int newblock(rb_bh *bh);
static void rb_bh_gc_event(void *unused);
#endif /* !NOBALLOC */
static rb_dlink_list *heap_lists;
rb_lib_log("rb_heap_blockheap failure: %s (%s:%d)", reason, file, line);
abort();
}
-
+
#ifndef NOBALLOC
/*
* static inline void free_block(void *ptr, size_t size)
#ifdef HAVE_MMAP
munmap(ptr, size);
#else
-#ifdef WIN32
+#ifdef _WIN32
HeapFree(block_heap, 0, ptr);
#else
free(ptr);
offset_pad += __alignof__(long long);
offset_pad &= ~(__alignof__(long long) - 1);
}
-#endif
-
+#endif
+
#ifndef NOBALLOC
-#ifdef WIN32
- block_heap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
+#ifdef _WIN32
+ block_heap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
#endif
rb_event_addish("rb_bh_gc_event", rb_bh_gc_event, NULL, 300);
#endif /* !NOBALLOC */
close(zero_fd);
#endif /* MAP_ANON */
if(ptr == MAP_FAILED)
- ptr = NULL;
+ ptr = NULL;
#else
-#ifdef WIN32
+#ifdef _WIN32
ptr = HeapAlloc(block_heap, 0, size);
-#else
+#else
ptr = malloc(size);
#endif
#endif
- return(ptr);
+ return (ptr);
}
/* ************************************************************************ */
static int
-newblock(rb_bh * bh)
+newblock(rb_bh *bh)
{
rb_heap_block *b;
unsigned long i;
}
offset = (uintptr_t)b->elems;
/* Setup our blocks now */
- for (i = 0; i < bh->elemsPerBlock; i++, offset += bh->elemSize)
+ for(i = 0; i < bh->elemsPerBlock; i++, offset += bh->elemSize)
{
*((void **)offset) = b;
node = (void *)(offset + offset_pad);
rb_dlinkAdd((void *)offset, node, &bh->free_list);
}
rb_dlinkAdd(b, &b->node, &bh->block_list);
- b->free_count = bh->elemsPerBlock;
+ b->free_count = bh->elemsPerBlock;
return (0);
}
#endif /* !NOBALLOC */
{
rb_bh_fail("Attempting to rb_bh_create idiotic sizes");
}
-
+
if(elemsize < sizeof(rb_dlink_node))
rb_bh_fail("Attempt to rb_bh_create smaller than sizeof(rb_dlink_node)");
-
+
/* Allocate our new rb_bh */
bh = rb_malloc(sizeof(rb_bh));
#ifndef NOBALLOC
/* ************************************************************************ */
void *
-rb_bh_alloc(rb_bh * bh)
+rb_bh_alloc(rb_bh *bh)
{
#ifndef NOBALLOC
rb_dlink_node *new_node;
- rb_heap_block *block;
+ rb_heap_block **block;
void *ptr;
-#endif
+#endif
lrb_assert(bh != NULL);
if(rb_unlikely(bh == NULL))
{
}
#ifdef NOBALLOC
- return(rb_malloc(bh->elemSize));
+ return (rb_malloc(bh->elemSize));
#else
if(bh->free_list.head == NULL)
{
}
new_node = bh->free_list.head;
- block = new_node->data;
- ptr = new_node->data + offset_pad;
+ block = (rb_heap_block **) new_node->data;
+ ptr = (void *)((uintptr_t)new_node->data + (uintptr_t)offset_pad);
rb_dlinkDelete(new_node, &bh->free_list);
+ (*block)->free_count--;
memset(ptr, 0, bh->elemSize - offset_pad);
- return(ptr);
+ return (ptr);
#endif
}
/* 0 if successful, 1 if element not contained within rb_bh. */
/* ************************************************************************ */
int
-rb_bh_free(rb_bh * bh, void *ptr)
+rb_bh_free(rb_bh *bh, void *ptr)
{
#ifndef NOBALLOC
rb_heap_block *block;
#ifdef NOBALLOC
rb_free(ptr);
#else
- data = (void *)(ptr - offset_pad);
- block = *(rb_heap_block **)data;
+ data = (void *)((uintptr_t)ptr - (uintptr_t)offset_pad);
+ block = *(rb_heap_block **) data;
/* XXX */
- if(rb_unlikely(!((uintptr_t)ptr >= (uintptr_t)block->elems && (uintptr_t)ptr < (uintptr_t)block->elems + (uintptr_t)block->alloc_size)))
+ if(rb_unlikely
+ (!((uintptr_t)ptr >= (uintptr_t)block->elems
+ && (uintptr_t)ptr < (uintptr_t)block->elems + (uintptr_t)block->alloc_size)))
{
rb_bh_fail("rb_bh_free() bogus pointer");
}
block->free_count++;
+
rb_dlinkAdd(data, (rb_dlink_node *)ptr, &bh->free_list);
#endif /* !NOBALLOC */
return (0);
/* 0 if successful, 1 if bh == NULL */
/* ************************************************************************ */
int
-rb_bh_destroy(rb_bh * bh)
+rb_bh_destroy(rb_bh *bh)
{
#ifndef NOBALLOC
rb_dlink_node *ptr, *next;
rb_free(b);
}
#endif /* !NOBALLOC */
-
+
rb_dlinkDelete(&bh->hlist, heap_lists);
rb_free(bh->desc);
rb_free(bh);
}
void
-rb_bh_usage(rb_bh * bh, size_t * bused, size_t * bfree, size_t * bmemusage, const char **desc)
+rb_bh_usage(rb_bh *bh, size_t *bused, size_t *bfree, size_t *bmemusage, const char **desc)
{
+#ifndef NOBALLOC
size_t used, freem, memusage;
if(bh == NULL)
*bmemusage = memusage;
if(desc != NULL)
*desc = bh->desc;
+#else
+ static char *noballoc = "no blockheap";
+ *bused = 0;
+ *bfree = 0;
+ *bmemusage = 0;
+ *desc = noballoc;
+#endif
}
-void rb_bh_usage_all(rb_bh_usage_cb *cb, void *data)
+void
+rb_bh_usage_all(rb_bh_usage_cb *cb, void *data)
{
rb_dlink_node *ptr;
rb_bh *bh;
RB_DLINK_FOREACH(ptr, heap_lists->head)
{
- bh = (rb_bh *)ptr->data;
+ bh = (rb_bh *)ptr->data;
freem = rb_dlink_list_length(&bh->free_list);
used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem;
memusage = used * bh->elemSize;
heapalloc = (freem + used) * bh->elemSize;
if(bh->desc != NULL)
desc = bh->desc;
- cb(used, freem, memusage, heapalloc, desc, data);
+ cb(used, freem, memusage, heapalloc, desc, data);
}
return;
}
rb_dlink_node *ptr;
size_t total_memory = 0, used_memory = 0, used, freem;
rb_bh *bh;
-
+
RB_DLINK_FOREACH(ptr, heap_lists->head)
{
bh = (rb_bh *)ptr->data;
used_memory += used * bh->elemSize;
total_memory += (freem + used) * bh->elemSize;
}
-
+
if(total_alloc != NULL)
*total_alloc = total_memory;
if(total_used != NULL)
#ifndef NOBALLOC
int
-rb_bh_gc(rb_bh * bh)
+rb_bh_gc(rb_bh *bh)
{
rb_heap_block *b;
rb_dlink_node *ptr, *next;
unsigned long i;
uintptr_t offset;
-
+
if(bh == NULL)
{
/* somebody is smoking some craq..(probably lee, but don't tell him that) */
return (1);
}
- if((rb_dlink_list_length(&bh->free_list) < bh->elemsPerBlock) || rb_dlink_list_length(&bh->block_list) == 1)
+ if((rb_dlink_list_length(&bh->free_list) < bh->elemsPerBlock)
+ || rb_dlink_list_length(&bh->block_list) == 1)
{
/* There couldn't possibly be an entire free block. Return. */
return (0);
b = ptr->data;
if(rb_dlink_list_length(&bh->block_list) == 1)
return (0);
-
+
if(b->free_count == bh->elemsPerBlock)
{
/* i'm seriously going to hell for this.. */
offset = (uintptr_t)b->elems;
- for (i = 0; i < bh->elemsPerBlock; i++, offset += (uintptr_t)bh->elemSize)
+ for(i = 0; i < bh->elemsPerBlock; i++, offset += (uintptr_t)bh->elemSize)
{
- rb_dlinkDelete(((rb_dlink_node *)offset), &bh->free_list);
+ rb_dlinkDelete((rb_dlink_node *)(offset + offset_pad),
+ &bh->free_list);
}
rb_dlinkDelete(&b->node, &bh->block_list);
free_block(b->elems, b->alloc_size);
rb_free(b);
}
-
+
}
return (0);
}
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: commio.c 25795 2008-07-29 15:26:55Z androsyn $
+ * $Id: commio.c 26096 2008-09-20 01:05:42Z androsyn $
*/
#include <libratbox_config.h>
#include <ratbox_lib.h>
/* Highest FD and number of open FDs .. */
static int number_fd = 0;
-static int rb_maxconnections = 0;
+int rb_maxconnections = 0;
static PF rb_connect_timeout;
static PF rb_connect_tryconnect;
#ifndef HAVE_SOCKETPAIR
static int rb_inet_socketpair(int d, int type, int protocol, int sv[2]);
+static int rb_inet_socketpair_udp(rb_fde_t **newF1, rb_fde_t **newF2);
#endif
static inline rb_fde_t *
/* look up to see if we have it already */
if(F != NULL)
- return F;
-
+ return F;
+
F = rb_bh_alloc(fd_heap);
F->fd = fd;
rb_dlinkAdd(F, &F->node, &rb_fd_table[rb_hash_fd(fd)]);
- return(F);
+ return (F);
}
static inline void
{
if(F == NULL || !IsFDOpen(F))
return;
-
+
rb_dlinkMoveNode(&F->node, &rb_fd_table[rb_hash_fd(F->fd)], &closed_list);
}
-static void
+static void
free_fds(void)
{
rb_fde_t *F;
static void
rb_close_all(void)
{
+#ifndef _WIN32
int i;
-#ifndef NDEBUG
- int fd;
-#endif
/* XXX someone tell me why we care about 4 fd's ? */
/* XXX btw, fd 3 is used for profiler ! */
- for (i = 4; i < rb_maxconnections; ++i)
+ for(i = 3; i < rb_maxconnections; ++i)
{
close(i);
}
-
- /* XXX should his hack be done in all cases? */
-#ifndef NDEBUG
- /* fugly hack to reserve fd == 2 */
- (void) close(2);
- fd = open("stderr.log", O_WRONLY | O_CREAT | O_APPEND, 0644);
- if(fd >= 0)
- {
- dup2(fd, 2);
- close(fd);
- }
#endif
}
errtmp = errno;
#ifdef SO_ERROR
- if(F != NULL && !getsockopt(rb_get_fd(F), SOL_SOCKET, SO_ERROR, (char *) &err, (rb_socklen_t *) & len))
+ if(F != NULL
+ && !getsockopt(rb_get_fd(F), SOL_SOCKET, SO_ERROR, (char *)&err, (rb_socklen_t *) & len))
{
if(err)
errtmp = err;
int
rb_getmaxconnect(void)
{
- return(rb_maxconnections);
+ return (rb_maxconnections);
}
/*
if(F == NULL)
return 0;
if(setsockopt
- (F->fd, SOL_SOCKET, SO_RCVBUF, (char *) &size, sizeof(size))
- || setsockopt(F->fd, SOL_SOCKET, SO_SNDBUF, (char *) &size, sizeof(size)))
+ (F->fd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size))
+ || setsockopt(F->fd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size)))
return 0;
return 1;
}
if(F == NULL)
return 0;
fd = F->fd;
-
+
if((res = rb_setup_fd(F)))
return res;
#ifdef O_NONBLOCK
lrb_assert(IsFDOpen(F));
td = F->timeout;
- if(callback == NULL) /* user wants to remove */
+ if(callback == NULL) /* user wants to remove */
{
if(td == NULL)
return;
rb_dlinkDelete(&td->node, &timeout_list);
rb_free(td);
F->timeout = NULL;
- if(rb_dlink_list_length(&timeout_list) == 0)
+ if(rb_dlink_list_length(&timeout_list) == 0)
{
rb_event_delete(rb_timeout_ev);
rb_timeout_ev = NULL;
}
if(F->timeout == NULL)
- td = F->timeout = rb_malloc(sizeof(struct timeout_data));
-
+ td = F->timeout = rb_malloc(sizeof(struct timeout_data));
+
td->F = F;
td->timeout = rb_current_time() + timeout;
td->timeout_handler = callback;
rb_dlinkAdd(td, &td->node, &timeout_list);
if(rb_timeout_ev == NULL)
{
- rb_timeout_ev = rb_event_add("rb_checktimeouts", rb_checktimeouts, NULL, 5);
+ rb_timeout_ev = rb_event_add("rb_checktimeouts", rb_checktimeouts, NULL, 5);
}
}
F->timeout = NULL;
rb_free(td);
hdl(F, data);
- }
+ }
}
}
if(new_F == NULL)
{
- rb_lib_log("rb_accept: new_F == NULL on incoming connection. Closing new_fd == %d\n", new_fd);
+ rb_lib_log
+ ("rb_accept: new_F == NULL on incoming connection. Closing new_fd == %d\n",
+ new_fd);
close(new_fd);
continue;
}
#ifdef RB_IPV6
mangle_mapped_sockaddr((struct sockaddr *)&st);
#endif
-
+
if(F->accept->precb != NULL)
{
- if(!F->accept->precb(new_F, (struct sockaddr *)&st, addrlen, F->accept->data)) /* pre-callback decided to drop it */
+ if(!F->accept->precb(new_F, (struct sockaddr *)&st, addrlen, F->accept->data)) /* pre-callback decided to drop it */
continue;
}
#ifdef HAVE_SSL
if(F->type & RB_FD_SSL)
{
rb_ssl_accept_setup(F, new_F, (struct sockaddr *)&st, addrlen);
- }
+ }
else
-#endif /* HAVE_SSL */
+#endif /* HAVE_SSL */
{
- F->accept->callback(new_F, RB_OK, (struct sockaddr *)&st, addrlen, F->accept->data);
+ F->accept->callback(new_F, RB_OK, (struct sockaddr *)&st, addrlen,
+ F->accept->data);
}
}
/* try to accept a TCP connection */
void
-rb_accept_tcp(rb_fde_t *F, ACPRE *precb, ACCB *callback, void *data)
+rb_accept_tcp(rb_fde_t *F, ACPRE * precb, ACCB * callback, void *data)
{
if(F == NULL)
return;
*/
void
rb_connect_tcp(rb_fde_t *F, struct sockaddr *dest,
- struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout)
+ struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout)
{
if(F == NULL)
return;
-
+
lrb_assert(callback);
F->connect = rb_malloc(sizeof(struct conndata));
F->connect->callback = callback;
{
CNCB *hdl;
void *data;
- int errtmp = errno; /* save errno as rb_settimeout clobbers it sometimes */
+ int errtmp = errno; /* save errno as rb_settimeout clobbers it sometimes */
/* This check is gross..but probably necessary */
if(F == NULL || F->connect == NULL || F->connect->callback == NULL)
/* Clear the timeout handler */
rb_settimeout(F, 0, NULL, NULL);
- errno = errtmp;
+ errno = errtmp;
/* Call the handler */
hdl(F, status, data);
}
return;
/* Try the connect() */
retval = connect(F->fd,
- (struct sockaddr *) &F->connect->hostaddr, GET_SS_LEN(&F->connect->hostaddr));
+ (struct sockaddr *)&F->connect->hostaddr,
+ GET_SS_LEN(&F->connect->hostaddr));
/* Error? */
if(retval < 0)
{
rb_connect_callback(F, RB_OK);
else if(rb_ignore_errno(errno))
/* Ignore error? Reschedule */
- rb_setselect(F, RB_SELECT_CONNECT,
- rb_connect_tryconnect, NULL);
+ rb_setselect(F, RB_SELECT_CONNECT, rb_connect_tryconnect, NULL);
else
/* Error? Fail with RB_ERR_CONNECT */
rb_connect_callback(F, RB_ERR_CONNECT);
return -1;
}
-#ifndef WIN32
+#ifdef HAVE_SOCKETPAIR
if(socketpair(family, sock_type, proto, nfd))
#else
- if(rb_inet_socketpair(AF_INET, SOCK_STREAM, proto, nfd))
+ if(sock_type == SOCK_DGRAM)
+ {
+ return rb_inet_socketpair_udp(F1, F2);
+ }
+
+ if(rb_inet_socketpair(AF_INET, sock_type, proto, nfd))
#endif
return -1;
int
rb_pipe(rb_fde_t **F1, rb_fde_t **F2, const char *desc)
{
-#ifndef WIN32
+#ifndef _WIN32
int fd[2];
if(number_fd >= rb_maxconnections)
{
/* Its not a pipe..but its selectable. I'll take dirty hacks
* for $500 Alex.
*/
- return rb_socketpair(AF_INET, SOCK_STREAM, 0, F1, F2, desc);
+ return rb_socketpair(AF_INET, SOCK_STREAM, 0, F1, F2, desc);
#endif
}
if(setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &off, sizeof(off)) == -1)
{
rb_lib_log("rb_socket: Could not set IPV6_V6ONLY option to 1 on FD %d: %s",
- fd, strerror(errno));
+ fd, strerror(errno));
close(fd);
return NULL;
}
F = rb_open(fd, RB_FD_SOCKET, note);
if(F == NULL)
{
- rb_lib_log("rb_socket: rb_open returns NULL on FD %d: %s, closing fd", fd, strerror(errno));
+ rb_lib_log("rb_socket: rb_open returns NULL on FD %d: %s, closing fd", fd,
+ strerror(errno));
close(fd);
return NULL;
}
static void
mangle_mapped_sockaddr(struct sockaddr *in)
{
- struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) in;
+ struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)in;
if(in->sa_family == AF_INET)
return;
memset(&in4, 0, sizeof(struct sockaddr_in));
in4.sin_family = AF_INET;
in4.sin_port = in6->sin6_port;
- in4.sin_addr.s_addr = ((uint32_t *) & in6->sin6_addr)[3];
+ in4.sin_addr.s_addr = ((uint32_t *)&in6->sin6_addr)[3];
memcpy(in, &in4, sizeof(struct sockaddr_in));
}
return;
int
rb_listen(rb_fde_t *F, int backlog)
{
- F->type = RB_FD_SOCKET|RB_FD_LISTEN;
+ F->type = RB_FD_SOCKET | RB_FD_LISTEN;
/* Currently just a simple wrapper for the sake of being complete */
return listen(F->fd, backlog);
}
rb_fdlist_init(int closeall, int maxfds, size_t heapsize)
{
static int initialized = 0;
-#ifdef WIN32
+#ifdef _WIN32
WSADATA wsaData;
int err;
int vers = MAKEWORD(2, 0);
-
+
err = WSAStartup(vers, &wsaData);
if(err != 0)
{
fdesc = F->desc;
else
fdesc = "NULL";
- rb_lib_log("Trying to rb_open an already open FD: %d desc: %d", fd, fdesc);
+ rb_lib_log("Trying to rb_open an already open FD: %d desc: %s", fd, fdesc);
return NULL;
}
F->fd = fd;
rb_close(rb_fde_t *F)
{
int type, fd;
-
+
if(F == NULL)
return;
fd = F->fd;
- type = F->type;
+ type = F->type;
lrb_assert(IsFDOpen(F));
lrb_assert(!(type & RB_FD_FILE));
number_fd--;
-#ifdef WIN32
- if(type & (RB_FD_SOCKET|RB_FD_PIPE))
+#ifdef _WIN32
+ if(type & (RB_FD_SOCKET | RB_FD_PIPE))
{
closesocket(fd);
return;
- } else
+ }
+ else
#endif
- close(fd);
+ close(fd);
}
return F->type;
}
-int
+int
rb_fd_ssl(rb_fde_t *F)
{
if(F == NULL)
return 0;
}
-int
+int
rb_get_fd(rb_fde_t *F)
{
if(F == NULL)
return -1;
- return(F->fd);
+ return (F->fd);
}
rb_fde_t *
ssize_t ret;
if(F == NULL)
return 0;
-
+
/* This needs to be *before* RB_FD_SOCKET otherwise you'll process
* an SSL socket as a regular socket
*/
if(F->type & RB_FD_SSL)
{
return rb_ssl_read(F, buf, count);
- }
+ }
#endif
if(F->type & RB_FD_SOCKET)
{
if(F->type & RB_FD_SSL)
{
return rb_ssl_write(F, buf, count);
- }
+ }
#endif
if(F->type & RB_FD_SOCKET)
{
ret = send(F->fd, buf, count, MSG_NOSIGNAL);
- if(ret < 0) {
+ if(ret < 0)
+ {
rb_get_errno();
}
return ret;
{
ssize_t count = 0;
- while (vpcount-- > 0)
+ while(vpcount-- > 0)
{
ssize_t written = rb_write(F, vp->iov_base, vp->iov_len);
- if (written <= 0)
+ if(written <= 0)
{
if(count > 0)
return count;
#if defined(WIN32) || !defined(HAVE_WRITEV)
ssize_t
-rb_writev(rb_fde_t *F, struct rb_iovec *vecount, int count)
+rb_writev(rb_fde_t *F, struct rb_iovec * vecount, int count)
{
return rb_fake_writev(F, vecount, count);
}
#else
ssize_t
-rb_writev(rb_fde_t *F, struct rb_iovec *vector, int count)
+rb_writev(rb_fde_t *F, struct rb_iovec * vector, int count)
{
- if(F == NULL) {
+ if(F == NULL)
+ {
errno = EBADF;
return -1;
}
#ifdef HAVE_SSL
if(F->type & RB_FD_SSL)
{
- return rb_fake_writev(F, vector, count);
+ return rb_fake_writev(F, vector, count);
}
#endif /* HAVE_SSL */
#ifdef HAVE_SENDMSG
msg.msg_iov = (struct iovec *)vector;
msg.msg_iovlen = count;
return sendmsg(F->fd, &msg, MSG_NOSIGNAL);
- }
+ }
#endif /* HAVE_SENDMSG */
return writev(F->fd, (struct iovec *)vector, count);
}
-#endif
+#endif
/*
{
static char buf[16];
char *bufptr = buf;
- const unsigned char *a = (const unsigned char *) in;
+ const unsigned char *a = (const unsigned char *)in;
const char *n;
n = IpQuadTab[*a++];
- while (*n)
+ while(*n)
*bufptr++ = *n++;
*bufptr++ = '.';
n = IpQuadTab[*a++];
- while (*n)
+ while(*n)
*bufptr++ = *n++;
*bufptr++ = '.';
n = IpQuadTab[*a++];
- while (*n)
+ while(*n)
*bufptr++ = *n++;
*bufptr++ = '.';
n = IpQuadTab[*a];
- while (*n)
+ while(*n)
*bufptr++ = *n++;
*bufptr = '\0';
return buf;
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
-static const char *inet_ntop4(const unsigned char * src, char *dst, unsigned int size);
+static const char *inet_ntop4(const unsigned char *src, char *dst, unsigned int size);
#ifdef RB_IPV6
-static const char *inet_ntop6(const unsigned char * src, char *dst, unsigned int size);
+static const char *inet_ntop6(const unsigned char *src, char *dst, unsigned int size);
#endif
/* const char *
{
if(size < 16)
return NULL;
- return strcpy(dst, inetntoa((const char *) src));
+ return strcpy(dst, inetntoa((const char *)src));
}
/* const char *
* Find the longest run of 0x00's in src[] for :: shorthanding.
*/
memset(words, '\0', sizeof words);
- for (i = 0; i < IN6ADDRSZ; i += 2)
+ for(i = 0; i < IN6ADDRSZ; i += 2)
words[i / 2] = (src[i] << 8) | src[i + 1];
best.base = -1;
best.len = 0;
cur.base = -1;
cur.len = 0;
- for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
+ for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
{
if(words[i] == 0)
{
* Format the result.
*/
tp = tmp;
- for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
+ for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
{
/* Are we inside the best run of 0x00's? */
if(best.base != -1 && i >= best.base && i < (best.base + best.len))
* Check for overflow, copy, and we're done.
*/
- if((unsigned int) (tp - tmp) > size)
+ if((unsigned int)(tp - tmp) > size)
{
return (NULL);
}
int
rb_inet_pton_sock(const char *src, struct sockaddr *dst)
{
- if(rb_inet_pton(AF_INET, src, &((struct sockaddr_in *) dst)->sin_addr))
+ if(rb_inet_pton(AF_INET, src, &((struct sockaddr_in *)dst)->sin_addr))
{
- ((struct sockaddr_in *) dst)->sin_port = 0;
- ((struct sockaddr_in *) dst)->sin_family = AF_INET;
+ ((struct sockaddr_in *)dst)->sin_port = 0;
+ ((struct sockaddr_in *)dst)->sin_family = AF_INET;
SET_SS_LEN(dst, sizeof(struct sockaddr_in));
return 1;
}
#ifdef RB_IPV6
- else if(rb_inet_pton(AF_INET6, src, &((struct sockaddr_in6 *) dst)->sin6_addr))
+ else if(rb_inet_pton(AF_INET6, src, &((struct sockaddr_in6 *)dst)->sin6_addr))
{
- ((struct sockaddr_in6 *) dst)->sin6_port = 0;
- ((struct sockaddr_in6 *) dst)->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *)dst)->sin6_port = 0;
+ ((struct sockaddr_in6 *)dst)->sin6_family = AF_INET6;
SET_SS_LEN(dst, sizeof(struct sockaddr_in6));
return 1;
}
switch (src->sa_family)
{
case AF_INET:
- return (rb_inet_ntop(AF_INET, &((struct sockaddr_in *) src)->sin_addr, dst, size));
+ return (rb_inet_ntop(AF_INET, &((struct sockaddr_in *)src)->sin_addr, dst, size));
break;
#ifdef RB_IPV6
case AF_INET6:
- return (rb_inet_ntop(AF_INET6, &((struct sockaddr_in6 *) src)->sin6_addr, dst, size));
+ return (rb_inet_ntop
+ (AF_INET6, &((struct sockaddr_in6 *)src)->sin6_addr, dst, size));
break;
#endif
default:
return (inet_ntop4(src, dst, size));
#ifdef RB_IPV6
case AF_INET6:
- if(IN6_IS_ADDR_V4MAPPED((const struct in6_addr *) src) ||
- IN6_IS_ADDR_V4COMPAT((const struct in6_addr *) src))
+ if(IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)src) ||
+ IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)src))
return (inet_ntop4
- ((const unsigned char *)
- &((const struct in6_addr *) src)->s6_addr[12], dst, size));
+ ((const unsigned char *)&((const struct in6_addr *)src)->
+ s6_addr[12], dst, size));
else
return (inet_ntop6(src, dst, size));
saw_digit = 0;
octets = 0;
*(tp = tmp) = 0;
- while ((ch = *src++) != '\0')
+ while((ch = *src++) != '\0')
{
if(ch >= '0' && ch <= '9')
curtok = src;
saw_xdigit = 0;
val = 0;
- while ((ch = tolower(*src++)) != '\0')
+ while((ch = tolower(*src++)) != '\0')
{
const char *pch;
}
if(tp + INT16SZ > endp)
return (0);
- *tp++ = (unsigned char) (val >> 8) & 0xff;
- *tp++ = (unsigned char) val & 0xff;
+ *tp++ = (unsigned char)(val >> 8) & 0xff;
+ *tp++ = (unsigned char)val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
{
if(tp + INT16SZ > endp)
return (0);
- *tp++ = (unsigned char) (val >> 8) & 0xff;
- *tp++ = (unsigned char) val & 0xff;
+ *tp++ = (unsigned char)(val >> 8) & 0xff;
+ *tp++ = (unsigned char)val & 0xff;
}
if(colonp != NULL)
{
if(tp == endp)
return (0);
- for (i = 1; i <= n; i++)
+ for(i = 1; i <= n; i++)
{
endp[-i] = colonp[n - i];
colonp[n - i] = 0;
#ifndef HAVE_SOCKETPAIR
+
+/* mostly based on perl's emulation of socketpair udp */
+static int
+rb_inet_socketpair_udp(rb_fde_t **newF1, rb_fde_t **newF2)
+{
+ struct sockaddr_in addr[2];
+ rb_socklen_t size = sizeof(struct sockaddr_in);
+ rb_fde_t *F[2];
+ unsigned int fd[2];
+ int i, got;
+ unsigned short port;
+
+ memset(&addr, 0, sizeof(addr));
+
+ for(i = 0; i < 2; i++)
+ {
+ F[i] = rb_socket(AF_INET, SOCK_DGRAM, 0, "udp socketpair");
+ if(F[i] == NULL)
+ goto failed;
+ addr[i].sin_family = AF_INET;
+ addr[i].sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ addr[i].sin_port = 0;
+ if(bind(rb_get_fd(F[i]), (struct sockaddr *)&addr[i], sizeof(struct sockaddr_in)))
+ goto failed;
+ fd[i] = rb_get_fd(F[i]);
+ }
+
+ for(i = 0; i < 2; i++)
+ {
+ if(getsockname(fd[i], (struct sockaddr *)&addr[i], &size))
+ goto failed;
+ if(size != sizeof(struct sockaddr_in))
+ goto failed;
+ if(connect(fd[!i], (struct sockaddr *)&addr[i], sizeof(struct sockaddr_in)) == -1)
+ goto failed;
+ }
+
+ for(i = 0; i < 2; i++)
+ {
+ port = addr[i].sin_port;
+ got = rb_write(F[i], &port, sizeof(port));
+ if(got != sizeof(port))
+ {
+ if(got == -1)
+ goto failed;
+ goto abort_failed;
+ }
+ }
+
+
+ struct timeval wait = { 0, 100000 };
+
+ int max = fd[1] > fd[0] ? fd[1] : fd[0];
+ fd_set rset;
+ FD_ZERO(&rset);
+ FD_SET(fd[0], &rset);
+ FD_SET(fd[1], &rset);
+ got = select(max + 1, &rset, NULL, NULL, &wait);
+ if(got != 2 || !FD_ISSET(fd[0], &rset) || !FD_ISSET(fd[1], &rset))
+ {
+ if(got == -1)
+ goto failed;
+ goto abort_failed;
+ }
+
+ struct sockaddr_in readfrom;
+ unsigned short buf[2];
+ for(i = 0; i < 2; i++)
+ {
+#ifdef MSG_DONTWAIT
+ int flag = MSG_DONTWAIT
+#else
+ int flag = 0;
+#endif
+ got = recvfrom(rb_get_fd(F[i]), (char *)&buf, sizeof(buf), flag,
+ (struct sockaddr *)&readfrom, &size);
+ if(got == -1)
+ goto failed;
+ if(got != sizeof(port)
+ || size != sizeof(struct sockaddr_in)
+ || buf[0] != (unsigned short)addr[!i].sin_port
+ || readfrom.sin_family != addr[!i].sin_family
+ || readfrom.sin_addr.s_addr != addr[!i].sin_addr.s_addr
+ || readfrom.sin_port != addr[!i].sin_port)
+ goto abort_failed;
+ }
+
+ *newF1 = F[0];
+ *newF2 = F[1];
+ return 0;
+
+#ifdef _WIN32
+#define ECONNABORTED WSAECONNABORTED
+#endif
+
+ abort_failed:
+ rb_get_errno();
+ errno = ECONNABORTED;
+ failed:
+ if(errno != ECONNABORTED)
+ rb_get_errno();
+ int o_errno = errno;
+ if(F[0] != NULL)
+ rb_close(F[0]);
+ if(F[1] != NULL)
+ rb_close(F[1]);
+ errno = o_errno;
+ return -1;
+}
+
+
int
rb_inet_socketpair(int family, int type, int protocol, int fd[2])
{
int acceptor = -1;
struct sockaddr_in listen_addr;
struct sockaddr_in connect_addr;
- size_t size;
+ rb_socklen_t size;
if(protocol || family != AF_INET)
{
listen_addr.sin_family = AF_INET;
listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
listen_addr.sin_port = 0; /* kernel choses port. */
- if(bind(listener, (struct sockaddr *) &listen_addr, sizeof(listen_addr)) == -1)
+ if(bind(listener, (struct sockaddr *)&listen_addr, sizeof(listen_addr)) == -1)
goto tidy_up_and_fail;
if(listen(listener, 1) == -1)
goto tidy_up_and_fail;
goto tidy_up_and_fail;
/* We want to find out the port number to connect to. */
size = sizeof(connect_addr);
- if(getsockname(listener, (struct sockaddr *) &connect_addr, &size) == -1)
+ if(getsockname(listener, (struct sockaddr *)&connect_addr, &size) == -1)
goto tidy_up_and_fail;
if(size != sizeof(connect_addr))
goto abort_tidy_up_and_fail;
- if(connect(connector, (struct sockaddr *) &connect_addr, sizeof(connect_addr)) == -1)
+ if(connect(connector, (struct sockaddr *)&connect_addr, sizeof(connect_addr)) == -1)
goto tidy_up_and_fail;
size = sizeof(listen_addr);
- acceptor = accept(listener, (struct sockaddr *) &listen_addr, &size);
+ acceptor = accept(listener, (struct sockaddr *)&listen_addr, &size);
if(acceptor == -1)
goto tidy_up_and_fail;
if(size != sizeof(listen_addr))
close(listener);
/* Now check we are talking to ourself by matching port and host on the
two sockets. */
- if(getsockname(connector, (struct sockaddr *) &connect_addr, &size) == -1)
+ if(getsockname(connector, (struct sockaddr *)&connect_addr, &size) == -1)
goto tidy_up_and_fail;
if(size != sizeof(connect_addr)
|| listen_addr.sin_family != connect_addr.sin_family
rb_strlcpy(iotype, "kqueue", sizeof(iotype));
return 0;
}
- return -1;
+ return -1;
}
static int
{
setselect_handler = rb_setselect_ports;
select_handler = rb_select_ports;
- setup_fd_handler = rb_setup_fd_ports;
+ setup_fd_handler = rb_setup_fd_ports;
io_sched_event = NULL;
io_unsched_event = NULL;
io_init_event = NULL;
{
setselect_handler = rb_setselect_devpoll;
select_handler = rb_select_devpoll;
- setup_fd_handler = rb_setup_fd_devpoll;
+ setup_fd_handler = rb_setup_fd_devpoll;
io_sched_event = NULL;
io_unsched_event = NULL;
io_init_event = NULL;
{
setselect_handler = rb_setselect_sigio;
select_handler = rb_select_sigio;
- setup_fd_handler = rb_setup_fd_sigio;
+ setup_fd_handler = rb_setup_fd_sigio;
io_sched_event = rb_sigio_sched_event;
- io_unsched_event = rb_sigio_unsched_event;
- io_supports_event = rb_sigio_supports_event;
- io_init_event = rb_sigio_init_event;
-
+ io_unsched_event = rb_sigio_unsched_event;
+ io_supports_event = rb_sigio_supports_event;
+ io_init_event = rb_sigio_init_event;
+
rb_strlcpy(iotype, "sigio", sizeof(iotype));
return 0;
}
return -1;
}
-static int
+static int
try_poll(void)
{
if(!rb_init_netio_poll())
{
setselect_handler = rb_setselect_poll;
select_handler = rb_select_poll;
- setup_fd_handler = rb_setup_fd_poll;
+ setup_fd_handler = rb_setup_fd_poll;
io_sched_event = NULL;
io_unsched_event = NULL;
io_init_event = NULL;
{
setselect_handler = rb_setselect_win32;
select_handler = rb_select_win32;
- setup_fd_handler = rb_setup_fd_win32;
+ setup_fd_handler = rb_setup_fd_win32;
io_sched_event = NULL;
io_unsched_event = NULL;
io_init_event = NULL;
static int
try_select(void)
-{
+{
if(!rb_init_netio_select())
{
setselect_handler = rb_setselect_select;
select_handler = rb_select_select;
- setup_fd_handler = rb_setup_fd_select;
+ setup_fd_handler = rb_setup_fd_select;
io_sched_event = NULL;
io_unsched_event = NULL;
io_init_event = NULL;
int
rb_io_sched_event(struct ev_entry *ev, int when)
{
- if(ev == NULL || io_supports_event == NULL || io_sched_event == NULL || !io_supports_event())
+ if(ev == NULL || io_supports_event == NULL || io_sched_event == NULL
+ || !io_supports_event())
return 0;
return io_sched_event(ev, when);
}
void
rb_io_unsched_event(struct ev_entry *ev)
{
- if(ev == NULL || io_supports_event == NULL || io_unsched_event == NULL || !io_supports_event())
+ if(ev == NULL || io_supports_event == NULL || io_unsched_event == NULL
+ || !io_supports_event())
return;
- io_unsched_event(ev);
+ io_unsched_event(ev);
}
+
int
rb_io_supports_event(void)
{
char *ioenv = getenv("LIBRB_USE_IOTYPE");
rb_fd_table = rb_malloc(RB_FD_HASH_SIZE * sizeof(rb_dlink_list));
rb_init_ssl();
-
+
if(ioenv != NULL)
{
if(!strcmp("epoll", ioenv))
{
if(!try_epoll())
return;
- } else
- if(!strcmp("kqueue", ioenv))
+ }
+ else if(!strcmp("kqueue", ioenv))
{
if(!try_kqueue())
return;
- } else
- if(!strcmp("ports", ioenv))
+ }
+ else if(!strcmp("ports", ioenv))
{
if(!try_ports())
return;
- } else
- if(!strcmp("poll", ioenv))
+ }
+ else if(!strcmp("poll", ioenv))
{
if(!try_poll())
return;
- } else
- if(!strcmp("devpoll", ioenv))
+ }
+ else if(!strcmp("devpoll", ioenv))
{
if(!try_devpoll())
return;
- } else
- if(!strcmp("sigio", ioenv))
+ }
+ else if(!strcmp("sigio", ioenv))
{
if(!try_sigio())
return;
- } else
- if(!strcmp("win32", ioenv))
+ }
+ else if(!strcmp("select", ioenv))
{
- if(!try_win32())
+ if(!try_select())
return;
}
- if(!strcmp("select", ioenv))
+ if(!strcmp("win32", ioenv))
{
- if(!try_select())
+ if(!try_win32())
return;
}
-
+
}
if(!try_kqueue())
abort();
}
-void
+void
rb_setselect(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
setselect_handler(F, type, handler, client_data);
}
-int
+int
rb_select(unsigned long timeout)
{
int ret = select_handler(timeout);
return ret;
}
-int
+int
rb_setup_fd(rb_fde_t *F)
{
return setup_fd_handler(F);
int
rb_ignore_errno(int error)
{
- switch(error)
+ switch (error)
{
#ifdef EINPROGRESS
- case EINPROGRESS:
+ case EINPROGRESS:
#endif
#if defined EWOULDBLOCK
- case EWOULDBLOCK:
+ case EWOULDBLOCK:
#endif
#if defined(EAGAIN) && (EWOULDBLOCK != EAGAIN)
- case EAGAIN:
+ case EAGAIN:
#endif
#ifdef EINTR
- case EINTR:
+ case EINTR:
#endif
#ifdef ERESTART
- case ERESTART:
+ case ERESTART:
#endif
#ifdef ENOBUFS
- case ENOBUFS:
-#endif
- return 1;
- default:
- break;
- }
+ case ENOBUFS:
+#endif
+ return 1;
+ default:
+ break;
+ }
return 0;
}
+#if defined(HAVE_SENDMSG) && !defined(WIN32)
int
rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds)
{
iov[0].iov_base = data;
iov[0].iov_len = datasize;
-
+
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
if((len = recvmsg(rb_get_fd(F), &msg, 0)) <= 0)
return len;
- if(msg.msg_controllen > 0 && msg.msg_control != NULL && (cmsg = CMSG_FIRSTHDR(&msg)) != NULL)
+ if(msg.msg_controllen > 0 && msg.msg_control != NULL
+ && (cmsg = CMSG_FIRSTHDR(&msg)) != NULL)
{
rfds = (msg.msg_controllen - sizeof(struct cmsghdr)) / sizeof(int);
}
xF[x] = rb_open(fd, stype, desc);
}
- } else
+ }
+ else
*xF = NULL;
- return len;
+ return len;
}
int
-rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize)
+rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid)
{
int n;
struct msghdr msg;
if(datasize == 0)
{
iov[0].iov_base = ∅
- iov[0].iov_len = 1;
- } else {
+ iov[0].iov_len = 1;
+ }
+ else
+ {
iov[0].iov_base = data;
iov[0].iov_len = datasize;
}
cmsg->cmsg_len = CMSG_LEN(sizeof(int) * count);
for(i = 0; i < count; i++)
- {
- ((int *)CMSG_DATA(cmsg))[i] = rb_get_fd(F[i]);
+ {
+ ((int *)CMSG_DATA(cmsg))[i] = rb_get_fd(F[i]);
}
msg.msg_controllen = cmsg->cmsg_len;
}
n = sendmsg(rb_get_fd(xF), &msg, MSG_NOSIGNAL);
return n;
}
+#else
+#ifndef _WIN32
+int
+rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds)
+{
+ errno = ENOSYS;
+ return -1;
+}
+int
+rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid)
+{
+ errno = ENOSYS;
+ return -1;
+}
+#endif
+#endif
char *
rb_crypt(const char *key, const char *salt)
{
- return(crypt(key, salt));
+ return (crypt(key, salt));
}
#else
-static char * __md5_crypt( const char *pw, const char *salt);
-static char * __des_crypt( const char *pw, const char *salt);
+static char *__md5_crypt(const char *pw, const char *salt);
+static char *__des_crypt(const char *pw, const char *salt);
-char *
+char *
rb_crypt(const char *key, const char *salt)
{
/* First, check if we are supposed to be using the MD5 replacement
* instead of DES... */
- if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$')
+ if(salt[0] == '$' && salt[1] == '1' && salt[2] == '$')
return __md5_crypt(key, salt);
else
return __des_crypt(key, salt);
/* Re-entrantify me -- all this junk needs to be in
* struct crypt_data to make this really reentrant... */
-static u_char inv_key_perm[64];
-static u_char inv_comp_perm[56];
-static u_char u_sbox[8][64];
-static u_char un_pbox[32];
+static uint8_t inv_key_perm[64];
+static uint8_t inv_comp_perm[56];
+static uint8_t u_sbox[8][64];
+static uint8_t un_pbox[32];
static uint32_t en_keysl[16], en_keysr[16];
static uint32_t de_keysl[16], de_keysr[16];
static uint32_t ip_maskl[8][256], ip_maskr[8][256];
/* Static stuff that stays resident and doesn't change after
* being initialized, and therefore doesn't need to be made
* reentrant. */
-static u_char init_perm[64], final_perm[64];
-static u_char m_sbox[4][4096];
+static uint8_t init_perm[64], final_perm[64];
+static uint8_t m_sbox[4][4096];
static uint32_t psbox[4][256];
/* A pile of data */
-static const u_char ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-static const u_char IP[64] = {
- 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
- 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
- 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
- 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
+static const uint8_t IP[64] = {
+ 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
+ 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
+ 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
+ 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
};
-static const u_char key_perm[56] = {
- 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
- 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
- 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
- 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
+static const uint8_t key_perm[56] = {
+ 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
+ 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
+ 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
+ 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
};
-static const u_char key_shifts[16] = {
+static const uint8_t key_shifts[16] = {
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
};
-static const u_char comp_perm[48] = {
- 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
- 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
+static const uint8_t comp_perm[48] = {
+ 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
+ 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
};
* No E box is used, as it's replaced by some ANDs, shifts, and ORs.
*/
-static const u_char sbox[8][64] = {
+static const uint8_t sbox[8][64] = {
{
- 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
- 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
- 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
- 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
- },
+ 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
+ 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
+ 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
+ 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13},
{
- 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
- 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
- 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
- 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
- },
+ 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
+ 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
+ 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
+ 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9},
{
- 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
- 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
- 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
- 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
- },
+ 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
+ 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
+ 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
+ 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12},
{
- 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
- 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
- 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
- 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
- },
+ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
+ 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
+ 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
+ 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14},
{
- 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
- 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
- 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
- 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
- },
+ 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
+ 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
+ 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
+ 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3},
{
- 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
- 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
- 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
- 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
- },
+ 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
+ 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
+ 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
+ 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13},
{
- 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
- 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
- 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
- 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
- },
+ 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
+ 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
+ 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
+ 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12},
{
- 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
- 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
- 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
- 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
- }
+ 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
+ 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
+ 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
+ 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}
};
-static const u_char pbox[32] = {
- 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
- 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
+static const uint8_t pbox[32] = {
+ 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
+ 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
};
-static const uint32_t bits32[32] =
-{
+static const uint32_t bits32[32] = {
0x80000000, 0x40000000, 0x20000000, 0x10000000,
0x08000000, 0x04000000, 0x02000000, 0x01000000,
0x00800000, 0x00400000, 0x00200000, 0x00100000,
0x00000008, 0x00000004, 0x00000002, 0x00000001
};
-static const u_char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+static const uint8_t bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+
static const uint32_t *bits28, *bits24;
-static int
+static int
ascii_to_bin(char ch)
{
- if (ch > 'z')
- return(0);
- if (ch >= 'a')
- return(ch - 'a' + 38);
- if (ch > 'Z')
- return(0);
- if (ch >= 'A')
- return(ch - 'A' + 12);
- if (ch > '9')
- return(0);
- if (ch >= '.')
- return(ch - '.');
- return(0);
+ if(ch > 'z')
+ return (0);
+ if(ch >= 'a')
+ return (ch - 'a' + 38);
+ if(ch > 'Z')
+ return (0);
+ if(ch >= 'A')
+ return (ch - 'A' + 12);
+ if(ch > '9')
+ return (0);
+ if(ch >= '.')
+ return (ch - '.');
+ return (0);
}
static void
des_init(void)
{
- int i, j, b, k, inbit, obit;
- uint32_t *p, *il, *ir, *fl, *fr;
+ int i, j, b, k, inbit, obit;
+ uint32_t *p, *il, *ir, *fl, *fr;
static int des_initialised = 0;
- if (des_initialised==1)
- return;
+ if(des_initialised == 1)
+ return;
old_rawkey0 = old_rawkey1 = 0L;
saltbits = 0L;
/*
* Invert the S-boxes, reordering the input bits.
*/
- for (i = 0; i < 8; i++)
- for (j = 0; j < 64; j++) {
+ for(i = 0; i < 8; i++)
+ for(j = 0; j < 64; j++)
+ {
b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
u_sbox[i][j] = sbox[i][b];
}
* Convert the inverted S-boxes into 4 arrays of 8 bits.
* Each will handle 12 bits of the S-box input.
*/
- for (b = 0; b < 4; b++)
- for (i = 0; i < 64; i++)
- for (j = 0; j < 64; j++)
+ for(b = 0; b < 4; b++)
+ for(i = 0; i < 64; i++)
+ for(j = 0; j < 64; j++)
m_sbox[b][(i << 6) | j] =
- (u_char)((u_sbox[(b << 1)][i] << 4) |
- u_sbox[(b << 1) + 1][j]);
+ (uint8_t)((u_sbox[(b << 1)][i] << 4) |
+ u_sbox[(b << 1) + 1][j]);
/*
* Set up the initial & final permutations into a useful form, and
* initialise the inverted key permutation.
*/
- for (i = 0; i < 64; i++) {
- init_perm[final_perm[i] = IP[i] - 1] = (u_char)i;
+ for(i = 0; i < 64; i++)
+ {
+ init_perm[final_perm[i] = IP[i] - 1] = (uint8_t)i;
inv_key_perm[i] = 255;
}
* Invert the key permutation and initialise the inverted key
* compression permutation.
*/
- for (i = 0; i < 56; i++) {
- inv_key_perm[key_perm[i] - 1] = (u_char)i;
+ for(i = 0; i < 56; i++)
+ {
+ inv_key_perm[key_perm[i] - 1] = (uint8_t)i;
inv_comp_perm[i] = 255;
}
/*
* Invert the key compression permutation.
*/
- for (i = 0; i < 48; i++) {
- inv_comp_perm[comp_perm[i] - 1] = (u_char)i;
+ for(i = 0; i < 48; i++)
+ {
+ inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i;
}
/*
* Set up the OR-mask arrays for the initial and final permutations,
* and for the key initial and compression permutations.
*/
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 256; i++) {
+ for(k = 0; k < 8; k++)
+ {
+ for(i = 0; i < 256; i++)
+ {
*(il = &ip_maskl[k][i]) = 0L;
*(ir = &ip_maskr[k][i]) = 0L;
*(fl = &fp_maskl[k][i]) = 0L;
*(fr = &fp_maskr[k][i]) = 0L;
- for (j = 0; j < 8; j++) {
+ for(j = 0; j < 8; j++)
+ {
inbit = 8 * k + j;
- if (i & bits8[j]) {
- if ((obit = init_perm[inbit]) < 32)
+ if(i & bits8[j])
+ {
+ if((obit = init_perm[inbit]) < 32)
*il |= bits32[obit];
else
- *ir |= bits32[obit-32];
- if ((obit = final_perm[inbit]) < 32)
+ *ir |= bits32[obit - 32];
+ if((obit = final_perm[inbit]) < 32)
*fl |= bits32[obit];
else
*fr |= bits32[obit - 32];
}
}
}
- for (i = 0; i < 128; i++) {
+ for(i = 0; i < 128; i++)
+ {
*(il = &key_perm_maskl[k][i]) = 0L;
*(ir = &key_perm_maskr[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
+ for(j = 0; j < 7; j++)
+ {
inbit = 8 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit = inv_key_perm[inbit]) == 255)
+ if(i & bits8[j + 1])
+ {
+ if((obit = inv_key_perm[inbit]) == 255)
continue;
- if (obit < 28)
+ if(obit < 28)
*il |= bits28[obit];
else
*ir |= bits28[obit - 28];
}
*(il = &comp_maskl[k][i]) = 0L;
*(ir = &comp_maskr[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
+ for(j = 0; j < 7; j++)
+ {
inbit = 7 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit=inv_comp_perm[inbit]) == 255)
+ if(i & bits8[j + 1])
+ {
+ if((obit = inv_comp_perm[inbit]) == 255)
continue;
- if (obit < 24)
+ if(obit < 24)
*il |= bits24[obit];
else
*ir |= bits24[obit - 24];
* Invert the P-box permutation, and convert into OR-masks for
* handling the output of the S-box arrays setup above.
*/
- for (i = 0; i < 32; i++)
- un_pbox[pbox[i] - 1] = (u_char)i;
+ for(i = 0; i < 32; i++)
+ un_pbox[pbox[i] - 1] = (uint8_t)i;
- for (b = 0; b < 4; b++)
- for (i = 0; i < 256; i++) {
+ for(b = 0; b < 4; b++)
+ for(i = 0; i < 256; i++)
+ {
*(p = &psbox[b][i]) = 0L;
- for (j = 0; j < 8; j++) {
- if (i & bits8[j])
+ for(j = 0; j < 8; j++)
+ {
+ if(i & bits8[j])
*p |= bits32[un_pbox[8 * b + j]];
}
}
static void
setup_salt(long salt)
{
- uint32_t obit, saltbit;
- int i;
+ uint32_t obit, saltbit;
+ int i;
- if (salt == (long)old_salt)
+ if(salt == (long)old_salt)
return;
old_salt = salt;
saltbits = 0L;
saltbit = 1;
obit = 0x800000;
- for (i = 0; i < 24; i++) {
- if (salt & saltbit)
+ for(i = 0; i < 24; i++)
+ {
+ if(salt & saltbit)
saltbits |= obit;
saltbit <<= 1;
obit >>= 1;
static int
des_setkey(const char *key)
{
- uint32_t k0, k1, rawkey0, rawkey1;
- int shifts, round;
+ uint32_t k0, k1, rawkey0, rawkey1;
+ int shifts, round;
des_init();
- rawkey0 = ntohl(*(const uint32_t *) key);
- rawkey1 = ntohl(*(const uint32_t *) (key + 4));
+ rawkey0 = ntohl(*(const uint32_t *)key);
+ rawkey1 = ntohl(*(const uint32_t *)(key + 4));
- if ((rawkey0 | rawkey1)
- && rawkey0 == old_rawkey0
- && rawkey1 == old_rawkey1) {
+ if((rawkey0 | rawkey1) && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1)
+ {
/*
* Already setup for this key.
* This optimisation fails on a zero key (which is weak and
* has bad parity anyway) in order to simplify the starting
* conditions.
*/
- return(0);
+ return (0);
}
old_rawkey0 = rawkey0;
old_rawkey1 = rawkey1;
/*
- * Do key permutation and split into two 28-bit subkeys.
+ * Do key permutation and split into two 28-bit subkeys.
*/
k0 = key_perm_maskl[0][rawkey0 >> 25]
- | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
- | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
- | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
- | key_perm_maskl[4][rawkey1 >> 25]
- | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
- | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
- | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
+ | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskl[4][rawkey1 >> 25]
+ | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
k1 = key_perm_maskr[0][rawkey0 >> 25]
- | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
- | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
- | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
- | key_perm_maskr[4][rawkey1 >> 25]
- | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
- | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
- | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
+ | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskr[4][rawkey1 >> 25]
+ | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
/*
- * Rotate subkeys and do compression permutation.
+ * Rotate subkeys and do compression permutation.
*/
shifts = 0;
- for (round = 0; round < 16; round++) {
- uint32_t t0, t1;
+ for(round = 0; round < 16; round++)
+ {
+ uint32_t t0, t1;
shifts += key_shifts[round];
t1 = (k1 << shifts) | (k1 >> (28 - shifts));
de_keysl[15 - round] =
- en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
- | comp_maskl[1][(t0 >> 14) & 0x7f]
- | comp_maskl[2][(t0 >> 7) & 0x7f]
- | comp_maskl[3][t0 & 0x7f]
- | comp_maskl[4][(t1 >> 21) & 0x7f]
- | comp_maskl[5][(t1 >> 14) & 0x7f]
- | comp_maskl[6][(t1 >> 7) & 0x7f]
- | comp_maskl[7][t1 & 0x7f];
+ en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
+ | comp_maskl[1][(t0 >> 14) & 0x7f]
+ | comp_maskl[2][(t0 >> 7) & 0x7f]
+ | comp_maskl[3][t0 & 0x7f]
+ | comp_maskl[4][(t1 >> 21) & 0x7f]
+ | comp_maskl[5][(t1 >> 14) & 0x7f]
+ | comp_maskl[6][(t1 >> 7) & 0x7f] | comp_maskl[7][t1 & 0x7f];
de_keysr[15 - round] =
- en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
- | comp_maskr[1][(t0 >> 14) & 0x7f]
- | comp_maskr[2][(t0 >> 7) & 0x7f]
- | comp_maskr[3][t0 & 0x7f]
- | comp_maskr[4][(t1 >> 21) & 0x7f]
- | comp_maskr[5][(t1 >> 14) & 0x7f]
- | comp_maskr[6][(t1 >> 7) & 0x7f]
- | comp_maskr[7][t1 & 0x7f];
+ en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
+ | comp_maskr[1][(t0 >> 14) & 0x7f]
+ | comp_maskr[2][(t0 >> 7) & 0x7f]
+ | comp_maskr[3][t0 & 0x7f]
+ | comp_maskr[4][(t1 >> 21) & 0x7f]
+ | comp_maskr[5][(t1 >> 14) & 0x7f]
+ | comp_maskr[6][(t1 >> 7) & 0x7f] | comp_maskr[7][t1 & 0x7f];
}
- return(0);
+ return (0);
}
static int
-do_des( uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int count)
+do_des(uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int count)
{
/*
- * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
+ * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
*/
- uint32_t l, r, *kl, *kr, *kl1, *kr1;
- uint32_t f, r48l, r48r;
- int round;
+ uint32_t l, r, *kl, *kr, *kl1, *kr1;
+ uint32_t f, r48l, r48r;
+ int round;
- if (count == 0) {
- return(1);
- } else if (count > 0) {
+ if(count == 0)
+ {
+ return (1);
+ }
+ else if(count > 0)
+ {
/*
* Encrypting
*/
kl1 = en_keysl;
kr1 = en_keysr;
- } else {
+ }
+ else
+ {
/*
* Decrypting
*/
}
/*
- * Do initial permutation (IP).
+ * Do initial permutation (IP).
*/
l = ip_maskl[0][l_in >> 24]
- | ip_maskl[1][(l_in >> 16) & 0xff]
- | ip_maskl[2][(l_in >> 8) & 0xff]
- | ip_maskl[3][l_in & 0xff]
- | ip_maskl[4][r_in >> 24]
- | ip_maskl[5][(r_in >> 16) & 0xff]
- | ip_maskl[6][(r_in >> 8) & 0xff]
- | ip_maskl[7][r_in & 0xff];
+ | ip_maskl[1][(l_in >> 16) & 0xff]
+ | ip_maskl[2][(l_in >> 8) & 0xff]
+ | ip_maskl[3][l_in & 0xff]
+ | ip_maskl[4][r_in >> 24]
+ | ip_maskl[5][(r_in >> 16) & 0xff]
+ | ip_maskl[6][(r_in >> 8) & 0xff] | ip_maskl[7][r_in & 0xff];
r = ip_maskr[0][l_in >> 24]
- | ip_maskr[1][(l_in >> 16) & 0xff]
- | ip_maskr[2][(l_in >> 8) & 0xff]
- | ip_maskr[3][l_in & 0xff]
- | ip_maskr[4][r_in >> 24]
- | ip_maskr[5][(r_in >> 16) & 0xff]
- | ip_maskr[6][(r_in >> 8) & 0xff]
- | ip_maskr[7][r_in & 0xff];
-
- while (count--) {
+ | ip_maskr[1][(l_in >> 16) & 0xff]
+ | ip_maskr[2][(l_in >> 8) & 0xff]
+ | ip_maskr[3][l_in & 0xff]
+ | ip_maskr[4][r_in >> 24]
+ | ip_maskr[5][(r_in >> 16) & 0xff]
+ | ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff];
+
+ while(count--)
+ {
/*
* Do each round.
*/
kl = kl1;
kr = kr1;
round = 16;
- while (round--) {
+ while(round--)
+ {
/*
* Expand R to 48 bits (simulate the E-box).
*/
- r48l = ((r & 0x00000001) << 23)
+ r48l = ((r & 0x00000001) << 23)
| ((r & 0xf8000000) >> 9)
| ((r & 0x1f800000) >> 11)
- | ((r & 0x01f80000) >> 13)
- | ((r & 0x001f8000) >> 15);
+ | ((r & 0x01f80000) >> 13) | ((r & 0x001f8000) >> 15);
- r48r = ((r & 0x0001f800) << 7)
+ r48r = ((r & 0x0001f800) << 7)
| ((r & 0x00001f80) << 5)
| ((r & 0x000001f8) << 3)
- | ((r & 0x0000001f) << 1)
- | ((r & 0x80000000) >> 31);
+ | ((r & 0x0000001f) << 1) | ((r & 0x80000000) >> 31);
/*
* Do salting for crypt() and friends, and
* XOR with the permuted key.
* and do the pbox permutation at the same time.
*/
f = psbox[0][m_sbox[0][r48l >> 12]]
- | psbox[1][m_sbox[1][r48l & 0xfff]]
- | psbox[2][m_sbox[2][r48r >> 12]]
- | psbox[3][m_sbox[3][r48r & 0xfff]];
+ | psbox[1][m_sbox[1][r48l & 0xfff]]
+ | psbox[2][m_sbox[2][r48r >> 12]]
+ | psbox[3][m_sbox[3][r48r & 0xfff]];
/*
* Now that we've permuted things, complete f().
*/
/*
* Do final permutation (inverse of IP).
*/
- *l_out = fp_maskl[0][l >> 24]
+ *l_out = fp_maskl[0][l >> 24]
| fp_maskl[1][(l >> 16) & 0xff]
| fp_maskl[2][(l >> 8) & 0xff]
| fp_maskl[3][l & 0xff]
| fp_maskl[4][r >> 24]
| fp_maskl[5][(r >> 16) & 0xff]
- | fp_maskl[6][(r >> 8) & 0xff]
- | fp_maskl[7][r & 0xff];
- *r_out = fp_maskr[0][l >> 24]
+ | fp_maskl[6][(r >> 8) & 0xff] | fp_maskl[7][r & 0xff];
+ *r_out = fp_maskr[0][l >> 24]
| fp_maskr[1][(l >> 16) & 0xff]
| fp_maskr[2][(l >> 8) & 0xff]
| fp_maskr[3][l & 0xff]
| fp_maskr[4][r >> 24]
| fp_maskr[5][(r >> 16) & 0xff]
- | fp_maskr[6][(r >> 8) & 0xff]
- | fp_maskr[7][r & 0xff];
- return(0);
+ | fp_maskr[6][(r >> 8) & 0xff] | fp_maskr[7][r & 0xff];
+ return (0);
}
static int
des_cipher(const char *in, char *out, uint32_t salt, int count)
{
- uint32_t l_out, r_out, rawl, rawr;
- int retval;
- union {
- uint32_t *ui32;
- const char *c;
+ uint32_t l_out, r_out, rawl, rawr;
+ int retval;
+ union
+ {
+ uint32_t *ui32;
+ const char *c;
} trans;
des_init();
trans.c = out;
*trans.ui32++ = htonl(l_out);
*trans.ui32 = htonl(r_out);
- return(retval);
+ return (retval);
}
#endif
void
setkey(const char *key)
{
- int i, j;
- uint32_t packed_keys[2];
- u_char *p;
+ int i, j;
+ uint32_t packed_keys[2];
+ uint8_t *p;
- p = (u_char *) packed_keys;
+ p = (uint8_t *)packed_keys;
- for (i = 0; i < 8; i++) {
+ for(i = 0; i < 8; i++)
+ {
p[i] = 0;
- for (j = 0; j < 8; j++)
- if (*key++ & 1)
+ for(j = 0; j < 8; j++)
+ if(*key++ & 1)
p[i] |= bits8[j];
}
des_setkey((char *)p);
void
encrypt(char *block, int flag)
{
- uint32_t io[2];
- u_char *p;
- int i, j;
+ uint32_t io[2];
+ uint8_t *p;
+ int i, j;
des_init();
setup_salt(0L);
- p = (u_char*)block;
- for (i = 0; i < 2; i++) {
+ p = (uint8_t *)block;
+ for(i = 0; i < 2; i++)
+ {
io[i] = 0L;
- for (j = 0; j < 32; j++)
- if (*p++ & 1)
+ for(j = 0; j < 32; j++)
+ if(*p++ & 1)
io[i] |= bits32[j];
}
do_des(io[0], io[1], io, io + 1, flag ? -1 : 1);
- for (i = 0; i < 2; i++)
- for (j = 0; j < 32; j++)
+ for(i = 0; i < 2; i++)
+ for(j = 0; j < 32; j++)
block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0;
}
#endif
static char *
__des_crypt(const char *key, const char *setting)
{
- uint32_t count, salt, l, r0, r1, keybuf[2];
- u_char *p, *q;
- static char output[21];
+ uint32_t count, salt, l, r0, r1, keybuf[2];
+ uint8_t *p, *q;
+ static char output[21];
des_init();
* Copy the key, shifting each character up by one bit
* and padding with zeros.
*/
- q = (u_char *)keybuf;
- while (q - (u_char *)keybuf - 8) {
+ q = (uint8_t *)keybuf;
+ while(q - (uint8_t *)keybuf - 8)
+ {
*q++ = *key << 1;
- if (*(q - 1))
+ if(*(q - 1))
key++;
}
- if (des_setkey((char *)keybuf))
- return(NULL);
+ if(des_setkey((char *)keybuf))
+ return (NULL);
#if 0
- if (*setting == _PASSWORD_EFMT1) {
- int i;
+ if(*setting == _PASSWORD_EFMT1)
+ {
+ int i;
/*
* "new"-style:
- * setting - underscore, 4 bytes of count, 4 bytes of salt
- * key - unlimited characters
+ * setting - underscore, 4 bytes of count, 4 bytes of salt
+ * key - unlimited characters
*/
- for (i = 1, count = 0L; i < 5; i++)
+ for(i = 1, count = 0L; i < 5; i++)
count |= ascii_to_bin(setting[i]) << ((i - 1) * 6);
- for (i = 5, salt = 0L; i < 9; i++)
+ for(i = 5, salt = 0L; i < 9; i++)
salt |= ascii_to_bin(setting[i]) << ((i - 5) * 6);
- while (*key) {
+ while(*key)
+ {
/*
* Encrypt the key with itself.
*/
- if (des_cipher((char *)keybuf, (char *)keybuf, 0L, 1))
- return(NULL);
+ if(des_cipher((char *)keybuf, (char *)keybuf, 0L, 1))
+ return (NULL);
/*
* And XOR with the next 8 characters of the key.
*/
- q = (u_char *)keybuf;
- while (q - (u_char *)keybuf - 8 && *key)
+ q = (uint8_t *)keybuf;
+ while(q - (uint8_t *)keybuf - 8 && *key)
*q++ ^= *key++ << 1;
- if (des_setkey((char *)keybuf))
- return(NULL);
+ if(des_setkey((char *)keybuf))
+ return (NULL);
}
strncpy(output, setting, 9);
* NUL in it.
*/
output[9] = '\0';
- p = (u_char *)output + strlen(output);
- } else
+ p = (uint8_t *)output + strlen(output);
+ }
+ else
#endif
{
/*
* "old"-style:
- * setting - 2 bytes of salt
- * key - up to 8 characters
+ * setting - 2 bytes of salt
+ * key - up to 8 characters
*/
count = 25;
- salt = (ascii_to_bin(setting[1]) << 6)
- | ascii_to_bin(setting[0]);
+ salt = (ascii_to_bin(setting[1]) << 6) | ascii_to_bin(setting[0]);
output[0] = setting[0];
/*
*/
output[1] = setting[1] ? setting[1] : output[0];
- p = (u_char *)output + 2;
+ p = (uint8_t *)output + 2;
}
setup_salt(salt);
/*
* Do it.
*/
- if (do_des(0L, 0L, &r0, &r1, (int)count))
- return(NULL);
+ if(do_des(0L, 0L, &r0, &r1, (int)count))
+ return (NULL);
/*
* Now encode the result...
*/
*p++ = ascii64[l & 0x3f];
*p = 0;
- return(output);
+ return (output);
}
/* Now md5 crypt */
/**********************************************************************/
/* MD5 context. */
-struct MD5Context {
- uint32_t state[4]; /* state (ABCD) */
- uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
- unsigned char buffer[64]; /* input buffer */
+struct MD5Context
+{
+ uint32_t state[4]; /* state (ABCD) */
+ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ unsigned char buffer[64]; /* input buffer */
};
-static void __md5_Init (struct MD5Context *);
-static void __md5_Update (struct MD5Context *, const char *, unsigned int);
-static void __md5_Pad (struct MD5Context *);
-static void __md5_Final (char [16], struct MD5Context *);
-static void __md5_Transform (uint32_t [4], const unsigned char [64]);
+static void __md5_Init(struct MD5Context *);
+static void __md5_Update(struct MD5Context *, const char *, unsigned int);
+static void __md5_Pad(struct MD5Context *);
+static void __md5_Final(char[16], struct MD5Context *);
+static void __md5_Transform(uint32_t[4], const unsigned char[64]);
static const char __md5__magic[] = "$1$"; /* This string is magic for this algorithm. Having
it this way, we can get better later on */
-static const unsigned char __md5_itoa64[] = /* 0 ... 63 => ascii - 64 */
+static const unsigned char __md5_itoa64[] = /* 0 ... 63 => ascii - 64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
*/
static void
-__md5_Encode (unsigned char *output, uint32_t *input, unsigned int len)
+__md5_Encode(unsigned char *output, uint32_t *input, unsigned int len)
{
unsigned int i, j;
- for (i = 0, j = 0; j < len; i++, j += 4) {
+ for(i = 0, j = 0; j < len; i++, j += 4)
+ {
output[j] = (unsigned char)(input[i] & 0xff);
- output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
- output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
- output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ output[j + 1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j + 2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j + 3] = (unsigned char)((input[i] >> 24) & 0xff);
}
}
*/
static void
-__md5_Decode (uint32_t *output, const unsigned char *input, unsigned int len)
+__md5_Decode(uint32_t *output, const unsigned char *input, unsigned int len)
{
unsigned int i, j;
- for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((uint32_t)input[j]) | (((uint32_t)input[j+1]) << 8) |
- (((uint32_t)input[j+2]) << 16) | (((uint32_t)input[j+3]) << 24);
+ for(i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = ((uint32_t)input[j]) | (((uint32_t)input[j + 1]) << 8) |
+ (((uint32_t)input[j + 2]) << 16) | (((uint32_t)input[j + 3]) << 24);
}
#endif /* i386 */
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
-static void __md5_Init (struct MD5Context *context)
+static void
+__md5_Init(struct MD5Context *context)
{
context->count[0] = context->count[1] = 0;
* context.
*/
-static void __md5_Update ( struct MD5Context *context, const char *xinput, unsigned int inputLen)
+static void
+__md5_Update(struct MD5Context *context, const char *xinput, unsigned int inputLen)
{
unsigned int i, lindex, partLen;
- const unsigned char *input = (const unsigned char *)xinput; /* i hate gcc */
+ const unsigned char *input = (const unsigned char *)xinput; /* i hate gcc */
/* Compute number of bytes mod 64 */
lindex = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((uint32_t)inputLen << 3))
- < ((uint32_t)inputLen << 3))
+ if((context->count[0] += ((uint32_t)inputLen << 3)) < ((uint32_t)inputLen << 3))
context->count[1]++;
context->count[1] += ((uint32_t)inputLen >> 29);
partLen = 64 - lindex;
/* Transform as many times as possible. */
- if (inputLen >= partLen) {
- memcpy(&context->buffer[lindex], input,
- partLen);
- __md5_Transform (context->state, context->buffer);
+ if(inputLen >= partLen)
+ {
+ memcpy(&context->buffer[lindex], input, partLen);
+ __md5_Transform(context->state, context->buffer);
- for (i = partLen; i + 63 < inputLen; i += 64)
- __md5_Transform (context->state, &input[i]);
+ for(i = partLen; i + 63 < inputLen; i += 64)
+ __md5_Transform(context->state, &input[i]);
lindex = 0;
}
i = 0;
/* Buffer remaining input */
- memcpy (&context->buffer[lindex], &input[i],
- inputLen-i);
+ memcpy(&context->buffer[lindex], &input[i], inputLen - i);
}
/*
* MD5 padding. Adds padding followed by original length.
*/
-static void __md5_Pad ( struct MD5Context *context)
+static void
+__md5_Pad(struct MD5Context *context)
{
char bits[8];
unsigned int lindex, padLen;
PADDING[0] = 0x80;
/* Save number of bits */
- __md5_Encode (bits, context->count, 8);
+ __md5_Encode(bits, context->count, 8);
/* Pad out to 56 mod 64. */
lindex = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (lindex < 56) ? (56 - lindex) : (120 - lindex);
- __md5_Update (context, PADDING, padLen);
+ __md5_Update(context, PADDING, padLen);
/* Append length (before padding) */
- __md5_Update (context, bits, 8);
+ __md5_Update(context, bits, 8);
}
/*
* the message digest and zeroizing the context.
*/
-static void __md5_Final ( char xdigest[16], struct MD5Context *context)
+static void
+__md5_Final(char xdigest[16], struct MD5Context *context)
{
unsigned char *digest = (unsigned char *)xdigest;
/* Do padding. */
- __md5_Pad (context);
+ __md5_Pad(context);
/* Store state in digest */
- __md5_Encode (digest, context->state, 16);
+ __md5_Encode(digest, context->state, 16);
/* Zeroize sensitive information. */
- memset (context, 0, sizeof (*context));
+ memset(context, 0, sizeof(*context));
}
/* MD5 basic transformation. Transforms state based on block. */
static void
-__md5_Transform (state, block)
- uint32_t state[4];
- const unsigned char block[64];
+__md5_Transform(state, block)
+ uint32_t state[4];
+ const unsigned char block[64];
{
uint32_t a, b, c, d, x[16];
int i;
static const uint32_t C[] = {
- /* round 1 */
+ /* round 1 */
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
- /* round 2 */
+ /* round 2 */
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
- 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
+ 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
- /* round 3 */
+ /* round 3 */
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
- /* round 4 */
+ /* round 4 */
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
};
static const char P[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */
- 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */
- 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */
- 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */
+ 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */
+ 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */
+ 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */
};
#endif /* MD5_SIZE_OVER_SPEED > 0 */
- __md5_Decode (x, block, 64);
+ __md5_Decode(x, block, 64);
- a = state[0]; b = state[1]; c = state[2]; d = state[3];
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
#if MD5_SIZE_OVER_SPEED > 2
- pc = C; pp = P; ps = S - 4;
+ pc = C;
+ pp = P;
+ ps = S - 4;
- for ( i = 0 ; i < 64 ; i++ ) {
- if ((i&0x0f) == 0) ps += 4;
+ for(i = 0; i < 64; i++)
+ {
+ if((i & 0x0f) == 0)
+ ps += 4;
temp = a;
- switch (i>>4) {
- case 0:
- temp += F(b,c,d);
- break;
- case 1:
- temp += G(b,c,d);
- break;
- case 2:
- temp += H(b,c,d);
- break;
- case 3:
- temp += I(b,c,d);
- break;
+ switch (i >> 4)
+ {
+ case 0:
+ temp += F(b, c, d);
+ break;
+ case 1:
+ temp += G(b, c, d);
+ break;
+ case 2:
+ temp += H(b, c, d);
+ break;
+ case 3:
+ temp += I(b, c, d);
+ break;
}
temp += x[(int)(*pp++)] + *pc++;
- temp = ROTATE_LEFT(temp, ps[i&3]);
+ temp = ROTATE_LEFT(temp, ps[i & 3]);
temp += b;
- a = d; d = c; c = b; b = temp;
+ a = d;
+ d = c;
+ c = b;
+ b = temp;
}
#elif MD5_SIZE_OVER_SPEED > 1
- pc = C; pp = P; ps = S;
+ pc = C;
+ pp = P;
+ ps = S;
/* Round 1 */
- for ( i = 0 ; i < 16 ; i++ ) {
- FF (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++);
- temp = d; d = c; c = b; b = a; a = temp;
+ for(i = 0; i < 16; i++)
+ {
+ FF(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++);
+ temp = d;
+ d = c;
+ c = b;
+ b = a;
+ a = temp;
}
/* Round 2 */
ps += 4;
- for ( ; i < 32 ; i++ ) {
- GG (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++);
- temp = d; d = c; c = b; b = a; a = temp;
+ for(; i < 32; i++)
+ {
+ GG(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++);
+ temp = d;
+ d = c;
+ c = b;
+ b = a;
+ a = temp;
}
/* Round 3 */
ps += 4;
- for ( ; i < 48 ; i++ ) {
- HH (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++);
- temp = d; d = c; c = b; b = a; a = temp;
+ for(; i < 48; i++)
+ {
+ HH(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++);
+ temp = d;
+ d = c;
+ c = b;
+ b = a;
+ a = temp;
}
/* Round 4 */
ps += 4;
- for ( ; i < 64 ; i++ ) {
- II (a, b, c, d, x[(int)(*pp++)], ps[i&0x3], *pc++);
- temp = d; d = c; c = b; b = a; a = temp;
+ for(; i < 64; i++)
+ {
+ II(a, b, c, d, x[(int)(*pp++)], ps[i & 0x3], *pc++);
+ temp = d;
+ d = c;
+ c = b;
+ b = a;
+ a = temp;
}
#elif MD5_SIZE_OVER_SPEED > 0
- pc = C; pp = P;
+ pc = C;
+ pp = P;
/* Round 1 */
- for ( i = 0 ; i < 4 ; i++ ) {
- FF (a, b, c, d, x[(int)(*pp++)], 7, *pc++);
- FF (d, a, b, c, x[(int)(*pp++)], 12, *pc++);
- FF (c, d, a, b, x[(int)(*pp++)], 17, *pc++);
- FF (b, c, d, a, x[(int)(*pp++)], 22, *pc++);
+ for(i = 0; i < 4; i++)
+ {
+ FF(a, b, c, d, x[(int)(*pp++)], 7, *pc++);
+ FF(d, a, b, c, x[(int)(*pp++)], 12, *pc++);
+ FF(c, d, a, b, x[(int)(*pp++)], 17, *pc++);
+ FF(b, c, d, a, x[(int)(*pp++)], 22, *pc++);
}
/* Round 2 */
- for ( i = 0 ; i < 4 ; i++ ) {
- GG (a, b, c, d, x[(int)(*pp++)], 5, *pc++);
- GG (d, a, b, c, x[(int)(*pp++)], 9, *pc++);
- GG (c, d, a, b, x[(int)(*pp++)], 14, *pc++);
- GG (b, c, d, a, x[(int)(*pp++)], 20, *pc++);
+ for(i = 0; i < 4; i++)
+ {
+ GG(a, b, c, d, x[(int)(*pp++)], 5, *pc++);
+ GG(d, a, b, c, x[(int)(*pp++)], 9, *pc++);
+ GG(c, d, a, b, x[(int)(*pp++)], 14, *pc++);
+ GG(b, c, d, a, x[(int)(*pp++)], 20, *pc++);
}
/* Round 3 */
- for ( i = 0 ; i < 4 ; i++ ) {
- HH (a, b, c, d, x[(int)(*pp++)], 4, *pc++);
- HH (d, a, b, c, x[(int)(*pp++)], 11, *pc++);
- HH (c, d, a, b, x[(int)(*pp++)], 16, *pc++);
- HH (b, c, d, a, x[(int)(*pp++)], 23, *pc++);
+ for(i = 0; i < 4; i++)
+ {
+ HH(a, b, c, d, x[(int)(*pp++)], 4, *pc++);
+ HH(d, a, b, c, x[(int)(*pp++)], 11, *pc++);
+ HH(c, d, a, b, x[(int)(*pp++)], 16, *pc++);
+ HH(b, c, d, a, x[(int)(*pp++)], 23, *pc++);
}
/* Round 4 */
- for ( i = 0 ; i < 4 ; i++ ) {
- II (a, b, c, d, x[(int)(*pp++)], 6, *pc++);
- II (d, a, b, c, x[(int)(*pp++)], 10, *pc++);
- II (c, d, a, b, x[(int)(*pp++)], 15, *pc++);
- II (b, c, d, a, x[(int)(*pp++)], 21, *pc++);
+ for(i = 0; i < 4; i++)
+ {
+ II(a, b, c, d, x[(int)(*pp++)], 6, *pc++);
+ II(d, a, b, c, x[(int)(*pp++)], 10, *pc++);
+ II(c, d, a, b, x[(int)(*pp++)], 15, *pc++);
+ II(b, c, d, a, x[(int)(*pp++)], 21, *pc++);
}
#else
/* Round 1 */
#define S12 12
#define S13 17
#define S14 22
- FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
- FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
- FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
- FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
- FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
- FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
- FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
- FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
- FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
- FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
- FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
- FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
- FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
- FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
- FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
- FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+ FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
+ FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
+ FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
+ FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
+ FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
+ FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
+ FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
+ FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
+ FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
+ FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
+ FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
- GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
- GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
- GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
- GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
- GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
- GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
- GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
- GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
- GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
- GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
- GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
- GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
- GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
- GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
- GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
- GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+ GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
+ GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
+ GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
+ GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
+ GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
+ GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
+ GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
+ GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
+ GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
+ GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
+ GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
- HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
- HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
- HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
- HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
- HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
- HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
- HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
- HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
- HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
- HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
- HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
- HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
- HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
- HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
- HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
- HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+ HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
+ HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
+ HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
+ HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
+ HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
+ HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
+ HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
+ HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
+ HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
+ HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
- II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
- II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
- II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
- II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
- II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
- II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
- II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
- II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
- II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
- II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
- II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
- II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
- II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
- II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
- II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
- II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+ II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
+ II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
+ II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
+ II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
+ II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
+ II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
+ II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
+ II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
+ II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
+ II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */
#endif
state[0] += a;
state[3] += d;
/* Zeroize sensitive information. */
- memset (x, 0, sizeof (x));
+ memset(x, 0, sizeof(x));
}
-static void __md5_to64( char *s, unsigned long v, int n)
+static void
+__md5_to64(char *s, unsigned long v, int n)
{
- while (--n >= 0) {
- *s++ = __md5_itoa64[v&0x3f];
+ while(--n >= 0)
+ {
+ *s++ = __md5_itoa64[v & 0x3f];
v >>= 6;
}
}
* Use MD5 for what it is best at...
*/
-static char * __md5_crypt( const char *pw, const char *salt)
+static char *
+__md5_crypt(const char *pw, const char *salt)
{
/* Static stuff */
static const char *sp, *ep;
static char passwd[120], *p;
- char final[17]; /* final[16] exists only to aid in looping */
- int sl,pl,i,__md5__magic_len,pw_len;
- struct MD5Context ctx,ctx1;
+ char final[17]; /* final[16] exists only to aid in looping */
+ int sl, pl, i, __md5__magic_len, pw_len;
+ struct MD5Context ctx, ctx1;
unsigned long l;
/* Refine the Salt first */
/* If it starts with the magic string, then skip that */
__md5__magic_len = strlen(__md5__magic);
- if(!strncmp(sp,__md5__magic,__md5__magic_len))
+ if(!strncmp(sp, __md5__magic, __md5__magic_len))
sp += __md5__magic_len;
/* It stops at the first '$', max 8 chars */
- for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++)
+ for(ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++)
continue;
/* get the length of the true salt */
/* The password first, since that is what is most unknown */
pw_len = strlen(pw);
- __md5_Update(&ctx,pw,pw_len);
+ __md5_Update(&ctx, pw, pw_len);
/* Then our magic string */
- __md5_Update(&ctx,__md5__magic,__md5__magic_len);
+ __md5_Update(&ctx, __md5__magic, __md5__magic_len);
/* Then the raw salt */
- __md5_Update(&ctx,sp,sl);
+ __md5_Update(&ctx, sp, sl);
/* Then just as many characters of the MD5(pw,salt,pw) */
__md5_Init(&ctx1);
- __md5_Update(&ctx1,pw,pw_len);
- __md5_Update(&ctx1,sp,sl);
- __md5_Update(&ctx1,pw,pw_len);
- __md5_Final(final,&ctx1);
+ __md5_Update(&ctx1, pw, pw_len);
+ __md5_Update(&ctx1, sp, sl);
+ __md5_Update(&ctx1, pw, pw_len);
+ __md5_Final(final, &ctx1);
for(pl = pw_len; pl > 0; pl -= 16)
- __md5_Update(&ctx,final,pl>16 ? 16 : pl);
+ __md5_Update(&ctx, final, pl > 16 ? 16 : pl);
/* Don't leave anything around in vm they could use. */
- memset(final,0,sizeof final);
+ memset(final, 0, sizeof final);
/* Then something really weird... */
- for (i = pw_len; i ; i >>= 1) {
- __md5_Update(&ctx, ((i&1) ? final : pw), 1);
+ for(i = pw_len; i; i >>= 1)
+ {
+ __md5_Update(&ctx, ((i & 1) ? final : pw), 1);
}
/* Now make the output string */
- strcpy(passwd,__md5__magic);
- strncat(passwd,sp,sl);
- strcat(passwd,"$");
+ strcpy(passwd, __md5__magic);
+ strncat(passwd, sp, sl);
+ strcat(passwd, "$");
- __md5_Final(final,&ctx);
+ __md5_Final(final, &ctx);
/*
* and now, just to make sure things don't run too fast
* On a 60 Mhz Pentium this takes 34 msec, so you would
* need 30 seconds to build a 1000 entry dictionary...
*/
- for(i=0;i<1000;i++) {
+ for(i = 0; i < 1000; i++)
+ {
__md5_Init(&ctx1);
if(i & 1)
- __md5_Update(&ctx1,pw,pw_len);
+ __md5_Update(&ctx1, pw, pw_len);
else
- __md5_Update(&ctx1,final,16);
+ __md5_Update(&ctx1, final, 16);
if(i % 3)
- __md5_Update(&ctx1,sp,sl);
+ __md5_Update(&ctx1, sp, sl);
if(i % 7)
- __md5_Update(&ctx1,pw,pw_len);
+ __md5_Update(&ctx1, pw, pw_len);
if(i & 1)
- __md5_Update(&ctx1,final,16);
+ __md5_Update(&ctx1, final, 16);
else
- __md5_Update(&ctx1,pw,pw_len);
- __md5_Final(final,&ctx1);
+ __md5_Update(&ctx1, pw, pw_len);
+ __md5_Final(final, &ctx1);
}
p = passwd + strlen(passwd);
final[16] = final[5];
- for ( i=0 ; i < 5 ; i++ ) {
- l = (final[i]<<16) | (final[i+6]<<8) | final[i+12];
- __md5_to64(p,l,4); p += 4;
+ for(i = 0; i < 5; i++)
+ {
+ l = (final[i] << 16) | (final[i + 6] << 8) | final[i + 12];
+ __md5_to64(p, l, 4);
+ p += 4;
}
l = final[11];
- __md5_to64(p,l,2); p += 2;
+ __md5_to64(p, l, 2);
+ p += 2;
*p = '\0';
/* Don't leave anything around in vm they could use. */
- memset(final,0,sizeof final);
+ memset(final, 0, sizeof final);
return passwd;
}
#endif /* NEED_CRYPT */
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: devpoll.c 25038 2008-01-23 16:03:08Z androsyn $
+ * $Id: devpoll.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
#include <ratbox_lib.h>
static void devpoll_write_update(int, int);
-int
+int
rb_setup_fd_devpoll(rb_fde_t *F)
{
- return 0;
+ return 0;
}
-
-
+
+
/*
* Write an update to the devpoll filter.
* See, we end up having to do a seperate (?) remove before we do an
/* Write the thing to our poll fd */
retval = write(dpfd, &pollfds[0], sizeof(struct pollfd));
if(retval != sizeof(struct pollfd))
- rb_lib_log("devpoll_write_update: dpfd write failed %d: %s", errno, strerror(errno));
+ rb_lib_log("devpoll_write_update: dpfd write failed %d: %s", errno,
+ strerror(errno));
/* Done! */
}
{
return errno;
}
- maxfd = getdtablesize() - 2; /* This makes more sense than HARD_FDLIMIT */
+ maxfd = getdtablesize() - 2; /* This makes more sense than HARD_FDLIMIT */
fdmask = rb_malloc(sizeof(fdmask) * maxfd + 1);
rb_open(dpfd, RB_FD_UNKNOWN, "/dev/poll file descriptor");
}
* and deregister interest in a pending IO state for a given FD.
*/
void
-rb_setselect_devpoll(rb_fde_t *F, unsigned int type, PF * handler,
- void *client_data)
+rb_setselect_devpoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
lrb_assert(IsFDOpen(F));
do
{
- for (;;)
+ for(;;)
{
dopoll.dp_timeout = delay;
dopoll.dp_nfds = maxfd;
if(num == 0)
continue;
- for (i = 0; i < num; i++)
+ for(i = 0; i < num; i++)
{
int fd = dopoll.dp_fds[i].fd;
PF *hdl = NULL;
rb_fde_t *F = rb_find_fd(fd);
- if((dopoll.dp_fds[i].
- revents & (POLLRDNORM | POLLIN | POLLHUP |
- POLLERR))
+ if((dopoll.dp_fds[i].revents & (POLLRDNORM | POLLIN | POLLHUP |
+ POLLERR))
&& (dopoll.dp_fds[i].events & (POLLRDNORM | POLLIN)))
{
if((hdl = F->read_handler) != NULL)
* poll set *if* the handler changes state (active ->
* NULL or vice versa.)
*/
- devpoll_update_events(fd,
- RB_SELECT_READ, F->read_handler);
+ devpoll_update_events(fd, RB_SELECT_READ, F->read_handler);
}
}
if(!IsFDOpen(F))
continue; /* Read handler closed us..go on to do something more useful */
- if((dopoll.dp_fds[i].
- revents & (POLLWRNORM | POLLOUT | POLLHUP |
- POLLERR))
+ if((dopoll.dp_fds[i].revents & (POLLWRNORM | POLLOUT | POLLHUP |
+ POLLERR))
&& (dopoll.dp_fds[i].events & (POLLWRNORM | POLLOUT)))
{
if((hdl = F->write_handler) != NULL)
}
return RB_OK;
}
- while (0);
+ while(0);
/* XXX Get here, we broke! */
return 0;
}
#else /* /dev/poll not supported */
-int
+int
rb_init_netio_devpoll(void)
{
return ENOSYS;
return -1;
}
#endif
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: epoll.c 25675 2008-07-06 04:13:05Z androsyn $
+ * $Id: epoll.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#define _GNU_SOURCE 1
#include <ratbox_lib.h>
#include <commio-int.h>
#include <event-int.h>
-
#if defined(HAVE_EPOLL_CTL) && (HAVE_SYS_EPOLL_H)
#define USING_EPOLL
#include <fcntl.h>
#define EPOLL_SCHED_EVENT 1
#endif
+#if defined(USE_TIMERFD_CREATE)
+#include <sys/timerfd.h>
+#endif
+
#define RTSIGNAL SIGRTMIN
struct epoll_info
{
static struct epoll_info *ep_info;
static int can_do_event;
-
-//static void setup_signalfd(void);
+static int can_do_timerfd;
/*
* rb_init_netio
int
rb_init_netio_epoll(void)
{
- can_do_event = 0; /* shut up gcc */
+ can_do_event = 0; /* shut up gcc */
ep_info = rb_malloc(sizeof(struct epoll_info));
ep_info->pfd_size = getdtablesize();
ep_info->ep = epoll_create(ep_info->pfd_size);
}
int
-rb_setup_fd_epoll(rb_fde_t * F)
+rb_setup_fd_epoll(rb_fde_t *F)
{
return 0;
}
* and deregister interest in a pending IO state for a given FD.
*/
void
-rb_setselect_epoll(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
struct epoll_event ep_event;
int old_flags = F->pflags;
if(num <= 0)
return RB_OK;
- for (i = 0; i < num; i++)
+ for(i = 0; i < num; i++)
{
PF *hdl;
rb_fde_t *F = ep_info->pfd[i].data.ptr;
return RB_OK;
}
-#ifdef EPOLL_SCHED_EVENT
+#ifdef EPOLL_SCHED_EVENT
int
rb_epoll_supports_event(void)
{
struct sigevent ev;
int fd;
sigset_t set;
-
+
if(can_do_event == 1)
return 1;
if(can_do_event == -1)
return 0;
-
+
+#ifdef USE_TIMERFD_CREATE
+ if((fd = timerfd_create(CLOCK_REALTIME, 0)) >= 0)
+ {
+ close(fd);
+ can_do_event = 1;
+ can_do_timerfd = 1;
+ return 0;
+ }
+#endif
+
ev.sigev_signo = SIGVTALRM;
ev.sigev_notify = SIGEV_SIGNAL;
if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0)
timer_delete(timer);
sigemptyset(&set);
fd = signalfd(-1, &set, 0);
- if(fd < 0)
+ if(fd < 0)
{
can_do_event = -1;
return 0;
/* bleh..work around a glibc header bug on 32bit systems */
-struct our_signalfd_siginfo {
- uint32_t signo;
- int32_t err;
- int32_t code;
- uint32_t pid;
- uint32_t uid;
- int32_t fd;
- uint32_t tid;
- uint32_t band;
- uint32_t overrun;
- uint32_t trapno;
- int32_t status;
- int32_t svint;
- uint64_t svptr;
- uint64_t utime;
- uint64_t stime;
- uint64_t addr;
- uint8_t pad[48];
+struct our_signalfd_siginfo
+{
+ uint32_t signo;
+ int32_t err;
+ int32_t code;
+ uint32_t pid;
+ uint32_t uid;
+ int32_t fd;
+ uint32_t tid;
+ uint32_t band;
+ uint32_t overrun;
+ uint32_t trapno;
+ int32_t status;
+ int32_t svint;
+ uint64_t svptr;
+ uint64_t utime;
+ uint64_t stime;
+ uint64_t addr;
+ uint8_t pad[48];
};
#define SIGFDIOV_COUNT 16
-static void
+static void
signalfd_handler(rb_fde_t *F, void *data)
{
static struct our_signalfd_siginfo fdsig[SIGFDIOV_COUNT];
static struct iovec iov[SIGFDIOV_COUNT];
struct ev_entry *ev;
int ret, x;
-
+
for(x = 0; x < SIGFDIOV_COUNT; x++)
{
iov[x].iov_base = &fdsig[x];
rb_epoll_init_event();
return;
}
-
- if(ret < 0)
+
+ if(ret < 0)
{
rb_setselect(F, RB_SELECT_READ, signalfd_handler, NULL);
return;
}
- for(x = 0; x < ret / (int)sizeof(struct signalfd_siginfo); x++)
+ for(x = 0; x < ret / (int)sizeof(struct our_signalfd_siginfo); x++)
{
- ev = (struct ev_entry *)fdsig[x].svptr;
+ ev = (struct ev_entry *)((uintptr_t)fdsig[x].svptr);
if(ev == NULL)
continue;
rb_run_event(ev);
void
rb_epoll_init_event(void)
{
+
sigset_t ss;
rb_fde_t *F;
int sfd;
- sigemptyset(&ss);
- sigaddset(&ss, RTSIGNAL);
- sigprocmask(SIG_BLOCK, &ss, 0);
- sigemptyset(&ss);
- sigaddset(&ss, RTSIGNAL);
- sfd = signalfd(-1, &ss, 0);
- if(sfd == -1) {
- can_do_event = -1;
- return;
+ rb_epoll_supports_event();
+ if(!can_do_timerfd)
+ {
+ sigemptyset(&ss);
+ sigaddset(&ss, RTSIGNAL);
+ sigprocmask(SIG_BLOCK, &ss, 0);
+ sigemptyset(&ss);
+ sigaddset(&ss, RTSIGNAL);
+ sfd = signalfd(-1, &ss, 0);
+ if(sfd == -1)
+ {
+ can_do_event = -1;
+ return;
+ }
+ F = rb_open(sfd, RB_FD_UNKNOWN, "signalfd");
+ rb_set_nb(F);
+ signalfd_handler(F, NULL);
}
- F = rb_open(sfd, RB_FD_UNKNOWN, "signalfd");
- rb_set_nb(F);
- signalfd_handler(F, NULL);
}
-int
-rb_epoll_sched_event(struct ev_entry *event, int when)
+static int
+rb_epoll_sched_event_signalfd(struct ev_entry *event, int when)
{
timer_t *id;
struct sigevent ev;
ev.sigev_signo = RTSIGNAL;
ev.sigev_value.sival_ptr = event;
- if (timer_create(CLOCK_REALTIME, &ev, id) < 0)
+ if(timer_create(CLOCK_REALTIME, &ev, id) < 0)
{
rb_lib_log("timer_create: %s\n", strerror(errno));
return 0;
ts.it_value.tv_nsec = 0;
if(event->frequency != 0)
ts.it_interval = ts.it_value;
-
- if(timer_settime(*id, 0, &ts, NULL) < 0)
+
+ if(timer_settime(*id, 0, &ts, NULL) < 0)
{
rb_lib_log("timer_settime: %s\n", strerror(errno));
return 0;
return 1;
}
+#ifdef USE_TIMERFD_CREATE
+static void
+rb_read_timerfd(rb_fde_t *F, void *data)
+{
+ struct ev_entry *event = (struct ev_entry *)data;
+ int retlen;
+ uint64_t count;
+
+ if(event == NULL)
+ {
+ rb_close(F);
+ return;
+ }
+
+ retlen = rb_read(F, &count, sizeof(count));
+ if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
+ {
+ rb_close(F);
+ rb_lib_log("rb_read_timerfd: timerfd[%s] closed on error: %s", event->name,
+ strerror(errno));
+ return;
+ }
+ rb_setselect(F, RB_SELECT_READ, rb_read_timerfd, event);
+ rb_run_event(event);
+}
+
+
+static int
+rb_epoll_sched_event_timerfd(struct ev_entry *event, int when)
+{
+ struct itimerspec ts;
+ static char buf[FD_DESC_SZ + 8];
+ int fd;
+ rb_fde_t *F;
+
+ if((fd = timerfd_create(CLOCK_REALTIME, 0)) < 0)
+ {
+ rb_lib_log("timerfd_create: %s\n", strerror(errno));
+ return 0;
+ }
+
+ memset(&ts, 0, sizeof(ts));
+ ts.it_value.tv_sec = when;
+ ts.it_value.tv_nsec = 0;
+ if(event->frequency != 0)
+ ts.it_interval = ts.it_value;
+
+ if(timerfd_settime(fd, 0, &ts, NULL) < 0)
+ {
+ rb_lib_log("timerfd_settime: %s\n", strerror(errno));
+ close(fd);
+ return 0;
+ }
+ rb_snprintf(buf, sizeof(buf), "timerfd: %s", event->name);
+ F = rb_open(fd, RB_FD_UNKNOWN, buf);
+ rb_set_nb(F);
+ event->comm_ptr = F;
+ rb_setselect(F, RB_SELECT_READ, rb_read_timerfd, event);
+ return 1;
+}
+#endif
+
+
+
+int
+rb_epoll_sched_event(struct ev_entry *event, int when)
+{
+#ifdef USE_TIMERFD_CREATE
+ if(can_do_timerfd)
+ {
+ return rb_epoll_sched_event_timerfd(event, when);
+ }
+#endif
+ return rb_epoll_sched_event_signalfd(event, when);
+}
+
void
rb_epoll_unsched_event(struct ev_entry *event)
{
- timer_delete(*((timer_t *)event->comm_ptr));
+#ifdef USE_TIMERFD_CREATE
+ if(can_do_timerfd)
+ {
+ rb_close((rb_fde_t *)event->comm_ptr);
+ event->comm_ptr = NULL;
+ return;
+ }
+#endif
+ timer_delete(*((timer_t *) event->comm_ptr));
rb_free(event->comm_ptr);
event->comm_ptr = NULL;
}
}
void
-rb_setselect_epoll(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
errno = ENOSYS;
return;
}
int
-rb_setup_fd_epoll(rb_fde_t * F)
+rb_setup_fd_epoll(rb_fde_t *F)
{
errno = ENOSYS;
return -1;
#endif
#if !defined(USING_EPOLL) || !defined(EPOLL_SCHED_EVENT)
-void rb_epoll_init_event(void)
+void
+rb_epoll_init_event(void)
{
return;
}
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: event.c 25147 2008-03-28 17:15:47Z androsyn $
+ * $Id: event.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
#include <commio-int.h>
#include <event-int.h>
-static const char *last_event_ran = NULL;
+#define EV_NAME_LEN 33
+static char last_event_ran[EV_NAME_LEN];
static rb_dlink_list event_list;
static time_t event_time_min = -1;
-/* The list of event processes */
-
-#if 0
-struct ev_entry
-{
- rb_dlink_node node;
- EVH *func;
- void *arg;
- const char *name;
- time_t frequency;
- time_t when;
- void *data;
-};
-#endif
/*
* struct ev_entry *
struct ev_entry *ev;
ev = rb_malloc(sizeof(struct ev_entry));
ev->func = func;
- ev->name = name;
+ ev->name = rb_strndup(name, EV_NAME_LEN);
ev->arg = arg;
ev->when = rb_current_time() + when;
ev->frequency = when;
rb_io_sched_event(ev, when);
return ev;
}
+
struct ev_entry *
rb_event_addonce(const char *name, EVH * func, void *arg, time_t when)
{
struct ev_entry *ev;
ev = rb_malloc(sizeof(struct ev_entry));
ev->func = func;
- ev->name = name;
+ ev->name = rb_strndup(name, EV_NAME_LEN);
ev->arg = arg;
ev->when = rb_current_time() + when;
ev->frequency = 0;
rb_dlinkDelete(&ev->node, &event_list);
rb_io_unsched_event(ev);
+ rb_free(ev->name);
rb_free(ev);
}
* Side Effects: Removes the event from the event list
*/
void
-rb_event_find_delete(EVH *func, void *arg)
+rb_event_find_delete(EVH * func, void *arg)
{
rb_event_delete(rb_event_find(func, arg));
}
void
rb_run_event(struct ev_entry *ev)
{
- last_event_ran = ev->name;
+ rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran));
ev->func(ev->arg);
if(!ev->frequency)
{
{
rb_dlink_node *ptr, *next;
struct ev_entry *ev;
-
+
if(rb_io_supports_event())
return;
ev = ptr->data;
if(ev->when <= rb_current_time())
{
- last_event_ran = ev->name;
+ rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran));
ev->func(ev->arg);
/* event is scheduled more than once */
- if(ev->frequency)
+ if(ev->frequency)
{
ev->when = rb_current_time() + ev->frequency;
if((ev->when < event_time_min) || (event_time_min == -1))
rb_dlinkDelete(&ev->node, &event_list);
rb_free(ev);
}
- } else {
+ }
+ else
+ {
if((ev->when < event_time_min) || (event_time_min == -1))
event_time_min = ev->when;
}
int when;
if(!rb_io_supports_event())
return;
-
+
RB_DLINK_FOREACH(ptr, event_list.head)
- {
+ {
ev = ptr->data;
when = ev->when - rb_current_time();
rb_io_sched_event(ev, when);
}
}
+
/*
* void rb_event_init(void)
*
void
rb_event_init(void)
{
- last_event_ran = NULL;
+ rb_strlcpy(last_event_ran, "NONE", sizeof(last_event_ran));
}
void
rb_dlink_node *dptr;
struct ev_entry *ev;
len = sizeof(buf);
- if(last_event_ran)
- {
- rb_snprintf(buf, len, "Last event to run: %s", last_event_ran);
- func(buf, ptr);
- }
+
+ rb_snprintf(buf, len, "Last event to run: %s", last_event_ran);
+ func(buf, ptr);
+
rb_strlcpy(buf, "Operation Next Execution", len);
func(buf, ptr);
{
ev = dptr->data;
rb_snprintf(buf, len, "%-28s %-4ld seconds", ev->name,
- ev->when - (long) rb_current_time());
+ ev->when - (long)rb_current_time());
func(buf, ptr);
}
}
rb_ssl_handshake_count
rb_ssl_clear_handshake_count
rb_get_pseudo_random
+rb_strerror
+rb_kill
+rb_setenv
+rb_getpid
+rb_waitpid
+rb_basename
+rb_dirname
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: gnutls.c 25793 2008-07-29 14:47:48Z androsyn $
+ * $Id: gnutls.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
#define SSL_P(x) *((gnutls_session_t *)F->ssl)
void
-rb_ssl_shutdown(rb_fde_t * F)
+rb_ssl_shutdown(rb_fde_t *F)
{
int i;
if(F == NULL || F->ssl == NULL)
return;
- for (i = 0; i < 4; i++)
+ for(i = 0; i < 4; i++)
{
if(gnutls_bye(SSL_P(F), GNUTLS_SHUT_RDWR) == GNUTLS_E_SUCCESS)
break;
}
static void
-rb_ssl_timeout(rb_fde_t * F, void *notused)
+rb_ssl_timeout(rb_fde_t *F, void *notused)
{
lrb_assert(F->accept != NULL);
F->accept->callback(F, RB_ERR_TIMEOUT, NULL, 0, F->accept->data);
}
-static int do_ssl_handshake(rb_fde_t *F, PF *callback)
+static int
+do_ssl_handshake(rb_fde_t *F, PF * callback)
{
int ret;
- int flags;
+ int flags;
ret = gnutls_handshake(SSL_P(F));
if(ret < 0)
flags = RB_SELECT_READ;
else
flags = RB_SELECT_WRITE;
- rb_setselect(F, flags, callback, NULL);
+ rb_setselect(F, flags, callback, NULL);
return 0;
}
F->ssl_errno = ret;
return -1;
- }
- return 1; /* handshake is finished..go about life */
+ }
+ return 1; /* handshake is finished..go about life */
}
static void
-rb_ssl_tryaccept(rb_fde_t * F, void *data)
+rb_ssl_tryaccept(rb_fde_t *F, void *data)
{
int ret;
struct acceptdata *ad;
lrb_assert(F->accept != NULL);
ret = do_ssl_handshake(F, rb_ssl_tryaccept);
-
- switch(ret)
+
+ switch (ret)
{
- case -1:
- F->accept->callback(F, RB_ERROR_SSL, NULL, 0, F->accept->data);
- break;
- case 0:
- /* do_ssl_handshake does the rb_setselect stuff */
- return;
- default:
- break;
-
-
+ case -1:
+ F->accept->callback(F, RB_ERROR_SSL, NULL, 0, F->accept->data);
+ break;
+ case 0:
+ /* do_ssl_handshake does the rb_setselect stuff */
+ return;
+ default:
+ break;
+
+
}
rb_settimeout(F, 0, NULL, NULL);
rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, NULL, NULL);
-
+
ad = F->accept;
F->accept = NULL;
- ad->callback(F, RB_OK, (struct sockaddr *) &ad->S, ad->addrlen,
- ad->data);
+ ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data);
rb_free(ad);
}
void
-rb_ssl_start_accepted(rb_fde_t * new_F, ACCB * cb, void *data, int timeout)
+rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout)
{
gnutls_session_t *ssl;
new_F->type |= RB_FD_SSL;
ssl = new_F->ssl = rb_malloc(sizeof(gnutls_session_t));
new_F->accept = rb_malloc(sizeof(struct acceptdata));
-
+
new_F->accept->callback = cb;
new_F->accept->data = data;
rb_settimeout(new_F, timeout, rb_ssl_timeout, NULL);
new_F->accept->addrlen = 0;
- gnutls_init(ssl, GNUTLS_SERVER);
+ gnutls_init(ssl, GNUTLS_SERVER);
gnutls_set_default_priority(*ssl);
gnutls_credentials_set(*ssl, GNUTLS_CRD_CERTIFICATE, x509);
gnutls_dh_set_prime_bits(*ssl, 1024);
{
struct acceptdata *ad = new_F->accept;
new_F->accept = NULL;
- ad->callback(new_F, RB_OK, (struct sockaddr *) &ad->S, ad->addrlen, ad->data);
- rb_free(ad);
+ ad->callback(new_F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data);
+ rb_free(ad);
}
}
void
-rb_ssl_accept_setup(rb_fde_t * F, rb_fde_t *new_F, struct sockaddr *st, int addrlen)
+rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen)
{
new_F->type |= RB_FD_SSL;
new_F->ssl = rb_malloc(sizeof(gnutls_session_t));
memcpy(&new_F->accept->S, st, addrlen);
new_F->accept->addrlen = addrlen;
- gnutls_init((gnutls_session_t *)new_F->ssl, GNUTLS_SERVER);
+ gnutls_init((gnutls_session_t *) new_F->ssl, GNUTLS_SERVER);
gnutls_set_default_priority(SSL_P(new_F));
gnutls_credentials_set(SSL_P(new_F), GNUTLS_CRD_CERTIFICATE, x509);
gnutls_dh_set_prime_bits(SSL_P(new_F), 1024);
{
struct acceptdata *ad = F->accept;
F->accept = NULL;
- ad->callback(F, RB_OK, (struct sockaddr *) &ad->S, ad->addrlen, ad->data);
- rb_free(ad);
+ ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data);
+ rb_free(ad);
}
}
static ssize_t
-rb_ssl_read_or_write(int r_or_w, rb_fde_t * F, void *rbuf, const void *wbuf, size_t count)
+rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size_t count)
{
ssize_t ret;
gnutls_session_t *ssl = F->ssl;
if(ret < 0)
{
- switch(ret)
+ switch (ret)
{
case GNUTLS_E_AGAIN:
case GNUTLS_E_INTERRUPTED:
}
ssize_t
-rb_ssl_read(rb_fde_t * F, void *buf, size_t count)
+rb_ssl_read(rb_fde_t *F, void *buf, size_t count)
{
return rb_ssl_read_or_write(0, F, buf, NULL, count);
}
ssize_t
-rb_ssl_write(rb_fde_t * F, const void *buf, size_t count)
+rb_ssl_write(rb_fde_t *F, const void *buf, size_t count)
{
return rb_ssl_read_or_write(1, F, NULL, buf, count);
}
rb_init_ssl(void)
{
gnutls_global_init();
-
+
if(gnutls_certificate_allocate_credentials(&x509) != GNUTLS_E_SUCCESS)
{
rb_lib_log("rb_init_ssl: Unable to allocate SSL/TLS certificate credentials");
}
static void
-rb_free_datum_t(gnutls_datum_t *d)
+rb_free_datum_t(gnutls_datum_t * d)
{
rb_free(d->data);
rb_free(d);
datum = rb_malloc(sizeof(gnutls_datum_t));
- if(fileinfo.st_size > 131072) /* deal with retards */
+ if(fileinfo.st_size > 131072) /* deal with retards */
datum->size = 131072;
else
- datum->size = fileinfo.st_size;
-
+ datum->size = fileinfo.st_size;
+
datum->data = rb_malloc(datum->size + 1);
fread(datum->data, datum->size, 1, f);
fclose(f);
- return datum;
+ return datum;
}
int
rb_lib_log("rb_setup_ssl_server: Error loading key: %s", strerror(errno));
return 0;
}
-
-
- if((ret = gnutls_certificate_set_x509_key_mem(x509, d_cert, d_key, GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS)
+
+
+ if((ret =
+ gnutls_certificate_set_x509_key_mem(x509, d_cert, d_key,
+ GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS)
{
- rb_lib_log("rb_setup_ssl_server: Error loading certificate or key file: %s", gnutls_strerror(ret));
+ rb_lib_log("rb_setup_ssl_server: Error loading certificate or key file: %s",
+ gnutls_strerror(ret));
return 0;
}
rb_free_datum_t(d_cert);
rb_free_datum_t(d_key);
-
+
if(dhfile != NULL)
{
if(gnutls_dh_params_init(&dh_params) == GNUTLS_E_SUCCESS)
data = rb_load_file_into_datum_t(dhfile);
if(data != NULL)
{
- xret = gnutls_dh_params_import_pkcs3(dh_params, data, GNUTLS_X509_FMT_PEM);
+ xret = gnutls_dh_params_import_pkcs3(dh_params, data,
+ GNUTLS_X509_FMT_PEM);
if(xret < 0)
- rb_lib_log("rb_setup_ssl_server: Error parsing DH file: %s\n", gnutls_strerror(xret));
+ rb_lib_log
+ ("rb_setup_ssl_server: Error parsing DH file: %s\n",
+ gnutls_strerror(xret));
rb_free_datum_t(data);
}
gnutls_certificate_set_dh_params(x509, dh_params);
- } else
+ }
+ else
rb_lib_log("rb_setup_ssl_server: Unable to setup DH parameters");
}
return 1;
}
int
-rb_ssl_listen(rb_fde_t * F, int backlog)
+rb_ssl_listen(rb_fde_t *F, int backlog)
{
F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL;
return listen(F->fd, backlog);
};
static void
-rb_ssl_connect_realcb(rb_fde_t * F, int status, struct ssl_connect *sconn)
+rb_ssl_connect_realcb(rb_fde_t *F, int status, struct ssl_connect *sconn)
{
F->connect->callback = sconn->callback;
F->connect->data = sconn->data;
}
static void
-rb_ssl_tryconn_timeout_cb(rb_fde_t * F, void *data)
+rb_ssl_tryconn_timeout_cb(rb_fde_t *F, void *data)
{
rb_ssl_connect_realcb(F, RB_ERR_TIMEOUT, data);
}
static void
-rb_ssl_tryconn_cb(rb_fde_t * F, void *data)
+rb_ssl_tryconn_cb(rb_fde_t *F, void *data)
{
struct ssl_connect *sconn = data;
int ret;
- ret = do_ssl_handshake(F, rb_ssl_tryconn_cb);
-
- switch(ret)
- {
- case -1:
- rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn);
- break;
- case 0:
- /* do_ssl_handshake does the rb_setselect stuff */
- return;
- default:
- break;
-
-
- }
+ ret = do_ssl_handshake(F, rb_ssl_tryconn_cb);
+
+ switch (ret)
+ {
+ case -1:
+ rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn);
+ break;
+ case 0:
+ /* do_ssl_handshake does the rb_setselect stuff */
+ return;
+ default:
+ break;
+
+
+ }
rb_ssl_connect_realcb(F, RB_OK, sconn);
}
static void
-rb_ssl_tryconn(rb_fde_t * F, int status, void *data)
+rb_ssl_tryconn(rb_fde_t *F, int status, void *data)
{
struct ssl_connect *sconn = data;
if(status != RB_OK)
F->type |= RB_FD_SSL;
-
+
rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn);
F->ssl = rb_malloc(sizeof(gnutls_session_t));
- gnutls_init(F->ssl, GNUTLS_CLIENT);
- gnutls_set_default_priority(SSL_P(F));
+ gnutls_init(F->ssl, GNUTLS_CLIENT);
+ gnutls_set_default_priority(SSL_P(F));
gnutls_dh_set_prime_bits(SSL_P(F), 1024);
gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd);
}
void
-rb_connect_tcp_ssl(rb_fde_t * F, struct sockaddr *dest,
+rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest,
struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout)
{
struct ssl_connect *sconn;
}
void
-rb_ssl_start_connected(rb_fde_t * F, CNCB * callback, void *data, int timeout)
+rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout)
{
struct ssl_connect *sconn;
if(F == NULL)
F->connect->data = data;
F->type |= RB_FD_SSL;
F->ssl = rb_malloc(sizeof(gnutls_session_t));
-
- gnutls_init(F->ssl, GNUTLS_CLIENT);
- gnutls_set_default_priority(SSL_P(F));
+
+ gnutls_init(F->ssl, GNUTLS_CLIENT);
+ gnutls_set_default_priority(SSL_P(F));
gnutls_dh_set_prime_bits(SSL_P(F), 1024);
gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd);
-
+
rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn);
if(do_ssl_handshake(F, rb_ssl_tryconn_cb))
}
const char *
-rb_get_ssl_strerror(rb_fde_t * F)
+rb_get_ssl_strerror(rb_fde_t *F)
{
return gnutls_strerror(F->ssl_errno);
}
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: helper.c 25245 2008-04-21 18:38:23Z androsyn $
+ * $Id: helper.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
#include <ratbox_lib.h>
/* setup all the stuff a new child needs */
rb_helper *
-rb_helper_child(rb_helper_cb *read_cb, rb_helper_cb *error_cb, log_cb *ilog, restart_cb *irestart, die_cb *idie,
- int maxcon, size_t lb_heap_size, size_t dh_size, size_t fd_heap_size)
+rb_helper_child(rb_helper_cb * read_cb, rb_helper_cb * error_cb, log_cb * ilog,
+ restart_cb * irestart, die_cb * idie, int maxcon, size_t lb_heap_size,
+ size_t dh_size, size_t fd_heap_size)
{
rb_helper *helper;
int maxfd, x = 0;
int ifd, ofd;
char *tifd, *tofd, *tmaxfd;
-
+
tifd = getenv("IFD");
tofd = getenv("OFD");
tmaxfd = getenv("MAXFD");
-
+
if(tifd == NULL || tofd == NULL || tmaxfd == NULL)
return NULL;
helper = rb_malloc(sizeof(rb_helper));
- ifd = (int)strtol(tifd, NULL, 10);
+ ifd = (int)strtol(tifd, NULL, 10);
ofd = (int)strtol(tofd, NULL, 10);
maxfd = (int)strtol(tmaxfd, NULL, 10);
-#ifndef WIN32
- for(x = 0; x < maxfd; x++)
- {
- if(x != ifd && x != ofd)
- close(x);
+#ifndef _WIN32
+ for(x = 0; x < maxfd; x++)
+ {
+ if(x != ifd && x != ofd)
+ close(x);
}
x = open("/dev/null", O_RDWR);
if(ifd != 0 && ofd != 0)
dup2(x, 1);
if(ifd != 2 && ofd != 2)
dup2(x, 2);
- if(x > 2) /* don't undo what we just did */
+ if(x > 2) /* don't undo what we just did */
close(x);
#else
- x = 0; /* shut gcc up */
+ x = 0; /* shut gcc up */
#endif
rb_lib_init(ilog, irestart, idie, 0, maxfd, dh_size, fd_heap_size);
helper->ofd = rb_open(ofd, RB_FD_PIPE, "outgoing connection");
rb_set_nb(helper->ifd);
rb_set_nb(helper->ofd);
-
+
helper->read_cb = read_cb;
helper->error_cb = error_cb;
return helper;
*/
rb_helper *
-rb_helper_start(const char *name, const char *fullpath, rb_helper_cb *read_cb, rb_helper_cb *error_cb)
+rb_helper_start(const char *name, const char *fullpath, rb_helper_cb * read_cb,
+ rb_helper_cb * error_cb)
{
rb_helper *helper;
const char *parv[2];
rb_fde_t *in_f[2];
rb_fde_t *out_f[2];
pid_t pid;
-
+
if(access(fullpath, X_OK) == -1)
return NULL;
-
+
helper = rb_malloc(sizeof(rb_helper));
rb_snprintf(buf, sizeof(buf), "%s helper - read", name);
- if(rb_pipe(&in_f[0], &in_f[1], buf) < 0)
+ if(rb_pipe(&in_f[0], &in_f[1], buf) < 0)
{
rb_free(helper);
return NULL;
rb_free(helper);
return NULL;
}
-
+
rb_snprintf(fx, sizeof(fx), "%d", rb_get_fd(in_f[1]));
rb_snprintf(fy, sizeof(fy), "%d", rb_get_fd(out_f[0]));
-
+
rb_set_nb(in_f[0]);
rb_set_nb(in_f[1]);
rb_set_nb(out_f[0]);
rb_set_nb(out_f[1]);
-
- setenv("IFD", fy, 1);
- setenv("OFD", fx, 1);
- setenv("MAXFD", "256", 1);
-
+
+ rb_setenv("IFD", fy, 1);
+ rb_setenv("OFD", fx, 1);
+ rb_setenv("MAXFD", "256", 1);
+
rb_snprintf(buf, sizeof(buf), "-ircd %s daemon", name);
parv[0] = buf;
parv[1] = NULL;
-#ifdef WIN32
- SetHandleInformation((HANDLE)rb_get_fd(in_f[1]), HANDLE_FLAG_INHERIT, 1);
- SetHandleInformation((HANDLE)rb_get_fd(out_f[0]), HANDLE_FLAG_INHERIT, 1);
+#ifdef _WIN32
+ SetHandleInformation((HANDLE) rb_get_fd(in_f[1]), HANDLE_FLAG_INHERIT, 1);
+ SetHandleInformation((HANDLE) rb_get_fd(out_f[0]), HANDLE_FLAG_INHERIT, 1);
#endif
-
+
pid = rb_spawn_process(fullpath, (const char **)parv);
-
+
if(pid == -1)
{
rb_close(in_f[0]);
rb_close(in_f[1]);
rb_close(out_f[0]);
-
+
rb_linebuf_newbuf(&helper->sendq);
rb_linebuf_newbuf(&helper->recvq);
-
+
helper->ifd = in_f[0];
helper->ofd = out_f[1];
helper->read_cb = read_cb;
- helper->error_cb = error_cb;
+ helper->error_cb = error_cb;
helper->fork_count = 0;
helper->pid = pid;
{
rb_helper *helper = helper_ptr;
int retlen;
-
+
if(rb_linebuf_len(&helper->sendq) > 0)
{
while((retlen = rb_linebuf_flush(F, &helper->sendq)) > 0)
;;
- if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) {
+ if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
+ {
rb_helper_restart(helper);
return;
}
rb_setselect(helper->ofd, RB_SELECT_WRITE, rb_helper_write_sendq, helper);
}
-void
+void
rb_helper_write_queue(rb_helper *helper, const char *format, ...)
{
va_list ap;
void
rb_helper_write_flush(rb_helper *helper)
{
- rb_helper_write_sendq(helper->ofd, helper);
+ rb_helper_write_sendq(helper->ofd, helper);
}
int length;
if(helper == NULL)
return;
-
+
while((length = rb_read(helper->ifd, buf, sizeof(buf))) > 0)
{
rb_linebuf_parse(&helper->recvq, buf, length, 0);
rb_helper_restart(helper);
return;
}
-
+
rb_setselect(helper->ifd, RB_SELECT_READ, rb_helper_read_cb, helper);
}
{
if(helper == NULL)
return;
- kill(helper->pid, SIGKILL);
+ rb_kill(helper->pid, SIGKILL);
rb_close(helper->ifd);
rb_close(helper->ofd);
- rb_free(helper);
+ rb_free(helper);
}
int
rb_lib_loop(delay);
}
}
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: kqueue.c 25364 2008-05-14 17:55:22Z jilles $
+ * $Id: kqueue.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
int
-rb_setup_fd_kqueue(rb_fde_t * F)
+rb_setup_fd_kqueue(rb_fde_t *F)
{
return 0;
}
static void
-kq_update_events(rb_fde_t * F, short filter, PF * handler)
+kq_update_events(rb_fde_t *F, short filter, PF * handler)
{
PF *cur_handler;
int kep_flags;
kep_flags = EV_DELETE;
}
- EV_SET(kep, (uintptr_t) F->fd, filter, kep_flags, 0, 0, (void *) F);
+ EV_SET(kep, (uintptr_t)F->fd, filter, kep_flags, 0, 0, (void *)F);
if(++kqoff == kqmax)
{
* because that would also return events we cannot
* process at this point.
*/
- for (i = 0; i < kqoff; i++)
+ for(i = 0; i < kqoff; i++)
{
ret = kevent(kq, kqlst + i, 1, NULL, 0, &zero_timespec);
/* jdc -- someone needs to do error checking... */
/* EBADF is normal here -- jilles */
if(ret == -1 && errno != EBADF)
- rb_lib_log("kq_update_events(): kevent(): %s", strerror(errno));
+ rb_lib_log("kq_update_events(): kevent(): %s",
+ strerror(errno));
}
kqoff = 0;
}
* and deregister interest in a pending IO state for a given FD.
*/
void
-rb_setselect_kqueue(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_kqueue(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
lrb_assert(IsFDOpen(F));
rb_fde_t *F;
- if(delay < 0) {
+ if(delay < 0)
+ {
pt = NULL;
}
- else {
+ else
+ {
pt = &poll_time;
poll_time.tv_sec = delay / 1000;
poll_time.tv_nsec = (delay % 1000) * 1000000;
}
- for (;;)
+ for(;;)
{
num = kevent(kq, kqlst, kqoff, kqout, kqmax, pt);
kqoff = 0;
if(num == 0)
return RB_OK; /* No error.. */
- for (i = 0; i < num; i++)
+ for(i = 0; i < num; i++)
{
PF *hdl = NULL;
ts.tv_nsec = 1000;
- EV_SET(&kv, (uintptr_t) 0x0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 1, 0);
+ EV_SET(&kv, (uintptr_t)0x0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 1, 0);
if(kevent(xkq, &kv, 1, NULL, 0, NULL) < 0)
{
can_do_event = -1;
kep_flags = EV_ADD;
if(event->frequency == 0)
kep_flags |= EV_ONESHOT;
- EV_SET(&kev, (uintptr_t) event, EVFILT_TIMER, kep_flags, 0, when * 1000, event);
+ EV_SET(&kev, (uintptr_t)event, EVFILT_TIMER, kep_flags, 0, when * 1000, event);
if(kevent(kq, &kev, 1, NULL, 0, NULL) < 0)
- return 0;
+ return 0;
return 1;
}
rb_kqueue_unsched_event(struct ev_entry *event)
{
struct kevent kev;
- EV_SET(&kev, (uintptr_t) event, EVFILT_TIMER, EV_DELETE, 0, 0, event);
+ EV_SET(&kev, (uintptr_t)event, EVFILT_TIMER, EV_DELETE, 0, 0, event);
kevent(kq, &kev, 1, NULL, 0, NULL);
}
}
void
-rb_setselect_kqueue(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_kqueue(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
errno = ENOSYS;
return;
}
int
-rb_setup_fd_kqueue(rb_fde_t * F)
+rb_setup_fd_kqueue(rb_fde_t *F)
{
errno = ENOSYS;
return -1;
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: linebuf.c 25375 2008-05-16 15:19:51Z androsyn $
+ * $Id: linebuf.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
void
rb_linebuf_init(size_t heap_size)
{
-#ifndef NOBALLOC
rb_linebuf_heap = rb_bh_create(sizeof(buf_line_t), heap_size, "librb_linebuf_heap");
-#endif
}
static buf_line_t *
rb_linebuf_allocate(void)
{
buf_line_t *t;
-#ifndef NOBALLOC
t = rb_bh_alloc(rb_linebuf_heap);
-#else
- t = rb_malloc(sizeof(buf_line_t));
-#endif
return (t);
}
static void
rb_linebuf_free(buf_line_t * p)
{
-#ifndef NOBALLOC
rb_bh_free(rb_linebuf_heap, p);
-#else
- rb_free(p);
-#endif
}
/*
* We've finished with the given line, so deallocate it
*/
static void
-rb_linebuf_done_line(buf_head_t * bufhead, buf_line_t * bufline, rb_dlink_node * node)
+rb_linebuf_done_line(buf_head_t * bufhead, buf_line_t * bufline, rb_dlink_node *node)
{
/* Remove it from the linked list */
rb_dlinkDestroy(node, &bufhead->list);
{
while(bufhead->list.head != NULL)
{
- rb_linebuf_done_line(bufhead, (buf_line_t *) bufhead->list.head->data, bufhead->list.head);
+ rb_linebuf_done_line(bufhead, (buf_line_t *) bufhead->list.head->data,
+ bufhead->list.head);
}
}
* Then format/va_args is appended to the buffer.
*/
void
-rb_linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args, const char *prefixfmt, ...)
+rb_linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args,
+ const char *prefixfmt, ...)
{
buf_line_t *bufline;
int len = 0;
else
{
/* Chop trailing CRLF's .. */
- while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') || (bufline->buf[len] == '\0'))
+ while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
+ || (bufline->buf[len] == '\0'))
{
len--;
}
}
void
-rb_linebuf_putbuf(buf_head_t *bufhead, const char *buffer)
+rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer)
{
buf_line_t *bufline;
int len = 0;
else
{
/* Chop trailing CRLF's .. */
- while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') || (bufline->buf[len] == '\0'))
+ while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
+ || (bufline->buf[len] == '\0'))
{
len--;
}
bufline->len = len;
bufhead->len += len;
-
+
}
void
else
{
/* Chop trailing CRLF's .. */
- while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') || (bufline->buf[len] == '\0'))
+ while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
+ || (bufline->buf[len] == '\0'))
{
len--;
}
}
ptr = bufhead->list.head;
-
+
bufline = ptr->data;
if(!bufline->terminated)
{
bufline = ptr->data;
if(!bufline->terminated)
break;
-
+
vec[x].iov_base = bufline->buf;
vec[x].iov_len = bufline->len;
ptr = ptr->next;
- } while(++x < RB_UIO_MAXIOV);
+ }
+ while(++x < RB_UIO_MAXIOV);
if(x == 0)
{
rb_linebuf_done_line(bufhead, bufline, bufhead->list.head);
bufhead->writeofs = 0;
}
- else
+ else
{
bufhead->writeofs += xret;
break;
return retval;
}
-#endif
+#endif
+
+ /* this is the non-writev case */
- /* this is the non-writev case */
-
/* Check we actually have a first buffer */
if(bufhead->list.head == NULL)
{
*/
void
-rb_count_rb_linebuf_memory(size_t * count, size_t * rb_linebuf_memory_used)
+rb_count_rb_linebuf_memory(size_t *count, size_t *rb_linebuf_memory_used)
{
-#ifndef NOBALLOC
rb_bh_usage(rb_linebuf_heap, count, NULL, rb_linebuf_memory_used, NULL);
-#else
- *count = 0;
- *rb_linebuf_memory_used = 0;
-#endif
}
#include <commio-int.h>
#include <commio-ssl.h>
-int
+int
rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
{
errno = ENOSYS;
{
arc4random_stir();
}
-
-int rb_init_prng(const char *path, prng_seed_t seed_type)
+
+int
+rb_init_prng(const char *path, prng_seed_t seed_type)
{
/* xxx this ignores the parameters above */
arc4random_stir();
rb_get_random(void *buf, size_t length)
{
uint32_t rnd = 0, i;
- uint8_t *xbuf = buf;
- for (i = 0; i < sizeof(length); i++)
+ uint8_t *xbuf = buf;
+ for(i = 0; i < length; i++)
{
if(i % 4 == 0)
rnd = arc4random();
int
rb_get_pseudo_random(void *buf, size_t length)
{
- return rb_get_random(buf, length);
+ return rb_get_random(buf, length);
}
return nosupport;
}
-void
-rb_ssl_start_accepted(rb_fde_t *new_F, ACCB *cb, void *data, int timeout)
+void
+rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout)
{
return;
}
-void
-rb_ssl_start_connected(rb_fde_t *F, CNCB *callback, void *data, int timeout)
+void
+rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout)
{
return;
}
void
-rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest,
- struct sockaddr *clocal, int socklen, CNCB *callback, void *data, int timeout)
+rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest,
+ struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout)
{
return;
}
}
void
-rb_ssl_shutdown(rb_fde_t * F)
-{
+rb_ssl_shutdown(rb_fde_t *F)
+{
return;
-}
+}
void
-rb_ssl_accept_setup(rb_fde_t * F, rb_fde_t *new_F, struct sockaddr *st, int addrlen)
+rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen)
{
return;
}
ssize_t
-rb_ssl_read(rb_fde_t * F, void *buf, size_t count)
+rb_ssl_read(rb_fde_t *F, void *buf, size_t count)
{
errno = ENOSYS;
return -1;
}
ssize_t
-rb_ssl_write(rb_fde_t * F, const void *buf, size_t count)
+rb_ssl_write(rb_fde_t *F, const void *buf, size_t count)
{
errno = ENOSYS;
return -1;
{
return 0;
}
-
-void
+
+void
rb_ssl_clear_handshake_count(rb_fde_t *F)
{
return;
}
-
-#endif /* !HAVE_OPENSSL */
+#endif /* !HAVE_OPENSSL */
static SSL_CTX *ssl_client_ctx;
static int libratbox_index = -1;
-static unsigned long get_last_err(void)
+static unsigned long
+get_last_err(void)
{
unsigned long t_err, err = 0;
err = ERR_get_error();
if(err == 0)
return 0;
-
+
while((t_err = ERR_get_error()) > 0)
err = t_err;
}
void
-rb_ssl_shutdown(rb_fde_t * F)
+rb_ssl_shutdown(rb_fde_t *F)
{
int i;
if(F == NULL || F->ssl == NULL)
return;
SSL_set_shutdown((SSL *) F->ssl, SSL_RECEIVED_SHUTDOWN);
- for (i = 0; i < 4; i++)
+ for(i = 0; i < 4; i++)
{
if(SSL_shutdown((SSL *) F->ssl))
break;
}
static void
-rb_ssl_timeout(rb_fde_t * F, void *notused)
+rb_ssl_timeout(rb_fde_t *F, void *notused)
{
lrb_assert(F->accept != NULL);
F->accept->callback(F, RB_ERR_TIMEOUT, NULL, 0, F->accept->data);
}
-static void rb_ssl_info_callback(SSL *ssl, int where, int ret)
+static void
+rb_ssl_info_callback(SSL * ssl, int where, int ret)
{
if(where & SSL_CB_HANDSHAKE_START)
{
if(F == NULL)
return;
F->handshake_count++;
- }
+ }
}
static void
rb_setup_ssl_cb(rb_fde_t *F)
{
SSL_set_ex_data(F->ssl, libratbox_index, (char *)F);
- SSL_set_info_callback((SSL *)F->ssl, (void *)rb_ssl_info_callback);
+ SSL_set_info_callback((SSL *) F->ssl, (void (*)(const SSL *,int,int))rb_ssl_info_callback);
}
static void
-rb_ssl_tryaccept(rb_fde_t * F, void *data)
+rb_ssl_tryaccept(rb_fde_t *F, void *data)
{
int ssl_err;
lrb_assert(F->accept != NULL);
}
rb_settimeout(F, 0, NULL, NULL);
rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, NULL, NULL);
-
+
ad = F->accept;
F->accept = NULL;
- ad->callback(F, RB_OK, (struct sockaddr *) &ad->S, ad->addrlen,
- ad->data);
+ ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data);
rb_free(ad);
}
}
void
-rb_ssl_start_accepted(rb_fde_t * new_F, ACCB * cb, void *data, int timeout)
+rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout)
{
new_F->type |= RB_FD_SSL;
new_F->ssl = SSL_new(ssl_server_ctx);
void
-rb_ssl_accept_setup(rb_fde_t * F, rb_fde_t *new_F, struct sockaddr *st, int addrlen)
+rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrlen)
{
new_F->type |= RB_FD_SSL;
new_F->ssl = SSL_new(ssl_server_ctx);
}
static ssize_t
-rb_ssl_read_or_write(int r_or_w, rb_fde_t * F, void *rbuf, const void *wbuf, size_t count)
+rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size_t count)
{
ssize_t ret;
unsigned long err;
SSL *ssl = F->ssl;
if(r_or_w == 0)
- ret = (ssize_t)SSL_read(ssl, rbuf, (int) count);
+ ret = (ssize_t) SSL_read(ssl, rbuf, (int)count);
else
- ret = (ssize_t)SSL_write(ssl, wbuf, (int) count);
+ ret = (ssize_t) SSL_write(ssl, wbuf, (int)count);
if(ret < 0)
{
}
ssize_t
-rb_ssl_read(rb_fde_t * F, void *buf, size_t count)
+rb_ssl_read(rb_fde_t *F, void *buf, size_t count)
{
return rb_ssl_read_or_write(0, F, buf, NULL, count);
}
ssize_t
-rb_ssl_write(rb_fde_t * F, const void *buf, size_t count)
+rb_ssl_write(rb_fde_t *F, const void *buf, size_t count)
{
return rb_ssl_read_or_write(1, F, NULL, buf, count);
}
}
/* Disable SSLv2, make the client use our settings */
SSL_CTX_set_options(ssl_server_ctx, SSL_OP_NO_SSLv2 | SSL_OP_CIPHER_SERVER_PREFERENCE);
-
+
ssl_client_ctx = SSL_CTX_new(TLSv1_client_method());
if(ssl_client_ctx == NULL)
int
rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
{
- FILE *param;
DH *dh;
unsigned long err;
if(cert == NULL)
if(dhfile != NULL)
{
/* DH parameters aren't necessary, but they are nice..if they didn't pass one..that is their problem */
- param = fopen(dhfile, "r");
- if(param != NULL)
+ BIO *bio = BIO_new_file(dhfile, "r");
+ if(bio != NULL)
{
- dh = PEM_read_DHparams(param, NULL, NULL, NULL);
+ dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
if(dh == NULL)
{
err = ERR_get_error();
rb_lib_log
("rb_setup_ssl_server: Error loading DH params file [%s]: %s",
- param, ERR_error_string(err, NULL));
- fclose(param);
+ dhfile, ERR_error_string(err, NULL));
+ BIO_free(bio);
return 0;
}
+ BIO_free(bio);
SSL_CTX_set_tmp_dh(ssl_server_ctx, dh);
- fclose(param);
+ }
+ else
+ {
+ err = ERR_get_error();
+ rb_lib_log("rb_setup_ssl_server: Error loading DH params file [%s]: %s",
+ dhfile, ERR_error_string(err, NULL));
}
}
return 1;
}
int
-rb_ssl_listen(rb_fde_t * F, int backlog)
+rb_ssl_listen(rb_fde_t *F, int backlog)
{
F->type = RB_FD_SOCKET | RB_FD_LISTEN | RB_FD_SSL;
return listen(F->fd, backlog);
};
static void
-rb_ssl_connect_realcb(rb_fde_t * F, int status, struct ssl_connect *sconn)
+rb_ssl_connect_realcb(rb_fde_t *F, int status, struct ssl_connect *sconn)
{
F->connect->callback = sconn->callback;
F->connect->data = sconn->data;
}
static void
-rb_ssl_tryconn_timeout_cb(rb_fde_t * F, void *data)
+rb_ssl_tryconn_timeout_cb(rb_fde_t *F, void *data)
{
rb_ssl_connect_realcb(F, RB_ERR_TIMEOUT, data);
}
static void
-rb_ssl_tryconn_cb(rb_fde_t * F, void *data)
+rb_ssl_tryconn_cb(rb_fde_t *F, void *data)
{
struct ssl_connect *sconn = data;
int ssl_err;
}
static void
-rb_ssl_tryconn(rb_fde_t * F, int status, void *data)
+rb_ssl_tryconn(rb_fde_t *F, int status, void *data)
{
struct ssl_connect *sconn = data;
int ssl_err;
}
void
-rb_connect_tcp_ssl(rb_fde_t * F, struct sockaddr *dest,
+rb_connect_tcp_ssl(rb_fde_t *F, struct sockaddr *dest,
struct sockaddr *clocal, int socklen, CNCB * callback, void *data, int timeout)
{
struct ssl_connect *sconn;
}
void
-rb_ssl_start_connected(rb_fde_t * F, CNCB * callback, void *data, int timeout)
+rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout)
{
struct ssl_connect *sconn;
int ssl_err;
F->connect->data = data;
F->type |= RB_FD_SSL;
F->ssl = SSL_new(ssl_client_ctx);
-
+
SSL_set_fd((SSL *) F->ssl, F->fd);
rb_setup_ssl_cb(F);
rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn);
{
if(seed_type == RB_PRNG_DEFAULT)
{
-#ifdef WIN32
+#ifdef _WIN32
RAND_screen();
#endif
return RAND_status();
if(RAND_load_file(path, -1) == -1)
return -1;
break;
-#ifdef WIN32
+#ifdef _WIN32
case RB_PRNGWIN32:
RAND_screen();
break;
rb_get_random(void *buf, size_t length)
{
int ret;
-
+
if((ret = RAND_bytes(buf, length)) == 0)
{
/* remove the error from the queue */
- ERR_get_error();
+ ERR_get_error();
}
return ret;
}
}
const char *
-rb_get_ssl_strerror(rb_fde_t * F)
+rb_get_ssl_strerror(rb_fde_t *F)
{
return ERR_error_string(F->ssl_errno, NULL);
}
* #define NOTYET 1
* #define PATRICIA_DEBUG 1
*/
-
+
#define PREFIX_HEAP_COUNT 1024
#define NODE_HEAP_COUNT 1024
#define PATRICIA_HEAP_COUNT 128
* convert prefix information to bytes
*/
static uint8_t *
-prefix_tochar(rb_prefix_t * prefix)
+prefix_tochar(rb_prefix_t *prefix)
{
if(prefix == NULL)
return (NULL);
- return ((uint8_t *) & prefix->add.sin);
+ return ((uint8_t *)&prefix->add.sin);
}
static int
int n = mask / 8;
int m = ((-1) << (8 - (mask % 8)));
- if(mask % 8 == 0 || (((uint8_t *) addr)[n] & m) == (((uint8_t *) dest)[n] & m))
+ if(mask % 8 == 0 || (((uint8_t *)addr)[n] & m) == (((uint8_t *)dest)[n] & m))
return (1);
}
return (0);
}
+
#ifdef NOTYET
static char *
-prefix_toa2x(rb_prefix_t * prefix, char *buf, int buf_len, int with_len)
+prefix_toa2x(rb_prefix_t *prefix, char *buf, int buf_len, int with_len)
{
static char tmp[6];
if(prefix == NULL)
*/
static char *
-prefix_toa2(rb_prefix_t * prefix, char *buff, int buf_len)
+prefix_toa2(rb_prefix_t *prefix, char *buff, int buf_len)
{
return (prefix_toa2x(prefix, buff, buf_len, 0));
}
+
static char *
-prefix_toa(rb_prefix_t * prefix)
+prefix_toa(rb_prefix_t *prefix)
{
#ifdef RB_IPV6
static char buf[INET6_ADDRSTRLEN + 6];
}
#endif
static rb_prefix_t *
-New_Prefix2(int family, void *dest, int bitlen, rb_prefix_t * prefix)
+New_Prefix2(int family, void *dest, int bitlen, rb_prefix_t *prefix)
{
int dynamic_allocated = 0;
#ifdef RB_IPV6
{
if(prefix == NULL)
{
- prefix = rb_malloc(sizeof(rb_prefix_t));
+ prefix = rb_malloc(sizeof(rb_prefix_t));
dynamic_allocated++;
}
memcpy(&prefix->add.sin, dest, 4);
}
static rb_prefix_t *
-Ref_Prefix(rb_prefix_t * prefix)
+Ref_Prefix(rb_prefix_t *prefix)
{
if(prefix == NULL)
return (NULL);
}
static void
-Deref_Prefix(rb_prefix_t * prefix)
+Deref_Prefix(rb_prefix_t *prefix)
{
if(prefix == NULL)
return;
*/
void
-rb_clear_patricia(rb_patricia_tree_t * patricia, void (*func)(void *))
+rb_clear_patricia(rb_patricia_tree_t *patricia, void (*func) (void *))
{
assert(patricia);
if(patricia->head)
rb_patricia_node_t **Xsp = Xstack;
rb_patricia_node_t *Xrn = patricia->head;
- while (Xrn)
+ while(Xrn)
{
rb_patricia_node_t *l = Xrn->l;
rb_patricia_node_t *r = Xrn->r;
}
else
{
- Xrn = (rb_patricia_node_t *) 0;
+ Xrn = (rb_patricia_node_t *)0;
}
}
}
void
-rb_destroy_patricia(rb_patricia_tree_t * patricia, void (*func)(void *))
+rb_destroy_patricia(rb_patricia_tree_t *patricia, void (*func) (void *))
{
rb_clear_patricia(patricia, func);
num_active_patricia--;
*/
void
-rb_patricia_process(rb_patricia_tree_t * patricia, void (*func)(rb_prefix_t *, void *))
+rb_patricia_process(rb_patricia_tree_t *patricia, void (*func) (rb_prefix_t *, void *))
{
rb_patricia_node_t *node;
assert(func);
}
rb_patricia_node_t *
-rb_patricia_search_exact(rb_patricia_tree_t * patricia, rb_prefix_t * prefix)
+rb_patricia_search_exact(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
{
rb_patricia_node_t *node;
uint8_t *addr;
addr = rb_prefix_touchar(prefix);
bitlen = prefix->bitlen;
- while (node->bit < bitlen)
+ while(node->bit < bitlen)
{
if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07)))
/* if inclusive != 0, "best" may be the given prefix itself */
rb_patricia_node_t *
-rb_patricia_search_best2(rb_patricia_tree_t * patricia, rb_prefix_t * prefix, int inclusive)
+rb_patricia_search_best2(rb_patricia_tree_t *patricia, rb_prefix_t *prefix, int inclusive)
{
rb_patricia_node_t *node;
rb_patricia_node_t *stack[RB_PATRICIA_MAXBITS + 1];
addr = rb_prefix_touchar(prefix);
bitlen = prefix->bitlen;
- while (node->bit < bitlen)
+ while(node->bit < bitlen)
{
if(node->prefix)
if(cnt <= 0)
return (NULL);
- while (--cnt >= 0)
+ while(--cnt >= 0)
{
node = stack[cnt];
#ifdef PATRICIA_DEBUG
rb_patricia_node_t *
-rb_patricia_search_best(rb_patricia_tree_t * patricia, rb_prefix_t * prefix)
+rb_patricia_search_best(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
{
return (rb_patricia_search_best2(patricia, prefix, 1));
}
rb_patricia_node_t *
-rb_patricia_lookup(rb_patricia_tree_t * patricia, rb_prefix_t * prefix)
+rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
{
rb_patricia_node_t *node, *new_node, *parent, *glue;
uint8_t *addr, *test_addr;
if(patricia->head == NULL)
{
- node = rb_malloc(sizeof(rb_patricia_node_t));
+ node = rb_malloc(sizeof(rb_patricia_node_t));
node->bit = prefix->bitlen;
node->prefix = Ref_Prefix(prefix);
node->parent = NULL;
bitlen = prefix->bitlen;
node = patricia->head;
- while (node->bit < bitlen || node->prefix == NULL)
+ while(node->bit < bitlen || node->prefix == NULL)
{
if(node->bit < patricia->maxbits &&
/* find the first bit different */
check_bit = (node->bit < bitlen) ? node->bit : bitlen;
differ_bit = 0;
- for (i = 0; i * 8 < check_bit; i++)
+ for(i = 0; i * 8 < check_bit; i++)
{
if((r = (addr[i] ^ test_addr[i])) == 0)
{
continue;
}
/* I know the better way, but for now */
- for (j = 0; j < 8; j++)
+ for(j = 0; j < 8; j++)
{
if(BIT_TEST(r, (0x80 >> j)))
break;
#endif /* PATRICIA_DEBUG */
parent = node->parent;
- while (parent && parent->bit >= differ_bit)
+ while(parent && parent->bit >= differ_bit)
{
node = parent;
parent = node->parent;
return (node);
}
- new_node = rb_malloc(sizeof(rb_patricia_node_t));
+ new_node = rb_malloc(sizeof(rb_patricia_node_t));
new_node->bit = prefix->bitlen;
new_node->prefix = Ref_Prefix(prefix);
new_node->parent = NULL;
void
-rb_patricia_remove(rb_patricia_tree_t * patricia, rb_patricia_node_t * node)
+rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node)
{
rb_patricia_node_t *parent, *child;
}
rb_patricia_node_t *
-make_and_lookup_ip(rb_patricia_tree_t * tree, struct sockaddr *in, int bitlen)
+make_and_lookup_ip(rb_patricia_tree_t *tree, struct sockaddr *in, int bitlen)
{
rb_prefix_t *prefix;
rb_patricia_node_t *node;
void *ipptr = NULL;
#ifdef RB_IPV6
if(in->sa_family == AF_INET6)
- ipptr = &((struct sockaddr_in6 *)in)->sin6_addr;
- else
+ ipptr = &((struct sockaddr_in6 *)in)->sin6_addr;
+ else
#endif
ipptr = &((struct sockaddr_in *)in)->sin_addr;
-
+
prefix = New_Prefix(in->sa_family, ipptr, bitlen);
if(prefix == NULL)
rb_patricia_node_t *
-make_and_lookup(rb_patricia_tree_t * tree, const char *string)
+make_and_lookup(rb_patricia_tree_t *tree, const char *string)
{
rb_prefix_t *prefix;
rb_patricia_node_t *node;
#ifdef NOTYET
static rb_patricia_node_t *
-try_search_exact(rb_patricia_tree_t * tree, char *string)
+try_search_exact(rb_patricia_tree_t *tree, char *string)
{
rb_prefix_t *prefix;
rb_patricia_node_t *node;
}
void
-lookup_then_remove(rb_patricia_tree_t * tree, char *string)
+lookup_then_remove(rb_patricia_tree_t *tree, char *string)
{
rb_patricia_node_t *node;
#endif
rb_patricia_node_t *
-rb_match_ip(rb_patricia_tree_t * tree, struct sockaddr *ip)
+rb_match_ip(rb_patricia_tree_t *tree, struct sockaddr *ip)
{
rb_prefix_t *prefix;
rb_patricia_node_t *node;
len = 128;
family = AF_INET6;
ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr;
- } else {
+ }
+ else
+ {
len = 32;
family = AF_INET;
ipptr = &((struct sockaddr_in *)ip)->sin_addr;
}
#endif
-
+
if((prefix = New_Prefix(family, ipptr, len)) != NULL)
{
node = rb_patricia_search_best(tree, prefix);
}
rb_patricia_node_t *
-rb_match_ip_exact(rb_patricia_tree_t * tree, struct sockaddr *ip, unsigned int len)
+rb_match_ip_exact(rb_patricia_tree_t *tree, struct sockaddr *ip, unsigned int len)
{
rb_prefix_t *prefix;
rb_patricia_node_t *node;
len = 128;
family = AF_INET6;
ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr;
- } else {
+ }
+ else
+ {
if(len > 32)
len = 32;
family = AF_INET;
ipptr = &((struct sockaddr_in *)ip)->sin_addr;
}
#endif
-
+
if((prefix = New_Prefix(family, ipptr, len)) != NULL)
{
node = rb_patricia_search_exact(tree, prefix);
rb_patricia_node_t *
-rb_match_string(rb_patricia_tree_t * tree, const char *string)
+rb_match_string(rb_patricia_tree_t *tree, const char *string)
{
rb_patricia_node_t *node;
rb_prefix_t *prefix;
}
rb_patricia_node_t *
-rb_match_exact_string(rb_patricia_tree_t * tree, const char *string)
+rb_match_exact_string(rb_patricia_tree_t *tree, const char *string)
{
rb_prefix_t *prefix;
rb_patricia_node_t *node;
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: poll.c 25375 2008-05-16 15:19:51Z androsyn $
+ * $Id: poll.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
#include <ratbox_lib.h>
static pollfd_list_t pollfd_list;
int
-rb_setup_fd_poll(rb_fde_t * F)
+rb_setup_fd_poll(rb_fde_t *F)
{
return 0;
}
int fd;
pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd)));
pollfd_list.allocated = rb_getmaxconnect();
- for (fd = 0; fd < rb_getmaxconnect(); fd++)
+ for(fd = 0; fd < rb_getmaxconnect(); fd++)
{
pollfd_list.pollfds[fd].fd = -1;
}
rb_realloc(pollfd_list.pollfds,
pollfd_list.allocated * (sizeof(struct pollfd)));
memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024);
- for (x = old_value + 1; x < pollfd_list.allocated; x++)
+ for(x = old_value + 1; x < pollfd_list.allocated; x++)
{
pollfd_list.pollfds[x].fd = -1;
}
* and deregister interest in a pending IO state for a given FD.
*/
void
-rb_setselect_poll(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
if(F == NULL)
return;
pollfd_list.pollfds[F->fd].fd = -1;
if(F->fd == pollfd_list.maxindex)
{
- while (pollfd_list.maxindex >= 0
- && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1)
+ while(pollfd_list.maxindex >= 0
+ && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1)
pollfd_list.maxindex--;
}
}
int revents;
num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay);
- rb_set_time();
+ rb_set_time();
if(num < 0)
{
if(!rb_ignore_errno(errno))
return RB_ERROR;
}
if(num == 0)
- return RB_OK;
-
+ return RB_OK;
+
/* XXX we *could* optimise by falling out after doing num fds ... */
- for (ci = 0; ci < pollfd_list.maxindex + 1; ci++)
+ for(ci = 0; ci < pollfd_list.maxindex + 1; ci++)
{
rb_fde_t *F;
pfd = &pollfd_list.pollfds[ci];
revents = pfd->revents;
- fd = pfd->fd;
+ fd = pfd->fd;
if(revents == 0 || fd == -1)
continue;
F = rb_find_fd(fd);
if(F == NULL)
continue;
-
+
if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR))
{
hdl = F->read_handler;
data = F->write_data;
F->write_handler = NULL;
F->write_data = NULL;
- if(hdl)
+ if(hdl)
hdl(F, data);
}
rb_setselect_poll(F, RB_SELECT_READ, NULL, NULL);
if(F->write_handler == NULL)
rb_setselect_poll(F, RB_SELECT_WRITE, NULL, NULL);
-
+
}
return 0;
}
}
void
-rb_setselect_poll(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
errno = ENOSYS;
return;
}
int
-rb_setup_fd_poll(rb_fde_t * F)
+rb_setup_fd_poll(rb_fde_t *F)
{
errno = ENOSYS;
return -1;
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: ports.c 25038 2008-01-23 16:03:08Z androsyn $
+ * $Id: ports.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
static port_event_t *pelst; /* port buffer */
static int pemax; /* max structs to buffer */
-int
-rb_setup_fd_ports(rb_fde_t *F)
+int
+rb_setup_fd_ports(int fd)
{
- return 0;
+ return 0;
}
-
+
static void
-pe_update_events(rb_fde_t * F, short filter, PF * handler)
+pe_update_events(rb_fde_t *F, short filter, PF * handler)
{
PF *cur_handler = NULL;
- if (filter == POLLRDNORM)
+ if(filter == POLLRDNORM)
cur_handler = F->read_handler;
- else if (filter == POLLWRNORM)
+ else if(filter == POLLWRNORM)
cur_handler = F->write_handler;
- if (!cur_handler && handler)
+ if(!cur_handler && handler)
port_associate(pe, PORT_SOURCE_FD, F->fd, filter, F);
- else if (cur_handler && !handler)
+ else if(cur_handler && !handler)
port_dissociate(pe, PORT_SOURCE_FD, F->fd);
}
int
rb_init_netio_ports(void)
{
- if((pe = port_create()) < 0) {
+ if((pe = port_create()) < 0)
+ {
return errno;
}
pemax = getdtablesize();
* and deregister interest in a pending IO state for a given FD.
*/
void
-rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler,
- void *client_data)
+rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
lrb_assert(IsFDOpen(F));
/* Update the list, even though we're not using it .. */
- if(type & RB_SELECT_READ) {
+ if(type & RB_SELECT_READ)
+ {
pe_update_events(F, POLLRDNORM, handler);
F->read_handler = handler;
F->read_data = client_data;
}
- if(type & RB_SELECT_WRITE) {
+ if(type & RB_SELECT_WRITE)
+ {
pe_update_events(F, POLLWRNORM, handler);
F->write_handler = handler;
F->write_data = client_data;
int
rb_select_ports(long delay)
{
- int i, fd;
- uint nget = 1;
-struct timespec poll_time;
-struct timer_data *tdata;
+ int i, fd;
+ uint nget = 1;
+ struct timespec poll_time;
+ struct timer_data *tdata;
poll_time.tv_sec = delay / 1000;
poll_time.tv_nsec = (delay % 1000) * 1000000;
i = port_getn(pe, pelst, pemax, &nget, &poll_time);
rb_set_time();
- if (i == -1)
+ if(i == -1)
return RB_OK;
- for (i = 0; i < nget; i++) {
- switch(pelst[i].portev_source) {
+ for(i = 0; i < nget; i++)
+ {
+ switch (pelst[i].portev_source)
+ {
case PORT_SOURCE_FD:
fd = pelst[i].portev_object;
PF *hdl = NULL;
rb_fde_t *F = rb_find_fd(fd);
- if ((pelst[i].portev_events & POLLRDNORM) && (hdl = F->read_handler)) {
+ if((pelst[i].portev_events & POLLRDNORM) && (hdl = F->read_handler))
+ {
F->read_handler = NULL;
hdl(F, F->read_data);
}
- if ((pelst[i].portev_events & POLLWRNORM) && (hdl = F->write_handler)) {
+ if((pelst[i].portev_events & POLLWRNORM) && (hdl = F->write_handler))
+ {
F->write_handler = NULL;
hdl(F, F->write_data);
}
}
#else /* ports not supported */
-int
+int
rb_init_netio_ports(void)
{
return ENOSYS;
void
rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
- errno = ENOSYS;
- return;
+ errno = ENOSYS;
+ return;
}
-
+
int
rb_select_ports(long delay)
{
- errno = ENOSYS;
- return -1;
+ errno = ENOSYS;
+ return -1;
}
-
+
int
rb_setup_fd_ports(rb_fde_t *F)
{
- errno = ENOSYS;
- return -1;
+ errno = ENOSYS;
+ return -1;
}
-
+
#endif
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: ratbox_lib.c 25375 2008-05-16 15:19:51Z androsyn $
+ * $Id: ratbox_lib.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
/* this doesn't do locales...oh well i guess */
static const char *months[] = {
- "January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December"
+ "January", "February", "March", "April",
+ "May", "June", "July", "August",
+ "September", "October", "November", "December"
};
static const char *weekdays[] = {
- "Sunday", "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday"
+ "Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"
};
static const char *s_month[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec"
-};
+};
static const char *s_weekdays[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
if(rb_unlikely(tp == NULL))
{
strcpy(buf, "");
- return(buf);
+ return (buf);
}
if(buf == NULL)
{
p = timex;
tlen = sizeof(timex);
- } else {
+ }
+ else
+ {
p = buf;
tlen = len;
}
rb_snprintf(p, tlen, "%s %s %d %02u:%02u:%02u %d",
- s_weekdays[tp->tm_wday], s_month[tp->tm_mon],
- tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec,
- tp->tm_year + 1900);
- return(p);
+ s_weekdays[tp->tm_wday], s_month[tp->tm_mon],
+ tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, tp->tm_year + 1900);
+ return (p);
}
if(rb_unlikely(gm == NULL))
{
- rb_strlcpy(buf, "", len);
- return(buf);
+ rb_strlcpy(buf, "", len);
+ return (buf);
}
-
- rb_snprintf(buf, len, "%s %s %d %d -- %02u:%02u:%02u +00:00",
- weekdays[gm->tm_wday], months[gm->tm_mon], gm->tm_mday,
- gm->tm_year + 1900, gm->tm_hour, gm->tm_min, gm->tm_sec);
- return(buf);
+
+ rb_snprintf(buf, len, "%s %s %d %d -- %02u:%02u:%02u +00:00",
+ weekdays[gm->tm_wday], months[gm->tm_mon], gm->tm_mday,
+ gm->tm_year + 1900, gm->tm_hour, gm->tm_min, gm->tm_sec);
+ return (buf);
}
time_t
if(rb_log == NULL)
return;
va_start(args, format);
- rb_vsnprintf(errbuf, sizeof(errbuf), format, args);
+ rb_vsnprintf(errbuf, sizeof(errbuf), format, args);
va_end(args);
rb_log(errbuf);
}
if(rb_die == NULL)
abort();
va_start(args, format);
- rb_vsnprintf(errbuf, sizeof(errbuf), format, args);
+ rb_vsnprintf(errbuf, sizeof(errbuf), format, args);
va_end(args);
rb_die(errbuf);
}
if(rb_restart == NULL)
abort();
va_start(args, format);
- rb_vsnprintf(errbuf, sizeof(errbuf), format, args);
+ rb_vsnprintf(errbuf, sizeof(errbuf), format, args);
va_end(args);
rb_restart(errbuf);
}
memcpy(&rb_time, &newtime, sizeof(struct timeval));
}
+extern const char *libratbox_serno;
+
const char *
rb_lib_version(void)
{
- static const char *id = "$Rev: 25375 $";
- return id;
+ return libratbox_serno;
}
void
-rb_lib_init(log_cb *ilog, restart_cb *irestart, die_cb *idie, int closeall, int maxcon, size_t dh_size, size_t fd_heap_size)
+rb_lib_init(log_cb * ilog, restart_cb * irestart, die_cb * idie, int closeall, int maxcon,
+ size_t dh_size, size_t fd_heap_size)
{
rb_set_time();
rb_log = ilog;
while(1)
rb_select(-1);
}
-
+
while(1)
{
if(delay == 0)
{
- if((next = rb_event_next()) > 0)
+ if((next = rb_event_next()) > 0)
{
next -= rb_current_time();
if(next <= 0)
next = 1000;
- else
+ else
next *= 1000;
}
else
next = -1;
rb_select(next);
- } else
+ }
+ else
rb_select(delay);
rb_event_run();
}
#ifndef HAVE_STRTOK_R
char *
-rb_strtok_r (char *s, const char *delim, char **save)
+rb_strtok_r(char *s, const char *delim, char **save)
{
char *token;
- if (s == NULL)
+ if(s == NULL)
s = *save;
/* Scan leading delimiters. */
s += strspn(s, delim);
- if (*s == '\0')
+ if(*s == '\0')
{
*save = s;
return NULL;
token = s;
s = strpbrk(token, delim);
-
- if (s == NULL)
+
+ if(s == NULL)
*save = (token + strlen(token));
else
{
- *s = '\0';
+ *s = '\0';
*save = s + 1;
}
return token;
}
#else
-char
-*rb_strtok_r(char *s, const char *delim, char **save)
+char *
+rb_strtok_r(char *s, const char *delim, char **save)
{
return strtok_r(s, delim, save);
}
static const char base64_table[] =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
- };
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
+};
static const char base64_pad = '=';
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
unsigned char *p;
unsigned char *result;
- if ((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) {
+ if((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2)))
+ {
return NULL;
}
result = rb_malloc(((length + 2) / 3) * 5);
p = result;
- while (length > 2)
- {
+ while(length > 2)
+ {
*p++ = base64_table[current[0] >> 2];
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
*p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
*p++ = base64_table[current[2] & 0x3f];
current += 3;
- length -= 3;
+ length -= 3;
}
- if (length != 0) {
+ if(length != 0)
+ {
*p++ = base64_table[current[0] >> 2];
- if (length > 1) {
+ if(length > 1)
+ {
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
*p++ = base64_table[(current[1] & 0x0f) << 2];
*p++ = base64_pad;
- } else {
+ }
+ else
+ {
*p++ = base64_table[(current[0] & 0x03) << 4];
*p++ = base64_pad;
*p++ = base64_pad;
const unsigned char *current = str;
int ch, i = 0, j = 0, k;
unsigned char *result;
-
+
result = rb_malloc(length + 1);
- while ((ch = *current++) != '\0' && length-- > 0) {
- if (ch == base64_pad) break;
+ while((ch = *current++) != '\0' && length-- > 0)
+ {
+ if(ch == base64_pad)
+ break;
ch = base64_reverse_table[ch];
- if (ch < 0) continue;
+ if(ch < 0)
+ continue;
- switch(i % 4) {
+ switch (i % 4)
+ {
case 0:
result[j] = ch << 2;
break;
result[j] = (ch & 0x0f) << 4;
break;
case 2:
- result[j++] |= ch >>2;
+ result[j++] |= ch >> 2;
result[j] = (ch & 0x03) << 6;
break;
case 3:
k = j;
- if (ch == base64_pad) {
- switch(i % 4) {
+ if(ch == base64_pad)
+ {
+ switch (i % 4)
+ {
case 1:
free(result);
return NULL;
*ret = j;
return result;
}
-
-
rb->len -= buf->len - rb->written;
rb_rawbuf_done(rb, buf);
continue;
- }
+ }
}
-
+
if(xret >= buf->len)
{
xret -= buf->len;
rb_bh_free(rawbuf_heap, buf);
}
rb->len -= retval;
- lrb_assert(rb->len >= 0);
+ lrb_assert(rb->len >= 0);
return retval;
}
{
buf = (rawbuf_t *) rb->list.tail->data;
clen = RAWBUF_SIZE - buf->len;
- ptr = (void *) (buf->data + buf->len);
+ ptr = (void *)(buf->data + buf->len);
if(len < clen)
clen = len;
}
- while (len > 0)
+ while(len > 0)
{
buf = rb_rawbuf_newbuf(rb);
buf = rb->list.head->data;
if(buf->flushing)
- ptr = (void *) (buf->data + rb->written);
+ ptr = (void *)(buf->data + rb->written);
else
ptr = buf->data;
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: rb_memory.c 25038 2008-01-23 16:03:08Z androsyn $
+ * $Id: rb_memory.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
#include <ratbox_lib.h>
rb_lib_log("Out of memory: restarting server...");
rb_lib_restart("Out of Memory");
}
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: select.c 25038 2008-01-23 16:03:08Z androsyn $
+ * $Id: select.c 26092 2008-09-19 15:13:52Z androsyn $
*/
+#define FD_SETSIZE 65535
#include <libratbox_config.h>
#include <ratbox_lib.h>
#include <commio-int.h>
-#if defined(HAVE_SELECT)
+#if defined(HAVE_SELECT) || defined(_WIN32)
+
+#ifdef _WIN32
+#define MY_FD_SET(x, y) FD_SET((SOCKET)x, y)
+#define MY_FD_CLR(x, y) FD_CLR((SOCKET)x, y)
+#else
+#define MY_FD_SET(x, y) FD_SET(x, y)
+#define MY_FD_CLR(x, y) FD_CLR(x, y)
+#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
/* Update the read / write set */
if(event & RB_SELECT_READ)
{
- if(handler)
+ if(handler)
{
- FD_SET(F->fd, &select_readfds);
- F->pflags |= RB_SELECT_READ;
- }
- else
+ MY_FD_SET(F->fd, &select_readfds);
+ F->pflags |= RB_SELECT_READ;
+ }
+ else
{
- FD_CLR(F->fd, &select_readfds);
+ MY_FD_CLR(F->fd, &select_readfds);
F->pflags &= ~RB_SELECT_READ;
}
}
if(event & RB_SELECT_WRITE)
{
- if(handler)
+ if(handler)
{
- FD_SET(F->fd, &select_writefds);
+ MY_FD_SET(F->fd, &select_writefds);
F->pflags |= RB_SELECT_WRITE;
}
- else
+ else
{
- FD_CLR(F->fd, &select_writefds);
+ MY_FD_CLR(F->fd, &select_writefds);
F->pflags &= ~RB_SELECT_WRITE;
}
}
- if(F->pflags & (RB_SELECT_READ|RB_SELECT_WRITE))
+ if(F->pflags & (RB_SELECT_READ | RB_SELECT_WRITE))
{
if(F->fd > rb_maxfd)
{
- rb_maxfd = F->fd;
+ rb_maxfd = F->fd;
}
- }
+ }
else if(F->fd <= rb_maxfd)
{
- while(rb_maxfd >= 0 && !FD_ISSET(rb_maxfd, &select_readfds) && !FD_ISSET(rb_maxfd, &select_writefds))
- rb_maxfd--;
+ while(rb_maxfd >= 0 && !FD_ISSET(rb_maxfd, &select_readfds)
+ && !FD_ISSET(rb_maxfd, &select_writefds))
+ rb_maxfd--;
}
}
int
rb_setup_fd_select(rb_fde_t *F)
{
- return 0;
+ return 0;
}
* This is a needed exported function which will be called to initialise
* the network loop code.
*/
+extern int rb_maxconnections;
int
rb_init_netio_select(void)
{
+ if(rb_maxconnections > FD_SETSIZE)
+ rb_maxconnections = FD_SETSIZE; /* override this */
FD_ZERO(&select_readfds);
FD_ZERO(&select_writefds);
return 0;
* and deregister interest in a pending IO state for a given FD.
*/
void
-rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler,
- void *client_data)
+rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
lrb_assert(IsFDOpen(F));
memcpy(&tmpreadfds, &select_readfds, sizeof(fd_set));
memcpy(&tmpwritefds, &select_writefds, sizeof(fd_set));
- for (;;)
+ for(;;)
{
to.tv_sec = 0;
to.tv_usec = delay * 1000;
return 0;
/* XXX we *could* optimise by falling out after doing num fds ... */
- for (fd = 0; fd < rb_maxfd + 1; fd++)
+ for(fd = 0; fd < rb_maxfd + 1; fd++)
{
F = rb_find_fd(fd);
if(F == NULL)
}
#else /* select not supported..what sort of garbage is this? */
-int
+int
rb_init_netio_select(void)
{
return ENOSYS;
void
rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
- errno = ENOSYS;
- return;
+ errno = ENOSYS;
+ return;
}
-
+
int
rb_select_select(long delay)
{
- errno = ENOSYS;
- return -1;
+ errno = ENOSYS;
+ return -1;
}
-
+
int
rb_setup_fd_select(rb_fde_t *F)
{
- errno = ENOSYS;
- return -1;
+ errno = ENOSYS;
+ return -1;
}
#endif
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: sigio.c 25375 2008-05-16 15:19:51Z androsyn $
+ * $Id: sigio.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#ifndef _GNU_SOURCE
int fd;
pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd)));
pollfd_list.allocated = rb_getmaxconnect();
- for (fd = 0; fd < rb_getmaxconnect(); fd++)
+ for(fd = 0; fd < rb_getmaxconnect(); fd++)
{
pollfd_list.pollfds[fd].fd = -1;
}
rb_realloc(pollfd_list.pollfds,
pollfd_list.allocated * (sizeof(struct pollfd)));
memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024);
- for (x = old_value + 1; x < pollfd_list.allocated; x++)
+ for(x = old_value + 1; x < pollfd_list.allocated; x++)
{
pollfd_list.pollfds[x].fd = -1;
}
*/
int
-rb_setup_fd_sigio(rb_fde_t * F)
+rb_setup_fd_sigio(rb_fde_t *F)
{
int flags = 0;
int fd = F->fd;
* and deregister interest in a pending IO state for a given FD.
*/
void
-rb_setselect_sigio(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
if(F == NULL)
return;
pollfd_list.pollfds[F->fd].fd = -1;
if(F->fd == pollfd_list.maxindex)
{
- while (pollfd_list.maxindex >= 0
- && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1)
+ while(pollfd_list.maxindex >= 0
+ && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1)
pollfd_list.maxindex--;
}
}
timeout.tv_nsec = (delay % 1000) * 1000000;
}
- for (;;)
+ for(;;)
{
if(!sigio_is_screwed)
{
#ifdef SIGIO_SCHED_EVENT
if(sig == RTSIGTIM && can_do_event)
{
- struct ev_entry *ev = (struct ev_entry *) si.si_ptr;
+ struct ev_entry *ev = (struct ev_entry *)si.si_ptr;
if(ev == NULL)
continue;
rb_run_event(ev);
return RB_OK;
/* XXX we *could* optimise by falling out after doing num fds ... */
- for (ci = 0; ci < pollfd_list.maxindex + 1; ci++)
+ for(ci = 0; ci < pollfd_list.maxindex + 1; ci++)
{
if(((revents = pollfd_list.pollfds[ci].revents) == 0)
|| (pollfd_list.pollfds[ci].fd) == -1)
}
void
-rb_setselect_sigio(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
errno = ENOSYS;
return;
}
int
-rb_setup_fd_sigio(rb_fde_t * F)
+rb_setup_fd_sigio(rb_fde_t *F)
{
errno = ENOSYS;
return -1;
* The original headers are below..
* Note that this implementation does not process floating point numbers so
* you will likely need to fall back to using sprintf yourself to do those...
- * $Id: snprintf.c 25375 2008-05-16 15:19:51Z androsyn $
+ * $Id: snprintf.c 26092 2008-09-19 15:13:52Z androsyn $
*/
/*
#include <libratbox_config.h>
#include <ratbox_lib.h>
-static int skip_atoi(const char **s)
+static int
+skip_atoi(const char **s)
{
- int i=0;
+ int i = 0;
- while (isdigit(**s))
- i = i*10 + *((*s)++) - '0';
+ while(isdigit(**s))
+ i = i * 10 + *((*s)++) - '0';
return i;
}
/* Formats correctly any integer in [0,99999].
* Outputs from one to five digits depending on input.
* On i386 gcc 4.1.2 -O2: ~250 bytes of code. */
-static char* put_dec_trunc(char *buf, unsigned q)
+static char *
+put_dec_trunc(char *buf, unsigned q)
{
unsigned d3, d2, d1, d0;
- d1 = (q>>4) & 0xf;
- d2 = (q>>8) & 0xf;
- d3 = (q>>12);
+ d1 = (q >> 4) & 0xf;
+ d2 = (q >> 8) & 0xf;
+ d3 = (q >> 12);
- d0 = 6*(d3 + d2 + d1) + (q & 0xf);
+ d0 = 6 * (d3 + d2 + d1) + (q & 0xf);
q = (d0 * 0xcd) >> 11;
- d0 = d0 - 10*q;
- *buf++ = d0 + '0'; /* least significant digit */
- d1 = q + 9*d3 + 5*d2 + d1;
- if (d1 != 0) {
+ d0 = d0 - 10 * q;
+ *buf++ = d0 + '0'; /* least significant digit */
+ d1 = q + 9 * d3 + 5 * d2 + d1;
+ if(d1 != 0)
+ {
q = (d1 * 0xcd) >> 11;
- d1 = d1 - 10*q;
- *buf++ = d1 + '0'; /* next digit */
+ d1 = d1 - 10 * q;
+ *buf++ = d1 + '0'; /* next digit */
- d2 = q + 2*d2;
- if ((d2 != 0) || (d3 != 0)) {
+ d2 = q + 2 * d2;
+ if((d2 != 0) || (d3 != 0))
+ {
q = (d2 * 0xd) >> 7;
- d2 = d2 - 10*q;
- *buf++ = d2 + '0'; /* next digit */
+ d2 = d2 - 10 * q;
+ *buf++ = d2 + '0'; /* next digit */
- d3 = q + 4*d3;
- if (d3 != 0) {
+ d3 = q + 4 * d3;
+ if(d3 != 0)
+ {
q = (d3 * 0xcd) >> 11;
- d3 = d3 - 10*q;
- *buf++ = d3 + '0'; /* next digit */
- if (q != 0)
- *buf++ = q + '0'; /* most sign. digit */
+ d3 = d3 - 10 * q;
+ *buf++ = d3 + '0'; /* next digit */
+ if(q != 0)
+ *buf++ = q + '0'; /* most sign. digit */
}
}
}
return buf;
}
+
/* Same with if's removed. Always emits five digits */
-static char* put_dec_full(char *buf, unsigned q)
+static char *
+put_dec_full(char *buf, unsigned q)
{
/* BTW, if q is in [0,9999], 8-bit ints will be enough, */
/* but anyway, gcc produces better code with full-sized ints */
unsigned d3, d2, d1, d0;
- d1 = (q>>4) & 0xf;
- d2 = (q>>8) & 0xf;
- d3 = (q>>12);
+ d1 = (q >> 4) & 0xf;
+ d2 = (q >> 8) & 0xf;
+ d3 = (q >> 12);
/* Possible ways to approx. divide by 10 */
/* gcc -O2 replaces multiply with shifts and adds */
// (x * 0x1a) >> 8: 11010 - same
// (x * 0x0d) >> 7: 1101 - same, shortest code (on i386)
- d0 = 6*(d3 + d2 + d1) + (q & 0xf);
+ d0 = 6 * (d3 + d2 + d1) + (q & 0xf);
q = (d0 * 0xcd) >> 11;
- d0 = d0 - 10*q;
+ d0 = d0 - 10 * q;
*buf++ = d0 + '0';
- d1 = q + 9*d3 + 5*d2 + d1;
- q = (d1 * 0xcd) >> 11;
- d1 = d1 - 10*q;
- *buf++ = d1 + '0';
-
- d2 = q + 2*d2;
- q = (d2 * 0xd) >> 7;
- d2 = d2 - 10*q;
- *buf++ = d2 + '0';
-
- d3 = q + 4*d3;
- q = (d3 * 0xcd) >> 11; /* - shorter code */
- /* q = (d3 * 0x67) >> 10; - would also work */
- d3 = d3 - 10*q;
- *buf++ = d3 + '0';
- *buf++ = q + '0';
+ d1 = q + 9 * d3 + 5 * d2 + d1;
+ q = (d1 * 0xcd) >> 11;
+ d1 = d1 - 10 * q;
+ *buf++ = d1 + '0';
+
+ d2 = q + 2 * d2;
+ q = (d2 * 0xd) >> 7;
+ d2 = d2 - 10 * q;
+ *buf++ = d2 + '0';
+
+ d3 = q + 4 * d3;
+ q = (d3 * 0xcd) >> 11; /* - shorter code */
+ /* q = (d3 * 0x67) >> 10; - would also work */
+ d3 = d3 - 10 * q;
+ *buf++ = d3 + '0';
+ *buf++ = q + '0';
return buf;
}
-static char* put_dec(char *buf, unsigned long long int num)
+static char *
+put_dec(char *buf, unsigned long long int num)
{
- while (1) {
+ while(1)
+ {
unsigned rem;
- if (num < 100000)
+ if(num < 100000)
return put_dec_trunc(buf, num);
rem = num % 100000;
num = num / 100000;
#define SPECIAL 32 /* 0x */
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
-static char *number(char *buf, char *end, unsigned long long int num, int base, int size, int precision, int type)
+static char *
+number(char *buf, char *end, unsigned long long int num, int base, int size, int precision,
+ int type)
{
- char sign,tmp[66];
+ char sign, tmp[66];
const char *digits;
/* we are called with base 8, 10 or 16, only, thus don't need "g..." */
- static const char small_digits[] = "0123456789abcdefx"; /* "ghijklmnopqrstuvwxyz"; */
- static const char large_digits[] = "0123456789ABCDEFX"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
+ static const char small_digits[] = "0123456789abcdefx"; /* "ghijklmnopqrstuvwxyz"; */
+ static const char large_digits[] = "0123456789ABCDEFX"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
int need_pfx = ((type & SPECIAL) && base != 10);
int i;
digits = (type & LARGE) ? large_digits : small_digits;
- if (type & LEFT)
+ if(type & LEFT)
type &= ~ZEROPAD;
- if (base < 2 || base > 36)
+ if(base < 2 || base > 36)
return NULL;
sign = 0;
- if (type & SIGN) {
- if ((signed long long int) num < 0) {
+ if(type & SIGN)
+ {
+ if((signed long long int)num < 0)
+ {
sign = '-';
- num = - (signed long long int) num;
+ num = -(signed long long int)num;
size--;
- } else if (type & PLUS) {
+ }
+ else if(type & PLUS)
+ {
sign = '+';
size--;
- } else if (type & SPACE) {
+ }
+ else if(type & SPACE)
+ {
sign = ' ';
size--;
}
}
- if (need_pfx) {
+ if(need_pfx)
+ {
size--;
- if (base == 16)
+ if(base == 16)
size--;
}
/* generate full string in tmp[], in reverse order */
i = 0;
- if (num == 0)
+ if(num == 0)
tmp[i++] = '0';
/* Generic code, for any base:
- else do {
- tmp[i++] = digits[do_div(num,base)];
- } while (num != 0);
- */
- else if (base != 10) { /* 8 or 16 */
+ else do {
+ tmp[i++] = digits[do_div(num,base)];
+ } while (num != 0);
+ */
+ else if(base != 10)
+ { /* 8 or 16 */
int mask = base - 1;
int shift = 3;
- if (base == 16) shift = 4;
- do {
+ if(base == 16)
+ shift = 4;
+ do
+ {
tmp[i++] = digits[((unsigned char)num) & mask];
num >>= shift;
- } while (num);
- } else { /* base 10 */
+ }
+ while(num);
+ }
+ else
+ { /* base 10 */
i = put_dec(tmp, num) - tmp;
}
/* printing 100 using %2d gives "100", not "00" */
- if (i > precision)
+ if(i > precision)
precision = i;
/* leading space padding */
size -= precision;
- if (!(type & (ZEROPAD+LEFT))) {
- while(--size >= 0) {
- if (buf < end)
+ if(!(type & (ZEROPAD + LEFT)))
+ {
+ while(--size >= 0)
+ {
+ if(buf < end)
*buf = ' ';
++buf;
}
}
/* sign */
- if (sign) {
- if (buf < end)
+ if(sign)
+ {
+ if(buf < end)
*buf = sign;
++buf;
}
/* "0x" / "0" prefix */
- if (need_pfx) {
- if (buf < end)
+ if(need_pfx)
+ {
+ if(buf < end)
*buf = '0';
++buf;
- if (base == 16) {
- if (buf < end)
- *buf = digits[16]; /* for arbitrary base: digits[33]; */
+ if(base == 16)
+ {
+ if(buf < end)
+ *buf = digits[16]; /* for arbitrary base: digits[33]; */
++buf;
}
}
/* zero or space padding */
- if (!(type & LEFT)) {
+ if(!(type & LEFT))
+ {
char c = (type & ZEROPAD) ? '0' : ' ';
- while (--size >= 0) {
- if (buf < end)
+ while(--size >= 0)
+ {
+ if(buf < end)
*buf = c;
++buf;
}
}
/* hmm even more zero padding? */
- while (i <= --precision) {
- if (buf < end)
+ while(i <= --precision)
+ {
+ if(buf < end)
*buf = '0';
++buf;
}
/* actual digits of result */
- while (--i >= 0) {
- if (buf < end)
+ while(--i >= 0)
+ {
+ if(buf < end)
*buf = tmp[i];
++buf;
}
/* trailing space padding */
- while (--size >= 0) {
- if (buf < end)
+ while(--size >= 0)
+ {
+ if(buf < end)
*buf = ' ';
++buf;
}
* Call this function if you are already dealing with a va_list.
* You probably want snprintf() instead.
*/
-int rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
+int
+rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
int len;
unsigned long long int num;
int precision; /* min. # of digits for integers; max
number of chars for from string */
int qualifier; /* 'h', 'l', or 'L' for integer fields */
- /* 'z' support added 23/7/1999 S.H. */
- /* 'z' changed to 'Z' --davidm 1/25/99 */
- /* 't' added for ptrdiff_t */
+ /* 'z' support added 23/7/1999 S.H. */
+ /* 'z' changed to 'Z' --davidm 1/25/99 */
+ /* 't' added for ptrdiff_t */
/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
- if (rb_unlikely((int) size < 0)) {
+ if(rb_unlikely((int)size < 0))
+ {
return 0;
}
end = buf + size;
/* Make sure end is always >= buf */
- if (end < buf) {
+ if(end < buf)
+ {
end = ((void *)-1);
size = end - buf;
}
- for (; *fmt ; ++fmt) {
- if (*fmt != '%') {
- if (str < end)
+ for(; *fmt; ++fmt)
+ {
+ if(*fmt != '%')
+ {
+ if(str < end)
*str = *fmt;
++str;
continue;
/* process flags */
flags = 0;
- repeat:
- ++fmt; /* this also skips first '%' */
- switch (*fmt) {
- case '-': flags |= LEFT; goto repeat;
- case '+': flags |= PLUS; goto repeat;
- case ' ': flags |= SPACE; goto repeat;
- case '#': flags |= SPECIAL; goto repeat;
- case '0': flags |= ZEROPAD; goto repeat;
- }
+ repeat:
+ ++fmt; /* this also skips first '%' */
+ switch (*fmt)
+ {
+ case '-':
+ flags |= LEFT;
+ goto repeat;
+ case '+':
+ flags |= PLUS;
+ goto repeat;
+ case ' ':
+ flags |= SPACE;
+ goto repeat;
+ case '#':
+ flags |= SPECIAL;
+ goto repeat;
+ case '0':
+ flags |= ZEROPAD;
+ goto repeat;
+ }
/* get field width */
field_width = -1;
- if (isdigit(*fmt))
+ if(isdigit(*fmt))
field_width = skip_atoi(&fmt);
- else if (*fmt == '*') {
+ else if(*fmt == '*')
+ {
++fmt;
/* it's the next argument */
field_width = va_arg(args, int);
- if (field_width < 0) {
+ if(field_width < 0)
+ {
field_width = -field_width;
flags |= LEFT;
}
/* get the precision */
precision = -1;
- if (*fmt == '.') {
- ++fmt;
- if (isdigit(*fmt))
+ if(*fmt == '.')
+ {
+ ++fmt;
+ if(isdigit(*fmt))
precision = skip_atoi(&fmt);
- else if (*fmt == '*') {
+ else if(*fmt == '*')
+ {
++fmt;
/* it's the next argument */
precision = va_arg(args, int);
}
- if (precision < 0)
+ if(precision < 0)
precision = 0;
}
/* get the conversion qualifier */
qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
- *fmt =='Z' || *fmt == 'z' || *fmt == 't') {
+ if(*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
+ *fmt == 'Z' || *fmt == 'z' || *fmt == 't')
+ {
qualifier = *fmt;
++fmt;
- if (qualifier == 'l' && *fmt == 'l') {
+ if(qualifier == 'l' && *fmt == 'l')
+ {
qualifier = 'L';
++fmt;
}
/* default base */
base = 10;
- switch (*fmt) {
- case 'c':
- if (!(flags & LEFT)) {
- while (--field_width > 0) {
- if (str < end)
- *str = ' ';
- ++str;
- }
- }
- c = (unsigned char) va_arg(args, int);
- if (str < end)
- *str = c;
- ++str;
- while (--field_width > 0) {
- if (str < end)
+ switch (*fmt)
+ {
+ case 'c':
+ if(!(flags & LEFT))
+ {
+ while(--field_width > 0)
+ {
+ if(str < end)
*str = ' ';
++str;
}
- continue;
+ }
+ c = (unsigned char)va_arg(args, int);
+ if(str < end)
+ *str = c;
+ ++str;
+ while(--field_width > 0)
+ {
+ if(str < end)
+ *str = ' ';
+ ++str;
+ }
+ continue;
- case 's':
- s = va_arg(args, char *);
- if (s == NULL) {
- abort(); /* prefer blowing up vs corrupt data */
- }
- len = rb_strnlen(s, precision);
-
- if (!(flags & LEFT)) {
- while (len < field_width--) {
- if (str < end)
- *str = ' ';
- ++str;
- }
- }
- for (i = 0; i < len; ++i) {
- if (str < end)
- *str = *s;
- ++str; ++s;
- }
- while (len < field_width--) {
- if (str < end)
+ case 's':
+ s = va_arg(args, char *);
+ if(s == NULL)
+ {
+ abort(); /* prefer blowing up vs corrupt data */
+ }
+ len = rb_strnlen(s, precision);
+
+ if(!(flags & LEFT))
+ {
+ while(len < field_width--)
+ {
+ if(str < end)
*str = ' ';
++str;
}
- continue;
+ }
+ for(i = 0; i < len; ++i)
+ {
+ if(str < end)
+ *str = *s;
+ ++str;
+ ++s;
+ }
+ while(len < field_width--)
+ {
+ if(str < end)
+ *str = ' ';
+ ++str;
+ }
+ continue;
- case 'p':
- if (field_width == -1) {
- field_width = 2*sizeof(void *);
- flags |= ZEROPAD;
- }
- str = number(str, end,
- (unsigned long) va_arg(args, void *),
- 16, field_width, precision, flags);
- continue;
-
-
- case 'n':
- /* FIXME:
- * What does C99 say about the overflow case here? */
- if (qualifier == 'l') {
- long * ip = va_arg(args, long *);
- *ip = (str - buf);
- } else if (qualifier == 'Z' || qualifier == 'z') {
- size_t * ip = va_arg(args, size_t *);
- *ip = (str - buf);
- } else {
- int * ip = va_arg(args, int *);
- *ip = (str - buf);
- }
- continue;
+ case 'p':
+ if(field_width == -1)
+ {
+ field_width = 2 * sizeof(void *);
+ flags |= ZEROPAD;
+ }
+ str = number(str, end,
+ (unsigned long)va_arg(args, void *),
+ 16, field_width, precision, flags);
+ continue;
- case '%':
- if (str < end)
- *str = '%';
- ++str;
- continue;
-
- /* integer number formats - set up the flags and "break" */
- case 'o':
- base = 8;
- break;
-
- case 'X':
- flags |= LARGE;
- case 'x':
- base = 16;
- break;
-
- case 'd':
- case 'i':
- flags |= SIGN;
- case 'u':
- break;
-
- default:
- if (str < end)
- *str = '%';
+
+ case 'n':
+ /* FIXME:
+ * What does C99 say about the overflow case here? */
+ if(qualifier == 'l')
+ {
+ long *ip = va_arg(args, long *);
+ *ip = (str - buf);
+ }
+ else if(qualifier == 'Z' || qualifier == 'z')
+ {
+ size_t *ip = va_arg(args, size_t *);
+ *ip = (str - buf);
+ }
+ else
+ {
+ int *ip = va_arg(args, int *);
+ *ip = (str - buf);
+ }
+ continue;
+
+ case '%':
+ if(str < end)
+ *str = '%';
+ ++str;
+ continue;
+
+ /* integer number formats - set up the flags and "break" */
+ case 'o':
+ base = 8;
+ break;
+
+ case 'X':
+ flags |= LARGE;
+ case 'x':
+ base = 16;
+ break;
+
+ case 'd':
+ case 'i':
+ flags |= SIGN;
+ case 'u':
+ break;
+
+ default:
+ if(str < end)
+ *str = '%';
+ ++str;
+ if(*fmt)
+ {
+ if(str < end)
+ *str = *fmt;
++str;
- if (*fmt) {
- if (str < end)
- *str = *fmt;
- ++str;
- } else {
- --fmt;
- }
- continue;
+ }
+ else
+ {
+ --fmt;
+ }
+ continue;
}
- if (qualifier == 'L')
+ if(qualifier == 'L')
num = va_arg(args, long long int);
- else if (qualifier == 'l') {
+ else if(qualifier == 'l')
+ {
num = va_arg(args, unsigned long);
- if (flags & SIGN)
- num = (signed long) num;
- } else if (qualifier == 'Z' || qualifier == 'z') {
+ if(flags & SIGN)
+ num = (signed long)num;
+ }
+ else if(qualifier == 'Z' || qualifier == 'z')
+ {
num = va_arg(args, size_t);
- } else if (qualifier == 't') {
+ }
+ else if(qualifier == 't')
+ {
num = va_arg(args, ptrdiff_t);
- } else if (qualifier == 'h') {
- num = (unsigned short) va_arg(args, int);
- if (flags & SIGN)
- num = (signed short) num;
- } else {
+ }
+ else if(qualifier == 'h')
+ {
+ num = (unsigned short)va_arg(args, int);
+ if(flags & SIGN)
+ num = (signed short)num;
+ }
+ else
+ {
num = va_arg(args, unsigned int);
- if (flags & SIGN)
- num = (signed int) num;
+ if(flags & SIGN)
+ num = (signed int)num;
}
- str = number(str, end, num, base,
- field_width, precision, flags);
+ str = number(str, end, num, base, field_width, precision, flags);
}
- if (size > 0) {
- if (str < end)
+ if(size > 0)
+ {
+ if(str < end)
*str = '\0';
else
end[-1] = '\0';
}
/* the trailing null byte doesn't count towards the total */
- return str-buf;
+ return str - buf;
}
/**
* as per ISO C99. If the return is greater than or equal to
* @size, the resulting string is truncated.
*/
-int rb_snprintf(char * buf, size_t size, const char *fmt, ...)
+int
+rb_snprintf(char *buf, size_t size, const char *fmt, ...)
{
va_list args;
int i;
va_start(args, fmt);
- i=rb_vsnprintf(buf,size,fmt,args);
+ i = rb_vsnprintf(buf, size, fmt, args);
va_end(args);
return i;
}
* Call this function if you are already dealing with a va_list.
* You probably want sprintf() instead.
*/
-int rb_vsprintf(char *buf, const char *fmt, va_list args)
+int
+rb_vsprintf(char *buf, const char *fmt, va_list args)
{
return rb_vsnprintf(buf, INT_MAX, fmt, args);
}
* into @buf. Use snprintf() or scnprintf() in order to avoid
* buffer overflows.
*/
-int rb_sprintf(char * buf, const char *fmt, ...)
+int
+rb_sprintf(char *buf, const char *fmt, ...)
{
va_list args;
int i;
va_start(args, fmt);
- i=rb_vsnprintf(buf, INT_MAX, fmt, args);
+ i = rb_vsnprintf(buf, INT_MAX, fmt, args);
va_end(args);
return i;
}
* rb_vsprintf_append()
* appends sprintf formatted string to the end of the buffer
*/
-
+
int
rb_vsprintf_append(char *str, const char *format, va_list ap)
{
- size_t x = strlen(str);
- return(rb_vsprintf(str+x, format, ap) + x);
+ size_t x = strlen(str);
+ return (rb_vsprintf(str + x, format, ap) + x);
}
/*
int
rb_sprintf_append(char *str, const char *format, ...)
{
- int x;
- va_list ap;
- va_start(ap, format);
- x = rb_vsprintf_append(str, format, ap);
- va_end(ap);
- return(x);
+ int x;
+ va_list ap;
+ va_start(ap, format);
+ x = rb_vsprintf_append(str, format, ap);
+ va_end(ap);
+ return (x);
}
/*
int
rb_vsnprintf_append(char *str, size_t len, const char *format, va_list ap)
{
- size_t x = strlen(str);
- return(rb_vsnprintf(str+x, len - x, format, ap) + x);
+ size_t x;
+ if(len == 0)
+ return 0;
+ x = strlen(str);
+
+ if(len < x)
+ {
+ str[len - 1] = '\0';
+ return len - 1;
+ }
+ return (rb_vsnprintf(str + x, len - x, format, ap) + x);
}
/*
int
rb_snprintf_append(char *str, size_t len, const char *format, ...)
{
- int x;
- va_list ap;
- va_start(ap, format);
- x = rb_vsnprintf_append(str, len, format, ap);
- va_end(ap);
- return(x);
+ int x;
+ va_list ap;
+ va_start(ap, format);
+ x = rb_vsnprintf_append(str, len, format, ap);
+ va_end(ap);
+ return (x);
}
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: tools.c 25040 2008-01-23 16:11:34Z androsyn $
+ * $Id: tools.c 26170 2008-10-26 20:59:07Z androsyn $
*
* Here is the original header:
*
rb_dlink_node *
rb_make_rb_dlink_node(void)
{
- return(rb_bh_alloc(dnode_heap));
+ return (rb_bh_alloc(dnode_heap));
}
/*
* side effects - free given rb_dlink_node
*/
void
-rb_free_rb_dlink_node(rb_dlink_node * ptr)
+rb_free_rb_dlink_node(rb_dlink_node *ptr)
{
assert(ptr != NULL);
rb_bh_free(dnode_heap, ptr);
if(string == NULL || string[0] == '\0')
return x;
- while (*xbuf == ' ') /* skip leading spaces */
+ while(*xbuf == ' ') /* skip leading spaces */
xbuf++;
if(*xbuf == '\0') /* ignore all-space args */
return x;
else
return x;
}
- while (*xbuf == ' ')
+ while(*xbuf == ' ')
xbuf++;
if(*xbuf == '\0')
return x;
}
- while (x < maxpara - 1);
+ while(x < maxpara - 1);
if(*p == ':')
p++;
}
#ifndef HAVE_STRLCAT
-size_t
+size_t
rb_strlcat(char *dest, const char *src, size_t count)
{
- size_t dsize = strlen(dest);
- size_t len = strlen(src);
- size_t res = dsize + len;
-
- dest += dsize;
- count -= dsize;
- if (len >= count)
- len = count-1;
- memcpy(dest, src, len);
- dest[len] = 0;
- return res;
+ size_t dsize = strlen(dest);
+ size_t len = strlen(src);
+ size_t res = dsize + len;
+
+ dest += dsize;
+ count -= dsize;
+ if(len >= count)
+ len = count - 1;
+ memcpy(dest, src, len);
+ dest[len] = 0;
+ return res;
}
#else
size_t
return strlcat(dest, src, count);
}
#endif
-
+
#ifndef HAVE_STRLCPY
-size_t
+size_t
rb_strlcpy(char *dest, const char *src, size_t size)
{
- size_t ret = strlen(src);
-
- if (size) {
- size_t len = (ret >= size) ? size-1 : ret;
- memcpy(dest, src, len);
- dest[len] = '\0';
- }
- return ret;
+ size_t ret = strlen(src);
+
+ if(size)
+ {
+ size_t len = (ret >= size) ? size - 1 : ret;
+ memcpy(dest, src, len);
+ dest[len] = '\0';
+ }
+ return ret;
}
#else
size_t
#ifndef HAVE_STRNLEN
-size_t
+size_t
rb_strnlen(const char *s, size_t count)
-{
+{
const char *sc;
- for (sc = s; count-- && *sc != '\0'; ++sc)
+ for(sc = s; count-- && *sc != '\0'; ++sc)
;;
return sc - s;
-}
+}
#else
size_t
rb_strnlen(const char *s, size_t count)
}
#endif
+/* rb_basename
+ *
+ * input -
+ * output -
+ * side effects -
+ */
+char *
+rb_basename(const char *path)
+{
+ const char *s;
+
+ if(!(s = strrchr(path, '/')))
+ s = path;
+ else
+ s++;
+ return rb_strdup(s);
+}
+
+/*
+ * rb_dirname
+ */
+
+char *
+rb_dirname (const char *path)
+{
+ char *s;
+
+ s = strrchr(path, '/');
+ if(s == NULL)
+ {
+ return rb_strdup(".");
+ }
+
+ /* remove extra slashes */
+ while(s > path && *s == '/')
+ --s;
+
+ return rb_strndup(path, ((uintptr_t)s - (uintptr_t)path) + 2);
+}
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: unix.c 25038 2008-01-23 16:03:08Z androsyn $
+ * $Id: unix.c 26180 2008-11-11 00:00:12Z androsyn $
*/
#include <libratbox_config.h>
#include <ratbox_lib.h>
-#ifndef WINDOWS
+
+#ifndef _WIN32
+
+#include <sys/wait.h>
+
+
#if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN)
#include <spawn.h>
+
+#ifdef __APPLE__
+#include <crt_externs.h>
+#endif
+
+#ifndef __APPLE__
extern char **environ;
+#endif
pid_t
rb_spawn_process(const char *path, const char **argv)
{
pid_t pid;
const void *arghack = argv;
+ char **myenviron;
posix_spawnattr_t spattr;
posix_spawnattr_init(&spattr);
#ifdef POSIX_SPAWN_USEVFORK
posix_spawnattr_setflags(&spattr, POSIX_SPAWN_USEVFORK);
#endif
- if(posix_spawn(&pid, path, NULL, &spattr, arghack, environ))
+#ifdef __APPLE__
+ myenviron = *_NSGetEnviron(); /* apple needs to go fuck themselves for this */
+#else
+ myenviron = environ;
+#endif
+ if(posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron))
{
return -1;
}
pid_t pid;
if(!(pid = vfork()))
{
- execv(path, (const void *)argv); /* make gcc shut up */
- _exit(1); /* if we're still here, we're screwed */
+ execv(path, (const void *)argv); /* make gcc shut up */
+ _exit(1); /* if we're still here, we're screwed */
}
- return(pid);
+ return (pid);
}
#endif
int
rb_gettimeofday(struct timeval *tv, void *tz)
{
- return(gettimeofday(tv, tz));
+ return (gettimeofday(tv, tz));
}
#endif
tv.tv_nsec = (useconds * 1000);
tv.tv_sec = seconds;
nanosleep(&tv, NULL);
-#else
+#else
struct timeval tv;
tv.tv_sec = seconds;
tv.tv_usec = useconds;
select(0, NULL, NULL, NULL, &tv);
#endif
}
-#endif /* !WINDOWS */
+
+/* this is to keep some linkers from bitching about exporting a non-existant symbol..bleh */
+char *
+rb_strerror(int error)
+{
+ return strerror(error);
+}
+
+int
+rb_kill(pid_t pid, int sig)
+{
+ return kill(pid, sig);
+}
+
+int
+rb_setenv(const char *name, const char *value, int overwrite)
+{
+ return setenv(name, value, overwrite);
+}
+
+pid_t
+rb_waitpid(pid_t pid, int *status, int options)
+{
+ return waitpid(pid, status, options);
+}
+
+pid_t
+rb_getpid(void)
+{
+ return getpid();
+}
+#endif /* !WIN32 */
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: win32.c 25038 2008-01-23 16:03:08Z androsyn $
+ * $Id: win32.c 26092 2008-09-19 15:13:52Z androsyn $
*/
#include <libratbox_config.h>
#include <ratbox_lib.h>
#include <commio-int.h>
-#ifdef WIN32
+#ifdef _WIN32
static HWND hwnd;
#define EPOCH_BIAS Const64(116444736000000000)
pid_t
-getpid()
+rb_getpid()
{
return GetCurrentProcessId();
}
GetSystemTimeAsFileTime(&ft.ft_val);
/* seconds since epoch */
- tp->tv_sec = (long) ((ft.ft_i64 - EPOCH_BIAS) / Const64(10000000));
+ tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / Const64(10000000));
/* microseconds remaining */
- tp->tv_usec = (long) ((ft.ft_i64 / Const64(10)) % Const64(1000000));
+ tp->tv_usec = (long)((ft.ft_i64 / Const64(10)) % Const64(1000000));
return 0;
}
}
pid_t
-waitpid(int pid, int *status, int flags)
+rb_waitpid(int pid, int *status, int flags)
{
DWORD timeout = (flags & WNOHANG) ? 0 : INFINITE;
HANDLE hProcess;
{
if(GetExitCodeProcess(hProcess, &waitcode))
{
- *status = (int) ((waitcode & 0xff) << 8);
+ *status = (int)((waitcode & 0xff) << 8);
CloseHandle(hProcess);
return pid;
}
}
int
-setenv(const char *name, const char *value, int overwrite)
+rb_setenv(const char *name, const char *value, int overwrite)
{
char *buf;
int len;
}
int
-kill(int pid, int sig)
+rb_kill(int pid, int sig)
{
HANDLE hProcess;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
}
-int
-rb_pass_fd_to_process(int fd, pid_t process, rb_fde_t *F)
+/*
+ * packet format is
+ uint32_t magic
+ uint8_t protocol count
+ WSAPROTOCOL_INFO * count
+ size_t datasize
+ data
+
+ */
+
+static int
+make_wsaprotocol_info(pid_t process, rb_fde_t *F, WSAPROTOCOL_INFO * inf)
{
WSAPROTOCOL_INFO info;
- WSADuplicateSocket((SOCKET)fd, process, &info);
- rb_write(F, &info, sizeof(info));
+ if(!WSADuplicateSocket((SOCKET) rb_get_fd(F), process, &info))
+ {
+ memcpy(inf, &info, sizeof(WSAPROTOCOL_INFO));
+ return 1;
+ }
return 0;
}
+static rb_fde_t *
+make_fde_from_wsaprotocol_info(void *data)
+{
+ WSAPROTOCOL_INFO *info = data;
+ SOCKET t;
+ t = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, info, 0, 0);
+ if(t == INVALID_SOCKET)
+ {
+ rb_get_errno();
+ return NULL;
+ }
+ return rb_open(t, RB_FD_SOCKET, "remote_socket");
+}
+
+static uint8_t fd_buf[16384];
+#define MAGIC_CONTROL 0xFF0ACAFE
+
+int
+rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid)
+{
+ size_t bufsize =
+ sizeof(uint32_t) + sizeof(uint8_t) + (sizeof(WSAPROTOCOL_INFO) * (size_t)count) +
+ sizeof(size_t) + datasize;
+ int i;
+ uint32_t magic = MAGIC_CONTROL;
+ void *ptr;
+ if(count > 4)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ if(bufsize > sizeof(fd_buf))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ memset(fd_buf, 0, sizeof(fd_buf));
+
+ ptr = fd_buf;
+ memcpy(ptr, &magic, sizeof(magic));
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(magic));
+ *((uint8_t *)ptr) = count;
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t));
+
+ for(i = 0; i < count; i++)
+ {
+ make_wsaprotocol_info(pid, F[i], (WSAPROTOCOL_INFO *) ptr);
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO));
+ }
+ memcpy(ptr, &datasize, sizeof(size_t));
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(size_t));
+ memcpy(ptr, data, datasize);
+ return rb_write(xF, fd_buf, bufsize);
+}
+
+#ifdef MYMIN
+#undef MYMIN
+#endif
+#define MYMIN(a, b) ((a) < (b) ? (a) : (b))
+
+int
+rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds)
+{
+ size_t minsize = sizeof(uint32_t) + sizeof(uint8_t) + sizeof(size_t);
+ size_t datalen;
+ ssize_t retlen;
+ uint32_t magic;
+ uint8_t count;
+ unsigned int i;
+ void *ptr;
+ ssize_t ret;
+ memset(fd_buf, 0, sizeof(fd_buf)); /* some paranoia here... */
+ ret = rb_read(F, fd_buf, sizeof(fd_buf));
+ if(ret <= 0)
+ {
+ return ret;
+ }
+ if(ret < (ssize_t) minsize)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ ptr = fd_buf;
+ memcpy(&magic, ptr, sizeof(uint32_t));
+ if(magic != MAGIC_CONTROL)
+ {
+ errno = EAGAIN;
+ return -1;
+ }
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint32_t));
+ memcpy(&count, ptr, sizeof(uint8_t));
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t));
+ for(i = 0; i < count && i < (unsigned int)nfds; i++)
+ {
+ rb_fde_t *tF = make_fde_from_wsaprotocol_info(ptr);
+ if(tF == NULL)
+ return -1;
+ xF[i] = tF;
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO));
+ }
+ memcpy(&datalen, ptr, sizeof(size_t));
+ ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(size_t));
+ retlen = MYMIN(datalen, datasize);
+ memcpy(data, ptr, datalen);
+ return retlen;
+}
static LRESULT CALLBACK
rb_process_events(HWND nhwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
void
rb_sleep(unsigned int seconds, unsigned int useconds)
{
- struct timeval tv;
- tv.tv_sec = seconds;
- tv.tv_usec = useconds;
- select(0, NULL, NULL, NULL, &tv);
+ DWORD msec = seconds * 1000;;
+ Sleep(msec);
}
int
-rb_setup_fd_win32(rb_fde_t * F)
+rb_setup_fd_win32(rb_fde_t *F)
{
if(F == NULL)
return 0;
}
void
-rb_setselect_win32(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
int old_flags = F->pflags;
#undef strerror
#endif
-const char *
-wsock_strerror(int error)
+static const char *
+_rb_strerror(int error)
{
switch (error)
{
return strerror(error);
}
};
+
+char *
+rb_strerror(int error)
+{
+ static char buf[128];
+ rb_strlcpy(buf, _rb_strerror(error), sizeof(buf));
+ return buf;
+}
#else /* win32 not supported */
int
rb_init_netio_win32(void)
}
void
-rb_setselect_win32(rb_fde_t * F, unsigned int type, PF * handler, void *client_data)
+rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
errno = ENOSYS;
return;
}
int
-rb_setup_fd_win32(rb_fde_t * F)
+rb_setup_fd_win32(rb_fde_t *F)
{
errno = ENOSYS;
return -1;
}
-#endif /* WIN32 */
+#endif /* _WIN32 */
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: sslproc.c 25677 2008-07-06 04:21:42Z androsyn $
+ * $Id$
*/
#include <ratbox_lib.h>
#include "stdinc.h"
+
+
#include "s_conf.h"
#include "logger.h"
#include "listener.h"
#define ZIPSTATS_TIME 60
static void collect_zipstats(void *unused);
-static void ssl_read_ctl(rb_fde_t *F, void *data);
+static void ssl_read_ctl(rb_fde_t * F, void *data);
static int ssld_count;
-static char tmpbuf[READBUF_SIZE];
+static char tmpbuf[READBUF_SIZE];
static char nul = '\0';
#define MAXPASSFD 4
uint8_t dead;
};
-static void send_new_ssl_certs_one(ssl_ctl_t *ctl, const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params);
-static void send_init_prng(ssl_ctl_t *ctl, prng_seed_t seedtype, const char *path);
+static void send_new_ssl_certs_one(ssl_ctl_t * ctl, const char *ssl_cert,
+ const char *ssl_private_key, const char *ssl_dh_params);
+static void send_init_prng(ssl_ctl_t * ctl, prng_seed_t seedtype, const char *path);
static rb_dlink_list ssl_daemons;
-static inline int32_t buf_to_int32(char *buf)
+static inline int32_t
+buf_to_int32(char *buf)
{
int32_t x;
memcpy(&x, buf, sizeof(x));
return x;
}
-static inline void int32_to_buf(char *buf, int32_t x)
+static inline void
+int32_to_buf(char *buf, int32_t x)
{
memcpy(buf, &x, sizeof(x));
return;
}
-static inline uint16_t buf_to_uint16(char *buf)
+static inline uint16_t
+buf_to_uint16(char *buf)
{
uint16_t x;
memcpy(&x, buf, sizeof(x));
return x;
}
-static inline void uint16_to_buf(char *buf, uint16_t x)
+static inline void
+uint16_to_buf(char *buf, uint16_t x)
{
memcpy(buf, &x, sizeof(x));
return;
static ssl_ctl_t *
-allocate_ssl_daemon(rb_fde_t *F, rb_fde_t *P, int pid)
+allocate_ssl_daemon(rb_fde_t * F, rb_fde_t * P, int pid)
{
ssl_ctl_t *ctl;
-
+
if(F == NULL || pid < 0)
return NULL;
- ctl = rb_malloc(sizeof(ssl_ctl_t));
+ ctl = rb_malloc(sizeof(ssl_ctl_t));
ctl->F = F;
ctl->P = P;
ctl->pid = pid;
}
static void
-free_ssl_daemon(ssl_ctl_t *ctl)
+free_ssl_daemon(ssl_ctl_t * ctl)
{
rb_dlink_node *ptr;
ssl_ctl_buf_t *ctl_buf;
int x;
if(ctl->cli_count)
return;
-
+
RB_DLINK_FOREACH(ptr, ctl->readq.head)
{
ctl_buf = ptr->data;
for(x = 0; x < ctl_buf->nfds; x++)
- rb_close(ctl_buf->F[x]);
+ rb_close(ctl_buf->F[x]);
rb_free(ctl_buf->buf);
- rb_free(ctl_buf);
+ rb_free(ctl_buf);
}
RB_DLINK_FOREACH(ptr, ctl->writeq.head)
continue;
ctl->dead = 1;
ssld_count--;
- kill(ctl->pid, SIGKILL);
+ rb_kill(ctl->pid, SIGKILL);
}
}
static void
-ssl_dead(ssl_ctl_t *ctl)
+ssl_dead(ssl_ctl_t * ctl)
{
if(ctl->dead)
return;
-
+
ctl->dead = 1;
ssld_count--;
- kill(ctl->pid, SIGKILL); /* make sure the process is really gone */
+ rb_kill(ctl->pid, SIGKILL); /* make sure the process is really gone */
ilog(L_MAIN, "ssld helper died - attempting to restart");
sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld helper died - attempting to restart");
start_ssldaemon(1, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);
}
static void
-ssl_do_pipe(rb_fde_t *F, void *data)
+ssl_do_pipe(rb_fde_t * F, void *data)
{
int retlen;
ssl_ctl_t *ctl = data;
{
rb_fde_t *F1, *F2;
rb_fde_t *P1, *P2;
+#ifdef _WIN32
+ const char *suffix = ".exe";
+#else
+ const char *suffix = "";
+#endif
+
char fullpath[PATH_MAX + 1];
char fdarg[6];
const char *parv[2];
char buf[128];
+ char s_pid[10];
pid_t pid;
int started = 0, i;
if(ssld_spin_count > 20 && (rb_current_time() - last_spin < 5))
{
ilog(L_MAIN, "ssld helper is spinning - will attempt to restart in 1 minute");
- sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld helper is spinning - will attempt to restart in 1 minute");
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "ssld helper is spinning - will attempt to restart in 1 minute");
rb_event_add("restart_ssld_event", restart_ssld_event, NULL, 60);
ssld_wait = 1;
return 0;
ssld_spin_count++;
last_spin = rb_current_time();
+
if(ssld_path == NULL)
{
- rb_snprintf(fullpath, sizeof(fullpath), "%s/ssld", BINPATH);
-
+ rb_snprintf(fullpath, sizeof(fullpath), "%s/ssld%s", BINPATH, suffix);
+
if(access(fullpath, X_OK) == -1)
{
- rb_snprintf(fullpath, sizeof(fullpath), "%s/bin/ssld", ConfigFileEntry.dpath);
+ rb_snprintf(fullpath, sizeof(fullpath), "%s/bin/ssld%s",
+ ConfigFileEntry.dpath, suffix);
if(access(fullpath, X_OK) == -1)
{
- ilog(L_MAIN, "Unable to execute ssld in %s/bin or %s", ConfigFileEntry.dpath, BINPATH);
- return 0 ;
+ ilog(L_MAIN,
+ "Unable to execute ssld%s in %s/bin or %s",
+ ConfigFileEntry.dpath, suffix, BINPATH);
+ return 0;
}
}
ssld_path = rb_strdup(fullpath);
}
-
rb_strlcpy(buf, "-ircd ssld daemon helper", sizeof(buf));
parv[0] = buf;
parv[1] = NULL;
rb_set_buffers(F1, READBUF_SIZE);
rb_set_buffers(F2, READBUF_SIZE);
rb_snprintf(fdarg, sizeof(fdarg), "%d", rb_get_fd(F2));
- setenv("CTL_FD", fdarg, 1);
+ rb_setenv("CTL_FD", fdarg, 1);
rb_pipe(&P1, &P2, "SSL/TLS pipe");
rb_snprintf(fdarg, sizeof(fdarg), "%d", rb_get_fd(P1));
- setenv("CTL_PIPE", fdarg, 1);
-
- pid = rb_spawn_process(ssld_path, (const char **)parv);
+ rb_setenv("CTL_PIPE", fdarg, 1);
+ rb_snprintf(s_pid, sizeof(s_pid), "%d", getpid());
+ rb_setenv("CTL_PPID", s_pid, 1);
+#ifdef _WIN32
+ SetHandleInformation((HANDLE) rb_get_fd(F2), HANDLE_FLAG_INHERIT, 1);
+ SetHandleInformation((HANDLE) rb_get_fd(P1), HANDLE_FLAG_INHERIT, 1);
+#endif
+
+ pid = rb_spawn_process(ssld_path, (const char **) parv);
if(pid == -1)
{
ilog(L_MAIN, "Unable to create ssld: %s\n", strerror(errno));
send_init_prng(ctl, RB_PRNG_DEFAULT, NULL);
}
if(ssl_ok && ssl_cert != NULL && ssl_private_key != NULL)
- send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key, ssl_dh_params != NULL ? ssl_dh_params : "");
+ send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key,
+ ssl_dh_params != NULL ? ssl_dh_params : "");
ssl_read_ctl(ctl->F, ctl);
ssl_do_pipe(P2, ctl);
+
}
- return started;
+ return started;
}
static void
-ssl_process_zipstats(ssl_ctl_t *ctl, ssl_ctl_buf_t *ctl_buf)
+ssl_process_zipstats(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf)
{
struct Client *server;
struct ZipStats *zips;
int parc;
char *parv[6];
- parc = rb_string_to_array(ctl_buf->buf, parv, 6);
+ parc = rb_string_to_array(ctl_buf->buf, parv, 6);
server = find_server(NULL, parv[1]);
if(server == NULL || server->localClient == NULL || !IsCapable(server, CAP_ZIP))
return;
if(server->localClient->zipstats == NULL)
server->localClient->zipstats = rb_malloc(sizeof(struct ZipStats));
-
+
zips = server->localClient->zipstats;
zips->in += strtoull(parv[2], NULL, 10);
zips->in_wire += strtoull(parv[3], NULL, 10);
zips->out += strtoull(parv[4], NULL, 10);
zips->out_wire += strtoull(parv[5], NULL, 10);
-
+
if(zips->in > 0)
- zips->in_ratio = ((double)(zips->in - zips->in_wire) / (double) zips->in) * 100.00;
+ zips->in_ratio = ((double) (zips->in - zips->in_wire) / (double) zips->in) * 100.00;
else
zips->in_ratio = 0;
-
+
if(zips->out > 0)
- zips->out_ratio = ((double)(zips->out - zips->out_wire) / (double) zips->out) * 100.00;
+ zips->out_ratio = ((double) (zips->out - zips->out_wire) / (double) zips->out) * 100.00;
else
zips->out_ratio = 0;
}
static void
-ssl_process_dead_fd(ssl_ctl_t *ctl, ssl_ctl_buf_t *ctl_buf)
+ssl_process_dead_fd(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf)
{
struct Client *client_p;
char reason[256];
int32_t fd;
if(ctl_buf->buflen < 6)
- return; /* bogus message..drop it.. XXX should warn here */
-
+ return; /* bogus message..drop it.. XXX should warn here */
+
fd = buf_to_int32(&ctl_buf->buf[1]);
rb_strlcpy(reason, &ctl_buf->buf[5], sizeof(reason));
client_p = find_cli_fd_hash(fd);
return;
if(IsAnyServer(client_p))
{
- sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL, "ssld error for %s: %s", client_p->name, reason);
+ sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld error for %s: %s", client_p->name, reason);
ilog(L_SERVER, "ssld error for %s: %s", log_client_name(client_p, SHOW_IP), reason);
}
exit_client(client_p, client_p, &me, reason);
static void
-ssl_process_zip_ready(ssl_ctl_t *ctl, ssl_ctl_buf_t *ctl_buf)
+ssl_process_zip_ready(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf)
{
struct Client *client_p;
int32_t fd;
if(ctl_buf->buflen < 5)
- return; /* bogus message..drop it.. XXX should warn here */
-
+ return; /* bogus message..drop it.. XXX should warn here */
+
fd = buf_to_int32(&ctl_buf->buf[1]);
client_p = find_cli_fd_hash(fd);
if(client_p == NULL)
static void
-ssl_process_cmd_recv(ssl_ctl_t *ctl)
+ssl_process_cmd_recv(ssl_ctl_t * ctl)
{
static const char *cannot_setup_ssl = "ssld cannot setup ssl, check your certificates and private key";
static const char *no_ssl_or_zlib = "ssld has neither SSL/TLS or zlib support killing all sslds";
- rb_dlink_node *ptr, *next;
+ rb_dlink_node *ptr, *next;
ssl_ctl_buf_t *ctl_buf;
if(ctl->dead)
return;
RB_DLINK_FOREACH_SAFE(ptr, next, ctl->readq.head)
{
- ctl_buf = ptr->data;
- switch(*ctl_buf->buf)
+ ctl_buf = ptr->data;
+ switch (*ctl_buf->buf)
{
- case 'N':
- ssl_ok = 0; /* ssld says it can't do ssl/tls */
- break;
- case 'D':
- ssl_process_dead_fd(ctl, ctl_buf);
- break;
- case 'S':
- ssl_process_zipstats(ctl, ctl_buf);
- break;
- case 'I':
- ssl_ok = 0;
- ilog(L_MAIN, cannot_setup_ssl);
- sendto_realops_snomask(SNO_GENERAL, L_ALL, cannot_setup_ssl);
- case 'U':
- zlib_ok = 0;
- ssl_ok = 0;
- ilog(L_MAIN, no_ssl_or_zlib);
- sendto_realops_snomask(SNO_GENERAL, L_ALL, no_ssl_or_zlib);
- ssl_killall();
- break;
- case 'R':
- ssl_process_zip_ready(ctl, ctl_buf);
- break;
- case 'z':
- zlib_ok = 0;
- break;
- default:
- ilog(L_MAIN, "Received invalid command from ssld: %s", ctl_buf->buf);
- sendto_realops_snomask(SNO_GENERAL, L_ALL, "Received invalid command from ssld");
- break;
+ case 'N':
+ ssl_ok = 0; /* ssld says it can't do ssl/tls */
+ break;
+ case 'D':
+ ssl_process_dead_fd(ctl, ctl_buf);
+ break;
+ case 'S':
+ ssl_process_zipstats(ctl, ctl_buf);
+ break;
+ case 'I':
+ ssl_ok = 0;
+ ilog(L_MAIN, cannot_setup_ssl);
+ sendto_realops_snomask(SNO_GENERAL, L_ALL, cannot_setup_ssl);
+ case 'U':
+ zlib_ok = 0;
+ ssl_ok = 0;
+ ilog(L_MAIN, no_ssl_or_zlib);
+ sendto_realops_snomask(SNO_GENERAL, L_ALL, no_ssl_or_zlib);
+ ssl_killall();
+ break;
+ case 'R':
+ ssl_process_zip_ready(ctl, ctl_buf);
+ break;
+ case 'z':
+ zlib_ok = 0;
+ break;
+ default:
+ ilog(L_MAIN, "Received invalid command from ssld: %s", ctl_buf->buf);
+ sendto_realops_snomask(SNO_GENERAL, L_ALL, "Received invalid command from ssld");
+ break;
}
rb_dlinkDelete(ptr, &ctl->readq);
rb_free(ctl_buf->buf);
static void
-ssl_read_ctl(rb_fde_t *F, void *data)
+ssl_read_ctl(rb_fde_t * F, void *data)
{
ssl_ctl_buf_t *ctl_buf;
ssl_ctl_t *ctl = data;
ctl_buf->buf = rb_malloc(READSIZE);
retlen = rb_recv_fd_buf(ctl->F, ctl_buf->buf, READSIZE, ctl_buf->F, 4);
ctl_buf->buflen = retlen;
- if(retlen <= 0) {
+ if(retlen <= 0)
+ {
rb_free(ctl_buf->buf);
rb_free(ctl_buf);
}
else
rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->readq);
- } while(retlen > 0);
-
+ }
+ while(retlen > 0);
+
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
{
ssl_dead(ctl);
return;
- }
+ }
ssl_process_cmd_recv(ctl);
rb_setselect(ctl->F, RB_SELECT_READ, ssl_read_ctl, ctl);
}
{
ssl_ctl_t *ctl, *lowest = NULL;
rb_dlink_node *ptr;
-
+
RB_DLINK_FOREACH(ptr, ssl_daemons.head)
{
ctl = ptr->data;
if(ctl->dead)
continue;
- if(lowest == NULL) {
+ if(lowest == NULL)
+ {
lowest = ctl;
continue;
}
if(ctl->cli_count < lowest->cli_count)
lowest = ctl;
}
- return(lowest);
+ return (lowest);
}
static void
-ssl_write_ctl(rb_fde_t *F, void *data)
+ssl_write_ctl(rb_fde_t * F, void *data)
{
ssl_ctl_t *ctl = data;
ssl_ctl_buf_t *ctl_buf;
{
ctl_buf = ptr->data;
/* in theory unix sock_dgram shouldn't ever short write this.. */
- retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf, ctl_buf->buflen);
+ retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf, ctl_buf->buflen, ctl->pid);
if(retlen > 0)
{
rb_dlinkDelete(ptr, &ctl->writeq);
rb_close(ctl_buf->F[x]);
rb_free(ctl_buf->buf);
rb_free(ctl_buf);
-
+
}
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
{
ssl_dead(ctl);
return;
- } else {
+ }
+ else
+ {
rb_setselect(ctl->F, RB_SELECT_WRITE, ssl_write_ctl, ctl);
}
}
}
static void
-ssl_cmd_write_queue(ssl_ctl_t *ctl, rb_fde_t **F, int count, const void *buf, size_t buflen)
+ssl_cmd_write_queue(ssl_ctl_t * ctl, rb_fde_t ** F, int count, const void *buf, size_t buflen)
{
ssl_ctl_buf_t *ctl_buf;
- int x;
+ int x;
/* don't bother */
if(ctl->dead)
return;
-
+
ctl_buf = rb_malloc(sizeof(ssl_ctl_buf_t));
ctl_buf->buf = rb_malloc(buflen);
memcpy(ctl_buf->buf, buf, buflen);
ctl_buf->buflen = buflen;
-
+
for(x = 0; x < count && x < MAXPASSFD; x++)
{
- ctl_buf->F[x] = F[x];
+ ctl_buf->F[x] = F[x];
}
ctl_buf->nfds = count;
rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->writeq);
static void
-send_new_ssl_certs_one(ssl_ctl_t *ctl, const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params)
+send_new_ssl_certs_one(ssl_ctl_t * ctl, const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params)
{
size_t len;
- len = strlen(ssl_cert) + strlen(ssl_private_key) + strlen(ssl_dh_params) + 5;
+ len = strlen(ssl_cert) + strlen(ssl_private_key) + strlen(ssl_dh_params) + 5;
if(len > sizeof(tmpbuf))
{
- sendto_realops_snomask(SNO_GENERAL, L_ALL,
- "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
- len, sizeof(tmpbuf));
- ilog(L_MAIN, "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
- len, sizeof(tmpbuf));
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
+ len, sizeof(tmpbuf));
+ ilog(L_MAIN,
+ "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
+ len, sizeof(tmpbuf));
return;
}
- len = rb_snprintf(tmpbuf, sizeof(tmpbuf), "K%c%s%c%s%c%s%c", nul, ssl_cert, nul, ssl_private_key, nul, ssl_dh_params, nul);
+ len = rb_snprintf(tmpbuf, sizeof(tmpbuf), "K%c%s%c%s%c%s%c", nul, ssl_cert, nul,
+ ssl_private_key, nul, ssl_dh_params, nul);
ssl_cmd_write_queue(ctl, NULL, 0, tmpbuf, len);
}
static void
-send_init_prng(ssl_ctl_t *ctl, prng_seed_t seedtype, const char *path)
+send_init_prng(ssl_ctl_t * ctl, prng_seed_t seedtype, const char *path)
{
size_t len;
const char *s;
len = strlen(s) + 3;
if(len > sizeof(tmpbuf))
{
- sendto_realops_snomask(SNO_GENERAL, L_ALL,
- "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
- len, sizeof(tmpbuf));
- ilog(L_MAIN, "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
- len, sizeof(tmpbuf));
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
+ len, sizeof(tmpbuf));
+ ilog(L_MAIN,
+ "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
+ len, sizeof(tmpbuf));
return;
-
- }
+
+ }
len = rb_snprintf(tmpbuf, sizeof(tmpbuf), "I%c%s%c", seed, s, nul);
ssl_cmd_write_queue(ctl, NULL, 0, tmpbuf, len);
}
RB_DLINK_FOREACH(ptr, ssl_daemons.head)
{
ssl_ctl_t *ctl = ptr->data;
- send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key, ssl_dh_params);
+ send_new_ssl_certs_one(ctl, ssl_cert, ssl_private_key, ssl_dh_params);
}
}
-ssl_ctl_t *
-start_ssld_accept(rb_fde_t *sslF, rb_fde_t *plainF, int32_t id)
+ssl_ctl_t *
+start_ssld_accept(rb_fde_t * sslF, rb_fde_t * plainF, int32_t id)
{
rb_fde_t *F[2];
ssl_ctl_t *ctl;
}
ssl_ctl_t *
-start_ssld_connect(rb_fde_t *sslF, rb_fde_t *plainF, int32_t id)
+start_ssld_connect(rb_fde_t * sslF, rb_fde_t * plainF, int32_t id)
{
rb_fde_t *F[2];
ssl_ctl_t *ctl;
ctl = which_ssld();
ctl->cli_count++;
ssl_cmd_write_queue(ctl, F, 2, buf, sizeof(buf));
- return ctl;
+ return ctl;
}
-void
-ssld_decrement_clicount(ssl_ctl_t *ctl)
+void
+ssld_decrement_clicount(ssl_ctl_t * ctl)
{
if(ctl == NULL)
return;
void
start_zlib_session(void *data)
{
- struct Client *server = (struct Client *)data;
+ struct Client *server = (struct Client *) data;
uint16_t recvqlen;
uint8_t level;
void *xbuf;
server->localClient->event = NULL;
recvqlen = rb_linebuf_len(&server->localClient->buf_recvq);
-
+
len = recvqlen + hdr;
if(len > READBUF_SIZE)
{
- rb_free(buf);
- sendto_realops_snomask(SNO_GENERAL, L_ALL, "ssld - attempted to pass message of %zd len, max len %d, giving up", len, READBUF_SIZE);
+ sendto_realops_snomask(SNO_GENERAL, L_ALL,
+ "ssld - attempted to pass message of %zd len, max len %d, giving up",
+ len, READBUF_SIZE);
ilog(L_MAIN, "ssld - attempted to pass message of %zd len, max len %d, giving up", len, READBUF_SIZE);
exit_client(server, server, server, "ssld readbuf exceeded");
return;
}
- buf = rb_malloc(len);
+ buf = rb_malloc(len);
level = ConfigFileEntry.compression_level;
int32_to_buf(&buf[1], rb_get_fd(server->localClient->F));
- buf[5] = (char)level;
+ buf[5] = (char) level;
- recvq_start = &buf[6];
+ recvq_start = &buf[6];
server->localClient->zipstats = rb_malloc(sizeof(struct ZipStats));
xbuf = recvq_start;
{
cpylen = rb_linebuf_get(&server->localClient->buf_recvq, xbuf, left, LINEBUF_PARTIAL, LINEBUF_RAW);
left -= cpylen;
- xbuf += cpylen;
- } while(cpylen > 0);
+ xbuf = (void *) (((uintptr_t) xbuf) + cpylen);
+ }
+ while(cpylen > 0);
/* Pass the socket to ssld. */
*buf = 'Z';
rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF1, &xF2, "Initial zlib socketpairs");
- F[0] = server->localClient->F;
+ F[0] = server->localClient->F;
F[1] = xF1;
- del_from_cli_fd_hash(server);
+ del_from_cli_fd_hash(server);
server->localClient->F = xF2;
/* need to redo as what we did before isn't valid now */
int32_to_buf(&buf[1], rb_get_fd(server->localClient->F));
id = rb_get_fd(target_p->localClient->F);
int32_to_buf(&buf[1], rb_get_fd(target_p->localClient->F));
- rb_strlcpy(odata, target_p->name, (sizeof(buf)-len));
- len += strlen(odata) + 1; /* Get the \0 as well */
- ssl_cmd_write_queue(target_p->localClient->ssl_ctl, NULL, 0, buf, len);
+ rb_strlcpy(odata, target_p->name, (sizeof(buf) - len));
+ len += strlen(odata) + 1; /* Get the \0 as well */
+ ssl_cmd_write_queue(target_p->localClient->ssl_ctl, NULL, 0, buf, len);
}
}
}
ctl = ptr->data;
if(ctl->dead && !ctl->cli_count)
{
- free_ssl_daemon(ctl);
+ free_ssl_daemon(ctl);
}
}
}
return ssld_count;
}
-void init_ssld(void)
+void
+init_ssld(void)
{
rb_event_addish("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
rb_event_addish("cleanup_dead_ssld", cleanup_dead_ssl, NULL, 1200);
}
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: ssld.c 25677 2008-07-06 04:21:42Z androsyn $
+ * $Id$
*/
#endif
static void setup_signals(void);
+static pid_t ppid;
-static inline int32_t buf_to_int32(char *buf)
+static inline int32_t
+buf_to_int32(char *buf)
{
int32_t x;
memcpy(&x, buf, sizeof(x));
return x;
}
-static inline void int32_to_buf(char *buf, int32_t x)
+static inline void
+int32_to_buf(char *buf, int32_t x)
{
memcpy(buf, &x, sizeof(x));
return;
}
-static inline uint16_t buf_to_uint16(char *buf)
+static inline uint16_t
+buf_to_uint16(char *buf)
{
uint16_t x;
memcpy(&x, buf, sizeof(x));
return x;
}
-static inline void uint16_to_buf(char *buf, uint16_t x)
+static inline void
+uint16_to_buf(char *buf, uint16_t x)
{
memcpy(buf, &x, sizeof(x));
return;
}
-
+
static char inbuf[READBUF_SIZE];
#ifdef HAVE_LIBZ
#define FLAG_ZIP 0x02
#define FLAG_CORK 0x04
#define FLAG_DEAD 0x08
-#define FLAG_SSL_W_WANTS_R 0x10 /* output needs to wait until input possible */
-#define FLAG_SSL_R_WANTS_W 0x20 /* input needs to wait until output possible */
+#define FLAG_SSL_W_WANTS_R 0x10 /* output needs to wait until input possible */
+#define FLAG_SSL_R_WANTS_W 0x20 /* input needs to wait until output possible */
#define IsSSL(x) ((x)->flags & FLAG_SSL)
#define IsZip(x) ((x)->flags & FLAG_ZIP)
static rb_dlink_list connid_hash_table[CONN_HASH_SIZE];
static rb_dlink_list dead_list;
-static void conn_mod_read_cb(rb_fde_t * fd, void *data);
+static void conn_mod_read_cb(rb_fde_t *fd, void *data);
static void conn_mod_write_sendq(rb_fde_t *, void *data);
static void conn_plain_write_sendq(rb_fde_t *, void *data);
static void mod_write_ctl(rb_fde_t *, void *data);
-static void conn_plain_read_cb(rb_fde_t * fd, void *data);
-static void mod_cmd_write_queue(mod_ctl_t *ctl, const void *data, size_t len);
+static void conn_plain_read_cb(rb_fde_t *fd, void *data);
+static void mod_cmd_write_queue(mod_ctl_t * ctl, const void *data, size_t len);
static const char *remote_closed = "Remote host closed the connection";
static int ssl_ok;
#ifdef HAVE_LIBZ
static void
ssld_free(void *unused, void *ptr)
{
- rb_free(ptr);
+ rb_free(ptr);
}
#endif
{
zlib_stream_t *stream = conn->stream;
inflateEnd(&stream->instream);
- deflateEnd(&stream->outstream);
+ deflateEnd(&stream->outstream);
}
#endif
rb_free(conn);
close_conn(conn_t * conn, int wait_plain, const char *fmt, ...)
{
va_list ap;
- char reason[128]; /* must always be under 250 bytes */
+ char reason[128]; /* must always be under 250 bytes */
char buf[256];
int len;
if(IsDead(conn))
return;
-
+
rb_rawbuf_flush(conn->modbuf_out, conn->mod_fd);
rb_rawbuf_flush(conn->plainbuf_out, conn->plain_fd);
rb_close(conn->mod_fd);
if(!wait_plain || fmt == NULL)
{
rb_close(conn->plain_fd);
-
+
if(conn->id >= 0)
rb_dlinkDelete(&conn->node, connid_hash(conn->id));
rb_dlinkAdd(conn, &conn->node, &dead_list);
return;
}
- rb_setselect(conn->plain_fd, RB_SELECT_WRITE|RB_SELECT_READ, NULL, NULL);
+ rb_setselect(conn->plain_fd, RB_SELECT_WRITE | RB_SELECT_READ, NULL, NULL);
va_start(ap, fmt);
rb_vsnprintf(reason, sizeof(reason), fmt, ap);
va_end(ap);
}
static conn_t *
-make_conn(mod_ctl_t *ctl, rb_fde_t * mod_fd, rb_fde_t * plain_fd)
+make_conn(mod_ctl_t * ctl, rb_fde_t *mod_fd, rb_fde_t *plain_fd)
{
conn_t *conn = rb_malloc(sizeof(conn_t));
conn->ctl = ctl;
conn = ptr->data;
if(!IsSSL(conn))
continue;
-
+
count = rb_ssl_handshake_count(conn->mod_fd);
/* nothing needs to do this more than twice in ten seconds i don't think */
if(count > 2)
close_conn(conn, WAIT_PLAIN, "Handshake flooding");
else
rb_ssl_clear_handshake_count(conn->mod_fd);
- }
- HASH_WALK_END
-
-}
+ }
+HASH_WALK_END}
static void
-conn_mod_write_sendq(rb_fde_t * fd, void *data)
+conn_mod_write_sendq(rb_fde_t *fd, void *data)
{
conn_t *conn = data;
const char *err;
return;
}
- while ((retlen = rb_rawbuf_flush(conn->modbuf_out, fd)) > 0)
+ while((retlen = rb_rawbuf_flush(conn->modbuf_out, fd)) > 0)
conn->mod_out += retlen;
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
common_zlib_deflate(conn_t * conn, void *buf, size_t len)
{
int ret, have;
- z_stream *outstream = &((zlib_stream_t *)conn->stream)->outstream;
+ z_stream *outstream = &((zlib_stream_t *) conn->stream)->outstream;
outstream->next_in = buf;
outstream->avail_in = len;
outstream->next_out = (Bytef *) outbuf;
}
if(outstream->avail_in != 0)
{
- /* avail_in isn't empty...*/
+ /* avail_in isn't empty... */
close_conn(conn, WAIT_PLAIN, "error compressing data, avail_in != 0");
return;
}
static void
common_zlib_inflate(conn_t * conn, void *buf, size_t len)
{
- int ret, have;
- ((zlib_stream_t *)conn->stream)->instream.next_in = buf;
- ((zlib_stream_t *)conn->stream)->instream.avail_in = len;
- ((zlib_stream_t *)conn->stream)->instream.next_out = (Bytef *) outbuf;
- ((zlib_stream_t *)conn->stream)->instream.avail_out = sizeof(outbuf);
+ int ret, have = 0;
+ ((zlib_stream_t *) conn->stream)->instream.next_in = buf;
+ ((zlib_stream_t *) conn->stream)->instream.avail_in = len;
+ ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf;
+ ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf);
- while (((zlib_stream_t *)conn->stream)->instream.avail_in)
+ while(((zlib_stream_t *) conn->stream)->instream.avail_in)
{
- ret = inflate(&((zlib_stream_t *)conn->stream)->instream, Z_NO_FLUSH);
+ ret = inflate(&((zlib_stream_t *) conn->stream)->instream, Z_NO_FLUSH);
if(ret != Z_OK)
{
if(!strncmp("ERROR ", buf, 6))
close_conn(conn, WAIT_PLAIN, "Inflate failed: %s", zError(ret));
return;
}
- have = sizeof(outbuf) - ((zlib_stream_t *)conn->stream)->instream.avail_out;
+ have = sizeof(outbuf) - ((zlib_stream_t *) conn->stream)->instream.avail_out;
- if(((zlib_stream_t *)conn->stream)->instream.avail_in)
+ if(((zlib_stream_t *) conn->stream)->instream.avail_in)
{
conn_plain_write(conn, outbuf, have);
have = 0;
- ((zlib_stream_t *)conn->stream)->instream.next_out = (Bytef *) outbuf;
- ((zlib_stream_t *)conn->stream)->instream.avail_out = sizeof(outbuf);
+ ((zlib_stream_t *) conn->stream)->instream.next_out = (Bytef *) outbuf;
+ ((zlib_stream_t *) conn->stream)->instream.avail_out = sizeof(outbuf);
}
}
if(have == 0)
static void
-conn_plain_read_cb(rb_fde_t * fd, void *data)
+conn_plain_read_cb(rb_fde_t *fd, void *data)
{
conn_t *conn = data;
int length = 0;
if(plain_check_cork(conn))
return;
- while (1)
+ while(1)
{
if(IsDead(conn))
return;
}
static void
-conn_mod_read_cb(rb_fde_t * fd, void *data)
+conn_mod_read_cb(rb_fde_t *fd, void *data)
{
conn_t *conn = data;
const char *err = remote_closed;
return;
}
- while (1)
+ while(1)
{
if(IsDead(conn))
return;
if(length == 0 || (length < 0 && !rb_ignore_errno(errno)))
{
- if(length == 0) {
+ if(length == 0)
+ {
close_conn(conn, WAIT_PLAIN, "%s", remote_closed);
return;
}
}
conn_plain_write_sendq(conn->plain_fd, conn);
return;
- }
+ }
conn->mod_in += length;
#ifdef HAVE_LIBZ
if(IsZip(conn))
}
static void
-conn_plain_write_sendq(rb_fde_t * fd, void *data)
+conn_plain_write_sendq(rb_fde_t *fd, void *data)
{
conn_t *conn = data;
int retlen;
if(IsDead(conn))
return;
- while ((retlen = rb_rawbuf_flush(conn->plainbuf_out, fd)) > 0)
+ while((retlen = rb_rawbuf_flush(conn->plainbuf_out, fd)) > 0)
{
conn->plain_out += retlen;
}
close_conn(data, NO_WAIT, NULL);
return;
}
-
+
if(rb_rawbuf_length(conn->plainbuf_out) > 0)
rb_setselect(conn->plain_fd, RB_SELECT_WRITE, conn_plain_write_sendq, conn);
}
static void
-ssl_process_accept_cb(rb_fde_t * F, int status, struct sockaddr *addr, rb_socklen_t len, void *data)
+ssl_process_accept_cb(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t len, void *data)
{
conn_t *conn = data;
if(status == RB_OK)
}
static void
-ssl_process_connect_cb(rb_fde_t * F, int status, void *data)
+ssl_process_connect_cb(rb_fde_t *F, int status, void *data)
{
conn_t *conn = data;
if(status == RB_OK)
if(rb_get_type(conn->mod_fd) & RB_FD_UNKNOWN)
{
-
+
rb_set_type(conn->mod_fd, RB_FD_SOCKET);
}
if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN)
if(id < 0)
return;
-
+
odata = &ctlb->buf[5];
conn = conn_find_by_id(id);
#ifdef HAVE_LIBZ
static void
-zlib_send_zip_ready(mod_ctl_t *ctl, conn_t *conn)
+zlib_send_zip_ready(mod_ctl_t * ctl, conn_t * conn)
{
char buf[5];
-
+
buf[0] = 'R';
int32_to_buf(&buf[1], conn->id);
mod_cmd_write_queue(conn->ctl, buf, sizeof(buf));
id = buf_to_int32(&ctlb->buf[1]);
conn_add_id_hash(conn, id);
- level = (uint8_t) ctlb->buf[5];
+ level = (uint8_t)ctlb->buf[5];
recvqlen = ctlb->buflen - hdr;
recvq_start = &ctlb->buf[6];
SetZip(conn);
conn->stream = rb_malloc(sizeof(zlib_stream_t));
- instream = &((zlib_stream_t *)conn->stream)->instream;
- outstream = &((zlib_stream_t *)conn->stream)->outstream;
-
+ instream = &((zlib_stream_t *) conn->stream)->instream;
+ outstream = &((zlib_stream_t *) conn->stream)->outstream;
+
instream->total_in = 0;
instream->total_out = 0;
instream->zalloc = (alloc_func) ssld_alloc;
instream->zfree = (free_func) ssld_free;
instream->data_type = Z_ASCII;
- inflateInit(&((zlib_stream_t *)conn->stream)->instream);
+ inflateInit(&((zlib_stream_t *) conn->stream)->instream);
outstream->total_in = 0;
outstream->total_out = 0;
if(level > 9)
level = Z_DEFAULT_COMPRESSION;
- deflateInit(&((zlib_stream_t *)conn->stream)->outstream, level);
+ deflateInit(&((zlib_stream_t *) conn->stream)->outstream, level);
if(recvqlen > 0)
common_zlib_inflate(conn, recvq_start, recvqlen);
zlib_send_zip_ready(ctl, conn);
{
char *path;
prng_seed_t seed_type;
-
- seed_type = (prng_seed_t)ctl_buf->buf[1];
+
+ seed_type = (prng_seed_t) ctl_buf->buf[1];
path = &ctl_buf->buf[2];
rb_init_prng(path, seed_type);
}
const char *invalid = "I";
mod_cmd_write_queue(ctl, invalid, strlen(invalid));
return;
- }
+ }
}
static void
-send_nossl_support(mod_ctl_t *ctl, mod_ctl_buf_t *ctlb)
+send_nossl_support(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
{
static const char *nossl_cmd = "N";
conn_t *conn;
int32_t id;
if(ctlb != NULL)
- {
+ {
conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]);
id = buf_to_int32(&ctlb->buf[1]);
if(id >= 0)
conn_add_id_hash(conn, id);
close_conn(conn, WAIT_PLAIN, "libratbox reports no SSL/TLS support");
- }
- mod_cmd_write_queue(ctl, nossl_cmd, strlen(nossl_cmd));
+ }
+ mod_cmd_write_queue(ctl, nossl_cmd, strlen(nossl_cmd));
}
static void
-send_i_am_useless(mod_ctl_t *ctl)
+send_i_am_useless(mod_ctl_t * ctl)
{
static const char *useless = "U";
mod_cmd_write_queue(ctl, useless, strlen(useless));
}
static void
-send_nozlib_support(mod_ctl_t *ctl, mod_ctl_buf_t *ctlb)
+send_nozlib_support(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb)
{
static const char *nozlib_cmd = "z";
conn_t *conn;
if(id >= 0)
conn_add_id_hash(conn, id);
close_conn(conn, WAIT_PLAIN, "libratbox reports no zlib support");
- }
+ }
mod_cmd_write_queue(ctl, nozlib_cmd, strlen(nozlib_cmd));
}
break;
}
case 'I':
- init_prng(ctl, ctl_buf);
- break;
+ init_prng(ctl, ctl_buf);
+ break;
case 'S':
{
process_stats(ctl, ctl_buf);
case 'Z':
send_nozlib_support(ctl, ctl_buf);
break;
-
+
#endif
default:
break;
static void
-mod_read_ctl(rb_fde_t * F, void *data)
+mod_read_ctl(rb_fde_t *F, void *data)
{
mod_ctl_buf_t *ctl_buf;
mod_ctl_t *ctl = data;
rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->readq);
}
}
- while (retlen > 0);
+ while(retlen > 0);
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
exit(0);
}
static void
-mod_write_ctl(rb_fde_t * F, void *data)
+mod_write_ctl(rb_fde_t *F, void *data)
{
mod_ctl_t *ctl = data;
mod_ctl_buf_t *ctl_buf;
{
ctl_buf = ptr->data;
retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf,
- ctl_buf->buflen);
+ ctl_buf->buflen, ppid);
if(retlen > 0)
{
rb_dlinkDelete(ptr, &ctl->writeq);
- for (x = 0; x < ctl_buf->nfds; x++)
+ for(x = 0; x < ctl_buf->nfds; x++)
rb_close(ctl_buf->F[x]);
rb_free(ctl_buf->buf);
rb_free(ctl_buf);
}
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
- exit(0);
-
+ exit(0);
+
rb_setselect(ctl->F, RB_SELECT_WRITE, mod_write_ctl, ctl);
}
}
static void
-read_pipe_ctl(rb_fde_t * F, void *data)
+read_pipe_ctl(rb_fde_t *F, void *data)
{
int retlen;
- while ((retlen = rb_read(F, inbuf, sizeof(inbuf))) > 0)
+ while((retlen = rb_read(F, inbuf, sizeof(inbuf))) > 0)
{
;; /* we don't do anything with the pipe really, just care if the other process dies.. */
}
int
main(int argc, char **argv)
{
- const char *s_ctlfd, *s_pipe;
+ const char *s_ctlfd, *s_pipe, *s_pid;
int ctlfd, pipefd, x, maxfd;
maxfd = maxconn();
+
s_ctlfd = getenv("CTL_FD");
s_pipe = getenv("CTL_PIPE");
+ s_pid = getenv("CTL_PPID");
- if(s_ctlfd == NULL || s_pipe == NULL)
+ if(s_ctlfd == NULL || s_pipe == NULL || s_pid == NULL)
{
- fprintf(stderr, "This is ircd-ratbox ssld. You know you aren't supposed to run me directly?\n");
- fprintf(stderr, "You get an Id tag for this: $Id: ssld.c 25677 2008-07-06 04:21:42Z androsyn $\n");
+ fprintf(stderr,
+ "This is ircd-ratbox ssld. You know you aren't supposed to run me directly?\n");
+ fprintf(stderr,
+ "You get an Id tag for this: $Id$\n");
fprintf(stderr, "Have a nice life\n");
exit(1);
}
ctlfd = atoi(s_ctlfd);
pipefd = atoi(s_pipe);
-
- for (x = 0; x < maxfd; x++)
+ ppid = atoi(s_pid);
+ x = 0;
+#ifndef _WIN32
+ for(x = 0; x < maxfd; x++)
{
if(x != ctlfd && x != pipefd && x > 2)
close(x);
}
-
x = open("/dev/null", O_RDWR);
if(x >= 0)
{
if(x > 2)
close(x);
}
-
+#endif
setup_signals();
rb_lib_init(NULL, NULL, NULL, 0, maxfd, 1024, 4096);
rb_init_rawbuffers(1024);
- ssl_ok = rb_supports_ssl();
-
+ ssl_ok = rb_supports_ssl();
mod_ctl = rb_malloc(sizeof(mod_ctl_t));
mod_ctl->F = rb_open(ctlfd, RB_FD_SOCKET, "ircd control socket");
mod_ctl->F_pipe = rb_open(pipefd, RB_FD_PIPE, "ircd pipe");
/* this is really useless... */
send_i_am_useless(mod_ctl);
/* sleep until the ircd kills us */
- rb_sleep(2<<30, 0);
+ rb_sleep(2 << 30, 0);
exit(1);
}
}
-
+#ifndef _WIN32
static void
dummy_handler(int sig)
{
return;
}
+#endif
static void
setup_signals()
{
+#ifndef _WIN32
struct sigaction act;
act.sa_flags = 0;
act.sa_handler = dummy_handler;
sigaction(SIGALRM, &act, 0);
+#endif
}
-