76
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #ifndef _NGX_IMAP_H_INCLUDED_
|
|
8 #define _NGX_IMAP_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
|
88
|
16 #if (NGX_IMAP_SSL)
|
|
17 #include <ngx_imap_ssl_module.h>
|
|
18 #endif
|
|
19
|
|
20
|
76
|
21
|
|
22 typedef struct {
|
|
23 void **main_conf;
|
|
24 void **srv_conf;
|
|
25 } ngx_imap_conf_ctx_t;
|
|
26
|
|
27
|
|
28 typedef struct {
|
|
29 ngx_array_t servers; /* ngx_imap_core_srv_conf_t */
|
|
30 } ngx_imap_core_main_conf_t;
|
|
31
|
|
32
|
|
33 #define NGX_IMAP_POP3_PROTOCOL 0
|
|
34 #define NGX_IMAP_IMAP_PROTOCOL 1
|
|
35
|
|
36 typedef struct {
|
|
37 ngx_msec_t timeout;
|
|
38
|
|
39 size_t imap_client_buffer_size;
|
|
40
|
|
41 ngx_uint_t protocol;
|
|
42
|
|
43 ngx_buf_t *pop3_capability;
|
|
44 ngx_buf_t *imap_capability;
|
|
45
|
|
46 ngx_array_t pop3_capabilities;
|
|
47 ngx_array_t imap_capabilities;
|
|
48
|
|
49 /* server ctx */
|
|
50 ngx_imap_conf_ctx_t *ctx;
|
|
51 } ngx_imap_core_srv_conf_t;
|
|
52
|
|
53
|
|
54 typedef struct {
|
|
55 void *(*create_main_conf)(ngx_conf_t *cf);
|
|
56 char *(*init_main_conf)(ngx_conf_t *cf, void *conf);
|
|
57
|
|
58 void *(*create_srv_conf)(ngx_conf_t *cf);
|
|
59 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, void *conf);
|
|
60 } ngx_imap_module_t;
|
|
61
|
|
62
|
|
63 typedef enum {
|
|
64 ngx_imap_start = 0,
|
|
65 ngx_imap_login,
|
|
66 ngx_imap_user,
|
|
67 ngx_imap_passwd,
|
|
68 } ngx_imap_state_e;
|
|
69
|
|
70
|
|
71 typedef enum {
|
|
72 ngx_pop3_start = 0,
|
|
73 ngx_pop3_user,
|
|
74 ngx_pop3_passwd
|
|
75 } ngx_po3_state_e;
|
|
76
|
|
77
|
|
78 typedef struct {
|
|
79 ngx_peer_connection_t upstream;
|
|
80 ngx_buf_t *buffer;
|
|
81 } ngx_imap_proxy_ctx_t;
|
|
82
|
|
83
|
|
84 typedef struct {
|
|
85 uint32_t signature; /* "IMAP" */
|
|
86
|
|
87 ngx_connection_t *connection;
|
|
88
|
88
|
89 ngx_str_t out;
|
76
|
90 ngx_buf_t *buffer;
|
|
91
|
|
92 void **ctx;
|
|
93 void **main_conf;
|
|
94 void **srv_conf;
|
|
95
|
|
96 ngx_imap_proxy_ctx_t *proxy;
|
|
97
|
|
98 ngx_uint_t imap_state;
|
|
99
|
88
|
100 unsigned blocked:1;
|
|
101 unsigned quit:1;
|
76
|
102 unsigned protocol:1;
|
|
103 unsigned quoted:1;
|
92
|
104 unsigned backslash:1;
|
|
105 unsigned no_sync_literal:1;
|
76
|
106
|
|
107 ngx_str_t login;
|
|
108 ngx_str_t passwd;
|
|
109
|
|
110 ngx_str_t tag;
|
88
|
111 ngx_str_t tagged_line;
|
76
|
112
|
|
113 ngx_uint_t command;
|
|
114 ngx_array_t args;
|
|
115
|
|
116 ngx_uint_t login_attempt;
|
|
117
|
|
118 /* used to parse IMAP/POP3 command */
|
|
119
|
|
120 ngx_uint_t state;
|
|
121 u_char *cmd_start;
|
|
122 u_char *arg_start;
|
|
123 u_char *arg_end;
|
|
124 ngx_uint_t literal_len;
|
|
125 } ngx_imap_session_t;
|
|
126
|
|
127
|
90
|
128 typedef struct {
|
|
129 ngx_str_t *client;
|
|
130 ngx_imap_session_t *session;
|
|
131 } ngx_imap_log_ctx_t;
|
|
132
|
|
133
|
76
|
134 #define NGX_POP3_USER 1
|
|
135 #define NGX_POP3_PASS 2
|
|
136 #define NGX_POP3_CAPA 3
|
|
137 #define NGX_POP3_QUIT 4
|
|
138 #define NGX_POP3_NOOP 5
|
|
139 #define NGX_POP3_APOP 6
|
|
140 #define NGX_POP3_STAT 7
|
|
141 #define NGX_POP3_LIST 8
|
|
142 #define NGX_POP3_RETR 9
|
|
143 #define NGX_POP3_DELE 10
|
|
144 #define NGX_POP3_RSET 11
|
|
145 #define NGX_POP3_TOP 12
|
|
146 #define NGX_POP3_UIDL 13
|
|
147
|
|
148
|
|
149 #define NGX_IMAP_LOGIN 1
|
|
150 #define NGX_IMAP_LOGOUT 2
|
|
151 #define NGX_IMAP_CAPABILITY 3
|
|
152 #define NGX_IMAP_NOOP 4
|
|
153
|
|
154 #define NGX_IMAP_NEXT 5
|
|
155
|
|
156
|
|
157 #define NGX_IMAP_PARSE_INVALID_COMMAND 20
|
|
158
|
|
159
|
|
160 #define NGX_IMAP_PROXY_INVALID 10
|
|
161 #define NGX_IMAP_PROXY_ERROR 11
|
|
162
|
|
163
|
|
164 #define NGX_IMAP_MODULE 0x50414D49 /* "IMAP" */
|
|
165
|
|
166 #define NGX_IMAP_MAIN_CONF 0x02000000
|
|
167 #define NGX_IMAP_SRV_CONF 0x04000000
|
|
168
|
|
169
|
|
170 #define NGX_IMAP_MAIN_CONF_OFFSET offsetof(ngx_imap_conf_ctx_t, main_conf)
|
|
171 #define NGX_IMAP_SRV_CONF_OFFSET offsetof(ngx_imap_conf_ctx_t, srv_conf)
|
|
172
|
|
173
|
|
174 #define ngx_imap_get_module_ctx(s, module) (s)->ctx[module.ctx_index]
|
|
175 #define ngx_imap_set_ctx(s, c, module) s->ctx[module.ctx_index] = c;
|
|
176 #define ngx_imap_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL;
|
|
177
|
|
178
|
|
179 #define ngx_imap_get_module_main_conf(s, module) \
|
|
180 (s)->main_conf[module.ctx_index]
|
|
181 #define ngx_imap_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index]
|
|
182
|
|
183
|
|
184 void ngx_imap_init_connection(ngx_connection_t *c);
|
88
|
185 void ngx_imap_send(ngx_event_t *wev);
|
76
|
186 void ngx_imap_auth_state(ngx_event_t *rev);
|
|
187 void ngx_pop3_auth_state(ngx_event_t *rev);
|
|
188 void ngx_imap_close_connection(ngx_connection_t *c);
|
|
189 void ngx_imap_session_internal_server_error(ngx_imap_session_t *s);
|
|
190
|
|
191 ngx_int_t ngx_imap_parse_command(ngx_imap_session_t *s);
|
|
192 ngx_int_t ngx_pop3_parse_command(ngx_imap_session_t *s);
|
|
193
|
|
194
|
|
195 /* STUB */
|
|
196 void ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers);
|
|
197 void ngx_imap_auth_http_init(ngx_imap_session_t *s);
|
|
198 /**/
|
|
199
|
|
200
|
|
201 extern ngx_uint_t ngx_imap_max_module;
|
|
202 extern ngx_module_t ngx_imap_core_module;
|
|
203
|
|
204
|
|
205 #endif /* _NGX_IMAP_H_INCLUDED_ */
|