]> granicus.if.org Git - pdns/commitdiff
webserver: determine daemon_type by product type
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Thu, 30 Jan 2014 22:58:21 +0000 (23:58 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Mon, 3 Feb 2014 14:06:19 +0000 (15:06 +0100)
pdns/pdns_recursor.cc
pdns/receiver.cc
pdns/version.cc
pdns/version.hh
pdns/ws-auth.cc

index c06a1ae2d9b98c46cd3d6362d1559ee78a0c372a..f67d31a5814be89ed77dce58e961c1aa227ecc43 100644 (file)
@@ -2007,7 +2007,7 @@ int main(int argc, char **argv)
   g_argc = argc;
   g_argv = argv;
   g_stats.startupTime=time(0);
-  versionSetProduct("Recursor");
+  versionSetProduct(ProductRecursor);
   reportBasicTypes();
   reportOtherTypes();
 
index 355dd05b9d8cc23fd9088849f4383dce0ce87082..61a9f912448fa386b95bedd2bf174b5418aa4e37 100644 (file)
@@ -405,7 +405,7 @@ static void tbhandler(int num)
 //! The main function of pdns, the pdns process
 int main(int argc, char **argv)
 {
-  versionSetProduct("Authoritative Server");
+  versionSetProduct(ProductAuthoritative);
   reportAllTypes(); // init MOADNSParser
 
   // Even if PDNS is not deamonized it must be
index e974b8a6fc7948e36fda19dd65c5a0fe2cf3ba14..a066d17777ff4164657556dc6daab91c804bb905 100644 (file)
@@ -24,7 +24,7 @@
 #include "version.hh"
 #include "version_generated.h"
 
-static string productName("");
+static ProductType productType;
 
 string compilerVersion()
 {
@@ -37,10 +37,30 @@ string compilerVersion()
 #endif
 }
 
+// Human-readable product name
+string productName() {
+  switch (productType) {
+  case ProductAuthoritative:
+    return "PowerDNS Authoritative Server";
+  case ProductRecursor:
+    return "PowerDNS Recursor";
+  };
+}
+
+// REST API product type
+string productTypeApiType() {
+  switch (productType) {
+  case ProductAuthoritative:
+    return "authoritative";
+  case ProductRecursor:
+    return "recursor";
+  };
+}
+
 void showProductVersion()
 {
-  theL()<<Logger::Warning<<"PowerDNS "<<productName<<" "<<PDNS_VERSION<<" ("DIST_HOST") "
-    "(C) 2001-2013 PowerDNS.COM BV" << endl;
+  theL()<<Logger::Warning<<productName()<<" "<<PDNS_VERSION<<" ("DIST_HOST") "
+    "(C) 2001-2014 PowerDNS.COM BV" << endl;
   theL()<<Logger::Warning<<"Using "<<(sizeof(unsigned long)*8)<<"-bits mode. "
     "Built on "BUILD_DATE" by "BUILD_HOST", "<<compilerVersion()<<"."<<endl;
   theL()<<Logger::Warning<<"PowerDNS comes with ABSOLUTELY NO WARRANTY. "
@@ -82,11 +102,16 @@ void showBuildConfiguration()
 string fullVersionString()
 {
   ostringstream s;
-  s << "PowerDNS "<<productName<<" "PDNS_VERSION" ("DIST_HOST" built "BUILD_DATE" "BUILD_HOST")";
+  s<<productName()<<" "PDNS_VERSION" ("DIST_HOST" built "BUILD_DATE" "BUILD_HOST")";
   return s.str();
 }
 
-void versionSetProduct(string product)
+void versionSetProduct(ProductType pt)
+{
+  productType = pt;
+}
+
+ProductType versionGetProduct()
 {
-  productName = product;
+  return productType;
 }
index 22da7cdc86585c1e90331c1b889168eb49bcbe45..8893d7ddd728378d2909f4d2081c047fe5cf052a 100644 (file)
 
 #include "namespaces.hh"
 
+enum ProductType { ProductAuthoritative, ProductRecursor };
+
 string compilerVersion();
 void showProductVersion();
 void showBuildConfiguration();
 string fullVersionString();
-void versionSetProduct(string product);
+string productName();
+string productTypeApiType();
+void versionSetProduct(ProductType pt);
+ProductType versionGetProduct();
 
 #endif //!VERSION_HH
index 3adf9a3156b0d2518a56d91e57499baa8133aa91..d8fc574702a1029ea3410e8f20ec0f0fb9e3b93c 100644 (file)
@@ -374,11 +374,12 @@ static string getZone(const string& zonename) {
 }
 
 static void fillServerDetail(Value& out, Value::AllocatorType& allocator) {
+  Value jdaemonType(productTypeApiType().c_str(), allocator);
   out.SetObject();
   out.AddMember("type", "Server", allocator);
   out.AddMember("id", "localhost", allocator);
   out.AddMember("url", "/servers/localhost", allocator);
-  out.AddMember("daemon_type", "authoritative", allocator);
+  out.AddMember("daemon_type", jdaemonType, allocator);
   out.AddMember("version", VERSION, allocator);
   out.AddMember("config_url", "/servers/localhost/config{/config_setting}", allocator);
   out.AddMember("zones_url", "/servers/localhost/zones{/zone}", allocator);