Added HTTP method for command execution 70/183170/1
authorPawel Kaczmarczyk <p.kaczmarczy@samsung.com>
Fri, 9 Mar 2018 12:44:47 +0000 (13:44 +0100)
committerPawel Kaczmarczyk <p.kaczmarczy@samsung.com>
Tue, 3 Jul 2018 06:38:22 +0000 (08:38 +0200)
Added possibility to execute shell commands
to set preconditions and perform actions
during testing

Change-Id: I75499e8d7038836dba5c3c3c50a4a2280061c036

source/httpserver.cpp

index 391f0be1c7db01f956a4400499618434fa7049df..234f6af28914fc9a59c28f9b50bfab9d0724fb67 100644 (file)
@@ -564,6 +564,18 @@ void HttpServer::processpost(int s, struct HttpRequest *prequest) {
             if (m_capability[name].asString() == value)
                 json_str = "{\"support\":1}";
         }
+       } else if (prequest->path.find("/execute_command") != string::npos) {
+                       Json::Value paras = splitContent(prequest->content);
+                       std::string cmd = paras["cmd"].asString();
+                       std::vector<std::string> output;
+                       run_cmd(cmd, "", &output);
+
+                       json_str = "{\"Input_value\" : \"" + cmd + "\"\n\"Output\" : [";
+                       for(auto line : output) {
+                               json_str += "\"" + line + "\", ";
+                       }
+                       json_str = json_str.substr(0, json_str.size() - 2);
+                       json_str += "]}";
        } else {
                json_str = "{\"Error\":\"unknown request\"}";
        }