]> git.proxmox.com Git - mirror_frr.git/blob - lib/json.c
Merge branch 'cmaster-next' into vtysh-grammar
[mirror_frr.git] / lib / json.c
1 /* json-c wrapper
2 * Copyright (C) 2015 Cumulus Networks, Inc.
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22 #include <zebra.h>
23
24 #include "command.h"
25 #include "lib/json.h"
26
27 /*
28 * This function assumes that the json keyword
29 * is the *last* keyword on the line no matter
30 * what.
31 */
32 int
33 use_json (const int argc, struct cmd_token *argv[])
34 {
35 if (argc == 0)
36 return 0;
37
38 if (argv[argc-1]->arg && strcmp(argv[argc-1]->arg, "json") == 0)
39 return 1;
40
41 return 0;
42 }
43
44 void
45 json_object_string_add(struct json_object* obj, const char *key,
46 const char *s)
47 {
48 json_object_object_add(obj, key, json_object_new_string(s));
49 }
50
51 void
52 json_object_int_add(struct json_object* obj, const char *key, int32_t i)
53 {
54 json_object_object_add(obj, key, json_object_new_int(i));
55 }
56
57 void
58 json_object_boolean_false_add(struct json_object* obj, const char *key)
59 {
60 json_object_object_add(obj, key, json_object_new_boolean(0));
61 }
62
63 void
64 json_object_boolean_true_add(struct json_object* obj, const char *key)
65 {
66 json_object_object_add(obj, key, json_object_new_boolean(1));
67 }
68
69 struct json_object*
70 json_object_lock(struct json_object *obj)
71 {
72 return json_object_get(obj);
73 }
74
75 void
76 json_object_free(struct json_object *obj)
77 {
78 json_object_put(obj);
79 }