This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathold-json-c-version.patch
210 lines (197 loc) · 6.62 KB
/
old-json-c-version.patch
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
diff --git a/Makefile b/Makefile
index e84074c..553fe2a 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ HELPPATCHES = json-help.pd urlparams-help.pd rest-help.pd
ALL_CFLAGS = -I"$(PD_INCLUDE)" -std=c99
ALL_LDFLAGS =
SHARED_LDFLAGS =
-ALL_LIBS = -lcurl -ljson-c -loauth
+ALL_LIBS = -lcurl -ljson -loauth
LIBS_windows = -lpthread -lm -lidn -lintl -lwldap32 -lgnutls -lhogweed -lgmp -lssl \
-liconv -lnettle -lssh2 -lgcrypt -lgpg-error -lcrypto \
-lws2_32 -lgdi32 -lcrypt32 -lz
diff --git a/debian/changelog b/debian/changelog
index 15fb989..8e747c1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,9 +1,9 @@
-pd-purest-json (1.2.0) UNRELEASED; urgency=low
+pd-purest-json (1.2.0+json-c-0.10) UNRELEASED; urgency=low
* [oauth]: PATCH, TRACE and OPTIONS request implemented
- -- Thomas Mayer <[email protected]> Sun, 02 Feb 2015 15:00:00 +0100
+ -- Thomas Mayer <[email protected]> Sun, 01 Feb 2015 15:00:00 +0100
-pd-purest-json (1.1.0) UNRELEASED; urgency=low
+pd-purest-json (1.1.0+json-c-0.10) UNRELEASED; urgency=low
* [rest]: HEAD, PATCH, TRACE and OPTIONS request implemented
* [oauth]: HEAD request implemented
* Bug fixes:
@@ -13,7 +13,7 @@ pd-purest-json (1.1.0) UNRELEASED; urgency=low
-- Thomas Mayer <[email protected]> Sat, 14 Jun 2014 23:00:00 +0200
-pd-purest-json (1.0.0) UNRELEASED; urgency=low
+pd-purest-json (1.0.0-libjson0.10) UNRELEASED; urgency=low
* Info for users while loading object
* Bug fixes in [json-encode]:
- array handling
@@ -22,9 +22,8 @@ pd-purest-json (1.0.0) UNRELEASED; urgency=low
-- Thomas Mayer <[email protected]> Fri, 03 Jan 2014 15:00:00 +0100
-pd-purest-json (0.15.0) UNRELEASED; urgency=low
+pd-purest-json (0.15.0-libjson0.10) UNRELEASED; urgency=low
* Cancellation is now faster
- * Switch to json-c 0.11
* Refactoring of code
* Breaking changes:
- [oauth] and [rest]:
diff --git a/debian/control b/debian/control
index d936a8d..12be207 100644
--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,7 @@ Priority: optional
Maintainer: Thomas Mayer <[email protected]>
Build-Depends: debhelper (>= 8.1.3),
puredata-dev | puredata,
- libjson-c-dev,
+ libjson0-dev,
libcurl4-gnutls-dev | libcurl4-openssl-dev,
liboauth-dev
Standards-Version: 3.9.2
diff --git a/src/json-decode.c b/src/json-decode.c
index 52d582f..54d0bfd 100644
--- a/src/json-decode.c
+++ b/src/json-decode.c
@@ -45,7 +45,11 @@ static void jdec_output_array(json_object *jobj, t_outlet *data_outlet, t_outlet
/* output json data */
static void jdec_output(json_object *jobj, t_outlet *data_outlet, t_outlet *done_outlet);
/* checks for valid json string and converts to json */
-static void jdec_output_string(const char *json_string, t_json_decode *jdec);
+static void jdec_output_string(char *json_string, t_json_decode *jdec);
+#if JSON_C_FIX
+/* workaround in json-c < 0.10 for https://github.com/json-c/json-c/issues/3 */
+static char *lowercase_unicode(char *orig, size_t *memsize);
+#endif
/* begin implementations */
static void jdec_output_object(json_object *const jobj, t_outlet *const data_outlet, t_outlet *const done_outlet) {
@@ -102,6 +106,60 @@ static void jdec_output_array(json_object *jobj, t_outlet *const data_outlet, t_
}
}
+#if JSON_C_FIX
+static char *lowercase_unicode(char *const orig, size_t *memsize) {
+ const char *const unicode_intro = "\\";
+ const short uni_len = 4; /*TODO: get real length, we just assume 4 for now */
+
+ char *cleaned_string = string_create(memsize, strlen(orig));
+ if (cleaned_string == NULL)
+ if (cleaned_string != NULL) {
+ MYERROR("Could not allocate memory");
+ return NULL;
+ }
+
+ if (strlen(orig) <= 0) {
+ return cleaned_string;
+ }
+
+ char *segment = strtok(orig, unicode_intro);
+ memset(cleaned_string, 0x00, strlen(orig) + 1);
+ strcpy(cleaned_string, segment);
+ segment = strtok(NULL, unicode_intro);
+
+ while(segment != NULL) {
+ strcat(cleaned_string, unicode_intro);
+ if (segment[0] == 'u') {
+ for (short i = 1; i < 1 + uni_len; i++) {
+ switch (segment[i]) {
+ case 'A':
+ segment[i] = 'a';
+ break;
+ case 'B':
+ segment[i] = 'b';
+ break;
+ case 'C':
+ segment[i] = 'c';
+ break;
+ case 'D':
+ segment[i] = 'd';
+ break;
+ case 'E':
+ segment[i] = 'e';
+ break;
+ case 'F':
+ segment[i] = 'f';
+ break;
+ }
+ }
+ }
+ strcat(cleaned_string, segment);
+ segment = strtok(NULL, unicode_intro);
+ }
+ return cleaned_string;
+}
+#endif
+
static void jdec_output(json_object *const jobj, t_outlet *const data_outlet, t_outlet *const done_outlet) {
t_atom out_data[2];
t_float out_float;
@@ -146,9 +204,17 @@ static void jdec_output(json_object *const jobj, t_outlet *const data_outlet, t_
}
}
-static void jdec_output_string(const char *const json_string, t_json_decode *const jdec) {
- json_object *const jobj = json_tokener_parse(json_string);
-
+static void jdec_output_string(char *const json_string, t_json_decode *const jdec) {
+ json_object *jobj;
+#if JSON_C_FIX
+ size_t memsize = 0;
+ /* Needed because of bug in json-c 0.9 */
+ char* corrected_json_string = lowercase_unicode(json_string, &memsize);
+ /* Parse JSON */
+ jobj = json_tokener_parse(corrected_json_string);
+#else
+ jobj = json_tokener_parse(json_string);
+#endif
if (!is_error(jobj)) {
jdec_output(jobj, jdec->x_ob.ob_outlet, jdec->done_outlet);
/* TODO: This sometimes results in a segfault. Why? */
@@ -156,6 +222,11 @@ static void jdec_output_string(const char *const json_string, t_json_decode *con
} else {
pd_error(jdec, "Not a JSON object.");
}
+#if JSON_C_FIX
+ if (corrected_json_string != NULL){
+ string_free(corrected_json_string, &memsize);
+ }
+#endif
}
void setup_json0x2ddecode(void) {
diff --git a/src/json-decode.h b/src/json-decode.h
index b34833b..e846e03 100644
--- a/src/json-decode.h
+++ b/src/json-decode.h
@@ -26,9 +26,17 @@ THE SOFTWARE.
#include <ctype.h>
#include <string.h>
-#include <json-c/json.h>
+#include <json/json.h>
#include "purest_json.h"
+#ifndef JSON_C_MAJOR_VERSION
+#define JSON_C_FIX 1
+#elif JSON_C_MAJOR_VERSION < 1 && JSON_MINOR_VERSION <10
+#define JSON_C_FIX 1
+#else
+#define JSON_C_FIX 0
+#endif
+
/* [json-decode] */
struct _json_decode;
typedef struct _json_decode t_json_decode;
diff --git a/src/json-encode.h b/src/json-encode.h
index 3419891..519dfa4 100644
--- a/src/json-encode.h
+++ b/src/json-encode.h
@@ -28,7 +28,7 @@ THE SOFTWARE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <json-c/json.h>
+#include <json/json.h>
#include "purest_json.h"
/* [json-encode] can store arrays */