|
@@ -116,7 +116,7 @@ CmdMan::CmdRet CmdMan::cmdPutdata(vector<string> args) {
|
|
|
root["file"] = fileman.getPutName();
|
|
|
root["cancel"] = false;
|
|
|
root["data"] = fileman.readBase64();
|
|
|
- root["remaining"] = fileman.getPutChunksRemaining(); // number already decremented by readBase64
|
|
|
+ root["remaining"] = fileman.getPutRemainingChunks(); // number already decremented by readBase64
|
|
|
retval.type = send;
|
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
|
|
|
@@ -169,6 +169,18 @@ CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
+CmdMan::CmdRet CmdMan::cmdListdata(vector<string> args) {
|
|
|
+ CmdRet retval;
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
+ Json::Value root;
|
|
|
+ root["command"] = "listdata";
|
|
|
+ root["chunk"] = fileman.getListRemainingChunks();
|
|
|
+ root["cancel"] = false;
|
|
|
+ retval.type = send;
|
|
|
+ retval.msg = Json::writeString(wbuilder, root);
|
|
|
+
|
|
|
+ return retval;
|
|
|
+}
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
@@ -178,7 +190,7 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
|
map<string,CmdRet(CmdMan::*)(vector<string>)>::iterator it = execmap.find(cmd);
|
|
|
string retmsg;
|
|
|
if(it == execmap.end()) {
|
|
|
- return { error, "unknown command \"" + cmd + "\".\ntype help to list available commands." };
|
|
|
+ return { error, string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd + "\".\ntype help to list available commands." };
|
|
|
}
|
|
|
return (this->*(execmap[cmd]))(args);
|
|
|
}
|
|
@@ -231,7 +243,7 @@ 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, "unknown command \"" + root["command"].asString() + "\".\nensure code is implemented." };
|
|
|
+ return { error, string(__PRETTY_FUNCTION__) + " unknown command \"" + root["command"].asString() + "\".\nensure code is implemented." };
|
|
|
}
|
|
|
return (this->*(handlemap[root["command"].asString()]))(root);
|
|
|
}
|
|
@@ -277,10 +289,10 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
- if(root["received"].asInt() != fileman.getPutChunksRemaining()) {
|
|
|
+ if(root["received"].asInt() != fileman.getPutRemainingChunks()) {
|
|
|
// the number of remaining chunks received from the daemon does not equal the number stored at the client side
|
|
|
retval.type = error;
|
|
|
- retval.msg = std::string("File upload failed: Server reports number of remaining chunks as ") + std::to_string(root["received"].asInt()) + " but actual number is " + std::to_string(fileman.getPutChunksRemaining());
|
|
|
+ retval.msg = std::string("File upload failed: Server reports number of remaining chunks as ") + std::to_string(root["received"].asInt()) + " but actual number is " + std::to_string(fileman.getPutRemainingChunks());
|
|
|
fileman.cancelPut();
|
|
|
} else if(root["cancel"].asBool()) {
|
|
|
retval.type = error;
|
|
@@ -316,7 +328,7 @@ CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
retval.type = error;
|
|
|
retval.msg = "File download request failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getGetName();
|
|
|
} else {
|
|
|
- fileman.setGetChunks(root["chunks"].asUInt());
|
|
|
+ fileman.setGetChunks(root["chunks"].asInt());
|
|
|
retval.type = send;
|
|
|
retval.msg = "getdata";
|
|
|
}
|
|
@@ -361,9 +373,45 @@ CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
- retval.type = send;
|
|
|
- retval.msg = Json::writeString(wbuilder, root);
|
|
|
+ if(!root["accept"].asBool()) {
|
|
|
+ retval.type = error;
|
|
|
+ retval.msg = "File listing request failed: Server reports: " + root["error"].asString();
|
|
|
+ } else {
|
|
|
+ fileman.setListChunks(root["chunks"].asInt());
|
|
|
+ retval.type = send;
|
|
|
+ retval.msg = "listdata";
|
|
|
+ }
|
|
|
+
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+CmdMan::CmdRet CmdMan::handleListdata(Json::Value root) {
|
|
|
+ CmdRet retval;
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
+ // the passed number of recieved chunks should equal the number of sent chunks
|
|
|
+ if(root["remaining"].asInt() != fileman.getListRemainingChunks()) {
|
|
|
+ retval.type = error;
|
|
|
+ retval.msg = std::string("File listing failed: Server reports number of remaining chunks as ") + std::to_string(root["remaining"].asInt()) + " but actual number is " + std::to_string(fileman.getListRemainingChunks());
|
|
|
+ fileman.cancelList();
|
|
|
+ } else if(root["cancel"].asBool()) {
|
|
|
+ retval.type = error;
|
|
|
+ retval.msg = "File listing cancelled: Server reports: " + root["error"].asString();
|
|
|
+ fileman.cancelList();
|
|
|
+ } else {
|
|
|
+ for(Json::Value i : root["names"]) fileman.putListData(i.asString());
|
|
|
+ // loaded successfully
|
|
|
+ if(!fileman.getListRemainingChunks()) {
|
|
|
+ // everything sent
|
|
|
+ retval.type = notsend;
|
|
|
+ retval.msg = "Files on server:\n";
|
|
|
+ for(string s : fileman.getListData()) retval.msg += s + "\n";
|
|
|
+ fileman.closeList();
|
|
|
+ } else {
|
|
|
+ retval.type = send;
|
|
|
+ retval.msg = "listdata";
|
|
|
+ }
|
|
|
+ }
|
|
|
return retval;
|
|
|
}
|
|
|
|