From 14b5edb14010fae75c8a4313aba0dcdc68db48f0 Mon Sep 17 00:00:00 2001 From: Jakob Olsson <jakobols@kth.se> Date: Mon, 18 Jun 2018 10:51:50 +0200 Subject: [PATCH] lib_commons.*: some fixes to get_object_by_keys --- lib_commons.c | 9 ++++++--- lib_commons.h | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib_commons.c b/lib_commons.c index 57444f5..fa93a17 100644 --- a/lib_commons.c +++ b/lib_commons.c @@ -25,7 +25,7 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *data) struct json_object *get_object_by_keys(struct json_object *input_obj, char *input_key, char *output_key) { struct json_object *obj = NULL; - struct json_object *jstring = NULL; + struct json_object *jstring; enum json_type type; type = json_object_get_type(input_obj); @@ -34,10 +34,13 @@ struct json_object *get_object_by_keys(struct json_object *input_obj, char *inpu json_object_object_foreach(input_obj, key, val) { if (strcmp(input_key, key) != 0) - goto fail; + continue; obj = json_object_new_object(); - json_object_object_add(obj, output_key, val); + jstring = json_object_new_string((char *)json_object_get_string(val)); + json_object_object_add(obj, output_key, jstring); + + //json_object_object_add(obj, output_key, val); break; } diff --git a/lib_commons.h b/lib_commons.h index 401d843..3aa05e9 100644 --- a/lib_commons.h +++ b/lib_commons.h @@ -4,6 +4,9 @@ #include <stdlib.h> #include <string.h> #include <json-c/json.h> +#define PIN_STATUS_H "PinOptState" +#define PIN_STATUS_Z "pin_status" +#define PIN_STATUS "pin_status" /** * Struct used for parsing the curl response from the dongle. @@ -25,5 +28,5 @@ struct string { */ size_t write_func(void *buffer, size_t size, size_t nmemb, void *data); -struct json_object *get_object_by_key(json_object *json_obj, char *string, char *output_key); +struct json_object *get_object_by_keys(json_object *json_obj, char *string, char *output_key); #endif \ No newline at end of file -- GitLab