76
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #ifndef _NGX_IMAP_H_INCLUDED_
|
|
8 #define _NGX_IMAP_H_INCLUDED_
|
|
9
|
|
10
|
|
11 #include <ngx_config.h>
|
|
12 #include <ngx_core.h>
|
|
13 #include <ngx_event.h>
|
|
14 #include <ngx_event_connect.h>
|
|
15
|
88
|
16 #if (NGX_IMAP_SSL)
|
|
17 #include <ngx_imap_ssl_module.h>
|
|
18 #endif
|
|
19
|
|
20
|
76
|
21
|
|
22 typedef struct {
|
132
|
23 void **main_conf;
|
|
24 void **srv_conf;
|
76
|
25 } ngx_imap_conf_ctx_t;
|
|
26
|
|
27
|
|
28 typedef struct {
|
132
|
29 ngx_array_t servers; /* ngx_imap_core_srv_conf_t */
|
76
|
30 } ngx_imap_core_main_conf_t;
|
|
31
|
|
32
|
|
33 #define NGX_IMAP_POP3_PROTOCOL 0
|
|
34 #define NGX_IMAP_IMAP_PROTOCOL 1
|
|
35
|
|
36 typedef struct {
|
132
|
37 ngx_msec_t timeout;
|
76
|
38
|
132
|
39 size_t imap_client_buffer_size;
|
76
|
40
|
132
|
41 ngx_uint_t protocol;
|
76
|
42
|
136
|
43 ngx_flag_t so_keepalive;
|
|
44
|
132
|
45 ngx_str_t pop3_capability;
|
|
46 ngx_str_t pop3_starttls_capability;
|
|
47 ngx_str_t imap_capability;
|
|
48 ngx_str_t imap_starttls_capability;
|
|
49 ngx_str_t imap_starttls_only_capability;
|
76
|
50
|
132
|
51 ngx_array_t pop3_capabilities;
|
|
52 ngx_array_t imap_capabilities;
|
76
|
53
|
|
54 /* server ctx */
|
|
55 ngx_imap_conf_ctx_t *ctx;
|
|
56 } ngx_imap_core_srv_conf_t;
|
|
57
|
|
58
|
|
59 typedef struct {
|
132
|
60 void *(*create_main_conf)(ngx_conf_t *cf);
|
|
61 char *(*init_main_conf)(ngx_conf_t *cf, void *conf);
|
76
|
62
|
132
|
63 void *(*create_srv_conf)(ngx_conf_t *cf);
|
|
64 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
|
|
65 void *conf);
|
76
|
66 } ngx_imap_module_t;
|
|
67
|
|
68
|
|
69 typedef enum {
|
|
70 ngx_imap_start = 0,
|
|
71 ngx_imap_login,
|
|
72 ngx_imap_user,
|
|
73 ngx_imap_passwd,
|
|
74 } ngx_imap_state_e;
|
|
75
|
|
76
|
|
77 typedef enum {
|
|
78 ngx_pop3_start = 0,
|
|
79 ngx_pop3_user,
|
|
80 ngx_pop3_passwd
|
|
81 } ngx_po3_state_e;
|
|
82
|
|
83
|
|
84 typedef struct {
|
|
85 ngx_peer_connection_t upstream;
|
|
86 ngx_buf_t *buffer;
|
|
87 } ngx_imap_proxy_ctx_t;
|
|
88
|
|
89
|
|
90 typedef struct {
|
|
91 uint32_t signature; /* "IMAP" */
|
|
92
|
|
93 ngx_connection_t *connection;
|
|
94
|
88
|
95 ngx_str_t out;
|
76
|
96 ngx_buf_t *buffer;
|
|
97
|
|
98 void **ctx;
|
|
99 void **main_conf;
|
|
100 void **srv_conf;
|
|
101
|
|
102 ngx_imap_proxy_ctx_t *proxy;
|
|
103
|
|
104 ngx_uint_t imap_state;
|
|
105
|
88
|
106 unsigned blocked:1;
|
|
107 unsigned quit:1;
|
76
|
108 unsigned protocol:1;
|
|
109 unsigned quoted:1;
|
92
|
110 unsigned backslash:1;
|
|
111 unsigned no_sync_literal:1;
|
76
|
112
|
|
113 ngx_str_t login;
|
|
114 ngx_str_t passwd;
|
|
115
|
|
116 ngx_str_t tag;
|
88
|
117 ngx_str_t tagged_line;
|
76
|
118
|
|
119 ngx_uint_t command;
|
|
120 ngx_array_t args;
|
|
121
|
|
122 ngx_uint_t login_attempt;
|
|
123
|
|
124 /* used to parse IMAP/POP3 command */
|
|
125
|
|
126 ngx_uint_t state;
|
|
127 u_char *cmd_start;
|
|
128 u_char *arg_start;
|
|
129 u_char *arg_end;
|
|
130 ngx_uint_t literal_len;
|
|
131 } ngx_imap_session_t;
|
|
132
|
|
133
|
90
|
134 typedef struct {
|
132
|
135 ngx_str_t *client;
|
|
136 ngx_imap_session_t *session;
|
90
|
137 } ngx_imap_log_ctx_t;
|
|
138
|
|
139
|
76
|
140 #define NGX_POP3_USER 1
|
|
141 #define NGX_POP3_PASS 2
|
|
142 #define NGX_POP3_CAPA 3
|
|
143 #define NGX_POP3_QUIT 4
|
|
144 #define NGX_POP3_NOOP 5
|
132
|
145 #define NGX_POP3_STLS 6
|
|
146 #define NGX_POP3_APOP 7
|
|
147 #define NGX_POP3_STAT 8
|
|
148 #define NGX_POP3_LIST 9
|
|
149 #define NGX_POP3_RETR 10
|
|
150 #define NGX_POP3_DELE 11
|
|
151 #define NGX_POP3_RSET 12
|
|
152 #define NGX_POP3_TOP 13
|
|
153 #define NGX_POP3_UIDL 14
|
76
|
154
|
|
155
|
|
156 #define NGX_IMAP_LOGIN 1
|
|
157 #define NGX_IMAP_LOGOUT 2
|
|
158 #define NGX_IMAP_CAPABILITY 3
|
|
159 #define NGX_IMAP_NOOP 4
|
132
|
160 #define NGX_IMAP_STARTTLS 5
|
76
|
161
|
132
|
162 #define NGX_IMAP_NEXT 6
|
76
|
163
|
|
164
|
|
165 #define NGX_IMAP_PARSE_INVALID_COMMAND 20
|
|
166
|
|
167
|
|
168 #define NGX_IMAP_MODULE 0x50414D49 /* "IMAP" */
|
|
169
|
|
170 #define NGX_IMAP_MAIN_CONF 0x02000000
|
|
171 #define NGX_IMAP_SRV_CONF 0x04000000
|
|
172
|
|
173
|
|
174 #define NGX_IMAP_MAIN_CONF_OFFSET offsetof(ngx_imap_conf_ctx_t, main_conf)
|
|
175 #define NGX_IMAP_SRV_CONF_OFFSET offsetof(ngx_imap_conf_ctx_t, srv_conf)
|
|
176
|
|
177
|
|
178 #define ngx_imap_get_module_ctx(s, module) (s)->ctx[module.ctx_index]
|
|
179 #define ngx_imap_set_ctx(s, c, module) s->ctx[module.ctx_index] = c;
|
|
180 #define ngx_imap_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL;
|
|
181
|
|
182
|
|
183 #define ngx_imap_get_module_main_conf(s, module) \
|
|
184 (s)->main_conf[module.ctx_index]
|
|
185 #define ngx_imap_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index]
|
|
186
|
|
187
|
|
188 void ngx_imap_init_connection(ngx_connection_t *c);
|
88
|
189 void ngx_imap_send(ngx_event_t *wev);
|
76
|
190 void ngx_imap_auth_state(ngx_event_t *rev);
|
|
191 void ngx_pop3_auth_state(ngx_event_t *rev);
|
|
192 void ngx_imap_close_connection(ngx_connection_t *c);
|
|
193 void ngx_imap_session_internal_server_error(ngx_imap_session_t *s);
|
|
194
|
|
195 ngx_int_t ngx_imap_parse_command(ngx_imap_session_t *s);
|
|
196 ngx_int_t ngx_pop3_parse_command(ngx_imap_session_t *s);
|
|
197
|
|
198
|
|
199 /* STUB */
|
|
200 void ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers);
|
|
201 void ngx_imap_auth_http_init(ngx_imap_session_t *s);
|
|
202 /**/
|
|
203
|
|
204
|
|
205 extern ngx_uint_t ngx_imap_max_module;
|
|
206 extern ngx_module_t ngx_imap_core_module;
|
|
207
|
|
208
|
|
209 #endif /* _NGX_IMAP_H_INCLUDED_ */
|