-
- while ((params = FCGI_KeyPair(params, &key, &value))) {
- if (!strcmp(key, "action"))
- action = value;
- else if (!strcmp(key, "key"))
- loginkey = value;
- else if (!strcmp(key, "force"))
- force = !force;
- else if (!strcmp(key, "id")) {
-
- }
- else if (!strcmp(key, "value")) {
-
- }
- }
-
- if (!strcmp(action, "start")) {
- FCGI_Authorize(context, force);
- } else if (!strcmp(action, "stop")) { //Don't require control key to stop...
- //EMERGENCY STOP!!
- FCGI_BeginJSON(context, STATUS_OK);
- FCGI_JSONPair("description", "stopped!"); //Not really
- FCGI_EndJSON();
- } else {
- if (!FCGI_Authorized(context, loginkey)) {
- FCGI_BeginJSON(context, STATUS_UNAUTHORIZED);
- FCGI_JSONPair("description", "Invalid key specified.");
- FCGI_EndJSON();
- return;
- } else if (!strcmp(action, "end")) {
- FCGI_AuthorizeEnd(context);
- } else if (!strcmp(action, "set")) {
- FCGI_BeginJSON(context, STATUS_OK);
- FCGI_JSONPair("description", "actuated!");
- FCGI_EndJSON();
+
+ FCGIValue values[5] = {
+ {"action", &action, FCGI_REQUIRED(FCGI_STRING_T)},
+ {"key", &key, FCGI_STRING_T},
+ {"force", &force, FCGI_BOOL_T},
+ {"mode", &mode, FCGI_STRING_T},
+ {"name", &name, FCGI_STRING_T}
+ };
+
+ if (!FCGI_ParseRequest(context, params, values, 5))
+ return;
+
+ if (!strcmp(action, "gain")) {
+ FCGI_BeginControl(context, force);
+ } else {
+ if (!FCGI_HasControl(context, key)) {
+ FCGI_RejectJSONEx(context,
+ STATUS_UNAUTHORIZED, "Invalid control key specified.");
+
+ } else if (!strcmp(action, "release")) {
+ FCGI_EndControl(context);
+ } else if (!strcmp(action, "experiment")) {
+ if (!strcmp(mode, "start")) {
+ FCGI_BeginJSON(context, STATUS_OK);
+ FCGI_JSONPair("description", mode);
+ FCGI_EndJSON();
+ } else if (!strcmp(mode, "pause")) {
+ FCGI_BeginJSON(context, STATUS_OK);
+ FCGI_JSONPair("description", mode);
+ FCGI_EndJSON();
+ } else if (!strcmp(mode, "stop")) {
+ FCGI_BeginJSON(context, STATUS_OK);
+ FCGI_JSONPair("description", mode);
+ FCGI_EndJSON();
+ } else {
+ FCGI_RejectJSON(context, "Unknown experiment mode specified");
+ }
+ } else {
+ FCGI_RejectJSON(context, "Unknown action specified");