]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: api: avoid a large number of new database connections 8457/head
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 23 Oct 2019 12:47:45 +0000 (14:47 +0200)
committermind04 <mind04@monshouwer.org>
Wed, 23 Oct 2019 21:20:42 +0000 (23:20 +0200)
pdns/ws-auth.cc

index c39b4e44962e83d0bf53ce9b6a386a764f48ca7d..c82775ababfce5141f100cf3c66efce33289d8ca 100644 (file)
@@ -52,7 +52,7 @@ using json11::Json;
 
 extern StatBag S;
 
-static void patchZone(HttpRequest* req, HttpResponse* resp);
+static void patchZone(UeberBackend& B, HttpRequest* req, HttpResponse* resp);
 static void storeChangedPTRs(UeberBackend& B, vector<DNSResourceRecord>& new_ptrs);
 static void makePtr(const DNSResourceRecord& rr, DNSResourceRecord* ptr);
 
@@ -352,8 +352,7 @@ static bool shouldDoRRSets(HttpRequest* req) {
   throw ApiException("'rrsets' request parameter value '"+req->getvars["rrsets"]+"' is not supported");
 }
 
-static void fillZone(const DNSName& zonename, HttpResponse* resp, bool doRRSets) {
-  UeberBackend B;
+static void fillZone(UeberBackend& B, const DNSName& zonename, HttpResponse* resp, bool doRRSets) {
   DomainInfo di;
   if(!B.getDomainInfo(zonename, di)) {
     throw HttpNotFoundException();
@@ -525,8 +524,7 @@ static void validateGatheredRRType(const DNSResourceRecord& rr) {
   }
 }
 
-static void gatherRecords(const string& logprefix, const Json container, const DNSName& qname, const QType qtype, const int ttl, vector<DNSResourceRecord>& new_records, vector<DNSResourceRecord>& new_ptrs) {
-  UeberBackend B;
+static void gatherRecords(UeberBackend& B, const string& logprefix, const Json container, const DNSName& qname, const QType qtype, const int ttl, vector<DNSResourceRecord>& new_records, vector<DNSResourceRecord>& new_ptrs) {
   DNSResourceRecord rr;
   rr.qname = qname;
   rr.qtype = qtype;
@@ -1562,7 +1560,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
         }
         if (rrset["records"].is_array()) {
           int ttl = intFromJson(rrset, "ttl");
-          gatherRecords(req->logprefix, rrset, qname, qtype, ttl, new_records, new_ptrs);
+          gatherRecords(B, req->logprefix, rrset, qname, qtype, ttl, new_records, new_ptrs);
         }
         if (rrset["comments"].is_array()) {
           gatherComments(rrset, qname, qtype, new_comments);
@@ -1671,7 +1669,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
 
     storeChangedPTRs(B, new_ptrs);
 
-    fillZone(zonename, resp, shouldDoRRSets(req));
+    fillZone(B, zonename, resp, shouldDoRRSets(req));
     resp->status = 201;
     return;
   }
@@ -1744,10 +1742,10 @@ static void apiServerZoneDetail(HttpRequest* req, HttpResponse* resp) {
     resp->status = 204; // No Content: declare that the zone is gone now
     return;
   } else if (req->method == "PATCH") {
-    patchZone(req, resp);
+    patchZone(B, req, resp);
     return;
   } else if (req->method == "GET") {
-    fillZone(zonename, resp, shouldDoRRSets(req));
+    fillZone(B, zonename, resp, shouldDoRRSets(req));
     return;
   }
   throw HttpMethodNotAllowedException();
@@ -1925,8 +1923,7 @@ static void storeChangedPTRs(UeberBackend& B, vector<DNSResourceRecord>& new_ptr
   }
 }
 
-static void patchZone(HttpRequest* req, HttpResponse* resp) {
-  UeberBackend B;
+static void patchZone(UeberBackend& B, HttpRequest* req, HttpResponse* resp) {
   DomainInfo di;
   DNSName zonename = apiZoneIdToName(req->parameters["id"]);
   if (!B.getDomainInfo(zonename, di)) {
@@ -1995,7 +1992,7 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) {
           // ttl shouldn't be part of DELETE, and it shouldn't be required if we don't get new records.
           int ttl = intFromJson(rrset, "ttl");
           // new_ptrs is merged.
-          gatherRecords(req->logprefix, rrset, qname, qtype, ttl, new_records, new_ptrs);
+          gatherRecords(B, req->logprefix, rrset, qname, qtype, ttl, new_records, new_ptrs);
 
           for(DNSResourceRecord& rr : new_records) {
             rr.domain_id = di.id;