2 * Copyright (c) 2009 Denys Vlasenko <vda.linux@googlemail.com>
4 * Licensed under GPLv2, see file LICENSE in this tarball for details.
8 * This program is a CGI application. It processes server-side includes:
9 * <!--#include file="file.html" -->
11 * Usage: put these lines in httpd.conf:
13 * *.html:/bin/httpd_ssi
14 * *.htm:/bin/httpd_ssi
18 i486-linux-uclibc-gcc \
19 -static -static-libgcc \
20 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \
21 -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Werror \
22 -Wold-style-definition -Wdeclaration-after-statement -Wno-pointer-sign \
23 -Wmissing-prototypes -Wmissing-declarations \
24 -Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer \
25 -ffunction-sections -fdata-sections -fno-guess-branch-probability \
27 -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 \
28 -march=i386 -mpreferred-stack-boundary=2 \
29 -Wl,-Map -Wl,link.map -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
30 httpd_ssi.c -o httpd_ssi
33 /* Size (i386, static uclibc, approximate):
34 text data bss dec hex filename
35 8931 164 68552 77647 12f4f httpd_ssi
38 #include <sys/types.h>
49 static char line[64 * 1024];
52 * Currently only handles directives which are alone on the line
54 static void process_includes(const char *filename)
56 FILE *fp = fopen(filename, "r");
60 #define INCLUDE "<!--#include file=\""
61 while (fgets(line, sizeof(line), fp)) {
64 /* FIXME: output text leading to INCLUDE first */
65 if (strncmp(line, INCLUDE, sizeof(INCLUDE)-1) != 0
66 || (closing_dq = strchr(line + sizeof(INCLUDE)-1, '"')) == NULL
67 /* or strstr(line + sizeof(INCLUDE)-1, "\" -->")? */
74 * (1) are relative paths with /../ etc ok?
75 * (2) if we include a/1.htm and it includes b/2.htm,
76 * do we need to include a/b/2.htm or b/2.htm?
77 * IOW, do we need to "cd $dirname"?
79 process_includes(line + sizeof(INCLUDE)-1);
80 /* FIXME: this should be the tail of line after --> */
85 int main(int argc, char *argv[])
90 /* Seen from busybox.net's Apache:
92 * Date: Thu, 10 Sep 2009 18:23:28 GMT
94 * Accept-Ranges: bytes
96 * Content-Type: text/html
99 /* "Date: Thu, 10 Sep 2009 18:23:28 GMT\r\n" */
100 /* "Server: Apache\r\n" */
101 /* "Accept-Ranges: bytes\r\n" - do we really accept bytes?! */
102 "Connection: close\r\n"
103 "Content-Type: text/html\r\n"
106 process_includes(argv[1]);