/*************************************************************************** * post-que.c sample script to handle Method=POST * * original: Rob McCool, NCSA HTTPD V. 1.3 * OS/2 port: Frankie Fan 7/11/94 * * $Header$ * * $Log$ **************************************************************************/ #include #include #include #include "util.h" #define MAX_ENTRIES 10000 typedef struct { char *name; char *val; } entry; char *makeword(char *line, char stop); char *fmakeword(FILE * f, char stop, int *len); char x2c(char *what); void unescape_url(char *url); void plustospace(char *str); entry entries[MAX_ENTRIES]; void main(void) { register int x, m = 0; int cl; printf("Content-type: text/html%c%c", 10, 10); if (!getenv("REQUEST_METHOD") || strcmp(getenv("REQUEST_METHOD"), "POST")) { printf("This script should be referenced with a METHOD of POST.\n"); printf("If you don't understand this, see this "); printf("forms overview.%c", 10); exit(1); } if (!getenv("CONTENT_TYPE") || strcmp(getenv("CONTENT_TYPE"), "application/x-www-form-urlencoded")) { printf("This script can only be used to decode form results. \n"); exit(1); } if (!getenv("CONTENT_LENGTH")) { printf("This script requires CONTENT_LENGTH environment variable.\n"); exit(1); } cl = atoi(getenv("CONTENT_LENGTH")); for (x = 0; cl && (!feof(stdin)); x++) { m = x; entries[x].val = fmakeword(stdin, '&', &cl); plustospace(entries[x].val); unescape_url(entries[x].val); entries[x].name = makeword(entries[x].val, '='); } printf("

Query Results

"); printf("You submitted the following name/value pairs:

%c", 10); printf("

    %c", 10); for (x = 0; x <= m; x++) printf("
  • %s = %s%c", entries[x].name, entries[x].val, 10); if (getenv("QUERY_STRING")) { printf("
  • QUERY_STRING=%s", getenv("QUERY_STRING")); } printf("
%c", 10); }