Commit 949f642c authored by Jelte Jansen's avatar Jelte Jansen

[trac491] added isc::resolve::initResponseMessage() functions

parent f59af820
......@@ -182,6 +182,8 @@ public:
MessagePtr message_;
};
// TODO: REMOVE, USE isc::resolve::MakeErrorMessage?
void
makeErrorMessage(MessagePtr message, OutputBufferPtr buffer,
const Rcode& rcode)
......
......@@ -144,8 +144,7 @@ private:
void doLookup() {
dlog("doLookup: try cache");
Message cached_message(Message::RENDER);
cached_message.addQuestion(question_);
cached_message.setOpcode(Opcode::QUERY());
isc::resolve::initResponseMessage(question_, cached_message);
if (cache_.lookup(question_.getName(), question_.getType(),
question_.getClass(), cached_message)) {
dlog("Message found in cache, returning that");
......@@ -396,11 +395,6 @@ public:
// until that one comes back to us)
done_ = true;
if (resume && !answer_sent_) {
// Store the answer we found in our cache
//std::cout << "[XX] caching our answer:" << std::endl;
//std::cout << answer_message_->toText();
//cache_.update(*answer_message_);
//std::cout << "[XX] done caching our answer" << std::endl;
resolvercallback_->success(answer_message_);
} else {
resolvercallback_->failure();
......@@ -461,11 +455,10 @@ RecursiveQuery::resolve(const QuestionPtr& question,
asio::io_service& io = dns_service_.get_io_service();
MessagePtr answer_message(new Message(Message::RENDER));
isc::resolve::initResponseMessage(*question, *answer_message);
OutputBufferPtr buffer(new OutputBuffer(0));
// TODO: general 'prepareinitialanswer'
answer_message->setOpcode(isc::dns::Opcode::QUERY());
answer_message->addQuestion(question);
dlog("Try out cache first (direct call to resolve)");
// First try to see if we have something cached in the messagecache
if (cache_.lookup(question->getName(), question->getType(),
......
......@@ -14,6 +14,9 @@
#include <resolve/resolve.h>
#include <dns/message.h>
#include <dns/opcode.h>
using namespace isc::dns;
namespace {
......@@ -44,6 +47,22 @@ makeErrorMessage(MessagePtr answer_message,
answer_message->setRcode(error_code);
}
void initResponseMessage(const isc::dns::Message& query_message,
isc::dns::Message& response_message)
{
response_message.setOpcode(query_message.getOpcode());
response_message.setQid(query_message.getQid());
response_message.appendSection(Message::SECTION_QUESTION,
query_message);
}
void initResponseMessage(const isc::dns::Question& question,
isc::dns::Message& response_message)
{
response_message.setOpcode(isc::dns::Opcode::QUERY());
response_message.addQuestion(question);
}
void copyResponseMessage(const Message& source, MessagePtr target) {
target->setRcode(source.getRcode());
......
......@@ -42,6 +42,36 @@ namespace resolve {
void makeErrorMessage(isc::dns::MessagePtr answer_message,
const isc::dns::Rcode& error_code);
/// \brief Initialize a response message
///
/// Based on the given query message, this fills in the very
/// first details of the response (i.e. the Question section and
/// the Opcode). This allows for direct usage of makeErrorMessage(),
/// as well as ResolveCache.lookup().
///
/// \param query_message The query message to take the Question, Qid,
/// and Opcode from.
/// \param response_message The fresh response message to initialize
/// (must be type Message::RENDER)
void initResponseMessage(const isc::dns::Message& query_message,
isc::dns::Message& response_message);
/// \brief Initialize a response message
///
/// Based on the given question, this fills in the very
/// first details of the response (i.e. the Question section and the
/// Opcode Query). This allows for direct usage of makeErrorMessage(),
/// as well as ResolveCache.lookup().
///
/// \param question The question to place in the Question section
/// \param response_message The fresh response message to initialize
/// (must be type Message::RENDER)
void initResponseMessage(const isc::dns::Question& question,
isc::dns::Message& response_message);
/// \brief Copies the parts relevant for a DNS response to the
/// target message
///
......
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