2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * @brief Function prototypes for missing functions in older json-c libraries.
21 * @file json_missing.h
23 * @copyright 2013-2014 Aaron Hurt <ahurt@anbcs.com>
26 #ifndef _jsonc_missing_h_
27 #define _jsonc_missing_h_
29 RCSIDH(jsonc_missing_h, "$Id$");
31 #include <json/json.h>
35 #ifndef HAVE_JSON_OBJECT_OBJECT_GET_EX
36 #include <json/json_object_private.h>
39 #ifndef HAVE_JSON_OBJECT_GET_STRING_LEN
40 int json_object_get_string_len(struct json_object *obj);
43 #ifndef HAVE_JSON_OBJECT_OBJECT_GET_EX
44 int json_object_object_get_ex(struct json_object* jso, const char *key, struct json_object **value);
47 #ifndef HAVE_JSON_TOKENER_PARSE_VERBOSE
48 struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error);
51 #ifndef HAVE_JSON_TOKENER_ERROR_DESC
52 const char *json_tokener_error_desc(enum json_tokener_error jerr);
55 #ifndef HAVE_JSON_TOKENER_GET_ERROR
56 enum json_tokener_error json_tokener_get_error(json_tokener *tok);
59 /* correct poor const handling within json-c library */
60 #ifdef json_object_object_foreach
61 #undef json_object_object_foreach
64 /* redefine with correct handling of const pointers */
65 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
66 #define json_object_object_foreach(obj, key, val) \
67 char *key; struct json_object *val; \
68 union ctn_u {const void *cdata; void *data; } ctn; \
69 for (struct lh_entry *entry = json_object_get_object(obj)->head; \
70 ({ if (entry) { key = (char *)entry->k; ctn.cdata = entry->v; \
71 val = (struct json_object *)ctn.data; }; entry; }); \
73 #else /* ANSI C or MSC */
74 #define json_object_object_foreach(obj,key,val) \
75 char *key; struct json_object *val; struct lh_entry *entry; \
76 union ctn_u {const void *cdata; void *data; } ctn; \
77 for (entry = json_object_get_object(obj)->head; \
78 (entry ? (key = (char *)entry->k, ctn.cdata = entry->v, \
79 val = (struct json_object *)ctn.data, entry) : 0); entry = entry->next)
80 #endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
83 /* correct poor const handling within json-c library */
84 #ifdef json_object_object_foreachC
85 #undef json_object_object_foreachC
88 /* redefine with correct const handling */
89 #define json_object_object_foreachC(obj,iter) \
90 union ctn_u {const void *cdata; void *data; } ctn; \
91 for (iter.entry = json_object_get_object(obj)->head; \
92 (iter.entry ? (iter.key = (char *)iter.entry->k, \
93 ctn.cdata = iter.entry->v, iter.val = (struct json_object*) ctn.data, iter.entry) : 0); \
94 iter.entry = iter.entry->next)
96 #endif /* _jsonc_missing_h_ */