X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fcontrol.c;h=0242a3b52f2a4b04ec771343d222f15b909d726d;hb=85a4ea3366eaf09950957e416a2e12c8e4270f92;hp=5c8a4103feceb3672c79aa0cde7b1298973854f4;hpb=b7150f722995ea6807182da24653a15693a82698;p=matches%2FMCTX3420.git diff --git a/server/control.c b/server/control.c index 5c8a410..0242a3b 100644 --- a/server/control.c +++ b/server/control.c @@ -15,7 +15,8 @@ typedef struct ControlData { ControlData g_controls = {CONTROL_STOP, PTHREAD_MUTEX_INITIALIZER, {0}}; -static bool PathExists(const char *path) { +bool PathExists(const char *path) +{ FILE *fp = fopen(path, "r"); if (fp) { fclose(fp); @@ -31,13 +32,19 @@ static bool PathExists(const char *path) { * @param params The input parameters */ void Control_Handler(FCGIContext *context, char *params) { - const char *action, *key = "", *name = ""; + const char *action = ""; + const char *name = ""; bool force = false; ControlModes desired_mode; + + + // Login/auth now handled entirely in fastcgi.c and login.c + //TODO: Need to not have the ability for any user to stop someone else' experiment... + // (achieve by storing the username of the person running the current experiment, even when they log out?) + // (Our program should only realisitically support a single experiment at a time, so that should be sufficient) FCGIValue values[4] = { {"action", &action, FCGI_REQUIRED(FCGI_STRING_T)}, - {"key", &key, FCGI_STRING_T}, {"force", &force, FCGI_BOOL_T}, {"name", &name, FCGI_STRING_T} }; @@ -45,32 +52,21 @@ void Control_Handler(FCGIContext *context, char *params) { if (!FCGI_ParseRequest(context, params, values, 4)) return; - if (!strcmp(action, "lock")) { - FCGI_LockControl(context, force); - return; - } else if (!strcmp(action, "emergency")) { + if (!strcmp(action, "emergency")) { desired_mode = CONTROL_EMERGENCY; - } else if (FCGI_HasControl(context, key)) { - if (!strcmp(action, "release")) { - FCGI_ReleaseControl(context); - } else if (!strcmp(action, "start")) { - desired_mode = CONTROL_START; - } else if (!strcmp(action, "pause")) { - desired_mode = CONTROL_PAUSE; - } else if (!strcmp(action, "resume")) { - desired_mode = CONTROL_RESUME; - } else if (!strcmp(action, "stop")) { - desired_mode = CONTROL_STOP; - } else { - FCGI_RejectJSON(context, "Unknown action specified."); - return; - } + } else if (!strcmp(action, "start")) { + desired_mode = CONTROL_START; + } else if (!strcmp(action, "pause")) { + desired_mode = CONTROL_PAUSE; + } else if (!strcmp(action, "resume")) { + desired_mode = CONTROL_RESUME; + } else if (!strcmp(action, "stop")) { + desired_mode = CONTROL_STOP; } else { - FCGI_RejectJSONEx(context, STATUS_UNAUTHORIZED, - "Invalid control key specified."); + FCGI_RejectJSON(context, "Unknown action specified."); return; } - + void *arg = NULL; if (desired_mode == CONTROL_START) { if (PathExists(name) && !force) { @@ -177,4 +173,4 @@ const char * Control_GetModeName() { */ const struct timeval* Control_GetStartTime() { return &g_controls.start_time; -} \ No newline at end of file +}