Skip to content

Commit

Permalink
Merge 18fcd87 into bc68688
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie committed Apr 5, 2024
2 parents bc68688 + 18fcd87 commit 2969c35
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,21 +444,21 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
vector<DNSResourceRecord> records;
vector<Comment> comments;

QType qType = QType::ANY;
DNSName qName;

// load all records + sort
{
DNSResourceRecord resourceRecord;
if (req->getvars.count("rrset_name") == 0) {
domainInfo.backend->list(zonename, static_cast<int>(domainInfo.id), true); // incl. disabled
}
else {
QType qType;
if (req->getvars.count("rrset_type") == 0) {
qType = QType::ANY;
}
else {
qName = DNSName(req->getvars["rrset_name"]);
if (req->getvars.count("rrset_type") != 0) {
qType = req->getvars["rrset_type"];
}
domainInfo.backend->lookup(qType, DNSName(req->getvars["rrset_name"]), static_cast<int>(domainInfo.id));
domainInfo.backend->lookup(qType, qName, static_cast<int>(domainInfo.id));
}
while (domainInfo.backend->get(resourceRecord)) {
if (resourceRecord.qtype.getCode() == 0) {
Expand Down Expand Up @@ -506,6 +506,14 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
auto cit = comments.begin();

while (rit != records.end() || cit != comments.end()) {
bool skipRRset = false;

if (qName.empty() || qName == cit->qname) {
if (qType == QType::ANY || qType == cit->qtype) {
skipRRset = true;
}
}

// if you think this should be rit < cit instead of cit < rit, note the b < a instead of a < b in the sort comparison functions above
if (cit == comments.end() || (rit != records.end() && (rit->qname == cit->qname ? (cit->qtype < rit->qtype || cit->qtype == rit->qtype) : cit->qname < rit->qname))) {
current_qname = rit->qname;
Expand All @@ -519,26 +527,33 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
}

while (rit != records.end() && rit->qname == current_qname && rit->qtype == current_qtype) {
ttl = min(ttl, rit->ttl);
rrset_records.push_back(Json::object{
{"disabled", rit->disabled},
{"content", makeApiRecordContent(rit->qtype, rit->content)}});
if (!skipRRset) {
ttl = min(ttl, rit->ttl);
rrset_records.push_back(Json::object{
{"disabled", rit->disabled},
{"content", makeApiRecordContent(rit->qtype, rit->content)}});
}
rit++;
}
while (cit != comments.end() && cit->qname == current_qname && cit->qtype == current_qtype) {
rrset_comments.push_back(Json::object{
{"modified_at", (double)cit->modified_at},
{"account", cit->account},
{"content", cit->content}});
if (!skipRRset) {
rrset_comments.push_back(Json::object{
{"modified_at", (double)cit->modified_at},
{"account", cit->account},
{"content", cit->content}});
}
cit++;
}

rrset["name"] = current_qname.toString();
rrset["type"] = current_qtype.toString();
rrset["records"] = rrset_records;
rrset["comments"] = rrset_comments;
rrset["ttl"] = (double)ttl;
rrsets.emplace_back(rrset);
if (!skipRRset) {
rrset["name"] = current_qname.toString();
rrset["type"] = current_qtype.toString();
rrset["records"] = rrset_records;
rrset["comments"] = rrset_comments;
rrset["ttl"] = (double)ttl;
rrsets.emplace_back(rrset);
}

rrset.clear();
rrset_records.clear();
rrset_comments.clear();
Expand Down

0 comments on commit 2969c35

Please sign in to comment.