瀏覽代碼

status usable in every state (no tests for this yet)

Denys 4 年之前
父節點
當前提交
d272e4fd0b
共有 4 個文件被更改,包括 17 次插入12 次删除
  1. 1 1
      cli/include/cmdman.h
  2. 10 7
      cli/src/cmdman.cpp
  3. 3 3
      daemon/src/main.cpp
  4. 3 1
      daemon/test/JsonCommanderTest.cpp

+ 1 - 1
cli/include/cmdman.h

@@ -101,7 +101,7 @@ private:
 	 * Vectors containing command strings that should either be usable in any
 	 * state or after connecting but not logging in
 	 */
-	vector<string> cmdAllowAlways = {"help", "keyfile", "closekey", "exit"};
+	vector<string> cmdAllowAlways = {"help", "keyfile", "closekey", "exit", "status"};
 	vector<string> cmdAllowAfterConnect = {"login", "signup", "disconnect"};
 
 	/**

+ 10 - 7
cli/src/cmdman.cpp

@@ -114,7 +114,15 @@ CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
 	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
 	Json::Value root;
 	root["command"] = "status";
-	retval.type = send;
+	if (currentState == normal) {
+		retval.type = send;
+	} else if (currentState == connectionpossible || currentState == disconnecttoexit || currentState == disconnecttoexitearly) {
+		retval.type = print;
+		root["response"] = "You are not connected.";
+	} else {
+		retval.type = print;
+		root["response"] = "Connected to " + ip + ":" + std::to_string(port) + ". Not logged in.";
+	}
 	retval.msg = root;
 
 	return retval;
@@ -471,7 +479,7 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
 		if (cmd.compare("version") && cmd.compare("connect")) {
 			retval.type = error;
 			root["command"] = "error";
-			root["error"] = string("Not connected. Connect using \"connect ip [port]\".");
+			root["error"] = "Not connected. Please connect.";
 			retval.msg = root;
 			return retval;
 		}
@@ -798,7 +806,6 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
 	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
 	output["command"] = "putdata";
 	output["file"] = fileman.getPutName();
-	output["speed"] = 0.0f; // TODO
 	output["cancel"] = true;
 
 	if (root["cancel"].asBool()) {
@@ -827,8 +834,6 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
 		if (!root["received"].asInt()) {
 			// everything sent
 			retval.type = print;
-			// TODO
-			//~ retval.msg = "succesfully uploaded file " + fileman.getPutName();
 			fileman.closePut();
 		} else {
 			retval.type = print | send;
@@ -876,7 +881,6 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
 	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
 	output["command"] = "getdata";
 	output["file"] = fileman.getGetName();
-	output["speed"] = 0.0f; // TODO
 	output["cancel"] = true;
 
 	if (root["cancel"].asBool()) {
@@ -903,7 +907,6 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
 		if (!root["remaining"].asInt()) {
 			// everything received
 			retval.type = print;
-			//~ retval.msg = "succesfully downloaded file " + fileman.getGetName();
 			fileman.closeGet();
 		} else {
 			retval.type = print | send;

+ 3 - 3
daemon/src/main.cpp

@@ -18,7 +18,7 @@ using namespace std;
  *
  * @return covert channel pointer | nullptr if no channel
  */
-CovertChannel * createChannel() {
+CovertChannel *createChannel() {
 	CovertChannel *covertchannel = nullptr;
 
 	const std::string covertChannelMode = Config::getValue("covertChannelMode");
@@ -71,8 +71,8 @@ CovertChannel * createChannel() {
 int main(int argc, char *argv[]) {
 
 	std::string configFile = "config.txt";
-	if(argc >= 2) {
-		if(std::string(argv[1]) == "help") {
+	if (argc >= 2) {
+		if (std::string(argv[1]) == "help") {
 			std::cout << "Usage " << argv[0] << " [config-file]" << std::endl;
 			return 0;
 		}

+ 3 - 1
daemon/test/JsonCommanderTest.cpp

@@ -1011,7 +1011,9 @@ TEST(Head, FileTooSmall) {
 	message["file"] = file;
 
 	std::vector<char> bytes;
-	EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).Times(2).WillRepeatedly(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
+	EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_))
+	    .Times(2)
+	    .WillRepeatedly(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
 
 	JsonCommander::Response response = jsonCommander.execute(message);