2 * Copyright (c) 2018, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
35 /* Utilities for working with JSON/jansson */
37 #ifndef TRUST_ROUTER_TR_JSON_UTIL_H
38 #define TRUST_ROUTER_TR_JSON_UTIL_H
41 * @def OBJECT_SET_OR_FAIL(job, key, val)
42 * Add a key/value pair to an object or jump to the cleanup label
43 * if the value is null.
45 * @param jobj JSON object instance to receive the key/value pair
46 * @param key key to set
47 * @param val value to set
49 #define OBJECT_SET_OR_FAIL(jobj, key, val) \
52 json_object_set_new((jobj),(key),(val)); \
58 * @def OBJECT_SET_OR_SKIP(job, key, val)
59 * Add a key/value pair to an object only if it is non-null.
61 * @param jobj JSON object instance to receive the key/value pair
62 * @param key key to set
63 * @param val value to set
65 #define OBJECT_SET_OR_SKIP(jobj, key, val) \
68 json_object_set_new((jobj),(key),(val)); \
73 * @def ARRAY_APPEND_OR_FAIL(job, key, val)
74 * Append a value to an array or jump to the cleanup label
75 * if the value is null.
77 * @param jobj JSON array instance to receive the value
78 * @param val value to set
80 #define ARRAY_APPEND_OR_FAIL(jary, val) \
83 json_array_append_new((jary),(val)); \
89 #endif //TRUST_ROUTER_TR_JSON_UTIL_H