Bladeren bron

fix argument bound checks for certain commands (and error outputs in user mode for this case)

Denys 5 jaren geleden
bovenliggende
commit
1154dfb07b
2 gewijzigde bestanden met toevoegingen van 16 en 6 verwijderingen
  1. 2 2
      cli/src/cmdman.cpp
  2. 14 4
      cli/src/userioman.cpp

+ 2 - 2
cli/src/cmdman.cpp

@@ -109,6 +109,7 @@ CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
   CmdRet retval;
   DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
   Json::Value root;
+  root["command"] = "put";
 
   if (args.size() < 1) {
     retval.type = error;
@@ -116,7 +117,6 @@ CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
     root["error"] = "not enough arguments, at least 1 argument required";
   } else {
     bool opened = fileman.openPut(args[0]);
-    root["command"] = "put";
     root["file"] = fileman.getPutName();
     if (opened) {
       root["size"] = fileman.getPutSize();
@@ -155,6 +155,7 @@ CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
   CmdRet retval;
   DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
   Json::Value root;
+  root["command"] = "get";
 
   if (args.size() < 1) {
     retval.type = error;
@@ -162,7 +163,6 @@ CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
     root["error"] = "not enough arguments, at least 1 argument required";
   } else {
     bool opened = fileman.openGet(args[0]);
-    root["command"] = "get";
     root["file"] = fileman.getGetName();
     if (opened) {
       retval.type = send;

+ 14 - 4
cli/src/userioman.cpp

@@ -124,8 +124,13 @@ void UserIoMan::printDisconnect(Json::Value root) {
 
 void UserIoMan::printPut(Json::Value root) {
   if (!root["accept"].asBool()) {
-    std::cout << "Upload request for file " << root["file"].asString()
-              << " failed: " << root["error"].asString() << std::endl;
+    if (root.isMember("file")) {
+      std::cout << "Upload request for file " << root["file"].asString()
+                << " failed: " << root["error"].asString() << std::endl;
+    } else {
+      std::cout << "Upload request failed: " << root["error"].asString()
+                << std::endl;
+    }
   } else
     std::cout << "Begin uploading file " << root["file"].asString()
               << std::endl;
@@ -133,8 +138,13 @@ void UserIoMan::printPut(Json::Value root) {
 
 void UserIoMan::printGet(Json::Value root) {
   if (!root["accept"].asBool()) {
-    std::cout << "Download request for file " << root["file"].asString()
-              << " failed: " << root["error"].asString() << std::endl;
+    if (root.isMember("file")) {
+      std::cout << "Download request for file " << root["file"].asString()
+                << " failed: " << root["error"].asString() << std::endl;
+    } else {
+      std::cout << "Download request failed: " << root["error"].asString()
+                << std::endl;
+    }
   } else
     std::cout << "Begin downloading file " << root["file"].asString()
               << std::endl;