]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5134] Basic example library added.
authorTomek Mrugalski <tomasz@isc.org>
Thu, 16 Feb 2017 01:15:13 +0000 (02:15 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 17 Feb 2017 13:06:49 +0000 (14:06 +0100)
src/bin/agent/simple_parser.cc
src/bin/agent/tests/Makefile.am
src/bin/agent/tests/basic_library.cc [new file with mode: 0644]

index 9363530aeee981bd2ba643c0c80c3281df1d0bed..de2ed66809d139ebf8994466c71a2e5c2574981a 100644 (file)
@@ -111,6 +111,10 @@ AgentSimpleParser::parse(CtrlAgentCfgContextPtr ctx, isc::data::ConstElementPtr
     if (hooks) {
         hooks_parser.parse(hooks);
         hooks_parser.verifyLibraries();
+
+        hooks::HookLibsCollection libs;
+        hooks_parser.getLibraries(libs);
+        ctx->setLibraries(libs);
     }
 
     if (!check_only) {
index 64695e4d0f42575dcab858073606a9d8dc896ce6..56397b053a3b5ccfa4a27b5462d6a6788af48031 100644 (file)
@@ -5,6 +5,8 @@ SHTESTS += ctrl_agent_process_tests.sh
 
 noinst_SCRIPTS = ctrl_agent_process_tests.sh
 
+noinst_LTLIBRARIES = libbasic.la
+
 EXTRA_DIST  = ctrl_agent_process_tests.sh.in
 
 # test using command-line arguments, so use check-local target instead of TESTS
@@ -74,6 +76,16 @@ ctrl_agent_unittest_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exception
 ctrl_agent_unittest_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS)
 ctrl_agent_unittest_LDADD += $(BOOST_LIBS) $(GTEST_LDADD)
 
+
+# The basic callout library - contains standard callouts
+libbasic_la_SOURCES  = basic_library.cc
+libbasic_la_CXXFLAGS = $(AM_CXXFLAGS)
+libbasic_la_CPPFLAGS = $(AM_CPPFLAGS)
+libbasic_la_LIBADD   = $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+libbasic_la_LIBADD  += $(top_builddir)/src/lib/hooks/libkea-hooks.la
+libbasic_la_LIBADD  += $(top_builddir)/src/lib/log/libkea-log.la
+libbasic_la_LDFLAGS  = -avoid-version -export-dynamic -module -rpath /nowhere
+
 endif
 
 noinst_PROGRAMS = $(TESTS)
diff --git a/src/bin/agent/tests/basic_library.cc b/src/bin/agent/tests/basic_library.cc
new file mode 100644 (file)
index 0000000..f3a44f8
--- /dev/null
@@ -0,0 +1,73 @@
+// Copyright (C) 2017 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/.
+
+/// @file
+/// @brief Basic callout library
+///
+/// This is source of a test library for Control Agent.
+///
+/// - Only the "version" framework function is supplied.
+///
+/// - hookpt_one callout is supplied.
+
+#include <config.h>
+#include <hooks/hooks.h>
+#include <fstream>
+
+using namespace isc::hooks;
+using namespace std;
+
+namespace {
+
+extern "C" {
+
+// Callouts.  All return their result through the "result" argument.
+
+int
+context_create(CalloutHandle& handle) {
+    handle.setContext("result", static_cast<int>(10));
+    handle.setArgument("result", static_cast<int>(10));
+    return (0);
+}
+
+// First callout adds the passed "integer" argument to the initialized context
+// value of 10. (Note that the value set by context_create is accessed through
+// context and not the argument, so checking that context is correctly passed
+// between callouts in the same library.)
+
+int
+hookpt_one(CalloutHandle& handle) {
+    int data;
+    handle.getArgument("integer", data);
+
+    int result;
+    handle.getArgument("result", result);
+
+    result += data;
+    handle.setArgument("result", result);
+
+    return (0);
+}
+
+// Framework functions.
+
+int
+version() {
+    return (KEA_HOOKS_VERSION);
+}
+
+// load() initializes the user library if the main image was statically linked.
+int
+load(isc::hooks::LibraryHandle&) {
+#ifdef USE_STATIC_LINK
+    hooksStaticLinkInit();
+#endif
+    return (0);
+}
+
+}
+}
+