]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Cleanup of some code, adding of method to return current config.
authorRuben d'Arco <cyclops@prof-x.net>
Mon, 30 Apr 2012 06:14:57 +0000 (08:14 +0200)
committerRuben d'Arco <cyclops@prof-x.net>
Tue, 7 May 2013 20:28:32 +0000 (22:28 +0200)
pdns/dynhandler.cc
pdns/dynhandler.hh [changed mode: 0644->0755]
pdns/dynlistener.cc [changed mode: 0644->0755]
pdns/receiver.cc [changed mode: 0644->0755]

index 141ed1bec28cfdcc9e3d5b77faa4941f320546fe..e50d489148034bbab9310bda5b36241f61505b18 100755 (executable)
@@ -28,6 +28,7 @@
 #include "dnsseckeeper.hh"
 
 static bool s_pleasequit;
+static string d_status;
 
 bool DLQuitPlease()
 {
@@ -51,6 +52,11 @@ static void dokill(int)
   exit(1);
 }
 
+string DLCurrentConfigHandler(const vector<string>&parts, Utility::pid_t ppid)
+{
+  return ::arg().configstring(true);
+}
+
 string DLRQuitHandler(const vector<string>&parts, Utility::pid_t ppid)
 {
 #ifndef WIN32
@@ -89,7 +95,6 @@ string DLShowHandler(const vector<string>&parts, Utility::pid_t ppid)
   return ret;
 }
 
-static string d_status;
 
 void setStatus(const string &str)
 {
@@ -265,3 +270,4 @@ string DLReloadHandler(const vector<string>&parts, Utility::pid_t ppid)
   L<<Logger::Error<<"Reload was requested"<<endl;
   return "Ok";
 }
+
old mode 100644 (file)
new mode 100755 (executable)
index c2b6ffa..33cda15
 
 
 bool DLQuitPlease();
+void setStatus(const string &str);
 string DLQuitHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLRQuitHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLPingHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLShowHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLUptimeHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLSettingsHandler(const vector<string>&parts, Utility::pid_t ppid);
-void setStatus(const string &str);
 string DLCCHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLStatusHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLNotifyHandler(const vector<string>&parts, Utility::pid_t ppid);
@@ -51,4 +51,5 @@ string DLRediscoverHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLVersionHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLPurgeHandler(const vector<string>&parts, Utility::pid_t ppid);
 string DLNotifyRetrieveHandler(const vector<string>&parts, Utility::pid_t ppid);
+string DLCurrentConfigHandler(const vector<string>&parts, Utility::pid_t ppid);
 #endif /* PDNS_DYNHANDLER_HH */
old mode 100644 (file)
new mode 100755 (executable)
index 593f907..c2a2d0d
@@ -195,7 +195,7 @@ string DynListener::getLine()
         continue;
       }
 
-      if(d_tcp && !d_tcprange.match(&remote)) { // ????
+      if(d_tcp && !d_tcprange.match(&remote)) { // checks if the remote is within the permitted range.
         L<<Logger::Error<<"Access denied to remote "<<remote.toString()<<" because not allowed"<<endl;
         writen2(d_client, "Access denied to "+remote.toString()+"\n");
         close(d_client);
@@ -292,11 +292,9 @@ void DynListener::registerRestFunc(g_funk_t *gf)
 void DynListener::theListener()
 {
   try {
-    map<string,string> parameters;
     signal(SIGPIPE,SIG_IGN);
 
     for(int n=0;;++n) {
-      //      cerr<<"Reading new line, "<<d_client<<endl;
       string line=getLine();
       boost::trim_right(line);
 
@@ -306,18 +304,18 @@ void DynListener::theListener()
         sendLine("Empty line");
         continue;
       }
-      parts[0] = toUpper( parts[0] );
-      if(!s_funcdb.count(parts[0])) {
-        if(parts[0] == "HELP")
-          sendLine(getHelp());
-        else if(s_restfunc)
-          sendLine((*s_restfunc)(parts,d_ppid));
-        else
-          sendLine("Unknown command: '"+parts[0]+"'");
-        continue;
-      }
 
-      sendLine((*(s_funcdb[parts[0]].func))(parts,d_ppid));
+      parts[0] = toUpper( parts[0] );
+      if(s_funcdb.count(parts[0])) {
+        cerr<<parts[0]<<" found in s_funcdb"<<endl;
+        sendLine((*(s_funcdb[parts[0]].func))(parts,d_ppid));
+      } else if (parts[0] == "HELP") {
+        sendLine(getHelp());
+      }else if(s_restfunc) {
+        cerr<<"Calling restfunction."<<endl;
+        sendLine((*s_restfunc)(parts,d_ppid));
+      } else
+        sendLine("Unknown command: '"+parts[0]+"'");
     }
   }
   catch(AhuException &AE)
old mode 100644 (file)
new mode 100755 (executable)
index 2f9563d..92e7154
@@ -135,6 +135,15 @@ int g_fd1[2], g_fd2[2];
 FILE *g_fp;
 pthread_mutex_t g_guardian_lock = PTHREAD_MUTEX_INITIALIZER;
 
+// The next two methods are not in dynhandler.cc because they use a few items declared in this file.
+static string DLCycleHandler(const vector<string>&parts, pid_t ppid)
+{
+  kill(cpid, SIGKILL); // why?
+  kill(cpid, SIGKILL); // why?
+  sleep(1);
+  return "ok";
+}
+
 static string DLRestHandler(const vector<string>&parts, pid_t ppid)
 {
   string line;
@@ -165,13 +174,7 @@ static string DLRestHandler(const vector<string>&parts, pid_t ppid)
   return response;
 }
 
-static string DLCycleHandler(const vector<string>&parts, pid_t ppid)
-{
-  kill(cpid, SIGKILL); // why?
-  kill(cpid, SIGKILL); // why?
-  sleep(1);
-  return "ok";
-}
+
 
 static int guardian(int argc, char **argv)
 {
@@ -561,6 +564,7 @@ int main(int argc, char **argv)
     DynListener::registerFunc("CCOUNTS",&DLCCHandler, "get cache statistics");
     DynListener::registerFunc("SET",&DLSettingsHandler, "set config variables", "<var> <value>");
     DynListener::registerFunc("RETRIEVE",&DLNotifyRetrieveHandler, "retrieve slave domain", "<domain>");
+    DynListener::registerFunc("CURRENT-CONFIG",&DLCurrentConfigHandler, "Retrieve the current configuration");
 
     if(!::arg()["tcp-control-address"].empty()) {
       DynListener* dlTCP=new DynListener(ComboAddress(::arg()["tcp-control-address"], ::arg().asNum("tcp-control-port")));