diff --git a/ChangeLog b/ChangeLog index a6d3c34..672fec0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,19 @@ 0.2.8 ===== +- 22-Mar-2003: - made compile on SUSE5.3 (libc5) + - added --enable-almost-static feature switch. This will + build siproxd statically linked against libosip & pthreads + (for Flifl use) +- 16-Mar-2003: - ERROR on unknown keywords in config file + - introduced INFO logging 0.2.7 ===== - 15-Mar-2003: - released 0.2.7 -- 9-Mar-2003: - replaced get_ip_by_ifname by a simpler (has to be *BSD tested) +- 9-Mar-2003: - replaced get_ip_by_ifname by simpler code + (still to be *BSD tested) - removed old host-name based style for in/outbound interface - configuration. This is only not done via interface names + configuration. This is only done via interface names - experimental: The host part of UA registration entries can be masqueraded (mask_host, masked_host config items) Siemens SIP phones seem to need this 'feature'. diff --git a/README b/README index bd2fbc3..6dea322 100644 --- a/README +++ b/README @@ -25,7 +25,11 @@ REQUIREMENTS - libosip-0.8.8 (http://www.fsf.org/software/osip/) - pthreads (should be part of any Linux distribution) -Up to now, siporxd only has been tested under an i386 Redhat Linux 6.0. +Up to now, siporxd only has been tested under: +- Redhat Linux 6.0 +- Redhat Linux 7.2 +- SUSE 5.3 (libc5) + However, it should build and run under newer versions (feedback is welcome). @@ -35,6 +39,10 @@ HOW TO GET STARTED - ./configure + For Flifl: use ./configure --enable-almost-static + This will build siproxd statically linked against libosib, pthreads and + dynamically against libc. + - make - make install diff --git a/TODO b/TODO index 59a58c4..22d781b 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,10 @@ TODOs, in random order: - Documentation (yeah, yeah...) +- support for proxy chaining + +- change host comparison to IP address level (resolve name, then compare addr) + - feature: don't bind to 0.0.0.0 address, but only to inbound/outbound IF's (defined by IFNAME) diff --git a/acinclude.m4 b/acinclude.m4 deleted file mode 100644 index a7710c8..0000000 --- a/acinclude.m4 +++ /dev/null @@ -1,226 +0,0 @@ -dnl -------------------------------------------------------------------- -dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl This macro figures out how to build C programs using POSIX -dnl threads. It sets the PTHREAD_LIBS output variable to the threads -dnl library and linker flags, and the PTHREAD_CFLAGS output variable -dnl to any special C compiler flags that are needed. (The user can also -dnl force certain compiler flags/libs to be tested by setting these -dnl environment variables.) -dnl -dnl Also sets PTHREAD_CC to any special C compiler that is needed for -dnl multi-threaded programs (defaults to the value of CC otherwise). -dnl (This is necessary on AIX to use the special cc_r compiler alias.) -dnl -dnl If you are only building threads programs, you may wish to -dnl use these variables in your default LIBS, CFLAGS, and CC: -dnl -dnl LIBS="$PTHREAD_LIBS $LIBS" -dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS" -dnl CC="$PTHREAD_CC" -dnl -dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute -dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE -dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). -dnl -dnl ACTION-IF-FOUND is a list of shell commands to run if a threads -dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands -dnl to run it if it is not found. If ACTION-IF-FOUND is not specified, -dnl the default action will define HAVE_PTHREAD. -dnl -dnl Please let the authors know if this macro fails on any platform, -dnl or if you have any other suggestions or comments. This macro was -dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org) -dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread -dnl macros posted by AFC to the autoconf macro repository. We are also -dnl grateful for the helpful feedback of numerous users. -dnl -dnl @version $Id$ -dnl @author Steven G. Johnson and Alejandro Forero Cuervo - -AC_DEFUN([ACX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_HOST]) -acx_pthread_ok=no - -# We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on True64 or Sequent). -# It gets checked for in the link test anyway. - -# First of all, check if the user has set any of the PTHREAD_LIBS, -# etcetera environment variables, and if threads linking works using -# them: -if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) - AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) - AC_MSG_RESULT($acx_pthread_ok) - if test x"$acx_pthread_ok" = xno; then - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" - fi - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" -fi - -# We must check for the threads library under a number of different -# names; the ordering is very important because some systems -# (e.g. DEC) have both -lpthread and -lpthreads, where one of the -# libraries is broken (non-POSIX). - -# Create a list of thread flags to try. Items starting with a "-" are -# C compiler flags, and other items are library names, except for "none" -# which indicates that we try without any flags at all. - -acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt" - -# The ordering *is* (sometimes) important. Some notes on the -# individual items follow: - -# pthreads: AIX (must check this before -lpthread) -# none: in case threads are in libc; should be tried before -Kthread and -# other compiler flags to prevent continual compiler warnings -# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) -# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) -# -pthreads: Solaris/gcc -# -mthreads: Mingw32/gcc, Lynx/gcc -# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads too; -# also defines -D_REENTRANT) -# pthread: Linux, etcetera -# --thread-safe: KAI C++ - -case "${host_cpu}-${host_os}" in - *solaris*) - - # On Solaris (at least, for some versions), libc contains stubbed - # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (We need to link with -pthread or - # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather - # a function called by this macro, so we could check for that, but - # who knows whether they'll stub that too in a future libc.) So, - # we'll just look for -pthreads and -lpthread first: - - acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags" - ;; -esac - -if test x"$acx_pthread_ok" = xno; then -for flag in $acx_pthread_flags; do - - case $flag in - none) - AC_MSG_CHECKING([whether pthreads work without any flags]) - ;; - - -*) - AC_MSG_CHECKING([whether pthreads work with $flag]) - PTHREAD_CFLAGS="$flag" - ;; - - *) - AC_MSG_CHECKING([for the pthreads library -l$flag]) - PTHREAD_LIBS="-l$flag" - ;; - esac - - save_LIBS="$LIBS" - save_CFLAGS="$CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - - # Check for various functions. We must include pthread.h, - # since some functions may be macros. (On the Sequent, we - # need a special flag -Kthread to make this header compile.) - # We check for pthread_join because it is in -lpthread on IRIX - # while pthread_create is in libc. We check for pthread_attr_init - # due to DEC craziness with -lpthreads. We check for - # pthread_cleanup_push because it is one of the few pthread - # functions on Solaris that doesn't have a non-functional libc stub. - # We try pthread_create on general principles. - AC_TRY_LINK([#include ], - [pthread_t th; pthread_join(th, 0); - pthread_attr_init(0); pthread_cleanup_push(0, 0); - pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], - [acx_pthread_ok=yes]) - - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" - - AC_MSG_RESULT($acx_pthread_ok) - if test "x$acx_pthread_ok" = xyes; then - break; - fi - - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" -done -fi - -# Various other checks: -if test "x$acx_pthread_ok" = xyes; then - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - - # Detect AIX lossage: threads are created detached by default - # and the JOINABLE attribute has a nonstandard name (UNDETACHED). - AC_MSG_CHECKING([for joinable pthread attribute]) - AC_TRY_LINK([#include ], - [int attr=PTHREAD_CREATE_JOINABLE;], - ok=PTHREAD_CREATE_JOINABLE, ok=unknown) - if test x"$ok" = xunknown; then - AC_TRY_LINK([#include ], - [int attr=PTHREAD_CREATE_UNDETACHED;], - ok=PTHREAD_CREATE_UNDETACHED, ok=unknown) - fi - if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then - AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok, - [Define to the necessary symbol if this constant - uses a non-standard name on your system.]) - fi - AC_MSG_RESULT(${ok}) - if test x"$ok" = xunknown; then - AC_MSG_WARN([we do not know how to create joinable pthreads]) - fi - - AC_MSG_CHECKING([if more special flags are required for pthreads]) - flag=no - case "${host_cpu}-${host_os}" in - *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";; - *solaris* | alpha*-osf*) flag="-D_REENTRANT";; - esac - AC_MSG_RESULT(${flag}) - if test "x$flag" != xno; then - PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" - fi - - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" - - # More AIX lossage: must compile with cc_r - AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) -else - PTHREAD_CC="$CC" -fi - -AC_SUBST(PTHREAD_LIBS) -AC_SUBST(PTHREAD_CFLAGS) -AC_SUBST(PTHREAD_CC) - -# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test x"$acx_pthread_ok" = xyes; then - ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) - : -else - acx_pthread_ok=no - $2 -fi - -])dnl ACX_PTHREAD - diff --git a/config.h.in b/config.h.in index c101ddf..48d7e02 100644 --- a/config.h.in +++ b/config.h.in @@ -48,6 +48,9 @@ /* Define if you have the getuid function. */ #undef HAVE_GETUID +/* Define if you have the hstrerror function. */ +#undef HAVE_HSTRERROR + /* Define if you have the read function. */ #undef HAVE_READ @@ -151,3 +154,6 @@ /* Define if you have POSIX threads libraries and header files. */ #undef HAVE_PTHREAD +/* typedef socklen_t available */ +#undef socklen_t + diff --git a/configure.in b/configure.in index 05fa46b..5e9ec3e 100644 --- a/configure.in +++ b/configure.in @@ -5,6 +5,8 @@ dnl before time a lot happend before start of history dnl 8-Sep-2002 tries included more tests for used functions dnl 17-Sep-2002 tries fail configure if needed libs not there dnl 14-Nov-2002 tries support for *BSD systems +dnl 22-Mar-2003 tries check for sockaddr_t, hstrerror() +dnl feature almost-static (for Fli4l use) dnl dnl dnl @@ -70,7 +72,6 @@ for each in $extra_libs; do done - dnl dnl system specific stuff dnl @@ -105,11 +106,46 @@ case "$target" in ;; esac +dnl +dnl Features: +dnl almost-static (only available on Linux, yet) +dnl +case "$target" in + *-*-linux*) + AC_MSG_CHECKING("build almost static") + AC_ARG_ENABLE(almost-static, + [ --enable-almost-static only link dynamically to libc, rest static], + build_almost_static=$enableval, + build_almost_static="no") + AC_MSG_RESULT($build_almost_static) + ;; + + *) + AC_MSG_RESULT("FEATURE almost-static not available on this platform") + ;; +esac + + dnl dnl Check for libosip dnl -AC_CHECK_LIB(osip, parser_init,, - echo "*** ERROR: libosip is required!";exit 1;) +if test "x$build_almost_static" = "xno"; then + dnl link dynamically (default) + AC_CHECK_LIB(osip, parser_init,, + echo "*** ERROR: libosip is required!";exit 1;) +else + dnl link statically to this lib + dnl (this probably only will work on linux yet...) + AC_MSG_CHECKING("where I can find libosip.a") + libosip_static=`find /lib /usr/lib /usr/local/lib $extra_libs \ + -name libosip.a 2>/dev/null|head -1` + if test "x$libosip_static" != "x"; then + LIBS="$libosip_static $LIBS" + AC_MSG_RESULT($libosip_static) + else + echo "*** ERROR: a static libosip library is required!";exit 1; + fi +fi dnl @@ -117,9 +153,26 @@ dnl Check for pthreads dnl ACX_PTHREAD(, echo "*** ERROR: pthreads is required!"; exit 1;) -LIBS="$PTHREAD_LIBS $LIBS" -CFLAGS="$CFLAGS $PTHREAD_CFLAGS" -CC="$PTHREAD_CC" +if test "x$build_almost_static" = "xno"; then + dnl link dynamically (default) + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + CC="$PTHREAD_CC" +else + dnl link statically to this lib + dnl (this probably only will work on linux yet...) + AC_MSG_CHECKING("where I can find static threads library") + libpthreads_static=`find /lib /usr/lib /usr/local/lib $extra_libs \ + -name 'lib*thread*.a' 2>/dev/null| \ + egrep 'lib[p]?thread[s]?.a' |head -1` + if test "x$libpthreads_static" != "x"; then + LIBS="$libpthreads_static $LIBS" + AC_MSG_RESULT($libpthreads_static) + else + echo "*** ERROR: a static threads library is required!";exit 1; + fi + CC="$PTHREAD_CC" +fi dnl @@ -138,6 +191,14 @@ AC_TYPE_SIZE_T AC_HEADER_TIME AC_STRUCT_TM +dnl check for typedef socklen (not available on SUSE 5.3 for example) +AC_MSG_CHECKING("typedef socklen_t") +AC_EGREP_HEADER([typedef.*socklen_t], sys/socket.h, + AC_MSG_RESULT("available"), + AC_MSG_RESULT("not available - create DEFINE to uint") + AC_DEFINE(socklen_t, [unsigned int],[typedef socklen_t available]) +) + dnl dnl Checks for library functions. dnl @@ -149,7 +210,7 @@ AC_CHECK_FUNCS(getopt_long daemon syslog) AC_CHECK_FUNCS(getuid setuid getgid setgid getpwnam chroot) AC_CHECK_FUNCS(socket bind select read send sendto) AC_CHECK_FUNCS(strncpy strchr strstr sprintf vfprintf vsnprintf) -AC_CHECK_FUNCS(fgets sscanf) +AC_CHECK_FUNCS(fgets sscanf hstrerror) AC_SUBST(CPPFLAGS) diff --git a/src/auth.c b/src/auth.c index f72e553..d43299b 100644 --- a/src/auth.c +++ b/src/auth.c @@ -134,7 +134,7 @@ static char *auth_generate_nonce() { /* yeah, I know... should be a better algorithm */ sprintf(nonce, "%8.8lx%8.8lx%8.8x%8.8x", - tv.tv_sec, tv.tv_usec, rand(), rand() ); + (long)tv.tv_sec, (long)tv.tv_usec, rand(), rand() ); DEBUGC(DBCLASS_AUTH,"created nonce=\"%s\"",nonce); return nonce; diff --git a/src/log.c b/src/log.c index d533859..695c055 100644 --- a/src/log.c +++ b/src/log.c @@ -107,7 +107,7 @@ void log_error(char *file, int line, const char *format, ...) { } else { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); - syslog(LOG_USER|LOG_WARNING, "%s:%i %s", file, line, string); + syslog(LOG_USER|LOG_WARNING, "%s:%i ERROR:%s", file, line, string); } va_end(ap); @@ -136,7 +136,36 @@ void log_warn(char *file, int line, const char *format, ...) { } else { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); - syslog(LOG_USER|LOG_NOTICE, "%s:%i %s", file, line, string); + syslog(LOG_USER|LOG_NOTICE, "%s:%i WARNING:%s", file, line, string); + } + + va_end(ap); + fflush(stderr); + return; + +} + + +void log_info(char *file, int line, const char *format, ...) { + va_list ap; + time_t t; + struct tm *tim; + char string[128]; + + va_start(ap, format); + + if (! log_to_syslog) { + /* not running as daemon - log to STDERR */ + time(&t); + tim=localtime(&t); + fprintf(stderr,"%2.2i:%2.2i:%2.2i INFO:%s:%i ",tim->tm_hour, + tim->tm_min, tim->tm_sec,file,line); + vfprintf(stderr, format, ap); + fprintf(stderr,"\n"); + } else { + /* running as daemon - log via SYSLOG facility */ + vsnprintf(string, sizeof(string), format, ap); + syslog(LOG_USER|LOG_NOTICE, "%s:%i INFO:%s", file, line, string); } va_end(ap); diff --git a/src/log.h b/src/log.h index 5662307..af57972 100644 --- a/src/log.h +++ b/src/log.h @@ -50,6 +50,9 @@ void log_error(char *file, int line, const char *format, ...); #define WARN(F...) log_warn(__FILE__, __LINE__,F) void log_warn(char *file, int line, const char *format, ...); +#define INFO(F...) log_info(__FILE__, __LINE__,F) +void log_info(char *file, int line, const char *format, ...); + /* tobedone: dump a buffer */ #define DUMP_BUFFER(C,F,L) log_dump_buffer(C,__FILE__, __LINE__,F,L) void log_dump_buffer(int class, char *file, int line, diff --git a/src/readconf.c b/src/readconf.c index 00c4279..9cc48e1 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -248,7 +248,14 @@ static int parse_config (FILE *configfile) { break; } - } - } + } // for configoptions + + /* + * complain if we hit a unknown keyword + */ + if (configoptions[k].keyword == NULL) { + ERROR("unknown keyword in config file, line:\"%s\"",buff); + } + } // while return STS_SUCCESS; } diff --git a/src/siproxd.c b/src/siproxd.c index 31b384b..9c66b15 100644 --- a/src/siproxd.c +++ b/src/siproxd.c @@ -174,6 +174,7 @@ int main (int argc, char *argv[]) } + INFO(PACKAGE"-"VERSION"-"BUILDSTR" started"); /* * Main loop */ diff --git a/src/sock.c b/src/sock.c index c1f0f94..9b543d7 100644 --- a/src/sock.c +++ b/src/sock.c @@ -60,6 +60,7 @@ int sipsock_listen (void) { listen_socket=sockbind(ipaddr, configuration.sip_listen_port); if (listen_socket==0) return STS_FAILURE; /* failure*/ + INFO("listening on port %i", configuration.sip_listen_port); DEBUGC(DBCLASS_NET,"bound listen socket %i",listen_socket); return STS_SUCCESS; } diff --git a/src/utils.c b/src/utils.c index efd5dc2..8a74d06 100644 --- a/src/utils.c +++ b/src/utils.c @@ -241,7 +241,11 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) { hostentry=gethostbyname(hostname); if (hostentry==NULL) { +#ifdef HAVE_HSTRERROR ERROR("gethostbyname(%s) failed: %s",hostname,hstrerror(h_errno)); +#else + ERROR("gethostbyname(%s) failed: h_errno=%i",hostname,h_errno); +#endif return STS_FAILURE; }