diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..da61a1d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +src/icecast +src/.deps +src/.libs +config.h +conf/*.dist +*.o +.DS_Store +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +compile +config.cache +config.guess +config.sub +config.h.in +config.log +config.status +configure +depcomp +install-sh +libtool +ltconfig +ltmain.sh +missing +mkinstalldirs +*.tar.gz diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..cae10be7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "m4"] + path = m4 + url = https://git.xiph.org/icecast/m4.git +[submodule "src/common"] + path = src/common + url = https://git.xiph.org/icecast/common.git diff --git a/configure.in b/configure.in index 157291c3..3c2aef65 100644 --- a/configure.in +++ b/configure.in @@ -158,9 +158,9 @@ AC_SUBST(ICECAST_OPTIONAL) AC_SUBST(HAVE_KATE) AC_SUBST(KATE_LIBS) -AC_OUTPUT([Makefile conf/Makefile src/Makefile src/avl/Makefile -src/httpp/Makefile src/thread/Makefile src/log/Makefile -src/net/Makefile src/timing/Makefile doc/Makefile doc/img/Makefile +AC_OUTPUT([Makefile conf/Makefile src/Makefile src/common/avl/Makefile +src/common/httpp/Makefile src/common/thread/Makefile src/common/log/Makefile +src/common/net/Makefile src/common/timing/Makefile doc/Makefile doc/img/Makefile doc/assets/Makefile doc/assets/css/Makefile doc/assets/font/Makefile doc/assets/img/Makefile web/Makefile admin/Makefile win32/Makefile win32/res/Makefile examples/Makefile]) diff --git a/m4 b/m4 new file mode 160000 index 00000000..06ff01f6 --- /dev/null +++ b/m4 @@ -0,0 +1 @@ +Subproject commit 06ff01f6acf3b644061eecdb5509cb899048e70c diff --git a/m4/ac_config_libconfig_in.m4 b/m4/ac_config_libconfig_in.m4 deleted file mode 100644 index d0d34246..00000000 --- a/m4/ac_config_libconfig_in.m4 +++ /dev/null @@ -1,270 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_config_libconfig_in.html -dnl -# AC_CONFIG_LIBCONFIG_IN(LIBRARY, DESTINATION, MODULES) -# ----------------------------------------------------- -# Generate a custom LIBRARY-config script. Create the script in the -# DESTINATION directory, including support for MODULES. -AC_DEFUN([AC_CONFIG_LIBCONFIG_IN], -[# create a custom library-config file ($1-config) -m4_if(AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG, [true], - [AC_PATH_PROG(PKG_CONFIG, pkg-config)]) -pushdef([LIBCONFIG_DIR], [m4_if([$2], , , [$2/])]) -LIBCONFIG_FILE="LIBCONFIG_DIR[]$1-config.in" -AC_SUBST(target)dnl -AC_SUBST(host)dnl -AC_SUBST(build)dnl -dnl create directory if it does not preexist -m4_if([$2], , , [AS_MKDIR_P([$2])]) -AC_MSG_NOTICE([creating $LIBCONFIG_FILE]) -echo '#! /bin/sh' >$LIBCONFIG_FILE -echo "# $1-config library configuration script" >>$LIBCONFIG_FILE -echo '# generated by ac_config_libconfig_in.m4' >>$LIBCONFIG_FILE -echo ' ' >>$LIBCONFIG_FILE -echo 'template_version="1.0.0"' >>$LIBCONFIG_FILE -echo ' ' >>$LIBCONFIG_FILE -echo 'package="@PACKAGE@"' >>$LIBCONFIG_FILE -echo ' ' >>$LIBCONFIG_FILE -echo '# usage instructions if no options given' >>$LIBCONFIG_FILE -echo 'if test "'"\$""#"'" -eq 0; then' >>$LIBCONFIG_FILE -echo ' cat <>$LIBCONFIG_FILE -m4_if($3, , - [echo 'Usage: $1-config [[OPTIONS]]' >>$LIBCONFIG_FILE], - [echo 'Usage: $1-config [[OPTIONS]] [[LIBRARIES]]' >>$LIBCONFIG_FILE]) -echo 'Options:' >>$LIBCONFIG_FILE -echo ' [[--prefix[=DIR]]]' >>$LIBCONFIG_FILE -echo ' [[--exec-prefix[=DIR]]]' >>$LIBCONFIG_FILE -echo ' [[--package]]' >>$LIBCONFIG_FILE -echo ' [[--version]]' >>$LIBCONFIG_FILE -echo ' [[--cppflags]]' >>$LIBCONFIG_FILE -echo ' [[--cflags-only]]' >>$LIBCONFIG_FILE -echo ' [[--cflags]]' >>$LIBCONFIG_FILE -echo ' [[--libs]]' >>$LIBCONFIG_FILE -echo ' [[--help]]' >>$LIBCONFIG_FILE -m4_if($3, , , - [echo 'Libraries:' >>$LIBCONFIG_FILE - for module in $1 $3 ; do - echo " $module" >>$LIBCONFIG_FILE ; - done]) -echo 'EOF' >>$LIBCONFIG_FILE -echo 'fi' >>$LIBCONFIG_FILE -echo ' ' >>$LIBCONFIG_FILE -echo '# parse options' >>$LIBCONFIG_FILE -echo 'o=""' >>$LIBCONFIG_FILE -echo 'h=""' >>$LIBCONFIG_FILE -echo 'for i' >>$LIBCONFIG_FILE -echo 'do' >>$LIBCONFIG_FILE -echo ' case $i in' >>$LIBCONFIG_FILE -options="prefix exec-prefix eprefix package version cppflags cflags-only cflags libs bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir infodir mandir target host build pkgdatadir pkglibdir pkgincludedir template-version help" -echo ' --prefix=*) prefix=`echo $i | sed -e "s/--prefix=//"` ;;' >>$LIBCONFIG_FILE -echo ' --exec-prefix=*) exec_prefix=`echo $i | sed -e "s/--exec-prefix=//"` ;;' >>$LIBCONFIG_FILE -echo ' --eprefix=*) exec_prefix=`echo $i | sed -e "s/--eprefix=//"` ;;' >>$LIBCONFIG_FILE -for option in $options ; do - case $option in - exec-prefix) echo " --$option) echo_exec_prefix=\"yes\" ;;" >>$LIBCONFIG_FILE ;; - template-version) echo " --$option) echo_template_version=\"yes\" ;;" >>$LIBCONFIG_FILE ;; - cflags-only) echo " --$option) echo_cflags_only=\"yes\" ;;" >>$LIBCONFIG_FILE ;; - *) echo " --$option) echo_$option=\"yes\" ;;" >>$LIBCONFIG_FILE ;; - esac -done -m4_if($3, , , - [for module in $1 $3 ; do - echo " $module) echo_module_$module=\"yes\" ;" >>$LIBCONFIG_FILE ; - echo ' echo_module="yes" ;;' >>$LIBCONFIG_FILE ; - done]) -echo ' //*|/*//*|./*//*) echo_extra="yes" ;;' >>$LIBCONFIG_FILE -echo ' *) eval "echo Unknown option: $i" ; exit 1 ;;' >>$LIBCONFIG_FILE -echo ' esac' >>$LIBCONFIG_FILE -echo 'done' >>$LIBCONFIG_FILE -echo ' ' >>$LIBCONFIG_FILE -# in the order of occurence a standard automake Makefile -echo '# defaults from configure; set only if not set previously' >>$LIBCONFIG_FILE -vars="prefix exec_prefix bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir infodir mandir includedir target host build" -for var in $vars ; do - echo "if test -z \"\$$var\" ; then" >>$LIBCONFIG_FILE - echo " $var=\"@$var@\"" >>$LIBCONFIG_FILE - echo 'fi' >>$LIBCONFIG_FILE -done -echo ' ' >>$LIBCONFIG_FILE -echo '# generate output' >>$LIBCONFIG_FILE -echo 'if test x$echo_module != xyes ; then' >>$LIBCONFIG_FILE -echo ' echo_module_$1="yes"' >>$LIBCONFIG_FILE -echo 'fi' >>$LIBCONFIG_FILE -AC_CONFIG_LIBCONFIG_IN_MODULES(m4_if([$3], , [$1], [m4_translit([$1 $3], [ ], [,])]))dnl -for option in $options extra; do - case $option in - exec-prefix) echo "if test x\$echo_exec_prefix = xyes ; then" >>$LIBCONFIG_FILE ;; - template-version) echo "if test x\$echo_template_version = xyes ; then" >>$LIBCONFIG_FILE ;; - cflags-only) echo "if test x\$echo_cflags_only = xyes ; then" >>$LIBCONFIG_FILE ;; - *) echo "if test x\$echo_$option = xyes ; then" >>$LIBCONFIG_FILE ;; - esac - case $option in - exec-prefix | eprefix) echo ' o="$o $exec_prefix"' >>$LIBCONFIG_FILE ;; - template-version) echo ' o="$o $template_version"' >>$LIBCONFIG_FILE ;; - cflags-only) echo ' o="$o $cflags"' >>$LIBCONFIG_FILE ;; - cppflags) echo ' o="$o $cppflags"' >>$LIBCONFIG_FILE ;; - cflags) -# echo ' i=`eval echo "$includedir"`' >>$LIBCONFIG_FILE ; -# echo ' i=`eval echo "$i"`' >>$LIBCONFIG_FILE ; -# echo ' if test "_$i" != "_/usr/include" ; then' >>$LIBCONFIG_FILE ; -# echo ' o="$o -I$includedir"' >>$LIBCONFIG_FILE ; -# echo ' fi' >>$LIBCONFIG_FILE ; - echo ' o="$o $cppflags $cflags"' >>$LIBCONFIG_FILE ;; - libs) echo ' o="$o -L$libdir $libs"' >>$LIBCONFIG_FILE ;; - help) echo ' h="1"' >>$LIBCONFIG_FILE ;; - pkgdatadir) echo " o=\"$o \${datadir}/\${package}\"" >>$LIBCONFIG_FILE ;; - pkglibdir) echo " o=\"$o \${libdir}/\${package}\"" >>$LIBCONFIG_FILE ;; - pkgincludedir) echo " o=\"$o \${includedir}/\${package}\"" >>$LIBCONFIG_FILE ;; - extra) - echo ' v=`echo $i | sed -e s://:\$:g`' >>$LIBCONFIG_FILE ; - echo ' v=`eval "echo $v"`' >>$LIBCONFIG_FILE ; - echo ' o="$o $v"' >>$LIBCONFIG_FILE ;; - *) echo " o=\"$o \$$option\"" >>$LIBCONFIG_FILE - esac - echo 'fi' >>$LIBCONFIG_FILE -done -echo ' ' >>$LIBCONFIG_FILE -echo '# output data' >>$LIBCONFIG_FILE -echo 'o=`eval "echo $o"`' >>$LIBCONFIG_FILE -echo 'o=`eval "echo $o"`' >>$LIBCONFIG_FILE -echo 'if test -n "$o" ; then ' >>$LIBCONFIG_FILE -echo ' eval "echo $o"' >>$LIBCONFIG_FILE -echo 'fi' >>$LIBCONFIG_FILE -echo ' ' >>$LIBCONFIG_FILE -echo '# help text' >>$LIBCONFIG_FILE -echo 'if test ! -z "$h" ; then ' >>$LIBCONFIG_FILE -echo ' cat <>$LIBCONFIG_FILE -echo 'All available options:' >>$LIBCONFIG_FILE -echo ' --prefix=DIR and change \$prefix and \$exec-prefix' >>$LIBCONFIG_FILE -echo ' --exec-prefix=DIR (affects all other options)' >>$LIBCONFIG_FILE -echo ' --prefix \$prefix $prefix' >>$LIBCONFIG_FILE -echo ' --exec_prefix or... ' >>$LIBCONFIG_FILE -echo ' --eprefix \$exec_prefix $exec_prefix' >>$LIBCONFIG_FILE -echo ' --version \$version $version' >>$LIBCONFIG_FILE -echo ' --cppflags C preprocessor flags' >>$LIBCONFIG_FILE -echo ' --cflags-only C compiler flags' >>$LIBCONFIG_FILE -echo ' --cflags C preprocessor and compiler flags' >>$LIBCONFIG_FILE -echo ' --libs -L\$libdir \$LIBS $libs' >>$LIBCONFIG_FILE -echo ' --package \$package $package' >>$LIBCONFIG_FILE -echo ' --bindir \$bindir $bindir' >>$LIBCONFIG_FILE -echo ' --sbindir \$sbindir $sbindir' >>$LIBCONFIG_FILE -echo ' --libexecdir \$libexecdir $libexecdir' >>$LIBCONFIG_FILE -echo ' --datadir \$datadir $datadir' >>$LIBCONFIG_FILE -echo ' --sysconfdir \$sysconfdir $sysconfdir' >>$LIBCONFIG_FILE -echo ' --sharedstatedir \$sharedstatedir$sharedstatedir' >>$LIBCONFIG_FILE -echo ' --localstatedir \$localstatedir $localstatedir' >>$LIBCONFIG_FILE -echo ' --libdir \$libdir $libdir' >>$LIBCONFIG_FILE -echo ' --infodir \$infodir $infodir' >>$LIBCONFIG_FILE -echo ' --mandir \$mandir $mandir' >>$LIBCONFIG_FILE -echo ' --target \$target $target' >>$LIBCONFIG_FILE -echo ' --host \$host $host' >>$LIBCONFIG_FILE -echo ' --build \$build $build' >>$LIBCONFIG_FILE -echo ' --pkgdatadir \$datadir/\$package ${datadir}/${package}' >>$LIBCONFIG_FILE -echo ' --pkglibdir \$libdir/\$package ${libdir}/${package}' >>$LIBCONFIG_FILE -echo ' --pkgincludedir \$includedir/\$package ${includedir}/${package}' >>$LIBCONFIG_FILE -echo ' --template-version \$template_version $template_version' >>$LIBCONFIG_FILE -echo ' --help' >>$LIBCONFIG_FILE -echo 'EOF' >>$LIBCONFIG_FILE -echo 'fi' >>$LIBCONFIG_FILE -m4_pushdef([LIBCONFIG_UP], [m4_translit([$1], [a-z], [A-Z])])dnl -LIBCONFIG_UP[]_CONFIG="LIBCONFIG_DIR[]$1-config" -AC_SUBST(LIBCONFIG_UP[]_CONFIG) -dnl AC_CONFIG_FILES(LIBCONFIG_DIR[]$1[-config], [chmod +x ]LIBCONFIG_DIR[]$1[-config]) -m4_popdef([LIBCONFIG_DIR]) -m4_popdef([LIBCONFIG_UP]) -]) - - -# AC_CONFIG_LIBCONFIG_IN_MODULES [(MODULE1 [, MODULE2 [, ...]])] -# -------------------------------------------------------------- -#Output shell script using custom module variables. -AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_MODULES], -[m4_if([$1], , , - [# create module definition for $1 -dnl we're going to need uppercase, lowercase and user-friendly versions of the -dnl string `MODULE' -m4_pushdef([MODULE_UP], m4_translit([$1], [a-z], [A-Z]))dnl -m4_pushdef([MODULE_DOWN], m4_translit([$1], [A-Z], [a-z]))dnl -if test -z "$MODULE_DOWN[]_cppflags" ; then - if test -n "$MODULE_UP[]_CPPFLAGS" ; then - MODULE_DOWN[]_cppflags="$MODULE_UP[]_CPPFLAGS" - else -dnl AC_MSG_WARN([variable `MODULE_DOWN[]_cppflags' undefined]) - MODULE_DOWN[]_cppflags='' - fi -fi -AC_SUBST(MODULE_DOWN[]_cppflags) -if test -z "$MODULE_DOWN[]_cflags" ; then - if test -n "$MODULE_UP[]_CFLAGS" ; then - MODULE_DOWN[]_cflags="$MODULE_UP[]_CFLAGS" - else -dnl AC_MSG_WARN([variable `MODULE_DOWN[]_cflags' undefined]) - MODULE_DOWN[]_cflags='' - fi -fi -AC_SUBST(MODULE_DOWN[]_cflags)dnl -if test -z "$MODULE_DOWN[]_libs" ; then - if test -n "$MODULE_UP[]_LIBS" ; then - MODULE_DOWN[]_libs="$MODULE_UP[]_LIBS" - else - AC_MSG_WARN([variable `MODULE_DOWN[]_libs' and `MODULE_UP[]_LIBS' undefined]) - MODULE_DOWN[]_libs='-l$1' - fi - if test -n "$MODULE_UP[]_LIBDEPS" ; then - MODULE_DOWN[]_libs="$MODULE_DOWN[]_libs $MODULE_UP[]_LIBDEPS" - fi -fi -AC_SUBST(MODULE_DOWN[]_libs)dnl -if test -z "$MODULE_UP[]_VERSION" ; then - AC_MSG_WARN([variable `MODULE_UP[]_VERSION' undefined]) - MODULE_UP[]_VERSION="$VERSION" -fi -AC_SUBST(MODULE_UP[]_VERSION)dnl -echo 'if test x$echo_module_$1 = xyes ; then' >>$LIBCONFIG_FILE -AC_CONFIG_LIBCONFIG_IN_MODULES_VARS([cppflags], [MODULE_DOWN[]_cppflags], [cppflags]) -AC_CONFIG_LIBCONFIG_IN_MODULES_VARS([cflags], [MODULE_DOWN[]_cflags], [cflags]) -AC_CONFIG_LIBCONFIG_IN_MODULES_VARS([libs], [MODULE_DOWN[]_libs], [libs]) -AC_CONFIG_LIBCONFIG_IN_MODULES_VARS([version], [MODULE_UP[]_VERSION], [modversion]) -echo 'fi' >>$LIBCONFIG_FILE -m4_popdef([MODULE_UP])dnl -m4_popdef([MODULE_DOWN])dnl -AC_CONFIG_LIBCONFIG_IN_MODULES(m4_shift($@))])dnl -]) - - -# AC_CONFIG_LIBCONFIG_IN_MODULES_VARS [(VAR, SUBSTITUTION, -# PKGCONFIG_ARGS)] -# -------------------------------------------------------- -# Output AC_CONFIG_LIBCONFIG_IN_MODULES variables. -# VAR = variable to set -# SUBSTITUTION = set if pkg-config is not available -# PKGCONFIG_ARGS = args for pkg-config -AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_MODULES_VARS], -[m4_if(AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG, [true], -[ -echo 'if test -x "`which pkg-config`" ; then' >>$LIBCONFIG_FILE -echo ' if pkg-config --atleast-pkgconfig-version=0.7 --exists "MODULE_DOWN"; then' >>$LIBCONFIG_FILE -echo ' $1="@S|@$1 `pkg-config --$3 MODULE_DOWN`"' >>$LIBCONFIG_FILE -echo ' fi' >>$LIBCONFIG_FILE -echo 'else' >>$LIBCONFIG_FILE -echo ' $1="@S|@$1 @$2@"' >>$LIBCONFIG_FILE -echo 'fi' >>$LIBCONFIG_FILE -], -[echo ' $1="@S|@$1 @$2@"' >>$LIBCONFIG_FILE -])]) - - -# AC_CONFIG_LIBCONFIG_IN_PKGCONFIG -# -------------------------------- -# Enable pkgconfig support in libconfig script (default) -AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_PKGCONFIG], -[m4_define([AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG], [true]) -])dnl - - -# AC_CONFIG_LIBCONFIG_IN_STATIC -# ----------------------------- -# Disable pkgconfig support in libconfig script -AC_DEFUN([AC_CONFIG_LIBCONFIG_IN_STATIC], -[m4_define([AC_CONFIG_LIBCONFIG_IN_USEPKGCONFIG], [false]) -])dnl diff --git a/m4/acx_pthread.m4 b/m4/acx_pthread.m4 deleted file mode 100644 index a67ba039..00000000 --- a/m4/acx_pthread.m4 +++ /dev/null @@ -1,199 +0,0 @@ -dnl Available from the GNU Autoconf Macro Archive at: -dnl http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html -dnl -AC_DEFUN([ACX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_HOST]) -AC_LANG_SAVE -AC_LANG_C -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, and "pthread-config" -# which is a program returning the flags for the Pth emulation library. - -acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" - -# 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) -# ... -mt is also the pthreads flag for HP/aCC -# pthread: Linux, etcetera -# --thread-safe: KAI C++ -# pthread-config: use pthread-config program (for GNU Pth library) - -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 -pthreads/-mt/ - # -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="-pthreads pthread -mt -pthread $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" - ;; - - pthread-config) - AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) - if test x"$acx_pthread_config" = xno; then continue; fi - PTHREAD_CFLAGS="`pthread-config --cflags`" - PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" - ;; - - *) - 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: JOINABLE attribute is called UNDETACHED. - AC_MSG_CHECKING([for joinable pthread attribute]) - attr_name=unknown - for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - AC_TRY_LINK([#include ], [int attr=$attr; return attr;], - [attr_name=$attr; break]) - done - AC_MSG_RESULT($attr_name) - if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then - AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, - [Define to necessary symbol if this constant - uses a non-standard name on your system.]) - fi - - AC_MSG_CHECKING([if more special flags are required for pthreads]) - flag=no - case "${host_cpu}-${host_os}" in - *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; - *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; - esac - AC_MSG_RESULT(${flag}) - if test "x$flag" != xno; then - PTHREAD_CPPFLAGS="$flag $PTHREAD_CPPFLAGS" - fi - - AC_CHECK_FUNCS([pthread_spin_lock]) - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" - - # More AIX lossage: must compile with xlc_r or cc_r - if test x"$GCC" != xyes; then - AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) - else - PTHREAD_CC=$CC - fi -else - PTHREAD_CC="$CC" -fi - -AC_SUBST(PTHREAD_LIBS) -AC_SUBST(PTHREAD_CFLAGS) -AC_SUBST(PTHREAD_CPPFLAGS) -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 -AC_LANG_RESTORE -])dnl ACX_PTHREAD diff --git a/m4/ogg.m4 b/m4/ogg.m4 deleted file mode 100644 index 4b00f900..00000000 --- a/m4/ogg.m4 +++ /dev/null @@ -1,65 +0,0 @@ -# Configure paths for libogg -# updated by Karl Heyes 10-Jun-2003 -# Jack Moffitt 10-21-2000 -# Shamelessly stolen from Owen Taylor and Manish Singh - -dnl XIPH_PATH_OGG([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libogg, and define OGG_CFLAGS OGG_LDFLAGS and OGG_LIBS -dnl -AC_DEFUN([XIPH_PATH_OGG], -[dnl -AC_ARG_VAR([OGG_PREFIX],[path to ogg installation]) -AC_ARG_WITH(ogg, - [AC_HELP_STRING([--with-ogg=PREFIX], - [Prefix where libogg is installed (optional)])], - ogg_prefix="$withval", - ogg_prefix="$OGG_PREFIX" - ) -if test "x$ogg_prefix" = "x" -o "x$ogg_prefix" = "xyes"; then - if test "x$prefix" = "xNONE"; then - ogg_prefix=/usr/local - else - ogg_prefix="$prefix" - fi -fi - -XIPH_GCC_WARNING([-I$ogg_prefix/include],, - [ OGG_CFLAGS="-I$ogg_prefix/include" - OGG_LDFLAGS="-L$ogg_prefix/lib" - ]) -AC_CACHE_CHECK([for libogg], xt_cv_lib_ogg, -[dnl -OGG_LIBS="-logg" - -# -# check if the installed Ogg is sufficiently new. -# -ac_save_CFLAGS="$CFLAGS" -ac_save_LIBS="$LIBS" -ac_save_LDFLAGS="$LDFLAGS" -CFLAGS="$CFLAGS $OGG_CFLAGS" -LIBS="$LIBS $OGG_LIBS" -LDFLAGS="$LDFLAGS $OGG_LDFLAGS" -AC_TRY_LINK_FUNC(ogg_sync_init, - [ xt_cv_lib_ogg=ok ], - [ AC_TRY_LINK([#include ],, - [ xt_cv_lib_ogg="pre v1.0, needs updating" ], - [ xt_cv_lib_ogg="not found" ]) - ]) -CFLAGS="$ac_save_CFLAGS" -LDFLAGS="$ac_save_LDFLAGS" -LIBS="$ac_save_LIBS" -]) -if test "x$xt_cv_lib_ogg" = "xok"; then - ifelse([$1],,,[$1]) - AC_DEFINE([HAVE_OGG], [1], [Define if you have libogg installed]) -else - OGG_LIBS="" - OGG_CFLAGS="" - OGG_LDFLAGS="" - ifelse([$2],,,[$2]) -fi -AC_SUBST(OGG_LIBS) -AC_SUBST(OGG_CFLAGS) -AC_SUBST(OGG_LDFLAGS) -]) diff --git a/m4/ogg2.m4 b/m4/ogg2.m4 deleted file mode 100644 index 78542d74..00000000 --- a/m4/ogg2.m4 +++ /dev/null @@ -1,106 +0,0 @@ -# Configure paths for libogg2 -# Arc Riley 03-03-2004 -# Shamelessly stolen from Jack Moffitt -# Who shamelessly stole it from Owen Taylor and Manish Singh -# Isn't Free Software awesome? - -dnl XIPH_PATH_OGG2([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libogg, and define OGG_CFLAGS and OGG_LIBS -dnl -dnl $Id$ -dnl -AC_DEFUN([XIPH_PATH_OGG2], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(ogg,[ --with-ogg=PFX Prefix where libogg2 is installed (optional)], ogg_prefix="$withval", ogg_prefix="") -AC_ARG_WITH(ogg-libraries,[ --with-ogg-libraries=DIR Directory where libogg2 library is installed (optional)], ogg_libraries="$withval", ogg_libraries="") -AC_ARG_WITH(ogg-includes,[ --with-ogg-includes=DIR Directory where libogg2 header files are installed (optional)], ogg_includes="$withval", ogg_includes="") -AC_ARG_ENABLE(oggtest, [ --disable-oggtest Do not try to compile and run a test Ogg program],, enable_oggtest=yes) - - if test "x$ogg_libraries" != "x" ; then - OGG_LIBS="-L$ogg_libraries" - elif test "x$ogg_prefix" != "x" ; then - OGG_LIBS="-L$ogg_prefix/lib" - elif test "x$prefix" != "xNONE" ; then - OGG_LIBS="-L$prefix/lib" - fi - - OGG_LIBS="$OGG_LIBS -logg2" - - if test "x$ogg_includes" != "x" ; then - OGG_CFLAGS="-I$ogg_includes" - elif test "x$ogg_prefix" != "x" ; then - OGG_CFLAGS="-I$ogg_prefix/include" - elif test "$prefix" != "xNONE"; then - OGG_CFLAGS="-I$prefix/include" - fi - - AC_MSG_CHECKING(for Ogg2) - no_ogg="" - - - if test "x$enable_oggtest" = "xyes" ; then - ac_save_CFLAGS="$CFLAGS" - ac_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $OGG_CFLAGS" - LIBS="$LIBS $OGG_LIBS" -dnl -dnl Now check if the installed Ogg is sufficiently new. -dnl - rm -f conf.oggtest - AC_TRY_RUN([ -#include -#include -#include -#include - -int main () -{ - system("touch conf.oggtest"); - return 0; -} - -],, no_ogg=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - - if test "x$no_ogg" = "x" ; then - AC_MSG_RESULT(yes) - ifelse([$1], , :, [$1]) - else - AC_MSG_RESULT(no) - if test -f conf.oggtest ; then - : - else - echo "*** Could not run Ogg test program, checking why..." - CFLAGS="$CFLAGS $OGG_CFLAGS" - LIBS="$LIBS $OGG_LIBS" - AC_TRY_LINK([ -#include -#include -], [ return 0; ], - [ echo "*** The test program compiled, but did not run. This usually means" - echo "*** that the run-time linker is not finding Ogg or finding the wrong" - echo "*** version of Ogg. If it is not finding Ogg, you'll need to set your" - echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" - echo "*** to the installed location Also, make sure you have run ldconfig if that" - echo "*** is required on your system" - echo "***" - echo "*** If you have an old version installed, it is best to remove it, although" - echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], - [ echo "*** The test program failed to compile or link. See the file config.log for the" - echo "*** exact error that occured. This usually means Ogg was incorrectly installed" - echo "*** or that you have moved Ogg since it was installed." ]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - OGG_CFLAGS="" - OGG_LIBS="" - ifelse([$2], , :, [$2]) - fi - AC_SUBST(OGG_CFLAGS) - AC_SUBST(OGG_LIBS) - rm -f conf.oggtest -]) diff --git a/m4/shout.m4 b/m4/shout.m4 deleted file mode 100644 index c1265a04..00000000 --- a/m4/shout.m4 +++ /dev/null @@ -1,79 +0,0 @@ -dnl XIPH_PATH_SHOUT -dnl Jack Moffitt 08-06-2001 -dnl Rewritten for libshout 2 -dnl Brendan Cully 20030612 -dnl -dnl $Id$ - -# XIPH_PATH_SHOUT([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -# Test for libshout, and define SHOUT_CPPFLAGS SHOUT_CFLAGS SHOUT_LIBS, and -# SHOUT_THREADSAFE -AC_DEFUN([XIPH_PATH_SHOUT], -[dnl -xt_have_shout="no" -SHOUT_THREADSAFE="no" -SHOUT_CPPFLAGS="" -SHOUT_CFLAGS="" -SHOUT_LIBS="" - -# NB: PKG_CHECK_MODULES exits if pkg-config is unavailable on the target -# system, so we can't use it. - -# seed pkg-config with the default libshout location -PKG_CONFIG_PATH=${PKG_CONFIG_PATH:-/usr/local/lib/pkgconfig} -export PKG_CONFIG_PATH - -# Step 1: Use pkg-config if available -AC_PATH_PROG([PKGCONFIG], [pkg-config], [no]) -if test "$PKGCONFIG" != "no" && `$PKGCONFIG --exists shout` -then - SHOUT_CFLAGS=`$PKGCONFIG --variable=cflags_only shout` - SHOUT_CPPFLAGS=`$PKGCONFIG --variable=cppflags shout` - SHOUT_LIBS=`$PKGCONFIG --libs shout` - xt_have_shout="maybe" -else - if test "$PKGCONFIG" != "no" - then - AC_MSG_NOTICE([$PKGCONFIG couldn't find libshout. Try adjusting PKG_CONFIG_PATH.]) - fi - # pkg-config unavailable, try shout-config - AC_PATH_PROG([SHOUTCONFIG], [shout-config], [no]) - if test "$SHOUTCONFIG" != "no" && test `$SHOUTCONFIG --package` = "libshout" - then - SHOUT_CPPFLAGS=`$SHOUTCONFIG --cppflags` - SHOUT_CFLAGS=`$SHOUTCONFIG --cflags-only` - SHOUT_LIBS=`$SHOUTCONFIG --libs` - xt_have_shout="maybe" - fi -fi - -# Now try actually using libshout -if test "$xt_have_shout" != "no" -then - ac_save_CPPFLAGS="$CPPFLAGS" - ac_save_CFLAGS="$CFLAGS" - ac_save_LIBS="$LIBS" - CPPFLAGS="$CPPFLAGS $SHOUT_CPPFLAGS" - CFLAGS="$CFLAGS $SHOUT_CFLAGS" - LIBS="$SHOUT_LIBS $LIBS" - AC_CHECK_HEADERS([shout/shout.h], [ - AC_CHECK_FUNC([shout_new], [ - ifelse([$1], , :, [$1]) - xt_have_shout="yes" - ]) - AC_EGREP_CPP([yes], [#include -#if SHOUT_THREADSAFE -yes -#endif -], [SHOUT_THREADSAFE="yes"]) - ]) - CPPFLAGS="$ac_save_CPPFLAGS" - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" -fi - -if test "$xt_have_shout" != "yes" -then - ifelse([$2], , :, [$2]) -fi -])dnl XIPH_PATH_SHOUT diff --git a/m4/speex.m4 b/m4/speex.m4 deleted file mode 100644 index 32455d88..00000000 --- a/m4/speex.m4 +++ /dev/null @@ -1,84 +0,0 @@ -# Configure paths for libspeex -# updated by Karl Heyes 02-Feb-2004 - -dnl XIPH_PATH_SPEEX([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libspeex, and define SPEEX_CFLAGS SPEEX_LIBS -dnl SPEEX_SPEEXENC_LIBS SPEEX_SPEEXFILE_LIBS SPEEX_LDFLAGS -dnl - -AC_DEFUN([XIPH_PATH_SPEEX], -[ -AC_REQUIRE([XIPH_PATH_OGG]) - -dnl Get the cflags and libraries for speex -dnl -AC_ARG_VAR([SPEEX],[path to speex installation]) -AC_ARG_WITH(speex, - AC_HELP_STRING([--with-speex=PREFIX], - [Prefix where libspeex is installed (optional)]), - speex_prefix="$withval", - speex_prefix="$SPEEX_PREFIX" - ) -if test "x$with_speex" = "xno" -then - AC_MSG_RESULT([Speex support disabled by request]) -else - if test "x$speex_prefix" = "x" -o "x$speex_prefix" = "xyes"; then - if test "x$prefix" = "xNONE"; then - speex_prefix="/usr/local" - else - speex_prefix="$prefix" - fi - fi - - SPEEX_CFLAGS="$OGG_CFLAGS" - SPEEX_LDFLAGS="$OGG_LDFLAGS" - if test "x$speex_prefix" != "x$ogg_prefix"; then - XIPH_GCC_WARNING(-I"$speex_prefix/include",, - [SPEEX_CFLAGS="$SPEEX_CFLAGS -I$speex_prefix/include" - SPEEX_LDFLAGS="-L$speex_prefix/lib $SPEEX_LDFLAGS" - ]) - fi - - SPEEX_LIBS="-lspeex" - - xt_save_LIBS="$LIBS" - xt_save_LDFLAGS="$LDFLAGS" - LDFLAGS="$LDFLAGS $SPEEX_LDFLAGS" - LIBS="$LIBS $SPEEX_LIBS" - xt_have_speex="yes" - AC_MSG_CHECKING([for libspeex]) - AC_TRY_LINK_FUNC(ogg_stream_init, [AC_MSG_RESULT([ok])], - [LIBS="$LIBS $OGG_LIBS" - AC_TRY_LINK_FUNC(ogg_stream_init, - [SPEEX_LIBS="$SPEEX_LIBS $OGG_LIBS"], - [xt_have_speex="no"]) - ]) - if test "x$xt_have_speex" = "xyes" - then - AC_LINK_IFELSE([AC_LANG_PROGRAM( - [#include ], - [void *p = speex_packet_to_header;])], - [], - [xt_have_speex="no"]) - fi - - LIBS="$xt_save_LIBS" - LDFLAGS="$xt_save_LDFLAGS" - - if test "x$xt_have_speex" = "xyes" - then - AC_MSG_RESULT([ok]) - AC_DEFINE([HAVE_SPEEX],[1],[Define if Speex support is available]) - $1 - else - ifelse([$2], , AC_MSG_ERROR([Unable to link to libspeex]), [$2]) - SPEEX_CFLAGS="" - SPEEX_LDFLAGS="" - SPEEX_LIBS="" - fi - AC_SUBST(SPEEX_CFLAGS) - AC_SUBST(SPEEX_LDFLAGS) - AC_SUBST(SPEEX_LIBS) -fi -]) diff --git a/m4/theora.m4 b/m4/theora.m4 deleted file mode 100644 index 0b2cb964..00000000 --- a/m4/theora.m4 +++ /dev/null @@ -1,77 +0,0 @@ -# Configure paths for libtheora -# Karl Heyes 02-Feb-2004 - -dnl XIPH_PATH_THEORA([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libtheora, and define THEORA_CFLAGS THEORA_LIBS -dnl - -AC_DEFUN([XIPH_PATH_THEORA], -[ -AC_REQUIRE([XIPH_PATH_OGG]) - -dnl Get the cflags and libraries for theora -dnl -AC_ARG_VAR([THEORA],[path to theora installation]) -AC_ARG_WITH(theora, - AC_HELP_STRING([--with-theora=PREFIX], - [Prefix where libtheora is installed (optional)]), - theora_prefix="$withval", - theora_prefix="$THEORA_PREFIX" - ) - -if test "x$with_theora" = "xno" -then - AC_MSG_RESULT([Theora support disabled by request]) -else - if test "x$theora_prefix" = "x" -o "x$theora_prefix" = "xyes"; then - if test "x$prefix" = "xNONE"; then - theora_prefix="/usr/local" - else - theora_prefix="$prefix" - fi - fi - - THEORA_CFLAGS="$OGG_CFLAGS" - THEORA_LDFLAGS="$OGG_LDFLAGS" - if test "x$theora_prefix" != "x$ogg_prefix"; then - XIPH_GCC_WARNING(-I"$theora_prefix/include",, - [THEORA_CFLAGS="$THEORA_CFLAGS -I$theora_prefix/include" - THEORA_LDFLAGS="-L$theora_prefix/lib $THEORA_LDFLAGS" - ]) - fi - - THEORA_LIBS="-ltheora -logg" - - ac_save_LIBS="$LIBS" - ac_save_LDFLAGS="$LDFLAGS" - LDFLAGS="$LDFLAGS $THEORA_LDFLAGS" - LIBS="$LIBS $THEORA_LIBS" - AC_MSG_CHECKING([for libtheora]) - AC_TRY_LINK_FUNC(theora_decode_header, [xt_have_theora="yes"], - [xt_have_theora="Not found"]) - if test "x$xt_have_theora" = "xyes" - then - AC_TRY_LINK_FUNC(theora_packet_isheader, [xt_have_theora="yes"], - [xt_have_theora="newer version required"]) - fi - - LIBS="$ac_save_LIBS" - LDFLAGS="$ac_save_LDFLAGS" - - if test "x$xt_have_theora" = "xyes" - then - AC_MSG_RESULT([ok]) - AC_DEFINE([HAVE_THEORA],[1],[Define if Theora support is available]) - $1 - else - THEORA_CFLAGS="" - THEORA_LDFLAGS="" - THEORA_LIBS="" - AC_MSG_RESULT([$xt_have_theora]) - $2 - fi -fi -AC_SUBST(THEORA_CFLAGS) -AC_SUBST(THEORA_LDFLAGS) -AC_SUBST(THEORA_LIBS) -]) diff --git a/m4/vorbis.m4 b/m4/vorbis.m4 deleted file mode 100644 index 17add29b..00000000 --- a/m4/vorbis.m4 +++ /dev/null @@ -1,92 +0,0 @@ -# Configure paths for libvorbis -# Jack Moffitt 10-21-2000 -# updated by Karl Heyes 31-Mar-2003 -# Shamelessly stolen from Owen Taylor and Manish Singh - -dnl XIPH_PATH_VORBIS([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libvorbis, and define VORBIS_CFLAGS VORBIS_LIBS -dnl VORBIS_VORBISENC_LIBS VORBIS_VORBISFILE_LIBS VORBIS_LDFLAGS -dnl - -AC_DEFUN([XIPH_PATH_VORBIS], -[dnl -AC_REQUIRE([XIPH_PATH_OGG]) - -dnl Get the cflags and libraries for vorbis -dnl -AC_ARG_VAR([VORBIS_PREFIX],[path to vorbis installation]) -AC_ARG_WITH(vorbis, - AC_HELP_STRING([--with-vorbis=PREFIX], - [Prefix where libvorbis is installed (optional)]), - vorbis_prefix="$withval", - vorbis_prefix="$VORBIS_PREFIX" - ) -if test "x$vorbis_prefix" = "x" -o "x$vorbis_prefix" = "xyes"; then - if test "x$prefix" = "xNONE"; then - vorbis_prefix="/usr/local" - else - vorbis_prefix="$prefix" - fi -fi - -VORBIS_CFLAGS="$OGG_CFLAGS" -VORBIS_LDFLAGS="$OGG_LDFLAGS" -if test "x$vorbis_prefix" != "x$ogg_prefix"; then - XIPH_GCC_WARNING(-I"$vorbis_prefix/include",, - [VORBIS_CFLAGS="$VORBIS_CFLAGS -I$vorbis_prefix/include" - VORBIS_LDFLAGS="-L$vorbis_prefix/lib $VORBIS_LDFLAGS" - ]) -fi - -VORBIS_LIBS="-lvorbis" -VORBISFILE_LIBS="-lvorbisfile" -VORBISENC_LIBS="-lvorbisenc" - -xt_save_LIBS="$LIBS" -xt_save_LDFLAGS="$LDFLAGS" -xt_save_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$CPPFLAGS $VORBIS_CFLAGS" -LDFLAGS="$LDFLAGS $VORBIS_LDFLAGS" -LIBS="$LIBS $VORBIS_LIBS" -xt_lib_vorbis="not found" -AC_MSG_CHECKING([for libvorbis]) -AC_TRY_LINK_FUNC(ogg_stream_init, [xt_lib_vorbis=ok], - [LIBS="$LIBS $OGG_LIBS -lm" - AC_TRY_LINK_FUNC(vorbis_info_init, - [xt_lib_vorbis=ok - VORBIS_LIBS="$VORBIS_LIBS $OGG_LIBS -lm"], - ) - ]) - -if test "x$xt_lib_vorbis" = "xok"; then -# -# Now check if the installed Vorbis is sufficiently new. -# -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ -#include -#include - ], [ -struct ovectl_ratemanage_arg a; -])],,[xt_lib_vorbis="old version found"]) -AC_MSG_RESULT([$xt_lib_vorbis]) -fi -CPPFLAGS="$xt_save_CPPFLAGS" -LIBS="$xt_save_LIBS" -LDFLAGS="$xt_save_LDFLAGS" - -if test "x$xt_lib_vorbis" = "xok"; then - ifelse([$1], ,[:], [$1]) -else - VORBIS_CFLAGS="" - VORBIS_LDFLAGS="" - VORBIS_LIBS="" - VORBISFILE_LIBS="" - VORBISENC_LIBS="" - ifelse([$2], ,, [$2]) -fi -AC_SUBST(VORBIS_CFLAGS) -AC_SUBST(VORBIS_LDFLAGS) -AC_SUBST(VORBIS_LIBS) -AC_SUBST(VORBISFILE_LIBS) -AC_SUBST(VORBISENC_LIBS) -]) diff --git a/m4/xiph_compiler.m4 b/m4/xiph_compiler.m4 deleted file mode 100644 index e1739c18..00000000 --- a/m4/xiph_compiler.m4 +++ /dev/null @@ -1,187 +0,0 @@ -dnl xiph_compiler.m4 -dnl $Id$ - -dnl XIPH_FUNC_VA_COPY -dnl Karl Heyes -dnl -# XIPH_FUNC_VA_COPY -# Test for implementation of va_copy, or define appropriately if missing -AC_DEFUN([XIPH_FUNC_VA_COPY], -[dnl -AC_MSG_CHECKING([for va_copy]) -AC_TRY_LINK([#include ], [va_list ap1, ap2; va_copy(ap1, ap2);], - AC_MSG_RESULT([va_copy]), - [dnl - AH_TEMPLATE([va_copy], [define if va_copy is not available]) - AC_TRY_LINK([#include ], [va_list ap1, ap2; __va_copy(ap1, ap2);], - [dnl - AC_DEFINE([va_copy], [__va_copy]) - AC_MSG_RESULT([__va_copy])], - [dnl - AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))]) - AC_MSG_RESULT([memcpy]) - ]) - ]) -]) -])dnl XIPH_FUNC_VA_COPY - -dnl XIPH_C_ATTRIBUTE -dnl Karl Heyes -dnl -# XIPH_C_ATTRIBUTE -# Define __attribute__ to be empty if the compiler does not support it -AC_DEFUN([XIPH_C_ATTRIBUTE], -[dnl -AC_TRY_COMPILE([int func(void) __attribute__((unused));], - [int x __attribute__ ((unused));],,[dnl - AH_TEMPLATE([__attribute__],[Define to empty if __attribute__ is not supported]) - AC_DEFINE([__attribute__(x)],[]) -]) -])dnl XIPH_C_ATTRIBUTE - -dnl XIPH_GCC_WARNING -dnl Karl Heyes -dnl -# XIPH_GCC_WARNING(flag, action-if-warning, action-if-not) -# Tests whether GCC emits a warning if explicitly asked to use flag. -# Useful for eg system default include paths -AC_DEFUN([XIPH_GCC_WARNING], -[AC_REQUIRE([AC_PROG_CC]) -xt_warning=no -if test x"$GCC" = "xyes" -then - save_cflags="$CFLAGS" - CFLAGS="-Werror $1" - AC_TRY_COMPILE(,,,xt_warning=yes) - CFLAGS="$save_cflags" -fi -if test "$xt_warning" = "yes" -then - ifelse([$2],,:,[$2]) -else - ifelse([$3],,:,[$3]) -fi -])dnl XIPH_GCC_WARNING - -dnl XIPH_CLEAN_CCFLAGS -dnl Brendan Cully 20030612 -dnl -# XIPH_CLEAN_CCFLAGS(flag-list, dest-shell-var-name) -# Filters out duplicate compiler flags, and -I flags if XIPH_GCC_WARNING -# complains about them -# Operates right-to-left on -l flags, left-to-right on everything else -# eg XIPH_CLEAN_CCFLAGS([-L/opt/lib -lfoo -lm -L/opt/lib -lbar -lm], [MY_LDFLAGS]) -# => MY_LDFLAGS="-L/opt/lib -lfoo -lbar -lm" -# the cat< /dev/null - then - xt_FLAGS="$flag $xt_FLAGS" - fi - ;; - esac -done - -$2='' -for flag in $xt_FLAGS -do - if { cat < /dev/null - then - $2="$flag $$2" - fi -done - -# Prune -I flags if $CC warns about them -xt_FLAGS='' -for flag in $$2 -do - case "$flag" in - -I*) - XIPH_GCC_WARNING([$flag], [], [xt_FLAGS="$xt_FLAGS $flag"]) - ;; - *) - xt_FLAGS="$xt_FLAGS $flag" - ;; - esac -done -$2="$xt_FLAGS" -])dnl XIPH_CLEAN_CCFLAGS - -dnl XIPH_VAR_APPEND -dnl Karl Heyes -dnl -# XIPH_VAR_APPEND(shell-var, list) -# Append each item in list to shell-var iff shell-var doesn't already have it -# eg XIPH_VAR_APPEND([CFLAGS], [-O2 -I/opt/packages/include]) -AC_DEFUN([XIPH_VAR_APPEND], -[dnl -AC_REQUIRE([AC_PROG_FGREP]) -for arg in $2 -do - if { cat < /dev/null - then - $1="$$1 $arg" - fi -done -])dnl XIPH_VAR_APPEND - -dnl XIPH_VAR_PREPEND -dnl Karl Heyes -dnl -# XIPH_VAR_PREPEND(shell-var, list) -# see XIPH_VAR_APPEND -AC_DEFUN([XIPH_VAR_PREPEND], -[dnl -AC_REQUIRE([AC_PROG_FGREP]) -xt_compare="$$1" -xt_filtered="" -for arg in $2 -do - if { cat < /dev/null - then - xt_compare="$arg $xt_compare" - xt_filtered="$xt_filtered $arg" - fi -done -$1="$xt_filtered $$1" -])dnl XIPH_VAR_PREPEND - -dnl XIPH_C__FUNC__ -dnl Karl Heyes 07/2004 -AC_DEFUN([XIPH_C__FUNC__], -[dnl -AC_MSG_CHECKING([for __func__]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[const char *x = __func__;])], - [ AC_MSG_RESULT([yes])], - [ AH_TEMPLATE([__func__], [Replace __func__ if not supported]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[const char *x = __FUNCTION__;])], - [ AC_DEFINE([__func__],[__FUNCTION__]) - AC_MSG_RESULT([Using __FUNCTION__])], - [ AC_DEFINE([__func__],["__FILE__"]) - AC_MSG_RESULT([using __FILE__]) - ]) - ]) -])dnl XIPH_C__FUNC__ - diff --git a/m4/xiph_curl.m4 b/m4/xiph_curl.m4 deleted file mode 100644 index f2b49aaf..00000000 --- a/m4/xiph_curl.m4 +++ /dev/null @@ -1,78 +0,0 @@ -dnl XIPH_PATH_CURL([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libcurl, and define CURL_CFLAGS and CURL_LIBS -dnl -dnl $Id$ -dnl -AC_DEFUN([XIPH_PATH_CURL], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(curl, - AC_HELP_STRING([--with-curl=PFX],[Prefix where libcurl is installed (optional)]), - curl_prefix="$withval", curl_prefix="$CURL_PREFIX") - -if test "x$curl_prefix" = "xno" -then - AC_MSG_RESULT([libcurl support disabled by request]) -else - -AC_ARG_WITH(curl-config, - AC_HELP_STRING([--with-curl-config=curl-config],[Use curl-config to find libcurl]), - CURL_CONFIG="$withval", [AC_PATH_PROGS(CURL_CONFIG, [curl-config], "")]) - -if test "x$curl_prefix" != "x" -a "x$curl_prefix" != "xyes"; then - CURL_LIBS="-L$curl_prefix/lib -lcurl" - CURL_CFLAGS="-I$curl_prefix/include" -elif test "x$CURL_CONFIG" != "x"; then - if ! test -x "$CURL_CONFIG"; then - AC_MSG_ERROR([$CURL_CONFIG cannot be executed]) - fi - CURL_LIBS="$($CURL_CONFIG --libs)" - CURL_CFLAGS="$($CURL_CONFIG --cflags)" -else - if test "x$prefix" = "xNONE"; then - curl_prefix="/usr/local" - else - curl_prefix="$prefix" - fi - CURL_LIBS="-L$curl_prefix/lib -lcurl" - CURL_CFLAGS="-I$curl_prefix/include" -fi - -curl_ok="yes" - -xt_curl_CPPFLAGS="$CPPFLAGS" -xt_curl_LIBS="$LIBS" -CPPFLAGS="$CPPFLAGS $CURL_CFLAGS" -LIBS="$CURL_LIBS $LIBS" -dnl -dnl Now check if the installed libcurl is sufficiently new. -dnl -AC_CHECK_HEADERS([curl/curl.h],, curl_ok="no") -AC_MSG_CHECKING(for libcurl) -if test "$curl_ok" = "yes" -then - AC_RUN_IFELSE(AC_LANG_SOURCE([ -#include -int main() -{ - return 0; -} -]),,[curl_ok="no"]) -fi -if test "$curl_ok" = "yes"; then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_CURL, 1, [Define if you have libcurl.]) - ifelse([$1], , :, [$1]) -else - AC_MSG_RESULT(no) - CURL_LIBS="" - CURL_CFLAGS="" - ifelse([$2], , :, [$2]) -fi -CPPFLAGS="$xt_curl_CPPFLAGS" -LIBS="$xt_curl_LIBS" -fi -AC_SUBST(CURL_CFLAGS) -AC_SUBST(CURL_LIBS) -]) diff --git a/m4/xiph_net.m4 b/m4/xiph_net.m4 deleted file mode 100644 index db63963c..00000000 --- a/m4/xiph_net.m4 +++ /dev/null @@ -1,26 +0,0 @@ -# XIPH_NET -# Perform tests required by the net module -AC_DEFUN([XIPH_NET], -[dnl -AC_REQUIRE([XIPH_TYPE_SOCKLEN_T]) -AC_REQUIRE([XIPH_FUNC_VA_COPY]) -AC_CHECK_HEADERS([sys/select.h sys/uio.h]) -AC_CHECK_HEADER([winsock2.h], - [AC_DEFINE([HAVE_WINSOCK2_H], [1], [Define if you have winsock2.h on MINGW]) - LIBS="$LIBS -lwsock32"]) - -# These tests are ordered based on solaris 8 tests -AC_SEARCH_LIBS([sethostent], [nsl], - [AC_DEFINE([HAVE_SETHOSTENT], [1], - [Define if you have the sethostent function])]) -AC_SEARCH_LIBS([getnameinfo], [socket], - [AC_DEFINE([HAVE_GETNAMEINFO], [1], - [Define if you have the getnameinfo function])]) -AC_CHECK_FUNCS([endhostent getaddrinfo inet_aton writev]) - -# Irix defines INET_PTON but not sockaddr_storage! -AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family], - [AC_CHECK_FUNCS([inet_pton])],, - [#include -#include ]) -]) diff --git a/m4/xiph_openssl.m4 b/m4/xiph_openssl.m4 deleted file mode 100644 index f62a5244..00000000 --- a/m4/xiph_openssl.m4 +++ /dev/null @@ -1,49 +0,0 @@ -dnl XIPH_PATH_OPENSSL([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Karl Heyes -dnl Test for openssl, and define OPENSSL_CFLAGS and OPENSSL_LIBS -dnl -AC_DEFUN([XIPH_PATH_OPENSSL], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(openssl, - AC_HELP_STRING([--with-openssl=PFX],[Prefix where openssl is installed (optional)]), - openssl_prefix="$withval", openssl_prefix="") - -if test "x$openssl_prefix" != "x" -a "x$openssl_prefix" != "xyes"; then - OPENSSL_LIBS="-L$openssl_prefix/lib -lssl" - OPENSSL_CFLAGS="-I$openssl_prefix/include" -else - AC_PATH_PROG([PKGCONFIG], [pkg-config], [no]) - if test "$PKGCONFIG" != "no" && `$PKGCONFIG --exists openssl`; then - OPENSSL_CFLAGS=`$PKGCONFIG --cflags openssl` - OPENSSL_LIBS=`$PKGCONFIG --libs openssl` - else - if test "x$prefix" = "xNONE"; then - openssl_prefix="/usr/local" - else - openssl_prefix="$prefix" - fi - OPENSSL_LIBS="-L$openssl_prefix/lib -lssl" - OPENSSL_CFLAGS="-I$openssl_prefix/include" - fi -fi - -# Now try linking to openssl -xt_save_CFLAGS="$CFLAGS" -xt_save_LIBS="$LIBS" -CFLAGS="$CFLAGS $OPENSSL_CFLAGS" -LIBS="$OPENSSL_LIBS $LIBS" -AC_TRY_LINK([#include ], [void *a = SSL_new], [openssl_ok='yes']) -CFLAGS="$xt_save_CFLAGS" -LIBS="$xt_save_LIBS" - -if test "$openssl_ok" = "yes"; then - AC_DEFINE(HAVE_OPENSSL, 1, [Define if you have libopenssl.]) - ifelse([$1], , :, [$1]) -else - OPENSSL_LIBS="" - OPENSSL_CFLAGS="" - ifelse([$2], , :, [$2]) -fi -]) diff --git a/m4/xiph_path_python.m4 b/m4/xiph_path_python.m4 deleted file mode 100644 index a0351c0f..00000000 --- a/m4/xiph_path_python.m4 +++ /dev/null @@ -1,73 +0,0 @@ -dnl local M4 configure macros -dnl Brendan Cully -dnl $Id: xiph_path_python.m4,v 1.1 2003/06/13 19:22:16 brendan Exp $ - -# XIPH_PATH_PYTHON(PATH) -# Search for python in PATH, or in the path if none is given. -# Defines PYTHON_CPPFLAGS and PYTHON_LIBS if found -AC_DEFUN([XIPH_PATH_PYTHON], - [ -m4_pushdef([xpp_path], [$1]) - -PYTHON="no" - -if test "xpp_path" != "yes" -then - AC_MSG_CHECKING([python]) - if test -x "xpp_path" - then - PYTHON="xpp_path" - fi - AC_MSG_RESULT([$PYTHON]) -else - AC_PATH_PROGS([PYTHON], [python python2 python2.3 python2.2]) -fi - -m4_popdef([xpp_path]) - -if test "$PYTHON" != "no" -then - # The library we're linking against - PYTHON_LIB="_XIPH_PYTHON_CFG([$PYTHON], [LIBRARY])" - - # if LIBRARY is nonsensical, bail out - if test $? -ne 0 -o -z "$PYTHON_LIB" - then - AC_MSG_WARN([Could not find library for $PYTHON]) - break - fi - # make library linker friendly. This is a hack, but I don't know what's better - PYTHON_LIB=`echo "$PYTHON_LIB" | sed 's/lib//;s/\.a.*//;s/\.so.*//;s/\.dylib.*//'` - - # LDFLAGS - PYTHON_LDFLAGS="-L[]_XIPH_PYTHON_CFG([$PYTHON], [LIBPL])" - - # Extra libraries required by python - PYTHON_EXTRA_LIBS="_XIPH_PYTHON_CFG([$PYTHON], [LIBS])" - PYTHON_EXTRA_LIBS="$PYTHON_EXTRA_LIBS _XIPH_PYTHON_CFG([$PYTHON], [SYSLIBS])" - PYTHON_EXTRA_LIBS="$PYTHON_EXTRA_LIBS _XIPH_PYTHON_CFG([$PYTHON], [SHLIBS])" - - PYTHON_CPPFLAGS="-I[]_XIPH_PYTHON_CFG([$PYTHON], [INCLUDEPY])" - - # test header and library functionality - saved_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS" - AC_CHECK_HEADER([Python.h], - [ - saved_LDFLAGS="$LDFLAGS" - LDFLAGS="$LDFLAGS $PYTHON_LDFLAGS" - AC_CHECK_LIB([$PYTHON_LIB], [Py_Initialize], - [PYTHON_LIBS="-l$PYTHON_LIB $PYTHON_EXTRA_LIBS"], - [AC_MSG_WARN([Could not link to the python library])], - [$PYTHON_EXTRA_LIBS]) - LDFLAGS="$saved_LDFLAGS" - ], - [AC_MSG_WARN([Python.h doesn't appear to be usable])]) - CPPFLAGS="$saved_CPPFLAGS" -fi - ])dnl - -# _XIPH_PYTHON_CFG(PYTHONPATH, CFGVAR) -# Ask python in PYTHONPATH for the definition of CFGVAR -m4_define([_XIPH_PYTHON_CFG], - [`$1 -c 'from distutils.sysconfig import get_config_var; print get_config_var("$2")' | sed 's/None//'`]) diff --git a/m4/xiph_types.m4 b/m4/xiph_types.m4 deleted file mode 100644 index 718bd9a2..00000000 --- a/m4/xiph_types.m4 +++ /dev/null @@ -1,59 +0,0 @@ -dnl xiph_types.m4 -dnl macros for type checks not covered by autoconf - -dnl XIPH_C99_INTTYPES -dnl Brendan Cully -dnl -# XIPH_C99_INTTYPES -# Check for C99 integer type definitions, or define if missing -AC_DEFUN([XIPH_C99_INTTYPES], -[dnl -AC_CHECK_HEADERS([inttypes.h]) -AC_CHECK_TYPE([uint32_t], - [AC_DEFINE(HAVE_C99_INTTYPES, 1, [Define if you have the C99 integer types])], - [AC_CHECK_SIZEOF(short) - AC_CHECK_SIZEOF(int) - AC_CHECK_SIZEOF(long) - AC_CHECK_SIZEOF(long long)]) -AH_VERBATIM([X_HAVE_C99_INTTYPES], - [#ifndef HAVE_C99_INTTYPES -# if SIZEOF_SHORT == 4 -typedef unsigned short uint32_t; -# elif SIZEOF_INT == 4 -typedef unsigned int uint32_t; -# elif SIZEOF_LONG == 4 -typedef unsigned long uint32_t; -# endif -# if SIZEOF_INT == 8 -typedef unsigned int uint64_t; -# elif SIZEOF_LONG == 8 -typedef unsigned long uint64_t; -# elif SIZEOF_LONG_LONG == 8 -typedef unsigned long long uint64_t; -# endif -#endif - ]) -]) - -dnl XIPH_TYPE_SOCKLEN_T -dnl Brendan Cully -dnl -# XIPH_TYPE_SOCKLEN_T -# Check for socklen_t, or define as int if missing -AC_DEFUN([XIPH_TYPE_SOCKLEN_T], -[dnl -AC_CHECK_HEADERS([sys/socket.h]) -AC_CHECK_TYPES([socklen_t],,, - [#if HAVE_SYS_TYPES_H -# include -#endif -#if HAVE_SYS_SOCKET_H -# include -#endif - ]) -AH_VERBATIM([X_HAVE_SOCKLEN_T], - [#ifndef HAVE_SOCKLEN_T -typedef int socklen_t; -#endif - ]) -]) diff --git a/m4/xiph_xml2.m4 b/m4/xiph_xml2.m4 deleted file mode 100644 index 1dbdaf37..00000000 --- a/m4/xiph_xml2.m4 +++ /dev/null @@ -1,58 +0,0 @@ -dnl XIPH_PATH_XML -dnl Populate XML_CFLAGS and XML_LIBS with infomation for -dnl linking with libxml2 -AC_DEFUN([XIPH_PATH_XML], -[dnl -AC_MSG_RESULT([checking for XML configuration]) -AC_ARG_VAR([XMLCONFIG],[XML configuration program]) -AC_ARG_WITH(xml-config, - [AC_HELP_STRING([--with-xml-config=PATH], - [use xml-config in PATH to find libxml])], - [XMLCONFIG="$withval"], - [AC_PATH_PROGS(XMLCONFIG, [xml2-config xml-config], "")] -) -if test "x$XMLCONFIG" = "x"; then - AC_MSG_ERROR([XML configuration could not be found]) -fi -if ! test -x "$XMLCONFIG"; then - AC_MSG_ERROR([$XMLCONFIG cannot be executed]) -fi -XML_LIBS="$($XMLCONFIG --libs)" -XML_CFLAGS="$($XMLCONFIG --cflags)" -ac_xml_save_LIBS="$LIBS" -ac_xml_save_CFLAGS="$CFLAGS" -LIBS="$XML_LIBS $LIBS" -CFLAGS="$CFLAGS $XML_CFLAGS" -AC_CHECK_FUNC(xmlParseFile,, [AC_MSG_ERROR([Unable to link with libxml])]) -CFLAGS="$ac_xml_save_CFLAGS" -LIBS="$ac_xml_save_LIBS" -]) - -dnl XIPH_PATH_XSLT -dnl Populate XSLT_CFLAGS and XSLT_LIBS with infomation for -dnl linking with libxml2 -AC_DEFUN([XIPH_PATH_XSLT], -[dnl -AC_ARG_VAR([XSLTCONFIG],[XSLT configuration program]) -AC_ARG_WITH(xslt-config, - [AC_HELP_STRING([--with-xslt-config=PATH], - [use xslt-config in PATH to find libxslt])], - [XSLTCONFIG="$withval"], - [AC_PATH_PROGS(XSLTCONFIG, [xslt-config], "")] -) -if test "x$XSLTCONFIG" = "x"; then - AC_MSG_ERROR([XSLT configuration could not be found]) -fi -if ! test -x "$XSLTCONFIG"; then - AC_MSG_ERROR([$XSLTCONFIG cannot be executed]) -fi -XSLT_LIBS="$($XSLTCONFIG --libs)" -XSLT_CFLAGS="$($XSLTCONFIG --cflags)" -ac_xslt_save_LIBS="$LIBS" -ac_xslt_save_CFLAGS="$CFLAGS" -LIBS="$XSLT_LIBS $LIBS" -CFLAGS="$CFLAGS $XSLT_CFLAGS" -AC_CHECK_FUNCS([xsltSaveResultToString]) -CFLAGS="$ac_xslt_save_CFLAGS" -LIBS="$ac_xslt_save_LIBS" -]) diff --git a/src/Makefile.am b/src/Makefile.am index 9425e661..8034d671 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,10 +2,12 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = avl thread httpp net log timing +SUBDIRS = common/avl common/net common/thread common/httpp common/log common/timing bin_PROGRAMS = icecast +INCLUDES = -I./common/ + noinst_HEADERS = admin.h cfgfile.h logging.h sighandler.h connection.h \ global.h util.h slave.h source.h stats.h refbuf.h client.h \ compat.h fserve.h xslt.h yp.h event.h md5.h \ @@ -22,8 +24,8 @@ EXTRA_icecast_SOURCES = yp.c \ auth_url.c \ format_vorbis.c format_theora.c format_speex.c -icecast_DEPENDENCIES = @ICECAST_OPTIONAL@ net/libicenet.la thread/libicethread.la \ - httpp/libicehttpp.la log/libicelog.la avl/libiceavl.la timing/libicetiming.la +icecast_DEPENDENCIES = @ICECAST_OPTIONAL@ common/net/libicenet.la common/thread/libicethread.la \ + common/httpp/libicehttpp.la common/log/libicelog.la common/avl/libiceavl.la common/timing/libicetiming.la icecast_LDADD = $(icecast_DEPENDENCIES) @XIPH_LIBS@ @KATE_LIBS@ AM_CFLAGS = @XIPH_CFLAGS@ diff --git a/src/acl.h b/src/acl.h index 6e1b13f1..1449bf83 100644 --- a/src/acl.h +++ b/src/acl.h @@ -16,7 +16,7 @@ #include #include #include -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" typedef enum acl_policy_tag { /* Error on function call */ diff --git a/src/auth.c b/src/auth.c index 5914f150..4b3792b3 100644 --- a/src/auth.c +++ b/src/auth.c @@ -33,7 +33,7 @@ #include "client.h" #include "cfgfile.h" #include "stats.h" -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" #include "fserve.h" #include "admin.h" #include "acl.h" diff --git a/src/auth.h b/src/auth.h index 031647c9..fdd2306a 100644 --- a/src/auth.h +++ b/src/auth.h @@ -26,7 +26,7 @@ struct auth_tag; #include #include "cfgfile.h" #include "client.h" -#include "thread/thread.h" +#include "common/thread/thread.h" /* implemented */ #define AUTH_TYPE_ANONYMOUS "anonymous" diff --git a/src/auth_htpasswd.c b/src/auth_htpasswd.c index 6b058126..c522c857 100644 --- a/src/auth_htpasswd.c +++ b/src/auth_htpasswd.c @@ -30,7 +30,7 @@ #include "source.h" #include "client.h" #include "cfgfile.h" -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" #include "md5.h" #include "logging.h" diff --git a/src/auth_url.c b/src/auth_url.c index fdfa27b1..436057b6 100644 --- a/src/auth_url.c +++ b/src/auth_url.c @@ -73,7 +73,7 @@ #include "source.h" #include "client.h" #include "cfgfile.h" -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" #include "logging.h" #define CATMODULE "auth_url" diff --git a/src/avl/BUILDING b/src/avl/BUILDING deleted file mode 100644 index 0aa7006f..00000000 --- a/src/avl/BUILDING +++ /dev/null @@ -1,7 +0,0 @@ -defines that affect compilation - -none - -library dependencies - -none diff --git a/src/avl/COPYING b/src/avl/COPYING deleted file mode 100644 index 92b8903f..00000000 --- a/src/avl/COPYING +++ /dev/null @@ -1,481 +0,0 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also compile or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - c) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - d) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/src/avl/Makefile.am b/src/avl/Makefile.am deleted file mode 100644 index 2e935a46..00000000 --- a/src/avl/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -## Process this with automake to create Makefile.in - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = BUILDING COPYING README TODO avl.dsp test.c - -noinst_LTLIBRARIES = libiceavl.la -noinst_HEADERS = avl.h - -libiceavl_la_SOURCES = avl.c -libiceavl_la_CFLAGS = @XIPH_CFLAGS@ - -INCLUDES = -I$(srcdir)/.. - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" - diff --git a/src/avl/README b/src/avl/README deleted file mode 100644 index 6b9d490f..00000000 --- a/src/avl/README +++ /dev/null @@ -1,6 +0,0 @@ -this is the avl tree library. - -lgpl - -by sam rushing -modified by jack moffitt diff --git a/src/avl/TODO b/src/avl/TODO deleted file mode 100644 index 46482071..00000000 --- a/src/avl/TODO +++ /dev/null @@ -1,2 +0,0 @@ -- avl_get_last() -- a little more cleanup probably diff --git a/src/avl/avl.c b/src/avl/avl.c deleted file mode 100644 index 5653440e..00000000 --- a/src/avl/avl.c +++ /dev/null @@ -1,1194 +0,0 @@ -/* - * Copyright (C) 1995-1997 by Sam Rushing - * - * All Rights Reserved - * - * Permission to use, copy, modify, and distribute this software and - * its documentation for any purpose and without fee is hereby - * granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission - * notice appear in supporting documentation, and that the name of Sam - * Rushing not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. - * - * SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN - * NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -/* $Id: avl.c,v 1.11 2004/01/27 02:16:25 karl Exp $ */ - -/* - * This is a fairly straightfoward translation of a prototype - * written in python, 'avl_tree.py'. Read that file first. - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include - -#include "avl.h" - -avl_node * -avl_node_new (void * key, - avl_node * parent) -{ - avl_node * node = (avl_node *) malloc (sizeof (avl_node)); - - if (!node) { - return NULL; - } else { - node->parent = parent; - node->key = key; - node->left = NULL; - node->right = NULL; - node->rank_and_balance = 0; - AVL_SET_BALANCE (node, 0); - AVL_SET_RANK (node, 1); -#ifdef HAVE_AVL_NODE_LOCK - thread_rwlock_create(&node->rwlock); -#endif - return node; - } -} - -avl_tree * -avl_tree_new (avl_key_compare_fun_type compare_fun, - void * compare_arg) -{ - avl_tree * t = (avl_tree *) malloc (sizeof (avl_tree)); - - if (!t) { - return NULL; - } else { - avl_node * root = avl_node_new((void *)NULL, (avl_node *) NULL); - if (!root) { - free (t); - return NULL; - } else { - t->root = root; - t->height = 0; - t->length = 0; - t->compare_fun = compare_fun; - t->compare_arg = compare_arg; - thread_rwlock_create(&t->rwlock); - return t; - } - } -} - -static void -avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun) -{ - if (node->left) { - avl_tree_free_helper (node->left, free_key_fun); - } - if (free_key_fun) - free_key_fun (node->key); - if (node->right) { - avl_tree_free_helper (node->right, free_key_fun); - } -#ifdef HAVE_AVL_NODE_LOCK - thread_rwlock_destroy (&node->rwlock); -#endif - free (node); -} - -void -avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun) -{ - if (tree->length) { - avl_tree_free_helper (tree->root->right, free_key_fun); - } - if (tree->root) { -#ifdef HAVE_AVL_NODE_LOCK - thread_rwlock_destroy(&tree->root->rwlock); -#endif - free (tree->root); - } - thread_rwlock_destroy(&tree->rwlock); - free (tree); -} - -int -avl_insert (avl_tree * ob, - void * key) -{ - if (!(ob->root->right)) { - avl_node * node = avl_node_new (key, ob->root); - if (!node) { - return -1; - } else { - ob->root->right = node; - ob->length = ob->length + 1; - return 0; - } - } else { /* not self.right == None */ - avl_node *t, *p, *s, *q, *r; - int a; - - t = ob->root; - s = p = t->right; - - while (1) { - if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) { - /* move left */ - AVL_SET_RANK (p, (AVL_GET_RANK (p) + 1)); - q = p->left; - if (!q) { - /* insert */ - avl_node * q_node = avl_node_new (key, p); - if (!q_node) { - return (-1); - } else { - q = q_node; - p->left = q; - break; - } - } else if (AVL_GET_BALANCE(q)) { - t = p; - s = q; - } - p = q; - } else { - /* move right */ - q = p->right; - if (!q) { - /* insert */ - avl_node * q_node = avl_node_new (key, p); - if (!q_node) { - return -1; - } else { - q = q_node; - p->right = q; - break; - } - } else if (AVL_GET_BALANCE(q)) { - t = p; - s = q; - } - p = q; - } - } - - ob->length = ob->length + 1; - - /* adjust balance factors */ - if (ob->compare_fun (ob->compare_arg, key, s->key) < 1) { - r = p = s->left; - } else { - r = p = s->right; - } - while (p != q) { - if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) { - AVL_SET_BALANCE (p, -1); - p = p->left; - } else { - AVL_SET_BALANCE (p, +1); - p = p->right; - } - } - - /* balancing act */ - - if (ob->compare_fun (ob->compare_arg, key, s->key) < 1) { - a = -1; - } else { - a = +1; - } - - if (AVL_GET_BALANCE (s) == 0) { - AVL_SET_BALANCE (s, a); - ob->height = ob->height + 1; - return 0; - } else if (AVL_GET_BALANCE (s) == -a) { - AVL_SET_BALANCE (s, 0); - return 0; - } else if (AVL_GET_BALANCE(s) == a) { - if (AVL_GET_BALANCE (r) == a) { - /* single rotation */ - p = r; - if (a == -1) { - s->left = r->right; - if (r->right) { - r->right->parent = s; - } - r->right = s; - s->parent = r; - AVL_SET_RANK (s, (AVL_GET_RANK (s) - AVL_GET_RANK (r))); - } else { - s->right = r->left; - if (r->left) { - r->left->parent = s; - } - r->left = s; - s->parent = r; - AVL_SET_RANK (r, (AVL_GET_RANK (r) + AVL_GET_RANK (s))); - } - AVL_SET_BALANCE (s, 0); - AVL_SET_BALANCE (r, 0); - } else if (AVL_GET_BALANCE (r) == -a) { - /* double rotation */ - if (a == -1) { - p = r->right; - r->right = p->left; - if (p->left) { - p->left->parent = r; - } - p->left = r; - r->parent = p; - s->left = p->right; - if (p->right) { - p->right->parent = s; - } - p->right = s; - s->parent = p; - AVL_SET_RANK (p, (AVL_GET_RANK (p) + AVL_GET_RANK (r))); - AVL_SET_RANK (s, (AVL_GET_RANK (s) - AVL_GET_RANK (p))); - } else { - p = r->left; - r->left = p->right; - if (p->right) { - p->right->parent = r; - } - p->right = r; - r->parent = p; - s->right = p->left; - if (p->left) { - p->left->parent = s; - } - p->left = s; - s->parent = p; - AVL_SET_RANK (r, (AVL_GET_RANK (r) - AVL_GET_RANK (p))); - AVL_SET_RANK (p, (AVL_GET_RANK (p) + AVL_GET_RANK (s))); - } - if (AVL_GET_BALANCE (p) == a) { - AVL_SET_BALANCE (s, -a); - AVL_SET_BALANCE (r, 0); - } else if (AVL_GET_BALANCE (p) == -a) { - AVL_SET_BALANCE (s, 0); - AVL_SET_BALANCE (r, a); - } else { - AVL_SET_BALANCE (s, 0); - AVL_SET_BALANCE (r, 0); - } - AVL_SET_BALANCE (p, 0); - } - /* finishing touch */ - if (s == t->right) { - t->right = p; - } else { - t->left = p; - } - p->parent = t; - } - } - return 0; -} - -int -avl_get_by_index (avl_tree * tree, - unsigned long index, - void ** value_address) -{ - avl_node * p = tree->root->right; - unsigned long m = index + 1; - while (1) { - if (!p) { - return -1; - } - if (m < AVL_GET_RANK(p)) { - p = p->left; - } else if (m > AVL_GET_RANK(p)) { - m = m - AVL_GET_RANK(p); - p = p->right; - } else { - *value_address = p->key; - return 0; - } - } -} - -int -avl_get_by_key (avl_tree * tree, - void * key, - void **value_address) -{ - avl_node * x = tree->root->right; - if (!x) { - return -1; - } - while (1) { - int compare_result = tree->compare_fun (tree->compare_arg, key, x->key); - if (compare_result < 0) { - if (x->left) { - x = x->left; - } else { - return -1; - } - } else if (compare_result > 0) { - if (x->right) { - x = x->right; - } else { - return -1; - } - } else { - *value_address = x->key; - return 0; - } - } -} - -int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun) -{ - avl_node *x, *y, *p, *q, *r, *top, *x_child; - int shortened_side, shorter; - - x = tree->root->right; - if (!x) { - return -1; - } - while (1) { - int compare_result = tree->compare_fun (tree->compare_arg, key, x->key); - if (compare_result < 0) { - /* move left - * We will be deleting from the left, adjust this node's - * rank accordingly - */ - AVL_SET_RANK (x, (AVL_GET_RANK(x) - 1)); - if (x->left) { - x = x->left; - } else { - /* Oops! now we have to undo the rank changes - * all the way up the tree - */ - AVL_SET_RANK(x, (AVL_GET_RANK (x) + 1)); - while (x != tree->root->right) { - if (x->parent->left == x) { - AVL_SET_RANK(x->parent, (AVL_GET_RANK (x->parent) + 1)); - } - x = x->parent; - } - return -1; /* key not in tree */ - } - } else if (compare_result > 0) { - /* move right */ - if (x->right) { - x = x->right; - } else { - AVL_SET_RANK(x, (AVL_GET_RANK (x) + 1)); - while (x != tree->root->right) { - if (x->parent->left == x) { - AVL_SET_RANK(x->parent, (AVL_GET_RANK (x->parent) + 1)); - } - x = x->parent; - } - return -1; /* key not in tree */ - } - } else { - break; - } - } - - if (x->left && x->right) { - void * temp_key; - - /* The complicated case. - * reduce this to the simple case where we are deleting - * a node with at most one child. - */ - - /* find the immediate predecessor */ - y = x->left; - while (y->right) { - y = y->right; - } - /* swap with */ - temp_key = x->key; - x->key = y->key; - y->key = temp_key; - /* we know 's left subtree lost a node because that's - * where we took it from - */ - AVL_SET_RANK (x, (AVL_GET_RANK (x) - 1)); - x = y; - } - /* now has at most one child - * scoot this child into the place of - */ - if (x->left) { - x_child = x->left; - x_child->parent = x->parent; - } else if (x->right) { - x_child = x->right; - x_child->parent = x->parent; - } else { - x_child = NULL; - } - - /* now tell 's parent that a grandchild became a child */ - if (x == x->parent->left) { - x->parent->left = x_child; - shortened_side = -1; - } else { - x->parent->right = x_child; - shortened_side = +1; - } - - /* - * the height of the subtree - * has now been shortened. climb back up - * the tree, rotating when necessary to adjust - * for the change. - */ - shorter = 1; - p = x->parent; - - /* return the key and node to storage */ - if (free_key_fun) - free_key_fun (x->key); -#ifdef HAVE_AVL_NODE_LOCK - thread_rwlock_destroy (&x->rwlock); -#endif - free (x); - - while (shorter && p->parent) { - - /* case 1: height unchanged */ - if (AVL_GET_BALANCE(p) == 0) { - if (shortened_side == -1) { - /* we removed a left child, the tree is now heavier - * on the right - */ - AVL_SET_BALANCE (p, +1); - } else { - /* we removed a right child, the tree is now heavier - * on the left - */ - AVL_SET_BALANCE (p, -1); - } - shorter = 0; - - } else if (AVL_GET_BALANCE (p) == shortened_side) { - /* case 2: taller subtree shortened, height reduced */ - AVL_SET_BALANCE (p, 0); - } else { - /* case 3: shorter subtree shortened */ - top = p->parent; - /* set to the taller of the two subtrees of

*/ - if (shortened_side == 1) { - q = p->left; - } else { - q = p->right; - } - if (AVL_GET_BALANCE (q) == 0) { - /* case 3a: height unchanged */ - if (shortened_side == -1) { - /* single rotate left */ - q->parent = p->parent; - p->right = q->left; - if (q->left) { - q->left->parent = p; - } - q->left = p; - p->parent = q; - AVL_SET_RANK (q, (AVL_GET_RANK (q) + AVL_GET_RANK (p))); - } else { - /* single rotate right */ - q->parent = p->parent; - p->left = q->right; - if (q->right) { - q->right->parent = p; - } - q->right = p; - p->parent = q; - AVL_SET_RANK (p, (AVL_GET_RANK (p) - AVL_GET_RANK (q))); - } - shorter = 0; - AVL_SET_BALANCE (q, shortened_side); - AVL_SET_BALANCE (p, (- shortened_side)); - } else if (AVL_GET_BALANCE (q) == AVL_GET_BALANCE (p)) { - /* case 3b: height reduced */ - if (shortened_side == -1) { - /* single rotate left */ - q->parent = p->parent; - p->right = q->left; - if (q->left) { - q->left->parent = p; - } - q->left = p; - p->parent = q; - AVL_SET_RANK (q, (AVL_GET_RANK (q) + AVL_GET_RANK (p))); - } else { - /* single rotate right */ - q->parent = p->parent; - p->left = q->right; - if (q->right) { - q->right->parent = p; - } - q->right = p; - p->parent = q; - AVL_SET_RANK (p, (AVL_GET_RANK (p) - AVL_GET_RANK (q))); - } - shorter = 1; - AVL_SET_BALANCE (q, 0); - AVL_SET_BALANCE (p, 0); - } else { - /* case 3c: height reduced, balance factors opposite */ - if (shortened_side == 1) { - /* double rotate right */ - /* first, a left rotation around q */ - r = q->right; - r->parent = p->parent; - q->right = r->left; - if (r->left) { - r->left->parent = q; - } - r->left = q; - q->parent = r; - /* now, a right rotation around p */ - p->left = r->right; - if (r->right) { - r->right->parent = p; - } - r->right = p; - p->parent = r; - AVL_SET_RANK (r, (AVL_GET_RANK (r) + AVL_GET_RANK (q))); - AVL_SET_RANK (p, (AVL_GET_RANK (p) - AVL_GET_RANK (r))); - } else { - /* double rotate left */ - /* first, a right rotation around q */ - r = q->left; - r->parent = p->parent; - q->left = r->right; - if (r->right) { - r->right->parent = q; - } - r->right = q; - q->parent = r; - /* now a left rotation around p */ - p->right = r->left; - if (r->left) { - r->left->parent = p; - } - r->left = p; - p->parent = r; - AVL_SET_RANK (q, (AVL_GET_RANK (q) - AVL_GET_RANK (r))); - AVL_SET_RANK (r, (AVL_GET_RANK (r) + AVL_GET_RANK (p))); - } - if (AVL_GET_BALANCE (r) == shortened_side) { - AVL_SET_BALANCE (q, (- shortened_side)); - AVL_SET_BALANCE (p, 0); - } else if (AVL_GET_BALANCE (r) == (- shortened_side)) { - AVL_SET_BALANCE (q, 0); - AVL_SET_BALANCE (p, shortened_side); - } else { - AVL_SET_BALANCE (q, 0); - AVL_SET_BALANCE (p, 0); - } - AVL_SET_BALANCE (r, 0); - q = r; - } - /* a rotation has caused (or in case 3c) to become - * the root. let

's former parent know this. - */ - if (top->left == p) { - top->left = q; - } else { - top->right = q; - } - /* end case 3 */ - p = q; - } - x = p; - p = x->parent; - /* shortened_side tells us which side we came up from */ - if (x == p->left) { - shortened_side = -1; - } else { - shortened_side = +1; - } - } /* end while(shorter) */ - /* when we're all done, we're one shorter */ - tree->length = tree->length - 1; - return (0); -} - -static int -avl_iterate_inorder_helper (avl_node * node, - avl_iter_fun_type iter_fun, - void * iter_arg) -{ - int result; - if (node->left) { - result = avl_iterate_inorder_helper (node->left, iter_fun, iter_arg); - if (result != 0) { - return result; - } - } - result = (iter_fun (node->key, iter_arg)); - if (result != 0) { - return result; - } - if (node->right) { - result = avl_iterate_inorder_helper (node->right, iter_fun, iter_arg); - if (result != 0) { - return result; - } - } - return 0; -} - -int -avl_iterate_inorder (avl_tree * tree, - avl_iter_fun_type iter_fun, - void * iter_arg) -{ - int result; - - if (tree->length) { - result = avl_iterate_inorder_helper (tree->root->right, iter_fun, iter_arg); - return (result); - } else { - return 0; - } -} - -avl_node *avl_get_first(avl_tree *tree) -{ - avl_node *node; - - node = tree->root->right; - if (node == NULL || node->key == NULL) return NULL; - - while (node->left) - node = node->left; - - return node; -} - -avl_node *avl_get_prev(avl_node *node) -{ - if (node->left) { - node = node->left; - while (node->right) { - node = node->right; - } - - return node; - } else { - avl_node *child = node; - while (node->parent && node->parent->key) { - node = node->parent; - if (child == node->right) { - return node; - } - child = node; - } - - return NULL; - } -} - -avl_node *avl_get_next(avl_node *node) -{ - if (node->right) { - node = node->right; - while (node->left) { - node = node->left; - } - - return node; - } else { - avl_node *child = node; - while (node->parent && node->parent->key) { - node = node->parent; - if (child == node->left) { - return node; - } - child = node; - } - - return NULL; - } -} - -/* iterate a function over a range of indices, using get_predecessor */ - -int -avl_iterate_index_range (avl_tree * tree, - avl_iter_index_fun_type iter_fun, - unsigned long low, - unsigned long high, - void * iter_arg) -{ - unsigned long m; - unsigned long num_left; - avl_node * node; - - if (high > tree->length) { - return -1; - } - num_left = (high - low); - /* find the th node */ - m = high; - node = tree->root->right; - while (1) { - if (m < AVL_GET_RANK (node)) { - node = node->left; - } else if (m > AVL_GET_RANK (node)) { - m = m - AVL_GET_RANK (node); - node = node->right; - } else { - break; - } - } - /* call on , , ... */ - while (num_left) { - num_left = num_left - 1; - if (iter_fun (num_left, node->key, iter_arg) != 0) { - return -1; - } - node = avl_get_prev (node); - } - return 0; -} - -/* If is present in the tree, return that key's node, and set <*index> - * appropriately. If not, return NULL, and set <*index> to the position - * representing the closest preceding value. - */ - -static avl_node * -avl_get_index_by_key (avl_tree * tree, - void * key, - unsigned long * index) -{ - avl_node * x = tree->root->right; - unsigned long m; - - if (!x) { - return NULL; - } - m = AVL_GET_RANK (x); - - while (1) { - int compare_result = tree->compare_fun (tree->compare_arg, key, x->key); - if (compare_result < 0) { - if (x->left) { - m = m - AVL_GET_RANK(x); - x = x->left; - m = m + AVL_GET_RANK(x); - } else { - *index = m - 2; - return NULL; - } - } else if (compare_result > 0) { - if (x->right) { - x = x->right; - m = m + AVL_GET_RANK(x); - } else { - *index = m - 1; - return NULL; - } - } else { - *index = m - 1; - return x; - } - } -} - -/* return the (low index, high index) pair that spans the given key */ - -int -avl_get_span_by_key (avl_tree * tree, - void * key, - unsigned long * low, - unsigned long * high) -{ - unsigned long m, i, j; - avl_node * node; - - node = avl_get_index_by_key (tree, key, &m); - - /* did we find an exact match? - * if so, we have to search left and right - * to find the span, since we know nothing about - * the arrangement of like keys. - */ - if (node) { - avl_node * left, * right; - /* search left */ - left = avl_get_prev (node); - i = m; - while (left && (i > 0) && (tree->compare_fun (tree->compare_arg, key, left->key) == 0)) { - left = avl_get_prev (left); - i = i - 1; - } - /* search right */ - right = avl_get_next (node); - j = m; - while (right && (j <= tree->length) && (tree->compare_fun (tree->compare_arg, key, right->key) == 0)) { - right = avl_get_next (right); - j = j + 1; - } - *low = i; - *high = j + 1; - return 0; - } else { - *low = *high = m; - } - return 0; -} - -/* return the (low index, high index) pair that spans the given key */ - -int -avl_get_span_by_two_keys (avl_tree * tree, - void * low_key, - void * high_key, - unsigned long * low, - unsigned long * high) -{ - unsigned long i, j; - avl_node * low_node, * high_node; - int order; - - /* we may need to swap them */ - order = tree->compare_fun (tree->compare_arg, low_key, high_key); - if (order > 0) { - void * temp = low_key; - low_key = high_key; - high_key = temp; - } - - low_node = avl_get_index_by_key (tree, low_key, &i); - high_node = avl_get_index_by_key (tree, high_key, &j); - - if (low_node) { - avl_node * left; - /* search left */ - left = avl_get_prev (low_node); - while (left && (i > 0) && (tree->compare_fun (tree->compare_arg, low_key, left->key) == 0)) { - left = avl_get_prev (left); - i = i - 1; - } - } else { - i = i + 1; - } - if (high_node) { - avl_node * right; - /* search right */ - right = avl_get_next (high_node); - while (right && (j <= tree->length) && (tree->compare_fun (tree->compare_arg, high_key, right->key) == 0)) { - right = avl_get_next (right); - j = j + 1; - } - } else { - j = j + 1; - } - - *low = i; - *high = j; - return 0; -} - - -int -avl_get_item_by_key_most (avl_tree * tree, - void * key, - void **value_address) -{ - avl_node * x = tree->root->right; - *value_address = NULL; - - if (!x) { - return -1; - } - while (1) { - int compare_result = tree->compare_fun (tree->compare_arg, key, x->key); - - if (compare_result == 0) { - *value_address = x->key; - return 0; - } else if (compare_result < 0) { - /* the given key is less than the current key */ - if (x->left) { - x = x->left; - } else { - if (*value_address) - return 0; - else - return -1; - } - } else { - /* the given key is more than the current key */ - /* save this value, it might end up being the right one! */ - *value_address = x->key; - if (x->right) { - /* there is a bigger entry */ - x = x->right; - } else { - if (*value_address) - return 0; - else - return -1; - } - } - } -} - -int -avl_get_item_by_key_least (avl_tree * tree, - void * key, - void **value_address) -{ - avl_node * x = tree->root->right; - *value_address = NULL; - - if (!x) { - return -1; - } - while (1) { - int compare_result = tree->compare_fun (tree->compare_arg, key, x->key); - if (compare_result == 0) { - *value_address = x->key; - return 0; /* exact match */ - } else if (compare_result < 0) { - /* the given key is less than the current key */ - /* save this value, it might end up being the right one! */ - *value_address = x->key; - if (x->left) { - x = x->left; - } else { - if (*value_address) /* we have found a valid entry */ - return 0; - else - return -1; - } - } else { - if (x->right) { - /* there is a bigger entry */ - x = x->right; - } else { - if (*value_address) /* we have found a valid entry */ - return 0; - else - return -1; - } - } - } -} - -#define AVL_MAX(X, Y) ((X) > (Y) ? (X) : (Y)) - -static long -avl_verify_balance (avl_node * node) -{ - if (!node) { - return 0; - } else { - long lh = avl_verify_balance (node->left); - long rh = avl_verify_balance (node->right); - if ((rh - lh) != AVL_GET_BALANCE(node)) { - return 0; - } - if (((lh - rh) > 1) || ((lh - rh) < -1)) { - return 0; - } - return (1 + AVL_MAX (lh, rh)); - } -} - -static void -avl_verify_parent (avl_node * node, avl_node * parent) -{ - if (node->parent != parent) { - return; - } - if (node->left) { - avl_verify_parent (node->left, node); - } - if (node->right) { - avl_verify_parent (node->right, node); - } -} - -static long -avl_verify_rank (avl_node * node) -{ - if (!node) { - return 0; - } else { - unsigned long num_left=0, num_right=0; - if (node->left) { - num_left = avl_verify_rank (node->left); - } - if (node->right) { - num_right = avl_verify_rank (node->right); - } - if (AVL_GET_RANK (node) != num_left + 1) { - fprintf (stderr, "invalid rank at node %ld\n", (long) node->key); - exit (1); - } - return (num_left + num_right + 1); - } -} - -/* sanity-check the tree */ - -int -avl_verify (avl_tree * tree) -{ - if (tree->length) { - avl_verify_balance (tree->root->right); - avl_verify_parent (tree->root->right, tree->root); - avl_verify_rank (tree->root->right); - } - return (0); -} - -/* - * These structures are accumulated on the stack during print_tree - * and are used to keep track of the width and direction of each - * branch in the history of a particular line . - */ - -typedef struct _link_node { - struct _link_node * parent; - char direction; - int width; -} link_node; - -static char balance_chars[3] = {'\\', '-', '/'}; - -static int -default_key_printer (char * buffer, void * key) -{ - return snprintf (buffer, AVL_KEY_PRINTER_BUFLEN, "%p", key); -} - -/* - * When traveling the family tree, a change in direction - * indicates when to print a connector. This is kinda crazy, - * we use the stack to build a linked list, and then travel - * it backwards using recursion. - */ - -static void -print_connectors (link_node * link) -{ - if (link->parent) { - print_connectors (link->parent); - } - if (link->parent && (link->parent->direction != link->direction) && (link->parent->parent)) { - int i; - fprintf (stdout, "|"); - for (i=0; i < (link->width - 1); i++) { - fprintf (stdout, " "); - } - } else { - int i; - for (i=0; i < (link->width); i++) { - fprintf (stdout, " "); - } - } -} - -/* - * The function writes a representation of the - * key into (which is conveniently fixed in size to add - * the spice of danger). It should return the size of the - * representation. - */ - -static void -print_node (avl_key_printer_fun_type key_printer, - avl_node * node, - link_node * link) -{ - char buffer[AVL_KEY_PRINTER_BUFLEN]; - unsigned int width; - width = key_printer (buffer, node->key); - - if (node->right) { - link_node here; - here.parent = link; - here.direction = 1; - here.width = width + 11; - print_node (key_printer, node->right, &here); - } - print_connectors (link); - fprintf (stdout, "+-[%c %s %03d]", - balance_chars[AVL_GET_BALANCE(node)+1], - buffer, - (int)AVL_GET_RANK(node)); - if (node->left || node->right) { - fprintf (stdout, "-|\n"); - } else { - fprintf (stdout, "\n"); - } - if (node->left) { - link_node here; - here.parent = link; - here.direction = -1; - here.width = width + 11; - print_node (key_printer, node->left, &here); - } -} - -void -avl_print_tree (avl_tree * tree, avl_key_printer_fun_type key_printer) -{ - link_node top = {NULL, 0, 0}; - if (!key_printer) { - key_printer = default_key_printer; - } - if (tree->length) { - print_node (key_printer, tree->root->right, &top); - } else { - fprintf (stdout, "\n"); - } -} - - -void avl_tree_rlock(avl_tree *tree) -{ - thread_rwlock_rlock(&tree->rwlock); -} - -void avl_tree_wlock(avl_tree *tree) -{ - thread_rwlock_wlock(&tree->rwlock); -} - -void avl_tree_unlock(avl_tree *tree) -{ - thread_rwlock_unlock(&tree->rwlock); -} - -#ifdef HAVE_AVL_NODE_LOCK -void avl_node_rlock(avl_node *node) -{ - thread_rwlock_rlock(&node->rwlock); -} - -void avl_node_wlock(avl_node *node) -{ - thread_rwlock_wlock(&node->rwlock); -} - -void avl_node_unlock(avl_node *node) -{ - thread_rwlock_unlock(&node->rwlock); -} -#endif diff --git a/src/avl/avl.dsp b/src/avl/avl.dsp deleted file mode 100644 index 10fabf3e..00000000 --- a/src/avl/avl.dsp +++ /dev/null @@ -1,100 +0,0 @@ -# Microsoft Developer Studio Project File - Name="avl" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=avl - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "avl.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "avl.mak" CFG="avl - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "avl - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "avl - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "avl - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "avl - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "avl - Win32 Release" -# Name "avl - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\avl.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\avl.h -# End Source File -# End Group -# End Target -# End Project diff --git a/src/avl/avl.h b/src/avl/avl.h deleted file mode 100644 index 3e02ce42..00000000 --- a/src/avl/avl.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 1995 by Sam Rushing - */ - -/* $Id: avl.h,v 1.7 2003/07/07 01:10:14 brendan Exp $ */ - -#ifndef __AVL_H -#define __AVL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define AVL_KEY_PRINTER_BUFLEN (256) - -#ifndef NO_THREAD -#include "thread/thread.h" -#else -#define thread_rwlock_create(x) do{}while(0) -#define thread_rwlock_destroy(x) do{}while(0) -#define thread_rwlock_rlock(x) do{}while(0) -#define thread_rwlock_wlock(x) do{}while(0) -#define thread_rwlock_unlock(x) do{}while(0) -#endif - -typedef struct avl_node_tag { - void * key; - struct avl_node_tag * left; - struct avl_node_tag * right; - struct avl_node_tag * parent; - /* - * The lower 2 bits of specify the balance - * factor: 00==-1, 01==0, 10==+1. - * The rest of the bits are used for - */ - unsigned int rank_and_balance; -#if !defined(NO_THREAD) && defined(HAVE_AVL_NODE_LOCK) - rwlock_t rwlock; -#endif -} avl_node; - -#define AVL_GET_BALANCE(n) ((int)(((n)->rank_and_balance & 3) - 1)) - -#define AVL_GET_RANK(n) (((n)->rank_and_balance >> 2)) - -#define AVL_SET_BALANCE(n,b) \ - ((n)->rank_and_balance) = \ - (((n)->rank_and_balance & (~3)) | ((int)((b) + 1))) - -#define AVL_SET_RANK(n,r) \ - ((n)->rank_and_balance) = \ - (((n)->rank_and_balance & 3) | (r << 2)) - -struct _avl_tree; - -typedef int (*avl_key_compare_fun_type) (void * compare_arg, void * a, void * b); -typedef int (*avl_iter_fun_type) (void * key, void * iter_arg); -typedef int (*avl_iter_index_fun_type) (unsigned long index, void * key, void * iter_arg); -typedef int (*avl_free_key_fun_type) (void * key); -typedef int (*avl_key_printer_fun_type) (char *, void *); - -/* - * and let us associate a particular compare - * function with each tree, separately. - */ - -#ifdef _mangle -# define avl_tree_new _mangle(avl_tree_new) -# define avl_node_new _mangle(avl_node_new) -# define avl_tree_free _mangle(avl_tree_free) -# define avl_insert _mangle(avl_insert) -# define avl_delete _mangle(avl_delete) -# define avl_get_by_index _mangle(avl_get_by_index) -# define avl_get_by_key _mangle(avl_get_by_key) -# define avl_iterate_inorder _mangle(avl_iterate_inorder) -# define avl_iterate_index_range _mangle(avl_iterate_index_range) -# define avl_tree_rlock _mangle(avl_tree_rlock) -# define avl_tree_wlock _mangle(avl_tree_wlock) -# define avl_tree_wlock _mangle(avl_tree_wlock) -# define avl_tree_unlock _mangle(avl_tree_unlock) -# define avl_node_rlock _mangle(avl_node_rlock) -# define avl_node_wlock _mangle(avl_node_wlock) -# define avl_node_unlock _mangle(avl_node_unlock) -# define avl_get_span_by_key _mangle(avl_get_span_by_key) -# define avl_get_span_by_two_keys _mangle(avl_get_span_by_two_keys) -# define avl_verify _mangle(avl_verify) -# define avl_print_tree _mangle(avl_print_tree) -# define avl_get_first _mangle(avl_get_first) -# define avl_get_prev _mangle(avl_get_prev) -# define avl_get_next _mangle(avl_get_next) -# define avl_get_item_by_key_most _mangle(avl_get_item_by_key_most) -# define avl_get_item_by_key_least _mangle(avl_get_item_by_key_least) -#endif - -typedef struct _avl_tree { - avl_node * root; - unsigned int height; - unsigned int length; - avl_key_compare_fun_type compare_fun; - void * compare_arg; -#ifndef NO_THREAD - rwlock_t rwlock; -#endif -} avl_tree; - -avl_tree * avl_tree_new (avl_key_compare_fun_type compare_fun, void * compare_arg); -avl_node * avl_node_new (void * key, avl_node * parent); - -void avl_tree_free ( - avl_tree * tree, - avl_free_key_fun_type free_key_fun - ); - -int avl_insert ( - avl_tree * ob, - void * key - ); - -int avl_delete ( - avl_tree * tree, - void * key, - avl_free_key_fun_type free_key_fun - ); - -int avl_get_by_index ( - avl_tree * tree, - unsigned long index, - void ** value_address - ); - -int avl_get_by_key ( - avl_tree * tree, - void * key, - void ** value_address - ); - -int avl_iterate_inorder ( - avl_tree * tree, - avl_iter_fun_type iter_fun, - void * iter_arg - ); - -int avl_iterate_index_range ( - avl_tree * tree, - avl_iter_index_fun_type iter_fun, - unsigned long low, - unsigned long high, - void * iter_arg - ); - -int avl_get_span_by_key ( - avl_tree * tree, - void * key, - unsigned long * low, - unsigned long * high - ); - -int avl_get_span_by_two_keys ( - avl_tree * tree, - void * key_a, - void * key_b, - unsigned long * low, - unsigned long * high - ); - -int avl_verify (avl_tree * tree); - -void avl_print_tree ( - avl_tree * tree, - avl_key_printer_fun_type key_printer - ); - -avl_node *avl_get_first(avl_tree *tree); - -avl_node *avl_get_prev(avl_node * node); - -avl_node *avl_get_next(avl_node * node); - -/* These two are from David Ascher */ - -int avl_get_item_by_key_most ( - avl_tree * tree, - void * key, - void ** value_address - ); - -int avl_get_item_by_key_least ( - avl_tree * tree, - void * key, - void ** value_address - ); - -/* optional locking stuff */ -void avl_tree_rlock(avl_tree *tree); -void avl_tree_wlock(avl_tree *tree); -void avl_tree_unlock(avl_tree *tree); -void avl_node_rlock(avl_node *node); -void avl_node_wlock(avl_node *node); -void avl_node_unlock(avl_node *node); - -#ifdef __cplusplus -} -#endif - -#endif /* __AVL_H */ diff --git a/src/avl/test.c b/src/avl/test.c deleted file mode 100644 index a33c2c16..00000000 --- a/src/avl/test.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include "avl.h" - -#ifdef _WIN32 -#define snprintf _snprintf -#endif - -int _compare(void *compare_arg, void *a, void *b); -int _free(void *key); -int _printer(char *buff, void *key); - -int main(int argc, char **argv) -{ - int i, max_nodes; - avl_tree *tree; - avl_node *node; - - max_nodes = 25; - - if (argc == 2) { - max_nodes = atoi(argv[1]); - if (max_nodes == 0) - max_nodes = 10; - } - - printf("avl test... max_nodes = %d...\n", max_nodes); - - tree = avl_tree_new(_compare, NULL); - - printf("Filling tree...\n"); - for (i = 0; i < max_nodes; i++) { - avl_insert(tree, (void *)rand()); - } - - printf("Traversing tree...\n"); - node = avl_get_first(tree); - while (node) { - i = (int)node->key; - - printf("...%5d\n", i); - - node = avl_get_next(node); - } - - printf("Trying to go backwards...\n"); - node = tree->root->right; - while (node) { - i = (int)node->key; - printf("...%5d\n", i); - node = avl_get_prev(node); - } - - printf("Printing tree...\n"); - avl_print_tree(tree, _printer); - - avl_tree_free(tree, _free); - - return 0; -} - -int _compare(void *compare_arg, void *a, void *b) -{ - int i, j; - - i = (int)a; - j = (int)b; - - if (i > j) - return 1; - if (j > i) - return -1; - return 0; -} - -int _free(void *key) -{ - return 1; -} - -int _printer(char *buff, void *key) -{ - return snprintf(buff, 25, "%d", (int)key); -} - - - - - - - - - - - - diff --git a/src/cfgfile.c b/src/cfgfile.c index 7aea0cb9..79af779e 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -26,7 +26,7 @@ #include #include -#include "thread/thread.h" +#include "common/thread/thread.h" #include "cfgfile.h" #include "refbuf.h" #include "client.h" diff --git a/src/cfgfile.h b/src/cfgfile.h index a5274b9f..1fb424fd 100644 --- a/src/cfgfile.h +++ b/src/cfgfile.h @@ -24,8 +24,8 @@ struct _mount_proxy; -#include "thread/thread.h" -#include "avl/avl.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" #include "global.h" #include "connection.h" diff --git a/src/client.c b/src/client.c index 9c4b72cc..730dc210 100644 --- a/src/client.c +++ b/src/client.c @@ -24,9 +24,9 @@ #include #include -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" #include "cfgfile.h" #include "connection.h" diff --git a/src/client.h b/src/client.h index 194dc257..f469958f 100644 --- a/src/client.h +++ b/src/client.h @@ -22,7 +22,7 @@ #include "connection.h" #include "refbuf.h" #include "acl.h" -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" typedef enum _protocol_tag { ICECAST_PROTOCOL_HTTP = 0, diff --git a/src/common b/src/common new file mode 160000 index 00000000..0e41ed23 --- /dev/null +++ b/src/common @@ -0,0 +1 @@ +Subproject commit 0e41ed2372826e659a27475c5e6f44862b040a50 diff --git a/src/connection.c b/src/connection.c index 6e0af113..239aea8e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -39,10 +39,10 @@ #include "compat.h" -#include "thread/thread.h" -#include "avl/avl.h" -#include "net/sock.h" -#include "httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/net/sock.h" +#include "common/httpp/httpp.h" #include "cfgfile.h" #include "global.h" diff --git a/src/connection.h b/src/connection.h index d532fbfe..7790fca8 100644 --- a/src/connection.h +++ b/src/connection.h @@ -22,9 +22,9 @@ #endif #include "compat.h" -#include "httpp/httpp.h" -#include "thread/thread.h" -#include "net/sock.h" +#include "common/httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/net/sock.h" struct _client_tag; struct source_tag; diff --git a/src/format.h b/src/format.h index d3eb975c..91d9b9bc 100644 --- a/src/format.h +++ b/src/format.h @@ -20,7 +20,7 @@ #include "client.h" #include "refbuf.h" -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" struct source_tag; struct _mount_proxy; diff --git a/src/format_mp3.c b/src/format_mp3.c index ac19f459..941249e9 100644 --- a/src/format_mp3.c +++ b/src/format_mp3.c @@ -35,7 +35,7 @@ #include "stats.h" #include "format.h" -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" #include "logging.h" diff --git a/src/fserve.c b/src/fserve.c index 35504f13..559e4012 100644 --- a/src/fserve.c +++ b/src/fserve.c @@ -45,10 +45,10 @@ #endif #endif -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" -#include "net/sock.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" +#include "common/net/sock.h" #include "connection.h" #include "global.h" diff --git a/src/global.c b/src/global.c index c0664280..041d7de3 100644 --- a/src/global.c +++ b/src/global.c @@ -17,9 +17,9 @@ #include -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" #include "connection.h" #include "refbuf.h" diff --git a/src/global.h b/src/global.h index 1770bc6b..c257359f 100644 --- a/src/global.h +++ b/src/global.h @@ -20,9 +20,9 @@ #define ICECAST_VERSION_STRING "Icecast " PACKAGE_VERSION -#include "thread/thread.h" +#include "common/thread/thread.h" #include "slave.h" -#include "net/sock.h" +#include "common/net/sock.h" typedef struct ice_global_tag { diff --git a/src/httpp/BUILDING b/src/httpp/BUILDING deleted file mode 100644 index 9484fac9..00000000 --- a/src/httpp/BUILDING +++ /dev/null @@ -1,7 +0,0 @@ -defines that affect compilation - -none - -library dependencies - -uses avl diff --git a/src/httpp/COPYING b/src/httpp/COPYING deleted file mode 100644 index 92b8903f..00000000 --- a/src/httpp/COPYING +++ /dev/null @@ -1,481 +0,0 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also compile or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - c) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - d) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/src/httpp/Makefile.am b/src/httpp/Makefile.am deleted file mode 100644 index 7240fd21..00000000 --- a/src/httpp/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -## Process this with automake to create Makefile.in - -AUTOMAKE_OPTIONS = foreign - -noinst_LTLIBRARIES = libicehttpp.la -noinst_HEADERS = httpp.h - -libicehttpp_la_SOURCES = httpp.c -libicehttpp_la_CFLAGS = @XIPH_CFLAGS@ -AM_CPPFLAGS = @XIPH_CPPFLAGS@ - -INCLUDES = -I$(srcdir)/.. - -# SCCS stuff (for BitKeeper) -GET = true - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" - diff --git a/src/httpp/README b/src/httpp/README deleted file mode 100644 index e4001d56..00000000 --- a/src/httpp/README +++ /dev/null @@ -1,5 +0,0 @@ -httpp is a simple http parser - -licensed under the lgpl - -created by jack moffitt diff --git a/src/httpp/TODO b/src/httpp/TODO deleted file mode 100644 index 04e2c790..00000000 --- a/src/httpp/TODO +++ /dev/null @@ -1 +0,0 @@ -- nothing i can think of diff --git a/src/httpp/httpp.c b/src/httpp/httpp.c deleted file mode 100644 index d65c00a0..00000000 --- a/src/httpp/httpp.c +++ /dev/null @@ -1,575 +0,0 @@ -/* Httpp.c -** -** http parsing engine -** -** This program is distributed under the GNU General Public License, version 2. -** A copy of this license is included with this source. -*/ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include - -#include -#include -#include -#ifdef HAVE_STRINGS_H -#include -#endif - -#include -#include "httpp.h" - -#if defined(_WIN32) && !defined(HAVE_STRCASECMP) -#define strcasecmp stricmp -#endif - -#define MAX_HEADERS 32 - -/* internal functions */ - -/* misc */ -static char *_lowercase(char *str); - -/* for avl trees */ -static int _compare_vars(void *compare_arg, void *a, void *b); -static int _free_vars(void *key); - -http_parser_t *httpp_create_parser(void) -{ - return (http_parser_t *)malloc(sizeof(http_parser_t)); -} - -void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults) -{ - http_varlist_t *list; - - parser->req_type = httpp_req_none; - parser->uri = NULL; - parser->vars = avl_tree_new(_compare_vars, NULL); - parser->queryvars = avl_tree_new(_compare_vars, NULL); - - /* now insert the default variables */ - list = defaults; - while (list != NULL) { - httpp_setvar(parser, list->var.name, list->var.value); - list = list->next; - } -} - -static int split_headers(char *data, unsigned long len, char **line) -{ - /* first we count how many lines there are - ** and set up the line[] array - */ - int lines = 0; - unsigned long i; - line[lines] = data; - for (i = 0; i < len && lines < MAX_HEADERS; i++) { - if (data[i] == '\r') - data[i] = '\0'; - if (data[i] == '\n') { - lines++; - data[i] = '\0'; - if (lines >= MAX_HEADERS) - return MAX_HEADERS; - if (i + 1 < len) { - if (data[i + 1] == '\n' || data[i + 1] == '\r') - break; - line[lines] = &data[i + 1]; - } - } - } - - i++; - while (i < len && data[i] == '\n') i++; - - return lines; -} - -static void parse_headers(http_parser_t *parser, char **line, int lines) -{ - int i, l; - int whitespace, slen; - char *name = NULL; - char *value = NULL; - - /* parse the name: value lines. */ - for (l = 1; l < lines; l++) { - whitespace = 0; - name = line[l]; - value = NULL; - slen = strlen(line[l]); - for (i = 0; i < slen; i++) { - if (line[l][i] == ':') { - whitespace = 1; - line[l][i] = '\0'; - } else { - if (whitespace) { - whitespace = 0; - while (i < slen && line[l][i] == ' ') - i++; - - if (i < slen) - value = &line[l][i]; - - break; - } - } - } - - if (name != NULL && value != NULL) { - httpp_setvar(parser, _lowercase(name), value); - name = NULL; - value = NULL; - } - } -} - -int httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri) -{ - char *data; - char *line[MAX_HEADERS]; - int lines, slen,i, whitespace=0, where=0,code; - char *version=NULL, *resp_code=NULL, *message=NULL; - - if(http_data == NULL) - return 0; - - /* make a local copy of the data, including 0 terminator */ - data = (char *)malloc(len+1); - if (data == NULL) return 0; - memcpy(data, http_data, len); - data[len] = 0; - - lines = split_headers(data, len, line); - - /* In this case, the first line contains: - * VERSION RESPONSE_CODE MESSAGE, such as HTTP/1.0 200 OK - */ - slen = strlen(line[0]); - version = line[0]; - for(i=0; i < slen; i++) { - if(line[0][i] == ' ') { - line[0][i] = 0; - whitespace = 1; - } else if(whitespace) { - whitespace = 0; - where++; - if(where == 1) - resp_code = &line[0][i]; - else { - message = &line[0][i]; - break; - } - } - } - - if(version == NULL || resp_code == NULL || message == NULL) { - free(data); - return 0; - } - - httpp_setvar(parser, HTTPP_VAR_ERROR_CODE, resp_code); - code = atoi(resp_code); - if(code < 200 || code >= 300) { - httpp_setvar(parser, HTTPP_VAR_ERROR_MESSAGE, message); - } - - httpp_setvar(parser, HTTPP_VAR_URI, uri); - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "NONE"); - - parse_headers(parser, line, lines); - - free(data); - - return 1; -} - -static int hex(char c) -{ - if(c >= '0' && c <= '9') - return c - '0'; - else if(c >= 'A' && c <= 'F') - return c - 'A' + 10; - else if(c >= 'a' && c <= 'f') - return c - 'a' + 10; - else - return -1; -} - -static char *url_escape(const char *src) -{ - int len = strlen(src); - unsigned char *decoded; - int i; - char *dst; - int done = 0; - - decoded = calloc(1, len + 1); - - dst = (char *)decoded; - - for(i=0; i < len; i++) { - switch(src[i]) { - case '%': - if(i+2 >= len) { - free(decoded); - return NULL; - } - if(hex(src[i+1]) == -1 || hex(src[i+2]) == -1 ) { - free(decoded); - return NULL; - } - - *dst++ = hex(src[i+1]) * 16 + hex(src[i+2]); - i+= 2; - break; - case '+': - *dst++ = ' '; - break; - case '#': - done = 1; - break; - case 0: - free(decoded); - return NULL; - break; - default: - *dst++ = src[i]; - break; - } - if(done) - break; - } - - *dst = 0; /* null terminator */ - - return (char *)decoded; -} - -/** TODO: This is almost certainly buggy in some cases */ -static void parse_query(http_parser_t *parser, char *query) -{ - int len; - int i=0; - char *key = query; - char *val=NULL; - - if(!query || !*query) - return; - - len = strlen(query); - - while(ireq_type = httpp_str_to_method(req_type); - - if (uri != NULL && strlen(uri) > 0) { - char *query; - if((query = strchr(uri, '?')) != NULL) { - httpp_setvar(parser, HTTPP_VAR_RAWURI, uri); - httpp_setvar(parser, HTTPP_VAR_QUERYARGS, query); - *query = 0; - query++; - parse_query(parser, query); - } - - parser->uri = strdup(uri); - } else { - free(data); - return 0; - } - - if ((version != NULL) && ((tmp = strchr(version, '/')) != NULL)) { - tmp[0] = '\0'; - if ((strlen(version) > 0) && (strlen(&tmp[1]) > 0)) { - httpp_setvar(parser, HTTPP_VAR_PROTOCOL, version); - httpp_setvar(parser, HTTPP_VAR_VERSION, &tmp[1]); - } else { - free(data); - return 0; - } - } else { - free(data); - return 0; - } - - if (parser->req_type != httpp_req_none && parser->req_type != httpp_req_unknown) { - switch (parser->req_type) { - case httpp_req_get: - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "GET"); - break; - case httpp_req_post: - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "POST"); - break; - case httpp_req_put: - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PUT"); - break; - case httpp_req_head: - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "HEAD"); - break; - case httpp_req_source: - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "SOURCE"); - break; - case httpp_req_play: - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PLAY"); - break; - case httpp_req_stats: - httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "STATS"); - break; - default: - break; - } - } else { - free(data); - return 0; - } - - if (parser->uri != NULL) { - httpp_setvar(parser, HTTPP_VAR_URI, parser->uri); - } else { - free(data); - return 0; - } - - parse_headers(parser, line, lines); - - free(data); - - return 1; -} - -void httpp_deletevar(http_parser_t *parser, const char *name) -{ - http_var_t var; - - if (parser == NULL || name == NULL) - return; - var.name = (char*)name; - var.value = NULL; - avl_delete(parser->vars, (void *)&var, _free_vars); -} - -void httpp_setvar(http_parser_t *parser, const char *name, const char *value) -{ - http_var_t *var; - - if (name == NULL || value == NULL) - return; - - var = (http_var_t *)malloc(sizeof(http_var_t)); - if (var == NULL) return; - - var->name = strdup(name); - var->value = strdup(value); - - if (httpp_getvar(parser, name) == NULL) { - avl_insert(parser->vars, (void *)var); - } else { - avl_delete(parser->vars, (void *)var, _free_vars); - avl_insert(parser->vars, (void *)var); - } -} - -const char *httpp_getvar(http_parser_t *parser, const char *name) -{ - http_var_t var; - http_var_t *found; - void *fp; - - if (parser == NULL || name == NULL) - return NULL; - - fp = &found; - var.name = (char*)name; - var.value = NULL; - - if (avl_get_by_key(parser->vars, &var, fp) == 0) - return found->value; - else - return NULL; -} - -void httpp_set_query_param(http_parser_t *parser, const char *name, const char *value) -{ - http_var_t *var; - - if (name == NULL || value == NULL) - return; - - var = (http_var_t *)malloc(sizeof(http_var_t)); - if (var == NULL) return; - - var->name = strdup(name); - var->value = url_escape(value); - - if (httpp_get_query_param(parser, name) == NULL) { - avl_insert(parser->queryvars, (void *)var); - } else { - avl_delete(parser->queryvars, (void *)var, _free_vars); - avl_insert(parser->queryvars, (void *)var); - } -} - -const char *httpp_get_query_param(http_parser_t *parser, const char *name) -{ - http_var_t var; - http_var_t *found; - void *fp; - - fp = &found; - var.name = (char *)name; - var.value = NULL; - - if (avl_get_by_key(parser->queryvars, (void *)&var, fp) == 0) - return found->value; - else - return NULL; -} - -void httpp_clear(http_parser_t *parser) -{ - parser->req_type = httpp_req_none; - if (parser->uri) - free(parser->uri); - parser->uri = NULL; - avl_tree_free(parser->vars, _free_vars); - avl_tree_free(parser->queryvars, _free_vars); - parser->vars = NULL; -} - -void httpp_destroy(http_parser_t *parser) -{ - httpp_clear(parser); - free(parser); -} - -static char *_lowercase(char *str) -{ - char *p = str; - for (; *p != '\0'; p++) - *p = tolower(*p); - - return str; -} - -static int _compare_vars(void *compare_arg, void *a, void *b) -{ - http_var_t *vara, *varb; - - vara = (http_var_t *)a; - varb = (http_var_t *)b; - - return strcmp(vara->name, varb->name); -} - -static int _free_vars(void *key) -{ - http_var_t *var; - - var = (http_var_t *)key; - - if (var->name) - free(var->name); - if (var->value) - free(var->value); - free(var); - - return 1; -} - -httpp_request_type_e httpp_str_to_method(const char * method) { - if (strcasecmp("GET", method) == 0) { - return httpp_req_get; - } else if (strcasecmp("POST", method) == 0) { - return httpp_req_post; - } else if (strcasecmp("PUT", method) == 0) { - return httpp_req_put; - } else if (strcasecmp("HEAD", method) == 0) { - return httpp_req_head; - } else if (strcasecmp("SOURCE", method) == 0) { - return httpp_req_source; - } else if (strcasecmp("PLAY", method) == 0) { - return httpp_req_play; - } else if (strcasecmp("STATS", method) == 0) { - return httpp_req_stats; - } else { - return httpp_req_unknown; - } -} - diff --git a/src/httpp/httpp.h b/src/httpp/httpp.h deleted file mode 100644 index 10abbd8b..00000000 --- a/src/httpp/httpp.h +++ /dev/null @@ -1,89 +0,0 @@ -/* httpp.h -** -** http parsing library -** -** This program is distributed under the GNU General Public License, version 2. -** A copy of this license is included with this source. -*/ - -#ifndef __HTTPP_H -#define __HTTPP_H - -#include - -#define HTTPP_VAR_PROTOCOL "__protocol" -#define HTTPP_VAR_VERSION "__version" -#define HTTPP_VAR_URI "__uri" -#define HTTPP_VAR_RAWURI "__rawuri" -#define HTTPP_VAR_QUERYARGS " __queryargs" -#define HTTPP_VAR_REQ_TYPE "__req_type" -#define HTTPP_VAR_ERROR_MESSAGE "__errormessage" -#define HTTPP_VAR_ERROR_CODE "__errorcode" -#define HTTPP_VAR_ICYPASSWORD "__icy_password" - -typedef enum httpp_request_type_tag { - /* Initial and internally used state of the engine */ - httpp_req_none = 0, - /* Part of HTTP standard: GET, POST, PUT and HEAD */ - httpp_req_get, - httpp_req_post, - httpp_req_put, - httpp_req_head, - /* Icecast SOURCE, to be replaced with PUT some day */ - httpp_req_source, - /* XXX: ??? */ - httpp_req_play, - /* Icecast 2.x STATS, to request a live stream of stats events */ - httpp_req_stats, - /* Used if request method is unknown. MUST BE LAST ONE IN LIST. */ - httpp_req_unknown -} httpp_request_type_e; - -typedef struct http_var_tag { - char *name; - char *value; -} http_var_t; - -typedef struct http_varlist_tag { - http_var_t var; - struct http_varlist_tag *next; -} http_varlist_t; - -typedef struct http_parser_tag { - httpp_request_type_e req_type; - char *uri; - avl_tree *vars; - avl_tree *queryvars; -} http_parser_t; - -#ifdef _mangle -# define httpp_create_parser _mangle(httpp_create_parser) -# define httpp_initialize _mangle(httpp_initialize) -# define httpp_parse _mangle(httpp_parse) -# define httpp_parse_icy _mangle(httpp_parse_icy) -# define httpp_parse_response _mangle(httpp_parse_response) -# define httpp_setvar _mangle(httpp_setvar) -# define httpp_getvar _mangle(httpp_getvar) -# define httpp_set_query_param _mangle(httpp_set_query_param) -# define httpp_get_query_param _mangle(httpp_get_query_param) -# define httpp_destroy _mangle(httpp_destroy) -# define httpp_clear _mangle(httpp_clear) -#endif - -http_parser_t *httpp_create_parser(void); -void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults); -int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len); -int httpp_parse_icy(http_parser_t *parser, const char *http_data, unsigned long len); -int httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri); -void httpp_setvar(http_parser_t *parser, const char *name, const char *value); -void httpp_deletevar(http_parser_t *parser, const char *name); -const char *httpp_getvar(http_parser_t *parser, const char *name); -void httpp_set_query_param(http_parser_t *parser, const char *name, const char *value); -const char *httpp_get_query_param(http_parser_t *parser, const char *name); -void httpp_destroy(http_parser_t *parser); -void httpp_clear(http_parser_t *parser); - -/* util functions */ -httpp_request_type_e httpp_str_to_method(const char * method); - -#endif diff --git a/src/httpp/test.c b/src/httpp/test.c deleted file mode 100644 index f5e4f6ab..00000000 --- a/src/httpp/test.c +++ /dev/null @@ -1,59 +0,0 @@ -#include - -#include -#include "httpp.h" - - -int main(int argc, char **argv) -{ - char buff[8192]; - int readed; - http_parser_t parser; - avl_node *node; - http_var_t *var; - - httpp_initialize(&parser, NULL); - - readed = fread(buff, 1, 8192, stdin); - if (httpp_parse(&parser, buff, readed)) { - printf("Parse succeeded...\n\n"); - printf("Request was "); - switch (parser.req_type) { - case httpp_req_none: - printf(" none\n"); - break; - case httpp_req_unknown: - printf(" unknown\n"); - break; - case httpp_req_get: - printf(" get\n"); - break; - case httpp_req_post: - printf(" post\n"); - break; - case httpp_req_head: - printf(" head\n"); - break; - } - printf("Version was 1.%d\n", parser.version); - - node = avl_get_first(parser.vars); - while (node) { - var = (http_var_t *)node->key; - - if (var) - printf("Iterating variable(s): %s = %s\n", var->name, var->value); - - node = avl_get_next(node); - } - } else { - printf("Parse failed...\n"); - } - - printf("Destroying parser...\n"); - httpp_destroy(&parser); - - return 0; -} - - diff --git a/src/log/Makefile.am b/src/log/Makefile.am deleted file mode 100644 index 40e67099..00000000 --- a/src/log/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -## Process this with automake to create Makefile.in - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = test.c - -noinst_LTLIBRARIES = libicelog.la -noinst_HEADERS = log.h - -libicelog_la_SOURCES = log.c -AM_CFLAGS = $(XIPH_CFLAGS) - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" - diff --git a/src/log/log.c b/src/log/log.c deleted file mode 100644 index 8987aac7..00000000 --- a/src/log/log.c +++ /dev/null @@ -1,662 +0,0 @@ -/* -** Logging framework. -** -** This program is distributed under the GNU General Public License, version 2. -** A copy of this license is included with this source. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - - -#ifndef _WIN32 -#include -#else -#include -#endif - -#include "log.h" - -#define LOG_MAXLOGS 25 -#define LOG_MAXLINELEN 1024 - -#ifdef _WIN32 -#define mutex_t CRITICAL_SECTION -#define snprintf _snprintf -#define vsnprintf _vsnprintf -#else -#define mutex_t pthread_mutex_t -#endif - -static mutex_t _logger_mutex; -static int _initialized = 0; - -typedef struct _log_entry_t -{ - char *line; - unsigned int len; - struct _log_entry_t *next; -} log_entry_t; - - -typedef struct log_tag -{ - int in_use; - - unsigned level; - - char *filename; - FILE *logfile; - off_t size; - off_t trigger_level; - int archive_timestamp; - - unsigned long total; - unsigned int entries; - unsigned int keep_entries; - log_entry_t *log_head; - log_entry_t **log_tail; - - char *buffer; -} log_t; - -static log_t loglist[LOG_MAXLOGS]; - -static int _get_log_id(void); -static void _release_log_id(int log_id); -static void _lock_logger(void); -static void _unlock_logger(void); - - -static int _log_open (int id) -{ - if (loglist [id] . in_use == 0) - return 0; - - /* check for cases where an open of the logfile is wanted */ - if (loglist [id] . logfile == NULL || - (loglist [id] . trigger_level && loglist [id] . size > loglist [id] . trigger_level)) - { - if (loglist [id] . filename) /* only re-open files where we have a name */ - { - struct stat st; - - if (loglist [id] . logfile) - { - char new_name [4096]; - fclose (loglist [id] . logfile); - loglist [id] . logfile = NULL; - /* simple rename, but could use time providing locking were used */ - if (loglist[id].archive_timestamp) - { - char timestamp [128]; - time_t now = time(NULL); - - strftime (timestamp, sizeof (timestamp), "%Y%m%d_%H%M%S", localtime (&now)); - snprintf (new_name, sizeof(new_name), "%s.%s", loglist[id].filename, timestamp); - } - else { - snprintf (new_name, sizeof(new_name), "%s.old", loglist [id] . filename); - } -#ifdef _WIN32 - if (stat (new_name, &st) == 0) - remove (new_name); -#endif - rename (loglist [id] . filename, new_name); - } - loglist [id] . logfile = fopen (loglist [id] . filename, "a"); - if (loglist [id] . logfile == NULL) - return 0; - setvbuf (loglist [id] . logfile, NULL, IO_BUFFER_TYPE, 0); - if (stat (loglist [id] . filename, &st) < 0) - loglist [id] . size = 0; - else - loglist [id] . size = st.st_size; - } - else - loglist [id] . size = 0; - } - return 1; -} - -void log_initialize(void) -{ - int i; - - if (_initialized) return; - - for (i = 0; i < LOG_MAXLOGS; i++) { - loglist[i].in_use = 0; - loglist[i].level = 2; - loglist[i].size = 0; - loglist[i].trigger_level = 1000000000; - loglist[i].filename = NULL; - loglist[i].logfile = NULL; - loglist[i].buffer = NULL; - loglist[i].total = 0; - loglist[i].entries = 0; - loglist[i].keep_entries = 0; - loglist[i].log_head = NULL; - loglist[i].log_tail = &loglist[i].log_head; - } - - /* initialize mutexes */ -#ifndef _WIN32 - pthread_mutex_init(&_logger_mutex, NULL); -#else - InitializeCriticalSection(&_logger_mutex); -#endif - - _initialized = 1; -} - -int log_open_file(FILE *file) -{ - int log_id; - - if(file == NULL) return LOG_EINSANE; - - log_id = _get_log_id(); - if (log_id < 0) return LOG_ENOMORELOGS; - - loglist[log_id].logfile = file; - loglist[log_id].filename = NULL; - loglist[log_id].size = 0; - - return log_id; -} - - -int log_open(const char *filename) -{ - int id; - FILE *file; - - if (filename == NULL) return LOG_EINSANE; - if (strcmp(filename, "") == 0) return LOG_EINSANE; - - file = fopen(filename, "a"); - - id = log_open_file(file); - - if (id >= 0) - { - struct stat st; - - setvbuf (loglist [id] . logfile, NULL, IO_BUFFER_TYPE, 0); - loglist [id] . filename = strdup (filename); - if (stat (loglist [id] . filename, &st) == 0) - loglist [id] . size = st.st_size; - loglist [id] . entries = 0; - loglist [id] . log_head = NULL; - loglist [id] . log_tail = &loglist [id] . log_head; - } - - return id; -} - - -/* set the trigger level to trigger, represented in kilobytes */ -void log_set_trigger(int id, unsigned trigger) -{ - if (id >= 0 && id < LOG_MAXLOGS && loglist [id] . in_use) - { - loglist [id] . trigger_level = trigger*1024; - } -} - - -int log_set_filename(int id, const char *filename) -{ - if (id < 0 || id >= LOG_MAXLOGS) - return LOG_EINSANE; - /* NULL filename is ok, empty filename is not. */ - if ((filename && !strcmp(filename, "")) || loglist [id] . in_use == 0) - return LOG_EINSANE; - _lock_logger(); - if (loglist [id] . filename) - free (loglist [id] . filename); - if (filename) - loglist [id] . filename = strdup (filename); - else - loglist [id] . filename = NULL; - _unlock_logger(); - return id; -} - -int log_set_archive_timestamp(int id, int value) -{ - if (id < 0 || id >= LOG_MAXLOGS) - return LOG_EINSANE; - _lock_logger(); - loglist[id].archive_timestamp = value; - _unlock_logger(); - return id; -} - - -int log_open_with_buffer(const char *filename, int size) -{ - /* not implemented */ - return LOG_ENOTIMPL; -} - - -void log_set_lines_kept (int log_id, unsigned int count) -{ - if (log_id < 0 || log_id >= LOG_MAXLOGS) return; - if (loglist[log_id].in_use == 0) return; - - _lock_logger (); - loglist[log_id].keep_entries = count; - while (loglist[log_id].entries > count) - { - log_entry_t *to_go = loglist [log_id].log_head; - loglist [log_id].log_head = to_go->next; - loglist [log_id].total -= to_go->len; - free (to_go->line); - free (to_go); - loglist [log_id].entries--; - } - _unlock_logger (); -} - - -void log_set_level(int log_id, unsigned level) -{ - if (log_id < 0 || log_id >= LOG_MAXLOGS) return; - if (loglist[log_id].in_use == 0) return; - - loglist[log_id].level = level; -} - -void log_flush(int log_id) -{ - if (log_id < 0 || log_id >= LOG_MAXLOGS) return; - if (loglist[log_id].in_use == 0) return; - - _lock_logger(); - if (loglist[log_id].logfile) - fflush(loglist[log_id].logfile); - _unlock_logger(); -} - -void log_reopen(int log_id) -{ - if (log_id < 0 || log_id >= LOG_MAXLOGS) - return; - if (loglist [log_id] . filename && loglist [log_id] . logfile) - { - _lock_logger(); - - fclose (loglist [log_id] . logfile); - loglist [log_id] . logfile = NULL; - - _unlock_logger(); - } -} - -void log_close(int log_id) -{ - if (log_id < 0 || log_id >= LOG_MAXLOGS) return; - - _lock_logger(); - - if (loglist[log_id].in_use == 0) - { - _unlock_logger(); - return; - } - - loglist[log_id].in_use = 0; - loglist[log_id].level = 2; - if (loglist[log_id].filename) free(loglist[log_id].filename); - if (loglist[log_id].buffer) free(loglist[log_id].buffer); - - if (loglist [log_id] . logfile) - { - fclose (loglist [log_id] . logfile); - loglist [log_id] . logfile = NULL; - } - while (loglist[log_id].entries) - { - log_entry_t *to_go = loglist [log_id].log_head; - loglist [log_id].log_head = to_go->next; - loglist [log_id].total -= to_go->len; - free (to_go->line); - free (to_go); - loglist [log_id].entries--; - } - _unlock_logger(); -} - -void log_shutdown(void) -{ - /* destroy mutexes */ -#ifndef _WIN32 - pthread_mutex_destroy(&_logger_mutex); -#else - DeleteCriticalSection(&_logger_mutex); -#endif - - _initialized = 0; -} - - -static int create_log_entry (int log_id, const char *pre, const char *line) -{ - log_entry_t *entry; - - if (loglist[log_id].keep_entries == 0) - return fprintf (loglist[log_id].logfile, "%s%s\n", pre, line); - - entry = calloc (1, sizeof (log_entry_t)); - entry->len = strlen (pre) + strlen (line) + 2; - entry->line = malloc (entry->len); - snprintf (entry->line, entry->len, "%s%s\n", pre, line); - loglist [log_id].total += entry->len; - fprintf (loglist[log_id].logfile, "%s", entry->line); - - *loglist [log_id].log_tail = entry; - loglist [log_id].log_tail = &entry->next; - - if (loglist [log_id].entries >= loglist [log_id].keep_entries) - { - log_entry_t *to_go = loglist [log_id].log_head; - loglist [log_id].log_head = to_go->next; - loglist [log_id].total -= to_go->len; - free (to_go->line); - free (to_go); - } - else - loglist [log_id].entries++; - return entry->len; -} - - -void log_contents (int log_id, char **_contents, unsigned int *_len) -{ - int remain; - log_entry_t *entry; - char *ptr; - - if (log_id < 0) return; - if (log_id >= LOG_MAXLOGS) return; /* Bad log number */ - - _lock_logger (); - remain = loglist [log_id].total + 1; - *_contents = malloc (remain); - **_contents= '\0'; - *_len = loglist [log_id].total; - - entry = loglist [log_id].log_head; - ptr = *_contents; - while (entry) - { - int len = snprintf (ptr, remain, "%s", entry->line); - if (len > 0) - { - ptr += len; - remain -= len; - } - entry = entry->next; - } - _unlock_logger (); -} - -static void __vsnprintf(char *str, size_t size, const char *format, va_list ap) { - int in_block = 0; - int block_size = 0; - int block_len; - int block_space = 0; - const char * arg; - char buf[80]; - - for (; *format && size; format++) - { - if ( !in_block ) - { - if ( *format == '%' ) { - in_block = 1; - block_size = 0; - block_len = 0; - block_space = 0; - } - else - { - *(str++) = *format; - size--; - } - } - else - { - // TODO: %l*[sdupi] as well as %.4080s and "%.*s - arg = NULL; - switch (*format) - { - case 'l': - block_size++; - break; - case '.': - // just ignore '.'. If somebody cares: fix it. - break; - case '*': - block_len = va_arg(ap, int); - break; - case ' ': - block_space = 1; - break; - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - block_len = atoi(format); - for (; *format >= '0' && *format <= '9'; format++); - format--; - break; - case 'p': - snprintf(buf, sizeof(buf), "%p", (void*)va_arg(ap, void *)); - arg = buf; - case 'd': - case 'i': - case 'u': - if (!arg) - { - switch (block_size) - { - case 0: - if (*format == 'u') - snprintf(buf, sizeof(buf), "%u", (unsigned int)va_arg(ap, unsigned int)); - else - snprintf(buf, sizeof(buf), "%i", (int)va_arg(ap, int)); - break; - case 1: - if (*format == 'u') - snprintf(buf, sizeof(buf), "%lu", (unsigned long int)va_arg(ap, unsigned long int)); - else - snprintf(buf, sizeof(buf), "%li", (long int)va_arg(ap, long int)); - break; - case 2: - if (*format == 'u') - snprintf(buf, sizeof(buf), "%llu", (unsigned long long int)va_arg(ap, unsigned long long int)); - else - snprintf(buf, sizeof(buf), "%lli", (long long int)va_arg(ap, long long int)); - break; - default: - snprintf(buf, sizeof(buf), "<<>>"); - break; - } - arg = buf; - } - case 's': - case 'H': - // TODO. - if (!arg) - arg = va_arg(ap, const char *); - if (!arg) - arg = "(null)"; - if (!block_len) - block_len = strlen(arg); - - // the if() is the outer structure so the inner for() - // is branch optimized. - if (*format == 'H' ) - { - for (; *arg && block_len && size; arg++, size--, block_len--) - { - if ((*arg <= '"' || *arg == '`' || *arg == '\\') && !(block_space && *arg == ' ')) - *(str++) = '.'; - else - *(str++) = *arg; - } - } - else - { - for (; *arg && block_len && size; arg++, size--, block_len--) - *(str++) = *arg; - } - in_block = 0; - break; - } - } - } - - if ( !size ) - str--; - - *str = 0; -} - -void log_write(int log_id, unsigned priority, const char *cat, const char *func, - const char *fmt, ...) -{ - static const char *prior[] = { "EROR", "WARN", "INFO", "DBUG" }; - int datelen; - time_t now; - char pre[256]; - char line[LOG_MAXLINELEN]; - va_list ap; - - if (log_id < 0 || log_id >= LOG_MAXLOGS) return; /* Bad log number */ - if (loglist[log_id].level < priority) return; - if (!priority || priority > sizeof(prior)/sizeof(prior[0])) return; /* Bad priority */ - - - va_start(ap, fmt); - __vsnprintf(line, sizeof(line), fmt, ap); - va_end(ap); - - now = time(NULL); - datelen = strftime (pre, sizeof (pre), "[%Y-%m-%d %H:%M:%S]", localtime(&now)); - snprintf (pre+datelen, sizeof (pre)-datelen, " %s %s%s ", prior [priority-1], cat, func); - - _lock_logger(); - if (_log_open (log_id)) - { - int len = create_log_entry (log_id, pre, line); - if (len > 0) - loglist[log_id].size += len; - } - _unlock_logger(); -} - -void log_write_direct(int log_id, const char *fmt, ...) -{ - va_list ap; - time_t now; - char line[LOG_MAXLINELEN]; - - if (log_id < 0 || log_id >= LOG_MAXLOGS) return; - - va_start(ap, fmt); - - now = time(NULL); - - _lock_logger(); - __vsnprintf(line, LOG_MAXLINELEN, fmt, ap); - if (_log_open (log_id)) - { - int len = create_log_entry (log_id, "", line); - if (len > 0) - loglist[log_id].size += len; - } - _unlock_logger(); - - va_end(ap); - - fflush(loglist[log_id].logfile); -} - -static int _get_log_id(void) -{ - int i; - int id = -1; - - /* lock mutex */ - _lock_logger(); - - for (i = 0; i < LOG_MAXLOGS; i++) - if (loglist[i].in_use == 0) { - loglist[i].in_use = 1; - id = i; - break; - } - - /* unlock mutex */ - _unlock_logger(); - - return id; -} - -static void _release_log_id(int log_id) -{ - /* lock mutex */ - _lock_logger(); - - loglist[log_id].in_use = 0; - - /* unlock mutex */ - _unlock_logger(); -} - -static void _lock_logger(void) -{ -#ifndef _WIN32 - pthread_mutex_lock(&_logger_mutex); -#else - EnterCriticalSection(&_logger_mutex); -#endif -} - -static void _unlock_logger(void) -{ -#ifndef _WIN32 - pthread_mutex_unlock(&_logger_mutex); -#else - LeaveCriticalSection(&_logger_mutex); -#endif -} - - - - diff --git a/src/log/log.h b/src/log/log.h deleted file mode 100644 index a7718f01..00000000 --- a/src/log/log.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -** Logging framework. -** -** This program is distributed under the GNU General Public License, version 2. -** A copy of this license is included with this source. -*/ - -#ifndef __LOG_H__ -#define __LOG_H__ - -#include - -#define LOG_EINSANE -1 -#define LOG_ENOMORELOGS -2 -#define LOG_ECANTOPEN -3 -#define LOG_ENOTOPEN -4 -#define LOG_ENOTIMPL -5 - -#ifdef _WIN32 -#define IO_BUFFER_TYPE _IONBF -#else -#define IO_BUFFER_TYPE _IOLBF -#endif - -void log_initialize(void); -int log_open_file(FILE *file); -int log_open(const char *filename); -int log_open_with_buffer(const char *filename, int size); -void log_set_level(int log_id, unsigned level); -void log_set_trigger(int id, unsigned trigger); -int log_set_filename(int id, const char *filename); -void log_set_lines_kept (int log_id, unsigned int count); -void log_contents (int log_id, char **_contents, unsigned int *_len); -int log_set_archive_timestamp(int id, int value); -void log_flush(int log_id); -void log_reopen(int log_id); -void log_close(int log_id); -void log_shutdown(void); - -void log_write(int log_id, unsigned priority, const char *cat, const char *func, - const char *fmt, ...); -void log_write_direct(int log_id, const char *fmt, ...); - -#endif /* __LOG_H__ */ diff --git a/src/log/test.c b/src/log/test.c deleted file mode 100644 index b7862cf1..00000000 --- a/src/log/test.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "log.h" - -#define CATMODULE "test" - -#define LOG_ERR(x, y, z...) log_write(x, 1, CATMODULE "/" __FUNCTION__, y, ##z) - - -int main(void) -{ - int lid; - - log_initialize(); - - lid = log_open("test.log"); - - LOG_ERR(lid, "The log id is %d, damnit...", lid); - - log_close(lid); - - log_shutdown(); -} diff --git a/src/logging.c b/src/logging.c index 5294a500..d113c58d 100644 --- a/src/logging.c +++ b/src/logging.c @@ -19,8 +19,8 @@ #include #include -#include "thread/thread.h" -#include "httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/httpp/httpp.h" #include "connection.h" #include "refbuf.h" diff --git a/src/logging.h b/src/logging.h index ece96c89..d68ce0db 100644 --- a/src/logging.h +++ b/src/logging.h @@ -16,7 +16,7 @@ #include "cfgfile.h" #include "client.h" -#include "log/log.h" +#include "common/log/log.h" /* declare the global log descriptors */ diff --git a/src/main.c b/src/main.c index dac9ea0d..dfe06df7 100644 --- a/src/main.c +++ b/src/main.c @@ -41,11 +41,11 @@ #include #endif -#include "thread/thread.h" -#include "avl/avl.h" -#include "net/sock.h" -#include "net/resolver.h" -#include "httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/net/sock.h" +#include "common/net/resolver.h" +#include "common/httpp/httpp.h" #if HAVE_SYS_TYPES_H #include diff --git a/src/net/BUILDING b/src/net/BUILDING deleted file mode 100644 index b63563a4..00000000 --- a/src/net/BUILDING +++ /dev/null @@ -1,3 +0,0 @@ -defines that affect compilation - -none currently diff --git a/src/net/COPYING b/src/net/COPYING deleted file mode 100644 index 92b8903f..00000000 --- a/src/net/COPYING +++ /dev/null @@ -1,481 +0,0 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also compile or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - c) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - d) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/src/net/Makefile.am b/src/net/Makefile.am deleted file mode 100644 index 0747825b..00000000 --- a/src/net/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -## Process this with automake to create Makefile.in - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = BUILDING COPYING README TODO test_resolver.c - -noinst_LTLIBRARIES = libicenet.la -noinst_HEADERS = resolver.h sock.h - -libicenet_la_SOURCES = sock.c resolver.c -libicenet_la_CFLAGS = @XIPH_CFLAGS@ - -INCLUDES = -I$(srcdir)/.. - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@ - diff --git a/src/net/README b/src/net/README deleted file mode 100644 index d0d2d00a..00000000 --- a/src/net/README +++ /dev/null @@ -1,10 +0,0 @@ -This is a name resolving library that's threadsafe. - -Right now it only implements this with mutexes, but we should extend it to use gethostbyXXXX_r() -if it's available. - -It shoudl work on win32, but i'm probably forgetting a headerfile. - -API is basically not going to change. Please consult with the rest of the team before changing the interface. - -jack. \ No newline at end of file diff --git a/src/net/TODO b/src/net/TODO deleted file mode 100644 index 3357459c..00000000 --- a/src/net/TODO +++ /dev/null @@ -1 +0,0 @@ -- add getXbyY_r function support diff --git a/src/net/resolver.c b/src/net/resolver.c deleted file mode 100644 index 8172578d..00000000 --- a/src/net/resolver.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * resolver.c - name resolver library - * - * Copyright (C) 1999 the icecast team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include -#include -#include - -#ifndef _WIN32 -#include -#include -#include -#include -#else -#include -#endif - -#ifndef NO_THREAD -#include -#else -#define thread_mutex_create(x) do{}while(0) -#define thread_mutex_destroy(x) do{}while(0) -#define thread_mutex_lock(x) do{}while(0) -#define thread_mutex_unlock(x) do{}while(0) -#endif - -#include "resolver.h" -#include "sock.h" - -/* internal function */ - -static int _isip(const char *what); - -/* internal data */ - -#ifndef NO_THREAD -static mutex_t _resolver_mutex; -#endif -static int _initialized = 0; - -#ifdef HAVE_INET_PTON -static int _isip(const char *what) -{ - union { - struct in_addr v4addr; - struct in6_addr v6addr; - } addr_u; - - if (inet_pton(AF_INET, what, &addr_u.v4addr) <= 0) - return inet_pton(AF_INET6, what, &addr_u.v6addr) > 0 ? 1 : 0; - - return 1; -} - -#else -static int _isip(const char *what) -{ - struct in_addr inp; - - return inet_aton(what, &inp); -} -#endif - - -#if defined (HAVE_GETNAMEINFO) && defined (HAVE_GETADDRINFO) -char *resolver_getname(const char *ip, char *buff, int len) -{ - struct addrinfo *head = NULL, hints; - char *ret = NULL; - - if (!_isip(ip)) { - strncpy(buff, ip, len); - buff [len-1] = '\0'; - return buff; - } - - memset (&hints, 0, sizeof (hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_CANONNAME; - if (getaddrinfo (ip, NULL, &hints, &head)) - return NULL; - - if (head) - { - if (getnameinfo(head->ai_addr, head->ai_addrlen, buff, len, NULL, - 0, NI_NAMEREQD) == 0) - ret = buff; - - freeaddrinfo (head); - } - - return ret; -} - - -char *resolver_getip(const char *name, char *buff, int len) -{ - struct addrinfo *head, hints; - char *ret = NULL; - - if (_isip(name)) { - strncpy(buff, name, len); - buff [len-1] = '\0'; - return buff; - } - - memset (&hints, 0, sizeof (hints)); - hints . ai_family = AF_UNSPEC; - hints . ai_socktype = SOCK_STREAM; - if (getaddrinfo (name, NULL, &hints, &head)) - return NULL; - - if (head) - { - if (getnameinfo(head->ai_addr, head->ai_addrlen, buff, len, NULL, - 0, NI_NUMERICHOST) == 0) - ret = buff; - freeaddrinfo (head); - } - - return ret; -} - -#else - -char *resolver_getname(const char *ip, char *buff, int len) -{ - struct hostent *host; - char *ret = NULL; - struct in_addr addr; - - if (! _isip(ip)) - { - strncpy(buff, ip, len); - buff [len-1] = '\0'; - return buff; - } - - thread_mutex_lock(&_resolver_mutex); - if (inet_aton (ip, &addr)) { - /* casting &addr to const char* as it is recommended on win* */ - if ((host=gethostbyaddr ((const char *)&addr, sizeof (struct in_addr), AF_INET))) - { - ret = strncpy (buff, host->h_name, len); - buff [len-1] = '\0'; - } - } - - thread_mutex_unlock(&_resolver_mutex); - return ret; -} - -char *resolver_getip(const char *name, char *buff, int len) -{ - struct hostent *host; - char *ret = NULL; - - if (_isip(name)) - { - strncpy(buff, name, len); - buff [len-1] = '\0'; - return buff; - } - thread_mutex_lock(&_resolver_mutex); - host = gethostbyname(name); - if (host) - { - char * temp = inet_ntoa(*(struct in_addr *)host->h_addr); - ret = strncpy(buff, temp, len); - buff [len-1] = '\0'; - } - thread_mutex_unlock(&_resolver_mutex); - - return ret; -} -#endif - - -void resolver_initialize() -{ - /* initialize the lib if we havne't done so already */ - - if (!_initialized) - { - _initialized = 1; - thread_mutex_create (&_resolver_mutex); - - /* keep dns connects (TCP) open */ -#ifdef HAVE_SETHOSTENT - sethostent(1); -#endif - } -} - -void resolver_shutdown(void) -{ - if (_initialized) - { - thread_mutex_destroy(&_resolver_mutex); - _initialized = 0; -#ifdef HAVE_ENDHOSTENT - endhostent(); -#endif - } -} - diff --git a/src/net/resolver.h b/src/net/resolver.h deleted file mode 100644 index 6ed1a219..00000000 --- a/src/net/resolver.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -** resolver.h -** -** name resolver library header -** -*/ - -#ifndef __RESOLVER_H -#define __RESOLVER_H - - -/* -** resolver_lookup -** -** resolves a hosts name from it's ip address -** or -** resolves an ip address from it's host name -** -** returns a pointer to buff, or NULL if an error occured -** -*/ - -#ifdef _mangle -# define resolver_initialize _mangle(resolver_initialize) -# define resolver_shutdown _mangle(resolver_shutdown) -# define resolver_getname _mangle(resolver_getname) -# define resolver_getip _mangle(resolver_getip) -#endif - -void resolver_initialize(void); -void resolver_shutdown(void); - -char *resolver_getname(const char *ip, char *buff, int len); -char *resolver_getip(const char *name, char *buff, int len); - -#endif - - - - - diff --git a/src/net/sock.c b/src/net/sock.c deleted file mode 100644 index beb53027..00000000 --- a/src/net/sock.c +++ /dev/null @@ -1,953 +0,0 @@ -/* -*- c-basic-offset: 4; -*- */ -/* sock.c: General Socket Functions - * - * Copyright (c) 1999 the icecast team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_POLL -#include -#endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#ifndef _WIN32 -#include -#include -#include -#include -#include -#include -#include -#else -#include -#define vsnprintf _vsnprintf -#define EINPROGRESS WSAEINPROGRESS -#define ENOTSOCK WSAENOTSOCK -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EALREADY WSAEALREADY -#define socklen_t int -#ifndef __MINGW32__ -#define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list)) -#endif -#endif - -#include "sock.h" -#include "resolver.h" - -/* for older C libraries */ -#ifndef AI_NUMERICSERV -# define AI_NUMERICSERV 0 -#endif -#ifndef AI_ADDRCONFIG -# define AI_ADDRCONFIG 0 -#endif - -/* sock_initialize -** -** initializes the socket library. you must call this -** before using the library! -*/ -void sock_initialize(void) -{ -#ifdef _WIN32 - WSADATA wsad; - WSAStartup(0x0101, &wsad); -#endif - - resolver_initialize(); -} - -/* sock_shutdown -** -** shutdown the socket library. remember to call this when you're -** through using the lib -*/ -void sock_shutdown(void) -{ -#ifdef _WIN32 - WSACleanup(); -#endif - - resolver_shutdown(); -} - -/* sock_get_localip -** -** gets the local ip address for the machine -** the ip it returns *should* be on the internet. -** in any case, it's as close as we can hope to get -** unless someone has better ideas on how to do this -*/ -char *sock_get_localip(char *buff, int len) -{ - char temp[1024]; - - if (gethostname(temp, sizeof(temp)) != 0) - return NULL; - - if (resolver_getip(temp, buff, len)) - return buff; - - return NULL; -} - -/* sock_error -** -** returns the last socket error -*/ -int sock_error(void) -{ -#ifdef _WIN32 - return WSAGetLastError(); -#else - return errno; -#endif -} - -void sock_set_error(int val) -{ -#ifdef _WIN32 - WSASetLastError (val); -#else - errno = val; -#endif -} - -/* sock_recoverable -** -** determines if the socket error is recoverable -** in terms of non blocking sockets -*/ -int sock_recoverable(int error) -{ - switch (error) - { - case 0: - case EAGAIN: - case EINTR: - case EINPROGRESS: -#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN - case EWOULDBLOCK: -#endif -#ifdef ERESTART - case ERESTART: -#endif - return 1; - default: - return 0; - } -} - -int sock_stalled (int error) -{ - switch (error) - { - case EAGAIN: - case EINPROGRESS: - case EALREADY: -#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN - case EWOULDBLOCK: -#endif -#ifdef ERESTART - case ERESTART: -#endif - return 1; - default: - return 0; - } -} - - -static int sock_connect_pending (int error) -{ - return error == EINPROGRESS || error == EALREADY; -} - -/* sock_valid_socket -** -** determines if a sock_t represents a valid socket -*/ -int sock_valid_socket(sock_t sock) -{ - int ret; - int optval; - socklen_t optlen; - - optlen = sizeof(int); - /* apparently on windows getsockopt.optval is a char * */ - ret = getsockopt(sock, SOL_SOCKET, SO_TYPE, (void*) &optval, &optlen); - - return (ret == 0); -} - - -/* determines if the passed socket is still connected */ -int sock_active (sock_t sock) -{ - char c; - int l; - - l = recv (sock, &c, 1, MSG_PEEK); - if (l == 0) - return 0; - if (l == SOCK_ERROR && sock_recoverable (sock_error())) - return 1; - return 0; -} - -/* inet_aton -** -** turns an ascii ip address into a binary representation -*/ -#ifdef _WIN32 -int inet_aton(const char *s, struct in_addr *a) -{ - int lsb, b2, b3, msb; - - if (sscanf(s, "%d.%d.%d.%d", &lsb, &b2, &b3, &msb) < 4) { - return 0; - } - - a->s_addr = inet_addr(s); - - return (a->s_addr != INADDR_NONE); -} -#endif /* _WIN32 */ - -/* sock_set_blocking - * - * set the sock blocking or nonblocking - * 1 for blocking - * 0 for nonblocking - */ -int sock_set_blocking(sock_t sock, int block) -{ -#ifdef _WIN32 -#ifdef __MINGW32__ - u_long varblock = 1; -#else - int varblock = 1; -#endif -#endif - - if ((!sock_valid_socket(sock)) || (block < 0) || (block > 1)) - return SOCK_ERROR; - -#ifdef _WIN32 - if (block) varblock = 0; - return ioctlsocket(sock, FIONBIO, &varblock); -#else - return fcntl(sock, F_SETFL, (block) ? 0 : O_NONBLOCK); -#endif -} - -int sock_set_nolinger(sock_t sock) -{ - struct linger lin = { 0, 0 }; - return setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&lin, - sizeof(struct linger)); -} - -int sock_set_nodelay(sock_t sock) -{ - int nodelay = 1; - - return setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *)&nodelay, - sizeof(int)); -} - -int sock_set_keepalive(sock_t sock) -{ - int keepalive = 1; - return setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepalive, - sizeof(int)); -} - -/* sock_close -** -** close the socket -*/ -int sock_close(sock_t sock) -{ -#ifdef _WIN32 - return closesocket(sock); -#else - return close(sock); -#endif -} - -/* sock_writev - * - * write multiple buffers at once, return bytes actually written - */ -#ifdef HAVE_WRITEV - -ssize_t sock_writev (sock_t sock, const struct iovec *iov, size_t count) -{ - return writev (sock, iov, count); -} - -#else - -ssize_t sock_writev (sock_t sock, const struct iovec *iov, size_t count) -{ - int i = count, accum = 0, ret; - const struct iovec *v = iov; - - while (i) - { - if (v->iov_base && v->iov_len) - { - ret = sock_write_bytes (sock, v->iov_base, v->iov_len); - if (ret == -1 && accum==0) - return -1; - if (ret == -1) - ret = 0; - accum += ret; - if (ret < (int)v->iov_len) - break; - } - v++; - i--; - } - return accum; -} - -#endif - -/* sock_write_bytes -** -** write bytes to the socket -** this function will _NOT_ block -*/ -int sock_write_bytes(sock_t sock, const void *buff, size_t len) -{ - /* sanity check */ - if (!buff) { - return SOCK_ERROR; - } else if (len <= 0) { - return SOCK_ERROR; - } /*else if (!sock_valid_socket(sock)) { - return SOCK_ERROR; - } */ - - return send(sock, buff, len, 0); -} - -/* sock_write_string -** -** writes a string to a socket -** This function must only be called with a blocking socket. -*/ -int sock_write_string(sock_t sock, const char *buff) -{ - return (sock_write_bytes(sock, buff, strlen(buff)) > 0); -} - -/* sock_write -** -** write a formatted string to the socket -** this function must only be called with a blocking socket. -** will truncate the string if it's greater than 1024 chars. -*/ -int sock_write(sock_t sock, const char *fmt, ...) -{ - int rc; - va_list ap; - - va_start (ap, fmt); - rc = sock_write_fmt (sock, fmt, ap); - va_end (ap); - - return rc; -} - -#ifdef HAVE_OLD_VSNPRINTF -int sock_write_fmt(sock_t sock, const char *fmt, va_list ap) -{ - va_list ap_local; - unsigned int len = 1024; - char *buff = NULL; - int ret; - - /* don't go infinite, but stop at some huge limit */ - while (len < 2*1024*1024) - { - char *tmp = realloc (buff, len); - ret = -1; - if (tmp == NULL) - break; - buff = tmp; - va_copy (ap_local, ap); - ret = vsnprintf (buff, len, fmt, ap_local); - if (ret > 0) - { - ret = sock_write_bytes (sock, buff, ret); - break; - } - len += 8192; - } - free (buff); - return ret; -} -#else -int sock_write_fmt(sock_t sock, const char *fmt, va_list ap) -{ - char buffer [1024], *buff = buffer; - int len; - int rc = SOCK_ERROR; - va_list ap_retry; - - va_copy (ap_retry, ap); - - len = vsnprintf (buff, sizeof (buffer), fmt, ap); - - if (len > 0) - { - if ((size_t)len < sizeof (buffer)) /* common case */ - rc = sock_write_bytes(sock, buff, (size_t)len); - else - { - /* truncated */ - buff = malloc (++len); - if (buff) - { - len = vsnprintf (buff, len, fmt, ap_retry); - if (len > 0) - rc = sock_write_bytes (sock, buff, len); - free (buff); - } - } - } - va_end (ap_retry); - - return rc; -} -#endif - - -int sock_read_bytes(sock_t sock, char *buff, size_t len) -{ - - /*if (!sock_valid_socket(sock)) return 0; */ - if (!buff) return 0; - if (len <= 0) return 0; - - return recv(sock, buff, len, 0); -} - -/* sock_read_line -** -** Read one line of at max len bytes from sock into buff. -** If ok, return 1 and nullterminate buff. Otherwize return 0. -** Terminating \n is not put into the buffer. -** -** this function will probably not work on sockets in nonblocking mode -*/ -int sock_read_line(sock_t sock, char *buff, const int len) -{ - char c = '\0'; - int read_bytes, pos; - - /*if (!sock_valid_socket(sock)) { - return 0; - } else*/ if (!buff) { - return 0; - } else if (len <= 0) { - return 0; - } - - pos = 0; - read_bytes = recv(sock, &c, 1, 0); - - if (read_bytes < 0) { - return 0; - } - - while ((c != '\n') && (pos < len) && (read_bytes == 1)) { - if (c != '\r') - buff[pos++] = c; - read_bytes = recv(sock, &c, 1, 0); - } - - if (read_bytes == 1) { - buff[pos] = '\0'; - return 1; - } else { - return 0; - } -} - -/* see if a connection has been established. If timeout is < 0 then wait - * indefinitely, else wait for the stated number of seconds. - * return SOCK_TIMEOUT for timeout - * return SOCK_ERROR for failure - * return 0 for try again, interrupted - * return 1 for ok - */ -#ifdef HAVE_POLL -int sock_connected (sock_t sock, int timeout) -{ - struct pollfd check; - int val = SOCK_ERROR; - socklen_t size = sizeof val; - - check.fd = sock; - check.events = POLLOUT; - switch (poll (&check, 1, timeout*1000)) - { - case 0: return SOCK_TIMEOUT; - default: - /* on windows getsockopt.val is defined as char* */ - if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) == 0) - { - if (val == 0) - return 1; - sock_set_error (val); - } - /* fall through */ - case -1: - if (sock_recoverable (sock_error())) - return 0; - return SOCK_ERROR; - } -} - -#else - -int sock_connected (sock_t sock, int timeout) -{ - fd_set wfds; - int val = SOCK_ERROR; - socklen_t size = sizeof val; - struct timeval tv, *timeval = NULL; - - /* make a timeout of <0 be indefinite */ - if (timeout >= 0) - { - tv.tv_sec = timeout; - tv.tv_usec = 0; - timeval = &tv; - } - - FD_ZERO(&wfds); - FD_SET(sock, &wfds); - - switch (select(sock + 1, NULL, &wfds, NULL, timeval)) - { - case 0: - return SOCK_TIMEOUT; - default: - /* on windows getsockopt.val is defined as char* */ - if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) == 0) - { - if (val == 0) - return 1; - sock_set_error (val); - } - /* fall through */ - case -1: - if (sock_recoverable (sock_error())) - return 0; - return SOCK_ERROR; - } -} -#endif - -sock_t sock_connect_wto (const char *hostname, int port, int timeout) -{ - return sock_connect_wto_bind(hostname, port, NULL, timeout); -} - -#ifdef HAVE_GETADDRINFO - -sock_t sock_connect_non_blocking (const char *hostname, unsigned port) -{ - int sock = SOCK_ERROR; - struct addrinfo *ai, *head, hints; - char service[8]; - - memset (&hints, 0, sizeof (hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - - snprintf (service, sizeof (service), "%u", port); - - if (getaddrinfo (hostname, service, &hints, &head)) - return SOCK_ERROR; - - ai = head; - while (ai) - { - if ((sock = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol)) - > -1) - { - sock_set_blocking (sock, 0); - if (connect(sock, ai->ai_addr, ai->ai_addrlen) < 0 && - !sock_connect_pending(sock_error())) - { - sock_close (sock); - sock = SOCK_ERROR; - } - else - break; - } - ai = ai->ai_next; - } - if (head) freeaddrinfo (head); - - return sock; -} - -/* issue a connect, but return after the timeout (seconds) is reached. If - * timeout is 0 or less then we will wait until the OS gives up on the connect - * The socket is returned - */ -sock_t sock_connect_wto_bind (const char *hostname, int port, const char *bnd, int timeout) -{ - sock_t sock = SOCK_ERROR; - struct addrinfo *ai, *head, *b_head=NULL, hints; - char service[8]; - - memset (&hints, 0, sizeof (hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - snprintf (service, sizeof (service), "%u", port); - - if (getaddrinfo (hostname, service, &hints, &head)) - return SOCK_ERROR; - - ai = head; - while (ai) - { - if ((sock = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol)) >= 0) - { - if (timeout > 0) - sock_set_blocking (sock, 0); - - if (bnd) - { - struct addrinfo b_hints; - memset (&b_hints, 0, sizeof(b_hints)); - b_hints.ai_family = ai->ai_family; - b_hints.ai_socktype = ai->ai_socktype; - b_hints.ai_protocol = ai->ai_protocol; - if (getaddrinfo (bnd, NULL, &b_hints, &b_head) || - bind (sock, b_head->ai_addr, b_head->ai_addrlen) < 0) - { - sock_close (sock); - sock = SOCK_ERROR; - break; - } - } - - if (connect (sock, ai->ai_addr, ai->ai_addrlen) == 0) - break; - - /* loop as the connect maybe async */ - while (sock != SOCK_ERROR) - { - if (sock_recoverable (sock_error())) - { - int connected = sock_connected (sock, timeout); - if (connected == 0) /* try again, interrupted */ - continue; - if (connected == 1) /* connected */ - { - if (timeout >= 0) - sock_set_blocking(sock, 1); - break; - } - } - sock_close (sock); - sock = SOCK_ERROR; - } - if (sock != SOCK_ERROR) - break; - } - ai = ai->ai_next; - } - if (b_head) - freeaddrinfo (b_head); - freeaddrinfo (head); - - return sock; -} - - -sock_t sock_get_server_socket (int port, const char *sinterface) -{ - struct sockaddr_storage sa; - struct addrinfo hints, *res, *ai; - char service [10]; - int sock; - - if (port < 0) - return SOCK_ERROR; - - memset (&sa, 0, sizeof(sa)); - memset (&hints, 0, sizeof(hints)); - - hints.ai_family = AF_UNSPEC; - hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_NUMERICSERV | AI_NUMERICHOST; - hints.ai_socktype = SOCK_STREAM; - snprintf (service, sizeof (service), "%d", port); - - if (getaddrinfo (sinterface, service, &hints, &res)) - return SOCK_ERROR; - ai = res; - do - { - int on = 1; - sock = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (sock < 0) - continue; - - setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)); - on = 0; -#ifdef IPV6_V6ONLY - setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof on); -#endif - - if (bind (sock, ai->ai_addr, ai->ai_addrlen) < 0) - { - sock_close (sock); - continue; - } - freeaddrinfo (res); - return sock; - - } while ((ai = ai->ai_next)); - - freeaddrinfo (res); - return SOCK_ERROR; -} - - -#else - - -int sock_try_connection (sock_t sock, const char *hostname, unsigned int port) -{ - struct sockaddr_in sin, server; - char ip[MAX_ADDR_LEN]; - - if (!hostname || !hostname[0] || port == 0) - return -1; - - memset(&sin, 0, sizeof(struct sockaddr_in)); - memset(&server, 0, sizeof(struct sockaddr_in)); - - if (!resolver_getip(hostname, ip, MAX_ADDR_LEN)) - { - sock_close (sock); - return -1; - } - - if (inet_aton(ip, (struct in_addr *)&sin.sin_addr) == 0) - { - sock_close(sock); - return -1; - } - - memcpy(&server.sin_addr, &sin.sin_addr, sizeof(struct sockaddr_in)); - - server.sin_family = AF_INET; - server.sin_port = htons((short)port); - - return connect(sock, (struct sockaddr *)&server, sizeof(server)); -} - -sock_t sock_connect_non_blocking (const char *hostname, unsigned port) -{ - sock_t sock; - - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock == SOCK_ERROR) - return SOCK_ERROR; - - sock_set_blocking (sock, 0); - sock_try_connection (sock, hostname, port); - - return sock; -} - -sock_t sock_connect_wto_bind (const char *hostname, int port, const char *bnd, int timeout) -{ - sock_t sock; - - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock == SOCK_ERROR) - return SOCK_ERROR; - - if (bnd) - { - struct sockaddr_in sa; - - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - - if (inet_aton (bnd, &sa.sin_addr) == 0 || - bind (sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) - { - sock_close (sock); - return SOCK_ERROR; - } - } - - if (timeout) - { - sock_set_blocking (sock, 0); - if (sock_try_connection (sock, hostname, port) < 0) - { - int ret = sock_connected (sock, timeout); - if (ret <= 0) - { - sock_close (sock); - return SOCK_ERROR; - } - } - sock_set_blocking(sock, 1); - } - else - { - if (sock_try_connection (sock, hostname, port) < 0) - { - sock_close (sock); - sock = SOCK_ERROR; - } - } - return sock; -} - - -/* sock_get_server_socket -** -** create a socket for incoming requests on a specified port and -** interface. if interface is null, listen on all interfaces. -** returns the socket, or SOCK_ERROR on failure -*/ -sock_t sock_get_server_socket(int port, const char *sinterface) -{ - struct sockaddr_in sa; - int error, opt; - sock_t sock; - char ip[MAX_ADDR_LEN]; - - if (port < 0) - return SOCK_ERROR; - - /* defaults */ - memset(&sa, 0, sizeof(sa)); - - /* set the interface to bind to if specified */ - if (sinterface != NULL) { - if (!resolver_getip(sinterface, ip, sizeof (ip))) - return SOCK_ERROR; - - if (!inet_aton(ip, &sa.sin_addr)) { - return SOCK_ERROR; - } else { - sa.sin_family = AF_INET; - sa.sin_port = htons((short)port); - } - } else { - sa.sin_addr.s_addr = INADDR_ANY; - sa.sin_family = AF_INET; - sa.sin_port = htons((short)port); - } - - /* get a socket */ - sock = socket (AF_INET, SOCK_STREAM, 0); - if (sock == -1) - return SOCK_ERROR; - - /* reuse it if we can */ - opt = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const void *)&opt, sizeof(int)); - - /* bind socket to port */ - error = bind(sock, (struct sockaddr *)&sa, sizeof (struct sockaddr_in)); - if (error == -1) - return SOCK_ERROR; - - return sock; -} - -#endif - -void sock_set_send_buffer (sock_t sock, int win_size) -{ - setsockopt (sock, SOL_SOCKET, SO_SNDBUF, (char *) &win_size, sizeof(win_size)); -} - -int sock_listen(sock_t serversock, int backlog) -{ - if (!sock_valid_socket(serversock)) - return 0; - - if (backlog <= 0) - backlog = 10; - - return (listen(serversock, backlog) == 0); -} - -sock_t sock_accept(sock_t serversock, char *ip, size_t len) -{ -#ifdef HAVE_GETNAMEINFO - struct sockaddr_storage sa; -#else - struct sockaddr_in sa; -#endif - sock_t ret; - socklen_t slen; - - if (ip == NULL || len == 0 || !sock_valid_socket(serversock)) - return SOCK_ERROR; - - slen = sizeof(sa); - ret = accept(serversock, (struct sockaddr *)&sa, &slen); - - if (ret != SOCK_ERROR) - { -#ifdef HAVE_GETNAMEINFO - if (getnameinfo ((struct sockaddr *)&sa, slen, ip, len, NULL, 0, NI_NUMERICHOST)) - snprintf (ip, len, "unknown"); -#else - /* inet_ntoa is not reentrant, we should protect this */ - strncpy(ip, inet_ntoa(sa.sin_addr), len); -#endif - sock_set_nolinger(ret); - sock_set_keepalive(ret); - } - - return ret; -} - diff --git a/src/net/sock.h b/src/net/sock.h deleted file mode 100644 index eb0e9010..00000000 --- a/src/net/sock.h +++ /dev/null @@ -1,146 +0,0 @@ -/* sock.h - * - General Socket Function Headers - * - * Copyright (c) 1999 the icecast team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __SOCK_H -#define __SOCK_H - -#include - -#ifdef HAVE_WINSOCK2_H -#include -#endif - -#ifdef HAVE_UNISTD_H -#include -#elif _WIN32 -#include -#endif - -#ifdef HAVE_SYS_UIO_H -#include -#else -#ifndef _SYS_UIO_H -struct iovec -{ - void *iov_base; - size_t iov_len; -}; -#endif -#endif - -#if !defined(HAVE_INET_ATON) && defined(HAVE_INET_PTON) -#define inet_aton(a,b) inet_pton(AF_INET, (a), (b)) -#endif - -#ifdef INET6_ADDRSTRLEN -#define MAX_ADDR_LEN INET6_ADDRSTRLEN -#else -#define MAX_ADDR_LEN 46 -#endif - -#ifndef sock_t -#define sock_t int -#endif - -/* The following values are based on unix avoiding errno value clashes */ -#define SOCK_SUCCESS 0 -#define SOCK_ERROR (sock_t)-1 -#define SOCK_TIMEOUT -2 - -/* sock connect macro */ -#define sock_connect(h, p) sock_connect_wto(h, p, 0) - -#ifdef _mangle -# define sock_initialize _mangle(sock_initialize) -# define sock_shutdown _mangle(sock_shutdown) -# define sock_get_localip _mangle(sock_get_localip) -# define sock_error _mangle(sock_error) -# define sock_set_error _mangle(sock_set_error) -# define sock_recoverable _mangle(sock_recoverable) -# define sock_stalled _mangle(sock_stalled) -# define sock_valid_socket _mangle(sock_valid_socket) -# define sock_set_blocking _mangle(sock_set_blocking) -# define sock_set_nolinger _mangle(sock_set_nolinger) -# define sock_set_nodelay _mangle(sock_set_nodelay) -# define sock_set_keepalive _mangle(sock_set_keepalive) -# define sock_close _mangle(sock_close) -# define sock_connect_wto _mangle(sock_connect_wto) -# define sock_connect_wto_bind _mangle(sock_connect_wto_bind) -# define sock_connect_non_blocking _mangle(sock_connect_non_blocking) -# define sock_connected _mangle(sock_connected) -# define sock_write_bytes _mangle(sock_write_bytes) -# define sock_write _mangle(sock_write) -# define sock_write_fmt _mangle(sock_write_fmt) -# define sock_write_string _mangle(sock_write_string) -# define sock_writev _mangle(sock_writev) -# define sock_read_bytes _mangle(sock_read_bytes) -# define sock_read_line _mangle(sock_read_line) -# define sock_get_server_socket _mangle(sock_get_server_socket) -# define sock_listen _mangle(sock_listen) -# define sock_set_send_buffer _mangle(sock_set_send_buffer) -# define sock_accept _mangle(sock_accept) -#endif - -/* Misc socket functions */ -void sock_initialize(void); -void sock_shutdown(void); -char *sock_get_localip(char *buff, int len); -int sock_error(void); -int sock_recoverable(int error); -int sock_stalled(int error); -int sock_valid_socket(sock_t sock); -int sock_active (sock_t sock); -int sock_set_blocking(sock_t sock, int block); -int sock_set_nolinger(sock_t sock); -int sock_set_keepalive(sock_t sock); -int sock_set_nodelay(sock_t sock); -void sock_set_send_buffer (sock_t sock, int win_size); -void sock_set_error(int val); -int sock_close(sock_t sock); - -/* Connection related socket functions */ -sock_t sock_connect_wto(const char *hostname, int port, int timeout); -sock_t sock_connect_wto_bind(const char *hostname, int port, const char *bnd, int timeout); -sock_t sock_connect_non_blocking(const char *host, unsigned port); -int sock_connected(sock_t sock, int timeout); - -/* Socket write functions */ -int sock_write_bytes(sock_t sock, const void *buff, size_t len); -int sock_write(sock_t sock, const char *fmt, ...); -int sock_write_fmt(sock_t sock, const char *fmt, va_list ap); -int sock_write_string(sock_t sock, const char *buff); -ssize_t sock_writev (sock_t sock, const struct iovec *iov, size_t count); - - -/* Socket read functions */ -int sock_read_bytes(sock_t sock, char *buff, size_t len); -int sock_read_line(sock_t sock, char *string, const int len); - -/* server socket functions */ -sock_t sock_get_server_socket(int port, const char *sinterface); -int sock_listen(sock_t serversock, int backlog); -sock_t sock_accept(sock_t serversock, char *ip, size_t len); - -#ifdef _WIN32 -int inet_aton(const char *s, struct in_addr *a); -#endif - -#endif /* __SOCK_H */ diff --git a/src/net/test_resolver.c b/src/net/test_resolver.c deleted file mode 100644 index cac1c8e2..00000000 --- a/src/net/test_resolver.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -#include "resolver.h" - -int main() -{ - char buff[1024]; - - resolver_initialize(); - - printf("I got %s, when looking up %s.\n", resolver_getip("bach.greenwitch.com", buff, 1024), "bach.greenwitch.com"); - printf("I got %s, when looking up %s.\n", resolver_getname("207.181.249.14", buff, 1024), "207.181.249.14"); - - return 0; -} - diff --git a/src/sighandler.c b/src/sighandler.c index 86f310d0..5cc9cff4 100644 --- a/src/sighandler.c +++ b/src/sighandler.c @@ -17,9 +17,9 @@ #include -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" #include "global.h" #include "connection.h" diff --git a/src/slave.c b/src/slave.c index 7648053b..b430d756 100644 --- a/src/slave.c +++ b/src/slave.c @@ -40,10 +40,10 @@ #include "compat.h" #include -#include "thread/thread.h" -#include "avl/avl.h" -#include "net/sock.h" -#include "httpp/httpp.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/net/sock.h" +#include "common/httpp/httpp.h" #include "cfgfile.h" #include "global.h" diff --git a/src/slave.h b/src/slave.h index 470d6f4b..d8ff50de 100644 --- a/src/slave.h +++ b/src/slave.h @@ -13,7 +13,7 @@ #ifndef __SLAVE_H__ #define __SLAVE_H__ -#include "thread/thread.h" +#include "common/thread/thread.h" typedef struct _relay_server { char *server; diff --git a/src/source.c b/src/source.c index 22465089..59c44431 100644 --- a/src/source.c +++ b/src/source.c @@ -44,10 +44,10 @@ #include #endif -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" -#include "net/sock.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" +#include "common/net/sock.h" #include "connection.h" #include "global.h" diff --git a/src/source.h b/src/source.h index 3d4bc5ae..7cefdcca 100644 --- a/src/source.h +++ b/src/source.h @@ -18,7 +18,7 @@ #include "yp.h" #include "util.h" #include "format.h" -#include "thread/thread.h" +#include "common/thread/thread.h" #include diff --git a/src/stats.c b/src/stats.c index e8cea0a7..747d0ade 100644 --- a/src/stats.c +++ b/src/stats.c @@ -24,10 +24,10 @@ #include #include -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" -#include "net/sock.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" +#include "common/net/sock.h" #include "connection.h" diff --git a/src/stats.h b/src/stats.h index 833fc159..25d0654e 100644 --- a/src/stats.h +++ b/src/stats.h @@ -15,7 +15,7 @@ #include "cfgfile.h" #include "connection.h" -#include "httpp/httpp.h" +#include "common/httpp/httpp.h" #include "client.h" #include #include diff --git a/src/thread/BUILDING b/src/thread/BUILDING deleted file mode 100644 index ebe84227..00000000 --- a/src/thread/BUILDING +++ /dev/null @@ -1,20 +0,0 @@ -defines that affect compilation - -_WIN32 - this should be defined for Win32 platforms - -DEBUG_MUTEXES - define this to turn on mutex debugging. this will log locks/unlocks. - -CHECK_MUTEXES (DEBUG_MUTEXES must also be defined) - checks to make sure mutex operations make sense. ie, multi_mutex is locked - when locking multiple mutexes, etc. - -THREAD_DEBUG (define to 1-4) - turns on the thread.log logging - - - - - - diff --git a/src/thread/COPYING b/src/thread/COPYING deleted file mode 100644 index 92b8903f..00000000 --- a/src/thread/COPYING +++ /dev/null @@ -1,481 +0,0 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also compile or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - c) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - d) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/src/thread/Makefile.am b/src/thread/Makefile.am deleted file mode 100644 index 5651a1bc..00000000 --- a/src/thread/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -## Process this with automake to create Makefile.in - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = BUILDING COPYING README TODO - -noinst_LTLIBRARIES = libicethread.la -noinst_HEADERS = thread.h - -libicethread_la_SOURCES = thread.c -libicethread_la_CFLAGS = @XIPH_CFLAGS@ - -INCLUDES = -I$(srcdir)/.. - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" - diff --git a/src/thread/README b/src/thread/README deleted file mode 100644 index 0ccadb07..00000000 --- a/src/thread/README +++ /dev/null @@ -1,9 +0,0 @@ -This is the cross platform thread and syncronization library. - -It depends on the avl library. - -This is a massively cleaned and picked through version of the code from -the icecast 1.3.x base. It has not been heavily tested *YET*. But since -it's just cleanups, it really shouldn't have that many problems. - -jack. diff --git a/src/thread/TODO b/src/thread/TODO deleted file mode 100644 index 84f20108..00000000 --- a/src/thread/TODO +++ /dev/null @@ -1,5 +0,0 @@ -- make DEBUG_MUTEXES and CHECK_MUTEXES work - -- recursive locking/unlocking (easy) -- reader/writer locking (easy) -- make a mode were _log is disabled (normal mode) (easy) diff --git a/src/thread/thread.c b/src/thread/thread.c deleted file mode 100644 index e842448e..00000000 --- a/src/thread/thread.c +++ /dev/null @@ -1,841 +0,0 @@ -/* threads.c: Thread Abstraction Functions - * - * Copyright (c) 1999, 2000 the icecast team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include -#include -#include -#include -#include - -#include - -#ifndef _WIN32 -#include -#include -#else -#include -#include -#endif - -#include - -#include -#include -#ifdef THREAD_DEBUG -#include -#endif - -#ifdef _WIN32 -#define __FUNCTION__ __FILE__ -#endif - -#ifdef THREAD_DEBUG -#define CATMODULE "thread" -#define LOG_ERROR(y) log_write(_logid, 1, CATMODULE "/", __FUNCTION__, y) -#define LOG_ERROR3(y, z1, z2, z3) log_write(_logid, 1, CATMODULE "/", __FUNCTION__, y, z1, z2, z3) -#define LOG_ERROR7(y, z1, z2, z3, z4, z5, z6, z7) log_write(_logid, 1, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4, z5, z6, z7) - -#define LOG_WARN(y) log_write(_logid, 2, CATMODULE "/", __FUNCTION__, y) -#define LOG_WARN3(y, z1, z2, z3) log_write(_logid, 2, CATMODULE "/", __FUNCTION__, y, z1, z2, z3) -#define LOG_WARN5(y, z1, z2, z3, z4, z5) log_write(_logid, 2, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4, z5) -#define LOG_WARN7(y, z1, z2, z3, z4, z5, z6, z7) log_write(_logid, 2, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4, z5, z6, z7) - -#define LOG_INFO(y) log_write(_logid, 3, CATMODULE "/", __FUNCTION__, y) -#define LOG_INFO4(y, z1, z2, z3, z4) log_write(_logid, 3, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4) -#define LOG_INFO5(y, z1, z2, z3, z4, z5) log_write(_logid, 3, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4, z5) - -#define LOG_DEBUG(y) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y) -#define LOG_DEBUG2(y, z1, z2) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y, z1, z2) -#define LOG_DEBUG5(y, z1, z2, z3, z4, z5) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4, z5) -#endif - -/* thread starting structure */ -typedef struct thread_start_tag { - /* the real start routine and arg */ - void *(*start_routine)(void *); - void *arg; - - /* the other stuff we need to make sure this thread is inserted into - ** the thread tree - */ - thread_type *thread; - pthread_t sys_thread; -} thread_start_t; - -static long _next_thread_id = 0; -static int _initialized = 0; -static avl_tree *_threadtree = NULL; - -#ifdef DEBUG_MUTEXES -static mutex_t _threadtree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1, - PTHREAD_MUTEX_INITIALIZER}; -#else -static mutex_t _threadtree_mutex = { PTHREAD_MUTEX_INITIALIZER }; -#endif - - - -#ifdef DEBUG_MUTEXES -static int _logid = -1; -static long _next_mutex_id = 0; - -static avl_tree *_mutextree = NULL; -static mutex_t _mutextree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1, - PTHREAD_MUTEX_INITIALIZER}; -#endif - -#ifdef DEBUG_MUTEXES -static mutex_t _library_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1, - PTHREAD_MUTEX_INITIALIZER}; -#else -static mutex_t _library_mutex = { PTHREAD_MUTEX_INITIALIZER }; -#endif - -/* INTERNAL FUNCTIONS */ - -/* avl tree functions */ -#ifdef DEBUG_MUTEXES -static int _compare_mutexes(void *compare_arg, void *a, void *b); -static int _free_mutex(void *key); -#endif - -static int _compare_threads(void *compare_arg, void *a, void *b); -static int _free_thread(void *key); - -/* mutex fuctions */ -static void _mutex_create(mutex_t *mutex); -static void _mutex_lock(mutex_t *mutex); -static void _mutex_unlock(mutex_t *mutex); - -/* misc thread stuff */ -static void *_start_routine(void *arg); -static void _catch_signals(void); -static void _block_signals(void); - -/* LIBRARY INITIALIZATION */ - -void thread_initialize(void) -{ - thread_type *thread; - - /* set up logging */ - -#ifdef THREAD_DEBUG - log_initialize(); - _logid = log_open("thread.log"); - log_set_level(_logid, THREAD_DEBUG); -#endif - -#ifdef DEBUG_MUTEXES - /* create all the internal mutexes, and initialize the mutex tree */ - - _mutextree = avl_tree_new(_compare_mutexes, NULL); - - /* we have to create this one by hand, because there's no - ** mutextree_mutex to lock yet! - */ - _mutex_create(&_mutextree_mutex); - - _mutextree_mutex.mutex_id = _next_mutex_id++; - avl_insert(_mutextree, (void *)&_mutextree_mutex); -#endif - - thread_mutex_create(&_threadtree_mutex); - thread_mutex_create(&_library_mutex); - - /* initialize the thread tree and insert the main thread */ - - _threadtree = avl_tree_new(_compare_threads, NULL); - - thread = (thread_type *)malloc(sizeof(thread_type)); - - thread->thread_id = _next_thread_id++; - thread->line = 0; - thread->file = strdup("main.c"); - thread->sys_thread = pthread_self(); - thread->create_time = time(NULL); - thread->name = strdup("Main Thread"); - - avl_insert(_threadtree, (void *)thread); - - _catch_signals(); - - _initialized = 1; -} - -void thread_shutdown(void) -{ - if (_initialized == 1) { - thread_mutex_destroy(&_library_mutex); - thread_mutex_destroy(&_threadtree_mutex); -#ifdef THREAD_DEBUG - thread_mutex_destroy(&_mutextree_mutex); - - avl_tree_free(_mutextree, _free_mutex); -#endif - avl_tree_free(_threadtree, _free_thread); - _threadtree = NULL; - } - -#ifdef THREAD_DEBUG - log_close(_logid); - log_shutdown(); -#endif - -} - -/* - * Signals should be handled by the main thread, nowhere else. - * I'm using POSIX signal interface here, until someone tells me - * that I should use signal/sigset instead - * - * This function only valid for non-Win32 - */ -static void _block_signals(void) -{ -#ifndef _WIN32 - sigset_t ss; - - sigfillset(&ss); - - /* These ones we want */ - sigdelset(&ss, SIGKILL); - sigdelset(&ss, SIGSTOP); - sigdelset(&ss, SIGSEGV); - sigdelset(&ss, SIGCHLD); - sigdelset(&ss, SIGBUS); - if (pthread_sigmask(SIG_BLOCK, &ss, NULL) != 0) { -#ifdef THREAD_DEBUG - LOG_ERROR("Pthread_sigmask() failed for blocking signals"); -#endif - } -#endif -} - -/* - * Let the calling thread catch all the relevant signals - * - * This function only valid for non-Win32 - */ -static void _catch_signals(void) -{ -#ifndef _WIN32 - sigset_t ss; - - sigemptyset(&ss); - - /* These ones should only be accepted by the signal handling thread (main thread) */ - sigaddset(&ss, SIGHUP); - sigaddset(&ss, SIGCHLD); - sigaddset(&ss, SIGINT); - sigaddset(&ss, SIGPIPE); - sigaddset(&ss, SIGTERM); - - if (pthread_sigmask(SIG_UNBLOCK, &ss, NULL) != 0) { -#ifdef THREAD_DEBUG - LOG_ERROR("pthread_sigmask() failed for catching signals!"); -#endif - } -#endif -} - - -thread_type *thread_create_c(char *name, void *(*start_routine)(void *), - void *arg, int detached, int line, char *file) -{ - int ok = 1; - thread_type *thread = NULL; - thread_start_t *start = NULL; - pthread_attr_t attr; - - thread = (thread_type *)calloc(1, sizeof(thread_type)); - do { - if (thread == NULL) - break; - start = (thread_start_t *)calloc(1, sizeof(thread_start_t)); - if (start == NULL) - break; - if (pthread_attr_init (&attr) < 0) - break; - - thread->line = line; - thread->file = strdup(file); - - _mutex_lock (&_threadtree_mutex); - thread->thread_id = _next_thread_id++; - _mutex_unlock (&_threadtree_mutex); - - thread->name = strdup(name); - thread->create_time = time(NULL); - - start->start_routine = start_routine; - start->arg = arg; - start->thread = thread; - - pthread_attr_setstacksize (&attr, 512*1024); - pthread_attr_setinheritsched (&attr, PTHREAD_INHERIT_SCHED); - if (detached) - { - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - thread->detached = 1; - } - - if (pthread_create (&thread->sys_thread, &attr, _start_routine, start) == 0) - { - pthread_attr_destroy (&attr); - return thread; - } - else - pthread_attr_destroy (&attr); - } - while (0); - -#ifdef THREAD_DEBUG - LOG_ERROR("Could not create new thread %s", name); -#endif - if (start) free (start); - if (thread) free (thread); - return NULL; -} - -/* _mutex_create -** -** creates a mutex -*/ -static void _mutex_create(mutex_t *mutex) -{ -#ifdef DEBUG_MUTEXES - mutex->thread_id = MUTEX_STATE_NEVERLOCKED; - mutex->line = -1; -#endif - - pthread_mutex_init(&mutex->sys_mutex, NULL); -} - -void thread_mutex_create_c(mutex_t *mutex, int line, char *file) -{ - _mutex_create(mutex); - -#ifdef DEBUG_MUTEXES - _mutex_lock(&_mutextree_mutex); - mutex->mutex_id = _next_mutex_id++; - avl_insert(_mutextree, (void *)mutex); - _mutex_unlock(&_mutextree_mutex); -#endif -} - -void thread_mutex_destroy (mutex_t *mutex) -{ - pthread_mutex_destroy(&mutex->sys_mutex); - -#ifdef DEBUG_MUTEXES - _mutex_lock(&_mutextree_mutex); - avl_delete(_mutextree, mutex, _free_mutex); - _mutex_unlock(&_mutextree_mutex); -#endif -} - -void thread_mutex_lock_c(mutex_t *mutex, int line, char *file) -{ -#ifdef DEBUG_MUTEXES - thread_type *th = thread_self(); - - if (!th) LOG_WARN("No mt record for %u in lock [%s:%d]", thread_self(), file, line); - - LOG_DEBUG5("Locking %p (%s) on line %d in file %s by thread %d", mutex, mutex->name, line, file, th ? th->thread_id : -1); - -# ifdef CHECK_MUTEXES - /* Just a little sanity checking to make sure that we're locking - ** mutexes correctly - */ - - if (th) { - int locks = 0; - avl_node *node; - mutex_t *tmutex; - - _mutex_lock(&_mutextree_mutex); - - node = avl_get_first (_mutextree); - - while (node) { - tmutex = (mutex_t *)node->key; - - if (tmutex->mutex_id == mutex->mutex_id) { - if (tmutex->thread_id == th->thread_id) { - /* Deadlock, same thread can't lock the same mutex twice */ - LOG_ERROR7("DEADLOCK AVOIDED (%d == %d) on mutex [%s] in file %s line %d by thread %d [%s]", - tmutex->thread_id, th->thread_id, mutex->name ? mutex->name : "undefined", file, line, th->thread_id, th->name); - - _mutex_unlock(&_mutextree_mutex); - return; - } - } else if (tmutex->thread_id == th->thread_id) { - /* Mutex locked by this thread (not this mutex) */ - locks++; - } - - node = avl_get_next(node); - } - - if (locks > 0) { - /* Has already got a mutex locked */ - if (_multi_mutex.thread_id != th->thread_id) { - /* Tries to lock two mutexes, but has not got the double mutex, norty boy! */ - LOG_WARN("(%d != %d) Thread %d [%s] tries to lock a second mutex [%s] in file %s line %d, without locking double mutex!", - _multi_mutex.thread_id, th->thread_id, th->thread_id, th->name, mutex->name ? mutex->name : "undefined", file, line); - } - } - - _mutex_unlock(&_mutextree_mutex); - } -# endif /* CHECK_MUTEXES */ - - _mutex_lock(mutex); - - _mutex_lock(&_mutextree_mutex); - - LOG_DEBUG2("Locked %p by thread %d", mutex, th ? th->thread_id : -1); - mutex->line = line; - if (th) { - mutex->thread_id = th->thread_id; - } - - _mutex_unlock(&_mutextree_mutex); -#else - _mutex_lock(mutex); -#endif /* DEBUG_MUTEXES */ -} - -void thread_mutex_unlock_c(mutex_t *mutex, int line, char *file) -{ -#ifdef DEBUG_MUTEXES - thread_type *th = thread_self(); - - if (!th) { - LOG_ERROR3("No record for %u in unlock [%s:%d]", thread_self(), file, line); - } - - LOG_DEBUG5("Unlocking %p (%s) on line %d in file %s by thread %d", mutex, mutex->name, line, file, th ? th->thread_id : -1); - - mutex->line = line; - -# ifdef CHECK_MUTEXES - if (th) { - int locks = 0; - avl_node *node; - mutex_t *tmutex; - - _mutex_lock(&_mutextree_mutex); - - while (node) { - tmutex = (mutex_t *)node->key; - - if (tmutex->mutex_id == mutex->mutex_id) { - if (tmutex->thread_id != th->thread_id) { - LOG_ERROR7("ILLEGAL UNLOCK (%d != %d) on mutex [%s] in file %s line %d by thread %d [%s]", tmutex->thread_id, th->thread_id, - mutex->name ? mutex->name : "undefined", file, line, th->thread_id, th->name); - _mutex_unlock(&_mutextree_mutex); - return; - } - } else if (tmutex->thread_id == th->thread_id) { - locks++; - } - - node = avl_get_next (node); - } - - if ((locks > 0) && (_multi_mutex.thread_id != th->thread_id)) { - /* Don't have double mutex, has more than this mutex left */ - - LOG_WARN("(%d != %d) Thread %d [%s] tries to unlock a mutex [%s] in file %s line %d, without owning double mutex!", - _multi_mutex.thread_id, th->thread_id, th->thread_id, th->name, mutex->name ? mutex->name : "undefined", file, line); - } - - _mutex_unlock(&_mutextree_mutex); - } -# endif /* CHECK_MUTEXES */ - - _mutex_unlock(mutex); - - _mutex_lock(&_mutextree_mutex); - - LOG_DEBUG2("Unlocked %p by thread %d", mutex, th ? th->thread_id : -1); - mutex->line = -1; - if (mutex->thread_id == th->thread_id) { - mutex->thread_id = MUTEX_STATE_NOTLOCKED; - } - - _mutex_unlock(&_mutextree_mutex); -#else - _mutex_unlock(mutex); -#endif /* DEBUG_MUTEXES */ -} - -void thread_cond_create_c(cond_t *cond, int line, char *file) -{ - pthread_cond_init(&cond->sys_cond, NULL); - pthread_mutex_init(&cond->cond_mutex, NULL); -} - -void thread_cond_destroy(cond_t *cond) -{ - pthread_mutex_destroy(&cond->cond_mutex); - pthread_cond_destroy(&cond->sys_cond); -} - -void thread_cond_signal_c(cond_t *cond, int line, char *file) -{ - pthread_cond_signal(&cond->sys_cond); -} - -void thread_cond_broadcast_c(cond_t *cond, int line, char *file) -{ - pthread_cond_broadcast(&cond->sys_cond); -} - -void thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *file) -{ - struct timespec time; - - time.tv_sec = millis/1000; - time.tv_nsec = (millis - time.tv_sec*1000)*1000000; - - pthread_mutex_lock(&cond->cond_mutex); - pthread_cond_timedwait(&cond->sys_cond, &cond->cond_mutex, &time); - pthread_mutex_unlock(&cond->cond_mutex); -} - -void thread_cond_wait_c(cond_t *cond, int line, char *file) -{ - pthread_mutex_lock(&cond->cond_mutex); - pthread_cond_wait(&cond->sys_cond, &cond->cond_mutex); - pthread_mutex_unlock(&cond->cond_mutex); -} - -void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file) -{ - pthread_rwlock_init(&rwlock->sys_rwlock, NULL); -} - -void thread_rwlock_destroy(rwlock_t *rwlock) -{ - pthread_rwlock_destroy(&rwlock->sys_rwlock); -} - -void thread_rwlock_rlock_c(rwlock_t *rwlock, int line, char *file) -{ - pthread_rwlock_rdlock(&rwlock->sys_rwlock); -} - -void thread_rwlock_wlock_c(rwlock_t *rwlock, int line, char *file) -{ - pthread_rwlock_wrlock(&rwlock->sys_rwlock); -} - -void thread_rwlock_unlock_c(rwlock_t *rwlock, int line, char *file) -{ - pthread_rwlock_unlock(&rwlock->sys_rwlock); -} - -void thread_exit_c(long val, int line, char *file) -{ - thread_type *th = thread_self(); - -#if defined(DEBUG_MUTEXES) && defined(CHECK_MUTEXES) - if (th) { - avl_node *node; - mutex_t *tmutex; - char name[40]; - - _mutex_lock(&_mutextree_mutex); - - while (node) { - tmutex = (mutex_t *)node->key; - - if (tmutex->thread_id == th->thread_id) { - LOG_WARN("Thread %d [%s] exiting in file %s line %d, without unlocking mutex [%s]", - th->thread_id, th->name, file, line, mutex_to_string(tmutex, name)); - } - - node = avl_get_next (node); - } - - _mutex_unlock(&_mutextree_mutex); - } -#endif - - if (th && th->detached) - { -#ifdef THREAD_DEBUG - LOG_INFO4("Removing thread %d [%s] started at [%s:%d], reason: 'Thread Exited'", th->thread_id, th->name, th->file, th->line); -#endif - - _mutex_lock(&_threadtree_mutex); - avl_delete(_threadtree, th, _free_thread); - _mutex_unlock(&_threadtree_mutex); - } - - pthread_exit ((void*)val); -} - -/* sleep for a number of microseconds */ -void thread_sleep(unsigned long len) -{ -#ifdef _WIN32 - Sleep(len / 1000); -#else -# ifdef HAVE_NANOSLEEP - struct timespec time_sleep; - struct timespec time_remaining; - int ret; - - time_sleep.tv_sec = len / 1000000; - time_sleep.tv_nsec = (len % 1000000) * 1000; - - ret = nanosleep(&time_sleep, &time_remaining); - while (ret != 0 && errno == EINTR) { - time_sleep.tv_sec = time_remaining.tv_sec; - time_sleep.tv_nsec = time_remaining.tv_nsec; - - ret = nanosleep(&time_sleep, &time_remaining); - } -# else - struct timeval tv; - - tv.tv_sec = len / 1000000; - tv.tv_usec = (len % 1000000); - - select(0, NULL, NULL, NULL, &tv); -# endif -#endif -} - -static void *_start_routine(void *arg) -{ - thread_start_t *start = (thread_start_t *)arg; - void *(*start_routine)(void *) = start->start_routine; - void *real_arg = start->arg; - thread_type *thread = start->thread; - - _block_signals(); - - /* insert thread into thread tree here */ - _mutex_lock(&_threadtree_mutex); - thread->sys_thread = pthread_self(); - avl_insert(_threadtree, (void *)thread); - _mutex_unlock(&_threadtree_mutex); - -#ifdef THREAD_DEBUG - LOG_INFO4("Added thread %d [%s] started at [%s:%d]", thread->thread_id, thread->name, thread->file, thread->line); -#endif - - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - free (start); - - (start_routine)(real_arg); - - if (thread->detached) - { - _mutex_lock (&_threadtree_mutex); - avl_delete (_threadtree, thread, _free_thread); - _mutex_unlock (&_threadtree_mutex); - } - - return NULL; -} - -thread_type *thread_self(void) -{ - avl_node *node; - thread_type *th; - pthread_t sys_thread = pthread_self(); - - _mutex_lock(&_threadtree_mutex); - - if (_threadtree == NULL) { -#ifdef THREAD_DEBUG - LOG_WARN("Thread tree is empty, this must be wrong!"); -#endif - _mutex_unlock(&_threadtree_mutex); - return NULL; - } - - node = avl_get_first(_threadtree); - - while (node) { - th = (thread_type *)node->key; - - if (th && pthread_equal(sys_thread, th->sys_thread)) { - _mutex_unlock(&_threadtree_mutex); - return th; - } - - node = avl_get_next(node); - } - _mutex_unlock(&_threadtree_mutex); - - -#ifdef THREAD_DEBUG - LOG_ERROR("Nonexistant thread alive..."); -#endif - - return NULL; -} - -void thread_rename(const char *name) -{ - thread_type *th; - - th = thread_self(); - if (th->name) free(th->name); - - th->name = strdup(name); -} - -static void _mutex_lock(mutex_t *mutex) -{ - pthread_mutex_lock(&mutex->sys_mutex); -} - -static void _mutex_unlock(mutex_t *mutex) -{ - pthread_mutex_unlock(&mutex->sys_mutex); -} - - -void thread_library_lock(void) -{ - _mutex_lock(&_library_mutex); -} - -void thread_library_unlock(void) -{ - _mutex_unlock(&_library_mutex); -} - -void thread_join(thread_type *thread) -{ - void *ret; - int i; - - i = pthread_join(thread->sys_thread, &ret); - _mutex_lock(&_threadtree_mutex); - avl_delete(_threadtree, thread, _free_thread); - _mutex_unlock(&_threadtree_mutex); -} - -/* AVL tree functions */ - -#ifdef DEBUG_MUTEXES -static int _compare_mutexes(void *compare_arg, void *a, void *b) -{ - mutex_t *m1, *m2; - - m1 = (mutex_t *)a; - m2 = (mutex_t *)b; - - if (m1->mutex_id > m2->mutex_id) - return 1; - if (m1->mutex_id < m2->mutex_id) - return -1; - return 0; -} -#endif - -static int _compare_threads(void *compare_arg, void *a, void *b) -{ - thread_type *t1, *t2; - - t1 = (thread_type *)a; - t2 = (thread_type *)b; - - if (t1->thread_id > t2->thread_id) - return 1; - if (t1->thread_id < t2->thread_id) - return -1; - return 0; -} - -#ifdef DEBUG_MUTEXES -static int _free_mutex(void *key) -{ - mutex_t *m; - - m = (mutex_t *)key; - - if (m && m->file) { - free(m->file); - m->file = NULL; - } - - /* all mutexes are static. don't need to free them */ - - return 1; -} -#endif - -static int _free_thread(void *key) -{ - thread_type *t; - - t = (thread_type *)key; - - if (t->file) - free(t->file); - if (t->name) - free(t->name); - - free(t); - - return 1; -} - - -#ifdef HAVE_PTHREAD_SPIN_LOCK -void thread_spin_create (spin_t *spin) -{ - int x = pthread_spin_init (&spin->lock, PTHREAD_PROCESS_PRIVATE); - if (x) - abort(); -} - -void thread_spin_destroy (spin_t *spin) -{ - pthread_spin_destroy (&spin->lock); -} - -void thread_spin_lock (spin_t *spin) -{ - int x = pthread_spin_lock (&spin->lock); - if (x != 0) - abort(); -} - -void thread_spin_unlock (spin_t *spin) -{ - pthread_spin_unlock (&spin->lock); -} -#endif - diff --git a/src/thread/thread.h b/src/thread/thread.h deleted file mode 100644 index 9b50040b..00000000 --- a/src/thread/thread.h +++ /dev/null @@ -1,202 +0,0 @@ -/* thread.h - * - Thread Abstraction Function Headers - * - * Copyright (c) 1999, 2000 the icecast team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __THREAD_H__ -#define __THREAD_H__ - -#include - -/* renamed from thread_t due to conflict on OS X */ - -typedef struct { - /* the local id for the thread, and it's name */ - long thread_id; - char *name; - - /* the time the thread was created */ - time_t create_time; - - /* the file and line which created this thread */ - char *file; - int line; - - /* is the thread running detached? */ - int detached; - - /* the system specific thread */ - pthread_t sys_thread; -} thread_type; - -typedef struct { -#ifdef DEBUG_MUTEXES - /* the local id and name of the mutex */ - long mutex_id; - char *name; - - /* the thread which is currently locking this mutex */ - long thread_id; - - /* the file and line where the mutex was locked */ - char *file; - int line; - -#endif - - /* the system specific mutex */ - pthread_mutex_t sys_mutex; -} mutex_t; - -typedef struct { -#ifdef THREAD_DEBUG - long cond_id; - char *name; -#endif - - pthread_mutex_t cond_mutex; - pthread_cond_t sys_cond; -} cond_t; - -typedef struct { -#ifdef THREAD_DEBUG - long rwlock_id; - char *name; - - /* information on which thread and where in the code - ** this rwlock was write locked - */ - long thread_id; - char *file; - int line; -#endif - - pthread_rwlock_t sys_rwlock; -} rwlock_t; - -#ifdef HAVE_PTHREAD_SPIN_LOCK -typedef struct -{ - pthread_spinlock_t lock; -} spin_t; - -void thread_spin_create (spin_t *spin); -void thread_spin_destroy (spin_t *spin); -void thread_spin_lock (spin_t *spin); -void thread_spin_unlock (spin_t *spin); -#else -typedef mutex_t spin_t; -#define thread_spin_create(x) thread_mutex_create(x) -#define thread_spin_destroy(x) thread_mutex_destroy(x) -#define thread_spin_lock(x) thread_mutex_lock(x) -#define thread_spin_unlock(x) thread_mutex_unlock(x) -#endif - -#define thread_create(n,x,y,z) thread_create_c(n,x,y,z,__LINE__,__FILE__) -#define thread_mutex_create(x) thread_mutex_create_c(x,__LINE__,__FILE__) -#define thread_mutex_lock(x) thread_mutex_lock_c(x,__LINE__,__FILE__) -#define thread_mutex_unlock(x) thread_mutex_unlock_c(x,__LINE__,__FILE__) -#define thread_cond_create(x) thread_cond_create_c(x,__LINE__,__FILE__) -#define thread_cond_signal(x) thread_cond_signal_c(x,__LINE__,__FILE__) -#define thread_cond_broadcast(x) thread_cond_broadcast_c(x,__LINE__,__FILE__) -#define thread_cond_wait(x) thread_cond_wait_c(x,__LINE__,__FILE__) -#define thread_cond_timedwait(x,t) thread_cond_wait_c(x,t,__LINE__,__FILE__) -#define thread_rwlock_create(x) thread_rwlock_create_c(x,__LINE__,__FILE__) -#define thread_rwlock_rlock(x) thread_rwlock_rlock_c(x,__LINE__,__FILE__) -#define thread_rwlock_wlock(x) thread_rwlock_wlock_c(x,__LINE__,__FILE__) -#define thread_rwlock_unlock(x) thread_rwlock_unlock_c(x,__LINE__,__FILE__) -#define thread_exit(x) thread_exit_c(x,__LINE__,__FILE__) - -#define MUTEX_STATE_NOTLOCKED -1 -#define MUTEX_STATE_NEVERLOCKED -2 -#define MUTEX_STATE_UNINIT -3 -#define THREAD_DETACHED 1 -#define THREAD_ATTACHED 0 - -#ifdef _mangle -# define thread_initialize _mangle(thread_initialize) -# define thread_initialize_with_log_id _mangle(thread_initialize_with_log_id) -# define thread_shutdown _mangle(thread_shutdown) -# define thread_create_c _mangle(thread_create_c) -# define thread_mutex_create_c _mangle(thread_mutex_create) -# define thread_mutex_lock_c _mangle(thread_mutex_lock_c) -# define thread_mutex_unlock_c _mangle(thread_mutex_unlock_c) -# define thread_mutex_destroy _mangle(thread_mutex_destroy) -# define thread_cond_create_c _mangle(thread_cond_create_c) -# define thread_cond_signal_c _mangle(thread_cond_signal_c) -# define thread_cond_broadcast_c _mangle(thread_cond_broadcast_c) -# define thread_cond_wait_c _mangle(thread_cond_wait_c) -# define thread_cond_timedwait_c _mangle(thread_cond_timedwait_c) -# define thread_cond_destroy _mangle(thread_cond_destroy) -# define thread_rwlock_create_c _mangle(thread_rwlock_create_c) -# define thread_rwlock_rlock_c _mangle(thread_rwlock_rlock_c) -# define thread_rwlock_wlock_c _mangle(thread_rwlock_wlock_c) -# define thread_rwlock_unlock_c _mangle(thread_rwlock_unlock_c) -# define thread_rwlock_destroy _mangle(thread_rwlock_destroy) -# define thread_exit_c _mangle(thread_exit_c) -# define thread_sleep _mangle(thread_sleep) -# define thread_library_lock _mangle(thread_library_lock) -# define thread_library_unlock _mangle(thread_library_unlock) -# define thread_self _mangle(thread_self) -# define thread_rename _mangle(thread_rename) -# define thread_join _mangle(thread_join) -#endif - -/* init/shutdown of the library */ -void thread_initialize(void); -void thread_initialize_with_log_id(int log_id); -void thread_shutdown(void); - -/* creation, destruction, locking, unlocking, signalling and waiting */ -thread_type *thread_create_c(char *name, void *(*start_routine)(void *), - void *arg, int detached, int line, char *file); -void thread_mutex_create_c(mutex_t *mutex, int line, char *file); -void thread_mutex_lock_c(mutex_t *mutex, int line, char *file); -void thread_mutex_unlock_c(mutex_t *mutex, int line, char *file); -void thread_mutex_destroy(mutex_t *mutex); -void thread_cond_create_c(cond_t *cond, int line, char *file); -void thread_cond_signal_c(cond_t *cond, int line, char *file); -void thread_cond_broadcast_c(cond_t *cond, int line, char *file); -void thread_cond_wait_c(cond_t *cond, int line, char *file); -void thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *file); -void thread_cond_destroy(cond_t *cond); -void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file); -void thread_rwlock_rlock_c(rwlock_t *rwlock, int line, char *file); -void thread_rwlock_wlock_c(rwlock_t *rwlock, int line, char *file); -void thread_rwlock_unlock_c(rwlock_t *rwlock, int line, char *file); -void thread_rwlock_destroy(rwlock_t *rwlock); -void thread_exit_c(long val, int line, char *file); - -/* sleeping */ -void thread_sleep(unsigned long len); - -/* for using library functions which aren't threadsafe */ -void thread_library_lock(void); -void thread_library_unlock(void); -#define PROTECT_CODE(code) { thread_library_lock(); code; thread_library_unlock(); } - -/* thread information functions */ -thread_type *thread_self(void); - -/* renames current thread */ -void thread_rename(const char *name); - -/* waits until thread_exit is called for another thread */ -void thread_join(thread_type *thread); - -#endif /* __THREAD_H__ */ diff --git a/src/timing/BUILDING b/src/timing/BUILDING deleted file mode 100644 index 0aa7006f..00000000 --- a/src/timing/BUILDING +++ /dev/null @@ -1,7 +0,0 @@ -defines that affect compilation - -none - -library dependencies - -none diff --git a/src/timing/COPYING b/src/timing/COPYING deleted file mode 100644 index 92b8903f..00000000 --- a/src/timing/COPYING +++ /dev/null @@ -1,481 +0,0 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also compile or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - c) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - d) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/src/timing/Makefile.am b/src/timing/Makefile.am deleted file mode 100644 index 493112e0..00000000 --- a/src/timing/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -## Process this with automake to create Makefile.in - -AUTOMAKE_OPTIONS = foreign - -EXTRA_DIST = BUILDING COPYING README TODO - -noinst_LTLIBRARIES = libicetiming.la -noinst_HEADERS = timing.h - -libicetiming_la_SOURCES = timing.c -libicetiming_la_CFLAGS = @XIPH_CFLAGS@ - -debug: - $(MAKE) all CFLAGS="@DEBUG@" - -profile: - $(MAKE) all CFLAGS="@PROFILE@" - diff --git a/src/timing/README b/src/timing/README deleted file mode 100644 index b43ead9d..00000000 --- a/src/timing/README +++ /dev/null @@ -1,5 +0,0 @@ -this is the timing library. - -lgpl - -by jack moffitt diff --git a/src/timing/TODO b/src/timing/TODO deleted file mode 100644 index 585db898..00000000 --- a/src/timing/TODO +++ /dev/null @@ -1,2 +0,0 @@ - -nothing diff --git a/src/timing/timing.c b/src/timing/timing.c deleted file mode 100644 index dd802319..00000000 --- a/src/timing/timing.c +++ /dev/null @@ -1,84 +0,0 @@ -/* timing.c -** - Timing functions -** -** This program is distributed under the GNU General Public License, version 2. -** A copy of this license is included with this source. -*/ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include - -#ifdef _WIN32 -#include -#include -#else -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#include -#endif - -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#ifdef HAVE_SYS_TIMEB_H -#include -#endif - -#include "timing.h" - -/* see timing.h for an explanation of _mangle() */ - -/* - * Returns milliseconds no matter what. - */ -uint64_t timing_get_time(void) -{ -#ifdef HAVE_GETTIMEOFDAY - struct timeval mtv; - - gettimeofday(&mtv, NULL); - - return (uint64_t)(mtv.tv_sec) * 1000 + (uint64_t)(mtv.tv_usec) / 1000; -#elif HAVE_FTIME - struct timeb t; - - ftime(&t); - return t.time * 1000 + t.millitm; -#else -#error need time query handler -#endif -} - - -void timing_sleep(uint64_t sleeptime) -{ - struct timeval sleeper; - - sleeper.tv_sec = sleeptime / 1000; - sleeper.tv_usec = (sleeptime % 1000) * 1000; - - /* NOTE: - * This should be 0 for the first argument. The linux manpage - * says so. The solaris manpage also says this is a legal - * value. If you think differerntly, please provide references. - */ -#ifdef WIN32 - Sleep(sleeptime); -#else - select(1, NULL, NULL, NULL, &sleeper); -#endif -} diff --git a/src/timing/timing.h b/src/timing/timing.h deleted file mode 100644 index 2ecd524b..00000000 --- a/src/timing/timing.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -** Timing functions. -** -** This program is distributed under the GNU General Public License, version 2. -** A copy of this license is included with this source. -*/ - -#ifndef __TIMING_H__ -#define __TIMING_H__ - -#include -#ifdef HAVE_INTTYPES_H -#include -#elif defined(HAVE_STDINT_H) -#include -#endif - -#if defined(_WIN32) && !defined(int64_t) -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#endif - -/* config.h should be included before we are to define _mangle */ -#ifdef _mangle -# define timing_get_time _mangle(timing_get_time) -# define timing_sleep _mangle(timing_sleep) -#endif - -uint64_t timing_get_time(void); -void timing_sleep(uint64_t sleeptime); - -#endif /* __TIMING_H__ */ diff --git a/src/util.c b/src/util.c index 1eb65c7f..365de7c6 100644 --- a/src/util.c +++ b/src/util.c @@ -36,8 +36,8 @@ #define strncasecmp strnicmp #endif -#include "net/sock.h" -#include "thread/thread.h" +#include "common/net/sock.h" +#include "common/thread/thread.h" #include "cfgfile.h" #include "util.h" diff --git a/src/xslt.c b/src/xslt.c index 2e047d5f..30977360 100644 --- a/src/xslt.c +++ b/src/xslt.c @@ -38,10 +38,10 @@ #define snprintf _snprintf #endif -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" -#include "net/sock.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" +#include "common/net/sock.h" #include "connection.h" diff --git a/src/xslt.h b/src/xslt.h index 6fe54e71..841ceb20 100644 --- a/src/xslt.h +++ b/src/xslt.h @@ -20,10 +20,10 @@ #include -#include "thread/thread.h" -#include "avl/avl.h" -#include "httpp/httpp.h" -#include "net/sock.h" +#include "common/thread/thread.h" +#include "common/avl/avl.h" +#include "common/httpp/httpp.h" +#include "common/net/sock.h" #include "connection.h" diff --git a/src/yp.c b/src/yp.c index 0d06a647..920f2cde 100644 --- a/src/yp.c +++ b/src/yp.c @@ -20,7 +20,7 @@ #include #include -#include "thread/thread.h" +#include "common/thread/thread.h" #include "connection.h" #include "refbuf.h"