Mercurial > hg > nginx-vendor-current
comparison src/http/modules/ngx_http_ssi_filter_module.c @ 194:003bd800ec2a NGINX_0_3_44
nginx 0.3.44
*) Feature: the "wait" parameter in the "include" SSI command.
*) Feature: the Ukrainian and Byelorussian characters were added to
koi-win conversion table.
*) Bugfix: in the SSI.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 04 May 2006 00:00:00 +0400 |
parents | af7f2341ecc5 |
children | d2ae1c9f1fd3 |
comparison
equal
deleted
inserted
replaced
193:2a1394604ae9 | 194:003bd800ec2a |
---|---|
186 | 186 |
187 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)"); | 187 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)"); |
188 | 188 |
189 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0 | 189 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0 |
190 #define NGX_HTTP_SSI_INCLUDE_FILE 1 | 190 #define NGX_HTTP_SSI_INCLUDE_FILE 1 |
191 #define NGX_HTTP_SSI_INCLUDE_WAIT 2 | |
191 | 192 |
192 #define NGX_HTTP_SSI_ECHO_VAR 0 | 193 #define NGX_HTTP_SSI_ECHO_VAR 0 |
193 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 | 194 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 |
194 | 195 |
195 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 | 196 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 |
202 | 203 |
203 | 204 |
204 static ngx_http_ssi_param_t ngx_http_ssi_include_params[] = { | 205 static ngx_http_ssi_param_t ngx_http_ssi_include_params[] = { |
205 { ngx_string("virtual"), NGX_HTTP_SSI_INCLUDE_VIRTUAL, 0, 0 }, | 206 { ngx_string("virtual"), NGX_HTTP_SSI_INCLUDE_VIRTUAL, 0, 0 }, |
206 { ngx_string("file"), NGX_HTTP_SSI_INCLUDE_FILE, 0, 0 }, | 207 { ngx_string("file"), NGX_HTTP_SSI_INCLUDE_FILE, 0, 0 }, |
208 { ngx_string("wait"), NGX_HTTP_SSI_INCLUDE_WAIT, 0, 0 }, | |
207 { ngx_null_string, 0, 0, 0 } | 209 { ngx_null_string, 0, 0, 0 } |
208 }; | 210 }; |
209 | 211 |
210 | 212 |
211 static ngx_http_ssi_param_t ngx_http_ssi_echo_params[] = { | 213 static ngx_http_ssi_param_t ngx_http_ssi_echo_params[] = { |
359 ngx_http_ssi_main_conf_t *smcf; | 361 ngx_http_ssi_main_conf_t *smcf; |
360 ngx_str_t *params[NGX_HTTP_SSI_MAX_PARAMS + 1]; | 362 ngx_str_t *params[NGX_HTTP_SSI_MAX_PARAMS + 1]; |
361 | 363 |
362 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); | 364 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); |
363 | 365 |
364 if (ctx == NULL || (in == NULL && ctx->in == NULL && ctx->busy == NULL)) { | 366 if (ctx == NULL |
367 || (in == NULL | |
368 && ctx->buf == NULL | |
369 && ctx->in == NULL | |
370 && ctx->busy == NULL)) | |
371 { | |
365 return ngx_http_next_body_filter(r, in); | 372 return ngx_http_next_body_filter(r, in); |
366 } | 373 } |
367 | 374 |
368 /* add the incoming chain to the chain ctx->in */ | 375 /* add the incoming chain to the chain ctx->in */ |
369 | 376 |
370 if (in) { | 377 if (in) { |
371 if (ngx_chain_add_copy(r->pool, &ctx->in, in) == NGX_ERROR) { | 378 if (ngx_chain_add_copy(r->pool, &ctx->in, in) == NGX_ERROR) { |
372 return NGX_ERROR; | 379 return NGX_ERROR; |
373 } | 380 } |
381 } | |
382 | |
383 if (ctx->wait) { | |
384 if (r->connection->data != r) { | |
385 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
386 "http ssi filter \"%V\" wait", &r->uri); | |
387 return NGX_AGAIN; | |
388 } | |
389 | |
390 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
391 "http ssi filter \"%V\" continue", &r->uri); | |
392 | |
393 ctx->wait = 0; | |
374 } | 394 } |
375 | 395 |
376 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module); | 396 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module); |
377 | 397 |
378 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 398 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
628 return NGX_DONE; | 648 return NGX_DONE; |
629 } | 649 } |
630 | 650 |
631 if (rc == NGX_OK) { | 651 if (rc == NGX_OK) { |
632 continue; | 652 continue; |
653 } | |
654 | |
655 if (rc == NGX_AGAIN) { | |
656 return NGX_AGAIN; | |
633 } | 657 } |
634 | 658 |
635 if (rc == NGX_ERROR) { | 659 if (rc == NGX_ERROR) { |
636 return NGX_ERROR; | 660 return NGX_ERROR; |
637 } | 661 } |
780 b->shadow->pos = b->shadow->last; | 804 b->shadow->pos = b->shadow->last; |
781 } | 805 } |
782 | 806 |
783 cl = ctx->busy; | 807 cl = ctx->busy; |
784 ctx->busy = cl->next; | 808 ctx->busy = cl->next; |
785 cl->next = ctx->free; | 809 |
786 ctx->free = cl; | 810 if (ngx_buf_in_memory(b) || b->in_file) { |
811 /* add data bufs only to the free buf chain */ | |
812 | |
813 cl->next = ctx->free; | |
814 ctx->free = cl; | |
815 } | |
787 } | 816 } |
788 | 817 |
789 return rc; | 818 return rc; |
790 } | 819 } |
791 | 820 |
1624 | 1653 |
1625 static ngx_int_t | 1654 static ngx_int_t |
1626 ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | 1655 ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
1627 ngx_str_t **params) | 1656 ngx_str_t **params) |
1628 { | 1657 { |
1629 ngx_str_t *uri, *file, args; | 1658 ngx_int_t rc; |
1659 ngx_str_t *uri, *file, *wait, args; | |
1630 ngx_uint_t flags; | 1660 ngx_uint_t flags; |
1631 | 1661 |
1632 uri = params[NGX_HTTP_SSI_INCLUDE_VIRTUAL]; | 1662 uri = params[NGX_HTTP_SSI_INCLUDE_VIRTUAL]; |
1633 file = params[NGX_HTTP_SSI_INCLUDE_FILE]; | 1663 file = params[NGX_HTTP_SSI_INCLUDE_FILE]; |
1664 wait = params[NGX_HTTP_SSI_INCLUDE_WAIT]; | |
1634 | 1665 |
1635 if (uri && file) { | 1666 if (uri && file) { |
1636 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1667 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1637 "inlcusion may be either virtual=\"%V\" or file=\"%V\"", | 1668 "inlcusion may be either virtual=\"%V\" or file=\"%V\"", |
1638 uri, file); | 1669 uri, file); |
1643 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1674 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1644 "no parameter in \"include\" SSI command"); | 1675 "no parameter in \"include\" SSI command"); |
1645 return NGX_HTTP_SSI_ERROR; | 1676 return NGX_HTTP_SSI_ERROR; |
1646 } | 1677 } |
1647 | 1678 |
1679 if (wait) { | |
1680 if (uri == NULL) { | |
1681 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1682 "\"wait\" may not be used with file=\"%V\"", | |
1683 uri, file); | |
1684 return NGX_HTTP_SSI_ERROR; | |
1685 } | |
1686 | |
1687 if (wait->len == 2 && ngx_strncasecmp(wait->data, "no", 2) == 0) { | |
1688 wait = NULL; | |
1689 | |
1690 } else if (wait->len != 3 || ngx_strncasecmp(wait->data, "yes", 3) != 0) | |
1691 { | |
1692 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1693 "invalid value \"%V\" in the \"wait\" parameter", | |
1694 &wait); | |
1695 return NGX_HTTP_SSI_ERROR; | |
1696 } | |
1697 } | |
1698 | |
1648 if (uri == NULL) { | 1699 if (uri == NULL) { |
1649 uri = file; | 1700 uri = file; |
1650 } | 1701 } |
1651 | 1702 |
1652 if (ngx_http_ssi_evaluate_string(r, ctx, uri, NGX_HTTP_SSI_ADD_PREFIX) | 1703 if (ngx_http_ssi_evaluate_string(r, ctx, uri, NGX_HTTP_SSI_ADD_PREFIX) |
1664 | 1715 |
1665 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { | 1716 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { |
1666 return NGX_HTTP_SSI_ERROR; | 1717 return NGX_HTTP_SSI_ERROR; |
1667 } | 1718 } |
1668 | 1719 |
1669 if (ngx_http_subrequest(r, uri, &args, flags) != NGX_OK) { | 1720 rc = ngx_http_subrequest(r, uri, &args, flags); |
1721 | |
1722 if (rc == NGX_ERROR) { | |
1670 return NGX_HTTP_SSI_ERROR; | 1723 return NGX_HTTP_SSI_ERROR; |
1671 } | 1724 } |
1672 | 1725 |
1673 return NGX_OK; | 1726 if (wait == NULL) { |
1727 return NGX_OK; | |
1728 } | |
1729 | |
1730 if (rc == NGX_AGAIN) { | |
1731 ctx->wait = 1; | |
1732 } | |
1733 | |
1734 return rc; | |
1674 } | 1735 } |
1675 | 1736 |
1676 | 1737 |
1677 static ngx_int_t | 1738 static ngx_int_t |
1678 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | 1739 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |