[cmaster-next] [PATCH 9/9] lib: Allow json to work across different versions.
Donald Sharp
sharpd at cumulusnetworks.com
Wed Dec 14 15:49:53 EST 2016
The json_object_object_get_ex function is not fully available
across all versions of json. Write a wrapper to allow
it to work.
Ticket: CM-13872
Signed-off-by: Donald Sharp <sharpd at cumulusnetworks.com>
---
lib/json.c | 15 +++++++++++++++
lib/json.h | 4 ++++
2 files changed, 19 insertions(+)
diff --git a/lib/json.c b/lib/json.c
index 3edd146..ccbecb7 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -87,3 +87,18 @@ json_object_free(struct json_object *obj)
{
json_object_put(obj);
}
+
+#if !defined(HAVE_JSON_C_JSON_H)
+int
+json_object_object_get_ex(struct json_object *obj,
+ const char *key,
+ struct json_object **value)
+{
+ *value = json_object_object_get(obj, key);
+
+ if (*value)
+ return 1;
+
+ return 0;
+}
+#endif
diff --git a/lib/json.h b/lib/json.h
index bacc799..7e98614 100644
--- a/lib/json.h
+++ b/lib/json.h
@@ -32,6 +32,10 @@
* so let's just turn it back to the original usage.
*/
#define json_object_to_json_string_ext(A, B) json_object_to_json_string (A)
+
+extern int json_object_object_get_ex(struct json_object *obj,
+ const char *key,
+ struct json_object **value);
#endif
#include "command.h"
--
2.5.5
More information about the dev
mailing list