All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
json_missing.c
Go to the documentation of this file.
1 /*
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.
6  *
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.
11  *
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
15  */
16 
17 /**
18  * $Id: e2b4172ed46d336eeba735997d122381a26f621f $
19  *
20  * @brief Workarounds for missing functions in older json-c libraries.
21  * @file json_missing.c
22  *
23  * @author Aaron Hurt <ahurt@anbcs.com>
24  * @copyright 2013-2014 The FreeRADIUS Server Project.
25  */
26 RCSID("$Id: e2b4172ed46d336eeba735997d122381a26f621f $")
27 
28 #include <string.h>
29 #include "json_missing.h"
30 
31 #ifndef HAVE_JSON_OBJECT_GET_STRING_LEN
32 int json_object_get_string_len(json_object *obj) {
33  if (fr_json_object_get_type(obj) != json_type_string)
34  return 0;
35  return (int)strlen(json_object_get_string(obj));
36 }
37 #endif
38 
39 #ifndef HAVE_JSON_OBJECT_OBJECT_GET_EX
40 int json_object_object_get_ex(struct json_object *jso, const char *key, struct json_object **value) {
41  struct json_object *jobj;
42 
43  if ((jso == NULL) || (key == NULL)) return 0;
44  if (value != NULL) *value = NULL;
45 
46  switch (fr_json_object_get_type(jso)) {
47  case json_type_object:
48  jobj = json_object_object_get(jso, key);
49  if (jobj == NULL) return 0;
50 
51  if (value != NULL) *value = jobj;
52  return 1;
53 
54  default:
55  if (value != NULL) *value = NULL;
56  return 0;
57  }
58 }
59 #endif
60 
61 #ifndef HAVE_JSON_TOKENER_GET_ERROR
62 enum json_tokener_error json_tokener_get_error(json_tokener *tok) {
63  return tok->err;
64 }
65 #endif
66 
67 #ifndef HAVE_JSON_TOKENER_ERROR_DESC
68 const char *json_tokener_error_desc(enum json_tokener_error jerr) {
69  int jerr_int = (int)jerr;
70  if (json_tokener_errors[jerr_int] == NULL)
71  return "Unknown error, invalid json_tokener_error value passed to json_tokener_error_desc()";
72  return json_tokener_errors[jerr_int];
73 }
74 #endif
#define fr_json_object_get_type(_obj)
Definition: json_missing.h:56
int json_object_object_get_ex(struct json_object *jso, const char *key, struct json_object **value)
Definition: json_missing.c:40
const char * json_tokener_error_desc(enum json_tokener_error jerr)
Definition: json_missing.c:68
int json_object_get_string_len(json_object *obj)
Definition: json_missing.c:32
Function prototypes for missing functions in older json-c libraries.
enum json_tokener_error json_tokener_get_error(json_tokener *tok)
Definition: json_missing.c:62
#define RCSID(id)
Definition: build.h:135