request_handler.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef REQUEST_HANDLER_H
  2. #define REQUEST_HANDLER_H
  3. #include "binom/binom.h"
  4. #include "tcp/TcpServer.h"
  5. #include "common.hpp"
  6. class RequestHandler {
  7. public:
  8. /**
  9. * @brief The ClientState enum
  10. */
  11. enum class ClientState : uint8_t {
  12. connected,
  13. secure_connected,
  14. authenticated
  15. };
  16. private:
  17. binom::DynamicStorage& db; ///< Server database
  18. TcpServer& server; ///< TCP Server
  19. EVP_PKEY* server_key; ///< Server key pair
  20. TcpServer::Client& client; ///< TCP Client
  21. binom::Variable data; ///< recived data
  22. binom::FileNodeVisitor session_data; ///< session
  23. std::string getHostStr();
  24. void routeOpenLayer();
  25. void routeSecuredLayer();
  26. void routeAuthenticatedLayer();
  27. void processRequest();
  28. void invalidActionCode();
  29. // Layer actions
  30. // Open layer
  31. void exchangeKey();
  32. // Secured layer
  33. void sendServerInfo();
  34. void authenticate();
  35. void registrate();
  36. void authenticateByUUID();
  37. // Authenticated layer
  38. // Request processing
  39. void changeProfile();
  40. void deleteAccount();
  41. void createDialog();
  42. void sendMessage();
  43. void changeMessage();
  44. void deleteMessage();
  45. void changePost();
  46. void publishPost();
  47. void deletePost();
  48. void requestUserProfiles();
  49. void requestUserPublicKey();
  50. void requestMessages();
  51. void requestPosts();
  52. // Layer gates
  53. void gotoSecuredLayer(); // Open -> Secu
  54. void gotoAuthenticatedLayer(); // Secured -> Authenticated
  55. /**
  56. * @brief Insert data in content-addressable storage
  57. * @param content
  58. * @param owner - login of data owner
  59. * @return hash-key of content in Content-addressable storage
  60. */
  61. binom::ByteArray insertContent(binom::ByteArray content, binom::ByteArray mime_type, binom::ByteArray owner);
  62. /**
  63. * @brief Get data from content-addressable storage
  64. * @param key
  65. * @return data entry
  66. */
  67. binom::Variable getContent(binom::ByteArray key);
  68. /**
  69. * @brief Assemble content list from content-addressable storage by hash key list
  70. * @param hash_key_list
  71. * @return
  72. */
  73. binom::Array assembleContentList(binom::Array hash_key_list);
  74. public:
  75. RequestHandler(
  76. binom::DynamicStorage& db,
  77. TcpServer& server,
  78. EVP_PKEY* server_key,
  79. TcpServer::Client& client,
  80. binom::Variable data,
  81. binom::FileNodeVisitor session_data
  82. )
  83. : db(db),
  84. server(server),
  85. server_key(server_key),
  86. client(client),
  87. data(std::move(data)),
  88. session_data(session_data) {
  89. routeOpenLayer();
  90. }
  91. };
  92. #endif // REQUEST_HANDLER_H