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 / query.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-18  |  1.4 KB  |  59 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. typedef struct {
  12.     char name[128];
  13.     char val[128];
  14. } entry;
  15.  
  16. void getword(char *word, char *line, char stop);
  17. char x2c(char *what);
  18. void unescape_url(char *url);
  19. void plustospace(char *str);
  20.  
  21.  
  22.  
  23. main(int argc, char *argv[]) {
  24.     entry entries[10000];
  25.     register int x,m=0;
  26.     char *cl;
  27.  
  28.     printf("Content-type: text/html%c%c",10,10);
  29.  
  30.     if(strcmp(getenv("REQUEST_METHOD"),"GET")) {
  31.         printf("This script should be referenced with a METHOD of GET.\n");
  32.         printf("If you don't understand this, see this ");
  33.         printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
  34.         exit(1);
  35.     }
  36.  
  37.     cl = getenv("QUERY_STRING");
  38.     if(cl == NULL) {
  39.         printf("No query information to decode.\n");
  40.         exit(1);
  41.     }
  42.     for(x=0;cl[0] != '\0';x++) {
  43.         m=x;
  44.         getword(entries[x].val,cl,'&');
  45.         plustospace(entries[x].val);
  46.         unescape_url(entries[x].val);
  47.         getword(entries[x].name,entries[x].val,'=');
  48.     }
  49.  
  50.     printf("<H1>Query Results</H1>");
  51.     printf("You submitted the following name/value pairs:<p>%c",10);
  52.     printf("<ul>%c",10);
  53.  
  54.     for(x=0; x <= m; x++)
  55.         printf("<li> <code>%s = %s</code>%c",entries[x].name,
  56.                entries[x].val,10);
  57.     printf("</ul>%c",10);
  58. }
  59.