Add POST handling and URLDecode POST/GET request data. Switch Login to use POST inste...
[matches/MCTX3420.git] / testing / fastcgi-approach / post / post.c
diff --git a/testing/fastcgi-approach/post/post.c b/testing/fastcgi-approach/post/post.c
new file mode 100644 (file)
index 0000000..7cd803d
--- /dev/null
@@ -0,0 +1,53 @@
+#include <fcgi_stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+char *FCGI_URLDecode(char *buf);
+
+int main() {
+       while (FCGI_Accept() >= 0) {
+               char buf[BUFSIZ];
+               printf("Content-type: text/plain\r\n\r\n");
+
+
+               while(fgets(buf, BUFSIZ, stdin)) {
+                       printf("POST (raw):\r\n");
+                       printf("%s", buf);
+                       printf("\r\nPOST (decoded):\r\n");
+                       printf("%s", FCGI_URLDecode(buf));
+               }
+
+               snprintf(buf, BUFSIZ, "%s", getenv("QUERY_STRING"));
+               printf("\r\nGET (raw):\r\n");
+               printf("%s", getenv("QUERY_STRING"));
+
+               printf("\r\nGET (decoded):\r\n");
+               printf("%s", FCGI_URLDecode(buf));
+       }
+       return 0;
+
+}
+
+char *FCGI_URLDecode(char *buf) {
+       char *head = buf, *tail = buf;
+       char hex[3] = {0};
+       while (*tail) {
+               if (*tail == '%') {
+                       tail++;
+                       if (isxdigit(*tail) && isxdigit(*(tail+1))) {
+                               hex[0] = *tail++;
+                               hex[1] = *tail++;
+                               *head++ = (char)strtol(hex, NULL, 16);
+                       } else {
+                               head++;
+                       }
+               } else if (*tail == '+') {
+                       tail++;
+                       *head++ = ' ';
+               } else {
+                       *head++ = *tail++;
+               }
+       }
+       *head = 0;
+       return buf;
+}

UCC git Repository :: git.ucc.asn.au