comparison src/imap/ngx_imap_handler.c @ 92:45945fa8b8ba NGINX_0_2_0

nginx 0.2.0 *) The pid-file names used during online upgrade was changed and now is not required a manual rename operation. The old master process adds the ".oldbin" suffix to its pid-file and executes a new binary file. The new master process creates usual pid-file without the ".newbin" suffix. If the master process exits, then old master process renames back its pid-file with the ".oldbin" suffix to the pid-file without suffix. *) Change: the "worker_connections" directive, new name of the "connections" directive; now the directive specifies maximum number of connections, but not maximum socket descriptor number. *) Feature: SSL supports the session cache inside one worker process. *) Feature: the "satisfy_any" directive. *) Change: the ngx_http_access_module and ngx_http_auth_basic_module do not run for subrequests. *) Feature: the "worker_rlimit_nofile" and "worker_rlimit_sigpending" directives. *) Bugfix: if all backend using in load-balancing failed after one error, then nginx did not try do connect to them during 60 seconds. *) Bugfix: in IMAP/POP3 command argument parsing. Thanks to Rob Mueller. *) Bugfix: errors while using SSL in IMAP/POP3 proxy. *) Bugfix: errors while using SSI and gzipping. *) Bugfix: the "Expires" and "Cache-Control" header lines were omitted from the 304 responses. Thanks to Alexandr Kukushkin.
author Igor Sysoev <http://sysoev.ru>
date Fri, 23 Sep 2005 00:00:00 +0400
parents 71c46860eb55
children ca4f70b3ccc6
comparison
equal deleted inserted replaced
91:c3eee83ea942 92:45945fa8b8ba
31 }; 31 };
32 32
33 static u_char pop3_ok[] = "+OK" CRLF; 33 static u_char pop3_ok[] = "+OK" CRLF;
34 static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF; 34 static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF;
35 35
36 static u_char imap_star[] = "* ";
36 static u_char imap_ok[] = "OK completed" CRLF; 37 static u_char imap_ok[] = "OK completed" CRLF;
37 static u_char imap_next[] = "+ OK" CRLF; 38 static u_char imap_next[] = "+ OK" CRLF;
38 static u_char imap_bye[] = "* BYE" CRLF; 39 static u_char imap_bye[] = "* BYE" CRLF;
39 static u_char imap_invalid_command[] = "BAD invalid command" CRLF; 40 static u_char imap_invalid_command[] = "BAD invalid command" CRLF;
40 41
41 42
42 void 43 void
43 ngx_imap_init_connection(ngx_connection_t *c) 44 ngx_imap_init_connection(ngx_connection_t *c)
44 { 45 {
45 ngx_imap_log_ctx_t *ctx; 46 ngx_imap_log_ctx_t *lctx;
47 #if (NGX_IMAP_SSL)
48 ngx_imap_conf_ctx_t *ctx;
49 ngx_imap_ssl_conf_t *sslcf;
50 #endif
46 51
47 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap init connection"); 52 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap init connection");
48 53
49 ctx = ngx_palloc(c->pool, sizeof(ngx_imap_log_ctx_t)); 54 lctx = ngx_palloc(c->pool, sizeof(ngx_imap_log_ctx_t));
50 if (ctx == NULL) { 55 if (lctx == NULL) {
51 ngx_imap_close_connection(c); 56 ngx_imap_close_connection(c);
52 return; 57 return;
53 } 58 }
54 59
55 ctx->client = &c->addr_text; 60 lctx->client = &c->addr_text;
56 ctx->session = NULL; 61 lctx->session = NULL;
57 62
58 c->log->connection = c->number; 63 c->log->connection = c->number;
59 c->log->handler = ngx_imap_log_error; 64 c->log->handler = ngx_imap_log_error;
60 c->log->data = ctx; 65 c->log->data = lctx;
61 c->log->action = "sending client greeting line"; 66 c->log->action = "sending client greeting line";
62 67
63 c->log_error = NGX_ERROR_INFO; 68 c->log_error = NGX_ERROR_INFO;
69
70 #if (NGX_IMAP_SSL)
71
72 ctx = c->ctx;
73 sslcf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_ssl_module);
74
75 if (sslcf->enable) {
76 if (ngx_ssl_create_connection(sslcf->ssl_ctx, c, 0) == NGX_ERROR) {
77 ngx_imap_close_connection(c);
78 return;
79 }
80
81 c->recv = ngx_ssl_recv;
82 c->send = ngx_ssl_write;
83 c->send_chain = ngx_ssl_send_chain;
84 }
85
86 #endif
64 87
65 ngx_imap_init_session(c->read); 88 ngx_imap_init_session(c->read);
66 } 89 }
67 90
68 91
74 ngx_imap_log_ctx_t *lctx; 97 ngx_imap_log_ctx_t *lctx;
75 ngx_imap_conf_ctx_t *ctx; 98 ngx_imap_conf_ctx_t *ctx;
76 ngx_imap_core_srv_conf_t *cscf; 99 ngx_imap_core_srv_conf_t *cscf;
77 #if (NGX_IMAP_SSL) 100 #if (NGX_IMAP_SSL)
78 ngx_int_t rc; 101 ngx_int_t rc;
79 ngx_imap_ssl_conf_t *sslcf;
80 #endif 102 #endif
81 103
82 c = rev->data; 104 c = rev->data;
83
84 ctx = c->ctx; 105 ctx = c->ctx;
85
86 cscf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_core_module); 106 cscf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_core_module);
87 107
88 #if (NGX_IMAP_SSL) 108 #if (NGX_IMAP_SSL)
89 109
90 sslcf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_ssl_module); 110 if (c->ssl) {
91
92 if (sslcf->enable) {
93
94 if (ngx_ssl_create_session(sslcf->ssl_ctx, c, NGX_SSL_BUFFER)
95 == NGX_ERROR)
96 {
97 ngx_imap_close_connection(c);
98 return;
99 }
100 111
101 rc = ngx_ssl_handshake(c); 112 rc = ngx_ssl_handshake(c);
102 113
103 if (rc == NGX_ERROR) { 114 if (rc == NGX_ERROR) {
104 ngx_imap_close_connection(c); 115 ngx_imap_close_connection(c);
114 } 125 }
115 126
116 return; 127 return;
117 } 128 }
118 129
119 c->recv = ngx_ssl_recv;
120 c->send = ngx_ssl_write;
121 c->send_chain = ngx_ssl_send_chain;
122 } 130 }
123 131
124 #endif 132 #endif
125 133
126 s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)); 134 s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t));
273 281
274 282
275 void 283 void
276 ngx_imap_auth_state(ngx_event_t *rev) 284 ngx_imap_auth_state(ngx_event_t *rev)
277 { 285 {
278 u_char *text, *last, *p; 286 u_char *text, *last, *p, *dst, *src, *end;
279 ssize_t text_len, last_len; 287 ssize_t text_len, last_len;
280 ngx_str_t *arg; 288 ngx_str_t *arg;
281 ngx_int_t rc; 289 ngx_int_t rc;
282 ngx_uint_t tag; 290 ngx_uint_t tag, i;
283 ngx_connection_t *c; 291 ngx_connection_t *c;
284 ngx_imap_session_t *s; 292 ngx_imap_session_t *s;
285 ngx_imap_core_srv_conf_t *cscf; 293 ngx_imap_core_srv_conf_t *cscf;
286 294
287 c = rev->data; 295 c = rev->data;
321 329
322 if (rc == NGX_OK) { 330 if (rc == NGX_OK) {
323 331
324 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth command: %i", 332 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth command: %i",
325 s->command); 333 s->command);
334
335 if (s->backslash) {
336
337 arg = s->args.elts;
338
339 for (i = 0; i < s->args.nelts; i++) {
340 dst = arg[i].data;
341 end = dst + arg[i].len;
342
343 for (src = dst; src < end; dst++) {
344 *dst = *src;
345 if (*src++ == '\\') {
346 *dst = *src++;
347 }
348 }
349
350 arg[i].len = dst - arg[i].data;
351 }
352
353 s->backslash = 0;
354 }
326 355
327 switch (s->command) { 356 switch (s->command) {
328 357
329 case NGX_IMAP_LOGIN: 358 case NGX_IMAP_LOGIN:
330 if (s->args.nelts == 2) { 359 if (s->args.nelts == 2) {
403 last = imap_invalid_command; 432 last = imap_invalid_command;
404 last_len = sizeof(imap_invalid_command) - 1; 433 last_len = sizeof(imap_invalid_command) - 1;
405 } 434 }
406 435
407 if (tag) { 436 if (tag) {
437 if (s->tag.len == 0) {
438 s->tag.len = sizeof(imap_star) - 1;
439 s->tag.data = (u_char *) imap_star;
440 }
441
408 if (s->tagged_line.len < s->tag.len + text_len + last_len) { 442 if (s->tagged_line.len < s->tag.len + text_len + last_len) {
409 s->tagged_line.len = s->tag.len + text_len + last_len; 443 s->tagged_line.len = s->tag.len + text_len + last_len;
410 s->tagged_line.data = ngx_palloc(c->pool, s->tagged_line.len); 444 s->tagged_line.data = ngx_palloc(c->pool, s->tagged_line.len);
411 if (s->tagged_line.data == NULL) { 445 if (s->tagged_line.data == NULL) {
412 ngx_imap_close_connection(c); 446 ngx_imap_close_connection(c);
691 } 725 }
692 } 726 }
693 727
694 #endif 728 #endif
695 729
730 c->closed = 1;
731
696 pool = c->pool; 732 pool = c->pool;
697 733
698 ngx_close_connection(c); 734 ngx_close_connection(c);
699 735
700 ngx_destroy_pool(pool); 736 ngx_destroy_pool(pool);