blobmsg_json: add blobmsg_add_json_from_file

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
Felix Fietkau 2013-05-29 12:14:40 +02:00
parent c4b79e4b54
commit 54a0b49326
2 changed files with 12 additions and 3 deletions

View file

@ -71,12 +71,10 @@ bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object
return ret; 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; bool ret = false;
obj = json_tokener_parse(str);
if (is_error(obj)) if (is_error(obj))
return false; return false;
@ -90,6 +88,16 @@ out:
return ret; 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 { struct strbuf {
int len; int len;

View file

@ -28,6 +28,7 @@
bool blobmsg_add_object(struct blob_buf *b, json_object *obj); 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_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_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); typedef const char *(*blobmsg_json_format_t)(void *priv, struct blob_attr *attr);