|
@@ -1,6 +1,8 @@
|
|
#include "../include/global.h"
|
|
#include "../include/global.h"
|
|
#include "../include/cmdman.h"
|
|
#include "../include/cmdman.h"
|
|
|
|
|
|
|
|
+#include <iostream>
|
|
|
|
+
|
|
CmdMan::CmdMan(FileMan &fm) : fileman(fileman) {
|
|
CmdMan::CmdMan(FileMan &fm) : fileman(fileman) {
|
|
|
|
|
|
/* setup json stuff */
|
|
/* setup json stuff */
|
|
@@ -8,6 +10,9 @@ CmdMan::CmdMan(FileMan &fm) : fileman(fileman) {
|
|
wbuilder.settings_["indentation"] = "";
|
|
wbuilder.settings_["indentation"] = "";
|
|
reader = rbuilder.newCharReader();
|
|
reader = rbuilder.newCharReader();
|
|
|
|
|
|
|
|
+ dologin = false;
|
|
|
|
+ doversion = false;
|
|
|
|
+
|
|
/* initialize execute command map */
|
|
/* initialize execute command map */
|
|
execmap["help"] = &CmdMan::cmdHelp;
|
|
execmap["help"] = &CmdMan::cmdHelp;
|
|
execmap["status"] = &CmdMan::cmdStatus;
|
|
execmap["status"] = &CmdMan::cmdStatus;
|
|
@@ -42,6 +47,7 @@ CmdMan::~CmdMan() {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdHelp(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdHelp(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
map<string,string>::iterator it;
|
|
map<string,string>::iterator it;
|
|
for(it = helpmap.begin(); it != helpmap.end(); it++) {
|
|
for(it = helpmap.begin(); it != helpmap.end(); it++) {
|
|
retval.msg.append(it->first);
|
|
retval.msg.append(it->first);
|
|
@@ -55,6 +61,7 @@ CmdMan::CmdRet CmdMan::cmdHelp(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
root["command"] = "status";
|
|
root["command"] = "status";
|
|
retval.type = send;
|
|
retval.type = send;
|
|
@@ -65,6 +72,7 @@ CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
root["command"] = "close";
|
|
root["command"] = "close";
|
|
retval.type = send;
|
|
retval.type = send;
|
|
@@ -75,6 +83,7 @@ CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
|
|
|
|
bool opened = fileman.openPut(args[0]);
|
|
bool opened = fileman.openPut(args[0]);
|
|
@@ -95,6 +104,7 @@ CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
|
|
|
|
bool opened = fileman.openGet(args[0]);
|
|
bool opened = fileman.openGet(args[0]);
|
|
@@ -114,6 +124,7 @@ CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
root["command"] = "list";
|
|
root["command"] = "list";
|
|
retval.type = send;
|
|
retval.type = send;
|
|
@@ -124,6 +135,10 @@ CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
|
|
|
|
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " using command \"" << cmd << "\" with arguments [ ";
|
|
|
|
+ for(string s : args) std::cerr << s << " ";
|
|
|
|
+ std::cerr << "]" << std::endl;
|
|
map<string,CmdRet(CmdMan::*)(vector<string>)>::iterator it = execmap.find(cmd);
|
|
map<string,CmdRet(CmdMan::*)(vector<string>)>::iterator it = execmap.find(cmd);
|
|
string retmsg;
|
|
string retmsg;
|
|
if(it == execmap.end()) {
|
|
if(it == execmap.end()) {
|
|
@@ -135,16 +150,20 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
/* internal commands */
|
|
/* internal commands */
|
|
CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
root["version"] = protocolVersion;
|
|
root["version"] = protocolVersion;
|
|
retval.type = send;
|
|
retval.type = send;
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
|
|
|
|
|
|
+ doversion = true;
|
|
|
|
+
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
root["user"] = args[0];
|
|
root["user"] = args[0];
|
|
root["pass"] = args[1];
|
|
root["pass"] = args[1];
|
|
@@ -153,6 +172,8 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
retval.type = send;
|
|
retval.type = send;
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
|
|
|
|
|
|
+ dologin = true;
|
|
|
|
+
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -167,8 +188,12 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
*/
|
|
*/
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
- map<string,CmdRet(CmdMan::*)(Json::Value)>::iterator it = handlemap.find(root["command"].asString());
|
|
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
+ if(doversion) root["command"] = "version";
|
|
|
|
+ else if (dologin) root["command"] = "login";
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " using json" << std::endl << root << std::endl;
|
|
string retmsg;
|
|
string retmsg;
|
|
|
|
+ map<string,CmdRet(CmdMan::*)(Json::Value)>::iterator it = handlemap.find(root["command"].asString());
|
|
if(it == handlemap.end()) {
|
|
if(it == handlemap.end()) {
|
|
return { error, "unknown command \"" + root["command"].asString() + "\".\nensure code is implemented." };
|
|
return { error, "unknown command \"" + root["command"].asString() + "\".\nensure code is implemented." };
|
|
}
|
|
}
|
|
@@ -177,6 +202,7 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
retval.type = notsend;
|
|
retval.type = notsend;
|
|
retval.msg = root["response"].asString();
|
|
retval.msg = root["response"].asString();
|
|
|
|
|
|
@@ -185,6 +211,7 @@ CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleClose(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handleClose(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
retval.type = close;
|
|
retval.type = close;
|
|
retval.msg = root["response"].asString();
|
|
retval.msg = root["response"].asString();
|
|
|
|
|
|
@@ -194,6 +221,7 @@ CmdMan::CmdRet CmdMan::handleClose(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
retval.type = send;
|
|
retval.type = send;
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
@@ -203,6 +231,7 @@ CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
retval.type = send;
|
|
retval.type = send;
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
@@ -212,6 +241,7 @@ CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
retval.type = send;
|
|
retval.type = send;
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
@@ -221,6 +251,7 @@ CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
if(!root["accept"].asBool()) {
|
|
if(!root["accept"].asBool()) {
|
|
retval.type = error;
|
|
retval.type = error;
|
|
@@ -229,6 +260,7 @@ CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
|
|
else {
|
|
else {
|
|
retval.type = seton;
|
|
retval.type = seton;
|
|
retval.msg = "Version check ok.";
|
|
retval.msg = "Version check ok.";
|
|
|
|
+ doversion = false;
|
|
}
|
|
}
|
|
|
|
|
|
return retval;
|
|
return retval;
|
|
@@ -236,6 +268,7 @@ CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
|
|
CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
if(!root["accept"].asBool()) {
|
|
if(!root["accept"].asBool()) {
|
|
retval.type = error;
|
|
retval.type = error;
|
|
@@ -244,6 +277,7 @@ CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
|
|
else {
|
|
else {
|
|
retval.type = seton;
|
|
retval.type = seton;
|
|
retval.msg = "Login ok.";
|
|
retval.msg = "Login ok.";
|
|
|
|
+ dologin = false;
|
|
}
|
|
}
|
|
|
|
|
|
return retval;
|
|
return retval;
|