/*********************** echoGetorPOSTparam.c *****************************
echo CGI parameters so that a shell script can read them in the following way:
#!/bin/sh
echo "Content-Type: text/html\n"
echo "\nForms support test server\n"
echoGetorPOSTparam | while read NAME REST
do
echo "${NAME}${REST}"
done
echo "\n"
****************************************************************************/
#include
#include
int strEqual (char *s1, char *s2)
{ if (!s1) return (s2==NULL); return !strcmp(s1,s2); }
char unescapeURLchar (char c1, char c2)
{ register char c = (c1 >= 'A') ? ((c1 & 0xdf) - 'A')+10 : (c1 - '0');
c *= 16; c+= (c2 >= 'A') ? ((c2 & 0xdf) - 'A')+10 : (c2 - '0');
return c;
}
int main ()
{ int c,c1,c2, i;
if (strEqual(getenv("REQUEST_METHOD"),"POST"))
{ if (!strEqual(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded"))
{fprintf(stderr,"This script can only be used to decode form results\n"); return 1;}
for (i=0; (c=getc(stdin))!=EOF; i++)
{ if (c=='+') putchar(' ');
else if (c=='%') { c1=getc(stdin); putchar(unescapeURLchar(c1,getc(stdin))); }
else if (c=='=') putchar(' ');
else if (c=='&') { putchar('\n'); i=-1; }
else putchar(c);
}
if (i>0) putchar('\n');
}
else if (strEqual(getenv("REQUEST_METHOD"),"GET"))
{ char *query= getenv("QUERY_STRING"); /* *queryBeginning=query */
if (!query||!*query) {fprintf(stderr,"No query information to process\n"); return 0;}
for (i=0; ((c = *query)); i++, query++)
{ if (c=='+') putchar(' ');
else if (c=='%') {c1= *(++query); c2=*(++query); putchar(unescapeURLchar(c1,c2));}
else if (c=='=') putchar(' ');
else if (c=='&') { putchar('\n'); i=-1; }
else putchar(c);
}
if (i>0) putchar('\n');
}
else
{ fprintf(stderr,"This script should be referenced with a METHOD of GET or POST.\n"
"If you don't understand this, see this "
""
"forms overview\n");
return 1;
}
return 0;
}