comparison src/imap/ngx_imap_proxy.c @ 501:d4ea69372b94 release-0.1.25

nginx-0.1.25-RELEASE import *) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author Igor Sysoev <igor@sysoev.ru>
date Sat, 19 Mar 2005 12:38:37 +0000
parents c52408583801
children 9b8c906f6e63
comparison
equal deleted inserted replaced
500:9a0f304470f5 501:d4ea69372b94
11 #include <ngx_imap.h> 11 #include <ngx_imap.h>
12 12
13 13
14 static void ngx_imap_proxy_block_read(ngx_event_t *rev); 14 static void ngx_imap_proxy_block_read(ngx_event_t *rev);
15 static void ngx_imap_proxy_auth_handler(ngx_event_t *rev); 15 static void ngx_imap_proxy_auth_handler(ngx_event_t *rev);
16 static void ngx_imap_proxy_init_handler(ngx_event_t *wev);
17 static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev); 16 static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev);
18 static ngx_int_t ngx_imap_proxy_read_response(ngx_imap_session_t *s); 17 static ngx_int_t ngx_imap_proxy_read_response(ngx_imap_session_t *s);
19 static void ngx_imap_proxy_handler(ngx_event_t *ev); 18 static void ngx_imap_proxy_handler(ngx_event_t *ev);
20 static void ngx_imap_proxy_close_session(ngx_imap_session_t *s); 19 static void ngx_imap_proxy_close_session(ngx_imap_session_t *s);
21 20
25 ngx_int_t rc; 24 ngx_int_t rc;
26 ngx_peers_t *peers; 25 ngx_peers_t *peers;
27 struct sockaddr_in *sin; 26 struct sockaddr_in *sin;
28 ngx_imap_proxy_ctx_t *p; 27 ngx_imap_proxy_ctx_t *p;
29 28
30 if (!(p = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_proxy_ctx_t)))) { 29 p = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_proxy_ctx_t));
30 if (p == NULL) {
31 ngx_imap_close_connection(s->connection); 31 ngx_imap_close_connection(s->connection);
32 return; 32 return;
33 } 33 }
34 34
35 s->proxy = p; 35 s->proxy = p;
36 36
37 /**/ 37 /**/
38 38
39 if (!(peers = ngx_pcalloc(s->connection->pool, sizeof(ngx_peers_t)))) { 39 peers = ngx_pcalloc(s->connection->pool, sizeof(ngx_peers_t));
40 if (peers == NULL) {
40 ngx_imap_close_connection(s->connection); 41 ngx_imap_close_connection(s->connection);
41 return; 42 return;
42 } 43 }
43 44
44 p->upstream.peers = peers; 45 p->upstream.peers = peers;
45 p->upstream.log = s->connection->log; 46 p->upstream.log = s->connection->log;
46 p->upstream.log_error = NGX_ERROR_ERR; 47 p->upstream.log_error = NGX_ERROR_ERR;
47 48
48 if (!(sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in)))) { 49 sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in));
50 if (sin == NULL) {
49 ngx_imap_close_connection(s->connection); 51 ngx_imap_close_connection(s->connection);
50 return; 52 return;
51 } 53 }
52 54
53 peers->peer[0].sockaddr = (struct sockaddr *) sin; 55 peers->peer[0].sockaddr = (struct sockaddr *) sin;
144 if (s->imap_state == ngx_pop3_start) { 146 if (s->imap_state == ngx_pop3_start) {
145 147
146 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user"); 148 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user");
147 149
148 line.len = sizeof("USER ") + s->login.len - 1 + 2; 150 line.len = sizeof("USER ") + s->login.len - 1 + 2;
149 if (!(line.data = ngx_palloc(c->pool, line.len))) { 151 line.data = ngx_palloc(c->pool, line.len);
152 if (line.data == NULL) {
150 ngx_imap_proxy_close_session(s); 153 ngx_imap_proxy_close_session(s);
151 return; 154 return;
152 } 155 }
153 156
154 p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1); 157 p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1);
155 p = ngx_cpymem(p, s->login.data, s->login.len); 158 p = ngx_cpymem(p, s->login.data, s->login.len);
156 *p++ = CR; *p++ = LF; 159 *p++ = CR; *p = LF;
157 160
158 if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) { 161 if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) {
159 /* 162 /*
160 * we treat the incomplete sending as NGX_ERROR 163 * we treat the incomplete sending as NGX_ERROR
161 * because it is very strange here 164 * because it is very strange here
173 } 176 }
174 177
175 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass"); 178 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass");
176 179
177 line.len = sizeof("PASS ") + s->passwd.len - 1 + 2; 180 line.len = sizeof("PASS ") + s->passwd.len - 1 + 2;
178 if (!(line.data = ngx_palloc(c->pool, line.len))) { 181 line.data = ngx_palloc(c->pool, line.len);
182 if (line.data == NULL) {
179 ngx_imap_proxy_close_session(s); 183 ngx_imap_proxy_close_session(s);
180 return; 184 return;
181 } 185 }
182 186
183 p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1); 187 p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1);
184 p = ngx_cpymem(p, s->passwd.data, s->passwd.len); 188 p = ngx_cpymem(p, s->passwd.data, s->passwd.len);
185 *p++ = CR; *p++ = LF; 189 *p++ = CR; *p = LF;
186 190
187 if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) { 191 if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) {
188 /* 192 /*
189 * we treat the incomplete sending as NGX_ERROR 193 * we treat the incomplete sending as NGX_ERROR
190 * because it is very strange here 194 * because it is very strange here