}
}
-DNSName dnsnameFromJson(const rapidjson::Value& container, const char* key)
-{
- if (!container.IsObject()) {
- throw JsonException("Container was not an object.");
- }
- const Value& val = container[key];
- if (val.IsString()) {
- string name = val.GetString();
- if (!isCanonical(name)) {
- throw JsonException("DNS Name '" + name + "' is not canonical");
- }
- try {
- return DNSName(name);
- } catch (...) {
- throw JsonException("Unable to parse DNS Name '" + name + "'");
- }
- } else {
- throw JsonException("Key '" + string(key) + "' not present or not a String");
- }
-}
-
bool boolFromJson(const rapidjson::Value& container, const char* key)
{
if (!container.IsObject()) {
#include <map>
#include <stdexcept>
#include "rapidjson/document.h"
-#include "dnsname.hh"
std::string returnJsonObject(const std::map<std::string, std::string>& items);
std::string returnJsonError(const std::string& error);
int intFromJson(const rapidjson::Value& container, const char* key, const int default_value);
std::string stringFromJson(const rapidjson::Value& container, const char* key);
std::string stringFromJson(const rapidjson::Value& container, const char* key, const std::string& default_value);
-DNSName dnsnameFromJson(const rapidjson::Value& container, const char* key);
bool boolFromJson(const rapidjson::Value& container, const char* key);
bool boolFromJson(const rapidjson::Value& container, const char* key, const bool default_value);
resp->setBody(doc);
}
+DNSName apiNameToDNSName(const string& name) {
+ if (!isCanonical(name)) {
+ throw ApiException("DNS Name '" + name + "' is not canonical");
+ }
+ try {
+ return DNSName(name);
+ } catch (...) {
+ throw ApiException("Unable to parse DNS Name '" + name + "'");
+ }
+}
+
DNSName apiZoneIdToName(const string& id) {
string zonename;
ostringstream ss;
DNSName apiZoneIdToName(const string& id);
string apiZoneNameToId(const DNSName& name);
void apiCheckNameAllowedCharacters(const string& label);
+DNSName apiNameToDNSName(const string& name);
// To be provided by product code.
void productServerStatisticsFetch(std::map<string,string>& out);
if (records.IsArray()) {
for (SizeType idx = 0; idx < records.Size(); ++idx) {
const Value& record = records[idx];
- rr.qname = dnsnameFromJson(record, "name");
+ rr.qname = apiNameToDNSName(stringFromJson(record, "name"));
rr.qtype = stringFromJson(record, "type");
string content = stringFromJson(record, "content");
rr.auth = 1;
DomainInfo di;
Document document;
req->json(document);
- DNSName zonename = dnsnameFromJson(document, "name");
+ DNSName zonename = apiNameToDNSName(stringFromJson(document, "name"));
apiCheckNameAllowedCharacters(zonename.toString());
string zonestring = stringFromJson(document, "zone", "");
const Value& rrset = rrsets[rrsetIdx];
string changetype;
QType qtype;
- DNSName qname = dnsnameFromJson(rrset, "name");
+ DNSName qname = apiNameToDNSName(stringFromJson(rrset, "name"));
apiCheckNameAllowedCharacters(qname.toString());
qtype = stringFromJson(rrset, "type");
changetype = toUpper(stringFromJson(rrset, "changetype"));
throw ApiException("Config Option \"api-config-dir\" must be set");
}
- DNSName zonename = dnsnameFromJson(document, "name");
+ DNSName zonename = apiNameToDNSName(stringFromJson(document, "name"));
apiCheckNameAllowedCharacters(zonename.toString());
string singleIPTarget = stringFromJson(document, "single_target_ip", "");
Document document;
req->json(document);
- DNSName zonename = dnsnameFromJson(document, "name");
+ DNSName zonename = apiNameToDNSName(stringFromJson(document, "name"));
auto iter = t_sstorage->domainmap->find(zonename);
if (iter != t_sstorage->domainmap->end())
doDeleteZone(zonename);
doCreateZone(document);
reloadAuthAndForwards();
- fillZone(dnsnameFromJson(document, "name"), resp);
+ fillZone(apiNameToDNSName(stringFromJson(document, "name")), resp);
}
else if(req->method == "DELETE" && !::arg().mustDo("api-readonly")) {
if (!doDeleteZone(zonename)) {