2004-09-28 04:34:51 -04:00
|
|
|
|
|
|
|
/*
|
2004-09-29 12:00:49 -04:00
|
|
|
* Copyright (C) Igor Sysoev
|
2004-09-28 04:34:51 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-09-07 11:29:22 -04:00
|
|
|
#ifndef _NGX_IMAP_H_INCLUDED_
|
|
|
|
#define _NGX_IMAP_H_INCLUDED_
|
|
|
|
|
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
2004-09-09 11:40:48 -04:00
|
|
|
#include <ngx_event.h>
|
|
|
|
#include <ngx_event_connect.h>
|
2004-09-07 11:29:22 -04:00
|
|
|
|
2005-09-06 12:09:32 -04:00
|
|
|
#if (NGX_IMAP_SSL)
|
|
|
|
#include <ngx_imap_ssl_module.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-09-07 11:29:22 -04:00
|
|
|
|
|
|
|
typedef struct {
|
2005-12-05 10:18:09 -03:00
|
|
|
void **main_conf;
|
|
|
|
void **srv_conf;
|
2005-06-07 11:56:31 -04:00
|
|
|
} ngx_imap_conf_ctx_t;
|
2004-09-08 01:18:51 -04:00
|
|
|
|
2005-06-07 11:56:31 -04:00
|
|
|
|
|
|
|
typedef struct {
|
2006-04-26 05:52:47 -04:00
|
|
|
in_addr_t addr;
|
|
|
|
in_port_t port;
|
|
|
|
int family;
|
|
|
|
|
|
|
|
/* server ctx */
|
|
|
|
ngx_imap_conf_ctx_t *ctx;
|
|
|
|
|
|
|
|
unsigned bind:1;
|
|
|
|
} ngx_imap_listen_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
in_addr_t addr;
|
|
|
|
ngx_imap_conf_ctx_t *ctx;
|
|
|
|
ngx_str_t addr_text;
|
|
|
|
} ngx_imap_in_addr_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ngx_imap_in_addr_t *addrs; /* array of ngx_imap_in_addr_t */
|
|
|
|
ngx_uint_t naddrs;
|
|
|
|
} ngx_imap_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;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
in_addr_t addr;
|
|
|
|
ngx_imap_conf_ctx_t *ctx;
|
|
|
|
unsigned bind:1;
|
|
|
|
} ngx_imap_conf_in_addr_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ngx_array_t servers; /* ngx_imap_core_srv_conf_t */
|
|
|
|
ngx_array_t listen; /* ngx_imap_listen_t */
|
2005-06-07 11:56:31 -04:00
|
|
|
} ngx_imap_core_main_conf_t;
|
|
|
|
|
|
|
|
|
|
|
|
#define NGX_IMAP_POP3_PROTOCOL 0
|
|
|
|
#define NGX_IMAP_IMAP_PROTOCOL 1
|
|
|
|
|
|
|
|
typedef struct {
|
2005-12-05 10:18:09 -03:00
|
|
|
ngx_msec_t timeout;
|
2005-06-07 11:56:31 -04:00
|
|
|
|
2005-12-05 10:18:09 -03:00
|
|
|
size_t imap_client_buffer_size;
|
2005-06-07 11:56:31 -04:00
|
|
|
|
2005-12-05 10:18:09 -03:00
|
|
|
ngx_uint_t protocol;
|
2005-06-07 11:56:31 -04:00
|
|
|
|
2005-12-07 11:51:31 -03:00
|
|
|
ngx_flag_t so_keepalive;
|
|
|
|
|
2005-12-05 10:18:09 -03:00
|
|
|
ngx_str_t pop3_capability;
|
|
|
|
ngx_str_t pop3_starttls_capability;
|
|
|
|
ngx_str_t imap_capability;
|
|
|
|
ngx_str_t imap_starttls_capability;
|
|
|
|
ngx_str_t imap_starttls_only_capability;
|
2005-07-08 10:34:20 -04:00
|
|
|
|
2005-12-05 10:18:09 -03:00
|
|
|
ngx_array_t pop3_capabilities;
|
|
|
|
ngx_array_t imap_capabilities;
|
2005-07-08 10:34:20 -04:00
|
|
|
|
2005-06-07 11:56:31 -04:00
|
|
|
/* server ctx */
|
2006-04-26 05:52:47 -04:00
|
|
|
ngx_imap_conf_ctx_t *ctx;
|
2005-06-07 11:56:31 -04:00
|
|
|
} ngx_imap_core_srv_conf_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2005-12-05 10:18:09 -03:00
|
|
|
void *(*create_main_conf)(ngx_conf_t *cf);
|
|
|
|
char *(*init_main_conf)(ngx_conf_t *cf, void *conf);
|
2005-06-07 11:56:31 -04:00
|
|
|
|
2005-12-05 10:18:09 -03:00
|
|
|
void *(*create_srv_conf)(ngx_conf_t *cf);
|
|
|
|
char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
|
|
|
|
void *conf);
|
2005-06-07 11:56:31 -04:00
|
|
|
} ngx_imap_module_t;
|
2004-09-08 01:18:51 -04:00
|
|
|
|
|
|
|
|
2004-09-10 10:32:02 -04:00
|
|
|
typedef enum {
|
2005-07-08 10:34:20 -04:00
|
|
|
ngx_imap_start = 0,
|
|
|
|
ngx_imap_login,
|
|
|
|
ngx_imap_user,
|
2006-07-07 12:33:19 -04:00
|
|
|
ngx_imap_passwd
|
2004-09-10 10:32:02 -04:00
|
|
|
} ngx_imap_state_e;
|
|
|
|
|
|
|
|
|
2005-07-08 10:34:20 -04:00
|
|
|
typedef enum {
|
|
|
|
ngx_pop3_start = 0,
|
|
|
|
ngx_pop3_user,
|
|
|
|
ngx_pop3_passwd
|
|
|
|
} ngx_po3_state_e;
|
|
|
|
|
|
|
|
|
2005-06-07 11:56:31 -04:00
|
|
|
typedef struct {
|
|
|
|
ngx_peer_connection_t upstream;
|
|
|
|
ngx_buf_t *buffer;
|
|
|
|
} ngx_imap_proxy_ctx_t;
|
|
|
|
|
|
|
|
|
2004-09-08 01:18:51 -04:00
|
|
|
typedef struct {
|
2004-09-09 11:40:48 -04:00
|
|
|
uint32_t signature; /* "IMAP" */
|
2004-09-08 01:18:51 -04:00
|
|
|
|
2004-09-09 11:40:48 -04:00
|
|
|
ngx_connection_t *connection;
|
2005-06-07 11:56:31 -04:00
|
|
|
|
2005-07-08 10:34:20 -04:00
|
|
|
ngx_str_t out;
|
2005-09-06 12:09:32 -04:00
|
|
|
ngx_buf_t *buffer;
|
2004-09-09 11:40:48 -04:00
|
|
|
|
2005-06-07 11:56:31 -04:00
|
|
|
void **ctx;
|
|
|
|
void **main_conf;
|
|
|
|
void **srv_conf;
|
2004-09-10 10:32:02 -04:00
|
|
|
|
2004-09-09 11:40:48 -04:00
|
|
|
ngx_imap_proxy_ctx_t *proxy;
|
|
|
|
|
2005-07-08 10:34:20 -04:00
|
|
|
ngx_uint_t imap_state;
|
2005-06-07 11:56:31 -04:00
|
|
|
|
2005-09-06 12:09:32 -04:00
|
|
|
unsigned blocked:1;
|
|
|
|
unsigned quit:1;
|
2005-06-07 11:56:31 -04:00
|
|
|
unsigned protocol:1;
|
2005-07-08 10:34:20 -04:00
|
|
|
unsigned quoted:1;
|
2005-09-23 07:02:22 -04:00
|
|
|
unsigned backslash:1;
|
|
|
|
unsigned no_sync_literal:1;
|
2006-04-26 05:52:47 -04:00
|
|
|
unsigned starttls:1;
|
2005-06-07 11:56:31 -04:00
|
|
|
|
2004-09-11 16:22:11 -04:00
|
|
|
ngx_str_t login;
|
|
|
|
ngx_str_t passwd;
|
|
|
|
|
2005-07-08 10:34:20 -04:00
|
|
|
ngx_str_t tag;
|
2005-09-06 12:09:32 -04:00
|
|
|
ngx_str_t tagged_line;
|
2005-07-08 10:34:20 -04:00
|
|
|
|
2006-04-26 05:52:47 -04:00
|
|
|
ngx_str_t *addr_text;
|
|
|
|
|
2004-09-09 11:40:48 -04:00
|
|
|
ngx_uint_t command;
|
|
|
|
ngx_array_t args;
|
|
|
|
|
2005-07-08 10:34:20 -04:00
|
|
|
ngx_uint_t login_attempt;
|
|
|
|
|
2004-09-09 11:40:48 -04:00
|
|
|
/* used to parse IMAP/POP3 command */
|
|
|
|
|
|
|
|
ngx_uint_t state;
|
2005-07-08 10:34:20 -04:00
|
|
|
u_char *cmd_start;
|
2004-09-09 11:40:48 -04:00
|
|
|
u_char *arg_start;
|
|
|
|
u_char *arg_end;
|
2005-07-08 10:34:20 -04:00
|
|
|
ngx_uint_t literal_len;
|
2004-09-08 01:18:51 -04:00
|
|
|
} ngx_imap_session_t;
|
|
|
|
|
|
|
|
|
2005-09-08 10:36:09 -04:00
|
|
|
typedef struct {
|
2005-12-05 10:18:09 -03:00
|
|
|
ngx_str_t *client;
|
|
|
|
ngx_imap_session_t *session;
|
2005-09-08 10:36:09 -04:00
|
|
|
} ngx_imap_log_ctx_t;
|
|
|
|
|
|
|
|
|
2004-09-09 11:40:48 -04:00
|
|
|
#define NGX_POP3_USER 1
|
|
|
|
#define NGX_POP3_PASS 2
|
2005-07-08 10:34:20 -04:00
|
|
|
#define NGX_POP3_CAPA 3
|
|
|
|
#define NGX_POP3_QUIT 4
|
|
|
|
#define NGX_POP3_NOOP 5
|
2005-12-05 10:18:09 -03:00
|
|
|
#define NGX_POP3_STLS 6
|
|
|
|
#define NGX_POP3_APOP 7
|
|
|
|
#define NGX_POP3_STAT 8
|
|
|
|
#define NGX_POP3_LIST 9
|
|
|
|
#define NGX_POP3_RETR 10
|
|
|
|
#define NGX_POP3_DELE 11
|
|
|
|
#define NGX_POP3_RSET 12
|
|
|
|
#define NGX_POP3_TOP 13
|
|
|
|
#define NGX_POP3_UIDL 14
|
2005-07-08 10:34:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
#define NGX_IMAP_LOGIN 1
|
|
|
|
#define NGX_IMAP_LOGOUT 2
|
|
|
|
#define NGX_IMAP_CAPABILITY 3
|
|
|
|
#define NGX_IMAP_NOOP 4
|
2005-12-05 10:18:09 -03:00
|
|
|
#define NGX_IMAP_STARTTLS 5
|
2005-07-08 10:34:20 -04:00
|
|
|
|
2005-12-05 10:18:09 -03:00
|
|
|
#define NGX_IMAP_NEXT 6
|
2004-09-09 11:40:48 -04:00
|
|
|
|
|
|
|
|
2005-07-08 10:34:20 -04:00
|
|
|
#define NGX_IMAP_PARSE_INVALID_COMMAND 20
|
2004-09-09 11:40:48 -04:00
|
|
|
|
|
|
|
|
2004-09-14 01:45:22 -04:00
|
|
|
#define NGX_IMAP_MODULE 0x50414D49 /* "IMAP" */
|
2004-09-13 12:18:09 -04:00
|
|
|
|
2005-06-07 11:56:31 -04:00
|
|
|
#define NGX_IMAP_MAIN_CONF 0x02000000
|
|
|
|
#define NGX_IMAP_SRV_CONF 0x04000000
|
|
|
|
|
|
|
|
|
|
|
|
#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_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_imap_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]
|
2004-09-13 12:18:09 -04:00
|
|
|
|
2006-04-26 05:52:47 -04:00
|
|
|
#define ngx_imap_conf_get_module_main_conf(cf, module) \
|
|
|
|
((ngx_imap_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
|
|
|
|
|
2004-09-13 12:18:09 -04:00
|
|
|
|
2004-09-07 11:29:22 -04:00
|
|
|
void ngx_imap_init_connection(ngx_connection_t *c);
|
2005-09-06 12:09:32 -04:00
|
|
|
void ngx_imap_send(ngx_event_t *wev);
|
2005-07-08 10:34:20 -04:00
|
|
|
void ngx_imap_auth_state(ngx_event_t *rev);
|
|
|
|
void ngx_pop3_auth_state(ngx_event_t *rev);
|
2004-09-07 11:29:22 -04:00
|
|
|
void ngx_imap_close_connection(ngx_connection_t *c);
|
2005-06-23 09:41:06 -04:00
|
|
|
void ngx_imap_session_internal_server_error(ngx_imap_session_t *s);
|
2004-09-07 11:29:22 -04:00
|
|
|
|
2005-07-08 10:34:20 -04:00
|
|
|
ngx_int_t ngx_imap_parse_command(ngx_imap_session_t *s);
|
2004-09-09 11:40:48 -04:00
|
|
|
ngx_int_t ngx_pop3_parse_command(ngx_imap_session_t *s);
|
|
|
|
|
2004-09-07 11:29:22 -04:00
|
|
|
|
2005-06-07 11:56:31 -04:00
|
|
|
/* STUB */
|
|
|
|
void ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers);
|
|
|
|
void ngx_imap_auth_http_init(ngx_imap_session_t *s);
|
|
|
|
/**/
|
|
|
|
|
|
|
|
|
|
|
|
extern ngx_uint_t ngx_imap_max_module;
|
|
|
|
extern ngx_module_t ngx_imap_core_module;
|
|
|
|
|
|
|
|
|
2004-09-07 11:29:22 -04:00
|
|
|
#endif /* _NGX_IMAP_H_INCLUDED_ */
|