Browse Source

US26.2: delete file (CLI)

Serdyukov, Denys 4 years ago
parent
commit
cabfe9036d
5 changed files with 77 additions and 7 deletions
  1. 22 4
      GUI-CLI Protocol.md
  2. 3 2
      cli/include/cmdman.h
  3. 1 0
      cli/include/userioman.h
  4. 42 0
      cli/src/cmdman.cpp
  5. 9 1
      cli/src/userioman.cpp

+ 22 - 4
GUI-CLI Protocol.md

@@ -99,9 +99,7 @@ CLI:
 #### 2.2.1 list - request file list download
 GUI:
 ```
-{
-	write: "list"
-}
+write: "list"
 ```
 CLI:
 ```
@@ -159,7 +157,7 @@ Get is split in two commands. `get` to request a file download and `getdata` to
 
 GUI:
 ```
-write: "get" file_name
+write: "get" file_path
 ```
 
 CLI:
@@ -190,6 +188,26 @@ If `cancel` is `true` then the download of the file is canceled and an error mes
 `speed` shall contain a float describing the download speed in kB/s.
 
 
+### 2.5 Deletefile command
+`deletefile` to request the deletion of a file on the server.
+
+#### 2.5.1  - request file list download
+GUI:
+```
+write: "deletefile" file_name
+```
+CLI:
+```
+{
+	"command": "deletefile",
+	"file": string,
+	"accept": bool,
+	"error": string
+}
+```
+
+
+
 ### TODO
 
 

+ 3 - 2
cli/include/cmdman.h

@@ -111,8 +111,8 @@ private:
 	CmdRet cmdList(vector<string> args);
 	const string descHead = "request the first four bytes of a file from the server";
 	CmdRet cmdHead(vector<string> args);
-	/* TODO cmdKeyfile */
-	/* TODO cmdClosekey */
+	const string descDeletefile = "delete a file from the server";
+	CmdRet cmdDeletefile(vector<string> args);
 	const string descKeyfile = "set keyfile to use";
 	CmdRet cmdKeyfile(vector<string> args);
 	const string descClosekey = "stop using the previously selected keyfile";
@@ -151,6 +151,7 @@ private:
 	CmdRet handleLogin(Json::Value);
 	CmdRet handleSignup(Json::Value);
 	CmdRet handleHead(Json::Value);
+	CmdRet handleDeletefile(Json::Value);
 	CmdRet handleDeleteme(Json::Value);
 };
 

+ 1 - 0
cli/include/userioman.h

@@ -48,6 +48,7 @@ private:
 	void printGetdata(Json::Value root);
 	void printListdata(Json::Value root);
 	void printHead(Json::Value root);
+	void printDeletefile(Json::Value root);
 	void printDeleteme(Json::Value root);
 	void printKeyfile(Json::Value root);
 	void printClosekey(Json::Value root);

+ 42 - 0
cli/src/cmdman.cpp

@@ -33,6 +33,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
 	execmap["getdata"] = &CmdMan::cmdGetdata;
 	execmap["listdata"] = &CmdMan::cmdListdata;
 	execmap["head"] = &CmdMan::cmdHead;
+	execmap["deletefile"] = &CmdMan::cmdDeletefile;
 	execmap["deleteme"] = &CmdMan::cmdDeleteme;
 	execmap["keyfile"] = &CmdMan::cmdKeyfile;
 	execmap["closekey"] = &CmdMan::cmdClosekey;
@@ -47,6 +48,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
 	helpmap["head"] = descHead;
 	helpmap["login"] = descLogin;
 	helpmap["signup"] = descSignup;
+	helpmap["deletefile"] = descDeletefile;
 	helpmap["deleteme"] = descDeleteme;
 	helpmap["keyfile"] = descKeyfile;
 	helpmap["closekey"] = descClosekey;
@@ -64,6 +66,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
 	handlemap["signup"] = &CmdMan::handleSignup;
 	handlemap["listdata"] = &CmdMan::handleListdata;
 	handlemap["head"] = &CmdMan::handleHead;
+	handlemap["deletefile"] = &CmdMan::handleDeletefile;
 	handlemap["deleteme"] = &CmdMan::handleDeleteme;
 
 	debugprintfunc = dpf;
@@ -254,6 +257,25 @@ CmdMan::CmdRet CmdMan::cmdHead(vector<string> args) {
 	return retval;
 }
 
+CmdMan::CmdRet CmdMan::cmdDeletefile(vector<string> args) {
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	root["command"] = "deletefile";
+
+	if (args.size() < 1) {
+		retval.type = error;
+		root["accept"] = false;
+		root["error"] = "not enough arguments, at least 1 argument required";
+	} else {
+		root["file"] = args[0];
+		retval.type = send;
+	}
+	retval.msg = root;
+
+	return retval;
+}
+
 CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
 	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
 	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using command \"" + cmd + "\" with arguments [ ");
@@ -760,6 +782,26 @@ CmdMan::CmdRet CmdMan::handleHead(Json::Value root) {
 		output["command"] = "head";
 		output["file"] = root["file"];
 		output["error"] = "Server reports: " + root["error"].asString();
+		output["accept"] = false;
+		retval.type = error;
+		retval.msg = output;
+	} else {
+		retval.type = print;
+		retval.msg = root;
+	}
+	return retval;
+}
+
+CmdMan::CmdRet CmdMan::handleDeletefile(Json::Value root) {
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	if (!root["accept"].asBool()) {
+		Json::Value output;
+		output["command"] = "deletefile";
+		output["file"] = root["file"];
+		output["error"] = "Server reports: " + root["error"].asString();
+		output["accept"] = false;
 		retval.type = error;
 		retval.msg = output;
 	} else {

+ 9 - 1
cli/src/userioman.cpp

@@ -34,6 +34,7 @@ UserIoMan::UserIoMan(char *ipcstring, bool usessl) : IoMan(ipcstring, usessl) {
 	printmap["putdata"] = &UserIoMan::printPutdata;
 	printmap["getdata"] = &UserIoMan::printGetdata;
 	printmap["head"] = &UserIoMan::printHead;
+	printmap["deletefile"] = &UserIoMan::printDeletefile;
 	printmap["deleteme"] = &UserIoMan::printDeleteme;
 	printmap["keyfile"] = &UserIoMan::printKeyfile;
 	printmap["closekey"] = &UserIoMan::printClosekey;
@@ -185,11 +186,18 @@ void UserIoMan::printListdata(Json::Value root) {}
 
 void UserIoMan::printHead(Json::Value root) {
 	if (!root["accept"].asBool())
-		std::cout << "Request of the first four bytes failed, server reports: " << root["error"].asString() << std::endl;
+		std::cout << "Request of the first four bytes failed. " << root["error"].asString() << std::endl;
 	else
 		std::cout << "First four bytes of file " << root["file"].asString() << " are: " << root["data"].asString() << std::endl;
 }
 
+void UserIoMan::printDeletefile(Json::Value root) {
+	if (!root["accept"].asBool())
+		std::cout << "Deletion of file " << root["file"] << " failed. " << root["error"].asString() << std::endl;
+	else
+		std::cout << "File " << root["file"] << " deleted succesfully" << std::endl;
+}
+
 void UserIoMan::printKeyfile(Json::Value root) {
 	if (!root["accept"].asBool())
 		std::cout << "Couldnt select keyfile " << root["file"].asString() << ": " << root["error"].asString() << std::endl;