Package: opensips / 2.2.2-3.1

json-c-0.13.patch Patch series | download
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
Subject: [PATCH] modules/json: Properly detect json-c version and adaptions
 for v0.13
Subject: [PATCH] mongodb: remove deprecated is_error() in json-c 0.13

--- a/modules/cachedb_mongodb/cachedb_mongodb_json.c
+++ b/modules/cachedb_mongodb/cachedb_mongodb_json.c
@@ -162,7 +162,7 @@ int json_to_bson(char *json,bson *bb)
 	LM_DBG("Trying to convert [%s]\n",json);
 
 	obj=json_tokener_parse(json);
-	if (is_error(obj)) {
+	if (!obj) {
 		LM_ERR("Failed to parse JSON: %s\n",json);
 		return -2;
 	}
diff --git a/modules/json/Makefile b/modules/json/Makefile
index 5c514655be..479bec7018 100644
--- a/modules/json/Makefile
+++ b/modules/json/Makefile
@@ -2,7 +2,7 @@
 #
 # Memcached implementation for memcache API.
 #
-# 
+#
 # WARNING: do not run this directly, it should be run by the master Makefile
 
 include ../../Makefile.defs
@@ -23,8 +23,23 @@ ifeq ($(JSON_BUILDER),)
 	DEFS += -I$(LOCALBASE)/include -I$(SYSBASE)/include
 	LIBS += -L$(LOCALBASE)/lib -ljson
 else
-	JSON_LIB_VER = $(shell $(JSON_BUILDER) --modversion | sed  "s/\.\([0-9]\)\./.0\1./g" | sed  "s/\.\([0-9]\)\$$/.0\1/g" | tr -d "." | sed -e "s/^0*//" )
-	DEFS += $(shell $(JSON_BUILDER) --cflags) -DJSON_LIB_VERSION=$(JSON_LIB_VER)
+	JSON_PKG_VER = $(shell $(JSON_BUILDER) --modversion)
+	JSON_PKG_MAJOR = $(shell \
+		ver_tmp=`echo '$(JSON_PKG_VER)' | cut -f1 -d.`; \
+		if [ -z "$$ver_tmp" ]; then ver_tmp=0; fi; \
+		echo "$$ver_tmp";)
+	JSON_PKG_MINOR = $(shell \
+		ver_tmp=`echo '$(JSON_PKG_VER)' | cut -f2 -d.`; \
+		if [ -z "$$ver_tmp" ]; then ver_tmp=0; fi; \
+		echo "$$ver_tmp";)
+	JSON_PKG_MICRO = $(shell \
+		ver_tmp=`echo '$(JSON_PKG_VER)' | cut -f3 -d.`; \
+		if [ -z "$$ver_tmp" ]; then ver_tmp=0; fi; \
+		echo "$$ver_tmp";)
+	DEFS += $(shell $(JSON_BUILDER) --cflags) \
+		-DJSON_PKG_MAJOR=$(JSON_PKG_MAJOR) \
+		-DJSON_PKG_MINOR=$(JSON_PKG_MINOR) \
+		-DJSON_PKG_MICRO=$(JSON_PKG_MICRO)
 	LIBS += $(shell $(JSON_BUILDER) --libs)
 endif
 
diff --git a/modules/json/array_del.c b/modules/json/array_del.c
index b23f6d3b39..9be6e2f847 100644
--- a/modules/json/array_del.c
+++ b/modules/json/array_del.c
@@ -22,27 +22,34 @@
  * History:
  * ---------
  *  2009-09-04  first version (andreidragus)
+ *  2017-12-12  use opensips_json_c_helper.h (besser82)
  */
 
-#include <json.h>
-#include <json_object_private.h>
+#include "opensips_json_c_helper.h"
 
-void array_list_del_idx( struct array_list * arr, int idx)
+#if JSON_C_VERSION_NUM < JSON_C_VER_013
+void array_list_del_idx(struct array_list * arr, int idx)
 {
 	int i;
 
-	if( idx >= arr->length)
+	if(idx >= arr->length)
 		return;
 
 
 	arr->free_fn(arr->array[idx]);
 	arr->length--;
 
-	for( i=idx; i<arr->length; i++ )
+	for(i=idx; i<arr->length; i++)
 		arr->array[i]  = arr->array[i+1];
 };
+#endif
 
 void json_object_array_del(struct json_object* obj, int idx)
 {
+#if JSON_C_VERSION_NUM >= JSON_C_VER_013
+	struct array_list * arr = json_object_get_array(obj);
+	array_list_del_idx(arr, idx, arr->length);
+#else
 	array_list_del_idx(obj->o.c_array, idx);
+#endif
 };
diff --git a/modules/json/json.c b/modules/json/json.c
index 452e4a8010..c709e44cf3 100644
--- a/modules/json/json.c
+++ b/modules/json/json.c
@@ -22,6 +22,7 @@
  * History:
  * ---------
  *  2009-09-04  first version (andreidragus)
+ *  2017-12-12  use opensips_json_c_helper.h (besser82)
  */
 
 
@@ -43,14 +44,9 @@
 #include "../../mi/mi.h"
 #include "../tm/tm_load.h"
 #include "../rr/api.h"
+#include "opensips_json_c_helper.h"
 
 
-#include <json.h>
-#include <json_object_private.h>
-
-
-#define JSON_BUFF_SIZE 4096
-
 enum
 {
 	TAG_KEY = 1,
@@ -93,7 +89,7 @@ typedef struct _json_name
 }json_name;
 
 pv_json_t * all;
-char buff[JSON_BUFF_SIZE];
+char buff[JSON_FILE_BUF_SIZE];
 
 static int mod_init(void);
 static int child_init(int );
@@ -297,19 +293,16 @@ json_t * get_object(pv_json_t * var, pv_param_t* pvp ,  json_tag ** tag,
 				!json_object_is_type( cur_obj, json_type_object ) )
 				goto error;
 
-#if JSON_LIB_VERSION < 10
+#if JSON_C_VERSION_NUM >= JSON_C_VER_010
+			if (!json_object_object_get_ex( cur_obj,buff, &cur_obj ) &&
+				tag == NULL)
+				goto error;
+#else
 			cur_obj = json_object_object_get( cur_obj, buff );
 
 			if( cur_obj == NULL && tag == NULL)
 				goto error;
-#else
-			if (!json_object_object_get_ex( cur_obj,buff, &cur_obj ) &&
-				tag == NULL)
-				goto error;
 #endif
-
-
-
 		}
 
 		if( cur_tag->type & TAG_IDX )
@@ -417,7 +410,7 @@ int pv_get_json (struct sip_msg* msg,  pv_param_t* pvp, pv_value_t* val)
 	{
 		val->flags = PV_VAL_STR;
 		val->rs.s = (char*)json_object_get_string( obj );
-#if JSON_LIB_VERSION >= 10
+#if JSON_C_VERSION_NUM >= JSON_C_VER_010
 		val->rs.len = json_object_get_string_len( obj );
 #else
 		val->rs.len = strlen(val->rs.s);
@@ -589,7 +582,7 @@ int pv_set_json (struct sip_msg* msg,  pv_param_t* pvp, int flag ,
 		if (obj == NULL)
 		{
 			LM_ERR("Error parsing json: %s\n",
-#if JSON_LIB_VERSION >= 10
+#if JSON_C_VERSION_NUM >= JSON_C_VER_010
 				json_tokener_error_desc(parse_status)
 #else
 				json_tokener_errors[(unsigned long)obj]
diff --git a/modules/json/opensips_json_c_helper.h b/modules/json/opensips_json_c_helper.h
new file mode 100644
index 0000000000..71c5c21899
--- /dev/null
+++ b/modules/json/opensips_json_c_helper.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2017 Björn Esser <besser82@fedoraproject.org>
+ *
+ * This file is part of opensips, a free SIP server.
+ *
+ * opensips 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.
+ *
+ * opensips 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * History:
+ * ---------
+ *  2017-12-12 first version (besser82)
+ */
+
+#ifndef OPENSIPS_JSON_C_HELPER_H
+#define OPENSIPS_JSON_C_HELPER_H
+
+// If those are not defined, we assume to build against json-c v0.9.
+// Starting with v0.11 there is json_c_version.h, which we prefer
+// anyways, so there are no regressions in this case.  Everything
+// conditionalized for v0.10 or later doesn't produce any fallout,
+// when we are asuming v0.9 and building against v0.10.
+#ifndef JSON_PKG_MAJOR
+#define JSON_PKG_MAJOR	0
+#endif
+#ifndef JSON_PKG_MINOR
+#define JSON_PKG_MINOR	9
+#endif
+#ifndef JSON_PKG_MICRO
+#define JSON_PKG_MICRO	0
+#endif
+
+// json.h automatically includes json_c_version.h, if available.
+#include <json.h>
+
+// We prefer JSON_C_VERSION_NUM defined in json_c_version.h.  If it is
+// not defined, we construct it the same way from our JSON_PKG_* defines.
+#ifndef JSON_C_VERSION_NUM
+#define JSON_C_VERSION_NUM (JSON_PKG_MAJOR << 16) | \
+			   (JSON_PKG_MINOR << 8)  | \
+			    JSON_PKG_MICRO
+#endif
+
+// Macros for checking specific versions.
+#define JSON_C_VER_010 (10 << 8)
+#define JSON_C_VER_013 (13 << 8)
+
+// json_object_private.h is gone and not needed anymore in json-c v0.13+.
+#if JSON_C_VERSION_NUM < JSON_C_VER_013
+#include <json_object_private.h>
+#endif
+
+// Newer versions of json-c define this in their headers, so we prefer
+// their definition in that case.
+#ifndef JSON_FILE_BUF_SIZE
+#define JSON_FILE_BUF_SIZE 4096
+#endif
+
+#endif // OPENSIPS_JSON_C_HELPER_H