cgi frontend
[henge/webcc.git] / src / bin / tools / ockpromo-fcgi.c
diff --git a/src/bin/tools/ockpromo-fcgi.c b/src/bin/tools/ockpromo-fcgi.c
new file mode 100644 (file)
index 0000000..9ecc790
--- /dev/null
@@ -0,0 +1,50 @@
+/*!@file
+  \brief   Mail router for OCKoreanMartialArts.com
+  \details This mail routing system is intended to run as a daemon for fastcgi
+           and stores usage information in a database before sending mail to the
+           administrator
+  \author  Ken
+  \date    Sept 2016
+  ----------------------------------------------------------------------------*/
+/* Standard */
+#include <stdlib.h> //atoi
+#include <string.h> //mem
+/* Third Party */
+#include <fcgi_stdio.h>
+/* Internal */
+#include <ock/ock.h>
+
+int get_body(void);
+
+int
+main
+()
+{ if (db_init())
+    return -1;
+
+  while(FCGI_Accept() >= 0)
+    { printf("Content-type: application/json\r\n\r\n");
+      printf("{ \"submission\" : ");
+      if (!get_body())
+       printf("\"fail\"");
+      printf("\"pass\"");
+      printf(" }");
+    }
+  return 0;
+}
+
+int
+get_body
+()
+{ char *lencp;
+  int   len, i;
+
+  if ((lencp = getenv("CONTENT_LENGTH")) == NULL
+      || (len = atoi(lencp)) < 1)
+    return -1;
+  for (i = 0; i < len; i++)
+    putchar(getchar());
+
+  return 0;
+}
+