+ } 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 {
+ FCGI_RejectJSONEx(context, STATUS_UNAUTHORIZED,
+ "Invalid control key specified.");
+ return;
+ }
+
+ void *arg = NULL;
+ if (desired_mode == CONTROL_START) {
+ int len = strlen(name);
+ if (len <= 0) {
+ FCGI_RejectJSON(context, "An experiment name must be specified.");
+ return;
+ } else if (PathExists(name) && !force) {
+ FCGI_RejectJSON(context, "An experiment with that name already exists.");
+ return;
+ }
+
+ arg = (void*)name;
+ }
+
+ const char *ret;
+ if ((ret = Control_SetMode(desired_mode, arg)) != NULL) {
+ FCGI_RejectJSON(context, ret);
+ } else {
+ FCGI_BeginJSON(context, STATUS_OK);
+ FCGI_JSONPair("description", "ok");
+ FCGI_EndJSON();
+ }
+}