resp->status = 200;
}
+static void fillZoneInfo(const DomainInfo& di, Value& jdi, Document& doc) {
+ DNSSECKeeper dk;
+ jdi.SetObject();
+ // id is the canonical lookup key, which doesn't actually match the name (in some cases)
+ string zoneId = apiZoneNameToId(di.zone);
+ Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy
+ jdi.AddMember("id", jzoneId, doc.GetAllocator());
+ string url = "/servers/localhost/zones/" + zoneId;
+ Value jurl(url.c_str(), doc.GetAllocator()); // copy
+ jdi.AddMember("url", jurl, doc.GetAllocator());
+ jdi.AddMember("name", di.zone.c_str(), doc.GetAllocator());
+ jdi.AddMember("kind", di.getKindString(), doc.GetAllocator());
+ jdi.AddMember("dnssec", dk.isSecuredZone(di.zone), doc.GetAllocator());
+ jdi.AddMember("account", di.account.c_str(), doc.GetAllocator());
+ Value masters;
+ masters.SetArray();
+ BOOST_FOREACH(const string& master, di.masters) {
+ Value value(master.c_str(), doc.GetAllocator());
+ masters.PushBack(value, doc.GetAllocator());
+ }
+ jdi.AddMember("masters", masters, doc.GetAllocator());
+ jdi.AddMember("serial", di.serial, doc.GetAllocator());
+ jdi.AddMember("notified_serial", di.notified_serial, doc.GetAllocator());
+ jdi.AddMember("last_check", (unsigned int) di.last_check, doc.GetAllocator());
+}
+
static void fillZone(const string& zonename, HttpResponse* resp) {
UeberBackend B;
DomainInfo di;
- DNSSECKeeper dk;
if(!B.getDomainInfo(zonename, di))
throw ApiException("Could not find domain '"+zonename+"'");
Document doc;
- doc.SetObject();
-
- // id is the canonical lookup key, which doesn't actually match the name (in some cases)
- string zoneId = apiZoneNameToId(di.zone);
- Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy
- doc.AddMember("id", jzoneId, doc.GetAllocator());
- string url = "/servers/localhost/zones/" + zoneId;
- Value jurl(url.c_str(), doc.GetAllocator()); // copy
- doc.AddMember("url", jurl, doc.GetAllocator());
- doc.AddMember("name", di.zone.c_str(), doc.GetAllocator());
- doc.AddMember("type", "Zone", doc.GetAllocator());
- doc.AddMember("kind", di.getKindString(), doc.GetAllocator());
- doc.AddMember("dnssec", dk.isSecuredZone(di.zone), doc.GetAllocator());
- doc.AddMember("account", di.account.c_str(), doc.GetAllocator());
+ fillZoneInfo(di, doc, doc);
+ // extra stuff fillZoneInfo doesn't do for us (more expensive)
string soa_edit_api;
di.backend->getDomainMetadataOne(zonename, "SOA-EDIT-API", soa_edit_api);
doc.AddMember("soa_edit_api", soa_edit_api.c_str(), doc.GetAllocator());
string soa_edit;
di.backend->getDomainMetadataOne(zonename, "SOA-EDIT", soa_edit);
doc.AddMember("soa_edit", soa_edit.c_str(), doc.GetAllocator());
- Value masters;
- masters.SetArray();
- BOOST_FOREACH(const string& master, di.masters) {
- Value value(master.c_str(), doc.GetAllocator());
- masters.PushBack(value, doc.GetAllocator());
- }
- doc.AddMember("masters", masters, doc.GetAllocator());
- doc.AddMember("serial", di.serial, doc.GetAllocator());
- doc.AddMember("notified_serial", di.notified_serial, doc.GetAllocator());
- doc.AddMember("last_check", (unsigned int) di.last_check, doc.GetAllocator());
// fill records
DNSResourceRecord rr;
BOOST_FOREACH(const DomainInfo& di, domains) {
Value jdi;
- jdi.SetObject();
- // id is the canonical lookup key, which doesn't actually match the name (in some cases)
- string zoneId = apiZoneNameToId(di.zone);
- Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy
- jdi.AddMember("id", jzoneId, doc.GetAllocator());
- string url = "/servers/localhost/zones/" + zoneId;
- Value jurl(url.c_str(), doc.GetAllocator()); // copy
- jdi.AddMember("url", jurl, doc.GetAllocator());
- jdi.AddMember("name", di.zone.c_str(), doc.GetAllocator());
- jdi.AddMember("kind", di.getKindString(), doc.GetAllocator());
- jdi.AddMember("dnssec", dk.isSecuredZone(di.zone), doc.GetAllocator());
- Value masters;
- masters.SetArray();
- BOOST_FOREACH(const string& master, di.masters) {
- Value value(master.c_str(), doc.GetAllocator());
- masters.PushBack(value, doc.GetAllocator());
- }
- jdi.AddMember("masters", masters, doc.GetAllocator());
- jdi.AddMember("serial", di.serial, doc.GetAllocator());
- jdi.AddMember("notified_serial", di.notified_serial, doc.GetAllocator());
- jdi.AddMember("last_check", (unsigned int) di.last_check, doc.GetAllocator());
+ fillZoneInfo(di, jdi, doc);
doc.PushBack(jdi, doc.GetAllocator());
}
resp->setBody(doc);