Commit 2808941e authored by chenzhengzhang's avatar chenzhengzhang
Browse files

[trac1113] commit minfo rdata

parent 0b98878e
......@@ -51,6 +51,8 @@ EXTRA_DIST += rdata/generic/soa_6.cc
EXTRA_DIST += rdata/generic/soa_6.h
EXTRA_DIST += rdata/generic/txt_16.cc
EXTRA_DIST += rdata/generic/txt_16.h
EXTRA_DIST += rdata/generic/minfo_14.cc
EXTRA_DIST += rdata/generic/minfo_14.h
EXTRA_DIST += rdata/hs_4/a_1.cc
EXTRA_DIST += rdata/hs_4/a_1.h
EXTRA_DIST += rdata/in_1/a_1.cc
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <string>
#include <sstream>
#include <util/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
using namespace std;
using namespace isc::dns;
// BEGIN_ISC_NAMESPACE
// BEGIN_RDATA_NAMESPACE
/// \brief Constructor from string.
///
/// \c minfo_str must be formatted as follows:
/// \code <rmailbox name> <emailbox name>
/// \endcode
/// where both fields must represent a valid domain name.
///
/// An example of valid string is:
/// \code "rmail.example.com. email.example.com." \endcode
///
/// <b>Exceptions</b>
///
/// If <rmailbox name> or <emailbox name> if not a valid domain name, a
/// corresponding exception from the \c Name class will be thrown;
/// If the number of RDATA fields (must be 2) is incorrect, an exception of
/// class \c InvalidRdataText will be thrown.
/// This constructor internally involves resource allocation, and if it
/// fails a corresponding standard exception std::bad_alloc will be throw.
MINFO::MINFO(const std::string& minfo_str) :
// We cannot construct both names in the initialization list due to the
// necessary text processing, so we have to initialize them with a dummy
// name and replace them later.
rmailbox_(Name::ROOT_NAME()), emailbox_(Name::ROOT_NAME())
{
istringstream iss(minfo_str);
string rmailbox_str, emailbox_str;
iss >> rmailbox_str >> emailbox_str;
// Validation: A valid MINFO RR must have exactly two fields.
if (iss.bad() || iss.fail()) {
isc_throw(InvalidRdataText, "Invalid MINFO text: " << minfo_str);
}
if (!iss.eof()) {
isc_throw(InvalidRdataText, "Invalid MINFO text (redundant field): "
<< minfo_str);
}
rmailbox_ = Name(rmailbox_str);
emailbox_ = Name(emailbox_str);
}
/// \brief Constructor from wire-format data.
///
/// This constructor doesn't check the validity of the second parameter (rdata
/// length) for parsing.
/// If necessary, the caller will check consistency.
///
/// \exception std::bad_alloc Memory allocation for names fails.
/// \exception Other The constructor of the \c Name class will throw if the
/// names in the wire is invalid.
MINFO::MINFO(InputBuffer& buffer, size_t) : rmailbox_(buffer), emailbox_(buffer) {
}
/// \brief Copy constructor.
///
/// \exception std::bad_alloc Memory allocation fails in copying internal
/// member variables (this should be very rare).
MINFO::MINFO(const MINFO& other) :
Rdata(), rmailbox_(other.rmailbox_), emailbox_(other.emailbox_)
{}
/// \brief Convert the \c MINFO to a string.
///
/// The output of this method is formatted as described in the "from string"
/// constructor (\c MINFO(const std::string&))).
///
/// If internal resource allocation fails, a corresponding
/// standard exception will be thrown.
///
/// \return A \c string object that represents the \c MINFO object.
std::string
MINFO::toText() const {
return (rmailbox_.toText() + " " + emailbox_.toText());
}
/// \brief Render the \c MINFO in the wire format without name compression.
///
/// If internal resource allocation fails, a corresponding standard
/// exception will be thrown.
/// This method never throws an exception otherwise.
///
/// \param buffer An output buffer to store the wire data.
void
MINFO::toWire(OutputBuffer& buffer) const {
rmailbox_.toWire(buffer);
emailbox_.toWire(buffer);
}
/// \brief Render the \c MINFO in the wire format with taking into account
/// compression.
///
/// As specified in RFC1035, the rmailbox and emailbox fields (domain names)
/// will be compressed.
///
/// If internal resource allocation fails, a corresponding
/// standard exception will be thrown.
/// This method never throws an exception otherwise.
///
/// \param renderer DNS message rendering context that encapsulates the
/// output buffer and name compression information.
void
MINFO::toWire(AbstractMessageRenderer& renderer) const {
renderer.writeName(rmailbox_);
renderer.writeName(emailbox_);
}
/// \brief Compare two instances of \c MINFO RDATA.
///
/// See documentation in \c Rdata.
int
MINFO::compare(const Rdata& other) const {
const MINFO& other_minfo = dynamic_cast<const MINFO&>(other);
const int cmp = compareNames(rmailbox_, other_minfo.rmailbox_);
if (cmp != 0) {
return (cmp);
}
return (compareNames(emailbox_, other_minfo.emailbox_));
}
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
// 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.
// BEGIN_HEADER_GUARD
#include <string>
#include <dns/name.h>
#include <dns/rdata.h>
// BEGIN_ISC_NAMESPACE
// BEGIN_COMMON_DECLARATIONS
// END_COMMON_DECLARATIONS
// BEGIN_RDATA_NAMESPACE
/// \brief \c rdata::generic::MINFO class represents the MINFO RDATA as
/// defined in RFC1035.
///
/// This class implements the basic interfaces inherited from the abstract
/// \c rdata::Rdata class, and provides trivial accessors specific to the
/// MINFO RDATA.
class MINFO : public Rdata {
public:
// BEGIN_COMMON_MEMBERS
// END_COMMON_MEMBERS
/// We use the default copy constructor and assignment operator.
/// \brief Constructor from RDATA field parameters.
///
/// The parameters are a straightforward mapping of %MINFO RDATA
/// fields as defined in RFC1035.
MINFO(const Name& rmailbox, const Name& emailbox) :
rmailbox_(rmailbox), emailbox_(emailbox)
{}
/// \brief Return the value of the rmailbox field.
///
/// This method normally does not throw an exception, but if resource
/// allocation for the returned \c Name object fails, a corresponding
/// standard exception will be thrown.
///
/// \note
/// Unlike the case of some other RDATA classes (such as
/// \c NS::getNSName()), this method constructs a new \c Name object
/// and returns it, instead of returning a reference to a \c Name object
/// internally maintained in the class (which is a private member).
/// This is based on the observation that this method will be rarely used
/// and even when it's used it will not be in a performance context
/// (for example, a recursive resolver won't need this field in its
/// resolution process). By returning a new object we have flexibility of
/// changing the internal representation without the risk of changing
/// the interface or method property.
/// The same note applies to the \c getEmailbox() method.
Name getRmailbox() const { return (rmailbox_); }
/// \brief Return the value of the emailbox field.
///
/// This method normally does not throw an exception, but if resource
/// allocation for the returned \c Name object fails, a corresponding
/// standard exception will be thrown.
Name getEmailbox() const { return (emailbox_); }
private:
Name rmailbox_;
Name emailbox_;
};
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
// END_HEADER_GUARD
// Local Variables:
// mode: c++
// End:
......@@ -12,13 +12,13 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// BEGIN_HEADER_GUARD
#include <stdint.h>
#include <dns/name.h>
#include <dns/rdata.h>
// BEGIN_HEADER_GUARD
// BEGIN_ISC_NAMESPACE
// BEGIN_COMMON_DECLARATIONS
......
......@@ -42,6 +42,7 @@ run_unittests_SOURCES += rdata_nsec3param_unittest.cc
run_unittests_SOURCES += rdata_rrsig_unittest.cc
run_unittests_SOURCES += rdata_rp_unittest.cc
run_unittests_SOURCES += rdata_srv_unittest.cc
run_unittests_SOURCES += rdata_minfo_unittest.cc
run_unittests_SOURCES += rdata_tsig_unittest.cc
run_unittests_SOURCES += rrset_unittest.cc rrsetlist_unittest.cc
run_unittests_SOURCES += question_unittest.cc
......
......@@ -102,6 +102,7 @@ EXTRA_DIST += rdata_rp_fromWire5.spec rdata_rp_fromWire6.spec
EXTRA_DIST += rdata_rp_toWire1.spec rdata_rp_toWire2.spec
EXTRA_DIST += rdata_soa_fromWire rdata_soa_toWireUncompressed.spec
EXTRA_DIST += rdata_srv_fromWire
EXTRA_DIST += rdata_minfo_fromWire
EXTRA_DIST += rdata_txt_fromWire1 rdata_txt_fromWire2.spec
EXTRA_DIST += rdata_txt_fromWire3.spec rdata_txt_fromWire4.spec
EXTRA_DIST += rdata_txt_fromWire5.spec rdata_unknown_fromWire
......
#
# various kinds of MINFO RDATA stored in an input buffer
#
# RDLENGHT=27 bytes
# 0 1
00 1c
# 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2(bytes)
04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07 65 6d
# 3 4 5 6 7 8 9
61 69 6c 62 78 c0 07
#
# compressed name
# RDLENGHT=04 bytes
#30 1
00 04
# 2 3 4 5(bytes)
c0 02 c0 14
#
# length too short
# 6 7
00 03
# 8 9 40 1(bytes)
c0 02 c0 14
#
# length too long
# 2 3
00 19
# 4 5 6 7(bytes)
c0 02 c0 14
#
# incomplete target name
# 8 9
00 13
#50 1 2 3 4 5 6 7 8 9 60 1 2 3 4 5 6 7 8 (bytes)
04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment