├── .gitignore ├── AUTHORS ├── BSDmakefile ├── COPYING ├── GIT-Access ├── Makefile ├── README ├── autogen.sh ├── buildsys.mk.in ├── config.guess ├── config.rpath ├── config.sub ├── configure ├── configure.ac ├── doc ├── BOOST └── design-concepts.txt ├── extra.mk.in ├── install-sh ├── libmowgli-2.pc.in ├── m4 ├── acx_pthread.m4 ├── ax_check_openssl.m4 ├── buildsys.m4 └── pkg.m4 ├── scripts └── makerelease.sh ├── src ├── Makefile ├── examples │ ├── Makefile │ ├── async_resolver │ │ ├── Makefile │ │ └── async_resolver.c │ ├── echoserver │ │ ├── Makefile │ │ └── echoserver.c │ ├── formattertest │ │ ├── Makefile │ │ └── formattertest.c │ ├── helpertest │ │ ├── Makefile │ │ └── helpertest.c │ ├── jsontest │ │ ├── Makefile │ │ └── jsontest.c │ ├── libevent-bench │ │ ├── Makefile │ │ └── bench.c │ ├── linetest │ │ ├── Makefile │ │ └── linetest.c │ ├── listsort │ │ ├── Makefile │ │ └── listsort.c │ ├── memslice-bench │ │ ├── Makefile │ │ └── memslice-bench.c │ ├── patriciatest │ │ ├── Makefile │ │ └── patriciatest.c │ ├── patriciatest2 │ │ ├── Makefile │ │ └── patriciatest2.c │ ├── randomtest │ │ ├── Makefile │ │ └── randomtest.c │ ├── timertest │ │ ├── Makefile │ │ └── timertest.c │ └── vio-udplistener │ │ ├── Makefile │ │ └── vio-udplistener.c └── libmowgli │ ├── Makefile │ ├── base │ ├── Makefile │ ├── argstack.c │ ├── argstack.h │ ├── bitvector.c │ ├── bitvector.h │ ├── formatter.c │ ├── formatter.h │ ├── hash.c │ ├── hash.h │ ├── hook.c │ ├── hook.h │ ├── memslice.c │ ├── memslice.h │ ├── mowgli_signal.c │ ├── mowgli_signal.h │ ├── random.c │ └── random.h │ ├── container │ ├── Makefile │ ├── dictionary.c │ ├── dictionary.h │ ├── index.c │ ├── index.h │ ├── list.c │ ├── list.h │ ├── patricia.c │ ├── patricia.h │ ├── queue.c │ └── queue.h │ ├── core │ ├── Makefile │ ├── alloc.c │ ├── alloc.h │ ├── allocation_policy.c │ ├── allocation_policy.h │ ├── allocator.c │ ├── allocator.h │ ├── assert.h │ ├── bootstrap.c │ ├── bootstrap.h │ ├── bootstrap_internal.h │ ├── heap.c │ ├── heap.disabled.c │ ├── heap.enabled.c │ ├── heap.h │ ├── iterator.h │ ├── logger.c │ ├── logger.h │ ├── mowgli_string.c │ ├── mowgli_string.h │ ├── process.c │ ├── process.h │ └── stdinc.h │ ├── dns │ ├── Makefile │ ├── dns.c │ ├── dns.h │ ├── evloop_res.c │ ├── evloop_res.h │ ├── evloop_reslib.c │ ├── evloop_reslib.h │ └── evloop_reslist_win32.c │ ├── eventloop │ ├── Makefile │ ├── epoll_pollops.c │ ├── eventloop.c │ ├── eventloop.h │ ├── eventloop_internal.h │ ├── helper.c │ ├── kqueue_pollops.c │ ├── null_pollops.c │ ├── poll_pollops.c │ ├── pollable.c │ ├── ports_pollops.c │ ├── qnx_pollops.c │ ├── select_pollops.c │ ├── timer.c │ └── windows_pollops.c │ ├── ext │ ├── Makefile │ ├── confparse.c │ ├── confparse.h │ ├── error_backtrace.c │ ├── error_backtrace.h │ ├── getopt_long.c │ ├── getopt_long.h │ ├── global_storage.c │ ├── global_storage.h │ ├── json-inline.h │ ├── json.c │ ├── json.h │ ├── proctitle.c │ ├── proctitle.h │ ├── program_opts.c │ └── program_opts.h │ ├── linebuf │ ├── Makefile │ ├── linebuf.c │ └── linebuf.h │ ├── module │ ├── Makefile │ ├── interface.c │ ├── loader_posix.c │ ├── loader_win32.c │ └── module.h │ ├── mowgli.h │ ├── object │ ├── Makefile │ ├── class.c │ ├── class.h │ ├── message.c │ ├── message.h │ ├── metadata.c │ ├── metadata.h │ ├── object.c │ └── object.h │ ├── platform │ ├── Makefile │ ├── attributes.h │ ├── autoconf.h.in │ ├── cacheline.c │ ├── cacheline.h │ ├── constructor.h │ ├── machine.h │ └── win32 │ │ ├── Makefile │ │ ├── fork.c │ │ ├── inet.c │ │ ├── pipe.c │ │ ├── setenv.c │ │ ├── socketpair.c │ │ └── win32_stdinc.h │ ├── thread │ ├── Makefile │ ├── mutex.c │ ├── mutex.h │ ├── mutex_internal.h │ ├── null_mutexops.c │ ├── posix_mutexops.c │ ├── thread.h │ └── win32_mutexops.c │ └── vio │ ├── Makefile │ ├── vio.c │ ├── vio.h │ ├── vio_openssl.c │ └── vio_sockets.c └── uncrustify.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | aclocal.m4 2 | autom4te.cache 3 | buildsys.mk 4 | src/libmowgli/platform/autoconf.h 5 | config.log 6 | config.status 7 | extra.mk 8 | libmowgli-2.pc 9 | src/examples/dicttest/dicttest 10 | src/examples/formattertest/formattertest 11 | src/examples/listsort/listsort 12 | src/examples/randomtest/randomtest 13 | src/examples/patriciatest/patriciatest 14 | src/examples/patriciatest2/patriciatest2 15 | src/examples/echoserver/echoserver 16 | src/examples/timertest/timertest 17 | src/examples/helpertest/helpertest 18 | src/examples/libevent-bench/bench 19 | src/examples/linetest/linetest 20 | src/examples/memslice-bench/memslice-bench 21 | src/examples/vio-udplistener/vio-udplistener 22 | src/examples/futuretest/futuretest 23 | src/examples/async_resolver/async_resolver 24 | src/examples/jsontest/jsontest 25 | src/examples/jsontest/test.json 26 | .deps 27 | *.dylib 28 | *.o 29 | *.a 30 | *.so 31 | *.so.* 32 | *.lib 33 | *.dll 34 | *.exe 35 | *~ 36 | *.core 37 | core 38 | *.swp 39 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | All names are listed in alphabetical order. 2 | 3 | The following people are active contributors to libmowgli: 4 | Elizabeth Myers 5 | William Pitcock 6 | Jonathan Schleifer 7 | Jilles Tjoelker 8 | 9 | The following people have contributed to libmowgli in the past: 10 | Patrick McFarland 11 | Pippijn van Steenhoven 12 | Andrew Wilcox 13 | -------------------------------------------------------------------------------- /BSDmakefile: -------------------------------------------------------------------------------- 1 | # This BSDmakefile redirects to GNU make. 2 | 3 | all: .DEFAULT 4 | .DEFAULT: 5 | @case ${MAKE} in \ 6 | gmake|*/gmake) \ 7 | echo "BSDmakefile run using gmake??"; \ 8 | exit 1;; \ 9 | esac 10 | gmake ${.MAKEFLAGS} ${.TARGETS} 11 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005-2012 atheme.org and individual contributors as listed in 2 | specific source headers. 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice is present in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 9 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 12 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 14 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 15 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 16 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 17 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 | 19 | -------------------------------------------------------------------------------- /GIT-Access: -------------------------------------------------------------------------------- 1 | The libmowgli GIT repository can be checked out using the following command: 2 | git clone git://github.com/atheme/libmowgli-2.git 3 | 4 | libmowgli's GIT repository can be browsed via HTTP at the following address: 5 | https://github.com/atheme/libmowgli-2 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS = src 2 | DISTCLEAN = extra.mk buildsys.mk config.log config.status libmowgli-2.pc 3 | 4 | include buildsys.mk 5 | 6 | install-extra: 7 | i="libmowgli-2.pc"; \ 8 | ${INSTALL_STATUS}; \ 9 | if ${MKDIR_P} ${DESTDIR}${libdir}/pkgconfig && ${INSTALL} -m 644 $$i ${DESTDIR}${libdir}/pkgconfig/$$i; then \ 10 | ${INSTALL_OK}; \ 11 | else \ 12 | ${INSTALL_FAILED}; \ 13 | fi 14 | 15 | uninstall-extra: 16 | i="libmowgli-2.pc"; \ 17 | if [ -f ${DESTDIR}${libdir}/pkgconfig/$$i ]; then \ 18 | if rm -f ${DESTDIR}${libdir}/pkgconfig/$$i; then \ 19 | ${DELETE_OK}; \ 20 | else \ 21 | ${DELETE_FAILED}; \ 22 | fi \ 23 | fi 24 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | libmowgli - A useful collection of routines for programming 2 | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 3 | 4 | libmowgli is a free but copyrighted library, check COPYING for details. 5 | 6 | 7 | Contents 8 | -------- 9 | 10 | 1. What is libmowgli? 11 | 2. Installation 12 | 3. Bug Reports 13 | 14 | 15 | What is libmowgli? 16 | ------------------ 17 | 18 | libmowgli is a class library containing performance and usability oriented 19 | extensions to C. 20 | 21 | It contains: 22 | - mowgli.alloc: A safe wrapper around malloc/free. 23 | - mowgli.argstack: Safe serialization of valists. 24 | - mowgli.assert: Various assertion routines that can be used. 25 | - mowgli.bitvector: Bitmasks with an unlimited level of precision. 26 | - mowgli.patricia: A dictionary implementation based on a modified 27 | patricia tree algorithm (uses nibbles instead of 28 | bits for branching). 29 | - mowgli.error_backtrace: Provide feedback to users on what caused 30 | the error they are recieving. 31 | - mowgli.formatter: A simple token formatter which is sometimes useful. 32 | - mowgli.global_storage: A simple global storage library. 33 | - mowgli.hash: A portable implementation of the FNV-1 hash. 34 | - mowgli.heap: An optimistic heap-based memory allocator 35 | - mowgli.hook: A simple hooks API you can use for your application, 36 | which allows for hooks to provide both application 37 | data and user data. 38 | - mowgli.json: A simple, flexible, reentrant JSON parser 39 | - mowgli.list: A high performance linked lists implementation with 40 | O(1) scalability for most common operations. 41 | - mowgli.logger: An internal class for handling logging of exceptions. 42 | - mowgli.module: A wrapper around dlopen(3) and dlsym(3). 43 | - mowgli.object: A simple class which provides reference counted 44 | pointers and polymorphism of structs. 45 | - mowgli.object_class: Classing and subclassing for objects. 46 | - mowgli.object_metadata: Metadata for objects. 47 | - mowgli.object_messaging: Messaging and signalling for objects. 48 | - mowgli.queue: A simple class which implements double-ended queues. 49 | - mowgli.random: A high performance psuedo-random number generator. 50 | - mowgli.signal: A wrapper for sigaction(2). 51 | - mowgli.eventloop: A portable event loop implementation. 52 | - mowgli.vio: An abstraction layer for I/O. 53 | - mowgli.linebuf: A line-buffering implementation for clients. 54 | - mowgli.thread: Minimal thread abstraction. 55 | 56 | More classes will be added with later releases. Please use GitHub's 57 | issue tracker if you have suggestions on what should be implemented. 58 | 59 | Installation 60 | ------------ 61 | 62 | Installation is fairly typical: 63 | 64 | $ ./configure 65 | $ make 66 | $ sudo make install 67 | 68 | (If sudo isn't on your system, su to root. On GNU systems you can even do 69 | "su -c 'make install'", which is basically the same thing as using sudo.) 70 | 71 | 72 | Bug Reports 73 | ----------- 74 | 75 | Bugs can be reported using the GitHub issue tracker on the libmowgli-2 76 | project page: https://github.com/atheme/libmowgli-2/issues 77 | 78 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | TOP_DIR=$(dirname $0) 4 | LAST_DIR=$PWD 5 | 6 | if test ! -f $TOP_DIR/configure.ac ; then 7 | echo "You must execute this script from the top level directory." 8 | exit 1 9 | fi 10 | 11 | AUTOCONF=${AUTOCONF:-autoconf} 12 | ACLOCAL=${ACLOCAL:-aclocal} 13 | AUTOHEADER=${AUTOHEADER:-autoheader} 14 | 15 | dump_help_screen () 16 | { 17 | echo "Usage: gen-auto-scripts.sh [options]" 18 | echo 19 | echo "options:" 20 | echo " -n skip CVS changelog creation" 21 | echo " -h,--help show this help screen" 22 | echo 23 | exit 0 24 | } 25 | 26 | parse_options () 27 | { 28 | while test "$1" != "" ; do 29 | case $1 in 30 | -h|--help) 31 | dump_help_screen 32 | ;; 33 | -n) 34 | SKIP_CVS_CHANGELOG=yes 35 | ;; 36 | *) 37 | echo Invalid argument - $1 38 | dump_help_screen 39 | ;; 40 | esac 41 | shift 42 | done 43 | } 44 | 45 | run_or_die () 46 | { 47 | COMMAND=$1 48 | 49 | # check for empty commands 50 | if test -z "$COMMAND" ; then 51 | echo "*warning* no command specified" 52 | return 1 53 | fi 54 | 55 | shift; 56 | 57 | OPTIONS="$@" 58 | 59 | # print a message 60 | printf "%s" "*info* running $COMMAND" 61 | if test -n "$OPTIONS" ; then 62 | echo " ($OPTIONS)" 63 | else 64 | echo 65 | fi 66 | 67 | # run or die 68 | $COMMAND $OPTIONS ; RESULT=$? 69 | if test $RESULT -ne 0 ; then 70 | echo "*error* $COMMAND failed. (exit code = $RESULT)" 71 | exit 1 72 | fi 73 | 74 | return 0 75 | } 76 | 77 | parse_options "$@" 78 | 79 | cd $TOP_DIR 80 | 81 | run_or_die $ACLOCAL 82 | run_or_die $AUTOHEADER 83 | run_or_die $AUTOCONF 84 | 85 | cd $LAST_DIR 86 | 87 | -------------------------------------------------------------------------------- /doc/BOOST: -------------------------------------------------------------------------------- 1 | This is a list of alphabetical libraries provided by Boost and their 2 | equivalent in libmowgli: 3 | 4 | dynamic_bitset -> mowgli_bitvector 5 | pool -> mowgli_memorypool 6 | smart_ptr -> mowgli_object 7 | asio -> mowgli_eventloop, mowgli_vio 8 | 9 | Many boost libraries that are applicable to C have not yet been 10 | implemented. You can visit http://www.boost.org/libs/libraries.htm 11 | for a full list of libs. 12 | 13 | -------------------------------------------------------------------------------- /extra.mk.in: -------------------------------------------------------------------------------- 1 | LIBMOWGLI_SHARED_LIB = @LIBMOWGLI_SHARED_LIB@ 2 | LIBMOWGLI_STATIC_LIB = @LIBMOWGLI_STATIC_LIB@ 3 | LIBMOWGLI_MODULES = @LIBMOWGLI_MODULES@ 4 | LIBMOWGLI_SHARED_MODULES = @LIBMOWGLI_SHARED_MODULES@ 5 | LIBMOWGLI_STATIC_MODULES = @LIBMOWGLI_STATIC_MODULES@ 6 | LIBMOWGLI_OS = @LIBMOWGLI_OS@ 7 | 8 | EXAMPLES_BUILD = @EXAMPLES_BUILD@ 9 | 10 | LIBMOWGLI_MODULE_BUILD = @LIBMOWGLI_MODULE_BUILD@ 11 | -------------------------------------------------------------------------------- /libmowgli-2.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | datarootdir=@datarootdir@ 4 | data_dir=@datadir@/@PACKAGE_NAME@ 5 | 6 | version=@PACKAGE_VERSION@ 7 | include_dir=@includedir@/@PACKAGE_NAME@ 8 | lib_dir=@libdir@ 9 | 10 | Name: libmowgli-2 11 | Description: A library which contains many utility functions and classes. 12 | Version: @PACKAGE_VERSION@ 13 | Libs: -L${lib_dir} -lmowgli-2 14 | Cflags: -I${include_dir} 15 | 16 | -------------------------------------------------------------------------------- /m4/pkg.m4: -------------------------------------------------------------------------------- 1 | 2 | dnl PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not) 3 | dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page 4 | dnl also defines GSTUFF_PKG_ERRORS on error 5 | AC_DEFUN([PKG_CHECK_MODULES], [ 6 | succeeded=no 7 | 8 | if test -z "$PKG_CONFIG"; then 9 | AC_PATH_PROG(PKG_CONFIG, pkg-config, no) 10 | fi 11 | 12 | if test "$PKG_CONFIG" = "no" ; then 13 | echo "*** The pkg-config script could not be found. Make sure it is" 14 | echo "*** in your path, or set the PKG_CONFIG environment variable" 15 | echo "*** to the full path to pkg-config." 16 | echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config." 17 | else 18 | PKG_CONFIG_MIN_VERSION=0.9.0 19 | if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then 20 | AC_MSG_CHECKING(for $2) 21 | 22 | if $PKG_CONFIG --exists "$2" ; then 23 | AC_MSG_RESULT(yes) 24 | succeeded=yes 25 | 26 | AC_MSG_CHECKING($1_CFLAGS) 27 | $1_CFLAGS=`$PKG_CONFIG --cflags "$2"` 28 | AC_MSG_RESULT($$1_CFLAGS) 29 | 30 | AC_MSG_CHECKING($1_LIBS) 31 | $1_LIBS=`$PKG_CONFIG --libs "$2"` 32 | AC_MSG_RESULT($$1_LIBS) 33 | else 34 | AC_MSG_RESULT(no) 35 | $1_CFLAGS="" 36 | $1_LIBS="" 37 | ## If we have a custom action on failure, don't print errors, but 38 | ## do set a variable so people can do so. 39 | $1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"` 40 | ifelse([$4], ,echo $$1_PKG_ERRORS,) 41 | fi 42 | 43 | AC_SUBST($1_CFLAGS) 44 | AC_SUBST($1_LIBS) 45 | else 46 | echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer." 47 | echo "*** See http://www.freedesktop.org/software/pkgconfig" 48 | fi 49 | fi 50 | 51 | if test $succeeded = yes; then 52 | ifelse([$3], , :, [$3]) 53 | else 54 | ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4]) 55 | fi 56 | ]) 57 | 58 | 59 | -------------------------------------------------------------------------------- /scripts/makerelease.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # mkrelease.sh: Creates a release suitable for distfiles.atheme.org. 3 | # 4 | # Copyright (c) 2007-2012 atheme.org 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for 7 | # any purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 11 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 12 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 13 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 14 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 15 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 16 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 17 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 18 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 19 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | # 21 | 22 | if [ "x$1" = "x" ]; then 23 | echo "usage: $0 releasename [--automatic]" 24 | exit 25 | else 26 | RELEASENAME="$1" 27 | fi 28 | 29 | if [ "x$2" = "x--automatic" ]; then 30 | AUTOMATIC="yes" 31 | fi 32 | 33 | TIP=`git log -1 --pretty=oneline | cut -d" " -f1` 34 | GITDIR=`git rev-parse --show-toplevel` 35 | 36 | WRKDIR=`pwd` 37 | 38 | if [ -d $RELEASENAME ]; then 39 | echo "Deleting previous release named $RELEASENAME." 40 | rm -rf $WRKDIR/$RELEASENAME/ 41 | fi 42 | 43 | echo "Making release named $RELEASENAME (tip $TIP)" 44 | 45 | echo 46 | echo "Building root: $RELEASENAME/" 47 | cd $GITDIR || exit 1 48 | git archive --format=tar --prefix=$RELEASENAME/ HEAD | gzip >$WRKDIR/$RELEASENAME-working.tar.gz || exit 1 49 | cd $WRKDIR || exit 1 50 | tar -xzvf $RELEASENAME-working.tar.gz || exit 1 51 | cd $RELEASENAME || exit 1 52 | rm -rf .gitignore 53 | sh autogen.sh 54 | rm -rf autogen.sh autom4te.cache 55 | 56 | # Run application specific instructions here. 57 | if [ -x "$WRKDIR/application.sh" ]; then 58 | source $WRKDIR/application.sh 59 | fi 60 | 61 | cd .. 62 | 63 | echo "Building $RELEASENAME.tar.gz from $RELEASENAME/" 64 | tar zcf $RELEASENAME.tar.gz $RELEASENAME/ 65 | 66 | echo "Building $RELEASENAME.tar.bz2 from $RELEASENAME/" 67 | tar jcf $RELEASENAME.tar.bz2 $RELEASENAME/ 68 | 69 | rm $RELEASENAME-working.tar.gz 70 | 71 | PUBLISH="yes" 72 | 73 | ok="0" 74 | if [ "x$AUTOMATIC" != "xyes" ]; then 75 | echo 76 | echo "Would you like to publish these releases now?" 77 | while [ $ok -eq 0 ]; do 78 | echo -n "[$PUBLISH] " 79 | 80 | read INPUT 81 | case $INPUT in 82 | [Yy]*) 83 | PUBLISH="yes" 84 | ok=1 85 | ;; 86 | [Nn]*) 87 | PUBLISH="no" 88 | ok=1 89 | ;; 90 | esac 91 | done 92 | fi 93 | 94 | if [ "x$PUBLISH" = "xyes" ]; then 95 | scp $RELEASENAME.tgz distfiles-master.atheme.org:/srv/distfiles 96 | scp $RELEASENAME.tbz2 distfiles-master.atheme.org:/srv/distfiles 97 | 98 | echo 99 | echo "The releases have been published, and will be available to the entire" 100 | echo "distribution network within 15 minutes." 101 | fi 102 | 103 | echo 104 | echo "Done. If you have any bugs to report, report them against" 105 | echo "the distfiles.atheme.org component at http://jira.atheme.org" 106 | echo "Thanks!" 107 | echo 108 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS = libmowgli ${EXAMPLES_BUILD} 2 | 3 | include ../buildsys.mk 4 | include ../extra.mk 5 | -------------------------------------------------------------------------------- /src/examples/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS = echoserver vio-udplistener async_resolver formattertest helpertest jsontest libevent-bench linetest listsort memslice-bench patriciatest patriciatest2 randomtest timertest 2 | include ../../buildsys.mk 3 | -------------------------------------------------------------------------------- /src/examples/async_resolver/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = async_resolver${PROG_SUFFIX} 2 | SRCS = async_resolver.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/echoserver/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = echoserver${PROG_SUFFIX} 2 | SRCS = echoserver.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/formattertest/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = formattertest${PROG_SUFFIX} 2 | SRCS = formattertest.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/formattertest/formattertest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * formattertest.c: Testsuite for mowgli.formatter. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. The name of the author may not be used to endorse or promote products 19 | * derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | 36 | int 37 | main(int argc, char *argv[]) 38 | { 39 | char buf[65535]; 40 | 41 | mowgli_formatter_format(buf, 65535, "%1! %2 %3 %4.", "sdpb", "Hello World", 1, 0xDEADBEEF, TRUE); 42 | 43 | puts(buf); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /src/examples/helpertest/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = helpertest${PROG_SUFFIX} 2 | SRCS = helpertest.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/helpertest/helpertest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * echoserver.c: Testing of the I/O system 4 | * 5 | * Copyright (c) 2012 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include 25 | 26 | int helper_count = 0; 27 | 28 | void 29 | timer_oneshot(mowgli_eventloop_helper_proc_t *helper) 30 | { 31 | mowgli_writef(helper->fd, "oneshot timer hit\n"); 32 | } 33 | 34 | void 35 | timer_tick(mowgli_eventloop_helper_proc_t *helper) 36 | { 37 | static int ticks = 0; 38 | 39 | mowgli_writef(helper->fd, "tick: %d\n", ++ticks); 40 | 41 | if (ticks > 10) 42 | mowgli_eventloop_break(helper->eventloop); 43 | } 44 | 45 | void 46 | helper_start(mowgli_eventloop_helper_proc_t *helper, void *userdata) 47 | { 48 | mowgli_eventloop_t *eventloop = helper->eventloop; 49 | 50 | mowgli_writef(helper->fd, "hi from pid %d\n", getpid()); 51 | 52 | mowgli_timer_add(eventloop, "timer_tick", (mowgli_event_dispatch_func_t *) timer_tick, helper, 1); 53 | mowgli_timer_add_once(eventloop, "timer_oneshot", (mowgli_event_dispatch_func_t *) timer_oneshot, helper, 5); 54 | 55 | mowgli_eventloop_run(eventloop); 56 | 57 | mowgli_writef(helper->fd, "eventloop halted\n"); 58 | 59 | mowgli_eventloop_destroy(eventloop); 60 | } 61 | 62 | void helper_read(mowgli_eventloop_t *eventloop, mowgli_eventloop_io_t *io, mowgli_eventloop_io_dir_t dir, void *userdata); 63 | 64 | void 65 | helper_spawn(mowgli_eventloop_t *eventloop) 66 | { 67 | mowgli_eventloop_helper_proc_t *helper; 68 | 69 | if (helper_count >= 100) 70 | return; 71 | 72 | helper = mowgli_helper_create(eventloop, helper_start, "Spawned helper", NULL); 73 | mowgli_helper_set_read_cb(eventloop, helper, helper_read); 74 | 75 | helper_count++; 76 | } 77 | 78 | void 79 | helper_read(mowgli_eventloop_t *eventloop, mowgli_eventloop_io_t *io, mowgli_eventloop_io_dir_t dir, void *userdata) 80 | { 81 | size_t r; 82 | char buf[16384]; 83 | mowgli_eventloop_helper_proc_t *helper = mowgli_eventloop_io_helper(io); 84 | 85 | bzero(buf, sizeof buf); 86 | r = read(helper->fd, buf, sizeof buf); 87 | 88 | if (r > 0) 89 | { 90 | printf("helper %p [%d/%d]: %s", helper, helper->child->pid, helper->fd, buf); 91 | } 92 | else if (r <= 0) 93 | { 94 | helper_count--; 95 | mowgli_helper_destroy(eventloop, helper); 96 | } 97 | 98 | if ((rand() % helper_count) == 0) 99 | helper_spawn(eventloop); 100 | } 101 | 102 | int 103 | main(int argc, char *argv[]) 104 | { 105 | mowgli_eventloop_t *base_eventloop; 106 | 107 | /* Bleh this is needed to ensure some systems can set the process title */ 108 | argv = mowgli_proctitle_init(argc, argv); 109 | 110 | base_eventloop = mowgli_eventloop_create(); 111 | 112 | helper_spawn(base_eventloop); 113 | 114 | mowgli_eventloop_run(base_eventloop); 115 | 116 | return EXIT_SUCCESS; 117 | } 118 | -------------------------------------------------------------------------------- /src/examples/jsontest/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = jsontest${PROG_SUFFIX} 2 | SRCS = jsontest.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/jsontest/jsontest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | out_string(mowgli_json_output_t *out, const char *str, size_t len) 5 | { 6 | fwrite(str, 1, len, stdout); 7 | } 8 | 9 | void 10 | out_char(mowgli_json_output_t *out, const char c) 11 | { 12 | fputc(c, stdout); 13 | } 14 | 15 | mowgli_json_output_t out = 16 | { 17 | .append = out_string, 18 | .append_char = out_char, 19 | }; 20 | 21 | int 22 | main(int argc, char *argv[]) 23 | { 24 | int i; 25 | mowgli_json_t *n; 26 | 27 | if (argc < 2) 28 | { 29 | printf("Usage: %s file [file ...]\n", argv[0]); 30 | return 1; 31 | } 32 | 33 | for (i = 1; i < argc; i++) 34 | { 35 | n = mowgli_json_parse_file(argv[i]); 36 | 37 | if (n != NULL) 38 | { 39 | mowgli_json_serialize(n, &out, 1); 40 | putchar('\n'); 41 | } 42 | 43 | mowgli_json_decref(n); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/examples/libevent-bench/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = bench${PROG_SUFFIX} 2 | SRCS = bench.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/linetest/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = linetest${PROG_SUFFIX} 2 | SRCS = linetest.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/listsort/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = listsort${PROG_SUFFIX} 2 | SRCS = listsort.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/memslice-bench/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = memslice-bench${PROG_SUFFIX} 2 | SRCS = memslice-bench.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/patriciatest/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = patriciatest${PROG_SUFFIX} 2 | SRCS = patriciatest.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/patriciatest2/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = patriciatest2${PROG_SUFFIX} 2 | SRCS = patriciatest2.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/randomtest/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = randomtest${PROG_SUFFIX} 2 | SRCS = randomtest.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/randomtest/randomtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * randomtest.c: Testsuite for the random number generator. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * Algorithm copyright (c) 1999-2007 Takuji Nishimura and Makoto Matsumoto 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are 10 | * met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | #include 35 | 36 | int 37 | main(int argc, char *argv[]) 38 | { 39 | mowgli_random_t *r = mowgli_random_create(); 40 | int i; 41 | 42 | printf("1000 iterations:\n"); 43 | 44 | for (i = 0; i < 1000; i++) 45 | { 46 | printf("%10u ", mowgli_random_int(r)); 47 | 48 | if (i % 5 == 4) 49 | printf("\n"); 50 | } 51 | 52 | mowgli_object_unref(r); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /src/examples/timertest/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = timertest${PROG_SUFFIX} 2 | SRCS = timertest.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/timertest/timertest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * echoserver.c: Testing of the I/O system 4 | * 5 | * Copyright (c) 2011 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include 25 | 26 | mowgli_eventloop_t *eventloop; 27 | 28 | void 29 | timer_oneshot(void *unused) 30 | { 31 | printf("oneshot timer hit\n"); 32 | } 33 | 34 | void 35 | timer_tick(void *unused) 36 | { 37 | static int ticks = 0; 38 | 39 | printf("tick: %d\n", ++ticks); 40 | 41 | if (ticks > 20) 42 | mowgli_eventloop_break(eventloop); 43 | } 44 | 45 | int 46 | main(int argc, char *argv[]) 47 | { 48 | eventloop = mowgli_eventloop_create(); 49 | 50 | mowgli_timer_add(eventloop, "timer_tick", timer_tick, NULL, 1); 51 | mowgli_timer_add_once(eventloop, "timer_oneshot", timer_oneshot, NULL, 5); 52 | 53 | mowgli_eventloop_run(eventloop); 54 | 55 | printf("eventloop halted\n"); 56 | 57 | mowgli_eventloop_destroy(eventloop); 58 | 59 | return EXIT_SUCCESS; 60 | } 61 | -------------------------------------------------------------------------------- /src/examples/vio-udplistener/Makefile: -------------------------------------------------------------------------------- 1 | PROG_NOINST = vio-udplistener${PROG_SUFFIX} 2 | SRCS = vio-udplistener.c 3 | 4 | include ../../../buildsys.mk 5 | 6 | CPPFLAGS += -I../../libmowgli 7 | LIBS += -L../../libmowgli -lmowgli-2 8 | -------------------------------------------------------------------------------- /src/examples/vio-udplistener/vio-udplistener.c: -------------------------------------------------------------------------------- 1 | /* vio-udplistener.c - An example of the VIO API 2 | * To use: nc -u localhost, and then type stuff and hit enter. :p 3 | * This example is public domain. 4 | */ 5 | 6 | #include 7 | 8 | #define BUFSIZE 2048 9 | 10 | #define PROTO AF_INET6 11 | #define LISTEN "::ffff:127.0.0.1" /* 6to4 mapping */ 12 | #define PORT 31337 13 | 14 | #define ECHOBACK "Echo: " 15 | 16 | int 17 | main(void) 18 | { 19 | mowgli_vio_t *vio = mowgli_vio_create(NULL); 20 | mowgli_vio_sockaddr_t addr; 21 | 22 | mowgli_vio_sockaddr_create(&addr, PROTO, LISTEN, PORT); 23 | 24 | if (mowgli_vio_socket(vio, PROTO, SOCK_DGRAM, 0)) 25 | return EXIT_FAILURE; 26 | 27 | if (mowgli_vio_bind(vio, &addr)) 28 | return EXIT_FAILURE; 29 | 30 | while (true) 31 | { 32 | char buf[BUFSIZE] = ""; 33 | mowgli_vio_sockdata_t sockinfo; 34 | 35 | mowgli_vio_recvfrom(vio, buf, sizeof(buf), &addr); 36 | 37 | mowgli_vio_sockaddr_info(&addr, &sockinfo); 38 | 39 | printf("Recieved bytes from addr [%s]:%hu: %s", sockinfo.host, sockinfo.port, buf); 40 | 41 | mowgli_vio_sendto(vio, ECHOBACK, sizeof(ECHOBACK), &addr); 42 | mowgli_vio_sendto(vio, buf, strlen(buf), &addr); 43 | } 44 | 45 | return EXIT_SUCCESS; /* Not reached */ 46 | } 47 | -------------------------------------------------------------------------------- /src/libmowgli/Makefile: -------------------------------------------------------------------------------- 1 | include ../../extra.mk 2 | 3 | LIB_MAJOR = 0 4 | LIB_MINOR = 0 5 | 6 | SHARED_LIB = ${LIBMOWGLI_SHARED_LIB} 7 | STATIC_LIB = ${LIBMOWGLI_STATIC_LIB} 8 | 9 | SUBDIRS = ${LIBMOWGLI_MODULES} 10 | 11 | INCLUDES = mowgli.h 12 | 13 | LIB_OBJS_EXTRA = ${LIB_OBJS} ${LIBMOWGLI_SHARED_MODULES} 14 | OBJS_EXTRA = ${LIBMOWGLI_STATIC_MODULES} 15 | 16 | include ../../buildsys.mk 17 | 18 | $(OBJS_EXTRA) $(LIB_OBJS_EXTRA): subdirs 19 | 20 | LIBS += ${PTHREAD_LIBS} 21 | CPPFLAGS += -I. -I../.. -DMOWGLI_CORE 22 | -------------------------------------------------------------------------------- /src/libmowgli/base/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_BASE} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_BASE} 5 | 6 | SRCS = argstack.c \ 7 | bitvector.c \ 8 | formatter.c \ 9 | hash.c \ 10 | hook.c \ 11 | memslice.c \ 12 | random.c \ 13 | mowgli_signal.c 14 | 15 | INCLUDES = argstack.h \ 16 | bitvector.h \ 17 | formatter.h \ 18 | hash.h \ 19 | hook.h \ 20 | memslice.h \ 21 | random.h \ 22 | mowgli_signal.h 23 | 24 | include ../../../buildsys.mk 25 | 26 | includesubdir = $(PACKAGE_NAME)/base 27 | 28 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 29 | 30 | -------------------------------------------------------------------------------- /src/libmowgli/base/argstack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * argstack.h: Argument stacks. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_ARGSTACK_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_BASE_ARGSTACK_H_INCLUDE_GUARD 1 26 | 27 | #include "container/list.h" 28 | #include "core/stdinc.h" 29 | #include "object/object.h" 30 | 31 | typedef enum 32 | { 33 | MOWGLI_ARG_NUMERIC, 34 | MOWGLI_ARG_POINTER, 35 | MOWGLI_ARG_STRING, 36 | MOWGLI_ARG_BOOLEAN 37 | } mowgli_argstack_element_type_t; 38 | 39 | typedef struct 40 | { 41 | union 42 | { 43 | int numeric; 44 | void *pointer; 45 | char *string; 46 | mowgli_boolean_t boolean; 47 | } data; 48 | 49 | mowgli_argstack_element_type_t type; 50 | } mowgli_argstack_element_t; 51 | 52 | typedef struct 53 | { 54 | mowgli_object_t parent; 55 | mowgli_list_t stack; 56 | } mowgli_argstack_t; 57 | 58 | extern mowgli_argstack_t *mowgli_argstack_create(const char *descstr, ...); 59 | extern mowgli_argstack_t *mowgli_argstack_create_from_va_list(const char *descstr, va_list va); 60 | extern const char *mowgli_argstack_pop_string(mowgli_argstack_t *); 61 | extern int mowgli_argstack_pop_numeric(mowgli_argstack_t *); 62 | extern mowgli_boolean_t mowgli_argstack_pop_boolean(mowgli_argstack_t *); 63 | extern void *mowgli_argstack_pop_pointer(mowgli_argstack_t *); 64 | 65 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_ARGSTACK_H_INCLUDE_GUARD */ 66 | -------------------------------------------------------------------------------- /src/libmowgli/base/bitvector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * bitvector.h: Bitvectors. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_BITVECTOR_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_BASE_BITVECTOR_H_INCLUDE_GUARD 1 26 | 27 | #include "core/stdinc.h" 28 | 29 | typedef struct 30 | { 31 | unsigned int bits; 32 | unsigned int divisor; 33 | unsigned int *vector; 34 | } mowgli_bitvector_t; 35 | 36 | extern mowgli_bitvector_t *mowgli_bitvector_create(int bits); 37 | extern void mowgli_bitvector_set(mowgli_bitvector_t *bv, int slot, mowgli_boolean_t val); 38 | extern mowgli_boolean_t mowgli_bitvector_get(mowgli_bitvector_t *bv, int slot); 39 | extern mowgli_bitvector_t *mowgli_bitvector_combine(mowgli_bitvector_t *bv1, mowgli_bitvector_t *bv2); 40 | extern mowgli_bitvector_t *mowgli_bitvector_xor(mowgli_bitvector_t *bv1, mowgli_bitvector_t *bv2); 41 | extern mowgli_boolean_t mowgli_bitvector_compare(mowgli_bitvector_t *bv1, mowgli_bitvector_t *bv2); 42 | 43 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_BITVECTOR_H_INCLUDE_GUARD */ 44 | -------------------------------------------------------------------------------- /src/libmowgli/base/formatter.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * formatter.c: Reusable formatting. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | void 27 | mowgli_formatter_format_from_argstack(char *buf, size_t bufstr, const char *fmtstr, const char *descstr, mowgli_argstack_t *stack) 28 | { 29 | size_t pos = 0; 30 | char *i = buf; 31 | const char *fiter = fmtstr; 32 | 33 | return_if_fail(buf != NULL); 34 | return_if_fail(fmtstr != NULL); 35 | return_if_fail(descstr != NULL); 36 | 37 | *i = '\0'; 38 | 39 | while (*fiter && pos <= bufstr) 40 | { 41 | int arg; 42 | mowgli_argstack_element_t *e; 43 | 44 | pos = strlen(buf); 45 | 46 | switch (*fiter) 47 | { 48 | case '%': 49 | fiter++; 50 | arg = atoi(fiter); 51 | e = mowgli_node_nth_data(&stack->stack, arg - 1); 52 | 53 | while (isdigit((unsigned char)*fiter)) 54 | { 55 | fiter++; 56 | } 57 | 58 | if (e == NULL) 59 | { 60 | arg = snprintf(i, bufstr - (i - buf), "(unknown)"); 61 | i += arg; 62 | continue; 63 | } 64 | 65 | switch (e->type) 66 | { 67 | case MOWGLI_ARG_STRING: 68 | arg = snprintf(i, bufstr - (i - buf), "%s", e->data.string); 69 | i += arg; 70 | break; 71 | case MOWGLI_ARG_NUMERIC: 72 | arg = snprintf(i, bufstr - (i - buf), "%d", e->data.numeric); 73 | i += arg; 74 | break; 75 | case MOWGLI_ARG_POINTER: 76 | arg = snprintf(i, bufstr - (i - buf), "%p", e->data.pointer); 77 | i += arg; 78 | break; 79 | case MOWGLI_ARG_BOOLEAN: 80 | arg = snprintf(i, bufstr - (i - buf), "%s", e->data.boolean ? "TRUE" : "FALSE"); 81 | i += arg; 82 | break; 83 | default: 84 | mowgli_log("unhandled type"); 85 | break; 86 | } 87 | 88 | continue; 89 | 90 | default: 91 | *i = *fiter; 92 | } 93 | 94 | i++; 95 | fiter++; 96 | } 97 | } 98 | 99 | void 100 | mowgli_formatter_format(char *buf, size_t bufstr, const char *fmtstr, const char *descstr, ...) 101 | { 102 | va_list va; 103 | mowgli_argstack_t *stack; 104 | 105 | va_start(va, descstr); 106 | stack = mowgli_argstack_create_from_va_list(descstr, va); 107 | va_end(va); 108 | 109 | mowgli_formatter_format_from_argstack(buf, bufstr, fmtstr, descstr, stack); 110 | } 111 | 112 | void 113 | mowgli_formatter_print(const char *fmtstr, const char *descstr, ...) 114 | { 115 | va_list va; 116 | char buf[65535]; 117 | mowgli_argstack_t *stack; 118 | 119 | va_start(va, descstr); 120 | stack = mowgli_argstack_create_from_va_list(descstr, va); 121 | va_end(va); 122 | 123 | mowgli_formatter_format_from_argstack(buf, 65535, fmtstr, descstr, stack); 124 | printf("%s", buf); 125 | } 126 | -------------------------------------------------------------------------------- /src/libmowgli/base/formatter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * formatter.h: Reusable formatting. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_FORMATTER_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_BASE_FORMATTER_H_INCLUDE_GUARD 1 26 | 27 | #include "base/argstack.h" 28 | #include "core/stdinc.h" 29 | 30 | extern void mowgli_formatter_format(char *buf, size_t bufstr, const char *fmtstr, const char *descstr, ...); 31 | extern void mowgli_formatter_print(const char *fmtstr, const char *descstr, ...); 32 | extern void mowgli_formatter_format_from_argstack(char *buf, size_t bufstr, const char *fmtstr, const char *descstr, mowgli_argstack_t *stack); 33 | 34 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_FORMATTER_H_INCLUDE_GUARD */ 35 | -------------------------------------------------------------------------------- /src/libmowgli/base/hash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * hash.c: FNV-1 hashing implementation. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | #define HASHINIT 0x811c9dc5 27 | #define HASHBITS 16 28 | #define HASHSIZE (1 << HASHBITS)/* 2^16 = 65536 */ 29 | 30 | int 31 | mowgli_fnv_hash_string(const char *p) 32 | { 33 | static int htoast = 0; 34 | unsigned int hval = HASHINIT; 35 | 36 | if (htoast == 0) 37 | { 38 | mowgli_random_t *r = mowgli_random_create(); 39 | htoast = mowgli_random_int(r); 40 | mowgli_object_unref(r); 41 | } 42 | 43 | if (!p) 44 | return 0; 45 | 46 | for (; *p != '\0'; ++p) 47 | { 48 | hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); 49 | hval ^= (tolower((unsigned char)*p) ^ htoast); 50 | } 51 | 52 | return (hval >> HASHBITS) ^ (hval & ((1 << HASHBITS) - 1)) % HASHSIZE; 53 | } 54 | 55 | int 56 | mowgli_fnv_hash(unsigned int *p) 57 | { 58 | static int htoast = 0; 59 | unsigned int hval = HASHINIT; 60 | 61 | if (htoast == 0) 62 | { 63 | mowgli_random_t *r = mowgli_random_create(); 64 | htoast = mowgli_random_int(r); 65 | mowgli_object_unref(r); 66 | } 67 | 68 | if (!p) 69 | return 0; 70 | 71 | for (; *p != '\0'; ++p) 72 | { 73 | hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); 74 | hval ^= (tolower((unsigned char)*p) ^ htoast); 75 | } 76 | 77 | return (hval >> HASHBITS) ^ (hval & ((1 << HASHBITS) - 1)) % HASHSIZE; 78 | } 79 | -------------------------------------------------------------------------------- /src/libmowgli/base/hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * hash.h: FNV-1 hashing implementation. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_HASH_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_BASE_HASH_H_INCLUDE_GUARD 1 26 | 27 | extern int mowgli_fnv_hash_string(const char *data); 28 | extern int mowgli_fnv_hash(unsigned int *data); 29 | 30 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_HASH_H_INCLUDE_GUARD */ 31 | -------------------------------------------------------------------------------- /src/libmowgli/base/hook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * hook.h: Hooks. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * Copyright (c) 2007 Giacomo Lozito 7 | * 8 | * Permission to use, copy, modify, and/or distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice is present in all copies. 11 | * 12 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 13 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 16 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 20 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_HOOK_H_INCLUDE_GUARD 26 | #define MOWGLI_SRC_LIBMOWGLI_BASE_HOOK_H_INCLUDE_GUARD 1 27 | 28 | #include "container/list.h" 29 | 30 | typedef void (*mowgli_hook_function_t)(void *hook_data, void *user_data); 31 | 32 | typedef struct 33 | { 34 | mowgli_hook_function_t func; 35 | void *user_data; 36 | mowgli_node_t node; 37 | } mowgli_hook_item_t; 38 | 39 | typedef struct 40 | { 41 | const char *name; 42 | mowgli_list_t items; 43 | } mowgli_hook_t; 44 | 45 | extern void mowgli_hook_register(const char *name); 46 | extern int mowgli_hook_associate(const char *name, mowgli_hook_function_t func, void *user_data); 47 | extern int mowgli_hook_dissociate(const char *name, mowgli_hook_function_t func); 48 | extern void mowgli_hook_call(const char *name, void *hook_data); 49 | 50 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_HOOK_H_INCLUDE_GUARD */ 51 | -------------------------------------------------------------------------------- /src/libmowgli/base/memslice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 William Pitcock 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice is present in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_MEMSLICE_H_INCLUDE_GUARD 22 | #define MOWGLI_SRC_LIBMOWGLI_BASE_MEMSLICE_H_INCLUDE_GUARD 1 23 | 24 | #include "core/allocation_policy.h" 25 | 26 | mowgli_allocation_policy_t *mowgli_memslice_get_policy(void); 27 | 28 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_MEMSLICE_H_INCLUDE_GUARD */ 29 | -------------------------------------------------------------------------------- /src/libmowgli/base/mowgli_signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * mowgli_signal.c: Safe signal handling. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef _WIN32 25 | 26 | #include "mowgli.h" 27 | 28 | #if defined(__linux__) && defined(__GNUC__) && defined(__STRICT_ANSI__) 29 | # error GCC/Linux in -std=c99 mode will not compile mowgli_signal; use -std=gnu99 instead 30 | #endif 31 | 32 | static mowgli_signal_handler_t 33 | mowgli_signal_install_handler_full(int signum, mowgli_signal_handler_t handler, int *sigtoblock, size_t sigtoblocksize) 34 | { 35 | struct sigaction action, old_action; 36 | 37 | size_t i; 38 | 39 | action.sa_handler = handler; 40 | action.sa_flags = SA_RESTART; 41 | 42 | sigemptyset(&action.sa_mask); 43 | 44 | for (i = 0; i < sigtoblocksize; i++) 45 | sigaddset(&action.sa_mask, sigtoblock[i]); 46 | 47 | if (sigaction(signum, &action, &old_action) == -1) 48 | { 49 | mowgli_log("Failed to install signal handler for signal %d", signum); 50 | return NULL; 51 | } 52 | 53 | return old_action.sa_handler; 54 | } 55 | 56 | /* 57 | * A version of signal(2) that works more reliably across different 58 | * platforms. 59 | * 60 | * It restarts interrupted system calls, does not reset the handler, 61 | * and blocks the same signal from within the handler. 62 | */ 63 | mowgli_signal_handler_t 64 | mowgli_signal_install_handler(int signum, mowgli_signal_handler_t handler) 65 | { 66 | return mowgli_signal_install_handler_full(signum, handler, NULL, 0); 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/libmowgli/base/mowgli_signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * mowgli_signal.h: Safe signal handling. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_MOWGLI_SIGNAL_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_BASE_MOWGLI_SIGNAL_H_INCLUDE_GUARD 1 26 | 27 | typedef void (*mowgli_signal_handler_t)(int); 28 | 29 | extern mowgli_signal_handler_t mowgli_signal_install_handler(int signum, mowgli_signal_handler_t handler); 30 | 31 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_MOWGLI_SIGNAL_H_INCLUDE_GUARD */ 32 | -------------------------------------------------------------------------------- /src/libmowgli/base/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * random.h: Portable mersinne-twister based psuedo-random number generator. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_BASE_RANDOM_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_BASE_RANDOM_H_INCLUDE_GUARD 1 26 | 27 | /* mowgli_random_t contains state data which is private */ 28 | struct mowgli_random_; 29 | 30 | typedef struct mowgli_random_ mowgli_random_t; 31 | 32 | /* construction and destruction. */ 33 | extern mowgli_random_t *mowgli_random_create(void); 34 | extern mowgli_random_t *mowgli_random_create_with_seed(unsigned int seed); 35 | 36 | /* reset seed */ 37 | extern void mowgli_random_reseed(mowgli_random_t *self, unsigned int seed); 38 | 39 | /* number retrieval */ 40 | extern unsigned int mowgli_random_int(mowgli_random_t *self); 41 | extern int mowgli_random_int_ranged(mowgli_random_t *self, int begin, int end); 42 | 43 | #endif /* MOWGLI_SRC_LIBMOWGLI_BASE_RANDOM_H_INCLUDE_GUARD */ 44 | -------------------------------------------------------------------------------- /src/libmowgli/container/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_CONTAINER} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_CONTAINER} 5 | 6 | SRCS = dictionary.c \ 7 | list.c \ 8 | queue.c \ 9 | index.c \ 10 | patricia.c 11 | 12 | INCLUDES = dictionary.h \ 13 | list.h \ 14 | queue.h \ 15 | index.h \ 16 | patricia.h 17 | 18 | include ../../../buildsys.mk 19 | 20 | includesubdir = $(PACKAGE_NAME)/container 21 | 22 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 23 | 24 | -------------------------------------------------------------------------------- /src/libmowgli/container/index.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2011 John Lindgren 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice is present in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #ifndef MOWGLI_SRC_LIBMOWGLI_CONTAINER_INDEX_H_INCLUDE_GUARD 22 | #define MOWGLI_SRC_LIBMOWGLI_CONTAINER_INDEX_H_INCLUDE_GUARD 1 23 | 24 | #include "platform/attributes.h" 25 | 26 | struct mowgli_index_; 27 | 28 | typedef struct mowgli_index_ mowgli_index_t; 29 | 30 | mowgli_index_t *mowgli_index_create(void) 31 | MOWGLI_FATTR_MALLOC; 32 | 33 | void mowgli_index_destroy(mowgli_index_t *index); 34 | int mowgli_index_count(mowgli_index_t *index); 35 | void mowgli_index_allocate(mowgli_index_t *index, int size); 36 | void mowgli_index_set(mowgli_index_t *index, int at, void *value); 37 | void *mowgli_index_get(mowgli_index_t *index, int at); 38 | void mowgli_index_insert(mowgli_index_t *index, int at, void *value); 39 | void mowgli_index_append(mowgli_index_t *index, void *value); 40 | void mowgli_index_copy_set(mowgli_index_t *source, int from, mowgli_index_t *target, int to, int count); 41 | void mowgli_index_copy_insert(mowgli_index_t *source, int from, mowgli_index_t *target, int to, int count); 42 | void mowgli_index_copy_append(mowgli_index_t *source, int from, mowgli_index_t *target, int count); 43 | void mowgli_index_merge_insert(mowgli_index_t *first, int at, mowgli_index_t *second); 44 | void mowgli_index_merge_append(mowgli_index_t *first, mowgli_index_t *second); 45 | void mowgli_index_move(mowgli_index_t *index, int from, int to, int count); 46 | void mowgli_index_delete(mowgli_index_t *index, int at, int count); 47 | void mowgli_index_sort(mowgli_index_t *index, int (*compare)(const void *a, const void *b)); 48 | void mowgli_index_sort_with_data(mowgli_index_t *index, int(*compare) 49 | (const void *a, const void *b, void *data), void *data); 50 | 51 | #endif /* MOWGLI_SRC_LIBMOWGLI_CONTAINER_INDEX_H_INCLUDE_GUARD */ 52 | -------------------------------------------------------------------------------- /src/libmowgli/container/queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * queue.h: Double-ended queues, also known as deque. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CONTAINER_QUEUE_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CONTAINER_QUEUE_H_INCLUDE_GUARD 1 26 | 27 | #include "core/iterator.h" 28 | 29 | typedef mowgli_iterator_t mowgli_queue_t; 30 | 31 | extern mowgli_queue_t *mowgli_queue_push(mowgli_queue_t *head, void *data); 32 | extern mowgli_queue_t *mowgli_queue_shift(mowgli_queue_t *head, void *data); 33 | extern mowgli_queue_t *mowgli_queue_remove(mowgli_queue_t *head); 34 | extern mowgli_queue_t *mowgli_queue_find(mowgli_queue_t *head, void *data); 35 | extern mowgli_queue_t *mowgli_queue_remove_data(mowgli_queue_t *head, void *data); 36 | extern void mowgli_queue_destroy(mowgli_queue_t *head); 37 | extern mowgli_queue_t *mowgli_queue_skip(mowgli_queue_t *head, int amt); 38 | extern mowgli_queue_t *mowgli_queue_rewind(mowgli_queue_t *head, int amt); 39 | extern mowgli_queue_t *mowgli_queue_head(mowgli_queue_t *n); 40 | extern mowgli_queue_t *mowgli_queue_tail(mowgli_queue_t *n); 41 | extern void *mowgli_queue_pop_head(mowgli_queue_t **n); 42 | extern void *mowgli_queue_pop_tail(mowgli_queue_t **n); 43 | extern int mowgli_queue_length(mowgli_queue_t *head); 44 | 45 | #endif /* MOWGLI_SRC_LIBMOWGLI_CONTAINER_QUEUE_H_INCLUDE_GUARD */ 46 | -------------------------------------------------------------------------------- /src/libmowgli/core/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_CORE} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_CORE} 5 | 6 | SRCS = bootstrap.c \ 7 | alloc.c \ 8 | allocation_policy.c \ 9 | allocator.c \ 10 | heap.c \ 11 | logger.c \ 12 | mowgli_string.c \ 13 | process.c 14 | 15 | INCLUDES = bootstrap.h \ 16 | alloc.h \ 17 | allocation_policy.h \ 18 | allocator.h \ 19 | assert.h \ 20 | heap.h \ 21 | iterator.h \ 22 | logger.h \ 23 | mowgli_string.h \ 24 | stdinc.h \ 25 | process.h 26 | 27 | include ../../../buildsys.mk 28 | 29 | includesubdir = $(PACKAGE_NAME)/core 30 | 31 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 32 | 33 | -------------------------------------------------------------------------------- /src/libmowgli/core/alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * alloc.h: Safe, portable implementations of malloc, calloc, and free. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_ALLOC_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_ALLOC_H_INCLUDE_GUARD 1 26 | 27 | #include "core/allocation_policy.h" 28 | #include "core/stdinc.h" 29 | #include "platform/attributes.h" 30 | 31 | extern void *mowgli_alloc_array_using_policy(mowgli_allocation_policy_t *policy, size_t size, size_t count) 32 | MOWGLI_FATTR_MALLOC MOWGLI_FATTR_ALLOC_SIZE_PRODUCT(2, 3); 33 | extern void *mowgli_alloc_using_policy(mowgli_allocation_policy_t *policy, size_t size) 34 | MOWGLI_FATTR_MALLOC MOWGLI_FATTR_ALLOC_SIZE(2); 35 | extern char *mowgli_strdup_using_policy(mowgli_allocation_policy_t *policy, const char *in) 36 | MOWGLI_FATTR_MALLOC; 37 | extern char *mowgli_strndup_using_policy(mowgli_allocation_policy_t *policy, const char *in, size_t size) 38 | MOWGLI_FATTR_MALLOC; 39 | 40 | extern void *mowgli_alloc_array(size_t size, size_t count) 41 | MOWGLI_FATTR_MALLOC MOWGLI_FATTR_ALLOC_SIZE_PRODUCT(1, 2); 42 | extern void *mowgli_alloc(size_t size) 43 | MOWGLI_FATTR_MALLOC MOWGLI_FATTR_ALLOC_SIZE(1); 44 | extern char *mowgli_strdup(const char *in) 45 | MOWGLI_FATTR_MALLOC; 46 | extern char *mowgli_strndup(const char *in, size_t size) 47 | MOWGLI_FATTR_MALLOC; 48 | 49 | extern void mowgli_free(void *ptr); 50 | 51 | extern mowgli_allocation_policy_t *mowgli_allocator_get_policy(void) MOWGLI_FATTR_RETURNS_NONNULL; 52 | extern void mowgli_allocator_set_policy(mowgli_allocation_policy_t *policy); 53 | extern void mowgli_allocator_set_policy_by_name(const char *name); 54 | 55 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_ALLOC_H_INCLUDE_GUARD */ 56 | -------------------------------------------------------------------------------- /src/libmowgli/core/allocation_policy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * allocation_policy.h: Allocation policy management. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "core/bootstrap_internal.h" 26 | 27 | static mowgli_object_class_t klass; 28 | static mowgli_patricia_t *mowgli_allocation_policy_dict = NULL; 29 | 30 | static void 31 | _allocation_policy_key_canon(char *str) 32 | { } 33 | 34 | void 35 | mowgli_allocation_policy_bootstrap(void) 36 | { 37 | mowgli_allocation_policy_dict = mowgli_patricia_create(_allocation_policy_key_canon); 38 | 39 | mowgli_object_class_init(&klass, "mowgli.allocation_policy", NULL, FALSE); 40 | } 41 | 42 | mowgli_allocation_policy_t * 43 | mowgli_allocation_policy_create(const char *name, mowgli_allocation_func_t allocator, mowgli_deallocation_func_t deallocator) 44 | { 45 | mowgli_allocation_policy_t *policy; 46 | 47 | if (mowgli_allocation_policy_dict == NULL) 48 | mowgli_allocation_policy_dict = mowgli_patricia_create(_allocation_policy_key_canon); 49 | 50 | if ((policy = mowgli_patricia_retrieve(mowgli_allocation_policy_dict, name))) 51 | return policy; 52 | 53 | policy = mowgli_alloc(sizeof *policy); 54 | mowgli_object_init_from_class(mowgli_object(policy), name, &klass); 55 | 56 | policy->allocate = allocator; 57 | policy->deallocate = deallocator; 58 | 59 | mowgli_patricia_add(mowgli_allocation_policy_dict, name, policy); 60 | 61 | return policy; 62 | } 63 | 64 | mowgli_allocation_policy_t * 65 | mowgli_allocation_policy_lookup(const char *name) 66 | { 67 | if (mowgli_allocation_policy_dict == NULL) 68 | mowgli_allocation_policy_dict = mowgli_patricia_create(_allocation_policy_key_canon); 69 | 70 | return mowgli_patricia_retrieve(mowgli_allocation_policy_dict, name); 71 | } 72 | -------------------------------------------------------------------------------- /src/libmowgli/core/allocation_policy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * allocation_policy.h: Allocation policy management. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_ALLOCATION_POLICY_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_ALLOCATION_POLICY_H_INCLUDE_GUARD 1 26 | 27 | #include "core/stdinc.h" 28 | #include "object/object.h" 29 | 30 | typedef void *(*mowgli_allocation_func_t)(size_t size); 31 | typedef void (*mowgli_deallocation_func_t)(void *ptr); 32 | 33 | typedef struct 34 | { 35 | mowgli_object_t parent; 36 | mowgli_allocation_func_t allocate; 37 | mowgli_deallocation_func_t deallocate; 38 | } mowgli_allocation_policy_t; 39 | 40 | mowgli_allocation_policy_t *mowgli_allocation_policy_create(const char *name, mowgli_allocation_func_t allocator, mowgli_deallocation_func_t deallocator); 41 | mowgli_allocation_policy_t *mowgli_allocation_policy_lookup(const char *name); 42 | 43 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_ALLOCATION_POLICY_H_INCLUDE_GUARD */ 44 | -------------------------------------------------------------------------------- /src/libmowgli/core/allocator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * allocator.h: Builtin allocation policies (mmap/malloc). 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "core/bootstrap_internal.h" 26 | 27 | mowgli_allocation_policy_t *mowgli_allocator_malloc = NULL; 28 | 29 | static void * MOWGLI_FATTR_MALLOC MOWGLI_FATTR_ALLOC_SIZE(1) 30 | mowgli_allocator_func_malloc(size_t size) 31 | { 32 | return calloc(1, size); 33 | } 34 | 35 | static void 36 | mowgli_allocator_func_free(void *ptr) 37 | { 38 | (void) free(ptr); 39 | } 40 | 41 | void 42 | mowgli_allocator_bootstrap(void) 43 | { 44 | mowgli_allocator_malloc = \ 45 | mowgli_allocation_policy_create("malloc", &mowgli_allocator_func_malloc, &mowgli_allocator_func_free); 46 | } 47 | -------------------------------------------------------------------------------- /src/libmowgli/core/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * allocator.h: Builtin allocation policies (mmap/malloc). 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_ALLOCATOR_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_ALLOCATOR_H_INCLUDE_GUARD 1 26 | 27 | #include "core/allocation_policy.h" 28 | 29 | extern mowgli_allocation_policy_t *mowgli_allocator_malloc; 30 | 31 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_ALLOCATOR_H_INCLUDE_GUARD */ 32 | -------------------------------------------------------------------------------- /src/libmowgli/core/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * assert.h: Assertions. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_ASSERT_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_ASSERT_H_INCLUDE_GUARD 1 26 | 27 | #include "core/logger.h" 28 | 29 | #define _assert_msg(exp) "assertion '" #exp "' failed." 30 | 31 | #define soft_assert(exp) \ 32 | do \ 33 | { \ 34 | if (!(exp)) \ 35 | { \ 36 | mowgli_log_warning(_assert_msg(exp)); \ 37 | } \ 38 | } while (0) 39 | 40 | #define return_if_fail(exp) \ 41 | do \ 42 | { \ 43 | if (!(exp)) \ 44 | { \ 45 | mowgli_log_warning(_assert_msg(exp)); \ 46 | return; \ 47 | } \ 48 | } while (0) 49 | 50 | #define return_val_if_fail(exp, val) \ 51 | do \ 52 | { \ 53 | if (!(exp)) \ 54 | { \ 55 | mowgli_log_warning(_assert_msg(exp)); \ 56 | return (val); \ 57 | } \ 58 | } while (0) 59 | 60 | #define return_null_if_fail(exp) return_val_if_fail(exp, NULL) 61 | 62 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_ASSERT_H_INCLUDE_GUARD */ 63 | -------------------------------------------------------------------------------- /src/libmowgli/core/bootstrap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * bootstrap.c: Initialization of libmowgli. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "core/bootstrap_internal.h" 26 | 27 | /* TODO: rename to mowgli_bootstrap next time there is a LIB_MAJOR bump */ 28 | MOWGLI_BOOTSTRAP_FUNC(mowgli_bootstrap_real) 29 | { 30 | static bool bootstrapped = 0; 31 | 32 | if (bootstrapped) 33 | return; 34 | 35 | /* initial bootstrap */ 36 | mowgli_log_bootstrap(); 37 | mowgli_node_bootstrap(); 38 | mowgli_queue_bootstrap(); 39 | mowgli_object_class_bootstrap(); 40 | mowgli_argstack_bootstrap(); 41 | mowgli_bitvector_bootstrap(); 42 | mowgli_global_storage_bootstrap(); 43 | mowgli_hook_bootstrap(); 44 | mowgli_random_bootstrap(); 45 | mowgli_allocation_policy_bootstrap(); 46 | mowgli_allocator_bootstrap(); 47 | mowgli_memslice_bootstrap(); 48 | mowgli_cacheline_bootstrap(); 49 | mowgli_interface_bootstrap(); 50 | mowgli_index_bootstrap(); 51 | 52 | #ifdef _WIN32 53 | mowgli_winsock_bootstrap(); 54 | #endif 55 | 56 | /* now that we're bootstrapped, we can use a more optimised allocator 57 | if one is available. */ 58 | mowgli_allocator_set_policy(mowgli_allocator_malloc); 59 | 60 | bootstrapped = true; 61 | } 62 | 63 | void 64 | mowgli_init(void) 65 | { 66 | mowgli_log("mowgli_init() is a deprecated function, provided only for backwards compatibility with Mowgli-1. You should remove it if you no longer support using Mowgli-1."); 67 | } 68 | -------------------------------------------------------------------------------- /src/libmowgli/core/bootstrap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * bootstrap.c: Initialization of libmowgli. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_BOOTSTRAP_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_BOOTSTRAP_H_INCLUDE_GUARD 1 26 | 27 | extern void mowgli_bootstrap(void); 28 | extern void mowgli_init(void); 29 | 30 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_BOOTSTRAP_H_INCLUDE_GUARD */ 31 | -------------------------------------------------------------------------------- /src/libmowgli/core/bootstrap_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * bootstrap.c: Initialization of libmowgli. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_BOOTSTRAP_INTERNAL_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_BOOTSTRAP_INTERNAL_H_INCLUDE_GUARD 1 26 | 27 | extern void mowgli_allocation_policy_bootstrap(void); 28 | extern void mowgli_allocator_bootstrap(void); 29 | extern void mowgli_argstack_bootstrap(void); 30 | extern void mowgli_bitvector_bootstrap(void); 31 | extern void mowgli_cacheline_bootstrap(void); 32 | extern void mowgli_global_storage_bootstrap(void); 33 | extern void mowgli_hook_bootstrap(void); 34 | extern void mowgli_interface_bootstrap(void); 35 | extern void mowgli_log_bootstrap(void); 36 | extern void mowgli_memslice_bootstrap(void); 37 | extern void mowgli_node_bootstrap(void); 38 | extern void mowgli_object_class_bootstrap(void); 39 | extern void mowgli_queue_bootstrap(void); 40 | extern void mowgli_random_bootstrap(void); 41 | extern void mowgli_index_bootstrap(void); 42 | 43 | #ifdef _WIN32 44 | extern void mowgli_winsock_bootstrap(void); 45 | #endif 46 | 47 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_BOOTSTRAP_INTERNAL_H_INCLUDE_GUARD */ 48 | -------------------------------------------------------------------------------- /src/libmowgli/core/heap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * heap.c: Heap allocation. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * Copyright (c) 2005-2006 Theo Julienne 7 | * Copyright (c) 2011 Andrew Wilcox 8 | * 9 | * Permission to use, copy, modify, and/or distribute this software for any 10 | * purpose with or without fee is hereby granted, provided that the above 11 | * copyright notice and this permission notice is present in all copies. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 17 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 22 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23 | * POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * Legal note: code devised from claro.base.block module r288 (Pre MPL) 26 | */ 27 | 28 | #include "mowgli.h" 29 | 30 | #ifndef DISABLE_HEAP_ALLOCATOR 31 | # include "heap.enabled.c" 32 | #else 33 | # include "heap.disabled.c" 34 | #endif 35 | -------------------------------------------------------------------------------- /src/libmowgli/core/heap.disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * heap.c: Heap allocation. 4 | * 5 | * Copyright (c) 2019 Aaron M. D. Jones 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | struct mowgli_heap_ 27 | { 28 | mowgli_list_t blocks; // retained for ABI compatibility 29 | mowgli_allocation_policy_t *allocator; 30 | size_t elem_size; 31 | }; 32 | 33 | mowgli_heap_t * 34 | mowgli_heap_create_full(const size_t elem_size, 35 | const size_t MOWGLI_VATTR_UNUSED mowgli_heap_elems, 36 | const unsigned int MOWGLI_VATTR_UNUSED flags, 37 | mowgli_allocation_policy_t *restrict allocator) 38 | { 39 | return_null_if_fail(elem_size != 0); 40 | 41 | if (! allocator) 42 | allocator = mowgli_allocator_get_policy(); 43 | 44 | return_null_if_fail(allocator != NULL); 45 | return_null_if_fail(allocator->allocate != NULL); 46 | 47 | mowgli_heap_t *const heap = allocator->allocate(sizeof *heap); 48 | 49 | if (! heap) 50 | return NULL; 51 | 52 | (void) memset(heap, 0x00, sizeof *heap); 53 | 54 | heap->allocator = allocator; 55 | heap->elem_size = elem_size; 56 | 57 | return heap; 58 | } 59 | 60 | mowgli_heap_t * 61 | mowgli_heap_create(const size_t elem_size, 62 | const size_t MOWGLI_VATTR_UNUSED mowgli_heap_elems, 63 | const unsigned int MOWGLI_VATTR_UNUSED flags) 64 | { 65 | return_null_if_fail(elem_size != 0); 66 | 67 | return mowgli_heap_create_full(elem_size, 0, 0, NULL); 68 | } 69 | 70 | void 71 | mowgli_heap_destroy(mowgli_heap_t *const restrict heap) 72 | { 73 | return_if_fail(heap != NULL); 74 | return_if_fail(heap->allocator != NULL); 75 | return_if_fail(heap->allocator->deallocate != NULL); 76 | 77 | (void) heap->allocator->deallocate(heap); 78 | } 79 | 80 | void * 81 | mowgli_heap_alloc(mowgli_heap_t *const restrict heap) 82 | { 83 | return_null_if_fail(heap != NULL); 84 | return_null_if_fail(heap->allocator != NULL); 85 | return_null_if_fail(heap->allocator->allocate != NULL); 86 | return_null_if_fail(heap->allocator->deallocate != NULL); 87 | 88 | void *ptr = heap->allocator->allocate(heap->elem_size); 89 | 90 | if (!ptr) 91 | return NULL; 92 | 93 | return memset(ptr, 0x00, heap->elem_size); 94 | } 95 | 96 | void 97 | mowgli_heap_free(mowgli_heap_t *const restrict heap, void *const restrict ptr) 98 | { 99 | return_if_fail(heap != NULL); 100 | return_if_fail(heap->allocator != NULL); 101 | return_if_fail(heap->allocator->deallocate != NULL); 102 | return_if_fail(ptr != NULL); 103 | 104 | (void) heap->allocator->deallocate(ptr); 105 | } 106 | -------------------------------------------------------------------------------- /src/libmowgli/core/heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * heap.h: Heap allocation. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * Copyright (c) 2005-2006 Theo Julienne 7 | * 8 | * Permission to use, copy, modify, and/or distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice is present in all copies. 11 | * 12 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 13 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 16 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 20 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | * 24 | * Legal note: code devised from claro.base.block module r288 (Pre MPL) 25 | */ 26 | 27 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_HEAP_H_INCLUDE_GUARD 28 | #define MOWGLI_SRC_LIBMOWGLI_CORE_HEAP_H_INCLUDE_GUARD 1 29 | 30 | #include "core/allocation_policy.h" 31 | #include "core/stdinc.h" 32 | #include "platform/attributes.h" 33 | 34 | typedef struct mowgli_heap_ mowgli_heap_t; 35 | typedef struct mowgli_block_ mowgli_block_t; 36 | 37 | /* Flag for mowgli_heap_create */ 38 | #define BH_DONTCARE 0 39 | 40 | #define BH_NOW 1 41 | #define BH_LAZY 0 42 | 43 | /* Functions for heaps */ 44 | extern mowgli_heap_t *mowgli_heap_create(size_t elem_size, size_t mowgli_heap_elems, unsigned int flags); 45 | extern mowgli_heap_t *mowgli_heap_create_full(size_t elem_size, size_t mowgli_heap_elems, unsigned int flags, mowgli_allocation_policy_t *allocator); 46 | extern void mowgli_heap_destroy(mowgli_heap_t *heap); 47 | 48 | /* Functions for blocks */ 49 | extern void *mowgli_heap_alloc(mowgli_heap_t *heap) 50 | MOWGLI_FATTR_MALLOC; 51 | 52 | extern void mowgli_heap_free(mowgli_heap_t *heap, void *data); 53 | 54 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_HEAP_H_INCLUDE_GUARD */ 55 | -------------------------------------------------------------------------------- /src/libmowgli/core/iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * iterator.h: Iterators. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_ITERATOR_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_ITERATOR_H_INCLUDE_GUARD 1 26 | 27 | typedef struct _mowgli_iterator 28 | { 29 | struct _mowgli_iterator *prev, *next; 30 | 31 | void *data; 32 | } mowgli_iterator_t; 33 | 34 | /* The following are macros which can be used with iterators. */ 35 | #define MOWGLI_ITER_FOREACH(n, head) \ 36 | for (n = (head); n; n = n->next) 37 | #define MOWGLI_ITER_FOREACH_NEXT(n, head) \ 38 | for (n = (head); n->next; n = n->next) 39 | #define MOWGLI_ITER_FOREACH_PREV(n, tail) \ 40 | for (n = (tail); n; n = n->prev) 41 | #define MOWGLI_ITER_FOREACH_SAFE(n, tn, head) \ 42 | for (n = (head), tn = n ? n->next : NULL; n != NULL; n = tn, tn = n ? n->next : NULL) 43 | 44 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_ITERATOR_H_INCLUDE_GUARD */ 45 | -------------------------------------------------------------------------------- /src/libmowgli/core/logger.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * logger.c: Event and debugging message logging. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "core/bootstrap_internal.h" 26 | 27 | #define MOWGLI_LOG_BUF_SIZE 4096 28 | 29 | static char _mowgli_log_buf[MOWGLI_LOG_BUF_SIZE]; 30 | static mowgli_log_cb_t _mowgli_log_cb; 31 | 32 | static void 33 | mowgli_log_cb_default(const char *buf) 34 | { 35 | fprintf(stderr, "%s\n", buf); 36 | } 37 | 38 | void 39 | mowgli_log_bootstrap(void) 40 | { 41 | _mowgli_log_cb = mowgli_log_cb_default; 42 | } 43 | 44 | void 45 | mowgli_log_set_cb(mowgli_log_cb_t callback) 46 | { 47 | return_if_fail(callback != NULL); 48 | 49 | _mowgli_log_cb = callback; 50 | } 51 | 52 | void 53 | mowgli_log_prefix_real(const char *file, int line, const char *func, const char *prefix, const char *fmt, ...) 54 | { 55 | int len = snprintf(_mowgli_log_buf, MOWGLI_LOG_BUF_SIZE, "(%s:%d %s): %s", 56 | file, line, func, prefix); 57 | 58 | char *buf = &_mowgli_log_buf[len]; 59 | 60 | va_list va; 61 | 62 | va_start(va, fmt); 63 | vsnprintf(buf, MOWGLI_LOG_BUF_SIZE - len, fmt, va); 64 | va_end(va); 65 | 66 | _mowgli_log_cb(_mowgli_log_buf); 67 | } 68 | 69 | /* TODO: remove next time there is a LIB_MAJOR bump */ 70 | void 71 | mowgli_log_real(const char *file, int line, const char *func, const char *fmt, ...) 72 | { 73 | int len = snprintf(_mowgli_log_buf, 4095, "(%s:%d %s): ", file, line, 74 | func); 75 | 76 | char *buf = &_mowgli_log_buf[len]; 77 | 78 | va_list va; 79 | 80 | va_start(va, fmt); 81 | vsnprintf(buf, 4095 - len, fmt, va); 82 | va_end(va); 83 | 84 | _mowgli_log_cb(_mowgli_log_buf); 85 | } 86 | 87 | /* TODO: remove next time there is a LIB_MAJOR bump */ 88 | void 89 | mowgli_soft_assert_log(const char *asrt, const char *file, int line, const char *function) 90 | { 91 | snprintf(_mowgli_log_buf, 4095, 92 | "(%s:%d %s): critical: Assertion '%s' failed.", file, line, 93 | function, asrt); 94 | 95 | _mowgli_log_cb(_mowgli_log_buf); 96 | } 97 | -------------------------------------------------------------------------------- /src/libmowgli/core/logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * logger.h: Event and debugging message logging. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * Copyright (c) 2013 Patrick McFarland 7 | * 8 | * Permission to use, copy, modify, and/or distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice is present in all copies. 11 | * 12 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 13 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 16 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 20 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_LOGGER_H_INCLUDE_GUARD 26 | #define MOWGLI_SRC_LIBMOWGLI_CORE_LOGGER_H_INCLUDE_GUARD 1 27 | 28 | #include "platform/attributes.h" 29 | 30 | #if defined(MOWGLI_COMPILER_GCC_COMPAT) 31 | # define MOWGLI_FUNC_NAME __PRETTY_FUNCTION__ 32 | #else 33 | # if defined(MOWGLI_COMPILER_MSVC) 34 | # define MOWGLI_FUNC_NAME __FUNCTION__ 35 | # else 36 | # define MOWGLI_FUNC_NAME __func__ 37 | # endif 38 | #endif 39 | 40 | typedef void (*mowgli_log_cb_t)(const char *); 41 | 42 | extern void mowgli_log_set_cb(mowgli_log_cb_t); 43 | 44 | extern void mowgli_log_real(const char *file, int line, const char *func, const char *fmt, ...) 45 | MOWGLI_FATTR_PRINTF(4, 5); 46 | 47 | extern void mowgli_log_prefix_real(const char *file, int line, const char *func, const char *prefix, const char *fmt, ...) 48 | MOWGLI_FATTR_PRINTF(5, 6); 49 | 50 | extern void mowgli_soft_assert_log(const char *asrt, const char *file, int line, const char *function); 51 | 52 | #define mowgli_log_prefix(prefix, ...) \ 53 | mowgli_log_prefix_real(__FILE__, __LINE__, MOWGLI_FUNC_NAME, prefix, __VA_ARGS__) 54 | 55 | #define mowgli_log(...) mowgli_log_prefix("", __VA_ARGS__) 56 | #define mowgli_log_warning(...) mowgli_log_prefix("warning: ", __VA_ARGS__) 57 | #define mowgli_log_error(...) mowgli_log_prefix("error: ", __VA_ARGS__) 58 | 59 | #define mowgli_log_fatal(...) \ 60 | do \ 61 | { \ 62 | mowgli_log_prefix("fatal: ", __VA_ARGS__); \ 63 | abort(); \ 64 | } while (0) 65 | 66 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_LOGGER_H_INCLUDE_GUARD */ 67 | -------------------------------------------------------------------------------- /src/libmowgli/core/mowgli_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * mowgli_string.h: Immutable string buffers with cheap manipulation. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * Copyright (c) 2007 Pippijn van Steenhoven 7 | * 8 | * Permission to use, copy, modify, and/or distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice is present in all copies. 11 | * 12 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 13 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 16 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 20 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_MOWGLI_STRING_H_INCLUDE_GUARD 26 | #define MOWGLI_SRC_LIBMOWGLI_CORE_MOWGLI_STRING_H_INCLUDE_GUARD 1 27 | 28 | #include "core/stdinc.h" 29 | #include "eventloop/eventloop.h" 30 | #include "platform/attributes.h" 31 | 32 | typedef struct mowgli_string_ 33 | { 34 | char *str; 35 | size_t pos; 36 | size_t size; 37 | 38 | void (*reset)(struct mowgli_string_ *self); 39 | 40 | void (*append)(struct mowgli_string_ *self, const char *src, size_t n); 41 | 42 | void (*append_char)(struct mowgli_string_ *self, const char c); 43 | 44 | void (*destroy)(struct mowgli_string_ *self); 45 | } mowgli_string_t; 46 | 47 | extern mowgli_string_t *mowgli_string_create(void); 48 | extern void mowgli_string_reset(mowgli_string_t *self); 49 | extern void mowgli_string_destroy(mowgli_string_t *self); 50 | extern void mowgli_string_append(mowgli_string_t *self, const char *src, size_t n); 51 | extern void mowgli_string_append_char(mowgli_string_t *self, const char c); 52 | 53 | extern size_t mowgli_strlcat(char *dest, const char *src, size_t count); 54 | extern size_t mowgli_strlcpy(char *dest, const char *src, size_t count); 55 | 56 | extern ssize_t mowgli_writef(mowgli_descriptor_t fd, const char *fmt, ...) 57 | MOWGLI_FATTR_PRINTF(2, 3); 58 | 59 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_MOWGLI_STRING_H_INCLUDE_GUARD */ 60 | -------------------------------------------------------------------------------- /src/libmowgli/core/process.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 William Pitcock 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice is present in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #include "mowgli.h" 22 | 23 | typedef struct 24 | { 25 | char *path; 26 | char **argv; 27 | } mowgli_process_execv_req_t; 28 | 29 | static void 30 | mowgli_process_cloned_execv(mowgli_process_execv_req_t *execv_req) 31 | { 32 | #ifndef _WIN32 33 | return_if_fail(execv_req != NULL); 34 | return_if_fail(execv_req->path != NULL); 35 | return_if_fail(execv_req->argv != NULL); 36 | 37 | /* Do best to set proctitle if below hack don't work */ 38 | mowgli_proctitle_set("%s", execv_req->argv[0]); 39 | execv(execv_req->path, execv_req->argv); 40 | 41 | mowgli_free(execv_req->argv); 42 | mowgli_free(execv_req->path); 43 | mowgli_free(execv_req); 44 | #else 45 | # warning implement me :( 46 | #endif 47 | } 48 | 49 | mowgli_process_t * 50 | mowgli_process_clone(mowgli_process_start_fn_t start_fn, const char *procname, void *userdata) 51 | { 52 | #ifndef _WIN32 53 | mowgli_process_t *out; 54 | 55 | return_val_if_fail(start_fn != NULL, NULL); 56 | 57 | out = mowgli_alloc(sizeof *out); 58 | out->userdata = userdata; 59 | 60 | out->pid = fork(); 61 | 62 | switch (out->pid) 63 | { 64 | case 0: 65 | /* Do our best to set this... */ 66 | mowgli_proctitle_set("%s", procname); 67 | start_fn(out->userdata); 68 | _exit(255); 69 | return NULL; 70 | 71 | case -1: 72 | mowgli_free(out); 73 | return NULL; 74 | } 75 | 76 | return out; 77 | #else 78 | # warning implement me :( 79 | return NULL; 80 | #endif 81 | } 82 | 83 | mowgli_process_t * 84 | mowgli_process_spawn(const char *path, char *const argv[]) 85 | { 86 | size_t i; 87 | mowgli_process_execv_req_t *req; 88 | 89 | return_val_if_fail(path != NULL, NULL); 90 | return_val_if_fail(argv != NULL, NULL); 91 | 92 | req = mowgli_alloc(sizeof *req); 93 | req->path = mowgli_strdup(path); 94 | 95 | for (i = 0; argv[i] != NULL; i++) 96 | ; 97 | 98 | req->argv = mowgli_alloc_array(sizeof(char *), i + 1); 99 | 100 | for (i = 0; argv[i] != NULL; i++) 101 | req->argv[i] = argv[i]; 102 | 103 | return mowgli_process_clone((mowgli_process_start_fn_t) mowgli_process_cloned_execv, req->argv[0], req); 104 | } 105 | 106 | void 107 | mowgli_process_kill(mowgli_process_t *process) 108 | { 109 | #ifndef _WIN32 110 | return_if_fail(process != NULL); 111 | 112 | kill(process->pid, SIGKILL); 113 | #else 114 | # warning implement me :( 115 | #endif 116 | } 117 | -------------------------------------------------------------------------------- /src/libmowgli/core/process.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 William Pitcock 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice is present in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_PROCESS_H_INCLUDE_GUARD 22 | #define MOWGLI_SRC_LIBMOWGLI_CORE_PROCESS_H_INCLUDE_GUARD 1 23 | 24 | #include "core/stdinc.h" 25 | 26 | typedef void (*mowgli_process_start_fn_t)(void *data); 27 | 28 | typedef pid_t mowgli_process_id_t; 29 | 30 | typedef struct 31 | { 32 | mowgli_process_id_t pid; 33 | void *userdata; 34 | } mowgli_process_t; 35 | 36 | extern mowgli_process_t *mowgli_process_clone(mowgli_process_start_fn_t start_fn, const char *proctitle, void *userdata); 37 | extern mowgli_process_t *mowgli_process_spawn(const char *path, char *const argv[]); 38 | extern void mowgli_process_kill(mowgli_process_t *process); 39 | 40 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_PROCESS_H_INCLUDE_GUARD */ 41 | -------------------------------------------------------------------------------- /src/libmowgli/core/stdinc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * stdinc.h: Pulls in the base system includes for libmowgli. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_CORE_STDINC_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_CORE_STDINC_H_INCLUDE_GUARD 1 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | /* socket stuff */ 46 | #ifndef _WIN32 47 | # include 48 | # include 49 | # include 50 | # include 51 | # include 52 | # include 53 | # include 54 | # include 55 | # include 56 | # include 57 | # include 58 | #else 59 | # define WINVER 0x0501 60 | # define WIN32_LEAN_AND_MEAN 61 | # include 62 | # include 63 | # include 64 | # include 65 | # include 66 | # include 67 | # include 68 | # include "platform/win32/win32_stdinc.h" 69 | #endif 70 | 71 | #ifdef _MSC_VER 72 | # pragma warning (disable: 4996) 73 | #endif 74 | 75 | #ifdef FALSE 76 | # undef FALSE 77 | #endif 78 | 79 | #ifdef TRUE 80 | # undef TRUE 81 | #endif 82 | 83 | typedef enum {FALSE, TRUE} mowgli_boolean_t; 84 | 85 | /* Macros for min/max. */ 86 | #ifndef MIN 87 | # define MIN(a, b) (((a) < (b)) ? (a) : (b)) 88 | #endif 89 | 90 | #ifndef MAX 91 | # define MAX(a, b) (((a) > (b)) ? (a) : (b)) 92 | #endif 93 | 94 | /* OpenSSL stuff */ 95 | #ifdef HAVE_OPENSSL 96 | # if defined(__APPLE__) 97 | # include 98 | # ifdef DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER 99 | # undef DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER 100 | # define DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER 101 | # endif 102 | # endif 103 | # include 104 | # include 105 | # include 106 | #endif 107 | 108 | #endif /* MOWGLI_SRC_LIBMOWGLI_CORE_STDINC_H_INCLUDE_GUARD */ 109 | -------------------------------------------------------------------------------- /src/libmowgli/dns/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_DNS} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_DNS} 5 | 6 | SRCS = dns.c \ 7 | evloop_res.c \ 8 | evloop_reslib.c \ 9 | evloop_reslist_win32.c 10 | 11 | INCLUDES = dns.h \ 12 | evloop_res.h \ 13 | evloop_reslib.h 14 | 15 | include ../../../buildsys.mk 16 | 17 | includesubdir = $(PACKAGE_NAME)/dns 18 | 19 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 20 | 21 | -------------------------------------------------------------------------------- /src/libmowgli/dns/dns.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Elizabeth J. Myers. All rights reserved. 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #include "mowgli.h" 22 | 23 | mowgli_dns_t * 24 | mowgli_dns_create(mowgli_eventloop_t *eventloop, int implementation) 25 | { 26 | mowgli_dns_t *dns = mowgli_alloc(sizeof *dns); 27 | const mowgli_dns_ops_t *ops; 28 | 29 | switch (implementation) 30 | { 31 | case MOWGLI_DNS_TYPE_CUSTOM: 32 | return dns; 33 | case MOWGLI_DNS_TYPE_ASYNC: 34 | default: 35 | ops = &mowgli_dns_evloop_resolver; 36 | break; 37 | } 38 | 39 | if (mowgli_dns_init(dns, eventloop, ops) != 0) 40 | { 41 | mowgli_free(dns); 42 | return NULL; 43 | } 44 | 45 | return dns; 46 | } 47 | 48 | int 49 | mowgli_dns_init(mowgli_dns_t *dns, mowgli_eventloop_t *eventloop, const mowgli_dns_ops_t *ops) 50 | { 51 | return_val_if_fail(dns != NULL, -1); 52 | 53 | dns->dns_ops = ops; 54 | 55 | return dns->dns_ops->mowgli_dns_init_func_t(dns, eventloop); 56 | } 57 | 58 | void 59 | mowgli_dns_destroy(mowgli_dns_t *dns) 60 | { 61 | dns->dns_ops->mowgli_dns_fini_func_t(dns); 62 | 63 | mowgli_free(dns); 64 | } 65 | 66 | int 67 | mowgli_dns_restart(mowgli_dns_t *dns) 68 | { 69 | return dns->dns_ops->mowgli_dns_restart_func_t(dns); 70 | } 71 | 72 | void 73 | mowgli_dns_delete_query(mowgli_dns_t *dns, const mowgli_dns_query_t *query) 74 | { 75 | dns->dns_ops->mowgli_dns_delete_query_func_t(dns, query); 76 | } 77 | 78 | void 79 | mowgli_dns_gethost_byname(mowgli_dns_t *dns, const char *name, mowgli_dns_query_t *query, int type) 80 | { 81 | dns->dns_ops->mowgli_dns_gethost_byname_func_t(dns, name, query, type); 82 | } 83 | 84 | void 85 | mowgli_dns_gethost_byaddr(mowgli_dns_t *dns, const struct sockaddr_storage *addr, mowgli_dns_query_t *query) 86 | { 87 | dns->dns_ops->mowgli_dns_gethost_byaddr_func_t(dns, addr, query); 88 | } 89 | -------------------------------------------------------------------------------- /src/libmowgli/dns/dns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Elizabeth J. Myers. All rights reserved. 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #ifndef MOWGLI_SRC_LIBMOWGLI_DNS_DNS_H_INCLUDE_GUARD 22 | #define MOWGLI_SRC_LIBMOWGLI_DNS_DNS_H_INCLUDE_GUARD 1 23 | 24 | #include "eventloop/eventloop.h" 25 | #include "vio/vio.h" 26 | 27 | /* Longest hostname we're willing to work with */ 28 | #define MOWGLI_DNS_RES_HOSTLEN 512 29 | 30 | /* Resolver types */ 31 | #define MOWGLI_DNS_TYPE_CUSTOM 0 32 | #define MOWGLI_DNS_TYPE_ASYNC 1 33 | #define MOWGLI_DNS_TYPE_HELPER 2 34 | 35 | /* Lookup types */ 36 | #define MOWGLI_DNS_T_A 1 37 | #define MOWGLI_DNS_T_AAAA 28 38 | #define MOWGLI_DNS_T_PTR 12 39 | #define MOWGLI_DNS_T_CNAME 5 40 | #define MOWGLI_DNS_T_MX 15 41 | #define MOWGLI_DNS_T_TXT 16 42 | #define MOWGLI_DNS_T_SSHFP 44 43 | #define MOWGLI_DNS_T_NULL 10 44 | 45 | /* Return codes */ 46 | #define MOWGLI_DNS_RES_SUCCESS 0 47 | #define MOWGLI_DNS_RES_NXDOMAIN 1 48 | #define MOWGLI_DNS_RES_INVALID 2 49 | #define MOWGLI_DNS_RES_TIMEOUT 3 50 | 51 | typedef struct _mowgli_dns_t mowgli_dns_t; 52 | typedef struct _mowgli_dns_query_t mowgli_dns_query_t; 53 | typedef struct _mowgli_dns_reply_t mowgli_dns_reply_t; 54 | 55 | typedef struct 56 | { 57 | int (*mowgli_dns_init_func_t)(mowgli_dns_t *, mowgli_eventloop_t *); 58 | void (*mowgli_dns_fini_func_t)(mowgli_dns_t *); 59 | int (*mowgli_dns_restart_func_t)(mowgli_dns_t *); 60 | void (*mowgli_dns_delete_query_func_t)(mowgli_dns_t *, const mowgli_dns_query_t *); 61 | void (*mowgli_dns_gethost_byname_func_t)(mowgli_dns_t *, const char *, mowgli_dns_query_t *, int); 62 | void (*mowgli_dns_gethost_byaddr_func_t)(mowgli_dns_t *, const struct sockaddr_storage *, mowgli_dns_query_t *); 63 | } mowgli_dns_ops_t; 64 | 65 | struct _mowgli_dns_reply_t 66 | { 67 | char *h_name; 68 | mowgli_vio_sockaddr_t addr; 69 | }; 70 | 71 | struct _mowgli_dns_t 72 | { 73 | int dns_type; 74 | const mowgli_dns_ops_t *dns_ops; 75 | void *dns_state; 76 | }; 77 | 78 | struct _mowgli_dns_query_t 79 | { 80 | void *ptr; /* pointer used by callback to identify request */ 81 | void (*callback)(mowgli_dns_reply_t *reply, int result, void *vptr); /* callback to call */ 82 | }; 83 | 84 | extern mowgli_dns_t *mowgli_dns_create(mowgli_eventloop_t *eventloop, int implementation); 85 | extern int mowgli_dns_init(mowgli_dns_t *dns, mowgli_eventloop_t *eventloop, const mowgli_dns_ops_t *ops); 86 | extern void mowgli_dns_destroy(mowgli_dns_t *dns); 87 | extern int mowgli_dns_restart(mowgli_dns_t *dns); 88 | extern void mowgli_dns_delete_query(mowgli_dns_t *dns, const mowgli_dns_query_t *query); 89 | extern void mowgli_dns_gethost_byname(mowgli_dns_t *dns, const char *name, mowgli_dns_query_t *query, int type); 90 | extern void mowgli_dns_gethost_byaddr(mowgli_dns_t *dns, const struct sockaddr_storage *addr, mowgli_dns_query_t *query); 91 | 92 | #endif /* MOWGLI_SRC_LIBMOWGLI_DNS_DNS_H_INCLUDE_GUARD */ 93 | -------------------------------------------------------------------------------- /src/libmowgli/dns/evloop_res.h: -------------------------------------------------------------------------------- 1 | /* 2 | * res.h for referencing functions in res.c, reslib.c 3 | * 4 | * Originally from Charybdis (before that, hybrid), but very little of the 5 | * original remains, so... 6 | */ 7 | 8 | #ifndef MOWGLI_SRC_LIBMOWGLI_DNS_EVLOOP_RES_H_INCLUDE_GUARD 9 | #define MOWGLI_SRC_LIBMOWGLI_DNS_EVLOOP_RES_H_INCLUDE_GUARD 1 10 | 11 | #include "base/random.h" 12 | #include "dns/dns.h" 13 | #include "eventloop/eventloop.h" 14 | #include "vio/vio.h" 15 | 16 | /* Maximum number of nameservers we track */ 17 | #define MOWGLI_DNS_MAXNS 10 18 | 19 | typedef struct 20 | { 21 | mowgli_vio_sockaddr_t nsaddr_list[MOWGLI_DNS_MAXNS]; 22 | int nscount; 23 | 24 | int retrycnt; 25 | 26 | int timeout_count[MOWGLI_DNS_MAXNS]; 27 | 28 | mowgli_vio_t *vio; 29 | mowgli_eventloop_t *eventloop; 30 | mowgli_eventloop_timer_t *timeout_resolver_timer; 31 | 32 | mowgli_list_t request_list; 33 | 34 | mowgli_random_t *rand; 35 | 36 | const char *resolvconf; 37 | bool dns_init; 38 | 39 | char domain[MOWGLI_DNS_RES_HOSTLEN]; 40 | } mowgli_dns_evloop_t; 41 | 42 | extern int mowgli_dns_evloop_init(mowgli_dns_t *dns, mowgli_eventloop_t *eventloop); 43 | extern int mowgli_dns_evloop_restart(mowgli_dns_t *dns); 44 | extern void mowgli_dns_evloop_destroy(mowgli_dns_t *dns); 45 | extern void mowgli_dns_evloop_delete_queries(mowgli_dns_t *dns, const mowgli_dns_query_t *); 46 | extern void mowgli_dns_evloop_gethost_byname(mowgli_dns_t *dns, const char *, mowgli_dns_query_t *, int); 47 | extern void mowgli_dns_evloop_gethost_byaddr(mowgli_dns_t *dns, const struct sockaddr_storage *, mowgli_dns_query_t *); 48 | 49 | extern void mowgli_dns_evloop_add_local_domain(mowgli_dns_t * dns, char *, size_t); 50 | extern int mowgli_dns_evloop_set_resolvconf(mowgli_dns_t *dns, const char *respath); 51 | 52 | extern const mowgli_dns_ops_t mowgli_dns_evloop_resolver; 53 | 54 | #endif /* MOWGLI_SRC_LIBMOWGLI_DNS_EVLOOP_RES_H_INCLUDE_GUARD */ 55 | -------------------------------------------------------------------------------- /src/libmowgli/dns/evloop_reslist_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * reslist.c - get nameservers from windows * 3 | * 4 | * Copyright 1998 by the Massachusetts Institute of Technology. 5 | * Copyright (C) 2007-2008 by Daniel Stenberg 6 | * 7 | * Permission to use, copy, modify, and distribute this 8 | * software and its documentation for any purpose and without 9 | * fee is hereby granted, provided that the above copyright 10 | * notice appear in all copies and that both that copyright 11 | * notice and this permission notice appear in supporting 12 | * documentation, and that the name of M.I.T. not be used in 13 | * advertising or publicity pertaining to distribution of the 14 | * software without specific, written prior permission. 15 | * M.I.T. makes no representations about the suitability of 16 | * this software for any purpose. It is provided "as is" 17 | * without express or implied warranty. 18 | */ 19 | 20 | #include "mowgli.h" 21 | 22 | #ifdef MOWGLI_OS_WIN 23 | # include 24 | # include 25 | 26 | int 27 | mowgli_dns_get_windows_nameservers(char *ret_buf, size_t ret_size) 28 | { 29 | FIXED_INFO *fixedinfo, tfixedinfo; 30 | DWORD size = sizeof(*fixedinfo); 31 | 32 | typedef DWORD (WINAPI * get_net_param_func)(FIXED_INFO *, DWORD *); 33 | get_net_param_func get_network_params; 34 | HMODULE handle; 35 | IP_ADDR_STRING *ip_addr; 36 | int i, count = 0; 37 | size_t ip_size = sizeof("255.255.255.255"); 38 | size_t left = ret_size; 39 | char *ret = ret_buf; 40 | HRESULT res; 41 | 42 | if (!(handle = LoadLibrary("iphlpapi.dll"))) 43 | return 0; 44 | 45 | if (!(get_network_params = (get_net_param_func) GetProcAddress(handle, "GetNetworkParams"))) 46 | goto quit; 47 | 48 | res = (*get_network_params)(&tfixedinfo, &size); 49 | 50 | if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS)) 51 | goto quit; 52 | 53 | fixedinfo = mowgli_alloc(size); 54 | 55 | if (!fixedinfo || ((*get_network_params)(fixedinfo, &size) != ERROR_SUCCESS)) 56 | goto quit; 57 | 58 | # ifdef DEBUG 59 | mowgli_log("Host Name: %s\n", fixedinfo->HostName); 60 | mowgli_log("Domain Name: %s\n", fixedinfo->DomainName); 61 | mowgli_log("DNS Servers:\n\t%s (primary)\n", fixedinfo->DnsServerList.IpAddress.String); 62 | # endif 63 | 64 | if ((strlen(fixedinfo->DnsServerList.IpAddress.String) > 0) && 65 | (inet_addr(fixedinfo->DnsServerList.IpAddress.String) != INADDR_NONE) && (left > ip_size)) 66 | { 67 | ret += sprintf(ret, "%s,", fixedinfo->DnsServerList.IpAddress.String); 68 | left -= ret - ret_buf; 69 | count++; 70 | } 71 | 72 | for (i = 0, ip_addr = fixedinfo->DnsServerList.Next; ip_addr && left > ip_size; ip_addr = ip_addr->Next, i++) 73 | { 74 | if (inet_addr(ip_addr->IpAddress.String) != INADDR_NONE) 75 | { 76 | ret += sprintf(ret, "%s,", ip_addr->IpAddress.String); 77 | left -= ret - ret_buf; 78 | count++; 79 | } 80 | 81 | # ifdef DEBUG 82 | mowgli_log("\t%s (secondary %d)\n", ip_addr->IpAddress.String, i + 1); 83 | # endif 84 | } 85 | 86 | mowgli_free(fixedinfo); 87 | 88 | quit: 89 | 90 | if (handle) 91 | FreeLibrary(handle); 92 | 93 | if (left <= ip_size) 94 | mowgli_log("Too many nameservers. Truncating to %d addressess", count); 95 | 96 | if (ret > ret_buf) 97 | ret[-1] = '\0'; 98 | 99 | return count; 100 | } 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/libmowgli/eventloop/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_EVENTLOOP} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_EVENTLOOP} 5 | 6 | SRCS = eventloop.c helper.c pollable.c timer.c null_pollops.c poll_pollops.c epoll_pollops.c kqueue_pollops.c qnx_pollops.c ports_pollops.c select_pollops.c windows_pollops.c 7 | 8 | INCLUDES = eventloop.h 9 | 10 | include ../../../buildsys.mk 11 | 12 | includesubdir = $(PACKAGE_NAME)/eventloop 13 | 14 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 15 | -------------------------------------------------------------------------------- /src/libmowgli/eventloop/eventloop_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011, 2012 William Pitcock . 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #ifndef MOWGLI_SRC_LIBMOWGLI_EVENTLOOP_EVENTLOOP_INTERNAL_H_INCLUDE_GUARD 22 | #define MOWGLI_SRC_LIBMOWGLI_EVENTLOOP_EVENTLOOP_INTERNAL_H_INCLUDE_GUARD 1 23 | 24 | #include "eventloop/eventloop.h" 25 | #include "platform/autoconf.h" 26 | 27 | extern mowgli_eventloop_ops_t _mowgli_null_pollops; 28 | 29 | #ifdef HAVE_PORT_CREATE 30 | extern mowgli_eventloop_ops_t _mowgli_ports_pollops; 31 | #endif 32 | 33 | #ifdef HAVE_DISPATCH_BLOCK 34 | extern mowgli_eventloop_ops_t _mowgli_qnx_pollops; 35 | #endif 36 | 37 | #ifdef HAVE_SELECT 38 | extern mowgli_eventloop_ops_t _mowgli_select_pollops; 39 | #endif 40 | 41 | #ifdef HAVE_POLL_H 42 | extern mowgli_eventloop_ops_t _mowgli_poll_pollops; 43 | #endif 44 | 45 | #ifdef HAVE_SYS_EPOLL_H 46 | extern mowgli_eventloop_ops_t _mowgli_epoll_pollops; 47 | #endif 48 | 49 | #ifdef HAVE_KQUEUE 50 | extern mowgli_eventloop_ops_t _mowgli_kqueue_pollops; 51 | #endif 52 | 53 | #if 0 54 | extern mowgli_eventloop_ops_t _mowgli_winsock_pollops; 55 | #endif 56 | 57 | #endif /* MOWGLI_SRC_LIBMOWGLI_EVENTLOOP_EVENTLOOP_INTERNAL_H_INCLUDE_GUARD */ 58 | -------------------------------------------------------------------------------- /src/libmowgli/ext/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_EXT} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_EXT} 5 | 6 | SRCS = confparse.c \ 7 | error_backtrace.c \ 8 | getopt_long.c \ 9 | global_storage.c \ 10 | program_opts.c \ 11 | proctitle.c \ 12 | json.c 13 | 14 | INCLUDES = confparse.h \ 15 | error_backtrace.h \ 16 | getopt_long.h \ 17 | global_storage.h \ 18 | program_opts.h \ 19 | proctitle.h \ 20 | json.h \ 21 | json-inline.h 22 | 23 | include ../../../buildsys.mk 24 | 25 | includesubdir = $(PACKAGE_NAME)/ext 26 | 27 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 28 | 29 | -------------------------------------------------------------------------------- /src/libmowgli/ext/confparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2008 William Pitcock, et al. 3 | * Rights to this code are as documented in doc/LICENSE. 4 | * 5 | * Config file parser. 6 | */ 7 | 8 | #ifndef MOWGLI_SRC_LIBMOWGLI_EXT_CONFPARSE_H_INCLUDE_GUARD 9 | #define MOWGLI_SRC_LIBMOWGLI_EXT_CONFPARSE_H_INCLUDE_GUARD 1 10 | 11 | typedef struct _mowgli_configfile mowgli_config_file_t; 12 | typedef struct _mowgli_configentry mowgli_config_file_entry_t; 13 | 14 | struct _mowgli_configfile 15 | { 16 | char *filename; 17 | mowgli_config_file_entry_t *entries; 18 | mowgli_config_file_t *next; 19 | int curline; 20 | char *mem; 21 | }; 22 | 23 | struct _mowgli_configentry 24 | { 25 | mowgli_config_file_t *fileptr; 26 | 27 | int varlinenum; 28 | char *varname; 29 | char *vardata; 30 | int sectlinenum;/* line containing closing brace */ 31 | 32 | mowgli_config_file_entry_t *entries; 33 | mowgli_config_file_entry_t *prevlevel; 34 | mowgli_config_file_entry_t *next; 35 | }; 36 | 37 | /* confp.c */ 38 | extern void mowgli_config_file_free(mowgli_config_file_t *cfptr); 39 | extern mowgli_config_file_t *mowgli_config_file_load(const char *filename); 40 | 41 | #endif /* MOWGLI_SRC_LIBMOWGLI_EXT_CONFPARSE_H_INCLUDE_GUARD */ 42 | -------------------------------------------------------------------------------- /src/libmowgli/ext/error_backtrace.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * error_backtrace.c: Print errors and explain how they were reached. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | void 27 | mowgli_error_context_display(mowgli_error_context_t *e, const char *delim) 28 | { 29 | return_if_fail(e != NULL); 30 | return_if_fail(delim != NULL); 31 | return_if_fail(MOWGLI_LIST_LENGTH(&e->bt) != 0); 32 | 33 | mowgli_node_t *n; 34 | char *bt_msg; 35 | 36 | MOWGLI_LIST_FOREACH(n, e->bt.head) 37 | { 38 | bt_msg = (char *) n->data; 39 | 40 | fprintf(stderr, "%s%s", bt_msg, n->next != NULL ? delim : "\n"); 41 | } 42 | } 43 | 44 | void 45 | mowgli_error_context_destroy(mowgli_error_context_t *e) 46 | { 47 | mowgli_node_t *n, *tn; 48 | 49 | return_if_fail(e != NULL); 50 | 51 | if (MOWGLI_LIST_LENGTH(&e->bt) == 0) 52 | { 53 | mowgli_free(e); 54 | return; 55 | } 56 | 57 | MOWGLI_LIST_FOREACH_SAFE(n, tn, e->bt.head) 58 | { 59 | mowgli_free(n->data); 60 | 61 | mowgli_node_delete(n, &e->bt); 62 | mowgli_node_free(n); 63 | } 64 | 65 | mowgli_free(e); 66 | } 67 | 68 | void 69 | mowgli_error_context_display_with_error(mowgli_error_context_t *e, const char *delim, const char *error) 70 | { 71 | mowgli_error_context_display(e, delim); 72 | fprintf(stderr, "Error: %s\n", error); 73 | 74 | _exit(EXIT_FAILURE); 75 | } 76 | 77 | void 78 | mowgli_error_context_push(mowgli_error_context_t *e, const char *msg, ...) 79 | { 80 | char buf[65535]; 81 | va_list va; 82 | 83 | return_if_fail(e != NULL); 84 | return_if_fail(msg != NULL); 85 | 86 | va_start(va, msg); 87 | vsnprintf(buf, 65535, msg, va); 88 | va_end(va); 89 | 90 | mowgli_node_add(mowgli_strdup(buf), mowgli_node_create(), &e->bt); 91 | } 92 | 93 | void 94 | mowgli_error_context_pop(mowgli_error_context_t *e) 95 | { 96 | return_if_fail(e != NULL); 97 | 98 | mowgli_node_delete(e->bt.tail, &e->bt); 99 | } 100 | 101 | mowgli_error_context_t * 102 | mowgli_error_context_create(void) 103 | { 104 | mowgli_error_context_t *out = mowgli_alloc(sizeof *out); 105 | 106 | return out; 107 | } 108 | -------------------------------------------------------------------------------- /src/libmowgli/ext/error_backtrace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * error_backtrace.h: Print errors and explain how they were reached. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_EXT_ERROR_BACKTRACE_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_EXT_ERROR_BACKTRACE_H_INCLUDE_GUARD 1 26 | 27 | #include "container/list.h" 28 | #include "platform/attributes.h" 29 | 30 | typedef struct mowgli_error_context_ 31 | { 32 | mowgli_list_t bt; 33 | } mowgli_error_context_t; 34 | 35 | extern void mowgli_error_context_display(mowgli_error_context_t *e, const char *delim); 36 | 37 | extern void mowgli_error_context_display_with_error(mowgli_error_context_t *e, const char *delim, const char *error) 38 | MOWGLI_FATTR_NORETURN; 39 | 40 | extern void mowgli_error_context_destroy(mowgli_error_context_t *e); 41 | 42 | extern void mowgli_error_context_push(mowgli_error_context_t *e, const char *msg, ...) 43 | MOWGLI_FATTR_PRINTF(2, 3); 44 | 45 | extern void mowgli_error_context_pop(mowgli_error_context_t *e); 46 | 47 | extern mowgli_error_context_t *mowgli_error_context_create(void) 48 | MOWGLI_FATTR_MALLOC; 49 | 50 | #endif /* MOWGLI_SRC_LIBMOWGLI_EXT_ERROR_BACKTRACE_H_INCLUDE_GUARD */ 51 | -------------------------------------------------------------------------------- /src/libmowgli/ext/getopt_long.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: getopt.h,v 1.11 2008/04/28 20:22:54 martin Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Dieter Baron and Thomas Klausner. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef MOWGLI_SRC_LIBMOWGLI_EXT_GETOPT_LONG_H_INCLUDE_GUARD 33 | #define MOWGLI_SRC_LIBMOWGLI_EXT_GETOPT_LONG_H_INCLUDE_GUARD 1 34 | 35 | /* 36 | * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions 37 | */ 38 | #define no_argument 0 39 | #define required_argument 1 40 | #define optional_argument 2 41 | 42 | typedef struct 43 | { 44 | /* name of long option */ 45 | const char *name; 46 | 47 | /* 48 | * one of no_argument, required_argument, and optional_argument: 49 | * whether option takes an argument 50 | */ 51 | int has_arg; 52 | 53 | /* if not NULL, set *flag to val when option found */ 54 | int *flag; 55 | 56 | /* if flag not NULL, value to set *flag to; else return value */ 57 | int val; 58 | 59 | /* internal value */ 60 | int iflag; 61 | } mowgli_getopt_option_t; 62 | 63 | extern int mowgli_getopt(int nargc, char *const *nargv, const char *options); 64 | 65 | extern int mowgli_getopt_long(int, char *const *, const char *, const mowgli_getopt_option_t *, int *); 66 | 67 | extern int mowgli_opterr; 68 | extern int mowgli_optind; 69 | extern int mowgli_optopt; 70 | extern int mowgli_optreset; 71 | extern char *mowgli_optarg; 72 | 73 | #endif /* MOWGLI_SRC_LIBMOWGLI_EXT_GETOPT_LONG_H_INCLUDE_GUARD */ 74 | -------------------------------------------------------------------------------- /src/libmowgli/ext/global_storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * global_storage.c: Simple key->value global storage tool. 4 | * 5 | * Copyright (c) 2007, 2011 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "core/bootstrap_internal.h" 26 | 27 | static mowgli_patricia_t *mowgli_global_storage_dict = NULL; 28 | static mowgli_mutex_t mowgli_global_storage_lock; 29 | 30 | static void 31 | _storage_key_canon(char *key) 32 | { } 33 | 34 | void 35 | mowgli_global_storage_bootstrap(void) 36 | { 37 | mowgli_global_storage_dict = mowgli_patricia_create(_storage_key_canon); 38 | 39 | mowgli_mutex_init(&mowgli_global_storage_lock); 40 | } 41 | 42 | void * 43 | mowgli_global_storage_get(char *name) 44 | { 45 | void *ret; 46 | 47 | mowgli_mutex_lock(&mowgli_global_storage_lock); 48 | ret = mowgli_patricia_retrieve(mowgli_global_storage_dict, name); 49 | mowgli_mutex_unlock(&mowgli_global_storage_lock); 50 | 51 | return ret; 52 | } 53 | 54 | void 55 | mowgli_global_storage_put(char *name, void *value) 56 | { 57 | mowgli_mutex_lock(&mowgli_global_storage_lock); 58 | mowgli_patricia_add(mowgli_global_storage_dict, name, value); 59 | mowgli_mutex_unlock(&mowgli_global_storage_lock); 60 | } 61 | 62 | void 63 | mowgli_global_storage_free(char *name) 64 | { 65 | mowgli_mutex_lock(&mowgli_global_storage_lock); 66 | mowgli_patricia_delete(mowgli_global_storage_dict, name); 67 | mowgli_mutex_unlock(&mowgli_global_storage_lock); 68 | } 69 | -------------------------------------------------------------------------------- /src/libmowgli/ext/global_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * global_storage.h: Simple key->value global storage tool. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_EXT_GLOBAL_STORAGE_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_EXT_GLOBAL_STORAGE_H_INCLUDE_GUARD 1 26 | 27 | extern void *mowgli_global_storage_get(char *name); 28 | extern void mowgli_global_storage_put(char *name, void *value); 29 | extern void mowgli_global_storage_free(char *name); 30 | 31 | #endif /* MOWGLI_SRC_LIBMOWGLI_EXT_GLOBAL_STORAGE_H_INCLUDE_GUARD */ 32 | -------------------------------------------------------------------------------- /src/libmowgli/ext/json-inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Alex Iadicicco 3 | * Rights to this code are as documented in COPYING. 4 | * 5 | * JSON inline functions, to simplify refcounting etc for other users 6 | */ 7 | 8 | #ifndef MOWGLI_SRC_LIBMOWGLI_EXT_JSON_INLINE_H_INCLUDE_GUARD 9 | #define MOWGLI_SRC_LIBMOWGLI_EXT_JSON_INLINE_H_INCLUDE_GUARD 1 10 | 11 | #include "ext/json.h" 12 | 13 | /* We don't need to include any other headers here. This is in a separate 14 | file to keep clutter out of the main json.h */ 15 | 16 | /* string */ 17 | static inline void 18 | mowgli_json_string_reset(mowgli_json_t *s) 19 | { 20 | mowgli_string_reset(MOWGLI_JSON_STRING(s)); 21 | } 22 | 23 | static inline void 24 | mowgli_json_string_append(mowgli_json_t *s, const char *src, size_t n) 25 | { 26 | mowgli_string_append(MOWGLI_JSON_STRING(s), src, n); 27 | } 28 | 29 | static inline void 30 | mowgli_json_string_append_char(mowgli_json_t *s, const char c) 31 | { 32 | mowgli_string_append_char(MOWGLI_JSON_STRING(s), c); 33 | } 34 | 35 | /* array */ 36 | static inline size_t 37 | mowgli_json_array_size(mowgli_json_t *arr) 38 | { 39 | return MOWGLI_JSON_ARRAY(arr)->count; 40 | } 41 | 42 | static inline void 43 | mowgli_json_array_add(mowgli_json_t *arr, mowgli_json_t *data) 44 | { 45 | mowgli_node_add(mowgli_json_incref(data), mowgli_node_create(), MOWGLI_JSON_ARRAY(arr)); 46 | } 47 | 48 | static inline void 49 | mowgli_json_array_add_head(mowgli_json_t *arr, mowgli_json_t *data) 50 | { 51 | mowgli_node_add_head(mowgli_json_incref(data), mowgli_node_create(), MOWGLI_JSON_ARRAY(arr)); 52 | } 53 | 54 | static inline void 55 | mowgli_json_array_insert(mowgli_json_t *arr, mowgli_json_t *data, size_t pos) 56 | { 57 | mowgli_node_insert(mowgli_json_incref(data), mowgli_node_create(), MOWGLI_JSON_ARRAY(arr), pos); 58 | } 59 | 60 | static inline void 61 | mowgli_json_array_delete(mowgli_json_t *arr, mowgli_json_t *data) 62 | { 63 | mowgli_node_t *n = mowgli_node_find(data, MOWGLI_JSON_ARRAY(arr)); 64 | 65 | if (n == NULL) 66 | return; 67 | 68 | mowgli_node_delete(n, MOWGLI_JSON_ARRAY(arr)); 69 | mowgli_json_decref(data); 70 | } 71 | 72 | static inline bool 73 | mowgli_json_array_contains(mowgli_json_t *arr, mowgli_json_t *data) 74 | { 75 | return mowgli_node_find(data, MOWGLI_JSON_ARRAY(arr)) != NULL; 76 | } 77 | 78 | static inline mowgli_json_t * 79 | mowgli_json_array_nth(mowgli_json_t *arr, size_t pos) 80 | { 81 | return (mowgli_json_t *) mowgli_node_nth_data(MOWGLI_JSON_ARRAY(arr), pos); 82 | } 83 | 84 | /* object */ 85 | static inline size_t 86 | mowgli_json_object_size(mowgli_json_t *obj) 87 | { 88 | return mowgli_patricia_size(MOWGLI_JSON_OBJECT(obj)); 89 | } 90 | 91 | static inline void 92 | mowgli_json_object_add(mowgli_json_t *obj, const char *key, mowgli_json_t *data) 93 | { 94 | mowgli_patricia_add(MOWGLI_JSON_OBJECT(obj), key, mowgli_json_incref(data)); 95 | } 96 | 97 | static inline mowgli_json_t * 98 | mowgli_json_object_retrieve(mowgli_json_t *obj, const char *key) 99 | { 100 | return (mowgli_json_t *) mowgli_patricia_retrieve(MOWGLI_JSON_OBJECT(obj), key); 101 | } 102 | 103 | static inline mowgli_json_t * 104 | mowgli_json_object_delete(mowgli_json_t *obj, const char *key) 105 | { 106 | return (mowgli_json_t *) mowgli_patricia_delete(MOWGLI_JSON_OBJECT(obj), key); 107 | } 108 | 109 | #endif /* MOWGLI_SRC_LIBMOWGLI_EXT_JSON_INLINE_H_INCLUDE_GUARD */ 110 | -------------------------------------------------------------------------------- /src/libmowgli/ext/proctitle.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * ps_status.h 4 | * 5 | * Declarations for backend/utils/misc/ps_status.c 6 | * 7 | * src/include/utils/ps_status.h 8 | * 9 | ***------------------------------------------------------------------------- 10 | */ 11 | 12 | #ifndef MOWGLI_SRC_LIBMOWGLI_EXT_PROCTITLE_H_INCLUDE_GUARD 13 | #define MOWGLI_SRC_LIBMOWGLI_EXT_PROCTITLE_H_INCLUDE_GUARD 1 14 | 15 | #include "core/stdinc.h" 16 | #include "platform/attributes.h" 17 | 18 | extern bool mowgli_proctitle_update; 19 | 20 | extern char **mowgli_argv; 21 | extern int mowgli_argc; 22 | 23 | extern char **mowgli_proctitle_init(int argc, char **argv); 24 | 25 | extern void mowgli_proctitle_set(const char *fmt, ...) 26 | MOWGLI_FATTR_PRINTF(1, 2); 27 | 28 | extern const char *mowgli_proctitle_get(int *displen); 29 | 30 | #endif /* MOWGLI_SRC_LIBMOWGLI_EXT_PROCTITLE_H_INCLUDE_GUARD */ 31 | -------------------------------------------------------------------------------- /src/libmowgli/ext/program_opts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * program_opts.h: Replacement for GNU getopt(). 4 | * 5 | * Copyright (c) 2012 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_EXT_PROGRAM_OPTS_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_EXT_PROGRAM_OPTS_H_INCLUDE_GUARD 1 26 | 27 | #include "core/stdinc.h" 28 | 29 | typedef void (*mowgli_program_opts_consumer_t)(const char *arg, void *userdata); 30 | 31 | typedef struct 32 | { 33 | const char *longopt; 34 | const char smallopt; 35 | bool has_param; 36 | mowgli_program_opts_consumer_t consumer; 37 | void *userdata; 38 | 39 | /* optional data */ 40 | const char *description; 41 | const char *paramname; 42 | } mowgli_program_opts_t; 43 | 44 | /* use when has_param is true */ 45 | extern void mowgli_program_opts_consumer_str(const char *arg, void *userdata); 46 | extern void mowgli_program_opts_consumer_int(const char *arg, void *userdata); 47 | 48 | /* use when has_param is false */ 49 | extern void mowgli_program_opts_consumer_bool(const char *arg, void *userdata); 50 | 51 | extern void mowgli_program_opts_parse(const mowgli_program_opts_t *opts, size_t opts_size, int *argc, char ***argv); 52 | 53 | #endif /* MOWGLI_SRC_LIBMOWGLI_EXT_PROGRAM_OPTS_H_INCLUDE_GUARD */ 54 | -------------------------------------------------------------------------------- /src/libmowgli/linebuf/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_LINEBUF} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_LINEBUF} 5 | 6 | SRCS = linebuf.c 7 | 8 | INCLUDES = linebuf.h 9 | 10 | include ../../../buildsys.mk 11 | 12 | includesubdir = $(PACKAGE_NAME)/linebuf 13 | 14 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 15 | 16 | -------------------------------------------------------------------------------- /src/libmowgli/linebuf/linebuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Elizabeth J. Myers. All rights reserved. 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #ifndef MOWGLI_SRC_LIBMOWGLI_LINEBUF_LINEBUF_H_INCLUDE_GUARD 22 | #define MOWGLI_SRC_LIBMOWGLI_LINEBUF_LINEBUF_H_INCLUDE_GUARD 1 23 | 24 | #include "eventloop/eventloop.h" 25 | #include "platform/attributes.h" 26 | #include "vio/vio.h" 27 | 28 | typedef struct _mowgli_linebuf_buf mowgli_linebuf_buf_t; 29 | 30 | typedef void mowgli_linebuf_readline_cb_t (mowgli_linebuf_t *, char *, size_t, void *); 31 | typedef void mowgli_linebuf_shutdown_cb_t (mowgli_linebuf_t *, void *); 32 | 33 | extern mowgli_linebuf_t *mowgli_linebuf_create(mowgli_linebuf_readline_cb_t *cb, void *userdata); 34 | 35 | /* XXX these are unfortunately named and will change */ 36 | extern void mowgli_linebuf_attach_to_eventloop(mowgli_linebuf_t *linebuf, mowgli_eventloop_t *eventloop); 37 | extern void mowgli_linebuf_detach_from_eventloop(mowgli_linebuf_t *linebuf); 38 | extern void mowgli_linebuf_destroy(mowgli_linebuf_t *linebuf); 39 | 40 | extern void mowgli_linebuf_setbuflen(mowgli_linebuf_buf_t *buffer, size_t buflen); 41 | extern void mowgli_linebuf_delim(mowgli_linebuf_t *linebuf, const char *delim, const char *endl); 42 | extern void mowgli_linebuf_write(mowgli_linebuf_t *linebuf, const char *data, int len); 43 | 44 | extern void mowgli_linebuf_writef(mowgli_linebuf_t *linebuf, const char *format, ...) 45 | MOWGLI_FATTR_PRINTF(2, 3); 46 | 47 | extern void mowgli_linebuf_shut_down(mowgli_linebuf_t *linebuf); 48 | 49 | struct _mowgli_linebuf_buf 50 | { 51 | char *buffer; 52 | size_t buflen; 53 | size_t maxbuflen; 54 | }; 55 | 56 | /* Errors */ 57 | #define MOWGLI_LINEBUF_ERR_NONE 0x0000 58 | #define MOWGLI_LINEBUF_ERR_READBUF_FULL 0x0001 59 | #define MOWGLI_LINEBUF_ERR_WRITEBUF_FULL 0x0002 60 | 61 | /* Informative */ 62 | #define MOWGLI_LINEBUF_LINE_HASNULLCHAR 0x0004 63 | 64 | /* State */ 65 | #define MOWGLI_LINEBUF_SHUTTING_DOWN 0x0100 66 | 67 | struct _mowgli_linebuf 68 | { 69 | mowgli_linebuf_readline_cb_t *readline_cb; 70 | mowgli_linebuf_shutdown_cb_t *shutdown_cb; 71 | 72 | mowgli_vio_t *vio; 73 | 74 | const char *delim; 75 | const char *endl; 76 | size_t endl_len; 77 | 78 | int flags; 79 | 80 | mowgli_linebuf_buf_t readbuf; 81 | mowgli_linebuf_buf_t writebuf; 82 | 83 | mowgli_eventloop_t *eventloop; 84 | 85 | bool return_normal_strings; 86 | 87 | void *userdata; 88 | }; 89 | 90 | static inline mowgli_vio_t * 91 | mowgli_linebuf_get_vio(mowgli_linebuf_t *linebuf) 92 | { 93 | return_val_if_fail(linebuf != NULL, NULL); 94 | return linebuf->vio; 95 | } 96 | 97 | #endif /* MOWGLI_SRC_LIBMOWGLI_LINEBUF_LINEBUF_H_INCLUDE_GUARD */ 98 | -------------------------------------------------------------------------------- /src/libmowgli/module/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_MODULE} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_MODULE} 5 | 6 | SRCS = interface.c loader_${LIBMOWGLI_OS}.c 7 | 8 | INCLUDES = module.h 9 | 10 | include ../../../buildsys.mk 11 | 12 | includesubdir = $(PACKAGE_NAME)/module 13 | 14 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 15 | 16 | -------------------------------------------------------------------------------- /src/libmowgli/module/interface.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * module.h: Loadable modules. 4 | * 5 | * Copyright (c) 2007, 2014 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "core/bootstrap_internal.h" 26 | 27 | static mowgli_patricia_t *mowgli_interface_dict = NULL; 28 | static mowgli_mutex_t mowgli_interface_lock; 29 | 30 | void 31 | mowgli_interface_bootstrap(void) 32 | { 33 | mowgli_interface_dict = mowgli_patricia_create(NULL); 34 | mowgli_mutex_init(&mowgli_interface_lock); 35 | } 36 | 37 | void 38 | mowgli_interface_register(mowgli_interface_t *iface) 39 | { 40 | mowgli_interface_base_t *base_iface = iface; 41 | 42 | mowgli_mutex_lock(&mowgli_interface_lock); 43 | mowgli_patricia_add(mowgli_interface_dict, base_iface->id, iface); 44 | mowgli_mutex_unlock(&mowgli_interface_lock); 45 | } 46 | 47 | void 48 | mowgli_interface_unregister(mowgli_interface_t *iface) 49 | { 50 | mowgli_interface_base_t *base_iface = iface; 51 | 52 | mowgli_mutex_lock(&mowgli_interface_lock); 53 | mowgli_patricia_delete(mowgli_interface_dict, base_iface->id); 54 | mowgli_mutex_unlock(&mowgli_interface_lock); 55 | } 56 | 57 | mowgli_interface_t * 58 | mowgli_interface_get(const char *id, uint32_t abirev) 59 | { 60 | mowgli_interface_base_t *base_iface; 61 | 62 | mowgli_mutex_lock(&mowgli_interface_lock); 63 | 64 | base_iface = mowgli_patricia_retrieve(mowgli_interface_dict, id); 65 | if (base_iface->abirev != abirev) 66 | { 67 | mowgli_log("requested interface %s, abi mismatch %" PRIu32 " != %" PRIu32, id, abirev, base_iface->abirev); 68 | base_iface = NULL; 69 | } 70 | 71 | mowgli_mutex_unlock(&mowgli_interface_lock); 72 | 73 | return base_iface; 74 | } 75 | -------------------------------------------------------------------------------- /src/libmowgli/module/loader_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * loader_posix.c: Loadable modules for POSIX systems. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | #include 27 | 28 | #ifdef __OpenBSD__ 29 | # define RTLD_NOW RTLD_LAZY 30 | #endif 31 | 32 | #ifndef RTLD_LOCAL 33 | # define RTLD_LOCAL 0 34 | #endif 35 | 36 | mowgli_module_t 37 | mowgli_module_open(const char *path) 38 | { 39 | void *handle = dlopen(path, RTLD_NOW | RTLD_LOCAL); 40 | 41 | if (handle == NULL) 42 | { 43 | mowgli_log("Failed to open %s: %s", path, dlerror()); 44 | return NULL; 45 | } 46 | 47 | return handle; 48 | } 49 | 50 | void * 51 | mowgli_module_symbol(mowgli_module_t module, const char *symbol) 52 | { 53 | void *handle; 54 | 55 | return_val_if_fail(module != NULL, NULL); 56 | 57 | handle = dlsym(module, symbol); 58 | 59 | if (handle == NULL) 60 | { 61 | mowgli_log("Failed to find symbol %s: %s", symbol, dlerror()); 62 | return NULL; 63 | } 64 | 65 | return handle; 66 | } 67 | 68 | void 69 | mowgli_module_close(mowgli_module_t module) 70 | { 71 | return_if_fail(module != NULL); 72 | 73 | dlclose(module); 74 | } 75 | -------------------------------------------------------------------------------- /src/libmowgli/module/loader_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * loader_win32.c: Loadable modules under Microsoft Windows. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | #define WIN32_LEAN_AND_MEAN 27 | #include 28 | 29 | mowgli_module_t 30 | mowgli_module_open(const char *path) 31 | { 32 | HANDLE handle = LoadLibraryA(path); 33 | 34 | /* make sure we have something. make this an assertion so that 35 | * there is feedback if something happens. (poor programming practice). 36 | */ 37 | return_val_if_fail(handle != NULL, NULL); 38 | 39 | return (mowgli_module_t) handle; 40 | } 41 | 42 | void * 43 | mowgli_module_symbol(mowgli_module_t module, const char *symbol) 44 | { 45 | void *handle; 46 | 47 | return_val_if_fail(module != NULL, NULL); 48 | 49 | handle = GetProcAddress((HANDLE) module, symbol); 50 | 51 | /* make sure we have something. make this an assertion so that 52 | * there is feedback if something happens. (poor programming practice). 53 | */ 54 | return_val_if_fail(handle != NULL, NULL); 55 | 56 | return handle; 57 | } 58 | 59 | void 60 | mowgli_module_close(mowgli_module_t module) 61 | { 62 | return_if_fail(module != NULL); 63 | 64 | FreeLibrary((HANDLE) module); 65 | } 66 | -------------------------------------------------------------------------------- /src/libmowgli/module/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * module.h: Loadable modules. 4 | * 5 | * Copyright (c) 2007, 2014 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_MODULE_MODULE_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_MODULE_MODULE_H_INCLUDE_GUARD 1 26 | 27 | #include "core/stdinc.h" 28 | 29 | typedef void *mowgli_module_t; 30 | 31 | extern mowgli_module_t mowgli_module_open(const char *path); 32 | extern void *mowgli_module_symbol(mowgli_module_t module, const char *symbol); 33 | extern void mowgli_module_close(mowgli_module_t module); 34 | 35 | typedef void mowgli_interface_t; 36 | 37 | typedef struct { 38 | const char *id; 39 | uint32_t abirev; 40 | } mowgli_interface_base_t; 41 | 42 | extern void mowgli_interface_register(mowgli_interface_t *iface); 43 | extern void mowgli_interface_unregister(mowgli_interface_t *iface); 44 | extern mowgli_interface_t *mowgli_interface_get(const char *id, uint32_t abirev); 45 | 46 | #endif /* MOWGLI_SRC_LIBMOWGLI_MODULE_MODULE_H_INCLUDE_GUARD */ 47 | -------------------------------------------------------------------------------- /src/libmowgli/mowgli.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * mowgli.h: Base header for libmowgli. Includes everything. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_MOWGLI_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_MOWGLI_H_INCLUDE_GUARD 1 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #ifdef MOWGLI_CORE 32 | # include "platform/autoconf.h" 33 | #endif 34 | 35 | #include "base/argstack.h" 36 | #include "base/bitvector.h" 37 | #include "base/formatter.h" 38 | #include "base/hash.h" 39 | #include "base/hook.h" 40 | #include "base/memslice.h" 41 | #include "base/mowgli_signal.h" 42 | #include "base/random.h" 43 | #include "container/dictionary.h" 44 | #include "container/index.h" 45 | #include "container/list.h" 46 | #include "container/patricia.h" 47 | #include "container/queue.h" 48 | #include "core/allocation_policy.h" 49 | #include "core/allocator.h" 50 | #include "core/alloc.h" 51 | #include "core/assert.h" 52 | #include "core/bootstrap.h" 53 | #include "core/heap.h" 54 | #include "core/iterator.h" 55 | #include "core/logger.h" 56 | #include "core/mowgli_string.h" 57 | #include "core/process.h" 58 | #include "dns/dns.h" 59 | #include "dns/evloop_res.h" 60 | #include "dns/evloop_reslib.h" 61 | #include "eventloop/eventloop.h" 62 | #include "ext/confparse.h" 63 | #include "ext/error_backtrace.h" 64 | #include "ext/getopt_long.h" 65 | #include "ext/global_storage.h" 66 | #include "ext/json.h" 67 | #include "ext/json-inline.h" 68 | #include "ext/proctitle.h" 69 | #include "ext/program_opts.h" 70 | #include "linebuf/linebuf.h" 71 | #include "module/module.h" 72 | #include "object/class.h" 73 | #include "object/message.h" 74 | #include "object/metadata.h" 75 | #include "object/object.h" 76 | #include "platform/attributes.h" 77 | #include "platform/cacheline.h" 78 | #include "platform/constructor.h" 79 | #include "platform/machine.h" 80 | #include "thread/mutex.h" 81 | #include "thread/thread.h" 82 | #include "vio/vio.h" 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* MOWGLI_SRC_LIBMOWGLI_MOWGLI_H_INCLUDE_GUARD */ 89 | -------------------------------------------------------------------------------- /src/libmowgli/object/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_OBJECT} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_OBJECT} 5 | 6 | SRCS = object.c \ 7 | class.c \ 8 | message.c \ 9 | metadata.c 10 | 11 | INCLUDES = object.h \ 12 | class.h \ 13 | message.h \ 14 | metadata.h 15 | 16 | include ../../../buildsys.mk 17 | 18 | includesubdir = $(PACKAGE_NAME)/object 19 | 20 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 21 | 22 | -------------------------------------------------------------------------------- /src/libmowgli/object/class.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * class.h: Object class and type management, cast checking. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_OBJECT_CLASS_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_OBJECT_CLASS_H_INCLUDE_GUARD 1 26 | 27 | #include "container/list.h" 28 | #include "core/stdinc.h" 29 | 30 | typedef void (*mowgli_destructor_t)(void *); 31 | 32 | typedef struct 33 | { 34 | char *name; 35 | mowgli_list_t derivitives; 36 | mowgli_destructor_t destructor; 37 | mowgli_boolean_t dynamic; 38 | mowgli_list_t message_handlers; 39 | } mowgli_object_class_t; 40 | 41 | extern void mowgli_object_class_init(mowgli_object_class_t *klass, const char *name, mowgli_destructor_t des, mowgli_boolean_t dynamic); 42 | extern int mowgli_object_class_check_cast(mowgli_object_class_t *klass1, mowgli_object_class_t *klass2); 43 | extern void mowgli_object_class_set_derivitive(mowgli_object_class_t *klass, mowgli_object_class_t *parent); 44 | extern void *mowgli_object_class_reinterpret_impl( /* mowgli_object_t */ void *object, mowgli_object_class_t *klass); 45 | extern mowgli_object_class_t *mowgli_object_class_find_by_name(const char *name); 46 | extern void mowgli_object_class_destroy(mowgli_object_class_t *klass); 47 | 48 | #define MOWGLI_REINTERPRET_CAST(object, klass) (klass *) mowgli_object_class_reinterpret_impl(object, mowgli_object_class_find_by_name(#klass)) 49 | 50 | #define mowgli_forced_cast(from_type, to_type, from, to) \ 51 | do \ 52 | { \ 53 | union cast_union \ 54 | { \ 55 | to_type out; \ 56 | from_type in; \ 57 | } u; \ 58 | typedef int cant_use_union_cast[ \ 59 | sizeof(from_type) == sizeof(u) \ 60 | && sizeof(from_type) == sizeof(to_type) ? 1 : -1]; \ 61 | u.in = from; \ 62 | to = u.out; \ 63 | } while (0) 64 | 65 | #endif /* MOWGLI_SRC_LIBMOWGLI_OBJECT_CLASS_H_INCLUDE_GUARD */ 66 | -------------------------------------------------------------------------------- /src/libmowgli/object/message.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * message.h: Object event notification and message passing. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_OBJECT_MESSAGE_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_OBJECT_MESSAGE_H_INCLUDE_GUARD 1 26 | 27 | #include "base/argstack.h" 28 | #include "object/class.h" 29 | #include "object/message.h" 30 | #include "object/object.h" 31 | 32 | typedef struct mowgli_object_message_handler_ mowgli_object_message_handler_t; 33 | typedef void (*mowgli_object_messaging_func_t)(mowgli_object_t *self, mowgli_object_message_handler_t *sig, mowgli_argstack_t *argstack); 34 | 35 | struct mowgli_object_message_handler_ 36 | { 37 | char *name; 38 | char *descstr; 39 | mowgli_object_messaging_func_t handler; 40 | }; 41 | 42 | extern void mowgli_object_class_message_handler_attach(mowgli_object_class_t *klass, mowgli_object_message_handler_t *sig); 43 | extern void mowgli_object_class_message_handler_detach(mowgli_object_class_t *klass, mowgli_object_message_handler_t *sig); 44 | extern void mowgli_object_message_handler_attach(mowgli_object_t *self, mowgli_object_message_handler_t *sig); 45 | extern void mowgli_object_message_handler_detach(mowgli_object_t *self, mowgli_object_message_handler_t *sig); 46 | extern void mowgli_object_message_broadcast(mowgli_object_t *self, const char *name, ...); 47 | 48 | #endif /* MOWGLI_SRC_LIBMOWGLI_OBJECT_MESSAGE_H_INCLUDE_GUARD */ 49 | -------------------------------------------------------------------------------- /src/libmowgli/object/metadata.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * metadata.c: Object metadata. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | void 27 | mowgli_object_metadata_associate(mowgli_object_t *self, const char *key, void *value) 28 | { 29 | return_if_fail(self != NULL); 30 | return_if_fail(key != NULL); 31 | 32 | mowgli_object_metadata_entry_t *e = NULL; 33 | mowgli_node_t *n; 34 | 35 | MOWGLI_LIST_FOREACH(n, self->metadata.head) 36 | { 37 | e = (mowgli_object_metadata_entry_t *) n->data; 38 | 39 | if (!strcasecmp(e->name, key)) 40 | break; 41 | } 42 | 43 | if (e != NULL) 44 | { 45 | e->data = value; 46 | return; 47 | } 48 | 49 | e = mowgli_alloc(sizeof *e); 50 | e->name = mowgli_strdup(key); 51 | e->data = value; 52 | 53 | mowgli_node_add(e, mowgli_node_create(), &self->metadata); 54 | } 55 | 56 | void 57 | mowgli_object_metadata_dissociate(mowgli_object_t *self, const char *key) 58 | { 59 | return_if_fail(self != NULL); 60 | return_if_fail(key != NULL); 61 | 62 | mowgli_object_metadata_entry_t *e; 63 | mowgli_node_t *n, *tn; 64 | 65 | MOWGLI_LIST_FOREACH_SAFE(n, tn, self->metadata.head) 66 | { 67 | e = (mowgli_object_metadata_entry_t *) n->data; 68 | 69 | if (!strcasecmp(e->name, key)) 70 | { 71 | mowgli_node_delete(n, &self->metadata); 72 | mowgli_node_free(n); 73 | 74 | mowgli_free(e->name); 75 | mowgli_free(e); 76 | } 77 | } 78 | } 79 | 80 | void * 81 | mowgli_object_metadata_retrieve(mowgli_object_t *self, const char *key) 82 | { 83 | return_null_if_fail(self != NULL); 84 | return_null_if_fail(key != NULL); 85 | 86 | mowgli_object_metadata_entry_t *e; 87 | mowgli_node_t *n; 88 | 89 | MOWGLI_LIST_FOREACH(n, self->metadata.head) 90 | { 91 | e = (mowgli_object_metadata_entry_t *) n->data; 92 | 93 | if (!strcasecmp(e->name, key)) 94 | return e->data; 95 | } 96 | 97 | return NULL; 98 | } 99 | -------------------------------------------------------------------------------- /src/libmowgli/object/metadata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * metadata.h: Object metadata. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_OBJECT_METADATA_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_OBJECT_METADATA_H_INCLUDE_GUARD 1 26 | 27 | #include "object/object.h" 28 | 29 | typedef struct 30 | { 31 | char *name; 32 | void *data; 33 | } mowgli_object_metadata_entry_t; 34 | 35 | extern void mowgli_object_metadata_associate(mowgli_object_t *self, const char *key, void *value); 36 | extern void mowgli_object_metadata_dissociate(mowgli_object_t *self, const char *key); 37 | extern void *mowgli_object_metadata_retrieve(mowgli_object_t *self, const char *key); 38 | 39 | #endif /* MOWGLI_SRC_LIBMOWGLI_OBJECT_METADATA_H_INCLUDE_GUARD */ 40 | -------------------------------------------------------------------------------- /src/libmowgli/object/object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * object.h: Object management. 4 | * 5 | * Copyright (c) 2007 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_OBJECT_OBJECT_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_OBJECT_OBJECT_H_INCLUDE_GUARD 1 26 | 27 | #include "object/class.h" 28 | 29 | typedef struct 30 | { 31 | char *name; 32 | int refcount; 33 | mowgli_object_class_t *klass; 34 | mowgli_list_t message_handlers; 35 | mowgli_list_t metadata; 36 | } mowgli_object_t; 37 | 38 | extern void mowgli_object_init(mowgli_object_t *, const char *name, mowgli_object_class_t *klass, mowgli_destructor_t destructor); 39 | extern void mowgli_object_init_from_class(mowgli_object_t *, const char *, mowgli_object_class_t *klass); 40 | extern void *mowgli_object_ref(void *); 41 | extern void mowgli_object_unref(void *); 42 | 43 | #define mowgli_object(x) ((mowgli_object_t *) x) 44 | 45 | #endif /* MOWGLI_SRC_LIBMOWGLI_OBJECT_OBJECT_H_INCLUDE_GUARD */ 46 | -------------------------------------------------------------------------------- /src/libmowgli/platform/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_PLATFORM} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_PLATFORM} 5 | 6 | DISTCLEAN = autoconf.h 7 | 8 | SUBDIRS = win32 9 | 10 | SRCS = cacheline.c 11 | 12 | INCLUDES = attributes.h cacheline.h constructor.h machine.h 13 | 14 | include ../../../buildsys.mk 15 | 16 | includesubdir = $(PACKAGE_NAME)/platform 17 | 18 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 19 | 20 | -------------------------------------------------------------------------------- /src/libmowgli/platform/autoconf.h.in: -------------------------------------------------------------------------------- 1 | /* src/libmowgli/platform/autoconf.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | 4 | #ifndef MOWGLI_SRC_LIBMOWGLI_PLATFORM_AUTOCONF_H_INCLUDE_GUARD 5 | #define MOWGLI_SRC_LIBMOWGLI_PLATFORM_AUTOCONF_H_INCLUDE_GUARD 1 6 | 7 | 8 | /* Disable the heap allocator */ 9 | #undef DISABLE_HEAP_ALLOCATOR 10 | 11 | /* Define to 1 if you have the `dispatch_block' function. */ 12 | #undef HAVE_DISPATCH_BLOCK 13 | 14 | /* Define to 1 if you have the `fcntl' function. */ 15 | #undef HAVE_FCNTL 16 | 17 | /* Define to 1 if you have the header file. */ 18 | #undef HAVE_INTTYPES_H 19 | 20 | /* Define to 1 if you have the `kqueue' function. */ 21 | #undef HAVE_KQUEUE 22 | 23 | /* Define to 1 if you have the header file. */ 24 | #undef HAVE_MEMORY_H 25 | 26 | /* Define to 1 if you have the `mmap' function. */ 27 | #undef HAVE_MMAP 28 | 29 | /* Define to 1 if OpenSSL is available */ 30 | #undef HAVE_OPENSSL 31 | 32 | /* Define to 1 if you have the header file. */ 33 | #undef HAVE_POLL_H 34 | 35 | /* Define to 1 if you have the `port_create' function. */ 36 | #undef HAVE_PORT_CREATE 37 | 38 | /* Define to 1 if you have the `pstat' function. */ 39 | #undef HAVE_PSTAT 40 | 41 | /* Define to 1 if the PS_STRINGS struct exists on your platform (likely no). 42 | */ 43 | #undef HAVE_PS_STRINGS 44 | 45 | /* Define if you have POSIX threads libraries and header files. */ 46 | #undef HAVE_PTHREAD 47 | 48 | /* Define to 1 if you have the `select' function. */ 49 | #undef HAVE_SELECT 50 | 51 | /* Define to 1 if you have the `setproctitle' function. */ 52 | #undef HAVE_SETPROCTITLE 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_STDINT_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_STDLIB_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_STRINGS_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #undef HAVE_STRING_H 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_SYS_EPOLL_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_SYS_PRCTL_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_SYS_PSTAT_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #undef HAVE_SYS_SELECT_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_SYS_STAT_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_SYS_TYPES_H 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #undef HAVE_UNISTD_H 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #undef HAVE_WINSOCK2_H 89 | 90 | /* Whether openssl/ec.h exists */ 91 | #undef OPENSSL_EC_AVAILABLE 92 | 93 | /* Define to the address where bug reports for this package should be sent. */ 94 | #undef PACKAGE_BUGREPORT 95 | 96 | /* Define to the full name of this package. */ 97 | #undef PACKAGE_NAME 98 | 99 | /* Define to the full name and version of this package. */ 100 | #undef PACKAGE_STRING 101 | 102 | /* Define to the one symbol short name of this package. */ 103 | #undef PACKAGE_TARNAME 104 | 105 | /* Define to the home page for this package. */ 106 | #undef PACKAGE_URL 107 | 108 | /* Define to the version of this package. */ 109 | #undef PACKAGE_VERSION 110 | 111 | /* Define to necessary symbol if this constant uses a non-standard name on 112 | your system. */ 113 | #undef PTHREAD_CREATE_JOINABLE 114 | 115 | /* Define to 1 if you have the ANSI C header files. */ 116 | #undef STDC_HEADERS 117 | 118 | 119 | #endif /* !MOWGLI_SRC_LIBMOWGLI_PLATFORM_AUTOCONF_H_INCLUDE_GUARD */ 120 | 121 | -------------------------------------------------------------------------------- /src/libmowgli/platform/cacheline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * cacheline.c: Platform specific routines to get L1 cache line size 4 | * 5 | * Copyright (c) 2013 Patrick McFarland 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "core/bootstrap_internal.h" 26 | 27 | #ifdef MOWGLI_OS_OSX 28 | # include 29 | #endif 30 | 31 | static size_t cacheline_size = 0; 32 | 33 | void 34 | mowgli_cacheline_bootstrap(void) 35 | { 36 | #if defined(MOWGLI_OS_LINUX) && defined(_SC_LEVEL1_DCACHE_LINESIZE) 37 | cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); 38 | #elif defined(MOWGLI_OS_OSX) 39 | size_t size = sizeof(size_t); 40 | sysctlbyname("hw.cachelinesize", &cacheline_size, &size, 0, 0); 41 | #elif defined(MOWGLI_OS_WIN) 42 | DWORD buf_size = 0; 43 | DWORD i = 0; 44 | SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buf = 0; 45 | 46 | GetLogicalProcessorInformation(0, &buf_size); 47 | buf = mowgli_alloc(buf_size); 48 | GetLogicalProcessorInformation(&buf[0], &buf_size); 49 | 50 | for (i = 0; i != buf_size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ++i) 51 | if ((buf[i].Relationship == RelationCache) && (buf[i].Cache.Level == 1)) 52 | { 53 | cacheline_size = buf[i].Cache.LineSize; 54 | break; 55 | } 56 | 57 | mowgli_free(buf); 58 | #else 59 | 60 | // This is often true 61 | # ifdef MOWGLI_CPU_BITS_32 62 | cacheline_size = 32; 63 | # else 64 | cacheline_size = 64; 65 | # endif 66 | #endif 67 | } 68 | 69 | size_t 70 | mowgli_cacheline_size(void) 71 | { 72 | return cacheline_size; 73 | } 74 | -------------------------------------------------------------------------------- /src/libmowgli/platform/cacheline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * cacheline.h: Platform specific routines to get L1 cache line size 4 | * 5 | * Copyright (c) 2013 Patrick McFarland 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_PLATFORM_CACHELINE_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_PLATFORM_CACHELINE_H_INCLUDE_GUARD 1 26 | 27 | #include "core/stdinc.h" 28 | 29 | extern size_t mowgli_cacheline_size(void); 30 | 31 | #endif /* MOWGLI_SRC_LIBMOWGLI_PLATFORM_CACHELINE_H_INCLUDE_GUARD */ 32 | -------------------------------------------------------------------------------- /src/libmowgli/platform/constructor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * constructor.h 3 | * Code for setting up automatic initializer functions portably. 4 | * 5 | * Copyright (c) 2012 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_PLATFORM_CONSTRUCTOR_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_PLATFORM_CONSTRUCTOR_H_INCLUDE_GUARD 1 26 | 27 | #include "platform/machine.h" 28 | 29 | #if defined MOWGLI_COMPILER_MSVC 30 | 31 | /* 32 | * Automatic constructors are not yet officially supported in MSVC, however, 33 | * there is a similar feature where functions in the ".CRT$XCU" section are 34 | * evaluated prior to DllMain(), main() and friends. 35 | * 36 | * See http://blogs.msdn.com/b/vcblog/archive/2006/10/20/crt-initialization.aspx 37 | * for more information. 38 | */ 39 | # define MOWGLI_BOOTSTRAP_FUNC(func) \ 40 | static void __cdecl func(void); \ 41 | __declspec(allocate(".CRT$XCU")) void(__cdecl * func##_) (void) = func; \ 42 | static void __cdecl func(void) 43 | #elif defined MOWGLI_COMPILER_GCC_COMPAT 44 | # if MOWGLI_COMPILER_GCC_VERSION >= 403000 45 | # define MOWGLI_BOOTSTRAP_FUNC(func) \ 46 | static void func(void) __attribute__((cold, constructor, flatten)); \ 47 | static void func(void) 48 | # else 49 | # define MOWGLI_BOOTSTRAP_FUNC(func) \ 50 | static void func(void) __attribute__((constructor, flatten)); \ 51 | static void func(void) 52 | # endif 53 | #elif defined __SUNPRO_C || defined __SUNPRO_CC 54 | # define MOWGLI_BOOTSTRAP_FUNC(func) \ 55 | static void func(void) __attribute__((constructor)); \ 56 | static void func(void) 57 | #else 58 | # error MOWGLI_BOOTSTRAP_FUNC not implemented for your platform :( 59 | #endif 60 | 61 | #endif /* MOWGLI_SRC_LIBMOWGLI_PLATFORM_CONSTRUCTOR_H_INCLUDE_GUARD */ 62 | -------------------------------------------------------------------------------- /src/libmowgli/platform/win32/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_PLATFORM_WIN32} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_PLATFORM_WIN32} 5 | 6 | SRCS = fork.c inet.c pipe.c socketpair.c setenv.c 7 | 8 | INCLUDES = win32_stdinc.h 9 | 10 | include ../../../../buildsys.mk 11 | 12 | includesubdir = $(PACKAGE_NAME)/platform/win32 13 | 14 | CPPFLAGS += -I. -I.. -I../.. -I../../../.. -DMOWGLI_CORE 15 | 16 | -------------------------------------------------------------------------------- /src/libmowgli/platform/win32/inet.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 William Pitcock . 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice is present in all copies. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 9 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 12 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 14 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 15 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 17 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 18 | * POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | 21 | #include "mowgli.h" 22 | 23 | #ifdef _WIN32 24 | 25 | int 26 | inet_pton(int af, const char *src, void *dst) 27 | { 28 | struct sockaddr_storage ss; 29 | 30 | int size = sizeof(struct sockaddr_storage); 31 | char src_copy[INET6_ADDRSTRLEN + 1]; 32 | 33 | mowgli_strlcpy(src_copy, src, sizeof src_copy); 34 | 35 | if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *) &ss, &size) != SOCKET_ERROR) 36 | switch (af) 37 | { 38 | case AF_INET: 39 | *(struct in_addr *) dst = ((struct sockaddr_in *) &ss)->sin_addr; 40 | return 1; 41 | 42 | case AF_INET6: 43 | *(struct in6_addr *) dst = ((struct sockaddr_in6 *) &ss)->sin6_addr; 44 | return 1; 45 | 46 | default: 47 | return 0; 48 | } 49 | 50 | return -1; 51 | } 52 | 53 | const char * 54 | inet_ntop(int af, const void *addr, char *host, size_t hostlen) 55 | { 56 | struct sockaddr_storage ss; 57 | 58 | int size = sizeof(struct sockaddr_storage); 59 | 60 | ss.ss_family = af; 61 | 62 | switch (af) 63 | { 64 | case AF_INET: 65 | memcpy(&(((struct sockaddr_in *) &ss)->sin_addr), (struct in_addr *) addr, sizeof(struct in_addr)); 66 | break; 67 | 68 | case AF_INET6: 69 | memcpy(&(((struct sockaddr_in6 *) &ss)->sin6_addr), (struct in6_addr *) addr, sizeof(struct in6_addr)); 70 | break; 71 | 72 | default: 73 | return NULL; 74 | } 75 | 76 | if (WSAAddressToString((struct sockaddr *) &ss, size, 0, host, (LPDWORD) &hostlen) != SOCKET_ERROR) 77 | return host; 78 | 79 | return NULL; 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/libmowgli/platform/win32/pipe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * pipe.c: UNIX pipe emulation 4 | * 5 | * Copyright (c) 2012 TortoiseLabs, LLC. 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | #ifdef _WIN32 27 | int 28 | pipe(int pipefd[2]) 29 | { 30 | return socketpair(AF_INET, SOCK_STREAM, 0, pipefd); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/libmowgli/platform/win32/setenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * setenv.c: setenv() wrapper around SetEnvironmentVariable(). 4 | * 5 | * Copyright (c) 2012 TortoiseLabs, LLC. 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | 26 | #ifdef _WIN32 27 | int 28 | setenv(const char *name, const char *value, int overwrite) 29 | { 30 | return !SetEnvironmentVariable(name, value); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/libmowgli/platform/win32/win32_stdinc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * win32_stdinc.h: Support functions and values for Win32 platform. 4 | * 5 | * Copyright (c) 2009 SystemInPlace, Inc. 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_PLATFORM_WIN32_WIN32_STDINC_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_PLATFORM_WIN32_WIN32_STDINC_H_INCLUDE_GUARD 1 26 | 27 | #ifdef _WIN32 28 | # include 29 | # include 30 | # include 31 | # define strcasecmp _stricmp 32 | # define strdup _strdup 33 | # ifdef _MSC_VER 34 | # define snprintf _snprintf 35 | # endif 36 | 37 | extern int setenv(const char *name, const char *value, int overwrite); 38 | 39 | extern int pipe(int pipefd[2]); 40 | extern int socketpair(int domain, int type, int protocol, int pipefd[2]); 41 | extern int fork(void); 42 | extern int inet_pton(int af, const char *src, void *dst); 43 | extern const char *inet_ntop(int af, const void *addr, char *host, size_t hostlen); 44 | 45 | /* MSYS autoconf is fucko. */ 46 | # ifndef HAVE_WINSOCK2_H 47 | # define HAVE_WINSOCK2_H 48 | # endif 49 | # define HAVE_SELECT 50 | 51 | #endif 52 | 53 | #endif /* MOWGLI_SRC_LIBMOWGLI_PLATFORM_WIN32_WIN32_STDINC_H_INCLUDE_GUARD */ 54 | -------------------------------------------------------------------------------- /src/libmowgli/thread/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_THREAD} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_THREAD} 5 | 6 | SRCS = mutex.c \ 7 | null_mutexops.c \ 8 | posix_mutexops.c \ 9 | win32_mutexops.c 10 | 11 | INCLUDES = thread.h mutex.h 12 | 13 | include ../../../buildsys.mk 14 | 15 | includesubdir = $(PACKAGE_NAME)/thread 16 | 17 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 18 | 19 | -------------------------------------------------------------------------------- /src/libmowgli/thread/mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * mutex.c: Cross-platform mutexes. 4 | * 5 | * Copyright (c) 2011 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "thread/mutex_internal.h" 26 | 27 | static const mowgli_mutex_ops_t *_mowgli_mutex_ops = NULL; 28 | 29 | static inline const mowgli_mutex_ops_t * 30 | get_mutex_platform(void) 31 | { 32 | /* allow for threading policy to set custom mutex ops */ 33 | if (_mowgli_mutex_ops != NULL) 34 | return _mowgli_mutex_ops; 35 | 36 | #if defined(_WIN32) 37 | return &_mowgli_win32_mutex_ops; 38 | #endif 39 | 40 | #if !defined(MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES) 41 | return &_mowgli_posix_mutex_ops; 42 | #endif 43 | 44 | return &_mowgli_null_mutex_ops; 45 | } 46 | 47 | mowgli_mutex_t * 48 | mowgli_mutex_create(void) 49 | { 50 | mowgli_mutex_t *mutex = mowgli_alloc(sizeof *mutex); 51 | 52 | return_val_if_fail(mutex != NULL, NULL); 53 | 54 | if (mowgli_mutex_init(mutex)) 55 | { 56 | return mutex; 57 | } 58 | else 59 | { 60 | mowgli_free(mutex); 61 | return NULL; 62 | } 63 | } 64 | 65 | int 66 | mowgli_mutex_init(mowgli_mutex_t *mutex) 67 | { 68 | return_val_if_fail(mutex != NULL, -1); 69 | 70 | mutex->ops = get_mutex_platform(); 71 | 72 | return mutex->ops->mutex_create(mutex); 73 | } 74 | 75 | int 76 | mowgli_mutex_lock(mowgli_mutex_t *mutex) 77 | { 78 | return_val_if_fail(mutex != NULL, -1); 79 | return_val_if_fail(mutex->ops != NULL, -1); 80 | 81 | return mutex->ops->mutex_lock(mutex); 82 | } 83 | 84 | int 85 | mowgli_mutex_trylock(mowgli_mutex_t *mutex) 86 | { 87 | return_val_if_fail(mutex != NULL, -1); 88 | return_val_if_fail(mutex->ops != NULL, -1); 89 | 90 | return mutex->ops->mutex_trylock(mutex); 91 | } 92 | 93 | int 94 | mowgli_mutex_unlock(mowgli_mutex_t *mutex) 95 | { 96 | return_val_if_fail(mutex != NULL, -1); 97 | return_val_if_fail(mutex->ops != NULL, -1); 98 | 99 | return mutex->ops->mutex_unlock(mutex); 100 | } 101 | 102 | int 103 | mowgli_mutex_uninit(mowgli_mutex_t *mutex) 104 | { 105 | return_val_if_fail(mutex != NULL, -1); 106 | return_val_if_fail(mutex->ops != NULL, -1); 107 | 108 | return mutex->ops->mutex_destroy(mutex); 109 | } 110 | 111 | void 112 | mowgli_mutex_destroy(mowgli_mutex_t *mutex) 113 | { 114 | return_if_fail(mutex != NULL); 115 | 116 | mowgli_mutex_uninit(mutex); 117 | mowgli_free(mutex); 118 | } 119 | 120 | void 121 | mowgli_mutex_set_policy(mowgli_thread_policy_t policy) 122 | { 123 | switch (policy) 124 | { 125 | case MOWGLI_THREAD_POLICY_DISABLED: 126 | _mowgli_mutex_ops = &_mowgli_null_mutex_ops; 127 | break; 128 | case MOWGLI_THREAD_POLICY_DEFAULT: 129 | default: 130 | _mowgli_mutex_ops = NULL; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/libmowgli/thread/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * mutex.h: Cross-platform mutexes. 4 | * 5 | * Copyright (c) 2011 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_THREAD_MUTEX_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_THREAD_MUTEX_H_INCLUDE_GUARD 1 26 | 27 | #include "platform/attributes.h" 28 | #include "thread/thread.h" 29 | 30 | #ifdef MOWGLI_OS_UNIX_TYPE 31 | # include 32 | # include 33 | # define MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES 34 | # define MOWGLI_NATIVE_MUTEX_DECL(name) mutex_t(name) 35 | #elif defined MOWGLI_OS_WIN 36 | # define MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES 37 | # define MOWGLI_NATIVE_MUTEX_DECL(name) HANDLE(name) 38 | #else 39 | # include 40 | #endif 41 | 42 | typedef struct mowgli_mutex_ mowgli_mutex_t; 43 | 44 | typedef struct 45 | { 46 | int (*mutex_create)(mowgli_mutex_t *mutex); 47 | int (*mutex_lock)(mowgli_mutex_t *mutex); 48 | int (*mutex_trylock)(mowgli_mutex_t *mutex); 49 | int (*mutex_unlock)(mowgli_mutex_t *mutex); 50 | int (*mutex_destroy)(mowgli_mutex_t *mutex); 51 | } mowgli_mutex_ops_t; 52 | 53 | struct mowgli_mutex_ 54 | { 55 | #ifdef MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES 56 | MOWGLI_NATIVE_MUTEX_DECL(mutex); 57 | #else 58 | pthread_mutex_t mutex; 59 | #endif 60 | const mowgli_mutex_ops_t *ops; 61 | }; 62 | 63 | #ifdef MOWGLI_NATIVE_MUTEX_DECL 64 | # undef MOWGLI_NATIVE_MUTEX_DECL 65 | #endif 66 | 67 | mowgli_mutex_t *mowgli_mutex_create(void) 68 | MOWGLI_FATTR_MALLOC; 69 | 70 | int mowgli_mutex_init(mowgli_mutex_t *mutex); 71 | int mowgli_mutex_lock(mowgli_mutex_t *mutex); 72 | int mowgli_mutex_trylock(mowgli_mutex_t *mutex); 73 | int mowgli_mutex_unlock(mowgli_mutex_t *mutex); 74 | int mowgli_mutex_uninit(mowgli_mutex_t *mutex); 75 | void mowgli_mutex_destroy(mowgli_mutex_t *mutex); 76 | 77 | void mowgli_mutex_set_policy(mowgli_thread_policy_t policy); 78 | 79 | /* simple dispatch function to set the ops up for the various subsystems. */ 80 | static inline void 81 | mowgli_thread_set_policy(mowgli_thread_policy_t policy) 82 | { 83 | mowgli_mutex_set_policy(policy); 84 | } 85 | 86 | #endif /* MOWGLI_SRC_LIBMOWGLI_THREAD_MUTEX_H_INCLUDE_GUARD */ 87 | -------------------------------------------------------------------------------- /src/libmowgli/thread/mutex_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * mutex.h: Cross-platform mutexes. 4 | * 5 | * Copyright (c) 2011 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #ifndef MOWGLI_SRC_LIBMOWGLI_THREAD_MUTEX_INTERNAL_H_INCLUDE_GUARD 25 | #define MOWGLI_SRC_LIBMOWGLI_THREAD_MUTEX_INTERNAL_H_INCLUDE_GUARD 1 26 | 27 | #include "platform/autoconf.h" 28 | #include "thread/mutex.h" 29 | 30 | #ifdef _WIN32 31 | extern const mowgli_mutex_ops_t _mowgli_win32_mutex_ops; 32 | #else 33 | extern const mowgli_mutex_ops_t _mowgli_posix_mutex_ops; 34 | #endif 35 | 36 | extern const mowgli_mutex_ops_t _mowgli_null_mutex_ops; 37 | 38 | #endif /* MOWGLI_SRC_LIBMOWGLI_THREAD_MUTEX_INTERNAL_H_INCLUDE_GUARD */ 39 | -------------------------------------------------------------------------------- /src/libmowgli/thread/null_mutexops.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * null_mutexops.c: null mutex operations 4 | * 5 | * Copyright (c) 2011 William Pitcock 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "thread/mutex_internal.h" 26 | 27 | static int 28 | mowgli_null_mutex_create(mowgli_mutex_t *mutex) 29 | { 30 | return 0; 31 | } 32 | 33 | static int 34 | mowgli_null_mutex_lock(mowgli_mutex_t *mutex) 35 | { 36 | return 0; 37 | } 38 | 39 | static int 40 | mowgli_null_mutex_trylock(mowgli_mutex_t *mutex) 41 | { 42 | return 0; 43 | } 44 | 45 | static int 46 | mowgli_null_mutex_unlock(mowgli_mutex_t *mutex) 47 | { 48 | return 0; 49 | } 50 | 51 | static int 52 | mowgli_null_mutex_destroy(mowgli_mutex_t *mutex) 53 | { 54 | return 0; 55 | } 56 | 57 | const mowgli_mutex_ops_t _mowgli_null_mutex_ops = 58 | { 59 | .mutex_create = mowgli_null_mutex_create, 60 | .mutex_lock = mowgli_null_mutex_lock, 61 | .mutex_trylock = mowgli_null_mutex_trylock, 62 | .mutex_unlock = mowgli_null_mutex_unlock, 63 | .mutex_destroy = mowgli_null_mutex_destroy 64 | }; 65 | -------------------------------------------------------------------------------- /src/libmowgli/thread/posix_mutexops.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * posix_mutexops.c: POSIX Mutexes. 4 | * 5 | * Copyright (c) 2011 Wilcox Technologies, LLC 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "thread/mutex_internal.h" 26 | 27 | #ifndef _WIN32 28 | 29 | /************* 30 | * This "default" implementation uses pthreads. Care has been taken to 31 | * ensure it runs on POSIX 1003.4a (draft 4, aka DECthreads, aka what OSF/1, 32 | * Tru64, Ultrix, CMU Mach, and HP-UX use) as well as POSIX 1003.1c-1995. 33 | * As long as you don't try playing with the pthread_attr module or the 34 | * scheduler routines (which are non-standard and broken anyway, IMO) then 35 | * it should be relatively easy to maintian d4 compatibility without 36 | * sacrificing any functionality. 37 | *************/ 38 | # if !defined(MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES) 39 | 40 | static int 41 | mowgli_posix_mutex_create(mowgli_mutex_t *mutex) 42 | { 43 | return pthread_mutex_init(&mutex->mutex, NULL); 44 | } 45 | 46 | static int 47 | mowgli_posix_mutex_lock(mowgli_mutex_t *mutex) 48 | { 49 | return pthread_mutex_lock(&mutex->mutex); 50 | } 51 | 52 | static int 53 | mowgli_posix_mutex_trylock(mowgli_mutex_t *mutex) 54 | { 55 | return pthread_mutex_trylock(&mutex->mutex); 56 | } 57 | 58 | static int 59 | mowgli_posix_mutex_unlock(mowgli_mutex_t *mutex) 60 | { 61 | return pthread_mutex_unlock(&mutex->mutex); 62 | } 63 | 64 | static int 65 | mowgli_posix_mutex_destroy(mowgli_mutex_t *mutex) 66 | { 67 | return pthread_mutex_destroy(&mutex->mutex); 68 | } 69 | 70 | const mowgli_mutex_ops_t _mowgli_posix_mutex_ops = 71 | { 72 | .mutex_create = mowgli_posix_mutex_create, 73 | .mutex_lock = mowgli_posix_mutex_lock, 74 | .mutex_trylock = mowgli_posix_mutex_trylock, 75 | .mutex_unlock = mowgli_posix_mutex_unlock, 76 | .mutex_destroy = mowgli_posix_mutex_destroy, 77 | }; 78 | 79 | # endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/libmowgli/thread/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * thread.h: Cross-platform threading helper routines. 4 | * 5 | * Copyright (c) 2011 Wilcox Technologies, LLC 6 | * Copyright (c) 2011, 2012 William Pitcock 7 | * 8 | * Permission to use, copy, modify, and/or distribute this software for any 9 | * purpose with or without fee is hereby granted, provided that the above 10 | * copyright notice and this permission notice is present in all copies. 11 | * 12 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 13 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 16 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 20 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 21 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 | * POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #ifndef MOWGLI_SRC_LIBMOWGLI_THREAD_THREAD_H_INCLUDE_GUARD 26 | #define MOWGLI_SRC_LIBMOWGLI_THREAD_THREAD_H_INCLUDE_GUARD 1 27 | 28 | #ifdef MOWGLI_OS_UNIX_TYPE 29 | # include 30 | # define MOWGLI_FEATURE_HAVE_NATIVE_THREADS 31 | # ifdef MOWGLI_OS_THREADS_SOLARIS 32 | # define MOWGLI_NATIVE_THREAD_DECL(name) pthread_t(name) 33 | # else 34 | # define MOWGLI_NATIVE_THREAD_DECL(name) thread_t(name) 35 | # endif 36 | #else 37 | # if defined MOWGLI_OS_WIN 38 | # define MOWGLI_FEATURE_HAVE_NATIVE_THREADS 39 | # define MOWGLI_NATIVE_THREAD_DECL(name) HANDLE(name) 40 | # else 41 | # include 42 | # endif 43 | #endif 44 | 45 | typedef struct 46 | { 47 | #ifdef MOWGLI_FEATURE_HAVE_NATIVE_THREADS 48 | MOWGLI_NATIVE_THREAD_DECL(thread); 49 | #else 50 | pthread_t thread; 51 | #endif 52 | } mowgli_thread_t; 53 | 54 | #ifdef MOWGLI_NATIVE_THREAD_DECL 55 | # undef MOWGLI_NATIVE_THREAD_DECL 56 | #endif 57 | 58 | typedef void *(*mowgli_thread_start_fn_t)(mowgli_thread_t *thread, void *userdata); 59 | 60 | /* 61 | * Note: we should keep our thread interface light and minimal for best possible 62 | * portability. Creating, ending, killing and cleanup functions are presently implemented, 63 | * and cover approximately 99.999% of uses of thread APIs. --nenolod 64 | */ 65 | typedef struct 66 | { 67 | int (*thread_create)(mowgli_thread_t *thread, mowgli_thread_start_fn_t start_fn, void *userdata); 68 | void (*thread_exit)(mowgli_thread_t *thread); 69 | void *(*thread_join)(mowgli_thread_t * thread); 70 | void (*thread_kill)(mowgli_thread_t *thread); 71 | void (*thread_destroy)(mowgli_thread_t *thread); 72 | } mowgli_thread_ops_t; 73 | 74 | int mowgli_thread_create(mowgli_thread_t *thread, mowgli_thread_start_fn_t start_fn, void *userdata); 75 | void mowgli_thread_exit(mowgli_thread_t *thread); 76 | void *mowgli_thread_join(mowgli_thread_t *thread); 77 | void mowgli_thread_kill(mowgli_thread_t *thread); 78 | void mowgli_thread_destroy(mowgli_thread_t *thread); 79 | 80 | typedef enum 81 | { 82 | MOWGLI_THREAD_POLICY_DEFAULT, 83 | MOWGLI_THREAD_POLICY_DISABLED, 84 | } mowgli_thread_policy_t; 85 | 86 | #endif /* MOWGLI_SRC_LIBMOWGLI_THREAD_THREAD_H_INCLUDE_GUARD */ 87 | -------------------------------------------------------------------------------- /src/libmowgli/thread/win32_mutexops.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libmowgli: A collection of useful routines for programming. 3 | * win32_mutexops.c: Windows mutex operations 4 | * 5 | * Copyright (c) 2011 Wilcox Technologies, LLC 6 | * 7 | * Permission to use, copy, modify, and/or distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice is present in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | * POSSIBILITY OF SUCH DAMAGE. 22 | */ 23 | 24 | #include "mowgli.h" 25 | #include "thread/mutex_internal.h" 26 | 27 | /************* 28 | * This Windows implementation is guaranteed to work on Windows 95, 29 | * Windows NT 4, and anything later. 30 | *************/ 31 | #if defined(_WIN32) 32 | 33 | static int 34 | mowgli_win32_mutex_create(mowgli_mutex_t *mutex) 35 | { 36 | mutex->mutex = CreateMutex(NULL, FALSE, NULL); 37 | 38 | if (mutex->mutex == NULL) 39 | return GetLastError(); 40 | 41 | return 0; 42 | } 43 | 44 | static int 45 | mowgli_win32_mutex_lock(mowgli_mutex_t *mutex) 46 | { 47 | return WaitForSingleObject(mutex->mutex, INFINITE); 48 | } 49 | 50 | static int 51 | mowgli_win32_mutex_trylock(mowgli_mutex_t *mutex) 52 | { 53 | return WaitForSingleObject(mutex->mutex, 0); 54 | } 55 | 56 | static int 57 | mowgli_win32_mutex_unlock(mowgli_mutex_t *mutex) 58 | { 59 | if (ReleaseMutex(mutex->mutex) != 0) 60 | return 0; 61 | 62 | return GetLastError(); 63 | } 64 | 65 | static int 66 | mowgli_win32_mutex_destroy(mowgli_mutex_t *mutex) 67 | { 68 | CloseHandle(mutex->mutex); 69 | return 0; 70 | } 71 | 72 | const mowgli_mutex_ops_t _mowgli_win32_mutex_ops = 73 | { 74 | .mutex_create = mowgli_win32_mutex_create, 75 | .mutex_lock = mowgli_win32_mutex_lock, 76 | .mutex_trylock = mowgli_win32_mutex_trylock, 77 | .mutex_unlock = mowgli_win32_mutex_unlock, 78 | .mutex_destroy = mowgli_win32_mutex_destroy 79 | }; 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/libmowgli/vio/Makefile: -------------------------------------------------------------------------------- 1 | include ../../../extra.mk 2 | 3 | STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_VIO} 4 | STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_VIO} 5 | 6 | SRCS = vio.c vio_sockets.c vio_openssl.c 7 | 8 | INCLUDES = vio.h 9 | 10 | include ../../../buildsys.mk 11 | 12 | includesubdir = $(PACKAGE_NAME)/vio 13 | 14 | CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE 15 | 16 | --------------------------------------------------------------------------------