Mercurial > hg > nginx-vendor-1-0
comparison src/imap/ngx_imap_proxy_module.c @ 120:e85dca77c46a NGINX_0_3_7
nginx 0.3.7
*) Feature: the "access_log" supports the "buffer=" parameter.
*) Bugfix: nginx could not be built on platforms different from i386,
amd64, sparc и ppc; bug appeared in 0.3.2.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 27 Oct 2005 00:00:00 +0400 |
parents | ca4f70b3ccc6 |
children | df17fbafec8f |
comparison
equal
deleted
inserted
replaced
119:85abc07cafba | 120:e85dca77c46a |
---|---|
30 static void *ngx_imap_proxy_create_conf(ngx_conf_t *cf); | 30 static void *ngx_imap_proxy_create_conf(ngx_conf_t *cf); |
31 static char *ngx_imap_proxy_merge_conf(ngx_conf_t *cf, void *parent, | 31 static char *ngx_imap_proxy_merge_conf(ngx_conf_t *cf, void *parent, |
32 void *child); | 32 void *child); |
33 | 33 |
34 | 34 |
35 #define NGX_IMAP_WAIT_OK 0 | 35 #define NGX_IMAP_WAIT_OK 0 |
36 #define NGX_IMAP_WAIT_NEXT 1 | 36 #define NGX_IMAP_WAIT_NEXT 1 |
37 | 37 |
38 | 38 |
39 static ngx_command_t ngx_imap_proxy_commands[] = { | 39 static ngx_command_t ngx_imap_proxy_commands[] = { |
40 | 40 |
41 { ngx_string("proxy"), | 41 { ngx_string("proxy"), |
154 | 154 |
155 | 155 |
156 static void | 156 static void |
157 ngx_imap_proxy_imap_handler(ngx_event_t *rev) | 157 ngx_imap_proxy_imap_handler(ngx_event_t *rev) |
158 { | 158 { |
159 char *action; | |
160 u_char *p; | 159 u_char *p; |
161 ngx_int_t rc; | 160 ngx_int_t rc; |
162 ngx_str_t line; | 161 ngx_str_t line; |
163 ngx_connection_t *c; | 162 ngx_connection_t *c; |
164 ngx_imap_session_t *s; | 163 ngx_imap_session_t *s; |
192 | 191 |
193 if (rc == NGX_AGAIN) { | 192 if (rc == NGX_AGAIN) { |
194 return; | 193 return; |
195 } | 194 } |
196 | 195 |
197 if (rc == NGX_ERROR || rc == NGX_IMAP_PROXY_INVALID) { | 196 if (rc == NGX_ERROR) { |
198 ngx_imap_proxy_internal_server_error(s); | 197 ngx_imap_proxy_internal_server_error(s); |
199 return; | |
200 } | |
201 | |
202 if (rc == NGX_IMAP_PROXY_ERROR) { | |
203 s->connection->read->handler = ngx_imap_proxy_handler; | |
204 s->connection->write->handler = ngx_imap_proxy_handler; | |
205 rev->handler = ngx_imap_proxy_handler; | |
206 c->write->handler = ngx_imap_proxy_handler; | |
207 | |
208 ngx_imap_proxy_handler(c->read); | |
209 return; | 198 return; |
210 } | 199 } |
211 | 200 |
212 switch (s->imap_state) { | 201 switch (s->imap_state) { |
213 | 202 |
292 | 281 |
293 pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module); | 282 pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module); |
294 ngx_add_timer(s->connection->read, pcf->timeout); | 283 ngx_add_timer(s->connection->read, pcf->timeout); |
295 ngx_del_timer(c->read); | 284 ngx_del_timer(c->read); |
296 | 285 |
297 action = c->log->action; | |
298 c->log->action = NULL; | 286 c->log->action = NULL; |
299 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | 287 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); |
300 c->log->action = action; | |
301 | 288 |
302 c->log->action = "proxying"; | 289 c->log->action = "proxying"; |
303 } | 290 } |
304 } | 291 } |
305 | 292 |
306 | 293 |
307 static void | 294 static void |
308 ngx_imap_proxy_pop3_handler(ngx_event_t *rev) | 295 ngx_imap_proxy_pop3_handler(ngx_event_t *rev) |
309 { | 296 { |
310 char *action; | |
311 u_char *p; | 297 u_char *p; |
312 ngx_int_t rc; | 298 ngx_int_t rc; |
313 ngx_str_t line; | 299 ngx_str_t line; |
314 ngx_connection_t *c; | 300 ngx_connection_t *c; |
315 ngx_imap_session_t *s; | 301 ngx_imap_session_t *s; |
342 | 328 |
343 if (rc == NGX_AGAIN) { | 329 if (rc == NGX_AGAIN) { |
344 return; | 330 return; |
345 } | 331 } |
346 | 332 |
347 if (rc == NGX_ERROR || rc == NGX_IMAP_PROXY_INVALID) { | 333 if (rc == NGX_ERROR) { |
348 ngx_imap_proxy_internal_server_error(s); | 334 ngx_imap_proxy_internal_server_error(s); |
349 return; | |
350 } | |
351 | |
352 if (rc == NGX_IMAP_PROXY_ERROR) { | |
353 s->connection->read->handler = ngx_imap_proxy_handler; | |
354 s->connection->write->handler = ngx_imap_proxy_handler; | |
355 rev->handler = ngx_imap_proxy_handler; | |
356 c->write->handler = ngx_imap_proxy_handler; | |
357 | |
358 ngx_imap_proxy_handler(c->read); | |
359 return; | 335 return; |
360 } | 336 } |
361 | 337 |
362 switch (s->imap_state) { | 338 switch (s->imap_state) { |
363 | 339 |
423 | 399 |
424 pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module); | 400 pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module); |
425 ngx_add_timer(s->connection->read, pcf->timeout); | 401 ngx_add_timer(s->connection->read, pcf->timeout); |
426 ngx_del_timer(c->read); | 402 ngx_del_timer(c->read); |
427 | 403 |
428 action = c->log->action; | |
429 c->log->action = NULL; | 404 c->log->action = NULL; |
430 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | 405 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); |
431 c->log->action = action; | |
432 | 406 |
433 c->log->action = "proxying"; | 407 c->log->action = "proxying"; |
434 } | 408 } |
435 } | 409 } |
436 | 410 |
472 if (b->last == b->end) { | 446 if (b->last == b->end) { |
473 *(b->last - 1) = '\0'; | 447 *(b->last - 1) = '\0'; |
474 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, | 448 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
475 "upstream sent too long response line: \"%s\"", | 449 "upstream sent too long response line: \"%s\"", |
476 b->pos); | 450 b->pos); |
477 return NGX_IMAP_PROXY_INVALID; | 451 return NGX_ERROR; |
478 } | 452 } |
479 | 453 |
480 return NGX_AGAIN; | 454 return NGX_AGAIN; |
481 } | 455 } |
482 | 456 |
485 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) { | 459 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) { |
486 if (p[0] == '+' && p[1] == 'O' && p[2] == 'K') { | 460 if (p[0] == '+' && p[1] == 'O' && p[2] == 'K') { |
487 return NGX_OK; | 461 return NGX_OK; |
488 } | 462 } |
489 | 463 |
490 if (p[0] == '-' && p[1] == 'E' && p[2] == 'R' && p[3] == 'R') { | |
491 return NGX_IMAP_PROXY_ERROR; | |
492 } | |
493 | |
494 } else { | 464 } else { |
495 if (p[0] == 'N' && p[1] == 'O') { | |
496 return NGX_IMAP_PROXY_ERROR; | |
497 } | |
498 | |
499 if (what == NGX_IMAP_WAIT_OK) { | 465 if (what == NGX_IMAP_WAIT_OK) { |
500 if (p[0] == '*' && p[1] == ' ' && p[2] == 'O' && p[3] == 'K') { | 466 if (p[0] == '*' && p[1] == ' ' && p[2] == 'O' && p[3] == 'K') { |
501 return NGX_OK; | 467 return NGX_OK; |
502 } | 468 } |
503 | 469 |
510 | 476 |
511 *(b->last - 2) = '\0'; | 477 *(b->last - 2) = '\0'; |
512 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, | 478 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
513 "upstream sent invalid response: \"%s\"", p); | 479 "upstream sent invalid response: \"%s\"", p); |
514 | 480 |
515 return NGX_IMAP_PROXY_INVALID; | 481 return NGX_ERROR; |
516 } | 482 } |
517 | 483 |
518 | 484 |
519 static void | 485 static void |
520 ngx_imap_proxy_handler(ngx_event_t *ev) | 486 ngx_imap_proxy_handler(ngx_event_t *ev) |