|
@@ -83,8 +83,18 @@ CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
- root["command"] = "close";
|
|
|
retval.type = send;
|
|
|
+ if(dologin) {
|
|
|
+ // not logged in, send appropriate login message instead of normal close
|
|
|
+ root["login"] = false;
|
|
|
+ root["user"] = "";
|
|
|
+ root["pass"] = "";
|
|
|
+ root["cancel"] = true;
|
|
|
+ retval.type |= close;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ root["command"] = "close";
|
|
|
+ }
|
|
|
retval.msg = root;
|
|
|
|
|
|
return retval;
|
|
@@ -204,13 +214,29 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
|
"\" with arguments [ ");
|
|
|
for (string s : args)
|
|
|
DEBUGPRINT(s + " ");
|
|
|
- DEBUGPRINT("]\n");
|
|
|
+ DEBUGPRINT("]");
|
|
|
map<string, CmdRet (CmdMan::*)(vector<string>)>::iterator it =
|
|
|
execmap.find(cmd);
|
|
|
- string retmsg;
|
|
|
+ CmdRet retval;
|
|
|
+ Json::Value root;
|
|
|
+ root["command"] = cmd;
|
|
|
if (it == execmap.end()) {
|
|
|
- return {error, string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd +
|
|
|
- "\".\ntype help to list available commands."};
|
|
|
+ retval.type = error;
|
|
|
+ root["command"] = "error";
|
|
|
+ root["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd + "\".\ntype help to list available commands.";
|
|
|
+ retval.msg = root;
|
|
|
+ return retval;
|
|
|
+ }
|
|
|
+ else if(dologin) {
|
|
|
+ DEBUGPRINT("execute does login");
|
|
|
+ DEBUGPRINT(string("comparison is ") + std::to_string(cmd.compare("login") && cmd.compare("signup") && cmd.compare("disconnect") && cmd.compare("help")));
|
|
|
+ if(cmd.compare("login") && cmd.compare("signup") && cmd.compare("disconnect") && cmd.compare("help")) {
|
|
|
+ retval.type = error;
|
|
|
+ root["command"] = "error";
|
|
|
+ root["error"] = string("Not logged in. Available commands are limited to ") + "login" + ", " + "signup" + " and " + "disconnect" + "\n" + "Use help for usage of these commands.";
|
|
|
+ retval.msg = root;
|
|
|
+ return retval;
|
|
|
+ }
|
|
|
}
|
|
|
return (this->*(execmap[cmd]))(args);
|
|
|
}
|
|
@@ -245,17 +271,9 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- handlemap["status"] = &CmdMan::handleDefault;
|
|
|
- handlemap["disconnect"] = &CmdMan::handleDefault;
|
|
|
- handlemap["put"] = &CmdMan::handleDefault;
|
|
|
- handlemap["get"] = &CmdMan::handleDefault;
|
|
|
- handlemap["list"] = NULL;
|
|
|
- handlemap["version"] = NULL;
|
|
|
- handlemap["login"] = NULL;
|
|
|
-*/
|
|
|
-
|
|
|
CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
|
+ CmdRet retval;
|
|
|
+ Json::Value output;
|
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
if (doversion)
|
|
|
root["command"] = "version";
|
|
@@ -266,10 +284,13 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
|
string retmsg;
|
|
|
map<string, CmdRet (CmdMan::*)(Json::Value)>::iterator it =
|
|
|
handlemap.find(root["command"].asString());
|
|
|
+
|
|
|
if (it == handlemap.end()) {
|
|
|
- return {error, string(__PRETTY_FUNCTION__) + " unknown command \"" +
|
|
|
- root["command"].asString() +
|
|
|
- "\".\nensure code is implemented."};
|
|
|
+ retval.type = error;
|
|
|
+ output["command"] = "error";
|
|
|
+ output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + root["command"].asString(); + "\".\nensure code is implemented.";
|
|
|
+ retval.msg = output;
|
|
|
+ return retval;
|
|
|
}
|
|
|
return (this->*(handlemap[root["command"].asString()]))(root);
|
|
|
}
|
|
@@ -523,6 +544,7 @@ CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
|
|
|
retval.type = print | seton;
|
|
|
output["accept"] = true;
|
|
|
doversion = false;
|
|
|
+ dologin = true;
|
|
|
}
|
|
|
retval.msg = output;
|
|
|
|