Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit 4c6578f

Browse files
committed
Server and ChatHandler documentation
1 parent df5f549 commit 4c6578f

3 files changed

Lines changed: 92 additions & 2 deletions

File tree

Server/GlobalClass.h

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <vector>
88
#include <mutex>
99

10-
10+
/*! Class with constants and some utility functions */
1111
class GlobalClass {
1212
private:
1313
static std::mutex _muTrim;
@@ -19,28 +19,80 @@ class GlobalClass {
1919
static const std::string DATABASE_USER;
2020
static const std::string DATABASE_PASSWORD;
2121

22+
/**
23+
* String which will be added to password before hashing, adding more security.
24+
*/
2225
static const std::string SALT;
2326

2427
static const int PORT_NUMBER;
25-
28+
/**
29+
*Delimiter which is used to separe the messages in the request
30+
*/
2631
static const char DELIMITER1;
32+
/**
33+
*Delimiter which is used to separe the messages sub-parts.
34+
*/
2735
static const char DELIMITER2;
36+
/**
37+
*Additional delimiter.
38+
*/
2839
static const char DELIMITER3;
2940

41+
/**
42+
* Common room user id.
43+
*/
3044
static const int COMMON_USER_ID;
45+
46+
/**
47+
* Common room username
48+
*/
3149
static const std::string COMMON_ROOM_NAME;
3250

51+
/*
52+
* Response code which indicates that the request was processed correctly. *
53+
*/
3354
static const int REQUEST_OK;
3455
static const int USER_NAME_ALREADY_EXIST;
56+
/*
57+
* Error code which means that the request format is invalide.
58+
*/
3559
static const int INCORRECT_REQUEST;
3660
static const int INCORRECT_USER_OR_PASSWOROD;
3761
static const int DATABASE_ERROR;
3862

63+
/*
64+
* Time interval in which the online checker thread checks the users activity.
65+
*/
3966
static const std::chrono::milliseconds ONLINECHECK_SLEEPTIME;
4067

68+
/**
69+
* \param str string which will be trimed
70+
* \param whitespace characters which should be considered white space.
71+
* \return Trimed string
72+
*
73+
* Remove space from the begining and ending of the string
74+
*/
4175
static std::string trim(const std::string& str, const std::string& whitespace = " \t\n");
76+
77+
/**
78+
* \param s input string
79+
* \param delim delimiter character, these wont be part of the return value
80+
* \return a std::vector of strings, each of which is a substring of string formed by splitting it on boundaries formed by the char delimiter.
81+
*
82+
*/
4283
static std::vector<std::string> split(const std::string &s, char delim);
84+
85+
/**
86+
Converts integer to string
87+
* \param a input integer
88+
* \return string interpretation of the parameter
89+
*/
4390
static std::string converter(int a);
91+
92+
/**
93+
Time since epoch.
94+
* \return milliseconds passed since 1970-1-1.
95+
*/
4496
static long currentTimeMillis();
4597
};
4698

Server/Server/ChatHandler.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,37 @@ class ChatHandler
1616
public:
1717
ChatHandler();
1818
~ChatHandler();
19+
/**
20+
* \param request register string request sent by client, format: username:delimiter1:password:delimiter1:email@email.com.
21+
* \return response string containing the code of the operation (success/fail)
22+
*
23+
* Register an user in the database if the request data is correct, otherwise it returns with an error code.
24+
*/
1925
std::string registerUser(const std::string &request);
26+
/**
27+
* \param request login string request sent by client, format: username:delimiter1:password.
28+
* \return response string containing the code of the operation (success/fail), and user random user token on success
29+
*
30+
* If the username/password combination user exist in the database it returns a token. With the token the client can
31+
* access the users messages and send messages to other users.
32+
*/
2033
std::string loginUser(const std::string &request);
34+
/**
35+
* \param token the user token generated on login
36+
* \return response string containing the code of the operation (success/fail), and update data format: error_code:delimit1:online_users:delimit1:private_msg:public_msg
37+
* If the token a valid one, it will update user last activity time,
38+
*/
2139
std::string updateUser(const std::string token);
40+
/**
41+
* \param request message string request sent by client, format: TOKEN:delimiter1:TARGET:delimiter1:This is the message:delimiter1:
42+
* \return response string containing the code of the operation (success/fail)
43+
*
44+
* If the request information is valid, it will send message from the token user to the target user
45+
*/
2246
std::string messageUser(const std::string &request);
47+
/**
48+
* It will remove all inactive user from the online user list.
49+
*/
2350
void checkOnlineUsers();
2451
private:
2552
UserEntity createUserFromRequest(const std::string &request);

Server/Server/Server.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@
1212

1313
class Server {
1414
public:
15+
/**
16+
* Binds server to port.
17+
*/
1518
Server(int port);
19+
/**
20+
* Closes server socket.
21+
*/
1622
~Server();
23+
/**
24+
* \brief Server start waiting for clients on PORT and update existing clients.
25+
* Server objects handles clients and threads. For each client creats a thread, it also has a thread in which
26+
checks the activity of user.
27+
*/
1728
void run();
1829
const int PORT;
1930
private:

0 commit comments

Comments
 (0)