blob: 17cb1afba980e75db20285e3357aa16467d885b5 [file] [log] [blame]
Igor Sysoevac72bd12006-05-04 15:32:46 +00001
2/*
3 * Copyright (C) Igor Sysoev
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>
Igor Sysoevafd7ec52006-05-29 17:28:12 +000014#include <ngx_event_connect.h>
Igor Sysoevac72bd12006-05-04 15:32:46 +000015
16
Igor Sysoevafd7ec52006-05-29 17:28:12 +000017typedef struct ngx_mysql_s ngx_mysql_t;
18
19typedef void (*ngx_mysql_handler_pt)(ngx_mysql_t *m);
20
21
22struct ngx_mysql_s {
Igor Sysoevac72bd12006-05-04 15:32:46 +000023 ngx_peer_connection_t peer;
Igor Sysoevafd7ec52006-05-29 17:28:12 +000024
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
Igor Sysoevac72bd12006-05-04 15:32:46 +000044
45
46#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED && 0)
47
Igor Sysoevafd7ec52006-05-29 17:28:12 +000048#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)
Igor Sysoevac72bd12006-05-04 15:32:46 +000059
60#else
61
Igor Sysoevafd7ec52006-05-29 17:28:12 +000062#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)
Igor Sysoevac72bd12006-05-04 15:32:46 +000076
77#endif
78
79
Igor Sysoevafd7ec52006-05-29 17:28:12 +000080ngx_int_t ngx_mysql_connect(ngx_mysql_t *m);
81ngx_int_t ngx_mysql_query(ngx_mysql_t *m);
82
83
Igor Sysoevac72bd12006-05-04 15:32:46 +000084#endif /* _NGX_MYSQL_H_INCLUDED_ */