forked from laocai/tcp-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrom_ngx_src.c
206 lines (172 loc) · 4.47 KB
/
from_ngx_src.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <from_ngx_src.h>
//#include <ngx_crc32.h>
static ngx_str_t err_levels[] = {
ngx_null_string,
ngx_string("emerg"),
ngx_string("alert"),
ngx_string("crit"),
ngx_string("error"),
ngx_string("warn"),
ngx_string("notice"),
ngx_string("info"),
ngx_string("debug")
};
static const char *debug_levels[] = {
"debug_core", "debug_alloc", "debug_mutex", "debug_event",
"debug_http", "debug_mail", "debug_mysql"
};
ngx_log_t *
__ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
{
ngx_log_t *log;
log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t));
if (log == NULL) {
return NULL;
}
log->file = ngx_conf_open_file(cycle, name);
if (log->file == NULL) {
return NULL;
}
return log;
}
char *
__ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
{
ngx_uint_t i, n, d, found;
ngx_str_t *value;
value = cf->args->elts;
for (i = 2; i < cf->args->nelts; i++) {
found = 0;
for (n = 1; n <= NGX_LOG_DEBUG; n++) {
if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) {
if (log->log_level != 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"duplicate log level \"%V\"",
&value[i]);
return NGX_CONF_ERROR;
}
log->log_level = n;
found = 1;
break;
}
}
for (n = 0, d = NGX_LOG_DEBUG_FIRST; d <= NGX_LOG_DEBUG_LAST; d <<= 1) {
if (ngx_strcmp(value[i].data, debug_levels[n++]) == 0) {
if (log->log_level & ~NGX_LOG_DEBUG_ALL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid log level \"%V\"",
&value[i]);
return NGX_CONF_ERROR;
}
log->log_level |= d;
found = 1;
break;
}
}
if (!found) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid log level \"%V\"", &value[i]);
return NGX_CONF_ERROR;
}
}
if (log->log_level == NGX_LOG_DEBUG) {
log->log_level = NGX_LOG_DEBUG_ALL;
}
return NGX_CONF_OK;
}
//void
//__ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
// const char *fmt, ...)
//{
// va_list args;
// u_char *p, *last, *msg;
// u_char errstr[NGX_MAX_ERROR_STR];
//
// if (log->file->fd == NGX_INVALID_FILE) {
// return;
// }
//
// last = errstr + NGX_MAX_ERROR_STR;
//
// ngx_memcpy(errstr, ngx_cached_err_log_time.data,
// ngx_cached_err_log_time.len);
//
// p = errstr + ngx_cached_err_log_time.len;
//
// p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
//
// /* pid#tid */
// p = ngx_slprintf(p, last, "%P#" NGX_TID_T_FMT ": ",
// ngx_log_pid, ngx_log_tid);
//
// if (log->connection) {
// p = ngx_slprintf(p, last, "*%uA ", log->connection);
// }
//
// msg = p;
//
// va_start(args, fmt);
// p = ngx_vslprintf(p, last, fmt, args);
// va_end(args);
//
// if (err) {
// p = ngx_log_errno(p, last, err);
// }
//
// if (level != NGX_LOG_DEBUG && log->handler) {
// p = log->handler(log, p, last - p);
// }
//
// if (p > last - NGX_LINEFEED_SIZE) {
// p = last - NGX_LINEFEED_SIZE;
// }
//
// ngx_linefeed(p);
//
// (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
//
// if (!ngx_use_stderr
// || level > NGX_LOG_WARN
// || log->file->fd == ngx_stderr)
// {
// return;
// }
//
// msg -= (7 + err_levels[level].len + 3);
//
// (void) ngx_sprintf(msg, "nginx: [%V] ", &err_levels[level]);
//
// (void) ngx_write_console(ngx_stderr, msg, p - msg);
//}
uint32_t
__ngx_crc32_long(u_char *p, size_t len)
{
uint32_t crc;
crc = 0xffffffff;
while (len--) {
crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8);
}
return crc ^ 0xffffffff;
}
uint32_t
__ngx_crc32_init(uint32_t *crc)
{
*crc = 0xffffffff;
return *crc;
}
void
__ngx_crc32_update(uint32_t *crc, u_char *p, size_t len)
{
uint32_t c;
c = *crc;
while (len--) {
c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8);
}
*crc = c;
}
uint32_t
__ngx_crc32_final(uint32_t *crc)
{
*crc ^= 0xffffffff;
return *crc;
}