Browse Source

[trac749] refactor C++ utility library

chenzhengzhang 14 years ago
parent
commit
f6aa7d5956
100 changed files with 235 additions and 1281 deletions
  1. 2 0
      configure.ac
  2. 3 1
      src/bin/auth/auth_srv.cc
  3. 1 1
      src/bin/auth/auth_srv.h
  4. 2 1
      src/bin/auth/benchmarks/query_bench.cc
  5. 3 1
      src/bin/auth/main.cc
  6. 1 0
      src/bin/auth/tests/auth_srv_unittest.cc
  7. 3 1
      src/bin/host/host.cc
  8. 1 1
      src/bin/resolver/main.cc
  9. 3 1
      src/bin/resolver/resolver.cc
  10. 1 1
      src/bin/resolver/resolver.h
  11. 2 2
      src/lib/Makefile.am
  12. 0 2
      src/lib/asiolink/Makefile.am
  13. 0 61
      src/lib/asiolink/asiolink_utilities.h
  14. 1 1
      src/lib/asiolink/dns_answer.h
  15. 2 2
      src/lib/asiolink/dns_lookup.h
  16. 3 3
      src/lib/asiolink/io_asio_socket.h
  17. 9 7
      src/lib/asiolink/io_fetch.cc
  18. 2 2
      src/lib/asiolink/io_fetch.h
  19. 0 54
      src/lib/asiolink/qid_gen.cc
  20. 0 85
      src/lib/asiolink/qid_gen.h
  21. 3 0
      src/lib/asiolink/tcp_server.cc
  22. 1 1
      src/lib/asiolink/tcp_server.h
  23. 7 7
      src/lib/asiolink/tcp_socket.h
  24. 2 2
      src/lib/asiolink/tests/Makefile.am
  25. 0 74
      src/lib/asiolink/tests/asiolink_utilities_unittest.cc
  26. 2 2
      src/lib/asiolink/tests/dns_server_unittest.cc
  27. 4 2
      src/lib/asiolink/tests/io_fetch_unittest.cc
  28. 0 59
      src/lib/asiolink/tests/qid_gen_unittest.cc
  29. 3 3
      src/lib/asiolink/tests/tcp_socket_unittest.cc
  30. 3 3
      src/lib/asiolink/tests/udp_socket_unittest.cc
  31. 2 1
      src/lib/asiolink/udp_server.cc
  32. 2 2
      src/lib/asiolink/udp_socket.h
  33. 2 1
      src/lib/bench/benchmark_util.cc
  34. 1 0
      src/lib/bench/tests/Makefile.am
  35. 2 1
      src/lib/bench/tests/loadquery_unittest.cc
  36. 1 0
      src/lib/cache/Makefile.am
  37. 2 2
      src/lib/cache/message_cache.h
  38. 3 2
      src/lib/cache/rrset_cache.h
  39. 2 0
      src/lib/cache/tests/Makefile.am
  40. 2 2
      src/lib/cache/tests/cache_test_messagefromfile.h
  41. 1 1
      src/lib/cache/tests/cache_test_sectioncount.h
  42. 2 1
      src/lib/cache/tests/message_cache_unittest.cc
  43. 1 1
      src/lib/cache/tests/message_entry_unittest.cc
  44. 5 3
      src/lib/datasrc/data_source.cc
  45. 3 1
      src/lib/datasrc/tests/datasrc_unittest.cc
  46. 5 9
      src/lib/dns/Makefile.am
  47. 0 446
      src/lib/dns/buffer.h
  48. 0 211
      src/lib/dns/dnssectime.cc
  49. 0 145
      src/lib/dns/dnssectime.h
  50. 1 0
      src/lib/dns/edns.cc
  51. 5 1
      src/lib/dns/edns.h
  52. 2 1
      src/lib/dns/message.cc
  53. 6 3
      src/lib/dns/message.h
  54. 3 1
      src/lib/dns/messagerenderer.cc
  55. 5 2
      src/lib/dns/messagerenderer.h
  56. 2 1
      src/lib/dns/name.cc
  57. 6 3
      src/lib/dns/name.h
  58. 1 0
      src/lib/dns/python/edns_python.cc
  59. 1 0
      src/lib/dns/python/message_python.cc
  60. 1 0
      src/lib/dns/python/messagerenderer_python.cc
  61. 1 0
      src/lib/dns/python/name_python.cc
  62. 1 1
      src/lib/dns/python/pydnspp.cc
  63. 1 0
      src/lib/dns/python/rdata_python.cc
  64. 1 0
      src/lib/dns/python/rrclass_python.cc
  65. 1 0
      src/lib/dns/python/rrset_python.cc
  66. 1 0
      src/lib/dns/python/rrttl_python.cc
  67. 1 0
      src/lib/dns/python/rrtype_python.cc
  68. 2 1
      src/lib/dns/question.cc
  69. 7 3
      src/lib/dns/question.h
  70. 2 1
      src/lib/dns/rdata.cc
  71. 7 5
      src/lib/dns/rdata.h
  72. 4 2
      src/lib/dns/rdata/any_255/tsig_250.cc
  73. 2 1
      src/lib/dns/rdata/ch_3/a_1.cc
  74. 2 1
      src/lib/dns/rdata/generic/cname_5.cc
  75. 2 1
      src/lib/dns/rdata/generic/dname_39.cc
  76. 3 2
      src/lib/dns/rdata/generic/dnskey_48.cc
  77. 4 2
      src/lib/dns/rdata/generic/ds_43.cc
  78. 2 1
      src/lib/dns/rdata/generic/mx_15.cc
  79. 2 1
      src/lib/dns/rdata/generic/ns_2.cc
  80. 5 3
      src/lib/dns/rdata/generic/nsec3_50.cc
  81. 3 2
      src/lib/dns/rdata/generic/nsec3param_51.cc
  82. 3 2
      src/lib/dns/rdata/generic/nsec_47.cc
  83. 2 1
      src/lib/dns/rdata/generic/opt_41.cc
  84. 2 1
      src/lib/dns/rdata/generic/ptr_12.cc
  85. 4 3
      src/lib/dns/rdata/generic/rrsig_46.cc
  86. 2 1
      src/lib/dns/rdata/generic/soa_6.cc
  87. 2 1
      src/lib/dns/rdata/generic/txt_16.cc
  88. 2 1
      src/lib/dns/rdata/hs_4/a_1.cc
  89. 2 1
      src/lib/dns/rdata/in_1/a_1.cc
  90. 2 1
      src/lib/dns/rdata/in_1/aaaa_28.cc
  91. 2 1
      src/lib/dns/rdata/template.cc
  92. 2 1
      src/lib/dns/rrclass.cc
  93. 2 2
      src/lib/dns/rrparamregistry.h
  94. 2 1
      src/lib/dns/rrset.cc
  95. 6 3
      src/lib/dns/rrset.h
  96. 2 1
      src/lib/dns/rrttl.cc
  97. 7 4
      src/lib/dns/rrttl.h
  98. 2 2
      src/lib/dns/rrtype.cc
  99. 2 6
      src/lib/dns/tests/Makefile.am
  100. 0 0
      src/lib/dns/tests/base32hex_unittest.cc

+ 2 - 0
configure.ac

@@ -677,6 +677,8 @@ AC_CONFIG_FILES([Makefile
                  src/lib/datasrc/Makefile
                  src/lib/datasrc/tests/Makefile
                  src/lib/xfr/Makefile
+                 src/lib/util/Makefile
+                 src/lib/util/tests/Makefile
                  src/lib/log/Makefile
                  src/lib/log/compiler/Makefile
                  src/lib/log/tests/Makefile

+ 3 - 1
src/bin/auth/auth_srv.cc

@@ -31,7 +31,8 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+
 #include <dns/edns.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
@@ -63,6 +64,7 @@ using namespace isc;
 using namespace isc::cc;
 using namespace isc::datasrc;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::auth;
 using namespace isc::dns::rdata;
 using namespace isc::data;

+ 1 - 1
src/bin/auth/auth_srv.h

@@ -109,7 +109,7 @@ public:
     /// \throw isc::Unexpected Protocol type of \a message is unexpected
     void processMessage(const asiolink::IOMessage& io_message,
                         isc::dns::MessagePtr message,
-                        isc::dns::OutputBufferPtr buffer,
+                        isc::util::OutputBufferPtr buffer,
                         asiolink::DNSServer* server);
 
     /// \brief Set verbose flag

+ 2 - 1
src/bin/auth/benchmarks/query_bench.cc

@@ -22,7 +22,7 @@
 #include <bench/benchmark.h>
 #include <bench/benchmark_util.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/message.h>
 #include <dns/name.h>
 #include <dns/question.h>
@@ -41,6 +41,7 @@ using namespace isc;
 using namespace isc::data;
 using namespace isc::auth;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::xfr;
 using namespace isc::bench;
 using namespace asiolink;

+ 3 - 1
src/bin/auth/main.cc

@@ -25,7 +25,8 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+
 #include <dns/message.h>
 #include <dns/messagerenderer.h>
 
@@ -49,6 +50,7 @@ using namespace isc::data;
 using namespace isc::cc;
 using namespace isc::config;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::xfr;
 using namespace asiolink;
 

+ 1 - 0
src/bin/auth/tests/auth_srv_unittest.cc

@@ -41,6 +41,7 @@
 using namespace std;
 using namespace isc::cc;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::dns::rdata;
 using namespace isc::data;
 using namespace isc::xfr;

+ 3 - 1
src/bin/host/host.cc

@@ -24,7 +24,8 @@
 #include <string>
 #include <iostream>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+
 #include <dns/name.h>
 #include <dns/message.h>
 #include <dns/messagerenderer.h>
@@ -37,6 +38,7 @@
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 
 namespace {
 char* dns_type = NULL;    // not set, so A, AAAA, MX

+ 1 - 1
src/bin/resolver/main.cc

@@ -29,7 +29,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/rcode.h>
 #include <dns/message.h>
 #include <dns/messagerenderer.h>

+ 3 - 1
src/bin/resolver/resolver.cc

@@ -29,9 +29,10 @@
 
 #include <exceptions/exceptions.h>
 
+#include <util/buffer.h>
+
 #include <dns/opcode.h>
 #include <dns/rcode.h>
-#include <dns/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/name.h>
 #include <dns/question.h>
@@ -50,6 +51,7 @@
 using namespace std;
 
 using namespace isc;
+using namespace isc::util;
 using namespace isc::dns;
 using namespace isc::data;
 using namespace isc::config;

+ 1 - 1
src/bin/resolver/resolver.h

@@ -77,7 +77,7 @@ public:
     void processMessage(const asiolink::IOMessage& io_message,
                         isc::dns::MessagePtr query_message,
                         isc::dns::MessagePtr answer_message,
-                        isc::dns::OutputBufferPtr buffer,
+                        isc::util::OutputBufferPtr buffer,
                         asiolink::DNSServer* server);
 
     /// \brief Set and get the config session

+ 2 - 2
src/lib/Makefile.am

@@ -1,2 +1,2 @@
-SUBDIRS = exceptions dns cc config python xfr bench log asiolink \
-          nsas cache resolve testutils datasrc server_common
+SUBDIRS = exceptions util dns cc config python xfr bench log \
+          asiolink nsas cache resolve testutils datasrc server_common

+ 0 - 2
src/lib/asiolink/Makefile.am

@@ -13,7 +13,6 @@ CLEANFILES = *.gcno *.gcda
 # which would make the build fail with -Werror (our default setting).
 lib_LTLIBRARIES = libasiolink.la
 libasiolink_la_SOURCES  = asiolink.h
-libasiolink_la_SOURCES += asiolink_utilities.h
 libasiolink_la_SOURCES += asiodef.cc asiodef.h
 libasiolink_la_SOURCES += dns_answer.h
 libasiolink_la_SOURCES += dns_lookup.h
@@ -27,7 +26,6 @@ libasiolink_la_SOURCES += io_endpoint.cc io_endpoint.h
 libasiolink_la_SOURCES += io_error.h
 libasiolink_la_SOURCES += io_fetch.cc io_fetch.h
 libasiolink_la_SOURCES += io_message.h
-libasiolink_la_SOURCES += qid_gen.cc qid_gen.h
 libasiolink_la_SOURCES += io_service.h io_service.cc
 libasiolink_la_SOURCES += io_socket.h io_socket.cc
 libasiolink_la_SOURCES += simple_callback.h

+ 0 - 61
src/lib/asiolink/asiolink_utilities.h

@@ -1,61 +0,0 @@
-// 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 __ASIOLINK_UTILITIES_H
-#define __ASIOLINK_UTILITIES_H
-
-#include <cstddef>
-
-namespace asiolink {
-
-/// \brief Read Unsigned 16-Bit Integer from Buffer
-///
-/// This is essentially a copy of the isc::dns::InputBuffer::readUint16.  It
-/// should really be moved into a separate library.
-///
-/// \param buffer Data buffer at least two bytes long of which the first two
-///        bytes are assumed to represent a 16-bit integer in network-byte
-///        order.
-///
-/// \return Value of 16-bit integer
-inline uint16_t
-readUint16(const void* buffer) {
-    const uint8_t* byte_buffer = static_cast<const uint8_t*>(buffer);
-
-    uint16_t result = (static_cast<uint16_t>(byte_buffer[0])) << 8;
-    result |= static_cast<uint16_t>(byte_buffer[1]);
-
-    return (result);
-}
-
-/// \brief Write Unisgned 16-Bit Integer to Buffer
-///
-/// This is essentially a copy of isc::dns::OutputBuffer::writeUint16.  It
-/// should really be moved into a separate library.
-///
-/// \param value 16-bit value to convert
-/// \param buffer Data buffer at least two bytes long into which the 16-bit
-///        value is written in network-byte order.
-
-inline void
-writeUint16(uint16_t value, void* buffer) {
-    uint8_t* byte_buffer = static_cast<uint8_t*>(buffer);
-
-    byte_buffer[0] = static_cast<uint8_t>((value & 0xff00U) >> 8);
-    byte_buffer[1] = static_cast<uint8_t>(value & 0x00ffU);
-}
-
-} // namespace asiolink
-
-#endif // __ASIOLINK_UTILITIES_H

+ 1 - 1
src/lib/asiolink/dns_answer.h

@@ -66,7 +66,7 @@ public:
     virtual void operator()(const IOMessage& io_message,
                             isc::dns::MessagePtr query_message,
                             isc::dns::MessagePtr answer_message,
-                            isc::dns::OutputBufferPtr buffer) const = 0;
+                            isc::util::OutputBufferPtr buffer) const = 0;
 };
 
 }      // namespace asiolink

+ 2 - 2
src/lib/asiolink/dns_lookup.h

@@ -17,7 +17,7 @@
 
 #include <asiolink/io_message.h>
 #include <asiolink/dns_server.h>
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/message.h>
 
 namespace asiolink {
@@ -70,7 +70,7 @@ public:
     virtual void operator()(const IOMessage& io_message,
                             isc::dns::MessagePtr message,
                             isc::dns::MessagePtr answer_message,
-                            isc::dns::OutputBufferPtr buffer,
+                            isc::util::OutputBufferPtr buffer,
                             DNSServer* server) const
     {
         (*self_)(io_message, message, answer_message, buffer, server);

+ 3 - 3
src/lib/asiolink/io_asio_socket.h

@@ -26,7 +26,7 @@
 #include <exceptions/exceptions.h>
 #include <coroutine.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 
 #include <asiolink/io_error.h>
 #include <asiolink/io_socket.h>
@@ -270,7 +270,7 @@ public:
     virtual bool processReceivedData(const void* staging, size_t length,
                                      size_t& cumulative, size_t& offset,
                                      size_t& expected,
-                                     isc::dns::OutputBufferPtr& outbuff) = 0;
+                                     isc::util::OutputBufferPtr& outbuff) = 0;
 
     /// \brief Cancel I/O On AsioSocket
     virtual void cancel() = 0;
@@ -372,7 +372,7 @@ public:
     virtual bool receiveComplete(const void* staging, size_t length,
                                  size_t& cumulative, size_t& offset,
                                  size_t& expected,
-                                 isc::dns::OutputBufferPtr& outbuff)
+                                 isc::util::OutputBufferPtr& outbuff)
     {
         return (true);
     }

+ 9 - 7
src/lib/asiolink/io_fetch.cc

@@ -22,13 +22,16 @@
 #include <boost/scoped_ptr.hpp>
 #include <boost/date_time/posix_time/posix_time_types.hpp>
 
+#include <util/buffer.h>
+
 #include <dns/message.h>
 #include <dns/messagerenderer.h>
 #include <dns/opcode.h>
 #include <dns/rcode.h>
 #include <log/logger.h>
 
-#include <asiolink/qid_gen.h>
+#include <util/qid_gen.h>
+#include <util/qid_gen.h>
 
 #include <asio.hpp>
 #include <asio/deadline_timer.hpp>
@@ -43,12 +46,12 @@
 #include <asiolink/tcp_socket.h>
 #include <asiolink/udp_endpoint.h>
 #include <asiolink/udp_socket.h>
-#include <asiolink/qid_gen.h>
 
 #include <stdint.h>
 
 using namespace asio;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::log;
 using namespace std;
 
@@ -76,8 +79,8 @@ struct IOFetchData {
     boost::scoped_ptr<IOEndpoint> remote_snd;///< Where the fetch is sent
     boost::scoped_ptr<IOEndpoint> remote_rcv;///< Where the response came from
     isc::dns::Question          question;    ///< Question to be asked
-    isc::dns::OutputBufferPtr   msgbuf;      ///< Wire buffer for question
-    isc::dns::OutputBufferPtr   received;    ///< Received data put here
+    OutputBufferPtr   msgbuf;      ///< Wire buffer for question
+    OutputBufferPtr   received;    ///< Received data put here
     IOFetch::Callback*          callback;    ///< Called on I/O Completion
     asio::deadline_timer        timer;       ///< Timer to measure timeouts
     IOFetch::Protocol           protocol;    ///< Protocol being used
@@ -117,8 +120,7 @@ struct IOFetchData {
     /// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
     IOFetchData(IOFetch::Protocol proto, IOService& service,
         const isc::dns::Question& query, const IOAddress& address,
-        uint16_t port, isc::dns::OutputBufferPtr& buff, IOFetch::Callback* cb,
-        int wait)
+        uint16_t port, OutputBufferPtr& buff, IOFetch::Callback* cb, int wait)
         :
         socket((proto == IOFetch::UDP) ?
             static_cast<IOAsioSocket<IOFetch>*>(
@@ -135,7 +137,7 @@ struct IOFetchData {
             static_cast<IOEndpoint*>(new TCPEndpoint(address, port))
             ),
         question(query),
-        msgbuf(new isc::dns::OutputBuffer(512)),
+        msgbuf(new OutputBuffer(512)),
         received(buff),
 
         callback(cb),

+ 2 - 2
src/lib/asiolink/io_fetch.h

@@ -25,7 +25,7 @@
 
 #include <asio/error_code.hpp>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/question.h>
 
 namespace asiolink {
@@ -134,7 +134,7 @@ public:
     ///     -1 indicates no timeout.
     IOFetch(Protocol protocol, IOService& service,
         const isc::dns::Question& question, const IOAddress& address,
-        uint16_t port, isc::dns::OutputBufferPtr& buff, Callback* cb,
+        uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
         int wait = -1);
 
     /// \brief Return Current Protocol

+ 0 - 54
src/lib/asiolink/qid_gen.cc

@@ -1,54 +0,0 @@
-// 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.
-
-// qid_gen defines a generator for query id's
-//
-// We probably want to merge this with the weighted random in the nsas
-// (and other parts where we need randomness, perhaps another thing
-// for a general libutil?)
-
-#include <asiolink/qid_gen.h>
-
-#include <sys/time.h>
-
-namespace {
-    asiolink::QidGenerator qid_generator_instance;
-}
-
-namespace asiolink {
-
-QidGenerator&
-QidGenerator::getInstance() {
-    return (qid_generator_instance);
-}
-
-QidGenerator::QidGenerator() : dist_(0, 65535),
-                               vgen_(generator_, dist_)
-{
-    seed();
-}
-
-void
-QidGenerator::seed() {
-    struct timeval tv;
-    gettimeofday(&tv, 0);
-    generator_.seed((tv.tv_sec * 1000000) + tv.tv_usec);
-}
-
-isc::dns::qid_t
-QidGenerator::generateQid() {
-    return (vgen_());
-}
-
-} // namespace asiolink

+ 0 - 85
src/lib/asiolink/qid_gen.h

@@ -1,85 +0,0 @@
-// 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.
-
-// qid_gen defines a generator for query id's
-//
-// We probably want to merge this with the weighted random in the nsas
-// (and other parts where we need randomness, perhaps another thing
-// for a general libutil?)
-
-#ifndef __QID_GEN_H
-#define __QID_GEN_H
-
-#include <dns/message.h>
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_int.hpp>
-#include <boost/random/variate_generator.hpp>
-
-
-namespace asiolink {
-
-/// This class generates Qids for outgoing queries
-///
-/// It is implemented as a singleton; the public way to access it
-/// is to call getInstance()->generateQid().
-///
-/// It automatically seeds it with the current time when it is first
-/// used.
-class QidGenerator {
-public:
-    /// \brief Returns the singleton instance of the QidGenerator
-    ///
-    /// Returns a reference to the singleton instance of the generator
-    static QidGenerator& getInstance();
-
-    /// \brief Default constructor
-    ///
-    /// It is recommended that getInstance is used rather than creating
-    /// separate instances of this class.
-    ///
-    /// The constructor automatically seeds the generator with the
-    /// current time.
-    QidGenerator();
-
-    /// Generate a Qid
-    ///
-    /// \return A random Qid
-    isc::dns::qid_t generateQid();
-
-    /// \brief Seeds the QidGenerator (based on the current time)
-    ///
-    /// This is automatically called by the constructor
-    void seed();
-
-private:
-    // "Mersenne Twister: A 623-dimensionally equidistributed
-    // uniform pseudo-random number generator", Makoto Matsumoto and
-    // Takuji Nishimura, ACM Transactions on Modeling and Computer
-    // Simulation: Special Issue on Uniform Random Number Generation,
-    // Vol. 8, No. 1, January 1998, pp. 3-30.
-    //
-    // mt19937 is an implementation of one of the pseudo random
-    // generators described in this paper.
-    boost::mt19937 generator_;
-
-    // For qid's we want a uniform distribution
-    boost::uniform_int<> dist_;
-
-    boost::variate_generator<boost::mt19937&, boost::uniform_int<> > vgen_;
-};
-
-
-} // namespace asiolink
-
-#endif // __QID_GEN_H

+ 3 - 0
src/lib/asiolink/tcp_server.cc

@@ -23,6 +23,8 @@
 
 #include <log/dummylog.h>
 
+#include <util/buffer.h>
+
 #include <asio.hpp>
 #include <asiolink/dummy_io_cb.h>
 #include <asiolink/tcp_endpoint.h>
@@ -36,6 +38,7 @@ using asio::ip::tcp;
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 
 namespace asiolink {
 

+ 1 - 1
src/lib/asiolink/tcp_server.h

@@ -91,7 +91,7 @@ private:
     boost::shared_ptr<asio::ip::tcp::socket> socket_;
 
     // The buffer into which the response is written
-    boost::shared_ptr<isc::dns::OutputBuffer> respbuf_;
+    boost::shared_ptr<isc::util::OutputBuffer> respbuf_;
 
     // \c IOMessage and \c Message objects to be passed to the
     // DNS lookup and answer providers

+ 7 - 7
src/lib/asiolink/tcp_socket.h

@@ -33,9 +33,9 @@
 
 #include <config.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+#include <util/asiolink_utilities.h>
 
-#include <asiolink/asiolink_utilities.h>
 #include <asiolink/io_asio_socket.h>
 #include <asiolink/io_endpoint.h>
 #include <asiolink/io_service.h>
@@ -155,7 +155,7 @@ public:
     virtual bool processReceivedData(const void* staging, size_t length,
                                      size_t& cumulative, size_t& offset,
                                      size_t& expected,
-                                     isc::dns::OutputBufferPtr& outbuff);
+                                     isc::util::OutputBufferPtr& outbuff);
 
     /// \brief Cancel I/O On Socket
     virtual void cancel();
@@ -185,7 +185,7 @@ private:
     // The option of sending the data in two operations, the count followed by
     // the data was discounted as that would lead to two callbacks which would
     // cause problems with the stackless coroutine code.
-    isc::dns::OutputBufferPtr   send_buffer_;   ///< Send buffer
+    isc::util::OutputBufferPtr   send_buffer_;   ///< Send buffer
 };
 
 // Constructor - caller manages socket
@@ -268,7 +268,7 @@ TCPSocket<C>::asyncSend(const void* data, size_t length,
             uint16_t count = boost::numeric_cast<uint16_t>(length);
 
             // Copy data into a buffer preceded by the count field.
-            send_buffer_.reset(new isc::dns::OutputBuffer(length + 2));
+            send_buffer_.reset(new isc::util::OutputBuffer(length + 2));
             send_buffer_->writeUint16(count);
             send_buffer_->writeData(data, length);
 
@@ -333,7 +333,7 @@ template <typename C> bool
 TCPSocket<C>::processReceivedData(const void* staging, size_t length,
                                   size_t& cumulative, size_t& offset,
                                   size_t& expected,
-                                  isc::dns::OutputBufferPtr& outbuff)
+                                  isc::util::OutputBufferPtr& outbuff)
 {
     // Point to the data in the staging buffer and note how much there is.
     const uint8_t* data = static_cast<const uint8_t*>(staging);
@@ -358,7 +358,7 @@ TCPSocket<C>::processReceivedData(const void* staging, size_t length,
         }
 
         // Have enough data to interpret the packet count, so do so now.
-        expected = readUint16(data);
+        expected = isc::util::readUint16(data);
 
         // We have two bytes less of data to process.  Point to the start of the
         // data and adjust the packet size.  Note that at this point,

+ 2 - 2
src/lib/asiolink/tests/Makefile.am

@@ -1,6 +1,7 @@
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/bin
+AM_CPPFLAGS += -I$(top_builddir)/src/lib/util -I$(top_srcdir)/src/util
 AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc
 AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(srcdir)/testdata\"
 
@@ -18,7 +19,6 @@ TESTS += run_unittests
 run_unittests_SOURCES  = run_unittests.cc
 run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.h
 run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.cc
-run_unittests_SOURCES += asiolink_utilities_unittest.cc
 run_unittests_SOURCES += io_address_unittest.cc
 run_unittests_SOURCES += io_endpoint_unittest.cc
 run_unittests_SOURCES += io_fetch_unittest.cc
@@ -30,7 +30,6 @@ run_unittests_SOURCES += tcp_socket_unittest.cc
 run_unittests_SOURCES += udp_endpoint_unittest.cc
 run_unittests_SOURCES += udp_socket_unittest.cc
 run_unittests_SOURCES += dns_server_unittest.cc
-run_unittests_SOURCES += qid_gen_unittest.cc
 
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 
@@ -38,6 +37,7 @@ run_unittests_LDADD  = $(GTEST_LDADD)
 run_unittests_LDADD += $(SQLITE_LIBS)
 run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
 run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/libutil.la
 run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
 run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
 

+ 0 - 74
src/lib/asiolink/tests/asiolink_utilities_unittest.cc

@@ -1,74 +0,0 @@
-// 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.
-
-/// \brief Test of asiolink utilties
-///
-/// Tests the fuctionality of the asiolink utilities code by comparing them
-/// with the equivalent methods in isc::dns::[Input/Output]Buffer.
-
-#include <cstddef>
-
-#include <gtest/gtest.h>
-
-#include <dns/buffer.h>
-#include <asiolink/asiolink_utilities.h>
-
-using namespace asiolink;
-using namespace isc::dns;
-
-TEST(asioutil, readUint16) {
-
-    // Reference buffer
-    uint8_t data[2];
-    isc::dns::InputBuffer buffer(data, sizeof(data));
-
-    // Avoid possible compiler warnings by only setting uint8_t variables to
-    // uint8_t values.
-    uint8_t i8 = 0;
-    uint8_t j8 = 0;
-    for (int i = 0; i < (2 << 8); ++i, ++i8) {
-        for (int j = 0; j < (2 << 8); ++j, ++j8) {
-            data[0] = i8;
-            data[1] = j8;
-            buffer.setPosition(0);
-            EXPECT_EQ(buffer.readUint16(), readUint16(data));
-        }
-    }
-}
-
-
-TEST(asioutil, writeUint16) {
-
-    // Reference buffer
-    isc::dns::OutputBuffer buffer(2);
-    uint8_t test[2];
-
-    // Avoid possible compiler warnings by only setting uint16_t variables to
-    // uint16_t values.
-    uint16_t i16 = 0;
-    for (uint32_t i = 0; i < (2 << 16); ++i, ++i16) {
-
-        // Write the reference data
-        buffer.clear();
-        buffer.writeUint16(i16);
-
-        // ... and the test data
-        writeUint16(i16, test);
-
-        // ... and compare
-        const uint8_t* ref = static_cast<const uint8_t*>(buffer.getData());
-        EXPECT_EQ(ref[0], test[0]);
-        EXPECT_EQ(ref[1], test[1]);
-    }
-}

+ 2 - 2
src/lib/asiolink/tests/dns_server_unittest.cc

@@ -109,7 +109,7 @@ class DummyLookup : public DNSLookup, public ServerStopper {
         void operator()(const IOMessage& io_message,
                 isc::dns::MessagePtr message,
                 isc::dns::MessagePtr answer_message,
-                isc::dns::OutputBufferPtr buffer,
+                isc::util::OutputBufferPtr buffer,
                 DNSServer* server) const {
             stopServer();
             server->resume(true);
@@ -123,7 +123,7 @@ class SimpleAnswer : public DNSAnswer, public ServerStopper {
         void operator()(const IOMessage& message,
                 isc::dns::MessagePtr query_message,
                 isc::dns::MessagePtr answer_message,
-                isc::dns::OutputBufferPtr buffer) const
+                isc::util::OutputBufferPtr buffer) const
         {
             //copy what we get from user
             buffer->writeData(message.getData(), message.getDataSize());

+ 4 - 2
src/lib/asiolink/tests/io_fetch_unittest.cc

@@ -26,7 +26,9 @@
 
 #include <asio.hpp>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+#include <util/asiolink_utilities.h>
+
 #include <dns/question.h>
 #include <dns/message.h>
 #include <dns/messagerenderer.h>
@@ -34,7 +36,6 @@
 #include <dns/name.h>
 #include <dns/rcode.h>
 
-#include <asiolink/asiolink_utilities.h>
 #include <asiolink/io_address.h>
 #include <asiolink/io_endpoint.h>
 #include <asiolink/io_fetch.h>
@@ -42,6 +43,7 @@
 
 using namespace asio;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace asio::ip;
 using namespace std;
 

+ 0 - 59
src/lib/asiolink/tests/qid_gen_unittest.cc

@@ -1,59 +0,0 @@
-// 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.
-
-// 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.
-
-
-/// \brief Test of QidGenerator
-///
-
-#include <gtest/gtest.h>
-
-#include <asiolink/qid_gen.h>
-#include <dns/message.h>
-
-// Tests the operation of the Qid generator
-
-// Check that getInstance returns a singleton
-TEST(QidGenerator, singleton) {
-    asiolink::QidGenerator& g1 = asiolink::QidGenerator::getInstance();
-    asiolink::QidGenerator& g2 = asiolink::QidGenerator::getInstance();
-
-    EXPECT_TRUE(&g1 == &g2);
-}
-
-TEST(QidGenerator, generate) {
-    // We'll assume that boost's generator is 'good enough', and won't
-    // do full statistical checking here. Let's just call it the xkcd
-    // test (http://xkcd.com/221/), and check if three consecutive
-    // generates are not all the same.
-    isc::dns::qid_t one, two, three;
-    asiolink::QidGenerator& gen = asiolink::QidGenerator::getInstance();
-    one = gen.generateQid();
-    two = gen.generateQid();
-    three = gen.generateQid();
-    ASSERT_FALSE((one == two) && (one == three));
-}

+ 3 - 3
src/lib/asiolink/tests/tcp_socket_unittest.cc

@@ -35,11 +35,11 @@
 #include <boost/bind.hpp>
 #include <boost/shared_ptr.hpp>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+#include <util/asiolink_utilities.h>
 
 #include <asio.hpp>
 
-#include <asiolink/asiolink_utilities.h>
 #include <asiolink/io_service.h>
 #include <asiolink/tcp_endpoint.h>
 #include <asiolink/tcp_socket.h>
@@ -47,7 +47,7 @@
 using namespace asio;
 using namespace asio::ip;
 using namespace asiolink;
-using namespace isc::dns;
+using namespace isc::util;
 using namespace std;
 
 namespace {

+ 3 - 3
src/lib/asiolink/tests/udp_socket_unittest.cc

@@ -35,18 +35,18 @@
 #include <boost/bind.hpp>
 #include <boost/shared_ptr.hpp>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+#include <util/asiolink_utilities.h>
 
 #include <asio.hpp>
 
-#include <asiolink/asiolink_utilities.h>
 #include <asiolink/io_service.h>
 #include <asiolink/udp_endpoint.h>
 #include <asiolink/udp_socket.h>
 
 using namespace asio;
 using namespace asiolink;
-using namespace isc::dns;
+using namespace isc::util;
 using namespace std;
 
 namespace {

+ 2 - 1
src/lib/asiolink/udp_server.cc

@@ -38,6 +38,7 @@ using isc::log::dlog;
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 
 namespace asiolink {
 
@@ -134,7 +135,7 @@ struct UDPServer::Data {
     isc::dns::MessagePtr answer_message_;
 
     // The buffer into which the response is written
-    isc::dns::OutputBufferPtr respbuf_;
+    isc::util::OutputBufferPtr respbuf_;
 
     // The buffer into which the query packet is written
     boost::shared_array<char> data_;

+ 2 - 2
src/lib/asiolink/udp_socket.h

@@ -141,7 +141,7 @@ public:
     virtual bool processReceivedData(const void* staging, size_t length,
                                      size_t& cumulative, size_t& offset,
                                      size_t& expected,
-                                     isc::dns::OutputBufferPtr& outbuff);
+                                     isc::util::OutputBufferPtr& outbuff);
 
     /// \brief Cancel I/O On Socket
     virtual void cancel();
@@ -283,7 +283,7 @@ template <typename C> bool
 UDPSocket<C>::processReceivedData(const void* staging, size_t length,
                                   size_t& cumulative, size_t& offset,
                                   size_t& expected,
-                                  isc::dns::OutputBufferPtr& outbuff)
+                                  isc::util::OutputBufferPtr& outbuff)
 {
     // Set return values to what we should expect.
     cumulative = length;

+ 2 - 1
src/lib/bench/benchmark_util.cc

@@ -19,7 +19,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/name.h>
 #include <dns/message.h>
@@ -35,6 +35,7 @@
 using namespace std;
 using namespace isc;
 using namespace isc::dns;
+using namespace isc::util;
 
 namespace isc {
 namespace bench {

+ 1 - 0
src/lib/bench/tests/Makefile.am

@@ -16,6 +16,7 @@ run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
 run_unittests_LDADD = $(top_builddir)/src/lib/exceptions/libexceptions.la
 run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/libutil.la
 run_unittests_LDADD += $(top_builddir)/src/lib/bench/libbench.la
 run_unittests_LDADD += $(GTEST_LDADD)
 endif

+ 2 - 1
src/lib/bench/tests/loadquery_unittest.cc

@@ -17,7 +17,7 @@
 #include <vector>
 #include <sstream>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/message.h>
 #include <dns/name.h>
 #include <dns/opcode.h>
@@ -32,6 +32,7 @@
 using namespace std;
 using namespace isc::bench;
 using namespace isc::dns;
+using namespace isc::util;
 
 namespace {
 typedef pair<string, string> QueryParam;

+ 1 - 0
src/lib/cache/Makefile.am

@@ -2,6 +2,7 @@ SUBDIRS = . tests
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES) $(MULTITHREADING_FLAG)
+AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/nsas -I$(top_builddir)/src/lib/nsas
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/cache -I$(top_builddir)/src/lib/cache

+ 2 - 2
src/lib/cache/message_cache.h

@@ -20,7 +20,7 @@
 #include <dns/message.h>
 #include "message_entry.h"
 #include <nsas/hash_table.h>
-#include <nsas/lru_list.h>
+#include <util/lru_list.h>
 #include "rrset_cache.h"
 
 namespace isc {
@@ -92,7 +92,7 @@ protected:
     RRsetCachePtr rrset_cache_;
     RRsetCachePtr negative_soa_cache_;
     isc::nsas::HashTable<MessageEntry> message_table_;
-    isc::nsas::LruList<MessageEntry> message_lru_;
+    isc::util::LruList<MessageEntry> message_lru_;
 };
 
 typedef boost::shared_ptr<MessageCache> MessageCachePtr;

+ 3 - 2
src/lib/cache/rrset_cache.h

@@ -17,7 +17,8 @@
 
 #include <cache/rrset_entry.h>
 #include <nsas/hash_table.h>
-#include <nsas/lru_list.h>
+
+#include <util/lru_list.h>
 
 using namespace isc::nsas;
 
@@ -98,7 +99,7 @@ public:
 protected:
     uint16_t class_; // The class of the rrset cache.
     isc::nsas::HashTable<RRsetEntry> rrset_table_;
-    isc::nsas::LruList<RRsetEntry> rrset_lru_;
+    isc::util::LruList<RRsetEntry> rrset_lru_;
 };
 
 typedef boost::shared_ptr<RRsetCache> RRsetCachePtr;

+ 2 - 0
src/lib/cache/tests/Makefile.am

@@ -2,6 +2,7 @@ SUBDIRS = .
 
 AM_CPPFLAGS  = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES) $(MULTITHREADING_FLAG)
+AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/cache -I$(top_builddir)/src/lib/cache
 AM_CPPFLAGS += -DTEST_DATA_SRCDIR=\"$(srcdir)/testdata\"
@@ -54,6 +55,7 @@ endif
 run_unittests_LDADD += $(top_builddir)/src/lib/cache/libcache.la
 run_unittests_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
 run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/libutil.la
 run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
 run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
 endif

+ 2 - 2
src/lib/cache/tests/cache_test_messagefromfile.h

@@ -14,7 +14,7 @@
 
 #include <vector>
 #include <dns/tests/unittest_util.h>
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/message.h>
 
 using namespace isc;
@@ -31,7 +31,7 @@ messageFromFile(Message& message, const char* datafile) {
     std::vector<unsigned char> data;
     UnitTestUtil::readWireData(datafile, data);
 
-    InputBuffer buffer(&data[0], data.size());
+    isc::util::InputBuffer buffer(&data[0], data.size());
     message.fromWire(buffer);
 }
 

+ 1 - 1
src/lib/cache/tests/cache_test_sectioncount.h

@@ -14,7 +14,7 @@
 
 #include <vector>
 #include <dns/tests/unittest_util.h>
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/message.h>
 
 using namespace isc;

+ 2 - 1
src/lib/cache/tests/message_cache_unittest.cc

@@ -16,7 +16,7 @@
 #include <string>
 #include <gtest/gtest.h>
 #include <dns/tests/unittest_util.h>
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include "../message_cache.h"
 #include "../rrset_cache.h"
 #include "../resolver_cache.h"
@@ -25,6 +25,7 @@
 using namespace isc::cache;
 using namespace isc;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace std;
 
 namespace {

+ 1 - 1
src/lib/cache/tests/message_entry_unittest.cc

@@ -15,7 +15,7 @@
 #include <gtest/gtest.h>
 #include <dns/tests/unittest_util.h>
 #include <dns/message.h>
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include "../message_entry.h"
 #include "../rrset_cache.h"
 #include "../resolver_cache.h"

+ 5 - 3
src/lib/datasrc/data_source.cc

@@ -26,15 +26,16 @@
 #include <datasrc/data_source.h>
 #include <datasrc/query.h>
 
-#include <dns/util/base32hex.h>
-#include <dns/buffer.h>
+#include <util/base32hex.h>
+#include <util/buffer.h>
+#include <util/sha1.h>
+
 #include <dns/message.h>
 #include <dns/name.h>
 #include <dns/rcode.h>
 #include <dns/rdataclass.h>
 #include <dns/rrset.h>
 #include <dns/rrsetlist.h>
-#include <dns/util/sha1.h>
 
 #include <cc/data.h>
 
@@ -45,6 +46,7 @@
                       } while (0)
 
 using namespace std;
+using namespace isc::util;
 using namespace isc::dns;
 using namespace isc::dns::rdata;
 

+ 3 - 1
src/lib/datasrc/tests/datasrc_unittest.cc

@@ -20,7 +20,8 @@
 
 #include <gtest/gtest.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+
 #include <dns/message.h>
 #include <dns/messagerenderer.h>
 #include <dns/question.h>
@@ -44,6 +45,7 @@
 
 using isc::UnitTestUtil;
 using namespace std;
+using namespace isc::util;
 using namespace isc::dns;
 using namespace isc::dns::rdata;
 using namespace isc::datasrc;

+ 5 - 9
src/lib/dns/Makefile.am

@@ -1,6 +1,7 @@
 SUBDIRS = . tests python
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
+AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 
@@ -60,12 +61,7 @@ BUILT_SOURCES = rrclass.h rrtype.h rrparamregistry.cc
 
 lib_LTLIBRARIES = libdns++.la
 
-libdns___la_SOURCES = util/base32hex.h util/base64.h util/base_n.cc
-libdns___la_SOURCES += util/base32hex_from_binary.h
-libdns___la_SOURCES += util/binary_from_base32hex.h
-libdns___la_SOURCES += util/base16_from_binary.h util/binary_from_base16.h
-libdns___la_SOURCES += buffer.h
-libdns___la_SOURCES += dnssectime.h dnssectime.cc
+libdns___la_SOURCES =
 libdns___la_SOURCES += edns.h edns.cc
 libdns___la_SOURCES += exceptions.h exceptions.cc
 libdns___la_SOURCES += util/hex.h
@@ -83,11 +79,13 @@ libdns___la_SOURCES += rrsetlist.h rrsetlist.cc
 libdns___la_SOURCES += rrttl.h rrttl.cc
 libdns___la_SOURCES += rrtype.cc
 libdns___la_SOURCES += question.h question.cc
-libdns___la_SOURCES += util/sha1.h util/sha1.cc
 libdns___la_SOURCES += tsigkey.h tsigkey.cc
 libdns___la_SOURCES += rdata/generic/detail/nsec_bitmap.h
 libdns___la_SOURCES += rdata/generic/detail/nsec_bitmap.cc
 
+libdns___la_CPPFLAGS = $(AM_CPPFLAGS)
+libdns___la_LIBADD = $(top_builddir)/src/lib/util/libutil.la
+
 nodist_libdns___la_SOURCES = rdataclass.cc rrclass.h rrtype.h
 nodist_libdns___la_SOURCES += rrparamregistry.cc
 
@@ -99,8 +97,6 @@ rrclass.h rrtype.h rrparamregistry.cc rdataclass.h rdataclass.cc: Makefile
 
 libdns___includedir = $(includedir)/dns
 libdns___include_HEADERS = \
-	buffer.h \
-	dnssectime.h \
 	edns.h \
 	exceptions.h \
 	message.h \

+ 0 - 446
src/lib/dns/buffer.h

@@ -1,446 +0,0 @@
-// Copyright (C) 2009  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 __BUFFER_H
-#define __BUFFER_H 1
-
-#include <vector>
-
-#include <string.h>
-
-#include <stdint.h>
-
-#include <exceptions/exceptions.h>
-
-#include <boost/shared_ptr.hpp>
-
-namespace isc {
-namespace dns {
-
-///
-/// \brief A standard DNS module exception that is thrown if an out-of-range
-/// buffer operation is being performed.
-///
-class InvalidBufferPosition : public Exception {
-public:
-    InvalidBufferPosition(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
-};
-
-///\brief The \c InputBuffer class is a buffer abstraction for manipulating
-/// read-only data.
-///
-/// The main purpose of this class is to provide a safe placeholder for
-/// examining wire-format data received from a network.
-///
-/// Applications normally use this class only in a limited situation: as an
-/// interface between legacy I/O operation (such as receiving data from a BSD
-/// socket) and the rest of the BIND10 DNS library.  One common usage of this
-/// class for an application would therefore be something like this:
-///
-/// \code unsigned char buf[1024];
-/// struct sockaddr addr;
-/// socklen_t addrlen = sizeof(addr);
-/// int cc = recvfrom(s, buf, sizeof(buf), 0, &addr, &addrlen);
-/// InputBuffer buffer(buf, cc);
-/// // pass the buffer to a DNS message object to parse the message \endcode
-///
-/// Other BIND10 DNS classes will then use methods of this class to get access
-/// to the data, but the application normally doesn't have to care about the
-/// details.
-///
-/// An \c InputBuffer object internally holds a reference to the given data,
-/// rather than make a local copy of the data.  Also, it does not have an
-/// ownership of the given data.  It is application's responsibility to ensure
-/// the data remains valid throughout the lifetime of the \c InputBuffer
-/// object.  Likewise, this object generally assumes the data isn't modified
-/// throughout its lifetime; if the application modifies the data while this
-/// object retains a reference to it, the result is undefined.  The application
-/// will also be responsible for releasing the data when it's not needed if it
-/// was dynamically acquired.
-///
-/// This is a deliberate design choice: although it's safer to make a local
-/// copy of the given data on construction, it would cause unacceptable
-/// performance overhead, especially considering that a DNS message can be
-/// as large as a few KB.  Alternatively, we could allow the object to allocate
-/// memory internally and expose it to the application to store network data
-/// in it.  This is also a bad design, however, in that we would effectively
-/// break the abstraction employed in the class, and do so by publishing
-/// "read-only" stuff as a writable memory region.  Since there doesn't seem to
-/// be a perfect solution, we have adopted what we thought a "least bad" one.
-///
-/// Methods for reading data from the buffer generally work like an input
-/// stream: it begins with the head of the data, and once some length of data
-/// is read from the buffer, the next read operation will take place from the
-/// head of the unread data.  An object of this class internally holds (a
-/// notion of) where the next read operation should start.  We call it the
-/// <em>read position</em> in this document.
-class InputBuffer {
-public:
-    ///
-    /// \name Constructors and Destructor
-    //@{
-    /// \brief Constructor from variable length of data.
-    ///
-    /// It is caller's responsibility to ensure that the data is valid as long
-    /// as the buffer exists.
-    /// \param data A pointer to the data stored in the buffer.
-    /// \param len The length of the data in bytes.
-    InputBuffer(const void* data, size_t len) :
-        position_(0), data_(static_cast<const uint8_t*>(data)), len_(len) {}
-    //@}
-
-    ///
-    /// \name Getter Methods
-    //@{
-    /// \brief Return the length of the data stored in the buffer.
-    size_t getLength() const { return (len_); }
-    /// \brief Return the current read position.
-    size_t getPosition() const { return (position_); }
-    //@}
-
-    ///
-    /// \name Setter Methods
-    ///
-    //@{
-    /// \brief Set the read position of the buffer to the given value.
-    ///
-    /// The new position must be in the valid range of the buffer; otherwise
-    /// an exception of class \c isc::dns::InvalidBufferPosition will be thrown.
-    /// \param position The new position (offset from the beginning of the
-    /// buffer).
-    void setPosition(size_t position)
-    {
-        if (position > len_)
-            isc_throw(InvalidBufferPosition, "position is too large");
-        position_ = position;
-    }
-    //@}
-
-    ///
-    /// \name Methods for reading data from the buffer.
-    //@{
-    /// \brief Read an unsigned 8-bit integer from the buffer and return it.
-    ///
-    /// If the remaining length of the buffer is smaller than 8-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
-    uint8_t readUint8()
-    {
-        if (position_ + sizeof(uint8_t) > len_) {
-            isc_throw(InvalidBufferPosition, "read beyond end of buffer");
-        }
-
-        return (data_[position_++]);
-    }
-    /// \brief Read an unsigned 16-bit integer in network byte order from the
-    /// buffer, convert it to host byte order, and return it.
-    ///
-    /// If the remaining length of the buffer is smaller than 16-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
-    uint16_t readUint16()
-    {
-        uint16_t data;
-        const uint8_t* cp;
-
-        if (position_ + sizeof(data) > len_) {
-            isc_throw(InvalidBufferPosition, "read beyond end of buffer");
-        }
-
-        cp = &data_[position_];
-        data = ((unsigned int)(cp[0])) << 8;
-        data |= ((unsigned int)(cp[1]));
-        position_ += sizeof(data);
-
-        return (data);
-    }
-    /// \brief Read an unsigned 32-bit integer in network byte order from the
-    /// buffer, convert it to host byte order, and return it.
-    ///
-    /// If the remaining length of the buffer is smaller than 32-bit, an
-    /// exception of class \c isc::dns::InvalidBufferPosition will be thrown.
-    uint32_t readUint32()
-    {
-        uint32_t data;
-        const uint8_t* cp;
-
-        if (position_ + sizeof(data) > len_) {
-            isc_throw(InvalidBufferPosition, "read beyond end of buffer");
-        }
-
-        cp = &data_[position_];
-        data = ((unsigned int)(cp[0])) << 24;
-        data |= ((unsigned int)(cp[1])) << 16;
-        data |= ((unsigned int)(cp[2])) << 8;
-        data |= ((unsigned int)(cp[3]));
-        position_ += sizeof(data);
-
-        return (data);
-    }
-    /// \brief Read data of the specified length from the buffer and copy it to
-    /// the caller supplied buffer.
-    ///
-    /// The data is copied as stored in the buffer; no conversion is performed.
-    /// If the remaining length of the buffer is smaller than the specified
-    /// length, an exception of class \c isc::dns::InvalidBufferPosition will
-    /// be thrown.
-    void readData(void* data, size_t len)
-    {
-        if (position_ + len > len_) {
-            isc_throw(InvalidBufferPosition, "read beyond end of buffer");
-        }
-
-        memcpy(data, &data_[position_], len);
-        position_ += len;
-    }
-    //@}
-
-private:
-    size_t position_;
-
-    // XXX: The following must be private, but for a short term workaround with
-    // Boost.Python binding, we changed it to protected.  We should soon
-    // revisit it.
-protected:
-    const uint8_t* data_;
-    size_t len_;
-};
-
-///
-///\brief The \c OutputBuffer class is a buffer abstraction for manipulating
-/// mutable data.
-///
-/// The main purpose of this class is to provide a safe workplace for
-/// constructing wire-format data to be sent out to a network.  Here,
-/// <em>safe</em> means that it automatically allocates necessary memory and
-/// avoid buffer overrun.
-///
-/// Like for the \c InputBuffer class, applications normally use this class only
-/// in a limited situation.  One common usage of this class for an application
-/// would be something like this:
-///
-/// \code OutputBuffer buffer(4096); // give a sufficiently large initial size
-/// // pass the buffer to a DNS message object to construct a wire-format
-/// // DNS message.
-/// struct sockaddr to;
-/// sendto(s, buffer.getData(), buffer.getLength(), 0, &to, sizeof(to));
-/// \endcode
-///
-/// where the \c getData() method gives a reference to the internal memory
-/// region stored in the \c buffer object.  This is a suboptimal design in that
-/// it exposes an encapsulated "handle" of an object to its user.
-/// Unfortunately, there is no easy way to avoid this without involving
-/// expensive data copy if we want to use this object with a legacy API such as
-/// a BSD socket interface.  And, indeed, this is one major purpose for this
-/// object.  Applications should use this method only under such a special
-/// circumstance.  It should also be noted that the memory region returned by
-/// \c getData() may be invalidated after a subsequent write operation.
-///
-/// An \c OutputBuffer class object automatically extends its memory region when
-/// data is written beyond the end of the current buffer.  However, it will
-/// involve performance overhead such as reallocating more memory and copying
-/// data.  It is therefore recommended to construct the buffer object with a
-/// sufficiently large initial size.
-/// The \c getCapacity() method provides the current maximum size of data
-/// (including the portion already written) that can be written into the buffer
-/// without causing memory reallocation.
-///
-/// Methods for writing data into the buffer generally work like an output
-/// stream: it begins with the head of the buffer, and once some length of data
-/// is written into the buffer, the next write operation will take place from
-/// the end of the buffer.  Other methods to emulate "random access" are also
-/// provided (e.g., \c writeUint16At()).  The normal write operations are
-/// normally exception-free as this class automatically extends the buffer
-/// when necessary.  However, in extreme cases such as an attempt of writing
-/// multi-GB data, a separate exception (e.g., \c std::bad_alloc) may be thrown
-/// by the system.  This also applies to the constructor with a very large
-/// initial size.
-///
-/// Note to developers: it may make more sense to introduce an abstract base
-/// class for the \c OutputBuffer and define the simple implementation as a
-/// a concrete derived class.  That way we can provide flexibility for future
-/// extension such as more efficient buffer implementation or allowing users
-/// to have their own customized version without modifying the source code.
-/// We in fact considered that option, but at the moment chose the simpler
-/// approach with a single concrete class because it may make the
-/// implementation unnecessarily complicated while we were still not certain
-/// if we really want that flexibility.  We may revisit the class design as
-/// we see more applications of the class.  The same considerations apply to
-/// the \c InputBuffer and \c MessageRenderer classes.
-class OutputBuffer {
-public:
-    ///
-    /// \name Constructors and Destructor
-    ///
-    //@{
-    /// \brief Constructor from the initial size of the buffer.
-    ///
-    /// \param len The initial length of the buffer in bytes.
-    OutputBuffer(size_t len) { data_.reserve(len); }
-    //@}
-
-    ///
-    /// \name Getter Methods
-    ///
-    //@{
-    /// \brief Return the current capacity of the buffer.
-    size_t getCapacity() const { return (data_.capacity()); }
-    /// \brief Return a pointer to the head of the data stored in the buffer.
-    ///
-    /// The caller can assume that the subsequent \c getLength() bytes are
-    /// identical to the stored data of the buffer.
-    ///
-    /// Note: The pointer returned by this method may be invalidated after a
-    /// subsequent write operation.
-    const void* getData() const { return (&data_[0]); }
-    /// \brief Return the length of data written in the buffer.
-    size_t getLength() const { return (data_.size()); }
-    /// \brief Return the value of the buffer at the specified position.
-    ///
-    /// \c pos must specify the valid position of the buffer; otherwise an
-    /// exception class of \c InvalidBufferPosition will be thrown.
-    ///
-    /// \param pos The position in the buffer to be returned.
-    const uint8_t& operator[](size_t pos) const
-    {
-        if (pos >= data_.size()) {
-            isc_throw(InvalidBufferPosition, "read at invalid position");
-        }
-        return (data_[pos]);
-    }
-    //@}
-
-    ///
-    /// \name Methods for writing data into the buffer.
-    ///
-    //@{
-    /// \brief Insert a specified length of gap at the end of the buffer.
-    ///
-    /// The caller should not assume any particular value to be inserted.
-    /// This method is provided as a shortcut to make a hole in the buffer
-    /// that is to be filled in later, e.g, by \ref writeUint16At().
-    /// \param len The length of the gap to be inserted in bytes.
-    void skip(size_t len) { data_.insert(data_.end(), len, 0); }
-
-    /// \brief Trim the specified length of data from the end of the buffer.
-    ///
-    /// The specified length must not exceed the current data size of the
-    /// buffer; otherwise an exception of class \c isc::OutOfRange will
-    /// be thrown.
-    ///
-    /// \param len The length of data that should be trimmed.
-    void trim(size_t len)
-    {
-        if (len > data_.size()) {
-            isc_throw(OutOfRange, "trimming too large from output buffer");
-        }
-        data_.resize(data_.size() - len);
-    }
-    /// \brief Clear buffer content.
-    ///
-    /// This method can be used to re-initialize and reuse the buffer without
-    /// constructing a new one.
-    void clear() { data_.clear(); }
-    /// \brief Write an unsigned 8-bit integer into the buffer.
-    ///
-    /// \param data The 8-bit integer to be written into the buffer.
-    void writeUint8(uint8_t data) { data_.push_back(data); }
-
-    /// \brief Write an unsigned 8-bit integer into the buffer.
-    ///
-    /// The position must be lower than the size of the buffer,
-    /// otherwise an exception of class \c isc::dns::InvalidBufferPosition
-    /// will be thrown.
-    ///
-    /// \param data The 8-bit integer to be written into the buffer.
-    /// \param pos The position in the buffer to write the data.
-    void writeUint8At(uint8_t data, size_t pos) {
-        if (pos + sizeof(data) > data_.size()) {
-            isc_throw(InvalidBufferPosition, "write at invalid position");
-        }
-        data_[pos] = data;
-    }
-
-    /// \brief Write an unsigned 16-bit integer in host byte order into the
-    /// buffer in network byte order.
-    ///
-    /// \param data The 16-bit integer to be written into the buffer.
-    void writeUint16(uint16_t data)
-    {
-        data_.push_back(static_cast<uint8_t>((data & 0xff00U) >> 8));
-        data_.push_back(static_cast<uint8_t>(data & 0x00ffU));
-    }
-    /// \brief Write an unsigned 16-bit integer in host byte order at the
-    /// specified position of the buffer in network byte order.
-    ///
-    /// The buffer must have a sufficient room to store the given data at the
-    /// given position, that is, <code>pos + 2 < getLength()</code>;
-    /// otherwise an exception of class \c isc::dns::InvalidBufferPosition will
-    /// be thrown.
-    /// Note also that this method never extends the buffer.
-    ///
-    /// \param data The 16-bit integer to be written into the buffer.
-    /// \param pos The beginning position in the buffer to write the data.
-    void writeUint16At(uint16_t data, size_t pos)
-    {
-        if (pos + sizeof(data) > data_.size()) {
-            isc_throw(InvalidBufferPosition, "write at invalid position");
-        }
-
-        data_[pos] = static_cast<uint8_t>((data & 0xff00U) >> 8);
-        data_[pos + 1] = static_cast<uint8_t>(data & 0x00ffU);
-    }
-    /// \brief Write an unsigned 32-bit integer in host byte order
-    /// into the buffer in network byte order.
-    ///
-    /// \param data The 32-bit integer to be written into the buffer.
-    void writeUint32(uint32_t data)
-    {
-        data_.push_back(static_cast<uint8_t>((data & 0xff000000) >> 24));
-        data_.push_back(static_cast<uint8_t>((data & 0x00ff0000) >> 16));
-        data_.push_back(static_cast<uint8_t>((data & 0x0000ff00) >> 8));
-        data_.push_back(static_cast<uint8_t>(data & 0x000000ff));
-    }
-    /// \brief Copy an arbitrary length of data into the buffer.
-    ///
-    /// No conversion on the copied data is performed.
-    ///
-    /// \param data A pointer to the data to be copied into the buffer.
-    /// \param len The length of the data in bytes.
-    void writeData(const void *data, size_t len)
-    {
-        const uint8_t* cp = static_cast<const uint8_t*>(data);
-        data_.insert(data_.end(), cp, cp + len);
-    }
-    //@}
-    
-private:
-    std::vector<uint8_t> data_;
-};
-
-/// \brief Pointer-like types pointing to \c InputBuffer or \c OutputBuffer
-///
-/// These types are expected to be used as an argument in asynchronous
-/// callback functions.  The internal reference-counting will ensure that
-/// that ongoing state information will not be lost if the object
-/// that originated the asynchronous call falls out of scope.
-typedef boost::shared_ptr<InputBuffer> InputBufferPtr;
-typedef boost::shared_ptr<OutputBuffer> OutputBufferPtr;
-
-}
-}
-#endif  // __BUFFER_H
-
-// Local Variables: 
-// mode: c++
-// End: 

+ 0 - 211
src/lib/dns/dnssectime.cc

@@ -1,211 +0,0 @@
-// Copyright (C) 2010  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 <stdint.h>
-
-#include <sys/time.h>
-
-#include <string>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-
-#include <stdio.h>
-#include <time.h>
-
-#include <exceptions/exceptions.h>
-
-#include <dns/dnssectime.h>
-
-using namespace std;
-
-namespace {
-int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-
-inline bool
-isLeap(const int y) {
-    return ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0);
-}
-
-unsigned int
-yearSecs(const int year) {
-    return ((isLeap(year) ? 366 : 365 ) * 86400);
-}
-
-unsigned int
-monthSecs(const int month, const int year) {
-    return ((days[month] + ((month == 1 && isLeap(year)) ? 1 : 0 )) * 86400);
-}
-}
-
-namespace isc {
-namespace dns {
-
-string
-timeToText64(uint64_t value) {
-    struct tm tm;
-    unsigned int secs;
-
-    // We cannot rely on gmtime() because time_t may not be of 64 bit
-    // integer.  The following conversion logic is borrowed from BIND 9.
-    tm.tm_year = 70;
-    while ((secs = yearSecs(tm.tm_year + 1900)) <= value) {
-        value -= secs;
-        ++tm.tm_year;
-        if (tm.tm_year + 1900 > 9999) {
-            isc_throw(InvalidTime,
-                      "Time value out of range (year > 9999): " <<
-                      tm.tm_year + 1900);
-        }
-    }
-    tm.tm_mon = 0;
-    while ((secs = monthSecs(tm.tm_mon, tm.tm_year + 1900)) <= value) {
-        value -= secs;
-        tm.tm_mon++;
-    }
-    tm.tm_mday = 1;
-    while (86400 <= value) {
-        value -= 86400;
-        ++tm.tm_mday;
-    }
-    tm.tm_hour = 0;
-    while (3600 <= value) {
-        value -= 3600;
-        ++tm.tm_hour;
-    }
-    tm.tm_min = 0;
-    while (60 <= value) {
-        value -= 60;
-        ++tm.tm_min;
-    }
-    tm.tm_sec = value;    // now t < 60, so this substitution is safe.
-
-    ostringstream oss;
-    oss << setfill('0')
-        << setw(4) << tm.tm_year + 1900
-        << setw(2) << tm.tm_mon + 1
-        << setw(2) << tm.tm_mday
-        << setw(2) << tm.tm_hour
-        << setw(2) << tm.tm_min
-        << setw(2) << tm.tm_sec;
-    return (oss.str());
-}
-
-// timeToText32() below uses the current system time.  To test it with
-// unusual current time values we introduce the following function pointer;
-// when it's non NULL, we call it to get the (normally faked) current time.
-// Otherwise we use the standard gettimeofday(2).  This hook is specifically
-// intended for testing purposes, so, even if it's visible outside of this
-// library, it's not even declared in a header file.
-namespace dnssectime {
-namespace detail {
-int64_t (*gettimeFunction)() = NULL;
-}
-}
-
-namespace {
-int64_t
-gettimeofdayWrapper() {
-    using namespace dnssectime::detail;
-    if (gettimeFunction != NULL) {
-        return (gettimeFunction());
-    }
-
-    struct timeval now;
-    gettimeofday(&now, NULL);
-
-    return (static_cast<int64_t>(now.tv_sec));
-}
-}
-
-string
-timeToText32(const uint32_t value) {
-    // We first adjust the time to the closest epoch based on the current time.
-    // Note that the following variables must be signed in order to handle
-    // time until year 2038 correctly.
-    const int64_t start = gettimeofdayWrapper() - 0x7fffffff;
-    int64_t base = 0;
-    int64_t t;
-    while ((t = (base + value)) < start) {
-        base += 0x100000000LL;
-    }
-
-    // Then convert it to text.
-    return (timeToText64(t));
-}
-
-namespace {
-const size_t DATE_LEN = 14;      // YYYYMMDDHHmmSS
-
-inline void
-checkRange(const int min, const int max, const int value,
-           const string& valname)
-{
-    if ((value >= min) && (value <= max)) {
-        return;
-    }
-    isc_throw(InvalidTime, "Invalid " << valname << "value: " << value);
-}
-}
-
-uint64_t
-timeFromText64(const string& time_txt) {
-    // Confirm the source only consists digits.  sscanf() allows some
-    // minor exceptions.
-    for (int i = 0; i < time_txt.length(); ++i) {
-        if (!isdigit(time_txt.at(i))) {
-            isc_throw(InvalidTime, "Couldn't convert non-numeric time value: "
-                      << time_txt);
-        }
-    }
-
-    int year, month, day, hour, minute, second;
-    if (time_txt.length() != DATE_LEN ||
-        sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
-               &year, &month, &day, &hour, &minute, &second) != 6)
-    {
-        isc_throw(InvalidTime, "Couldn't convert time value: " << time_txt);
-    }
-
-    checkRange(1970, 9999, year, "year");
-    checkRange(1, 12, month, "month");
-    checkRange(1, days[month - 1] + ((month == 2 && isLeap(year)) ? 1 : 0),
-            day, "day");
-    checkRange(0, 23, hour, "hour");
-    checkRange(0, 59, minute, "minute");
-    checkRange(0, 60, second, "second"); // 60 == leap second.
-
-    uint64_t timeval = second + (60 * minute) + (3600 * hour) +
-        ((day - 1) * 86400);
-    for (int m = 0; m < (month - 1); ++m) {
-            timeval += days[m] * 86400;
-    }
-    if (isLeap(year) && month > 2) {
-            timeval += 86400;
-    }
-    for (int y = 1970; y < year; ++y) {
-        timeval += ((isLeap(y) ? 366 : 365 ) * 86400);
-    }
-
-    return (timeval);
-}
-
-uint32_t
-timeFromText32(const string& time_txt) {
-    // The implicit conversion from uint64_t to uint32_t should just work here,
-    // because we only need to drop higher 32 bits.
-    return (timeFromText64(time_txt));
-}
-}
-}

+ 0 - 145
src/lib/dns/dnssectime.h

@@ -1,145 +0,0 @@
-// Copyright (C) 2009  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 __DNSSECTIME_H
-#define __DNSSECTIME_H 1
-
-#include <sys/types.h>
-#include <stdint.h>
-
-#include <exceptions/exceptions.h>
-
-//
-// Note: this helper module isn't specific to the DNS protocol per se.
-// We should probably move this to somewhere else, possibly in some common
-// utility area.
-//
-
-namespace isc {
-namespace dns {
-
-///
-/// \brief A standard DNS (or ISC) module exception that is thrown if 
-/// a time conversion function encounters bad input
-///
-class InvalidTime : public Exception {
-public:
-    InvalidTime(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
-};
-
-///
-/// \name DNSSEC time conversion functions.
-///
-/// These functions convert between times represented in seconds (in integer)
-/// since epoch and those in the textual form used in the RRSIG records.
-/// For integers we provide both 32-bit and 64-bit versions.
-/// The RRSIG expiration and inception fields are both 32-bit unsigned
-/// integers, so 32-bit versions would be more useful for protocol operations.
-/// However, with 32-bit integers we need to take into account wrap-around
-/// points and compare values using the serial number arithmetic as specified
-/// in RFC4034, which would be more error prone.  We therefore provide 64-bit
-/// versions, too.
-///
-/// The timezone is always UTC for these functions.
-//@{
-/// Convert textual DNSSEC time to integer, 64-bit version.
-///
-/// The textual form must only consist of digits and be in the form of
-/// YYYYMMDDHHmmSS, where:
-/// - YYYY must be between 1970 and 9999
-/// - MM must be between 01 and 12
-/// - DD must be between 01 and 31 and must be a valid day for the month
-///   represented in 'MM'.  For example, if MM is 04, DD cannot be 31.
-///   DD can be 29 when MM is 02 only when YYYY is a leap year.
-/// - HH must be between 00 and 23
-/// - mm must be between 00 and 59
-/// - SS must be between 00 and 60
-///
-/// For all fields the range includes the begin and end values.  Note that
-/// 60 is allowed for 'SS', intending a leap second, although in real operation
-/// it's unlikely to be specified.
-///
-/// If the given text is valid, this function converts it to an unsigned
-/// 64-bit number of seconds since epoch (1 January 1970 00:00:00) and returns
-/// the converted value.  64 bits are sufficient to represent all possible
-/// values for the valid format uniquely, so there is no overflow.
-///
-/// \note RFC4034 also defines the textual form of an unsigned decimal integer
-/// for the corresponding time in seconds.  This function doesn't support
-/// this form, and if given it throws an exception of class \c InvalidTime.
-///
-/// \exception InvalidTime The given textual representation is invalid.
-///
-/// \param time_txt Textual time in the form of YYYYMMDDHHmmSS
-/// \return Seconds since epoch corresponding to \c time_txt
-uint64_t
-timeFromText64(const std::string& time_txt);
-
-/// Convert textual DNSSEC time to integer, 32-bit version.
-///
-/// This version is the same as \c timeFromText64() except that the return
-/// value is wrapped around to an unsigned 32-bit integer, simply dropping
-/// the upper 32 bits.
-uint32_t
-timeFromText32(const std::string& time_txt);
-
-/// Convert integral DNSSEC time to textual form, 64-bit version.
-///
-/// This function takes an integer that would be seconds since epoch and
-/// converts it in the form of YYYYMMDDHHmmSS.  For example, if \c value is
-/// 0, it returns "19700101000000".  If the value corresponds to a point
-/// of time on and after year 10,000, which cannot be represented in the
-/// YYYY... form, an exception of class \c InvalidTime will be thrown.
-///
-/// \exception InvalidTime The given time specifies on or after year 10,000.
-/// \exception Other A standard exception, if resource allocation for the
-/// returned text fails.
-///
-/// \param value Seconds since epoch to be converted.
-/// \return Textual representation of \c value in the form of YYYYMMDDHHmmSS.
-std::string
-timeToText64(uint64_t value);
-
-/// Convert integral DNSSEC time to textual form, 32-bit version.
-///
-/// This version is the same as \c timeToText64(), but the time value
-/// is expected to be the lower 32 bits of the full 64-bit value.
-/// These two will be different on and after a certain point of time
-/// in year 2106, so this function internally resolves the ambiguity
-/// using the current system time at the time of function call;
-/// it first identifies the range of [N*2^32 - 2^31, N*2^32 + 2^31)
-/// that contains the current time, and interprets \c value in the context
-/// of that range.  It then applies the same process as \c timeToText64().
-///
-/// There is one important exception in this processing, however.
-/// Until 19 Jan 2038 03:14:08 (2^31 seconds since epoch), this range
-/// would contain time before epoch.  In order to ensure the returned
-/// value is also a valid input to \c timeFromText, this function uses
-/// a special range [0, 2^32) until that time.  As a result, all upper
-/// half of the 32-bit values are treated as a future time.  For example,
-/// 2^32-1 (the highest value in 32-bit unsigned integers) will be converted
-/// to "21060207062815", instead of "19691231235959".
-std::string
-timeToText32(const uint32_t value);
-
-//@}
-}
-}
-
-#endif  // __DNSSECTIME_H
-
-// Local Variables: 
-// mode: c++
-// End: 

+ 1 - 0
src/lib/dns/edns.cc

@@ -36,6 +36,7 @@
 using namespace std;
 using namespace boost;
 using namespace isc::dns::rdata;
+using namespace isc::util;
 
 namespace isc {
 namespace dns {

+ 5 - 1
src/lib/dns/edns.h

@@ -24,6 +24,10 @@
 #include <dns/rdata.h>
 
 namespace isc {
+namespace util {
+class OutputBuffer;
+}
+
 namespace dns {
 
 class EDNS;
@@ -319,7 +323,7 @@ public:
     /// except it renders the OPT RR in an \c OutputBuffer and therefore
     /// does not care about message size limit.
     /// As a consequence it always returns 1.
-    unsigned int toWire(OutputBuffer& buffer,
+    unsigned int toWire(isc::util::OutputBuffer& buffer,
                         const uint8_t extended_rcode) const;
 
     /// \brief Convert the EDNS to a string.

+ 2 - 1
src/lib/dns/message.cc

@@ -25,7 +25,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/edns.h>
 #include <dns/exceptions.h>
 #include <dns/message.h>
@@ -43,6 +43,7 @@
 using namespace std;
 using namespace boost;
 using namespace isc::dns::rdata;
+using namespace isc::util;
 
 namespace isc {
 namespace dns {

+ 6 - 3
src/lib/dns/message.h

@@ -28,6 +28,10 @@
 #include <dns/rrset.h>
 
 namespace isc {
+namespace util {
+class InputBuffer;
+}
+
 namespace dns {
 
 ///
@@ -76,7 +80,6 @@ public:
 
 typedef uint16_t qid_t;
 
-class InputBuffer;
 class MessageRenderer;
 class Message;
 class MessageImpl;
@@ -529,10 +532,10 @@ public:
     void toWire(MessageRenderer& renderer);
 
     /// \brief Parse the header section of the \c Message.
-    void parseHeader(InputBuffer& buffer);
+    void parseHeader(isc::util::InputBuffer& buffer);
 
     /// \brief Parse the \c Message.
-    void fromWire(InputBuffer& buffer);
+    void fromWire(isc::util::InputBuffer& buffer);
 
     ///
     /// \name Protocol constants

+ 3 - 1
src/lib/dns/messagerenderer.cc

@@ -16,10 +16,12 @@
 #include <cassert>
 #include <set>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 
+using namespace isc::util;
+
 namespace isc {
 namespace dns {
 

+ 5 - 2
src/lib/dns/messagerenderer.h

@@ -16,9 +16,12 @@
 #define __MESSAGERENDERER_H 1
 
 namespace isc {
+namespace util {
+class OutputBuffer;
+}
+
 namespace dns {
 // forward declarations
-class OutputBuffer;
 class Name;
 
 ///
@@ -101,7 +104,7 @@ public:
     ///
     /// \param buffer An \c OutputBuffer object to which wire format data is
     /// written.
-    MessageRenderer(OutputBuffer& buffer);
+    MessageRenderer(isc::util::OutputBuffer& buffer);
     /// \brief The destructor.
     ///
     /// The destructor does nothing on the given \c buffer on construction;

+ 2 - 1
src/lib/dns/name.cc

@@ -20,12 +20,13 @@
 #include <iostream>
 #include <algorithm>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 
 using namespace std;
+using namespace isc::util;
 using isc::dns::NameComparisonResult;
 using isc::dns::MessageRenderer;
 

+ 6 - 3
src/lib/dns/name.h

@@ -23,9 +23,12 @@
 #include <exceptions/exceptions.h>
 
 namespace isc {
-namespace dns {
+namespace util {
 class InputBuffer;
 class OutputBuffer;
+}
+
+namespace dns {
 class MessageRenderer;
 
 ///
@@ -247,7 +250,7 @@ public:
     ///
     /// \param buffer A buffer storing the wire format %data.
     /// \param downcase Whether to convert upper case alphabets to lower case.
-    explicit Name(InputBuffer& buffer, bool downcase = false);
+    explicit Name(isc::util::InputBuffer& buffer, bool downcase = false);
     ///
     /// We use the default copy constructor intentionally.
     //@}
@@ -359,7 +362,7 @@ public:
     /// then this method should not throw an exception.
     ///
     /// \param buffer An output buffer to store the wire %data.
-    void toWire(OutputBuffer& buffer) const;
+    void toWire(isc::util::OutputBuffer& buffer) const;
     //@}
 
     ///

+ 1 - 0
src/lib/dns/python/edns_python.cc

@@ -17,6 +17,7 @@
 #include <dns/edns.h>
 
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::dns::rdata;
 
 //

+ 1 - 0
src/lib/dns/python/message_python.cc

@@ -15,6 +15,7 @@
 #include <exceptions/exceptions.h>
 #include <dns/message.h>
 using namespace isc::dns;
+using namespace isc::util;
 
 //
 // Declaration of the custom exceptions

+ 1 - 0
src/lib/dns/python/messagerenderer_python.cc

@@ -18,6 +18,7 @@
 // and static wrappers around the methods we export), a list of methods,
 // and a type description
 using namespace isc::dns;
+using namespace isc::util;
 
 // MessageRenderer
 

+ 1 - 0
src/lib/dns/python/name_python.cc

@@ -41,6 +41,7 @@ static PyObject* po_NameRelation;
 // and static wrappers around the methods we export), a list of methods,
 // and a type description
 using namespace isc::dns;
+using namespace isc::util;
 
 // NameComparisonResult
 class s_NameComparisonResult : public PyObject {

+ 1 - 1
src/lib/dns/python/pydnspp.cc

@@ -31,7 +31,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>

+ 1 - 0
src/lib/dns/python/rdata_python.cc

@@ -14,6 +14,7 @@
 
 #include <dns/rdata.h>
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::dns::rdata;
 
 //

+ 1 - 0
src/lib/dns/python/rrclass_python.cc

@@ -14,6 +14,7 @@
 
 #include <dns/rrclass.h>
 using namespace isc::dns;
+using namespace isc::util;
 
 //
 // Declaration of the custom exceptions

+ 1 - 0
src/lib/dns/python/rrset_python.cc

@@ -29,6 +29,7 @@ static PyObject* po_EmptyRRset;
 // and static wrappers around the methods we export), a list of methods,
 // and a type description
 using namespace isc::dns;
+using namespace isc::util;
 
 // RRset
 

+ 1 - 0
src/lib/dns/python/rrttl_python.cc

@@ -18,6 +18,7 @@
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 
 //
 // Declaration of the custom exceptions

+ 1 - 0
src/lib/dns/python/rrtype_python.cc

@@ -18,6 +18,7 @@
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 
 //
 // Declaration of the custom exceptions

+ 2 - 1
src/lib/dns/question.cc

@@ -15,7 +15,7 @@
 #include <iostream>
 #include <string>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/question.h>
@@ -23,6 +23,7 @@
 #include <dns/rrtype.h>
 
 using namespace std;
+using namespace isc::util;
 
 namespace isc {
 namespace dns {

+ 7 - 3
src/lib/dns/question.h

@@ -25,9 +25,13 @@
 #include <dns/rrtype.h>
 
 namespace isc {
+namespace util {
+class InputBuffer;
+class OutputBuffer;
+}
+
 namespace dns {
 
-class InputBuffer;
 class MessageRenderer;
 class Question;
 
@@ -118,7 +122,7 @@ public:
     /// classes fails.
     ///
     /// \param buffer A buffer storing the wire format data.
-    Question(InputBuffer& buffer);
+    Question(isc::util::InputBuffer& buffer);
 
     /// \brief Constructor from fixed parameters of the \c Question.
     ///
@@ -224,7 +228,7 @@ public:
     ///
     /// \param buffer An output buffer to store the wire data.
     /// \return 1
-    unsigned int toWire(OutputBuffer& buffer) const;
+    unsigned int toWire(isc::util::OutputBuffer& buffer) const;
     //@}
 
     ///

+ 2 - 1
src/lib/dns/rdata.cc

@@ -27,7 +27,7 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/shared_ptr.hpp>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -36,6 +36,7 @@
 
 using namespace std;
 using namespace boost;
+using namespace isc::util;
 
 namespace isc {
 namespace dns {

+ 7 - 5
src/lib/dns/rdata.h

@@ -22,9 +22,11 @@
 #include <exceptions/exceptions.h>
 
 namespace isc {
-namespace dns {
+namespace util {
 class InputBuffer;
 class OutputBuffer;
+}
+namespace dns {
 class MessageRenderer;
 class RRType;
 class RRClass;
@@ -168,7 +170,7 @@ public:
     /// should be explicitly defined in the derived class.
     ///
     /// \param buffer An output buffer to store the wire data.
-    virtual void toWire(OutputBuffer& buffer) const = 0;
+    virtual void toWire(isc::util::OutputBuffer& buffer) const = 0;
     /// \brief Render the \c Rdata in the wire format into a
     /// \c MessageRenderer object.
     ///
@@ -272,7 +274,7 @@ public:
     /// \param buffer A reference to an \c InputBuffer object storing the
     /// \c Rdata to parse.
     /// \param rdata_len The length in buffer of the \c Rdata.  In bytes.
-    Generic(InputBuffer& buffer, size_t rdata_len);
+    Generic(isc::util::InputBuffer& buffer, size_t rdata_len);
     ///
     /// \brief The destructor.
     virtual ~Generic();
@@ -316,7 +318,7 @@ public:
     /// be thrown.
     ///
     /// \param buffer An output buffer to store the wire data.
-    virtual void toWire(OutputBuffer& buffer) const;
+    virtual void toWire(isc::util::OutputBuffer& buffer) const;
     /// \brief Render the \c generic::Generic in the wire format into a
     /// \c MessageRenderer object.
     ///
@@ -443,7 +445,7 @@ RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
 /// \return An \c RdataPtr object pointing to the created \c Rdata
 /// object.
 RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
-                     InputBuffer& buffer, size_t len);
+                     isc::util::InputBuffer& buffer, size_t len);
 /// \brief Create RDATA of a given pair of RR type and class, copying
 /// of another RDATA of same kind.
 ///

+ 4 - 2
src/lib/dns/rdata/any_255/tsig_250.cc

@@ -18,15 +18,17 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
+#include <util/base64.h>
+
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
-#include <dns/util/base64.h>
 
 using namespace std;
 using namespace boost;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/ch_3/a_1.cc

@@ -16,12 +16,13 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/cname_5.cc

@@ -16,13 +16,14 @@
 
 #include <string>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/dname_39.cc

@@ -16,13 +16,14 @@
 
 #include <string>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 3 - 2
src/lib/dns/rdata/generic/dnskey_48.cc

@@ -20,8 +20,8 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/foreach.hpp>
 
-#include <dns/util/base64.h>
-#include <dns/buffer.h>
+#include <util/base64.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/rdata.h>
@@ -31,6 +31,7 @@
 #include <time.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 4 - 2
src/lib/dns/rdata/generic/ds_43.cc

@@ -19,8 +19,9 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <dns/buffer.h>
-#include <dns/util/hex.h>
+#include <util/buffer.h>
+#include <util/hex.h>
+
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/rdata.h>
@@ -30,6 +31,7 @@
 #include <time.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/mx_15.cc

@@ -20,7 +20,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -28,6 +28,7 @@
 
 using namespace std;
 using namespace boost;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/ns_2.cc

@@ -16,13 +16,14 @@
 
 #include <string>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 5 - 3
src/lib/dns/rdata/generic/nsec3_50.cc

@@ -20,10 +20,11 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <dns/util/base32hex.h>
-#include <dns/buffer.h>
+#include <util/base32hex.h>
+#include <util/buffer.h>
+#include <util/hex.h>
 #include <dns/exceptions.h>
-#include <dns/util/hex.h>
+
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/rrtype.h>
@@ -37,6 +38,7 @@
 
 using namespace std;
 using namespace isc::dns::rdata::generic::detail::nsec;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 3 - 2
src/lib/dns/rdata/generic/nsec3param_51.cc

@@ -19,8 +19,8 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <dns/buffer.h>
-#include <dns/util/hex.h>
+#include <util/buffer.h>
+#include <util/hex.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/rdata.h>
@@ -30,6 +30,7 @@
 #include <time.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 3 - 2
src/lib/dns/rdata/generic/nsec_47.cc

@@ -17,8 +17,8 @@
 #include <sstream>
 #include <vector>
 
-#include <dns/util/base64.h>
-#include <dns/buffer.h>
+#include <util/base64.h>
+#include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
@@ -32,6 +32,7 @@
 #include <time.h>
 
 using namespace std;
+using namespace isc::util;
 using namespace isc::dns::rdata::generic::detail::nsec;
 
 // BEGIN_ISC_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/opt_41.cc

@@ -16,12 +16,13 @@
 
 #include <string>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/ptr_12.cc

@@ -16,13 +16,14 @@
 
 #include <string>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 4 - 3
src/lib/dns/rdata/generic/rrsig_46.cc

@@ -20,9 +20,9 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <dns/util/base64.h>
-#include <dns/buffer.h>
-#include <dns/dnssectime.h>
+#include <util/base64.h>
+#include <util/buffer.h>
+#include <util/dnssectime.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/rrtype.h>
@@ -34,6 +34,7 @@
 #include <time.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/soa_6.cc

@@ -20,7 +20,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -28,6 +28,7 @@
 
 using namespace std;
 using namespace boost;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/generic/txt_16.cc

@@ -18,13 +18,14 @@
 #include <string>
 #include <vector>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/hs_4/a_1.cc

@@ -16,12 +16,13 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/in_1/a_1.cc

@@ -22,13 +22,14 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/in_1/aaaa_28.cc

@@ -22,13 +22,14 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rdata/template.cc

@@ -14,12 +14,13 @@
 
 #include <string>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 using namespace std;
+using namespace isc::util;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE

+ 2 - 1
src/lib/dns/rrclass.cc

@@ -18,13 +18,14 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rrparamregistry.h>
 #include <dns/rrclass.h>
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 
 namespace isc {
 namespace dns {

+ 2 - 2
src/lib/dns/rrparamregistry.h

@@ -102,7 +102,7 @@ public:
     /// \c Rdata to parse.
     /// \param rdata_len The length in buffer of the \c Rdata.  In bytes.
     /// \return An \c RdataPtr object pointing to the created \c Rdata object.
-    virtual RdataPtr create(InputBuffer& buffer, size_t rdata_len) const = 0;
+    virtual RdataPtr create(isc::util::InputBuffer& buffer, size_t rdata_len) const = 0;
     ///
     /// \brief Create RDATA from another \c Rdata object of the same type.
     ///
@@ -473,7 +473,7 @@ public:
     /// \return An \c rdata::RdataPtr object pointing to the created \c Rdata
     /// object.
     rdata::RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
-                                InputBuffer& buffer, size_t len);
+                                isc::util::InputBuffer& buffer, size_t len);
     /// \brief Create RDATA of a given pair of RR type and class, copying
     /// of another RDATA of same kind.
     ///

+ 2 - 1
src/lib/dns/rrset.cc

@@ -18,7 +18,7 @@
 
 #include <boost/shared_ptr.hpp>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
 #include <dns/rrclass.h>
@@ -28,6 +28,7 @@
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 using namespace isc::dns::rdata;
 
 namespace isc {

+ 6 - 3
src/lib/dns/rrset.h

@@ -26,6 +26,10 @@
 #include <dns/rrtype.h>
 
 namespace isc {
+namespace util {
+class OututBuffer;
+}
+
 namespace dns {
 
 ///
@@ -43,7 +47,6 @@ class Name;
 class RRType;
 class RRClass;
 class RRTTL;
-class OututBuffer;
 class MessageRenderer;
 class AbstractRRset;
 class BasicRRset;
@@ -316,7 +319,7 @@ public:
     ///
     /// \param buffer An output buffer to store the wire data.
     /// \return The number of RRs rendered.
-    virtual unsigned int toWire(OutputBuffer& buffer) const = 0;
+    virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const = 0;
     //@}
 
     ///
@@ -620,7 +623,7 @@ public:
     ///
     /// This method simply uses the default implementation.
     /// See \c AbstractRRset::toWire(OutputBuffer&)const.
-    virtual unsigned int toWire(OutputBuffer& buffer) const;
+    virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const;
     //@}
 
     ///

+ 2 - 1
src/lib/dns/rrttl.cc

@@ -17,12 +17,13 @@
 #include <sstream>
 #include <ostream>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rrttl.h>
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::util;
 
 namespace isc {
 namespace dns {

+ 7 - 4
src/lib/dns/rrttl.h

@@ -20,11 +20,14 @@
 #include <exceptions/exceptions.h>
 
 namespace isc {
+namespace util {
+class InputBuffer;
+class OutputBuffer;
+}
+
 namespace dns {
 
 // forward declarations
-class InputBuffer;
-class OutputBuffer;
 class MessageRenderer;
 
 ///
@@ -91,7 +94,7 @@ public:
     /// an exception of class \c IncompleteRRTTL will be thrown.
     ///
     /// \param buffer A buffer storing the wire format data.
-    explicit RRTTL(InputBuffer& buffer);
+    explicit RRTTL(isc::util::InputBuffer& buffer);
     ///
     //@}
 
@@ -130,7 +133,7 @@ public:
     /// standard exception will be thrown.
     ///
     /// \param buffer An output buffer to store the wire data.
-    void toWire(OutputBuffer& buffer) const;
+    void toWire(isc::util::OutputBuffer& buffer) const;
     //@}
 
     ///

+ 2 - 2
src/lib/dns/rrtype.cc

@@ -19,14 +19,14 @@
 
 #include <exceptions/exceptions.h>
 
-#include <dns/buffer.h>
+#include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/rrparamregistry.h>
 #include <dns/rrtype.h>
 
 using namespace std;
+using namespace isc::util;
 using isc::dns::RRType;
-using isc::dns::OutputBuffer;
 
 namespace isc {
 namespace dns {

+ 2 - 6
src/lib/dns/tests/Makefile.am

@@ -3,6 +3,7 @@ SUBDIRS = testdata .
 AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
+AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
 AM_CPPFLAGS += -DTEST_DATA_SRCDIR=\"$(srcdir)/testdata\"
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/dns/tests/testdata\"
 AM_CXXFLAGS = $(B10_CXXFLAGS)
@@ -17,12 +18,10 @@ TESTS =
 if HAVE_GTEST
 TESTS += run_unittests
 run_unittests_SOURCES = unittest_util.h unittest_util.cc
-run_unittests_SOURCES += buffer_unittest.cc name_unittest.cc
 run_unittests_SOURCES += edns_unittest.cc
 run_unittests_SOURCES += messagerenderer_unittest.cc
 run_unittests_SOURCES += rrclass_unittest.cc rrtype_unittest.cc
 run_unittests_SOURCES += rrttl_unittest.cc
-run_unittests_SOURCES += dnssectime_unittest.cc
 run_unittests_SOURCES += opcode_unittest.cc
 run_unittests_SOURCES += rcode_unittest.cc
 run_unittests_SOURCES += rdata_unittest.h rdata_unittest.cc
@@ -45,10 +44,6 @@ run_unittests_SOURCES += question_unittest.cc
 run_unittests_SOURCES += rrparamregistry_unittest.cc
 run_unittests_SOURCES += masterload_unittest.cc
 run_unittests_SOURCES += message_unittest.cc
-run_unittests_SOURCES += base32hex_unittest.cc
-run_unittests_SOURCES += base64_unittest.cc
-run_unittests_SOURCES += hex_unittest.cc
-run_unittests_SOURCES += sha1_unittest.cc
 run_unittests_SOURCES += tsigkey_unittest.cc
 run_unittests_SOURCES += run_unittests.cc
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
@@ -56,6 +51,7 @@ run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
 run_unittests_LDADD = $(GTEST_LDADD)
 run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
 run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
+run_unittests_LDADD += $(top_builddir)/src/lib/util/libutil.la
 endif
 
 noinst_PROGRAMS = $(TESTS)

+ 0 - 0
src/lib/dns/tests/base32hex_unittest.cc


Some files were not shown because too many files changed in this diff