nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev
17 years ago
90 | 90 | |
91 | 91 | |
92 | 92 | struct ngx_module_s { |
93 | ngx_uint_t ctx_index; | |
94 | ngx_uint_t index; | |
95 | void *ctx; | |
96 | ngx_command_t *commands; | |
97 | ngx_uint_t type; | |
98 | ngx_int_t (*init_module)(ngx_cycle_t *cycle); | |
99 | ngx_int_t (*init_process)(ngx_cycle_t *cycle); | |
93 | ngx_uint_t ctx_index; | |
94 | ngx_uint_t index; | |
95 | void *ctx; | |
96 | ngx_command_t *commands; | |
97 | ngx_uint_t type; | |
98 | ngx_int_t (*init_module)(ngx_cycle_t *cycle); | |
99 | ngx_int_t (*init_process)(ngx_cycle_t *cycle); | |
100 | 100 | #if 0 |
101 | ngx_int_t (*init_thread)(ngx_cycle_t *cycle); | |
101 | ngx_int_t (*init_thread)(ngx_cycle_t *cycle); | |
102 | 102 | #endif |
103 | 103 | }; |
104 | 104 |
393 | 393 | |
394 | 394 | |
395 | 395 | #define NGX_EVENT_MODULE 0x544E5645 /* "EVNT" */ |
396 | #define NGX_EVENT_CONF 0x00200000 | |
396 | #define NGX_EVENT_CONF 0x02000000 | |
397 | 397 | |
398 | 398 | |
399 | 399 | typedef struct { |
417 | 417 | |
418 | 418 | in_port->port = lscf[l].port; |
419 | 419 | |
420 | ngx_test_null(in_port->port_name.data, ngx_palloc(cf->pool, 7), | |
420 | ngx_test_null(in_port->port_text.data, ngx_palloc(cf->pool, 7), | |
421 | 421 | NGX_CONF_ERROR); |
422 | in_port->port_name.len = ngx_snprintf((char *) | |
423 | in_port->port_name.data, | |
422 | in_port->port_text.len = ngx_snprintf((char *) | |
423 | in_port->port_text.data, | |
424 | 424 | 7, ":%d", |
425 | 425 | in_port->port); |
426 | 426 | |
548 | 548 | NGX_CONF_ERROR); |
549 | 549 | |
550 | 550 | inport->port = in_port[p].port; |
551 | inport->port_name = in_port[p].port_name; | |
551 | inport->port_text = in_port[p].port_text; | |
552 | 552 | |
553 | 553 | /* init list of the addresses ... */ |
554 | 554 |
78 | 78 | |
79 | 79 | typedef struct { |
80 | 80 | in_port_t port; |
81 | ngx_str_t port_name; | |
81 | ngx_str_t port_text; | |
82 | 82 | ngx_array_t addrs; /* array of ngx_http_in_addr_t */ |
83 | 83 | } ngx_http_in_port_t; |
84 | 84 |
205 | 205 | + r->server_name->len + r->headers_out.location->value.len + 2; |
206 | 206 | |
207 | 207 | if (r->port != 80) { |
208 | len += r->port_name->len; | |
208 | len += r->port_text->len; | |
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
324 | 324 | b->last = ngx_cpymem(b->last, r->server_name->data, |
325 | 325 | r->server_name->len); |
326 | 326 | if (r->port != 80) { |
327 | b->last = ngx_cpymem(b->last, r->port_name->data, | |
328 | r->port_name->len); | |
327 | b->last = ngx_cpymem(b->last, r->port_text->data, | |
328 | r->port_text->len); | |
329 | 329 | } |
330 | 330 | |
331 | 331 | b->last = ngx_cpymem(b->last, r->headers_out.location->value.data, |
201 | 201 | in_addr = in_port->addrs.elts; |
202 | 202 | |
203 | 203 | r->port = in_port->port; |
204 | r->port_name = &in_port->port_name; | |
204 | r->port_text = &in_port->port_text; | |
205 | 205 | |
206 | 206 | i = 0; |
207 | 207 |
256 | 256 | |
257 | 257 | uint32_t in_addr; |
258 | 258 | ngx_uint_t port; |
259 | ngx_str_t *port_name; /* ":80" */ | |
259 | ngx_str_t *port_text; /* ":80" */ | |
260 | 260 | ngx_str_t *server_name; |
261 | 261 | ngx_array_t *virtual_names; |
262 | 262 |
65 | 65 | #define NGX_IMAP_PROXY_ERROR 11 |
66 | 66 | |
67 | 67 | |
68 | #define NGX_IMAP_MODULE 0x50414D49 /* "IMAP" */ | |
69 | ||
70 | #define NGX_IMAP_CONF 0x02000000 | |
71 | ||
72 | ||
68 | 73 | void ngx_imap_init_connection(ngx_connection_t *c); |
69 | 74 | void ngx_imap_close_connection(ngx_connection_t *c); |
70 | 75 |
57 | 57 | |
58 | 58 | c = rev->data; |
59 | 59 | |
60 | /* TODO: timeout */ | |
60 | if (rev->timedout) { | |
61 | ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
62 | ngx_imap_close_connection(c); | |
63 | return; | |
64 | } | |
61 | 65 | |
62 | 66 | if (!(s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)))) { |
63 | 67 | ngx_imap_close_connection(c); |
101 | 105 | |
102 | 106 | ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "pop3 auth state"); |
103 | 107 | |
104 | /* TODO: timeout */ | |
108 | if (rev->timedout) { | |
109 | ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
110 | ngx_imap_close_connection(c); | |
111 | return; | |
112 | } | |
105 | 113 | |
106 | 114 | rc = ngx_pop3_read_command(s); |
107 | 115 |
40 | 40 | |
41 | 41 | peers->number = 1; |
42 | 42 | peers->max_fails = 1; |
43 | #if 0 | |
43 | 44 | peers->peers[0].addr = inet_addr("81.19.69.70"); |
44 | 45 | peers->peers[0].addr_port_text.len = sizeof("81.19.69.70:110") - 1; |
45 | 46 | peers->peers[0].addr_port_text.data = "81.19.69.70:110"; |
46 | 47 | peers->peers[0].port = htons(110); |
48 | #else | |
49 | peers->peers[0].addr = inet_addr("81.19.64.101"); | |
50 | peers->peers[0].addr_port_text.len = sizeof("81.19.64.101:110") - 1; | |
51 | peers->peers[0].addr_port_text.data = "81.19.64.101:110"; | |
52 | peers->peers[0].port = htons(110); | |
53 | #endif | |
47 | 54 | |
48 | 55 | rc = ngx_event_connect_peer(&p->upstream); |
49 | 56 | |
89 | 96 | |
90 | 97 | c = rev->data; |
91 | 98 | s = c->data; |
99 | ||
100 | if (rev->timedout) { | |
101 | ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
102 | ngx_imap_proxy_close_session(s); | |
103 | return; | |
104 | } | |
92 | 105 | |
93 | 106 | if (s->proxy->buffer == NULL) { |
94 | 107 | s->proxy->buffer = ngx_create_temp_buf(c->pool, /* STUB */ 4096); |
237 | 250 | size_t size; |
238 | 251 | ssize_t n; |
239 | 252 | ngx_buf_t *b; |
240 | ngx_uint_t data, do_write; | |
253 | ngx_uint_t again, do_write; | |
241 | 254 | ngx_connection_t *c, *src, *dst; |
242 | 255 | ngx_imap_session_t *s; |
243 | 256 | |
244 | 257 | c = ev->data; |
245 | 258 | s = c->data; |
246 | 259 | |
260 | if (ev->timedout) { | |
261 | if (c == s->connection) { | |
262 | ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
263 | "client timed out"); | |
264 | } else { | |
265 | ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
266 | "upstream timed out"); | |
267 | } | |
268 | ||
269 | ngx_imap_proxy_close_session(s); | |
270 | return; | |
271 | } | |
272 | ||
247 | 273 | if (c == s->connection) { |
248 | src = c; | |
249 | dst = s->proxy->upstream.connection; | |
250 | b = s->buffer; | |
274 | if (ev->write) { | |
275 | src = s->proxy->upstream.connection; | |
276 | dst = c; | |
277 | b = s->proxy->buffer; | |
278 | ||
279 | } else { | |
280 | src = c; | |
281 | dst = s->proxy->upstream.connection; | |
282 | b = s->buffer; | |
283 | } | |
251 | 284 | |
252 | 285 | } else { |
253 | src = c; | |
254 | dst = s->connection; | |
255 | b = s->proxy->buffer; | |
286 | if (ev->write) { | |
287 | src = s->connection; | |
288 | dst = c; | |
289 | b = s->buffer; | |
290 | ||
291 | } else { | |
292 | src = c; | |
293 | dst = s->connection; | |
294 | b = s->proxy->buffer; | |
295 | } | |
256 | 296 | } |
257 | 297 | |
258 | 298 | do_write = ev->write ? 1 : 0; |
262 | 302 | do_write, src->fd, dst->fd); |
263 | 303 | |
264 | 304 | do { |
265 | data = 0; | |
305 | again = 0; | |
266 | 306 | |
267 | 307 | if (do_write == 1) { |
268 | 308 | |
269 | 309 | size = b->last - b->pos; |
270 | 310 | |
271 | if (dst->write->ready && size) { | |
311 | if (size && dst->write->ready) { | |
272 | 312 | n = ngx_send(dst, b->pos, size); |
273 | 313 | |
274 | 314 | if (n == NGX_ERROR) { |
277 | 317 | } |
278 | 318 | |
279 | 319 | if (n > 0) { |
280 | data = 1; | |
320 | again = 1; | |
281 | 321 | b->pos += n; |
282 | 322 | |
283 | 323 | if (b->pos == b->last) { |
300 | 340 | |
301 | 341 | size = b->end - b->last; |
302 | 342 | |
303 | if (src->read->ready && size) { | |
343 | if (size && src->read->ready) { | |
304 | 344 | n = ngx_recv(src, b->last, size); |
305 | 345 | |
306 | 346 | if (n == NGX_ERROR || n == 0) { |
309 | 349 | } |
310 | 350 | |
311 | 351 | if (n > 0) { |
312 | data = 1; | |
352 | again = 1; | |
313 | 353 | do_write = 1; |
314 | 354 | b->last += n; |
315 | 355 | } |
322 | 362 | } |
323 | 363 | } |
324 | 364 | |
325 | } while (data); | |
365 | } while (again); | |
326 | 366 | } |
327 | 367 | |
328 | 368 |