]> granicus.if.org Git - pdns/commitdiff
Add support for searchRecords to RemoteBackend
authorAki Tuomi <cmouse@desteem.org>
Thu, 30 Jul 2015 17:23:29 +0000 (20:23 +0300)
committerAki Tuomi <cmouse@cmouse.fi>
Tue, 4 Aug 2015 12:26:16 +0000 (15:26 +0300)
modules/remotebackend/httpconnector.cc
modules/remotebackend/remotebackend.cc
modules/remotebackend/remotebackend.hh

index d2d6cb78665411fe9b85ab1771c6837373b23aa4..e809a1f254f9c29f18379ca10ee3821f64e032b8 100644 (file)
@@ -245,6 +245,11 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi
         req.POST()["query"] = sparam;
         req.preparePost();
         verb = "POST";
+    } else if (method == "searchRecords" || method == "searchComments") {
+        json2string(parameters["pattern"],sparam);
+        req.GET()["pattern"] = sparam;
+        req.GET()["maxResults"] = boost::lexical_cast<std::string>(parameters["maxResults"].GetInt());
+        verb = "GET";
     } else {
         // perform normal get
         verb = "GET";
index 2bdb71c4c5b833fb76a9da9b417c6c23910c1dfb..f1b3bad06f7b59bb8895deaa67b62ca581756cf5 100644 (file)
@@ -954,6 +954,55 @@ string RemoteBackend::directBackendCmd(const string& querystr) {
    return getString(answer["result"]);
 }
 
+bool RemoteBackend::searchRecords(const string &pattern, int maxResults, vector<DNSResourceRecord>& result)
+{
+   rapidjson::Document query,answer;
+   rapidjson::Value parameters;
+
+   query.SetObject();
+   JSON_ADD_MEMBER(query, "method", "searchRecords", query.GetAllocator());
+   parameters.SetObject();
+   JSON_ADD_MEMBER(parameters, "pattern", pattern.c_str(), query.GetAllocator());
+   JSON_ADD_MEMBER(parameters, "maxResults", maxResults, query.GetAllocator());
+   query.AddMember("parameters", parameters, query.GetAllocator());
+
+   if (this->send(query) == false || this->recv(answer) == false)
+     return false;
+
+   if (answer["result"].IsArray() == false)
+     return false;
+
+   for(rapidjson::SizeType i = 0; i < answer["result"].Size(); i++) {
+     DNSResourceRecord rr;
+     rapidjson::Value value;
+     value = "";
+     rr.qtype = getString(JSON_GET((*d_result)["result"][d_index], "qtype", value));
+     rr.qname = getString(JSON_GET((*d_result)["result"][d_index], "qname", value));
+     rr.qclass = QClass::IN;
+     rr.content = getString(JSON_GET((*d_result)["result"][d_index], "content",value));
+     value = -1;
+     rr.ttl = getInt(JSON_GET((*d_result)["result"][d_index], "ttl",value));
+     rr.domain_id = getInt(JSON_GET((*d_result)["result"][d_index],"domain_id",value));
+     value = 1;
+     if (d_dnssec)
+       rr.auth = getInt(JSON_GET((*d_result)["result"][d_index],"auth", value));
+     else
+       rr.auth = 1;
+     value = 0;
+     rr.scopeMask = getInt(JSON_GET((*d_result)["result"][d_index],"scopeMask", value));
+     result.push_back(rr);
+  }
+
+  return true;
+}
+
+bool RemoteBackend::searchComments(const string &pattern, int maxResults, vector<Comment>& result)
+{
+  // FIXME: Implement Comment API
+  return false;
+}
+
+
 // some rapidjson helpers 
 bool RemoteBackend::getBool(rapidjson::Value &value) {
    if (value.IsNull()) return false;
index 89b8ee0c92367bb7dd7d72019f4a17f93c25fb1b..b1b18083a8477a3e15561a564a4e939e288f7f74 100644 (file)
@@ -165,6 +165,8 @@ class RemoteBackend : public DNSBackend
   virtual bool deleteTSIGKey(const DNSName& name);
   virtual bool getTSIGKeys(std::vector< struct TSIGKey > &keys);
   virtual string directBackendCmd(const string& querystr);
+  virtual bool searchRecords(const string &pattern, int maxResults, vector<DNSResourceRecord>& result);
+  virtual bool searchComments(const string &pattern, int maxResults, vector<Comment>& result);
 
   static DNSBackend *maker();