├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── TODO ├── autogen.sh ├── config ├── ax_boost_header.m4 ├── ax_boost_lib.m4 ├── ax_boost_multi_index.m4 ├── ax_boost_prefix.m4 ├── ax_boost_python.m4 ├── ax_boost_required.m4 ├── ax_boost_system.m4 ├── ax_boost_thread.m4 ├── ax_boost_unit_test.m4 ├── ax_check_compiler_flags.m4 ├── ax_prefix_config_h.m4 ├── ax_python_devel.m4 └── libxml2.m4 ├── configure.in ├── daemon ├── Makefile.am ├── command_line.cpp ├── command_line.hpp ├── main.cpp ├── variable_map.cpp ├── variable_map.hpp ├── xiva.conf.example ├── xml.cpp ├── xml.hpp ├── xml_enumeration.hpp ├── xml_settings.cpp └── xml_settings.hpp ├── debian ├── changelog ├── compat ├── control ├── libxiva-dev.files ├── libxiva.files ├── rules ├── xiva-daemon.files ├── xiva-python.files ├── xiva-stdin-reader.files ├── xiva-syslog.files └── xiva-utils.files ├── doxyfile ├── examples ├── crossdomain.xml ├── xiva-daemon-fastcgi-perl │ ├── debian │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── install │ │ ├── rules │ │ ├── xiva-daemon-fastcgi-perl.init │ │ └── xiva-daemon-fastcgi-perl.logrotate │ └── xiva.pl ├── xiva-daemon-python-configs │ ├── crossdomain.xml │ ├── debian │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── rules │ │ ├── xiva-daemon-python-configs.install │ │ └── xiva-daemon-python-configs.preinst │ ├── xiva-ulimits.conf │ ├── xiva.conf │ └── xiva.init.conf ├── xiva-daemon-python │ ├── debian │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── rules │ │ ├── xiva-daemon-check.install │ │ ├── xiva-daemon-python-dev.install │ │ ├── xiva-daemon-python.init │ │ ├── xiva-daemon-python.install │ │ └── xiva-daemon-python.preinst │ ├── xiva-ulimits.conf.example │ ├── xiva.conf.example │ ├── xiva.init.conf.example │ ├── xiva_check.py │ ├── xiva_clt.py │ ├── xivadaemon.py │ └── xivadaemonstart.sh ├── xiva-daemon-tools-perl │ ├── debian │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── install │ │ └── rules │ └── xiva_cmd.pl ├── xiva-web-chat-lighttpd-config │ ├── 10-xiva-web-chat.conf │ └── debian │ │ ├── changelog │ │ ├── control │ │ ├── install │ │ ├── postinst │ │ └── rules └── xiva-web-chat │ ├── blocks │ ├── b-chat │ │ ├── _type │ │ │ ├── b-chat_chat.css │ │ │ ├── b-chat_chat.ie.css │ │ │ └── b-chat_login.css │ │ └── b-chat.css │ ├── b-login │ │ ├── b-login.css │ │ └── b-login.ie.css │ ├── b-message │ │ ├── _type │ │ │ └── b-message_you.css │ │ ├── b-message.css │ │ └── b-message.ie.css │ ├── b-messages │ │ └── b-messages.css │ ├── b-pseudo-link │ │ └── b-pseudo-link.css │ ├── b-rooms │ │ └── b-rooms.css │ ├── b-userlist │ │ └── b-userlist.css │ ├── b-writemessage │ │ ├── b-writemessage.css │ │ └── b-writemessage.ie.css │ ├── g-hidden │ │ └── g-hidden.css │ ├── g-reset │ │ └── g-reset.css │ └── l-page │ │ ├── html5.js │ │ ├── innershiv.min.js │ │ └── l-page.css │ ├── debian │ ├── changelog │ ├── compat │ ├── control │ └── rules │ ├── index.css │ ├── index.html │ ├── index.ie.css │ ├── index.js │ ├── json2.js │ ├── transport.js │ └── web-socket-js │ ├── FABridge.js │ ├── WebSocketMain.swf │ ├── swfobject.js │ └── web_socket.js ├── include ├── Makefile.am ├── details │ ├── Makefile.am │ ├── acceptor.hpp │ ├── acceptor_base.hpp │ ├── asio.hpp │ ├── channels_stat_impl.hpp │ ├── char_traits.hpp │ ├── compound_listener.hpp │ ├── connection.hpp │ ├── connection_base.hpp │ ├── connection_data.hpp │ ├── connection_impl.hpp │ ├── connection_manager.hpp │ ├── connection_manager_base.hpp │ ├── connection_socket.hpp │ ├── connection_traits.hpp │ ├── connection_traits_base.hpp │ ├── dynamic_loader.hpp │ ├── formatters_data.hpp │ ├── formatters_data_channels.hpp │ ├── formatters_data_simple.hpp │ ├── formatters_factory.hpp │ ├── functors.hpp │ ├── guard.hpp │ ├── handler_invoker.hpp │ ├── handler_invoker_base.hpp │ ├── http.hpp │ ├── http_constants.hpp │ ├── iterator_checker.hpp │ ├── line_reader.hpp │ ├── message_queue.hpp │ ├── range.hpp │ ├── request_checker.hpp │ ├── request_helper.hpp │ ├── request_impl.hpp │ ├── resource.hpp │ ├── response_impl.hpp │ ├── server_impl.hpp │ ├── ssl_connection_socket.hpp │ ├── ssl_connection_traits.hpp │ ├── ssl_context.hpp │ ├── stdio_logger.hpp │ ├── string_utils.hpp │ ├── system_error.hpp │ ├── threaded_connection.hpp │ ├── threaded_handler_invoker.hpp │ ├── threaded_listener.hpp │ ├── threaded_queue.hpp │ ├── threaded_shared.hpp │ ├── url_response_handler.hpp │ ├── urlencode.hpp │ └── websocket_info.hpp ├── xiva.hpp └── xiva │ ├── Makefile.am │ ├── channel_id.hpp │ ├── channel_info.hpp │ ├── component_set.hpp │ ├── config.hpp │ ├── connection_listener.hpp │ ├── enumeration.hpp │ ├── error.hpp │ ├── formatter.hpp │ ├── formatter_creator.hpp │ ├── forward.hpp │ ├── globals.hpp │ ├── http_error.hpp │ ├── logger.hpp │ ├── message.hpp │ ├── message_filter.hpp │ ├── message_sender.hpp │ ├── ping_formatter.hpp │ ├── request.hpp │ ├── response.hpp │ ├── response_handler.hpp │ ├── server.hpp │ ├── settings.hpp │ └── shared.hpp ├── library ├── Makefile.am ├── acceptor_base.cpp ├── channels_stat_impl.cpp ├── component_set.cpp ├── compound_listener.cpp ├── connection.cpp ├── connection_base.cpp ├── connection_data.cpp ├── connection_listener.cpp ├── connection_manager_base.cpp ├── connection_socket.cpp ├── connection_traits_base.cpp ├── dynamic_loader.cpp ├── error.cpp ├── formatter.cpp ├── formatter_creator.cpp ├── formatters_data.cpp ├── formatters_data_channels.cpp ├── formatters_data_simple.cpp ├── formatters_factory.cpp ├── guard.cpp ├── handler_invoker.cpp ├── handler_invoker_base.cpp ├── http.cpp ├── http_constants.cpp ├── http_error.cpp ├── logger.cpp ├── message.cpp ├── message_filter.cpp ├── message_queue.cpp ├── message_sender.cpp ├── ping_formatter.cpp ├── request.cpp ├── request_impl.cpp ├── response.cpp ├── response_handler.cpp ├── response_impl.cpp ├── server.cpp ├── server_impl.cpp ├── settings.cpp ├── ssl_connection_socket.cpp ├── ssl_context.cpp ├── stdio_logger.cpp ├── system_error.cpp ├── threaded_connection.cpp ├── threaded_handler_invoker.cpp ├── threaded_listener.cpp ├── url_response_handler.cpp └── websocket_info.cpp ├── python ├── Makefile.am ├── cleanup_list.cpp ├── cleanup_list.hpp ├── interpreter_lock.cpp ├── interpreter_lock.hpp ├── module.cpp ├── python_enumeration.hpp ├── python_formatter.cpp ├── python_formatter.hpp ├── python_formatter_creator.cpp ├── python_formatter_creator.hpp ├── python_handler.cpp ├── python_handler.hpp ├── python_listener.cpp ├── python_listener.hpp ├── python_logger.cpp ├── python_logger.hpp ├── python_message_filter.cpp ├── python_message_filter.hpp ├── python_ping_formatter.cpp ├── python_ping_formatter.hpp ├── python_request.cpp ├── python_request.hpp ├── python_response.cpp ├── python_response.hpp ├── python_server.cpp ├── python_server.hpp ├── python_settings.cpp ├── python_settings.hpp ├── request_class.hpp ├── response_class.hpp └── server_class.hpp ├── stdext ├── Makefile.am ├── stdin_reader.cpp └── syslog_logger.cpp ├── tests ├── Makefile.am ├── checker_test.cpp ├── date_test.cpp ├── line_reader_test.cpp ├── listener_test.cpp ├── main.cpp ├── manager_test.cpp ├── mock_connection.cpp ├── mock_connection.hpp ├── mock_listener.cpp ├── mock_listener.hpp ├── mock_logger.cpp ├── mock_logger.hpp ├── queue_test.cpp ├── range_test.cpp ├── request_test.cpp ├── settings_test.cpp ├── string_test.cpp ├── test.conf ├── test_utils.hpp ├── url_handler_test.cpp └── urlencode_test.cpp ├── utils ├── Makefile.am └── main.cpp ├── xiva-bf.spec └── xiva.spec /AUTHORS: -------------------------------------------------------------------------------- 1 | Oleg Obolenskiy 2 | Alexey Ponomarev 3 | Grigory Bakunov 4 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = include libltdl library stdext utils 2 | 3 | if HAVE_DAEMON 4 | SUBDIRS += daemon 5 | endif 6 | 7 | if HAVE_PYTHON 8 | SUBDIRS += python 9 | endif 10 | 11 | if HAVE_BOOST_UNIT_TEST 12 | SUBDIRS += tests 13 | endif 14 | 15 | ACLOCAL_AMFLAGS = -I config 16 | 17 | EXTRA_DIST = autogen.sh AUTHORS ChangeLog COPYING INSTALL NEWS README \ 18 | config/ax_boost_header.m4 config/ax_boost_lib.m4 \ 19 | config/ax_boost_multi_index.m4 config/ax_boost_prefix.m4 \ 20 | config/ax_boost_python.m4 config/ax_boost_required.m4 \ 21 | config/ax_boost_system.m4 config/ax_boost_thread.m4 \ 22 | config/ax_boost_unit_test.m4 config/ax_check_compiler_flags.m4 \ 23 | config/ax_prefix_config_h.m4 config/ax_python_devel.m4 \ 24 | config/libxml2.m4 25 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/highpower/xiva/0b89a8c26d577cf6c9e42ceddbf90b712eba4a6a/NEWS -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * Replace std::ostream construction in connection_impl with copying to 2 | streambuf_iterator 3 | 4 | * Fix http error response to send text representing error as well http 5 | status. 6 | 7 | * Make python binding usable. 8 | 9 | * Implement asynchronous (in separate thread) receiver recognizing. 10 | 11 | * Implement fast (asynchronous) logger. 12 | -------------------------------------------------------------------------------- /config/ax_boost_header.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_HEADER], 2 | [ 3 | ax_header_found="yes" 4 | AC_REQUIRE([AX_BOOST_PREFIX]) 5 | 6 | ax_boost_header_stored_cppflags="$CPPFLAGS" 7 | CPPFLAGS="$ax_boost_header_stored_cppflags $BOOST_CPPFLAGS" 8 | AC_CHECK_HEADER([boost/$1], [], [ax_header_found="no"]) 9 | CPPFLAGS="$ax_boost_header_stored_cppflags" 10 | if test "f$ax_header_found" = "fyes"; then 11 | ifelse([$2], , :, [$2]) 12 | else 13 | ifelse([$3], , :, [$3]) 14 | fi 15 | ]) 16 | -------------------------------------------------------------------------------- /config/ax_boost_lib.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_LIB], 2 | [ 3 | AC_REQUIRE([AX_BOOST_PREFIX]) 4 | AC_MSG_CHECKING([for $2]) 5 | ax_check=$2 6 | ax_library="$ax_check" 7 | ax_value=`echo $CPPFLAGS $CXXFLAGS | grep -- -pthread` 8 | if test "f$ax_value" != "f"; then 9 | ax_check="$ax_check-mt" 10 | fi 11 | if test -f "$ax_boost_prefix/lib/lib$ax_check.so"; then 12 | ax_library="$ax_check" 13 | fi 14 | ax_value=`echo $CPPFLAGS $CXXFLAGS | grep -- -g` 15 | if test "f$ax_value" != "f"; then 16 | ax_check="$ax_check-d" 17 | fi 18 | if test -f "$ax_boost_prefix/lib/lib$ax_check.so"; then 19 | ax_library="$ax_check" 20 | fi 21 | $1="$ax_library" 22 | AC_MSG_RESULT([$ax_library]) 23 | ]) 24 | -------------------------------------------------------------------------------- /config/ax_boost_multi_index.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_MULTI_INDEX], 2 | [ 3 | ax_boost_multi_index_stored_cppflags="$CPPFLAGS" 4 | AC_REQUIRE([AX_BOOST_PREFIX]) 5 | CPPFLAGS="$ax_boost_multi_index_stored_cppflags $BOOST_CPPFLAGS -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION" 6 | 7 | ax_have_boost_multi_index="yes" 8 | AX_BOOST_HEADER([multi_index_container.hpp], [], [ax_have_boost_multi_index="no"]) 9 | AX_BOOST_HEADER([multi_index/hashed_index.hpp], [], [ax_have_boost_multi_index="no"]) 10 | AX_BOOST_HEADER([multi_index/ordered_index.hpp], [], [ax_have_boost_multi_index="no"]) 11 | CPPFLAGS="$ax_boost_multi_index_stored_cppflags" 12 | if test "f$ax_have_boost_multi_index" = "fyes"; then 13 | ifelse([$1], , :, [$1]) 14 | else 15 | ifelse([$2], , :, [$2]) 16 | fi 17 | ]) 18 | -------------------------------------------------------------------------------- /config/ax_boost_prefix.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([_AX_CHECK_BOOST_IN], 2 | [ 3 | ax_prefix=$1 4 | AC_MSG_CHECKING([whether boost is installed in $1]) 5 | ax_have_boost_in="yes" 6 | if test ! -d "$ax_prefix/include/boost"; then 7 | ax_have_boost_in="no" 8 | fi 9 | if test ! -d "$ax_prefix/lib"; then 10 | ax_have_boost_in="no" 11 | fi 12 | AC_MSG_RESULT([$ax_have_boost_in]) 13 | if test "f$ax_have_boost_in" = "fyes"; then 14 | ifelse([$2], , :, [$2]) 15 | else 16 | ifelse([$3], , :, [$3]) 17 | fi 18 | ]) 19 | 20 | AC_DEFUN([AX_BOOST_PREFIX], 21 | [ 22 | ax_boost_prefix="" 23 | AC_ARG_WITH([boost-prefix], 24 | AS_HELP_STRING(--with-boost-prefix, specifies boost installation), 25 | [ 26 | if test "f$withval" != "f"; then 27 | ax_boost_prefix="$withval" 28 | fi 29 | ]) 30 | if test "f$ax_boost_prefix" != "f"; then 31 | _AX_CHECK_BOOST_IN([$ax_boost_prefix], [], [ax_boost_prefix=""]) 32 | else 33 | for i in /usr/local /usr; do 34 | _AX_CHECK_BOOST_IN([$i], [ax_boost_prefix="$i"], []) 35 | done; 36 | fi 37 | 38 | if test "f$ax_boost_prefix" != "f"; then 39 | AC_SUBST([BOOST_LDFLAGS], ["-I$ax_boost_prefix/lib"]) 40 | AC_SUBST([BOOST_CPPFLAGS], ["-I$ax_boost_prefix/include"]) 41 | ifelse([$1], , :, [$1]) 42 | else 43 | ifelse([$2], , :, [$2]) 44 | fi 45 | ]) 46 | -------------------------------------------------------------------------------- /config/ax_boost_python.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_PYTHON], 2 | [ 3 | ax_boost_python_stored_ldflags="$LDFLAGS" 4 | ax_boost_python_stored_cppflags="$CPPFLAGS" 5 | 6 | AC_REQUIRE([AX_BOOST_PREFIX]) 7 | AC_REQUIRE([AX_PYTHON_DEVEL]) 8 | AX_BOOST_LIB([ax_boost_python_lib], [boost_python]) 9 | 10 | CPPFLAGS="$ax_boost_python_stored_cppflags $PYTHON_CPPFLAGS" 11 | LDFLAGS="$ax_boost_python_stored_ldflags $BOOST_LDFLAGS -l$ax_boost_python_lib $PYTHON_LDFLAGS" 12 | 13 | ax_have_boost_python="yes" 14 | AX_BOOST_HEADER([python.hpp], [], [ax_have_boost_python="no"]) 15 | 16 | AC_MSG_CHECKING([trying to link with boost::python]) 17 | AC_LINK_IFELSE( 18 | [ AC_LANG_PROGRAM([#include ], [boost::python::str s;]) ], 19 | [ AC_MSG_RESULT(yes) ], 20 | [ AC_MSG_RESULT(no); ax_have_boost_python="no" ]) 21 | 22 | CPPFLAGS="$ax_boost_python_stored_cppflags" 23 | LDFLAGS="$ax_boost_python_stored_ldflags" 24 | 25 | if test "f$ax_have_boost_python" = "fyes"; then 26 | ifelse([$1], , :, [$1]) 27 | AC_SUBST([BOOST_PYTHON_LDFLAGS], ["-l$ax_boost_python_lib"]) 28 | else 29 | ifelse([$2], , :, [$2]) 30 | fi 31 | ]) 32 | -------------------------------------------------------------------------------- /config/ax_boost_required.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_REQUIRED], 2 | [ 3 | ax_header_found="yes" 4 | AC_REQUIRE([AX_BOOST_PREFIX]) 5 | 6 | ax_boost_requeired_stored_cppflags="$CPPFLAGS" 7 | CPPFLAGS="$ax_boost_requeired_stored_cppflags $BOOST_CPPFLAGS" 8 | AC_CHECK_HEADER([boost/$1], [], [ax_header_found="no"]) 9 | CPPFLAGS="$ax_boost_requeired_stored_cppflags" 10 | 11 | if test "f$ax_header_found" != "fyes"; then 12 | AC_MSG_ERROR([required header boost/$1 is not found in $ax_boost_prefix/include]) 13 | fi 14 | ]) 15 | -------------------------------------------------------------------------------- /config/ax_boost_system.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_SYSTEM], 2 | [ 3 | ax_boost_system_stored_ldflags="$LDFLAGS" 4 | 5 | AC_REQUIRE([AX_BOOST_PREFIX]) 6 | AX_BOOST_LIB([ax_boost_system_lib], [boost_system]) 7 | 8 | LDFLAGS="$ax_boost_regex_stored_ldflags $BOOST_LDFLAGS -l$ax_boost_system_lib" 9 | 10 | ax_have_boost_system="yes" 11 | AX_BOOST_HEADER([system/config.hpp], [], [ax_have_boost_system="no"]) 12 | 13 | AC_MSG_CHECKING([trying to link with boost::system]) 14 | AC_LINK_IFELSE( 15 | [ AC_LANG_PROGRAM([#include ], [boost::system::error_code code;]) ], 16 | [ AC_MSG_RESULT(yes) ], 17 | [ AC_MSG_RESULT(no); ax_have_boost_system="no" ]) 18 | 19 | LDFLAGS="$ax_boost_system_stored_ldflags" 20 | 21 | if test "f$ax_have_boost_system" = "fyes"; then 22 | ifelse([$1], , :, [$1]) 23 | AC_SUBST([BOOST_SYSTEM_LDFLAGS], ["-l$ax_boost_system_lib"]) 24 | else 25 | ifelse([$2], , :, [$2]) 26 | fi 27 | ]) 28 | -------------------------------------------------------------------------------- /config/ax_boost_thread.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_THREAD], 2 | [ 3 | ax_boost_thread_stored_ldflags="$LDFLAGS" 4 | 5 | AC_REQUIRE([AX_BOOST_PREFIX]) 6 | AX_BOOST_LIB([ax_boost_thread_lib], [boost_thread]) 7 | 8 | LDFLAGS="$ax_boost_thread_stored_ldflags $BOOST_LDFLAGS -l$ax_boost_thread_lib" 9 | 10 | ax_have_boost_thread="yes" 11 | AX_BOOST_HEADER([thread.hpp], [], [ax_have_boost_thread="no"]) 12 | AX_BOOST_HEADER([thread/mutex.hpp], [], [ax_have_boost_thread="no"]) 13 | AX_BOOST_HEADER([thread/condition.hpp], [], [ax_have_boost_thread="no"]) 14 | AX_BOOST_HEADER([thread/thread.hpp], [], [ax_have_boost_thread="no"]) 15 | 16 | AC_MSG_CHECKING([trying to link with boost::thread]) 17 | AC_LINK_IFELSE( 18 | [ AC_LANG_PROGRAM([#include ], [boost::thread_group g;]) ], 19 | [ AC_MSG_RESULT(yes) ], 20 | [ AC_MSG_RESULT(no); ax_have_boost_thread="no" ]) 21 | 22 | LDFLAGS="$ax_boost_thread_stored_ldflags" 23 | 24 | if test "f$ax_have_boost_thread" = "fyes"; then 25 | ifelse([$1], , :, [$1]) 26 | AC_SUBST([BOOST_THREAD_LDFLAGS], ["-l$ax_boost_thread_lib"]) 27 | else 28 | ifelse([$2], , :, [$2]) 29 | fi 30 | ]) 31 | -------------------------------------------------------------------------------- /config/ax_boost_unit_test.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_BOOST_UNIT_TEST], 2 | [ 3 | ax_boost_unit_test_stored_ldflags="$LDFLAGS" 4 | 5 | AC_REQUIRE([AX_BOOST_PREFIX]) 6 | AX_BOOST_LIB([ax_boost_unit_test_lib], [boost_unit_test_framework]) 7 | 8 | LDFLAGS="$ax_boost_unit_test_stored_ldflags $BOOST_LDFLAGS -l$ax_boost_unit_test_lib" 9 | 10 | ax_have_boost_unit_test="yes" 11 | AX_BOOST_HEADER([test/unit_test.hpp], [], [ax_have_boost_unit_test="no"]) 12 | AX_BOOST_HEADER([test/test_case_template.hpp], [], [ax_have_boost_unit_test="no"]) 13 | 14 | AC_MSG_CHECKING([trying to link with boost::test]) 15 | AC_LINK_IFELSE( 16 | [ AC_LANG_PROGRAM([#include ], []) ], 17 | [ AC_MSG_RESULT(yes) ], 18 | [ AC_MSG_RESULT(no); ax_have_boost_unit_test="no" ]) 19 | 20 | LDFLAGS="$ax_boost_unit_test_stored_ldflags" 21 | 22 | if test "f$ax_have_boost_unit_test" = "fyes"; then 23 | ifelse([$1], , :, [$1]) 24 | AC_SUBST([BOOST_UNIT_TEST_LDFLAGS], ["-l$ax_boost_unit_test_lib"]) 25 | else 26 | ifelse([$2], , :, [$2]) 27 | fi 28 | ]) 29 | -------------------------------------------------------------------------------- /daemon/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libxiva-daemon.la 2 | 3 | libxiva_daemon_la_LIBADD = ${top_srcdir}/library/libxiva.la 4 | libxiva_daemon_la_SOURCES = command_line.cpp xml.cpp xml_settings.cpp \ 5 | variable_map.cpp 6 | 7 | sbin_PROGRAMS = xiva-daemon 8 | xiva_daemon_SOURCES = main.cpp 9 | xiva_daemon_LDADD = libxiva-daemon.la ${top_srcdir}/library/libxiva-loader.la 10 | 11 | AM_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/config \ 12 | @XML_CPPFLAGS@ @BOOST_CPPFLAGS@ @INCLTDL@ 13 | 14 | AM_CXXFLAGS = -pthread 15 | AM_LDFLAGS = @BOOST_LDFLAGS@ @XML_LIBS@ 16 | 17 | noinst_HEADERS = command_line.hpp xml.hpp xml_settings.hpp \ 18 | variable_map.hpp 19 | 20 | dist_sysconf_DATA = xiva.conf.example 21 | -------------------------------------------------------------------------------- /daemon/command_line.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "command_line.hpp" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "xiva/error.hpp" 9 | 10 | namespace xiva { namespace daemon { 11 | 12 | command_line::command_line(int argc, char *argv[]) : 13 | help_mode_(false) 14 | { 15 | for (std::size_t i = 1; i < static_cast(argc); ++i) { 16 | if (strncmp("--help", argv[i], sizeof("--help")) == 0) { 17 | help_mode_ = true; 18 | break; 19 | } 20 | else if (strncmp("--config=", argv[i], sizeof("--config=") - 1) == 0) { 21 | config_file_.assign(argv[i] + sizeof("--config=") - 1); 22 | } 23 | else if (strncmp("--dump-variable=", argv[i], sizeof("--dump-variable=") - 1) == 0) { 24 | dump_variable_.assign(argv[i] + sizeof("--dump-variable=") - 1); 25 | } 26 | } 27 | } 28 | 29 | command_line::~command_line() { 30 | } 31 | 32 | bool 33 | command_line::is_help_mode() const { 34 | return help_mode_; 35 | } 36 | 37 | bool 38 | command_line::is_dump_mode() const { 39 | return !dump_variable_.empty(); 40 | } 41 | 42 | bool 43 | command_line::is_config_file_set() const { 44 | return !config_file_.empty(); 45 | } 46 | 47 | std::string const& 48 | command_line::config_file() const { 49 | return config_file_; 50 | } 51 | 52 | std::string const& 53 | command_line::dump_variable() const { 54 | return dump_variable_; 55 | } 56 | 57 | std::ostream& 58 | command_line::print_usage(std::ostream &stream) { 59 | stream << "usage: xiva-daemon --help | --config= [--dump-variable=]" << std::endl; 60 | return stream; 61 | } 62 | 63 | }} // namespaces 64 | -------------------------------------------------------------------------------- /daemon/command_line.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DAEMON_COMMAND_LINE_HPP_INCLUDED 19 | #define XIVA_DAEMON_COMMAND_LINE_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | namespace xiva { namespace daemon { 25 | 26 | class command_line { 27 | 28 | public: 29 | command_line(int argc, char *argv[]); 30 | virtual ~command_line(); 31 | 32 | bool is_help_mode() const; 33 | bool is_dump_mode() const; 34 | bool is_config_file_set() const; 35 | 36 | std::string const& config_file() const; 37 | std::string const& dump_variable() const; 38 | 39 | static std::ostream& print_usage(std::ostream &stream); 40 | 41 | private: 42 | bool help_mode_; 43 | std::string config_file_, dump_variable_; 44 | }; 45 | 46 | }} // namespaces 47 | 48 | #endif // XIVA_DAEMON_COMMAND_LINE_HPP_INCLUDED 49 | -------------------------------------------------------------------------------- /daemon/main.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "xiva/server.hpp" 9 | #include "details/dynamic_loader.hpp" 10 | #include "xml_settings.hpp" 11 | 12 | int 13 | main(int argc, char *argv[]) { 14 | 15 | try { 16 | xiva::details::dynamic_loader loader; 17 | xiva::daemon::xml_settings settings(argc, argv); 18 | xiva::server server; 19 | 20 | xiva::enumeration::ptr_type en = settings.value_list("/xiva/modules/module"); 21 | while (!en->empty()) { 22 | loader.load_module(en->next(), settings, server.components()); 23 | } 24 | 25 | signal(SIGPIPE, SIG_IGN); 26 | 27 | server.start(settings); 28 | return EXIT_SUCCESS; 29 | } 30 | catch (std::exception const &e) { 31 | std::cerr << e.what() << std::endl; 32 | return EXIT_FAILURE; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /daemon/variable_map.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DAEMON_VARIABLE_MAP_HPP_INCLUDED 19 | #define XIVA_DAEMON_VARIABLE_MAP_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include "xiva/shared.hpp" 25 | 26 | namespace xiva { namespace daemon { 27 | 28 | class variable_map : public shared { 29 | 30 | public: 31 | variable_map(); 32 | virtual ~variable_map(); 33 | 34 | void resolve_variables(std::string &str); 35 | void add_variable(std::string const &name, std::string const &value); 36 | 37 | private: 38 | variable_map(variable_map const &); 39 | variable_map& operator = (variable_map const &); 40 | 41 | std::string const& find_variable(std::string const &name) const; 42 | void resolve_variables(std::string &str, std::string::size_type begin, std::string::size_type end); 43 | 44 | private: 45 | std::map vars_; 46 | }; 47 | 48 | }} // namespaces 49 | 50 | #endif // XIVA_DAEMON_VARIABLE_MAP_HPP_INCLUDED 51 | -------------------------------------------------------------------------------- /daemon/xiva.conf.example: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /usr/lib/xiva 5 | 6 | 7 | 8081 8 | 1000 9 |
127.0.0.1
10 |
11 | 3000 12 | 3000 13 | 60000 14 | 10000 15 | 1 16 | 1 17 | 18 | ${path}/xiva-syslog.so 19 | ${path}/xiva-stdin-reader.so 20 | 21 | 22 | xiva-test 23 | 24 |
25 | -------------------------------------------------------------------------------- /daemon/xml.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xml.hpp" 3 | 4 | #include 5 | #include 6 | 7 | #include "xiva/error.hpp" 8 | 9 | namespace xiva { namespace daemon { namespace xml { 10 | 11 | struct xml_setup { 12 | xml_setup(); 13 | }; 14 | 15 | void 16 | throw_unless(bool condition) { 17 | if (condition) { 18 | return; 19 | } 20 | char const *message = "unknown XML error"; 21 | xmlErrorPtr xml_err = xmlGetLastError(); 22 | if (xml_err && xml_err->message) { 23 | message = xml_err->message; 24 | } 25 | error err("%s", message); 26 | xmlResetLastError(); 27 | throw err; 28 | } 29 | 30 | void 31 | doc_traits::destroy(xmlDocPtr doc) { 32 | xmlFreeDoc(doc); 33 | } 34 | 35 | void 36 | xpath_object_traits::destroy(xmlXPathObjectPtr object) { 37 | xmlXPathFreeObject(object); 38 | } 39 | 40 | void 41 | xpath_context_traits::destroy(xmlXPathContextPtr context) { 42 | xmlXPathFreeContext(context); 43 | } 44 | 45 | char const* 46 | attr_value(xmlNodePtr node, char const *name) { 47 | assert(node); 48 | xmlAttrPtr attr = xmlHasProp(node, (xmlChar const*) name); 49 | return attr ? text_value(attr) : 0; 50 | } 51 | 52 | extern "C" void 53 | xiva_xml_null_error(void *ctx, char const *format, ...) { 54 | 55 | (void) ctx; 56 | (void) format; 57 | 58 | } 59 | 60 | xml_setup::xml_setup() { 61 | xmlSetGenericErrorFunc(0, &xiva_xml_null_error); 62 | } 63 | 64 | static xml_setup setup_; 65 | 66 | }}} // namespaces 67 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: xiva 2 | Priority: optional 3 | Maintainer: Oleg Obolenskiy 4 | Build-Depends: debhelper (>= 4.0.0), automake1.9, libtool, autotools-dev, libboost-dev, libboost-thread-dev, libboost-regex-dev, libboost-date-time-dev, libboost-dev, libboost-system-dev (>= 1.40) | libasio-dev, python-dev, libssl-dev 5 | Standards-Version: 3.6.1 6 | Section: libs 7 | 8 | Package: libxiva 9 | Section: libs 10 | Architecture: any 11 | Depends: ${shlibs:Depends} 12 | Description: xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 13 | This is the core package. 14 | 15 | Package: libxiva-dev 16 | Section: libdevel 17 | Architecture: any 18 | Depends: libxiva(=${Source-Version}) 19 | Description: xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 20 | This is the package containing header files. 21 | 22 | Package: xiva-daemon 23 | Section: binary 24 | Architecture: any 25 | Depends: ${shlibs:Depends}, libxiva(=${Source-Version}) 26 | Description: xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 27 | Daemon package. 28 | 29 | Package: xiva-syslog 30 | Section: libs 31 | Architecture: any 32 | Depends: ${shlibs:Depends}, libxiva(=${Source-Version}) 33 | Description: xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 34 | Syslog logger package. 35 | 36 | Package: xiva-stdin-reader 37 | Section: libs 38 | Architecture: any 39 | Depends: ${shlibs:Depends}, libxiva(=${Source-Version}) 40 | Description: xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 41 | This package contains message reader which reads content from stdin. 42 | 43 | Package: xiva-utils 44 | Section: binary 45 | Architecture: any 46 | Depends: ${shlibs:Depends}, libxiva(=${Source-Version}) 47 | Description: xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 48 | This package contains utility which reads content from unix socket. 49 | 50 | Package: xiva-python 51 | Section: libs 52 | Conflicts: python-xiva 53 | Replaces: python-xiva 54 | Architecture: any 55 | Depends: ${shlibs:Depends}, libxiva (= ${Source-Version}) 56 | Description: Python binding for C++ libxiva library 57 | -------------------------------------------------------------------------------- /debian/libxiva-dev.files: -------------------------------------------------------------------------------- 1 | usr/lib/libxiva.a 2 | usr/lib/libxiva.la 3 | usr/include/xiva.hpp 4 | usr/include/xiva/*.hpp 5 | -------------------------------------------------------------------------------- /debian/libxiva.files: -------------------------------------------------------------------------------- 1 | usr/lib/libxiva*so* 2 | 3 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | CXX = g++ 4 | ACLOCAL = /usr/bin/aclocal-1.9 5 | AUTOMAKE = /usr/bin/automake-1.9 6 | LIBTOOLIZE = /usr/bin/libtoolize 7 | 8 | LDFLAGS = `pkg-config --libs yandex-platform` 9 | CXXFLAGS = `pkg-config --cflags yandex-platform` 10 | 11 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) 12 | CFLAGS += -g -O0 13 | CXXFLAGS += -g -O0 14 | else 15 | # CFLAGS += -O3 -DNDEBUG 16 | # CXXFLAGS += -O3 -DNDEBUG 17 | CFLAGS += -g -O2 18 | CXXFLAGS += -g -O2 19 | endif 20 | 21 | autogen: autogen-stamp 22 | 23 | autogen-stamp: 24 | dh_testdir 25 | ACLOCAL="$(ACLOCAL)" AUTOMAKE="$(AUTOMAKE)" LIBTOOLIZE="$(LIBTOOLIZE) --force --copy --ltdl" ./autogen.sh 26 | touch autogen-stamp 27 | 28 | configure: configure-stamp 29 | 30 | configure-stamp: autogen-stamp 31 | dh_testdir 32 | CXX="$(CXX)" LDFLAGS="$(LDFLAGS)" CXXFLAGS="$(CXXFLAGS)" ./configure \ 33 | --prefix=/usr \ 34 | --sysconfdir=/etc/xiva \ 35 | --enable-maintainer-mode 36 | touch configure-stamp 37 | 38 | build: build-stamp 39 | 40 | build-stamp: configure-stamp 41 | dh_testdir 42 | $(MAKE) release=1 43 | $(MAKE) check 44 | touch build-stamp 45 | 46 | clean: 47 | dh_testdir 48 | dh_testroot 49 | rm -f configure-stamp build-stamp 50 | -$(MAKE) distclean 51 | dh_clean 52 | 53 | tests: build 54 | dh_testdir 55 | $(MAKE) check 56 | 57 | install: build tests 58 | dh_testdir 59 | dh_testroot 60 | dh_clean -k 61 | dh_installdirs 62 | $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp 63 | 64 | binary-arch: build install 65 | dh_testdir 66 | dh_testroot 67 | dh_movefiles 68 | dh_installchangelogs 69 | dh_installinit --no-start 70 | dh_link 71 | # dh_strip 72 | dh_compress 73 | dh_fixperms 74 | dh_makeshlibs -V 75 | dh_installdeb 76 | dh_shlibdeps 77 | dh_gencontrol 78 | dh_md5sums 79 | dh_builddeb 80 | 81 | binary: binary-arch 82 | 83 | .PHONY: build clean binary-arch binary install configure 84 | -------------------------------------------------------------------------------- /debian/xiva-daemon.files: -------------------------------------------------------------------------------- 1 | usr/sbin/xiva-daemon 2 | etc/xiva/xiva.conf.example 3 | -------------------------------------------------------------------------------- /debian/xiva-python.files: -------------------------------------------------------------------------------- 1 | usr/lib/python*/*-packages/* 2 | -------------------------------------------------------------------------------- /debian/xiva-stdin-reader.files: -------------------------------------------------------------------------------- 1 | usr/lib/xiva/xiva-stdin-reader.* 2 | -------------------------------------------------------------------------------- /debian/xiva-syslog.files: -------------------------------------------------------------------------------- 1 | usr/lib/xiva/xiva-syslog.* 2 | -------------------------------------------------------------------------------- /debian/xiva-utils.files: -------------------------------------------------------------------------------- 1 | usr/bin/xiva-util -------------------------------------------------------------------------------- /examples/crossdomain.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/xiva-daemon-fastcgi-perl/debian/changelog: -------------------------------------------------------------------------------- 1 | xiva-daemon-fastcgi-perl (1.5.1-2) unstable; urgency=low 2 | 3 | * added dependence libtimedate-perl 4 | 5 | -- ponomarev Wed, 15 Dec 2010 16:45:50 +0300 6 | 7 | xiva-daemon-fastcgi-perl (1.5.1-1) unstable; urgency=low 8 | 9 | * support history files for rooms of xiva-web-chat 10 | * added logrotate script for main and history logs 11 | 12 | -- ponomarev Wed, 15 Dec 2010 15:41:51 +0300 13 | 14 | xiva-daemon-fastcgi-perl (1.4.1-1) unstable; urgency=low 15 | 16 | * init script added 17 | 18 | -- ponomarev Mon, 22 Nov 2010 19:26:31 +0300 19 | 20 | xiva-daemon-fastcgi-perl (1.3.1-2) unstable; urgency=low 21 | 22 | * fixed description in control 23 | 24 | -- ponomarev Tue, 02 Nov 2010 13:35:38 +0300 25 | 26 | xiva-daemon-fastcgi-perl (1.3.1-1) unstable; urgency=low 27 | 28 | * Initial release 29 | 30 | -- ponomarev Mon, 16 Aug 2010 18:54:00 +0400 31 | -------------------------------------------------------------------------------- /examples/xiva-daemon-fastcgi-perl/debian/compat: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /examples/xiva-daemon-fastcgi-perl/debian/control: -------------------------------------------------------------------------------- 1 | Source: xiva-daemon-fastcgi-perl 2 | Priority: optional 3 | Maintainer: Alexey Ponomarev 4 | Build-Depends: debhelper (>= 4.0.0), libfcgi-perl 5 | Standards-Version: 3.6.1 6 | Section: libs 7 | 8 | Package: xiva-daemon-fastcgi-perl 9 | Section: libs 10 | Architecture: all 11 | Depends: ${shlibs:Depends}, xiva-daemon-python, libfcgi-perl, libtimedate-perl, spawn-fcgi, grep, awk, sed, procps, logrotate 12 | Description: Fastcgi perl script for pushing messages into python xiva-server 13 | -------------------------------------------------------------------------------- /examples/xiva-daemon-fastcgi-perl/debian/install: -------------------------------------------------------------------------------- 1 | *.pl usr/share/xiva 2 | 3 | -------------------------------------------------------------------------------- /examples/xiva-daemon-fastcgi-perl/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | #export DH_VERBOSE=1 3 | 4 | build: 5 | dh_testdir 6 | 7 | install: build 8 | dh_testdir 9 | dh_testroot 10 | dh_clean -k 11 | dh_install 12 | 13 | clean: 14 | dh_testdir 15 | dh_testroot 16 | dh_clean 17 | 18 | binary: build install 19 | dh_testdir 20 | dh_testroot 21 | dh_installchangelogs 22 | dh_installinit --no-start 23 | dh_installlogrotate 24 | dh_compress 25 | dh_fixperms 26 | dh_installdeb 27 | dh_gencontrol 28 | dh_md5sums 29 | dh_builddeb 30 | 31 | .PHONY: build install clean binary 32 | -------------------------------------------------------------------------------- /examples/xiva-daemon-fastcgi-perl/debian/xiva-daemon-fastcgi-perl.logrotate: -------------------------------------------------------------------------------- 1 | /var/log/xiva-daemon-fastcgi/*.log { 2 | daily 3 | rotate 7 4 | missingok 5 | create 666 www-data www-data 6 | } 7 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/crossdomain.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/debian/changelog: -------------------------------------------------------------------------------- 1 | xiva-daemon-python-configs (1.4.4-1) unstable; urgency=low 2 | 3 | * up ping interval to 5 minutes 4 | 5 | -- ponomarev Fri, 03 Dec 2010 16:35:07 +0300 6 | 7 | xiva-daemon-python-configs (1.4.1-1) unstable; urgency=low 8 | 9 | * Initial release 10 | 11 | -- ponomarev Mon, 22 Nov 2010 18:25:28 +0300 12 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/debian/compat: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/debian/control: -------------------------------------------------------------------------------- 1 | Source: xiva-daemon-python-configs 2 | Priority: optional 3 | Maintainer: Alexey Ponomarev 4 | Build-Depends: debhelper (>= 4.0.0) 5 | Standards-Version: 3.6.1 6 | Section: libs 7 | 8 | Package: xiva-daemon-python-configs 9 | Section: libs 10 | Architecture: all 11 | Depends: xiva-daemon-python, xiva-python (>= 1.4.4) 12 | Description: Configs for sample xiva-server on python 13 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | #export DH_VERBOSE=1 3 | 4 | build: 5 | dh_testdir 6 | 7 | install: build 8 | dh_testdir 9 | dh_testroot 10 | dh_clean -k 11 | dh_install 12 | 13 | clean: 14 | dh_testdir 15 | dh_testroot 16 | dh_clean 17 | 18 | binary: build install 19 | dh_testdir 20 | dh_testroot 21 | dh_installchangelogs 22 | # dh_installinit --no-start 23 | dh_compress 24 | dh_fixperms 25 | dh_installdeb 26 | dh_gencontrol 27 | dh_md5sums 28 | dh_builddeb 29 | 30 | .PHONY: build install clean binary 31 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/debian/xiva-daemon-python-configs.install: -------------------------------------------------------------------------------- 1 | xiva*.conf* etc/xiva 2 | *.xml var/www 3 | 4 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/debian/xiva-daemon-python-configs.preinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | WWW_DIR=/var/www 4 | 5 | USER=www-data 6 | 7 | mkdir -p $WWW_DIR $RUN_DIR 8 | 9 | chown $USER $WWW_DIR $WWW_DIR 10 | chgrp $USER $WWW_DIR $WWW_DIR 11 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/xiva-ulimits.conf: -------------------------------------------------------------------------------- 1 | COREDIR=/var/tmp/core-files 2 | ulimit -s 1024 3 | ulimit -c unlimited 4 | ulimit -n 51200 5 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/xiva.conf: -------------------------------------------------------------------------------- 1 | { 2 | #xiva application server settings 3 | # 4 | 'socket': '/tmp/xivadaemon.sock', 5 | 'pidfile': '/var/run/xiva/xivadaemon.pid', 6 | 'log': 7 | { 8 | 'level': 'INFO', # 'DEBUG', 'INFO', 'WARNING' 9 | 'type' : 'syslog', # 'syslog', 'default' 10 | 'name' : 'xiva-daemon-python', 11 | }, 12 | 13 | # 14 | # xiva non-crypted endpoint 15 | # 16 | 'address': '0.0.0.0', 17 | 'backlog': 100, 18 | 'port': 80, 19 | 20 | # 21 | # xiva crypted optional endpoint 22 | # 23 | 'ssl_port': 0, # 8443 # (0 - disable) 24 | 'ssl_backlog': 100, 25 | 'ss_address': '0.0.0.0', 26 | 'ssl_cert_file_name': '/etc/cert/cert_key.pem', 27 | 'ssl_cacert_file_name': '/etc/cert/cacert.pem', 28 | 29 | # 30 | # xiva core settings 31 | # 32 | 'handler_threads': 5, 33 | 'listener_threads': 1, 34 | 'ping_interval': 300000, # 5 minutes 35 | 'inactive_timeout': 1200000, # 20 minutes 36 | 'read_timeout': 5000, # 5 seconds 37 | 'write_timeout': 5000, # 5 seconds 38 | 'policy_file_name': '/var/www/crossdomain.xml', 39 | } 40 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python-configs/xiva.init.conf: -------------------------------------------------------------------------------- 1 | export XIVA_USER=root 2 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/debian/compat: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/debian/control: -------------------------------------------------------------------------------- 1 | Source: xiva-daemon-python 2 | Priority: optional 3 | Maintainer: Alexey Ponomarev 4 | Build-Depends: debhelper (>= 4.0.0) 5 | Standards-Version: 3.6.1 6 | Section: libs 7 | 8 | Package: xiva-daemon-python 9 | Section: libs 10 | Architecture: all 11 | Depends: ${shlibs:Depends}, xiva-python (>= 1.6.3), python 12 | Description: Simple xiva-server on python and init scripts 13 | 14 | Package: xiva-daemon-check 15 | Section: libs 16 | Architecture: all 17 | Depends: ${shlibs:Depends}, xiva-python, python 18 | Description: Checker for xiva-server on python 19 | 20 | Package: xiva-daemon-python-dev 21 | Section: libs 22 | Architecture: all 23 | Depends: ${shlibs:Depends}, xiva-daemon-python 24 | Description: Tools for development apps for xiva-server on python 25 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | #export DH_VERBOSE=1 3 | 4 | build: 5 | dh_testdir 6 | 7 | install: build 8 | dh_testdir 9 | dh_testroot 10 | dh_clean -k 11 | dh_install 12 | 13 | clean: 14 | dh_testdir 15 | dh_testroot 16 | dh_clean 17 | 18 | binary: build install 19 | dh_testdir 20 | dh_testroot 21 | dh_installchangelogs 22 | dh_installinit --no-start 23 | dh_compress 24 | dh_fixperms 25 | dh_installdeb 26 | dh_gencontrol 27 | dh_md5sums 28 | dh_builddeb 29 | 30 | .PHONY: build install clean binary 31 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/debian/xiva-daemon-check.install: -------------------------------------------------------------------------------- 1 | *check.py usr/bin 2 | 3 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/debian/xiva-daemon-python-dev.install: -------------------------------------------------------------------------------- 1 | *clt.py usr/bin 2 | 3 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/debian/xiva-daemon-python.install: -------------------------------------------------------------------------------- 1 | *daemon.py usr/bin 2 | *start.sh usr/bin 3 | xiva*.conf* etc/xiva 4 | 5 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/debian/xiva-daemon-python.preinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LOG_DIR=/var/log/xiva 4 | RUN_DIR=/var/run/xiva 5 | 6 | USER=www-data 7 | 8 | mkdir -p $LOG_DIR $RUN_DIR 9 | 10 | chown $USER $LOG_DIR $RUN_DIR 11 | chgrp $USER $LOG_DIR $RUN_DIR 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/xiva-ulimits.conf.example: -------------------------------------------------------------------------------- 1 | COREDIR=/var/tmp/core-files 2 | ulimit -s 1024 3 | ulimit -c unlimited 4 | ulimit -n 100000 5 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/xiva.conf.example: -------------------------------------------------------------------------------- 1 | { 2 | #xiva application server settings 3 | # 4 | 'socket': '/tmp/xivadaemon.sock', 5 | 'pidfile': '/var/run/xiva/xivadaemon.pid', 6 | 'log': 7 | { 8 | 'level': 'INFO', # 'DEBUG', 'INFO', 'WARNING' 9 | 'type' : 'syslog', # 'syslog', 'default' 10 | 'name' : 'xiva-daemon-python', 11 | }, 12 | 13 | # 14 | # xiva non-crypted endpoint 15 | # 16 | 'address': '0.0.0.0', 17 | 'backlog': 100, 18 | 'port': 8881, 19 | 20 | # 21 | # xiva crypted optional endpoint 22 | # 23 | 'ssl_port': 0, # 8443 # (0 - disable) 24 | 'ssl_backlog': 100, 25 | 'ss_address': '0.0.0.0', 26 | 'ssl_cert_file_name': '/etc/cert/cert_key.pem', 27 | 'ssl_cacert_file_name': '/etc/cert/cacert.pem', 28 | 29 | # 30 | # xiva core settings 31 | # 32 | 'handler_threads': 5, 33 | 'listener_threads': 1, 34 | 'ping_interval': 20000, 35 | 'inactive_timeout': 60000, 36 | 'read_timeout': 5000, 37 | 'write_timeout': 5000, 38 | 'policy_file_name': '/var/www/crossdomain.xml', 39 | } 40 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/xiva.init.conf.example: -------------------------------------------------------------------------------- 1 | export XIVA_USER=root 2 | #export XIVA_USER=www-data 3 | ulimit -n 100000 4 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/xiva_clt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # -*- coding: utf-8 -*- 4 | 5 | import socket, sys 6 | 7 | def print_usage(): 8 | print 'Usage:\n' + sys.argv[0] + ' ( send [/] ... | list [] )'; 9 | exit(1) 10 | 11 | if __name__ == "__main__": 12 | argc = len(sys.argv) 13 | if argc < 3: 14 | print_usage() 15 | msg = ''; uds_path = sys.argv[1]; cmd = sys.argv[2] 16 | if cmd == 'list': 17 | if argc == 3: 18 | msg = cmd 19 | elif argc == 4: 20 | msg = cmd + ' ' + sys.argv[3] 21 | else: 22 | print_usage() 23 | else: 24 | if argc < 5: 25 | print_usage() 26 | if cmd != 'send': 27 | print_usage() 28 | idx = 4 29 | msg = 'msg ' + sys.argv[3] # [/channel] 30 | for i in xrange(idx, argc): 31 | msg += ' ' + sys.argv[i] 32 | print 'Send:', msg 33 | uds = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 34 | try: 35 | try: 36 | uds.connect(uds_path) 37 | uds.send(msg) 38 | print 'Recv:', uds.recv(1024*1024) 39 | finally: 40 | uds.close() 41 | except Exception, e: 42 | print "Failed", e 43 | exit(2) 44 | -------------------------------------------------------------------------------- /examples/xiva-daemon-python/xivadaemonstart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #Starting script for xiva-daemon-python 3 | 4 | #Main options 5 | ETCDIR='/etc' 6 | NAME=$1 7 | WORK_DIR=$ETCDIR/$NAME 8 | 9 | XIVA_CONFIG=$WORK_DIR/xiva.conf 10 | CUSTOM_FILE_TEMPLATE=xiva-*\.conf 11 | 12 | LOCKFILE="/var/run/$NAME/xivadaemonstart.pid" 13 | LOGFILE="/var/log/$NAME/xivadaemonstart.log" 14 | RDELAY=1 15 | EXIT_TIMEOUT=10 16 | 17 | 18 | for CUSTOM_CONFIG in $WORK_DIR/$CUSTOM_FILE_TEMPLATE 19 | do 20 | if [ -r $CUSTOM_CONFIG ]; then 21 | . $CUSTOM_CONFIG 22 | fi 23 | done 24 | 25 | if [ -e $XIVA_CONFIG ]; then 26 | touch $LOCKFILE 27 | trap "rm $LOCKFILE 2>/dev/null" 0 28 | ps ax | grep "xivadaemonstart.sh $NAME$" | grep -v grep | awk '{print $1}' > $LOCKFILE 29 | if [ -d "$COREDIR" ]; then 30 | mkdir -p $COREDIR 2>/dev/null 31 | fi 32 | SLEEP_TIMEOUT=0 33 | while [ -f $LOCKFILE ]; do 34 | sleep $SLEEP_TIMEOUT 35 | STARTTIME=`date +%s` 36 | echo "/usr/bin/xivadaemon.py --config=$XIVA_CONFIG" 37 | /usr/bin/xivadaemon.py --config=$XIVA_CONFIG >> $LOGFILE 2>&1 38 | echo "on `date` ::xivadaemonstart.sh:: xivadaemonstart.sh on `hostname` restarted" >>$LOGFILE 39 | NOWTIME=`date +%s` 40 | if [ $SLEEP_TIMEOUT -eq 0 -a $EXIT_TIMEOUT -gt 0 ]; then 41 | WORKTIME=$(($NOWTIME-$STARTTIME)) 42 | if [ $WORKTIME -lt $EXIT_TIMEOUT ]; then 43 | echo "Fast xiva crash. Exit 1" 44 | exit 1 45 | fi 46 | fi 47 | SLEEP_TIMEOUT=$RDELAY 48 | done 49 | else 50 | echo "Can not find $XIVA_CONFIG" 51 | exit 1 52 | fi 53 | -------------------------------------------------------------------------------- /examples/xiva-daemon-tools-perl/debian/changelog: -------------------------------------------------------------------------------- 1 | xiva-daemon-tools-perl (1.3.1-1) unstable; urgency=low 2 | 3 | * Initial release 4 | 5 | -- ponomarev Mon, 16 Aug 2010 18:54:00 +0400 6 | -------------------------------------------------------------------------------- /examples/xiva-daemon-tools-perl/debian/compat: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /examples/xiva-daemon-tools-perl/debian/control: -------------------------------------------------------------------------------- 1 | Source: xiva-daemon-tools-perl 2 | Priority: optional 3 | Maintainer: Alexey Ponomarev 4 | Build-Depends: debhelper (>= 4.0.0), perl 5 | Standards-Version: 3.6.1 6 | Section: libs 7 | 8 | Package: xiva-daemon-tools-perl 9 | Section: libs 10 | Architecture: all 11 | Depends: ${shlibs:Depends}, xiva-daemon-python, perl 12 | Description: Perl tools for simple xiva-server on python 13 | -------------------------------------------------------------------------------- /examples/xiva-daemon-tools-perl/debian/install: -------------------------------------------------------------------------------- 1 | *.pl usr/bin 2 | 3 | -------------------------------------------------------------------------------- /examples/xiva-daemon-tools-perl/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | #export DH_VERBOSE=1 3 | 4 | build: 5 | dh_testdir 6 | 7 | install: build 8 | dh_testdir 9 | dh_testroot 10 | dh_clean -k 11 | dh_install 12 | 13 | clean: 14 | dh_testdir 15 | dh_testroot 16 | dh_clean 17 | 18 | binary: build install 19 | dh_testdir 20 | dh_testroot 21 | dh_installchangelogs 22 | dh_compress 23 | dh_fixperms 24 | dh_installdeb 25 | dh_gencontrol 26 | dh_md5sums 27 | dh_builddeb 28 | 29 | .PHONY: build install clean binary 30 | -------------------------------------------------------------------------------- /examples/xiva-daemon-tools-perl/xiva_cmd.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | use Socket; 5 | 6 | my $argc = $#ARGV; 7 | if ($argc < 1) { 8 | print "Usage: xiva_cmd.pl \n"; 9 | exit(1); 10 | } 11 | my $sockpath = $ARGV[0]; 12 | shift; 13 | my $cmd = join(" ", @ARGV); 14 | print "CMD: '$cmd'\n"; 15 | my $ret = 2; 16 | socket(S, AF_UNIX, SOCK_STREAM, 0); 17 | if (connect(S, sockaddr_un($sockpath))) { 18 | if (send(S, $cmd, 0)) { 19 | if (recv(S, my $data, 1042 * 1024, 0)) { 20 | print $data, "\n"; 21 | $ret = 0; 22 | } 23 | } 24 | } 25 | print "Fail\n" if $ret; 26 | close S; 27 | exit(2); 28 | -------------------------------------------------------------------------------- /examples/xiva-web-chat-lighttpd-config/10-xiva-web-chat.conf: -------------------------------------------------------------------------------- 1 | $HTTP["host"] =~ "^xchat\.opensource(\.[a-z0-9]+)*\.yandex\.(ru|net)$" { 2 | server.document-root = "/usr/local/www/xiva-web-chat" 3 | fastcgi.map-extensions = ( "/xiva" => ".xivaperl", "/xiva.pl" => ".xivaperl" ) 4 | fastcgi.server = ( 5 | ".xivaperl" => 6 | (( 7 | "host" => "95.108.234.78", #xiva.opensource.yandex.net 8 | "port" => 18881, 9 | "check-local" => "disable" 10 | )), 11 | ) 12 | } 13 | -------------------------------------------------------------------------------- /examples/xiva-web-chat-lighttpd-config/debian/changelog: -------------------------------------------------------------------------------- 1 | xiva-web-chat-lighttpd-config (1.0) unstable; urgency=low 2 | 3 | * Initial release 4 | 5 | -- ponomarev Mon, 13 Dec 2010 18:20:47 +0300 6 | -------------------------------------------------------------------------------- /examples/xiva-web-chat-lighttpd-config/debian/control: -------------------------------------------------------------------------------- 1 | Source: xiva-web-chat-lighttpd-config 2 | Priority: optional 3 | Maintainer: Alexey Ponomarev 4 | Build-Depends: debhelper (>= 4.0.0) 5 | Standards-Version: 3.6.1 6 | 7 | Package: xiva-web-chat-lighttpd-config 8 | Section: libs 9 | Architecture: all 10 | Depends: lighttpd | lighttpd1.5, xiva-web-chat 11 | Description: Lighttpd config for xiva-web-chat 12 | -------------------------------------------------------------------------------- /examples/xiva-web-chat-lighttpd-config/debian/install: -------------------------------------------------------------------------------- 1 | *.conf etc/lighttpd/conf-available 2 | -------------------------------------------------------------------------------- /examples/xiva-web-chat-lighttpd-config/debian/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case $1 in 4 | configure) 5 | echo "Enabling xiva-web-chat module; don't forget to restart lighttpd then" >&2 6 | lighty-enable-mod xiva-web-chat 7 | if ! lighttpd -t -f /etc/lighttpd/lighttpd.conf; then 8 | echo "WARN: lighttpd config is not valid" 9 | fi 10 | ;; 11 | 12 | abort-upgrade|abort-remove|abort-deconfigure) 13 | ;; 14 | 15 | *) 16 | echo "postinst called with unknown argument '$1'" >&2 17 | ;; 18 | esac 19 | 20 | # vim: set ts=4 sw=4 et: 21 | -------------------------------------------------------------------------------- /examples/xiva-web-chat-lighttpd-config/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | build: 4 | # Nothing to do 5 | 6 | install: 7 | dh_testdir 8 | dh_testroot 9 | dh_clean -k 10 | 11 | binary-indep: build install 12 | dh_testdir 13 | dh_testroot 14 | dh_install 15 | dh_installchangelogs 16 | dh_compress 17 | dh_fixperms 18 | dh_installdeb 19 | dh_gencontrol 20 | dh_builddeb 21 | 22 | binary-arch: build install 23 | #Nothing to do 24 | 25 | binary: binary-indep binary-arch 26 | 27 | clean: 28 | dh_clean 29 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-chat/_type/b-chat_chat.css: -------------------------------------------------------------------------------- 1 | .b-chat_chat { 2 | height: 0; 3 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-chat/_type/b-chat_chat.ie.css: -------------------------------------------------------------------------------- 1 | .b-chat_chat { 2 | height: 100%; 3 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-chat/_type/b-chat_login.css: -------------------------------------------------------------------------------- 1 | .b-chat_login { 2 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-chat/b-chat.css: -------------------------------------------------------------------------------- 1 | .b-chat { 2 | overflow: auto; 3 | 4 | padding: 2px; 5 | 6 | border: 1px solid #ccc; 7 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-login/b-login.css: -------------------------------------------------------------------------------- 1 | .b-login { 2 | clear: both; 3 | 4 | padding: 16px; 5 | 6 | text-align: center; 7 | font-size: 140%; 8 | 9 | background-color: #F0F0F0; 10 | background: -moz-linear-gradient(90deg, #F0F0F0, #FFF); 11 | background: -webkit-gradient(linear, left top, left bottom, from(#FFF), to(#F0F0F0)); 12 | } 13 | 14 | .b-login .b-login__field { 15 | margin: 0 30% 10px 30%; 16 | 17 | text-align: left; 18 | } 19 | 20 | .b-login .b-login__field__error { 21 | margin: 5px 0 0 80px; 22 | 23 | font-size: 70%; 24 | } 25 | 26 | .b-login .b-login__field label { 27 | display: block; 28 | float: left; 29 | width: 80px; 30 | } 31 | 32 | .b-login .b-login__field input, .b-login .b-login__field select { 33 | width: 180px; 34 | box-sizing: border-box; 35 | -moz-box-sizing: border-box; 36 | -webkit-box-sizing: border-box; 37 | } 38 | 39 | .b-login .b-login__field input { 40 | font-size: 100%; 41 | 42 | border: 1px solid #666; 43 | border-color: #666 #CCC #CCC; 44 | } 45 | 46 | .b-login .b-login__send { 47 | font-size: 120%; 48 | } 49 | 50 | .b-login .b-login__send_disabled { 51 | color: #999; 52 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-login/b-login.ie.css: -------------------------------------------------------------------------------- 1 | * html .b-login .b-login__field { 2 | margin: 0 24% 10px; 3 | } 4 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-message/_type/b-message_you.css: -------------------------------------------------------------------------------- 1 | .b-message_you .b-message__head { 2 | background-color: #EEE; 3 | border-color: #EEE; 4 | } 5 | 6 | .b-message_you .b-message__body { 7 | text-align: right; 8 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-message/b-message.css: -------------------------------------------------------------------------------- 1 | .b-message { 2 | margin: 3px 3px 9px 3px; 3 | } 4 | 5 | .b-message .b-message__head { 6 | overflow: auto; 7 | padding: 3px; 8 | 9 | font-size: 80%; 10 | 11 | background: #FEF; 12 | border: 1px solid #FEF; 13 | border-radius: 4px; 14 | -moz-border-radius: 4px; 15 | -webkit-border-radius: 4px; 16 | } 17 | 18 | .b-message .b-message__head__user { 19 | float: left; 20 | width: 50%; 21 | } 22 | 23 | .b-message .b-message__head__time { 24 | float: right; 25 | width: 50%; 26 | 27 | text-align: right; 28 | } 29 | 30 | .b-message .b-message__body { 31 | margin: 5px 3px; 32 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-message/b-message.ie.css: -------------------------------------------------------------------------------- 1 | .b-message .b-message__head { 2 | height: 15px; 3 | 4 | font-size: 85%; 5 | } 6 | 7 | .b-message .b-message__head__user { 8 | width: 45%; 9 | } 10 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-messages/b-messages.css: -------------------------------------------------------------------------------- 1 | .b-messages { 2 | float: left; 3 | width: 593px; 4 | height: 255px; 5 | 6 | overflow-x: hidden; 7 | overflow-y: auto; 8 | 9 | margin-bottom: 10px; 10 | 11 | border-bottom: 1px solid #EEE; 12 | border-left: 1px solid #EEE; 13 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-pseudo-link/b-pseudo-link.css: -------------------------------------------------------------------------------- 1 | .b-pseudo-link, .b-pseudo-link:hover { 2 | color: #1A3DC1; 3 | text-decoration: none; 4 | border-bottom: 1px dotted; 5 | } 6 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-rooms/b-rooms.css: -------------------------------------------------------------------------------- 1 | .b-rooms { 2 | float: left; 3 | width: 200px; 4 | height: 255px; 5 | 6 | margin-bottom: 10px; 7 | } 8 | 9 | .b-rooms .b-rooms__room { 10 | padding: 6px; 11 | 12 | border-bottom: 1px solid #EEE; 13 | } 14 | 15 | .b-rooms .b-rooms__room:hover { 16 | background-color: #F9F9F9; 17 | background: -moz-linear-gradient(90deg, #F9F9F9, #FFF); 18 | background: -webkit-gradient(linear, left top, left bottom, from(#FFF), to(#F9F9F9)); 19 | } 20 | 21 | .b-rooms .b-rooms__room_active, .b-rooms .b-rooms__room_active:hover { 22 | font-weight: bold; 23 | 24 | background: #EEE; 25 | } 26 | 27 | .b-rooms .b-rooms__room__unread { 28 | margin-left: 5px; 29 | 30 | font-weight: bold; 31 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-userlist/b-userlist.css: -------------------------------------------------------------------------------- 1 | .b-userlist { 2 | margin: .5em 0; 3 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-writemessage/b-writemessage.css: -------------------------------------------------------------------------------- 1 | .b-writemessage { 2 | clear: both; 3 | 4 | margin: 2px 2px 2px 204px; 5 | } 6 | 7 | .b-writemessage .b-writemessage__area { 8 | width: 100%; 9 | height: 50px; 10 | 11 | margin: 0; 12 | padding: 0; 13 | 14 | border: 1px solid #666; 15 | border-color: #666 #CCC #CCC; 16 | } 17 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/b-writemessage/b-writemessage.ie.css: -------------------------------------------------------------------------------- 1 | * html .b-writemessage { 2 | margin-top: -56px; 3 | } 4 | 5 | .b-writemessage .b-writemessage__area { 6 | width: 585px; 7 | } 8 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/g-hidden/g-hidden.css: -------------------------------------------------------------------------------- 1 | .g-hidden { 2 | display: none; 3 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/g-reset/g-reset.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #FFF; 3 | font: 0.8em Arial, Helvetica, sans-serif; 4 | 5 | margin: 0; 6 | padding: 0; 7 | } 8 | 9 | h1 { 10 | position: relative; 11 | left: -10px; 12 | width: 800px; 13 | 14 | margin: .5em 0; 15 | padding: 2px 10px; 16 | 17 | font-family: 'Cantarell', Arial, sans-serif; 18 | 19 | color: #FFF; 20 | background-color: #F33; 21 | background: -moz-linear-gradient(-90deg, #FFD0FF, #F33); 22 | background: -webkit-gradient(linear, left top, left bottom, from(#FFD0FF), to(#F33)); 23 | } 24 | 25 | header, footer, section { 26 | display: block; 27 | } -------------------------------------------------------------------------------- /examples/xiva-web-chat/blocks/l-page/html5.js: -------------------------------------------------------------------------------- 1 | // html5shiv MIT @rem remysharp.com/html5-enabling-script 2 | // iepp v1.5.1 MIT @jon_neal iecss.com/print-protector 3 | /*@cc_on(function(p,e){var q=e.createElement("div");q.innerHTML="i";q.childNodes.length!==1&&function(){function r(a,b){if(g[a])g[a].styleSheet.cssText+=b;else{var c=s[l],d=e[j]("style");d.media=a;c.insertBefore(d,c[l]);g[a]=d;r(a,b)}}function t(a,b){for(var c=new RegExp("\\b("+m+")\\b(?!.*[;}])","gi"),d=function(k){return".iepp_"+k},h=-1;++h\\s*$","i");i.innerHTML=a.outerHTML.replace(/\r|\n/g," ").replace(c,a.currentStyle.display=="block"?"":"");c=i.childNodes[0];c.className+=" iepp_"+ 5 | d;c=f[f.length]=[a,c];a.parentNode.replaceChild(c[1],c[0])}t(e.styleSheets,"all")});p.attachEvent("onafterprint",function(){for(var a=-1,b;++a Fri, 17 Dec 2010 13:30:15 +0300 6 | 7 | xiva-web-chat (1.0) unstable; urgency=low 8 | 9 | * fixed control and rules 10 | * set this.ws_url to 'xiva.opensource.yandex.net/?id=chat' 11 | 12 | -- ponomarev Fri, 03 Dec 2010 16:53:43 +0300 13 | 14 | xiva-web-chat (0.1) unstable; urgency=low 15 | 16 | * Initial Release 17 | 18 | -- Leonid Khachaturov Thu, 30 Sep 2010 20:42:21 +0400 19 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/debian/compat: -------------------------------------------------------------------------------- 1 | 4 -------------------------------------------------------------------------------- /examples/xiva-web-chat/debian/control: -------------------------------------------------------------------------------- 1 | Source: xiva-web-chat 2 | Section: misc 3 | Priority: extra 4 | Maintainer: Leonid Khachaturov 5 | Build-Depends: debhelper (>= 5) 6 | Standards-Version: 3.8.0 7 | 8 | Package: xiva-web-chat 9 | Architecture: all 10 | Description: Xiva-based web-chat 11 | A sample application built on Xiva. Contains a reference transport implementation 12 | -------------------------------------------------------------------------------- /examples/xiva-web-chat/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | PRJDIR=$(CURDIR) 4 | DEBDIR=$(CURDIR)/debian/xiva-web-chat/usr/local/www/xiva-web-chat 5 | 6 | configure: configure-stamp 7 | 8 | configure-stamp: 9 | dh_testdir 10 | touch configure-stamp 11 | 12 | build: build-stamp 13 | 14 | build-stamp: configure-stamp 15 | dh_testdir 16 | touch $@ 17 | 18 | clean: 19 | dh_testdir 20 | dh_testroot 21 | rm -f build-stamp configure-stamp 22 | dh_clean 23 | 24 | install/xiva-web-chat:: 25 | mkdir -p $(DEBDIR) 26 | for d in $(PRJDIR)/*; do case $$d in */debian) ;; *) cp -r $$d $(DEBDIR) ;; esac; done 27 | find $(DEBDIR) -name .git | xargs rm -Rf 28 | find $(DEBDIR) -name '*-stamp' | xargs rm -Rf 29 | find $(DEBDIR) -name .gitignore | xargs rm -f 30 | rm -Rf $(DEBDIR)/web-socket-js/flash-src 31 | 32 | binary-indep: build install 33 | 34 | binary-arch: build install install/xiva-web-chat 35 | dh_testdir 36 | dh_installchangelogs 37 | dh_link 38 | dh_fixperms 39 | dh_installdeb 40 | dh_gencontrol 41 | dh_md5sums 42 | dh_builddeb 43 | 44 | binary: binary-indep binary-arch 45 | .PHONY: build clean binary-indep binary-arch binary install configure -------------------------------------------------------------------------------- /examples/xiva-web-chat/index.css: -------------------------------------------------------------------------------- 1 | @import url("blocks/g-reset/g-reset.css"); 2 | @import url("blocks/g-hidden/g-hidden.css"); 3 | @import url("blocks/b-pseudo-link/b-pseudo-link.css"); 4 | 5 | @import url("blocks/l-page/l-page.css"); 6 | @import url("blocks/b-chat/b-chat.css"); 7 | @import url("blocks/b-chat/_type/b-chat_login.css"); 8 | @import url("blocks/b-chat/_type/b-chat_chat.css"); 9 | @import url("blocks/b-login/b-login.css"); 10 | @import url("blocks/b-message/b-message.css"); 11 | @import url("blocks/b-message/_type/b-message_you.css"); 12 | @import url("blocks/b-messages/b-messages.css"); 13 | @import url("blocks/b-rooms/b-rooms.css"); 14 | @import url("blocks/b-userlist/b-userlist.css"); 15 | @import url("blocks/b-writemessage/b-writemessage.css"); -------------------------------------------------------------------------------- /examples/xiva-web-chat/index.ie.css: -------------------------------------------------------------------------------- 1 | @import url("index.css"); 2 | 3 | @import url("blocks/b-chat/_type/b-chat_chat.ie.css"); 4 | @import url("blocks/b-login/b-login.ie.css"); 5 | @import url("blocks/b-message/b-message.ie.css"); 6 | @import url("blocks/b-writemessage/b-writemessage.ie.css"); -------------------------------------------------------------------------------- /examples/xiva-web-chat/web-socket-js/WebSocketMain.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/highpower/xiva/0b89a8c26d577cf6c9e42ceddbf90b712eba4a6a/examples/xiva-web-chat/web-socket-js/WebSocketMain.swf -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = details xiva 2 | include_HEADERS = xiva.hpp 3 | 4 | -------------------------------------------------------------------------------- /include/details/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_HEADERS = acceptor_base.hpp acceptor.hpp asio.hpp \ 2 | channels_stat_impl.hpp char_traits.hpp compound_listener.hpp \ 3 | connection_base.hpp connection_socket.hpp connection_data.hpp \ 4 | connection.hpp connection_impl.hpp connection_manager_base.hpp \ 5 | connection_manager.hpp connection_traits_base.hpp connection_traits.hpp \ 6 | dynamic_loader.hpp functors.hpp formatters_data.hpp \ 7 | formatters_data_channels.hpp formatters_data_simple.hpp \ 8 | formatters_factory.hpp guard.hpp handler_invoker.hpp \ 9 | handler_invoker_base.hpp http.hpp http_constants.hpp \ 10 | iterator_checker.hpp line_reader.hpp message_queue.hpp range.hpp \ 11 | request_checker.hpp request_helper.hpp request_impl.hpp resource.hpp \ 12 | response_impl.hpp server_impl.hpp ssl_connection_socket.hpp \ 13 | ssl_connection_traits.hpp ssl_context.hpp stdio_logger.hpp string_utils.hpp \ 14 | system_error.hpp threaded_connection.hpp threaded_handler_invoker.hpp \ 15 | threaded_listener.hpp threaded_queue.hpp threaded_shared.hpp \ 16 | urlencode.hpp url_response_handler.hpp websocket_info.hpp 17 | -------------------------------------------------------------------------------- /include/details/acceptor_base.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_ACCEPTOR_BASE_HPP_INCLUDED 19 | #define XIVA_DETAILS_ACCEPTOR_BASE_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include "xiva/shared.hpp" 25 | #include "xiva/forward.hpp" 26 | 27 | namespace xiva { namespace details { 28 | 29 | class acceptor_base : public shared { 30 | 31 | public: 32 | acceptor_base(); 33 | virtual ~acceptor_base(); 34 | 35 | virtual void accept() = 0; 36 | 37 | virtual void attach_logger(boost::intrusive_ptr const &log) = 0; 38 | virtual void bind(std::string const &addr, unsigned short port, unsigned short backlog) = 0; 39 | virtual void stop() = 0; 40 | 41 | private: 42 | acceptor_base(acceptor_base const &); 43 | acceptor_base& operator = (acceptor_base const &); 44 | }; 45 | 46 | }} // namespaces 47 | 48 | #endif // XIVA_DETAILS_ACCEPTOR_BASE_HPP_INCLUDED 49 | -------------------------------------------------------------------------------- /include/details/asio.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_ASIO_HPP_INCLUDED 19 | #define XIVA_DETAILS_ASIO_HPP_INCLUDED 20 | 21 | #if XIVA_HAVE_BOOST_ASIO 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | namespace asio = boost::asio; 29 | namespace syst = boost::system; 30 | 31 | #define XIVA_BEGIN_ASIO_NAMESPACE namespace boost { namespace asio { 32 | #define XIVA_END_ASIO_NAMESPACE }} 33 | 34 | #else // XIVA_HAVE_BOOST_ASIO 35 | 36 | #include 37 | #include 38 | 39 | namespace syst = asio; 40 | 41 | #define XIVA_BEGIN_ASIO_NAMESPACE namespace asio { 42 | #define XIVA_END_ASIO_NAMESPACE } 43 | 44 | #endif // XIVA_HAVE_BOOST_ASIO 45 | 46 | #endif // XIVA_DETAILS_ASIO_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /include/details/channels_stat_impl.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_CHANNELS_STAT_IMPL_HPP_INCLUDED 19 | #define XIVA_DETAILS_CHANNELS_STAT_IMPL_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include "xiva/forward.hpp" 28 | #include "xiva/enumeration.hpp" 29 | 30 | namespace xiva { namespace details { 31 | 32 | class channels_stat_impl { 33 | 34 | public: 35 | channels_stat_impl(); 36 | virtual ~channels_stat_impl(); 37 | 38 | void inc(channel_id const &ch_id); 39 | void dec(channel_id const &ch_id); 40 | 41 | enumeration::ptr_type load_names() const; 42 | enumeration::ptr_type load_keys(std::string const &ch_name) const; 43 | 44 | private: 45 | channels_stat_impl(channels_stat_impl const &); 46 | channels_stat_impl& operator = (channels_stat_impl const &); 47 | 48 | typedef std::map channel_stat; 49 | 50 | mutable boost::mutex mutex_; 51 | std::map data_; 52 | }; 53 | 54 | }} // namespaces 55 | 56 | #endif // XIVA_DETAILS_CHANNELS_STAT_IMPL_HPP_INCLUDED 57 | -------------------------------------------------------------------------------- /include/details/connection.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_CONNECTION_HPP_INCLUDED 19 | #define XIVA_DETAILS_CONNECTION_HPP_INCLUDED 20 | 21 | #include "xiva/shared.hpp" 22 | #include "xiva/forward.hpp" 23 | #include "details/connection_base.hpp" 24 | 25 | namespace xiva { namespace details { 26 | 27 | class connection : public shared, public connection_base { 28 | 29 | public: 30 | connection(); 31 | virtual ~connection(); 32 | 33 | private: 34 | connection(connection const &); 35 | connection& operator = (connection const &); 36 | }; 37 | 38 | 39 | }} // namespaces 40 | 41 | #endif // XIVA_DETAILS_CONNECTION_HPP_INCLUDED 42 | -------------------------------------------------------------------------------- /include/details/connection_traits_base.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_CONNECTION_TRAITS_BASE_HPP_INCLUDED 19 | #define XIVA_DETAILS_CONNECTION_TRAITS_BASE_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/shared.hpp" 24 | #include "xiva/forward.hpp" 25 | 26 | namespace xiva { namespace details { 27 | 28 | class connection_traits_base : public shared { 29 | 30 | public: 31 | connection_traits_base(); 32 | virtual ~connection_traits_base(); 33 | 34 | private: 35 | connection_traits_base(connection_traits_base const &); 36 | connection_traits_base& operator = (connection_traits_base const &); 37 | }; 38 | 39 | }} // namespaces 40 | 41 | #endif // XIVA_DETAILS_CONNECTION_TRAITS_BASE_HPP_INCLUDED 42 | -------------------------------------------------------------------------------- /include/details/dynamic_loader.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_DYNAMIC_LOADER_HPP_INCLUDED 19 | #define XIVA_DETAILS_DYNAMIC_LOADER_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include "ltdl.h" 25 | #include "xiva/forward.hpp" 26 | 27 | namespace xiva { namespace details { 28 | 29 | class dynamic_loader { 30 | 31 | public: 32 | dynamic_loader(); 33 | virtual ~dynamic_loader(); 34 | void load_module(std::string const &name, settings const &s, component_set &cs); 35 | 36 | private: 37 | dynamic_loader(dynamic_loader const &); 38 | dynamic_loader& operator = (dynamic_loader const &); 39 | void check_loaded(bool condition) const; 40 | 41 | private: 42 | std::vector handles_; 43 | }; 44 | 45 | }} // namespaces 46 | 47 | #endif // XIVA_DETAILS_DYNAMIC_LOADER_HPP_INCLUDED 48 | -------------------------------------------------------------------------------- /include/details/formatters_data.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_FORMATTERS_DATA_HPP_INCLUDED 19 | #define XIVA_DETAILS_FORMATTERS_DATA_HPP_INCLUDED 20 | 21 | #include "xiva/forward.hpp" 22 | 23 | namespace xiva { namespace details { 24 | 25 | class formatters_data { 26 | 27 | public: 28 | formatters_data(); 29 | virtual ~formatters_data(); 30 | 31 | virtual bool allow_message(message const& msg, message_filter const *filter) const = 0; 32 | 33 | virtual formatter const* find_formatter(message const& msg) const = 0; 34 | 35 | virtual void update(message const& msg) = 0; 36 | virtual void update_channels_stat(channels_stat_impl &ch_stat, bool add) const = 0; 37 | 38 | private: 39 | formatters_data(formatters_data const &); 40 | formatters_data& operator = (formatters_data const &); 41 | }; 42 | 43 | 44 | }} // namespaces 45 | 46 | #endif // XIVA_DETAILS_FORMATTERS_DATA_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /include/details/formatters_data_channels.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_FORMATTERS_DATA_CHANNELS_HPP_INCLUDED 19 | #define XIVA_DETAILS_FORMATTERS_DATA_CHANNELS_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include "xiva/forward.hpp" 27 | #include "xiva/channel_id.hpp" 28 | #include "details/formatters_data.hpp" 29 | 30 | namespace xiva { namespace details { 31 | 32 | class formatters_data_channels : public formatters_data { 33 | 34 | public: 35 | formatters_data_channels(formatters_factory const &factory, request_impl const &req, response_impl const &resp); 36 | virtual ~formatters_data_channels(); 37 | 38 | virtual bool allow_message(message const& msg, message_filter const *filter) const; 39 | 40 | virtual formatter const* find_formatter(message const& msg) const; 41 | 42 | virtual void update(message const& msg); 43 | virtual void update_channels_stat(channels_stat_impl &ch_stat, bool add) const; 44 | 45 | private: 46 | typedef boost::shared_ptr formatter_ptr; 47 | 48 | typedef std::pair channel_data; 49 | typedef std::map channels_data; 50 | 51 | channels_data channels_data_; 52 | }; 53 | 54 | }} // namespaces 55 | 56 | #endif // XIVA_DETAILS_FORMATTERS_DATA_CHANNELS_HPP_INCLUDED 57 | -------------------------------------------------------------------------------- /include/details/formatters_data_simple.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_FORMATTERS_DATA_SIMPLE_HPP_INCLUDED 19 | #define XIVA_DETAILS_FORMATTERS_DATA_SIMPLE_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "xiva/forward.hpp" 26 | #include "details/formatters_data.hpp" 27 | 28 | namespace xiva { namespace details { 29 | 30 | class formatters_data_simple : public formatters_data { 31 | 32 | protected: 33 | explicit formatters_data_simple(formatter *fmt_ptr); 34 | 35 | public: 36 | virtual ~formatters_data_simple(); 37 | 38 | static std::auto_ptr create( 39 | formatters_factory const &factory, request_impl const &req, response_impl const &resp); 40 | 41 | virtual bool allow_message(message const& msg, message_filter const *filter) const; 42 | 43 | virtual formatter const* find_formatter(message const& msg) const; 44 | 45 | virtual void update(message const& msg); 46 | virtual void update_channels_stat(channels_stat_impl &ch_stat, bool add) const; 47 | 48 | private: 49 | boost::scoped_ptr fmt_ptr_; 50 | }; 51 | 52 | 53 | }} // namespaces 54 | 55 | #endif // XIVA_DETAILS_FORMATTERS_DATA_SIMPLE_HPP_INCLUDED 56 | -------------------------------------------------------------------------------- /include/details/formatters_factory.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_FORMATTERS_FACTORY_HPP_INCLUDED 19 | #define XIVA_DETAILS_FORMATTERS_FACTORY_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "xiva/forward.hpp" 28 | #include "xiva/formatter.hpp" 29 | #include "details/formatters_data.hpp" 30 | 31 | namespace xiva { namespace details { 32 | 33 | class formatters_factory { 34 | 35 | public: 36 | formatters_factory(); 37 | virtual ~formatters_factory(); 38 | 39 | std::auto_ptr find(std::string const &fmt_id, request const &req) const; 40 | 41 | void attach_creator(std::string const &fmt_id, boost::intrusive_ptr const &fmt_ptr); 42 | 43 | std::auto_ptr create_formatters_data(request_impl const &req, response_impl const &resp) const; 44 | 45 | private: 46 | formatters_factory(formatters_factory const &); 47 | formatters_factory& operator = (formatters_factory const &); 48 | 49 | typedef std::map< std::string, boost::intrusive_ptr > formatters_type; 50 | 51 | formatters_type formatters_; 52 | }; 53 | 54 | 55 | }} // namespaces 56 | 57 | #endif // XIVA_DETAILS_FORMATTERS_FACTORY_HPP_INCLUDED 58 | -------------------------------------------------------------------------------- /include/details/guard.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_GUARD_HPP_INCLUDED 19 | #define XIVA_DETAILS_GUARD_HPP_INCLUDED 20 | 21 | namespace xiva { namespace details { 22 | 23 | class guard { 24 | 25 | public: 26 | guard(); 27 | virtual ~guard(); 28 | 29 | bool open(); // once 30 | bool commit(); // allow close (after open) 31 | bool cancel(); // disallow close (after open) 32 | bool close(); // once (after commit) 33 | 34 | private: 35 | guard(guard const &); 36 | guard& operator = (guard const &); 37 | 38 | private: 39 | int state_; 40 | }; 41 | 42 | }} // namespaces 43 | 44 | #endif // XIVA_DETAILS_GUARD_HPP_INCLUDED 45 | -------------------------------------------------------------------------------- /include/details/handler_invoker_base.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_HANDLER_INVOKER_BASE_HPP_INCLUDED 19 | #define XIVA_DETAILS_HANDLER_INVOKER_BASE_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/shared.hpp" 24 | #include "xiva/forward.hpp" 25 | 26 | namespace xiva { namespace details { 27 | 28 | class handler_invoker_base : public shared { 29 | 30 | public: 31 | handler_invoker_base(); 32 | virtual ~handler_invoker_base(); 33 | 34 | virtual void finish() = 0; 35 | virtual void wait_for_complete() = 0; 36 | virtual void init(settings const &s) = 0; 37 | virtual void attach_logger(boost::intrusive_ptr const &log) = 0; 38 | 39 | private: 40 | handler_invoker_base(handler_invoker_base const &); 41 | handler_invoker_base& operator = (handler_invoker_base const &); 42 | }; 43 | 44 | }} // namespaces 45 | 46 | #endif // XIVA_DETAILS_HANDLER_INVOKER_BASE_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /include/details/http_constants.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_HTTP_CONSTANTS_HPP_INCLUDED 19 | #define XIVA_DETAILS_HTTP_CONSTANTS_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "details/range.hpp" 24 | 25 | namespace xiva { namespace details { 26 | 27 | template 28 | struct http_constants; 29 | 30 | struct http_constants_char { 31 | static char const* const endl; 32 | static range const range_endl; 33 | 34 | static std::string const empty_string; 35 | static range const get; 36 | static range const range_name; 37 | static range const cookie; 38 | static range const param_delimiter; 39 | static range const protocol_version; 40 | 41 | static range const sec_websocket_key1; 42 | 43 | static range const headers_end; 44 | static range const nonstd_headers_end; 45 | }; 46 | 47 | template <> 48 | struct http_constants : public http_constants_char { 49 | }; 50 | 51 | template <> 52 | struct http_constants : public http_constants_char { 53 | }; 54 | 55 | }} // namespaces 56 | 57 | #endif // XIVA_DETAILS_HTTP_CONSTANTS_HPP_INCLUDED 58 | -------------------------------------------------------------------------------- /include/details/iterator_checker.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_ITERATOR_CHECKER_HPP_INCLUDED 19 | #define XIVA_DETAILS_ITERATOR_CHECKER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | namespace xiva { namespace details { 24 | 25 | template 26 | struct iterator_tag_checker; 27 | 28 | template <> 29 | struct iterator_tag_checker { 30 | }; 31 | 32 | template <> 33 | struct iterator_tag_checker { 34 | }; 35 | 36 | template <> 37 | struct iterator_tag_checker { 38 | }; 39 | 40 | template 41 | struct iterator_checker : iterator_tag_checker::iterator_category> { 42 | }; 43 | 44 | }} // namespaces 45 | 46 | #endif // XIVA_DETAILS_ITERATOR_CHECKER_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /include/details/ssl_context.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_SSL_CONTEXT_HPP_INCLUDED 19 | #define XIVA_DETAILS_SSL_CONTEXT_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/forward.hpp" 24 | #include "details/asio.hpp" 25 | #include "details/ssl_connection_socket.hpp" 26 | 27 | namespace xiva { namespace details { 28 | 29 | class ssl_context { 30 | 31 | public: 32 | explicit ssl_context(asio::io_service &io); 33 | virtual ~ssl_context(); 34 | 35 | void init(settings const &s); 36 | 37 | std::auto_ptr create_socket(asio::io_service &io); 38 | 39 | private: 40 | ssl_context(ssl_context const &); 41 | ssl_context& operator = (ssl_context const &); 42 | 43 | private: 44 | asio::ssl::context context_; 45 | }; 46 | 47 | }} // namespaces 48 | 49 | #endif // XIVA_DETAILS_SSL_CONTEXT_HPP_INCLUDED 50 | -------------------------------------------------------------------------------- /include/details/stdio_logger.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_SYSLOG_LOGGER_HPP_INCLUDED 19 | #define XIVA_DETAILS_SYSLOG_LOGGER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/logger.hpp" 24 | 25 | namespace xiva { namespace details { 26 | 27 | class stdio_logger : public logger { 28 | 29 | public: 30 | stdio_logger(); 31 | virtual ~stdio_logger(); 32 | 33 | virtual void info(char const *format, ...); 34 | virtual void debug(char const *format, ...); 35 | virtual void error(char const *format, ...); 36 | 37 | private: 38 | stdio_logger(stdio_logger const &); 39 | stdio_logger& operator = (stdio_logger const &); 40 | void print_message(char const *level, char const *format, va_list args); 41 | }; 42 | 43 | }} // namespaces 44 | 45 | #endif // XIVA_DETAILS_SYSLOG_LOGGER_HPP_INCLUDED 46 | -------------------------------------------------------------------------------- /include/details/system_error.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_SYSTEM_ERROR_HPP_INCLUDED 19 | #define XIVA_DETAILS_SYSTEM_ERROR_HPP_INCLUDED 20 | 21 | #include "xiva/error.hpp" 22 | 23 | namespace xiva { namespace details { 24 | 25 | class system_error : public error { 26 | 27 | public: 28 | system_error(char const *message); 29 | virtual ~system_error() throw (); 30 | 31 | static void throw_error(int error); 32 | static void throw_unless(bool condition); 33 | }; 34 | 35 | }} // namespaces 36 | 37 | #endif // XIVA_DETAILS_SYSTEM_ERROR_HPP_INCLUDED 38 | -------------------------------------------------------------------------------- /include/details/threaded_connection.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_THREADED_CONNECTION_HPP_INCLUDED 19 | #define XIVA_DETAILS_THREADED_CONNECTION_HPP_INCLUDED 20 | 21 | #include "xiva/forward.hpp" 22 | #include "details/connection_base.hpp" 23 | #include "details/threaded_shared.hpp" 24 | 25 | namespace xiva { namespace details { 26 | 27 | class threaded_connection : public threaded_shared, public connection_base { 28 | 29 | public: 30 | threaded_connection(); 31 | virtual ~threaded_connection(); 32 | 33 | private: 34 | threaded_connection(threaded_connection const &); 35 | threaded_connection& operator = (threaded_connection const &); 36 | }; 37 | 38 | }} // namespaces 39 | 40 | #endif // XIVA_DETAILS_THREADED_CONNECTION_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /include/details/url_response_handler.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_URL_RESPONSE_HANDLER_HPP_INCLUDED 19 | #define XIVA_DETAILS_URL_RESPONSE_HANDLER_HPP_INCLUDED 20 | 21 | #include "xiva/response_handler.hpp" 22 | 23 | namespace xiva { namespace details { 24 | 25 | class url_response_handler : public response_handler { 26 | 27 | public: 28 | url_response_handler(); 29 | virtual ~url_response_handler(); 30 | 31 | std::string receiver(std::string const &url) const; 32 | 33 | virtual bool threaded() const; 34 | virtual bool has_enough_data(request const &req) const; 35 | 36 | virtual std::string receiver(request const &req) const; 37 | virtual void handle_response(request const &req, response &resp); 38 | 39 | private: 40 | url_response_handler(url_response_handler const &); 41 | url_response_handler& operator = (url_response_handler const &); 42 | }; 43 | 44 | }} // namespaces 45 | 46 | #endif // XIVA_DETAILS_URL_RESPONSE_HANDLER_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /include/xiva.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_HPP_INCLUDED 19 | #define XIVA_HPP_INCLUDED 20 | 21 | #include "xiva/component_set.hpp" 22 | #include "xiva/config.hpp" 23 | #include "xiva/connection_listener.hpp" 24 | #include "xiva/enumeration.hpp" 25 | #include "xiva/error.hpp" 26 | #include "xiva/forward.hpp" 27 | #include "xiva/formatter.hpp" 28 | #include "xiva/globals.hpp" 29 | #include "xiva/http_error.hpp" 30 | #include "xiva/logger.hpp" 31 | #include "xiva/message.hpp" 32 | #include "xiva/message_sender.hpp" 33 | #include "xiva/response_handler.hpp" 34 | #include "xiva/request.hpp" 35 | #include "xiva/response.hpp" 36 | #include "xiva/server.hpp" 37 | #include "xiva/settings.hpp" 38 | #include "xiva/shared.hpp" 39 | 40 | #endif // XIVA_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /include/xiva/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = channel_id.hpp channel_info.hpp \ 2 | component_set.hpp config.hpp connection_listener.hpp \ 3 | enumeration.hpp error.hpp formatter.hpp formatter_creator.hpp \ 4 | forward.hpp globals.hpp http_error.hpp logger.hpp \ 5 | message.hpp message_filter.hpp message_sender.hpp \ 6 | ping_formatter.hpp request.hpp \ 7 | response.hpp response_handler.hpp server.hpp settings.hpp shared.hpp 8 | -------------------------------------------------------------------------------- /include/xiva/channel_info.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_CHANNEL_INFO_HPP_INCLUDED 19 | #define XIVA_CHANNEL_INFO_HPP_INCLUDED 20 | 21 | 22 | #include 23 | 24 | #include "xiva/config.hpp" 25 | #include "xiva/channel_id.hpp" 26 | 27 | namespace xiva { 28 | 29 | class XIVA_API channel_info : public channel_id { 30 | 31 | public: 32 | channel_info(); 33 | channel_info(std::string const &name, std::string const &key, std::string const &data); 34 | 35 | // simple non-virtual destructor 36 | ~channel_info(); 37 | 38 | std::string const& data() const; 39 | void data(std::string const &value); 40 | 41 | private: 42 | std::string data_; 43 | }; 44 | 45 | 46 | inline 47 | channel_info::channel_info() 48 | { 49 | } 50 | 51 | inline 52 | channel_info::channel_info(std::string const &name, std::string const &key, std::string const &data) : 53 | channel_id(name, key), data_(data) 54 | { 55 | } 56 | 57 | inline 58 | channel_info::~channel_info() { 59 | } 60 | 61 | inline std::string const& 62 | channel_info::data() const { 63 | return data_; 64 | } 65 | 66 | inline void 67 | channel_info::data(std::string const &value) { 68 | data_.assign(value); 69 | } 70 | 71 | 72 | } // namespace 73 | 74 | #endif // XIVA_CHANNEL_INFO_HPP_INCLUDED 75 | -------------------------------------------------------------------------------- /include/xiva/config.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_CONFIG_HPP_INCLUDED 19 | #define XIVA_CONFIG_HPP_INCLUDED 20 | 21 | #ifdef WIN32 22 | #else 23 | #define XIVA_API 24 | #endif // WIN32 25 | 26 | #endif // XIVA_CONFIG_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /include/xiva/error.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_ERROR_HPP_INCLUDED 19 | #define XIVA_ERROR_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | 25 | namespace xiva { 26 | 27 | /** 28 | * This is the xiva-specific exception. 29 | */ 30 | class XIVA_API error : public std::exception { 31 | 32 | public: 33 | /** */ 34 | error(char const *format, ...); 35 | 36 | /** destructor */ 37 | virtual ~error() throw (); 38 | 39 | /** inherited from std::exception 40 | * @return textual description of error. 41 | */ 42 | virtual char const* what() const throw (); 43 | 44 | enum { message_size = 128 }; 45 | 46 | private: 47 | char buffer_[message_size]; 48 | }; 49 | 50 | } // namespace 51 | 52 | #endif // XIVA_ERROR_HPP_INCLUDED 53 | -------------------------------------------------------------------------------- /include/xiva/formatter.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_FORMATTER_HPP_INCLUDED 19 | #define XIVA_FORMATTER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | 25 | namespace xiva { 26 | 27 | 28 | class XIVA_API formatter { 29 | 30 | public: 31 | formatter(); 32 | virtual ~formatter(); 33 | 34 | virtual std::string wrap_message(std::string const &content) const = 0; 35 | 36 | private: 37 | formatter(formatter const &); 38 | formatter& operator = (formatter const &); 39 | }; 40 | 41 | 42 | } // namespace 43 | 44 | #endif // XIVA_FORMATTER_HPP_INCLUDED 45 | -------------------------------------------------------------------------------- /include/xiva/formatter_creator.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_FORMATTER_CREATOR_HPP_INCLUDED 19 | #define XIVA_FORMATTER_CREATOR_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | #include "xiva/shared.hpp" 25 | #include "xiva/formatter.hpp" 26 | #include "xiva/forward.hpp" 27 | 28 | namespace xiva { 29 | 30 | class XIVA_API formatter_creator : public shared { 31 | 32 | public: 33 | formatter_creator(); 34 | virtual ~formatter_creator(); 35 | 36 | virtual std::auto_ptr create(request const &req) const = 0; 37 | 38 | private: 39 | formatter_creator(formatter_creator const &); 40 | formatter_creator& operator = (formatter_creator const &); 41 | }; 42 | 43 | } // namespace 44 | 45 | #endif // XIVA_FORMATTER_CREATOR_HPP_INCLUDED 46 | -------------------------------------------------------------------------------- /include/xiva/forward.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_DETAILS_FORWARD_HPP_INCLUDED 19 | #define XIVA_DETAILS_FORWARD_HPP_INCLUDED 20 | 21 | namespace xiva { 22 | 23 | class channel_id; 24 | class channel_info; 25 | class formatter; 26 | class formatter_creator; 27 | class logger; 28 | class message; 29 | class ping_formatter; 30 | class request; 31 | class response; 32 | class server; 33 | class settings; 34 | 35 | class http_error; 36 | class component_set; 37 | class message_filter; 38 | class message_sender; 39 | class response_handler; 40 | class connection_listener; 41 | 42 | namespace details { 43 | 44 | class channels_stat_impl; 45 | class formatters_factory; 46 | class server_impl; 47 | class request_impl; 48 | class response_impl; 49 | 50 | }} // namespaces 51 | 52 | #endif // XIVA_DETAILS_FORWARD_HPP_INCLUDED 53 | -------------------------------------------------------------------------------- /include/xiva/globals.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_GLOBALS_HPP_INCLUDED 19 | #define XIVA_GLOBALS_HPP_INCLUDED 20 | 21 | namespace xiva { 22 | 23 | class message_sender; 24 | 25 | struct globals { 26 | typedef void (provider_type) (message_sender&); 27 | typedef unsigned long connection_id; 28 | }; 29 | 30 | } // namespace 31 | 32 | #endif // XIVA_GLOBALS_HPP_INCLUDED 33 | -------------------------------------------------------------------------------- /include/xiva/http_error.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_HTTP_ERROR_HPP_INCLUDED 19 | #define XIVA_HTTP_ERROR_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | 25 | namespace xiva { 26 | 27 | class XIVA_API http_error : public std::exception { 28 | 29 | public: 30 | http_error(unsigned short code); 31 | 32 | virtual ~http_error() throw (); 33 | virtual char const* what() const throw (); 34 | unsigned short code() const; 35 | 36 | static unsigned short const bad_request; 37 | static unsigned short const unauthorized; 38 | static unsigned short const payment_required; 39 | static unsigned short const forbidden; 40 | static unsigned short const not_found; 41 | static unsigned short const method_not_allowed; 42 | static unsigned short const entity_too_large; 43 | static unsigned short const range_not_satisfiable; 44 | 45 | static unsigned short const internal_error; 46 | static unsigned short const not_implemented; 47 | static unsigned short const bad_gateway; 48 | static unsigned short const service_unavailable; 49 | static unsigned short const gateway_timeout; 50 | static unsigned short const version_not_supported; 51 | 52 | private: 53 | unsigned short code_; 54 | }; 55 | 56 | } // namespace 57 | 58 | #endif // XIVA_HTTP_ERROR_HPP_INCLUDED 59 | -------------------------------------------------------------------------------- /include/xiva/logger.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_LOGGER_HPP_INCLUDED 19 | #define XIVA_LOGGER_HPP_INCLUDED 20 | 21 | #include "xiva/config.hpp" 22 | #include "xiva/shared.hpp" 23 | 24 | namespace xiva { 25 | 26 | class XIVA_API logger : public shared { 27 | 28 | public: 29 | logger(); 30 | virtual ~logger(); 31 | 32 | virtual void info(char const *format, ...) = 0; 33 | virtual void debug(char const *format, ...) = 0; 34 | virtual void error(char const *format, ...) = 0; 35 | 36 | private: 37 | logger(logger const &); 38 | logger& operator = (logger const &); 39 | }; 40 | 41 | } // namespace 42 | 43 | #endif // XIVA_LOGGER_HPP_INCLUDED 44 | -------------------------------------------------------------------------------- /include/xiva/message.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_MESSAGE_HPP_INCLUDED 19 | #define XIVA_MESSAGE_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | #include "xiva/channel_info.hpp" 25 | 26 | namespace xiva { 27 | 28 | class XIVA_API message { 29 | public: 30 | message(); 31 | message(std::string const &value); 32 | template message(Iter begin, Iter end); 33 | virtual ~message(); 34 | 35 | std::string const& content() const; 36 | void content(std::string const &value); 37 | 38 | channel_info const& get_channel_info() const; 39 | void set_channel_info(channel_info const &ch_info); 40 | 41 | private: 42 | message(message const &); 43 | message& operator = (message const &); 44 | 45 | private: 46 | std::string content_; 47 | channel_info ch_info_; 48 | }; 49 | 50 | template inline 51 | message::message(Iter begin, Iter end) : 52 | content_(begin, end) { 53 | } 54 | 55 | } // namespace 56 | 57 | #endif // XIVA_MESSAGE_HPP_INCLUDED 58 | -------------------------------------------------------------------------------- /include/xiva/message_filter.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_MESSAGE_FILTER_HPP_INCLUDED 19 | #define XIVA_MESSAGE_FILTER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | #include "xiva/forward.hpp" 25 | #include "xiva/shared.hpp" 26 | 27 | namespace xiva { 28 | 29 | class message; 30 | 31 | class XIVA_API message_filter : public shared { 32 | 33 | public: 34 | message_filter(); 35 | virtual ~message_filter(); 36 | 37 | virtual bool allow_message(message const &msg, std::string const &channel_data) const = 0; 38 | 39 | private: 40 | message_filter(message_filter const &); 41 | message_filter& operator = (message_filter const &); 42 | }; 43 | 44 | } // namespace 45 | 46 | #endif // XIVA_MESSAGE_FILTER_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /include/xiva/message_sender.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_MESSAGE_SENDER_HPP_INCLUDED 19 | #define XIVA_MESSAGE_SENDER_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include "xiva/config.hpp" 25 | #include "xiva/globals.hpp" 26 | 27 | namespace xiva { 28 | 29 | class message; 30 | 31 | class XIVA_API message_sender { 32 | 33 | public: 34 | message_sender(); 35 | virtual ~message_sender(); 36 | 37 | virtual bool active() const = 0; 38 | virtual void send(std::string const &to, boost::shared_ptr const &m) = 0; 39 | virtual void send(globals::connection_id to, boost::shared_ptr const &m) = 0; 40 | 41 | private: 42 | message_sender(message_sender const &); 43 | message_sender& operator = (message_sender const &); 44 | }; 45 | 46 | } // namespace 47 | 48 | #endif // XIVA_MESSAGE_SENDER_HPP_INCLUDED 49 | -------------------------------------------------------------------------------- /include/xiva/ping_formatter.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PING_FORMATTER_HPP_INCLUDED 19 | #define XIVA_PING_FORMATTER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | #include "xiva/shared.hpp" 25 | 26 | namespace xiva { 27 | 28 | 29 | class XIVA_API ping_formatter : public shared { 30 | 31 | public: 32 | ping_formatter(); 33 | virtual ~ping_formatter(); 34 | 35 | virtual std::string message() const = 0; 36 | virtual std::string message_for_single() const = 0; 37 | 38 | private: 39 | ping_formatter(ping_formatter const &); 40 | ping_formatter& operator = (ping_formatter const &); 41 | }; 42 | 43 | 44 | } // namespace 45 | 46 | #endif // XIVA_PING_FORMATTER_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /include/xiva/request.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_REQUEST_HPP_INCLUDED 19 | #define XIVA_REQUEST_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | #include "xiva/forward.hpp" 25 | #include "xiva/enumeration.hpp" 26 | 27 | namespace xiva { 28 | 29 | class XIVA_API request { 30 | 31 | public: 32 | request(details::request_impl const &impl); 33 | virtual ~request(); 34 | 35 | std::string const& uri() const; 36 | 37 | bool has_param(std::string const &name) const; 38 | std::string const& param(std::string const &name) const; 39 | enumeration::ptr_type params(std::string const &name) const; 40 | 41 | bool has_header(std::string const &name) const; 42 | std::string const& header(std::string const &name) const; 43 | 44 | bool has_cookie(std::string const &name) const; 45 | std::string const& cookie(std::string const &name) const; 46 | 47 | bool is_websocket() const; 48 | 49 | private: 50 | details::request_impl const &impl_; 51 | }; 52 | 53 | } // namespace 54 | 55 | #endif // XIVA_REQUEST_HPP_INCLUDED 56 | -------------------------------------------------------------------------------- /include/xiva/response.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_RESPONSE_HPP_INCLUDED 19 | #define XIVA_RESPONSE_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | #include "xiva/forward.hpp" 25 | 26 | namespace xiva { 27 | 28 | class XIVA_API response { 29 | 30 | public: 31 | response(details::response_impl &impl); 32 | virtual ~response(); 33 | 34 | void content_type(char const *type); 35 | void content_type(std::string const &type); 36 | 37 | void formatter_id(std::string const &fmt_id); 38 | 39 | void formatter_by_channel(channel_info const &ch_info, std::string const &fmt_id); 40 | 41 | void set_header(std::string const &name, std::string const &value); 42 | 43 | void single_message(bool value); 44 | 45 | void content(std::string const &body); 46 | void content(std::string const *body); 47 | 48 | private: 49 | response(response const &); 50 | response& operator = (response const &); 51 | 52 | private: 53 | details::response_impl &impl_; 54 | }; 55 | 56 | } // namespace 57 | 58 | #endif // XIVA_RESPONSE_HPP_INCLUDED 59 | -------------------------------------------------------------------------------- /include/xiva/response_handler.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_RESPONSE_HANDLER_HPP_INCLUDED 19 | #define XIVA_RESPONSE_HANDLER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | #include "xiva/shared.hpp" 25 | 26 | namespace xiva { 27 | 28 | class request; 29 | class response; 30 | 31 | class XIVA_API response_handler : public shared { 32 | 33 | public: 34 | response_handler(); 35 | virtual ~response_handler(); 36 | 37 | virtual bool threaded() const = 0; 38 | virtual bool has_enough_data(request const &req) const = 0; 39 | 40 | virtual std::string receiver(request const &req) const = 0; 41 | virtual void handle_response(request const &req, response &resp) = 0; 42 | 43 | private: 44 | response_handler(response_handler const &); 45 | response_handler& operator = (response_handler const &); 46 | }; 47 | 48 | } // namespace 49 | 50 | #endif // XIVA_RESPONSE_HANDLER_HPP_INCLUDED 51 | -------------------------------------------------------------------------------- /include/xiva/shared.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_SHARED_HPP_INCLUDED 19 | #define XIVA_SHARED_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/config.hpp" 24 | 25 | namespace xiva { 26 | 27 | class shared; 28 | 29 | void intrusive_ptr_add_ref(shared *object); 30 | void intrusive_ptr_release(shared *object); 31 | 32 | class XIVA_API shared { 33 | 34 | public: 35 | shared(); 36 | virtual ~shared(); 37 | 38 | private: 39 | shared(const shared &); 40 | shared& operator = (const shared &); 41 | 42 | friend void intrusive_ptr_add_ref(shared *object); 43 | friend void intrusive_ptr_release(shared *object); 44 | 45 | private: 46 | int count_; 47 | }; 48 | 49 | inline 50 | shared::shared() : 51 | count_(0) { 52 | } 53 | 54 | inline 55 | shared::~shared() { 56 | assert(0 == count_); 57 | } 58 | 59 | inline XIVA_API void 60 | intrusive_ptr_add_ref(shared *object) { 61 | ++object->count_; 62 | } 63 | 64 | 65 | inline XIVA_API void 66 | intrusive_ptr_release(shared *object) { 67 | if (0 == --object->count_) delete object; 68 | } 69 | 70 | } // namespace 71 | 72 | #endif // XIVA_SHARED_HPP_INCLUDED 73 | -------------------------------------------------------------------------------- /library/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libxiva.la 2 | 3 | libxiva_la_LDFLAGS = @BOOST_THREAD_LDFLAGS@ @BOOST_SYSTEM_LDFLAGS@ 4 | libxiva_la_SOURCES = acceptor_base.cpp channels_stat_impl.cpp \ 5 | component_set.cpp compound_listener.cpp connection.cpp connection_base.cpp \ 6 | connection_socket.cpp connection_data.cpp connection_listener.cpp connection_manager_base.cpp \ 7 | connection_traits_base.cpp error.cpp formatter.cpp formatter_creator.cpp \ 8 | formatters_data.cpp formatters_data_channels.cpp formatters_data_simple.cpp \ 9 | formatters_factory.cpp guard.cpp handler_invoker.cpp handler_invoker_base.cpp \ 10 | http.cpp http_constants.cpp http_error.cpp logger.cpp message.cpp message_filter.cpp \ 11 | message_queue.cpp message_sender.cpp ping_formatter.cpp request.cpp request_impl.cpp \ 12 | response.cpp response_handler.cpp response_impl.cpp server.cpp \ 13 | server_impl.cpp settings.cpp ssl_connection_socket.cpp \ 14 | ssl_context.cpp stdio_logger.cpp system_error.cpp \ 15 | threaded_connection.cpp threaded_handler_invoker.cpp \ 16 | threaded_listener.cpp url_response_handler.cpp websocket_info.cpp 17 | 18 | noinst_LTLIBRARIES = libxiva-loader.la 19 | 20 | top_build_prefix=../ 21 | libxiva_loader_la_LIBADD = libxiva.la 22 | libxiva_loader_la_LDFLAGS = @LIBLTDL@ @BOOST_LDFLAGS@ 23 | libxiva_loader_la_SOURCES = dynamic_loader.cpp 24 | 25 | AM_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/config \ 26 | @INCLTDL@ @BOOST_CPPFLAGS@ 27 | AM_CXXFLAGS = -pthread 28 | AM_LDFLAGS = @BOOST_LDFLAGS@ 29 | -------------------------------------------------------------------------------- /library/acceptor_base.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/acceptor_base.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | acceptor_base::acceptor_base() 7 | { 8 | } 9 | 10 | acceptor_base::~acceptor_base() { 11 | } 12 | 13 | }} // namespaces 14 | -------------------------------------------------------------------------------- /library/component_set.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/component_set.hpp" 3 | 4 | namespace xiva { 5 | 6 | component_set::component_set() 7 | { 8 | } 9 | 10 | component_set::~component_set() { 11 | } 12 | 13 | } // namespace 14 | -------------------------------------------------------------------------------- /library/connection.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/connection.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | connection::connection() 7 | { 8 | } 9 | 10 | connection::~connection() { 11 | } 12 | 13 | }} // namespaces 14 | -------------------------------------------------------------------------------- /library/connection_listener.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/connection_listener.hpp" 3 | 4 | namespace xiva { 5 | 6 | connection_listener::connection_listener() { 7 | } 8 | 9 | connection_listener::~connection_listener() { 10 | } 11 | 12 | } // namespace 13 | -------------------------------------------------------------------------------- /library/connection_socket.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/connection_socket.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | connection_socket::connection_socket(asio::io_service &io) : socket_(io) 7 | { 8 | } 9 | 10 | connection_socket::~connection_socket() { 11 | } 12 | 13 | }} // namespaces 14 | -------------------------------------------------------------------------------- /library/connection_traits_base.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/connection_traits_base.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | connection_traits_base::connection_traits_base() { 7 | } 8 | 9 | connection_traits_base::~connection_traits_base() { 10 | } 11 | 12 | }} // namespaces 13 | -------------------------------------------------------------------------------- /library/dynamic_loader.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/dynamic_loader.hpp" 3 | 4 | #include 5 | #include 6 | 7 | #include "xiva/error.hpp" 8 | #include "xiva/settings.hpp" 9 | #include "xiva/component_set.hpp" 10 | 11 | #include "details/resource.hpp" 12 | 13 | namespace xiva { namespace details { 14 | 15 | struct handle_traits : public default_traits { 16 | void destroy(lt_dlhandle handle); 17 | }; 18 | 19 | dynamic_loader::dynamic_loader() { 20 | lt_dlinit(); 21 | } 22 | 23 | dynamic_loader::~dynamic_loader() { 24 | std::for_each(handles_.begin(), handles_.end(), boost::bind(<_dlclose, _1)); 25 | lt_dlexit(); 26 | } 27 | 28 | void 29 | dynamic_loader::load_module(std::string const &name, settings const &s, component_set &cs) { 30 | 31 | typedef void (*register_func_type)(settings const &, component_set &); 32 | if (name.empty()) { 33 | throw error("cannot load empty module"); 34 | } 35 | 36 | resource handle(lt_dlopen(name.c_str())); 37 | check_loaded(handle); 38 | 39 | register_func_type func = (register_func_type) lt_dlsym(handle.get(), "xiva_register_module"); 40 | if (!func) { 41 | throw error("cannot find xiva_register_module function in %s", name.c_str()); 42 | } 43 | 44 | func(s, cs); 45 | handles_.push_back(handle.get()); 46 | handle.release(); 47 | } 48 | 49 | void 50 | dynamic_loader::check_loaded(bool condition) const { 51 | if (!condition) { 52 | throw error("%s", lt_dlerror()); 53 | } 54 | } 55 | 56 | void 57 | handle_traits::destroy(lt_dlhandle handle) { 58 | lt_dlclose(handle); 59 | } 60 | 61 | }} // namespaces 62 | -------------------------------------------------------------------------------- /library/error.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/error.hpp" 3 | 4 | #include 5 | #include 6 | 7 | namespace xiva { 8 | 9 | error::error(char const *format, ...) { 10 | va_list args; 11 | va_start(args, format); 12 | vsnprintf(buffer_, message_size, format, args); 13 | va_end(args); 14 | } 15 | 16 | error::~error() throw () { 17 | } 18 | 19 | char const* 20 | error::what() const throw () { 21 | return buffer_; 22 | } 23 | 24 | } // namespace 25 | -------------------------------------------------------------------------------- /library/formatter.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/formatter.hpp" 3 | 4 | namespace xiva { 5 | 6 | formatter::formatter() 7 | { 8 | } 9 | 10 | formatter::~formatter() { 11 | } 12 | 13 | } // namespace 14 | -------------------------------------------------------------------------------- /library/formatter_creator.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/formatter_creator.hpp" 3 | 4 | namespace xiva { 5 | 6 | formatter_creator::formatter_creator() 7 | { 8 | } 9 | 10 | formatter_creator::~formatter_creator() { 11 | } 12 | 13 | } // namespace 14 | -------------------------------------------------------------------------------- /library/formatters_data.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/formatters_data.hpp" 3 | 4 | 5 | namespace xiva { namespace details { 6 | 7 | formatters_data::formatters_data() 8 | { 9 | } 10 | 11 | formatters_data::~formatters_data() { 12 | } 13 | 14 | 15 | } } // namespaces 16 | -------------------------------------------------------------------------------- /library/formatters_data_simple.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/formatters_data_simple.hpp" 3 | 4 | #include 5 | 6 | #include "xiva/message_filter.hpp" 7 | #include "xiva/request.hpp" 8 | #include "xiva/formatter.hpp" 9 | 10 | #include "details/response_impl.hpp" 11 | #include "details/formatters_factory.hpp" 12 | #include "details/http_constants.hpp" 13 | 14 | namespace xiva { namespace details { 15 | 16 | formatters_data_simple::formatters_data_simple(formatter *fmt_ptr) : 17 | fmt_ptr_(fmt_ptr) 18 | { 19 | assert(fmt_ptr); 20 | } 21 | 22 | formatters_data_simple::~formatters_data_simple() { 23 | } 24 | 25 | std::auto_ptr 26 | formatters_data_simple::create( 27 | formatters_factory const &factory, request_impl const &req, response_impl const &resp) 28 | { 29 | assert(resp.channels_data().empty()); 30 | 31 | std::string const &fmt_id = resp.default_formatter_id(); 32 | if (!fmt_id.empty()) { 33 | request request_adapter(req); 34 | std::auto_ptr fmt_ptr = factory.find(fmt_id, request_adapter); 35 | if (NULL != fmt_ptr.get()) { 36 | return std::auto_ptr(new formatters_data_simple(fmt_ptr.release())); 37 | } 38 | } 39 | return std::auto_ptr(); 40 | } 41 | 42 | bool 43 | formatters_data_simple::allow_message(message const& msg, message_filter const *filter) const { 44 | return NULL == filter || filter->allow_message(msg, http_constants::empty_string); 45 | } 46 | 47 | formatter const* 48 | formatters_data_simple::find_formatter(message const &msg) const { 49 | (void) msg; 50 | return fmt_ptr_.get(); 51 | } 52 | 53 | void 54 | formatters_data_simple::update(message const& msg) { 55 | (void) msg; 56 | } 57 | 58 | void 59 | formatters_data_simple::update_channels_stat(channels_stat_impl &ch_stat, bool add) const { 60 | (void) ch_stat; 61 | (void) add; 62 | } 63 | 64 | } } // namespaces 65 | -------------------------------------------------------------------------------- /library/formatters_factory.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/formatters_factory.hpp" 3 | 4 | #include "xiva/formatter.hpp" 5 | #include "xiva/formatter_creator.hpp" 6 | #include "xiva/response_handler.hpp" 7 | 8 | #include "details/response_impl.hpp" 9 | #include "details/formatters_data_channels.hpp" 10 | #include "details/formatters_data_simple.hpp" 11 | 12 | 13 | namespace xiva { namespace details { 14 | 15 | formatters_factory::formatters_factory() 16 | { 17 | } 18 | 19 | formatters_factory::~formatters_factory() { 20 | } 21 | 22 | std::auto_ptr 23 | formatters_factory::find(std::string const &fmt_id, request const &req) const { 24 | formatters_type::const_iterator i = formatters_.find(fmt_id); 25 | if (formatters_.end() != i) { 26 | formatter_creator const *creator = i->second.get(); 27 | if (NULL != creator) { 28 | return creator->create(req); 29 | } 30 | } 31 | return std::auto_ptr(); 32 | } 33 | 34 | void 35 | formatters_factory::attach_creator(std::string const &fmt_id, boost::intrusive_ptr const &creator) { 36 | formatters_.insert(std::make_pair(fmt_id, creator)); 37 | } 38 | 39 | std::auto_ptr 40 | formatters_factory::create_formatters_data(request_impl const &req, response_impl const &resp) const { 41 | if (!resp.channels_data().empty()) { 42 | return std::auto_ptr(new formatters_data_channels(*this, req, resp)); 43 | } 44 | return formatters_data_simple::create(*this, req, resp); 45 | } 46 | 47 | }} // namespaces 48 | -------------------------------------------------------------------------------- /library/guard.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/guard.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | static const int GUARD_NONE = 0; 7 | static const int GUARD_OPENED = 1; 8 | static const int GUARD_OK = 2; 9 | static const int GUARD_CANCELED = 3; 10 | static const int GUARD_CLOSED = 4; 11 | 12 | 13 | 14 | guard::guard() : state_(GUARD_NONE) 15 | { 16 | } 17 | 18 | guard::~guard() { 19 | } 20 | 21 | bool 22 | guard::open() { 23 | if (GUARD_NONE != state_) { 24 | return false; 25 | } 26 | state_ = GUARD_OPENED; 27 | return true; 28 | } 29 | 30 | bool 31 | guard::commit() { 32 | if (GUARD_OPENED != state_) { 33 | return false; 34 | } 35 | state_ = GUARD_OK; 36 | return true; 37 | } 38 | 39 | bool 40 | guard::cancel() { 41 | if (GUARD_OPENED != state_) { 42 | return false; 43 | } 44 | state_ = GUARD_CANCELED; 45 | return true; 46 | } 47 | 48 | bool 49 | guard::close() { 50 | if (GUARD_OK != state_) { 51 | return false; 52 | } 53 | state_ = GUARD_CLOSED; 54 | return true; 55 | } 56 | 57 | }} // namespaces 58 | -------------------------------------------------------------------------------- /library/handler_invoker.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/handler_invoker.hpp" 3 | 4 | #include 5 | #include 6 | 7 | #include "xiva/request.hpp" 8 | #include "xiva/response.hpp" 9 | #include "xiva/http_error.hpp" 10 | #include "xiva/response_handler.hpp" 11 | 12 | #include "details/connection.hpp" 13 | #include "details/connection_data.hpp" 14 | 15 | namespace xiva { namespace details { 16 | 17 | handler_invoker::handler_invoker(asio::io_service::strand &st, connection_data const &data) 18 | { 19 | (void)st; 20 | 21 | handler_ = data.handler(); 22 | assert(handler_); 23 | assert(!handler_->threaded()); 24 | } 25 | 26 | handler_invoker::~handler_invoker() { 27 | } 28 | 29 | void 30 | handler_invoker::init(settings const &s) { 31 | (void) s; 32 | } 33 | 34 | void 35 | handler_invoker::finish() { 36 | } 37 | 38 | void 39 | handler_invoker::wait_for_complete() { 40 | } 41 | 42 | void 43 | handler_invoker::attach_logger(boost::intrusive_ptr const &log) { 44 | (void) log; 45 | } 46 | 47 | void 48 | handler_invoker::invoke_handler(handler_invoker::connection_ptr_type conn, request_impl &req, response_impl &resp) { 49 | 50 | request request_adapter(req); 51 | if (!handler_->has_enough_data(request_adapter)) { 52 | throw http_error(http_error::forbidden); 53 | } 54 | std::string receiver = handler_->receiver(request_adapter); 55 | conn->name(receiver); 56 | 57 | response response_adapter(resp); 58 | handler_->handle_response(request_adapter, response_adapter); 59 | conn->handled(req, resp); 60 | } 61 | 62 | }} // namespaces 63 | -------------------------------------------------------------------------------- /library/handler_invoker_base.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/handler_invoker_base.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | handler_invoker_base::handler_invoker_base() 7 | { 8 | } 9 | 10 | handler_invoker_base::~handler_invoker_base() { 11 | } 12 | 13 | }} // namespaces 14 | -------------------------------------------------------------------------------- /library/http_constants.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/http_constants.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | char const* const 7 | http_constants_char::endl = "\r\n"; 8 | 9 | range const 10 | http_constants_char::range_endl = make_range("\r\n"); 11 | 12 | std::string const 13 | http_constants_char::empty_string; 14 | 15 | range const 16 | http_constants_char::get = make_range("get"); 17 | 18 | range const 19 | http_constants_char::range_name = make_range("range"); 20 | 21 | range const 22 | http_constants_char::cookie = make_range("cookie"); 23 | 24 | range const 25 | http_constants_char::param_delimiter = make_range(";&"); 26 | 27 | range const 28 | http_constants_char::protocol_version = make_range("http/1.1"); 29 | 30 | range const 31 | http_constants_char::sec_websocket_key1 = make_range("sec-websocket-key1"); 32 | 33 | range const 34 | http_constants_char::headers_end = make_range("\r\n\r\n"); 35 | 36 | range const 37 | http_constants_char::nonstd_headers_end = make_range("\n\n"); 38 | 39 | }} // namespaces 40 | -------------------------------------------------------------------------------- /library/http_error.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/http_error.hpp" 3 | #include "details/http.hpp" 4 | 5 | namespace xiva { 6 | 7 | unsigned short const http_error::bad_request = 400; 8 | unsigned short const http_error::unauthorized = 401; 9 | unsigned short const http_error::payment_required = 402; 10 | unsigned short const http_error::forbidden = 403; 11 | unsigned short const http_error::not_found = 404; 12 | unsigned short const http_error::method_not_allowed = 405; 13 | unsigned short const http_error::entity_too_large = 413; 14 | unsigned short const http_error::range_not_satisfiable = 416; 15 | 16 | unsigned short const http_error::internal_error = 500; 17 | unsigned short const http_error::not_implemented = 501; 18 | unsigned short const http_error::bad_gateway = 502; 19 | unsigned short const http_error::service_unavailable = 503; 20 | unsigned short const http_error::gateway_timeout = 504; 21 | unsigned short const http_error::version_not_supported = 505; 22 | 23 | http_error::http_error(unsigned short code) : 24 | code_(code) 25 | { 26 | } 27 | 28 | http_error::~http_error() throw () { 29 | } 30 | 31 | char const* 32 | http_error::what() const throw () { 33 | return details::http_status::str(code_); 34 | } 35 | 36 | unsigned short 37 | http_error::code() const { 38 | return code_; 39 | } 40 | 41 | } // namespace 42 | 43 | -------------------------------------------------------------------------------- /library/logger.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/logger.hpp" 3 | 4 | namespace xiva { 5 | 6 | logger::logger() 7 | { 8 | } 9 | 10 | logger::~logger() { 11 | } 12 | 13 | } // namespace 14 | -------------------------------------------------------------------------------- /library/message.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/message.hpp" 3 | 4 | #include "xiva/channel_info.hpp" 5 | 6 | namespace xiva { 7 | 8 | message::message() 9 | { 10 | } 11 | 12 | message::message(std::string const &value) : 13 | content_(value) 14 | { 15 | } 16 | 17 | message::~message() { 18 | } 19 | 20 | std::string const& 21 | message::content() const { 22 | return content_; 23 | } 24 | 25 | void 26 | message::content(std::string const &value) { 27 | content_.assign(value); 28 | } 29 | 30 | channel_info const& 31 | message::get_channel_info() const { 32 | return ch_info_; 33 | } 34 | 35 | void 36 | message::set_channel_info(channel_info const &ch_info) { 37 | ch_info_ = ch_info; 38 | } 39 | 40 | 41 | } // namespace 42 | -------------------------------------------------------------------------------- /library/message_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/message_filter.hpp" 3 | 4 | namespace xiva { 5 | 6 | message_filter::message_filter() 7 | { 8 | } 9 | 10 | message_filter::~message_filter() { 11 | } 12 | 13 | } // namespace 14 | -------------------------------------------------------------------------------- /library/message_sender.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/message_sender.hpp" 3 | 4 | namespace xiva { 5 | 6 | message_sender::message_sender() { 7 | } 8 | 9 | message_sender::~message_sender() { 10 | } 11 | 12 | } // namespaces 13 | -------------------------------------------------------------------------------- /library/ping_formatter.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/ping_formatter.hpp" 3 | 4 | namespace xiva { 5 | 6 | ping_formatter::ping_formatter() 7 | { 8 | } 9 | 10 | ping_formatter::~ping_formatter() { 11 | } 12 | 13 | } // namespace 14 | -------------------------------------------------------------------------------- /library/request.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/request.hpp" 3 | #include "details/request_impl.hpp" 4 | 5 | namespace xiva { 6 | 7 | request::request(details::request_impl const &impl) : 8 | impl_(impl) 9 | { 10 | } 11 | 12 | request::~request() { 13 | } 14 | 15 | std::string const& 16 | request::uri() const { 17 | return impl_.uri(); 18 | } 19 | 20 | bool 21 | request::has_param(std::string const &name) const { 22 | return impl_.has_param(name); 23 | } 24 | 25 | std::string const& 26 | request::param(std::string const &name) const { 27 | return impl_.param(name); 28 | } 29 | 30 | enumeration::ptr_type 31 | request::params(std::string const &name) const { 32 | return impl_.params(name); 33 | } 34 | 35 | bool 36 | request::has_header(std::string const &name) const { 37 | return impl_.has_header(name); 38 | } 39 | 40 | std::string const& 41 | request::header(std::string const &name) const { 42 | return impl_.header(name); 43 | } 44 | 45 | bool 46 | request::has_cookie(std::string const &name) const { 47 | return impl_.has_cookie(name); 48 | } 49 | 50 | std::string const& 51 | request::cookie(std::string const &name) const { 52 | return impl_.cookie(name); 53 | } 54 | 55 | bool 56 | request::is_websocket() const { 57 | return impl_.is_websocket(); 58 | } 59 | 60 | } // namespace 61 | -------------------------------------------------------------------------------- /library/response.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/response.hpp" 3 | #include "details/response_impl.hpp" 4 | 5 | namespace xiva { 6 | 7 | response::response(details::response_impl &impl) : 8 | impl_(impl) 9 | { 10 | } 11 | 12 | response::~response() { 13 | } 14 | 15 | void 16 | response::content_type(char const *type) { 17 | impl_.content_type(std::string(type)); 18 | } 19 | 20 | void 21 | response::content_type(std::string const &type) { 22 | impl_.content_type(type); 23 | } 24 | 25 | void 26 | response::formatter_id(std::string const &fmt_id) { 27 | impl_.formatter_id(fmt_id); 28 | } 29 | 30 | void 31 | response::formatter_by_channel(channel_info const &ch_info, std::string const &fmt_id) { 32 | impl_.formatter_by_channel(ch_info, fmt_id); 33 | } 34 | 35 | void 36 | response::set_header(std::string const &name, std::string const &value) { 37 | impl_.set_header(name, value); 38 | } 39 | 40 | void 41 | response::single_message(bool value) { 42 | impl_.single_message(value); 43 | } 44 | 45 | void 46 | response::content(std::string const &body) { 47 | impl_.content(body); 48 | } 49 | 50 | void 51 | response::content(std::string const *body) { 52 | impl_.content(body); 53 | } 54 | 55 | } // namespaces 56 | -------------------------------------------------------------------------------- /library/response_handler.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/response_handler.hpp" 3 | 4 | namespace xiva { 5 | 6 | response_handler::response_handler() 7 | { 8 | } 9 | 10 | response_handler::~response_handler() { 11 | } 12 | 13 | } // namespace 14 | -------------------------------------------------------------------------------- /library/response_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/response_impl.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | response_impl::response_impl() : headers_(new headers_data_type()), content_ptr_(NULL), single_message_(false) 7 | { 8 | } 9 | 10 | response_impl::~response_impl() { 11 | } 12 | 13 | void 14 | response_impl::swap(response_impl &other) throw () { 15 | std::swap(type_, other.type_); 16 | std::swap(formatter_id_, other.formatter_id_); 17 | std::swap(content_, other.content_); 18 | std::swap(content_ptr_, other.content_ptr_); 19 | std::swap(single_message_, other.single_message_); 20 | std::swap(channels_data_, other.channels_data_); 21 | std::swap(headers_, other.headers_); 22 | } 23 | 24 | void 25 | response_impl::set_header(std::string const &name, std::string const &value) { 26 | if (!name.empty()) { 27 | headers_->insert(std::make_pair(name, value)); 28 | } 29 | } 30 | 31 | void 32 | response_impl::formatter_by_channel(channel_info const &ch_info, std::string const &fmt_id) { 33 | if (!ch_info.empty()) { 34 | channels_data_[ch_info] = fmt_id; 35 | } 36 | } 37 | 38 | 39 | }} // namespaces 40 | -------------------------------------------------------------------------------- /library/server.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/server.hpp" 3 | #include "details/server_impl.hpp" 4 | 5 | namespace xiva { 6 | 7 | server::server() : 8 | impl_(new details::server_impl()) 9 | { 10 | } 11 | 12 | server::~server() { 13 | } 14 | 15 | void 16 | server::stop() { 17 | impl_->stop(); 18 | } 19 | 20 | void 21 | server::start(settings const &s) { 22 | impl_->init(s); 23 | impl_->start(); 24 | } 25 | 26 | void 27 | server::send(std::string const &to, boost::shared_ptr const &m) { 28 | impl_->send(to, m); 29 | } 30 | 31 | void 32 | server::send(globals::connection_id to, boost::shared_ptr const &m) { 33 | impl_->send(to, m); 34 | } 35 | 36 | void 37 | server::notify_connection_opened_failed(std::string const &to, globals::connection_id id) { 38 | impl_->notify_connection_opened_failed(to, id); 39 | } 40 | 41 | component_set& 42 | server::components() { 43 | return *impl_; 44 | } 45 | 46 | void 47 | server::start_provider(unsigned short nthreads, boost::function f) { 48 | impl_->start_provider(nthreads, f); 49 | } 50 | 51 | void 52 | server::attach_logger(boost::intrusive_ptr const &log) { 53 | impl_->attach_logger(log); 54 | } 55 | 56 | void 57 | server::attach_response_handler(boost::intrusive_ptr const &m) { 58 | impl_->attach_response_handler(m); 59 | } 60 | 61 | void 62 | server::attach_ping_formatter(boost::intrusive_ptr const &f) { 63 | impl_->attach_ping_formatter(f); 64 | } 65 | 66 | void 67 | server::attach_formatter_creator(std::string const &fmt_id, boost::intrusive_ptr const &creator) { 68 | impl_->attach_formatter_creator(fmt_id, creator); 69 | } 70 | 71 | void 72 | server::add_connection_listener(boost::intrusive_ptr const &l) { 73 | impl_->add_connection_listener(l); 74 | } 75 | 76 | void 77 | server::attach_message_filter(boost::intrusive_ptr const &filter) { 78 | impl_->attach_message_filter(filter); 79 | } 80 | 81 | } // namespace 82 | -------------------------------------------------------------------------------- /library/settings.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "xiva/settings.hpp" 3 | 4 | namespace xiva { 5 | 6 | settings::settings() 7 | { 8 | } 9 | 10 | settings::~settings() { 11 | } 12 | 13 | std::string 14 | settings::value(std::string const &name) const { 15 | return value(name.c_str()); 16 | } 17 | 18 | enumeration::ptr_type 19 | settings::value_list(std::string const &prefix) const { 20 | return value_list(prefix.c_str()); 21 | } 22 | 23 | } // namespace 24 | -------------------------------------------------------------------------------- /library/ssl_connection_socket.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/ssl_connection_socket.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | ssl_connection_socket::ssl_connection_socket(asio::io_service &io, asio::ssl::context& context) : socket_(io, context) 7 | { 8 | } 9 | 10 | ssl_connection_socket::~ssl_connection_socket() { 11 | } 12 | 13 | }} // namespaces 14 | -------------------------------------------------------------------------------- /library/ssl_context.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/ssl_context.hpp" 3 | 4 | #include 5 | 6 | #include "xiva/settings.hpp" 7 | #include "details/ssl_connection_socket.hpp" 8 | 9 | 10 | namespace xiva { namespace details { 11 | 12 | ssl_context::ssl_context(asio::io_service &io) : context_(io, asio::ssl::context::sslv23) 13 | { 14 | } 15 | 16 | ssl_context::~ssl_context() { 17 | } 18 | 19 | void 20 | ssl_context::init(settings const &s) { 21 | 22 | context_.set_options(asio::ssl::context::default_workarounds); 23 | 24 | std::string cacert = s.ssl_cacert_file_name(); 25 | if (!cacert.empty()) { 26 | context_.load_verify_file(cacert.c_str()); 27 | } 28 | 29 | std::string cert = s.ssl_cert_file_name(); 30 | if (!cert.empty()) { 31 | //context_.use_certificate_file(cert.c_str(), asio::ssl::context::pem); 32 | context_.use_certificate_chain_file(cert.c_str()); 33 | context_.use_private_key_file(cert.c_str(), asio::ssl::context::pem); 34 | } 35 | } 36 | 37 | std::auto_ptr 38 | ssl_context::create_socket(asio::io_service &io) { 39 | return std::auto_ptr(new ssl_connection_socket(io, context_)); 40 | } 41 | 42 | }} // namespaces 43 | -------------------------------------------------------------------------------- /library/stdio_logger.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/stdio_logger.hpp" 3 | 4 | #include 5 | 6 | #include "details/system_error.hpp" 7 | 8 | namespace xiva { namespace details { 9 | 10 | stdio_logger::stdio_logger() 11 | { 12 | } 13 | 14 | stdio_logger::~stdio_logger() { 15 | } 16 | 17 | void 18 | stdio_logger::info(char const *format, ...) { 19 | va_list args; 20 | va_start(args, format); 21 | print_message("[INFO]", format, args); 22 | va_end(args); 23 | } 24 | 25 | void 26 | stdio_logger::debug(char const *format, ...) { 27 | va_list args; 28 | va_start(args, format); 29 | print_message("[DEBUG]", format, args); 30 | va_end(args); 31 | } 32 | 33 | void 34 | stdio_logger::error(char const *format, ...) { 35 | va_list args; 36 | va_start(args, format); 37 | print_message("[ERROR]", format, args); 38 | va_end(args); 39 | } 40 | 41 | void 42 | stdio_logger::print_message(char const *level, char const *format, va_list args) { 43 | char buffer[1024]; 44 | int res = vsnprintf(buffer, sizeof(buffer) - 1, format, args); 45 | system_error::throw_unless(static_cast(res) < sizeof(buffer)); 46 | buffer[sizeof(buffer) - 1] = '\0'; 47 | fprintf(stderr, "%s %s\n", level, buffer); 48 | } 49 | 50 | }} // namespaces 51 | -------------------------------------------------------------------------------- /library/system_error.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/system_error.hpp" 3 | 4 | #include 5 | #include 6 | 7 | namespace xiva { namespace details { 8 | 9 | inline char const* 10 | wrap_strerror(char const *buffer, char const *) { 11 | return buffer; 12 | } 13 | 14 | inline char const* 15 | wrap_strerror(int, char const *buffer) { 16 | return buffer; 17 | } 18 | 19 | system_error::system_error(char const *message) : 20 | error("%s", message) { 21 | } 22 | 23 | system_error::~system_error() throw () { 24 | } 25 | 26 | void 27 | system_error::throw_error(int error) { 28 | char buffer[256]; 29 | char const *res = wrap_strerror(strerror_r(error, buffer, sizeof(buffer)), buffer); 30 | throw system_error(res); 31 | } 32 | 33 | void 34 | system_error::throw_unless(bool condition) { 35 | if (!condition) { 36 | throw_error(errno); 37 | } 38 | } 39 | 40 | }} // namespaces 41 | -------------------------------------------------------------------------------- /library/threaded_connection.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/threaded_connection.hpp" 3 | 4 | namespace xiva { namespace details { 5 | 6 | threaded_connection::threaded_connection() { 7 | } 8 | 9 | threaded_connection::~threaded_connection() { 10 | } 11 | 12 | }} // namespaces 13 | -------------------------------------------------------------------------------- /library/url_response_handler.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "details/url_response_handler.hpp" 3 | 4 | #include 5 | 6 | #include "xiva/request.hpp" 7 | #include "xiva/response.hpp" 8 | #include "xiva/http_error.hpp" 9 | 10 | #include "details/range.hpp" 11 | #include "details/urlencode.hpp" 12 | 13 | namespace xiva { namespace details { 14 | 15 | url_response_handler::url_response_handler() 16 | { 17 | } 18 | 19 | url_response_handler::~url_response_handler() { 20 | } 21 | 22 | std::string 23 | url_response_handler::receiver(std::string const &url) const { 24 | 25 | std::string::const_iterator s = url.begin(); 26 | std::string::size_type spos = url.rfind('/'); 27 | if (std::string::npos != spos) { 28 | std::advance(s, spos + 1); 29 | } 30 | std::string::size_type qpos = url.rfind('?'); 31 | std::string::const_iterator q = url.begin(); 32 | if (std::string::npos != qpos) { 33 | std::advance(q, qpos); 34 | } 35 | else { 36 | q = url.end(); 37 | } 38 | std::string res = urldecode(make_range(s, q)); 39 | if (res.empty()) { 40 | throw http_error(http_error::not_found); 41 | } 42 | return res; 43 | } 44 | 45 | bool 46 | url_response_handler::threaded() const { 47 | return false; 48 | } 49 | 50 | bool 51 | url_response_handler::has_enough_data(request const &req) const { 52 | return "/" != req.uri(); 53 | } 54 | 55 | std::string 56 | url_response_handler::receiver(request const &req) const { 57 | return receiver(req.uri()); 58 | } 59 | 60 | void 61 | url_response_handler::handle_response(request const &req, response &resp) { 62 | (void) req; 63 | resp.content_type("text/plain"); 64 | } 65 | 66 | }} // namespaces 67 | -------------------------------------------------------------------------------- /python/Makefile.am: -------------------------------------------------------------------------------- 1 | pyexec_LTLIBRARIES = xiva.la 2 | 3 | xiva_la_SOURCES = cleanup_list.cpp \ 4 | interpreter_lock.cpp module.cpp python_formatter.cpp \ 5 | python_formatter_creator.cpp python_handler.cpp \ 6 | python_listener.cpp python_logger.cpp \ 7 | python_message_filter.cpp python_ping_formatter.cpp \ 8 | python_request.cpp python_response.cpp \ 9 | python_server.cpp python_settings.cpp 10 | 11 | xiva_la_LDFLAGS = -module -avoid-version @BOOST_LDFLAGS@ @BOOST_PYTHON_LDFLAGS@ @BOOST_THREAD_LDFLAGS@ @PYTHON_LDFLAGS@ 12 | xiva_la_LIBADD = \ 13 | ${top_srcdir}/library/libxiva.la \ 14 | ${top_srcdir}/library/libxiva-loader.la 15 | 16 | AM_CXXFLAGS = -pthread 17 | AM_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/config \ 18 | @PYTHON_CPPFLAGS@ @BOOST_CPPFLAGS@ @INCLTDL@ 19 | 20 | noinst_HEADERS = cleanup_list.hpp \ 21 | interpreter_lock.hpp python_enumeration.hpp \ 22 | python_formatter.hpp python_formatter_creator.hpp \ 23 | python_handler.hpp python_listener.hpp python_logger.hpp \ 24 | python_message_filter.hpp python_ping_formatter.hpp \ 25 | python_request.hpp python_response.hpp python_server.hpp \ 26 | python_settings.hpp request_class.hpp response_class.hpp \ 27 | server_class.hpp 28 | -------------------------------------------------------------------------------- /python/cleanup_list.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "cleanup_list.hpp" 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "interpreter_lock.hpp" 10 | 11 | namespace xiva { namespace python { 12 | 13 | cleanup_list::cleanup_list() : started_(false), stopped_(false) 14 | { 15 | } 16 | 17 | cleanup_list::~cleanup_list() { 18 | try { 19 | stop(); 20 | join_all(); 21 | } 22 | catch (std::exception const &e) { 23 | (void) e; 24 | } 25 | } 26 | 27 | void 28 | cleanup_list::start() { 29 | assert(!started_); 30 | started_ = true; 31 | boost::function f = boost::bind(&cleanup_list::thread_func, this); 32 | create_thread(f); 33 | } 34 | 35 | void 36 | cleanup_list::stop() { 37 | boost::mutex::scoped_lock lock(mutex_); 38 | stopped_ = true; 39 | condition_.notify_all(); 40 | } 41 | 42 | void 43 | cleanup_list::push_ref(boost::shared_ptr &obj_ref) { 44 | 45 | boost::shared_ptr obj; 46 | obj.swap(obj_ref); 47 | 48 | boost::mutex::scoped_lock lock(mutex_); 49 | input_.push_back(obj); 50 | condition_.notify_all(); 51 | } 52 | 53 | bool 54 | cleanup_list::acquire_destroy_list() { 55 | boost::mutex::scoped_lock lock(mutex_); 56 | while (!stopped_ && input_.empty()) { 57 | condition_.wait(lock); 58 | } 59 | if (stopped_) { 60 | return false; 61 | } 62 | to_destroy_.swap(input_); 63 | return true; 64 | } 65 | 66 | void 67 | cleanup_list::thread_func() { 68 | while (!stopped_) { 69 | try { 70 | if (!acquire_destroy_list()) { 71 | return; 72 | } 73 | 74 | interpreter_try_lock py_lock; 75 | if (stopped_ || !py_lock.acquired()) { 76 | return; 77 | } 78 | 79 | objects_type to_destroy_now; 80 | to_destroy_now.swap(to_destroy_); 81 | } 82 | catch (std::exception const &e) { 83 | (void) e; 84 | } 85 | } 86 | } 87 | 88 | 89 | cleanup_list_auto::cleanup_list_auto(cleanup_list &cleanup) : cleanup_(cleanup) { 90 | cleanup_.start(); 91 | } 92 | 93 | cleanup_list_auto::~cleanup_list_auto() { 94 | cleanup_.stop(); 95 | } 96 | 97 | 98 | }} // namespaces 99 | -------------------------------------------------------------------------------- /python/module.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | 5 | #include "server_class.hpp" 6 | #include "request_class.hpp" 7 | #include "response_class.hpp" 8 | 9 | namespace py = boost::python; 10 | 11 | namespace xiva { namespace python { 12 | 13 | BOOST_PYTHON_MODULE(xiva) { 14 | register_server_class(); 15 | register_request_class(); 16 | register_response_class(); 17 | } 18 | 19 | }} // namespaces 20 | -------------------------------------------------------------------------------- /python/python_formatter.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "python_formatter.hpp" 3 | 4 | #include 5 | 6 | #include "cleanup_list.hpp" 7 | #include "interpreter_lock.hpp" 8 | 9 | namespace xiva { namespace python { 10 | 11 | python_formatter::python_formatter(py::object const &impl, cleanup_list &cleanup) : 12 | impl_(boost::shared_ptr(new py::object(impl))), cleanup_(cleanup) 13 | { 14 | } 15 | 16 | python_formatter::~python_formatter() { 17 | cleanup_.push_ref(impl_); 18 | } 19 | 20 | std::string 21 | python_formatter::wrap_message(std::string const &content) const { 22 | 23 | try { 24 | interpreter_lock lock; 25 | return py::extract(py::call_method(impl_->ptr(), "wrap_message", content)); 26 | } 27 | catch (std::exception const &) { 28 | throw; 29 | } 30 | catch (...) { 31 | throw std::runtime_error("caught unknown exception in python_formatter::wrap_message"); 32 | } 33 | } 34 | 35 | }} // namespaces 36 | -------------------------------------------------------------------------------- /python/python_formatter.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_FORMATTER_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_FORMATTER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "xiva/forward.hpp" 27 | #include "xiva/formatter.hpp" 28 | 29 | namespace py = boost::python; 30 | 31 | namespace xiva { namespace python { 32 | 33 | class cleanup_list; 34 | 35 | class python_formatter : public xiva::formatter { 36 | 37 | public: 38 | python_formatter(py::object const &impl, cleanup_list &cleanup); 39 | virtual ~python_formatter(); 40 | 41 | virtual std::string wrap_message(std::string const &content) const; 42 | 43 | private: 44 | python_formatter(python_formatter const &); 45 | python_formatter& operator = (python_formatter const &); 46 | 47 | boost::shared_ptr impl_; 48 | cleanup_list &cleanup_; 49 | }; 50 | 51 | }} // namespaces 52 | 53 | #endif // XIVA_PYTHON_PYTHON_FORMATTER_HPP_INCLUDED 54 | -------------------------------------------------------------------------------- /python/python_formatter_creator.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "python_formatter_creator.hpp" 3 | 4 | #include 5 | 6 | #include "python_formatter.hpp" 7 | #include "python_request.hpp" 8 | #include "interpreter_lock.hpp" 9 | 10 | #include "cleanup_list.hpp" 11 | 12 | namespace xiva { namespace python { 13 | 14 | python_formatter_creator::python_formatter_creator(py::object const &impl, cleanup_list &cleanup) : 15 | impl_(boost::shared_ptr(new py::object(impl))), cleanup_(cleanup) 16 | { 17 | } 18 | 19 | python_formatter_creator::~python_formatter_creator() { 20 | cleanup_.push_ref(impl_); 21 | } 22 | 23 | std::auto_ptr 24 | python_formatter_creator::create(request const &req) const { 25 | 26 | try { 27 | python_request request_adapter(req); 28 | interpreter_lock lock; 29 | 30 | py::object formatter_impl = py::call_method(impl_->ptr(), "create", request_adapter); 31 | return std::auto_ptr(new python_formatter(formatter_impl, cleanup_)); 32 | } 33 | catch (std::exception const &) { 34 | throw; 35 | } 36 | catch (...) { 37 | throw std::runtime_error("caught unknown exception in python_formatter_creator::create"); 38 | } 39 | } 40 | 41 | }} // namespaces 42 | -------------------------------------------------------------------------------- /python/python_formatter_creator.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_FORMATTER_CREATOR_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_FORMATTER_CREATOR_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include "xiva/forward.hpp" 25 | #include "xiva/formatter.hpp" 26 | #include "xiva/formatter_creator.hpp" 27 | 28 | namespace py = boost::python; 29 | 30 | namespace xiva { namespace python { 31 | 32 | class cleanup_list; 33 | 34 | class python_formatter_creator : public xiva::formatter_creator { 35 | 36 | public: 37 | python_formatter_creator(py::object const &impl, cleanup_list &cleanup); 38 | virtual ~python_formatter_creator(); 39 | 40 | virtual std::auto_ptr create(request const &req) const; 41 | 42 | private: 43 | python_formatter_creator(python_formatter_creator const &); 44 | python_formatter_creator& operator = (python_formatter_creator const &); 45 | 46 | boost::shared_ptr impl_; 47 | cleanup_list &cleanup_; 48 | }; 49 | 50 | }} // namespaces 51 | 52 | #endif // XIVA_PYTHON_PYTHON_FORMATTER_CREATOR_HPP_INCLUDED 53 | -------------------------------------------------------------------------------- /python/python_handler.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "python_handler.hpp" 3 | 4 | #include 5 | 6 | #include "python_request.hpp" 7 | #include "python_response.hpp" 8 | #include "interpreter_lock.hpp" 9 | 10 | #include "xiva/request.hpp" 11 | 12 | namespace xiva { namespace python { 13 | 14 | python_handler::python_handler(py::object const &impl) : 15 | impl_(impl) 16 | { 17 | } 18 | 19 | python_handler::~python_handler() { 20 | } 21 | 22 | bool 23 | python_handler::threaded() const { 24 | return true; 25 | } 26 | 27 | bool 28 | python_handler::has_enough_data(request const &req) const { 29 | 30 | try { 31 | python_request request_adapter(req); 32 | interpreter_lock lock; 33 | 34 | return py::call_method(impl_.ptr(), "has_enough_data", request_adapter); 35 | } 36 | catch (std::exception const &) { 37 | throw; 38 | } 39 | catch (...) { 40 | throw std::runtime_error("caught unknown exception in python_handler::has_enough_data"); 41 | } 42 | } 43 | 44 | std::string 45 | python_handler::receiver(request const &req) const { 46 | 47 | try { 48 | python_request request_adapter(req); 49 | interpreter_lock lock; 50 | 51 | return py::call_method(impl_.ptr(), "receiver", request_adapter); 52 | } 53 | catch (std::exception const &) { 54 | throw; 55 | } 56 | catch (...) { 57 | throw std::runtime_error("caught unknown exception in python_handler::receiver"); 58 | } 59 | } 60 | 61 | void 62 | python_handler::handle_response(request const &req, response &resp) { 63 | 64 | try { 65 | python_request request_adapter(req); 66 | python_response response_adapter(resp); 67 | interpreter_lock lock; 68 | 69 | py::call_method(impl_.ptr(), "handle_response", request_adapter, response_adapter); 70 | } 71 | catch (std::exception const &) { 72 | throw; 73 | } 74 | catch (...) { 75 | throw std::runtime_error("caught unknown exception in handle_response"); 76 | } 77 | } 78 | 79 | }} // namespaces 80 | -------------------------------------------------------------------------------- /python/python_handler.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_HANDLER_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_HANDLER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/response_handler.hpp" 24 | 25 | namespace py = boost::python; 26 | 27 | namespace xiva { namespace python { 28 | 29 | class python_handler : public response_handler { 30 | 31 | public: 32 | python_handler(py::object const &impl); 33 | virtual ~python_handler(); 34 | 35 | virtual bool threaded() const; 36 | virtual bool has_enough_data(request const &req) const; 37 | 38 | virtual std::string receiver(request const &req) const; 39 | virtual void handle_response(request const &req, response &resp); 40 | 41 | private: 42 | python_handler(python_handler const &); 43 | python_handler& operator = (python_handler const &); 44 | 45 | private: 46 | py::object impl_; 47 | }; 48 | 49 | }} // namespaces 50 | 51 | #endif // XIVA_PYTHON_PYTHON_HANDLER_HPP_INCLUDED 52 | -------------------------------------------------------------------------------- /python/python_listener.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "python_listener.hpp" 3 | 4 | #include 5 | #include 6 | 7 | #include "interpreter_lock.hpp" 8 | 9 | namespace xiva { namespace python { 10 | 11 | static void 12 | throw_listener_unknown_error(char const *method, std::string const &to, globals::connection_id id) { 13 | std::string msg = "caught unknown exception in python_listener::"; 14 | msg.append(method).append(" for ").append(to); 15 | if (id) { 16 | msg.append(" ").append(boost::lexical_cast(id)); 17 | } 18 | throw std::runtime_error(msg); 19 | } 20 | 21 | python_listener::python_listener(py::object const &impl) : 22 | impl_(impl) 23 | { 24 | } 25 | 26 | python_listener::~python_listener() { 27 | } 28 | 29 | void 30 | python_listener::connection_opened(std::string const &to, globals::connection_id id) throw (std::exception) { 31 | 32 | try { 33 | interpreter_lock lock; 34 | py::call_method(impl_.ptr(), "connection_opened", to, id); 35 | } 36 | catch (std::exception const &) { 37 | throw; 38 | } 39 | catch (...) { 40 | throw_listener_unknown_error("connection_opened", to, id); 41 | } 42 | } 43 | 44 | void 45 | python_listener::connection_closed(std::string const &to, globals::connection_id id) throw (std::exception) { 46 | 47 | try { 48 | interpreter_lock lock; 49 | py::call_method(impl_.ptr(), "connection_closed", to, id); 50 | } 51 | catch (std::exception const &) { 52 | throw; 53 | } 54 | catch (...) { 55 | throw_listener_unknown_error("connection_closed", to, id); 56 | } 57 | } 58 | 59 | void 60 | python_listener::disconnected(std::string const &to) throw (std::exception) { 61 | 62 | try { 63 | interpreter_lock lock; 64 | py::call_method(impl_.ptr(), "disconnected", to); 65 | } 66 | catch (std::exception const &) { 67 | throw; 68 | } 69 | catch (...) { 70 | throw_listener_unknown_error("disconnected", to, 0); 71 | } 72 | } 73 | 74 | }} // namespaces 75 | -------------------------------------------------------------------------------- /python/python_listener.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_LISTENER_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_LISTENER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/connection_listener.hpp" 24 | 25 | namespace py = boost::python; 26 | 27 | namespace xiva { namespace python { 28 | 29 | class python_listener : public connection_listener { 30 | 31 | public: 32 | python_listener(py::object const &impl); 33 | virtual ~python_listener(); 34 | 35 | virtual void connection_opened(std::string const &to, globals::connection_id id) throw (std::exception); 36 | virtual void connection_closed(std::string const &to, globals::connection_id id) throw (std::exception); 37 | virtual void disconnected(std::string const &to) throw (std::exception); 38 | 39 | private: 40 | python_listener(python_listener const &); 41 | python_listener& operator = (python_listener const &); 42 | 43 | private: 44 | py::object impl_; 45 | }; 46 | 47 | }} // namespaces 48 | 49 | #endif // XIVA_PYTHON_PYTHON_LISTENER_HPP_INCLUDED 50 | -------------------------------------------------------------------------------- /python/python_message_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "python_message_filter.hpp" 3 | 4 | #include 5 | 6 | #include "xiva/message.hpp" 7 | #include "xiva/channel_info.hpp" 8 | 9 | #include "interpreter_lock.hpp" 10 | 11 | namespace xiva { namespace python { 12 | 13 | python_message_filter::python_message_filter(py::object const &impl) : 14 | impl_(impl) 15 | { 16 | } 17 | 18 | python_message_filter::~python_message_filter() { 19 | } 20 | 21 | bool 22 | python_message_filter::allow_message(message const &msg, std::string const &channel_data) const { 23 | 24 | channel_info const &ch_info = msg.get_channel_info(); 25 | 26 | try { 27 | interpreter_lock lock; 28 | 29 | return py::call_method(impl_.ptr(), "allow_message", 30 | ch_info.name(), ch_info.key(), ch_info.data(), channel_data); 31 | } 32 | catch (std::exception const &) { 33 | throw; 34 | } 35 | catch (...) { 36 | std::string msg = "caught unknown exception in python_message_filter::allow_message: "; 37 | msg.append(ch_info.name()).append("_").append(ch_info.key()); 38 | msg.append(" ").append(ch_info.data()).append(" ").append(channel_data); 39 | throw std::runtime_error(msg); 40 | } 41 | } 42 | 43 | }} // namespaces 44 | -------------------------------------------------------------------------------- /python/python_message_filter.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_MESSAGE_FILTER_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_MESSAGE_FILTER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/forward.hpp" 24 | #include "xiva/message_filter.hpp" 25 | 26 | namespace py = boost::python; 27 | 28 | namespace xiva { namespace python { 29 | 30 | class python_message_filter : public xiva::message_filter { 31 | 32 | public: 33 | python_message_filter(py::object const &impl); 34 | virtual ~python_message_filter(); 35 | 36 | virtual bool allow_message(message const &msg, std::string const &channel_data) const; 37 | 38 | private: 39 | python_message_filter(python_message_filter const &); 40 | python_message_filter& operator = (python_message_filter const &); 41 | 42 | py::object impl_; 43 | }; 44 | 45 | }} // namespaces 46 | 47 | #endif // XIVA_PYTHON_PYTHON_MESSAGE_FILTER_HPP_INCLUDED 48 | -------------------------------------------------------------------------------- /python/python_ping_formatter.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "python_ping_formatter.hpp" 3 | 4 | #include 5 | 6 | #include "cleanup_list.hpp" 7 | #include "interpreter_lock.hpp" 8 | 9 | namespace xiva { namespace python { 10 | 11 | python_ping_formatter::python_ping_formatter(py::object const &impl, cleanup_list &cleanup) : 12 | impl_(boost::shared_ptr(new py::object(impl))), cleanup_(cleanup) 13 | { 14 | } 15 | 16 | python_ping_formatter::~python_ping_formatter() { 17 | cleanup_.push_ref(impl_); 18 | } 19 | 20 | std::string 21 | python_ping_formatter::message() const { 22 | 23 | try { 24 | interpreter_lock lock; 25 | return py::extract(py::call_method(impl_->ptr(), "message")); 26 | } 27 | catch (std::exception const &) { 28 | throw; 29 | } 30 | catch (...) { 31 | throw std::runtime_error("caught unknown exception in python_formatter::message"); 32 | } 33 | } 34 | 35 | std::string 36 | python_ping_formatter::message_for_single() const { 37 | 38 | try { 39 | interpreter_lock lock; 40 | return py::extract(py::call_method(impl_->ptr(), "message_for_single")); 41 | } 42 | catch (std::exception const &) { 43 | throw; 44 | } 45 | catch (...) { 46 | throw std::runtime_error("caught unknown exception in python_formatter::message_for_single"); 47 | } 48 | } 49 | 50 | }} // namespaces 51 | -------------------------------------------------------------------------------- /python/python_ping_formatter.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_PING_FORMATTER_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_PING_FORMATTER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "xiva/forward.hpp" 27 | #include "xiva/ping_formatter.hpp" 28 | 29 | namespace py = boost::python; 30 | 31 | namespace xiva { namespace python { 32 | 33 | class cleanup_list; 34 | 35 | class python_ping_formatter : public xiva::ping_formatter { 36 | 37 | public: 38 | python_ping_formatter(py::object const &impl, cleanup_list &cleanup); 39 | virtual ~python_ping_formatter(); 40 | 41 | virtual std::string message() const; 42 | virtual std::string message_for_single() const; 43 | 44 | private: 45 | python_ping_formatter(python_ping_formatter const &); 46 | python_ping_formatter& operator = (python_ping_formatter const &); 47 | 48 | boost::shared_ptr impl_; 49 | cleanup_list &cleanup_; 50 | }; 51 | 52 | }} // namespaces 53 | 54 | #endif // XIVA_PYTHON_PYTHON_PING_FORMATTER_HPP_INCLUDED 55 | -------------------------------------------------------------------------------- /python/python_request.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_REQUEST_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_REQUEST_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/forward.hpp" 24 | 25 | namespace py = boost::python; 26 | 27 | namespace xiva { namespace python { 28 | 29 | class python_request { 30 | 31 | public: 32 | python_request(request const &req); 33 | virtual ~python_request(); 34 | 35 | py::str uri() const; 36 | 37 | py::str param(std::string const &name) const; 38 | bool has_param(std::string const &name) const; 39 | py::list params(std::string const &name) const; 40 | 41 | py::str header(std::string const &name) const; 42 | bool has_header(std::string const &name) const; 43 | 44 | py::str cookie(std::string const &name) const; 45 | bool has_cookie(std::string const &name) const; 46 | 47 | bool is_websocket() const; 48 | 49 | private: 50 | request const &req_; 51 | }; 52 | 53 | }} // namespaces 54 | 55 | #endif // XIVA_PYTHON_PYTHON_REQUEST_HPP_INCLUDED 56 | -------------------------------------------------------------------------------- /python/python_response.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_PYTHON_RESPONSE_HPP_INCLUDED 19 | #define XIVA_PYTHON_PYTHON_RESPONSE_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #include "xiva/forward.hpp" 24 | 25 | namespace py = boost::python; 26 | 27 | namespace xiva { namespace python { 28 | 29 | class python_response { 30 | 31 | public: 32 | python_response(response &resp); 33 | virtual ~python_response(); 34 | 35 | void content_type(std::string const &type); 36 | void single_message(bool value); 37 | void content(std::string const &body); 38 | 39 | void formatter_id(std::string const &fmt_id); 40 | void formatter_by_channel( 41 | std::string const &channel_name, std::string const &channel_key, std::string const &channel_data, 42 | std::string const &fmt_id); 43 | 44 | void set_header(std::string const &name, std::string const &value); 45 | 46 | private: 47 | response &resp_; 48 | }; 49 | 50 | }} // namespaces 51 | 52 | #endif // XIVA_PYTHON_PYTHON_RESPONSE_HPP_INCLUDED 53 | -------------------------------------------------------------------------------- /python/request_class.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_REQUEST_CLASS_HPP_INCLUDED 19 | #define XIVA_PYTHON_REQUEST_CLASS_HPP_INCLUDED 20 | 21 | namespace xiva { namespace python { 22 | 23 | void 24 | register_request_class() throw (); 25 | 26 | }} // namespaces 27 | 28 | #endif // XIVA_PYTHON_REQUEST_CLASS_HPP_INCLUDED 29 | -------------------------------------------------------------------------------- /python/response_class.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_RESPONSE_CLASS_HPP_INCLUDED 19 | #define XIVA_PYTHON_RESPONSE_CLASS_HPP_INCLUDED 20 | 21 | namespace xiva { namespace python { 22 | 23 | void 24 | register_response_class() throw (); 25 | 26 | }} // namespaces 27 | 28 | #endif // XIVA_PYTHON_RESPONSE_CLASS_HPP_INCLUDED 29 | -------------------------------------------------------------------------------- /python/server_class.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_PYTHON_SERVER_CLASS_HPP_INCLUDED 19 | #define XIVA_PYTHON_SERVER_CLASS_HPP_INCLUDED 20 | 21 | namespace xiva { namespace python { 22 | 23 | void register_server_class() throw (); 24 | 25 | }} // namespaces 26 | 27 | #endif // XIVA_PYTHON_SERVER_CLASS_HPP_INCLUDED 28 | -------------------------------------------------------------------------------- /stdext/Makefile.am: -------------------------------------------------------------------------------- 1 | pkglib_LTLIBRARIES = xiva-syslog.la xiva-stdin-reader.la 2 | 3 | xiva_syslog_la_LIBADD = ${top_srcdir}/library/libxiva.la 4 | xiva_syslog_la_SOURCES = syslog_logger.cpp 5 | xiva_syslog_la_LDFLAGS = -module 6 | 7 | xiva_stdin_reader_la_LIBADD = ${top_srcdir}/library/libxiva.la 8 | xiva_stdin_reader_la_SOURCES = stdin_reader.cpp 9 | xiva_stdin_reader_la_LDFLAGS = -module 10 | 11 | AM_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/config @BOOST_CPPFLAGS@ 12 | AM_CXXFLAGS = -pthread 13 | AM_LDFLAGS = @BOOST_LDFLAGS@ 14 | -------------------------------------------------------------------------------- /stdext/stdin_reader.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "xiva/config.hpp" 9 | #include "xiva/message.hpp" 10 | #include "xiva/component_set.hpp" 11 | #include "xiva/message_sender.hpp" 12 | #include "details/string_utils.hpp" 13 | 14 | namespace xiva { namespace standard { 15 | 16 | void 17 | process_stdin_messages(message_sender &sender) { 18 | 19 | std::string line; 20 | while (sender.active() && std::getline(std::cin, line)) { 21 | try { 22 | typedef std::string::const_iterator iterator_type; 23 | typedef boost::iterator_range range_type; 24 | 25 | iterator_type begin = line.begin(), end = line.end(); 26 | iterator_type pos = std::find(begin, end, ':'); 27 | 28 | if (end != pos) { 29 | range_type to = details::trim(range_type(begin, pos)); 30 | range_type cont = details::trim(range_type(++pos, end)); 31 | 32 | boost::shared_ptr msg(new message(cont.begin(), cont.end())); 33 | sender.send(std::string(to.begin(), to.end()), msg); 34 | } 35 | } 36 | catch (std::exception const &e) { 37 | } 38 | } 39 | } 40 | 41 | extern "C" XIVA_API void 42 | xiva_register_module(settings const &s, component_set &cs) { 43 | (void) s; 44 | boost::function f = boost::bind(process_stdin_messages, _1); 45 | cs.start_provider(1, f); 46 | } 47 | 48 | }} // namespaces 49 | -------------------------------------------------------------------------------- /stdext/syslog_logger.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include "xiva/config.hpp" 7 | #include "xiva/logger.hpp" 8 | #include "xiva/settings.hpp" 9 | #include "xiva/component_set.hpp" 10 | 11 | namespace xiva { namespace standard { 12 | 13 | class syslog_logger : public logger { 14 | 15 | public: 16 | syslog_logger(std::string const &name); 17 | virtual ~syslog_logger(); 18 | 19 | virtual void info(char const *format, ...); 20 | virtual void debug(char const *format, ...); 21 | virtual void error(char const *format, ...); 22 | 23 | private: 24 | syslog_logger(syslog_logger const &); 25 | syslog_logger& operator = (syslog_logger const &); 26 | 27 | private: 28 | std::string const name_; 29 | }; 30 | 31 | syslog_logger::syslog_logger(std::string const &name) : 32 | name_(name) 33 | { 34 | openlog(name_.c_str(), 0, LOG_DAEMON); 35 | } 36 | 37 | syslog_logger::~syslog_logger() { 38 | closelog(); 39 | } 40 | 41 | void 42 | syslog_logger::info(char const *format, ...) { 43 | va_list args; 44 | va_start(args, format); 45 | vsyslog(LOG_INFO, format, args); 46 | va_end(args); 47 | } 48 | 49 | void 50 | syslog_logger::debug(char const *format, ...) { 51 | va_list args; 52 | va_start(args, format); 53 | vsyslog(LOG_DEBUG, format, args); 54 | va_end(args); 55 | } 56 | 57 | void 58 | syslog_logger::error(char const *format, ...) { 59 | va_list args; 60 | va_start(args, format); 61 | vsyslog(LOG_ERR, format, args); 62 | va_end(args); 63 | } 64 | 65 | extern "C" XIVA_API void 66 | xiva_register_module(settings const &s, component_set &cs) { 67 | std::string logname = s.value("/xiva/logger/name"); 68 | boost::intrusive_ptr log(new syslog_logger(logname)); 69 | cs.attach_logger(log); 70 | } 71 | 72 | }} // namespaces 73 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | check_PROGRAMS = xiva-tests 2 | 3 | xiva_tests_SOURCES = main.cpp mock_connection.cpp mock_listener.cpp \ 4 | mock_logger.cpp checker_test.cpp date_test.cpp line_reader_test.cpp \ 5 | listener_test.cpp manager_test.cpp queue_test.cpp range_test.cpp \ 6 | request_test.cpp string_test.cpp urlencode_test.cpp url_handler_test.cpp 7 | 8 | xiva_tests_LDADD = \ 9 | ${top_srcdir}/library/libxiva.la \ 10 | ${top_srcdir}/library/libxiva-loader.la 11 | 12 | AM_CXXFLAGS = -pthread 13 | AM_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/config \ 14 | -I${top_srcdir}/daemon @BOOST_CPPFLAGS@ 15 | 16 | AM_LDFLAGS = @BOOST_LDFLAGS@ @BOOST_THREAD_LDFLAGS@ @BOOST_UNIT_TEST_LDFLAGS@ 17 | 18 | if HAVE_DAEMON 19 | AM_LDFLAGS += @XML_LIBS@ 20 | AM_CPPFLAGS += @XML_CPPFLAGS@ 21 | xiva_tests_SOURCES += settings_test.cpp 22 | xiva_tests_LDADD += ${top_srcdir}/daemon/libxiva-daemon.la 23 | endif 24 | 25 | noinst_DATA = test.conf 26 | 27 | noinst_HEADERS = mock_connection.hpp mock_listener.hpp mock_logger.hpp \ 28 | test_utils.hpp 29 | 30 | TESTS = xiva-tests 31 | -------------------------------------------------------------------------------- /tests/date_test.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "details/http.hpp" 9 | 10 | namespace xiva { namespace tests { 11 | 12 | using namespace details; 13 | 14 | BOOST_AUTO_TEST_SUITE(date_test) 15 | 16 | BOOST_AUTO_TEST_CASE(test_format) { 17 | 18 | std::stringstream stream; 19 | boost::posix_time::ptime now = boost::posix_time::from_time_t(static_cast(1170416178)); 20 | 21 | stream << http_date(now); 22 | BOOST_CHECK_EQUAL("Date: Fri, 02 Feb 2007 11:36:18 GMT\r\n", stream.str()); 23 | } 24 | 25 | BOOST_AUTO_TEST_SUITE_END() 26 | 27 | }} // namespaces 28 | -------------------------------------------------------------------------------- /tests/line_reader_test.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "test_utils.hpp" 13 | #include "details/range.hpp" 14 | #include "details/line_reader.hpp" 15 | 16 | namespace xiva { namespace tests { 17 | 18 | using namespace details; 19 | 20 | typedef boost::mpl::list, std::list, 21 | range, std::string> line_reader_test_types; 22 | 23 | BOOST_AUTO_TEST_SUITE(line_reader_test) 24 | 25 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_read_lines, Range, line_reader_test_types) { 26 | 27 | char const* values[] = { "123", "456", "789", "12", "345" }; 28 | char const* end_lines[] = { "\n\r", "\r\n", "\r\n\r\n", "\n", "" }; 29 | 30 | Range const value = as("123\n\r456\r\n789\r\n\r\n12\n345"); 31 | typedef typename Range::const_iterator iterator_type; 32 | 33 | range result, end_line; 34 | line_reader reader(value.begin(), value.end()); 35 | 36 | for (std::size_t i = 0; reader.read_line(result, end_line); ++i) { 37 | BOOST_CHECK_EQUAL(values[i], make_string(result)); 38 | BOOST_CHECK_EQUAL(end_lines[i], make_string(end_line)); 39 | } 40 | } 41 | 42 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_read_spaces, Range, line_reader_test_types) { 43 | 44 | 45 | char const* values[] = { "123\n 123\n\t123\n 123", "456", "789" }; 46 | 47 | Range const value = as("123\n 123\n\t123\n 123\n456\n789"); 48 | typedef typename Range::const_iterator iterator_type; 49 | 50 | range result, end_line; 51 | line_reader reader(value.begin(), value.end()); 52 | 53 | for (std::size_t i = 0; reader.read_line(result, end_line); ++i) { 54 | BOOST_CHECK_EQUAL(values[i], make_string(result)); 55 | } 56 | } 57 | 58 | BOOST_AUTO_TEST_SUITE_END() 59 | 60 | }} // namespaces 61 | -------------------------------------------------------------------------------- /tests/listener_test.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "mock_logger.hpp" 8 | #include "mock_listener.hpp" 9 | 10 | #include "xiva/error.hpp" 11 | #include "details/compound_listener.hpp" 12 | 13 | 14 | namespace xiva { namespace tests { 15 | 16 | using namespace details; 17 | 18 | BOOST_AUTO_TEST_SUITE(listener_test) 19 | 20 | BOOST_AUTO_TEST_CASE(test_listener) { 21 | 22 | compound_listener compound; 23 | compound.attach_logger(boost::intrusive_ptr(new mock_logger())); 24 | typedef boost::intrusive_ptr listener_ptr_type; 25 | 26 | std::vector listeners; 27 | for (std::size_t i = 0; i < 100; ++i) { 28 | listener_ptr_type l(new mock_listener()); 29 | compound.add_connection_listener(l); 30 | listeners.push_back(l); 31 | } 32 | compound.connection_opened("swan", 1); 33 | compound.connection_opened("highpower", 2); 34 | compound.connection_opened("compwolf", 3); 35 | 36 | for (std::vector::const_iterator i = listeners.begin(), end = listeners.end(); i != end; ++i) { 37 | BOOST_CHECK_EQUAL(true, (*i)->available("swan")); 38 | BOOST_CHECK_EQUAL(true, (*i)->available("highpower")); 39 | BOOST_CHECK_EQUAL(true, (*i)->available("compwolf")); 40 | BOOST_CHECK_EQUAL(false, (*i)->available("bobuk")); 41 | } 42 | compound.connection_closed("highpower", 2); 43 | for (std::vector::const_iterator i = listeners.begin(), end = listeners.end(); i != end; ++i) { 44 | BOOST_CHECK_EQUAL(false, (*i)->available("highpower")); 45 | BOOST_CHECK_EQUAL(true, (*i)->available("swan")); 46 | } 47 | BOOST_CHECK_THROW(listeners[0]->connection_closed("highpower", 2), xiva::error); 48 | BOOST_CHECK_THROW(listeners[0]->connection_closed("highpower", 3), xiva::error); 49 | BOOST_CHECK_THROW(listeners[0]->connection_closed("swan", 2), xiva::error); 50 | 51 | compound.connection_closed("highpower", 2); 52 | compound.connection_closed("highpower", 3); 53 | compound.connection_closed("swan", 2); 54 | } 55 | 56 | BOOST_AUTO_TEST_SUITE_END() 57 | 58 | }} // namespaces 59 | -------------------------------------------------------------------------------- /tests/main.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #define BOOST_TEST_DYN_LINK 4 | #define BOOST_TEST_MODULE xiva 5 | 6 | #include 7 | 8 | -------------------------------------------------------------------------------- /tests/mock_connection.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "mock_connection.hpp" 3 | 4 | namespace xiva { namespace tests { 5 | 6 | mock_connection::mock_connection(std::string const &to) : 7 | connection(), finished_(false), message_count_(0) 8 | { 9 | name(to); 10 | } 11 | 12 | mock_connection::~mock_connection() { 13 | } 14 | 15 | bool 16 | mock_connection::finished() const { 17 | return finished_; 18 | } 19 | 20 | std::size_t 21 | mock_connection::message_count() const { 22 | return message_count_; 23 | } 24 | 25 | void 26 | mock_connection::close() { 27 | } 28 | 29 | void 30 | mock_connection::finish() { 31 | finished_ = true; 32 | } 33 | 34 | void 35 | mock_connection::send(boost::shared_ptr const &m) { 36 | (void) m; 37 | ++message_count_; 38 | } 39 | 40 | void 41 | mock_connection::handled(details::request_impl const &req, details::response_impl const &resp) { 42 | (void) req; 43 | (void) resp; 44 | } 45 | 46 | void 47 | mock_connection::handled_errors( 48 | details::request_impl const &req, details::response_impl const &resp, 49 | unsigned short http_code, std::string const &error_msg) { 50 | 51 | (void) req; 52 | (void) resp; 53 | (void) http_code; 54 | (void) error_msg; 55 | } 56 | 57 | 58 | }} // namespaces 59 | -------------------------------------------------------------------------------- /tests/mock_connection.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_TESTS_MOCK_CONNECTION_HPP_INCLUDED 19 | #define XIVA_TESTS_MOCK_CONNECTION_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | 24 | #include "details/connection.hpp" 25 | 26 | namespace xiva { namespace tests { 27 | 28 | class mock_connection : public details::connection { 29 | 30 | public: 31 | mock_connection(std::string const &to); 32 | virtual ~mock_connection(); 33 | 34 | bool finished() const; 35 | std::size_t message_count() const; 36 | 37 | virtual void close(); 38 | virtual void finish(); 39 | virtual void send(boost::shared_ptr const &m); 40 | virtual void handled(details::request_impl const &req, details::response_impl const &resp); 41 | virtual void handled_errors( 42 | details::request_impl const &req, details::response_impl const &resp, 43 | unsigned short http_code, std::string const &error_msg); 44 | 45 | 46 | private: 47 | mock_connection(mock_connection const &); 48 | mock_connection& operator = (mock_connection const &); 49 | 50 | private: 51 | bool finished_; 52 | std::size_t message_count_; 53 | }; 54 | 55 | }} // namespaces 56 | 57 | #endif // XIVA_TESTS_MOCK_CONNECTION_HPP_INCLUDED 58 | -------------------------------------------------------------------------------- /tests/mock_listener.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "mock_listener.hpp" 3 | 4 | #include 5 | #include 6 | 7 | #include "xiva/error.hpp" 8 | 9 | namespace xiva { namespace tests { 10 | 11 | mock_listener::mock_listener() { 12 | } 13 | 14 | mock_listener::~mock_listener() { 15 | } 16 | 17 | bool 18 | mock_listener::available(std::string const &to) const { 19 | return available_.find(to) != available_.end(); 20 | } 21 | 22 | void 23 | mock_listener::connection_opened(std::string const &to, globals::connection_id id) throw (std::exception) { 24 | std::map::iterator i = available_.find(to); 25 | if (available_.end() == i) { 26 | connection_ids ids; 27 | ids.insert(id); 28 | ids.swap(available_[to]); 29 | } 30 | else { 31 | connection_ids &ids = i->second; 32 | ids.insert(id); 33 | } 34 | } 35 | 36 | void 37 | mock_listener::connection_closed(std::string const &to, globals::connection_id id) throw (std::exception) { 38 | std::map::iterator i = available_.find(to); 39 | if (available_.end() == i) { 40 | throw error("empty container, failed to close inexistent connection to %s, id %s", 41 | to.c_str(), boost::lexical_cast(id).c_str()); 42 | } 43 | connection_ids &ids = i->second; 44 | connection_ids::iterator it = ids.find(id); 45 | if (ids.end() == it) { 46 | throw error("non-empty container, failed to close inexistent connection to %s, id %s", 47 | to.c_str(), boost::lexical_cast(id).c_str()); 48 | } 49 | ids.erase(it); 50 | if (ids.empty()) { 51 | available_.erase(i); 52 | } 53 | } 54 | 55 | void 56 | mock_listener::disconnected(std::string const &to) throw (std::exception) { 57 | (void) to; 58 | throw error("disconnected"); 59 | } 60 | 61 | }} // namespaces 62 | -------------------------------------------------------------------------------- /tests/mock_listener.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_TESTS_MOCK_LISTENER_HPP_INCLUDED 19 | #define XIVA_TESTS_MOCK_LISTENER_HPP_INCLUDED 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "xiva/globals.hpp" 27 | #include "xiva/connection_listener.hpp" 28 | 29 | namespace xiva { namespace tests { 30 | 31 | class mock_listener : public connection_listener { 32 | 33 | public: 34 | mock_listener(); 35 | virtual ~mock_listener(); 36 | 37 | bool available(std::string const &user) const; 38 | virtual void connection_opened(std::string const &to, globals::connection_id id) throw (std::exception); 39 | virtual void connection_closed(std::string const &to, globals::connection_id id) throw (std::exception); 40 | virtual void disconnected(std::string const &to) throw (std::exception); 41 | 42 | private: 43 | mock_listener(mock_listener const &); 44 | mock_listener& operator = (mock_listener const &); 45 | 46 | private: 47 | typedef std::set connection_ids; 48 | std::map available_; 49 | }; 50 | 51 | }} // namespaces 52 | 53 | #endif // XIVA_TESTS_MOCK_LISTENER_HPP_INCLUDED 54 | -------------------------------------------------------------------------------- /tests/mock_logger.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | #include "mock_logger.hpp" 3 | 4 | namespace xiva { namespace tests { 5 | 6 | mock_logger::mock_logger() { 7 | } 8 | 9 | mock_logger::~mock_logger() { 10 | } 11 | 12 | void 13 | mock_logger::info(char const *format, ...) { 14 | (void) format; 15 | } 16 | 17 | void 18 | mock_logger::debug(char const *format, ...) { 19 | (void) format; 20 | } 21 | 22 | void 23 | mock_logger::error(char const *format, ...) { 24 | (void) format; 25 | } 26 | 27 | }} // namespaces 28 | -------------------------------------------------------------------------------- /tests/mock_logger.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_TESTS_MOCK_LOGGER_HPP_INCLUDED 19 | #define XIVA_TESTS_MOCK_LOGGER_HPP_INCLUDED 20 | 21 | #include "xiva/logger.hpp" 22 | 23 | namespace xiva { namespace tests { 24 | 25 | class mock_logger : public logger { 26 | 27 | public: 28 | mock_logger(); 29 | virtual ~mock_logger(); 30 | 31 | virtual void info(char const *format, ...); 32 | virtual void debug(char const *format, ...); 33 | virtual void error(char const *format, ...); 34 | 35 | private: 36 | mock_logger(mock_logger const &); 37 | mock_logger& operator = (mock_logger const &); 38 | }; 39 | 40 | }} // namespaces 41 | 42 | #endif // XIVA_TESTS_MOCK_LOGGER_HPP_INCLUDED 43 | -------------------------------------------------------------------------------- /tests/queue_test.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "details/threaded_queue.hpp" 10 | 11 | namespace xiva { namespace tests { 12 | 13 | using namespace details; 14 | 15 | BOOST_AUTO_TEST_SUITE(queue_test) 16 | 17 | void 18 | queue_thread_push_func(threaded_queue &queue) { 19 | for (std::size_t i = 0; i < 100; ++i) { 20 | queue.push(i); 21 | } 22 | queue.finish(); 23 | } 24 | 25 | BOOST_AUTO_TEST_CASE(test_queue_push) { 26 | 27 | threaded_queue queue; 28 | boost::function f = boost::bind(&queue_thread_push_func, boost::ref(queue)); 29 | boost::thread thread(f); 30 | 31 | std::size_t item = 0; 32 | for (std::size_t i = 0; queue.pop(item); ++i) { 33 | BOOST_CHECK_EQUAL(i, item); 34 | } 35 | thread.join(); 36 | } 37 | 38 | BOOST_AUTO_TEST_SUITE_END() 39 | 40 | }} // namespaces 41 | -------------------------------------------------------------------------------- /tests/range_test.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "test_utils.hpp" 14 | #include "details/range.hpp" 15 | 16 | namespace xiva { namespace tests { 17 | 18 | using namespace details; 19 | 20 | typedef boost::mpl::list, std::list, 21 | details::range, std::string> range_test_types; 22 | 23 | BOOST_AUTO_TEST_SUITE(string_test) 24 | 25 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_construct, Range, range_test_types) { 26 | 27 | typedef range test_range; 28 | 29 | test_range tr; 30 | BOOST_CHECK_EQUAL(true, tr.empty()); 31 | BOOST_CHECK_EQUAL(0, tr.size()); 32 | 33 | Range r = as("12345"); 34 | test_range other = make_range(r); 35 | 36 | BOOST_CHECK_EQUAL(false, other.empty()); 37 | BOOST_CHECK_EQUAL(5, other.size()); 38 | } 39 | 40 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_comparision, Range, range_test_types) { 41 | 42 | Range r = as("test string"); 43 | range pattern = make_range("test string"); 44 | range result = make_range(r); 45 | 46 | BOOST_CHECK_EQUAL(true, result == pattern); 47 | BOOST_CHECK_EQUAL(true, result <= pattern); 48 | BOOST_CHECK_EQUAL(true, result >= pattern); 49 | BOOST_CHECK_EQUAL(false, result != pattern); 50 | } 51 | 52 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_reversed_comparision, Range, range_test_types) { 53 | 54 | Range r = as("test string"); 55 | range source = make_range("test string"); 56 | range result(r.rbegin(), r.rend()); 57 | range::const_reverse_iterator> pattern(source.rbegin(), source.rend()); 58 | 59 | BOOST_CHECK_EQUAL(true, result == pattern); 60 | BOOST_CHECK_EQUAL(true, result <= pattern); 61 | BOOST_CHECK_EQUAL(true, result >= pattern); 62 | BOOST_CHECK_EQUAL(false, result != pattern); 63 | } 64 | 65 | BOOST_AUTO_TEST_SUITE_END() 66 | 67 | }} // namespaces 68 | -------------------------------------------------------------------------------- /tests/settings_test.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include "xml_settings.hpp" 7 | 8 | namespace xiva { namespace tests { 9 | 10 | BOOST_AUTO_TEST_SUITE(settings_test) 11 | 12 | BOOST_AUTO_TEST_CASE(test_value) { 13 | 14 | daemon::xml_settings set("test.conf"); 15 | BOOST_CHECK_EQUAL(10, set.as("/" XIVA_PACKAGE_NAME "/endpoint/backlog")); 16 | BOOST_CHECK_EQUAL("/tmp/" XIVA_PACKAGE_NAME "-1.sock", set.as("/" XIVA_PACKAGE_NAME "/endpoint/socket")); 17 | } 18 | 19 | BOOST_AUTO_TEST_CASE(test_enumeration) { 20 | 21 | daemon::xml_settings set("test.conf"); 22 | enumeration::ptr_type en = set.value_list("/" XIVA_PACKAGE_NAME "/proxy-deny/url"); 23 | for (std::size_t i = 1; !en->empty(); ++i) { 24 | std::ostringstream stream; 25 | stream << "http://127.0.0.1/" << i << ".html"; 26 | BOOST_CHECK_EQUAL(stream.str(), en->next()); 27 | } 28 | } 29 | 30 | BOOST_AUTO_TEST_SUITE_END(); 31 | 32 | }} // namespaces 33 | -------------------------------------------------------------------------------- /tests/test.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | 6 | daemon-logger 7 | DEBUG 8 | xiva-${id} 9 | 10 | 10 11 | /tmp/xiva-${id}.sock 12 | 13 | /var/run/xiva-${id}.pid 14 | 15 | http://127.0.0.1/1.html 16 | http://127.0.0.1/2.html 17 | http://127.0.0.1/3.html 18 | http://127.0.0.1/4.html 19 | http://127.0.0.1/5.html 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/test_utils.hpp: -------------------------------------------------------------------------------- 1 | // xiva (acronym for HTTP Extended EVent Automata) is a simple HTTP server. 2 | // Copyright (C) 2009 Yandex 3 | 4 | // This program is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU General Public License 6 | // as published by the Free Software Foundation; either version 2 7 | // of the License, or (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | 18 | #ifndef XIVA_TESTS_TEST_UTILS_HPP_INCLUDED 19 | #define XIVA_TESTS_TEST_UTILS_HPP_INCLUDED 20 | 21 | namespace xiva { namespace tests { 22 | 23 | template inline Range 24 | as(char const *str) { 25 | return Range(str, str + std::char_traits::length(str)); 26 | } 27 | 28 | template inline std::string 29 | make_string(Range const &range) { 30 | return std::string(range.begin(), range.end()); 31 | } 32 | 33 | template <> inline std::string 34 | make_string(std::string const &str) { 35 | return str; 36 | } 37 | 38 | }} // namespaces 39 | 40 | #endif // XIVA_TESTS_TEST_UTILS_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /tests/url_handler_test.cpp: -------------------------------------------------------------------------------- 1 | #include "acsetup.hpp" 2 | 3 | #include 4 | 5 | #include "xiva/http_error.hpp" 6 | #include "details/url_response_handler.hpp" 7 | 8 | namespace xiva { namespace tests { 9 | 10 | bool 11 | is_right_http_code(http_error const &http) { 12 | return http.code() == http_error::not_found; 13 | } 14 | 15 | BOOST_AUTO_TEST_SUITE(matcher_test) 16 | 17 | BOOST_AUTO_TEST_CASE(test_matcher) { 18 | 19 | using namespace details; 20 | url_response_handler handler; 21 | 22 | BOOST_CHECK_EQUAL("swan", handler.receiver("/swan")); 23 | BOOST_CHECK_EQUAL("swan", handler.receiver("/swan?id=123")); 24 | BOOST_CHECK_EQUAL("swan swan", handler.receiver("/swan%20swan")); 25 | BOOST_CHECK_EXCEPTION(handler.receiver(""), http_error, is_right_http_code); 26 | BOOST_CHECK_EXCEPTION(handler.receiver("/swan/"), http_error, is_right_http_code); 27 | 28 | } 29 | 30 | BOOST_AUTO_TEST_SUITE_END() 31 | 32 | }} // namespaces 33 | -------------------------------------------------------------------------------- /tests/urlencode_test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/highpower/xiva/0b89a8c26d577cf6c9e42ceddbf90b712eba4a6a/tests/urlencode_test.cpp -------------------------------------------------------------------------------- /utils/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = xiva-util 2 | 3 | xiva_util_SOURCES = main.cpp 4 | xiva_util_LDFLAGS = @BOOST_THREAD_LDFLAGS@ @BOOST_SYSTEM_LDFLAGS@ 5 | 6 | AM_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/config @BOOST_CPPFLAGS@ 7 | AM_CXXFLAGS = -pthread 8 | AM_LDFLAGS = @BOOST_LDFLAGS@ 9 | --------------------------------------------------------------------------------