comparison src/http/modules/ngx_http_range_filter.c @ 343:6bdf858bff8c

nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
author Igor Sysoev <igor@sysoev.ru>
date Fri, 28 May 2004 15:49:23 +0000
parents d4241d7787fe
children 55e496a8ece3
comparison
equal deleted inserted replaced
342:0ee0642af5f1 343:6bdf858bff8c
404 404
405 static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, 405 static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r,
406 ngx_chain_t *in) 406 ngx_chain_t *in)
407 { 407 {
408 ngx_uint_t i; 408 ngx_uint_t i;
409 ngx_hunk_t *h; 409 ngx_buf_t *b;
410 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; 410 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll;
411 ngx_http_range_t *range; 411 ngx_http_range_t *range;
412 ngx_http_range_filter_ctx_t *ctx; 412 ngx_http_range_filter_ctx_t *ctx;
413 413
414 if (r->headers_out.ranges.nelts == 0) { 414 if (r->headers_out.ranges.nelts == 0) {
415 return ngx_http_next_body_filter(r, in); 415 return ngx_http_next_body_filter(r, in);
416 } 416 }
417 417
418 /* 418 /*
419 * the optimized version for the static files only 419 * the optimized version for the static files only
420 * that are passed in the single file hunk 420 * that are passed in the single file buf
421 */ 421 */
422 422
423 if (in 423 if (in && in->buf->in_file && in->buf->last_buf) {
424 && in->hunk->type & NGX_HUNK_FILE
425 && in->hunk->type & NGX_HUNK_LAST)
426 {
427 range = r->headers_out.ranges.elts; 424 range = r->headers_out.ranges.elts;
428 425
429 if (r->headers_out.ranges.nelts == 1) { 426 if (r->headers_out.ranges.nelts == 1) {
430 in->hunk->file_pos = range->start; 427 in->buf->file_pos = range->start;
431 in->hunk->file_last = range->end; 428 in->buf->file_last = range->end;
432 429
433 return ngx_http_next_body_filter(r, in); 430 return ngx_http_next_body_filter(r, in);
434 } 431 }
435 432
436 ctx = ngx_http_get_module_ctx(r, ngx_http_range_body_filter_module); 433 ctx = ngx_http_get_module_ctx(r, ngx_http_range_body_filter_module);
444 * "--0123456789" CRLF 441 * "--0123456789" CRLF
445 * "Content-Type: image/jpeg" CRLF 442 * "Content-Type: image/jpeg" CRLF
446 * "Content-Range: bytes " 443 * "Content-Range: bytes "
447 */ 444 */
448 445
449 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 446 ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
450 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; 447 b->memory = 1;
451 h->pos = ctx->boundary_header.data; 448 b->pos = ctx->boundary_header.data;
452 h->last = ctx->boundary_header.data + ctx->boundary_header.len; 449 b->last = ctx->boundary_header.data + ctx->boundary_header.len;
453 450
454 ngx_test_null(hcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); 451 ngx_test_null(hcl, ngx_alloc_chain_link(r->pool), NGX_ERROR);
455 hcl->hunk = h; 452 hcl->buf = b;
456 453
457 /* "SSSS-EEEE/TTTT" CRLF CRLF */ 454 /* "SSSS-EEEE/TTTT" CRLF CRLF */
458 455
459 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 456 ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
460 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; 457 b->temporary = 1;
461 h->pos = range[i].content_range.data; 458 b->pos = range[i].content_range.data;
462 h->last = range[i].content_range.data + range[i].content_range.len; 459 b->last = range[i].content_range.data + range[i].content_range.len;
463 460
464 ngx_test_null(rcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); 461 ngx_test_null(rcl, ngx_alloc_chain_link(r->pool), NGX_ERROR);
465 rcl->hunk = h; 462 rcl->buf = b;
466 463
467 /* the range data */ 464 /* the range data */
468 465
469 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 466 ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
470 h->type = NGX_HUNK_FILE; 467 b->in_file = 1;
471 h->file_pos = range[i].start; 468 b->file_pos = range[i].start;
472 h->file_last = range[i].end; 469 b->file_last = range[i].end;
473 h->file = in->hunk->file; 470 b->file = in->buf->file;
474 471
475 ngx_alloc_link_and_set_hunk(dcl, h, r->pool, NGX_ERROR); 472 ngx_alloc_link_and_set_buf(dcl, b, r->pool, NGX_ERROR);
476 473
477 *ll = hcl; 474 *ll = hcl;
478 hcl->next = rcl; 475 hcl->next = rcl;
479 rcl->next = dcl; 476 rcl->next = dcl;
480 ll = &dcl->next; 477 ll = &dcl->next;
481 } 478 }
482 479
483 /* the last boundary CRLF "--0123456789--" CRLF */ 480 /* the last boundary CRLF "--0123456789--" CRLF */
484 481
485 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 482 ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
486 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP|NGX_HUNK_LAST; 483 b->temporary = 1;
487 ngx_test_null(h->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); 484 b->last_buf = 1;
488 h->last = ngx_cpymem(h->pos, ctx->boundary_header.data, 4 + 10); 485 ngx_test_null(b->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR);
489 *h->last++ = '-'; *h->last++ = '-'; 486 b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10);
490 *h->last++ = CR; *h->last++ = LF; 487 *b->last++ = '-'; *b->last++ = '-';
491 488 *b->last++ = CR; *b->last++ = LF;
492 ngx_alloc_link_and_set_hunk(hcl, h, r->pool, NGX_ERROR); 489
490 ngx_alloc_link_and_set_buf(hcl, b, r->pool, NGX_ERROR);
493 *ll = hcl; 491 *ll = hcl;
494 492
495 return ngx_http_next_body_filter(r, out); 493 return ngx_http_next_body_filter(r, out);
496 } 494 }
497 495