X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Ffastcgi.c;h=4fc374243f4a08cf188001b19a32460524e0f8ea;hb=0cde65933e9da0b196661ec0863e5d705b657286;hp=3bcb36a6ed15cab2b1ecf0d04a93ad6a859b8993;hpb=621ec4c4752d4a01838aa1866cfc1bc401021dcb;p=matches%2FMCTX3420.git diff --git a/server/fastcgi.c b/server/fastcgi.c index 3bcb36a..4fc3742 100644 --- a/server/fastcgi.c +++ b/server/fastcgi.c @@ -83,6 +83,25 @@ static void LoginHandler(FCGIContext *context, char *params) { } } +/*TODO: Remove and replace with the actual actuator code*/ +static void ActuatorHandler(FCGIContext *context, char *params) { + const char *key, *value, *loginkey = NULL; + while ((params = FCGI_KeyPair(params, &key, &value))) { + if (!strcmp(key, "key")) { + loginkey = value; + } + } + if (!loginkey || !FCGI_Authorized(context, loginkey)) { + FCGI_BeginJSON(context, STATUS_UNAUTHORIZED); + FCGI_JSONPair("description", "Invalid key specified."); + FCGI_EndJSON(); + } else { + FCGI_BeginJSON(context, STATUS_OK); + FCGI_JSONPair("description", "Logged in!"); + FCGI_EndJSON(); + } +} + /** * Given an FCGIContext, determines if the current user (as specified by * the key) is authorized or not. If validated, the context login_timestamp is @@ -93,7 +112,7 @@ static void LoginHandler(FCGIContext *context, char *params) { */ bool FCGI_Authorized(FCGIContext *context, const char *key) { time_t now = time(NULL); - int result = (now - context->login_timestamp) <= LOGIN_TIMEOUT && + int result = (now - context->login_timestamp) <= LOGIN_TIMEOUT && !strcmp(context->login_key, key); if (result) { context->login_timestamp = now; //Update the login_timestamp @@ -263,7 +282,7 @@ void FCGI_RequestLoop (void *data) } else if (!strcmp("sensors", module)) { module_handler = Sensor_Handler; } else if (!strcmp("actuators", module)) { - + module_handler = ActuatorHandler; } context.current_module = module;