Mercurial > hg > nginx-mail
annotate src/mail/ngx_mail.h @ 410:cd9cb7a3ff9e
Merge with nginx 0.7.8.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 11 Aug 2008 22:07:06 +0400 |
parents | 52b28d322d76 babd3d9efb62 |
children | 9205084bd1f3 |
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 | |
71 | |
72 #define NGX_MAIL_POP3_PROTOCOL 0 | |
73 #define NGX_MAIL_IMAP_PROTOCOL 1 | |
74 #define NGX_MAIL_SMTP_PROTOCOL 2 | |
75 | |
336 | 76 |
77 typedef struct ngx_mail_protocol_s ngx_mail_protocol_t; | |
78 | |
290 | 79 |
336 | 80 typedef struct { |
81 ngx_mail_protocol_t *protocol; | |
290 | 82 |
336 | 83 ngx_msec_t timeout; |
366 | 84 ngx_msec_t resolver_timeout; |
290 | 85 |
86 ngx_flag_t so_keepalive; | |
87 | |
336 | 88 ngx_str_t server_name; |
290 | 89 |
336 | 90 u_char *file_name; |
91 ngx_int_t line; | |
290 | 92 |
366 | 93 ngx_resolver_t *resolver; |
94 | |
290 | 95 /* server ctx */ |
96 ngx_mail_conf_ctx_t *ctx; | |
97 } ngx_mail_core_srv_conf_t; | |
98 | |
99 | |
100 typedef enum { | |
101 ngx_pop3_start = 0, | |
102 ngx_pop3_user, | |
103 ngx_pop3_passwd, | |
104 ngx_pop3_auth_login_username, | |
105 ngx_pop3_auth_login_password, | |
106 ngx_pop3_auth_plain, | |
107 ngx_pop3_auth_cram_md5 | |
354 | 108 } ngx_pop3_state_e; |
290 | 109 |
110 | |
111 typedef enum { | |
112 ngx_imap_start = 0, | |
322 | 113 ngx_imap_auth_login_username, |
114 ngx_imap_auth_login_password, | |
115 ngx_imap_auth_plain, | |
116 ngx_imap_auth_cram_md5, | |
290 | 117 ngx_imap_login, |
118 ngx_imap_user, | |
119 ngx_imap_passwd | |
120 } ngx_imap_state_e; | |
121 | |
122 | |
123 typedef enum { | |
124 ngx_smtp_start = 0, | |
125 ngx_smtp_auth_login_username, | |
126 ngx_smtp_auth_login_password, | |
127 ngx_smtp_auth_plain, | |
128 ngx_smtp_auth_cram_md5, | |
129 ngx_smtp_helo, | |
404
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
130 ngx_smtp_helo_xclient, |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
131 ngx_smtp_helo_from, |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
132 ngx_smtp_xclient, |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
133 ngx_smtp_xclient_from, |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
134 ngx_smtp_from, |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
135 ngx_smtp_to |
290 | 136 } ngx_smtp_state_e; |
137 | |
138 | |
139 typedef struct { | |
140 ngx_peer_connection_t upstream; | |
141 ngx_buf_t *buffer; | |
142 } ngx_mail_proxy_ctx_t; | |
143 | |
144 | |
145 typedef struct { | |
146 uint32_t signature; /* "MAIL" */ | |
147 | |
148 ngx_connection_t *connection; | |
149 | |
150 ngx_str_t out; | |
151 ngx_buf_t *buffer; | |
152 | |
153 void **ctx; | |
154 void **main_conf; | |
155 void **srv_conf; | |
156 | |
366 | 157 ngx_resolver_ctx_t *resolver_ctx; |
158 | |
290 | 159 ngx_mail_proxy_ctx_t *proxy; |
160 | |
161 ngx_uint_t mail_state; | |
162 | |
336 | 163 unsigned protocol:3; |
290 | 164 unsigned blocked:1; |
165 unsigned quit:1; | |
166 unsigned quoted:1; | |
167 unsigned backslash:1; | |
168 unsigned no_sync_literal:1; | |
169 unsigned starttls:1; | |
170 unsigned esmtp:1; | |
404
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
171 unsigned auth_method:3; |
290 | 172 unsigned auth_wait:1; |
173 | |
174 ngx_str_t login; | |
175 ngx_str_t passwd; | |
176 | |
177 ngx_str_t salt; | |
178 ngx_str_t tag; | |
179 ngx_str_t tagged_line; | |
336 | 180 ngx_str_t text; |
290 | 181 |
182 ngx_str_t *addr_text; | |
366 | 183 ngx_str_t host; |
290 | 184 ngx_str_t smtp_helo; |
404
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
185 ngx_str_t smtp_from; |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
186 ngx_str_t smtp_to; |
290 | 187 |
188 ngx_uint_t command; | |
189 ngx_array_t args; | |
190 | |
191 ngx_uint_t login_attempt; | |
192 | |
336 | 193 /* used to parse POP3/IMAP/SMTP command */ |
290 | 194 |
195 ngx_uint_t state; | |
196 u_char *cmd_start; | |
197 u_char *arg_start; | |
198 u_char *arg_end; | |
199 ngx_uint_t literal_len; | |
200 } ngx_mail_session_t; | |
201 | |
202 | |
203 typedef struct { | |
204 ngx_str_t *client; | |
205 ngx_mail_session_t *session; | |
206 } ngx_mail_log_ctx_t; | |
207 | |
208 | |
322 | 209 #define NGX_POP3_USER 1 |
210 #define NGX_POP3_PASS 2 | |
211 #define NGX_POP3_CAPA 3 | |
212 #define NGX_POP3_QUIT 4 | |
213 #define NGX_POP3_NOOP 5 | |
214 #define NGX_POP3_STLS 6 | |
215 #define NGX_POP3_APOP 7 | |
216 #define NGX_POP3_AUTH 8 | |
217 #define NGX_POP3_STAT 9 | |
218 #define NGX_POP3_LIST 10 | |
219 #define NGX_POP3_RETR 11 | |
220 #define NGX_POP3_DELE 12 | |
221 #define NGX_POP3_RSET 13 | |
222 #define NGX_POP3_TOP 14 | |
223 #define NGX_POP3_UIDL 15 | |
290 | 224 |
225 | |
322 | 226 #define NGX_IMAP_LOGIN 1 |
227 #define NGX_IMAP_LOGOUT 2 | |
228 #define NGX_IMAP_CAPABILITY 3 | |
229 #define NGX_IMAP_NOOP 4 | |
230 #define NGX_IMAP_STARTTLS 5 | |
290 | 231 |
322 | 232 #define NGX_IMAP_NEXT 6 |
233 | |
234 #define NGX_IMAP_AUTHENTICATE 7 | |
290 | 235 |
236 | |
322 | 237 #define NGX_SMTP_HELO 1 |
238 #define NGX_SMTP_EHLO 2 | |
239 #define NGX_SMTP_AUTH 3 | |
240 #define NGX_SMTP_QUIT 4 | |
241 #define NGX_SMTP_NOOP 5 | |
242 #define NGX_SMTP_MAIL 6 | |
243 #define NGX_SMTP_RSET 7 | |
244 #define NGX_SMTP_RCPT 8 | |
245 #define NGX_SMTP_DATA 9 | |
246 #define NGX_SMTP_VRFY 10 | |
247 #define NGX_SMTP_EXPN 11 | |
248 #define NGX_SMTP_HELP 12 | |
249 #define NGX_SMTP_STARTTLS 13 | |
290 | 250 |
251 | |
252 #define NGX_MAIL_AUTH_PLAIN 0 | |
253 #define NGX_MAIL_AUTH_LOGIN 1 | |
254 #define NGX_MAIL_AUTH_APOP 2 | |
255 #define NGX_MAIL_AUTH_CRAM_MD5 3 | |
404
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
256 #define NGX_MAIL_AUTH_NONE 4 |
290 | 257 |
258 | |
259 #define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002 | |
260 #define NGX_MAIL_AUTH_LOGIN_ENABLED 0x0004 | |
261 #define NGX_MAIL_AUTH_APOP_ENABLED 0x0008 | |
262 #define NGX_MAIL_AUTH_CRAM_MD5_ENABLED 0x0010 | |
404
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
263 #define NGX_MAIL_AUTH_NONE_ENABLED 0x0020 |
290 | 264 |
265 | |
266 #define NGX_MAIL_PARSE_INVALID_COMMAND 20 | |
267 | |
268 | |
336 | 269 typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s, |
270 ngx_connection_t *c); | |
271 typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev); | |
272 typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev); | |
273 typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s); | |
274 | |
275 | |
276 struct ngx_mail_protocol_s { | |
277 ngx_str_t name; | |
278 in_port_t port[4]; | |
279 ngx_uint_t type; | |
280 | |
281 ngx_mail_init_session_pt init_session; | |
282 ngx_mail_init_protocol_pt init_protocol; | |
283 ngx_mail_parse_command_pt parse_command; | |
284 ngx_mail_auth_state_pt auth_state; | |
290 | 285 |
336 | 286 ngx_str_t internal_server_error; |
287 }; | |
288 | |
289 | |
290 typedef struct { | |
291 ngx_mail_protocol_t *protocol; | |
292 | |
293 void *(*create_main_conf)(ngx_conf_t *cf); | |
294 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
295 | |
296 void *(*create_srv_conf)(ngx_conf_t *cf); | |
297 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
298 void *conf); | |
299 } ngx_mail_module_t; | |
300 | |
301 | |
302 #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */ | |
303 | |
304 #define NGX_MAIL_MAIN_CONF 0x02000000 | |
305 #define NGX_MAIL_SRV_CONF 0x04000000 | |
290 | 306 |
307 | |
308 #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf) | |
309 #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf) | |
310 | |
311 | |
312 #define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
313 #define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
314 #define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
315 | |
316 | |
317 #define ngx_mail_get_module_main_conf(s, module) \ | |
318 (s)->main_conf[module.ctx_index] | |
319 #define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index] | |
320 | |
321 #define ngx_mail_conf_get_module_main_conf(cf, module) \ | |
322 ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
322 | 323 #define ngx_mail_conf_get_module_srv_conf(cf, module) \ |
324 ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
290 | 325 |
326 | |
336 | 327 #if (NGX_MAIL_SSL) |
328 void ngx_mail_starttls_handler(ngx_event_t *rev); | |
329 ngx_int_t ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c); | |
330 #endif | |
331 | |
332 | |
290 | 333 void ngx_mail_init_connection(ngx_connection_t *c); |
336 | 334 |
335 ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c, | |
336 ngx_mail_core_srv_conf_t *cscf); | |
337 ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, | |
338 ngx_uint_t n); | |
339 ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s, | |
340 ngx_connection_t *c); | |
341 ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s, | |
342 ngx_connection_t *c); | |
343 ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, | |
344 ngx_connection_t *c, char *prefix, size_t len); | |
345 ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c); | |
346 ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c); | |
347 | |
290 | 348 void ngx_mail_send(ngx_event_t *wev); |
336 | 349 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c); |
350 void ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c); | |
290 | 351 void ngx_mail_close_connection(ngx_connection_t *c); |
352 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s); | |
336 | 353 u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len); |
290 | 354 |
336 | 355 |
356 char *ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
290 | 357 |
404
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
358 #if (NGX_MAIL_SSL) |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
359 void ngx_mail_starttls_handler(ngx_event_t *rev); |
481e8f936572
Mail: rename "unauth" to "none".
Maxim Dounin <mdounin@mdounin.ru>
parents:
403
diff
changeset
|
360 #endif |
290 | 361 |
362 /* STUB */ | |
363 void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer); | |
364 void ngx_mail_auth_http_init(ngx_mail_session_t *s); | |
365 /**/ | |
366 | |
367 | |
368 extern ngx_uint_t ngx_mail_max_module; | |
369 extern ngx_module_t ngx_mail_core_module; | |
370 | |
371 | |
372 #endif /* _NGX_MAIL_H_INCLUDED_ */ |