]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/statbag.cc
rec: ensure correct service user on debian
[thirdparty/pdns.git] / pdns / statbag.cc
index f6d07218b0846182a8f21e4a9d5fbc757a969833..c4f46a5b1f8fc70a62cb183f2d7fa7097c34c86d 100644 (file)
@@ -1,25 +1,24 @@
 /*
-    PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002 - 2014  PowerDNS.COM BV
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License version 2
-    as published by the Free Software Foundation
-
-    Additionally, the license of this program contains a special
-    exception which allows to distribute the program in binary form when
-    it is linked against OpenSSL.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -54,12 +53,9 @@ string StatBag::directory()
   string dir;
   ostringstream o;
 
-  for(map<string, AtomicCounter *>::const_iterator i=d_stats.begin();
-      i!=d_stats.end();
-      i++)
-    {
-      o<<i->first<<"="<<*(i->second)<<",";
-    }
+  for(const auto& i: d_stats) {
+    o<<i.first<<"="<<*(i.second)<<",";
+  }
 
 
   for(const funcstats_t::value_type& val :  d_funcstats) {
@@ -74,10 +70,9 @@ vector<string>StatBag::getEntries()
 {
   vector<string> ret;
 
-  for(map<string, AtomicCounter *>::const_iterator i=d_stats.begin();
-      i!=d_stats.end();
-      i++)
-      ret.push_back(i->first);
+  for(const auto& i: d_stats) {
+      ret.push_back(i.first);
+  }
 
   for(const funcstats_t::value_type& val :  d_funcstats) {
     ret.push_back(val.first);
@@ -155,12 +150,9 @@ AtomicCounter *StatBag::getPointer(const string &key)
 
 StatBag::~StatBag()
 {
-  for(map<string, AtomicCounter *>::const_iterator i=d_stats.begin();
-      i!=d_stats.end();
-      i++)
-    {
-      delete i->second;
-    }
+  for(const auto& i: d_stats) {
+    delete i.second;
+  }
   
 }
 
@@ -226,7 +218,7 @@ vector<pair<T, unsigned int> >StatRing<T,Comp>::get() const
 
 void StatBag::declareRing(const string &name, const string &help, unsigned int size)
 {
-  d_rings[name]=StatRing<string>(size);
+  d_rings[name]=StatRing<string, CIStringCompare>(size);
   d_rings[name].setHelp(help);
 }
 
@@ -236,21 +228,33 @@ void StatBag::declareComboRing(const string &name, const string &help, unsigned
   d_comborings[name].setHelp(help);
 }
 
+void StatBag::declareDNSNameQTypeRing(const string &name, const string &help, unsigned int size)
+{
+  d_dnsnameqtyperings[name] = StatRing<std::tuple<DNSName, QType> >(size);
+  d_dnsnameqtyperings[name].setHelp(help);
+}
+
 
 vector<pair<string, unsigned int> > StatBag::getRing(const string &name)
 {
-  if(d_rings.count(name))
+  if(d_rings.count(name)) {
     return d_rings[name].get();
-  else {
+  }
+  vector<pair<string, unsigned int> > ret;
+
+  if (d_comborings.count(name)) {
     typedef pair<SComboAddress, unsigned int> stor_t;
     vector<stor_t> raw =d_comborings[name].get();
-    vector<pair<string, unsigned int> > ret;
     for(const stor_t& stor :  raw) {
       ret.push_back(make_pair(stor.first.ca.toString(), stor.second));
     }
-    return ret;
+  } else if(d_dnsnameqtyperings.count(name)) {
+    auto raw = d_dnsnameqtyperings[name].get();
+    for (auto const &e : raw) {
+      ret.push_back(make_pair(std::get<0>(e.first).toLogString() + "/" + std::get<1>(e.first).getName(), e.second));
+    }
   }
-    
+  return ret;
 }
 
 template<typename T, typename Comp>
@@ -264,16 +268,20 @@ void StatBag::resetRing(const string &name)
 {
   if(d_rings.count(name))
     d_rings[name].reset();
-  else
+  if(d_comborings.count(name))
     d_comborings[name].reset();
+  if(d_dnsnameqtyperings.count(name))
+    d_dnsnameqtyperings[name].reset();
 }
 
 void StatBag::resizeRing(const string &name, unsigned int newsize)
 {
   if(d_rings.count(name))
     d_rings[name].resize(newsize);
-  else
+  if(d_comborings.count(name))
     d_comborings[name].resize(newsize);
+  if(d_dnsnameqtyperings.count(name))
+    return d_dnsnameqtyperings[name].resize(newsize);
 }
 
 
@@ -281,33 +289,42 @@ unsigned int StatBag::getRingSize(const string &name)
 {
   if(d_rings.count(name))
     return d_rings[name].getSize();
-  else
+  if(d_comborings.count(name))
     return d_comborings[name].getSize();
+  if(d_dnsnameqtyperings.count(name))
+    return d_dnsnameqtyperings[name].getSize();
+  return 0;
 }
 
 string StatBag::getRingTitle(const string &name)
 {
   if(d_rings.count(name))
     return d_rings[name].getHelp();
-  else 
+  if(d_comborings.count(name))
     return d_comborings[name].getHelp();
+  if(d_dnsnameqtyperings.count(name))
+    return d_dnsnameqtyperings[name].getHelp();
+  return "";
 }
 
 vector<string>StatBag::listRings()
 {
   vector<string> ret;
-  for(map<string,StatRing<string> >::const_iterator i=d_rings.begin();i!=d_rings.end();++i)
+  for(auto i=d_rings.begin();i!=d_rings.end();++i)
     ret.push_back(i->first);
-  for(map<string,StatRing<SComboAddress> >::const_iterator i=d_comborings.begin();i!=d_comborings.end();++i)
+  for(auto i=d_comborings.begin();i!=d_comborings.end();++i)
     ret.push_back(i->first);
+  for(const auto &i : d_dnsnameqtyperings)
+    ret.push_back(i.first);
 
   return ret;
 }
 
 bool StatBag::ringExists(const string &name)
 {
-  return d_rings.count(name) || d_comborings.count(name);
+  return d_rings.count(name) || d_comborings.count(name) || d_dnsnameqtyperings.count(name);
 }
 
-template class StatRing<std::string>;
+template class StatRing<std::string, CIStringCompare>;
 template class StatRing<SComboAddress>;
+template class StatRing<std::tuple<DNSName, QType> >;