Mercurial > hg > nginx-mail
annotate src/mail/ngx_mail.h @ 396:e2d916d7e50f PATCH_NGINX_MAIL_0_1
Mail: starttls only support for SMTP.
Capabilities tweaks according to starttls settings.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 18 Jul 2007 02:54:56 +0000 |
parents | a96157df5186 |
children | f9e6413396d4 |
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; | |
104 ngx_uint_t smtp_auth_methods; | |
105 | |
106 ngx_array_t pop3_capabilities; | |
107 ngx_array_t imap_capabilities; | |
108 ngx_array_t smtp_capabilities; | |
109 | |
394 | 110 /* |
111 * Handlers: | |
112 * | |
113 * - handler_init_session | |
114 * | |
115 * Init new session after client connects. Protocol greetings printed | |
116 * from here, so you need to define this if you need custom greeting | |
117 * (or pause before greeting printed). | |
118 * | |
119 * - handler_init_protocol | |
120 * | |
121 * Initialize protocol-specific data after client sent first command. | |
122 * Notably, this is re-called after STARTTLS negotiation. | |
123 * | |
124 * - handler_read | |
125 * | |
126 * Read client command. Could be the only handler used by simple | |
127 * modules. | |
128 * | |
129 * NB: handler_read is re-used after auth_http module work (if it was | |
130 * called throgh ngx_mail_auth_http_init()) in case of error returned | |
131 * by auth server, so you should set this if you use auth_http. | |
132 */ | |
133 | |
134 ngx_mail_handler_pt handler_init_session; | |
135 ngx_event_handler_pt handler_init_protocol; | |
136 ngx_event_handler_pt handler_read; | |
137 | |
290 | 138 /* server ctx */ |
139 ngx_mail_conf_ctx_t *ctx; | |
140 } ngx_mail_core_srv_conf_t; | |
141 | |
142 | |
143 typedef struct { | |
144 void *(*create_main_conf)(ngx_conf_t *cf); | |
145 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
146 | |
147 void *(*create_srv_conf)(ngx_conf_t *cf); | |
148 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
149 void *conf); | |
150 } ngx_mail_module_t; | |
151 | |
152 | |
153 typedef enum { | |
154 ngx_pop3_start = 0, | |
155 ngx_pop3_user, | |
156 ngx_pop3_passwd, | |
157 ngx_pop3_auth_login_username, | |
158 ngx_pop3_auth_login_password, | |
159 ngx_pop3_auth_plain, | |
160 ngx_pop3_auth_cram_md5 | |
161 } ngx_po3_state_e; | |
162 | |
163 | |
164 typedef enum { | |
165 ngx_imap_start = 0, | |
166 ngx_imap_login, | |
167 ngx_imap_user, | |
168 ngx_imap_passwd | |
169 } ngx_imap_state_e; | |
170 | |
171 | |
172 typedef enum { | |
173 ngx_smtp_start = 0, | |
174 ngx_smtp_auth_login_username, | |
175 ngx_smtp_auth_login_password, | |
176 ngx_smtp_auth_plain, | |
177 ngx_smtp_auth_cram_md5, | |
178 ngx_smtp_helo, | |
179 ngx_smtp_noxclient, | |
180 ngx_smtp_xclient | |
181 } ngx_smtp_state_e; | |
182 | |
183 | |
184 typedef struct { | |
185 ngx_peer_connection_t upstream; | |
186 ngx_buf_t *buffer; | |
187 } ngx_mail_proxy_ctx_t; | |
188 | |
189 | |
190 typedef struct { | |
191 uint32_t signature; /* "MAIL" */ | |
192 | |
193 ngx_connection_t *connection; | |
194 | |
195 ngx_str_t out; | |
196 ngx_buf_t *buffer; | |
197 | |
198 void **ctx; | |
199 void **main_conf; | |
200 void **srv_conf; | |
201 | |
202 ngx_mail_proxy_ctx_t *proxy; | |
203 | |
204 ngx_uint_t mail_state; | |
205 | |
206 unsigned blocked:1; | |
207 unsigned quit:1; | |
208 unsigned protocol:2; | |
209 unsigned quoted:1; | |
210 unsigned backslash:1; | |
211 unsigned no_sync_literal:1; | |
212 unsigned starttls:1; | |
213 unsigned esmtp:1; | |
214 unsigned auth_method:2; | |
215 unsigned auth_wait:1; | |
216 | |
217 ngx_str_t login; | |
218 ngx_str_t passwd; | |
219 | |
220 ngx_str_t salt; | |
221 ngx_str_t tag; | |
222 ngx_str_t tagged_line; | |
223 | |
224 ngx_str_t *addr_text; | |
225 ngx_str_t smtp_helo; | |
226 | |
227 ngx_uint_t command; | |
228 ngx_array_t args; | |
229 | |
230 ngx_uint_t login_attempt; | |
231 | |
232 /* used to parse IMAP/POP3/SMTP command */ | |
233 | |
234 ngx_uint_t state; | |
235 u_char *cmd_start; | |
236 u_char *arg_start; | |
237 u_char *arg_end; | |
238 ngx_uint_t literal_len; | |
239 } ngx_mail_session_t; | |
240 | |
241 | |
242 typedef struct { | |
243 ngx_str_t *client; | |
244 ngx_mail_session_t *session; | |
245 } ngx_mail_log_ctx_t; | |
246 | |
247 | |
248 #define NGX_POP3_USER 1 | |
249 #define NGX_POP3_PASS 2 | |
250 #define NGX_POP3_CAPA 3 | |
251 #define NGX_POP3_QUIT 4 | |
252 #define NGX_POP3_NOOP 5 | |
253 #define NGX_POP3_STLS 6 | |
254 #define NGX_POP3_APOP 7 | |
255 #define NGX_POP3_AUTH 8 | |
256 #define NGX_POP3_STAT 9 | |
257 #define NGX_POP3_LIST 10 | |
258 #define NGX_POP3_RETR 11 | |
259 #define NGX_POP3_DELE 12 | |
260 #define NGX_POP3_RSET 13 | |
261 #define NGX_POP3_TOP 14 | |
262 #define NGX_POP3_UIDL 15 | |
263 | |
264 | |
265 #define NGX_IMAP_LOGIN 1 | |
266 #define NGX_IMAP_LOGOUT 2 | |
267 #define NGX_IMAP_CAPABILITY 3 | |
268 #define NGX_IMAP_NOOP 4 | |
269 #define NGX_IMAP_STARTTLS 5 | |
270 | |
271 #define NGX_IMAP_NEXT 6 | |
272 | |
273 | |
274 #define NGX_SMTP_HELO 1 | |
275 #define NGX_SMTP_EHLO 2 | |
276 #define NGX_SMTP_AUTH 3 | |
277 #define NGX_SMTP_QUIT 4 | |
278 #define NGX_SMTP_NOOP 5 | |
279 #define NGX_SMTP_MAIL 6 | |
280 #define NGX_SMTP_RSET 7 | |
394 | 281 #define NGX_SMTP_RCPT 8 |
282 #define NGX_SMTP_DATA 9 | |
283 #define NGX_SMTP_VRFY 10 | |
284 #define NGX_SMTP_EXPN 11 | |
285 #define NGX_SMTP_HELP 12 | |
286 #define NGX_SMTP_STARTTLS 13 | |
290 | 287 |
288 | |
289 #define NGX_MAIL_AUTH_PLAIN 0 | |
290 #define NGX_MAIL_AUTH_LOGIN 1 | |
291 #define NGX_MAIL_AUTH_APOP 2 | |
292 #define NGX_MAIL_AUTH_CRAM_MD5 3 | |
293 | |
294 | |
295 #define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002 | |
296 #define NGX_MAIL_AUTH_LOGIN_ENABLED 0x0004 | |
297 #define NGX_MAIL_AUTH_APOP_ENABLED 0x0008 | |
298 #define NGX_MAIL_AUTH_CRAM_MD5_ENABLED 0x0010 | |
299 | |
300 | |
301 #define NGX_MAIL_PARSE_INVALID_COMMAND 20 | |
302 | |
303 | |
304 #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */ | |
305 | |
306 #define NGX_MAIL_MAIN_CONF 0x02000000 | |
307 #define NGX_MAIL_SRV_CONF 0x04000000 | |
308 | |
309 | |
310 #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf) | |
311 #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf) | |
312 | |
313 | |
314 #define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
315 #define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
316 #define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
317 | |
318 | |
319 #define ngx_mail_get_module_main_conf(s, module) \ | |
320 (s)->main_conf[module.ctx_index] | |
321 #define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index] | |
322 | |
323 #define ngx_mail_conf_get_module_main_conf(cf, module) \ | |
324 ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
394 | 325 #define ngx_mail_conf_get_module_srv_conf(cf, module) \ |
326 ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
290 | 327 |
328 | |
329 void ngx_mail_init_connection(ngx_connection_t *c); | |
330 void ngx_mail_send(ngx_event_t *wev); | |
331 void ngx_pop3_auth_state(ngx_event_t *rev); | |
332 void ngx_imap_auth_state(ngx_event_t *rev); | |
333 void ngx_smtp_auth_state(ngx_event_t *rev); | |
334 void ngx_mail_close_connection(ngx_connection_t *c); | |
335 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s); | |
336 | |
394 | 337 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s); |
338 | |
290 | 339 ngx_int_t ngx_pop3_parse_command(ngx_mail_session_t *s); |
340 ngx_int_t ngx_imap_parse_command(ngx_mail_session_t *s); | |
341 ngx_int_t ngx_smtp_parse_command(ngx_mail_session_t *s); | |
342 | |
394 | 343 #if (NGX_MAIL_SSL) |
344 void ngx_mail_starttls_handler(ngx_event_t *rev); | |
345 #endif | |
290 | 346 |
347 /* STUB */ | |
348 void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer); | |
349 void ngx_mail_auth_http_init(ngx_mail_session_t *s); | |
350 /**/ | |
351 | |
352 | |
353 extern ngx_uint_t ngx_mail_max_module; | |
354 extern ngx_module_t ngx_mail_core_module; | |
355 | |
356 | |
357 #endif /* _NGX_MAIL_H_INCLUDED_ */ |