Annotation of embedaddon/nginx/src/mail/ngx_mail.h, revision 1.1.1.1

1.1       misho       1: 
                      2: /*
                      3:  * Copyright (C) Igor Sysoev
                      4:  * Copyright (C) Nginx, Inc.
                      5:  */
                      6: 
                      7: 
                      8: #ifndef _NGX_MAIL_H_INCLUDED_
                      9: #define _NGX_MAIL_H_INCLUDED_
                     10: 
                     11: 
                     12: #include <ngx_config.h>
                     13: #include <ngx_core.h>
                     14: #include <ngx_event.h>
                     15: #include <ngx_event_connect.h>
                     16: 
                     17: #if (NGX_MAIL_SSL)
                     18: #include <ngx_mail_ssl_module.h>
                     19: #endif
                     20: 
                     21: 
                     22: 
                     23: typedef struct {
                     24:     void                  **main_conf;
                     25:     void                  **srv_conf;
                     26: } ngx_mail_conf_ctx_t;
                     27: 
                     28: 
                     29: typedef struct {
                     30:     u_char                  sockaddr[NGX_SOCKADDRLEN];
                     31:     socklen_t               socklen;
                     32: 
                     33:     /* server ctx */
                     34:     ngx_mail_conf_ctx_t    *ctx;
                     35: 
                     36:     unsigned                bind:1;
                     37:     unsigned                wildcard:1;
                     38: #if (NGX_MAIL_SSL)
                     39:     unsigned                ssl:1;
                     40: #endif
                     41: #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
                     42:     unsigned                ipv6only:1;
                     43: #endif
                     44:     unsigned                so_keepalive:2;
                     45: #if (NGX_HAVE_KEEPALIVE_TUNABLE)
                     46:     int                     tcp_keepidle;
                     47:     int                     tcp_keepintvl;
                     48:     int                     tcp_keepcnt;
                     49: #endif
                     50: } ngx_mail_listen_t;
                     51: 
                     52: 
                     53: typedef struct {
                     54:     ngx_mail_conf_ctx_t    *ctx;
                     55:     ngx_str_t               addr_text;
                     56: #if (NGX_MAIL_SSL)
                     57:     ngx_uint_t              ssl;    /* unsigned   ssl:1; */
                     58: #endif
                     59: } ngx_mail_addr_conf_t;
                     60: 
                     61: typedef struct {
                     62:     in_addr_t               addr;
                     63:     ngx_mail_addr_conf_t    conf;
                     64: } ngx_mail_in_addr_t;
                     65: 
                     66: 
                     67: #if (NGX_HAVE_INET6)
                     68: 
                     69: typedef struct {
                     70:     struct in6_addr         addr6;
                     71:     ngx_mail_addr_conf_t    conf;
                     72: } ngx_mail_in6_addr_t;
                     73: 
                     74: #endif
                     75: 
                     76: 
                     77: typedef struct {
                     78:     /* ngx_mail_in_addr_t or ngx_mail_in6_addr_t */
                     79:     void                   *addrs;
                     80:     ngx_uint_t              naddrs;
                     81: } ngx_mail_port_t;
                     82: 
                     83: 
                     84: typedef struct {
                     85:     int                     family;
                     86:     in_port_t               port;
                     87:     ngx_array_t             addrs;       /* array of ngx_mail_conf_addr_t */
                     88: } ngx_mail_conf_port_t;
                     89: 
                     90: 
                     91: typedef struct {
                     92:     struct sockaddr        *sockaddr;
                     93:     socklen_t               socklen;
                     94: 
                     95:     ngx_mail_conf_ctx_t    *ctx;
                     96: 
                     97:     unsigned                bind:1;
                     98:     unsigned                wildcard:1;
                     99: #if (NGX_MAIL_SSL)
                    100:     unsigned                ssl:1;
                    101: #endif
                    102: #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
                    103:     unsigned                ipv6only:1;
                    104: #endif
                    105:     unsigned                so_keepalive:2;
                    106: #if (NGX_HAVE_KEEPALIVE_TUNABLE)
                    107:     int                     tcp_keepidle;
                    108:     int                     tcp_keepintvl;
                    109:     int                     tcp_keepcnt;
                    110: #endif
                    111: } ngx_mail_conf_addr_t;
                    112: 
                    113: 
                    114: typedef struct {
                    115:     ngx_array_t             servers;     /* ngx_mail_core_srv_conf_t */
                    116:     ngx_array_t             listen;      /* ngx_mail_listen_t */
                    117: } ngx_mail_core_main_conf_t;
                    118: 
                    119: 
                    120: #define NGX_MAIL_POP3_PROTOCOL  0
                    121: #define NGX_MAIL_IMAP_PROTOCOL  1
                    122: #define NGX_MAIL_SMTP_PROTOCOL  2
                    123: 
                    124: 
                    125: typedef struct ngx_mail_protocol_s  ngx_mail_protocol_t;
                    126: 
                    127: 
                    128: typedef struct {
                    129:     ngx_mail_protocol_t    *protocol;
                    130: 
                    131:     ngx_msec_t              timeout;
                    132:     ngx_msec_t              resolver_timeout;
                    133: 
                    134:     ngx_flag_t              so_keepalive;
                    135: 
                    136:     ngx_str_t               server_name;
                    137: 
                    138:     u_char                 *file_name;
                    139:     ngx_int_t               line;
                    140: 
                    141:     ngx_resolver_t         *resolver;
                    142: 
                    143:     /* server ctx */
                    144:     ngx_mail_conf_ctx_t    *ctx;
                    145: } ngx_mail_core_srv_conf_t;
                    146: 
                    147: 
                    148: typedef enum {
                    149:     ngx_pop3_start = 0,
                    150:     ngx_pop3_user,
                    151:     ngx_pop3_passwd,
                    152:     ngx_pop3_auth_login_username,
                    153:     ngx_pop3_auth_login_password,
                    154:     ngx_pop3_auth_plain,
                    155:     ngx_pop3_auth_cram_md5
                    156: } ngx_pop3_state_e;
                    157: 
                    158: 
                    159: typedef enum {
                    160:     ngx_imap_start = 0,
                    161:     ngx_imap_auth_login_username,
                    162:     ngx_imap_auth_login_password,
                    163:     ngx_imap_auth_plain,
                    164:     ngx_imap_auth_cram_md5,
                    165:     ngx_imap_login,
                    166:     ngx_imap_user,
                    167:     ngx_imap_passwd
                    168: } ngx_imap_state_e;
                    169: 
                    170: 
                    171: typedef enum {
                    172:     ngx_smtp_start = 0,
                    173:     ngx_smtp_auth_login_username,
                    174:     ngx_smtp_auth_login_password,
                    175:     ngx_smtp_auth_plain,
                    176:     ngx_smtp_auth_cram_md5,
                    177:     ngx_smtp_helo,
                    178:     ngx_smtp_helo_xclient,
                    179:     ngx_smtp_helo_from,
                    180:     ngx_smtp_xclient,
                    181:     ngx_smtp_xclient_from,
                    182:     ngx_smtp_xclient_helo,
                    183:     ngx_smtp_from,
                    184:     ngx_smtp_to
                    185: } ngx_smtp_state_e;
                    186: 
                    187: 
                    188: typedef struct {
                    189:     ngx_peer_connection_t   upstream;
                    190:     ngx_buf_t              *buffer;
                    191: } ngx_mail_proxy_ctx_t;
                    192: 
                    193: 
                    194: typedef struct {
                    195:     uint32_t                signature;         /* "MAIL" */
                    196: 
                    197:     ngx_connection_t       *connection;
                    198: 
                    199:     ngx_str_t               out;
                    200:     ngx_buf_t              *buffer;
                    201: 
                    202:     void                  **ctx;
                    203:     void                  **main_conf;
                    204:     void                  **srv_conf;
                    205: 
                    206:     ngx_resolver_ctx_t     *resolver_ctx;
                    207: 
                    208:     ngx_mail_proxy_ctx_t   *proxy;
                    209: 
                    210:     ngx_uint_t              mail_state;
                    211: 
                    212:     unsigned                protocol:3;
                    213:     unsigned                blocked:1;
                    214:     unsigned                quit:1;
                    215:     unsigned                quoted:1;
                    216:     unsigned                backslash:1;
                    217:     unsigned                no_sync_literal:1;
                    218:     unsigned                starttls:1;
                    219:     unsigned                esmtp:1;
                    220:     unsigned                auth_method:3;
                    221:     unsigned                auth_wait:1;
                    222: 
                    223:     ngx_str_t               login;
                    224:     ngx_str_t               passwd;
                    225: 
                    226:     ngx_str_t               salt;
                    227:     ngx_str_t               tag;
                    228:     ngx_str_t               tagged_line;
                    229:     ngx_str_t               text;
                    230: 
                    231:     ngx_str_t              *addr_text;
                    232:     ngx_str_t               host;
                    233:     ngx_str_t               smtp_helo;
                    234:     ngx_str_t               smtp_from;
                    235:     ngx_str_t               smtp_to;
                    236: 
                    237:     ngx_uint_t              command;
                    238:     ngx_array_t             args;
                    239: 
                    240:     ngx_uint_t              login_attempt;
                    241: 
                    242:     /* used to parse POP3/IMAP/SMTP command */
                    243: 
                    244:     ngx_uint_t              state;
                    245:     u_char                 *cmd_start;
                    246:     u_char                 *arg_start;
                    247:     u_char                 *arg_end;
                    248:     ngx_uint_t              literal_len;
                    249: } ngx_mail_session_t;
                    250: 
                    251: 
                    252: typedef struct {
                    253:     ngx_str_t              *client;
                    254:     ngx_mail_session_t     *session;
                    255: } ngx_mail_log_ctx_t;
                    256: 
                    257: 
                    258: #define NGX_POP3_USER          1
                    259: #define NGX_POP3_PASS          2
                    260: #define NGX_POP3_CAPA          3
                    261: #define NGX_POP3_QUIT          4
                    262: #define NGX_POP3_NOOP          5
                    263: #define NGX_POP3_STLS          6
                    264: #define NGX_POP3_APOP          7
                    265: #define NGX_POP3_AUTH          8
                    266: #define NGX_POP3_STAT          9
                    267: #define NGX_POP3_LIST          10
                    268: #define NGX_POP3_RETR          11
                    269: #define NGX_POP3_DELE          12
                    270: #define NGX_POP3_RSET          13
                    271: #define NGX_POP3_TOP           14
                    272: #define NGX_POP3_UIDL          15
                    273: 
                    274: 
                    275: #define NGX_IMAP_LOGIN         1
                    276: #define NGX_IMAP_LOGOUT        2
                    277: #define NGX_IMAP_CAPABILITY    3
                    278: #define NGX_IMAP_NOOP          4
                    279: #define NGX_IMAP_STARTTLS      5
                    280: 
                    281: #define NGX_IMAP_NEXT          6
                    282: 
                    283: #define NGX_IMAP_AUTHENTICATE  7
                    284: 
                    285: 
                    286: #define NGX_SMTP_HELO          1
                    287: #define NGX_SMTP_EHLO          2
                    288: #define NGX_SMTP_AUTH          3
                    289: #define NGX_SMTP_QUIT          4
                    290: #define NGX_SMTP_NOOP          5
                    291: #define NGX_SMTP_MAIL          6
                    292: #define NGX_SMTP_RSET          7
                    293: #define NGX_SMTP_RCPT          8
                    294: #define NGX_SMTP_DATA          9
                    295: #define NGX_SMTP_VRFY          10
                    296: #define NGX_SMTP_EXPN          11
                    297: #define NGX_SMTP_HELP          12
                    298: #define NGX_SMTP_STARTTLS      13
                    299: 
                    300: 
                    301: #define NGX_MAIL_AUTH_PLAIN             0
                    302: #define NGX_MAIL_AUTH_LOGIN             1
                    303: #define NGX_MAIL_AUTH_LOGIN_USERNAME    2
                    304: #define NGX_MAIL_AUTH_APOP              3
                    305: #define NGX_MAIL_AUTH_CRAM_MD5          4
                    306: #define NGX_MAIL_AUTH_NONE              5
                    307: 
                    308: 
                    309: #define NGX_MAIL_AUTH_PLAIN_ENABLED     0x0002
                    310: #define NGX_MAIL_AUTH_LOGIN_ENABLED     0x0004
                    311: #define NGX_MAIL_AUTH_APOP_ENABLED      0x0008
                    312: #define NGX_MAIL_AUTH_CRAM_MD5_ENABLED  0x0010
                    313: #define NGX_MAIL_AUTH_NONE_ENABLED      0x0020
                    314: 
                    315: 
                    316: #define NGX_MAIL_PARSE_INVALID_COMMAND  20
                    317: 
                    318: 
                    319: typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
                    320:     ngx_connection_t *c);
                    321: typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
                    322: typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
                    323: typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);
                    324: 
                    325: 
                    326: struct ngx_mail_protocol_s {
                    327:     ngx_str_t                   name;
                    328:     in_port_t                   port[4];
                    329:     ngx_uint_t                  type;
                    330: 
                    331:     ngx_mail_init_session_pt    init_session;
                    332:     ngx_mail_init_protocol_pt   init_protocol;
                    333:     ngx_mail_parse_command_pt   parse_command;
                    334:     ngx_mail_auth_state_pt      auth_state;
                    335: 
                    336:     ngx_str_t                   internal_server_error;
                    337: };
                    338: 
                    339: 
                    340: typedef struct {
                    341:     ngx_mail_protocol_t        *protocol;
                    342: 
                    343:     void                       *(*create_main_conf)(ngx_conf_t *cf);
                    344:     char                       *(*init_main_conf)(ngx_conf_t *cf, void *conf);
                    345: 
                    346:     void                       *(*create_srv_conf)(ngx_conf_t *cf);
                    347:     char                       *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
                    348:                                       void *conf);
                    349: } ngx_mail_module_t;
                    350: 
                    351: 
                    352: #define NGX_MAIL_MODULE         0x4C49414D     /* "MAIL" */
                    353: 
                    354: #define NGX_MAIL_MAIN_CONF      0x02000000
                    355: #define NGX_MAIL_SRV_CONF       0x04000000
                    356: 
                    357: 
                    358: #define NGX_MAIL_MAIN_CONF_OFFSET  offsetof(ngx_mail_conf_ctx_t, main_conf)
                    359: #define NGX_MAIL_SRV_CONF_OFFSET   offsetof(ngx_mail_conf_ctx_t, srv_conf)
                    360: 
                    361: 
                    362: #define ngx_mail_get_module_ctx(s, module)     (s)->ctx[module.ctx_index]
                    363: #define ngx_mail_set_ctx(s, c, module)         s->ctx[module.ctx_index] = c;
                    364: #define ngx_mail_delete_ctx(s, module)         s->ctx[module.ctx_index] = NULL;
                    365: 
                    366: 
                    367: #define ngx_mail_get_module_main_conf(s, module)                             \
                    368:     (s)->main_conf[module.ctx_index]
                    369: #define ngx_mail_get_module_srv_conf(s, module)  (s)->srv_conf[module.ctx_index]
                    370: 
                    371: #define ngx_mail_conf_get_module_main_conf(cf, module)                       \
                    372:     ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
                    373: #define ngx_mail_conf_get_module_srv_conf(cf, module)                        \
                    374:     ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
                    375: 
                    376: 
                    377: #if (NGX_MAIL_SSL)
                    378: void ngx_mail_starttls_handler(ngx_event_t *rev);
                    379: ngx_int_t ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c);
                    380: #endif
                    381: 
                    382: 
                    383: void ngx_mail_init_connection(ngx_connection_t *c);
                    384: 
                    385: ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
                    386:     ngx_mail_core_srv_conf_t *cscf);
                    387: ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
                    388:     ngx_uint_t n);
                    389: ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s,
                    390:     ngx_connection_t *c, ngx_uint_t n);
                    391: ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s,
                    392:     ngx_connection_t *c);
                    393: ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,
                    394:     ngx_connection_t *c, char *prefix, size_t len);
                    395: ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c);
                    396: ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c);
                    397: 
                    398: void ngx_mail_send(ngx_event_t *wev);
                    399: ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c);
                    400: void ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c);
                    401: void ngx_mail_close_connection(ngx_connection_t *c);
                    402: void ngx_mail_session_internal_server_error(ngx_mail_session_t *s);
                    403: u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len);
                    404: 
                    405: 
                    406: char *ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
                    407: 
                    408: 
                    409: /* STUB */
                    410: void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_addr_t *peer);
                    411: void ngx_mail_auth_http_init(ngx_mail_session_t *s);
                    412: /**/
                    413: 
                    414: 
                    415: extern ngx_uint_t    ngx_mail_max_module;
                    416: extern ngx_module_t  ngx_mail_core_module;
                    417: 
                    418: 
                    419: #endif /* _NGX_MAIL_H_INCLUDED_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>