|
@@ -23,7 +23,7 @@ CmdMan::CmdMan(FileMan &fm) : fileman(fm) {
|
|
|
execmap["version"] = &CmdMan::cmdVersion;
|
|
|
execmap["login"] = &CmdMan::cmdLogin;
|
|
|
execmap["putdata"] = &CmdMan::cmdPutdata;
|
|
|
-// execmap["getdata"] = &CmdMan::cmdGetdata;
|
|
|
+ execmap["getdata"] = &CmdMan::cmdGetdata;
|
|
|
|
|
|
/* initialize description map */
|
|
|
helpmap["help"] = descHelp;
|
|
@@ -39,7 +39,7 @@ CmdMan::CmdMan(FileMan &fm) : fileman(fm) {
|
|
|
handlemap["put"] = &CmdMan::handlePut;
|
|
|
handlemap["get"] = &CmdMan::handleGet;
|
|
|
handlemap["putdata"] = &CmdMan::handlePutdata;
|
|
|
-// handlemap["getdata"] = &CmdMan::handleGetdata;
|
|
|
+ handlemap["getdata"] = &CmdMan::handleGetdata;
|
|
|
handlemap["list"] = &CmdMan::handleList;
|
|
|
handlemap["version"] = &CmdMan::handleVersion;
|
|
|
handlemap["login"] = &CmdMan::handleLogin;
|
|
@@ -94,7 +94,8 @@ CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
|
|
|
if(opened) {
|
|
|
root["command"] = "put";
|
|
|
root["file"] = fileman.getPutName();
|
|
|
- root["size"] = fileman.getPutChunks();
|
|
|
+ root["size"] = fileman.getPutSize();
|
|
|
+ root["chunks"] = fileman.getPutChunks();
|
|
|
retval.type = send;
|
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
|
}
|
|
@@ -115,6 +116,7 @@ CmdMan::CmdRet CmdMan::cmdPutdata(vector<string> args) {
|
|
|
root["file"] = fileman.getPutName();
|
|
|
root["remaining"] = fileman.getPutChunksRemaining();
|
|
|
root["cancel"] = false;
|
|
|
+ root["data"] = fileman.readBase64();
|
|
|
retval.type = send;
|
|
|
retval.msg = Json::writeString(wbuilder, root);
|
|
|
|
|
@@ -141,6 +143,21 @@ CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
+CmdMan::CmdRet CmdMan::cmdGetdata(vector<string> args) {
|
|
|
+ CmdRet retval;
|
|
|
+ std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
+ Json::Value root;
|
|
|
+
|
|
|
+ root["command"] = "getdata";
|
|
|
+ root["file"] = fileman.getGetName();
|
|
|
+ root["chunk"] = fileman.getGetReceivedChunks();
|
|
|
+ root["cancel"] = false;
|
|
|
+ retval.type = send;
|
|
|
+ retval.msg = Json::writeString(wbuilder, root);
|
|
|
+
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
@@ -260,22 +277,21 @@ CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
|
CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|
|
|
- // TODO
|
|
|
|
|
|
// the passed number of recieved chunks should equal the number of sent chunks
|
|
|
- unsigned int sentChunks = fileman.getPutChunks() - fileman.getPutChunksRemaining();
|
|
|
- if(root["received"].asInt() != sentChunks) {
|
|
|
+ unsigned int sentChunks = fileman.getPutChunksRemaining()+1;
|
|
|
+ if(root["received"].asUInt() != sentChunks) {
|
|
|
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 (sentChunks);
|
|
|
- } else if(!root["accept"].asBool()) {
|
|
|
+ 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(sentChunks);
|
|
|
+ } else if(root["cancel"].asBool()) {
|
|
|
retval.type = error;
|
|
|
- retval.msg = "File upload failed: Server reports: " + root["error"].asString();
|
|
|
+ retval.msg = "File upload cancelles: Server reports: " + root["error"].asString();
|
|
|
} else if(root["file"].asString() != fileman.getPutName()) {
|
|
|
retval.type = error;
|
|
|
retval.msg = "File upload request failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getPutName();
|
|
|
} else {
|
|
|
// sent successfully
|
|
|
- if(root["received"].asInt() == fileman.getPutChunks()) {
|
|
|
+ if(!root["received"].asUInt()) {
|
|
|
// everything sent
|
|
|
retval.type = notsend;
|
|
|
retval.msg = "succesfully uploaded file " + fileman.getPutName();
|
|
@@ -288,6 +304,36 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
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()) {
|
|
|
+ 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());
|
|
|
+ } 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()) {
|
|
|
+ retval.type = error;
|
|
|
+ retval.msg = "File upload request failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getPutName();
|
|
|
+ } else {
|
|
|
+ fileman.writeBase64(root["data"].asString());
|
|
|
+ // loaded successfully
|
|
|
+ if(fileman.getGetChunks() == fileman.getGetReceivedChunks()) {
|
|
|
+ // everything sent
|
|
|
+ retval.type = notsend;
|
|
|
+ retval.msg = "succesfully downloaded file " + fileman.getGetName();
|
|
|
+ fileman.closePut();
|
|
|
+ } else {
|
|
|
+ retval.type = send;
|
|
|
+ retval.msg = "getdata";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
std::cerr << __PRETTY_FUNCTION__ << " begin" << std::endl;
|