X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fhttpd_ssi.c;h=4bd9a6d97dfab58b3453f80da6fd898c82d4148a;hb=2b1559056cf32c42675ecd937796e1455bcb5c2c;hp=f75805923549c206f8b37db19b17134e40a6b48c;hpb=db4a67628d4e4418d01bbba1c8603a6ca8c3562e;p=oweals%2Fbusybox.git diff --git a/networking/httpd_ssi.c b/networking/httpd_ssi.c index f75805923..4bd9a6d97 100644 --- a/networking/httpd_ssi.c +++ b/networking/httpd_ssi.c @@ -1,12 +1,17 @@ /* * 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. */ /* * This program is a CGI application. It processes server-side includes: * + * + * Usage: put these lines in httpd.conf: + * + * *.html:/bin/httpd_ssi + * *.htm:/bin/httpd_ssi */ /* Build a-la @@ -26,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 @@ -41,39 +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[]) @@ -89,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;