]>
git.proxmox.com Git - mirror_frr.git/blob - lib/json.c
2 * Copyright (C) 2015 Cumulus Networks, Inc.
4 * This file is part of GNU Zebra.
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
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.
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
28 * This function assumes that the json keyword
29 * is the *last* keyword on the line no matter
33 use_json (const int argc
, struct cmd_token
*argv
[])
38 if (argv
[argc
-1]->arg
&& strcmp(argv
[argc
-1]->arg
, "json") == 0)
45 json_object_string_add(struct json_object
* obj
, const char *key
,
48 json_object_object_add(obj
, key
, json_object_new_string(s
));
52 json_object_int_add(struct json_object
* obj
, const char *key
, int32_t i
)
54 json_object_object_add(obj
, key
, json_object_new_int(i
));
58 json_object_long_add(struct json_object
* obj
, const char *key
, int64_t i
)
60 #if defined(HAVE_JSON_C_JSON_H)
61 json_object_object_add(obj
, key
, json_object_new_int64(i
));
63 json_object_object_add(obj
, key
, json_object_new_int((int)i
));
68 json_object_boolean_false_add(struct json_object
* obj
, const char *key
)
70 json_object_object_add(obj
, key
, json_object_new_boolean(0));
74 json_object_boolean_true_add(struct json_object
* obj
, const char *key
)
76 json_object_object_add(obj
, key
, json_object_new_boolean(1));
80 json_object_lock(struct json_object
*obj
)
82 return json_object_get(obj
);
86 json_object_free(struct json_object
*obj
)
91 #if !defined(HAVE_JSON_C_JSON_H)
93 json_object_object_get_ex(struct json_object
*obj
,
95 struct json_object
**value
)
97 *value
= json_object_object_get(obj
, key
);