Mercurial > hg > nginx-mail
comparison src/mail/ngx_mail_proxy_module.c @ 467:d67e93e97b4a
Merge with nginx 0.7.30.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 11 Jan 2009 17:17:57 +0300 |
parents | 9b19e26b2660 dac47e9ef0d5 |
children | 2c989ee54dbd |
comparison
equal
deleted
inserted
replaced
444:4c92e29a7375 | 467:d67e93e97b4a |
---|---|
102 NULL, /* exit master */ | 102 NULL, /* exit master */ |
103 NGX_MODULE_V1_PADDING | 103 NGX_MODULE_V1_PADDING |
104 }; | 104 }; |
105 | 105 |
106 | 106 |
107 static u_char smtp_ok[] = "235 2.0.0 OK" CRLF; | 107 static u_char smtp_ok[] = "250 2.0.0 OK" CRLF; |
108 | 108 |
109 | 109 |
110 void | 110 void |
111 ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer) | 111 ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer) |
112 { | 112 { |
199 ngx_connection_t *c; | 199 ngx_connection_t *c; |
200 ngx_mail_session_t *s; | 200 ngx_mail_session_t *s; |
201 | 201 |
202 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy block read"); | 202 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy block read"); |
203 | 203 |
204 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 204 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
205 c = rev->data; | 205 c = rev->data; |
206 s = c->data; | 206 s = c->data; |
207 | 207 |
208 ngx_mail_proxy_close_session(s); | 208 ngx_mail_proxy_close_session(s); |
209 } | 209 } |
463 ngx_mail_proxy_smtp_handler(ngx_event_t *rev) | 463 ngx_mail_proxy_smtp_handler(ngx_event_t *rev) |
464 { | 464 { |
465 u_char *p; | 465 u_char *p; |
466 ngx_int_t rc; | 466 ngx_int_t rc; |
467 ngx_str_t line; | 467 ngx_str_t line; |
468 ngx_buf_t *b; | |
468 ngx_connection_t *c; | 469 ngx_connection_t *c; |
469 ngx_mail_session_t *s; | 470 ngx_mail_session_t *s; |
470 ngx_mail_proxy_conf_t *pcf; | 471 ngx_mail_proxy_conf_t *pcf; |
471 ngx_mail_core_srv_conf_t *cscf; | 472 ngx_mail_core_srv_conf_t *cscf; |
472 | 473 |
518 sizeof("HELO ") - 1); | 519 sizeof("HELO ") - 1); |
519 | 520 |
520 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); | 521 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
521 *p++ = CR; *p = LF; | 522 *p++ = CR; *p = LF; |
522 | 523 |
523 s->mail_state = pcf->xclient ? ngx_smtp_helo_xclient : | 524 if (pcf->xclient) { |
524 s->auth_method == NGX_MAIL_AUTH_NONE ? | 525 s->mail_state = ngx_smtp_helo_xclient; |
525 ngx_smtp_helo_from : ngx_smtp_helo; | 526 |
527 } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { | |
528 s->mail_state = ngx_smtp_helo_from; | |
529 | |
530 } else { | |
531 s->mail_state = ngx_smtp_helo; | |
532 } | |
526 | 533 |
527 break; | 534 break; |
528 | 535 |
529 case ngx_smtp_helo_xclient: | 536 case ngx_smtp_helo_xclient: |
530 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | 537 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
542 ngx_mail_proxy_internal_server_error(s); | 549 ngx_mail_proxy_internal_server_error(s); |
543 return; | 550 return; |
544 } | 551 } |
545 | 552 |
546 line.len = ngx_sprintf(line.data, | 553 line.len = ngx_sprintf(line.data, |
547 "XCLIENT PROTO=%sSMTP%s%V ADDR=%V%s%V " | 554 "XCLIENT PROTO=%sSMTP%s%V ADDR=%V%s%V NAME=%V" CRLF, |
548 "NAME=%V" CRLF, | 555 (s->esmtp ? "E" : ""), |
549 (s->esmtp ? "E" : ""), | |
550 (s->smtp_helo.len ? " HELO=" : ""), &s->smtp_helo, | 556 (s->smtp_helo.len ? " HELO=" : ""), &s->smtp_helo, |
551 &s->connection->addr_text, | 557 &s->connection->addr_text, |
552 (s->login.len ? " LOGIN=" : ""), &s->login, &s->host) | 558 (s->login.len ? " LOGIN=" : ""), &s->login, &s->host) |
553 - line.data; | 559 - line.data; |
554 | 560 |
555 s->mail_state = s->auth_method == NGX_MAIL_AUTH_NONE ? | 561 s->mail_state = (s->auth_method == NGX_MAIL_AUTH_NONE) ? |
556 ngx_smtp_xclient_from : ngx_smtp_xclient; | 562 ngx_smtp_xclient_from : ngx_smtp_xclient; |
557 | 563 |
558 break; | 564 break; |
559 | 565 |
560 case ngx_smtp_helo_from: | 566 case ngx_smtp_helo_from: |
561 case ngx_smtp_xclient_from: | 567 case ngx_smtp_xclient_from: |
600 | 606 |
601 case ngx_smtp_helo: | 607 case ngx_smtp_helo: |
602 case ngx_smtp_xclient: | 608 case ngx_smtp_xclient: |
603 case ngx_smtp_to: | 609 case ngx_smtp_to: |
604 | 610 |
605 if (s->auth_method != NGX_MAIL_AUTH_NONE) { | 611 b = s->proxy->buffer; |
606 ngx_memcpy(s->proxy->buffer->start, smtp_ok, | 612 |
607 sizeof(smtp_ok) - 1); | 613 if (s->auth_method == NGX_MAIL_AUTH_NONE) { |
608 s->proxy->buffer->last = s->proxy->buffer->start | 614 b->pos = b->start; |
609 + sizeof(smtp_ok) - 1; | 615 |
610 s->proxy->buffer->pos = s->proxy->buffer->start; | 616 } else { |
611 } | 617 ngx_memcpy(b->start, smtp_ok, sizeof(smtp_ok) - 1); |
612 | 618 b->last = b->start + sizeof(smtp_ok) - 1; |
619 } | |
613 | 620 |
614 s->connection->read->handler = ngx_mail_proxy_handler; | 621 s->connection->read->handler = ngx_mail_proxy_handler; |
615 s->connection->write->handler = ngx_mail_proxy_handler; | 622 s->connection->write->handler = ngx_mail_proxy_handler; |
616 rev->handler = ngx_mail_proxy_handler; | 623 rev->handler = ngx_mail_proxy_handler; |
617 c->write->handler = ngx_mail_proxy_handler; | 624 c->write->handler = ngx_mail_proxy_handler; |
660 ngx_connection_t *c; | 667 ngx_connection_t *c; |
661 ngx_mail_session_t *s; | 668 ngx_mail_session_t *s; |
662 | 669 |
663 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0, "mail proxy dummy handler"); | 670 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0, "mail proxy dummy handler"); |
664 | 671 |
665 if (ngx_handle_write_event(wev, 0) == NGX_ERROR) { | 672 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
666 c = wev->data; | 673 c = wev->data; |
667 s = c->data; | 674 s = c->data; |
668 | 675 |
669 ngx_mail_proxy_close_session(s); | 676 ngx_mail_proxy_close_session(s); |
670 } | 677 } |
751 break; | 758 break; |
752 | 759 |
753 default: /* NGX_MAIL_SMTP_PROTOCOL */ | 760 default: /* NGX_MAIL_SMTP_PROTOCOL */ |
754 switch (state) { | 761 switch (state) { |
755 | 762 |
756 case ngx_smtp_to: | 763 case ngx_smtp_start: |
757 return NGX_OK; | 764 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { |
758 | |
759 case ngx_smtp_helo: | |
760 case ngx_smtp_helo_from: | |
761 case ngx_smtp_helo_xclient: | |
762 case ngx_smtp_from: | |
763 if (p[0] == '2' && p[1] == '5' && p[2] == '0') { | |
764 return NGX_OK; | 765 return NGX_OK; |
765 } | 766 } |
766 break; | 767 break; |
767 | 768 |
768 case ngx_smtp_start: | 769 case ngx_smtp_helo: |
769 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { | 770 case ngx_smtp_helo_xclient: |
771 case ngx_smtp_helo_from: | |
772 case ngx_smtp_from: | |
773 if (p[0] == '2' && p[1] == '5' && p[2] == '0') { | |
770 return NGX_OK; | 774 return NGX_OK; |
771 } | 775 } |
772 break; | 776 break; |
773 | 777 |
774 case ngx_smtp_xclient: | 778 case ngx_smtp_xclient: |
775 case ngx_smtp_xclient_from: | 779 case ngx_smtp_xclient_from: |
776 if (p[0] == '2' && (p[1] == '2' || p[1] == '5') && p[2] == '0') { | 780 if (p[0] == '2' && (p[1] == '2' || p[1] == '5') && p[2] == '0') { |
777 return NGX_OK; | 781 return NGX_OK; |
778 } | 782 } |
779 break; | 783 break; |
784 | |
785 case ngx_smtp_to: | |
786 return NGX_OK; | |
780 } | 787 } |
781 | 788 |
782 break; | 789 break; |
783 } | 790 } |
784 | 791 |
943 | 950 |
944 ngx_mail_proxy_close_session(s); | 951 ngx_mail_proxy_close_session(s); |
945 return; | 952 return; |
946 } | 953 } |
947 | 954 |
948 if (ngx_handle_write_event(dst->write, 0) == NGX_ERROR) { | 955 if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { |
949 ngx_mail_proxy_close_session(s); | 956 ngx_mail_proxy_close_session(s); |
950 return; | 957 return; |
951 } | 958 } |
952 | 959 |
953 if (ngx_handle_read_event(dst->read, 0) == NGX_ERROR) { | 960 if (ngx_handle_read_event(dst->read, 0) != NGX_OK) { |
954 ngx_mail_proxy_close_session(s); | 961 ngx_mail_proxy_close_session(s); |
955 return; | 962 return; |
956 } | 963 } |
957 | 964 |
958 if (ngx_handle_write_event(src->write, 0) == NGX_ERROR) { | 965 if (ngx_handle_write_event(src->write, 0) != NGX_OK) { |
959 ngx_mail_proxy_close_session(s); | 966 ngx_mail_proxy_close_session(s); |
960 return; | 967 return; |
961 } | 968 } |
962 | 969 |
963 if (ngx_handle_read_event(src->read, 0) == NGX_ERROR) { | 970 if (ngx_handle_read_event(src->read, 0) != NGX_OK) { |
964 ngx_mail_proxy_close_session(s); | 971 ngx_mail_proxy_close_session(s); |
965 return; | 972 return; |
966 } | 973 } |
967 | 974 |
968 if (c == s->connection) { | 975 if (c == s->connection) { |