|
@@ -150,7 +150,7 @@ CmdMan::CmdRet CmdMan::cmdGetdata(vector<string> args) {
|
|
|
|
|
|
root["command"] = "getdata";
|
|
|
root["file"] = fileman.getGetName();
|
|
|
- root["chunk"] = fileman.getGetReceivedChunks();
|
|
|
+ root["chunk"] = fileman.getGetRemainingChunks();
|
|
|
root["cancel"] = false;
|
|
|
retval.type = send;
|
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
@@ -259,7 +259,6 @@ CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
- retval.type = send;
|
|
|
if(!root["accept"].asBool()) {
|
|
|
retval.type = error;
|
|
|
retval.msg = "File upload request failed: Server reports: " + root["error"].asString();
|
|
@@ -278,7 +277,7 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
|
|
|
- if(root["received"].asUInt() != fileman.getPutChunksRemaining()) {
|
|
|
+ if(root["received"].asInt() != fileman.getPutChunksRemaining()) {
|
|
|
// 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());
|
|
@@ -290,7 +289,7 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
retval.msg = "File upload request failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getPutName();
|
|
|
} else {
|
|
|
// sent successfully
|
|
|
- if(!root["received"].asUInt()) {
|
|
|
+ if(root["received"].asInt() < 0) {
|
|
|
// everything sent
|
|
|
retval.type = notsend;
|
|
|
retval.msg = "succesfully uploaded file " + fileman.getPutName();
|
|
@@ -303,28 +302,47 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
+CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
+ CmdRet retval;
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
+
|
|
|
+ if(!root["accept"].asBool()) {
|
|
|
+ retval.type = error;
|
|
|
+ retval.msg = "File download request failed: Server reports: " + root["error"].asString();
|
|
|
+ } else if(root["file"].asString() != fileman.getGetName()) {
|
|
|
+ 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());
|
|
|
+ retval.type = send;
|
|
|
+ retval.msg = "getdata";
|
|
|
+ }
|
|
|
+
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
CmdMan::CmdRet CmdMan::handleGetdata(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["received"].asUInt() != fileman.getGetReceivedChunks()) {
|
|
|
+ if(root["remaining"].asInt() != fileman.getGetRemainingChunks()) {
|
|
|
retval.type = error;
|
|
|
- retval.msg = std::string("File upload failed: Server reports number of sent chunks as ") + std::to_string(root["received"].asInt()) + " but actual number is " + std::to_string(fileman.getGetReceivedChunks());
|
|
|
+ retval.msg = std::string("File download failed: Server reports number of remaining chunks as ") + std::to_string(root["remaining"].asInt()) + " but actual number is " + std::to_string(fileman.getGetRemainingChunks());
|
|
|
} else if(root["cancel"].asBool()) {
|
|
|
retval.type = error;
|
|
|
retval.msg = "File download cancelled: Server reports: " + root["error"].asString();
|
|
|
- } else if(root["file"].asString() != fileman.getPutName()) {
|
|
|
+ } else if(root["file"].asString() != fileman.getGetName()) {
|
|
|
retval.type = error;
|
|
|
- retval.msg = "File upload request failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getPutName();
|
|
|
+ retval.msg = "File download failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getGetName();
|
|
|
} else {
|
|
|
fileman.writeBase64(root["data"].asString());
|
|
|
// loaded successfully
|
|
|
- if(fileman.getGetChunks() == fileman.getGetReceivedChunks()) {
|
|
|
+ if(fileman.getGetRemainingChunks() < 0) {
|
|
|
// everything sent
|
|
|
retval.type = notsend;
|
|
|
retval.msg = "succesfully downloaded file " + fileman.getGetName();
|
|
|
- fileman.closePut();
|
|
|
+ fileman.closeGet();
|
|
|
} else {
|
|
|
retval.type = send;
|
|
|
retval.msg = "getdata";
|
|
@@ -333,16 +351,6 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
- CmdRet retval;
|
|
|
- std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
- // TODO
|
|
|
- retval.type = error;
|
|
|
- retval.msg = "Get handler not implemented yet";
|
|
|
-
|
|
|
- return retval;
|
|
|
-}
|
|
|
-
|
|
|
CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|