From: Francis Dupont Date: Sat, 5 Jan 2019 13:33:23 +0000 (+0100) Subject: [333-parser-libraries-for-servers] Added libraries and parser* tools X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10c256071f5cf8b14590008919287706e6659ab4;p=thirdparty%2Fkea.git [333-parser-libraries-for-servers] Added libraries and parser* tools --- diff --git a/configure.ac b/configure.ac index a721b37dda..dbfbf76f4d 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/bin/agent/Makefile.am b/src/bin/agent/Makefile.am index dfb52a2304..ef2022c844 100644 --- a/src/bin/agent/Makefile.am +++ b/src/bin/agent/Makefile.am @@ -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 diff --git a/src/bin/agent/tests/Makefile.am b/src/bin/agent/tests/Makefile.am index eb8c89849e..ac80f98c2e 100644 --- a/src/bin/agent/tests/Makefile.am +++ b/src/bin/agent/tests/Makefile.am @@ -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 index 0000000000..b7dc257d98 --- /dev/null +++ b/src/bin/agent/tools/.gitignore @@ -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 index 0000000000..6d8861260c --- /dev/null +++ b/src/bin/agent/tools/Makefile.am @@ -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 index 0000000000..c2f549ce02 --- /dev/null +++ b/src/bin/agent/tools/parser-ca.cc @@ -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 +#include + +#include + +#include +#include + +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 -o " << 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); +} diff --git a/src/bin/d2/Makefile.am b/src/bin/d2/Makefile.am index 7da230336a..df06ca0eee 100644 --- a/src/bin/d2/Makefile.am +++ b/src/bin/d2/Makefile.am @@ -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 diff --git a/src/bin/d2/tests/Makefile.am b/src/bin/d2/tests/Makefile.am index 168f50c7b8..582998e047 100644 --- a/src/bin/d2/tests/Makefile.am +++ b/src/bin/d2/tests/Makefile.am @@ -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 index 0000000000..31a12e5884 --- /dev/null +++ b/src/bin/d2/tools/.gitignore @@ -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 index 0000000000..467048da5e --- /dev/null +++ b/src/bin/d2/tools/Makefile.am @@ -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 index 0000000000..4bd46f2956 --- /dev/null +++ b/src/bin/d2/tools/parser2.cc @@ -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 +#include + +#include + +#include +#include + +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 -o " << 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); +} diff --git a/src/bin/dhcp4/Makefile.am b/src/bin/dhcp4/Makefile.am index a0da1621b8..34df6554e3 100644 --- a/src/bin/dhcp4/Makefile.am +++ b/src/bin/dhcp4/Makefile.am @@ -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 diff --git a/src/bin/dhcp4/tests/Makefile.am b/src/bin/dhcp4/tests/Makefile.am index 9e0221d3b5..6c54368bce 100644 --- a/src/bin/dhcp4/tests/Makefile.am +++ b/src/bin/dhcp4/tests/Makefile.am @@ -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 index 0000000000..191faa7af8 --- /dev/null +++ b/src/bin/dhcp4/tools/.gitignore @@ -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 index 0000000000..59ed2a8d5b --- /dev/null +++ b/src/bin/dhcp4/tools/Makefile.am @@ -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 index 0000000000..ff2add61a2 --- /dev/null +++ b/src/bin/dhcp4/tools/parser4.cc @@ -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 +#include + +#include + +#include +#include + +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 -o " << 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); +} diff --git a/src/bin/dhcp6/Makefile.am b/src/bin/dhcp6/Makefile.am index e82f9c2770..7f7b8ccd02 100644 --- a/src/bin/dhcp6/Makefile.am +++ b/src/bin/dhcp6/Makefile.am @@ -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 diff --git a/src/bin/dhcp6/tests/Makefile.am b/src/bin/dhcp6/tests/Makefile.am index f92c8d77e5..7829277986 100644 --- a/src/bin/dhcp6/tests/Makefile.am +++ b/src/bin/dhcp6/tests/Makefile.am @@ -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 index 0000000000..b4e6ce27f2 --- /dev/null +++ b/src/bin/dhcp6/tools/.gitignore @@ -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 index 0000000000..984094c335 --- /dev/null +++ b/src/bin/dhcp6/tools/Makefile.am @@ -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 index 0000000000..5b178ab54c --- /dev/null +++ b/src/bin/dhcp6/tools/parser6.cc @@ -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 +#include + +#include + +#include +#include + +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 -o " << 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); +} diff --git a/src/bin/netconf/Makefile.am b/src/bin/netconf/Makefile.am index a2ed58c31a..0c02738f91 100644 --- a/src/bin/netconf/Makefile.am +++ b/src/bin/netconf/Makefile.am @@ -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 diff --git a/src/bin/netconf/tests/Makefile.am b/src/bin/netconf/tests/Makefile.am index 321a5ff577..2e83f8b541 100644 --- a/src/bin/netconf/tests/Makefile.am +++ b/src/bin/netconf/tests/Makefile.am @@ -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 index 0000000000..76a39cc834 --- /dev/null +++ b/src/bin/netconf/tools/.gitignore @@ -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 index 0000000000..bcd7ed608b --- /dev/null +++ b/src/bin/netconf/tools/Makefile.am @@ -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 index 0000000000..980368db92 --- /dev/null +++ b/src/bin/netconf/tools/parser-nc.cc @@ -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 +#include + +#include + +#include +#include + +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 -o " << 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); +}