]>
git.proxmox.com Git - mirror_frr.git/blob - lib/json.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2015 Cumulus Networks, Inc.
12 * This function assumes that the json keyword
13 * is the *last* keyword on the line no matter
16 bool use_json(const int argc
, struct cmd_token
*argv
[])
21 if (argv
[argc
- 1]->arg
&& strmatch(argv
[argc
- 1]->text
, "json"))
27 struct json_object
*json_object_new_stringv(const char *fmt
, va_list args
)
29 struct json_object
*ret
;
32 text
= vasnprintfrr(MTYPE_TMP
, buf
, sizeof(buf
), fmt
, args
);
33 ret
= json_object_new_string(text
);
36 XFREE(MTYPE_TMP
, text
);
40 void json_array_string_add(json_object
*json
, const char *str
)
42 json_object_array_add(json
, json_object_new_string(str
));
45 void json_array_string_addv(json_object
*json
, const char *fmt
, va_list args
)
47 json_object_array_add(json
, json_object_new_stringv(fmt
, args
));
50 void json_object_string_add(struct json_object
*obj
, const char *key
,
53 json_object_object_add(obj
, key
, json_object_new_string(s
));
56 void json_object_string_addv(struct json_object
*obj
, const char *key
,
57 const char *fmt
, va_list args
)
59 json_object_object_add(obj
, key
, json_object_new_stringv(fmt
, args
));
62 void json_object_object_addv(struct json_object
*parent
,
63 struct json_object
*child
, const char *keyfmt
,
68 text
= vasnprintfrr(MTYPE_TMP
, buf
, sizeof(buf
), keyfmt
, args
);
69 json_object_object_add(parent
, text
, child
);
72 XFREE(MTYPE_TMP
, text
);
75 void json_object_int_add(struct json_object
*obj
, const char *key
, int64_t i
)
77 json_object_object_add(obj
, key
, json_object_new_int64(i
));
80 void json_object_double_add(struct json_object
*obj
, const char *key
, double i
)
82 json_object_object_add(obj
, key
, json_object_new_double(i
));
85 void json_object_boolean_false_add(struct json_object
*obj
, const char *key
)
87 json_object_object_add(obj
, key
, json_object_new_boolean(0));
90 void json_object_boolean_true_add(struct json_object
*obj
, const char *key
)
92 json_object_object_add(obj
, key
, json_object_new_boolean(1));
95 void json_object_boolean_add(struct json_object
*obj
, const char *key
, bool val
)
97 json_object_object_add(obj
, key
, json_object_new_boolean(val
));
100 struct json_object
*json_object_lock(struct json_object
*obj
)
102 return json_object_get(obj
);
105 void json_object_free(struct json_object
*obj
)
107 json_object_put(obj
);