lua/uloop: 'end' is the keyword of Lua, use 'cancel' replace it.
[project/libubox.git] / blobmsg_json.h
1 /*
2  * Copyright (C) 2010-2012 Felix Fietkau <nbd@openwrt.org>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #ifndef __BLOBMSG_JSON_H
17 #define __BLOBMSG_JSON_H
18
19 #ifdef JSONC
20         #include <json.h>
21 #else
22         #include <json/json.h>
23 #endif
24
25 #include <stdbool.h>
26 #include "blobmsg.h"
27
28 bool blobmsg_add_object(struct blob_buf *b, json_object *obj);
29 bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object *obj);
30 bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str);
31 bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file);
32
33 typedef const char *(*blobmsg_json_format_t)(void *priv, struct blob_attr *attr);
34
35 char *blobmsg_format_json_with_cb(struct blob_attr *attr, bool list,
36                                   blobmsg_json_format_t cb, void *priv,
37                                   int indent);
38
39 static inline char *blobmsg_format_json(struct blob_attr *attr, bool list)
40 {
41         return blobmsg_format_json_with_cb(attr, list, NULL, NULL, -1);
42 }
43
44 static inline char *blobmsg_format_json_indent(struct blob_attr *attr, bool list, int indent)
45 {
46         return blobmsg_format_json_with_cb(attr, list, NULL, NULL, indent);
47 }
48
49 #endif