--- fnord-1.10-20090206fwb/httpd.c.nophpbinfmt 2009-02-07 20:36:53.000000000 +0100 +++ fnord-1.10-20090206fwb/httpd.c 2009-02-07 20:40:23.000000000 +0100 @@ -175,6 +175,19 @@ char* remote_ident; #endif +unsigned long str_rchrlong(const char *haystack, char needle) { + register const char* t=haystack; + register const char c=needle; + register const char* found=0; + for (;;) { + if (!*t) break; if (*t==c) found=t; ++t; + if (!*t) break; if (*t==c) found=t; ++t; + if (!*t) break; if (*t==c) found=t; ++t; + if (!*t) break; if (*t==c) found=t; ++t; + } + return (found?found:t)-haystack; +} + static int buffer_put2digits(buffer* b,unsigned int i) { char x[2]; x[0]=(i/10)+'0'; @@ -267,7 +280,7 @@ } #ifdef CGI -#define CGIENVLEN 21 +#define CGIENVLEN 23 static const char *cgivars[CGIENVLEN] = { "GATEWAY_INTERFACE=", @@ -290,7 +303,9 @@ "CONTENT_LENGTH=", "QUERY_STRING=", "PATH_INFO=", - "PATH_TRANSLATED=" + "PATH_TRANSLATED=", + "SCRIPT_FILENAME=", + "REDIRECT_STATUS=" }; static int iscgivar(const char *s) { @@ -429,6 +444,16 @@ tmp+=realpath(pathinfo,tmp)?str_len(tmp):str_copy(tmp,pathinfo); ++tmp; } + else { + cgi_env[++i]=tmp; + tmp+=str_copy(tmp,"SCRIPT_FILENAME="); + tmp+=str_copy(tmp,url+1+str_rchrlong(url,'/')); + *tmp=0; ++tmp; + cgi_env[++i]=tmp; + tmp+=str_copy(tmp,"REDIRECT_STATUS="); + tmp+=str_copy(tmp,""); + ++tmp; + } { unsigned int j=0; @@ -1103,8 +1128,11 @@ #ifdef CGI static int findcgi(const char* c) { return (c[0]=='.' && c[1]=='c' && - c[2]=='g' && c[3]=='i' && - (c[4]=='/' || c[4]==0)); + c[2]=='g' && c[3]=='i' && + (c[4]=='/' || c[4]==0)) || + (c[0]=='.' && c[1]=='p' && + c[2]=='h' && c[3]=='p' && + (c[4]=='/' || c[4]==0)); } #endif