cgi frontend
[henge/webcc.git] / src / bin / tools / ockpromo-fcgi.c
1 /*!@file
2 \brief Mail router for OCKoreanMartialArts.com
3 \details This mail routing system is intended to run as a daemon for fastcgi
4 and stores usage information in a database before sending mail to the
5 administrator
6 \author Ken
7 \date Sept 2016
8 ----------------------------------------------------------------------------*/
9 /* Standard */
10 #include <stdlib.h> //atoi
11 #include <string.h> //mem
12 /* Third Party */
13 #include <fcgi_stdio.h>
14 /* Internal */
15 #include <ock/ock.h>
16
17 int get_body(void);
18
19 int
20 main
21 ()
22 { if (db_init())
23 return -1;
24
25 while(FCGI_Accept() >= 0)
26 { printf("Content-type: application/json\r\n\r\n");
27 printf("{ \"submission\" : ");
28 if (!get_body())
29 printf("\"fail\"");
30 printf("\"pass\"");
31 printf(" }");
32 }
33 return 0;
34 }
35
36 int
37 get_body
38 ()
39 { char *lencp;
40 int len, i;
41
42 if ((lencp = getenv("CONTENT_LENGTH")) == NULL
43 || (len = atoi(lencp)) < 1)
44 return -1;
45 for (i = 0; i < len; i++)
46 putchar(getchar());
47
48 return 0;
49 }
50