Commit 17398faf authored by Francis Dupont's avatar Francis Dupont

[fd-nghttp2-rbac] Checkpoint with asio-sv2.cc as sample

parent 88fa7fe8
......@@ -1568,6 +1568,32 @@ AC_TRY_LINK(
AM_CONDITIONAL(HAVE_OPTRESET, test "x$var_optreset_exists" != "xno")
AM_COND_IF([HAVE_OPTRESET], [AC_DEFINE([HAVE_OPTRESET], [1], [Check for optreset?])])
AC_ARG_WITH([nghttp2],
AC_HELP_STRING([--with-nghttp2=PATH],
[specify exact directory of nghttp2_asio library and headers]),
[nghttp2_path="$withval"])
if test "${nghttp2_path}" = "yes" ; then
for d in $defaultdirs; do
if test -f $d/include/nghttp2/nghttp2.h ; then
NGHTTP2_INCLUDES="-I$d/include"
NGHTTP2_LIBS="-L$d/lib"
if test -d $d/lib64 ; then
NGHTTP2_LIBS="$NGHTTP2_LIBS -L$d/lib64"
fi
break
fi
done
elif test "${nghttp2_path}" != "no" ; then
NGHTTP2_INCLUDES="-I${nghttp2_path}/include"
NGHTTP2_LIBS="-L${nghttp2_path}/lib"
fi
if test "X$NGHTTP2_LIBS" != "X" ; then
NGHTTP2_LIBS="$NGHTTP2_LIBS -lnghttp2_asio"
fi
AC_SUBST(NGHTTP2_INCLUDES)
AC_SUBST(NGHTTP2_LIBS)
AC_DEFINE([CONFIG_H_WAS_INCLUDED], [1], [config.h inclusion marker])
# Autoconf 2.70 has runstatedir but is not yet released.
......@@ -1637,6 +1663,8 @@ AC_CONFIG_FILES([Makefile
src/bin/netconf/tests/shtests/netconf_tests.sh
src/bin/netconf/tests/test_data_files_config.h
src/bin/netconf/tests/test_libraries.h
src/bin/ngrv/Makefile
src/bin/ngrv/tests/Makefile
src/bin/perfdhcp/Makefile
src/bin/perfdhcp/tests/Makefile
src/bin/perfdhcp/tests/testdata/Makefile
......
......@@ -10,7 +10,7 @@ SUBDIRS += shell
endif
if REVERSE_PROXY
SUBDIRS += secure_shell reverse_proxy
SUBDIRS += secure_shell reverse_proxy ngrv
endif
if HAVE_SYSREPO
......
/kea-ngrv
/ngrv_parser.report
SUBDIRS = . #tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
AM_CPPFLAGS += $(BOOST_INCLUDES) $(CRYPTO_CFLAGS) $(CRYPTO_INCLUDES)
AM_CPPFLAGS += $(NGHTTP2_INCLUDES)
AM_CXXFLAGS = $(KEA_CXXFLAGS)
if USE_STATIC_LINK
AM_LDFLAGS = -static
endif
CLEANFILES = *.gcno *.gcda
# convenience archive
noinst_LTLIBRARIES = libngrv.la
libngrv_la_SOURCES =
#EXTRA_DIST = ngrv_messages.mes
#EXTRA_DIST += ngrv_lexer.ll
#EXTRA_DIST += ngrv_parser.yy
sbin_PROGRAMS = kea-ngrv
kea_ngrv_SOURCES = ngrv.cc
kea_ngrv_LDADD = #libngrv.la
kea_ngrv_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
kea_ngrv_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
kea_ngrv_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
kea_ngrv_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
kea_ngrv_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
kea_ngrv_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
kea_ngrv_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
kea_ngrv_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS) $(BOOST_LIBS) $(NGHTTP2_LIBS)
kea_ngrv_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS)
# If we want to get rid of all generated messages files, we need to use
# make maintainer-clean. The proper way to introduce custom commands for
# that operation is to define maintainer-clean-local target. However,
# make maintainer-clean also removes Makefile, so running configure script
# is required. To make it easy to rebuild messages without going through
# reconfigure, a new target messages-clean has been added.
maintainer-clean-local:
rm -f ngrv_messages.h ngrv_messages.cc
# To regenerate messages files, one can do:
#
# make messages-clean
# make messages
#
# This is needed only when a .mes file is modified.
messages-clean: maintainer-clean-local
if GENERATE_MESSAGES
# Define rule to build logging source files from message file
messages: ngrv_messages.h ngrv_messages.cc
@echo Message files regenerated
ngrv_messages.h ngrv_messages.cc: ngrv_messages.mes
$(top_builddir)/src/lib/log/compiler/kea-msg-compiler $(top_srcdir)/src/bin/ngrv/ngrv_messages.mes
else
messages ngrv_messages.h ngrv_messages.cc:
@echo Messages generation disabled. Configure with --enable-generate-messages to enable it.
endif
if GENERATE_PARSER
parser: ngrv_lexer.cc location.hh position.hh stack.hh ngrv_parser.cc ngrv_parser.h
@echo "Flex/bison files regenerated"
# --- Flex/Bison stuff below --------------------------------------------------
# When debugging grammar issues, it's useful to add -v to bison parameters.
# bison will generate parser.output file that explains the whole grammar.
# It can be used to manually follow what's going on in the parser.
# This is especially useful if yydebug_ is set to 1 as that variable
# will cause parser to print out its internal state.
# Call flex with -s to check that the default rule can be suppressed
# Call bison with -W to get warnings like unmarked empty rules
# Note C++11 deprecated register still used by flex < 2.6.0
location.hh position.hh stack.hh ngrv_parser.cc ngrv_parser.h: ngrv_parser.yy
$(YACC) --defines=ngrv_parser.h --report=all --report-file=ngrv_parser.report -o ngrv_parser.cc ngrv_parser.yy
ngrv_lexer.cc: ngrv_lexer.ll
$(LEX) --prefix ngrv_ -o ngrv_lexer.cc ngrv_lexer.ll
else
parser location.hh position.hh stack.hh ngrv_parser.cc ngrv_parser.h ngrv_lexer.cc:
@echo Parser generation disabled. Configure with --enable-generate-parser to enable it.
endif
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <nghttp2/asio_http2_server.h>
using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server;
int main(int argc, char *argv[]) {
try {
// Check command line arguments.
if (argc < 3) {
std::cerr << "Usage: ngrv <address> <port>"
<< "[<private-key-file> <cert-file>]\n";
return 1;
}
boost::system::error_code ec;
std::string addr = argv[1];
std::string port = argv[2];
std::string docroot = "/tmp";
http2 server;
server.handle("/", [&docroot](const request &req, const response &res) {
std::cerr << "received request" << std::endl;
std::cerr << " method: " << req.method() << std::endl;
auto uri = req.uri();
std::cerr << " uri: " << uri.scheme << "://" << uri.host << uri.path << std::endl;
std::cerr << " #headers: " << req.header().size() << std::endl;
for (auto h : req.header()) {
std::cerr << " (header): " << h.first
<< " = " << h.second.value << std::endl;
}
auto path = percent_decode(req.uri().path);
if (!check_path(path)) {
res.write_head(404);
res.end();
return;
}
auto header = header_map();
path = docroot + path;
auto fd = open(path.c_str(), O_RDONLY);
if (fd == -1) {
res.write_head(404);
res.end();
return;
}
struct stat stbuf;
if (stat(path.c_str(), &stbuf) == 0) {
header.emplace("content-length",
header_value{std::to_string(stbuf.st_size)});
header.emplace("last-modified",
header_value{http_date(stbuf.st_mtime)});
}
res.write_head(200, std::move(header));
res.end(file_generator_from_fd(fd));
});
if (argc >= 5) {
boost::asio::ssl::context tls(boost::asio::ssl::context::sslv23);
tls.use_private_key_file(argv[3], boost::asio::ssl::context::pem);
tls.use_certificate_chain_file(argv[4]);
configure_tls_context_easy(ec, tls);
if (server.listen_and_serve(ec, tls, addr, port)) {
std::cerr << "error: " << ec.message() << std::endl;
}
} else {
if (server.listen_and_serve(ec, addr, port)) {
std::cerr << "error: " << ec.message() << std::endl;
}
}
} catch (std::exception &e) {
std::cerr << "exception: " << e.what() << "\n";
}
return 0;
}
/ngrv_tests.sh
ngrv_unittests
SUBDIRS = .
#EXTRA_DIST = testdata/get_config.json
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_builddir)/src
AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/bin/ngrv/tests\"
AM_CPPFLAGS += -DCFG_EXAMPLES=\"$(abs_top_srcdir)/doc/examples/ngrv\"
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/bin/ngrv/tests\"
AM_CPPFLAGS += -DSYNTAX_FILE=\"$(srcdir)/../ngrv_parser.yy\"
AM_CPPFLAGS += $(BOOST_INCLUDES) $(NGHTTP2_INCLUDES)
CLEANFILES = *.json *.log
AM_CXXFLAGS = $(KEA_CXXFLAGS)
if USE_STATIC_LINK
AM_LDFLAGS = -static
endif
TESTS_ENVIRONMENT = \
$(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
TESTS =
if HAVE_GTEST
TESTS += ngrv_unittests
ngrv_unittests_SOURCES =
ngrv_unittests_SOURCES += run_unittests.cc
ngrv_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
ngrv_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS)
ngrv_unittests_LDADD = $(top_builddir)/src/bin/ngrv/libngrv.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/process/testutils/libprocesstest.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
ngrv_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
ngrv_unittests_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS)
ngrv_unittests_LDADD += $(BOOST_LIBS) $(GTEST_LDADD) $(NGHTTP2_LIBS)
endif
#noinst_EXTRA_DIST = configs-list.txt
noinst_PROGRAMS = $(TESTS)
// Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <gtest/gtest.h>
#include <util/unittests/run_all.h>
#include <log/logger_support.h>
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
// See the documentation of the KEA_* environment variables in
// the developer's guide for info on how to tweak logging
isc::log::initLogger();
// Override --localstatedir value for PID files
setenv("KEA_PIDFILE_DIR", TEST_DATA_BUILDDIR, 1);
int result = RUN_ALL_TESTS();
return (result);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment