Notes from meeting
[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 #define FCGI_PARAM_REQUIRED (1 << 0)
24 #define FCGI_PARAM_RECEIVED (1 << 1)
25 #define FCGI_BOOL_T (1 << 2)
26 #define FCGI_INT_T      (1 << 3)
27 #define FCGI_LONG_T (1 << 4)
28 #define FCGI_DOUBLE_T (1 << 5)
29 #define FCGI_STRING_T (1 << 6)
30 #define FCGI_REQUIRED(x) ((x) | FCGI_PARAM_REQUIRED)
31 #define FCGI_IS_REQUIRED(x) ((x) & FCGI_PARAM_REQUIRED)
32 #define FCGI_RECEIVED(x) ((x) & FCGI_PARAM_RECEIVED)
33 #define FCGI_TYPE(x) ((x) & ~(FCGI_PARAM_REQUIRED | FCGI_PARAM_RECEIVED))
34
35 typedef struct FCGIValue {
36         const char *key;
37         void *value;
38         unsigned flags;
39 } FCGIValue;
40
41 typedef struct FCGIContext FCGIContext;
42 typedef void (*ModuleHandler) (FCGIContext *context, char *params);
43
44 extern void FCGI_BeginControl(FCGIContext *context, bool force);
45 extern void FCGI_EndControl(FCGIContext *context);
46 extern bool FCGI_HasControl(FCGIContext *context, const char *key);
47 extern char *FCGI_KeyPair(char *in, const char **key, const char **value);
48 extern bool FCGI_ParseRequest(FCGIContext *context, char *params, FCGIValue values[], size_t count);
49 extern void FCGI_BeginJSON(FCGIContext *context, StatusCodes status_code);
50 extern void FCGI_JSONPair(const char *key, const char *value);
51 extern void FCGI_JSONLong(const char *key, long value);
52 extern void FCGI_JSONDouble(const char *key, double value);
53 extern void FCGI_JSONBool(const char *key, bool value);
54 extern void FCGI_JSONKey(const char *key);
55 extern void FCGI_PrintRaw(const char *format, ...);
56 extern void FCGI_EndJSON();
57 extern char *FCGI_EscapeJSON(char *buf);
58 extern void FCGI_RejectJSONEx(FCGIContext *context, StatusCodes status, const char *description);
59 extern void *FCGI_RequestLoop (void *data);
60
61 extern void FCGI_WriteBinary(void * data, size_t size, size_t num_elem);
62
63 /**
64  * Shortcut to calling FCGI_RejectJSONEx. Sets the error code
65  * to STATUS_ERROR.
66  * @param context The context to work in
67  * @param description A short description of why the request was rejected.
68  * @see FCGI_RejectJSONEx
69  */
70 #define FCGI_RejectJSON(context, description) FCGI_RejectJSONEx(context, STATUS_ERROR, description)
71
72 /**
73  * Custom formatting function for the JSON value. To be used in 
74  * conjunction with FCGI_JSONKey. Care should be taken to ensure
75  * that valid JSON is produced.
76  * @see FCGI_PrintRaw for calling syntax
77  */
78 #define FCGI_JSONValue FCGI_PrintRaw
79
80 #endif
81
82

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