Klaus Demo nginx / 980a924
nginx-0.0.10-2004-09-05-23:54:02 import Igor Sysoev 17 years ago
24 changed file(s) with 343 addition(s) and 225 deletion(s). Raw diff Collapse all Expand all
125125 . $OBJS/auto
126126 fi
127127
128 modules="$CORE_MODULES $EVENT_MODULES $HTTP_MODULES $HTTP_FILTER_MODULES \
129 $HTTP_HEADERS_FILTER_MODULE \
130 $HTTP_COPY_FILTER_MODULE \
131 $HTTP_RANGE_BODY_FILTER_MODULE \
132 $HTTP_NOT_MODIFIED_FILTER_MODULE"
128 modules="$CORE_MODULES $EVENT_MODULES"
129
130 if [ $HTTP = YES ]; then
131 modules="$modules $HTTP_MODULES $HTTP_FILTER_MODULES \
132 $HTTP_HEADERS_FILTER_MODULE \
133 $HTTP_COPY_FILTER_MODULE \
134 $HTTP_RANGE_BODY_FILTER_MODULE \
135 $HTTP_NOT_MODIFIED_FILTER_MODULE"
136 fi
133137
134138
135139 echo "#include <ngx_config.h>" > $NGX_MODULES_C
2828
2929 USE_THREADS=NO
3030
31 HTTP=YES
3132 HTTP_CHARSET=YES
3233 HTTP_GZIP=YES
3334 HTTP_SSL=NO
6970 --prefix=*) PREFIX="$value" ;;
7071 --sbin-path=*) SBIN_PATH="$value" ;;
7172 --conf-path=*) CONF_PATH="$value" ;;
72 --http-log-path=*) HTTP_LOG_PATH="$value" ;;
7373 --error-log-path=*) ERROR_LOG_PATH="$value" ;;
7474 --pid-path=*) PID_PATH="$value" ;;
7575
8686
8787 --with-threads=*) USE_THREADS="$value" ;;
8888 --with-threads) USE_THREADS="pthreads" ;;
89
90 --without-http) HTTP=NO ;;
91 --http-log-path=*) HTTP_LOG_PATH="$value" ;;
8992
9093 --with-http_ssl_module) HTTP_SSL=YES ;;
9194 --without-http_charset_module) HTTP_CHARSET=NO ;;
1919 void *ngx_push_array(ngx_array_t *a);
2020
2121
22 ngx_inline static ngx_int_t ngx_init_array0(ngx_array_t *array, ngx_pool_t *pool,
23 ngx_uint_t n, size_t size)
24 {
25 if (!(array->elts = ngx_palloc(pool, n * size))) {
26 return NGX_ERROR;
27 }
28
29 array->nelts = 0;
30 array->size = size;
31 array->nalloc = n;
32 array->pool = pool;
33
34 return NGX_OK;
35 }
36
37
38
2239 #define ngx_init_array(a, p, n, s, rc) \
2340 ngx_test_null(a.elts, ngx_palloc(p, n * s), rc); \
2441 a.nelts = 0; a.size = s; a.nalloc = n; a.pool = p;
589589 i = 0;
590590 }
591591
592 #if 0
593 file = cycle->open_files.elts;
594 for (i = 0; i < cycle->open_files.nelts; i++) {
595 #endif
596592 if (name->len != file[i].name.len) {
597593 continue;
598594 }
611607
612608 if (name) {
613609 file->name = *name;
610 } else {
611 file->name.len = 0;
612 file->name.data = NULL;
614613 }
615614
616615 return file;
2222 /* STUB NAME */
2323 static ngx_connection_t dumb;
2424 /* STUB */
25
26 static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
2527
2628
2729 ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
7880 n = 20;
7981 }
8082
81 cycle->open_files.part.elts = ngx_palloc(pool, n * sizeof(ngx_open_file_t));
82 if (cycle->open_files.part.elts == NULL) {
83 ngx_destroy_pool(pool);
84 return NULL;
85 }
86 cycle->open_files.part.nelts = 0;
87 cycle->open_files.part.next = NULL;
88 cycle->open_files.last = &cycle->open_files.part;
89 cycle->open_files.size = sizeof(ngx_open_file_t);
90 cycle->open_files.nalloc = n;
91 cycle->open_files.pool = pool;
92
93
94 #if 0
95 n = old_cycle->open_files.nelts ? old_cycle->open_files.nelts : 20;
96 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t));
97 if (cycle->open_files.elts == NULL) {
98 ngx_destroy_pool(pool);
99 return NULL;
100 }
101 cycle->open_files.nelts = 0;
102 cycle->open_files.size = sizeof(ngx_open_file_t);
103 cycle->open_files.nalloc = n;
104 cycle->open_files.pool = pool;
105 #endif
83 if (ngx_init_list(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))
84 == NGX_ERROR)
85 {
86 ngx_destroy_pool(pool);
87 return NULL;
88 }
10689
10790
10891 if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) {
10992 ngx_destroy_pool(pool);
11093 return NULL;
11194 }
95
96 cycle->new_log->file->name = error_log;
11297
11398
11499 n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
220205 i = 0;
221206 }
222207
223 #if 0
224 file = cycle->open_files.elts;
225 for (i = 0; i < cycle->open_files.nelts; i++) {
226 #endif
227
228208 if (file[i].name.data == NULL) {
229209 continue;
230210 }
233213 NGX_FILE_RDWR,
234214 NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
235215
216 #if 0
236217 log->log_level = NGX_LOG_DEBUG_ALL;
218 #endif
237219 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
238220 "log: %0X %d \"%s\"",
239221 &file[i], file[i].fd, file[i].name.data);
268250
269251 cycle->log = cycle->new_log;
270252 pool->log = cycle->new_log;
253
254 if (cycle->log->log_level == 0) {
255 cycle->log->log_level = NGX_LOG_ERR;
256 }
271257
272258 if (!failed) {
273259 if (old_cycle->listening.nelts) {
334320
335321 #if !(WIN32)
336322
337 if (!failed && !ngx_test_config) {
323 if (!failed && !ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
338324
339325 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
340326 "dup2: %0X %d \"%s\"",
368354 i = 0;
369355 }
370356
371 #if 0
372 file = cycle->open_files.elts;
373 for (i = 0; i < cycle->open_files.nelts; i++) {
374 #endif
375
376357 if (file[i].fd == NGX_INVALID_FILE) {
377358 continue;
378359 }
454435 file = part->elts;
455436 i = 0;
456437 }
457
458 #if 0
459 file = old_cycle->open_files.elts;
460 for (i = 0; i < old_cycle->open_files.nelts; i++) {
461 #endif
462438
463439 if (file[i].fd == NGX_INVALID_FILE) {
464440 continue;
638614 i = 0;
639615 }
640616
641 #if 0
642 file = cycle->open_files.elts;
643 for (i = 0; i < cycle->open_files.nelts; i++) {
644 #endif
645
646617 if (file[i].name.data == NULL) {
647618 continue;
648619 }
714685
715686 #if !(WIN32)
716687
717 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
718 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
719 "dup2(STDERR) failed");
688 if (cycle->log->file->fd != STDERR_FILENO) {
689 if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {
690 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
691 "dup2(STDERR) failed");
692 }
720693 }
721694
722695 #endif
2323 } ngx_list_t;
2424
2525
26 #define ngx_init_list(l, p, n, s, rc) \
27 if (!(l.part.elts = ngx_palloc(p, n * s))) { \
28 return rc; \
29 } \
30 l.part.nelts = 0; l.part.next = NULL; \
31 l.last = &l.part; l.size = s; l.nalloc = n; l.pool = p;
26 ngx_inline static ngx_int_t ngx_init_list(ngx_list_t *list, ngx_pool_t *pool,
27 ngx_uint_t n, size_t size)
28 {
29 if (!(list->part.elts = ngx_palloc(pool, n * size))) {
30 return NGX_ERROR;
31 }
32
33 list->part.nelts = 0;
34 list->part.next = NULL;
35 list->last = &list->part;
36 list->size = size;
37 list->nalloc = n;
38 list->pool = pool;
39
40 return NGX_OK;
41 }
3242
3343
34 #define ngx_iterate_list(p, i) \
35 for ( ;; i++) { \
36 if (i >= p->nelts) { \
37 if (p->next == NULL) { \
38 break; \
39 } \
40 p = p->next; i = 0; \
41 }
44 /*
45 *
46 * the iteration through the list:
47 *
48 * part = &list.part;
49 * data = part->elts;
50 *
51 * for (i = 0 ;; i++) {
52 *
53 * if (i >= part->nelts) {
54 * if (part->next == NULL) {
55 * break;
56 * }
57 *
58 * part = part->next;
59 * data = part->elts;
60 * i = 0;
61 * }
62 *
63 * ... data[i] ...
64 *
65 * }
66 */
4267
4368
4469 void *ngx_push_list(ngx_list_t *list);
3636 };
3737
3838
39 static ngx_log_t ngx_log;
3940 static ngx_open_file_t ngx_stderr;
40 static ngx_log_t ngx_log;
4141
4242
4343 static const char *err_levels[] = {
295295 name = NULL;
296296 }
297297
298 ngx_test_null(log, ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)), NULL);
299 ngx_test_null(log->file, ngx_conf_open_file(cycle, name), NULL);
298 if (!(log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)))) {
299 return NULL;
300 }
301
302 if (!(log->file = ngx_conf_open_file(cycle, name))) {
303 return NULL;
304 }
300305
301306 return log;
302307 }
362367 value = cf->args->elts;
363368
364369 if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
365 cf->cycle->new_log->file = &ngx_stderr;
370 cf->cycle->new_log->file->fd = ngx_stderr.fd;
371 cf->cycle->new_log->file->name.len = 0;
372 cf->cycle->new_log->file->name.data = NULL;
366373
367374 } else {
368375 cf->cycle->new_log->file->name = value[1];
296296 sizeof(ngx_http_gzip_ctx_t), NGX_ERROR);
297297 ctx->request = r;
298298
299 r->headers_out.content_encoding =
300 ngx_http_add_header(&r->headers_out, ngx_http_headers_out);
299 r->headers_out.content_encoding = ngx_push_list(&r->headers_out.headers);
301300 if (r->headers_out.content_encoding == NULL) {
302301 return NGX_ERROR;
303302 }
7474
7575 if (conf->expires != NGX_HTTP_EXPIRES_OFF) {
7676
77 expires = ngx_http_add_header(&r->headers_out, ngx_http_headers_out);
78 if (expires == NULL) {
77 if (!(expires = ngx_push_list(&r->headers_out.headers))) {
7978 return NGX_ERROR;
8079 }
8180
8281 r->headers_out.expires = expires;
8382
84 cc = ngx_http_add_header(&r->headers_out, ngx_http_headers_out);
85 if (cc == NULL) {
83 if (!(cc = ngx_push_list(&r->headers_out.headers))) {
8684 return NGX_ERROR;
8785 }
8886
122122 || ngx_strncasecmp(r->headers_in.range->value.data, "bytes=", 6) != 0)
123123 {
124124
125 if (!(r->headers_out.accept_ranges =
126 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
127 {
125 r->headers_out.accept_ranges = ngx_push_list(&r->headers_out.headers);
126 if (r->headers_out.accept_ranges == NULL) {
128127 return NGX_ERROR;
129128 }
130129
244243 r->headers_out.status = rc;
245244 r->headers_out.ranges.nelts = 0;
246245
247 if (!(r->headers_out.content_range =
248 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
249 {
246 r->headers_out.content_range = ngx_push_list(&r->headers_out.headers);
247 if (r->headers_out.content_range == NULL) {
250248 return NGX_ERROR;
251249 }
252250
253251 r->headers_out.content_range->key.len = sizeof("Content-Range") - 1;
254252 r->headers_out.content_range->key.data = (u_char *) "Content-Range";
255253
256 ngx_test_null(r->headers_out.content_range->value.data,
257 ngx_palloc(r->pool, 8 + 20 + 1),
258 NGX_ERROR);
254 r->headers_out.content_range->value.data =
255 ngx_palloc(r->pool, 8 + 20 + 1);
256 if (r->headers_out.content_range->value.data == NULL) {
257 return NGX_ERROR;
258 }
259259
260260 r->headers_out.content_range->value.len =
261261 ngx_snprintf((char *) r->headers_out.content_range->value.data,
275275
276276 if (r->headers_out.ranges.nelts == 1) {
277277
278 if (!(r->headers_out.content_range =
279 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
280 {
278 r->headers_out.content_range =
279 ngx_push_list(&r->headers_out.headers);
280 if (r->headers_out.content_range == NULL) {
281281 return NGX_ERROR;
282282 }
283283
340340 *last++ = '/';
341341 *last = '\0';
342342
343 if (!(r->headers_out.location =
344 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
343 if (!(r->headers_out.location = ngx_push_list(&r->headers_out.headers)))
345344 {
346345 return NGX_HTTP_INTERNAL_SERVER_ERROR;
347346 }
6969 return rc;
7070 }
7171
72 if (!(r->headers_out.content_type =
73 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
72 if (!(r->headers_out.content_type = ngx_push_list(&r->headers_out.headers)))
7473 {
7574 return NGX_HTTP_INTERNAL_SERVER_ERROR;
7675 }
195195 ngx_http_userid_ctx_t *ctx,
196196 ngx_http_userid_conf_t *conf)
197197 {
198 u_char *start, *last, *end;
199 ngx_uint_t *cookies, i;
200 ngx_str_t src, dst;
201 ngx_table_elt_t *headers;
202
203 headers = r->headers_in.headers.elts;
198 u_char *start, *last, *end;
199 ngx_uint_t i;
200 ngx_str_t src, dst;
201 ngx_table_elt_t **cookies;
202
204203 cookies = r->headers_in.cookies.elts;
205204
206205 for (i = 0; i < r->headers_in.cookies.nelts; i++) {
207 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
208 "cookie: %d:\"%s\"",
209 cookies[i],
210 headers[cookies[i]].value.data);
211
212 end = headers[cookies[i]].value.data + headers[cookies[i]].value.len;
213
214 for (start = headers[cookies[i]].value.data; start < end; /* void */) {
215
216 if (conf->name.len >= headers[cookies[i]].value.len
206 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
207 "cookie: \"%s\"", cookies[i]->value.data);
208
209 end = cookies[i]->value.data + cookies[i]->value.len;
210
211 for (start = cookies[i]->value.data; start < end; /* void */) {
212
213 if (conf->name.len >= cookies[i]->value.len
217214 || ngx_strncmp(start, conf->name.data, conf->name.len) != 0)
218215 {
219216 start += conf->name.len;
240237 if (last - start < 22) {
241238 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
242239 "client sent too short userid cookie \"%s\"",
243 headers[cookies[i]].value.data);
240 cookies[i]->value.data);
244241 break;
245242 }
246243
257254 if (ngx_decode_base64(&src, &dst) == NGX_ERROR) {
258255 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
259256 "client sent invalid userid cookie \"%s\"",
260 headers[cookies[i]].value.data);
257 cookies[i]->value.data);
261258 break;
262259 }
263260
383380 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
384381 "uid cookie: \"%s\"", cookie);
385382
386 set_cookie = ngx_http_add_header(&r->headers_out, ngx_http_headers_out);
387 if (set_cookie == NULL) {
383 if (!(set_cookie = ngx_push_list(&r->headers_out.headers))) {
388384 return NGX_ERROR;
389385 }
390386
112112 ngx_uint_t i;
113113 ngx_buf_t *b;
114114 ngx_chain_t *chain;
115 ngx_list_part_t *part;
115116 ngx_table_elt_t *header;
116117 ngx_http_request_t *r;
117118 ngx_http_proxy_upstream_conf_t *uc;
164165 }
165166
166167
167 header = r->headers_in.headers.elts;
168 for (i = 0; i < r->headers_in.headers.nelts; i++) {
168 part = &r->headers_in.headers.part;
169 header = part->elts;
170
171 for (i = 0; /* void */; i++) {
172
173 if (i >= part->nelts) {
174 if (part->next == NULL) {
175 break;
176 }
177
178 part = part->next;
179 header = part->elts;
180 i = 0;
181 }
169182
170183 if (&header[i] == r->headers_in.host) {
171184 continue;
273286 }
274287
275288
276 for (i = 0; i < r->headers_in.headers.nelts; i++) {
289 part = &r->headers_in.headers.part;
290 header = part->elts;
291
292 for (i = 0; /* void */; i++) {
293
294 if (i >= part->nelts) {
295 if (part->next == NULL) {
296 break;
297 }
298
299 part = part->next;
300 header = part->elts;
301 i = 0;
302 }
277303
278304 if (&header[i] == r->headers_in.host) {
279305 continue;
530530
531531
532532 if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
533 if (!(r->headers_out.location =
534 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
533 if (!(r->headers_out.location = ngx_push_list(&r->headers_out.headers)))
535534 {
536535 return NGX_HTTP_INTERNAL_SERVER_ERROR;
537536 }
673672 ngx_http_type_t *type;
674673 ngx_http_core_loc_conf_t *clcf;
675674
676 if (!(r->headers_out.content_type =
677 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
675 if (!(r->headers_out.content_type = ngx_push_list(&r->headers_out.headers)))
678676 {
679677 return NGX_HTTP_INTERNAL_SERVER_ERROR;
680678 }
9191
9292 static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r)
9393 {
94 u_char *p;
95 size_t len;
96 ngx_uint_t status, i;
97 ngx_buf_t *b;
98 ngx_chain_t *ln;
99 ngx_table_elt_t *header;
94 u_char *p;
95 size_t len;
96 ngx_uint_t status, i;
97 ngx_buf_t *b;
98 ngx_chain_t *ln;
99 ngx_list_part_t *part;
100 ngx_table_elt_t *header;
100101
101102 if (r->http_version < NGX_HTTP_VERSION_10) {
102103 return NGX_OK;
204205 len += sizeof("Connection: closed" CRLF) - 1;
205206 }
206207
208 part = &r->headers_out.headers.part;
209 header = part->elts;
210
211 for (i = 0; /* void */; i++) {
212
213 if (i >= part->nelts) {
214 if (part->next == NULL) {
215 break;
216 }
217
218 part = part->next;
219 header = part->elts;
220 i = 0;
221 }
222
223 #if 0
207224 header = r->headers_out.headers.elts;
208225 for (i = 0; i < r->headers_out.headers.nelts; i++) {
226 #endif
227
209228 if (header[i].key.len == 0) {
210229 continue;
211230 }
320339 sizeof("Connection: close" CRLF) - 1);
321340 }
322341
342 part = &r->headers_out.headers.part;
343 header = part->elts;
344
345 for (i = 0; /* void */; i++) {
346
347 if (i >= part->nelts) {
348 if (part->next == NULL) {
349 break;
350 }
351
352 part = part->next;
353 header = part->elts;
354 i = 0;
355 }
356
357 #if 0
323358 for (i = 0; i < r->headers_out.headers.nelts; i++) {
359 #endif
360
324361 if (header[i].key.len == 0) {
325362 continue;
326363 }
9393 };
9494
9595
96 static ngx_str_t http_access_log = ngx_string("access.log");
96 static ngx_str_t http_access_log = ngx_string(NGX_HTTP_LOG_PATH);
9797
9898
9999 static ngx_str_t ngx_http_combined_fmt =
338338 {
339339 ngx_uint_t i;
340340 ngx_str_t *s;
341 ngx_list_part_t *part;
341342 ngx_table_elt_t *h;
342343
343344 s = (ngx_str_t *) data;
344345
345 h = r->headers_in.headers.elts;
346 for (i = 0; i < r->headers_in.headers.nelts; i++) {
346 part = &r->headers_in.headers.part;
347 h = part->elts;
348
349 for (i = 0; /* void */; i++) {
350
351 if (i >= part->nelts) {
352 if (part->next == NULL) {
353 break;
354 }
355
356 part = part->next;
357 h = part->elts;
358 i = 0;
359 }
360
347361 if (h[i].key.len != s->len) {
348362 continue;
349363 }
546560 {
547561 ngx_uint_t i;
548562 ngx_str_t *s;
563 ngx_list_part_t *part;
549564 ngx_table_elt_t *h;
550565
551566 s = (ngx_str_t *) data;
552567
553 h = r->headers_out.headers.elts;
554 for (i = 0; i < r->headers_out.headers.nelts; i++) {
568 part = &r->headers_out.headers.part;
569 h = part->elts;
570
571 for (i = 0; /* void */; i++) {
572
573 if (i >= part->nelts) {
574 if (part->next == NULL) {
575 break;
576 }
577
578 part = part->next;
579 h = part->elts;
580 i = 0;
581 }
582
555583 if (h[i].key.len != s->len) {
556584 continue;
557585 }
3939
4040 "client %s sent invalid header, URL: %s",
4141 "client %s sent too long header line, URL: %s",
42 "client %s sent too many headers, URL: %s",
4243 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s",
4344 "client %s sent invalid \"Content-Length\" header, URL: %s",
4445 "client %s sent POST method without \"Content-Length\" header, URL: %s",
308309 r->cleanup.pool = r->pool;
309310
310311
312 if (ngx_init_list(&r->headers_out.headers, r->pool, 2,
313 sizeof(ngx_table_elt_t)) == NGX_ERROR)
314 {
315 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
316 ngx_http_close_connection(c);
317 return;
318 }
319
320
321 #if 0
311322 /* init the r->headers_out.headers table */
312323
313324 r->headers_out.headers.elts = ngx_pcalloc(r->pool,
321332 r->headers_out.headers.nalloc = 20;
322333 r->headers_out.headers.size = sizeof(ngx_table_elt_t);
323334 r->headers_out.headers.pool = r->pool;
335 #endif
324336
325337
326338 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
606618 }
607619
608620
609 /* init the r->headers_in.headers table */
610
611 r->headers_in.headers.elts = ngx_pcalloc(r->pool,
612 20 * sizeof(ngx_table_elt_t));
613 if (r->headers_in.headers.elts == NULL) {
621 if (ngx_init_list(&r->headers_in.headers, r->pool, 2,
622 sizeof(ngx_table_elt_t)) == NGX_ERROR)
623 {
614624 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
615625 ngx_http_close_connection(c);
616626 return;
617627 }
618628
619 /* r->headers_in.headers.nelts = 0; */
620 r->headers_in.headers.size = sizeof(ngx_table_elt_t);
621 r->headers_in.headers.nalloc = 20;
622 r->headers_in.headers.pool = r->pool;
623
624
625 /* init the r->headers_in.cookies array */
626
627 r->headers_in.cookies.elts = ngx_pcalloc(r->pool,
628 5 * sizeof(ngx_uint_t));
629 if (r->headers_in.cookies.elts == NULL) {
629
630 if (ngx_init_array0(&r->headers_in.cookies, r->pool, 5,
631 sizeof(ngx_table_elt_t *)) == NGX_ERROR)
632 {
630633 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
631634 ngx_http_close_connection(c);
632635 return;
633636 }
634
635 /* r->headers_in.cookies.nelts = 0; */
636 r->headers_in.cookies.size = sizeof(ngx_uint_t);
637 r->headers_in.cookies.nalloc = 5;
638 r->headers_in.cookies.pool = r->pool;
639637
640638
641639 ctx = c->log->data;
730728 {
731729 ssize_t n;
732730 ngx_int_t rc, i, offset;
733 ngx_uint_t *cookie;
734 ngx_table_elt_t *h;
731 ngx_table_elt_t *h, **cookie;
735732 ngx_connection_t *c;
736733 ngx_http_request_t *r;
737734 ngx_http_core_srv_conf_t *cscf;
760757 }
761758 }
762759
760 if (r->headers_n > 100) {
761 ngx_http_client_error(r, NGX_HTTP_PARSE_TOO_MANY_HEADERS,
762 NGX_HTTP_BAD_REQUEST);
763 return;
764 }
765
763766 rc = ngx_http_parse_header_line(r, r->header_in);
764767
765768 if (rc == NGX_OK) {
766769
767770 /* a header line has been parsed successfully */
768771
769 h = ngx_http_add_header(&r->headers_in, ngx_http_headers_in);
770 if (h == NULL) {
772 r->headers_n++;
773
774 if (!(h = ngx_push_list(&r->headers_in.headers))) {
771775 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
772776 ngx_http_close_connection(c);
773777 return;
808812 return;
809813 }
810814
811 *cookie = r->headers_in.headers.nelts - 1;
815 *cookie = h;
812816
813817 } else {
814818
13681372
13691373 static void ngx_http_read_discarded_body_event(ngx_event_t *rev)
13701374 {
1371 int rc;
1375 ngx_int_t rc;
13721376 ngx_connection_t *c;
13731377 ngx_http_request_t *r;
13741378
14451449
14461450 static void ngx_http_set_keepalive(ngx_http_request_t *r)
14471451 {
1448 int len;
1452 size_t len;
14491453 ngx_buf_t *b;
14501454 ngx_event_t *rev, *wev;
14511455 ngx_connection_t *c;
2727 #define NGX_HTTP_PARSE_HEADER_ERROR 14
2828 #define NGX_HTTP_PARSE_INVALID_HEADER 14
2929 #define NGX_HTTP_PARSE_TOO_LONG_HEADER 15
30 #define NGX_HTTP_PARSE_NO_HOST_HEADER 16
31 #define NGX_HTTP_PARSE_INVALID_CL_HEADER 17
32 #define NGX_HTTP_PARSE_POST_WO_CL_HEADER 18
33 #define NGX_HTTP_PARSE_HTTP_TO_HTTPS 19
34 #define NGX_HTTP_PARSE_INVALID_HOST 20
30 #define NGX_HTTP_PARSE_TOO_MANY_HEADERS 16
31 #define NGX_HTTP_PARSE_NO_HOST_HEADER 17
32 #define NGX_HTTP_PARSE_INVALID_CL_HEADER 18
33 #define NGX_HTTP_PARSE_POST_WO_CL_HEADER 19
34 #define NGX_HTTP_PARSE_HTTP_TO_HTTPS 20
35 #define NGX_HTTP_PARSE_INVALID_HOST 21
3536
3637
3738 #define NGX_HTTP_OK 200
113114
114115
115116 typedef struct {
116 ngx_table_t headers; /* it must be first field */
117 ngx_list_t headers;
117118
118119 ngx_table_elt_t *host;
119120 ngx_table_elt_t *connection;
157158
158159
159160 typedef struct {
161 ngx_list_t headers;
162 #if 0
160163 ngx_table_t headers; /* it must be first field */
164 #endif
161165
162166 ngx_uint_t status;
163167 ngx_str_t status_line;
305309 unsigned filter_ssi_need_in_memory:1;
306310 unsigned filter_need_temporary:1;
307311 unsigned filter_allow_ranges:1;
312
313 ngx_uint_t headers_n;
308314
309315 /* used to parse HTTP headers */
310316 ngx_int_t state;
282282 }
283283
284284 if (!(r->headers_out.content_type =
285 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
285 ngx_push_list(&r->headers_out.headers)))
286286 {
287287 return NGX_ERROR;
288288 }
0
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_event.h>
4
5
6 static ngx_command_t ngx_imap_commands[] = {
7
8 { ngx_string("imap"),
9 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
10 ngx_imap_block,
11 0,
12 0,
13 NULL },
14
15 ngx_null_command
16 };
17
18
19 static ngx_core_module_t ngx_imap_module_ctx = {
20 ngx_string("imap"),
21 NULL,
22 NULL
23 };
24
25
26 ngx_module_t ngx_imap_module = {
27 NGX_MODULE,
28 &ngx_imap_module_ctx, /* module context */
29 ngx_imap_commands, /* module directives */
30 NGX_CORE_MODULE, /* module type */
31 NULL, /* init module */
32 NULL /* init child */
33 };
0
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_event.h>
4
5
6 void ngx_imap_init_connection(ngx_connection_t *c)
7 {
8 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
9 "imap init connection");
10
11 if (ngx_close_socket(c->fd) == -1) {
12
13 /* we use ngx_cycle->log because c->log was in c->pool */
14
15 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
16 ngx_close_socket_n " failed");
17 }
18 }
+0
-34
src/imap/ngx_imap_proxy.c less more
0
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_event.h>
4
5
6 static ngx_command_t ngx_imap_commands[] = {
7
8 { ngx_string("imap"),
9 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
10 ngx_imap_block,
11 0,
12 0,
13 NULL },
14
15 ngx_null_command
16 };
17
18
19 static ngx_core_module_t ngx_imap_module_ctx = {
20 ngx_string("imap"),
21 NULL,
22 NULL
23 };
24
25
26 ngx_module_t ngx_imap_module = {
27 NGX_MODULE,
28 &ngx_imap_module_ctx, /* module context */
29 ngx_imap_commands, /* module directives */
30 NGX_CORE_MODULE, /* module type */
31 NULL, /* init module */
32 NULL /* init child */
33 };
+0
-19
src/imap/ngx_imap_proxy_handler.c less more
0
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_event.h>
4
5
6 void ngx_imap_proxy_init_connection(ngx_connection_t *c)
7 {
8 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
9 "imap proxy init connection");
10
11 if (ngx_close_socket(c->fd) == -1) {
12
13 /* we use ngx_cycle->log because c->log was in c->pool */
14
15 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
16 ngx_close_socket_n " failed");
17 }
18 }