]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Refactored some redundant loops in CommunicatorClass::go()
authorRalph Covelli <rcovelli@he.net>
Fri, 12 May 2017 03:40:14 +0000 (04:40 +0100)
committerRalph Covelli <rcovelli@he.net>
Fri, 12 May 2017 03:40:14 +0000 (04:40 +0100)
pdns/communicator.cc

index eff4f2bb74ef7785be7b6e5c270ec7aeaca54b89..6958a8ef3afd5a2e1dc6ce79e7c81d9404bdb6a0 100644 (file)
 #include "arguments.hh"
 #include "packetcache.hh"
 
+#define CommunicatorLoadArgsIntoSet(listname,listset) do {                                 \
+  vector<string> parts;                                                                    \
+  stringtok(parts, ::arg()[(listname)], ", \t");                                           \
+  for (vector<string>::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) { \
+    try {                                                                                  \
+      ComboAddress caIp(*iter, 53);                                                        \
+      (listset).insert(caIp.toStringWithPort());                                           \
+    }                                                                                      \
+    catch(PDNSException &e) {                                                              \
+      L<<Logger::Error<<"Unparseable IP in "<<(listname)<<". Error: "<<e.reason<<endl;     \
+      exit(1);                                                                             \
+    }                                                                                      \
+  }                                                                                        \
+} while(0)
+
 // there can be MANY OF THESE
 void CommunicatorClass::retrievalLoopThread(void)
 {
@@ -80,31 +95,9 @@ void CommunicatorClass::go()
     exit(1);
   }
 
-  vector<string> parts;
-  stringtok(parts, ::arg()["also-notify"], ", \t");
-  for (vector<string>::const_iterator iter = parts.begin(); iter != parts.end(); ++iter) {
-    try {
-      ComboAddress caIp(*iter, 53);
-      d_alsoNotify.insert(caIp.toStringWithPort());
-    }
-    catch(PDNSException &e) {
-      L<<Logger::Error<<"Unparseable IP in also-notify. Error: "<<e.reason<<endl;
-      exit(1);
-    }
-  }
+  CommunicatorLoadArgsIntoSet("also-notify",d_alsoNotify);
 
-  vector<string> forwards;
-  stringtok(forwards, ::arg()["forward-notify"], ", \t");
-  for (vector<string>::const_iterator iter = forwards.begin(); iter != forwards.end(); ++iter) {
-    try {
-      ComboAddress caIp(*iter, 53);
-      PacketHandler::s_forwardNotify.insert(caIp.toStringWithPort());
-    }
-    catch(PDNSException &e) {
-      L<<Logger::Error<<"Unparseable IP in forward-notify. Error: "<<e.reason<<endl;
-      exit(1);
-    }
-  }
+  CommunicatorLoadArgsIntoSet("forward-notify",PacketHandler::s_forwardNotify);
 }
 
 void CommunicatorClass::mainloop(void)