comparison src/mail/ngx_mail.h @ 409:52b28d322d76

Merge with nginx 0.6.12.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 11 Aug 2008 21:22:47 +0400
parents 481e8f936572 1c519aff5c0c
children cd9cb7a3ff9e
comparison
equal deleted inserted replaced
408:4243eecbd594 409:52b28d322d76
66 typedef struct { 66 typedef struct {
67 ngx_array_t servers; /* ngx_mail_core_srv_conf_t */ 67 ngx_array_t servers; /* ngx_mail_core_srv_conf_t */
68 ngx_array_t listen; /* ngx_mail_listen_t */ 68 ngx_array_t listen; /* ngx_mail_listen_t */
69 } ngx_mail_core_main_conf_t; 69 } ngx_mail_core_main_conf_t;
70 70
71 typedef void (*ngx_mail_handler_pt)(ngx_connection_t *c);
72 71
73 #define NGX_MAIL_POP3_PROTOCOL 0 72 #define NGX_MAIL_POP3_PROTOCOL 0
74 #define NGX_MAIL_IMAP_PROTOCOL 1 73 #define NGX_MAIL_IMAP_PROTOCOL 1
75 #define NGX_MAIL_SMTP_PROTOCOL 2 74 #define NGX_MAIL_SMTP_PROTOCOL 2
76 75
77 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
78 ngx_msec_t timeout; 83 ngx_msec_t timeout;
79 84
80 size_t imap_client_buffer_size;
81
82 ngx_uint_t protocol;
83
84 ngx_flag_t so_keepalive; 85 ngx_flag_t so_keepalive;
85 86
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;
96 ngx_str_t smtp_starttls_capability;
97 ngx_str_t smtp_starttls_only_capability;
98
99 ngx_str_t server_name; 87 ngx_str_t server_name;
100 ngx_str_t smtp_server_name; 88
101 ngx_str_t smtp_greeting; 89 u_char *file_name;
102 90 ngx_int_t line;
103 ngx_uint_t pop3_auth_methods;
104 ngx_uint_t imap_auth_methods;
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
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 91
139 /* server ctx */ 92 /* server ctx */
140 ngx_mail_conf_ctx_t *ctx; 93 ngx_mail_conf_ctx_t *ctx;
141 } ngx_mail_core_srv_conf_t; 94 } 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 95
153 96
154 typedef enum { 97 typedef enum {
155 ngx_pop3_start = 0, 98 ngx_pop3_start = 0,
156 ngx_pop3_user, 99 ngx_pop3_user,
210 153
211 ngx_mail_proxy_ctx_t *proxy; 154 ngx_mail_proxy_ctx_t *proxy;
212 155
213 ngx_uint_t mail_state; 156 ngx_uint_t mail_state;
214 157
158 unsigned protocol:3;
215 unsigned blocked:1; 159 unsigned blocked:1;
216 unsigned quit:1; 160 unsigned quit:1;
217 unsigned protocol:2;
218 unsigned quoted:1; 161 unsigned quoted:1;
219 unsigned backslash:1; 162 unsigned backslash:1;
220 unsigned no_sync_literal:1; 163 unsigned no_sync_literal:1;
221 unsigned starttls:1; 164 unsigned starttls:1;
222 unsigned esmtp:1; 165 unsigned esmtp:1;
227 ngx_str_t passwd; 170 ngx_str_t passwd;
228 171
229 ngx_str_t salt; 172 ngx_str_t salt;
230 ngx_str_t tag; 173 ngx_str_t tag;
231 ngx_str_t tagged_line; 174 ngx_str_t tagged_line;
175 ngx_str_t text;
232 176
233 ngx_str_t *addr_text; 177 ngx_str_t *addr_text;
234 ngx_str_t smtp_helo; 178 ngx_str_t smtp_helo;
235 ngx_str_t smtp_from; 179 ngx_str_t smtp_from;
236 ngx_str_t smtp_to; 180 ngx_str_t smtp_to;
238 ngx_uint_t command; 182 ngx_uint_t command;
239 ngx_array_t args; 183 ngx_array_t args;
240 184
241 ngx_uint_t login_attempt; 185 ngx_uint_t login_attempt;
242 186
243 /* used to parse IMAP/POP3/SMTP command */ 187 /* used to parse POP3/IMAP/SMTP command */
244 188
245 ngx_uint_t state; 189 ngx_uint_t state;
246 u_char *cmd_start; 190 u_char *cmd_start;
247 u_char *arg_start; 191 u_char *arg_start;
248 u_char *arg_end; 192 u_char *arg_end;
314 258
315 259
316 #define NGX_MAIL_PARSE_INVALID_COMMAND 20 260 #define NGX_MAIL_PARSE_INVALID_COMMAND 20
317 261
318 262
319 #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */ 263 typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
320 264 ngx_connection_t *c);
321 #define NGX_MAIL_MAIN_CONF 0x02000000 265 typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
322 #define NGX_MAIL_SRV_CONF 0x04000000 266 typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
267 typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);
268
269
270 struct ngx_mail_protocol_s {
271 ngx_str_t name;
272 in_port_t port[4];
273 ngx_uint_t type;
274
275 ngx_mail_init_session_pt init_session;
276 ngx_mail_init_protocol_pt init_protocol;
277 ngx_mail_parse_command_pt parse_command;
278 ngx_mail_auth_state_pt auth_state;
279
280 ngx_str_t internal_server_error;
281 };
282
283
284 typedef struct {
285 ngx_mail_protocol_t *protocol;
286
287 void *(*create_main_conf)(ngx_conf_t *cf);
288 char *(*init_main_conf)(ngx_conf_t *cf, void *conf);
289
290 void *(*create_srv_conf)(ngx_conf_t *cf);
291 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
292 void *conf);
293 } ngx_mail_module_t;
294
295
296 #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */
297
298 #define NGX_MAIL_MAIN_CONF 0x02000000
299 #define NGX_MAIL_SRV_CONF 0x04000000
323 300
324 301
325 #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf) 302 #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf)
326 #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf) 303 #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf)
327 304
339 ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] 316 ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
340 #define ngx_mail_conf_get_module_srv_conf(cf, module) \ 317 #define ngx_mail_conf_get_module_srv_conf(cf, module) \
341 ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] 318 ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
342 319
343 320
321 #if (NGX_MAIL_SSL)
322 void ngx_mail_starttls_handler(ngx_event_t *rev);
323 ngx_int_t ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c);
324 #endif
325
326
344 void ngx_mail_init_connection(ngx_connection_t *c); 327 void ngx_mail_init_connection(ngx_connection_t *c);
328
329 ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
330 ngx_mail_core_srv_conf_t *cscf);
331 ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
332 ngx_uint_t n);
333 ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s,
334 ngx_connection_t *c);
335 ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s,
336 ngx_connection_t *c);
337 ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,
338 ngx_connection_t *c, char *prefix, size_t len);
339 ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c);
340 ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c);
341
345 void ngx_mail_send(ngx_event_t *wev); 342 void ngx_mail_send(ngx_event_t *wev);
346 void ngx_pop3_auth_state(ngx_event_t *rev); 343 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c);
347 void ngx_imap_auth_state(ngx_event_t *rev); 344 void ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c);
348 void ngx_smtp_auth_state(ngx_event_t *rev);
349 void ngx_mail_close_connection(ngx_connection_t *c); 345 void ngx_mail_close_connection(ngx_connection_t *c);
350 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s); 346 void ngx_mail_session_internal_server_error(ngx_mail_session_t *s);
351 347 u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len);
352 ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s); 348
353 349
354 ngx_int_t ngx_pop3_parse_command(ngx_mail_session_t *s); 350 char *ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
355 ngx_int_t ngx_imap_parse_command(ngx_mail_session_t *s);
356 ngx_int_t ngx_smtp_parse_command(ngx_mail_session_t *s);
357 351
358 #if (NGX_MAIL_SSL) 352 #if (NGX_MAIL_SSL)
359 void ngx_mail_starttls_handler(ngx_event_t *rev); 353 void ngx_mail_starttls_handler(ngx_event_t *rev);
360 #endif 354 #endif
361 355