-SUBDIRS = . tests // @todo - please update
- // @todo - please update
+SUBDIRS = . tests
+
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
-AM_CPPFLAGS += $(BOOST_INCLUDES) // @todo - please update
- // @todo - please update
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+
AM_CXXFLAGS = $(KEA_CXXFLAGS)
- // @todo - please update
+
CLEANFILES = *.gcno *.gcda
EXTRA_DIST = asiodns_messages.mes
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-$NAMESPACE isc::asiodns // @todo - please update
+$NAMESPACE isc::asiodns
% ASIODNS_FD_ADD_TCP adding a new TCP server by opened fd %1
A debug message informing about installing a file descriptor as a server.
#include <cryptolink/crypto_rng.h>
#include <dns/rcode.h>
#include <util/io.h>
- // @todo - please update
+
#include <boost/scoped_ptr.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <stdint.h>
#include <sys/socket.h>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
using namespace isc::dns;
using namespace isc::log;
using namespace isc::util;
using namespace boost::asio;
using namespace std;
-namespace isc { // @todo - please update
-namespace asiodns { // @todo - please update
+namespace isc {
+namespace asiodns {
// Log debug verbosity.
initIOFetch(question, protocol, service, **(query_message->beginQuestion()), address,
port, buff, cb, wait);
-} // @todo - please update
- // @todo - please update
-void // @todo - please update
+}
+
+void
IOFetch::initIOFetch(MessagePtr& query, Protocol protocol, const IOServicePtr& service,
const isc::dns::Question& question, const IOAddress& address, uint16_t port,
OutputBufferPtr& buff, Callback* cb, int wait, bool edns) {
r.setBuffer(data_->msgbuf.get());
query->toWire(r);
r.setBuffer(NULL);
-} // @todo - please update
- // @todo - please update
+}
+
IOFetch::Protocol
IOFetch::getProtocol() const {
return (data_->protocol);
#include <ext/coroutine/coroutine.hpp>
#endif
-#include <asiolink/io_address.h> // @todo - please update
+#include <asiolink/io_address.h>
#include <asiolink/io_service.h>
-#include <dns/message.h> // @todo - please update
+#include <dns/message.h>
#include <dns/question.h>
#include <util/buffer.h>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/system/error_code.hpp>
-namespace isc { // @todo - please update
-namespace asiodns { // @todo - please update
+namespace isc {
+namespace asiodns {
// Forward declarations
struct IOFetchData;
bool edns = true);
/// @brief Constructor
- /// // @todo - please update
+ ///
/// This constructor has one parameter "query_message", which is the shared_ptr
/// to a full query message. It's different with above constructor which has only
/// question section. All other parameters are the same.
isc::util::OutputBufferPtr& buff,
Callback* cb,
int wait = -1);
- // @todo - please update
+
/// @brief Constructor.
///
/// Creates the object that will handle the upstream fetch.
isc::util::OutputBufferPtr& buff,
Callback* cb, int wait,
bool edns = true);
- // @todo - please update
+
/// @brief Log I/O Failure.
///
/// Records an I/O failure to the log file.
-AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib // @todo - please update
-AM_CPPFLAGS += $(BOOST_INCLUDES) // @todo - please update
- // @todo - please update
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+
AM_CXXFLAGS = $(KEA_CXXFLAGS)
- // @todo - please update
-if USE_STATIC_LINK // @todo - please update
-AM_LDFLAGS = -static // @todo - please update
-endif // @todo - please update
- // @todo - please update
-CLEANFILES = *.gcno *.gcda // @todo - please update
- // @todo - please update
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+CLEANFILES = *.gcno *.gcda
+
TESTS_ENVIRONMENT = $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
-TESTS = // @todo - please update
-if HAVE_GTEST // @todo - please update
-TESTS += run_unittests // @todo - please update
-run_unittests_SOURCES = run_unittests.cc // @todo - please update
-run_unittests_SOURCES += io_fetch_unittest.cc // @todo - please update
- // @todo - please update
-run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) // @todo - please update
- // @todo - please update
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = run_unittests.cc
+run_unittests_SOURCES += io_fetch_unittest.cc
+
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+
run_unittests_LDADD = $(top_builddir)/src/lib/asiodns/libkea-asiodns.la
run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
run_unittests_LDADD += $(LOG4CPLUS_LIBS) $(CRYPTO_LIBS)
run_unittests_LDADD += $(BOOST_LIBS) $(GTEST_LDADD)
- // @todo - please update
+
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)
- // @todo - please update
+
# Note: the ordering matters: -Wno-... must follow -Wextra (defined in KEA_CXXFLAGS)
-run_unittests_CXXFLAGS = $(AM_CXXFLAGS) // @todo - please update
-if USE_GXX // @todo - please update
-run_unittests_CXXFLAGS += -Wno-unused-parameter // @todo - please update
-endif // @todo - please update
-endif // @todo - please update
- // @todo - please update
+run_unittests_CXXFLAGS = $(AM_CXXFLAGS)
+if USE_GXX
+run_unittests_CXXFLAGS += -Wno-unused-parameter
+endif
+endif
+
noinst_PROGRAMS = $(TESTS)
using namespace isc::asiolink;
using namespace isc::dns;
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using namespace boost::asio;
using namespace boost::asio::ip;
namespace ph = std::placeholders;
-namespace isc { // @todo - please update
-namespace asiodns { // @todo - please update
+namespace isc {
+namespace asiodns {
const boost::asio::ip::address TEST_HOST(boost::asio::ip::address::from_string("127.0.0.1"));
const uint16_t TEST_PORT(5301);
// Copyright (C) 2009-2015 Internet Systems Consortium, Inc. ("ISC")
-// // @todo - please update
+//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
- // @todo - please update
+
#include <config.h>
-#include <gtest/gtest.h> // @todo - please update
- // @todo - please update
+#include <gtest/gtest.h>
+
#include <util/unittests/run_all.h>
#include <log/logger_support.h>
- // @todo - please update
-int // @todo - please update
+
+int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
isc::log::initLogger();
return (isc::util::unittests::run_all());
-} // @todo - please update
+}
#include <boost/asio/error.hpp>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief Asynchronous I/O Completion Callback
using namespace std;
namespace ph = std::placeholders;
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// This class holds a call back function of asynchronous operations.
#include <asiolink/io_service.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
class IntervalTimerImpl;
using namespace std;
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
size_t
#include <exceptions/exceptions.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// Defines length of IPv6 address (in binary format).
#include <boost/asio/coroutine.hpp>
#endif
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief Socket not open
using namespace std;
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
const IOEndpoint*
#include <sys/socket.h> // for sockaddr
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief The \c IOEndpoint class is an abstract base class to represent
#include <exceptions/exceptions.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief An exception that is thrown if an error occurs within the IO
#include <boost/shared_ptr.hpp>
#include <sys/socket.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
class IOServiceImpl {
}
}
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
class IOServiceImpl;
#include <asiolink/asio_wrapper.h>
#include <asiolink/io_socket.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief The \c DummySocket class is a concrete derived class of
#include <exceptions/exceptions.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief The \c IOSocket class is an abstract base class to represent
#include <asiolink/io_endpoint.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief The \c TCPEndpoint class is a concrete derived class of
#include <sys/socket.h>
#include <unistd.h> // for some IPC/network system calls
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief Buffer Too Large
#include <sstream>
#include <unordered_set>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
TEST(IOAddressHashTest, hashIPv4) {
IOAddress::Hash hash;
#include <netdb.h>
#include <string.h>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
namespace {
typedef boost::shared_ptr<const IOEndpoint> ConstIOEndpointPtr;
#include <gtest/gtest.h>
#include <netinet/in.h>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
TEST(IOSocketTest, dummySockets) {
EXPECT_EQ(static_cast<short>(IPPROTO_UDP),
#include <string>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
using namespace std;
// This test checks that the endpoint can manage its own internal
#include <string>
#include <vector>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
using namespace isc::util;
using namespace std;
#include <string>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
using namespace std;
// This test checks that the endpoint can manage its own internal
#include <vector>
-using namespace isc::asiolink; // @todo - please update
+using namespace isc::asiolink;
using namespace isc::util;
using namespace boost::asio;
#include <asiolink/io_endpoint.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief The \c UDPEndpoint class is a concrete derived class of
#include <exceptions/isc_assert.h>
-namespace isc { // @todo - please update
+namespace isc {
namespace asiolink {
/// \brief The \c UDPSocket class is a concrete derived class of \c IOAsioSocket
libkea_dns___la_LIBADD += $(top_builddir)/src/lib/util/libkea-util.la
libkea_dns___la_LIBADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
libkea_dns___la_LIBADD += $(CRYPTO_LIBS)
- // @todo - please update
+
# The following files used to be generated, but they are now part of the git tree:
# rrclass.h rrtype.h rrparamregistry.cc rdataclass.h rdataclass.cc
libkea_dns___la_SOURCES += rdataclass.h rrclass.h rrtype.h
#include <boost/shared_ptr.hpp>
using namespace isc::dns::rdata;
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using namespace std;
using boost::lexical_cast;
/// NOTE: If the header has already been parsed by a previous call
/// to this method, this method simply returns (i.e., it does not
/// read from the \c buffer).
- void parseHeader(isc::util::InputBuffer& buffer); // @todo - please update
+ void parseHeader(isc::util::InputBuffer& buffer);
/// \brief (Re)build a \c Message object from wire-format data.
///
/// that ongoing state information will not be lost if the object
/// that originated the asynchronous call falls out of scope.
typedef boost::shared_ptr<Message> MessagePtr;
-typedef boost::shared_ptr<const Message> ConstMessagePtr; // @todo - please update
+typedef boost::shared_ptr<const Message> ConstMessagePtr;
/// Insert the \c Message as a string into stream.
///
#include <cassert>
#include <vector>
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using isc::dns::name::internal::maptolower;
- // @todo - please update
+
using namespace std;
namespace isc {
#include <iostream>
#include <algorithm>
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using namespace isc::dns::name::internal;
using namespace std;
#include <dns/exceptions.h>
namespace isc {
-namespace dns { // @todo - please update
+namespace dns {
///
/// \brief A standard DNS module exception that is thrown if the name parser
/// encounters an empty label in the middle of a name.
#include <iostream>
#include <string>
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using namespace std;
#include <stdint.h>
namespace isc {
-namespace dns { // @todo - please update
+namespace dns {
class AbstractMessageRenderer;
class RRType;
class RRClass;
#include <string>
using namespace isc::dns;
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using namespace std;
#include <boost/shared_ptr.hpp>
using namespace isc::dns;
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using namespace isc::dns::rdata;
using namespace std;
using namespace std;
using namespace isc::dns;
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
namespace {
#include <string>
#include <ostream>
-using namespace isc::util; // @todo - please update
+using namespace isc::util;
using isc::dns::RRType;
using namespace std;
#include <util/filesystem.h>
#include <util/str.h>
- // @todo - please update
+
#include <log/log_messages.h>
#include <log/message_dictionary.h>
#include <log/message_exception.h>
#include <log/logger_support.h>
#include <log/message_dictionary.h>
#include <log/message_types.h>
- // @todo - please update
+
using namespace std;
namespace isc {
#include <log/message_types.h>
#include <log/interprocess/interprocess_sync_file.h>
#include <log/interprocess/interprocess_sync_null.h>
- // @todo - please update
+
// Note: as log4cplus and the Kea logger have many concepts in common, and
// thus many similar names, to disambiguate types we don't "use" the log4cplus
// namespace: instead, all log4cplus types are explicitly qualified.
AUTOMAKE_OPTIONS = subdir-objects
SUBDIRS = . io unittests tests python
- // @todo - please update
-AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib // @todo - please update
-AM_CPPFLAGS += $(BOOST_INCLUDES) // @todo - please update
+
+AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CXXFLAGS = $(KEA_CXXFLAGS)
- // @todo - please update
+
lib_LTLIBRARIES = libkea-util.la
libkea_util_la_SOURCES =
libkea_util_la_SOURCES += bigints.h
libkea_util_la_SOURCES += watched_thread.cc watched_thread.h
libkea_util_la_SOURCES += encode/encode.cc encode/encode.h
libkea_util_la_SOURCES += encode/utf8.cc encode/utf8.h
- // @todo - please update
+
libkea_util_la_LIBADD = $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
libkea_util_la_LDFLAGS = -no-undefined -version-info 83:0:0
// Copyright (C) 2009-2024 Internet Systems Consortium, Inc. ("ISC")
-// // @todo - please update
+//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
- // @todo - please update
+
#ifndef BUFFER_H
#define BUFFER_H
- // @todo - please update
-#include <exceptions/exceptions.h> // @todo - please update
- // @todo - please update
-#include <boost/shared_ptr.hpp> // @todo - please update
- // @todo - please update
+
+#include <exceptions/exceptions.h>
+
+#include <boost/shared_ptr.hpp>
+
#include <cstring>
#include <stdint.h>
#include <stdlib.h>
#include <vector>
-namespace isc { // @todo - please update
-namespace util { // @todo - please update
- // @todo - please update
+namespace isc {
+namespace util {
+
/// @brief The @c InputBuffer class is a buffer abstraction for
/// manipulating read-only data.
-/// // @todo - please update
+///
/// The main purpose of this class is to provide a safe placeholder
/// for examining wire-format data received from a network.
-/// // @todo - please update
+///
/// 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 Kea DNS library. One
/// common usage of this class for an application would therefore be
/// something like this:
-/// // @todo - please update
+///
/// @code
/// unsigned char buf[1024];
/// struct sockaddr addr;
/// InputBuffer buffer(buf, cc);
/// // pass the buffer to a DNS message object to parse the message
/// @endcode
-/// // @todo - please update
+///
/// Other Kea 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.
-/// // @todo - please update
+///
/// 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
/// 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.
-/// // @todo - please update
+///
/// 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
/// "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.
-/// // @todo - please update
+///
/// 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
/// base_ at the initial state, current_ == end_ when the whole buffer
/// was read. Even the difference of two pointers is a std::ptrdiff_t
/// it is safe to cast to a size_t because of the inequality.
-class InputBuffer { // @todo - please update
-public: // @todo - please update
+class InputBuffer {
+public:
/// @brief Constructor.
- /// // @todo - please update
+ ///
/// 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.
: base_(static_cast<const uint8_t*>(data)), current_(base_),
end_(base_ + len) {
}
- // @todo - please update
+
/// @brief Return the length of the data stored in the buffer.
size_t getLength() const {
return (static_cast<size_t>(end_ - base_));
size_t getPosition() const {
return (static_cast<size_t>(current_ - base_));
}
- // @todo - please update
+
/// @brief Set the read position of the buffer to the given value.
- /// // @todo - please update
+ ///
/// The new position must be in the valid range of the buffer;
/// otherwise an exception of class @c isc::OutOfRange will be thrown.
///
"InputBuffer::setPosition position is too large");
}
current_ = base_ + position;
- } // @todo - please update
- // @todo - please update
+ }
+
/// @brief Peek an unsigned 8-bit integer from the buffer and return it.
///
/// If the remaining length of the buffer is smaller than 8-bit,
}
/// @brief Read an unsigned 8-bit integer from the buffer and return it.
- /// // @todo - please update
+ ///
/// If the remaining length of the buffer is smaller than 8-bit,
/// an exception of class @c isc::OutOfRange will be thrown.
uint8_t readUint8() {
if (current_ + sizeof(uint16_t) > end_) {
isc_throw(OutOfRange,
"InputBuffer::peekUint16 read beyond end of buffer");
- } // @todo - please update
- // @todo - please update
+ }
+
uint16_t ret;
ret = (static_cast<uint16_t>(current_[0])) << 8;
ret |= (static_cast<uint16_t>(current_[1]));
return (ret);
- } // @todo - please update
+ }
/// @brief Read an unsigned 16-bit integer in network byte order
/// from the buffer, and return it.
- /// // @todo - please update
+ ///
/// If the remaining length of the buffer is smaller than 16-bit,
/// an exception of class @c isc::OutOfRange will be thrown.
uint16_t readUint16() {
return (ret);
}
- // @todo - please update
+
/// @brief Read an unsigned 32-bit integer in network byte order
/// from the buffer, and return it.
///
if (current_ + sizeof(uint32_t) > end_) {
isc_throw(OutOfRange,
"InputBuffer::peekUint32 read beyond end of buffer");
- } // @todo - please update
- // @todo - please update
+ }
+
uint32_t ret;
ret = (static_cast<uint32_t>(current_[0])) << 24;
ret |= (static_cast<uint32_t>(current_[1])) << 16;
ret |= (static_cast<uint32_t>(current_[2])) << 8;
ret |= (static_cast<uint32_t>(current_[3]));
- // @todo - please update
+
return (ret);
- } // @todo - please update
+ }
/// @brief Read an unsigned 32-bit integer in network byte order
/// from the buffer, and return it.
- /// // @todo - please update
+ ///
/// If the remaining length of the buffer is smaller than 32-bit,
/// an exception of class @c isc::OutOfRange will be thrown.
uint32_t readUint32() {
return (ret);
}
- // @todo - please update
+
/// @brief Peek data of the specified length from the buffer and
/// copy it to the caller supplied buffer.
///
if (current_ + len > end_) {
isc_throw(OutOfRange,
"InputBuffer::peekData read beyond end of buffer");
- } // @todo - please update
- // @todo - please update
+ }
+
static_cast<void>(std::memmove(data, current_, len));
- } // @todo - please update
+ }
/// @brief Read data of the specified length from the buffer and
/// copy it to the caller supplied buffer.
- /// // @todo - please update
+ ///
/// 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::OutOfRange
if (current_ + len > end_) {
isc_throw(OutOfRange,
"InputBuffer::peekVector read beyond end of buffer");
- } // @todo - please update
- // @todo - please update
+ }
+
data.resize(len);
peekData(&data[0], len);
- } // @todo - please update
- // @todo - please update
+ }
+
/// @brief Read specified number of bytes as a vector.
///
/// If specified buffer is too short, it will be expanded using
current_ += len;
}
-private: // @todo - please update
+private:
/// @brief Base of the buffer.
const uint8_t* base_;
/// @brief Current poisition in the buffer.
const uint8_t* current_;
- // @todo - please update
+
/// @brief End of the buffer (address of the byte after).
const uint8_t* end_;
-}; // @todo - please update
- // @todo - please update
+};
+
/// @brief Type of pointers to input buffer.
typedef boost::shared_ptr<InputBuffer> InputBufferPtr;
/// @brief The @c OutputBuffer class is a buffer abstraction for
/// manipulating mutable data.
-/// // @todo - please update
-/// The main purpose of this class is to provide a safe workplace for // @todo - please update
-/// constructing wire-format data to be sent out to a network. Here, // @todo - please update
+///
+/// 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.
-/// // @todo - please update
+///
/// 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:
-/// // @todo - please update
+///
/// @code
/// OutputBuffer buffer(4096); // give a sufficiently large initial size
/// // pass the buffer to a DNS message object to construct a wire-format
/// struct sockaddr to;
/// sendto(s, buffer.getDataAsVoidPtr(), buffer.getLength(), 0, &to, sizeof(to));
/// @endcode
-/// // @todo - please update
+///
/// where the @c getData() (in fact @c getDataAsVoidPtr()) 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
/// 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.
-/// // @todo - please update
+///
/// 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
/// 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.
-/// // @todo - please update
+///
/// 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
/// 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.
-/// // @todo - please update
+///
/// 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 concrete derived class. That way we can
/// 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 // @todo - please update
+/// 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 { // @todo - please update
-public: // @todo - please update
+class OutputBuffer {
+public:
/// @brief Constructor.
- /// // @todo - please update
+ ///
/// @param len The initial allocated length of the buffer in bytes.
OutputBuffer(size_t len) : buffer_() {
if (len != 0) {
/// @brief Destructor.
~OutputBuffer() = default;
- // @todo - please update
+
/// @brief Assignment operator.
///
/// @param other Object to copy into "this".
}
/// @brief Return a pointer to the head of the data stored in the buffer.
- /// // @todo - please update
+ ///
/// The caller can assume that the subsequent @c getLength() bytes
/// are identical to the stored data of the buffer.
- /// // @todo - please update
+ ///
/// Note: The pointer returned by this method may be invalidated
/// after a subsequent write operation.
const uint8_t* getData() const {
}
/// @brief Return the value of the buffer at the specified position.
- /// // @todo - please update
+ ///
/// @c pos must specify the valid position of the buffer;
/// otherwise an exception class of @c isc::OutOfRange will
/// be thrown.
- /// // @todo - please update
+ ///
/// @param pos The position in the buffer to be returned.
uint8_t operator[](size_t pos) const {
if (pos >= buffer_.size()) {
<< ") >= size (" << buffer_.size() << ")");
}
return (buffer_[pos]);
- } // @todo - please update
+ }
/// @brief Return the buffer.
///
const std::vector<uint8_t>& getVector() const {
return (buffer_);
}
- // @todo - please update
+
/// @brief Insert a specified length of gap at the end of the buffer.
- /// // @todo - please update
+ ///
/// 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
void skip(size_t len) {
buffer_.resize(buffer_.size() + len);
}
- // @todo - please update
+
/// @brief Trim the specified length of data from the end of the buffer.
- /// // @todo - please update
+ ///
/// The specified length must not exceed the current data size of
/// the buffer; otherwise an exception of class @c isc::OutOfRange
/// will be thrown.
- /// // @todo - please update
+ ///
/// @param len The length of data that should be trimmed.
void trim(size_t len) {
if (len > buffer_.size()) {
isc_throw(OutOfRange,
"OutputBuffer::trim length too large from output buffer");
- } // @todo - please update
+ }
buffer_.resize(buffer_.size() - len);
- } // @todo - please update
+ }
/// @brief Clear buffer content.
void clear() {
}
/// @brief Write an unsigned 8-bit integer into the buffer.
- /// // @todo - please update
+ ///
/// @param data The 8-bit integer to be written into the buffer.
void writeUint8(uint8_t data) {
buffer_.push_back(data);
}
- // @todo - please update
+
/// @brief Write an unsigned 8-bit integer into the buffer.
- /// // @todo - please update
- /// The position must be lower than the size of the buffer, // @todo - please update
+ ///
+ /// The position must be lower than the size of the buffer,
/// otherwise an exception of class @c isc::OutOfRange will
/// be thrown.
- /// // @todo - please update
+ ///
/// @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) { // @todo - please update
+ void writeUint8At(uint8_t data, size_t pos) {
if (pos + sizeof(data) > buffer_.size()) {
isc_throw(OutOfRange,
"OutputBuffer::writeUint8At write at invalid position");
- } // @todo - please update
+ }
buffer_[pos] = data;
- } // @todo - please update
- // @todo - please update
+ }
+
/// @brief Write an unsigned 16-bit integer in host byte order
/// into the buffer in network byte order.
- /// // @todo - please update
+ ///
/// @param data The 16-bit integer to be written into the buffer.
void writeUint16(uint16_t data) {
buffer_.push_back(static_cast<uint8_t>((data & 0xff00U) >> 8));
buffer_.push_back(static_cast<uint8_t>(data & 0x00ffU));
- } // @todo - please update
+ }
/// @brief Write an unsigned 16-bit integer in host byte order at
/// the specified position of the buffer in network byte order.
- /// // @todo - please update
+ ///
/// 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::OutOfRange will be thrown.
- /// Note also that this method never extends the buffer. // @todo - please update
- /// // @todo - please update
+ /// 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) > buffer_.size()) {
isc_throw(OutOfRange,
"OutputBuffer::writeUint16At write at invalid position");
- } // @todo - please update
- // @todo - please update
+ }
+
buffer_[pos] = static_cast<uint8_t>((data & 0xff00U) >> 8);
buffer_[pos + 1] = static_cast<uint8_t>(data & 0x00ffU);
- } // @todo - please update
+ }
/// @brief Write an unsigned 32-bit integer in host byte order
- /// into the buffer in network byte order. // @todo - please update
- /// // @todo - please update
+ /// into the buffer in network byte order.
+ ///
/// @param data The 32-bit integer to be written into the buffer.
void writeUint32(uint32_t data) {
buffer_.push_back(static_cast<uint8_t>((data & 0xff000000) >> 24));
buffer_.push_back(static_cast<uint8_t>((data & 0x00ff0000) >> 16));
buffer_.push_back(static_cast<uint8_t>((data & 0x0000ff00) >> 8));
buffer_.push_back(static_cast<uint8_t>(data & 0x000000ff));
- } // @todo - please update
+ }
/// @brief Write an unsigned 64-bit integer in host byte order
/// into the buffer in network byte order.
}
/// @brief Copy an arbitrary length of data into the buffer.
- /// // @todo - please update
- /// No conversion on the copied data is performed. // @todo - please update
- /// // @todo - please update
+ ///
+ /// 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* ptr = static_cast<const uint8_t*>(data);
buffer_.insert(buffer_.end(), ptr, ptr + len);
- } // @todo - please update
+ }
-private: // @todo - please update
+private:
/// The actual data.
std::vector<uint8_t> buffer_;
-}; // @todo - please update
- // @todo - please update
+};
+
/// @brief Type of pointers to output buffers.
-typedef boost::shared_ptr<OutputBuffer> OutputBufferPtr; // @todo - please update
- // @todo - please update
+typedef boost::shared_ptr<OutputBuffer> OutputBufferPtr;
+
} // end of namespace util
} // end of namespace isc
- // @todo - please update
+
#endif // BUFFER_H
// Copyright (C) 2010-2019 Internet Systems Consortium, Inc. ("ISC")
-// // @todo - please update
+//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
- // @todo - please update
+
#include <config.h>
#include <cstring>
#include <cstdlib>
-#include <sys/types.h> // @todo - please update
-#include <sys/socket.h> // @todo - please update
-#include <sys/uio.h> // @todo - please update
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
#include <errno.h>
#include <stdlib.h> // for malloc and free
#include <unistd.h>
#include <util/io/fd_share.h>
- // @todo - please update
-namespace isc { // @todo - please update
+
+namespace isc {
namespace util {
namespace io {
- // @todo - please update
+
namespace {
// Not all OSes support advanced CMSG macros: CMSG_LEN and CMSG_SPACE.
// In order to ensure as much portability as possible, we provide wrapper
return ((char*)cmsgp - (char*)msg.msg_control);
} else {
return (0);
- } // @todo - please update
+ }
#endif // CMSG_SPACE
}
}
- // @todo - please update
-int // @todo - please update
+
+int
recv_fd(const int sock) {
- struct msghdr msghdr; // @todo - please update
+ struct msghdr msghdr;
struct iovec iov_dummy;
unsigned char dummy_data;
- // @todo - please update
+
iov_dummy.iov_base = &dummy_data;
iov_dummy.iov_len = sizeof(dummy_data);
- msghdr.msg_name = NULL; // @todo - please update
- msghdr.msg_namelen = 0; // @todo - please update
+ msghdr.msg_name = NULL;
+ msghdr.msg_namelen = 0;
msghdr.msg_iov = &iov_dummy;
- msghdr.msg_iovlen = 1; // @todo - please update
- msghdr.msg_flags = 0; // @todo - please update
+ msghdr.msg_iovlen = 1;
+ msghdr.msg_flags = 0;
msghdr.msg_controllen = cmsg_space(sizeof(int));
msghdr.msg_control = malloc(msghdr.msg_controllen);
if (msghdr.msg_control == NULL) {
return (FD_SYSTEM_ERROR);
}
return (new_fd);
-} // @todo - please update
- // @todo - please update
-int // @todo - please update
+}
+
+int
send_fd(const int sock, const int fd) {
- struct msghdr msghdr; // @todo - please update
+ struct msghdr msghdr;
struct iovec iov_dummy;
unsigned char dummy_data = 0;
- // @todo - please update
+
iov_dummy.iov_base = &dummy_data;
iov_dummy.iov_len = sizeof(dummy_data);
- msghdr.msg_name = NULL; // @todo - please update
- msghdr.msg_namelen = 0; // @todo - please update
+ msghdr.msg_name = NULL;
+ msghdr.msg_namelen = 0;
msghdr.msg_iov = &iov_dummy;
- msghdr.msg_iovlen = 1; // @todo - please update
- msghdr.msg_flags = 0; // @todo - please update
+ msghdr.msg_iovlen = 1;
+ msghdr.msg_flags = 0;
msghdr.msg_controllen = cmsg_space(sizeof(int));
msghdr.msg_control = malloc(msghdr.msg_controllen);
if (msghdr.msg_control == NULL) {
return (FD_OTHER_ERROR);
}
std::memset(msghdr.msg_control, 0, msghdr.msg_controllen);
- // @todo - please update
+
struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msghdr);
cmsg->cmsg_len = cmsg_len(sizeof(int));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
std::memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
- // @todo - please update
+
const int ret = sendmsg(sock, &msghdr, 0);
free(msghdr.msg_control);
return (ret >= 0 ? 0 : FD_SYSTEM_ERROR);
-} // @todo - please update
- // @todo - please update
+}
+
} // namespace io
} // namespace util
} // namespace isc
// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
-// // @todo - please update
+//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
- // @todo - please update
+
#ifndef FD_SHARE_H
#define FD_SHARE_H
- // @todo - please update
+
/**
* \file fd_share.h
* \short Support to transfer file descriptors between processes.
* \todo This interface is very C-ish. Should we have some kind of exceptions?
*/
-namespace isc { // @todo - please update
+namespace isc {
namespace util {
namespace io {
- // @todo - please update
+
const int FD_SYSTEM_ERROR = -2;
const int FD_OTHER_ERROR = -1;
* not work with a pipe.
*/
int recv_fd(const int sock);
- // @todo - please update
+
/**
* \short Sends a file descriptor.
* This sends a file descriptor over an unix domain socket. This is the
* file descriptor.
*/
int send_fd(const int sock, const int fd);
- // @todo - please update
+
} // namespace io
} // namespace util
} // namespace isc
- // @todo - please update
+
#endif // FD_SHARE_H
// Copyright (C) 2009-2024 Internet Systems Consortium, Inc. ("ISC")
-// // @todo - please update
+//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
- // @todo - please update
+
#include <config.h>
-#include <exceptions/exceptions.h> // @todo - please update
+#include <exceptions/exceptions.h>
#include <util/buffer.h>
- // @todo - please update
+
#ifdef EXPECT_DEATH
#include <util/unittests/resource.h>
#include <util/unittests/check_valgrind.h>
#endif /* EXPECT_DEATH */
- // @todo - please update
+
#include <gtest/gtest.h>
- // @todo - please update
-using namespace isc; // @todo - please update
+
+using namespace isc;
using namespace isc::util;
- // @todo - please update
-namespace { // @todo - please update
- // @todo - please update
-class BufferTest : public ::testing::Test { // @todo - please update
-protected: // @todo - please update
- BufferTest() : ibuffer(testdata, sizeof(testdata)), obuffer(0), // @todo - please update
+
+namespace {
+
+class BufferTest : public ::testing::Test {
+protected:
+ BufferTest() : ibuffer(testdata, sizeof(testdata)), obuffer(0),
expected_size(0) {
- data16 = (2 << 8) | 3; // @todo - please update
- data32 = (4 << 24) | (5 << 16) | (6 << 8) | 7; // @todo - please update
- memset(vdata, 0, sizeof(testdata)); // @todo - please update
- } // @todo - please update
- // @todo - please update
- InputBuffer ibuffer; // @todo - please update
- OutputBuffer obuffer; // @todo - please update
- static const uint8_t testdata[5]; // @todo - please update
- uint8_t vdata[sizeof(testdata)]; // @todo - please update
- size_t expected_size; // @todo - please update
- uint16_t data16; // @todo - please update
- uint32_t data32; // @todo - please update
+ data16 = (2 << 8) | 3;
+ data32 = (4 << 24) | (5 << 16) | (6 << 8) | 7;
+ memset(vdata, 0, sizeof(testdata));
+ }
+
+ InputBuffer ibuffer;
+ OutputBuffer obuffer;
+ static const uint8_t testdata[5];
+ uint8_t vdata[sizeof(testdata)];
+ size_t expected_size;
+ uint16_t data16;
+ uint32_t data32;
std::vector<uint8_t> datav;
-}; // @todo - please update
- // @todo - please update
-const uint8_t BufferTest::testdata[5] = {1, 2, 3, 4, 5}; // @todo - please update
- // @todo - please update
+};
+
+const uint8_t BufferTest::testdata[5] = {1, 2, 3, 4, 5};
+
TEST_F(BufferTest, outputBufferClear) {
obuffer.writeData(testdata, sizeof(testdata));
obuffer.clear();
ASSERT_THROW(obuffer.trim(3), OutOfRange);
}
-TEST_F(BufferTest, inputBufferRead) { // @todo - please update
+TEST_F(BufferTest, inputBufferRead) {
ASSERT_EQ(5, ibuffer.getLength());
ASSERT_EQ(1, ibuffer.peekUint8());
ASSERT_EQ(0, ibuffer.getPosition());
ASSERT_EQ(data16, ibuffer.readUint16());
ASSERT_EQ((2 << 8) | 3, data16);
ASSERT_EQ(3, ibuffer.getPosition());
- ibuffer.setPosition(1); // @todo - please update
+ ibuffer.setPosition(1);
ASSERT_EQ(1, ibuffer.getPosition());
data32 = ibuffer.peekUint32();
ASSERT_EQ(1, ibuffer.getPosition());
ASSERT_EQ(data32, ibuffer.readUint32());
ASSERT_EQ((2 << 24) | (3 << 16) | (4 << 8) | 5, data32);
- ibuffer.setPosition(0); // @todo - please update
- memset(vdata, 0, sizeof(vdata)); // @todo - please update
+ ibuffer.setPosition(0);
+ memset(vdata, 0, sizeof(vdata));
ibuffer.peekData(vdata, sizeof(vdata));
ASSERT_EQ(0, memcmp(vdata, testdata, sizeof(testdata)));
ASSERT_EQ(0, ibuffer.getPosition());
memset(vdata, 0, sizeof(vdata));
- ibuffer.readData(vdata, sizeof(vdata)); // @todo - please update
+ ibuffer.readData(vdata, sizeof(vdata));
ASSERT_EQ(0, memcmp(vdata, testdata, sizeof(testdata)));
ASSERT_EQ(sizeof(vdata), ibuffer.getPosition());
ibuffer.setPosition(0);
ASSERT_EQ(sizeof(vdata), datav.size());
ASSERT_EQ(0, memcmp(&vdata[0], testdata, sizeof(testdata)));
ASSERT_EQ(sizeof(vdata), ibuffer.getPosition());
-} // @todo - please update
- // @todo - please update
+}
+
TEST_F(BufferTest, outputBufferReadAt) {
obuffer.writeData(testdata, sizeof(testdata));
for (size_t i = 0; i < sizeof(testdata); ++i) {
ASSERT_EQ(testdata[i], obuffer[i]);
}
ASSERT_THROW(obuffer[sizeof(testdata)], isc::OutOfRange);
-} // @todo - please update
- // @todo - please update
+}
+
TEST_F(BufferTest, inputBufferReadVectorChunks) {
std::vector<uint8_t> vec;
ASSERT_NO_THROW(ibuffer.readVector(vec, 2));
ASSERT_EQ(2, vec.size());
ASSERT_EQ(0, memcmp(&vec[0], &testdata[3], 2));
-} // @todo - please update
- // @todo - please update
-TEST_F(BufferTest, outputBufferWrite) { // @todo - please update
- obuffer.writeUint8(1); // @todo - please update
- expected_size += sizeof(uint8_t); // @todo - please update
+}
+
+TEST_F(BufferTest, outputBufferWrite) {
+ obuffer.writeUint8(1);
+ expected_size += sizeof(uint8_t);
ASSERT_EQ(expected_size, obuffer.getLength());
const uint8_t* cp = obuffer.getData();
ASSERT_EQ(1, *cp);
- // @todo - please update
- obuffer.writeUint16(data16); // @todo - please update
- expected_size += sizeof(data16); // @todo - please update
+
+ obuffer.writeUint16(data16);
+ expected_size += sizeof(data16);
cp = obuffer.getData();
ASSERT_EQ(expected_size, obuffer.getLength());
ASSERT_EQ(2, *(cp + 1));
ASSERT_EQ(3, *(cp + 2));
- // @todo - please update
- obuffer.writeUint32(data32); // @todo - please update
- expected_size += sizeof(data32); // @todo - please update
+
+ obuffer.writeUint32(data32);
+ expected_size += sizeof(data32);
cp = obuffer.getData();
ASSERT_EQ(expected_size, obuffer.getLength());
ASSERT_EQ(4, *(cp + 3));
ASSERT_EQ(5, *(cp + 4));
ASSERT_EQ(6, *(cp + 5));
ASSERT_EQ(7, *(cp + 6));
- // @todo - please update
- obuffer.writeData(testdata, sizeof(testdata)); // @todo - please update
- expected_size += sizeof(testdata); // @todo - please update
+
+ obuffer.writeData(testdata, sizeof(testdata));
+ expected_size += sizeof(testdata);
ASSERT_EQ(expected_size, obuffer.getLength());
cp = obuffer.getData();
ASSERT_EQ(0, memcmp(cp + 7, testdata, sizeof(testdata)));
expected.insert(expected.end(), testdata, testdata + sizeof(testdata));
ASSERT_EQ(expected_size, expected.size());
ASSERT_EQ(0, memcmp(&expected[0], &datav[0], expected_size));
-} // @todo - please update
- // @todo - please update
+}
+
TEST_F(BufferTest, outputBufferWriteAt) {
- obuffer.writeUint32(data32); // @todo - please update
- expected_size += sizeof(data32); // @todo - please update
- // @todo - please update
- // overwrite 2nd byte // @todo - please update
- obuffer.writeUint8At(4, 1); // @todo - please update
+ obuffer.writeUint32(data32);
+ expected_size += sizeof(data32);
+
+ // overwrite 2nd byte
+ obuffer.writeUint8At(4, 1);
ASSERT_EQ(expected_size, obuffer.getLength()); // length shouldn't change
const uint8_t* cp = obuffer.getData();
ASSERT_EQ(4, *(cp + 1));
- // @todo - please update
- // overwrite 2nd and 3rd bytes // @todo - please update
- obuffer.writeUint16At(data16, 1); // @todo - please update
+
+ // overwrite 2nd and 3rd bytes
+ obuffer.writeUint16At(data16, 1);
ASSERT_EQ(expected_size, obuffer.getLength()); // length shouldn't change
cp = obuffer.getData();
ASSERT_EQ(2, *(cp + 1));
ASSERT_EQ(3, *(cp + 2));
- // @todo - please update
- // overwrite 3rd and 4th bytes // @todo - please update
- obuffer.writeUint16At(data16, 2); // @todo - please update
+
+ // overwrite 3rd and 4th bytes
+ obuffer.writeUint16At(data16, 2);
ASSERT_EQ(expected_size, obuffer.getLength());
cp = obuffer.getData();
ASSERT_EQ(2, *(cp + 2));
ASSERT_FALSE(memcmp(exp_val2, obuffer.getData(), sizeof(uint64_t)));
}
-} // @todo - please update
+}