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" -->
13 i486-linux-uclibc-gcc \
14 -static -static-libgcc \
15 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \
16 -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Werror \
17 -Wold-style-definition -Wdeclaration-after-statement -Wno-pointer-sign \
18 -Wmissing-prototypes -Wmissing-declarations \
19 -Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer \
20 -ffunction-sections -fdata-sections -fno-guess-branch-probability \
22 -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 \
23 -march=i386 -mpreferred-stack-boundary=2 \
24 -Wl,-Map -Wl,link.map -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
25 httpd_ssi.c -o httpd_ssi
28 /* Size (i386, static uclibc, approximate):
29 text data bss dec hex filename
30 8931 164 68552 77647 12f4f httpd_ssi
33 #include <sys/types.h>
44 static char line[64 * 1024];
47 * Currently only handles directives which are alone on the line
49 static void process_includes(const char *filename)
51 FILE *fp = fopen(filename, "r");
55 #define INCLUDE "<!--#include file=\""
56 while (fgets(line, sizeof(line), fp)) {
59 /* FIXME: output text leading to INCLUDE first */
60 if (strncmp(line, INCLUDE, sizeof(INCLUDE)-1) != 0
61 || (closing_dq = strchr(line + sizeof(INCLUDE)-1, '"')) == NULL
62 /* or strstr(line + sizeof(INCLUDE)-1, "\" -->")? */
68 /* FIXME: (1) are relative paths ok?
69 * (2) if we include a/1.htm and it includes b/2.htm,
70 * do we need to insert a/b/2.htm or b/2.htm?
71 * IOW, do we need to "cd $dirname"?
73 process_includes(line + sizeof(INCLUDE)-1);
74 /* FIXME: this should be the tail of line after --> */
79 int main(int argc, char *argv[])
84 /* Seen from busybox.net's Apache:
86 * Date: Thu, 10 Sep 2009 18:23:28 GMT
88 * Accept-Ranges: bytes
90 * Content-Type: text/html
93 /* "Date: Thu, 10 Sep 2009 18:23:28 GMT\r\n" */
94 /* "Server: Apache\r\n" */
95 /* "Accept-Ranges: bytes\r\n" - do we really accept bytes?! */
96 "Connection: close\r\n"
97 "Content-Type: text/html\r\n"
100 process_includes(argv[1]);