-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.c
147 lines (142 loc) · 5.43 KB
/
logger.c
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "logger.h"
#include "config.h"
#include "debug_utils.h"
#include <string.h>
void logger_init(Logger *logger_this)
{
memset(logger_this->keep_alive_auth_send, 0, CONFIG_SIZE_KEEP_ALIVE_AUTH);
memset(logger_this->keep_alive_heart_beat_send, 0, CONFIG_SIZE_KEEP_ALIVE_HEART_BEAT);
logger_this->time_keep_alive_auth_send = 0;
logger_this->time_keep_alive_auth_receive = 0;
logger_this->time_keep_alive_heart_beat_send = 0;
logger_this->time_keep_alive_heart_beat_receive = 0;
logger_this->count_keep_alive_auth_send = 0;
logger_this->count_keep_alive_auth_receive = 0;
logger_this->count_keep_alive_heart_beat_send = 0;
logger_this->count_keep_alive_heart_beat_receive = 0;
pthread_mutex_init(&(logger_this->mutex_keep_alive_auth_send), NULL);
pthread_mutex_init(&(logger_this->mutex_keep_alive_auth_receive), NULL);
pthread_mutex_init(&(logger_this->mutex_keep_alive_heart_beat_send), NULL);
pthread_mutex_init(&(logger_this->mutex_keep_alive_heart_beat_receive), NULL);
}
void logger_log_challenge_send(unsigned char *buffer_send)
{
if (CONFIG_DEBUG)
{
debug_msg("send challenge msg to server", buffer_send, CONFIG_SIZE_CHALLENGE);
}
}
void logger_log_challenge_receive(unsigned char *buffer_receive, unsigned long size)
{
if (CONFIG_DEBUG)
{
debug_msg("receive challenge msg from server", buffer_receive, size);
debug_msg("login salt", buffer_receive + 4, CONFIG_SIZE_SALT);
}
}
void logger_log_auth_send(unsigned char *buffer_send, unsigned long size)
{
if (CONFIG_DEBUG)
{
debug_msg("send auth msg to server", buffer_send, size);
}
}
void logger_log_auth_receive(unsigned char *buffer_receive, unsigned long size)
{
if (CONFIG_DEBUG)
{
debug_msg("receive auth msg from server", buffer_receive, size);
}
}
void logger_log_keep_alive_auth_send(Logger *logger_this, unsigned char *buffer_send)
{
if (CONFIG_DEBUG)
{
debug_msg("send keep alive auth msg to server", buffer_send, CONFIG_SIZE_KEEP_ALIVE_AUTH);
}
logger_try_lock_mutex_keep_alive_auth_send(logger_this);
memcpy(logger_this->keep_alive_auth_send, buffer_send, CONFIG_SIZE_KEEP_ALIVE_AUTH);
logger_this->time_keep_alive_auth_send = time(NULL);
++(logger_this->count_keep_alive_auth_send);
logger_unlock_mutex_keep_alive_auth_send(logger_this);
}
void logger_log_keep_alive_auth_receive(Logger *logger_this, unsigned char *buffer_receive, unsigned long size)
{
if (CONFIG_DEBUG)
{
debug_msg("receive keep alive auth msg from server", buffer_receive, size);
}
logger_try_lock_mutex_keep_alive_auth_receive(logger_this);
logger_this->time_keep_alive_auth_receive = time(NULL);
++(logger_this->count_keep_alive_auth_receive);
logger_unlock_mutex_keep_alive_auth_receive(logger_this);
}
void logger_log_keep_alive_heart_beat_send(Logger *logger_this, unsigned char *buffer_send)
{
if (CONFIG_DEBUG)
{
debug_msg("send keep alive heart beat msg to server", buffer_send, CONFIG_SIZE_KEEP_ALIVE_HEART_BEAT);
}
logger_try_lock_mutex_keep_alive_heart_beat_send(logger_this);
memcpy(logger_this->keep_alive_heart_beat_send, buffer_send, CONFIG_SIZE_KEEP_ALIVE_HEART_BEAT);
logger_this->time_keep_alive_heart_beat_send = time(NULL);
++(logger_this->count_keep_alive_heart_beat_send);
logger_unlock_mutex_keep_alive_heart_beat_send(logger_this);
}
void logger_log_keep_alive_heart_beat_receive(Logger *logger_this, unsigned char *buffer_receive, unsigned long size)
{
if (CONFIG_DEBUG)
{
debug_msg("receive keep alive heart beat msg from server", buffer_receive, size);
}
logger_try_lock_mutex_keep_alive_heart_beat_receive(logger_this);
logger_this->time_keep_alive_heart_beat_receive = time(NULL);
++(logger_this->count_keep_alive_heart_beat_receive);
logger_unlock_mutex_keep_alive_heart_beat_receive(logger_this);
}
void logger_log_logout_send(unsigned char *buffer_send)
{
if (CONFIG_DEBUG)
{
debug_msg("send logout msg to server", buffer_send, CONFIG_SIZE_LOGOUT);
}
}
void logger_log_logout_receive(unsigned char *buffer_receive, unsigned long size)
{
if (CONFIG_DEBUG)
{
debug_msg("receive logout msg from server", buffer_receive, size);
}
}
void logger_try_lock_mutex_keep_alive_auth_send(Logger *logger_this)
{
pthread_mutex_trylock(&(logger_this->mutex_keep_alive_auth_send));
}
void logger_unlock_mutex_keep_alive_auth_send(Logger *logger_this)
{
pthread_mutex_unlock(&(logger_this->mutex_keep_alive_auth_send));
}
void logger_try_lock_mutex_keep_alive_auth_receive(Logger *logger_this)
{
pthread_mutex_trylock(&(logger_this->mutex_keep_alive_auth_receive));
}
void logger_unlock_mutex_keep_alive_auth_receive(Logger *logger_this)
{
pthread_mutex_unlock(&(logger_this->mutex_keep_alive_auth_receive));
}
void logger_try_lock_mutex_keep_alive_heart_beat_send(Logger *logger_this)
{
pthread_mutex_trylock(&(logger_this->mutex_keep_alive_heart_beat_send));
}
void logger_unlock_mutex_keep_alive_heart_beat_send(Logger *logger_this)
{
pthread_mutex_unlock(&(logger_this->mutex_keep_alive_heart_beat_send));
}
void logger_try_lock_mutex_keep_alive_heart_beat_receive(Logger *logger_this)
{
pthread_mutex_trylock(&(logger_this->mutex_keep_alive_heart_beat_receive));
}
void logger_unlock_mutex_keep_alive_heart_beat_receive(Logger *logger_this)
{
pthread_mutex_unlock(&(logger_this->mutex_keep_alive_heart_beat_receive));
}