/* slurp.c, to be #included in AnyURL.c and cover.c */
/* slurp contents were verbatim from post-query.c */
/* modified at cover V1.3 to add METHOD=GET */
/* modified at AnyURL V1.5 to add check for existence of REQUEST_METHOD */
void slurp() {
if ( getenv("REQUEST_METHOD") == NULL ) {
error_header;
printf( "REQUEST_METHOD was null.
\n" );
printf( "This program is a CGI server script and therefore
\n" );
printf( "must execute within proper web context.
\n" );
more_info;
exit(EXIT_SUCCESS);
}
if (!strcmp(getenv("REQUEST_METHOD"),"POST")) {
int cl;
/* printf("METHOD=POST\n"); */
/* code from post-query.c -- read name/value pairs from stdin */
if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
error_header;
printf( "REQUEST_METHOD of POST requires forms-encoded content.
\n" );
more_info;
exit(EXIT_SUCCESS);
}
cl = atoi(getenv("CONTENT_LENGTH"));
for(E=0;cl && (!feof(stdin));E++) {
NE=E;
entries[E].val = fmakeword(stdin,'&',&cl);
plustospace(entries[E].val);
unescape_url(entries[E].val);
entries[E].name = makeword(entries[E].val,'=');
}
} else if (!strcmp(getenv("REQUEST_METHOD"),"GET")) {
char *cl;
char *qs;
/* printf("METHOD=GET\n"); */
/* code from query.c -- read name/value pairs from QUERY_STRING env var */
qs = getenv("QUERY_STRING");
if ( qs == NULL ) {
error_header;
printf("REQUEST_METHOD was GET, but there was no query information to decode.\n");
more_info;
exit(EXIT_SUCCESS);
}
if( qs[0] == '\0' ) {
error_header;
printf("REQUEST_METHOD was GET, but there was no query information to decode.\n");
more_info;
exit(EXIT_SUCCESS);
}
/* make our own copy of query string, so we don't change the env var */
cl = (char *) malloc(sizeof(char) * (strlen(qs)+1));
strcpy(cl,qs);
for(E=0;cl[0] != '\0';E++) {
NE=E;
entries[E].val = makeword(cl,'&');
/* getword(entries[E].val,cl,'&'); */
plustospace(entries[E].val);
unescape_url(entries[E].val);
entries[E].name = makeword(entries[E].val,'=');
}
} else {
/* printf("METHOD=(neither)\n"); */
error_header;
printf("This script must be referenced with a METHOD of GET or POST.
\n");
more_info;
exit(EXIT_SUCCESS);
}
} /* slurp */