]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[333-parser-libraries-for-servers] Added libraries and parser* tools
authorFrancis Dupont <fdupont@isc.org>
Sat, 5 Jan 2019 13:33:23 +0000 (14:33 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sat, 5 Jan 2019 13:33:23 +0000 (14:33 +0100)
26 files changed:
configure.ac
src/bin/agent/Makefile.am
src/bin/agent/tests/Makefile.am
src/bin/agent/tools/.gitignore [new file with mode: 0644]
src/bin/agent/tools/Makefile.am [new file with mode: 0644]
src/bin/agent/tools/parser-ca.cc [new file with mode: 0644]
src/bin/d2/Makefile.am
src/bin/d2/tests/Makefile.am
src/bin/d2/tools/.gitignore [new file with mode: 0644]
src/bin/d2/tools/Makefile.am [new file with mode: 0644]
src/bin/d2/tools/parser2.cc [new file with mode: 0644]
src/bin/dhcp4/Makefile.am
src/bin/dhcp4/tests/Makefile.am
src/bin/dhcp4/tools/.gitignore [new file with mode: 0644]
src/bin/dhcp4/tools/Makefile.am [new file with mode: 0644]
src/bin/dhcp4/tools/parser4.cc [new file with mode: 0644]
src/bin/dhcp6/Makefile.am
src/bin/dhcp6/tests/Makefile.am
src/bin/dhcp6/tools/.gitignore [new file with mode: 0644]
src/bin/dhcp6/tools/Makefile.am [new file with mode: 0644]
src/bin/dhcp6/tools/parser6.cc [new file with mode: 0644]
src/bin/netconf/Makefile.am
src/bin/netconf/tests/Makefile.am
src/bin/netconf/tools/.gitignore [new file with mode: 0644]
src/bin/netconf/tools/Makefile.am [new file with mode: 0644]
src/bin/netconf/tools/parser-nc.cc [new file with mode: 0644]

index a721b37dda7f41e1767058af7c03436e6c0d5722..dbfbf76f4d54f9b11b45d00b9ec48d641016a01d 100644 (file)
@@ -1501,22 +1501,26 @@ AC_CONFIG_FILES([Makefile
                  src/bin/agent/tests/ca_process_tests.sh
                  src/bin/agent/tests/test_data_files_config.h
                  src/bin/agent/tests/test_libraries.h
+                 src/bin/agent/tools/Makefile
                  src/bin/d2/Makefile
                  src/bin/d2/tests/Makefile
                  src/bin/d2/tests/d2_process_tests.sh
                  src/bin/d2/tests/test_data_files_config.h
+                 src/bin/d2/tools/Makefile
                  src/bin/dhcp4/Makefile
                  src/bin/dhcp4/tests/Makefile
                  src/bin/dhcp4/tests/dhcp4_process_tests.sh
                  src/bin/dhcp4/tests/marker_file.h
                  src/bin/dhcp4/tests/test_data_files_config.h
                  src/bin/dhcp4/tests/test_libraries.h
+                 src/bin/dhcp4/tools/Makefile
                  src/bin/dhcp6/Makefile
                  src/bin/dhcp6/tests/Makefile
                  src/bin/dhcp6/tests/dhcp6_process_tests.sh
                  src/bin/dhcp6/tests/marker_file.h
                  src/bin/dhcp6/tests/test_data_files_config.h
                  src/bin/dhcp6/tests/test_libraries.h
+                 src/bin/dhcp6/tools/Makefile
                  src/bin/keactrl/Makefile
                  src/bin/keactrl/keactrl
                  src/bin/keactrl/keactrl.conf
@@ -1530,6 +1534,7 @@ 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/netconf/tools/Makefile
                  src/bin/perfdhcp/Makefile
                  src/bin/perfdhcp/tests/Makefile
                  src/bin/perfdhcp/tests/testdata/Makefile
index dfb52a23045047002e4906650ea2e5e092391e9e..ef2022c844f3fb57cb8ae219c9b50aca13f45ae9 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . tests tools
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
@@ -39,13 +39,11 @@ s-messages: ca_messages.mes
 BUILT_SOURCES = ca_messages.h ca_messages.cc
 
 
-# convenience archive
+# convenience archives
 
-noinst_LTLIBRARIES = libagent.la
+noinst_LTLIBRARIES = libagent.la libparser-ca.la
 
-libagent_la_SOURCES  = agent_parser.cc agent_parser.h
-libagent_la_SOURCES += agent_lexer.cc
-libagent_la_SOURCES += ca_cfg_mgr.cc ca_cfg_mgr.h
+libagent_la_SOURCES  = ca_cfg_mgr.cc ca_cfg_mgr.h
 libagent_la_SOURCES += ca_controller.cc ca_controller.h
 libagent_la_SOURCES += ca_command_mgr.cc ca_command_mgr.h
 libagent_la_SOURCES += ca_log.cc ca_log.h
@@ -53,19 +51,22 @@ libagent_la_SOURCES += ca_process.cc ca_process.h
 libagent_la_SOURCES += ca_response_creator.cc ca_response_creator.h
 libagent_la_SOURCES += ca_response_creator_factory.h
 libagent_la_SOURCES += simple_parser.cc simple_parser.h
-libagent_la_SOURCES += parser_context.cc parser_context.h parser_context_decl.h
-libagent_la_SOURCES += agent_lexer.ll location.hh position.hh stack.hh
-
 nodist_libagent_la_SOURCES = ca_messages.h ca_messages.cc
 EXTRA_DIST += ca_messages.mes
 EXTRA_DIST += agent_lexer.ll
 EXTRA_DIST += agent_parser.yy
 
+libparser_ca_la_SOURCES  = agent_lexer.ll agent_lexer.cc
+libparser_ca_la_SOURCES += location.hh position.hh stack.hh
+libparser_ca_la_SOURCES += agent_parser.cc agent_parser.h 
+libparser_ca_la_SOURCES += parser_context.cc parser_context.h
+libparser_ca_la_SOURCES += parser_context_decl.h
+
 sbin_PROGRAMS = kea-ctrl-agent
 
 kea_ctrl_agent_SOURCES = main.cc
 
-kea_ctrl_agent_LDADD  = libagent.la
+kea_ctrl_agent_LDADD  = libagent.la libparser-ca.la
 kea_ctrl_agent_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 kea_ctrl_agent_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
 kea_ctrl_agent_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
index eb8c89849e67ce80e5a258523d6c0f60740895db..ac80f98c2ee1d8639638866796e8608b6be93e2b 100644 (file)
@@ -57,7 +57,8 @@ ca_unittests_SOURCES += get_config_unittest.cc
 ca_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 ca_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)
 
-ca_unittests_LDADD = $(top_builddir)/src/bin/agent/libagent.la
+ca_unittests_LDADD  = $(top_builddir)/src/bin/agent/libagent.la
+ca_unittests_LDADD += $(top_builddir)/src/bin/agent/libparser-ca.la
 ca_unittests_LDADD += $(top_builddir)/src/lib/process/testutils/libprocesstest.la
 ca_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 ca_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
diff --git a/src/bin/agent/tools/.gitignore b/src/bin/agent/tools/.gitignore
new file mode 100644 (file)
index 0000000..b7dc257
--- /dev/null
@@ -0,0 +1,2 @@
+/parser-ca
+/tools-ca.8
diff --git a/src/bin/agent/tools/Makefile.am b/src/bin/agent/tools/Makefile.am
new file mode 100644 (file)
index 0000000..6d88612
--- /dev/null
@@ -0,0 +1,19 @@
+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 += $(BOOST_INCLUDES)
+#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+sbin_PROGRAMS = parser-ca
+#sbin_PROGRAMS += to-yang from-yang
+
+parser_ca_SOURCES = parser-ca.cc
+parser_ca_LDADD  = $(top_builddir)/src/bin/agent/libparser-ca.la
+parser_ca_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+parser_ca_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+parser_ca_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+parser_ca_LDADD += $(BOOST_LIBS)
+#parser_ca_LDADD += $(SYSREPO_LIBS)
+parser_ca_LDFLAGS = $(AM_LDFLAGS)
diff --git a/src/bin/agent/tools/parser-ca.cc b/src/bin/agent/tools/parser-ca.cc
new file mode 100644 (file)
index 0000000..c2f549c
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2019 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 <kea_version.h>
+
+#include <agent/parser_context.h>
+
+#include <fstream>
+#include <iostream>
+
+using namespace isc;
+using namespace isc::data;
+using namespace std;
+
+/// @file Just apply the Control agent parser from the input file and
+/// pretty print the result to the output file.
+
+/// @brief Print parser-ca usage.
+void
+usage() {
+    cerr << "Usage: parser-ca [-v] [-V] -i <input> -o <output>" << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+    string input_file("");
+    string output_file("");
+
+    int ch;
+    while ((ch = getopt(argc, argv, "i:o:vV")) != -1) {
+        switch (ch) {
+        case 'i':
+            input_file = optarg;
+            break;
+
+        case 'o':
+            output_file = optarg;
+            break;
+
+        case 'v':
+            cout << VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        case 'V':
+            cout << VERSION << endl << EXTENDED_VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        default:
+            usage();
+            return (EXIT_FAILURE);
+        }
+    }
+
+    // Check for extraneous parameters.
+    if (argc > optind) {
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    // Input file is required.
+    if (input_file.empty()) {
+        cerr << "Input file was not specified." << endl;
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    try {
+        ParserContext parser;
+        ConstElementPtr json;
+        json = parser.parseFile(input_file, ParserContext::PARSER_AGENT);
+        if (!json) {
+            cerr << "No input found" << endl;
+            return (EXIT_FAILURE);
+        }
+
+        if (output_file.empty()) {
+            cout << prettyPrint(json) << endl;
+        } else {
+            ofstream out(output_file, ios::trunc);
+            if (!out.good()) {
+                isc_throw(Unexpected, "Unable to open file " + output_file +
+                          " for writing");
+                out << prettyPrint(json) << endl;
+            }
+            out.close();
+        }
+    } catch (const std::exception& ex) {
+        cerr << "parser-ca failed with " << ex.what() << endl;
+        return (EXIT_FAILURE);
+    }
+    return (EXIT_SUCCESS);
+}
index 7da230336a66946d0f14a4bc64552e7066c38b53..df06ca0eee274ecff819f96ce7ffc3995b0fa11c 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . tests tools
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
@@ -47,17 +47,15 @@ s-messages: d2_messages.mes
 
 BUILT_SOURCES = d2_messages.h d2_messages.cc
 
-# convenience archive
+# convenience archives
 
-noinst_LTLIBRARIES = libd2.la
+noinst_LTLIBRARIES = libd2.la libparser2.la
 
 libd2_la_SOURCES  =
 libd2_la_SOURCES += d2_log.cc d2_log.h
 libd2_la_SOURCES += d2_process.cc d2_process.h
 libd2_la_SOURCES += d2_config.cc d2_config.h
 libd2_la_SOURCES += d2_cfg_mgr.cc d2_cfg_mgr.h
-libd2_la_SOURCES += d2_lexer.ll location.hh position.hh stack.hh
-libd2_la_SOURCES += d2_parser.cc d2_parser.h
 libd2_la_SOURCES += d2_queue_mgr.cc d2_queue_mgr.h
 libd2_la_SOURCES += d2_simple_parser.cc d2_simple_parser.h
 libd2_la_SOURCES += d2_update_message.cc d2_update_message.h
@@ -68,16 +66,22 @@ libd2_la_SOURCES += nc_add.cc nc_add.h
 libd2_la_SOURCES += nc_remove.cc nc_remove.h
 libd2_la_SOURCES += nc_trans.cc nc_trans.h
 libd2_la_SOURCES += d2_controller.cc d2_controller.h
-libd2_la_SOURCES += parser_context.cc parser_context.h parser_context_decl.h
+
 
 nodist_libd2_la_SOURCES = d2_messages.h d2_messages.cc
 EXTRA_DIST += d2_messages.mes
 
+libparser2_la_SOURCES  =
+libparser2_la_SOURCES += d2_lexer.ll location.hh position.hh stack.hh
+libparser2_la_SOURCES += d2_parser.cc d2_parser.h
+libparser2_la_SOURCES += parser_context.cc parser_context.h
+libparser2_la_SOURCES += parser_context_decl.h
+
 sbin_PROGRAMS = kea-dhcp-ddns
 
 kea_dhcp_ddns_SOURCES  = main.cc
 
-kea_dhcp_ddns_LDADD  = libd2.la
+kea_dhcp_ddns_LDADD  = libd2.la libparser2.la
 kea_dhcp_ddns_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 kea_dhcp_ddns_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
 kea_dhcp_ddns_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
index 168f50c7b8ef65a5f8837fcef632a82ee00a9525..582998e047ed66475b5f027db4eb16a17523fc76 100644 (file)
@@ -74,6 +74,7 @@ endif
 d2_unittests_LDFLAGS += $(GTEST_LDFLAGS)
 
 d2_unittests_LDADD = $(top_builddir)/src/bin/d2/libd2.la
+d2_unittests_LDADD += $(top_builddir)/src/bin/d2/libparser2.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/process/testutils/libprocesstest.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
diff --git a/src/bin/d2/tools/.gitignore b/src/bin/d2/tools/.gitignore
new file mode 100644 (file)
index 0000000..31a12e5
--- /dev/null
@@ -0,0 +1,2 @@
+/parser2
+/tools4.8
diff --git a/src/bin/d2/tools/Makefile.am b/src/bin/d2/tools/Makefile.am
new file mode 100644 (file)
index 0000000..467048d
--- /dev/null
@@ -0,0 +1,20 @@
+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 += $(BOOST_INCLUDES)
+#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+sbin_PROGRAMS = parser2
+#sbin_PROGRAMS += to-yang from-yang
+
+parser2_SOURCES = parser2.cc
+parser2_LDADD  = $(top_builddir)/src/bin/d2/libparser2.la
+parser2_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+parser2_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+parser2_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+parser2_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+parser2_LDADD += $(BOOST_LIBS)
+#parser2_LDADD += $(SYSREPO_LIBS)
+parser2_LDFLAGS = $(AM_LDFLAGS)
diff --git a/src/bin/d2/tools/parser2.cc b/src/bin/d2/tools/parser2.cc
new file mode 100644 (file)
index 0000000..4bd46f2
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2019 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 <kea_version.h>
+
+#include <d2/parser_context.h>
+
+#include <fstream>
+#include <iostream>
+
+using namespace isc;
+using namespace isc::data;
+using namespace std;
+
+/// @file Just apply the D2 parser from the input file and pretty print
+/// the result to the output file.
+
+/// @brief Print parser2 usage.
+void
+usage() {
+    cerr << "Usage: parser2 [-v] [-V] -i <input> -o <output>" << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+    string input_file("");
+    string output_file("");
+
+    int ch;
+    while ((ch = getopt(argc, argv, "i:o:vV")) != -1) {
+        switch (ch) {
+        case 'i':
+            input_file = optarg;
+            break;
+
+        case 'o':
+            output_file = optarg;
+            break;
+
+        case 'v':
+            cout << VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        case 'V':
+            cout << VERSION << endl << EXTENDED_VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        default:
+            usage();
+            return (EXIT_FAILURE);
+        }
+    }
+
+    // Check for extraneous parameters.
+    if (argc > optind) {
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    // Input file is required.
+    if (input_file.empty()) {
+        cerr << "Input file was not specified." << endl;
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    try {
+        D2ParserContext parser;
+        ConstElementPtr json;
+        json = parser.parseFile(input_file, D2ParserContext::PARSER_DHCPDDNS);
+        if (!json) {
+            cerr << "No input found" << endl;
+            return (EXIT_FAILURE);
+        }
+
+        if (output_file.empty()) {
+            cout << prettyPrint(json) << endl;
+        } else {
+            ofstream out(output_file, ios::trunc);
+            if (!out.good()) {
+                isc_throw(Unexpected, "Unable to open file " + output_file +
+                          " for writing");
+                out << prettyPrint(json) << endl;
+            }
+            out.close();
+        }
+    } catch (const std::exception& ex) {
+        cerr << "parser2 failed with " << ex.what() << endl;
+        return (EXIT_FAILURE);
+    }
+    return (EXIT_SUCCESS);
+}
index a0da1621b88faa715fdebc806769108c83caf0c0..34df6554e3d9d919cc7975417e0be9ee4931e5e0 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . tests tools
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
@@ -50,9 +50,9 @@ s-messages: dhcp4_messages.mes
 
 BUILT_SOURCES = dhcp4_messages.h dhcp4_messages.cc
 
-# convenience archive
+# convenience archives
 
-noinst_LTLIBRARIES = libdhcp4.la
+noinst_LTLIBRARIES = libdhcp4.la libparser4.la
 
 libdhcp4_la_SOURCES  =
 libdhcp4_la_SOURCES += ctrl_dhcp4_srv.cc ctrl_dhcp4_srv.h
@@ -60,18 +60,21 @@ libdhcp4_la_SOURCES += json_config_parser.cc json_config_parser.h
 libdhcp4_la_SOURCES += dhcp4_log.cc dhcp4_log.h
 libdhcp4_la_SOURCES += dhcp4_srv.cc dhcp4_srv.h
 libdhcp4_la_SOURCES += dhcp4to6_ipc.cc dhcp4to6_ipc.h
-libdhcp4_la_SOURCES += dhcp4_lexer.ll location.hh position.hh stack.hh
-libdhcp4_la_SOURCES += dhcp4_parser.cc dhcp4_parser.h
-libdhcp4_la_SOURCES += parser_context.cc parser_context.h parser_context_decl.h
 
 nodist_libdhcp4_la_SOURCES = dhcp4_messages.h dhcp4_messages.cc
 EXTRA_DIST += dhcp4_messages.mes
 
+libparser4_la_SOURCES  =
+libparser4_la_SOURCES += dhcp4_lexer.ll location.hh position.hh stack.hh
+libparser4_la_SOURCES += dhcp4_parser.cc dhcp4_parser.h
+libparser4_la_SOURCES += parser_context.cc parser_context.h
+libparser4_la_SOURCES += parser_context_decl.h
+
 sbin_PROGRAMS = kea-dhcp4
 
 kea_dhcp4_SOURCES  = main.cc
 
-kea_dhcp4_LDADD  = libdhcp4.la
+kea_dhcp4_LDADD  = libdhcp4.la libparser4.la
 kea_dhcp4_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 kea_dhcp4_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 kea_dhcp4_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
index 9e0221d3b52b5aa07c3be794e8dbc60a285e8fa2..6c54368bced5cfc625df2480a9fdc8e327e5818a 100644 (file)
@@ -120,6 +120,7 @@ endif
 dhcp4_unittests_LDFLAGS += $(GTEST_LDFLAGS)
 
 dhcp4_unittests_LDADD = $(top_builddir)/src/bin/dhcp4/libdhcp4.la
+dhcp4_unittests_LDADD += $(top_builddir)/src/bin/dhcp4/libparser4.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
diff --git a/src/bin/dhcp4/tools/.gitignore b/src/bin/dhcp4/tools/.gitignore
new file mode 100644 (file)
index 0000000..191faa7
--- /dev/null
@@ -0,0 +1,2 @@
+/parser4
+/tools4.8
diff --git a/src/bin/dhcp4/tools/Makefile.am b/src/bin/dhcp4/tools/Makefile.am
new file mode 100644 (file)
index 0000000..59ed2a8
--- /dev/null
@@ -0,0 +1,20 @@
+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 += $(BOOST_INCLUDES)
+#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+sbin_PROGRAMS = parser4
+#sbin_PROGRAMS += to-yang from-yang
+
+parser4_SOURCES = parser4.cc
+parser4_LDADD  = $(top_builddir)/src/bin/dhcp4/libparser4.la
+parser4_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+parser4_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+parser4_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+parser4_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+parser4_LDADD += $(BOOST_LIBS)
+#parser4_LDADD += $(SYSREPO_LIBS)
+parser4_LDFLAGS = $(AM_LDFLAGS)
diff --git a/src/bin/dhcp4/tools/parser4.cc b/src/bin/dhcp4/tools/parser4.cc
new file mode 100644 (file)
index 0000000..ff2add6
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2019 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 <kea_version.h>
+
+#include <dhcp4/parser_context.h>
+
+#include <fstream>
+#include <iostream>
+
+using namespace isc;
+using namespace isc::data;
+using namespace std;
+
+/// @file Just apply the DHCPv4 parser from the input file and pretty print
+/// the result to the output file.
+
+/// @brief Print parser4 usage.
+void
+usage() {
+    cerr << "Usage: parser4 [-v] [-V] -i <input> -o <output>" << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+    string input_file("");
+    string output_file("");
+
+    int ch;
+    while ((ch = getopt(argc, argv, "i:o:vV")) != -1) {
+        switch (ch) {
+        case 'i':
+            input_file = optarg;
+            break;
+
+        case 'o':
+            output_file = optarg;
+            break;
+
+        case 'v':
+            cout << VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        case 'V':
+            cout << VERSION << endl << EXTENDED_VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        default:
+            usage();
+            return (EXIT_FAILURE);
+        }
+    }
+
+    // Check for extraneous parameters.
+    if (argc > optind) {
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    // Input file is required.
+    if (input_file.empty()) {
+        cerr << "Input file was not specified." << endl;
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    try {
+        Parser4Context parser;
+        ConstElementPtr json;
+        json = parser.parseFile(input_file, Parser4Context::PARSER_DHCP4);
+        if (!json) {
+            cerr << "No input found" << endl;
+            return (EXIT_FAILURE);
+        }
+
+        if (output_file.empty()) {
+            cout << prettyPrint(json) << endl;
+        } else {
+            ofstream out(output_file, ios::trunc);
+            if (!out.good()) {
+                isc_throw(Unexpected, "Unable to open file " + output_file +
+                          " for writing");
+                out << prettyPrint(json) << endl;
+            }
+            out.close();
+        }
+    } catch (const std::exception& ex) {
+        cerr << "parser4 failed with " << ex.what() << endl;
+        return (EXIT_FAILURE);
+    }
+    return (EXIT_SUCCESS);
+}
index e82f9c2770bea7c962a7c099c75dccf868bfd783..7f7b8ccd0211bd9776421f02d4501e53f5423b12 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . tests tools
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
@@ -51,9 +51,9 @@ s-messages: dhcp6_messages.mes
 
 BUILT_SOURCES = dhcp6_messages.h dhcp6_messages.cc
 
-# convenience archive
+# convenience archives
 
-noinst_LTLIBRARIES = libdhcp6.la
+noinst_LTLIBRARIES = libdhcp6.la libparser6.la
 
 libdhcp6_la_SOURCES  =
 libdhcp6_la_SOURCES += dhcp6_log.cc dhcp6_log.h
@@ -61,17 +61,20 @@ libdhcp6_la_SOURCES += dhcp6_srv.cc dhcp6_srv.h
 libdhcp6_la_SOURCES += ctrl_dhcp6_srv.cc ctrl_dhcp6_srv.h
 libdhcp6_la_SOURCES += json_config_parser.cc json_config_parser.h
 libdhcp6_la_SOURCES += dhcp6to4_ipc.cc dhcp6to4_ipc.h
-libdhcp6_la_SOURCES += dhcp6_lexer.ll location.hh position.hh stack.hh
-libdhcp6_la_SOURCES += dhcp6_parser.cc dhcp6_parser.h
-libdhcp6_la_SOURCES += parser_context.cc parser_context.h parser_context_decl.h
 nodist_libdhcp6_la_SOURCES = dhcp6_messages.h dhcp6_messages.cc
 EXTRA_DIST += dhcp6_messages.mes
 
+libparser6_la_SOURCES  =
+libparser6_la_SOURCES += dhcp6_lexer.ll location.hh position.hh stack.hh
+libparser6_la_SOURCES += dhcp6_parser.cc dhcp6_parser.h
+libparser6_la_SOURCES += parser_context.cc parser_context.h
+libparser6_la_SOURCES += parser_context_decl.h
+
 sbin_PROGRAMS = kea-dhcp6
 
 kea_dhcp6_SOURCES  = main.cc
 
-kea_dhcp6_LDADD  = libdhcp6.la
+kea_dhcp6_LDADD  = libdhcp6.la libparser6.la
 kea_dhcp6_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 kea_dhcp6_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 kea_dhcp6_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
index f92c8d77e59b39dd306c5350fac2d7bfe5e9e5ee..78292779863739ea4885b3c75b2f5e1ee4d3975e 100644 (file)
@@ -120,6 +120,7 @@ endif
 dhcp6_unittests_LDFLAGS += $(GTEST_LDFLAGS)
 
 dhcp6_unittests_LDADD = $(top_builddir)/src/bin/dhcp6/libdhcp6.la
+dhcp6_unittests_LDADD += $(top_builddir)/src/bin/dhcp6/libparser6.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
diff --git a/src/bin/dhcp6/tools/.gitignore b/src/bin/dhcp6/tools/.gitignore
new file mode 100644 (file)
index 0000000..b4e6ce2
--- /dev/null
@@ -0,0 +1,2 @@
+/parser6
+/tools6.8
diff --git a/src/bin/dhcp6/tools/Makefile.am b/src/bin/dhcp6/tools/Makefile.am
new file mode 100644 (file)
index 0000000..984094c
--- /dev/null
@@ -0,0 +1,20 @@
+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 += $(BOOST_INCLUDES)
+#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+sbin_PROGRAMS = parser6
+#sbin_PROGRAMS += to-yang from-yang
+
+parser6_SOURCES = parser6.cc
+parser6_LDADD  = $(top_builddir)/src/bin/dhcp6/libparser6.la
+parser6_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+parser6_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+parser6_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+parser6_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+parser6_LDADD += $(BOOST_LIBS)
+#parser6_LDADD += $(SYSREPO_LIBS)
+parser6_LDFLAGS = $(AM_LDFLAGS)
diff --git a/src/bin/dhcp6/tools/parser6.cc b/src/bin/dhcp6/tools/parser6.cc
new file mode 100644 (file)
index 0000000..5b178ab
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2019 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 <kea_version.h>
+
+#include <dhcp6/parser_context.h>
+
+#include <fstream>
+#include <iostream>
+
+using namespace isc;
+using namespace isc::data;
+using namespace std;
+
+/// @file Just apply the DHCPv6 parser from the input file and pretty print
+/// the result to the output file.
+
+/// @brief Print parser6 usage.
+void
+usage() {
+    cerr << "Usage: parser6 [-v] [-V] -i <input> -o <output>" << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+    string input_file("");
+    string output_file("");
+
+    int ch;
+    while ((ch = getopt(argc, argv, "i:o:vV")) != -1) {
+        switch (ch) {
+        case 'i':
+            input_file = optarg;
+            break;
+
+        case 'o':
+            output_file = optarg;
+            break;
+
+        case 'v':
+            cout << VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        case 'V':
+            cout << VERSION << endl << EXTENDED_VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        default:
+            usage();
+            return (EXIT_FAILURE);
+        }
+    }
+
+    // Check for extraneous parameters.
+    if (argc > optind) {
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    // Input file is required.
+    if (input_file.empty()) {
+        cerr << "Input file was not specified." << endl;
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    try {
+        Parser6Context parser;
+        ConstElementPtr json;
+        json = parser.parseFile(input_file, Parser6Context::PARSER_DHCP6);
+        if (!json) {
+            cerr << "No input found" << endl;
+            return (EXIT_FAILURE);
+        }
+
+        if (output_file.empty()) {
+            cout << prettyPrint(json) << endl;
+        } else {
+            ofstream out(output_file, ios::trunc);
+            if (!out.good()) {
+                isc_throw(Unexpected, "Unable to open file " + output_file +
+                          " for writing");
+                out << prettyPrint(json) << endl;
+            }
+            out.close();
+        }
+    } catch (const std::exception& ex) {
+        cerr << "parser6 failed with " << ex.what() << endl;
+        return (EXIT_FAILURE);
+    }
+    return (EXIT_SUCCESS);
+}
index a2ed58c31acca137397a9a7cac811bf6c1daa03f..0c02738f918c7416d28320748f93beb1acf23114 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . tests
+SUBDIRS = . tests tools
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
@@ -40,9 +40,9 @@ s-messages: netconf_messages.mes
 
 BUILT_SOURCES = netconf_messages.h netconf_messages.cc
 
-# convenience archive
+# convenience archives
 
-noinst_LTLIBRARIES = libnetconf.la
+noinst_LTLIBRARIES = libnetconf.la libparser-nc.la
 
 libnetconf_la_SOURCES  = control_socket.cc control_socket.h
 libnetconf_la_SOURCES += http_control_socket.cc http_control_socket.h
@@ -53,13 +53,8 @@ libnetconf_la_SOURCES += netconf_cfg_mgr.cc netconf_cfg_mgr.h
 libnetconf_la_SOURCES += netconf_config.cc netconf_config.h
 libnetconf_la_SOURCES += netconf_controller.cc netconf_controller.h
 libnetconf_la_SOURCES += netconf_log.cc netconf_log.h
-libnetconf_la_SOURCES += netconf_parser.cc netconf_parser.h
 libnetconf_la_SOURCES += netconf_process.cc netconf_process.h
-libnetconf_la_SOURCES += parser_context.cc parser_context.h
-libnetconf_la_SOURCES += parser_context_decl.h
 libnetconf_la_SOURCES += simple_parser.cc simple_parser.h
-libnetconf_la_SOURCES += location.hh position.hh stack.hh
-libnetconf_la_SOURCES += netconf_lexer.ll netconf_parser.yy
 
 nodist_libnetconf_la_SOURCES = netconf_messages.h netconf_messages.cc
 
@@ -67,11 +62,18 @@ EXTRA_DIST += netconf_messages.mes
 EXTRA_DIST += netconf_lexer.ll
 EXTRA_DIST += netconf_parser.yy
 
+libparser_nc_la_SOURCES  = netconf_parser.cc netconf_parser.h
+libparser_nc_la_SOURCES += parser_context.cc parser_context.h
+libparser_nc_la_SOURCES += parser_context_decl.h
+libparser_nc_la_SOURCES += location.hh position.hh stack.hh
+libparser_nc_la_SOURCES += netconf_lexer.ll netconf_parser.yy
+
+
 sbin_PROGRAMS = kea-netconf
 
 kea_netconf_SOURCES  = main.cc
 
-kea_netconf_LDADD  = libnetconf.la
+kea_netconf_LDADD  = libnetconf.la libparser-nc.la
 kea_netconf_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
 kea_netconf_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
 kea_netconf_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
index 321a5ff577898ae9db8a1a336a568805069d76c9..2e83f8b5419cdc2003deb7caa320e9c1a97742bd 100644 (file)
@@ -44,19 +44,14 @@ netconf_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS)
 
 
 netconf_unittests_LDADD = $(top_builddir)/src/bin/netconf/libnetconf.la
+netconf_unittests_LDADD += $(top_builddir)/src/bin/netconf/libparser-nc.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/process/testutils/libprocesstest.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
-#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
-#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
-#netconf_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
-#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/yang/testutils/libyangtest.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/yang/libkea-yang.la
-#netconf_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
-#netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcp/tests/libdhcptest.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
 netconf_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
diff --git a/src/bin/netconf/tools/.gitignore b/src/bin/netconf/tools/.gitignore
new file mode 100644 (file)
index 0000000..76a39cc
--- /dev/null
@@ -0,0 +1,2 @@
+/parser-nc
+/tools-nc.8
diff --git a/src/bin/netconf/tools/Makefile.am b/src/bin/netconf/tools/Makefile.am
new file mode 100644 (file)
index 0000000..bcd7ed6
--- /dev/null
@@ -0,0 +1,20 @@
+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 += $(BOOST_INCLUDES)
+#AM_CPPFLAGS += $(SYSREPO_CPPFLAGS)
+
+CLEANFILES = *.gcno *.gcda
+
+sbin_PROGRAMS = parser-nc
+#sbin_PROGRAMS += to-yang from-yang
+
+parser_nc_SOURCES = parser-nc.cc
+parser_nc_LDADD  = $(top_builddir)/src/bin/netconf/libparser-nc.la
+parser_nc_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+parser_nc_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+parser_nc_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+parser_nc_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+parser_nc_LDADD += $(BOOST_LIBS)
+#parser_nc_LDADD += $(SYSREPO_LIBS)
+parser_nc_LDFLAGS = $(AM_LDFLAGS)
diff --git a/src/bin/netconf/tools/parser-nc.cc b/src/bin/netconf/tools/parser-nc.cc
new file mode 100644 (file)
index 0000000..980368d
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2019 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 <kea_version.h>
+
+#include <netconf/parser_context.h>
+
+#include <fstream>
+#include <iostream>
+
+using namespace isc;
+using namespace isc::data;
+using namespace std;
+
+/// @file Just apply the Netconf parser from the input file and pretty print
+/// the result to the output file.
+
+/// @brief Print parser-nc usage.
+void
+usage() {
+    cerr << "Usage: parser-nc [-v] [-V] -i <input> -o <output>" << endl;
+}
+
+int
+main(int argc, char* argv[]) {
+    string input_file("");
+    string output_file("");
+
+    int ch;
+    while ((ch = getopt(argc, argv, "i:o:vV")) != -1) {
+        switch (ch) {
+        case 'i':
+            input_file = optarg;
+            break;
+
+        case 'o':
+            output_file = optarg;
+            break;
+
+        case 'v':
+            cout << VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        case 'V':
+            cout << VERSION << endl << EXTENDED_VERSION << endl;
+            return (EXIT_SUCCESS);
+
+        default:
+            usage();
+            return (EXIT_FAILURE);
+        }
+    }
+
+    // Check for extraneous parameters.
+    if (argc > optind) {
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    // Input file is required.
+    if (input_file.empty()) {
+        cerr << "Input file was not specified." << endl;
+        usage();
+        return (EXIT_FAILURE);
+    }
+
+    try {
+        ParserContext parser;
+        ConstElementPtr json;
+        json = parser.parseFile(input_file, ParserContext::PARSER_NETCONF);
+        if (!json) {
+            cerr << "No input found" << endl;
+            return (EXIT_FAILURE);
+        }
+
+        if (output_file.empty()) {
+            cout << prettyPrint(json) << endl;
+        } else {
+            ofstream out(output_file, ios::trunc);
+            if (!out.good()) {
+                isc_throw(Unexpected, "Unable to open file " + output_file +
+                          " for writing");
+                out << prettyPrint(json) << endl;
+            }
+            out.close();
+        }
+    } catch (const std::exception& ex) {
+        cerr << "parser-nc failed with " << ex.what() << endl;
+        return (EXIT_FAILURE);
+    }
+    return (EXIT_SUCCESS);
+}