Add experimental support for querying a sensor an arbitrary range of points
[matches/MCTX3420.git] / server / fastcgi.h
1 /**
2  * @file fastcgi.h
3  * @brief Headers for the fastcgi web interface
4  */
5  
6 #ifndef _FASTCGI_H
7 #define _FASTCGI_H
8  
9 /**
10  * Status codes that fcgi module handlers can return
11  * Success status codes have values > 0
12  * Failure status codes have values <(=) 0 
13  * Note: 0 is counted as an error code to minimise confusion
14  * with in-browser JSON parsing error codes
15  */
16 typedef enum StatusCodes {
17         STATUS_OK = 1,
18         STATUS_ERROR = -1,
19         STATUS_UNAUTHORIZED = -2,
20         STATUS_OUTOFRANGE = -3
21 } StatusCodes;
22
23 typedef struct FCGIContext FCGIContext;
24 typedef void (*ModuleHandler) (FCGIContext *context, char *params);
25
26 extern void FCGI_BeginControl(FCGIContext *context, bool force);
27 extern void FCGI_EndControl(FCGIContext *context);
28 extern bool FCGI_HasControl(FCGIContext *context, const char *key);
29 extern char *FCGI_KeyPair(char *in, const char **key, const char **value);
30 extern void FCGI_BeginJSON(FCGIContext *context, StatusCodes status_code);
31 extern void FCGI_JSONPair(const char *key, const char *value);
32 extern void FCGI_JSONLong(const char *key, long value);
33 extern void FCGI_JSONDouble(const char *key, double value);
34 extern void FCGI_JSONBool(const char *key, bool value);
35 extern void FCGI_JSONKey(const char *key);
36 extern void FCGI_PrintRaw(const char *format, ...);
37 extern void FCGI_EndJSON();
38 extern void FCGI_RejectJSONEx(FCGIContext *context, StatusCodes status, const char *description);
39 extern void *FCGI_RequestLoop (void *data);
40
41 /**
42  * Shortcut to calling FCGI_RejectJSONEx. Sets the error code
43  * to STATUS_ERROR.
44  * @param context The context to work in
45  * @param description A short description of why the request was rejected.
46  * @see FCGI_RejectJSONEx
47  */
48 #define FCGI_RejectJSON(context, description) FCGI_RejectJSONEx(context, STATUS_ERROR, description)
49
50 /**
51  * Custom formatting function for the JSON value. To be used in 
52  * conjunction with FCGI_JSONKey. Care should be taken to ensure
53  * that valid JSON is produced.
54  * @see FCGI_PrintRaw for calling syntax
55  */
56 #define FCGI_JSONValue FCGI_PrintRaw
57
58 #endif
59
60

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