Klaus Demo nginx / 0292cbb
nginx-0.0.10-2004-09-13-20:18:09 import Igor Sysoev 17 years ago
10 changed file(s) with 87 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
9090
9191
9292 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);
100100 #if 0
101 ngx_int_t (*init_thread)(ngx_cycle_t *cycle);
101 ngx_int_t (*init_thread)(ngx_cycle_t *cycle);
102102 #endif
103103 };
104104
393393
394394
395395 #define NGX_EVENT_MODULE 0x544E5645 /* "EVNT" */
396 #define NGX_EVENT_CONF 0x00200000
396 #define NGX_EVENT_CONF 0x02000000
397397
398398
399399 typedef struct {
417417
418418 in_port->port = lscf[l].port;
419419
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),
421421 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,
424424 7, ":%d",
425425 in_port->port);
426426
548548 NGX_CONF_ERROR);
549549
550550 inport->port = in_port[p].port;
551 inport->port_name = in_port[p].port_name;
551 inport->port_text = in_port[p].port_text;
552552
553553 /* init list of the addresses ... */
554554
7878
7979 typedef struct {
8080 in_port_t port;
81 ngx_str_t port_name;
81 ngx_str_t port_text;
8282 ngx_array_t addrs; /* array of ngx_http_in_addr_t */
8383 } ngx_http_in_port_t;
8484
205205 + r->server_name->len + r->headers_out.location->value.len + 2;
206206
207207 if (r->port != 80) {
208 len += r->port_name->len;
208 len += r->port_text->len;
209209 }
210210 }
211211
324324 b->last = ngx_cpymem(b->last, r->server_name->data,
325325 r->server_name->len);
326326 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);
329329 }
330330
331331 b->last = ngx_cpymem(b->last, r->headers_out.location->value.data,
201201 in_addr = in_port->addrs.elts;
202202
203203 r->port = in_port->port;
204 r->port_name = &in_port->port_name;
204 r->port_text = &in_port->port_text;
205205
206206 i = 0;
207207
256256
257257 uint32_t in_addr;
258258 ngx_uint_t port;
259 ngx_str_t *port_name; /* ":80" */
259 ngx_str_t *port_text; /* ":80" */
260260 ngx_str_t *server_name;
261261 ngx_array_t *virtual_names;
262262
6565 #define NGX_IMAP_PROXY_ERROR 11
6666
6767
68 #define NGX_IMAP_MODULE 0x50414D49 /* "IMAP" */
69
70 #define NGX_IMAP_CONF 0x02000000
71
72
6873 void ngx_imap_init_connection(ngx_connection_t *c);
6974 void ngx_imap_close_connection(ngx_connection_t *c);
7075
5757
5858 c = rev->data;
5959
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 }
6165
6266 if (!(s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)))) {
6367 ngx_imap_close_connection(c);
101105
102106 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "pop3 auth state");
103107
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 }
105113
106114 rc = ngx_pop3_read_command(s);
107115
4040
4141 peers->number = 1;
4242 peers->max_fails = 1;
43 #if 0
4344 peers->peers[0].addr = inet_addr("81.19.69.70");
4445 peers->peers[0].addr_port_text.len = sizeof("81.19.69.70:110") - 1;
4546 peers->peers[0].addr_port_text.data = "81.19.69.70:110";
4647 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
4754
4855 rc = ngx_event_connect_peer(&p->upstream);
4956
8996
9097 c = rev->data;
9198 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 }
92105
93106 if (s->proxy->buffer == NULL) {
94107 s->proxy->buffer = ngx_create_temp_buf(c->pool, /* STUB */ 4096);
237250 size_t size;
238251 ssize_t n;
239252 ngx_buf_t *b;
240 ngx_uint_t data, do_write;
253 ngx_uint_t again, do_write;
241254 ngx_connection_t *c, *src, *dst;
242255 ngx_imap_session_t *s;
243256
244257 c = ev->data;
245258 s = c->data;
246259
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
247273 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 }
251284
252285 } 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 }
256296 }
257297
258298 do_write = ev->write ? 1 : 0;
262302 do_write, src->fd, dst->fd);
263303
264304 do {
265 data = 0;
305 again = 0;
266306
267307 if (do_write == 1) {
268308
269309 size = b->last - b->pos;
270310
271 if (dst->write->ready && size) {
311 if (size && dst->write->ready) {
272312 n = ngx_send(dst, b->pos, size);
273313
274314 if (n == NGX_ERROR) {
277317 }
278318
279319 if (n > 0) {
280 data = 1;
320 again = 1;
281321 b->pos += n;
282322
283323 if (b->pos == b->last) {
300340
301341 size = b->end - b->last;
302342
303 if (src->read->ready && size) {
343 if (size && src->read->ready) {
304344 n = ngx_recv(src, b->last, size);
305345
306346 if (n == NGX_ERROR || n == 0) {
309349 }
310350
311351 if (n > 0) {
312 data = 1;
352 again = 1;
313353 do_write = 1;
314354 b->last += n;
315355 }
322362 }
323363 }
324364
325 } while (data);
365 } while (again);
326366 }
327367
328368