diff options
-rw-r--r-- | po/POTFILES.in | 128 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/jsonapi/.gitignore | 1 | ||||
-rw-r--r-- | src/jsonapi/Makefile.am | 70 | ||||
-rw-r--r-- | src/jsonapi/jsonapi.c | 82 | ||||
-rw-r--r-- | src/jsonapi/jsonapi_document.c | 402 | ||||
-rw-r--r-- | src/jsonapi/jsonapi_error.c | 241 | ||||
-rw-r--r-- | src/jsonapi/jsonapi_objects.h | 162 | ||||
-rw-r--r-- | src/jsonapi/jsonapi_relationship.c | 17 | ||||
-rw-r--r-- | src/jsonapi/jsonapi_resource.c | 367 | ||||
-rw-r--r-- | src/jsonapi/test_jsonapi.c | 190 | ||||
-rw-r--r-- | src/rest-plugins/Makefile.am | 21 | ||||
-rw-r--r-- | src/rest-plugins/json_reclaim.c | 242 | ||||
-rw-r--r-- | src/rest-plugins/json_reclaim.h | 46 | ||||
-rw-r--r-- | src/rest-plugins/plugin_rest_reclaim.c (renamed from src/jsonapi/plugin_rest_reclaim.c) | 368 |
15 files changed, 477 insertions, 1862 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 44bd751e4..49e4b64ac 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -4,13 +4,21 @@ src/arm/arm_monitor_api.c | |||
4 | src/arm/gnunet-arm.c | 4 | src/arm/gnunet-arm.c |
5 | src/arm/gnunet-service-arm.c | 5 | src/arm/gnunet-service-arm.c |
6 | src/arm/mockup-service.c | 6 | src/arm/mockup-service.c |
7 | src/ats-tests/ats-testing-experiment.c | ||
8 | src/ats-tests/ats-testing-log.c | ||
9 | src/ats-tests/ats-testing-preferences.c | ||
10 | src/ats-tests/ats-testing-traffic.c | ||
11 | src/ats-tests/ats-testing.c | ||
12 | src/ats-tests/gnunet-ats-sim.c | ||
13 | src/ats-tests/gnunet-solver-eval.c | ||
14 | src/ats-tool/gnunet-ats.c | ||
7 | src/ats/ats_api_connectivity.c | 15 | src/ats/ats_api_connectivity.c |
8 | src/ats/ats_api_performance.c | 16 | src/ats/ats_api_performance.c |
9 | src/ats/ats_api_scanner.c | 17 | src/ats/ats_api_scanner.c |
10 | src/ats/ats_api_scheduling.c | 18 | src/ats/ats_api_scheduling.c |
11 | src/ats/gnunet-ats-solver-eval.c | 19 | src/ats/gnunet-ats-solver-eval.c |
12 | src/ats/gnunet-service-ats_addresses.c | ||
13 | src/ats/gnunet-service-ats.c | 20 | src/ats/gnunet-service-ats.c |
21 | src/ats/gnunet-service-ats_addresses.c | ||
14 | src/ats/gnunet-service-ats_connectivity.c | 22 | src/ats/gnunet-service-ats_connectivity.c |
15 | src/ats/gnunet-service-ats_normalization.c | 23 | src/ats/gnunet-service-ats_normalization.c |
16 | src/ats/gnunet-service-ats_performance.c | 24 | src/ats/gnunet-service-ats_performance.c |
@@ -21,14 +29,6 @@ src/ats/gnunet-service-ats_scheduling.c | |||
21 | src/ats/plugin_ats_mlp.c | 29 | src/ats/plugin_ats_mlp.c |
22 | src/ats/plugin_ats_proportional.c | 30 | src/ats/plugin_ats_proportional.c |
23 | src/ats/plugin_ats_ril.c | 31 | src/ats/plugin_ats_ril.c |
24 | src/ats-tests/ats-testing.c | ||
25 | src/ats-tests/ats-testing-experiment.c | ||
26 | src/ats-tests/ats-testing-log.c | ||
27 | src/ats-tests/ats-testing-preferences.c | ||
28 | src/ats-tests/ats-testing-traffic.c | ||
29 | src/ats-tests/gnunet-ats-sim.c | ||
30 | src/ats-tests/gnunet-solver-eval.c | ||
31 | src/ats-tool/gnunet-ats.c | ||
32 | src/auction/gnunet-auction-create.c | 32 | src/auction/gnunet-auction-create.c |
33 | src/auction/gnunet-auction-info.c | 33 | src/auction/gnunet-auction-info.c |
34 | src/auction/gnunet-auction-join.c | 34 | src/auction/gnunet-auction-join.c |
@@ -40,8 +40,8 @@ src/block/plugin_block_test.c | |||
40 | src/cadet/cadet_api.c | 40 | src/cadet/cadet_api.c |
41 | src/cadet/cadet_test_lib.c | 41 | src/cadet/cadet_test_lib.c |
42 | src/cadet/desirability_table.c | 42 | src/cadet/desirability_table.c |
43 | src/cadet/gnunet-cadet.c | ||
44 | src/cadet/gnunet-cadet-profiler.c | 43 | src/cadet/gnunet-cadet-profiler.c |
44 | src/cadet/gnunet-cadet.c | ||
45 | src/cadet/gnunet-service-cadet.c | 45 | src/cadet/gnunet-service-cadet.c |
46 | src/cadet/gnunet-service-cadet_channel.c | 46 | src/cadet/gnunet-service-cadet_channel.c |
47 | src/cadet/gnunet-service-cadet_connection.c | 47 | src/cadet/gnunet-service-cadet_connection.c |
@@ -57,15 +57,15 @@ src/consensus/gnunet-service-consensus.c | |||
57 | src/consensus/plugin_block_consensus.c | 57 | src/consensus/plugin_block_consensus.c |
58 | src/conversation/conversation_api.c | 58 | src/conversation/conversation_api.c |
59 | src/conversation/conversation_api_call.c | 59 | src/conversation/conversation_api_call.c |
60 | src/conversation/gnunet-conversation.c | ||
61 | src/conversation/gnunet-conversation-test.c | 60 | src/conversation/gnunet-conversation-test.c |
62 | src/conversation/gnunet_gst.c | 61 | src/conversation/gnunet-conversation.c |
63 | src/conversation/gnunet_gst_test.c | ||
64 | src/conversation/gnunet-helper-audio-playback.c | ||
65 | src/conversation/gnunet-helper-audio-playback-gst.c | 62 | src/conversation/gnunet-helper-audio-playback-gst.c |
66 | src/conversation/gnunet-helper-audio-record.c | 63 | src/conversation/gnunet-helper-audio-playback.c |
67 | src/conversation/gnunet-helper-audio-record-gst.c | 64 | src/conversation/gnunet-helper-audio-record-gst.c |
65 | src/conversation/gnunet-helper-audio-record.c | ||
68 | src/conversation/gnunet-service-conversation.c | 66 | src/conversation/gnunet-service-conversation.c |
67 | src/conversation/gnunet_gst.c | ||
68 | src/conversation/gnunet_gst_test.c | ||
69 | src/conversation/microphone.c | 69 | src/conversation/microphone.c |
70 | src/conversation/plugin_gnsrecord_conversation.c | 70 | src/conversation/plugin_gnsrecord_conversation.c |
71 | src/conversation/speaker.c | 71 | src/conversation/speaker.c |
@@ -82,7 +82,6 @@ src/credential/credential_serialization.c | |||
82 | src/credential/gnunet-credential.c | 82 | src/credential/gnunet-credential.c |
83 | src/credential/gnunet-service-credential.c | 83 | src/credential/gnunet-service-credential.c |
84 | src/credential/plugin_gnsrecord_credential.c | 84 | src/credential/plugin_gnsrecord_credential.c |
85 | src/credential/plugin_rest_credential.c | ||
86 | src/curl/curl.c | 85 | src/curl/curl.c |
87 | src/curl/curl_reschedule.c | 86 | src/curl/curl_reschedule.c |
88 | src/datacache/datacache.c | 87 | src/datacache/datacache.c |
@@ -102,7 +101,6 @@ src/dht/dht_api.c | |||
102 | src/dht/dht_test_lib.c | 101 | src/dht/dht_test_lib.c |
103 | src/dht/gnunet-dht-get.c | 102 | src/dht/gnunet-dht-get.c |
104 | src/dht/gnunet-dht-monitor.c | 103 | src/dht/gnunet-dht-monitor.c |
105 | src/dht/gnunet_dht_profiler.c | ||
106 | src/dht/gnunet-dht-put.c | 104 | src/dht/gnunet-dht-put.c |
107 | src/dht/gnunet-service-dht.c | 105 | src/dht/gnunet-service-dht.c |
108 | src/dht/gnunet-service-dht_clients.c | 106 | src/dht/gnunet-service-dht_clients.c |
@@ -111,6 +109,7 @@ src/dht/gnunet-service-dht_hello.c | |||
111 | src/dht/gnunet-service-dht_neighbours.c | 109 | src/dht/gnunet-service-dht_neighbours.c |
112 | src/dht/gnunet-service-dht_nse.c | 110 | src/dht/gnunet-service-dht_nse.c |
113 | src/dht/gnunet-service-dht_routing.c | 111 | src/dht/gnunet-service-dht_routing.c |
112 | src/dht/gnunet_dht_profiler.c | ||
114 | src/dht/plugin_block_dht.c | 113 | src/dht/plugin_block_dht.c |
115 | src/dns/dns_api.c | 114 | src/dns/dns_api.c |
116 | src/dns/gnunet-dns-monitor.c | 115 | src/dns/gnunet-dns-monitor.c |
@@ -124,8 +123,8 @@ src/dv/gnunet-dv.c | |||
124 | src/dv/gnunet-service-dv.c | 123 | src/dv/gnunet-service-dv.c |
125 | src/dv/plugin_transport_dv.c | 124 | src/dv/plugin_transport_dv.c |
126 | src/exit/gnunet-daemon-exit.c | 125 | src/exit/gnunet-daemon-exit.c |
127 | src/exit/gnunet-helper-exit.c | ||
128 | src/exit/gnunet-helper-exit-windows.c | 126 | src/exit/gnunet-helper-exit-windows.c |
127 | src/exit/gnunet-helper-exit.c | ||
129 | src/fragmentation/defragmentation.c | 128 | src/fragmentation/defragmentation.c |
130 | src/fragmentation/fragmentation.c | 129 | src/fragmentation/fragmentation.c |
131 | src/fs/fs_api.c | 130 | src/fs/fs_api.c |
@@ -150,8 +149,8 @@ src/fs/gnunet-auto-share.c | |||
150 | src/fs/gnunet-daemon-fsprofiler.c | 149 | src/fs/gnunet-daemon-fsprofiler.c |
151 | src/fs/gnunet-directory.c | 150 | src/fs/gnunet-directory.c |
152 | src/fs/gnunet-download.c | 151 | src/fs/gnunet-download.c |
153 | src/fs/gnunet-fs.c | ||
154 | src/fs/gnunet-fs-profiler.c | 152 | src/fs/gnunet-fs-profiler.c |
153 | src/fs/gnunet-fs.c | ||
155 | src/fs/gnunet-helper-fs-publish.c | 154 | src/fs/gnunet-helper-fs-publish.c |
156 | src/fs/gnunet-publish.c | 155 | src/fs/gnunet-publish.c |
157 | src/fs/gnunet-search.c | 156 | src/fs/gnunet-search.c |
@@ -171,10 +170,10 @@ src/gns/gns_tld_api.c | |||
171 | src/gns/gnunet-bcd.c | 170 | src/gns/gnunet-bcd.c |
172 | src/gns/gnunet-dns2gns.c | 171 | src/gns/gnunet-dns2gns.c |
173 | src/gns/gnunet-gns-benchmark.c | 172 | src/gns/gnunet-gns-benchmark.c |
174 | src/gns/gnunet-gns.c | ||
175 | src/gns/gnunet-gns-helper-service-w32.c | 173 | src/gns/gnunet-gns-helper-service-w32.c |
176 | src/gns/gnunet-gns-import.c | 174 | src/gns/gnunet-gns-import.c |
177 | src/gns/gnunet-gns-proxy.c | 175 | src/gns/gnunet-gns-proxy.c |
176 | src/gns/gnunet-gns.c | ||
178 | src/gns/gnunet-service-gns.c | 177 | src/gns/gnunet-service-gns.c |
179 | src/gns/gnunet-service-gns_interceptor.c | 178 | src/gns/gnunet-service-gns_interceptor.c |
180 | src/gns/gnunet-service-gns_resolver.c | 179 | src/gns/gnunet-service-gns_resolver.c |
@@ -182,15 +181,15 @@ src/gns/nss/nss_gns.c | |||
182 | src/gns/nss/nss_gns_query.c | 181 | src/gns/nss/nss_gns_query.c |
183 | src/gns/plugin_block_gns.c | 182 | src/gns/plugin_block_gns.c |
184 | src/gns/plugin_gnsrecord_gns.c | 183 | src/gns/plugin_gnsrecord_gns.c |
184 | src/gns/w32nsp-install.c | ||
185 | src/gns/w32nsp-resolve.c | ||
186 | src/gns/w32nsp-uninstall.c | ||
187 | src/gns/w32nsp.c | ||
185 | src/gnsrecord/gnsrecord.c | 188 | src/gnsrecord/gnsrecord.c |
186 | src/gnsrecord/gnsrecord_crypto.c | 189 | src/gnsrecord/gnsrecord_crypto.c |
187 | src/gnsrecord/gnsrecord_misc.c | 190 | src/gnsrecord/gnsrecord_misc.c |
188 | src/gnsrecord/gnsrecord_serialization.c | 191 | src/gnsrecord/gnsrecord_serialization.c |
189 | src/gnsrecord/plugin_gnsrecord_dns.c | 192 | src/gnsrecord/plugin_gnsrecord_dns.c |
190 | src/gns/w32nsp.c | ||
191 | src/gns/w32nsp-install.c | ||
192 | src/gns/w32nsp-resolve.c | ||
193 | src/gns/w32nsp-uninstall.c | ||
194 | src/hello/address.c | 193 | src/hello/address.c |
195 | src/hello/gnunet-hello.c | 194 | src/hello/gnunet-hello.c |
196 | src/hello/hello.c | 195 | src/hello/hello.c |
@@ -201,17 +200,16 @@ src/identity/gnunet-identity.c | |||
201 | src/identity/gnunet-service-identity.c | 200 | src/identity/gnunet-service-identity.c |
202 | src/identity/identity_api.c | 201 | src/identity/identity_api.c |
203 | src/identity/identity_api_lookup.c | 202 | src/identity/identity_api_lookup.c |
204 | src/jsonapi/jsonapi.c | ||
205 | src/jsonapi/jsonapi_document.c | ||
206 | src/jsonapi/jsonapi_error.c | ||
207 | src/jsonapi/jsonapi_relationship.c | ||
208 | src/jsonapi/jsonapi_resource.c | ||
209 | src/jsonapi/plugin_rest_reclaim.c | ||
210 | src/json/json.c | 203 | src/json/json.c |
211 | src/json/json_generator.c | 204 | src/json/json_generator.c |
212 | src/json/json_gnsrecord.c | 205 | src/json/json_gnsrecord.c |
213 | src/json/json_helper.c | 206 | src/json/json_helper.c |
214 | src/json/json_mhd.c | 207 | src/json/json_mhd.c |
208 | src/jsonapi/jsonapi.c | ||
209 | src/jsonapi/jsonapi_document.c | ||
210 | src/jsonapi/jsonapi_error.c | ||
211 | src/jsonapi/jsonapi_relationship.c | ||
212 | src/jsonapi/jsonapi_resource.c | ||
215 | src/multicast/gnunet-multicast.c | 213 | src/multicast/gnunet-multicast.c |
216 | src/multicast/gnunet-service-multicast.c | 214 | src/multicast/gnunet-service-multicast.c |
217 | src/multicast/multicast_api.c | 215 | src/multicast/multicast_api.c |
@@ -225,8 +223,8 @@ src/namecache/namecache_api.c | |||
225 | src/namecache/plugin_namecache_flat.c | 223 | src/namecache/plugin_namecache_flat.c |
226 | src/namecache/plugin_namecache_postgres.c | 224 | src/namecache/plugin_namecache_postgres.c |
227 | src/namecache/plugin_namecache_sqlite.c | 225 | src/namecache/plugin_namecache_sqlite.c |
228 | src/namestore/gnunet-namestore.c | ||
229 | src/namestore/gnunet-namestore-fcfsd.c | 226 | src/namestore/gnunet-namestore-fcfsd.c |
227 | src/namestore/gnunet-namestore.c | ||
230 | src/namestore/gnunet-service-namestore.c | 228 | src/namestore/gnunet-service-namestore.c |
231 | src/namestore/gnunet-zoneimport.c | 229 | src/namestore/gnunet-zoneimport.c |
232 | src/namestore/namestore_api.c | 230 | src/namestore/namestore_api.c |
@@ -241,10 +239,10 @@ src/nat-auto/gnunet-service-nat-auto.c | |||
241 | src/nat-auto/gnunet-service-nat-auto_legacy.c | 239 | src/nat-auto/gnunet-service-nat-auto_legacy.c |
242 | src/nat-auto/nat_auto_api.c | 240 | src/nat-auto/nat_auto_api.c |
243 | src/nat-auto/nat_auto_api_test.c | 241 | src/nat-auto/nat_auto_api_test.c |
244 | src/nat/gnunet-helper-nat-client.c | ||
245 | src/nat/gnunet-helper-nat-client-windows.c | 242 | src/nat/gnunet-helper-nat-client-windows.c |
246 | src/nat/gnunet-helper-nat-server.c | 243 | src/nat/gnunet-helper-nat-client.c |
247 | src/nat/gnunet-helper-nat-server-windows.c | 244 | src/nat/gnunet-helper-nat-server-windows.c |
245 | src/nat/gnunet-helper-nat-server.c | ||
248 | src/nat/gnunet-nat.c | 246 | src/nat/gnunet-nat.c |
249 | src/nat/gnunet-service-nat.c | 247 | src/nat/gnunet-service-nat.c |
250 | src/nat/gnunet-service-nat_externalip.c | 248 | src/nat/gnunet-service-nat_externalip.c |
@@ -253,15 +251,15 @@ src/nat/gnunet-service-nat_mini.c | |||
253 | src/nat/gnunet-service-nat_stun.c | 251 | src/nat/gnunet-service-nat_stun.c |
254 | src/nat/nat_api.c | 252 | src/nat/nat_api.c |
255 | src/nat/nat_api_stun.c | 253 | src/nat/nat_api_stun.c |
256 | src/nse/gnunet-nse.c | ||
257 | src/nse/gnunet-nse-profiler.c | 254 | src/nse/gnunet-nse-profiler.c |
255 | src/nse/gnunet-nse.c | ||
258 | src/nse/gnunet-service-nse.c | 256 | src/nse/gnunet-service-nse.c |
259 | src/nse/nse_api.c | 257 | src/nse/nse_api.c |
258 | src/peerinfo-tool/gnunet-peerinfo.c | ||
259 | src/peerinfo-tool/gnunet-peerinfo_plugins.c | ||
260 | src/peerinfo/gnunet-service-peerinfo.c | 260 | src/peerinfo/gnunet-service-peerinfo.c |
261 | src/peerinfo/peerinfo_api.c | 261 | src/peerinfo/peerinfo_api.c |
262 | src/peerinfo/peerinfo_api_notify.c | 262 | src/peerinfo/peerinfo_api_notify.c |
263 | src/peerinfo-tool/gnunet-peerinfo.c | ||
264 | src/peerinfo-tool/gnunet-peerinfo_plugins.c | ||
265 | src/peerstore/gnunet-peerstore.c | 263 | src/peerstore/gnunet-peerstore.c |
266 | src/peerstore/gnunet-service-peerstore.c | 264 | src/peerstore/gnunet-service-peerstore.c |
267 | src/peerstore/peerstore_api.c | 265 | src/peerstore/peerstore_api.c |
@@ -308,34 +306,38 @@ src/regex/regex_internal_dht.c | |||
308 | src/regex/regex_test_graph.c | 306 | src/regex/regex_test_graph.c |
309 | src/regex/regex_test_lib.c | 307 | src/regex/regex_test_lib.c |
310 | src/regex/regex_test_random.c | 308 | src/regex/regex_test_random.c |
311 | src/rest/gnunet-rest-server.c | 309 | src/rest-plugins/json_reclaim.c |
312 | src/rest-plugins/oidc_helper.c | 310 | src/rest-plugins/oidc_helper.c |
313 | src/rest-plugins/plugin_rest_copying.c | 311 | src/rest-plugins/plugin_rest_copying.c |
312 | src/rest-plugins/plugin_rest_credential.c | ||
314 | src/rest-plugins/plugin_rest_gns.c | 313 | src/rest-plugins/plugin_rest_gns.c |
315 | src/rest-plugins/plugin_rest_identity.c | 314 | src/rest-plugins/plugin_rest_identity.c |
316 | src/rest-plugins/plugin_rest_namestore.c | 315 | src/rest-plugins/plugin_rest_namestore.c |
317 | src/rest-plugins/plugin_rest_openid_connect.c | 316 | src/rest-plugins/plugin_rest_openid_connect.c |
318 | src/rest-plugins/plugin_rest_peerinfo.c | 317 | src/rest-plugins/plugin_rest_peerinfo.c |
318 | src/rest-plugins/plugin_rest_reclaim.c | ||
319 | src/rest/gnunet-rest-server.c | ||
319 | src/rest/rest.c | 320 | src/rest/rest.c |
320 | src/revocation/gnunet-revocation.c | 321 | src/revocation/gnunet-revocation.c |
321 | src/revocation/gnunet-service-revocation.c | 322 | src/revocation/gnunet-service-revocation.c |
322 | src/revocation/plugin_block_revocation.c | 323 | src/revocation/plugin_block_revocation.c |
323 | src/revocation/revocation_api.c | 324 | src/revocation/revocation_api.c |
324 | src/rps/gnunet-rps.c | ||
325 | src/rps/gnunet-rps-profiler.c | 325 | src/rps/gnunet-rps-profiler.c |
326 | src/rps/gnunet-rps.c | ||
326 | src/rps/gnunet-service-rps.c | 327 | src/rps/gnunet-service-rps.c |
327 | src/rps/gnunet-service-rps_custommap.c | 328 | src/rps/gnunet-service-rps_custommap.c |
328 | src/rps/gnunet-service-rps_sampler.c | 329 | src/rps/gnunet-service-rps_sampler.c |
329 | src/rps/gnunet-service-rps_sampler_elem.c | 330 | src/rps/gnunet-service-rps_sampler_elem.c |
330 | src/rps/gnunet-service-rps_view.c | 331 | src/rps/gnunet-service-rps_view.c |
331 | src/rps/rps_api.c | 332 | src/rps/rps-sampler_client.c |
332 | src/rps/rps_test_lib.c | 333 | src/rps/rps-sampler_common.c |
333 | src/rps/rps-test_util.c | 334 | src/rps/rps-test_util.c |
335 | src/rps/rps_api.c | ||
334 | src/scalarproduct/gnunet-scalarproduct.c | 336 | src/scalarproduct/gnunet-scalarproduct.c |
335 | src/scalarproduct/gnunet-service-scalarproduct_alice.c | ||
336 | src/scalarproduct/gnunet-service-scalarproduct_bob.c | ||
337 | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | 337 | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c |
338 | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | 338 | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c |
339 | src/scalarproduct/gnunet-service-scalarproduct_alice.c | ||
340 | src/scalarproduct/gnunet-service-scalarproduct_bob.c | ||
339 | src/scalarproduct/scalarproduct_api.c | 341 | src/scalarproduct/scalarproduct_api.c |
340 | src/secretsharing/gnunet-secretsharing-profiler.c | 342 | src/secretsharing/gnunet-secretsharing-profiler.c |
341 | src/secretsharing/gnunet-service-secretsharing.c | 343 | src/secretsharing/gnunet-service-secretsharing.c |
@@ -364,15 +366,16 @@ src/statistics/gnunet-statistics.c | |||
364 | src/statistics/statistics_api.c | 366 | src/statistics/statistics_api.c |
365 | src/template/gnunet-service-template.c | 367 | src/template/gnunet-service-template.c |
366 | src/template/gnunet-template.c | 368 | src/template/gnunet-template.c |
369 | src/testbed-logger/gnunet-service-testbed-logger.c | ||
370 | src/testbed-logger/testbed_logger_api.c | ||
367 | src/testbed/generate-underlay-topology.c | 371 | src/testbed/generate-underlay-topology.c |
368 | src/testbed/gnunet-daemon-latency-logger.c | 372 | src/testbed/gnunet-daemon-latency-logger.c |
369 | src/testbed/gnunet-daemon-testbed-blacklist.c | 373 | src/testbed/gnunet-daemon-testbed-blacklist.c |
370 | src/testbed/gnunet-daemon-testbed-underlay.c | 374 | src/testbed/gnunet-daemon-testbed-underlay.c |
371 | src/testbed/gnunet-helper-testbed.c | 375 | src/testbed/gnunet-helper-testbed.c |
372 | src/testbed/gnunet_mpi_test.c | ||
373 | src/testbed/gnunet-service-test-barriers.c | 376 | src/testbed/gnunet-service-test-barriers.c |
374 | src/testbed/gnunet-service-testbed_barriers.c | ||
375 | src/testbed/gnunet-service-testbed.c | 377 | src/testbed/gnunet-service-testbed.c |
378 | src/testbed/gnunet-service-testbed_barriers.c | ||
376 | src/testbed/gnunet-service-testbed_cache.c | 379 | src/testbed/gnunet-service-testbed_cache.c |
377 | src/testbed/gnunet-service-testbed_connectionpool.c | 380 | src/testbed/gnunet-service-testbed_connectionpool.c |
378 | src/testbed/gnunet-service-testbed_cpustatus.c | 381 | src/testbed/gnunet-service-testbed_cpustatus.c |
@@ -380,20 +383,19 @@ src/testbed/gnunet-service-testbed_links.c | |||
380 | src/testbed/gnunet-service-testbed_meminfo.c | 383 | src/testbed/gnunet-service-testbed_meminfo.c |
381 | src/testbed/gnunet-service-testbed_oc.c | 384 | src/testbed/gnunet-service-testbed_oc.c |
382 | src/testbed/gnunet-service-testbed_peers.c | 385 | src/testbed/gnunet-service-testbed_peers.c |
383 | src/testbed/gnunet_testbed_mpi_spawn.c | ||
384 | src/testbed/gnunet-testbed-profiler.c | 386 | src/testbed/gnunet-testbed-profiler.c |
385 | src/testbed-logger/gnunet-service-testbed-logger.c | 387 | src/testbed/gnunet_mpi_test.c |
386 | src/testbed-logger/testbed_logger_api.c | 388 | src/testbed/gnunet_testbed_mpi_spawn.c |
387 | src/testbed/testbed_api_barriers.c | ||
388 | src/testbed/testbed_api.c | 389 | src/testbed/testbed_api.c |
390 | src/testbed/testbed_api_barriers.c | ||
389 | src/testbed/testbed_api_hosts.c | 391 | src/testbed/testbed_api_hosts.c |
390 | src/testbed/testbed_api_operations.c | 392 | src/testbed/testbed_api_operations.c |
391 | src/testbed/testbed_api_peers.c | 393 | src/testbed/testbed_api_peers.c |
392 | src/testbed/testbed_api_sd.c | 394 | src/testbed/testbed_api_sd.c |
393 | src/testbed/testbed_api_services.c | 395 | src/testbed/testbed_api_services.c |
394 | src/testbed/testbed_api_statistics.c | 396 | src/testbed/testbed_api_statistics.c |
395 | src/testbed/testbed_api_testbed.c | ||
396 | src/testbed/testbed_api_test.c | 397 | src/testbed/testbed_api_test.c |
398 | src/testbed/testbed_api_testbed.c | ||
397 | src/testbed/testbed_api_topology.c | 399 | src/testbed/testbed_api_topology.c |
398 | src/testbed/testbed_api_underlay.c | 400 | src/testbed/testbed_api_underlay.c |
399 | src/testing/gnunet-testing.c | 401 | src/testing/gnunet-testing.c |
@@ -402,28 +404,28 @@ src/testing/testing.c | |||
402 | src/topology/friends.c | 404 | src/topology/friends.c |
403 | src/topology/gnunet-daemon-topology.c | 405 | src/topology/gnunet-daemon-topology.c |
404 | src/transport/gnunet-helper-transport-bluetooth.c | 406 | src/transport/gnunet-helper-transport-bluetooth.c |
405 | src/transport/gnunet-helper-transport-wlan.c | ||
406 | src/transport/gnunet-helper-transport-wlan-dummy.c | 407 | src/transport/gnunet-helper-transport-wlan-dummy.c |
407 | src/transport/gnunet-service-transport_ats.c | 408 | src/transport/gnunet-helper-transport-wlan.c |
408 | src/transport/gnunet-service-transport.c | 409 | src/transport/gnunet-service-transport.c |
410 | src/transport/gnunet-service-transport_ats.c | ||
409 | src/transport/gnunet-service-transport_hello.c | 411 | src/transport/gnunet-service-transport_hello.c |
410 | src/transport/gnunet-service-transport_manipulation.c | 412 | src/transport/gnunet-service-transport_manipulation.c |
411 | src/transport/gnunet-service-transport_neighbours.c | 413 | src/transport/gnunet-service-transport_neighbours.c |
412 | src/transport/gnunet-service-transport_plugins.c | 414 | src/transport/gnunet-service-transport_plugins.c |
413 | src/transport/gnunet-service-transport_validation.c | 415 | src/transport/gnunet-service-transport_validation.c |
414 | src/transport/gnunet-transport.c | ||
415 | src/transport/gnunet-transport-certificate-creation.c | 416 | src/transport/gnunet-transport-certificate-creation.c |
416 | src/transport/gnunet-transport-profiler.c | 417 | src/transport/gnunet-transport-profiler.c |
417 | src/transport/gnunet-transport-wlan-receiver.c | 418 | src/transport/gnunet-transport-wlan-receiver.c |
418 | src/transport/gnunet-transport-wlan-sender.c | 419 | src/transport/gnunet-transport-wlan-sender.c |
420 | src/transport/gnunet-transport.c | ||
419 | src/transport/plugin_transport_http_client.c | 421 | src/transport/plugin_transport_http_client.c |
420 | src/transport/plugin_transport_http_common.c | 422 | src/transport/plugin_transport_http_common.c |
421 | src/transport/plugin_transport_http_server.c | 423 | src/transport/plugin_transport_http_server.c |
422 | src/transport/plugin_transport_smtp.c | 424 | src/transport/plugin_transport_smtp.c |
423 | src/transport/plugin_transport_tcp.c | 425 | src/transport/plugin_transport_tcp.c |
424 | src/transport/plugin_transport_template.c | 426 | src/transport/plugin_transport_template.c |
425 | src/transport/plugin_transport_udp_broadcasting.c | ||
426 | src/transport/plugin_transport_udp.c | 427 | src/transport/plugin_transport_udp.c |
428 | src/transport/plugin_transport_udp_broadcasting.c | ||
427 | src/transport/plugin_transport_unix.c | 429 | src/transport/plugin_transport_unix.c |
428 | src/transport/plugin_transport_wlan.c | 430 | src/transport/plugin_transport_wlan.c |
429 | src/transport/plugin_transport_xt.c | 431 | src/transport/plugin_transport_xt.c |
@@ -432,6 +434,11 @@ src/transport/tcp_connection_legacy.c | |||
432 | src/transport/tcp_server_legacy.c | 434 | src/transport/tcp_server_legacy.c |
433 | src/transport/tcp_server_mst_legacy.c | 435 | src/transport/tcp_server_mst_legacy.c |
434 | src/transport/tcp_service_legacy.c | 436 | src/transport/tcp_service_legacy.c |
437 | src/transport/transport-testing-filenames.c | ||
438 | src/transport/transport-testing-loggers.c | ||
439 | src/transport/transport-testing-main.c | ||
440 | src/transport/transport-testing-send.c | ||
441 | src/transport/transport-testing.c | ||
435 | src/transport/transport_api_address_to_string.c | 442 | src/transport/transport_api_address_to_string.c |
436 | src/transport/transport_api_blacklist.c | 443 | src/transport/transport_api_blacklist.c |
437 | src/transport/transport_api_core.c | 444 | src/transport/transport_api_core.c |
@@ -440,11 +447,6 @@ src/transport/transport_api_manipulation.c | |||
440 | src/transport/transport_api_monitor_peers.c | 447 | src/transport/transport_api_monitor_peers.c |
441 | src/transport/transport_api_monitor_plugins.c | 448 | src/transport/transport_api_monitor_plugins.c |
442 | src/transport/transport_api_offer_hello.c | 449 | src/transport/transport_api_offer_hello.c |
443 | src/transport/transport-testing.c | ||
444 | src/transport/transport-testing-filenames.c | ||
445 | src/transport/transport-testing-loggers.c | ||
446 | src/transport/transport-testing-main.c | ||
447 | src/transport/transport-testing-send.c | ||
448 | src/util/bandwidth.c | 450 | src/util/bandwidth.c |
449 | src/util/benchmark.c | 451 | src/util/benchmark.c |
450 | src/util/bio.c | 452 | src/util/bio.c |
@@ -457,8 +459,8 @@ src/util/configuration_loader.c | |||
457 | src/util/container_bloomfilter.c | 459 | src/util/container_bloomfilter.c |
458 | src/util/container_heap.c | 460 | src/util/container_heap.c |
459 | src/util/container_meta_data.c | 461 | src/util/container_meta_data.c |
460 | src/util/container_multihashmap32.c | ||
461 | src/util/container_multihashmap.c | 462 | src/util/container_multihashmap.c |
463 | src/util/container_multihashmap32.c | ||
462 | src/util/container_multipeermap.c | 464 | src/util/container_multipeermap.c |
463 | src/util/container_multishortmap.c | 465 | src/util/container_multishortmap.c |
464 | src/util/crypto_abe.c | 466 | src/util/crypto_abe.c |
@@ -480,15 +482,15 @@ src/util/dnsparser.c | |||
480 | src/util/dnsstub.c | 482 | src/util/dnsstub.c |
481 | src/util/getopt.c | 483 | src/util/getopt.c |
482 | src/util/getopt_helpers.c | 484 | src/util/getopt_helpers.c |
483 | src/util/gnunet-config.c | ||
484 | src/util/gnunet-config-diff.c | 485 | src/util/gnunet-config-diff.c |
486 | src/util/gnunet-config.c | ||
485 | src/util/gnunet-ecc.c | 487 | src/util/gnunet-ecc.c |
486 | src/util/gnunet-helper-w32-console.c | 488 | src/util/gnunet-helper-w32-console.c |
487 | src/util/gnunet-resolver.c | 489 | src/util/gnunet-resolver.c |
488 | src/util/gnunet-scrypt.c | 490 | src/util/gnunet-scrypt.c |
489 | src/util/gnunet-service-resolver.c | 491 | src/util/gnunet-service-resolver.c |
490 | src/util/gnunet-timeout.c | ||
491 | src/util/gnunet-timeout-w32.c | 492 | src/util/gnunet-timeout-w32.c |
493 | src/util/gnunet-timeout.c | ||
492 | src/util/gnunet-uri.c | 494 | src/util/gnunet-uri.c |
493 | src/util/helper.c | 495 | src/util/helper.c |
494 | src/util/load.c | 496 | src/util/load.c |
@@ -516,13 +518,13 @@ src/util/tun.c | |||
516 | src/util/w32cat.c | 518 | src/util/w32cat.c |
517 | src/util/win.c | 519 | src/util/win.c |
518 | src/util/winproc.c | 520 | src/util/winproc.c |
519 | src/vpn/gnunet-helper-vpn.c | ||
520 | src/vpn/gnunet-helper-vpn-windows.c | 521 | src/vpn/gnunet-helper-vpn-windows.c |
522 | src/vpn/gnunet-helper-vpn.c | ||
521 | src/vpn/gnunet-service-vpn.c | 523 | src/vpn/gnunet-service-vpn.c |
522 | src/vpn/gnunet-vpn.c | 524 | src/vpn/gnunet-vpn.c |
523 | src/vpn/vpn_api.c | 525 | src/vpn/vpn_api.c |
524 | src/zonemaster/gnunet-service-zonemaster.c | ||
525 | src/zonemaster/gnunet-service-zonemaster-monitor.c | 526 | src/zonemaster/gnunet-service-zonemaster-monitor.c |
527 | src/zonemaster/gnunet-service-zonemaster.c | ||
526 | src/fs/fs_api.h | 528 | src/fs/fs_api.h |
527 | src/include/gnunet_common.h | 529 | src/include/gnunet_common.h |
528 | src/include/gnunet_mq_lib.h | 530 | src/include/gnunet_mq_lib.h |
diff --git a/src/Makefile.am b/src/Makefile.am index 7f97190d0..39cbaa893 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -66,7 +66,7 @@ endif | |||
66 | 66 | ||
67 | if HAVE_MHD | 67 | if HAVE_MHD |
68 | if HAVE_JSON | 68 | if HAVE_JSON |
69 | REST_DIR = rest jsonapi rest-plugins | 69 | REST_DIR = rest rest-plugins |
70 | endif | 70 | endif |
71 | endif | 71 | endif |
72 | 72 | ||
diff --git a/src/jsonapi/.gitignore b/src/jsonapi/.gitignore deleted file mode 100644 index 077606988..000000000 --- a/src/jsonapi/.gitignore +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | test_jsonapi | ||
diff --git a/src/jsonapi/Makefile.am b/src/jsonapi/Makefile.am deleted file mode 100644 index e572ffa9d..000000000 --- a/src/jsonapi/Makefile.am +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | # This Makefile.am is in the public domain | ||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | ||
3 | |||
4 | plugindir = $(libdir)/gnunet | ||
5 | |||
6 | if USE_COVERAGE | ||
7 | AM_CFLAGS = --coverage -O0 | ||
8 | XLIB = -lgcov | ||
9 | endif | ||
10 | |||
11 | lib_LTLIBRARIES = \ | ||
12 | libgnunetjsonapi.la \ | ||
13 | libgnunetjsonapiutils.la | ||
14 | |||
15 | if HAVE_ABE | ||
16 | lib_LTLIBRARIES += libgnunet_plugin_rest_reclaim.la | ||
17 | endif | ||
18 | |||
19 | libgnunet_plugin_rest_reclaim_la_SOURCES = \ | ||
20 | plugin_rest_reclaim.c | ||
21 | libgnunet_plugin_rest_reclaim_la_LIBADD = \ | ||
22 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
23 | $(top_builddir)/src/reclaim/libgnunetreclaim.la \ | ||
24 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
25 | libgnunetjsonapi.la \ | ||
26 | $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ | ||
27 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
28 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
29 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
30 | libgnunet_plugin_rest_reclaim_la_LDFLAGS = \ | ||
31 | i$(GN_PLUGIN_LDFLAGS) | ||
32 | |||
33 | |||
34 | libgnunetjsonapiutils_la_LDFLAGS = \ | ||
35 | -version-info 0:0:0 \ | ||
36 | -no-undefined | ||
37 | libgnunetjsonapiutils_la_SOURCES = \ | ||
38 | jsonapi.c | ||
39 | libgnunetjsonapiutils_la_LIBADD = \ | ||
40 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
41 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
42 | $(XLIB) | ||
43 | |||
44 | libgnunetjsonapi_la_LDFLAGS = \ | ||
45 | -version-info 0:0:0 \ | ||
46 | -no-undefined | ||
47 | libgnunetjsonapi_la_SOURCES = \ | ||
48 | jsonapi_document.c jsonapi_objects.h \ | ||
49 | jsonapi_resource.c \ | ||
50 | jsonapi_error.c \ | ||
51 | jsonapi_relationship.c | ||
52 | libgnunetjsonapi_la_LIBADD = \ | ||
53 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
54 | $(top_builddir)/src/json/libgnunetjson.la \ | ||
55 | -ljansson \ | ||
56 | $(XLIB) | ||
57 | |||
58 | check_PROGRAMS = \ | ||
59 | test_jsonapi | ||
60 | |||
61 | TESTS = \ | ||
62 | $(check_PROGRAMS) | ||
63 | |||
64 | test_jsonapi_SOURCES = \ | ||
65 | test_jsonapi.c | ||
66 | test_jsonapi_LDADD = \ | ||
67 | libgnunetjsonapi.la \ | ||
68 | $(top_builddir)/src/json/libgnunetjson.la \ | ||
69 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
70 | -ljansson | ||
diff --git a/src/jsonapi/jsonapi.c b/src/jsonapi/jsonapi.c deleted file mode 100644 index f7fcd972a..000000000 --- a/src/jsonapi/jsonapi.c +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | /** | ||
19 | * @file jsonapi/jsonapi.c | ||
20 | * @brief functions to generate specifciations for JSONAPI parsing | ||
21 | * @author Martin Schanzenbach | ||
22 | */ | ||
23 | #include "platform.h" | ||
24 | #include "gnunet_json_lib.h" | ||
25 | #include "gnunet_rest_lib.h" | ||
26 | |||
27 | /** | ||
28 | * TODO move this to jsonapi-utils | ||
29 | */ | ||
30 | |||
31 | /** | ||
32 | * Check rest request for validity | ||
33 | * | ||
34 | * @param req handle to the request | ||
35 | * @return GNUNET_OK if valid | ||
36 | */ | ||
37 | int | ||
38 | GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle *req) | ||
39 | { | ||
40 | //TODO | ||
41 | return GNUNET_OK; | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Check rest request for validity | ||
46 | * | ||
47 | * @param req handle to the request | ||
48 | * @return GNUNET_OK if valid | ||
49 | */ | ||
50 | int | ||
51 | GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req) | ||
52 | { | ||
53 | //TODO | ||
54 | return GNUNET_OK; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Handle jsonapi rest request. Checks request headers for jsonapi compliance | ||
59 | * | ||
60 | * @param req rest request handle | ||
61 | * @param handler rest request handlers | ||
62 | * @param cls closure | ||
63 | * @return GNUNET_OK if successful | ||
64 | */ | ||
65 | int | ||
66 | GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *handle, | ||
67 | const struct GNUNET_REST_RequestHandler *handlers, | ||
68 | struct GNUNET_REST_RequestHandlerError *err, | ||
69 | void *cls) | ||
70 | { | ||
71 | if (GNUNET_OK != GNUNET_JSONAPI_check_request_acceptable (handle)) | ||
72 | { | ||
73 | err->error_code = MHD_HTTP_NOT_ACCEPTABLE; | ||
74 | return GNUNET_SYSERR; | ||
75 | } | ||
76 | if (GNUNET_OK != GNUNET_JSONAPI_check_request_supported (handle)) | ||
77 | { | ||
78 | err->error_code = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE; | ||
79 | return GNUNET_SYSERR; | ||
80 | } | ||
81 | return GNUNET_REST_handle_request (handle, handlers, err, cls); | ||
82 | } | ||
diff --git a/src/jsonapi/jsonapi_document.c b/src/jsonapi/jsonapi_document.c deleted file mode 100644 index 3a60940f6..000000000 --- a/src/jsonapi/jsonapi_document.c +++ /dev/null | |||
@@ -1,402 +0,0 @@ | |||
1 | |||
2 | #include "platform.h" | ||
3 | #include "gnunet_util_lib.h" | ||
4 | #include "gnunet_json_lib.h" | ||
5 | #include "jsonapi_objects.h" | ||
6 | |||
7 | /** | ||
8 | * Get a JSON API object resource count | ||
9 | * | ||
10 | * @param resp the JSON API object | ||
11 | * @return the number of resources | ||
12 | */ | ||
13 | int | ||
14 | GNUNET_JSONAPI_document_resource_count (struct GNUNET_JSONAPI_Document *doc) | ||
15 | { | ||
16 | return doc->res_count; | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * Get a JSON API object resource by index | ||
21 | * | ||
22 | * @param resp the JSON API object | ||
23 | * @param idx index of the resource | ||
24 | * @return the resource | ||
25 | */ | ||
26 | struct GNUNET_JSONAPI_Resource* | ||
27 | GNUNET_JSONAPI_document_get_resource (struct GNUNET_JSONAPI_Document *doc, | ||
28 | int idx) | ||
29 | { | ||
30 | struct GNUNET_JSONAPI_Resource *res; | ||
31 | int i; | ||
32 | |||
33 | if ((0 == doc->res_count) || | ||
34 | (idx >= doc->res_count)) | ||
35 | return NULL; | ||
36 | res = doc->res_list_head; | ||
37 | for (i = 0; i < idx; i++) | ||
38 | { | ||
39 | res = res->next; | ||
40 | } | ||
41 | return res; | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Delete a JSON API primary data | ||
46 | * | ||
47 | * @param type the JSON API resource type | ||
48 | * @param id the JSON API resource id | ||
49 | * @return a new JSON API resource or NULL on error. | ||
50 | */ | ||
51 | void | ||
52 | GNUNET_JSONAPI_document_delete (struct GNUNET_JSONAPI_Document *doc) | ||
53 | { | ||
54 | struct GNUNET_JSONAPI_Resource *res; | ||
55 | struct GNUNET_JSONAPI_Resource *res_next; | ||
56 | struct GNUNET_JSONAPI_Error *err; | ||
57 | struct GNUNET_JSONAPI_Error *err_next; | ||
58 | |||
59 | |||
60 | for (err = doc->err_list_head; | ||
61 | err != NULL;) | ||
62 | { | ||
63 | err_next = err->next; | ||
64 | GNUNET_CONTAINER_DLL_remove (doc->err_list_head, | ||
65 | doc->err_list_tail, | ||
66 | err); | ||
67 | GNUNET_JSONAPI_error_delete (err); | ||
68 | err = err_next; | ||
69 | } | ||
70 | |||
71 | for (res = doc->res_list_head; | ||
72 | res != NULL;) | ||
73 | { | ||
74 | res_next = res->next; | ||
75 | GNUNET_CONTAINER_DLL_remove (doc->res_list_head, | ||
76 | doc->res_list_tail, | ||
77 | res); | ||
78 | GNUNET_JSONAPI_resource_delete (res); | ||
79 | res = res_next; | ||
80 | } | ||
81 | |||
82 | if (NULL != doc->meta) | ||
83 | json_decref (doc->meta); | ||
84 | GNUNET_free (doc); | ||
85 | doc = NULL; | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * Create a JSON API primary data | ||
90 | * | ||
91 | * @return a new JSON API resource or NULL on error. | ||
92 | */ | ||
93 | struct GNUNET_JSONAPI_Document* | ||
94 | GNUNET_JSONAPI_document_new () | ||
95 | { | ||
96 | struct GNUNET_JSONAPI_Document *result; | ||
97 | |||
98 | result = GNUNET_new (struct GNUNET_JSONAPI_Document); | ||
99 | result->res_count = 0; | ||
100 | result->err_count = 0; | ||
101 | result->meta = 0; | ||
102 | return result; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Add a JSON API error to document | ||
107 | * | ||
108 | * @param data The JSON API document to add to | ||
109 | * @param res the JSON API error to add | ||
110 | * @return the new number of resources | ||
111 | */ | ||
112 | void | ||
113 | GNUNET_JSONAPI_document_error_add (struct GNUNET_JSONAPI_Document *doc, | ||
114 | struct GNUNET_JSONAPI_Error *err) | ||
115 | { | ||
116 | GNUNET_CONTAINER_DLL_insert (doc->err_list_head, | ||
117 | doc->err_list_tail, | ||
118 | err); | ||
119 | |||
120 | doc->err_count++; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * Add a JSON API resource to primary data | ||
125 | * | ||
126 | * @param data The JSON API data to add to | ||
127 | * @param res the JSON API resource to add | ||
128 | * @return the new number of resources | ||
129 | */ | ||
130 | void | ||
131 | GNUNET_JSONAPI_document_resource_add (struct GNUNET_JSONAPI_Document *doc, | ||
132 | struct GNUNET_JSONAPI_Resource *res) | ||
133 | { | ||
134 | GNUNET_CONTAINER_DLL_insert (doc->res_list_head, | ||
135 | doc->res_list_tail, | ||
136 | res); | ||
137 | |||
138 | doc->res_count++; | ||
139 | } | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Parse given JSON object to jsonapi document. | ||
144 | * | ||
145 | * @param cls closure, NULL | ||
146 | * @param root the json object representing data | ||
147 | * @param[out] spec where to write the data | ||
148 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
149 | */ | ||
150 | static int | ||
151 | parse_jsonapiobject (void *cls, | ||
152 | json_t *root, | ||
153 | struct GNUNET_JSON_Specification *spec) | ||
154 | { | ||
155 | struct GNUNET_JSONAPI_Document *result; | ||
156 | struct GNUNET_JSONAPI_Error *error; | ||
157 | struct GNUNET_JSONAPI_Resource *resource; | ||
158 | json_t *meta_json; | ||
159 | json_t *resource_json; | ||
160 | json_t *errors_json; | ||
161 | json_t *value; | ||
162 | size_t index; | ||
163 | |||
164 | struct GNUNET_JSON_Specification jsonapispecerrors[] = { | ||
165 | GNUNET_JSON_spec_json (GNUNET_JSONAPI_KEY_ERRORS, &errors_json), | ||
166 | GNUNET_JSON_spec_end() | ||
167 | }; | ||
168 | if (GNUNET_OK != | ||
169 | GNUNET_JSON_parse (root, jsonapispecerrors, | ||
170 | NULL, NULL)) | ||
171 | { | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
173 | "JSONAPI document does not contain error objects\n"); | ||
174 | } else if (!json_is_array (errors_json)) | ||
175 | { | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
177 | "Error object is not array!\n"); | ||
178 | GNUNET_JSON_parse_free (jsonapispecerrors); | ||
179 | return GNUNET_SYSERR; | ||
180 | } | ||
181 | struct GNUNET_JSON_Specification jsonapispecmeta[] = { | ||
182 | GNUNET_JSON_spec_json (GNUNET_JSONAPI_KEY_META, &meta_json), | ||
183 | GNUNET_JSON_spec_end() | ||
184 | }; | ||
185 | if (GNUNET_OK != | ||
186 | GNUNET_JSON_parse (root, jsonapispecmeta, | ||
187 | NULL, NULL)) | ||
188 | { | ||
189 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
190 | "JSONAPI document does not contain error objects\n"); | ||
191 | } | ||
192 | struct GNUNET_JSON_Specification jsonapispecresource[] = { | ||
193 | GNUNET_JSON_spec_json (GNUNET_JSONAPI_KEY_DATA, &resource_json), | ||
194 | GNUNET_JSON_spec_end() | ||
195 | }; | ||
196 | if (GNUNET_OK != | ||
197 | GNUNET_JSON_parse (root, jsonapispecresource, | ||
198 | NULL, NULL)) | ||
199 | { | ||
200 | if (NULL == errors_json) | ||
201 | { | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
203 | "JSONAPI document contains neither error nor data!\n"); | ||
204 | GNUNET_JSON_parse_free (jsonapispecerrors); | ||
205 | GNUNET_JSON_parse_free (jsonapispecmeta); | ||
206 | return GNUNET_SYSERR; | ||
207 | } | ||
208 | } else { | ||
209 | if (NULL != errors_json) | ||
210 | { | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
212 | "JSONAPI document contains both error and data!\n"); | ||
213 | GNUNET_JSON_parse_free (jsonapispecerrors); | ||
214 | GNUNET_JSON_parse_free (jsonapispecmeta); | ||
215 | GNUNET_JSON_parse_free (jsonapispecresource); | ||
216 | return GNUNET_SYSERR; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | result = GNUNET_new (struct GNUNET_JSONAPI_Document); | ||
221 | result->res_count = 0; | ||
222 | result->err_count = 0; | ||
223 | if (NULL != meta_json) | ||
224 | result->meta = json_deep_copy (meta_json); | ||
225 | if (NULL != errors_json) { | ||
226 | json_array_foreach(errors_json, index, value) { | ||
227 | GNUNET_assert (GNUNET_OK == | ||
228 | GNUNET_JSONAPI_json_to_error (value, | ||
229 | &error)); | ||
230 | GNUNET_JSONAPI_document_error_add (result, error); | ||
231 | } | ||
232 | } | ||
233 | if (NULL != resource_json) { | ||
234 | if (0 != json_is_array (resource_json)) | ||
235 | { | ||
236 | json_array_foreach(resource_json, index, value) { | ||
237 | GNUNET_assert (GNUNET_OK == | ||
238 | GNUNET_JSONAPI_json_to_resource (value, | ||
239 | &resource)); | ||
240 | GNUNET_JSONAPI_document_resource_add (result, resource); | ||
241 | } | ||
242 | } else { | ||
243 | GNUNET_assert (GNUNET_OK == | ||
244 | GNUNET_JSONAPI_json_to_resource (resource_json, | ||
245 | &resource)); | ||
246 | GNUNET_JSONAPI_document_resource_add (result, resource); | ||
247 | } | ||
248 | } | ||
249 | if (NULL != errors_json) | ||
250 | GNUNET_JSON_parse_free (jsonapispecerrors); | ||
251 | if (NULL != resource) | ||
252 | GNUNET_JSON_parse_free (jsonapispecresource); | ||
253 | if (NULL != meta_json) | ||
254 | GNUNET_JSON_parse_free (jsonapispecmeta); | ||
255 | *(struct GNUNET_JSONAPI_Document **) spec->ptr = result; | ||
256 | return GNUNET_OK; | ||
257 | } | ||
258 | |||
259 | |||
260 | /** | ||
261 | * Cleanup data left from parsing RSA public key. | ||
262 | * | ||
263 | * @param cls closure, NULL | ||
264 | * @param[out] spec where to free the data | ||
265 | */ | ||
266 | static void | ||
267 | clean_jsonapiobject (void *cls, | ||
268 | struct GNUNET_JSON_Specification *spec) | ||
269 | { | ||
270 | struct GNUNET_JSONAPI_Document **jsonapi_obj; | ||
271 | jsonapi_obj = (struct GNUNET_JSONAPI_Document **) spec->ptr; | ||
272 | if (NULL != *jsonapi_obj) | ||
273 | { | ||
274 | GNUNET_JSONAPI_document_delete (*jsonapi_obj); | ||
275 | *jsonapi_obj = NULL; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | /** | ||
280 | * Add a JSON API resource to primary data | ||
281 | * | ||
282 | * @param data The JSON API data to add to | ||
283 | * @param res the JSON API resource to add | ||
284 | * @return the new number of resources | ||
285 | */ | ||
286 | void | ||
287 | GNUNET_JSONAPI_document_resource_remove (struct GNUNET_JSONAPI_Document *resp, | ||
288 | struct GNUNET_JSONAPI_Resource *res) | ||
289 | { | ||
290 | GNUNET_CONTAINER_DLL_remove (resp->res_list_head, | ||
291 | resp->res_list_tail, | ||
292 | res); | ||
293 | resp->res_count--; | ||
294 | } | ||
295 | |||
296 | |||
297 | /** | ||
298 | * String serialze jsonapi primary data | ||
299 | * | ||
300 | * @param data the JSON API primary data | ||
301 | * @param result where to store the result | ||
302 | * @return GNUNET_SYSERR on error else GNUNET_OK | ||
303 | */ | ||
304 | int | ||
305 | GNUNET_JSONAPI_document_to_json (const struct GNUNET_JSONAPI_Document *doc, | ||
306 | json_t **root_json) | ||
307 | { | ||
308 | struct GNUNET_JSONAPI_Resource *res; | ||
309 | struct GNUNET_JSONAPI_Error *error; | ||
310 | json_t *res_json; | ||
311 | json_t *res_json_tmp; | ||
312 | |||
313 | if ((NULL == doc)) | ||
314 | return GNUNET_SYSERR; | ||
315 | |||
316 | *root_json = json_object (); | ||
317 | |||
318 | //Check for errors first | ||
319 | if (doc->err_count != 0) | ||
320 | { | ||
321 | res_json = json_array (); | ||
322 | for (error = doc->err_list_head; | ||
323 | error != NULL; | ||
324 | error = error->next) | ||
325 | { | ||
326 | GNUNET_assert (GNUNET_OK == | ||
327 | GNUNET_JSONAPI_error_to_json (error, | ||
328 | &res_json_tmp)); | ||
329 | json_array_append_new (res_json, res_json_tmp); | ||
330 | } | ||
331 | json_object_set_new (*root_json, | ||
332 | GNUNET_JSONAPI_KEY_ERRORS, | ||
333 | res_json); | ||
334 | } else { | ||
335 | if (0 == doc->res_count) | ||
336 | { | ||
337 | res_json = json_null(); | ||
338 | } else { | ||
339 | res_json = json_array (); | ||
340 | for (res = doc->res_list_head; | ||
341 | res != NULL; | ||
342 | res = res->next) | ||
343 | { | ||
344 | GNUNET_assert (GNUNET_OK == | ||
345 | GNUNET_JSONAPI_resource_to_json (res, | ||
346 | &res_json_tmp)); | ||
347 | json_array_append_new (res_json, res_json_tmp); | ||
348 | } | ||
349 | } | ||
350 | json_object_set_new (*root_json, | ||
351 | GNUNET_JSONAPI_KEY_DATA, | ||
352 | res_json); | ||
353 | } | ||
354 | json_object_set (*root_json, | ||
355 | GNUNET_JSONAPI_KEY_META, | ||
356 | doc->meta); | ||
357 | return GNUNET_OK; | ||
358 | } | ||
359 | |||
360 | /** | ||
361 | * String serialze jsonapi primary data | ||
362 | * | ||
363 | * @param data the JSON API primary data | ||
364 | * @param result where to store the result | ||
365 | * @return GNUNET_SYSERR on error else GNUNET_OK | ||
366 | */ | ||
367 | int | ||
368 | GNUNET_JSONAPI_document_serialize (const struct GNUNET_JSONAPI_Document *doc, | ||
369 | char **result) | ||
370 | { | ||
371 | json_t *json_doc; | ||
372 | if (GNUNET_OK != GNUNET_JSONAPI_document_to_json (doc, | ||
373 | &json_doc)) | ||
374 | return GNUNET_SYSERR; | ||
375 | |||
376 | *result = json_dumps (json_doc, JSON_INDENT(2)); | ||
377 | json_decref (json_doc); | ||
378 | return GNUNET_OK; | ||
379 | } | ||
380 | |||
381 | /** | ||
382 | * JSON object. | ||
383 | * | ||
384 | * @param name name of the JSON field | ||
385 | * @param[out] jsonp where to store the JSON found under @a name | ||
386 | */ | ||
387 | struct GNUNET_JSON_Specification | ||
388 | GNUNET_JSON_spec_jsonapi_document (struct GNUNET_JSONAPI_Document **jsonapi_object) | ||
389 | { | ||
390 | struct GNUNET_JSON_Specification ret = { | ||
391 | .parser = &parse_jsonapiobject, | ||
392 | .cleaner = &clean_jsonapiobject, | ||
393 | .cls = NULL, | ||
394 | .field = NULL, | ||
395 | .ptr = jsonapi_object, | ||
396 | .ptr_size = 0, | ||
397 | .size_ptr = NULL | ||
398 | }; | ||
399 | *jsonapi_object = NULL; | ||
400 | return ret; | ||
401 | } | ||
402 | |||
diff --git a/src/jsonapi/jsonapi_error.c b/src/jsonapi/jsonapi_error.c deleted file mode 100644 index 8ce71d26f..000000000 --- a/src/jsonapi/jsonapi_error.c +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_jsonapi_lib.h" | ||
3 | #include "jsonapi_objects.h" | ||
4 | |||
5 | /** | ||
6 | * Parse json to error object | ||
7 | * | ||
8 | * @param err_json JSON object | ||
9 | * @param[out] err error object | ||
10 | * @return GNUNET_OK on success | ||
11 | */ | ||
12 | int | ||
13 | GNUNET_JSONAPI_json_to_error (json_t *err_json, | ||
14 | struct GNUNET_JSONAPI_Error **err) | ||
15 | { | ||
16 | struct GNUNET_JSON_Specification jsonapispecerror[] = { | ||
17 | GNUNET_JSON_spec_jsonapi_error (err), | ||
18 | GNUNET_JSON_spec_end() | ||
19 | }; | ||
20 | return GNUNET_JSON_parse (err_json, jsonapispecerror, | ||
21 | NULL, NULL); | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * Serialze jsonapi errors | ||
26 | * | ||
27 | * @param data the JSON API errors | ||
28 | * @param result where to store the result | ||
29 | * @return GNUNET_SYSERR on error else GNUNET_OK | ||
30 | */ | ||
31 | int | ||
32 | GNUNET_JSONAPI_error_to_json (const struct GNUNET_JSONAPI_Error *err, | ||
33 | json_t **result) | ||
34 | { | ||
35 | *result = json_object (); | ||
36 | |||
37 | if ((NULL != err->id) && | ||
38 | (0 != json_object_set_new (*result, | ||
39 | GNUNET_JSONAPI_KEY_ID, | ||
40 | json_string (err->id)))) | ||
41 | return GNUNET_SYSERR; | ||
42 | if ((NULL != err->status) && | ||
43 | (0 != json_object_set_new (*result, | ||
44 | GNUNET_JSONAPI_KEY_STATUS, | ||
45 | json_string (err->status)))) | ||
46 | return GNUNET_SYSERR; | ||
47 | if ((NULL != err->code) && | ||
48 | (0 != json_object_set_new (*result, | ||
49 | GNUNET_JSONAPI_KEY_CODE, | ||
50 | json_string (err->code)))) | ||
51 | return GNUNET_SYSERR; | ||
52 | |||
53 | if ((NULL != err->title) && | ||
54 | (0 != json_object_set_new (*result, | ||
55 | GNUNET_JSONAPI_KEY_TITLE, | ||
56 | json_string (err->title)))) | ||
57 | return GNUNET_SYSERR; | ||
58 | if ((NULL != err->detail) && | ||
59 | (0 != json_object_set_new (*result, | ||
60 | GNUNET_JSONAPI_KEY_DETAIL, | ||
61 | json_string (err->detail)))) | ||
62 | return GNUNET_SYSERR; | ||
63 | if ((NULL != err->source) && | ||
64 | (0 != json_object_set_new (*result, | ||
65 | GNUNET_JSONAPI_KEY_SOURCE, | ||
66 | err->source))) | ||
67 | return GNUNET_SYSERR; | ||
68 | if ((NULL != err->links) && | ||
69 | (0 != json_object_set_new (*result, | ||
70 | GNUNET_JSONAPI_KEY_LINKS, | ||
71 | err->links))) | ||
72 | return GNUNET_SYSERR; | ||
73 | if ((NULL != err->meta) && | ||
74 | (0 != json_object_set_new (*result, | ||
75 | GNUNET_JSONAPI_KEY_META, | ||
76 | err->meta))) | ||
77 | return GNUNET_SYSERR; | ||
78 | return GNUNET_OK; | ||
79 | } | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Parse given JSON object to jsonapi document. | ||
84 | * | ||
85 | * @param cls closure, NULL | ||
86 | * @param root the json object representing data | ||
87 | * @param[out] spec where to write the data | ||
88 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
89 | */ | ||
90 | static int | ||
91 | parse_jsonapierror (void *cls, | ||
92 | json_t *root, | ||
93 | struct GNUNET_JSON_Specification *spec) | ||
94 | { | ||
95 | struct GNUNET_JSONAPI_Error *result; | ||
96 | json_t *pos; | ||
97 | |||
98 | GNUNET_assert (NULL != root); | ||
99 | result = GNUNET_new (struct GNUNET_JSONAPI_Error); | ||
100 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_ID); | ||
101 | if (json_is_string (pos)) | ||
102 | result->id = GNUNET_strdup (json_string_value (pos)); | ||
103 | |||
104 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_LINKS); | ||
105 | if (json_is_object (pos)) | ||
106 | result->links = json_deep_copy (pos); | ||
107 | |||
108 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_STATUS); | ||
109 | if (json_is_string (pos)) | ||
110 | result->status = GNUNET_strdup (json_string_value (pos)); | ||
111 | |||
112 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_CODE); | ||
113 | if (json_is_string (pos)) | ||
114 | result->code = GNUNET_strdup (json_string_value (pos)); | ||
115 | |||
116 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_TITLE); | ||
117 | if (json_is_string (pos)) | ||
118 | result->title = GNUNET_strdup (json_string_value (pos)); | ||
119 | |||
120 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_DETAIL); | ||
121 | if (json_is_string (pos)) | ||
122 | result->detail = GNUNET_strdup (json_string_value (pos)); | ||
123 | |||
124 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_SOURCE); | ||
125 | if (json_is_object (pos)) | ||
126 | result->source = json_deep_copy (pos); | ||
127 | pos = json_object_get (root, GNUNET_JSONAPI_KEY_META); | ||
128 | if (json_is_object (pos)) | ||
129 | result->meta = json_deep_copy (pos); | ||
130 | *(struct GNUNET_JSONAPI_Error **) spec->ptr = result; | ||
131 | return GNUNET_OK; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * Create a JSON API error | ||
136 | * | ||
137 | * @param res the JSON error | ||
138 | */ | ||
139 | struct GNUNET_JSONAPI_Error* | ||
140 | GNUNET_JSONAPI_error_new (const char *id, | ||
141 | const char *status, | ||
142 | const char *code, | ||
143 | const char *title, | ||
144 | const char *detail, | ||
145 | json_t *links, | ||
146 | json_t *source, | ||
147 | json_t *meta) | ||
148 | { | ||
149 | struct GNUNET_JSONAPI_Error *error; | ||
150 | error = GNUNET_new (struct GNUNET_JSONAPI_Error); | ||
151 | |||
152 | if (NULL != id) | ||
153 | error->id = GNUNET_strdup (id); | ||
154 | if (NULL != status) | ||
155 | error->status = GNUNET_strdup (status); | ||
156 | if (NULL != code) | ||
157 | error->code = GNUNET_strdup (code); | ||
158 | if (NULL != title) | ||
159 | error->title = GNUNET_strdup (title); | ||
160 | if (NULL != detail) | ||
161 | error->detail = GNUNET_strdup (detail); | ||
162 | if (NULL != links) | ||
163 | error->links = json_deep_copy (links); | ||
164 | if (NULL != source) | ||
165 | error->source = json_deep_copy (source); | ||
166 | if (NULL != meta) | ||
167 | error->meta = json_deep_copy (meta); | ||
168 | return error; | ||
169 | } | ||
170 | /** | ||
171 | * Delete a JSON API error | ||
172 | * | ||
173 | * @param res the JSON error | ||
174 | */ | ||
175 | void | ||
176 | GNUNET_JSONAPI_error_delete (struct GNUNET_JSONAPI_Error *error) | ||
177 | { | ||
178 | GNUNET_assert (NULL != error); | ||
179 | |||
180 | if (NULL != error->id) | ||
181 | GNUNET_free (error->id); | ||
182 | if (NULL != error->status) | ||
183 | GNUNET_free (error->status); | ||
184 | if (NULL != error->code) | ||
185 | GNUNET_free (error->code); | ||
186 | if (NULL != error->title) | ||
187 | GNUNET_free (error->title); | ||
188 | if (NULL != error->detail) | ||
189 | GNUNET_free (error->detail); | ||
190 | if (NULL != error->links) | ||
191 | json_decref (error->links); | ||
192 | if (NULL != error->source) | ||
193 | json_decref (error->source); | ||
194 | if (NULL != error->meta) | ||
195 | json_decref (error->meta); | ||
196 | GNUNET_free (error); | ||
197 | } | ||
198 | |||
199 | |||
200 | |||
201 | /** | ||
202 | * Cleanup data left from parsing RSA public key. | ||
203 | * | ||
204 | * @param cls closure, NULL | ||
205 | * @param[out] spec where to free the data | ||
206 | */ | ||
207 | static void | ||
208 | clean_jsonapierror (void *cls, | ||
209 | struct GNUNET_JSON_Specification *spec) | ||
210 | { | ||
211 | struct GNUNET_JSONAPI_Error **jsonapi_obj; | ||
212 | jsonapi_obj = (struct GNUNET_JSONAPI_Error **) spec->ptr; | ||
213 | if (NULL != *jsonapi_obj) | ||
214 | { | ||
215 | GNUNET_JSONAPI_error_delete (*jsonapi_obj); | ||
216 | *jsonapi_obj = NULL; | ||
217 | } | ||
218 | } | ||
219 | /** | ||
220 | * JSON object. | ||
221 | * | ||
222 | * @param name name of the JSON field | ||
223 | * @param[out] jsonp where to store the JSON found under @a name | ||
224 | */ | ||
225 | struct GNUNET_JSON_Specification | ||
226 | GNUNET_JSON_spec_jsonapi_error (struct GNUNET_JSONAPI_Error **jsonapi_object) | ||
227 | { | ||
228 | struct GNUNET_JSON_Specification ret = { | ||
229 | .parser = &parse_jsonapierror, | ||
230 | .cleaner = &clean_jsonapierror, | ||
231 | .cls = NULL, | ||
232 | .field = NULL, | ||
233 | .ptr = jsonapi_object, | ||
234 | .ptr_size = 0, | ||
235 | .size_ptr = NULL | ||
236 | }; | ||
237 | *jsonapi_object = NULL; | ||
238 | return ret; | ||
239 | } | ||
240 | |||
241 | |||
diff --git a/src/jsonapi/jsonapi_objects.h b/src/jsonapi/jsonapi_objects.h deleted file mode 100644 index 27c64eeb7..000000000 --- a/src/jsonapi/jsonapi_objects.h +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_jsonapi_lib.h" | ||
3 | /** | ||
4 | * jsonapi error object | ||
5 | */ | ||
6 | struct GNUNET_JSONAPI_Error | ||
7 | { | ||
8 | /** | ||
9 | * DLL | ||
10 | */ | ||
11 | struct GNUNET_JSONAPI_Error *next; | ||
12 | |||
13 | /** | ||
14 | * DLL | ||
15 | */ | ||
16 | struct GNUNET_JSONAPI_Error *prev; | ||
17 | |||
18 | /** | ||
19 | * Unique error id | ||
20 | */ | ||
21 | char *id; | ||
22 | |||
23 | /** | ||
24 | * Links object | ||
25 | */ | ||
26 | json_t *links; | ||
27 | |||
28 | /** | ||
29 | * HTTP status code for this error | ||
30 | */ | ||
31 | char *status; | ||
32 | |||
33 | /** | ||
34 | * Application error code | ||
35 | */ | ||
36 | char *code; | ||
37 | |||
38 | /** | ||
39 | * Error title | ||
40 | */ | ||
41 | char *title; | ||
42 | |||
43 | /** | ||
44 | * Error details | ||
45 | */ | ||
46 | char *detail; | ||
47 | |||
48 | /** | ||
49 | * Error source | ||
50 | */ | ||
51 | json_t *source; | ||
52 | |||
53 | /** | ||
54 | * Meta info for the error | ||
55 | */ | ||
56 | json_t *meta; | ||
57 | }; | ||
58 | |||
59 | struct GNUNET_JSONAPI_Relationship | ||
60 | { | ||
61 | /** | ||
62 | * Links object | ||
63 | */ | ||
64 | struct GNUNET_JSONAPI_Link *links; | ||
65 | |||
66 | /** | ||
67 | * Resource linkage data | ||
68 | */ | ||
69 | struct GNUNET_JSONAPI_Resource *res_list_head; | ||
70 | |||
71 | /** | ||
72 | * DLL | ||
73 | */ | ||
74 | struct GNUNET_JSONAPI_Resource *res_list_tail; | ||
75 | |||
76 | /** | ||
77 | * Number of resources in data section | ||
78 | */ | ||
79 | int res_count; | ||
80 | |||
81 | /** | ||
82 | * Meta information | ||
83 | */ | ||
84 | json_t *meta; | ||
85 | }; | ||
86 | |||
87 | /** | ||
88 | * A jsonapi resource object | ||
89 | */ | ||
90 | struct GNUNET_JSONAPI_Resource | ||
91 | { | ||
92 | /** | ||
93 | * DLL | ||
94 | */ | ||
95 | struct GNUNET_JSONAPI_Resource *next; | ||
96 | |||
97 | /** | ||
98 | * DLL | ||
99 | */ | ||
100 | struct GNUNET_JSONAPI_Resource *prev; | ||
101 | |||
102 | /** | ||
103 | * Resource type | ||
104 | */ | ||
105 | char *type; | ||
106 | |||
107 | /** | ||
108 | * Resource ID | ||
109 | */ | ||
110 | char *id; | ||
111 | |||
112 | /** | ||
113 | * Attributes object | ||
114 | */ | ||
115 | json_t *attr_obj; | ||
116 | |||
117 | /** | ||
118 | * Relationship | ||
119 | */ | ||
120 | struct GNUNET_JSONAPI_Relationship *relationship; | ||
121 | }; | ||
122 | |||
123 | |||
124 | struct GNUNET_JSONAPI_Document | ||
125 | { | ||
126 | /** | ||
127 | * DLL Resource | ||
128 | */ | ||
129 | struct GNUNET_JSONAPI_Resource *res_list_head; | ||
130 | |||
131 | /** | ||
132 | * DLL Resource | ||
133 | */ | ||
134 | struct GNUNET_JSONAPI_Resource *res_list_tail; | ||
135 | |||
136 | /** | ||
137 | * num resources | ||
138 | */ | ||
139 | int res_count; | ||
140 | |||
141 | /** | ||
142 | * DLL Error | ||
143 | */ | ||
144 | struct GNUNET_JSONAPI_Error *err_list_head; | ||
145 | |||
146 | /** | ||
147 | * DLL Error | ||
148 | */ | ||
149 | struct GNUNET_JSONAPI_Error *err_list_tail; | ||
150 | |||
151 | /** | ||
152 | * num errors | ||
153 | */ | ||
154 | int err_count; | ||
155 | |||
156 | /** | ||
157 | * Meta info | ||
158 | */ | ||
159 | json_t *meta; | ||
160 | }; | ||
161 | |||
162 | |||
diff --git a/src/jsonapi/jsonapi_relationship.c b/src/jsonapi/jsonapi_relationship.c deleted file mode 100644 index b88e74cc9..000000000 --- a/src/jsonapi/jsonapi_relationship.c +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_jsonapi_lib.h" | ||
3 | |||
4 | |||
5 | /** | ||
6 | * Delete a JSON API relationship TODO | ||
7 | * | ||
8 | * @param res the JSON relationship | ||
9 | */ | ||
10 | void | ||
11 | GNUNET_JSONAPI_relationship_delete (struct GNUNET_JSONAPI_Relationship *relationship) | ||
12 | { | ||
13 | GNUNET_assert (NULL != relationship); | ||
14 | GNUNET_free (relationship); | ||
15 | } | ||
16 | |||
17 | |||
diff --git a/src/jsonapi/jsonapi_resource.c b/src/jsonapi/jsonapi_resource.c deleted file mode 100644 index be28ad5df..000000000 --- a/src/jsonapi/jsonapi_resource.c +++ /dev/null | |||
@@ -1,367 +0,0 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_jsonapi_lib.h" | ||
3 | #include "jsonapi_objects.h" | ||
4 | |||
5 | /** | ||
6 | * String serialze jsonapi resources | ||
7 | * | ||
8 | * @param data the JSON API resource | ||
9 | * @param result where to store the result | ||
10 | * @return GNUNET_SYSERR on error else GNUNET_OK | ||
11 | */ | ||
12 | int | ||
13 | GNUNET_JSONAPI_resource_to_json (const struct GNUNET_JSONAPI_Resource *res, | ||
14 | json_t **result) | ||
15 | { | ||
16 | struct GNUNET_JSONAPI_Resource *rel_res; | ||
17 | json_t *relationship; | ||
18 | json_t *res_json_tmp; | ||
19 | *result = json_object (); | ||
20 | |||
21 | if (0 != json_object_set_new (*result, | ||
22 | GNUNET_JSONAPI_KEY_ID, | ||
23 | json_string (res->id))) | ||
24 | return GNUNET_SYSERR; | ||
25 | if (0 != json_object_set_new (*result, | ||
26 | GNUNET_JSONAPI_KEY_TYPE, | ||
27 | json_string (res->type))) | ||
28 | return GNUNET_SYSERR; | ||
29 | if ((NULL != res->attr_obj) && | ||
30 | (0 != json_object_set (*result, | ||
31 | GNUNET_JSONAPI_KEY_ATTRIBUTES, | ||
32 | res->attr_obj))) | ||
33 | return GNUNET_SYSERR; | ||
34 | |||
35 | //Relationships | ||
36 | if (NULL != res->relationship) | ||
37 | { | ||
38 | relationship = json_object (); | ||
39 | if (0 != res->relationship->res_count) | ||
40 | { | ||
41 | json_t *res_json; | ||
42 | switch (res->relationship->res_count) | ||
43 | { | ||
44 | case 0: | ||
45 | res_json = json_null(); | ||
46 | break; | ||
47 | case 1: | ||
48 | GNUNET_assert (GNUNET_OK == | ||
49 | GNUNET_JSONAPI_resource_to_json (res->relationship->res_list_head, | ||
50 | &res_json)); | ||
51 | break; | ||
52 | default: | ||
53 | res_json = json_array (); | ||
54 | rel_res = NULL; | ||
55 | for (rel_res = res->relationship->res_list_head; | ||
56 | rel_res != NULL; | ||
57 | rel_res = rel_res->next) | ||
58 | { | ||
59 | GNUNET_assert (GNUNET_OK == | ||
60 | GNUNET_JSONAPI_resource_to_json (rel_res, | ||
61 | &res_json_tmp)); | ||
62 | json_array_append_new (res_json, res_json_tmp); | ||
63 | } | ||
64 | break; | ||
65 | } | ||
66 | json_object_set_new (relationship, | ||
67 | GNUNET_JSONAPI_KEY_DATA, | ||
68 | res_json); | ||
69 | } | ||
70 | if ((NULL != res->relationship->meta) && | ||
71 | (0 != json_object_set_new (relationship, | ||
72 | GNUNET_JSONAPI_KEY_META, | ||
73 | res->relationship->meta))) | ||
74 | return GNUNET_SYSERR; | ||
75 | //TODO link | ||
76 | } | ||
77 | |||
78 | |||
79 | return GNUNET_OK; | ||
80 | } | ||
81 | |||
82 | |||
83 | /** | ||
84 | * Create a JSON API resource | ||
85 | * | ||
86 | * @param type the JSON API resource type | ||
87 | * @param id the JSON API resource id | ||
88 | * @return a new JSON API resource or NULL on error. | ||
89 | */ | ||
90 | struct GNUNET_JSONAPI_Resource* | ||
91 | GNUNET_JSONAPI_resource_new (const char *type, const char *id) | ||
92 | { | ||
93 | struct GNUNET_JSONAPI_Resource *res; | ||
94 | |||
95 | if (NULL == type) | ||
96 | return NULL; | ||
97 | if (NULL == id) | ||
98 | return NULL; | ||
99 | |||
100 | res = GNUNET_new (struct GNUNET_JSONAPI_Resource); | ||
101 | res->prev = NULL; | ||
102 | res->next = NULL; | ||
103 | res->attr_obj = NULL; | ||
104 | res->relationship = NULL; | ||
105 | res->id = GNUNET_strdup (id); | ||
106 | res->type = GNUNET_strdup (type); | ||
107 | return res; | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Add a jsonapi relationship | ||
112 | * @param res the resource to add to | ||
113 | * @param rel the relationship to add | ||
114 | * @return #GNUNETOK if added successfully | ||
115 | */ | ||
116 | int | ||
117 | GNUNET_JSONAPI_resource_set_relationship (struct GNUNET_JSONAPI_Resource *res, | ||
118 | struct GNUNET_JSONAPI_Relationship *rel) | ||
119 | { | ||
120 | GNUNET_assert (NULL != res); | ||
121 | GNUNET_assert (NULL != rel); | ||
122 | if (NULL != res->relationship) | ||
123 | return GNUNET_SYSERR; | ||
124 | res->relationship = rel; | ||
125 | return GNUNET_OK; | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * Add a JSON API attribute | ||
130 | * | ||
131 | * @param res the JSON resource | ||
132 | * @param key the key for the attribute | ||
133 | * @param json the json_t attribute to add | ||
134 | * @return #GNUNET_OK if added successfully | ||
135 | * #GNUNET_SYSERR if not | ||
136 | */ | ||
137 | int | ||
138 | GNUNET_JSONAPI_resource_add_attr (struct GNUNET_JSONAPI_Resource *resource, | ||
139 | const char* key, | ||
140 | json_t *json) | ||
141 | { | ||
142 | if ( (NULL == resource) || | ||
143 | (NULL == key) || | ||
144 | (NULL == json) ) | ||
145 | return GNUNET_SYSERR; | ||
146 | if (NULL == resource->attr_obj) | ||
147 | resource->attr_obj = json_object (); | ||
148 | json_object_set (resource->attr_obj, key, json); | ||
149 | return GNUNET_OK; | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * Read a JSON API attribute | ||
154 | * | ||
155 | * @param res the JSON resource | ||
156 | * @param key the key for the attribute | ||
157 | * @return the json_t object | ||
158 | */ | ||
159 | json_t* | ||
160 | GNUNET_JSONAPI_resource_read_attr (const struct GNUNET_JSONAPI_Resource *resource, | ||
161 | const char* key) | ||
162 | { | ||
163 | if ( (NULL == resource) || | ||
164 | (NULL == key) || | ||
165 | (NULL == resource->attr_obj)) | ||
166 | return NULL; | ||
167 | return json_object_get (resource->attr_obj, key); | ||
168 | } | ||
169 | |||
170 | int | ||
171 | check_resource_attr_str (const struct GNUNET_JSONAPI_Resource *resource, | ||
172 | const char* key, | ||
173 | const char* attr) | ||
174 | { | ||
175 | json_t *value; | ||
176 | if ( (NULL == resource) || | ||
177 | (NULL == key) || | ||
178 | (NULL == attr) || | ||
179 | (NULL == resource->attr_obj)) | ||
180 | return GNUNET_NO; | ||
181 | value = json_object_get (resource->attr_obj, key); | ||
182 | if (NULL == value) | ||
183 | return GNUNET_NO; | ||
184 | if (!json_is_string (value) || | ||
185 | (0 != strcmp (attr, json_string_value(value)))) | ||
186 | { | ||
187 | return GNUNET_NO; | ||
188 | } | ||
189 | return GNUNET_YES; | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Check a JSON API resource type | ||
194 | * | ||
195 | * @param res the JSON resource | ||
196 | * @param type the expected type | ||
197 | * @return GNUNET_YES if id matches | ||
198 | */ | ||
199 | int | ||
200 | GNUNET_JSONAPI_resource_check_type (const struct GNUNET_JSONAPI_Resource *resource, | ||
201 | const char* type) | ||
202 | { | ||
203 | return (0 == memcmp (type, resource->type, | ||
204 | strlen (resource->type))) ? GNUNET_YES : GNUNET_NO; | ||
205 | } | ||
206 | |||
207 | |||
208 | /** | ||
209 | * Delete a JSON API resource | ||
210 | * | ||
211 | * @param res the JSON resource | ||
212 | * @param result Pointer where the resource should be stored | ||
213 | */ | ||
214 | void | ||
215 | GNUNET_JSONAPI_resource_delete (struct GNUNET_JSONAPI_Resource *resource) | ||
216 | { | ||
217 | GNUNET_free (resource->id); | ||
218 | GNUNET_free (resource->type); | ||
219 | if (NULL != resource->attr_obj) | ||
220 | json_decref (resource->attr_obj); | ||
221 | if (NULL != resource->relationship) | ||
222 | GNUNET_JSONAPI_relationship_delete (resource->relationship); | ||
223 | GNUNET_free (resource); | ||
224 | resource = NULL; | ||
225 | } | ||
226 | |||
227 | |||
228 | /** | ||
229 | * Check a JSON API resource id | ||
230 | * | ||
231 | * @param res the JSON resource | ||
232 | * @param id the expected id | ||
233 | * @return GNUNET_YES if id matches | ||
234 | */ | ||
235 | int | ||
236 | GNUNET_JSONAPI_resource_check_id (const struct GNUNET_JSONAPI_Resource *resource, | ||
237 | const char* id) | ||
238 | { | ||
239 | return (0 == memcmp (resource->id, id, strlen (id))) ? GNUNET_YES : GNUNET_NO; | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * Check a JSON API resource id | ||
244 | * | ||
245 | * @param res the JSON resource | ||
246 | * @return the resource id | ||
247 | */ | ||
248 | const char* | ||
249 | GNUNET_JSONAPI_resource_get_id (const struct GNUNET_JSONAPI_Resource *resource) | ||
250 | { | ||
251 | return resource->id; | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Parse json to resource object | ||
256 | * | ||
257 | * @param res_json JSON object | ||
258 | * @param[out] res resource object | ||
259 | * @return GNUNET_OK on success | ||
260 | */ | ||
261 | int | ||
262 | GNUNET_JSONAPI_json_to_resource (json_t *res_json, | ||
263 | struct GNUNET_JSONAPI_Resource **res) | ||
264 | { | ||
265 | struct GNUNET_JSON_Specification jsonapispecresource[] = { | ||
266 | GNUNET_JSON_spec_jsonapi_resource (res), | ||
267 | GNUNET_JSON_spec_end() | ||
268 | }; | ||
269 | return GNUNET_JSON_parse (res_json, jsonapispecresource, | ||
270 | NULL, NULL); | ||
271 | } | ||
272 | |||
273 | /** | ||
274 | * Parse given JSON object to jsonapi document. | ||
275 | * | ||
276 | * @param cls closure, NULL | ||
277 | * @param root the json object representing data | ||
278 | * @param[out] spec where to write the data | ||
279 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
280 | */ | ||
281 | static int | ||
282 | parse_jsonapiresource (void *cls, | ||
283 | json_t *root, | ||
284 | struct GNUNET_JSON_Specification *spec) | ||
285 | { | ||
286 | struct GNUNET_JSONAPI_Resource *res; | ||
287 | const char *type; | ||
288 | const char *id; | ||
289 | json_t *attrs; | ||
290 | |||
291 | struct GNUNET_JSON_Specification dspec[] = { | ||
292 | GNUNET_JSON_spec_string (GNUNET_JSONAPI_KEY_TYPE, &type), | ||
293 | GNUNET_JSON_spec_string (GNUNET_JSONAPI_KEY_ID, &id), | ||
294 | GNUNET_JSON_spec_end() | ||
295 | }; | ||
296 | |||
297 | if (GNUNET_OK != | ||
298 | GNUNET_JSON_parse (root, dspec, | ||
299 | NULL, NULL)) | ||
300 | { | ||
301 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to parse resource\n"); | ||
302 | return GNUNET_SYSERR; | ||
303 | } | ||
304 | res = GNUNET_JSONAPI_resource_new (type, id); | ||
305 | GNUNET_JSON_parse_free (dspec); | ||
306 | |||
307 | struct GNUNET_JSON_Specification attrspec[] = { | ||
308 | GNUNET_JSON_spec_json (GNUNET_JSONAPI_KEY_ATTRIBUTES, &attrs), | ||
309 | GNUNET_JSON_spec_end() | ||
310 | }; | ||
311 | if (GNUNET_OK != | ||
312 | GNUNET_JSON_parse (root, attrspec, | ||
313 | NULL, NULL)) | ||
314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Resource does not contain attributes\n"); | ||
315 | if (NULL != attrs) | ||
316 | res->attr_obj = json_deep_copy (attrs); | ||
317 | |||
318 | //TODO relationship | ||
319 | GNUNET_JSON_parse_free (attrspec); | ||
320 | *(struct GNUNET_JSONAPI_Resource **) spec->ptr = res; | ||
321 | return GNUNET_OK; | ||
322 | } | ||
323 | |||
324 | |||
325 | /** | ||
326 | * Cleanup data left from parsing resource. | ||
327 | * | ||
328 | * @param cls closure, NULL | ||
329 | * @param[out] spec where to free the data | ||
330 | */ | ||
331 | static void | ||
332 | clean_jsonapiresource (void *cls, | ||
333 | struct GNUNET_JSON_Specification *spec) | ||
334 | { | ||
335 | struct GNUNET_JSONAPI_Resource **jsonapi_obj; | ||
336 | jsonapi_obj = (struct GNUNET_JSONAPI_Resource **) spec->ptr; | ||
337 | if (NULL != *jsonapi_obj) | ||
338 | { | ||
339 | GNUNET_JSONAPI_resource_delete (*jsonapi_obj); | ||
340 | *jsonapi_obj = NULL; | ||
341 | } | ||
342 | } | ||
343 | |||
344 | |||
345 | /** | ||
346 | * JSON object. | ||
347 | * | ||
348 | * @param name name of the JSON field | ||
349 | * @param[out] jsonp where to store the JSON found under @a name | ||
350 | */ | ||
351 | struct GNUNET_JSON_Specification | ||
352 | GNUNET_JSON_spec_jsonapi_resource (struct GNUNET_JSONAPI_Resource **jsonapi_object) | ||
353 | { | ||
354 | struct GNUNET_JSON_Specification ret = { | ||
355 | .parser = &parse_jsonapiresource, | ||
356 | .cleaner = &clean_jsonapiresource, | ||
357 | .cls = NULL, | ||
358 | .field = NULL, | ||
359 | .ptr = jsonapi_object, | ||
360 | .ptr_size = 0, | ||
361 | .size_ptr = NULL | ||
362 | }; | ||
363 | *jsonapi_object = NULL; | ||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | |||
diff --git a/src/jsonapi/test_jsonapi.c b/src/jsonapi/test_jsonapi.c deleted file mode 100644 index 59d0bed76..000000000 --- a/src/jsonapi/test_jsonapi.c +++ /dev/null | |||
@@ -1,190 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2015, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | /** | ||
20 | * @file json/test_jsonapi.c | ||
21 | * @brief Tests for jsonapi conversion functions | ||
22 | * @author Martin Schanzenbach | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | #include "gnunet_jsonapi_lib.h" | ||
27 | #include "gnunet_json_lib.h" | ||
28 | |||
29 | #define TEST_JSONAPI_DOCUMENT "{\"data\":[{\"id\":\"1\",\"type\":\"bar\",\"attributes\":{\"foo\":\"bar\"}}]}" | ||
30 | |||
31 | #define TEST_JSONAPI_DOCUMENT_ERR "{\"errors\":[{\"id\":\"1\",\"status\":\"403\",\"code\":\"23\", \"title\":\"Error\", \"detail\":\"Error details\"}]}" | ||
32 | |||
33 | static int | ||
34 | test_document_error () | ||
35 | { | ||
36 | struct GNUNET_JSONAPI_Document *obj; | ||
37 | struct GNUNET_JSONAPI_Error *error; | ||
38 | json_t *doc_json; | ||
39 | json_t *data_js; | ||
40 | json_error_t err; | ||
41 | |||
42 | obj = GNUNET_JSONAPI_document_new (); | ||
43 | error = GNUNET_JSONAPI_error_new ("1", | ||
44 | "403", | ||
45 | "23", | ||
46 | "Error", | ||
47 | "Error details", | ||
48 | NULL, | ||
49 | NULL, | ||
50 | NULL); | ||
51 | |||
52 | |||
53 | GNUNET_JSONAPI_document_error_add (obj, | ||
54 | error); | ||
55 | |||
56 | GNUNET_assert (GNUNET_OK == | ||
57 | GNUNET_JSONAPI_document_to_json (obj, | ||
58 | &doc_json)); | ||
59 | data_js = json_loads (TEST_JSONAPI_DOCUMENT_ERR, | ||
60 | JSON_DECODE_ANY, | ||
61 | &err); | ||
62 | GNUNET_assert (NULL != data_js); | ||
63 | GNUNET_assert (0 != json_equal (data_js, doc_json)); | ||
64 | GNUNET_JSONAPI_document_delete (obj); | ||
65 | json_decref (data_js); | ||
66 | json_decref (doc_json); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | |||
71 | static int | ||
72 | test_document () | ||
73 | { | ||
74 | struct GNUNET_JSONAPI_Document *obj; | ||
75 | struct GNUNET_JSONAPI_Resource *res; | ||
76 | json_t *doc_json; | ||
77 | json_t *data_js; | ||
78 | json_error_t err; | ||
79 | int ret; | ||
80 | |||
81 | obj = GNUNET_JSONAPI_document_new (); | ||
82 | res = GNUNET_JSONAPI_resource_new ("bar", | ||
83 | "1"); | ||
84 | |||
85 | GNUNET_assert (GNUNET_OK == | ||
86 | GNUNET_JSONAPI_resource_add_attr (res, | ||
87 | "foo", | ||
88 | json_string ("bar"))); | ||
89 | |||
90 | GNUNET_JSONAPI_document_resource_add (obj, | ||
91 | res); | ||
92 | |||
93 | GNUNET_assert (GNUNET_OK == | ||
94 | GNUNET_JSONAPI_document_to_json (obj, | ||
95 | &doc_json)); | ||
96 | data_js = json_loads (TEST_JSONAPI_DOCUMENT, | ||
97 | JSON_DECODE_ANY, | ||
98 | &err); | ||
99 | GNUNET_assert (NULL != data_js); | ||
100 | ret = json_equal (data_js, doc_json) ? 0 : 1; | ||
101 | GNUNET_JSONAPI_document_delete (obj); | ||
102 | json_decref (data_js); | ||
103 | json_decref (doc_json); | ||
104 | return ret; | ||
105 | } | ||
106 | |||
107 | static int | ||
108 | test_serialize () | ||
109 | { | ||
110 | struct GNUNET_JSONAPI_Document *obj; | ||
111 | char* tmp_data; | ||
112 | int ret; | ||
113 | json_t* data_js; | ||
114 | json_t* tmp_data_js; | ||
115 | json_error_t err; | ||
116 | struct GNUNET_JSON_Specification jsonapispec[] = { | ||
117 | GNUNET_JSON_spec_jsonapi_document (&obj), | ||
118 | GNUNET_JSON_spec_end() | ||
119 | }; | ||
120 | data_js = json_loads (TEST_JSONAPI_DOCUMENT, | ||
121 | JSON_DECODE_ANY, | ||
122 | &err); | ||
123 | GNUNET_assert (NULL != data_js); | ||
124 | GNUNET_assert (GNUNET_OK == | ||
125 | GNUNET_JSON_parse (data_js, jsonapispec, | ||
126 | NULL, NULL)); | ||
127 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_document_serialize (obj, | ||
128 | &tmp_data)); | ||
129 | GNUNET_JSON_parse_free (jsonapispec); | ||
130 | tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err); | ||
131 | GNUNET_assert (NULL != tmp_data_js); | ||
132 | ret = (1 == json_equal (tmp_data_js, data_js)) ? 0 : 1; | ||
133 | json_decref (data_js); | ||
134 | json_decref (tmp_data_js); | ||
135 | GNUNET_free (tmp_data); | ||
136 | return ret; | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * Test rsa conversions from/to JSON. | ||
141 | * | ||
142 | * @return 0 on success | ||
143 | */ | ||
144 | static int | ||
145 | test_spec_jsonapi () | ||
146 | { | ||
147 | struct GNUNET_JSONAPI_Document *obj; | ||
148 | struct GNUNET_JSONAPI_Resource *res; | ||
149 | const char* data = "{\"data\":{\"id\":\"1\", \"type\":\"test\"}}"; | ||
150 | json_t* data_js; | ||
151 | json_error_t err; | ||
152 | |||
153 | struct GNUNET_JSON_Specification jsonapispec[] = { | ||
154 | GNUNET_JSON_spec_jsonapi_document (&obj), | ||
155 | GNUNET_JSON_spec_end() | ||
156 | }; | ||
157 | data_js = json_loads (data, JSON_DECODE_ANY, &err); | ||
158 | GNUNET_assert (NULL != data_js); | ||
159 | GNUNET_assert (GNUNET_OK == | ||
160 | GNUNET_JSON_parse (data_js, jsonapispec, | ||
161 | NULL, NULL)); | ||
162 | json_decref (data_js); | ||
163 | res = GNUNET_JSONAPI_document_get_resource (obj, 0); | ||
164 | GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_id (res, "1")); | ||
165 | GNUNET_assert (GNUNET_YES == GNUNET_JSONAPI_resource_check_type (res, "test")); | ||
166 | GNUNET_assert (1 == GNUNET_JSONAPI_document_resource_count (obj)); | ||
167 | GNUNET_JSON_parse_free (jsonapispec); | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | |||
172 | int | ||
173 | main(int argc, | ||
174 | const char *const argv[]) | ||
175 | { | ||
176 | GNUNET_log_setup ("test-jsonapi", | ||
177 | "WARNING", | ||
178 | NULL); | ||
179 | if (0 != test_spec_jsonapi ()) | ||
180 | return 1; | ||
181 | if (0 != test_serialize ()) | ||
182 | return 1; | ||
183 | if (0 != test_document ()) | ||
184 | return 1; | ||
185 | if (0 != test_document_error ()) | ||
186 | return 1; | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | /* end of test_json.c */ | ||
diff --git a/src/rest-plugins/Makefile.am b/src/rest-plugins/Makefile.am index 484dceaba..61cd7955d 100644 --- a/src/rest-plugins/Makefile.am +++ b/src/rest-plugins/Makefile.am | |||
@@ -25,9 +25,25 @@ plugin_LTLIBRARIES = \ | |||
25 | libgnunet_plugin_rest_gns.la \ | 25 | libgnunet_plugin_rest_gns.la \ |
26 | libgnunet_plugin_rest_credential.la | 26 | libgnunet_plugin_rest_credential.la |
27 | if HAVE_ABE | 27 | if HAVE_ABE |
28 | plugin_LTLIBRARIES += libgnunet_plugin_rest_openid_connect.la | 28 | plugin_LTLIBRARIES += libgnunet_plugin_rest_openid_connect.la \ |
29 | libgnunet_plugin_rest_reclaim.la | ||
29 | endif | 30 | endif |
30 | 31 | ||
32 | libgnunet_plugin_rest_reclaim_la_SOURCES = \ | ||
33 | plugin_rest_reclaim.c \ | ||
34 | json_reclaim.c | ||
35 | libgnunet_plugin_rest_reclaim_la_LIBADD = \ | ||
36 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
37 | $(top_builddir)/src/reclaim/libgnunetreclaim.la \ | ||
38 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
39 | $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ | ||
40 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
41 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
42 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
43 | libgnunet_plugin_rest_reclaim_la_LDFLAGS = \ | ||
44 | i$(GN_PLUGIN_LDFLAGS) | ||
45 | |||
46 | |||
31 | libgnunet_plugin_rest_credential_la_SOURCES = \ | 47 | libgnunet_plugin_rest_credential_la_SOURCES = \ |
32 | plugin_rest_credential.c | 48 | plugin_rest_credential.c |
33 | libgnunet_plugin_rest_credential_la_LIBADD = \ | 49 | libgnunet_plugin_rest_credential_la_LIBADD = \ |
@@ -41,9 +57,6 @@ libgnunet_plugin_rest_credential_la_LIBADD = \ | |||
41 | libgnunet_plugin_rest_credential_la_LDFLAGS = \ | 57 | libgnunet_plugin_rest_credential_la_LDFLAGS = \ |
42 | $(GN_PLUGIN_LDFLAGS) | 58 | $(GN_PLUGIN_LDFLAGS) |
43 | 59 | ||
44 | |||
45 | |||
46 | |||
47 | libgnunet_plugin_rest_copying_la_SOURCES = \ | 60 | libgnunet_plugin_rest_copying_la_SOURCES = \ |
48 | plugin_rest_copying.c | 61 | plugin_rest_copying.c |
49 | libgnunet_plugin_rest_copying_la_LIBADD = \ | 62 | libgnunet_plugin_rest_copying_la_LIBADD = \ |
diff --git a/src/rest-plugins/json_reclaim.c b/src/rest-plugins/json_reclaim.c new file mode 100644 index 000000000..c0cce3be5 --- /dev/null +++ b/src/rest-plugins/json_reclaim.c | |||
@@ -0,0 +1,242 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009-2018 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | /** | ||
20 | * @file rest-plugins/json_reclaim.c | ||
21 | * @brief JSON handling of reclaim data | ||
22 | * @author Martin Schanzenbach | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | #include "gnunet_json_lib.h" | ||
27 | #include "gnunet_reclaim_service.h" | ||
28 | #include "gnunet_reclaim_attribute_lib.h" | ||
29 | |||
30 | /** | ||
31 | * Parse given JSON object to a claim | ||
32 | * | ||
33 | * @param cls closure, NULL | ||
34 | * @param root the json object representing data | ||
35 | * @param spec where to write the data | ||
36 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
37 | */ | ||
38 | static int | ||
39 | parse_attr (void *cls, | ||
40 | json_t *root, | ||
41 | struct GNUNET_JSON_Specification *spec) | ||
42 | { | ||
43 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | ||
44 | const char* name_str; | ||
45 | const char* val_str; | ||
46 | const char* type_str; | ||
47 | const char* exp_str; | ||
48 | char *data; | ||
49 | int unpack_state; | ||
50 | uint32_t type; | ||
51 | size_t data_size; | ||
52 | |||
53 | GNUNET_assert(NULL != root); | ||
54 | |||
55 | if(!json_is_object(root)) | ||
56 | { | ||
57 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
58 | "Error json is not array nor object!\n"); | ||
59 | return GNUNET_SYSERR; | ||
60 | } | ||
61 | //interpret single attribute | ||
62 | unpack_state = json_unpack(root, | ||
63 | "{s:s, s:s, s:s, s:s!}", | ||
64 | "name", &name_str, | ||
65 | "type", &type_str, | ||
66 | "value", &val_str, | ||
67 | "exp", &exp_str); | ||
68 | if (0 != unpack_state) | ||
69 | { | ||
70 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
71 | "Error json object has a wrong format!\n"); | ||
72 | return GNUNET_SYSERR; | ||
73 | } | ||
74 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | ||
75 | if (GNUNET_SYSERR == (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, | ||
76 | val_str, | ||
77 | (void**)&data, | ||
78 | &data_size))) | ||
79 | { | ||
80 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
81 | "Attribute value invalid!\n"); | ||
82 | return GNUNET_SYSERR; | ||
83 | } | ||
84 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, | ||
85 | type, | ||
86 | data, | ||
87 | data_size); | ||
88 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; | ||
89 | return GNUNET_OK; | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * Cleanup data left from parsing RSA public key. | ||
94 | * | ||
95 | * @param cls closure, NULL | ||
96 | * @param[out] spec where to free the data | ||
97 | */ | ||
98 | static void | ||
99 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | ||
100 | { | ||
101 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; | ||
102 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; | ||
103 | if (NULL != *attr) | ||
104 | { | ||
105 | GNUNET_free(*attr); | ||
106 | *attr = NULL; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * JSON Specification for Reclaim claims. | ||
112 | * | ||
113 | * @param ticket struct of GNUNET_RECLAIM_ATTRIBUTE_Claim to fill | ||
114 | * @return JSON Specification | ||
115 | */ | ||
116 | struct GNUNET_JSON_Specification | ||
117 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | ||
118 | { | ||
119 | struct GNUNET_JSON_Specification ret = { | ||
120 | .parser = &parse_attr, | ||
121 | .cleaner = &clean_attr, | ||
122 | .cls = NULL, | ||
123 | .field = NULL, | ||
124 | .ptr = attr, | ||
125 | .ptr_size = 0, | ||
126 | .size_ptr = NULL | ||
127 | }; | ||
128 | *attr = NULL; | ||
129 | return ret; | ||
130 | } | ||
131 | /** | ||
132 | * Parse given JSON object to a ticket | ||
133 | * | ||
134 | * @param cls closure, NULL | ||
135 | * @param root the json object representing data | ||
136 | * @param spec where to write the data | ||
137 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
138 | */ | ||
139 | static int | ||
140 | parse_ticket (void *cls, | ||
141 | json_t *root, | ||
142 | struct GNUNET_JSON_Specification *spec) | ||
143 | { | ||
144 | struct GNUNET_RECLAIM_Ticket *ticket; | ||
145 | const char* rnd_str; | ||
146 | const char* aud_str; | ||
147 | const char* id_str; | ||
148 | int unpack_state; | ||
149 | |||
150 | GNUNET_assert(NULL != root); | ||
151 | |||
152 | if(!json_is_object(root)) | ||
153 | { | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
155 | "Error json is not array nor object!\n"); | ||
156 | return GNUNET_SYSERR; | ||
157 | } | ||
158 | //interpret single ticket | ||
159 | unpack_state = json_unpack(root, | ||
160 | "{s:s, s:s, s:s!}", | ||
161 | "rnd", &rnd_str, | ||
162 | "audience", &aud_str, | ||
163 | "identity", &id_str); | ||
164 | if (0 != unpack_state) | ||
165 | { | ||
166 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
167 | "Error json object has a wrong format!\n"); | ||
168 | return GNUNET_SYSERR; | ||
169 | } | ||
170 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); | ||
171 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, | ||
172 | strlen (rnd_str), | ||
173 | &ticket->rnd, | ||
174 | sizeof (uint64_t))) | ||
175 | { | ||
176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Rnd invalid\n"); | ||
177 | GNUNET_free(ticket); | ||
178 | return GNUNET_SYSERR; | ||
179 | } | ||
180 | GNUNET_STRINGS_string_to_data (id_str, | ||
181 | strlen (id_str), | ||
182 | &ticket->identity, | ||
183 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
184 | { | ||
185 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Identity invalid\n"); | ||
186 | GNUNET_free(ticket); | ||
187 | return GNUNET_SYSERR; | ||
188 | } | ||
189 | |||
190 | GNUNET_STRINGS_string_to_data (aud_str, | ||
191 | strlen (aud_str), | ||
192 | &ticket->audience, | ||
193 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
194 | { | ||
195 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Audience invalid\n"); | ||
196 | GNUNET_free(ticket); | ||
197 | return GNUNET_SYSERR; | ||
198 | } | ||
199 | |||
200 | *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket; | ||
201 | return GNUNET_OK; | ||
202 | } | ||
203 | |||
204 | /** | ||
205 | * Cleanup data left from parsing RSA public key. | ||
206 | * | ||
207 | * @param cls closure, NULL | ||
208 | * @param[out] spec where to free the data | ||
209 | */ | ||
210 | static void | ||
211 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) | ||
212 | { | ||
213 | struct GNUNET_RECLAIM_Ticket **ticket; | ||
214 | ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr; | ||
215 | if (NULL != *ticket) | ||
216 | { | ||
217 | GNUNET_free(*ticket); | ||
218 | *ticket = NULL; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * JSON Specification for Reclaim tickets. | ||
224 | * | ||
225 | * @param ticket struct of GNUNET_RECLAIM_Ticket to fill | ||
226 | * @return JSON Specification | ||
227 | */ | ||
228 | struct GNUNET_JSON_Specification | ||
229 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) | ||
230 | { | ||
231 | struct GNUNET_JSON_Specification ret = { | ||
232 | .parser = &parse_ticket, | ||
233 | .cleaner = &clean_ticket, | ||
234 | .cls = NULL, | ||
235 | .field = NULL, | ||
236 | .ptr = ticket, | ||
237 | .ptr_size = 0, | ||
238 | .size_ptr = NULL | ||
239 | }; | ||
240 | *ticket = NULL; | ||
241 | return ret; | ||
242 | } | ||
diff --git a/src/rest-plugins/json_reclaim.h b/src/rest-plugins/json_reclaim.h new file mode 100644 index 000000000..49674a173 --- /dev/null +++ b/src/rest-plugins/json_reclaim.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009-2018 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | /** | ||
20 | * @file rest-plugins/json_reclaim.h | ||
21 | * @brief JSON handling of reclaim data | ||
22 | * @author Martin Schanzenbach | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | #include "gnunet_json_lib.h" | ||
27 | #include "gnunet_reclaim_service.h" | ||
28 | #include "gnunet_reclaim_attribute_lib.h" | ||
29 | |||
30 | /** | ||
31 | * JSON Specification for Reclaim claims. | ||
32 | * | ||
33 | * @param ticket struct of GNUNET_RECLAIM_ATTRIBUTE_Claim to fill | ||
34 | * @return JSON Specification | ||
35 | */ | ||
36 | struct GNUNET_JSON_Specification | ||
37 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr); | ||
38 | |||
39 | /** | ||
40 | * JSON Specification for Reclaim tickets. | ||
41 | * | ||
42 | * @param ticket struct of GNUNET_RECLAIM_Ticket to fill | ||
43 | * @return JSON Specification | ||
44 | */ | ||
45 | struct GNUNET_JSON_Specification | ||
46 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket); | ||
diff --git a/src/jsonapi/plugin_rest_reclaim.c b/src/rest-plugins/plugin_rest_reclaim.c index 38ffc4ddb..9115a9449 100644 --- a/src/jsonapi/plugin_rest_reclaim.c +++ b/src/rest-plugins/plugin_rest_reclaim.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "gnunet_signatures.h" | 38 | #include "gnunet_signatures.h" |
39 | #include "gnunet_reclaim_attribute_lib.h" | 39 | #include "gnunet_reclaim_attribute_lib.h" |
40 | #include "gnunet_reclaim_service.h" | 40 | #include "gnunet_reclaim_service.h" |
41 | #include "json_reclaim.h" | ||
41 | 42 | ||
42 | /** | 43 | /** |
43 | * REST root namespace | 44 | * REST root namespace |
@@ -65,22 +66,6 @@ | |||
65 | #define GNUNET_REST_API_NS_IDENTITY_CONSUME "/reclaim/consume" | 66 | #define GNUNET_REST_API_NS_IDENTITY_CONSUME "/reclaim/consume" |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * Attribute key | ||
69 | */ | ||
70 | #define GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE "attribute" | ||
71 | |||
72 | /** | ||
73 | * Ticket key | ||
74 | */ | ||
75 | #define GNUNET_REST_JSONAPI_IDENTITY_TICKET "ticket" | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Value key | ||
80 | */ | ||
81 | #define GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE_VALUE "value" | ||
82 | |||
83 | /** | ||
84 | * State while collecting all egos | 69 | * State while collecting all egos |
85 | */ | 70 | */ |
86 | #define ID_REST_STATE_INIT 0 | 71 | #define ID_REST_STATE_INIT 0 |
@@ -260,7 +245,7 @@ struct RequestHandle | |||
260 | /** | 245 | /** |
261 | * Response object | 246 | * Response object |
262 | */ | 247 | */ |
263 | struct GNUNET_JSONAPI_Document *resp_object; | 248 | json_t *resp_object; |
264 | 249 | ||
265 | }; | 250 | }; |
266 | 251 | ||
@@ -278,7 +263,7 @@ cleanup_handle (struct RequestHandle *handle) | |||
278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
279 | "Cleaning up\n"); | 264 | "Cleaning up\n"); |
280 | if (NULL != handle->resp_object) | 265 | if (NULL != handle->resp_object) |
281 | GNUNET_JSONAPI_document_delete (handle->resp_object); | 266 | json_decref (handle->resp_object); |
282 | if (NULL != handle->timeout_task) | 267 | if (NULL != handle->timeout_task) |
283 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 268 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
284 | if (NULL != handle->identity_handle) | 269 | if (NULL != handle->identity_handle) |
@@ -410,7 +395,7 @@ return_response (void *cls) | |||
410 | struct RequestHandle *handle = cls; | 395 | struct RequestHandle *handle = cls; |
411 | struct MHD_Response *resp; | 396 | struct MHD_Response *resp; |
412 | 397 | ||
413 | GNUNET_JSONAPI_document_serialize (handle->resp_object, &result_str); | 398 | result_str = json_dumps (handle->resp_object, 0); |
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
415 | resp = GNUNET_REST_create_response (result_str); | 400 | resp = GNUNET_REST_create_response (result_str); |
416 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 401 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
@@ -437,7 +422,7 @@ static void | |||
437 | ticket_collect (void *cls, | 422 | ticket_collect (void *cls, |
438 | const struct GNUNET_RECLAIM_Ticket *ticket) | 423 | const struct GNUNET_RECLAIM_Ticket *ticket) |
439 | { | 424 | { |
440 | struct GNUNET_JSONAPI_Resource *json_resource; | 425 | json_t *json_resource; |
441 | struct RequestHandle *handle = cls; | 426 | struct RequestHandle *handle = cls; |
442 | json_t *value; | 427 | json_t *value; |
443 | char* tmp; | 428 | char* tmp; |
@@ -445,33 +430,33 @@ ticket_collect (void *cls, | |||
445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n"); | 430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n"); |
446 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, | 431 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, |
447 | sizeof (uint64_t)); | 432 | sizeof (uint64_t)); |
448 | json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_TICKET, | 433 | json_resource = json_object (); |
449 | tmp); | ||
450 | GNUNET_free (tmp); | 434 | GNUNET_free (tmp); |
451 | GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource); | 435 | json_array_append (handle->resp_object, |
436 | json_resource); | ||
452 | 437 | ||
453 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, | 438 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, |
454 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 439 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
455 | value = json_string (tmp); | 440 | value = json_string (tmp); |
456 | GNUNET_JSONAPI_resource_add_attr (json_resource, | 441 | json_object_set_new (json_resource, |
457 | "issuer", | 442 | "issuer", |
458 | value); | 443 | value); |
459 | GNUNET_free (tmp); | 444 | GNUNET_free (tmp); |
460 | json_decref (value); | 445 | json_decref (value); |
461 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, | 446 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, |
462 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 447 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
463 | value = json_string (tmp); | 448 | value = json_string (tmp); |
464 | GNUNET_JSONAPI_resource_add_attr (json_resource, | 449 | json_object_set_new (json_resource, |
465 | "audience", | 450 | "audience", |
466 | value); | 451 | value); |
467 | GNUNET_free (tmp); | 452 | GNUNET_free (tmp); |
468 | json_decref (value); | 453 | json_decref (value); |
469 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, | 454 | tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, |
470 | sizeof (uint64_t)); | 455 | sizeof (uint64_t)); |
471 | value = json_string (tmp); | 456 | value = json_string (tmp); |
472 | GNUNET_JSONAPI_resource_add_attr (json_resource, | 457 | json_object_set_new (json_resource, |
473 | "rnd", | 458 | "rnd", |
474 | value); | 459 | value); |
475 | GNUNET_free (tmp); | 460 | GNUNET_free (tmp); |
476 | json_decref (value); | 461 | json_decref (value); |
477 | GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it); | 462 | GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it); |
@@ -512,7 +497,7 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
512 | ego_entry = ego_entry->next) | 497 | ego_entry = ego_entry->next) |
513 | if (0 == strcmp (identity, ego_entry->identifier)) | 498 | if (0 == strcmp (identity, ego_entry->identifier)) |
514 | break; | 499 | break; |
515 | handle->resp_object = GNUNET_JSONAPI_document_new (); | 500 | handle->resp_object = json_array (); |
516 | 501 | ||
517 | if (NULL == ego_entry) | 502 | if (NULL == ego_entry) |
518 | { | 503 | { |
@@ -525,13 +510,13 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
525 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 510 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
526 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 511 | handle->idp = GNUNET_RECLAIM_connect (cfg); |
527 | handle->ticket_it = GNUNET_RECLAIM_ticket_iteration_start (handle->idp, | 512 | handle->ticket_it = GNUNET_RECLAIM_ticket_iteration_start (handle->idp, |
528 | priv_key, | 513 | priv_key, |
529 | &collect_error_cb, | 514 | &collect_error_cb, |
530 | handle, | 515 | handle, |
531 | &ticket_collect, | 516 | &ticket_collect, |
532 | handle, | 517 | handle, |
533 | &collect_finished_cb, | 518 | &collect_finished_cb, |
534 | handle); | 519 | handle); |
535 | } | 520 | } |
536 | 521 | ||
537 | 522 | ||
@@ -542,24 +527,15 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
542 | { | 527 | { |
543 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 528 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
544 | const char* identity; | 529 | const char* identity; |
545 | const char* name_str; | ||
546 | const char* value_str; | ||
547 | const char* exp_str; | ||
548 | |||
549 | struct RequestHandle *handle = cls; | 530 | struct RequestHandle *handle = cls; |
550 | struct EgoEntry *ego_entry; | 531 | struct EgoEntry *ego_entry; |
551 | struct MHD_Response *resp; | ||
552 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attribute; | 532 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attribute; |
553 | struct GNUNET_JSONAPI_Document *json_obj; | ||
554 | struct GNUNET_JSONAPI_Resource *json_res; | ||
555 | struct GNUNET_TIME_Relative exp; | 533 | struct GNUNET_TIME_Relative exp; |
556 | char term_data[handle->rest_handle->data_size+1]; | 534 | char term_data[handle->rest_handle->data_size+1]; |
557 | json_t *value_json; | ||
558 | json_t *data_json; | 535 | json_t *data_json; |
559 | json_t *exp_json; | ||
560 | json_error_t err; | 536 | json_error_t err; |
561 | struct GNUNET_JSON_Specification docspec[] = { | 537 | struct GNUNET_JSON_Specification attrspec[] = { |
562 | GNUNET_JSON_spec_jsonapi_document (&json_obj), | 538 | GNUNET_RECLAIM_JSON_spec_claim (&attribute), |
563 | GNUNET_JSON_spec_end() | 539 | GNUNET_JSON_spec_end() |
564 | }; | 540 | }; |
565 | 541 | ||
@@ -584,7 +560,6 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
584 | { | 560 | { |
585 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 561 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
586 | "Identity unknown (%s)\n", identity); | 562 | "Identity unknown (%s)\n", identity); |
587 | GNUNET_JSONAPI_document_delete (json_obj); | ||
588 | return; | 563 | return; |
589 | } | 564 | } |
590 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 565 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
@@ -603,67 +578,25 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
603 | JSON_DECODE_ANY, | 578 | JSON_DECODE_ANY, |
604 | &err); | 579 | &err); |
605 | GNUNET_assert (GNUNET_OK == | 580 | GNUNET_assert (GNUNET_OK == |
606 | GNUNET_JSON_parse (data_json, docspec, | 581 | GNUNET_JSON_parse (data_json, attrspec, |
607 | NULL, NULL)); | 582 | NULL, NULL)); |
608 | json_decref (data_json); | 583 | json_decref (data_json); |
609 | if (NULL == json_obj) | 584 | if (NULL == attribute) |
610 | { | 585 | { |
611 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 586 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
612 | "Unable to parse JSONAPI Object from %s\n", | 587 | "Unable to parse attribute from %s\n", |
613 | term_data); | 588 | term_data); |
614 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 589 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
615 | return; | 590 | return; |
616 | } | 591 | } |
617 | if (1 != GNUNET_JSONAPI_document_resource_count (json_obj)) | ||
618 | { | ||
619 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
620 | "Cannot create more than 1 resource! (Got %d)\n", | ||
621 | GNUNET_JSONAPI_document_resource_count (json_obj)); | ||
622 | GNUNET_JSONAPI_document_delete (json_obj); | ||
623 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
624 | return; | ||
625 | } | ||
626 | json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); | ||
627 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, | ||
628 | GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE)) | ||
629 | { | ||
630 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
631 | "Unsupported JSON data type\n"); | ||
632 | GNUNET_JSONAPI_document_delete (json_obj); | ||
633 | resp = GNUNET_REST_create_response (NULL); | ||
634 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | ||
635 | cleanup_handle (handle); | ||
636 | return; | ||
637 | } | ||
638 | name_str = GNUNET_JSONAPI_resource_get_id (json_res); | ||
639 | exp_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
640 | "exp"); | ||
641 | exp_str = json_string_value (exp_json); | ||
642 | if (NULL == exp_str) { | ||
643 | exp = GNUNET_TIME_UNIT_HOURS; | ||
644 | } else { | ||
645 | if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (exp_str, | ||
646 | &exp)) { | ||
647 | exp = GNUNET_TIME_UNIT_HOURS; | ||
648 | } | ||
649 | } | ||
650 | |||
651 | value_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
652 | "value"); | ||
653 | value_str = json_string_value (value_json); | ||
654 | attribute = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, | ||
655 | GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, | ||
656 | value_str, | ||
657 | strlen (value_str) + 1); | ||
658 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 592 | handle->idp = GNUNET_RECLAIM_connect (cfg); |
659 | handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, | 593 | handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, |
660 | identity_priv, | 594 | identity_priv, |
661 | attribute, | 595 | attribute, |
662 | &exp, | 596 | &exp, |
663 | &finished_cont, | 597 | &finished_cont, |
664 | handle); | 598 | handle); |
665 | GNUNET_free (attribute); | 599 | GNUNET_JSON_parse_free (attrspec); |
666 | GNUNET_JSONAPI_document_delete (json_obj); | ||
667 | } | 600 | } |
668 | 601 | ||
669 | 602 | ||
@@ -677,11 +610,10 @@ attr_collect (void *cls, | |||
677 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 610 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
678 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 611 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
679 | { | 612 | { |
680 | struct GNUNET_JSONAPI_Resource *json_resource; | ||
681 | struct RequestHandle *handle = cls; | 613 | struct RequestHandle *handle = cls; |
682 | json_t *value; | 614 | json_t *value; |
683 | char* tmp_value; | 615 | char* tmp_value; |
684 | 616 | ||
685 | if ((NULL == attr->name) || (NULL == attr->data)) | 617 | if ((NULL == attr->name) || (NULL == attr->data)) |
686 | { | 618 | { |
687 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 619 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); |
@@ -690,19 +622,16 @@ attr_collect (void *cls, | |||
690 | 622 | ||
691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", | 623 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", |
692 | attr->name); | 624 | attr->name); |
693 | json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE, | ||
694 | attr->name); | ||
695 | GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource); | ||
696 | 625 | ||
697 | tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, | 626 | tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, |
698 | attr->data, | 627 | attr->data, |
699 | attr->data_size); | 628 | attr->data_size); |
700 | 629 | ||
701 | value = json_string (tmp_value); | 630 | value = json_string (tmp_value); |
702 | 631 | ||
703 | GNUNET_JSONAPI_resource_add_attr (json_resource, | 632 | json_object_set_new (handle->resp_object, |
704 | "value", | 633 | attr->name, |
705 | value); | 634 | value); |
706 | json_decref (value); | 635 | json_decref (value); |
707 | GNUNET_free(tmp_value); | 636 | GNUNET_free(tmp_value); |
708 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 637 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); |
@@ -743,7 +672,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
743 | ego_entry = ego_entry->next) | 672 | ego_entry = ego_entry->next) |
744 | if (0 == strcmp (identity, ego_entry->identifier)) | 673 | if (0 == strcmp (identity, ego_entry->identifier)) |
745 | break; | 674 | break; |
746 | handle->resp_object = GNUNET_JSONAPI_document_new (); | 675 | handle->resp_object = json_object (); |
747 | 676 | ||
748 | 677 | ||
749 | if (NULL == ego_entry) | 678 | if (NULL == ego_entry) |
@@ -757,13 +686,13 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
757 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 686 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
758 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 687 | handle->idp = GNUNET_RECLAIM_connect (cfg); |
759 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, | 688 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, |
760 | priv_key, | 689 | priv_key, |
761 | &collect_error_cb, | 690 | &collect_error_cb, |
762 | handle, | 691 | handle, |
763 | &attr_collect, | 692 | &attr_collect, |
764 | handle, | 693 | handle, |
765 | &collect_finished_cb, | 694 | &collect_finished_cb, |
766 | handle); | 695 | handle); |
767 | } | 696 | } |
768 | 697 | ||
769 | 698 | ||
@@ -773,25 +702,15 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
773 | void *cls) | 702 | void *cls) |
774 | { | 703 | { |
775 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 704 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
776 | const char* identity_str; | ||
777 | const char* audience_str; | ||
778 | const char* rnd_str; | ||
779 | |||
780 | struct RequestHandle *handle = cls; | 705 | struct RequestHandle *handle = cls; |
781 | struct EgoEntry *ego_entry; | 706 | struct EgoEntry *ego_entry; |
782 | struct MHD_Response *resp; | 707 | struct GNUNET_RECLAIM_Ticket *ticket; |
783 | struct GNUNET_RECLAIM_Ticket ticket; | ||
784 | struct GNUNET_JSONAPI_Document *json_obj; | ||
785 | struct GNUNET_JSONAPI_Resource *json_res; | ||
786 | struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; | 708 | struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; |
787 | char term_data[handle->rest_handle->data_size+1]; | 709 | char term_data[handle->rest_handle->data_size+1]; |
788 | json_t *rnd_json; | ||
789 | json_t *identity_json; | ||
790 | json_t *audience_json; | ||
791 | json_t *data_json; | 710 | json_t *data_json; |
792 | json_error_t err; | 711 | json_error_t err; |
793 | struct GNUNET_JSON_Specification docspec[] = { | 712 | struct GNUNET_JSON_Specification tktspec[] = { |
794 | GNUNET_JSON_spec_jsonapi_document (&json_obj), | 713 | GNUNET_RECLAIM_JSON_spec_ticket (&ticket), |
795 | GNUNET_JSON_spec_end() | 714 | GNUNET_JSON_spec_end() |
796 | }; | 715 | }; |
797 | 716 | ||
@@ -809,60 +728,27 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
809 | JSON_DECODE_ANY, | 728 | JSON_DECODE_ANY, |
810 | &err); | 729 | &err); |
811 | GNUNET_assert (GNUNET_OK == | 730 | GNUNET_assert (GNUNET_OK == |
812 | GNUNET_JSON_parse (data_json, docspec, | 731 | GNUNET_JSON_parse (data_json, tktspec, |
813 | NULL, NULL)); | 732 | NULL, NULL)); |
814 | json_decref (data_json); | 733 | json_decref (data_json); |
815 | if (NULL == json_obj) | 734 | if (NULL == ticket) |
816 | { | 735 | { |
817 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 736 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
818 | "Unable to parse JSONAPI Object from %s\n", | 737 | "Unable to parse ticket from %s\n", |
819 | term_data); | 738 | term_data); |
820 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 739 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
821 | return; | 740 | return; |
822 | } | 741 | } |
823 | if (1 != GNUNET_JSONAPI_document_resource_count (json_obj)) | 742 | if (GNUNET_OK != GNUNET_JSON_parse (data_json, |
743 | tktspec, | ||
744 | NULL, NULL)) | ||
824 | { | 745 | { |
825 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 746 | handle->emsg = GNUNET_strdup ("Not a ticket!\n"); |
826 | "Cannot create more than 1 resource! (Got %d)\n", | ||
827 | GNUNET_JSONAPI_document_resource_count (json_obj)); | ||
828 | GNUNET_JSONAPI_document_delete (json_obj); | ||
829 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 747 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
748 | GNUNET_JSON_parse_free (tktspec); | ||
749 | json_decref (data_json); | ||
830 | return; | 750 | return; |
831 | } | 751 | } |
832 | json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); | ||
833 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, | ||
834 | GNUNET_REST_JSONAPI_IDENTITY_TICKET)) | ||
835 | { | ||
836 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
837 | "Unsupported JSON data type\n"); | ||
838 | GNUNET_JSONAPI_document_delete (json_obj); | ||
839 | resp = GNUNET_REST_create_response (NULL); | ||
840 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | ||
841 | cleanup_handle (handle); | ||
842 | return; | ||
843 | } | ||
844 | rnd_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
845 | "rnd"); | ||
846 | identity_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
847 | "issuer"); | ||
848 | audience_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
849 | "audience"); | ||
850 | rnd_str = json_string_value (rnd_json); | ||
851 | identity_str = json_string_value (identity_json); | ||
852 | audience_str = json_string_value (audience_json); | ||
853 | |||
854 | GNUNET_STRINGS_string_to_data (rnd_str, | ||
855 | strlen (rnd_str), | ||
856 | &ticket.rnd, | ||
857 | sizeof (uint64_t)); | ||
858 | GNUNET_STRINGS_string_to_data (identity_str, | ||
859 | strlen (identity_str), | ||
860 | &ticket.identity, | ||
861 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
862 | GNUNET_STRINGS_string_to_data (audience_str, | ||
863 | strlen (audience_str), | ||
864 | &ticket.audience, | ||
865 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
866 | 752 | ||
867 | for (ego_entry = handle->ego_head; | 753 | for (ego_entry = handle->ego_head; |
868 | NULL != ego_entry; | 754 | NULL != ego_entry; |
@@ -870,7 +756,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
870 | { | 756 | { |
871 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, | 757 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, |
872 | &tmp_pk); | 758 | &tmp_pk); |
873 | if (0 == memcmp (&ticket.identity, | 759 | if (0 == memcmp (&ticket->identity, |
874 | &tmp_pk, | 760 | &tmp_pk, |
875 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 761 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
876 | break; | 762 | break; |
@@ -878,19 +764,19 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
878 | if (NULL == ego_entry) | 764 | if (NULL == ego_entry) |
879 | { | 765 | { |
880 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 766 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
881 | "Identity unknown (%s)\n", identity_str); | 767 | "Identity unknown\n"); |
882 | GNUNET_JSONAPI_document_delete (json_obj); | 768 | GNUNET_JSON_parse_free (tktspec); |
883 | return; | 769 | return; |
884 | } | 770 | } |
885 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 771 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
886 | 772 | ||
887 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 773 | handle->idp = GNUNET_RECLAIM_connect (cfg); |
888 | handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp, | 774 | handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp, |
889 | identity_priv, | 775 | identity_priv, |
890 | &ticket, | 776 | ticket, |
891 | &finished_cont, | 777 | &finished_cont, |
892 | handle); | 778 | handle); |
893 | GNUNET_JSONAPI_document_delete (json_obj); | 779 | GNUNET_JSON_parse_free (tktspec); |
894 | } | 780 | } |
895 | 781 | ||
896 | static void | 782 | static void |
@@ -899,7 +785,7 @@ consume_cont (void *cls, | |||
899 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 785 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
900 | { | 786 | { |
901 | struct RequestHandle *handle = cls; | 787 | struct RequestHandle *handle = cls; |
902 | struct GNUNET_JSONAPI_Resource *json_resource; | 788 | char *val_str; |
903 | json_t *value; | 789 | json_t *value; |
904 | 790 | ||
905 | if (NULL == identity) | 791 | if (NULL == identity) |
@@ -910,15 +796,21 @@ consume_cont (void *cls, | |||
910 | 796 | ||
911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", | 797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", |
912 | attr->name); | 798 | attr->name); |
913 | json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE, | 799 | val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, |
914 | attr->name); | 800 | attr->data, |
915 | GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource); | 801 | attr->data_size); |
916 | 802 | if (NULL == val_str) | |
917 | value = json_string (attr->data); | 803 | { |
918 | GNUNET_JSONAPI_resource_add_attr (json_resource, | 804 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse value for: %s\n", |
919 | "value", | 805 | attr->name); |
920 | value); | 806 | return; |
807 | } | ||
808 | value = json_string(val_str); | ||
809 | json_object_set_new (handle->resp_object, | ||
810 | attr->name, | ||
811 | value); | ||
921 | json_decref (value); | 812 | json_decref (value); |
813 | GNUNET_free (val_str); | ||
922 | } | 814 | } |
923 | 815 | ||
924 | static void | 816 | static void |
@@ -927,26 +819,16 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
927 | void *cls) | 819 | void *cls) |
928 | { | 820 | { |
929 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 821 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
930 | const char* identity_str; | ||
931 | const char* audience_str; | ||
932 | const char* rnd_str; | ||
933 | |||
934 | struct RequestHandle *handle = cls; | 822 | struct RequestHandle *handle = cls; |
935 | struct EgoEntry *ego_entry; | 823 | struct EgoEntry *ego_entry; |
936 | struct MHD_Response *resp; | 824 | struct GNUNET_RECLAIM_Ticket *ticket; |
937 | struct GNUNET_RECLAIM_Ticket ticket; | ||
938 | struct GNUNET_JSONAPI_Document *json_obj; | ||
939 | struct GNUNET_JSONAPI_Resource *json_res; | ||
940 | struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; | 825 | struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; |
941 | char term_data[handle->rest_handle->data_size+1]; | 826 | char term_data[handle->rest_handle->data_size+1]; |
942 | json_t *rnd_json; | ||
943 | json_t *identity_json; | ||
944 | json_t *audience_json; | ||
945 | json_t *data_json; | 827 | json_t *data_json; |
946 | json_error_t err; | 828 | json_error_t err; |
947 | struct GNUNET_JSON_Specification docspec[] = { | 829 | struct GNUNET_JSON_Specification tktspec[] = { |
948 | GNUNET_JSON_spec_jsonapi_document (&json_obj), | 830 | GNUNET_RECLAIM_JSON_spec_ticket (&ticket), |
949 | GNUNET_JSON_spec_end() | 831 | GNUNET_JSON_spec_end () |
950 | }; | 832 | }; |
951 | 833 | ||
952 | if (0 >= handle->rest_handle->data_size) | 834 | if (0 >= handle->rest_handle->data_size) |
@@ -962,69 +844,31 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
962 | data_json = json_loads (term_data, | 844 | data_json = json_loads (term_data, |
963 | JSON_DECODE_ANY, | 845 | JSON_DECODE_ANY, |
964 | &err); | 846 | &err); |
965 | GNUNET_assert (GNUNET_OK == | 847 | if (NULL == data_json) |
966 | GNUNET_JSON_parse (data_json, docspec, | ||
967 | NULL, NULL)); | ||
968 | json_decref (data_json); | ||
969 | if (NULL == json_obj) | ||
970 | { | 848 | { |
971 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 849 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
972 | "Unable to parse JSONAPI Object from %s\n", | 850 | "Unable to parse JSON Object from %s\n", |
973 | term_data); | 851 | term_data); |
974 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 852 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
975 | return; | 853 | return; |
976 | } | 854 | } |
977 | if (1 != GNUNET_JSONAPI_document_resource_count (json_obj)) | 855 | if (GNUNET_OK != GNUNET_JSON_parse (data_json, |
856 | tktspec, | ||
857 | NULL, NULL)) | ||
978 | { | 858 | { |
979 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 859 | handle->emsg = GNUNET_strdup ("Not a ticket!\n"); |
980 | "Cannot create more than 1 resource! (Got %d)\n", | ||
981 | GNUNET_JSONAPI_document_resource_count (json_obj)); | ||
982 | GNUNET_JSONAPI_document_delete (json_obj); | ||
983 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 860 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
861 | GNUNET_JSON_parse_free(tktspec); | ||
862 | json_decref (data_json); | ||
984 | return; | 863 | return; |
985 | } | 864 | } |
986 | json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); | ||
987 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, | ||
988 | GNUNET_REST_JSONAPI_IDENTITY_TICKET)) | ||
989 | { | ||
990 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
991 | "Unsupported JSON data type\n"); | ||
992 | GNUNET_JSONAPI_document_delete (json_obj); | ||
993 | resp = GNUNET_REST_create_response (NULL); | ||
994 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | ||
995 | cleanup_handle (handle); | ||
996 | return; | ||
997 | } | ||
998 | rnd_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
999 | "rnd"); | ||
1000 | identity_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
1001 | "identity"); | ||
1002 | audience_json = GNUNET_JSONAPI_resource_read_attr (json_res, | ||
1003 | "audience"); | ||
1004 | rnd_str = json_string_value (rnd_json); | ||
1005 | identity_str = json_string_value (identity_json); | ||
1006 | audience_str = json_string_value (audience_json); | ||
1007 | |||
1008 | GNUNET_STRINGS_string_to_data (rnd_str, | ||
1009 | strlen (rnd_str), | ||
1010 | &ticket.rnd, | ||
1011 | sizeof (uint64_t)); | ||
1012 | GNUNET_STRINGS_string_to_data (identity_str, | ||
1013 | strlen (identity_str), | ||
1014 | &ticket.identity, | ||
1015 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
1016 | GNUNET_STRINGS_string_to_data (audience_str, | ||
1017 | strlen (audience_str), | ||
1018 | &ticket.audience, | ||
1019 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
1020 | |||
1021 | for (ego_entry = handle->ego_head; | 865 | for (ego_entry = handle->ego_head; |
1022 | NULL != ego_entry; | 866 | NULL != ego_entry; |
1023 | ego_entry = ego_entry->next) | 867 | ego_entry = ego_entry->next) |
1024 | { | 868 | { |
1025 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, | 869 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, |
1026 | &tmp_pk); | 870 | &tmp_pk); |
1027 | if (0 == memcmp (&ticket.audience, | 871 | if (0 == memcmp (&ticket->audience, |
1028 | &tmp_pk, | 872 | &tmp_pk, |
1029 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 873 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
1030 | break; | 874 | break; |
@@ -1032,19 +876,19 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1032 | if (NULL == ego_entry) | 876 | if (NULL == ego_entry) |
1033 | { | 877 | { |
1034 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 878 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1035 | "Identity unknown (%s)\n", identity_str); | 879 | "Identity unknown\n"); |
1036 | GNUNET_JSONAPI_document_delete (json_obj); | 880 | GNUNET_JSON_parse_free (tktspec); |
1037 | return; | 881 | return; |
1038 | } | 882 | } |
1039 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 883 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
1040 | handle->resp_object = GNUNET_JSONAPI_document_new (); | 884 | handle->resp_object = json_object (); |
1041 | handle->idp = GNUNET_RECLAIM_connect (cfg); | 885 | handle->idp = GNUNET_RECLAIM_connect (cfg); |
1042 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, | 886 | handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, |
1043 | identity_priv, | 887 | identity_priv, |
1044 | &ticket, | 888 | ticket, |
1045 | &consume_cont, | 889 | &consume_cont, |
1046 | handle); | 890 | handle); |
1047 | GNUNET_JSONAPI_document_delete (json_obj); | 891 | GNUNET_JSON_parse_free (tktspec); |
1048 | } | 892 | } |
1049 | 893 | ||
1050 | 894 | ||