Line data Source code
1 : #ifndef PARSER_H
2 : #define PARSER_H
3 :
4 : #include <string>
5 : #include "DatabaseManager.h"
6 : #include <iostream>
7 : #include "api_constants_client.h"
8 : #include "SharedServerClient.h"
9 : #include "api_server_constants.h"
10 : #include <stdexcept>
11 : #include <vector>
12 : #include "Tokenizer.h"
13 : #include "Parsers/UserParser.h"
14 : #include "Parsers/CsvParser.h"
15 : #include "Parsers/JsonParser.h"
16 : #include "../libs/loger/easylogging++.h"
17 : #include "./matches/UserMatcher.h"
18 : #include "ChatDatabaseManager.h"
19 : #include "ServerUtils.h"
20 :
21 : #include <cstdbool>
22 : #include <list>
23 : #include <queue>
24 :
25 : #include "../libs/jsoncpp/dist/json/json.h"
26 : #include "User.h"
27 : #include "./matches/UserMatcher.h"
28 : #include "LikesDatabaseManager.h"
29 :
30 : #define DEFAULT_PASS "123456"
31 4 : class ExistentUserException : public exception {
32 : };
33 :
34 : typedef struct _server_databases_t {
35 : rocksdb::DB *usersDB;
36 : rocksdb::DB *chatDB;
37 : rocksdb::DB *likesDB;
38 : } server_databases_t;
39 :
40 0 : typedef struct _new_message_t {
41 : std::string sender;
42 : std::string message;
43 : } new_message_t;
44 :
45 : /* Handler for incomming requests. */
46 : class MessageHandler {
47 : public:
48 : /* Create new handler with pDatabase as usersDB. */
49 : MessageHandler(server_databases_t* databases);
50 : /* Destroy handler. */
51 : ~MessageHandler();
52 : bool isUserSet();
53 : void setUser(string name);
54 : /* Set initialized usersDB. */
55 : void setUsersDB(DatabaseManager* usersDB);
56 : bool validateToken(std::string user_token);
57 :
58 : bool authenticate(std::string username, std::string password);
59 :
60 : bool createUser(std::string user_data, std::string pass);
61 :
62 : bool getUsers(std::string& resultMsg);
63 :
64 : bool updateUser(std::string user_data);
65 :
66 : bool deleteUser();
67 :
68 : void getMatches(std::string& matches);
69 :
70 : bool getNewMatches(std::string& newMatches);
71 :
72 : void getInteractions(std::string& matches);
73 :
74 : bool getInterestPhoto(std::string& photo_64, std::string id_interest);
75 :
76 : bool getChat(std::string friend_username, std::string& chat_history);
77 :
78 : bool postChatMsg(string receiverUserName, string message);
79 :
80 : bool getNewMessages(string friend_name, string& newMessages);
81 :
82 : bool getPhoto(string username, string &photo_64);
83 :
84 : bool postPhoto(std::string photo_64);
85 :
86 : std::string getToken();
87 :
88 : bool addLocalization(std::string localization);
89 :
90 : bool getUser(std::string username, std::string &user_data);
91 :
92 : void setSharedLink(std::string linkToShared);
93 :
94 : void createInterests(Interests* interests);
95 :
96 : void saveUserInDB(std::string userJson, string pass);
97 :
98 : void updateUsersWithSS();
99 :
100 : bool postInteraction(string friend_name, string reaction);
101 :
102 : void split(string values, string& value1, string& value2);
103 :
104 : string getReactionToken(string reaction);
105 :
106 : protected:
107 : /* Authenticate user and password in message. Saves INCORRECT_LOGIN
108 : or CORRECT_LOGIN in resultMsg. */
109 : /* Returns first substring of message until SEPARATOR. */
110 : std::string divideMessage(std::string& message);
111 :
112 : bool postLogin(std::string user_name, std::string token, std::string& resultMsg);
113 : bool postSignUp(std::string data, std::string& resultMsg);
114 :
115 :
116 : std::string getId();
117 : private:
118 : DatabaseManager * usersDB;
119 : ChatDatabaseManager * chatDB;
120 : LikesDatabaseManager * likesDB;
121 : SharedServerClient * ssClient;
122 : Tokenizer* tokenizer;
123 : std::string username;
124 : std::queue<string> newMatches;
125 : std::queue<new_message_t> newMessages;
126 :
127 :
128 : bool appUserLikesAnotherUser(string &users, string &candidate_data);
129 : };
130 :
131 : #endif // PARSER_H
|