Merge branch 'master' of https://github.com/szmoore/MCTX3420.git
[matches/MCTX3420.git] / server / control.c
1 #include "common.h"
2 #include "control.h"
3
4 /**
5  * System control handler. This covers control over all aspects of the system.
6  * E.g: Actuators, system commands (start/stop experiment/recording) etc
7  * @param context The context to work in
8  * @param params The input parameters
9  */
10 void Control_Handler(FCGIContext *context, char *params) {
11         const char *key, *value, *loginkey = NULL, *action = NULL;
12         bool force = false;
13         
14         while ((params = FCGI_KeyPair(params, &key, &value))) {
15                 if (!strcmp(key, "action"))
16                         action = value;
17                 else if (!strcmp(key, "key"))
18                         loginkey = value;
19                 else if (!strcmp(key, "force"))
20                         force = !force;
21                 else if (!strcmp(key, "id")) {
22                 
23                 }
24                 else if (!strcmp(key, "value")) {
25                 
26                 }
27         }
28         
29         if (!strcmp(action, "start")) {
30                 FCGI_Authorize(context, force);
31         } else if (!strcmp(action, "stop")) { //Don't require control key to stop...
32                 //EMERGENCY STOP!!
33                 FCGI_BeginJSON(context, STATUS_OK);
34                 FCGI_JSONPair("description", "stopped!"); //Not really
35                 FCGI_EndJSON();
36         } else {
37                 if (!FCGI_Authorized(context, loginkey)) {
38                         FCGI_BeginJSON(context, STATUS_UNAUTHORIZED);
39                         FCGI_JSONPair("description", "Invalid key specified.");
40                         FCGI_EndJSON();
41                         return;
42                 } else if (!strcmp(action, "end")) {
43                         FCGI_AuthorizeEnd(context);
44                 } else if (!strcmp(action, "set")) {
45                         FCGI_BeginJSON(context, STATUS_OK);
46                         FCGI_JSONPair("description", "actuated!");
47                         FCGI_EndJSON();
48                 }
49         }
50 }

UCC git Repository :: git.ucc.asn.au