- Implemented seperate functions to create header/footer buffers.

- Simplified template.html and make code work with new template. Some vars
  were uneeded.
- Added buffer chain debug macro in module header.
pull/4/head
Adrian Perez 17 years ago
parent 549d00bdae
commit 7e156ff58d

@ -168,6 +168,48 @@ ngx_module_t ngx_http_fancyindex_module = {
static inline ngx_buf_t*
make_header_buf(ngx_http_request_t *r)
{
size_t blen = r->uri.len
+ nfi_sizeof_ssz(t01_head1)
+ nfi_sizeof_ssz(t02_head2)
+ nfi_sizeof_ssz(t03_body1)
;
ngx_buf_t *b = ngx_create_temp_buf(r->pool, blen);
if (b == NULL) goto bailout;
b->last = nfi_cpymem_ssz(b->last, t01_head1);
b->last = nfi_cpymem_str(b->last, r->uri);
b->last = nfi_cpymem_ssz(b->last, t02_head2);
b->last = nfi_cpymem_ssz(b->last, t03_body1);
bailout:
return b;
}
static inline ngx_buf_t*
make_footer_buf(ngx_http_request_t *r)
{
/*
* TODO: Make this buffer static (i.e. readonly and reusable from
* one request to another.
*/
ngx_buf_t *b = ngx_create_temp_buf(r->pool, nfi_sizeof_ssz(t07_foot1));
if (b == NULL) goto bailout;
b->last = nfi_cpymem_ssz(b->last, t07_foot1);
bailout:
return b;
}
static ngx_int_t static ngx_int_t
ngx_http_fancyindex_handler(ngx_http_request_t *r) ngx_http_fancyindex_handler(ngx_http_request_t *r)
{ {
@ -651,12 +693,6 @@ skip_readme_top:
/* Output table bottom */ /* Output table bottom */
b->last = nfi_cpymem_ssz(b->last, t06_list2); b->last = nfi_cpymem_ssz(b->last, t06_list2);
/*
* Output body end, including readme if requested. The t07_body3 and
* t08_body4 templates may be empty, so use ngx_http_fancyindex_tcpy_if
*/
b->last = nfi_cpymem_ssz(b->last, t07_body3);
/* Insert readme at bottom, if appropriate */ /* Insert readme at bottom, if appropriate */
if ((readme_path.len == 0) || if ((readme_path.len == 0) ||
nfi_has_flag(alcf->readme_flags, NGX_HTTP_FANCYINDEX_README_TOP) || nfi_has_flag(alcf->readme_flags, NGX_HTTP_FANCYINDEX_README_TOP) ||
@ -672,8 +708,6 @@ skip_readme_top:
} }
skip_readme_bottom: skip_readme_bottom:
b->last = nfi_cpymem_ssz(b->last, t08_body4);
/* Output page footer */ /* Output page footer */
if (alcf->footer.len > 0) { if (alcf->footer.len > 0) {
/* URI is configured, make Nginx take care of with a subrequest. */ /* URI is configured, make Nginx take care of with a subrequest. */
@ -718,19 +752,21 @@ skip_readme_bottom:
} }
else { else {
add_builtin_footer: add_builtin_footer:
b->last = nfi_cpymem_ssz(b->last, t09_foot1); b->last = nfi_cpymem_ssz(b->last, t07_foot1);
} }
if (r == r->main) { if (r == r->main) {
b->last_buf = 1; b->last_buf = 1;
} }
b->last_in_chain = 1;
b->last_in_chain = 1; nfi_log_debug_buf_chain(r, &out);
out.buf = b; out.buf = b;
out.next = NULL; out.next = NULL;
return ngx_http_output_filter(r, &out); return ngx_http_output_filter(r, &out);
} }

@ -54,16 +54,6 @@ typedef struct {
#define nfi_sizeof_ssz(_s) (sizeof(_s) - 1) #define nfi_sizeof_ssz(_s) (sizeof(_s) - 1)
#define NFI_BUILTIN_HEAD_SIZE ( \
nfi_sizeof_ssz(t01_head1) + \
nfi_sizeof_ssz(t02_head2) + \
nfi_sizeof_ssz(t03_body1) )
#define NFI_BUILTIN_FOOT_SIZE ( \
nfi_sizeof_ssz(t08_body4) + \
nfi_sizeof_ssz(t09_foot1) )
#define NGX_HTTP_FANCYINDEX_PREALLOCATE 50 #define NGX_HTTP_FANCYINDEX_PREALLOCATE 50
#define NGX_HTTP_FANCYINDEX_NAME_LEN 50 #define NGX_HTTP_FANCYINDEX_NAME_LEN 50
@ -92,6 +82,23 @@ typedef struct {
(((_where) & (_what)) == (_what)) (((_where) & (_what)) == (_what))
#define nfi_log_debug_buf_chain(_r, _b) \
do { \
ngx_chain_t *__chain_b = (_b); \
ngx_buf_t *__temp_b = __chain_b->buf; \
while (!__temp_b->last_buf && __chain_b->buf != NULL) { \
ngx_log_debug(NGX_LOG_DEBUG_HTTP, (_r)->connection->log, 0, \
"http fancyindex: buf %p, last_in_buf = %i\n" \
"\tmemory = %i, temporary = %i\n", \
__temp_b, __temp_b->last_in_chain, \
__temp_b->memory, __temp_b->temporary \
); \
__chain_b = __chain_b->next; \
__temp_b = __chain_b->buf; \
} \
} while (0)
#endif /* !__ngx_http_fancyindex_module_h__ */ #endif /* !__ngx_http_fancyindex_module_h__ */
/* vim:ft=c /* vim:ft=c
*/ */

@ -98,20 +98,14 @@ static const u_char t06_list2[] = ""
"</tbody>" "</tbody>"
"</table>" "</table>"
; ;
static const u_char t07_body3[] = "" static const u_char t07_foot1[] = ""
;
static const u_char t08_body4[] = ""
;
static const u_char t09_foot1[] = ""
"</body>" "</body>"
"</html>" "</html>"
; ;
#define NFI_TEMPLATE_SIZE (0 \ #define NFI_TEMPLATE_SIZE (0 \
+ nfi_sizeof_ssz(t05_list1) \ + nfi_sizeof_ssz(t05_list1) \
+ nfi_sizeof_ssz(t06_list2) \ + nfi_sizeof_ssz(t06_list2) \
+ nfi_sizeof_ssz(t07_body3) \ + nfi_sizeof_ssz(t07_foot1) \
+ nfi_sizeof_ssz(t08_body4) \
+ nfi_sizeof_ssz(t09_foot1) \
+ nfi_sizeof_ssz(t01_head1) \ + nfi_sizeof_ssz(t01_head1) \
+ nfi_sizeof_ssz(t02_head2) \ + nfi_sizeof_ssz(t02_head2) \
+ nfi_sizeof_ssz(t03_body1) \ + nfi_sizeof_ssz(t03_body1) \

@ -111,8 +111,6 @@
<!-- var t06_list2 --> <!-- var t06_list2 -->
</tbody> </tbody>
</table> </table>
<!-- var t07_body3 --> <!-- var t07_foot1 -->
<!-- var t08_body4 -->
<!-- var t09_foot1 -->
</body> </body>
</html> </html>

Loading…
Cancel
Save