Bladeren bron

run autoformatter with new config

Missingmew 5 jaren geleden
bovenliggende
commit
a39ee97d3f

+ 123 - 130
cli/include/cmdman.h

@@ -21,138 +21,131 @@ using std::vector;
  */
 class CmdMan {
 public:
-  /**
-   * Flags for type of message returned in CmdRet.
-   * print	- print something to the user
-   * send	- send something to the server
-   * error	- an error occured, do not send to the server
-   * close	- terminate the connection
-   * seton	- contextually change state, used for version check and login
-   */
-  enum rettype {
-    print = (1 << 0),
-    send = (1 << 1),
-    error = (1 << 2),
-    close = (1 << 3),
-    seton = (1 << 4)
-  };
-  /**
-   * Response to user or command input
-   *
-   * msg is to be handled depending on type
-   * if nextcommand isnt an empty string it should be handled;
-   */
-  struct CmdRet {
-    unsigned int type;
-    string nextcommand;
-    Json::Value msg;
-  };
-  /**
-   * Constructor and destructor
-   */
-  CmdMan(FileMan &fm, void (*dpf)(string));
-  ~CmdMan();
-
-  /**
-   * Executes a user provided command with optional arguments
-   */
-  CmdRet execute(string cmd, vector<string> args);
-  /**
-   * Handles a server provided response json
-   */
-  CmdRet handle(Json::Value root);
-
-  /**
-   * Internal json reader
-   */
-  Json::CharReader *reader;
+	/**
+	 * Flags for type of message returned in CmdRet.
+	 * print	- print something to the user
+	 * send	- send something to the server
+	 * error	- an error occured, do not send to the server
+	 * close	- terminate the connection
+	 * seton	- contextually change state, used for version check and login
+	 */
+	enum rettype { print = (1 << 0), send = (1 << 1), error = (1 << 2), close = (1 << 3), seton = (1 << 4) };
+	/**
+	 * Response to user or command input
+	 *
+	 * msg is to be handled depending on type
+	 * if nextcommand isnt an empty string it should be handled;
+	 */
+	struct CmdRet {
+		unsigned int type;
+		string nextcommand;
+		Json::Value msg;
+	};
+	/**
+	 * Constructor and destructor
+	 */
+	CmdMan(FileMan &fm, void (*dpf)(string));
+	~CmdMan();
+
+	/**
+	 * Executes a user provided command with optional arguments
+	 */
+	CmdRet execute(string cmd, vector<string> args);
+	/**
+	 * Handles a server provided response json
+	 */
+	CmdRet handle(Json::Value root);
+
+	/**
+	 * Internal json reader
+	 */
+	Json::CharReader *reader;
 
 private:
-  /**
-   * internal json writer and error string member
-   */
-  Json::StreamWriterBuilder wbuilder;
-  string jsonerror;
-
-  /**
-   * FileMan instance used to file commands
-   */
-  FileMan &fileman;
-
-  void (*debugprintfunc)(string);
-
-  /**
-   * Maps containing pointers to the appropriate member functions for executing
-   * or handling commands
-   */
-  map<string, CmdRet (CmdMan::*)(vector<string>)> execmap;
-  map<string, CmdRet (CmdMan::*)(Json::Value)> handlemap;
-  /**
-   * Map containing help strings to show to a user
-   */
-  map<string, string> helpmap;
-
-  /**
-   * State used to internally format received json to allow easy handling using
-   * handlemap and to disallow the use of certain commands when logged in/not
-   * logged in.
-   */
-  bool doversion, loginpossible, dologin, dosignup;
-
-  /**
-   * Help strings and method prototypes for commands to be used by a user
-   */
-  /* execute command descriptions and methods go here */
-  const string descHelp = "print available commands";
-  CmdRet cmdHelp(vector<string> args);
-  const string descStatus = "request status from server";
-  CmdRet cmdStatus(vector<string> args);
-  const string descDisconnect = "disconnect from server";
-  CmdRet cmdDisconnect(vector<string> args);
-  const string descPut = "upload file to server and add to queue";
-  CmdRet cmdPut(vector<string> args);
-  const string descGet = "retrieve file from server";
-  CmdRet cmdGet(vector<string> args);
-  const string descList = "list files available on server";
-  CmdRet cmdList(vector<string> args);
-  const string descHead =
-      "request the first four bytes of a file from the server";
-  CmdRet cmdHead(vector<string> args);
-
-  const string descLogin = "login to the server";
-  CmdRet cmdLogin(vector<string> args);
-  const string descSignup = "sign up and login to the server";
-  CmdRet cmdSignup(vector<string> args);
-  const string descDeleteme = "delete the user you are currently logged in as "
-                              "(needs to be confirmed with the password)";
-  CmdRet cmdDeleteme(vector<string> args);
-
-  /**
-   * Method prototypes for commands used internally
-   */
-  /* internal execute commands */
-  CmdRet cmdVersion(vector<string> args);
-  CmdRet cmdPutdata(vector<string> args);
-  CmdRet cmdGetdata(vector<string> args);
-  CmdRet cmdListdata(vector<string> args);
-
-  /**
-   * Method prototypes for handling json responses
-   */
-  /* handle commands go here */
-  CmdRet handleStatus(Json::Value);
-  CmdRet handleClose(Json::Value);
-  CmdRet handlePut(Json::Value);
-  CmdRet handleGet(Json::Value);
-  CmdRet handleList(Json::Value);
-  CmdRet handlePutdata(Json::Value);
-  CmdRet handleGetdata(Json::Value);
-  CmdRet handleListdata(Json::Value);
-  CmdRet handleVersion(Json::Value);
-  CmdRet handleLogin(Json::Value);
-  CmdRet handleSignup(Json::Value);
-  CmdRet handleHead(Json::Value);
-  CmdRet handleDeleteme(Json::Value);
+	/**
+	 * internal json writer and error string member
+	 */
+	Json::StreamWriterBuilder wbuilder;
+	string jsonerror;
+
+	/**
+	 * FileMan instance used to file commands
+	 */
+	FileMan &fileman;
+
+	void (*debugprintfunc)(string);
+
+	/**
+	 * Maps containing pointers to the appropriate member functions for executing
+	 * or handling commands
+	 */
+	map<string, CmdRet (CmdMan::*)(vector<string>)> execmap;
+	map<string, CmdRet (CmdMan::*)(Json::Value)> handlemap;
+	/**
+	 * Map containing help strings to show to a user
+	 */
+	map<string, string> helpmap;
+
+	/**
+	 * State used to internally format received json to allow easy handling using
+	 * handlemap and to disallow the use of certain commands when logged in/not
+	 * logged in.
+	 */
+	bool doversion, loginpossible, dologin, dosignup;
+
+	/**
+	 * Help strings and method prototypes for commands to be used by a user
+	 */
+	/* execute command descriptions and methods go here */
+	const string descHelp = "print available commands";
+	CmdRet cmdHelp(vector<string> args);
+	const string descStatus = "request status from server";
+	CmdRet cmdStatus(vector<string> args);
+	const string descDisconnect = "disconnect from server";
+	CmdRet cmdDisconnect(vector<string> args);
+	const string descPut = "upload file to server and add to queue";
+	CmdRet cmdPut(vector<string> args);
+	const string descGet = "retrieve file from server";
+	CmdRet cmdGet(vector<string> args);
+	const string descList = "list files available on server";
+	CmdRet cmdList(vector<string> args);
+	const string descHead = "request the first four bytes of a file from the server";
+	CmdRet cmdHead(vector<string> args);
+
+	const string descLogin = "login to the server";
+	CmdRet cmdLogin(vector<string> args);
+	const string descSignup = "sign up and login to the server";
+	CmdRet cmdSignup(vector<string> args);
+	const string descDeleteme = "delete the user you are currently logged in as "
+	                            "(needs to be confirmed with the password)";
+	CmdRet cmdDeleteme(vector<string> args);
+
+	/**
+	 * Method prototypes for commands used internally
+	 */
+	/* internal execute commands */
+	CmdRet cmdVersion(vector<string> args);
+	CmdRet cmdPutdata(vector<string> args);
+	CmdRet cmdGetdata(vector<string> args);
+	CmdRet cmdListdata(vector<string> args);
+
+	/**
+	 * Method prototypes for handling json responses
+	 */
+	/* handle commands go here */
+	CmdRet handleStatus(Json::Value);
+	CmdRet handleClose(Json::Value);
+	CmdRet handlePut(Json::Value);
+	CmdRet handleGet(Json::Value);
+	CmdRet handleList(Json::Value);
+	CmdRet handlePutdata(Json::Value);
+	CmdRet handleGetdata(Json::Value);
+	CmdRet handleListdata(Json::Value);
+	CmdRet handleVersion(Json::Value);
+	CmdRet handleLogin(Json::Value);
+	CmdRet handleSignup(Json::Value);
+	CmdRet handleHead(Json::Value);
+	CmdRet handleDeleteme(Json::Value);
 };
 
 #endif

+ 114 - 114
cli/include/fileman.h

@@ -14,122 +14,122 @@
  */
 class FileMan {
 private:
-  /**
-   * Internal state
-   *
-   * Filestreams for put and get
-   * Vector for holding received filenames from listing
-   * Paths and filenames for put and get
-   * Size for internal read
-   * Total and Remaining chunks for put, get and list
-   * Boolean replacement for filestreams being open for list
-   *
-   */
-  std::ifstream putfile;
-  std::ofstream getfile;
-  std::vector<std::string> listdata;
-  std::string getpath, getname, putpath, putname;
-  const unsigned int max_read_len = 8;
-  int putsize;
-  int putchunks;
-  int putchunksRemaining;
-  int getchunks;
-  int getchunksRemaining;
-  int listchunks;
-  int listchunksRemaining;
-
-  bool islisting;
+	/**
+	 * Internal state
+	 *
+	 * Filestreams for put and get
+	 * Vector for holding received filenames from listing
+	 * Paths and filenames for put and get
+	 * Size for internal read
+	 * Total and Remaining chunks for put, get and list
+	 * Boolean replacement for filestreams being open for list
+	 *
+	 */
+	std::ifstream putfile;
+	std::ofstream getfile;
+	std::vector<std::string> listdata;
+	std::string getpath, getname, putpath, putname;
+	const unsigned int max_read_len = 8;
+	int putsize;
+	int putchunks;
+	int putchunksRemaining;
+	int getchunks;
+	int getchunksRemaining;
+	int listchunks;
+	int listchunksRemaining;
+
+	bool islisting;
 
 public:
-  /**
-   * Constructor and Destructor
-   */
-  FileMan();
-  ~FileMan();
-
-  /**
-   * Query internal state
-   *
-   * Return true if the corresponding action is being performed, false otherwise
-   */
-  bool isGetting();
-  bool isPutting();
-  bool isListing();
-
-  /**
-   * Check for and prepare state and streams for reading/writing
-   *
-   * Return true if successful, false otherwise
-   */
-  bool openPut(const std::string &path);
-  bool openGet(const std::string &path);
-  bool openList();
-
-  /**
-   * Close the respective filestream
-   */
-  void closePut();
-  void closeGet();
-  void closeList();
-
-  /**
-   * Query the names of the file currently being put or get
-   */
-  std::string getPutName();
-  std::string getGetName();
-
-  /**
-   * Cancel a put, get or list, depreparing internal state (closing streams if
-   * required)
-   */
-  void cancelPut();
-  void cancelGet();
-  void cancelList();
-
-  /**
-   * Read max_rea_len bytes from the current file opened for put
-   */
-  std::vector<char> readPut();
-  /**
-   * Write the provided vector to the current file opened for get
-   */
-  void writeGet(std::vector<char> data);
-
-  /**
-   * Wrapper methods for reading and writing base64 encoded data instead of raw
-   * bytes
-   */
-  std::string readBase64();
-  void writeBase64(std::string data);
-
-  /**
-   * read and write emulating methods for list
-   */
-  void putListData(std::vector<std::string> names);
-  std::vector<std::string> getListData();
-
-  /**
-   * Query internal state, requesting the corresponding size
-   */
-  int getPutChunks();
-  int getGetChunks();
-  int getListChunks();
-  int getPutRemainingChunks();
-  int getGetRemainingChunks();
-  int getListRemainingChunks();
-  int getPutSize();
-
-  /**
-   * Set internal state, adjusting the chunks as well as chunks remaining for
-   * get and list
-   */
-  void setGetChunks(int chunks);
-  void setListChunks(int chunks);
-
-  /**
-   * Returns the filename of the passed (relative) path of a file
-   */
-  std::string pathToFilename(std::string path);
+	/**
+	 * Constructor and Destructor
+	 */
+	FileMan();
+	~FileMan();
+
+	/**
+	 * Query internal state
+	 *
+	 * Return true if the corresponding action is being performed, false otherwise
+	 */
+	bool isGetting();
+	bool isPutting();
+	bool isListing();
+
+	/**
+	 * Check for and prepare state and streams for reading/writing
+	 *
+	 * Return true if successful, false otherwise
+	 */
+	bool openPut(const std::string &path);
+	bool openGet(const std::string &path);
+	bool openList();
+
+	/**
+	 * Close the respective filestream
+	 */
+	void closePut();
+	void closeGet();
+	void closeList();
+
+	/**
+	 * Query the names of the file currently being put or get
+	 */
+	std::string getPutName();
+	std::string getGetName();
+
+	/**
+	 * Cancel a put, get or list, depreparing internal state (closing streams if
+	 * required)
+	 */
+	void cancelPut();
+	void cancelGet();
+	void cancelList();
+
+	/**
+	 * Read max_rea_len bytes from the current file opened for put
+	 */
+	std::vector<char> readPut();
+	/**
+	 * Write the provided vector to the current file opened for get
+	 */
+	void writeGet(std::vector<char> data);
+
+	/**
+	 * Wrapper methods for reading and writing base64 encoded data instead of raw
+	 * bytes
+	 */
+	std::string readBase64();
+	void writeBase64(std::string data);
+
+	/**
+	 * read and write emulating methods for list
+	 */
+	void putListData(std::vector<std::string> names);
+	std::vector<std::string> getListData();
+
+	/**
+	 * Query internal state, requesting the corresponding size
+	 */
+	int getPutChunks();
+	int getGetChunks();
+	int getListChunks();
+	int getPutRemainingChunks();
+	int getGetRemainingChunks();
+	int getListRemainingChunks();
+	int getPutSize();
+
+	/**
+	 * Set internal state, adjusting the chunks as well as chunks remaining for
+	 * get and list
+	 */
+	void setGetChunks(int chunks);
+	void setListChunks(int chunks);
+
+	/**
+	 * Returns the filename of the passed (relative) path of a file
+	 */
+	std::string pathToFilename(std::string path);
 };
 
 #endif

+ 124 - 124
cli/include/ioman.h

@@ -23,137 +23,137 @@ using boost::asio::ip::tcp;
  * as well as providing user and network output
  */
 class IoMan {
-  /* this is technically private and protected stuff which needs to be public
-   * for the readline callback */
+	/* this is technically private and protected stuff which needs to be public
+	 * for the readline callback */
 public:
-  /**
-   * Type of message to be output
-   */
-  enum OutMsgType { normal, error, debug };
-  /**
-   * Output msg to the user, treating it as type
-   */
-  virtual void printMessage(std::string msg, OutMsgType type);
-  /**
-   * Flag wether to keep the main thread running
-   * Matching mutex to provide syncthonizes access
-   */
-  bool runmain;
-  std::mutex mainmutex;
-  /**
-   * Vector to hold input generated/fetched locally (e.g. from the user)
-   * Matching condition variable to wake up waiting threads
-   * Matching mutex to provide synchronized access
-   */
-  std::mutex localmutex;
-  std::vector<std::string> localinput;
-  std::condition_variable localcv;
+	/**
+	 * Type of message to be output
+	 */
+	enum OutMsgType { normal, error, debug };
+	/**
+	 * Output msg to the user, treating it as type
+	 */
+	virtual void printMessage(std::string msg, OutMsgType type);
+	/**
+	 * Flag wether to keep the main thread running
+	 * Matching mutex to provide syncthonizes access
+	 */
+	bool runmain;
+	std::mutex mainmutex;
+	/**
+	 * Vector to hold input generated/fetched locally (e.g. from the user)
+	 * Matching condition variable to wake up waiting threads
+	 * Matching mutex to provide synchronized access
+	 */
+	std::mutex localmutex;
+	std::vector<std::string> localinput;
+	std::condition_variable localcv;
 
 private:
-  /**
-   * Internal state to provide class-wide asio networking functionality
-   */
-  boost::asio::io_service ios;
-  boost::asio::streambuf recvbuf;
-  boost::system::error_code errcode;
-  tcp::socket *tcpsock;
-  /**
-   * The IP and port to connect to
-   * Flag telling wether one is connected
-   */
-  std::string ipstring;
-  unsigned short port;
-  bool connected;
-  /**
-   * Instances of CmdMan and FileMan to process user input and handle File I/O
-   */
-  CmdMan cmdman;
-  FileMan fileman;
-
-  /**
-   * Thread handles for processing local and network input as well as generating
-   * responses to both Matching mutexes for the flags wether the threads should
-   * keep running Function prototypes for the main thread functions
-   */
-  std::thread tinput, tnetwork, tresponse;
-  std::mutex inputmutex, networkmutex, responsemutex;
-  bool runinput, runnetwork, runresponse;
-  void networkMain();
-  void inputMain();
-  void responseMain();
-
-  /**
-   * Vector to hold preprocessed input from the network
-   * Matching condition variable to wake up waiting threads
-   * Matching mutex to provide synchronized access
-   */
-  std::vector<Json::Value> netinput;
-  std::mutex netmutex;
-  std::condition_variable netcv;
-
-  /**
-   * Class-wide json functionality
-   */
-  Json::CharReader *reader;
-  Json::StreamWriterBuilder wbuilder;
-  string jsonerror;
-
-  /**
-   * Enum for internal login and version state
-   * Variables for keeping said state
-   * Matching mutex and condition variable
-   */
-  enum Status { off, on, err };
-  Status versionstatus;
-  Status loginstatus;
-  std::mutex initmutex;
-  std::condition_variable initcv;
-
-  /**
-   * Tokenizes input based on space as seperator
-   * Respects double-quoted tokens
-   * Returns a vector with the tokens as elements in order
-   */
-  std::vector<std::string> tokenizeInput(std::string in);
+	/**
+	 * Internal state to provide class-wide asio networking functionality
+	 */
+	boost::asio::io_service ios;
+	boost::asio::streambuf recvbuf;
+	boost::system::error_code errcode;
+	tcp::socket *tcpsock;
+	/**
+	 * The IP and port to connect to
+	 * Flag telling wether one is connected
+	 */
+	std::string ipstring;
+	unsigned short port;
+	bool connected;
+	/**
+	 * Instances of CmdMan and FileMan to process user input and handle File I/O
+	 */
+	CmdMan cmdman;
+	FileMan fileman;
+
+	/**
+	 * Thread handles for processing local and network input as well as generating
+	 * responses to both Matching mutexes for the flags wether the threads should
+	 * keep running Function prototypes for the main thread functions
+	 */
+	std::thread tinput, tnetwork, tresponse;
+	std::mutex inputmutex, networkmutex, responsemutex;
+	bool runinput, runnetwork, runresponse;
+	void networkMain();
+	void inputMain();
+	void responseMain();
+
+	/**
+	 * Vector to hold preprocessed input from the network
+	 * Matching condition variable to wake up waiting threads
+	 * Matching mutex to provide synchronized access
+	 */
+	std::vector<Json::Value> netinput;
+	std::mutex netmutex;
+	std::condition_variable netcv;
+
+	/**
+	 * Class-wide json functionality
+	 */
+	Json::CharReader *reader;
+	Json::StreamWriterBuilder wbuilder;
+	string jsonerror;
+
+	/**
+	 * Enum for internal login and version state
+	 * Variables for keeping said state
+	 * Matching mutex and condition variable
+	 */
+	enum Status { off, on, err };
+	Status versionstatus;
+	Status loginstatus;
+	std::mutex initmutex;
+	std::condition_variable initcv;
+
+	/**
+	 * Tokenizes input based on space as seperator
+	 * Respects double-quoted tokens
+	 * Returns a vector with the tokens as elements in order
+	 */
+	std::vector<std::string> tokenizeInput(std::string in);
 
 protected:
-  /**
-   * Prompt messages for readline prompt
-   */
-  virtual void printWelcomeMessage() = 0;
-  virtual std::string getCmdPrompt() = 0;
-  // following prompts currently not in use because login happens by entering
-  // command
-  //~  virtual std::string getUserPrompt() = 0;
-  //~  virtual std::string getPassPrompt() = 0;
+	/**
+	 * Prompt messages for readline prompt
+	 */
+	virtual void printWelcomeMessage() = 0;
+	virtual std::string getCmdPrompt() = 0;
+	// following prompts currently not in use because login happens by entering
+	// command
+	//~  virtual std::string getUserPrompt() = 0;
+	//~  virtual std::string getPassPrompt() = 0;
 
 public:
-  /**
-   * Constructor and destructor
-   */
-  IoMan(char *ipcstring);
-  virtual ~IoMan();
-
-  /**
-   * Establish connection to server and perform vesion check
-   * Return true if successful, false otherwise
-   */
-  bool init();
-
-  /**
-   * Main loop, call init first
-   */
-  void run();
-
-  /**
-   * Establish connection to server
-   * Return true if successful, false otherwise
-   */
-  bool connect();
-  /**
-   * Disconnect from a connected server
-   */
-  void disconnect();
+	/**
+	 * Constructor and destructor
+	 */
+	IoMan(char *ipcstring);
+	virtual ~IoMan();
+
+	/**
+	 * Establish connection to server and perform vesion check
+	 * Return true if successful, false otherwise
+	 */
+	bool init();
+
+	/**
+	 * Main loop, call init first
+	 */
+	void run();
+
+	/**
+	 * Establish connection to server
+	 * Return true if successful, false otherwise
+	 */
+	bool connect();
+	/**
+	 * Disconnect from a connected server
+	 */
+	void disconnect();
 };
 
 #endif

+ 12 - 12
cli/include/machineioman.h

@@ -11,21 +11,21 @@
  */
 class MachineIoMan : public IoMan {
 public:
-  using IoMan::IoMan;
+	using IoMan::IoMan;
 
 protected:
-  /**
-   * Specific implementations for printing messages
-   */
-  void printMessage(std::string msg, OutMsgType type);
-  void printWelcomeMessage();
+	/**
+	 * Specific implementations for printing messages
+	 */
+	void printMessage(std::string msg, OutMsgType type);
+	void printWelcomeMessage();
 
-  /**
-   * Return the specific prompt strings for IoMan prompts
-   */
-  std::string getCmdPrompt();
-  std::string getUserPrompt();
-  std::string getPassPrompt();
+	/**
+	 * Return the specific prompt strings for IoMan prompts
+	 */
+	std::string getCmdPrompt();
+	std::string getUserPrompt();
+	std::string getPassPrompt();
 };
 
 #endif

+ 55 - 55
cli/include/userioman.h

@@ -11,70 +11,70 @@
  */
 class UserIoMan : public IoMan {
 private:
-  /**
-   * Map containing pointers to the appropriate member functions for printing
-   * formatted json output
-   */
-  map<string, void (UserIoMan::*)(Json::Value)> printmap;
+	/**
+	 * Map containing pointers to the appropriate member functions for printing
+	 * formatted json output
+	 */
+	map<string, void (UserIoMan::*)(Json::Value)> printmap;
 
-  /**
-   * Class-wide json functionality
-   */
-  Json::CharReader *reader;
-  Json::StreamWriterBuilder wbuilder;
-  string jsonerror;
+	/**
+	 * Class-wide json functionality
+	 */
+	Json::CharReader *reader;
+	Json::StreamWriterBuilder wbuilder;
+	string jsonerror;
 
-  /**
-   * Format and pretty print json for terminal output
-   */
-  void printJson(Json::Value root);
+	/**
+	 * Format and pretty print json for terminal output
+	 */
+	void printJson(Json::Value root);
 
-  /**
-   * Method prototypes for printing json output
-   */
-  /* printing commands go here */
-  void printError(Json::Value root);
-  void printConnect(Json::Value root);
-  void printHelp(Json::Value root);
-  void printStatus(Json::Value root);
-  void printDisconnect(Json::Value root);
-  void printPut(Json::Value root);
-  void printGet(Json::Value root);
-  void printList(Json::Value root);
-  void printVersion(Json::Value root);
-  void printLogin(Json::Value root);
-  void printSignup(Json::Value root);
-  void printPutdata(Json::Value root);
-  void printGetdata(Json::Value root);
-  void printListdata(Json::Value root);
-  void printHead(Json::Value root);
-  void printDeleteme(Json::Value root);
+	/**
+	 * Method prototypes for printing json output
+	 */
+	/* printing commands go here */
+	void printError(Json::Value root);
+	void printConnect(Json::Value root);
+	void printHelp(Json::Value root);
+	void printStatus(Json::Value root);
+	void printDisconnect(Json::Value root);
+	void printPut(Json::Value root);
+	void printGet(Json::Value root);
+	void printList(Json::Value root);
+	void printVersion(Json::Value root);
+	void printLogin(Json::Value root);
+	void printSignup(Json::Value root);
+	void printPutdata(Json::Value root);
+	void printGetdata(Json::Value root);
+	void printListdata(Json::Value root);
+	void printHead(Json::Value root);
+	void printDeleteme(Json::Value root);
 
-  /**
-   * Mutex for synchronized message output
-   */
-  std::recursive_mutex msgmutex;
+	/**
+	 * Mutex for synchronized message output
+	 */
+	std::recursive_mutex msgmutex;
 
 public:
-  /**
-   * Constructor and destructor
-   */
-  UserIoMan(char *ipcstring);
-  ~UserIoMan();
+	/**
+	 * Constructor and destructor
+	 */
+	UserIoMan(char *ipcstring);
+	~UserIoMan();
 
 protected:
-  /**
-   * Specific implementations for printing messages
-   */
-  void printMessage(std::string msg, OutMsgType type);
-  void printWelcomeMessage();
+	/**
+	 * Specific implementations for printing messages
+	 */
+	void printMessage(std::string msg, OutMsgType type);
+	void printWelcomeMessage();
 
-  /**
-   * Return the specific prompt strings for IoMan prompts
-   */
-  std::string getCmdPrompt();
-  std::string getUserPrompt();
-  std::string getPassPrompt();
+	/**
+	 * Return the specific prompt strings for IoMan prompts
+	 */
+	std::string getCmdPrompt();
+	std::string getUserPrompt();
+	std::string getPassPrompt();
 };
 
 #endif

+ 20 - 26
cli/src/base64.cpp

@@ -3,47 +3,41 @@
 #include <boost/beast.hpp>
 
 std::string base64::decode(const std::string &val) {
-  std::string ret;
-  ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
+	std::string ret;
+	ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
 
-  std::size_t read = boost::beast::detail::base64::decode(
-                         &ret.front(), val.c_str(), val.size())
-                         .first;
+	std::size_t read = boost::beast::detail::base64::decode(&ret.front(), val.c_str(), val.size()).first;
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }
 
 std::vector<char> base64::decodeVector(const std::string &val) {
-  std::vector<char> ret;
-  ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
+	std::vector<char> ret;
+	ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
 
-  std::size_t read =
-      boost::beast::detail::base64::decode(ret.data(), val.c_str(), val.size())
-          .first;
+	std::size_t read = boost::beast::detail::base64::decode(ret.data(), val.c_str(), val.size()).first;
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }
 
 std::string base64::encode(const std::string &val) {
-  std::string ret;
-  ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
+	std::string ret;
+	ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
 
-  std::size_t read = boost::beast::detail::base64::encode(
-      &ret.front(), val.data(), val.size());
+	std::size_t read = boost::beast::detail::base64::encode(&ret.front(), val.data(), val.size());
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }
 
 std::string base64::encodeVector(const std::vector<char> &val) {
-  std::string ret;
-  ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
+	std::string ret;
+	ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
 
-  std::size_t read = boost::beast::detail::base64::encode(
-      &ret.front(), val.data(), val.size());
+	std::size_t read = boost::beast::detail::base64::encode(&ret.front(), val.data(), val.size());
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }

+ 628 - 653
cli/src/cmdman.cpp

@@ -9,751 +9,726 @@
 
 CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
 
-  /* setup json stuff */
-  Json::CharReaderBuilder rbuilder;
-  wbuilder.settings_["indentation"] = "";
-  reader = rbuilder.newCharReader();
-
-  doversion = false;
-  loginpossible = false;
-  dologin = false;
-  dosignup = false;
-
-  /* initialize execute command map */
-  execmap["help"] = &CmdMan::cmdHelp;
-  execmap["status"] = &CmdMan::cmdStatus;
-  execmap["disconnect"] = &CmdMan::cmdDisconnect;
-  execmap["put"] = &CmdMan::cmdPut;
-  execmap["get"] = &CmdMan::cmdGet;
-  execmap["list"] = &CmdMan::cmdList;
-  execmap["version"] = &CmdMan::cmdVersion;
-  execmap["login"] = &CmdMan::cmdLogin;
-  execmap["signup"] = &CmdMan::cmdSignup;
-  execmap["putdata"] = &CmdMan::cmdPutdata;
-  execmap["getdata"] = &CmdMan::cmdGetdata;
-  execmap["listdata"] = &CmdMan::cmdListdata;
-  execmap["head"] = &CmdMan::cmdHead;
-  execmap["deleteme"] = &CmdMan::cmdDeleteme;
-
-  /* initialize description map */
-  helpmap["help"] = descHelp;
-  helpmap["status"] = descStatus;
-  helpmap["disconnect"] = descDisconnect;
-  helpmap["put"] = descPut;
-  helpmap["get"] = descGet;
-  helpmap["list"] = descList;
-  helpmap["head"] = descHead;
-  helpmap["login"] = descLogin;
-  helpmap["signup"] = descSignup;
-  helpmap["deleteme"] = descDeleteme;
-
-  /* initialize handle command map */
-  handlemap["status"] = &CmdMan::handleStatus;
-  handlemap["close"] = &CmdMan::handleClose;
-  handlemap["put"] = &CmdMan::handlePut;
-  handlemap["get"] = &CmdMan::handleGet;
-  handlemap["putdata"] = &CmdMan::handlePutdata;
-  handlemap["getdata"] = &CmdMan::handleGetdata;
-  handlemap["list"] = &CmdMan::handleList;
-  handlemap["version"] = &CmdMan::handleVersion;
-  handlemap["login"] = &CmdMan::handleLogin;
-  handlemap["signup"] = &CmdMan::handleSignup;
-  handlemap["listdata"] = &CmdMan::handleListdata;
-  handlemap["head"] = &CmdMan::handleHead;
-  handlemap["deleteme"] = &CmdMan::handleDeleteme;
-
-  debugprintfunc = dpf;
+	/* setup json stuff */
+	Json::CharReaderBuilder rbuilder;
+	wbuilder.settings_["indentation"] = "";
+	reader = rbuilder.newCharReader();
+
+	doversion = false;
+	loginpossible = false;
+	dologin = false;
+	dosignup = false;
+
+	/* initialize execute command map */
+	execmap["help"] = &CmdMan::cmdHelp;
+	execmap["status"] = &CmdMan::cmdStatus;
+	execmap["disconnect"] = &CmdMan::cmdDisconnect;
+	execmap["put"] = &CmdMan::cmdPut;
+	execmap["get"] = &CmdMan::cmdGet;
+	execmap["list"] = &CmdMan::cmdList;
+	execmap["version"] = &CmdMan::cmdVersion;
+	execmap["login"] = &CmdMan::cmdLogin;
+	execmap["signup"] = &CmdMan::cmdSignup;
+	execmap["putdata"] = &CmdMan::cmdPutdata;
+	execmap["getdata"] = &CmdMan::cmdGetdata;
+	execmap["listdata"] = &CmdMan::cmdListdata;
+	execmap["head"] = &CmdMan::cmdHead;
+	execmap["deleteme"] = &CmdMan::cmdDeleteme;
+
+	/* initialize description map */
+	helpmap["help"] = descHelp;
+	helpmap["status"] = descStatus;
+	helpmap["disconnect"] = descDisconnect;
+	helpmap["put"] = descPut;
+	helpmap["get"] = descGet;
+	helpmap["list"] = descList;
+	helpmap["head"] = descHead;
+	helpmap["login"] = descLogin;
+	helpmap["signup"] = descSignup;
+	helpmap["deleteme"] = descDeleteme;
+
+	/* initialize handle command map */
+	handlemap["status"] = &CmdMan::handleStatus;
+	handlemap["close"] = &CmdMan::handleClose;
+	handlemap["put"] = &CmdMan::handlePut;
+	handlemap["get"] = &CmdMan::handleGet;
+	handlemap["putdata"] = &CmdMan::handlePutdata;
+	handlemap["getdata"] = &CmdMan::handleGetdata;
+	handlemap["list"] = &CmdMan::handleList;
+	handlemap["version"] = &CmdMan::handleVersion;
+	handlemap["login"] = &CmdMan::handleLogin;
+	handlemap["signup"] = &CmdMan::handleSignup;
+	handlemap["listdata"] = &CmdMan::handleListdata;
+	handlemap["head"] = &CmdMan::handleHead;
+	handlemap["deleteme"] = &CmdMan::handleDeleteme;
+
+	debugprintfunc = dpf;
 }
 
 CmdMan::~CmdMan() { delete reader; }
 
 CmdMan::CmdRet CmdMan::cmdHelp(vector<string> args) {
-  CmdRet retval;
-  Json::Value root, arr;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  map<string, string>::iterator it;
-  root["command"] = "help";
-  for (it = helpmap.begin(); it != helpmap.end(); it++) {
-    arr.append(it->first + " - " + it->second);
-  }
-  root["names"] = arr;
-  retval.type = print;
-  retval.msg = root;
-  return retval;
+	CmdRet retval;
+	Json::Value root, arr;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	map<string, string>::iterator it;
+	root["command"] = "help";
+	for (it = helpmap.begin(); it != helpmap.end(); it++) {
+		arr.append(it->first + " - " + it->second);
+	}
+	root["names"] = arr;
+	retval.type = print;
+	retval.msg = root;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-  root["command"] = "status";
-  retval.type = send;
-  retval.msg = root;
-
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	root["command"] = "status";
+	retval.type = send;
+	retval.msg = root;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-  retval.type = send;
-  if (loginpossible) {
-    // not logged in, send appropriate login message instead of normal close
-    root["login"] = false;
-    root["user"] = "";
-    root["pass"] = "";
-    root["cancel"] = true;
-    retval.type |= close;
-  } else {
-    root["command"] = "close";
-  }
-  retval.msg = root;
-
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	retval.type = send;
+	if (loginpossible) {
+		// not logged in, send appropriate login message instead of normal close
+		root["login"] = false;
+		root["user"] = "";
+		root["pass"] = "";
+		root["cancel"] = true;
+		retval.type |= close;
+	} else {
+		root["command"] = "close";
+	}
+	retval.msg = root;
+
+	return retval;
 }
 
 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;
-    root["accept"] = false;
-    root["error"] = "not enough arguments, at least 1 argument required";
-  } else {
-    bool opened = fileman.openPut(args[0]);
-    root["file"] = fileman.getPutName();
-    if (opened) {
-      root["size"] = fileman.getPutSize();
-      root["chunks"] = fileman.getPutChunks();
-      retval.type = send;
-    } else {
-      retval.type = error;
-      root["accept"] = false;
-      root["error"] = "couldnt open local file \"" + args[0] + "\"";
-    }
-  }
-
-  retval.msg = root;
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	root["command"] = "put";
+
+	if (args.size() < 1) {
+		retval.type = error;
+		root["accept"] = false;
+		root["error"] = "not enough arguments, at least 1 argument required";
+	} else {
+		bool opened = fileman.openPut(args[0]);
+		root["file"] = fileman.getPutName();
+		if (opened) {
+			root["size"] = fileman.getPutSize();
+			root["chunks"] = fileman.getPutChunks();
+			retval.type = send;
+		} else {
+			retval.type = error;
+			root["accept"] = false;
+			root["error"] = "couldnt open local file \"" + args[0] + "\"";
+		}
+	}
+
+	retval.msg = root;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdPutdata(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-
-  root["command"] = "putdata";
-  root["file"] = fileman.getPutName();
-  root["cancel"] = false;
-  root["data"] = fileman.readBase64();
-  root["remaining"] =
-      fileman
-          .getPutRemainingChunks(); // number already decremented by readBase64
-  retval.type = send;
-  retval.msg = root;
-
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+
+	root["command"] = "putdata";
+	root["file"] = fileman.getPutName();
+	root["cancel"] = false;
+	root["data"] = fileman.readBase64();
+	root["remaining"] = fileman.getPutRemainingChunks(); // number already decremented by readBase64
+	retval.type = send;
+	retval.msg = root;
+
+	return retval;
 }
 
 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;
-    root["accept"] = false;
-    root["error"] = "not enough arguments, at least 1 argument required";
-  } else {
-    bool opened = fileman.openGet(args[0]);
-    root["file"] = fileman.getGetName();
-    if (opened) {
-      retval.type = send;
-    } else {
-      retval.type = error;
-      root["accept"] = false;
-      root["error"] = "local file \"" + args[0] + "\" already exists";
-    }
-  }
-
-  retval.msg = root;
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	root["command"] = "get";
+
+	if (args.size() < 1) {
+		retval.type = error;
+		root["accept"] = false;
+		root["error"] = "not enough arguments, at least 1 argument required";
+	} else {
+		bool opened = fileman.openGet(args[0]);
+		root["file"] = fileman.getGetName();
+		if (opened) {
+			retval.type = send;
+		} else {
+			retval.type = error;
+			root["accept"] = false;
+			root["error"] = "local file \"" + args[0] + "\" already exists";
+		}
+	}
+
+	retval.msg = root;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdGetdata(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-
-  root["command"] = "getdata";
-  root["file"] = fileman.getGetName();
-  root["chunk"] = fileman.getGetRemainingChunks();
-  root["cancel"] = false;
-  retval.type = send;
-  retval.msg = root;
-
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+
+	root["command"] = "getdata";
+	root["file"] = fileman.getGetName();
+	root["chunk"] = fileman.getGetRemainingChunks();
+	root["cancel"] = false;
+	retval.type = send;
+	retval.msg = root;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-
-  bool opened = fileman.openList();
-  root["command"] = "list";
-  if (opened) {
-    retval.type = send;
-  } else {
-    retval.type = error;
-    root["accept"] = false;
-    root["names"] = "";
-    root["error"] = "cannot list, already listing";
-  }
-
-  retval.msg = root;
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+
+	bool opened = fileman.openList();
+	root["command"] = "list";
+	if (opened) {
+		retval.type = send;
+	} else {
+		retval.type = error;
+		root["accept"] = false;
+		root["names"] = "";
+		root["error"] = "cannot list, already listing";
+	}
+
+	retval.msg = root;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdListdata(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-  root["command"] = "listdata";
-  root["chunk"] = fileman.getListRemainingChunks();
-  root["cancel"] = false;
-  retval.type = send;
-  retval.msg = root;
-
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	root["command"] = "listdata";
+	root["chunk"] = fileman.getListRemainingChunks();
+	root["cancel"] = false;
+	retval.type = send;
+	retval.msg = root;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdHead(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-  root["command"] = "head";
-
-  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;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	root["command"] = "head";
+
+	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 [ ");
-  for (string s : args)
-    DEBUGPRINT(s + " ");
-  DEBUGPRINT("]");
-  map<string, CmdRet (CmdMan::*)(vector<string>)>::iterator it =
-      execmap.find(cmd);
-  CmdRet retval;
-  Json::Value root;
-  root["command"] = cmd;
-  if (it == execmap.end()) {
-    retval.type = error;
-    root["command"] = "error";
-    root["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd +
-                    "\".\ntype help to list available commands.";
-    retval.msg = root;
-    return retval;
-  } else if (loginpossible || dologin || dosignup) {
-    DEBUGPRINT("execute does login");
-    DEBUGPRINT(string("comparison is ") +
-               std::to_string(cmd.compare("login") && cmd.compare("signup") &&
-                              cmd.compare("disconnect") &&
-                              cmd.compare("help")));
-    if (cmd.compare("login") && cmd.compare("signup") &&
-        cmd.compare("disconnect") && cmd.compare("help")) {
-      retval.type = error;
-      root["command"] = "error";
-      root["error"] =
-          string("Not logged in. Available commands are limited to ") +
-          "login" + ", " + "signup" + " and " + "disconnect" + "\n" +
-          "Use help for usage of these commands.";
-      retval.msg = root;
-      return retval;
-    }
-  }
-  return (this->*(execmap[cmd]))(args);
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using command \"" + cmd + "\" with arguments [ ");
+	for (string s : args)
+		DEBUGPRINT(s + " ");
+	DEBUGPRINT("]");
+	map<string, CmdRet (CmdMan::*)(vector<string>)>::iterator it = execmap.find(cmd);
+	CmdRet retval;
+	Json::Value root;
+	root["command"] = cmd;
+	if (it == execmap.end()) {
+		retval.type = error;
+		root["command"] = "error";
+		root["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd + "\".\ntype help to list available commands.";
+		retval.msg = root;
+		return retval;
+	} else if (loginpossible || dologin || dosignup) {
+		DEBUGPRINT("execute does login");
+		DEBUGPRINT(string("comparison is ") +
+		           std::to_string(cmd.compare("login") && cmd.compare("signup") && cmd.compare("disconnect") && cmd.compare("help")));
+		if (cmd.compare("login") && cmd.compare("signup") && cmd.compare("disconnect") && cmd.compare("help")) {
+			retval.type = error;
+			root["command"] = "error";
+			root["error"] = string("Not logged in. Available commands are limited to ") + "login" + ", " + "signup" + " and " + "disconnect" + "\n" +
+			                "Use help for usage of these commands.";
+			retval.msg = root;
+			return retval;
+		}
+	}
+	return (this->*(execmap[cmd]))(args);
 }
 
 CmdMan::CmdRet CmdMan::cmdDeleteme(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-
-  root["command"] = "deleteme";
-
-  if (args.size() < 1) {
-    retval.type = error;
-    root["accept"] = false;
-    root["error"] = "not enough arguments, at least 1 argument required";
-  } else {
-    retval.type = send;
-    root["pass"] = args[0];
-  }
-  retval.msg = root;
-
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+
+	root["command"] = "deleteme";
+
+	if (args.size() < 1) {
+		retval.type = error;
+		root["accept"] = false;
+		root["error"] = "not enough arguments, at least 1 argument required";
+	} else {
+		retval.type = send;
+		root["pass"] = args[0];
+	}
+	retval.msg = root;
+
+	return retval;
 }
 
 /* login and signup commands */
 CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-
-  if (args.size() < 2) {
-    retval.type = error;
-    root["command"] = "login";
-    root["accept"] = false;
-    root["error"] = "not enough arguments, at least 2 argument required";
-  } else {
-    if (loginpossible) {
-      dologin = true;
-      loginpossible = false;
-      root["user"] = args[0];
-      root["pass"] = args[1];
-      root["login"] = true;
-      root["cancel"] = false;
-      retval.type = send;
-    } else {
-      root["command"] = "login";
-      root["error"] =
-          "Login not possible, because you already requested a login "
-          "or you are logged in";
-      root["accept"] = false;
-      retval.type = error;
-    }
-  }
-
-  retval.msg = root;
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+
+	if (args.size() < 2) {
+		retval.type = error;
+		root["command"] = "login";
+		root["accept"] = false;
+		root["error"] = "not enough arguments, at least 2 argument required";
+	} else {
+		if (loginpossible) {
+			dologin = true;
+			loginpossible = false;
+			root["user"] = args[0];
+			root["pass"] = args[1];
+			root["login"] = true;
+			root["cancel"] = false;
+			retval.type = send;
+		} else {
+			root["command"] = "login";
+			root["error"] = "Login not possible, because you already requested a login "
+			                "or you are logged in";
+			root["accept"] = false;
+			retval.type = error;
+		}
+	}
+
+	retval.msg = root;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::cmdSignup(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-
-  if (args.size() < 2) {
-    retval.type = error;
-    root["command"] = "signup";
-    root["accept"] = false;
-    root["error"] = "not enough arguments, at least 2 argument required";
-  } else {
-    if (loginpossible) {
-      dosignup = true;
-      loginpossible = false;
-      root["user"] = args[0];
-      root["pass"] = args[1];
-      root["login"] = false;
-      root["cancel"] = false;
-      retval.type = send;
-    } else {
-      root["command"] = "signup";
-      root["error"] = "Signup not possible, because you already requested a "
-                      "login or you are logged in";
-      root["accept"] = false;
-      retval.type = error;
-    }
-  }
-
-  retval.msg = root;
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+
+	if (args.size() < 2) {
+		retval.type = error;
+		root["command"] = "signup";
+		root["accept"] = false;
+		root["error"] = "not enough arguments, at least 2 argument required";
+	} else {
+		if (loginpossible) {
+			dosignup = true;
+			loginpossible = false;
+			root["user"] = args[0];
+			root["pass"] = args[1];
+			root["login"] = false;
+			root["cancel"] = false;
+			retval.type = send;
+		} else {
+			root["command"] = "signup";
+			root["error"] = "Signup not possible, because you already requested a "
+			                "login or you are logged in";
+			root["accept"] = false;
+			retval.type = error;
+		}
+	}
+
+	retval.msg = root;
+	return retval;
 }
 
 /* internal commands */
 CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  Json::Value root;
-  root["version"] = protocolVersion;
-  retval.type = send;
-  retval.msg = root;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	Json::Value root;
+	root["version"] = protocolVersion;
+	retval.type = send;
+	retval.msg = root;
 
-  doversion = true;
+	doversion = true;
 
-  return retval;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handle(Json::Value root) {
-  CmdRet retval;
-  Json::Value output;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  if (doversion)
-    root["command"] = "version";
-  else if (dosignup)
-    root["command"] = "signup";
-  else if (dologin)
-    root["command"] = "login";
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using json\n" +
-             Json::writeString(wbuilder, root) + "\n");
-  string retmsg;
-  map<string, CmdRet (CmdMan::*)(Json::Value)>::iterator it =
-      handlemap.find(root["command"].asString());
-
-  if (it == handlemap.end()) {
-    retval.type = error;
-    output["command"] = "error";
-    output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" +
-                      root["command"].asString() +
-                      "\".\nEnsure code is implemented.";
-    retval.msg = output;
-    return retval;
-  }
-  return (this->*(handlemap[root["command"].asString()]))(root);
+	CmdRet retval;
+	Json::Value output;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	if (doversion)
+		root["command"] = "version";
+	else if (dosignup)
+		root["command"] = "signup";
+	else if (dologin)
+		root["command"] = "login";
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using json\n" + Json::writeString(wbuilder, root) + "\n");
+	string retmsg;
+	map<string, CmdRet (CmdMan::*)(Json::Value)>::iterator it = handlemap.find(root["command"].asString());
+
+	if (it == handlemap.end()) {
+		retval.type = error;
+		output["command"] = "error";
+		output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + root["command"].asString() + "\".\nEnsure code is implemented.";
+		retval.msg = output;
+		return retval;
+	}
+	return (this->*(handlemap[root["command"].asString()]))(root);
 }
 
 CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  retval.type = print;
-  retval.msg = root;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	retval.type = print;
+	retval.msg = root;
 
-  return retval;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleClose(Json::Value root) {
-  CmdRet retval;
-  Json::Value output;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  output["command"] = "disconnect";
-  output["accept"] = true;
-  retval.type = close | print;
-  retval.msg = output;
-
-  return retval;
+	CmdRet retval;
+	Json::Value output;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	output["command"] = "disconnect";
+	output["accept"] = true;
+	retval.type = close | print;
+	retval.msg = output;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
-  CmdRet retval;
-  Json::Value output;
-  output["command"] = "put";
-  output["file"] = fileman.getPutName();
-  output["accept"] = false;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  if (!root["accept"].asBool()) {
-    retval.type = error;
-    output["error"] = "Server reports: " + root["error"].asString();
-    fileman.cancelPut();
-  } else if (root["file"].asString() != fileman.getPutName()) {
-    retval.type = error;
-    output["error"] = "Server reports filename " + root["file"].asString() +
-                      " but actual filename is " + fileman.getPutName();
-    fileman.cancelPut();
-  } else {
-    output["accept"] = true;
-    output["error"] = "";
-    retval.type = print | send;
-    retval.nextcommand = "putdata";
-  }
-  retval.msg = output;
-
-  return retval;
+	CmdRet retval;
+	Json::Value output;
+	output["command"] = "put";
+	output["file"] = fileman.getPutName();
+	output["accept"] = false;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	if (!root["accept"].asBool()) {
+		retval.type = error;
+		output["error"] = "Server reports: " + root["error"].asString();
+		fileman.cancelPut();
+	} else if (root["file"].asString() != fileman.getPutName()) {
+		retval.type = error;
+		output["error"] = "Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getPutName();
+		fileman.cancelPut();
+	} else {
+		output["accept"] = true;
+		output["error"] = "";
+		retval.type = print | send;
+		retval.nextcommand = "putdata";
+	}
+	retval.msg = output;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
-  CmdRet retval;
-  Json::Value output;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  output["command"] = "putdata";
-  output["file"] = fileman.getPutName();
-  output["speed"] = 0.0f; // TODO
-  output["cancel"] = true;
-
-  if (root["received"].asInt() != fileman.getPutRemainingChunks()) {
-    // the number of remaining chunks received from the daemon does not equal
-    // the number stored at the client side
-    retval.type = error;
-    output["error"] = std::string("Server reports number of "
-                                  "remaining chunks as ") +
-                      std::to_string(root["received"].asInt()) +
-                      " but actual number is " +
-                      std::to_string(fileman.getPutRemainingChunks());
-    fileman.cancelPut();
-  } else if (root["cancel"].asBool()) {
-    retval.type = error;
-    output["error"] = "Server reports: " + root["error"].asString();
-    fileman.cancelPut();
-  } else if (root["file"].asString() != fileman.getPutName()) {
-    retval.type = error;
-    output["error"] = "Server reports filename " + root["file"].asString() +
-                      " but actual filename is " + fileman.getPutName();
-    fileman.cancelPut();
-  } else {
-    output["cancel"] = false;
-    output["error"] = "";
-    // sent successfully
-    if (!root["received"].asInt()) {
-      // everything sent
-      retval.type = print;
-      // TODO
-      //~ retval.msg = "succesfully uploaded file " + fileman.getPutName();
-      fileman.closePut();
-    } else {
-      retval.type = print | send;
-      retval.nextcommand = "putdata";
-    }
-  }
-  retval.msg = output;
-  return retval;
+	CmdRet retval;
+	Json::Value output;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	output["command"] = "putdata";
+	output["file"] = fileman.getPutName();
+	output["speed"] = 0.0f; // TODO
+	output["cancel"] = true;
+
+	if (root["received"].asInt() != fileman.getPutRemainingChunks()) {
+		// the number of remaining chunks received from the daemon does not equal
+		// the number stored at the client side
+		retval.type = error;
+		output["error"] = std::string("Server reports number of "
+		                              "remaining chunks as ") +
+		                  std::to_string(root["received"].asInt()) + " but actual number is " + std::to_string(fileman.getPutRemainingChunks());
+		fileman.cancelPut();
+	} else if (root["cancel"].asBool()) {
+		retval.type = error;
+		output["error"] = "Server reports: " + root["error"].asString();
+		fileman.cancelPut();
+	} else if (root["file"].asString() != fileman.getPutName()) {
+		retval.type = error;
+		output["error"] = "Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getPutName();
+		fileman.cancelPut();
+	} else {
+		output["cancel"] = false;
+		output["error"] = "";
+		// sent successfully
+		if (!root["received"].asInt()) {
+			// everything sent
+			retval.type = print;
+			// TODO
+			//~ retval.msg = "succesfully uploaded file " + fileman.getPutName();
+			fileman.closePut();
+		} else {
+			retval.type = print | send;
+			retval.nextcommand = "putdata";
+		}
+	}
+	retval.msg = output;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
-  CmdRet retval;
-  Json::Value output;
-  output["command"] = "get";
-  output["file"] = fileman.getGetName();
-  output["accept"] = false;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  if (!root["accept"].asBool()) {
-    retval.type = error;
-    output["error"] = "Server reports: " + root["error"].asString();
-  } else if (root["file"].asString() != fileman.getGetName()) {
-    retval.type = error;
-    output["error"] = "Server reports filename " + root["file"].asString() +
-                      " but actual filename is " + fileman.getGetName();
-  } else {
-    fileman.setGetChunks(root["chunks"].asInt());
-    output["accept"] = true;
-    output["error"] = "";
-    retval.type = print | send;
-    retval.nextcommand = "getdata";
-  }
-  retval.msg = output;
-
-  return retval;
+	CmdRet retval;
+	Json::Value output;
+	output["command"] = "get";
+	output["file"] = fileman.getGetName();
+	output["accept"] = false;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	if (!root["accept"].asBool()) {
+		retval.type = error;
+		output["error"] = "Server reports: " + root["error"].asString();
+	} else if (root["file"].asString() != fileman.getGetName()) {
+		retval.type = error;
+		output["error"] = "Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getGetName();
+	} else {
+		fileman.setGetChunks(root["chunks"].asInt());
+		output["accept"] = true;
+		output["error"] = "";
+		retval.type = print | send;
+		retval.nextcommand = "getdata";
+	}
+	retval.msg = output;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
-  CmdRet retval;
-  Json::Value output;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  output["command"] = "getdata";
-  output["file"] = fileman.getGetName();
-  output["speed"] = 0.0f; // TODO
-  output["cancel"] = true;
-
-  // the passed number of recieved chunks should equal the number of sent chunks
-  if (root["remaining"].asInt() != fileman.getGetRemainingChunks()) {
-    retval.type = error;
-    output["error"] =
-        std::string("Server reports number of remaining chunks as ") +
-        std::to_string(root["remaining"].asInt()) + " but actual number is " +
-        std::to_string(fileman.getGetRemainingChunks());
-    fileman.cancelGet();
-  } else if (root["cancel"].asBool()) {
-    retval.type = error;
-    output["error"] = "Server reports: " + root["error"].asString();
-    fileman.cancelGet();
-  } else if (root["file"].asString() != fileman.getGetName()) {
-    retval.type = error;
-    output["error"] = "Server reports filename " + root["file"].asString() +
-                      " but actual filename is " + fileman.getGetName();
-    fileman.cancelGet();
-  } else {
-    output["cancel"] = false;
-    output["error"] = "";
-    fileman.writeBase64(root["data"].asString());
-    // loaded successfully
-    if (fileman.getGetRemainingChunks() < 0) {
-      // everything sent
-      retval.type = print;
-      //~ retval.msg = "succesfully downloaded file " + fileman.getGetName();
-      fileman.closeGet();
-    } else {
-      retval.type = print | send;
-      retval.nextcommand = "getdata";
-    }
-  }
-  retval.msg = output;
-  return retval;
+	CmdRet retval;
+	Json::Value output;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	output["command"] = "getdata";
+	output["file"] = fileman.getGetName();
+	output["speed"] = 0.0f; // TODO
+	output["cancel"] = true;
+
+	// the passed number of recieved chunks should equal the number of sent chunks
+	if (root["remaining"].asInt() != fileman.getGetRemainingChunks()) {
+		retval.type = error;
+		output["error"] = std::string("Server reports number of remaining chunks as ") + std::to_string(root["remaining"].asInt()) + " but actual number is " +
+		                  std::to_string(fileman.getGetRemainingChunks());
+		fileman.cancelGet();
+	} else if (root["cancel"].asBool()) {
+		retval.type = error;
+		output["error"] = "Server reports: " + root["error"].asString();
+		fileman.cancelGet();
+	} else if (root["file"].asString() != fileman.getGetName()) {
+		retval.type = error;
+		output["error"] = "Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getGetName();
+		fileman.cancelGet();
+	} else {
+		output["cancel"] = false;
+		output["error"] = "";
+		fileman.writeBase64(root["data"].asString());
+		// loaded successfully
+		if (fileman.getGetRemainingChunks() < 0) {
+			// everything sent
+			retval.type = print;
+			//~ retval.msg = "succesfully downloaded file " + fileman.getGetName();
+			fileman.closeGet();
+		} else {
+			retval.type = print | send;
+			retval.nextcommand = "getdata";
+		}
+	}
+	retval.msg = output;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
-  CmdRet retval;
-  Json::Value output; // LOCALOUTPUT
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  output["command"] = "list";
-  output["names"] = "";
-
-  if (!root["accept"].asBool()) {
-    retval.type = error;
-    output["accept"] = false;
-    output["error"] = "Server reports: " + root["error"].asString();
-    fileman.cancelList();
-  } else {
-    fileman.setListChunks(root["chunks"].asInt());
-    retval.type = send;
-    output["accept"] = true;
-    retval.nextcommand = "listdata";
-  }
-
-  retval.msg = output;
-  return retval;
+	CmdRet retval;
+	Json::Value output; // LOCALOUTPUT
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	output["command"] = "list";
+	output["names"] = "";
+
+	if (!root["accept"].asBool()) {
+		retval.type = error;
+		output["accept"] = false;
+		output["error"] = "Server reports: " + root["error"].asString();
+		fileman.cancelList();
+	} else {
+		fileman.setListChunks(root["chunks"].asInt());
+		retval.type = send;
+		output["accept"] = true;
+		retval.nextcommand = "listdata";
+	}
+
+	retval.msg = output;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleListdata(Json::Value root) {
-  CmdRet retval;
-  Json::Value output, arr;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-  vector<string> toadd;
-
-  output["command"] = "list";
-  output["names"] = "";
-  output["accept"] = false;
-  // the passed number of recieved chunks should equal the number of sent chunks
-  if (root["remaining"].asInt() != fileman.getListRemainingChunks()) {
-    retval.type = error;
-    output["error"] = std::string("Server reports number of "
-                                  "remaining chunks as ") +
-                      std::to_string(root["remaining"].asInt()) +
-                      " but actual number is " +
-                      std::to_string(fileman.getListRemainingChunks());
-    fileman.cancelList();
-  } else if (root["cancel"].asBool()) {
-    retval.type = error;
-    output["error"] = "Server reports: " + root["error"].asString();
-    fileman.cancelList();
-  } else {
-    output["accept"] = true;
-    for (Json::Value i : root["names"])
-      toadd.push_back(i.asString());
-    fileman.putListData(toadd);
-    // loaded successfully
-    if (fileman.getListRemainingChunks() < 0) {
-      // everything sent
-      retval.type = print;
-      for (string s : fileman.getListData())
-        arr.append(s);
-      output["names"] = arr;
-      fileman.closeList();
-    } else {
-      retval.type = send;
-      retval.nextcommand = "listdata";
-    }
-  }
-  retval.msg = output;
-  return retval;
+	CmdRet retval;
+	Json::Value output, arr;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+	vector<string> toadd;
+
+	output["command"] = "list";
+	output["names"] = "";
+	output["accept"] = false;
+	// the passed number of recieved chunks should equal the number of sent chunks
+	if (root["remaining"].asInt() != fileman.getListRemainingChunks()) {
+		retval.type = error;
+		output["error"] = std::string("Server reports number of "
+		                              "remaining chunks as ") +
+		                  std::to_string(root["remaining"].asInt()) + " but actual number is " + std::to_string(fileman.getListRemainingChunks());
+		fileman.cancelList();
+	} else if (root["cancel"].asBool()) {
+		retval.type = error;
+		output["error"] = "Server reports: " + root["error"].asString();
+		fileman.cancelList();
+	} else {
+		output["accept"] = true;
+		for (Json::Value i : root["names"])
+			toadd.push_back(i.asString());
+		fileman.putListData(toadd);
+		// loaded successfully
+		if (fileman.getListRemainingChunks() < 0) {
+			// everything sent
+			retval.type = print;
+			for (string s : fileman.getListData())
+				arr.append(s);
+			output["names"] = arr;
+			fileman.closeList();
+		} else {
+			retval.type = send;
+			retval.nextcommand = "listdata";
+		}
+	}
+	retval.msg = output;
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
-  CmdRet retval;
-  Json::Value output; // LOCALOUTPUT
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  output["command"] = "version";
-  output["serverversion"] = root["version"].asString();
-  output["clientversion"] = protocolVersion;
-
-  if (!root["accept"].asBool()) {
-    retval.type = error;
-    output["accept"] = false;
-  } else {
-    retval.type = print | seton;
-    output["accept"] = true;
-    doversion = false;
-    loginpossible = true;
-  }
-  retval.msg = output;
-
-  return retval;
+	CmdRet retval;
+	Json::Value output; // LOCALOUTPUT
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	output["command"] = "version";
+	output["serverversion"] = root["version"].asString();
+	output["clientversion"] = protocolVersion;
+
+	if (!root["accept"].asBool()) {
+		retval.type = error;
+		output["accept"] = false;
+	} else {
+		retval.type = print | seton;
+		output["accept"] = true;
+		doversion = false;
+		loginpossible = true;
+	}
+	retval.msg = output;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
-  CmdRet retval;
-  Json::Value output; // LOCALOUTPUT
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  output["command"] = "login";
-
-  if (!root["accept"].asBool()) {
-    retval.type = error;
-    output["error"] = root["error"].asString();
-    output["accept"] = false;
-    loginpossible = true;
-    dologin = false;
-  } else {
-    retval.type = print | seton;
-    output["error"] = "";
-    output["accept"] = true;
-    dologin = false;
-  }
-  retval.msg = output;
-
-  return retval;
+	CmdRet retval;
+	Json::Value output; // LOCALOUTPUT
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	output["command"] = "login";
+
+	if (!root["accept"].asBool()) {
+		retval.type = error;
+		output["error"] = root["error"].asString();
+		output["accept"] = false;
+		loginpossible = true;
+		dologin = false;
+	} else {
+		retval.type = print | seton;
+		output["error"] = "";
+		output["accept"] = true;
+		dologin = false;
+	}
+	retval.msg = output;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleSignup(Json::Value root) {
-  CmdRet retval;
-  Json::Value output; // LOCALOUTPUT
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  output["command"] = "signup";
-
-  if (!root["accept"].asBool()) {
-    retval.type = error;
-    output["error"] = root["error"].asString();
-    output["accept"] = false;
-    loginpossible = true;
-    dosignup = false;
-  } else {
-    retval.type = print | seton;
-    output["error"] = "";
-    output["accept"] = true;
-    dosignup = false;
-  }
-  retval.msg = output;
-
-  return retval;
+	CmdRet retval;
+	Json::Value output; // LOCALOUTPUT
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	output["command"] = "signup";
+
+	if (!root["accept"].asBool()) {
+		retval.type = error;
+		output["error"] = root["error"].asString();
+		output["accept"] = false;
+		loginpossible = true;
+		dosignup = false;
+	} else {
+		retval.type = print | seton;
+		output["error"] = "";
+		output["accept"] = true;
+		dosignup = false;
+	}
+	retval.msg = output;
+
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleHead(Json::Value root) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  if (!root["accept"].asBool()) {
-    Json::Value output;
-    output["command"] = "head";
-    output["file"] = root["file"];
-    output["error"] = "Server reports: " + root["error"].asString();
-    retval.type = error;
-    retval.msg = output;
-  } else {
-    retval.type = print;
-    retval.msg = root;
-  }
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	if (!root["accept"].asBool()) {
+		Json::Value output;
+		output["command"] = "head";
+		output["file"] = root["file"];
+		output["error"] = "Server reports: " + root["error"].asString();
+		retval.type = error;
+		retval.msg = output;
+	} else {
+		retval.type = print;
+		retval.msg = root;
+	}
+	return retval;
 }
 
 CmdMan::CmdRet CmdMan::handleDeleteme(Json::Value root) {
-  CmdRet retval;
-  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
-
-  if (!root["accept"].asBool()) {
-    retval.type = error;
-  } else {
-    retval.type = close | print;
-  }
-  retval.msg = root;
-  return retval;
+	CmdRet retval;
+	DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+	if (!root["accept"].asBool()) {
+		retval.type = error;
+	} else {
+		retval.type = close | print;
+	}
+	retval.msg = root;
+	return retval;
 }

+ 80 - 83
cli/src/fileman.cpp

@@ -4,9 +4,9 @@
 FileMan::FileMan() { islisting = false; }
 
 FileMan::~FileMan() {
-  cancelGet();
-  cancelPut();
-  cancelList();
+	cancelGet();
+	cancelPut();
+	cancelList();
 }
 
 bool FileMan::isGetting() { return getfile.is_open(); }
@@ -16,40 +16,40 @@ bool FileMan::isPutting() { return putfile.is_open(); }
 bool FileMan::isListing() { return islisting; }
 
 bool FileMan::openPut(const std::string &path) {
-  putpath = path;
-  putname = pathToFilename(path);
-  putfile.open(path, std::ios::ate | std::ios::binary);
-  if (putfile.is_open()) {
-    size_t size = putfile.tellg();
-    putsize = size;
-    putchunks = size / max_read_len + ((size % max_read_len) ? 1 : 0);
-    putchunksRemaining = putchunks;
-    putfile.seekg(std::ios::beg);
-    return true;
-  }
-  return false;
+	putpath = path;
+	putname = pathToFilename(path);
+	putfile.open(path, std::ios::ate | std::ios::binary);
+	if (putfile.is_open()) {
+		size_t size = putfile.tellg();
+		putsize = size;
+		putchunks = size / max_read_len + ((size % max_read_len) ? 1 : 0);
+		putchunksRemaining = putchunks;
+		putfile.seekg(std::ios::beg);
+		return true;
+	}
+	return false;
 }
 
 bool FileMan::openGet(const std::string &path) {
-  getpath = path;
-  getname = pathToFilename(path);
-  getchunks = 0;
-  getchunksRemaining = 0;
-  getfile.open(path, std::ios::app | std::ios::binary);
-  if (getfile.tellp() != std::ios::beg) {
-    closeGet();
-    return false;
-  }
-  return true;
+	getpath = path;
+	getname = pathToFilename(path);
+	getchunks = 0;
+	getchunksRemaining = 0;
+	getfile.open(path, std::ios::app | std::ios::binary);
+	if (getfile.tellp() != std::ios::beg) {
+		closeGet();
+		return false;
+	}
+	return true;
 }
 
 bool FileMan::openList() {
-  if (isListing()) {
-    return false;
-  }
-  listdata = std::vector<std::string>();
-  islisting = true;
-  return true;
+	if (isListing()) {
+		return false;
+	}
+	listdata = std::vector<std::string>();
+	islisting = true;
+	return true;
 }
 
 void FileMan::closePut() { putfile.close(); }
@@ -59,36 +59,34 @@ void FileMan::closeGet() { getfile.close(); }
 void FileMan::closeList() { islisting = false; }
 
 void FileMan::cancelPut() {
-  if (isPutting()) {
-    closePut();
-  }
+	if (isPutting()) {
+		closePut();
+	}
 }
 
 void FileMan::cancelGet() {
-  if (isGetting()) {
-    closeGet();
-    std::remove(getname.c_str());
-  }
+	if (isGetting()) {
+		closeGet();
+		std::remove(getname.c_str());
+	}
 }
 
 void FileMan::cancelList() {
-  if (isListing()) {
-    closeList();
-  }
+	if (isListing()) {
+		closeList();
+	}
 }
 
 void FileMan::writeGet(const std::vector<char> data) {
-  getfile.write(data.data(), data.size());
-  getchunksRemaining--;
+	getfile.write(data.data(), data.size());
+	getchunksRemaining--;
 }
 
-void FileMan::writeBase64(std::string data) {
-  writeGet(base64::decodeVector(data));
-}
+void FileMan::writeBase64(std::string data) { writeGet(base64::decodeVector(data)); }
 
 void FileMan::putListData(std::vector<std::string> names) {
-  listdata.insert(listdata.end(), names.begin(), names.end());
-  listchunksRemaining--;
+	listdata.insert(listdata.end(), names.begin(), names.end());
+	listchunksRemaining--;
 }
 
 std::vector<std::string> FileMan::getListData() { return listdata; }
@@ -98,30 +96,30 @@ int FileMan::getGetChunks() { return getchunks; }
 int FileMan::getGetRemainingChunks() { return getchunksRemaining; }
 
 void FileMan::setGetChunks(int chunks) {
-  getchunks = chunks;
-  getchunksRemaining = chunks - 1;
+	getchunks = chunks;
+	getchunksRemaining = chunks - 1;
 }
 
 void FileMan::setListChunks(int chunks) {
-  listchunks = chunks;
-  listchunksRemaining = chunks - 1;
+	listchunks = chunks;
+	listchunksRemaining = chunks - 1;
 }
 
 std::vector<char> FileMan::readPut() {
-  char buf[max_read_len];
-  std::vector<char> data;
-
-  std::streamoff read = this->putfile.tellg();
-  if (read + max_read_len > this->putsize) {
-    read = this->putsize % max_read_len;
-  } else {
-    read = max_read_len;
-  }
-
-  putfile.read(buf, read);
-  data.assign(buf, buf + read);
-  putchunksRemaining--;
-  return data;
+	char buf[max_read_len];
+	std::vector<char> data;
+
+	std::streamoff read = this->putfile.tellg();
+	if (read + max_read_len > this->putsize) {
+		read = this->putsize % max_read_len;
+	} else {
+		read = max_read_len;
+	}
+
+	putfile.read(buf, read);
+	data.assign(buf, buf + read);
+	putchunksRemaining--;
+	return data;
 }
 
 std::string FileMan::readBase64() { return base64::encodeVector(readPut()); }
@@ -142,26 +140,25 @@ int FileMan::getListChunks() { return listchunks; }
 
 std::string FileMan::pathToFilename(std::string path) {
 
-  int lastFoundIndex = -1;
+	int lastFoundIndex = -1;
 
-  for (int currentIndex = path.find("/"); currentIndex != std::string::npos;
-       currentIndex = path.find("/", currentIndex + 1)) {
+	for (int currentIndex = path.find("/"); currentIndex != std::string::npos; currentIndex = path.find("/", currentIndex + 1)) {
 
-    // check if the "/" was escaped
-    if (currentIndex > 0 && path[currentIndex - 1] == '\\')
-      continue;
+		// check if the "/" was escaped
+		if (currentIndex > 0 && path[currentIndex - 1] == '\\')
+			continue;
 
-    /*  // check unnecessary, because error occurs when trying to open file
-       anyways
+		/*  // check unnecessary, because error occurs when trying to open file
+		   anyways
 
-        // check if the "/" is at the end of path name
-        if (currentIndex + 1 == path.length()) {
-          // ERROR: INVALID FILENAME, BECAUSE ENDS WITH "/"
-        }
-    */
-    // otherwise we found a valid "/"
-    lastFoundIndex = currentIndex;
-  }
+		    // check if the "/" is at the end of path name
+		    if (currentIndex + 1 == path.length()) {
+		      // ERROR: INVALID FILENAME, BECAUSE ENDS WITH "/"
+		    }
+		*/
+		// otherwise we found a valid "/"
+		lastFoundIndex = currentIndex;
+	}
 
-  return path.substr(lastFoundIndex + 1);
+	return path.substr(lastFoundIndex + 1);
 }

+ 454 - 488
cli/src/ioman.cpp

@@ -23,535 +23,501 @@ using boost::asio::ip::tcp;
 /* this will be provided by main.cpp for the readline callback */
 extern IoMan *gIOMAN;
 
-void ioman_externalDebugPrint(string msg) {
-  gIOMAN->printMessage(msg, gIOMAN->OutMsgType::debug);
-}
+void ioman_externalDebugPrint(string msg) { gIOMAN->printMessage(msg, gIOMAN->OutMsgType::debug); }
 
 IoMan::IoMan(char *ipcstring) : cmdman(fileman, &ioman_externalDebugPrint) {
-  ipstring = std::string(ipcstring);
-  port = 1234;
-  tcpsock = new tcp::socket(ios);
-  connected = false;
-
-  /* to be put elsewhere */
-
-  /* setup json stuff */
-  Json::CharReaderBuilder rbuilder;
-  wbuilder.settings_["indentation"] = "";
-  reader = rbuilder.newCharReader();
-  runnetwork = false;
-  runinput = false;
-  runresponse = false;
-  versionstatus = off;
-  loginstatus = off;
+	ipstring = std::string(ipcstring);
+	port = 1234;
+	tcpsock = new tcp::socket(ios);
+	connected = false;
+
+	/* to be put elsewhere */
+
+	/* setup json stuff */
+	Json::CharReaderBuilder rbuilder;
+	wbuilder.settings_["indentation"] = "";
+	reader = rbuilder.newCharReader();
+	runnetwork = false;
+	runinput = false;
+	runresponse = false;
+	versionstatus = off;
+	loginstatus = off;
 }
 
 IoMan::~IoMan() {
-  initcv.notify_all();
-  if (runnetwork) {
-    networkmutex.lock();
-    runnetwork = false;
-    networkmutex.unlock();
-    tnetwork.join();
-  }
-  if (runinput) {
-    inputmutex.lock();
-    runinput = false;
-    inputmutex.unlock();
-    localcv.notify_all();
-    tinput.join();
-  }
-  if (runresponse) {
-    responsemutex.lock();
-    runresponse = false;
-    responsemutex.unlock();
-    netcv.notify_all();
-    tresponse.join();
-  }
-
-  if (connected) {
-    disconnect();
-  }
-
-  delete tcpsock;
-  delete reader;
+	initcv.notify_all();
+	if (runnetwork) {
+		networkmutex.lock();
+		runnetwork = false;
+		networkmutex.unlock();
+		tnetwork.join();
+	}
+	if (runinput) {
+		inputmutex.lock();
+		runinput = false;
+		inputmutex.unlock();
+		localcv.notify_all();
+		tinput.join();
+	}
+	if (runresponse) {
+		responsemutex.lock();
+		runresponse = false;
+		responsemutex.unlock();
+		netcv.notify_all();
+		tresponse.join();
+	}
+
+	if (connected) {
+		disconnect();
+	}
+
+	delete tcpsock;
+	delete reader;
 }
 
 void IoMan::printMessage(string nouse, OutMsgType nouse2) {}
 
 vector<string> IoMan::tokenizeInput(string in) {
-  size_t prev, index, quot;
-  vector<string> args;
-  /* tokenize string into command and arguments vector*/
-  if ((index = in.find(" ")) == string::npos) {
-    // only command no args
-    args.push_back(in);
-  } else {
-    args.push_back(in.substr(0, index));
-    index++;
-
-    bool end_tokenizing = false;
-    while (!end_tokenizing) {
-      // find first char thats not a space
-      while (in[index] == ' ') {
-        index++;
-
-        // bounds check
-        if (index == in.size())
-          end_tokenizing = true;
-      }
-      if (end_tokenizing)
-        break;
-
-      in = in.substr(index);
-
-      if (in[0] == '\"') {
-        // quoted string
-        in = in.substr(1);
-        index = in.find("\"");
-        args.push_back(in.substr(0, index));
-        index++;
-
-        /*
-        tokens.push_back(in.substr(0, ++index));
-        */
-
-        // char after closing quote should be space while within bounds
-        if (index == in.size())
-          end_tokenizing = true;
-      } else {
-        // non-quoted string
-        index = in.find(" ");
-        if (index == string::npos) { // no spaces, last arg
-          args.push_back(in);
-          end_tokenizing = true;
-        } else {
-          args.push_back(in.substr(0, index));
-        }
-      }
-    }
-  }
-  return args;
+	size_t prev, index, quot;
+	vector<string> args;
+	/* tokenize string into command and arguments vector*/
+	if ((index = in.find(" ")) == string::npos) {
+		// only command no args
+		args.push_back(in);
+	} else {
+		args.push_back(in.substr(0, index));
+		index++;
+
+		bool end_tokenizing = false;
+		while (!end_tokenizing) {
+			// find first char thats not a space
+			while (in[index] == ' ') {
+				index++;
+
+				// bounds check
+				if (index == in.size())
+					end_tokenizing = true;
+			}
+			if (end_tokenizing)
+				break;
+
+			in = in.substr(index);
+
+			if (in[0] == '\"') {
+				// quoted string
+				in = in.substr(1);
+				index = in.find("\"");
+				args.push_back(in.substr(0, index));
+				index++;
+
+				/*
+				tokens.push_back(in.substr(0, ++index));
+				*/
+
+				// char after closing quote should be space while within bounds
+				if (index == in.size())
+					end_tokenizing = true;
+			} else {
+				// non-quoted string
+				index = in.find(" ");
+				if (index == string::npos) { // no spaces, last arg
+					args.push_back(in);
+					end_tokenizing = true;
+				} else {
+					args.push_back(in.substr(0, index));
+				}
+			}
+		}
+	}
+	return args;
 }
 
 bool IoMan::connect() {
-  tcp::endpoint *ep = NULL;
-  address addr;
-  Json::Value root;
-  root["command"] = "connect";
-  root["address"] = ipstring;
-  root["port"] = port;
-  addr = address::from_string(ipstring, errcode);
-  if (errcode) {
-    root["error"] = errcode.message();
-    connected = false;
-  } else {
-    // establish connection
-    printMessage("IoMan::connect() connecting to " + ipstring, debug);
-    ep = new tcp::endpoint(addr, port);
-    tcpsock->connect(*ep, errcode);
-    if (errcode) {
-      root["error"] = errcode.message();
-      connected = false;
-    } else {
-      connected = true;
-      root["error"] = "";
-    }
-    delete ep;
-  }
-  root["accept"] = connected;
-  printMessage(Json::writeString(wbuilder, root), normal);
-  return connected;
+	tcp::endpoint *ep = NULL;
+	address addr;
+	Json::Value root;
+	root["command"] = "connect";
+	root["address"] = ipstring;
+	root["port"] = port;
+	addr = address::from_string(ipstring, errcode);
+	if (errcode) {
+		root["error"] = errcode.message();
+		connected = false;
+	} else {
+		// establish connection
+		printMessage("IoMan::connect() connecting to " + ipstring, debug);
+		ep = new tcp::endpoint(addr, port);
+		tcpsock->connect(*ep, errcode);
+		if (errcode) {
+			root["error"] = errcode.message();
+			connected = false;
+		} else {
+			connected = true;
+			root["error"] = "";
+		}
+		delete ep;
+	}
+	root["accept"] = connected;
+	printMessage(Json::writeString(wbuilder, root), normal);
+	return connected;
 }
 
 void IoMan::disconnect() {
-  printMessage("IoMan::disconnect()", debug);
-  tcpsock->close();
-  connected = false;
+	printMessage("IoMan::disconnect()", debug);
+	tcpsock->close();
+	connected = false;
 }
 
 bool IoMan::init() {
-  CmdMan::CmdRet ret;
-  string work;
-  Json::Value root;
-  std::unique_lock<std::mutex> ulock;
-
-  printMessage("IoMan::Init() begin", debug);
-
-  if (!connect())
-    return false;
-
-  printMessage("IoMan::Init() versioncheck", debug);
-
-  localmutex.lock();
-  printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), debug);
-  localinput.push_back("version " + protocolVersion);
-  localmutex.unlock();
-  printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"),
-               debug);
-  localcv.notify_all();
-
-  printMessage("IoMan::Init() begin", debug);
-
-  runnetwork = true;
-  runinput = true;
-  runresponse = true;
-
-  tnetwork = std::thread(&IoMan::networkMain, this);
-  tinput = std::thread(&IoMan::inputMain, this);
-  tresponse = std::thread(&IoMan::responseMain, this);
-
-  ulock = std::unique_lock<std::mutex>(initmutex);
-  while (versionstatus == off) {
-    initcv.wait(ulock);
-  }
-  if (versionstatus == err) {
-    runnetwork = false;
-    runinput = false;
-    runresponse = false;
-    return false;
-  }
-  initmutex.unlock();
-  initcv.notify_all();
-
-  printWelcomeMessage();
-  return true;
+	CmdMan::CmdRet ret;
+	string work;
+	Json::Value root;
+	std::unique_lock<std::mutex> ulock;
+
+	printMessage("IoMan::Init() begin", debug);
+
+	if (!connect())
+		return false;
+
+	printMessage("IoMan::Init() versioncheck", debug);
+
+	localmutex.lock();
+	printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), debug);
+	localinput.push_back("version " + protocolVersion);
+	localmutex.unlock();
+	printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
+	localcv.notify_all();
+
+	printMessage("IoMan::Init() begin", debug);
+
+	runnetwork = true;
+	runinput = true;
+	runresponse = true;
+
+	tnetwork = std::thread(&IoMan::networkMain, this);
+	tinput = std::thread(&IoMan::inputMain, this);
+	tresponse = std::thread(&IoMan::responseMain, this);
+
+	ulock = std::unique_lock<std::mutex>(initmutex);
+	while (versionstatus == off) {
+		initcv.wait(ulock);
+	}
+	if (versionstatus == err) {
+		runnetwork = false;
+		runinput = false;
+		runresponse = false;
+		return false;
+	}
+	initmutex.unlock();
+	initcv.notify_all();
+
+	printWelcomeMessage();
+	return true;
 }
 
 /* loop to fetch data from the network, doing light preprocessing on it to be
  * handled by responseMain */
 void IoMan::networkMain() {
-  vector<Json::Value> toput;
-  char *recvjson;
-  Json::Value root;
-  unsigned int jsonsize, readsize;
-
-  printMessage("IoMan::networkMain() begin", debug);
-  networkmutex.lock();
-  while (runnetwork) {
-    networkmutex.unlock();
-    /*
-    read from network until \n
-    try to parse json
-    - output error if not ok
-    store all ok json in local vector
-
-    get networkmutex
-    put all local jsons into network vector
-    release networkmutex
-    */
-
-    // read from network
-    readsize = boost::asio::read_until(*tcpsock, recvbuf, '\n', errcode);
-    printMessage(string(__PRETTY_FUNCTION__) + string(" asio::read() ok ") +
-                     std::to_string(readsize),
-                 debug);
-    // printMessage(string("have ") + std::to_string(toprocess.size()) +
-    // string(" commands"), debug);
-    if (errcode && errcode != boost::asio::error::eof) {
-      printMessage("IoMan::networkMain() couldnt read json data\n" +
-                       errcode.message(),
-                   error);
-      continue;
-    }
-    if (!readsize)
-      break;
-    recvjson = (char *)(boost::asio::buffer_cast<const char *>(recvbuf.data()));
-    recvjson[readsize] = 0;
-    while (strchr(recvjson, '\n')) {
-      // parse
-      jsonsize = strchr(recvjson, '\n') - recvjson + 1;
-
-      printMessage(string(__PRETTY_FUNCTION__) + string(" found jsondata ") +
-                       string(recvjson),
-                   debug);
-
-      if (!reader->parse(recvjson, recvjson + jsonsize, &root, &jsonerror)) {
-        printMessage("IoMan::networkMain() couldnt parse json data: " +
-                         jsonerror,
-                     error);
-        recvbuf.consume(jsonsize);
-        continue;
-      }
-      recvbuf.consume(jsonsize);
-      readsize -= jsonsize;
-
-      printMessage(
-          string(__PRETTY_FUNCTION__) + string(" remaining recvbuf ") +
-              string(boost::asio::buffer_cast<const char *>(recvbuf.data())),
-          debug);
-
-      for (int i = 0; i < jsonsize; i++)
-        recvjson++;
-      // store locally
-      toput.push_back(root);
-    }
-
-    if (toput.size()) {
-      // put into global vector
-      netmutex.lock();
-      printMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"),
-                   debug);
-      netinput.insert(netinput.end(), toput.begin(), toput.end());
-      netmutex.unlock();
-      printMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"),
-                   debug);
-    }
-    netcv.notify_all();
-
-    // clean up local stuff
-    toput = vector<Json::Value>();
-    recvbuf.consume(readsize);
-    networkmutex.lock();
-  }
+	vector<Json::Value> toput;
+	char *recvjson;
+	Json::Value root;
+	unsigned int jsonsize, readsize;
+
+	printMessage("IoMan::networkMain() begin", debug);
+	networkmutex.lock();
+	while (runnetwork) {
+		networkmutex.unlock();
+		/*
+		read from network until \n
+		try to parse json
+		- output error if not ok
+		store all ok json in local vector
+
+		get networkmutex
+		put all local jsons into network vector
+		release networkmutex
+		*/
+
+		// read from network
+		readsize = boost::asio::read_until(*tcpsock, recvbuf, '\n', errcode);
+		printMessage(string(__PRETTY_FUNCTION__) + string(" asio::read() ok ") + std::to_string(readsize), debug);
+		// printMessage(string("have ") + std::to_string(toprocess.size()) +
+		// string(" commands"), debug);
+		if (errcode && errcode != boost::asio::error::eof) {
+			printMessage("IoMan::networkMain() couldnt read json data\n" + errcode.message(), error);
+			continue;
+		}
+		if (!readsize)
+			break;
+		recvjson = (char *)(boost::asio::buffer_cast<const char *>(recvbuf.data()));
+		recvjson[readsize] = 0;
+		while (strchr(recvjson, '\n')) {
+			// parse
+			jsonsize = strchr(recvjson, '\n') - recvjson + 1;
+
+			printMessage(string(__PRETTY_FUNCTION__) + string(" found jsondata ") + string(recvjson), debug);
+
+			if (!reader->parse(recvjson, recvjson + jsonsize, &root, &jsonerror)) {
+				printMessage("IoMan::networkMain() couldnt parse json data: " + jsonerror, error);
+				recvbuf.consume(jsonsize);
+				continue;
+			}
+			recvbuf.consume(jsonsize);
+			readsize -= jsonsize;
+
+			printMessage(string(__PRETTY_FUNCTION__) + string(" remaining recvbuf ") + string(boost::asio::buffer_cast<const char *>(recvbuf.data())), debug);
+
+			for (int i = 0; i < jsonsize; i++)
+				recvjson++;
+			// store locally
+			toput.push_back(root);
+		}
+
+		if (toput.size()) {
+			// put into global vector
+			netmutex.lock();
+			printMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"), debug);
+			netinput.insert(netinput.end(), toput.begin(), toput.end());
+			netmutex.unlock();
+			printMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"), debug);
+		}
+		netcv.notify_all();
+
+		// clean up local stuff
+		toput = vector<Json::Value>();
+		recvbuf.consume(readsize);
+		networkmutex.lock();
+	}
 }
 
 /* loop to handle input from the user and responseMain, sending data via network
  * if required */
 void IoMan::inputMain() {
-  vector<string> toprocess;
-  string command;
-  vector<string> args;
-  CmdMan::CmdRet cmdret;
-  std::unique_lock<std::mutex> ulock;
-
-  printMessage("IoMan::inputMain() begin", debug);
-  inputmutex.lock();
-  while (runinput) {
-    inputmutex.unlock();
-    /*
-    get inputmutex
-    read all input vector into local vector
-    release inputmutex
-
-    process inputs
-    send to server if required
-    */
-
-    // read into local vector
-    ulock = std::unique_lock<std::mutex>(localmutex);
-    while (!localinput.size() && runinput) {
-      localcv.wait(ulock);
-    }
-    printMessage(string(__PRETTY_FUNCTION__) + string(" has localmutex"),
-                 debug);
-    toprocess = vector<string>(localinput);
-    localinput = vector<string>();
-    localmutex.unlock();
-    printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"),
-                 debug);
-    localcv.notify_all();
-
-    if (!runinput)
-      return;
-
-    // printMessage(string("have ") + std::to_string(toprocess.size()) +
-    // string(" commands"), debug);
-
-    // process
-    for (string cmd : toprocess) {
-      args = tokenizeInput(cmd);
-      command = args.front();
-      args.erase(args.begin());
-      cmdret = cmdman.execute(command, args);
-
-      // determine wether to send something and do so if required
-      if (cmdret.type & CmdMan::rettype::print) {
-        printMessage(Json::writeString(wbuilder, cmdret.msg), normal);
-      }
-      if (cmdret.type & CmdMan::rettype::send) {
-        printMessage("IoMan::inputMain() sending json \"" +
-                         Json::writeString(wbuilder, cmdret.msg) + "\"",
-                     debug);
-        boost::asio::write(
-            *tcpsock, buffer(Json::writeString(wbuilder, cmdret.msg) + "\n"),
-            errcode);
-        if (errcode) {
-          printMessage("IoMan::inputMain() couldnt send json data\n" +
-                           errcode.message() + "\n",
-                       error);
-          continue;
-        }
-      }
-      if (cmdret.type & CmdMan::rettype::error) {
-        printMessage(Json::writeString(wbuilder, cmdret.msg), error);
-      }
-      if (cmdret.type & CmdMan::rettype::close) {
-        /* TODO i dunno */
-        mainmutex.lock();
-        runmain = false;
-        mainmutex.unlock();
-      }
-    }
-
-    // clean up local stuff
-    toprocess = vector<string>();
-    inputmutex.lock();
-  }
+	vector<string> toprocess;
+	string command;
+	vector<string> args;
+	CmdMan::CmdRet cmdret;
+	std::unique_lock<std::mutex> ulock;
+
+	printMessage("IoMan::inputMain() begin", debug);
+	inputmutex.lock();
+	while (runinput) {
+		inputmutex.unlock();
+		/*
+		get inputmutex
+		read all input vector into local vector
+		release inputmutex
+
+		process inputs
+		send to server if required
+		*/
+
+		// read into local vector
+		ulock = std::unique_lock<std::mutex>(localmutex);
+		while (!localinput.size() && runinput) {
+			localcv.wait(ulock);
+		}
+		printMessage(string(__PRETTY_FUNCTION__) + string(" has localmutex"), debug);
+		toprocess = vector<string>(localinput);
+		localinput = vector<string>();
+		localmutex.unlock();
+		printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
+		localcv.notify_all();
+
+		if (!runinput)
+			return;
+
+		// printMessage(string("have ") + std::to_string(toprocess.size()) +
+		// string(" commands"), debug);
+
+		// process
+		for (string cmd : toprocess) {
+			args = tokenizeInput(cmd);
+			command = args.front();
+			args.erase(args.begin());
+			cmdret = cmdman.execute(command, args);
+
+			// determine wether to send something and do so if required
+			if (cmdret.type & CmdMan::rettype::print) {
+				printMessage(Json::writeString(wbuilder, cmdret.msg), normal);
+			}
+			if (cmdret.type & CmdMan::rettype::send) {
+				printMessage("IoMan::inputMain() sending json \"" + Json::writeString(wbuilder, cmdret.msg) + "\"", debug);
+				boost::asio::write(*tcpsock, buffer(Json::writeString(wbuilder, cmdret.msg) + "\n"), errcode);
+				if (errcode) {
+					printMessage("IoMan::inputMain() couldnt send json data\n" + errcode.message() + "\n", error);
+					continue;
+				}
+			}
+			if (cmdret.type & CmdMan::rettype::error) {
+				printMessage(Json::writeString(wbuilder, cmdret.msg), error);
+			}
+			if (cmdret.type & CmdMan::rettype::close) {
+				/* TODO i dunno */
+				mainmutex.lock();
+				runmain = false;
+				mainmutex.unlock();
+			}
+		}
+
+		// clean up local stuff
+		toprocess = vector<string>();
+		inputmutex.lock();
+	}
 }
 
 /* loop to handle responses that have been fetched by netMain and possibly add
  * new commands to be handled by inputMain */
 void IoMan::responseMain() {
-  vector<Json::Value> toprocess;
-  vector<string> toput;
-  CmdMan::CmdRet cmdret;
-  std::unique_lock<std::mutex> ulock;
-
-  printMessage("IoMan::responseMain() begin", debug);
-  responsemutex.lock();
-  while (runresponse) {
-    responsemutex.unlock();
-    /*
-    get networkmutex
-    read all network vector into local vector
-    release networkmutex
-
-    process all jsons
-    process putdata
-    process getdata
-    process listdata
-
-    get inputmutex
-    place new commands into input vector
-    release inputmutex
-    */
-
-    // read into local vector
-    ulock = std::unique_lock<std::mutex>(netmutex);
-    while (!netinput.size() && runresponse) {
-      netcv.wait(ulock);
-    }
-    printMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"), debug);
-    toprocess = vector<Json::Value>(netinput);
-    netinput = vector<Json::Value>();
-    netmutex.unlock();
-    printMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"),
-                 debug);
-    netcv.notify_all();
-
-    if (!runresponse)
-      return;
-
-    // process jsons
-    for (Json::Value root : toprocess) {
-      cmdret = cmdman.handle(root);
-      if (cmdret.type & CmdMan::rettype::close) {
-        /* TODO i dunno */
-        mainmutex.lock();
-        runmain = false;
-        mainmutex.unlock();
-      }
-      if (cmdret.type & CmdMan::rettype::error) {
-        initmutex.lock();
-        if (versionstatus == off)
-          versionstatus = err;
-        else if (loginstatus == off)
-          loginstatus = err;
-        initmutex.unlock();
-        initcv.notify_all();
-        printMessage(Json::writeString(wbuilder, cmdret.msg), error);
-      }
-      if (cmdret.type & CmdMan::rettype::seton) {
-        initmutex.lock();
-        if (versionstatus == off)
-          versionstatus = on;
-        else
-          loginstatus = on;
-        initmutex.unlock();
-        initcv.notify_all();
-      }
-      if (cmdret.type & CmdMan::rettype::print) {
-        printMessage(Json::writeString(wbuilder, cmdret.msg), normal);
-      }
-      if (cmdret.type & CmdMan::rettype::send) {
-        if (cmdret.nextcommand.size()) {
-          toput.push_back(cmdret.nextcommand);
-        }
-      }
-    }
-
-    if (toput.size()) {
-      // put new commands into global vector
-      localmutex.lock();
-      printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"),
-                   debug);
-      localinput.insert(localinput.end(), toput.begin(), toput.end());
-      localmutex.unlock();
-      printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"),
-                   debug);
-    }
-    localcv.notify_all();
-
-    // clean up local stuff
-    toprocess = vector<Json::Value>();
-    toput = vector<string>();
-    responsemutex.lock();
-  }
+	vector<Json::Value> toprocess;
+	vector<string> toput;
+	CmdMan::CmdRet cmdret;
+	std::unique_lock<std::mutex> ulock;
+
+	printMessage("IoMan::responseMain() begin", debug);
+	responsemutex.lock();
+	while (runresponse) {
+		responsemutex.unlock();
+		/*
+		get networkmutex
+		read all network vector into local vector
+		release networkmutex
+
+		process all jsons
+		process putdata
+		process getdata
+		process listdata
+
+		get inputmutex
+		place new commands into input vector
+		release inputmutex
+		*/
+
+		// read into local vector
+		ulock = std::unique_lock<std::mutex>(netmutex);
+		while (!netinput.size() && runresponse) {
+			netcv.wait(ulock);
+		}
+		printMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"), debug);
+		toprocess = vector<Json::Value>(netinput);
+		netinput = vector<Json::Value>();
+		netmutex.unlock();
+		printMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"), debug);
+		netcv.notify_all();
+
+		if (!runresponse)
+			return;
+
+		// process jsons
+		for (Json::Value root : toprocess) {
+			cmdret = cmdman.handle(root);
+			if (cmdret.type & CmdMan::rettype::close) {
+				/* TODO i dunno */
+				mainmutex.lock();
+				runmain = false;
+				mainmutex.unlock();
+			}
+			if (cmdret.type & CmdMan::rettype::error) {
+				initmutex.lock();
+				if (versionstatus == off)
+					versionstatus = err;
+				else if (loginstatus == off)
+					loginstatus = err;
+				initmutex.unlock();
+				initcv.notify_all();
+				printMessage(Json::writeString(wbuilder, cmdret.msg), error);
+			}
+			if (cmdret.type & CmdMan::rettype::seton) {
+				initmutex.lock();
+				if (versionstatus == off)
+					versionstatus = on;
+				else
+					loginstatus = on;
+				initmutex.unlock();
+				initcv.notify_all();
+			}
+			if (cmdret.type & CmdMan::rettype::print) {
+				printMessage(Json::writeString(wbuilder, cmdret.msg), normal);
+			}
+			if (cmdret.type & CmdMan::rettype::send) {
+				if (cmdret.nextcommand.size()) {
+					toput.push_back(cmdret.nextcommand);
+				}
+			}
+		}
+
+		if (toput.size()) {
+			// put new commands into global vector
+			localmutex.lock();
+			printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), debug);
+			localinput.insert(localinput.end(), toput.begin(), toput.end());
+			localmutex.unlock();
+			printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
+		}
+		localcv.notify_all();
+
+		// clean up local stuff
+		toprocess = vector<Json::Value>();
+		toput = vector<string>();
+		responsemutex.lock();
+	}
 }
 
 /* this is the handler that readlines alternative interface will use to process
  * user input */
 void ioman_readlineHandler(char *line) {
-  vector<string> tokens;
-  if (!line) {
-    printf("\nNULLBURGER\n");
-    gIOMAN->mainmutex.lock();
-    gIOMAN->runmain = false;
-    gIOMAN->mainmutex.unlock();
-  } else {
-    // split input line into tokens
-    boost::algorithm::split(tokens, std::string(line),
-                            boost::algorithm::is_any_of(" "),
-                            boost::algorithm::token_compress_on);
-    if (strlen(line) && tokens.size()) {
-      add_history(line);
-
-      gIOMAN->localmutex.lock();
-      gIOMAN->printMessage(string(__PRETTY_FUNCTION__) +
-                               string(" get localmutex"),
-                           gIOMAN->debug);
-      gIOMAN->localinput.push_back(line);
-      gIOMAN->localmutex.unlock();
-      gIOMAN->printMessage(string(__PRETTY_FUNCTION__) +
-                               string(" release localmutex"),
-                           gIOMAN->debug);
-      gIOMAN->localcv.notify_all();
-    }
-    free(line);
-  }
+	vector<string> tokens;
+	if (!line) {
+		printf("\nNULLBURGER\n");
+		gIOMAN->mainmutex.lock();
+		gIOMAN->runmain = false;
+		gIOMAN->mainmutex.unlock();
+	} else {
+		// split input line into tokens
+		boost::algorithm::split(tokens, std::string(line), boost::algorithm::is_any_of(" "), boost::algorithm::token_compress_on);
+		if (strlen(line) && tokens.size()) {
+			add_history(line);
+
+			gIOMAN->localmutex.lock();
+			gIOMAN->printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), gIOMAN->debug);
+			gIOMAN->localinput.push_back(line);
+			gIOMAN->localmutex.unlock();
+			gIOMAN->printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), gIOMAN->debug);
+			gIOMAN->localcv.notify_all();
+		}
+		free(line);
+	}
 }
 
 /* main user input loop */
 void IoMan::run() {
-  printMessage("IoMan::run() begin", debug);
-  struct pollfd inPipeStatus;
-  inPipeStatus.fd = STDIN_FILENO;
-  inPipeStatus.events = POLLIN;
-
-  runmain = true;
-
-  // Install readline handler
-  rl_callback_handler_install(getCmdPrompt().c_str(),
-                              (rl_vcpfunc_t *)&ioman_readlineHandler);
-
-  mainmutex.lock();
-  while (runmain) {
-    mainmutex.unlock();
-
-    poll(&inPipeStatus, 1, 100);
-
-    if (inPipeStatus.revents & POLLIN) {
-      rl_callback_read_char();
-    }
-    if (!connected)
-      break;
-    if (loginstatus == err)
-      break;
-    mainmutex.lock();
-  }
-  mainmutex.unlock();
-
-  // Remove the handler
-  rl_callback_handler_remove();
+	printMessage("IoMan::run() begin", debug);
+	struct pollfd inPipeStatus;
+	inPipeStatus.fd = STDIN_FILENO;
+	inPipeStatus.events = POLLIN;
+
+	runmain = true;
+
+	// Install readline handler
+	rl_callback_handler_install(getCmdPrompt().c_str(), (rl_vcpfunc_t *)&ioman_readlineHandler);
+
+	mainmutex.lock();
+	while (runmain) {
+		mainmutex.unlock();
+
+		poll(&inPipeStatus, 1, 100);
+
+		if (inPipeStatus.revents & POLLIN) {
+			rl_callback_read_char();
+		}
+		if (!connected)
+			break;
+		if (loginstatus == err)
+			break;
+		mainmutex.lock();
+	}
+	mainmutex.unlock();
+
+	// Remove the handler
+	rl_callback_handler_remove();
 }

+ 15 - 15
cli/src/machineioman.cpp

@@ -11,24 +11,24 @@
 using boost::asio::buffer;
 
 void MachineIoMan::printMessage(std::string msg, OutMsgType type) {
-  switch (type) {
-  case normal: {
-    std::cout << msg << std::endl;
-    break;
-  }
-  case error: {
-    std::cout << msg << std::endl;
-    break;
-  }
-  case debug: {
-    //~ std::cerr << msg << std::endl;
-    break;
-  }
-  }
+	switch (type) {
+	case normal: {
+		std::cout << msg << std::endl;
+		break;
+	}
+	case error: {
+		std::cout << msg << std::endl;
+		break;
+	}
+	case debug: {
+		//~ std::cerr << msg << std::endl;
+		break;
+	}
+	}
 }
 
 void MachineIoMan::printWelcomeMessage() {
-  //~ std::cout << "please enter user and password" << std::endl;
+	//~ std::cout << "please enter user and password" << std::endl;
 }
 
 std::string MachineIoMan::getCmdPrompt() { return ""; }

+ 47 - 51
cli/src/main.cpp

@@ -11,63 +11,59 @@ namespace bpo = boost::program_options;
 IoMan *gIOMAN = NULL;
 
 void show_help(char *exec) {
-  std::printf("ccats command line interface\n");
-  std::printf("usage: %s IP [Options]\n", exec);
-  std::printf("IP should be in the format \"xxx.xxx.xxx.xxx\"\n");
+	std::printf("ccats command line interface\n");
+	std::printf("usage: %s IP [Options]\n", exec);
+	std::printf("IP should be in the format \"xxx.xxx.xxx.xxx\"\n");
 }
 
 int main(int argc, char **argv) {
-  bpo::options_description desc{"Options"};
-  desc.add_options()("help", "show this help")(
-      "machine",
-      "switch to machine mode for I/O (not designed for user interaction)")(
-      "batch", bpo::value<std::string>(),
-      "run operations from arg as batch file");
+	bpo::options_description desc{"Options"};
+	desc.add_options()("help", "show this help")("machine", "switch to machine mode for I/O (not designed for user interaction)")(
+	    "batch", bpo::value<std::string>(), "run operations from arg as batch file");
 
-  bpo::variables_map vm;
-  unsigned int machine = 0;
-  const char *file = NULL;
-  IoMan *ioman;
+	bpo::variables_map vm;
+	unsigned int machine = 0;
+	const char *file = NULL;
+	IoMan *ioman;
 
-  if (argc < 2 || !std::strncmp(argv[1], "--help", 6)) {
-    show_help(argv[0]);
-    std::cout << desc;
-    return 1;
-  }
+	if (argc < 2 || !std::strncmp(argv[1], "--help", 6)) {
+		show_help(argv[0]);
+		std::cout << desc;
+		return 1;
+	}
 
-  try {
-    store(parse_command_line(argc - 1, argv + 1, desc), vm);
-    notify(vm);
+	try {
+		store(parse_command_line(argc - 1, argv + 1, desc), vm);
+		notify(vm);
 
-    if (vm.count("help")) {
-      show_help(argv[0]);
-      std::cout << desc;
-      return 1;
-    }
-    if (vm.count("machine")) {
-      // enable machine/gui mode
-      machine = 1;
-    }
-    if (vm.count("batch")) {
-      // handle batch file mode
-      file = vm["batch"].as<std::string>().c_str();
-    }
-  } catch (const bpo::error &ex) {
-    std::fprintf(stderr, "%s\n", ex.what());
-  }
-  std::printf("ip %s machine mode is %d file is %s\n", argv[1], machine,
-              file ? file : "");
+		if (vm.count("help")) {
+			show_help(argv[0]);
+			std::cout << desc;
+			return 1;
+		}
+		if (vm.count("machine")) {
+			// enable machine/gui mode
+			machine = 1;
+		}
+		if (vm.count("batch")) {
+			// handle batch file mode
+			file = vm["batch"].as<std::string>().c_str();
+		}
+	} catch (const bpo::error &ex) {
+		std::fprintf(stderr, "%s\n", ex.what());
+	}
+	std::printf("ip %s machine mode is %d file is %s\n", argv[1], machine, file ? file : "");
 
-  if (machine) {
-    ioman = new MachineIoMan(argv[1]);
-  } else {
-    ioman = new UserIoMan(argv[1]);
-  }
-  gIOMAN = ioman;
-  if (ioman->init()) {
-    ioman->run();
-  }
-  delete ioman;
-  gIOMAN = NULL;
-  std::printf("done\n");
+	if (machine) {
+		ioman = new MachineIoMan(argv[1]);
+	} else {
+		ioman = new UserIoMan(argv[1]);
+	}
+	gIOMAN = ioman;
+	if (ioman->init()) {
+		ioman->run();
+	}
+	delete ioman;
+	gIOMAN = NULL;
+	std::printf("done\n");
 }

+ 114 - 139
cli/src/userioman.cpp

@@ -12,65 +12,62 @@ using boost::asio::buffer;
 
 UserIoMan::UserIoMan(char *ipcstring) : IoMan(ipcstring) {
 
-  /* setup json stuff */
-  Json::CharReaderBuilder rbuilder;
-  wbuilder.settings_["indentation"] = "";
-  reader = rbuilder.newCharReader();
-
-  /* initialize print command map */
-  printmap["error"] = &UserIoMan::printError;
-  printmap["connect"] = &UserIoMan::printConnect;
-  printmap["help"] = &UserIoMan::printHelp;
-  printmap["status"] = &UserIoMan::printStatus;
-  printmap["disconnect"] = &UserIoMan::printDisconnect;
-  printmap["put"] = &UserIoMan::printPut;
-  printmap["get"] = &UserIoMan::printGet;
-  printmap["list"] = &UserIoMan::printList;
-  printmap["version"] = &UserIoMan::printVersion;
-  printmap["login"] = &UserIoMan::printLogin;
-  printmap["signup"] = &UserIoMan::printSignup;
-  printmap["putdata"] = &UserIoMan::printPutdata;
-  printmap["getdata"] = &UserIoMan::printGetdata;
-  printmap["head"] = &UserIoMan::printHead;
-  printmap["deleteme"] = &UserIoMan::printDeleteme;
+	/* setup json stuff */
+	Json::CharReaderBuilder rbuilder;
+	wbuilder.settings_["indentation"] = "";
+	reader = rbuilder.newCharReader();
+
+	/* initialize print command map */
+	printmap["error"] = &UserIoMan::printError;
+	printmap["connect"] = &UserIoMan::printConnect;
+	printmap["help"] = &UserIoMan::printHelp;
+	printmap["status"] = &UserIoMan::printStatus;
+	printmap["disconnect"] = &UserIoMan::printDisconnect;
+	printmap["put"] = &UserIoMan::printPut;
+	printmap["get"] = &UserIoMan::printGet;
+	printmap["list"] = &UserIoMan::printList;
+	printmap["version"] = &UserIoMan::printVersion;
+	printmap["login"] = &UserIoMan::printLogin;
+	printmap["signup"] = &UserIoMan::printSignup;
+	printmap["putdata"] = &UserIoMan::printPutdata;
+	printmap["getdata"] = &UserIoMan::printGetdata;
+	printmap["head"] = &UserIoMan::printHead;
+	printmap["deleteme"] = &UserIoMan::printDeleteme;
 }
 
 UserIoMan::~UserIoMan() { delete reader; }
 
 void UserIoMan::printMessage(std::string msg, OutMsgType type) {
-  Json::Value root;
-  msgmutex.lock();
-  switch (type) {
-  case normal:
-  case error: {
-    // this should never happen outside of development
-    if (!reader->parse(msg.c_str(), msg.c_str() + msg.size(), &root,
-                       &jsonerror)) {
-      printMessage(string(__PRETTY_FUNCTION__) +
-                       " couldnt parse json data: " + jsonerror,
-                   debug);
-    } else {
-      printJson(root);
-    }
-    break;
-  }
-  //~ case error: {
-  //~ std::cout << msg << std::endl;
-  //~ break;
-  //~ }
-  case debug: {
-    std::cerr << msg << std::endl;
-    break;
-  }
-  }
-  rl_redisplay();
-  msgmutex.unlock();
+	Json::Value root;
+	msgmutex.lock();
+	switch (type) {
+	case normal:
+	case error: {
+		// this should never happen outside of development
+		if (!reader->parse(msg.c_str(), msg.c_str() + msg.size(), &root, &jsonerror)) {
+			printMessage(string(__PRETTY_FUNCTION__) + " couldnt parse json data: " + jsonerror, debug);
+		} else {
+			printJson(root);
+		}
+		break;
+	}
+	//~ case error: {
+	//~ std::cout << msg << std::endl;
+	//~ break;
+	//~ }
+	case debug: {
+		std::cerr << msg << std::endl;
+		break;
+	}
+	}
+	rl_redisplay();
+	msgmutex.unlock();
 }
 
 void UserIoMan::printWelcomeMessage() {
-  std::cout << "please login by entering \"login <username> <password>\" \nor "
-               "sign up and log in with \"signup <username> <password>\""
-            << std::endl;
+	std::cout << "please login by entering \"login <username> <password>\" \nor "
+	             "sign up and log in with \"signup <username> <password>\""
+	          << std::endl;
 }
 
 std::string UserIoMan::getCmdPrompt() { return "ccats> "; }
@@ -80,120 +77,100 @@ std::string UserIoMan::getCmdPrompt() { return "ccats> "; }
 //~ std::string UserIoMan::getPassPrompt() { return "Pass: "; }
 
 void UserIoMan::printJson(Json::Value root) {
-  map<string, void (UserIoMan::*)(Json::Value)>::iterator it =
-      printmap.find(root["command"].asString());
-  if (it == printmap.end()) {
-    // this should never happen outside of development
-    printMessage(string(__PRETTY_FUNCTION__) + " unknown command \"" +
-                     root["command"].asString() +
-                     "\".\nensure code is implemented.",
-                 debug);
-    return;
-  }
-  (this->*(printmap[root["command"].asString()]))(root);
+	map<string, void (UserIoMan::*)(Json::Value)>::iterator it = printmap.find(root["command"].asString());
+	if (it == printmap.end()) {
+		// this should never happen outside of development
+		printMessage(string(__PRETTY_FUNCTION__) + " unknown command \"" + root["command"].asString() + "\".\nensure code is implemented.", debug);
+		return;
+	}
+	(this->*(printmap[root["command"].asString()]))(root);
 }
 
-void UserIoMan::printError(Json::Value root) {
-  std::cout << "Error: " << root["error"].asString() << std::endl;
-}
+void UserIoMan::printError(Json::Value root) { std::cout << "Error: " << root["error"].asString() << std::endl; }
 
 void UserIoMan::printConnect(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    std::cout << "Couldnt connect to " << root["address"].asString() << ":"
-              << root["port"].asUInt() << std::endl
-              << "Reason: " << root["error"].asString() << std::endl;
-  }
+	if (!root["accept"].asBool()) {
+		std::cout << "Couldnt connect to " << root["address"].asString() << ":" << root["port"].asUInt() << std::endl
+		          << "Reason: " << root["error"].asString() << std::endl;
+	}
 }
 
 void UserIoMan::printHelp(Json::Value root) {
-  std::cout << "Available commands are: " << std::endl;
-  for (Json::Value i : root["names"])
-    std::cout << i.asString() << std::endl;
+	std::cout << "Available commands are: " << std::endl;
+	for (Json::Value i : root["names"])
+		std::cout << i.asString() << std::endl;
 }
 
-void UserIoMan::printStatus(Json::Value root) {
-  std::cout << "Server reports status: " << root["response"].asString()
-            << std::endl;
-}
+void UserIoMan::printStatus(Json::Value root) { std::cout << "Server reports status: " << root["response"].asString() << std::endl; }
 
 void UserIoMan::printDisconnect(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    std::cout << "Disconnect failed." << std::endl;
-  } else {
-    std::cout << "Disconnect successful." << std::endl;
-  }
+	if (!root["accept"].asBool()) {
+		std::cout << "Disconnect failed." << std::endl;
+	} else {
+		std::cout << "Disconnect successful." << std::endl;
+	}
 }
 
 void UserIoMan::printPut(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    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;
+	if (!root["accept"].asBool()) {
+		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;
 }
 
 void UserIoMan::printGet(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    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;
+	if (!root["accept"].asBool()) {
+		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;
 }
 
 void UserIoMan::printList(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    std::cout << "Listing files failed: " << root["error"].asString()
-              << std::endl;
-  } else {
-    std::cout << "Listing files stored on server: " << std::endl;
-    for (Json::Value i : root["names"])
-      std::cout << i.asString() << std::endl;
-    std::cout << "End of list." << std::endl;
-  }
+	if (!root["accept"].asBool()) {
+		std::cout << "Listing files failed: " << root["error"].asString() << std::endl;
+	} else {
+		std::cout << "Listing files stored on server: " << std::endl;
+		for (Json::Value i : root["names"])
+			std::cout << i.asString() << std::endl;
+		std::cout << "End of list." << std::endl;
+	}
 }
 
 void UserIoMan::printVersion(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    std::cout << "Version check failed. Server reports "
-              << root["serverversion"].asString() << " but client is "
-              << root["clientversion"].asString() << std::endl;
-  } else
-    std::cout << "Version check ok." << std::endl;
+	if (!root["accept"].asBool()) {
+		std::cout << "Version check failed. Server reports " << root["serverversion"].asString() << " but client is " << root["clientversion"].asString()
+		          << std::endl;
+	} else
+		std::cout << "Version check ok." << std::endl;
 }
 
 void UserIoMan::printLogin(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    std::cout << "Login failed: " << root["error"].asString() << std::endl;
-  } else
-    std::cout << "Login ok." << std::endl;
+	if (!root["accept"].asBool()) {
+		std::cout << "Login failed: " << root["error"].asString() << std::endl;
+	} else
+		std::cout << "Login ok." << std::endl;
 }
 
 void UserIoMan::printSignup(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    std::cout << "Signup failed: " << root["error"].asString() << std::endl;
-  } else
-    std::cout << "Signup ok. You are now logged in." << std::endl;
+	if (!root["accept"].asBool()) {
+		std::cout << "Signup failed: " << root["error"].asString() << std::endl;
+	} else
+		std::cout << "Signup ok. You are now logged in." << std::endl;
 }
 
 void UserIoMan::printDeleteme(Json::Value root) {
-  if (!root["accept"].asBool()) {
-    std::cout << "User deletion failed: " << root["error"].asString()
-              << std::endl;
-  } else
-    std::cout << "User deletion ok. You are now disconnected from the server."
-              << std::endl;
+	if (!root["accept"].asBool()) {
+		std::cout << "User deletion failed: " << root["error"].asString() << std::endl;
+	} else
+		std::cout << "User deletion ok. You are now disconnected from the server." << std::endl;
 }
 
 void UserIoMan::printPutdata(Json::Value root) {}
@@ -203,10 +180,8 @@ void UserIoMan::printGetdata(Json::Value root) {}
 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;
-  else
-    std::cout << "First four bytes of file " << root["file"].asString()
-              << " are: " << root["data"].asString() << std::endl;
+	if (!root["accept"].asBool())
+		std::cout << "Request of the first four bytes failed, server reports: " << root["error"].asString() << std::endl;
+	else
+		std::cout << "First four bytes of file " << root["file"].asString() << " are: " << root["data"].asString() << std::endl;
 }

+ 170 - 171
daemon/include/FileManager.h

@@ -11,179 +11,178 @@
  */
 class FileManager {
 private:
-  const std::string fileDirectory;
-
-  /**
-   * file stream for get command
-   */
-  std::ifstream getFile;
-
-  /**
-   * file stream for put command
-   */
-  std::ofstream putFile;
-
-  /**
-   * file name for put command
-   * (used to delete the file if the upload is canceled)
-   */
-  std::string putFileName;
-
-  /**
-   * file name for put command
-   */
-  std::string putBaseFileName;
-
-  /**
-   * file name for get command
-   */
-  std::string getBaseFileName;
-
-  /*
-   * size of the get file
-   *
-   * Used to determine how much to read and encode as base64
-   */
-  std::streamoff getFileSize;
-
-  /**
-   * list vector for list command
-   */
-  std::vector<std::vector<std::string>> list;
+	const std::string fileDirectory;
+
+	/**
+	 * file stream for get command
+	 */
+	std::ifstream getFile;
+
+	/**
+	 * file stream for put command
+	 */
+	std::ofstream putFile;
+
+	/**
+	 * file name for put command
+	 * (used to delete the file if the upload is canceled)
+	 */
+	std::string putFileName;
+
+	/**
+	 * file name for put command
+	 */
+	std::string putBaseFileName;
+
+	/**
+	 * file name for get command
+	 */
+	std::string getBaseFileName;
+
+	/*
+	 * size of the get file
+	 *
+	 * Used to determine how much to read and encode as base64
+	 */
+	std::streamoff getFileSize;
+
+	/**
+	 * list vector for list command
+	 */
+	std::vector<std::vector<std::string>> list;
 
 public:
-  enum { max_data_length = 512 };
-
-  /**
-   * Creates the file manager
-   */
-  FileManager();
-
-  /**
-   * Destroys the file manager
-   */
-  ~FileManager();
-
-  /**
-   * Checks if an upload is running
-   * @return true - upload running | false - no upload
-   */
-  virtual bool isUploading();
-
-  /**
-   * Check if a download is running
-   * @return true - download running | false - no download
-   */
-  virtual bool isDownloading();
-
-  /**
-   * Opens put file if it doesn't exist
-   * @return true - file is open | false - file is not open
-   */
-  virtual bool openPutFile(const std::string &filename);
-
-  /**
-   * Opens get file if it exists and reports the amount of chunks
-   * @return true - file is open | false - file is not open
-   */
-  virtual std::pair<bool, int> openGetFile(const std::string &filename);
-
-  /**
-   * Closes file
-   */
-  void closePutFile();
-
-  /**
-   * Closes file
-   */
-  void closeGetFile();
-
-  /**
-   * Closes put file and deletes it
-   */
-  virtual void cancelPut();
-
-  /**
-   * Checks if a file name is valid
-   * @return true - name is valid | false - name is invalid
-   */
-  bool checkFilename(const std::string &name);
-
-  /**
-   * Return the name of the download file
-   * @return name of the download file
-   */
-  virtual std::string getGetBaseFileName();
-
-  /**
-   * Return the name of the upload file
-   * @return name of the upload file
-   */
-  virtual std::string getPutBaseFileName();
-
-  /**
-   * Writes data to put file
-   */
-  virtual void writePut(const std::vector<char> &data);
-
-  /**
-   * Reads data from get file
-   */
-  virtual std::vector<char> readGet();
-
-  /**
-   * Open list command. Set list vector and claculate chunks
-   *
-   * @return chunks of the resulting list | if a filename is too long it returns
-   * -1
-   */
-  virtual int openList();
-
-  /**
-   * @return remaining chunks to be send with listdata command
-   */
-  virtual int getRemainingListChunks();
-
-  /**
-   * @return size of the list vector
-   */
-  virtual int getListSize();
-
-  /**
-   * Return next chunk for listdata command.
-   * Increases remainingListChunks. You need to run openList before.
-   *
-   * @return next chnuk vector
-   */
-  virtual std::vector<std::string> getNextChunkFromList();
-
-  /**
-   * Cancel current list command.
-   * Clear list vector and set remainingListChunks zero.
-   */
-  void cancelList();
-
-  /**
-   * head error
-   *
-   * errors which the head command returns
-   *
-   * - no error
-   * - no such file
-   * - file is smaller than specified size
-   */
-  enum headError { no_error, no_such_file, file_too_small };
-
-  /**
-   * Get the first n bytes of a file as string.
-   * @param filename name of the files
-   * @param numOfBytes the number of bytes you want
-   *
-   * @return first: the array of chars containing the data if no error occured
-   *         second: an error code
-   */
-  virtual std::pair<std::vector<char>, headError>
-  getBytesFromFile(const std::string &filename, int numOfBytes);
+	enum { max_data_length = 512 };
+
+	/**
+	 * Creates the file manager
+	 */
+	FileManager();
+
+	/**
+	 * Destroys the file manager
+	 */
+	~FileManager();
+
+	/**
+	 * Checks if an upload is running
+	 * @return true - upload running | false - no upload
+	 */
+	virtual bool isUploading();
+
+	/**
+	 * Check if a download is running
+	 * @return true - download running | false - no download
+	 */
+	virtual bool isDownloading();
+
+	/**
+	 * Opens put file if it doesn't exist
+	 * @return true - file is open | false - file is not open
+	 */
+	virtual bool openPutFile(const std::string &filename);
+
+	/**
+	 * Opens get file if it exists and reports the amount of chunks
+	 * @return true - file is open | false - file is not open
+	 */
+	virtual std::pair<bool, int> openGetFile(const std::string &filename);
+
+	/**
+	 * Closes file
+	 */
+	void closePutFile();
+
+	/**
+	 * Closes file
+	 */
+	void closeGetFile();
+
+	/**
+	 * Closes put file and deletes it
+	 */
+	virtual void cancelPut();
+
+	/**
+	 * Checks if a file name is valid
+	 * @return true - name is valid | false - name is invalid
+	 */
+	bool checkFilename(const std::string &name);
+
+	/**
+	 * Return the name of the download file
+	 * @return name of the download file
+	 */
+	virtual std::string getGetBaseFileName();
+
+	/**
+	 * Return the name of the upload file
+	 * @return name of the upload file
+	 */
+	virtual std::string getPutBaseFileName();
+
+	/**
+	 * Writes data to put file
+	 */
+	virtual void writePut(const std::vector<char> &data);
+
+	/**
+	 * Reads data from get file
+	 */
+	virtual std::vector<char> readGet();
+
+	/**
+	 * Open list command. Set list vector and claculate chunks
+	 *
+	 * @return chunks of the resulting list | if a filename is too long it returns
+	 * -1
+	 */
+	virtual int openList();
+
+	/**
+	 * @return remaining chunks to be send with listdata command
+	 */
+	virtual int getRemainingListChunks();
+
+	/**
+	 * @return size of the list vector
+	 */
+	virtual int getListSize();
+
+	/**
+	 * Return next chunk for listdata command.
+	 * Increases remainingListChunks. You need to run openList before.
+	 *
+	 * @return next chnuk vector
+	 */
+	virtual std::vector<std::string> getNextChunkFromList();
+
+	/**
+	 * Cancel current list command.
+	 * Clear list vector and set remainingListChunks zero.
+	 */
+	void cancelList();
+
+	/**
+	 * head error
+	 *
+	 * errors which the head command returns
+	 *
+	 * - no error
+	 * - no such file
+	 * - file is smaller than specified size
+	 */
+	enum headError { no_error, no_such_file, file_too_small };
+
+	/**
+	 * Get the first n bytes of a file as string.
+	 * @param filename name of the files
+	 * @param numOfBytes the number of bytes you want
+	 *
+	 * @return first: the array of chars containing the data if no error occured
+	 *         second: an error code
+	 */
+	virtual std::pair<std::vector<char>, headError> getBytesFromFile(const std::string &filename, int numOfBytes);
 };
 
 #endif

+ 125 - 126
daemon/include/JsonCommander.h

@@ -13,134 +13,133 @@
  */
 class JsonCommander {
 public:
-  /**
-   * Action for the json response.
-   * send         - send the json answer
-   * closeAndSend - send the json answer and close the socket
-   * close        - close the socket
-   */
-  enum Action { close, send, closeAndSend };
-
-  /**
-   * Response for commands
-   *
-   * If action is set to close json can be uninitialized.
-   */
-  struct Response {
-    Action action;
-    Json::Value json;
-  };
-
-  /**
-   * Creates a JsonCommaner
-   */
-  JsonCommander(FileManager &fileManager);
-
-  /**
-   * Deletes the JsonCommander
-   */
-  ~JsonCommander();
-
-  /**
-   * Executes commands
-   */
-  Response execute(const Json::Value &message);
-
-  /**
-   * Does version check before login
-   */
-  Response testVersion(const Json::Value &message);
-
-  /**
-   * Checks if login is valid
-   */
-  Response checkLogin(const Json::Value &message);
+	/**
+	 * Action for the json response.
+	 * send         - send the json answer
+	 * closeAndSend - send the json answer and close the socket
+	 * close        - close the socket
+	 */
+	enum Action { close, send, closeAndSend };
+
+	/**
+	 * Response for commands
+	 *
+	 * If action is set to close json can be uninitialized.
+	 */
+	struct Response {
+		Action action;
+		Json::Value json;
+	};
+
+	/**
+	 * Creates a JsonCommaner
+	 */
+	JsonCommander(FileManager &fileManager);
+
+	/**
+	 * Deletes the JsonCommander
+	 */
+	~JsonCommander();
+
+	/**
+	 * Executes commands
+	 */
+	Response execute(const Json::Value &message);
+
+	/**
+	 * Does version check before login
+	 */
+	Response testVersion(const Json::Value &message);
+
+	/**
+	 * Checks if login is valid
+	 */
+	Response checkLogin(const Json::Value &message);
 
 private:
-  /**
-   * protocol version of the client server protocol
-   */
-  const std::string protocolVersion = "0.2";
-
-  /**
-   * Contains the name of the user which uses the current connection.
-   * Is set at checkLogin. Used for deleteUser.
-   */
-  std::string currentUser;
-
-  /**
-   * Map of all commands
-   *
-   * Used to find the command function fast
-   */
-  std::map<std::string, Response (JsonCommander::*)(const Json::Value &)>
-      commandsMap;
-
-  /**
-   * file manager for reading and writing files
-   */
-  FileManager &fileManager;
-
-  /**
-   *
-   * Last chunk number which was sent.
-   */
-  int getFileRemaining;
-
-  /**
-   * Last chunk number which was received.
-   */
-  int putFileReceived;
-
-  /**
-   * Executes the status command
-   */
-  Response executeStatus(const Json::Value &message);
-
-  /**
-   * Executes the close command
-   */
-  Response executeClose(const Json::Value &message);
-
-  /**
-   * Executes the list command
-   */
-  Response executeList(const Json::Value &message);
-
-  /**
-   * Executes the listdata command
-   */
-  Response executeListData(const Json::Value &message);
-
-  /**
-   * Executes the put command
-   */
-  Response executePut(const Json::Value &message);
-
-  /**
-   * Executes the putdata command
-   */
-  Response executePutdata(const Json::Value &message);
-
-  /**
-   * Executes the get command
-   */
-  Response executeGet(const Json::Value &message);
-
-  /**
-   * Executes the getdata command
-   */
-  Response executeGetdata(const Json::Value &message);
-
-  /**
-   * Executes the head command
-   */
-  Response executeHead(const Json::Value &message);
-
-  /**
-   * Executes the deleteme command
-   */
-  Response executeDeleteMe(const Json::Value &message);
+	/**
+	 * protocol version of the client server protocol
+	 */
+	const std::string protocolVersion = "0.2";
+
+	/**
+	 * Contains the name of the user which uses the current connection.
+	 * Is set at checkLogin. Used for deleteUser.
+	 */
+	std::string currentUser;
+
+	/**
+	 * Map of all commands
+	 *
+	 * Used to find the command function fast
+	 */
+	std::map<std::string, Response (JsonCommander::*)(const Json::Value &)> commandsMap;
+
+	/**
+	 * file manager for reading and writing files
+	 */
+	FileManager &fileManager;
+
+	/**
+	 *
+	 * Last chunk number which was sent.
+	 */
+	int getFileRemaining;
+
+	/**
+	 * Last chunk number which was received.
+	 */
+	int putFileReceived;
+
+	/**
+	 * Executes the status command
+	 */
+	Response executeStatus(const Json::Value &message);
+
+	/**
+	 * Executes the close command
+	 */
+	Response executeClose(const Json::Value &message);
+
+	/**
+	 * Executes the list command
+	 */
+	Response executeList(const Json::Value &message);
+
+	/**
+	 * Executes the listdata command
+	 */
+	Response executeListData(const Json::Value &message);
+
+	/**
+	 * Executes the put command
+	 */
+	Response executePut(const Json::Value &message);
+
+	/**
+	 * Executes the putdata command
+	 */
+	Response executePutdata(const Json::Value &message);
+
+	/**
+	 * Executes the get command
+	 */
+	Response executeGet(const Json::Value &message);
+
+	/**
+	 * Executes the getdata command
+	 */
+	Response executeGetdata(const Json::Value &message);
+
+	/**
+	 * Executes the head command
+	 */
+	Response executeHead(const Json::Value &message);
+
+	/**
+	 * Executes the deleteme command
+	 */
+	Response executeDeleteMe(const Json::Value &message);
 };
 
 #endif

+ 161 - 168
daemon/include/Server.h

@@ -21,151 +21,145 @@ using ip::tcp;
  */
 class con_handler : public boost::enable_shared_from_this<con_handler> {
 private:
-  tcp::socket sock;
-
-  /**
-   * max buffer length
-   */
-  enum { max_length = 1024 };
-
-  /**
-   * data buffer
-   */
-  streambuf buf;
-
-  /**
-   * string builder for json
-   */
-  Json::StreamWriterBuilder jsonStringBuilder;
-
-  /**
-   * json reader to parse json strings
-   */
-  std::unique_ptr<Json::CharReader> jsonReader;
-
-  /**
-   * Executes json commands
-   */
-  JsonCommander jsonCommander;
-
-  /**
-   * File manager used by jsonCommander
-   */
-  FileManager fileManager;
-
-  /**
-   * Reads data and binds it to a handler.
-   *
-   * @param handler method pointer to a handler_read_* method
-   */
-  void read(void (con_handler::*handler)(const boost::system::error_code &err,
-                                         size_t bytes_transferred));
-
-  /**
-   * Sends json data over the network.
-   *
-   * @param json json object
-   */
-  void sendJson(const Json::Value &json);
-
-  /**
-   * Parses a line of the buffer to a json value object.
-   *
-   * @return json object
-   */
-  Json::Value parseMessage();
+	tcp::socket sock;
+
+	/**
+	 * max buffer length
+	 */
+	enum { max_length = 1024 };
+
+	/**
+	 * data buffer
+	 */
+	streambuf buf;
+
+	/**
+	 * string builder for json
+	 */
+	Json::StreamWriterBuilder jsonStringBuilder;
+
+	/**
+	 * json reader to parse json strings
+	 */
+	std::unique_ptr<Json::CharReader> jsonReader;
+
+	/**
+	 * Executes json commands
+	 */
+	JsonCommander jsonCommander;
+
+	/**
+	 * File manager used by jsonCommander
+	 */
+	FileManager fileManager;
+
+	/**
+	 * Reads data and binds it to a handler.
+	 *
+	 * @param handler method pointer to a handler_read_* method
+	 */
+	void read(void (con_handler::*handler)(const boost::system::error_code &err, size_t bytes_transferred));
+
+	/**
+	 * Sends json data over the network.
+	 *
+	 * @param json json object
+	 */
+	void sendJson(const Json::Value &json);
+
+	/**
+	 * Parses a line of the buffer to a json value object.
+	 *
+	 * @return json object
+	 */
+	Json::Value parseMessage();
 
 public:
-  /**
-   * Pointer to a con_handler.
-   */
-  typedef boost::shared_ptr<con_handler> pointer;
-
-  /**
-   * con_handler constructor
-   *
-   * Creates a con_handler
-   *
-   * @param io_service connection info
-   */
-  con_handler(basic_socket_acceptor<ip::tcp>::executor_type &io_service);
-
-  /**
-   * con_handler destructor.
-   */
-  ~con_handler();
-
-  /**
-   * Creates a new con_handler.
-   *
-   * Allocates a new con_hanlder and returns the pointer.
-   *
-   * @param io_service connection info
-   *
-   * @return con_handler pointer
-   */
-  static pointer
-  create(basic_socket_acceptor<ip::tcp>::executor_type &io_service);
-
-  /**
-   * socket getter
-   *
-   * Returns the socket of the connection.
-   *
-   * @return the socket
-   */
-  tcp::socket &socket();
-
-  /**
-   * Starts a connection.
-   *
-   * Negotiates a connection and sets everything important to the connection up.
-   */
-  void start();
-
-  /**
-   * Read handler
-   *
-   * Will be called if the server expected a version and received something.
-   *
-   * @param err error
-   * @param bytes_transferred amount of transferred bytes
-   */
-  void handle_read_version(const boost::system::error_code &err,
-                           size_t bytes_transferred);
-
-  /**
-   * Read handler
-   *
-   * Will be called after the version was verifyed. Checks login data.
-   *
-   * @param err error
-   * @param bytes_transferred amount of transferred bytes
-   */
-  void handle_read_login(const boost::system::error_code &err,
-                         size_t bytes_transferred);
-
-  /**
-   * Read handler
-   *
-   * Will be called after the version and login was verifyed. Executes commands.
-   *
-   * @param err error
-   * @param bytes_transferred amount of transferred bytes
-   */
-  void handle_read_command(const boost::system::error_code &err,
-                           size_t bytes_transferred);
-
-  /**
-   * Write handler
-   *
-   * Will be called if the server sends something.
-   *
-   * @param err error
-   * @param bytes_transferred amount of transferred bytes
-   */
-  void handle_write(const boost::system::error_code &err,
-                    size_t bytes_transferred);
+	/**
+	 * Pointer to a con_handler.
+	 */
+	typedef boost::shared_ptr<con_handler> pointer;
+
+	/**
+	 * con_handler constructor
+	 *
+	 * Creates a con_handler
+	 *
+	 * @param io_service connection info
+	 */
+	con_handler(basic_socket_acceptor<ip::tcp>::executor_type &io_service);
+
+	/**
+	 * con_handler destructor.
+	 */
+	~con_handler();
+
+	/**
+	 * Creates a new con_handler.
+	 *
+	 * Allocates a new con_hanlder and returns the pointer.
+	 *
+	 * @param io_service connection info
+	 *
+	 * @return con_handler pointer
+	 */
+	static pointer create(basic_socket_acceptor<ip::tcp>::executor_type &io_service);
+
+	/**
+	 * socket getter
+	 *
+	 * Returns the socket of the connection.
+	 *
+	 * @return the socket
+	 */
+	tcp::socket &socket();
+
+	/**
+	 * Starts a connection.
+	 *
+	 * Negotiates a connection and sets everything important to the connection up.
+	 */
+	void start();
+
+	/**
+	 * Read handler
+	 *
+	 * Will be called if the server expected a version and received something.
+	 *
+	 * @param err error
+	 * @param bytes_transferred amount of transferred bytes
+	 */
+	void handle_read_version(const boost::system::error_code &err, size_t bytes_transferred);
+
+	/**
+	 * Read handler
+	 *
+	 * Will be called after the version was verifyed. Checks login data.
+	 *
+	 * @param err error
+	 * @param bytes_transferred amount of transferred bytes
+	 */
+	void handle_read_login(const boost::system::error_code &err, size_t bytes_transferred);
+
+	/**
+	 * Read handler
+	 *
+	 * Will be called after the version and login was verifyed. Executes commands.
+	 *
+	 * @param err error
+	 * @param bytes_transferred amount of transferred bytes
+	 */
+	void handle_read_command(const boost::system::error_code &err, size_t bytes_transferred);
+
+	/**
+	 * Write handler
+	 *
+	 * Will be called if the server sends something.
+	 *
+	 * @param err error
+	 * @param bytes_transferred amount of transferred bytes
+	 */
+	void handle_write(const boost::system::error_code &err, size_t bytes_transferred);
 };
 
 /**
@@ -177,34 +171,33 @@ public:
  */
 class Server {
 private:
-  tcp::acceptor acceptor_;
+	tcp::acceptor acceptor_;
 
-  /**
-   * Accepts traffic
-   */
-  void start_accept();
+	/**
+	 * Accepts traffic
+	 */
+	void start_accept();
 
 public:
-  /**
-   * Creates a boost server
-   *
-   * @param io_service connection info
-   */
-  Server(io_service &io_service);
-
-  /**
-   * Destroys the server
-   */
-  ~Server();
-
-  /**
-   * Handles traffic?
-   *
-   * @param connection con_handler
-   * @param err error
-   */
-  void handle_accept(con_handler::pointer connection,
-                     const boost::system::error_code &err);
+	/**
+	 * Creates a boost server
+	 *
+	 * @param io_service connection info
+	 */
+	Server(io_service &io_service);
+
+	/**
+	 * Destroys the server
+	 */
+	~Server();
+
+	/**
+	 * Handles traffic?
+	 *
+	 * @param connection con_handler
+	 * @param err error
+	 */
+	void handle_accept(con_handler::pointer connection, const boost::system::error_code &err);
 };
 
 #endif

+ 45 - 45
daemon/include/Sniffer.h

@@ -14,57 +14,57 @@
  */
 class Sniffer {
 public:
-  /**
-   * Creates a Sniffer.
-   *
-   * Creates a Sniffer and sets the network interface for sniffing.
-   *
-   * @param interface name of the interface for sniffing
-   */
-  Sniffer(const std::string &interfaceName);
+	/**
+	 * Creates a Sniffer.
+	 *
+	 * Creates a Sniffer and sets the network interface for sniffing.
+	 *
+	 * @param interface name of the interface for sniffing
+	 */
+	Sniffer(const std::string &interfaceName);
 
-  /**
-   * Destroys the Sniffer.
-   *
-   * Destructor of the Sniffer.
-   */
-  ~Sniffer();
+	/**
+	 * Destroys the Sniffer.
+	 *
+	 * Destructor of the Sniffer.
+	 */
+	~Sniffer();
 
-  /**
-   * Start sniffing on the interface.
-   *
-   * Starts a sniffing loop which calls handle. The loop will only be stopped if
-   * handle returns false.
-   */
-  void startSniffing();
+	/**
+	 * Start sniffing on the interface.
+	 *
+	 * Starts a sniffing loop which calls handle. The loop will only be stopped if
+	 * handle returns false.
+	 */
+	void startSniffing();
 
-  /**
-   * Sets a filter for the sniffer.
-   *
-   * Sets the filter for a sniffer with a pcap filter string. E.g. "ip
-   * dst 8.8.8.8".
-   *
-   * @param filterString pcap filter string
-   */
-  void setFilter(const std::string &filterString);
+	/**
+	 * Sets a filter for the sniffer.
+	 *
+	 * Sets the filter for a sniffer with a pcap filter string. E.g. "ip
+	 * dst 8.8.8.8".
+	 *
+	 * @param filterString pcap filter string
+	 */
+	void setFilter(const std::string &filterString);
 
 private:
-  /**
-   * Handler for sniffed packets.
-   *
-   * Handles incoming connections and provides data for the package analyzer and
-   * modifyer.
-   *
-   * @param pdu sniffed packet
-   *
-   * @return false = stop loop | true = continue loop
-   */
-  bool handle(Tins::PDU &pdu);
+	/**
+	 * Handler for sniffed packets.
+	 *
+	 * Handles incoming connections and provides data for the package analyzer and
+	 * modifyer.
+	 *
+	 * @param pdu sniffed packet
+	 *
+	 * @return false = stop loop | true = continue loop
+	 */
+	bool handle(Tins::PDU &pdu);
 
-  /**
-   * Tins sniffer object.
-   */
-  Tins::Sniffer *sniffer;
+	/**
+	 * Tins sniffer object.
+	 */
+	Tins::Sniffer *sniffer;
 };
 
 #endif

+ 42 - 42
daemon/include/UserManager.h

@@ -15,55 +15,55 @@
  */
 class UserManager {
 public:
-  /**
-   * Makes shure that there is a user storage.
-   * If not. It creates a new one
-   */
-  static void init(const std::string &file);
+	/**
+	 * Makes shure that there is a user storage.
+	 * If not. It creates a new one
+	 */
+	static void init(const std::string &file);
 
-  /**
-   * Checks if a given user with password is valid
-   *
-   * @param user the name of the users
-   * @param pw password in plain text
-   */
-  static bool isAllowed(const std::string &user, const std::string &pw);
+	/**
+	 * Checks if a given user with password is valid
+	 *
+	 * @param user the name of the users
+	 * @param pw password in plain text
+	 */
+	static bool isAllowed(const std::string &user, const std::string &pw);
 
-  /**
-   * Add a new user and write to storage.
-   *
-   * @param user the name of the users
-   * @param pw password in plain text
-   */
-  static bool addUser(const std::string &name, const std::string &pw);
+	/**
+	 * Add a new user and write to storage.
+	 *
+	 * @param user the name of the users
+	 * @param pw password in plain text
+	 */
+	static bool addUser(const std::string &name, const std::string &pw);
 
-  /**
-   * Delete a new user and delete from storage.
-   *
-   * @param user the name of the users
-   * @param pw password in plain text
-   */
-  static bool deleteUser(const std::string &name, const std::string &pw);
+	/**
+	 * Delete a new user and delete from storage.
+	 *
+	 * @param user the name of the users
+	 * @param pw password in plain text
+	 */
+	static bool deleteUser(const std::string &name, const std::string &pw);
 
 private:
-  /**
-   * Name of the file which holds the user data
-   */
-  static std::string filename;
+	/**
+	 * Name of the file which holds the user data
+	 */
+	static std::string filename;
 
-  /**
-   * Read data from file and create map.
-   *
-   * @param user_map pointer to the map
-   */
-  static void readFromFile(std::map<std::string, std::string> &user_map);
+	/**
+	 * Read data from file and create map.
+	 *
+	 * @param user_map pointer to the map
+	 */
+	static void readFromFile(std::map<std::string, std::string> &user_map);
 
-  /**
-   * Write data to afile
-   *
-   * @param user_map pointer to the map
-   */
-  static void writeToFile(std::map<std::string, std::string> &user_map);
+	/**
+	 * Write data to afile
+	 *
+	 * @param user_map pointer to the map
+	 */
+	static void writeToFile(std::map<std::string, std::string> &user_map);
 };
 
 #endif

+ 23 - 23
daemon/src/Config.cpp

@@ -5,32 +5,32 @@ std::map<std::string, std::string> storage;
 };
 
 bool Config::init(const std::string &filename) {
-  std::ifstream ifile(filename);
-  std::string line;
+	std::ifstream ifile(filename);
+	std::string line;
 
-  if (ifile.is_open()) {
-    while (getline(ifile, line)) {
-      std::stringstream ss(line);
-      std::string segment;
-      std::vector<std::string> v;
-      while (getline(ss, segment, '=')) {
-        v.push_back(segment);
-      }
-      if (v.size() != 2) {
-        return false;
-      }
-      storage.insert(std::pair<std::string, std::string>(v.at(0), v.at(1)));
-    }
-    return true;
-  }
-  return false;
+	if (ifile.is_open()) {
+		while (getline(ifile, line)) {
+			std::stringstream ss(line);
+			std::string segment;
+			std::vector<std::string> v;
+			while (getline(ss, segment, '=')) {
+				v.push_back(segment);
+			}
+			if (v.size() != 2) {
+				return false;
+			}
+			storage.insert(std::pair<std::string, std::string>(v.at(0), v.at(1)));
+		}
+		return true;
+	}
+	return false;
 }
 
 std::string Config::getValue(const std::string &key) {
-  auto it = storage.find(key);
-  if (it != storage.end()) {
-    return it->second;
-  }
+	auto it = storage.find(key);
+	if (it != storage.end()) {
+		return it->second;
+	}
 
-  return "";
+	return "";
 }

+ 110 - 117
daemon/src/FileManager.cpp

@@ -8,8 +8,8 @@
 FileManager::FileManager() : fileDirectory(Config::getValue("filedirectory")) {}
 
 FileManager::~FileManager() {
-  cancelPut();
-  closeGetFile();
+	cancelPut();
+	closeGetFile();
 }
 
 bool FileManager::isUploading() { return this->putFile.is_open(); }
@@ -17,41 +17,40 @@ bool FileManager::isUploading() { return this->putFile.is_open(); }
 bool FileManager::isDownloading() { return this->getFile.is_open(); }
 
 bool FileManager::openPutFile(const std::string &filename) {
-  this->putBaseFileName = filename;
-  this->putFileName = this->fileDirectory;
-  this->putFileName.append(filename);
-
-  std::ifstream ifile(this->putFileName);
-  if (ifile.is_open()) {
-    // file alread exists
-    ifile.close();
-    closePutFile();
-    return false;
-  }
-
-  // open file and test if it already exists
-  this->putFile.open(this->putFileName, std::ios::app | std::ios::binary);
-  return true;
+	this->putBaseFileName = filename;
+	this->putFileName = this->fileDirectory;
+	this->putFileName.append(filename);
+
+	std::ifstream ifile(this->putFileName);
+	if (ifile.is_open()) {
+		// file alread exists
+		ifile.close();
+		closePutFile();
+		return false;
+	}
+
+	// open file and test if it already exists
+	this->putFile.open(this->putFileName, std::ios::app | std::ios::binary);
+	return true;
 }
 
 std::pair<bool, int> FileManager::openGetFile(const std::string &filename) {
-  this->getBaseFileName = filename;
-  std::string file = this->fileDirectory;
-  file.append(filename);
-
-  this->getFile.open(file, std::ios::ate | std::ios::binary);
-
-  if (this->getFile.is_open() == 0) {
-    // file does not exist or cannot be opened
-    return std::pair<bool, int>(false, -1);
-  } else {
-    this->getFileSize = this->getFile.tellg();
-    int chunks = this->getFileSize / max_data_length +
-                 (this->getFileSize % max_data_length == 0 ? 0 : 1);
-
-    this->getFile.seekg(std::ios::beg);
-    return std::pair<bool, int>(true, chunks);
-  }
+	this->getBaseFileName = filename;
+	std::string file = this->fileDirectory;
+	file.append(filename);
+
+	this->getFile.open(file, std::ios::ate | std::ios::binary);
+
+	if (this->getFile.is_open() == 0) {
+		// file does not exist or cannot be opened
+		return std::pair<bool, int>(false, -1);
+	} else {
+		this->getFileSize = this->getFile.tellg();
+		int chunks = this->getFileSize / max_data_length + (this->getFileSize % max_data_length == 0 ? 0 : 1);
+
+		this->getFile.seekg(std::ios::beg);
+		return std::pair<bool, int>(true, chunks);
+	}
 }
 
 void FileManager::closePutFile() { this->putFile.close(); }
@@ -59,123 +58,117 @@ void FileManager::closePutFile() { this->putFile.close(); }
 void FileManager::closeGetFile() { this->getFile.close(); }
 
 void FileManager::cancelPut() {
-  if (isUploading()) {
-    closePutFile();
-    std::remove(this->putFileName.c_str());
-  }
+	if (isUploading()) {
+		closePutFile();
+		std::remove(this->putFileName.c_str());
+	}
 }
 
-bool FileManager::checkFilename(const std::string &name) {
-  return name.find('/') == std::string::npos;
-}
+bool FileManager::checkFilename(const std::string &name) { return name.find('/') == std::string::npos; }
 
 std::string FileManager::getGetBaseFileName() { return this->getBaseFileName; }
 
 std::string FileManager::getPutBaseFileName() { return this->putBaseFileName; }
 
-void FileManager::writePut(const std::vector<char> &data) {
-  this->putFile.write(data.data(), data.size());
-}
+void FileManager::writePut(const std::vector<char> &data) { this->putFile.write(data.data(), data.size()); }
 
 std::vector<char> FileManager::readGet() {
-  // store position before read
-  std::streamoff read = this->getFile.tellg();
-  if (read + max_data_length > this->getFileSize) {
-    read = this->getFileSize % max_data_length;
-  } else {
-    read = max_data_length;
-  }
+	// store position before read
+	std::streamoff read = this->getFile.tellg();
+	if (read + max_data_length > this->getFileSize) {
+		read = this->getFileSize % max_data_length;
+	} else {
+		read = max_data_length;
+	}
 
-  std::vector<char> data;
-  data.resize(read);
+	std::vector<char> data;
+	data.resize(read);
 
-  this->getFile.read(data.data(), read);
+	this->getFile.read(data.data(), read);
 
-  return data;
+	return data;
 }
 
 int FileManager::openList() {
-  // add empty chunk vector
-  this->list.push_back(std::vector<std::string>());
-
-  int cursize = 0;
-
-  for (const auto &entry :
-       boost::filesystem::directory_iterator(this->fileDirectory)) {
-    // getting filename from
-    if (boost::filesystem::is_directory(entry.path()))
-      continue;
-    const std::string s = entry.path().filename().string();
-
-    // check if the size is too big
-    if (s.length() > max_data_length)
-      return -1;
-
-    cursize += s.length() + 3;
-    if (cursize > max_data_length) {
-      this->list.push_back(std::vector<std::string>());
-      cursize = 0;
-    }
-
-    // add string to its chunk
-    this->list.back().push_back(s);
-  }
-
-  // empty list if no file was read
-  if (this->list.size() == 1 && this->list.back().size() == 0) {
-    this->list.clear();
-  }
-
-  return this->list.size();
+	// add empty chunk vector
+	this->list.push_back(std::vector<std::string>());
+
+	int cursize = 0;
+
+	for (const auto &entry : boost::filesystem::directory_iterator(this->fileDirectory)) {
+		// getting filename from
+		if (boost::filesystem::is_directory(entry.path()))
+			continue;
+		const std::string s = entry.path().filename().string();
+
+		// check if the size is too big
+		if (s.length() > max_data_length)
+			return -1;
+
+		cursize += s.length() + 3;
+		if (cursize > max_data_length) {
+			this->list.push_back(std::vector<std::string>());
+			cursize = 0;
+		}
+
+		// add string to its chunk
+		this->list.back().push_back(s);
+	}
+
+	// empty list if no file was read
+	if (this->list.size() == 1 && this->list.back().size() == 0) {
+		this->list.clear();
+	}
+
+	return this->list.size();
 }
 
 int FileManager::getRemainingListChunks() { return this->list.size(); }
 
 int FileManager::getListSize() {
-  int size = 0;
-  for (const std::vector<std::string> &l : this->list) {
-    size += l.size();
-  }
-  return size;
+	int size = 0;
+	for (const std::vector<std::string> &l : this->list) {
+		size += l.size();
+	}
+	return size;
 }
 
 std::vector<std::string> FileManager::getNextChunkFromList() {
-  if (getRemainingListChunks() == 0) { // This should never happen!!!
-    return std::vector<std::string>();
-  }
+	if (getRemainingListChunks() == 0) { // This should never happen!!!
+		return std::vector<std::string>();
+	}
 
-  std::vector<std::string> ret = this->list.back();
-  this->list.pop_back();
+	std::vector<std::string> ret = this->list.back();
+	this->list.pop_back();
 
-  return ret;
+	return ret;
 }
 
 void FileManager::cancelList() { this->list.clear(); }
 
-std::pair<std::vector<char>, FileManager::headError>
-FileManager::getBytesFromFile(const std::string &filename, int numOfBytes) {
-  std::ifstream file;
-  std::string fname = this->fileDirectory;
-  fname.append(filename);
-  file.open(fname, std::ios::ate | std::ios::binary);
+std::pair<std::vector<char>, FileManager::headError> FileManager::getBytesFromFile(const std::string &filename, int numOfBytes) {
+	std::ifstream file;
+	std::string fname = this->fileDirectory;
+	fname.append(filename);
+	file.open(fname, std::ios::ate | std::ios::binary);
 
-  std::vector<char> bytes;
+	std::vector<char> bytes;
 
-  if (!file.is_open()) {
-    return std::make_pair(bytes, FileManager::headError::no_such_file);
-  }
+	if (!file.is_open()) {
+		return std::make_pair(bytes, FileManager::headError::no_such_file);
+	}
 
-  auto size = file.tellg();
-  if (size < numOfBytes) {
-    return std::make_pair(bytes, FileManager::headError::file_too_small);
-  }
+	auto size = file.tellg();
+	if (size < numOfBytes) {
+		return std::make_pair(bytes, FileManager::headError::file_too_small);
+	}
 
-  bytes.resize(numOfBytes);
+	bytes.resize(numOfBytes);
 
-  file.seekg(0, std::ios::beg);
-  file.read(bytes.data(), numOfBytes);
+	file.seekg(0, std::ios::beg);
+	file.read(bytes.data(), numOfBytes);
 
-  file.close();
+	file.close();
 
-  return std::make_pair(bytes, FileManager::headError::no_error);
+	return std::make_pair(bytes, FileManager::headError::no_error);
 }

+ 421 - 443
daemon/src/JsonCommander.cpp

@@ -2,486 +2,464 @@
 #include "../include/UserManager.h"
 #include "../include/base64.h"
 
-JsonCommander::JsonCommander(FileManager &fileManager)
-    : fileManager(fileManager) {
-  commandsMap["status"] = &JsonCommander::executeStatus;
-  commandsMap["close"] = &JsonCommander::executeClose;
-  commandsMap["list"] = &JsonCommander::executeList;
-  commandsMap["listdata"] = &JsonCommander::executeListData;
-  commandsMap["put"] = &JsonCommander::executePut;
-  commandsMap["putdata"] = &JsonCommander::executePutdata;
-  commandsMap["get"] = &JsonCommander::executeGet;
-  commandsMap["getdata"] = &JsonCommander::executeGetdata;
-  commandsMap["head"] = &JsonCommander::executeHead;
-  commandsMap["deleteme"] = &JsonCommander::executeDeleteMe;
+JsonCommander::JsonCommander(FileManager &fileManager) : fileManager(fileManager) {
+	commandsMap["status"] = &JsonCommander::executeStatus;
+	commandsMap["close"] = &JsonCommander::executeClose;
+	commandsMap["list"] = &JsonCommander::executeList;
+	commandsMap["listdata"] = &JsonCommander::executeListData;
+	commandsMap["put"] = &JsonCommander::executePut;
+	commandsMap["putdata"] = &JsonCommander::executePutdata;
+	commandsMap["get"] = &JsonCommander::executeGet;
+	commandsMap["getdata"] = &JsonCommander::executeGetdata;
+	commandsMap["head"] = &JsonCommander::executeHead;
+	commandsMap["deleteme"] = &JsonCommander::executeDeleteMe;
 }
 
 JsonCommander::~JsonCommander() {}
 
 JsonCommander::Response JsonCommander::execute(const Json::Value &message) {
-  JsonCommander::Response response;
+	JsonCommander::Response response;
 
-  Response (JsonCommander::*commandExecutor)(const Json::Value &) =
-      commandsMap[message["command"].asString()];
+	Response (JsonCommander::*commandExecutor)(const Json::Value &) = commandsMap[message["command"].asString()];
 
-  if (commandExecutor != nullptr) {
-    response = (this->*commandExecutor)(message);
-  } else {
-    // command does not exist
-    response.action = close;
-  }
+	if (commandExecutor != nullptr) {
+		response = (this->*commandExecutor)(message);
+	} else {
+		// command does not exist
+		response.action = close;
+	}
 
-  return response;
+	return response;
 }
 
-JsonCommander::Response
-JsonCommander::executeStatus(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.action = send;
-  response.json["command"] = "status";
-
-  // answer a real status message
-  std::string status;
-  if (this->fileManager.isUploading() && this->fileManager.isDownloading()) {
-    status = "download and upload running";
-  } else if (this->fileManager.isUploading()) {
-    status = "upload running";
-  } else if (this->fileManager.isDownloading()) {
-    status = "download running";
-  } else {
-    status = "ok";
-  }
-
-  response.json["response"] = status;
-
-  return response;
+JsonCommander::Response JsonCommander::executeStatus(const Json::Value &message) {
+	JsonCommander::Response response;
+	response.action = send;
+	response.json["command"] = "status";
+
+	// answer a real status message
+	std::string status;
+	if (this->fileManager.isUploading() && this->fileManager.isDownloading()) {
+		status = "download and upload running";
+	} else if (this->fileManager.isUploading()) {
+		status = "upload running";
+	} else if (this->fileManager.isDownloading()) {
+		status = "download running";
+	} else {
+		status = "ok";
+	}
+
+	response.json["response"] = status;
+
+	return response;
 }
 
-JsonCommander::Response
-JsonCommander::executeClose(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.action = closeAndSend;
-  response.json["command"] = "close";
-  response.json["response"] = "bye";
+JsonCommander::Response JsonCommander::executeClose(const Json::Value &message) {
+	JsonCommander::Response response;
+	response.action = closeAndSend;
+	response.json["command"] = "close";
+	response.json["response"] = "bye";
 
-  return response;
+	return response;
 }
 
 JsonCommander::Response JsonCommander::executeList(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.action = send;
-  response.json["command"] = "list";
-
-  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 ((chunks = fileManager.openList()) ==
-             -1) { // TODO do we need to check? maybe. Think about it
-    response.json["accept"] = false;
-    response.json["chunks"] = -1;
-    response.json["items"] = -1;
-    response.json["error"] = "there is a filename which is too long";
-  } else {
-    response.json["accept"] = true;
-    response.json["chunks"] = chunks;
-    response.json["items"] = fileManager.getListSize();
-    response.json["error"] = "";
-  }
-
-  return response;
+	JsonCommander::Response response;
+	response.action = send;
+	response.json["command"] = "list";
+
+	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 ((chunks = fileManager.openList()) == -1) { // TODO do we need to check? maybe. Think about it
+		response.json["accept"] = false;
+		response.json["chunks"] = -1;
+		response.json["items"] = -1;
+		response.json["error"] = "there is a filename which is too long";
+	} else {
+		response.json["accept"] = true;
+		response.json["chunks"] = chunks;
+		response.json["items"] = fileManager.getListSize();
+		response.json["error"] = "";
+	}
+
+	return response;
 }
 
-JsonCommander::Response
-JsonCommander::executeListData(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.action = send;
-  response.json["command"] = "listdata";
-  Json::Value array;
-
-  const int remainingListchunks = fileManager.getRemainingListChunks();
-  if (!message["chunk"].isInt() || !message["cancel"].isBool()) {
-    response.action = closeAndSend;
-    response.json["cancel"] = true;
-    response.json["remaining"] = -1;
-    response.json["names"] = Json::arrayValue;
-    response.json["error"] = "incorrect listdata command request";
-  } else if (remainingListchunks == 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"] =
-        message["chunk"].asInt(); // so it can be associated to the request
-    response.json["names"] = Json::arrayValue;
-    response.json["error"] = "";
-    fileManager.cancelList();
-  } else if (remainingListchunks - 1 != message["chunk"].asInt()) {
-    response.action = closeAndSend;
-    response.json["cancel"] = true;
-    response.json["remaining"] = -1;
-    response.json["names"] = Json::arrayValue;
-    response.json["error"] = "wrong chunk number";
-  } else {
-    std::vector<std::string> v = fileManager.getNextChunkFromList();
-    for (int i = 0; i < v.size(); i++)
-      array.append(v.at(i));
-    response.json["remaining"] = message["chunk"].asInt();
-    response.json["cancel"] = false;
-    response.json["names"] = array;
-    response.json["error"] = "";
-  }
-
-  return response;
+JsonCommander::Response JsonCommander::executeListData(const Json::Value &message) {
+	JsonCommander::Response response;
+	response.action = send;
+	response.json["command"] = "listdata";
+	Json::Value array;
+
+	const int remainingListchunks = fileManager.getRemainingListChunks();
+	if (!message["chunk"].isInt() || !message["cancel"].isBool()) {
+		response.action = closeAndSend;
+		response.json["cancel"] = true;
+		response.json["remaining"] = -1;
+		response.json["names"] = Json::arrayValue;
+		response.json["error"] = "incorrect listdata command request";
+	} else if (remainingListchunks == 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"] = message["chunk"].asInt(); // so it can be associated to the request
+		response.json["names"] = Json::arrayValue;
+		response.json["error"] = "";
+		fileManager.cancelList();
+	} else if (remainingListchunks - 1 != message["chunk"].asInt()) {
+		response.action = closeAndSend;
+		response.json["cancel"] = true;
+		response.json["remaining"] = -1;
+		response.json["names"] = Json::arrayValue;
+		response.json["error"] = "wrong chunk number";
+	} else {
+		std::vector<std::string> v = fileManager.getNextChunkFromList();
+		for (int i = 0; i < v.size(); i++)
+			array.append(v.at(i));
+		response.json["remaining"] = message["chunk"].asInt();
+		response.json["cancel"] = false;
+		response.json["names"] = array;
+		response.json["error"] = "";
+	}
+
+	return response;
 }
 
 JsonCommander::Response JsonCommander::executePut(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.json["command"] = "put";
-  response.json["file"] = message["file"].asString();
-
-  if (!message["file"].isString() || !message["size"].isInt() ||
-      !message["chunks"].isInt()) {
-    // if request is incomplete close connection
-    response.action = closeAndSend;
-    response.json["accept"] = false;
-    response.json["error"] = "incorrect put command request";
-  } else if (fileManager.isUploading()) {
-    // if an upload is alread running deny request
-    response.action = send;
-    response.json["accept"] = false;
-    response.json["error"] = "upload already running";
-  } else if (message["chunks"].asInt() <= 0) {
-    response.action = send;
-    response.json["accept"] = false;
-    response.json["error"] = "there must be at least one chunk";
-  } else if (fileManager.checkFilename(message["file"].asString())) {
-    // accept request
-    response.action = send;
-
-    bool opened = fileManager.openPutFile(message["file"].asString());
-    if (opened) {
-      response.json["accept"] = true;
-      response.json["error"] = "";
-      this->putFileReceived = message["chunks"].asInt();
-    } else {
-      response.json["accept"] = false;
-      response.json["error"] = "file already exists";
-    }
-
-  } else {
-    // deny request if file name is not valid
-    response.action = send;
-    response.json["accept"] = false;
-    response.json["error"] = "invalid file name";
-  }
-
-  return response;
+	JsonCommander::Response response;
+	response.json["command"] = "put";
+	response.json["file"] = message["file"].asString();
+
+	if (!message["file"].isString() || !message["size"].isInt() || !message["chunks"].isInt()) {
+		// if request is incomplete close connection
+		response.action = closeAndSend;
+		response.json["accept"] = false;
+		response.json["error"] = "incorrect put command request";
+	} else if (fileManager.isUploading()) {
+		// if an upload is alread running deny request
+		response.action = send;
+		response.json["accept"] = false;
+		response.json["error"] = "upload already running";
+	} else if (message["chunks"].asInt() <= 0) {
+		response.action = send;
+		response.json["accept"] = false;
+		response.json["error"] = "there must be at least one chunk";
+	} else if (fileManager.checkFilename(message["file"].asString())) {
+		// accept request
+		response.action = send;
+
+		bool opened = fileManager.openPutFile(message["file"].asString());
+		if (opened) {
+			response.json["accept"] = true;
+			response.json["error"] = "";
+			this->putFileReceived = message["chunks"].asInt();
+		} else {
+			response.json["accept"] = false;
+			response.json["error"] = "file already exists";
+		}
+
+	} else {
+		// deny request if file name is not valid
+		response.action = send;
+		response.json["accept"] = false;
+		response.json["error"] = "invalid file name";
+	}
+
+	return response;
 }
 
-JsonCommander::Response
-JsonCommander::executePutdata(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.json["command"] = "putdata";
-  response.json["file"] = message["file"].asString();
-  response.json["received"] = message["remaining"].asInt();
-
-  if (!message["file"].isString() || !message["data"].isString() ||
-      !message["remaining"].isInt() || !message["cancel"].isBool()) {
-    // if request is incomplete close connection
-    response.action = closeAndSend;
-    response.json["cancel"] = true;
-    response.json["error"] = "incorrect putdata command request";
-
-    this->fileManager.cancelPut();
-
-  } else if (!fileManager.isUploading()) {
-    // no upload running -> command
-    response.action = send;
-    response.json["cancel"] = true;
-    response.json["error"] = "no upload running";
-  } else if (message["cancel"].asBool()) {
-    response.action = send;
-    response.json["cancel"] = true;
-    response.json["error"] = "";
-
-    this->fileManager.cancelPut();
-
-  } else if (message["file"].asString().compare(
-                 fileManager.getPutBaseFileName()) == 0) {
-
-    if (--this->putFileReceived == message["remaining"].asInt()) {
-      // accept request
-      response.action = send;
-      response.json["cancel"] = false;
-      response.json["error"] = "";
-
-      const std::vector<char> data =
-          base64::decodeVector(message["data"].asString());
-
-      fileManager.writePut(data);
-
-      this->putFileReceived = message["remaining"].asInt();
-
-      if (this->putFileReceived == 0) {
-        // close file after last chunk was received
-        this->fileManager.closePutFile();
-      }
-
-    } else {
-      // wrong remaining number
-      response.action = send;
-      response.json["cancel"] = true;
-      response.json["error"] = "wrong remaining number";
-
-      this->fileManager.cancelPut();
-    }
-  } else {
-    // wrong file name
-    response.action = send;
-    response.json["cancel"] = true;
-    response.json["error"] = "another file was already being uploaded";
-
-    this->fileManager.cancelPut();
-  }
-
-  return response;
+JsonCommander::Response JsonCommander::executePutdata(const Json::Value &message) {
+	JsonCommander::Response response;
+	response.json["command"] = "putdata";
+	response.json["file"] = message["file"].asString();
+	response.json["received"] = message["remaining"].asInt();
+
+	if (!message["file"].isString() || !message["data"].isString() || !message["remaining"].isInt() || !message["cancel"].isBool()) {
+		// if request is incomplete close connection
+		response.action = closeAndSend;
+		response.json["cancel"] = true;
+		response.json["error"] = "incorrect putdata command request";
+
+		this->fileManager.cancelPut();
+
+	} else if (!fileManager.isUploading()) {
+		// no upload running -> command
+		response.action = send;
+		response.json["cancel"] = true;
+		response.json["error"] = "no upload running";
+	} else if (message["cancel"].asBool()) {
+		response.action = send;
+		response.json["cancel"] = true;
+		response.json["error"] = "";
+
+		this->fileManager.cancelPut();
+
+	} else if (message["file"].asString().compare(fileManager.getPutBaseFileName()) == 0) {
+
+		if (--this->putFileReceived == message["remaining"].asInt()) {
+			// accept request
+			response.action = send;
+			response.json["cancel"] = false;
+			response.json["error"] = "";
+
+			const std::vector<char> data = base64::decodeVector(message["data"].asString());
+
+			fileManager.writePut(data);
+
+			this->putFileReceived = message["remaining"].asInt();
+
+			if (this->putFileReceived == 0) {
+				// close file after last chunk was received
+				this->fileManager.closePutFile();
+			}
+
+		} else {
+			// wrong remaining number
+			response.action = send;
+			response.json["cancel"] = true;
+			response.json["error"] = "wrong remaining number";
+
+			this->fileManager.cancelPut();
+		}
+	} else {
+		// wrong file name
+		response.action = send;
+		response.json["cancel"] = true;
+		response.json["error"] = "another file was already being uploaded";
+
+		this->fileManager.cancelPut();
+	}
+
+	return response;
 }
 
 JsonCommander::Response JsonCommander::executeGet(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.json["command"] = "get";
-  response.json["file"] = message["file"].asString();
-
-  if (!message["file"].isString()) {
-    // if request is incomplete close connection
-    response.action = closeAndSend;
-    response.json["accept"] = false;
-    response.json["chunks"] = -1;
-    response.json["error"] = "incorrect get command request";
-  } else if (fileManager.isDownloading()) {
-    // if an upload is alread running deny request
-    response.action = send;
-    response.json["accept"] = false;
-    response.json["chunks"] = -1;
-    response.json["error"] = "download already running";
-  } else if (fileManager.checkFilename(message["file"].asString())) {
-    // accept request
-    response.action = send;
-
-    std::pair<bool, int> opened =
-        fileManager.openGetFile(message["file"].asString());
-
-    if (opened.first) {
-      this->getFileRemaining = opened.second;
-      response.json["accept"] = true;
-      response.json["chunks"] = this->getFileRemaining;
-      response.json["error"] = "";
-    } else {
-      response.json["accept"] = false;
-      response.json["chunks"] = -1;
-      response.json["error"] = "file does not exist";
-    }
-
-  } else {
-    // deny request if file name is not valid
-    response.action = send;
-    response.json["accept"] = false;
-    response.json["chunks"] = -1;
-    response.json["error"] = "invalid file name";
-  }
-
-  return response;
+	JsonCommander::Response response;
+	response.json["command"] = "get";
+	response.json["file"] = message["file"].asString();
+
+	if (!message["file"].isString()) {
+		// if request is incomplete close connection
+		response.action = closeAndSend;
+		response.json["accept"] = false;
+		response.json["chunks"] = -1;
+		response.json["error"] = "incorrect get command request";
+	} else if (fileManager.isDownloading()) {
+		// if an upload is alread running deny request
+		response.action = send;
+		response.json["accept"] = false;
+		response.json["chunks"] = -1;
+		response.json["error"] = "download already running";
+	} else if (fileManager.checkFilename(message["file"].asString())) {
+		// accept request
+		response.action = send;
+
+		std::pair<bool, int> opened = fileManager.openGetFile(message["file"].asString());
+
+		if (opened.first) {
+			this->getFileRemaining = opened.second;
+			response.json["accept"] = true;
+			response.json["chunks"] = this->getFileRemaining;
+			response.json["error"] = "";
+		} else {
+			response.json["accept"] = false;
+			response.json["chunks"] = -1;
+			response.json["error"] = "file does not exist";
+		}
+
+	} else {
+		// deny request if file name is not valid
+		response.action = send;
+		response.json["accept"] = false;
+		response.json["chunks"] = -1;
+		response.json["error"] = "invalid file name";
+	}
+
+	return response;
 }
 
-JsonCommander::Response
-JsonCommander::executeGetdata(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.json["command"] = "getdata";
-  response.json["file"] = message["file"].asString();
-  response.json["remaining"] = message["chunk"].asInt();
-
-  if (!message["file"].isString() || !message["chunk"].isInt() ||
-      !message["cancel"].isBool()) {
-    // if request is incomplete close connection
-    response.action = closeAndSend;
-    response.json["cancel"] = true;
-    response.json["data"] = "";
-    response.json["error"] = "incorrect putdata command request";
-
-    this->fileManager.closeGetFile();
-
-  } else if (!fileManager.isDownloading()) {
-    // no upload running -> command
-    response.action = send;
-    response.json["cancel"] = true;
-    response.json["data"] = "";
-    response.json["error"] = "no download running";
-  } else if (message["cancel"].asBool()) {
-    response.action = send;
-    response.json["cancel"] = true;
-    response.json["data"] = "";
-    response.json["error"] = "";
-
-    this->fileManager.closeGetFile();
-
-  } else if (message["file"].asString().compare(
-                 fileManager.getGetBaseFileName()) == 0) {
-
-    if (--this->getFileRemaining == message["chunk"].asInt()) {
-      // accept request
-      response.action = send;
-      response.json["cancel"] = false;
-      response.json["error"] = "";
-
-      const std::vector<char> data = fileManager.readGet();
-      response.json["data"] = base64::encodeVector(data);
-
-      fileManager.writePut(data);
-
-      if (this->getFileRemaining == 0) {
-        // close file after last chunk was sent
-        this->fileManager.closeGetFile();
-      }
-
-    } else {
-      // wrong chunk number
-      response.action = send;
-      response.json["cancel"] = true;
-      response.json["data"] = "";
-      response.json["error"] = "wrong chunk number";
-
-      this->fileManager.closeGetFile();
-    }
-  } else {
-    // wrong file name
-    response.action = send;
-    response.json["cancel"] = true;
-    response.json["data"] = "";
-    response.json["error"] = "another file was already being downloaded";
-
-    this->fileManager.closeGetFile();
-  }
-
-  return response;
+JsonCommander::Response JsonCommander::executeGetdata(const Json::Value &message) {
+	JsonCommander::Response response;
+	response.json["command"] = "getdata";
+	response.json["file"] = message["file"].asString();
+	response.json["remaining"] = message["chunk"].asInt();
+
+	if (!message["file"].isString() || !message["chunk"].isInt() || !message["cancel"].isBool()) {
+		// if request is incomplete close connection
+		response.action = closeAndSend;
+		response.json["cancel"] = true;
+		response.json["data"] = "";
+		response.json["error"] = "incorrect putdata command request";
+
+		this->fileManager.closeGetFile();
+
+	} else if (!fileManager.isDownloading()) {
+		// no upload running -> command
+		response.action = send;
+		response.json["cancel"] = true;
+		response.json["data"] = "";
+		response.json["error"] = "no download running";
+	} else if (message["cancel"].asBool()) {
+		response.action = send;
+		response.json["cancel"] = true;
+		response.json["data"] = "";
+		response.json["error"] = "";
+
+		this->fileManager.closeGetFile();
+
+	} else if (message["file"].asString().compare(fileManager.getGetBaseFileName()) == 0) {
+
+		if (--this->getFileRemaining == message["chunk"].asInt()) {
+			// accept request
+			response.action = send;
+			response.json["cancel"] = false;
+			response.json["error"] = "";
+
+			const std::vector<char> data = fileManager.readGet();
+			response.json["data"] = base64::encodeVector(data);
+
+			fileManager.writePut(data);
+
+			if (this->getFileRemaining == 0) {
+				// close file after last chunk was sent
+				this->fileManager.closeGetFile();
+			}
+
+		} else {
+			// wrong chunk number
+			response.action = send;
+			response.json["cancel"] = true;
+			response.json["data"] = "";
+			response.json["error"] = "wrong chunk number";
+
+			this->fileManager.closeGetFile();
+		}
+	} else {
+		// wrong file name
+		response.action = send;
+		response.json["cancel"] = true;
+		response.json["data"] = "";
+		response.json["error"] = "another file was already being downloaded";
+
+		this->fileManager.closeGetFile();
+	}
+
+	return response;
 }
 
 JsonCommander::Response JsonCommander::executeHead(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.action = send;
-  response.json["command"] = "head";
-
-  if (!message["file"].isString()) {
-    response.json["accept"] = false;
-    response.json["file"] = "";
-    response.json["data"] = "";
-    response.json["error"] = "incorrect head command request";
-  } else {
-    std::pair<std::vector<char>, FileManager::headError> res =
-        fileManager.getBytesFromFile(message["file"].asString(), 4);
-    if (res.second == FileManager::headError::no_error) {
-      response.json["accept"] = true;
-      response.json["file"] = message["file"].asString();
-      response.json["data"] = base64::encodeVector(res.first);
-      response.json["error"] = "";
-    } else if (res.second == FileManager::headError::no_such_file) {
-      response.json["accept"] = false;
-      response.json["file"] = message["file"].asString();
-      response.json["data"] = "";
-      response.json["error"] = "no such file";
-    } else {
-      response.json["accept"] = false;
-      response.json["file"] = message["file"].asString();
-      response.json["data"] = "";
-      response.json["error"] = "file is smaller than specified size";
-    }
-  }
-
-  return response;
+	JsonCommander::Response response;
+	response.action = send;
+	response.json["command"] = "head";
+
+	if (!message["file"].isString()) {
+		response.json["accept"] = false;
+		response.json["file"] = "";
+		response.json["data"] = "";
+		response.json["error"] = "incorrect head command request";
+	} else {
+		std::pair<std::vector<char>, FileManager::headError> res = fileManager.getBytesFromFile(message["file"].asString(), 4);
+		if (res.second == FileManager::headError::no_error) {
+			response.json["accept"] = true;
+			response.json["file"] = message["file"].asString();
+			response.json["data"] = base64::encodeVector(res.first);
+			response.json["error"] = "";
+		} else if (res.second == FileManager::headError::no_such_file) {
+			response.json["accept"] = false;
+			response.json["file"] = message["file"].asString();
+			response.json["data"] = "";
+			response.json["error"] = "no such file";
+		} else {
+			response.json["accept"] = false;
+			response.json["file"] = message["file"].asString();
+			response.json["data"] = "";
+			response.json["error"] = "file is smaller than specified size";
+		}
+	}
+
+	return response;
 }
 
-JsonCommander::Response
-JsonCommander::executeDeleteMe(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.json["command"] = "deleteme";
-
-  if (!message["pass"].isString()) {
-    response.action = send;
-    response.json["accept"] = false;
-    response.json["error"] = "incorrect deleteme command request";
-  } else if (UserManager::deleteUser(currentUser, message["pass"].asString())) {
-    // success
-    response.action = closeAndSend;
-    response.json["accept"] = true;
-    response.json["error"] = "";
-  } else {
-    response.action = send;
-    response.json["accept"] = false;
-    response.json["error"] = "wrong password";
-  }
-
-  return response;
+JsonCommander::Response JsonCommander::executeDeleteMe(const Json::Value &message) {
+	JsonCommander::Response response;
+	response.json["command"] = "deleteme";
+
+	if (!message["pass"].isString()) {
+		response.action = send;
+		response.json["accept"] = false;
+		response.json["error"] = "incorrect deleteme command request";
+	} else if (UserManager::deleteUser(currentUser, message["pass"].asString())) {
+		// success
+		response.action = closeAndSend;
+		response.json["accept"] = true;
+		response.json["error"] = "";
+	} else {
+		response.action = send;
+		response.json["accept"] = false;
+		response.json["error"] = "wrong password";
+	}
+
+	return response;
 }
 
 JsonCommander::Response JsonCommander::testVersion(const Json::Value &message) {
-  JsonCommander::Response response;
-  response.json["version"] = this->protocolVersion;
-
-  // check version string is the same
-  if (message["version"].asString().compare(this->protocolVersion) == 0) {
-    response.action = send;
-    response.json["accept"] = true;
-  } else {
-    response.action = closeAndSend;
-    response.json["accept"] = false;
-  }
-
-  return response;
+	JsonCommander::Response response;
+	response.json["version"] = this->protocolVersion;
+
+	// check version string is the same
+	if (message["version"].asString().compare(this->protocolVersion) == 0) {
+		response.action = send;
+		response.json["accept"] = true;
+	} else {
+		response.action = closeAndSend;
+		response.json["accept"] = false;
+	}
+
+	return response;
 }
 
 JsonCommander::Response JsonCommander::checkLogin(const Json::Value &message) {
-  JsonCommander::Response response;
-
-  if (!message["login"].isBool() || !message["user"].isString() ||
-      !message["pass"].isString() || !message["cancel"].isBool()) {
-    // invalid login request
-    response.action = closeAndSend;
-    response.json["accept"] = false;
-    response.json["error"] = "invalid login request";
-  } else if (message["cancel"].asBool()) {
-    response.action = close;
-
-  } else if (message["login"].asBool() &&
-             UserManager::isAllowed(message["user"].asString(),
-                                    message["pass"].asString())) {
-    // credential check
-    response.action = send;
-    response.json["accept"] = true;
-    response.json["error"] = "";
-    currentUser = message["user"].asString();
-  } else if (!message["login"].asBool()) {
-    // add user. Check if already exists before
-    if (!UserManager::addUser(message["user"].asString(),
-                              message["pass"].asString())) {
-      response.action = closeAndSend;
-      response.json["accept"] = false;
-      response.json["error"] = "user does already exist";
-    } else {
-      response.action = send;
-      response.json["accept"] = true;
-      response.json["error"] = "";
-      currentUser = message["user"].asString();
-    }
-  } else {
-    // reject user
-    response.action = closeAndSend;
-    response.json["accept"] = false;
-    response.json["error"] = "wrong username or password";
-  }
-
-  return response;
+	JsonCommander::Response response;
+
+	if (!message["login"].isBool() || !message["user"].isString() || !message["pass"].isString() || !message["cancel"].isBool()) {
+		// invalid login request
+		response.action = closeAndSend;
+		response.json["accept"] = false;
+		response.json["error"] = "invalid login request";
+	} else if (message["cancel"].asBool()) {
+		response.action = close;
+
+	} else if (message["login"].asBool() && UserManager::isAllowed(message["user"].asString(), message["pass"].asString())) {
+		// credential check
+		response.action = send;
+		response.json["accept"] = true;
+		response.json["error"] = "";
+		currentUser = message["user"].asString();
+	} else if (!message["login"].asBool()) {
+		// add user. Check if already exists before
+		if (!UserManager::addUser(message["user"].asString(), message["pass"].asString())) {
+			response.action = closeAndSend;
+			response.json["accept"] = false;
+			response.json["error"] = "user does already exist";
+		} else {
+			response.action = send;
+			response.json["accept"] = true;
+			response.json["error"] = "";
+			currentUser = message["user"].asString();
+		}
+	} else {
+		// reject user
+		response.action = closeAndSend;
+		response.json["accept"] = false;
+		response.json["error"] = "wrong username or password";
+	}
+
+	return response;
 }

+ 112 - 133
daemon/src/Server.cpp

@@ -11,153 +11,139 @@ using ip::tcp;
  * con_handler *
  ***************/
 
-con_handler::con_handler(
-    basic_socket_acceptor<ip::tcp>::executor_type &io_service)
-    : sock(io_service), buf(max_length), jsonCommander(fileManager) {
-  // disable indentation for json
-  this->jsonStringBuilder.settings_["indentation"] = "";
-
-  // init reader to parse json
-  Json::CharReaderBuilder builder;
-  jsonReader = std::unique_ptr<Json::CharReader>(builder.newCharReader());
+con_handler::con_handler(basic_socket_acceptor<ip::tcp>::executor_type &io_service) : sock(io_service), buf(max_length), jsonCommander(fileManager) {
+	// disable indentation for json
+	this->jsonStringBuilder.settings_["indentation"] = "";
+
+	// init reader to parse json
+	Json::CharReaderBuilder builder;
+	jsonReader = std::unique_ptr<Json::CharReader>(builder.newCharReader());
 }
 
 con_handler::~con_handler() {}
 
-con_handler::pointer
-con_handler::create(basic_socket_acceptor<ip::tcp>::executor_type &io_service) {
-  return pointer(new con_handler(io_service));
-}
+con_handler::pointer con_handler::create(basic_socket_acceptor<ip::tcp>::executor_type &io_service) { return pointer(new con_handler(io_service)); }
 
 tcp::socket &con_handler::socket() { return sock; }
 
 void con_handler::start() { read(&con_handler::handle_read_version); }
 
-void con_handler::handle_read_version(const boost::system::error_code &err,
-                                      size_t bytes_transferred) {
-  if (!err) {
-    // set up json stuff
-    Json::Value root = parseMessage();
-
-    JsonCommander::Response response = this->jsonCommander.testVersion(root);
-
-    switch (response.action) {
-    case JsonCommander::Action::send:
-      read(&con_handler::handle_read_login);
-      sendJson(response.json);
-      break;
-    case JsonCommander::Action::closeAndSend:
-      sendJson(response.json);
-    default:
-      sock.close();
-    }
-
-  } else {
-    std::cerr << "error: " << err.message() << std::endl;
-    sock.close();
-  }
+void con_handler::handle_read_version(const boost::system::error_code &err, size_t bytes_transferred) {
+	if (!err) {
+		// set up json stuff
+		Json::Value root = parseMessage();
+
+		JsonCommander::Response response = this->jsonCommander.testVersion(root);
+
+		switch (response.action) {
+		case JsonCommander::Action::send:
+			read(&con_handler::handle_read_login);
+			sendJson(response.json);
+			break;
+		case JsonCommander::Action::closeAndSend:
+			sendJson(response.json);
+		default:
+			sock.close();
+		}
+
+	} else {
+		std::cerr << "error: " << err.message() << std::endl;
+		sock.close();
+	}
 }
 
-void con_handler::handle_read_login(const boost::system::error_code &err,
-                                    size_t bytes_transferred) {
-  if (!err) {
-    // set up json stuff
-    Json::Value root = parseMessage();
-
-    JsonCommander::Response response = this->jsonCommander.checkLogin(root);
-
-    switch (response.action) {
-    case JsonCommander::Action::send:
-      read(&con_handler::handle_read_command);
-      sendJson(response.json);
-      break;
-    case JsonCommander::Action::closeAndSend:
-      sendJson(response.json);
-    default:
-      sock.close();
-    }
-
-  } else {
-    std::cerr << "error: " << err.message() << std::endl;
-    sock.close();
-  }
+void con_handler::handle_read_login(const boost::system::error_code &err, size_t bytes_transferred) {
+	if (!err) {
+		// set up json stuff
+		Json::Value root = parseMessage();
+
+		JsonCommander::Response response = this->jsonCommander.checkLogin(root);
+
+		switch (response.action) {
+		case JsonCommander::Action::send:
+			read(&con_handler::handle_read_command);
+			sendJson(response.json);
+			break;
+		case JsonCommander::Action::closeAndSend:
+			sendJson(response.json);
+		default:
+			sock.close();
+		}
+
+	} else {
+		std::cerr << "error: " << err.message() << std::endl;
+		sock.close();
+	}
 }
 
-void con_handler::handle_read_command(const boost::system::error_code &err,
-                                      size_t bytes_transferred) {
-  if (!err) {
-    // set up json stuff
-    Json::Value root = parseMessage();
-
-    JsonCommander::Response response = this->jsonCommander.execute(root);
-
-    switch (response.action) {
-    case JsonCommander::Action::send:
-      read(&con_handler::handle_read_command);
-      sendJson(response.json);
-      break;
-    case JsonCommander::Action::closeAndSend:
-      sendJson(response.json);
-    default:
-      sock.close();
-    }
-
-  } else {
-    std::cerr << "error: " << err.message() << std::endl;
-    sock.close();
-  }
+void con_handler::handle_read_command(const boost::system::error_code &err, size_t bytes_transferred) {
+	if (!err) {
+		// set up json stuff
+		Json::Value root = parseMessage();
+
+		JsonCommander::Response response = this->jsonCommander.execute(root);
+
+		switch (response.action) {
+		case JsonCommander::Action::send:
+			read(&con_handler::handle_read_command);
+			sendJson(response.json);
+			break;
+		case JsonCommander::Action::closeAndSend:
+			sendJson(response.json);
+		default:
+			sock.close();
+		}
+
+	} else {
+		std::cerr << "error: " << err.message() << std::endl;
+		sock.close();
+	}
 }
 
-void con_handler::handle_write(const boost::system::error_code &err,
-                               size_t bytes_transferred) {
-  if (!err) {
-    std::cout << "Hello World!" << std::endl;
-  } else {
-    std::cerr << "error: " << err.message() << std::endl;
-    sock.close();
-  }
+void con_handler::handle_write(const boost::system::error_code &err, size_t bytes_transferred) {
+	if (!err) {
+		std::cout << "Hello World!" << std::endl;
+	} else {
+		std::cerr << "error: " << err.message() << std::endl;
+		sock.close();
+	}
 }
 
-void con_handler::read(void (con_handler::*handler)(
-    const boost::system::error_code &err, size_t bytes_transferred)) {
-  /*sock.async_read_some(buffer(data, max_length),
-                       boost::bind(handler, shared_from_this(),
-                                   placeholders::error,
-                                   placeholders::bytes_transferred));*/
+void con_handler::read(void (con_handler::*handler)(const boost::system::error_code &err, size_t bytes_transferred)) {
+	/*sock.async_read_some(buffer(data, max_length),
+	                     boost::bind(handler, shared_from_this(),
+	                                 placeholders::error,
+	                                 placeholders::bytes_transferred));*/
 
-  async_read_until(sock, buf, '\n',
-                   bind(handler, shared_from_this(), placeholders::error,
-                        placeholders::bytes_transferred));
+	async_read_until(sock, buf, '\n', bind(handler, shared_from_this(), placeholders::error, placeholders::bytes_transferred));
 }
 
 void con_handler::sendJson(const Json::Value &json) {
-  std::string jsonString = Json::writeString(jsonStringBuilder, json);
-  jsonString.append("\n");
+	std::string jsonString = Json::writeString(jsonStringBuilder, json);
+	jsonString.append("\n");
 
-  sock.async_write_some(buffer(jsonString, max_length),
-                        boost::bind(&con_handler::handle_write,
-                                    shared_from_this(), placeholders::error,
-                                    placeholders::bytes_transferred));
+	sock.async_write_some(buffer(jsonString, max_length),
+	                      boost::bind(&con_handler::handle_write, shared_from_this(), placeholders::error, placeholders::bytes_transferred));
 }
 
 Json::Value con_handler::parseMessage() {
-  const char *data = buffer_cast<const char *>(buf.data());
+	const char *data = buffer_cast<const char *>(buf.data());
 
-  std::string dataStr(data, buf.size());
-  const int lineEnd = dataStr.find('\n');
+	std::string dataStr(data, buf.size());
+	const int lineEnd = dataStr.find('\n');
 
-  JSONCPP_STRING err;
-  Json::Value root;
+	JSONCPP_STRING err;
+	Json::Value root;
 
-  // parse data
-  if (!this->jsonReader->parse(data, data + lineEnd, &root, &err)) {
-    std::cerr << "Json error: " << err << std::endl << "data: " << data;
-    sock.close();
-  }
+	// parse data
+	if (!this->jsonReader->parse(data, data + lineEnd, &root, &err)) {
+		std::cerr << "Json error: " << err << std::endl << "data: " << data;
+		sock.close();
+	}
 
-  buf.consume(lineEnd + 1);
+	buf.consume(lineEnd + 1);
 
-  return root;
+	return root;
 }
 
 /**********
@@ -165,25 +151,18 @@ Json::Value con_handler::parseMessage() {
  **********/
 
 void Server::start_accept() {
-  auto executor = acceptor_.get_executor();
-  con_handler::pointer connection = con_handler::create(executor);
-  acceptor_.async_accept(connection->socket(),
-                         boost::bind(&Server::handle_accept, this, connection,
-                                     placeholders::error));
+	auto executor = acceptor_.get_executor();
+	con_handler::pointer connection = con_handler::create(executor);
+	acceptor_.async_accept(connection->socket(), boost::bind(&Server::handle_accept, this, connection, placeholders::error));
 }
 
-Server::Server(io_service &io_service)
-    : acceptor_(io_service,
-                tcp::endpoint(tcp::v4(), std::stoi(Config::getValue("port")))) {
-  start_accept();
-}
+Server::Server(io_service &io_service) : acceptor_(io_service, tcp::endpoint(tcp::v4(), std::stoi(Config::getValue("port")))) { start_accept(); }
 
 Server::~Server() {}
 
-void Server::handle_accept(con_handler::pointer connection,
-                           const boost::system::error_code &err) {
-  if (!err) {
-    connection->start();
-  }
-  start_accept();
+void Server::handle_accept(con_handler::pointer connection, const boost::system::error_code &err) {
+	if (!err) {
+		connection->start();
+	}
+	start_accept();
 }

+ 17 - 22
daemon/src/Sniffer.cpp

@@ -3,36 +3,31 @@
 #include <iostream>
 
 Sniffer::Sniffer(const std::string &interfaceName) {
-  Tins::SnifferConfiguration config;
-  config.set_promisc_mode(true);
-
-  try {
-    sniffer = new Tins::Sniffer(interfaceName, config);
-  } catch (const Tins::pcap_error &e) {
-    std::cerr << "An error accured setting up the sniffer: " << e.what()
-              << std::endl;
-    std::exit(EXIT_FAILURE);
-  }
+	Tins::SnifferConfiguration config;
+	config.set_promisc_mode(true);
+
+	try {
+		sniffer = new Tins::Sniffer(interfaceName, config);
+	} catch (const Tins::pcap_error &e) {
+		std::cerr << "An error accured setting up the sniffer: " << e.what() << std::endl;
+		std::exit(EXIT_FAILURE);
+	}
 }
 
 Sniffer::~Sniffer() {
-  sniffer->stop_sniff();
-  delete (sniffer);
+	sniffer->stop_sniff();
+	delete (sniffer);
 }
 
-void Sniffer::startSniffing() {
-  sniffer->sniff_loop(make_sniffer_handler(this, &Sniffer::handle));
-}
+void Sniffer::startSniffing() { sniffer->sniff_loop(make_sniffer_handler(this, &Sniffer::handle)); }
 
-void Sniffer::setFilter(const std::string &filterString) {
-  sniffer->set_filter(filterString);
-}
+void Sniffer::setFilter(const std::string &filterString) { sniffer->set_filter(filterString); }
 
 bool Sniffer::handle(Tins::PDU &pdu) {
-  // TODO implement handler for sniffed traffic
+	// TODO implement handler for sniffed traffic
 
-  std::cout << "packet sniffed" << std::endl;
+	std::cout << "packet sniffed" << std::endl;
 
-  return false; // will stop sniffing after the first packet because this
-                // handler returns false
+	return false; // will stop sniffing after the first packet because this
+	              // handler returns false
 }

+ 60 - 61
daemon/src/UserManager.cpp

@@ -7,82 +7,81 @@
 std::string UserManager::filename = "";
 
 void UserManager::init(const std::string &file) {
-  filename = file;
-  std::ifstream ifile(filename);
-  if (!ifile.is_open()) {
-    // create new file if userStorage does not exist
-    std::ofstream ofile;
-    ofile.open(filename);
-    ofile << "user;pass\n";
-    ofile.close();
-    std::cout << "Created \"" << filename << "\" and added the default user"
-              << std::endl;
-  }
-  ifile.close();
+	filename = file;
+	std::ifstream ifile(filename);
+	if (!ifile.is_open()) {
+		// create new file if userStorage does not exist
+		std::ofstream ofile;
+		ofile.open(filename);
+		ofile << "user;pass\n";
+		ofile.close();
+		std::cout << "Created \"" << filename << "\" and added the default user" << std::endl;
+	}
+	ifile.close();
 }
 
 bool UserManager::isAllowed(const std::string &name, const std::string &pw) {
-  std::map<std::string, std::string> user_map;
-  readFromFile(user_map);
-  auto it = user_map.find(name);
-  // check if user exists and pw is equal
-  if (it != user_map.end() && (it->second.compare(pw) == 0)) {
-    return true;
-  }
-  return false;
+	std::map<std::string, std::string> user_map;
+	readFromFile(user_map);
+	auto it = user_map.find(name);
+	// check if user exists and pw is equal
+	if (it != user_map.end() && (it->second.compare(pw) == 0)) {
+		return true;
+	}
+	return false;
 }
 
 bool UserManager::addUser(const std::string &name, const std::string &pw) {
-  std::map<std::string, std::string> user_map;
-  readFromFile(user_map);
-  auto it = user_map.find(name);
-  // if user exists, do nothing
-  if (it != user_map.end()) {
-    return false;
-  }
-  user_map.insert(std::pair<std::string, std::string>(name, pw));
-  writeToFile(user_map);
-  return true;
+	std::map<std::string, std::string> user_map;
+	readFromFile(user_map);
+	auto it = user_map.find(name);
+	// if user exists, do nothing
+	if (it != user_map.end()) {
+		return false;
+	}
+	user_map.insert(std::pair<std::string, std::string>(name, pw));
+	writeToFile(user_map);
+	return true;
 }
 
 bool UserManager::deleteUser(const std::string &name, const std::string &pw) {
-  // TODO check pw before delete
-  std::map<std::string, std::string> user_map;
-  readFromFile(user_map);
-  auto it = user_map.find(name);
-  if (it == user_map.end()) {
-    return false;
-  }
-  if (it->second.compare(pw) != 0) {
-    return false;
-  }
-  user_map.erase(it);
-  writeToFile(user_map);
-  return true;
+	// TODO check pw before delete
+	std::map<std::string, std::string> user_map;
+	readFromFile(user_map);
+	auto it = user_map.find(name);
+	if (it == user_map.end()) {
+		return false;
+	}
+	if (it->second.compare(pw) != 0) {
+		return false;
+	}
+	user_map.erase(it);
+	writeToFile(user_map);
+	return true;
 }
 
 // read content from file into given map
 void UserManager::readFromFile(std::map<std::string, std::string> &user_map) {
-  std::ifstream ifile(filename);
-  std::string line;
-  while (getline(ifile, line)) {
-    std::stringstream ss(line);
-    std::string segment;
-    std::vector<std::string> v;
-    while (std::getline(ss, segment, ';')) {
-      v.push_back(segment);
-    }
-    user_map.insert(std::pair<std::string, std::string>(v.at(0), v.at(1)));
-  }
-  ifile.close();
+	std::ifstream ifile(filename);
+	std::string line;
+	while (getline(ifile, line)) {
+		std::stringstream ss(line);
+		std::string segment;
+		std::vector<std::string> v;
+		while (std::getline(ss, segment, ';')) {
+			v.push_back(segment);
+		}
+		user_map.insert(std::pair<std::string, std::string>(v.at(0), v.at(1)));
+	}
+	ifile.close();
 }
 
 // write content from map to file
 void UserManager::writeToFile(std::map<std::string, std::string> &user_map) {
-  std::ofstream file;
-  file.open(filename);
-  for (auto const &x : user_map) {
-    file << x.first << ";" << x.second << std::endl;
-  }
-  file.close();
+	std::ofstream file;
+	file.open(filename);
+	for (auto const &x : user_map) {
+		file << x.first << ";" << x.second << std::endl;
+	}
+	file.close();
 }

+ 20 - 26
daemon/src/base64.cpp

@@ -3,47 +3,41 @@
 #include <boost/beast.hpp>
 
 std::string base64::decode(const std::string &val) {
-  std::string ret;
-  ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
+	std::string ret;
+	ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
 
-  std::size_t read = boost::beast::detail::base64::decode(
-                         &ret.front(), val.c_str(), val.size())
-                         .first;
+	std::size_t read = boost::beast::detail::base64::decode(&ret.front(), val.c_str(), val.size()).first;
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }
 
 std::vector<char> base64::decodeVector(const std::string &val) {
-  std::vector<char> ret;
-  ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
+	std::vector<char> ret;
+	ret.resize(boost::beast::detail::base64::decoded_size(val.size()));
 
-  std::size_t read =
-      boost::beast::detail::base64::decode(ret.data(), val.c_str(), val.size())
-          .first;
+	std::size_t read = boost::beast::detail::base64::decode(ret.data(), val.c_str(), val.size()).first;
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }
 
 std::string base64::encode(const std::string &val) {
-  std::string ret;
-  ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
+	std::string ret;
+	ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
 
-  std::size_t read = boost::beast::detail::base64::encode(
-      &ret.front(), val.data(), val.size());
+	std::size_t read = boost::beast::detail::base64::encode(&ret.front(), val.data(), val.size());
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }
 
 std::string base64::encodeVector(const std::vector<char> &val) {
-  std::string ret;
-  ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
+	std::string ret;
+	ret.resize(boost::beast::detail::base64::encoded_size(val.size()));
 
-  std::size_t read = boost::beast::detail::base64::encode(
-      &ret.front(), val.data(), val.size());
+	std::size_t read = boost::beast::detail::base64::encode(&ret.front(), val.data(), val.size());
 
-  ret.resize(read);
-  return ret;
+	ret.resize(read);
+	return ret;
 }

+ 26 - 26
daemon/src/main.cpp

@@ -9,30 +9,30 @@
 using namespace std;
 
 int main(int argc, char *argv[]) {
-  // load config int namespace
-  if (!Config::init("config.txt")) {
-    cerr << "configuration could not be loaded properly" << endl;
-    exit(EXIT_FAILURE);
-  }
-
-  const string interface = Config::getValue("interface");
-
-  // check if userStorage is add specified location
-  // if not create one
-  UserManager::init(Config::getValue("userdatabase"));
-
-  Sniffer *sniffer = new Sniffer(interface);
-  thread snifferThread(&Sniffer::startSniffing, sniffer);
-
-  try {
-    io_service io_service;
-    Server server(io_service);
-    io_service.run();
-  } catch (exception &e) {
-    cerr << e.what() << endl;
-  }
-
-  snifferThread.join();
-  delete (sniffer);
-  return 0;
+	// load config int namespace
+	if (!Config::init("config.txt")) {
+		cerr << "configuration could not be loaded properly" << endl;
+		exit(EXIT_FAILURE);
+	}
+
+	const string interface = Config::getValue("interface");
+
+	// check if userStorage is add specified location
+	// if not create one
+	UserManager::init(Config::getValue("userdatabase"));
+
+	Sniffer *sniffer = new Sniffer(interface);
+	thread snifferThread(&Sniffer::startSniffing, sniffer);
+
+	try {
+		io_service io_service;
+		Server server(io_service);
+		io_service.run();
+	} catch (exception &e) {
+		cerr << e.what() << endl;
+	}
+
+	snifferThread.join();
+	delete (sniffer);
+	return 0;
 }

+ 5 - 5
daemon/test/ConfigMock.cpp

@@ -7,10 +7,10 @@ std::map<std::string, std::string> storage;
 bool Config::init(const std::string &filename) { return true; }
 
 std::string Config::getValue(const std::string &key) {
-  auto it = storage.find(key);
-  if (it != storage.end()) {
-    return it->second;
-  }
+	auto it = storage.find(key);
+	if (it != storage.end()) {
+		return it->second;
+	}
 
-  return "";
+	return "";
 }

+ 693 - 719
daemon/test/JsonCommanderTest.cpp

@@ -7,894 +7,868 @@
 namespace {
 /* Version tests */
 TEST(testVersion, Positive) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string versionString = "0.2";
-  Json::Value version;
-  version["version"] = versionString;
+	const std::string versionString = "0.2";
+	Json::Value version;
+	version["version"] = versionString;
 
-  JsonCommander::Response response = jsonCommander.testVersion(version);
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["version"].asString(), versionString);
+	JsonCommander::Response response = jsonCommander.testVersion(version);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["version"].asString(), versionString);
 }
 
 TEST(testVersion, Negative) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string versionString = "0.1";
-  Json::Value version;
-  version["version"] = versionString;
+	const std::string versionString = "0.1";
+	Json::Value version;
+	version["version"] = versionString;
 
-  JsonCommander::Response response = jsonCommander.testVersion(version);
-  EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
-  EXPECT_FALSE(response.json["accept"].asBool());
-  EXPECT_FALSE(response.json["version"].asString().compare(versionString) == 0);
+	JsonCommander::Response response = jsonCommander.testVersion(version);
+	EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_FALSE(response.json["version"].asString().compare(versionString) == 0);
 }
 
 /* Status tests */
 TEST(Status, Ok) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "status";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "status";
+	Json::Value message;
+	message["command"] = command;
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_EQ(response.json["response"].asString(), "ok");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_EQ(response.json["response"].asString(), "ok");
 }
 
 TEST(Status, Downloading) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "status";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "status";
+	Json::Value message;
+	message["command"] = command;
 
-  ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_EQ(response.json["response"].asString(), "download running");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_EQ(response.json["response"].asString(), "download running");
 }
 
 TEST(Status, Uploading) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "status";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "status";
+	Json::Value message;
+	message["command"] = command;
 
-  ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_EQ(response.json["response"].asString(), "upload running");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_EQ(response.json["response"].asString(), "upload running");
 }
 
 TEST(Status, UploadingAndDownloading) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "status";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "status";
+	Json::Value message;
+	message["command"] = command;
 
-  ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
-  ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_EQ(response.json["response"].asString(),
-            "download and upload running");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_EQ(response.json["response"].asString(), "download and upload running");
 }
 
 /* Close tests */
 TEST(Close, Close) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "close";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "close";
+	Json::Value message;
+	message["command"] = command;
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_EQ(response.json["response"].asString(), "bye");
+	EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_EQ(response.json["response"].asString(), "bye");
 }
 
 /* Put tests */
 TEST(Put, Positive) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "put";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-  message["size"] = 1337;
-  message["chunks"] = 1;
+	const std::string command = "put";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+	message["size"] = 1337;
+	message["chunks"] = 1;
 
-  ON_CALL(fileManager, openPutFile(testing::_))
-      .WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["error"].asString(), "");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["error"].asString(), "");
 }
 
 TEST(Put, Negative) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "put";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-  message["size"] = 1337;
-  message["chunks"] = 1;
+	const std::string command = "put";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+	message["size"] = 1337;
+	message["chunks"] = 1;
 
-  ON_CALL(fileManager, openPutFile(testing::_))
-      .WillByDefault(testing::Return(false));
+	ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(false));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_TRUE(response.json["error"].asString().length() > 0);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_TRUE(response.json["error"].asString().length() > 0);
 }
 
 /* Putdata tests */
 TEST(Putdata, Positive) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  /* start with put */
-  std::string command = "put";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-  message["size"] = 1337;
-  const int chunks = 3;
-  message["chunks"] = chunks;
-
-  ON_CALL(fileManager, openPutFile(testing::_))
-      .WillByDefault(testing::Return(true));
-
-  JsonCommander::Response response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  /* putdata */
-  command = "putdata";
-
-  ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
-  ON_CALL(fileManager, getPutBaseFileName())
-      .WillByDefault(testing::Return(filename));
-
-  for (int remaining = chunks - 1; remaining >= 0; remaining--) {
-    message = Json::Value();
-    message["command"] = command;
-    message["file"] = filename;
-    message["data"] = "MTMzNw==";
-    message["remaining"] = remaining;
-    message["cancel"] = false;
-
-    response = jsonCommander.execute(message);
-
-    EXPECT_TRUE(response.action == JsonCommander::Action::send);
-    EXPECT_EQ(response.json["command"].asString(), command);
-    EXPECT_FALSE(response.json["cancel"].asBool());
-    EXPECT_EQ(response.json["received"].asInt(), remaining);
-    EXPECT_EQ(response.json["file"].asString(), filename);
-    EXPECT_EQ(response.json["error"].asString(), "");
-  }
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	/* start with put */
+	std::string command = "put";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+	message["size"] = 1337;
+	const int chunks = 3;
+	message["chunks"] = chunks;
+
+	ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	/* putdata */
+	command = "putdata";
+
+	ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
+
+	for (int remaining = chunks - 1; remaining >= 0; remaining--) {
+		message = Json::Value();
+		message["command"] = command;
+		message["file"] = filename;
+		message["data"] = "MTMzNw==";
+		message["remaining"] = remaining;
+		message["cancel"] = false;
+
+		response = jsonCommander.execute(message);
+
+		EXPECT_TRUE(response.action == JsonCommander::Action::send);
+		EXPECT_EQ(response.json["command"].asString(), command);
+		EXPECT_FALSE(response.json["cancel"].asBool());
+		EXPECT_EQ(response.json["received"].asInt(), remaining);
+		EXPECT_EQ(response.json["file"].asString(), filename);
+		EXPECT_EQ(response.json["error"].asString(), "");
+	}
 }
 
 TEST(Putdata, Cancel) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  /* start with put */
-  std::string command = "put";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-  message["size"] = 1337;
-  const int chunks = 3;
-  message["chunks"] = chunks;
-
-  ON_CALL(fileManager, openPutFile(testing::_))
-      .WillByDefault(testing::Return(true));
-
-  JsonCommander::Response response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  /* putdata */
-  command = "putdata";
-
-  ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
-  ON_CALL(fileManager, getPutBaseFileName())
-      .WillByDefault(testing::Return(filename));
-
-  int remaining = chunks - 1;
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["data"] = "MTMzNw==";
-  message["remaining"] = remaining;
-  message["cancel"] = false;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["received"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  // cancel transfer
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["data"] = "MTMzNw==";
-  message["remaining"] = --remaining;
-  message["cancel"] = true;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["received"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["error"].asString(), "");
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	/* start with put */
+	std::string command = "put";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+	message["size"] = 1337;
+	const int chunks = 3;
+	message["chunks"] = chunks;
+
+	ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	/* putdata */
+	command = "putdata";
+
+	ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
+
+	int remaining = chunks - 1;
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["data"] = "MTMzNw==";
+	message["remaining"] = remaining;
+	message["cancel"] = false;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["received"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	// cancel transfer
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["data"] = "MTMzNw==";
+	message["remaining"] = --remaining;
+	message["cancel"] = true;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["received"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["error"].asString(), "");
 }
 
 TEST(Putdata, WrongRemaining) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  /* start with put */
-  std::string command = "put";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-  message["size"] = 1337;
-  const int chunks = 3;
-  message["chunks"] = chunks;
-
-  ON_CALL(fileManager, openPutFile(testing::_))
-      .WillByDefault(testing::Return(true));
-
-  JsonCommander::Response response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  /* putdata */
-  command = "putdata";
-
-  ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
-  ON_CALL(fileManager, getPutBaseFileName())
-      .WillByDefault(testing::Return(filename));
-
-  int remaining = chunks - 1;
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["data"] = "MTMzNw==";
-  message["remaining"] = remaining;
-  message["cancel"] = false;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["received"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["error"].asString(), "");
-  message = Json::Value();
-
-  // skip remaining=1 and provoke an error
-  remaining = 0;
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["data"] = "MTMzNw==";
-  message["remaining"] = remaining;
-  message["cancel"] = false;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["received"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_TRUE(response.json["error"].asString().length() > 0);
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	/* start with put */
+	std::string command = "put";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+	message["size"] = 1337;
+	const int chunks = 3;
+	message["chunks"] = chunks;
+
+	ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	/* putdata */
+	command = "putdata";
+
+	ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
+
+	int remaining = chunks - 1;
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["data"] = "MTMzNw==";
+	message["remaining"] = remaining;
+	message["cancel"] = false;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["received"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["error"].asString(), "");
+	message = Json::Value();
+
+	// skip remaining=1 and provoke an error
+	remaining = 0;
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["data"] = "MTMzNw==";
+	message["remaining"] = remaining;
+	message["cancel"] = false;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["received"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_TRUE(response.json["error"].asString().length() > 0);
 }
 
 /* Get tests */
 TEST(Get, Positive) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "get";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
+	const std::string command = "get";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
 
-  const int chunks = 3;
-  EXPECT_CALL(fileManager, openGetFile(testing::_))
-      .WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
+	const int chunks = 3;
+	EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["chunks"].asInt(), chunks);
-  EXPECT_EQ(response.json["error"].asString(), "");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["chunks"].asInt(), chunks);
+	EXPECT_EQ(response.json["error"].asString(), "");
 }
 
 TEST(Get, Negative) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "get";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
+	const std::string command = "get";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
 
-  EXPECT_CALL(fileManager, openGetFile(testing::_))
-      .WillOnce(testing::Return(std::pair<bool, int>(false, -1)));
+	EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(false, -1)));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["chunks"].asInt(), -1);
-  EXPECT_TRUE(response.json["error"].asString().length() > 0);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["chunks"].asInt(), -1);
+	EXPECT_TRUE(response.json["error"].asString().length() > 0);
 }
 
 /* Getdata tests */
 TEST(Getdata, Positive) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  std::string command = "get";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-
-  const int chunks = 3;
-  EXPECT_CALL(fileManager, openGetFile(testing::_))
-      .WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
-
-  JsonCommander::Response response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["chunks"].asInt(), chunks);
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  /* getdata */
-  command = "getdata";
-
-  ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
-  ON_CALL(fileManager, getGetBaseFileName())
-      .WillByDefault(testing::Return(filename));
-
-  std::vector<char> data;
-  data.push_back('1');
-  data.push_back('3');
-  data.push_back('3');
-  data.push_back('7');
-
-  ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
-
-  for (int remaining = chunks - 1; remaining >= 0; remaining--) {
-    message = Json::Value();
-    message["command"] = command;
-    message["file"] = filename;
-    message["chunk"] = remaining;
-    message["cancel"] = false;
-
-    response = jsonCommander.execute(message);
-
-    EXPECT_TRUE(response.action == JsonCommander::Action::send);
-    EXPECT_EQ(response.json["command"].asString(), command);
-    EXPECT_FALSE(response.json["cancel"].asBool());
-    EXPECT_EQ(response.json["remaining"].asInt(), remaining);
-    EXPECT_EQ(response.json["file"].asString(), filename);
-    EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
-    EXPECT_EQ(response.json["error"].asString(), "");
-  }
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	std::string command = "get";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+
+	const int chunks = 3;
+	EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["chunks"].asInt(), chunks);
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	/* getdata */
+	command = "getdata";
+
+	ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
+
+	std::vector<char> data;
+	data.push_back('1');
+	data.push_back('3');
+	data.push_back('3');
+	data.push_back('7');
+
+	ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
+
+	for (int remaining = chunks - 1; remaining >= 0; remaining--) {
+		message = Json::Value();
+		message["command"] = command;
+		message["file"] = filename;
+		message["chunk"] = remaining;
+		message["cancel"] = false;
+
+		response = jsonCommander.execute(message);
+
+		EXPECT_TRUE(response.action == JsonCommander::Action::send);
+		EXPECT_EQ(response.json["command"].asString(), command);
+		EXPECT_FALSE(response.json["cancel"].asBool());
+		EXPECT_EQ(response.json["remaining"].asInt(), remaining);
+		EXPECT_EQ(response.json["file"].asString(), filename);
+		EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
+		EXPECT_EQ(response.json["error"].asString(), "");
+	}
 }
 
 TEST(Getdata, Cancle) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  std::string command = "get";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-
-  const int chunks = 3;
-  EXPECT_CALL(fileManager, openGetFile(testing::_))
-      .WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
-
-  JsonCommander::Response response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["chunks"].asInt(), chunks);
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  /* getdata */
-  command = "getdata";
-
-  ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
-  ON_CALL(fileManager, getGetBaseFileName())
-      .WillByDefault(testing::Return(filename));
-
-  std::vector<char> data;
-  data.push_back('1');
-  data.push_back('3');
-  data.push_back('3');
-  data.push_back('7');
-
-  ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
-
-  int remaining = chunks - 1;
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["chunk"] = remaining;
-  message["cancel"] = false;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  // set cancel to true
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["chunk"] = --remaining;
-  message["cancel"] = true;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["data"].asString(), "");
-  EXPECT_EQ(response.json["error"].asString(), "");
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	std::string command = "get";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+
+	const int chunks = 3;
+	EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["chunks"].asInt(), chunks);
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	/* getdata */
+	command = "getdata";
+
+	ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
+
+	std::vector<char> data;
+	data.push_back('1');
+	data.push_back('3');
+	data.push_back('3');
+	data.push_back('7');
+
+	ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
+
+	int remaining = chunks - 1;
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["chunk"] = remaining;
+	message["cancel"] = false;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	// set cancel to true
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["chunk"] = --remaining;
+	message["cancel"] = true;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["data"].asString(), "");
+	EXPECT_EQ(response.json["error"].asString(), "");
 }
 
 TEST(Getdata, WrongChunk) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  std::string command = "get";
-  const std::string filename = "cool.txt";
-  Json::Value message;
-  message["command"] = command;
-  message["file"] = filename;
-
-  const int chunks = 3;
-  EXPECT_CALL(fileManager, openGetFile(testing::_))
-      .WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
-
-  JsonCommander::Response response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["chunks"].asInt(), chunks);
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  /* getdata */
-  command = "getdata";
-
-  ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
-  ON_CALL(fileManager, getGetBaseFileName())
-      .WillByDefault(testing::Return(filename));
-
-  std::vector<char> data;
-  data.push_back('1');
-  data.push_back('3');
-  data.push_back('3');
-  data.push_back('7');
-
-  ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
-
-  int remaining = chunks - 1;
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["chunk"] = remaining;
-  message["cancel"] = false;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  // skip chunk=0
-  remaining = 0;
-  message = Json::Value();
-  message["command"] = command;
-  message["file"] = filename;
-  message["chunk"] = remaining;
-  message["cancel"] = false;
-
-  response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), remaining);
-  EXPECT_EQ(response.json["file"].asString(), filename);
-  EXPECT_EQ(response.json["data"].asString(), "");
-  EXPECT_TRUE(response.json["error"].asString().length() > 0);
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	std::string command = "get";
+	const std::string filename = "cool.txt";
+	Json::Value message;
+	message["command"] = command;
+	message["file"] = filename;
+
+	const int chunks = 3;
+	EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["chunks"].asInt(), chunks);
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	/* getdata */
+	command = "getdata";
+
+	ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
+	ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
+
+	std::vector<char> data;
+	data.push_back('1');
+	data.push_back('3');
+	data.push_back('3');
+	data.push_back('7');
+
+	ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
+
+	int remaining = chunks - 1;
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["chunk"] = remaining;
+	message["cancel"] = false;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	// skip chunk=0
+	remaining = 0;
+	message = Json::Value();
+	message["command"] = command;
+	message["file"] = filename;
+	message["chunk"] = remaining;
+	message["cancel"] = false;
+
+	response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), remaining);
+	EXPECT_EQ(response.json["file"].asString(), filename);
+	EXPECT_EQ(response.json["data"].asString(), "");
+	EXPECT_TRUE(response.json["error"].asString().length() > 0);
 }
 
 /* List tests */
 TEST(List, Positive) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "list";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "list";
+	Json::Value message;
+	message["command"] = command;
 
-  EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(1));
-  EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(5));
+	EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(1));
+	EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(5));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["chunks"].asInt(), 1);
-  EXPECT_EQ(response.json["items"].asInt(), 5);
-  EXPECT_EQ(response.json["error"].asString(), "");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["chunks"].asInt(), 1);
+	EXPECT_EQ(response.json["items"].asInt(), 5);
+	EXPECT_EQ(response.json["error"].asString(), "");
 }
 
 TEST(List, Negative) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "list";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "list";
+	Json::Value message;
+	message["command"] = command;
 
-  EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(-1));
+	EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(-1));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["chunks"].asInt(), -1);
-  EXPECT_EQ(response.json["items"].asInt(), -1);
-  EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["chunks"].asInt(), -1);
+	EXPECT_EQ(response.json["items"].asInt(), -1);
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
 }
 
 TEST(List, EmptyList) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "list";
-  Json::Value message;
-  message["command"] = command;
+	const std::string command = "list";
+	Json::Value message;
+	message["command"] = command;
 
-  EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(0));
-  EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(0));
+	EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(0));
+	EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(0));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["accept"].asBool());
-  EXPECT_EQ(response.json["chunks"].asInt(), 0);
-  EXPECT_EQ(response.json["items"].asInt(), 0);
-  EXPECT_EQ(response.json["error"].asString(), "");
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["accept"].asBool());
+	EXPECT_EQ(response.json["chunks"].asInt(), 0);
+	EXPECT_EQ(response.json["items"].asInt(), 0);
+	EXPECT_EQ(response.json["error"].asString(), "");
 }
 
 /* Listdata tests */
 
 void fillExampleFileList(std::vector<std::string> (&chunk)[3]) {
-  chunk[0].push_back("file01.txt");
-  chunk[0].push_back("bumdibumps");
-  chunk[0].push_back("1");
-  chunk[0].push_back("Ich habe Hunger.txt");
-  chunk[0].push_back("answerIs42");
-  chunk[0].push_back("123456789456115811");
-  chunk[0].push_back("kek");
-  chunk[1].push_back("1337");
-  chunk[1].push_back("cats.png");
-  chunk[1].push_back("more_cats.png");
-  chunk[1].push_back("ugly dog.tiff");
-  chunk[1].push_back("hello.txt");
-  chunk[1].push_back("bye.exe");
-  chunk[1].push_back("poster.pdf");
-  chunk[2].push_back("headbang.gif");
-  chunk[2].push_back("feelsbad.jpg");
-  chunk[2].push_back("hack.s");
-  chunk[2].push_back("SodiumChloride");
-  chunk[2].push_back(
-      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst"
-      "uvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN"
-      "OPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
+	chunk[0].push_back("file01.txt");
+	chunk[0].push_back("bumdibumps");
+	chunk[0].push_back("1");
+	chunk[0].push_back("Ich habe Hunger.txt");
+	chunk[0].push_back("answerIs42");
+	chunk[0].push_back("123456789456115811");
+	chunk[0].push_back("kek");
+	chunk[1].push_back("1337");
+	chunk[1].push_back("cats.png");
+	chunk[1].push_back("more_cats.png");
+	chunk[1].push_back("ugly dog.tiff");
+	chunk[1].push_back("hello.txt");
+	chunk[1].push_back("bye.exe");
+	chunk[1].push_back("poster.pdf");
+	chunk[2].push_back("headbang.gif");
+	chunk[2].push_back("feelsbad.jpg");
+	chunk[2].push_back("hack.s");
+	chunk[2].push_back("SodiumChloride");
+	chunk[2].push_back("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst"
+	                   "uvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN"
+	                   "OPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
 }
 
 TEST(Listdata, Positive) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  const std::string command = "listdata";
-
-  const int chunks = 3;
-  std::vector<std::string> chunk[chunks];
-  fillExampleFileList(chunk);
-
-  int remaining = chunks - 1;
-
-  for (int k = 0; k < chunks; k++) {
-    Json::Value message;
-    message["command"] = command;
-    message["chunk"] = remaining;
-    message["cancel"] = false;
-
-    EXPECT_CALL(fileManager, getRemainingListChunks())
-        .WillOnce(testing::Return(remaining + 1));
-    EXPECT_CALL(fileManager, getNextChunkFromList())
-        .WillOnce(testing::Return(chunk[k]));
-
-    JsonCommander::Response response = jsonCommander.execute(message);
-
-    EXPECT_TRUE(response.action == JsonCommander::Action::send);
-    EXPECT_EQ(response.json["command"].asString(), command);
-    EXPECT_FALSE(response.json["cancel"].asBool());
-    EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
-    EXPECT_TRUE(response.json["names"].isArray());
-    Json::Value array = response.json["names"];
-    EXPECT_EQ(array.size(), chunk[k].size());
-    for (int i = 0; i < 3; i++) {
-      EXPECT_EQ(array[i].asString(), chunk[k][i]);
-    }
-    EXPECT_EQ(response.json["error"].asString(), "");
-  }
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "listdata";
+
+	const int chunks = 3;
+	std::vector<std::string> chunk[chunks];
+	fillExampleFileList(chunk);
+
+	int remaining = chunks - 1;
+
+	for (int k = 0; k < chunks; k++) {
+		Json::Value message;
+		message["command"] = command;
+		message["chunk"] = remaining;
+		message["cancel"] = false;
+
+		EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
+		EXPECT_CALL(fileManager, getNextChunkFromList()).WillOnce(testing::Return(chunk[k]));
+
+		JsonCommander::Response response = jsonCommander.execute(message);
+
+		EXPECT_TRUE(response.action == JsonCommander::Action::send);
+		EXPECT_EQ(response.json["command"].asString(), command);
+		EXPECT_FALSE(response.json["cancel"].asBool());
+		EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
+		EXPECT_TRUE(response.json["names"].isArray());
+		Json::Value array = response.json["names"];
+		EXPECT_EQ(array.size(), chunk[k].size());
+		for (int i = 0; i < 3; i++) {
+			EXPECT_EQ(array[i].asString(), chunk[k][i]);
+		}
+		EXPECT_EQ(response.json["error"].asString(), "");
+	}
 }
 
 TEST(Listdata, Cancel) {
-  FileManagerMock fileManager;
-
-  JsonCommander jsonCommander(fileManager);
-
-  const std::string command = "listdata";
-
-  const int chunks = 3;
-  std::vector<std::string> chunk[chunks];
-  fillExampleFileList(chunk);
-
-  int remaining = chunks - 1;
-
-  Json::Value message;
-  message["command"] = command;
-  message["chunk"] = remaining;
-  message["cancel"] = false;
-
-  EXPECT_CALL(fileManager, getRemainingListChunks())
-      .WillOnce(testing::Return(remaining + 1));
-  EXPECT_CALL(fileManager, getNextChunkFromList())
-      .WillOnce(testing::Return(chunk[0]));
-
-  JsonCommander::Response response = jsonCommander.execute(message);
-
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_FALSE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
-  EXPECT_TRUE(response.json["names"].isArray());
-  Json::Value array = response.json["names"];
-  EXPECT_EQ(array.size(), chunk[0].size());
-  for (int i = 0; i < 3; i++) {
-    EXPECT_EQ(array[i].asString(), chunk[0][i]);
-  }
-  EXPECT_EQ(response.json["error"].asString(), "");
-
-  message = Json::Value();
-  message["command"] = command;
-  message["chunk"] = remaining;
-  message["cancel"] = true;
-
-  EXPECT_CALL(fileManager, getRemainingListChunks())
-      .WillOnce(testing::Return(remaining + 1));
-
-  response = jsonCommander.execute(message);
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
-  EXPECT_TRUE(response.json["names"].isArray());
-  EXPECT_EQ(response.json["error"].asString(), "");
+	FileManagerMock fileManager;
+
+	JsonCommander jsonCommander(fileManager);
+
+	const std::string command = "listdata";
+
+	const int chunks = 3;
+	std::vector<std::string> chunk[chunks];
+	fillExampleFileList(chunk);
+
+	int remaining = chunks - 1;
+
+	Json::Value message;
+	message["command"] = command;
+	message["chunk"] = remaining;
+	message["cancel"] = false;
+
+	EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
+	EXPECT_CALL(fileManager, getNextChunkFromList()).WillOnce(testing::Return(chunk[0]));
+
+	JsonCommander::Response response = jsonCommander.execute(message);
+
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_FALSE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
+	EXPECT_TRUE(response.json["names"].isArray());
+	Json::Value array = response.json["names"];
+	EXPECT_EQ(array.size(), chunk[0].size());
+	for (int i = 0; i < 3; i++) {
+		EXPECT_EQ(array[i].asString(), chunk[0][i]);
+	}
+	EXPECT_EQ(response.json["error"].asString(), "");
+
+	message = Json::Value();
+	message["command"] = command;
+	message["chunk"] = remaining;
+	message["cancel"] = true;
+
+	EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
+
+	response = jsonCommander.execute(message);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
+	EXPECT_TRUE(response.json["names"].isArray());
+	EXPECT_EQ(response.json["error"].asString(), "");
 }
 
 TEST(Listdata, WrongChunkNumber) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "listdata";
+	const std::string command = "listdata";
 
-  const int chunks = 3;
-  int remaining = chunks - 1;
+	const int chunks = 3;
+	int remaining = chunks - 1;
 
-  Json::Value message;
-  message["command"] = command;
-  message["chunk"] = remaining;
-  message["cancel"] = false;
+	Json::Value message;
+	message["command"] = command;
+	message["chunk"] = remaining;
+	message["cancel"] = false;
 
-  // return smaller remaining
-  EXPECT_CALL(fileManager, getRemainingListChunks())
-      .WillOnce(testing::Return(remaining));
+	// return smaller remaining
+	EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), -1);
-  EXPECT_TRUE(response.json["names"].isArray());
-  EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+	EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), -1);
+	EXPECT_TRUE(response.json["names"].isArray());
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
 }
 
 TEST(Listdata, NoChunksToBeSend) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "listdata";
+	const std::string command = "listdata";
 
-  const int chunks = 0;
+	const int chunks = 0;
 
-  Json::Value message;
-  message["command"] = command;
-  message["chunk"] = 1;
-  message["cancel"] = false;
+	Json::Value message;
+	message["command"] = command;
+	message["chunk"] = 1;
+	message["cancel"] = false;
 
-  // return smaller remaining
-  EXPECT_CALL(fileManager, getRemainingListChunks())
-      .WillOnce(testing::Return(chunks));
+	// return smaller remaining
+	EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(chunks));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::send);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), -1);
-  EXPECT_TRUE(response.json["names"].isArray());
-  EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+	EXPECT_TRUE(response.action == JsonCommander::Action::send);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), -1);
+	EXPECT_TRUE(response.json["names"].isArray());
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
 }
 
 TEST(Listdata, InvalidRequest) {
-  FileManagerMock fileManager;
+	FileManagerMock fileManager;
 
-  JsonCommander jsonCommander(fileManager);
+	JsonCommander jsonCommander(fileManager);
 
-  const std::string command = "listdata";
+	const std::string command = "listdata";
 
-  const int chunks = 3;
+	const int chunks = 3;
 
-  Json::Value message;
-  message["command"] = command;
-  message["chunk"] = 1;
+	Json::Value message;
+	message["command"] = command;
+	message["chunk"] = 1;
 
-  // return smaller remaining
-  EXPECT_CALL(fileManager, getRemainingListChunks())
-      .WillOnce(testing::Return(chunks));
+	// return smaller remaining
+	EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(chunks));
 
-  JsonCommander::Response response = jsonCommander.execute(message);
+	JsonCommander::Response response = jsonCommander.execute(message);
 
-  EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
-  EXPECT_EQ(response.json["command"].asString(), command);
-  EXPECT_TRUE(response.json["cancel"].asBool());
-  EXPECT_EQ(response.json["remaining"].asInt(), -1);
-  EXPECT_TRUE(response.json["names"].isArray());
-  EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
+	EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
+	EXPECT_EQ(response.json["command"].asString(), command);
+	EXPECT_TRUE(response.json["cancel"].asBool());
+	EXPECT_EQ(response.json["remaining"].asInt(), -1);
+	EXPECT_TRUE(response.json["names"].isArray());
+	EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
 }
 
 } // namespace

+ 29 - 29
gui/src/main.cpp

@@ -18,44 +18,44 @@
 using namespace std;
 
 int main(int argc, char *argv[]) {
-  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 
-  // This has to be here to fix warnings
-  QCoreApplication::setOrganizationName("CCats");
+	// This has to be here to fix warnings
+	QCoreApplication::setOrganizationName("CCats");
 
-  QGuiApplication app(argc, argv);
+	QGuiApplication app(argc, argv);
 
-  QQmlApplicationEngine engine;
+	QQmlApplicationEngine engine;
 
-  QMLHandler qmlHandler;
+	QMLHandler qmlHandler;
 
-  // Set the context for the window, so that the qml files can be connected to
-  // the qmlHandler
-  engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
+	// Set the context for the window, so that the qml files can be connected to
+	// the qmlHandler
+	engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
 
-  // Load the main window
-  QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
+	// Load the main window
+	QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/main.qml")));
 
-  QObject *object = component.create();
+	QObject *object = component.create();
 
-  // Run the main window and save the return of the application in an integer
-  // ret This is blocking, which means it will block the main program until the
-  // window is closed
-  int ret = app.exec();
+	// Run the main window and save the return of the application in an integer
+	// ret This is blocking, which means it will block the main program until the
+	// window is closed
+	int ret = app.exec();
 
-  // If we land here, the window has been closed. Properly disconnect from the
-  // server now
-  qmlHandler.onExit();
+	// If we land here, the window has been closed. Properly disconnect from the
+	// server now
+	qmlHandler.onExit();
 
-  if (_RESTART) {
-    // DO SHIT
-    pid_t pid = 0;
-    pid = fork();
-    if (pid == 0) {
-      execl("./CCats-GUI", "CCats-GUI", (char *)NULL);
-      exit(1);
-    }
-  }
+	if (_RESTART) {
+		// DO SHIT
+		pid_t pid = 0;
+		pid = fork();
+		if (pid == 0) {
+			execl("./CCats-GUI", "CCats-GUI", (char *)NULL);
+			exit(1);
+		}
+	}
 
-  return ret;
+	return ret;
 }

+ 222 - 244
gui/src/qmlhandler.cpp

@@ -31,180 +31,169 @@ bool programActive = true;
 QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
 
 void QMLHandler::closeCLI() {
-  close(outpipefd[1]);
-  close(inpipefd[0]);
-  _CLI_RUNNING = false;
+	close(outpipefd[1]);
+	close(inpipefd[0]);
+	_CLI_RUNNING = false;
 }
 
 void QMLHandler::reopenCLI(QString ip) {
-  if (_CLI_RUNNING) {
-    closeCLI();
-  }
-
-  _IP = ip;
-  pid_t pid = 0;
-
-  pipe(inpipefd);
-  pipe(outpipefd);
-  pid = fork();
-  if (pid == 0) {
-    // Child
-    dup2(outpipefd[0], STDIN_FILENO);
-    dup2(inpipefd[1], STDOUT_FILENO);
-    // dup2(inpipefd[1], STDERR_FILENO);
-
-    // ask kernel to deliver SIGTERM in case the parent dies
-    prctl(PR_SET_PDEATHSIG, SIGTERM);
-
-    // Set the path to the CLI - pass argument h (help) for now
-    // TODO: Change hardcoded path
-    execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(),
-          "--machine", (char *)NULL);
-
-    exit(1);
-  }
-
-  _CLI_RUNNING = true;
-
-  close(outpipefd[0]);
-  close(inpipefd[1]);
-  std::thread(&QMLHandler::readPipeLoop, this, pid).detach();
+	if (_CLI_RUNNING) {
+		closeCLI();
+	}
+
+	_IP = ip;
+	pid_t pid = 0;
+
+	pipe(inpipefd);
+	pipe(outpipefd);
+	pid = fork();
+	if (pid == 0) {
+		// Child
+		dup2(outpipefd[0], STDIN_FILENO);
+		dup2(inpipefd[1], STDOUT_FILENO);
+		// dup2(inpipefd[1], STDERR_FILENO);
+
+		// ask kernel to deliver SIGTERM in case the parent dies
+		prctl(PR_SET_PDEATHSIG, SIGTERM);
+
+		// Set the path to the CLI - pass argument h (help) for now
+		// TODO: Change hardcoded path
+		execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(), "--machine", (char *)NULL);
+
+		exit(1);
+	}
+
+	_CLI_RUNNING = true;
+
+	close(outpipefd[0]);
+	close(inpipefd[1]);
+	std::thread(&QMLHandler::readPipeLoop, this, pid).detach();
 }
 
 std::vector<std::string> tokenizeByNewlines(std::string in) {
-  vector<string> res;
-  size_t index;
-  for (index = in.find("\n"); index != std::string::npos;
-       index = in.find("\n")) {
-    if (index != 0)
-      res.push_back(in.substr(0, index));
-    in = in.substr(index + 1);
-  }
-  if (in.length() > 0)
-    res.push_back(in);
-  return res;
+	vector<string> res;
+	size_t index;
+	for (index = in.find("\n"); index != std::string::npos; index = in.find("\n")) {
+		if (index != 0)
+			res.push_back(in.substr(0, index));
+		in = in.substr(index + 1);
+	}
+	if (in.length() > 0)
+		res.push_back(in);
+	return res;
 }
 
-void QMLHandler::onExit() {
-  write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
-}
+void QMLHandler::onExit() { write(outpipefd[1], "disconnect\n", strlen("disconnect\n")); }
 
 // This method gets a string and tries to read it as Json
 // If it fails to do so, return and do nothing, else handle the content
 void QMLHandler::handleJSON(string buffer) {
-  Json::Value root;
-  Json::CharReaderBuilder builder;
-  Json::CharReader *reader = builder.newCharReader();
-  string jsonError;
-
-  // Try to parse the string as Json and store the result of the pasring in a
-  // boolean
-  bool parsingSuccessful = reader->parse(
-      buffer.c_str(), buffer.c_str() + buffer.size(), &root, &jsonError);
-
-  // If the string is not correct Json, return
-  if (!parsingSuccessful) {
-    return;
-  }
-
-  const Json::Value command = root["command"];
-  string cmd = command.asString();
-  qInfo() << QString::fromStdString("Received command " + cmd);
-
-  if (!cmd.compare("status")) {
-    emit footerSetStatus(root["response"].asString().c_str());
-  }
-
-  else if (!cmd.compare("close")) {
-    programActive = false;
-  }
-
-  else if (!cmd.compare("list")) {
-    if (root["accept"] == true) {
-      emit receivingClearFileList();
-
-      // Get the array of file Names
-      auto fileNames = root["names"];
-      for (int i = 0; i < fileNames.size(); i++) {
-        emit receivingListFile(
-            QString::fromStdString(fileNames[i].asString().c_str()));
-      }
-    } else {
-      emit log(root["error"].asString().c_str());
-    }
-  }
-
-  else if (!cmd.compare("connect")) {
-    if (root["accept"].asBool()) {
-    } else {
-      emit ipPopupSetStatus(root["error"].asString().c_str());
-      closeCLI();
-    }
-  }
-
-  else if (!cmd.compare("version")) {
-    if (root["accept"] == true) {
-      emit ipPopupClose();
-      emit loginSignupPopupOpen();
-    } else {
-      QString errorMessage = QString::fromStdString(string(
-          "Version mismatch: \nClient: " + root["clientversion"].asString() +
-          "\nServer: " + root["serverversion"].asString()));
-      emit ipPopupSetStatus(errorMessage);
-      reopenCLI(_IP);
-    }
-  }
-
-  else if (!cmd.compare("login")) {
-    if (root["accept"] == true) {
-      emit loginSignupPopupClose();
-    } else {
-      emit loginSetStatus(root["error"].asString().c_str());
-      reopenCLI(_IP);
-    }
-  }
-
-  else if (!cmd.compare("signup")) {
-    if (root["accept"] == true) {
-      emit loginSignupPopupClose();
-    } else {
-      emit loginSetStatus(root["error"].asString().c_str());
-      reopenCLI(_IP);
-    }
-  }
-
-  else if (!cmd.compare("put")) {
-    if (root["accept"] == false) {
-      QString errorMessage = QString::fromStdString(
-          string("Error when uploading file " + root["file"].asString() +
-                 ":\n" + root["error"].asString()));
-      emit log(errorMessage);
-    }
-  }
-
-  else if (!cmd.compare("putdata")) {
-    // TODO: Show speed and handle Error
-  }
-
-  else if (!cmd.compare("get")) {
-    if (root["accept"] == false) {
-      QString errorMessage = QString::fromStdString(
-          string("Error when downloading file " + root["file"].asString() +
-                 ":\n" + root["error"].asString()));
-      emit log(errorMessage);
-    }
-  }
-
-  else if (!cmd.compare("getdata")) {
-    // TODO: Show speed and handle Error
-  }
-
-  else if (!cmd.compare("deleteme")) {
-    if (root["accept"] == true) {
-      _RESTART = true;
-      emit closeWindow();
-    }
-  }
+	Json::Value root;
+	Json::CharReaderBuilder builder;
+	Json::CharReader *reader = builder.newCharReader();
+	string jsonError;
+
+	// Try to parse the string as Json and store the result of the pasring in a
+	// boolean
+	bool parsingSuccessful = reader->parse(buffer.c_str(), buffer.c_str() + buffer.size(), &root, &jsonError);
+
+	// If the string is not correct Json, return
+	if (!parsingSuccessful) {
+		return;
+	}
+
+	const Json::Value command = root["command"];
+	string cmd = command.asString();
+	qInfo() << QString::fromStdString("Received command " + cmd);
+
+	if (!cmd.compare("status")) {
+		emit footerSetStatus(root["response"].asString().c_str());
+	}
+
+	else if (!cmd.compare("close")) {
+		programActive = false;
+	}
+
+	else if (!cmd.compare("list")) {
+		if (root["accept"] == true) {
+			emit receivingClearFileList();
+
+			// Get the array of file Names
+			auto fileNames = root["names"];
+			for (int i = 0; i < fileNames.size(); i++) {
+				emit receivingListFile(QString::fromStdString(fileNames[i].asString().c_str()));
+			}
+		} else {
+			emit log(root["error"].asString().c_str());
+		}
+	}
+
+	else if (!cmd.compare("connect")) {
+		if (root["accept"].asBool()) {
+		} else {
+			emit ipPopupSetStatus(root["error"].asString().c_str());
+			closeCLI();
+		}
+	}
+
+	else if (!cmd.compare("version")) {
+		if (root["accept"] == true) {
+			emit ipPopupClose();
+			emit loginSignupPopupOpen();
+		} else {
+			QString errorMessage = QString::fromStdString(
+			    string("Version mismatch: \nClient: " + root["clientversion"].asString() + "\nServer: " + root["serverversion"].asString()));
+			emit ipPopupSetStatus(errorMessage);
+			reopenCLI(_IP);
+		}
+	}
+
+	else if (!cmd.compare("login")) {
+		if (root["accept"] == true) {
+			emit loginSignupPopupClose();
+		} else {
+			emit loginSetStatus(root["error"].asString().c_str());
+			reopenCLI(_IP);
+		}
+	}
+
+	else if (!cmd.compare("signup")) {
+		if (root["accept"] == true) {
+			emit loginSignupPopupClose();
+		} else {
+			emit loginSetStatus(root["error"].asString().c_str());
+			reopenCLI(_IP);
+		}
+	}
+
+	else if (!cmd.compare("put")) {
+		if (root["accept"] == false) {
+			QString errorMessage = QString::fromStdString(string("Error when uploading file " + root["file"].asString() + ":\n" + root["error"].asString()));
+			emit log(errorMessage);
+		}
+	}
+
+	else if (!cmd.compare("putdata")) {
+		// TODO: Show speed and handle Error
+	}
+
+	else if (!cmd.compare("get")) {
+		if (root["accept"] == false) {
+			QString errorMessage = QString::fromStdString(string("Error when downloading file " + root["file"].asString() + ":\n" + root["error"].asString()));
+			emit log(errorMessage);
+		}
+	}
+
+	else if (!cmd.compare("getdata")) {
+		// TODO: Show speed and handle Error
+	}
+
+	else if (!cmd.compare("deleteme")) {
+		if (root["accept"] == true) {
+			_RESTART = true;
+			emit closeWindow();
+		}
+	}
 }
 
 // This method is a loop which runs in a seperate thread.
@@ -212,120 +201,109 @@ void QMLHandler::handleJSON(string buffer) {
 // on stdout by the CLI/Server, and calls handleJSON with the read content
 // one it reads a newline.
 void QMLHandler::readPipeLoop(pid_t childid) {
-  unsigned int readOffset = 0;
-  unsigned int pollCount = 0;
-  struct pollfd inPipeStatus;
-  inPipeStatus.fd = inpipefd[0];
-  inPipeStatus.events = POLLIN;
-  vector<string> inputs;
-  string pipeInput;
-
-  while (programActive && _CLI_RUNNING) {
-    inputs = vector<string>();
-    poll(&inPipeStatus, 1, 100);
-
-    if (inPipeStatus.revents & POLLIN) {
-      readOffset += read(inpipefd[0], buf + readOffset, 1);
-      pollCount = 0;
-
-    } else {
-      pollCount++;
-    }
-
-    if (pollCount > 9 && (readOffset || pipeInput.size())) {
-      pipeInput.append(buf);
-      inputs = tokenizeByNewlines(pipeInput);
-      for (string s : inputs) {
-        emit log(QString::fromStdString(s));
-        qInfo() << QString::fromStdString(s);
-        handleJSON(s);
-      }
-      pipeInput = string();
-      memset(buf, 0, 1025);
-      pollCount = 0;
-      readOffset = 0;
-      if (waitpid(childid, NULL, WNOHANG)) {
-        // nonzero means error or childid has changed state
-        // for us that means child has exited -> CLI is dead
-        break;
-      }
-    }
-
-    // Fixme
-    if (readOffset >= 1024) {
-      pipeInput.append(buf);
-      readOffset = 0;
-      pollCount = 0;
-      memset(buf, 0, 1025);
-    }
-  }
+	unsigned int readOffset = 0;
+	unsigned int pollCount = 0;
+	struct pollfd inPipeStatus;
+	inPipeStatus.fd = inpipefd[0];
+	inPipeStatus.events = POLLIN;
+	vector<string> inputs;
+	string pipeInput;
+
+	while (programActive && _CLI_RUNNING) {
+		inputs = vector<string>();
+		poll(&inPipeStatus, 1, 100);
+
+		if (inPipeStatus.revents & POLLIN) {
+			readOffset += read(inpipefd[0], buf + readOffset, 1);
+			pollCount = 0;
+
+		} else {
+			pollCount++;
+		}
+
+		if (pollCount > 9 && (readOffset || pipeInput.size())) {
+			pipeInput.append(buf);
+			inputs = tokenizeByNewlines(pipeInput);
+			for (string s : inputs) {
+				emit log(QString::fromStdString(s));
+				qInfo() << QString::fromStdString(s);
+				handleJSON(s);
+			}
+			pipeInput = string();
+			memset(buf, 0, 1025);
+			pollCount = 0;
+			readOffset = 0;
+			if (waitpid(childid, NULL, WNOHANG)) {
+				// nonzero means error or childid has changed state
+				// for us that means child has exited -> CLI is dead
+				break;
+			}
+		}
+
+		// Fixme
+		if (readOffset >= 1024) {
+			pipeInput.append(buf);
+			readOffset = 0;
+			pollCount = 0;
+			memset(buf, 0, 1025);
+		}
+	}
 }
 
 // ### QML Handlers ###
 
 // Sending
 void QMLHandler::onSendingSelectFileButton(QUrl url) {
-  sendFileUrl = url.toLocalFile();
-  emit log("File Selected: " + sendFileUrl.toString());
-  emit sendingSetFileUrlText("Selected File: " + sendFileUrl.toString());
-  emit sendingEnableSendButton();
+	sendFileUrl = url.toLocalFile();
+	emit log("File Selected: " + sendFileUrl.toString());
+	emit sendingSetFileUrlText("Selected File: " + sendFileUrl.toString());
+	emit sendingEnableSendButton();
 }
 
 void QMLHandler::onSendingSendFileButton() {
-  QString command = "put " + sendFileUrl.toString() + "\n";
-  write(outpipefd[1], command.toUtf8().constData(),
-        strlen(command.toUtf8().constData()));
+	QString command = "put " + sendFileUrl.toString() + "\n";
+	write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
 }
 
 void QMLHandler::onSendingClearSelectionButton() {
-  sendFileUrl = QUrl("");
-  emit log("Cleared Selection");
-  emit sendingSetFileUrlText("Selected File: None");
-  emit sendingDisableSendButton();
+	sendFileUrl = QUrl("");
+	emit log("Cleared Selection");
+	emit sendingSetFileUrlText("Selected File: None");
+	emit sendingDisableSendButton();
 }
 
 // Receiving
-void QMLHandler::onReceivingListFilesButton() {
-  write(outpipefd[1], "list\n", strlen("list\n"));
-}
+void QMLHandler::onReceivingListFilesButton() { write(outpipefd[1], "list\n", strlen("list\n")); }
 
 void QMLHandler::onReceivingGetFileButton(QString fileName) {
-  QString command = "get " + fileName + "\n";
-  write(outpipefd[1], command.toUtf8().constData(),
-        strlen(command.toUtf8().constData()));
+	QString command = "get " + fileName + "\n";
+	write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
 }
 
 // Messages
 void QMLHandler::onMessagesSendButton(QString msg) { emit message(msg); }
 
 // Settings
-void QMLHandler::onSettingsDeleteMeButton() {
-  write(outpipefd[1], "deleteme\n", strlen("deleteme\n"));
-}
+void QMLHandler::onSettingsDeleteMeButton() { write(outpipefd[1], "deleteme\n", strlen("deleteme\n")); }
 
 // Ip Popup
 void QMLHandler::onIpPopupConnectButton(QString ip) { reopenCLI(ip); }
 
 // Login
 void QMLHandler::onLoginLoginButton(QString username, QString password) {
-  QString command = "login " + username + " " + password + "\n";
-  write(outpipefd[1], command.toUtf8().constData(),
-        strlen(command.toUtf8().constData()));
+	QString command = "login " + username + " " + password + "\n";
+	write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
 }
 
 // Signup
-void QMLHandler::onSignupRegisterButton(QString username, QString passwordOne,
-                                        QString passwordTwo) {
-  if (QString::compare(passwordOne, passwordTwo, Qt::CaseSensitive)) {
-    emit signupSetStatus("Passwords don't match");
-    return;
-  }
-  QString command = "signup " + username + " " + passwordOne + "\n";
-  write(outpipefd[1], command.toUtf8().constData(),
-        strlen(command.toUtf8().constData()));
+void QMLHandler::onSignupRegisterButton(QString username, QString passwordOne, QString passwordTwo) {
+	if (QString::compare(passwordOne, passwordTwo, Qt::CaseSensitive)) {
+		emit signupSetStatus("Passwords don't match");
+		return;
+	}
+	QString command = "signup " + username + " " + passwordOne + "\n";
+	write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
 }
 
 // Footer
-void QMLHandler::onFooterGetStatusButton() {
-  write(outpipefd[1], "status\n", strlen("status\n"));
-}
+void QMLHandler::onFooterGetStatusButton() { write(outpipefd[1], "status\n", strlen("status\n")); }