-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_reader.c
More file actions
executable file
·34 lines (26 loc) · 802 Bytes
/
json_reader.c
File metadata and controls
executable file
·34 lines (26 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "json_reader.h"
keyValuePair *readJson(request_rec *r)
{
apr_off_t size;
const char *buffer;
keyValuePair *kvp;
if (util_read(r, &buffer, &size) == OK)
{
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "buffer : %s\n", buffer);
struct json_object *json_obj = json_tokener_parse(buffer);
if (!json_obj)
{
return NULL;
}
kvp = apr_pcalloc(r->pool, sizeof(keyValuePair) * (json_object_object_length(json_obj) + 1));
if (kvp == NULL) {
return NULL; // Handle memory allocation failure
}
// json_obj to string
const char *json_str = json_object_to_json_string(json_obj);
kvp[0].key = strdup("json");
kvp[0].value = strdup(json_str);
return kvp;
}
return NULL;
}