|
@@ -69,15 +69,12 @@ JsonCommander::Response JsonCommander::executeList(const Json::Value &message) {
|
|
|
response.action = send;
|
|
|
response.json["command"] = "list";
|
|
|
|
|
|
- // TODO test validity of message request
|
|
|
-
|
|
|
int chunks;
|
|
|
if (fileManager.getRemainingListChunks() > 0) {
|
|
|
response.json["accept"] = false;
|
|
|
response.json["chunks"] = -1;
|
|
|
response.json["items"] = -1;
|
|
|
response.json["error"] = "there is already an open list command";
|
|
|
- // TODO cancel last list command???
|
|
|
} else if ((chunks = fileManager.openList()) ==
|
|
|
-1) { // TODO do we need to check? maybe. Think about it
|
|
|
response.json["accept"] = false;
|
|
@@ -101,22 +98,28 @@ JsonCommander::executeListData(const Json::Value &message) {
|
|
|
response.json["command"] = "listdata";
|
|
|
Json::Value array;
|
|
|
|
|
|
- // TODO test validity of message request
|
|
|
-
|
|
|
- // TODO execute request and add the ability to CANCEL the download
|
|
|
-
|
|
|
- if (fileManager.getRemainingListChunks() == 0) {
|
|
|
+ if (!message["chunk"].isInt() || !message["cancel"].isBool()) {
|
|
|
+ response.json["cancel"] = true;
|
|
|
+ response.json["remaining"] = -1;
|
|
|
+ response.json["names"] = Json::arrayValue;
|
|
|
+ response.json["error"] = "incorrect listdata command request";
|
|
|
+ } else if (fileManager.getRemainingListChunks() == 0) {
|
|
|
response.json["cancel"] = true;
|
|
|
response.json["remaining"] = -1;
|
|
|
response.json["names"] = Json::arrayValue;
|
|
|
response.json["error"] = "there are no chunks to send";
|
|
|
+ } else if (message["cancel"].asBool()) {
|
|
|
+ response.json["cancel"] = true;
|
|
|
+ response.json["remaining"] = 0;
|
|
|
+ response.json["names"] = Json::arrayValue;
|
|
|
+ response.json["error"] = "";
|
|
|
+ fileManager.cancelList();
|
|
|
} else if (fileManager.getRemainingListChunks() - 1 !=
|
|
|
message["chunk"].asInt()) {
|
|
|
response.json["cancel"] = true;
|
|
|
response.json["remaining"] = -1;
|
|
|
response.json["names"] = Json::arrayValue;
|
|
|
response.json["error"] = "wrong chunk number";
|
|
|
- // TODO discard file list and cancel list download
|
|
|
} else {
|
|
|
std::vector<std::string> v = fileManager.getNextChunkFromList();
|
|
|
for (int i = 0; i < v.size(); i++)
|