|
@@ -21,7 +21,6 @@
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
#include <boost/bind.hpp>
|
|
|
-#include <boost/foreach.hpp>
|
|
|
|
|
|
#include <exceptions/exceptions.h>
|
|
|
|
|
@@ -39,12 +38,9 @@
|
|
|
#include <datasrc/data_source.h>
|
|
|
#include <datasrc/factory.h>
|
|
|
|
|
|
-#include <cc/data.h>
|
|
|
-
|
|
|
using namespace std;
|
|
|
using namespace isc::dns;
|
|
|
using namespace isc::dns::rdata;
|
|
|
-using namespace isc::data;
|
|
|
using boost::scoped_ptr;
|
|
|
|
|
|
namespace isc {
|
|
@@ -1220,146 +1216,5 @@ InMemoryClient::getJournalReader(const isc::dns::Name&, uint32_t,
|
|
|
"in memory data source");
|
|
|
}
|
|
|
|
|
|
-namespace {
|
|
|
-// convencience function to add an error message to a list of those
|
|
|
-// (TODO: move functions like these to some util lib?)
|
|
|
-void
|
|
|
-addError(ElementPtr errors, const std::string& error) {
|
|
|
- if (errors != ElementPtr() && errors->getType() == Element::list) {
|
|
|
- errors->add(Element::create(error));
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/// Check if the given element exists in the map, and if it is a string
|
|
|
-bool
|
|
|
-checkConfigElementString(ConstElementPtr config, const std::string& name,
|
|
|
- ElementPtr errors)
|
|
|
-{
|
|
|
- if (!config->contains(name)) {
|
|
|
- addError(errors,
|
|
|
- "Config for memory backend does not contain a '"
|
|
|
- +name+
|
|
|
- "' value");
|
|
|
- return false;
|
|
|
- } else if (!config->get(name) ||
|
|
|
- config->get(name)->getType() != Element::string) {
|
|
|
- addError(errors, "value of " + name +
|
|
|
- " in memory backend config is not a string");
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-bool
|
|
|
-checkZoneConfig(ConstElementPtr config, ElementPtr errors) {
|
|
|
- bool result = true;
|
|
|
- if (!config || config->getType() != Element::map) {
|
|
|
- addError(errors, "Elements in memory backend's zone list must be maps");
|
|
|
- result = false;
|
|
|
- } else {
|
|
|
- if (!checkConfigElementString(config, "origin", errors)) {
|
|
|
- result = false;
|
|
|
- }
|
|
|
- if (!checkConfigElementString(config, "file", errors)) {
|
|
|
- result = false;
|
|
|
- }
|
|
|
- // we could add some existence/readabilty/parsability checks here
|
|
|
- // if we want
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-bool
|
|
|
-checkConfig(ConstElementPtr config, ElementPtr errors) {
|
|
|
- /* Specific configuration is under discussion, right now this accepts
|
|
|
- * the 'old' configuration, see [TODO]
|
|
|
- * So for memory datasource, we get a structure like this:
|
|
|
- * { "type": string ("memory"),
|
|
|
- * "class": string ("IN"/"CH"/etc),
|
|
|
- * "zones": list
|
|
|
- * }
|
|
|
- * Zones list is a list of maps:
|
|
|
- * { "origin": string,
|
|
|
- * "file": string
|
|
|
- * }
|
|
|
- *
|
|
|
- * At this moment we cannot be completely sure of the contents of the
|
|
|
- * structure, so we have to do some more extensive tests than should
|
|
|
- * strictly be necessary (e.g. existence and type of elements)
|
|
|
- */
|
|
|
- bool result = true;
|
|
|
-
|
|
|
- if (!config || config->getType() != Element::map) {
|
|
|
- addError(errors, "Base config for memory backend must be a map");
|
|
|
- result = false;
|
|
|
- } else {
|
|
|
- if (!checkConfigElementString(config, "type", errors)) {
|
|
|
- result = false;
|
|
|
- } else {
|
|
|
- if (config->get("type")->stringValue() != "memory") {
|
|
|
- addError(errors,
|
|
|
- "Config for memory backend is not of type \"memory\"");
|
|
|
- result = false;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!checkConfigElementString(config, "class", errors)) {
|
|
|
- result = false;
|
|
|
- } else {
|
|
|
- try {
|
|
|
- RRClass rrc(config->get("class")->stringValue());
|
|
|
- } catch (const isc::Exception& rrce) {
|
|
|
- addError(errors,
|
|
|
- "Error parsing class config for memory backend: " +
|
|
|
- std::string(rrce.what()));
|
|
|
- result = false;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!config->contains("zones")) {
|
|
|
- addError(errors, "No 'zones' element in memory backend config");
|
|
|
- result = false;
|
|
|
- } else if (!config->get("zones") ||
|
|
|
- config->get("zones")->getType() != Element::list) {
|
|
|
- addError(errors, "'zones' element in memory backend config is not a list");
|
|
|
- result = false;
|
|
|
- } else {
|
|
|
- BOOST_FOREACH(ConstElementPtr zone_config,
|
|
|
- config->get("zones")->listValue()) {
|
|
|
- if (!checkZoneConfig(zone_config, errors)) {
|
|
|
- result = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return (result);
|
|
|
-}
|
|
|
-
|
|
|
-} // end anonymous namespace
|
|
|
-
|
|
|
-DataSourceClient *
|
|
|
-createInstance(isc::data::ConstElementPtr config, std::string& error) {
|
|
|
- ElementPtr errors(Element::createList());
|
|
|
- if (!checkConfig(config, errors)) {
|
|
|
- error = "Configuration error: " + errors->str();
|
|
|
- return (NULL);
|
|
|
- }
|
|
|
- try {
|
|
|
- return (new InMemoryClient());
|
|
|
- } catch (const std::exception& exc) {
|
|
|
- error = std::string("Error creating memory datasource: ") + exc.what();
|
|
|
- return (NULL);
|
|
|
- } catch (...) {
|
|
|
- error = std::string("Error creating memory datasource, "
|
|
|
- "unknown exception");
|
|
|
- return (NULL);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void destroyInstance(DataSourceClient* instance) {
|
|
|
- delete instance;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
} // end of namespace datasrc
|
|
|
} // end of namespace isc
|