]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Optimize abiVersion usage
authorAki Tuomi <cmouse@desteem.org>
Sun, 27 Apr 2014 14:38:34 +0000 (17:38 +0300)
committerAki Tuomi <cmouse@desteem.org>
Tue, 27 May 2014 10:30:16 +0000 (13:30 +0300)
modules/pipebackend/pipebackend.cc
modules/pipebackend/pipebackend.hh

index 1c8e1d023c0ee00d2de6aff034243f0de9391289..a5f5c493dd0be82ded90c8dbea2691daba820aed 100644 (file)
@@ -32,6 +32,7 @@ CoWrapper::CoWrapper(const string &command, int timeout)
    d_cp=0;
    d_command=command;
    d_timeout=timeout;
+   d_abiVersion = ::arg().asNum("pipebackend-abi-version");
    launch(); // let exceptions fall through - if initial launch fails, we want to die
    // I think
 }
@@ -52,7 +53,7 @@ void CoWrapper::launch()
      d_cp = new UnixRemote(d_command, d_timeout);
    else
      d_cp = new CoProcess(d_command, d_timeout); 
-   d_cp->send("HELO\t"+lexical_cast<string>(::arg().asNum("pipebackend-abi-version")));
+   d_cp->send("HELO\t"+lexical_cast<string>(d_abiVersion));
    string banner;
    d_cp->receive(banner); 
    L<<Logger::Error<<"Backend launched with banner: "<<banner<<endl;
@@ -94,6 +95,7 @@ PipeBackend::PipeBackend(const string &suffix)
      d_coproc=shared_ptr<CoWrapper>(new CoWrapper(getArg("command"), getArgAsNum("timeout")));
      d_regex=getArg("regex").empty() ? 0 : new Regex(getArg("regex"));
      d_regexstr=getArg("regex");
+     d_abiVersion = ::arg().asNum("pipebackend-abi-version");
    }
    catch(const ArgException &A) {
       L<<Logger::Error<<kBackendId<<" Fatal argument error: "<<A.reason<<endl;
@@ -122,15 +124,14 @@ void PipeBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pkt_
             realRemote = pkt_p->getRealRemote();
             remoteIP = pkt_p->getRemote();
          }
-         int abiVersion = ::arg().asNum("pipebackend-abi-version");
          // pipebackend-abi-version = 1
          // type    qname           qclass  qtype   id      remote-ip-address
          query<<"Q\t"<<qname<<"\tIN\t"<<qtype.getName()<<"\t"<<zoneId<<"\t"<<remoteIP;
 
          // add the local-ip-address if pipebackend-abi-version is set to 2
-         if (abiVersion >= 2)
+         if (d_abiVersion >= 2)
             query<<"\t"<<localIP;
-         if(abiVersion >= 3)
+         if(d_abiVersion >= 3)
            query <<"\t"<<realRemote.toString(); 
 
          if(::arg().mustDo("query-logging"))
@@ -154,10 +155,10 @@ bool PipeBackend::list(const string &target, int inZoneId, bool include_disabled
 // The question format:
 
 // type    qname           qclass  qtype   id      ip-address
-      if (abiVersion >= 4)
+      if (d_abiVersion >= 4)
         query<<"AXFR\t"<<inZoneId<<"\t"<<target;
       else
-        query<<"AXFR\t"<<inZoneId<;
+        query<<"AXFR\t"<<inZoneId;
 
       d_coproc->send(query.str());
    }
@@ -195,9 +196,8 @@ bool PipeBackend::get(DNSResourceRecord &r)
 
    // The answer format:
    // DATA    qname           qclass  qtype   ttl     id      content 
-   int abiVersion = ::arg().asNum("pipebackend-abi-version");
    unsigned int extraFields = 0;
-   if(abiVersion == 3)
+   if(d_abiVersion == 3)
      extraFields = 2;
      
    for(;;) {
@@ -225,7 +225,7 @@ bool PipeBackend::get(DNSResourceRecord &r)
             // now what?
          }
          
-         if(abiVersion == 3) {
+         if(d_abiVersion == 3) {
            r.scopeMask = atoi(parts[1].c_str());
            r.auth = atoi(parts[2].c_str());
          } else {
index 07bc3995cc8b8b99eab8965062ea227776e49d74..8131270300d04bcd6b344983da755dcee2f5be24 100644 (file)
@@ -29,6 +29,7 @@ private:
   string d_command;
   void launch();
   int d_timeout;
+  int d_abiVersion;
 };
 
 class PipeBackend : public DNSBackend
@@ -49,6 +50,7 @@ private:
   Regex* d_regex;
   string d_regexstr;
   bool d_disavow;
+  int d_abiVersion;
 };