libubox
C utility functions for OpenWrt.
blobmsg_json.h
Go to the documentation of this file.
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 struct json_object;
20 
21 #include <stdbool.h>
22 #include "blobmsg.h"
23 
24 bool blobmsg_add_object(struct blob_buf *b, struct json_object *obj);
25 bool blobmsg_add_json_element(struct blob_buf *b, const char *name, struct json_object *obj);
26 bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str);
27 bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file);
28 
29 typedef const char *(*blobmsg_json_format_t)(void *priv, struct blob_attr *attr);
30 
31 char *blobmsg_format_json_with_cb(struct blob_attr *attr, bool list,
32  blobmsg_json_format_t cb, void *priv,
33  int indent);
34 
35 static inline char *blobmsg_format_json(struct blob_attr *attr, bool list)
36 {
37  return blobmsg_format_json_with_cb(attr, list, NULL, NULL, -1);
38 }
39 
40 static inline char *blobmsg_format_json_indent(struct blob_attr *attr, bool list, int indent)
41 {
42  return blobmsg_format_json_with_cb(attr, list, NULL, NULL, indent);
43 }
44 
46  blobmsg_json_format_t cb, void *priv,
47  int indent);
48 
49 static inline char *blobmsg_format_json_value(struct blob_attr *attr)
50 {
51  return blobmsg_format_json_value_with_cb(attr, NULL, NULL, -1);
52 }
53 
54 static inline char *blobmsg_format_json_value_indent(struct blob_attr *attr, int indent)
55 {
56  return blobmsg_format_json_value_with_cb(attr, NULL, NULL, indent);
57 }
58 
59 #endif
uint8_t name[]
Definition: blobmsg.h:1
char * blobmsg_format_json_value_with_cb(struct blob_attr *attr, blobmsg_json_format_t cb, void *priv, int indent)
Definition: blobmsg_json.c:356
static char * blobmsg_format_json_indent(struct blob_attr *attr, bool list, int indent)
Definition: blobmsg_json.h:40
static char * blobmsg_format_json_value(struct blob_attr *attr)
Definition: blobmsg_json.h:49
bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file)
Definition: blobmsg_json.c:107
const char *(* blobmsg_json_format_t)(void *priv, struct blob_attr *attr)
Definition: blobmsg_json.h:29
char * blobmsg_format_json_with_cb(struct blob_attr *attr, bool list, blobmsg_json_format_t cb, void *priv, int indent)
Definition: blobmsg_json.c:322
bool blobmsg_add_json_element(struct blob_buf *b, const char *name, struct json_object *obj)
Definition: blobmsg_json.c:47
bool blobmsg_add_object(struct blob_buf *b, struct json_object *obj)
Definition: blobmsg_json.c:26
bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str)
Definition: blobmsg_json.c:112
static char * blobmsg_format_json(struct blob_attr *attr, bool list)
Definition: blobmsg_json.h:35
static char * blobmsg_format_json_value_indent(struct blob_attr *attr, int indent)
Definition: blobmsg_json.h:54
static struct blob_buf b
Definition: jshn.c:40
Definition: blob.h:52
Definition: blob.h:64