powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. d336cf29a785


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. d336cf29a785c338ad11bf960fa1116c07ccd050
Date: Sun, 9 Dec 2018 18:36:23 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  d336cf29a785c338ad11bf960fa1116c07ccd050 (commit)
      from  7c3a1fedb7a514d9aae374ead2f923bcc3fe59f7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=d336cf29a785c338ad11bf960fa1116c07ccd050


commit d336cf29a785c338ad11bf960fa1116c07ccd050
Author: Rob Savoye <address@hidden>
Date:   Sun Dec 9 16:36:12 2018 -0700

    Add HELO message to handshake network connections

diff --git a/lib/commands.cc b/lib/commands.cc
index abcd535..40c98b5 100644
--- a/lib/commands.cc
+++ b/lib/commands.cc
@@ -30,12 +30,18 @@
 #include "xml.h"
 #include "log.h"
 #include "commands.h"
+#include <thread>
 
 extern LogFile dbglogfile;
 
 Commands::Commands()
 {
     DEBUGLOG_REPORT_FUNCTION;
+
+    _commands["nop"] = Commands::NOP;
+    _commands["list"] = Commands::LIST;
+    _commands["poll"] = Commands::POLL;
+    _commands["helo"] = Commands::HELO;
 }
 
 Commands::~Commands()
@@ -48,32 +54,56 @@ Commands::createCommand(cmd_t cmd, const std::string &args,
                         std::string &str)
 {
     DEBUGLOG_REPORT_FUNCTION;
+    
     str.clear();
     str = "<command>";
     switch (cmd) {
       case LIST:
-          dbglogfile << "LIST command" << std::endl;
+          dbglogfile << "create LIST command" << std::endl;
           str += "<list>" + args + "</list>";
           break;
       case POLL:
-          dbglogfile << "POLL command" << std::endl;  
+          dbglogfile << "create POLL command" << std::endl;  
           str += "<poll>" + args + "</poll>";
           break;
       case NOP:
-          dbglogfile << "NOP command" << std::endl;  
+          dbglogfile << "create NOP command" << std::endl;  
+          str += "<nop>" + args + "</nop>";
+          break;
+      case HELO:
+          dbglogfile << "create HELO command" << std::endl;
+          std::string data = "<hostname>";
+          size_t pos = args.find(' ');
+          if (pos == std::string::npos) {
+              data += args;
+          } else {
+              data += args.substr(0, pos);
+          }
+          data += "</hostname>";
+          if (pos != std::string::npos) {
+              data += "<user>";
+              data += args.substr(pos+1);
+              data += "</user>";
+          }
+          
+          str += "<helo>" + data + "</helo>";
           break;
     };
     
-    str += "</command>";
+    str += "</command>\n";
 
     return str;
 }
 
 std::string &
-parseCommand(XML &xml, std::string &str)
+Commands::execCommand(XML &xml, std::string &str)
 {
     DEBUGLOG_REPORT_FUNCTION;
 
+    std::string cmd = xml.nameGet();
+    
+    dbglogfile << "Executing remote command " << cmd << std::endl;
+
     return str;
 }
 
diff --git a/lib/commands.h b/lib/commands.h
index a72a86c..a7fe69f 100644
--- a/lib/commands.h
+++ b/lib/commands.h
@@ -32,14 +32,19 @@
 
 class Commands 
 {
- public:
-  typedef enum { NOP, LIST, POLL } cmd_t; 
-  Commands();
-  ~Commands();
-
-  std::string &createCommand(cmd_t cmd, const std::string &args,
-                                   std::string &str);
-  std::string &execCommand(XML &xml, std::string &str);
+public:
+    typedef enum { NOP, LIST, POLL, HELO } cmd_t; 
+    Commands();
+    ~Commands();
+    std::string &createCommand(cmd_t cmd, const std::string &args,
+                               std::string &str);
+    std::string &execCommand(XML &xml, std::string &str);
+    cmd_t &convertAction(const std::string &cmd) {
+        return _commands[cmd];
+    };
+    
+protected:
+    std::map<const std::string, cmd_t> _commands;
 };
 
 #endif // __COMMANDS_H__
diff --git a/testsuite/libtests/cmd-test.cc b/testsuite/libtests/cmd-test.cc
index 352173a..9b44b30 100644
--- a/testsuite/libtests/cmd-test.cc
+++ b/testsuite/libtests/cmd-test.cc
@@ -42,9 +42,38 @@ public:
         DEBUGLOG_REPORT_FUNCTION;
 
         // Test creating commands
+
+        if (convertAction("nop") == Commands::NOP) {
+            runtest.pass("convertAction(nop)");
+        } else {
+            runtest.fail("convertAction(nop)");
+        }
+        if (convertAction("list") == Commands::LIST) {
+            runtest.pass("convertAction(list)");
+        } else {
+            runtest.fail("convertAction(list)");
+        }
+        if (convertAction("poll") == Commands::POLL) {
+            runtest.pass("convertAction(poll)");
+        } else {
+            runtest.fail("convertAction(poll)");
+        }
+        if (convertAction("helo") == Commands::HELO) {
+            runtest.pass("convertAction(helo)");
+        } else {
+            runtest.fail("convertAction(helo)");
+        }
+        
         std::string str;
+        createCommand(Commands::HELO, "localhost enduser", str);
+        if (str == 
"<command><helo><hostname>localhost</hostname><user>enduser</user></helo></command>\n")
 {
+            runtest.pass("create HELO command");
+        } else {
+            runtest.fail("create HELO command");
+        }
+        str.erase();
         createCommand(Commands::NOP, "", str);
-        if (str == "<command></command>") {
+        if (str == "<command><nop></nop></command>\n") {
             runtest.pass("create NOP command");
         } else {
             runtest.fail("create NOP command");
@@ -52,14 +81,14 @@ public:
         str.erase();
         //
         createCommand(Commands::LIST, "foo", str);
-        if (str == "<command><list>foo</list></command>") {
+        if (str == "<command><list>foo</list></command>\n") {
             runtest.pass("create LIST command");
         } else {
             runtest.fail("create LIST command");
         }
         str.erase();
         createCommand(Commands::POLL, "bar", str);
-        if (str == "<command><poll>bar</poll></command>") {
+        if (str == "<command><poll>bar</poll></command>\n") {
             runtest.pass("create POLL command");
         } else {
             runtest.fail("create POLL command");
@@ -68,7 +97,7 @@ public:
 
         // Test oarsing XML commands
         XML xml;
-        std::string testnop = "<command></command>";
+        std::string testnop = "<command></command>\n";
         if (!xml.parseMem(testnop)) {
             runtest.untested("XML::parseMem(nop command) failed!");
         }
@@ -84,7 +113,7 @@ public:
         }
         str.erase();
 
-        std::string testlist = "<command><list>foo</list></command>"; 
+        std::string testlist = "<command><list>foo</list></command>\n";
         if (!xml.parseMem(testlist)) {
             runtest.untested("XML::parseMem(list command) failed!");
         }
@@ -110,7 +139,7 @@ public:
         
         //execCommand(xml, str);        
         
-        std::string testpoll = "<command><poll>bar</poll></command>";
+        std::string testpoll = "<command><poll>bar</poll></command>\n";
         if (!xml.parseMem(testpoll)) {
             runtest.untested("XML::parseMem(poll command) failed!");
         }
@@ -133,8 +162,28 @@ public:
         } else {
             runtest.fail("POLL command has correct child");
         }
+
+        std::string testhelo = 
"<command><helo><hostname>localhost</hostname><user>enduser</user></helo></command>\n";
+        if (!xml.parseMem(testhelo)) {
+            runtest.untested("XML::parseMem(helo command) failed!");
+        }
+        node = xml[0];
+        if (node->nameGet() == "helo") {
+            runtest.pass("parse helo command");
+        } else {
+            runtest.fail("parse helo command");
+        }
+        str.erase();
+        // This top level node has two children
+        if (node->childGet(0)->nameGet() == "hostname" && 
node->childGet(1)->nameGet() == "user") {
+            runtest.pass("POLL command has children");
+        } else {
+            runtest.fail("POLL command has children");
+        }
+        
+        
     };
-    
+
     ~Test() {};
 };
 

-----------------------------------------------------------------------

Summary of changes:
 lib/commands.cc                | 40 +++++++++++++++++++++++----
 lib/commands.h                 | 21 ++++++++------
 testsuite/libtests/cmd-test.cc | 63 +++++++++++++++++++++++++++++++++++++-----
 3 files changed, 104 insertions(+), 20 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]