X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Ffastcgi.c;h=8714db28a6c2a183bf2a35170d8c9bba18a06162;hb=7284f69ded90441c34efb8f86a515ef399d3ccf3;hp=b58ba79ba545c8b7e3f3b168eac95dccf8507ae1;hpb=d0f77e15cfa58191a7683caf343037c25be9f31c;p=matches%2FMCTX3420.git diff --git a/server/fastcgi.c b/server/fastcgi.c index b58ba79..8714db2 100644 --- a/server/fastcgi.c +++ b/server/fastcgi.c @@ -12,6 +12,7 @@ #include "common.h" #include "sensor.h" +#include "actuator.h" #include "control.h" #include "options.h" @@ -39,24 +40,14 @@ struct FCGIContext { */ static void IdentifyHandler(FCGIContext *context, char *params) { bool ident_sensors = false, ident_actuators = false; - //const char *key, *value; int i; FCGIValue values[2] = {{"sensors", &ident_sensors, FCGI_BOOL_T}, {"actuators", &ident_actuators, FCGI_BOOL_T}}; - if (!FCGI_ParseRequest(context, params, values, 2)) return; - /*while ((params = FCGI_KeyPair(params, &key, &value))) { - if (!strcmp(key, "sensors")) { - ident_sensors = !ident_sensors; - } else if (!strcmp(key, "actuators")) { - ident_actuators = !ident_actuators; - } - }*/ - FCGI_BeginJSON(context, STATUS_OK); FCGI_JSONPair("description", "MCTX3420 Server API (2013)"); FCGI_JSONPair("build_date", __DATE__ " " __TIME__); @@ -237,14 +228,19 @@ bool FCGI_ParseRequest(FCGIContext *context, char *params, FCGIValue values[], s case FCGI_BOOL_T: *((bool*) val->value) = true; break; - case FCGI_LONG_T: - *((long*) val->value) = strtol(value, &ptr, 10); + case FCGI_INT_T: case FCGI_LONG_T: { + long parsed = strtol(value, &ptr, 10); if (!*value || *ptr) { snprintf(buf, BUFSIZ, "Expected int for '%s' but got '%s'", key, value); FCGI_RejectJSON(context, FCGI_EscapeJSON(buf)); return false; } - break; + + if (FCGI_TYPE(val->flags) == FCGI_INT_T) + *((int*) val->value) = parsed; + else + *((long*) val->value) = parsed; + } break; case FCGI_DOUBLE_T: *((double*) val->value) = strtod(value, &ptr); if (!*value || *ptr) { @@ -439,8 +435,6 @@ void * FCGI_RequestLoop (void *data) Log(LOGDEBUG, "First request..."); while (FCGI_Accept() >= 0) { - - Log(LOGDEBUG, "Got request #%d", context.response_number); ModuleHandler module_handler = NULL; char module[BUFSIZ], params[BUFSIZ]; @@ -464,6 +458,8 @@ void * FCGI_RequestLoop (void *data) module_handler = Control_Handler; } else if (!strcmp("sensors", module)) { module_handler = Sensor_Handler; + } else if (!strcmp("actuators", module)) { + module_handler = Actuator_Handler; } context.current_module = module;