X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fhttpd_ssi.c;h=4bd9a6d97dfab58b3453f80da6fd898c82d4148a;hb=a4d4ab04c3706af1cb2f65fb00c96d3ccba1020c;hp=86f341fbd0872e6fd99cbae3eb20e497c5b71b0e;hpb=56573cb4f7393fdb320660a5c258c72688a74f64;p=oweals%2Fbusybox.git diff --git a/networking/httpd_ssi.c b/networking/httpd_ssi.c index 86f341fbd..4bd9a6d97 100644 --- a/networking/httpd_ssi.c +++ b/networking/httpd_ssi.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2009 Denys Vlasenko * - * Licensed under GPLv2, see file LICENSE in this tarball for details. + * Licensed under GPLv2, see file LICENSE in this source tree. */ /* @@ -31,13 +31,17 @@ httpd_ssi.c -o httpd_ssi */ /* Size (i386, static uclibc, approximate): - text data bss dec hex filename - 8931 164 68552 77647 12f4f httpd_ssi -*/ + * text data bss dec hex filename + * 9487 160 68552 78199 13177 httpd_ssi + * + * Note: it wouldn't be too hard to get rid of stdio and strdup, + * (especially that fgets() mangles NULs...) + */ #include #include #include +#include #include #include #include @@ -46,40 +50,97 @@ httpd_ssi.c -o httpd_ssi #include #include +static char* skip_whitespace(char *s) +{ + while (*s == ' ' || *s == '\t') ++s; + + return s; +} + static char line[64 * 1024]; -/* - * Currently only handles directives which are alone on the line - */ static void process_includes(const char *filename) { + int curdir_fd; + char *end; FILE *fp = fopen(filename, "r"); if (!fp) exit(1); -#define INCLUDE "")? */ + include_directive = strstr(line, INCLUDE); + if (!include_directive) { + fputs(line, stdout); + continue; + } + preceding_len = include_directive - line; + if (memchr(line, '\"', preceding_len) + || memchr(line, '\'', preceding_len) ) { + /* INCLUDE string may be inside "str" or 'str', + * ignore it */ + fputs(line, stdout); + continue; + } + /* Small bug: we accept #includefile="file" too */ + include_directive = skip_whitespace(include_directive + sizeof(INCLUDE)-1); + if (strncmp(include_directive, "file=\"", 6) != 0) { + /* " */ - putchar('\n'); + process_includes(include_directive); + + /* Print everything after directive */ + if (end) { + fputs(end, stdout); + free(end); + } } + if (curdir_fd >= 0) + fchdir(curdir_fd); + fclose(fp); } int main(int argc, char *argv[]) @@ -95,13 +156,14 @@ int main(int argc, char *argv[]) * Connection: close * Content-Type: text/html */ - printf( + fputs( /* "Date: Thu, 10 Sep 2009 18:23:28 GMT\r\n" */ /* "Server: Apache\r\n" */ /* "Accept-Ranges: bytes\r\n" - do we really accept bytes?! */ "Connection: close\r\n" "Content-Type: text/html\r\n" - "\r\n" + "\r\n", + stdout ); process_includes(argv[1]); return 0;