-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.h
More file actions
63 lines (48 loc) · 1.87 KB
/
helpers.h
File metadata and controls
63 lines (48 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef _HELPERS_
#define _HELPERS_
#define BUFLEN 4096
#define LINELEN 1000
#define SESSION_COOKIE_LEN 200
#define TOKEN_LEN 300
#define IP "34.241.4.235"
#define PORT 8080
#define PAYLOAD_TYPE "application/json"
#define REGISTER_ROUTE "/api/v1/tema/auth/register"
#define AUTH_ROUTE " /api/v1/tema/auth/login"
#define LIBRARY_ROUTE " /api/v1/tema/library/access"
#define BOOK_ROUTE " /api/v1/tema/library/books"
#define ADD_BOOK_ROUTE " /api/v1/tema/library/books"
#define DEAUTH_ROUTE "/api/v1/tema/auth/logout"
#define MAX_COMMAND_LEN 20
#define LOGIN_COMMAND "login"
#define REGISTER_COMMAND "register"
#define ENTER_LIBRARY_COMMAND "enter_library"
#define GET_BOOKS_COMMAND "get_books"
#define GET_BOOK_COMMAND "get_book"
#define ADD_BOOK_COMMAND "add_book"
#define DELETE_BOOK_COMMAND "delete_book"
#define LOGOUT_COMMAND "logout"
#define EXIT_COMMAND "exit"
typedef struct user {
char username[100];
char password[100];
}user;
// reopens the connection and send the message again
void reopen_connection_and_send(int *sockfd, char **response, char *message);
// shows the current error
void error(const char *msg);
// adds a line to a string message
void compute_message(char *message, const char *line);
// opens a connection with server host_ip on port portno, returns a socket
int open_connection(const char *host_ip, int portno, int ip_type, int socket_type, int flag);
// closes a server connection on socket sockfd
void close_connection(int sockfd);
// send a message to a server
void send_to_server(int sockfd, char *message);
// receives and returns the message from a server
char *receive_from_server(int sockfd);
// extracts and returns a JSON from a server response
char *basic_extract_json_response(char *str);
bool check_respond(char *response);
void get_session_cookie(char *response, char *buffer);
#endif