diff options
| author | nirav <nirav@teisuu.com> | 2019-03-07 01:27:55 +0530 | 
|---|---|---|
| committer | Dandelion <nirav@teisuu.com> | 2019-03-07 01:27:55 +0530 | 
| commit | 6dd58a30761eca36544c4e815b36907eab084949 (patch) | |
| tree | c1bc857a14fffe6f35f7405f133c0ed114aec1a4 /src/instance_info.c | |
| download | ap_client-6dd58a30761eca36544c4e815b36907eab084949.tar.gz ap_client-6dd58a30761eca36544c4e815b36907eab084949.zip | |
Initial commit
Diffstat (limited to 'src/instance_info.c')
| -rw-r--r-- | src/instance_info.c | 36 | 
1 files changed, 36 insertions, 0 deletions
| diff --git a/src/instance_info.c b/src/instance_info.c new file mode 100644 index 0000000..6dab351 --- /dev/null +++ b/src/instance_info.c @@ -0,0 +1,36 @@ +#define _POSIX_C_SOURCE 200809L +#include <string.h> +#include <jansson.h> +#include "instance_info.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) { +        fprintf(stderr, "error: on line %d: %s\n", error.line, error.text); +        return NULL; +    } + +    if (!json_is_object(root)) { +        fprintf(stderr, "root is not object"); +        json_decref(root); +        return NULL; +    } + +    json_t *title = json_object_get(root, "title"); +    if (!json_is_string(title)) { +        fprintf(stderr, "title is not string"); +        return NULL; +    } +    info->title = strdup(json_string_value(title)); + +    json_decref(root); +    return info; +} | 
