|
@@ -69,14 +69,24 @@ JsonCommander::Response JsonCommander::executeList(const Json::Value &message) {
|
|
|
response.action = send;
|
|
|
response.json["command"] = "list";
|
|
|
|
|
|
- if(fileManager.getRemainingListChunks()!=0) {
|
|
|
+ // 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";
|
|
|
- } else if (fileManager.openList() == -1){
|
|
|
+ // 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;
|
|
|
- response.json["error"] = "there is a filename which is to long";
|
|
|
+ response.json["chunks"] = -1;
|
|
|
+ response.json["items"] = -1;
|
|
|
+ response.json["error"] = "there is a filename which is too long";
|
|
|
} else {
|
|
|
- response.json["chunks"] = fileManager.getRemainingListChunks();
|
|
|
+ response.json["accept"] = true;
|
|
|
+ response.json["chunks"] = chunks;
|
|
|
response.json["items"] = fileManager.getListSize();
|
|
|
response.json["error"] = "";
|
|
|
}
|
|
@@ -84,23 +94,34 @@ JsonCommander::Response JsonCommander::executeList(const Json::Value &message) {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
-JsonCommander::Response JsonCommander::executeListData(const Json::Value &message) {
|
|
|
+JsonCommander::Response
|
|
|
+JsonCommander::executeListData(const Json::Value &message) {
|
|
|
JsonCommander::Response response;
|
|
|
response.action = send;
|
|
|
response.json["command"] = "listdata";
|
|
|
Json::Value array;
|
|
|
|
|
|
- if(fileManager.getRemainingListChunks()==0) {
|
|
|
- response.json["accept"] = false;
|
|
|
+ // TODO test validity of message request
|
|
|
+
|
|
|
+ // TODO execute request and add the ability to CANCEL the download
|
|
|
+
|
|
|
+ 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(fileManager.getRemainingListChunks()-1!=message["chunk"].asInt()) {
|
|
|
- response.json["accept"] = false;
|
|
|
+ } 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++)
|
|
|
+ for (int i = 0; i < v.size(); i++)
|
|
|
array.append(v.at(i));
|
|
|
- response.json["remaining"] = fileManager.getRemainingListChunks();
|
|
|
+ response.json["remaining"] = message["chunk"].asInt();
|
|
|
response.json["cancel"] = false;
|
|
|
response.json["names"] = array;
|
|
|
response.json["error"] = "";
|