From: Christian Hofstaedtler Date: Sun, 21 Feb 2016 22:15:17 +0000 (+0100) Subject: Turn Comment.qname into a DNSName X-Git-Tag: auth-4.0.0-alpha2~17^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25dcc05fade87e302a910108e107a21f7173b082;p=thirdparty%2Fpdns.git Turn Comment.qname into a DNSName --- diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index c41670ce50..e6322e789f 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -1495,25 +1495,30 @@ bool GSQLBackend::getComment(Comment& comment) { SSqlStatement::row_t row; - if (!d_query_stmt->hasNextRow()) { + for(;;) { + if (!d_query_stmt->hasNextRow()) { + try { + d_query_stmt->reset(); + } catch(SSqlException &e) { + throw DBException("GSQLBackend comment get: "+e.txtReason()); + } + d_query_stmt = NULL; + return false; + } + try { - d_query_stmt->reset(); + d_query_stmt->nextRow(row); + ASSERT_ROW_COLUMNS(d_query_name, row, 6); } catch(SSqlException &e) { throw DBException("GSQLBackend comment get: "+e.txtReason()); } - d_query_stmt = NULL; - return false; - } - - try { - d_query_stmt->nextRow(row); - ASSERT_ROW_COLUMNS(d_query_name, row, 6); - } catch(SSqlException &e) { - throw DBException("GSQLBackend comment get: "+e.txtReason()); + try { + extractComment(row, comment); + } catch (...) { + continue; + } + return true; } - // domain_id,name,type,modified_at,account,comment - extractComment(row, comment); - return true; } void GSQLBackend::feedComment(const Comment& comment) @@ -1521,7 +1526,7 @@ void GSQLBackend::feedComment(const Comment& comment) try { d_InsertCommentQuery_stmt-> bind("domain_id",comment.domain_id)-> - bind("qname",toLower(comment.qname))-> + bind("qname",comment.qname)-> bind("qtype",comment.qtype.getName())-> bind("modified_at",comment.modified_at)-> bind("account",comment.account)-> @@ -1592,6 +1597,7 @@ string GSQLBackend::pattern2SQLPattern(const string &pattern) bool GSQLBackend::searchRecords(const string &pattern, int maxResults, vector& result) { + d_qname.clear(); try { string escaped_pattern = pattern2SQLPattern(pattern); @@ -1690,12 +1696,12 @@ void GSQLBackend::extractRecord(const SSqlStatement::row_t& row, DNSResourceReco void GSQLBackend::extractComment(const SSqlStatement::row_t& row, Comment& comment) { - comment.domain_id = pdns_stou(row[0]); - comment.qname = row[1]; - comment.qtype = row[2]; - comment.modified_at = pdns_stou(row[3]); - comment.account = row[4]; - comment.content = row[5]; + comment.domain_id = pdns_stou(row[0]); + comment.qname = DNSName(row[1]); + comment.qtype = row[2]; + comment.modified_at = pdns_stou(row[3]); + comment.account = row[4]; + comment.content = row[5]; } bool GSQLBackend::isOurDomain(const DNSName *zone, int domain_id) { diff --git a/pdns/comment.hh b/pdns/comment.hh index 2fd3e5ea99..06692bbc75 100644 --- a/pdns/comment.hh +++ b/pdns/comment.hh @@ -33,7 +33,7 @@ public: ~Comment() {}; // data - string qname; //!< the name of the associated RRset, for example: www.powerdns.com + DNSName qname; //!< the name of the associated RRset, for example: www.powerdns.com time_t modified_at; string account; //!< account last updating this comment string content; //!< The actual comment. Example: blah blah diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 8d88687755..e69f470244 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -359,7 +359,7 @@ static void fillZone(const DNSName& zonename, HttpResponse* resp) { di.backend->listComments(di.id); while(di.backend->getComment(comment)) { comments.push_back(Json::object { - { "name", comment.qname }, + { "name", comment.qname.toString() }, { "type", comment.qtype.getName() }, { "modified_at", (double)comment.modified_at }, { "account", comment.account }, @@ -1068,7 +1068,7 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { { auto object = Json::object { { "object_type", "comment" }, - { "name", c.qname }, + { "name", c.qname.toString() }, { "content", c.content } }; if ((val = zoneIdZone.find(c.domain_id)) != zoneIdZone.end()) {