Mercurial > hg > nginx
diff src/mail/ngx_mail.h @ 1136:68f30ab68bb7
Many changes:
*) rename imap to mail, sort pop3/imap functions
*) smtp auth support
*) pop3 starttls only
*) fix segfault if cram-md5 was used without apop
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 19 Mar 2007 13:36:56 +0000 |
parents | src/imap/ngx_imap.h@4d68c486fcb0 |
children | 27f2299e0d80 |
line wrap: on
line diff
copy from src/imap/ngx_imap.h copy to src/mail/ngx_mail.h --- a/src/imap/ngx_imap.h +++ b/src/mail/ngx_mail.h @@ -4,8 +4,8 @@ */ -#ifndef _NGX_IMAP_H_INCLUDED_ -#define _NGX_IMAP_H_INCLUDED_ +#ifndef _NGX_MAIL_H_INCLUDED_ +#define _NGX_MAIL_H_INCLUDED_ #include <ngx_config.h> @@ -13,8 +13,8 @@ #include <ngx_event.h> #include <ngx_event_connect.h> -#if (NGX_IMAP_SSL) -#include <ngx_imap_ssl_module.h> +#if (NGX_MAIL_SSL) +#include <ngx_mail_ssl_module.h> #endif @@ -22,7 +22,7 @@ typedef struct { void **main_conf; void **srv_conf; -} ngx_imap_conf_ctx_t; +} ngx_mail_conf_ctx_t; typedef struct { @@ -31,46 +31,47 @@ typedef struct { int family; /* server ctx */ - ngx_imap_conf_ctx_t *ctx; + ngx_mail_conf_ctx_t *ctx; unsigned bind:1; -} ngx_imap_listen_t; +} ngx_mail_listen_t; typedef struct { in_addr_t addr; - ngx_imap_conf_ctx_t *ctx; + ngx_mail_conf_ctx_t *ctx; ngx_str_t addr_text; -} ngx_imap_in_addr_t; +} ngx_mail_in_addr_t; typedef struct { - ngx_imap_in_addr_t *addrs; /* array of ngx_imap_in_addr_t */ + ngx_mail_in_addr_t *addrs; /* array of ngx_mail_in_addr_t */ ngx_uint_t naddrs; -} ngx_imap_in_port_t; +} ngx_mail_in_port_t; typedef struct { in_port_t port; - ngx_array_t addrs; /* array of ngx_imap_conf_in_addr_t */ -} ngx_imap_conf_in_port_t; + ngx_array_t addrs; /* array of ngx_mail_conf_in_addr_t */ +} ngx_mail_conf_in_port_t; typedef struct { in_addr_t addr; - ngx_imap_conf_ctx_t *ctx; + ngx_mail_conf_ctx_t *ctx; unsigned bind:1; -} ngx_imap_conf_in_addr_t; +} ngx_mail_conf_in_addr_t; typedef struct { - ngx_array_t servers; /* ngx_imap_core_srv_conf_t */ - ngx_array_t listen; /* ngx_imap_listen_t */ -} ngx_imap_core_main_conf_t; + ngx_array_t servers; /* ngx_mail_core_srv_conf_t */ + ngx_array_t listen; /* ngx_mail_listen_t */ +} ngx_mail_core_main_conf_t; -#define NGX_IMAP_POP3_PROTOCOL 0 -#define NGX_IMAP_IMAP_PROTOCOL 1 +#define NGX_MAIL_POP3_PROTOCOL 0 +#define NGX_MAIL_IMAP_PROTOCOL 1 +#define NGX_MAIL_SMTP_PROTOCOL 2 typedef struct { ngx_msec_t timeout; @@ -83,22 +84,29 @@ typedef struct { ngx_str_t pop3_capability; ngx_str_t pop3_starttls_capability; + ngx_str_t pop3_starttls_only_capability; ngx_str_t pop3_auth_capability; ngx_str_t imap_capability; ngx_str_t imap_starttls_capability; ngx_str_t imap_starttls_only_capability; - ngx_str_t server_name; + ngx_str_t smtp_capability; - ngx_uint_t auth_methods; + ngx_str_t server_name; + ngx_str_t smtp_server_name; + ngx_str_t smtp_greeting; + + ngx_uint_t pop3_auth_methods; + ngx_uint_t smtp_auth_methods; ngx_array_t pop3_capabilities; ngx_array_t imap_capabilities; + ngx_array_t smtp_capabilities; /* server ctx */ - ngx_imap_conf_ctx_t *ctx; -} ngx_imap_core_srv_conf_t; + ngx_mail_conf_ctx_t *ctx; +} ngx_mail_core_srv_conf_t; typedef struct { @@ -108,15 +116,7 @@ typedef struct { void *(*create_srv_conf)(ngx_conf_t *cf); char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, void *conf); -} ngx_imap_module_t; - - -typedef enum { - ngx_imap_start = 0, - ngx_imap_login, - ngx_imap_user, - ngx_imap_passwd -} ngx_imap_state_e; +} ngx_mail_module_t; typedef enum { @@ -130,14 +130,34 @@ typedef enum { } ngx_po3_state_e; +typedef enum { + ngx_imap_start = 0, + ngx_imap_login, + ngx_imap_user, + ngx_imap_passwd +} ngx_imap_state_e; + + +typedef enum { + ngx_smtp_start = 0, + ngx_smtp_auth_login_username, + ngx_smtp_auth_login_password, + ngx_smtp_auth_plain, + ngx_smtp_auth_cram_md5, + ngx_smtp_helo, + ngx_smtp_noxclient, + ngx_smtp_xclient +} ngx_smtp_state_e; + + typedef struct { ngx_peer_connection_t upstream; ngx_buf_t *buffer; -} ngx_imap_proxy_ctx_t; +} ngx_mail_proxy_ctx_t; typedef struct { - uint32_t signature; /* "IMAP" */ + uint32_t signature; /* "MAIL" */ ngx_connection_t *connection; @@ -148,17 +168,18 @@ typedef struct { void **main_conf; void **srv_conf; - ngx_imap_proxy_ctx_t *proxy; + ngx_mail_proxy_ctx_t *proxy; - ngx_uint_t imap_state; + ngx_uint_t mail_state; unsigned blocked:1; unsigned quit:1; - unsigned protocol:1; + unsigned protocol:2; unsigned quoted:1; unsigned backslash:1; unsigned no_sync_literal:1; unsigned starttls:1; + unsigned esmtp:1; unsigned auth_method:2; unsigned auth_wait:1; @@ -170,26 +191,27 @@ typedef struct { ngx_str_t tagged_line; ngx_str_t *addr_text; + ngx_str_t smtp_helo; ngx_uint_t command; ngx_array_t args; ngx_uint_t login_attempt; - /* used to parse IMAP/POP3 command */ + /* used to parse IMAP/POP3/SMTP command */ ngx_uint_t state; u_char *cmd_start; u_char *arg_start; u_char *arg_end; ngx_uint_t literal_len; -} ngx_imap_session_t; +} ngx_mail_session_t; typedef struct { ngx_str_t *client; - ngx_imap_session_t *session; -} ngx_imap_log_ctx_t; + ngx_mail_session_t *session; +} ngx_mail_log_ctx_t; #define NGX_POP3_USER 1 @@ -218,61 +240,74 @@ typedef struct { #define NGX_IMAP_NEXT 6 -#define NGX_IMAP_AUTH_PLAIN 0 -#define NGX_IMAP_AUTH_APOP 1 -#define NGX_IMAP_AUTH_CRAM_MD5 2 - - -#define NGX_IMAP_AUTH_PLAIN_ENABLED 0x0002 -#define NGX_IMAP_AUTH_APOP_ENABLED 0x0004 -#define NGX_IMAP_AUTH_CRAM_MD5_ENABLED 0x0008 +#define NGX_SMTP_HELO 1 +#define NGX_SMTP_EHLO 2 +#define NGX_SMTP_AUTH 3 +#define NGX_SMTP_QUIT 4 +#define NGX_SMTP_NOOP 5 +#define NGX_SMTP_MAIL 6 +#define NGX_SMTP_RSET 7 -#define NGX_IMAP_PARSE_INVALID_COMMAND 20 +#define NGX_MAIL_AUTH_PLAIN 0 +#define NGX_MAIL_AUTH_LOGIN 1 +#define NGX_MAIL_AUTH_APOP 2 +#define NGX_MAIL_AUTH_CRAM_MD5 3 -#define NGX_IMAP_MODULE 0x50414D49 /* "IMAP" */ - -#define NGX_IMAP_MAIN_CONF 0x02000000 -#define NGX_IMAP_SRV_CONF 0x04000000 +#define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002 +#define NGX_MAIL_AUTH_LOGIN_ENABLED 0x0004 +#define NGX_MAIL_AUTH_APOP_ENABLED 0x0008 +#define NGX_MAIL_AUTH_CRAM_MD5_ENABLED 0x0010 -#define NGX_IMAP_MAIN_CONF_OFFSET offsetof(ngx_imap_conf_ctx_t, main_conf) -#define NGX_IMAP_SRV_CONF_OFFSET offsetof(ngx_imap_conf_ctx_t, srv_conf) +#define NGX_MAIL_PARSE_INVALID_COMMAND 20 -#define ngx_imap_get_module_ctx(s, module) (s)->ctx[module.ctx_index] -#define ngx_imap_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; -#define ngx_imap_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; +#define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */ + +#define NGX_MAIL_MAIN_CONF 0x02000000 +#define NGX_MAIL_SRV_CONF 0x04000000 + + +#define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf) +#define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf) + + +#define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index] +#define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; +#define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; -#define ngx_imap_get_module_main_conf(s, module) \ +#define ngx_mail_get_module_main_conf(s, module) \ (s)->main_conf[module.ctx_index] -#define ngx_imap_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index] +#define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index] -#define ngx_imap_conf_get_module_main_conf(cf, module) \ - ((ngx_imap_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] +#define ngx_mail_conf_get_module_main_conf(cf, module) \ + ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] -void ngx_imap_init_connection(ngx_connection_t *c); -void ngx_imap_send(ngx_event_t *wev); -void ngx_imap_auth_state(ngx_event_t *rev); +void ngx_mail_init_connection(ngx_connection_t *c); +void ngx_mail_send(ngx_event_t *wev); void ngx_pop3_auth_state(ngx_event_t *rev); -void ngx_imap_close_connection(ngx_connection_t *c); -void ngx_imap_session_internal_server_error(ngx_imap_session_t *s); +void ngx_imap_auth_state(ngx_event_t *rev); +void ngx_smtp_auth_state(ngx_event_t *rev); +void ngx_mail_close_connection(ngx_connection_t *c); +void ngx_mail_session_internal_server_error(ngx_mail_session_t *s); -ngx_int_t ngx_imap_parse_command(ngx_imap_session_t *s); -ngx_int_t ngx_pop3_parse_command(ngx_imap_session_t *s); +ngx_int_t ngx_pop3_parse_command(ngx_mail_session_t *s); +ngx_int_t ngx_imap_parse_command(ngx_mail_session_t *s); +ngx_int_t ngx_smtp_parse_command(ngx_mail_session_t *s); /* STUB */ -void ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peer_addr_t *peer); -void ngx_imap_auth_http_init(ngx_imap_session_t *s); +void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer); +void ngx_mail_auth_http_init(ngx_mail_session_t *s); /**/ -extern ngx_uint_t ngx_imap_max_module; -extern ngx_module_t ngx_imap_core_module; +extern ngx_uint_t ngx_mail_max_module; +extern ngx_module_t ngx_mail_core_module; -#endif /* _NGX_IMAP_H_INCLUDED_ */ +#endif /* _NGX_MAIL_H_INCLUDED_ */