Add API version and change FCGI_RejectJSON
[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 } StatusCodes;
21
22 typedef struct FCGIContext FCGIContext;
23 typedef void (*ModuleHandler) (FCGIContext *context, char *params);
24
25 extern void FCGI_BeginControl(FCGIContext *context, bool force);
26 extern void FCGI_EndControl(FCGIContext *context);
27 extern bool FCGI_HasControl(FCGIContext *context, const char *key);
28 extern char *FCGI_KeyPair(char *in, const char **key, const char **value);
29 extern void FCGI_BeginJSON(FCGIContext *context, StatusCodes status_code);
30 extern void FCGI_JSONPair(const char *key, const char *value);
31 extern void FCGI_JSONLong(const char *key, long value);
32 extern void FCGI_JSONDouble(const char *key, double value);
33 extern void FCGI_JSONBool(const char *key, bool value);
34 extern void FCGI_JSONKey(const char *key);
35 extern void FCGI_PrintRaw(const char *format, ...);
36 extern void FCGI_EndJSON();
37 extern void FCGI_RejectJSONEx(FCGIContext *context, StatusCodes status, const char *description);
38 extern void *FCGI_RequestLoop (void *data);
39
40 /**
41  * Shortcut to calling FCGI_RejectJSONEx. Sets the error code
42  * to STATUS_ERROR.
43  * @param context The context to work in
44  * @param description A short description of why the request was rejected.
45  * @see FCGI_RejectJSONEx
46  */
47 #define FCGI_RejectJSON(context, description) FCGI_RejectJSONEx(context, STATUS_ERROR, description)
48
49 /**
50  * Custom formatting function for the JSON value. To be used in 
51  * conjunction with FCGI_JSONKey. Care should be taken to ensure
52  * that valid JSON is produced.
53  * @see FCGI_PrintRaw for calling syntax
54  */
55 #define FCGI_JSONValue FCGI_PrintRaw
56
57 #endif
58
59

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