home *** CD-ROM | disk | FTP | other *** search
/ The HTML Web Publisher's Construction Kit / HTMLWPCK.ISO / unix / servers / httpd_14 / source.z / source / httpd_1.4.1 / cgi-src / post-query.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-18  |  1.5 KB  |  61 lines

  1.  
  2.  
  3.  
  4. #include <stdio.h>
  5. #ifndef NO_STDLIB_H
  6. #include <stdlib.h>
  7. #else
  8. char *getenv();
  9. #endif
  10.  
  11. #define MAX_ENTRIES 10000
  12.  
  13. typedef struct {
  14.     char *name;
  15.     char *val;
  16. } entry;
  17.  
  18. char *makeword(char *line, char stop);
  19. char *fmakeword(FILE *f, char stop, int *len);
  20. char x2c(char *what);
  21. void unescape_url(char *url);
  22. void plustospace(char *str);
  23.  
  24.  
  25. main(int argc, char *argv[]) {
  26.     entry entries[MAX_ENTRIES];
  27.     register int x,m=0;
  28.     int cl;
  29.  
  30.     printf("Content-type: text/html%c%c",10,10);
  31.  
  32.     if(strcmp(getenv("REQUEST_METHOD"),"POST")) {
  33.         printf("This script should be referenced with a METHOD of POST.\n");
  34.         printf("If you don't understand this, see this ");
  35.         printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
  36.         exit(1);
  37.     }
  38.     if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
  39.         printf("This script can only be used to decode form results. \n");
  40.         exit(1);
  41.     }
  42.     cl = atoi(getenv("CONTENT_LENGTH"));
  43.  
  44.     for(x=0;cl && (!feof(stdin));x++) {
  45.         m=x;
  46.         entries[x].val = fmakeword(stdin,'&',&cl);
  47.         plustospace(entries[x].val);
  48.         unescape_url(entries[x].val);
  49.         entries[x].name = makeword(entries[x].val,'=');
  50.     }
  51.  
  52.     printf("<H1>Query Results</H1>");
  53.     printf("You submitted the following name/value pairs:<p>%c",10);
  54.     printf("<ul>%c",10);
  55.  
  56.     for(x=0; x <= m; x++)
  57.         printf("<li> <code>%s = %s</code>%c",entries[x].name,
  58.                entries[x].val,10);
  59.     printf("</ul>%c",10);
  60. }
  61.