1 #include "fcgi_stdio.h" /* fcgi library; put it first*/
5 But the suggestion was: FunctionName, variable_name (local or member),
6 Structure, ENUMVALUE, Extern_FunctionName, g_global
9 typedef struct Data Data;
11 typedef void (*ModuleHandler) (Data *data, const char *params);
13 static void SensorsHandler(Data *data, const char *params) {
14 printf("Sensors module!<br>");
21 *get=x is optional. Retrieves info for sensor with id x
23 /cgi/devices?status=x&power=y&id=z
24 *status and power is optional
25 *status retrieves whether device with id x is operational
26 *power tells whether or not to power on/off the device with id z
29 200 OK if request was ok
30 400 bad request for malformed request
33 int main (int argc, char *argv[])
39 while (FCGI_Accept() >= 0) {
40 ModuleHandler module_handler = NULL;
41 const char *module = getenv("DOCUMENT_URI_LOCAL");
42 const char *params = getenv("QUERY_STRING");
44 if (!strcmp("sensors", module)) {
45 module_handler = SensorsHandler; //Replace with pointer to sensors handler
46 } else if (!strcmp("admin"), module) {
47 module_handler = NULL; //Replace with pointer to admin handler
48 printf("Admin module selected!\n");
52 printf("Content-type: text/html\r\n\r\n"); //Replace with actual type
53 module_handler(data, params);
55 printf("Status: 400 Bad Request\r\n"
56 "Content-type: text/html\r\n\r\n"
57 "<title>400 Bad Request</title>\n"
58 "Unknown module '%s' selected.<br>\n",
63 printf("Module: %s, Params: %s<br>\n", module, params);
64 printf("Request number %d, host <i>%s</i>\n",
65 count++, getenv("SERVER_HOSTNAME"));