123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #ifndef JSONCOMMANDER_H
- #define JSONCOMMANDER_H
- #include <json/json.h>
- #include "FileManager.h"
- /**
- * @class JsonCommander
- *
- * A class to execute the json commands which were sent by a client.
- * It also uses the file manager for writing and reading files.
- */
- 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);
- /**
- * protocol version of the client server protocol
- */
- const int protocolMajorVersion = 0;
- const int protocolMinorVersion = 3;
- private:
- /**
- * 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);
- /**
- * Executes the deletefile command
- */
- Response executeDeleteFile(const Json::Value &message);
- /**
- * Executes the notifications command
- */
- Response executeNotifications(const Json::Value &message);
- };
- #endif
|