comparison src/mail/ngx_mail_handler.c @ 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 93ff27726d2e
comparison
equal deleted inserted replaced
1486:0e7074ef7303 1487:f69493e8faab
14 14
15 #if (NGX_MAIL_SSL) 15 #if (NGX_MAIL_SSL)
16 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); 16 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c);
17 static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c); 17 static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c);
18 #endif 18 #endif
19
20
21 static ngx_mail_init_session_pt ngx_mail_init_sessions[] = {
22 ngx_mail_pop3_init_session,
23 ngx_mail_imap_init_session,
24 ngx_mail_smtp_init_session
25 };
26
27
28 static ngx_mail_init_protocol_pt ngx_mail_init_protocols[] = {
29 ngx_mail_pop3_init_protocol,
30 ngx_mail_imap_init_protocol,
31 ngx_mail_smtp_init_protocol
32 };
33
34
35 static ngx_mail_parse_command_pt ngx_mail_parse_commands[] = {
36 ngx_mail_pop3_parse_command,
37 ngx_mail_imap_parse_command,
38 ngx_mail_smtp_parse_command
39 };
40
41
42 static ngx_str_t internal_server_errors[] = {
43 ngx_string("-ERR internal server error" CRLF),
44 ngx_string("* BAD internal server error" CRLF),
45 ngx_string("451 4.3.2 Internal server error" CRLF),
46 };
47 19
48 20
49 void 21 void
50 ngx_mail_init_connection(ngx_connection_t *c) 22 ngx_mail_init_connection(ngx_connection_t *c)
51 { 23 {
208 180
209 181
210 static void 182 static void
211 ngx_mail_ssl_handshake_handler(ngx_connection_t *c) 183 ngx_mail_ssl_handshake_handler(ngx_connection_t *c)
212 { 184 {
213 ngx_mail_session_t *s; 185 ngx_mail_session_t *s;
186 ngx_mail_core_srv_conf_t *cscf;
214 187
215 if (c->ssl->handshaked) { 188 if (c->ssl->handshaked) {
216 189
217 s = c->data; 190 s = c->data;
218 191
219 if (s->starttls) { 192 if (s->starttls) {
220 c->read->handler = ngx_mail_init_protocols[s->protocol]; 193 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
194
195 c->read->handler = cscf->protocol->init_protocol;
221 c->write->handler = ngx_mail_send; 196 c->write->handler = ngx_mail_send;
222 197
223 ngx_mail_init_protocols[s->protocol](c->read); 198 cscf->protocol->init_protocol(c->read);
224 199
225 return; 200 return;
226 } 201 }
227 202
228 ngx_mail_init_session(c); 203 ngx_mail_init_session(c);
243 218
244 s = c->data; 219 s = c->data;
245 220
246 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); 221 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
247 222
248 s->protocol = cscf->protocol; 223 s->protocol = cscf->protocol->type;
249 224
250 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module); 225 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module);
251 if (s->ctx == NULL) { 226 if (s->ctx == NULL) {
252 ngx_mail_session_internal_server_error(s); 227 ngx_mail_session_internal_server_error(s);
253 return; 228 return;
254 } 229 }
255 230
256 c->write->handler = ngx_mail_send; 231 c->write->handler = ngx_mail_send;
257 232
258 ngx_mail_init_sessions[s->protocol](s, c); 233 cscf->protocol->init_session(s, c);
259 } 234 }
260 235
261 236
262 ngx_int_t 237 ngx_int_t
263 ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c, 238 ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
565 540
566 541
567 ngx_int_t 542 ngx_int_t
568 ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c) 543 ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c)
569 { 544 {
570 ssize_t n; 545 ssize_t n;
571 ngx_int_t rc; 546 ngx_int_t rc;
572 ngx_str_t l; 547 ngx_str_t l;
548 ngx_mail_core_srv_conf_t *cscf;
573 549
574 n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last); 550 n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last);
575 551
576 if (n == NGX_ERROR || n == 0) { 552 if (n == NGX_ERROR || n == 0) {
577 ngx_mail_close_connection(c); 553 ngx_mail_close_connection(c);
589 } 565 }
590 566
591 return NGX_AGAIN; 567 return NGX_AGAIN;
592 } 568 }
593 569
594 rc = ngx_mail_parse_commands[s->protocol](s); 570 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
571
572 rc = cscf->protocol->parse_command(s);
595 573
596 if (rc == NGX_AGAIN) { 574 if (rc == NGX_AGAIN) {
597 575
598 if (s->buffer->last < s->buffer->end) { 576 if (s->buffer->last < s->buffer->end) {
599 return rc; 577 return rc;
642 620
643 621
644 void 622 void
645 ngx_mail_session_internal_server_error(ngx_mail_session_t *s) 623 ngx_mail_session_internal_server_error(ngx_mail_session_t *s)
646 { 624 {
647 s->out = internal_server_errors[s->protocol]; 625 ngx_mail_core_srv_conf_t *cscf;
626
627 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
628
629 s->out = cscf->protocol->internal_server_error;
648 s->quit = 1; 630 s->quit = 1;
649 631
650 ngx_mail_send(s->connection->write); 632 ngx_mail_send(s->connection->write);
651 } 633 }
652 634