BIND 10 trac575, updated. 8f77709804055982134db51383ee1455e7905692 [trac575] Move parseAddresses to libserver_common
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Feb 18 17:06:31 UTC 2011
The branch, trac575 has been updated
via 8f77709804055982134db51383ee1455e7905692 (commit)
via 7eb6dab85f3e03104c30127c7af34b75e2c21002 (commit)
from 689503220317cf2e86dae704a8e660ed646af67b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 8f77709804055982134db51383ee1455e7905692
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Feb 18 18:05:39 2011 +0100
[trac575] Move parseAddresses to libserver_common
It is taken out from the resolver and will be used by both servers.
Added tests, it was tested implicitly before.
commit 7eb6dab85f3e03104c30127c7af34b75e2c21002
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Feb 18 15:43:56 2011 +0100
[trac575] Create libserver_common
-----------------------------------------------------------------------
Summary of changes:
configure.ac | 2 +
doc/Doxyfile | 2 +-
src/bin/resolver/Makefile.am | 1 +
src/bin/resolver/resolver.cc | 53 ++-----------
src/bin/resolver/tests/Makefile.am | 1 +
src/lib/Makefile.am | 2 +-
src/lib/server_common/Makefile.am | 25 ++++++
src/lib/server_common/portconfig.cc | 66 ++++++++++++++++
src/lib/server_common/portconfig.h | 83 ++++++++++++++++++++
src/lib/server_common/tests/Makefile.am | 38 +++++++++
.../{log => server_common}/tests/run_unittests.cc | 5 +
11 files changed, 231 insertions(+), 47 deletions(-)
create mode 100644 src/lib/server_common/Makefile.am
create mode 100644 src/lib/server_common/portconfig.cc
create mode 100644 src/lib/server_common/portconfig.h
create mode 100644 src/lib/server_common/tests/Makefile.am
copy src/lib/{log => server_common}/tests/run_unittests.cc (93%)
-----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 139166b..3531d43 100644
--- a/configure.ac
+++ b/configure.ac
@@ -714,6 +714,8 @@ AC_CONFIG_FILES([Makefile
src/lib/nsas/tests/Makefile
src/lib/cache/Makefile
src/lib/cache/tests/Makefile
+ src/lib/server_common/Makefile
+ src/lib/server_common/tests/Makefile
])
AC_OUTPUT([doc/version.ent
src/bin/cfgmgr/b10-cfgmgr.py
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 34ec3d8..46aa178 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -568,7 +568,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth ../src/bin/resolver ../src/lib/bench ../src/lib/log ../src/lib/asiolink/ ../src/lib/nsas ../src/lib/testutils ../src/lib/cache
+INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth ../src/bin/resolver ../src/lib/bench ../src/lib/log ../src/lib/asiolink/ ../src/lib/nsas ../src/lib/testutils ../src/lib/cache ../src/lib/server_common/
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
diff --git a/src/bin/resolver/Makefile.am b/src/bin/resolver/Makefile.am
index 9e86ddd..40b13de 100644
--- a/src/bin/resolver/Makefile.am
+++ b/src/bin/resolver/Makefile.am
@@ -48,6 +48,7 @@ b10_resolver_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
b10_resolver_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_resolver_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
b10_resolver_LDADD += $(top_builddir)/src/lib/log/liblog.la
+b10_resolver_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
b10_resolver_LDADD += $(top_builddir)/src/bin/auth/change_user.o
b10_resolver_LDFLAGS = -pthread
diff --git a/src/bin/resolver/resolver.cc b/src/bin/resolver/resolver.cc
index dfd84a6..efdb1be 100644
--- a/src/bin/resolver/resolver.cc
+++ b/src/bin/resolver/resolver.cc
@@ -39,6 +39,7 @@
#include <dns/rrttl.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
+#include <server_common/portconfig.h>
#include <log/dummylog.h>
@@ -52,8 +53,7 @@ using namespace isc::data;
using namespace isc::config;
using isc::log::dlog;
using namespace asiolink;
-
-typedef pair<string, uint16_t> addr_t;
+using namespace isc::server_common::portconfig;
class ResolverImpl {
private:
@@ -460,46 +460,6 @@ ResolverImpl::processNormalQuery(const Question& question,
rec_query_->resolve(question, answer_message, buffer, server);
}
-namespace {
-
-vector<addr_t>
-parseAddresses(ConstElementPtr addresses) {
- vector<addr_t> result;
- if (addresses) {
- if (addresses->getType() == Element::list) {
- for (size_t i(0); i < addresses->size(); ++ i) {
- ConstElementPtr addrPair(addresses->get(i));
- ConstElementPtr addr(addrPair->get("address"));
- ConstElementPtr port(addrPair->get("port"));
- if (!addr || ! port) {
- isc_throw(BadValue, "Address must contain both the IP"
- "address and port");
- }
- try {
- IOAddress(addr->stringValue());
- if (port->intValue() < 0 ||
- port->intValue() > 0xffff) {
- isc_throw(BadValue, "Bad port value (" <<
- port->intValue() << ")");
- }
- result.push_back(addr_t(addr->stringValue(),
- port->intValue()));
- }
- catch (const TypeError &e) { // Better error message
- isc_throw(TypeError,
- "Address must be a string and port an integer");
- }
- }
- } else if (addresses->getType() != Element::null) {
- isc_throw(TypeError,
- "root_addresses, forward_addresses, and listen_on config element must be a list");
- }
- }
- return (result);
-}
-
-}
-
ConstElementPtr
Resolver::updateConfig(ConstElementPtr config) {
dlog("New config comes: " + config->toWire());
@@ -507,11 +467,14 @@ Resolver::updateConfig(ConstElementPtr config) {
try {
// Parse forward_addresses
ConstElementPtr rootAddressesE(config->get("root_addresses"));
- vector<addr_t> rootAddresses(parseAddresses(rootAddressesE));
+ vector<addr_t> rootAddresses(parseAddresses(rootAddressesE,
+ "root_addresses"));
ConstElementPtr forwardAddressesE(config->get("forward_addresses"));
- vector<addr_t> forwardAddresses(parseAddresses(forwardAddressesE));
+ vector<addr_t> forwardAddresses(parseAddresses(forwardAddressesE,
+ "forward_addresse"));
ConstElementPtr listenAddressesE(config->get("listen_on"));
- vector<addr_t> listenAddresses(parseAddresses(listenAddressesE));
+ vector<addr_t> listenAddresses(parseAddresses(listenAddressesE,
+ "listen_on"));
bool set_timeouts(false);
int qtimeout = impl_->query_timeout_;
int ctimeout = impl_->client_timeout_;
diff --git a/src/bin/resolver/tests/Makefile.am b/src/bin/resolver/tests/Makefile.am
index a03439c..1c7f248 100644
--- a/src/bin/resolver/tests/Makefile.am
+++ b/src/bin/resolver/tests/Makefile.am
@@ -37,6 +37,7 @@ run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
run_unittests_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
+run_unittests_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
# Note the ordering matters: -Wno-... must follow -Wextra (defined in
# B10_CXXFLAGS
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 8ab93ba..0b4cbb5 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -1,2 +1,2 @@
SUBDIRS = exceptions dns cc config datasrc python xfr bench log \
- resolve asiolink testutils nsas cache
+ resolve asiolink testutils nsas cache server_common
diff --git a/src/lib/server_common/Makefile.am b/src/lib/server_common/Makefile.am
new file mode 100644
index 0000000..9ba3d77
--- /dev/null
+++ b/src/lib/server_common/Makefile.am
@@ -0,0 +1,25 @@
+SUBDIRS = . tests
+
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CXXFLAGS = $(B10_CXXFLAGS)
+
+# Some versions of GCC warn about some versions of Boost regarding
+# missing initializer for members in its posix_time.
+# https://svn.boost.org/trac/boost/ticket/3477
+# But older GCC compilers don't have the flag.
+AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
+
+if USE_CLANGPP
+# clang++ complains about unused function parameters in some boost header
+# files.
+AM_CXXFLAGS += -Wno-unused-parameter
+endif
+
+lib_LTLIBRARIES = libserver_common.la
+libserver_common_la_SOURCES = portconfig.h portconfig.cc
+libserver_common_la_LIBADD = $(top_builddir)/src/lib/exceptions/libexceptions.la
+libserver_common_la_LIBADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
+libserver_common_la_LIBADD += $(top_builddir)/src/lib/cc/libcc.la
+
+CLEANFILES = *.gcno *.gcda
diff --git a/src/lib/server_common/portconfig.cc b/src/lib/server_common/portconfig.cc
new file mode 100644
index 0000000..2957c69
--- /dev/null
+++ b/src/lib/server_common/portconfig.cc
@@ -0,0 +1,66 @@
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include "portconfig.h"
+
+#include <asiolink/io_address.h>
+
+using namespace std;
+using namespace isc::data;
+using namespace asiolink;
+
+namespace isc {
+namespace server_common {
+namespace portconfig {
+
+std::vector<addr_t>
+parseAddresses(isc::data::ConstElementPtr addresses,
+ const std::string& elemName)
+{
+ vector<addr_t> result;
+ if (addresses) {
+ if (addresses->getType() == Element::list) {
+ for (size_t i(0); i < addresses->size(); ++ i) {
+ ConstElementPtr addrPair(addresses->get(i));
+ ConstElementPtr addr(addrPair->get("address"));
+ ConstElementPtr port(addrPair->get("port"));
+ if (!addr || ! port) {
+ isc_throw(BadValue, "Address must contain both the IP"
+ "address and port");
+ }
+ try {
+ IOAddress(addr->stringValue());
+ if (port->intValue() < 0 ||
+ port->intValue() > 0xffff) {
+ isc_throw(BadValue, "Bad port value (" <<
+ port->intValue() << ")");
+ }
+ result.push_back(addr_t(addr->stringValue(),
+ port->intValue()));
+ }
+ catch (const TypeError &e) { // Better error message
+ isc_throw(TypeError,
+ "Address must be a string and port an integer");
+ }
+ }
+ } else if (addresses->getType() != Element::null) {
+ isc_throw(TypeError, elemName + " config element must be a list");
+ }
+ }
+ return (result);
+}
+
+}
+}
+}
diff --git a/src/lib/server_common/portconfig.h b/src/lib/server_common/portconfig.h
new file mode 100644
index 0000000..6d8c2fb
--- /dev/null
+++ b/src/lib/server_common/portconfig.h
@@ -0,0 +1,83 @@
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef ISC_SERVER_COMMON_PORTCONFIG_H
+#define ISC_SERVER_COMMON_PORTCONFIG_H
+
+#include <utility>
+#include <string>
+#include <stdint.h>
+#include <vector>
+
+#include <cc/data.h>
+
+namespace isc {
+namespace server_common {
+/**
+ * \brief Utilities to configure ports and addresses.
+ *
+ * Here are some utilities to help a server to parse configuration of addresses
+ * and ports and install the configuration.
+ */
+namespace portconfig {
+
+/**
+ * \brief An address-port pair.
+ *
+ * It is just a pair of string for an address and unsigned integer for port
+ * number. Anything more fancy would be an overkill, it is used only to pass
+ * the addresses and ports around as intermediate results.
+ */
+typedef std::pair<std::string, uint16_t> addr_t;
+
+/**
+ * \brief
+ *
+ * This parses a list of address-port configurations and returns them. The
+ * configuration looks like this:
+ *
+ * \verbatim
+[
+ {
+ "address": "192.0.2.1",
+ "port": 13
+ },
+ {
+ "address": "::",
+ "port": 80
+ }
+]
+ * \endverbatim
+ * \param addresses The configuration element to parse (the list). Empty list,
+ * null element and null pointer all mean empty list of addresses.
+ * \param elemName The name of the element, used to create descriptions for
+ * exceptions.
+ * \return Vector of parsed address-port pairs found in the configuration.
+ * \throw isc::data::TypeError if something in the configuration is of a wrong
+ * type (string passed to a port, element in the list that isn't hash,
+ * etc).
+ * \throw asiolink::IOError if the provided address string can't be parsed.
+ * \throw BadValue for other invalid configurations (missing port or address
+ * element in the hash, port number out of range).
+ * \throw std::bad_alloc when allocation fails.
+ */
+std::vector<addr_t>
+parseAddresses(isc::data::ConstElementPtr addresses,
+ const std::string& elemName);
+
+}
+}
+}
+
+#endif
diff --git a/src/lib/server_common/tests/Makefile.am b/src/lib/server_common/tests/Makefile.am
new file mode 100644
index 0000000..22fe104
--- /dev/null
+++ b/src/lib/server_common/tests/Makefile.am
@@ -0,0 +1,38 @@
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -I$(top_srcdir)/src/lib/server_common
+AM_CPPFLAGS += -I$(top_builddir)/src/lib/server_common
+AM_CXXFLAGS = $(B10_CXXFLAGS)
+
+AM_LDFLAGS =
+if USE_STATIC_LINK
+AM_LDFLAGS += -static
+endif
+
+# Some versions of GCC warn about some versions of Boost regarding
+# missing initializer for members in its posix_time.
+# https://svn.boost.org/trac/boost/ticket/3477
+# But older GCC compilers don't have the flag.
+AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
+
+if USE_CLANGPP
+# see ../Makefile.am
+AM_CXXFLAGS += -Wno-unused-parameter
+endif
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = run_unittests.cc
+run_unittests_SOURCES += portconfig_unittest.cc
+
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+run_unittests_LDADD = $(GTEST_LDADD)
+
+run_unittests_LDADD += $(top_builddir)/src/lib/server_common/libserver_common.la
+endif
+
+noinst_PROGRAMS = $(TESTS)
diff --git a/src/lib/server_common/tests/run_unittests.cc b/src/lib/server_common/tests/run_unittests.cc
new file mode 100644
index 0000000..7ebc985
--- /dev/null
+++ b/src/lib/server_common/tests/run_unittests.cc
@@ -0,0 +1,26 @@
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <config.h>
+
+#include <gtest/gtest.h>
+
+#include <dns/tests/unittest_util.h>
+
+int
+main(int argc, char* argv[]) {
+ ::testing::InitGoogleTest(&argc, argv);
+
+ return (RUN_ALL_TESTS());
+}
More information about the bind10-changes
mailing list