├── .gitignore ├── .travis.yml ├── AUTHORS ├── COPYING ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── README.markdown ├── TODO ├── autogen.sh ├── configure.ac ├── m4 ├── ac_check_yajl.m4 ├── libtool.m4 ├── ltoptions.m4 ├── ltsugar.m4 ├── ltversion.m4 └── lt~obsolete.m4 ├── pincaster.conf ├── src ├── Makefile.am ├── app.c ├── app_config.c ├── app_config.h ├── common.h ├── cqueue.c ├── cqueue.h ├── db_log.c ├── db_log.h ├── domain_layers.c ├── domain_layers.h ├── domain_records.c ├── domain_records.h ├── domain_search.c ├── domain_search.h ├── domain_system.c ├── domain_system.h ├── expirables.c ├── expirables.h ├── ext │ ├── Makefile.am │ ├── queue.h │ └── tree.h ├── handle_consumer_ops.c ├── handle_consumer_ops.h ├── http_server.c ├── http_server.h ├── key_nodes.c ├── key_nodes.h ├── keys.c ├── keys.h ├── levent2 │ ├── .gitignore │ ├── CMakeLists.txt │ ├── CONTRIBUTING.md │ ├── CONTRIBUTORS.md │ ├── ChangeLog │ ├── ChangeLog-1.4 │ ├── ChangeLog-2.0 │ ├── Documentation │ │ └── Building.md │ ├── Doxyfile │ ├── LICENSE │ ├── Makefile.am │ ├── README.md │ ├── WIN32-Code │ │ ├── getopt.c │ │ ├── getopt.h │ │ ├── getopt_long.c │ │ └── tree.h │ ├── arc4random.c │ ├── autogen.sh │ ├── buffer.c │ ├── buffer_iocp.c │ ├── bufferevent-internal.h │ ├── bufferevent.c │ ├── bufferevent_async.c │ ├── bufferevent_filter.c │ ├── bufferevent_mbedtls.c │ ├── bufferevent_openssl.c │ ├── bufferevent_pair.c │ ├── bufferevent_ratelim.c │ ├── bufferevent_sock.c │ ├── bufferevent_ssl.c │ ├── build-aux │ │ └── test-driver │ ├── changelist-internal.h │ ├── checkpatch.sh │ ├── cmake │ │ ├── COPYING-CMAKE-SCRIPTS │ │ ├── CheckFileOffsetBits.c │ │ ├── CheckPrototypeDefinition.c.in │ │ ├── Copyright.txt │ │ ├── LibeventConfig.cmake.in │ │ ├── LibeventConfigVersion.cmake.in │ │ └── Uninstall.cmake.in │ ├── compat │ │ └── sys │ │ │ └── queue.h │ ├── configure.ac │ ├── defer-internal.h │ ├── devpoll.c │ ├── doxygen.am │ ├── epoll.c │ ├── epoll_sub.c │ ├── epolltable-internal.h │ ├── evbuffer-internal.h │ ├── evconfig-private.h.in │ ├── evdns.c │ ├── event-internal.h │ ├── event.c │ ├── event_iocp.c │ ├── event_rpcgen.py │ ├── event_tagging.c │ ├── evmap-internal.h │ ├── evmap.c │ ├── evport.c │ ├── evrpc-internal.h │ ├── evrpc.c │ ├── evsignal-internal.h │ ├── evthread-internal.h │ ├── evthread.c │ ├── evthread_pthread.c │ ├── evthread_win32.c │ ├── evutil.c │ ├── evutil_rand.c │ ├── evutil_time.c │ ├── extra │ │ ├── abi-check │ │ │ ├── README.md │ │ │ ├── abi_check.sh │ │ │ └── libevent.json │ │ ├── lsan.supp │ │ └── tsan.supp │ ├── ht-internal.h │ ├── http-internal.h │ ├── http.c │ ├── include │ │ ├── evdns.h │ │ ├── event.h │ │ ├── event2 │ │ │ ├── buffer.h │ │ │ ├── buffer_compat.h │ │ │ ├── bufferevent.h │ │ │ ├── bufferevent_compat.h │ │ │ ├── bufferevent_ssl.h │ │ │ ├── bufferevent_struct.h │ │ │ ├── dns.h │ │ │ ├── dns_compat.h │ │ │ ├── dns_struct.h │ │ │ ├── event.h │ │ │ ├── event_compat.h │ │ │ ├── event_struct.h │ │ │ ├── http.h │ │ │ ├── http_compat.h │ │ │ ├── http_struct.h │ │ │ ├── keyvalq_struct.h │ │ │ ├── listener.h │ │ │ ├── rpc.h │ │ │ ├── rpc_compat.h │ │ │ ├── rpc_struct.h │ │ │ ├── tag.h │ │ │ ├── tag_compat.h │ │ │ ├── thread.h │ │ │ ├── util.h │ │ │ ├── visibility.h │ │ │ └── watch.h │ │ ├── evhttp.h │ │ ├── evrpc.h │ │ ├── evutil.h │ │ └── include.am │ ├── iocp-internal.h │ ├── ipv6-internal.h │ ├── kqueue-internal.h │ ├── kqueue.c │ ├── libevent.pc.in │ ├── libevent_core.pc.in │ ├── libevent_extra.pc.in │ ├── libevent_mbedtls.pc.in │ ├── libevent_openssl.pc.in │ ├── libevent_pthreads.pc.in │ ├── listener.c │ ├── log-internal.h │ ├── log.c │ ├── m4 │ │ ├── ac_backport_259_ssizet.m4 │ │ ├── ax_check_compile_flag.m4 │ │ ├── ax_check_funcs_ex.m4 │ │ ├── ax_prog_doxygen.m4 │ │ ├── ax_pthread.m4 │ │ ├── libevent_mbedtls.m4 │ │ └── libevent_openssl.m4 │ ├── make-event-config.sed │ ├── make_epoll_table.py │ ├── mbedtls-compat.h │ ├── minheap-internal.h │ ├── mm-internal.h │ ├── openssl-compat.h │ ├── poll.c │ ├── ratelim-internal.h │ ├── sample │ │ ├── becat.c │ │ ├── dns-example.c │ │ ├── event-read-fifo.c │ │ ├── hello-world.c │ │ ├── hostcheck.c │ │ ├── hostcheck.h │ │ ├── http-connect.c │ │ ├── http-server.c │ │ ├── https-client.c │ │ ├── include.am │ │ ├── le-proxy.c │ │ ├── openssl_hostname_validation.c │ │ ├── openssl_hostname_validation.h │ │ ├── signal-test.c │ │ ├── ssl-client-mbedtls.c │ │ ├── time-test.c │ │ └── watch-timing.c │ ├── select.c │ ├── signal.c │ ├── ssl-compat.h │ ├── strlcpy-internal.h │ ├── strlcpy.c │ ├── test-export │ │ ├── CMakeLists.txt │ │ ├── test-export.c │ │ └── test-export.py │ ├── test │ │ ├── bench.c │ │ ├── bench_cascade.c │ │ ├── bench_http.c │ │ ├── bench_httpclient.c │ │ ├── check-dumpevents.py │ │ ├── include.am │ │ ├── print-winsock-errors.c │ │ ├── regress.c │ │ ├── regress.h │ │ ├── regress.rpc │ │ ├── regress_buffer.c │ │ ├── regress_bufferevent.c │ │ ├── regress_dns.c │ │ ├── regress_et.c │ │ ├── regress_finalize.c │ │ ├── regress_http.c │ │ ├── regress_iocp.c │ │ ├── regress_listener.c │ │ ├── regress_main.c │ │ ├── regress_mbedtls.c │ │ ├── regress_minheap.c │ │ ├── regress_openssl.c │ │ ├── regress_rpc.c │ │ ├── regress_ssl.c │ │ ├── regress_testutils.c │ │ ├── regress_testutils.h │ │ ├── regress_thread.c │ │ ├── regress_thread.h │ │ ├── regress_util.c │ │ ├── regress_watch.c │ │ ├── regress_zlib.c │ │ ├── rpcgen_wrapper.sh │ │ ├── test-changelist.c │ │ ├── test-closed.c │ │ ├── test-dumpevents.c │ │ ├── test-eof.c │ │ ├── test-fdleak.c │ │ ├── test-init.c │ │ ├── test-ratelim.c │ │ ├── test-ratelim.sh │ │ ├── test-time.c │ │ ├── test-weof.c │ │ ├── test.sh │ │ ├── tinytest.c │ │ ├── tinytest.h │ │ ├── tinytest_demo.c │ │ ├── tinytest_local.h │ │ └── tinytest_macros.h │ ├── time-internal.h │ ├── util-internal.h │ ├── watch.c │ ├── wepoll.c │ ├── wepoll.h │ ├── whatsnew-2.0.txt │ ├── whatsnew-2.1.txt │ ├── whatsnew-2.2.txt │ └── win32select.c ├── log.c ├── log.h ├── pandb.c ├── pandb.h ├── parser.c ├── parser.h ├── parser_p.h ├── public.c ├── public.h ├── query_parser.c ├── query_parser.h ├── replication_master.c ├── replication_master.h ├── replication_slave.c ├── replication_slave.h ├── slab.c ├── slab.h ├── slab_p.h ├── slipmap.c ├── slipmap.h ├── stack.c ├── stack.h ├── utils.c ├── utils.h └── yajl │ ├── .gitignore │ ├── COPYING │ ├── Makefile.am │ ├── api │ ├── .gitignore │ ├── Makefile.am │ ├── yajl_common.h │ ├── yajl_gen.h │ ├── yajl_parse.h │ ├── yajl_tree.h │ └── yajl_version.h │ ├── yajl.c │ ├── yajl_alloc.c │ ├── yajl_alloc.h │ ├── yajl_buf.c │ ├── yajl_buf.h │ ├── yajl_bytestack.h │ ├── yajl_encode.c │ ├── yajl_encode.h │ ├── yajl_gen.c │ ├── yajl_lex.c │ ├── yajl_lex.h │ ├── yajl_parser.c │ ├── yajl_parser.h │ ├── yajl_tree.c │ └── yajl_version.c ├── test-driver └── test ├── Rakefile ├── features ├── layer.feature ├── public.feature ├── record.feature ├── search.feature ├── step_definitions │ └── pincaster.rb └── system.feature ├── pincaster.conf ├── test_utils.c └── tests.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.cmake 2 | *.log 3 | *.scan 4 | *.status 5 | *.tar.* 6 | *~ 7 | INSTALL 8 | Makefile 9 | Makefile.in 10 | aclocal.m4 11 | autom4te.cache 12 | compile 13 | confdefs.h 14 | config.* 15 | configure 16 | depcomp 17 | install-sh 18 | ltmain.sh 19 | missing 20 | src/*.dSYM 21 | src/*.o 22 | src/.deps 23 | src/Makefile.in 24 | src/ext/Makefile.in 25 | src/levent2/doxygen 26 | src/levent2/m4/libtool.m4 27 | src/levent2/m4/lt*.m4 28 | src/pincaster 29 | src/yajl/*.o 30 | src/yajl/.deps 31 | stamp-* 32 | testing 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - clang 5 | - gcc 6 | 7 | before_script: 8 | - ./autogen.sh 9 | - ./configure --disable-dependency-tracking 10 | 11 | script: make 12 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Frank DENIS 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | Pincaster is covered by the following license : 3 | 4 | /* 5 | * Copyright (c) 2010-2025 6 | * Frank Denis 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 appear in all copies. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 | */ 20 | 21 | For conveniency, this package also includes possibly modified versions 22 | of libevent, yajl, and OpenBSD tree.h / queue.h headers whose original 23 | licenses are included in their respective directories. 24 | 25 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jedisct1/Pincaster/ce43cbefb14078ec5cdcfc7050f23aed6c4248e9/ChangeLog -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | AUTOMAKE_OPTIONS = gnu 4 | 5 | dist_doc_DATA = README.markdown 6 | 7 | SUBDIRS = \ 8 | src 9 | 10 | EXTRA_DIST = \ 11 | pincaster.conf 12 | 13 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jedisct1/Pincaster/ce43cbefb14078ec5cdcfc7050f23aed6c4248e9/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | See README.markdown 2 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | - Rewrite URI handling code. 3 | 4 | - Authentication. 5 | 6 | - Tuneable HTTP cache control. 7 | 8 | - Handle clusterized geographic results for point+radius search. 9 | 10 | - Ajust the coordinates of cluster results according to the number of 11 | children of the quad node. 12 | 13 | - Write tests. 14 | 15 | - Replace pointers + size and stringz with binvals. 16 | 17 | - Drop the global rwlock for layer-specific rwlocks. 18 | 19 | - Drop pthread rwlocks for fcfs rwlocks. 20 | 21 | - Add configuration to the journal at startup time. 22 | 23 | - Multiget. 24 | 25 | - Get rid of the remaining fixed-size malloc() calls and use slab allocation. 26 | 27 | - Replication. 28 | 29 | - Scripting through TinyScheme, LUA or Spidermonkey. 30 | 31 | - Decent documentation. 32 | 33 | - Long-polling HTTP notification service for tracking changes in registered 34 | layers and rectangles. 35 | 36 | - Proxy for easy sharding and caching. 37 | 38 | - rewriteaof should compress the journal. New operations would happen 39 | on a second, uncompressed journal. 40 | 41 | - Support for reverse geocoding (find what convex polygon a point is in). 42 | 43 | - Use zero-copy when serving public documents. 44 | 45 | - Eradicate app_context. db_log should especially join httpcontext. 46 | 47 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | glibtoolize --copy --install || libtoolize --copy --install 4 | autoheader -I m4 && \ 5 | aclocal -I m4 && \ 6 | automake --add-missing --force-missing --include-deps && \ 7 | autoconf 8 | -------------------------------------------------------------------------------- /m4/ac_check_yajl.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # 3 | # SYNOPSIS 4 | # 5 | # AC_CHECK_YAJL([action-if-found], [action-if-not-found]) 6 | # 7 | # DESCRIPTION 8 | # 9 | # Tests for the YAJL library. 10 | # 11 | # This macro calls: 12 | # 13 | # AC_SUBST(YAJL_CFLAGS) / AC_SUBST(YAJL_LIBS) 14 | # 15 | # LAST MODIFICATION 16 | # 17 | # 2010-06-29 18 | # 19 | # LICENSE 20 | # 21 | # Copyright (c) 2010 Cristian Greco 22 | # 23 | # Copying and distribution of this file, with or without modification, are 24 | # permitted in any medium without royalty provided the copyright notice 25 | # and this notice are preserved. 26 | 27 | AC_DEFUN([AC_CHECK_YAJL], [ 28 | ac_yajl_found="no" 29 | 30 | CPPFLAGS_SAVED="$CPPFLAGS" 31 | LDFLAGS_SAVED="$LDFLAGS" 32 | CFLAGS_SAVED="$CFLAGS" 33 | LIBS_SAVED="$LIBS" 34 | 35 | AC_CHECK_HEADER([yajl/yajl_tree.h], [ 36 | AC_CHECK_LIB([yajl], [yajl_tree_parse], [ 37 | YAJL_CFLAGS="-I/usr/include/yajl" 38 | YAJL_LIBS="-lyajl" 39 | ac_yajl_found="yes" 40 | ], [ 41 | AC_MSG_WARN([yajl library not found]) 42 | ]) 43 | ], [ 44 | for ac_yajl_path in /usr /usr/local /opt /opt/local; do 45 | AC_MSG_CHECKING([for yajl_parse.h in $ac_yajl_path]) 46 | if test -d "$ac_yajl_path/include/yajl/" -a -r "$ac_yajl_path/include/yajl/yajl_parse.h"; then 47 | AC_MSG_RESULT([yes]) 48 | YAJL_CFLAGS="-I$ac_yajl_path/include/yajl" 49 | YAJL_LIBS="-lyajl" 50 | break; 51 | else 52 | AC_MSG_RESULT([no]) 53 | fi 54 | done 55 | 56 | CFLAGS="YAJL_CFLAGS $CFLAGS" 57 | export CFLAGS 58 | LIBS="$YAJL_LIBS $LIBS" 59 | export LIBS 60 | 61 | AC_MSG_CHECKING([for yajl_gen_alloc in -lyajl]) 62 | AC_LINK_IFELSE([ 63 | AC_LANG_PROGRAM([[ #include ]], [[ yajl_gen g = yajl_gen_alloc(&conf, (void *)0); yajl_gen_config(g, yajl_gen_beautify, 1); ]]) 64 | ], [ 65 | AC_MSG_RESULT([yes]) 66 | ac_yajl_found="yes" 67 | ], [ 68 | AC_MSG_RESULT([no]) 69 | ]) 70 | ]) 71 | 72 | CPPFLAGS="$CPPFLAGS_SAVED" 73 | LDFLAGS="$LDFLAGS_SAVED" 74 | CFLAGS="$CFLAGS_SAVED" 75 | LIBS="$LIBS_SAVED" 76 | 77 | AS_IF([ test "x$ac_yajl_found" != xno ], [$1], [$2]) 78 | 79 | AC_SUBST([YAJL_CFLAGS]) 80 | AC_SUBST([YAJL_LIBS]) 81 | ]) 82 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2019, 2021-2022 Free Software Foundation, 4 | # Inc. 5 | # Written by Scott James Remnant, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # @configure_input@ 12 | 13 | # serial 4245 ltversion.m4 14 | # This file is part of GNU Libtool 15 | 16 | m4_define([LT_PACKAGE_VERSION], [2.4.7]) 17 | m4_define([LT_PACKAGE_REVISION], [2.4.7]) 18 | 19 | AC_DEFUN([LTVERSION_VERSION], 20 | [macro_version='2.4.7' 21 | macro_revision='2.4.7' 22 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 23 | _LT_DECL(, macro_revision, 0) 24 | ]) 25 | -------------------------------------------------------------------------------- /pincaster.conf: -------------------------------------------------------------------------------- 1 | 2 | ######################################### 3 | # # 4 | # Sample Pincaster configuration file # 5 | # # 6 | ######################################### 7 | 8 | 9 | # Number of workers threads. One per CPU core might not be a bad idea. 10 | 11 | Workers 2 12 | 13 | 14 | # The file name to save the database journal 15 | # You can comment this out if you want a memory-only database. 16 | 17 | DBFileName /var/db/pincaster/pincaster.db 18 | 19 | 20 | # Listen to this IP address. 21 | # Comment out to listen to * or leave 0.0.0.0 to listen to ipv4.* 22 | 23 | ServerIP 0.0.0.0 24 | 25 | 26 | # Listen to this port number 27 | 28 | ServerPort 4269 29 | 30 | 31 | # Run as a background process 32 | # If you need to kill the process, send a TERM signal, never pkill -9 33 | # unless you absolutely have to. 34 | 35 | Daemonize no 36 | 37 | 38 | # Log file - You should probably change this for a decent location 39 | # Comment out to log to stderr 40 | 41 | # LogFileName /tmp/pincaster.log 42 | 43 | 44 | # Client connection timeout 45 | 46 | Timeout 20 47 | 48 | 49 | # The default type of layer. 50 | # Should be one of: flat, flatwrap, spherical and ellipsoidal. 51 | 52 | DefaultLayerType ellipsoidal 53 | 54 | 55 | # The formula used for distance calculation in radius search. 56 | # In-rect search always uses rhomboid, the reference point 57 | # being the center of the rectangle. 58 | # Should be one of: vincenty, haversine, greatcircle, fast and rhomboid. 59 | 60 | Accuracy fast 61 | 62 | 63 | ############################################################# 64 | # Replication. # 65 | # Don't comment out unless you want to enable replication # 66 | ############################################################# 67 | 68 | 69 | # Replication IP address or host name we should bind as a master 70 | 71 | # ReplicationMasterIp 0.0.0.0 72 | 73 | 74 | # Replication TCP port we should listen to as a master 75 | 76 | # ReplicationMasterPort 4270 77 | 78 | 79 | # Replication IP address or host name of the master, if we are a slave 80 | 81 | # ReplicationSlaveOfIp 10.0.0.0 82 | 83 | 84 | # Replication TCP port of the master, if we are a slave 85 | 86 | # ReplicationSlaveOfPort 4270 87 | 88 | 89 | 90 | ############################################################# 91 | # You should probably not change anything below this line. # 92 | ############################################################# 93 | 94 | 95 | # fsync() every x seconds. 96 | # 0 means fsync() after every write. Safe, but slow. 97 | # -1 means no fsync() at all. 98 | 99 | FsyncPeriod 5 100 | 101 | 102 | # The journal write buffer size. 103 | 104 | JournalBufferSize 4096 105 | 106 | 107 | # The highest number of queued queries waiting for being processed. 108 | 109 | MaxQueuedReplies 10000 110 | 111 | 112 | # The bucket size, i.e. the max number of items in each node of the quadtree. 113 | # Ignored, for now. 114 | 115 | BucketSize 50 116 | 117 | 118 | # Nodes within this range will all be in the same bucket. 119 | 120 | DimensionAccuracy 0.0001 121 | 122 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pincaster_LDADD = \ 3 | levent2/.libs/libevent_core.a \ 4 | levent2/.libs/libevent_extra.a \ 5 | levent2/.libs/libevent_pthreads.a \ 6 | @YAJL_LDADD@ 7 | 8 | AM_CFLAGS = \ 9 | @YAJL_INCLUDE@ 10 | 11 | bin_PROGRAMS = \ 12 | pincaster 13 | 14 | pincaster_SOURCES = \ 15 | common.h \ 16 | ext/queue.h \ 17 | ext/tree.h \ 18 | app.c \ 19 | parser.c \ 20 | parser_p.h \ 21 | parser.h \ 22 | app_config.c \ 23 | app_config.h \ 24 | utils.c \ 25 | utils.h \ 26 | log.c \ 27 | log.h \ 28 | cqueue.c \ 29 | cqueue.h \ 30 | keys.c \ 31 | keys.h \ 32 | pandb.c \ 33 | pandb.h \ 34 | slab.c \ 35 | slab.h \ 36 | slab_p.h \ 37 | slipmap.c \ 38 | slipmap.h \ 39 | stack.c \ 40 | stack.h \ 41 | db_log.c \ 42 | db_log.h \ 43 | query_parser.c \ 44 | query_parser.h \ 45 | http_server.c \ 46 | http_server.h \ 47 | key_nodes.c \ 48 | key_nodes.h \ 49 | expirables.c \ 50 | expirables.h \ 51 | domain_system.c \ 52 | domain_system.h \ 53 | domain_layers.c \ 54 | domain_layers.h \ 55 | domain_records.c \ 56 | domain_records.h \ 57 | domain_search.c \ 58 | domain_search.h \ 59 | handle_consumer_ops.c \ 60 | handle_consumer_ops.h \ 61 | public.c \ 62 | public.h \ 63 | replication_master.c \ 64 | replication_master.h \ 65 | replication_slave.c \ 66 | replication_slave.h 67 | 68 | SUBDIRS = \ 69 | ext levent2 yajl 70 | -------------------------------------------------------------------------------- /src/app.c: -------------------------------------------------------------------------------- 1 | 2 | #define DEFINE_GLOBALS 1 3 | 4 | #include "common.h" 5 | #include "http_server.h" 6 | #include "app_config.h" 7 | 8 | static void usage(void) 9 | { 10 | puts("\nUsage: pincaster \n"); 11 | } 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | if (argc < 2) { 16 | usage(); 17 | return 1; 18 | } 19 | check_sys_config(); 20 | init_db_log(); 21 | if (parse_config(argv[1]) != 0) { 22 | return 2; 23 | } 24 | if (app_context.daemonize != 0 && do_daemonize() != 0) { 25 | return 3; 26 | } 27 | if (open_db_log() < 0) { 28 | return 4; 29 | } 30 | if (http_server() != 0) { 31 | return 5; 32 | } 33 | free_db_log(); 34 | free_config(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /src/app_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __APP_CONFIG_H__ 3 | #define __APP_CONFIG_H__ 1 4 | 5 | #ifndef NB_WORKERS 6 | # define NB_WORKERS 10U 7 | #endif 8 | #ifndef MAX_QUEUED_REPLIES 9 | # define MAX_QUEUED_REPLIES 10000U 10 | #endif 11 | #ifndef BUCKET_SIZE 12 | # define BUCKET_SIZE 50U 13 | #endif 14 | #ifndef DEFAULT_DIMENSION_ACCURACY 15 | # define DEFAULT_DIMENSION_ACCURACY ((Dimension) 0.001) 16 | #endif 17 | #ifndef DEFAULT_ACCURACY 18 | # define DEFAULT_ACCURACY ACCURACY_FAST 19 | #endif 20 | #ifndef DEFAULT_LAYER_TYPE 21 | # define DEFAULT_LAYER_TYPE LAYER_TYPE_ELLIPSOIDAL 22 | #endif 23 | #ifndef DEFAULT_SERVER_PORT 24 | # define DEFAULT_SERVER_PORT "4269" 25 | #endif 26 | #ifndef DEFAULT_REPLICATION_PORT 27 | # define DEFAULT_REPLICATION_PORT "4270" 28 | #endif 29 | #ifndef DEFAULT_CLIENT_TIMEOUT 30 | # define DEFAULT_CLIENT_TIMEOUT 60 31 | #endif 32 | #ifndef DEFAULT_JOURNAL_BUFFER_SIZE 33 | # define DEFAULT_JOURNAL_BUFFER_SIZE 4096U 34 | #endif 35 | #ifndef DEFAULT_FSYNC_PERIOD 36 | # define DEFAULT_FSYNC_PERIOD 5 37 | #endif 38 | 39 | #define PROJECTION 0 40 | 41 | int parse_config(const char * const file); 42 | int check_sys_config(void); 43 | void free_config(void); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __COMMON_H__ 3 | #define __COMMON_H__ 1 4 | 5 | #include 6 | 7 | #ifndef __GNUC__ 8 | # ifdef __attribute__ 9 | # undef __attribute__ 10 | # endif 11 | # define __attribute__(a) 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "ext/queue.h" 37 | #include "ext/tree.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include "app_config.h" 44 | #include "slab.h" 45 | #include "cqueue.h" 46 | #include "keys.h" 47 | #include "stack.h" 48 | #include "slipmap.h" 49 | #include "pandb.h" 50 | #include "key_nodes.h" 51 | #include "utils.h" 52 | #include "db_log.h" 53 | #include "log.h" 54 | 55 | #define INT_PROPERTY_COMMON_PREFIX '_' 56 | #define INT_PROPERTY_TYPE "_type" 57 | #define INT_PROPERTY_EXPIRES_AT "_expires_at" 58 | #define INT_PROPERTY_POSITION "_loc" 59 | #define INT_PROPERTY_DELETE_PREFIX "_delete:" 60 | #define INT_PROPERTY_DELETE_ALL_PREFIX "_delete_all" 61 | #define INT_PROPERTY_ADD_INT_PREFIX "_add_int:" 62 | #define INT_PROPERTY_CONTENT "$content" 63 | #define INT_PROPERTY_CONTENT_TYPE "$content_type" 64 | #define INT_PROPERTY_LINK "$link:" 65 | 66 | typedef struct AppContext_ { 67 | char *server_ip; 68 | char *server_port; 69 | char *replication_master_ip; 70 | char *replication_master_port; 71 | char *replication_slave_ip; 72 | char *replication_slave_port; 73 | _Bool daemonize; 74 | char *log_file_name; 75 | int timeout; 76 | unsigned int nb_workers; 77 | size_t max_queued_replies; 78 | LayerType default_layer_type; 79 | Accuracy default_accuracy; 80 | size_t bucket_size; 81 | Dimension dimension_accuracy; 82 | DBLog db_log; 83 | struct HttpHandlerContext_ *http_handler_context; 84 | } AppContext; 85 | 86 | #ifndef DEFINE_GLOBALS 87 | extern AppContext app_context; 88 | #else 89 | AppContext app_context; 90 | #endif 91 | 92 | #ifndef AUTOMATICALLY_CREATE_LAYERS 93 | # define AUTOMATICALLY_CREATE_LAYERS 0 94 | #endif 95 | 96 | #ifdef __APPLE_CC__ 97 | int fdatasync(int fd); 98 | #endif 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /src/cqueue.c: -------------------------------------------------------------------------------- 1 | 2 | #include "common.h" 3 | #include "cqueue.h" 4 | 5 | int init_cqueue(CQueue * const cqueue, const size_t nb_elements, 6 | const size_t element_size) 7 | { 8 | size_t cqueue_size; 9 | 10 | if (nb_elements < (size_t) 2U || SIZE_MAX / nb_elements < element_size) { 11 | return -1; 12 | } 13 | cqueue->element_size = element_size; 14 | cqueue_size = nb_elements * element_size; 15 | if ((cqueue->cqueue = malloc(cqueue_size)) == NULL) { 16 | return -1; 17 | } 18 | cqueue->cqueue_end = cqueue->cqueue + (cqueue_size - element_size); 19 | cqueue->first_element = cqueue->last_element = NULL; 20 | 21 | return 0; 22 | } 23 | 24 | void free_cqueue(CQueue * const cqueue) 25 | { 26 | if (cqueue == NULL) { 27 | return; 28 | } 29 | free(cqueue->cqueue); 30 | cqueue->cqueue = cqueue->cqueue_end = NULL; 31 | cqueue->first_element = cqueue->last_element = NULL; 32 | free(cqueue); 33 | } 34 | 35 | int push_cqueue(CQueue * const cqueue, const void * const pnt) 36 | { 37 | unsigned char *new_element; 38 | 39 | if (cqueue->last_element == NULL) { 40 | assert(cqueue->first_element == NULL); 41 | new_element = cqueue->first_element = cqueue->cqueue; 42 | } else { 43 | if (cqueue->last_element != cqueue->cqueue_end) { 44 | new_element = cqueue->last_element + cqueue->element_size; 45 | } else { 46 | new_element = cqueue->cqueue; 47 | } 48 | if (new_element == cqueue->first_element) { 49 | return -1; 50 | } 51 | } 52 | memcpy(new_element, pnt, cqueue->element_size); 53 | cqueue->last_element = new_element; 54 | 55 | return 0; 56 | } 57 | 58 | void * shift_cqueue(CQueue * const cqueue) 59 | { 60 | unsigned char *next_element; 61 | unsigned char *element; 62 | 63 | if (cqueue->first_element == NULL) { 64 | return NULL; 65 | } 66 | if (cqueue->first_element == cqueue->last_element) { 67 | cqueue->last_element = next_element = NULL; 68 | } else { 69 | if (cqueue->first_element != cqueue->cqueue_end) { 70 | next_element = cqueue->first_element + cqueue->element_size; 71 | } else { 72 | next_element = cqueue->cqueue; 73 | } 74 | } 75 | element = cqueue->first_element; 76 | cqueue->first_element = next_element; 77 | 78 | return element; 79 | } 80 | -------------------------------------------------------------------------------- /src/cqueue.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __CQUEUE_H__ 3 | #define __CQUEUE_H__ 1 4 | 5 | typedef struct CQueue_ { 6 | unsigned char *cqueue; 7 | unsigned char *cqueue_end; 8 | unsigned char *first_element; 9 | unsigned char *last_element; 10 | size_t cqueue_size; 11 | size_t element_size; 12 | } CQueue; 13 | 14 | int init_cqueue(CQueue * const cqueue, const size_t nb_elements, 15 | const size_t element_size); 16 | 17 | void free_cqueue(CQueue * const cqueue); 18 | int push_cqueue(CQueue * const cqueue, const void * const pnt); 19 | void * shift_cqueue(CQueue * const cqueue); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/db_log.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DBLOG_H__ 3 | #define __DBLOG_H__ 1 4 | 5 | #define DB_LOG_RECORD_COOKIE_HEAD "-<" 6 | #define DB_LOG_RECORD_COOKIE_TAIL ">\n" 7 | #define DB_LOG_RECORD_COOKIE_MARK_CHAR "@" 8 | #define DB_LOG_RECORD_COOKIE_TIMESTAMP_CHAR "T" 9 | #ifndef DB_LOG_MAX_URI_LEN 10 | # define DB_LOG_MAX_URI_LEN (size_t) 10000U 11 | #endif 12 | #ifndef DB_LOG_MAX_BODY_LEN 13 | # define DB_LOG_MAX_BODY_LEN (size_t) 100000U 14 | #endif 15 | #ifndef DB_LOG_TMP_SUFFIX 16 | # define DB_LOG_TMP_SUFFIX ".tmp" 17 | #endif 18 | #ifndef DB_LOG_TIMESTAMP_GRANULARITY 19 | # define DB_LOG_TIMESTAMP_GRANULARITY (time_t) 60 20 | #endif 21 | 22 | typedef struct DBLog_ { 23 | char *db_log_file_name; 24 | int db_log_fd; 25 | struct evbuffer *log_buffer; 26 | size_t journal_buffer_size; 27 | int fsync_period; 28 | pid_t journal_rewrite_process; 29 | off_t offset_before_fork; 30 | time_t last_ts; 31 | } DBLog; 32 | 33 | int init_db_log(void); 34 | int open_db_log(void); 35 | void free_db_log(void); 36 | int close_db_log(void); 37 | 38 | int add_to_db_log(struct HttpHandlerContext_ * const context, const int verb, 39 | const char *uri, struct evbuffer * const input_buffer, 40 | _Bool send_to_slaves); 41 | 42 | int flush_db_log(const _Bool sync); 43 | 44 | int add_ts_to_ev_log_buffer(struct evbuffer * const log_buffer, 45 | const time_t ts); 46 | 47 | int reset_log(struct HttpHandlerContext_ * const context); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/domain_layers.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DOMAIN_LAYERS_H__ 3 | #define __DOMAIN_LAYERS_H__ 1 4 | 5 | int handle_domain_layers(struct evhttp_request * const req, 6 | HttpHandlerContext * const context, 7 | char *uri, char *opts, _Bool * const write_to_log, 8 | const _Bool fake_req); 9 | 10 | int handle_op_layers_create(LayersCreateOp * const create_op, 11 | HttpHandlerContext * const context); 12 | 13 | int handle_op_layers_delete(LayersDeleteOp * const delete_op, 14 | HttpHandlerContext * const context); 15 | 16 | int handle_op_layers_index(LayersIndexOp * const index_op, 17 | HttpHandlerContext * const context); 18 | 19 | int get_pan_db_by_layer_name(HttpHandlerContext * const context_, 20 | const char * const layer_name, 21 | const _Bool create, 22 | PanDB * * const pan_db); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/domain_records.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DOMAIN_RECORDS_H__ 3 | #define __DOMAIN_RECORDS_H__ 1 4 | 5 | int handle_domain_records(struct evhttp_request * const req, 6 | HttpHandlerContext * const context, 7 | char *uri, char *opts, _Bool * const write_to_log, 8 | const _Bool fake_req); 9 | 10 | int handle_op_records_put(RecordsPutOp * const put_op, 11 | HttpHandlerContext * const context); 12 | 13 | int handle_op_records_get(RecordsGetOp * const get_op, 14 | HttpHandlerContext * const context); 15 | 16 | int handle_op_records_delete(RecordsDeleteOp * const get_op, 17 | HttpHandlerContext * const context); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/domain_search.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DOMAIN_SEARCH_H__ 3 | #define __DOMAIN_SEARCH_H__ 1 4 | 5 | int handle_domain_search(struct evhttp_request * const req, 6 | HttpHandlerContext * const context, 7 | char *uri, char *opts, _Bool * const write_to_log, 8 | const _Bool fake_req); 9 | 10 | int handle_op_search_nearby(SearchNearbyOp * const nearby_op, 11 | HttpHandlerContext * const context); 12 | 13 | int handle_op_search_in_rect(SearchInRectOp * const in_rect_op, 14 | HttpHandlerContext * const context); 15 | 16 | int handle_op_search_in_keys(SearchInKeysOp * const in_keys_op, 17 | HttpHandlerContext * const context); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/domain_system.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DOMAIN_SYSTEM_H__ 3 | #define __DOMAIN_SYSTEM_H__ 1 4 | 5 | #define TMP_LOG_BUFFER_SIZE 65536 6 | #ifndef BGREWRITEAOF_NICENESS 7 | # define BGREWRITEAOF_NICENESS 10 8 | #endif 9 | 10 | int handle_domain_system(struct evhttp_request * const req, 11 | HttpHandlerContext * const context, 12 | char *uri, char *opts, _Bool * const write_to_log, 13 | const _Bool fake_req); 14 | 15 | int handle_op_system_ping(SystemPingOp * const ping_op, 16 | HttpHandlerContext * const context); 17 | 18 | int system_rewrite_after_fork_cb(HttpHandlerContext * const context); 19 | 20 | char *get_tmp_log_file_name(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/expirables.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __EXPIRABLES_H__ 3 | #define __EXPIRABLES_H__ 1 4 | 5 | #ifndef SPREAD_EXPIRATION 6 | # define SPREAD_EXPIRATION 0 7 | #endif 8 | 9 | int add_expirable_to_tree(PanDB * const pan_db, Expirable * const expirable); 10 | 11 | int remove_expirable_from_tree(PanDB * const pan_db, 12 | Expirable * const expirable); 13 | 14 | int purge_expired_keys(HttpHandlerContext * const context); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/ext/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jedisct1/Pincaster/ce43cbefb14078ec5cdcfc7050f23aed6c4248e9/src/ext/Makefile.am -------------------------------------------------------------------------------- /src/handle_consumer_ops.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __HANDLE_CONSUMER_OPS_H__ 3 | #define __HANDLE_CONSUMER_OPS__ 1 4 | 5 | void consumer_cb(struct bufferevent * const bev, void *context_); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/key_nodes.c: -------------------------------------------------------------------------------- 1 | 2 | #include "common.h" 3 | #include "http_server.h" 4 | #include "key_nodes.h" 5 | #include "expirables.h" 6 | 7 | RB_GENERATE(KeyNodes_, KeyNode_, entry, key_node_cmp); 8 | 9 | int key_node_cmp(const KeyNode * const kn1, const KeyNode * const kn2) 10 | { 11 | const Key * const k1 = kn1->key; 12 | const Key * const k2 = kn2->key; 13 | int ret; 14 | 15 | if (k1->len == k2->len) { 16 | ret = memcmp(k1->val, k2->val, k1->len); 17 | } else if (k1->len < k2->len) { 18 | if ((ret = memcmp(k1->val, k2->val, k1->len)) == 0) { 19 | ret = -1; 20 | } 21 | } else { 22 | if ((ret = memcmp(k1->val, k2->val, k2->len)) == 0) { 23 | ret = 1; 24 | } 25 | } 26 | return ret; 27 | } 28 | 29 | int get_key_node_from_key(PanDB * const db, Key * const key, 30 | const _Bool create, 31 | KeyNode * * const key_node) 32 | { 33 | KeyNode *found_key_node; 34 | KeyNode scanned_key_node = { .key = key }; 35 | KeyNode *new_key_node; 36 | 37 | *key_node = NULL; 38 | found_key_node = RB_FIND(KeyNodes_, &db->key_nodes, &scanned_key_node); 39 | if (found_key_node != NULL) { 40 | *key_node = found_key_node; 41 | return 1; 42 | } 43 | if (create == 0) { 44 | return 0; 45 | } 46 | if ((new_key_node = malloc(sizeof *new_key_node)) == NULL) { 47 | return -1; 48 | } 49 | retain_key(key); 50 | *new_key_node = (KeyNode) { 51 | .key = key, 52 | .slot = NULL, 53 | .properties = NULL, 54 | .expirable = NULL 55 | }; 56 | if (RB_INSERT(KeyNodes_, &db->key_nodes, new_key_node) != NULL) { 57 | release_key(key); 58 | free(new_key_node); 59 | return -1; 60 | } 61 | *key_node = new_key_node; 62 | 63 | return 2; 64 | } 65 | 66 | void free_key_node(PanDB * const db, KeyNode * const key_node) 67 | { 68 | if (key_node == NULL) { 69 | return; 70 | } 71 | assert(key_node->slot == NULL); 72 | release_key(key_node->key); 73 | key_node->key = NULL; 74 | free_slip_map(&key_node->properties); 75 | key_node->properties = NULL; 76 | HttpHandlerContext * context = db->context; 77 | if (key_node->expirable != NULL) { 78 | remove_expirable_from_tree(db, key_node->expirable); 79 | remove_entry_from_slab(&context->expirables_slab, key_node->expirable); 80 | key_node->expirable = NULL; 81 | } 82 | free(key_node); 83 | } 84 | 85 | SubSlots count_key_nodes(const KeyNodes * const key_nodes_) 86 | { 87 | KeyNodes * const key_nodes = (KeyNodes *) key_nodes_; 88 | SubSlots count = (SubSlots) 0U; 89 | 90 | if (key_nodes == NULL) { 91 | return count; 92 | } 93 | KeyNode *key_node = NULL; 94 | RB_FOREACH(key_node, KeyNodes_, key_nodes) { 95 | count++; 96 | } 97 | return count; 98 | } 99 | 100 | int key_nodes_foreach(KeyNodes * const key_nodes, 101 | KeyNodesForeachCB cb, void * const context) 102 | { 103 | if (key_nodes == NULL) { 104 | return 0; 105 | } 106 | int ret; 107 | KeyNode *key_node = NULL; 108 | RB_FOREACH(key_node, KeyNodes_, key_nodes) { 109 | if ((ret = cb(context, key_node)) != 0) { 110 | return ret; 111 | } 112 | } 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /src/key_nodes.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __KEY_NODES_H__ 3 | #define __KEY_NODES_H__ 1 4 | 5 | RB_PROTOTYPE(KeyNodes_, KeyNode_, entry, key_node_cmp); 6 | 7 | int key_node_cmp(const KeyNode * const kn1, const KeyNode * const kn2); 8 | 9 | int get_key_node_from_key(PanDB * const db, Key * const key, 10 | const _Bool create, 11 | KeyNode * * const key_node); 12 | 13 | void free_key_node(PanDB * const db, KeyNode * const key_node); 14 | 15 | SubSlots count_key_nodes(const KeyNodes * const key_nodes); 16 | 17 | typedef int (*KeyNodesForeachCB)(void *context, KeyNode * const key_node); 18 | 19 | int key_nodes_foreach(KeyNodes * const key_nodes, 20 | KeyNodesForeachCB cb, void * const context); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/keys.c: -------------------------------------------------------------------------------- 1 | 2 | #include "common.h" 3 | #include "keys.h" 4 | #include 5 | 6 | int init_key(Key * const key) 7 | { 8 | key->len = (size_t) 0U; 9 | key->ref_count = 1U; 10 | 11 | return 0; 12 | } 13 | 14 | void free_key(Key * const key) 15 | { 16 | if (key == NULL) { 17 | return; 18 | } 19 | assert(key->ref_count == 0U); 20 | key->val[0] = 0; 21 | key->len = (size_t) 0U; 22 | key->ref_count = 0U; 23 | free(key); 24 | } 25 | 26 | int retain_key(Key * const key) 27 | { 28 | assert(key->ref_count > 0U); 29 | if (key->ref_count >= UINT_MAX) { 30 | assert(key->ref_count < UINT_MAX); 31 | return -1; 32 | } 33 | key->ref_count++; 34 | 35 | return 0; 36 | } 37 | 38 | void release_key(Key * const key) 39 | { 40 | if (key == NULL) { 41 | return; 42 | } 43 | assert(key->ref_count > 0U); 44 | if (key->ref_count <= 0U) { 45 | return; 46 | } 47 | key->ref_count--; 48 | if (key->ref_count <= 0U) { 49 | free_key(key); 50 | } 51 | } 52 | 53 | Key *new_key(const void * const val, const size_t len) 54 | { 55 | Key *key; 56 | 57 | if (len < (size_t) 1U) { 58 | return NULL; 59 | } 60 | if (SIZE_MAX - sizeof *key < len) { 61 | return NULL; 62 | } 63 | if ((key = malloc(sizeof *key + len)) == NULL) { 64 | return NULL; 65 | } 66 | init_key(key); 67 | key->len = len; 68 | memcpy(key->val, val, len); 69 | 70 | return key; 71 | } 72 | 73 | Key *new_key_from_c_string(const char *ckey) 74 | { 75 | const size_t len = strlen(ckey); 76 | 77 | assert(len > (size_t) 0U); 78 | return new_key(ckey, len + (size_t) 1U); 79 | } 80 | 81 | Key *new_key_from_uri_encoded_c_string(const char * const uckey) 82 | { 83 | assert(uckey != NULL); 84 | assert(*uckey != 0); 85 | 86 | char * const decoded_uri = evhttp_decode_uri(uckey); 87 | if (decoded_uri == NULL) { 88 | return NULL; 89 | } 90 | const size_t decoded_uri_len = strlen(decoded_uri); 91 | assert(decoded_uri_len > (size_t) 0U); 92 | Key * const key = new_key(decoded_uri, decoded_uri_len + (size_t) 1U); 93 | free(decoded_uri); 94 | 95 | return key; 96 | } 97 | 98 | Key *new_key_with_leading_zero(const void * const val, const size_t len) 99 | { 100 | if (len >= SIZE_MAX) { 101 | return NULL; 102 | } 103 | Key *key; 104 | const size_t len1 = len + (size_t) 1U; 105 | if (SIZE_MAX - sizeof *key < len1) { 106 | return NULL; 107 | } 108 | if ((key = malloc(sizeof *key + len1)) == NULL) { 109 | return NULL; 110 | } 111 | init_key(key); 112 | key->len = len1; 113 | memcpy(key->val, val, len); 114 | *((char *) key->val + len) = 0; 115 | 116 | return key; 117 | } 118 | -------------------------------------------------------------------------------- /src/keys.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __KEYS_H__ 3 | #define __KEYS_H__ 1 4 | 5 | typedef struct Key_ { 6 | size_t len; 7 | unsigned int ref_count; 8 | char val[]; 9 | } Key; 10 | 11 | int init_key(Key * const key); 12 | void free_key(Key * const key); 13 | int retain_key(Key * const key); 14 | void release_key(Key * const key); 15 | Key *new_key(const void * const val, const size_t len); 16 | Key *new_key_from_c_string(const char *ckey); 17 | Key *new_key_from_uri_encoded_c_string(const char * const uckey); 18 | Key *new_key_with_leading_zero(const void * const val, const size_t len); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/levent2/.gitignore: -------------------------------------------------------------------------------- 1 | ### These files should get ignored no matter where they appear. 2 | 3 | # Editors leave these lying around 4 | \#*\# 5 | .#* 6 | *~ 7 | *.swp 8 | 9 | # C stuff 10 | *.o 11 | 12 | # Windows stuff 13 | *.obj 14 | *.exe 15 | *.lib 16 | 17 | # Patch leaves these lying arround 18 | *.orig 19 | *.rej 20 | 21 | # gcov stuff 22 | *.gcno 23 | *.gcov 24 | *.gcda 25 | 26 | # Autotools stuff 27 | .deps 28 | Makefile 29 | Makefile.in 30 | 31 | # Libtool stuff 32 | .libs 33 | *.lo 34 | *.la 35 | 36 | # ctags stuff 37 | TAGS 38 | 39 | # Stuff made by our makefiles 40 | libevent.pc 41 | libevent_pthreads.pc 42 | libevent_openssl.pc 43 | 44 | ## The initial / makes these files only get ignored in particular directories. 45 | /autom4te.cache 46 | 47 | # Libtool adds these, at least sometimes 48 | /m4/libtool.m4 49 | /m4/ltoptions.m4 50 | /m4/ltsugar.m4 51 | /m4/ltversion.m4 52 | /m4/lt~obsolete.m4 53 | 54 | /aclocal.m4 55 | /compile 56 | /config.guess 57 | /config.log 58 | /config.status 59 | /config.sub 60 | /configure 61 | /depcomp 62 | /config.h 63 | /config.h.in 64 | /install-sh 65 | /libtool 66 | /ltmain.sh 67 | /missing 68 | /stamp-h1 69 | /stamp-h2 70 | 71 | /include/event2/event-config.h 72 | /evconfig-private.h 73 | 74 | /sample/dns-example 75 | /sample/event-test 76 | /sample/hello-world 77 | /sample/http-server 78 | /sample/le-proxy 79 | /sample/signal-test 80 | /sample/time-test 81 | 82 | /test/bench 83 | /test/bench_cascade 84 | /test/bench_http 85 | /test/bench_httpclient 86 | /test/regress 87 | /test/regress.gen.c 88 | /test/regress.gen.h 89 | /test/test-eof 90 | /test/test-init 91 | /test/test-ratelim 92 | /test/test-time 93 | /test/test-weof 94 | /test/test-changelist 95 | 96 | -------------------------------------------------------------------------------- /src/levent2/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to libevent 2 | 3 | ## Coding style 4 | 5 | First and most generic rule: **just look around**. 6 | 7 | But, we have a script for checking patches/files/git-refs: 8 | ```shell 9 | # Chech HEAD git ref 10 | ./checkpatch.sh -r 11 | ./checkpatch.sh -r HEAD 12 | 13 | # Check patch 14 | git format-patch --stdout -1 | ./checkpatch.sh -p 15 | git show -1 | ./checkpatch.sh -p 16 | 17 | # Or via regular files 18 | git format-patch --stdout -2 19 | ./checkpatch.sh *.patch 20 | 21 | # Over a file 22 | ./checkpatch.sh -d event.c 23 | ./checkpatch.sh -d < event.c 24 | 25 | # And print the whole file not only summary 26 | ./checkpatch.sh -f event.c 27 | ./checkpatch.sh -f < event.c 28 | 29 | # See 30 | ./checkpatch.sh -h 31 | ``` 32 | 33 | ## Testing 34 | - Write new unit test in `test/regress_{MORE_SUITABLE_FOR_YOU}.c` 35 | - `make verify` 36 | 37 | ## Asking Questions 38 | It's all right to have questions! Instead of filing an issue here, go ahead and leave a message in our [Gitter Room](https://gitter.im/libevent/libevent) 39 | -------------------------------------------------------------------------------- /src/levent2/WIN32-Code/getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef __GETOPT_H__ 2 | #define __GETOPT_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern int opterr; /* if error message should be printed */ 9 | extern int optind; /* index into parent argv vector */ 10 | extern int optopt; /* character checked for validity */ 11 | extern int optreset; /* reset getopt */ 12 | extern char *optarg; /* argument associated with option */ 13 | 14 | struct option 15 | { 16 | const char *name; 17 | int has_arg; 18 | int *flag; 19 | int val; 20 | }; 21 | 22 | #define no_argument 0 23 | #define required_argument 1 24 | #define optional_argument 2 25 | 26 | int getopt(int, char**, const char*); 27 | int getopt_long(int, char**, const char*, const struct option*, int*); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* __GETOPT_H__ */ 34 | -------------------------------------------------------------------------------- /src/levent2/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | MAKE=make 4 | if command -v gmake >/dev/null 2>/dev/null; then 5 | MAKE=gmake 6 | fi 7 | $MAKE maintainer-clean >/dev/null 2>/dev/null 8 | 9 | if [ -x "`which autoreconf 2>/dev/null`" ] ; then 10 | exec autoreconf -ivf 11 | fi 12 | 13 | LIBTOOLIZE=libtoolize 14 | SYSNAME=`uname` 15 | if [ "$SYSNAME" = "Darwin" ] ; then 16 | LIBTOOLIZE=glibtoolize 17 | fi 18 | aclocal -I m4 && \ 19 | autoheader && \ 20 | $LIBTOOLIZE && \ 21 | autoconf && \ 22 | automake --add-missing --force-missing --copy 23 | -------------------------------------------------------------------------------- /src/levent2/cmake/COPYING-CMAKE-SCRIPTS: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 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 WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/levent2/cmake/CheckFileOffsetBits.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define KB ((off_t)1024) 4 | #define MB ((off_t)1024 * KB) 5 | #define GB ((off_t)1024 * MB) 6 | #define TB ((off_t)1024 * GB) 7 | int t2[(((64 * GB -1) % 671088649) == 268434537) 8 | && (((TB - (64 * GB -1) + 255) % 1792151290) == 305159546)? 1: -1]; 9 | 10 | int main() 11 | { 12 | ; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/levent2/cmake/CheckPrototypeDefinition.c.in: -------------------------------------------------------------------------------- 1 | @CHECK_PROTOTYPE_DEFINITION_HEADER@ 2 | 3 | static void cmakeRequireSymbol(int dummy, ...) { 4 | (void) dummy; 5 | } 6 | 7 | static void checkSymbol(void) { 8 | #ifndef @CHECK_PROTOTYPE_DEFINITION_SYMBOL@ 9 | cmakeRequireSymbol(0, &@CHECK_PROTOTYPE_DEFINITION_SYMBOL@); 10 | #endif 11 | } 12 | 13 | @CHECK_PROTOTYPE_DEFINITION_PROTO@ { 14 | return @CHECK_PROTOTYPE_DEFINITION_RETURN@; 15 | } 16 | 17 | #ifdef __CLASSIC_C__ 18 | int main() { 19 | int ac; 20 | char*av[]; 21 | #else 22 | int main(int ac, char *av[]) { 23 | #endif 24 | checkSymbol(); 25 | if (ac > 1000) { 26 | return *av[0]; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/levent2/cmake/Copyright.txt: -------------------------------------------------------------------------------- 1 | CMake - Cross Platform Makefile Generator 2 | Copyright 2000-2013 Kitware, Inc. 3 | Copyright 2000-2011 Insight Software Consortium 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | * Neither the names of Kitware, Inc., the Insight Software Consortium, 18 | nor the names of their contributors may be used to endorse or promote 19 | products derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | ------------------------------------------------------------------------------ 35 | 36 | The above copyright and license notice applies to distributions of 37 | CMake in source and binary form. Some source files contain additional 38 | notices of original copyright by their contributors; see each source 39 | for details. Third-party software packages supplied with CMake under 40 | compatible licenses provide their own copyright notices documented in 41 | corresponding subdirectories. 42 | 43 | ------------------------------------------------------------------------------ 44 | 45 | CMake was initially developed by Kitware with the following sponsorship: 46 | 47 | * National Library of Medicine at the National Institutes of Health 48 | as part of the Insight Segmentation and Registration Toolkit (ITK). 49 | 50 | * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel 51 | Visualization Initiative. 52 | 53 | * National Alliance for Medical Image Computing (NAMIC) is funded by the 54 | National Institutes of Health through the NIH Roadmap for Medical Research, 55 | Grant U54 EB005149. 56 | 57 | * Kitware, Inc. -------------------------------------------------------------------------------- /src/levent2/cmake/LibeventConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@EVENT_PACKAGE_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /src/levent2/cmake/Uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake 2 | 3 | if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 4 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") 5 | endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 6 | 7 | file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 8 | string(REGEX REPLACE "\n" ";" files "${files}") 9 | foreach(file ${files}) 10 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 11 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 12 | exec_program( 13 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 14 | OUTPUT_VARIABLE rm_out 15 | RETURN_VALUE rm_retval 16 | ) 17 | if(NOT "${rm_retval}" STREQUAL 0) 18 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 19 | endif(NOT "${rm_retval}" STREQUAL 0) 20 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 22 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 23 | endforeach(file) 24 | -------------------------------------------------------------------------------- /src/levent2/defer-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef DEFER_INTERNAL_H_INCLUDED_ 27 | #define DEFER_INTERNAL_H_INCLUDED_ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include "event2/event-config.h" 34 | #include "evconfig-private.h" 35 | 36 | #include 37 | 38 | struct event_callback; 39 | typedef void (*deferred_cb_fn)(struct event_callback *, void *); 40 | 41 | /** 42 | Initialize an empty, non-pending event_callback. 43 | 44 | @param deferred The struct event_callback structure to initialize. 45 | @param priority The priority that the callback should run at. 46 | @param cb The function to run when the struct event_callback executes. 47 | @param arg The function's second argument. 48 | */ 49 | EVENT2_EXPORT_SYMBOL 50 | void event_deferred_cb_init_(struct event_callback *, ev_uint8_t, deferred_cb_fn, void *); 51 | /** 52 | Change the priority of a non-pending event_callback. 53 | */ 54 | void event_deferred_cb_set_priority_(struct event_callback *, ev_uint8_t); 55 | /** 56 | Cancel a struct event_callback if it is currently scheduled in an event_base. 57 | */ 58 | EVENT2_EXPORT_SYMBOL 59 | void event_deferred_cb_cancel_(struct event_base *, struct event_callback *); 60 | /** 61 | Activate a struct event_callback if it is not currently scheduled in an event_base. 62 | 63 | Return true if it was not previously scheduled. 64 | */ 65 | EVENT2_EXPORT_SYMBOL 66 | int event_deferred_cb_schedule_(struct event_base *, struct event_callback *); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 73 | 74 | -------------------------------------------------------------------------------- /src/levent2/doxygen.am: -------------------------------------------------------------------------------- 1 | # Doxygen documentation will not be generated with default configuration, 2 | # unless '--enable-doxygen-doc' is configured. 3 | # The following targets are all about doxygen: 4 | # make # 'make doxygen' would be auto executed 5 | # make doxygen # generating doxygen documentation 6 | # make doxygen-doc # same as 'make doxygen' 7 | # make clean # clean docs generated by doxygen 8 | # make install # install doxygen documentation 9 | # make uninstall # uninstall doxygen documentation 10 | 11 | if ENABLE_DOXYGEN 12 | 13 | # Add all needed rules defined in ax_prog_doxygen.m4 14 | @DX_RULES@ 15 | 16 | # Use 'make clean' to clean docs generated by doxygen. 17 | clean-local: 18 | -rm -rf $(DX_CLEANFILES) 19 | 20 | if ENABLE_DOXYGEN_MAN 21 | man3_MAN_DIR = @DX_DOCDIR@/man/man3 22 | 23 | # add "libevent_" prefix for man pages 24 | # 25 | # XXX: we cannot clean old man pages here since 26 | # doxygen-rename-man-pages will be called twice: 27 | # - for make 28 | # - for make install 29 | # (cmake works differently) 30 | # 31 | # Once this will be solved add the following to the target: 32 | # 33 | # -rm -fr $(man3_MAN_DIR)/libevent_* 34 | doxygen-rename-man-pages: doxygen-doc 35 | echo "Rename man pages in $(man3_MAN_DIR)" 36 | @for p in $(man3_MAN_DIR)/*; do \ 37 | p=`basename $$p`; \ 38 | p_strip=$${p/libevent_/}; \ 39 | if [ ! "$$p_strip" = "$$p" ]; then continue; fi; \ 40 | mv '$(man3_MAN_DIR)/'$$p '$(man3_MAN_DIR)/'libevent_$$p; \ 41 | done 42 | 43 | # integrate doxygen with automake targets 44 | man3_MANS = $(man3_MAN_DIR)/* 45 | $(man3_MANS): doxygen-doc doxygen-rename-man-pages 46 | endif ENABLE_DOXYGEN_MAN 47 | 48 | # Docs will be installed. It may be one or more docs supported 49 | # by doxygen, but does not include 'man'. 50 | docdirs = $(DX_INSTALL_DOCS) 51 | 52 | # Rules for installing docs generated by doxygen into $(htmldir), 53 | # The typical value of $(htmldir) is '/usr/local/share/doc/$(PACKAGE)' 54 | install-data-local: 55 | @if ! test -d "$(DESTDIR)$(htmldir)"; then \ 56 | echo "$(mkinstalldirs) '$(DESTDIR)$(htmldir)'"; \ 57 | $(mkinstalldirs) '$(DESTDIR)$(htmldir)'; \ 58 | fi 59 | @for d in $(docdirs); do \ 60 | echo "cp -pR $$d '$(DESTDIR)$(htmldir)/'"; \ 61 | cp -pR $$d '$(DESTDIR)$(htmldir)/'; \ 62 | done 63 | 64 | # Rules for uninstalling docs generated by doxygen from $(htmldir) 65 | uninstall-local: 66 | @for d in $(docdirs); do \ 67 | d=`basename $$d`; \ 68 | echo "test ! -d '$(DESTDIR)$(htmldir)/'$$d || \ 69 | { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \ 70 | rm -rf '$(DESTDIR)$(htmldir)/'$$d; }"; \ 71 | test ! -d '$(DESTDIR)$(htmldir)/'$$d || \ 72 | { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \ 73 | rm -rf '$(DESTDIR)$(htmldir)/'$$d; }; \ 74 | done 75 | rmdir "$(DESTDIR)$(htmldir)/" || true 76 | 77 | doxygen: doxygen-doc 78 | all: doxygen 79 | 80 | endif ENABLE_DOXYGEN 81 | -------------------------------------------------------------------------------- /src/levent2/epoll_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003-2009 Niels Provos 3 | * Copyright 2009-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "evconfig-private.h" 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | int 38 | epoll_create(int size) 39 | { 40 | #if !defined(__NR_epoll_create) && defined(__NR_epoll_create1) 41 | if (size <= 0) { 42 | errno = EINVAL; 43 | return -1; 44 | } 45 | return (syscall(__NR_epoll_create1, 0)); 46 | #else 47 | return (syscall(__NR_epoll_create, size)); 48 | #endif 49 | } 50 | 51 | int 52 | epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) 53 | { 54 | 55 | return (syscall(__NR_epoll_ctl, epfd, op, fd, event)); 56 | } 57 | 58 | int 59 | epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) 60 | { 61 | #if !defined(__NR_epoll_wait) && defined(__NR_epoll_pwait) 62 | return (syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL, 0)); 63 | #else 64 | return (syscall(__NR_epoll_wait, epfd, events, maxevents, timeout)); 65 | #endif 66 | } 67 | -------------------------------------------------------------------------------- /src/levent2/evconfig-private.h.in: -------------------------------------------------------------------------------- 1 | /* evconfig-private.h template - see "Configuration Header Templates" */ 2 | /* in AC manual. Kevin Bowling 3 | * Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVSIGNAL_INTERNAL_H_INCLUDED_ 28 | #define EVSIGNAL_INTERNAL_H_INCLUDED_ 29 | 30 | #ifndef evutil_socket_t 31 | #include "event2/util.h" 32 | #endif 33 | #include 34 | 35 | typedef void (*ev_sighandler_t)(int); 36 | 37 | /* Data structure for the default signal-handling implementation in signal.c 38 | */ 39 | struct evsig_info { 40 | /* Event watching ev_signal_pair[1] */ 41 | struct event ev_signal; 42 | /* Socketpair used to send notifications from the signal handler */ 43 | evutil_socket_t ev_signal_pair[2]; 44 | /* True iff we've added the ev_signal event yet. */ 45 | int ev_signal_added; 46 | /* Count of the number of signals we're currently watching. */ 47 | int ev_n_signals_added; 48 | 49 | /* Array of previous signal handler objects before Libevent started 50 | * messing with them. Used to restore old signal handlers. */ 51 | #ifdef EVENT__HAVE_SIGACTION 52 | struct sigaction **sh_old; 53 | #else 54 | ev_sighandler_t **sh_old; 55 | #endif 56 | /* Size of sh_old. */ 57 | int sh_old_max; 58 | }; 59 | int evsig_init_(struct event_base *); 60 | void evsig_dealloc_(struct event_base *); 61 | 62 | void evsig_set_base_(struct event_base *base); 63 | void evsig_free_globals_(void); 64 | 65 | #endif /* EVSIGNAL_INTERNAL_H_INCLUDED_ */ 66 | -------------------------------------------------------------------------------- /src/levent2/extra/abi-check/README.md: -------------------------------------------------------------------------------- 1 | ## libevent ABI/API changes 2 | 3 | 4 | This script is used to generate information about changes in libevent ABI/API 5 | between various versions using [LVC tools](https://github.com/lvc). Such an 6 | overview can help developers migrate from one version to another. 7 | 8 | Here is the `abi_check.sh`, which is used to generate ABI/API timeline for 9 | libevent. 10 | 11 | You can limit the number of included libevent versions via a number given 12 | as a parameter to the script. For example 13 | 14 | ```shell 15 | $ ./abi_check.sh 3 16 | ``` 17 | 18 | generates overview for the last 3 versions and the current version. 19 | If no parameter given, it will generate overview for the last 2 versions and 20 | the current version by default. 21 | 22 | But this script requires some tools that are available in the following docker image: 23 | 24 | ``` 25 | docker.pkg.github.com/azat/docker-images/lvc-debian 26 | ``` 27 | 28 | And the full command looks like: 29 | 30 | ```shell 31 | docker run --rm -it -v $PWD:/src:ro -w /src -v tmp/le-abi-check-root:/abi-root -e ABI_CHECK_ROOT=/abi-root docker.pkg.github.com/azat/docker-images/lvc-debian /src/extra/abi-check/abi_check.sh 32 | ``` 33 | 34 | 'timeline/libevent/index.html' is the final result and can be viewed 35 | [here](https://libevent.org/abi) 36 | -------------------------------------------------------------------------------- /src/levent2/extra/abi-check/abi_check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Requirements: 4 | # - wdiff 5 | # - rfcdiff 6 | # - universal-ctags 7 | # - abi-tracker 8 | # - abi-monitor 9 | # - git 10 | # 11 | # All of this are included in: 12 | # docker.pkg.github.com/azat/docker-images/lvc-debian:latest 13 | # 14 | # TODO: 15 | # - move image into libevent namespace 16 | 17 | # verify backward compatibility of API/ABI changes 18 | 19 | set -e 20 | 21 | LIMIT=${1:-2} 22 | EVENT_SOURCE_DIR=${EVENT_SOURCE_DIR:-"$(cd "$(dirname "$0")"/../.. && pwd)"} 23 | ABI_CHECK_ROOT=${ABI_CHECK_ROOT:-$EVENT_SOURCE_DIR/.abi-check} 24 | ABI_CHECK_WORKSPACE=${ABI_CHECK_WORKSPACE:-"work/abi-check"} 25 | 26 | mkdir -p "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE" 27 | cd "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE" 28 | 29 | # copy current source code and profile into workspace 30 | mkdir -p src/libevent/current 31 | mkdir -p installed/libevent/current 32 | ( # to avoid cd back 33 | cd "$EVENT_SOURCE_DIR" 34 | # XXX: not `git archive` since it will not copy changes that are not in index, 35 | # and maybe some issues on CI (since it does not contain full clone) 36 | find . -maxdepth 1 -mindepth 1 | { 37 | git check-ignore --no-index --verbose --non-matching --stdin 38 | } | fgrep :: | cut -f2 | grep -v /.git/ | tee /dev/stderr | { 39 | xargs cp -r -t "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE/src/libevent/current/" 40 | } 41 | cp extra/abi-check/libevent.json "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE/" 42 | ) 43 | 44 | # run LVC tools 45 | abi-monitor -get -limit "$LIMIT" libevent.json 46 | # XXX: abi-monitor 1.12 supports "-make -j8", but 1.10 does not 47 | # (we can detect which version we have, and add this options) 48 | abi-monitor -v current -build libevent.json 49 | abi-monitor -build libevent.json 50 | abi-tracker -build libevent.json 51 | 52 | # remove useless files 53 | rm -rf src installed build_logs libevent.json 54 | -------------------------------------------------------------------------------- /src/levent2/extra/abi-check/libevent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Name": "libevent", 3 | "Title": "Libevent", 4 | "SourceUrl": "https://github.com/libevent/libevent/tags", 5 | "Git": "https://github.com/libevent/libevent.git", 6 | "Maintainer": "Nick Mathewson, Azat Khuzhin and Niels Provos", 7 | "MaintainerUrl": "https://libevent.org", 8 | "BuildSystem": "Autotools", 9 | "HeadersDiff": "On", 10 | "Package": "release-", 11 | "ReleasePattern": "\A([\d\-\.\_]+)(|\-beta|\-rc|\-stable)\Z", 12 | } 13 | -------------------------------------------------------------------------------- /src/levent2/extra/lsan.supp: -------------------------------------------------------------------------------- 1 | # TODO: temporary, until tests itself will be fixed 2 | leak:libcrypto.so 3 | leak:libssl.so 4 | -------------------------------------------------------------------------------- /src/levent2/extra/tsan.supp: -------------------------------------------------------------------------------- 1 | # https://github.com/libevent/libevent/issues/777 2 | race:event_debug_mode_too_late 3 | -------------------------------------------------------------------------------- /src/levent2/include/evdns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVDNS_H_INCLUDED_ 28 | #define EVENT1_EVDNS_H_INCLUDED_ 29 | 30 | /** @file evdns.h 31 | 32 | A dns subsystem for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVDNS_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /src/levent2/include/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVENT_H_INCLUDED_ 28 | #define EVENT1_EVENT_H_INCLUDED_ 29 | 30 | /** @file event.h 31 | 32 | A library for writing event-driven network servers. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other event2/ 37 | headers. 38 | */ 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include 45 | #ifdef EVENT__HAVE_SYS_TYPES_H 46 | #include 47 | #endif 48 | #ifdef EVENT__HAVE_SYS_TIME_H 49 | #include 50 | #endif 51 | #ifdef EVENT__HAVE_STDINT_H 52 | #include 53 | #endif 54 | #include 55 | 56 | /* For int types. */ 57 | #include 58 | 59 | #ifdef _WIN32 60 | #ifndef WIN32_LEAN_AND_MEAN 61 | #define WIN32_LEAN_AND_MEAN 62 | #endif 63 | #include 64 | #include 65 | #undef WIN32_LEAN_AND_MEAN 66 | #endif 67 | 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* EVENT1_EVENT_H_INCLUDED_ */ 84 | -------------------------------------------------------------------------------- /src/levent2/include/event2/dns_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_DNS_STRUCT_H_INCLUDED_ 28 | #define EVENT2_DNS_STRUCT_H_INCLUDED_ 29 | 30 | /** @file event2/dns_struct.h 31 | 32 | Data structures for dns. Using these structures may hurt forward 33 | compatibility with later versions of Libevent: be careful! 34 | 35 | */ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include 42 | #ifdef EVENT__HAVE_SYS_TYPES_H 43 | #include 44 | #endif 45 | #ifdef EVENT__HAVE_SYS_TIME_H 46 | #include 47 | #endif 48 | 49 | /* For int types. */ 50 | #include 51 | 52 | /* 53 | * Structures used to implement a DNS server. 54 | */ 55 | 56 | struct evdns_server_request { 57 | int flags; 58 | int nquestions; 59 | struct evdns_server_question **questions; 60 | }; 61 | struct evdns_server_question { 62 | int type; 63 | #ifdef __cplusplus 64 | int dns_question_class; 65 | #else 66 | /* You should refer to this field as "dns_question_class". The 67 | * name "class" works in C for backward compatibility, and will be 68 | * removed in a future version. (1.5 or later). */ 69 | int class; 70 | #define dns_question_class class 71 | #endif 72 | char name[1]; 73 | }; 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* EVENT2_DNS_STRUCT_H_INCLUDED_ */ 80 | 81 | -------------------------------------------------------------------------------- /src/levent2/include/event2/http_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_HTTP_COMPAT_H_INCLUDED_ 28 | #define EVENT2_HTTP_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/http_compat.h 31 | 32 | @brief Potentially non-threadsafe versions of the functions in http.h: provided 33 | only for backwards compatibility. 34 | 35 | */ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include 42 | #ifdef EVENT__HAVE_SYS_TYPES_H 43 | #include 44 | #endif 45 | #ifdef EVENT__HAVE_SYS_TIME_H 46 | #include 47 | #endif 48 | 49 | /* For int types. */ 50 | #include 51 | 52 | /** 53 | * Start an HTTP server on the specified address and port 54 | * 55 | * @deprecated It does not allow an event base to be specified 56 | * 57 | * @param address the address to which the HTTP server should be bound 58 | * @param port the port number on which the HTTP server should listen 59 | * @return a pointer to a newly initialized evhttp server structure 60 | * or NULL on error 61 | */ 62 | EVENT2_EXPORT_SYMBOL 63 | struct evhttp *evhttp_start(const char *address, ev_uint16_t port); 64 | 65 | /** 66 | * A connection object that can be used to for making HTTP requests. The 67 | * connection object tries to establish the connection when it is given an 68 | * http request object. 69 | * 70 | * @deprecated It does not allow an event base to be specified 71 | */ 72 | EVENT2_EXPORT_SYMBOL 73 | struct evhttp_connection *evhttp_connection_new( 74 | const char *address, ev_uint16_t port); 75 | 76 | /** 77 | * Associates an event base with the connection - can only be called 78 | * on a freshly created connection object that has not been used yet. 79 | * 80 | * @deprecated XXXX Why? 81 | */ 82 | EVENT2_EXPORT_SYMBOL 83 | void evhttp_connection_set_base(struct evhttp_connection *evcon, 84 | struct event_base *base); 85 | 86 | 87 | /** Returns the request URI */ 88 | #define evhttp_request_uri evhttp_request_get_uri 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 95 | -------------------------------------------------------------------------------- /src/levent2/include/event2/keyvalq_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ 28 | #define EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Fix so that people don't have to run with */ 35 | /* XXXX This code is duplicated with event_struct.h */ 36 | #ifndef TAILQ_ENTRY 37 | #define EVENT_DEFINED_TQENTRY_ 38 | #define TAILQ_ENTRY(type) \ 39 | struct { \ 40 | struct type *tqe_next; /* next element */ \ 41 | struct type **tqe_prev; /* address of previous next element */ \ 42 | } 43 | #endif /* !TAILQ_ENTRY */ 44 | 45 | #ifndef TAILQ_HEAD 46 | #define EVENT_DEFINED_TQHEAD_ 47 | #define TAILQ_HEAD(name, type) \ 48 | struct name { \ 49 | struct type *tqh_first; \ 50 | struct type **tqh_last; \ 51 | } 52 | #endif 53 | 54 | /* 55 | * Key-Value pairs. Can be used for HTTP headers but also for 56 | * query argument parsing. 57 | */ 58 | struct evkeyval { 59 | TAILQ_ENTRY(evkeyval) next; 60 | 61 | char *key; 62 | char *value; 63 | }; 64 | 65 | TAILQ_HEAD (evkeyvalq, evkeyval); 66 | 67 | /* XXXX This code is duplicated with event_struct.h */ 68 | #ifdef EVENT_DEFINED_TQENTRY_ 69 | #undef TAILQ_ENTRY 70 | #endif 71 | 72 | #ifdef EVENT_DEFINED_TQHEAD_ 73 | #undef TAILQ_HEAD 74 | #endif 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/levent2/include/event2/rpc_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_RPC_COMPAT_H_INCLUDED_ 28 | #define EVENT2_RPC_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/rpc_compat.h 31 | 32 | @brief Deprecated versions of the functions in rpc.h: provided only for 33 | backwards compatibility. 34 | 35 | */ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** backwards compatible accessors that work only with gcc */ 42 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 43 | 44 | #undef EVTAG_ASSIGN 45 | #undef EVTAG_GET 46 | #undef EVTAG_ADD 47 | 48 | #define EVTAG_ASSIGN(msg, member, args...) \ 49 | (*(msg)->base->member##_assign)(msg, ## args) 50 | #define EVTAG_GET(msg, member, args...) \ 51 | (*(msg)->base->member##_get)(msg, ## args) 52 | #define EVTAG_ADD(msg, member, args...) \ 53 | (*(msg)->base->member##_add)(msg, ## args) 54 | #endif 55 | #define EVTAG_LEN(msg, member) ((msg)->member##_length) 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 62 | -------------------------------------------------------------------------------- /src/levent2/include/event2/tag_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_TAG_COMPAT_H_INCLUDED_ 28 | #define EVENT2_TAG_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/tag_compat.h 31 | 32 | @brief Obsolete/deprecated functions from tag.h; provided only for backwards 33 | compatibility. 34 | */ 35 | 36 | /** 37 | @name Misnamed functions 38 | 39 | @deprecated These macros are deprecated because their names don't follow 40 | Libevent's naming conventions. Use evtag_encode_int and 41 | evtag_encode_int64 instead. 42 | 43 | @{ 44 | */ 45 | #define encode_int(evbuf, number) evtag_encode_int((evbuf), (number)) 46 | #define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number)) 47 | /**@}*/ 48 | 49 | #endif /* EVENT2_TAG_H_INCLUDED_ */ 50 | -------------------------------------------------------------------------------- /src/levent2/include/event2/visibility.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_VISIBILITY_H_INCLUDED_ 28 | #define EVENT2_VISIBILITY_H_INCLUDED_ 29 | 30 | #include 31 | 32 | #if defined(event_shared_EXPORTS) || \ 33 | defined(event_extra_shared_EXPORTS) || \ 34 | defined(event_core_shared_EXPORTS) || \ 35 | defined(event_pthreads_shared_EXPORTS) || \ 36 | defined(event_openssl_shared_EXPORTS) || \ 37 | defined(event_mbedtls_shared_EXPORTS) 38 | 39 | # if defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) 40 | # define EVENT2_EXPORT_SYMBOL __global 41 | # elif defined __GNUC__ 42 | # define EVENT2_EXPORT_SYMBOL __attribute__ ((visibility("default"))) 43 | # elif defined(_MSC_VER) 44 | # define EVENT2_EXPORT_SYMBOL __declspec(dllexport) 45 | # else 46 | # define EVENT2_EXPORT_SYMBOL /* unknown compiler */ 47 | # endif 48 | 49 | #else /* event_*_EXPORTS */ 50 | 51 | # define EVENT2_EXPORT_SYMBOL 52 | 53 | #endif /* event_*_EXPORTS */ 54 | 55 | /** We need to dllimport event_debug_logging_mask_ into event_extra */ 56 | #if defined(_MSC_VER) 57 | # if defined(event_core_shared_EXPORTS) /** from core export */ 58 | # define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllexport) 59 | # elif defined(event_extra_shared_EXPORTS) || /** from extra import */ \ 60 | defined(EVENT_VISIBILITY_WANT_DLLIMPORT) 61 | # define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllimport) 62 | # endif 63 | #endif /* _MSC_VER */ 64 | #if !defined(EVENT2_CORE_EXPORT_SYMBOL) 65 | # define EVENT2_CORE_EXPORT_SYMBOL EVENT2_EXPORT_SYMBOL 66 | #endif 67 | 68 | #endif /* EVENT2_VISIBILITY_H_INCLUDED_ */ 69 | -------------------------------------------------------------------------------- /src/levent2/include/evhttp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2000-2007 Niels Provos 3 | * Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVHTTP_H_INCLUDED_ 28 | #define EVENT1_EVHTTP_H_INCLUDED_ 29 | 30 | /** @file evhttp.h 31 | 32 | An http implementation subsystem for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVHTTP_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /src/levent2/include/evrpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVRPC_H_INCLUDED_ 28 | #define EVENT1_EVRPC_H_INCLUDED_ 29 | 30 | /** @file evrpc.h 31 | 32 | An RPC system for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVRPC_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /src/levent2/include/evutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef EVENT1_EVUTIL_H_INCLUDED_ 27 | #define EVENT1_EVUTIL_H_INCLUDED_ 28 | 29 | /** @file evutil.h 30 | 31 | Utility and compatibility functions for Libevent. 32 | 33 | The header is deprecated in Libevent 2.0 and later; please 34 | use instead. 35 | */ 36 | 37 | #include 38 | 39 | #endif /* EVENT1_EVUTIL_H_INCLUDED_ */ 40 | -------------------------------------------------------------------------------- /src/levent2/include/include.am: -------------------------------------------------------------------------------- 1 | # include/include.am for libevent 2 | # Copyright 2000-2007 Niels Provos 3 | # Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | # 5 | # See LICENSE for copying information. 6 | 7 | include_event2dir = $(includedir)/event2 8 | 9 | EVENT2_EXPORT = \ 10 | include/event2/buffer.h \ 11 | include/event2/buffer_compat.h \ 12 | include/event2/bufferevent.h \ 13 | include/event2/bufferevent_compat.h \ 14 | include/event2/bufferevent_struct.h \ 15 | include/event2/dns.h \ 16 | include/event2/dns_compat.h \ 17 | include/event2/dns_struct.h \ 18 | include/event2/event.h \ 19 | include/event2/event_compat.h \ 20 | include/event2/event_struct.h \ 21 | include/event2/watch.h \ 22 | include/event2/http.h \ 23 | include/event2/http_compat.h \ 24 | include/event2/http_struct.h \ 25 | include/event2/keyvalq_struct.h \ 26 | include/event2/listener.h \ 27 | include/event2/rpc.h \ 28 | include/event2/rpc_compat.h \ 29 | include/event2/rpc_struct.h \ 30 | include/event2/tag.h \ 31 | include/event2/tag_compat.h \ 32 | include/event2/thread.h \ 33 | include/event2/util.h \ 34 | include/event2/visibility.h 35 | 36 | if OPENSSL 37 | EVENT2_EXPORT += include/event2/bufferevent_ssl.h 38 | else 39 | if MBEDTLS 40 | EVENT2_EXPORT += include/event2/bufferevent_ssl.h 41 | endif 42 | endif 43 | 44 | ## Without the nobase_ prefixing, Automake would strip "include/event2/" from 45 | ## the source header filename to derive the installed header filename. 46 | ## With nobase_ the installed path is $(includedir)/include/event2/ev*.h. 47 | 48 | if INSTALL_LIBEVENT 49 | include_event2_HEADERS = $(EVENT2_EXPORT) 50 | nodist_include_event2_HEADERS = include/event2/event-config.h 51 | else 52 | noinst_HEADERS += $(EVENT2_EXPORT) 53 | nodist_noinst_HEADERS = include/event2/event-config.h 54 | endif 55 | -------------------------------------------------------------------------------- /src/levent2/ipv6-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* Internal use only: Fake IPv6 structures and values on platforms that 28 | * do not have them */ 29 | 30 | #ifndef IPV6_INTERNAL_H_INCLUDED_ 31 | #define IPV6_INTERNAL_H_INCLUDED_ 32 | 33 | #include "event2/event-config.h" 34 | #include "evconfig-private.h" 35 | 36 | #include 37 | #ifdef EVENT__HAVE_SYS_SOCKET_H 38 | #include 39 | #endif 40 | #include "event2/util.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @file ipv6-internal.h 47 | * 48 | * Replacement types and functions for platforms that don't support ipv6 49 | * properly. 50 | */ 51 | 52 | #ifndef EVENT__HAVE_STRUCT_IN6_ADDR 53 | struct in6_addr { 54 | ev_uint8_t s6_addr[16]; 55 | }; 56 | #endif 57 | 58 | #ifndef EVENT__HAVE_SA_FAMILY_T 59 | typedef int sa_family_t; 60 | #endif 61 | 62 | #ifndef EVENT__HAVE_STRUCT_SOCKADDR_IN6 63 | struct sockaddr_in6 { 64 | /* This will fail if we find a struct sockaddr that doesn't have 65 | * sa_family as the first element. */ 66 | sa_family_t sin6_family; 67 | ev_uint16_t sin6_port; 68 | struct in6_addr sin6_addr; 69 | }; 70 | #endif 71 | 72 | #ifndef AF_INET6 73 | #define AF_INET6 3333 74 | #endif 75 | #ifndef PF_INET6 76 | #define PF_INET6 AF_INET6 77 | #endif 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/levent2/kqueue-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef KQUEUE_INTERNAL_H_INCLUDED_ 27 | #define KQUEUE_INTERNAL_H_INCLUDED_ 28 | 29 | /** Notification function, used to tell an event base to wake up from another 30 | * thread. Only works when event_kq_add_notify_event_() has previously been 31 | * called successfully on that base. */ 32 | int event_kq_notify_base_(struct event_base *base); 33 | 34 | /** Prepare a kqueue-using event base to receive notifications via an internal 35 | * EVFILT_USER event. Return 0 on sucess, -1 on failure. 36 | */ 37 | int event_kq_add_notify_event_(struct event_base *base); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/levent2/libevent.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent 9 | Description: libevent is an asynchronous notification event loop library 10 | Version: @VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -levent_core -levent_extra 14 | Libs.private: @LIBS@ 15 | Cflags: -I${includedir} 16 | 17 | -------------------------------------------------------------------------------- /src/levent2/libevent_core.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_core 9 | Description: libevent_core 10 | Version: @VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -levent_core 14 | Libs.private: @LIBS@ 15 | Cflags: -I${includedir} 16 | 17 | -------------------------------------------------------------------------------- /src/levent2/libevent_extra.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_extra 9 | Description: libevent_extra 10 | Version: @VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -levent_extra 14 | Libs.private: @LIBS@ 15 | Cflags: -I${includedir} 16 | 17 | -------------------------------------------------------------------------------- /src/levent2/libevent_mbedtls.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_mbedtls 9 | Description: libevent_mbedtls adds mbedtls-based TLS support to libevent 10 | Version: @VERSION@ 11 | Requires: libevent_core 12 | Conflicts: 13 | Libs: -L${libdir} -levent_mbedtls 14 | Libs.private: @LIBS@ @MBEDTLS_LIBS@ 15 | Cflags: -I${includedir} @MBEDTLS_INCS@ 16 | 17 | -------------------------------------------------------------------------------- /src/levent2/libevent_openssl.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_openssl 9 | Description: libevent_openssl adds openssl-based TLS support to libevent 10 | Version: @VERSION@ 11 | Requires: libevent_core 12 | Conflicts: 13 | Libs: -L${libdir} -levent_openssl 14 | Libs.private: @LIBS@ @OPENSSL_LIBS@ 15 | Cflags: -I${includedir} @OPENSSL_INCS@ 16 | 17 | -------------------------------------------------------------------------------- /src/levent2/libevent_pthreads.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_pthreads 9 | Description: libevent_pthreads adds pthreads-based threading support to libevent 10 | Version: @VERSION@ 11 | Requires: libevent_core 12 | Conflicts: 13 | Libs: -L${libdir} -levent_pthreads 14 | Libs.private: @LIBS@ @PTHREAD_LIBS@ 15 | Cflags: -I${includedir} @PTHREAD_CFLAGS@ 16 | 17 | -------------------------------------------------------------------------------- /src/levent2/log-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef LOG_INTERNAL_H_INCLUDED_ 28 | #define LOG_INTERNAL_H_INCLUDED_ 29 | 30 | #include "event2/util.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifdef __GNUC__ 37 | #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b))) 38 | #define EV_NORETURN __attribute__((noreturn)) 39 | #else 40 | #define EV_CHECK_FMT(a,b) 41 | #define EV_NORETURN 42 | #endif 43 | 44 | #define EVENT_ERR_ABORT_ ((int)0xdeaddead) 45 | 46 | #if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG) 47 | #define EVENT_DEBUG_LOGGING_ENABLED 48 | #endif 49 | 50 | #ifdef EVENT_DEBUG_LOGGING_ENABLED 51 | EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_; 52 | #define event_debug_get_logging_mask_() (event_debug_logging_mask_) 53 | #else 54 | #define event_debug_get_logging_mask_() (0) 55 | #endif 56 | 57 | EVENT2_EXPORT_SYMBOL 58 | void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN; 59 | EVENT2_EXPORT_SYMBOL 60 | void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2); 61 | EVENT2_EXPORT_SYMBOL 62 | void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN; 63 | EVENT2_EXPORT_SYMBOL 64 | void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3); 65 | EVENT2_EXPORT_SYMBOL 66 | void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN; 67 | EVENT2_EXPORT_SYMBOL 68 | void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2); 69 | EVENT2_EXPORT_SYMBOL 70 | void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2); 71 | EVENT2_EXPORT_SYMBOL 72 | void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2); 73 | 74 | EVENT2_EXPORT_SYMBOL 75 | void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap) 76 | EV_CHECK_FMT(3,0); 77 | 78 | #ifdef EVENT_DEBUG_LOGGING_ENABLED 79 | #define event_debug(x) do { \ 80 | if (event_debug_get_logging_mask_()) { \ 81 | event_debugx_ x; \ 82 | } \ 83 | } while (0) 84 | #else 85 | #define event_debug(x) ((void)0) 86 | #endif 87 | 88 | #undef EV_CHECK_FMT 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* LOG_INTERNAL_H_INCLUDED_ */ 95 | -------------------------------------------------------------------------------- /src/levent2/m4/ac_backport_259_ssizet.m4: -------------------------------------------------------------------------------- 1 | AN_IDENTIFIER([ssize_t], [AC_TYPE_SSIZE_T]) 2 | AC_DEFUN([AC_TYPE_SSIZE_T], [AC_CHECK_TYPE(ssize_t, int)]) 3 | 4 | -------------------------------------------------------------------------------- /src/levent2/m4/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # Copying and distribution of this file, with or without modification, are 33 | # permitted in any medium without royalty provided the copyright notice 34 | # and this notice are preserved. This file is offered as-is, without any 35 | # warranty. 36 | 37 | #serial 6 38 | 39 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 40 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 41 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 42 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 43 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 44 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 45 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 46 | [AS_VAR_SET(CACHEVAR,[yes])], 47 | [AS_VAR_SET(CACHEVAR,[no])]) 48 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 49 | AS_VAR_IF(CACHEVAR,yes, 50 | [m4_default([$2], :)], 51 | [m4_default([$3], :)]) 52 | AS_VAR_POPDEF([CACHEVAR])dnl 53 | ])dnl AX_CHECK_COMPILE_FLAGS 54 | -------------------------------------------------------------------------------- /src/levent2/m4/ax_check_funcs_ex.m4: -------------------------------------------------------------------------------- 1 | # Check if the function is available. 2 | # HAVE_XXX will be defined if yes. 3 | 4 | # $1: the name of function 5 | # $2: the headers in where the function declared 6 | AC_DEFUN([AX_CHECK_DECL_EX], [dnl 7 | AS_IF([test "$2" = ""], [AC_MSG_ERROR([header not provided])]) 8 | AS_VAR_PUSHDEF([have_func_var], [HAVE_[]m4_toupper($1)]) 9 | AC_CHECK_DECL([$1],dnl 10 | [AC_DEFINE([have_func_var], [1], [Define to 1 if you have the `$1' function.])],,dnl 11 | [$2]dnl 12 | ) 13 | AS_VAR_POPDEF([have_func_var])dnl 14 | ]) 15 | 16 | AC_DEFUN([AX_CHECK_DECLS_EX], [dnl 17 | AS_IF([test "$2" = ""], [AC_MSG_ERROR([header not provided])]) 18 | m4_foreach([decl],dnl 19 | m4_split(m4_normalize($1)),dnl 20 | [AX_CHECK_DECL_EX([decl], [$2])]dnl 21 | ) 22 | ]) 23 | -------------------------------------------------------------------------------- /src/levent2/m4/libevent_mbedtls.m4: -------------------------------------------------------------------------------- 1 | dnl ###################################################################### 2 | dnl mbedtls support 3 | AC_DEFUN([LIBEVENT_MBEDTLS], [ 4 | 5 | case "$enable_mbedtls" in 6 | yes) 7 | case "$have_mbedtls" in 8 | yes) ;; 9 | *) 10 | save_LIBS="$LIBS" 11 | LIBS="" 12 | MBEDTLS_LIBS="" 13 | # clear cache 14 | unset ac_cv_search_mbedtls_ssl_init 15 | AC_SEARCH_LIBS([mbedtls_ssl_init], [mbedtls], 16 | [have_mbedtls=yes 17 | MBEDTLS_LIBS="$LIBS -lmbedtls -lmbedcrypto -lmbedx509 $EV_LIB_GDI $EV_LIB_WS32"], 18 | [have_mbedtls=no], 19 | [-lmbedtls -lmbedcrypto -lmbedx509 $EV_LIB_GDI $EV_LIB_WS32]) 20 | LIBS="$save_LIBS" 21 | test "$have_mbedtls" = "yes" && break 22 | esac 23 | CPPFLAGS_SAVE=$CPPFLAGS 24 | CPPFLAGS="$CPPFLAGS $MBEDTLS_INCS" 25 | AC_CHECK_HEADERS([mbedtls/ssl.h], [], [have_mbedtls=no]) 26 | CPPFLAGS=$CPPFLAGS_SAVE 27 | AC_SUBST(MBEDTLS_INCS) 28 | AC_SUBST(MBEDTLS_LIBS) 29 | case "$have_mbedtls" in 30 | yes) AC_DEFINE(HAVE_MBEDTLS, 1, [Define if the system has mbedtls]) ;; 31 | esac 32 | ;; 33 | esac 34 | 35 | # check if we have and should use mbedtls 36 | AM_CONDITIONAL(MBEDTLS, [test "$enable_mbedtls" != "no" && test "$have_mbedtls" = "yes"]) 37 | ]) 38 | -------------------------------------------------------------------------------- /src/levent2/m4/libevent_openssl.m4: -------------------------------------------------------------------------------- 1 | dnl ###################################################################### 2 | dnl OpenSSL support 3 | AC_DEFUN([LIBEVENT_OPENSSL], [ 4 | 5 | m4_ifndef([PKG_PROG_PKG_CONFIG], [AC_MSG_ERROR([PKG_PROG_PKG_CONFIG not found. Please install pkg-config and re-run autogen.sh])]) 6 | 7 | PKG_PROG_PKG_CONFIG([0.15.0]) 8 | 9 | case "$host_os" in 10 | darwin*) 11 | dnl when compiling for Darwin, attempt to find OpenSSL using brew. 12 | dnl We append the location given by brew to PKG_CONFIG_PATH path 13 | dnl and then export it, so that it can be used in detection below. 14 | AC_CHECK_PROG([BREW],brew, brew) 15 | if test x$BREW = xbrew; then 16 | openssl_prefix=$($BREW --prefix openssl 2>/dev/null) 17 | if test x$openssl_prefix != x; then 18 | OPENSSL_LIBS=`$PKG_CONFIG --libs openssl 2>/dev/null` 19 | case "$OPENSSL_LIBS" in 20 | dnl only if openssl is not in PKG_CONFIG_PATH already 21 | '') 22 | if test x$PKG_CONFIG_PATH != x; then 23 | PKG_CONFIG_PATH="$PKG_CONFIG_PATH:" 24 | fi 25 | OPENSSL_PKG_CONFIG="$openssl_prefix/lib/pkgconfig" 26 | PKG_CONFIG_PATH="$PKG_CONFIG_PATH$OPENSSL_PKG_CONFIG" 27 | export PKG_CONFIG_PATH 28 | AC_MSG_NOTICE([PKG_CONFIG_PATH has been set to $PKG_CONFIG_PATH (added openssl from brew)]) 29 | ;; 30 | esac 31 | fi 32 | fi 33 | ;; 34 | esac 35 | 36 | case "$enable_openssl" in 37 | yes) 38 | have_openssl=no 39 | case "$PKG_CONFIG" in 40 | '') 41 | ;; 42 | *) 43 | OPENSSL_LIBS=`$PKG_CONFIG --libs openssl 2>/dev/null` 44 | case "$OPENSSL_LIBS" in 45 | '') ;; 46 | *) OPENSSL_LIBS="$OPENSSL_LIBS $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD" 47 | have_openssl=yes 48 | ;; 49 | esac 50 | OPENSSL_INCS=`$PKG_CONFIG --cflags openssl 2>/dev/null` 51 | ;; 52 | esac 53 | case "$have_openssl" in 54 | yes) ;; 55 | *) 56 | save_LIBS="$LIBS" 57 | LIBS="" 58 | OPENSSL_LIBS="" 59 | for lib in crypto eay32; do 60 | dnl clear cache 61 | unset ac_cv_search_SSL_new 62 | AC_SEARCH_LIBS([SSL_new], [ssl ssl32], 63 | [have_openssl=yes 64 | OPENSSL_LIBS="$LIBS -l$lib $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"], 65 | [have_openssl=no], 66 | [-l$lib $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD]) 67 | LIBS="$save_LIBS" 68 | test "$have_openssl" = "yes" && break 69 | done 70 | ;; 71 | esac 72 | CPPFLAGS_SAVE=$CPPFLAGS 73 | CPPFLAGS="$CPPFLAGS $OPENSSL_INCS" 74 | AC_CHECK_HEADERS([openssl/ssl.h], [], [have_openssl=no]) 75 | CPPFLAGS=$CPPFLAGS_SAVE 76 | AC_SUBST(OPENSSL_INCS) 77 | AC_SUBST(OPENSSL_LIBS) 78 | case "$have_openssl" in 79 | yes) AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl]) ;; 80 | *) AC_MSG_ERROR([OpenSSL could not be found. You should add the directory \ 81 | containing 'openssl.pc' to the 'PKG_CONFIG_PATH' environment variable, set \ 82 | 'CFLAGS' and 'LDFLAGS' directly, or use '--disable-openssl' to disable \ 83 | support for OpenSSL encryption]) 84 | ;; 85 | esac 86 | ;; 87 | esac 88 | 89 | dnl check if we have and should use OpenSSL 90 | AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"]) 91 | ]) 92 | -------------------------------------------------------------------------------- /src/levent2/make-event-config.sed: -------------------------------------------------------------------------------- 1 | # Sed script to postprocess config.h into event-config.h. 2 | 3 | 1i\ 4 | /* event2/event-config.h\ 5 | *\ 6 | * This file was generated by autoconf when libevent was built, and post-\ 7 | * processed by Libevent so that its macros would have a uniform prefix.\ 8 | *\ 9 | * DO NOT EDIT THIS FILE.\ 10 | *\ 11 | * Do not rely on macros in this file existing in later versions.\ 12 | */\ 13 | \ 14 | #ifndef EVENT2_EVENT_CONFIG_H_INCLUDED_\ 15 | #define EVENT2_EVENT_CONFIG_H_INCLUDED_\ 16 | 17 | $a\ 18 | \ 19 | #endif /* event2/event-config.h */ 20 | 21 | /#\( *\)undef STDC_HEADERS\>/b 22 | /#\( *\)define STDC_HEADERS\>/b 23 | 24 | # Only rewrite symbols starting with capitals 25 | s/#\( *\)define \([A-Z]\)/#\1define EVENT__\2/ 26 | s/#\( *\)undef \([A-Z]\)/#\1undef EVENT__\2/ 27 | s/#\( *\)if\(n*\)def \([A-Z]\)/#\1if\2def EVENT__\2/ 28 | -------------------------------------------------------------------------------- /src/levent2/make_epoll_table.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | def get(old,wc,rc,cc): 4 | if ('xxx' in (rc, wc, cc)): 5 | return "0",255 6 | 7 | if ('add' in (rc, wc, cc)): 8 | events = [] 9 | if rc == 'add' or (rc != 'del' and 'r' in old): 10 | events.append("EPOLLIN") 11 | if wc == 'add' or (wc != 'del' and 'w' in old): 12 | events.append("EPOLLOUT") 13 | if cc == 'add' or (cc != 'del' and 'c' in old): 14 | events.append("EPOLLRDHUP") 15 | 16 | if old == "0": 17 | op = "EPOLL_CTL_ADD" 18 | else: 19 | op = "EPOLL_CTL_MOD" 20 | return "|".join(events), op 21 | 22 | if ('del' in (rc, wc, cc)): 23 | delevents = [] 24 | modevents = [] 25 | op = "EPOLL_CTL_DEL" 26 | 27 | if 'r' in old: 28 | modevents.append("EPOLLIN") 29 | if 'w' in old: 30 | modevents.append("EPOLLOUT") 31 | if 'c' in old: 32 | modevents.append("EPOLLRDHUP") 33 | 34 | for item, event in [(rc,"EPOLLIN"), 35 | (wc,"EPOLLOUT"), 36 | (cc,"EPOLLRDHUP")]: 37 | if item == 'del': 38 | delevents.append(event) 39 | if event in modevents: 40 | modevents.remove(event) 41 | 42 | if modevents: 43 | return "|".join(modevents), "EPOLL_CTL_MOD" 44 | else: 45 | return "|".join(delevents), "EPOLL_CTL_DEL" 46 | 47 | return 0, 0 48 | 49 | 50 | def fmt(op, ev, old, wc, rc, cc): 51 | entry = "{ %s, %s },"%(op, ev) 52 | print "\t/* old=%3s, write:%3s, read:%3s, close:%3s */\n\t%s" % ( 53 | old, wc, rc, cc, entry) 54 | return len(entry) 55 | 56 | for old in ('0','r','w','rw','c','cr','cw','crw'): 57 | for wc in ('0', 'add', 'del', 'xxx'): 58 | for rc in ('0', 'add', 'del', 'xxx'): 59 | for cc in ('0', 'add', 'del', 'xxx'): 60 | 61 | op,ev = get(old,wc,rc,cc) 62 | 63 | fmt(op, ev, old, wc, rc, cc) 64 | -------------------------------------------------------------------------------- /src/levent2/mbedtls-compat.h: -------------------------------------------------------------------------------- 1 | #ifndef MBEDTLS_COMPAT_H 2 | #define MBEDTLS_COMPAT_H 3 | 4 | #include 5 | #if MBEDTLS_VERSION_MAJOR < 2 || (MBEDTLS_VERSION_MAJOR == 2 && MBEDTLS_VERSION_MINOR < 4) 6 | #include 7 | #else 8 | #include 9 | #endif 10 | 11 | #endif // LIBEVENT_MBEDTLS_COMPAT_H 12 | -------------------------------------------------------------------------------- /src/levent2/openssl-compat.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENSSL_COMPAT_H 2 | #define OPENSSL_COMPAT_H 3 | 4 | #include 5 | #include "util-internal.h" 6 | 7 | #if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ 8 | (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) 9 | 10 | static inline BIO_METHOD *BIO_meth_new(int type, const char *name) 11 | { 12 | BIO_METHOD *biom = calloc(1, sizeof(BIO_METHOD)); 13 | 14 | if (biom != NULL) { 15 | biom->type = type; 16 | biom->name = name; 17 | } 18 | return biom; 19 | } 20 | 21 | #define BIO_meth_set_write(b, f) (b)->bwrite = (f) 22 | #define BIO_meth_set_read(b, f) (b)->bread = (f) 23 | #define BIO_meth_set_puts(b, f) (b)->bputs = (f) 24 | #define BIO_meth_set_ctrl(b, f) (b)->ctrl = (f) 25 | #define BIO_meth_set_create(b, f) (b)->create = (f) 26 | #define BIO_meth_set_destroy(b, f) (b)->destroy = (f) 27 | 28 | #define BIO_set_init(b, val) (b)->init = (val) 29 | #define BIO_set_data(b, val) (b)->ptr = (val) 30 | #define BIO_set_shutdown(b, val) (b)->shutdown = (val) 31 | #define BIO_get_init(b) (b)->init 32 | #define BIO_get_data(b) (b)->ptr 33 | #define BIO_get_shutdown(b) (b)->shutdown 34 | 35 | #define TLS_method SSLv23_method 36 | 37 | #define X509_getm_notBefore X509_get_notBefore 38 | #define X509_getm_notAfter X509_get_notAfter 39 | 40 | #endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ 41 | (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */ 42 | 43 | #if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x20700000L && \ 44 | LIBRESSL_VERSION_NUMBER < 0x30500000L 45 | #define BIO_get_init(b) (b)->init 46 | #endif 47 | 48 | #endif /* OPENSSL_COMPAT_H */ 49 | -------------------------------------------------------------------------------- /src/levent2/sample/hostcheck.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_CURL_HOSTCHECK_H 2 | #define HEADER_CURL_HOSTCHECK_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #define CURL_HOST_NOMATCH 0 26 | #define CURL_HOST_MATCH 1 27 | int Curl_cert_hostcheck(const char *match_pattern, const char *hostname); 28 | 29 | #endif /* HEADER_CURL_HOSTCHECK_H */ 30 | 31 | -------------------------------------------------------------------------------- /src/levent2/sample/include.am: -------------------------------------------------------------------------------- 1 | # sample/include.am for libevent 2 | # Copyright 2000-2007 Niels Provos 3 | # Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | # 5 | # See LICENSE for copying information. 6 | 7 | SAMPLES = \ 8 | sample/dns-example \ 9 | sample/event-read-fifo \ 10 | sample/hello-world \ 11 | sample/http-server \ 12 | sample/http-connect \ 13 | sample/signal-test \ 14 | sample/time-test \ 15 | sample/watch-timing 16 | 17 | if OPENSSL 18 | SAMPLES += sample/le-proxy 19 | sample_le_proxy_SOURCES = sample/le-proxy.c 20 | sample_le_proxy_LDADD = libevent.la libevent_openssl.la $(OPENSSL_LIBS) $(OPENSSL_LIBADD) 21 | sample_le_proxy_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS) 22 | 23 | SAMPLES += sample/becat 24 | sample_becat_SOURCES = sample/becat.c 25 | sample_becat_LDADD = libevent.la libevent_openssl.la $(OPENSSL_LIBS) $(OPENSSL_LIBADD) 26 | sample_becat_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS) 27 | 28 | SAMPLES += sample/https-client 29 | sample_https_client_SOURCES = \ 30 | sample/https-client.c \ 31 | sample/hostcheck.c \ 32 | sample/openssl_hostname_validation.c 33 | sample_https_client_LDADD = libevent.la libevent_openssl.la $(OPENSSL_LIBS) $(OPENSSL_LIBADD) 34 | if BUILD_WIN32 35 | sample_https_client_LDADD += -lcrypt32 36 | endif 37 | sample_https_client_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS) 38 | noinst_HEADERS += \ 39 | sample/hostcheck.h \ 40 | sample/openssl_hostname_validation.h 41 | endif 42 | 43 | if MBEDTLS 44 | SAMPLES += sample/ssl-client-mbedtls 45 | sample_ssl_client_mbedtls_SOURCES = sample/ssl-client-mbedtls.c 46 | sample_ssl_client_mbedtls_LDADD = libevent.la libevent_mbedtls.la $(MBEDTLS_LIBS) $(MBEDTLS_LIBADD) 47 | sample_ssl_client_mbedtls_CPPFLAGS = $(AM_CPPFLAGS) $(MBEDTLS_INCS) 48 | 49 | SAMPLES += sample/https-client-mbedtls 50 | sample_https_client_mbedtls_SOURCES = sample/https-client.c 51 | sample_https_client_mbedtls_LDADD = libevent.la libevent_mbedtls.la $(MBEDTLS_LIBS) $(MBEDTLS_LIBADD) 52 | sample_https_client_mbedtls_CPPFLAGS = $(AM_CPPFLAGS) $(MBEDTLS_INCS) -DUSE_MBEDTLS 53 | endif 54 | 55 | if BUILD_SAMPLES 56 | noinst_PROGRAMS += $(SAMPLES) 57 | endif 58 | 59 | $(SAMPLES) : libevent.la 60 | 61 | sample_event_read_fifo_SOURCES = sample/event-read-fifo.c 62 | sample_event_read_fifo_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 63 | sample_time_test_SOURCES = sample/time-test.c 64 | sample_time_test_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 65 | sample_signal_test_SOURCES = sample/signal-test.c 66 | sample_signal_test_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 67 | sample_dns_example_SOURCES = sample/dns-example.c 68 | sample_dns_example_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 69 | sample_hello_world_SOURCES = sample/hello-world.c 70 | sample_hello_world_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 71 | sample_http_server_SOURCES = sample/http-server.c 72 | sample_http_server_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 73 | sample_http_connect_SOURCES = sample/http-connect.c 74 | sample_http_connect_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 75 | sample_watch_timing_SOURCES = sample/watch-timing.c 76 | sample_watch_timing_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la -lm 77 | -------------------------------------------------------------------------------- /src/levent2/sample/openssl_hostname_validation.h: -------------------------------------------------------------------------------- 1 | /* Obtained from: https://github.com/iSECPartners/ssl-conservatory */ 2 | 3 | /* 4 | Copyright (C) 2012, iSEC Partners. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is furnished to do 11 | so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | /* 26 | * Helper functions to perform basic hostname validation using OpenSSL. 27 | * 28 | * Please read "everything-you-wanted-to-know-about-openssl.pdf" before 29 | * attempting to use this code. This whitepaper describes how the code works, 30 | * how it should be used, and what its limitations are. 31 | * 32 | * Author: Alban Diquet 33 | * License: See LICENSE 34 | * 35 | */ 36 | 37 | typedef enum { 38 | MatchFound, 39 | MatchNotFound, 40 | NoSANPresent, 41 | MalformedCertificate, 42 | Error 43 | } HostnameValidationResult; 44 | 45 | /** 46 | * Validates the server's identity by looking for the expected hostname in the 47 | * server's certificate. As described in RFC 6125, it first tries to find a match 48 | * in the Subject Alternative Name extension. If the extension is not present in 49 | * the certificate, it checks the Common Name instead. 50 | * 51 | * Returns MatchFound if a match was found. 52 | * Returns MatchNotFound if no matches were found. 53 | * Returns MalformedCertificate if any of the hostnames had a NUL character embedded in it. 54 | * Returns Error if there was an error. 55 | */ 56 | HostnameValidationResult validate_hostname(const char *hostname, const X509 *server_cert); 57 | -------------------------------------------------------------------------------- /src/levent2/sample/signal-test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Compile with: 3 | * cc -I/usr/local/include -o signal-test \ 4 | * signal-test.c -L/usr/local/lib -levent 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #ifndef _WIN32 13 | #include 14 | #include 15 | #include 16 | #else 17 | #include 18 | #include 19 | #endif 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | int called = 0; 30 | 31 | static void 32 | signal_cb(evutil_socket_t fd, short event, void *arg) 33 | { 34 | struct event *signal = arg; 35 | 36 | printf("signal_cb: got signal %d\n", event_get_signal(signal)); 37 | 38 | if (called >= 2) 39 | event_del(signal); 40 | 41 | called++; 42 | } 43 | 44 | int 45 | main(int argc, char **argv) 46 | { 47 | struct event *signal_int = NULL; 48 | struct event_base* base; 49 | int ret = 0; 50 | #ifdef _WIN32 51 | WORD wVersionRequested; 52 | WSADATA wsaData; 53 | 54 | wVersionRequested = MAKEWORD(2, 2); 55 | 56 | (void) WSAStartup(wVersionRequested, &wsaData); 57 | #endif 58 | 59 | /* Initialize the event library */ 60 | base = event_base_new(); 61 | if (!base) { 62 | ret = 1; 63 | goto out; 64 | } 65 | 66 | /* Initialize one event */ 67 | signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg()); 68 | if (!signal_int) { 69 | ret = 2; 70 | goto out; 71 | } 72 | event_add(signal_int, NULL); 73 | 74 | event_base_dispatch(base); 75 | 76 | out: 77 | if (signal_int) 78 | event_free(signal_int); 79 | if (base) 80 | event_base_free(base); 81 | return ret; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/levent2/sample/time-test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * XXX This sample code was once meant to show how to use the basic Libevent 3 | * interfaces, but it never worked on non-Unix platforms, and some of the 4 | * interfaces have changed since it was first written. It should probably 5 | * be removed or replaced with something better. 6 | * 7 | * Compile with: 8 | * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent 9 | */ 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #ifndef _WIN32 17 | #include 18 | #include 19 | #endif 20 | #include 21 | #ifdef EVENT__HAVE_SYS_TIME_H 22 | #include 23 | #endif 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef _WIN32 35 | #include 36 | #endif 37 | 38 | struct timeval lasttime; 39 | 40 | int event_is_persistent; 41 | 42 | static void 43 | timeout_cb(evutil_socket_t fd, short event, void *arg) 44 | { 45 | struct timeval newtime, difference; 46 | struct event *timeout = arg; 47 | double elapsed; 48 | 49 | evutil_gettimeofday(&newtime, NULL); 50 | evutil_timersub(&newtime, &lasttime, &difference); 51 | elapsed = difference.tv_sec + 52 | (difference.tv_usec / 1.0e6); 53 | 54 | printf("timeout_cb called at %d: %.3f seconds elapsed.\n", 55 | (int)newtime.tv_sec, elapsed); 56 | lasttime = newtime; 57 | 58 | if (! event_is_persistent) { 59 | struct timeval tv; 60 | evutil_timerclear(&tv); 61 | tv.tv_sec = 2; 62 | event_add(timeout, &tv); 63 | } 64 | } 65 | 66 | int 67 | main(int argc, char **argv) 68 | { 69 | struct event timeout; 70 | struct timeval tv; 71 | struct event_base *base; 72 | int flags; 73 | 74 | #ifdef _WIN32 75 | WORD wVersionRequested; 76 | WSADATA wsaData; 77 | 78 | wVersionRequested = MAKEWORD(2, 2); 79 | 80 | (void)WSAStartup(wVersionRequested, &wsaData); 81 | #endif 82 | 83 | if (argc == 2 && !strcmp(argv[1], "-p")) { 84 | event_is_persistent = 1; 85 | flags = EV_PERSIST; 86 | } else { 87 | event_is_persistent = 0; 88 | flags = 0; 89 | } 90 | 91 | /* Initialize the event library */ 92 | base = event_base_new(); 93 | 94 | /* Initialize one event */ 95 | event_assign(&timeout, base, -1, flags, timeout_cb, (void*) &timeout); 96 | 97 | evutil_timerclear(&tv); 98 | tv.tv_sec = 2; 99 | event_add(&timeout, &tv); 100 | 101 | evutil_gettimeofday(&lasttime, NULL); 102 | 103 | setbuf(stdout, NULL); 104 | setbuf(stderr, NULL); 105 | 106 | event_base_dispatch(base); 107 | 108 | return (0); 109 | } 110 | 111 | -------------------------------------------------------------------------------- /src/levent2/strlcpy-internal.h: -------------------------------------------------------------------------------- 1 | #ifndef STRLCPY_INTERNAL_H_INCLUDED_ 2 | #define STRLCPY_INTERNAL_H_INCLUDED_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "event2/event-config.h" 9 | #include "event2/visibility.h" 10 | #include "evconfig-private.h" 11 | 12 | #ifndef EVENT__HAVE_STRLCPY 13 | #include 14 | EVENT2_EXPORT_SYMBOL 15 | size_t event_strlcpy_(char *dst, const char *src, size_t siz); 16 | #define strlcpy event_strlcpy_ 17 | #endif 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /src/levent2/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1998 Todd C. Miller 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #if defined(LIBC_SCCS) && !defined(lint) 31 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; 32 | #endif /* LIBC_SCCS and not lint */ 33 | 34 | #include "event2/event-config.h" 35 | #include "evconfig-private.h" 36 | 37 | #include 38 | 39 | #ifndef EVENT__HAVE_STRLCPY 40 | #include "strlcpy-internal.h" 41 | 42 | /* 43 | * Copy src to string dst of size siz. At most siz-1 characters 44 | * will be copied. Always NUL terminates (unless siz == 0). 45 | * Returns strlen(src); if retval >= siz, truncation occurred. 46 | */ 47 | size_t 48 | event_strlcpy_(dst, src, siz) 49 | char *dst; 50 | const char *src; 51 | size_t siz; 52 | { 53 | register char *d = dst; 54 | register const char *s = src; 55 | register size_t n = siz; 56 | 57 | /* Copy as many bytes as will fit */ 58 | if (n != 0 && --n != 0) { 59 | do { 60 | if ((*d++ = *s++) == 0) 61 | break; 62 | } while (--n != 0); 63 | } 64 | 65 | /* Not enough room in dst, add NUL and traverse rest of src */ 66 | if (n == 0) { 67 | if (siz != 0) 68 | *d = '\0'; /* NUL-terminate dst */ 69 | while (*s++) 70 | ; 71 | } 72 | 73 | return (s - src - 1); /* count does not include NUL */ 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /src/levent2/test-export/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1.2) 2 | if (POLICY CMP0074) 3 | cmake_policy(SET CMP0074 NEW) 4 | endif() 5 | project(verify) 6 | # set(CMAKE_VERBOSE_MAKEFILE 1) 7 | if(NOT ${EVENT__CODE_COMPONENT} STREQUAL "") 8 | string(TOUPPER ${EVENT__CODE_COMPONENT} _UPPER_COMPONENT) 9 | endif() 10 | find_package(Libevent 2.2.0 REQUIRED COMPONENTS ${EVENT__LINK_COMPONENT}) 11 | add_definitions(-DEVENT_EXPORT_TEST_COMPONENT_${_UPPER_COMPONENT}) 12 | add_executable(test-export test-export.c) 13 | target_link_libraries(test-export ${LIBEVENT_LIBRARIES}) 14 | enable_testing() 15 | add_test(test-export test-export) 16 | -------------------------------------------------------------------------------- /src/levent2/test/check-dumpevents.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Post-process the output of test-dumpevents and check it for correctness. 4 | # 5 | 6 | import math 7 | import re 8 | import sys 9 | 10 | text = sys.stdin.readlines() 11 | 12 | try: 13 | expect_inserted_pos = text.index("Inserted:\n") 14 | expect_active_pos = text.index("Active:\n") 15 | got_inserted_pos = text.index("Inserted events:\n") 16 | got_active_pos = text.index("Active events:\n") 17 | except ValueError: 18 | sys.stderr.write("Missing expected dividing line in dumpevents output") 19 | sys.exit(1) 20 | 21 | if not (expect_inserted_pos < expect_active_pos < 22 | got_inserted_pos < got_active_pos): 23 | sys.stderr.write("Sections out of order in dumpevents output") 24 | sys.exit(1) 25 | 26 | now,T= text[1].split() 27 | T = float(T) 28 | 29 | want_inserted = set(text[expect_inserted_pos+1:expect_active_pos]) 30 | want_active = set(text[expect_active_pos+1:got_inserted_pos-1]) 31 | got_inserted = set(text[got_inserted_pos+1:got_active_pos]) 32 | got_active = set(text[got_active_pos+1:]) 33 | 34 | pat = re.compile(r'Timeout=([0-9\.]+)') 35 | def replace_time(m): 36 | t = float(m.group(1)) 37 | if .9 < abs(t-T) < 1.1: 38 | return "Timeout=T+1" 39 | elif 2.4 < abs(t-T) < 2.6: 40 | return "Timeout=T+2.5" 41 | else: 42 | return m.group(0) 43 | 44 | cleaned_inserted = set( pat.sub(replace_time, s) for s in got_inserted 45 | if "Internal" not in s) 46 | 47 | if cleaned_inserted != want_inserted: 48 | sys.stderr.write("Inserted event lists were not as expected!") 49 | sys.exit(1) 50 | 51 | if set(got_active) != set(want_active): 52 | sys.stderr.write("Active event lists were not as expected!") 53 | sys.exit(1) 54 | 55 | -------------------------------------------------------------------------------- /src/levent2/test/print-winsock-errors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "event2/event.h" 8 | #include "event2/util.h" 9 | #include "event2/thread.h" 10 | 11 | #define E(x) printf (#x " -> \"%s\"\n", evutil_socket_error_to_string (x)); 12 | 13 | int main (int argc, char **argv) 14 | { 15 | int i, j; 16 | const char *s1, *s2; 17 | 18 | #ifdef EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 19 | evthread_use_windows_threads (); 20 | #endif 21 | 22 | s1 = evutil_socket_error_to_string (WSAEINTR); 23 | 24 | for (i = 0; i < 3; i++) { 25 | printf ("\niteration %d:\n\n", i); 26 | E(WSAEINTR); 27 | E(WSAEACCES); 28 | E(WSAEFAULT); 29 | E(WSAEINVAL); 30 | E(WSAEMFILE); 31 | E(WSAEWOULDBLOCK); 32 | E(WSAEINPROGRESS); 33 | E(WSAEALREADY); 34 | E(WSAENOTSOCK); 35 | E(WSAEDESTADDRREQ); 36 | E(WSAEMSGSIZE); 37 | E(WSAEPROTOTYPE); 38 | E(WSAENOPROTOOPT); 39 | E(WSAEPROTONOSUPPORT); 40 | E(WSAESOCKTNOSUPPORT); 41 | E(WSAEOPNOTSUPP); 42 | E(WSAEPFNOSUPPORT); 43 | E(WSAEAFNOSUPPORT); 44 | E(WSAEADDRINUSE); 45 | E(WSAEADDRNOTAVAIL); 46 | E(WSAENETDOWN); 47 | E(WSAENETUNREACH); 48 | E(WSAENETRESET); 49 | E(WSAECONNABORTED); 50 | E(WSAECONNRESET); 51 | E(WSAENOBUFS); 52 | E(WSAEISCONN); 53 | E(WSAENOTCONN); 54 | E(WSAESHUTDOWN); 55 | E(WSAETIMEDOUT); 56 | E(WSAECONNREFUSED); 57 | E(WSAEHOSTDOWN); 58 | E(WSAEHOSTUNREACH); 59 | E(WSAEPROCLIM); 60 | E(WSASYSNOTREADY); 61 | E(WSAVERNOTSUPPORTED); 62 | E(WSANOTINITIALISED); 63 | E(WSAEDISCON); 64 | E(WSATYPE_NOT_FOUND); 65 | E(WSAHOST_NOT_FOUND); 66 | E(WSATRY_AGAIN); 67 | E(WSANO_RECOVERY); 68 | E(WSANO_DATA); 69 | E(0xdeadbeef); /* test the case where no message is available */ 70 | 71 | /* fill up the hash table a bit to make sure it grows properly */ 72 | for (j = 0; j < 50; j++) { 73 | int err; 74 | evutil_secure_rng_get_bytes(&err, sizeof(err)); 75 | evutil_socket_error_to_string(err); 76 | } 77 | } 78 | 79 | s2 = evutil_socket_error_to_string (WSAEINTR); 80 | if (s1 != s2) 81 | printf ("caching failed!\n"); 82 | 83 | libevent_global_shutdown (); 84 | 85 | return EXIT_SUCCESS; 86 | } 87 | -------------------------------------------------------------------------------- /src/levent2/test/regress.rpc: -------------------------------------------------------------------------------- 1 | /* tests data packing and unpacking */ 2 | 3 | struct msg { 4 | string /* sender */ from_name = 1; /* be verbose */ 5 | string to_name = 2; 6 | optional struct[kill] attack = 3; 7 | array struct[run] run = 4; 8 | } 9 | 10 | struct kill { 11 | string weapon = 0x10121; 12 | string action = 2; 13 | array int how_often = 3; 14 | } 15 | 16 | struct run { 17 | string how = 1; 18 | optional bytes some_bytes = 2; 19 | 20 | bytes fixed_bytes[24] = 3; 21 | array string notes = 4; 22 | 23 | optional int64 large_number = 5; 24 | array int other_numbers = 6; 25 | } 26 | -------------------------------------------------------------------------------- /src/levent2/test/regress_minheap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #include "../minheap-internal.h" 27 | 28 | #include 29 | #include "event2/event_struct.h" 30 | 31 | #include "tinytest.h" 32 | #include "tinytest_macros.h" 33 | #include "regress.h" 34 | 35 | static void 36 | set_random_timeout(struct event *ev) 37 | { 38 | ev->ev_timeout.tv_sec = test_weakrand(); 39 | ev->ev_timeout.tv_usec = test_weakrand() & 0xfffff; 40 | ev->ev_timeout_pos.min_heap_idx = -1; 41 | } 42 | 43 | static void 44 | check_heap(struct min_heap *heap) 45 | { 46 | unsigned i; 47 | for (i = 1; i < heap->n; ++i) { 48 | unsigned parent_idx = (i-1)/2; 49 | tt_want(evutil_timercmp(&heap->p[i]->ev_timeout, 50 | &heap->p[parent_idx]->ev_timeout, >=)); 51 | } 52 | } 53 | 54 | static void 55 | test_heap_randomized(void *ptr) 56 | { 57 | struct min_heap heap; 58 | struct event *inserted[1024]; 59 | struct event *e, *last_e; 60 | int i; 61 | 62 | min_heap_ctor_(&heap); 63 | 64 | for (i = 0; i < 1024; ++i) { 65 | inserted[i] = malloc(sizeof(struct event)); 66 | set_random_timeout(inserted[i]); 67 | min_heap_push_(&heap, inserted[i]); 68 | } 69 | check_heap(&heap); 70 | 71 | tt_assert(min_heap_size_(&heap) == 1024); 72 | 73 | for (i = 0; i < 512; ++i) { 74 | min_heap_erase_(&heap, inserted[i]); 75 | if (0 == (i % 32)) 76 | check_heap(&heap); 77 | } 78 | tt_assert(min_heap_size_(&heap) == 512); 79 | 80 | last_e = min_heap_pop_(&heap); 81 | while (1) { 82 | e = min_heap_pop_(&heap); 83 | if (!e) 84 | break; 85 | tt_want(evutil_timercmp(&last_e->ev_timeout, 86 | &e->ev_timeout, <=)); 87 | } 88 | tt_assert(min_heap_size_(&heap) == 0); 89 | end: 90 | for (i = 0; i < 1024; ++i) 91 | free(inserted[i]); 92 | 93 | min_heap_dtor_(&heap); 94 | } 95 | 96 | struct testcase_t minheap_testcases[] = { 97 | { "randomized", test_heap_randomized, 0, NULL, NULL }, 98 | END_OF_TESTCASES 99 | }; 100 | -------------------------------------------------------------------------------- /src/levent2/test/regress_testutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef REGRESS_TESTUTILS_H_INCLUDED_ 28 | #define REGRESS_TESTUTILS_H_INCLUDED_ 29 | 30 | #include "event2/dns.h" 31 | 32 | struct regress_dns_server_table { 33 | const char *q; 34 | const char *anstype; 35 | const char *ans; /* Comma-separated list of IP numbers (e.g. "1.2.3.4", "1.2.3.4,5.6.7.8") */ 36 | int seen; 37 | int lower; 38 | }; 39 | 40 | struct evdns_server_port * 41 | regress_get_udp_dnsserver(struct event_base *base, 42 | ev_uint16_t *portnum, 43 | evutil_socket_t *psock, 44 | evdns_request_callback_fn_type cb, 45 | void *arg); 46 | 47 | struct evdns_server_port * 48 | regress_get_tcp_dnsserver(struct event_base *base, 49 | ev_uint16_t *portnum, 50 | evutil_socket_t *psock, 51 | evdns_request_callback_fn_type cb, 52 | void *arg); 53 | 54 | /* Helper: return the port that a socket is bound on, in host order. */ 55 | int regress_get_socket_port(evutil_socket_t fd); 56 | 57 | /* used to look up pre-canned responses in a search table */ 58 | void regress_dns_server_cb( 59 | struct evdns_server_request *req, void *data); 60 | 61 | /* Globally allocates a dns server that serves from a search table. 62 | TCP and UDP listeners are created on the same port number. If one of the 63 | input search tables is NULL appropriate listener is not created. */ 64 | int regress_dnsserver(struct event_base *base, ev_uint16_t *port, 65 | struct regress_dns_server_table *udp_seach_table, 66 | struct regress_dns_server_table *tcp_seach_table); 67 | 68 | /* clean up the global dns server resources */ 69 | void regress_clean_dnsserver(void); 70 | 71 | struct evconnlistener; 72 | struct sockaddr; 73 | int regress_get_listener_addr(struct evconnlistener *lev, 74 | struct sockaddr *sa, ev_socklen_t *socklen); 75 | 76 | /* Parse comma-separated list of IP addresses. */ 77 | int parse_csv_address_list(const char *s, int family, 78 | void *addrs, size_t addrs_size); 79 | 80 | #endif /* REGRESS_TESTUTILS_H_INCLUDED_ */ 81 | 82 | -------------------------------------------------------------------------------- /src/levent2/test/regress_thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef REGRESS_THREAD_H_INCLUDED_ 28 | #define REGRESS_THREAD_H_INCLUDED_ 29 | 30 | #if defined(_WIN32) /** _WIN32 */ 31 | #define THREAD_T void * /* HANDLE */ 32 | #define THREAD_FN unsigned __stdcall 33 | #define THREAD_RETURN() return (0) 34 | #define THREAD_SELF() GetCurrentThreadId() 35 | #define THREAD_START(threadvar, fn, arg) do { \ 36 | uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ 37 | (threadvar) = (THREAD_T)threadhandle; \ 38 | thread_setup(threadvar); \ 39 | } while (0) 40 | #define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) 41 | #else /* !_WIN32 */ 42 | #include 43 | #define THREAD_T pthread_t 44 | #define THREAD_FN void * 45 | #define THREAD_RETURN() return (NULL) 46 | #define THREAD_SELF() pthread_self() 47 | #define THREAD_START(threadvar, fn, arg) do { \ 48 | if (!pthread_create(&(threadvar), NULL, fn, arg)) \ 49 | thread_setup(threadvar); \ 50 | } while (0) 51 | #define THREAD_JOIN(th) pthread_join(th, NULL) 52 | #endif /* \!_WIN32 */ 53 | 54 | void thread_setup(THREAD_T pthread); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/levent2/test/rpcgen_wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # libevent rpcgen_wrapper.sh 3 | # Transforms event_rpcgen.py failure into success for make, only if 4 | # regress.gen.c and regress.gen.h already exist in $srcdir. This 5 | # is needed for "make distcheck" to pass the read-only $srcdir build, 6 | # as with read-only sources fresh from tarball, regress.gen.[ch] will 7 | # be correct in $srcdir but unwritable. This previously triggered 8 | # Makefile.am to create stub regress.gen.c and regress.gen.h in the 9 | # distcheck _build directory, which were then detected as leftover 10 | # files in the build tree after distclean, breaking distcheck. 11 | # Note that regress.gen.[ch] are not in fresh git clones, making 12 | # working Python a requirement for make distcheck of a git tree. 13 | 14 | exit_updated() { 15 | # echo "Updated ${srcdir}/regress.gen.c and ${srcdir}/regress.gen.h" 16 | exit 0 17 | } 18 | 19 | exit_reuse() { 20 | echo "event_rpcgen.py failed, ${srcdir}/regress.gen.\[ch\] will be reused." >&2 21 | exit 0 22 | } 23 | 24 | exit_failed() { 25 | echo "Could not generate regress.gen.\[ch\] using event_rpcgen.sh" >&2 26 | exit 1 27 | } 28 | srcdir=$1 29 | srcdir=${srcdir:-.} 30 | 31 | ${srcdir}/../event_rpcgen.py --quiet ${srcdir}/regress.rpc \ 32 | test/regress.gen.h test/regress.gen.c 33 | 34 | case "$?" in 35 | 0) 36 | exit_updated 37 | ;; 38 | *) 39 | test -r ${srcdir}/regress.gen.c -a -r ${srcdir}/regress.gen.h && \ 40 | exit_reuse 41 | exit_failed 42 | ;; 43 | esac 44 | -------------------------------------------------------------------------------- /src/levent2/test/test-eof.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "../util-internal.h" 28 | #include "event2/event-config.h" 29 | 30 | #ifdef _WIN32 31 | #include 32 | #else 33 | #include 34 | #endif 35 | #include 36 | #include 37 | #ifdef EVENT__HAVE_SYS_TIME_H 38 | #include 39 | #endif 40 | #ifdef EVENT__HAVE_SYS_SOCKET_H 41 | #include 42 | #endif 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | #include 51 | 52 | int test_okay = 1; 53 | int called = 0; 54 | struct timeval timeout = {60, 0}; 55 | 56 | static void 57 | read_cb(evutil_socket_t fd, short event, void *arg) 58 | { 59 | char buf[256]; 60 | int len; 61 | 62 | if (EV_TIMEOUT & event) { 63 | printf("%s: Timeout!\n", __func__); 64 | exit(1); 65 | } 66 | 67 | len = recv(fd, buf, sizeof(buf), 0); 68 | 69 | printf("%s: read %d%s\n", __func__, 70 | len, len ? "" : " - means EOF"); 71 | 72 | if (len) { 73 | if (!called) 74 | event_add(arg, &timeout); 75 | } else if (called == 1) 76 | test_okay = 0; 77 | 78 | called++; 79 | } 80 | 81 | int 82 | main(int argc, char **argv) 83 | { 84 | struct event ev; 85 | const char *test = "test string"; 86 | evutil_socket_t pair[2]; 87 | 88 | #ifdef _WIN32 89 | WORD wVersionRequested; 90 | WSADATA wsaData; 91 | 92 | wVersionRequested = MAKEWORD(2, 2); 93 | 94 | (void) WSAStartup(wVersionRequested, &wsaData); 95 | #endif 96 | 97 | if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) 98 | return (1); 99 | 100 | 101 | if (send(pair[0], test, (int)strlen(test)+1, 0) < 0) 102 | return (1); 103 | shutdown(pair[0], EVUTIL_SHUT_WR); 104 | 105 | /* Initialize the event library */ 106 | event_init(); 107 | 108 | /* Initialize one event */ 109 | event_set(&ev, pair[1], EV_READ | EV_TIMEOUT, read_cb, &ev); 110 | 111 | event_add(&ev, &timeout); 112 | 113 | event_dispatch(); 114 | 115 | return (test_okay); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /src/levent2/test/test-init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "event2/event-config.h" 28 | 29 | #include 30 | #include 31 | #ifdef EVENT__HAVE_SYS_TIME_H 32 | #include 33 | #endif 34 | #ifdef EVENT__HAVE_SYS_SOCKET_H 35 | #include 36 | #endif 37 | #include 38 | #include 39 | #include 40 | #include 41 | #ifndef _WIN32 42 | #include 43 | #endif 44 | #include 45 | 46 | #include 47 | 48 | int 49 | main(int argc, char **argv) 50 | { 51 | #ifdef _WIN32 52 | WORD wVersionRequested; 53 | WSADATA wsaData; 54 | 55 | wVersionRequested = MAKEWORD(2, 2); 56 | 57 | (void) WSAStartup(wVersionRequested, &wsaData); 58 | #endif 59 | 60 | /* Initialize the event library */ 61 | event_init(); 62 | 63 | return (0); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/levent2/test/test-ratelim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | FAILED=no 4 | 5 | if test "$TEST_OUTPUT_FILE" = "" 6 | then 7 | TEST_OUTPUT_FILE=/dev/null 8 | fi 9 | 10 | # /bin/echo is a little more likely to support -n than sh's builtin echo. 11 | if test -x /bin/echo 12 | then 13 | ECHO=/bin/echo 14 | else 15 | ECHO=echo 16 | fi 17 | 18 | if test "$TEST_OUTPUT_FILE" != "/dev/null" 19 | then 20 | touch "$TEST_OUTPUT_FILE" || exit 1 21 | fi 22 | 23 | TEST_DIR=. 24 | 25 | T=`echo "$0" | sed -e 's/test-ratelim.sh$//'` 26 | if test -x "$T/test-ratelim" 27 | then 28 | TEST_DIR="$T" 29 | fi 30 | 31 | announce () { 32 | echo $@ 33 | echo $@ >>"$TEST_OUTPUT_FILE" 34 | } 35 | 36 | announce_n () { 37 | $ECHO -n $@ 38 | echo $@ >>"$TEST_OUTPUT_FILE" 39 | } 40 | 41 | 42 | run_tests () { 43 | announce_n " Group limits, no connection limit:" 44 | if $TEST_DIR/test-ratelim -g 30000 -n 30 -t 100 --check-grouplimit 1000 --check-stddev 100 >>"$TEST_OUTPUT_FILE" 45 | then 46 | announce OKAY 47 | else 48 | announce FAILED 49 | FAILED=yes 50 | fi 51 | 52 | announce_n " Connection limit, no group limit:" 53 | if $TEST_DIR/test-ratelim -c 1000 -n 30 -t 100 --check-connlimit 50 --check-stddev 50 >>"$TEST_OUTPUT_FILE" 54 | then 55 | announce OKAY ; 56 | else 57 | announce FAILED ; 58 | FAILED=yes 59 | fi 60 | 61 | announce_n " Connection limit and group limit:" 62 | if $TEST_DIR/test-ratelim -c 1000 -g 30000 -n 30 -t 100 --check-grouplimit 1000 --check-connlimit 50 --check-stddev 50 >>"$TEST_OUTPUT_FILE" 63 | then 64 | announce OKAY ; 65 | else 66 | announce FAILED ; 67 | FAILED=yes 68 | fi 69 | 70 | announce_n " Connection limit and group limit with independent drain:" 71 | if $TEST_DIR/test-ratelim -c 1000 -g 35000 -n 30 -t 100 -G 500 --check-grouplimit 1000 --check-connlimit 50 --check-stddev 50 >>"$TEST_OUTPUT_FILE" 72 | then 73 | announce OKAY ; 74 | else 75 | announce FAILED ; 76 | FAILED=yes 77 | fi 78 | 79 | 80 | } 81 | 82 | announce "Running rate-limiting tests:" 83 | 84 | run_tests 85 | 86 | if test "$FAILED" = "yes"; then 87 | exit 1 88 | fi 89 | -------------------------------------------------------------------------------- /src/levent2/test/test-weof.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "../util-internal.h" 28 | #include "event2/event-config.h" 29 | 30 | #ifdef _WIN32 31 | #include 32 | #else 33 | #include 34 | #endif 35 | #include 36 | #include 37 | #ifdef EVENT__HAVE_SYS_TIME_H 38 | #include 39 | #endif 40 | #ifdef EVENT__HAVE_SYS_SOCKET_H 41 | #include 42 | #endif 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include "event2/event.h" 51 | #include "event2/event_struct.h" 52 | #include "event2/event_compat.h" 53 | #include "event2/util.h" 54 | 55 | evutil_socket_t pair[2]; 56 | int test_okay = 1; 57 | int called = 0; 58 | 59 | static void 60 | write_cb(evutil_socket_t fd, short event, void *arg) 61 | { 62 | const char *test = "test string"; 63 | int len; 64 | 65 | len = send(fd, test, (int)strlen(test) + 1, 0); 66 | 67 | printf("%s: write %d%s\n", __func__, 68 | len, len ? "" : " - means EOF"); 69 | 70 | if (len > 0) { 71 | if (!called) 72 | event_add(arg, NULL); 73 | evutil_closesocket(pair[0]); 74 | } else if (called == 1) 75 | test_okay = 0; 76 | 77 | called++; 78 | } 79 | 80 | int 81 | main(int argc, char **argv) 82 | { 83 | struct event ev; 84 | 85 | #ifdef _WIN32 86 | WORD wVersionRequested; 87 | WSADATA wsaData; 88 | 89 | wVersionRequested = MAKEWORD(2, 2); 90 | 91 | (void) WSAStartup(wVersionRequested, &wsaData); 92 | #endif 93 | 94 | #ifndef _WIN32 95 | if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) 96 | return (1); 97 | #endif 98 | 99 | if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) 100 | return (1); 101 | 102 | /* Initialize the event library */ 103 | event_init(); 104 | 105 | /* Initialize one event */ 106 | event_set(&ev, pair[1], EV_WRITE, write_cb, &ev); 107 | 108 | event_add(&ev, NULL); 109 | 110 | event_dispatch(); 111 | 112 | return (test_okay); 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/levent2/test/tinytest_local.h: -------------------------------------------------------------------------------- 1 | 2 | #include "util-internal.h" 3 | #ifdef _WIN32 4 | #include 5 | #endif 6 | 7 | #include "event2/util.h" 8 | 9 | #ifdef snprintf 10 | #undef snprintf 11 | #endif 12 | #define snprintf evutil_snprintf 13 | -------------------------------------------------------------------------------- /src/levent2/time-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef TIME_INTERNAL_H_INCLUDED_ 28 | #define TIME_INTERNAL_H_INCLUDED_ 29 | 30 | #include "event2/event-config.h" 31 | #include "evconfig-private.h" 32 | 33 | #ifdef EVENT__HAVE_MACH_MACH_TIME_H 34 | /* For mach_timebase_info */ 35 | #include 36 | #endif 37 | 38 | #include 39 | 40 | #include "event2/util.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) 47 | #define HAVE_POSIX_MONOTONIC 48 | #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) 49 | #define HAVE_MACH_MONOTONIC 50 | #elif defined(_WIN32) 51 | #define HAVE_WIN32_MONOTONIC 52 | #else 53 | #define HAVE_FALLBACK_MONOTONIC 54 | #endif 55 | 56 | long evutil_tv_to_msec_(const struct timeval *tv); 57 | EVENT2_EXPORT_SYMBOL 58 | void evutil_usleep_(const struct timeval *tv); 59 | 60 | #ifdef _WIN32 61 | typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void); 62 | #endif 63 | 64 | struct evutil_monotonic_timer { 65 | 66 | #ifdef HAVE_MACH_MONOTONIC 67 | struct mach_timebase_info mach_timebase_units; 68 | #endif 69 | 70 | #ifdef HAVE_POSIX_MONOTONIC 71 | int monotonic_clock; 72 | #endif 73 | 74 | #ifdef HAVE_WIN32_MONOTONIC 75 | ev_GetTickCount_func GetTickCount64_fn; 76 | ev_GetTickCount_func GetTickCount_fn; 77 | ev_uint64_t last_tick_count; 78 | ev_uint64_t adjust_tick_count; 79 | 80 | ev_uint64_t first_tick; 81 | ev_uint64_t first_counter; 82 | double usec_per_count; 83 | int use_performance_counter; 84 | #endif 85 | 86 | struct timeval adjust_monotonic_clock; 87 | struct timeval last_time; 88 | }; 89 | 90 | EVENT2_EXPORT_SYMBOL 91 | int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt, 92 | int flags); 93 | EVENT2_EXPORT_SYMBOL 94 | int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv); 95 | 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 102 | -------------------------------------------------------------------------------- /src/levent2/watch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Redistribution and use in source and binary forms, with or without 3 | * modification, are permitted provided that the following conditions 4 | * are met: 5 | * 1. Redistributions of source code must retain the above copyright 6 | * notice, this list of conditions and the following disclaimer. 7 | * 2. Redistributions in binary form must reproduce the above copyright 8 | * notice, this list of conditions and the following disclaimer in the 9 | * documentation and/or other materials provided with the distribution. 10 | * 3. The name of the author may not be used to endorse or promote products 11 | * derived from this software without specific prior written permission. 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 WARRANTIES 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | */ 24 | 25 | #include "event2/watch.h" 26 | #include "event-internal.h" 27 | #include "evthread-internal.h" 28 | 29 | static inline struct evwatch * 30 | evwatch_new(struct event_base *base, union evwatch_cb callback, void *arg, unsigned type) 31 | { 32 | struct evwatch *watcher = mm_malloc(sizeof(struct evwatch)); 33 | if (!watcher) 34 | return NULL; 35 | watcher->base = base; 36 | watcher->type = type; 37 | watcher->callback = callback; 38 | watcher->arg = arg; 39 | EVBASE_ACQUIRE_LOCK(base, th_base_lock); 40 | TAILQ_INSERT_TAIL(&base->watchers[type], watcher, next); 41 | EVBASE_RELEASE_LOCK(base, th_base_lock); 42 | return watcher; 43 | } 44 | 45 | struct evwatch * 46 | evwatch_prepare_new(struct event_base *base, evwatch_prepare_cb callback, void *arg) 47 | { 48 | union evwatch_cb cb = { .prepare = callback }; 49 | return evwatch_new(base, cb, arg, EVWATCH_PREPARE); 50 | } 51 | 52 | struct evwatch * 53 | evwatch_check_new(struct event_base *base, evwatch_check_cb callback, void *arg) 54 | { 55 | union evwatch_cb cb = { .check = callback }; 56 | return evwatch_new(base, cb, arg, EVWATCH_CHECK); 57 | } 58 | 59 | struct event_base * 60 | evwatch_base(struct evwatch *watcher) 61 | { 62 | return watcher->base; 63 | } 64 | 65 | void 66 | evwatch_free(struct evwatch *watcher) 67 | { 68 | EVBASE_ACQUIRE_LOCK(watcher->base, th_base_lock); 69 | TAILQ_REMOVE(&watcher->base->watchers[watcher->type], watcher, next); 70 | EVBASE_RELEASE_LOCK(watcher->base, th_base_lock); 71 | mm_free(watcher); 72 | } 73 | 74 | int 75 | evwatch_prepare_get_timeout(const struct evwatch_prepare_cb_info *info, struct timeval *timeout) 76 | { 77 | if (info->timeout) { 78 | *timeout = *(info->timeout); 79 | return 1; 80 | } 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /src/log.c: -------------------------------------------------------------------------------- 1 | 2 | #include "common.h" 3 | #include "http_server.h" 4 | #include "log.h" 5 | 6 | int logfile(struct HttpHandlerContext_ * const context, 7 | const int crit, const char * const format, ...) 8 | { 9 | const char *urgency; 10 | va_list va; 11 | char line[MAX_LOG_LINE]; 12 | 13 | #ifndef DEBUG 14 | if (crit == LOG_DEBUG) { 15 | return 0; 16 | } 17 | #endif 18 | switch (crit) { 19 | case LOG_INFO: 20 | urgency = "[INFO] "; 21 | break; 22 | case LOG_WARNING: 23 | urgency = "[WARNING] "; 24 | break; 25 | case LOG_ERR: 26 | urgency = "[ERROR] "; 27 | break; 28 | case LOG_NOTICE: 29 | urgency = "[NOTICE] "; 30 | break; 31 | case LOG_DEBUG: 32 | urgency = "[DEBUG] "; 33 | break; 34 | default: 35 | urgency = ""; 36 | } 37 | va_start(va, format); 38 | vsnprintf(line, sizeof line, format, va); 39 | va_end(va); 40 | 41 | int log_fd; 42 | if (context == NULL || context->log_fd == -1) { 43 | log_fd = STDERR_FILENO; 44 | } else { 45 | log_fd = context->log_fd; 46 | } 47 | safe_write(log_fd, urgency, strlen(urgency), LOG_WRITE_TIMEOUT); 48 | safe_write(log_fd, line, strlen(line), LOG_WRITE_TIMEOUT); 49 | safe_write(log_fd, "\n", (size_t) 1U, LOG_WRITE_TIMEOUT); 50 | 51 | return 0; 52 | } 53 | 54 | int logfile_noformat(struct HttpHandlerContext_ * const context, 55 | const int crit, const char * const msg) 56 | { 57 | return logfile(context, crit, "%s", msg); 58 | } 59 | 60 | int logfile_error(struct HttpHandlerContext_ * const context, 61 | const char * const msg) 62 | { 63 | const char *const err_msg = strerror(errno); 64 | 65 | return logfile(context, LOG_ERR, "%s: %s", msg, err_msg); 66 | } 67 | -------------------------------------------------------------------------------- /src/log.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __LOG_H__ 3 | #define __LOG_H__ 1 4 | 5 | #ifndef MAX_LOG_LINE 6 | # define MAX_LOG_LINE 1024U 7 | #endif 8 | #ifndef LOG_WRITE_TIMEOUT 9 | # define LOG_WRITE_TIMEOUT 10 10 | #endif 11 | 12 | #ifdef DEBUG 13 | # define XDEBUG(X) do { X; } while(0) 14 | #else 15 | # define XDEBUG(X) 16 | #endif 17 | 18 | int logfile(struct HttpHandlerContext_ * const context, 19 | const int crit, const char * const format, ...) 20 | __attribute__ ((format(printf, 3, 4))); 21 | 22 | int logfile_noformat(struct HttpHandlerContext_ * const context, 23 | const int crit, const char * const msg); 24 | 25 | int logfile_error(struct HttpHandlerContext_ * const context, 26 | const char * const msg); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/parser.c: -------------------------------------------------------------------------------- 1 | 2 | #include "common.h" 3 | #include "parser.h" 4 | #include "parser_p.h" 5 | 6 | int generic_parser(const char * const file, 7 | ConfigKeywords *config_keywords) 8 | { 9 | char *linepnt; 10 | char *linepnt2; 11 | FILE *fp; 12 | ConfigKeywords *config_keywords_pnt; 13 | char line[LINE_MAX]; 14 | 15 | if (file == NULL || (fp = fopen(file, "r")) == NULL) { 16 | return -1; 17 | } 18 | while (fgets(line, sizeof line, fp) != NULL) { 19 | line[sizeof line - 1U] = 0; 20 | linepnt = line; 21 | while (*linepnt != 0 && isspace((unsigned char) *linepnt)) { 22 | linepnt++; 23 | } 24 | if (iscntrl((unsigned char) *linepnt) || *linepnt == CONFIG_COMMENT) { 25 | continue; 26 | } 27 | config_keywords_pnt = config_keywords; 28 | do { 29 | size_t keyword_len; 30 | 31 | keyword_len = strlen(config_keywords_pnt->keyword); 32 | if (strncasecmp(config_keywords_pnt->keyword, 33 | linepnt, keyword_len) == 0) { 34 | linepnt += keyword_len; 35 | while (*linepnt != 0 && isspace((unsigned char) *linepnt)) { 36 | linepnt++; 37 | } 38 | if (*linepnt == 0) { 39 | fclose(fp); 40 | return -1; 41 | } 42 | linepnt2 = linepnt + strlen(linepnt) - 1U; 43 | while (linepnt2 != linepnt && 44 | (isspace((unsigned char) *linepnt2) || 45 | iscntrl((unsigned char) *linepnt2))) { 46 | linepnt2--; 47 | } 48 | linepnt2[1] = 0; 49 | if ((*config_keywords_pnt->value = strdup(linepnt)) == NULL) { 50 | fclose(fp); 51 | return -1; 52 | } 53 | break; 54 | } 55 | config_keywords_pnt++; 56 | } while (config_keywords_pnt->keyword != NULL); 57 | if (config_keywords_pnt->keyword == NULL) { 58 | fclose(fp); 59 | return -1; 60 | } 61 | } 62 | fclose(fp); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /src/parser.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __PARSER_H__ 3 | #define __PARSER_H__ 1 4 | 5 | typedef struct ConfigKeywords_ { 6 | const char *keyword; 7 | char **value; 8 | } ConfigKeywords; 9 | 10 | int generic_parser(const char * const file, 11 | ConfigKeywords *config_keywords); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/parser_p.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __PARSER_P_H__ 3 | #define __PARSER_P_H__ 1 4 | 5 | #define CONFIG_COMMENT '#' 6 | 7 | #ifndef LINE_MAX 8 | # define LINE_MAX 4096 9 | #endif 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/public.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DOMAIN_PUBLIC_H__ 3 | #define __DOMAIN_PUBLIC_H__ 1 4 | 5 | #ifndef DEFAULT_CONTENT_TYPE_FOR_PUBLIC_DATA 6 | # define DEFAULT_CONTENT_TYPE_FOR_PUBLIC_DATA "text/plain" 7 | #endif 8 | #ifndef MAX_CONTENT_TYPE_LENGTH 9 | # define MAX_CONTENT_TYPE_LENGTH 100U 10 | #endif 11 | 12 | int handle_public_request(HttpHandlerContext * const context, 13 | const char * const uri, 14 | const char * const opts, 15 | struct evhttp_request * const req); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/query_parser.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUERY_PARSER_H__ 3 | #define __QUERY_PARSER_H__ 1 4 | 5 | #ifndef MAX_URI_COMPONENTS 6 | # define MAX_URI_COMPONENTS 8U 7 | #endif 8 | #ifndef MAX_QUERY_STRING_VARS 9 | # define MAX_QUERY_STRING_VARS 8U 10 | #endif 11 | 12 | typedef int (*QueryParseCB)(void *context, 13 | const BinVal *key, const BinVal *value); 14 | 15 | typedef struct ParsedURI_ { 16 | SBinVal uri_components[MAX_URI_COMPONENTS]; 17 | SBinVal query_string_vars[MAX_QUERY_STRING_VARS]; 18 | size_t nb_uri_components; 19 | size_t nb_query_string_vars; 20 | } ParsedURI; 21 | 22 | int query_parse(const char * const query, QueryParseCB cb, 23 | void * const context); 24 | 25 | int uri_encode_binval(BinVal * const evalue, const BinVal * const value); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/replication_master.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __REPLICATION_MASTER_H__ 3 | #define __REPLICATION_MASTER_H__ 1 4 | 5 | typedef struct ReplicationMasterContext_ { 6 | HttpHandlerContext *context; 7 | unsigned int active_slaves; 8 | unsigned int slaves_in_initial_download; 9 | struct evconnlistener *evl; 10 | Slab r_clients_slab; 11 | } ReplicationMasterContext; 12 | 13 | typedef struct ReplicationClient_ { 14 | ReplicationMasterContext *rm_context; 15 | evutil_socket_t client_fd; 16 | int db_log_fd; 17 | struct bufferevent *bev; 18 | _Bool active; 19 | } ReplicationClient; 20 | 21 | int start_replication_master(HttpHandlerContext * const context, 22 | const char * const replication_master_ip, 23 | const char * const replication_master_port); 24 | 25 | void stop_replication_master(HttpHandlerContext * const context); 26 | 27 | _Bool any_slave_in_initial_download(const HttpHandlerContext * const context); 28 | 29 | int send_to_active_slaves(HttpHandlerContext * const context, 30 | struct evbuffer * const r_entry_buffer); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/replication_slave.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __REPLICATION_SLAVE_H__ 3 | #define __REPLICATION_SLAVE_H__ 1 4 | 5 | typedef struct ReplicationSlaveContext_ { 6 | HttpHandlerContext *context; 7 | struct bufferevent *bev; 8 | } ReplicationSlaveContext; 9 | 10 | int start_replication_slave(HttpHandlerContext * const context, 11 | const char * const replication_master_ip, 12 | const char * const replication_master_port); 13 | 14 | void stop_replication_slave(HttpHandlerContext * const context); 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /src/slab.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __SLAB_H__ 3 | #define __SLAB_H__ 1 4 | 5 | typedef struct Slab_ { 6 | size_t nb_slots_per_chunk; 7 | size_t sizeof_entry; 8 | size_t alignment_gap; 9 | size_t alignment_gap_before_data; 10 | size_t sizeof_slab_slot; 11 | struct SlabChunk_ *first_partial_chunk; 12 | struct SlabChunk_ *first_full_chunk; 13 | const void *name; 14 | } Slab; 15 | 16 | typedef int (*SlabForeachCB)(void *context, void *entry, 17 | const size_t sizeof_entry); 18 | 19 | typedef void (*FreeSlabEntryCB)(void *entry); 20 | 21 | int init_slab(Slab * const slab, const size_t sizeof_entry, 22 | const void * const name); 23 | 24 | void free_slab(Slab * const slab, FreeSlabEntryCB free_cb); 25 | int slab_foreach(Slab * const slab, SlabForeachCB cb, void * const context); 26 | 27 | void *add_entry_to_slab(Slab * const slab, const void * const entry); 28 | int remove_entry_from_slab(Slab * const slab, void * const entry); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /src/slab_p.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __SLAB_P_H__ 3 | #define __SLAB_P_H__ 1 4 | 5 | typedef unsigned long BitmapType; 6 | 7 | typedef struct SlabSlotFodder_ { 8 | struct SlabSlotFodder_ *fodder1; 9 | struct SlabSlotFodder_ *fodder2; 10 | } SlabSlotFodder; 11 | 12 | typedef struct SlabSlotFodderFirst_ { 13 | BitmapType bitmap; 14 | struct SlabSlotFodder_ *fodder; 15 | } SlabSlotFodderFirst; 16 | 17 | typedef struct SlabSlot_ { 18 | struct SlabChunk_ *slab_chunk; 19 | unsigned char unaligned_data[]; 20 | } SlabSlot; 21 | 22 | typedef struct SlabChunk_ { 23 | BitmapType bitmap; 24 | struct SlabChunk_ *next; 25 | struct SlabChunk_ *previous; 26 | SlabSlot unaligned_slots[]; 27 | } SlabChunk; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/slipmap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __SLIPMAP_H__ 3 | #define __SLIPMAP_H__ 1 4 | 5 | typedef struct SlipMap_ { 6 | size_t sizeof_map; 7 | unsigned char map[]; 8 | } SlipMap; 9 | 10 | typedef struct SlipMap * SlipMapPnt; 11 | 12 | SlipMap *new_slip_map(size_t buffer_size); 13 | void free_slip_map(SlipMap * * const slip_map_pnt); 14 | 15 | int add_entry_to_slip_map(SlipMap * * const slip_map_pnt, 16 | void * const key, const size_t key_len, 17 | void * const value, const size_t value_len); 18 | 19 | int replace_entry_in_slip_map(SlipMap * * const slip_map_pnt, 20 | void * const key, const size_t key_len, 21 | void * const value, const size_t value_len); 22 | 23 | int remove_entry_from_slip_map(SlipMap * * const slip_map_pnt, 24 | void * const key, const size_t key_len); 25 | 26 | typedef int (*SlipMapForeachCB)(void *context, 27 | const void * const key, 28 | const size_t key_len, 29 | const void * const value, 30 | const size_t value_len); 31 | 32 | int slip_map_foreach(SlipMap * * const slip_map_pnt, SlipMapForeachCB cb, 33 | void * const context); 34 | 35 | int find_in_slip_map(SlipMap * * const slip_map_pnt, 36 | const void * const key, const size_t key_len, 37 | const void * * const value, size_t * const value_len); 38 | 39 | int dump_slip_map(SlipMap * const * const slip_map_pnt); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/stack.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __STACK_H__ 3 | #define __STACK_H__ 1 4 | 5 | #ifndef STACK_CHUNK_SIZE 6 | # define STACK_CHUNK_SIZE ((size_t) 4096U) 7 | #endif 8 | #define STACK_CHUNK_SIZE_1 (STACK_CHUNK_SIZE - (size_t) 1U) 9 | #ifndef STACK_SHRINK_AFTER_LOW_DEPTH_COUNT 10 | # define STACK_SHRINK_AFTER_LOW_DEPTH_COUNT 100U 11 | #endif 12 | 13 | typedef struct PntStack_ { 14 | unsigned char *stack; 15 | size_t stack_size; 16 | size_t element_size; 17 | size_t depth; 18 | size_t low_depth; 19 | unsigned int low_depth_unreached_count; 20 | } PntStack; 21 | 22 | typedef struct PntStackIterator_ { 23 | PntStack * pnt_stack; 24 | size_t depth; 25 | } PntStackIterator; 26 | 27 | int init_pnt_stack(PntStack * const pnt_stack, 28 | const size_t initial_nb_elements, 29 | const size_t element_size); 30 | 31 | void free_pnt_stack(PntStack * const pnt_stack); 32 | 33 | PntStack *new_pnt_stack(size_t initial_nb_elements, 34 | const size_t element_size); 35 | 36 | int push_pnt_stack(PntStack * const pnt_stack, const void * const pnt); 37 | 38 | void * pop_pnt_stack(PntStack * const pnt_stack); 39 | 40 | typedef int (*PntStackForeachCB)(void *context, void *pnt); 41 | 42 | int pnt_stack_foreach(PntStack * const pnt_stack, PntStackForeachCB cb, 43 | void * const context); 44 | 45 | _Bool pnt_stack_exists(PntStack * const pnt_stack, const void * const pnt); 46 | 47 | int init_pnt_stack_iterator(PntStackIterator * const pnt_stack_iterator, 48 | PntStack * const pnt_stack); 49 | 50 | int pnt_stack_iterator_rewind(PntStackIterator * const pnt_stack_iterator); 51 | void *pnt_stack_iterator_next(PntStackIterator * const pnt_stack_iterator); 52 | void *pnt_stack_cyterator_next(PntStackIterator * const pnt_stack_iterator); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/yajl/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.in 2 | libyajl.a 3 | -------------------------------------------------------------------------------- /src/yajl/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2010, Lloyd Hilaiel. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the 13 | distribution. 14 | 15 | 3. Neither the name of Lloyd Hilaiel nor the names of its 16 | contributors may be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 23 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 28 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /src/yajl/Makefile.am: -------------------------------------------------------------------------------- 1 | if ENABLE_EMBEDDED_YAJL 2 | noinst_LIBRARIES = libyajl.a 3 | endif 4 | 5 | libyajl_a_SOURCES = \ 6 | yajl.c \ 7 | yajl_alloc.c \ 8 | yajl_alloc.h \ 9 | yajl_buf.c \ 10 | yajl_buf.h \ 11 | yajl_bytestack.h \ 12 | yajl_encode.c \ 13 | yajl_encode.h \ 14 | yajl_gen.c \ 15 | yajl_lex.c \ 16 | yajl_lex.h \ 17 | yajl_parser.c \ 18 | yajl_parser.h \ 19 | yajl_tree.c \ 20 | yajl_version.c \ 21 | api/yajl_common.h \ 22 | api/yajl_gen.h \ 23 | api/yajl_parse.h \ 24 | api/yajl_tree.h 25 | 26 | SUBDIRS = api 27 | 28 | EXTRA_DIST = COPYING 29 | -------------------------------------------------------------------------------- /src/yajl/api/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.in 2 | -------------------------------------------------------------------------------- /src/yajl/api/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_HEADERS = \ 3 | yajl_common.h \ 4 | yajl_gen.h \ 5 | yajl_parse.h \ 6 | yajl_tree.h \ 7 | yajl_version.h 8 | -------------------------------------------------------------------------------- /src/yajl/api/yajl_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __YAJL_COMMON_H__ 18 | #define __YAJL_COMMON_H__ 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #define YAJL_MAX_DEPTH 128 27 | 28 | /* msft dll export gunk. To build a DLL on windows, you 29 | * must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared 30 | * DLL, you must define YAJL_SHARED and WIN32 */ 31 | #if (defined(_WIN32) || defined(WIN32)) && defined(YAJL_SHARED) 32 | # ifdef YAJL_BUILD 33 | # define YAJL_API __declspec(dllexport) 34 | # else 35 | # define YAJL_API __declspec(dllimport) 36 | # endif 37 | #else 38 | # if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303 39 | # define YAJL_API __attribute__ ((visibility("default"))) 40 | # else 41 | # define YAJL_API 42 | # endif 43 | #endif 44 | 45 | /** pointer to a malloc function, supporting client overriding memory 46 | * allocation routines */ 47 | typedef void * (*yajl_malloc_func)(void *ctx, size_t sz); 48 | 49 | /** pointer to a free function, supporting client overriding memory 50 | * allocation routines */ 51 | typedef void (*yajl_free_func)(void *ctx, void * ptr); 52 | 53 | /** pointer to a realloc function which can resize an allocation. */ 54 | typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz); 55 | 56 | /** A structure which can be passed to yajl_*_alloc routines to allow the 57 | * client to specify memory allocation functions to be used. */ 58 | typedef struct 59 | { 60 | /** pointer to a function that can allocate uninitialized memory */ 61 | yajl_malloc_func malloc; 62 | /** pointer to a function that can resize memory allocations */ 63 | yajl_realloc_func realloc; 64 | /** pointer to a function that can free memory allocated using 65 | * reallocFunction or mallocFunction */ 66 | yajl_free_func free; 67 | /** a context pointer that will be passed to above allocation routines */ 68 | void * ctx; 69 | } yajl_alloc_funcs; 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/yajl/api/yajl_version.h: -------------------------------------------------------------------------------- 1 | #ifndef YAJL_VERSION_H_ 2 | #define YAJL_VERSION_H_ 3 | 4 | #include "yajl_common.h" 5 | 6 | #define YAJL_MAJOR 2 7 | #define YAJL_MINOR 1 8 | #define YAJL_MICRO 1 9 | 10 | #define YAJL_VERSION ((YAJL_MAJOR * 10000) + (YAJL_MINOR * 100) + YAJL_MICRO) 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern int YAJL_API yajl_version(void); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* YAJL_VERSION_H_ */ 23 | 24 | -------------------------------------------------------------------------------- /src/yajl/yajl_alloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /** 18 | * \file yajl_alloc.h 19 | * default memory allocation routines for yajl which use malloc/realloc and 20 | * free 21 | */ 22 | 23 | #include "yajl_alloc.h" 24 | #include 25 | 26 | static void * yajl_internal_malloc(void *ctx, size_t sz) 27 | { 28 | (void)ctx; 29 | return malloc(sz); 30 | } 31 | 32 | static void * yajl_internal_realloc(void *ctx, void * previous, 33 | size_t sz) 34 | { 35 | (void)ctx; 36 | return realloc(previous, sz); 37 | } 38 | 39 | static void yajl_internal_free(void *ctx, void * ptr) 40 | { 41 | (void)ctx; 42 | free(ptr); 43 | } 44 | 45 | void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf) 46 | { 47 | yaf->malloc = yajl_internal_malloc; 48 | yaf->free = yajl_internal_free; 49 | yaf->realloc = yajl_internal_realloc; 50 | yaf->ctx = NULL; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/yajl/yajl_alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /** 18 | * \file yajl_alloc.h 19 | * default memory allocation routines for yajl which use malloc/realloc and 20 | * free 21 | */ 22 | 23 | #ifndef __YAJL_ALLOC_H__ 24 | #define __YAJL_ALLOC_H__ 25 | 26 | #include "api/yajl_common.h" 27 | 28 | #define YA_MALLOC(afs, sz) (afs)->malloc((afs)->ctx, (sz)) 29 | #define YA_FREE(afs, ptr) (afs)->free((afs)->ctx, (ptr)) 30 | #define YA_REALLOC(afs, ptr, sz) (afs)->realloc((afs)->ctx, (ptr), (sz)) 31 | 32 | void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/yajl/yajl_buf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "yajl_buf.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #define YAJL_BUF_INIT_SIZE 2048 24 | 25 | struct yajl_buf_t { 26 | size_t len; 27 | size_t used; 28 | unsigned char * data; 29 | yajl_alloc_funcs * alloc; 30 | }; 31 | 32 | static 33 | void yajl_buf_ensure_available(yajl_buf buf, size_t want) 34 | { 35 | size_t need; 36 | 37 | assert(buf != NULL); 38 | 39 | /* first call */ 40 | if (buf->data == NULL) { 41 | buf->len = YAJL_BUF_INIT_SIZE; 42 | buf->data = (unsigned char *) YA_MALLOC(buf->alloc, buf->len); 43 | buf->data[0] = 0; 44 | } 45 | 46 | need = buf->len; 47 | 48 | while (want >= (need - buf->used)) need <<= 1; 49 | 50 | if (need != buf->len) { 51 | buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need); 52 | buf->len = need; 53 | } 54 | } 55 | 56 | yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc) 57 | { 58 | yajl_buf b = YA_MALLOC(alloc, sizeof(struct yajl_buf_t)); 59 | memset((void *) b, 0, sizeof(struct yajl_buf_t)); 60 | b->alloc = alloc; 61 | return b; 62 | } 63 | 64 | void yajl_buf_free(yajl_buf buf) 65 | { 66 | assert(buf != NULL); 67 | if (buf->data) YA_FREE(buf->alloc, buf->data); 68 | YA_FREE(buf->alloc, buf); 69 | } 70 | 71 | void yajl_buf_append(yajl_buf buf, const void * data, size_t len) 72 | { 73 | yajl_buf_ensure_available(buf, len); 74 | if (len > 0) { 75 | assert(data != NULL); 76 | memcpy(buf->data + buf->used, data, len); 77 | buf->used += len; 78 | buf->data[buf->used] = 0; 79 | } 80 | } 81 | 82 | void yajl_buf_clear(yajl_buf buf) 83 | { 84 | buf->used = 0; 85 | if (buf->data) buf->data[buf->used] = 0; 86 | } 87 | 88 | const unsigned char * yajl_buf_data(yajl_buf buf) 89 | { 90 | return buf->data; 91 | } 92 | 93 | size_t yajl_buf_len(yajl_buf buf) 94 | { 95 | return buf->used; 96 | } 97 | 98 | void 99 | yajl_buf_truncate(yajl_buf buf, size_t len) 100 | { 101 | assert(len <= buf->used); 102 | buf->used = len; 103 | } 104 | -------------------------------------------------------------------------------- /src/yajl/yajl_buf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __YAJL_BUF_H__ 18 | #define __YAJL_BUF_H__ 19 | 20 | #include "api/yajl_common.h" 21 | #include "yajl_alloc.h" 22 | 23 | /* 24 | * Implementation/performance notes. If this were moved to a header 25 | * only implementation using #define's where possible we might be 26 | * able to sqeeze a little performance out of the guy by killing function 27 | * call overhead. YMMV. 28 | */ 29 | 30 | /** 31 | * yajl_buf is a buffer with exponential growth. the buffer ensures that 32 | * you are always null padded. 33 | */ 34 | typedef struct yajl_buf_t * yajl_buf; 35 | 36 | /* allocate a new buffer */ 37 | yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc); 38 | 39 | /* free the buffer */ 40 | void yajl_buf_free(yajl_buf buf); 41 | 42 | /* append a number of bytes to the buffer */ 43 | void yajl_buf_append(yajl_buf buf, const void * data, size_t len); 44 | 45 | /* empty the buffer */ 46 | void yajl_buf_clear(yajl_buf buf); 47 | 48 | /* get a pointer to the beginning of the buffer */ 49 | const unsigned char * yajl_buf_data(yajl_buf buf); 50 | 51 | /* get the length of the buffer */ 52 | size_t yajl_buf_len(yajl_buf buf); 53 | 54 | /* truncate the buffer */ 55 | void yajl_buf_truncate(yajl_buf buf, size_t len); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/yajl/yajl_bytestack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * A header only implementation of a simple stack of bytes, used in YAJL 19 | * to maintain parse state. 20 | */ 21 | 22 | #ifndef __YAJL_BYTESTACK_H__ 23 | #define __YAJL_BYTESTACK_H__ 24 | 25 | #include "api/yajl_common.h" 26 | 27 | #define YAJL_BS_INC 128 28 | 29 | typedef struct yajl_bytestack_t 30 | { 31 | unsigned char * stack; 32 | size_t size; 33 | size_t used; 34 | yajl_alloc_funcs * yaf; 35 | } yajl_bytestack; 36 | 37 | /* initialize a bytestack */ 38 | #define yajl_bs_init(obs, _yaf) { \ 39 | (obs).stack = NULL; \ 40 | (obs).size = 0; \ 41 | (obs).used = 0; \ 42 | (obs).yaf = (_yaf); \ 43 | } \ 44 | 45 | 46 | /* initialize a bytestack */ 47 | #define yajl_bs_free(obs) \ 48 | if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack); 49 | 50 | #define yajl_bs_current(obs) \ 51 | (assert((obs).used > 0), (obs).stack[(obs).used - 1]) 52 | 53 | #define yajl_bs_push(obs, byte) { \ 54 | if (((obs).size - (obs).used) == 0) { \ 55 | (obs).size += YAJL_BS_INC; \ 56 | (obs).stack = (obs).yaf->realloc((obs).yaf->ctx,\ 57 | (void *) (obs).stack, (obs).size);\ 58 | } \ 59 | (obs).stack[((obs).used)++] = (byte); \ 60 | } 61 | 62 | /* removes the top item of the stack, returns nothing */ 63 | #define yajl_bs_pop(obs) { ((obs).used)--; } 64 | 65 | #define yajl_bs_set(obs, byte) \ 66 | (obs).stack[((obs).used) - 1] = (byte); 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/yajl/yajl_encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __YAJL_ENCODE_H__ 18 | #define __YAJL_ENCODE_H__ 19 | 20 | #include "yajl_buf.h" 21 | #include "api/yajl_gen.h" 22 | 23 | void yajl_string_encode(const yajl_print_t printer, 24 | void * ctx, 25 | const unsigned char * str, 26 | size_t length, 27 | int escape_solidus); 28 | 29 | void yajl_string_decode(yajl_buf buf, const unsigned char * str, 30 | size_t length); 31 | 32 | int yajl_string_validate_utf8(const unsigned char * s, size_t len); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/yajl/yajl_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel 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 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __YAJL_PARSER_H__ 18 | #define __YAJL_PARSER_H__ 19 | 20 | #include "api/yajl_parse.h" 21 | #include "yajl_bytestack.h" 22 | #include "yajl_buf.h" 23 | #include "yajl_lex.h" 24 | 25 | 26 | typedef enum { 27 | yajl_state_start = 0, 28 | yajl_state_parse_complete, 29 | yajl_state_parse_error, 30 | yajl_state_lexical_error, 31 | yajl_state_map_start, 32 | yajl_state_map_sep, 33 | yajl_state_map_need_val, 34 | yajl_state_map_got_val, 35 | yajl_state_map_need_key, 36 | yajl_state_array_start, 37 | yajl_state_array_got_val, 38 | yajl_state_array_need_val, 39 | yajl_state_got_value, 40 | } yajl_state; 41 | 42 | struct yajl_handle_t { 43 | const yajl_callbacks * callbacks; 44 | void * ctx; 45 | yajl_lexer lexer; 46 | const char * parseError; 47 | /* the number of bytes consumed from the last client buffer, 48 | * in the case of an error this will be an error offset, in the 49 | * case of an error this can be used as the error offset */ 50 | size_t bytesConsumed; 51 | /* temporary storage for decoded strings */ 52 | yajl_buf decodeBuf; 53 | /* a stack of states. access with yajl_state_XXX routines */ 54 | yajl_bytestack stateStack; 55 | /* memory allocation routines */ 56 | yajl_alloc_funcs alloc; 57 | /* bitfield */ 58 | unsigned int flags; 59 | }; 60 | 61 | yajl_status 62 | yajl_do_parse(yajl_handle handle, const unsigned char * jsonText, 63 | size_t jsonTextLen); 64 | 65 | yajl_status 66 | yajl_do_finish(yajl_handle handle); 67 | 68 | unsigned char * 69 | yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, 70 | size_t jsonTextLen, int verbose); 71 | 72 | /* A little built in integer parsing routine with the same semantics as strtol 73 | * that's unaffected by LOCALE. */ 74 | long long 75 | yajl_parse_integer(const unsigned char *number, unsigned int length); 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/yajl/yajl_version.c: -------------------------------------------------------------------------------- 1 | #include "api/yajl_version.h" 2 | 3 | int yajl_version(void) 4 | { 5 | return YAJL_VERSION; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /test/Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'cucumber' 3 | require 'cucumber/rake/task' 4 | require 'rake/clean' 5 | 6 | Cucumber::Rake::Task.new 7 | 8 | CLEAN.include('test_utils') 9 | 10 | file 'test_utils' => ["test_utils.c", "../src/utils.c"] do 11 | sh "cc -o test_utils test_utils.c ../src/utils.c ../src/slipmap.c ../src/log.c ../src/keys.c ../src/stack.c ../src/key_nodes.c ../src/expirables.c ../src/slab.c ../src/pandb.c -I../src -I../src/yajl/api -I.. -I../src/levent2/include -I../src/levent2 ../src/levent2/.libs/libevent.a ../src/levent2/.libs/libevent_pthreads.a ../src/yajl/libyajl.a -lm -lrt" 12 | end 13 | 14 | task :unittest => [:test_utils] do 15 | sh "./test_utils" 16 | end 17 | 18 | task :default => [:unittest, :cucumber] 19 | -------------------------------------------------------------------------------- /test/features/layer.feature: -------------------------------------------------------------------------------- 1 | Feature: Layer API 2 | Client should be able to edit Pincaster layers throught its HTTP API 3 | Scenario: create/get/delete 4 | Given Pincaster is started 5 | When Client POST /api/1.0/layers/tlay.json '' 6 | Then Pincaster returns: 7 | """ 8 | { 9 | "status": "created" 10 | } 11 | """ 12 | When Client GET /api/1.0/layers/index.json 13 | Then Pincaster returns: 14 | """ 15 | { 16 | "layers": [ 17 | { 18 | "name": "tlay", 19 | "records": 0, 20 | "geo_records": 0, 21 | "type": "geoidal", 22 | "distance_accuracy": "fast", 23 | "latitude_accuracy": 0.0001, 24 | "longitude_accuracy": 0.0001, 25 | "bounds": [ 26 | -180, 27 | -180, 28 | 180, 29 | 180 30 | ] 31 | } 32 | ] 33 | } 34 | """ 35 | When Client DELETE /api/1.0/layers/tlay.json 36 | Then Pincaster returns: 37 | """ 38 | { 39 | "status": "deleted" 40 | } 41 | """ 42 | When Client GET /api/1.0/layers/index.json 43 | Then Pincaster returns: 44 | """ 45 | { 46 | "layers": [ 47 | ] 48 | } 49 | """ 50 | -------------------------------------------------------------------------------- /test/features/public.feature: -------------------------------------------------------------------------------- 1 | Feature: Public API 2 | Pincaster can also act like a web server and directly serve documents stored in keys. 3 | Scenario: get 4 | Given Pincaster is started 5 | And Layer 'restaurants' is created 6 | And Record 'abcd' is created in layer 'restaurants' with location '_loc=48.512,2.243' and properties 'name=MacDonalds&address=blabla&visits=100000&$content=

Hello world

&$content_type=text/html' 7 | When Client GET /public/restaurants/abcd 8 | Then Pincaster returns text/html: 9 | """ 10 |

Hello world

11 | """ 12 | -------------------------------------------------------------------------------- /test/features/record.feature: -------------------------------------------------------------------------------- 1 | Feature: Record API 2 | Client should be able to edit Pincaster records throught its HTTP API 3 | Scenario: create/get/delete 4 | Given Pincaster is started 5 | And Layer 'tlay' is created 6 | When Client PUT /api/1.0/records/tlay/home.json 'description=Maison&who=Robert' 7 | Then Pincaster returns: 8 | """ 9 | { 10 | "status": "stored" 11 | } 12 | """ 13 | When Client GET /api/1.0/records/tlay/home.json 14 | Then Pincaster returns: 15 | """ 16 | { 17 | "key": "home", 18 | "type": "hash", 19 | "properties": { 20 | "description": "Maison", 21 | "who": "Robert" 22 | } 23 | } 24 | """ 25 | When Client DELETE /api/1.0/records/tlay/home.json 26 | Then Pincaster returns: 27 | """ 28 | { 29 | "status": "deleted" 30 | } 31 | """ 32 | When Client GET /api/1.0/records/tlay/home.json 33 | Then Pincaster throws 404 34 | Scenario: create/update/delete properties 35 | Given Pincaster is started 36 | And Layer 'restaurants' is created 37 | When Client PUT /api/1.0/records/restaurants/abcd.json '_loc=48.512,2.243' 38 | Then Pincaster returns: 39 | """ 40 | { 41 | "status": "stored" 42 | } 43 | """ 44 | When Client GET /api/1.0/records/restaurants/abcd.json 45 | Then Pincaster returns: 46 | """ 47 | { 48 | "key": "abcd", 49 | "type": "point", 50 | "latitude": 48.512, 51 | "longitude": 2.243 52 | } 53 | """ 54 | When Client PUT /api/1.0/records/restaurants/abcd.json 'name=MacDonalds&closed=1&address=blabla&visits=100000' 55 | Then Pincaster returns: 56 | """ 57 | { 58 | "status": "stored" 59 | } 60 | """ 61 | When Client GET /api/1.0/records/restaurants/abcd.json 62 | Then Pincaster returns: 63 | """ 64 | { 65 | "key": "abcd", 66 | "type": "point+hash", 67 | "latitude": 48.512, 68 | "longitude": 2.243, 69 | "properties": { 70 | "name": "MacDonalds", 71 | "closed": "1", 72 | "address": "blabla", 73 | "visits": "100000" 74 | } 75 | } 76 | """ 77 | When Client PUT /api/1.0/records/restaurants/abcd.json '_delete:closed=1&_add_int:visits=127' 78 | Then Pincaster returns: 79 | """ 80 | { 81 | "status": "stored" 82 | } 83 | """ 84 | When Client GET /api/1.0/records/restaurants/abcd.json 85 | Then Pincaster returns: 86 | """ 87 | { 88 | "key": "abcd", 89 | "type": "point+hash", 90 | "latitude": 48.512, 91 | "longitude": 2.243, 92 | "properties": { 93 | "name": "MacDonalds", 94 | "address": "blabla", 95 | "visits": "100127" 96 | } 97 | } 98 | """ 99 | -------------------------------------------------------------------------------- /test/features/step_definitions/pincaster.rb: -------------------------------------------------------------------------------- 1 | require 'rest_client' 2 | require 'json' 3 | 4 | Before do 5 | @pid = fork { exec('../src/pincaster pincaster.conf') } 6 | end 7 | 8 | After do |scenario| 9 | Process.kill("HUP", @pid) 10 | sleep 1 11 | end 12 | 13 | Given /^Pincaster is started$/ do 14 | sleep 1 15 | end 16 | 17 | Given /^Layer '(.*)' is created$/ do |layer| 18 | RestClient.post 'localhost:4269/api/1.0/layers/'+layer+'.json', '' 19 | end 20 | 21 | Given /^Record '(.*)' is created in layer '(.*)' with location '(.*)' and properties '(.*)'$/ do |record, layer, location, properties| 22 | RestClient.put 'localhost:4269/api/1.0/records/'+layer+'/'+record+'.json', location+'&'+properties 23 | end 24 | 25 | def capture_api_result 26 | begin 27 | result = JSON.parse(yield) 28 | result.delete('tid') 29 | rescue Exception=>e 30 | result = e.class 31 | end 32 | return result 33 | end 34 | 35 | When /^Client GET (\/api\/.*)$/ do |path| 36 | @result = capture_api_result { RestClient.get 'localhost:4269'+path } 37 | end 38 | 39 | When /^Client GET (\/public\/.*)$/ do |path| 40 | @result = RestClient.get 'localhost:4269'+path do |response, request| 41 | @content_type = response.headers[:content_type] 42 | response.return! 43 | end 44 | end 45 | 46 | When /^Client POST (.*) '(.*)'$/ do |path, content| 47 | @result = capture_api_result { RestClient.post 'localhost:4269'+path, content } 48 | end 49 | 50 | When /^Client DELETE (.*)$/ do |path| 51 | @result = capture_api_result { RestClient.delete 'localhost:4269'+path } 52 | end 53 | 54 | When /^Client PUT (.*) '(.*)'$/ do |path, content| 55 | @result = capture_api_result { RestClient.put 'localhost:4269'+path, content } 56 | end 57 | 58 | Then /^Pincaster returns:$/ do |string| 59 | expected = JSON.parse(string) 60 | @result.should == expected 61 | end 62 | 63 | Then /^Pincaster returns (.*):$/ do |expected_content_type, expected_result| 64 | @content_type.should == expected_content_type 65 | @result.should == expected_result 66 | end 67 | 68 | Then /^Pincaster is dead$/ do 69 | @result.should == RestClient::ServerBrokeConnection 70 | end 71 | 72 | Then /^Pincaster throws 404$/ do 73 | @result.should == RestClient::ResourceNotFound 74 | end 75 | -------------------------------------------------------------------------------- /test/features/system.feature: -------------------------------------------------------------------------------- 1 | Feature: System API 2 | Client should be able to control Pincaster process throught its HTTP API 3 | Scenario: ping 4 | Given Pincaster is started 5 | When Client GET /api/1.0/system/ping.json 6 | Then Pincaster returns: 7 | """ 8 | { 9 | "pong": "pong" 10 | } 11 | """ 12 | Scenario: shutdown 13 | Given Pincaster is started 14 | When Client POST /api/1.0/system/shutdown.json '' 15 | Then Pincaster is dead 16 | -------------------------------------------------------------------------------- /test/pincaster.conf: -------------------------------------------------------------------------------- 1 | 2 | ######################################### 3 | # # 4 | # Sample Pincaster configuration file # 5 | # # 6 | ######################################### 7 | 8 | 9 | # Number of workers threads. One per CPU core might not be a bad idea. 10 | 11 | Workers 2 12 | 13 | 14 | # The file name to save the database journal 15 | # You can comment this out if you want a memory-only database. 16 | 17 | DBFileName /tmp/pincaster.db 18 | 19 | 20 | # Listen to this IP address. 21 | # Comment out to listen to * or leave 0.0.0.0 to listen to ipv4.* 22 | 23 | ServerIP 0.0.0.0 24 | 25 | 26 | # Listen to this port number 27 | 28 | ServerPort 4269 29 | 30 | 31 | # Run as a background process 32 | # If you need to kill the process, send a TERM signal, never pkill -9 33 | # unless you absolutely have to. 34 | 35 | Daemonize no 36 | 37 | 38 | # Log file - You should probably change this for a decent location 39 | # Comment out to log to stderr 40 | 41 | # LogFileName /tmp/pincaster.log 42 | 43 | 44 | # Client connection timeout 45 | 46 | Timeout 20 47 | 48 | 49 | # The default type of layer. 50 | # Should be one of: flat, flatwrap, spherical and ellipsoidal. 51 | 52 | DefaultLayerType ellipsoidal 53 | 54 | 55 | # The formula used for distance calculation in radius search. 56 | # In-rect search always uses rhomboid, the reference point 57 | # being the center of the rectangle. 58 | # Should be one of: vincenty, haversine, greatcircle, fast and rhomboid. 59 | 60 | Accuracy fast 61 | 62 | 63 | ############################################################# 64 | # Replication. # 65 | # Don't comment out unless you want to enable replication # 66 | ############################################################# 67 | 68 | 69 | # Replication IP address or host name we should bind as a master 70 | 71 | # ReplicationMasterIp 0.0.0.0 72 | 73 | 74 | # Replication TCP port we should listen to as a master 75 | 76 | # ReplicationMasterPort 4270 77 | 78 | 79 | # Replication IP address or host name of the master, if we are a slave 80 | 81 | # ReplicationSlaveOfIp 10.0.0.0 82 | 83 | 84 | # Replication TCP port of the master, if we are a slave 85 | 86 | # ReplicationSlaveOfPort 4270 87 | 88 | 89 | 90 | ############################################################# 91 | # You should probably not change anything below this line. # 92 | ############################################################# 93 | 94 | 95 | # fsync() every x seconds. 96 | # 0 means fsync() after every write. Safe, but slow. 97 | # -1 means no fsync() at all. 98 | 99 | FsyncPeriod 5 100 | 101 | 102 | # The journal write buffer size. 103 | 104 | JournalBufferSize 4096 105 | 106 | 107 | # The highest number of queued queries waiting for being processed. 108 | 109 | MaxQueuedReplies 10000 110 | 111 | 112 | # The bucket size, i.e. the max number of items in each node of the quadtree. 113 | # Ignored, for now. 114 | 115 | BucketSize 50 116 | 117 | 118 | # Nodes within this range will all be in the same bucket. 119 | 120 | DimensionAccuracy 0.0001 121 | 122 | -------------------------------------------------------------------------------- /test/test_utils.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "utils.h" 3 | #include 4 | 5 | int main() { 6 | assert(0.0 != gc_distance_between_ellipsoidal_positions 7 | (&(Position2D){.latitude = 48.510, .longitude = 2.240}, &(Position2D){.latitude = 48.512, .longitude = 2.243})); 8 | return 0; 9 | } 10 | --------------------------------------------------------------------------------