Commit 77c158af authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

change method names to likeThis() based on coding guidelines


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@145 e5f2f494-b856-4b98-b285-d166d9295462
parent daff3480
......@@ -23,7 +23,7 @@ using isc::SingleBuffer;
// The interface should be revisited.
int
SingleBuffer::send_to(int s, const struct sockaddr& to, socklen_t to_len)
SingleBuffer::sendTo(int s, const struct sockaddr& to, socklen_t to_len)
{
int cc;
......@@ -32,7 +32,7 @@ SingleBuffer::send_to(int s, const struct sockaddr& to, socklen_t to_len)
}
int
SingleBuffer::recv_from(int s, struct sockaddr* from, socklen_t* from_len)
SingleBuffer::recvFrom(int s, struct sockaddr* from, socklen_t* from_len)
{
int cc;
......
......@@ -39,20 +39,20 @@ class Buffer {
public:
virtual ~Buffer() {}
virtual void reserve(size_t len) = 0;
virtual void write_data(const void *cp, size_t len) = 0;
virtual void write_uint32(uint32_t data) = 0;
virtual void write_uint16(uint16_t data) = 0;
virtual void write_uint16_at(uint16_t data, size_t pos) = 0;
virtual void write_uint8(uint8_t data) = 0;
virtual int send_to(int s, const struct sockaddr& to, socklen_t to_len) = 0;
virtual size_t get_size() const = 0;
virtual size_t get_space() const = 0;
virtual size_t get_current() const = 0;
virtual uint8_t read_uint8() = 0;
virtual uint16_t read_uint16() = 0;
virtual int recv_from(int s, struct sockaddr *from,
socklen_t *from_len) = 0;
virtual void writeData(const void *cp, size_t len) = 0;
virtual void writeUint32(uint32_t data) = 0;
virtual void writeUint16(uint16_t data) = 0;
virtual void writeUint16At(uint16_t data, size_t pos) = 0;
virtual void writeUint8(uint8_t data) = 0;
virtual int sendTo(int s, const struct sockaddr& to, socklen_t to_len) = 0;
virtual size_t getSize() const = 0;
virtual size_t getSpace() const = 0;
virtual size_t getCurrent() const = 0;
virtual uint8_t readUint8() = 0;
virtual uint16_t readUint16() = 0;
virtual int recvFrom(int s, struct sockaddr *from,
socklen_t *from_len) = 0;
};
// I/O Buffer with a single array-style storage
......@@ -64,24 +64,24 @@ public:
{
buf_.resize(len);
}
void write_data(const void *data, size_t len)
void writeData(const void *data, size_t len)
{
const uint8_t* cp = static_cast<const uint8_t*>(data);
buf_.insert(buf_.end(), cp, cp + len);
}
void write_uint32(uint32_t data)
void writeUint32(uint32_t data)
{
data = htonl(data);
uint8_t* cp = static_cast<uint8_t*>((void*)&data);
buf_.insert(buf_.end(), cp, cp + sizeof(uint32_t));
}
void write_uint16(uint16_t data)
void writeUint16(uint16_t data)
{
data = htons(data);
uint8_t* cp = static_cast<uint8_t*>((void*)&data);
buf_.insert(buf_.end(), cp, cp + sizeof(uint16_t));
}
void write_uint16_at(uint16_t data, size_t pos)
void writeUint16At(uint16_t data, size_t pos)
{
if (pos + sizeof(data) >= buf_.size())
throw isc::ISCBufferInvalidPosition();
......@@ -90,18 +90,18 @@ public:
uint8_t* cp = static_cast<uint8_t*>((void*)&data);
copy(cp, cp + sizeof(uint16_t), buf_.begin() + pos);
}
void write_uint8(uint8_t data)
void writeUint8(uint8_t data)
{
buf_.push_back(data);
}
int send_to(int s, const struct sockaddr& to, socklen_t to_len);
int sendTo(int s, const struct sockaddr& to, socklen_t to_len);
size_t get_size() const { return (buf_.size()); }
size_t get_space() const { return (buf_.size() - _readpos); }
size_t get_current() const { return (_readpos); }
uint8_t read_uint8();
uint16_t read_uint16();
int recv_from(int s, struct sockaddr* from, socklen_t* from_len);
size_t getSize() const { return (buf_.size()); }
size_t getSpace() const { return (buf_.size() - _readpos); }
size_t getCurrent() const { return (_readpos); }
uint8_t readUint8();
uint16_t readUint16();
int recvFrom(int s, struct sockaddr* from, socklen_t* from_len);
private:
size_t _readpos;
......@@ -109,7 +109,7 @@ private:
};
inline uint8_t
SingleBuffer::read_uint8()
SingleBuffer::readUint8()
{
if (_readpos + sizeof(uint8_t) > buf_.size())
throw ISCBufferInvalidPosition();
......@@ -118,7 +118,7 @@ SingleBuffer::read_uint8()
}
inline uint16_t
SingleBuffer::read_uint16()
SingleBuffer::readUint16()
{
uint16_t data;
......
......@@ -77,7 +77,7 @@ Message::initialize()
}
void
Message::add_rrset(section_t section, RRsetPtr rrsetp)
Message::addRrset(section_t section, RRsetPtr rrsetp)
{
if (section >= SECTION_MAX)
throw DNSInvalidMessageSection();
......@@ -87,14 +87,14 @@ Message::add_rrset(section_t section, RRsetPtr rrsetp)
}
void
Message::add_question(const Name& qname, const RRClass& qclass,
Message::addQuestion(const Name& qname, const RRClass& qclass,
const RRType& qtype)
{
add_rrset(SECTION_QUESTION, RRsetPtr(new Question(qname, qclass, qtype)));
addRrset(SECTION_QUESTION, RRsetPtr(new Question(qname, qclass, qtype)));
}
void
Message::to_wire()
Message::toWire()
{
uint16_t codes_and_flags;
......@@ -109,12 +109,12 @@ Message::to_wire()
sorter_->sort(*this, (section_t)section); //TBD
counts_[section] = 0;
for (std::vector<RRsetPtr>::const_iterator it =
get_section((section_t)section).begin();
it != get_section((section_t)section).end();
getSection((section_t)section).begin();
it != getSection((section_t)section).end();
++it)
{
int counter = (*it)->to_wire(*buffer_, get_compressor(),
(section_t)section);
int counter = (*it)->toWire(*buffer_, getCompressor(),
(section_t)section);
// TBD: if truncation is necessary, do something special.
// throw an exception, return an error code (in which case the
......@@ -128,37 +128,37 @@ Message::to_wire()
// fill in the header
size_t header_pos = 0;
buffer_->write_uint16_at(qid_, header_pos);
buffer_->writeUint16At(qid_, header_pos);
header_pos += sizeof(uint16_t);
codes_and_flags = (opcode_ << OPCODE_SHIFT) & OPCODE_MASK;
codes_and_flags |= (rcode_ & RCODE_MASK);
codes_and_flags |= (flags_ & FLAG_MASK);
buffer_->write_uint16_at(codes_and_flags, header_pos);
buffer_->writeUint16At(codes_and_flags, header_pos);
header_pos += sizeof(uint16_t);
for (int section = SECTION_QUESTION; section < SECTION_MAX; ++section) {
buffer_->write_uint16_at(counts_[section], header_pos);
buffer_->writeUint16At(counts_[section], header_pos);
header_pos += sizeof(uint16_t);
}
}
void
Message::from_wire()
Message::fromWire()
{
if (buffer_ == NULL)
throw DNSNoMessageBuffer();
if (buffer_->get_space() < HEADERLEN)
if (buffer_->getSpace() < HEADERLEN)
throw DNSMessageTooShort();
qid_ = buffer_->read_uint16();
uint16_t codes_and_flags = buffer_->read_uint16();
qid_ = buffer_->readUint16();
uint16_t codes_and_flags = buffer_->readUint16();
opcode_ = ((codes_and_flags & OPCODE_MASK) >> OPCODE_SHIFT);
rcode_ = (codes_and_flags & RCODE_MASK);
flags_ = (codes_and_flags & FLAG_MASK);
counts_[SECTION_QUESTION] = buffer_->read_uint16();
counts_[SECTION_ANSWER] = buffer_->read_uint16();
counts_[SECTION_AUTHORITY] = buffer_->read_uint16();
counts_[SECTION_ADDITIONAL] = buffer_->read_uint16();
counts_[SECTION_QUESTION] = buffer_->readUint16();
counts_[SECTION_ANSWER] = buffer_->readUint16();
counts_[SECTION_AUTHORITY] = buffer_->readUint16();
counts_[SECTION_ADDITIONAL] = buffer_->readUint16();
parse_question();
// parse other sections (TBD)
......@@ -173,20 +173,20 @@ Message::parse_question()
throw DNSNoMessageBuffer();
for (int count = 0; count < this->counts_[SECTION_QUESTION]; count++) {
Name name(*buffer_, get_decompressor());
Name name(*buffer_, getDecompressor());
// Get type and class
if (buffer_->get_space() < 2 * sizeof(uint16_t))
if (buffer_->getSpace() < 2 * sizeof(uint16_t))
throw DNSMessageTooShort();
// XXX: need a duplicate check. We might also want to have an optimized
// algorithm that requires the question section contain exactly one
// RR.
RRType rrtype(buffer_->read_uint16());
RRClass rrclass(buffer_->read_uint16());
add_rrset(SECTION_QUESTION,
RRsetPtr(new Question(name, rrclass, rrtype)));
RRType rrtype(buffer_->readUint16());
RRClass rrclass(buffer_->readUint16());
addRrset(SECTION_QUESTION,
RRsetPtr(new Question(name, rrclass, rrtype)));
}
}
......@@ -236,7 +236,7 @@ static const char *sectiontext[] = {
};
std::string
Message::to_text() const
Message::toText() const
{
std::string s;
......@@ -245,19 +245,19 @@ Message::to_text() const
s += ", status: " + std::string(rcodetext[rcode_]);
s += ", id: " + boost::lexical_cast<std::string>(qid_);
s += "\n;; flags: ";
if (get_qr())
if (getQr())
s += "qr ";
if (get_aa())
if (getAa())
s += "aa ";
if (get_tc())
if (getTc())
s += "tc ";
if (get_rd())
if (getRd())
s += "rd ";
if (get_ra())
if (getRa())
s += "ra ";
if (get_ad())
if (getAd())
s += "ad ";
if (get_cd())
if (getCd())
s += "cd ";
// for simply, don't consider the update case
......@@ -283,7 +283,7 @@ Message::to_text() const
{
if (section == SECTION_QUESTION)
s += ";";
s += (**it).to_text() + "\n";
s += (**it).toText() + "\n";
}
}
......@@ -293,34 +293,34 @@ Message::to_text() const
struct MatchRR : public std::binary_function<RRsetPtr, RR, bool> {
bool operator()(const RRsetPtr& rrset, const RR& rr) const
{
return (rrset->get_type() == rr.get_type() &&
rrset->get_class() == rr.get_class() &&
rrset->get_name() == rr.get_name());
return (rrset->getType() == rr.getType() &&
rrset->getClass() == rr.getClass() &&
rrset->getName() == rr.getName());
}
};
void
Message::add_rr(section_t section, const RR& rr)
Message::addRr(section_t section, const RR& rr)
{
std::vector<RRsetPtr>::iterator it;
it = find_if(sections_[section].begin(), sections_[section].end(),
std::bind2nd(MatchRR(), rr));
if (it != sections_[section].end()) {
(*it)->set_ttl(std::min((*it)->get_ttl(), rr.get_ttl()));
(*it)->add_rdata(Rdata::RDATAPTR(rr.get_rdata()->copy()));
(*it)->setTtl(std::min((*it)->getTtl(), rr.getTtl()));
(*it)->addRdata(Rdata::RDATAPTR(rr.getRdata()->copy()));
} else {
RRset *rrset = new RRset(rr.get_name(), rr.get_class(), rr.get_type(),
rr.get_ttl());
rrset->add_rdata(Rdata::RDATAPTR(rr.get_rdata()->copy()));
RRset *rrset = new RRset(rr.getName(), rr.getClass(), rr.getType(),
rr.getTtl());
rrset->addRdata(Rdata::RDATAPTR(rr.getRdata()->copy()));
sections_[section].push_back(RRsetPtr(rrset));
}
}
void
Message::make_response()
Message::makeResponse()
{
flags_ &= MESSAGE_REPLYPRESERVE;
set_qr(true);
setQr(true);
for (int section = SECTION_ANSWER; section < SECTION_MAX; ++section) {
sections_[section].clear();
......
......@@ -46,10 +46,10 @@ public:
void sort(Message& message, section_t section) {} // dummy for now.
};
#define get_msgflg(flg, capflg) \
bool get_ ## flg() const { return ((flags_ & FLAG_ ## capflg) != 0); }
#define set_msgflg(flg, capflg) \
bool set_ ## flg(bool on) { \
#define getMsgFlg(flg, capflg) \
bool get ## flg() const { return ((flags_ & FLAG_ ## capflg) != 0); }
#define setMsgFlg(flg, capflg) \
bool set ## flg(bool on) { \
if (on) \
flags_ |= FLAG_ ## capflg; \
else \
......@@ -60,27 +60,27 @@ class Message {
public:
Message();
~Message();
qid_t get_qid() const { return (qid_); }
void set_qid(qid_t qid) { qid_ = qid; }
get_msgflg(rd, RD)
set_msgflg(rd, RD)
get_msgflg(aa, AA)
set_msgflg(aa, AA)
get_msgflg(qr, QR)
set_msgflg(qr, QR)
get_msgflg(tc, TC)
set_msgflg(tc, TC)
get_msgflg(ra, RA)
set_msgflg(ra, RA)
get_msgflg(ad, AD)
set_msgflg(ad, AD)
get_msgflg(cd, CD)
set_msgflg(cd, CD)
rcode_t get_rcode() const { return (rcode_); }
void set_rcode(rcode_t rcode) { rcode_ = rcode; }
opcode_t get_opcode() const { return (opcode_); }
void set_opcode(opcode_t opcode) { opcode_ = opcode; }
std::string to_text() const;
qid_t getQid() const { return (qid_); }
void setQid(qid_t qid) { qid_ = qid; }
getMsgFlg(Rd, RD)
setMsgFlg(Rd, RD)
getMsgFlg(Aa, AA)
setMsgFlg(Aa, AA)
getMsgFlg(Qr, QR)
setMsgFlg(Qr, QR)
getMsgFlg(Tc, TC)
setMsgFlg(Tc, TC)
getMsgFlg(Ra, RA)
setMsgFlg(Ra, RA)
getMsgFlg(Ad, AD)
setMsgFlg(Ad, AD)
getMsgFlg(Cd, CD)
setMsgFlg(Cd, CD)
rcode_t getRcode() const { return (rcode_); }
void setRcode(rcode_t rcode) { rcode_ = rcode; }
opcode_t getOpcode() const { return (opcode_); }
void setOpcode(opcode_t opcode) { opcode_ = opcode; }
std::string toText() const;
// we don't provide accessors to QD/AN/NS/AR counters as this information
// is included in the corresponding RRsets.
......@@ -89,16 +89,16 @@ public:
// - may want to provide an "iterator" for all RRsets/RRs
// - may want to provide a "find" method for a specified type
// of RR in the message
const std::vector<RRsetPtr>& get_section(section_t section) const
const std::vector<RRsetPtr>& getSection(section_t section) const
{ return (sections_[section]); }
void add_rrset(section_t section, RRsetPtr rrset);
// add_question() is redundant in that it's a special case of add_rrset,
void addRrset(section_t section, RRsetPtr rrset);
// addQuestion() is redundant in that it's a special case of add_rrset,
// but it'd be convenient for general purpose applications.
void add_question(const Name& qname, const RRClass& qclass,
const RRType& qtype);
void remove_rrset(section_t section, RRsetPtr rrset);
void add_rr(section_t section, const RR& rr);
void remove_rr(section_t section, const RR& rr);
void addQuestion(const Name& qname, const RRClass& qclass,
const RRType& qtype);
void removeRrset(section_t section, RRsetPtr rrset);
void addRr(section_t section, const RR& rr);
void removeRr(section_t section, const RR& rr);
// should we separate methods for different EDNS0-related
// parameters/options? it would probably be better to have a
......@@ -106,33 +106,33 @@ public:
// on the other hand, considering we're going to use EDNS0 pretty
// ubiquitously, perhaps we should include currently-defined EDNS0
// parameters and options by default.
void set_edns(EDNS* edns); // TBD
const EDNS* get_edns() const; // TBD
void setEdns(EDNS* edns); // TBD
const EDNS* getEdns() const; // TBD
// prepare for making a response from a request. This will clear the
// DNS header except those fields that should be kept for the response,
// and clear answer and the following sections.
// see also dns_message_reply() of BIND9.
void make_response();
void makeResponse();
// Render message
void to_wire(); // should probably return some result code?
void toWire(); // should probably return some result code?
Buffer& get_buffer()
Buffer& getBuffer()
{
if (buffer_ == NULL)
throw DNSNoMessageBuffer();
return (*buffer_);
}
NameCompressor& get_compressor()
NameCompressor& getCompressor()
{
if (compressor_ == NULL)
throw DNSNoNameCompressor();
return (*compressor_);
}
NameDecompressor& get_decompressor()
NameDecompressor& getDecompressor()
{
if (decompressor_ == NULL)
throw DNSNoNameDecompressor();
......@@ -141,7 +141,7 @@ public:
// Parse message:
// This function may throw exceptions. We may revisit this design.
void from_wire();
void fromWire();
public:
// public protocol constants
......
......@@ -41,7 +41,7 @@ class MessageTest : public ::testing::Test {
protected:
MessageTest()
{
query.add_question(Name("www.example.com"), RRClass::IN, RRType::A);
query.addQuestion(Name("www.example.com"), RRClass::IN, RRType::A);
}
Message query;
Message response;
......@@ -49,76 +49,76 @@ protected:
TEST_F(MessageTest, check_flags)
{
EXPECT_EQ(false, query.get_qr());
query.set_qr(true);
EXPECT_EQ(true, query.get_qr());
EXPECT_EQ(false, query.getQr());
query.setQr(true);
EXPECT_EQ(true, query.getQr());
EXPECT_EQ(false, query.get_aa());
query.set_aa(true);
EXPECT_EQ(true, query.get_aa());
EXPECT_EQ(false, query.getAa());
query.setAa(true);
EXPECT_EQ(true, query.getAa());
EXPECT_EQ(false, query.get_tc());
query.set_tc(true);
EXPECT_EQ(true, query.get_tc());
EXPECT_EQ(false, query.getTc());
query.setTc(true);
EXPECT_EQ(true, query.getTc());
EXPECT_EQ(false, query.get_rd());
query.set_rd(true);
EXPECT_EQ(true, query.get_rd());
EXPECT_EQ(false, query.getRd());
query.setRd(true);
EXPECT_EQ(true, query.getRd());
EXPECT_EQ(false, query.get_ra());
query.set_ra(true);
EXPECT_EQ(true, query.get_ra());
EXPECT_EQ(false, query.getRa());
query.setRa(true);
EXPECT_EQ(true, query.getRa());
EXPECT_EQ(false, query.get_ad());
query.set_ad(true);
EXPECT_EQ(true, query.get_ad());
EXPECT_EQ(false, query.getAd());
query.setAd(true);
EXPECT_EQ(true, query.getAd());
EXPECT_EQ(false, query.get_cd());
query.set_cd(true);
EXPECT_EQ(true, query.get_cd());
EXPECT_EQ(false, query.getCd());
query.setCd(true);
EXPECT_EQ(true, query.getCd());
}
TEST_F(MessageTest, get_question)
TEST_F(MessageTest, getQuestion)
{
const std::vector<RRsetPtr>& question = query.get_section(SECTION_QUESTION);
const std::vector<RRsetPtr>& question = query.getSection(SECTION_QUESTION);
EXPECT_EQ(1, question.size());
EXPECT_EQ("www.example.com. IN A", (**question.begin()).to_text());
EXPECT_EQ("www.example.com. IN A", (**question.begin()).toText());
}
TEST_F(MessageTest, make_response)
TEST_F(MessageTest, makeResponse)
{
query.make_response();
EXPECT_EQ(true, query.get_qr());
query.makeResponse();
EXPECT_EQ(true, query.getQr());
EXPECT_EQ("www.example.com. IN A",
(**query.get_section(SECTION_QUESTION).begin()).to_text());
EXPECT_EQ(0, query.get_section(SECTION_ANSWER).size());
EXPECT_EQ(0, query.get_section(SECTION_AUTHORITY).size());
EXPECT_EQ(0, query.get_section(SECTION_ADDITIONAL).size());
(**query.getSection(SECTION_QUESTION).begin()).toText());
EXPECT_EQ(0, query.getSection(SECTION_ANSWER).size());
EXPECT_EQ(0, query.getSection(SECTION_AUTHORITY).size());
EXPECT_EQ(0, query.getSection(SECTION_ADDITIONAL).size());
}
TEST_F(MessageTest, add_rr)
TEST_F(MessageTest, addRr)
{
// Add one RR to the answer section.
response.add_rr(SECTION_ANSWER, RR(Name("www.example.com"), RRClass::IN,
response.addRr(SECTION_ANSWER, RR(Name("www.example.com"), RRClass::IN,
RRType::A, TTL(3600), A("192.0.2.1")));
EXPECT_EQ("www.example.com. 3600 IN A 192.0.2.1",
(**response.get_section(SECTION_ANSWER).begin()).to_text());
(**response.getSection(SECTION_ANSWER).begin()).toText());
// Add another RR of the same RRset with a larger TTL. The original
// (smaller) TTL should remain.
response.add_rr(SECTION_ANSWER, RR(Name("www.example.com"), RRClass::IN,
response.addRr(SECTION_ANSWER, RR(Name("www.example.com"), RRClass::IN,
RRType::A, TTL(7200), A("192.0.2.2")));
EXPECT_EQ("www.example.com. 3600 IN A 192.0.2.1\n"
"www.example.com. 3600 IN A 192.0.2.2",
(**response.get_section(SECTION_ANSWER).begin()).to_text());
(**response.getSection(SECTION_ANSWER).begin()).toText());
// Add one more RR of the same RRset with a smaller TTL. The new (smaller)
// TTL should replace with the old one.
response.add_rr(SECTION_ANSWER, RR(Name("www.example.com"), RRClass::IN,
response.addRr(SECTION_ANSWER, RR(Name("www.example.com"), RRClass::IN,
RRType::A, TTL(1800), A("192.0.2.3")));
EXPECT_EQ("www.example.com. 1800 IN A 192.0.2.1\n"
"www.example.com. 1800 IN A 192.0.2.2\n"
"www.example.com. 1800 IN A 192.0.2.3",
(**response.get_section(SECTION_ANSWER).begin()).to_text());
(**response.getSection(SECTION_ANSWER).begin()).toText());
}
}
......@@ -296,14 +296,14 @@ Name::Name(Buffer& buffer, NameDecompressor& decompressor)
*/
nmax = MAXWIRE;
current = buffer.get_current