Klaus Demo nginx / 5afd74b
Removed the prototype mysql module. Ruslan Ermilov 4 years ago
8 changed file(s) with 3 addition(s) and 773 deletion(s). Raw diff Collapse all Expand all
5656 syn keyword ngxDirectiveDeprecated connections
5757 syn keyword ngxDirectiveDeprecated imap
5858 syn keyword ngxDirectiveDeprecated limit_zone
59 syn keyword ngxDirectiveDeprecated mysql_test
5960 syn keyword ngxDirectiveDeprecated open_file_cache_retest
6061 syn keyword ngxDirectiveDeprecated optimize_server_names
6162 syn keyword ngxDirectiveDeprecated satisfy_any
245246 syn keyword ngxDirective msie_padding
246247 syn keyword ngxDirective msie_refresh
247248 syn keyword ngxDirective multi_accept
248 syn keyword ngxDirective mysql_test
249249 syn keyword ngxDirective open_file_cache
250250 syn keyword ngxDirective open_file_cache_errors
251251 syn keyword ngxDirective open_file_cache_events
1818 rm $(TEMP)/$(NGINX)/src/event/ngx_event_connectex.c
1919 rm $(TEMP)/$(NGINX)/src/event/modules/ngx_iocp_module.*
2020 rm -r $(TEMP)/$(NGINX)/src/os/win32
21
22 rm -r $(TEMP)/$(NGINX)/src/mysql
2321
2422 mv $(TEMP)/$(NGINX)/docs/text/LICENSE $(TEMP)/$(NGINX)
2523 mv $(TEMP)/$(NGINX)/docs/text/README $(TEMP)/$(NGINX)
8585
8686 static const char *debug_levels[] = {
8787 "debug_core", "debug_alloc", "debug_mutex", "debug_event",
88 "debug_http", "debug_mail", "debug_mysql", "debug_stream"
88 "debug_http", "debug_mail", "debug_stream"
8989 };
9090
9191
2828 #define NGX_LOG_DEBUG_EVENT 0x080
2929 #define NGX_LOG_DEBUG_HTTP 0x100
3030 #define NGX_LOG_DEBUG_MAIL 0x200
31 #define NGX_LOG_DEBUG_MYSQL 0x400
32 #define NGX_LOG_DEBUG_STREAM 0x800
31 #define NGX_LOG_DEBUG_STREAM 0x400
3332
3433 /*
3534 * do not forget to update debug_levels[] in src/core/ngx_log.c
+0
-13
src/mysql/config less more
0
1 ngx_addon_name=ngx_mysql
2
3 HTTP_MODULES="$HTTP_MODULES ngx_http_mysql_test_module"
4
5 HTTP_INCS="$HTTP_INCS $ngx_addon_dir"
6 HTTP_DEPS="$HTTP_DEPS $ngx_addon_dir/ngx_mysql.h"
7 #CORE_LIBS="$CORE_LIBS -lmd"
8
9 USE_SHA1=YES
10
11 NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_mysql.c"
12 NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_mysql_test.c"
+0
-204
src/mysql/ngx_http_mysql_test.c less more
0
1 /*
2 * Copyright (C) Igor Sysoev
3 * Copyright (C) Nginx, Inc.
4 */
5
6 #include <ngx_config.h>
7 #include <ngx_core.h>
8 #include <ngx_mysql.h>
9 #include <ngx_http.h>
10
11
12 typedef struct {
13 ngx_addr_t *peers;
14 ngx_uint_t npeers;
15 } ngx_http_mysql_test_conf_t;
16
17
18 static void ngx_http_mysql_auth(ngx_mysql_t *m);
19 static void ngx_http_mysql_done(ngx_mysql_t *m);
20 static void *ngx_http_mysql_test_create_loc_conf(ngx_conf_t *cf);
21 static char *ngx_http_mysql_test(ngx_conf_t *cf, ngx_command_t *cmd,
22 void *conf);
23
24 static ngx_command_t ngx_http_mysql_test_commands[] = {
25
26 { ngx_string("mysql_test"),
27 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
28 ngx_http_mysql_test,
29 NGX_HTTP_LOC_CONF_OFFSET,
30 0,
31 NULL },
32
33 ngx_null_command
34 };
35
36
37 static ngx_http_module_t ngx_http_mysql_test_module_ctx = {
38 NULL, /* preconfiguration */
39 NULL, /* postconfiguration */
40
41 NULL, /* create main configuration */
42 NULL, /* init main configuration */
43
44 NULL, /* create server configuration */
45 NULL, /* merge server configuration */
46
47 ngx_http_mysql_test_create_loc_conf, /* create location configuration */
48 NULL /* merge location configuration */
49 };
50
51
52 ngx_module_t ngx_http_mysql_test_module = {
53 NGX_MODULE_V1,
54 &ngx_http_mysql_test_module_ctx, /* module context */
55 ngx_http_mysql_test_commands, /* module directives */
56 NGX_HTTP_MODULE, /* module type */
57 NULL, /* init master */
58 NULL, /* init module */
59 NULL, /* init process */
60 NULL, /* init thread */
61 NULL, /* exit thread */
62 NULL, /* exit process */
63 NULL, /* exit master */
64 NGX_MODULE_V1_PADDING
65 };
66
67
68 static ngx_str_t ngx_mysql_login = ngx_string("root");
69 static ngx_str_t ngx_mysql_passwd = ngx_string("tp");
70 static ngx_str_t ngx_mysql_database = ngx_string("mysql");
71 static ngx_str_t ngx_mysql_command_query =
72 ngx_string("select * from user");
73
74
75 static ngx_int_t
76 ngx_http_mysql_test_handler(ngx_http_request_t *r)
77 {
78 ngx_int_t rc;
79 ngx_mysql_t *m;
80 ngx_http_mysql_test_conf_t *mtcf;
81
82 mtcf = ngx_http_get_module_loc_conf(r, ngx_http_mysql_test_module);
83
84 m = ngx_pcalloc(r->pool, sizeof(ngx_mysql_t));
85
86 if (m == NULL) {
87 return NGX_HTTP_INTERNAL_SERVER_ERROR;
88 }
89
90 m->pool = r->pool;
91 m->handler = ngx_http_mysql_auth;
92 m->data = r;
93
94 m->login = &ngx_mysql_login;
95 m->passwd = &ngx_mysql_passwd;
96 m->database = &ngx_mysql_database;
97
98 /* STUB */
99 m->peer.sockaddr = mtcf->peers[0].sockaddr;
100 m->peer.socklen = mtcf->peers[0].socklen;
101 m->peer.name = &mtcf->peers[0].name;
102 m->peer.tries = mtcf->npeers;
103 m->peer.get = ngx_event_get_peer;
104 /**/
105 m->peer.log = r->connection->log;
106 m->peer.log_error = NGX_ERROR_ERR;
107
108 rc = ngx_mysql_connect(m);
109
110 if (rc == NGX_OK || rc == NGX_AGAIN) {
111 return NGX_DONE;
112 }
113
114 return NGX_HTTP_INTERNAL_SERVER_ERROR;
115 }
116
117
118 static void
119 ngx_http_mysql_auth(ngx_mysql_t *m)
120 {
121 ngx_http_request_t *r;
122
123 r = m->data;
124
125 if (m->state != NGX_OK) {
126 ngx_http_finalize_request(r, NGX_HTTP_NO_CONTENT);
127 return;
128 }
129
130 m->query.len = NGX_MYSQL_CMDPKT_LEN + ngx_mysql_command_query.len;
131
132 m->query.data = ngx_pnalloc(r->pool, m->query.len);
133 if (m->query.data == NULL) {
134 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
135 return;
136 }
137
138 ngx_memcpy(m->query.data + NGX_MYSQL_CMDPKT_LEN,
139 ngx_mysql_command_query.data, ngx_mysql_command_query.len);
140
141 m->handler = ngx_http_mysql_done;
142
143 ngx_mysql_query(m);
144 }
145
146
147 static void
148 ngx_http_mysql_done(ngx_mysql_t *m)
149 {
150 ngx_http_request_t *r;
151
152 r = m->data;
153
154 ngx_http_finalize_request(r, NGX_HTTP_NO_CONTENT);
155 }
156
157
158 static void *
159 ngx_http_mysql_test_create_loc_conf(ngx_conf_t *cf)
160 {
161 ngx_http_mysql_test_conf_t *conf;
162
163 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_mysql_test_conf_t));
164 if (conf == NULL) {
165 return NGX_CONF_ERROR;
166 }
167
168 return conf;
169 }
170
171 static char *
172 ngx_http_mysql_test(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
173 {
174 ngx_http_mysql_test_conf_t *mtcf = conf;
175
176 ngx_str_t *value;
177 ngx_url_t u;
178 ngx_http_core_loc_conf_t *clcf;
179
180 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
181 clcf->handler = ngx_http_mysql_test_handler;
182
183 value = cf->args->elts;
184
185 ngx_memzero(&u, sizeof(ngx_url_t));
186
187 u.url = value[1];
188 u.default_port = 3306;
189
190 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
191 if (u.err) {
192 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
193 "%s in upstream \"%V\"", u.err, &u.url);
194 }
195
196 return NGX_CONF_ERROR;
197 }
198
199 mtcf->peers = u.addrs;
200 mtcf->npeers = u.naddrs;
201
202 return NGX_CONF_OK;
203 }
+0
-465
src/mysql/ngx_mysql.c less more
0
1 /*
2 * Copyright (C) Igor Sysoev
3 * Copyright (C) Nginx, Inc.
4 */
5
6
7 /* the library supports the subset of the MySQL 4.1+ protocol (version 10) */
8
9
10 #include <ngx_config.h>
11 #include <ngx_core.h>
12 #include <ngx_event.h>
13 #include <ngx_event_connect.h>
14 #include <ngx_mysql.h>
15 #include <ngx_sha1.h>
16
17
18 #define NGX_MYSQL_LONG_PASSWORD 0x0001
19 #define NGX_MYSQL_CONNECT_WITH_DB 0x0008
20 #define NGX_MYSQL_PROTOCOL_41 0x0200
21 #define NGX_MYSQL_SECURE_CONNECTION 0x8000
22
23
24 #define NGX_MYSQL_CMD_QUERY 3
25
26
27 typedef struct {
28 u_char pktlen[3];
29 u_char pktn;
30
31 u_char protocol;
32 u_char version[1]; /* NULL-terminated string */
33 } ngx_mysql_greeting1_pkt_t;
34
35
36 typedef struct {
37 u_char thread[4];
38 u_char salt1[9];
39 u_char capacity[2];
40 u_char charset;
41 u_char status[2];
42 u_char zero[13];
43 u_char salt2[13];
44 } ngx_mysql_greeting2_pkt_t;
45
46
47 typedef struct {
48 u_char pktlen[3];
49 u_char pktn;
50
51 u_char capacity[4];
52 u_char max_packet[4];
53 u_char charset;
54 u_char zero[23];
55 u_char login[1]; /* NULL-terminated string */
56
57 /*
58 * u_char passwd_len; 0 if no password
59 * u_char passwd[20];
60 *
61 * u_char database[1]; NULL-terminated string
62 */
63
64 } ngx_mysql_auth_pkt_t;
65
66
67 typedef struct {
68 u_char pktlen[3];
69 u_char pktn;
70 u_char fields;
71 } ngx_mysql_response_pkt_t;
72
73
74 typedef struct {
75 u_char pktlen[3];
76 u_char pktn;
77 u_char err;
78 u_char code[2];
79 u_char message[1]; /* string */
80 } ngx_mysql_error_pkt_t;
81
82
83 typedef struct {
84 u_char pktlen[3];
85 u_char pktn;
86 u_char command;
87 u_char arg[1]; /* string */
88 } ngx_mysql_command_pkt_t;
89
90
91 static void ngx_mysql_read_server_greeting(ngx_event_t *rev);
92 static void ngx_mysql_empty_handler(ngx_event_t *wev);
93 static void ngx_mysql_read_auth_result(ngx_event_t *rev);
94 static void ngx_mysql_read_query_result(ngx_event_t *rev);
95 static void ngx_mysql_close(ngx_mysql_t *m, ngx_int_t rc);
96
97
98 ngx_int_t
99 ngx_mysql_connect(ngx_mysql_t *m)
100 {
101 ngx_int_t rc;
102
103 #if 0
104 if (cached) {
105 return NGX_OK;
106 }
107 #endif
108
109 m->peer.log->action = "connecting to mysql server";
110
111 rc = ngx_event_connect_peer(&m->peer);
112
113 if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
114 return rc;
115 }
116
117 m->peer.connection->data = m;
118
119 m->peer.connection->read->handler = ngx_mysql_read_server_greeting;
120 m->peer.connection->write->handler = ngx_mysql_empty_handler;
121
122 ngx_add_timer(m->peer.connection->read, /* STUB */ 5000);
123
124 return NGX_OK;
125 }
126
127
128 static void
129 ngx_mysql_read_server_greeting(ngx_event_t *rev)
130 {
131 size_t len;
132 u_char *p;
133 ssize_t n;
134 ngx_uint_t i, capacity;
135 ngx_mysql_t *m;
136 ngx_connection_t *c;
137 ngx_mysql_greeting1_pkt_t *gr1;
138 ngx_mysql_greeting2_pkt_t *gr2;
139 ngx_mysql_auth_pkt_t *auth;
140 ngx_sha1_t sha;
141 u_char hash1[20], hash2[20];
142
143 c = rev->data;
144 m = c->data;
145
146 if (rev->timedout) {
147 ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT,
148 "mysql server %V timed out", m->peer.name);
149
150 ngx_mysql_close(m, NGX_ERROR);
151 return;
152 }
153
154 if (m->buf == NULL) {
155 m->peer.log->action = "reading mysql server greeting";
156
157 m->buf = ngx_create_temp_buf(m->pool, /* STUB */ 1024);
158 if (m->buf == NULL) {
159 ngx_mysql_close(m, NGX_ERROR);
160 return;
161 }
162 }
163
164 n = ngx_recv(m->peer.connection, m->buf->pos, /* STUB */ 1024);
165
166 if (n == NGX_AGAIN) {
167 return;
168 }
169
170 if (n < 5) {
171 ngx_mysql_close(m, NGX_ERROR);
172 return;
173 }
174
175 gr1 = (ngx_mysql_greeting1_pkt_t *) m->buf->pos;
176
177 if (ngx_m24toh(gr1->pktlen) > n - 4) {
178 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
179 "mysql server %V sent incomplete greeting packet",
180 m->peer.name);
181
182 ngx_mysql_close(m, NGX_ERROR);
183 return;
184 }
185
186 if (gr1->protocol < 10) {
187 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
188 "mysql server %V sent unsupported protocol version %ud",
189 m->peer.name, gr1->protocol);
190
191 ngx_mysql_close(m, NGX_ERROR);
192 return;
193 }
194
195 gr2 = (ngx_mysql_greeting2_pkt_t *)
196 (gr1->version + ngx_strlen(gr1->version) + 1);
197
198 capacity = ngx_m16toh(gr2->capacity);
199
200 ngx_log_debug8(NGX_LOG_DEBUG_MYSQL, rev->log, 0,
201 "mysql version: %ud, \"%s\", thread: %ud, salt: \"%s\", "
202 "capacity: %Xd, charset: %ud, status: %ud, salt rest \"%s\"",
203 gr1->protocol, gr1->version, ngx_m32toh(gr2->thread),
204 gr2->salt1, capacity, gr2->charset,
205 ngx_m16toh(gr2->status), &gr2->salt2);
206
207 capacity = NGX_MYSQL_LONG_PASSWORD
208 | NGX_MYSQL_CONNECT_WITH_DB
209 | NGX_MYSQL_PROTOCOL_41
210 | NGX_MYSQL_SECURE_CONNECTION;
211
212 len = 4 + 4 + 4 + 1 + 23 + m->login->len + 1 + 1 + m->database->len + 1;
213
214 if (m->passwd->len) {
215 len += 20;
216 }
217
218 auth = ngx_pnalloc(m->pool, len);
219 if (auth == NULL) {
220 ngx_mysql_close(m, NGX_ERROR);
221 return;
222 }
223
224 ngx_htom24(auth->pktlen, len - 4);
225 auth->pktn = (u_char) (gr1->pktn + 1);
226
227 ngx_htom32(auth->capacity, capacity);
228 ngx_htom32(auth->max_packet, 0x01000000); /* max packet size 2^24 */
229 ngx_memzero(auth->zero, 24);
230 auth->charset = gr2->charset;
231
232 p = ngx_copy(auth->login, m->login->data, m->login->len);
233 *p++ = '\0';
234
235 if (m->passwd->len) {
236
237 *p++ = (u_char) 20;
238
239 ngx_sha1_init(&sha);
240 ngx_sha1_update(&sha, m->passwd->data, m->passwd->len);
241 ngx_sha1_final(hash1, &sha);
242
243 ngx_sha1_init(&sha);
244 ngx_sha1_update(&sha, hash1, 20);
245 ngx_sha1_final(hash2, &sha);
246
247 ngx_sha1_init(&sha);
248 ngx_sha1_update(&sha, gr2->salt1, 8);
249 ngx_sha1_update(&sha, gr2->salt2, 12);
250 ngx_sha1_update(&sha, hash2, 20);
251 ngx_sha1_final(hash2, &sha);
252
253 for (i = 0; i < 20; i++) {
254 *p++ = (u_char) (hash1[i] ^ hash2[i]);
255 }
256
257 } else {
258 *p++ = '\0';
259 }
260
261 p = ngx_copy(p, m->database->data, m->database->len);
262 *p = '\0';
263
264
265 n = ngx_send(m->peer.connection, (void *) auth, len);
266
267 if (n < (ssize_t) len) {
268 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
269 "the incomplete packet was sent to mysql server %V",
270 m->peer.name);
271
272 ngx_mysql_close(m, NGX_ERROR);
273 return;
274 }
275
276 m->peer.connection->read->handler = ngx_mysql_read_auth_result;
277
278 ngx_add_timer(m->peer.connection->read, /* STUB */ 5000);
279 }
280
281
282 static void
283 ngx_mysql_empty_handler(ngx_event_t *wev)
284 {
285 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "mysql empty handler");
286
287 return;
288 }
289
290
291 static void
292 ngx_mysql_read_auth_result(ngx_event_t *rev)
293 {
294 ssize_t n, len;
295 ngx_str_t msg;
296 ngx_mysql_t *m;
297 ngx_connection_t *c;
298 ngx_mysql_error_pkt_t *epkt;
299 ngx_mysql_response_pkt_t *pkt;
300
301 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "mysql read auth");
302
303 c = rev->data;
304 m = c->data;
305
306 m->peer.log->action = "reading mysql auth result";
307
308 n = ngx_recv(m->peer.connection, m->buf->pos, /* STUB */ 1024);
309
310 if (n == NGX_AGAIN) {
311 return;
312 }
313
314 if (n < 5) {
315 ngx_mysql_close(m, NGX_ERROR);
316 return;
317 }
318
319 pkt = (ngx_mysql_response_pkt_t *) m->buf->pos;
320
321 len = ngx_m24toh(pkt->pktlen);
322
323 if (len > n - 4) {
324 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
325 "mysql server %V sent incomplete response packet",
326 m->peer.name);
327
328 ngx_mysql_close(m, NGX_ERROR);
329 return;
330 }
331
332 if (pkt->fields == 0) {
333 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "mysql auth OK");
334
335 m->state = NGX_OK;
336 m->pktn = 0;
337
338 m->handler(m);
339
340 return;
341 }
342
343 epkt = (ngx_mysql_error_pkt_t *) pkt;
344
345 msg.len = (u_char *) epkt + 4 + len - epkt->message;
346 msg.data = epkt->message;
347
348 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
349 "mysql server %V sent error (%ud): \"%V\"",
350 m->peer.name, ngx_m16toh(epkt->code), &msg);
351
352 ngx_mysql_close(m, NGX_ERROR);
353 }
354
355
356 ngx_int_t
357 ngx_mysql_query(ngx_mysql_t *m)
358 {
359 ssize_t n;
360 ngx_mysql_command_pkt_t *pkt;
361
362 pkt = (ngx_mysql_command_pkt_t *) m->query.data;
363
364 ngx_htom24(pkt->pktlen, m->query.len - 4);
365 pkt->pktn = (u_char) m->pktn++;
366 pkt->command = NGX_MYSQL_CMD_QUERY;
367
368 n = ngx_send(m->peer.connection, m->query.data, m->query.len);
369
370 if (n < (ssize_t) m->query.len) {
371 ngx_log_error(NGX_LOG_ERR, m->peer.log, 0,
372 "the incomplete packet was sent to mysql server %V",
373 m->peer.name);
374
375 ngx_mysql_close(m, NGX_ERROR);
376 return NGX_OK;
377 }
378
379 m->peer.connection->read->handler = ngx_mysql_read_query_result;
380
381 ngx_add_timer(m->peer.connection->read, /* STUB */ 5000);
382
383 /* STUB handle event */
384
385 return NGX_OK;
386 }
387
388
389 static void
390 ngx_mysql_read_query_result(ngx_event_t *rev)
391 {
392 ssize_t n, len;
393 ngx_str_t msg;
394 ngx_mysql_t *m;
395 ngx_connection_t *c;
396 ngx_mysql_error_pkt_t *epkt;
397 ngx_mysql_response_pkt_t *pkt;
398
399 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "mysql read query result");
400
401 c = rev->data;
402 m = c->data;
403
404 m->peer.log->action = "reading mysql read query result";
405
406 n = ngx_recv(m->peer.connection, m->buf->pos, /* STUB */ 1024);
407
408 if (n == NGX_AGAIN) {
409 return;
410 }
411
412 if (n < 5) {
413 ngx_mysql_close(m, NGX_ERROR);
414 return;
415 }
416
417 pkt = (ngx_mysql_response_pkt_t *) m->buf->pos;
418
419 len = ngx_m24toh(pkt->pktlen);
420
421 if (len > n - 4) {
422 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
423 "mysql server %V sent incomplete response packet",
424 m->peer.name);
425
426 ngx_mysql_close(m, NGX_ERROR);
427 return;
428 }
429
430 if (pkt->fields != 0xff) {
431 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "mysql query OK");
432
433 m->state = NGX_OK;
434 m->pktn = pkt->pktn;
435
436 m->handler(m);
437
438 return;
439 }
440
441 epkt = (ngx_mysql_error_pkt_t *) pkt;
442
443 msg.len = (u_char *) epkt + 4 + len - epkt->message;
444 msg.data = epkt->message;
445
446 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
447 "mysql server %V sent error (%ud): \"%V\"",
448 m->peer.name, ngx_m16toh(epkt->code), &msg);
449
450 ngx_mysql_close(m, NGX_ERROR);
451 }
452
453
454 static void
455 ngx_mysql_close(ngx_mysql_t *m, ngx_int_t rc)
456 {
457 if (rc == NGX_ERROR) {
458 ngx_close_connection(m->peer.connection);
459 }
460
461 m->state = rc;
462
463 m->handler(m);
464 }
+0
-85
src/mysql/ngx_mysql.h less more
0
1 /*
2 * Copyright (C) Igor Sysoev
3 * Copyright (C) Nginx, Inc.
4 */
5
6
7 #ifndef _NGX_MYSQL_H_INCLUDED_
8 #define _NGX_MYSQL_H_INCLUDED_
9
10
11 #include <ngx_config.h>
12 #include <ngx_core.h>
13 #include <ngx_event.h>
14 #include <ngx_event_connect.h>
15
16
17 typedef struct ngx_mysql_s ngx_mysql_t;
18
19 typedef void (*ngx_mysql_handler_pt)(ngx_mysql_t *m);
20
21
22 struct ngx_mysql_s {
23 ngx_peer_connection_t peer;
24
25 ngx_buf_t *buf;
26 ngx_pool_t *pool;
27
28 ngx_str_t *login;
29 ngx_str_t *passwd;
30 ngx_str_t *database;
31
32 ngx_str_t query;
33
34 ngx_uint_t pktn;
35
36 ngx_mysql_handler_pt handler;
37 void *data;
38 ngx_int_t state;
39
40 };
41
42
43 #define NGX_MYSQL_CMDPKT_LEN 5
44
45
46 #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED && 0)
47
48 #define ngx_m16toh(n) (*(uint32_t *) n & 0x0000ffff)
49 #define ngx_m24toh(n) (*(uint32_t *) n & 0x00ffffff)
50 #define ngx_m32toh(n) *(uint32_t *) n
51
52 #define ngx_htom16(n, m) *(uint16_t *) n = (uint16_t) ((m) & 0xffff)
53
54 #define ngx_htom24(n, m) (n)[0] = (u_char) ((m) & 0xff); \
55 (n)[1] = (u_char) (((m) >> 8) & 0xff); \
56 (n)[2] = (u_char) (((m) >> 16) & 0xff)
57
58 #define ngx_htom32(n, m) *(uint32_t *) (n) = (m)
59
60 #else
61
62 #define ngx_m16toh(n) (n[0] | n[1] << 8)
63 #define ngx_m24toh(n) (n[0] | n[1] << 8 | n[2] << 16)
64 #define ngx_m32toh(n) (n[0] | n[1] << 8 | n[2] << 16 | n[3] << 24)
65
66 #define ngx_htom16(n, m) (n)[0] = (u_char) (m); (n)[1] = (u_char) ((m) >> 8)
67
68 #define ngx_htom24(n, m) (n)[0] = (u_char) ((m) & 0xff); \
69 (n)[1] = (u_char) (((m) >> 8) & 0xff); \
70 (n)[2] = (u_char) (((m) >> 16) & 0xff)
71
72 #define ngx_htom32(n, m) (n)[0] = (u_char) ((m) & 0xff); \
73 (n)[1] = (u_char) (((m) >> 8) & 0xff); \
74 (n)[2] = (u_char) (((m) >> 16) & 0xff); \
75 (n)[3] = (u_char) (((m) >> 24) & 0xff)
76
77 #endif
78
79
80 ngx_int_t ngx_mysql_connect(ngx_mysql_t *m);
81 ngx_int_t ngx_mysql_query(ngx_mysql_t *m);
82
83
84 #endif /* _NGX_MYSQL_H_INCLUDED_ */