Mercurial > hg > nginx-mail
annotate src/mail/ngx_mail.h @ 398:f9e6413396d4 PATCH_NGINX_MAIL_0_2
Mail: IMAP AUTHENTICATE command support.
Supported auth methods: PLAIN, LOGIN, CRAM-MD5.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 19 Jul 2007 02:43:59 +0000 |
parents | e2d916d7e50f |
children | f1e2fab7a46c |
rev | line source |
---|---|
290 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #ifndef _NGX_MAIL_H_INCLUDED_ | |
8 #define _NGX_MAIL_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 #if (NGX_MAIL_SSL) | |
17 #include <ngx_mail_ssl_module.h> | |
18 #endif | |
19 | |
20 | |
21 | |
22 typedef struct { | |
23 void **main_conf; | |
24 void **srv_conf; | |
25 } ngx_mail_conf_ctx_t; | |
26 | |
27 | |
28 typedef struct { | |
29 in_addr_t addr; | |
30 in_port_t port; | |
31 int family; | |
32 | |
33 /* server ctx */ | |
34 ngx_mail_conf_ctx_t *ctx; | |
35 | |
36 unsigned bind:1; | |
37 } ngx_mail_listen_t; | |
38 | |
39 | |
40 typedef struct { | |
41 in_addr_t addr; | |
42 ngx_mail_conf_ctx_t *ctx; | |
43 ngx_str_t addr_text; | |
44 } ngx_mail_in_addr_t; | |
45 | |
46 | |
47 typedef struct { | |
48 ngx_mail_in_addr_t *addrs; /* array of ngx_mail_in_addr_t */ | |
49 ngx_uint_t naddrs; | |
50 } ngx_mail_in_port_t; | |
51 | |
52 | |
53 typedef struct { | |
54 in_port_t port; | |
55 ngx_array_t addrs; /* array of ngx_mail_conf_in_addr_t */ | |
56 } ngx_mail_conf_in_port_t; | |
57 | |
58 | |
59 typedef struct { | |
60 in_addr_t addr; | |
61 ngx_mail_conf_ctx_t *ctx; | |
62 unsigned bind:1; | |
63 } ngx_mail_conf_in_addr_t; | |
64 | |
65 | |
66 typedef struct { | |
67 ngx_array_t servers; /* ngx_mail_core_srv_conf_t */ | |
68 ngx_array_t listen; /* ngx_mail_listen_t */ | |
69 } ngx_mail_core_main_conf_t; | |
70 | |
394 | 71 typedef void (*ngx_mail_handler_pt)(ngx_connection_t *c); |
290 | 72 |
73 #define NGX_MAIL_POP3_PROTOCOL 0 | |
74 #define NGX_MAIL_IMAP_PROTOCOL 1 | |
75 #define NGX_MAIL_SMTP_PROTOCOL 2 | |
76 | |
77 typedef struct { | |
78 ngx_msec_t timeout; | |
79 | |
80 size_t imap_client_buffer_size; | |
81 | |
82 ngx_uint_t protocol; | |
83 | |
84 ngx_flag_t so_keepalive; | |
85 | |
86 ngx_str_t pop3_capability; | |
87 ngx_str_t pop3_starttls_capability; | |
88 ngx_str_t pop3_starttls_only_capability; | |
89 ngx_str_t pop3_auth_capability; | |
90 | |
91 ngx_str_t imap_capability; | |
92 ngx_str_t imap_starttls_capability; | |
93 ngx_str_t imap_starttls_only_capability; | |
94 | |
95 ngx_str_t smtp_capability; | |
396
e2d916d7e50f
Mail: starttls only support for SMTP.
Maxim Dounin <mdounin@mdounin.ru>
parents:
394
diff
changeset
|
96 ngx_str_t smtp_starttls_capability; |
e2d916d7e50f
Mail: starttls only support for SMTP.
Maxim Dounin <mdounin@mdounin.ru>
parents:
394
diff
changeset
|
97 ngx_str_t smtp_starttls_only_capability; |
290 | 98 |
99 ngx_str_t server_name; | |
100 ngx_str_t smtp_server_name; | |
101 ngx_str_t smtp_greeting; | |
102 | |
103 ngx_uint_t pop3_auth_methods; | |
398
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
104 ngx_uint_t imap_auth_methods; |
290 | 105 ngx_uint_t smtp_auth_methods; |
106 | |
107 ngx_array_t pop3_capabilities; | |
108 ngx_array_t imap_capabilities; | |
109 ngx_array_t smtp_capabilities; | |
110 | |
394 | 111 /* |
112 * Handlers: | |
113 * | |
114 * - handler_init_session | |
115 * | |
116 * Init new session after client connects. Protocol greetings printed | |
117 * from here, so you need to define this if you need custom greeting | |
118 * (or pause before greeting printed). | |
119 * | |
120 * - handler_init_protocol | |
121 * | |
122 * Initialize protocol-specific data after client sent first command. | |
123 * Notably, this is re-called after STARTTLS negotiation. | |
124 * | |
125 * - handler_read | |
126 * | |
127 * Read client command. Could be the only handler used by simple | |
128 * modules. | |
129 * | |
130 * NB: handler_read is re-used after auth_http module work (if it was | |
131 * called throgh ngx_mail_auth_http_init()) in case of error returned | |
132 * by auth server, so you should set this if you use auth_http. | |
133 */ | |
134 | |
135 ngx_mail_handler_pt handler_init_session; | |
136 ngx_event_handler_pt handler_init_protocol; | |
137 ngx_event_handler_pt handler_read; | |
138 | |
290 | 139 /* server ctx */ |
140 ngx_mail_conf_ctx_t *ctx; | |
141 } ngx_mail_core_srv_conf_t; | |
142 | |
143 | |
144 typedef struct { | |
145 void *(*create_main_conf)(ngx_conf_t *cf); | |
146 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
147 | |
148 void *(*create_srv_conf)(ngx_conf_t *cf); | |
149 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
150 void *conf); | |
151 } ngx_mail_module_t; | |
152 | |
153 | |
154 typedef enum { | |
155 ngx_pop3_start = 0, | |
156 ngx_pop3_user, | |
157 ngx_pop3_passwd, | |
158 ngx_pop3_auth_login_username, | |
159 ngx_pop3_auth_login_password, | |
160 ngx_pop3_auth_plain, | |
161 ngx_pop3_auth_cram_md5 | |
162 } ngx_po3_state_e; | |
163 | |
164 | |
165 typedef enum { | |
166 ngx_imap_start = 0, | |
398
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
167 ngx_imap_auth_login_username, |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
168 ngx_imap_auth_login_password, |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
169 ngx_imap_auth_plain, |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
170 ngx_imap_auth_cram_md5, |
290 | 171 ngx_imap_login, |
172 ngx_imap_user, | |
173 ngx_imap_passwd | |
174 } ngx_imap_state_e; | |
175 | |
176 | |
177 typedef enum { | |
178 ngx_smtp_start = 0, | |
179 ngx_smtp_auth_login_username, | |
180 ngx_smtp_auth_login_password, | |
181 ngx_smtp_auth_plain, | |
182 ngx_smtp_auth_cram_md5, | |
183 ngx_smtp_helo, | |
184 ngx_smtp_noxclient, | |
185 ngx_smtp_xclient | |
186 } ngx_smtp_state_e; | |
187 | |
188 | |
189 typedef struct { | |
190 ngx_peer_connection_t upstream; | |
191 ngx_buf_t *buffer; | |
192 } ngx_mail_proxy_ctx_t; | |
193 | |
194 | |
195 typedef struct { | |
196 uint32_t signature; /* "MAIL" */ | |
197 | |
198 ngx_connection_t *connection; | |
199 | |
200 ngx_str_t out; | |
201 ngx_buf_t *buffer; | |
202 | |
203 void **ctx; | |
204 void **main_conf; | |
205 void **srv_conf; | |
206 | |
207 ngx_mail_proxy_ctx_t *proxy; | |
208 | |
209 ngx_uint_t mail_state; | |
210 | |
211 unsigned blocked:1; | |
212 unsigned quit:1; | |
213 unsigned protocol:2; | |
214 unsigned quoted:1; | |
215 unsigned backslash:1; | |
216 unsigned no_sync_literal:1; | |
217 unsigned starttls:1; | |
218 unsigned esmtp:1; | |
219 unsigned auth_method:2; | |
220 unsigned auth_wait:1; | |
221 | |
222 ngx_str_t login; | |
223 ngx_str_t passwd; | |
224 | |
225 ngx_str_t salt; | |
226 ngx_str_t tag; | |
227 ngx_str_t tagged_line; | |
228 | |
229 ngx_str_t *addr_text; | |
230 ngx_str_t smtp_helo; | |
231 | |
232 ngx_uint_t command; | |
233 ngx_array_t args; | |
234 | |
235 ngx_uint_t login_attempt; | |
236 | |
237 /* used to parse IMAP/POP3/SMTP command */ | |
238 | |
239 ngx_uint_t state; | |
240 u_char *cmd_start; | |
241 u_char *arg_start; | |
242 u_char *arg_end; | |
243 ngx_uint_t literal_len; | |
244 } ngx_mail_session_t; | |
245 | |
246 | |
247 typedef struct { | |
248 ngx_str_t *client; | |
249 ngx_mail_session_t *session; | |
250 } ngx_mail_log_ctx_t; | |
251 | |
252 | |
398
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
253 #define NGX_POP3_USER 1 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
254 #define NGX_POP3_PASS 2 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
255 #define NGX_POP3_CAPA 3 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
256 #define NGX_POP3_QUIT 4 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
257 #define NGX_POP3_NOOP 5 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
258 #define NGX_POP3_STLS 6 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
259 #define NGX_POP3_APOP 7 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
260 #define NGX_POP3_AUTH 8 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
261 #define NGX_POP3_STAT 9 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
262 #define NGX_POP3_LIST 10 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
263 #define NGX_POP3_RETR 11 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
264 #define NGX_POP3_DELE 12 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
265 #define NGX_POP3_RSET 13 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
266 #define NGX_POP3_TOP 14 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
267 #define NGX_POP3_UIDL 15 |
290 | 268 |
269 | |
398
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
270 #define NGX_IMAP_LOGIN 1 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
271 #define NGX_IMAP_LOGOUT 2 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
272 #define NGX_IMAP_CAPABILITY 3 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
273 #define NGX_IMAP_NOOP 4 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
274 #define NGX_IMAP_STARTTLS 5 |
290 | 275 |
398
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
276 #define NGX_IMAP_NEXT 6 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
277 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
278 #define NGX_IMAP_AUTHENTICATE 7 |
290 | 279 |
280 | |
398
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
281 #define NGX_SMTP_HELO 1 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
282 #define NGX_SMTP_EHLO 2 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
283 #define NGX_SMTP_AUTH 3 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
284 #define NGX_SMTP_QUIT 4 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
285 #define NGX_SMTP_NOOP 5 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
286 #define NGX_SMTP_MAIL 6 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
287 #define NGX_SMTP_RSET 7 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
288 #define NGX_SMTP_RCPT 8 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
289 #define NGX_SMTP_DATA 9 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
290 #define NGX_SMTP_VRFY 10 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
291 #define NGX_SMTP_EXPN 11 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
292 #define NGX_SMTP_HELP 12 |
f9e6413396d4
Mail: IMAP AUTHENTICATE command support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
396
diff
changeset
|
293 #define NGX_SMTP_STARTTLS 13 |
290 | 294 |
295 | |
296 #define NGX_MAIL_AUTH_PLAIN 0 | |
297 #define NGX_MAIL_AUTH_LOGIN 1 | |
298 #define NGX_MAIL_AUTH_APOP 2 | |
299 #define NGX_MAIL_AUTH_CRAM_MD5 3 | |
300 | |
301 | |
302 #define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002 | |
303 #define NGX_MAIL_AUTH_LOGIN_ENABLED 0x0004 | |
304 #define NGX_MAIL_AUTH_APOP_ENABLED 0x0008 | |
305 #define NGX_MAIL_AUTH_CRAM_MD5_ENABLED 0x0010 | |
306 | |
307 | |
308 #define NGX_MAIL_PARSE_INVALID_COMMAND 20 | |
309 | |
310 | |
311 #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */ | |
312 | |
313 #define NGX_MAIL_MAIN_CONF 0x02000000 | |
314 #define NGX_MAIL_SRV_CONF 0x04000000 | |
315 | |
316 | |
317 #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf) | |
318 #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf) | |
319 | |
320 | |
321 #define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
322 #define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
323 #define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
324 | |
325 | |
326 #define ngx_mail_get_module_main_conf(s, module) \ | |
327 (s)->main_conf[module.ctx_index] | |
328 #define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index] | |
329 | |
330 #define ngx_mail_conf_get_module_main_conf(cf, module) \ | |
331 ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
394 | 332 #define ngx_mail_conf_get_module_srv_conf(cf, module) \ |
333 ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
290 | 334 |
335 | |
336 void ngx_mail_init_connection(ngx_connection_t *c); | |
337 void ngx_mail_send(ngx_event_t *wev); | |
338 void ngx_pop3_auth_state(ngx_event_t *rev); | |
339 void ngx_imap_auth_state(ngx_event_t *rev); | |
340 void ngx_smtp_auth_state(ngx_event_t *rev); | |
341 void ngx_mail_close_connection(ngx_connection_t *c); | |
342 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s); | |
343 | |
394 | 344 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s); |
345 | |
290 | 346 ngx_int_t ngx_pop3_parse_command(ngx_mail_session_t *s); |
347 ngx_int_t ngx_imap_parse_command(ngx_mail_session_t *s); | |
348 ngx_int_t ngx_smtp_parse_command(ngx_mail_session_t *s); | |
349 | |
394 | 350 #if (NGX_MAIL_SSL) |
351 void ngx_mail_starttls_handler(ngx_event_t *rev); | |
352 #endif | |
290 | 353 |
354 /* STUB */ | |
355 void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer); | |
356 void ngx_mail_auth_http_init(ngx_mail_session_t *s); | |
357 /**/ | |
358 | |
359 | |
360 extern ngx_uint_t ngx_mail_max_module; | |
361 extern ngx_module_t ngx_mail_core_module; | |
362 | |
363 | |
364 #endif /* _NGX_MAIL_H_INCLUDED_ */ |