Commit a6219d83 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

moved the Opcode class declarations and definitions to separate files.

also fixed a potential bug in pydnspp where message.set_opcode() could leave a dangling reference.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac351@3034 e5f2f494-b856-4b98-b285-d166d9295462
parent 16c15276
......@@ -28,6 +28,7 @@
#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/question.h>
#include <dns/opcode.h>
#include <dns/rrset.h>
#include <dns/rrttl.h>
#include <dns/message.h>
......
......@@ -22,6 +22,7 @@
#include <dns/name.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
#include <dns/opcode.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
......@@ -114,7 +115,7 @@ protected:
AuthSrvTest() : server(true, xfrout),
request_message(Message::RENDER),
parse_message(Message::PARSE), default_qid(0x1035),
opcode(Opcode(Opcode::QUERY())), qname("www.example.com"),
opcode(Opcode::QUERY()), qname("www.example.com"),
qclass(RRClass::IN()), qtype(RRType::A()),
io_message(NULL), endpoint(NULL), request_obuffer(0),
request_renderer(request_obuffer),
......
......@@ -28,6 +28,7 @@
#include <dns/name.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
#include <dns/opcode.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <dns/rrset.h>
......
......@@ -26,6 +26,7 @@
#include <dns/name.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>
#include <dns/opcode.h>
#include <dns/rrtype.h>
#include <dns/rrclass.h>
#include <dns/question.h>
......
......@@ -22,6 +22,7 @@
#include <dns/buffer.h>
#include <dns/message.h>
#include <dns/name.h>
#include <dns/opcode.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
......
......@@ -26,6 +26,7 @@
#include <dns/message.h>
#include <dns/messagerenderer.h>
#include <dns/question.h>
#include <dns/opcode.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
......
......@@ -19,6 +19,7 @@
#include <dns/buffer.h>
#include <dns/message.h>
#include <dns/name.h>
#include <dns/opcode.h>
#include <dns/rrtype.h>
#include <dns/rrclass.h>
......
......@@ -68,6 +68,7 @@ libdns___la_SOURCES += util/hex.h
libdns___la_SOURCES += message.h message.cc
libdns___la_SOURCES += messagerenderer.h messagerenderer.cc
libdns___la_SOURCES += name.h name.cc
libdns___la_SOURCES += opcode.h opcode.cc
libdns___la_SOURCES += rdata.h rdata.cc
libdns___la_SOURCES += rrclass.cc
libdns___la_SOURCES += rrparamregistry.h
......
......@@ -32,6 +32,7 @@
#include <dns/message.h>
#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/opcode.h>
#include <dns/question.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
......@@ -135,25 +136,6 @@ const Opcode* opcodes[] = {
&Opcode::RESERVED15()
};
const char *opcodetext[] = {
"QUERY",
"IQUERY",
"STATUS",
"RESERVED3",
"NOTIFY",
"UPDATE",
"RESERVED6",
"RESERVED7",
"RESERVED8",
"RESERVED9",
"RESERVED10",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15"
};
const char *sectiontext[] = {
"QUESTION",
"ANSWER",
......@@ -162,11 +144,6 @@ const char *sectiontext[] = {
};
}
string
Opcode::toText() const {
return (opcodetext[code_]);
}
Rcode::Rcode(uint16_t code) : code_(code) {
if (code_ > MAX_RCODE) {
isc_throw(OutOfRange, "Rcode is too large to construct");
......@@ -202,6 +179,7 @@ public:
qid_t qid_;
Rcode rcode_;
const Opcode* opcode_;
Opcode opcode_placeholder_;
flags_t flags_;
bool dnssec_ok_;
......@@ -226,7 +204,7 @@ public:
};
MessageImpl::MessageImpl(Message::Mode mode) :
mode_(mode), rcode_(Rcode::NOERROR())
mode_(mode), rcode_(Rcode::NOERROR()), opcode_placeholder_(Opcode(0))
{
init();
}
......@@ -356,7 +334,8 @@ Message::setOpcode(const Opcode& opcode) {
isc_throw(InvalidMessageOperation,
"setOpcode performed in non-render mode");
}
impl_->opcode_ = &opcode;
impl_->opcode_placeholder_ = opcode;
impl_->opcode_ = &impl_->opcode_placeholder_;
}
unsigned int
......@@ -582,7 +561,9 @@ Message::parseHeader(InputBuffer& buffer) {
impl_->qid_ = buffer.readUint16();
const uint16_t codes_and_flags = buffer.readUint16();
impl_->opcode_ = opcodes[((codes_and_flags & OPCODE_MASK) >> OPCODE_SHIFT)];
impl_->opcode_placeholder_ =
Opcode((codes_and_flags & OPCODE_MASK) >> OPCODE_SHIFT);
impl_->opcode_ = &impl_->opcode_placeholder_;
impl_->rcode_ = rcodes[(codes_and_flags & RCODE_MASK)];
impl_->flags_ = (codes_and_flags & FLAG_MASK);
impl_->counts_[Section::QUESTION().getCode()] = buffer.readUint16();
......@@ -1004,11 +985,6 @@ Message::endSection(const Section& section) const {
impl_->rrsets_[sectionCodeToId(section)].end())));
}
ostream&
operator<<(ostream& os, const Opcode& opcode) {
return (os << opcode.toText());
}
ostream&
operator<<(ostream& os, const Rcode& rcode) {
return (os << rcode.toText());
......
......@@ -81,6 +81,7 @@ class InputBuffer;
class MessageRenderer;
class Message;
class MessageImpl;
class Opcode;
template <typename T>
struct SectionIteratorImpl;
......@@ -159,154 +160,6 @@ MessageFlag::CD()
return (f);
}
/// \brief The \c Opcode class objects represent standard OPCODEs
/// of the header section of DNS messages.
///
/// Note: since there are only 15 possible values, it may make more sense to
/// simply define an enum type to represent these values.
///
/// Constant objects are defined for standard flags.
class Opcode {
public:
uint16_t getCode() const { return (code_); }
bool operator==(const Opcode& other) const
{ return (code_ == other.code_); }
bool operator!=(const Opcode& other) const
{ return (code_ != other.code_); }
std::string toText() const;
static const Opcode& QUERY();
static const Opcode& IQUERY();
static const Opcode& STATUS();
static const Opcode& RESERVED3();
static const Opcode& NOTIFY();
static const Opcode& UPDATE();
static const Opcode& RESERVED6();
static const Opcode& RESERVED7();
static const Opcode& RESERVED8();
static const Opcode& RESERVED9();
static const Opcode& RESERVED10();
static const Opcode& RESERVED11();
static const Opcode& RESERVED12();
static const Opcode& RESERVED13();
static const Opcode& RESERVED14();
static const Opcode& RESERVED15();
private:
Opcode(uint16_t code) : code_(code) {}
uint16_t code_;
};
inline const Opcode&
Opcode::QUERY()
{
static Opcode c(0);
return (c);
}
inline const Opcode&
Opcode::IQUERY()
{
static Opcode c(1);
return (c);
}
inline const Opcode&
Opcode::STATUS()
{
static Opcode c(2);
return (c);
}
inline const Opcode&
Opcode::RESERVED3()
{
static Opcode c(3);
return (c);
}
inline const Opcode&
Opcode::NOTIFY()
{
static Opcode c(4);
return (c);
}
inline const Opcode&
Opcode::UPDATE()
{
static Opcode c(5);
return (c);
}
inline const Opcode&
Opcode::RESERVED6()
{
static Opcode c(6);
return (c);
}
inline const Opcode&
Opcode::RESERVED7()
{
static Opcode c(7);
return (c);
}
inline const Opcode&
Opcode::RESERVED8()
{
static Opcode c(8);
return (c);
}
inline const Opcode&
Opcode::RESERVED9()
{
static Opcode c(9);
return (c);
}
inline const Opcode&
Opcode::RESERVED10()
{
static Opcode c(10);
return (c);
}
inline const Opcode&
Opcode::RESERVED11()
{
static Opcode c(11);
return (c);
}
inline const Opcode&
Opcode::RESERVED12()
{
static Opcode c(12);
return (c);
}
inline const Opcode&
Opcode::RESERVED13()
{
static Opcode c(13);
return (c);
}
inline const Opcode&
Opcode::RESERVED14()
{
static Opcode c(14);
return (c);
}
inline const Opcode&
Opcode::RESERVED15()
{
static Opcode c(15);
return (c);
}
/// \brief The \c Rcode class objects represent standard Response Codes
/// (RCODEs) of the header section of DNS messages, and extended response
/// codes as defined in the EDNS specification.
......
// 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.
// $Id$
#include <string>
#include <ostream>
#include <exceptions/exceptions.h>
#include <dns/opcode.h>
using namespace std;
namespace isc {
namespace dns {
namespace {
const char *opcodetext[] = {
"QUERY",
"IQUERY",
"STATUS",
"RESERVED3",
"NOTIFY",
"UPDATE",
"RESERVED6",
"RESERVED7",
"RESERVED8",
"RESERVED9",
"RESERVED10",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15"
};
}
Opcode::Opcode(const uint16_t code) : code_(static_cast<CodeValue>(code)) {
if (code > MAX_CODE) {
isc_throw(OutOfRange,
"DNS Opcode is too large to construct: " << code);
}
}
string
Opcode::toText() const {
return (opcodetext[code_]);
}
ostream&
operator<<(std::ostream& os, const Opcode& opcode) {
return (os << opcode.toText());
}
}
}
/*
* 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.
*/
/* $Id$ */
#include <ostream>
#ifndef __OPCODE_H
#define __OPCODE_H 1
namespace isc {
namespace dns {
/// \brief The \c Opcode class objects represent standard OPCODEs
/// of the header section of DNS messages as defined in RFC1035.
///
/// Note: since there are only 15 possible values, it may make more sense to
/// simply define an enum type to represent these values.
///
/// Constant objects are defined for standard flags.
class Opcode {
public:
enum CodeValue {
QUERY_CODE = 0,
IQUERY_CODE = 1,
STATUS_CODE = 2,
RESERVED3_CODE = 3,
NOTIFY_CODE = 4,
UPDATE_CODE = 5,
RESERVED6_CODE = 6,
RESERVED7_CODE = 7,
RESERVED8_CODE = 8,
RESERVED9_CODE = 9,
RESERVED10_CODE = 10,
RESERVED11_CODE = 11,
RESERVED12_CODE = 12,
RESERVED13_CODE = 13,
RESERVED14_CODE = 14,
RESERVED15_CODE = 15,
MAX_CODE = 15
};
explicit Opcode(const uint16_t code);
CodeValue getCode() const { return (code_); }
bool equals(const Opcode& other) const
{ return (code_ == other.code_); }
bool operator==(const Opcode& other) const { return (equals(other)); }
bool nequals(const Opcode& other) const
{ return (code_ != other.code_); }
bool operator!=(const Opcode& other) const { return (nequals(other)); }
std::string toText() const;
static const Opcode& QUERY();
static const Opcode& IQUERY();
static const Opcode& STATUS();
static const Opcode& RESERVED3();
static const Opcode& NOTIFY();
static const Opcode& UPDATE();
static const Opcode& RESERVED6();
static const Opcode& RESERVED7();
static const Opcode& RESERVED8();
static const Opcode& RESERVED9();
static const Opcode& RESERVED10();
static const Opcode& RESERVED11();
static const Opcode& RESERVED12();
static const Opcode& RESERVED13();
static const Opcode& RESERVED14();
static const Opcode& RESERVED15();
private:
CodeValue code_;
};
inline const Opcode&
Opcode::QUERY() {
static Opcode c(0);
return (c);
}
inline const Opcode&
Opcode::IQUERY() {
static Opcode c(1);
return (c);
}
inline const Opcode&
Opcode::STATUS() {
static Opcode c(2);
return (c);
}
inline const Opcode&
Opcode::RESERVED3() {
static Opcode c(3);
return (c);
}
inline const Opcode&
Opcode::NOTIFY() {
static Opcode c(4);
return (c);
}
inline const Opcode&
Opcode::UPDATE() {
static Opcode c(5);
return (c);
}
inline const Opcode&
Opcode::RESERVED6() {
static Opcode c(6);
return (c);
}
inline const Opcode&
Opcode::RESERVED7() {
static Opcode c(7);
return (c);
}
inline const Opcode&
Opcode::RESERVED8() {
static Opcode c(8);
return (c);
}
inline const Opcode&
Opcode::RESERVED9() {
static Opcode c(9);
return (c);
}
inline const Opcode&
Opcode::RESERVED10() {
static Opcode c(10);
return (c);
}
inline const Opcode&
Opcode::RESERVED11() {
static Opcode c(11);
return (c);
}
inline const Opcode&
Opcode::RESERVED12() {
static Opcode c(12);
return (c);
}
inline const Opcode&
Opcode::RESERVED13() {
static Opcode c(13);
return (c);
}
inline const Opcode&
Opcode::RESERVED14() {
static Opcode c(14);
return (c);
}
inline const Opcode&
Opcode::RESERVED15() {
static Opcode c(15);
return (c);
}
/// \brief Insert the \c Opcode as a string into stream.
///
/// This method convert \c edns into a string and inserts it into the
/// output stream \c os.
///
/// \param os A \c std::ostream object on which the insertion operation is
/// performed.
/// \param opcode A reference to an \c Opcode object output by the operation.
/// \return A reference to the same \c std::ostream object referenced by
/// parameter \c os after the insertion operation.
std::ostream& operator<<(std::ostream& os, const Opcode& opcode);
}
}
#endif // OPCODE_H
// Local Variables:
// mode: c++
// End:
......@@ -15,6 +15,7 @@ EXTRA_DIST += messagerenderer_python.cc
EXTRA_DIST += message_python.cc
EXTRA_DIST += rrclass_python.cc
EXTRA_DIST += name_python.cc
EXTRA_DIST += opcode_python.cc
EXTRA_DIST += rrset_python.cc
EXTRA_DIST += question_python.cc
EXTRA_DIST += rrttl_python.cc
......
......@@ -191,280 +191,6 @@ MessageFlag_CD(s_MessageFlag* self UNUSED_PARAM) {
// End of MessageFlag wrapper
//
//
// Opcode
//
class s_Opcode : public PyObject {
public:
const Opcode* opcode;
};