Commit 9f172776 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[trac494] initial addition of lib/resolve

parent 8a175757
......@@ -652,6 +652,8 @@ AC_CONFIG_FILES([Makefile
src/lib/datasrc/tests/Makefile
src/lib/xfr/Makefile
src/lib/log/Makefile
src/lib/resolve/Makefile
src/lib/resolve/tests/Makefile
src/lib/testutils/Makefile
src/lib/testutils/testdata/Makefile
src/lib/nsas/Makefile
......
SUBDIRS = exceptions dns cc config datasrc python xfr bench log asiolink \
testutils nsas
testutils nsas resolve
......@@ -32,3 +32,4 @@ libasiolink_la_CXXFLAGS += -Wno-error
endif
libasiolink_la_CPPFLAGS = $(AM_CPPFLAGS)
libasiolink_la_LIBADD = $(top_builddir)/src/lib/log/liblog.la
libasiolink_la_LIBADD += $(top_builddir)/src/lib/resolve/libresolve.la
......@@ -37,6 +37,8 @@
#include <asiolink/internal/tcpdns.h>
#include <asiolink/internal/udpdns.h>
#include <resolve/resolve.h>
#include <log/dummylog.h>
using namespace asio;
......@@ -355,7 +357,7 @@ private:
// Server to notify when we succeed or fail
//shared_ptr<DNSServer> server_;
AbstractResolverCallback* resolvercallback_;
isc::resolve::AbstractResolverCallback* resolvercallback_;
/*
* TODO Do something more clever with timeouts. In the long term, some
......@@ -478,7 +480,7 @@ public:
shared_ptr<AddressVector> upstream_root,
OutputBufferPtr buffer,
//DNSServer* server,
AbstractResolverCallback* cb,
isc::resolve::AbstractResolverCallback* cb,
int timeout,
unsigned retries) :
io_(io),
......@@ -566,8 +568,9 @@ RecursiveQuery::sendQuery(const isc::dns::QuestionPtr& question,
MessagePtr answer_message(new Message(Message::RENDER));
answer_message->setOpcode(isc::dns::Opcode::QUERY());
OutputBufferPtr buffer(new OutputBuffer(0));
ResolverCallbackDirect* rcd = new ResolverCallbackDirect(callback,
answer_message);
isc::resolve::ResolverCallbackDirect* rcd =
new isc::resolve::ResolverCallbackDirect(callback,
answer_message);
// It will delete itself when it is done
new RunningQuery(io, *question, answer_message, upstream_,
......@@ -586,39 +589,14 @@ RecursiveQuery::sendQuery(const Question& question,
// we're only going to handle UDP.
asio::io_service& io = dns_service_.get_io_service();
ResolverCallbackServer* crs = new ResolverCallbackServer(server);
isc::resolve::ResolverCallbackServer* crs =
new isc::resolve::ResolverCallbackServer(server);
// It will delete itself when it is done
new RunningQuery(io, question, answer_message, upstream_,
upstream_root_, buffer, crs, timeout_, retries_);
}
void
ResolverCallbackServer::callback(bool result) {
server_->resume(result);
delete server_;
delete this;
}
void
ResolverCallbackDirect::callback(bool result)
{
// simply return with the first rrset from answer right now
if (result &&
answer_message_->getRcode() == isc::dns::Rcode::NOERROR() &&
answer_message_->getRRCount(isc::dns::Message::SECTION_ANSWER) > 0) {
std::cout << *answer_message_ << std::endl;
isc::dns::RRsetIterator rrsi = answer_message_->beginSection(isc::dns::Message::SECTION_ANSWER);
const isc::dns::RRsetPtr result = *rrsi;
callback_->success(result);
} else {
callback_->failure();
}
// once called back we don't need ourselves anymore
delete this;
}
class IntervalTimerImpl {
private:
// prohibit copy
......
......@@ -371,43 +371,6 @@ private:
DNSServer* self_;
};
// We define two types of callbackholders for processing recursive
// queries; one calls back the original DNSServer to resume()
// the other uses direct callbacks (for instance when we need to
// resolve something ourselves)
// Caller warning: only callback once! The objects will delete
// themselves on callback (after they have done they callback)
class AbstractResolverCallback {
public:
~AbstractResolverCallback() {};
virtual void callback(bool result) = 0;
};
class ResolverCallbackServer : public AbstractResolverCallback {
public:
ResolverCallbackServer(DNSServer* server) :
server_(server->clone()) {}
void callback(bool result);
private:
DNSServer* server_;
};
class ResolverCallbackDirect : public AbstractResolverCallback {
public:
ResolverCallbackDirect(
const isc::nsas::ResolverInterface::CallbackPtr callback,
isc::dns::MessagePtr answer_message) :
callback_(callback),
answer_message_(answer_message) {}
void callback(bool result);
private:
const isc::nsas::ResolverInterface::CallbackPtr callback_;
isc::dns::MessagePtr answer_message_;
};
/// \brief The \c DNSLookup class is an abstract base class for a DNS
/// Lookup provider function.
///
......
SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += $(SQLITE_CFLAGS)
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
lib_LTLIBRARIES = libresolve.la
libresolve_la_SOURCES = resolve.h resolve.cc
libresolve_la_LIBADD = $(top_builddir)/src/lib/dns/libdns++.la
libresolve_la_LIBADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
// 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 <resolve/resolve.h>
namespace isc {
namespace resolve {
void
ResolverCallbackServer::callback(bool result) {
server_->resume(result);
delete server_;
delete this;
}
void
ResolverCallbackDirect::callback(bool result)
{
// simply return with the first rrset from answer right now
if (result &&
answer_message_->getRcode() == isc::dns::Rcode::NOERROR() &&
answer_message_->getRRCount(isc::dns::Message::SECTION_ANSWER) > 0) {
std::cout << *answer_message_ << std::endl;
isc::dns::RRsetIterator rrsi = answer_message_->beginSection(isc::dns::Message::SECTION_ANSWER);
const isc::dns::RRsetPtr result = *rrsi;
callback_->success(result);
} else {
callback_->failure();
}
// once called back we don't need ourselves anymore
delete this;
}
} // namespace resolve
} // namespace isc
// 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.
#ifndef _ISC_RESOLVE_H
#define _ISC_RESOLVE_H 1
#include <asiolink/asiolink.h>
namespace isc {
namespace resolve {
// We define two types of callbackholders for processing recursive
// queries; one calls back the original DNSServer to resume()
// the other uses direct callbacks (for instance when we need to
// resolve something ourselves)
// Caller warning: only callback once! The objects will delete
// themselves on callback (after they have done they callback)
class AbstractResolverCallback {
public:
~AbstractResolverCallback() {};
virtual void callback(bool result) = 0;
};
class ResolverCallbackServer : public AbstractResolverCallback {
public:
ResolverCallbackServer(asiolink::DNSServer* server) :
server_(server->clone()) {}
void callback(bool result);
private:
asiolink::DNSServer* server_;
};
class ResolverCallbackDirect : public AbstractResolverCallback {
public:
ResolverCallbackDirect(
const isc::nsas::ResolverInterface::CallbackPtr callback,
isc::dns::MessagePtr answer_message) :
callback_(callback),
answer_message_(answer_message) {}
void callback(bool result);
private:
const isc::nsas::ResolverInterface::CallbackPtr callback_;
isc::dns::MessagePtr answer_message_;
};
} //namespace resolve
} //namespace isc
#endif // ISC_RESOLVE_H_
// Copyright (C) 2009 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 <gtest/gtest.h>
#include <dns/tests/unittest_util.h>
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
return (RUN_ALL_TESTS());
}
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