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