aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-10-15 15:49:38 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-10-15 15:49:38 +0200
commitcd1c45b00ae4ba98ad3b365c2db67d82bdc0843d (patch)
tree17346ca2852fd38b63484dc817720080002b6195
parent17e43503b9e8c88e24e66d1f6a8ffcf543361c27 (diff)
downloadgnunet-cd1c45b00ae4ba98ad3b365c2db67d82bdc0843d.tar.gz
gnunet-cd1c45b00ae4ba98ad3b365c2db67d82bdc0843d.zip
- more dep fixes
-rw-r--r--po/POTFILES.in2
-rw-r--r--src/gns/Makefile.am1
-rw-r--r--src/gns/plugin_rest_gns.c3
-rw-r--r--src/gnsrecord/Makefile.am14
-rw-r--r--src/gnsrecord/json_gnsrecord.c (renamed from src/json/json_gnsrecord.c)114
-rw-r--r--src/include/gnunet_json_lib.h25
-rw-r--r--src/json/Makefile.am7
-rw-r--r--src/json/json_generator.c108
-rw-r--r--src/namestore/Makefile.am1
-rw-r--r--src/namestore/plugin_rest_namestore.c16
10 files changed, 141 insertions, 150 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5c379eed8..6aab56d14 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -185,6 +185,7 @@ src/gnsrecord/gnsrecord_crypto.c
185src/gnsrecord/gnsrecord_misc.c 185src/gnsrecord/gnsrecord_misc.c
186src/gnsrecord/gnsrecord_serialization.c 186src/gnsrecord/gnsrecord_serialization.c
187src/gnsrecord/gnunet-gnsrecord-tvg.c 187src/gnsrecord/gnunet-gnsrecord-tvg.c
188src/gnsrecord/json_gnsrecord.c
188src/gnsrecord/plugin_gnsrecord_dns.c 189src/gnsrecord/plugin_gnsrecord_dns.c
189src/hello/address.c 190src/hello/address.c
190src/hello/gnunet-hello.c 191src/hello/gnunet-hello.c
@@ -201,7 +202,6 @@ src/identity/identity_api_suffix_lookup.c
201src/identity/plugin_rest_identity.c 202src/identity/plugin_rest_identity.c
202src/json/json.c 203src/json/json.c
203src/json/json_generator.c 204src/json/json_generator.c
204src/json/json_gnsrecord.c
205src/json/json_helper.c 205src/json/json_helper.c
206src/json/json_mhd.c 206src/json/json_mhd.c
207src/my/my.c 207src/my/my.c
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 5a9c70997..47941b8ef 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -109,6 +109,7 @@ libgnunet_plugin_rest_gns_la_SOURCES = \
109 plugin_rest_gns.c 109 plugin_rest_gns.c
110libgnunet_plugin_rest_gns_la_LIBADD = \ 110libgnunet_plugin_rest_gns_la_LIBADD = \
111 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 111 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
112 $(top_builddir)/src/gnsrecord/libgnunetgnsrecordjson.la \
112 libgnunetgns.la \ 113 libgnunetgns.la \
113 $(top_builddir)/src/rest/libgnunetrest.la \ 114 $(top_builddir)/src/rest/libgnunetrest.la \
114 $(top_builddir)/src/identity/libgnunetidentity.la \ 115 $(top_builddir)/src/identity/libgnunetidentity.la \
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 6ec921f70..2ccb5be2b 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -28,6 +28,7 @@
28#include "gnunet_rest_lib.h" 28#include "gnunet_rest_lib.h"
29#include "gnunet_json_lib.h" 29#include "gnunet_json_lib.h"
30#include "gnunet_gnsrecord_lib.h" 30#include "gnunet_gnsrecord_lib.h"
31#include "gnunet_gnsrecord_json_lib.h"
31#include "gnunet_gns_service.h" 32#include "gnunet_gns_service.h"
32#include "microhttpd.h" 33#include "microhttpd.h"
33#include <jansson.h> 34#include <jansson.h>
@@ -264,7 +265,7 @@ handle_gns_response (void *cls,
264 return; 265 return;
265 } 266 }
266 267
267 result_obj = GNUNET_JSON_from_gnsrecord (handle->name, rd, rd_count); 268 result_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (handle->name, rd, rd_count);
268 269
269 result = json_dumps (result_obj, 0); 270 result = json_dumps (result_obj, 0);
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); 271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 02a50973b..36be13c8d 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -30,7 +30,8 @@ TESTS = \
30endif 30endif
31 31
32lib_LTLIBRARIES = \ 32lib_LTLIBRARIES = \
33 libgnunetgnsrecord.la 33 libgnunetgnsrecord.la \
34 libgnunetgnsrecordjson.la
34 35
35gnunet_gnsrecord_tvg_SOURCES = \ 36gnunet_gnsrecord_tvg_SOURCES = \
36 gnunet-gnsrecord-tvg.c 37 gnunet-gnsrecord-tvg.c
@@ -56,6 +57,17 @@ libgnunetgnsrecord_la_LDFLAGS = \
56 $(GN_LIB_LDFLAGS) \ 57 $(GN_LIB_LDFLAGS) \
57 -version-info 0:0:0 58 -version-info 0:0:0
58 59
60libgnunetgnsrecordjson_la_SOURCES = \
61 json_gnsrecord.c
62libgnunetgnsrecordjson_la_LIBADD = \
63 $(top_builddir)/src/util/libgnunetutil.la \
64 $(top_builddir)/src/identity/libgnunetidentity.la \
65 libgnunetgnsrecord.la \
66 -ljansson \
67 $(GN_LIBINTL)
68libgnunetgnsrecordjson_la_LDFLAGS = \
69 $(GN_LIB_LDFLAGS) \
70 -version-info 0:0:0
59 71
60plugin_LTLIBRARIES = \ 72plugin_LTLIBRARIES = \
61 libgnunet_plugin_gnsrecord_dns.la 73 libgnunet_plugin_gnsrecord_dns.la
diff --git a/src/json/json_gnsrecord.c b/src/gnsrecord/json_gnsrecord.c
index 7e11aba94..068ff48c1 100644
--- a/src/json/json_gnsrecord.c
+++ b/src/gnsrecord/json_gnsrecord.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_json_lib.h" 28#include "gnunet_json_lib.h"
29#include "gnunet_gnsrecord_lib.h"
29 30
30#define GNUNET_JSON_GNSRECORD_VALUE "value" 31#define GNUNET_JSON_GNSRECORD_VALUE "value"
31#define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" 32#define GNUNET_JSON_GNSRECORD_RECORD_DATA "data"
@@ -258,7 +259,7 @@ clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec)
258 * @return JSON Specification 259 * @return JSON Specification
259 */ 260 */
260struct GNUNET_JSON_Specification 261struct GNUNET_JSON_Specification
261GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, 262GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
262 unsigned int *rd_count, 263 unsigned int *rd_count,
263 char **name) 264 char **name)
264{ 265{
@@ -277,3 +278,114 @@ GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
277 .size_ptr = NULL }; 278 .size_ptr = NULL };
278 return ret; 279 return ret;
279} 280}
281
282
283/**
284 * Convert GNS record to JSON.
285 *
286 * @param rname name of record
287 * @param rd record data
288 * @return corresponding JSON encoding
289 */
290json_t *
291GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
292 const struct GNUNET_GNSRECORD_Data *rd,
293 unsigned int rd_count)
294{
295 struct GNUNET_TIME_Absolute abs_exp;
296 struct GNUNET_TIME_Relative rel_exp;
297 const char *expiration_time_str;
298 const char *record_type_str;
299 char *value_str;
300 json_t *data;
301 json_t *record;
302 json_t *records;
303
304 data = json_object ();
305 if (NULL == data)
306 {
307 GNUNET_break (0);
308 return NULL;
309 }
310 if (0 !=
311 json_object_set_new (data,
312 "record_name",
313 json_string (rname)))
314 {
315 GNUNET_break (0);
316 json_decref (data);
317 return NULL;
318 }
319 records = json_array ();
320 if (NULL == records)
321 {
322 GNUNET_break (0);
323 json_decref (data);
324 return NULL;
325 }
326 for (int i = 0; i < rd_count; i++)
327 {
328 value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
329 rd[i].data,
330 rd[i].data_size);
331 if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags)
332 {
333 rel_exp.rel_value_us = rd[i].expiration_time;
334 expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp,
335 GNUNET_NO);
336 }
337 else
338 {
339 abs_exp.abs_value_us = rd[i].expiration_time;
340 expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp);
341 }
342 record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 "Packing %s %s %s %d\n",
345 value_str, record_type_str, expiration_time_str, rd[i].flags);
346 record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}",
347 "value",
348 value_str,
349 "record_type",
350 record_type_str,
351 "expiration_time",
352 expiration_time_str,
353 "private",
354 rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
355 "relative_expiration",
356 rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION,
357 "supplemental",
358 rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL,
359 "shadow",
360 rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD);
361 GNUNET_free (value_str);
362 if (NULL == record)
363 {
364 GNUNET_break (0);
365 json_decref (records);
366 json_decref (data);
367 return NULL;
368 }
369 if (0 !=
370 json_array_append_new (records,
371 record))
372 {
373 GNUNET_break (0);
374 json_decref (records);
375 json_decref (data);
376 return NULL;
377 }
378 }
379 if (0 !=
380 json_object_set_new (data,
381 "data",
382 records))
383 {
384 GNUNET_break (0);
385 json_decref (data);
386 return NULL;
387 }
388 return data;
389}
390
391
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 07a14d329..92597d3dd 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -28,7 +28,6 @@
28#define GNUNET_JSON_LIB_H 28#define GNUNET_JSON_LIB_H
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_gnsrecord_lib.h"
32#include <jansson.h> 31#include <jansson.h>
33#include <microhttpd.h> 32#include <microhttpd.h>
34 33
@@ -359,18 +358,6 @@ GNUNET_JSON_spec_rsa_signature (const char *name,
359 struct GNUNET_CRYPTO_RsaSignature **sig); 358 struct GNUNET_CRYPTO_RsaSignature **sig);
360 359
361 360
362/**
363 * JSON Specification for GNS Records.
364 *
365 * @param gnsrecord_object struct of GNUNET_GNSRECORD_Data to fill
366 * @return JSON Specification
367 */
368struct GNUNET_JSON_Specification
369GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
370 unsigned int *rd_count,
371 char **name);
372
373
374/* ****************** Generic generator interface ******************* */ 361/* ****************** Generic generator interface ******************* */
375 362
376 363
@@ -446,18 +433,6 @@ GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk);
446json_t * 433json_t *
447GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); 434GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig);
448 435
449/**
450 * Convert Gns record to JSON.
451 *
452 * @param rname name of record
453 * @param rd record data
454 * @return corresponding JSON encoding
455 */
456json_t *
457GNUNET_JSON_from_gnsrecord (const char *rname,
458 const struct GNUNET_GNSRECORD_Data *rd,
459 unsigned int rd_count);
460
461/* ******************* Helpers for MHD upload handling ******************* */ 436/* ******************* Helpers for MHD upload handling ******************* */
462 437
463/** 438/**
diff --git a/src/json/Makefile.am b/src/json/Makefile.am
index 2ed05c35a..d4ea38adf 100644
--- a/src/json/Makefile.am
+++ b/src/json/Makefile.am
@@ -18,18 +18,15 @@ libgnunetjson_la_SOURCES = \
18 json.c \ 18 json.c \
19 json_mhd.c \ 19 json_mhd.c \
20 json_generator.c \ 20 json_generator.c \
21 json_helper.c \ 21 json_helper.c
22 json_gnsrecord.c
23libgnunetjson_la_LIBADD = \ 22libgnunetjson_la_LIBADD = \
24 $(top_builddir)/src/util/libgnunetutil.la \ 23 $(top_builddir)/src/util/libgnunetutil.la \
25 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
26 -ljansson \ 24 -ljansson \
27 $(MHD_LIBS) \ 25 $(MHD_LIBS) \
28 $(XLIB) \ 26 $(XLIB) \
29 $(Z_LIBS) 27 $(Z_LIBS)
30libgnunetjson_la_DEPENDENCIES = \ 28libgnunetjson_la_DEPENDENCIES = \
31 $(top_builddir)/src/util/libgnunetutil.la \ 29 $(top_builddir)/src/util/libgnunetutil.la
32 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la
33 30
34 31
35check_PROGRAMS = \ 32check_PROGRAMS = \
diff --git a/src/json/json_generator.c b/src/json/json_generator.c
index 3f82a5f17..5806eb174 100644
--- a/src/json/json_generator.c
+++ b/src/json/json_generator.c
@@ -201,113 +201,5 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
201} 201}
202 202
203 203
204/**
205 * Convert GNS record to JSON.
206 *
207 * @param rname name of record
208 * @param rd record data
209 * @return corresponding JSON encoding
210 */
211json_t *
212GNUNET_JSON_from_gnsrecord (const char*rname,
213 const struct GNUNET_GNSRECORD_Data *rd,
214 unsigned int rd_count)
215{
216 struct GNUNET_TIME_Absolute abs_exp;
217 struct GNUNET_TIME_Relative rel_exp;
218 const char *expiration_time_str;
219 const char *record_type_str;
220 char *value_str;
221 json_t *data;
222 json_t *record;
223 json_t *records;
224
225 data = json_object ();
226 if (NULL == data)
227 {
228 GNUNET_break (0);
229 return NULL;
230 }
231 if (0 !=
232 json_object_set_new (data,
233 "record_name",
234 json_string (rname)))
235 {
236 GNUNET_break (0);
237 json_decref (data);
238 return NULL;
239 }
240 records = json_array ();
241 if (NULL == records)
242 {
243 GNUNET_break (0);
244 json_decref (data);
245 return NULL;
246 }
247 for (int i = 0; i < rd_count; i++)
248 {
249 value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
250 rd[i].data,
251 rd[i].data_size);
252 if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags)
253 {
254 rel_exp.rel_value_us = rd[i].expiration_time;
255 expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp,
256 GNUNET_NO);
257 }
258 else
259 {
260 abs_exp.abs_value_us = rd[i].expiration_time;
261 expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp);
262 }
263 record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "Packing %s %s %s %d\n",
266 value_str, record_type_str, expiration_time_str, rd[i].flags);
267 record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}",
268 "value",
269 value_str,
270 "record_type",
271 record_type_str,
272 "expiration_time",
273 expiration_time_str,
274 "private",
275 rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
276 "relative_expiration",
277 rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION,
278 "supplemental",
279 rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL,
280 "shadow",
281 rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD);
282 GNUNET_free (value_str);
283 if (NULL == record)
284 {
285 GNUNET_break (0);
286 json_decref (records);
287 json_decref (data);
288 return NULL;
289 }
290 if (0 !=
291 json_array_append_new (records,
292 record))
293 {
294 GNUNET_break (0);
295 json_decref (records);
296 json_decref (data);
297 return NULL;
298 }
299 }
300 if (0 !=
301 json_object_set_new (data,
302 "data",
303 records))
304 {
305 GNUNET_break (0);
306 json_decref (data);
307 return NULL;
308 }
309 return data;
310}
311
312 204
313/* End of json/json_generator.c */ 205/* End of json/json_generator.c */
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 40ac64197..d057a0a99 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -131,6 +131,7 @@ libgnunet_plugin_rest_namestore_la_LIBADD = \
131 $(top_builddir)/src/identity/libgnunetidentity.la \ 131 $(top_builddir)/src/identity/libgnunetidentity.la \
132 $(top_builddir)/src/json/libgnunetjson.la \ 132 $(top_builddir)/src/json/libgnunetjson.la \
133 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 133 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
134 $(top_builddir)/src/gnsrecord/libgnunetgnsrecordjson.la \
134 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ 135 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
135 $(LTLIBINTL) -ljansson $(MHD_LIBS) 136 $(LTLIBINTL) -ljansson $(MHD_LIBS)
136libgnunet_plugin_rest_namestore_la_LDFLAGS = \ 137libgnunet_plugin_rest_namestore_la_LDFLAGS = \
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index f295951bc..edcbeb874 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -30,7 +30,7 @@
30#include "gnunet_namestore_service.h" 30#include "gnunet_namestore_service.h"
31#include "gnunet_identity_service.h" 31#include "gnunet_identity_service.h"
32#include "gnunet_rest_lib.h" 32#include "gnunet_rest_lib.h"
33#include "gnunet_json_lib.h" 33#include "gnunet_gnsrecord_json_lib.h"
34#include "microhttpd.h" 34#include "microhttpd.h"
35#include <jansson.h> 35#include <jansson.h>
36 36
@@ -535,9 +535,9 @@ namestore_list_iteration (void *cls,
535 /** Only add if not empty **/ 535 /** Only add if not empty **/
536 if (j > 0) 536 if (j > 0)
537 { 537 {
538 record_obj = GNUNET_JSON_from_gnsrecord (rname, 538 record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (rname,
539 rd_filtered, 539 rd_filtered,
540 j); 540 j);
541 json_array_append_new (handle->resp_object, record_obj); 541 json_array_append_new (handle->resp_object, record_obj);
542 } 542 }
543 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); 543 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
@@ -587,9 +587,9 @@ ns_get_lookup_cb (void *cls,
587 /** Only add if not empty **/ 587 /** Only add if not empty **/
588 if (j > 0) 588 if (j > 0)
589 { 589 {
590 record_obj = GNUNET_JSON_from_gnsrecord (label, 590 record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (label,
591 rd_filtered, 591 rd_filtered,
592 j); 592 j);
593 json_array_append_new (handle->resp_object, record_obj); 593 json_array_append_new (handle->resp_object, record_obj);
594 } 594 }
595 GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle); 595 GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle);
@@ -755,7 +755,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle,
755 handle->rest_handle->data_size); 755 handle->rest_handle->data_size);
756 data_js = json_loads (term_data, JSON_DECODE_ANY, &err); 756 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
757 struct GNUNET_JSON_Specification gnsspec[] = 757 struct GNUNET_JSON_Specification gnsspec[] =
758 { GNUNET_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count, 758 { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count,
759 &handle->record_name), 759 &handle->record_name),
760 GNUNET_JSON_spec_end () }; 760 GNUNET_JSON_spec_end () };
761 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) 761 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))