X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Ffastcgi.c;h=1bd520bd379ae30fe2bcf4c31123c2e5f4417b9a;hb=84282dc8bd6b84d23284742741fab5664ffb25a6;hp=4b7f13729900b6dd09f45aaf05d700600ede19f6;hpb=7518a87e619085f9622d268dd7130726b5947dea;p=matches%2FMCTX3420.git diff --git a/server/fastcgi.c b/server/fastcgi.c index 4b7f137..1bd520b 100644 --- a/server/fastcgi.c +++ b/server/fastcgi.c @@ -30,8 +30,11 @@ struct FCGIContext { }; /** - * Identifies current version info. Useful for testing that the API is running. - * TODO - Consider adding info about available sensors and actuators (eg capabilities)? + * Identifies build information and the current API version to the user. + * Also useful for testing that the API is running and identifying the + * sensors and actuators present. + * @param context The context to work in + * @param params User specified paramters: [actuators, sensors] */ static void IdentifyHandler(FCGIContext *context, char *params) { bool identSensors = false, identActuators = false; @@ -49,6 +52,7 @@ static void IdentifyHandler(FCGIContext *context, char *params) { FCGI_BeginJSON(context, STATUS_OK); FCGI_JSONPair("description", "MCTX3420 Server API (2013)"); FCGI_JSONPair("build_date", __DATE__ " " __TIME__); + FCGI_JSONLong("api_version", API_VERSION); if (identSensors) { FCGI_JSONKey("sensors"); FCGI_JSONValue("{\n\t\t"); @@ -205,7 +209,6 @@ void FCGI_BeginJSON(FCGIContext *context, StatusCodes status_code) FCGI_JSONDouble("start_time", start_time); FCGI_JSONDouble("current_time", current_time); FCGI_JSONDouble("running_time", current_time - start_time); - } /** @@ -267,16 +270,6 @@ void FCGI_EndJSON() printf("\r\n}\r\n"); } -/** - * To be used when the input parameters are invalid. The return data will - * have a status of STATUS_ERROR, along with other debugging information. - * @param context The context to work in - */ -void FCGI_RejectJSON(FCGIContext *context) -{ - FCGI_RejectJSONEx(context, STATUS_ERROR, "Invalid request"); -} - /** * To be used when the input parameters are rejected. The return data * will also have debugging information provided. @@ -352,8 +345,12 @@ void * FCGI_RequestLoop (void *data) size_t lastchar = strlen(module) - 1; if (lastchar > 0 && module[lastchar] == '/') module[lastchar] = 0; + + //Default to the 'identify' module if none specified + if (!*module) + strcpy(module, "identify"); - if (!*module || !strcmp("identify", module)) { + if (!strcmp("identify", module)) { module_handler = IdentifyHandler; } else if (!strcmp("control", module)) { module_handler = Control_Handler; @@ -365,8 +362,7 @@ void * FCGI_RequestLoop (void *data) if (module_handler) { module_handler(&context, params); } else { - strncat(module, " (unhandled)", BUFSIZ); - FCGI_RejectJSON(&context); + FCGI_RejectJSON(&context, "Unhandled module"); } context.response_number++;