diff options
Diffstat (limited to 'src/mint/taler-mint-httpd_json.h')
-rw-r--r-- | src/mint/taler-mint-httpd_json.h | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/mint/taler-mint-httpd_json.h b/src/mint/taler-mint-httpd_json.h new file mode 100644 index 000000000..da601401f --- /dev/null +++ b/src/mint/taler-mint-httpd_json.h | |||
@@ -0,0 +1,119 @@ | |||
1 | |||
2 | |||
3 | #ifndef TALER_MICROHTTPD_LIB_H_ | ||
4 | #define TALER_MICROHTTPD_LIB_H_ | ||
5 | |||
6 | |||
7 | #include <microhttpd.h> | ||
8 | #include <jansson.h> | ||
9 | |||
10 | |||
11 | /** | ||
12 | * Constants for JSON navigation description. | ||
13 | */ | ||
14 | enum | ||
15 | { | ||
16 | /** | ||
17 | * Access a field. | ||
18 | * Param: const char * | ||
19 | */ | ||
20 | JNAV_FIELD, | ||
21 | /** | ||
22 | * Access an array index. | ||
23 | * Param: int | ||
24 | */ | ||
25 | JNAV_INDEX, | ||
26 | /** | ||
27 | * Return base32crockford encoded data of | ||
28 | * constant size. | ||
29 | * Params: (void *, size_t) | ||
30 | */ | ||
31 | JNAV_RET_DATA, | ||
32 | /** | ||
33 | * Return base32crockford encoded data of | ||
34 | * variable size. | ||
35 | * Params: (void **, size_t *) | ||
36 | */ | ||
37 | JNAV_RET_DATA_VAR, | ||
38 | /** | ||
39 | * Return a json object, which must be | ||
40 | * of the given type (JSON_* type constants, | ||
41 | * or -1 for any type). | ||
42 | * Params: (int, json_t **) | ||
43 | */ | ||
44 | JNAV_RET_TYPED_JSON | ||
45 | }; | ||
46 | |||
47 | |||
48 | |||
49 | /** | ||
50 | * Send JSON object as response. Decreases | ||
51 | * the reference count of the JSON object. | ||
52 | * | ||
53 | * @param connection the MHD connection | ||
54 | * @param json the json object | ||
55 | * @param status_code the http status code | ||
56 | * @return MHD result code (MHD_YES on success) | ||
57 | */ | ||
58 | int | ||
59 | send_response_json (struct MHD_Connection *connection, | ||
60 | json_t *json, | ||
61 | unsigned int status_code); | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Send a JSON object via an MHD connection, | ||
66 | * specified with the JANSSON pack syntax (see json_pack). | ||
67 | * | ||
68 | * @param connection connection to send the JSON over | ||
69 | * @param http_code HTTP status for the response | ||
70 | * @param fmt format string for pack | ||
71 | * @param ... varargs | ||
72 | * @return MHD_YES on success or MHD_NO on error | ||
73 | */ | ||
74 | int | ||
75 | request_send_json_pack (struct MHD_Connection *connection, | ||
76 | unsigned int http_code, | ||
77 | const char *fmt, ...); | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Process a POST request containing a JSON object. | ||
82 | * | ||
83 | * @param connection the MHD connection | ||
84 | * @param con_cs the closure (contains a 'struct Buffer *') | ||
85 | * @param upload_data the POST data | ||
86 | * @param upload_data_size the POST data size | ||
87 | * @param json the JSON object for a completed request | ||
88 | * | ||
89 | * @returns | ||
90 | * GNUNET_YES if json object was parsed | ||
91 | * GNUNET_NO is request incomplete or invalid | ||
92 | * GNUNET_SYSERR on internal error | ||
93 | */ | ||
94 | int | ||
95 | process_post_json (struct MHD_Connection *connection, | ||
96 | void **con_cls, | ||
97 | const char *upload_data, | ||
98 | size_t *upload_data_size, | ||
99 | json_t **json); | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Navigate through a JSON tree. | ||
104 | * | ||
105 | * Sends an error response if navigation is impossible (i.e. | ||
106 | * the JSON object is invalid) | ||
107 | * | ||
108 | * @param connection the connection to send an error response to | ||
109 | * @param root the JSON node to start the navigation at. | ||
110 | * @param ... navigation specification (see JNAV_*) | ||
111 | * @return GNUNET_YES if navigation was successful | ||
112 | * GNUNET_NO if json is malformed, error response was generated | ||
113 | * GNUNET_SYSERR on internal error | ||
114 | */ | ||
115 | int | ||
116 | request_json_require_nav (struct MHD_Connection *connection, | ||
117 | const json_t *root, ...); | ||
118 | |||
119 | #endif /* TALER_MICROHTTPD_LIB_H_ */ | ||