/* * Copyright (c) 2009 Denys Vlasenko * * 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 i486-linux-uclibc-gcc \ -static -static-libgcc \ -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \ -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Werror \ -Wold-style-definition -Wdeclaration-after-statement -Wno-pointer-sign \ -Wmissing-prototypes -Wmissing-declarations \ -Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer \ -ffunction-sections -fdata-sections -fno-guess-branch-probability \ -funsigned-char \ -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 \ -march=i386 -mpreferred-stack-boundary=2 \ -Wl,-Map -Wl,link.map -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ httpd_ssi.c -o httpd_ssi */ /* Size (i386, static uclibc, approximate): * 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 #include #include #include #include static char* skip_whitespace(char *s) { while (*s == ' ' || *s == '\t') ++s; return s; } static char line[64 * 1024]; static void process_includes(const char *filename) { int curdir_fd; char *end; FILE *fp = fopen(filename, "r"); if (!fp) exit(1); /* Ensure that nested includes are relative: * if we include a/1.htm and it includes b/2.htm, * we need to include a/b/2.htm, not b/2.htm */ curdir_fd = -1; end = strrchr(filename, '/'); if (end) { curdir_fd = open(".", O_RDONLY); /* *end = '\0' would mishandle "/file.htm" */ end[1] = '\0'; chdir(filename); } #define INCLUDE "