From 54a0b49326904fc3281c72cd9d9f1fe950e39d05 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 29 May 2013 12:14:40 +0200 Subject: [PATCH] blobmsg_json: add blobmsg_add_json_from_file Signed-off-by: Felix Fietkau --- blobmsg_json.c | 14 +++++++++++--- blobmsg_json.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/blobmsg_json.c b/blobmsg_json.c index f166358..7a4ab7b 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -71,12 +71,10 @@ bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object return ret; } -bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str) +static bool __blobmsg_add_json(struct blob_buf *b, json_object *obj) { - json_object *obj; bool ret = false; - obj = json_tokener_parse(str); if (is_error(obj)) return false; @@ -90,6 +88,16 @@ out: return ret; } +bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file) +{ + return __blobmsg_add_json(b, json_object_from_file(file)); +} + +bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str) +{ + return __blobmsg_add_json(b, json_tokener_parse(str)); +} + struct strbuf { int len; diff --git a/blobmsg_json.h b/blobmsg_json.h index 45ebd6d..e8036eb 100644 --- a/blobmsg_json.h +++ b/blobmsg_json.h @@ -28,6 +28,7 @@ bool blobmsg_add_object(struct blob_buf *b, json_object *obj); bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object *obj); bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str); +bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file); typedef const char *(*blobmsg_json_format_t)(void *priv, struct blob_attr *attr); -- 2.25.1