Mercurial > hg > nginx
comparison src/mail/ngx_mail.h @ 1487:f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 15 Sep 2007 16:51:16 +0000 |
parents | 4606dce4f416 |
children | cd042416586c |
comparison
equal
deleted
inserted
replaced
1486:0e7074ef7303 | 1487:f69493e8faab |
---|---|
71 | 71 |
72 #define NGX_MAIL_POP3_PROTOCOL 0 | 72 #define NGX_MAIL_POP3_PROTOCOL 0 |
73 #define NGX_MAIL_IMAP_PROTOCOL 1 | 73 #define NGX_MAIL_IMAP_PROTOCOL 1 |
74 #define NGX_MAIL_SMTP_PROTOCOL 2 | 74 #define NGX_MAIL_SMTP_PROTOCOL 2 |
75 | 75 |
76 typedef struct { | 76 |
77 typedef struct ngx_mail_protocol_s ngx_mail_protocol_t; | |
78 | |
79 | |
80 typedef struct { | |
81 ngx_mail_protocol_t *protocol; | |
82 | |
77 ngx_msec_t timeout; | 83 ngx_msec_t timeout; |
78 ngx_msec_t smtp_greeting_delay; | |
79 | |
80 size_t imap_client_buffer_size; | |
81 size_t smtp_client_buffer_size; | |
82 | |
83 ngx_uint_t protocol; | |
84 | 84 |
85 ngx_flag_t so_keepalive; | 85 ngx_flag_t so_keepalive; |
86 | 86 |
87 ngx_str_t pop3_capability; | |
88 ngx_str_t pop3_starttls_capability; | |
89 ngx_str_t pop3_starttls_only_capability; | |
90 ngx_str_t pop3_auth_capability; | |
91 | |
92 ngx_str_t imap_capability; | |
93 ngx_str_t imap_starttls_capability; | |
94 ngx_str_t imap_starttls_only_capability; | |
95 | |
96 ngx_str_t smtp_capability; | |
97 ngx_str_t smtp_starttls_capability; | |
98 ngx_str_t smtp_starttls_only_capability; | |
99 | |
100 ngx_str_t server_name; | 87 ngx_str_t server_name; |
101 ngx_str_t smtp_server_name; | 88 |
102 ngx_str_t smtp_greeting; | 89 u_char *file_name; |
103 | 90 ngx_int_t line; |
104 ngx_uint_t pop3_auth_methods; | |
105 ngx_uint_t imap_auth_methods; | |
106 ngx_uint_t smtp_auth_methods; | |
107 | |
108 ngx_array_t pop3_capabilities; | |
109 ngx_array_t imap_capabilities; | |
110 ngx_array_t smtp_capabilities; | |
111 | 91 |
112 /* server ctx */ | 92 /* server ctx */ |
113 ngx_mail_conf_ctx_t *ctx; | 93 ngx_mail_conf_ctx_t *ctx; |
114 } ngx_mail_core_srv_conf_t; | 94 } ngx_mail_core_srv_conf_t; |
115 | |
116 | |
117 typedef struct { | |
118 void *(*create_main_conf)(ngx_conf_t *cf); | |
119 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
120 | |
121 void *(*create_srv_conf)(ngx_conf_t *cf); | |
122 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
123 void *conf); | |
124 } ngx_mail_module_t; | |
125 | 95 |
126 | 96 |
127 typedef enum { | 97 typedef enum { |
128 ngx_pop3_start = 0, | 98 ngx_pop3_start = 0, |
129 ngx_pop3_user, | 99 ngx_pop3_user, |
179 | 149 |
180 ngx_mail_proxy_ctx_t *proxy; | 150 ngx_mail_proxy_ctx_t *proxy; |
181 | 151 |
182 ngx_uint_t mail_state; | 152 ngx_uint_t mail_state; |
183 | 153 |
154 unsigned protocol:3; | |
184 unsigned blocked:1; | 155 unsigned blocked:1; |
185 unsigned quit:1; | 156 unsigned quit:1; |
186 unsigned protocol:2; | |
187 unsigned quoted:1; | 157 unsigned quoted:1; |
188 unsigned backslash:1; | 158 unsigned backslash:1; |
189 unsigned no_sync_literal:1; | 159 unsigned no_sync_literal:1; |
190 unsigned starttls:1; | 160 unsigned starttls:1; |
191 unsigned esmtp:1; | 161 unsigned esmtp:1; |
206 ngx_uint_t command; | 176 ngx_uint_t command; |
207 ngx_array_t args; | 177 ngx_array_t args; |
208 | 178 |
209 ngx_uint_t login_attempt; | 179 ngx_uint_t login_attempt; |
210 | 180 |
211 /* used to parse IMAP/POP3/SMTP command */ | 181 /* used to parse POP3/IMAP/SMTP command */ |
212 | 182 |
213 ngx_uint_t state; | 183 ngx_uint_t state; |
214 u_char *cmd_start; | 184 u_char *cmd_start; |
215 u_char *arg_start; | 185 u_char *arg_start; |
216 u_char *arg_end; | 186 u_char *arg_end; |
280 | 250 |
281 | 251 |
282 #define NGX_MAIL_PARSE_INVALID_COMMAND 20 | 252 #define NGX_MAIL_PARSE_INVALID_COMMAND 20 |
283 | 253 |
284 | 254 |
285 #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */ | |
286 | |
287 #define NGX_MAIL_MAIN_CONF 0x02000000 | |
288 #define NGX_MAIL_SRV_CONF 0x04000000 | |
289 | |
290 | |
291 #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf) | |
292 #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf) | |
293 | |
294 | |
295 #define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
296 #define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
297 #define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
298 | |
299 | |
300 #define ngx_mail_get_module_main_conf(s, module) \ | |
301 (s)->main_conf[module.ctx_index] | |
302 #define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index] | |
303 | |
304 #define ngx_mail_conf_get_module_main_conf(cf, module) \ | |
305 ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
306 #define ngx_mail_conf_get_module_srv_conf(cf, module) \ | |
307 ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
308 | |
309 typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s, | 255 typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s, |
310 ngx_connection_t *c); | 256 ngx_connection_t *c); |
311 typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev); | 257 typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev); |
312 typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev); | 258 typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev); |
313 typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s); | 259 typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s); |
314 | 260 |
315 | 261 |
262 struct ngx_mail_protocol_s { | |
263 ngx_str_t name; | |
264 in_port_t port[4]; | |
265 ngx_uint_t type; | |
266 | |
267 ngx_mail_init_session_pt init_session; | |
268 ngx_mail_init_protocol_pt init_protocol; | |
269 ngx_mail_parse_command_pt parse_command; | |
270 ngx_mail_auth_state_pt auth_state; | |
271 | |
272 ngx_str_t internal_server_error; | |
273 }; | |
274 | |
275 | |
276 typedef struct { | |
277 ngx_mail_protocol_t *protocol; | |
278 | |
279 void *(*create_main_conf)(ngx_conf_t *cf); | |
280 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
281 | |
282 void *(*create_srv_conf)(ngx_conf_t *cf); | |
283 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
284 void *conf); | |
285 } ngx_mail_module_t; | |
286 | |
287 | |
288 #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */ | |
289 | |
290 #define NGX_MAIL_MAIN_CONF 0x02000000 | |
291 #define NGX_MAIL_SRV_CONF 0x04000000 | |
292 | |
293 | |
294 #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf) | |
295 #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf) | |
296 | |
297 | |
298 #define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
299 #define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
300 #define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
301 | |
302 | |
303 #define ngx_mail_get_module_main_conf(s, module) \ | |
304 (s)->main_conf[module.ctx_index] | |
305 #define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index] | |
306 | |
307 #define ngx_mail_conf_get_module_main_conf(cf, module) \ | |
308 ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
309 #define ngx_mail_conf_get_module_srv_conf(cf, module) \ | |
310 ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
311 | |
312 | |
316 #if (NGX_MAIL_SSL) | 313 #if (NGX_MAIL_SSL) |
317 void ngx_mail_starttls_handler(ngx_event_t *rev); | 314 void ngx_mail_starttls_handler(ngx_event_t *rev); |
318 ngx_int_t ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c); | 315 ngx_int_t ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c); |
319 #endif | 316 #endif |
320 | 317 |
321 | 318 |
322 void ngx_mail_init_connection(ngx_connection_t *c); | 319 void ngx_mail_init_connection(ngx_connection_t *c); |
323 | |
324 void ngx_mail_pop3_auth_state(ngx_event_t *rev); | |
325 void ngx_mail_imap_auth_state(ngx_event_t *rev); | |
326 void ngx_mail_smtp_auth_state(ngx_event_t *rev); | |
327 | 320 |
328 ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c, | 321 ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c, |
329 ngx_mail_core_srv_conf_t *cscf); | 322 ngx_mail_core_srv_conf_t *cscf); |
330 ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, | 323 ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, |
331 ngx_uint_t n); | 324 ngx_uint_t n); |
334 ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s, | 327 ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s, |
335 ngx_connection_t *c); | 328 ngx_connection_t *c); |
336 ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, | 329 ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, |
337 ngx_connection_t *c, char *prefix, size_t len); | 330 ngx_connection_t *c, char *prefix, size_t len); |
338 ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c); | 331 ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c); |
332 ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c); | |
339 | 333 |
340 void ngx_mail_send(ngx_event_t *wev); | 334 void ngx_mail_send(ngx_event_t *wev); |
341 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c); | 335 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c); |
342 void ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c); | 336 void ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c); |
343 void ngx_mail_close_connection(ngx_connection_t *c); | 337 void ngx_mail_close_connection(ngx_connection_t *c); |
344 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s); | 338 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s); |
345 u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len); | 339 u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len); |
346 | 340 |
347 | 341 |
348 void ngx_mail_pop3_init_session(ngx_mail_session_t *s, ngx_connection_t *c); | 342 char *ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
349 void ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c); | |
350 void ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c); | |
351 | |
352 void ngx_mail_pop3_init_protocol(ngx_event_t *rev); | |
353 void ngx_mail_imap_init_protocol(ngx_event_t *rev); | |
354 void ngx_mail_smtp_init_protocol(ngx_event_t *rev); | |
355 | |
356 ngx_int_t ngx_mail_pop3_parse_command(ngx_mail_session_t *s); | |
357 ngx_int_t ngx_mail_imap_parse_command(ngx_mail_session_t *s); | |
358 ngx_int_t ngx_mail_smtp_parse_command(ngx_mail_session_t *s); | |
359 ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c); | |
360 | 343 |
361 | 344 |
362 /* STUB */ | 345 /* STUB */ |
363 void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer); | 346 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); | 347 void ngx_mail_auth_http_init(ngx_mail_session_t *s); |