From e0a80cea6f2e1b6ae648e027bea569438e74fbec Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Mon, 24 Aug 2015 10:01:20 +0200 Subject: [PATCH] Revert "Search API for 3.4.6" --- modules/bindbackend/bindbackend2.cc | 34 ------ modules/bindbackend/bindbackend2.hh | 1 - modules/gmysqlbackend/gmysqlbackend.cc | 3 - modules/goraclebackend/goraclebackend.cc | 3 - modules/gpgsqlbackend/gpgsqlbackend.cc | 3 - modules/gsqlite3backend/gsqlite3backend.cc | 3 - modules/remotebackend/httpconnector.cc | 5 - modules/remotebackend/remotebackend.cc | 49 -------- modules/remotebackend/remotebackend.hh | 2 - pdns/backends/gsql/gsqlbackend.cc | 128 +++++---------------- pdns/backends/gsql/gsqlbackend.hh | 10 -- pdns/dnsbackend.hh | 12 -- pdns/misc.hh | 47 -------- pdns/test-misc_hh.cc | 26 ----- pdns/ueberbackend.cc | 15 --- pdns/ueberbackend.hh | 3 - pdns/ws-auth.cc | 93 +++++++-------- regression-tests.api/test_Zones.py | 12 +- 18 files changed, 77 insertions(+), 372 deletions(-) diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 9c072ce49a..39abbd30c7 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -1321,40 +1321,6 @@ bool Bind2Backend::createSlaveDomain(const string &ip, const string &domain, con return true; } -bool Bind2Backend::searchRecords(const string &pattern, int maxResults, vector& result) -{ - SimpleMatch sm(pattern,true); - static bool mustlog=::arg().mustDo("query-logging"); - if(mustlog) - L<d_id, &h); - shared_ptr handle = h.d_records.get(); - - for(recordstorage_t::const_iterator ri = handle->begin(); result.size() < static_cast::size_type>(maxResults) && ri != handle->end(); ri++) { - string name = ri->qname.empty() ? i->d_name : (ri->qname+i->d_name); - if (sm.match(name) || sm.match(ri->content)) { - DNSResourceRecord r; - r.qname=name; - r.domain_id=i->d_id; - r.content=ri->content; - r.qtype=ri->qtype; - r.ttl=ri->ttl; - r.auth = ri->auth; - result.push_back(r); - } - } - } - } - - return true; -} - class Bind2Factory : public BackendFactory { public: diff --git a/modules/bindbackend/bindbackend2.hh b/modules/bindbackend/bindbackend2.hh index 79d7d83370..8666a702a4 100644 --- a/modules/bindbackend/bindbackend2.hh +++ b/modules/bindbackend/bindbackend2.hh @@ -201,7 +201,6 @@ public: bool commitTransaction(); bool abortTransaction(); void alsoNotifies(const string &domain, set *ips); - bool searchRecords(const string &pattern, int maxResults, vector& result); // the DNSSEC related (getDomainMetadata has broader uses too) virtual bool getAllDomainMetadata(const string& name, std::map >& meta); diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index 4999092043..66da8041fa 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -124,9 +124,6 @@ public: declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')"); declare(suffix, "delete-comment-rrset-query", "", "DELETE FROM comments WHERE domain_id=%d AND name='%s' AND type='%s'"); declare(suffix, "delete-comments-query", "", "DELETE FROM comments WHERE domain_id=%d"); - - declare(suffix, "search-records-query", "", record_query+" name LIKE '%s' OR content LIKE '%s' LIMIT %d"); - declare(suffix, "search-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE name LIKE '%s' OR comment LIKE '%s' LIMIT %d"); } DNSBackend *make(const string &suffix="") diff --git a/modules/goraclebackend/goraclebackend.cc b/modules/goraclebackend/goraclebackend.cc index 8e296a1ba1..7d24ddd41e 100644 --- a/modules/goraclebackend/goraclebackend.cc +++ b/modules/goraclebackend/goraclebackend.cc @@ -131,9 +131,6 @@ public: declare(suffix, "insert-comment-query", "", "INSERT INTO comments (id, domain_id, name, type, modified_at, account, \"comment\") VALUES (comments_id_sequence.nextval, %d, '%s', '%s', %d, '%s', '%s')"); declare(suffix, "delete-comment-rrset-query", "", "DELETE FROM comments WHERE domain_id=%d AND name='%s' AND type='%s'"); declare(suffix, "delete-comments-query", "", "DELETE FROM comments WHERE domain_id=%d"); - - declare(suffix, "search-records-query", "", record_query+" name LIKE '%s' OR content LIKE '%s' LIMIT %d"); - declare(suffix, "search-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE name LIKE '%s' OR comment LIKE '%s' LIMIT %d"); } DNSBackend* make(const string &suffix="") { diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index 1d1e3af140..d3c1866084 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -118,9 +118,6 @@ public: declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, E'%s', E'%s', %d, E'%s', E'%s')"); declare(suffix, "delete-comment-rrset-query", "", "DELETE FROM comments WHERE domain_id=%d AND name=E'%s' AND type=E'%s'"); declare(suffix, "delete-comments-query", "", "DELETE FROM comments WHERE domain_id=%d"); - - declare(suffix, "search-records-query", "", record_query+" name LIKE '%s' OR content LIKE '%s' LIMIT %d"); - declare(suffix, "search-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE name LIKE '%s' OR comment LIKE '%s' LIMIT %d"); } DNSBackend *make(const string &suffix="") diff --git a/modules/gsqlite3backend/gsqlite3backend.cc b/modules/gsqlite3backend/gsqlite3backend.cc index 670031e5f6..b99888cda4 100644 --- a/modules/gsqlite3backend/gsqlite3backend.cc +++ b/modules/gsqlite3backend/gsqlite3backend.cc @@ -134,9 +134,6 @@ public: declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')"); declare(suffix, "delete-comment-rrset-query", "", "DELETE FROM comments WHERE domain_id=%d AND name='%s' AND type='%s'"); declare(suffix, "delete-comments-query", "", "DELETE FROM comments WHERE domain_id=%d"); - - declare(suffix, "search-records-query", "", record_query+" name LIKE '%s' OR content LIKE '%s' LIMIT %d"); - declare(suffix, "search-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE name LIKE '%s' OR comment LIKE '%s' LIMIT %d"); } //! Constructs a new gSQLite3Backend object. diff --git a/modules/remotebackend/httpconnector.cc b/modules/remotebackend/httpconnector.cc index 6586aee51b..b74d105a9d 100644 --- a/modules/remotebackend/httpconnector.cc +++ b/modules/remotebackend/httpconnector.cc @@ -237,11 +237,6 @@ void HTTPConnector::restful_requestbuilder(const std::string &method, const rapi req.POST()["serial"] = sparam; req.preparePost(); verb = "PATCH"; - } else if (method == "searchRecords" || method == "searchComments") { - json2string(parameters["pattern"],sparam); - req.GET()["pattern"] = sparam; - req.GET()["maxResults"] = boost::lexical_cast(parameters["maxResults"].GetInt()); - verb = "GET"; } else { // perform normal get verb = "GET"; diff --git a/modules/remotebackend/remotebackend.cc b/modules/remotebackend/remotebackend.cc index 65848871dc..884480ddbc 100644 --- a/modules/remotebackend/remotebackend.cc +++ b/modules/remotebackend/remotebackend.cc @@ -935,55 +935,6 @@ bool RemoteBackend::calculateSOASerial(const string& domain, const SOAData& sd, return true; } -bool RemoteBackend::searchRecords(const string &pattern, int maxResults, vector& 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& result) -{ - // FIXME: Implement Comment API - return false; -} - - // some rapidjson helpers bool RemoteBackend::getBool(rapidjson::Value &value) { if (value.IsNull()) return false; diff --git a/modules/remotebackend/remotebackend.hh b/modules/remotebackend/remotebackend.hh index 79f0db7675..2a7d37d7b4 100644 --- a/modules/remotebackend/remotebackend.hh +++ b/modules/remotebackend/remotebackend.hh @@ -162,8 +162,6 @@ class RemoteBackend : public DNSBackend virtual bool setTSIGKey(const string& name, const string& algorithm, const string& content); virtual bool deleteTSIGKey(const string& name); virtual bool getTSIGKeys(std::vector< struct TSIGKey > &keys); - virtual bool searchRecords(const string &pattern, int maxResults, vector& result); - virtual bool searchComments(const string &pattern, int maxResults, vector& result); static DNSBackend *maker(); diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 1d995d4862..f6b259ffc6 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -356,9 +356,6 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix) d_setTSIGKeyQuery = getArg("set-tsig-key-query"); d_deleteTSIGKeyQuery = getArg("delete-tsig-key-query"); d_getTSIGKeysQuery = getArg("get-tsig-keys-query"); - - d_SearchRecordsQuery = getArg("search-records-query"); - d_SearchCommentsQuery = getArg("search-comments-query"); } bool GSQLBackend::updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth) @@ -1038,7 +1035,27 @@ bool GSQLBackend::get(DNSResourceRecord &r) // L << "GSQLBackend get() was called for "<getRow(row)) { - extractRecord(row, r); + r.content=row[0]; + if (row[1].empty()) + r.ttl = ::arg().asNum( "default-ttl" ); + else + r.ttl=atol(row[1].c_str()); + r.priority=atol(row[2].c_str()); + if(!d_qname.empty()) + r.qname=d_qname; + else + r.qname=row[6]; + r.qtype=row[3]; + r.last_modified=0; + + if(d_dnssecQueries) + r.auth = !row[7].empty() && row[7][0]=='1'; + else + r.auth = 1; + + r.disabled = !row[5].empty() && row[5][0]=='1'; + + r.domain_id=atoi(row[4].c_str()); return true; } @@ -1277,7 +1294,13 @@ bool GSQLBackend::getComment(Comment& comment) } // domain_id,name,type,modified_at,account,comment - extractComment(row, comment); + comment.domain_id = atol(row[0].c_str()); + comment.qname = row[1]; + comment.qtype = row[2]; + comment.modified_at = atol(row[3].c_str()); + comment.account = row[4]; + comment.content = row[5]; + return true; } @@ -1322,98 +1345,3 @@ bool GSQLBackend::replaceComments(const uint32_t domain_id, const string& qname, return true; } - -string GSQLBackend::pattern2SQLPattern(const string &pattern) -{ - string escaped_pattern = boost::replace_all_copy(pattern,"\\","\\\\"); - boost::replace_all(escaped_pattern,"_","\\_"); - boost::replace_all(escaped_pattern,"%","\\%"); - boost::replace_all(escaped_pattern,"*","%"); - boost::replace_all(escaped_pattern,"?","_"); - return escaped_pattern; -} - -bool GSQLBackend::searchRecords(const string &pattern, int maxResults, vector& result) -{ - string escaped_pattern = pattern2SQLPattern(pattern); - string query = (GSQLformat(d_SearchRecordsQuery) - % escaped_pattern - % escaped_pattern - % maxResults).str(); - - try { - SSql::row_t row; - d_db->doQuery(query); - while(d_db->getRow(row)) { - DNSResourceRecord r; - extractRecord(row, r); - result.push_back(r); - } - return true; - } - catch (SSqlException &e) { - throw PDNSException("GSQLBackend unable to execute query: "+e.txtReason()); - } - - return false; -} - -bool GSQLBackend::searchComments(const string &pattern, int maxResults, vector& result) -{ - string escaped_pattern = pattern2SQLPattern(pattern); - string query = (GSQLformat(d_SearchCommentsQuery) - % escaped_pattern - % escaped_pattern - % maxResults).str(); - - try { - SSql::row_t row; - d_db->doQuery(query); - while(d_db->getRow(row)) { - Comment c; - extractComment(row, c); - result.push_back(c); - } - return true; - } - catch (SSqlException &e) { - throw PDNSException("GSQLBackend unable to execute query: "+e.txtReason()); - } - - return false; -} - -void GSQLBackend::extractRecord(const SSql::row_t& row, DNSResourceRecord& r) -{ - r.content=row[0]; - if (row[1].empty()) - r.ttl = ::arg().asNum( "default-ttl" ); - else - r.ttl=atol(row[1].c_str()); - r.priority=atol(row[2].c_str()); - if(!d_qname.empty()) - r.qname=d_qname; - else - r.qname=row[6]; - r.qtype=row[3]; - r.last_modified=0; - - if(d_dnssecQueries) - r.auth = !row[7].empty() && row[7][0]=='1'; - else - r.auth = 1; - - r.disabled = !row[5].empty() && row[5][0]=='1'; - - r.domain_id=atoi(row[4].c_str()); -} - -void GSQLBackend::extractComment(const SSql::row_t& row, Comment& comment) -{ - comment.domain_id = atol(row[0].c_str()); - comment.qname = row[1]; - comment.qtype = row[2]; - comment.modified_at = atol(row[3].c_str()); - comment.account = row[4]; - comment.content = row[5]; -} diff --git a/pdns/backends/gsql/gsqlbackend.hh b/pdns/backends/gsql/gsqlbackend.hh index 792460c5ec..246ce51001 100644 --- a/pdns/backends/gsql/gsqlbackend.hh +++ b/pdns/backends/gsql/gsqlbackend.hh @@ -88,13 +88,6 @@ public: void feedComment(const Comment& comment); bool replaceComments(const uint32_t domain_id, const string& qname, const QType& qt, const vector& comments); - bool searchRecords(const string &pattern, int maxResults, vector& result); - bool searchComments(const string &pattern, int maxResults, vector& result); - -protected: - string pattern2SQLPattern(const string& pattern); - void extractRecord(const SSql::row_t& row, DNSResourceRecord& rr); - void extractComment(const SSql::row_t& row, Comment& comment); private: string d_qname; SSql *d_db; @@ -172,9 +165,6 @@ private: string d_DeleteCommentRRsetQuery; string d_DeleteCommentsQuery; - string d_SearchRecordsQuery; - string d_SearchCommentsQuery; - protected: bool d_dnssecQueries; }; diff --git a/pdns/dnsbackend.hh b/pdns/dnsbackend.hh index e43483fae9..b4122b96e4 100644 --- a/pdns/dnsbackend.hh +++ b/pdns/dnsbackend.hh @@ -381,18 +381,6 @@ public: return false; } - //! Search for records, returns true if search was done successfully. - virtual bool searchRecords(const string &pattern, int maxResults, vector& result) - { - return false; - } - - //! Search for comments, returns true if search was done successfully. - virtual bool searchComments(const string &pattern, int maxResults, vector& result) - { - return false; - } - protected: bool mustDo(const string &key); const string &getArg(const string &key); diff --git a/pdns/misc.hh b/pdns/misc.hh index 5d99f98c9a..e682fb70a7 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -535,53 +535,6 @@ private: regex_t d_preg; }; -class SimpleMatch -{ -public: - SimpleMatch(const string &mask, bool caseFold = false) - { - this->d_mask = mask; - this->d_fold = caseFold; - } - - bool match(string::const_iterator mi, string::const_iterator mend, string::const_iterator vi, string::const_iterator vend) - { - for(;;mi++) { - if (mi == mend) { - return vi == vend; - } else if (*mi == '?') { - if (vi == vend) return false; - vi++; - } else if (*mi == '*') { - while(*mi == '*') mi++; - if (mi == d_mask.end()) return true; - while(vi != vend) { - if (match(mi,mend,vi,vend)) return true; - vi++; - } - return false; - } else { - if ((mi == mend && vi != vend)|| - (mi != mend && vi == vend)) return false; - if (d_fold) { - if (dns_tolower(*mi) != dns_tolower(*vi)) return false; - } else { - if (*mi != *vi) return false; - } - vi++; - } - } - } - - bool match(const string& value) { - return match(d_mask.begin(), d_mask.end(), value.begin(), value.end()); - } - -private: - string d_mask; - bool d_fold; -}; - union ComboAddress; void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, ComboAddress* source); diff --git a/pdns/test-misc_hh.cc b/pdns/test-misc_hh.cc index 4d602b39f8..9d495a2da2 100644 --- a/pdns/test-misc_hh.cc +++ b/pdns/test-misc_hh.cc @@ -141,31 +141,5 @@ BOOST_AUTO_TEST_CASE(test_parseService) { BOOST_CHECK_EQUAL(tp.port, 25); } -BOOST_AUTO_TEST_CASE(test_SimpleMatch) { - BOOST_CHECK_EQUAL(SimpleMatch("").match(std::string("")), true); - BOOST_CHECK_EQUAL(SimpleMatch("?").match(std::string("")), false); - BOOST_CHECK_EQUAL(SimpleMatch("*").match(std::string("")), true); - - BOOST_CHECK_EQUAL(SimpleMatch("abc").match(std::string("abc")), true); - BOOST_CHECK_EQUAL(SimpleMatch("abc").match(std::string("ab")), false); - BOOST_CHECK_EQUAL(SimpleMatch("abc").match(std::string("bc")), false); - - BOOST_CHECK_EQUAL(SimpleMatch("?").match(std::string("a")), true); - BOOST_CHECK_EQUAL(SimpleMatch("a?c").match(std::string("abc")), true); - BOOST_CHECK_EQUAL(SimpleMatch("a?c").match(std::string("ab")), false); - BOOST_CHECK_EQUAL(SimpleMatch("a?c").match(std::string("bc")), false); - - BOOST_CHECK_EQUAL(SimpleMatch("*").match(std::string("*")), true); - BOOST_CHECK_EQUAL(SimpleMatch("a*c").match(std::string("abc")), true); - BOOST_CHECK_EQUAL(SimpleMatch("a*c").match(std::string("ab")), false); - BOOST_CHECK_EQUAL(SimpleMatch("a*c").match(std::string("bc")), false); - - BOOST_CHECK_EQUAL(SimpleMatch("*").match(std::string("abcdefghj")), true); - BOOST_CHECK_EQUAL(SimpleMatch("*a").match(std::string("abca")), true); - BOOST_CHECK_EQUAL(SimpleMatch("*a").match(std::string("abcb")), false); - BOOST_CHECK_EQUAL(SimpleMatch("abc*").match(std::string("abcabcabcabacabac")), true); - BOOST_CHECK_EQUAL(SimpleMatch("abc*").match(std::string("abc")), true); -} - BOOST_AUTO_TEST_SUITE_END() diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index ab3cefc9a6..0c48f69161 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -618,21 +618,6 @@ bool UeberBackend::list(const string &target, int domain_id, bool include_disabl return false; } -bool UeberBackend::searchRecords(const string& pattern, int maxResults, vector& result) -{ - bool rc = false; - for ( vector< DNSBackend * >::iterator i = backends.begin(); result.size() < static_cast::size_type>(maxResults) && i != backends.end(); ++i ) - if ((*i)->searchRecords(pattern, maxResults - result.size(), result)) rc = true; - return rc; -} - -bool UeberBackend::searchComments(const string& pattern, int maxResults, vector& result) -{ - bool rc = false; - for ( vector< DNSBackend * >::iterator i = backends.begin(); result.size() < static_cast::size_type>(maxResults) && i != backends.end(); ++i ) - if ((*i)->searchComments(pattern, maxResults - result.size(), result)) rc = true; - return rc; -} AtomicCounter UeberBackend::handle::instances(0); diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index c9f1b264f4..6837ed1b72 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -153,9 +153,6 @@ public: void alsoNotifies(const string &domain, set *ips); void rediscover(string* status=0); void reload(); - - bool searchRecords(const string &pattern, int maxResults, vector& result); - bool searchComments(const string &pattern, int maxResults, vector& result); private: unsigned int d_cache_ttl, d_negcache_ttl; diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index afa842eb51..0a4fcfb07b 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -1111,88 +1111,81 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { throw HttpMethodNotAllowedException(); string q = req->getvars["q"]; - string sMax = req->getvars["max"]; - int maxEnts = 100; - int ents = 0; - if (q.empty()) throw ApiException("Query q can't be blank"); - if (sMax.empty() == false) - maxEnts = boost::lexical_cast(sMax); - if (maxEnts < 1) - throw ApiException("Maximum entries must be larger than 0"); - SimpleMatch sm(q,true); UeberBackend B; + vector domains; - vector result_rr; - vector result_c; - map zoneIdZone; - map::iterator val; - Document doc; + B.getAllDomains(&domains, true); // incl. disabled + Document doc; doc.SetArray(); - B.getAllDomains(&domains, true); + DNSResourceRecord rr; + Comment comment; - BOOST_FOREACH(const DomainInfo di, domains) - { - if (ents < maxEnts && sm.match(di.zone)) { + BOOST_FOREACH(const DomainInfo& di, domains) { + string zoneId = apiZoneNameToId(di.zone); + + if (pdns_ci_find(di.zone, q) != string::npos) { Value object; object.SetObject(); - object.AddMember("object_type", "zone", doc.GetAllocator()); - object.AddMember("zone_id", di.id, doc.GetAllocator()); + object.AddMember("type", "zone", doc.GetAllocator()); + Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy + object.AddMember("zone_id", jzoneId, doc.GetAllocator()); Value jzoneName(di.zone.c_str(), doc.GetAllocator()); // copy object.AddMember("name", jzoneName, doc.GetAllocator()); doc.PushBack(object, doc.GetAllocator()); - ents++; } - zoneIdZone[di.id] = di.zone; // populate cache - } - if (B.searchRecords(q, maxEnts, result_rr)) - { - BOOST_FOREACH(const DNSResourceRecord& rr, result_rr) - { + // if zone name is an exact match, don't bother with returning all records/comments in it + if (di.zone == q) { + continue; + } + // the code below is too slow +#if 0 + di.backend->list(di.zone, di.id, true); // incl. disabled + while(di.backend->get(rr)) { + if (!rr.qtype.getCode()) + continue; // skip empty non-terminals + + if (pdns_ci_find(rr.qname, q) == string::npos && pdns_ci_find(rr.content, q) == string::npos) + continue; + Value object; object.SetObject(); - object.AddMember("object_type", "record", doc.GetAllocator()); - object.AddMember("zone_id", rr.domain_id, doc.GetAllocator()); - if ((val = zoneIdZone.find(rr.domain_id)) != zoneIdZone.end()) { - Value zname(val->second.c_str(), doc.GetAllocator()); // copy - object.AddMember("zone", zname, doc.GetAllocator()); // copy - } + object.AddMember("type", "record", doc.GetAllocator()); + Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy + object.AddMember("zone_id", jzoneId, doc.GetAllocator()); + Value jzoneName(di.zone.c_str(), doc.GetAllocator()); // copy + object.AddMember("zone_name", jzoneName, doc.GetAllocator()); Value jname(rr.qname.c_str(), doc.GetAllocator()); // copy object.AddMember("name", jname, doc.GetAllocator()); - Value jtype(rr.qtype.getName().c_str(), doc.GetAllocator()); // copy - object.AddMember("type", jtype, doc.GetAllocator()); - object.AddMember("ttl", rr.ttl, doc.GetAllocator()); - object.AddMember("disabled", rr.disabled, doc.GetAllocator()); Value jcontent(rr.content.c_str(), doc.GetAllocator()); // copy object.AddMember("content", jcontent, doc.GetAllocator()); doc.PushBack(object, doc.GetAllocator()); } - } - if (B.searchComments(q, maxEnts, result_c)) - { - BOOST_FOREACH(const Comment &c, result_c) - { + di.backend->listComments(di.id); + while(di.backend->getComment(comment)) { + if (pdns_ci_find(comment.qname, q) == string::npos && pdns_ci_find(comment.content, q) == string::npos) + continue; Value object; object.SetObject(); - object.AddMember("object_type", "comment", doc.GetAllocator()); - object.AddMember("zone_id", c.domain_id, doc.GetAllocator()); - if ((val = zoneIdZone.find(c.domain_id)) != zoneIdZone.end()) { - Value zname(val->second.c_str(), doc.GetAllocator()); // copy - object.AddMember("zone", zname, doc.GetAllocator()); // copy - } - Value jname(c.qname.c_str(), doc.GetAllocator()); // copy + object.AddMember("type", "comment", doc.GetAllocator()); + Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy + object.AddMember("zone_id", jzoneId, doc.GetAllocator()); + Value jzoneName(di.zone.c_str(), doc.GetAllocator()); // copy + object.AddMember("zone_name", jzoneName, doc.GetAllocator()); + Value jname(comment.qname.c_str(), doc.GetAllocator()); // copy object.AddMember("name", jname, doc.GetAllocator()); - Value jcontent(c.content.c_str(), doc.GetAllocator()); // copy + Value jcontent(comment.content.c_str(), doc.GetAllocator()); // copy object.AddMember("content", jcontent, doc.GetAllocator()); doc.PushBack(object, doc.GetAllocator()); } +#endif } resp->setBody(doc); diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index adffaa0e80..75f306a0dd 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -984,26 +984,26 @@ fred IN A 192.168.0.4 self.create_zone(name=name) r = self.session.get(self.url("/servers/localhost/search-data?q=" + name)) self.assert_success_json(r) - r = [r.json()[0]] - self.assertEquals(r, [{u'object_type': u'zone', u'name': name, u'zone_id': 22}]) + print r.json() + self.assertEquals(r.json(), [{u'type': u'zone', u'name': name, u'zone_id': name+'.'}]) def test_search_rr_substring(self): name = 'search-rr-zone.name' self.create_zone(name=name) - r = self.session.get(self.url("/servers/localhost/search-data?q=*rr-zone*")) + r = self.session.get(self.url("/servers/localhost/search-data?q=rr-zone")) self.assert_success_json(r) print r.json() # should return zone, SOA, ns1, ns2 - self.assertEquals(len(r.json()), 4) + self.assertEquals(len(r.json()), 1) # FIXME test disarmed for now (should be 4) def test_search_rr_case_insensitive(self): name = 'search-rr-insenszone.name' self.create_zone(name=name) - r = self.session.get(self.url("/servers/localhost/search-data?q=*rr-insensZONE*")) + r = self.session.get(self.url("/servers/localhost/search-data?q=rr-insensZONE")) self.assert_success_json(r) print r.json() # should return zone, SOA, ns1, ns2 - self.assertEquals(len(r.json()), 4) + self.assertEquals(len(r.json()), 1) # FIXME test disarmed for now (should be 4) @unittest.skipIf(not is_auth(), "Not applicable") -- 2.47.2