|
@@ -15,6 +15,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
|
|
reader = rbuilder.newCharReader();
|
|
reader = rbuilder.newCharReader();
|
|
|
|
|
|
dologin = false;
|
|
dologin = false;
|
|
|
|
+ dosignup = false;
|
|
doversion = false;
|
|
doversion = false;
|
|
|
|
|
|
/* initialize execute command map */
|
|
/* initialize execute command map */
|
|
@@ -26,6 +27,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
|
|
execmap["list"] = &CmdMan::cmdList;
|
|
execmap["list"] = &CmdMan::cmdList;
|
|
execmap["version"] = &CmdMan::cmdVersion;
|
|
execmap["version"] = &CmdMan::cmdVersion;
|
|
execmap["login"] = &CmdMan::cmdLogin;
|
|
execmap["login"] = &CmdMan::cmdLogin;
|
|
|
|
+ execmap["signup"] = &CmdMan::cmdSignup;
|
|
execmap["putdata"] = &CmdMan::cmdPutdata;
|
|
execmap["putdata"] = &CmdMan::cmdPutdata;
|
|
execmap["getdata"] = &CmdMan::cmdGetdata;
|
|
execmap["getdata"] = &CmdMan::cmdGetdata;
|
|
|
|
|
|
@@ -47,6 +49,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
|
|
handlemap["list"] = &CmdMan::handleList;
|
|
handlemap["list"] = &CmdMan::handleList;
|
|
handlemap["version"] = &CmdMan::handleVersion;
|
|
handlemap["version"] = &CmdMan::handleVersion;
|
|
handlemap["login"] = &CmdMan::handleLogin;
|
|
handlemap["login"] = &CmdMan::handleLogin;
|
|
|
|
+ handlemap["signup"] = &CmdMan::handleSignup;
|
|
|
|
|
|
debugprintfunc = dpf;
|
|
debugprintfunc = dpf;
|
|
}
|
|
}
|
|
@@ -241,32 +244,52 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
return (this->*(execmap[cmd]))(args);
|
|
return (this->*(execmap[cmd]))(args);
|
|
}
|
|
}
|
|
|
|
|
|
-/* internal commands */
|
|
|
|
-CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
|
|
|
|
|
|
+/* login and signup commands */
|
|
|
|
+CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
Json::Value root;
|
|
Json::Value root;
|
|
- root["version"] = protocolVersion;
|
|
|
|
|
|
+ root["user"] = args[0];
|
|
|
|
+ root["pass"] = args[1];
|
|
|
|
+ root["login"] = true;
|
|
|
|
+ root["cancel"] = false;
|
|
retval.type = send;
|
|
retval.type = send;
|
|
retval.msg = root;
|
|
retval.msg = root;
|
|
|
|
|
|
- doversion = true;
|
|
|
|
|
|
+ // dologin already set by handleVersion, so no need here
|
|
|
|
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
|
|
-CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
|
|
|
|
+CmdMan::CmdRet CmdMan::cmdSignup(vector<string> args) {
|
|
CmdRet retval;
|
|
CmdRet retval;
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
Json::Value root;
|
|
Json::Value root;
|
|
root["user"] = args[0];
|
|
root["user"] = args[0];
|
|
root["pass"] = args[1];
|
|
root["pass"] = args[1];
|
|
- root["login"] = true;
|
|
|
|
|
|
+ root["login"] = false;
|
|
root["cancel"] = false;
|
|
root["cancel"] = false;
|
|
retval.type = send;
|
|
retval.type = send;
|
|
retval.msg = root;
|
|
retval.msg = root;
|
|
|
|
|
|
- dologin = true;
|
|
|
|
|
|
+ // set dosignin to differentiate from only logging in
|
|
|
|
+ // note: dologin was also set (by handleVersion)
|
|
|
|
+ dosignup = true;
|
|
|
|
+
|
|
|
|
+ return retval;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/* internal commands */
|
|
|
|
+CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
|
|
|
|
+ CmdRet retval;
|
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
|
+ Json::Value root;
|
|
|
|
+ root["version"] = protocolVersion;
|
|
|
|
+ retval.type = send;
|
|
|
|
+ retval.msg = root;
|
|
|
|
+
|
|
|
|
+ doversion = true;
|
|
|
|
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
@@ -277,6 +300,8 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
if (doversion)
|
|
if (doversion)
|
|
root["command"] = "version";
|
|
root["command"] = "version";
|
|
|
|
+ else if (dosignup)
|
|
|
|
+ root["command"] = "signup";
|
|
else if (dologin)
|
|
else if (dologin)
|
|
root["command"] = "login";
|
|
root["command"] = "login";
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using json\n" +
|
|
DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using json\n" +
|
|
@@ -288,7 +313,7 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
if (it == handlemap.end()) {
|
|
if (it == handlemap.end()) {
|
|
retval.type = error;
|
|
retval.type = error;
|
|
output["command"] = "error";
|
|
output["command"] = "error";
|
|
- output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + root["command"].asString(); + "\".\nensure code is implemented.";
|
|
|
|
|
|
+ output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + root["command"].asString() + "\".\nEnsure code is implemented.";
|
|
retval.msg = output;
|
|
retval.msg = output;
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
@@ -572,3 +597,26 @@ CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
|
|
|
|
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+CmdMan::CmdRet CmdMan::handleSignup(Json::Value root) {
|
|
|
|
+ CmdRet retval;
|
|
|
|
+ Json::Value output; // LOCALOUTPUT
|
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
|
+
|
|
|
|
+ output["command"] = "signup";
|
|
|
|
+
|
|
|
|
+ if (!root["accept"].asBool()) {
|
|
|
|
+ retval.type = error;
|
|
|
|
+ output["error"] = root["error"].asString();
|
|
|
|
+ output["accept"] = false;
|
|
|
|
+ } else {
|
|
|
|
+ retval.type = print | seton;
|
|
|
|
+ output["error"] = "";
|
|
|
|
+ output["accept"] = true;
|
|
|
|
+ dologin = false;
|
|
|
|
+ dosignup = false;
|
|
|
|
+ }
|
|
|
|
+ retval.msg = output;
|
|
|
|
+
|
|
|
|
+ return retval;
|
|
|
|
+}
|