Klaus Demo nginx / 1077835
nginx-0.0.10-2004-09-10-18:32:02 import Igor Sysoev 17 years ago
3 changed file(s) with 87 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1414 } ngx_imap_proxy_ctx_t;
1515
1616
17 typedef enum {
18 ngx_pop3_start = 0,
19 ngx_pop3_user
20 } ngx_imap_state_e;
21
22
1723 typedef struct {
1824 uint32_t signature; /* "IMAP" */
1925
2026 ngx_connection_t *connection;
2127 ngx_buf_t *buffer;
28
29 ngx_imap_state_e imap_state;
2230
2331 ngx_imap_proxy_ctx_t *proxy;
2432
8080 return;
8181 }
8282
83 c->read->event_handler = ngx_pop3_auth_state;
84
8385 ngx_pop3_auth_state(rev);
8486 }
8587
8688
8789 static void ngx_pop3_auth_state(ngx_event_t *rev)
8890 {
91 ngx_uint_t quit;
8992 u_char *text;
9093 ssize_t size;
9194 ngx_int_t rc;
9598 c = rev->data;
9699 s = c->data;
97100
101 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "pop3 auth state");
102
98103 /* TODO: timeout */
99104
100105 rc = ngx_pop3_read_command(s);
103108 return;
104109 }
105110
106 s->state = 0;
111 quit = 0;
112 text = pop3_ok;
113 size = sizeof(pop3_ok) - 1;
114
115 if (rc == NGX_OK) {
116 switch (s->imap_state) {
117
118 case ngx_pop3_start:
119
120 switch (s->command) {
121
122 case NGX_POP3_USER:
123 if (s->args.nelts == 1) {
124 s->imap_state = ngx_pop3_user;
125 } else {
126 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
127 }
128
129 break;
130
131 case NGX_POP3_QUIT:
132 quit = 1;
133 break;
134
135 default:
136 s->imap_state = ngx_pop3_start;
137 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
138 break;
139 }
140
141 break;
142
143 case ngx_pop3_user:
144
145 switch (s->command) {
146
147 case NGX_POP3_PASS:
148 if (s->args.nelts == 1) {
149 /* STUB */ s->imap_state = ngx_pop3_start;
150 } else {
151 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
152 }
153
154 break;
155
156 case NGX_POP3_QUIT:
157 quit = 1;
158 break;
159
160 default:
161 s->imap_state = ngx_pop3_start;
162 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
163 break;
164 }
165
166 break;
167 }
168 }
107169
108170 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) {
109171 text = pop3_invalid_command;
110172 size = sizeof(pop3_invalid_command) - 1;
111
112 } else {
113 text = pop3_ok;
114 size = sizeof(pop3_ok) - 1;
115173 }
116174
117175 if (ngx_send(c, text, size) < size) {
122180 ngx_imap_close_connection(c);
123181 return;
124182 }
183
184 if (quit) {
185 ngx_imap_close_connection(c);
186 return;
187 }
188
189 s->args.nelts = 0;
190 s->buffer->pos = s->buffer->start;
191 s->buffer->last = s->buffer->start;
125192 }
126193
127194
3838 s->command = NGX_POP3_USER;
3939
4040 } else if (c[0] == 'P' && c[1] == 'A'
41 && c[2] == 'A' && c[3] == 'S')
41 && c[2] == 'S' && c[3] == 'S')
4242 {
4343 s->command = NGX_POP3_PASS;
4444
5555 #endif
5656
5757 } else {
58 s->state = sw_start;
5859 return NGX_IMAP_PARSE_INVALID_COMMAND;
5960 }
6061
6162 } else {
63 s->state = sw_start;
6264 return NGX_IMAP_PARSE_INVALID_COMMAND;
6365 }
6466
7779 }
7880
7981 if (ch < 'A' || ch > 'Z') {
82 s->state = sw_start;
8083 return NGX_IMAP_PARSE_INVALID_COMMAND;
8184 }
8285
97100 break;
98101 default:
99102 if (s->args.nelts > 2) {
103 s->state = sw_start;
100104 return NGX_IMAP_PARSE_INVALID_COMMAND;
101105 }
102106
144148 state = sw_done;
145149 break;
146150 default:
151 s->state = sw_start;
147152 return NGX_IMAP_PARSE_INVALID_COMMAND;
148153 }
149154 break;
166171 s->arg_start = NULL;
167172 }
168173
174 s->state = sw_start;
169175 return NGX_OK;
170176
171177 } else {