JsonCommander.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #ifndef JSONCOMMANDER_H
  2. #define JSONCOMMANDER_H
  3. #include <json/json.h>
  4. #include "FileManager.h"
  5. /**
  6. * @class JsonCommander
  7. *
  8. * A class to execute the json commands which were sent by a client.
  9. * It also uses the file manager for writing and reading files.
  10. */
  11. class JsonCommander {
  12. public:
  13. /**
  14. * Action for the json response.
  15. * send - send the json answer
  16. * closeAndSend - send the json answer and close the socket
  17. * close - close the socket
  18. */
  19. enum Action { close, send, closeAndSend };
  20. /**
  21. * Response for commands
  22. *
  23. * If action is set to close json can be uninitialized.
  24. */
  25. struct Response {
  26. Action action;
  27. Json::Value json;
  28. };
  29. /**
  30. * Creates a JsonCommaner
  31. */
  32. JsonCommander(FileManager &fileManager);
  33. /**
  34. * Deletes the JsonCommander
  35. */
  36. ~JsonCommander();
  37. /**
  38. * Executes commands
  39. */
  40. Response execute(const Json::Value &message);
  41. /**
  42. * Does version check before login
  43. */
  44. Response testVersion(const Json::Value &message);
  45. /**
  46. * Checks if login is valid
  47. */
  48. Response checkLogin(const Json::Value &message);
  49. /**
  50. * protocol version of the client server protocol
  51. */
  52. const int protocolMajorVersion = 0;
  53. const int protocolMinorVersion = 3;
  54. private:
  55. /**
  56. * Contains the name of the user which uses the current connection.
  57. * Is set at checkLogin. Used for deleteUser.
  58. */
  59. std::string currentUser;
  60. /**
  61. * Map of all commands
  62. *
  63. * Used to find the command function fast
  64. */
  65. std::map<std::string, Response (JsonCommander::*)(const Json::Value &)> commandsMap;
  66. /**
  67. * file manager for reading and writing files
  68. */
  69. FileManager &fileManager;
  70. /**
  71. *
  72. * Last chunk number which was sent.
  73. */
  74. int getFileRemaining;
  75. /**
  76. * Last chunk number which was received.
  77. */
  78. int putFileReceived;
  79. /**
  80. * Total chunk number from current put transfer
  81. */
  82. int putSize;
  83. /**
  84. * Total chunk number from current get transfer
  85. */
  86. int getSize;
  87. /**
  88. * Executes the status command
  89. */
  90. Response executeStatus(const Json::Value &message);
  91. /**
  92. * Executes the close command
  93. */
  94. Response executeClose(const Json::Value &message);
  95. /**
  96. * Executes the list command
  97. */
  98. Response executeList(const Json::Value &message);
  99. /**
  100. * Executes the listdata command
  101. */
  102. Response executeListData(const Json::Value &message);
  103. /**
  104. * Executes the put command
  105. */
  106. Response executePut(const Json::Value &message);
  107. /**
  108. * Executes the putdata command
  109. */
  110. Response executePutdata(const Json::Value &message);
  111. /**
  112. * Executes the get command
  113. */
  114. Response executeGet(const Json::Value &message);
  115. /**
  116. * Executes the getdata command
  117. */
  118. Response executeGetdata(const Json::Value &message);
  119. /**
  120. * Executes the head command
  121. */
  122. Response executeHead(const Json::Value &message);
  123. /**
  124. * Executes the deleteme command
  125. */
  126. Response executeDeleteMe(const Json::Value &message);
  127. /**
  128. * Executes the deletefile command
  129. */
  130. Response executeDeleteFile(const Json::Value &message);
  131. /**
  132. * Executes the extendedstatus command
  133. */
  134. Response executeExtendedStatus(const Json::Value &message);
  135. /**
  136. * Executes the notifications command
  137. */
  138. Response executeNotifications(const Json::Value &message);
  139. /**
  140. * Executes the queue command
  141. */
  142. Response executeQueue(const Json::Value &message);
  143. /**
  144. * Executes the dequeue command
  145. */
  146. Response executeDequeue(const Json::Value &message);
  147. };
  148. #endif