From: Pawel Kaczmarczyk Date: Fri, 9 Mar 2018 12:44:47 +0000 (+0100) Subject: Added HTTP method for command execution X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=772ea689fec5c79f0d7a11a1f9e23173458fbd3d;p=test%2Ftools%2Ftestkit-stub.git Added HTTP method for command execution Added possibility to execute shell commands to set preconditions and perform actions during testing Change-Id: I75499e8d7038836dba5c3c3c50a4a2280061c036 --- diff --git a/source/httpserver.cpp b/source/httpserver.cpp index 391f0be..234f6af 100644 --- a/source/httpserver.cpp +++ b/source/httpserver.cpp @@ -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 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\"}"; }