1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* $Id$
*
* @brief Function prototypes for missing functions in older json-c libraries.
* @file jsonc_missing.h
*
* @author Aaron Hurt <ahurt@anbcs.com>
* @copyright 2013-2014 The FreeRADIUS Server Project.
*/
#ifndef _jsonc_missing_h_
#define _jsonc_missing_h_
RCSIDH(jsonc_missing_h, "$Id$")
#include "config.h"
#if defined(HAVE_JSONMC_JSON_H)
# include <json-c/json.h>
#elif defined(HAVE_JSON_JSON_H)
# include <json/json.h>
#endif
#ifndef HAVE_JSON_C_VERSION
const char *json_c_version(void);
#endif
#ifndef HAVE_JSON_OBJECT_OBJECT_GET_EX
# include <json/json_object_private.h>
#endif
#ifndef HAVE_JSON_OBJECT_GET_STRING_LEN
int json_object_get_string_len(struct json_object *obj);
#endif
#ifndef HAVE_JSON_OBJECT_OBJECT_GET_EX
int json_object_object_get_ex(struct json_object* jso, const char *key, struct json_object **value);
#endif
#ifndef HAVE_JSON_TOKENER_ERROR_DESC
const char *json_tokener_error_desc(enum json_tokener_error jerr);
#endif
#ifndef HAVE_JSON_TOKENER_GET_ERROR
enum json_tokener_error json_tokener_get_error(json_tokener *tok);
#endif
/* correct poor const handling within json-c library */
#ifdef json_object_object_foreach
# undef json_object_object_foreach
#endif
/* redefine with correct handling of const pointers */
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define json_object_object_foreach(obj, key, val) \
char *key = NULL; \
struct json_object *val = NULL; \
union ctn_u {const void *cdata; void *data; } ctn; \
for (struct lh_entry *entry = json_object_get_object(obj)->head; \
({ if (entry) { key = (char *)entry->k; ctn.cdata = entry->v; \
val = (struct json_object *)ctn.data; }; entry; }); \
entry = entry->next)
#else /* ANSI C or MSC */
# define json_object_object_foreach(obj,key,val) \
char const *key = NULL; \
struct json_object *val = NULL; \
struct lh_entry *entry; \
union ctn_u {const void *cdata; void *data; } ctn; \
for (entry = json_object_get_object(obj)->head; \
(entry ? (key = (char const *)entry->k, ctn.cdata = entry->v, \
val = (struct json_object *)ctn.data, entry) : 0); entry = entry->next)
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */
#endif /* _jsonc_missing_h_ */
|