blob: 3c13ebd3a5d94ee69c4eb41053e7fd6abc8f250a (
plain)
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
35
36
37
38
|
#define _POSIX_C_SOURCE 200809L
#include <string.h>
#include <jansson.h>
#include "instance_info.h"
#include "log.h"
struct instance_info *instance_info_from_json(char *json_data)
{
struct instance_info *info;
info = malloc(sizeof(struct instance_info));
json_t *root;
json_error_t error;
root = json_loads(json_data, 0, &error);
if (!root) {
log_msg(LOG_WARNING, "instance_info_from_json", "error: on line %d: %s",
error.line, error.text);
return NULL;
}
if (!json_is_object(root)) {
log_msg(LOG_WARNING, "instance_info_from_json", "root is not object");
json_decref(root);
return NULL;
}
json_t *title = json_object_get(root, "title");
if (!json_is_string(title)) {
log_msg(LOG_WARNING, "instance_info_from_json", "title is not string");
return NULL;
}
info->title = strdup(json_string_value(title));
json_decref(root);
return info;
}
|