aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/namestore
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c1097
-rw-r--r--src/namestore/gnunet-namestore.c1779
-rw-r--r--src/namestore/gnunet-service-namestore.c1934
-rw-r--r--src/namestore/gnunet-zoneimport.c1801
-rw-r--r--src/namestore/namestore.h48
-rw-r--r--src/namestore/namestore_api.c841
-rw-r--r--src/namestore/namestore_api_monitor.c189
-rw-r--r--src/namestore/perf_namestore_api_zone_iteration.c386
-rw-r--r--src/namestore/plugin_namestore_flat.c828
-rw-r--r--src/namestore/plugin_namestore_postgres.c674
-rw-r--r--src/namestore/plugin_namestore_sqlite.c849
-rw-r--r--src/namestore/plugin_rest_namestore.c632
-rw-r--r--src/namestore/test_common.c68
-rw-r--r--src/namestore/test_namestore_api_lookup_nick.c367
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c230
-rw-r--r--src/namestore/test_namestore_api_lookup_public.c214
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow.c276
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow_filter.c375
-rw-r--r--src/namestore/test_namestore_api_monitoring.c390
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c444
-rw-r--r--src/namestore/test_namestore_api_remove.c204
-rw-r--r--src/namestore/test_namestore_api_remove_not_existing_record.c144
-rw-r--r--src/namestore/test_namestore_api_store.c132
-rw-r--r--src/namestore/test_namestore_api_store_update.c326
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c584
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_nick.c463
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c546
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_stop.c527
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c274
-rw-r--r--src/namestore/test_plugin_namestore.c176
30 files changed, 8381 insertions, 8417 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index 58e824ea6..3abf1ed21 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file gnunet-namestore-fcfsd.c 21 * @file gnunet-namestore-fcfsd.c
22 * @brief HTTP daemon that offers first-come-first-serve GNS domain registration 22 * @brief HTTP daemon that offers first-come-first-serve GNS domain registration
@@ -74,41 +74,38 @@
74/** 74/**
75 * Phases a request goes through. 75 * Phases a request goes through.
76 */ 76 */
77enum Phase 77enum Phase {
78 { 78 /**
79 /** 79 * Start phase (parsing POST, checking).
80 * Start phase (parsing POST, checking). 80 */
81 */ 81 RP_START = 0,
82 RP_START = 0, 82
83 83 /**
84 /** 84 * Lookup to see if the domain name is taken.
85 * Lookup to see if the domain name is taken. 85 */
86 */ 86 RP_LOOKUP,
87 RP_LOOKUP, 87
88 88 /**
89 /** 89 * Storing of the record.
90 * Storing of the record. 90 */
91 */ 91 RP_PUT,
92 RP_PUT, 92
93 93 /**
94 /** 94 * We're done with success.
95 * We're done with success. 95 */
96 */ 96 RP_SUCCESS,
97 RP_SUCCESS, 97
98 98 /**
99 /** 99 * Send failure message.
100 * Send failure message. 100 */
101 */ 101 RP_FAIL
102 RP_FAIL 102};
103 };
104 103
105 104
106/** 105/**
107 * Data kept per request. 106 * Data kept per request.
108 */ 107 */
109struct Request 108struct Request {
110{
111
112 /** 109 /**
113 * Associated session. 110 * Associated session.
114 */ 111 */
@@ -119,7 +116,7 @@ struct Request
119 * a POST request). 116 * a POST request).
120 */ 117 */
121 struct MHD_PostProcessor *pp; 118 struct MHD_PostProcessor *pp;
122 119
123 /** 120 /**
124 * MHD Connection 121 * MHD Connection
125 */ 122 */
@@ -161,14 +158,12 @@ struct Request
161 char public_key[128]; 158 char public_key[128];
162 159
163 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 160 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
164
165}; 161};
166 162
167/** 163/**
168 * Zoneinfo request 164 * Zoneinfo request
169 */ 165 */
170struct ZoneinfoRequest 166struct ZoneinfoRequest {
171{
172 /** 167 /**
173 * List iterator 168 * List iterator
174 */ 169 */
@@ -247,21 +242,21 @@ static char *zone;
247 * @param cls unused 242 * @param cls unused
248 */ 243 */
249static void 244static void
250do_httpd (void *cls); 245do_httpd(void *cls);
251 246
252 247
253/** 248/**
254 * Schedule task to run MHD server now. 249 * Schedule task to run MHD server now.
255 */ 250 */
256static void 251static void
257run_httpd_now () 252run_httpd_now()
258{ 253{
259 if (NULL != httpd_task) 254 if (NULL != httpd_task)
260 { 255 {
261 GNUNET_SCHEDULER_cancel (httpd_task); 256 GNUNET_SCHEDULER_cancel(httpd_task);
262 httpd_task = NULL; 257 httpd_task = NULL;
263 } 258 }
264 httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, NULL); 259 httpd_task = GNUNET_SCHEDULER_add_now(&do_httpd, NULL);
265} 260}
266 261
267 262
@@ -269,22 +264,22 @@ run_httpd_now ()
269 * Create fresh version of zone information. 264 * Create fresh version of zone information.
270 */ 265 */
271static void 266static void
272update_zoneinfo_page (void *cls); 267update_zoneinfo_page(void *cls);
268
273 269
274
275/** 270/**
276 * Function called on error in zone iteration. 271 * Function called on error in zone iteration.
277 */ 272 */
278static void 273static void
279zone_iteration_error (void *cls) 274zone_iteration_error(void *cls)
280{ 275{
281 struct ZoneinfoRequest *zr = cls; 276 struct ZoneinfoRequest *zr = cls;
282 277
283 zr->list_it = NULL; 278 zr->list_it = NULL;
284 GNUNET_free (zr->zoneinfo); 279 GNUNET_free(zr->zoneinfo);
285 GNUNET_SCHEDULER_cancel (uzp_task); 280 GNUNET_SCHEDULER_cancel(uzp_task);
286 uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, 281 uzp_task = GNUNET_SCHEDULER_add_now(&update_zoneinfo_page,
287 NULL); 282 NULL);
288} 283}
289 284
290 285
@@ -292,7 +287,7 @@ zone_iteration_error (void *cls)
292 * Function called once the zone iteration is done. 287 * Function called once the zone iteration is done.
293 */ 288 */
294static void 289static void
295zone_iteration_end (void *cls) 290zone_iteration_end(void *cls)
296{ 291{
297 struct ZoneinfoRequest *zr = cls; 292 struct ZoneinfoRequest *zr = cls;
298 struct MHD_Response *response; 293 struct MHD_Response *response;
@@ -301,19 +296,19 @@ zone_iteration_end (void *cls)
301 zr->list_it = NULL; 296 zr->list_it = NULL;
302 297
303 /* return static form */ 298 /* return static form */
304 GNUNET_asprintf (&full_page, 299 GNUNET_asprintf(&full_page,
305 ZONEINFO_PAGE, 300 ZONEINFO_PAGE,
306 zr->zoneinfo, 301 zr->zoneinfo,
307 zr->zoneinfo); 302 zr->zoneinfo);
308 response = MHD_create_response_from_buffer (strlen (full_page), 303 response = MHD_create_response_from_buffer(strlen(full_page),
309 (void *) full_page, 304 (void *)full_page,
310 MHD_RESPMEM_MUST_FREE); 305 MHD_RESPMEM_MUST_FREE);
311 MHD_add_response_header (response, 306 MHD_add_response_header(response,
312 MHD_HTTP_HEADER_CONTENT_TYPE, 307 MHD_HTTP_HEADER_CONTENT_TYPE,
313 MIME_HTML); 308 MIME_HTML);
314 MHD_destroy_response (info_page); 309 MHD_destroy_response(info_page);
315 info_page = response; 310 info_page = response;
316 GNUNET_free (zr->zoneinfo); 311 GNUNET_free(zr->zoneinfo);
317} 312}
318 313
319 314
@@ -328,59 +323,59 @@ zone_iteration_end (void *cls)
328 * @param rd array of records with data to store 323 * @param rd array of records with data to store
329 */ 324 */
330static void 325static void
331iterate_cb (void *cls, 326iterate_cb(void *cls,
332 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 327 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
333 const char *name, 328 const char *name,
334 unsigned int rd_len, 329 unsigned int rd_len,
335 const struct GNUNET_GNSRECORD_Data *rd) 330 const struct GNUNET_GNSRECORD_Data *rd)
336{ 331{
337 struct ZoneinfoRequest *zr = cls; 332 struct ZoneinfoRequest *zr = cls;
338 size_t bytes_free; 333 size_t bytes_free;
339 char* pkey; 334 char* pkey;
340 char* new_buf; 335 char* new_buf;
341 336
342 (void) zone_key; 337 (void)zone_key;
343 if (1 != rd_len) 338 if (1 != rd_len)
344 { 339 {
345 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, 340 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it,
346 1); 341 1);
347 return; 342 return;
348 } 343 }
349 344
350 if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type) 345 if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)
351 { 346 {
352 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, 347 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it,
353 1); 348 1);
354 return; 349 return;
355 } 350 }
356 351
357 bytes_free = zr->buf_len - zr->write_offset; 352 bytes_free = zr->buf_len - zr->write_offset;
358 pkey = GNUNET_GNSRECORD_value_to_string (rd->record_type, 353 pkey = GNUNET_GNSRECORD_value_to_string(rd->record_type,
359 rd->data, 354 rd->data,
360 rd->data_size); 355 rd->data_size);
361 if (NULL == pkey) 356 if (NULL == pkey)
362 { 357 {
363 GNUNET_break (0); 358 GNUNET_break(0);
364 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, 359 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it,
365 1); 360 1);
366 return; 361 return;
367 } 362 }
368 if (bytes_free < (strlen (name) + strlen (pkey) + 40)) 363 if (bytes_free < (strlen(name) + strlen(pkey) + 40))
369 { 364 {
370 new_buf = GNUNET_malloc (zr->buf_len * 2); 365 new_buf = GNUNET_malloc(zr->buf_len * 2);
371 GNUNET_memcpy (new_buf, zr->zoneinfo, zr->write_offset); 366 GNUNET_memcpy(new_buf, zr->zoneinfo, zr->write_offset);
372 GNUNET_free (zr->zoneinfo); 367 GNUNET_free(zr->zoneinfo);
373 zr->zoneinfo = new_buf; 368 zr->zoneinfo = new_buf;
374 zr->buf_len *= 2; 369 zr->buf_len *= 2;
375 } 370 }
376 sprintf (zr->zoneinfo + zr->write_offset, 371 sprintf(zr->zoneinfo + zr->write_offset,
377 "<tr><td>%s</td><td>%s</td></tr>", 372 "<tr><td>%s</td><td>%s</td></tr>",
378 name, 373 name,
379 pkey); 374 pkey);
380 zr->write_offset = strlen (zr->zoneinfo); 375 zr->write_offset = strlen(zr->zoneinfo);
381 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, 376 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it,
382 1); 377 1);
383 GNUNET_free (pkey); 378 GNUNET_free(pkey);
384} 379}
385 380
386 381
@@ -389,12 +384,12 @@ iterate_cb (void *cls,
389 * 384 *
390 * @param connection connection to use 385 * @param connection connection to use
391 */ 386 */
392static int 387static int
393serve_zoneinfo_page (struct MHD_Connection *connection) 388serve_zoneinfo_page(struct MHD_Connection *connection)
394{ 389{
395 return MHD_queue_response (connection, 390 return MHD_queue_response(connection,
396 MHD_HTTP_OK, 391 MHD_HTTP_OK,
397 info_page); 392 info_page);
398} 393}
399 394
400 395
@@ -402,27 +397,27 @@ serve_zoneinfo_page (struct MHD_Connection *connection)
402 * Create fresh version of zone information. 397 * Create fresh version of zone information.
403 */ 398 */
404static void 399static void
405update_zoneinfo_page (void *cls) 400update_zoneinfo_page(void *cls)
406{ 401{
407 static struct ZoneinfoRequest zr; 402 static struct ZoneinfoRequest zr;
408 403
409 (void) cls; 404 (void)cls;
410 uzp_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 405 uzp_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
411 &update_zoneinfo_page, 406 &update_zoneinfo_page,
412 NULL); 407 NULL);
413 if (NULL != zr.list_it) 408 if (NULL != zr.list_it)
414 return; 409 return;
415 zr.zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); 410 zr.zoneinfo = GNUNET_malloc(DEFAULT_ZONEINFO_BUFSIZE);
416 zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE; 411 zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE;
417 zr.write_offset = 0; 412 zr.write_offset = 0;
418 zr.list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 413 zr.list_it = GNUNET_NAMESTORE_zone_iteration_start(ns,
419 &fcfs_zone_pkey, 414 &fcfs_zone_pkey,
420 &zone_iteration_error, 415 &zone_iteration_error,
421 &zr, 416 &zr,
422 &iterate_cb, 417 &iterate_cb,
423 &zr, 418 &zr,
424 &zone_iteration_end, 419 &zone_iteration_end,
425 &zr); 420 &zr);
426} 421}
427 422
428 423
@@ -433,22 +428,22 @@ update_zoneinfo_page (void *cls)
433 * @return #MHD_YES on success 428 * @return #MHD_YES on success
434 */ 429 */
435static int 430static int
436serve_main_page (struct MHD_Connection *connection) 431serve_main_page(struct MHD_Connection *connection)
437{ 432{
438 int ret; 433 int ret;
439 struct MHD_Response *response; 434 struct MHD_Response *response;
440 435
441 /* return static form */ 436 /* return static form */
442 response = MHD_create_response_from_buffer (strlen (MAIN_PAGE), 437 response = MHD_create_response_from_buffer(strlen(MAIN_PAGE),
443 (void *) MAIN_PAGE, 438 (void *)MAIN_PAGE,
444 MHD_RESPMEM_PERSISTENT); 439 MHD_RESPMEM_PERSISTENT);
445 MHD_add_response_header (response, 440 MHD_add_response_header(response,
446 MHD_HTTP_HEADER_CONTENT_TYPE, 441 MHD_HTTP_HEADER_CONTENT_TYPE,
447 MIME_HTML); 442 MIME_HTML);
448 ret = MHD_queue_response (connection, 443 ret = MHD_queue_response(connection,
449 MHD_HTTP_OK, 444 MHD_HTTP_OK,
450 response); 445 response);
451 MHD_destroy_response (response); 446 MHD_destroy_response(response);
452 return ret; 447 return ret;
453} 448}
454 449
@@ -461,30 +456,30 @@ serve_main_page (struct MHD_Connection *connection)
461 * @param connection connection to use 456 * @param connection connection to use
462 */ 457 */
463static int 458static int
464fill_s_reply (const char *info, 459fill_s_reply(const char *info,
465 struct Request *request, 460 struct Request *request,
466 struct MHD_Connection *connection) 461 struct MHD_Connection *connection)
467{ 462{
468 int ret; 463 int ret;
469 char *reply; 464 char *reply;
470 struct MHD_Response *response; 465 struct MHD_Response *response;
471 466
472 (void) request; 467 (void)request;
473 GNUNET_asprintf (&reply, 468 GNUNET_asprintf(&reply,
474 SUBMIT_PAGE, 469 SUBMIT_PAGE,
475 info, 470 info,
476 info); 471 info);
477 /* return static form */ 472 /* return static form */
478 response = MHD_create_response_from_buffer (strlen (reply), 473 response = MHD_create_response_from_buffer(strlen(reply),
479 (void *) reply, 474 (void *)reply,
480 MHD_RESPMEM_MUST_FREE); 475 MHD_RESPMEM_MUST_FREE);
481 MHD_add_response_header (response, 476 MHD_add_response_header(response,
482 MHD_HTTP_HEADER_CONTENT_TYPE, 477 MHD_HTTP_HEADER_CONTENT_TYPE,
483 MIME_HTML); 478 MIME_HTML);
484 ret = MHD_queue_response (connection, 479 ret = MHD_queue_response(connection,
485 MHD_HTTP_OK, 480 MHD_HTTP_OK,
486 response); 481 response);
487 MHD_destroy_response (response); 482 MHD_destroy_response(response);
488 return ret; 483 return ret;
489} 484}
490 485
@@ -509,45 +504,45 @@ fill_s_reply (const char *info,
509 * MHD_NO to abort the iteration 504 * MHD_NO to abort the iteration
510 */ 505 */
511static int 506static int
512post_iterator (void *cls, 507post_iterator(void *cls,
513 enum MHD_ValueKind kind, 508 enum MHD_ValueKind kind,
514 const char *key, 509 const char *key,
515 const char *filename, 510 const char *filename,
516 const char *content_type, 511 const char *content_type,
517 const char *transfer_encoding, 512 const char *transfer_encoding,
518 const char *data, 513 const char *data,
519 uint64_t off, 514 uint64_t off,
520 size_t size) 515 size_t size)
521{ 516{
522 struct Request *request = cls; 517 struct Request *request = cls;
523 518
524 (void) kind; 519 (void)kind;
525 (void) filename; 520 (void)filename;
526 (void) content_type; 521 (void)content_type;
527 (void) transfer_encoding; 522 (void)transfer_encoding;
528 if (0 == strcmp ("domain", key)) 523 if (0 == strcmp("domain", key))
529 { 524 {
530 if (size + off >= sizeof(request->domain_name)) 525 if (size + off >= sizeof(request->domain_name))
531 size = sizeof (request->domain_name) - off - 1; 526 size = sizeof(request->domain_name) - off - 1;
532 GNUNET_memcpy (&request->domain_name[off], 527 GNUNET_memcpy(&request->domain_name[off],
533 data, 528 data,
534 size); 529 size);
535 request->domain_name[size+off] = '\0'; 530 request->domain_name[size + off] = '\0';
536 return MHD_YES; 531 return MHD_YES;
537 } 532 }
538 if (0 == strcmp ("pkey", key)) 533 if (0 == strcmp("pkey", key))
539 { 534 {
540 if (size + off >= sizeof(request->public_key)) 535 if (size + off >= sizeof(request->public_key))
541 size = sizeof (request->public_key) - off - 1; 536 size = sizeof(request->public_key) - off - 1;
542 GNUNET_memcpy (&request->public_key[off], 537 GNUNET_memcpy(&request->public_key[off],
543 data, 538 data,
544 size); 539 size);
545 request->public_key[size+off] = '\0'; 540 request->public_key[size + off] = '\0';
546 return MHD_YES; 541 return MHD_YES;
547 } 542 }
548 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 543 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
549 _("Unsupported form value `%s'\n"), 544 _("Unsupported form value `%s'\n"),
550 key); 545 key);
551 return MHD_YES; 546 return MHD_YES;
552} 547}
553 548
@@ -563,25 +558,25 @@ post_iterator (void *cls,
563 * @param emsg NULL on success, otherwise an error message 558 * @param emsg NULL on success, otherwise an error message
564 */ 559 */
565static void 560static void
566put_continuation (void *cls, 561put_continuation(void *cls,
567 int32_t success, 562 int32_t success,
568 const char *emsg) 563 const char *emsg)
569{ 564{
570 struct Request *request = cls; 565 struct Request *request = cls;
571 566
572 request->qe = NULL; 567 request->qe = NULL;
573 if (0 >= success) 568 if (0 >= success)
574 { 569 {
575 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 570 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
576 _("Failed to create record for domain `%s': %s\n"), 571 _("Failed to create record for domain `%s': %s\n"),
577 request->domain_name, 572 request->domain_name,
578 emsg); 573 emsg);
579 request->phase = RP_FAIL; 574 request->phase = RP_FAIL;
580 } 575 }
581 else 576 else
582 request->phase = RP_SUCCESS; 577 request->phase = RP_SUCCESS;
583 MHD_resume_connection (request->con); 578 MHD_resume_connection(request->con);
584 run_httpd_now (); 579 run_httpd_now();
585} 580}
586 581
587 582
@@ -589,15 +584,15 @@ put_continuation (void *cls,
589 * Function called if we had an error in zone-to-name mapping. 584 * Function called if we had an error in zone-to-name mapping.
590 */ 585 */
591static void 586static void
592zone_to_name_error (void *cls) 587zone_to_name_error(void *cls)
593{ 588{
594 struct Request *request = cls; 589 struct Request *request = cls;
595 590
596 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 591 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
597 _("Error when mapping zone to name\n")); 592 _("Error when mapping zone to name\n"));
598 request->phase = RP_FAIL; 593 request->phase = RP_FAIL;
599 MHD_resume_connection (request->con); 594 MHD_resume_connection(request->con);
600 run_httpd_now (); 595 run_httpd_now();
601} 596}
602 597
603 598
@@ -611,39 +606,39 @@ zone_to_name_error (void *cls)
611 * @param rd array of records with data to store 606 * @param rd array of records with data to store
612 */ 607 */
613static void 608static void
614zone_to_name_cb (void *cls, 609zone_to_name_cb(void *cls,
615 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 610 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
616 const char *name, 611 const char *name,
617 unsigned int rd_count, 612 unsigned int rd_count,
618 const struct GNUNET_GNSRECORD_Data *rd) 613 const struct GNUNET_GNSRECORD_Data *rd)
619{ 614{
620 struct Request *request = cls; 615 struct Request *request = cls;
621 struct GNUNET_GNSRECORD_Data r; 616 struct GNUNET_GNSRECORD_Data r;
622 617
623 (void) rd; 618 (void)rd;
624 (void) zone_key; 619 (void)zone_key;
625 request->qe = NULL; 620 request->qe = NULL;
626 if (0 != rd_count) 621 if (0 != rd_count)
627 { 622 {
628 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 623 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
629 _("Found existing name `%s' for the given key\n"), 624 _("Found existing name `%s' for the given key\n"),
630 name); 625 name);
631 request->phase = RP_FAIL; 626 request->phase = RP_FAIL;
632 MHD_resume_connection (request->con); 627 MHD_resume_connection(request->con);
633 run_httpd_now (); 628 run_httpd_now();
634 return; 629 return;
635 } 630 }
636 r.data = &request->pub; 631 r.data = &request->pub;
637 r.data_size = sizeof (request->pub); 632 r.data_size = sizeof(request->pub);
638 r.expiration_time = UINT64_MAX; 633 r.expiration_time = UINT64_MAX;
639 r.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 634 r.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
640 r.flags = GNUNET_GNSRECORD_RF_NONE; 635 r.flags = GNUNET_GNSRECORD_RF_NONE;
641 request->qe = GNUNET_NAMESTORE_records_store (ns, 636 request->qe = GNUNET_NAMESTORE_records_store(ns,
642 &fcfs_zone_pkey, 637 &fcfs_zone_pkey,
643 request->domain_name, 638 request->domain_name,
644 1, &r, 639 1, &r,
645 &put_continuation, 640 &put_continuation,
646 request); 641 request);
647} 642}
648 643
649 644
@@ -651,13 +646,14 @@ zone_to_name_cb (void *cls,
651 * We encountered an error in the name lookup. 646 * We encountered an error in the name lookup.
652 */ 647 */
653static void 648static void
654lookup_it_error (void *cls) 649lookup_it_error(void *cls)
655{ 650{
656 struct Request *request = cls; 651 struct Request *request = cls;
657 MHD_resume_connection (request->con); 652
653 MHD_resume_connection(request->con);
658 request->qe = NULL; 654 request->qe = NULL;
659 request->phase = RP_FAIL; 655 request->phase = RP_FAIL;
660 run_httpd_now (); 656 run_httpd_now();
661} 657}
662 658
663 659
@@ -672,57 +668,58 @@ lookup_it_error (void *cls)
672 * @param rd array of records with data to store 668 * @param rd array of records with data to store
673 */ 669 */
674static void 670static void
675lookup_it_processor (void *cls, 671lookup_it_processor(void *cls,
676 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, 672 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey,
677 const char *label, 673 const char *label,
678 unsigned int rd_count, 674 unsigned int rd_count,
679 const struct GNUNET_GNSRECORD_Data *rd) 675 const struct GNUNET_GNSRECORD_Data *rd)
680{ 676{
681 struct Request *request = cls; 677 struct Request *request = cls;
682 678
683 (void) label; 679 (void)label;
684 (void) rd; 680 (void)rd;
685 (void) zonekey; 681 (void)zonekey;
686 if (0 == strcmp (label, request->domain_name)) { 682 if (0 == strcmp(label, request->domain_name))
687 GNUNET_break (0 != rd_count); 683 {
688 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 684 GNUNET_break(0 != rd_count);
689 _("Found %u existing records for domain `%s'\n"), 685 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
690 rd_count, 686 _("Found %u existing records for domain `%s'\n"),
691 request->domain_name); 687 rd_count,
692 request->phase = RP_FAIL; 688 request->domain_name);
693 } 689 request->phase = RP_FAIL;
694 GNUNET_NAMESTORE_zone_iterator_next (request->lookup_it, 1); 690 }
691 GNUNET_NAMESTORE_zone_iterator_next(request->lookup_it, 1);
695} 692}
696 693
697static void 694static void
698lookup_it_finished (void *cls) 695lookup_it_finished(void *cls)
699{ 696{
700 struct Request *request = cls; 697 struct Request *request = cls;
701 698
702 if (RP_FAIL == request->phase) 699 if (RP_FAIL == request->phase)
703 { 700 {
704 MHD_resume_connection (request->con); 701 MHD_resume_connection(request->con);
705 run_httpd_now (); 702 run_httpd_now();
706 return; 703 return;
707 } 704 }
708 if (GNUNET_OK != 705 if (GNUNET_OK !=
709 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, 706 GNUNET_CRYPTO_ecdsa_public_key_from_string(request->public_key,
710 strlen (request->public_key), 707 strlen(request->public_key),
711 &request->pub)) 708 &request->pub))
712 { 709 {
713 GNUNET_break (0); 710 GNUNET_break(0);
714 request->phase = RP_FAIL; 711 request->phase = RP_FAIL;
715 MHD_resume_connection (request->con); 712 MHD_resume_connection(request->con);
716 run_httpd_now (); 713 run_httpd_now();
717 return; 714 return;
718 } 715 }
719 request->qe = GNUNET_NAMESTORE_zone_to_name (ns, 716 request->qe = GNUNET_NAMESTORE_zone_to_name(ns,
720 &fcfs_zone_pkey, 717 &fcfs_zone_pkey,
721 &request->pub, 718 &request->pub,
722 &zone_to_name_error, 719 &zone_to_name_error,
723 request, 720 request,
724 &zone_to_name_cb, 721 &zone_to_name_cb,
725 request); 722 request);
726} 723}
727 724
728/** 725/**
@@ -749,136 +746,141 @@ lookup_it_finished (void *cls)
749 * error while handling the request 746 * error while handling the request
750 */ 747 */
751static int 748static int
752create_response (void *cls, 749create_response(void *cls,
753 struct MHD_Connection *connection, 750 struct MHD_Connection *connection,
754 const char *url, 751 const char *url,
755 const char *method, 752 const char *method,
756 const char *version, 753 const char *version,
757 const char *upload_data, 754 const char *upload_data,
758 size_t *upload_data_size, 755 size_t *upload_data_size,
759 void **ptr) 756 void **ptr)
760{ 757{
761 struct MHD_Response *response; 758 struct MHD_Response *response;
762 struct Request *request; 759 struct Request *request;
763 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 760 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
764 int ret; 761 int ret;
765 762
766 (void) cls; 763 (void)cls;
767 (void) version; 764 (void)version;
768 if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || 765 if ((0 == strcmp(method, MHD_HTTP_METHOD_GET)) ||
769 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) 766 (0 == strcmp(method, MHD_HTTP_METHOD_HEAD)))
770 {
771 if (0 == strcmp (url, FCFS_ZONEINFO_URL))
772 ret = serve_zoneinfo_page (connection);
773 else
774 ret = serve_main_page (connection);
775 if (ret != MHD_YES)
776 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
777 _("Failed to create page for `%s'\n"),
778 url);
779 return ret;
780 }
781 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
782 {
783 request = *ptr;
784 if (NULL == request)
785 { 767 {
786 request = GNUNET_new (struct Request); 768 if (0 == strcmp(url, FCFS_ZONEINFO_URL))
787 request->con = connection; 769 ret = serve_zoneinfo_page(connection);
788 *ptr = request; 770 else
789 request->pp = MHD_create_post_processor (connection, 771 ret = serve_main_page(connection);
790 1024, 772 if (ret != MHD_YES)
791 &post_iterator, 773 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
792 request); 774 _("Failed to create page for `%s'\n"),
793 if (NULL == request->pp) 775 url);
794 { 776 return ret;
795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
796 _("Failed to setup post processor for `%s'\n"),
797 url);
798 return MHD_NO; /* internal error */
799 }
800 return MHD_YES;
801 }
802 if (NULL != request->pp)
803 {
804 /* evaluate POST data */
805 MHD_post_process (request->pp,
806 upload_data,
807 *upload_data_size);
808 if (0 != *upload_data_size)
809 {
810 *upload_data_size = 0;
811 return MHD_YES;
812 }
813 /* done with POST data, serve response */
814 MHD_destroy_post_processor (request->pp);
815 request->pp = NULL;
816 } 777 }
817 if (GNUNET_OK != 778 if (0 == strcmp(method, MHD_HTTP_METHOD_POST))
818 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
819 strlen (request->public_key),
820 &pub))
821 { 779 {
822 /* parse error */ 780 request = *ptr;
823 return fill_s_reply ("Failed to parse given public key", 781 if (NULL == request)
824 request, connection);
825 }
826 switch (request->phase)
827 {
828 case RP_START:
829 if (NULL != strchr (request->domain_name, (int) '.'))
830 { 782 {
831 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 783 request = GNUNET_new(struct Request);
832 _("Domain name must not contain `.'\n")); 784 request->con = connection;
833 request->phase = RP_FAIL; 785 *ptr = request;
834 return fill_s_reply ("Domain name must not contain `.', sorry.", 786 request->pp = MHD_create_post_processor(connection,
835 request, 787 1024,
836 connection); 788 &post_iterator,
789 request);
790 if (NULL == request->pp)
791 {
792 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
793 _("Failed to setup post processor for `%s'\n"),
794 url);
795 return MHD_NO; /* internal error */
796 }
797 return MHD_YES;
837 } 798 }
838 if (NULL != strchr (request->domain_name, (int) '+')) 799 if (NULL != request->pp)
839 { 800 {
840 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 801 /* evaluate POST data */
841 _("Domain name must not contain `+'\n")); 802 MHD_post_process(request->pp,
842 request->phase = RP_FAIL; 803 upload_data,
843 return fill_s_reply ("Domain name must not contain `+', sorry.", 804 *upload_data_size);
844 request, connection); 805 if (0 != *upload_data_size)
806 {
807 *upload_data_size = 0;
808 return MHD_YES;
809 }
810 /* done with POST data, serve response */
811 MHD_destroy_post_processor(request->pp);
812 request->pp = NULL;
845 } 813 }
846 request->phase = RP_LOOKUP; 814 if (GNUNET_OK !=
847 MHD_suspend_connection (request->con); 815 GNUNET_CRYPTO_ecdsa_public_key_from_string(request->public_key,
848 request->lookup_it 816 strlen(request->public_key),
849 = GNUNET_NAMESTORE_zone_iteration_start (ns, 817 &pub))
850 &fcfs_zone_pkey, 818 {
851 &lookup_it_error, 819 /* parse error */
852 request, 820 return fill_s_reply("Failed to parse given public key",
853 &lookup_it_processor, 821 request, connection);
854 request, 822 }
855 &lookup_it_finished, 823 switch (request->phase)
856 request); 824 {
857 break; 825 case RP_START:
858 case RP_LOOKUP: 826 if (NULL != strchr(request->domain_name, (int)'.'))
859 break; 827 {
860 case RP_PUT: 828 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
861 break; 829 _("Domain name must not contain `.'\n"));
862 case RP_FAIL: 830 request->phase = RP_FAIL;
863 return fill_s_reply ("Request failed, sorry.", 831 return fill_s_reply("Domain name must not contain `.', sorry.",
864 request, connection); 832 request,
865 case RP_SUCCESS: 833 connection);
866 return fill_s_reply ("Success.", 834 }
867 request, connection); 835 if (NULL != strchr(request->domain_name, (int)'+'))
868 default: 836 {
869 GNUNET_break (0); 837 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
870 return MHD_NO; 838 _("Domain name must not contain `+'\n"));
839 request->phase = RP_FAIL;
840 return fill_s_reply("Domain name must not contain `+', sorry.",
841 request, connection);
842 }
843 request->phase = RP_LOOKUP;
844 MHD_suspend_connection(request->con);
845 request->lookup_it
846 = GNUNET_NAMESTORE_zone_iteration_start(ns,
847 &fcfs_zone_pkey,
848 &lookup_it_error,
849 request,
850 &lookup_it_processor,
851 request,
852 &lookup_it_finished,
853 request);
854 break;
855
856 case RP_LOOKUP:
857 break;
858
859 case RP_PUT:
860 break;
861
862 case RP_FAIL:
863 return fill_s_reply("Request failed, sorry.",
864 request, connection);
865
866 case RP_SUCCESS:
867 return fill_s_reply("Success.",
868 request, connection);
869
870 default:
871 GNUNET_break(0);
872 return MHD_NO;
873 }
874 return MHD_YES; /* will have a reply later... */
871 } 875 }
872 return MHD_YES; /* will have a reply later... */
873 }
874 /* unsupported HTTP method */ 876 /* unsupported HTTP method */
875 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR), 877 response = MHD_create_response_from_buffer(strlen(METHOD_ERROR),
876 (void *) METHOD_ERROR, 878 (void *)METHOD_ERROR,
877 MHD_RESPMEM_PERSISTENT); 879 MHD_RESPMEM_PERSISTENT);
878 ret = MHD_queue_response (connection, 880 ret = MHD_queue_response(connection,
879 MHD_HTTP_NOT_ACCEPTABLE, 881 MHD_HTTP_NOT_ACCEPTABLE,
880 response); 882 response);
881 MHD_destroy_response (response); 883 MHD_destroy_response(response);
882 return ret; 884 return ret;
883} 885}
884 886
@@ -893,23 +895,23 @@ create_response (void *cls,
893 * @param toe status code 895 * @param toe status code
894 */ 896 */
895static void 897static void
896request_completed_callback (void *cls, 898request_completed_callback(void *cls,
897 struct MHD_Connection *connection, 899 struct MHD_Connection *connection,
898 void **con_cls, 900 void **con_cls,
899 enum MHD_RequestTerminationCode toe) 901 enum MHD_RequestTerminationCode toe)
900{ 902{
901 struct Request *request = *con_cls; 903 struct Request *request = *con_cls;
902 904
903 (void) cls; 905 (void)cls;
904 (void) connection; 906 (void)connection;
905 (void) toe; 907 (void)toe;
906 if (NULL == request) 908 if (NULL == request)
907 return; 909 return;
908 if (NULL != request->pp) 910 if (NULL != request->pp)
909 MHD_destroy_post_processor (request->pp); 911 MHD_destroy_post_processor(request->pp);
910 if (NULL != request->qe) 912 if (NULL != request->qe)
911 GNUNET_NAMESTORE_cancel (request->qe); 913 GNUNET_NAMESTORE_cancel(request->qe);
912 GNUNET_free (request); 914 GNUNET_free(request);
913} 915}
914 916
915 917
@@ -920,7 +922,7 @@ request_completed_callback (void *cls,
920 * Schedule tasks to run MHD server. 922 * Schedule tasks to run MHD server.
921 */ 923 */
922static void 924static void
923run_httpd () 925run_httpd()
924{ 926{
925 fd_set rs; 927 fd_set rs;
926 fd_set ws; 928 fd_set ws;
@@ -933,44 +935,44 @@ run_httpd ()
933 UNSIGNED_MHD_LONG_LONG timeout; 935 UNSIGNED_MHD_LONG_LONG timeout;
934 struct GNUNET_TIME_Relative tv; 936 struct GNUNET_TIME_Relative tv;
935 937
936 FD_ZERO (&rs); 938 FD_ZERO(&rs);
937 FD_ZERO (&ws); 939 FD_ZERO(&ws);
938 FD_ZERO (&es); 940 FD_ZERO(&es);
939 wrs = GNUNET_NETWORK_fdset_create (); 941 wrs = GNUNET_NETWORK_fdset_create();
940 wes = GNUNET_NETWORK_fdset_create (); 942 wes = GNUNET_NETWORK_fdset_create();
941 wws = GNUNET_NETWORK_fdset_create (); 943 wws = GNUNET_NETWORK_fdset_create();
942 max = -1; 944 max = -1;
943 GNUNET_assert (MHD_YES == 945 GNUNET_assert(MHD_YES ==
944 MHD_get_fdset (httpd, 946 MHD_get_fdset(httpd,
945 &rs, 947 &rs,
946 &ws, 948 &ws,
947 &es, 949 &es,
948 &max)); 950 &max));
949 haveto = MHD_get_timeout (httpd, 951 haveto = MHD_get_timeout(httpd,
950 &timeout); 952 &timeout);
951 if (haveto == MHD_YES) 953 if (haveto == MHD_YES)
952 tv.rel_value_us = (uint64_t) timeout * 1000LL; 954 tv.rel_value_us = (uint64_t)timeout * 1000LL;
953 else 955 else
954 tv = GNUNET_TIME_UNIT_FOREVER_REL; 956 tv = GNUNET_TIME_UNIT_FOREVER_REL;
955 GNUNET_NETWORK_fdset_copy_native (wrs, 957 GNUNET_NETWORK_fdset_copy_native(wrs,
956 &rs, 958 &rs,
957 max + 1); 959 max + 1);
958 GNUNET_NETWORK_fdset_copy_native (wws, 960 GNUNET_NETWORK_fdset_copy_native(wws,
959 &ws, 961 &ws,
960 max + 1); 962 max + 1);
961 GNUNET_NETWORK_fdset_copy_native (wes, 963 GNUNET_NETWORK_fdset_copy_native(wes,
962 &es, 964 &es,
963 max + 1); 965 max + 1);
964 httpd_task = 966 httpd_task =
965 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 967 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH,
966 tv, 968 tv,
967 wrs, 969 wrs,
968 wws, 970 wws,
969 &do_httpd, 971 &do_httpd,
970 NULL); 972 NULL);
971 GNUNET_NETWORK_fdset_destroy (wrs); 973 GNUNET_NETWORK_fdset_destroy(wrs);
972 GNUNET_NETWORK_fdset_destroy (wws); 974 GNUNET_NETWORK_fdset_destroy(wws);
973 GNUNET_NETWORK_fdset_destroy (wes); 975 GNUNET_NETWORK_fdset_destroy(wes);
974} 976}
975 977
976 978
@@ -980,12 +982,12 @@ run_httpd ()
980 * @param cls unused 982 * @param cls unused
981 */ 983 */
982static void 984static void
983do_httpd (void *cls) 985do_httpd(void *cls)
984{ 986{
985 (void) cls; 987 (void)cls;
986 httpd_task = NULL; 988 httpd_task = NULL;
987 MHD_run (httpd); 989 MHD_run(httpd);
988 run_httpd (); 990 run_httpd();
989} 991}
990 992
991 993
@@ -995,39 +997,39 @@ do_httpd (void *cls)
995 * @param cls unused 997 * @param cls unused
996 */ 998 */
997static void 999static void
998do_shutdown (void *cls) 1000do_shutdown(void *cls)
999{ 1001{
1000 (void) cls; 1002 (void)cls;
1001 if (NULL != httpd_task) 1003 if (NULL != httpd_task)
1002 { 1004 {
1003 GNUNET_SCHEDULER_cancel (httpd_task); 1005 GNUNET_SCHEDULER_cancel(httpd_task);
1004 httpd_task = NULL; 1006 httpd_task = NULL;
1005 } 1007 }
1006 if (NULL != uzp_task) 1008 if (NULL != uzp_task)
1007 { 1009 {
1008 GNUNET_SCHEDULER_cancel (uzp_task); 1010 GNUNET_SCHEDULER_cancel(uzp_task);
1009 uzp_task = NULL; 1011 uzp_task = NULL;
1010 } 1012 }
1011 if (NULL != ns) 1013 if (NULL != ns)
1012 { 1014 {
1013 GNUNET_NAMESTORE_disconnect (ns); 1015 GNUNET_NAMESTORE_disconnect(ns);
1014 ns = NULL; 1016 ns = NULL;
1015 } 1017 }
1016 if (NULL != httpd) 1018 if (NULL != httpd)
1017 { 1019 {
1018 MHD_stop_daemon (httpd); 1020 MHD_stop_daemon(httpd);
1019 httpd = NULL; 1021 httpd = NULL;
1020 } 1022 }
1021 if (NULL != id_op) 1023 if (NULL != id_op)
1022 { 1024 {
1023 GNUNET_IDENTITY_cancel (id_op); 1025 GNUNET_IDENTITY_cancel(id_op);
1024 id_op = NULL; 1026 id_op = NULL;
1025 } 1027 }
1026 if (NULL != identity) 1028 if (NULL != identity)
1027 { 1029 {
1028 GNUNET_IDENTITY_disconnect (identity); 1030 GNUNET_IDENTITY_disconnect(identity);
1029 identity = NULL; 1031 identity = NULL;
1030 } 1032 }
1031} 1033}
1032 1034
1033 1035
@@ -1051,56 +1053,55 @@ do_shutdown (void *cls)
1051 * must thus no longer be used 1053 * must thus no longer be used
1052 */ 1054 */
1053static void 1055static void
1054identity_cb (void *cls, 1056identity_cb(void *cls,
1055 struct GNUNET_IDENTITY_Ego *ego, 1057 struct GNUNET_IDENTITY_Ego *ego,
1056 void **ctx, 1058 void **ctx,
1057 const char *name) 1059 const char *name)
1058{ 1060{
1059 int options; 1061 int options;
1060 1062
1061 (void) cls; 1063 (void)cls;
1062 (void) ctx; 1064 (void)ctx;
1063 if (NULL == name) 1065 if (NULL == name)
1064 return; 1066 return;
1065 if (0 != strcmp (name, 1067 if (0 != strcmp(name,
1066 zone)) 1068 zone))
1067 return; 1069 return;
1068 if (NULL == ego) 1070 if (NULL == ego)
1069 { 1071 {
1070 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1072 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1071 _("No ego configured for `fcfsd` subsystem\n")); 1073 _("No ego configured for `fcfsd` subsystem\n"));
1072 GNUNET_SCHEDULER_shutdown (); 1074 GNUNET_SCHEDULER_shutdown();
1073 return; 1075 return;
1074 } 1076 }
1075 fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); 1077 fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key(ego);
1076 1078
1077 options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME; 1079 options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
1078 do 1080 do
1079 { 1081 {
1080 httpd = MHD_start_daemon (options, 1082 httpd = MHD_start_daemon(options,
1081 (uint16_t) port, 1083 (uint16_t)port,
1082 NULL, NULL, 1084 NULL, NULL,
1083 &create_response, NULL, 1085 &create_response, NULL,
1084 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, 1086 MHD_OPTION_CONNECTION_LIMIT, (unsigned int)128,
1085 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, 1087 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int)1,
1086 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, 1088 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16,
1087 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4 * 1024), 1089 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(4 * 1024),
1088 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, 1090 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL,
1089 MHD_OPTION_END); 1091 MHD_OPTION_END);
1090 if (MHD_USE_DEBUG == options) 1092 if (MHD_USE_DEBUG == options)
1091 break; 1093 break;
1092 options = MHD_USE_DEBUG; 1094 options = MHD_USE_DEBUG;
1093 } 1095 }
1094 while (NULL == httpd); 1096 while (NULL == httpd);
1095 if (NULL == httpd) 1097 if (NULL == httpd)
1096 { 1098 {
1097 1099 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1098 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1100 _("Failed to start HTTP server\n"));
1099 _("Failed to start HTTP server\n")); 1101 GNUNET_SCHEDULER_shutdown();
1100 GNUNET_SCHEDULER_shutdown (); 1102 return;
1101 return; 1103 }
1102 } 1104 run_httpd();
1103 run_httpd ();
1104} 1105}
1105 1106
1106 1107
@@ -1113,44 +1114,44 @@ identity_cb (void *cls,
1113 * @param cfg configuration 1114 * @param cfg configuration
1114 */ 1115 */
1115static void 1116static void
1116run (void *cls, 1117run(void *cls,
1117 char *const *args, 1118 char *const *args,
1118 const char *cfgfile, 1119 const char *cfgfile,
1119 const struct GNUNET_CONFIGURATION_Handle *cfg) 1120 const struct GNUNET_CONFIGURATION_Handle *cfg)
1120{ 1121{
1121 (void) cls; 1122 (void)cls;
1122 (void) args; 1123 (void)args;
1123 (void) cfgfile; 1124 (void)cfgfile;
1124 if (GNUNET_OK != 1125 if (GNUNET_OK !=
1125 GNUNET_CONFIGURATION_get_value_number (cfg, 1126 GNUNET_CONFIGURATION_get_value_number(cfg,
1126 "fcfsd", 1127 "fcfsd",
1127 "HTTPPORT", 1128 "HTTPPORT",
1128 &port)) 1129 &port))
1129 { 1130 {
1130 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1131 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
1131 "fcfsd", "HTTPPORT"); 1132 "fcfsd", "HTTPPORT");
1132 return; 1133 return;
1133 } 1134 }
1134 ns = GNUNET_NAMESTORE_connect (cfg); 1135 ns = GNUNET_NAMESTORE_connect(cfg);
1135 if (NULL == ns) 1136 if (NULL == ns)
1136 { 1137 {
1137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1138 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1138 _("Failed to connect to namestore\n")); 1139 _("Failed to connect to namestore\n"));
1139 return; 1140 return;
1140 } 1141 }
1141 identity = GNUNET_IDENTITY_connect (cfg, 1142 identity = GNUNET_IDENTITY_connect(cfg,
1142 &identity_cb, 1143 &identity_cb,
1143 NULL); 1144 NULL);
1144 if (NULL == identity) 1145 if (NULL == identity)
1145 { 1146 {
1146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1147 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1147 _("Failed to connect to identity\n")); 1148 _("Failed to connect to identity\n"));
1148 return; 1149 return;
1149 } 1150 }
1150 uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, 1151 uzp_task = GNUNET_SCHEDULER_add_now(&update_zoneinfo_page,
1151 NULL); 1152 NULL);
1152 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 1153 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
1153 NULL); 1154 NULL);
1154} 1155}
1155 1156
1156 1157
@@ -1162,38 +1163,38 @@ run (void *cls,
1162 * @return 0 ok, 1 on error 1163 * @return 0 ok, 1 on error
1163 */ 1164 */
1164int 1165int
1165main (int argc, 1166main(int argc,
1166 char *const *argv) 1167 char *const *argv)
1167{ 1168{
1168 struct GNUNET_GETOPT_CommandLineOption options[] = { 1169 struct GNUNET_GETOPT_CommandLineOption options[] = {
1169 GNUNET_GETOPT_option_mandatory 1170 GNUNET_GETOPT_option_mandatory
1170 (GNUNET_GETOPT_option_string ('z', 1171 (GNUNET_GETOPT_option_string('z',
1171 "zone", 1172 "zone",
1172 "EGO", 1173 "EGO",
1173 gettext_noop ("name of the zone that is to be managed by FCFSD"), 1174 gettext_noop("name of the zone that is to be managed by FCFSD"),
1174 &zone)), 1175 &zone)),
1175 GNUNET_GETOPT_OPTION_END 1176 GNUNET_GETOPT_OPTION_END
1176 }; 1177 };
1177 int ret; 1178 int ret;
1178 1179
1179 if (GNUNET_OK != 1180 if (GNUNET_OK !=
1180 GNUNET_STRINGS_get_utf8_args (argc, argv, 1181 GNUNET_STRINGS_get_utf8_args(argc, argv,
1181 &argc, &argv)) 1182 &argc, &argv))
1182 return 2; 1183 return 2;
1183 1184
1184 GNUNET_log_setup ("fcfsd", 1185 GNUNET_log_setup("fcfsd",
1185 "WARNING", 1186 "WARNING",
1186 NULL); 1187 NULL);
1187 ret = 1188 ret =
1188 (GNUNET_OK == 1189 (GNUNET_OK ==
1189 GNUNET_PROGRAM_run (argc, 1190 GNUNET_PROGRAM_run(argc,
1190 argv, 1191 argv,
1191 "gnunet-namestore-fcfsd", 1192 "gnunet-namestore-fcfsd",
1192 _("GNU Name System First Come First Serve name registration service"), 1193 _("GNU Name System First Come First Serve name registration service"),
1193 options, 1194 options,
1194 &run, NULL)) ? 0 : 1; 1195 &run, NULL)) ? 0 : 1;
1195 GNUNET_free ((void*) argv); 1196 GNUNET_free((void*)argv);
1196 GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey); 1197 GNUNET_CRYPTO_ecdsa_key_clear(&fcfs_zone_pkey);
1197 return ret; 1198 return ret;
1198} 1199}
1199 1200
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 2b814206b..cc1362a51 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file gnunet-namestore.c 21 * @file gnunet-namestore.c
22 * @brief command line tool to manipulate the local zone 22 * @brief command line tool to manipulate the local zone
@@ -37,8 +37,7 @@
37/** 37/**
38 * Entry in record set for bulk processing. 38 * Entry in record set for bulk processing.
39 */ 39 */
40struct RecordSetEntry 40struct RecordSetEntry {
41{
42 /** 41 /**
43 * Kept in a linked list. 42 * Kept in a linked list.
44 */ 43 */
@@ -228,75 +227,75 @@ static struct RecordSetEntry *recordset;
228 * @param cls unused 227 * @param cls unused
229 */ 228 */
230static void 229static void
231do_shutdown (void *cls) 230do_shutdown(void *cls)
232{ 231{
233 (void) cls; 232 (void)cls;
234 if (NULL != get_default) 233 if (NULL != get_default)
235 { 234 {
236 GNUNET_IDENTITY_cancel (get_default); 235 GNUNET_IDENTITY_cancel(get_default);
237 get_default = NULL; 236 get_default = NULL;
238 } 237 }
239 if (NULL != idh) 238 if (NULL != idh)
240 { 239 {
241 GNUNET_IDENTITY_disconnect (idh); 240 GNUNET_IDENTITY_disconnect(idh);
242 idh = NULL; 241 idh = NULL;
243 } 242 }
244 if (NULL != el) 243 if (NULL != el)
245 { 244 {
246 GNUNET_IDENTITY_ego_lookup_cancel (el); 245 GNUNET_IDENTITY_ego_lookup_cancel(el);
247 el = NULL; 246 el = NULL;
248 } 247 }
249 if (NULL != list_it) 248 if (NULL != list_it)
250 { 249 {
251 GNUNET_NAMESTORE_zone_iteration_stop (list_it); 250 GNUNET_NAMESTORE_zone_iteration_stop(list_it);
252 list_it = NULL; 251 list_it = NULL;
253 } 252 }
254 if (NULL != add_qe) 253 if (NULL != add_qe)
255 { 254 {
256 GNUNET_NAMESTORE_cancel (add_qe); 255 GNUNET_NAMESTORE_cancel(add_qe);
257 add_qe = NULL; 256 add_qe = NULL;
258 } 257 }
259 if (NULL != set_qe) 258 if (NULL != set_qe)
260 { 259 {
261 GNUNET_NAMESTORE_cancel (set_qe); 260 GNUNET_NAMESTORE_cancel(set_qe);
262 set_qe = NULL; 261 set_qe = NULL;
263 } 262 }
264 if (NULL != add_qe_uri) 263 if (NULL != add_qe_uri)
265 { 264 {
266 GNUNET_NAMESTORE_cancel (add_qe_uri); 265 GNUNET_NAMESTORE_cancel(add_qe_uri);
267 add_qe_uri = NULL; 266 add_qe_uri = NULL;
268 } 267 }
269 if (NULL != get_qe) 268 if (NULL != get_qe)
270 { 269 {
271 GNUNET_NAMESTORE_cancel (get_qe); 270 GNUNET_NAMESTORE_cancel(get_qe);
272 get_qe = NULL; 271 get_qe = NULL;
273 } 272 }
274 if (NULL != del_qe) 273 if (NULL != del_qe)
275 { 274 {
276 GNUNET_NAMESTORE_cancel (del_qe); 275 GNUNET_NAMESTORE_cancel(del_qe);
277 del_qe = NULL; 276 del_qe = NULL;
278 } 277 }
279 if (NULL != ns) 278 if (NULL != ns)
280 { 279 {
281 GNUNET_NAMESTORE_disconnect (ns); 280 GNUNET_NAMESTORE_disconnect(ns);
282 ns = NULL; 281 ns = NULL;
283 } 282 }
284 memset (&zone_pkey, 0, sizeof (zone_pkey)); 283 memset(&zone_pkey, 0, sizeof(zone_pkey));
285 if (NULL != uri) 284 if (NULL != uri)
286 { 285 {
287 GNUNET_free (uri); 286 GNUNET_free(uri);
288 uri = NULL; 287 uri = NULL;
289 } 288 }
290 if (NULL != zm) 289 if (NULL != zm)
291 { 290 {
292 GNUNET_NAMESTORE_zone_monitor_stop (zm); 291 GNUNET_NAMESTORE_zone_monitor_stop(zm);
293 zm = NULL; 292 zm = NULL;
294 } 293 }
295 if (NULL != data) 294 if (NULL != data)
296 { 295 {
297 GNUNET_free (data); 296 GNUNET_free(data);
298 data = NULL; 297 data = NULL;
299 } 298 }
300} 299}
301 300
302 301
@@ -304,11 +303,11 @@ do_shutdown (void *cls)
304 * Check if we are finished, and if so, perform shutdown. 303 * Check if we are finished, and if so, perform shutdown.
305 */ 304 */
306static void 305static void
307test_finished () 306test_finished()
308{ 307{
309 if ((NULL == add_qe) && (NULL == add_qe_uri) && (NULL == get_qe) && 308 if ((NULL == add_qe) && (NULL == add_qe_uri) && (NULL == get_qe) &&
310 (NULL == del_qe) && (NULL == reverse_qe) && (NULL == list_it)) 309 (NULL == del_qe) && (NULL == reverse_qe) && (NULL == list_it))
311 GNUNET_SCHEDULER_shutdown (); 310 GNUNET_SCHEDULER_shutdown();
312} 311}
313 312
314 313
@@ -323,21 +322,21 @@ test_finished ()
323 * @param emsg NULL on success, otherwise an error message 322 * @param emsg NULL on success, otherwise an error message
324 */ 323 */
325static void 324static void
326add_continuation (void *cls, int32_t success, const char *emsg) 325add_continuation(void *cls, int32_t success, const char *emsg)
327{ 326{
328 struct GNUNET_NAMESTORE_QueueEntry **qe = cls; 327 struct GNUNET_NAMESTORE_QueueEntry **qe = cls;
329 328
330 *qe = NULL; 329 *qe = NULL;
331 if (GNUNET_YES != success) 330 if (GNUNET_YES != success)
332 { 331 {
333 fprintf (stderr, 332 fprintf(stderr,
334 _ ("Adding record failed: %s\n"), 333 _("Adding record failed: %s\n"),
335 (GNUNET_NO == success) ? "record exists" : emsg); 334 (GNUNET_NO == success) ? "record exists" : emsg);
336 if (GNUNET_NO != success) 335 if (GNUNET_NO != success)
337 ret = 1; 336 ret = 1;
338 } 337 }
339 ret = 0; 338 ret = 0;
340 test_finished (); 339 test_finished();
341} 340}
342 341
343 342
@@ -352,25 +351,25 @@ add_continuation (void *cls, int32_t success, const char *emsg)
352 * @param emsg NULL on success, otherwise an error message 351 * @param emsg NULL on success, otherwise an error message
353 */ 352 */
354static void 353static void
355del_continuation (void *cls, int32_t success, const char *emsg) 354del_continuation(void *cls, int32_t success, const char *emsg)
356{ 355{
357 (void) cls; 356 (void)cls;
358 del_qe = NULL; 357 del_qe = NULL;
359 if (GNUNET_NO == success) 358 if (GNUNET_NO == success)
360 { 359 {
361 fprintf (stderr, 360 fprintf(stderr,
362 _ ("Deleting record failed, record does not exist%s%s\n"), 361 _("Deleting record failed, record does not exist%s%s\n"),
363 (NULL != emsg) ? ": " : "", 362 (NULL != emsg) ? ": " : "",
364 (NULL != emsg) ? emsg : ""); 363 (NULL != emsg) ? emsg : "");
365 } 364 }
366 if (GNUNET_SYSERR == success) 365 if (GNUNET_SYSERR == success)
367 { 366 {
368 fprintf (stderr, 367 fprintf(stderr,
369 _ ("Deleting record failed%s%s\n"), 368 _("Deleting record failed%s%s\n"),
370 (NULL != emsg) ? ": " : "", 369 (NULL != emsg) ? ": " : "",
371 (NULL != emsg) ? emsg : ""); 370 (NULL != emsg) ? emsg : "");
372 } 371 }
373 test_finished (); 372 test_finished();
374} 373}
375 374
376 375
@@ -378,11 +377,11 @@ del_continuation (void *cls, int32_t success, const char *emsg)
378 * Function called when we are done with a zone iteration. 377 * Function called when we are done with a zone iteration.
379 */ 378 */
380static void 379static void
381zone_iteration_finished (void *cls) 380zone_iteration_finished(void *cls)
382{ 381{
383 (void) cls; 382 (void)cls;
384 list_it = NULL; 383 list_it = NULL;
385 test_finished (); 384 test_finished();
386} 385}
387 386
388 387
@@ -390,13 +389,13 @@ zone_iteration_finished (void *cls)
390 * Function called when we encountered an error in a zone iteration. 389 * Function called when we encountered an error in a zone iteration.
391 */ 390 */
392static void 391static void
393zone_iteration_error_cb (void *cls) 392zone_iteration_error_cb(void *cls)
394{ 393{
395 (void) cls; 394 (void)cls;
396 list_it = NULL; 395 list_it = NULL;
397 fprintf (stderr, "Error iterating over zone\n"); 396 fprintf(stderr, "Error iterating over zone\n");
398 ret = 1; 397 ret = 1;
399 test_finished (); 398 test_finished();
400} 399}
401 400
402 401
@@ -408,9 +407,9 @@ zone_iteration_error_cb (void *cls)
408 * @param rd array of records with data to store 407 * @param rd array of records with data to store
409 */ 408 */
410static void 409static void
411display_record (const char *rname, 410display_record(const char *rname,
412 unsigned int rd_len, 411 unsigned int rd_len,
413 const struct GNUNET_GNSRECORD_Data *rd) 412 const struct GNUNET_GNSRECORD_Data *rd)
414{ 413{
415 const char *typestr; 414 const char *typestr;
416 char *s; 415 char *s;
@@ -419,69 +418,69 @@ display_record (const char *rname,
419 struct GNUNET_TIME_Relative rt; 418 struct GNUNET_TIME_Relative rt;
420 int have_record; 419 int have_record;
421 420
422 if ((NULL != name) && (0 != strcmp (name, rname))) 421 if ((NULL != name) && (0 != strcmp(name, rname)))
423 { 422 {
424 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); 423 GNUNET_NAMESTORE_zone_iterator_next(list_it, 1);
425 return; 424 return;
426 } 425 }
427 have_record = GNUNET_NO; 426 have_record = GNUNET_NO;
428 for (unsigned int i = 0; i < rd_len; i++) 427 for (unsigned int i = 0; i < rd_len; i++)
429 { 428 {
430 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && 429 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
431 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) 430 (0 != strcmp(rname, GNUNET_GNS_EMPTY_LABEL_AT)))
432 continue; 431 continue;
433 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type)) 432 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
434 continue; 433 continue;
435 have_record = GNUNET_YES; 434 have_record = GNUNET_YES;
436 break; 435 break;
437 } 436 }
438 if (GNUNET_NO == have_record) 437 if (GNUNET_NO == have_record)
439 return; 438 return;
440 fprintf (stdout, "%s:\n", rname); 439 fprintf(stdout, "%s:\n", rname);
441 if (NULL != typestring) 440 if (NULL != typestring)
442 type = GNUNET_GNSRECORD_typename_to_number (typestring); 441 type = GNUNET_GNSRECORD_typename_to_number(typestring);
443 else 442 else
444 type = GNUNET_GNSRECORD_TYPE_ANY; 443 type = GNUNET_GNSRECORD_TYPE_ANY;
445 for (unsigned int i = 0; i < rd_len; i++) 444 for (unsigned int i = 0; i < rd_len; i++)
446 {
447 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
448 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
449 continue;
450 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
451 continue;
452 typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
453 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
454 rd[i].data,
455 rd[i].data_size);
456 if (NULL == s)
457 { 445 {
458 fprintf (stdout, 446 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
459 _ ("\tCorrupt or unsupported record of type %u\n"), 447 (0 != strcmp(rname, GNUNET_GNS_EMPTY_LABEL_AT)))
460 (unsigned int) rd[i].record_type); 448 continue;
461 continue; 449 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
450 continue;
451 typestr = GNUNET_GNSRECORD_number_to_typename(rd[i].record_type);
452 s = GNUNET_GNSRECORD_value_to_string(rd[i].record_type,
453 rd[i].data,
454 rd[i].data_size);
455 if (NULL == s)
456 {
457 fprintf(stdout,
458 _("\tCorrupt or unsupported record of type %u\n"),
459 (unsigned int)rd[i].record_type);
460 continue;
461 }
462 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
463 {
464 rt.rel_value_us = rd[i].expiration_time;
465 ets = GNUNET_STRINGS_relative_time_to_string(rt, GNUNET_YES);
466 }
467 else
468 {
469 at.abs_value_us = rd[i].expiration_time;
470 ets = GNUNET_STRINGS_absolute_time_to_string(at);
471 }
472 fprintf(stdout,
473 "\t%s: %s (%s)\t%s\t%s\n",
474 typestr,
475 s,
476 ets,
477 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE"
478 : "PUBLIC",
479 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW"
480 : "");
481 GNUNET_free(s);
462 } 482 }
463 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 483 fprintf(stdout, "%s", "\n");
464 {
465 rt.rel_value_us = rd[i].expiration_time;
466 ets = GNUNET_STRINGS_relative_time_to_string (rt, GNUNET_YES);
467 }
468 else
469 {
470 at.abs_value_us = rd[i].expiration_time;
471 ets = GNUNET_STRINGS_absolute_time_to_string (at);
472 }
473 fprintf (stdout,
474 "\t%s: %s (%s)\t%s\t%s\n",
475 typestr,
476 s,
477 ets,
478 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE"
479 : "PUBLIC",
480 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW"
481 : "");
482 GNUNET_free (s);
483 }
484 fprintf (stdout, "%s", "\n");
485} 484}
486 485
487 486
@@ -495,16 +494,16 @@ display_record (const char *rname,
495 * @param rd array of records with data to store 494 * @param rd array of records with data to store
496 */ 495 */
497static void 496static void
498display_record_iterator (void *cls, 497display_record_iterator(void *cls,
499 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 498 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
500 const char *rname, 499 const char *rname,
501 unsigned int rd_len, 500 unsigned int rd_len,
502 const struct GNUNET_GNSRECORD_Data *rd) 501 const struct GNUNET_GNSRECORD_Data *rd)
503{ 502{
504 (void) cls; 503 (void)cls;
505 (void) zone_key; 504 (void)zone_key;
506 display_record (rname, rd_len, rd); 505 display_record(rname, rd_len, rd);
507 GNUNET_NAMESTORE_zone_iterator_next (list_it, 1); 506 GNUNET_NAMESTORE_zone_iterator_next(list_it, 1);
508} 507}
509 508
510 509
@@ -518,16 +517,16 @@ display_record_iterator (void *cls,
518 * @param rd array of records with data to store 517 * @param rd array of records with data to store
519 */ 518 */
520static void 519static void
521display_record_monitor (void *cls, 520display_record_monitor(void *cls,
522 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 521 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
523 const char *rname, 522 const char *rname,
524 unsigned int rd_len, 523 unsigned int rd_len,
525 const struct GNUNET_GNSRECORD_Data *rd) 524 const struct GNUNET_GNSRECORD_Data *rd)
526{ 525{
527 (void) cls; 526 (void)cls;
528 (void) zone_key; 527 (void)zone_key;
529 display_record (rname, rd_len, rd); 528 display_record(rname, rd_len, rd);
530 GNUNET_NAMESTORE_zone_monitor_next (zm, 1); 529 GNUNET_NAMESTORE_zone_monitor_next(zm, 1);
531} 530}
532 531
533 532
@@ -541,17 +540,17 @@ display_record_monitor (void *cls,
541 * @param rd array of records with data to store 540 * @param rd array of records with data to store
542 */ 541 */
543static void 542static void
544display_record_lookup (void *cls, 543display_record_lookup(void *cls,
545 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 544 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
546 const char *rname, 545 const char *rname,
547 unsigned int rd_len, 546 unsigned int rd_len,
548 const struct GNUNET_GNSRECORD_Data *rd) 547 const struct GNUNET_GNSRECORD_Data *rd)
549{ 548{
550 (void) cls; 549 (void)cls;
551 (void) zone_key; 550 (void)zone_key;
552 get_qe = NULL; 551 get_qe = NULL;
553 display_record (rname, rd_len, rd); 552 display_record(rname, rd_len, rd);
554 test_finished (); 553 test_finished();
555} 554}
556 555
557 556
@@ -561,10 +560,10 @@ display_record_lookup (void *cls,
561 * @param cls NULL 560 * @param cls NULL
562 */ 561 */
563static void 562static void
564sync_cb (void *cls) 563sync_cb(void *cls)
565{ 564{
566 (void) cls; 565 (void)cls;
567 fprintf (stdout, "%s", "Monitor is now in sync.\n"); 566 fprintf(stdout, "%s", "Monitor is now in sync.\n");
568} 567}
569 568
570 569
@@ -574,10 +573,10 @@ sync_cb (void *cls)
574 * @param cls NULL 573 * @param cls NULL
575 */ 574 */
576static void 575static void
577monitor_error_cb (void *cls) 576monitor_error_cb(void *cls)
578{ 577{
579 (void) cls; 578 (void)cls;
580 fprintf (stderr, "%s", "Monitor disconnected and out of sync.\n"); 579 fprintf(stderr, "%s", "Monitor disconnected and out of sync.\n");
581} 580}
582 581
583 582
@@ -587,12 +586,12 @@ monitor_error_cb (void *cls)
587 * @param cls NULL 586 * @param cls NULL
588 */ 587 */
589static void 588static void
590lookup_error_cb (void *cls) 589lookup_error_cb(void *cls)
591{ 590{
592 (void) cls; 591 (void)cls;
593 get_qe = NULL; 592 get_qe = NULL;
594 fprintf (stderr, "%s", "Failed to lookup record.\n"); 593 fprintf(stderr, "%s", "Failed to lookup record.\n");
595 test_finished (); 594 test_finished();
596} 595}
597 596
598 597
@@ -600,13 +599,13 @@ lookup_error_cb (void *cls)
600 * Function called if lookup fails. 599 * Function called if lookup fails.
601 */ 600 */
602static void 601static void
603add_error_cb (void *cls) 602add_error_cb(void *cls)
604{ 603{
605 (void) cls; 604 (void)cls;
606 add_qe = NULL; 605 add_qe = NULL;
607 GNUNET_break (0); 606 GNUNET_break(0);
608 ret = 1; 607 ret = 1;
609 test_finished (); 608 test_finished();
610} 609}
611 610
612 611
@@ -621,114 +620,118 @@ add_error_cb (void *cls)
621 * @param rd array of records with data to store 620 * @param rd array of records with data to store
622 */ 621 */
623static void 622static void
624get_existing_record (void *cls, 623get_existing_record(void *cls,
625 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 624 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
626 const char *rec_name, 625 const char *rec_name,
627 unsigned int rd_count, 626 unsigned int rd_count,
628 const struct GNUNET_GNSRECORD_Data *rd) 627 const struct GNUNET_GNSRECORD_Data *rd)
629{ 628{
630 struct GNUNET_GNSRECORD_Data rdn[rd_count + 1]; 629 struct GNUNET_GNSRECORD_Data rdn[rd_count + 1];
631 struct GNUNET_GNSRECORD_Data *rde; 630 struct GNUNET_GNSRECORD_Data *rde;
632 631
633 (void) cls; 632 (void)cls;
634 (void) zone_key; 633 (void)zone_key;
635 add_qe = NULL; 634 add_qe = NULL;
636 if (0 != strcmp (rec_name, name)) 635 if (0 != strcmp(rec_name, name))
637 {
638 GNUNET_break (0);
639 ret = 1;
640 test_finished ();
641 return;
642 }
643
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
645 "Received %u records for name `%s'\n",
646 rd_count,
647 rec_name);
648 for (unsigned int i = 0; i < rd_count; i++)
649 {
650 switch (rd[i].record_type)
651 { 636 {
652 case GNUNET_DNSPARSER_TYPE_CNAME: 637 GNUNET_break(0);
653 fprintf (
654 stderr,
655 _ (
656 "A %s record exists already under `%s', no other records can be added.\n"),
657 "CNAME",
658 rec_name);
659 ret = 1; 638 ret = 1;
660 test_finished (); 639 test_finished();
661 return; 640 return;
662 case GNUNET_GNSRECORD_TYPE_PKEY:
663 fprintf (
664 stderr,
665 _ (
666 "A %s record exists already under `%s', no other records can be added.\n"),
667 "PKEY",
668 rec_name);
669 ret = 1;
670 test_finished ();
671 return;
672 case GNUNET_DNSPARSER_TYPE_SOA:
673 if (GNUNET_DNSPARSER_TYPE_SOA == type)
674 {
675 fprintf (
676 stderr,
677 _ (
678 "A SOA record exists already under `%s', cannot add a second SOA to the same zone.\n"),
679 rec_name);
680 ret = 1;
681 test_finished ();
682 return;
683 }
684 break;
685 } 641 }
686 } 642
687 switch (type) 643 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
688 { 644 "Received %u records for name `%s'\n",
689 case GNUNET_DNSPARSER_TYPE_CNAME: 645 rd_count,
690 if (0 != rd_count) 646 rec_name);
647 for (unsigned int i = 0; i < rd_count; i++)
691 { 648 {
692 fprintf (stderr, 649 switch (rd[i].record_type)
693 _ ( 650 {
694 "Records already exist under `%s', cannot add `%s' record.\n"), 651 case GNUNET_DNSPARSER_TYPE_CNAME:
695 rec_name, 652 fprintf(
696 "CNAME"); 653 stderr,
697 ret = 1; 654 _(
698 test_finished (); 655 "A %s record exists already under `%s', no other records can be added.\n"),
699 return; 656 "CNAME",
657 rec_name);
658 ret = 1;
659 test_finished();
660 return;
661
662 case GNUNET_GNSRECORD_TYPE_PKEY:
663 fprintf(
664 stderr,
665 _(
666 "A %s record exists already under `%s', no other records can be added.\n"),
667 "PKEY",
668 rec_name);
669 ret = 1;
670 test_finished();
671 return;
672
673 case GNUNET_DNSPARSER_TYPE_SOA:
674 if (GNUNET_DNSPARSER_TYPE_SOA == type)
675 {
676 fprintf(
677 stderr,
678 _(
679 "A SOA record exists already under `%s', cannot add a second SOA to the same zone.\n"),
680 rec_name);
681 ret = 1;
682 test_finished();
683 return;
684 }
685 break;
686 }
700 } 687 }
701 break; 688 switch (type)
702 case GNUNET_GNSRECORD_TYPE_PKEY:
703 if (0 != rd_count)
704 { 689 {
705 fprintf (stderr, 690 case GNUNET_DNSPARSER_TYPE_CNAME:
706 _ ( 691 if (0 != rd_count)
707 "Records already exist under `%s', cannot add `%s' record.\n"), 692 {
708 rec_name, 693 fprintf(stderr,
709 "PKEY"); 694 _(
710 ret = 1; 695 "Records already exist under `%s', cannot add `%s' record.\n"),
711 test_finished (); 696 rec_name,
712 return; 697 "CNAME");
698 ret = 1;
699 test_finished();
700 return;
701 }
702 break;
703
704 case GNUNET_GNSRECORD_TYPE_PKEY:
705 if (0 != rd_count)
706 {
707 fprintf(stderr,
708 _(
709 "Records already exist under `%s', cannot add `%s' record.\n"),
710 rec_name,
711 "PKEY");
712 ret = 1;
713 test_finished();
714 return;
715 }
716 break;
717
718 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
719 for (unsigned int i = 0; i < rd_count; i++)
720 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type)
721 {
722 fprintf(
723 stderr,
724 _(
725 "Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"),
726 rec_name);
727 ret = 1;
728 test_finished();
729 return;
730 }
731 break;
713 } 732 }
714 break; 733 memset(rdn, 0, sizeof(struct GNUNET_GNSRECORD_Data));
715 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 734 GNUNET_memcpy(&rdn[1], rd, rd_count * sizeof(struct GNUNET_GNSRECORD_Data));
716 for (unsigned int i = 0; i < rd_count; i++)
717 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type)
718 {
719 fprintf (
720 stderr,
721 _ (
722 "Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"),
723 rec_name);
724 ret = 1;
725 test_finished ();
726 return;
727 }
728 break;
729 }
730 memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data));
731 GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
732 rde = &rdn[0]; 735 rde = &rdn[0];
733 rde->data = data; 736 rde->data = data;
734 rde->data_size = data_size; 737 rde->data_size = data_size;
@@ -742,14 +745,14 @@ get_existing_record (void *cls,
742 rde->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 745 rde->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
743 else if (GNUNET_NO != etime_is_rel) 746 else if (GNUNET_NO != etime_is_rel)
744 rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 747 rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
745 GNUNET_assert (NULL != name); 748 GNUNET_assert(NULL != name);
746 add_qe = GNUNET_NAMESTORE_records_store (ns, 749 add_qe = GNUNET_NAMESTORE_records_store(ns,
747 &zone_pkey, 750 &zone_pkey,
748 name, 751 name,
749 rd_count + 1, 752 rd_count + 1,
750 rde, 753 rde,
751 &add_continuation, 754 &add_continuation,
752 &add_qe); 755 &add_qe);
753} 756}
754 757
755 758
@@ -757,11 +760,11 @@ get_existing_record (void *cls,
757 * Function called if we encountered an error in zone-to-name. 760 * Function called if we encountered an error in zone-to-name.
758 */ 761 */
759static void 762static void
760reverse_error_cb (void *cls) 763reverse_error_cb(void *cls)
761{ 764{
762 (void) cls; 765 (void)cls;
763 reverse_qe = NULL; 766 reverse_qe = NULL;
764 fprintf (stdout, "%s.zkey\n", reverse_pkey); 767 fprintf(stdout, "%s.zkey\n", reverse_pkey);
765} 768}
766 769
767 770
@@ -776,22 +779,22 @@ reverse_error_cb (void *cls)
776 * @param rd array of records with data to store 779 * @param rd array of records with data to store
777 */ 780 */
778static void 781static void
779handle_reverse_lookup (void *cls, 782handle_reverse_lookup(void *cls,
780 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 783 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
781 const char *label, 784 const char *label,
782 unsigned int rd_count, 785 unsigned int rd_count,
783 const struct GNUNET_GNSRECORD_Data *rd) 786 const struct GNUNET_GNSRECORD_Data *rd)
784{ 787{
785 (void) cls; 788 (void)cls;
786 (void) zone; 789 (void)zone;
787 (void) rd_count; 790 (void)rd_count;
788 (void) rd; 791 (void)rd;
789 reverse_qe = NULL; 792 reverse_qe = NULL;
790 if (NULL == label) 793 if (NULL == label)
791 fprintf (stdout, "%s\n", reverse_pkey); 794 fprintf(stdout, "%s\n", reverse_pkey);
792 else 795 else
793 fprintf (stdout, "%s.%s\n", label, ego_name); 796 fprintf(stdout, "%s.%s\n", label, ego_name);
794 test_finished (); 797 test_finished();
795} 798}
796 799
797 800
@@ -799,13 +802,13 @@ handle_reverse_lookup (void *cls,
799 * Function called if lookup for deletion fails. 802 * Function called if lookup for deletion fails.
800 */ 803 */
801static void 804static void
802del_lookup_error_cb (void *cls) 805del_lookup_error_cb(void *cls)
803{ 806{
804 (void) cls; 807 (void)cls;
805 del_qe = NULL; 808 del_qe = NULL;
806 GNUNET_break (0); 809 GNUNET_break(0);
807 ret = 1; 810 ret = 1;
808 test_finished (); 811 test_finished();
809} 812}
810 813
811 814
@@ -821,80 +824,80 @@ del_lookup_error_cb (void *cls)
821 * @param rd existing records 824 * @param rd existing records
822 */ 825 */
823static void 826static void
824del_monitor (void *cls, 827del_monitor(void *cls,
825 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 828 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
826 const char *label, 829 const char *label,
827 unsigned int rd_count, 830 unsigned int rd_count,
828 const struct GNUNET_GNSRECORD_Data *rd) 831 const struct GNUNET_GNSRECORD_Data *rd)
829{ 832{
830 struct GNUNET_GNSRECORD_Data rdx[rd_count]; 833 struct GNUNET_GNSRECORD_Data rdx[rd_count];
831 unsigned int rd_left; 834 unsigned int rd_left;
832 uint32_t type; 835 uint32_t type;
833 char *vs; 836 char *vs;
834 837
835 (void) cls; 838 (void)cls;
836 (void) zone; 839 (void)zone;
837 del_qe = NULL; 840 del_qe = NULL;
838 if (0 == rd_count) 841 if (0 == rd_count)
839 { 842 {
840 fprintf (stderr, 843 fprintf(stderr,
841 _ ( 844 _(
842 "There are no records under label `%s' that could be deleted.\n"), 845 "There are no records under label `%s' that could be deleted.\n"),
843 label); 846 label);
844 ret = 1; 847 ret = 1;
845 test_finished (); 848 test_finished();
846 return; 849 return;
847 } 850 }
848 if ((NULL == value) && (NULL == typestring)) 851 if ((NULL == value) && (NULL == typestring))
849 { 852 {
850 /* delete everything */ 853 /* delete everything */
851 del_qe = GNUNET_NAMESTORE_records_store (ns, 854 del_qe = GNUNET_NAMESTORE_records_store(ns,
852 &zone_pkey, 855 &zone_pkey,
853 name, 856 name,
854 0, 857 0,
855 NULL, 858 NULL,
856 &del_continuation, 859 &del_continuation,
857 NULL); 860 NULL);
858 return; 861 return;
859 } 862 }
860 rd_left = 0; 863 rd_left = 0;
861 if (NULL != typestring) 864 if (NULL != typestring)
862 type = GNUNET_GNSRECORD_typename_to_number (typestring); 865 type = GNUNET_GNSRECORD_typename_to_number(typestring);
863 else 866 else
864 type = GNUNET_GNSRECORD_TYPE_ANY; 867 type = GNUNET_GNSRECORD_TYPE_ANY;
865 for (unsigned int i = 0; i < rd_count; i++) 868 for (unsigned int i = 0; i < rd_count; i++)
866 { 869 {
867 vs = NULL; 870 vs = NULL;
868 if (! (((GNUNET_GNSRECORD_TYPE_ANY == type) || 871 if (!(((GNUNET_GNSRECORD_TYPE_ANY == type) ||
869 (rd[i].record_type == type)) && 872 (rd[i].record_type == type)) &&
870 ((NULL == value) || 873 ((NULL == value) ||
871 (NULL == 874 (NULL ==
872 (vs = (GNUNET_GNSRECORD_value_to_string (rd[i].record_type, 875 (vs = (GNUNET_GNSRECORD_value_to_string(rd[i].record_type,
873 rd[i].data, 876 rd[i].data,
874 rd[i].data_size)))) || 877 rd[i].data_size)))) ||
875 (0 == strcmp (vs, value))))) 878 (0 == strcmp(vs, value)))))
876 rdx[rd_left++] = rd[i]; 879 rdx[rd_left++] = rd[i];
877 GNUNET_free_non_null (vs); 880 GNUNET_free_non_null(vs);
878 } 881 }
879 if (rd_count == rd_left) 882 if (rd_count == rd_left)
880 { 883 {
881 /* nothing got deleted */ 884 /* nothing got deleted */
882 fprintf ( 885 fprintf(
883 stderr, 886 stderr,
884 _ ( 887 _(
885 "There are no records under label `%s' that match the request for deletion.\n"), 888 "There are no records under label `%s' that match the request for deletion.\n"),
886 label); 889 label);
887 test_finished (); 890 test_finished();
888 return; 891 return;
889 } 892 }
890 /* delete everything but what we copied to 'rdx' */ 893 /* delete everything but what we copied to 'rdx' */
891 del_qe = GNUNET_NAMESTORE_records_store (ns, 894 del_qe = GNUNET_NAMESTORE_records_store(ns,
892 &zone_pkey, 895 &zone_pkey,
893 name, 896 name,
894 rd_left, 897 rd_left,
895 rdx, 898 rdx,
896 &del_continuation, 899 &del_continuation,
897 NULL); 900 NULL);
898} 901}
899 902
900 903
@@ -907,39 +910,39 @@ del_monitor (void *cls,
907 * @return #GNUNET_OK on success 910 * @return #GNUNET_OK on success
908 */ 911 */
909static int 912static int
910parse_expiration (const char *expirationstring, 913parse_expiration(const char *expirationstring,
911 int *etime_is_rel, 914 int *etime_is_rel,
912 uint64_t *etime) 915 uint64_t *etime)
913{ 916{
914 struct GNUNET_TIME_Relative etime_rel; 917 struct GNUNET_TIME_Relative etime_rel;
915 struct GNUNET_TIME_Absolute etime_abs; 918 struct GNUNET_TIME_Absolute etime_abs;
916 919
917 if (0 == strcmp (expirationstring, "never")) 920 if (0 == strcmp(expirationstring, "never"))
918 { 921 {
919 *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 922 *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
920 *etime_is_rel = GNUNET_NO; 923 *etime_is_rel = GNUNET_NO;
921 return GNUNET_OK; 924 return GNUNET_OK;
922 } 925 }
923 if (GNUNET_OK == 926 if (GNUNET_OK ==
924 GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel)) 927 GNUNET_STRINGS_fancy_time_to_relative(expirationstring, &etime_rel))
925 { 928 {
926 *etime_is_rel = GNUNET_YES; 929 *etime_is_rel = GNUNET_YES;
927 *etime = etime_rel.rel_value_us; 930 *etime = etime_rel.rel_value_us;
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 931 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
929 "Storing record with relative expiration time of %s\n", 932 "Storing record with relative expiration time of %s\n",
930 GNUNET_STRINGS_relative_time_to_string (etime_rel, GNUNET_NO)); 933 GNUNET_STRINGS_relative_time_to_string(etime_rel, GNUNET_NO));
931 return GNUNET_OK; 934 return GNUNET_OK;
932 } 935 }
933 if (GNUNET_OK == 936 if (GNUNET_OK ==
934 GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs)) 937 GNUNET_STRINGS_fancy_time_to_absolute(expirationstring, &etime_abs))
935 { 938 {
936 *etime_is_rel = GNUNET_NO; 939 *etime_is_rel = GNUNET_NO;
937 *etime = etime_abs.abs_value_us; 940 *etime = etime_abs.abs_value_us;
938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 941 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
939 "Storing record with absolute expiration time of %s\n", 942 "Storing record with absolute expiration time of %s\n",
940 GNUNET_STRINGS_absolute_time_to_string (etime_abs)); 943 GNUNET_STRINGS_absolute_time_to_string(etime_abs));
941 return GNUNET_OK; 944 return GNUNET_OK;
942 } 945 }
943 return GNUNET_SYSERR; 946 return GNUNET_SYSERR;
944} 947}
945 948
@@ -955,19 +958,19 @@ parse_expiration (const char *expirationstring,
955 * @param emsg NULL on success, otherwise an error message 958 * @param emsg NULL on success, otherwise an error message
956 */ 959 */
957static void 960static void
958replace_cont (void *cls, int success, const char *emsg) 961replace_cont(void *cls, int success, const char *emsg)
959{ 962{
960 (void) cls; 963 (void)cls;
961 964
962 set_qe = NULL; 965 set_qe = NULL;
963 if (GNUNET_OK != success) 966 if (GNUNET_OK != success)
964 { 967 {
965 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 968 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
966 _ ("Failed to replace records: %s\n"), 969 _("Failed to replace records: %s\n"),
967 emsg); 970 emsg);
968 ret = 1; /* fail from 'main' */ 971 ret = 1; /* fail from 'main' */
969 } 972 }
970 GNUNET_SCHEDULER_shutdown (); 973 GNUNET_SCHEDULER_shutdown();
971} 974}
972 975
973 976
@@ -978,261 +981,261 @@ replace_cont (void *cls, int success, const char *emsg)
978 * @param cfg configuration to use 981 * @param cfg configuration to use
979 */ 982 */
980static void 983static void
981run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) 984run_with_zone_pkey(const struct GNUNET_CONFIGURATION_Handle *cfg)
982{ 985{
983 struct GNUNET_GNSRECORD_Data rd; 986 struct GNUNET_GNSRECORD_Data rd;
984 987
985 if (! (add | del | list | (NULL != nickstring) | (NULL != uri) | 988 if (!(add | del | list | (NULL != nickstring) | (NULL != uri) |
986 (NULL != reverse_pkey) | (NULL != recordset))) 989 (NULL != reverse_pkey) | (NULL != recordset)))
987 {
988 /* nothing more to be done */
989 fprintf (stderr, _ ("No options given\n"));
990 GNUNET_SCHEDULER_shutdown ();
991 return;
992 }
993 ns = GNUNET_NAMESTORE_connect (cfg);
994 if (NULL == ns)
995 {
996 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
997 _ ("Failed to connect to namestore\n"));
998 return;
999 }
1000
1001 if (NULL != recordset)
1002 {
1003 /* replace entire record set */
1004 unsigned int rd_count;
1005 struct GNUNET_GNSRECORD_Data *rd;
1006
1007 if (NULL == name)
1008 { 990 {
1009 fprintf (stderr, 991 /* nothing more to be done */
1010 _ ("Missing option `%s' for operation `%s'\n"), 992 fprintf(stderr, _("No options given\n"));
1011 "-R", 993 GNUNET_SCHEDULER_shutdown();
1012 _ ("replace"));
1013 GNUNET_SCHEDULER_shutdown ();
1014 ret = 1;
1015 return;
1016 }
1017 rd_count = 0;
1018 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1019 rd_count++;
1020 rd = GNUNET_new_array (rd_count, struct GNUNET_GNSRECORD_Data);
1021 rd_count = 0;
1022 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1023 {
1024 rd[rd_count] = e->record;
1025 rd_count++;
1026 }
1027 set_qe = GNUNET_NAMESTORE_records_store (ns,
1028 &zone_pkey,
1029 name,
1030 rd_count,
1031 rd,
1032 &replace_cont,
1033 NULL);
1034 GNUNET_free (rd);
1035 return;
1036 }
1037
1038 if (add)
1039 {
1040 if (NULL == name)
1041 {
1042 fprintf (stderr,
1043 _ ("Missing option `%s' for operation `%s'\n"),
1044 "-n",
1045 _ ("add"));
1046 GNUNET_SCHEDULER_shutdown ();
1047 ret = 1;
1048 return;
1049 }
1050 if (NULL == typestring)
1051 {
1052 fprintf (stderr,
1053 _ ("Missing option `%s' for operation `%s'\n"),
1054 "-t",
1055 _ ("add"));
1056 GNUNET_SCHEDULER_shutdown ();
1057 ret = 1;
1058 return; 994 return;
1059 } 995 }
1060 type = GNUNET_GNSRECORD_typename_to_number (typestring); 996 ns = GNUNET_NAMESTORE_connect(cfg);
1061 if (UINT32_MAX == type) 997 if (NULL == ns)
1062 {
1063 fprintf (stderr, _ ("Unsupported type `%s'\n"), typestring);
1064 GNUNET_SCHEDULER_shutdown ();
1065 ret = 1;
1066 return;
1067 }
1068 if (NULL == value)
1069 {
1070 fprintf (stderr,
1071 _ ("Missing option `%s' for operation `%s'\n"),
1072 "-V",
1073 _ ("add"));
1074 ret = 1;
1075 GNUNET_SCHEDULER_shutdown ();
1076 return;
1077 }
1078 if (GNUNET_OK !=
1079 GNUNET_GNSRECORD_string_to_value (type, value, &data, &data_size))
1080 { 998 {
1081 fprintf (stderr, 999 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1082 _ ("Value `%s' invalid for record type `%s'\n"), 1000 _("Failed to connect to namestore\n"));
1083 value,
1084 typestring);
1085 GNUNET_SCHEDULER_shutdown ();
1086 ret = 1;
1087 return; 1001 return;
1088 } 1002 }
1089 if (NULL == expirationstring) 1003
1004 if (NULL != recordset)
1090 { 1005 {
1091 fprintf (stderr, 1006 /* replace entire record set */
1092 _ ("Missing option `%s' for operation `%s'\n"), 1007 unsigned int rd_count;
1093 "-e", 1008 struct GNUNET_GNSRECORD_Data *rd;
1094 _ ("add")); 1009
1095 GNUNET_SCHEDULER_shutdown (); 1010 if (NULL == name)
1096 ret = 1; 1011 {
1012 fprintf(stderr,
1013 _("Missing option `%s' for operation `%s'\n"),
1014 "-R",
1015 _("replace"));
1016 GNUNET_SCHEDULER_shutdown();
1017 ret = 1;
1018 return;
1019 }
1020 rd_count = 0;
1021 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1022 rd_count++;
1023 rd = GNUNET_new_array(rd_count, struct GNUNET_GNSRECORD_Data);
1024 rd_count = 0;
1025 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1026 {
1027 rd[rd_count] = e->record;
1028 rd_count++;
1029 }
1030 set_qe = GNUNET_NAMESTORE_records_store(ns,
1031 &zone_pkey,
1032 name,
1033 rd_count,
1034 rd,
1035 &replace_cont,
1036 NULL);
1037 GNUNET_free(rd);
1097 return; 1038 return;
1098 } 1039 }
1099 if (GNUNET_OK != parse_expiration (expirationstring, &etime_is_rel, &etime)) 1040
1041 if (add)
1100 { 1042 {
1101 fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring); 1043 if (NULL == name)
1102 GNUNET_SCHEDULER_shutdown (); 1044 {
1103 ret = 1; 1045 fprintf(stderr,
1104 return; 1046 _("Missing option `%s' for operation `%s'\n"),
1047 "-n",
1048 _("add"));
1049 GNUNET_SCHEDULER_shutdown();
1050 ret = 1;
1051 return;
1052 }
1053 if (NULL == typestring)
1054 {
1055 fprintf(stderr,
1056 _("Missing option `%s' for operation `%s'\n"),
1057 "-t",
1058 _("add"));
1059 GNUNET_SCHEDULER_shutdown();
1060 ret = 1;
1061 return;
1062 }
1063 type = GNUNET_GNSRECORD_typename_to_number(typestring);
1064 if (UINT32_MAX == type)
1065 {
1066 fprintf(stderr, _("Unsupported type `%s'\n"), typestring);
1067 GNUNET_SCHEDULER_shutdown();
1068 ret = 1;
1069 return;
1070 }
1071 if (NULL == value)
1072 {
1073 fprintf(stderr,
1074 _("Missing option `%s' for operation `%s'\n"),
1075 "-V",
1076 _("add"));
1077 ret = 1;
1078 GNUNET_SCHEDULER_shutdown();
1079 return;
1080 }
1081 if (GNUNET_OK !=
1082 GNUNET_GNSRECORD_string_to_value(type, value, &data, &data_size))
1083 {
1084 fprintf(stderr,
1085 _("Value `%s' invalid for record type `%s'\n"),
1086 value,
1087 typestring);
1088 GNUNET_SCHEDULER_shutdown();
1089 ret = 1;
1090 return;
1091 }
1092 if (NULL == expirationstring)
1093 {
1094 fprintf(stderr,
1095 _("Missing option `%s' for operation `%s'\n"),
1096 "-e",
1097 _("add"));
1098 GNUNET_SCHEDULER_shutdown();
1099 ret = 1;
1100 return;
1101 }
1102 if (GNUNET_OK != parse_expiration(expirationstring, &etime_is_rel, &etime))
1103 {
1104 fprintf(stderr, _("Invalid time format `%s'\n"), expirationstring);
1105 GNUNET_SCHEDULER_shutdown();
1106 ret = 1;
1107 return;
1108 }
1109 add_qe = GNUNET_NAMESTORE_records_lookup(ns,
1110 &zone_pkey,
1111 name,
1112 &add_error_cb,
1113 NULL,
1114 &get_existing_record,
1115 NULL);
1105 } 1116 }
1106 add_qe = GNUNET_NAMESTORE_records_lookup (ns,
1107 &zone_pkey,
1108 name,
1109 &add_error_cb,
1110 NULL,
1111 &get_existing_record,
1112 NULL);
1113 }
1114 if (del) 1117 if (del)
1115 {
1116 if (NULL == name)
1117 { 1118 {
1118 fprintf (stderr, 1119 if (NULL == name)
1119 _ ("Missing option `%s' for operation `%s'\n"), 1120 {
1120 "-n", 1121 fprintf(stderr,
1121 _ ("del")); 1122 _("Missing option `%s' for operation `%s'\n"),
1122 GNUNET_SCHEDULER_shutdown (); 1123 "-n",
1123 ret = 1; 1124 _("del"));
1124 return; 1125 GNUNET_SCHEDULER_shutdown();
1126 ret = 1;
1127 return;
1128 }
1129 del_qe = GNUNET_NAMESTORE_records_lookup(ns,
1130 &zone_pkey,
1131 name,
1132 &del_lookup_error_cb,
1133 NULL,
1134 &del_monitor,
1135 NULL);
1125 } 1136 }
1126 del_qe = GNUNET_NAMESTORE_records_lookup (ns,
1127 &zone_pkey,
1128 name,
1129 &del_lookup_error_cb,
1130 NULL,
1131 &del_monitor,
1132 NULL);
1133 }
1134 if (list) 1137 if (list)
1135 { 1138 {
1136 if (NULL != name) 1139 if (NULL != name)
1137 get_qe = GNUNET_NAMESTORE_records_lookup (ns, 1140 get_qe = GNUNET_NAMESTORE_records_lookup(ns,
1138 &zone_pkey, 1141 &zone_pkey,
1139 name, 1142 name,
1140 &lookup_error_cb, 1143 &lookup_error_cb,
1141 NULL, 1144 NULL,
1142 &display_record_lookup, 1145 &display_record_lookup,
1143 NULL); 1146 NULL);
1144 else 1147 else
1145 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 1148 list_it = GNUNET_NAMESTORE_zone_iteration_start(ns,
1146 &zone_pkey, 1149 &zone_pkey,
1147 &zone_iteration_error_cb, 1150 &zone_iteration_error_cb,
1148 NULL, 1151 NULL,
1149 &display_record_iterator, 1152 &display_record_iterator,
1150 NULL, 1153 NULL,
1151 &zone_iteration_finished, 1154 &zone_iteration_finished,
1152 NULL); 1155 NULL);
1153 } 1156 }
1154 if (NULL != reverse_pkey) 1157 if (NULL != reverse_pkey)
1155 {
1156 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
1157
1158 if (GNUNET_OK !=
1159 GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_pkey,
1160 strlen (reverse_pkey),
1161 &pubkey))
1162 { 1158 {
1163 fprintf (stderr, 1159 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
1164 _ ("Invalid public key for reverse lookup `%s'\n"), 1160
1165 reverse_pkey); 1161 if (GNUNET_OK !=
1166 GNUNET_SCHEDULER_shutdown (); 1162 GNUNET_CRYPTO_ecdsa_public_key_from_string(reverse_pkey,
1163 strlen(reverse_pkey),
1164 &pubkey))
1165 {
1166 fprintf(stderr,
1167 _("Invalid public key for reverse lookup `%s'\n"),
1168 reverse_pkey);
1169 GNUNET_SCHEDULER_shutdown();
1170 }
1171 reverse_qe = GNUNET_NAMESTORE_zone_to_name(ns,
1172 &zone_pkey,
1173 &pubkey,
1174 &reverse_error_cb,
1175 NULL,
1176 &handle_reverse_lookup,
1177 NULL);
1167 } 1178 }
1168 reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns,
1169 &zone_pkey,
1170 &pubkey,
1171 &reverse_error_cb,
1172 NULL,
1173 &handle_reverse_lookup,
1174 NULL);
1175 }
1176 if (NULL != uri) 1179 if (NULL != uri)
1177 {
1178 char sh[105];
1179 char sname[64];
1180 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1181
1182 GNUNET_STRINGS_utf8_tolower (uri, uri);
1183 if ((2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname))) ||
1184 (GNUNET_OK !=
1185 GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)))
1186 { 1180 {
1187 fprintf (stderr, _ ("Invalid URI `%s'\n"), uri); 1181 char sh[105];
1188 GNUNET_SCHEDULER_shutdown (); 1182 char sname[64];
1189 ret = 1; 1183 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1190 return; 1184
1185 GNUNET_STRINGS_utf8_tolower(uri, uri);
1186 if ((2 != (sscanf(uri, "gnunet://gns/%52s/%63s", sh, sname))) ||
1187 (GNUNET_OK !=
1188 GNUNET_CRYPTO_ecdsa_public_key_from_string(sh, strlen(sh), &pkey)))
1189 {
1190 fprintf(stderr, _("Invalid URI `%s'\n"), uri);
1191 GNUNET_SCHEDULER_shutdown();
1192 ret = 1;
1193 return;
1194 }
1195 memset(&rd, 0, sizeof(rd));
1196 rd.data = &pkey;
1197 rd.data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
1198 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
1199 rd.expiration_time = etime;
1200 if (GNUNET_YES == etime_is_rel)
1201 rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1202 if (1 == is_shadow)
1203 rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
1204 add_qe_uri = GNUNET_NAMESTORE_records_store(ns,
1205 &zone_pkey,
1206 sname,
1207 1,
1208 &rd,
1209 &add_continuation,
1210 &add_qe_uri);
1191 } 1211 }
1192 memset (&rd, 0, sizeof (rd));
1193 rd.data = &pkey;
1194 rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
1195 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
1196 rd.expiration_time = etime;
1197 if (GNUNET_YES == etime_is_rel)
1198 rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1199 if (1 == is_shadow)
1200 rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
1201 add_qe_uri = GNUNET_NAMESTORE_records_store (ns,
1202 &zone_pkey,
1203 sname,
1204 1,
1205 &rd,
1206 &add_continuation,
1207 &add_qe_uri);
1208 }
1209 if (NULL != nickstring) 1212 if (NULL != nickstring)
1210 {
1211 if (0 == strlen (nickstring))
1212 { 1213 {
1213 fprintf (stderr, _ ("Invalid nick `%s'\n"), nickstring); 1214 if (0 == strlen(nickstring))
1214 GNUNET_SCHEDULER_shutdown (); 1215 {
1215 ret = 1; 1216 fprintf(stderr, _("Invalid nick `%s'\n"), nickstring);
1216 return; 1217 GNUNET_SCHEDULER_shutdown();
1218 ret = 1;
1219 return;
1220 }
1221 add_qe_uri = GNUNET_NAMESTORE_set_nick(ns,
1222 &zone_pkey,
1223 nickstring,
1224 &add_continuation,
1225 &add_qe_uri);
1217 } 1226 }
1218 add_qe_uri = GNUNET_NAMESTORE_set_nick (ns,
1219 &zone_pkey,
1220 nickstring,
1221 &add_continuation,
1222 &add_qe_uri);
1223 }
1224 if (monitor) 1227 if (monitor)
1225 { 1228 {
1226 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 1229 zm = GNUNET_NAMESTORE_zone_monitor_start(cfg,
1227 &zone_pkey, 1230 &zone_pkey,
1228 GNUNET_YES, 1231 GNUNET_YES,
1229 &monitor_error_cb, 1232 &monitor_error_cb,
1230 NULL, 1233 NULL,
1231 &display_record_monitor, 1234 &display_record_monitor,
1232 NULL, 1235 NULL,
1233 &sync_cb, 1236 &sync_cb,
1234 NULL); 1237 NULL);
1235 } 1238 }
1236} 1239}
1237 1240
1238 1241
@@ -1244,37 +1247,37 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg)
1244 * @param ego an ego known to identity service, or NULL 1247 * @param ego an ego known to identity service, or NULL
1245 */ 1248 */
1246static void 1249static void
1247identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) 1250identity_cb(void *cls, const struct GNUNET_IDENTITY_Ego *ego)
1248{ 1251{
1249 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 1252 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1250 1253
1251 el = NULL; 1254 el = NULL;
1252 if ((NULL != name) && (0 != strchr (name, '.'))) 1255 if ((NULL != name) && (0 != strchr(name, '.')))
1253 { 1256 {
1254 fprintf (stderr, 1257 fprintf(stderr,
1255 _ ("Label `%s' contains `.' which is not allowed\n"), 1258 _("Label `%s' contains `.' which is not allowed\n"),
1256 name); 1259 name);
1257 GNUNET_SCHEDULER_shutdown (); 1260 GNUNET_SCHEDULER_shutdown();
1258 ret = -1; 1261 ret = -1;
1259 return; 1262 return;
1260 } 1263 }
1261 1264
1262 if (NULL == ego) 1265 if (NULL == ego)
1263 {
1264 if (NULL != ego_name)
1265 { 1266 {
1266 fprintf (stderr, 1267 if (NULL != ego_name)
1267 _ ("Ego `%s' not known to identity service\n"), 1268 {
1268 ego_name); 1269 fprintf(stderr,
1270 _("Ego `%s' not known to identity service\n"),
1271 ego_name);
1272 }
1273 GNUNET_SCHEDULER_shutdown();
1274 ret = -1;
1275 return;
1269 } 1276 }
1270 GNUNET_SCHEDULER_shutdown (); 1277 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key(ego);
1271 ret = -1; 1278 GNUNET_free_non_null(ego_name);
1272 return;
1273 }
1274 zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1275 GNUNET_free_non_null (ego_name);
1276 ego_name = NULL; 1279 ego_name = NULL;
1277 run_with_zone_pkey (cfg); 1280 run_with_zone_pkey(cfg);
1278} 1281}
1279 1282
1280 1283
@@ -1289,27 +1292,27 @@ identity_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
1289 * @param name unused 1292 * @param name unused
1290 */ 1293 */
1291static void 1294static void
1292default_ego_cb (void *cls, 1295default_ego_cb(void *cls,
1293 struct GNUNET_IDENTITY_Ego *ego, 1296 struct GNUNET_IDENTITY_Ego *ego,
1294 void **ctx, 1297 void **ctx,
1295 const char *name) 1298 const char *name)
1296{ 1299{
1297 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 1300 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1298 1301
1299 (void) ctx; 1302 (void)ctx;
1300 (void) name; 1303 (void)name;
1301 get_default = NULL; 1304 get_default = NULL;
1302 if (NULL == ego) 1305 if (NULL == ego)
1303 { 1306 {
1304 fprintf (stderr, _ ("No default ego configured in identity service\n")); 1307 fprintf(stderr, _("No default ego configured in identity service\n"));
1305 GNUNET_SCHEDULER_shutdown (); 1308 GNUNET_SCHEDULER_shutdown();
1306 ret = -1; 1309 ret = -1;
1307 return; 1310 return;
1308 } 1311 }
1309 else 1312 else
1310 { 1313 {
1311 identity_cb ((void *) cfg, ego); 1314 identity_cb((void *)cfg, ego);
1312 } 1315 }
1313} 1316}
1314 1317
1315 1318
@@ -1326,19 +1329,19 @@ default_ego_cb (void *cls,
1326 * @param name name associated with @a ego 1329 * @param name name associated with @a ego
1327 */ 1330 */
1328static void 1331static void
1329id_connect_cb (void *cls, 1332id_connect_cb(void *cls,
1330 struct GNUNET_IDENTITY_Ego *ego, 1333 struct GNUNET_IDENTITY_Ego *ego,
1331 void **ctx, 1334 void **ctx,
1332 const char *name) 1335 const char *name)
1333{ 1336{
1334 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 1337 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1335 1338
1336 (void) ctx; 1339 (void)ctx;
1337 (void) name; 1340 (void)name;
1338 if (NULL != ego) 1341 if (NULL != ego)
1339 return; 1342 return;
1340 get_default = 1343 get_default =
1341 GNUNET_IDENTITY_get (idh, "namestore", &default_ego_cb, (void *) cfg); 1344 GNUNET_IDENTITY_get(idh, "namestore", &default_ego_cb, (void *)cfg);
1342} 1345}
1343 1346
1344 1347
@@ -1351,53 +1354,53 @@ id_connect_cb (void *cls,
1351 * @param cfg configuration 1354 * @param cfg configuration
1352 */ 1355 */
1353static void 1356static void
1354run (void *cls, 1357run(void *cls,
1355 char *const *args, 1358 char *const *args,
1356 const char *cfgfile, 1359 const char *cfgfile,
1357 const struct GNUNET_CONFIGURATION_Handle *cfg) 1360 const struct GNUNET_CONFIGURATION_Handle *cfg)
1358{ 1361{
1359 const char *pkey_str; 1362 const char *pkey_str;
1360 1363
1361 (void) cls; 1364 (void)cls;
1362 (void) args; 1365 (void)args;
1363 (void) cfgfile; 1366 (void)cfgfile;
1364 if (NULL != args[0]) 1367 if (NULL != args[0])
1365 GNUNET_log ( 1368 GNUNET_log(
1366 GNUNET_ERROR_TYPE_WARNING, 1369 GNUNET_ERROR_TYPE_WARNING,
1367 _ ("Superfluous command line arguments (starting with `%s') ignored\n"), 1370 _("Superfluous command line arguments (starting with `%s') ignored\n"),
1368 args[0]); 1371 args[0]);
1369 if ((NULL != args[0]) && (NULL == uri)) 1372 if ((NULL != args[0]) && (NULL == uri))
1370 uri = GNUNET_strdup (args[0]); 1373 uri = GNUNET_strdup(args[0]);
1371 1374
1372 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg); 1375 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, (void *)cfg);
1373 pkey_str = getenv ("GNUNET_NAMESTORE_EGO_PRIVATE_KEY"); 1376 pkey_str = getenv("GNUNET_NAMESTORE_EGO_PRIVATE_KEY");
1374 if (NULL != pkey_str) 1377 if (NULL != pkey_str)
1375 {
1376 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (pkey_str,
1377 strlen (pkey_str),
1378 &zone_pkey,
1379 sizeof (zone_pkey)))
1380 { 1378 {
1381 fprintf (stderr, 1379 if (GNUNET_OK != GNUNET_STRINGS_string_to_data(pkey_str,
1382 "Malformed private key `%s' in $%s\n", 1380 strlen(pkey_str),
1383 pkey_str, 1381 &zone_pkey,
1384 "GNUNET_NAMESTORE_EGO_PRIVATE_KEY"); 1382 sizeof(zone_pkey)))
1385 ret = 1; 1383 {
1386 GNUNET_SCHEDULER_shutdown (); 1384 fprintf(stderr,
1385 "Malformed private key `%s' in $%s\n",
1386 pkey_str,
1387 "GNUNET_NAMESTORE_EGO_PRIVATE_KEY");
1388 ret = 1;
1389 GNUNET_SCHEDULER_shutdown();
1390 return;
1391 }
1392 run_with_zone_pkey(cfg);
1387 return; 1393 return;
1388 } 1394 }
1389 run_with_zone_pkey (cfg);
1390 return;
1391 }
1392 if (NULL == ego_name) 1395 if (NULL == ego_name)
1393 { 1396 {
1394 idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg); 1397 idh = GNUNET_IDENTITY_connect(cfg, &id_connect_cb, (void *)cfg);
1395 if (NULL == idh) 1398 if (NULL == idh)
1396 fprintf (stderr, _ ("Cannot connect to identity service\n")); 1399 fprintf(stderr, _("Cannot connect to identity service\n"));
1397 ret = -1; 1400 ret = -1;
1398 return; 1401 return;
1399 } 1402 }
1400 el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); 1403 el = GNUNET_IDENTITY_ego_lookup(cfg, ego_name, &identity_cb, (void *)cfg);
1401} 1404}
1402 1405
1403 1406
@@ -1419,10 +1422,10 @@ run (void *cls,
1419 * @return #GNUNET_OK on success 1422 * @return #GNUNET_OK on success
1420 */ 1423 */
1421static int 1424static int
1422multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 1425multirecord_process(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1423 void *scls, 1426 void *scls,
1424 const char *option, 1427 const char *option,
1425 const char *value) 1428 const char *value)
1426{ 1429{
1427 struct RecordSetEntry **head = scls; 1430 struct RecordSetEntry **head = scls;
1428 struct RecordSetEntry *r; 1431 struct RecordSetEntry *r;
@@ -1433,94 +1436,94 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1433 int etime_is_rel; 1436 int etime_is_rel;
1434 void *raw_data; 1437 void *raw_data;
1435 1438
1436 (void) ctx; 1439 (void)ctx;
1437 (void) option; 1440 (void)option;
1438 cp = GNUNET_strdup (value); 1441 cp = GNUNET_strdup(value);
1439 tok = strtok_r (cp, " ", &saveptr); 1442 tok = strtok_r(cp, " ", &saveptr);
1440 if (NULL == tok) 1443 if (NULL == tok)
1441 { 1444 {
1442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1445 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1443 _ ("Empty record line argument is not allowed.\n")); 1446 _("Empty record line argument is not allowed.\n"));
1444 GNUNET_free (cp); 1447 GNUNET_free(cp);
1445 return GNUNET_SYSERR; 1448 return GNUNET_SYSERR;
1446 } 1449 }
1447 { 1450 {
1448 char *etime_in_s; 1451 char *etime_in_s;
1449 1452
1450 GNUNET_asprintf (&etime_in_s, "%s s", tok); 1453 GNUNET_asprintf(&etime_in_s, "%s s", tok);
1451 if (GNUNET_OK != 1454 if (GNUNET_OK !=
1452 parse_expiration (etime_in_s, &etime_is_rel, &record.expiration_time)) 1455 parse_expiration(etime_in_s, &etime_is_rel, &record.expiration_time))
1456 {
1457 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1458 _("Invalid expiration time `%s' (must be without unit)\n"),
1459 tok);
1460 GNUNET_free(cp);
1461 GNUNET_free(etime_in_s);
1462 return GNUNET_SYSERR;
1463 }
1464 GNUNET_free(etime_in_s);
1465 }
1466 tok = strtok_r(NULL, " ", &saveptr);
1467 if (NULL == tok)
1453 { 1468 {
1454 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1469 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1455 _ ("Invalid expiration time `%s' (must be without unit)\n"), 1470 _("Missing entries in record line `%s'.\n"),
1456 tok); 1471 value);
1457 GNUNET_free (cp); 1472 GNUNET_free(cp);
1458 GNUNET_free (etime_in_s);
1459 return GNUNET_SYSERR; 1473 return GNUNET_SYSERR;
1460 } 1474 }
1461 GNUNET_free (etime_in_s); 1475 record.record_type = GNUNET_GNSRECORD_typename_to_number(tok);
1462 }
1463 tok = strtok_r (NULL, " ", &saveptr);
1464 if (NULL == tok)
1465 {
1466 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1467 _ ("Missing entries in record line `%s'.\n"),
1468 value);
1469 GNUNET_free (cp);
1470 return GNUNET_SYSERR;
1471 }
1472 record.record_type = GNUNET_GNSRECORD_typename_to_number (tok);
1473 if (UINT32_MAX == record.record_type) 1476 if (UINT32_MAX == record.record_type)
1474 { 1477 {
1475 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unknown record type `%s'\n"), tok); 1478 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Unknown record type `%s'\n"), tok);
1476 GNUNET_free (cp); 1479 GNUNET_free(cp);
1477 return GNUNET_SYSERR; 1480 return GNUNET_SYSERR;
1478 } 1481 }
1479 tok = strtok_r (NULL, " ", &saveptr); 1482 tok = strtok_r(NULL, " ", &saveptr);
1480 if (NULL == tok) 1483 if (NULL == tok)
1481 { 1484 {
1482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1485 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1483 _ ("Missing entries in record line `%s'.\n"), 1486 _("Missing entries in record line `%s'.\n"),
1484 value); 1487 value);
1485 GNUNET_free (cp); 1488 GNUNET_free(cp);
1486 return GNUNET_SYSERR; 1489 return GNUNET_SYSERR;
1487 } 1490 }
1488 record.flags = GNUNET_GNSRECORD_RF_NONE; 1491 record.flags = GNUNET_GNSRECORD_RF_NONE;
1489 if (etime_is_rel) 1492 if (etime_is_rel)
1490 record.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1493 record.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1491 if (NULL == strchr (tok, (unsigned char) 'p')) /* p = public */ 1494 if (NULL == strchr(tok, (unsigned char)'p')) /* p = public */
1492 record.flags |= GNUNET_GNSRECORD_RF_PRIVATE; 1495 record.flags |= GNUNET_GNSRECORD_RF_PRIVATE;
1493 if (NULL != strchr (tok, (unsigned char) 's')) 1496 if (NULL != strchr(tok, (unsigned char)'s'))
1494 record.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; 1497 record.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
1495 /* find beginning of record value */ 1498 /* find beginning of record value */
1496 tok = strchr (&value[tok - cp], (unsigned char) ' '); 1499 tok = strchr(&value[tok - cp], (unsigned char)' ');
1497 if (NULL == tok) 1500 if (NULL == tok)
1498 { 1501 {
1499 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1502 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1500 _ ("Missing entries in record line `%s'.\n"), 1503 _("Missing entries in record line `%s'.\n"),
1501 value); 1504 value);
1502 GNUNET_free (cp); 1505 GNUNET_free(cp);
1503 return GNUNET_SYSERR; 1506 return GNUNET_SYSERR;
1504 } 1507 }
1505 GNUNET_free (cp); 1508 GNUNET_free(cp);
1506 tok++; /* skip space */ 1509 tok++; /* skip space */
1507 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record.record_type, 1510 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value(record.record_type,
1508 tok, 1511 tok,
1509 &raw_data, 1512 &raw_data,
1510 &record.data_size)) 1513 &record.data_size))
1511 { 1514 {
1512 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1515 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1513 _ ("Invalid record data for type %s: `%s'.\n"), 1516 _("Invalid record data for type %s: `%s'.\n"),
1514 GNUNET_GNSRECORD_number_to_typename (record.record_type), 1517 GNUNET_GNSRECORD_number_to_typename(record.record_type),
1515 tok); 1518 tok);
1516 return GNUNET_SYSERR; 1519 return GNUNET_SYSERR;
1517 } 1520 }
1518 1521
1519 r = GNUNET_malloc (sizeof (struct RecordSetEntry) + record.data_size); 1522 r = GNUNET_malloc(sizeof(struct RecordSetEntry) + record.data_size);
1520 r->next = *head; 1523 r->next = *head;
1521 record.data = &r[1]; 1524 record.data = &r[1];
1522 memcpy (&r[1], raw_data, record.data_size); 1525 memcpy(&r[1], raw_data, record.data_size);
1523 GNUNET_free (raw_data); 1526 GNUNET_free(raw_data);
1524 r->record = record; 1527 r->record = record;
1525 *head = r; 1528 *head = r;
1526 return GNUNET_OK; 1529 return GNUNET_OK;
@@ -1537,20 +1540,20 @@ multirecord_process (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
1537 * @param[out] topKeywords set to the desired value 1540 * @param[out] topKeywords set to the desired value
1538 */ 1541 */
1539struct GNUNET_GETOPT_CommandLineOption 1542struct GNUNET_GETOPT_CommandLineOption
1540multirecord_option (char shortName, 1543multirecord_option(char shortName,
1541 const char *name, 1544 const char *name,
1542 const char *argumentHelp, 1545 const char *argumentHelp,
1543 const char *description, 1546 const char *description,
1544 struct RecordSetEntry **rs) 1547 struct RecordSetEntry **rs)
1545{ 1548{
1546 struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, 1549 struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName,
1547 .name = name, 1550 .name = name,
1548 .argumentHelp = argumentHelp, 1551 .argumentHelp = argumentHelp,
1549 .description = description, 1552 .description = description,
1550 .require_argument = 1, 1553 .require_argument = 1,
1551 .processor = 1554 .processor =
1552 &multirecord_process, 1555 &multirecord_process,
1553 .scls = (void *) rs}; 1556 .scls = (void *)rs };
1554 1557
1555 return clo; 1558 return clo;
1556} 1559}
@@ -1564,112 +1567,112 @@ multirecord_option (char shortName,
1564 * @return 0 ok, 1 on error 1567 * @return 0 ok, 1 on error
1565 */ 1568 */
1566int 1569int
1567main (int argc, char *const *argv) 1570main(int argc, char *const *argv)
1568{ 1571{
1569 struct GNUNET_GETOPT_CommandLineOption options[] = 1572 struct GNUNET_GETOPT_CommandLineOption options[] =
1570 {GNUNET_GETOPT_option_flag ('a', "add", gettext_noop ("add record"), &add), 1573 { GNUNET_GETOPT_option_flag('a', "add", gettext_noop("add record"), &add),
1571 GNUNET_GETOPT_option_flag ('d', 1574 GNUNET_GETOPT_option_flag('d',
1572 "delete", 1575 "delete",
1573 gettext_noop ("delete record"), 1576 gettext_noop("delete record"),
1574 &del), 1577 &del),
1575 GNUNET_GETOPT_option_flag ('D', 1578 GNUNET_GETOPT_option_flag('D',
1576 "display", 1579 "display",
1577 gettext_noop ("display records"), 1580 gettext_noop("display records"),
1578 &list), 1581 &list),
1579 GNUNET_GETOPT_option_string ( 1582 GNUNET_GETOPT_option_string(
1580 'e', 1583 'e',
1581 "expiration", 1584 "expiration",
1582 "TIME", 1585 "TIME",
1583 gettext_noop ( 1586 gettext_noop(
1584 "expiration time for record to use (for adding only), \"never\" is possible"), 1587 "expiration time for record to use (for adding only), \"never\" is possible"),
1585 &expirationstring), 1588 &expirationstring),
1586 GNUNET_GETOPT_option_string ('i', 1589 GNUNET_GETOPT_option_string('i',
1587 "nick", 1590 "nick",
1588 "NICKNAME", 1591 "NICKNAME",
1589 gettext_noop ( 1592 gettext_noop(
1590 "set the desired nick name for the zone"), 1593 "set the desired nick name for the zone"),
1591 &nickstring), 1594 &nickstring),
1592 GNUNET_GETOPT_option_flag ('m', 1595 GNUNET_GETOPT_option_flag('m',
1593 "monitor", 1596 "monitor",
1594 gettext_noop ( 1597 gettext_noop(
1595 "monitor changes in the namestore"), 1598 "monitor changes in the namestore"),
1596 &monitor), 1599 &monitor),
1597 GNUNET_GETOPT_option_string ('n', 1600 GNUNET_GETOPT_option_string('n',
1598 "name", 1601 "name",
1599 "NAME", 1602 "NAME",
1600 gettext_noop ( 1603 gettext_noop(
1601 "name of the record to add/delete/display"), 1604 "name of the record to add/delete/display"),
1602 &name), 1605 &name),
1603 GNUNET_GETOPT_option_string ('r', 1606 GNUNET_GETOPT_option_string('r',
1604 "reverse", 1607 "reverse",
1605 "PKEY", 1608 "PKEY",
1606 gettext_noop ( 1609 gettext_noop(
1607 "determine our name for the given PKEY"), 1610 "determine our name for the given PKEY"),
1608 &reverse_pkey), 1611 &reverse_pkey),
1609 multirecord_option ( 1612 multirecord_option(
1610 'R', 1613 'R',
1611 "replace", 1614 "replace",
1612 "RECORDLINE", 1615 "RECORDLINE",
1613 gettext_noop ( 1616 gettext_noop(
1614 "set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"), 1617 "set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"),
1615 &recordset), 1618 &recordset),
1616 GNUNET_GETOPT_option_string ('t', 1619 GNUNET_GETOPT_option_string('t',
1617 "type", 1620 "type",
1618 "TYPE", 1621 "TYPE",
1619 gettext_noop ( 1622 gettext_noop(
1620 "type of the record to add/delete/display"), 1623 "type of the record to add/delete/display"),
1621 &typestring), 1624 &typestring),
1622 GNUNET_GETOPT_option_string ('u', 1625 GNUNET_GETOPT_option_string('u',
1623 "uri", 1626 "uri",
1624 "URI", 1627 "URI",
1625 gettext_noop ("URI to import into our zone"), 1628 gettext_noop("URI to import into our zone"),
1626 &uri), 1629 &uri),
1627 GNUNET_GETOPT_option_string ('V', 1630 GNUNET_GETOPT_option_string('V',
1628 "value", 1631 "value",
1629 "VALUE", 1632 "VALUE",
1630 gettext_noop ( 1633 gettext_noop(
1631 "value of the record to add/delete"), 1634 "value of the record to add/delete"),
1632 &value), 1635 &value),
1633 GNUNET_GETOPT_option_flag ('p', 1636 GNUNET_GETOPT_option_flag('p',
1634 "public", 1637 "public",
1635 gettext_noop ("create or list public record"), 1638 gettext_noop("create or list public record"),
1636 &is_public), 1639 &is_public),
1637 GNUNET_GETOPT_option_flag ( 1640 GNUNET_GETOPT_option_flag(
1638 's', 1641 's',
1639 "shadow", 1642 "shadow",
1640 gettext_noop ( 1643 gettext_noop(
1641 "create shadow record (only valid if all other records of the same type have expired"), 1644 "create shadow record (only valid if all other records of the same type have expired"),
1642 &is_shadow), 1645 &is_shadow),
1643 GNUNET_GETOPT_option_string ('z', 1646 GNUNET_GETOPT_option_string('z',
1644 "zone", 1647 "zone",
1645 "EGO", 1648 "EGO",
1646 gettext_noop ( 1649 gettext_noop(
1647 "name of the ego controlling the zone"), 1650 "name of the ego controlling the zone"),
1648 &ego_name), 1651 &ego_name),
1649 GNUNET_GETOPT_OPTION_END}; 1652 GNUNET_GETOPT_OPTION_END };
1650 int lret; 1653 int lret;
1651 1654
1652 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1655 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1653 return 2; 1656 return 2;
1654 1657
1655 is_public = -1; 1658 is_public = -1;
1656 is_shadow = -1; 1659 is_shadow = -1;
1657 GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL); 1660 GNUNET_log_setup("gnunet-namestore", "WARNING", NULL);
1658 if (GNUNET_OK != 1661 if (GNUNET_OK !=
1659 (lret = GNUNET_PROGRAM_run (argc, 1662 (lret = GNUNET_PROGRAM_run(argc,
1660 argv, 1663 argv,
1661 "gnunet-namestore", 1664 "gnunet-namestore",
1662 _ ("GNUnet zone manipulation tool"), 1665 _("GNUnet zone manipulation tool"),
1663 options, 1666 options,
1664 &run, 1667 &run,
1665 NULL))) 1668 NULL)))
1666 { 1669 {
1667 GNUNET_free ((void *) argv); 1670 GNUNET_free((void *)argv);
1668 GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); 1671 GNUNET_CRYPTO_ecdsa_key_clear(&zone_pkey);
1669 return lret; 1672 return lret;
1670 } 1673 }
1671 GNUNET_free ((void *) argv); 1674 GNUNET_free((void *)argv);
1672 GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); 1675 GNUNET_CRYPTO_ecdsa_key_clear(&zone_pkey);
1673 return ret; 1676 return ret;
1674} 1677}
1675 1678
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 3a925b952..71754081e 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file namestore/gnunet-service-namestore.c 22 * @file namestore/gnunet-service-namestore.c
@@ -36,7 +36,7 @@
36#include "namestore.h" 36#include "namestore.h"
37 37
38#define LOG_STRERROR_FILE(kind, syscall, filename) \ 38#define LOG_STRERROR_FILE(kind, syscall, filename) \
39 GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 39 GNUNET_log_from_strerror_file(kind, "util", syscall, filename)
40 40
41/** 41/**
42 * If a monitor takes more than 1 minute to process an event, print a warning. 42 * If a monitor takes more than 1 minute to process an event, print a warning.
@@ -57,8 +57,7 @@ struct NamestoreClient;
57/** 57/**
58 * A namestore iteration operation. 58 * A namestore iteration operation.
59 */ 59 */
60struct ZoneIteration 60struct ZoneIteration {
61{
62 /** 61 /**
63 * Next element in the DLL 62 * Next element in the DLL
64 */ 63 */
@@ -125,9 +124,7 @@ struct ZoneIteration
125/** 124/**
126 * A namestore client 125 * A namestore client
127 */ 126 */
128struct NamestoreClient 127struct NamestoreClient {
129{
130
131 /** 128 /**
132 * The client 129 * The client
133 */ 130 */
@@ -155,8 +152,7 @@ struct NamestoreClient
155/** 152/**
156 * A namestore monitor. 153 * A namestore monitor.
157 */ 154 */
158struct ZoneMonitor 155struct ZoneMonitor {
159{
160 /** 156 /**
161 * Next element in the DLL 157 * Next element in the DLL
162 */ 158 */
@@ -233,9 +229,7 @@ struct ZoneMonitor
233/** 229/**
234 * Pending operation on the namecache. 230 * Pending operation on the namecache.
235 */ 231 */
236struct CacheOperation 232struct CacheOperation {
237{
238
239 /** 233 /**
240 * Kept in a DLL. 234 * Kept in a DLL.
241 */ 235 */
@@ -273,8 +267,7 @@ struct CacheOperation
273 * Information for an ongoing #handle_record_store() operation. 267 * Information for an ongoing #handle_record_store() operation.
274 * Needed as we may wait for monitors to be ready for the notification. 268 * Needed as we may wait for monitors to be ready for the notification.
275 */ 269 */
276struct StoreActivity 270struct StoreActivity {
277{
278 /** 271 /**
279 * Kept in a DLL. 272 * Kept in a DLL.
280 */ 273 */
@@ -311,8 +304,7 @@ struct StoreActivity
311/** 304/**
312 * Entry in list of cached nick resolutions. 305 * Entry in list of cached nick resolutions.
313 */ 306 */
314struct NickCache 307struct NickCache {
315{
316 /** 308 /**
317 * Zone the cache entry is for. 309 * Zone the cache entry is for.
318 */ 310 */
@@ -419,38 +411,38 @@ static int disable_namecache;
419 * @param cls unused 411 * @param cls unused
420 */ 412 */
421static void 413static void
422cleanup_task (void *cls) 414cleanup_task(void *cls)
423{ 415{
424 struct CacheOperation *cop; 416 struct CacheOperation *cop;
425 417
426 (void) cls; 418 (void)cls;
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); 419 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
428 while (NULL != (cop = cop_head)) 420 while (NULL != (cop = cop_head))
429 { 421 {
430 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 422 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
431 "Aborting incomplete namecache operation\n"); 423 "Aborting incomplete namecache operation\n");
432 GNUNET_NAMECACHE_cancel (cop->qe); 424 GNUNET_NAMECACHE_cancel(cop->qe);
433 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); 425 GNUNET_CONTAINER_DLL_remove(cop_head, cop_tail, cop);
434 GNUNET_free (cop); 426 GNUNET_free(cop);
435 } 427 }
436 if (NULL != namecache) 428 if (NULL != namecache)
437 { 429 {
438 GNUNET_NAMECACHE_disconnect (namecache); 430 GNUNET_NAMECACHE_disconnect(namecache);
439 namecache = NULL; 431 namecache = NULL;
440 } 432 }
441 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); 433 GNUNET_break(NULL == GNUNET_PLUGIN_unload(db_lib_name, GSN_database));
442 GNUNET_free (db_lib_name); 434 GNUNET_free(db_lib_name);
443 db_lib_name = NULL; 435 db_lib_name = NULL;
444 if (NULL != monitor_nc) 436 if (NULL != monitor_nc)
445 { 437 {
446 GNUNET_notification_context_destroy (monitor_nc); 438 GNUNET_notification_context_destroy(monitor_nc);
447 monitor_nc = NULL; 439 monitor_nc = NULL;
448 } 440 }
449 if (NULL != statistics) 441 if (NULL != statistics)
450 { 442 {
451 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); 443 GNUNET_STATISTICS_destroy(statistics, GNUNET_NO);
452 statistics = NULL; 444 statistics = NULL;
453 } 445 }
454} 446}
455 447
456 448
@@ -460,11 +452,11 @@ cleanup_task (void *cls)
460 * @param sa activity to free 452 * @param sa activity to free
461 */ 453 */
462static void 454static void
463free_store_activity (struct StoreActivity *sa) 455free_store_activity(struct StoreActivity *sa)
464{ 456{
465 GNUNET_CONTAINER_DLL_remove (sa_head, sa_tail, sa); 457 GNUNET_CONTAINER_DLL_remove(sa_head, sa_tail, sa);
466 GNUNET_free (sa->conv_name); 458 GNUNET_free(sa->conv_name);
467 GNUNET_free (sa); 459 GNUNET_free(sa);
468} 460}
469 461
470 462
@@ -481,37 +473,37 @@ free_store_activity (struct StoreActivity *sa)
481 * @param rd records stored under @a label in the zone 473 * @param rd records stored under @a label in the zone
482 */ 474 */
483static void 475static void
484lookup_nick_it (void *cls, 476lookup_nick_it(void *cls,
485 uint64_t seq, 477 uint64_t seq,
486 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, 478 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
487 const char *label, 479 const char *label,
488 unsigned int rd_count, 480 unsigned int rd_count,
489 const struct GNUNET_GNSRECORD_Data *rd) 481 const struct GNUNET_GNSRECORD_Data *rd)
490{ 482{
491 struct GNUNET_GNSRECORD_Data **res = cls; 483 struct GNUNET_GNSRECORD_Data **res = cls;
492 484
493 (void) private_key; 485 (void)private_key;
494 GNUNET_assert (0 != seq); 486 GNUNET_assert(0 != seq);
495 if (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT)) 487 if (0 != strcmp(label, GNUNET_GNS_EMPTY_LABEL_AT))
496 {
497 GNUNET_break (0);
498 return;
499 }
500 for (unsigned int c = 0; c < rd_count; c++)
501 {
502 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
503 { 488 {
504 (*res) = 489 GNUNET_break(0);
505 GNUNET_malloc (rd[c].data_size + sizeof (struct GNUNET_GNSRECORD_Data));
506 (*res)->data = &(*res)[1];
507 GNUNET_memcpy ((void *) (*res)->data, rd[c].data, rd[c].data_size);
508 (*res)->data_size = rd[c].data_size;
509 (*res)->expiration_time = rd[c].expiration_time;
510 (*res)->flags = rd[c].flags;
511 (*res)->record_type = GNUNET_GNSRECORD_TYPE_NICK;
512 return; 490 return;
513 } 491 }
514 } 492 for (unsigned int c = 0; c < rd_count; c++)
493 {
494 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
495 {
496 (*res) =
497 GNUNET_malloc(rd[c].data_size + sizeof(struct GNUNET_GNSRECORD_Data));
498 (*res)->data = &(*res)[1];
499 GNUNET_memcpy((void *)(*res)->data, rd[c].data, rd[c].data_size);
500 (*res)->data_size = rd[c].data_size;
501 (*res)->expiration_time = rd[c].expiration_time;
502 (*res)->flags = rd[c].flags;
503 (*res)->record_type = GNUNET_GNSRECORD_TYPE_NICK;
504 return;
505 }
506 }
515 (*res) = NULL; 507 (*res) = NULL;
516} 508}
517 509
@@ -523,39 +515,39 @@ lookup_nick_it (void *cls,
523 * @param nick nick entry to cache 515 * @param nick nick entry to cache
524 */ 516 */
525static void 517static void
526cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 518cache_nick(const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
527 const struct GNUNET_GNSRECORD_Data *nick) 519 const struct GNUNET_GNSRECORD_Data *nick)
528{ 520{
529 struct NickCache *oldest; 521 struct NickCache *oldest;
530 522
531 oldest = NULL; 523 oldest = NULL;
532 for (unsigned int i = 0; i < NC_SIZE; i++) 524 for (unsigned int i = 0; i < NC_SIZE; i++)
533 {
534 struct NickCache *pos = &nick_cache[i];
535
536 if ((NULL == oldest) ||
537 (oldest->last_used.abs_value_us > pos->last_used.abs_value_us))
538 oldest = pos;
539 if (0 == GNUNET_memcmp (zone, &pos->zone))
540 { 525 {
541 oldest = pos; 526 struct NickCache *pos = &nick_cache[i];
542 break; 527
528 if ((NULL == oldest) ||
529 (oldest->last_used.abs_value_us > pos->last_used.abs_value_us))
530 oldest = pos;
531 if (0 == GNUNET_memcmp(zone, &pos->zone))
532 {
533 oldest = pos;
534 break;
535 }
543 } 536 }
544 } 537 GNUNET_free_non_null(oldest->rd);
545 GNUNET_free_non_null (oldest->rd);
546 oldest->zone = *zone; 538 oldest->zone = *zone;
547 if (NULL != nick) 539 if (NULL != nick)
548 { 540 {
549 oldest->rd = GNUNET_malloc (sizeof (*nick) + nick->data_size); 541 oldest->rd = GNUNET_malloc(sizeof(*nick) + nick->data_size);
550 *oldest->rd = *nick; 542 *oldest->rd = *nick;
551 oldest->rd->data = &oldest->rd[1]; 543 oldest->rd->data = &oldest->rd[1];
552 memcpy (&oldest->rd[1], nick->data, nick->data_size); 544 memcpy(&oldest->rd[1], nick->data, nick->data_size);
553 } 545 }
554 else 546 else
555 { 547 {
556 oldest->rd = NULL; 548 oldest->rd = NULL;
557 } 549 }
558 oldest->last_used = GNUNET_TIME_absolute_get (); 550 oldest->last_used = GNUNET_TIME_absolute_get();
559} 551}
560 552
561 553
@@ -566,7 +558,7 @@ cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
566 * @return NULL if no NICK record was found 558 * @return NULL if no NICK record was found
567 */ 559 */
568static struct GNUNET_GNSRECORD_Data * 560static struct GNUNET_GNSRECORD_Data *
569get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) 561get_nick_record(const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
570{ 562{
571 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 563 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
572 struct GNUNET_GNSRECORD_Data *nick; 564 struct GNUNET_GNSRECORD_Data *nick;
@@ -574,53 +566,53 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
574 566
575 /* check cache first */ 567 /* check cache first */
576 for (unsigned int i = 0; i < NC_SIZE; i++) 568 for (unsigned int i = 0; i < NC_SIZE; i++)
577 {
578 struct NickCache *pos = &nick_cache[i];
579 if ((NULL != pos->rd) && (0 == GNUNET_memcmp (zone, &pos->zone)))
580 { 569 {
581 if (NULL == pos->rd) 570 struct NickCache *pos = &nick_cache[i];
582 return NULL; 571 if ((NULL != pos->rd) && (0 == GNUNET_memcmp(zone, &pos->zone)))
583 nick = GNUNET_malloc (sizeof (*nick) + pos->rd->data_size); 572 {
584 *nick = *pos->rd; 573 if (NULL == pos->rd)
585 nick->data = &nick[1]; 574 return NULL;
586 memcpy (&nick[1], pos->rd->data, pos->rd->data_size); 575 nick = GNUNET_malloc(sizeof(*nick) + pos->rd->data_size);
587 pos->last_used = GNUNET_TIME_absolute_get (); 576 *nick = *pos->rd;
588 return nick; 577 nick->data = &nick[1];
578 memcpy(&nick[1], pos->rd->data, pos->rd->data_size);
579 pos->last_used = GNUNET_TIME_absolute_get();
580 return nick;
581 }
589 } 582 }
590 }
591 583
592 nick = NULL; 584 nick = NULL;
593 res = GSN_database->lookup_records (GSN_database->cls, 585 res = GSN_database->lookup_records(GSN_database->cls,
594 zone, 586 zone,
595 GNUNET_GNS_EMPTY_LABEL_AT, 587 GNUNET_GNS_EMPTY_LABEL_AT,
596 &lookup_nick_it, 588 &lookup_nick_it,
597 &nick); 589 &nick);
598 if ((GNUNET_OK != res) || (NULL == nick)) 590 if ((GNUNET_OK != res) || (NULL == nick))
599 {
600#if ! defined(GNUNET_CULL_LOGGING)
601 static int do_log = GNUNET_LOG_CALL_STATUS;
602
603 if (0 == do_log)
604 do_log = GNUNET_get_log_call_status (GNUNET_ERROR_TYPE_DEBUG,
605 "namestore",
606 __FILE__,
607 __FUNCTION__,
608 __LINE__);
609 if (1 == do_log)
610 { 591 {
611 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); 592#if !defined(GNUNET_CULL_LOGGING)
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 593 static int do_log = GNUNET_LOG_CALL_STATUS;
613 "No nick name set for zone `%s'\n", 594
614 GNUNET_GNSRECORD_z2s (&pub)); 595 if (0 == do_log)
615 } 596 do_log = GNUNET_get_log_call_status(GNUNET_ERROR_TYPE_DEBUG,
597 "namestore",
598 __FILE__,
599 __FUNCTION__,
600 __LINE__);
601 if (1 == do_log)
602 {
603 GNUNET_CRYPTO_ecdsa_key_get_public(zone, &pub);
604 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
605 "No nick name set for zone `%s'\n",
606 GNUNET_GNSRECORD_z2s(&pub));
607 }
616#endif 608#endif
617 /* update cache */ 609 /* update cache */
618 cache_nick (zone, NULL); 610 cache_nick(zone, NULL);
619 return NULL; 611 return NULL;
620 } 612 }
621 613
622 /* update cache */ 614 /* update cache */
623 cache_nick (zone, nick); 615 cache_nick(zone, nick);
624 return nick; 616 return nick;
625} 617}
626 618
@@ -641,11 +633,11 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
641 * allocated in the same chunk of memory! 633 * allocated in the same chunk of memory!
642 */ 634 */
643static void 635static void
644merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, 636merge_with_nick_records(const struct GNUNET_GNSRECORD_Data *nick_rd,
645 unsigned int rd2_length, 637 unsigned int rd2_length,
646 const struct GNUNET_GNSRECORD_Data *rd2, 638 const struct GNUNET_GNSRECORD_Data *rd2,
647 unsigned int *rdc_res, 639 unsigned int *rdc_res,
648 struct GNUNET_GNSRECORD_Data **rd_res) 640 struct GNUNET_GNSRECORD_Data **rd_res)
649{ 641{
650 uint64_t latest_expiration; 642 uint64_t latest_expiration;
651 size_t req; 643 size_t req;
@@ -655,54 +647,54 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
655 647
656 (*rdc_res) = 1 + rd2_length; 648 (*rdc_res) = 1 + rd2_length;
657 if (0 == 1 + rd2_length) 649 if (0 == 1 + rd2_length)
658 {
659 GNUNET_break (0);
660 (*rd_res) = NULL;
661 return;
662 }
663 req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size;
664 for (unsigned int i = 0; i < rd2_length; i++)
665 {
666 const struct GNUNET_GNSRECORD_Data *orig = &rd2[i];
667
668 if (req + sizeof (struct GNUNET_GNSRECORD_Data) + orig->data_size < req)
669 { 650 {
670 GNUNET_break (0); 651 GNUNET_break(0);
671 (*rd_res) = NULL; 652 (*rd_res) = NULL;
672 return; 653 return;
673 } 654 }
674 req += sizeof (struct GNUNET_GNSRECORD_Data) + orig->data_size; 655 req = sizeof(struct GNUNET_GNSRECORD_Data) + nick_rd->data_size;
675 } 656 for (unsigned int i = 0; i < rd2_length; i++)
676 target = GNUNET_malloc (req); 657 {
658 const struct GNUNET_GNSRECORD_Data *orig = &rd2[i];
659
660 if (req + sizeof(struct GNUNET_GNSRECORD_Data) + orig->data_size < req)
661 {
662 GNUNET_break(0);
663 (*rd_res) = NULL;
664 return;
665 }
666 req += sizeof(struct GNUNET_GNSRECORD_Data) + orig->data_size;
667 }
668 target = GNUNET_malloc(req);
677 (*rd_res) = target; 669 (*rd_res) = target;
678 data = (char *) &target[1 + rd2_length]; 670 data = (char *)&target[1 + rd2_length];
679 data_offset = 0; 671 data_offset = 0;
680 latest_expiration = 0; 672 latest_expiration = 0;
681 for (unsigned int i = 0; i < rd2_length; i++) 673 for (unsigned int i = 0; i < rd2_length; i++)
682 {
683 const struct GNUNET_GNSRECORD_Data *orig = &rd2[i];
684
685 if (0 != (orig->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
686 { 674 {
687 if ((GNUNET_TIME_absolute_get ().abs_value_us + orig->expiration_time) > 675 const struct GNUNET_GNSRECORD_Data *orig = &rd2[i];
688 latest_expiration) 676
677 if (0 != (orig->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
678 {
679 if ((GNUNET_TIME_absolute_get().abs_value_us + orig->expiration_time) >
680 latest_expiration)
681 latest_expiration = orig->expiration_time;
682 }
683 else if (orig->expiration_time > latest_expiration)
689 latest_expiration = orig->expiration_time; 684 latest_expiration = orig->expiration_time;
685 target[i] = *orig;
686 target[i].data = (void *)&data[data_offset];
687 GNUNET_memcpy(&data[data_offset], orig->data, orig->data_size);
688 data_offset += orig->data_size;
690 } 689 }
691 else if (orig->expiration_time > latest_expiration)
692 latest_expiration = orig->expiration_time;
693 target[i] = *orig;
694 target[i].data = (void *) &data[data_offset];
695 GNUNET_memcpy (&data[data_offset], orig->data, orig->data_size);
696 data_offset += orig->data_size;
697 }
698 /* append nick */ 690 /* append nick */
699 target[rd2_length] = *nick_rd; 691 target[rd2_length] = *nick_rd;
700 target[rd2_length].expiration_time = latest_expiration; 692 target[rd2_length].expiration_time = latest_expiration;
701 target[rd2_length].data = (void *) &data[data_offset]; 693 target[rd2_length].data = (void *)&data[data_offset];
702 GNUNET_memcpy (&data[data_offset], nick_rd->data, nick_rd->data_size); 694 GNUNET_memcpy(&data[data_offset], nick_rd->data, nick_rd->data_size);
703 data_offset += nick_rd->data_size; 695 data_offset += nick_rd->data_size;
704 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + 696 GNUNET_assert(req == (sizeof(struct GNUNET_GNSRECORD_Data)) * (*rdc_res) +
705 data_offset); 697 data_offset);
706} 698}
707 699
708 700
@@ -718,12 +710,12 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
718 * @param rd array of records 710 * @param rd array of records
719 */ 711 */
720static void 712static void
721send_lookup_response (struct NamestoreClient *nc, 713send_lookup_response(struct NamestoreClient *nc,
722 uint32_t request_id, 714 uint32_t request_id,
723 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 715 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
724 const char *name, 716 const char *name,
725 unsigned int rd_count, 717 unsigned int rd_count,
726 const struct GNUNET_GNSRECORD_Data *rd) 718 const struct GNUNET_GNSRECORD_Data *rd)
727{ 719{
728 struct GNUNET_MQ_Envelope *env; 720 struct GNUNET_MQ_Envelope *env;
729 struct RecordResultMessage *zir_msg; 721 struct RecordResultMessage *zir_msg;
@@ -735,63 +727,63 @@ send_lookup_response (struct NamestoreClient *nc,
735 char *name_tmp; 727 char *name_tmp;
736 char *rd_ser; 728 char *rd_ser;
737 729
738 nick = get_nick_record (zone_key); 730 nick = get_nick_record(zone_key);
739 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (rd_count, rd)); 731 GNUNET_assert(-1 != GNUNET_GNSRECORD_records_get_size(rd_count, rd));
740 732
741 if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT))) 733 if ((NULL != nick) && (0 != strcmp(name, GNUNET_GNS_EMPTY_LABEL_AT)))
742 { 734 {
743 nick->flags = 735 nick->flags =
744 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 736 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
745 merge_with_nick_records (nick, rd_count, rd, &res_count, &res); 737 merge_with_nick_records(nick, rd_count, rd, &res_count, &res);
746 GNUNET_free (nick); 738 GNUNET_free(nick);
747 } 739 }
748 else 740 else
749 { 741 {
750 res_count = rd_count; 742 res_count = rd_count;
751 res = (struct GNUNET_GNSRECORD_Data *) rd; 743 res = (struct GNUNET_GNSRECORD_Data *)rd;
752 } 744 }
753 745
754 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (res_count, res)); 746 GNUNET_assert(-1 != GNUNET_GNSRECORD_records_get_size(res_count, res));
755 747
756 748
757 name_len = strlen (name) + 1; 749 name_len = strlen(name) + 1;
758 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); 750 rd_ser_len = GNUNET_GNSRECORD_records_get_size(res_count, res);
759 if (rd_ser_len < 0) 751 if (rd_ser_len < 0)
760 { 752 {
761 GNUNET_break (0); 753 GNUNET_break(0);
762 GNUNET_SERVICE_client_drop (nc->client); 754 GNUNET_SERVICE_client_drop(nc->client);
763 return; 755 return;
764 } 756 }
765 if (((size_t) rd_ser_len) >= UINT16_MAX - name_len - sizeof (*zir_msg)) 757 if (((size_t)rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg))
766 { 758 {
767 GNUNET_break (0); 759 GNUNET_break(0);
768 GNUNET_SERVICE_client_drop (nc->client); 760 GNUNET_SERVICE_client_drop(nc->client);
769 return; 761 return;
770 } 762 }
771 env = GNUNET_MQ_msg_extra (zir_msg, 763 env = GNUNET_MQ_msg_extra(zir_msg,
772 name_len + rd_ser_len, 764 name_len + rd_ser_len,
773 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); 765 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
774 zir_msg->gns_header.r_id = htonl (request_id); 766 zir_msg->gns_header.r_id = htonl(request_id);
775 zir_msg->name_len = htons (name_len); 767 zir_msg->name_len = htons(name_len);
776 zir_msg->rd_count = htons (res_count); 768 zir_msg->rd_count = htons(res_count);
777 zir_msg->rd_len = htons ((uint16_t) rd_ser_len); 769 zir_msg->rd_len = htons((uint16_t)rd_ser_len);
778 zir_msg->private_key = *zone_key; 770 zir_msg->private_key = *zone_key;
779 name_tmp = (char *) &zir_msg[1]; 771 name_tmp = (char *)&zir_msg[1];
780 GNUNET_memcpy (name_tmp, name, name_len); 772 GNUNET_memcpy(name_tmp, name, name_len);
781 rd_ser = &name_tmp[name_len]; 773 rd_ser = &name_tmp[name_len];
782 GNUNET_assert ( 774 GNUNET_assert(
783 rd_ser_len == 775 rd_ser_len ==
784 GNUNET_GNSRECORD_records_serialize (res_count, res, rd_ser_len, rd_ser)); 776 GNUNET_GNSRECORD_records_serialize(res_count, res, rd_ser_len, rd_ser));
785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 777 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
786 "Sending RECORD_RESULT message with %u records\n", 778 "Sending RECORD_RESULT message with %u records\n",
787 res_count); 779 res_count);
788 GNUNET_STATISTICS_update (statistics, 780 GNUNET_STATISTICS_update(statistics,
789 "Record sets sent to clients", 781 "Record sets sent to clients",
790 1, 782 1,
791 GNUNET_NO); 783 GNUNET_NO);
792 GNUNET_MQ_send (nc->mq, env); 784 GNUNET_MQ_send(nc->mq, env);
793 if (rd != res) 785 if (rd != res)
794 GNUNET_free (res); 786 GNUNET_free(res);
795} 787}
796 788
797 789
@@ -803,23 +795,23 @@ send_lookup_response (struct NamestoreClient *nc,
803 * @param rid client's request ID 795 * @param rid client's request ID
804 */ 796 */
805static void 797static void
806send_store_response (struct NamestoreClient *nc, int res, uint32_t rid) 798send_store_response(struct NamestoreClient *nc, int res, uint32_t rid)
807{ 799{
808 struct GNUNET_MQ_Envelope *env; 800 struct GNUNET_MQ_Envelope *env;
809 struct RecordStoreResponseMessage *rcr_msg; 801 struct RecordStoreResponseMessage *rcr_msg;
810 802
811 GNUNET_assert (NULL != nc); 803 GNUNET_assert(NULL != nc);
812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 804 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
813 "Sending RECORD_STORE_RESPONSE message\n"); 805 "Sending RECORD_STORE_RESPONSE message\n");
814 GNUNET_STATISTICS_update (statistics, 806 GNUNET_STATISTICS_update(statistics,
815 "Store requests completed", 807 "Store requests completed",
816 1, 808 1,
817 GNUNET_NO); 809 GNUNET_NO);
818 env = GNUNET_MQ_msg (rcr_msg, 810 env = GNUNET_MQ_msg(rcr_msg,
819 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); 811 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
820 rcr_msg->gns_header.r_id = htonl (rid); 812 rcr_msg->gns_header.r_id = htonl(rid);
821 rcr_msg->op_result = htonl (res); 813 rcr_msg->op_result = htonl(res);
822 GNUNET_MQ_send (nc->mq, env); 814 GNUNET_MQ_send(nc->mq, env);
823} 815}
824 816
825 817
@@ -830,21 +822,21 @@ send_store_response (struct NamestoreClient *nc, int res, uint32_t rid)
830 * @param zi zone iteration we are processing 822 * @param zi zone iteration we are processing
831 */ 823 */
832static void 824static void
833zone_iteration_done_client_continue (struct ZoneIteration *zi) 825zone_iteration_done_client_continue(struct ZoneIteration *zi)
834{ 826{
835 struct GNUNET_MQ_Envelope *env; 827 struct GNUNET_MQ_Envelope *env;
836 struct GNUNET_NAMESTORE_Header *em; 828 struct GNUNET_NAMESTORE_Header *em;
837 829
838 GNUNET_SERVICE_client_continue (zi->nc->client); 830 GNUNET_SERVICE_client_continue(zi->nc->client);
839 if (! zi->send_end) 831 if (!zi->send_end)
840 return; 832 return;
841 /* send empty response to indicate end of list */ 833 /* send empty response to indicate end of list */
842 env = GNUNET_MQ_msg (em, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END); 834 env = GNUNET_MQ_msg(em, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END);
843 em->r_id = htonl (zi->request_id); 835 em->r_id = htonl(zi->request_id);
844 GNUNET_MQ_send (zi->nc->mq, env); 836 GNUNET_MQ_send(zi->nc->mq, env);
845 837
846 GNUNET_CONTAINER_DLL_remove (zi->nc->op_head, zi->nc->op_tail, zi); 838 GNUNET_CONTAINER_DLL_remove(zi->nc->op_head, zi->nc->op_tail, zi);
847 GNUNET_free (zi); 839 GNUNET_free(zi);
848} 840}
849 841
850 842
@@ -856,30 +848,30 @@ zone_iteration_done_client_continue (struct ZoneIteration *zi)
856 * @param emsg error messages 848 * @param emsg error messages
857 */ 849 */
858static void 850static void
859finish_cache_operation (void *cls, int32_t success, const char *emsg) 851finish_cache_operation(void *cls, int32_t success, const char *emsg)
860{ 852{
861 struct CacheOperation *cop = cls; 853 struct CacheOperation *cop = cls;
862 struct ZoneIteration *zi; 854 struct ZoneIteration *zi;
863 855
864 if (NULL != emsg) 856 if (NULL != emsg)
865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 857 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
866 _ ("Failed to replicate block in namecache: %s\n"), 858 _("Failed to replicate block in namecache: %s\n"),
867 emsg); 859 emsg);
868 else 860 else
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n"); 861 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CACHE operation completed\n");
870 GNUNET_CONTAINER_DLL_remove (cop_head, cop_tail, cop); 862 GNUNET_CONTAINER_DLL_remove(cop_head, cop_tail, cop);
871 if (NULL != cop->nc) 863 if (NULL != cop->nc)
872 send_store_response (cop->nc, success, cop->rid); 864 send_store_response(cop->nc, success, cop->rid);
873 if (NULL != (zi = cop->zi)) 865 if (NULL != (zi = cop->zi))
874 {
875 zi->cache_ops--;
876 if (0 == zi->cache_ops)
877 { 866 {
878 /* unchoke zone iteration, cache has caught up */ 867 zi->cache_ops--;
879 zone_iteration_done_client_continue (zi); 868 if (0 == zi->cache_ops)
869 {
870 /* unchoke zone iteration, cache has caught up */
871 zone_iteration_done_client_continue(zi);
872 }
880 } 873 }
881 } 874 GNUNET_free(cop);
882 GNUNET_free (cop);
883} 875}
884 876
885 877
@@ -896,13 +888,13 @@ finish_cache_operation (void *cls, int32_t success, const char *emsg)
896 * @param rd records stored under the given @a name 888 * @param rd records stored under the given @a name
897 */ 889 */
898static void 890static void
899refresh_block (struct NamestoreClient *nc, 891refresh_block(struct NamestoreClient *nc,
900 struct ZoneIteration *zi, 892 struct ZoneIteration *zi,
901 uint32_t rid, 893 uint32_t rid,
902 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 894 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
903 const char *name, 895 const char *name,
904 unsigned int rd_count, 896 unsigned int rd_count,
905 const struct GNUNET_GNSRECORD_Data *rd) 897 const struct GNUNET_GNSRECORD_Data *rd)
906{ 898{
907 struct GNUNET_GNSRECORD_Block *block; 899 struct GNUNET_GNSRECORD_Block *block;
908 struct CacheOperation *cop; 900 struct CacheOperation *cop;
@@ -912,64 +904,64 @@ refresh_block (struct NamestoreClient *nc,
912 unsigned int res_count; 904 unsigned int res_count;
913 struct GNUNET_TIME_Absolute exp_time; 905 struct GNUNET_TIME_Absolute exp_time;
914 906
915 nick = get_nick_record (zone_key); 907 nick = get_nick_record(zone_key);
916 res_count = rd_count; 908 res_count = rd_count;
917 res = (struct GNUNET_GNSRECORD_Data *) rd; /* fixme: a bit unclean... */ 909 res = (struct GNUNET_GNSRECORD_Data *)rd; /* fixme: a bit unclean... */
918 if (NULL != nick) 910 if (NULL != nick)
919 { 911 {
920 nick->flags = 912 nick->flags =
921 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 913 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
922 merge_with_nick_records (nick, rd_count, rd, &res_count, &res); 914 merge_with_nick_records(nick, rd_count, rd, &res_count, &res);
923 GNUNET_free (nick); 915 GNUNET_free(nick);
924 } 916 }
925 if (0 == res_count) 917 if (0 == res_count)
926 { 918 {
927 if (NULL != nc) 919 if (NULL != nc)
928 send_store_response (nc, GNUNET_OK, rid); 920 send_store_response(nc, GNUNET_OK, rid);
929 return; /* no data, no need to update cache */ 921 return; /* no data, no need to update cache */
930 } 922 }
931 if (GNUNET_YES == disable_namecache) 923 if (GNUNET_YES == disable_namecache)
932 { 924 {
933 GNUNET_STATISTICS_update (statistics, 925 GNUNET_STATISTICS_update(statistics,
934 "Namecache updates skipped (NC disabled)", 926 "Namecache updates skipped (NC disabled)",
935 1, 927 1,
936 GNUNET_NO); 928 GNUNET_NO);
937 if (NULL != nc) 929 if (NULL != nc)
938 send_store_response (nc, GNUNET_OK, rid); 930 send_store_response(nc, GNUNET_OK, rid);
939 return; 931 return;
940 } 932 }
941 exp_time = GNUNET_GNSRECORD_record_get_expiration_time (res_count, res); 933 exp_time = GNUNET_GNSRECORD_record_get_expiration_time(res_count, res);
942 if (cache_keys) 934 if (cache_keys)
943 block = 935 block =
944 GNUNET_GNSRECORD_block_create2 (zone_key, exp_time, name, res, res_count); 936 GNUNET_GNSRECORD_block_create2(zone_key, exp_time, name, res, res_count);
945 else 937 else
946 block = 938 block =
947 GNUNET_GNSRECORD_block_create (zone_key, exp_time, name, res, res_count); 939 GNUNET_GNSRECORD_block_create(zone_key, exp_time, name, res, res_count);
948 GNUNET_assert (NULL != block); 940 GNUNET_assert(NULL != block);
949 GNUNET_CRYPTO_ecdsa_key_get_public (zone_key, &pkey); 941 GNUNET_CRYPTO_ecdsa_key_get_public(zone_key, &pkey);
950 GNUNET_log ( 942 GNUNET_log(
951 GNUNET_ERROR_TYPE_DEBUG, 943 GNUNET_ERROR_TYPE_DEBUG,
952 "Caching block for label `%s' with %u records and expiration %s in zone `%s' in namecache\n", 944 "Caching block for label `%s' with %u records and expiration %s in zone `%s' in namecache\n",
953 name, 945 name,
954 res_count, 946 res_count,
955 GNUNET_STRINGS_absolute_time_to_string (exp_time), 947 GNUNET_STRINGS_absolute_time_to_string(exp_time),
956 GNUNET_GNSRECORD_z2s (&pkey)); 948 GNUNET_GNSRECORD_z2s(&pkey));
957 GNUNET_STATISTICS_update (statistics, 949 GNUNET_STATISTICS_update(statistics,
958 "Namecache updates pushed", 950 "Namecache updates pushed",
959 1, 951 1,
960 GNUNET_NO); 952 GNUNET_NO);
961 cop = GNUNET_new (struct CacheOperation); 953 cop = GNUNET_new(struct CacheOperation);
962 cop->nc = nc; 954 cop->nc = nc;
963 cop->zi = zi; 955 cop->zi = zi;
964 if (NULL != zi) 956 if (NULL != zi)
965 zi->cache_ops++; 957 zi->cache_ops++;
966 cop->rid = rid; 958 cop->rid = rid;
967 GNUNET_CONTAINER_DLL_insert (cop_head, cop_tail, cop); 959 GNUNET_CONTAINER_DLL_insert(cop_head, cop_tail, cop);
968 cop->qe = GNUNET_NAMECACHE_block_cache (namecache, 960 cop->qe = GNUNET_NAMECACHE_block_cache(namecache,
969 block, 961 block,
970 &finish_cache_operation, 962 &finish_cache_operation,
971 cop); 963 cop);
972 GNUNET_free (block); 964 GNUNET_free(block);
973} 965}
974 966
975 967
@@ -979,16 +971,16 @@ refresh_block (struct NamestoreClient *nc,
979 * @param cls a `struct ZoneMonitor` to warn about 971 * @param cls a `struct ZoneMonitor` to warn about
980 */ 972 */
981static void 973static void
982warn_monitor_slow (void *cls) 974warn_monitor_slow(void *cls)
983{ 975{
984 struct ZoneMonitor *zm = cls; 976 struct ZoneMonitor *zm = cls;
985 977
986 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 978 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
987 "No response from monitor since %s\n", 979 "No response from monitor since %s\n",
988 GNUNET_STRINGS_absolute_time_to_string (zm->sa_waiting_start)); 980 GNUNET_STRINGS_absolute_time_to_string(zm->sa_waiting_start));
989 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, 981 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY,
990 &warn_monitor_slow, 982 &warn_monitor_slow,
991 zm); 983 zm);
992} 984}
993 985
994 986
@@ -998,7 +990,7 @@ warn_monitor_slow (void *cls)
998 * @param sa store activity to process 990 * @param sa store activity to process
999 */ 991 */
1000static void 992static void
1001continue_store_activity (struct StoreActivity *sa) 993continue_store_activity(struct StoreActivity *sa)
1002{ 994{
1003 const struct RecordStoreMessage *rp_msg = sa->rsm; 995 const struct RecordStoreMessage *rp_msg = sa->rsm;
1004 unsigned int rd_count; 996 unsigned int rd_count;
@@ -1008,63 +1000,63 @@ continue_store_activity (struct StoreActivity *sa)
1008 const char *name_tmp; 1000 const char *name_tmp;
1009 const char *rd_ser; 1001 const char *rd_ser;
1010 1002
1011 rid = ntohl (rp_msg->gns_header.r_id); 1003 rid = ntohl(rp_msg->gns_header.r_id);
1012 name_len = ntohs (rp_msg->name_len); 1004 name_len = ntohs(rp_msg->name_len);
1013 rd_count = ntohs (rp_msg->rd_count); 1005 rd_count = ntohs(rp_msg->rd_count);
1014 rd_ser_len = ntohs (rp_msg->rd_len); 1006 rd_ser_len = ntohs(rp_msg->rd_len);
1015 name_tmp = (const char *) &rp_msg[1]; 1007 name_tmp = (const char *)&rp_msg[1];
1016 rd_ser = &name_tmp[name_len]; 1008 rd_ser = &name_tmp[name_len];
1017 { 1009 {
1018 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; 1010 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
1019 1011
1020 /* We did this before, must succeed again */ 1012 /* We did this before, must succeed again */
1021 GNUNET_assert ( 1013 GNUNET_assert(
1022 GNUNET_OK == 1014 GNUNET_OK ==
1023 GNUNET_GNSRECORD_records_deserialize (rd_ser_len, rd_ser, rd_count, rd)); 1015 GNUNET_GNSRECORD_records_deserialize(rd_ser_len, rd_ser, rd_count, rd));
1024 1016
1025 for (struct ZoneMonitor *zm = sa->zm_pos; NULL != zm; zm = sa->zm_pos) 1017 for (struct ZoneMonitor *zm = sa->zm_pos; NULL != zm; zm = sa->zm_pos)
1026 {
1027 if ((0 != GNUNET_memcmp (&rp_msg->private_key, &zm->zone)) &&
1028 (0 != GNUNET_memcmp (&zm->zone, &zero)))
1029 {
1030 sa->zm_pos = zm->next; /* not interesting to this monitor */
1031 continue;
1032 }
1033 if (zm->limit == zm->iteration_cnt)
1034 { 1018 {
1035 zm->sa_waiting = GNUNET_YES; 1019 if ((0 != GNUNET_memcmp(&rp_msg->private_key, &zm->zone)) &&
1036 zm->sa_waiting_start = GNUNET_TIME_absolute_get (); 1020 (0 != GNUNET_memcmp(&zm->zone, &zero)))
1037 if (NULL != zm->sa_wait_warning) 1021 {
1038 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); 1022 sa->zm_pos = zm->next; /* not interesting to this monitor */
1039 zm->sa_wait_warning = 1023 continue;
1040 GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, 1024 }
1041 &warn_monitor_slow, 1025 if (zm->limit == zm->iteration_cnt)
1042 zm); 1026 {
1043 return; /* blocked on zone monitor */ 1027 zm->sa_waiting = GNUNET_YES;
1028 zm->sa_waiting_start = GNUNET_TIME_absolute_get();
1029 if (NULL != zm->sa_wait_warning)
1030 GNUNET_SCHEDULER_cancel(zm->sa_wait_warning);
1031 zm->sa_wait_warning =
1032 GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY,
1033 &warn_monitor_slow,
1034 zm);
1035 return; /* blocked on zone monitor */
1036 }
1037 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1038 "Notifying monitor about changes under label `%s'\n",
1039 sa->conv_name);
1040 zm->limit--;
1041 send_lookup_response(zm->nc,
1042 0,
1043 &rp_msg->private_key,
1044 sa->conv_name,
1045 rd_count,
1046 rd);
1047 sa->zm_pos = zm->next;
1044 } 1048 }
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "Notifying monitor about changes under label `%s'\n",
1047 sa->conv_name);
1048 zm->limit--;
1049 send_lookup_response (zm->nc,
1050 0,
1051 &rp_msg->private_key,
1052 sa->conv_name,
1053 rd_count,
1054 rd);
1055 sa->zm_pos = zm->next;
1056 }
1057 /* great, done with the monitors, unpack (again) for refresh_block operation */ 1049 /* great, done with the monitors, unpack (again) for refresh_block operation */
1058 refresh_block (sa->nc, 1050 refresh_block(sa->nc,
1059 NULL, 1051 NULL,
1060 rid, 1052 rid,
1061 &rp_msg->private_key, 1053 &rp_msg->private_key,
1062 sa->conv_name, 1054 sa->conv_name,
1063 rd_count, 1055 rd_count,
1064 rd); 1056 rd);
1065 } 1057 }
1066 GNUNET_SERVICE_client_continue (sa->nc->client); 1058 GNUNET_SERVICE_client_continue(sa->nc->client);
1067 free_store_activity (sa); 1059 free_store_activity(sa);
1068} 1060}
1069 1061
1070 1062
@@ -1077,64 +1069,64 @@ continue_store_activity (struct StoreActivity *sa)
1077 * @param app_ctx the `struct NamestoreClient` of @a client 1069 * @param app_ctx the `struct NamestoreClient` of @a client
1078 */ 1070 */
1079static void 1071static void
1080client_disconnect_cb (void *cls, 1072client_disconnect_cb(void *cls,
1081 struct GNUNET_SERVICE_Client *client, 1073 struct GNUNET_SERVICE_Client *client,
1082 void *app_ctx) 1074 void *app_ctx)
1083{ 1075{
1084 struct NamestoreClient *nc = app_ctx; 1076 struct NamestoreClient *nc = app_ctx;
1085 struct ZoneIteration *no; 1077 struct ZoneIteration *no;
1086 struct CacheOperation *cop; 1078 struct CacheOperation *cop;
1087 1079
1088 (void) cls; 1080 (void)cls;
1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); 1081 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
1090 for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next) 1082 for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
1091 {
1092 struct StoreActivity *san;
1093
1094 if (nc != zm->nc)
1095 continue;
1096 GNUNET_CONTAINER_DLL_remove (monitor_head, monitor_tail, zm);
1097 if (NULL != zm->task)
1098 { 1083 {
1099 GNUNET_SCHEDULER_cancel (zm->task); 1084 struct StoreActivity *san;
1100 zm->task = NULL; 1085
1101 } 1086 if (nc != zm->nc)
1102 if (NULL != zm->sa_wait_warning) 1087 continue;
1103 { 1088 GNUNET_CONTAINER_DLL_remove(monitor_head, monitor_tail, zm);
1104 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); 1089 if (NULL != zm->task)
1105 zm->sa_wait_warning = NULL; 1090 {
1106 } 1091 GNUNET_SCHEDULER_cancel(zm->task);
1107 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san) 1092 zm->task = NULL;
1108 { 1093 }
1109 san = sa->next; 1094 if (NULL != zm->sa_wait_warning)
1110 if (zm == sa->zm_pos) 1095 {
1111 { 1096 GNUNET_SCHEDULER_cancel(zm->sa_wait_warning);
1112 sa->zm_pos = zm->next; 1097 zm->sa_wait_warning = NULL;
1113 /* this may free sa */ 1098 }
1114 continue_store_activity (sa); 1099 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san)
1115 } 1100 {
1101 san = sa->next;
1102 if (zm == sa->zm_pos)
1103 {
1104 sa->zm_pos = zm->next;
1105 /* this may free sa */
1106 continue_store_activity(sa);
1107 }
1108 }
1109 GNUNET_free(zm);
1110 break;
1116 } 1111 }
1117 GNUNET_free (zm);
1118 break;
1119 }
1120 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next) 1112 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
1121 {
1122 if (sa->nc == nc)
1123 { 1113 {
1124 /* this may free sa */ 1114 if (sa->nc == nc)
1125 free_store_activity (sa); 1115 {
1126 break; /* there can only be one per nc */ 1116 /* this may free sa */
1117 free_store_activity(sa);
1118 break; /* there can only be one per nc */
1119 }
1127 } 1120 }
1128 }
1129 while (NULL != (no = nc->op_head)) 1121 while (NULL != (no = nc->op_head))
1130 { 1122 {
1131 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); 1123 GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, no);
1132 GNUNET_free (no); 1124 GNUNET_free(no);
1133 } 1125 }
1134 for (cop = cop_head; NULL != cop; cop = cop->next) 1126 for (cop = cop_head; NULL != cop; cop = cop->next)
1135 if (nc == cop->nc) 1127 if (nc == cop->nc)
1136 cop->nc = NULL; 1128 cop->nc = NULL;
1137 GNUNET_free (nc); 1129 GNUNET_free(nc);
1138} 1130}
1139 1131
1140 1132
@@ -1147,15 +1139,15 @@ client_disconnect_cb (void *cls,
1147 * @return internal namestore client structure for this client 1139 * @return internal namestore client structure for this client
1148 */ 1140 */
1149static void * 1141static void *
1150client_connect_cb (void *cls, 1142client_connect_cb(void *cls,
1151 struct GNUNET_SERVICE_Client *client, 1143 struct GNUNET_SERVICE_Client *client,
1152 struct GNUNET_MQ_Handle *mq) 1144 struct GNUNET_MQ_Handle *mq)
1153{ 1145{
1154 struct NamestoreClient *nc; 1146 struct NamestoreClient *nc;
1155 1147
1156 (void) cls; 1148 (void)cls;
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); 1149 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1158 nc = GNUNET_new (struct NamestoreClient); 1150 nc = GNUNET_new(struct NamestoreClient);
1159 nc->client = client; 1151 nc->client = client;
1160 nc->mq = mq; 1152 nc->mq = mq;
1161 return nc; 1153 return nc;
@@ -1165,9 +1157,7 @@ client_connect_cb (void *cls,
1165/** 1157/**
1166 * Closure for #lookup_it(). 1158 * Closure for #lookup_it().
1167 */ 1159 */
1168struct RecordLookupContext 1160struct RecordLookupContext {
1169{
1170
1171 /** 1161 /**
1172 * FIXME. 1162 * FIXME.
1173 */ 1163 */
@@ -1213,93 +1203,93 @@ struct RecordLookupContext
1213 * @param rd array of records with data to store 1203 * @param rd array of records with data to store
1214 */ 1204 */
1215static void 1205static void
1216lookup_it (void *cls, 1206lookup_it(void *cls,
1217 uint64_t seq, 1207 uint64_t seq,
1218 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, 1208 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
1219 const char *label, 1209 const char *label,
1220 unsigned int rd_count, 1210 unsigned int rd_count,
1221 const struct GNUNET_GNSRECORD_Data *rd) 1211 const struct GNUNET_GNSRECORD_Data *rd)
1222{ 1212{
1223 struct RecordLookupContext *rlc = cls; 1213 struct RecordLookupContext *rlc = cls;
1224 1214
1225 (void) private_key; 1215 (void)private_key;
1226 GNUNET_assert (0 != seq); 1216 GNUNET_assert(0 != seq);
1227 if (0 != strcmp (label, rlc->label)) 1217 if (0 != strcmp(label, rlc->label))
1228 return; 1218 return;
1229 rlc->found = GNUNET_YES; 1219 rlc->found = GNUNET_YES;
1230 if (0 == rd_count) 1220 if (0 == rd_count)
1231 {
1232 rlc->rd_ser_len = 0;
1233 rlc->res_rd_count = 0;
1234 rlc->res_rd = NULL;
1235 return;
1236 }
1237 if ((NULL != rlc->nick) && (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT)))
1238 {
1239 /* Merge */
1240 struct GNUNET_GNSRECORD_Data *rd_res;
1241 unsigned int rdc_res;
1242
1243 rd_res = NULL;
1244 rdc_res = 0;
1245 rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^
1246 GNUNET_GNSRECORD_RF_PRIVATE;
1247 merge_with_nick_records (rlc->nick, rd_count, rd, &rdc_res, &rd_res);
1248 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res);
1249 if (rlc->rd_ser_len < 0)
1250 { 1221 {
1251 GNUNET_break (0);
1252 GNUNET_free (rd_res);
1253 rlc->found = GNUNET_NO;
1254 rlc->rd_ser_len = 0; 1222 rlc->rd_ser_len = 0;
1255 return;
1256 }
1257 rlc->res_rd_count = rdc_res;
1258 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
1259 if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize (rdc_res,
1260 rd_res,
1261 rlc->rd_ser_len,
1262 rlc->res_rd))
1263 {
1264 GNUNET_break (0);
1265 GNUNET_free (rlc->res_rd);
1266 rlc->res_rd = NULL;
1267 rlc->res_rd_count = 0; 1223 rlc->res_rd_count = 0;
1268 rlc->rd_ser_len = 0; 1224 rlc->res_rd = NULL;
1269 GNUNET_free (rd_res);
1270 rlc->found = GNUNET_NO;
1271 return; 1225 return;
1272 } 1226 }
1273 GNUNET_free (rd_res); 1227 if ((NULL != rlc->nick) && (0 != strcmp(label, GNUNET_GNS_EMPTY_LABEL_AT)))
1274 GNUNET_free (rlc->nick);
1275 rlc->nick = NULL;
1276 }
1277 else
1278 {
1279 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
1280 if (rlc->rd_ser_len < 0)
1281 { 1228 {
1282 GNUNET_break (0); 1229 /* Merge */
1283 rlc->found = GNUNET_NO; 1230 struct GNUNET_GNSRECORD_Data *rd_res;
1284 rlc->rd_ser_len = 0; 1231 unsigned int rdc_res;
1285 return; 1232
1233 rd_res = NULL;
1234 rdc_res = 0;
1235 rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^
1236 GNUNET_GNSRECORD_RF_PRIVATE;
1237 merge_with_nick_records(rlc->nick, rd_count, rd, &rdc_res, &rd_res);
1238 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size(rdc_res, rd_res);
1239 if (rlc->rd_ser_len < 0)
1240 {
1241 GNUNET_break(0);
1242 GNUNET_free(rd_res);
1243 rlc->found = GNUNET_NO;
1244 rlc->rd_ser_len = 0;
1245 return;
1246 }
1247 rlc->res_rd_count = rdc_res;
1248 rlc->res_rd = GNUNET_malloc(rlc->rd_ser_len);
1249 if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize(rdc_res,
1250 rd_res,
1251 rlc->rd_ser_len,
1252 rlc->res_rd))
1253 {
1254 GNUNET_break(0);
1255 GNUNET_free(rlc->res_rd);
1256 rlc->res_rd = NULL;
1257 rlc->res_rd_count = 0;
1258 rlc->rd_ser_len = 0;
1259 GNUNET_free(rd_res);
1260 rlc->found = GNUNET_NO;
1261 return;
1262 }
1263 GNUNET_free(rd_res);
1264 GNUNET_free(rlc->nick);
1265 rlc->nick = NULL;
1286 } 1266 }
1287 rlc->res_rd_count = rd_count; 1267 else
1288 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
1289 if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize (rd_count,
1290 rd,
1291 rlc->rd_ser_len,
1292 rlc->res_rd))
1293 { 1268 {
1294 GNUNET_break (0); 1269 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size(rd_count, rd);
1295 GNUNET_free (rlc->res_rd); 1270 if (rlc->rd_ser_len < 0)
1296 rlc->res_rd = NULL; 1271 {
1297 rlc->res_rd_count = 0; 1272 GNUNET_break(0);
1298 rlc->rd_ser_len = 0; 1273 rlc->found = GNUNET_NO;
1299 rlc->found = GNUNET_NO; 1274 rlc->rd_ser_len = 0;
1300 return; 1275 return;
1276 }
1277 rlc->res_rd_count = rd_count;
1278 rlc->res_rd = GNUNET_malloc(rlc->rd_ser_len);
1279 if (rlc->rd_ser_len != GNUNET_GNSRECORD_records_serialize(rd_count,
1280 rd,
1281 rlc->rd_ser_len,
1282 rlc->res_rd))
1283 {
1284 GNUNET_break(0);
1285 GNUNET_free(rlc->res_rd);
1286 rlc->res_rd = NULL;
1287 rlc->res_rd_count = 0;
1288 rlc->rd_ser_len = 0;
1289 rlc->found = GNUNET_NO;
1290 return;
1291 }
1301 } 1292 }
1302 }
1303} 1293}
1304 1294
1305 1295
@@ -1311,20 +1301,20 @@ lookup_it (void *cls,
1311 * @return #GNUNET_OK if @a ll_msg is well-formed 1301 * @return #GNUNET_OK if @a ll_msg is well-formed
1312 */ 1302 */
1313static int 1303static int
1314check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) 1304check_record_lookup(void *cls, const struct LabelLookupMessage *ll_msg)
1315{ 1305{
1316 uint32_t name_len; 1306 uint32_t name_len;
1317 size_t src_size; 1307 size_t src_size;
1318 1308
1319 (void) cls; 1309 (void)cls;
1320 name_len = ntohl (ll_msg->label_len); 1310 name_len = ntohl(ll_msg->label_len);
1321 src_size = ntohs (ll_msg->gns_header.header.size); 1311 src_size = ntohs(ll_msg->gns_header.header.size);
1322 if (name_len != src_size - sizeof (struct LabelLookupMessage)) 1312 if (name_len != src_size - sizeof(struct LabelLookupMessage))
1323 { 1313 {
1324 GNUNET_break (0); 1314 GNUNET_break(0);
1325 return GNUNET_SYSERR; 1315 return GNUNET_SYSERR;
1326 } 1316 }
1327 GNUNET_MQ_check_zero_termination (ll_msg); 1317 GNUNET_MQ_check_zero_termination(ll_msg);
1328 return GNUNET_OK; 1318 return GNUNET_OK;
1329} 1319}
1330 1320
@@ -1336,7 +1326,7 @@ check_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1336 * @param ll_msg message of type `struct LabelLookupMessage` 1326 * @param ll_msg message of type `struct LabelLookupMessage`
1337 */ 1327 */
1338static void 1328static void
1339handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) 1329handle_record_lookup(void *cls, const struct LabelLookupMessage *ll_msg)
1340{ 1330{
1341 struct NamestoreClient *nc = cls; 1331 struct NamestoreClient *nc = cls;
1342 struct GNUNET_MQ_Envelope *env; 1332 struct GNUNET_MQ_Envelope *env;
@@ -1348,52 +1338,52 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1348 uint32_t name_len; 1338 uint32_t name_len;
1349 int res; 1339 int res;
1350 1340
1351 name_len = ntohl (ll_msg->label_len); 1341 name_len = ntohl(ll_msg->label_len);
1352 name_tmp = (const char *) &ll_msg[1]; 1342 name_tmp = (const char *)&ll_msg[1];
1353 GNUNET_SERVICE_client_continue (nc->client); 1343 GNUNET_SERVICE_client_continue(nc->client);
1354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1355 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", 1345 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n",
1356 name_tmp); 1346 name_tmp);
1357 1347
1358 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); 1348 conv_name = GNUNET_GNSRECORD_string_to_lowercase(name_tmp);
1359 if (NULL == conv_name) 1349 if (NULL == conv_name)
1360 { 1350 {
1361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1351 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1362 "Error converting name `%s'\n", 1352 "Error converting name `%s'\n",
1363 name_tmp); 1353 name_tmp);
1364 GNUNET_SERVICE_client_drop (nc->client); 1354 GNUNET_SERVICE_client_drop(nc->client);
1365 return; 1355 return;
1366 } 1356 }
1367 rlc.label = conv_name; 1357 rlc.label = conv_name;
1368 rlc.found = GNUNET_NO; 1358 rlc.found = GNUNET_NO;
1369 rlc.res_rd_count = 0; 1359 rlc.res_rd_count = 0;
1370 rlc.res_rd = NULL; 1360 rlc.res_rd = NULL;
1371 rlc.rd_ser_len = 0; 1361 rlc.rd_ser_len = 0;
1372 rlc.nick = get_nick_record (&ll_msg->zone); 1362 rlc.nick = get_nick_record(&ll_msg->zone);
1373 res = GSN_database->lookup_records (GSN_database->cls, 1363 res = GSN_database->lookup_records(GSN_database->cls,
1374 &ll_msg->zone, 1364 &ll_msg->zone,
1375 conv_name, 1365 conv_name,
1376 &lookup_it, 1366 &lookup_it,
1377 &rlc); 1367 &rlc);
1378 GNUNET_free (conv_name); 1368 GNUNET_free(conv_name);
1379 env = 1369 env =
1380 GNUNET_MQ_msg_extra (llr_msg, 1370 GNUNET_MQ_msg_extra(llr_msg,
1381 name_len + rlc.rd_ser_len, 1371 name_len + rlc.rd_ser_len,
1382 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); 1372 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE);
1383 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; 1373 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id;
1384 llr_msg->private_key = ll_msg->zone; 1374 llr_msg->private_key = ll_msg->zone;
1385 llr_msg->name_len = htons (name_len); 1375 llr_msg->name_len = htons(name_len);
1386 llr_msg->rd_count = htons (rlc.res_rd_count); 1376 llr_msg->rd_count = htons(rlc.res_rd_count);
1387 llr_msg->rd_len = htons (rlc.rd_ser_len); 1377 llr_msg->rd_len = htons(rlc.rd_ser_len);
1388 res_name = (char *) &llr_msg[1]; 1378 res_name = (char *)&llr_msg[1];
1389 if ((GNUNET_YES == rlc.found) && (GNUNET_OK == res)) 1379 if ((GNUNET_YES == rlc.found) && (GNUNET_OK == res))
1390 llr_msg->found = ntohs (GNUNET_YES); 1380 llr_msg->found = ntohs(GNUNET_YES);
1391 else 1381 else
1392 llr_msg->found = ntohs (GNUNET_NO); 1382 llr_msg->found = ntohs(GNUNET_NO);
1393 GNUNET_memcpy (&llr_msg[1], name_tmp, name_len); 1383 GNUNET_memcpy(&llr_msg[1], name_tmp, name_len);
1394 GNUNET_memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len); 1384 GNUNET_memcpy(&res_name[name_len], rlc.res_rd, rlc.rd_ser_len);
1395 GNUNET_MQ_send (nc->mq, env); 1385 GNUNET_MQ_send(nc->mq, env);
1396 GNUNET_free_non_null (rlc.res_rd); 1386 GNUNET_free_non_null(rlc.res_rd);
1397} 1387}
1398 1388
1399 1389
@@ -1405,7 +1395,7 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1405 * @return #GNUNET_OK if @a rp_msg is well-formed 1395 * @return #GNUNET_OK if @a rp_msg is well-formed
1406 */ 1396 */
1407static int 1397static int
1408check_record_store (void *cls, const struct RecordStoreMessage *rp_msg) 1398check_record_store(void *cls, const struct RecordStoreMessage *rp_msg)
1409{ 1399{
1410 size_t name_len; 1400 size_t name_len;
1411 size_t msg_size; 1401 size_t msg_size;
@@ -1413,27 +1403,27 @@ check_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1413 size_t rd_ser_len; 1403 size_t rd_ser_len;
1414 const char *name_tmp; 1404 const char *name_tmp;
1415 1405
1416 (void) cls; 1406 (void)cls;
1417 name_len = ntohs (rp_msg->name_len); 1407 name_len = ntohs(rp_msg->name_len);
1418 msg_size = ntohs (rp_msg->gns_header.header.size); 1408 msg_size = ntohs(rp_msg->gns_header.header.size);
1419 rd_ser_len = ntohs (rp_msg->rd_len); 1409 rd_ser_len = ntohs(rp_msg->rd_len);
1420 msg_size_exp = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len; 1410 msg_size_exp = sizeof(struct RecordStoreMessage) + name_len + rd_ser_len;
1421 if (msg_size != msg_size_exp) 1411 if (msg_size != msg_size_exp)
1422 { 1412 {
1423 GNUNET_break (0); 1413 GNUNET_break(0);
1424 return GNUNET_SYSERR; 1414 return GNUNET_SYSERR;
1425 } 1415 }
1426 if ((0 == name_len) || (name_len > MAX_NAME_LEN)) 1416 if ((0 == name_len) || (name_len > MAX_NAME_LEN))
1427 { 1417 {
1428 GNUNET_break (0); 1418 GNUNET_break(0);
1429 return GNUNET_SYSERR; 1419 return GNUNET_SYSERR;
1430 } 1420 }
1431 name_tmp = (const char *) &rp_msg[1]; 1421 name_tmp = (const char *)&rp_msg[1];
1432 if ('\0' != name_tmp[name_len - 1]) 1422 if ('\0' != name_tmp[name_len - 1])
1433 { 1423 {
1434 GNUNET_break (0); 1424 GNUNET_break(0);
1435 return GNUNET_SYSERR; 1425 return GNUNET_SYSERR;
1436 } 1426 }
1437 return GNUNET_OK; 1427 return GNUNET_OK;
1438} 1428}
1439 1429
@@ -1445,7 +1435,7 @@ check_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1445 * @param rp_msg message of type `struct RecordStoreMessage` 1435 * @param rp_msg message of type `struct RecordStoreMessage`
1446 */ 1436 */
1447static void 1437static void
1448handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) 1438handle_record_store(void *cls, const struct RecordStoreMessage *rp_msg)
1449{ 1439{
1450 struct NamestoreClient *nc = cls; 1440 struct NamestoreClient *nc = cls;
1451 size_t name_len; 1441 size_t name_len;
@@ -1458,112 +1448,112 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1458 int res; 1448 int res;
1459 struct StoreActivity *sa; 1449 struct StoreActivity *sa;
1460 1450
1461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1451 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1462 "Received NAMESTORE_RECORD_STORE message\n"); 1452 "Received NAMESTORE_RECORD_STORE message\n");
1463 rid = ntohl (rp_msg->gns_header.r_id); 1453 rid = ntohl(rp_msg->gns_header.r_id);
1464 name_len = ntohs (rp_msg->name_len); 1454 name_len = ntohs(rp_msg->name_len);
1465 rd_count = ntohs (rp_msg->rd_count); 1455 rd_count = ntohs(rp_msg->rd_count);
1466 rd_ser_len = ntohs (rp_msg->rd_len); 1456 rd_ser_len = ntohs(rp_msg->rd_len);
1467 GNUNET_break (0 == ntohs (rp_msg->reserved)); 1457 GNUNET_break(0 == ntohs(rp_msg->reserved));
1468 name_tmp = (const char *) &rp_msg[1]; 1458 name_tmp = (const char *)&rp_msg[1];
1469 rd_ser = &name_tmp[name_len]; 1459 rd_ser = &name_tmp[name_len];
1470 { 1460 {
1471 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; 1461 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
1472 1462
1473 if (GNUNET_OK != 1463 if (GNUNET_OK !=
1474 GNUNET_GNSRECORD_records_deserialize (rd_ser_len, rd_ser, rd_count, rd)) 1464 GNUNET_GNSRECORD_records_deserialize(rd_ser_len, rd_ser, rd_count, rd))
1475 { 1465 {
1476 GNUNET_break (0); 1466 GNUNET_break(0);
1477 GNUNET_SERVICE_client_drop (nc->client); 1467 GNUNET_SERVICE_client_drop(nc->client);
1478 return; 1468 return;
1479 } 1469 }
1480 1470
1481 /* Extracting and converting private key */ 1471 /* Extracting and converting private key */
1482 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); 1472 conv_name = GNUNET_GNSRECORD_string_to_lowercase(name_tmp);
1483 if (NULL == conv_name) 1473 if (NULL == conv_name)
1484 { 1474 {
1485 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1475 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1486 "Error converting name `%s'\n", 1476 "Error converting name `%s'\n",
1487 name_tmp); 1477 name_tmp);
1488 GNUNET_SERVICE_client_drop (nc->client); 1478 GNUNET_SERVICE_client_drop(nc->client);
1489 return; 1479 return;
1490 } 1480 }
1491 GNUNET_STATISTICS_update (statistics, 1481 GNUNET_STATISTICS_update(statistics,
1492 "Well-formed store requests received", 1482 "Well-formed store requests received",
1493 1, 1483 1,
1494 GNUNET_NO); 1484 GNUNET_NO);
1495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1485 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1496 "Creating %u records for name `%s'\n", 1486 "Creating %u records for name `%s'\n",
1497 (unsigned int) rd_count, 1487 (unsigned int)rd_count,
1498 conv_name); 1488 conv_name);
1499 if ((0 == rd_count) && 1489 if ((0 == rd_count) &&
1500 (GNUNET_NO == GSN_database->lookup_records (GSN_database->cls, 1490 (GNUNET_NO == GSN_database->lookup_records(GSN_database->cls,
1501 &rp_msg->private_key, 1491 &rp_msg->private_key,
1502 conv_name, 1492 conv_name,
1503 NULL, 1493 NULL,
1504 0))) 1494 0)))
1505 {
1506 /* This name does not exist, so cannot be removed */
1507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1508 "Name `%s' does not exist, no deletion required\n",
1509 conv_name);
1510 res = GNUNET_NO;
1511 }
1512 else
1513 {
1514 /* remove "NICK" records, unless this is for the
1515 #GNUNET_GNS_EMPTY_LABEL_AT label */
1516 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL (rd_count)];
1517 unsigned int rd_clean_off;
1518 int have_nick;
1519
1520 rd_clean_off = 0;
1521 have_nick = GNUNET_NO;
1522 for (unsigned int i = 0; i < rd_count; i++)
1523 { 1495 {
1524 rd_clean[rd_clean_off] = rd[i]; 1496 /* This name does not exist, so cannot be removed */
1525 if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) || 1497 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1526 (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type)) 1498 "Name `%s' does not exist, no deletion required\n",
1527 rd_clean_off++; 1499 conv_name);
1528 1500 res = GNUNET_NO;
1529 if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) &&
1530 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
1531 {
1532 cache_nick (&rp_msg->private_key, &rd[i]);
1533 have_nick = GNUNET_YES;
1534 }
1535 } 1501 }
1536 if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && 1502 else
1537 (GNUNET_NO == have_nick))
1538 { 1503 {
1539 /* remove nick record from cache, in case we have one there */ 1504 /* remove "NICK" records, unless this is for the
1540 cache_nick (&rp_msg->private_key, NULL); 1505 #GNUNET_GNS_EMPTY_LABEL_AT label */
1506 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
1507 unsigned int rd_clean_off;
1508 int have_nick;
1509
1510 rd_clean_off = 0;
1511 have_nick = GNUNET_NO;
1512 for (unsigned int i = 0; i < rd_count; i++)
1513 {
1514 rd_clean[rd_clean_off] = rd[i];
1515 if ((0 == strcmp(GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) ||
1516 (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type))
1517 rd_clean_off++;
1518
1519 if ((0 == strcmp(GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) &&
1520 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
1521 {
1522 cache_nick(&rp_msg->private_key, &rd[i]);
1523 have_nick = GNUNET_YES;
1524 }
1525 }
1526 if ((0 == strcmp(GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) &&
1527 (GNUNET_NO == have_nick))
1528 {
1529 /* remove nick record from cache, in case we have one there */
1530 cache_nick(&rp_msg->private_key, NULL);
1531 }
1532 res = GSN_database->store_records(GSN_database->cls,
1533 &rp_msg->private_key,
1534 conv_name,
1535 rd_clean_off,
1536 rd_clean);
1541 } 1537 }
1542 res = GSN_database->store_records (GSN_database->cls,
1543 &rp_msg->private_key,
1544 conv_name,
1545 rd_clean_off,
1546 rd_clean);
1547 }
1548 1538
1549 if (GNUNET_OK != res) 1539 if (GNUNET_OK != res)
1550 { 1540 {
1551 /* store not successful, not need to tell monitors */ 1541 /* store not successful, not need to tell monitors */
1552 send_store_response (nc, res, rid); 1542 send_store_response(nc, res, rid);
1553 GNUNET_SERVICE_client_continue (nc->client); 1543 GNUNET_SERVICE_client_continue(nc->client);
1554 GNUNET_free (conv_name); 1544 GNUNET_free(conv_name);
1555 return; 1545 return;
1556 } 1546 }
1557 1547
1558 sa = GNUNET_malloc (sizeof (struct StoreActivity) + 1548 sa = GNUNET_malloc(sizeof(struct StoreActivity) +
1559 ntohs (rp_msg->gns_header.header.size)); 1549 ntohs(rp_msg->gns_header.header.size));
1560 GNUNET_CONTAINER_DLL_insert (sa_head, sa_tail, sa); 1550 GNUNET_CONTAINER_DLL_insert(sa_head, sa_tail, sa);
1561 sa->nc = nc; 1551 sa->nc = nc;
1562 sa->rsm = (const struct RecordStoreMessage *) &sa[1]; 1552 sa->rsm = (const struct RecordStoreMessage *)&sa[1];
1563 GNUNET_memcpy (&sa[1], rp_msg, ntohs (rp_msg->gns_header.header.size)); 1553 GNUNET_memcpy(&sa[1], rp_msg, ntohs(rp_msg->gns_header.header.size));
1564 sa->zm_pos = monitor_head; 1554 sa->zm_pos = monitor_head;
1565 sa->conv_name = conv_name; 1555 sa->conv_name = conv_name;
1566 continue_store_activity (sa); 1556 continue_store_activity(sa);
1567 } 1557 }
1568} 1558}
1569 1559
@@ -1572,8 +1562,7 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1572 * Context for record remove operations passed from #handle_zone_to_name to 1562 * Context for record remove operations passed from #handle_zone_to_name to
1573 * #handle_zone_to_name_it as closure 1563 * #handle_zone_to_name_it as closure
1574 */ 1564 */
1575struct ZoneToNameCtx 1565struct ZoneToNameCtx {
1576{
1577 /** 1566 /**
1578 * Namestore client 1567 * Namestore client
1579 */ 1568 */
@@ -1604,12 +1593,12 @@ struct ZoneToNameCtx
1604 * @param rd record data 1593 * @param rd record data
1605 */ 1594 */
1606static void 1595static void
1607handle_zone_to_name_it (void *cls, 1596handle_zone_to_name_it(void *cls,
1608 uint64_t seq, 1597 uint64_t seq,
1609 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 1598 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
1610 const char *name, 1599 const char *name,
1611 unsigned int rd_count, 1600 unsigned int rd_count,
1612 const struct GNUNET_GNSRECORD_Data *rd) 1601 const struct GNUNET_GNSRECORD_Data *rd)
1613{ 1602{
1614 struct ZoneToNameCtx *ztn_ctx = cls; 1603 struct ZoneToNameCtx *ztn_ctx = cls;
1615 struct GNUNET_MQ_Envelope *env; 1604 struct GNUNET_MQ_Envelope *env;
@@ -1621,45 +1610,45 @@ handle_zone_to_name_it (void *cls,
1621 char *name_tmp; 1610 char *name_tmp;
1622 char *rd_tmp; 1611 char *rd_tmp;
1623 1612
1624 GNUNET_assert (0 != seq); 1613 GNUNET_assert(0 != seq);
1625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1614 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1626 "Found result for zone-to-name lookup: `%s'\n", 1615 "Found result for zone-to-name lookup: `%s'\n",
1627 name); 1616 name);
1628 res = GNUNET_YES; 1617 res = GNUNET_YES;
1629 name_len = (NULL == name) ? 0 : strlen (name) + 1; 1618 name_len = (NULL == name) ? 0 : strlen(name) + 1;
1630 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 1619 rd_ser_len = GNUNET_GNSRECORD_records_get_size(rd_count, rd);
1631 if (rd_ser_len < 0) 1620 if (rd_ser_len < 0)
1632 { 1621 {
1633 GNUNET_break (0); 1622 GNUNET_break(0);
1634 ztn_ctx->success = GNUNET_SYSERR; 1623 ztn_ctx->success = GNUNET_SYSERR;
1635 return; 1624 return;
1636 } 1625 }
1637 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len; 1626 msg_size = sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len;
1638 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) 1627 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE)
1639 { 1628 {
1640 GNUNET_break (0); 1629 GNUNET_break(0);
1641 ztn_ctx->success = GNUNET_SYSERR; 1630 ztn_ctx->success = GNUNET_SYSERR;
1642 return; 1631 return;
1643 } 1632 }
1644 env = 1633 env =
1645 GNUNET_MQ_msg_extra (ztnr_msg, 1634 GNUNET_MQ_msg_extra(ztnr_msg,
1646 name_len + rd_ser_len, 1635 name_len + rd_ser_len,
1647 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); 1636 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1648 ztnr_msg->gns_header.header.size = htons (msg_size); 1637 ztnr_msg->gns_header.header.size = htons(msg_size);
1649 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); 1638 ztnr_msg->gns_header.r_id = htonl(ztn_ctx->rid);
1650 ztnr_msg->res = htons (res); 1639 ztnr_msg->res = htons(res);
1651 ztnr_msg->rd_len = htons (rd_ser_len); 1640 ztnr_msg->rd_len = htons(rd_ser_len);
1652 ztnr_msg->rd_count = htons (rd_count); 1641 ztnr_msg->rd_count = htons(rd_count);
1653 ztnr_msg->name_len = htons (name_len); 1642 ztnr_msg->name_len = htons(name_len);
1654 ztnr_msg->zone = *zone_key; 1643 ztnr_msg->zone = *zone_key;
1655 name_tmp = (char *) &ztnr_msg[1]; 1644 name_tmp = (char *)&ztnr_msg[1];
1656 GNUNET_memcpy (name_tmp, name, name_len); 1645 GNUNET_memcpy(name_tmp, name, name_len);
1657 rd_tmp = &name_tmp[name_len]; 1646 rd_tmp = &name_tmp[name_len];
1658 GNUNET_assert ( 1647 GNUNET_assert(
1659 rd_ser_len == 1648 rd_ser_len ==
1660 GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_tmp)); 1649 GNUNET_GNSRECORD_records_serialize(rd_count, rd, rd_ser_len, rd_tmp));
1661 ztn_ctx->success = GNUNET_OK; 1650 ztn_ctx->success = GNUNET_OK;
1662 GNUNET_MQ_send (ztn_ctx->nc->mq, env); 1651 GNUNET_MQ_send(ztn_ctx->nc->mq, env);
1663} 1652}
1664 1653
1665 1654
@@ -1670,41 +1659,41 @@ handle_zone_to_name_it (void *cls,
1670 * @param ztn_msg message of type 'struct ZoneToNameMessage' 1659 * @param ztn_msg message of type 'struct ZoneToNameMessage'
1671 */ 1660 */
1672static void 1661static void
1673handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) 1662handle_zone_to_name(void *cls, const struct ZoneToNameMessage *ztn_msg)
1674{ 1663{
1675 struct NamestoreClient *nc = cls; 1664 struct NamestoreClient *nc = cls;
1676 struct ZoneToNameCtx ztn_ctx; 1665 struct ZoneToNameCtx ztn_ctx;
1677 struct GNUNET_MQ_Envelope *env; 1666 struct GNUNET_MQ_Envelope *env;
1678 struct ZoneToNameResponseMessage *ztnr_msg; 1667 struct ZoneToNameResponseMessage *ztnr_msg;
1679 1668
1680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n"); 1669 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n");
1681 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 1670 ztn_ctx.rid = ntohl(ztn_msg->gns_header.r_id);
1682 ztn_ctx.nc = nc; 1671 ztn_ctx.nc = nc;
1683 ztn_ctx.success = GNUNET_NO; 1672 ztn_ctx.success = GNUNET_NO;
1684 if (GNUNET_SYSERR == GSN_database->zone_to_name (GSN_database->cls, 1673 if (GNUNET_SYSERR == GSN_database->zone_to_name(GSN_database->cls,
1685 &ztn_msg->zone, 1674 &ztn_msg->zone,
1686 &ztn_msg->value_zone, 1675 &ztn_msg->value_zone,
1687 &handle_zone_to_name_it, 1676 &handle_zone_to_name_it,
1688 &ztn_ctx)) 1677 &ztn_ctx))
1689 { 1678 {
1690 /* internal error, hang up instead of signalling something 1679 /* internal error, hang up instead of signalling something
1691 that might be wrong */ 1680 that might be wrong */
1692 GNUNET_break (0); 1681 GNUNET_break(0);
1693 GNUNET_SERVICE_client_drop (nc->client); 1682 GNUNET_SERVICE_client_drop(nc->client);
1694 return; 1683 return;
1695 } 1684 }
1696 if (GNUNET_NO == ztn_ctx.success) 1685 if (GNUNET_NO == ztn_ctx.success)
1697 { 1686 {
1698 /* no result found, send empty response */ 1687 /* no result found, send empty response */
1699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1700 "Found no result for zone-to-name lookup.\n"); 1689 "Found no result for zone-to-name lookup.\n");
1701 env = GNUNET_MQ_msg (ztnr_msg, 1690 env = GNUNET_MQ_msg(ztnr_msg,
1702 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); 1691 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1703 ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id; 1692 ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id;
1704 ztnr_msg->res = htons (GNUNET_NO); 1693 ztnr_msg->res = htons(GNUNET_NO);
1705 GNUNET_MQ_send (nc->mq, env); 1694 GNUNET_MQ_send(nc->mq, env);
1706 } 1695 }
1707 GNUNET_SERVICE_client_continue (nc->client); 1696 GNUNET_SERVICE_client_continue(nc->client);
1708} 1697}
1709 1698
1710 1699
@@ -1712,8 +1701,7 @@ handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg)
1712 * Context for record remove operations passed from 1701 * Context for record remove operations passed from
1713 * #run_zone_iteration_round to #zone_iterate_proc as closure 1702 * #run_zone_iteration_round to #zone_iterate_proc as closure
1714 */ 1703 */
1715struct ZoneIterationProcResult 1704struct ZoneIterationProcResult {
1716{
1717 /** 1705 /**
1718 * The zone iteration handle 1706 * The zone iteration handle
1719 */ 1707 */
@@ -1737,53 +1725,53 @@ struct ZoneIterationProcResult
1737 * @param rd record data 1725 * @param rd record data
1738 */ 1726 */
1739static void 1727static void
1740zone_iterate_proc (void *cls, 1728zone_iterate_proc(void *cls,
1741 uint64_t seq, 1729 uint64_t seq,
1742 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 1730 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
1743 const char *name, 1731 const char *name,
1744 unsigned int rd_count, 1732 unsigned int rd_count,
1745 const struct GNUNET_GNSRECORD_Data *rd) 1733 const struct GNUNET_GNSRECORD_Data *rd)
1746{ 1734{
1747 struct ZoneIterationProcResult *proc = cls; 1735 struct ZoneIterationProcResult *proc = cls;
1748 int do_refresh_block; 1736 int do_refresh_block;
1749 1737
1750 GNUNET_assert (0 != seq); 1738 GNUNET_assert(0 != seq);
1751 if ((NULL == zone_key) && (NULL == name)) 1739 if ((NULL == zone_key) && (NULL == name))
1752 { 1740 {
1753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration done\n"); 1741 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iteration done\n");
1754 return; 1742 return;
1755 } 1743 }
1756 if ((NULL == zone_key) || (NULL == name)) 1744 if ((NULL == zone_key) || (NULL == name))
1757 { 1745 {
1758 /* what is this!? should never happen */ 1746 /* what is this!? should never happen */
1759 GNUNET_break (0); 1747 GNUNET_break(0);
1760 return; 1748 return;
1761 } 1749 }
1762 if (0 == proc->limit) 1750 if (0 == proc->limit)
1763 { 1751 {
1764 /* what is this!? should never happen */ 1752 /* what is this!? should never happen */
1765 GNUNET_break (0); 1753 GNUNET_break(0);
1766 return; 1754 return;
1767 } 1755 }
1768 proc->limit--; 1756 proc->limit--;
1769 proc->zi->seq = seq; 1757 proc->zi->seq = seq;
1770 send_lookup_response (proc->zi->nc, 1758 send_lookup_response(proc->zi->nc,
1771 proc->zi->request_id, 1759 proc->zi->request_id,
1772 zone_key, 1760 zone_key,
1773 name, 1761 name,
1774 rd_count, 1762 rd_count,
1775 rd); 1763 rd);
1776 1764
1777 1765
1778 do_refresh_block = GNUNET_NO; 1766 do_refresh_block = GNUNET_NO;
1779 for (unsigned int i = 0; i < rd_count; i++) 1767 for (unsigned int i = 0; i < rd_count; i++)
1780 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 1768 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1781 { 1769 {
1782 do_refresh_block = GNUNET_YES; 1770 do_refresh_block = GNUNET_YES;
1783 break; 1771 break;
1784 } 1772 }
1785 if (GNUNET_YES == do_refresh_block) 1773 if (GNUNET_YES == do_refresh_block)
1786 refresh_block (NULL, proc->zi, 0, zone_key, name, rd_count, rd); 1774 refresh_block(NULL, proc->zi, 0, zone_key, name, rd_count, rd);
1787} 1775}
1788 1776
1789 1777
@@ -1794,42 +1782,42 @@ zone_iterate_proc (void *cls,
1794 * @param limit number of results to return in one pass 1782 * @param limit number of results to return in one pass
1795 */ 1783 */
1796static void 1784static void
1797run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit) 1785run_zone_iteration_round(struct ZoneIteration *zi, uint64_t limit)
1798{ 1786{
1799 struct ZoneIterationProcResult proc; 1787 struct ZoneIterationProcResult proc;
1800 struct GNUNET_TIME_Absolute start; 1788 struct GNUNET_TIME_Absolute start;
1801 struct GNUNET_TIME_Relative duration; 1789 struct GNUNET_TIME_Relative duration;
1802 1790
1803 memset (&proc, 0, sizeof (proc)); 1791 memset(&proc, 0, sizeof(proc));
1804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1792 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1805 "Asked to return up to %llu records at position %llu\n", 1793 "Asked to return up to %llu records at position %llu\n",
1806 (unsigned long long) limit, 1794 (unsigned long long)limit,
1807 (unsigned long long) zi->seq); 1795 (unsigned long long)zi->seq);
1808 proc.zi = zi; 1796 proc.zi = zi;
1809 proc.limit = limit; 1797 proc.limit = limit;
1810 start = GNUNET_TIME_absolute_get (); 1798 start = GNUNET_TIME_absolute_get();
1811 GNUNET_break (GNUNET_SYSERR != 1799 GNUNET_break(GNUNET_SYSERR !=
1812 GSN_database->iterate_records (GSN_database->cls, 1800 GSN_database->iterate_records(GSN_database->cls,
1813 (0 == GNUNET_is_zero (&zi->zone)) 1801 (0 == GNUNET_is_zero(&zi->zone))
1814 ? NULL 1802 ? NULL
1815 : &zi->zone, 1803 : &zi->zone,
1816 zi->seq, 1804 zi->seq,
1817 limit, 1805 limit,
1818 &zone_iterate_proc, 1806 &zone_iterate_proc,
1819 &proc)); 1807 &proc));
1820 duration = GNUNET_TIME_absolute_get_duration (start); 1808 duration = GNUNET_TIME_absolute_get_duration(start);
1821 duration = GNUNET_TIME_relative_divide (duration, limit - proc.limit); 1809 duration = GNUNET_TIME_relative_divide(duration, limit - proc.limit);
1822 GNUNET_STATISTICS_set (statistics, 1810 GNUNET_STATISTICS_set(statistics,
1823 "NAMESTORE iteration delay (μs/record)", 1811 "NAMESTORE iteration delay (μs/record)",
1824 duration.rel_value_us, 1812 duration.rel_value_us,
1825 GNUNET_NO); 1813 GNUNET_NO);
1826 if (0 == proc.limit) 1814 if (0 == proc.limit)
1827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1815 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1828 "Returned %llu results, more results available\n", 1816 "Returned %llu results, more results available\n",
1829 (unsigned long long) limit); 1817 (unsigned long long)limit);
1830 zi->send_end = (0 != proc.limit); 1818 zi->send_end = (0 != proc.limit);
1831 if (0 == zi->cache_ops) 1819 if (0 == zi->cache_ops)
1832 zone_iteration_done_client_continue (zi); 1820 zone_iteration_done_client_continue(zi);
1833} 1821}
1834 1822
1835 1823
@@ -1840,22 +1828,22 @@ run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit)
1840 * @param zis_msg message from the client 1828 * @param zis_msg message from the client
1841 */ 1829 */
1842static void 1830static void
1843handle_iteration_start (void *cls, 1831handle_iteration_start(void *cls,
1844 const struct ZoneIterationStartMessage *zis_msg) 1832 const struct ZoneIterationStartMessage *zis_msg)
1845{ 1833{
1846 struct NamestoreClient *nc = cls; 1834 struct NamestoreClient *nc = cls;
1847 struct ZoneIteration *zi; 1835 struct ZoneIteration *zi;
1848 1836
1849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1837 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1850 "Received ZONE_ITERATION_START message\n"); 1838 "Received ZONE_ITERATION_START message\n");
1851 zi = GNUNET_new (struct ZoneIteration); 1839 zi = GNUNET_new(struct ZoneIteration);
1852 zi->request_id = ntohl (zis_msg->gns_header.r_id); 1840 zi->request_id = ntohl(zis_msg->gns_header.r_id);
1853 zi->offset = 0; 1841 zi->offset = 0;
1854 zi->nc = nc; 1842 zi->nc = nc;
1855 zi->zone = zis_msg->zone; 1843 zi->zone = zis_msg->zone;
1856 1844
1857 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 1845 GNUNET_CONTAINER_DLL_insert(nc->op_head, nc->op_tail, zi);
1858 run_zone_iteration_round (zi, 1); 1846 run_zone_iteration_round(zi, 1);
1859} 1847}
1860 1848
1861 1849
@@ -1866,28 +1854,28 @@ handle_iteration_start (void *cls,
1866 * @param zis_msg message from the client 1854 * @param zis_msg message from the client
1867 */ 1855 */
1868static void 1856static void
1869handle_iteration_stop (void *cls, 1857handle_iteration_stop(void *cls,
1870 const struct ZoneIterationStopMessage *zis_msg) 1858 const struct ZoneIterationStopMessage *zis_msg)
1871{ 1859{
1872 struct NamestoreClient *nc = cls; 1860 struct NamestoreClient *nc = cls;
1873 struct ZoneIteration *zi; 1861 struct ZoneIteration *zi;
1874 uint32_t rid; 1862 uint32_t rid;
1875 1863
1876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1864 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1877 "Received ZONE_ITERATION_STOP message\n"); 1865 "Received ZONE_ITERATION_STOP message\n");
1878 rid = ntohl (zis_msg->gns_header.r_id); 1866 rid = ntohl(zis_msg->gns_header.r_id);
1879 for (zi = nc->op_head; NULL != zi; zi = zi->next) 1867 for (zi = nc->op_head; NULL != zi; zi = zi->next)
1880 if (zi->request_id == rid) 1868 if (zi->request_id == rid)
1881 break; 1869 break;
1882 if (NULL == zi) 1870 if (NULL == zi)
1883 { 1871 {
1884 GNUNET_break (0); 1872 GNUNET_break(0);
1885 GNUNET_SERVICE_client_drop (nc->client); 1873 GNUNET_SERVICE_client_drop(nc->client);
1886 return; 1874 return;
1887 } 1875 }
1888 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); 1876 GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi);
1889 GNUNET_free (zi); 1877 GNUNET_free(zi);
1890 GNUNET_SERVICE_client_continue (nc->client); 1878 GNUNET_SERVICE_client_continue(nc->client);
1891} 1879}
1892 1880
1893 1881
@@ -1898,32 +1886,32 @@ handle_iteration_stop (void *cls,
1898 * @param message message from the client 1886 * @param message message from the client
1899 */ 1887 */
1900static void 1888static void
1901handle_iteration_next (void *cls, 1889handle_iteration_next(void *cls,
1902 const struct ZoneIterationNextMessage *zis_msg) 1890 const struct ZoneIterationNextMessage *zis_msg)
1903{ 1891{
1904 struct NamestoreClient *nc = cls; 1892 struct NamestoreClient *nc = cls;
1905 struct ZoneIteration *zi; 1893 struct ZoneIteration *zi;
1906 uint32_t rid; 1894 uint32_t rid;
1907 uint64_t limit; 1895 uint64_t limit;
1908 1896
1909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1897 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1910 "Received ZONE_ITERATION_NEXT message\n"); 1898 "Received ZONE_ITERATION_NEXT message\n");
1911 GNUNET_STATISTICS_update (statistics, 1899 GNUNET_STATISTICS_update(statistics,
1912 "Iteration NEXT messages received", 1900 "Iteration NEXT messages received",
1913 1, 1901 1,
1914 GNUNET_NO); 1902 GNUNET_NO);
1915 rid = ntohl (zis_msg->gns_header.r_id); 1903 rid = ntohl(zis_msg->gns_header.r_id);
1916 limit = GNUNET_ntohll (zis_msg->limit); 1904 limit = GNUNET_ntohll(zis_msg->limit);
1917 for (zi = nc->op_head; NULL != zi; zi = zi->next) 1905 for (zi = nc->op_head; NULL != zi; zi = zi->next)
1918 if (zi->request_id == rid) 1906 if (zi->request_id == rid)
1919 break; 1907 break;
1920 if (NULL == zi) 1908 if (NULL == zi)
1921 { 1909 {
1922 GNUNET_break (0); 1910 GNUNET_break(0);
1923 GNUNET_SERVICE_client_drop (nc->client); 1911 GNUNET_SERVICE_client_drop(nc->client);
1924 return; 1912 return;
1925 } 1913 }
1926 run_zone_iteration_round (zi, limit); 1914 run_zone_iteration_round(zi, limit);
1927} 1915}
1928 1916
1929 1917
@@ -1933,37 +1921,37 @@ handle_iteration_next (void *cls,
1933 * monitor not being ready. 1921 * monitor not being ready.
1934 */ 1922 */
1935static void 1923static void
1936monitor_unblock (struct ZoneMonitor *zm) 1924monitor_unblock(struct ZoneMonitor *zm)
1937{ 1925{
1938 struct StoreActivity *sa = sa_head; 1926 struct StoreActivity *sa = sa_head;
1939 1927
1940 while ((NULL != sa) && (zm->limit > zm->iteration_cnt)) 1928 while ((NULL != sa) && (zm->limit > zm->iteration_cnt))
1941 { 1929 {
1942 struct StoreActivity *sn = sa->next; 1930 struct StoreActivity *sn = sa->next;
1943 1931
1944 if (sa->zm_pos == zm) 1932 if (sa->zm_pos == zm)
1945 continue_store_activity (sa); 1933 continue_store_activity(sa);
1946 sa = sn; 1934 sa = sn;
1947 } 1935 }
1948 if (zm->limit > zm->iteration_cnt) 1936 if (zm->limit > zm->iteration_cnt)
1949 {
1950 zm->sa_waiting = GNUNET_NO;
1951 if (NULL != zm->sa_wait_warning)
1952 { 1937 {
1953 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); 1938 zm->sa_waiting = GNUNET_NO;
1954 zm->sa_wait_warning = NULL; 1939 if (NULL != zm->sa_wait_warning)
1940 {
1941 GNUNET_SCHEDULER_cancel(zm->sa_wait_warning);
1942 zm->sa_wait_warning = NULL;
1943 }
1955 } 1944 }
1956 }
1957 else if (GNUNET_YES == zm->sa_waiting) 1945 else if (GNUNET_YES == zm->sa_waiting)
1958 { 1946 {
1959 zm->sa_waiting_start = GNUNET_TIME_absolute_get (); 1947 zm->sa_waiting_start = GNUNET_TIME_absolute_get();
1960 if (NULL != zm->sa_wait_warning) 1948 if (NULL != zm->sa_wait_warning)
1961 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); 1949 GNUNET_SCHEDULER_cancel(zm->sa_wait_warning);
1962 zm->sa_wait_warning = 1950 zm->sa_wait_warning =
1963 GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, 1951 GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY,
1964 &warn_monitor_slow, 1952 &warn_monitor_slow,
1965 zm); 1953 zm);
1966 } 1954 }
1967} 1955}
1968 1956
1969 1957
@@ -1973,18 +1961,18 @@ monitor_unblock (struct ZoneMonitor *zm)
1973 * @param zm monitor that is now in sync 1961 * @param zm monitor that is now in sync
1974 */ 1962 */
1975static void 1963static void
1976monitor_sync (struct ZoneMonitor *zm) 1964monitor_sync(struct ZoneMonitor *zm)
1977{ 1965{
1978 struct GNUNET_MQ_Envelope *env; 1966 struct GNUNET_MQ_Envelope *env;
1979 struct GNUNET_MessageHeader *sync; 1967 struct GNUNET_MessageHeader *sync;
1980 1968
1981 env = GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); 1969 env = GNUNET_MQ_msg(sync, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
1982 GNUNET_MQ_send (zm->nc->mq, env); 1970 GNUNET_MQ_send(zm->nc->mq, env);
1983 /* mark iteration done */ 1971 /* mark iteration done */
1984 zm->in_first_iteration = GNUNET_NO; 1972 zm->in_first_iteration = GNUNET_NO;
1985 zm->iteration_cnt = 0; 1973 zm->iteration_cnt = 0;
1986 if ((zm->limit > 0) && (zm->sa_waiting)) 1974 if ((zm->limit > 0) && (zm->sa_waiting))
1987 monitor_unblock (zm); 1975 monitor_unblock(zm);
1988} 1976}
1989 1977
1990 1978
@@ -1994,7 +1982,7 @@ monitor_sync (struct ZoneMonitor *zm)
1994 * @param cls zone monitor that does its initial iteration 1982 * @param cls zone monitor that does its initial iteration
1995 */ 1983 */
1996static void 1984static void
1997monitor_iteration_next (void *cls); 1985monitor_iteration_next(void *cls);
1998 1986
1999 1987
2000/** 1988/**
@@ -2008,32 +1996,32 @@ monitor_iteration_next (void *cls);
2008 * @param rd array of records 1996 * @param rd array of records
2009 */ 1997 */
2010static void 1998static void
2011monitor_iterate_cb (void *cls, 1999monitor_iterate_cb(void *cls,
2012 uint64_t seq, 2000 uint64_t seq,
2013 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 2001 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
2014 const char *name, 2002 const char *name,
2015 unsigned int rd_count, 2003 unsigned int rd_count,
2016 const struct GNUNET_GNSRECORD_Data *rd) 2004 const struct GNUNET_GNSRECORD_Data *rd)
2017{ 2005{
2018 struct ZoneMonitor *zm = cls; 2006 struct ZoneMonitor *zm = cls;
2019 2007
2020 GNUNET_assert (0 != seq); 2008 GNUNET_assert(0 != seq);
2021 zm->seq = seq; 2009 zm->seq = seq;
2022 GNUNET_assert (NULL != name); 2010 GNUNET_assert(NULL != name);
2023 GNUNET_STATISTICS_update (statistics, 2011 GNUNET_STATISTICS_update(statistics,
2024 "Monitor notifications sent", 2012 "Monitor notifications sent",
2025 1, 2013 1,
2026 GNUNET_NO); 2014 GNUNET_NO);
2027 zm->limit--; 2015 zm->limit--;
2028 zm->iteration_cnt--; 2016 zm->iteration_cnt--;
2029 send_lookup_response (zm->nc, 0, zone_key, name, rd_count, rd); 2017 send_lookup_response(zm->nc, 0, zone_key, name, rd_count, rd);
2030 if ((0 == zm->iteration_cnt) && (0 != zm->limit)) 2018 if ((0 == zm->iteration_cnt) && (0 != zm->limit))
2031 { 2019 {
2032 /* We are done with the current iteration batch, AND the 2020 /* We are done with the current iteration batch, AND the
2033 client would right now accept more, so go again! */ 2021 client would right now accept more, so go again! */
2034 GNUNET_assert (NULL == zm->task); 2022 GNUNET_assert(NULL == zm->task);
2035 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, zm); 2023 zm->task = GNUNET_SCHEDULER_add_now(&monitor_iteration_next, zm);
2036 } 2024 }
2037} 2025}
2038 2026
2039 2027
@@ -2044,25 +2032,25 @@ monitor_iterate_cb (void *cls,
2044 * @param zis_msg message from the client 2032 * @param zis_msg message from the client
2045 */ 2033 */
2046static void 2034static void
2047handle_monitor_start (void *cls, const struct ZoneMonitorStartMessage *zis_msg) 2035handle_monitor_start(void *cls, const struct ZoneMonitorStartMessage *zis_msg)
2048{ 2036{
2049 struct NamestoreClient *nc = cls; 2037 struct NamestoreClient *nc = cls;
2050 struct ZoneMonitor *zm; 2038 struct ZoneMonitor *zm;
2051 2039
2052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_MONITOR_START message\n"); 2040 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_MONITOR_START message\n");
2053 zm = GNUNET_new (struct ZoneMonitor); 2041 zm = GNUNET_new(struct ZoneMonitor);
2054 zm->nc = nc; 2042 zm->nc = nc;
2055 zm->zone = zis_msg->zone; 2043 zm->zone = zis_msg->zone;
2056 zm->limit = 1; 2044 zm->limit = 1;
2057 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first)); 2045 zm->in_first_iteration = (GNUNET_YES == ntohl(zis_msg->iterate_first));
2058 GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, zm); 2046 GNUNET_CONTAINER_DLL_insert(monitor_head, monitor_tail, zm);
2059 GNUNET_SERVICE_client_mark_monitor (nc->client); 2047 GNUNET_SERVICE_client_mark_monitor(nc->client);
2060 GNUNET_SERVICE_client_continue (nc->client); 2048 GNUNET_SERVICE_client_continue(nc->client);
2061 GNUNET_notification_context_add (monitor_nc, nc->mq); 2049 GNUNET_notification_context_add(monitor_nc, nc->mq);
2062 if (zm->in_first_iteration) 2050 if (zm->in_first_iteration)
2063 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, zm); 2051 zm->task = GNUNET_SCHEDULER_add_now(&monitor_iteration_next, zm);
2064 else 2052 else
2065 monitor_sync (zm); 2053 monitor_sync(zm);
2066} 2054}
2067 2055
2068 2056
@@ -2072,36 +2060,36 @@ handle_monitor_start (void *cls, const struct ZoneMonitorStartMessage *zis_msg)
2072 * @param cls zone monitor that does its initial iteration 2060 * @param cls zone monitor that does its initial iteration
2073 */ 2061 */
2074static void 2062static void
2075monitor_iteration_next (void *cls) 2063monitor_iteration_next(void *cls)
2076{ 2064{
2077 struct ZoneMonitor *zm = cls; 2065 struct ZoneMonitor *zm = cls;
2078 int ret; 2066 int ret;
2079 2067
2080 zm->task = NULL; 2068 zm->task = NULL;
2081 GNUNET_assert (0 == zm->iteration_cnt); 2069 GNUNET_assert(0 == zm->iteration_cnt);
2082 if (zm->limit > 16) 2070 if (zm->limit > 16)
2083 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */ 2071 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
2084 else 2072 else
2085 zm->iteration_cnt = zm->limit; /* use it all */ 2073 zm->iteration_cnt = zm->limit; /* use it all */
2086 ret = GSN_database->iterate_records (GSN_database->cls, 2074 ret = GSN_database->iterate_records(GSN_database->cls,
2087 (0 == GNUNET_is_zero (&zm->zone)) 2075 (0 == GNUNET_is_zero(&zm->zone))
2088 ? NULL 2076 ? NULL
2089 : &zm->zone, 2077 : &zm->zone,
2090 zm->seq, 2078 zm->seq,
2091 zm->iteration_cnt, 2079 zm->iteration_cnt,
2092 &monitor_iterate_cb, 2080 &monitor_iterate_cb,
2093 zm); 2081 zm);
2094 if (GNUNET_SYSERR == ret) 2082 if (GNUNET_SYSERR == ret)
2095 { 2083 {
2096 GNUNET_SERVICE_client_drop (zm->nc->client); 2084 GNUNET_SERVICE_client_drop(zm->nc->client);
2097 return; 2085 return;
2098 } 2086 }
2099 if (GNUNET_NO == ret) 2087 if (GNUNET_NO == ret)
2100 { 2088 {
2101 /* empty zone */ 2089 /* empty zone */
2102 monitor_sync (zm); 2090 monitor_sync(zm);
2103 return; 2091 return;
2104 } 2092 }
2105} 2093}
2106 2094
2107 2095
@@ -2112,55 +2100,55 @@ monitor_iteration_next (void *cls)
2112 * @param nm message from the client 2100 * @param nm message from the client
2113 */ 2101 */
2114static void 2102static void
2115handle_monitor_next (void *cls, const struct ZoneMonitorNextMessage *nm) 2103handle_monitor_next(void *cls, const struct ZoneMonitorNextMessage *nm)
2116{ 2104{
2117 struct NamestoreClient *nc = cls; 2105 struct NamestoreClient *nc = cls;
2118 struct ZoneMonitor *zm; 2106 struct ZoneMonitor *zm;
2119 uint64_t inc; 2107 uint64_t inc;
2120 2108
2121 inc = GNUNET_ntohll (nm->limit); 2109 inc = GNUNET_ntohll(nm->limit);
2122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2110 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2123 "Received ZONE_MONITOR_NEXT message with limit %llu\n", 2111 "Received ZONE_MONITOR_NEXT message with limit %llu\n",
2124 (unsigned long long) inc); 2112 (unsigned long long)inc);
2125 for (zm = monitor_head; NULL != zm; zm = zm->next) 2113 for (zm = monitor_head; NULL != zm; zm = zm->next)
2126 if (zm->nc == nc) 2114 if (zm->nc == nc)
2127 break; 2115 break;
2128 if (NULL == zm) 2116 if (NULL == zm)
2129 { 2117 {
2130 GNUNET_break (0); 2118 GNUNET_break(0);
2131 GNUNET_SERVICE_client_drop (nc->client); 2119 GNUNET_SERVICE_client_drop(nc->client);
2132 return; 2120 return;
2133 } 2121 }
2134 GNUNET_SERVICE_client_continue (nc->client); 2122 GNUNET_SERVICE_client_continue(nc->client);
2135 if (zm->limit + inc < zm->limit) 2123 if (zm->limit + inc < zm->limit)
2136 { 2124 {
2137 GNUNET_break (0); 2125 GNUNET_break(0);
2138 GNUNET_SERVICE_client_drop (nc->client); 2126 GNUNET_SERVICE_client_drop(nc->client);
2139 return; 2127 return;
2140 } 2128 }
2141 zm->limit += inc; 2129 zm->limit += inc;
2142 if ((zm->in_first_iteration) && (zm->limit == inc)) 2130 if ((zm->in_first_iteration) && (zm->limit == inc))
2143 { 2131 {
2144 /* We are still iterating, and the previous iteration must 2132 /* We are still iterating, and the previous iteration must
2145 have stopped due to the client's limit, so continue it! */ 2133 have stopped due to the client's limit, so continue it! */
2146 GNUNET_assert (NULL == zm->task); 2134 GNUNET_assert(NULL == zm->task);
2147 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next, zm); 2135 zm->task = GNUNET_SCHEDULER_add_now(&monitor_iteration_next, zm);
2148 } 2136 }
2149 GNUNET_assert (zm->iteration_cnt <= zm->limit); 2137 GNUNET_assert(zm->iteration_cnt <= zm->limit);
2150 if ((zm->limit > zm->iteration_cnt) && (zm->sa_waiting)) 2138 if ((zm->limit > zm->iteration_cnt) && (zm->sa_waiting))
2151 { 2139 {
2152 monitor_unblock (zm); 2140 monitor_unblock(zm);
2153 } 2141 }
2154 else if (GNUNET_YES == zm->sa_waiting) 2142 else if (GNUNET_YES == zm->sa_waiting)
2155 { 2143 {
2156 if (NULL != zm->sa_wait_warning) 2144 if (NULL != zm->sa_wait_warning)
2157 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); 2145 GNUNET_SCHEDULER_cancel(zm->sa_wait_warning);
2158 zm->sa_waiting_start = GNUNET_TIME_absolute_get (); 2146 zm->sa_waiting_start = GNUNET_TIME_absolute_get();
2159 zm->sa_wait_warning = 2147 zm->sa_wait_warning =
2160 GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, 2148 GNUNET_SCHEDULER_add_delayed(MONITOR_STALL_WARN_DELAY,
2161 &warn_monitor_slow, 2149 &warn_monitor_slow,
2162 zm); 2150 zm);
2163 } 2151 }
2164} 2152}
2165 2153
2166 2154
@@ -2172,92 +2160,92 @@ handle_monitor_next (void *cls, const struct ZoneMonitorNextMessage *nm)
2172 * @param service the initialized service 2160 * @param service the initialized service
2173 */ 2161 */
2174static void 2162static void
2175run (void *cls, 2163run(void *cls,
2176 const struct GNUNET_CONFIGURATION_Handle *cfg, 2164 const struct GNUNET_CONFIGURATION_Handle *cfg,
2177 struct GNUNET_SERVICE_Handle *service) 2165 struct GNUNET_SERVICE_Handle *service)
2178{ 2166{
2179 char *database; 2167 char *database;
2180 2168
2181 (void) cls; 2169 (void)cls;
2182 (void) service; 2170 (void)service;
2183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); 2171 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
2184 cache_keys = 2172 cache_keys =
2185 GNUNET_CONFIGURATION_get_value_yesno (cfg, "namestore", "CACHE_KEYS"); 2173 GNUNET_CONFIGURATION_get_value_yesno(cfg, "namestore", "CACHE_KEYS");
2186 disable_namecache = 2174 disable_namecache =
2187 GNUNET_CONFIGURATION_get_value_yesno (cfg, "namecache", "DISABLE"); 2175 GNUNET_CONFIGURATION_get_value_yesno(cfg, "namecache", "DISABLE");
2188 GSN_cfg = cfg; 2176 GSN_cfg = cfg;
2189 monitor_nc = GNUNET_notification_context_create (1); 2177 monitor_nc = GNUNET_notification_context_create(1);
2190 if (GNUNET_YES != disable_namecache) 2178 if (GNUNET_YES != disable_namecache)
2191 { 2179 {
2192 namecache = GNUNET_NAMECACHE_connect (cfg); 2180 namecache = GNUNET_NAMECACHE_connect(cfg);
2193 GNUNET_assert (NULL != namecache); 2181 GNUNET_assert(NULL != namecache);
2194 } 2182 }
2195 /* Loading database plugin */ 2183 /* Loading database plugin */
2196 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 2184 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg,
2197 "namestore", 2185 "namestore",
2198 "database", 2186 "database",
2199 &database)) 2187 &database))
2200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); 2188 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
2201 2189
2202 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); 2190 GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_namestore_%s", database);
2203 GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg); 2191 GSN_database = GNUNET_PLUGIN_load(db_lib_name, (void *)GSN_cfg);
2204 GNUNET_free (database); 2192 GNUNET_free(database);
2205 statistics = GNUNET_STATISTICS_create ("namestore", cfg); 2193 statistics = GNUNET_STATISTICS_create("namestore", cfg);
2206 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 2194 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL);
2207 if (NULL == GSN_database) 2195 if (NULL == GSN_database)
2208 { 2196 {
2209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2197 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2210 "Could not load database backend `%s'\n", 2198 "Could not load database backend `%s'\n",
2211 db_lib_name); 2199 db_lib_name);
2212 GNUNET_SCHEDULER_shutdown (); 2200 GNUNET_SCHEDULER_shutdown();
2213 return; 2201 return;
2214 } 2202 }
2215} 2203}
2216 2204
2217 2205
2218/** 2206/**
2219 * Define "main" method using service macro. 2207 * Define "main" method using service macro.
2220 */ 2208 */
2221GNUNET_SERVICE_MAIN ( 2209GNUNET_SERVICE_MAIN(
2222 "namestore", 2210 "namestore",
2223 GNUNET_SERVICE_OPTION_NONE, 2211 GNUNET_SERVICE_OPTION_NONE,
2224 &run, 2212 &run,
2225 &client_connect_cb, 2213 &client_connect_cb,
2226 &client_disconnect_cb, 2214 &client_disconnect_cb,
2227 NULL, 2215 NULL,
2228 GNUNET_MQ_hd_var_size (record_store, 2216 GNUNET_MQ_hd_var_size(record_store,
2229 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 2217 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE,
2230 struct RecordStoreMessage, 2218 struct RecordStoreMessage,
2231 NULL), 2219 NULL),
2232 GNUNET_MQ_hd_var_size (record_lookup, 2220 GNUNET_MQ_hd_var_size(record_lookup,
2233 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, 2221 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP,
2234 struct LabelLookupMessage, 2222 struct LabelLookupMessage,
2235 NULL), 2223 NULL),
2236 GNUNET_MQ_hd_fixed_size (zone_to_name, 2224 GNUNET_MQ_hd_fixed_size(zone_to_name,
2237 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 2225 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME,
2238 struct ZoneToNameMessage, 2226 struct ZoneToNameMessage,
2239 NULL), 2227 NULL),
2240 GNUNET_MQ_hd_fixed_size (iteration_start, 2228 GNUNET_MQ_hd_fixed_size(iteration_start,
2241 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, 2229 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START,
2242 struct ZoneIterationStartMessage, 2230 struct ZoneIterationStartMessage,
2243 NULL), 2231 NULL),
2244 GNUNET_MQ_hd_fixed_size (iteration_next, 2232 GNUNET_MQ_hd_fixed_size(iteration_next,
2245 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 2233 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT,
2246 struct ZoneIterationNextMessage, 2234 struct ZoneIterationNextMessage,
2247 NULL), 2235 NULL),
2248 GNUNET_MQ_hd_fixed_size (iteration_stop, 2236 GNUNET_MQ_hd_fixed_size(iteration_stop,
2249 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 2237 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP,
2250 struct ZoneIterationStopMessage, 2238 struct ZoneIterationStopMessage,
2251 NULL), 2239 NULL),
2252 GNUNET_MQ_hd_fixed_size (monitor_start, 2240 GNUNET_MQ_hd_fixed_size(monitor_start,
2253 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, 2241 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START,
2254 struct ZoneMonitorStartMessage, 2242 struct ZoneMonitorStartMessage,
2255 NULL), 2243 NULL),
2256 GNUNET_MQ_hd_fixed_size (monitor_next, 2244 GNUNET_MQ_hd_fixed_size(monitor_next,
2257 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT, 2245 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT,
2258 struct ZoneMonitorNextMessage, 2246 struct ZoneMonitorNextMessage,
2259 NULL), 2247 NULL),
2260 GNUNET_MQ_handler_end ()); 2248 GNUNET_MQ_handler_end());
2261 2249
2262 2250
2263/* end of gnunet-service-namestore.c */ 2251/* end of gnunet-service-namestore.c */
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index 4c5205ab3..60d8b0537 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file src/namestore/gnunet-zoneimport.c 21 * @file src/namestore/gnunet-zoneimport.c
22 * @brief import a DNS zone for publication in GNS, incremental 22 * @brief import a DNS zone for publication in GNS, incremental
@@ -57,7 +57,7 @@
57 * How long do we wait at least between series of requests? 57 * How long do we wait at least between series of requests?
58 */ 58 */
59#define SERIES_DELAY \ 59#define SERIES_DELAY \
60 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) 60 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MICROSECONDS, 10)
61 61
62/** 62/**
63 * How long do DNS records have to last at least after being imported? 63 * How long do DNS records have to last at least after being imported?
@@ -76,9 +76,7 @@ static struct GNUNET_TIME_Relative minimum_expiration_time;
76 * each dot represents a zone cut, we then need to create a 76 * each dot represents a zone cut, we then need to create a
77 * zone on-the-fly to capture those records properly. 77 * zone on-the-fly to capture those records properly.
78 */ 78 */
79struct Zone 79struct Zone {
80{
81
82 /** 80 /**
83 * Kept in a DLL. 81 * Kept in a DLL.
84 */ 82 */
@@ -104,8 +102,7 @@ struct Zone
104/** 102/**
105 * Record for the request to be stored by GNS. 103 * Record for the request to be stored by GNS.
106 */ 104 */
107struct Record 105struct Record {
108{
109 /** 106 /**
110 * Kept in a DLL. 107 * Kept in a DLL.
111 */ 108 */
@@ -128,8 +125,7 @@ struct Record
128 * thus optimizing it is crucial for the overall memory consumption of 125 * thus optimizing it is crucial for the overall memory consumption of
129 * the zone importer. 126 * the zone importer.
130 */ 127 */
131struct Request 128struct Request {
132{
133 /** 129 /**
134 * Requests are kept in a heap while waiting to be resolved. 130 * Requests are kept in a heap while waiting to be resolved.
135 */ 131 */
@@ -379,28 +375,28 @@ typedef void (*RecordProcessor) (void *cls,
379 * @param rp_cls closure for @a rp 375 * @param rp_cls closure for @a rp
380 */ 376 */
381static void 377static void
382for_all_records (const struct GNUNET_DNSPARSER_Packet *p, 378for_all_records(const struct GNUNET_DNSPARSER_Packet *p,
383 RecordProcessor rp, 379 RecordProcessor rp,
384 void *rp_cls) 380 void *rp_cls)
385{ 381{
386 for (unsigned int i = 0; i < p->num_answers; i++) 382 for (unsigned int i = 0; i < p->num_answers; i++)
387 { 383 {
388 struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; 384 struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
389 385
390 rp (rp_cls, rs); 386 rp(rp_cls, rs);
391 } 387 }
392 for (unsigned int i = 0; i < p->num_authority_records; i++) 388 for (unsigned int i = 0; i < p->num_authority_records; i++)
393 { 389 {
394 struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; 390 struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
395 391
396 rp (rp_cls, rs); 392 rp(rp_cls, rs);
397 } 393 }
398 for (unsigned int i = 0; i < p->num_additional_records; i++) 394 for (unsigned int i = 0; i < p->num_additional_records; i++)
399 { 395 {
400 struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; 396 struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
401 397
402 rp (rp_cls, rs); 398 rp(rp_cls, rs);
403 } 399 }
404} 400}
405 401
406 402
@@ -412,23 +408,23 @@ for_all_records (const struct GNUNET_DNSPARSER_Packet *p,
412 * overwritten upon the next request! 408 * overwritten upon the next request!
413 */ 409 */
414static const char * 410static const char *
415get_label (struct Request *req) 411get_label(struct Request *req)
416{ 412{
417 static char label[64]; 413 static char label[64];
418 const char *dot; 414 const char *dot;
419 415
420 dot = strchr (req->hostname, (unsigned char) '.'); 416 dot = strchr(req->hostname, (unsigned char)'.');
421 if (NULL == dot) 417 if (NULL == dot)
422 { 418 {
423 GNUNET_break (0); 419 GNUNET_break(0);
424 return NULL; 420 return NULL;
425 } 421 }
426 if (((size_t) (dot - req->hostname)) >= sizeof (label)) 422 if (((size_t)(dot - req->hostname)) >= sizeof(label))
427 { 423 {
428 GNUNET_break (0); 424 GNUNET_break(0);
429 return NULL; 425 return NULL;
430 } 426 }
431 GNUNET_memcpy (label, req->hostname, dot - req->hostname); 427 GNUNET_memcpy(label, req->hostname, dot - req->hostname);
432 label[dot - req->hostname] = '\0'; 428 label[dot - req->hostname] = '\0';
433 return label; 429 return label;
434} 430}
@@ -443,7 +439,7 @@ get_label (struct Request *req)
443 * allocated query buffer 439 * allocated query buffer
444 */ 440 */
445static void * 441static void *
446build_dns_query (struct Request *req, size_t *raw_size) 442build_dns_query(struct Request *req, size_t *raw_size)
447{ 443{
448 static char raw[512]; 444 static char raw[512];
449 char *rawp; 445 char *rawp;
@@ -451,37 +447,37 @@ build_dns_query (struct Request *req, size_t *raw_size)
451 struct GNUNET_DNSPARSER_Query q; 447 struct GNUNET_DNSPARSER_Query q;
452 int ret; 448 int ret;
453 449
454 q.name = (char *) req->hostname; 450 q.name = (char *)req->hostname;
455 q.type = GNUNET_DNSPARSER_TYPE_NS; 451 q.type = GNUNET_DNSPARSER_TYPE_NS;
456 q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; 452 q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
457 453
458 memset (&p, 0, sizeof (p)); 454 memset(&p, 0, sizeof(p));
459 p.num_queries = 1; 455 p.num_queries = 1;
460 p.queries = &q; 456 p.queries = &q;
461 p.id = req->id; 457 p.id = req->id;
462 ret = GNUNET_DNSPARSER_pack (&p, UINT16_MAX, &rawp, raw_size); 458 ret = GNUNET_DNSPARSER_pack(&p, UINT16_MAX, &rawp, raw_size);
463 if (GNUNET_OK != ret) 459 if (GNUNET_OK != ret)
464 { 460 {
465 if (GNUNET_NO == ret) 461 if (GNUNET_NO == ret)
466 GNUNET_free (rawp); 462 GNUNET_free(rawp);
467 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 463 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
468 "Failed to pack query for hostname `%s'\n", 464 "Failed to pack query for hostname `%s'\n",
469 req->hostname); 465 req->hostname);
470 rejects++; 466 rejects++;
471 return NULL; 467 return NULL;
472 } 468 }
473 if (*raw_size > sizeof (raw)) 469 if (*raw_size > sizeof(raw))
474 { 470 {
475 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 471 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
476 "Failed to pack query for hostname `%s'\n", 472 "Failed to pack query for hostname `%s'\n",
477 req->hostname); 473 req->hostname);
478 rejects++; 474 rejects++;
479 GNUNET_break (0); 475 GNUNET_break(0);
480 GNUNET_free (rawp); 476 GNUNET_free(rawp);
481 return NULL; 477 return NULL;
482 } 478 }
483 GNUNET_memcpy (raw, rawp, *raw_size); 479 GNUNET_memcpy(raw, rawp, *raw_size);
484 GNUNET_free (rawp); 480 GNUNET_free(rawp);
485 return raw; 481 return raw;
486} 482}
487 483
@@ -492,16 +488,16 @@ build_dns_query (struct Request *req, size_t *raw_size)
492 * @param req request to free records of 488 * @param req request to free records of
493 */ 489 */
494static void 490static void
495free_records (struct Request *req) 491free_records(struct Request *req)
496{ 492{
497 struct Record *rec; 493 struct Record *rec;
498 494
499 /* Free records */ 495 /* Free records */
500 while (NULL != (rec = req->rec_head)) 496 while (NULL != (rec = req->rec_head))
501 { 497 {
502 GNUNET_CONTAINER_DLL_remove (req->rec_head, req->rec_tail, rec); 498 GNUNET_CONTAINER_DLL_remove(req->rec_head, req->rec_tail, rec);
503 GNUNET_free (rec); 499 GNUNET_free(rec);
504 } 500 }
505} 501}
506 502
507 503
@@ -511,10 +507,10 @@ free_records (struct Request *req)
511 * @param req request to free 507 * @param req request to free
512 */ 508 */
513static void 509static void
514free_request (struct Request *req) 510free_request(struct Request *req)
515{ 511{
516 free_records (req); 512 free_records(req);
517 GNUNET_free (req); 513 GNUNET_free(req);
518} 514}
519 515
520 516
@@ -524,7 +520,7 @@ free_request (struct Request *req)
524 * @param cls NULL 520 * @param cls NULL
525 */ 521 */
526static void 522static void
527process_queue (void *cls); 523process_queue(void *cls);
528 524
529 525
530/** 526/**
@@ -533,17 +529,17 @@ process_queue (void *cls);
533 * @param req request to insert into #req_heap 529 * @param req request to insert into #req_heap
534 */ 530 */
535static void 531static void
536insert_sorted (struct Request *req) 532insert_sorted(struct Request *req)
537{ 533{
538 req->hn = 534 req->hn =
539 GNUNET_CONTAINER_heap_insert (req_heap, req, req->expires.abs_value_us); 535 GNUNET_CONTAINER_heap_insert(req_heap, req, req->expires.abs_value_us);
540 if (req == GNUNET_CONTAINER_heap_peek (req_heap)) 536 if (req == GNUNET_CONTAINER_heap_peek(req_heap))
541 { 537 {
542 if (NULL != t) 538 if (NULL != t)
543 GNUNET_SCHEDULER_cancel (t); 539 GNUNET_SCHEDULER_cancel(t);
544 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 540 sleep_time_reg_proc = GNUNET_TIME_absolute_get();
545 t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); 541 t = GNUNET_SCHEDULER_add_at(req->expires, &process_queue, NULL);
546 } 542 }
547} 543}
548 544
549 545
@@ -557,30 +553,29 @@ insert_sorted (struct Request *req)
557 * @param data_len number of bytes in @a data 553 * @param data_len number of bytes in @a data
558 */ 554 */
559static void 555static void
560add_record (struct Request *req, 556add_record(struct Request *req,
561 uint32_t type, 557 uint32_t type,
562 struct GNUNET_TIME_Absolute expiration_time, 558 struct GNUNET_TIME_Absolute expiration_time,
563 const void *data, 559 const void *data,
564 size_t data_len) 560 size_t data_len)
565{ 561{
566 struct Record *rec; 562 struct Record *rec;
567 563
568 rec = GNUNET_malloc (sizeof (struct Record) + data_len); 564 rec = GNUNET_malloc(sizeof(struct Record) + data_len);
569 rec->grd.data = &rec[1]; 565 rec->grd.data = &rec[1];
570 rec->grd.expiration_time = expiration_time.abs_value_us; 566 rec->grd.expiration_time = expiration_time.abs_value_us;
571 rec->grd.data_size = data_len; 567 rec->grd.data_size = data_len;
572 rec->grd.record_type = type; 568 rec->grd.record_type = type;
573 rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; 569 rec->grd.flags = GNUNET_GNSRECORD_RF_NONE;
574 GNUNET_memcpy (&rec[1], data, data_len); 570 GNUNET_memcpy(&rec[1], data, data_len);
575 GNUNET_CONTAINER_DLL_insert (req->rec_head, req->rec_tail, rec); 571 GNUNET_CONTAINER_DLL_insert(req->rec_head, req->rec_tail, rec);
576} 572}
577 573
578 574
579/** 575/**
580 * Closure for #check_for_glue. 576 * Closure for #check_for_glue.
581 */ 577 */
582struct GlueClosure 578struct GlueClosure {
583{
584 /** 579 /**
585 * Overall request we are processing. 580 * Overall request we are processing.
586 */ 581 */
@@ -605,113 +600,115 @@ struct GlueClosure
605 * @param rec record that may contain glue information 600 * @param rec record that may contain glue information
606 */ 601 */
607static void 602static void
608check_for_glue (void *cls, const struct GNUNET_DNSPARSER_Record *rec) 603check_for_glue(void *cls, const struct GNUNET_DNSPARSER_Record *rec)
609{ 604{
610 struct GlueClosure *gc = cls; 605 struct GlueClosure *gc = cls;
611 char dst[65536]; 606 char dst[65536];
612 size_t dst_len; 607 size_t dst_len;
613 size_t off; 608 size_t off;
614 char ip[INET6_ADDRSTRLEN + 1]; 609 char ip[INET6_ADDRSTRLEN + 1];
615 socklen_t ip_size = (socklen_t) sizeof (ip); 610 socklen_t ip_size = (socklen_t)sizeof(ip);
616 struct GNUNET_TIME_Absolute expiration_time; 611 struct GNUNET_TIME_Absolute expiration_time;
617 struct GNUNET_TIME_Relative left; 612 struct GNUNET_TIME_Relative left;
618 613
619 if (0 != strcasecmp (rec->name, gc->ns)) 614 if (0 != strcasecmp(rec->name, gc->ns))
620 return; 615 return;
621 expiration_time = rec->expiration_time; 616 expiration_time = rec->expiration_time;
622 left = GNUNET_TIME_absolute_get_remaining (expiration_time); 617 left = GNUNET_TIME_absolute_get_remaining(expiration_time);
623 if (0 == left.rel_value_us) 618 if (0 == left.rel_value_us)
624 return; /* ignore expired glue records */ 619 return; /* ignore expired glue records */
625 /* if expiration window is too short, bump it to configured minimum */ 620 /* if expiration window is too short, bump it to configured minimum */
626 if (left.rel_value_us < minimum_expiration_time.rel_value_us) 621 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
627 expiration_time = 622 expiration_time =
628 GNUNET_TIME_relative_to_absolute (minimum_expiration_time); 623 GNUNET_TIME_relative_to_absolute(minimum_expiration_time);
629 dst_len = sizeof (dst); 624 dst_len = sizeof(dst);
630 off = 0; 625 off = 0;
631 switch (rec->type) 626 switch (rec->type)
632 {
633 case GNUNET_DNSPARSER_TYPE_A:
634 if (sizeof (struct in_addr) != rec->data.raw.data_len)
635 {
636 GNUNET_break (0);
637 return;
638 }
639 if (NULL == inet_ntop (AF_INET, rec->data.raw.data, ip, ip_size))
640 {
641 GNUNET_break (0);
642 return;
643 }
644 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
645 dst_len,
646 &off,
647 gc->req->hostname)) &&
648 (GNUNET_OK ==
649 GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip)))
650 {
651 add_record (gc->req,
652 GNUNET_GNSRECORD_TYPE_GNS2DNS,
653 expiration_time,
654 dst,
655 off);
656 gc->found = GNUNET_YES;
657 }
658 break;
659 case GNUNET_DNSPARSER_TYPE_AAAA:
660 if (sizeof (struct in6_addr) != rec->data.raw.data_len)
661 {
662 GNUNET_break (0);
663 return;
664 }
665 if (NULL == inet_ntop (AF_INET6, rec->data.raw.data, ip, ip_size))
666 {
667 GNUNET_break (0);
668 return;
669 }
670 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
671 dst_len,
672 &off,
673 gc->req->hostname)) &&
674 (GNUNET_OK ==
675 GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip)))
676 {
677 add_record (gc->req,
678 GNUNET_GNSRECORD_TYPE_GNS2DNS,
679 expiration_time,
680 dst,
681 off);
682 gc->found = GNUNET_YES;
683 }
684 break;
685 case GNUNET_DNSPARSER_TYPE_CNAME:
686 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
687 dst_len,
688 &off,
689 gc->req->hostname)) &&
690 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
691 dst_len,
692 &off,
693 rec->data.hostname)))
694 { 627 {
695 add_record (gc->req, 628 case GNUNET_DNSPARSER_TYPE_A:
696 GNUNET_GNSRECORD_TYPE_GNS2DNS, 629 if (sizeof(struct in_addr) != rec->data.raw.data_len)
697 expiration_time, 630 {
698 dst, 631 GNUNET_break(0);
699 off); 632 return;
700 gc->found = GNUNET_YES; 633 }
634 if (NULL == inet_ntop(AF_INET, rec->data.raw.data, ip, ip_size))
635 {
636 GNUNET_break(0);
637 return;
638 }
639 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
640 dst_len,
641 &off,
642 gc->req->hostname)) &&
643 (GNUNET_OK ==
644 GNUNET_DNSPARSER_builder_add_name(dst, dst_len, &off, ip)))
645 {
646 add_record(gc->req,
647 GNUNET_GNSRECORD_TYPE_GNS2DNS,
648 expiration_time,
649 dst,
650 off);
651 gc->found = GNUNET_YES;
652 }
653 break;
654
655 case GNUNET_DNSPARSER_TYPE_AAAA:
656 if (sizeof(struct in6_addr) != rec->data.raw.data_len)
657 {
658 GNUNET_break(0);
659 return;
660 }
661 if (NULL == inet_ntop(AF_INET6, rec->data.raw.data, ip, ip_size))
662 {
663 GNUNET_break(0);
664 return;
665 }
666 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
667 dst_len,
668 &off,
669 gc->req->hostname)) &&
670 (GNUNET_OK ==
671 GNUNET_DNSPARSER_builder_add_name(dst, dst_len, &off, ip)))
672 {
673 add_record(gc->req,
674 GNUNET_GNSRECORD_TYPE_GNS2DNS,
675 expiration_time,
676 dst,
677 off);
678 gc->found = GNUNET_YES;
679 }
680 break;
681
682 case GNUNET_DNSPARSER_TYPE_CNAME:
683 if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
684 dst_len,
685 &off,
686 gc->req->hostname)) &&
687 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
688 dst_len,
689 &off,
690 rec->data.hostname)))
691 {
692 add_record(gc->req,
693 GNUNET_GNSRECORD_TYPE_GNS2DNS,
694 expiration_time,
695 dst,
696 off);
697 gc->found = GNUNET_YES;
698 }
699 break;
700
701 default:
702 /* useless, do nothing */
703 break;
701 } 704 }
702 break;
703 default:
704 /* useless, do nothing */
705 break;
706 }
707} 705}
708 706
709 707
710/** 708/**
711 * Closure for #process_record(). 709 * Closure for #process_record().
712 */ 710 */
713struct ProcessRecordContext 711struct ProcessRecordContext {
714{
715 /** 712 /**
716 * Answer we got back and are currently parsing, or NULL 713 * Answer we got back and are currently parsing, or NULL
717 * if not active. 714 * if not active.
@@ -732,7 +729,7 @@ struct ProcessRecordContext
732 * @param rec response 729 * @param rec response
733 */ 730 */
734static void 731static void
735process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec) 732process_record(void *cls, const struct GNUNET_DNSPARSER_Record *rec)
736{ 733{
737 struct ProcessRecordContext *prc = cls; 734 struct ProcessRecordContext *prc = cls;
738 struct Request *req = prc->req; 735 struct Request *req = prc->req;
@@ -742,175 +739,183 @@ process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec)
742 struct GNUNET_TIME_Absolute expiration_time; 739 struct GNUNET_TIME_Absolute expiration_time;
743 struct GNUNET_TIME_Relative left; 740 struct GNUNET_TIME_Relative left;
744 741
745 dst_len = sizeof (dst); 742 dst_len = sizeof(dst);
746 off = 0; 743 off = 0;
747 records++; 744 records++;
748 if (0 != strcasecmp (rec->name, req->hostname)) 745 if (0 != strcasecmp(rec->name, req->hostname))
749 { 746 {
750 GNUNET_log ( 747 GNUNET_log(
751 GNUNET_ERROR_TYPE_DEBUG, 748 GNUNET_ERROR_TYPE_DEBUG,
752 "DNS returned record from zone `%s' of type %u while resolving `%s'\n", 749 "DNS returned record from zone `%s' of type %u while resolving `%s'\n",
753 rec->name, 750 rec->name,
754 (unsigned int) rec->type, 751 (unsigned int)rec->type,
755 req->hostname); 752 req->hostname);
756 return; /* does not match hostname, might be glue, but 753 return; /* does not match hostname, might be glue, but
757 not useful for this pass! */ 754 not useful for this pass! */
758 } 755 }
759 expiration_time = rec->expiration_time; 756 expiration_time = rec->expiration_time;
760 left = GNUNET_TIME_absolute_get_remaining (expiration_time); 757 left = GNUNET_TIME_absolute_get_remaining(expiration_time);
761 if (0 == left.rel_value_us) 758 if (0 == left.rel_value_us)
762 { 759 {
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 760 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
764 "DNS returned expired record for `%s'\n", 761 "DNS returned expired record for `%s'\n",
765 req->hostname); 762 req->hostname);
766 GNUNET_STATISTICS_update (stats, 763 GNUNET_STATISTICS_update(stats,
767 "# expired records obtained from DNS", 764 "# expired records obtained from DNS",
768 1, 765 1,
769 GNUNET_NO); 766 GNUNET_NO);
770 return; /* record expired */ 767 return; /* record expired */
771 } 768 }
772 769
773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
774 "DNS returned record that expires at %s for `%s'\n", 771 "DNS returned record that expires at %s for `%s'\n",
775 GNUNET_STRINGS_absolute_time_to_string (expiration_time), 772 GNUNET_STRINGS_absolute_time_to_string(expiration_time),
776 req->hostname); 773 req->hostname);
777 /* if expiration window is too short, bump it to configured minimum */ 774 /* if expiration window is too short, bump it to configured minimum */
778 if (left.rel_value_us < minimum_expiration_time.rel_value_us) 775 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
779 expiration_time = 776 expiration_time =
780 GNUNET_TIME_relative_to_absolute (minimum_expiration_time); 777 GNUNET_TIME_relative_to_absolute(minimum_expiration_time);
781 switch (rec->type) 778 switch (rec->type)
782 { 779 {
783 case GNUNET_DNSPARSER_TYPE_NS: { 780 case GNUNET_DNSPARSER_TYPE_NS: {
784 struct GlueClosure gc; 781 struct GlueClosure gc;
785 782
786 /* check for glue */ 783 /* check for glue */
787 gc.req = req; 784 gc.req = req;
788 gc.ns = rec->data.hostname; 785 gc.ns = rec->data.hostname;
789 gc.found = GNUNET_NO; 786 gc.found = GNUNET_NO;
790 for_all_records (prc->p, &check_for_glue, &gc); 787 for_all_records(prc->p, &check_for_glue, &gc);
791 if ((GNUNET_NO == gc.found) && 788 if ((GNUNET_NO == gc.found) &&
792 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, 789 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
790 dst_len,
791 &off,
792 req->hostname)) &&
793 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
794 dst_len,
795 &off,
796 rec->data.hostname)))
797 {
798 /* FIXME: actually check if this is out-of-bailiwick,
799 and if not request explicit resolution... */
800 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
801 "Converted OOB (`%s') NS record for `%s'\n",
802 rec->data.hostname,
803 rec->name);
804 add_record(req,
805 GNUNET_GNSRECORD_TYPE_GNS2DNS,
806 expiration_time,
807 dst,
808 off);
809 }
810 else
811 {
812 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
813 "Converted NS record for `%s' using glue\n",
814 rec->name);
815 }
816 break;
817 }
818
819 case GNUNET_DNSPARSER_TYPE_CNAME:
820 if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
793 dst_len, 821 dst_len,
794 &off, 822 &off,
795 req->hostname)) && 823 rec->data.hostname))
796 (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, 824 {
825 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
826 "Converting CNAME (`%s') record for `%s'\n",
827 rec->data.hostname,
828 rec->name);
829 add_record(req, rec->type, expiration_time, dst, off);
830 }
831 break;
832
833 case GNUNET_DNSPARSER_TYPE_DNAME:
834 /* No support for DNAME in GNS yet! FIXME: support later! */
835 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
836 "FIXME: not supported: %s DNAME %s\n",
837 rec->name,
838 rec->data.hostname);
839 break;
840
841 case GNUNET_DNSPARSER_TYPE_MX:
842 if (GNUNET_OK ==
843 GNUNET_DNSPARSER_builder_add_mx(dst, dst_len, &off, rec->data.mx))
844 {
845 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
846 "Converting MX (`%s') record for `%s'\n",
847 rec->data.mx->mxhost,
848 rec->name);
849 add_record(req, rec->type, expiration_time, dst, off);
850 }
851 break;
852
853 case GNUNET_DNSPARSER_TYPE_SOA:
854 if (GNUNET_OK ==
855 GNUNET_DNSPARSER_builder_add_soa(dst, dst_len, &off, rec->data.soa))
856 {
857 /* NOTE: GNS does not really use SOAs */
858 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
859 "Converting SOA record for `%s'\n",
860 rec->name);
861 add_record(req, rec->type, expiration_time, dst, off);
862 }
863 break;
864
865 case GNUNET_DNSPARSER_TYPE_SRV:
866 if (GNUNET_OK ==
867 GNUNET_DNSPARSER_builder_add_srv(dst, dst_len, &off, rec->data.srv))
868 {
869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
870 "Converting SRV record for `%s'\n",
871 rec->name);
872 add_record(req, rec->type, expiration_time, dst, off);
873 }
874 break;
875
876 case GNUNET_DNSPARSER_TYPE_PTR:
877 if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name(dst,
797 dst_len, 878 dst_len,
798 &off, 879 &off,
799 rec->data.hostname))) 880 rec->data.hostname))
800 { 881 {
801 /* FIXME: actually check if this is out-of-bailiwick, 882 /* !?: what does a PTR record do in a regular TLD??? */
802 and if not request explicit resolution... */ 883 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 884 "Converting PTR record for `%s' (weird)\n",
804 "Converted OOB (`%s') NS record for `%s'\n", 885 rec->name);
805 rec->data.hostname, 886 add_record(req, rec->type, expiration_time, dst, off);
806 rec->name); 887 }
807 add_record (req, 888 break;
808 GNUNET_GNSRECORD_TYPE_GNS2DNS, 889
809 expiration_time, 890 case GNUNET_DNSPARSER_TYPE_CERT:
810 dst, 891 if (GNUNET_OK ==
811 off); 892 GNUNET_DNSPARSER_builder_add_cert(dst, dst_len, &off, rec->data.cert))
812 } 893 {
813 else 894 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
814 { 895 "Converting CERT record for `%s'\n",
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 896 rec->name);
816 "Converted NS record for `%s' using glue\n", 897 add_record(req, rec->type, expiration_time, dst, off);
817 rec->name); 898 }
818 } 899 break;
819 break; 900
820 }
821 case GNUNET_DNSPARSER_TYPE_CNAME:
822 if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
823 dst_len,
824 &off,
825 rec->data.hostname))
826 {
827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
828 "Converting CNAME (`%s') record for `%s'\n",
829 rec->data.hostname,
830 rec->name);
831 add_record (req, rec->type, expiration_time, dst, off);
832 }
833 break;
834 case GNUNET_DNSPARSER_TYPE_DNAME:
835 /* No support for DNAME in GNS yet! FIXME: support later! */
836 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
837 "FIXME: not supported: %s DNAME %s\n",
838 rec->name,
839 rec->data.hostname);
840 break;
841 case GNUNET_DNSPARSER_TYPE_MX:
842 if (GNUNET_OK ==
843 GNUNET_DNSPARSER_builder_add_mx (dst, dst_len, &off, rec->data.mx))
844 {
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
846 "Converting MX (`%s') record for `%s'\n",
847 rec->data.mx->mxhost,
848 rec->name);
849 add_record (req, rec->type, expiration_time, dst, off);
850 }
851 break;
852 case GNUNET_DNSPARSER_TYPE_SOA:
853 if (GNUNET_OK ==
854 GNUNET_DNSPARSER_builder_add_soa (dst, dst_len, &off, rec->data.soa))
855 {
856 /* NOTE: GNS does not really use SOAs */
857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
858 "Converting SOA record for `%s'\n",
859 rec->name);
860 add_record (req, rec->type, expiration_time, dst, off);
861 }
862 break;
863 case GNUNET_DNSPARSER_TYPE_SRV:
864 if (GNUNET_OK ==
865 GNUNET_DNSPARSER_builder_add_srv (dst, dst_len, &off, rec->data.srv))
866 {
867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
868 "Converting SRV record for `%s'\n",
869 rec->name);
870 add_record (req, rec->type, expiration_time, dst, off);
871 }
872 break;
873 case GNUNET_DNSPARSER_TYPE_PTR:
874 if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
875 dst_len,
876 &off,
877 rec->data.hostname))
878 {
879 /* !?: what does a PTR record do in a regular TLD??? */
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
881 "Converting PTR record for `%s' (weird)\n",
882 rec->name);
883 add_record (req, rec->type, expiration_time, dst, off);
884 }
885 break;
886 case GNUNET_DNSPARSER_TYPE_CERT:
887 if (GNUNET_OK ==
888 GNUNET_DNSPARSER_builder_add_cert (dst, dst_len, &off, rec->data.cert))
889 {
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
891 "Converting CERT record for `%s'\n",
892 rec->name);
893 add_record (req, rec->type, expiration_time, dst, off);
894 }
895 break;
896 /* Rest is 'raw' encoded and just needs to be copied IF 901 /* Rest is 'raw' encoded and just needs to be copied IF
897 the hostname matches the requested name; otherwise we 902 the hostname matches the requested name; otherwise we
898 simply cannot use it. */ 903 simply cannot use it. */
899 case GNUNET_DNSPARSER_TYPE_A: 904 case GNUNET_DNSPARSER_TYPE_A:
900 case GNUNET_DNSPARSER_TYPE_AAAA: 905 case GNUNET_DNSPARSER_TYPE_AAAA:
901 case GNUNET_DNSPARSER_TYPE_TXT: 906 case GNUNET_DNSPARSER_TYPE_TXT:
902 default: 907 default:
903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
904 "Converting record of type %u for `%s'\n", 909 "Converting record of type %u for `%s'\n",
905 (unsigned int) rec->type, 910 (unsigned int)rec->type,
906 rec->name); 911 rec->name);
907 add_record (req, 912 add_record(req,
908 rec->type, 913 rec->type,
909 expiration_time, 914 expiration_time,
910 rec->data.raw.data, 915 rec->data.raw.data,
911 rec->data.raw.data_len); 916 rec->data.raw.data_len);
912 break; 917 break;
913 } 918 }
914} 919}
915 920
916 921
@@ -925,89 +930,89 @@ process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec)
925 * @param emsg NULL on success, otherwise an error message 930 * @param emsg NULL on success, otherwise an error message
926 */ 931 */
927static void 932static void
928store_completed_cb (void *cls, int32_t success, const char *emsg) 933store_completed_cb(void *cls, int32_t success, const char *emsg)
929{ 934{
930 static struct GNUNET_TIME_Absolute last; 935 static struct GNUNET_TIME_Absolute last;
931 struct Request *req = cls; 936 struct Request *req = cls;
932 937
933 req->qe = NULL; 938 req->qe = NULL;
934 if (GNUNET_SYSERR == success) 939 if (GNUNET_SYSERR == success)
935 { 940 {
936 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 941 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
937 "Failed to store zone data for `%s': %s\n", 942 "Failed to store zone data for `%s': %s\n",
938 req->hostname, 943 req->hostname,
939 emsg); 944 emsg);
940 } 945 }
941 else 946 else
942 { 947 {
943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 948 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
944 "Stored records under `%s' (%d)\n", 949 "Stored records under `%s' (%d)\n",
945 req->hostname, 950 req->hostname,
946 success); 951 success);
947 } 952 }
948 total_reg_proc_dns_ns++; /* finished regular processing */ 953 total_reg_proc_dns_ns++; /* finished regular processing */
949 pending_rs--; 954 pending_rs--;
950 free_records (req); 955 free_records(req);
951 /* compute NAMESTORE statistics */ 956 /* compute NAMESTORE statistics */
952 { 957 {
953 static uint64_t total_ns_latency_cnt; 958 static uint64_t total_ns_latency_cnt;
954 static struct GNUNET_TIME_Relative total_ns_latency; 959 static struct GNUNET_TIME_Relative total_ns_latency;
955 struct GNUNET_TIME_Relative ns_latency; 960 struct GNUNET_TIME_Relative ns_latency;
956 961
957 ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); 962 ns_latency = GNUNET_TIME_absolute_get_duration(req->op_start_time);
958 total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, ns_latency); 963 total_ns_latency = GNUNET_TIME_relative_add(total_ns_latency, ns_latency);
959 if (0 == total_ns_latency_cnt) 964 if (0 == total_ns_latency_cnt)
960 last = GNUNET_TIME_absolute_get (); 965 last = GNUNET_TIME_absolute_get();
961 total_ns_latency_cnt++; 966 total_ns_latency_cnt++;
962 if (0 == (total_ns_latency_cnt % 1000)) 967 if (0 == (total_ns_latency_cnt % 1000))
963 { 968 {
964 struct GNUNET_TIME_Relative delta; 969 struct GNUNET_TIME_Relative delta;
965 970
966 delta = GNUNET_TIME_absolute_get_duration (last); 971 delta = GNUNET_TIME_absolute_get_duration(last);
967 last = GNUNET_TIME_absolute_get (); 972 last = GNUNET_TIME_absolute_get();
968 fprintf (stderr, 973 fprintf(stderr,
969 "Processed 1000 records in %s\n", 974 "Processed 1000 records in %s\n",
970 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); 975 GNUNET_STRINGS_relative_time_to_string(delta, GNUNET_YES));
971 GNUNET_STATISTICS_set (stats, 976 GNUNET_STATISTICS_set(stats,
972 "# average NAMESTORE PUT latency (μs)", 977 "# average NAMESTORE PUT latency (μs)",
973 total_ns_latency.rel_value_us / 978 total_ns_latency.rel_value_us /
974 total_ns_latency_cnt, 979 total_ns_latency_cnt,
975 GNUNET_NO); 980 GNUNET_NO);
976 } 981 }
977 } 982 }
978 /* compute and publish overall velocity */ 983 /* compute and publish overall velocity */
979 if (0 == (total_reg_proc_dns_ns % 100)) 984 if (0 == (total_reg_proc_dns_ns % 100))
980 { 985 {
981 struct GNUNET_TIME_Relative runtime; 986 struct GNUNET_TIME_Relative runtime;
982 987
983 runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc); 988 runtime = GNUNET_TIME_absolute_get_duration(start_time_reg_proc);
984 runtime = GNUNET_TIME_relative_subtract (runtime, idle_time); 989 runtime = GNUNET_TIME_relative_subtract(runtime, idle_time);
985 runtime = 990 runtime =
986 GNUNET_TIME_relative_divide (runtime, 991 GNUNET_TIME_relative_divide(runtime,
987 total_reg_proc_dns + total_reg_proc_dns_ns); 992 total_reg_proc_dns + total_reg_proc_dns_ns);
988 GNUNET_STATISTICS_set (stats, 993 GNUNET_STATISTICS_set(stats,
989 "# Regular processing completed without NAMESTORE", 994 "# Regular processing completed without NAMESTORE",
990 total_reg_proc_dns, 995 total_reg_proc_dns,
991 GNUNET_NO); 996 GNUNET_NO);
992 GNUNET_STATISTICS_set (stats, 997 GNUNET_STATISTICS_set(stats,
993 "# Regular processing completed with NAMESTORE PUT", 998 "# Regular processing completed with NAMESTORE PUT",
994 total_reg_proc_dns_ns, 999 total_reg_proc_dns_ns,
995 GNUNET_NO); 1000 GNUNET_NO);
996 GNUNET_STATISTICS_set (stats, 1001 GNUNET_STATISTICS_set(stats,
997 "# average request processing latency (μs)", 1002 "# average request processing latency (μs)",
998 runtime.rel_value_us, 1003 runtime.rel_value_us,
999 GNUNET_NO); 1004 GNUNET_NO);
1000 GNUNET_STATISTICS_set (stats, 1005 GNUNET_STATISTICS_set(stats,
1001 "# total time spent idle (μs)", 1006 "# total time spent idle (μs)",
1002 idle_time.rel_value_us, 1007 idle_time.rel_value_us,
1003 GNUNET_NO); 1008 GNUNET_NO);
1004 } 1009 }
1005 1010
1006 if (NULL == t) 1011 if (NULL == t)
1007 { 1012 {
1008 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1013 sleep_time_reg_proc = GNUNET_TIME_absolute_get();
1009 t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); 1014 t = GNUNET_SCHEDULER_add_now(&process_queue, NULL);
1010 } 1015 }
1011} 1016}
1012 1017
1013 1018
@@ -1019,148 +1024,148 @@ store_completed_cb (void *cls, int32_t success, const char *emsg)
1019 * @param dns_len number of bytes in @a dns 1024 * @param dns_len number of bytes in @a dns
1020 */ 1025 */
1021static void 1026static void
1022process_result (void *cls, 1027process_result(void *cls,
1023 const struct GNUNET_TUN_DnsHeader *dns, 1028 const struct GNUNET_TUN_DnsHeader *dns,
1024 size_t dns_len) 1029 size_t dns_len)
1025{ 1030{
1026 struct Request *req = cls; 1031 struct Request *req = cls;
1027 struct Record *rec; 1032 struct Record *rec;
1028 struct GNUNET_DNSPARSER_Packet *p; 1033 struct GNUNET_DNSPARSER_Packet *p;
1029 unsigned int rd_count; 1034 unsigned int rd_count;
1030 1035
1031 GNUNET_assert (NULL == req->hn); 1036 GNUNET_assert(NULL == req->hn);
1032 if (NULL == dns) 1037 if (NULL == dns)
1033 {
1034 /* stub gave up */
1035 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
1036 pending--;
1037 if (NULL == t)
1038 { 1038 {
1039 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1039 /* stub gave up */
1040 t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); 1040 GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req);
1041 pending--;
1042 if (NULL == t)
1043 {
1044 sleep_time_reg_proc = GNUNET_TIME_absolute_get();
1045 t = GNUNET_SCHEDULER_add_now(&process_queue, NULL);
1046 }
1047 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1048 "Stub gave up on DNS reply for `%s'\n",
1049 req->hostname);
1050 GNUNET_STATISTICS_update(stats, "# DNS lookups timed out", 1, GNUNET_NO);
1051 if (req->issue_num > MAX_RETRIES)
1052 {
1053 failures++;
1054 free_request(req);
1055 GNUNET_STATISTICS_update(stats, "# requests given up on", 1, GNUNET_NO);
1056 return;
1057 }
1058 total_reg_proc_dns++;
1059 req->rs = NULL;
1060 insert_sorted(req);
1061 return;
1041 } 1062 }
1042 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1063 if (req->id != dns->id)
1043 "Stub gave up on DNS reply for `%s'\n",
1044 req->hostname);
1045 GNUNET_STATISTICS_update (stats, "# DNS lookups timed out", 1, GNUNET_NO);
1046 if (req->issue_num > MAX_RETRIES)
1047 { 1064 {
1048 failures++; 1065 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1049 free_request (req); 1066 "DNS ID did not match request, ignoring reply\n");
1050 GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); 1067 GNUNET_STATISTICS_update(stats, "# DNS ID mismatches", 1, GNUNET_NO);
1051 return; 1068 return;
1052 } 1069 }
1053 total_reg_proc_dns++; 1070 GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req);
1054 req->rs = NULL; 1071 GNUNET_DNSSTUB_resolve_cancel(req->rs);
1055 insert_sorted (req);
1056 return;
1057 }
1058 if (req->id != dns->id)
1059 {
1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1061 "DNS ID did not match request, ignoring reply\n");
1062 GNUNET_STATISTICS_update (stats, "# DNS ID mismatches", 1, GNUNET_NO);
1063 return;
1064 }
1065 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
1066 GNUNET_DNSSTUB_resolve_cancel (req->rs);
1067 req->rs = NULL; 1072 req->rs = NULL;
1068 pending--; 1073 pending--;
1069 p = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len); 1074 p = GNUNET_DNSPARSER_parse((const char *)dns, dns_len);
1070 if (NULL == p) 1075 if (NULL == p)
1071 {
1072 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1073 "Failed to parse DNS reply for `%s'\n",
1074 req->hostname);
1075 GNUNET_STATISTICS_update (stats, "# DNS parser errors", 1, GNUNET_NO);
1076 if (NULL == t)
1077 {
1078 sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
1079 t = GNUNET_SCHEDULER_add_now (&process_queue, NULL);
1080 }
1081 if (req->issue_num > MAX_RETRIES)
1082 { 1076 {
1083 failures++; 1077 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1084 free_request (req); 1078 "Failed to parse DNS reply for `%s'\n",
1085 GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); 1079 req->hostname);
1080 GNUNET_STATISTICS_update(stats, "# DNS parser errors", 1, GNUNET_NO);
1081 if (NULL == t)
1082 {
1083 sleep_time_reg_proc = GNUNET_TIME_absolute_get();
1084 t = GNUNET_SCHEDULER_add_now(&process_queue, NULL);
1085 }
1086 if (req->issue_num > MAX_RETRIES)
1087 {
1088 failures++;
1089 free_request(req);
1090 GNUNET_STATISTICS_update(stats, "# requests given up on", 1, GNUNET_NO);
1091 return;
1092 }
1093 insert_sorted(req);
1086 return; 1094 return;
1087 } 1095 }
1088 insert_sorted (req);
1089 return;
1090 }
1091 /* import new records */ 1096 /* import new records */
1092 req->issue_num = 0; /* success, reset counter! */ 1097 req->issue_num = 0; /* success, reset counter! */
1093 { 1098 {
1094 struct ProcessRecordContext prc = {.req = req, .p = p}; 1099 struct ProcessRecordContext prc = { .req = req, .p = p };
1095 1100
1096 for_all_records (p, &process_record, &prc); 1101 for_all_records(p, &process_record, &prc);
1097 } 1102 }
1098 GNUNET_DNSPARSER_free_packet (p); 1103 GNUNET_DNSPARSER_free_packet(p);
1099 /* count records found, determine minimum expiration time */ 1104 /* count records found, determine minimum expiration time */
1100 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; 1105 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS;
1101 { 1106 {
1102 struct GNUNET_TIME_Relative dns_latency; 1107 struct GNUNET_TIME_Relative dns_latency;
1103 1108
1104 dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); 1109 dns_latency = GNUNET_TIME_absolute_get_duration(req->op_start_time);
1105 total_dns_latency = 1110 total_dns_latency =
1106 GNUNET_TIME_relative_add (total_dns_latency, dns_latency); 1111 GNUNET_TIME_relative_add(total_dns_latency, dns_latency);
1107 total_dns_latency_cnt++; 1112 total_dns_latency_cnt++;
1108 if (0 == (total_dns_latency_cnt % 1000)) 1113 if (0 == (total_dns_latency_cnt % 1000))
1109 { 1114 {
1110 GNUNET_STATISTICS_set (stats, 1115 GNUNET_STATISTICS_set(stats,
1111 "# average DNS lookup latency (μs)", 1116 "# average DNS lookup latency (μs)",
1112 total_dns_latency.rel_value_us / 1117 total_dns_latency.rel_value_us /
1113 total_dns_latency_cnt, 1118 total_dns_latency_cnt,
1114 GNUNET_NO); 1119 GNUNET_NO);
1115 } 1120 }
1116 } 1121 }
1117 rd_count = 0; 1122 rd_count = 0;
1118 for (rec = req->rec_head; NULL != rec; rec = rec->next) 1123 for (rec = req->rec_head; NULL != rec; rec = rec->next)
1119 { 1124 {
1120 struct GNUNET_TIME_Absolute at; 1125 struct GNUNET_TIME_Absolute at;
1121 1126
1122 at.abs_value_us = rec->grd.expiration_time; 1127 at.abs_value_us = rec->grd.expiration_time;
1123 req->expires = GNUNET_TIME_absolute_min (req->expires, at); 1128 req->expires = GNUNET_TIME_absolute_min(req->expires, at);
1124 rd_count++; 1129 rd_count++;
1125 } 1130 }
1126 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1131 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1127 "Obtained %u records for `%s'\n", 1132 "Obtained %u records for `%s'\n",
1128 rd_count, 1133 rd_count,
1129 req->hostname); 1134 req->hostname);
1130 /* Instead of going for SOA, simplified for now to look each 1135 /* Instead of going for SOA, simplified for now to look each
1131 day in case we got an empty response */ 1136 day in case we got an empty response */
1132 if (0 == rd_count) 1137 if (0 == rd_count)
1133 { 1138 {
1134 req->expires = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); 1139 req->expires = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_DAYS);
1135 GNUNET_STATISTICS_update (stats, 1140 GNUNET_STATISTICS_update(stats,
1136 "# empty DNS replies (usually NXDOMAIN)", 1141 "# empty DNS replies (usually NXDOMAIN)",
1137 1, 1142 1,
1138 GNUNET_NO); 1143 GNUNET_NO);
1139 } 1144 }
1140 else 1145 else
1141 { 1146 {
1142 record_sets++; 1147 record_sets++;
1143 } 1148 }
1144 /* convert records to namestore import format */ 1149 /* convert records to namestore import format */
1145 { 1150 {
1146 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; 1151 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
1147 unsigned int off = 0; 1152 unsigned int off = 0;
1148 1153
1149 /* convert linked list into array */ 1154 /* convert linked list into array */
1150 for (rec = req->rec_head; NULL != rec; rec = rec->next) 1155 for (rec = req->rec_head; NULL != rec; rec = rec->next)
1151 rd[off++] = rec->grd; 1156 rd[off++] = rec->grd;
1152 pending_rs++; 1157 pending_rs++;
1153 req->op_start_time = GNUNET_TIME_absolute_get (); 1158 req->op_start_time = GNUNET_TIME_absolute_get();
1154 req->qe = GNUNET_NAMESTORE_records_store (ns, 1159 req->qe = GNUNET_NAMESTORE_records_store(ns,
1155 &req->zone->key, 1160 &req->zone->key,
1156 get_label (req), 1161 get_label(req),
1157 rd_count, 1162 rd_count,
1158 rd, 1163 rd,
1159 &store_completed_cb, 1164 &store_completed_cb,
1160 req); 1165 req);
1161 GNUNET_assert (NULL != req->qe); 1166 GNUNET_assert(NULL != req->qe);
1162 } 1167 }
1163 insert_sorted (req); 1168 insert_sorted(req);
1164} 1169}
1165 1170
1166 1171
@@ -1170,7 +1175,7 @@ process_result (void *cls,
1170 * @param cls NULL 1175 * @param cls NULL
1171 */ 1176 */
1172static void 1177static void
1173process_queue (void *cls) 1178process_queue(void *cls)
1174{ 1179{
1175 struct Request *req; 1180 struct Request *req;
1176 unsigned int series; 1181 unsigned int series;
@@ -1178,82 +1183,82 @@ process_queue (void *cls)
1178 size_t raw_size; 1183 size_t raw_size;
1179 struct GNUNET_TIME_Relative delay; 1184 struct GNUNET_TIME_Relative delay;
1180 1185
1181 (void) cls; 1186 (void)cls;
1182 delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc); 1187 delay = GNUNET_TIME_absolute_get_duration(sleep_time_reg_proc);
1183 idle_time = GNUNET_TIME_relative_add (idle_time, delay); 1188 idle_time = GNUNET_TIME_relative_add(idle_time, delay);
1184 series = 0; 1189 series = 0;
1185 t = NULL; 1190 t = NULL;
1186 while (pending + pending_rs < THRESH) 1191 while (pending + pending_rs < THRESH)
1187 {
1188 req = GNUNET_CONTAINER_heap_peek (req_heap);
1189 if (NULL == req)
1190 break;
1191 if (NULL != req->qe)
1192 return; /* namestore op still pending */
1193 if (NULL != req->rs)
1194 { 1192 {
1195 GNUNET_break (0); 1193 req = GNUNET_CONTAINER_heap_peek(req_heap);
1196 return; /* already submitted */ 1194 if (NULL == req)
1195 break;
1196 if (NULL != req->qe)
1197 return; /* namestore op still pending */
1198 if (NULL != req->rs)
1199 {
1200 GNUNET_break(0);
1201 return; /* already submitted */
1202 }
1203 if (GNUNET_TIME_absolute_get_remaining(req->expires).rel_value_us > 0)
1204 break;
1205 GNUNET_assert(req == GNUNET_CONTAINER_heap_remove_root(req_heap));
1206 req->hn = NULL;
1207 GNUNET_CONTAINER_DLL_insert(req_head, req_tail, req);
1208 GNUNET_assert(NULL == req->rs);
1209 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1210 "Requesting resolution for `%s'\n",
1211 req->hostname);
1212 raw = build_dns_query(req, &raw_size);
1213 if (NULL == raw)
1214 {
1215 GNUNET_break(0);
1216 free_request(req);
1217 continue;
1218 }
1219 req->op_start_time = GNUNET_TIME_absolute_get();
1220 req->rs = GNUNET_DNSSTUB_resolve(ctx, raw, raw_size, &process_result, req);
1221 GNUNET_assert(NULL != req->rs);
1222 req->issue_num++;
1223 lookups++;
1224 pending++;
1225 series++;
1226 if (series > MAX_SERIES)
1227 break;
1197 } 1228 }
1198 if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) 1229 if (pending + pending_rs >= THRESH)
1199 break;
1200 GNUNET_assert (req == GNUNET_CONTAINER_heap_remove_root (req_heap));
1201 req->hn = NULL;
1202 GNUNET_CONTAINER_DLL_insert (req_head, req_tail, req);
1203 GNUNET_assert (NULL == req->rs);
1204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1205 "Requesting resolution for `%s'\n",
1206 req->hostname);
1207 raw = build_dns_query (req, &raw_size);
1208 if (NULL == raw)
1209 { 1230 {
1210 GNUNET_break (0); 1231 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1211 free_request (req); 1232 "Stopped processing queue (%u+%u/%u)]\n",
1212 continue; 1233 pending,
1234 pending_rs,
1235 THRESH);
1236 return; /* wait for replies */
1213 } 1237 }
1214 req->op_start_time = GNUNET_TIME_absolute_get (); 1238 req = GNUNET_CONTAINER_heap_peek(req_heap);
1215 req->rs = GNUNET_DNSSTUB_resolve (ctx, raw, raw_size, &process_result, req);
1216 GNUNET_assert (NULL != req->rs);
1217 req->issue_num++;
1218 lookups++;
1219 pending++;
1220 series++;
1221 if (series > MAX_SERIES)
1222 break;
1223 }
1224 if (pending + pending_rs >= THRESH)
1225 {
1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1227 "Stopped processing queue (%u+%u/%u)]\n",
1228 pending,
1229 pending_rs,
1230 THRESH);
1231 return; /* wait for replies */
1232 }
1233 req = GNUNET_CONTAINER_heap_peek (req_heap);
1234 if (NULL == req) 1239 if (NULL == req)
1235 { 1240 {
1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1241 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1237 "Stopped processing queue: empty queue\n"); 1242 "Stopped processing queue: empty queue\n");
1238 return; 1243 return;
1239 } 1244 }
1240 if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) 1245 if (GNUNET_TIME_absolute_get_remaining(req->expires).rel_value_us > 0)
1241 { 1246 {
1242 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1247 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1243 "Waiting until %s for next record (`%s') to expire\n", 1248 "Waiting until %s for next record (`%s') to expire\n",
1244 GNUNET_STRINGS_absolute_time_to_string (req->expires), 1249 GNUNET_STRINGS_absolute_time_to_string(req->expires),
1245 req->hostname); 1250 req->hostname);
1246 if (NULL != t) 1251 if (NULL != t)
1247 GNUNET_SCHEDULER_cancel (t); 1252 GNUNET_SCHEDULER_cancel(t);
1248 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1253 sleep_time_reg_proc = GNUNET_TIME_absolute_get();
1249 t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); 1254 t = GNUNET_SCHEDULER_add_at(req->expires, &process_queue, NULL);
1250 return; 1255 return;
1251 } 1256 }
1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Throttling\n"); 1257 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Throttling\n");
1253 if (NULL != t) 1258 if (NULL != t)
1254 GNUNET_SCHEDULER_cancel (t); 1259 GNUNET_SCHEDULER_cancel(t);
1255 sleep_time_reg_proc = GNUNET_TIME_absolute_get (); 1260 sleep_time_reg_proc = GNUNET_TIME_absolute_get();
1256 t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, &process_queue, NULL); 1261 t = GNUNET_SCHEDULER_add_delayed(SERIES_DELAY, &process_queue, NULL);
1257} 1262}
1258 1263
1259 1264
@@ -1267,13 +1272,13 @@ process_queue (void *cls)
1267 * @return #GNUNET_OK 1272 * @return #GNUNET_OK
1268 */ 1273 */
1269static int 1274static int
1270free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value) 1275free_request_it(void *cls, const struct GNUNET_HashCode *key, void *value)
1271{ 1276{
1272 struct Request *req = value; 1277 struct Request *req = value;
1273 1278
1274 (void) cls; 1279 (void)cls;
1275 (void) key; 1280 (void)key;
1276 free_request (req); 1281 free_request(req);
1277 return GNUNET_OK; 1282 return GNUNET_OK;
1278} 1283}
1279 1284
@@ -1284,73 +1289,73 @@ free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value)
1284 * @param cls NULL 1289 * @param cls NULL
1285 */ 1290 */
1286static void 1291static void
1287do_shutdown (void *cls) 1292do_shutdown(void *cls)
1288{ 1293{
1289 struct Request *req; 1294 struct Request *req;
1290 struct Zone *zone; 1295 struct Zone *zone;
1291 1296
1292 (void) cls; 1297 (void)cls;
1293 if (NULL != id) 1298 if (NULL != id)
1294 { 1299 {
1295 GNUNET_IDENTITY_disconnect (id); 1300 GNUNET_IDENTITY_disconnect(id);
1296 id = NULL; 1301 id = NULL;
1297 } 1302 }
1298 if (NULL != t) 1303 if (NULL != t)
1299 { 1304 {
1300 GNUNET_SCHEDULER_cancel (t); 1305 GNUNET_SCHEDULER_cancel(t);
1301 t = NULL; 1306 t = NULL;
1302 } 1307 }
1303 while (NULL != (req = req_head)) 1308 while (NULL != (req = req_head))
1304 { 1309 {
1305 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); 1310 GNUNET_CONTAINER_DLL_remove(req_head, req_tail, req);
1306 if (NULL != req->qe) 1311 if (NULL != req->qe)
1307 GNUNET_NAMESTORE_cancel (req->qe); 1312 GNUNET_NAMESTORE_cancel(req->qe);
1308 free_request (req); 1313 free_request(req);
1309 } 1314 }
1310 while (NULL != (req = GNUNET_CONTAINER_heap_remove_root (req_heap))) 1315 while (NULL != (req = GNUNET_CONTAINER_heap_remove_root(req_heap)))
1311 { 1316 {
1312 req->hn = NULL; 1317 req->hn = NULL;
1313 if (NULL != req->qe) 1318 if (NULL != req->qe)
1314 GNUNET_NAMESTORE_cancel (req->qe); 1319 GNUNET_NAMESTORE_cancel(req->qe);
1315 free_request (req); 1320 free_request(req);
1316 } 1321 }
1317 if (NULL != zone_it) 1322 if (NULL != zone_it)
1318 { 1323 {
1319 GNUNET_NAMESTORE_zone_iteration_stop (zone_it); 1324 GNUNET_NAMESTORE_zone_iteration_stop(zone_it);
1320 zone_it = NULL; 1325 zone_it = NULL;
1321 } 1326 }
1322 if (NULL != ns) 1327 if (NULL != ns)
1323 { 1328 {
1324 GNUNET_NAMESTORE_disconnect (ns); 1329 GNUNET_NAMESTORE_disconnect(ns);
1325 ns = NULL; 1330 ns = NULL;
1326 } 1331 }
1327 if (NULL != ctx) 1332 if (NULL != ctx)
1328 { 1333 {
1329 GNUNET_DNSSTUB_stop (ctx); 1334 GNUNET_DNSSTUB_stop(ctx);
1330 ctx = NULL; 1335 ctx = NULL;
1331 } 1336 }
1332 if (NULL != req_heap) 1337 if (NULL != req_heap)
1333 { 1338 {
1334 GNUNET_CONTAINER_heap_destroy (req_heap); 1339 GNUNET_CONTAINER_heap_destroy(req_heap);
1335 req_heap = NULL; 1340 req_heap = NULL;
1336 } 1341 }
1337 if (NULL != ns_pending) 1342 if (NULL != ns_pending)
1338 { 1343 {
1339 GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &free_request_it, NULL); 1344 GNUNET_CONTAINER_multihashmap_iterate(ns_pending, &free_request_it, NULL);
1340 GNUNET_CONTAINER_multihashmap_destroy (ns_pending); 1345 GNUNET_CONTAINER_multihashmap_destroy(ns_pending);
1341 ns_pending = NULL; 1346 ns_pending = NULL;
1342 } 1347 }
1343 while (NULL != (zone = zone_head)) 1348 while (NULL != (zone = zone_head))
1344 { 1349 {
1345 GNUNET_CONTAINER_DLL_remove (zone_head, zone_tail, zone); 1350 GNUNET_CONTAINER_DLL_remove(zone_head, zone_tail, zone);
1346 GNUNET_free (zone->domain); 1351 GNUNET_free(zone->domain);
1347 GNUNET_free (zone); 1352 GNUNET_free(zone);
1348 } 1353 }
1349 if (NULL != stats) 1354 if (NULL != stats)
1350 { 1355 {
1351 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 1356 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
1352 stats = NULL; 1357 stats = NULL;
1353 } 1358 }
1354} 1359}
1355 1360
1356 1361
@@ -1361,7 +1366,7 @@ do_shutdown (void *cls)
1361 * @param cls NULL 1366 * @param cls NULL
1362 */ 1367 */
1363static void 1368static void
1364iterate_zones (void *cls); 1369iterate_zones(void *cls);
1365 1370
1366 1371
1367/** 1372/**
@@ -1371,16 +1376,16 @@ iterate_zones (void *cls);
1371 * @param cls a `struct Zone` 1376 * @param cls a `struct Zone`
1372 */ 1377 */
1373static void 1378static void
1374ns_lookup_error_cb (void *cls) 1379ns_lookup_error_cb(void *cls)
1375{ 1380{
1376 struct Zone *zone = cls; 1381 struct Zone *zone = cls;
1377 1382
1378 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1383 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1379 "Failed to load data from namestore for zone `%s'\n", 1384 "Failed to load data from namestore for zone `%s'\n",
1380 zone->domain); 1385 zone->domain);
1381 zone_it = NULL; 1386 zone_it = NULL;
1382 ns_iterator_trigger_next = 0; 1387 ns_iterator_trigger_next = 0;
1383 iterate_zones (NULL); 1388 iterate_zones(NULL);
1384} 1389}
1385 1390
1386 1391
@@ -1394,11 +1399,11 @@ ns_lookup_error_cb (void *cls)
1394 * @param rd array of records with data to store 1399 * @param rd array of records with data to store
1395 */ 1400 */
1396static void 1401static void
1397ns_lookup_result_cb (void *cls, 1402ns_lookup_result_cb(void *cls,
1398 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 1403 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
1399 const char *label, 1404 const char *label,
1400 unsigned int rd_count, 1405 unsigned int rd_count,
1401 const struct GNUNET_GNSRECORD_Data *rd) 1406 const struct GNUNET_GNSRECORD_Data *rd)
1402{ 1407{
1403 struct Zone *zone = cls; 1408 struct Zone *zone = cls;
1404 struct Request *req; 1409 struct Request *req;
@@ -1406,85 +1411,85 @@ ns_lookup_result_cb (void *cls,
1406 char *fqdn; 1411 char *fqdn;
1407 1412
1408 ns_iterator_trigger_next--; 1413 ns_iterator_trigger_next--;
1409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1414 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1410 "Obtained NAMESTORE reply, %llu left in round\n", 1415 "Obtained NAMESTORE reply, %llu left in round\n",
1411 (unsigned long long) ns_iterator_trigger_next); 1416 (unsigned long long)ns_iterator_trigger_next);
1412 if (0 == ns_iterator_trigger_next) 1417 if (0 == ns_iterator_trigger_next)
1413 { 1418 {
1414 ns_iterator_trigger_next = NS_BATCH_SIZE; 1419 ns_iterator_trigger_next = NS_BATCH_SIZE;
1415 GNUNET_STATISTICS_update (stats, 1420 GNUNET_STATISTICS_update(stats,
1416 "# NAMESTORE records requested from cache", 1421 "# NAMESTORE records requested from cache",
1417 ns_iterator_trigger_next, 1422 ns_iterator_trigger_next,
1418 GNUNET_NO); 1423 GNUNET_NO);
1419 GNUNET_NAMESTORE_zone_iterator_next (zone_it, ns_iterator_trigger_next); 1424 GNUNET_NAMESTORE_zone_iterator_next(zone_it, ns_iterator_trigger_next);
1420 } 1425 }
1421 GNUNET_asprintf (&fqdn, "%s.%s", label, zone->domain); 1426 GNUNET_asprintf(&fqdn, "%s.%s", label, zone->domain);
1422 GNUNET_CRYPTO_hash (fqdn, strlen (fqdn) + 1, &hc); 1427 GNUNET_CRYPTO_hash(fqdn, strlen(fqdn) + 1, &hc);
1423 GNUNET_free (fqdn); 1428 GNUNET_free(fqdn);
1424 req = GNUNET_CONTAINER_multihashmap_get (ns_pending, &hc); 1429 req = GNUNET_CONTAINER_multihashmap_get(ns_pending, &hc);
1425 if (NULL == req) 1430 if (NULL == req)
1426 { 1431 {
1427 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1432 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1428 "Ignoring record `%s' in zone `%s': not on my list!\n", 1433 "Ignoring record `%s' in zone `%s': not on my list!\n",
1429 label, 1434 label,
1430 zone->domain); 1435 zone->domain);
1431 return; 1436 return;
1432 } 1437 }
1433 GNUNET_assert (GNUNET_OK == 1438 GNUNET_assert(GNUNET_OK ==
1434 GNUNET_CONTAINER_multihashmap_remove (ns_pending, &hc, req)); 1439 GNUNET_CONTAINER_multihashmap_remove(ns_pending, &hc, req));
1435 GNUNET_break (0 == GNUNET_memcmp (key, &req->zone->key)); 1440 GNUNET_break(0 == GNUNET_memcmp(key, &req->zone->key));
1436 GNUNET_break (0 == strcasecmp (label, get_label (req))); 1441 GNUNET_break(0 == strcasecmp(label, get_label(req)));
1437 for (unsigned int i = 0; i < rd_count; i++) 1442 for (unsigned int i = 0; i < rd_count; i++)
1438 {
1439 struct GNUNET_TIME_Absolute at;
1440
1441 if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1442 { 1443 {
1443 struct GNUNET_TIME_Relative rel; 1444 struct GNUNET_TIME_Absolute at;
1444 1445
1445 rel.rel_value_us = rd->expiration_time; 1446 if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1446 at = GNUNET_TIME_relative_to_absolute (rel); 1447 {
1448 struct GNUNET_TIME_Relative rel;
1449
1450 rel.rel_value_us = rd->expiration_time;
1451 at = GNUNET_TIME_relative_to_absolute(rel);
1452 }
1453 else
1454 {
1455 at.abs_value_us = rd->expiration_time;
1456 }
1457 add_record(req, rd->record_type, at, rd->data, rd->data_size);
1447 } 1458 }
1448 else 1459 if (0 == rd_count)
1449 { 1460 {
1450 at.abs_value_us = rd->expiration_time; 1461 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1462 "Empty record set in namestore for `%s'\n",
1463 req->hostname);
1451 } 1464 }
1452 add_record (req, rd->record_type, at, rd->data, rd->data_size);
1453 }
1454 if (0 == rd_count)
1455 {
1456 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1457 "Empty record set in namestore for `%s'\n",
1458 req->hostname);
1459 }
1460 else 1465 else
1461 {
1462 unsigned int pos = 0;
1463
1464 cached++;
1465 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS;
1466 for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next)
1467 { 1466 {
1468 struct GNUNET_TIME_Absolute at; 1467 unsigned int pos = 0;
1469 1468
1470 at.abs_value_us = rec->grd.expiration_time; 1469 cached++;
1471 req->expires = GNUNET_TIME_absolute_min (req->expires, at); 1470 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS;
1472 pos++; 1471 for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next)
1472 {
1473 struct GNUNET_TIME_Absolute at;
1474
1475 at.abs_value_us = rec->grd.expiration_time;
1476 req->expires = GNUNET_TIME_absolute_min(req->expires, at);
1477 pos++;
1478 }
1479 if (0 == pos)
1480 req->expires = GNUNET_TIME_UNIT_ZERO_ABS;
1481 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1482 "Hot-start with %u existing records for `%s'\n",
1483 pos,
1484 req->hostname);
1473 } 1485 }
1474 if (0 == pos) 1486 free_records(req);
1475 req->expires = GNUNET_TIME_UNIT_ZERO_ABS;
1476 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1477 "Hot-start with %u existing records for `%s'\n",
1478 pos,
1479 req->hostname);
1480 }
1481 free_records (req);
1482 1487
1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1488 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1484 "Adding `%s' to worklist to start at %s\n", 1489 "Adding `%s' to worklist to start at %s\n",
1485 req->hostname, 1490 req->hostname,
1486 GNUNET_STRINGS_absolute_time_to_string (req->expires)); 1491 GNUNET_STRINGS_absolute_time_to_string(req->expires));
1487 insert_sorted (req); 1492 insert_sorted(req);
1488} 1493}
1489 1494
1490 1495
@@ -1494,7 +1499,7 @@ ns_lookup_result_cb (void *cls,
1494 * @param hostname name to resolve 1499 * @param hostname name to resolve
1495 */ 1500 */
1496static void 1501static void
1497queue (const char *hostname) 1502queue(const char *hostname)
1498{ 1503{
1499 struct Request *req; 1504 struct Request *req;
1500 const char *dot; 1505 const char *dot;
@@ -1502,55 +1507,55 @@ queue (const char *hostname)
1502 size_t hlen; 1507 size_t hlen;
1503 struct GNUNET_HashCode hc; 1508 struct GNUNET_HashCode hc;
1504 1509
1505 if (GNUNET_OK != GNUNET_DNSPARSER_check_name (hostname)) 1510 if (GNUNET_OK != GNUNET_DNSPARSER_check_name(hostname))
1506 { 1511 {
1507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1512 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1508 "Refusing invalid hostname `%s'\n", 1513 "Refusing invalid hostname `%s'\n",
1509 hostname); 1514 hostname);
1510 rejects++; 1515 rejects++;
1511 return; 1516 return;
1512 } 1517 }
1513 dot = strchr (hostname, (unsigned char) '.'); 1518 dot = strchr(hostname, (unsigned char)'.');
1514 if (NULL == dot) 1519 if (NULL == dot)
1515 { 1520 {
1516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1521 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1517 "Refusing invalid hostname `%s' (lacks '.')\n", 1522 "Refusing invalid hostname `%s' (lacks '.')\n",
1518 hostname); 1523 hostname);
1519 rejects++; 1524 rejects++;
1520 return; 1525 return;
1521 } 1526 }
1522 for (zone = zone_head; NULL != zone; zone = zone->next) 1527 for (zone = zone_head; NULL != zone; zone = zone->next)
1523 if (0 == strcmp (zone->domain, dot + 1)) 1528 if (0 == strcmp(zone->domain, dot + 1))
1524 break; 1529 break;
1525 if (NULL == zone) 1530 if (NULL == zone)
1526 { 1531 {
1527 rejects++; 1532 rejects++;
1528 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1533 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1529 "Domain name `%s' not in ego list!\n", 1534 "Domain name `%s' not in ego list!\n",
1530 dot + 1); 1535 dot + 1);
1531 return; 1536 return;
1532 } 1537 }
1533 1538
1534 hlen = strlen (hostname) + 1; 1539 hlen = strlen(hostname) + 1;
1535 req = GNUNET_malloc (sizeof (struct Request) + hlen); 1540 req = GNUNET_malloc(sizeof(struct Request) + hlen);
1536 req->zone = zone; 1541 req->zone = zone;
1537 req->hostname = (char *) &req[1]; 1542 req->hostname = (char *)&req[1];
1538 GNUNET_memcpy (req->hostname, hostname, hlen); 1543 GNUNET_memcpy(req->hostname, hostname, hlen);
1539 req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1544 req->id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE,
1540 UINT16_MAX); 1545 UINT16_MAX);
1541 GNUNET_CRYPTO_hash (req->hostname, hlen, &hc); 1546 GNUNET_CRYPTO_hash(req->hostname, hlen, &hc);
1542 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( 1547 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
1543 ns_pending, 1548 ns_pending,
1544 &hc, 1549 &hc,
1545 req, 1550 req,
1546 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1551 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1547 { 1552 {
1548 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1553 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1549 "Duplicate hostname `%s' ignored\n", 1554 "Duplicate hostname `%s' ignored\n",
1550 hostname); 1555 hostname);
1551 GNUNET_free (req); 1556 GNUNET_free(req);
1552 return; 1557 return;
1553 } 1558 }
1554} 1559}
1555 1560
1556 1561
@@ -1566,13 +1571,13 @@ queue (const char *hostname)
1566 * @return #GNUNET_OK (continue to iterate) 1571 * @return #GNUNET_OK (continue to iterate)
1567 */ 1572 */
1568static int 1573static int
1569move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value) 1574move_to_queue(void *cls, const struct GNUNET_HashCode *key, void *value)
1570{ 1575{
1571 struct Request *req = value; 1576 struct Request *req = value;
1572 1577
1573 (void) cls; 1578 (void)cls;
1574 (void) key; 1579 (void)key;
1575 insert_sorted (req); 1580 insert_sorted(req);
1576 return GNUNET_OK; 1581 return GNUNET_OK;
1577} 1582}
1578 1583
@@ -1584,65 +1589,65 @@ move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value)
1584 * @param cls NULL 1589 * @param cls NULL
1585 */ 1590 */
1586static void 1591static void
1587iterate_zones (void *cls) 1592iterate_zones(void *cls)
1588{ 1593{
1589 static struct Zone *last; 1594 static struct Zone *last;
1590 1595
1591 (void) cls; 1596 (void)cls;
1592 if (NULL != zone_it) 1597 if (NULL != zone_it)
1593 { 1598 {
1594 zone_it = NULL; 1599 zone_it = NULL;
1595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1600 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1596 "Finished iteration over zone `%s'!\n", 1601 "Finished iteration over zone `%s'!\n",
1597 last->domain); 1602 last->domain);
1598 /* subtract left-overs from previous iteration */ 1603 /* subtract left-overs from previous iteration */
1599 GNUNET_STATISTICS_update (stats, 1604 GNUNET_STATISTICS_update(stats,
1600 "# NAMESTORE records requested from cache", 1605 "# NAMESTORE records requested from cache",
1601 (long long) (-ns_iterator_trigger_next), 1606 (long long)(-ns_iterator_trigger_next),
1602 GNUNET_NO); 1607 GNUNET_NO);
1603 ns_iterator_trigger_next = 0; 1608 ns_iterator_trigger_next = 0;
1604 } 1609 }
1605 GNUNET_assert (NULL != zone_tail); 1610 GNUNET_assert(NULL != zone_tail);
1606 if (zone_tail == last) 1611 if (zone_tail == last)
1607 { 1612 {
1608 /* Done iterating over relevant zones in NAMESTORE, move 1613 /* Done iterating over relevant zones in NAMESTORE, move
1609 rest of hash map to work queue as well. */ 1614 rest of hash map to work queue as well. */
1610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1615 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1611 "Finished all NAMESTORE iterations!\n"); 1616 "Finished all NAMESTORE iterations!\n");
1612 GNUNET_STATISTICS_set (stats, 1617 GNUNET_STATISTICS_set(stats,
1613 "# Domain names without cached reply", 1618 "# Domain names without cached reply",
1614 GNUNET_CONTAINER_multihashmap_size (ns_pending), 1619 GNUNET_CONTAINER_multihashmap_size(ns_pending),
1615 GNUNET_NO); 1620 GNUNET_NO);
1616 GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &move_to_queue, NULL); 1621 GNUNET_CONTAINER_multihashmap_iterate(ns_pending, &move_to_queue, NULL);
1617 GNUNET_CONTAINER_multihashmap_destroy (ns_pending); 1622 GNUNET_CONTAINER_multihashmap_destroy(ns_pending);
1618 ns_pending = NULL; 1623 ns_pending = NULL;
1619 start_time_reg_proc = GNUNET_TIME_absolute_get (); 1624 start_time_reg_proc = GNUNET_TIME_absolute_get();
1620 total_reg_proc_dns = 0; 1625 total_reg_proc_dns = 0;
1621 total_reg_proc_dns_ns = 0; 1626 total_reg_proc_dns_ns = 0;
1622 return; 1627 return;
1623 } 1628 }
1624 if (NULL == last) 1629 if (NULL == last)
1625 last = zone_head; 1630 last = zone_head;
1626 else 1631 else
1627 last = last->next; 1632 last = last->next;
1628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1633 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1629 "Starting iteration over zone `%s'!\n", 1634 "Starting iteration over zone `%s'!\n",
1630 last->domain); 1635 last->domain);
1631 /* subtract left-overs from previous iteration */ 1636 /* subtract left-overs from previous iteration */
1632 GNUNET_STATISTICS_update (stats, 1637 GNUNET_STATISTICS_update(stats,
1633 "# NAMESTORE records requested from cache", 1638 "# NAMESTORE records requested from cache",
1634 1, 1639 1,
1635 GNUNET_NO); 1640 GNUNET_NO);
1636 ns_iterator_trigger_next = 1; 1641 ns_iterator_trigger_next = 1;
1637 GNUNET_STATISTICS_update (stats, "# zones iterated", 1, GNUNET_NO); 1642 GNUNET_STATISTICS_update(stats, "# zones iterated", 1, GNUNET_NO);
1638 zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 1643 zone_it = GNUNET_NAMESTORE_zone_iteration_start(ns,
1639 &last->key, 1644 &last->key,
1640 &ns_lookup_error_cb, 1645 &ns_lookup_error_cb,
1641 NULL, 1646 NULL,
1642 &ns_lookup_result_cb, 1647 &ns_lookup_result_cb,
1643 last, 1648 last,
1644 &iterate_zones, 1649 &iterate_zones,
1645 NULL); 1650 NULL);
1646} 1651}
1647 1652
1648 1653
@@ -1652,44 +1657,44 @@ iterate_zones (void *cls)
1652 * @param cls NULL 1657 * @param cls NULL
1653 */ 1658 */
1654static void 1659static void
1655process_stdin (void *cls) 1660process_stdin(void *cls)
1656{ 1661{
1657 static struct GNUNET_TIME_Absolute last; 1662 static struct GNUNET_TIME_Absolute last;
1658 static uint64_t idot; 1663 static uint64_t idot;
1659 char hn[256]; 1664 char hn[256];
1660 1665
1661 (void) cls; 1666 (void)cls;
1662 t = NULL; 1667 t = NULL;
1663 if (NULL != id) 1668 if (NULL != id)
1664 {
1665 GNUNET_IDENTITY_disconnect (id);
1666 id = NULL;
1667 }
1668 while (NULL != fgets (hn, sizeof (hn), stdin))
1669 {
1670 if (strlen (hn) > 0)
1671 hn[strlen (hn) - 1] = '\0'; /* eat newline */
1672 if (0 == idot)
1673 last = GNUNET_TIME_absolute_get ();
1674 idot++;
1675 if (0 == idot % 100000)
1676 { 1669 {
1677 struct GNUNET_TIME_Relative delta; 1670 GNUNET_IDENTITY_disconnect(id);
1678 1671 id = NULL;
1679 delta = GNUNET_TIME_absolute_get_duration (last);
1680 last = GNUNET_TIME_absolute_get ();
1681 fprintf (stderr,
1682 "Read 100000 domain names in %s\n",
1683 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
1684 GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO);
1685 } 1672 }
1686 queue (hn); 1673 while (NULL != fgets(hn, sizeof(hn), stdin))
1687 } 1674 {
1688 fprintf (stderr, 1675 if (strlen(hn) > 0)
1689 "Done reading %llu domain names\n", 1676 hn[strlen(hn) - 1] = '\0'; /* eat newline */
1690 (unsigned long long) idot); 1677 if (0 == idot)
1691 GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO); 1678 last = GNUNET_TIME_absolute_get();
1692 iterate_zones (NULL); 1679 idot++;
1680 if (0 == idot % 100000)
1681 {
1682 struct GNUNET_TIME_Relative delta;
1683
1684 delta = GNUNET_TIME_absolute_get_duration(last);
1685 last = GNUNET_TIME_absolute_get();
1686 fprintf(stderr,
1687 "Read 100000 domain names in %s\n",
1688 GNUNET_STRINGS_relative_time_to_string(delta, GNUNET_YES));
1689 GNUNET_STATISTICS_set(stats, "# domain names provided", idot, GNUNET_NO);
1690 }
1691 queue(hn);
1692 }
1693 fprintf(stderr,
1694 "Done reading %llu domain names\n",
1695 (unsigned long long)idot);
1696 GNUNET_STATISTICS_set(stats, "# domain names provided", idot, GNUNET_NO);
1697 iterate_zones(NULL);
1693} 1698}
1694 1699
1695 1700
@@ -1728,36 +1733,36 @@ process_stdin (void *cls)
1728 * must thus no longer be used 1733 * must thus no longer be used
1729 */ 1734 */
1730static void 1735static void
1731identity_cb (void *cls, 1736identity_cb(void *cls,
1732 struct GNUNET_IDENTITY_Ego *ego, 1737 struct GNUNET_IDENTITY_Ego *ego,
1733 void **ctx, 1738 void **ctx,
1734 const char *name) 1739 const char *name)
1735{ 1740{
1736 (void) cls; 1741 (void)cls;
1737 (void) ctx; 1742 (void)ctx;
1738 1743
1739 if (NULL == ego) 1744 if (NULL == ego)
1740 {
1741 /* end of iteration */
1742 if (NULL == zone_head)
1743 { 1745 {
1744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No zone found\n"); 1746 /* end of iteration */
1745 GNUNET_SCHEDULER_shutdown (); 1747 if (NULL == zone_head)
1748 {
1749 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No zone found\n");
1750 GNUNET_SCHEDULER_shutdown();
1751 return;
1752 }
1753 /* zone_head non-null, process hostnames from stdin */
1754 t = GNUNET_SCHEDULER_add_now(&process_stdin, NULL);
1746 return; 1755 return;
1747 } 1756 }
1748 /* zone_head non-null, process hostnames from stdin */
1749 t = GNUNET_SCHEDULER_add_now (&process_stdin, NULL);
1750 return;
1751 }
1752 if (NULL != name) 1757 if (NULL != name)
1753 { 1758 {
1754 struct Zone *zone; 1759 struct Zone *zone;
1755 1760
1756 zone = GNUNET_new (struct Zone); 1761 zone = GNUNET_new(struct Zone);
1757 zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego); 1762 zone->key = *GNUNET_IDENTITY_ego_get_private_key(ego);
1758 zone->domain = GNUNET_strdup (name); 1763 zone->domain = GNUNET_strdup(name);
1759 GNUNET_CONTAINER_DLL_insert (zone_head, zone_tail, zone); 1764 GNUNET_CONTAINER_DLL_insert(zone_head, zone_tail, zone);
1760 } 1765 }
1761} 1766}
1762 1767
1763 1768
@@ -1771,52 +1776,52 @@ identity_cb (void *cls,
1771 * @param cfg configuration 1776 * @param cfg configuration
1772 */ 1777 */
1773static void 1778static void
1774run (void *cls, 1779run(void *cls,
1775 char *const *args, 1780 char *const *args,
1776 const char *cfgfile, 1781 const char *cfgfile,
1777 const struct GNUNET_CONFIGURATION_Handle *cfg) 1782 const struct GNUNET_CONFIGURATION_Handle *cfg)
1778{ 1783{
1779 (void) cls; 1784 (void)cls;
1780 (void) args; 1785 (void)args;
1781 (void) cfgfile; 1786 (void)cfgfile;
1782 stats = GNUNET_STATISTICS_create ("zoneimport", cfg); 1787 stats = GNUNET_STATISTICS_create("zoneimport", cfg);
1783 req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1788 req_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
1784 ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, GNUNET_NO); 1789 ns_pending = GNUNET_CONTAINER_multihashmap_create(map_size, GNUNET_NO);
1785 if (NULL == ns_pending) 1790 if (NULL == ns_pending)
1786 { 1791 {
1787 fprintf (stderr, "Failed to allocate memory for main hash map\n"); 1792 fprintf(stderr, "Failed to allocate memory for main hash map\n");
1788 return; 1793 return;
1789 } 1794 }
1790 ctx = GNUNET_DNSSTUB_start (256); 1795 ctx = GNUNET_DNSSTUB_start(256);
1791 if (NULL == ctx) 1796 if (NULL == ctx)
1792 { 1797 {
1793 fprintf (stderr, "Failed to initialize GNUnet DNS STUB\n"); 1798 fprintf(stderr, "Failed to initialize GNUnet DNS STUB\n");
1794 return; 1799 return;
1795 } 1800 }
1796 if (NULL == args[0]) 1801 if (NULL == args[0])
1797 {
1798 fprintf (stderr,
1799 "You must provide a list of DNS resolvers on the command line\n");
1800 return;
1801 }
1802 for (unsigned int i = 0; NULL != args[i]; i++)
1803 {
1804 if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip (ctx, args[i]))
1805 { 1802 {
1806 fprintf (stderr, "Failed to use `%s' for DNS resolver\n", args[i]); 1803 fprintf(stderr,
1804 "You must provide a list of DNS resolvers on the command line\n");
1807 return; 1805 return;
1808 } 1806 }
1809 } 1807 for (unsigned int i = 0; NULL != args[i]; i++)
1808 {
1809 if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip(ctx, args[i]))
1810 {
1811 fprintf(stderr, "Failed to use `%s' for DNS resolver\n", args[i]);
1812 return;
1813 }
1814 }
1810 1815
1811 1816
1812 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 1817 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
1813 ns = GNUNET_NAMESTORE_connect (cfg); 1818 ns = GNUNET_NAMESTORE_connect(cfg);
1814 if (NULL == ns) 1819 if (NULL == ns)
1815 { 1820 {
1816 GNUNET_SCHEDULER_shutdown (); 1821 GNUNET_SCHEDULER_shutdown();
1817 return; 1822 return;
1818 } 1823 }
1819 id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); 1824 id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL);
1820} 1825}
1821 1826
1822 1827
@@ -1828,46 +1833,46 @@ run (void *cls,
1828 * @return 0 on success 1833 * @return 0 on success
1829 */ 1834 */
1830int 1835int
1831main (int argc, char *const *argv) 1836main(int argc, char *const *argv)
1832{ 1837{
1833 struct GNUNET_GETOPT_CommandLineOption options[] = 1838 struct GNUNET_GETOPT_CommandLineOption options[] =
1834 {GNUNET_GETOPT_option_uint ('s', 1839 { GNUNET_GETOPT_option_uint('s',
1835 "size", 1840 "size",
1836 "MAPSIZE", 1841 "MAPSIZE",
1837 gettext_noop ( 1842 gettext_noop(
1838 "size to use for the main hash map"), 1843 "size to use for the main hash map"),
1839 &map_size), 1844 &map_size),
1840 GNUNET_GETOPT_option_relative_time ( 1845 GNUNET_GETOPT_option_relative_time(
1841 'm', 1846 'm',
1842 "minimum-expiration", 1847 "minimum-expiration",
1843 "RELATIVETIME", 1848 "RELATIVETIME",
1844 gettext_noop ("minimum expiration time we assume for imported records"), 1849 gettext_noop("minimum expiration time we assume for imported records"),
1845 &minimum_expiration_time), 1850 &minimum_expiration_time),
1846 GNUNET_GETOPT_OPTION_END}; 1851 GNUNET_GETOPT_OPTION_END };
1847 int ret; 1852 int ret;
1848 1853
1849 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1854 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1850 return 2; 1855 return 2;
1851 if (GNUNET_OK != (ret = GNUNET_PROGRAM_run (argc, 1856 if (GNUNET_OK != (ret = GNUNET_PROGRAM_run(argc,
1852 argv, 1857 argv,
1853 "gnunet-zoneimport", 1858 "gnunet-zoneimport",
1854 "import DNS zone into namestore", 1859 "import DNS zone into namestore",
1855 options, 1860 options,
1856 &run, 1861 &run,
1857 NULL))) 1862 NULL)))
1858 return ret; 1863 return ret;
1859 GNUNET_free ((void *) argv); 1864 GNUNET_free((void *)argv);
1860 fprintf (stderr, 1865 fprintf(stderr,
1861 "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" 1866 "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n"
1862 "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", 1867 "Found %u records, %u lookups failed, %u/%u pending on shutdown\n",
1863 rejects, 1868 rejects,
1864 cached, 1869 cached,
1865 lookups, 1870 lookups,
1866 record_sets, 1871 record_sets,
1867 records, 1872 records,
1868 failures, 1873 failures,
1869 pending, 1874 pending,
1870 pending_rs); 1875 pending_rs);
1871 return 0; 1876 return 0;
1872} 1877}
1873 1878
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index 67d61f9b3..e9a38f0b4 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file namestore/namestore.h 22 * @file namestore/namestore.h
@@ -37,8 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
37/** 37/**
38 * Generic namestore message with op id 38 * Generic namestore message with op id
39 */ 39 */
40struct GNUNET_NAMESTORE_Header 40struct GNUNET_NAMESTORE_Header {
41{
42 /** 41 /**
43 * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* 42 * header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_*
44 * header.size will be message size 43 * header.size will be message size
@@ -55,8 +54,7 @@ struct GNUNET_NAMESTORE_Header
55/** 54/**
56 * Store a record to the namestore (as authority). 55 * Store a record to the namestore (as authority).
57 */ 56 */
58struct RecordStoreMessage 57struct RecordStoreMessage {
59{
60 /** 58 /**
61 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE 59 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE
62 */ 60 */
@@ -102,8 +100,7 @@ struct RecordStoreMessage
102/** 100/**
103 * Response to a record storage request. 101 * Response to a record storage request.
104 */ 102 */
105struct RecordStoreResponseMessage 103struct RecordStoreResponseMessage {
106{
107 /** 104 /**
108 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE 105 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
109 */ 106 */
@@ -119,8 +116,7 @@ struct RecordStoreResponseMessage
119/** 116/**
120 * Lookup a label 117 * Lookup a label
121 */ 118 */
122struct LabelLookupMessage 119struct LabelLookupMessage {
123{
124 /** 120 /**
125 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP 121 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP
126 */ 122 */
@@ -145,8 +141,7 @@ struct LabelLookupMessage
145/** 141/**
146 * Lookup a label 142 * Lookup a label
147 */ 143 */
148struct LabelLookupResponseMessage 144struct LabelLookupResponseMessage {
149{
150 /** 145 /**
151 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE 146 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
152 */ 147 */
@@ -189,8 +184,7 @@ struct LabelLookupResponseMessage
189/** 184/**
190 * Lookup a name for a zone hash 185 * Lookup a name for a zone hash
191 */ 186 */
192struct ZoneToNameMessage 187struct ZoneToNameMessage {
193{
194 /** 188 /**
195 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 189 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
196 */ 190 */
@@ -211,8 +205,7 @@ struct ZoneToNameMessage
211/** 205/**
212 * Respone for zone to name lookup 206 * Respone for zone to name lookup
213 */ 207 */
214struct ZoneToNameResponseMessage 208struct ZoneToNameResponseMessage {
215{
216 /** 209 /**
217 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE 210 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
218 */ 211 */
@@ -248,15 +241,13 @@ struct ZoneToNameResponseMessage
248 * name with length name_len 241 * name with length name_len
249 * serialized record data with rd_count records 242 * serialized record data with rd_count records
250 */ 243 */
251
252}; 244};
253 245
254 246
255/** 247/**
256 * Record is returned from the namestore (as authority). 248 * Record is returned from the namestore (as authority).
257 */ 249 */
258struct RecordResultMessage 250struct RecordResultMessage {
259{
260 /** 251 /**
261 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT 252 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
262 */ 253 */
@@ -297,8 +288,7 @@ struct RecordResultMessage
297/** 288/**
298 * Start monitoring a zone. 289 * Start monitoring a zone.
299 */ 290 */
300struct ZoneMonitorStartMessage 291struct ZoneMonitorStartMessage {
301{
302 /** 292 /**
303 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START 293 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
304 */ 294 */
@@ -314,15 +304,13 @@ struct ZoneMonitorStartMessage
314 * Zone key. 304 * Zone key.
315 */ 305 */
316 struct GNUNET_CRYPTO_EcdsaPrivateKey zone; 306 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
317
318}; 307};
319 308
320 309
321/** 310/**
322 * Ask for next result of zone iteration for the given operation 311 * Ask for next result of zone iteration for the given operation
323 */ 312 */
324struct ZoneMonitorNextMessage 313struct ZoneMonitorNextMessage {
325{
326 /** 314 /**
327 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT 315 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT
328 */ 316 */
@@ -339,7 +327,6 @@ struct ZoneMonitorNextMessage
339 * should be send again). In NBO. 327 * should be send again). In NBO.
340 */ 328 */
341 uint64_t limit; 329 uint64_t limit;
342
343}; 330};
344 331
345 332
@@ -347,8 +334,7 @@ struct ZoneMonitorNextMessage
347/** 334/**
348 * Start a zone iteration for the given zone 335 * Start a zone iteration for the given zone
349 */ 336 */
350struct ZoneIterationStartMessage 337struct ZoneIterationStartMessage {
351{
352 /** 338 /**
353 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 339 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
354 */ 340 */
@@ -358,15 +344,13 @@ struct ZoneIterationStartMessage
358 * Zone key. All zeros for "all zones". 344 * Zone key. All zeros for "all zones".
359 */ 345 */
360 struct GNUNET_CRYPTO_EcdsaPrivateKey zone; 346 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
361
362}; 347};
363 348
364 349
365/** 350/**
366 * Ask for next result of zone iteration for the given operation 351 * Ask for next result of zone iteration for the given operation
367 */ 352 */
368struct ZoneIterationNextMessage 353struct ZoneIterationNextMessage {
369{
370 /** 354 /**
371 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 355 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
372 */ 356 */
@@ -378,15 +362,13 @@ struct ZoneIterationNextMessage
378 * should be send again). In NBO. 362 * should be send again). In NBO.
379 */ 363 */
380 uint64_t limit; 364 uint64_t limit;
381
382}; 365};
383 366
384 367
385/** 368/**
386 * Stop zone iteration for the given operation 369 * Stop zone iteration for the given operation
387 */ 370 */
388struct ZoneIterationStopMessage 371struct ZoneIterationStopMessage {
389{
390 /** 372 /**
391 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 373 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
392 */ 374 */
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 6c64062ea..c80ca0bd5 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file namestore/namestore_api.c 22 * @file namestore/namestore_api.c
@@ -38,7 +38,7 @@
38#include "namestore.h" 38#include "namestore.h"
39 39
40 40
41#define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__) 41#define LOG(kind, ...) GNUNET_log_from(kind, "namestore-api", __VA_ARGS__)
42 42
43/** 43/**
44 * We grant the namestore up to 1 minute of latency, if it is slower than 44 * We grant the namestore up to 1 minute of latency, if it is slower than
@@ -50,9 +50,7 @@
50 * An QueueEntry used to store information for a pending 50 * An QueueEntry used to store information for a pending
51 * NAMESTORE record operation 51 * NAMESTORE record operation
52 */ 52 */
53struct GNUNET_NAMESTORE_QueueEntry 53struct GNUNET_NAMESTORE_QueueEntry {
54{
55
56 /** 54 /**
57 * Kept in a DLL. 55 * Kept in a DLL.
58 */ 56 */
@@ -119,9 +117,7 @@ struct GNUNET_NAMESTORE_QueueEntry
119/** 117/**
120 * Handle for a zone iterator operation 118 * Handle for a zone iterator operation
121 */ 119 */
122struct GNUNET_NAMESTORE_ZoneIterator 120struct GNUNET_NAMESTORE_ZoneIterator {
123{
124
125 /** 121 /**
126 * Kept in a DLL. 122 * Kept in a DLL.
127 */ 123 */
@@ -188,9 +184,7 @@ struct GNUNET_NAMESTORE_ZoneIterator
188/** 184/**
189 * Connection to the NAMESTORE service. 185 * Connection to the NAMESTORE service.
190 */ 186 */
191struct GNUNET_NAMESTORE_Handle 187struct GNUNET_NAMESTORE_Handle {
192{
193
194 /** 188 /**
195 * Configuration to use. 189 * Configuration to use.
196 */ 190 */
@@ -249,7 +243,7 @@ struct GNUNET_NAMESTORE_Handle
249 * @param h our handle 243 * @param h our handle
250 */ 244 */
251static void 245static void
252force_reconnect (struct GNUNET_NAMESTORE_Handle *h); 246force_reconnect(struct GNUNET_NAMESTORE_Handle *h);
253 247
254 248
255/** 249/**
@@ -260,7 +254,7 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h);
260 * @return NULL if @a rid was not found 254 * @return NULL if @a rid was not found
261 */ 255 */
262static struct GNUNET_NAMESTORE_QueueEntry * 256static struct GNUNET_NAMESTORE_QueueEntry *
263find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) 257find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
264{ 258{
265 struct GNUNET_NAMESTORE_QueueEntry *qe; 259 struct GNUNET_NAMESTORE_QueueEntry *qe;
266 260
@@ -279,7 +273,7 @@ find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
279 * @return NULL if @a rid was not found 273 * @return NULL if @a rid was not found
280 */ 274 */
281static struct GNUNET_NAMESTORE_ZoneIterator * 275static struct GNUNET_NAMESTORE_ZoneIterator *
282find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) 276find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
283{ 277{
284 struct GNUNET_NAMESTORE_ZoneIterator *ze; 278 struct GNUNET_NAMESTORE_ZoneIterator *ze;
285 279
@@ -296,16 +290,16 @@ find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
296 * @param qe entry to free 290 * @param qe entry to free
297 */ 291 */
298static void 292static void
299free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe) 293free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
300{ 294{
301 struct GNUNET_NAMESTORE_Handle *h = qe->h; 295 struct GNUNET_NAMESTORE_Handle *h = qe->h;
302 296
303 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, qe); 297 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
304 if (NULL != qe->env) 298 if (NULL != qe->env)
305 GNUNET_MQ_discard (qe->env); 299 GNUNET_MQ_discard(qe->env);
306 if (NULL != qe->timeout_task) 300 if (NULL != qe->timeout_task)
307 GNUNET_SCHEDULER_cancel (qe->timeout_task); 301 GNUNET_SCHEDULER_cancel(qe->timeout_task);
308 GNUNET_free (qe); 302 GNUNET_free(qe);
309} 303}
310 304
311 305
@@ -315,14 +309,14 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe)
315 * @param ze entry to free 309 * @param ze entry to free
316 */ 310 */
317static void 311static void
318free_ze (struct GNUNET_NAMESTORE_ZoneIterator *ze) 312free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
319{ 313{
320 struct GNUNET_NAMESTORE_Handle *h = ze->h; 314 struct GNUNET_NAMESTORE_Handle *h = ze->h;
321 315
322 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, ze); 316 GNUNET_CONTAINER_DLL_remove(h->z_head, h->z_tail, ze);
323 if (NULL != ze->env) 317 if (NULL != ze->env)
324 GNUNET_MQ_discard (ze->env); 318 GNUNET_MQ_discard(ze->env);
325 GNUNET_free (ze); 319 GNUNET_free(ze);
326} 320}
327 321
328 322
@@ -336,16 +330,16 @@ free_ze (struct GNUNET_NAMESTORE_ZoneIterator *ze)
336 * @return #GNUNET_OK if @a rd_buf is well-formed 330 * @return #GNUNET_OK if @a rd_buf is well-formed
337 */ 331 */
338static int 332static int
339check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count) 333check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
340{ 334{
341 struct GNUNET_GNSRECORD_Data rd[rd_count]; 335 struct GNUNET_GNSRECORD_Data rd[rd_count];
342 336
343 if (GNUNET_OK != 337 if (GNUNET_OK !=
344 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_buf, rd_count, rd)) 338 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_buf, rd_count, rd))
345 { 339 {
346 GNUNET_break (0); 340 GNUNET_break(0);
347 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
348 } 342 }
349 return GNUNET_OK; 343 return GNUNET_OK;
350} 344}
351 345
@@ -358,27 +352,27 @@ check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
358 * @param msg the message we received 352 * @param msg the message we received
359 */ 353 */
360static void 354static void
361handle_record_store_response (void *cls, 355handle_record_store_response(void *cls,
362 const struct RecordStoreResponseMessage *msg) 356 const struct RecordStoreResponseMessage *msg)
363{ 357{
364 struct GNUNET_NAMESTORE_Handle *h = cls; 358 struct GNUNET_NAMESTORE_Handle *h = cls;
365 struct GNUNET_NAMESTORE_QueueEntry *qe; 359 struct GNUNET_NAMESTORE_QueueEntry *qe;
366 int res; 360 int res;
367 const char *emsg; 361 const char *emsg;
368 362
369 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 363 qe = find_qe(h, ntohl(msg->gns_header.r_id));
370 res = ntohl (msg->op_result); 364 res = ntohl(msg->op_result);
371 LOG (GNUNET_ERROR_TYPE_DEBUG, 365 LOG(GNUNET_ERROR_TYPE_DEBUG,
372 "Received RECORD_STORE_RESPONSE with result %d\n", 366 "Received RECORD_STORE_RESPONSE with result %d\n",
373 res); 367 res);
374 /* TODO: add actual error message from namestore to response... */ 368 /* TODO: add actual error message from namestore to response... */
375 if (GNUNET_SYSERR == res) 369 if (GNUNET_SYSERR == res)
376 emsg = _ ("Namestore failed to store record\n"); 370 emsg = _("Namestore failed to store record\n");
377 else 371 else
378 emsg = NULL; 372 emsg = NULL;
379 if (NULL != qe->cont) 373 if (NULL != qe->cont)
380 qe->cont (qe->cont_cls, res, emsg); 374 qe->cont(qe->cont_cls, res, emsg);
381 free_qe (qe); 375 free_qe(qe);
382} 376}
383 377
384 378
@@ -391,7 +385,7 @@ handle_record_store_response (void *cls,
391 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 385 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
392 */ 386 */
393static int 387static int
394check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) 388check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
395{ 389{
396 const char *name; 390 const char *name;
397 size_t exp_msg_len; 391 size_t exp_msg_len;
@@ -399,32 +393,32 @@ check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
399 size_t name_len; 393 size_t name_len;
400 size_t rd_len; 394 size_t rd_len;
401 395
402 (void) cls; 396 (void)cls;
403 rd_len = ntohs (msg->rd_len); 397 rd_len = ntohs(msg->rd_len);
404 msg_len = ntohs (msg->gns_header.header.size); 398 msg_len = ntohs(msg->gns_header.header.size);
405 name_len = ntohs (msg->name_len); 399 name_len = ntohs(msg->name_len);
406 exp_msg_len = sizeof (*msg) + name_len + rd_len; 400 exp_msg_len = sizeof(*msg) + name_len + rd_len;
407 if (msg_len != exp_msg_len) 401 if (msg_len != exp_msg_len)
408 { 402 {
409 GNUNET_break (0); 403 GNUNET_break(0);
410 return GNUNET_SYSERR; 404 return GNUNET_SYSERR;
411 } 405 }
412 name = (const char *) &msg[1]; 406 name = (const char *)&msg[1];
413 if ((name_len > 0) && ('\0' != name[name_len - 1])) 407 if ((name_len > 0) && ('\0' != name[name_len - 1]))
414 {
415 GNUNET_break (0);
416 return GNUNET_SYSERR;
417 }
418 if (GNUNET_NO == ntohs (msg->found))
419 {
420 if (0 != ntohs (msg->rd_count))
421 { 408 {
422 GNUNET_break (0); 409 GNUNET_break(0);
423 return GNUNET_SYSERR; 410 return GNUNET_SYSERR;
424 } 411 }
425 return GNUNET_OK; 412 if (GNUNET_NO == ntohs(msg->found))
426 } 413 {
427 return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count)); 414 if (0 != ntohs(msg->rd_count))
415 {
416 GNUNET_break(0);
417 return GNUNET_SYSERR;
418 }
419 return GNUNET_OK;
420 }
421 return check_rd(rd_len, &name[name_len], ntohs(msg->rd_count));
428} 422}
429 423
430 424
@@ -436,7 +430,7 @@ check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
436 * @param msg the message we received 430 * @param msg the message we received
437 */ 431 */
438static void 432static void
439handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) 433handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
440{ 434{
441 struct GNUNET_NAMESTORE_Handle *h = cls; 435 struct GNUNET_NAMESTORE_Handle *h = cls;
442 struct GNUNET_NAMESTORE_QueueEntry *qe; 436 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -446,40 +440,40 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
446 size_t rd_len; 440 size_t rd_len;
447 unsigned int rd_count; 441 unsigned int rd_count;
448 442
449 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n"); 443 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n");
450 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 444 qe = find_qe(h, ntohl(msg->gns_header.r_id));
451 if (NULL == qe) 445 if (NULL == qe)
452 return; 446 return;
453 rd_len = ntohs (msg->rd_len); 447 rd_len = ntohs(msg->rd_len);
454 rd_count = ntohs (msg->rd_count); 448 rd_count = ntohs(msg->rd_count);
455 name_len = ntohs (msg->name_len); 449 name_len = ntohs(msg->name_len);
456 name = (const char *) &msg[1]; 450 name = (const char *)&msg[1];
457 if (GNUNET_NO == ntohs (msg->found)) 451 if (GNUNET_NO == ntohs(msg->found))
458 { 452 {
459 /* label was not in namestore */ 453 /* label was not in namestore */
460 if (NULL != qe->proc) 454 if (NULL != qe->proc)
461 qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL); 455 qe->proc(qe->proc_cls, &msg->private_key, name, 0, NULL);
462 free_qe (qe); 456 free_qe(qe);
463 return; 457 return;
464 } 458 }
465 459
466 rd_tmp = &name[name_len]; 460 rd_tmp = &name[name_len];
467 { 461 {
468 struct GNUNET_GNSRECORD_Data rd[rd_count]; 462 struct GNUNET_GNSRECORD_Data rd[rd_count];
469 463
470 GNUNET_assert ( 464 GNUNET_assert(
471 GNUNET_OK == 465 GNUNET_OK ==
472 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd)); 466 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd));
473 if (0 == name_len) 467 if (0 == name_len)
474 name = NULL; 468 name = NULL;
475 if (NULL != qe->proc) 469 if (NULL != qe->proc)
476 qe->proc (qe->proc_cls, 470 qe->proc(qe->proc_cls,
477 &msg->private_key, 471 &msg->private_key,
478 name, 472 name,
479 rd_count, 473 rd_count,
480 (rd_count > 0) ? rd : NULL); 474 (rd_count > 0) ? rd : NULL);
481 } 475 }
482 free_qe (qe); 476 free_qe(qe);
483} 477}
484 478
485 479
@@ -492,7 +486,7 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
492 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 486 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
493 */ 487 */
494static int 488static int
495check_record_result (void *cls, const struct RecordResultMessage *msg) 489check_record_result(void *cls, const struct RecordResultMessage *msg)
496{ 490{
497 static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy; 491 static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy;
498 const char *name; 492 const char *name;
@@ -500,32 +494,32 @@ check_record_result (void *cls, const struct RecordResultMessage *msg)
500 size_t name_len; 494 size_t name_len;
501 size_t rd_len; 495 size_t rd_len;
502 496
503 (void) cls; 497 (void)cls;
504 rd_len = ntohs (msg->rd_len); 498 rd_len = ntohs(msg->rd_len);
505 msg_len = ntohs (msg->gns_header.header.size); 499 msg_len = ntohs(msg->gns_header.header.size);
506 name_len = ntohs (msg->name_len); 500 name_len = ntohs(msg->name_len);
507 if (0 != ntohs (msg->reserved)) 501 if (0 != ntohs(msg->reserved))
508 { 502 {
509 GNUNET_break (0); 503 GNUNET_break(0);
510 return GNUNET_SYSERR; 504 return GNUNET_SYSERR;
511 } 505 }
512 if (msg_len != sizeof (struct RecordResultMessage) + name_len + rd_len) 506 if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len)
513 { 507 {
514 GNUNET_break (0); 508 GNUNET_break(0);
515 return GNUNET_SYSERR; 509 return GNUNET_SYSERR;
516 } 510 }
517 name = (const char *) &msg[1]; 511 name = (const char *)&msg[1];
518 if ((0 == name_len) || ('\0' != name[name_len - 1])) 512 if ((0 == name_len) || ('\0' != name[name_len - 1]))
519 { 513 {
520 GNUNET_break (0); 514 GNUNET_break(0);
521 return GNUNET_SYSERR; 515 return GNUNET_SYSERR;
522 } 516 }
523 if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy)) 517 if (0 == GNUNET_memcmp(&msg->private_key, &priv_dummy))
524 { 518 {
525 GNUNET_break (0); 519 GNUNET_break(0);
526 return GNUNET_SYSERR; 520 return GNUNET_SYSERR;
527 } 521 }
528 return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count)); 522 return check_rd(rd_len, &name[name_len], ntohs(msg->rd_count));
529} 523}
530 524
531 525
@@ -537,7 +531,7 @@ check_record_result (void *cls, const struct RecordResultMessage *msg)
537 * @param msg the message we received 531 * @param msg the message we received
538 */ 532 */
539static void 533static void
540handle_record_result (void *cls, const struct RecordResultMessage *msg) 534handle_record_result(void *cls, const struct RecordResultMessage *msg)
541{ 535{
542 struct GNUNET_NAMESTORE_Handle *h = cls; 536 struct GNUNET_NAMESTORE_Handle *h = cls;
543 struct GNUNET_NAMESTORE_QueueEntry *qe; 537 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -548,49 +542,49 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
548 size_t rd_len; 542 size_t rd_len;
549 unsigned int rd_count; 543 unsigned int rd_count;
550 544
551 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n"); 545 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
552 rd_len = ntohs (msg->rd_len); 546 rd_len = ntohs(msg->rd_len);
553 rd_count = ntohs (msg->rd_count); 547 rd_count = ntohs(msg->rd_count);
554 name_len = ntohs (msg->name_len); 548 name_len = ntohs(msg->name_len);
555 ze = find_zi (h, ntohl (msg->gns_header.r_id)); 549 ze = find_zi(h, ntohl(msg->gns_header.r_id));
556 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 550 qe = find_qe(h, ntohl(msg->gns_header.r_id));
557 if ((NULL == ze) && (NULL == qe)) 551 if ((NULL == ze) && (NULL == qe))
558 return; /* rid not found */ 552 return; /* rid not found */
559 if ((NULL != ze) && (NULL != qe)) 553 if ((NULL != ze) && (NULL != qe))
560 { 554 {
561 GNUNET_break (0); /* rid ambigous */ 555 GNUNET_break(0); /* rid ambigous */
562 force_reconnect (h); 556 force_reconnect(h);
563 return; 557 return;
564 } 558 }
565 name = (const char *) &msg[1]; 559 name = (const char *)&msg[1];
566 rd_tmp = &name[name_len]; 560 rd_tmp = &name[name_len];
567 { 561 {
568 struct GNUNET_GNSRECORD_Data rd[rd_count]; 562 struct GNUNET_GNSRECORD_Data rd[rd_count];
569 563
570 GNUNET_assert ( 564 GNUNET_assert(
571 GNUNET_OK == 565 GNUNET_OK ==
572 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd)); 566 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd));
573 if (0 == name_len) 567 if (0 == name_len)
574 name = NULL; 568 name = NULL;
575 if (NULL != qe) 569 if (NULL != qe)
576 { 570 {
577 if (NULL != qe->proc) 571 if (NULL != qe->proc)
578 qe->proc (qe->proc_cls, 572 qe->proc(qe->proc_cls,
579 &msg->private_key, 573 &msg->private_key,
580 name, 574 name,
581 rd_count, 575 rd_count,
582 (rd_count > 0) ? rd : NULL); 576 (rd_count > 0) ? rd : NULL);
583 free_qe (qe); 577 free_qe(qe);
584 return; 578 return;
585 } 579 }
586 if (NULL != ze) 580 if (NULL != ze)
587 { 581 {
588 if (NULL != ze->proc) 582 if (NULL != ze->proc)
589 ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd); 583 ze->proc(ze->proc_cls, &msg->private_key, name, rd_count, rd);
590 return; 584 return;
591 } 585 }
592 } 586 }
593 GNUNET_assert (0); 587 GNUNET_assert(0);
594} 588}
595 589
596 590
@@ -602,33 +596,33 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
602 * @param msg the message we received 596 * @param msg the message we received
603 */ 597 */
604static void 598static void
605handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg) 599handle_record_result_end(void *cls, const struct GNUNET_NAMESTORE_Header *msg)
606{ 600{
607 struct GNUNET_NAMESTORE_Handle *h = cls; 601 struct GNUNET_NAMESTORE_Handle *h = cls;
608 struct GNUNET_NAMESTORE_QueueEntry *qe; 602 struct GNUNET_NAMESTORE_QueueEntry *qe;
609 struct GNUNET_NAMESTORE_ZoneIterator *ze; 603 struct GNUNET_NAMESTORE_ZoneIterator *ze;
610 604
611 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n"); 605 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
612 ze = find_zi (h, ntohl (msg->r_id)); 606 ze = find_zi(h, ntohl(msg->r_id));
613 qe = find_qe (h, ntohl (msg->r_id)); 607 qe = find_qe(h, ntohl(msg->r_id));
614 if ((NULL == ze) && (NULL == qe)) 608 if ((NULL == ze) && (NULL == qe))
615 return; /* rid not found */ 609 return; /* rid not found */
616 if ((NULL != ze) && (NULL != qe)) 610 if ((NULL != ze) && (NULL != qe))
617 { 611 {
618 GNUNET_break (0); /* rid ambigous */ 612 GNUNET_break(0); /* rid ambigous */
619 force_reconnect (h); 613 force_reconnect(h);
620 return; 614 return;
621 } 615 }
622 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n"); 616 LOG(GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
623 if (NULL == ze) 617 if (NULL == ze)
624 { 618 {
625 GNUNET_break (0); 619 GNUNET_break(0);
626 force_reconnect (h); 620 force_reconnect(h);
627 return; 621 return;
628 } 622 }
629 if (NULL != ze->finish_cb) 623 if (NULL != ze->finish_cb)
630 ze->finish_cb (ze->finish_cb_cls); 624 ze->finish_cb(ze->finish_cb_cls);
631 free_ze (ze); 625 free_ze(ze);
632} 626}
633 627
634 628
@@ -641,31 +635,31 @@ handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg)
641 * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed 635 * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed
642 */ 636 */
643static int 637static int
644check_zone_to_name_response (void *cls, 638check_zone_to_name_response(void *cls,
645 const struct ZoneToNameResponseMessage *msg) 639 const struct ZoneToNameResponseMessage *msg)
646{ 640{
647 size_t name_len; 641 size_t name_len;
648 size_t rd_ser_len; 642 size_t rd_ser_len;
649 const char *name_tmp; 643 const char *name_tmp;
650 644
651 (void) cls; 645 (void)cls;
652 if (GNUNET_OK != ntohs (msg->res)) 646 if (GNUNET_OK != ntohs(msg->res))
653 return GNUNET_OK; 647 return GNUNET_OK;
654 name_len = ntohs (msg->name_len); 648 name_len = ntohs(msg->name_len);
655 rd_ser_len = ntohs (msg->rd_len); 649 rd_ser_len = ntohs(msg->rd_len);
656 if (ntohs (msg->gns_header.header.size) != 650 if (ntohs(msg->gns_header.header.size) !=
657 sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len) 651 sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len)
658 { 652 {
659 GNUNET_break (0); 653 GNUNET_break(0);
660 return GNUNET_SYSERR; 654 return GNUNET_SYSERR;
661 } 655 }
662 name_tmp = (const char *) &msg[1]; 656 name_tmp = (const char *)&msg[1];
663 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1])) 657 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
664 { 658 {
665 GNUNET_break (0); 659 GNUNET_break(0);
666 return GNUNET_SYSERR; 660 return GNUNET_SYSERR;
667 } 661 }
668 return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count)); 662 return check_rd(rd_ser_len, &name_tmp[name_len], ntohs(msg->rd_count));
669} 663}
670 664
671 665
@@ -677,8 +671,8 @@ check_zone_to_name_response (void *cls,
677 * @param msg the message we received 671 * @param msg the message we received
678 */ 672 */
679static void 673static void
680handle_zone_to_name_response (void *cls, 674handle_zone_to_name_response(void *cls,
681 const struct ZoneToNameResponseMessage *msg) 675 const struct ZoneToNameResponseMessage *msg)
682{ 676{
683 struct GNUNET_NAMESTORE_Handle *h = cls; 677 struct GNUNET_NAMESTORE_Handle *h = cls;
684 struct GNUNET_NAMESTORE_QueueEntry *qe; 678 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -689,54 +683,57 @@ handle_zone_to_name_response (void *cls,
689 const char *name_tmp; 683 const char *name_tmp;
690 const char *rd_tmp; 684 const char *rd_tmp;
691 685
692 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n"); 686 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
693 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 687 qe = find_qe(h, ntohl(msg->gns_header.r_id));
694 res = ntohs (msg->res); 688 res = ntohs(msg->res);
695 switch (res) 689 switch (res)
696 {
697 case GNUNET_SYSERR:
698 LOG (GNUNET_ERROR_TYPE_DEBUG,
699 "An error occurred during zone to name operation\n");
700 break;
701 case GNUNET_NO:
702 LOG (GNUNET_ERROR_TYPE_DEBUG,
703 "Namestore has no result for zone to name mapping \n");
704 if (NULL != qe->proc)
705 qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL);
706 free_qe (qe);
707 return;
708 case GNUNET_YES:
709 LOG (GNUNET_ERROR_TYPE_DEBUG,
710 "Namestore has result for zone to name mapping \n");
711 name_len = ntohs (msg->name_len);
712 rd_count = ntohs (msg->rd_count);
713 rd_ser_len = ntohs (msg->rd_len);
714 name_tmp = (const char *) &msg[1];
715 rd_tmp = &name_tmp[name_len];
716 { 690 {
717 struct GNUNET_GNSRECORD_Data rd[rd_count]; 691 case GNUNET_SYSERR:
692 LOG(GNUNET_ERROR_TYPE_DEBUG,
693 "An error occurred during zone to name operation\n");
694 break;
695
696 case GNUNET_NO:
697 LOG(GNUNET_ERROR_TYPE_DEBUG,
698 "Namestore has no result for zone to name mapping \n");
699 if (NULL != qe->proc)
700 qe->proc(qe->proc_cls, &msg->zone, NULL, 0, NULL);
701 free_qe(qe);
702 return;
718 703
719 GNUNET_assert (GNUNET_OK == 704 case GNUNET_YES:
720 GNUNET_GNSRECORD_records_deserialize (rd_ser_len, 705 LOG(GNUNET_ERROR_TYPE_DEBUG,
706 "Namestore has result for zone to name mapping \n");
707 name_len = ntohs(msg->name_len);
708 rd_count = ntohs(msg->rd_count);
709 rd_ser_len = ntohs(msg->rd_len);
710 name_tmp = (const char *)&msg[1];
711 rd_tmp = &name_tmp[name_len];
712 {
713 struct GNUNET_GNSRECORD_Data rd[rd_count];
714
715 GNUNET_assert(GNUNET_OK ==
716 GNUNET_GNSRECORD_records_deserialize(rd_ser_len,
721 rd_tmp, 717 rd_tmp,
722 rd_count, 718 rd_count,
723 rd)); 719 rd));
724 /* normal end, call continuation with result */ 720 /* normal end, call continuation with result */
725 if (NULL != qe->proc) 721 if (NULL != qe->proc)
726 qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd); 722 qe->proc(qe->proc_cls, &msg->zone, name_tmp, rd_count, rd);
727 /* return is important here: break would call continuation with error! */ 723 /* return is important here: break would call continuation with error! */
728 free_qe (qe); 724 free_qe(qe);
725 return;
726 }
727
728 default:
729 GNUNET_break(0);
730 force_reconnect(h);
729 return; 731 return;
730 } 732 }
731 default:
732 GNUNET_break (0);
733 force_reconnect (h);
734 return;
735 }
736 /* error case, call continuation with error */ 733 /* error case, call continuation with error */
737 if (NULL != qe->error_cb) 734 if (NULL != qe->error_cb)
738 qe->error_cb (qe->error_cb_cls); 735 qe->error_cb(qe->error_cb_cls);
739 free_qe (qe); 736 free_qe(qe);
740} 737}
741 738
742 739
@@ -749,12 +746,12 @@ handle_zone_to_name_response (void *cls,
749 * @param error error code 746 * @param error error code
750 */ 747 */
751static void 748static void
752mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 749mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
753{ 750{
754 struct GNUNET_NAMESTORE_Handle *h = cls; 751 struct GNUNET_NAMESTORE_Handle *h = cls;
755 752
756 (void) error; 753 (void)error;
757 force_reconnect (h); 754 force_reconnect(h);
758} 755}
759 756
760 757
@@ -764,49 +761,49 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
764 * @param h the handle to the NAMESTORE service 761 * @param h the handle to the NAMESTORE service
765 */ 762 */
766static void 763static void
767reconnect (struct GNUNET_NAMESTORE_Handle *h) 764reconnect(struct GNUNET_NAMESTORE_Handle *h)
768{ 765{
769 struct GNUNET_MQ_MessageHandler handlers[] = 766 struct GNUNET_MQ_MessageHandler handlers[] =
770 {GNUNET_MQ_hd_fixed_size (record_store_response, 767 { GNUNET_MQ_hd_fixed_size(record_store_response,
771 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, 768 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE,
772 struct RecordStoreResponseMessage, 769 struct RecordStoreResponseMessage,
773 h),
774 GNUNET_MQ_hd_var_size (zone_to_name_response,
775 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE,
776 struct ZoneToNameResponseMessage,
777 h),
778 GNUNET_MQ_hd_var_size (record_result,
779 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
780 struct RecordResultMessage,
781 h), 770 h),
782 GNUNET_MQ_hd_fixed_size (record_result_end, 771 GNUNET_MQ_hd_var_size(zone_to_name_response,
783 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END, 772 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE,
784 struct GNUNET_NAMESTORE_Header, 773 struct ZoneToNameResponseMessage,
785 h), 774 h),
786 GNUNET_MQ_hd_var_size (lookup_result, 775 GNUNET_MQ_hd_var_size(record_result,
787 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, 776 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
788 struct LabelLookupResponseMessage, 777 struct RecordResultMessage,
778 h),
779 GNUNET_MQ_hd_fixed_size(record_result_end,
780 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END,
781 struct GNUNET_NAMESTORE_Header,
789 h), 782 h),
790 GNUNET_MQ_handler_end ()}; 783 GNUNET_MQ_hd_var_size(lookup_result,
784 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE,
785 struct LabelLookupResponseMessage,
786 h),
787 GNUNET_MQ_handler_end() };
791 struct GNUNET_NAMESTORE_ZoneIterator *it; 788 struct GNUNET_NAMESTORE_ZoneIterator *it;
792 struct GNUNET_NAMESTORE_QueueEntry *qe; 789 struct GNUNET_NAMESTORE_QueueEntry *qe;
793 790
794 GNUNET_assert (NULL == h->mq); 791 GNUNET_assert(NULL == h->mq);
795 h->mq = 792 h->mq =
796 GNUNET_CLIENT_connect (h->cfg, "namestore", handlers, &mq_error_handler, h); 793 GNUNET_CLIENT_connect(h->cfg, "namestore", handlers, &mq_error_handler, h);
797 if (NULL == h->mq) 794 if (NULL == h->mq)
798 return; 795 return;
799 /* re-transmit pending requests that waited for a reconnect... */ 796 /* re-transmit pending requests that waited for a reconnect... */
800 for (it = h->z_head; NULL != it; it = it->next) 797 for (it = h->z_head; NULL != it; it = it->next)
801 { 798 {
802 GNUNET_MQ_send (h->mq, it->env); 799 GNUNET_MQ_send(h->mq, it->env);
803 it->env = NULL; 800 it->env = NULL;
804 } 801 }
805 for (qe = h->op_head; NULL != qe; qe = qe->next) 802 for (qe = h->op_head; NULL != qe; qe = qe->next)
806 { 803 {
807 GNUNET_MQ_send (h->mq, qe->env); 804 GNUNET_MQ_send(h->mq, qe->env);
808 qe->env = NULL; 805 qe->env = NULL;
809 } 806 }
810} 807}
811 808
812 809
@@ -816,12 +813,12 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h)
816 * @param cls handle to use to re-connect. 813 * @param cls handle to use to re-connect.
817 */ 814 */
818static void 815static void
819reconnect_task (void *cls) 816reconnect_task(void *cls)
820{ 817{
821 struct GNUNET_NAMESTORE_Handle *h = cls; 818 struct GNUNET_NAMESTORE_Handle *h = cls;
822 819
823 h->reconnect_task = NULL; 820 h->reconnect_task = NULL;
824 reconnect (h); 821 reconnect(h);
825} 822}
826 823
827 824
@@ -831,34 +828,34 @@ reconnect_task (void *cls)
831 * @param h our handle 828 * @param h our handle
832 */ 829 */
833static void 830static void
834force_reconnect (struct GNUNET_NAMESTORE_Handle *h) 831force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
835{ 832{
836 struct GNUNET_NAMESTORE_ZoneIterator *ze; 833 struct GNUNET_NAMESTORE_ZoneIterator *ze;
837 struct GNUNET_NAMESTORE_QueueEntry *qe; 834 struct GNUNET_NAMESTORE_QueueEntry *qe;
838 835
839 GNUNET_MQ_destroy (h->mq); 836 GNUNET_MQ_destroy(h->mq);
840 h->mq = NULL; 837 h->mq = NULL;
841 while (NULL != (ze = h->z_head)) 838 while (NULL != (ze = h->z_head))
842 { 839 {
843 if (NULL != ze->error_cb) 840 if (NULL != ze->error_cb)
844 ze->error_cb (ze->error_cb_cls); 841 ze->error_cb(ze->error_cb_cls);
845 free_ze (ze); 842 free_ze(ze);
846 } 843 }
847 while (NULL != (qe = h->op_head)) 844 while (NULL != (qe = h->op_head))
848 { 845 {
849 if (NULL != qe->error_cb) 846 if (NULL != qe->error_cb)
850 qe->error_cb (qe->error_cb_cls); 847 qe->error_cb(qe->error_cb_cls);
851 if (NULL != qe->cont) 848 if (NULL != qe->cont)
852 qe->cont (qe->cont_cls, 849 qe->cont(qe->cont_cls,
853 GNUNET_SYSERR, 850 GNUNET_SYSERR,
854 "failure in communication with namestore service"); 851 "failure in communication with namestore service");
855 free_qe (qe); 852 free_qe(qe);
856 } 853 }
857 854
858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n"); 855 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
859 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); 856 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay);
860 h->reconnect_task = 857 h->reconnect_task =
861 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h); 858 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect_task, h);
862} 859}
863 860
864 861
@@ -869,7 +866,7 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
869 * @return next operation id to use 866 * @return next operation id to use
870 */ 867 */
871static uint32_t 868static uint32_t
872get_op_id (struct GNUNET_NAMESTORE_Handle *h) 869get_op_id(struct GNUNET_NAMESTORE_Handle *h)
873{ 870{
874 return h->last_op_id_used++; 871 return h->last_op_id_used++;
875} 872}
@@ -882,18 +879,18 @@ get_op_id (struct GNUNET_NAMESTORE_Handle *h)
882 * @return handle to the GNS service, or NULL on error 879 * @return handle to the GNS service, or NULL on error
883 */ 880 */
884struct GNUNET_NAMESTORE_Handle * 881struct GNUNET_NAMESTORE_Handle *
885GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 882GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
886{ 883{
887 struct GNUNET_NAMESTORE_Handle *h; 884 struct GNUNET_NAMESTORE_Handle *h;
888 885
889 h = GNUNET_new (struct GNUNET_NAMESTORE_Handle); 886 h = GNUNET_new(struct GNUNET_NAMESTORE_Handle);
890 h->cfg = cfg; 887 h->cfg = cfg;
891 reconnect (h); 888 reconnect(h);
892 if (NULL == h->mq) 889 if (NULL == h->mq)
893 { 890 {
894 GNUNET_free (h); 891 GNUNET_free(h);
895 return NULL; 892 return NULL;
896 } 893 }
897 return h; 894 return h;
898} 895}
899 896
@@ -905,35 +902,35 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
905 * @param h handle to the namestore 902 * @param h handle to the namestore
906 */ 903 */
907void 904void
908GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) 905GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
909{ 906{
910 struct GNUNET_NAMESTORE_QueueEntry *q; 907 struct GNUNET_NAMESTORE_QueueEntry *q;
911 struct GNUNET_NAMESTORE_ZoneIterator *z; 908 struct GNUNET_NAMESTORE_ZoneIterator *z;
912 909
913 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 910 LOG(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
914 GNUNET_break (NULL == h->op_head); 911 GNUNET_break(NULL == h->op_head);
915 while (NULL != (q = h->op_head)) 912 while (NULL != (q = h->op_head))
916 { 913 {
917 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q); 914 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, q);
918 GNUNET_free (q); 915 GNUNET_free(q);
919 } 916 }
920 GNUNET_break (NULL == h->z_head); 917 GNUNET_break(NULL == h->z_head);
921 while (NULL != (z = h->z_head)) 918 while (NULL != (z = h->z_head))
922 { 919 {
923 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z); 920 GNUNET_CONTAINER_DLL_remove(h->z_head, h->z_tail, z);
924 GNUNET_free (z); 921 GNUNET_free(z);
925 } 922 }
926 if (NULL != h->mq) 923 if (NULL != h->mq)
927 { 924 {
928 GNUNET_MQ_destroy (h->mq); 925 GNUNET_MQ_destroy(h->mq);
929 h->mq = NULL; 926 h->mq = NULL;
930 } 927 }
931 if (NULL != h->reconnect_task) 928 if (NULL != h->reconnect_task)
932 { 929 {
933 GNUNET_SCHEDULER_cancel (h->reconnect_task); 930 GNUNET_SCHEDULER_cancel(h->reconnect_task);
934 h->reconnect_task = NULL; 931 h->reconnect_task = NULL;
935 } 932 }
936 GNUNET_free (h); 933 GNUNET_free(h);
937} 934}
938 935
939 936
@@ -944,21 +941,21 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
944 * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *` 941 * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *`
945 */ 942 */
946static void 943static void
947warn_delay (void *cls) 944warn_delay(void *cls)
948{ 945{
949 struct GNUNET_NAMESTORE_QueueEntry *qe = cls; 946 struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
950 947
951 qe->timeout_task = NULL; 948 qe->timeout_task = NULL;
952 LOG (GNUNET_ERROR_TYPE_WARNING, 949 LOG(GNUNET_ERROR_TYPE_WARNING,
953 "Did not receive response from namestore after %s!\n", 950 "Did not receive response from namestore after %s!\n",
954 GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE, 951 GNUNET_STRINGS_relative_time_to_string(NAMESTORE_DELAY_TOLERANCE,
955 GNUNET_YES)); 952 GNUNET_YES));
956 if (NULL != qe->cont) 953 if (NULL != qe->cont)
957 { 954 {
958 qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout"); 955 qe->cont(qe->cont_cls, GNUNET_SYSERR, "timeout");
959 qe->cont = NULL; 956 qe->cont = NULL;
960 } 957 }
961 GNUNET_NAMESTORE_cancel (qe); 958 GNUNET_NAMESTORE_cancel(qe);
962} 959}
963 960
964 961
@@ -977,7 +974,7 @@ warn_delay (void *cls)
977 * @return handle to abort the request 974 * @return handle to abort the request
978 */ 975 */
979struct GNUNET_NAMESTORE_QueueEntry * 976struct GNUNET_NAMESTORE_QueueEntry *
980GNUNET_NAMESTORE_records_store ( 977GNUNET_NAMESTORE_records_store(
981 struct GNUNET_NAMESTORE_Handle *h, 978 struct GNUNET_NAMESTORE_Handle *h,
982 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 979 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
983 const char *label, 980 const char *label,
@@ -996,69 +993,69 @@ GNUNET_NAMESTORE_records_store (
996 struct RecordStoreMessage *msg; 993 struct RecordStoreMessage *msg;
997 ssize_t sret; 994 ssize_t sret;
998 995
999 name_len = strlen (label) + 1; 996 name_len = strlen(label) + 1;
1000 if (name_len > MAX_NAME_LEN) 997 if (name_len > MAX_NAME_LEN)
1001 { 998 {
1002 GNUNET_break (0); 999 GNUNET_break(0);
1003 return NULL; 1000 return NULL;
1004 } 1001 }
1005 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 1002 rd_ser_len = GNUNET_GNSRECORD_records_get_size(rd_count, rd);
1006 if (rd_ser_len < 0) 1003 if (rd_ser_len < 0)
1007 { 1004 {
1008 GNUNET_break (0); 1005 GNUNET_break(0);
1009 return NULL; 1006 return NULL;
1010 } 1007 }
1011 if (rd_ser_len > UINT16_MAX) 1008 if (rd_ser_len > UINT16_MAX)
1012 { 1009 {
1013 GNUNET_break (0); 1010 GNUNET_break(0);
1014 return NULL; 1011 return NULL;
1015 } 1012 }
1016 rid = get_op_id (h); 1013 rid = get_op_id(h);
1017 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1014 qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry);
1018 qe->h = h; 1015 qe->h = h;
1019 qe->cont = cont; 1016 qe->cont = cont;
1020 qe->cont_cls = cont_cls; 1017 qe->cont_cls = cont_cls;
1021 qe->op_id = rid; 1018 qe->op_id = rid;
1022 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1019 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
1023 1020
1024 /* setup msg */ 1021 /* setup msg */
1025 env = GNUNET_MQ_msg_extra (msg, 1022 env = GNUNET_MQ_msg_extra(msg,
1026 name_len + rd_ser_len, 1023 name_len + rd_ser_len,
1027 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); 1024 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE);
1028 msg->gns_header.r_id = htonl (rid); 1025 msg->gns_header.r_id = htonl(rid);
1029 msg->name_len = htons (name_len); 1026 msg->name_len = htons(name_len);
1030 msg->rd_count = htons (rd_count); 1027 msg->rd_count = htons(rd_count);
1031 msg->rd_len = htons (rd_ser_len); 1028 msg->rd_len = htons(rd_ser_len);
1032 msg->reserved = htons (0); 1029 msg->reserved = htons(0);
1033 msg->private_key = *pkey; 1030 msg->private_key = *pkey;
1034 1031
1035 name_tmp = (char *) &msg[1]; 1032 name_tmp = (char *)&msg[1];
1036 GNUNET_memcpy (name_tmp, label, name_len); 1033 GNUNET_memcpy(name_tmp, label, name_len);
1037 rd_ser = &name_tmp[name_len]; 1034 rd_ser = &name_tmp[name_len];
1038 sret = GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_ser); 1035 sret = GNUNET_GNSRECORD_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1039 if ((0 > sret) || (sret != rd_ser_len)) 1036 if ((0 > sret) || (sret != rd_ser_len))
1040 { 1037 {
1041 GNUNET_break (0); 1038 GNUNET_break(0);
1042 GNUNET_free (env); 1039 GNUNET_free(env);
1043 return NULL; 1040 return NULL;
1044 } 1041 }
1045 GNUNET_assert (rd_ser_len == sret); 1042 GNUNET_assert(rd_ser_len == sret);
1046 LOG (GNUNET_ERROR_TYPE_DEBUG, 1043 LOG(GNUNET_ERROR_TYPE_DEBUG,
1047 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", 1044 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1048 label, 1045 label,
1049 rd_count); 1046 rd_count);
1050 qe->timeout_task = 1047 qe->timeout_task =
1051 GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe); 1048 GNUNET_SCHEDULER_add_delayed(NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe);
1052 if (NULL == h->mq) 1049 if (NULL == h->mq)
1053 { 1050 {
1054 qe->env = env; 1051 qe->env = env;
1055 LOG (GNUNET_ERROR_TYPE_WARNING, 1052 LOG(GNUNET_ERROR_TYPE_WARNING,
1056 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n"); 1053 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1057 } 1054 }
1058 else 1055 else
1059 { 1056 {
1060 GNUNET_MQ_send (h->mq, env); 1057 GNUNET_MQ_send(h->mq, env);
1061 } 1058 }
1062 return qe; 1059 return qe;
1063} 1060}
1064 1061
@@ -1074,29 +1071,29 @@ GNUNET_NAMESTORE_records_store (
1074 * @return handle to abort the request 1071 * @return handle to abort the request
1075 */ 1072 */
1076struct GNUNET_NAMESTORE_QueueEntry * 1073struct GNUNET_NAMESTORE_QueueEntry *
1077GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h, 1074GNUNET_NAMESTORE_set_nick(struct GNUNET_NAMESTORE_Handle *h,
1078 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 1075 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
1079 const char *nick, 1076 const char *nick,
1080 GNUNET_NAMESTORE_ContinuationWithStatus cont, 1077 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1081 void *cont_cls) 1078 void *cont_cls)
1082{ 1079{
1083 struct GNUNET_GNSRECORD_Data rd; 1080 struct GNUNET_GNSRECORD_Data rd;
1084 1081
1085 if (NULL == h->mq) 1082 if (NULL == h->mq)
1086 return NULL; 1083 return NULL;
1087 memset (&rd, 0, sizeof (rd)); 1084 memset(&rd, 0, sizeof(rd));
1088 rd.data = nick; 1085 rd.data = nick;
1089 rd.data_size = strlen (nick) + 1; 1086 rd.data_size = strlen(nick) + 1;
1090 rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; 1087 rd.record_type = GNUNET_GNSRECORD_TYPE_NICK;
1091 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 1088 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
1092 rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; 1089 rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE;
1093 return GNUNET_NAMESTORE_records_store (h, 1090 return GNUNET_NAMESTORE_records_store(h,
1094 pkey, 1091 pkey,
1095 GNUNET_GNS_EMPTY_LABEL_AT, 1092 GNUNET_GNS_EMPTY_LABEL_AT,
1096 1, 1093 1,
1097 &rd, 1094 &rd,
1098 cont, 1095 cont,
1099 cont_cls); 1096 cont_cls);
1100} 1097}
1101 1098
1102 1099
@@ -1113,7 +1110,7 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
1113 * @return handle to abort the request 1110 * @return handle to abort the request
1114 */ 1111 */
1115struct GNUNET_NAMESTORE_QueueEntry * 1112struct GNUNET_NAMESTORE_QueueEntry *
1116GNUNET_NAMESTORE_records_lookup ( 1113GNUNET_NAMESTORE_records_lookup(
1117 struct GNUNET_NAMESTORE_Handle *h, 1114 struct GNUNET_NAMESTORE_Handle *h,
1118 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 1115 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
1119 const char *label, 1116 const char *label,
@@ -1127,32 +1124,32 @@ GNUNET_NAMESTORE_records_lookup (
1127 struct LabelLookupMessage *msg; 1124 struct LabelLookupMessage *msg;
1128 size_t label_len; 1125 size_t label_len;
1129 1126
1130 if (1 == (label_len = strlen (label) + 1)) 1127 if (1 == (label_len = strlen(label) + 1))
1131 { 1128 {
1132 GNUNET_break (0); 1129 GNUNET_break(0);
1133 return NULL; 1130 return NULL;
1134 } 1131 }
1135 1132
1136 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1133 qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry);
1137 qe->h = h; 1134 qe->h = h;
1138 qe->error_cb = error_cb; 1135 qe->error_cb = error_cb;
1139 qe->error_cb_cls = error_cb_cls; 1136 qe->error_cb_cls = error_cb_cls;
1140 qe->proc = rm; 1137 qe->proc = rm;
1141 qe->proc_cls = rm_cls; 1138 qe->proc_cls = rm_cls;
1142 qe->op_id = get_op_id (h); 1139 qe->op_id = get_op_id(h);
1143 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1140 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
1144 1141
1145 env = GNUNET_MQ_msg_extra (msg, 1142 env = GNUNET_MQ_msg_extra(msg,
1146 label_len, 1143 label_len,
1147 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP); 1144 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP);
1148 msg->gns_header.r_id = htonl (qe->op_id); 1145 msg->gns_header.r_id = htonl(qe->op_id);
1149 msg->zone = *pkey; 1146 msg->zone = *pkey;
1150 msg->label_len = htonl (label_len); 1147 msg->label_len = htonl(label_len);
1151 GNUNET_memcpy (&msg[1], label, label_len); 1148 GNUNET_memcpy(&msg[1], label, label_len);
1152 if (NULL == h->mq) 1149 if (NULL == h->mq)
1153 qe->env = env; 1150 qe->env = env;
1154 else 1151 else
1155 GNUNET_MQ_send (h->mq, env); 1152 GNUNET_MQ_send(h->mq, env);
1156 return qe; 1153 return qe;
1157} 1154}
1158 1155
@@ -1173,7 +1170,7 @@ GNUNET_NAMESTORE_records_lookup (
1173 * cancel 1170 * cancel
1174 */ 1171 */
1175struct GNUNET_NAMESTORE_QueueEntry * 1172struct GNUNET_NAMESTORE_QueueEntry *
1176GNUNET_NAMESTORE_zone_to_name ( 1173GNUNET_NAMESTORE_zone_to_name(
1177 struct GNUNET_NAMESTORE_Handle *h, 1174 struct GNUNET_NAMESTORE_Handle *h,
1178 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1175 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1179 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, 1176 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
@@ -1187,24 +1184,24 @@ GNUNET_NAMESTORE_zone_to_name (
1187 struct ZoneToNameMessage *msg; 1184 struct ZoneToNameMessage *msg;
1188 uint32_t rid; 1185 uint32_t rid;
1189 1186
1190 rid = get_op_id (h); 1187 rid = get_op_id(h);
1191 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1188 qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry);
1192 qe->h = h; 1189 qe->h = h;
1193 qe->error_cb = error_cb; 1190 qe->error_cb = error_cb;
1194 qe->error_cb_cls = error_cb_cls; 1191 qe->error_cb_cls = error_cb_cls;
1195 qe->proc = proc; 1192 qe->proc = proc;
1196 qe->proc_cls = proc_cls; 1193 qe->proc_cls = proc_cls;
1197 qe->op_id = rid; 1194 qe->op_id = rid;
1198 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1195 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
1199 1196
1200 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); 1197 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
1201 msg->gns_header.r_id = htonl (rid); 1198 msg->gns_header.r_id = htonl(rid);
1202 msg->zone = *zone; 1199 msg->zone = *zone;
1203 msg->value_zone = *value_zone; 1200 msg->value_zone = *value_zone;
1204 if (NULL == h->mq) 1201 if (NULL == h->mq)
1205 qe->env = env; 1202 qe->env = env;
1206 else 1203 else
1207 GNUNET_MQ_send (h->mq, env); 1204 GNUNET_MQ_send(h->mq, env);
1208 return qe; 1205 return qe;
1209} 1206}
1210 1207
@@ -1229,7 +1226,7 @@ GNUNET_NAMESTORE_zone_to_name (
1229 * @return an iterator handle to use for iteration 1226 * @return an iterator handle to use for iteration
1230 */ 1227 */
1231struct GNUNET_NAMESTORE_ZoneIterator * 1228struct GNUNET_NAMESTORE_ZoneIterator *
1232GNUNET_NAMESTORE_zone_iteration_start ( 1229GNUNET_NAMESTORE_zone_iteration_start(
1233 struct GNUNET_NAMESTORE_Handle *h, 1230 struct GNUNET_NAMESTORE_Handle *h,
1234 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1231 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1235 GNUNET_SCHEDULER_TaskCallback error_cb, 1232 GNUNET_SCHEDULER_TaskCallback error_cb,
@@ -1244,9 +1241,9 @@ GNUNET_NAMESTORE_zone_iteration_start (
1244 struct ZoneIterationStartMessage *msg; 1241 struct ZoneIterationStartMessage *msg;
1245 uint32_t rid; 1242 uint32_t rid;
1246 1243
1247 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); 1244 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1248 rid = get_op_id (h); 1245 rid = get_op_id(h);
1249 it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator); 1246 it = GNUNET_new(struct GNUNET_NAMESTORE_ZoneIterator);
1250 it->h = h; 1247 it->h = h;
1251 it->error_cb = error_cb; 1248 it->error_cb = error_cb;
1252 it->error_cb_cls = error_cb_cls; 1249 it->error_cb_cls = error_cb_cls;
@@ -1257,15 +1254,15 @@ GNUNET_NAMESTORE_zone_iteration_start (
1257 it->op_id = rid; 1254 it->op_id = rid;
1258 if (NULL != zone) 1255 if (NULL != zone)
1259 it->zone = *zone; 1256 it->zone = *zone;
1260 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); 1257 GNUNET_CONTAINER_DLL_insert_tail(h->z_head, h->z_tail, it);
1261 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); 1258 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1262 msg->gns_header.r_id = htonl (rid); 1259 msg->gns_header.r_id = htonl(rid);
1263 if (NULL != zone) 1260 if (NULL != zone)
1264 msg->zone = *zone; 1261 msg->zone = *zone;
1265 if (NULL == h->mq) 1262 if (NULL == h->mq)
1266 it->env = env; 1263 it->env = env;
1267 else 1264 else
1268 GNUNET_MQ_send (h->mq, env); 1265 GNUNET_MQ_send(h->mq, env);
1269 return it; 1266 return it;
1270} 1267}
1271 1268
@@ -1279,20 +1276,20 @@ GNUNET_NAMESTORE_zone_iteration_start (
1279 * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again) 1276 * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again)
1280 */ 1277 */
1281void 1278void
1282GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it, 1279GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it,
1283 uint64_t limit) 1280 uint64_t limit)
1284{ 1281{
1285 struct GNUNET_NAMESTORE_Handle *h = it->h; 1282 struct GNUNET_NAMESTORE_Handle *h = it->h;
1286 struct ZoneIterationNextMessage *msg; 1283 struct ZoneIterationNextMessage *msg;
1287 struct GNUNET_MQ_Envelope *env; 1284 struct GNUNET_MQ_Envelope *env;
1288 1285
1289 LOG (GNUNET_ERROR_TYPE_DEBUG, 1286 LOG(GNUNET_ERROR_TYPE_DEBUG,
1290 "Sending ZONE_ITERATION_NEXT message with limit %llu\n", 1287 "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
1291 (unsigned long long) limit); 1288 (unsigned long long)limit);
1292 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); 1289 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT);
1293 msg->gns_header.r_id = htonl (it->op_id); 1290 msg->gns_header.r_id = htonl(it->op_id);
1294 msg->limit = GNUNET_htonll (limit); 1291 msg->limit = GNUNET_htonll(limit);
1295 GNUNET_MQ_send (h->mq, env); 1292 GNUNET_MQ_send(h->mq, env);
1296} 1293}
1297 1294
1298 1295
@@ -1302,21 +1299,21 @@ GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it,
1302 * @param it the iterator 1299 * @param it the iterator
1303 */ 1300 */
1304void 1301void
1305GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it) 1302GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
1306{ 1303{
1307 struct GNUNET_NAMESTORE_Handle *h = it->h; 1304 struct GNUNET_NAMESTORE_Handle *h = it->h;
1308 struct GNUNET_MQ_Envelope *env; 1305 struct GNUNET_MQ_Envelope *env;
1309 struct ZoneIterationStopMessage *msg; 1306 struct ZoneIterationStopMessage *msg;
1310 1307
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n"); 1308 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n");
1312 if (NULL != h->mq) 1309 if (NULL != h->mq)
1313 { 1310 {
1314 env = 1311 env =
1315 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); 1312 GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP);
1316 msg->gns_header.r_id = htonl (it->op_id); 1313 msg->gns_header.r_id = htonl(it->op_id);
1317 GNUNET_MQ_send (h->mq, env); 1314 GNUNET_MQ_send(h->mq, env);
1318 } 1315 }
1319 free_ze (it); 1316 free_ze(it);
1320} 1317}
1321 1318
1322 1319
@@ -1327,9 +1324,9 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
1327 * @param qe operation to cancel 1324 * @param qe operation to cancel
1328 */ 1325 */
1329void 1326void
1330GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe) 1327GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
1331{ 1328{
1332 free_qe (qe); 1329 free_qe(qe);
1333} 1330}
1334 1331
1335 1332
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 2881a28ac..d87a76eed 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/namestore_api_monitor.c 21 * @file namestore/namestore_api_monitor.c
22 * @brief API to monitor changes in the NAMESTORE 22 * @brief API to monitor changes in the NAMESTORE
@@ -37,8 +37,7 @@
37/** 37/**
38 * Handle for a monitoring activity. 38 * Handle for a monitoring activity.
39 */ 39 */
40struct GNUNET_NAMESTORE_ZoneMonitor 40struct GNUNET_NAMESTORE_ZoneMonitor {
41{
42 /** 41 /**
43 * Configuration (to reconnect). 42 * Configuration (to reconnect).
44 */ 43 */
@@ -97,7 +96,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor
97 * @param zm monitor to reconnect 96 * @param zm monitor to reconnect
98 */ 97 */
99static void 98static void
100reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm); 99reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm);
101 100
102 101
103/** 102/**
@@ -107,14 +106,14 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
107 * @param msg the sync message 106 * @param msg the sync message
108 */ 107 */
109static void 108static void
110handle_sync (void *cls, const struct GNUNET_MessageHeader *msg) 109handle_sync(void *cls, const struct GNUNET_MessageHeader *msg)
111{ 110{
112 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 111 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
113 112
114 (void) cls; 113 (void)cls;
115 (void) msg; 114 (void)msg;
116 if (NULL != zm->sync_cb) 115 if (NULL != zm->sync_cb)
117 zm->sync_cb (zm->sync_cb_cls); 116 zm->sync_cb(zm->sync_cb_cls);
118} 117}
119 118
120 119
@@ -126,7 +125,7 @@ handle_sync (void *cls, const struct GNUNET_MessageHeader *msg)
126 * @param lrm the message from the service. 125 * @param lrm the message from the service.
127 */ 126 */
128static int 127static int
129check_result (void *cls, const struct RecordResultMessage *lrm) 128check_result(void *cls, const struct RecordResultMessage *lrm)
130{ 129{
131 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 130 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
132 size_t lrm_len; 131 size_t lrm_len;
@@ -137,49 +136,49 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
137 const char *name_tmp; 136 const char *name_tmp;
138 const char *rd_ser_tmp; 137 const char *rd_ser_tmp;
139 138
140 (void) cls; 139 (void)cls;
141 if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) && 140 if ((0 != GNUNET_memcmp(&lrm->private_key, &zm->zone)) &&
142 (0 != GNUNET_is_zero (&zm->zone))) 141 (0 != GNUNET_is_zero(&zm->zone)))
143 { 142 {
144 GNUNET_break (0); 143 GNUNET_break(0);
145 return GNUNET_SYSERR; 144 return GNUNET_SYSERR;
146 } 145 }
147 lrm_len = ntohs (lrm->gns_header.header.size); 146 lrm_len = ntohs(lrm->gns_header.header.size);
148 rd_len = ntohs (lrm->rd_len); 147 rd_len = ntohs(lrm->rd_len);
149 rd_count = ntohs (lrm->rd_count); 148 rd_count = ntohs(lrm->rd_count);
150 name_len = ntohs (lrm->name_len); 149 name_len = ntohs(lrm->name_len);
151 if (name_len > MAX_NAME_LEN) 150 if (name_len > MAX_NAME_LEN)
152 { 151 {
153 GNUNET_break (0); 152 GNUNET_break(0);
154 return GNUNET_SYSERR; 153 return GNUNET_SYSERR;
155 } 154 }
156 exp_lrm_len = sizeof (struct RecordResultMessage) + name_len + rd_len; 155 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len;
157 if (lrm_len != exp_lrm_len) 156 if (lrm_len != exp_lrm_len)
158 { 157 {
159 GNUNET_break (0); 158 GNUNET_break(0);
160 return GNUNET_SYSERR; 159 return GNUNET_SYSERR;
161 } 160 }
162 if (0 == name_len) 161 if (0 == name_len)
163 { 162 {
164 GNUNET_break (0); 163 GNUNET_break(0);
165 return GNUNET_SYSERR; 164 return GNUNET_SYSERR;
166 } 165 }
167 name_tmp = (const char *) &lrm[1]; 166 name_tmp = (const char *)&lrm[1];
168 if (name_tmp[name_len - 1] != '\0') 167 if (name_tmp[name_len - 1] != '\0')
169 { 168 {
170 GNUNET_break (0); 169 GNUNET_break(0);
171 return GNUNET_SYSERR; 170 return GNUNET_SYSERR;
172 } 171 }
173 rd_ser_tmp = (const char *) &name_tmp[name_len]; 172 rd_ser_tmp = (const char *)&name_tmp[name_len];
174 { 173 {
175 struct GNUNET_GNSRECORD_Data rd[rd_count]; 174 struct GNUNET_GNSRECORD_Data rd[rd_count];
176 175
177 if (GNUNET_OK != 176 if (GNUNET_OK !=
178 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)) 177 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_ser_tmp, rd_count, rd))
179 { 178 {
180 GNUNET_break (0); 179 GNUNET_break(0);
181 return GNUNET_SYSERR; 180 return GNUNET_SYSERR;
182 } 181 }
183 } 182 }
184 return GNUNET_OK; 183 return GNUNET_OK;
185} 184}
@@ -193,7 +192,7 @@ check_result (void *cls, const struct RecordResultMessage *lrm)
193 * @param lrm the message from the service. 192 * @param lrm the message from the service.
194 */ 193 */
195static void 194static void
196handle_result (void *cls, const struct RecordResultMessage *lrm) 195handle_result(void *cls, const struct RecordResultMessage *lrm)
197{ 196{
198 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 197 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
199 size_t name_len; 198 size_t name_len;
@@ -202,18 +201,18 @@ handle_result (void *cls, const struct RecordResultMessage *lrm)
202 const char *name_tmp; 201 const char *name_tmp;
203 const char *rd_ser_tmp; 202 const char *rd_ser_tmp;
204 203
205 rd_len = ntohs (lrm->rd_len); 204 rd_len = ntohs(lrm->rd_len);
206 rd_count = ntohs (lrm->rd_count); 205 rd_count = ntohs(lrm->rd_count);
207 name_len = ntohs (lrm->name_len); 206 name_len = ntohs(lrm->name_len);
208 name_tmp = (const char *) &lrm[1]; 207 name_tmp = (const char *)&lrm[1];
209 rd_ser_tmp = (const char *) &name_tmp[name_len]; 208 rd_ser_tmp = (const char *)&name_tmp[name_len];
210 { 209 {
211 struct GNUNET_GNSRECORD_Data rd[rd_count]; 210 struct GNUNET_GNSRECORD_Data rd[rd_count];
212 211
213 GNUNET_assert ( 212 GNUNET_assert(
214 GNUNET_OK == 213 GNUNET_OK ==
215 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)); 214 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_ser_tmp, rd_count, rd));
216 zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); 215 zm->monitor(zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd);
217 } 216 }
218} 217}
219 218
@@ -227,12 +226,12 @@ handle_result (void *cls, const struct RecordResultMessage *lrm)
227 * @param error error code 226 * @param error error code
228 */ 227 */
229static void 228static void
230mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 229mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
231{ 230{
232 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 231 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
233 232
234 (void) error; 233 (void)error;
235 reconnect (zm); 234 reconnect(zm);
236} 235}
237 236
238 237
@@ -242,37 +241,37 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
242 * @param zm monitor to reconnect 241 * @param zm monitor to reconnect
243 */ 242 */
244static void 243static void
245reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) 244reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
246{ 245{
247 struct GNUNET_MQ_MessageHandler handlers[] = 246 struct GNUNET_MQ_MessageHandler handlers[] =
248 {GNUNET_MQ_hd_fixed_size (sync, 247 { GNUNET_MQ_hd_fixed_size(sync,
249 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, 248 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC,
250 struct GNUNET_MessageHeader, 249 struct GNUNET_MessageHeader,
251 zm),
252 GNUNET_MQ_hd_var_size (result,
253 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
254 struct RecordResultMessage,
255 zm), 250 zm),
256 GNUNET_MQ_handler_end ()}; 251 GNUNET_MQ_hd_var_size(result,
252 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
253 struct RecordResultMessage,
254 zm),
255 GNUNET_MQ_handler_end() };
257 struct GNUNET_MQ_Envelope *env; 256 struct GNUNET_MQ_Envelope *env;
258 struct ZoneMonitorStartMessage *sm; 257 struct ZoneMonitorStartMessage *sm;
259 258
260 if (NULL != zm->mq) 259 if (NULL != zm->mq)
261 { 260 {
262 GNUNET_MQ_destroy (zm->mq); 261 GNUNET_MQ_destroy(zm->mq);
263 zm->error_cb (zm->error_cb_cls); 262 zm->error_cb(zm->error_cb_cls);
264 } 263 }
265 zm->mq = GNUNET_CLIENT_connect (zm->cfg, 264 zm->mq = GNUNET_CLIENT_connect(zm->cfg,
266 "namestore", 265 "namestore",
267 handlers, 266 handlers,
268 &mq_error_handler, 267 &mq_error_handler,
269 zm); 268 zm);
270 if (NULL == zm->mq) 269 if (NULL == zm->mq)
271 return; 270 return;
272 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); 271 env = GNUNET_MQ_msg(sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
273 sm->iterate_first = htonl (zm->iterate_first); 272 sm->iterate_first = htonl(zm->iterate_first);
274 sm->zone = zm->zone; 273 sm->zone = zm->zone;
275 GNUNET_MQ_send (zm->mq, env); 274 GNUNET_MQ_send(zm->mq, env);
276} 275}
277 276
278 277
@@ -300,7 +299,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
300 * @return handle to stop monitoring 299 * @return handle to stop monitoring
301 */ 300 */
302struct GNUNET_NAMESTORE_ZoneMonitor * 301struct GNUNET_NAMESTORE_ZoneMonitor *
303GNUNET_NAMESTORE_zone_monitor_start ( 302GNUNET_NAMESTORE_zone_monitor_start(
304 const struct GNUNET_CONFIGURATION_Handle *cfg, 303 const struct GNUNET_CONFIGURATION_Handle *cfg,
305 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 304 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
306 int iterate_first, 305 int iterate_first,
@@ -313,7 +312,7 @@ GNUNET_NAMESTORE_zone_monitor_start (
313{ 312{
314 struct GNUNET_NAMESTORE_ZoneMonitor *zm; 313 struct GNUNET_NAMESTORE_ZoneMonitor *zm;
315 314
316 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor); 315 zm = GNUNET_new(struct GNUNET_NAMESTORE_ZoneMonitor);
317 if (NULL != zone) 316 if (NULL != zone)
318 zm->zone = *zone; 317 zm->zone = *zone;
319 zm->iterate_first = iterate_first; 318 zm->iterate_first = iterate_first;
@@ -324,12 +323,12 @@ GNUNET_NAMESTORE_zone_monitor_start (
324 zm->sync_cb = sync_cb; 323 zm->sync_cb = sync_cb;
325 zm->sync_cb_cls = sync_cb_cls; 324 zm->sync_cb_cls = sync_cb_cls;
326 zm->cfg = cfg; 325 zm->cfg = cfg;
327 reconnect (zm); 326 reconnect(zm);
328 if (NULL == zm->mq) 327 if (NULL == zm->mq)
329 { 328 {
330 GNUNET_free (zm); 329 GNUNET_free(zm);
331 return NULL; 330 return NULL;
332 } 331 }
333 return zm; 332 return zm;
334} 333}
335 334
@@ -356,15 +355,15 @@ GNUNET_NAMESTORE_zone_monitor_start (
356 * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again) 355 * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again)
357 */ 356 */
358void 357void
359GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm, 358GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm,
360 uint64_t limit) 359 uint64_t limit)
361{ 360{
362 struct GNUNET_MQ_Envelope *env; 361 struct GNUNET_MQ_Envelope *env;
363 struct ZoneMonitorNextMessage *nm; 362 struct ZoneMonitorNextMessage *nm;
364 363
365 env = GNUNET_MQ_msg (nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); 364 env = GNUNET_MQ_msg(nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT);
366 nm->limit = GNUNET_htonll (limit); 365 nm->limit = GNUNET_htonll(limit);
367 GNUNET_MQ_send (zm->mq, env); 366 GNUNET_MQ_send(zm->mq, env);
368} 367}
369 368
370 369
@@ -374,14 +373,14 @@ GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm,
374 * @param zm handle to the monitor activity to stop 373 * @param zm handle to the monitor activity to stop
375 */ 374 */
376void 375void
377GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm) 376GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
378{ 377{
379 if (NULL != zm->mq) 378 if (NULL != zm->mq)
380 { 379 {
381 GNUNET_MQ_destroy (zm->mq); 380 GNUNET_MQ_destroy(zm->mq);
382 zm->mq = NULL; 381 zm->mq = NULL;
383 } 382 }
384 GNUNET_free (zm); 383 GNUNET_free(zm);
385} 384}
386 385
387/* end of namestore_api_monitor.c */ 386/* end of namestore_api_monitor.c */
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c
index 156f9227c..6b79a35f6 100644
--- a/src/namestore/perf_namestore_api_zone_iteration.c
+++ b/src/namestore/perf_namestore_api_zone_iteration.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/perf_namestore_api_zone_iteration.c 21 * @file namestore/perf_namestore_api_zone_iteration.c
22 * @brief testcase for zone iteration functionality: iterate all zones 22 * @brief testcase for zone iteration functionality: iterate all zones
@@ -35,7 +35,7 @@
35 * modern system, so 30 minutes should be OK even for very, very 35 * modern system, so 30 minutes should be OK even for very, very
36 * slow systems. 36 * slow systems.
37 */ 37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) 38#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30)
39 39
40/** 40/**
41 * The runtime of the benchmark is expected to be linear 41 * The runtime of the benchmark is expected to be linear
@@ -87,39 +87,39 @@ static struct GNUNET_TIME_Absolute start;
87 * @param cls NULL 87 * @param cls NULL
88 */ 88 */
89static void 89static void
90end (void *cls) 90end(void *cls)
91{ 91{
92 (void) cls; 92 (void)cls;
93 if (NULL != qe) 93 if (NULL != qe)
94 { 94 {
95 GNUNET_NAMESTORE_cancel (qe); 95 GNUNET_NAMESTORE_cancel(qe);
96 qe = NULL; 96 qe = NULL;
97 } 97 }
98 if (NULL != zi) 98 if (NULL != zi)
99 { 99 {
100 GNUNET_NAMESTORE_zone_iteration_stop (zi); 100 GNUNET_NAMESTORE_zone_iteration_stop(zi);
101 zi = NULL; 101 zi = NULL;
102 } 102 }
103 if (NULL != nsh) 103 if (NULL != nsh)
104 { 104 {
105 GNUNET_NAMESTORE_disconnect (nsh); 105 GNUNET_NAMESTORE_disconnect(nsh);
106 nsh = NULL; 106 nsh = NULL;
107 } 107 }
108 if (NULL != t) 108 if (NULL != t)
109 { 109 {
110 GNUNET_SCHEDULER_cancel (t); 110 GNUNET_SCHEDULER_cancel(t);
111 t = NULL; 111 t = NULL;
112 } 112 }
113 if (NULL != timeout_task) 113 if (NULL != timeout_task)
114 { 114 {
115 GNUNET_SCHEDULER_cancel (timeout_task); 115 GNUNET_SCHEDULER_cancel(timeout_task);
116 timeout_task = NULL; 116 timeout_task = NULL;
117 } 117 }
118 if (NULL != privkey) 118 if (NULL != privkey)
119 { 119 {
120 GNUNET_free (privkey); 120 GNUNET_free(privkey);
121 privkey = NULL; 121 privkey = NULL;
122 } 122 }
123} 123}
124 124
125 125
@@ -128,228 +128,228 @@ end (void *cls)
128 * fail hard but return "skipped". 128 * fail hard but return "skipped".
129 */ 129 */
130static void 130static void
131timeout (void *cls) 131timeout(void *cls)
132{ 132{
133 (void) cls; 133 (void)cls;
134 timeout_task = NULL; 134 timeout_task = NULL;
135 GNUNET_SCHEDULER_shutdown (); 135 GNUNET_SCHEDULER_shutdown();
136 res = 77; 136 res = 77;
137} 137}
138 138
139 139
140static struct GNUNET_GNSRECORD_Data * 140static struct GNUNET_GNSRECORD_Data *
141create_record (unsigned int count) 141create_record(unsigned int count)
142{ 142{
143 struct GNUNET_GNSRECORD_Data *rd; 143 struct GNUNET_GNSRECORD_Data *rd;
144 144
145 rd = GNUNET_malloc (count + sizeof (struct GNUNET_GNSRECORD_Data)); 145 rd = GNUNET_malloc(count + sizeof(struct GNUNET_GNSRECORD_Data));
146 rd->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 146 rd->expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us;
147 rd->record_type = TEST_RECORD_TYPE; 147 rd->record_type = TEST_RECORD_TYPE;
148 rd->data_size = count; 148 rd->data_size = count;
149 rd->data = (void *) &rd[1]; 149 rd->data = (void *)&rd[1];
150 rd->flags = 0; 150 rd->flags = 0;
151 memset (&rd[1], 151 memset(&rd[1],
152 'a', 152 'a',
153 count); 153 count);
154 return rd; 154 return rd;
155} 155}
156 156
157 157
158static void 158static void
159zone_end (void *cls) 159zone_end(void *cls)
160{ 160{
161 struct GNUNET_TIME_Relative delay; 161 struct GNUNET_TIME_Relative delay;
162 162
163 zi = NULL; 163 zi = NULL;
164 delay = GNUNET_TIME_absolute_get_duration (start); 164 delay = GNUNET_TIME_absolute_get_duration(start);
165 fprintf (stdout, 165 fprintf(stdout,
166 "Iterating over %u records took %s\n", 166 "Iterating over %u records took %s\n",
167 off, 167 off,
168 GNUNET_STRINGS_relative_time_to_string (delay, 168 GNUNET_STRINGS_relative_time_to_string(delay,
169 GNUNET_YES)); 169 GNUNET_YES));
170 if (BENCHMARK_SIZE == off) 170 if (BENCHMARK_SIZE == off)
171 { 171 {
172 res = 0; 172 res = 0;
173 } 173 }
174 else 174 else
175 { 175 {
176 GNUNET_break (0); 176 GNUNET_break(0);
177 res = 1; 177 res = 1;
178 } 178 }
179 GNUNET_SCHEDULER_shutdown (); 179 GNUNET_SCHEDULER_shutdown();
180} 180}
181 181
182 182
183static void 183static void
184fail_cb (void *cls) 184fail_cb(void *cls)
185{ 185{
186 zi = NULL; 186 zi = NULL;
187 res = 2; 187 res = 2;
188 GNUNET_break (0); 188 GNUNET_break(0);
189 GNUNET_SCHEDULER_shutdown (); 189 GNUNET_SCHEDULER_shutdown();
190} 190}
191 191
192 192
193static void 193static void
194zone_proc (void *cls, 194zone_proc(void *cls,
195 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 195 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
196 const char *label, 196 const char *label,
197 unsigned int rd_count, 197 unsigned int rd_count,
198 const struct GNUNET_GNSRECORD_Data *rd) 198 const struct GNUNET_GNSRECORD_Data *rd)
199{ 199{
200 struct GNUNET_GNSRECORD_Data *wrd; 200 struct GNUNET_GNSRECORD_Data *wrd;
201 unsigned int xoff; 201 unsigned int xoff;
202 202
203 GNUNET_assert (NULL != zone); 203 GNUNET_assert(NULL != zone);
204 if (1 != sscanf (label, 204 if (1 != sscanf(label,
205 "l%u", 205 "l%u",
206 &xoff)) 206 &xoff))
207 { 207 {
208 res = 3; 208 res = 3;
209 GNUNET_break (0); 209 GNUNET_break(0);
210 GNUNET_SCHEDULER_shutdown (); 210 GNUNET_SCHEDULER_shutdown();
211 return; 211 return;
212 } 212 }
213 if ( (xoff > BENCHMARK_SIZE) || 213 if ((xoff > BENCHMARK_SIZE) ||
214 (0 != (seen[xoff / 8] & (1U << (xoff % 8)))) ) 214 (0 != (seen[xoff / 8] & (1U << (xoff % 8)))))
215 { 215 {
216 res = 3; 216 res = 3;
217 GNUNET_break (0); 217 GNUNET_break(0);
218 GNUNET_SCHEDULER_shutdown (); 218 GNUNET_SCHEDULER_shutdown();
219 return; 219 return;
220 } 220 }
221 seen[xoff / 8] |= (1U << (xoff % 8)); 221 seen[xoff / 8] |= (1U << (xoff % 8));
222 wrd = create_record (xoff % MAX_REC_SIZE); 222 wrd = create_record(xoff % MAX_REC_SIZE);
223 if ( (rd->record_type != wrd->record_type) || 223 if ((rd->record_type != wrd->record_type) ||
224 (rd->data_size != wrd->data_size) || 224 (rd->data_size != wrd->data_size) ||
225 (rd->flags != wrd->flags) ) 225 (rd->flags != wrd->flags))
226 { 226 {
227 res = 4; 227 res = 4;
228 GNUNET_break (0); 228 GNUNET_break(0);
229 GNUNET_SCHEDULER_shutdown (); 229 GNUNET_SCHEDULER_shutdown();
230 GNUNET_free (wrd); 230 GNUNET_free(wrd);
231 return; 231 return;
232 } 232 }
233 if (0 != memcmp (rd->data, 233 if (0 != memcmp(rd->data,
234 wrd->data, 234 wrd->data,
235 wrd->data_size)) 235 wrd->data_size))
236 { 236 {
237 res = 4; 237 res = 4;
238 GNUNET_break (0); 238 GNUNET_break(0);
239 GNUNET_SCHEDULER_shutdown (); 239 GNUNET_SCHEDULER_shutdown();
240 GNUNET_free (wrd); 240 GNUNET_free(wrd);
241 return; 241 return;
242 } 242 }
243 GNUNET_free (wrd); 243 GNUNET_free(wrd);
244 if (0 != GNUNET_memcmp (zone, 244 if (0 != GNUNET_memcmp(zone,
245 privkey)) 245 privkey))
246 { 246 {
247 res = 5; 247 res = 5;
248 GNUNET_break (0); 248 GNUNET_break(0);
249 GNUNET_SCHEDULER_shutdown (); 249 GNUNET_SCHEDULER_shutdown();
250 return; 250 return;
251 } 251 }
252 off++; 252 off++;
253 left_until_next--; 253 left_until_next--;
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 254 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
255 "Obtained record %u, expecting %u more until asking for mor explicitly\n", 255 "Obtained record %u, expecting %u more until asking for mor explicitly\n",
256 off, 256 off,
257 left_until_next); 257 left_until_next);
258 if (0 == left_until_next) 258 if (0 == left_until_next)
259 { 259 {
260 left_until_next = BLOCK_SIZE; 260 left_until_next = BLOCK_SIZE;
261 GNUNET_NAMESTORE_zone_iterator_next (zi, 261 GNUNET_NAMESTORE_zone_iterator_next(zi,
262 left_until_next); 262 left_until_next);
263 } 263 }
264} 264}
265 265
266 266
267static void 267static void
268publish_record (void *cls); 268publish_record(void *cls);
269 269
270 270
271static void 271static void
272put_cont (void *cls, 272put_cont(void *cls,
273 int32_t success, 273 int32_t success,
274 const char *emsg) 274 const char *emsg)
275{ 275{
276 (void) cls; 276 (void)cls;
277 qe = NULL; 277 qe = NULL;
278 if (GNUNET_OK != success) 278 if (GNUNET_OK != success)
279 { 279 {
280 GNUNET_break (0); 280 GNUNET_break(0);
281 GNUNET_SCHEDULER_shutdown (); 281 GNUNET_SCHEDULER_shutdown();
282 return; 282 return;
283 } 283 }
284 t = GNUNET_SCHEDULER_add_now (&publish_record, 284 t = GNUNET_SCHEDULER_add_now(&publish_record,
285 NULL); 285 NULL);
286} 286}
287 287
288 288
289static void 289static void
290publish_record (void *cls) 290publish_record(void *cls)
291{ 291{
292 struct GNUNET_GNSRECORD_Data *rd; 292 struct GNUNET_GNSRECORD_Data *rd;
293 char *label; 293 char *label;
294 294
295 (void) cls; 295 (void)cls;
296 t = NULL; 296 t = NULL;
297 if (BENCHMARK_SIZE == off) 297 if (BENCHMARK_SIZE == off)
298 { 298 {
299 struct GNUNET_TIME_Relative delay; 299 struct GNUNET_TIME_Relative delay;
300 300
301 delay = GNUNET_TIME_absolute_get_duration (start); 301 delay = GNUNET_TIME_absolute_get_duration(start);
302 fprintf (stdout, 302 fprintf(stdout,
303 "Inserting %u records took %s\n", 303 "Inserting %u records took %s\n",
304 off, 304 off,
305 GNUNET_STRINGS_relative_time_to_string (delay, 305 GNUNET_STRINGS_relative_time_to_string(delay,
306 GNUNET_YES)); 306 GNUNET_YES));
307 start = GNUNET_TIME_absolute_get (); 307 start = GNUNET_TIME_absolute_get();
308 off = 0; 308 off = 0;
309 left_until_next = 1; 309 left_until_next = 1;
310 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 310 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
311 NULL, 311 NULL,
312 &fail_cb, 312 &fail_cb,
313 NULL, 313 NULL,
314 &zone_proc, 314 &zone_proc,
315 NULL, 315 NULL,
316 &zone_end, 316 &zone_end,
317 NULL); 317 NULL);
318 GNUNET_assert (NULL != zi); 318 GNUNET_assert(NULL != zi);
319 return; 319 return;
320 } 320 }
321 rd = create_record ((++off) % MAX_REC_SIZE); 321 rd = create_record((++off) % MAX_REC_SIZE);
322 GNUNET_asprintf (&label, 322 GNUNET_asprintf(&label,
323 "l%u", 323 "l%u",
324 off); 324 off);
325 qe = GNUNET_NAMESTORE_records_store (nsh, 325 qe = GNUNET_NAMESTORE_records_store(nsh,
326 privkey, 326 privkey,
327 label, 327 label,
328 1, rd, 328 1, rd,
329 &put_cont, 329 &put_cont,
330 NULL); 330 NULL);
331 GNUNET_free (label); 331 GNUNET_free(label);
332 GNUNET_free (rd); 332 GNUNET_free(rd);
333} 333}
334 334
335 335
336static void 336static void
337run (void *cls, 337run(void *cls,
338 const struct GNUNET_CONFIGURATION_Handle *cfg, 338 const struct GNUNET_CONFIGURATION_Handle *cfg,
339 struct GNUNET_TESTING_Peer *peer) 339 struct GNUNET_TESTING_Peer *peer)
340{ 340{
341 GNUNET_SCHEDULER_add_shutdown (&end, 341 GNUNET_SCHEDULER_add_shutdown(&end,
342 NULL);
343 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
344 &timeout,
345 NULL);
346 nsh = GNUNET_NAMESTORE_connect (cfg);
347 GNUNET_assert (NULL != nsh);
348 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
349 GNUNET_assert (NULL != privkey);
350 start = GNUNET_TIME_absolute_get ();
351 t = GNUNET_SCHEDULER_add_now (&publish_record,
352 NULL); 342 NULL);
343 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
344 &timeout,
345 NULL);
346 nsh = GNUNET_NAMESTORE_connect(cfg);
347 GNUNET_assert(NULL != nsh);
348 privkey = GNUNET_CRYPTO_ecdsa_key_create();
349 GNUNET_assert(NULL != privkey);
350 start = GNUNET_TIME_absolute_get();
351 t = GNUNET_SCHEDULER_add_now(&publish_record,
352 NULL);
353} 353}
354 354
355 355
@@ -357,25 +357,25 @@ run (void *cls,
357 357
358 358
359int 359int
360main (int argc, 360main(int argc,
361 char *argv[]) 361 char *argv[])
362{ 362{
363 const char *plugin_name; 363 const char *plugin_name;
364 char *cfg_name; 364 char *cfg_name;
365 365
366 SETUP_CFG (plugin_name, cfg_name); 366 SETUP_CFG(plugin_name, cfg_name);
367 res = 1; 367 res = 1;
368 if (0 != 368 if (0 !=
369 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", 369 GNUNET_TESTING_peer_run("perf-namestore-api-zone-iteration",
370 cfg_name, 370 cfg_name,
371 &run, 371 &run,
372 NULL)) 372 NULL))
373 { 373 {
374 res = 1; 374 res = 1;
375 } 375 }
376 GNUNET_DISK_purge_cfg_dir (cfg_name, 376 GNUNET_DISK_purge_cfg_dir(cfg_name,
377 "GNUNET_TEST_HOME"); 377 "GNUNET_TEST_HOME");
378 GNUNET_free (cfg_name); 378 GNUNET_free(cfg_name);
379 return res; 379 return res;
380} 380}
381 381
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index 4e1d33907..083609359 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -1,22 +1,22 @@
1 /* 1/*
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2009-2015, 2018, 2019 GNUnet e.V. 3 * Copyright (C) 2009-2015, 2018, 2019 GNUnet e.V.
4 * 4 *
5 * GNUnet is free software: you can redistribute it and/or modify it 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 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, 7 * by the Free Software Foundation, either version 3 of the License,
8 * or (at your option) any later version. 8 * or (at your option) any later version.
9 * 9 *
10 * GNUnet is distributed in the hope that it will be useful, but 10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details. 13 * Affero General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Affero General Public License 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/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @file namestore/plugin_namestore_flat.c 21 * @file namestore/plugin_namestore_flat.c
22 * @brief file-based namestore backend 22 * @brief file-based namestore backend
@@ -33,9 +33,7 @@
33/** 33/**
34 * Context for all functions in this plugin. 34 * Context for all functions in this plugin.
35 */ 35 */
36struct Plugin 36struct Plugin {
37{
38
39 const struct GNUNET_CONFIGURATION_Handle *cfg; 37 const struct GNUNET_CONFIGURATION_Handle *cfg;
40 38
41 /** 39 /**
@@ -47,12 +45,10 @@ struct Plugin
47 * HashMap 45 * HashMap
48 */ 46 */
49 struct GNUNET_CONTAINER_MultiHashMap *hm; 47 struct GNUNET_CONTAINER_MultiHashMap *hm;
50
51}; 48};
52 49
53 50
54struct FlatFileEntry 51struct FlatFileEntry {
55{
56 /** 52 /**
57 * Entry zone 53 * Entry zone
58 */ 54 */
@@ -77,7 +73,6 @@ struct FlatFileEntry
77 * Label 73 * Label
78 */ 74 */
79 char *label; 75 char *label;
80
81}; 76};
82 77
83 78
@@ -89,27 +84,27 @@ struct FlatFileEntry
89 * @param h[out] initialized hash 84 * @param h[out] initialized hash
90 */ 85 */
91static void 86static void
92hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 87hash_pkey_and_label(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
93 const char *label, 88 const char *label,
94 struct GNUNET_HashCode *h) 89 struct GNUNET_HashCode *h)
95{ 90{
96 char *key; 91 char *key;
97 size_t label_len; 92 size_t label_len;
98 size_t key_len; 93 size_t key_len;
99 94
100 label_len = strlen (label); 95 label_len = strlen(label);
101 key_len = label_len + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 96 key_len = label_len + sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey);
102 key = GNUNET_malloc (key_len); 97 key = GNUNET_malloc(key_len);
103 GNUNET_memcpy (key, 98 GNUNET_memcpy(key,
104 label, 99 label,
105 label_len); 100 label_len);
106 GNUNET_memcpy (key + label_len, 101 GNUNET_memcpy(key + label_len,
107 pkey, 102 pkey,
108 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 103 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey));
109 GNUNET_CRYPTO_hash (key, 104 GNUNET_CRYPTO_hash(key,
110 key_len, 105 key_len,
111 h); 106 h);
112 GNUNET_free (key); 107 GNUNET_free(key);
113} 108}
114 109
115 110
@@ -122,7 +117,7 @@ hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
122 * @return #GNUNET_OK on success 117 * @return #GNUNET_OK on success
123 */ 118 */
124static int 119static int
125database_setup (struct Plugin *plugin) 120database_setup(struct Plugin *plugin)
126{ 121{
127 char *flatdbfile; 122 char *flatdbfile;
128 char *record_data; 123 char *record_data;
@@ -141,188 +136,188 @@ database_setup (struct Plugin *plugin)
141 struct GNUNET_DISK_MapHandle *mh; 136 struct GNUNET_DISK_MapHandle *mh;
142 137
143 if (GNUNET_OK != 138 if (GNUNET_OK !=
144 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, 139 GNUNET_CONFIGURATION_get_value_filename(plugin->cfg,
145 "namestore-flat", 140 "namestore-flat",
146 "FILENAME", 141 "FILENAME",
147 &flatdbfile)) 142 &flatdbfile))
148 {
149 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
150 "namestore-flat",
151 "FILENAME");
152 return GNUNET_SYSERR;
153 }
154 if (GNUNET_OK !=
155 GNUNET_DISK_file_test (flatdbfile))
156 {
157 if (GNUNET_OK !=
158 GNUNET_DISK_directory_create_for_file (flatdbfile))
159 { 143 {
160 GNUNET_break (0); 144 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
161 GNUNET_free (flatdbfile); 145 "namestore-flat",
146 "FILENAME");
162 return GNUNET_SYSERR; 147 return GNUNET_SYSERR;
163 } 148 }
164 } 149 if (GNUNET_OK !=
150 GNUNET_DISK_file_test(flatdbfile))
151 {
152 if (GNUNET_OK !=
153 GNUNET_DISK_directory_create_for_file(flatdbfile))
154 {
155 GNUNET_break(0);
156 GNUNET_free(flatdbfile);
157 return GNUNET_SYSERR;
158 }
159 }
165 /* flatdbfile should be UTF-8-encoded. If it isn't, it's a bug */ 160 /* flatdbfile should be UTF-8-encoded. If it isn't, it's a bug */
166 plugin->fn = flatdbfile; 161 plugin->fn = flatdbfile;
167 162
168 /* Load data from file into hashmap */ 163 /* Load data from file into hashmap */
169 plugin->hm = GNUNET_CONTAINER_multihashmap_create (10, 164 plugin->hm = GNUNET_CONTAINER_multihashmap_create(10,
170 GNUNET_NO); 165 GNUNET_NO);
171 fh = GNUNET_DISK_file_open (flatdbfile, 166 fh = GNUNET_DISK_file_open(flatdbfile,
172 GNUNET_DISK_OPEN_CREATE | 167 GNUNET_DISK_OPEN_CREATE |
173 GNUNET_DISK_OPEN_READWRITE, 168 GNUNET_DISK_OPEN_READWRITE,
174 GNUNET_DISK_PERM_USER_WRITE | 169 GNUNET_DISK_PERM_USER_WRITE |
175 GNUNET_DISK_PERM_USER_READ); 170 GNUNET_DISK_PERM_USER_READ);
176 if (NULL == fh) 171 if (NULL == fh)
177 { 172 {
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 173 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
179 _("Unable to initialize file: %s.\n"), 174 _("Unable to initialize file: %s.\n"),
180 flatdbfile); 175 flatdbfile);
181 return GNUNET_SYSERR; 176 return GNUNET_SYSERR;
182 } 177 }
183 if (GNUNET_SYSERR == 178 if (GNUNET_SYSERR ==
184 GNUNET_DISK_file_size (flatdbfile, 179 GNUNET_DISK_file_size(flatdbfile,
185 &size, 180 &size,
186 GNUNET_YES, 181 GNUNET_YES,
187 GNUNET_YES)) 182 GNUNET_YES))
188 { 183 {
189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 184 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
190 _("Unable to get filesize: %s.\n"), 185 _("Unable to get filesize: %s.\n"),
191 flatdbfile); 186 flatdbfile);
192 GNUNET_DISK_file_close (fh); 187 GNUNET_DISK_file_close(fh);
193 return GNUNET_SYSERR; 188 return GNUNET_SYSERR;
194 } 189 }
195 if (size > SIZE_MAX) 190 if (size > SIZE_MAX)
196 { 191 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 192 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
198 _("File too big to map: %llu bytes.\n"), 193 _("File too big to map: %llu bytes.\n"),
199 (unsigned long long) size); 194 (unsigned long long)size);
200 GNUNET_DISK_file_close (fh); 195 GNUNET_DISK_file_close(fh);
201 return GNUNET_SYSERR; 196 return GNUNET_SYSERR;
202 } 197 }
203 if (0 == size) 198 if (0 == size)
204 { 199 {
205 GNUNET_DISK_file_close (fh); 200 GNUNET_DISK_file_close(fh);
206 return GNUNET_OK; 201 return GNUNET_OK;
207 } 202 }
208 buffer = GNUNET_DISK_file_map (fh, 203 buffer = GNUNET_DISK_file_map(fh,
209 &mh, 204 &mh,
210 GNUNET_DISK_MAP_TYPE_READ, 205 GNUNET_DISK_MAP_TYPE_READ,
211 size); 206 size);
212 if (NULL == buffer) 207 if (NULL == buffer)
213 { 208 {
214 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
215 "mmap"); 210 "mmap");
216 GNUNET_DISK_file_close (fh); 211 GNUNET_DISK_file_close(fh);
217 return GNUNET_SYSERR; 212 return GNUNET_SYSERR;
218 } 213 }
219 if ('\0' != buffer[size-1]) 214 if ('\0' != buffer[size - 1])
220 { 215 {
221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 216 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
222 _("Namestore database file `%s' malformed\n"), 217 _("Namestore database file `%s' malformed\n"),
223 flatdbfile); 218 flatdbfile);
224 GNUNET_DISK_file_unmap (mh); 219 GNUNET_DISK_file_unmap(mh);
225 GNUNET_DISK_file_close (fh); 220 GNUNET_DISK_file_close(fh);
226 return GNUNET_SYSERR; 221 return GNUNET_SYSERR;
227 } 222 }
228 223
229 line = strtok (buffer, "\n"); 224 line = strtok(buffer, "\n");
230 while (NULL != line) 225 while (NULL != line)
231 {
232 zone_private_key = strtok (line, ",");
233 if (NULL == zone_private_key)
234 break;
235 rvalue = strtok (NULL, ",");
236 if (NULL == rvalue)
237 break;
238 record_count = strtok (NULL, ",");
239 if (NULL == record_count)
240 break;
241 record_data_b64 = strtok (NULL, ",");
242 if (NULL == record_data_b64)
243 break;
244 label = strtok (NULL, ",");
245 if (NULL == label)
246 break;
247 line = strtok (NULL, "\n");
248 entry = GNUNET_new (struct FlatFileEntry);
249 { 226 {
250 unsigned long long ll; 227 zone_private_key = strtok(line, ",");
251 228 if (NULL == zone_private_key)
252 if (1 != sscanf (rvalue, 229 break;
253 "%llu", 230 rvalue = strtok(NULL, ",");
254 &ll)) 231 if (NULL == rvalue)
255 { 232 break;
256 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 233 record_count = strtok(NULL, ",");
257 "Error parsing entry\n"); 234 if (NULL == record_count)
258 GNUNET_free (entry);
259 break; 235 break;
236 record_data_b64 = strtok(NULL, ",");
237 if (NULL == record_data_b64)
238 break;
239 label = strtok(NULL, ",");
240 if (NULL == label)
241 break;
242 line = strtok(NULL, "\n");
243 entry = GNUNET_new(struct FlatFileEntry);
244 {
245 unsigned long long ll;
246
247 if (1 != sscanf(rvalue,
248 "%llu",
249 &ll))
250 {
251 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
252 "Error parsing entry\n");
253 GNUNET_free(entry);
254 break;
255 }
256 entry->rvalue = (uint64_t)ll;
260 } 257 }
261 entry->rvalue = (uint64_t) ll; 258 {
262 } 259 unsigned int ui;
263 { 260
264 unsigned int ui; 261 if (1 != sscanf(record_count,
262 "%u",
263 &ui))
264 {
265 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
266 "Error parsing entry\n");
267 GNUNET_free(entry);
268 break;
269 }
270 entry->record_count = (uint32_t)ui;
271 }
272 entry->label = GNUNET_strdup(label);
273 record_data_size
274 = GNUNET_STRINGS_base64_decode(record_data_b64,
275 strlen(record_data_b64),
276 (void **)&record_data);
277 entry->record_data =
278 GNUNET_new_array(entry->record_count,
279 struct GNUNET_GNSRECORD_Data);
280 if (GNUNET_OK !=
281 GNUNET_GNSRECORD_records_deserialize(record_data_size,
282 record_data,
283 entry->record_count,
284 entry->record_data))
285 {
286 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
287 "Unable to deserialize record %s\n",
288 label);
289 GNUNET_free(entry->label);
290 GNUNET_free(entry);
291 GNUNET_free(record_data);
292 break;
293 }
294 GNUNET_free(record_data);
265 295
266 if (1 != sscanf (record_count,
267 "%u",
268 &ui))
269 { 296 {
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 297 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key;
271 "Error parsing entry\n"); 298
272 GNUNET_free (entry); 299 GNUNET_STRINGS_base64_decode(zone_private_key,
273 break; 300 strlen(zone_private_key),
301 (void**)&private_key);
302 entry->private_key = *private_key;
303 GNUNET_free(private_key);
274 } 304 }
275 entry->record_count = (uint32_t) ui; 305
276 } 306 hash_pkey_and_label(&entry->private_key,
277 entry->label = GNUNET_strdup (label); 307 label,
278 record_data_size 308 &hkey);
279 = GNUNET_STRINGS_base64_decode (record_data_b64, 309 if (GNUNET_OK !=
280 strlen (record_data_b64), 310 GNUNET_CONTAINER_multihashmap_put(plugin->hm,
281 (void **) &record_data); 311 &hkey,
282 entry->record_data = 312 entry,
283 GNUNET_new_array (entry->record_count, 313 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
284 struct GNUNET_GNSRECORD_Data); 314 {
285 if (GNUNET_OK != 315 GNUNET_free(entry);
286 GNUNET_GNSRECORD_records_deserialize (record_data_size, 316 GNUNET_break(0);
287 record_data, 317 }
288 entry->record_count,
289 entry->record_data))
290 {
291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
292 "Unable to deserialize record %s\n",
293 label);
294 GNUNET_free (entry->label);
295 GNUNET_free (entry);
296 GNUNET_free (record_data);
297 break;
298 }
299 GNUNET_free (record_data);
300
301 {
302 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key;
303
304 GNUNET_STRINGS_base64_decode (zone_private_key,
305 strlen (zone_private_key),
306 (void**)&private_key);
307 entry->private_key = *private_key;
308 GNUNET_free (private_key);
309 }
310
311 hash_pkey_and_label (&entry->private_key,
312 label,
313 &hkey);
314 if (GNUNET_OK !=
315 GNUNET_CONTAINER_multihashmap_put (plugin->hm,
316 &hkey,
317 entry,
318 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
319 {
320 GNUNET_free (entry);
321 GNUNET_break (0);
322 } 318 }
323 } 319 GNUNET_DISK_file_unmap(mh);
324 GNUNET_DISK_file_unmap (mh); 320 GNUNET_DISK_file_close(fh);
325 GNUNET_DISK_file_close (fh);
326 return GNUNET_OK; 321 return GNUNET_OK;
327} 322}
328 323
@@ -335,9 +330,9 @@ database_setup (struct Plugin *plugin)
335 * @param value a `struct FlatFileEntry` 330 * @param value a `struct FlatFileEntry`
336 */ 331 */
337static int 332static int
338store_and_free_entries (void *cls, 333store_and_free_entries(void *cls,
339 const struct GNUNET_HashCode *key, 334 const struct GNUNET_HashCode *key,
340 void *value) 335 void *value)
341{ 336{
342 struct GNUNET_DISK_FileHandle *fh = cls; 337 struct GNUNET_DISK_FileHandle *fh = cls;
343 struct FlatFileEntry *entry = value; 338 struct FlatFileEntry *entry = value;
@@ -346,61 +341,61 @@ store_and_free_entries (void *cls,
346 char *record_data_b64; 341 char *record_data_b64;
347 ssize_t data_size; 342 ssize_t data_size;
348 343
349 (void) key; 344 (void)key;
350 GNUNET_STRINGS_base64_encode (&entry->private_key, 345 GNUNET_STRINGS_base64_encode(&entry->private_key,
351 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 346 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
352 &zone_private_key); 347 &zone_private_key);
353 data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, 348 data_size = GNUNET_GNSRECORD_records_get_size(entry->record_count,
354 entry->record_data); 349 entry->record_data);
355 if (data_size < 0) 350 if (data_size < 0)
356 { 351 {
357 GNUNET_break (0); 352 GNUNET_break(0);
358 GNUNET_free (zone_private_key); 353 GNUNET_free(zone_private_key);
359 return GNUNET_SYSERR; 354 return GNUNET_SYSERR;
360 } 355 }
361 if (data_size >= UINT16_MAX) 356 if (data_size >= UINT16_MAX)
362 { 357 {
363 GNUNET_break (0); 358 GNUNET_break(0);
364 GNUNET_free (zone_private_key); 359 GNUNET_free(zone_private_key);
365 return GNUNET_SYSERR; 360 return GNUNET_SYSERR;
366 } 361 }
367 { 362 {
368 char data[data_size]; 363 char data[data_size];
369 ssize_t ret; 364 ssize_t ret;
370 365
371 ret = GNUNET_GNSRECORD_records_serialize (entry->record_count, 366 ret = GNUNET_GNSRECORD_records_serialize(entry->record_count,
372 entry->record_data, 367 entry->record_data,
373 data_size, 368 data_size,
374 data); 369 data);
375 if ( (ret < 0) || 370 if ((ret < 0) ||
376 (data_size != ret) ) 371 (data_size != ret))
377 { 372 {
378 GNUNET_break (0); 373 GNUNET_break(0);
379 GNUNET_free (zone_private_key); 374 GNUNET_free(zone_private_key);
380 return GNUNET_SYSERR; 375 return GNUNET_SYSERR;
381 } 376 }
382 GNUNET_STRINGS_base64_encode (data, 377 GNUNET_STRINGS_base64_encode(data,
383 data_size, 378 data_size,
384 &record_data_b64); 379 &record_data_b64);
385 } 380 }
386 GNUNET_asprintf (&line, 381 GNUNET_asprintf(&line,
387 "%s,%llu,%u,%s,%s\n", 382 "%s,%llu,%u,%s,%s\n",
388 zone_private_key, 383 zone_private_key,
389 (unsigned long long) entry->rvalue, 384 (unsigned long long)entry->rvalue,
390 (unsigned int) entry->record_count, 385 (unsigned int)entry->record_count,
391 record_data_b64, 386 record_data_b64,
392 entry->label); 387 entry->label);
393 GNUNET_free (record_data_b64); 388 GNUNET_free(record_data_b64);
394 GNUNET_free (zone_private_key); 389 GNUNET_free(zone_private_key);
395 390
396 GNUNET_DISK_file_write (fh, 391 GNUNET_DISK_file_write(fh,
397 line, 392 line,
398 strlen (line)); 393 strlen(line));
399 394
400 GNUNET_free (line); 395 GNUNET_free(line);
401 GNUNET_free (entry->label); 396 GNUNET_free(entry->label);
402 GNUNET_free (entry->record_data); 397 GNUNET_free(entry->record_data);
403 GNUNET_free (entry); 398 GNUNET_free(entry);
404 return GNUNET_YES; 399 return GNUNET_YES;
405} 400}
406 401
@@ -411,33 +406,33 @@ store_and_free_entries (void *cls,
411 * @param plugin the plugin context (state for this module) 406 * @param plugin the plugin context (state for this module)
412 */ 407 */
413static void 408static void
414database_shutdown (struct Plugin *plugin) 409database_shutdown(struct Plugin *plugin)
415{ 410{
416 struct GNUNET_DISK_FileHandle *fh; 411 struct GNUNET_DISK_FileHandle *fh;
417 412
418 fh = GNUNET_DISK_file_open (plugin->fn, 413 fh = GNUNET_DISK_file_open(plugin->fn,
419 GNUNET_DISK_OPEN_CREATE | 414 GNUNET_DISK_OPEN_CREATE |
420 GNUNET_DISK_OPEN_TRUNCATE | 415 GNUNET_DISK_OPEN_TRUNCATE |
421 GNUNET_DISK_OPEN_READWRITE, 416 GNUNET_DISK_OPEN_READWRITE,
422 GNUNET_DISK_PERM_USER_WRITE | 417 GNUNET_DISK_PERM_USER_WRITE |
423 GNUNET_DISK_PERM_USER_READ); 418 GNUNET_DISK_PERM_USER_READ);
424 if (NULL == fh) 419 if (NULL == fh)
425 { 420 {
426 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 421 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
427 _("Unable to initialize file: %s.\n"), 422 _("Unable to initialize file: %s.\n"),
428 plugin->fn); 423 plugin->fn);
429 return; 424 return;
430 } 425 }
431 426
432 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 427 GNUNET_CONTAINER_multihashmap_iterate(plugin->hm,
433 &store_and_free_entries, 428 &store_and_free_entries,
434 fh); 429 fh);
435 GNUNET_CONTAINER_multihashmap_destroy (plugin->hm); 430 GNUNET_CONTAINER_multihashmap_destroy(plugin->hm);
436 /* append 0-terminator */ 431 /* append 0-terminator */
437 GNUNET_DISK_file_write (fh, 432 GNUNET_DISK_file_write(fh,
438 "", 433 "",
439 1); 434 1);
440 GNUNET_DISK_file_close (fh); 435 GNUNET_DISK_file_close(fh);
441} 436}
442 437
443 438
@@ -453,57 +448,57 @@ database_shutdown (struct Plugin *plugin)
453 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 448 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
454 */ 449 */
455static int 450static int
456namestore_flat_store_records (void *cls, 451namestore_flat_store_records(void *cls,
457 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 452 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
458 const char *label, 453 const char *label,
459 unsigned int rd_count, 454 unsigned int rd_count,
460 const struct GNUNET_GNSRECORD_Data *rd) 455 const struct GNUNET_GNSRECORD_Data *rd)
461{ 456{
462 struct Plugin *plugin = cls; 457 struct Plugin *plugin = cls;
463 uint64_t rvalue; 458 uint64_t rvalue;
464 struct GNUNET_HashCode hkey; 459 struct GNUNET_HashCode hkey;
465 struct FlatFileEntry *entry; 460 struct FlatFileEntry *entry;
466 461
467 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 462 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
468 UINT64_MAX); 463 UINT64_MAX);
469 hash_pkey_and_label (zone_key, 464 hash_pkey_and_label(zone_key,
470 label, 465 label,
471 &hkey); 466 &hkey);
472 GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm, 467 GNUNET_CONTAINER_multihashmap_remove_all(plugin->hm,
473 &hkey); 468 &hkey);
474 if (0 == rd_count) 469 if (0 == rd_count)
475 { 470 {
476 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
477 "sqlite", 472 "sqlite",
478 "Record deleted\n"); 473 "Record deleted\n");
479 return GNUNET_OK; 474 return GNUNET_OK;
480 } 475 }
481 entry = GNUNET_new (struct FlatFileEntry); 476 entry = GNUNET_new(struct FlatFileEntry);
482 GNUNET_asprintf (&entry->label, 477 GNUNET_asprintf(&entry->label,
483 label, 478 label,
484 strlen (label)); 479 strlen(label));
485 GNUNET_memcpy (&entry->private_key, 480 GNUNET_memcpy(&entry->private_key,
486 zone_key, 481 zone_key,
487 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 482 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey));
488 entry->rvalue = rvalue; 483 entry->rvalue = rvalue;
489 entry->record_count = rd_count; 484 entry->record_count = rd_count;
490 entry->record_data = GNUNET_new_array (rd_count, 485 entry->record_data = GNUNET_new_array(rd_count,
491 struct GNUNET_GNSRECORD_Data); 486 struct GNUNET_GNSRECORD_Data);
492 for (unsigned int i = 0; i < rd_count; i++) 487 for (unsigned int i = 0; i < rd_count; i++)
493 { 488 {
494 entry->record_data[i].expiration_time = rd[i].expiration_time; 489 entry->record_data[i].expiration_time = rd[i].expiration_time;
495 entry->record_data[i].record_type = rd[i].record_type; 490 entry->record_data[i].record_type = rd[i].record_type;
496 entry->record_data[i].flags = rd[i].flags; 491 entry->record_data[i].flags = rd[i].flags;
497 entry->record_data[i].data_size = rd[i].data_size; 492 entry->record_data[i].data_size = rd[i].data_size;
498 entry->record_data[i].data = GNUNET_malloc (rd[i].data_size); 493 entry->record_data[i].data = GNUNET_malloc(rd[i].data_size);
499 GNUNET_memcpy ((char*)entry->record_data[i].data, 494 GNUNET_memcpy((char*)entry->record_data[i].data,
500 rd[i].data, 495 rd[i].data,
501 rd[i].data_size); 496 rd[i].data_size);
502 } 497 }
503 return GNUNET_CONTAINER_multihashmap_put (plugin->hm, 498 return GNUNET_CONTAINER_multihashmap_put(plugin->hm,
504 &hkey, 499 &hkey,
505 entry, 500 entry,
506 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 501 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
507} 502}
508 503
509 504
@@ -518,36 +513,36 @@ namestore_flat_store_records (void *cls,
518 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR 513 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
519 */ 514 */
520static int 515static int
521namestore_flat_lookup_records (void *cls, 516namestore_flat_lookup_records(void *cls,
522 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 517 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
523 const char *label, 518 const char *label,
524 GNUNET_NAMESTORE_RecordIterator iter, 519 GNUNET_NAMESTORE_RecordIterator iter,
525 void *iter_cls) 520 void *iter_cls)
526{ 521{
527 struct Plugin *plugin = cls; 522 struct Plugin *plugin = cls;
528 struct FlatFileEntry *entry; 523 struct FlatFileEntry *entry;
529 struct GNUNET_HashCode hkey; 524 struct GNUNET_HashCode hkey;
530 525
531 if (NULL == zone) 526 if (NULL == zone)
532 { 527 {
533 GNUNET_break (0); 528 GNUNET_break(0);
534 return GNUNET_SYSERR; 529 return GNUNET_SYSERR;
535 } 530 }
536 hash_pkey_and_label (zone, 531 hash_pkey_and_label(zone,
537 label, 532 label,
538 &hkey); 533 &hkey);
539 entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm, 534 entry = GNUNET_CONTAINER_multihashmap_get(plugin->hm,
540 &hkey); 535 &hkey);
541 536
542 if (NULL == entry) 537 if (NULL == entry)
543 return GNUNET_NO; 538 return GNUNET_NO;
544 if (NULL != iter) 539 if (NULL != iter)
545 iter (iter_cls, 540 iter(iter_cls,
546 1, /* zero is illegal */ 541 1, /* zero is illegal */
547 &entry->private_key, 542 &entry->private_key,
548 entry->label, 543 entry->label,
549 entry->record_count, 544 entry->record_count,
550 entry->record_data); 545 entry->record_data);
551 return GNUNET_YES; 546 return GNUNET_YES;
552} 547}
553 548
@@ -555,8 +550,7 @@ namestore_flat_lookup_records (void *cls,
555/** 550/**
556 * Closure for #iterate_zones. 551 * Closure for #iterate_zones.
557 */ 552 */
558struct IterateContext 553struct IterateContext {
559{
560 /** 554 /**
561 * How many more records should we skip before returning results? 555 * How many more records should we skip before returning results?
562 */ 556 */
@@ -587,7 +581,6 @@ struct IterateContext
587 * Closure for @e iter. 581 * Closure for @e iter.
588 */ 582 */
589 void *iter_cls; 583 void *iter_cls;
590
591}; 584};
592 585
593 586
@@ -600,34 +593,34 @@ struct IterateContext
600 * @return #GNUNET_YES to continue the iteration 593 * @return #GNUNET_YES to continue the iteration
601 */ 594 */
602static int 595static int
603iterate_zones (void *cls, 596iterate_zones(void *cls,
604 const struct GNUNET_HashCode *key, 597 const struct GNUNET_HashCode *key,
605 void *value) 598 void *value)
606{ 599{
607 struct IterateContext *ic = cls; 600 struct IterateContext *ic = cls;
608 struct FlatFileEntry *entry = value; 601 struct FlatFileEntry *entry = value;
609 602
610 (void) key; 603 (void)key;
611 if (0 == ic->limit) 604 if (0 == ic->limit)
612 return GNUNET_NO; 605 return GNUNET_NO;
613 if ( (NULL != ic->zone) && 606 if ((NULL != ic->zone) &&
614 (0 != GNUNET_memcmp (&entry->private_key, 607 (0 != GNUNET_memcmp(&entry->private_key,
615 ic->zone)) ) 608 ic->zone)))
616 return GNUNET_YES; 609 return GNUNET_YES;
617 ic->pos++; 610 ic->pos++;
618 if (ic->offset > 0) 611 if (ic->offset > 0)
619 { 612 {
620 ic->offset--; 613 ic->offset--;
621 return GNUNET_YES; 614 return GNUNET_YES;
622 } 615 }
623 ic->iter (ic->iter_cls, 616 ic->iter(ic->iter_cls,
624 ic->pos, 617 ic->pos,
625 (NULL == ic->zone) 618 (NULL == ic->zone)
626 ? &entry->private_key 619 ? &entry->private_key
627 : ic->zone, 620 : ic->zone,
628 entry->label, 621 entry->label,
629 entry->record_count, 622 entry->record_count,
630 entry->record_data); 623 entry->record_data);
631 ic->limit--; 624 ic->limit--;
632 if (0 == ic->limit) 625 if (0 == ic->limit)
633 return GNUNET_NO; 626 return GNUNET_NO;
@@ -648,12 +641,12 @@ iterate_zones (void *cls,
648 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error 641 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
649 */ 642 */
650static int 643static int
651namestore_flat_iterate_records (void *cls, 644namestore_flat_iterate_records(void *cls,
652 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 645 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
653 uint64_t serial, 646 uint64_t serial,
654 uint64_t limit, 647 uint64_t limit,
655 GNUNET_NAMESTORE_RecordIterator iter, 648 GNUNET_NAMESTORE_RecordIterator iter,
656 void *iter_cls) 649 void *iter_cls)
657{ 650{
658 struct Plugin *plugin = cls; 651 struct Plugin *plugin = cls;
659 struct IterateContext ic; 652 struct IterateContext ic;
@@ -664,9 +657,9 @@ namestore_flat_iterate_records (void *cls,
664 ic.iter = iter; 657 ic.iter = iter;
665 ic.iter_cls = iter_cls; 658 ic.iter_cls = iter_cls;
666 ic.zone = zone; 659 ic.zone = zone;
667 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 660 GNUNET_CONTAINER_multihashmap_iterate(plugin->hm,
668 &iterate_zones, 661 &iterate_zones,
669 &ic); 662 &ic);
670 return (0 == ic.limit) ? GNUNET_OK : GNUNET_NO; 663 return (0 == ic.limit) ? GNUNET_OK : GNUNET_NO;
671} 664}
672 665
@@ -674,8 +667,7 @@ namestore_flat_iterate_records (void *cls,
674/** 667/**
675 * Closure for #zone_to_name. 668 * Closure for #zone_to_name.
676 */ 669 */
677struct ZoneToNameContext 670struct ZoneToNameContext {
678{
679 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone; 671 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
680 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone; 672 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone;
681 GNUNET_NAMESTORE_RecordIterator iter; 673 GNUNET_NAMESTORE_RecordIterator iter;
@@ -686,35 +678,35 @@ struct ZoneToNameContext
686 678
687 679
688static int 680static int
689zone_to_name (void *cls, 681zone_to_name(void *cls,
690 const struct GNUNET_HashCode *key, 682 const struct GNUNET_HashCode *key,
691 void *value) 683 void *value)
692{ 684{
693 struct ZoneToNameContext *ztn = cls; 685 struct ZoneToNameContext *ztn = cls;
694 struct FlatFileEntry *entry = value; 686 struct FlatFileEntry *entry = value;
695 687
696 (void) key; 688 (void)key;
697 if (0 != GNUNET_memcmp (&entry->private_key, 689 if (0 != GNUNET_memcmp(&entry->private_key,
698 ztn->zone)) 690 ztn->zone))
699 return GNUNET_YES; 691 return GNUNET_YES;
700 692
701 for (unsigned int i = 0; i < entry->record_count; i++) 693 for (unsigned int i = 0; i < entry->record_count; i++)
702 {
703 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
704 continue;
705 if (0 == memcmp (ztn->value_zone,
706 entry->record_data[i].data,
707 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
708 { 694 {
709 ztn->iter (ztn->iter_cls, 695 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
710 i + 1, /* zero is illegal! */ 696 continue;
711 &entry->private_key, 697 if (0 == memcmp(ztn->value_zone,
712 entry->label, 698 entry->record_data[i].data,
713 entry->record_count, 699 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
714 entry->record_data); 700 {
715 ztn->result_found = GNUNET_YES; 701 ztn->iter(ztn->iter_cls,
702 i + 1, /* zero is illegal! */
703 &entry->private_key,
704 entry->label,
705 entry->record_count,
706 entry->record_data);
707 ztn->result_found = GNUNET_YES;
708 }
716 } 709 }
717 }
718 return GNUNET_YES; 710 return GNUNET_YES;
719} 711}
720 712
@@ -731,11 +723,11 @@ zone_to_name (void *cls,
731 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 723 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
732 */ 724 */
733static int 725static int
734namestore_flat_zone_to_name (void *cls, 726namestore_flat_zone_to_name(void *cls,
735 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 727 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
736 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, 728 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
737 GNUNET_NAMESTORE_RecordIterator iter, 729 GNUNET_NAMESTORE_RecordIterator iter,
738 void *iter_cls) 730 void *iter_cls)
739{ 731{
740 struct Plugin *plugin = cls; 732 struct Plugin *plugin = cls;
741 struct ZoneToNameContext ztn = { 733 struct ZoneToNameContext ztn = {
@@ -746,12 +738,12 @@ namestore_flat_zone_to_name (void *cls,
746 .result_found = GNUNET_NO 738 .result_found = GNUNET_NO
747 }; 739 };
748 740
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 741 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
750 "Performing reverse lookup for `%s'\n", 742 "Performing reverse lookup for `%s'\n",
751 GNUNET_GNSRECORD_z2s (value_zone)); 743 GNUNET_GNSRECORD_z2s(value_zone));
752 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 744 GNUNET_CONTAINER_multihashmap_iterate(plugin->hm,
753 &zone_to_name, 745 &zone_to_name,
754 &ztn); 746 &ztn);
755 return ztn.result_found; 747 return ztn.result_found;
756} 748}
757 749
@@ -763,7 +755,7 @@ namestore_flat_zone_to_name (void *cls,
763 * @return NULL on error, otherwise the plugin context 755 * @return NULL on error, otherwise the plugin context
764 */ 756 */
765void * 757void *
766libgnunet_plugin_namestore_flat_init (void *cls) 758libgnunet_plugin_namestore_flat_init(void *cls)
767{ 759{
768 static struct Plugin plugin; 760 static struct Plugin plugin;
769 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 761 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
@@ -771,23 +763,23 @@ libgnunet_plugin_namestore_flat_init (void *cls)
771 763
772 if (NULL != plugin.cfg) 764 if (NULL != plugin.cfg)
773 return NULL; /* can only initialize once! */ 765 return NULL; /* can only initialize once! */
774 memset (&plugin, 766 memset(&plugin,
775 0, 767 0,
776 sizeof (struct Plugin)); 768 sizeof(struct Plugin));
777 plugin.cfg = cfg; 769 plugin.cfg = cfg;
778 if (GNUNET_OK != database_setup (&plugin)) 770 if (GNUNET_OK != database_setup(&plugin))
779 { 771 {
780 database_shutdown (&plugin); 772 database_shutdown(&plugin);
781 return NULL; 773 return NULL;
782 } 774 }
783 api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); 775 api = GNUNET_new(struct GNUNET_NAMESTORE_PluginFunctions);
784 api->cls = &plugin; 776 api->cls = &plugin;
785 api->store_records = &namestore_flat_store_records; 777 api->store_records = &namestore_flat_store_records;
786 api->iterate_records = &namestore_flat_iterate_records; 778 api->iterate_records = &namestore_flat_iterate_records;
787 api->zone_to_name = &namestore_flat_zone_to_name; 779 api->zone_to_name = &namestore_flat_zone_to_name;
788 api->lookup_records = &namestore_flat_lookup_records; 780 api->lookup_records = &namestore_flat_lookup_records;
789 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 781 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
790 _("Flat file database running\n")); 782 _("Flat file database running\n"));
791 return api; 783 return api;
792} 784}
793 785
@@ -799,16 +791,16 @@ libgnunet_plugin_namestore_flat_init (void *cls)
799 * @return always NULL 791 * @return always NULL
800 */ 792 */
801void * 793void *
802libgnunet_plugin_namestore_flat_done (void *cls) 794libgnunet_plugin_namestore_flat_done(void *cls)
803{ 795{
804 struct GNUNET_NAMESTORE_PluginFunctions *api = cls; 796 struct GNUNET_NAMESTORE_PluginFunctions *api = cls;
805 struct Plugin *plugin = api->cls; 797 struct Plugin *plugin = api->cls;
806 798
807 database_shutdown (plugin); 799 database_shutdown(plugin);
808 plugin->cfg = NULL; 800 plugin->cfg = NULL;
809 GNUNET_free (api); 801 GNUNET_free(api);
810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 802 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
811 "Flat file plugin is finished\n"); 803 "Flat file plugin is finished\n");
812 return NULL; 804 return NULL;
813} 805}
814 806
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index f2e065882..ac35b01b4 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -1,22 +1,22 @@
1 /* 1/*
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2009-2013, 2016-2018 GNUnet e.V. 3 * Copyright (C) 2009-2013, 2016-2018 GNUnet e.V.
4 * 4 *
5 * GNUnet is free software: you can redistribute it and/or modify it 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 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, 7 * by the Free Software Foundation, either version 3 of the License,
8 * or (at your option) any later version. 8 * or (at your option) any later version.
9 * 9 *
10 * GNUnet is distributed in the hope that it will be useful, but 10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details. 13 * Affero General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Affero General Public License 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/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21/** 21/**
22 * @file namestore/plugin_namestore_postgres.c 22 * @file namestore/plugin_namestore_postgres.c
@@ -31,15 +31,13 @@
31#include "namestore.h" 31#include "namestore.h"
32 32
33 33
34#define LOG(kind,...) GNUNET_log_from (kind, "namestore-postgres", __VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log_from(kind, "namestore-postgres", __VA_ARGS__)
35 35
36 36
37/** 37/**
38 * Context for all functions in this plugin. 38 * Context for all functions in this plugin.
39 */ 39 */
40struct Plugin 40struct Plugin {
41{
42
43 /** 41 /**
44 * Our configuration. 42 * Our configuration.
45 */ 43 */
@@ -49,7 +47,6 @@ struct Plugin
49 * Native Postgres database handle. 47 * Native Postgres database handle.
50 */ 48 */
51 PGconn *dbh; 49 PGconn *dbh;
52
53}; 50};
54 51
55 52
@@ -62,136 +59,136 @@ struct Plugin
62 * @return #GNUNET_OK on success 59 * @return #GNUNET_OK on success
63 */ 60 */
64static int 61static int
65database_setup (struct Plugin *plugin) 62database_setup(struct Plugin *plugin)
66{ 63{
67 struct GNUNET_PQ_ExecuteStatement es_temporary = 64 struct GNUNET_PQ_ExecuteStatement es_temporary =
68 GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS ns098records (" 65 GNUNET_PQ_make_execute("CREATE TEMPORARY TABLE IF NOT EXISTS ns098records ("
69 " seq BIGSERIAL PRIMARY KEY," 66 " seq BIGSERIAL PRIMARY KEY,"
70 " zone_private_key BYTEA NOT NULL DEFAULT ''," 67 " zone_private_key BYTEA NOT NULL DEFAULT '',"
71 " pkey BYTEA DEFAULT ''," 68 " pkey BYTEA DEFAULT '',"
72 " rvalue BYTEA NOT NULL DEFAULT ''," 69 " rvalue BYTEA NOT NULL DEFAULT '',"
73 " record_count INTEGER NOT NULL DEFAULT 0," 70 " record_count INTEGER NOT NULL DEFAULT 0,"
74 " record_data BYTEA NOT NULL DEFAULT ''," 71 " record_data BYTEA NOT NULL DEFAULT '',"
75 " label TEXT NOT NULL DEFAULT ''," 72 " label TEXT NOT NULL DEFAULT '',"
76 " CONSTRAINT zl UNIQUE (zone_private_key,label)" 73 " CONSTRAINT zl UNIQUE (zone_private_key,label)"
77 ")" 74 ")"
78 "WITH OIDS"); 75 "WITH OIDS");
79 struct GNUNET_PQ_ExecuteStatement es_default = 76 struct GNUNET_PQ_ExecuteStatement es_default =
80 GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" 77 GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS ns098records ("
81 " seq BIGSERIAL PRIMARY KEY," 78 " seq BIGSERIAL PRIMARY KEY,"
82 " zone_private_key BYTEA NOT NULL DEFAULT ''," 79 " zone_private_key BYTEA NOT NULL DEFAULT '',"
83 " pkey BYTEA DEFAULT ''," 80 " pkey BYTEA DEFAULT '',"
84 " rvalue BYTEA NOT NULL DEFAULT ''," 81 " rvalue BYTEA NOT NULL DEFAULT '',"
85 " record_count INTEGER NOT NULL DEFAULT 0," 82 " record_count INTEGER NOT NULL DEFAULT 0,"
86 " record_data BYTEA NOT NULL DEFAULT ''," 83 " record_data BYTEA NOT NULL DEFAULT '',"
87 " label TEXT NOT NULL DEFAULT ''," 84 " label TEXT NOT NULL DEFAULT '',"
88 " CONSTRAINT zl UNIQUE (zone_private_key,label)" 85 " CONSTRAINT zl UNIQUE (zone_private_key,label)"
89 ")" 86 ")"
90 "WITH OIDS"); 87 "WITH OIDS");
91 const struct GNUNET_PQ_ExecuteStatement *cr; 88 const struct GNUNET_PQ_ExecuteStatement *cr;
92 89
93 plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, 90 plugin->dbh = GNUNET_PQ_connect_with_cfg(plugin->cfg,
94 "namestore-postgres"); 91 "namestore-postgres");
95 if (NULL == plugin->dbh) 92 if (NULL == plugin->dbh)
96 return GNUNET_SYSERR; 93 return GNUNET_SYSERR;
97 if (GNUNET_YES == 94 if (GNUNET_YES ==
98 GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, 95 GNUNET_CONFIGURATION_get_value_yesno(plugin->cfg,
99 "namestore-postgres", 96 "namestore-postgres",
100 "ASYNC_COMMIT")) 97 "ASYNC_COMMIT"))
101 {
102 struct GNUNET_PQ_ExecuteStatement es[] = {
103 GNUNET_PQ_make_try_execute ("SET synchronous_commit TO off"),
104 GNUNET_PQ_EXECUTE_STATEMENT_END
105 };
106
107 if (GNUNET_OK !=
108 GNUNET_PQ_exec_statements (plugin->dbh,
109 es))
110 { 98 {
111 PQfinish (plugin->dbh); 99 struct GNUNET_PQ_ExecuteStatement es[] = {
112 plugin->dbh = NULL; 100 GNUNET_PQ_make_try_execute("SET synchronous_commit TO off"),
113 return GNUNET_SYSERR; 101 GNUNET_PQ_EXECUTE_STATEMENT_END
102 };
103
104 if (GNUNET_OK !=
105 GNUNET_PQ_exec_statements(plugin->dbh,
106 es))
107 {
108 PQfinish(plugin->dbh);
109 plugin->dbh = NULL;
110 return GNUNET_SYSERR;
111 }
114 } 112 }
115 }
116 if (GNUNET_YES == 113 if (GNUNET_YES ==
117 GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, 114 GNUNET_CONFIGURATION_get_value_yesno(plugin->cfg,
118 "namestore-postgres", 115 "namestore-postgres",
119 "TEMPORARY_TABLE")) 116 "TEMPORARY_TABLE"))
120 { 117 {
121 cr = &es_temporary; 118 cr = &es_temporary;
122 } 119 }
123 else 120 else
124 { 121 {
125 cr = &es_default; 122 cr = &es_default;
126 } 123 }
127 124
128 { 125 {
129 struct GNUNET_PQ_ExecuteStatement es[] = { 126 struct GNUNET_PQ_ExecuteStatement es[] = {
130 *cr, 127 *cr,
131 GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " 128 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
132 "ON ns098records (zone_private_key,pkey)"), 129 "ON ns098records (zone_private_key,pkey)"),
133 GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " 130 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
134 "ON ns098records (zone_private_key,seq)"), 131 "ON ns098records (zone_private_key,seq)"),
135 GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_label " 132 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_label "
136 "ON ns098records (label)"), 133 "ON ns098records (label)"),
137 GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS zone_label " 134 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS zone_label "
138 "ON ns098records (zone_private_key,label)"), 135 "ON ns098records (zone_private_key,label)"),
139 GNUNET_PQ_EXECUTE_STATEMENT_END 136 GNUNET_PQ_EXECUTE_STATEMENT_END
140 }; 137 };
141 138
142 if (GNUNET_OK != 139 if (GNUNET_OK !=
143 GNUNET_PQ_exec_statements (plugin->dbh, 140 GNUNET_PQ_exec_statements(plugin->dbh,
144 es)) 141 es))
145 { 142 {
146 PQfinish (plugin->dbh); 143 PQfinish(plugin->dbh);
147 plugin->dbh = NULL; 144 plugin->dbh = NULL;
148 return GNUNET_SYSERR; 145 return GNUNET_SYSERR;
149 } 146 }
150 } 147 }
151 148
152 { 149 {
153 struct GNUNET_PQ_PreparedStatement ps[] = { 150 struct GNUNET_PQ_PreparedStatement ps[] = {
154 GNUNET_PQ_make_prepare ("store_records", 151 GNUNET_PQ_make_prepare("store_records",
155 "INSERT INTO ns098records" 152 "INSERT INTO ns098records"
156 " (zone_private_key, pkey, rvalue, record_count, record_data, label)" 153 " (zone_private_key, pkey, rvalue, record_count, record_data, label)"
157 " VALUES ($1, $2, $3, $4, $5, $6)" 154 " VALUES ($1, $2, $3, $4, $5, $6)"
158 " ON CONFLICT ON CONSTRAINT zl" 155 " ON CONFLICT ON CONSTRAINT zl"
159 " DO UPDATE" 156 " DO UPDATE"
160 " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5" 157 " SET pkey=$2,rvalue=$3,record_count=$4,record_data=$5"
161 " WHERE ns098records.zone_private_key = $1" 158 " WHERE ns098records.zone_private_key = $1"
162 " AND ns098records.label = $6", 159 " AND ns098records.label = $6",
163 6), 160 6),
164 GNUNET_PQ_make_prepare ("delete_records", 161 GNUNET_PQ_make_prepare("delete_records",
165 "DELETE FROM ns098records " 162 "DELETE FROM ns098records "
166 "WHERE zone_private_key=$1 AND label=$2", 163 "WHERE zone_private_key=$1 AND label=$2",
167 2), 164 2),
168 GNUNET_PQ_make_prepare ("zone_to_name", 165 GNUNET_PQ_make_prepare("zone_to_name",
169 "SELECT seq,record_count,record_data,label FROM ns098records" 166 "SELECT seq,record_count,record_data,label FROM ns098records"
170 " WHERE zone_private_key=$1 AND pkey=$2", 167 " WHERE zone_private_key=$1 AND pkey=$2",
171 2), 168 2),
172 GNUNET_PQ_make_prepare ("iterate_zone", 169 GNUNET_PQ_make_prepare("iterate_zone",
173 "SELECT seq,record_count,record_data,label FROM ns098records " 170 "SELECT seq,record_count,record_data,label FROM ns098records "
174 "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3", 171 "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3",
175 3), 172 3),
176 GNUNET_PQ_make_prepare ("iterate_all_zones", 173 GNUNET_PQ_make_prepare("iterate_all_zones",
177 "SELECT seq,record_count,record_data,label,zone_private_key" 174 "SELECT seq,record_count,record_data,label,zone_private_key"
178 " FROM ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2", 175 " FROM ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2",
179 2), 176 2),
180 GNUNET_PQ_make_prepare ("lookup_label", 177 GNUNET_PQ_make_prepare("lookup_label",
181 "SELECT seq,record_count,record_data,label " 178 "SELECT seq,record_count,record_data,label "
182 "FROM ns098records WHERE zone_private_key=$1 AND label=$2", 179 "FROM ns098records WHERE zone_private_key=$1 AND label=$2",
183 2), 180 2),
184 GNUNET_PQ_PREPARED_STATEMENT_END 181 GNUNET_PQ_PREPARED_STATEMENT_END
185 }; 182 };
186 183
187 if (GNUNET_OK != 184 if (GNUNET_OK !=
188 GNUNET_PQ_prepare_statements (plugin->dbh, 185 GNUNET_PQ_prepare_statements(plugin->dbh,
189 ps)) 186 ps))
190 { 187 {
191 PQfinish (plugin->dbh); 188 PQfinish(plugin->dbh);
192 plugin->dbh = NULL; 189 plugin->dbh = NULL;
193 return GNUNET_SYSERR; 190 return GNUNET_SYSERR;
194 } 191 }
195 } 192 }
196 193
197 return GNUNET_OK; 194 return GNUNET_OK;
@@ -210,97 +207,97 @@ database_setup (struct Plugin *plugin)
210 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 207 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
211 */ 208 */
212static int 209static int
213namestore_postgres_store_records (void *cls, 210namestore_postgres_store_records(void *cls,
214 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 211 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
215 const char *label, 212 const char *label,
216 unsigned int rd_count, 213 unsigned int rd_count,
217 const struct GNUNET_GNSRECORD_Data *rd) 214 const struct GNUNET_GNSRECORD_Data *rd)
218{ 215{
219 struct Plugin *plugin = cls; 216 struct Plugin *plugin = cls;
220 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 217 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
221 uint64_t rvalue; 218 uint64_t rvalue;
222 uint32_t rd_count32 = (uint32_t) rd_count; 219 uint32_t rd_count32 = (uint32_t)rd_count;
223 ssize_t data_size; 220 ssize_t data_size;
224 221
225 memset (&pkey, 222 memset(&pkey,
226 0, 223 0,
227 sizeof (pkey)); 224 sizeof(pkey));
228 for (unsigned int i=0;i<rd_count;i++) 225 for (unsigned int i = 0; i < rd_count; i++)
229 if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) 226 if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type)
227 {
228 GNUNET_break(sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) == rd[i].data_size);
229 GNUNET_memcpy(&pkey,
230 rd[i].data,
231 rd[i].data_size);
232 break;
233 }
234 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
235 UINT64_MAX);
236 data_size = GNUNET_GNSRECORD_records_get_size(rd_count,
237 rd);
238 if (data_size < 0)
230 { 239 {
231 GNUNET_break (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) == rd[i].data_size); 240 GNUNET_break(0);
232 GNUNET_memcpy (&pkey, 241 return GNUNET_SYSERR;
233 rd[i].data,
234 rd[i].data_size);
235 break;
236 } 242 }
237 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
238 UINT64_MAX);
239 data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
240 rd);
241 if (data_size < 0)
242 {
243 GNUNET_break (0);
244 return GNUNET_SYSERR;
245 }
246 if (data_size >= UINT16_MAX) 243 if (data_size >= UINT16_MAX)
247 { 244 {
248 GNUNET_break (0); 245 GNUNET_break(0);
249 return GNUNET_SYSERR; 246 return GNUNET_SYSERR;
250 } 247 }
251 /* if record set is empty, delete existing records */ 248 /* if record set is empty, delete existing records */
252 if (0 == rd_count) 249 if (0 == rd_count)
253 {
254 struct GNUNET_PQ_QueryParam params[] = {
255 GNUNET_PQ_query_param_auto_from_type (zone_key),
256 GNUNET_PQ_query_param_string (label),
257 GNUNET_PQ_query_param_end
258 };
259 enum GNUNET_DB_QueryStatus res;
260
261 res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
262 "delete_records",
263 params);
264 if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) &&
265 (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != res) )
266 { 250 {
267 GNUNET_break (0); 251 struct GNUNET_PQ_QueryParam params[] = {
268 return GNUNET_SYSERR; 252 GNUNET_PQ_query_param_auto_from_type(zone_key),
253 GNUNET_PQ_query_param_string(label),
254 GNUNET_PQ_query_param_end
255 };
256 enum GNUNET_DB_QueryStatus res;
257
258 res = GNUNET_PQ_eval_prepared_non_select(plugin->dbh,
259 "delete_records",
260 params);
261 if ((GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) &&
262 (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != res))
263 {
264 GNUNET_break(0);
265 return GNUNET_SYSERR;
266 }
267 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
268 "postgres",
269 "Record deleted\n");
270 return GNUNET_OK;
269 } 271 }
270 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
271 "postgres",
272 "Record deleted\n");
273 return GNUNET_OK;
274 }
275 /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */ 272 /* otherwise, UPSERT (i.e. UPDATE if exists, otherwise INSERT) */
276 { 273 {
277 char data[data_size]; 274 char data[data_size];
278 struct GNUNET_PQ_QueryParam params[] = { 275 struct GNUNET_PQ_QueryParam params[] = {
279 GNUNET_PQ_query_param_auto_from_type (zone_key), 276 GNUNET_PQ_query_param_auto_from_type(zone_key),
280 GNUNET_PQ_query_param_auto_from_type (&pkey), 277 GNUNET_PQ_query_param_auto_from_type(&pkey),
281 GNUNET_PQ_query_param_uint64 (&rvalue), 278 GNUNET_PQ_query_param_uint64(&rvalue),
282 GNUNET_PQ_query_param_uint32 (&rd_count32), 279 GNUNET_PQ_query_param_uint32(&rd_count32),
283 GNUNET_PQ_query_param_fixed_size (data, data_size), 280 GNUNET_PQ_query_param_fixed_size(data, data_size),
284 GNUNET_PQ_query_param_string (label), 281 GNUNET_PQ_query_param_string(label),
285 GNUNET_PQ_query_param_end 282 GNUNET_PQ_query_param_end
286 }; 283 };
287 enum GNUNET_DB_QueryStatus res; 284 enum GNUNET_DB_QueryStatus res;
288 ssize_t ret; 285 ssize_t ret;
289 286
290 ret = GNUNET_GNSRECORD_records_serialize (rd_count, 287 ret = GNUNET_GNSRECORD_records_serialize(rd_count,
291 rd, 288 rd,
292 data_size, 289 data_size,
293 data); 290 data);
294 if ( (ret < 0) || 291 if ((ret < 0) ||
295 (data_size != ret) ) 292 (data_size != ret))
296 { 293 {
297 GNUNET_break (0); 294 GNUNET_break(0);
298 return GNUNET_SYSERR; 295 return GNUNET_SYSERR;
299 } 296 }
300 297
301 res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, 298 res = GNUNET_PQ_eval_prepared_non_select(plugin->dbh,
302 "store_records", 299 "store_records",
303 params); 300 params);
304 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res) 301 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != res)
305 return GNUNET_SYSERR; 302 return GNUNET_SYSERR;
306 } 303 }
@@ -311,8 +308,7 @@ namestore_postgres_store_records (void *cls,
311/** 308/**
312 * Closure for #parse_result_call_iterator. 309 * Closure for #parse_result_call_iterator.
313 */ 310 */
314struct ParserContext 311struct ParserContext {
315{
316 /** 312 /**
317 * Function to call for each result. 313 * Function to call for each result.
318 */ 314 */
@@ -345,81 +341,81 @@ struct ParserContext
345 * @param num_result the number of results in @a result 341 * @param num_result the number of results in @a result
346 */ 342 */
347static void 343static void
348parse_result_call_iterator (void *cls, 344parse_result_call_iterator(void *cls,
349 PGresult *res, 345 PGresult *res,
350 unsigned int num_results) 346 unsigned int num_results)
351{ 347{
352 struct ParserContext *pc = cls; 348 struct ParserContext *pc = cls;
353 349
354 if (NULL == pc->iter) 350 if (NULL == pc->iter)
355 return; /* no need to do more work */ 351 return; /* no need to do more work */
356 for (unsigned int i=0;i<num_results;i++) 352 for (unsigned int i = 0; i < num_results; i++)
357 {
358 uint64_t serial;
359 void *data;
360 size_t data_size;
361 uint32_t record_count;
362 char *label;
363 struct GNUNET_CRYPTO_EcdsaPrivateKey zk;
364 struct GNUNET_PQ_ResultSpec rs_with_zone[] = {
365 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
366 GNUNET_PQ_result_spec_uint32 ("record_count", &record_count),
367 GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size),
368 GNUNET_PQ_result_spec_string ("label", &label),
369 GNUNET_PQ_result_spec_auto_from_type ("zone_private_key", &zk),
370 GNUNET_PQ_result_spec_end
371 };
372 struct GNUNET_PQ_ResultSpec rs_without_zone[] = {
373 GNUNET_PQ_result_spec_uint64 ("seq", &serial),
374 GNUNET_PQ_result_spec_uint32 ("record_count", &record_count),
375 GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size),
376 GNUNET_PQ_result_spec_string ("label", &label),
377 GNUNET_PQ_result_spec_end
378 };
379 struct GNUNET_PQ_ResultSpec *rs;
380
381 rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone;
382 if (GNUNET_YES !=
383 GNUNET_PQ_extract_result (res,
384 rs,
385 i))
386 {
387 GNUNET_break (0);
388 return;
389 }
390
391 if (record_count > 64 * 1024)
392 {
393 /* sanity check, don't stack allocate far too much just
394 because database might contain a large value here */
395 GNUNET_break (0);
396 GNUNET_PQ_cleanup_result (rs);
397 return;
398 }
399
400 { 353 {
401 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(record_count)]; 354 uint64_t serial;
355 void *data;
356 size_t data_size;
357 uint32_t record_count;
358 char *label;
359 struct GNUNET_CRYPTO_EcdsaPrivateKey zk;
360 struct GNUNET_PQ_ResultSpec rs_with_zone[] = {
361 GNUNET_PQ_result_spec_uint64("seq", &serial),
362 GNUNET_PQ_result_spec_uint32("record_count", &record_count),
363 GNUNET_PQ_result_spec_variable_size("record_data", &data, &data_size),
364 GNUNET_PQ_result_spec_string("label", &label),
365 GNUNET_PQ_result_spec_auto_from_type("zone_private_key", &zk),
366 GNUNET_PQ_result_spec_end
367 };
368 struct GNUNET_PQ_ResultSpec rs_without_zone[] = {
369 GNUNET_PQ_result_spec_uint64("seq", &serial),
370 GNUNET_PQ_result_spec_uint32("record_count", &record_count),
371 GNUNET_PQ_result_spec_variable_size("record_data", &data, &data_size),
372 GNUNET_PQ_result_spec_string("label", &label),
373 GNUNET_PQ_result_spec_end
374 };
375 struct GNUNET_PQ_ResultSpec *rs;
376
377 rs = (NULL == pc->zone_key) ? rs_with_zone : rs_without_zone;
378 if (GNUNET_YES !=
379 GNUNET_PQ_extract_result(res,
380 rs,
381 i))
382 {
383 GNUNET_break(0);
384 return;
385 }
386
387 if (record_count > 64 * 1024)
388 {
389 /* sanity check, don't stack allocate far too much just
390 because database might contain a large value here */
391 GNUNET_break(0);
392 GNUNET_PQ_cleanup_result(rs);
393 return;
394 }
402 395
403 GNUNET_assert (0 != serial);
404 if (GNUNET_OK !=
405 GNUNET_GNSRECORD_records_deserialize (data_size,
406 data,
407 record_count,
408 rd))
409 { 396 {
410 GNUNET_break (0); 397 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(record_count)];
411 GNUNET_PQ_cleanup_result (rs); 398
412 return; 399 GNUNET_assert(0 != serial);
400 if (GNUNET_OK !=
401 GNUNET_GNSRECORD_records_deserialize(data_size,
402 data,
403 record_count,
404 rd))
405 {
406 GNUNET_break(0);
407 GNUNET_PQ_cleanup_result(rs);
408 return;
409 }
410 pc->iter(pc->iter_cls,
411 serial,
412 (NULL == pc->zone_key) ? &zk : pc->zone_key,
413 label,
414 record_count,
415 rd);
413 } 416 }
414 pc->iter (pc->iter_cls, 417 GNUNET_PQ_cleanup_result(rs);
415 serial,
416 (NULL == pc->zone_key) ? &zk : pc->zone_key,
417 label,
418 record_count,
419 rd);
420 } 418 }
421 GNUNET_PQ_cleanup_result (rs);
422 }
423 pc->limit -= num_results; 419 pc->limit -= num_results;
424} 420}
425 421
@@ -435,34 +431,34 @@ parse_result_call_iterator (void *cls,
435 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR 431 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
436 */ 432 */
437static int 433static int
438namestore_postgres_lookup_records (void *cls, 434namestore_postgres_lookup_records(void *cls,
439 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 435 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
440 const char *label, 436 const char *label,
441 GNUNET_NAMESTORE_RecordIterator iter, 437 GNUNET_NAMESTORE_RecordIterator iter,
442 void *iter_cls) 438 void *iter_cls)
443{ 439{
444 struct Plugin *plugin = cls; 440 struct Plugin *plugin = cls;
445 struct GNUNET_PQ_QueryParam params[] = { 441 struct GNUNET_PQ_QueryParam params[] = {
446 GNUNET_PQ_query_param_auto_from_type (zone), 442 GNUNET_PQ_query_param_auto_from_type(zone),
447 GNUNET_PQ_query_param_string (label), 443 GNUNET_PQ_query_param_string(label),
448 GNUNET_PQ_query_param_end 444 GNUNET_PQ_query_param_end
449 }; 445 };
450 struct ParserContext pc; 446 struct ParserContext pc;
451 enum GNUNET_DB_QueryStatus res; 447 enum GNUNET_DB_QueryStatus res;
452 448
453 if (NULL == zone) 449 if (NULL == zone)
454 { 450 {
455 GNUNET_break (0); 451 GNUNET_break(0);
456 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
457 } 453 }
458 pc.iter = iter; 454 pc.iter = iter;
459 pc.iter_cls = iter_cls; 455 pc.iter_cls = iter_cls;
460 pc.zone_key = zone; 456 pc.zone_key = zone;
461 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, 457 res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh,
462 "lookup_label", 458 "lookup_label",
463 params, 459 params,
464 &parse_result_call_iterator, 460 &parse_result_call_iterator,
465 &pc); 461 &pc);
466 if (res < 0) 462 if (res < 0)
467 return GNUNET_SYSERR; 463 return GNUNET_SYSERR;
468 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) 464 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res)
@@ -484,12 +480,12 @@ namestore_postgres_lookup_records (void *cls,
484 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error 480 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
485 */ 481 */
486static int 482static int
487namestore_postgres_iterate_records (void *cls, 483namestore_postgres_iterate_records(void *cls,
488 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 484 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
489 uint64_t serial, 485 uint64_t serial,
490 uint64_t limit, 486 uint64_t limit,
491 GNUNET_NAMESTORE_RecordIterator iter, 487 GNUNET_NAMESTORE_RecordIterator iter,
492 void *iter_cls) 488 void *iter_cls)
493{ 489{
494 struct Plugin *plugin = cls; 490 struct Plugin *plugin = cls;
495 enum GNUNET_DB_QueryStatus res; 491 enum GNUNET_DB_QueryStatus res;
@@ -500,39 +496,39 @@ namestore_postgres_iterate_records (void *cls,
500 pc.zone_key = zone; 496 pc.zone_key = zone;
501 pc.limit = limit; 497 pc.limit = limit;
502 if (NULL == zone) 498 if (NULL == zone)
503 { 499 {
504 struct GNUNET_PQ_QueryParam params_without_zone[] = { 500 struct GNUNET_PQ_QueryParam params_without_zone[] = {
505 GNUNET_PQ_query_param_uint64 (&serial), 501 GNUNET_PQ_query_param_uint64(&serial),
506 GNUNET_PQ_query_param_uint64 (&limit), 502 GNUNET_PQ_query_param_uint64(&limit),
507 GNUNET_PQ_query_param_end 503 GNUNET_PQ_query_param_end
508 }; 504 };
509 505
510 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, 506 res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh,
511 "iterate_all_zones", 507 "iterate_all_zones",
512 params_without_zone, 508 params_without_zone,
513 &parse_result_call_iterator, 509 &parse_result_call_iterator,
514 &pc); 510 &pc);
515 } 511 }
516 else 512 else
517 { 513 {
518 struct GNUNET_PQ_QueryParam params_with_zone[] = { 514 struct GNUNET_PQ_QueryParam params_with_zone[] = {
519 GNUNET_PQ_query_param_auto_from_type (zone), 515 GNUNET_PQ_query_param_auto_from_type(zone),
520 GNUNET_PQ_query_param_uint64 (&serial), 516 GNUNET_PQ_query_param_uint64(&serial),
521 GNUNET_PQ_query_param_uint64 (&limit), 517 GNUNET_PQ_query_param_uint64(&limit),
522 GNUNET_PQ_query_param_end 518 GNUNET_PQ_query_param_end
523 }; 519 };
524 520
525 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, 521 res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh,
526 "iterate_zone", 522 "iterate_zone",
527 params_with_zone, 523 params_with_zone,
528 &parse_result_call_iterator, 524 &parse_result_call_iterator,
529 &pc); 525 &pc);
530 } 526 }
531 if (res < 0) 527 if (res < 0)
532 return GNUNET_SYSERR; 528 return GNUNET_SYSERR;
533 529
534 if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) || 530 if ((GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == res) ||
535 (pc.limit > 0) ) 531 (pc.limit > 0))
536 return GNUNET_NO; 532 return GNUNET_NO;
537 return GNUNET_OK; 533 return GNUNET_OK;
538} 534}
@@ -550,15 +546,15 @@ namestore_postgres_iterate_records (void *cls,
550 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 546 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
551 */ 547 */
552static int 548static int
553namestore_postgres_zone_to_name (void *cls, 549namestore_postgres_zone_to_name(void *cls,
554 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 550 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
555 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, 551 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
556 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) 552 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
557{ 553{
558 struct Plugin *plugin = cls; 554 struct Plugin *plugin = cls;
559 struct GNUNET_PQ_QueryParam params[] = { 555 struct GNUNET_PQ_QueryParam params[] = {
560 GNUNET_PQ_query_param_auto_from_type (zone), 556 GNUNET_PQ_query_param_auto_from_type(zone),
561 GNUNET_PQ_query_param_auto_from_type (value_zone), 557 GNUNET_PQ_query_param_auto_from_type(value_zone),
562 GNUNET_PQ_query_param_end 558 GNUNET_PQ_query_param_end
563 }; 559 };
564 enum GNUNET_DB_QueryStatus res; 560 enum GNUNET_DB_QueryStatus res;
@@ -567,11 +563,11 @@ namestore_postgres_zone_to_name (void *cls,
567 pc.iter = iter; 563 pc.iter = iter;
568 pc.iter_cls = iter_cls; 564 pc.iter_cls = iter_cls;
569 pc.zone_key = zone; 565 pc.zone_key = zone;
570 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, 566 res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh,
571 "zone_to_name", 567 "zone_to_name",
572 params, 568 params,
573 &parse_result_call_iterator, 569 &parse_result_call_iterator,
574 &pc); 570 &pc);
575 if (res < 0) 571 if (res < 0)
576 return GNUNET_SYSERR; 572 return GNUNET_SYSERR;
577 return GNUNET_OK; 573 return GNUNET_OK;
@@ -585,9 +581,9 @@ namestore_postgres_zone_to_name (void *cls,
585 * @param plugin the plugin context (state for this module) 581 * @param plugin the plugin context (state for this module)
586 */ 582 */
587static void 583static void
588database_shutdown (struct Plugin *plugin) 584database_shutdown(struct Plugin *plugin)
589{ 585{
590 PQfinish (plugin->dbh); 586 PQfinish(plugin->dbh);
591 plugin->dbh = NULL; 587 plugin->dbh = NULL;
592} 588}
593 589
@@ -599,7 +595,7 @@ database_shutdown (struct Plugin *plugin)
599 * @return NULL on error, othrewise the plugin context 595 * @return NULL on error, othrewise the plugin context
600 */ 596 */
601void * 597void *
602libgnunet_plugin_namestore_postgres_init (void *cls) 598libgnunet_plugin_namestore_postgres_init(void *cls)
603{ 599{
604 static struct Plugin plugin; 600 static struct Plugin plugin;
605 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 601 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
@@ -607,21 +603,21 @@ libgnunet_plugin_namestore_postgres_init (void *cls)
607 603
608 if (NULL != plugin.cfg) 604 if (NULL != plugin.cfg)
609 return NULL; /* can only initialize once! */ 605 return NULL; /* can only initialize once! */
610 memset (&plugin, 0, sizeof (struct Plugin)); 606 memset(&plugin, 0, sizeof(struct Plugin));
611 plugin.cfg = cfg; 607 plugin.cfg = cfg;
612 if (GNUNET_OK != database_setup (&plugin)) 608 if (GNUNET_OK != database_setup(&plugin))
613 { 609 {
614 database_shutdown (&plugin); 610 database_shutdown(&plugin);
615 return NULL; 611 return NULL;
616 } 612 }
617 api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); 613 api = GNUNET_new(struct GNUNET_NAMESTORE_PluginFunctions);
618 api->cls = &plugin; 614 api->cls = &plugin;
619 api->store_records = &namestore_postgres_store_records; 615 api->store_records = &namestore_postgres_store_records;
620 api->iterate_records = &namestore_postgres_iterate_records; 616 api->iterate_records = &namestore_postgres_iterate_records;
621 api->zone_to_name = &namestore_postgres_zone_to_name; 617 api->zone_to_name = &namestore_postgres_zone_to_name;
622 api->lookup_records = &namestore_postgres_lookup_records; 618 api->lookup_records = &namestore_postgres_lookup_records;
623 LOG (GNUNET_ERROR_TYPE_INFO, 619 LOG(GNUNET_ERROR_TYPE_INFO,
624 "Postgres namestore plugin running\n"); 620 "Postgres namestore plugin running\n");
625 return api; 621 return api;
626} 622}
627 623
@@ -633,16 +629,16 @@ libgnunet_plugin_namestore_postgres_init (void *cls)
633 * @return always NULL 629 * @return always NULL
634 */ 630 */
635void * 631void *
636libgnunet_plugin_namestore_postgres_done (void *cls) 632libgnunet_plugin_namestore_postgres_done(void *cls)
637{ 633{
638 struct GNUNET_NAMESTORE_PluginFunctions *api = cls; 634 struct GNUNET_NAMESTORE_PluginFunctions *api = cls;
639 struct Plugin *plugin = api->cls; 635 struct Plugin *plugin = api->cls;
640 636
641 database_shutdown (plugin); 637 database_shutdown(plugin);
642 plugin->cfg = NULL; 638 plugin->cfg = NULL;
643 GNUNET_free (api); 639 GNUNET_free(api);
644 LOG (GNUNET_ERROR_TYPE_DEBUG, 640 LOG(GNUNET_ERROR_TYPE_DEBUG,
645 "Postgres namestore plugin is finished\n"); 641 "Postgres namestore plugin is finished\n");
646 return NULL; 642 return NULL;
647} 643}
648 644
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index e4bfcde16..ba031217d 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -50,17 +50,15 @@
50 * a failure of the command 'cmd' on file 'filename' 50 * a failure of the command 'cmd' on file 'filename'
51 * with the message given by strerror(errno). 51 * with the message given by strerror(errno).
52 */ 52 */
53#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "namestore-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) 53#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from(level, "namestore-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while (0)
54 54
55#define LOG(kind,...) GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__) 55#define LOG(kind, ...) GNUNET_log_from(kind, "namestore-sqlite", __VA_ARGS__)
56 56
57 57
58/** 58/**
59 * Context for all functions in this plugin. 59 * Context for all functions in this plugin.
60 */ 60 */
61struct Plugin 61struct Plugin {
62{
63
64 const struct GNUNET_CONFIGURATION_Handle *cfg; 62 const struct GNUNET_CONFIGURATION_Handle *cfg;
65 63
66 /** 64 /**
@@ -114,123 +112,123 @@ struct Plugin
114 * @return #GNUNET_OK on success 112 * @return #GNUNET_OK on success
115 */ 113 */
116static int 114static int
117database_setup (struct Plugin *plugin) 115database_setup(struct Plugin *plugin)
118{ 116{
119 char *sqlite_filename; 117 char *sqlite_filename;
120 struct GNUNET_SQ_ExecuteStatement es[] = { 118 struct GNUNET_SQ_ExecuteStatement es[] = {
121 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"), 119 GNUNET_SQ_make_try_execute("PRAGMA temp_store=MEMORY"),
122 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"), 120 GNUNET_SQ_make_try_execute("PRAGMA synchronous=NORMAL"),
123 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"), 121 GNUNET_SQ_make_try_execute("PRAGMA legacy_file_format=OFF"),
124 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"), 122 GNUNET_SQ_make_try_execute("PRAGMA auto_vacuum=INCREMENTAL"),
125 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""), 123 GNUNET_SQ_make_try_execute("PRAGMA encoding=\"UTF-8\""),
126 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"), 124 GNUNET_SQ_make_try_execute("PRAGMA locking_mode=EXCLUSIVE"),
127 GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"), 125 GNUNET_SQ_make_try_execute("PRAGMA journal_mode=WAL"),
128 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"), 126 GNUNET_SQ_make_try_execute("PRAGMA page_size=4092"),
129 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" 127 GNUNET_SQ_make_execute("CREATE TABLE IF NOT EXISTS ns098records ("
130 " uid INTEGER PRIMARY KEY," 128 " uid INTEGER PRIMARY KEY,"
131 " zone_private_key BLOB NOT NULL," 129 " zone_private_key BLOB NOT NULL,"
132 " pkey BLOB," 130 " pkey BLOB,"
133 " rvalue INT8 NOT NULL," 131 " rvalue INT8 NOT NULL,"
134 " record_count INT NOT NULL," 132 " record_count INT NOT NULL,"
135 " record_data BLOB NOT NULL," 133 " record_data BLOB NOT NULL,"
136 " label TEXT NOT NULL" 134 " label TEXT NOT NULL"
137 ")"), 135 ")"),
138 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " 136 GNUNET_SQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
139 "ON ns098records (zone_private_key,pkey)"), 137 "ON ns098records (zone_private_key,pkey)"),
140 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " 138 GNUNET_SQ_make_try_execute("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
141 "ON ns098records (zone_private_key,uid)"), 139 "ON ns098records (zone_private_key,uid)"),
142 GNUNET_SQ_EXECUTE_STATEMENT_END 140 GNUNET_SQ_EXECUTE_STATEMENT_END
143 }; 141 };
144 struct GNUNET_SQ_PrepareStatement ps[] = { 142 struct GNUNET_SQ_PrepareStatement ps[] = {
145 GNUNET_SQ_make_prepare ("INSERT INTO ns098records " 143 GNUNET_SQ_make_prepare("INSERT INTO ns098records "
146 "(zone_private_key,pkey,rvalue,record_count,record_data,label)" 144 "(zone_private_key,pkey,rvalue,record_count,record_data,label)"
147 " VALUES (?, ?, ?, ?, ?, ?)", 145 " VALUES (?, ?, ?, ?, ?, ?)",
148 &plugin->store_records), 146 &plugin->store_records),
149 GNUNET_SQ_make_prepare ("DELETE FROM ns098records " 147 GNUNET_SQ_make_prepare("DELETE FROM ns098records "
150 "WHERE zone_private_key=? AND label=?", 148 "WHERE zone_private_key=? AND label=?",
151 &plugin->delete_records), 149 &plugin->delete_records),
152 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" 150 GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label"
153 " FROM ns098records" 151 " FROM ns098records"
154 " WHERE zone_private_key=? AND pkey=?", 152 " WHERE zone_private_key=? AND pkey=?",
155 &plugin->zone_to_name), 153 &plugin->zone_to_name),
156 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" 154 GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label"
157 " FROM ns098records" 155 " FROM ns098records"
158 " WHERE zone_private_key=? AND uid > ?" 156 " WHERE zone_private_key=? AND uid > ?"
159 " ORDER BY uid ASC" 157 " ORDER BY uid ASC"
160 " LIMIT ?", 158 " LIMIT ?",
161 &plugin->iterate_zone), 159 &plugin->iterate_zone),
162 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key" 160 GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label,zone_private_key"
163 " FROM ns098records" 161 " FROM ns098records"
164 " WHERE uid > ?" 162 " WHERE uid > ?"
165 " ORDER BY uid ASC" 163 " ORDER BY uid ASC"
166 " LIMIT ?", 164 " LIMIT ?",
167 &plugin->iterate_all_zones), 165 &plugin->iterate_all_zones),
168 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label" 166 GNUNET_SQ_make_prepare("SELECT uid,record_count,record_data,label"
169 " FROM ns098records" 167 " FROM ns098records"
170 " WHERE zone_private_key=? AND label=?", 168 " WHERE zone_private_key=? AND label=?",
171 &plugin->lookup_label), 169 &plugin->lookup_label),
172 GNUNET_SQ_PREPARE_END 170 GNUNET_SQ_PREPARE_END
173 }; 171 };
174 172
175 if (GNUNET_OK != 173 if (GNUNET_OK !=
176 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, 174 GNUNET_CONFIGURATION_get_value_filename(plugin->cfg,
177 "namestore-sqlite", 175 "namestore-sqlite",
178 "FILENAME", 176 "FILENAME",
179 &sqlite_filename)) 177 &sqlite_filename))
180 {
181 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
182 "namestore-sqlite",
183 "FILENAME");
184 return GNUNET_SYSERR;
185 }
186 if (GNUNET_OK !=
187 GNUNET_DISK_file_test (sqlite_filename))
188 {
189 if (GNUNET_OK !=
190 GNUNET_DISK_directory_create_for_file (sqlite_filename))
191 { 178 {
192 GNUNET_break (0); 179 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
193 GNUNET_free (sqlite_filename); 180 "namestore-sqlite",
181 "FILENAME");
194 return GNUNET_SYSERR; 182 return GNUNET_SYSERR;
195 } 183 }
196 } 184 if (GNUNET_OK !=
185 GNUNET_DISK_file_test(sqlite_filename))
186 {
187 if (GNUNET_OK !=
188 GNUNET_DISK_directory_create_for_file(sqlite_filename))
189 {
190 GNUNET_break(0);
191 GNUNET_free(sqlite_filename);
192 return GNUNET_SYSERR;
193 }
194 }
197 /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */ 195 /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
198 plugin->fn = sqlite_filename; 196 plugin->fn = sqlite_filename;
199 197
200 /* Open database and precompile statements */ 198 /* Open database and precompile statements */
201 if (SQLITE_OK != 199 if (SQLITE_OK !=
202 sqlite3_open (plugin->fn, 200 sqlite3_open(plugin->fn,
203 &plugin->dbh)) 201 &plugin->dbh))
204 { 202 {
205 LOG (GNUNET_ERROR_TYPE_ERROR, 203 LOG(GNUNET_ERROR_TYPE_ERROR,
206 _("Unable to initialize SQLite: %s.\n"), 204 _("Unable to initialize SQLite: %s.\n"),
207 sqlite3_errmsg (plugin->dbh)); 205 sqlite3_errmsg(plugin->dbh));
208 return GNUNET_SYSERR; 206 return GNUNET_SYSERR;
209 } 207 }
210 GNUNET_break (SQLITE_OK == 208 GNUNET_break(SQLITE_OK ==
211 sqlite3_busy_timeout (plugin->dbh, 209 sqlite3_busy_timeout(plugin->dbh,
212 BUSY_TIMEOUT_MS)); 210 BUSY_TIMEOUT_MS));
213 if (GNUNET_OK != 211 if (GNUNET_OK !=
214 GNUNET_SQ_exec_statements (plugin->dbh, 212 GNUNET_SQ_exec_statements(plugin->dbh,
215 es)) 213 es))
216 { 214 {
217 GNUNET_break (0); 215 GNUNET_break(0);
218 LOG (GNUNET_ERROR_TYPE_ERROR, 216 LOG(GNUNET_ERROR_TYPE_ERROR,
219 _("Failed to setup database at `%s'\n"), 217 _("Failed to setup database at `%s'\n"),
220 plugin->fn); 218 plugin->fn);
221 return GNUNET_SYSERR; 219 return GNUNET_SYSERR;
222 } 220 }
223 221
224 if (GNUNET_OK != 222 if (GNUNET_OK !=
225 GNUNET_SQ_prepare (plugin->dbh, 223 GNUNET_SQ_prepare(plugin->dbh,
226 ps)) 224 ps))
227 { 225 {
228 GNUNET_break (0); 226 GNUNET_break(0);
229 LOG (GNUNET_ERROR_TYPE_ERROR, 227 LOG(GNUNET_ERROR_TYPE_ERROR,
230 _("Failed to setup database at `%s'\n"), 228 _("Failed to setup database at `%s'\n"),
231 plugin->fn); 229 plugin->fn);
232 return GNUNET_SYSERR; 230 return GNUNET_SYSERR;
233 } 231 }
234 return GNUNET_OK; 232 return GNUNET_OK;
235} 233}
236 234
@@ -241,54 +239,54 @@ database_setup (struct Plugin *plugin)
241 * @param plugin the plugin context (state for this module) 239 * @param plugin the plugin context (state for this module)
242 */ 240 */
243static void 241static void
244database_shutdown (struct Plugin *plugin) 242database_shutdown(struct Plugin *plugin)
245{ 243{
246 int result; 244 int result;
247 sqlite3_stmt *stmt; 245 sqlite3_stmt *stmt;
248 246
249 if (NULL != plugin->store_records) 247 if (NULL != plugin->store_records)
250 sqlite3_finalize (plugin->store_records); 248 sqlite3_finalize(plugin->store_records);
251 if (NULL != plugin->delete_records) 249 if (NULL != plugin->delete_records)
252 sqlite3_finalize (plugin->delete_records); 250 sqlite3_finalize(plugin->delete_records);
253 if (NULL != plugin->iterate_zone) 251 if (NULL != plugin->iterate_zone)
254 sqlite3_finalize (plugin->iterate_zone); 252 sqlite3_finalize(plugin->iterate_zone);
255 if (NULL != plugin->iterate_all_zones) 253 if (NULL != plugin->iterate_all_zones)
256 sqlite3_finalize (plugin->iterate_all_zones); 254 sqlite3_finalize(plugin->iterate_all_zones);
257 if (NULL != plugin->zone_to_name) 255 if (NULL != plugin->zone_to_name)
258 sqlite3_finalize (plugin->zone_to_name); 256 sqlite3_finalize(plugin->zone_to_name);
259 if (NULL != plugin->lookup_label) 257 if (NULL != plugin->lookup_label)
260 sqlite3_finalize (plugin->lookup_label); 258 sqlite3_finalize(plugin->lookup_label);
261 result = sqlite3_close (plugin->dbh); 259 result = sqlite3_close(plugin->dbh);
262 if (result == SQLITE_BUSY) 260 if (result == SQLITE_BUSY)
263 {
264 LOG (GNUNET_ERROR_TYPE_WARNING,
265 _("Tried to close sqlite without finalizing all prepared statements.\n"));
266 stmt = sqlite3_next_stmt (plugin->dbh,
267 NULL);
268 while (NULL != stmt)
269 { 261 {
270 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 262 LOG(GNUNET_ERROR_TYPE_WARNING,
271 "sqlite", 263 _("Tried to close sqlite without finalizing all prepared statements.\n"));
272 "Closing statement %p\n", 264 stmt = sqlite3_next_stmt(plugin->dbh,
273 stmt); 265 NULL);
274 result = sqlite3_finalize (stmt); 266 while (NULL != stmt)
275 if (result != SQLITE_OK) 267 {
276 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 268 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
277 "sqlite", 269 "sqlite",
278 "Failed to close statement %p: %d\n", 270 "Closing statement %p\n",
279 stmt, 271 stmt);
280 result); 272 result = sqlite3_finalize(stmt);
281 stmt = sqlite3_next_stmt (plugin->dbh, 273 if (result != SQLITE_OK)
282 NULL); 274 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING,
275 "sqlite",
276 "Failed to close statement %p: %d\n",
277 stmt,
278 result);
279 stmt = sqlite3_next_stmt(plugin->dbh,
280 NULL);
281 }
282 result = sqlite3_close(plugin->dbh);
283 } 283 }
284 result = sqlite3_close (plugin->dbh);
285 }
286 if (SQLITE_OK != result) 284 if (SQLITE_OK != result)
287 LOG_SQLITE (plugin, 285 LOG_SQLITE(plugin,
288 GNUNET_ERROR_TYPE_ERROR, 286 GNUNET_ERROR_TYPE_ERROR,
289 "sqlite3_close"); 287 "sqlite3_close");
290 288
291 GNUNET_free_non_null (plugin->fn); 289 GNUNET_free_non_null(plugin->fn);
292} 290}
293 291
294 292
@@ -304,11 +302,11 @@ database_shutdown (struct Plugin *plugin)
304 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 302 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
305 */ 303 */
306static int 304static int
307namestore_sqlite_store_records (void *cls, 305namestore_sqlite_store_records(void *cls,
308 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 306 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
309 const char *label, 307 const char *label,
310 unsigned int rd_count, 308 unsigned int rd_count,
311 const struct GNUNET_GNSRECORD_Data *rd) 309 const struct GNUNET_GNSRECORD_Data *rd)
312{ 310{
313 struct Plugin *plugin = cls; 311 struct Plugin *plugin = cls;
314 int n; 312 int n;
@@ -316,121 +314,122 @@ namestore_sqlite_store_records (void *cls,
316 uint64_t rvalue; 314 uint64_t rvalue;
317 ssize_t data_size; 315 ssize_t data_size;
318 316
319 memset (&pkey, 317 memset(&pkey,
320 0, 318 0,
321 sizeof (pkey)); 319 sizeof(pkey));
322 for (unsigned int i=0;i<rd_count;i++) 320 for (unsigned int i = 0; i < rd_count; i++)
323 if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) 321 if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type)
324 { 322 {
325 GNUNET_break (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) == 323 GNUNET_break(sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) ==
326 rd[i].data_size);
327 GNUNET_memcpy (&pkey,
328 rd[i].data,
329 rd[i].data_size); 324 rd[i].data_size);
330 break; 325 GNUNET_memcpy(&pkey,
331 } 326 rd[i].data,
332 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 327 rd[i].data_size);
333 UINT64_MAX); 328 break;
334 data_size = GNUNET_GNSRECORD_records_get_size (rd_count, 329 }
335 rd); 330 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
331 UINT64_MAX);
332 data_size = GNUNET_GNSRECORD_records_get_size(rd_count,
333 rd);
336 if (data_size < 0) 334 if (data_size < 0)
337 { 335 {
338 GNUNET_break (0); 336 GNUNET_break(0);
339 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
340 } 338 }
341 if (data_size > 64 * 65536) 339 if (data_size > 64 * 65536)
342 { 340 {
343 GNUNET_break (0); 341 GNUNET_break(0);
344 return GNUNET_SYSERR; 342 return GNUNET_SYSERR;
345 } 343 }
346 { 344 {
347 /* First delete 'old' records */ 345 /* First delete 'old' records */
348 char data[data_size]; 346 char data[data_size];
349 struct GNUNET_SQ_QueryParam dparams[] = { 347 struct GNUNET_SQ_QueryParam dparams[] = {
350 GNUNET_SQ_query_param_auto_from_type (zone_key), 348 GNUNET_SQ_query_param_auto_from_type(zone_key),
351 GNUNET_SQ_query_param_string (label), 349 GNUNET_SQ_query_param_string(label),
352 GNUNET_SQ_query_param_end 350 GNUNET_SQ_query_param_end
353 }; 351 };
354 ssize_t ret; 352 ssize_t ret;
355 353
356 ret = GNUNET_GNSRECORD_records_serialize (rd_count, 354 ret = GNUNET_GNSRECORD_records_serialize(rd_count,
357 rd, 355 rd,
358 data_size, 356 data_size,
359 data); 357 data);
360 if ( (ret < 0) || 358 if ((ret < 0) ||
361 (data_size != ret) ) 359 (data_size != ret))
362 { 360 {
363 GNUNET_break (0); 361 GNUNET_break(0);
364 return GNUNET_SYSERR; 362 return GNUNET_SYSERR;
365 } 363 }
366 if (GNUNET_OK != 364 if (GNUNET_OK !=
367 GNUNET_SQ_bind (plugin->delete_records, 365 GNUNET_SQ_bind(plugin->delete_records,
368 dparams)) 366 dparams))
369 { 367 {
370 LOG_SQLITE (plugin, 368 LOG_SQLITE(plugin,
371 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 369 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
372 "sqlite3_bind_XXXX"); 370 "sqlite3_bind_XXXX");
373 GNUNET_SQ_reset (plugin->dbh, 371 GNUNET_SQ_reset(plugin->dbh,
374 plugin->delete_records); 372 plugin->delete_records);
375 return GNUNET_SYSERR; 373 return GNUNET_SYSERR;
376 374 }
377 } 375 n = sqlite3_step(plugin->delete_records);
378 n = sqlite3_step (plugin->delete_records); 376 GNUNET_SQ_reset(plugin->dbh,
379 GNUNET_SQ_reset (plugin->dbh, 377 plugin->delete_records);
380 plugin->delete_records);
381 378
382 if (0 != rd_count) 379 if (0 != rd_count)
383 {
384 uint32_t rd_count32 = (uint32_t) rd_count;
385 struct GNUNET_SQ_QueryParam sparams[] = {
386 GNUNET_SQ_query_param_auto_from_type (zone_key),
387 GNUNET_SQ_query_param_auto_from_type (&pkey),
388 GNUNET_SQ_query_param_uint64 (&rvalue),
389 GNUNET_SQ_query_param_uint32 (&rd_count32),
390 GNUNET_SQ_query_param_fixed_size (data, data_size),
391 GNUNET_SQ_query_param_string (label),
392 GNUNET_SQ_query_param_end
393 };
394
395 if (GNUNET_OK !=
396 GNUNET_SQ_bind (plugin->store_records,
397 sparams))
398 { 380 {
399 LOG_SQLITE (plugin, 381 uint32_t rd_count32 = (uint32_t)rd_count;
400 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 382 struct GNUNET_SQ_QueryParam sparams[] = {
401 "sqlite3_bind_XXXX"); 383 GNUNET_SQ_query_param_auto_from_type(zone_key),
402 GNUNET_SQ_reset (plugin->dbh, 384 GNUNET_SQ_query_param_auto_from_type(&pkey),
403 plugin->store_records); 385 GNUNET_SQ_query_param_uint64(&rvalue),
404 return GNUNET_SYSERR; 386 GNUNET_SQ_query_param_uint32(&rd_count32),
387 GNUNET_SQ_query_param_fixed_size(data, data_size),
388 GNUNET_SQ_query_param_string(label),
389 GNUNET_SQ_query_param_end
390 };
391
392 if (GNUNET_OK !=
393 GNUNET_SQ_bind(plugin->store_records,
394 sparams))
395 {
396 LOG_SQLITE(plugin,
397 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
398 "sqlite3_bind_XXXX");
399 GNUNET_SQ_reset(plugin->dbh,
400 plugin->store_records);
401 return GNUNET_SYSERR;
402 }
403 n = sqlite3_step(plugin->store_records);
404 GNUNET_SQ_reset(plugin->dbh,
405 plugin->store_records);
405 } 406 }
406 n = sqlite3_step (plugin->store_records);
407 GNUNET_SQ_reset (plugin->dbh,
408 plugin->store_records);
409 }
410 } 407 }
411 switch (n) 408 switch (n)
412 { 409 {
413 case SQLITE_DONE: 410 case SQLITE_DONE:
414 if (0 != rd_count) 411 if (0 != rd_count)
415 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 412 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
416 "sqlite", 413 "sqlite",
417 "Record stored\n"); 414 "Record stored\n");
418 else 415 else
419 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
420 "sqlite", 417 "sqlite",
421 "Record deleted\n"); 418 "Record deleted\n");
422 return GNUNET_OK; 419 return GNUNET_OK;
420
423 case SQLITE_BUSY: 421 case SQLITE_BUSY:
424 LOG_SQLITE (plugin, 422 LOG_SQLITE(plugin,
425 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 423 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
426 "sqlite3_step"); 424 "sqlite3_step");
427 return GNUNET_NO; 425 return GNUNET_NO;
426
428 default: 427 default:
429 LOG_SQLITE (plugin, 428 LOG_SQLITE(plugin,
430 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 429 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
431 "sqlite3_step"); 430 "sqlite3_step");
432 return GNUNET_SYSERR; 431 return GNUNET_SYSERR;
433 } 432 }
434} 433}
435 434
436 435
@@ -448,108 +447,108 @@ namestore_sqlite_store_records (void *cls,
448 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 447 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
449 */ 448 */
450static int 449static int
451get_records_and_call_iterator (struct Plugin *plugin, 450get_records_and_call_iterator(struct Plugin *plugin,
452 sqlite3_stmt *stmt, 451 sqlite3_stmt *stmt,
453 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 452 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
454 uint64_t limit, 453 uint64_t limit,
455 GNUNET_NAMESTORE_RecordIterator iter, 454 GNUNET_NAMESTORE_RecordIterator iter,
456 void *iter_cls) 455 void *iter_cls)
457{ 456{
458 int ret; 457 int ret;
459 int sret; 458 int sret;
460 459
461 ret = GNUNET_OK; 460 ret = GNUNET_OK;
462 for (uint64_t i = 0;i<limit;i++) 461 for (uint64_t i = 0; i < limit; i++)
463 {
464 sret = sqlite3_step (stmt);
465
466 if (SQLITE_DONE == sret)
467 {
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "Iteration done (no results)\n");
470 ret = GNUNET_NO;
471 break;
472 }
473 if (SQLITE_ROW != sret)
474 { 462 {
475 LOG_SQLITE (plugin, 463 sret = sqlite3_step(stmt);
476 GNUNET_ERROR_TYPE_ERROR,
477 "sqlite_step");
478 ret = GNUNET_SYSERR;
479 break;
480 }
481
482 {
483 uint64_t seq;
484 uint32_t record_count;
485 size_t data_size;
486 void *data;
487 char *label;
488 struct GNUNET_CRYPTO_EcdsaPrivateKey zk;
489 struct GNUNET_SQ_ResultSpec rs[] = {
490 GNUNET_SQ_result_spec_uint64 (&seq),
491 GNUNET_SQ_result_spec_uint32 (&record_count),
492 GNUNET_SQ_result_spec_variable_size (&data,
493 &data_size),
494 GNUNET_SQ_result_spec_string (&label),
495 GNUNET_SQ_result_spec_end
496 };
497 struct GNUNET_SQ_ResultSpec rsx[] = {
498 GNUNET_SQ_result_spec_uint64 (&seq),
499 GNUNET_SQ_result_spec_uint32 (&record_count),
500 GNUNET_SQ_result_spec_variable_size (&data,
501 &data_size),
502 GNUNET_SQ_result_spec_string (&label),
503 GNUNET_SQ_result_spec_auto_from_type (&zk),
504 GNUNET_SQ_result_spec_end
505 };
506
507 ret = GNUNET_SQ_extract_result (stmt,
508 (NULL == zone_key)
509 ? rsx
510 : rs);
511 if ( (GNUNET_OK != ret) ||
512 (record_count > 64 * 1024) )
513 {
514 /* sanity check, don't stack allocate far too much just
515 because database might contain a large value here */
516 GNUNET_break (0);
517 ret = GNUNET_SYSERR;
518 break;
519 }
520 else
521 {
522 struct GNUNET_GNSRECORD_Data rd[record_count];
523 464
524 GNUNET_assert (0 != seq); 465 if (SQLITE_DONE == sret)
525 if (GNUNET_OK !=
526 GNUNET_GNSRECORD_records_deserialize (data_size,
527 data,
528 record_count,
529 rd))
530 { 466 {
531 GNUNET_break (0); 467 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
532 ret = GNUNET_SYSERR; 468 "Iteration done (no results)\n");
469 ret = GNUNET_NO;
533 break; 470 break;
534 } 471 }
535 else 472 if (SQLITE_ROW != sret)
536 { 473 {
537 if (NULL != zone_key) 474 LOG_SQLITE(plugin,
538 zk = *zone_key; 475 GNUNET_ERROR_TYPE_ERROR,
539 if (NULL != iter) 476 "sqlite_step");
540 iter (iter_cls, 477 ret = GNUNET_SYSERR;
541 seq, 478 break;
542 &zk,
543 label,
544 record_count,
545 rd);
546 } 479 }
480
481 {
482 uint64_t seq;
483 uint32_t record_count;
484 size_t data_size;
485 void *data;
486 char *label;
487 struct GNUNET_CRYPTO_EcdsaPrivateKey zk;
488 struct GNUNET_SQ_ResultSpec rs[] = {
489 GNUNET_SQ_result_spec_uint64(&seq),
490 GNUNET_SQ_result_spec_uint32(&record_count),
491 GNUNET_SQ_result_spec_variable_size(&data,
492 &data_size),
493 GNUNET_SQ_result_spec_string(&label),
494 GNUNET_SQ_result_spec_end
495 };
496 struct GNUNET_SQ_ResultSpec rsx[] = {
497 GNUNET_SQ_result_spec_uint64(&seq),
498 GNUNET_SQ_result_spec_uint32(&record_count),
499 GNUNET_SQ_result_spec_variable_size(&data,
500 &data_size),
501 GNUNET_SQ_result_spec_string(&label),
502 GNUNET_SQ_result_spec_auto_from_type(&zk),
503 GNUNET_SQ_result_spec_end
504 };
505
506 ret = GNUNET_SQ_extract_result(stmt,
507 (NULL == zone_key)
508 ? rsx
509 : rs);
510 if ((GNUNET_OK != ret) ||
511 (record_count > 64 * 1024))
512 {
513 /* sanity check, don't stack allocate far too much just
514 because database might contain a large value here */
515 GNUNET_break(0);
516 ret = GNUNET_SYSERR;
517 break;
518 }
519 else
520 {
521 struct GNUNET_GNSRECORD_Data rd[record_count];
522
523 GNUNET_assert(0 != seq);
524 if (GNUNET_OK !=
525 GNUNET_GNSRECORD_records_deserialize(data_size,
526 data,
527 record_count,
528 rd))
529 {
530 GNUNET_break(0);
531 ret = GNUNET_SYSERR;
532 break;
533 }
534 else
535 {
536 if (NULL != zone_key)
537 zk = *zone_key;
538 if (NULL != iter)
539 iter(iter_cls,
540 seq,
541 &zk,
542 label,
543 record_count,
544 rd);
545 }
546 }
547 GNUNET_SQ_cleanup_result(rs);
547 } 548 }
548 GNUNET_SQ_cleanup_result (rs);
549 } 549 }
550 } 550 GNUNET_SQ_reset(plugin->dbh,
551 GNUNET_SQ_reset (plugin->dbh, 551 stmt);
552 stmt);
553 return ret; 552 return ret;
554} 553}
555 554
@@ -565,40 +564,40 @@ get_records_and_call_iterator (struct Plugin *plugin,
565 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR 564 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
566 */ 565 */
567static int 566static int
568namestore_sqlite_lookup_records (void *cls, 567namestore_sqlite_lookup_records(void *cls,
569 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 568 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
570 const char *label, 569 const char *label,
571 GNUNET_NAMESTORE_RecordIterator iter, 570 GNUNET_NAMESTORE_RecordIterator iter,
572 void *iter_cls) 571 void *iter_cls)
573{ 572{
574 struct Plugin *plugin = cls; 573 struct Plugin *plugin = cls;
575 struct GNUNET_SQ_QueryParam params[] = { 574 struct GNUNET_SQ_QueryParam params[] = {
576 GNUNET_SQ_query_param_auto_from_type (zone), 575 GNUNET_SQ_query_param_auto_from_type(zone),
577 GNUNET_SQ_query_param_string (label), 576 GNUNET_SQ_query_param_string(label),
578 GNUNET_SQ_query_param_end 577 GNUNET_SQ_query_param_end
579 }; 578 };
580 579
581 if (NULL == zone) 580 if (NULL == zone)
582 { 581 {
583 GNUNET_break (0); 582 GNUNET_break(0);
584 return GNUNET_SYSERR; 583 return GNUNET_SYSERR;
585 } 584 }
586 if (GNUNET_OK != 585 if (GNUNET_OK !=
587 GNUNET_SQ_bind (plugin->lookup_label, 586 GNUNET_SQ_bind(plugin->lookup_label,
588 params)) 587 params))
589 { 588 {
590 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 589 LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
591 "sqlite3_bind_XXXX"); 590 "sqlite3_bind_XXXX");
592 GNUNET_SQ_reset (plugin->dbh, 591 GNUNET_SQ_reset(plugin->dbh,
593 plugin->lookup_label); 592 plugin->lookup_label);
594 return GNUNET_SYSERR; 593 return GNUNET_SYSERR;
595 } 594 }
596 return get_records_and_call_iterator (plugin, 595 return get_records_and_call_iterator(plugin,
597 plugin->lookup_label, 596 plugin->lookup_label,
598 zone, 597 zone,
599 1, 598 1,
600 iter, 599 iter,
601 iter_cls); 600 iter_cls);
602} 601}
603 602
604 603
@@ -615,57 +614,57 @@ namestore_sqlite_lookup_records (void *cls,
615 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error 614 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
616 */ 615 */
617static int 616static int
618namestore_sqlite_iterate_records (void *cls, 617namestore_sqlite_iterate_records(void *cls,
619 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 618 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
620 uint64_t serial, 619 uint64_t serial,
621 uint64_t limit, 620 uint64_t limit,
622 GNUNET_NAMESTORE_RecordIterator iter, 621 GNUNET_NAMESTORE_RecordIterator iter,
623 void *iter_cls) 622 void *iter_cls)
624{ 623{
625 struct Plugin *plugin = cls; 624 struct Plugin *plugin = cls;
626 sqlite3_stmt *stmt; 625 sqlite3_stmt *stmt;
627 int err; 626 int err;
628 627
629 if (NULL == zone) 628 if (NULL == zone)
630 { 629 {
631 struct GNUNET_SQ_QueryParam params[] = { 630 struct GNUNET_SQ_QueryParam params[] = {
632 GNUNET_SQ_query_param_uint64 (&serial), 631 GNUNET_SQ_query_param_uint64(&serial),
633 GNUNET_SQ_query_param_uint64 (&limit), 632 GNUNET_SQ_query_param_uint64(&limit),
634 GNUNET_SQ_query_param_end 633 GNUNET_SQ_query_param_end
635 }; 634 };
636 635
637 stmt = plugin->iterate_all_zones; 636 stmt = plugin->iterate_all_zones;
638 err = GNUNET_SQ_bind (stmt, 637 err = GNUNET_SQ_bind(stmt,
639 params); 638 params);
640 } 639 }
641 else 640 else
642 { 641 {
643 struct GNUNET_SQ_QueryParam params[] = { 642 struct GNUNET_SQ_QueryParam params[] = {
644 GNUNET_SQ_query_param_auto_from_type (zone), 643 GNUNET_SQ_query_param_auto_from_type(zone),
645 GNUNET_SQ_query_param_uint64 (&serial), 644 GNUNET_SQ_query_param_uint64(&serial),
646 GNUNET_SQ_query_param_uint64 (&limit), 645 GNUNET_SQ_query_param_uint64(&limit),
647 GNUNET_SQ_query_param_end 646 GNUNET_SQ_query_param_end
648 }; 647 };
649 648
650 stmt = plugin->iterate_zone; 649 stmt = plugin->iterate_zone;
651 err = GNUNET_SQ_bind (stmt, 650 err = GNUNET_SQ_bind(stmt,
652 params); 651 params);
653 } 652 }
654 if (GNUNET_OK != err) 653 if (GNUNET_OK != err)
655 { 654 {
656 LOG_SQLITE (plugin, 655 LOG_SQLITE(plugin,
657 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 656 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
658 "sqlite3_bind_XXXX"); 657 "sqlite3_bind_XXXX");
659 GNUNET_SQ_reset (plugin->dbh, 658 GNUNET_SQ_reset(plugin->dbh,
660 stmt); 659 stmt);
661 return GNUNET_SYSERR; 660 return GNUNET_SYSERR;
662 } 661 }
663 return get_records_and_call_iterator (plugin, 662 return get_records_and_call_iterator(plugin,
664 stmt, 663 stmt,
665 zone, 664 zone,
666 limit, 665 limit,
667 iter, 666 iter,
668 iter_cls); 667 iter_cls);
669} 668}
670 669
671 670
@@ -681,39 +680,39 @@ namestore_sqlite_iterate_records (void *cls,
681 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 680 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
682 */ 681 */
683static int 682static int
684namestore_sqlite_zone_to_name (void *cls, 683namestore_sqlite_zone_to_name(void *cls,
685 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 684 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
686 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, 685 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
687 GNUNET_NAMESTORE_RecordIterator iter, 686 GNUNET_NAMESTORE_RecordIterator iter,
688 void *iter_cls) 687 void *iter_cls)
689{ 688{
690 struct Plugin *plugin = cls; 689 struct Plugin *plugin = cls;
691 struct GNUNET_SQ_QueryParam params[] = { 690 struct GNUNET_SQ_QueryParam params[] = {
692 GNUNET_SQ_query_param_auto_from_type (zone), 691 GNUNET_SQ_query_param_auto_from_type(zone),
693 GNUNET_SQ_query_param_auto_from_type (value_zone), 692 GNUNET_SQ_query_param_auto_from_type(value_zone),
694 GNUNET_SQ_query_param_end 693 GNUNET_SQ_query_param_end
695 }; 694 };
696 695
697 if (GNUNET_OK != 696 if (GNUNET_OK !=
698 GNUNET_SQ_bind (plugin->zone_to_name, 697 GNUNET_SQ_bind(plugin->zone_to_name,
699 params)) 698 params))
700 { 699 {
701 LOG_SQLITE (plugin, 700 LOG_SQLITE(plugin,
702 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 701 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
703 "sqlite3_bind_XXXX"); 702 "sqlite3_bind_XXXX");
704 GNUNET_SQ_reset (plugin->dbh, 703 GNUNET_SQ_reset(plugin->dbh,
705 plugin->zone_to_name); 704 plugin->zone_to_name);
706 return GNUNET_SYSERR; 705 return GNUNET_SYSERR;
707 } 706 }
708 LOG (GNUNET_ERROR_TYPE_DEBUG, 707 LOG(GNUNET_ERROR_TYPE_DEBUG,
709 "Performing reverse lookup for `%s'\n", 708 "Performing reverse lookup for `%s'\n",
710 GNUNET_GNSRECORD_z2s (value_zone)); 709 GNUNET_GNSRECORD_z2s(value_zone));
711 return get_records_and_call_iterator (plugin, 710 return get_records_and_call_iterator(plugin,
712 plugin->zone_to_name, 711 plugin->zone_to_name,
713 zone, 712 zone,
714 1, 713 1,
715 iter, 714 iter,
716 iter_cls); 715 iter_cls);
717} 716}
718 717
719 718
@@ -724,7 +723,7 @@ namestore_sqlite_zone_to_name (void *cls,
724 * @return NULL on error, otherwise the plugin context 723 * @return NULL on error, otherwise the plugin context
725 */ 724 */
726void * 725void *
727libgnunet_plugin_namestore_sqlite_init (void *cls) 726libgnunet_plugin_namestore_sqlite_init(void *cls)
728{ 727{
729 static struct Plugin plugin; 728 static struct Plugin plugin;
730 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 729 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
@@ -732,23 +731,23 @@ libgnunet_plugin_namestore_sqlite_init (void *cls)
732 731
733 if (NULL != plugin.cfg) 732 if (NULL != plugin.cfg)
734 return NULL; /* can only initialize once! */ 733 return NULL; /* can only initialize once! */
735 memset (&plugin, 734 memset(&plugin,
736 0, 735 0,
737 sizeof (struct Plugin)); 736 sizeof(struct Plugin));
738 plugin.cfg = cfg; 737 plugin.cfg = cfg;
739 if (GNUNET_OK != database_setup (&plugin)) 738 if (GNUNET_OK != database_setup(&plugin))
740 { 739 {
741 database_shutdown (&plugin); 740 database_shutdown(&plugin);
742 return NULL; 741 return NULL;
743 } 742 }
744 api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); 743 api = GNUNET_new(struct GNUNET_NAMESTORE_PluginFunctions);
745 api->cls = &plugin; 744 api->cls = &plugin;
746 api->store_records = &namestore_sqlite_store_records; 745 api->store_records = &namestore_sqlite_store_records;
747 api->iterate_records = &namestore_sqlite_iterate_records; 746 api->iterate_records = &namestore_sqlite_iterate_records;
748 api->zone_to_name = &namestore_sqlite_zone_to_name; 747 api->zone_to_name = &namestore_sqlite_zone_to_name;
749 api->lookup_records = &namestore_sqlite_lookup_records; 748 api->lookup_records = &namestore_sqlite_lookup_records;
750 LOG (GNUNET_ERROR_TYPE_INFO, 749 LOG(GNUNET_ERROR_TYPE_INFO,
751 _("Sqlite database running\n")); 750 _("Sqlite database running\n"));
752 return api; 751 return api;
753} 752}
754 753
@@ -760,16 +759,16 @@ libgnunet_plugin_namestore_sqlite_init (void *cls)
760 * @return always NULL 759 * @return always NULL
761 */ 760 */
762void * 761void *
763libgnunet_plugin_namestore_sqlite_done (void *cls) 762libgnunet_plugin_namestore_sqlite_done(void *cls)
764{ 763{
765 struct GNUNET_NAMESTORE_PluginFunctions *api = cls; 764 struct GNUNET_NAMESTORE_PluginFunctions *api = cls;
766 struct Plugin *plugin = api->cls; 765 struct Plugin *plugin = api->cls;
767 766
768 database_shutdown (plugin); 767 database_shutdown(plugin);
769 plugin->cfg = NULL; 768 plugin->cfg = NULL;
770 GNUNET_free (api); 769 GNUNET_free(api);
771 LOG (GNUNET_ERROR_TYPE_DEBUG, 770 LOG(GNUNET_ERROR_TYPE_DEBUG,
772 "sqlite plugin is finished\n"); 771 "sqlite plugin is finished\n");
773 return NULL; 772 return NULL;
774} 773}
775 774
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 1d8c180fb..42fbf8347 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @author Martin Schanzenbach 21 * @author Martin Schanzenbach
22 * @author Philippe Buschmann 22 * @author Philippe Buschmann
@@ -87,16 +87,14 @@ static char *allow_methods;
87/** 87/**
88 * @brief struct returned by the initialization function of the plugin 88 * @brief struct returned by the initialization function of the plugin
89 */ 89 */
90struct Plugin 90struct Plugin {
91{
92 const struct GNUNET_CONFIGURATION_Handle *cfg; 91 const struct GNUNET_CONFIGURATION_Handle *cfg;
93}; 92};
94 93
95/** 94/**
96 * The default namestore ego 95 * The default namestore ego
97 */ 96 */
98struct EgoEntry 97struct EgoEntry {
99{
100 /** 98 /**
101 * DLL 99 * DLL
102 */ 100 */
@@ -126,8 +124,7 @@ struct EgoEntry
126/** 124/**
127 * The request handle 125 * The request handle
128 */ 126 */
129struct RequestHandle 127struct RequestHandle {
130{
131 /** 128 /**
132 * Records to store 129 * Records to store
133 */ 130 */
@@ -244,61 +241,61 @@ struct RequestHandle
244 * @param handle Handle to clean up 241 * @param handle Handle to clean up
245 */ 242 */
246static void 243static void
247cleanup_handle (void *cls) 244cleanup_handle(void *cls)
248{ 245{
249 struct RequestHandle *handle = cls; 246 struct RequestHandle *handle = cls;
250 struct EgoEntry *ego_entry; 247 struct EgoEntry *ego_entry;
251 struct EgoEntry *ego_tmp; 248 struct EgoEntry *ego_tmp;
252 249
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 250 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
254 if (NULL != handle->timeout_task) 251 if (NULL != handle->timeout_task)
255 { 252 {
256 GNUNET_SCHEDULER_cancel (handle->timeout_task); 253 GNUNET_SCHEDULER_cancel(handle->timeout_task);
257 handle->timeout_task = NULL; 254 handle->timeout_task = NULL;
258 } 255 }
259 if (NULL != handle->record_name) 256 if (NULL != handle->record_name)
260 GNUNET_free (handle->record_name); 257 GNUNET_free(handle->record_name);
261 if (NULL != handle->url) 258 if (NULL != handle->url)
262 GNUNET_free (handle->url); 259 GNUNET_free(handle->url);
263 if (NULL != handle->emsg) 260 if (NULL != handle->emsg)
264 GNUNET_free (handle->emsg); 261 GNUNET_free(handle->emsg);
265 if (NULL != handle->rd) 262 if (NULL != handle->rd)
266 {
267 for (int i = 0; i < handle->rd_count; i++)
268 { 263 {
269 if (NULL != handle->rd[i].data) 264 for (int i = 0; i < handle->rd_count; i++)
270 GNUNET_free ((void *) handle->rd[i].data); 265 {
266 if (NULL != handle->rd[i].data)
267 GNUNET_free((void *)handle->rd[i].data);
268 }
269 GNUNET_free(handle->rd);
271 } 270 }
272 GNUNET_free (handle->rd);
273 }
274 if (NULL != handle->timeout_task) 271 if (NULL != handle->timeout_task)
275 GNUNET_SCHEDULER_cancel (handle->timeout_task); 272 GNUNET_SCHEDULER_cancel(handle->timeout_task);
276 if (NULL != handle->list_it) 273 if (NULL != handle->list_it)
277 GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it); 274 GNUNET_NAMESTORE_zone_iteration_stop(handle->list_it);
278 if (NULL != handle->add_qe) 275 if (NULL != handle->add_qe)
279 GNUNET_NAMESTORE_cancel (handle->add_qe); 276 GNUNET_NAMESTORE_cancel(handle->add_qe);
280 if (NULL != handle->identity_handle) 277 if (NULL != handle->identity_handle)
281 GNUNET_IDENTITY_disconnect (handle->identity_handle); 278 GNUNET_IDENTITY_disconnect(handle->identity_handle);
282 if (NULL != handle->ns_handle) 279 if (NULL != handle->ns_handle)
283 { 280 {
284 GNUNET_NAMESTORE_disconnect (handle->ns_handle); 281 GNUNET_NAMESTORE_disconnect(handle->ns_handle);
285 } 282 }
286 283
287 for (ego_entry = handle->ego_head; NULL != ego_entry;) 284 for (ego_entry = handle->ego_head; NULL != ego_entry;)
288 { 285 {
289 ego_tmp = ego_entry; 286 ego_tmp = ego_entry;
290 ego_entry = ego_entry->next; 287 ego_entry = ego_entry->next;
291 GNUNET_free (ego_tmp->identifier); 288 GNUNET_free(ego_tmp->identifier);
292 GNUNET_free (ego_tmp->keystring); 289 GNUNET_free(ego_tmp->keystring);
293 GNUNET_free (ego_tmp); 290 GNUNET_free(ego_tmp);
294 } 291 }
295 292
296 if (NULL != handle->resp_object) 293 if (NULL != handle->resp_object)
297 { 294 {
298 json_decref (handle->resp_object); 295 json_decref(handle->resp_object);
299 } 296 }
300 297
301 GNUNET_free (handle); 298 GNUNET_free(handle);
302} 299}
303 300
304 301
@@ -308,26 +305,26 @@ cleanup_handle (void *cls)
308 * @param cls the `struct RequestHandle` 305 * @param cls the `struct RequestHandle`
309 */ 306 */
310static void 307static void
311do_error (void *cls) 308do_error(void *cls)
312{ 309{
313 struct RequestHandle *handle = cls; 310 struct RequestHandle *handle = cls;
314 struct MHD_Response *resp; 311 struct MHD_Response *resp;
315 json_t *json_error = json_object (); 312 json_t *json_error = json_object();
316 char *response; 313 char *response;
317 314
318 if (NULL == handle->emsg) 315 if (NULL == handle->emsg)
319 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_ERROR_UNKNOWN); 316 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_ERROR_UNKNOWN);
320 317
321 json_object_set_new (json_error, "error", json_string (handle->emsg)); 318 json_object_set_new(json_error, "error", json_string(handle->emsg));
322 319
323 if (0 == handle->response_code) 320 if (0 == handle->response_code)
324 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; 321 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
325 response = json_dumps (json_error, 0); 322 response = json_dumps(json_error, 0);
326 resp = GNUNET_REST_create_response (response); 323 resp = GNUNET_REST_create_response(response);
327 handle->proc (handle->proc_cls, resp, handle->response_code); 324 handle->proc(handle->proc_cls, resp, handle->response_code);
328 json_decref (json_error); 325 json_decref(json_error);
329 GNUNET_free (response); 326 GNUNET_free(response);
330 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 327 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
331} 328}
332 329
333 330
@@ -341,19 +338,20 @@ do_error (void *cls)
341 * @return EgoEntry or NULL if not found 338 * @return EgoEntry or NULL if not found
342 */ 339 */
343struct EgoEntry * 340struct EgoEntry *
344get_egoentry_namestore (struct RequestHandle *handle, char *name) 341get_egoentry_namestore(struct RequestHandle *handle, char *name)
345{ 342{
346 struct EgoEntry *ego_entry; 343 struct EgoEntry *ego_entry;
344
347 if (NULL != name) 345 if (NULL != name)
348 {
349 for (ego_entry = handle->ego_head; NULL != ego_entry;
350 ego_entry = ego_entry->next)
351 { 346 {
352 if (0 != strcasecmp (name, ego_entry->identifier)) 347 for (ego_entry = handle->ego_head; NULL != ego_entry;
353 continue; 348 ego_entry = ego_entry->next)
354 return ego_entry; 349 {
350 if (0 != strcasecmp(name, ego_entry->identifier))
351 continue;
352 return ego_entry;
353 }
355 } 354 }
356 }
357 return NULL; 355 return NULL;
358} 356}
359 357
@@ -364,11 +362,12 @@ get_egoentry_namestore (struct RequestHandle *handle, char *name)
364 * @param cls the `struct RequestHandle` 362 * @param cls the `struct RequestHandle`
365 */ 363 */
366static void 364static void
367namestore_iteration_error (void *cls) 365namestore_iteration_error(void *cls)
368{ 366{
369 struct RequestHandle *handle = cls; 367 struct RequestHandle *handle = cls;
370 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 368
371 GNUNET_SCHEDULER_add_now (&do_error, handle); 369 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
370 GNUNET_SCHEDULER_add_now(&do_error, handle);
372 return; 371 return;
373} 372}
374 373
@@ -381,27 +380,27 @@ namestore_iteration_error (void *cls)
381 * @param emsg the error message (can be NULL) 380 * @param emsg the error message (can be NULL)
382 */ 381 */
383static void 382static void
384create_finished (void *cls, int32_t success, const char *emsg) 383create_finished(void *cls, int32_t success, const char *emsg)
385{ 384{
386 struct RequestHandle *handle = cls; 385 struct RequestHandle *handle = cls;
387 struct MHD_Response *resp; 386 struct MHD_Response *resp;
388 387
389 handle->add_qe = NULL; 388 handle->add_qe = NULL;
390 if (GNUNET_YES != success) 389 if (GNUNET_YES != success)
391 {
392 if (NULL != emsg)
393 { 390 {
394 handle->emsg = GNUNET_strdup (emsg); 391 if (NULL != emsg)
395 GNUNET_SCHEDULER_add_now (&do_error, handle); 392 {
393 handle->emsg = GNUNET_strdup(emsg);
394 GNUNET_SCHEDULER_add_now(&do_error, handle);
395 return;
396 }
397 handle->emsg = GNUNET_strdup("Error storing records");
398 GNUNET_SCHEDULER_add_now(&do_error, handle);
396 return; 399 return;
397 } 400 }
398 handle->emsg = GNUNET_strdup ("Error storing records"); 401 resp = GNUNET_REST_create_response(NULL);
399 GNUNET_SCHEDULER_add_now (&do_error, handle); 402 handle->proc(handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
400 return; 403 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
401 }
402 resp = GNUNET_REST_create_response (NULL);
403 handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
404 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
405} 404}
406 405
407 406
@@ -413,34 +412,34 @@ create_finished (void *cls, int32_t success, const char *emsg)
413 * @param emsg the error message (can be NULL) 412 * @param emsg the error message (can be NULL)
414 */ 413 */
415static void 414static void
416del_finished (void *cls, int32_t success, const char *emsg) 415del_finished(void *cls, int32_t success, const char *emsg)
417{ 416{
418 struct RequestHandle *handle = cls; 417 struct RequestHandle *handle = cls;
419 418
420 handle->add_qe = NULL; 419 handle->add_qe = NULL;
421 if (GNUNET_NO == success) 420 if (GNUNET_NO == success)
422 { 421 {
423 handle->response_code = MHD_HTTP_NOT_FOUND; 422 handle->response_code = MHD_HTTP_NOT_FOUND;
424 handle->emsg = GNUNET_strdup ("No record found"); 423 handle->emsg = GNUNET_strdup("No record found");
425 GNUNET_SCHEDULER_add_now (&do_error, handle); 424 GNUNET_SCHEDULER_add_now(&do_error, handle);
426 return; 425 return;
427 } 426 }
428 if (GNUNET_SYSERR == success) 427 if (GNUNET_SYSERR == success)
429 {
430 if (NULL != emsg)
431 { 428 {
432 handle->emsg = GNUNET_strdup (emsg); 429 if (NULL != emsg)
433 GNUNET_SCHEDULER_add_now (&do_error, handle); 430 {
431 handle->emsg = GNUNET_strdup(emsg);
432 GNUNET_SCHEDULER_add_now(&do_error, handle);
433 return;
434 }
435 handle->emsg = GNUNET_strdup("Deleting record failed");
436 GNUNET_SCHEDULER_add_now(&do_error, handle);
434 return; 437 return;
435 } 438 }
436 handle->emsg = GNUNET_strdup ("Deleting record failed"); 439 handle->proc(handle->proc_cls,
437 GNUNET_SCHEDULER_add_now (&do_error, handle); 440 GNUNET_REST_create_response(NULL),
438 return; 441 MHD_HTTP_NO_CONTENT);
439 } 442 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
440 handle->proc (handle->proc_cls,
441 GNUNET_REST_create_response (NULL),
442 MHD_HTTP_NO_CONTENT);
443 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
444} 443}
445 444
446 445
@@ -451,7 +450,7 @@ del_finished (void *cls, int32_t success, const char *emsg)
451 * @param cls the `struct RequestHandle` 450 * @param cls the `struct RequestHandle`
452 */ 451 */
453static void 452static void
454namestore_list_finished (void *cls) 453namestore_list_finished(void *cls)
455{ 454{
456 struct RequestHandle *handle = cls; 455 struct RequestHandle *handle = cls;
457 char *result_str; 456 char *result_str;
@@ -460,14 +459,14 @@ namestore_list_finished (void *cls)
460 handle->list_it = NULL; 459 handle->list_it = NULL;
461 460
462 if (NULL == handle->resp_object) 461 if (NULL == handle->resp_object)
463 handle->resp_object = json_array (); 462 handle->resp_object = json_array();
464 463
465 result_str = json_dumps (handle->resp_object, 0); 464 result_str = json_dumps(handle->resp_object, 0);
466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 465 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
467 resp = GNUNET_REST_create_response (result_str); 466 resp = GNUNET_REST_create_response(result_str);
468 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 467 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
469 GNUNET_free_non_null (result_str); 468 GNUNET_free_non_null(result_str);
470 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 469 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
471} 470}
472 471
473 472
@@ -477,22 +476,22 @@ namestore_list_finished (void *cls)
477 * @param handle the RequestHandle 476 * @param handle the RequestHandle
478 */ 477 */
479static void 478static void
480namestore_list_iteration (void *cls, 479namestore_list_iteration(void *cls,
481 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 480 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
482 const char *rname, 481 const char *rname,
483 unsigned int rd_len, 482 unsigned int rd_len,
484 const struct GNUNET_GNSRECORD_Data *rd) 483 const struct GNUNET_GNSRECORD_Data *rd)
485{ 484{
486 struct RequestHandle *handle = cls; 485 struct RequestHandle *handle = cls;
487 json_t *record_obj; 486 json_t *record_obj;
488 487
489 if (NULL == handle->resp_object) 488 if (NULL == handle->resp_object)
490 handle->resp_object = json_array (); 489 handle->resp_object = json_array();
491 record_obj = GNUNET_JSON_from_gnsrecord (rname, 490 record_obj = GNUNET_JSON_from_gnsrecord(rname,
492 rd, 491 rd,
493 rd_len); 492 rd_len);
494 json_array_append_new (handle->resp_object, record_obj); 493 json_array_append_new(handle->resp_object, record_obj);
495 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); 494 GNUNET_NAMESTORE_zone_iterator_next(handle->list_it, 1);
496} 495}
497 496
498 497
@@ -504,9 +503,9 @@ namestore_list_iteration (void *cls,
504 * @param cls the RequestHandle 503 * @param cls the RequestHandle
505 */ 504 */
506void 505void
507namestore_get (struct GNUNET_REST_RequestHandle *con_handle, 506namestore_get(struct GNUNET_REST_RequestHandle *con_handle,
508 const char *url, 507 const char *url,
509 void *cls) 508 void *cls)
510{ 509{
511 struct RequestHandle *handle = cls; 510 struct RequestHandle *handle = cls;
512 struct EgoEntry *ego_entry; 511 struct EgoEntry *ego_entry;
@@ -516,75 +515,77 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
516 ego_entry = NULL; 515 ego_entry = NULL;
517 516
518 // set zone to name if given 517 // set zone to name if given
519 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) 518 if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
520 {
521 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
522 ego_entry = get_egoentry_namestore (handle, egoname);
523
524 if (NULL == ego_entry)
525 { 519 {
526 handle->response_code = MHD_HTTP_NOT_FOUND; 520 egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
527 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); 521 ego_entry = get_egoentry_namestore(handle, egoname);
528 GNUNET_SCHEDULER_add_now (&do_error, handle); 522
529 return; 523 if (NULL == ego_entry)
524 {
525 handle->response_code = MHD_HTTP_NOT_FOUND;
526 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
527 GNUNET_SCHEDULER_add_now(&do_error, handle);
528 return;
529 }
530 } 530 }
531 }
532 if (NULL != ego_entry) 531 if (NULL != ego_entry)
533 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 532 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
534 533
535 handle->list_it = 534 handle->list_it =
536 GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, 535 GNUNET_NAMESTORE_zone_iteration_start(handle->ns_handle,
537 handle->zone_pkey, 536 handle->zone_pkey,
538 &namestore_iteration_error, 537 &namestore_iteration_error,
539 handle, 538 handle,
540 &namestore_list_iteration, 539 &namestore_list_iteration,
541 handle, 540 handle,
542 &namestore_list_finished, 541 &namestore_list_finished,
543 handle); 542 handle);
544 if (NULL == handle->list_it) 543 if (NULL == handle->list_it)
545 { 544 {
546 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 545 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
547 GNUNET_SCHEDULER_add_now (&do_error, handle); 546 GNUNET_SCHEDULER_add_now(&do_error, handle);
548 return; 547 return;
549 } 548 }
550} 549}
551 550
552 551
553static void 552static void
554ns_lookup_error_cb (void *cls) 553ns_lookup_error_cb(void *cls)
555{ 554{
556 struct RequestHandle *handle = cls; 555 struct RequestHandle *handle = cls;
557 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 556
558 GNUNET_SCHEDULER_add_now (&do_error, handle); 557 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
558 GNUNET_SCHEDULER_add_now(&do_error, handle);
559} 559}
560 560
561 561
562static void 562static void
563ns_lookup_cb (void *cls, 563ns_lookup_cb(void *cls,
564 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 564 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
565 const char *label, 565 const char *label,
566 unsigned int rd_count, 566 unsigned int rd_count,
567 const struct GNUNET_GNSRECORD_Data *rd) 567 const struct GNUNET_GNSRECORD_Data *rd)
568{ 568{
569 struct RequestHandle *handle = cls; 569 struct RequestHandle *handle = cls;
570 struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count]; 570 struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count];
571
571 for (int i = 0; i < rd_count; i++) 572 for (int i = 0; i < rd_count; i++)
572 rd_new[i] = rd[i]; 573 rd_new[i] = rd[i];
573 for (int j = 0; j < handle->rd_count; j++) 574 for (int j = 0; j < handle->rd_count; j++)
574 rd_new[rd_count + j] = handle->rd[j]; 575 rd_new[rd_count + j] = handle->rd[j];
575 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, 576 handle->add_qe = GNUNET_NAMESTORE_records_store(handle->ns_handle,
576 handle->zone_pkey, 577 handle->zone_pkey,
577 handle->record_name, 578 handle->record_name,
578 rd_count + handle->rd_count, 579 rd_count + handle->rd_count,
579 rd_new, 580 rd_new,
580 &create_finished, 581 &create_finished,
581 handle); 582 handle);
582 if (NULL == handle->add_qe) 583 if (NULL == handle->add_qe)
583 { 584 {
584 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 585 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
585 GNUNET_SCHEDULER_add_now (&do_error, handle); 586 GNUNET_SCHEDULER_add_now(&do_error, handle);
586 return; 587 return;
587 } 588 }
588} 589}
589 590
590 591
@@ -596,9 +597,9 @@ ns_lookup_cb (void *cls,
596 * @param cls the RequestHandle 597 * @param cls the RequestHandle
597 */ 598 */
598void 599void
599namestore_add (struct GNUNET_REST_RequestHandle *con_handle, 600namestore_add(struct GNUNET_REST_RequestHandle *con_handle,
600 const char *url, 601 const char *url,
601 void *cls) 602 void *cls)
602{ 603{
603 struct RequestHandle *handle = cls; 604 struct RequestHandle *handle = cls;
604 struct EgoEntry *ego_entry; 605 struct EgoEntry *ego_entry;
@@ -609,67 +610,67 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
609 char term_data[handle->rest_handle->data_size + 1]; 610 char term_data[handle->rest_handle->data_size + 1];
610 611
611 if (0 >= handle->rest_handle->data_size) 612 if (0 >= handle->rest_handle->data_size)
612 { 613 {
613 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA); 614 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA);
614 GNUNET_SCHEDULER_add_now (&do_error, handle); 615 GNUNET_SCHEDULER_add_now(&do_error, handle);
615 return; 616 return;
616 } 617 }
617 term_data[handle->rest_handle->data_size] = '\0'; 618 term_data[handle->rest_handle->data_size] = '\0';
618 GNUNET_memcpy (term_data, 619 GNUNET_memcpy(term_data,
619 handle->rest_handle->data, 620 handle->rest_handle->data,
620 handle->rest_handle->data_size); 621 handle->rest_handle->data_size);
621 data_js = json_loads (term_data, JSON_DECODE_ANY, &err); 622 data_js = json_loads(term_data, JSON_DECODE_ANY, &err);
622 struct GNUNET_JSON_Specification gnsspec[] = 623 struct GNUNET_JSON_Specification gnsspec[] =
623 {GNUNET_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count, &handle->record_name), GNUNET_JSON_spec_end ()}; 624 { GNUNET_JSON_spec_gnsrecord(&handle->rd, &handle->rd_count, &handle->record_name), GNUNET_JSON_spec_end() };
624 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) 625 if (GNUNET_OK != GNUNET_JSON_parse(data_js, gnsspec, NULL, NULL))
625 { 626 {
626 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); 627 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
627 GNUNET_SCHEDULER_add_now (&do_error, handle); 628 GNUNET_SCHEDULER_add_now(&do_error, handle);
628 json_decref (data_js); 629 json_decref(data_js);
629 return; 630 return;
630 } 631 }
631 GNUNET_JSON_parse_free (gnsspec); 632 GNUNET_JSON_parse_free(gnsspec);
632 if (0 >= strlen (handle->record_name)) 633 if (0 >= strlen(handle->record_name))
633 { 634 {
634 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); 635 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
635 GNUNET_SCHEDULER_add_now (&do_error, handle); 636 GNUNET_SCHEDULER_add_now(&do_error, handle);
636 json_decref (data_js); 637 json_decref(data_js);
637 return; 638 return;
638 } 639 }
639 json_decref (data_js); 640 json_decref(data_js);
640 641
641 egoname = NULL; 642 egoname = NULL;
642 ego_entry = NULL; 643 ego_entry = NULL;
643 644
644 // set zone to name if given 645 // set zone to name if given
645 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) 646 if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
646 {
647 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
648 ego_entry = get_egoentry_namestore (handle, egoname);
649
650 if (NULL == ego_entry)
651 { 647 {
652 handle->response_code = MHD_HTTP_NOT_FOUND; 648 egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
653 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); 649 ego_entry = get_egoentry_namestore(handle, egoname);
654 GNUNET_SCHEDULER_add_now (&do_error, handle); 650
655 return; 651 if (NULL == ego_entry)
652 {
653 handle->response_code = MHD_HTTP_NOT_FOUND;
654 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
655 GNUNET_SCHEDULER_add_now(&do_error, handle);
656 return;
657 }
656 } 658 }
657 }
658 if (NULL != ego_entry) 659 if (NULL != ego_entry)
659 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 660 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
660 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, 661 handle->add_qe = GNUNET_NAMESTORE_records_lookup(handle->ns_handle,
661 handle->zone_pkey, 662 handle->zone_pkey,
662 handle->record_name, 663 handle->record_name,
663 &ns_lookup_error_cb, 664 &ns_lookup_error_cb,
664 handle, 665 handle,
665 &ns_lookup_cb, 666 &ns_lookup_cb,
666 handle); 667 handle);
667 if (NULL == handle->add_qe) 668 if (NULL == handle->add_qe)
668 { 669 {
669 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 670 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
670 GNUNET_SCHEDULER_add_now (&do_error, handle); 671 GNUNET_SCHEDULER_add_now(&do_error, handle);
671 return; 672 return;
672 } 673 }
673} 674}
674 675
675 676
@@ -681,9 +682,9 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
681 * @param cls the RequestHandle 682 * @param cls the RequestHandle
682 */ 683 */
683void 684void
684namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, 685namestore_delete(struct GNUNET_REST_RequestHandle *con_handle,
685 const char *url, 686 const char *url,
686 void *cls) 687 void *cls)
687{ 688{
688 struct RequestHandle *handle = cls; 689 struct RequestHandle *handle = cls;
689 struct GNUNET_HashCode key; 690 struct GNUNET_HashCode key;
@@ -694,46 +695,46 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
694 ego_entry = NULL; 695 ego_entry = NULL;
695 696
696 // set zone to name if given 697 // set zone to name if given
697 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) 698 if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url))
698 {
699 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
700 ego_entry = get_egoentry_namestore (handle, egoname);
701
702 if (NULL == ego_entry)
703 { 699 {
704 handle->response_code = MHD_HTTP_NOT_FOUND; 700 egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1];
705 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); 701 ego_entry = get_egoentry_namestore(handle, egoname);
706 GNUNET_SCHEDULER_add_now (&do_error, handle); 702
707 return; 703 if (NULL == ego_entry)
704 {
705 handle->response_code = MHD_HTTP_NOT_FOUND;
706 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
707 GNUNET_SCHEDULER_add_now(&do_error, handle);
708 return;
709 }
708 } 710 }
709 }
710 if (NULL != ego_entry) 711 if (NULL != ego_entry)
711 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 712 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
712 713
713 GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key); 714 GNUNET_CRYPTO_hash("record_name", strlen("record_name"), &key);
714 if (GNUNET_NO == 715 if (GNUNET_NO ==
715 GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key)) 716 GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, &key))
716 { 717 {
717 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); 718 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA);
718 GNUNET_SCHEDULER_add_now (&do_error, handle); 719 GNUNET_SCHEDULER_add_now(&do_error, handle);
719 return; 720 return;
720 } 721 }
721 handle->record_name = GNUNET_strdup ( 722 handle->record_name = GNUNET_strdup(
722 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); 723 GNUNET_CONTAINER_multihashmap_get(con_handle->url_param_map, &key));
723 724
724 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, 725 handle->add_qe = GNUNET_NAMESTORE_records_store(handle->ns_handle,
725 handle->zone_pkey, 726 handle->zone_pkey,
726 handle->record_name, 727 handle->record_name,
727 0, 728 0,
728 NULL, 729 NULL,
729 &del_finished, 730 &del_finished,
730 handle); 731 handle);
731 if (NULL == handle->add_qe) 732 if (NULL == handle->add_qe)
732 { 733 {
733 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 734 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED);
734 GNUNET_SCHEDULER_add_now (&do_error, handle); 735 GNUNET_SCHEDULER_add_now(&do_error, handle);
735 return; 736 return;
736 } 737 }
737} 738}
738 739
739 740
@@ -745,18 +746,18 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
745 * @param cls the RequestHandle 746 * @param cls the RequestHandle
746 */ 747 */
747static void 748static void
748options_cont (struct GNUNET_REST_RequestHandle *con_handle, 749options_cont(struct GNUNET_REST_RequestHandle *con_handle,
749 const char *url, 750 const char *url,
750 void *cls) 751 void *cls)
751{ 752{
752 struct MHD_Response *resp; 753 struct MHD_Response *resp;
753 struct RequestHandle *handle = cls; 754 struct RequestHandle *handle = cls;
754 755
755 // independent of path return all options 756 // independent of path return all options
756 resp = GNUNET_REST_create_response (NULL); 757 resp = GNUNET_REST_create_response(NULL);
757 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); 758 MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods);
758 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 759 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
759 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 760 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
760 return; 761 return;
761} 762}
762 763
@@ -767,22 +768,22 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
767 * @param handle the request handle 768 * @param handle the request handle
768 */ 769 */
769static void 770static void
770init_cont (struct RequestHandle *handle) 771init_cont(struct RequestHandle *handle)
771{ 772{
772 struct GNUNET_REST_RequestHandlerError err; 773 struct GNUNET_REST_RequestHandlerError err;
773 static const struct GNUNET_REST_RequestHandler handlers[] = 774 static const struct GNUNET_REST_RequestHandler handlers[] =
774 {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get}, 775 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get },
775 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add}, 776 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add },
776 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete}, 777 { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete },
777 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont}, 778 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont },
778 GNUNET_REST_HANDLER_END}; 779 GNUNET_REST_HANDLER_END };
779 780
780 if (GNUNET_NO == 781 if (GNUNET_NO ==
781 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) 782 GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle))
782 { 783 {
783 handle->response_code = err.error_code; 784 handle->response_code = err.error_code;
784 GNUNET_SCHEDULER_add_now (&do_error, handle); 785 GNUNET_SCHEDULER_add_now(&do_error, handle);
785 } 786 }
786} 787}
787 788
788 789
@@ -818,32 +819,32 @@ init_cont (struct RequestHandle *handle)
818 * must thus no longer be used 819 * must thus no longer be used
819 */ 820 */
820static void 821static void
821id_connect_cb (void *cls, 822id_connect_cb(void *cls,
822 struct GNUNET_IDENTITY_Ego *ego, 823 struct GNUNET_IDENTITY_Ego *ego,
823 void **ctx, 824 void **ctx,
824 const char *name) 825 const char *name)
825{ 826{
826 struct RequestHandle *handle = cls; 827 struct RequestHandle *handle = cls;
827 struct EgoEntry *ego_entry; 828 struct EgoEntry *ego_entry;
828 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 829 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
829 830
830 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 831 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
831 { 832 {
832 handle->state = ID_REST_STATE_POST_INIT; 833 handle->state = ID_REST_STATE_POST_INIT;
833 init_cont (handle); 834 init_cont(handle);
834 return; 835 return;
835 } 836 }
836 if (ID_REST_STATE_INIT == handle->state) 837 if (ID_REST_STATE_INIT == handle->state)
837 { 838 {
838 ego_entry = GNUNET_new (struct EgoEntry); 839 ego_entry = GNUNET_new(struct EgoEntry);
839 GNUNET_IDENTITY_ego_get_public_key (ego, &pk); 840 GNUNET_IDENTITY_ego_get_public_key(ego, &pk);
840 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 841 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk);
841 ego_entry->ego = ego; 842 ego_entry->ego = ego;
842 GNUNET_asprintf (&ego_entry->identifier, "%s", name); 843 GNUNET_asprintf(&ego_entry->identifier, "%s", name);
843 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, 844 GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,
844 handle->ego_tail, 845 handle->ego_tail,
845 ego_entry); 846 ego_entry);
846 } 847 }
847} 848}
848 849
849 850
@@ -859,11 +860,11 @@ id_connect_cb (void *cls,
859 * @return GNUNET_OK if request accepted 860 * @return GNUNET_OK if request accepted
860 */ 861 */
861static void 862static void
862rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 863rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
863 GNUNET_REST_ResultProcessor proc, 864 GNUNET_REST_ResultProcessor proc,
864 void *proc_cls) 865 void *proc_cls)
865{ 866{
866 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 867 struct RequestHandle *handle = GNUNET_new(struct RequestHandle);
867 868
868 handle->response_code = 0; 869 handle->response_code = 0;
869 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 870 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -872,18 +873,18 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
872 handle->rest_handle = rest_handle; 873 handle->rest_handle = rest_handle;
873 handle->zone_pkey = NULL; 874 handle->zone_pkey = NULL;
874 875
875 handle->url = GNUNET_strdup (rest_handle->url); 876 handle->url = GNUNET_strdup(rest_handle->url);
876 if (handle->url[strlen (handle->url) - 1] == '/') 877 if (handle->url[strlen(handle->url) - 1] == '/')
877 handle->url[strlen (handle->url) - 1] = '\0'; 878 handle->url[strlen(handle->url) - 1] = '\0';
878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 879 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
879 880
880 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); 881 handle->ns_handle = GNUNET_NAMESTORE_connect(cfg);
881 handle->identity_handle = 882 handle->identity_handle =
882 GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); 883 GNUNET_IDENTITY_connect(cfg, &id_connect_cb, handle);
883 handle->timeout_task = 884 handle->timeout_task =
884 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); 885 GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_error, handle);
885 886
886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 887 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
887} 888}
888 889
889 890
@@ -894,7 +895,7 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
894 * @return NULL on error, otherwise the plugin context 895 * @return NULL on error, otherwise the plugin context
895 */ 896 */
896void * 897void *
897libgnunet_plugin_rest_namestore_init (void *cls) 898libgnunet_plugin_rest_namestore_init(void *cls)
898{ 899{
899 static struct Plugin plugin; 900 static struct Plugin plugin;
900 struct GNUNET_REST_Plugin *api; 901 struct GNUNET_REST_Plugin *api;
@@ -902,21 +903,21 @@ libgnunet_plugin_rest_namestore_init (void *cls)
902 cfg = cls; 903 cfg = cls;
903 if (NULL != plugin.cfg) 904 if (NULL != plugin.cfg)
904 return NULL; /* can only initialize once! */ 905 return NULL; /* can only initialize once! */
905 memset (&plugin, 0, sizeof (struct Plugin)); 906 memset(&plugin, 0, sizeof(struct Plugin));
906 plugin.cfg = cfg; 907 plugin.cfg = cfg;
907 api = GNUNET_new (struct GNUNET_REST_Plugin); 908 api = GNUNET_new(struct GNUNET_REST_Plugin);
908 api->cls = &plugin; 909 api->cls = &plugin;
909 api->name = GNUNET_REST_API_NS_NAMESTORE; 910 api->name = GNUNET_REST_API_NS_NAMESTORE;
910 api->process_request = &rest_process_request; 911 api->process_request = &rest_process_request;
911 GNUNET_asprintf (&allow_methods, 912 GNUNET_asprintf(&allow_methods,
912 "%s, %s, %s, %s, %s", 913 "%s, %s, %s, %s, %s",
913 MHD_HTTP_METHOD_GET, 914 MHD_HTTP_METHOD_GET,
914 MHD_HTTP_METHOD_POST, 915 MHD_HTTP_METHOD_POST,
915 MHD_HTTP_METHOD_PUT, 916 MHD_HTTP_METHOD_PUT,
916 MHD_HTTP_METHOD_DELETE, 917 MHD_HTTP_METHOD_DELETE,
917 MHD_HTTP_METHOD_OPTIONS); 918 MHD_HTTP_METHOD_OPTIONS);
918 919
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n")); 920 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Namestore REST API initialized\n"));
920 return api; 921 return api;
921} 922}
922 923
@@ -928,15 +929,16 @@ libgnunet_plugin_rest_namestore_init (void *cls)
928 * @return always NULL 929 * @return always NULL
929 */ 930 */
930void * 931void *
931libgnunet_plugin_rest_namestore_done (void *cls) 932libgnunet_plugin_rest_namestore_done(void *cls)
932{ 933{
933 struct GNUNET_REST_Plugin *api = cls; 934 struct GNUNET_REST_Plugin *api = cls;
934 struct Plugin *plugin = api->cls; 935 struct Plugin *plugin = api->cls;
936
935 plugin->cfg = NULL; 937 plugin->cfg = NULL;
936 938
937 GNUNET_free_non_null (allow_methods); 939 GNUNET_free_non_null(allow_methods);
938 GNUNET_free (api); 940 GNUNET_free(api);
939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n"); 941 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n");
940 return NULL; 942 return NULL;
941} 943}
942 944
diff --git a/src/namestore/test_common.c b/src/namestore/test_common.c
index 6d9761701..d88d1feb9 100644
--- a/src/namestore/test_common.c
+++ b/src/namestore/test_common.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_common.c 21 * @file namestore/test_common.c
22 * @brief common functions for testcase setup 22 * @brief common functions for testcase setup
@@ -26,36 +26,36 @@
26 * test if we can load the plugin @a name. 26 * test if we can load the plugin @a name.
27 */ 27 */
28static int 28static int
29TNC_test_plugin (const char *cfg_name) 29TNC_test_plugin(const char *cfg_name)
30{ 30{
31 char *database; 31 char *database;
32 char *db_lib_name; 32 char *db_lib_name;
33 struct GNUNET_NAMESTORE_PluginFunctions *db; 33 struct GNUNET_NAMESTORE_PluginFunctions *db;
34 struct GNUNET_CONFIGURATION_Handle *cfg; 34 struct GNUNET_CONFIGURATION_Handle *cfg;
35 35
36 cfg = GNUNET_CONFIGURATION_create (); 36 cfg = GNUNET_CONFIGURATION_create();
37 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_name)) 37 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfg_name))
38 { 38 {
39 GNUNET_break (0); 39 GNUNET_break(0);
40 GNUNET_CONFIGURATION_destroy (cfg); 40 GNUNET_CONFIGURATION_destroy(cfg);
41 return GNUNET_SYSERR; 41 return GNUNET_SYSERR;
42 } 42 }
43 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 43 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg,
44 "namestore", 44 "namestore",
45 "database", 45 "database",
46 &database)) 46 &database))
47 { 47 {
48 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); 48 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
49 GNUNET_CONFIGURATION_destroy (cfg); 49 GNUNET_CONFIGURATION_destroy(cfg);
50 return GNUNET_SYSERR; 50 return GNUNET_SYSERR;
51 } 51 }
52 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); 52 GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_namestore_%s", database);
53 GNUNET_free (database); 53 GNUNET_free(database);
54 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); 54 db = GNUNET_PLUGIN_load(db_lib_name, (void *)cfg);
55 if (NULL != db) 55 if (NULL != db)
56 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); 56 GNUNET_break(NULL == GNUNET_PLUGIN_unload(db_lib_name, db));
57 GNUNET_free (db_lib_name); 57 GNUNET_free(db_lib_name);
58 GNUNET_CONFIGURATION_destroy (cfg); 58 GNUNET_CONFIGURATION_destroy(cfg);
59 if (NULL == db) 59 if (NULL == db)
60 return GNUNET_NO; 60 return GNUNET_NO;
61 return GNUNET_YES; 61 return GNUNET_YES;
@@ -68,13 +68,13 @@ TNC_test_plugin (const char *cfg_name)
68 */ 68 */
69#define SETUP_CFG(plugin_name, cfg_name) \ 69#define SETUP_CFG(plugin_name, cfg_name) \
70 do \ 70 do \
71 { \ 71 { \
72 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \ 72 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); \
73 GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \ 73 GNUNET_asprintf(&cfg_name, "test_namestore_api_%s.conf", plugin_name); \
74 if (! TNC_test_plugin (cfg_name)) \ 74 if (!TNC_test_plugin(cfg_name)) \
75 { \ 75 { \
76 GNUNET_free (cfg_name); \ 76 GNUNET_free(cfg_name); \
77 return 77; \ 77 return 77; \
78 } \ 78 } \
79 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TEST_HOME"); \ 79 GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TEST_HOME"); \
80 } while (0) 80 } while (0)
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c
index 392a2521d..130f9bc1e 100644
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ b/src/namestore/test_namestore_api_lookup_nick.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_lookup_nick.c 21 * @file namestore/test_namestore_api_lookup_nick.c
22 * @brief testcase for namestore_api.c: NICK records 22 * @brief testcase for namestore_api.c: NICK records
@@ -34,7 +34,7 @@
34 34
35#define TEST_RECORD_DATA 'a' 35#define TEST_RECORD_DATA 'a'
36 36
37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 37#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
38 38
39static struct GNUNET_NAMESTORE_Handle *nsh; 39static struct GNUNET_NAMESTORE_Handle *nsh;
40 40
@@ -55,20 +55,20 @@ static const char * name = "d";
55 55
56 56
57static void 57static void
58cleanup () 58cleanup()
59{ 59{
60 GNUNET_free_non_null ((void *)rd_orig.data); 60 GNUNET_free_non_null((void *)rd_orig.data);
61 if (NULL != nsh) 61 if (NULL != nsh)
62 { 62 {
63 GNUNET_NAMESTORE_disconnect (nsh); 63 GNUNET_NAMESTORE_disconnect(nsh);
64 nsh = NULL; 64 nsh = NULL;
65 } 65 }
66 if (NULL != privkey) 66 if (NULL != privkey)
67 { 67 {
68 GNUNET_free (privkey); 68 GNUNET_free(privkey);
69 privkey = NULL; 69 privkey = NULL;
70 } 70 }
71 GNUNET_SCHEDULER_shutdown (); 71 GNUNET_SCHEDULER_shutdown();
72} 72}
73 73
74 74
@@ -79,32 +79,32 @@ cleanup ()
79 * @param tc scheduler context 79 * @param tc scheduler context
80 */ 80 */
81static void 81static void
82endbadly (void *cls) 82endbadly(void *cls)
83{ 83{
84 if (NULL != nsqe) 84 if (NULL != nsqe)
85 { 85 {
86 GNUNET_NAMESTORE_cancel (nsqe); 86 GNUNET_NAMESTORE_cancel(nsqe);
87 nsqe = NULL; 87 nsqe = NULL;
88 } 88 }
89 cleanup (); 89 cleanup();
90 res = 1; 90 res = 1;
91} 91}
92 92
93 93
94static void 94static void
95end (void *cls) 95end(void *cls)
96{ 96{
97 cleanup (); 97 cleanup();
98 res = 0; 98 res = 0;
99} 99}
100 100
101 101
102static void 102static void
103lookup_it (void *cls, 103lookup_it(void *cls,
104 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 104 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
105 const char *label, 105 const char *label,
106 unsigned int rd_count, 106 unsigned int rd_count,
107 const struct GNUNET_GNSRECORD_Data *rd) 107 const struct GNUNET_GNSRECORD_Data *rd)
108{ 108{
109 nsqe = NULL; 109 nsqe = NULL;
110 int c; 110 int c;
@@ -112,222 +112,221 @@ lookup_it (void *cls,
112 int found_nick = GNUNET_NO; 112 int found_nick = GNUNET_NO;
113 113
114 if (0 != GNUNET_memcmp(privkey, zone)) 114 if (0 != GNUNET_memcmp(privkey, zone))
115 { 115 {
116 GNUNET_break(0); 116 GNUNET_break(0);
117 GNUNET_SCHEDULER_cancel (endbadly_task); 117 GNUNET_SCHEDULER_cancel(endbadly_task);
118 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 118 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
119 return; 119 return;
120 } 120 }
121 121
122 if (NULL == label) 122 if (NULL == label)
123 { 123 {
124 GNUNET_break(0); 124 GNUNET_break(0);
125 GNUNET_SCHEDULER_cancel (endbadly_task); 125 GNUNET_SCHEDULER_cancel(endbadly_task);
126 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 126 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
127 return; 127 return;
128 } 128 }
129
130 if (0 != strcmp (label, name))
131 {
132 GNUNET_break(0);
133 GNUNET_SCHEDULER_cancel (endbadly_task);
134 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
135 return;
136 }
137
138 if (2 != rd_count)
139 {
140 GNUNET_break(0);
141 GNUNET_SCHEDULER_cancel (endbadly_task);
142 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
143 return;
144 }
145 129
146 for (c = 0; c < rd_count; c++) 130 if (0 != strcmp(label, name))
147 {
148 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
149 { 131 {
150 if (rd[c].data_size != strlen(TEST_NICK)+1) 132 GNUNET_break(0);
151 { 133 GNUNET_SCHEDULER_cancel(endbadly_task);
152 GNUNET_break(0); 134 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
153 GNUNET_SCHEDULER_cancel (endbadly_task); 135 return;
154 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
155 return;
156 }
157 if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_PRIVATE))
158 {
159 GNUNET_break(0);
160 GNUNET_SCHEDULER_cancel (endbadly_task);
161 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
162 return;
163 }
164 if (0 != strcmp(rd[c].data, TEST_NICK))
165 {
166 GNUNET_SCHEDULER_cancel (endbadly_task);
167 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
168 return;
169 }
170 found_nick = GNUNET_YES;
171 } 136 }
172 else 137
138 if (2 != rd_count)
173 { 139 {
174 if (rd[c].record_type != TEST_RECORD_TYPE) 140 GNUNET_break(0);
175 { 141 GNUNET_SCHEDULER_cancel(endbadly_task);
176 GNUNET_break(0); 142 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
177 GNUNET_SCHEDULER_cancel (endbadly_task); 143 return;
178 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
179 return;
180 }
181 if (rd[c].data_size != TEST_RECORD_DATALEN)
182 {
183 GNUNET_break(0);
184 GNUNET_SCHEDULER_cancel (endbadly_task);
185 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
186 return;
187 }
188 if (0 != memcmp (rd[c].data, rd_orig.data, TEST_RECORD_DATALEN))
189 {
190 GNUNET_break(0);
191 GNUNET_SCHEDULER_cancel (endbadly_task);
192 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
193 return;
194 }
195 if (rd[c].flags != rd->flags)
196 {
197 GNUNET_break(0);
198 GNUNET_SCHEDULER_cancel (endbadly_task);
199 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
200 return;
201 }
202 found_record = GNUNET_YES;
203 } 144 }
204 145
205 } 146 for (c = 0; c < rd_count; c++)
147 {
148 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
149 {
150 if (rd[c].data_size != strlen(TEST_NICK) + 1)
151 {
152 GNUNET_break(0);
153 GNUNET_SCHEDULER_cancel(endbadly_task);
154 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
155 return;
156 }
157 if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_PRIVATE))
158 {
159 GNUNET_break(0);
160 GNUNET_SCHEDULER_cancel(endbadly_task);
161 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
162 return;
163 }
164 if (0 != strcmp(rd[c].data, TEST_NICK))
165 {
166 GNUNET_SCHEDULER_cancel(endbadly_task);
167 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
168 return;
169 }
170 found_nick = GNUNET_YES;
171 }
172 else
173 {
174 if (rd[c].record_type != TEST_RECORD_TYPE)
175 {
176 GNUNET_break(0);
177 GNUNET_SCHEDULER_cancel(endbadly_task);
178 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
179 return;
180 }
181 if (rd[c].data_size != TEST_RECORD_DATALEN)
182 {
183 GNUNET_break(0);
184 GNUNET_SCHEDULER_cancel(endbadly_task);
185 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
186 return;
187 }
188 if (0 != memcmp(rd[c].data, rd_orig.data, TEST_RECORD_DATALEN))
189 {
190 GNUNET_break(0);
191 GNUNET_SCHEDULER_cancel(endbadly_task);
192 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
193 return;
194 }
195 if (rd[c].flags != rd->flags)
196 {
197 GNUNET_break(0);
198 GNUNET_SCHEDULER_cancel(endbadly_task);
199 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
200 return;
201 }
202 found_record = GNUNET_YES;
203 }
204 }
206 205
207 /* Done */ 206 /* Done */
208 if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record)) 207 if ((GNUNET_YES == found_nick) && (GNUNET_YES == found_record))
209 { 208 {
210 GNUNET_SCHEDULER_cancel (endbadly_task); 209 GNUNET_SCHEDULER_cancel(endbadly_task);
211 endbadly_task = NULL; 210 endbadly_task = NULL;
212 GNUNET_SCHEDULER_add_now (&end, NULL ); 211 GNUNET_SCHEDULER_add_now(&end, NULL);
213 } 212 }
214 else 213 else
215 { 214 {
216 GNUNET_break (0); 215 GNUNET_break(0);
217 GNUNET_SCHEDULER_cancel (endbadly_task); 216 GNUNET_SCHEDULER_cancel(endbadly_task);
218 endbadly_task = NULL; 217 endbadly_task = NULL;
219 GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 218 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
220 } 219 }
221} 220}
222 221
223 222
224static void 223static void
225fail_cb (void *cls) 224fail_cb(void *cls)
226{ 225{
227 GNUNET_assert (0); 226 GNUNET_assert(0);
228} 227}
229 228
230 229
231static void 230static void
232put_cont (void *cls, int32_t success, const char *emsg) 231put_cont(void *cls, int32_t success, const char *emsg)
233{ 232{
234 const char *name = cls; 233 const char *name = cls;
235 234
236 nsqe = NULL; 235 nsqe = NULL;
237 GNUNET_assert (NULL != cls); 236 GNUNET_assert(NULL != cls);
238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 237 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
239 "Name store added record for `%s': %s\n", 238 "Name store added record for `%s': %s\n",
240 name, 239 name,
241 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 240 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
242 241
243 if (GNUNET_OK != success) 242 if (GNUNET_OK != success)
244 { 243 {
245 GNUNET_SCHEDULER_cancel (endbadly_task); 244 GNUNET_SCHEDULER_cancel(endbadly_task);
246 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 245 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
247 return; 246 return;
248 } 247 }
249 /* Lookup */ 248 /* Lookup */
250 nsqe = GNUNET_NAMESTORE_records_lookup (nsh, 249 nsqe = GNUNET_NAMESTORE_records_lookup(nsh,
251 privkey, 250 privkey,
252 name, 251 name,
253 &fail_cb, 252 &fail_cb,
254 NULL, 253 NULL,
255 &lookup_it, 254 &lookup_it,
256 NULL); 255 NULL);
257} 256}
258 257
259 258
260static void 259static void
261nick_cont (void *cls, int32_t success, const char *emsg) 260nick_cont(void *cls, int32_t success, const char *emsg)
262{ 261{
263 const char *name = cls; 262 const char *name = cls;
264 263
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 264 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
266 "Nick added : %s\n", 265 "Nick added : %s\n",
267 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 266 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
268 267
269 rd_orig.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 268 rd_orig.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
270 rd_orig.record_type = TEST_RECORD_TYPE; 269 rd_orig.record_type = TEST_RECORD_TYPE;
271 rd_orig.data_size = TEST_RECORD_DATALEN; 270 rd_orig.data_size = TEST_RECORD_DATALEN;
272 rd_orig.data = GNUNET_malloc (TEST_RECORD_DATALEN); 271 rd_orig.data = GNUNET_malloc(TEST_RECORD_DATALEN);
273 rd_orig.flags = 0; 272 rd_orig.flags = 0;
274 memset ((char *) rd_orig.data, 'a', TEST_RECORD_DATALEN); 273 memset((char *)rd_orig.data, 'a', TEST_RECORD_DATALEN);
275 274
276 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 275 nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, name,
277 1, &rd_orig, &put_cont, (void *) name); 276 1, &rd_orig, &put_cont, (void *)name);
278} 277}
279 278
280 279
281static void 280static void
282run (void *cls, 281run(void *cls,
283 const struct GNUNET_CONFIGURATION_Handle *cfg, 282 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 struct GNUNET_TESTING_Peer *peer) 283 struct GNUNET_TESTING_Peer *peer)
285{ 284{
286 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 285 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
287 &endbadly, 286 &endbadly,
288 NULL); 287 NULL);
289 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 288 privkey = GNUNET_CRYPTO_ecdsa_key_create();
290 GNUNET_assert (privkey != NULL); 289 GNUNET_assert(privkey != NULL);
291 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 290 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
292 &pubkey); 291 &pubkey);
293 292
294 nsh = GNUNET_NAMESTORE_connect (cfg); 293 nsh = GNUNET_NAMESTORE_connect(cfg);
295 GNUNET_break (NULL != nsh); 294 GNUNET_break(NULL != nsh);
296 295
297 nsqe = GNUNET_NAMESTORE_set_nick (nsh, 296 nsqe = GNUNET_NAMESTORE_set_nick(nsh,
298 privkey, 297 privkey,
299 TEST_NICK, 298 TEST_NICK,
300 &nick_cont, 299 &nick_cont,
301 (void *) name); 300 (void *)name);
302 if (NULL == nsqe) 301 if (NULL == nsqe)
303 { 302 {
304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 303 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
305 _("Namestore cannot store no block\n")); 304 _("Namestore cannot store no block\n"));
306 } 305 }
307} 306}
308 307
309#include "test_common.c" 308#include "test_common.c"
310 309
311 310
312int 311int
313main (int argc, char *argv[]) 312main(int argc, char *argv[])
314{ 313{
315 const char *plugin_name; 314 const char *plugin_name;
316 char *cfg_name; 315 char *cfg_name;
317 316
318 SETUP_CFG (plugin_name, cfg_name); 317 SETUP_CFG(plugin_name, cfg_name);
319 res = 1; 318 res = 1;
320 if (0 != 319 if (0 !=
321 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", 320 GNUNET_TESTING_peer_run("test-namestore-api-lookup-nick",
322 cfg_name, 321 cfg_name,
323 &run, 322 &run,
324 NULL)) 323 NULL))
325 { 324 {
326 res = 1; 325 res = 1;
327 } 326 }
328 GNUNET_DISK_purge_cfg_dir (cfg_name, 327 GNUNET_DISK_purge_cfg_dir(cfg_name,
329 "GNUNET_TEST_HOME"); 328 "GNUNET_TEST_HOME");
330 GNUNET_free (cfg_name); 329 GNUNET_free(cfg_name);
331 return res; 330 return res;
332} 331}
333 332
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
index cf9bfc20c..a387720a0 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_store.c 21 * @file namestore/test_namestore_api_store.c
22 * @brief testcase for namestore_api.c: store a record 22 * @brief testcase for namestore_api.c: store a record
@@ -32,7 +32,7 @@
32 32
33#define TEST_RECORD_DATA 'a' 33#define TEST_RECORD_DATA 'a'
34 34
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
36 36
37static struct GNUNET_NAMESTORE_Handle *nsh; 37static struct GNUNET_NAMESTORE_Handle *nsh;
38 38
@@ -51,19 +51,19 @@ static const char * name = "d";
51 51
52 52
53static void 53static void
54cleanup () 54cleanup()
55{ 55{
56 if (NULL != nsh) 56 if (NULL != nsh)
57 { 57 {
58 GNUNET_NAMESTORE_disconnect (nsh); 58 GNUNET_NAMESTORE_disconnect(nsh);
59 nsh = NULL; 59 nsh = NULL;
60 } 60 }
61 if (NULL != privkey) 61 if (NULL != privkey)
62 { 62 {
63 GNUNET_free (privkey); 63 GNUNET_free(privkey);
64 privkey = NULL; 64 privkey = NULL;
65 } 65 }
66 GNUNET_SCHEDULER_shutdown (); 66 GNUNET_SCHEDULER_shutdown();
67} 67}
68 68
69 69
@@ -73,152 +73,152 @@ cleanup ()
73 * @param cls handle to use to re-connect. 73 * @param cls handle to use to re-connect.
74 */ 74 */
75static void 75static void
76endbadly (void *cls) 76endbadly(void *cls)
77{ 77{
78 endbadly_task = NULL; 78 endbadly_task = NULL;
79 if (NULL != nsqe) 79 if (NULL != nsqe)
80 { 80 {
81 GNUNET_NAMESTORE_cancel (nsqe); 81 GNUNET_NAMESTORE_cancel(nsqe);
82 nsqe = NULL; 82 nsqe = NULL;
83 } 83 }
84 cleanup (); 84 cleanup();
85 res = 1; 85 res = 1;
86} 86}
87 87
88 88
89static void 89static void
90end (void *cls) 90end(void *cls)
91{ 91{
92 cleanup (); 92 cleanup();
93 res = 0; 93 res = 0;
94} 94}
95 95
96 96
97static void 97static void
98lookup_it (void *cls, 98lookup_it(void *cls,
99 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 99 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
100 const char *label, 100 const char *label,
101 unsigned int rd_count, 101 unsigned int rd_count,
102 const struct GNUNET_GNSRECORD_Data *rd) 102 const struct GNUNET_GNSRECORD_Data *rd)
103{ 103{
104 nsqe = NULL; 104 nsqe = NULL;
105 105
106 if (0 != GNUNET_memcmp (privkey, 106 if (0 != GNUNET_memcmp(privkey,
107 zone)) 107 zone))
108 { 108 {
109 GNUNET_break(0); 109 GNUNET_break(0);
110 GNUNET_SCHEDULER_cancel (endbadly_task); 110 GNUNET_SCHEDULER_cancel(endbadly_task);
111 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 111 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
112 return; 112 return;
113 } 113 }
114 114
115 115
116 if (NULL == label) 116 if (NULL == label)
117 { 117 {
118 GNUNET_break(0); 118 GNUNET_break(0);
119 GNUNET_SCHEDULER_cancel (endbadly_task); 119 GNUNET_SCHEDULER_cancel(endbadly_task);
120 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 120 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
121 return; 121 return;
122 } 122 }
123 123
124 if (0 != strcmp (label, name)) 124 if (0 != strcmp(label, name))
125 { 125 {
126 GNUNET_break(0); 126 GNUNET_break(0);
127 GNUNET_SCHEDULER_cancel (endbadly_task); 127 GNUNET_SCHEDULER_cancel(endbadly_task);
128 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 128 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
129 return; 129 return;
130 } 130 }
131 131
132 if (1 != rd_count) 132 if (1 != rd_count)
133 { 133 {
134 GNUNET_break(0); 134 GNUNET_break(0);
135 GNUNET_SCHEDULER_cancel (endbadly_task); 135 GNUNET_SCHEDULER_cancel(endbadly_task);
136 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 136 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
137 return; 137 return;
138 } 138 }
139 139
140 /* Done */ 140 /* Done */
141 GNUNET_SCHEDULER_cancel (endbadly_task); 141 GNUNET_SCHEDULER_cancel(endbadly_task);
142 endbadly_task = NULL; 142 endbadly_task = NULL;
143 GNUNET_SCHEDULER_add_now (&end, NULL); 143 GNUNET_SCHEDULER_add_now(&end, NULL);
144} 144}
145 145
146 146
147static void 147static void
148fail_cb (void *cls) 148fail_cb(void *cls)
149{ 149{
150 GNUNET_assert (0); 150 GNUNET_assert(0);
151} 151}
152 152
153 153
154static void 154static void
155put_cont (void *cls, 155put_cont(void *cls,
156 int32_t success, 156 int32_t success,
157 const char *emsg) 157 const char *emsg)
158{ 158{
159 const char *name = cls; 159 const char *name = cls;
160 160
161 nsqe = NULL; 161 nsqe = NULL;
162 GNUNET_assert (NULL != cls); 162 GNUNET_assert(NULL != cls);
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 163 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
164 "Name store added record for `%s': %s\n", 164 "Name store added record for `%s': %s\n",
165 name, 165 name,
166 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 166 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
167 167
168 if (GNUNET_OK != success) 168 if (GNUNET_OK != success)
169 { 169 {
170 GNUNET_SCHEDULER_cancel (endbadly_task); 170 GNUNET_SCHEDULER_cancel(endbadly_task);
171 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 171 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
172 return; 172 return;
173 } 173 }
174 /* Lookup */ 174 /* Lookup */
175 nsqe = GNUNET_NAMESTORE_records_lookup (nsh, 175 nsqe = GNUNET_NAMESTORE_records_lookup(nsh,
176 privkey, 176 privkey,
177 name, 177 name,
178 &fail_cb, 178 &fail_cb,
179 NULL, 179 NULL,
180 &lookup_it, 180 &lookup_it,
181 NULL); 181 NULL);
182} 182}
183 183
184 184
185static void 185static void
186run (void *cls, 186run(void *cls,
187 const struct GNUNET_CONFIGURATION_Handle *cfg, 187 const struct GNUNET_CONFIGURATION_Handle *cfg,
188 struct GNUNET_TESTING_Peer *peer) 188 struct GNUNET_TESTING_Peer *peer)
189{ 189{
190 struct GNUNET_GNSRECORD_Data rd; 190 struct GNUNET_GNSRECORD_Data rd;
191 191
192 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 192 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
193 &endbadly, 193 &endbadly,
194 NULL); 194 NULL);
195 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 195 privkey = GNUNET_CRYPTO_ecdsa_key_create();
196 GNUNET_assert (privkey != NULL); 196 GNUNET_assert(privkey != NULL);
197 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 197 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
198 198
199 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 199 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
200 rd.record_type = TEST_RECORD_TYPE; 200 rd.record_type = TEST_RECORD_TYPE;
201 rd.data_size = TEST_RECORD_DATALEN; 201 rd.data_size = TEST_RECORD_DATALEN;
202 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 202 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
203 rd.flags = 0; 203 rd.flags = 0;
204 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 204 memset((char *)rd.data, 'a', TEST_RECORD_DATALEN);
205 205
206 nsh = GNUNET_NAMESTORE_connect (cfg); 206 nsh = GNUNET_NAMESTORE_connect(cfg);
207 GNUNET_break (NULL != nsh); 207 GNUNET_break(NULL != nsh);
208 nsqe = GNUNET_NAMESTORE_records_store (nsh, 208 nsqe = GNUNET_NAMESTORE_records_store(nsh,
209 privkey, 209 privkey,
210 name, 210 name,
211 1, 211 1,
212 &rd, 212 &rd,
213 &put_cont, 213 &put_cont,
214 (void *) name); 214 (void *)name);
215 if (NULL == nsqe) 215 if (NULL == nsqe)
216 { 216 {
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 217 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
218 _("Namestore cannot store no block\n")); 218 _("Namestore cannot store no block\n"));
219 } 219 }
220 220
221 GNUNET_free ((void *)rd.data); 221 GNUNET_free((void *)rd.data);
222} 222}
223 223
224 224
@@ -226,7 +226,7 @@ run (void *cls,
226 226
227 227
228int 228int
229main (int argc, char *argv[]) 229main(int argc, char *argv[])
230{ 230{
231 const char *plugin_name; 231 const char *plugin_name;
232 char *cfg_name; 232 char *cfg_name;
@@ -234,16 +234,16 @@ main (int argc, char *argv[])
234 SETUP_CFG(plugin_name, cfg_name); 234 SETUP_CFG(plugin_name, cfg_name);
235 res = 1; 235 res = 1;
236 if (0 != 236 if (0 !=
237 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", 237 GNUNET_TESTING_peer_run("test-namestore-api-lookup-private",
238 cfg_name, 238 cfg_name,
239 &run, 239 &run,
240 NULL)) 240 NULL))
241 { 241 {
242 res = 1; 242 res = 1;
243 } 243 }
244 GNUNET_DISK_purge_cfg_dir (cfg_name, 244 GNUNET_DISK_purge_cfg_dir(cfg_name,
245 "GNUNET_TEST_HOME"); 245 "GNUNET_TEST_HOME");
246 GNUNET_free (cfg_name); 246 GNUNET_free(cfg_name);
247 return res; 247 return res;
248} 248}
249 249
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c
index 460be0a18..01f07eb39 100644
--- a/src/namestore/test_namestore_api_lookup_public.c
+++ b/src/namestore/test_namestore_api_lookup_public.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api.c 21 * @file namestore/test_namestore_api.c
22 * @brief testcase for namestore_api.c: store a record and perform a lookup 22 * @brief testcase for namestore_api.c: store a record and perform a lookup
@@ -33,7 +33,7 @@
33 33
34#define TEST_RECORD_DATA 'a' 34#define TEST_RECORD_DATA 'a'
35 35
36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 36#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
37 37
38 38
39static struct GNUNET_NAMESTORE_Handle *nsh; 39static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -54,24 +54,24 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
54 54
55 55
56static void 56static void
57cleanup () 57cleanup()
58{ 58{
59 if (NULL != nsh) 59 if (NULL != nsh)
60 { 60 {
61 GNUNET_NAMESTORE_disconnect (nsh); 61 GNUNET_NAMESTORE_disconnect(nsh);
62 nsh = NULL; 62 nsh = NULL;
63 } 63 }
64 if (NULL != nch) 64 if (NULL != nch)
65 { 65 {
66 GNUNET_NAMECACHE_disconnect (nch); 66 GNUNET_NAMECACHE_disconnect(nch);
67 nch = NULL; 67 nch = NULL;
68 } 68 }
69 if (NULL != privkey) 69 if (NULL != privkey)
70 { 70 {
71 GNUNET_free (privkey); 71 GNUNET_free(privkey);
72 privkey = NULL; 72 privkey = NULL;
73 } 73 }
74 GNUNET_SCHEDULER_shutdown (); 74 GNUNET_SCHEDULER_shutdown();
75} 75}
76 76
77 77
@@ -81,145 +81,145 @@ cleanup ()
81 * @param cls handle to use to re-connect. 81 * @param cls handle to use to re-connect.
82 */ 82 */
83static void 83static void
84endbadly (void *cls) 84endbadly(void *cls)
85{ 85{
86 if (NULL != nsqe) 86 if (NULL != nsqe)
87 { 87 {
88 GNUNET_NAMESTORE_cancel (nsqe); 88 GNUNET_NAMESTORE_cancel(nsqe);
89 nsqe = NULL; 89 nsqe = NULL;
90 } 90 }
91 if (NULL != ncqe) 91 if (NULL != ncqe)
92 { 92 {
93 GNUNET_NAMECACHE_cancel (ncqe); 93 GNUNET_NAMECACHE_cancel(ncqe);
94 ncqe = NULL; 94 ncqe = NULL;
95 } 95 }
96 cleanup (); 96 cleanup();
97 res = 1; 97 res = 1;
98} 98}
99 99
100 100
101static void 101static void
102end (void *cls) 102end(void *cls)
103{ 103{
104 cleanup (); 104 cleanup();
105 res = 0; 105 res = 0;
106} 106}
107 107
108 108
109static void 109static void
110rd_decrypt_cb (void *cls, 110rd_decrypt_cb(void *cls,
111 unsigned int rd_count, 111 unsigned int rd_count,
112 const struct GNUNET_GNSRECORD_Data *rd) 112 const struct GNUNET_GNSRECORD_Data *rd)
113{ 113{
114 char rd_cmp_data[TEST_RECORD_DATALEN]; 114 char rd_cmp_data[TEST_RECORD_DATALEN];
115 115
116 GNUNET_assert (1 == rd_count); 116 GNUNET_assert(1 == rd_count);
117 GNUNET_assert (NULL != rd); 117 GNUNET_assert(NULL != rd);
118 118
119 memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); 119 memset(rd_cmp_data, 'a', TEST_RECORD_DATALEN);
120 120
121 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 121 GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type);
122 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); 122 GNUNET_assert(TEST_RECORD_DATALEN == rd[0].data_size);
123 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); 123 GNUNET_assert(0 == memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN));
124 124
125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
126 "Block was decrypted successfully \n"); 126 "Block was decrypted successfully \n");
127 127
128 GNUNET_SCHEDULER_add_now (&end, NULL); 128 GNUNET_SCHEDULER_add_now(&end, NULL);
129} 129}
130 130
131 131
132static void 132static void
133name_lookup_proc (void *cls, 133name_lookup_proc(void *cls,
134 const struct GNUNET_GNSRECORD_Block *block) 134 const struct GNUNET_GNSRECORD_Block *block)
135{ 135{
136 const char *name = cls; 136 const char *name = cls;
137 137
138 ncqe = NULL; 138 ncqe = NULL;
139 GNUNET_assert (NULL != cls); 139 GNUNET_assert(NULL != cls);
140 140
141 if (endbadly_task != NULL) 141 if (endbadly_task != NULL)
142 { 142 {
143 GNUNET_SCHEDULER_cancel (endbadly_task); 143 GNUNET_SCHEDULER_cancel(endbadly_task);
144 endbadly_task = NULL; 144 endbadly_task = NULL;
145 } 145 }
146 146
147 if (NULL == block) 147 if (NULL == block)
148 { 148 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 149 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
150 _("Namestore returned no block\n")); 150 _("Namestore returned no block\n"));
151 if (endbadly_task != NULL) 151 if (endbadly_task != NULL)
152 GNUNET_SCHEDULER_cancel (endbadly_task); 152 GNUNET_SCHEDULER_cancel(endbadly_task);
153 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 153 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
154 return; 154 return;
155 } 155 }
156 156
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
158 "Namestore returned block, decrypting \n"); 158 "Namestore returned block, decrypting \n");
159 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, 159 GNUNET_assert(GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
160 &pubkey, name, &rd_decrypt_cb, (void *) name)); 160 &pubkey, name, &rd_decrypt_cb, (void *)name));
161} 161}
162 162
163 163
164static void 164static void
165put_cont (void *cls, int32_t success, const char *emsg) 165put_cont(void *cls, int32_t success, const char *emsg)
166{ 166{
167 const char *name = cls; 167 const char *name = cls;
168 struct GNUNET_HashCode derived_hash; 168 struct GNUNET_HashCode derived_hash;
169 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 169 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
170 170
171 nsqe = NULL; 171 nsqe = NULL;
172 GNUNET_assert (NULL != cls); 172 GNUNET_assert(NULL != cls);
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
174 "Name store added record for `%s': %s\n", 174 "Name store added record for `%s': %s\n",
175 name, 175 name,
176 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 176 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
177 177
178 /* Create derived hash */ 178 /* Create derived hash */
179 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 179 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
180 GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); 180 GNUNET_GNSRECORD_query_from_public_key(&pubkey, name, &derived_hash);
181 181
182 ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 182 ncqe = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash,
183 &name_lookup_proc, (void *) name); 183 &name_lookup_proc, (void *)name);
184} 184}
185 185
186 186
187static void 187static void
188run (void *cls, 188run(void *cls,
189 const struct GNUNET_CONFIGURATION_Handle *cfg, 189 const struct GNUNET_CONFIGURATION_Handle *cfg,
190 struct GNUNET_TESTING_Peer *peer) 190 struct GNUNET_TESTING_Peer *peer)
191{ 191{
192 struct GNUNET_GNSRECORD_Data rd; 192 struct GNUNET_GNSRECORD_Data rd;
193 const char * name = "dummy.dummy.gnunet"; 193 const char * name = "dummy.dummy.gnunet";
194 194
195 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 195 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
196 &endbadly, 196 &endbadly,
197 NULL); 197 NULL);
198 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 198 privkey = GNUNET_CRYPTO_ecdsa_key_create();
199 GNUNET_assert (privkey != NULL); 199 GNUNET_assert(privkey != NULL);
200 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 200 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
201 &pubkey); 201 &pubkey);
202 202
203 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 203 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
204 rd.record_type = TEST_RECORD_TYPE; 204 rd.record_type = TEST_RECORD_TYPE;
205 rd.data_size = TEST_RECORD_DATALEN; 205 rd.data_size = TEST_RECORD_DATALEN;
206 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 206 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
207 rd.flags = 0; 207 rd.flags = 0;
208 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 208 memset((char *)rd.data, 'a', TEST_RECORD_DATALEN);
209 209
210 nsh = GNUNET_NAMESTORE_connect (cfg); 210 nsh = GNUNET_NAMESTORE_connect(cfg);
211 nch = GNUNET_NAMECACHE_connect (cfg); 211 nch = GNUNET_NAMECACHE_connect(cfg);
212 GNUNET_break (NULL != nsh); 212 GNUNET_break(NULL != nsh);
213 GNUNET_break (NULL != nch); 213 GNUNET_break(NULL != nch);
214 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 214 nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, name,
215 1, &rd, &put_cont, (void *) name); 215 1, &rd, &put_cont, (void *)name);
216 if (NULL == nsqe) 216 if (NULL == nsqe)
217 { 217 {
218 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 218 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
219 _("Namestore cannot store no block\n")); 219 _("Namestore cannot store no block\n"));
220 } 220 }
221 221
222 GNUNET_free ((void *)rd.data); 222 GNUNET_free((void *)rd.data);
223} 223}
224 224
225 225
@@ -227,24 +227,24 @@ run (void *cls,
227 227
228 228
229int 229int
230main (int argc, char *argv[]) 230main(int argc, char *argv[])
231{ 231{
232 const char *plugin_name; 232 const char *plugin_name;
233 char *cfg_name; 233 char *cfg_name;
234 234
235 SETUP_CFG (plugin_name, cfg_name); 235 SETUP_CFG(plugin_name, cfg_name);
236 res = 1; 236 res = 1;
237 if (0 != 237 if (0 !=
238 GNUNET_TESTING_peer_run ("test-namestore-api", 238 GNUNET_TESTING_peer_run("test-namestore-api",
239 cfg_name, 239 cfg_name,
240 &run, 240 &run,
241 NULL)) 241 NULL))
242 { 242 {
243 res = 1; 243 res = 1;
244 } 244 }
245 GNUNET_DISK_purge_cfg_dir (cfg_name, 245 GNUNET_DISK_purge_cfg_dir(cfg_name,
246 "GNUNET_TEST_HOME"); 246 "GNUNET_TEST_HOME");
247 GNUNET_free (cfg_name); 247 GNUNET_free(cfg_name);
248 return res; 248 return res;
249} 249}
250 250
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c
index 1938054d4..d25cdcdbb 100644
--- a/src/namestore/test_namestore_api_lookup_shadow.c
+++ b/src/namestore/test_namestore_api_lookup_shadow.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_lookup_shadow.c 21 * @file namestore/test_namestore_api_lookup_shadow.c
22 * @brief testcase for namestore_api.c: store a shadow record and perform a lookup 22 * @brief testcase for namestore_api.c: store a shadow record and perform a lookup
@@ -35,7 +35,7 @@
35 35
36#define TEST_RECORD_DATA 'a' 36#define TEST_RECORD_DATA 'a'
37 37
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 38#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
39 39
40 40
41static struct GNUNET_NAMESTORE_Handle *nsh; 41static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -56,24 +56,24 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
56 56
57 57
58static void 58static void
59cleanup () 59cleanup()
60{ 60{
61 if (NULL != nsh) 61 if (NULL != nsh)
62 { 62 {
63 GNUNET_NAMESTORE_disconnect (nsh); 63 GNUNET_NAMESTORE_disconnect(nsh);
64 nsh = NULL; 64 nsh = NULL;
65 } 65 }
66 if (NULL != nch) 66 if (NULL != nch)
67 { 67 {
68 GNUNET_NAMECACHE_disconnect (nch); 68 GNUNET_NAMECACHE_disconnect(nch);
69 nch = NULL; 69 nch = NULL;
70 } 70 }
71 if (NULL != privkey) 71 if (NULL != privkey)
72 { 72 {
73 GNUNET_free (privkey); 73 GNUNET_free(privkey);
74 privkey = NULL; 74 privkey = NULL;
75 } 75 }
76 GNUNET_SCHEDULER_shutdown (); 76 GNUNET_SCHEDULER_shutdown();
77} 77}
78 78
79 79
@@ -83,178 +83,178 @@ cleanup ()
83 * @param cls handle to use to re-connect. 83 * @param cls handle to use to re-connect.
84 */ 84 */
85static void 85static void
86endbadly (void *cls) 86endbadly(void *cls)
87{ 87{
88 if (NULL != nsqe) 88 if (NULL != nsqe)
89 { 89 {
90 GNUNET_NAMESTORE_cancel (nsqe); 90 GNUNET_NAMESTORE_cancel(nsqe);
91 nsqe = NULL; 91 nsqe = NULL;
92 } 92 }
93 if (NULL != ncqe) 93 if (NULL != ncqe)
94 { 94 {
95 GNUNET_NAMECACHE_cancel (ncqe); 95 GNUNET_NAMECACHE_cancel(ncqe);
96 ncqe = NULL; 96 ncqe = NULL;
97 } 97 }
98 cleanup (); 98 cleanup();
99 res = 1; 99 res = 1;
100} 100}
101 101
102 102
103static void 103static void
104end (void *cls) 104end(void *cls)
105{ 105{
106 cleanup (); 106 cleanup();
107 res = 0; 107 res = 0;
108} 108}
109 109
110 110
111static void 111static void
112rd_decrypt_cb (void *cls, 112rd_decrypt_cb(void *cls,
113 unsigned int rd_count, 113 unsigned int rd_count,
114 const struct GNUNET_GNSRECORD_Data *rd) 114 const struct GNUNET_GNSRECORD_Data *rd)
115{ 115{
116 char rd_cmp_data[TEST_RECORD_DATALEN]; 116 char rd_cmp_data[TEST_RECORD_DATALEN];
117 117
118 if (1 != rd_count) 118 if (1 != rd_count)
119 { 119 {
120 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 120 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
121 GNUNET_break (0); 121 GNUNET_break(0);
122 return; 122 return;
123 } 123 }
124 if (NULL == rd) 124 if (NULL == rd)
125 { 125 {
126 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 126 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
127 GNUNET_break (0); 127 GNUNET_break(0);
128 return; 128 return;
129 } 129 }
130 memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); 130 memset(rd_cmp_data, 'a', TEST_RECORD_DATALEN);
131 131
132 if (TEST_RECORD_TYPE != rd[0].record_type) 132 if (TEST_RECORD_TYPE != rd[0].record_type)
133 { 133 {
134 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 134 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
135 GNUNET_break (0); 135 GNUNET_break(0);
136 return; 136 return;
137 } 137 }
138 if (TEST_RECORD_DATALEN != rd[0].data_size) 138 if (TEST_RECORD_DATALEN != rd[0].data_size)
139 { 139 {
140 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 140 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
141 GNUNET_break (0); 141 GNUNET_break(0);
142 return; 142 return;
143 } 143 }
144 if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) 144 if (0 != memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN))
145 { 145 {
146 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 146 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
147 GNUNET_break (0); 147 GNUNET_break(0);
148 return; 148 return;
149 } 149 }
150 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) 150 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags))
151 { 151 {
152 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 152 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
153 GNUNET_break (0); 153 GNUNET_break(0);
154 return; 154 return;
155 } 155 }
156 156
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
158 "Block was decrypted successfully \n"); 158 "Block was decrypted successfully \n");
159 159
160 GNUNET_SCHEDULER_add_now (&end, NULL); 160 GNUNET_SCHEDULER_add_now(&end, NULL);
161} 161}
162 162
163 163
164static void 164static void
165name_lookup_proc (void *cls, 165name_lookup_proc(void *cls,
166 const struct GNUNET_GNSRECORD_Block *block) 166 const struct GNUNET_GNSRECORD_Block *block)
167{ 167{
168 const char *name = cls; 168 const char *name = cls;
169 169
170 ncqe = NULL; 170 ncqe = NULL;
171 GNUNET_assert (NULL != cls); 171 GNUNET_assert(NULL != cls);
172 172
173 if (endbadly_task != NULL) 173 if (endbadly_task != NULL)
174 { 174 {
175 GNUNET_SCHEDULER_cancel (endbadly_task); 175 GNUNET_SCHEDULER_cancel(endbadly_task);
176 endbadly_task = NULL; 176 endbadly_task = NULL;
177 } 177 }
178 178
179 if (NULL == block) 179 if (NULL == block)
180 { 180 {
181 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 181 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
182 _("Namestore returned no block\n")); 182 _("Namestore returned no block\n"));
183 if (endbadly_task != NULL) 183 if (endbadly_task != NULL)
184 GNUNET_SCHEDULER_cancel (endbadly_task); 184 GNUNET_SCHEDULER_cancel(endbadly_task);
185 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 185 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
186 return; 186 return;
187 } 187 }
188 188
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
190 "Namestore returned block, decrypting \n"); 190 "Namestore returned block, decrypting \n");
191 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, 191 GNUNET_assert(GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
192 &pubkey, name, &rd_decrypt_cb, (void *) name)); 192 &pubkey, name, &rd_decrypt_cb, (void *)name));
193} 193}
194 194
195 195
196static void 196static void
197put_cont (void *cls, int32_t success, const char *emsg) 197put_cont(void *cls, int32_t success, const char *emsg)
198{ 198{
199 const char *name = cls; 199 const char *name = cls;
200 struct GNUNET_HashCode derived_hash; 200 struct GNUNET_HashCode derived_hash;
201 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 201 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
202 202
203 nsqe = NULL; 203 nsqe = NULL;
204 GNUNET_assert (NULL != cls); 204 GNUNET_assert(NULL != cls);
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 205 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
206 "Name store added record for `%s': %s\n", 206 "Name store added record for `%s': %s\n",
207 name, 207 name,
208 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 208 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
209 209
210 /* Create derived hash */ 210 /* Create derived hash */
211 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 211 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
212 GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); 212 GNUNET_GNSRECORD_query_from_public_key(&pubkey, name, &derived_hash);
213 213
214 ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 214 ncqe = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash,
215 &name_lookup_proc, (void *) name); 215 &name_lookup_proc, (void *)name);
216} 216}
217 217
218 218
219static void 219static void
220run (void *cls, 220run(void *cls,
221 const struct GNUNET_CONFIGURATION_Handle *cfg, 221 const struct GNUNET_CONFIGURATION_Handle *cfg,
222 struct GNUNET_TESTING_Peer *peer) 222 struct GNUNET_TESTING_Peer *peer)
223{ 223{
224 struct GNUNET_GNSRECORD_Data rd; 224 struct GNUNET_GNSRECORD_Data rd;
225 const char * name = "dummy.dummy.gnunet"; 225 const char * name = "dummy.dummy.gnunet";
226 226
227 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 227 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
228 &endbadly, 228 &endbadly,
229 NULL); 229 NULL);
230 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 230 privkey = GNUNET_CRYPTO_ecdsa_key_create();
231 GNUNET_assert (privkey != NULL); 231 GNUNET_assert(privkey != NULL);
232 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 232 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
233 &pubkey); 233 &pubkey);
234 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 234 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
235 rd.record_type = TEST_RECORD_TYPE; 235 rd.record_type = TEST_RECORD_TYPE;
236 rd.data_size = TEST_RECORD_DATALEN; 236 rd.data_size = TEST_RECORD_DATALEN;
237 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 237 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
238 rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; 238 rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
239 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 239 memset((char *)rd.data, 'a', TEST_RECORD_DATALEN);
240 240
241 nsh = GNUNET_NAMESTORE_connect (cfg); 241 nsh = GNUNET_NAMESTORE_connect(cfg);
242 nch = GNUNET_NAMECACHE_connect (cfg); 242 nch = GNUNET_NAMECACHE_connect(cfg);
243 GNUNET_break (NULL != nsh); 243 GNUNET_break(NULL != nsh);
244 GNUNET_break (NULL != nch); 244 GNUNET_break(NULL != nch);
245 nsqe = GNUNET_NAMESTORE_records_store (nsh, 245 nsqe = GNUNET_NAMESTORE_records_store(nsh,
246 privkey, 246 privkey,
247 name, 247 name,
248 1, 248 1,
249 &rd, 249 &rd,
250 &put_cont, 250 &put_cont,
251 (void *) name); 251 (void *)name);
252 if (NULL == nsqe) 252 if (NULL == nsqe)
253 { 253 {
254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 254 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
255 _("Namestore cannot store no block\n")); 255 _("Namestore cannot store no block\n"));
256 } 256 }
257 GNUNET_free ((void *)rd.data); 257 GNUNET_free((void *)rd.data);
258} 258}
259 259
260 260
@@ -262,24 +262,24 @@ run (void *cls,
262 262
263 263
264int 264int
265main (int argc, char *argv[]) 265main(int argc, char *argv[])
266{ 266{
267 const char *plugin_name; 267 const char *plugin_name;
268 char *cfg_name; 268 char *cfg_name;
269 269
270 SETUP_CFG (plugin_name, cfg_name); 270 SETUP_CFG(plugin_name, cfg_name);
271 res = 1; 271 res = 1;
272 if (0 != 272 if (0 !=
273 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", 273 GNUNET_TESTING_peer_run("test-namestore-api-lookup-shadow",
274 cfg_name, 274 cfg_name,
275 &run, 275 &run,
276 NULL)) 276 NULL))
277 { 277 {
278 res = 1; 278 res = 1;
279 } 279 }
280 GNUNET_DISK_purge_cfg_dir (cfg_name, 280 GNUNET_DISK_purge_cfg_dir(cfg_name,
281 "GNUNET_TEST_HOME"); 281 "GNUNET_TEST_HOME");
282 GNUNET_free (cfg_name); 282 GNUNET_free(cfg_name);
283 return res; 283 return res;
284} 284}
285 285
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c
index 3d1dbfacf..d8d6b8a29 100644
--- a/src/namestore/test_namestore_api_lookup_shadow_filter.c
+++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_lookup_shadow_filter.c 21 * @file namestore/test_namestore_api_lookup_shadow_filter.c
22 * @brief testcase for namestore_api.c: store a record with short expiration 22 * @brief testcase for namestore_api.c: store a record with short expiration
@@ -37,8 +37,8 @@
37#define TEST_RECORD_DATA 'a' 37#define TEST_RECORD_DATA 'a'
38#define TEST_SHADOW_RECORD_DATA 'b' 38#define TEST_SHADOW_RECORD_DATA 'b'
39 39
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
41#define EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 41#define EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
42 42
43static struct GNUNET_NAMESTORE_Handle *nsh; 43static struct GNUNET_NAMESTORE_Handle *nsh;
44 44
@@ -70,24 +70,24 @@ static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
70 70
71 71
72static void 72static void
73cleanup () 73cleanup()
74{ 74{
75 if (NULL != nsh) 75 if (NULL != nsh)
76 { 76 {
77 GNUNET_NAMESTORE_disconnect (nsh); 77 GNUNET_NAMESTORE_disconnect(nsh);
78 nsh = NULL; 78 nsh = NULL;
79 } 79 }
80 if (NULL != nch) 80 if (NULL != nch)
81 { 81 {
82 GNUNET_NAMECACHE_disconnect (nch); 82 GNUNET_NAMECACHE_disconnect(nch);
83 nch = NULL; 83 nch = NULL;
84 } 84 }
85 if (NULL != privkey) 85 if (NULL != privkey)
86 { 86 {
87 GNUNET_free (privkey); 87 GNUNET_free(privkey);
88 privkey = NULL; 88 privkey = NULL;
89 } 89 }
90 GNUNET_SCHEDULER_shutdown (); 90 GNUNET_SCHEDULER_shutdown();
91} 91}
92 92
93 93
@@ -97,239 +97,240 @@ cleanup ()
97 * @param cls handle to use to re-connect. 97 * @param cls handle to use to re-connect.
98 */ 98 */
99static void 99static void
100endbadly (void *cls) 100endbadly(void *cls)
101{ 101{
102 if (NULL != delayed_lookup_task) 102 if (NULL != delayed_lookup_task)
103 { 103 {
104 GNUNET_SCHEDULER_cancel (delayed_lookup_task); 104 GNUNET_SCHEDULER_cancel(delayed_lookup_task);
105 delayed_lookup_task = NULL; 105 delayed_lookup_task = NULL;
106 } 106 }
107 if (NULL != nsqe) 107 if (NULL != nsqe)
108 { 108 {
109 GNUNET_NAMESTORE_cancel (nsqe); 109 GNUNET_NAMESTORE_cancel(nsqe);
110 nsqe = NULL; 110 nsqe = NULL;
111 } 111 }
112 if (NULL != ncqe) 112 if (NULL != ncqe)
113 { 113 {
114 GNUNET_NAMECACHE_cancel (ncqe); 114 GNUNET_NAMECACHE_cancel(ncqe);
115 ncqe = NULL; 115 ncqe = NULL;
116 } 116 }
117 cleanup (); 117 cleanup();
118 res = 1; 118 res = 1;
119} 119}
120 120
121 121
122static void 122static void
123end (void *cls) 123end(void *cls)
124{ 124{
125 cleanup (); 125 cleanup();
126 res = 0; 126 res = 0;
127} 127}
128 128
129 129
130static void 130static void
131rd_decrypt_cb (void *cls, 131rd_decrypt_cb(void *cls,
132 unsigned int rd_count, 132 unsigned int rd_count,
133 const struct GNUNET_GNSRECORD_Data *rd) 133 const struct GNUNET_GNSRECORD_Data *rd)
134{ 134{
135 struct GNUNET_GNSRECORD_Data *expected_rd = cls; 135 struct GNUNET_GNSRECORD_Data *expected_rd = cls;
136 char rd_cmp_data[TEST_RECORD_DATALEN]; 136 char rd_cmp_data[TEST_RECORD_DATALEN];
137 137
138 if (1 != rd_count) 138 if (1 != rd_count)
139 {
140 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
141 GNUNET_break (0);
142 return;
143 }
144 if (NULL == rd)
145 {
146 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
147 GNUNET_break (0);
148 return;
149 }
150 if (expected_rd == &records[0])
151 {
152 /* Expecting active record */
153 memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
154 if (TEST_RECORD_TYPE != rd[0].record_type)
155 {
156 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
157 GNUNET_break (0);
158 return;
159 }
160 if (TEST_RECORD_DATALEN != rd[0].data_size)
161 { 139 {
162 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 140 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
163 GNUNET_break (0); 141 GNUNET_break(0);
164 return; 142 return;
165 } 143 }
166 if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) 144 if (NULL == rd)
167 { 145 {
168 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 146 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
169 GNUNET_break (0); 147 GNUNET_break(0);
170 return; 148 return;
171 } 149 }
172 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) 150 if (expected_rd == &records[0])
173 { 151 {
174 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 152 /* Expecting active record */
175 GNUNET_break (0); 153 memset(rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
176 return; 154 if (TEST_RECORD_TYPE != rd[0].record_type)
155 {
156 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
157 GNUNET_break(0);
158 return;
159 }
160 if (TEST_RECORD_DATALEN != rd[0].data_size)
161 {
162 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
163 GNUNET_break(0);
164 return;
165 }
166 if (0 != memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN))
167 {
168 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
169 GNUNET_break(0);
170 return;
171 }
172 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags))
173 {
174 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
175 GNUNET_break(0);
176 return;
177 }
178 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
179 "Block was decrypted successfully with active record\n");
177 } 180 }
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
179 "Block was decrypted successfully with active record\n");
180 }
181 if (expected_rd == &records[1]) 181 if (expected_rd == &records[1])
182 {
183 /* Expecting shadow record but without shadow flag*/
184 memset (rd_cmp_data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN);
185 if (TEST_RECORD_TYPE != rd[0].record_type)
186 { 182 {
187 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 183 /* Expecting shadow record but without shadow flag*/
188 GNUNET_break (0); 184 memset(rd_cmp_data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN);
189 return; 185 if (TEST_RECORD_TYPE != rd[0].record_type)
186 {
187 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
188 GNUNET_break(0);
189 return;
190 }
191 if (TEST_RECORD_DATALEN != rd[0].data_size)
192 {
193 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
194 GNUNET_break(0);
195 return;
196 }
197 if (0 != memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN))
198 {
199 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
200 GNUNET_break(0);
201 return;
202 }
203 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags))
204 {
205 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
206 GNUNET_break(0);
207 return;
208 }
209 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
210 "Block was decrypted successfully with former shadow record \n");
211 GNUNET_SCHEDULER_add_now(&end, NULL);
190 } 212 }
191 if (TEST_RECORD_DATALEN != rd[0].data_size)
192 {
193 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
194 GNUNET_break (0);
195 return;
196 }
197 if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN))
198 {
199 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
200 GNUNET_break (0);
201 return;
202 }
203 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags))
204 {
205 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
206 GNUNET_break (0);
207 return;
208 }
209 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
210 "Block was decrypted successfully with former shadow record \n");
211 GNUNET_SCHEDULER_add_now (&end, NULL );
212 }
213} 213}
214 214
215 215
216static void 216static void
217name_lookup_active_proc (void *cls, 217name_lookup_active_proc(void *cls,
218 const struct GNUNET_GNSRECORD_Block *block) 218 const struct GNUNET_GNSRECORD_Block *block)
219{ 219{
220 struct GNUNET_GNSRECORD_Data *expected_rd = cls; 220 struct GNUNET_GNSRECORD_Data *expected_rd = cls;
221 GNUNET_assert (NULL != expected_rd); 221
222 GNUNET_assert(NULL != expected_rd);
222 223
223 ncqe = NULL; 224 ncqe = NULL;
224 ncqe_shadow = NULL; 225 ncqe_shadow = NULL;
225 if (endbadly_task != NULL) 226 if (endbadly_task != NULL)
226 { 227 {
227 GNUNET_SCHEDULER_cancel (endbadly_task); 228 GNUNET_SCHEDULER_cancel(endbadly_task);
228 endbadly_task = NULL; 229 endbadly_task = NULL;
229 } 230 }
230 231
231 if (NULL == block) 232 if (NULL == block)
232 { 233 {
233 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 234 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
234 _("Namestore returned no block\n")); 235 _("Namestore returned no block\n"));
235 if (endbadly_task != NULL) 236 if (endbadly_task != NULL)
236 GNUNET_SCHEDULER_cancel (endbadly_task); 237 GNUNET_SCHEDULER_cancel(endbadly_task);
237 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 238 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
238 return; 239 return;
239 } 240 }
240 241
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
242 "Namestore returned block, decrypting \n"); 243 "Namestore returned block, decrypting \n");
243 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, 244 GNUNET_assert(GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
244 &pubkey, TEST_NAME, &rd_decrypt_cb, expected_rd)); 245 &pubkey, TEST_NAME, &rd_decrypt_cb, expected_rd));
245} 246}
246 247
247 248
248static void 249static void
249name_lookup_shadow (void *cls) 250name_lookup_shadow(void *cls)
250{ 251{
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 252 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
252 "Performing lookup for shadow record \n"); 253 "Performing lookup for shadow record \n");
253 delayed_lookup_task = NULL; 254 delayed_lookup_task = NULL;
254 ncqe_shadow = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 255 ncqe_shadow = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash,
255 &name_lookup_active_proc, &records[1]); 256 &name_lookup_active_proc, &records[1]);
256} 257}
257 258
258 259
259static void 260static void
260put_cont (void *cls, int32_t success, const char *emsg) 261put_cont(void *cls, int32_t success, const char *emsg)
261{ 262{
262 nsqe = NULL; 263 nsqe = NULL;
263 264
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 265 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
265 "Name store added record for `%s': %s\n", 266 "Name store added record for `%s': %s\n",
266 TEST_NAME, 267 TEST_NAME,
267 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 268 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
268 269
269 /* Create derived hash */ 270 /* Create derived hash */
270 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 271 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
271 GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash); 272 GNUNET_GNSRECORD_query_from_public_key(&pubkey, TEST_NAME, &derived_hash);
272 273
273 if (0 == GNUNET_TIME_absolute_get_remaining(record_expiration).rel_value_us ) 274 if (0 == GNUNET_TIME_absolute_get_remaining(record_expiration).rel_value_us)
274 { 275 {
275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 276 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
276 "Test to too long to store records, cannot run test!\n"); 277 "Test to too long to store records, cannot run test!\n");
277 GNUNET_SCHEDULER_add_now (&end, NULL ); 278 GNUNET_SCHEDULER_add_now(&end, NULL);
278 return; 279 return;
279 } 280 }
280 /* Lookup active record now */ 281 /* Lookup active record now */
281 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 282 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
282 "Performing lookup for active record \n"); 283 "Performing lookup for active record \n");
283 ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 284 ncqe = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash,
284 &name_lookup_active_proc, &records[0]); 285 &name_lookup_active_proc, &records[0]);
285 286
286 delayed_lookup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (EXPIRATION, 2), &name_lookup_shadow, NULL); 287 delayed_lookup_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(EXPIRATION, 2), &name_lookup_shadow, NULL);
287} 288}
288 289
289 290
290static void 291static void
291run (void *cls, 292run(void *cls,
292 const struct GNUNET_CONFIGURATION_Handle *cfg, 293 const struct GNUNET_CONFIGURATION_Handle *cfg,
293 struct GNUNET_TESTING_Peer *peer) 294 struct GNUNET_TESTING_Peer *peer)
294{ 295{
295 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 296 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
296 &endbadly, 297 &endbadly,
297 NULL); 298 NULL);
298 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 299 privkey = GNUNET_CRYPTO_ecdsa_key_create();
299 GNUNET_assert (privkey != NULL); 300 GNUNET_assert(privkey != NULL);
300 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 301 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
301 &pubkey); 302 &pubkey);
302 303
303 record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), 304 record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
304 EXPIRATION); 305 EXPIRATION);
305 records[0].expiration_time = record_expiration.abs_value_us; 306 records[0].expiration_time = record_expiration.abs_value_us;
306 records[0].record_type = TEST_RECORD_TYPE; 307 records[0].record_type = TEST_RECORD_TYPE;
307 records[0].data_size = TEST_RECORD_DATALEN; 308 records[0].data_size = TEST_RECORD_DATALEN;
308 records[0].data = GNUNET_malloc (TEST_RECORD_DATALEN); 309 records[0].data = GNUNET_malloc(TEST_RECORD_DATALEN);
309 records[0].flags = GNUNET_GNSRECORD_RF_NONE; 310 records[0].flags = GNUNET_GNSRECORD_RF_NONE;
310 memset ((char *) records[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); 311 memset((char *)records[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
311 312
312 records[1].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 313 records[1].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
313 records[1].record_type = TEST_RECORD_TYPE; 314 records[1].record_type = TEST_RECORD_TYPE;
314 records[1].data_size = TEST_RECORD_DATALEN; 315 records[1].data_size = TEST_RECORD_DATALEN;
315 records[1].data = GNUNET_malloc (TEST_RECORD_DATALEN); 316 records[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
316 records[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; 317 records[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
317 memset ((char *) records[1].data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN); 318 memset((char *)records[1].data, TEST_SHADOW_RECORD_DATA, TEST_RECORD_DATALEN);
318 319
319 nsh = GNUNET_NAMESTORE_connect (cfg); 320 nsh = GNUNET_NAMESTORE_connect(cfg);
320 nch = GNUNET_NAMECACHE_connect (cfg); 321 nch = GNUNET_NAMECACHE_connect(cfg);
321 GNUNET_break (NULL != nsh); 322 GNUNET_break(NULL != nsh);
322 GNUNET_break (NULL != nch); 323 GNUNET_break(NULL != nch);
323 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, TEST_NAME, 324 nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, TEST_NAME,
324 2, records, &put_cont, NULL); 325 2, records, &put_cont, NULL);
325 if (NULL == nsqe) 326 if (NULL == nsqe)
326 { 327 {
327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 328 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
328 _("Namestore cannot store no block\n")); 329 _("Namestore cannot store no block\n"));
329 } 330 }
330 331
331 GNUNET_free ((void *) records[0].data); 332 GNUNET_free((void *)records[0].data);
332 GNUNET_free ((void *) records[1].data); 333 GNUNET_free((void *)records[1].data);
333} 334}
334 335
335 336
@@ -337,24 +338,24 @@ run (void *cls,
337 338
338 339
339int 340int
340main (int argc, char *argv[]) 341main(int argc, char *argv[])
341{ 342{
342 const char *plugin_name; 343 const char *plugin_name;
343 char *cfg_name; 344 char *cfg_name;
344 345
345 SETUP_CFG (plugin_name, cfg_name); 346 SETUP_CFG(plugin_name, cfg_name);
346 res = 1; 347 res = 1;
347 if (0 != 348 if (0 !=
348 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter", 349 GNUNET_TESTING_peer_run("test-namestore-api-lookup-shadow-filter",
349 cfg_name, 350 cfg_name,
350 &run, 351 &run,
351 NULL)) 352 NULL))
352 { 353 {
353 res = 1; 354 res = 1;
354 } 355 }
355 GNUNET_DISK_purge_cfg_dir (cfg_name, 356 GNUNET_DISK_purge_cfg_dir(cfg_name,
356 "GNUNET_TEST_HOME"); 357 "GNUNET_TEST_HOME");
357 GNUNET_free (cfg_name); 358 GNUNET_free(cfg_name);
358 return res; 359 return res;
359} 360}
360 361
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index 8fbeb6479..f1ee980cc 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_monitoring.c 21 * @file namestore/test_namestore_api_monitoring.c
22 * @brief testcase for zone monitoring functionality: monitor first, then add records 22 * @brief testcase for zone monitoring functionality: monitor first, then add records
@@ -31,7 +31,7 @@
31 31
32 32
33 33
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 34#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
35 35
36 36
37static struct GNUNET_NAMESTORE_Handle * nsh; 37static struct GNUNET_NAMESTORE_Handle * nsh;
@@ -62,63 +62,63 @@ struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
62 62
63 63
64static void 64static void
65do_shutdown () 65do_shutdown()
66{ 66{
67 if (NULL != zm) 67 if (NULL != zm)
68 { 68 {
69 GNUNET_NAMESTORE_zone_monitor_stop (zm); 69 GNUNET_NAMESTORE_zone_monitor_stop(zm);
70 zm = NULL; 70 zm = NULL;
71 } 71 }
72 if (NULL != ns_ops[0]) 72 if (NULL != ns_ops[0])
73 { 73 {
74 GNUNET_NAMESTORE_cancel(ns_ops[0]); 74 GNUNET_NAMESTORE_cancel(ns_ops[0]);
75 ns_ops[0] = NULL; 75 ns_ops[0] = NULL;
76 } 76 }
77 if (NULL != ns_ops[1]) 77 if (NULL != ns_ops[1])
78 { 78 {
79 GNUNET_NAMESTORE_cancel(ns_ops[1]); 79 GNUNET_NAMESTORE_cancel(ns_ops[1]);
80 ns_ops[1] = NULL; 80 ns_ops[1] = NULL;
81 } 81 }
82 if (NULL != ns_ops[2]) 82 if (NULL != ns_ops[2])
83 { 83 {
84 GNUNET_NAMESTORE_cancel(ns_ops[2]); 84 GNUNET_NAMESTORE_cancel(ns_ops[2]);
85 ns_ops[2] = NULL; 85 ns_ops[2] = NULL;
86 } 86 }
87 if (NULL != nsh) 87 if (NULL != nsh)
88 { 88 {
89 GNUNET_NAMESTORE_disconnect (nsh); 89 GNUNET_NAMESTORE_disconnect(nsh);
90 nsh = NULL; 90 nsh = NULL;
91 } 91 }
92 GNUNET_free_non_null(s_name_1); 92 GNUNET_free_non_null(s_name_1);
93 GNUNET_free_non_null(s_name_2); 93 GNUNET_free_non_null(s_name_2);
94 GNUNET_free_non_null(s_name_3); 94 GNUNET_free_non_null(s_name_3);
95 95
96 if (s_rd_1 != NULL) 96 if (s_rd_1 != NULL)
97 { 97 {
98 GNUNET_free ((void *)s_rd_1->data); 98 GNUNET_free((void *)s_rd_1->data);
99 GNUNET_free (s_rd_1); 99 GNUNET_free(s_rd_1);
100 } 100 }
101 if (s_rd_2 != NULL) 101 if (s_rd_2 != NULL)
102 { 102 {
103 GNUNET_free ((void *)s_rd_2->data); 103 GNUNET_free((void *)s_rd_2->data);
104 GNUNET_free (s_rd_2); 104 GNUNET_free(s_rd_2);
105 } 105 }
106 if (s_rd_3 != NULL) 106 if (s_rd_3 != NULL)
107 { 107 {
108 GNUNET_free ((void *)s_rd_3->data); 108 GNUNET_free((void *)s_rd_3->data);
109 GNUNET_free (s_rd_3); 109 GNUNET_free(s_rd_3);
110 } 110 }
111 111
112 if (NULL != privkey) 112 if (NULL != privkey)
113 { 113 {
114 GNUNET_free (privkey); 114 GNUNET_free(privkey);
115 privkey = NULL; 115 privkey = NULL;
116 } 116 }
117 if (NULL != privkey2) 117 if (NULL != privkey2)
118 { 118 {
119 GNUNET_free (privkey2); 119 GNUNET_free(privkey2);
120 privkey2 = NULL; 120 privkey2 = NULL;
121 } 121 }
122} 122}
123 123
124 124
@@ -128,218 +128,218 @@ do_shutdown ()
128 * @param cls handle to use to re-connect. 128 * @param cls handle to use to re-connect.
129 */ 129 */
130static void 130static void
131endbadly (void *cls) 131endbadly(void *cls)
132{ 132{
133 do_shutdown (); 133 do_shutdown();
134 res = 1; 134 res = 1;
135} 135}
136 136
137 137
138static void 138static void
139end (void *cls) 139end(void *cls)
140{ 140{
141 do_shutdown (); 141 do_shutdown();
142 res = 0; 142 res = 0;
143} 143}
144 144
145 145
146static void 146static void
147zone_proc (void *cls, 147zone_proc(void *cls,
148 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 148 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
149 const char *name, 149 const char *name,
150 unsigned int rd_count, 150 unsigned int rd_count,
151 const struct GNUNET_GNSRECORD_Data *rd) 151 const struct GNUNET_GNSRECORD_Data *rd)
152{ 152{
153 static int returned_records; 153 static int returned_records;
154 static int fail = GNUNET_NO; 154 static int fail = GNUNET_NO;
155 155
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
157 "Comparing results name %s\n", 157 "Comparing results name %s\n",
158 name); 158 name);
159 if (0 != GNUNET_memcmp (zone_key, 159 if (0 != GNUNET_memcmp(zone_key,
160 privkey)) 160 privkey))
161 { 161 {
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
163 "Monitoring returned wrong zone key\n"); 163 "Monitoring returned wrong zone key\n");
164 GNUNET_break (0); 164 GNUNET_break(0);
165 GNUNET_SCHEDULER_cancel (endbadly_task); 165 GNUNET_SCHEDULER_cancel(endbadly_task);
166 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 166 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
167 return; 167 return;
168 } 168 }
169 169
170 if (0 == strcmp (name, s_name_1)) 170 if (0 == strcmp(name, s_name_1))
171 {
172 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1))
173 { 171 {
174 GNUNET_break (0); 172 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1))
175 fail = GNUNET_YES; 173 {
174 GNUNET_break(0);
175 fail = GNUNET_YES;
176 }
176 } 177 }
177 } 178 else if (0 == strcmp(name, s_name_2))
178 else if (0 == strcmp (name, s_name_2))
179 {
180 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
181 { 179 {
182 GNUNET_break (0); 180 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
183 fail = GNUNET_YES; 181 {
182 GNUNET_break(0);
183 fail = GNUNET_YES;
184 }
184 } 185 }
185 }
186 else 186 else
187 { 187 {
188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 188 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
189 "Invalid name %s\n", 189 "Invalid name %s\n",
190 name); 190 name);
191 GNUNET_break (0); 191 GNUNET_break(0);
192 fail = GNUNET_YES; 192 fail = GNUNET_YES;
193 } 193 }
194 GNUNET_NAMESTORE_zone_monitor_next (zm, 194 GNUNET_NAMESTORE_zone_monitor_next(zm,
195 1); 195 1);
196 if (2 == ++returned_records) 196 if (2 == ++returned_records)
197 {
198 if (endbadly_task != NULL)
199 { 197 {
200 GNUNET_SCHEDULER_cancel (endbadly_task); 198 if (endbadly_task != NULL)
201 endbadly_task = NULL; 199 {
200 GNUNET_SCHEDULER_cancel(endbadly_task);
201 endbadly_task = NULL;
202 }
203 if (GNUNET_YES == fail)
204 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
205 else
206 GNUNET_SCHEDULER_add_now(&end, NULL);
202 } 207 }
203 if (GNUNET_YES == fail)
204 GNUNET_SCHEDULER_add_now (&endbadly, NULL);
205 else
206 GNUNET_SCHEDULER_add_now (&end, NULL);
207 }
208} 208}
209 209
210 210
211static void 211static void
212put_cont (void *cls, 212put_cont(void *cls,
213 int32_t success, 213 int32_t success,
214 const char *emsg) 214 const char *emsg)
215{ 215{
216 static int c = 0; 216 static int c = 0;
217 char *label = cls; 217 char *label = cls;
218 218
219 if (0 == strcmp (label, s_name_1)) 219 if (0 == strcmp(label, s_name_1))
220 ns_ops[0] = NULL; 220 ns_ops[0] = NULL;
221 else if (0 == strcmp (label, s_name_2)) 221 else if (0 == strcmp(label, s_name_2))
222 ns_ops[1] = NULL; 222 ns_ops[1] = NULL;
223 else if (0 == strcmp (label, s_name_3)) 223 else if (0 == strcmp(label, s_name_3))
224 ns_ops[2] = NULL; 224 ns_ops[2] = NULL;
225 225
226 if (success == GNUNET_OK) 226 if (success == GNUNET_OK)
227 { 227 {
228 c++; 228 c++;
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 229 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
230 "Created record %u: `%s'\n", 230 "Created record %u: `%s'\n",
231 c, 231 c,
232 label); 232 label);
233 } 233 }
234 else 234 else
235 { 235 {
236 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
237 "Failed to create record `%s'\n", 237 "Failed to create record `%s'\n",
238 label); 238 label);
239 GNUNET_break (0); 239 GNUNET_break(0);
240 GNUNET_SCHEDULER_cancel (endbadly_task); 240 GNUNET_SCHEDULER_cancel(endbadly_task);
241 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, 241 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly,
242 NULL); 242 NULL);
243 } 243 }
244} 244}
245 245
246 246
247static struct GNUNET_GNSRECORD_Data * 247static struct GNUNET_GNSRECORD_Data *
248create_record (unsigned int count) 248create_record(unsigned int count)
249{ 249{
250 struct GNUNET_GNSRECORD_Data *rd; 250 struct GNUNET_GNSRECORD_Data *rd;
251 251
252 rd = GNUNET_new_array (count, 252 rd = GNUNET_new_array(count,
253 struct GNUNET_GNSRECORD_Data); 253 struct GNUNET_GNSRECORD_Data);
254 for (unsigned int c = 0; c < count; c++) 254 for (unsigned int c = 0; c < count; c++)
255 { 255 {
256 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 256 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us;
257 rd[c].record_type = TEST_RECORD_TYPE; 257 rd[c].record_type = TEST_RECORD_TYPE;
258 rd[c].data_size = 50; 258 rd[c].data_size = 50;
259 rd[c].data = GNUNET_malloc(50); 259 rd[c].data = GNUNET_malloc(50);
260 rd[c].flags = 0; 260 rd[c].flags = 0;
261 memset ((char *) rd[c].data, 'a', 50); 261 memset((char *)rd[c].data, 'a', 50);
262 } 262 }
263 return rd; 263 return rd;
264} 264}
265 265
266 266
267static void 267static void
268fail_cb (void *cls) 268fail_cb(void *cls)
269{ 269{
270 GNUNET_assert (0); 270 GNUNET_assert(0);
271} 271}
272 272
273 273
274static void 274static void
275sync_cb (void *cls) 275sync_cb(void *cls)
276{ 276{
277 /* do nothing */ 277 /* do nothing */
278} 278}
279 279
280 280
281static void 281static void
282run (void *cls, 282run(void *cls,
283 const struct GNUNET_CONFIGURATION_Handle *cfg, 283 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 struct GNUNET_TESTING_Peer *peer) 284 struct GNUNET_TESTING_Peer *peer)
285{ 285{
286 res = 1; 286 res = 1;
287 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 287 privkey = GNUNET_CRYPTO_ecdsa_key_create();
288 GNUNET_assert (privkey != NULL); 288 GNUNET_assert(privkey != NULL);
289 289
290 /* Start monitoring */ 290 /* Start monitoring */
291 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 291 zm = GNUNET_NAMESTORE_zone_monitor_start(cfg,
292 privkey, 292 privkey,
293 GNUNET_YES, 293 GNUNET_YES,
294 &fail_cb, 294 &fail_cb,
295 NULL, 295 NULL,
296 &zone_proc, 296 &zone_proc,
297 NULL, 297 NULL,
298 &sync_cb, 298 &sync_cb,
299 NULL); 299 NULL);
300 if (NULL == zm) 300 if (NULL == zm)
301 { 301 {
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 302 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
303 "Failed to create zone monitor\n"); 303 "Failed to create zone monitor\n");
304 GNUNET_break (0); 304 GNUNET_break(0);
305 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 305 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
306 return; 306 return;
307 } 307 }
308 308
309 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); 309 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
310 /* Connect to namestore */ 310 /* Connect to namestore */
311 nsh = GNUNET_NAMESTORE_connect (cfg); 311 nsh = GNUNET_NAMESTORE_connect(cfg);
312 if (NULL == nsh) 312 if (NULL == nsh)
313 { 313 {
314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n"); 314 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n");
315 GNUNET_break (0); 315 GNUNET_break(0);
316 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 316 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
317 return; 317 return;
318 } 318 }
319 319
320 privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); 320 privkey2 = GNUNET_CRYPTO_ecdsa_key_create();
321 GNUNET_assert (privkey2 != NULL); 321 GNUNET_assert(privkey2 != NULL);
322 322
323 323
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 324 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
325 "Created record 3\n"); 325 "Created record 3\n");
326 /* name in different zone */ 326 /* name in different zone */
327 GNUNET_asprintf(&s_name_3, "dummy3"); 327 GNUNET_asprintf(&s_name_3, "dummy3");
328 s_rd_3 = create_record(1); 328 s_rd_3 = create_record(1);
329 GNUNET_assert (NULL != (ns_ops[2] = 329 GNUNET_assert(NULL != (ns_ops[2] =
330 GNUNET_NAMESTORE_records_store (nsh, 330 GNUNET_NAMESTORE_records_store(nsh,
331 privkey2, 331 privkey2,
332 s_name_3, 332 s_name_3,
333 1, 333 1,
334 s_rd_3, 334 s_rd_3,
335 &put_cont, 335 &put_cont,
336 s_name_3))); 336 s_name_3)));
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 337 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
338 "Created record 1\n"); 338 "Created record 1\n");
339 GNUNET_asprintf(&s_name_1, "dummy1"); 339 GNUNET_asprintf(&s_name_1, "dummy1");
340 s_rd_1 = create_record(1); 340 s_rd_1 = create_record(1);
341 GNUNET_assert (NULL != (ns_ops[0] = 341 GNUNET_assert(NULL != (ns_ops[0] =
342 GNUNET_NAMESTORE_records_store (nsh, 342 GNUNET_NAMESTORE_records_store(nsh,
343 privkey, 343 privkey,
344 s_name_1, 344 s_name_1,
345 1, 345 1,
@@ -348,11 +348,11 @@ run (void *cls,
348 s_name_1))); 348 s_name_1)));
349 349
350 350
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
352 GNUNET_asprintf(&s_name_2, "dummy2"); 352 GNUNET_asprintf(&s_name_2, "dummy2");
353 s_rd_2 = create_record(1); 353 s_rd_2 = create_record(1);
354 GNUNET_assert (NULL != (ns_ops[1] = 354 GNUNET_assert(NULL != (ns_ops[1] =
355 GNUNET_NAMESTORE_records_store (nsh, 355 GNUNET_NAMESTORE_records_store(nsh,
356 privkey, 356 privkey,
357 s_name_2, 357 s_name_2,
358 1, 358 1,
@@ -366,25 +366,25 @@ run (void *cls,
366 366
367 367
368int 368int
369main (int argc, 369main(int argc,
370 char *argv[]) 370 char *argv[])
371{ 371{
372 const char *plugin_name; 372 const char *plugin_name;
373 char *cfg_name; 373 char *cfg_name;
374 374
375 SETUP_CFG (plugin_name, cfg_name); 375 SETUP_CFG(plugin_name, cfg_name);
376 res = 1; 376 res = 1;
377 if (0 != 377 if (0 !=
378 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", 378 GNUNET_TESTING_peer_run("test-namestore-api-monitoring",
379 cfg_name, 379 cfg_name,
380 &run, 380 &run,
381 NULL)) 381 NULL))
382 { 382 {
383 res = 1; 383 res = 1;
384 } 384 }
385 GNUNET_DISK_purge_cfg_dir (cfg_name, 385 GNUNET_DISK_purge_cfg_dir(cfg_name,
386 "GNUNET_TEST_HOME"); 386 "GNUNET_TEST_HOME");
387 GNUNET_free (cfg_name); 387 GNUNET_free(cfg_name);
388 return res; 388 return res;
389} 389}
390 390
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index e54046c85..97432b2a2 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_monitoring_existing.c 21 * @file namestore/test_namestore_api_monitoring_existing.c
22 * @brief testcase for zone monitoring functionality: add records first, then monitor 22 * @brief testcase for zone monitoring functionality: add records first, then monitor
@@ -30,7 +30,7 @@
30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT 30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
31 31
32 32
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 33#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
34 34
35static const struct GNUNET_CONFIGURATION_Handle *cfg; 35static const struct GNUNET_CONFIGURATION_Handle *cfg;
36 36
@@ -67,311 +67,311 @@ struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
67 * @param cls handle to use to re-connect. 67 * @param cls handle to use to re-connect.
68 */ 68 */
69static void 69static void
70endbadly (void *cls) 70endbadly(void *cls)
71{ 71{
72 endbadly_task = NULL; 72 endbadly_task = NULL;
73 GNUNET_break (0); 73 GNUNET_break(0);
74 GNUNET_SCHEDULER_shutdown (); 74 GNUNET_SCHEDULER_shutdown();
75 res = 1; 75 res = 1;
76} 76}
77 77
78 78
79static void 79static void
80end (void *cls) 80end(void *cls)
81{ 81{
82 if (NULL != zm) 82 if (NULL != zm)
83 { 83 {
84 GNUNET_NAMESTORE_zone_monitor_stop (zm); 84 GNUNET_NAMESTORE_zone_monitor_stop(zm);
85 zm = NULL; 85 zm = NULL;
86 } 86 }
87 if (NULL != ns_ops[0]) 87 if (NULL != ns_ops[0])
88 { 88 {
89 GNUNET_NAMESTORE_cancel(ns_ops[0]); 89 GNUNET_NAMESTORE_cancel(ns_ops[0]);
90 ns_ops[0] = NULL; 90 ns_ops[0] = NULL;
91 } 91 }
92 if (NULL != ns_ops[1]) 92 if (NULL != ns_ops[1])
93 { 93 {
94 GNUNET_NAMESTORE_cancel(ns_ops[1]); 94 GNUNET_NAMESTORE_cancel(ns_ops[1]);
95 ns_ops[1] = NULL; 95 ns_ops[1] = NULL;
96 } 96 }
97 if (NULL != ns_ops[2]) 97 if (NULL != ns_ops[2])
98 { 98 {
99 GNUNET_NAMESTORE_cancel(ns_ops[2]); 99 GNUNET_NAMESTORE_cancel(ns_ops[2]);
100 ns_ops[2] = NULL; 100 ns_ops[2] = NULL;
101 } 101 }
102 if (NULL != endbadly_task) 102 if (NULL != endbadly_task)
103 { 103 {
104 GNUNET_SCHEDULER_cancel (endbadly_task); 104 GNUNET_SCHEDULER_cancel(endbadly_task);
105 endbadly_task = NULL; 105 endbadly_task = NULL;
106 } 106 }
107 if (NULL != nsh) 107 if (NULL != nsh)
108 { 108 {
109 GNUNET_NAMESTORE_disconnect (nsh); 109 GNUNET_NAMESTORE_disconnect(nsh);
110 nsh = NULL; 110 nsh = NULL;
111 } 111 }
112 if (NULL != s_rd_1) 112 if (NULL != s_rd_1)
113 { 113 {
114 GNUNET_free ((void *)s_rd_1->data); 114 GNUNET_free((void *)s_rd_1->data);
115 GNUNET_free (s_rd_1); 115 GNUNET_free(s_rd_1);
116 } 116 }
117 if (NULL != s_rd_2) 117 if (NULL != s_rd_2)
118 { 118 {
119 GNUNET_free ((void *)s_rd_2->data); 119 GNUNET_free((void *)s_rd_2->data);
120 GNUNET_free (s_rd_2); 120 GNUNET_free(s_rd_2);
121 } 121 }
122 if (NULL != s_rd_3) 122 if (NULL != s_rd_3)
123 { 123 {
124 GNUNET_free ((void *)s_rd_3->data); 124 GNUNET_free((void *)s_rd_3->data);
125 GNUNET_free (s_rd_3); 125 GNUNET_free(s_rd_3);
126 } 126 }
127 if (NULL != privkey) 127 if (NULL != privkey)
128 { 128 {
129 GNUNET_free (privkey); 129 GNUNET_free(privkey);
130 privkey = NULL; 130 privkey = NULL;
131 } 131 }
132 if (NULL != privkey2) 132 if (NULL != privkey2)
133 { 133 {
134 GNUNET_free (privkey2); 134 GNUNET_free(privkey2);
135 privkey2 = NULL; 135 privkey2 = NULL;
136 } 136 }
137} 137}
138 138
139 139
140static void 140static void
141zone_proc (void *cls, 141zone_proc(void *cls,
142 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 142 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
143 const char *name, 143 const char *name,
144 unsigned int rd_count, 144 unsigned int rd_count,
145 const struct GNUNET_GNSRECORD_Data *rd) 145 const struct GNUNET_GNSRECORD_Data *rd)
146{ 146{
147 static int returned_records; 147 static int returned_records;
148 static int fail = GNUNET_NO; 148 static int fail = GNUNET_NO;
149 149
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
151 "Comparing results name %s\n", 151 "Comparing results name %s\n",
152 name); 152 name);
153 if (0 != GNUNET_memcmp (zone_key, 153 if (0 != GNUNET_memcmp(zone_key,
154 privkey)) 154 privkey))
155 {
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
157 "Monitoring returned wrong zone key\n");
158 GNUNET_break (0);
159 GNUNET_SCHEDULER_shutdown ();
160 return;
161 }
162
163 if (0 == strcmp (name,
164 s_name_1))
165 {
166 if (GNUNET_YES !=
167 GNUNET_GNSRECORD_records_cmp (rd,
168 s_rd_1))
169 { 155 {
170 GNUNET_break (0); 156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
171 fail = GNUNET_YES; 157 "Monitoring returned wrong zone key\n");
158 GNUNET_break(0);
159 GNUNET_SCHEDULER_shutdown();
160 return;
172 } 161 }
173 } 162
174 else if (0 == strcmp (name, 163 if (0 == strcmp(name,
175 s_name_2)) 164 s_name_1))
176 {
177 if (GNUNET_YES !=
178 GNUNET_GNSRECORD_records_cmp (rd,
179 s_rd_2))
180 { 165 {
181 GNUNET_break (0); 166 if (GNUNET_YES !=
182 fail = GNUNET_YES; 167 GNUNET_GNSRECORD_records_cmp(rd,
168 s_rd_1))
169 {
170 GNUNET_break(0);
171 fail = GNUNET_YES;
172 }
173 }
174 else if (0 == strcmp(name,
175 s_name_2))
176 {
177 if (GNUNET_YES !=
178 GNUNET_GNSRECORD_records_cmp(rd,
179 s_rd_2))
180 {
181 GNUNET_break(0);
182 fail = GNUNET_YES;
183 }
183 } 184 }
184 }
185 else 185 else
186 {
187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
188 "Invalid name %s\n",
189 name);
190 GNUNET_break (0);
191 fail = GNUNET_YES;
192 }
193 GNUNET_NAMESTORE_zone_monitor_next (zm,
194 1);
195 if (2 == ++returned_records)
196 {
197 GNUNET_SCHEDULER_shutdown ();
198 if (GNUNET_YES == fail)
199 { 186 {
200 GNUNET_break (0); 187 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
201 res = 1; 188 "Invalid name %s\n",
189 name);
190 GNUNET_break(0);
191 fail = GNUNET_YES;
202 } 192 }
203 else 193 GNUNET_NAMESTORE_zone_monitor_next(zm,
194 1);
195 if (2 == ++returned_records)
204 { 196 {
205 res = 0; 197 GNUNET_SCHEDULER_shutdown();
198 if (GNUNET_YES == fail)
199 {
200 GNUNET_break(0);
201 res = 1;
202 }
203 else
204 {
205 res = 0;
206 }
206 } 207 }
207 }
208} 208}
209 209
210 210
211static void 211static void
212fail_cb (void *cls) 212fail_cb(void *cls)
213{ 213{
214 GNUNET_assert (0); 214 GNUNET_assert(0);
215} 215}
216 216
217 217
218static void 218static void
219sync_cb (void *cls) 219sync_cb(void *cls)
220{ 220{
221 /* do nothing */ 221 /* do nothing */
222} 222}
223 223
224 224
225static void 225static void
226put_cont (void *cls, 226put_cont(void *cls,
227 int32_t success, 227 int32_t success,
228 const char *emsg) 228 const char *emsg)
229{ 229{
230 static int c = 0; 230 static int c = 0;
231 const char *label = cls; 231 const char *label = cls;
232 232
233 if (0 == strcmp (label, 233 if (0 == strcmp(label,
234 s_name_1)) 234 s_name_1))
235 ns_ops[0] = NULL; 235 ns_ops[0] = NULL;
236 else if (0 == strcmp (label, 236 else if (0 == strcmp(label,
237 s_name_2)) 237 s_name_2))
238 ns_ops[1] = NULL; 238 ns_ops[1] = NULL;
239 else if (0 == strcmp (label, 239 else if (0 == strcmp(label,
240 s_name_3)) 240 s_name_3))
241 ns_ops[2] = NULL; 241 ns_ops[2] = NULL;
242 242
243 if (success == GNUNET_OK) 243 if (success == GNUNET_OK)
244 { 244 {
245 c++; 245 c++;
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
247 "Created record %u: `%s'\n", 247 "Created record %u: `%s'\n",
248 c, 248 c,
249 label); 249 label);
250 } 250 }
251 else 251 else
252 {
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 "Failed to created records\n");
255 GNUNET_break (0);
256 res = 1;
257 GNUNET_SCHEDULER_shutdown ();
258 return;
259 }
260
261 if (3 == c)
262 {
263 /* Start monitoring */
264 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
265 privkey,
266 GNUNET_YES,
267 &fail_cb,
268 NULL,
269 &zone_proc,
270 NULL,
271 &sync_cb,
272 NULL);
273 if (NULL == zm)
274 { 252 {
275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 253 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
276 "Failed to create zone monitor\n"); 254 "Failed to created records\n");
277 GNUNET_break (0); 255 GNUNET_break(0);
278 res = 1; 256 res = 1;
279 GNUNET_SCHEDULER_shutdown (); 257 GNUNET_SCHEDULER_shutdown();
280 return; 258 return;
281 } 259 }
282 } 260
261 if (3 == c)
262 {
263 /* Start monitoring */
264 zm = GNUNET_NAMESTORE_zone_monitor_start(cfg,
265 privkey,
266 GNUNET_YES,
267 &fail_cb,
268 NULL,
269 &zone_proc,
270 NULL,
271 &sync_cb,
272 NULL);
273 if (NULL == zm)
274 {
275 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
276 "Failed to create zone monitor\n");
277 GNUNET_break(0);
278 res = 1;
279 GNUNET_SCHEDULER_shutdown();
280 return;
281 }
282 }
283} 283}
284 284
285 285
286static struct GNUNET_GNSRECORD_Data * 286static struct GNUNET_GNSRECORD_Data *
287create_record (unsigned int count) 287create_record(unsigned int count)
288{ 288{
289 struct GNUNET_GNSRECORD_Data *rd; 289 struct GNUNET_GNSRECORD_Data *rd;
290 290
291 rd = GNUNET_new_array (count, 291 rd = GNUNET_new_array(count,
292 struct GNUNET_GNSRECORD_Data); 292 struct GNUNET_GNSRECORD_Data);
293 for (unsigned int c = 0; c < count; c++) 293 for (unsigned int c = 0; c < count; c++)
294 { 294 {
295 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 295 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us;
296 rd[c].record_type = TEST_RECORD_TYPE; 296 rd[c].record_type = TEST_RECORD_TYPE;
297 rd[c].data_size = 50; 297 rd[c].data_size = 50;
298 rd[c].data = GNUNET_malloc(50); 298 rd[c].data = GNUNET_malloc(50);
299 rd[c].flags = 0; 299 rd[c].flags = 0;
300 memset ((char *) rd[c].data, 300 memset((char *)rd[c].data,
301 'a', 301 'a',
302 50); 302 50);
303 } 303 }
304 return rd; 304 return rd;
305} 305}
306 306
307 307
308static void 308static void
309run (void *cls, 309run(void *cls,
310 const struct GNUNET_CONFIGURATION_Handle *mycfg, 310 const struct GNUNET_CONFIGURATION_Handle *mycfg,
311 struct GNUNET_TESTING_Peer *peer) 311 struct GNUNET_TESTING_Peer *peer)
312{ 312{
313 res = 1; 313 res = 1;
314 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 314 privkey = GNUNET_CRYPTO_ecdsa_key_create();
315 GNUNET_assert (NULL != privkey); 315 GNUNET_assert(NULL != privkey);
316 privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); 316 privkey2 = GNUNET_CRYPTO_ecdsa_key_create();
317 GNUNET_assert (NULL != privkey2); 317 GNUNET_assert(NULL != privkey2);
318 318
319 cfg = mycfg; 319 cfg = mycfg;
320 GNUNET_SCHEDULER_add_shutdown (&end, 320 GNUNET_SCHEDULER_add_shutdown(&end,
321 NULL); 321 NULL);
322 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 322 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
323 &endbadly, 323 &endbadly,
324 NULL); 324 NULL);
325 /* Connect to namestore */ 325 /* Connect to namestore */
326 nsh = GNUNET_NAMESTORE_connect (cfg); 326 nsh = GNUNET_NAMESTORE_connect(cfg);
327 if (NULL == nsh) 327 if (NULL == nsh)
328 { 328 {
329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 329 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
330 "Connect to namestore failed\n"); 330 "Connect to namestore failed\n");
331 GNUNET_break (0); 331 GNUNET_break(0);
332 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, 332 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly,
333 NULL); 333 NULL);
334 return; 334 return;
335 } 335 }
336 336
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 337 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
338 "Created record 3\n"); 338 "Created record 3\n");
339 /* name in different zone */ 339 /* name in different zone */
340 s_name_3 = "dummy3"; 340 s_name_3 = "dummy3";
341 s_rd_3 = create_record(1); 341 s_rd_3 = create_record(1);
342 GNUNET_assert (NULL != (ns_ops[2] = 342 GNUNET_assert(NULL != (ns_ops[2] =
343 GNUNET_NAMESTORE_records_store (nsh, 343 GNUNET_NAMESTORE_records_store(nsh,
344 privkey2, 344 privkey2,
345 s_name_3, 345 s_name_3,
346 1, 346 1,
347 s_rd_3, 347 s_rd_3,
348 &put_cont, 348 &put_cont,
349 (void *) s_name_3))); 349 (void *)s_name_3)));
350 350
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
352 "Created record 1\n"); 352 "Created record 1\n");
353 s_name_1 = "dummy1"; 353 s_name_1 = "dummy1";
354 s_rd_1 = create_record (1); 354 s_rd_1 = create_record(1);
355 GNUNET_assert (NULL != (ns_ops[0] = 355 GNUNET_assert(NULL != (ns_ops[0] =
356 GNUNET_NAMESTORE_records_store (nsh, 356 GNUNET_NAMESTORE_records_store(nsh,
357 privkey, 357 privkey,
358 s_name_1, 358 s_name_1,
359 1, 359 1,
360 s_rd_1, 360 s_rd_1,
361 &put_cont, 361 &put_cont,
362 (void *) s_name_1))); 362 (void *)s_name_1)));
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 363 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
364 "Created record 2 \n"); 364 "Created record 2 \n");
365 s_name_2 = "dummy2"; 365 s_name_2 = "dummy2";
366 s_rd_2 = create_record (1); 366 s_rd_2 = create_record(1);
367 GNUNET_assert (NULL != (ns_ops[1] = 367 GNUNET_assert(NULL != (ns_ops[1] =
368 GNUNET_NAMESTORE_records_store (nsh, 368 GNUNET_NAMESTORE_records_store(nsh,
369 privkey, 369 privkey,
370 s_name_2, 370 s_name_2,
371 1, 371 1,
372 s_rd_2, 372 s_rd_2,
373 &put_cont, 373 &put_cont,
374 (void *) s_name_2))); 374 (void *)s_name_2)));
375} 375}
376 376
377 377
@@ -379,26 +379,26 @@ run (void *cls,
379 379
380 380
381int 381int
382main (int argc, 382main(int argc,
383 char *argv[]) 383 char *argv[])
384{ 384{
385 const char *plugin_name; 385 const char *plugin_name;
386 char *cfg_name; 386 char *cfg_name;
387 387
388 SETUP_CFG (plugin_name, cfg_name); 388 SETUP_CFG(plugin_name, cfg_name);
389 res = 1; 389 res = 1;
390 if (0 != 390 if (0 !=
391 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", 391 GNUNET_TESTING_peer_run("test-namestore-api-monitoring-existing",
392 cfg_name, 392 cfg_name,
393 &run, 393 &run,
394 NULL)) 394 NULL))
395 { 395 {
396 GNUNET_break (0); 396 GNUNET_break(0);
397 res = 1; 397 res = 1;
398 } 398 }
399 GNUNET_DISK_purge_cfg_dir (cfg_name, 399 GNUNET_DISK_purge_cfg_dir(cfg_name,
400 "GNUNET_TEST_HOME"); 400 "GNUNET_TEST_HOME");
401 GNUNET_free (cfg_name); 401 GNUNET_free(cfg_name);
402 return res; 402 return res;
403} 403}
404 404
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c
index 4c3d55efc..b2334667e 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api.c 21 * @file namestore/test_namestore_api.c
22 * @brief testcase for namestore_api.c to: remove record 22 * @brief testcase for namestore_api.c to: remove record
@@ -32,7 +32,7 @@
32 32
33#define TEST_RECORD_DATA 'a' 33#define TEST_RECORD_DATA 'a'
34 34
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
36 36
37 37
38static struct GNUNET_NAMESTORE_Handle *nsh; 38static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -51,19 +51,19 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
51 51
52 52
53static void 53static void
54cleanup () 54cleanup()
55{ 55{
56 if (NULL != nsh) 56 if (NULL != nsh)
57 { 57 {
58 GNUNET_NAMESTORE_disconnect (nsh); 58 GNUNET_NAMESTORE_disconnect(nsh);
59 nsh = NULL; 59 nsh = NULL;
60 } 60 }
61 if (NULL != privkey) 61 if (NULL != privkey)
62 { 62 {
63 GNUNET_free (privkey); 63 GNUNET_free(privkey);
64 privkey = NULL; 64 privkey = NULL;
65 } 65 }
66 GNUNET_SCHEDULER_shutdown (); 66 GNUNET_SCHEDULER_shutdown();
67} 67}
68 68
69 69
@@ -73,127 +73,127 @@ cleanup ()
73 * @param cls handle to use to re-connect. 73 * @param cls handle to use to re-connect.
74 */ 74 */
75static void 75static void
76endbadly (void *cls) 76endbadly(void *cls)
77{ 77{
78 if (NULL != nsqe) 78 if (NULL != nsqe)
79 { 79 {
80 GNUNET_NAMESTORE_cancel (nsqe); 80 GNUNET_NAMESTORE_cancel(nsqe);
81 nsqe = NULL; 81 nsqe = NULL;
82 } 82 }
83 cleanup (); 83 cleanup();
84 res = 1; 84 res = 1;
85} 85}
86 86
87 87
88static void 88static void
89end (void *cls) 89end(void *cls)
90{ 90{
91 cleanup (); 91 cleanup();
92 res = 0; 92 res = 0;
93} 93}
94 94
95 95
96static void 96static void
97remove_cont (void *cls, 97remove_cont(void *cls,
98 int32_t success, 98 int32_t success,
99 const char *emsg) 99 const char *emsg)
100{ 100{
101 nsqe = NULL; 101 nsqe = NULL;
102 if (GNUNET_YES != success) 102 if (GNUNET_YES != success)
103 { 103 {
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 104 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
105 _("Records could not be removed: `%s'\n"), 105 _("Records could not be removed: `%s'\n"),
106 emsg); 106 emsg);
107 if (NULL != endbadly_task) 107 if (NULL != endbadly_task)
108 GNUNET_SCHEDULER_cancel (endbadly_task); 108 GNUNET_SCHEDULER_cancel(endbadly_task);
109 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, 109 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly,
110 NULL); 110 NULL);
111 return; 111 return;
112 } 112 }
113 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 113 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
114 "Records were removed, perform lookup\n"); 114 "Records were removed, perform lookup\n");
115 removed = GNUNET_YES; 115 removed = GNUNET_YES;
116 if (NULL != endbadly_task) 116 if (NULL != endbadly_task)
117 GNUNET_SCHEDULER_cancel (endbadly_task); 117 GNUNET_SCHEDULER_cancel(endbadly_task);
118 GNUNET_SCHEDULER_add_now (&end, NULL); 118 GNUNET_SCHEDULER_add_now(&end, NULL);
119} 119}
120 120
121 121
122static void 122static void
123put_cont (void *cls, 123put_cont(void *cls,
124 int32_t success, 124 int32_t success,
125 const char *emsg) 125 const char *emsg)
126{ 126{
127 const char *name = cls; 127 const char *name = cls;
128 128
129 GNUNET_assert (NULL != cls); 129 GNUNET_assert(NULL != cls);
130 nsqe = NULL; 130 nsqe = NULL;
131 if (GNUNET_SYSERR == success) 131 if (GNUNET_SYSERR == success)
132 { 132 {
133 GNUNET_break (0); 133 GNUNET_break(0);
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 134 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
135 "Namestore could not store record: `%s'\n", 135 "Namestore could not store record: `%s'\n",
136 emsg); 136 emsg);
137 if (endbadly_task != NULL) 137 if (endbadly_task != NULL)
138 GNUNET_SCHEDULER_cancel (endbadly_task); 138 GNUNET_SCHEDULER_cancel(endbadly_task);
139 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 139 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
140 return; 140 return;
141 } 141 }
142 142
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
144 "Name store added record for `%s': %s\n", 144 "Name store added record for `%s': %s\n",
145 name, 145 name,
146 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 146 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
147 nsqe = GNUNET_NAMESTORE_records_store (nsh, 147 nsqe = GNUNET_NAMESTORE_records_store(nsh,
148 privkey, 148 privkey,
149 name, 149 name,
150 0, NULL, 150 0, NULL,
151 &remove_cont, (void *) name); 151 &remove_cont, (void *)name);
152} 152}
153 153
154 154
155static void 155static void
156run (void *cls, 156run(void *cls,
157 const struct GNUNET_CONFIGURATION_Handle *cfg, 157 const struct GNUNET_CONFIGURATION_Handle *cfg,
158 struct GNUNET_TESTING_Peer *peer) 158 struct GNUNET_TESTING_Peer *peer)
159{ 159{
160 struct GNUNET_GNSRECORD_Data rd; 160 struct GNUNET_GNSRECORD_Data rd;
161 const char * name = "dummy.dummy.gnunet"; 161 const char * name = "dummy.dummy.gnunet";
162 162
163 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 163 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
164 &endbadly, 164 &endbadly,
165 NULL); 165 NULL);
166 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 166 privkey = GNUNET_CRYPTO_ecdsa_key_create();
167 GNUNET_assert (privkey != NULL); 167 GNUNET_assert(privkey != NULL);
168 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 168 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
169 &pubkey); 169 &pubkey);
170 170
171 removed = GNUNET_NO; 171 removed = GNUNET_NO;
172 172
173 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 173 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
174 rd.record_type = TEST_RECORD_TYPE; 174 rd.record_type = TEST_RECORD_TYPE;
175 rd.data_size = TEST_RECORD_DATALEN; 175 rd.data_size = TEST_RECORD_DATALEN;
176 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 176 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
177 rd.flags = 0; 177 rd.flags = 0;
178 memset ((char *) rd.data, 178 memset((char *)rd.data,
179 'a', 179 'a',
180 TEST_RECORD_DATALEN); 180 TEST_RECORD_DATALEN);
181 181
182 nsh = GNUNET_NAMESTORE_connect (cfg); 182 nsh = GNUNET_NAMESTORE_connect(cfg);
183 GNUNET_break (NULL != nsh); 183 GNUNET_break(NULL != nsh);
184 nsqe = GNUNET_NAMESTORE_records_store (nsh, 184 nsqe = GNUNET_NAMESTORE_records_store(nsh,
185 privkey, 185 privkey,
186 name, 186 name,
187 1, 187 1,
188 &rd, 188 &rd,
189 &put_cont, 189 &put_cont,
190 (void *) name); 190 (void *)name);
191 if (NULL == nsqe) 191 if (NULL == nsqe)
192 { 192 {
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 193 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
194 _("Namestore cannot store no block\n")); 194 _("Namestore cannot store no block\n"));
195 } 195 }
196 GNUNET_free ((void *)rd.data); 196 GNUNET_free((void *)rd.data);
197} 197}
198 198
199 199
@@ -201,24 +201,24 @@ run (void *cls,
201 201
202 202
203int 203int
204main (int argc, char *argv[]) 204main(int argc, char *argv[])
205{ 205{
206 const char *plugin_name; 206 const char *plugin_name;
207 char *cfg_name; 207 char *cfg_name;
208 208
209 SETUP_CFG (plugin_name, cfg_name); 209 SETUP_CFG(plugin_name, cfg_name);
210 res = 1; 210 res = 1;
211 if (0 != 211 if (0 !=
212 GNUNET_TESTING_peer_run ("test-namestore-api-remove", 212 GNUNET_TESTING_peer_run("test-namestore-api-remove",
213 cfg_name, 213 cfg_name,
214 &run, 214 &run,
215 NULL)) 215 NULL))
216 { 216 {
217 res = 1; 217 res = 1;
218 } 218 }
219 GNUNET_DISK_purge_cfg_dir (cfg_name, 219 GNUNET_DISK_purge_cfg_dir(cfg_name,
220 "GNUNET_TEST_HOME"); 220 "GNUNET_TEST_HOME");
221 GNUNET_free (cfg_name); 221 GNUNET_free(cfg_name);
222 return res; 222 return res;
223} 223}
224 224
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c
index c8110fe6b..fee06e3af 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_remove_not_existing_record.c 21 * @file namestore/test_namestore_api_remove_not_existing_record.c
22 * @brief testcase for namestore_api.c 22 * @brief testcase for namestore_api.c
@@ -31,7 +31,7 @@
31 31
32#define TEST_RECORD_DATA 'a' 32#define TEST_RECORD_DATA 'a'
33 33
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 34#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
35 35
36 36
37static struct GNUNET_NAMESTORE_Handle *nsh; 37static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -48,19 +48,19 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48 48
49 49
50static void 50static void
51cleanup () 51cleanup()
52{ 52{
53 if (NULL != nsh) 53 if (NULL != nsh)
54 { 54 {
55 GNUNET_NAMESTORE_disconnect (nsh); 55 GNUNET_NAMESTORE_disconnect(nsh);
56 nsh = NULL; 56 nsh = NULL;
57 } 57 }
58 if (NULL != privkey) 58 if (NULL != privkey)
59 { 59 {
60 GNUNET_free (privkey); 60 GNUNET_free(privkey);
61 privkey = NULL; 61 privkey = NULL;
62 } 62 }
63 GNUNET_SCHEDULER_shutdown (); 63 GNUNET_SCHEDULER_shutdown();
64} 64}
65 65
66 66
@@ -70,85 +70,87 @@ cleanup ()
70 * @param cls handle to use to re-connect. 70 * @param cls handle to use to re-connect.
71 */ 71 */
72static void 72static void
73endbadly (void *cls) 73endbadly(void *cls)
74{ 74{
75 if (NULL != nsqe) 75 if (NULL != nsqe)
76 { 76 {
77 GNUNET_NAMESTORE_cancel (nsqe); 77 GNUNET_NAMESTORE_cancel(nsqe);
78 nsqe = NULL; 78 nsqe = NULL;
79 } 79 }
80 cleanup (); 80 cleanup();
81 res = 1; 81 res = 1;
82} 82}
83 83
84 84
85static void 85static void
86end (void *cls) 86end(void *cls)
87{ 87{
88 cleanup (); 88 cleanup();
89 res = 0; 89 res = 0;
90} 90}
91 91
92 92
93static void 93static void
94put_cont (void *cls, 94put_cont(void *cls,
95 int32_t success, 95 int32_t success,
96 const char *emsg) 96 const char *emsg)
97{ 97{
98 GNUNET_assert (NULL != cls); 98 GNUNET_assert(NULL != cls);
99 nsqe = NULL; 99 nsqe = NULL;
100 if (endbadly_task != NULL) 100 if (endbadly_task != NULL)
101 { 101 {
102 GNUNET_SCHEDULER_cancel (endbadly_task); 102 GNUNET_SCHEDULER_cancel(endbadly_task);
103 endbadly_task = NULL; 103 endbadly_task = NULL;
104 } 104 }
105 switch (success) 105 switch (success)
106 { 106 {
107 case GNUNET_NO: 107 case GNUNET_NO:
108 /* We expected GNUNET_NO, since record was not found */ 108 /* We expected GNUNET_NO, since record was not found */
109 GNUNET_SCHEDULER_add_now (&end, NULL); 109 GNUNET_SCHEDULER_add_now(&end, NULL);
110 break; 110 break;
111
111 case GNUNET_OK: 112 case GNUNET_OK:
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 113 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
113 "Namestore could remove non-existing record: `%s'\n", 114 "Namestore could remove non-existing record: `%s'\n",
114 (NULL !=emsg) ? emsg : ""); 115 (NULL != emsg) ? emsg : "");
115 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 116 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
116 break; 117 break;
118
117 case GNUNET_SYSERR: 119 case GNUNET_SYSERR:
118 default: 120 default:
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 121 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
120 "Namestore failed: `%s'\n", 122 "Namestore failed: `%s'\n",
121 (NULL !=emsg) ? emsg : ""); 123 (NULL != emsg) ? emsg : "");
122 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 124 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
123 break; 125 break;
124 } 126 }
125} 127}
126 128
127 129
128static void 130static void
129run (void *cls, 131run(void *cls,
130 const struct GNUNET_CONFIGURATION_Handle *cfg, 132 const struct GNUNET_CONFIGURATION_Handle *cfg,
131 struct GNUNET_TESTING_Peer *peer) 133 struct GNUNET_TESTING_Peer *peer)
132{ 134{
133 const char * name = "dummy.dummy.gnunet"; 135 const char * name = "dummy.dummy.gnunet";
134 136
135 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 137 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
136 &endbadly, 138 &endbadly,
137 NULL); 139 NULL);
138 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 140 privkey = GNUNET_CRYPTO_ecdsa_key_create();
139 GNUNET_assert (privkey != NULL); 141 GNUNET_assert(privkey != NULL);
140 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 142 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
141 143
142 nsh = GNUNET_NAMESTORE_connect (cfg); 144 nsh = GNUNET_NAMESTORE_connect(cfg);
143 GNUNET_break (NULL != nsh); 145 GNUNET_break(NULL != nsh);
144 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 146 nsqe = GNUNET_NAMESTORE_records_store(nsh, privkey, name,
145 0, NULL, 147 0, NULL,
146 &put_cont, (void *) name); 148 &put_cont, (void *)name);
147 if (NULL == nsqe) 149 if (NULL == nsqe)
148 { 150 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 151 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
150 _("Namestore cannot store no block\n")); 152 _("Namestore cannot store no block\n"));
151 } 153 }
152} 154}
153 155
154 156
@@ -156,24 +158,24 @@ run (void *cls,
156 158
157 159
158int 160int
159main (int argc, char *argv[]) 161main(int argc, char *argv[])
160{ 162{
161 const char *plugin_name; 163 const char *plugin_name;
162 char *cfg_name; 164 char *cfg_name;
163 165
164 SETUP_CFG (plugin_name, cfg_name); 166 SETUP_CFG(plugin_name, cfg_name);
165 res = 1; 167 res = 1;
166 if (0 != 168 if (0 !=
167 GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", 169 GNUNET_TESTING_peer_run("test-namestore-api-remove-non-existing-record",
168 cfg_name, 170 cfg_name,
169 &run, 171 &run,
170 NULL)) 172 NULL))
171 { 173 {
172 res = 1; 174 res = 1;
173 } 175 }
174 GNUNET_DISK_purge_cfg_dir (cfg_name, 176 GNUNET_DISK_purge_cfg_dir(cfg_name,
175 "GNUNET_TEST_HOME"); 177 "GNUNET_TEST_HOME");
176 GNUNET_free (cfg_name); 178 GNUNET_free(cfg_name);
177 return res; 179 return res;
178} 180}
179 181
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c
index 0dbad8ce3..622227471 100644
--- a/src/namestore/test_namestore_api_store.c
+++ b/src/namestore/test_namestore_api_store.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_store.c 21 * @file namestore/test_namestore_api_store.c
22 * @brief testcase for namestore_api.c: store a record 22 * @brief testcase for namestore_api.c: store a record
@@ -32,7 +32,7 @@
32 32
33#define TEST_RECORD_DATA 'a' 33#define TEST_RECORD_DATA 'a'
34 34
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
36 36
37 37
38static struct GNUNET_NAMESTORE_Handle *nsh; 38static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -49,19 +49,19 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
49 49
50 50
51static void 51static void
52cleanup () 52cleanup()
53{ 53{
54 if (NULL != nsh) 54 if (NULL != nsh)
55 { 55 {
56 GNUNET_NAMESTORE_disconnect (nsh); 56 GNUNET_NAMESTORE_disconnect(nsh);
57 nsh = NULL; 57 nsh = NULL;
58 } 58 }
59 if (NULL != privkey) 59 if (NULL != privkey)
60 { 60 {
61 GNUNET_free (privkey); 61 GNUNET_free(privkey);
62 privkey = NULL; 62 privkey = NULL;
63 } 63 }
64 GNUNET_SCHEDULER_shutdown (); 64 GNUNET_SCHEDULER_shutdown();
65} 65}
66 66
67 67
@@ -71,80 +71,80 @@ cleanup ()
71 * @param cls handle to use to re-connect. 71 * @param cls handle to use to re-connect.
72 */ 72 */
73static void 73static void
74endbadly (void *cls) 74endbadly(void *cls)
75{ 75{
76 if (NULL != nsqe) 76 if (NULL != nsqe)
77 { 77 {
78 GNUNET_NAMESTORE_cancel (nsqe); 78 GNUNET_NAMESTORE_cancel(nsqe);
79 nsqe = NULL; 79 nsqe = NULL;
80 } 80 }
81 cleanup (); 81 cleanup();
82 res = 1; 82 res = 1;
83} 83}
84 84
85 85
86static void 86static void
87end (void *cls) 87end(void *cls)
88{ 88{
89 cleanup (); 89 cleanup();
90 res = 0; 90 res = 0;
91} 91}
92 92
93 93
94static void 94static void
95put_cont (void *cls, int32_t success, const char *emsg) 95put_cont(void *cls, int32_t success, const char *emsg)
96{ 96{
97 const char *name = cls; 97 const char *name = cls;
98 98
99 nsqe = NULL; 99 nsqe = NULL;
100 GNUNET_assert (NULL != cls); 100 GNUNET_assert(NULL != cls);
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 101 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
102 "Name store added record for `%s': %s\n", 102 "Name store added record for `%s': %s\n",
103 name, 103 name,
104 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 104 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
105 GNUNET_SCHEDULER_cancel (endbadly_task); 105 GNUNET_SCHEDULER_cancel(endbadly_task);
106 endbadly_task = NULL; 106 endbadly_task = NULL;
107 GNUNET_SCHEDULER_add_now (&end, NULL); 107 GNUNET_SCHEDULER_add_now(&end, NULL);
108} 108}
109 109
110 110
111static void 111static void
112run (void *cls, 112run(void *cls,
113 const struct GNUNET_CONFIGURATION_Handle *cfg, 113 const struct GNUNET_CONFIGURATION_Handle *cfg,
114 struct GNUNET_TESTING_Peer *peer) 114 struct GNUNET_TESTING_Peer *peer)
115{ 115{
116 struct GNUNET_GNSRECORD_Data rd; 116 struct GNUNET_GNSRECORD_Data rd;
117 const char * name = "dummy.dummy.gnunet"; 117 const char * name = "dummy.dummy.gnunet";
118 118
119 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 119 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
120 &endbadly, NULL); 120 &endbadly, NULL);
121 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 121 privkey = GNUNET_CRYPTO_ecdsa_key_create();
122 GNUNET_assert (privkey != NULL); 122 GNUNET_assert(privkey != NULL);
123 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 123 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
124 124
125 125
126 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 126 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
127 rd.record_type = TEST_RECORD_TYPE; 127 rd.record_type = TEST_RECORD_TYPE;
128 rd.data_size = TEST_RECORD_DATALEN; 128 rd.data_size = TEST_RECORD_DATALEN;
129 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 129 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
130 rd.flags = 0; 130 rd.flags = 0;
131 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 131 memset((char *)rd.data, 'a', TEST_RECORD_DATALEN);
132 132
133 nsh = GNUNET_NAMESTORE_connect (cfg); 133 nsh = GNUNET_NAMESTORE_connect(cfg);
134 GNUNET_break (NULL != nsh); 134 GNUNET_break(NULL != nsh);
135 nsqe = GNUNET_NAMESTORE_records_store (nsh, 135 nsqe = GNUNET_NAMESTORE_records_store(nsh,
136 privkey, 136 privkey,
137 name, 137 name,
138 1, 138 1,
139 &rd, 139 &rd,
140 &put_cont, 140 &put_cont,
141 (void *) name); 141 (void *)name);
142 if (NULL == nsqe) 142 if (NULL == nsqe)
143 { 143 {
144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 144 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
145 _("Namestore cannot store no block\n")); 145 _("Namestore cannot store no block\n"));
146 } 146 }
147 GNUNET_free ((void *)rd.data); 147 GNUNET_free((void *)rd.data);
148} 148}
149 149
150 150
@@ -152,24 +152,24 @@ run (void *cls,
152 152
153 153
154int 154int
155main (int argc, char *argv[]) 155main(int argc, char *argv[])
156{ 156{
157 const char *plugin_name; 157 const char *plugin_name;
158 char *cfg_name; 158 char *cfg_name;
159 159
160 SETUP_CFG (plugin_name, cfg_name); 160 SETUP_CFG(plugin_name, cfg_name);
161 res = 1; 161 res = 1;
162 if (0 != 162 if (0 !=
163 GNUNET_TESTING_peer_run ("test-namestore-api", 163 GNUNET_TESTING_peer_run("test-namestore-api",
164 cfg_name, 164 cfg_name,
165 &run, 165 &run,
166 NULL)) 166 NULL))
167 { 167 {
168 res = 1; 168 res = 1;
169 } 169 }
170 GNUNET_DISK_purge_cfg_dir (cfg_name, 170 GNUNET_DISK_purge_cfg_dir(cfg_name,
171 "GNUNET_TEST_HOME"); 171 "GNUNET_TEST_HOME");
172 GNUNET_free (cfg_name); 172 GNUNET_free(cfg_name);
173 return res; 173 return res;
174} 174}
175 175
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c
index b1c0770ae..5e9885b3e 100644
--- a/src/namestore/test_namestore_api_store_update.c
+++ b/src/namestore/test_namestore_api_store_update.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_store_update.c 21 * @file namestore/test_namestore_api_store_update.c
22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup 22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup
@@ -39,7 +39,7 @@
39 39
40#define TEST_RECORD_DATA2 'b' 40#define TEST_RECORD_DATA2 'b'
41 41
42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 42#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
43 43
44 44
45static struct GNUNET_NAMESTORE_Handle *nsh; 45static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -69,217 +69,217 @@ static const char *name = "dummy";
69 * @param cls handle to use to re-connect. 69 * @param cls handle to use to re-connect.
70 */ 70 */
71static void 71static void
72endbadly (void *cls) 72endbadly(void *cls)
73{ 73{
74 GNUNET_break (0); 74 GNUNET_break(0);
75 endbadly_task = NULL; 75 endbadly_task = NULL;
76 GNUNET_SCHEDULER_shutdown (); 76 GNUNET_SCHEDULER_shutdown();
77 res = 1; 77 res = 1;
78} 78}
79 79
80 80
81static void 81static void
82end (void *cls) 82end(void *cls)
83{ 83{
84 if (NULL != endbadly_task) 84 if (NULL != endbadly_task)
85 { 85 {
86 GNUNET_SCHEDULER_cancel (endbadly_task); 86 GNUNET_SCHEDULER_cancel(endbadly_task);
87 endbadly_task = NULL; 87 endbadly_task = NULL;
88 } 88 }
89 if (NULL != nsqe) 89 if (NULL != nsqe)
90 { 90 {
91 GNUNET_NAMESTORE_cancel (nsqe); 91 GNUNET_NAMESTORE_cancel(nsqe);
92 nsqe = NULL; 92 nsqe = NULL;
93 } 93 }
94 if (NULL != ncqe) 94 if (NULL != ncqe)
95 { 95 {
96 GNUNET_NAMECACHE_cancel (ncqe); 96 GNUNET_NAMECACHE_cancel(ncqe);
97 ncqe = NULL; 97 ncqe = NULL;
98 } 98 }
99 if (NULL != nsh) 99 if (NULL != nsh)
100 { 100 {
101 GNUNET_NAMESTORE_disconnect (nsh); 101 GNUNET_NAMESTORE_disconnect(nsh);
102 nsh = NULL; 102 nsh = NULL;
103 } 103 }
104 if (NULL != nch) 104 if (NULL != nch)
105 { 105 {
106 GNUNET_NAMECACHE_disconnect (nch); 106 GNUNET_NAMECACHE_disconnect(nch);
107 nch = NULL; 107 nch = NULL;
108 } 108 }
109 if (NULL != privkey) 109 if (NULL != privkey)
110 { 110 {
111 GNUNET_free (privkey); 111 GNUNET_free(privkey);
112 privkey = NULL; 112 privkey = NULL;
113 } 113 }
114} 114}
115 115
116 116
117static void 117static void
118put_cont (void *cls, 118put_cont(void *cls,
119 int32_t success, 119 int32_t success,
120 const char *emsg); 120 const char *emsg);
121 121
122 122
123static void 123static void
124rd_decrypt_cb (void *cls, 124rd_decrypt_cb(void *cls,
125 unsigned int rd_count, 125 unsigned int rd_count,
126 const struct GNUNET_GNSRECORD_Data *rd) 126 const struct GNUNET_GNSRECORD_Data *rd)
127{ 127{
128 struct GNUNET_GNSRECORD_Data rd_new; 128 struct GNUNET_GNSRECORD_Data rd_new;
129 129
130 GNUNET_assert (1 == rd_count); 130 GNUNET_assert(1 == rd_count);
131 GNUNET_assert (NULL != rd); 131 GNUNET_assert(NULL != rd);
132 132
133 if (GNUNET_NO == update_performed) 133 if (GNUNET_NO == update_performed)
134 { 134 {
135 char rd_cmp_data[TEST_RECORD_DATALEN]; 135 char rd_cmp_data[TEST_RECORD_DATALEN];
136 136
137 memset (rd_cmp_data, 137 memset(rd_cmp_data,
138 TEST_RECORD_DATA, 138 TEST_RECORD_DATA,
139 TEST_RECORD_DATALEN); 139 TEST_RECORD_DATALEN);
140 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 140 GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type);
141 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); 141 GNUNET_assert(TEST_RECORD_DATALEN == rd[0].data_size);
142 GNUNET_assert (0 == memcmp (&rd_cmp_data, 142 GNUNET_assert(0 == memcmp(&rd_cmp_data,
143 rd[0].data, 143 rd[0].data,
144 TEST_RECORD_DATALEN)); 144 TEST_RECORD_DATALEN));
145 145
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 146 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
147 "Block was decrypted successfully, updating record \n"); 147 "Block was decrypted successfully, updating record \n");
148 148
149 rd_new.flags = GNUNET_GNSRECORD_RF_NONE; 149 rd_new.flags = GNUNET_GNSRECORD_RF_NONE;
150 rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 150 rd_new.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
151 rd_new.record_type = TEST_RECORD_TYPE; 151 rd_new.record_type = TEST_RECORD_TYPE;
152 rd_new.data_size = TEST_RECORD_DATALEN2; 152 rd_new.data_size = TEST_RECORD_DATALEN2;
153 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); 153 rd_new.data = GNUNET_malloc(TEST_RECORD_DATALEN2);
154 memset ((char *) rd_new.data, 154 memset((char *)rd_new.data,
155 TEST_RECORD_DATA2, 155 TEST_RECORD_DATA2,
156 TEST_RECORD_DATALEN2); 156 TEST_RECORD_DATALEN2);
157 157
158 nsqe = GNUNET_NAMESTORE_records_store (nsh, 158 nsqe = GNUNET_NAMESTORE_records_store(nsh,
159 privkey, 159 privkey,
160 name, 160 name,
161 1, 161 1,
162 &rd_new, 162 &rd_new,
163 &put_cont, 163 &put_cont,
164 (void *) name); 164 (void *)name);
165 update_performed = GNUNET_YES; 165 update_performed = GNUNET_YES;
166 } 166 }
167 else 167 else
168 { 168 {
169 char rd_cmp_data[TEST_RECORD_DATALEN2]; 169 char rd_cmp_data[TEST_RECORD_DATALEN2];
170 170
171 memset (rd_cmp_data, 171 memset(rd_cmp_data,
172 TEST_RECORD_DATA2, 172 TEST_RECORD_DATA2,
173 TEST_RECORD_DATALEN2); 173 TEST_RECORD_DATALEN2);
174 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 174 GNUNET_assert(TEST_RECORD_TYPE == rd[0].record_type);
175 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); 175 GNUNET_assert(TEST_RECORD_DATALEN2 == rd[0].data_size);
176 GNUNET_assert (0 == memcmp (&rd_cmp_data, 176 GNUNET_assert(0 == memcmp(&rd_cmp_data,
177 rd[0].data, 177 rd[0].data,
178 TEST_RECORD_DATALEN2)); 178 TEST_RECORD_DATALEN2));
179 GNUNET_SCHEDULER_shutdown (); 179 GNUNET_SCHEDULER_shutdown();
180 res = 0; 180 res = 0;
181 } 181 }
182} 182}
183 183
184 184
185static void 185static void
186name_lookup_proc (void *cls, 186name_lookup_proc(void *cls,
187 const struct GNUNET_GNSRECORD_Block *block) 187 const struct GNUNET_GNSRECORD_Block *block)
188{ 188{
189 const char *name = cls; 189 const char *name = cls;
190 190
191 ncqe = NULL; 191 ncqe = NULL;
192 GNUNET_assert (NULL != cls); 192 GNUNET_assert(NULL != cls);
193 if (NULL == block) 193 if (NULL == block)
194 { 194 {
195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 195 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
196 _("Namecache returned no block for `%s'\n"), 196 _("Namecache returned no block for `%s'\n"),
197 name); 197 name);
198 GNUNET_SCHEDULER_shutdown (); 198 GNUNET_SCHEDULER_shutdown();
199 return; 199 return;
200 } 200 }
201 201
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
203 "Namecache returned block, decrypting \n"); 203 "Namecache returned block, decrypting \n");
204 GNUNET_assert (GNUNET_OK == 204 GNUNET_assert(GNUNET_OK ==
205 GNUNET_GNSRECORD_block_decrypt (block, 205 GNUNET_GNSRECORD_block_decrypt(block,
206 &pubkey, 206 &pubkey,
207 name, 207 name,
208 &rd_decrypt_cb, 208 &rd_decrypt_cb,
209 (void *) name)); 209 (void *)name));
210} 210}
211 211
212 212
213static void 213static void
214put_cont (void *cls, 214put_cont(void *cls,
215 int32_t success, 215 int32_t success,
216 const char *emsg) 216 const char *emsg)
217{ 217{
218 const char *name = cls; 218 const char *name = cls;
219 struct GNUNET_HashCode derived_hash; 219 struct GNUNET_HashCode derived_hash;
220 220
221 nsqe = NULL; 221 nsqe = NULL;
222 GNUNET_assert (NULL != cls); 222 GNUNET_assert(NULL != cls);
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 223 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
224 "Name store added record for `%s': %s\n", 224 "Name store added record for `%s': %s\n",
225 name, 225 name,
226 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 226 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
227 /* Create derived hash */ 227 /* Create derived hash */
228 GNUNET_GNSRECORD_query_from_private_key (privkey, 228 GNUNET_GNSRECORD_query_from_private_key(privkey,
229 name, 229 name,
230 &derived_hash); 230 &derived_hash);
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 231 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
232 "Looking in namecache for `%s'\n", 232 "Looking in namecache for `%s'\n",
233 GNUNET_h2s (&derived_hash)); 233 GNUNET_h2s(&derived_hash));
234 ncqe = GNUNET_NAMECACHE_lookup_block (nch, 234 ncqe = GNUNET_NAMECACHE_lookup_block(nch,
235 &derived_hash, 235 &derived_hash,
236 &name_lookup_proc, (void *) name); 236 &name_lookup_proc, (void *)name);
237} 237}
238 238
239 239
240static void 240static void
241run (void *cls, 241run(void *cls,
242 const struct GNUNET_CONFIGURATION_Handle *cfg, 242 const struct GNUNET_CONFIGURATION_Handle *cfg,
243 struct GNUNET_TESTING_Peer *peer) 243 struct GNUNET_TESTING_Peer *peer)
244{ 244{
245 struct GNUNET_GNSRECORD_Data rd; 245 struct GNUNET_GNSRECORD_Data rd;
246 246
247 update_performed = GNUNET_NO; 247 update_performed = GNUNET_NO;
248 GNUNET_SCHEDULER_add_shutdown (&end, 248 GNUNET_SCHEDULER_add_shutdown(&end,
249 NULL); 249 NULL);
250 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 250 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
251 &endbadly, 251 &endbadly,
252 NULL); 252 NULL);
253 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 253 privkey = GNUNET_CRYPTO_ecdsa_key_create();
254 GNUNET_assert (privkey != NULL); 254 GNUNET_assert(privkey != NULL);
255 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 255 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
256 &pubkey); 256 &pubkey);
257 rd.flags = GNUNET_GNSRECORD_RF_NONE; 257 rd.flags = GNUNET_GNSRECORD_RF_NONE;
258 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 258 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
259 rd.record_type = TEST_RECORD_TYPE; 259 rd.record_type = TEST_RECORD_TYPE;
260 rd.data_size = TEST_RECORD_DATALEN; 260 rd.data_size = TEST_RECORD_DATALEN;
261 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 261 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
262 memset ((char *) rd.data, 262 memset((char *)rd.data,
263 TEST_RECORD_DATA, 263 TEST_RECORD_DATA,
264 TEST_RECORD_DATALEN); 264 TEST_RECORD_DATALEN);
265 265
266 nsh = GNUNET_NAMESTORE_connect (cfg); 266 nsh = GNUNET_NAMESTORE_connect(cfg);
267 GNUNET_break (NULL != nsh); 267 GNUNET_break(NULL != nsh);
268 nch = GNUNET_NAMECACHE_connect (cfg); 268 nch = GNUNET_NAMECACHE_connect(cfg);
269 GNUNET_break (NULL != nch); 269 GNUNET_break(NULL != nch);
270 nsqe = GNUNET_NAMESTORE_records_store (nsh, 270 nsqe = GNUNET_NAMESTORE_records_store(nsh,
271 privkey, 271 privkey,
272 name, 272 name,
273 1, 273 1,
274 &rd, 274 &rd,
275 &put_cont, 275 &put_cont,
276 (void *) name); 276 (void *)name);
277 if (NULL == nsqe) 277 if (NULL == nsqe)
278 { 278 {
279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 279 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
280 _("Namestore cannot store no block\n")); 280 _("Namestore cannot store no block\n"));
281 } 281 }
282 GNUNET_free ((void *)rd.data); 282 GNUNET_free((void *)rd.data);
283} 283}
284 284
285 285
@@ -287,25 +287,25 @@ run (void *cls,
287 287
288 288
289int 289int
290main (int argc, 290main(int argc,
291 char *argv[]) 291 char *argv[])
292{ 292{
293 const char *plugin_name; 293 const char *plugin_name;
294 char *cfg_name; 294 char *cfg_name;
295 295
296 SETUP_CFG (plugin_name, cfg_name); 296 SETUP_CFG(plugin_name, cfg_name);
297 res = 1; 297 res = 1;
298 if (0 != 298 if (0 !=
299 GNUNET_TESTING_peer_run ("test-namestore-api-store-update", 299 GNUNET_TESTING_peer_run("test-namestore-api-store-update",
300 cfg_name, 300 cfg_name,
301 &run, 301 &run,
302 NULL)) 302 NULL))
303 { 303 {
304 res = 1; 304 res = 1;
305 } 305 }
306 GNUNET_DISK_purge_cfg_dir (cfg_name, 306 GNUNET_DISK_purge_cfg_dir(cfg_name,
307 "GNUNET_TEST_HOME"); 307 "GNUNET_TEST_HOME");
308 GNUNET_free (cfg_name); 308 GNUNET_free(cfg_name);
309 return res; 309 return res;
310} 310}
311 311
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 94331f89e..62686403a 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_zone_iteration.c 21 * @file namestore/test_namestore_api_zone_iteration.c
22 * @brief testcase for zone iteration functionality: iterate all zones 22 * @brief testcase for zone iteration functionality: iterate all zones
@@ -30,7 +30,7 @@
30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT 30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
31 31
32 32
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 33#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
34 34
35 35
36static struct GNUNET_NAMESTORE_Handle * nsh; 36static struct GNUNET_NAMESTORE_Handle * nsh;
@@ -67,268 +67,268 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
67 * @param tc scheduler context 67 * @param tc scheduler context
68 */ 68 */
69static void 69static void
70endbadly (void *cls) 70endbadly(void *cls)
71{ 71{
72 endbadly_task = NULL; 72 endbadly_task = NULL;
73 GNUNET_SCHEDULER_shutdown (); 73 GNUNET_SCHEDULER_shutdown();
74 res = 1; 74 res = 1;
75} 75}
76 76
77 77
78static void 78static void
79end (void *cls) 79end(void *cls)
80{ 80{
81 if (NULL != zi) 81 if (NULL != zi)
82 { 82 {
83 GNUNET_NAMESTORE_zone_iteration_stop (zi); 83 GNUNET_NAMESTORE_zone_iteration_stop(zi);
84 zi = NULL; 84 zi = NULL;
85 } 85 }
86 if (NULL != endbadly_task) 86 if (NULL != endbadly_task)
87 { 87 {
88 GNUNET_SCHEDULER_cancel (endbadly_task); 88 GNUNET_SCHEDULER_cancel(endbadly_task);
89 endbadly_task = NULL; 89 endbadly_task = NULL;
90 } 90 }
91 if (NULL != privkey) 91 if (NULL != privkey)
92 { 92 {
93 GNUNET_free (privkey); 93 GNUNET_free(privkey);
94 privkey = NULL; 94 privkey = NULL;
95 } 95 }
96 if (NULL != privkey2) 96 if (NULL != privkey2)
97 { 97 {
98 GNUNET_free (privkey2); 98 GNUNET_free(privkey2);
99 privkey2 = NULL; 99 privkey2 = NULL;
100 } 100 }
101 GNUNET_free_non_null (s_name_1); 101 GNUNET_free_non_null(s_name_1);
102 GNUNET_free_non_null (s_name_2); 102 GNUNET_free_non_null(s_name_2);
103 GNUNET_free_non_null (s_name_3); 103 GNUNET_free_non_null(s_name_3);
104 if (NULL != s_rd_1) 104 if (NULL != s_rd_1)
105 { 105 {
106 GNUNET_free ((void *)s_rd_1->data); 106 GNUNET_free((void *)s_rd_1->data);
107 GNUNET_free (s_rd_1); 107 GNUNET_free(s_rd_1);
108 } 108 }
109 if (NULL != s_rd_2) 109 if (NULL != s_rd_2)
110 { 110 {
111 GNUNET_free ((void *)s_rd_2->data); 111 GNUNET_free((void *)s_rd_2->data);
112 GNUNET_free (s_rd_2); 112 GNUNET_free(s_rd_2);
113 } 113 }
114 if (NULL != s_rd_3) 114 if (NULL != s_rd_3)
115 { 115 {
116 GNUNET_free ((void *)s_rd_3->data); 116 GNUNET_free((void *)s_rd_3->data);
117 GNUNET_free (s_rd_3); 117 GNUNET_free(s_rd_3);
118 } 118 }
119 if (NULL != nsh) 119 if (NULL != nsh)
120 { 120 {
121 GNUNET_NAMESTORE_disconnect (nsh); 121 GNUNET_NAMESTORE_disconnect(nsh);
122 nsh = NULL; 122 nsh = NULL;
123 } 123 }
124} 124}
125 125
126 126
127static void 127static void
128zone_end (void *cls) 128zone_end(void *cls)
129{ 129{
130 GNUNET_break (3 == returned_records); 130 GNUNET_break(3 == returned_records);
131 if (3 == returned_records) 131 if (3 == returned_records)
132 { 132 {
133 res = 0; /* Last iteraterator callback, we are done */ 133 res = 0; /* Last iteraterator callback, we are done */
134 zi = NULL; 134 zi = NULL;
135 } 135 }
136 else 136 else
137 res = 1; 137 res = 1;
138 138
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
140 "Received last result, iteration done after receing %u results\n", 140 "Received last result, iteration done after receing %u results\n",
141 returned_records); 141 returned_records);
142 GNUNET_SCHEDULER_shutdown (); 142 GNUNET_SCHEDULER_shutdown();
143} 143}
144 144
145 145
146static void 146static void
147fail_cb (void *cls) 147fail_cb(void *cls)
148{ 148{
149 GNUNET_assert (0); 149 GNUNET_assert(0);
150} 150}
151 151
152 152
153static void 153static void
154zone_proc (void *cls, 154zone_proc(void *cls,
155 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 155 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
156 const char *label, 156 const char *label,
157 unsigned int rd_count, 157 unsigned int rd_count,
158 const struct GNUNET_GNSRECORD_Data *rd) 158 const struct GNUNET_GNSRECORD_Data *rd)
159{ 159{
160 int failed = GNUNET_NO; 160 int failed = GNUNET_NO;
161 161
162 GNUNET_assert (NULL != zone); 162 GNUNET_assert(NULL != zone);
163 if (0 == GNUNET_memcmp (zone, 163 if (0 == GNUNET_memcmp(zone,
164 privkey)) 164 privkey))
165 {
166 if (0 == strcmp (label, s_name_1))
167 { 165 {
168 if (rd_count == 1) 166 if (0 == strcmp(label, s_name_1))
169 {
170 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1))
171 { 167 {
172 failed = GNUNET_YES; 168 if (rd_count == 1)
173 GNUNET_break (0); 169 {
170 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1))
171 {
172 failed = GNUNET_YES;
173 GNUNET_break(0);
174 }
175 }
176 else
177 {
178 failed = GNUNET_YES;
179 GNUNET_break(0);
180 }
181 }
182 else if (0 == strcmp(label, s_name_2))
183 {
184 if (rd_count == 1)
185 {
186 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
187 {
188 failed = GNUNET_YES;
189 GNUNET_break(0);
190 }
191 }
192 else
193 {
194 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
195 "Received invalid record count\n");
196 failed = GNUNET_YES;
197 GNUNET_break(0);
198 }
174 } 199 }
175 }
176 else 200 else
177 {
178 failed = GNUNET_YES;
179 GNUNET_break (0);
180 }
181 }
182 else if (0 == strcmp (label, s_name_2))
183 {
184 if (rd_count == 1)
185 {
186 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
187 { 201 {
202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
203 "Comparing result failed: got name `%s' for first zone\n",
204 label);
188 failed = GNUNET_YES; 205 failed = GNUNET_YES;
189 GNUNET_break (0); 206 GNUNET_break(0);
190 } 207 }
191 }
192 else
193 {
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 "Received invalid record count\n");
196 failed = GNUNET_YES;
197 GNUNET_break (0);
198 }
199 } 208 }
200 else 209 else if (0 == GNUNET_memcmp(zone,
210 privkey2))
201 { 211 {
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 212 if (0 == strcmp(label, s_name_3))
203 "Comparing result failed: got name `%s' for first zone\n",
204 label);
205 failed = GNUNET_YES;
206 GNUNET_break (0);
207 }
208 }
209 else if (0 == GNUNET_memcmp (zone,
210 privkey2))
211 {
212 if (0 == strcmp (label, s_name_3))
213 {
214 if (rd_count == 1)
215 {
216 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3))
217 { 213 {
218 failed = GNUNET_YES; 214 if (rd_count == 1)
219 GNUNET_break (0); 215 {
216 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3))
217 {
218 failed = GNUNET_YES;
219 GNUNET_break(0);
220 }
221 }
222 else
223 {
224 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
225 "Received invalid record count\n");
226 failed = GNUNET_YES;
227 GNUNET_break(0);
228 }
220 } 229 }
221 }
222 else 230 else
223 { 231 {
224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 232 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
225 "Received invalid record count\n"); 233 "Comparing result failed: got name `%s' for first zone\n",
226 failed = GNUNET_YES; 234 label);
227 GNUNET_break (0); 235 failed = GNUNET_YES;
228 } 236 GNUNET_break(0);
237 }
229 } 238 }
230 else 239 else
231 { 240 {
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
233 "Comparing result failed: got name `%s' for first zone\n", 242 "Received invalid zone\n");
234 label);
235 failed = GNUNET_YES; 243 failed = GNUNET_YES;
236 GNUNET_break (0); 244 GNUNET_break(0);
237 } 245 }
238 }
239 else
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
242 "Received invalid zone\n");
243 failed = GNUNET_YES;
244 GNUNET_break (0);
245 }
246 246
247 if (failed == GNUNET_NO) 247 if (failed == GNUNET_NO)
248 { 248 {
249 returned_records ++; 249 returned_records++;
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 250 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
251 "Telling namestore to send the next result\n"); 251 "Telling namestore to send the next result\n");
252 GNUNET_NAMESTORE_zone_iterator_next (zi, 252 GNUNET_NAMESTORE_zone_iterator_next(zi,
253 1); 253 1);
254 } 254 }
255 else 255 else
256 { 256 {
257 GNUNET_break (0); 257 GNUNET_break(0);
258 GNUNET_SCHEDULER_shutdown (); 258 GNUNET_SCHEDULER_shutdown();
259 res = 1; 259 res = 1;
260 } 260 }
261} 261}
262 262
263 263
264static void 264static void
265put_cont (void *cls, 265put_cont(void *cls,
266 int32_t success, 266 int32_t success,
267 const char *emsg) 267 const char *emsg)
268{ 268{
269 static int c = 0; 269 static int c = 0;
270 270
271 if (success == GNUNET_OK) 271 if (success == GNUNET_OK)
272 { 272 {
273 c++; 273 c++;
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 274 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
275 "Created record %u \n", 275 "Created record %u \n",
276 c); 276 c);
277 } 277 }
278 else 278 else
279 { 279 {
280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 280 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
281 "Failed to created records: `%s'\n", 281 "Failed to created records: `%s'\n",
282 emsg); 282 emsg);
283 GNUNET_break (0); 283 GNUNET_break(0);
284 GNUNET_SCHEDULER_shutdown (); 284 GNUNET_SCHEDULER_shutdown();
285 res = 1; 285 res = 1;
286 return; 286 return;
287 } 287 }
288 288
289 if (c == 3) 289 if (c == 3)
290 {
291 res = 1;
292 returned_records = 0;
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "All records created, starting iteration over all zones \n");
295 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
296 NULL,
297 &fail_cb,
298 NULL,
299 &zone_proc,
300 NULL,
301 &zone_end,
302 NULL);
303 if (zi == NULL)
304 { 290 {
305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
306 "Failed to create zone iterator\n");
307 GNUNET_break (0);
308 GNUNET_SCHEDULER_shutdown ();
309 res = 1; 291 res = 1;
310 return; 292 returned_records = 0;
293 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
294 "All records created, starting iteration over all zones \n");
295 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
296 NULL,
297 &fail_cb,
298 NULL,
299 &zone_proc,
300 NULL,
301 &zone_end,
302 NULL);
303 if (zi == NULL)
304 {
305 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
306 "Failed to create zone iterator\n");
307 GNUNET_break(0);
308 GNUNET_SCHEDULER_shutdown();
309 res = 1;
310 return;
311 }
311 } 312 }
312 }
313} 313}
314 314
315 315
316static struct GNUNET_GNSRECORD_Data * 316static struct GNUNET_GNSRECORD_Data *
317create_record (unsigned int count) 317create_record(unsigned int count)
318{ 318{
319 struct GNUNET_GNSRECORD_Data * rd; 319 struct GNUNET_GNSRECORD_Data * rd;
320 320
321 rd = GNUNET_new_array (count, 321 rd = GNUNET_new_array(count,
322 struct GNUNET_GNSRECORD_Data); 322 struct GNUNET_GNSRECORD_Data);
323 for (unsigned int c = 0; c < count; c++) 323 for (unsigned int c = 0; c < count; c++)
324 { 324 {
325 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 325 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us;
326 rd[c].record_type = TEST_RECORD_TYPE; 326 rd[c].record_type = TEST_RECORD_TYPE;
327 rd[c].data_size = 50; 327 rd[c].data_size = 50;
328 rd[c].data = GNUNET_malloc(50); 328 rd[c].data = GNUNET_malloc(50);
329 rd[c].flags = 0; 329 rd[c].flags = 0;
330 memset ((char *) rd[c].data, 'a', 50); 330 memset((char *)rd[c].data, 'a', 50);
331 } 331 }
332 return rd; 332 return rd;
333} 333}
334 334
@@ -339,128 +339,128 @@ create_record (unsigned int count)
339 * start the actual tests by filling the zone. 339 * start the actual tests by filling the zone.
340 */ 340 */
341static void 341static void
342empty_zone_proc (void *cls, 342empty_zone_proc(void *cls,
343 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 343 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
344 const char *label, 344 const char *label,
345 unsigned int rd_count, 345 unsigned int rd_count,
346 const struct GNUNET_GNSRECORD_Data *rd) 346 const struct GNUNET_GNSRECORD_Data *rd)
347{ 347{
348 GNUNET_assert (nsh == cls); 348 GNUNET_assert(nsh == cls);
349 if (NULL != zone) 349 if (NULL != zone)
350 { 350 {
351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 351 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
352 _("Expected empty zone but received zone private key\n")); 352 _("Expected empty zone but received zone private key\n"));
353 GNUNET_break (0); 353 GNUNET_break(0);
354 GNUNET_SCHEDULER_shutdown (); 354 GNUNET_SCHEDULER_shutdown();
355 res = 1; 355 res = 1;
356 return; 356 return;
357 } 357 }
358 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 358 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
359 { 359 {
360 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 360 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
361 _("Expected no zone content but received data\n")); 361 _("Expected no zone content but received data\n"));
362 GNUNET_break (0); 362 GNUNET_break(0);
363 GNUNET_SCHEDULER_shutdown (); 363 GNUNET_SCHEDULER_shutdown();
364 res = 1; 364 res = 1;
365 return; 365 return;
366 } 366 }
367 GNUNET_assert (0); 367 GNUNET_assert(0);
368} 368}
369 369
370 370
371static void 371static void
372empty_zone_end (void *cls) 372empty_zone_end(void *cls)
373{ 373{
374 char *hostkey_file; 374 char *hostkey_file;
375 375
376 zi = NULL; 376 zi = NULL;
377 GNUNET_asprintf (&hostkey_file, 377 GNUNET_asprintf(&hostkey_file,
378 "zonefiles%s%s", 378 "zonefiles%s%s",
379 DIR_SEPARATOR_STR, 379 DIR_SEPARATOR_STR,
380 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 380 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 381 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
382 "Using zonekey file `%s' \n", 382 "Using zonekey file `%s' \n",
383 hostkey_file); 383 hostkey_file);
384 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 384 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
385 GNUNET_free (hostkey_file); 385 GNUNET_free(hostkey_file);
386 GNUNET_assert (privkey != NULL); 386 GNUNET_assert(privkey != NULL);
387 387
388 GNUNET_asprintf (&hostkey_file, 388 GNUNET_asprintf(&hostkey_file,
389 "zonefiles%s%s", 389 "zonefiles%s%s",
390 DIR_SEPARATOR_STR, 390 DIR_SEPARATOR_STR,
391 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 391 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
393 "Using zonekey file `%s' \n", 393 "Using zonekey file `%s' \n",
394 hostkey_file); 394 hostkey_file);
395 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 395 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
396 GNUNET_free (hostkey_file); 396 GNUNET_free(hostkey_file);
397 GNUNET_assert (privkey2 != NULL); 397 GNUNET_assert(privkey2 != NULL);
398 398
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); 399 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
400 400
401 GNUNET_asprintf(&s_name_1, "dummy1"); 401 GNUNET_asprintf(&s_name_1, "dummy1");
402 s_rd_1 = create_record(1); 402 s_rd_1 = create_record(1);
403 GNUNET_NAMESTORE_records_store (nsh, 403 GNUNET_NAMESTORE_records_store(nsh,
404 privkey, 404 privkey,
405 s_name_1, 405 s_name_1,
406 1, s_rd_1, 406 1, s_rd_1,
407 &put_cont, 407 &put_cont,
408 NULL); 408 NULL);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 409 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
410 "Created record 2 \n"); 410 "Created record 2 \n");
411 GNUNET_asprintf(&s_name_2, "dummy2"); 411 GNUNET_asprintf(&s_name_2, "dummy2");
412 s_rd_2 = create_record(1); 412 s_rd_2 = create_record(1);
413 GNUNET_NAMESTORE_records_store (nsh, 413 GNUNET_NAMESTORE_records_store(nsh,
414 privkey, 414 privkey,
415 s_name_2, 415 s_name_2,
416 1, s_rd_2, 416 1, s_rd_2,
417 &put_cont, 417 &put_cont,
418 NULL); 418 NULL);
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 419 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
420 "Created record 3\n"); 420 "Created record 3\n");
421 /* name in different zone */ 421 /* name in different zone */
422 GNUNET_asprintf(&s_name_3, "dummy3"); 422 GNUNET_asprintf(&s_name_3, "dummy3");
423 s_rd_3 = create_record(1); 423 s_rd_3 = create_record(1);
424 GNUNET_NAMESTORE_records_store (nsh, 424 GNUNET_NAMESTORE_records_store(nsh,
425 privkey2, 425 privkey2,
426 s_name_3, 426 s_name_3,
427 1, 427 1,
428 s_rd_3, 428 s_rd_3,
429 &put_cont, 429 &put_cont,
430 NULL); 430 NULL);
431} 431}
432 432
433 433
434static void 434static void
435run (void *cls, 435run(void *cls,
436 const struct GNUNET_CONFIGURATION_Handle *cfg, 436 const struct GNUNET_CONFIGURATION_Handle *cfg,
437 struct GNUNET_TESTING_Peer *peer) 437 struct GNUNET_TESTING_Peer *peer)
438{ 438{
439 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 439 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
440 &endbadly, 440 &endbadly,
441 NULL); 441 NULL);
442 GNUNET_SCHEDULER_add_shutdown (&end, 442 GNUNET_SCHEDULER_add_shutdown(&end,
443 NULL); 443 NULL);
444 444
445 nsh = GNUNET_NAMESTORE_connect (cfg); 445 nsh = GNUNET_NAMESTORE_connect(cfg);
446 GNUNET_break (NULL != nsh); 446 GNUNET_break(NULL != nsh);
447 /* first, iterate over empty namestore */ 447 /* first, iterate over empty namestore */
448 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 448 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
449 NULL, 449 NULL,
450 &fail_cb, 450 &fail_cb,
451 NULL, 451 NULL,
452 &empty_zone_proc, 452 &empty_zone_proc,
453 nsh, 453 nsh,
454 &empty_zone_end, 454 &empty_zone_end,
455 NULL); 455 NULL);
456 if (NULL == zi) 456 if (NULL == zi)
457 { 457 {
458 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 458 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
459 "Failed to create zone iterator\n"); 459 "Failed to create zone iterator\n");
460 GNUNET_break (0); 460 GNUNET_break(0);
461 res = 1; 461 res = 1;
462 GNUNET_SCHEDULER_shutdown (); 462 GNUNET_SCHEDULER_shutdown();
463 } 463 }
464} 464}
465 465
466 466
@@ -468,24 +468,24 @@ run (void *cls,
468 468
469 469
470int 470int
471main (int argc, char *argv[]) 471main(int argc, char *argv[])
472{ 472{
473 const char *plugin_name; 473 const char *plugin_name;
474 char *cfg_name; 474 char *cfg_name;
475 475
476 SETUP_CFG (plugin_name, cfg_name); 476 SETUP_CFG(plugin_name, cfg_name);
477 res = 1; 477 res = 1;
478 if (0 != 478 if (0 !=
479 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", 479 GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration",
480 cfg_name, 480 cfg_name,
481 &run, 481 &run,
482 NULL)) 482 NULL))
483 { 483 {
484 res = 1; 484 res = 1;
485 } 485 }
486 GNUNET_DISK_purge_cfg_dir (cfg_name, 486 GNUNET_DISK_purge_cfg_dir(cfg_name,
487 "GNUNET_TEST_HOME"); 487 "GNUNET_TEST_HOME");
488 GNUNET_free (cfg_name); 488 GNUNET_free(cfg_name);
489 return res; 489 return res;
490} 490}
491 491
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c
index 069c6d831..739e71c05 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_zone_iteration.c 21 * @file namestore/test_namestore_api_zone_iteration.c
22 * @brief testcase for zone iteration functionality: iterate all zones 22 * @brief testcase for zone iteration functionality: iterate all zones
@@ -32,7 +32,7 @@
32#define ZONE_NICK_1 "nick1" 32#define ZONE_NICK_1 "nick1"
33#define ZONE_NICK_2 "nick2" 33#define ZONE_NICK_2 "nick2"
34 34
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
36 36
37 37
38static struct GNUNET_NAMESTORE_Handle * nsh; 38static struct GNUNET_NAMESTORE_Handle * nsh;
@@ -69,266 +69,266 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
69 * @param tc scheduler context 69 * @param tc scheduler context
70 */ 70 */
71static void 71static void
72end (void *cls) 72end(void *cls)
73{ 73{
74 if (NULL != zi) 74 if (NULL != zi)
75 { 75 {
76 GNUNET_NAMESTORE_zone_iteration_stop (zi); 76 GNUNET_NAMESTORE_zone_iteration_stop(zi);
77 zi = NULL; 77 zi = NULL;
78 } 78 }
79 if (nsh != NULL) 79 if (nsh != NULL)
80 { 80 {
81 GNUNET_NAMESTORE_disconnect (nsh); 81 GNUNET_NAMESTORE_disconnect(nsh);
82 nsh = NULL; 82 nsh = NULL;
83 } 83 }
84 GNUNET_free_non_null (s_name_1); 84 GNUNET_free_non_null(s_name_1);
85 GNUNET_free_non_null (s_name_2); 85 GNUNET_free_non_null(s_name_2);
86 GNUNET_free_non_null (s_name_3); 86 GNUNET_free_non_null(s_name_3);
87 87
88 if (s_rd_1 != NULL) 88 if (s_rd_1 != NULL)
89 { 89 {
90 GNUNET_free ((void *)s_rd_1->data); 90 GNUNET_free((void *)s_rd_1->data);
91 GNUNET_free (s_rd_1); 91 GNUNET_free(s_rd_1);
92 } 92 }
93 if (s_rd_2 != NULL) 93 if (s_rd_2 != NULL)
94 { 94 {
95 GNUNET_free ((void *)s_rd_2->data); 95 GNUNET_free((void *)s_rd_2->data);
96 GNUNET_free (s_rd_2); 96 GNUNET_free(s_rd_2);
97 } 97 }
98 if (s_rd_3 != NULL) 98 if (s_rd_3 != NULL)
99 { 99 {
100 GNUNET_free ((void *)s_rd_3->data); 100 GNUNET_free((void *)s_rd_3->data);
101 GNUNET_free (s_rd_3); 101 GNUNET_free(s_rd_3);
102 } 102 }
103 103
104 if (privkey != NULL) 104 if (privkey != NULL)
105 { 105 {
106 GNUNET_free (privkey); 106 GNUNET_free(privkey);
107 privkey = NULL; 107 privkey = NULL;
108 } 108 }
109 if (privkey2 != NULL) 109 if (privkey2 != NULL)
110 { 110 {
111 GNUNET_free (privkey2); 111 GNUNET_free(privkey2);
112 privkey2 = NULL; 112 privkey2 = NULL;
113 } 113 }
114} 114}
115 115
116 116
117static int 117static int
118check_zone_1 (const char *label, unsigned int rd_count, 118check_zone_1(const char *label, unsigned int rd_count,
119 const struct GNUNET_GNSRECORD_Data *rd) 119 const struct GNUNET_GNSRECORD_Data *rd)
120{ 120{
121 for (unsigned int c = 0; c< rd_count ; c++) 121 for (unsigned int c = 0; c < rd_count; c++)
122 {
123 if ( (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) &&
124 (0 != strcmp (rd[c].data, ZONE_NICK_1)) )
125 { 122 {
126 GNUNET_break (0); 123 if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) &&
127 return GNUNET_YES; 124 (0 != strcmp(rd[c].data, ZONE_NICK_1)))
125 {
126 GNUNET_break(0);
127 return GNUNET_YES;
128 }
128 } 129 }
129 }
130 return GNUNET_NO; 130 return GNUNET_NO;
131} 131}
132 132
133 133
134static int 134static int
135check_zone_2 (const char *label, 135check_zone_2(const char *label,
136 unsigned int rd_count, 136 unsigned int rd_count,
137 const struct GNUNET_GNSRECORD_Data *rd) 137 const struct GNUNET_GNSRECORD_Data *rd)
138{ 138{
139 for (unsigned int c = 0; c< rd_count ; c++) 139 for (unsigned int c = 0; c < rd_count; c++)
140 {
141 if ( (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) &&
142 (0 != strcmp (rd[c].data, ZONE_NICK_2)) )
143 { 140 {
144 GNUNET_break (0); 141 if ((rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) &&
145 return GNUNET_YES; 142 (0 != strcmp(rd[c].data, ZONE_NICK_2)))
143 {
144 GNUNET_break(0);
145 return GNUNET_YES;
146 }
146 } 147 }
147 }
148 return GNUNET_NO; 148 return GNUNET_NO;
149} 149}
150 150
151 151
152static void 152static void
153zone_proc_end (void *cls) 153zone_proc_end(void *cls)
154{ 154{
155 zi = NULL; 155 zi = NULL;
156 res = 0; 156 res = 0;
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
158 "Received last result, iteration done after receing %u results\n", 158 "Received last result, iteration done after receing %u results\n",
159 returned_records); 159 returned_records);
160 GNUNET_SCHEDULER_shutdown (); 160 GNUNET_SCHEDULER_shutdown();
161} 161}
162 162
163 163
164static void 164static void
165zone_proc (void *cls, 165zone_proc(void *cls,
166 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 166 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
167 const char *label, 167 const char *label,
168 unsigned int rd_count, 168 unsigned int rd_count,
169 const struct GNUNET_GNSRECORD_Data *rd) 169 const struct GNUNET_GNSRECORD_Data *rd)
170{ 170{
171 int failed = GNUNET_NO; 171 int failed = GNUNET_NO;
172 172
173 GNUNET_assert (NULL != zone); 173 GNUNET_assert(NULL != zone);
174 if (0 == GNUNET_memcmp (zone, privkey)) 174 if (0 == GNUNET_memcmp(zone, privkey))
175 { 175 {
176 failed = check_zone_1 (label, rd_count, rd); 176 failed = check_zone_1(label, rd_count, rd);
177 if (GNUNET_YES == failed) 177 if (GNUNET_YES == failed)
178 GNUNET_break (0); 178 GNUNET_break(0);
179 } 179 }
180 else if (0 == GNUNET_memcmp (zone, privkey2)) 180 else if (0 == GNUNET_memcmp(zone, privkey2))
181 { 181 {
182 failed = check_zone_2 (label, rd_count, rd); 182 failed = check_zone_2(label, rd_count, rd);
183 if (GNUNET_YES == failed) 183 if (GNUNET_YES == failed)
184 GNUNET_break (0); 184 GNUNET_break(0);
185 } 185 }
186 else 186 else
187 { 187 {
188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 188 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
189 "Received invalid zone\n"); 189 "Received invalid zone\n");
190 failed = GNUNET_YES; 190 failed = GNUNET_YES;
191 GNUNET_break (0); 191 GNUNET_break(0);
192 } 192 }
193 193
194 if (failed == GNUNET_NO) 194 if (failed == GNUNET_NO)
195 { 195 {
196 returned_records ++; 196 returned_records++;
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
198 "Telling namestore to send the next result\n"); 198 "Telling namestore to send the next result\n");
199 GNUNET_NAMESTORE_zone_iterator_next (zi, 199 GNUNET_NAMESTORE_zone_iterator_next(zi,
200 1); 200 1);
201 } 201 }
202 else 202 else
203 { 203 {
204 GNUNET_break (0); 204 GNUNET_break(0);
205 res = 1; 205 res = 1;
206 GNUNET_SCHEDULER_shutdown (); 206 GNUNET_SCHEDULER_shutdown();
207 } 207 }
208} 208}
209 209
210 210
211static void 211static void
212fail_cb (void *cls) 212fail_cb(void *cls)
213{ 213{
214 GNUNET_assert (0); 214 GNUNET_assert(0);
215} 215}
216 216
217 217
218static void 218static void
219put_cont (void *cls, 219put_cont(void *cls,
220 int32_t success, 220 int32_t success,
221 const char *emsg) 221 const char *emsg)
222{ 222{
223 static int c = 0; 223 static int c = 0;
224 224
225 if (success == GNUNET_OK) 225 if (success == GNUNET_OK)
226 { 226 {
227 c++; 227 c++;
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); 228 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
229 } 229 }
230 else 230 else
231 { 231 {
232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", 232 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n",
233 emsg); 233 emsg);
234 GNUNET_break (0); 234 GNUNET_break(0);
235 GNUNET_SCHEDULER_shutdown (); 235 GNUNET_SCHEDULER_shutdown();
236 return; 236 return;
237 } 237 }
238 238
239 if (c == 3) 239 if (c == 3)
240 {
241 res = 1;
242 returned_records = 0;
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
244 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
245 NULL,
246 &fail_cb,
247 NULL,
248 &zone_proc,
249 NULL,
250 &zone_proc_end,
251 NULL);
252 if (zi == NULL)
253 { 240 {
254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 241 res = 1;
255 GNUNET_break (0); 242 returned_records = 0;
256 GNUNET_SCHEDULER_shutdown (); 243 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
257 return; 244 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
245 NULL,
246 &fail_cb,
247 NULL,
248 &zone_proc,
249 NULL,
250 &zone_proc_end,
251 NULL);
252 if (zi == NULL)
253 {
254 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
255 GNUNET_break(0);
256 GNUNET_SCHEDULER_shutdown();
257 return;
258 }
258 } 259 }
259 }
260} 260}
261 261
262 262
263static struct GNUNET_GNSRECORD_Data * 263static struct GNUNET_GNSRECORD_Data *
264create_record (unsigned int count) 264create_record(unsigned int count)
265{ 265{
266 struct GNUNET_GNSRECORD_Data * rd; 266 struct GNUNET_GNSRECORD_Data * rd;
267 267
268 rd = GNUNET_new_array (count, 268 rd = GNUNET_new_array(count,
269 struct GNUNET_GNSRECORD_Data); 269 struct GNUNET_GNSRECORD_Data);
270 for (unsigned int c = 0; c < count; c++) 270 for (unsigned int c = 0; c < count; c++)
271 { 271 {
272 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 272 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us;
273 rd[c].record_type = TEST_RECORD_TYPE; 273 rd[c].record_type = TEST_RECORD_TYPE;
274 rd[c].data_size = 50; 274 rd[c].data_size = 50;
275 rd[c].data = GNUNET_malloc(50); 275 rd[c].data = GNUNET_malloc(50);
276 rd[c].flags = 0; 276 rd[c].flags = 0;
277 memset ((char *) rd[c].data, 'a', 50); 277 memset((char *)rd[c].data, 'a', 50);
278 } 278 }
279 return rd; 279 return rd;
280} 280}
281 281
282 282
283static void 283static void
284nick_2_cont (void *cls, 284nick_2_cont(void *cls,
285 int32_t success, 285 int32_t success,
286 const char *emsg) 286 const char *emsg)
287{ 287{
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 288 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
289 "Nick added : %s\n", 289 "Nick added : %s\n",
290 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 290 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
291 291
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); 292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
293 293
294 GNUNET_asprintf(&s_name_1, "dummy1"); 294 GNUNET_asprintf(&s_name_1, "dummy1");
295 s_rd_1 = create_record(1); 295 s_rd_1 = create_record(1);
296 GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, 296 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
297 1, s_rd_1, 297 1, s_rd_1,
298 &put_cont, NULL); 298 &put_cont, NULL);
299 299
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 300 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
301 "Created record 2 \n"); 301 "Created record 2 \n");
302 GNUNET_asprintf(&s_name_2, "dummy2"); 302 GNUNET_asprintf(&s_name_2, "dummy2");
303 s_rd_2 = create_record(1); 303 s_rd_2 = create_record(1);
304 GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, 304 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
305 1, s_rd_2, &put_cont, NULL); 305 1, s_rd_2, &put_cont, NULL);
306 306
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 307 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
308 "Created record 3\n"); 308 "Created record 3\n");
309 309
310 /* name in different zone */ 310 /* name in different zone */
311 GNUNET_asprintf(&s_name_3, "dummy3"); 311 GNUNET_asprintf(&s_name_3, "dummy3");
312 s_rd_3 = create_record(1); 312 s_rd_3 = create_record(1);
313 GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 313 GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3,
314 1, s_rd_3, 314 1, s_rd_3,
315 &put_cont, NULL); 315 &put_cont, NULL);
316} 316}
317 317
318 318
319static void 319static void
320nick_1_cont (void *cls, int32_t success, const char *emsg) 320nick_1_cont(void *cls, int32_t success, const char *emsg)
321{ 321{
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 322 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
323 "Nick 1 added : %s\n", 323 "Nick 1 added : %s\n",
324 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 324 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
325 325
326 nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey2, ZONE_NICK_2, &nick_2_cont, &privkey2); 326 nsqe = GNUNET_NAMESTORE_set_nick(nsh, privkey2, ZONE_NICK_2, &nick_2_cont, &privkey2);
327 if (NULL == nsqe) 327 if (NULL == nsqe)
328 { 328 {
329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 329 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
330 _("Namestore cannot store no block\n")); 330 _("Namestore cannot store no block\n"));
331 } 331 }
332} 332}
333 333
334 334
@@ -338,70 +338,69 @@ nick_1_cont (void *cls, int32_t success, const char *emsg)
338 * start the actual tests by filling the zone. 338 * start the actual tests by filling the zone.
339 */ 339 */
340static void 340static void
341empty_zone_proc (void *cls, 341empty_zone_proc(void *cls,
342 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 342 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
343 const char *label, 343 const char *label,
344 unsigned int rd_count, 344 unsigned int rd_count,
345 const struct GNUNET_GNSRECORD_Data *rd) 345 const struct GNUNET_GNSRECORD_Data *rd)
346{ 346{
347 GNUNET_assert (nsh == cls); 347 GNUNET_assert(nsh == cls);
348 348
349 if (NULL != zone) 349 if (NULL != zone)
350 { 350 {
351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 351 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
352 _("Expected empty zone but received zone private key\n")); 352 _("Expected empty zone but received zone private key\n"));
353 GNUNET_break (0); 353 GNUNET_break(0);
354 GNUNET_SCHEDULER_shutdown (); 354 GNUNET_SCHEDULER_shutdown();
355 return; 355 return;
356 } 356 }
357 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 357 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
358 { 358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 359 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
360 _("Expected no zone content but received data\n")); 360 _("Expected no zone content but received data\n"));
361 GNUNET_break (0); 361 GNUNET_break(0);
362 GNUNET_SCHEDULER_shutdown (); 362 GNUNET_SCHEDULER_shutdown();
363 return; 363 return;
364 } 364 }
365 GNUNET_assert (0); 365 GNUNET_assert(0);
366} 366}
367 367
368 368
369static void 369static void
370empty_zone_end (void *cls) 370empty_zone_end(void *cls)
371{ 371{
372 GNUNET_assert (nsh == cls); 372 GNUNET_assert(nsh == cls);
373 zi = NULL; 373 zi = NULL;
374 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 374 privkey = GNUNET_CRYPTO_ecdsa_key_create();
375 GNUNET_assert (privkey != NULL); 375 GNUNET_assert(privkey != NULL);
376 privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); 376 privkey2 = GNUNET_CRYPTO_ecdsa_key_create();
377 GNUNET_assert (privkey2 != NULL); 377 GNUNET_assert(privkey2 != NULL);
378 378
379 nsqe = GNUNET_NAMESTORE_set_nick (nsh, 379 nsqe = GNUNET_NAMESTORE_set_nick(nsh,
380 privkey, 380 privkey,
381 ZONE_NICK_1, 381 ZONE_NICK_1,
382 &nick_1_cont, 382 &nick_1_cont,
383 &privkey); 383 &privkey);
384 if (NULL == nsqe) 384 if (NULL == nsqe)
385 { 385 {
386 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 386 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
387 _("Namestore cannot store no block\n")); 387 _("Namestore cannot store no block\n"));
388 } 388 }
389
390} 389}
391 390
392 391
393static void 392static void
394run (void *cls, 393run(void *cls,
395 const struct GNUNET_CONFIGURATION_Handle *cfg, 394 const struct GNUNET_CONFIGURATION_Handle *cfg,
396 struct GNUNET_TESTING_Peer *peer) 395 struct GNUNET_TESTING_Peer *peer)
397{ 396{
398 nsh = GNUNET_NAMESTORE_connect (cfg); 397 nsh = GNUNET_NAMESTORE_connect(cfg);
399 GNUNET_break (NULL != nsh); 398 GNUNET_break(NULL != nsh);
400 GNUNET_SCHEDULER_add_shutdown (&end, 399 GNUNET_SCHEDULER_add_shutdown(&end,
401 NULL); 400 NULL);
402 /* first, iterate over empty namestore */ 401 /* first, iterate over empty namestore */
403 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 402 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
404 NULL, 403 NULL,
405 &fail_cb, 404 &fail_cb,
406 NULL, 405 NULL,
407 &empty_zone_proc, 406 &empty_zone_proc,
@@ -409,12 +408,12 @@ run (void *cls,
409 &empty_zone_end, 408 &empty_zone_end,
410 nsh); 409 nsh);
411 if (NULL == zi) 410 if (NULL == zi)
412 { 411 {
413 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 412 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
414 "Failed to create zone iterator\n"); 413 "Failed to create zone iterator\n");
415 GNUNET_break (0); 414 GNUNET_break(0);
416 GNUNET_SCHEDULER_shutdown (); 415 GNUNET_SCHEDULER_shutdown();
417 } 416 }
418} 417}
419 418
420 419
@@ -422,24 +421,24 @@ run (void *cls,
422 421
423 422
424int 423int
425main (int argc, char *argv[]) 424main(int argc, char *argv[])
426{ 425{
427 const char *plugin_name; 426 const char *plugin_name;
428 char *cfg_name; 427 char *cfg_name;
429 428
430 SETUP_CFG (plugin_name, cfg_name); 429 SETUP_CFG(plugin_name, cfg_name);
431 res = 1; 430 res = 1;
432 if (0 != 431 if (0 !=
433 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", 432 GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration-nick",
434 cfg_name, 433 cfg_name,
435 &run, 434 &run,
436 NULL)) 435 NULL))
437 { 436 {
438 res = 1; 437 res = 1;
439 } 438 }
440 GNUNET_DISK_purge_cfg_dir (cfg_name, 439 GNUNET_DISK_purge_cfg_dir(cfg_name,
441 "GNUNET_TEST_HOME"); 440 "GNUNET_TEST_HOME");
442 GNUNET_free (cfg_name); 441 GNUNET_free(cfg_name);
443 return res; 442 return res;
444} 443}
445 444
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
index e3c6d698a..924e1eb1e 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_zone_iteration_specific_zone.c 21 * @file namestore/test_namestore_api_zone_iteration_specific_zone.c
22 * @brief testcase for zone iteration functionality: iterate over a specific zone 22 * @brief testcase for zone iteration functionality: iterate over a specific zone
@@ -31,7 +31,7 @@
31#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT 31#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
32 32
33 33
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 34#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
35 35
36 36
37static struct GNUNET_NAMESTORE_Handle * nsh; 37static struct GNUNET_NAMESTORE_Handle * nsh;
@@ -67,246 +67,246 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
67 * @param cls handle to use to re-connect. 67 * @param cls handle to use to re-connect.
68 */ 68 */
69static void 69static void
70endbadly (void *cls) 70endbadly(void *cls)
71{ 71{
72 endbadly_task = NULL; 72 endbadly_task = NULL;
73 GNUNET_SCHEDULER_shutdown (); 73 GNUNET_SCHEDULER_shutdown();
74 res = 1; 74 res = 1;
75} 75}
76 76
77 77
78static void 78static void
79end (void *cls) 79end(void *cls)
80{ 80{
81 if (NULL != zi) 81 if (NULL != zi)
82 { 82 {
83 GNUNET_NAMESTORE_zone_iteration_stop (zi); 83 GNUNET_NAMESTORE_zone_iteration_stop(zi);
84 zi = NULL; 84 zi = NULL;
85 } 85 }
86 if (NULL != endbadly_task) 86 if (NULL != endbadly_task)
87 { 87 {
88 GNUNET_SCHEDULER_cancel (endbadly_task); 88 GNUNET_SCHEDULER_cancel(endbadly_task);
89 endbadly_task = NULL; 89 endbadly_task = NULL;
90 } 90 }
91 if (NULL != privkey) 91 if (NULL != privkey)
92 { 92 {
93 GNUNET_free (privkey); 93 GNUNET_free(privkey);
94 privkey = NULL; 94 privkey = NULL;
95 } 95 }
96 if (NULL != privkey2) 96 if (NULL != privkey2)
97 { 97 {
98 GNUNET_free (privkey2); 98 GNUNET_free(privkey2);
99 privkey2 = NULL; 99 privkey2 = NULL;
100 } 100 }
101 GNUNET_free_non_null (s_name_1); 101 GNUNET_free_non_null(s_name_1);
102 GNUNET_free_non_null (s_name_2); 102 GNUNET_free_non_null(s_name_2);
103 GNUNET_free_non_null (s_name_3); 103 GNUNET_free_non_null(s_name_3);
104 if (s_rd_1 != NULL) 104 if (s_rd_1 != NULL)
105 { 105 {
106 GNUNET_free ((void *)s_rd_1->data); 106 GNUNET_free((void *)s_rd_1->data);
107 GNUNET_free (s_rd_1); 107 GNUNET_free(s_rd_1);
108 } 108 }
109 if (s_rd_2 != NULL) 109 if (s_rd_2 != NULL)
110 { 110 {
111 GNUNET_free ((void *)s_rd_2->data); 111 GNUNET_free((void *)s_rd_2->data);
112 GNUNET_free (s_rd_2); 112 GNUNET_free(s_rd_2);
113 } 113 }
114 if (s_rd_3 != NULL) 114 if (s_rd_3 != NULL)
115 { 115 {
116 GNUNET_free ((void *)s_rd_3->data); 116 GNUNET_free((void *)s_rd_3->data);
117 GNUNET_free (s_rd_3); 117 GNUNET_free(s_rd_3);
118 } 118 }
119 if (nsh != NULL) 119 if (nsh != NULL)
120 { 120 {
121 GNUNET_NAMESTORE_disconnect (nsh); 121 GNUNET_NAMESTORE_disconnect(nsh);
122 nsh = NULL; 122 nsh = NULL;
123 } 123 }
124} 124}
125 125
126 126
127static void 127static void
128fail_cb (void *cls) 128fail_cb(void *cls)
129{ 129{
130 GNUNET_assert (0); 130 GNUNET_assert(0);
131 zi = NULL; 131 zi = NULL;
132} 132}
133 133
134 134
135static void 135static void
136zone_proc (void *cls, 136zone_proc(void *cls,
137 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 137 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
138 const char *label, 138 const char *label,
139 unsigned int rd_count, 139 unsigned int rd_count,
140 const struct GNUNET_GNSRECORD_Data *rd) 140 const struct GNUNET_GNSRECORD_Data *rd)
141{ 141{
142 int failed = GNUNET_NO; 142 int failed = GNUNET_NO;
143 143
144 GNUNET_assert (NULL != zone); 144 GNUNET_assert(NULL != zone);
145 if (0 == GNUNET_memcmp (zone, 145 if (0 == GNUNET_memcmp(zone,
146 privkey)) 146 privkey))
147 {
148 if (0 == strcmp (label, s_name_1))
149 { 147 {
150 if (rd_count == 1) 148 if (0 == strcmp(label, s_name_1))
151 {
152 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp (rd, s_rd_1))
153 { 149 {
154 failed = GNUNET_YES; 150 if (rd_count == 1)
155 GNUNET_break (0); 151 {
152 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1))
153 {
154 failed = GNUNET_YES;
155 GNUNET_break(0);
156 }
157 }
158 else
159 {
160 failed = GNUNET_YES;
161 GNUNET_break(0);
162 }
163 }
164 else if (0 == strcmp(label, s_name_2))
165 {
166 if (rd_count == 1)
167 {
168 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
169 {
170 failed = GNUNET_YES;
171 GNUNET_break(0);
172 }
173 }
174 else
175 {
176 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
177 "Received invalid record count\n");
178 failed = GNUNET_YES;
179 GNUNET_break(0);
180 }
156 } 181 }
157 }
158 else 182 else
159 {
160 failed = GNUNET_YES;
161 GNUNET_break (0);
162 }
163 }
164 else if (0 == strcmp (label, s_name_2))
165 {
166 if (rd_count == 1)
167 {
168 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
169 { 183 {
184 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
185 "Comparing result failed: got name `%s' for first zone\n",
186 label);
170 failed = GNUNET_YES; 187 failed = GNUNET_YES;
171 GNUNET_break (0); 188 GNUNET_break(0);
172 } 189 }
173 }
174 else
175 {
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
177 "Received invalid record count\n");
178 failed = GNUNET_YES;
179 GNUNET_break (0);
180 }
181 } 190 }
182 else 191 else if (0 == GNUNET_memcmp(zone, privkey2))
183 { 192 {
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
185 "Comparing result failed: got name `%s' for first zone\n", 194 "Received data for not requested zone\n");
186 label);
187 failed = GNUNET_YES; 195 failed = GNUNET_YES;
188 GNUNET_break (0); 196 GNUNET_break(0);
189 } 197 }
190 }
191 else if (0 == GNUNET_memcmp (zone, privkey2))
192 {
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 "Received data for not requested zone\n");
195 failed = GNUNET_YES;
196 GNUNET_break (0);
197 }
198 else 198 else
199 { 199 {
200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 200 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
201 "Received invalid zone\n"); 201 "Received invalid zone\n");
202 failed = GNUNET_YES; 202 failed = GNUNET_YES;
203 GNUNET_break (0); 203 GNUNET_break(0);
204 } 204 }
205 if (failed == GNUNET_NO) 205 if (failed == GNUNET_NO)
206 { 206 {
207 returned_records ++; 207 returned_records++;
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 208 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
209 "Telling namestore to send the next result\n"); 209 "Telling namestore to send the next result\n");
210 GNUNET_NAMESTORE_zone_iterator_next (zi, 210 GNUNET_NAMESTORE_zone_iterator_next(zi,
211 1); 211 1);
212 } 212 }
213 else 213 else
214 { 214 {
215 GNUNET_break (0); 215 GNUNET_break(0);
216 res = 2; 216 res = 2;
217 GNUNET_SCHEDULER_shutdown (); 217 GNUNET_SCHEDULER_shutdown();
218 } 218 }
219} 219}
220 220
221 221
222static void 222static void
223zone_proc_end (void *cls) 223zone_proc_end(void *cls)
224{ 224{
225 zi = NULL; 225 zi = NULL;
226 GNUNET_break (2 == returned_records); 226 GNUNET_break(2 == returned_records);
227 if (2 == returned_records) 227 if (2 == returned_records)
228 { 228 {
229 res = 0; /* Last iteraterator callback, we are done */ 229 res = 0; /* Last iteraterator callback, we are done */
230 } 230 }
231 else 231 else
232 { 232 {
233 res = 1; 233 res = 1;
234 } 234 }
235 235
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 236 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
237 "Received last result, iteration done after receing %u results\n", 237 "Received last result, iteration done after receing %u results\n",
238 returned_records); 238 returned_records);
239 GNUNET_SCHEDULER_shutdown (); 239 GNUNET_SCHEDULER_shutdown();
240} 240}
241 241
242 242
243static void 243static void
244put_cont (void *cls, 244put_cont(void *cls,
245 int32_t success, 245 int32_t success,
246 const char *emsg) 246 const char *emsg)
247{ 247{
248 static int c = 0; 248 static int c = 0;
249 249
250 if (success == GNUNET_OK) 250 if (success == GNUNET_OK)
251 { 251 {
252 c++; 252 c++;
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
254 "Created record %u \n", c); 254 "Created record %u \n", c);
255 } 255 }
256 else 256 else
257 {
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
259 "Failed to created records: `%s'\n",
260 emsg);
261 GNUNET_break (0);
262 res = 2;
263 GNUNET_SCHEDULER_shutdown ();
264 return;
265 }
266
267 if (c == 3)
268 {
269 res = 1;
270 returned_records = 0;
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "All records created, starting iteration over all zones \n");
273 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
274 privkey,
275 &fail_cb,
276 NULL,
277 &zone_proc,
278 NULL,
279 &zone_proc_end,
280 NULL);
281 if (zi == NULL)
282 { 257 {
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 258 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
284 "Failed to create zone iterator\n"); 259 "Failed to created records: `%s'\n",
285 GNUNET_break (0); 260 emsg);
261 GNUNET_break(0);
286 res = 2; 262 res = 2;
287 GNUNET_SCHEDULER_shutdown (); 263 GNUNET_SCHEDULER_shutdown();
288 return; 264 return;
289 } 265 }
290 } 266
267 if (c == 3)
268 {
269 res = 1;
270 returned_records = 0;
271 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
272 "All records created, starting iteration over all zones \n");
273 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
274 privkey,
275 &fail_cb,
276 NULL,
277 &zone_proc,
278 NULL,
279 &zone_proc_end,
280 NULL);
281 if (zi == NULL)
282 {
283 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
284 "Failed to create zone iterator\n");
285 GNUNET_break(0);
286 res = 2;
287 GNUNET_SCHEDULER_shutdown();
288 return;
289 }
290 }
291} 291}
292 292
293 293
294static struct GNUNET_GNSRECORD_Data * 294static struct GNUNET_GNSRECORD_Data *
295create_record (unsigned int count) 295create_record(unsigned int count)
296{ 296{
297 struct GNUNET_GNSRECORD_Data *rd; 297 struct GNUNET_GNSRECORD_Data *rd;
298 298
299 rd = GNUNET_new_array (count, 299 rd = GNUNET_new_array(count,
300 struct GNUNET_GNSRECORD_Data); 300 struct GNUNET_GNSRECORD_Data);
301 for (unsigned int c = 0; c < count; c++) 301 for (unsigned int c = 0; c < count; c++)
302 { 302 {
303 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 303 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us;
304 rd[c].record_type = TEST_RECORD_TYPE; 304 rd[c].record_type = TEST_RECORD_TYPE;
305 rd[c].data_size = 50; 305 rd[c].data_size = 50;
306 rd[c].data = GNUNET_malloc(50); 306 rd[c].data = GNUNET_malloc(50);
307 rd[c].flags = 0; 307 rd[c].flags = 0;
308 memset ((char *) rd[c].data, 'a', 50); 308 memset((char *)rd[c].data, 'a', 50);
309 } 309 }
310 return rd; 310 return rd;
311} 311}
312 312
@@ -317,114 +317,114 @@ create_record (unsigned int count)
317 * start the actual tests by filling the zone. 317 * start the actual tests by filling the zone.
318 */ 318 */
319static void 319static void
320empty_zone_proc (void *cls, 320empty_zone_proc(void *cls,
321 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 321 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
322 const char *label, 322 const char *label,
323 unsigned int rd_count, 323 unsigned int rd_count,
324 const struct GNUNET_GNSRECORD_Data *rd) 324 const struct GNUNET_GNSRECORD_Data *rd)
325{ 325{
326 GNUNET_assert (nsh == cls); 326 GNUNET_assert(nsh == cls);
327 if (NULL != zone) 327 if (NULL != zone)
328 { 328 {
329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 329 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
330 _("Expected empty zone but received zone private key\n")); 330 _("Expected empty zone but received zone private key\n"));
331 GNUNET_break (0); 331 GNUNET_break(0);
332 res = 2; 332 res = 2;
333 GNUNET_SCHEDULER_shutdown (); 333 GNUNET_SCHEDULER_shutdown();
334 return; 334 return;
335 } 335 }
336 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 336 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
337 { 337 {
338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 338 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
339 _("Expected no zone content but received data\n")); 339 _("Expected no zone content but received data\n"));
340 GNUNET_break (0); 340 GNUNET_break(0);
341 res = 2; 341 res = 2;
342 GNUNET_SCHEDULER_shutdown (); 342 GNUNET_SCHEDULER_shutdown();
343 return; 343 return;
344 } 344 }
345 GNUNET_assert (0); 345 GNUNET_assert(0);
346} 346}
347 347
348 348
349static void 349static void
350empty_zone_proc_end (void *cls) 350empty_zone_proc_end(void *cls)
351{ 351{
352 zi = NULL; 352 zi = NULL;
353 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 353 privkey = GNUNET_CRYPTO_ecdsa_key_create();
354 GNUNET_assert (privkey != NULL); 354 GNUNET_assert(privkey != NULL);
355 privkey2 = GNUNET_CRYPTO_ecdsa_key_create (); 355 privkey2 = GNUNET_CRYPTO_ecdsa_key_create();
356 GNUNET_assert (privkey2 != NULL); 356 GNUNET_assert(privkey2 != NULL);
357 357
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 358 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
359 "Created record 1\n"); 359 "Created record 1\n");
360 GNUNET_asprintf (&s_name_1, 360 GNUNET_asprintf(&s_name_1,
361 "dummy1"); 361 "dummy1");
362 s_rd_1 = create_record (1); 362 s_rd_1 = create_record(1);
363 GNUNET_NAMESTORE_records_store (nsh, 363 GNUNET_NAMESTORE_records_store(nsh,
364 privkey, 364 privkey,
365 s_name_1, 365 s_name_1,
366 1, 366 1,
367 s_rd_1, 367 s_rd_1,
368 &put_cont, 368 &put_cont,
369 NULL); 369 NULL);
370 370
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 371 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
372 "Created record 2 \n"); 372 "Created record 2 \n");
373 GNUNET_asprintf (&s_name_2, 373 GNUNET_asprintf(&s_name_2,
374 "dummy2"); 374 "dummy2");
375 s_rd_2 = create_record (1); 375 s_rd_2 = create_record(1);
376 GNUNET_NAMESTORE_records_store (nsh, 376 GNUNET_NAMESTORE_records_store(nsh,
377 privkey, 377 privkey,
378 s_name_2, 378 s_name_2,
379 1, 379 1,
380 s_rd_2, 380 s_rd_2,
381 &put_cont, 381 &put_cont,
382 NULL); 382 NULL);
383 383
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
385 "Created record 3\n"); 385 "Created record 3\n");
386 386
387 /* name in different zone */ 387 /* name in different zone */
388 GNUNET_asprintf (&s_name_3, 388 GNUNET_asprintf(&s_name_3,
389 "dummy3"); 389 "dummy3");
390 s_rd_3 = create_record (1); 390 s_rd_3 = create_record(1);
391 GNUNET_NAMESTORE_records_store (nsh, 391 GNUNET_NAMESTORE_records_store(nsh,
392 privkey2, 392 privkey2,
393 s_name_3, 393 s_name_3,
394 1, s_rd_3, 394 1, s_rd_3,
395 &put_cont, 395 &put_cont,
396 NULL); 396 NULL);
397} 397}
398 398
399 399
400static void 400static void
401run (void *cls, 401run(void *cls,
402 const struct GNUNET_CONFIGURATION_Handle *cfg, 402 const struct GNUNET_CONFIGURATION_Handle *cfg,
403 struct GNUNET_TESTING_Peer *peer) 403 struct GNUNET_TESTING_Peer *peer)
404{ 404{
405 GNUNET_SCHEDULER_add_shutdown (&end, 405 GNUNET_SCHEDULER_add_shutdown(&end,
406 NULL); 406 NULL);
407 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 407 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
408 &endbadly, 408 &endbadly,
409 NULL); 409 NULL);
410 nsh = GNUNET_NAMESTORE_connect (cfg); 410 nsh = GNUNET_NAMESTORE_connect(cfg);
411 GNUNET_break (NULL != nsh); 411 GNUNET_break(NULL != nsh);
412 /* first, iterate over empty namestore */ 412 /* first, iterate over empty namestore */
413 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 413 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
414 NULL, 414 NULL,
415 &fail_cb, 415 &fail_cb,
416 NULL, 416 NULL,
417 &empty_zone_proc, 417 &empty_zone_proc,
418 nsh, 418 nsh,
419 &empty_zone_proc_end, 419 &empty_zone_proc_end,
420 nsh); 420 nsh);
421 if (NULL == zi) 421 if (NULL == zi)
422 { 422 {
423 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 423 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
424 "Failed to create zone iterator\n"); 424 "Failed to create zone iterator\n");
425 GNUNET_break (0); 425 GNUNET_break(0);
426 GNUNET_SCHEDULER_shutdown (); 426 GNUNET_SCHEDULER_shutdown();
427 } 427 }
428} 428}
429 429
430 430
@@ -432,24 +432,24 @@ run (void *cls,
432 432
433 433
434int 434int
435main (int argc, char *argv[]) 435main(int argc, char *argv[])
436{ 436{
437 const char *plugin_name; 437 const char *plugin_name;
438 char *cfg_name; 438 char *cfg_name;
439 439
440 SETUP_CFG (plugin_name, cfg_name); 440 SETUP_CFG(plugin_name, cfg_name);
441 res = 1; 441 res = 1;
442 if (0 != 442 if (0 !=
443 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", 443 GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration-specific-zone",
444 cfg_name, 444 cfg_name,
445 &run, 445 &run,
446 NULL)) 446 NULL))
447 { 447 {
448 res = 1; 448 res = 1;
449 } 449 }
450 GNUNET_DISK_purge_cfg_dir (cfg_name, 450 GNUNET_DISK_purge_cfg_dir(cfg_name,
451 "GNUNET_TEST_HOME"); 451 "GNUNET_TEST_HOME");
452 GNUNET_free (cfg_name); 452 GNUNET_free(cfg_name);
453 return res; 453 return res;
454} 454}
455 455
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c
index 28f424b23..89007c82c 100644
--- a/src/namestore/test_namestore_api_zone_iteration_stop.c
+++ b/src/namestore/test_namestore_api_zone_iteration_stop.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_zone_iteration_stop.c 21 * @file namestore/test_namestore_api_zone_iteration_stop.c
22 * @brief testcase for zone iteration functionality: stop iterating of zones 22 * @brief testcase for zone iteration functionality: stop iterating of zones
@@ -29,8 +29,8 @@
29 29
30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT 30#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
31 31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 32#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
33#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) 33#define WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2)
34 34
35static struct GNUNET_NAMESTORE_Handle * nsh; 35static struct GNUNET_NAMESTORE_Handle * nsh;
36 36
@@ -63,257 +63,257 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
63 * @param cls handle to use to re-connect. 63 * @param cls handle to use to re-connect.
64 */ 64 */
65static void 65static void
66end (void *cls) 66end(void *cls)
67{ 67{
68 if (NULL != zi) 68 if (NULL != zi)
69 { 69 {
70 GNUNET_NAMESTORE_zone_iteration_stop (zi); 70 GNUNET_NAMESTORE_zone_iteration_stop(zi);
71 zi = NULL; 71 zi = NULL;
72 } 72 }
73 if (nsh != NULL) 73 if (nsh != NULL)
74 { 74 {
75 GNUNET_NAMESTORE_disconnect (nsh); 75 GNUNET_NAMESTORE_disconnect(nsh);
76 nsh = NULL; 76 nsh = NULL;
77 } 77 }
78 GNUNET_free_non_null (s_name_1); 78 GNUNET_free_non_null(s_name_1);
79 GNUNET_free_non_null (s_name_2); 79 GNUNET_free_non_null(s_name_2);
80 GNUNET_free_non_null (s_name_3); 80 GNUNET_free_non_null(s_name_3);
81 if (s_rd_1 != NULL) 81 if (s_rd_1 != NULL)
82 { 82 {
83 GNUNET_free ((void *)s_rd_1->data); 83 GNUNET_free((void *)s_rd_1->data);
84 GNUNET_free (s_rd_1); 84 GNUNET_free(s_rd_1);
85 } 85 }
86 if (s_rd_2 != NULL) 86 if (s_rd_2 != NULL)
87 { 87 {
88 GNUNET_free ((void *)s_rd_2->data); 88 GNUNET_free((void *)s_rd_2->data);
89 GNUNET_free (s_rd_2); 89 GNUNET_free(s_rd_2);
90 } 90 }
91 if (s_rd_3 != NULL) 91 if (s_rd_3 != NULL)
92 { 92 {
93 GNUNET_free ((void *)s_rd_3->data); 93 GNUNET_free((void *)s_rd_3->data);
94 GNUNET_free (s_rd_3); 94 GNUNET_free(s_rd_3);
95 } 95 }
96 if (privkey != NULL) 96 if (privkey != NULL)
97 { 97 {
98 GNUNET_free (privkey); 98 GNUNET_free(privkey);
99 privkey = NULL; 99 privkey = NULL;
100 } 100 }
101 if (privkey2 != NULL) 101 if (privkey2 != NULL)
102 { 102 {
103 GNUNET_free (privkey2); 103 GNUNET_free(privkey2);
104 privkey2 = NULL; 104 privkey2 = NULL;
105 } 105 }
106} 106}
107 107
108 108
109static void 109static void
110delayed_end (void *cls) 110delayed_end(void *cls)
111{ 111{
112 GNUNET_SCHEDULER_shutdown (); 112 GNUNET_SCHEDULER_shutdown();
113} 113}
114 114
115 115
116static void 116static void
117fail_cb (void *cls) 117fail_cb(void *cls)
118{ 118{
119 GNUNET_assert (0); 119 GNUNET_assert(0);
120} 120}
121 121
122 122
123static void 123static void
124zone_proc (void *cls, 124zone_proc(void *cls,
125 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 125 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
126 const char *label, 126 const char *label,
127 unsigned int rd_count, 127 unsigned int rd_count,
128 const struct GNUNET_GNSRECORD_Data *rd) 128 const struct GNUNET_GNSRECORD_Data *rd)
129{ 129{
130 int failed = GNUNET_NO; 130 int failed = GNUNET_NO;
131 131
132 GNUNET_assert (NULL != zone); 132 GNUNET_assert(NULL != zone);
133 if (0 == GNUNET_memcmp (zone, privkey)) 133 if (0 == GNUNET_memcmp(zone, privkey))
134 {
135 if (0 == strcmp (label, s_name_1))
136 { 134 {
137 if (rd_count == 1) 135 if (0 == strcmp(label, s_name_1))
138 {
139 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1))
140 { 136 {
141 failed = GNUNET_YES; 137 if (rd_count == 1)
142 GNUNET_break (0); 138 {
139 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_1))
140 {
141 failed = GNUNET_YES;
142 GNUNET_break(0);
143 }
144 }
145 else
146 {
147 failed = GNUNET_YES;
148 GNUNET_break(0);
149 }
150 }
151 else if (0 == strcmp(label, s_name_2))
152 {
153 if (rd_count == 1)
154 {
155 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
156 {
157 failed = GNUNET_YES;
158 GNUNET_break(0);
159 }
160 }
161 else
162 {
163 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
164 "Received invalid record count\n");
165 failed = GNUNET_YES;
166 GNUNET_break(0);
167 }
143 } 168 }
144 }
145 else 169 else
146 {
147 failed = GNUNET_YES;
148 GNUNET_break (0);
149 }
150 }
151 else if (0 == strcmp (label, s_name_2))
152 {
153 if (rd_count == 1)
154 {
155 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_2))
156 { 170 {
171 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
172 "Comparing result failed: got name `%s' for first zone\n", label);
157 failed = GNUNET_YES; 173 failed = GNUNET_YES;
158 GNUNET_break (0); 174 GNUNET_break(0);
159 } 175 }
160 }
161 else
162 {
163 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
164 "Received invalid record count\n");
165 failed = GNUNET_YES;
166 GNUNET_break (0);
167 }
168 }
169 else
170 {
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
172 "Comparing result failed: got name `%s' for first zone\n", label);
173 failed = GNUNET_YES;
174 GNUNET_break (0);
175 } 176 }
176 } 177 else if (0 == GNUNET_memcmp(zone, privkey2))
177 else if (0 == GNUNET_memcmp (zone, privkey2))
178 {
179 if (0 == strcmp (label, s_name_3))
180 { 178 {
181 if (rd_count == 1) 179 if (0 == strcmp(label, s_name_3))
182 {
183 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3))
184 { 180 {
185 failed = GNUNET_YES; 181 if (rd_count == 1)
186 GNUNET_break (0); 182 {
183 if (GNUNET_YES != GNUNET_GNSRECORD_records_cmp(rd, s_rd_3))
184 {
185 failed = GNUNET_YES;
186 GNUNET_break(0);
187 }
188 }
189 else
190 {
191 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
192 "Received invalid record count\n");
193 failed = GNUNET_YES;
194 GNUNET_break(0);
195 }
187 } 196 }
188 }
189 else 197 else
190 { 198 {
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 199 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
192 "Received invalid record count\n"); 200 "Comparing result failed: got name `%s' for first zone\n", label);
193 failed = GNUNET_YES; 201 failed = GNUNET_YES;
194 GNUNET_break (0); 202 GNUNET_break(0);
195 } 203 }
196 } 204 }
197 else 205 else
198 { 206 {
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 207 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
200 "Comparing result failed: got name `%s' for first zone\n", label); 208 "Received invalid zone\n");
201 failed = GNUNET_YES; 209 failed = GNUNET_YES;
202 GNUNET_break (0); 210 GNUNET_break(0);
203 } 211 }
204 }
205 else
206 {
207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
208 "Received invalid zone\n");
209 failed = GNUNET_YES;
210 GNUNET_break (0);
211 }
212 if (failed == GNUNET_NO) 212 if (failed == GNUNET_NO)
213 {
214 if (1 == returned_records)
215 { 213 {
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 214 if (1 == returned_records)
217 "Telling namestore to stop zone iteration\n"); 215 {
218 GNUNET_NAMESTORE_zone_iteration_stop (zi); 216 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
219 zi = NULL; 217 "Telling namestore to stop zone iteration\n");
220 res = 0; 218 GNUNET_NAMESTORE_zone_iteration_stop(zi);
221 GNUNET_SCHEDULER_add_delayed (WAIT, 219 zi = NULL;
222 &delayed_end, 220 res = 0;
223 NULL); 221 GNUNET_SCHEDULER_add_delayed(WAIT,
224 return; 222 &delayed_end,
223 NULL);
224 return;
225 }
226 returned_records++;
227 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
228 "Telling namestore to send the next result\n");
229 GNUNET_NAMESTORE_zone_iterator_next(zi,
230 1);
225 } 231 }
226 returned_records ++;
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Telling namestore to send the next result\n");
229 GNUNET_NAMESTORE_zone_iterator_next (zi,
230 1);
231 }
232 else 232 else
233 { 233 {
234 GNUNET_break (0); 234 GNUNET_break(0);
235 GNUNET_SCHEDULER_shutdown (); 235 GNUNET_SCHEDULER_shutdown();
236 } 236 }
237} 237}
238 238
239 239
240static void 240static void
241zone_proc_end (void *cls) 241zone_proc_end(void *cls)
242{ 242{
243 GNUNET_break (1 <= returned_records); 243 GNUNET_break(1 <= returned_records);
244 if (1 >= returned_records) 244 if (1 >= returned_records)
245 res = 1; /* Last iteraterator callback, we are done */ 245 res = 1; /* Last iteraterator callback, we are done */
246 else 246 else
247 res = 0; 247 res = 0;
248 zi = NULL; 248 zi = NULL;
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 249 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
250 "Received last result, iteration done after receing %u results\n", 250 "Received last result, iteration done after receing %u results\n",
251 returned_records); 251 returned_records);
252 GNUNET_SCHEDULER_add_now (&end, NULL); 252 GNUNET_SCHEDULER_add_now(&end, NULL);
253} 253}
254 254
255 255
256static void 256static void
257put_cont (void *cls, int32_t success, const char *emsg) 257put_cont(void *cls, int32_t success, const char *emsg)
258{ 258{
259 static int c = 0; 259 static int c = 0;
260 260
261 if (success == GNUNET_OK) 261 if (success == GNUNET_OK)
262 { 262 {
263 c++; 263 c++;
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); 264 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
265 } 265 }
266 else 266 else
267 { 267 {
268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", 268 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n",
269 emsg); 269 emsg);
270 GNUNET_break (0); 270 GNUNET_break(0);
271 GNUNET_SCHEDULER_shutdown (); 271 GNUNET_SCHEDULER_shutdown();
272 return; 272 return;
273 } 273 }
274 274
275 if (c == 3) 275 if (c == 3)
276 {
277 res = 1;
278 returned_records = 0;
279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
280 "All records created, starting iteration over all zones \n");
281 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
282 NULL,
283 &fail_cb,
284 NULL,
285 &zone_proc,
286 NULL,
287 &zone_proc_end,
288 NULL);
289 if (zi == NULL)
290 { 276 {
291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 277 res = 1;
292 "Failed to create zone iterator\n"); 278 returned_records = 0;
293 GNUNET_break (0); 279 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
294 GNUNET_SCHEDULER_shutdown (); 280 "All records created, starting iteration over all zones \n");
295 return; 281 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
282 NULL,
283 &fail_cb,
284 NULL,
285 &zone_proc,
286 NULL,
287 &zone_proc_end,
288 NULL);
289 if (zi == NULL)
290 {
291 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
292 "Failed to create zone iterator\n");
293 GNUNET_break(0);
294 GNUNET_SCHEDULER_shutdown();
295 return;
296 }
296 } 297 }
297 }
298} 298}
299 299
300 300
301static struct GNUNET_GNSRECORD_Data * 301static struct GNUNET_GNSRECORD_Data *
302create_record (unsigned int count) 302create_record(unsigned int count)
303{ 303{
304 struct GNUNET_GNSRECORD_Data *rd; 304 struct GNUNET_GNSRECORD_Data *rd;
305 305
306 rd = GNUNET_new_array (count, 306 rd = GNUNET_new_array(count,
307 struct GNUNET_GNSRECORD_Data); 307 struct GNUNET_GNSRECORD_Data);
308 for (unsigned int c = 0; c < count; c++) 308 for (unsigned int c = 0; c < count; c++)
309 { 309 {
310 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 310 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us;
311 rd[c].record_type = TEST_RECORD_TYPE; 311 rd[c].record_type = TEST_RECORD_TYPE;
312 rd[c].data_size = 50; 312 rd[c].data_size = 50;
313 rd[c].data = GNUNET_malloc(50); 313 rd[c].data = GNUNET_malloc(50);
314 rd[c].flags = 0; 314 rd[c].flags = 0;
315 memset ((char *) rd[c].data, 'a', 50); 315 memset((char *)rd[c].data, 'a', 50);
316 } 316 }
317 return rd; 317 return rd;
318} 318}
319 319
@@ -324,86 +324,85 @@ create_record (unsigned int count)
324 * start the actual tests by filling the zone. 324 * start the actual tests by filling the zone.
325 */ 325 */
326static void 326static void
327empty_zone_proc (void *cls, 327empty_zone_proc(void *cls,
328 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 328 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
329 const char *label, 329 const char *label,
330 unsigned int rd_count, 330 unsigned int rd_count,
331 const struct GNUNET_GNSRECORD_Data *rd) 331 const struct GNUNET_GNSRECORD_Data *rd)
332{ 332{
333 333 GNUNET_assert(nsh == cls);
334 GNUNET_assert (nsh == cls);
335 if (NULL != zone) 334 if (NULL != zone)
336 { 335 {
337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 336 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
338 _("Expected empty zone but received zone private key\n")); 337 _("Expected empty zone but received zone private key\n"));
339 GNUNET_break (0); 338 GNUNET_break(0);
340 GNUNET_SCHEDULER_shutdown (); 339 GNUNET_SCHEDULER_shutdown();
341 return; 340 return;
342 } 341 }
343 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 342 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
344 { 343 {
345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 344 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
346 _("Expected no zone content but received data\n")); 345 _("Expected no zone content but received data\n"));
347 GNUNET_break (0); 346 GNUNET_break(0);
348 GNUNET_SCHEDULER_shutdown (); 347 GNUNET_SCHEDULER_shutdown();
349 return; 348 return;
350 } 349 }
351 GNUNET_assert (0); 350 GNUNET_assert(0);
352} 351}
353 352
354 353
355static void 354static void
356empty_zone_proc_end (void *cls) 355empty_zone_proc_end(void *cls)
357{ 356{
358 char *hostkey_file; 357 char *hostkey_file;
359 358
360 GNUNET_assert (nsh == cls); 359 GNUNET_assert(nsh == cls);
361 zi = NULL; 360 zi = NULL;
362 GNUNET_asprintf(&hostkey_file, 361 GNUNET_asprintf(&hostkey_file,
363 "zonefiles%s%s", 362 "zonefiles%s%s",
364 DIR_SEPARATOR_STR, 363 DIR_SEPARATOR_STR,
365 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 364 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
367 "Using zonekey file `%s' \n", 366 "Using zonekey file `%s' \n",
368 hostkey_file); 367 hostkey_file);
369 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 368 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
370 GNUNET_free (hostkey_file); 369 GNUNET_free(hostkey_file);
371 GNUNET_assert (privkey != NULL); 370 GNUNET_assert(privkey != NULL);
372 371
373 GNUNET_asprintf (&hostkey_file, 372 GNUNET_asprintf(&hostkey_file,
374 "zonefiles%s%s", 373 "zonefiles%s%s",
375 DIR_SEPARATOR_STR, 374 DIR_SEPARATOR_STR,
376 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 375 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 376 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
378 "Using zonekey file `%s'\n", 377 "Using zonekey file `%s'\n",
379 hostkey_file); 378 hostkey_file);
380 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 379 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
381 GNUNET_free (hostkey_file); 380 GNUNET_free(hostkey_file);
382 GNUNET_assert (privkey2 != NULL); 381 GNUNET_assert(privkey2 != NULL);
383 382
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 383 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
385 "Created record 1\n"); 384 "Created record 1\n");
386 385
387 GNUNET_asprintf(&s_name_1, 386 GNUNET_asprintf(&s_name_1,
388 "dummy1"); 387 "dummy1");
389 s_rd_1 = create_record(1); 388 s_rd_1 = create_record(1);
390 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 389 GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
391 1, s_rd_1, &put_cont, NULL); 390 1, s_rd_1, &put_cont, NULL);
392 391
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
394 "Created record 2 \n"); 393 "Created record 2 \n");
395 GNUNET_asprintf(&s_name_2, 394 GNUNET_asprintf(&s_name_2,
396 "dummy2"); 395 "dummy2");
397 s_rd_2 = create_record(1); 396 s_rd_2 = create_record(1);
398 GNUNET_NAMESTORE_records_store (nsh, 397 GNUNET_NAMESTORE_records_store(nsh,
399 privkey, 398 privkey,
400 s_name_2, 399 s_name_2,
401 1, 400 1,
402 s_rd_2, 401 s_rd_2,
403 &put_cont, NULL); 402 &put_cont, NULL);
404 403
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 404 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
406 "Created record 3\n"); 405 "Created record 3\n");
407 406
408 /* name in different zone */ 407 /* name in different zone */
409 GNUNET_asprintf(&s_name_3, "dummy3"); 408 GNUNET_asprintf(&s_name_3, "dummy3");
@@ -418,30 +417,30 @@ empty_zone_proc_end (void *cls)
418 417
419 418
420static void 419static void
421run (void *cls, 420run(void *cls,
422 const struct GNUNET_CONFIGURATION_Handle *cfg, 421 const struct GNUNET_CONFIGURATION_Handle *cfg,
423 struct GNUNET_TESTING_Peer *peer) 422 struct GNUNET_TESTING_Peer *peer)
424{ 423{
425 nsh = GNUNET_NAMESTORE_connect (cfg); 424 nsh = GNUNET_NAMESTORE_connect(cfg);
426 GNUNET_break (NULL != nsh); 425 GNUNET_break(NULL != nsh);
427 GNUNET_SCHEDULER_add_shutdown (&end, 426 GNUNET_SCHEDULER_add_shutdown(&end,
428 NULL); 427 NULL);
429 /* first, iterate over empty namestore */ 428 /* first, iterate over empty namestore */
430 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 429 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
431 NULL, 430 NULL,
432 &fail_cb, 431 &fail_cb,
433 NULL, 432 NULL,
434 &empty_zone_proc, 433 &empty_zone_proc,
435 nsh, 434 nsh,
436 &empty_zone_proc_end, 435 &empty_zone_proc_end,
437 nsh); 436 nsh);
438 if (NULL == zi) 437 if (NULL == zi)
439 { 438 {
440 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 439 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
441 "Failed to create zone iterator\n"); 440 "Failed to create zone iterator\n");
442 GNUNET_break (0); 441 GNUNET_break(0);
443 GNUNET_SCHEDULER_shutdown (); 442 GNUNET_SCHEDULER_shutdown();
444 } 443 }
445} 444}
446 445
447 446
@@ -449,24 +448,24 @@ run (void *cls,
449 448
450 449
451int 450int
452main (int argc, char *argv[]) 451main(int argc, char *argv[])
453{ 452{
454 const char *plugin_name; 453 const char *plugin_name;
455 char *cfg_name; 454 char *cfg_name;
456 455
457 SETUP_CFG (plugin_name, cfg_name); 456 SETUP_CFG(plugin_name, cfg_name);
458 res = 1; 457 res = 1;
459 if (0 != 458 if (0 !=
460 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", 459 GNUNET_TESTING_peer_run("test-namestore-api-zone-iteration-stop",
461 cfg_name, 460 cfg_name,
462 &run, 461 &run,
463 NULL)) 462 NULL))
464 { 463 {
465 res = 1; 464 res = 1;
466 } 465 }
467 GNUNET_DISK_purge_cfg_dir (cfg_name, 466 GNUNET_DISK_purge_cfg_dir(cfg_name,
468 "GNUNET_TEST_HOME"); 467 "GNUNET_TEST_HOME");
469 GNUNET_free (cfg_name); 468 GNUNET_free(cfg_name);
470 469
471 return res; 470 return res;
472} 471}
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index cb580572e..0c02c9a52 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_zone_to_name.c 21 * @file namestore/test_namestore_api_zone_to_name.c
22 * @brief testcase for zone to name translation 22 * @brief testcase for zone to name translation
@@ -35,7 +35,7 @@
35 35
36#define TEST_RECORD_DATA 'a' 36#define TEST_RECORD_DATA 'a'
37 37
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 38#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
39 39
40 40
41static struct GNUNET_NAMESTORE_Handle *nsh; 41static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -61,180 +61,180 @@ static struct GNUNET_NAMESTORE_QueueEntry *qe;
61 * @param cls handle to use to re-connect. 61 * @param cls handle to use to re-connect.
62 */ 62 */
63static void 63static void
64endbadly (void *cls) 64endbadly(void *cls)
65{ 65{
66 (void) cls; 66 (void)cls;
67 GNUNET_SCHEDULER_shutdown (); 67 GNUNET_SCHEDULER_shutdown();
68 res = 1; 68 res = 1;
69} 69}
70 70
71 71
72static void 72static void
73end (void *cls) 73end(void *cls)
74{ 74{
75 if (NULL != qe) 75 if (NULL != qe)
76 { 76 {
77 GNUNET_NAMESTORE_cancel (qe); 77 GNUNET_NAMESTORE_cancel(qe);
78 qe = NULL; 78 qe = NULL;
79 } 79 }
80 if (NULL != endbadly_task) 80 if (NULL != endbadly_task)
81 { 81 {
82 GNUNET_SCHEDULER_cancel (endbadly_task); 82 GNUNET_SCHEDULER_cancel(endbadly_task);
83 endbadly_task = NULL; 83 endbadly_task = NULL;
84 } 84 }
85 if (NULL != privkey) 85 if (NULL != privkey)
86 { 86 {
87 GNUNET_free (privkey); 87 GNUNET_free(privkey);
88 privkey = NULL; 88 privkey = NULL;
89 } 89 }
90 if (NULL != nsh) 90 if (NULL != nsh)
91 { 91 {
92 GNUNET_NAMESTORE_disconnect (nsh); 92 GNUNET_NAMESTORE_disconnect(nsh);
93 nsh = NULL; 93 nsh = NULL;
94 } 94 }
95} 95}
96 96
97 97
98static void 98static void
99zone_to_name_proc (void *cls, 99zone_to_name_proc(void *cls,
100 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 100 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
101 const char *n, 101 const char *n,
102 unsigned int rd_count, 102 unsigned int rd_count,
103 const struct GNUNET_GNSRECORD_Data *rd) 103 const struct GNUNET_GNSRECORD_Data *rd)
104{ 104{
105 int fail = GNUNET_NO; 105 int fail = GNUNET_NO;
106 106
107 qe = NULL; 107 qe = NULL;
108 if ( (NULL == zone_key) && 108 if ((NULL == zone_key) &&
109 (NULL == n) && 109 (NULL == n) &&
110 (0 == rd_count) && 110 (0 == rd_count) &&
111 (NULL == rd) ) 111 (NULL == rd))
112 {
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
114 "No result found\n");
115 res = 1;
116 }
117 else
118 {
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 "Result found: `%s'\n",
121 n);
122 if ( (NULL == n) ||
123 (0 != strcmp (n,
124 s_name)))
125 { 112 {
126 fail = GNUNET_YES; 113 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
127 GNUNET_break (0); 114 "No result found\n");
128 } 115 res = 1;
129 if (1 != rd_count)
130 {
131 fail = GNUNET_YES;
132 GNUNET_break (0);
133 } 116 }
134 if ( (NULL == zone_key) || 117 else
135 (0 != GNUNET_memcmp (zone_key,
136 privkey)))
137 { 118 {
138 fail = GNUNET_YES; 119 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
139 GNUNET_break (0); 120 "Result found: `%s'\n",
121 n);
122 if ((NULL == n) ||
123 (0 != strcmp(n,
124 s_name)))
125 {
126 fail = GNUNET_YES;
127 GNUNET_break(0);
128 }
129 if (1 != rd_count)
130 {
131 fail = GNUNET_YES;
132 GNUNET_break(0);
133 }
134 if ((NULL == zone_key) ||
135 (0 != GNUNET_memcmp(zone_key,
136 privkey)))
137 {
138 fail = GNUNET_YES;
139 GNUNET_break(0);
140 }
141 if (fail == GNUNET_NO)
142 res = 0;
143 else
144 res = 1;
140 } 145 }
141 if (fail == GNUNET_NO) 146 GNUNET_SCHEDULER_add_now(&end,
142 res = 0; 147 NULL);
143 else
144 res = 1;
145 }
146 GNUNET_SCHEDULER_add_now (&end,
147 NULL);
148} 148}
149 149
150 150
151static void 151static void
152error_cb (void *cls) 152error_cb(void *cls)
153{ 153{
154 (void) cls; 154 (void)cls;
155 qe = NULL; 155 qe = NULL;
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 156 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
157 "Not found!\n"); 157 "Not found!\n");
158 GNUNET_SCHEDULER_shutdown (); 158 GNUNET_SCHEDULER_shutdown();
159 res = 2; 159 res = 2;
160} 160}
161 161
162 162
163static void 163static void
164put_cont (void *cls, 164put_cont(void *cls,
165 int32_t success, 165 int32_t success,
166 const char *emsg) 166 const char *emsg)
167{ 167{
168 char *name = cls; 168 char *name = cls;
169 169
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 170 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
171 "Name store added record for `%s': %s\n", 171 "Name store added record for `%s': %s\n",
172 name, 172 name,
173 (success == GNUNET_OK) ? "SUCCESS" : emsg); 173 (success == GNUNET_OK) ? "SUCCESS" : emsg);
174 if (success == GNUNET_OK) 174 if (success == GNUNET_OK)
175 { 175 {
176 res = 0; 176 res = 0;
177 177
178 qe = GNUNET_NAMESTORE_zone_to_name (nsh, 178 qe = GNUNET_NAMESTORE_zone_to_name(nsh,
179 privkey, 179 privkey,
180 &s_zone_value, 180 &s_zone_value,
181 &error_cb, 181 &error_cb,
182 NULL, 182 NULL,
183 &zone_to_name_proc, 183 &zone_to_name_proc,
184 NULL); 184 NULL);
185 } 185 }
186 else 186 else
187 { 187 {
188 res = 1; 188 res = 1;
189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 189 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
190 "Failed to put records for name `%s'\n", 190 "Failed to put records for name `%s'\n",
191 name); 191 name);
192 GNUNET_SCHEDULER_add_now (&end, 192 GNUNET_SCHEDULER_add_now(&end,
193 NULL); 193 NULL);
194 } 194 }
195} 195}
196 196
197 197
198static void 198static void
199run (void *cls, 199run(void *cls,
200 const struct GNUNET_CONFIGURATION_Handle *cfg, 200 const struct GNUNET_CONFIGURATION_Handle *cfg,
201 struct GNUNET_TESTING_Peer *peer) 201 struct GNUNET_TESTING_Peer *peer)
202{ 202{
203 (void) cls; 203 (void)cls;
204 (void) peer; 204 (void)peer;
205 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 205 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
206 &endbadly, 206 &endbadly,
207 NULL); 207 NULL);
208 GNUNET_SCHEDULER_add_shutdown (&end, 208 GNUNET_SCHEDULER_add_shutdown(&end,
209 NULL); 209 NULL);
210 GNUNET_asprintf (&s_name, "dummy"); 210 GNUNET_asprintf(&s_name, "dummy");
211 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 211 privkey = GNUNET_CRYPTO_ecdsa_key_create();
212 GNUNET_assert (NULL != privkey); 212 GNUNET_assert(NULL != privkey);
213 /* get public key */ 213 /* get public key */
214 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 214 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
215 &pubkey); 215 &pubkey);
216 216
217 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, 217 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK,
218 &s_zone_value, 218 &s_zone_value,
219 sizeof (s_zone_value)); 219 sizeof(s_zone_value));
220 { 220 {
221 struct GNUNET_GNSRECORD_Data rd; 221 struct GNUNET_GNSRECORD_Data rd;
222 222
223 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 223 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
224 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 224 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
225 rd.data_size = sizeof (s_zone_value); 225 rd.data_size = sizeof(s_zone_value);
226 rd.data = &s_zone_value; 226 rd.data = &s_zone_value;
227 rd.flags = 0; 227 rd.flags = 0;
228 228
229 nsh = GNUNET_NAMESTORE_connect (cfg); 229 nsh = GNUNET_NAMESTORE_connect(cfg);
230 GNUNET_break (NULL != nsh); 230 GNUNET_break(NULL != nsh);
231 GNUNET_NAMESTORE_records_store (nsh, 231 GNUNET_NAMESTORE_records_store(nsh,
232 privkey, 232 privkey,
233 s_name, 233 s_name,
234 1, 234 1,
235 &rd, 235 &rd,
236 &put_cont, 236 &put_cont,
237 NULL); 237 NULL);
238 } 238 }
239} 239}
240 240
@@ -243,26 +243,26 @@ run (void *cls,
243 243
244 244
245int 245int
246main (int argc, 246main(int argc,
247 char *argv[]) 247 char *argv[])
248{ 248{
249 const char *plugin_name; 249 const char *plugin_name;
250 char *cfg_name; 250 char *cfg_name;
251 251
252 (void) argc; 252 (void)argc;
253 SETUP_CFG (plugin_name, cfg_name); 253 SETUP_CFG(plugin_name, cfg_name);
254 res = 1; 254 res = 1;
255 if (0 != 255 if (0 !=
256 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", 256 GNUNET_TESTING_peer_run("test-namestore-api-zone-to-name",
257 cfg_name, 257 cfg_name,
258 &run, 258 &run,
259 NULL)) 259 NULL))
260 { 260 {
261 res = 1; 261 res = 1;
262 } 262 }
263 GNUNET_DISK_purge_cfg_dir (cfg_name, 263 GNUNET_DISK_purge_cfg_dir(cfg_name,
264 "GNUNET_TEST_HOME"); 264 "GNUNET_TEST_HOME");
265 GNUNET_free (cfg_name); 265 GNUNET_free(cfg_name);
266 return res; 266 return res;
267} 267}
268 268
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index b4ed4c70d..8fb30b651 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/* 20/*
21 * @file namestore/test_plugin_namestore.c 21 * @file namestore/test_plugin_namestore.c
22 * @brief Test for the namestore plugins 22 * @brief Test for the namestore plugins
@@ -45,13 +45,13 @@ static const char *plugin_name;
45 * @param api api to unload 45 * @param api api to unload
46 */ 46 */
47static void 47static void
48unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api) 48unload_plugin(struct GNUNET_NAMESTORE_PluginFunctions *api)
49{ 49{
50 char *libname; 50 char *libname;
51 51
52 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); 52 GNUNET_asprintf(&libname, "libgnunet_plugin_namestore_%s", plugin_name);
53 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); 53 GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api));
54 GNUNET_free (libname); 54 GNUNET_free(libname);
55} 55}
56 56
57 57
@@ -62,33 +62,33 @@ unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
62 * @return NULL on error 62 * @return NULL on error
63 */ 63 */
64static struct GNUNET_NAMESTORE_PluginFunctions * 64static struct GNUNET_NAMESTORE_PluginFunctions *
65load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) 65load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg)
66{ 66{
67 struct GNUNET_NAMESTORE_PluginFunctions *ret; 67 struct GNUNET_NAMESTORE_PluginFunctions *ret;
68 char *libname; 68 char *libname;
69 69
70 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 70 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
71 _ ("Loading `%s' namestore plugin\n"), 71 _("Loading `%s' namestore plugin\n"),
72 plugin_name); 72 plugin_name);
73 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); 73 GNUNET_asprintf(&libname, "libgnunet_plugin_namestore_%s", plugin_name);
74 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg))) 74 if (NULL == (ret = GNUNET_PLUGIN_load(libname, (void *)cfg)))
75 { 75 {
76 fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name); 76 fprintf(stderr, "Failed to load plugin `%s'!\n", plugin_name);
77 GNUNET_free (libname); 77 GNUNET_free(libname);
78 return NULL; 78 return NULL;
79 } 79 }
80 GNUNET_free (libname); 80 GNUNET_free(libname);
81 return ret; 81 return ret;
82} 82}
83 83
84 84
85static void 85static void
86test_record (void *cls, 86test_record(void *cls,
87 uint64_t seq, 87 uint64_t seq,
88 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, 88 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
89 const char *label, 89 const char *label,
90 unsigned int rd_count, 90 unsigned int rd_count,
91 const struct GNUNET_GNSRECORD_Data *rd) 91 const struct GNUNET_GNSRECORD_Data *rd)
92{ 92{
93 int *idp = cls; 93 int *idp = cls;
94 int id = *idp; 94 int id = *idp;
@@ -96,106 +96,106 @@ test_record (void *cls,
96 char tname[64]; 96 char tname[64];
97 unsigned int trd_count = 1 + (id % 1024); 97 unsigned int trd_count = 1 + (id % 1024);
98 98
99 GNUNET_snprintf (tname, sizeof (tname), "a%u", (unsigned int) id); 99 GNUNET_snprintf(tname, sizeof(tname), "a%u", (unsigned int)id);
100 GNUNET_assert (trd_count == rd_count); 100 GNUNET_assert(trd_count == rd_count);
101 for (unsigned int i = 0; i < trd_count; i++) 101 for (unsigned int i = 0; i < trd_count; i++)
102 { 102 {
103 GNUNET_assert (rd[i].data_size == id % 10); 103 GNUNET_assert(rd[i].data_size == id % 10);
104 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); 104 GNUNET_assert(0 == memcmp("Hello World", rd[i].data, id % 10));
105 GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE); 105 GNUNET_assert(rd[i].record_type == TEST_RECORD_TYPE);
106 GNUNET_assert (rd[i].flags == 0); 106 GNUNET_assert(rd[i].flags == 0);
107 } 107 }
108 memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key)); 108 memset(&tzone_private_key, (id % 241), sizeof(tzone_private_key));
109 GNUNET_assert (0 == strcmp (label, tname)); 109 GNUNET_assert(0 == strcmp(label, tname));
110 GNUNET_assert (0 == GNUNET_memcmp (&tzone_private_key, private_key)); 110 GNUNET_assert(0 == GNUNET_memcmp(&tzone_private_key, private_key));
111} 111}
112 112
113 113
114static void 114static void
115get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 115get_record(struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
116{ 116{
117 GNUNET_assert ( 117 GNUNET_assert(
118 GNUNET_OK == 118 GNUNET_OK ==
119 nsp->iterate_records (nsp->cls, NULL, 0, 1, &test_record, &id)); 119 nsp->iterate_records(nsp->cls, NULL, 0, 1, &test_record, &id));
120} 120}
121 121
122 122
123static void 123static void
124put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 124put_record(struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
125{ 125{
126 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; 126 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
127 char label[64]; 127 char label[64];
128 unsigned int rd_count = 1 + (id % 1024); 128 unsigned int rd_count = 1 + (id % 1024);
129 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; 129 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
130 struct GNUNET_CRYPTO_EcdsaSignature signature; 130 struct GNUNET_CRYPTO_EcdsaSignature signature;
131 131
132 GNUNET_snprintf (label, sizeof (label), "a%u", (unsigned int) id); 132 GNUNET_snprintf(label, sizeof(label), "a%u", (unsigned int)id);
133 for (unsigned int i = 0; i < rd_count; i++) 133 for (unsigned int i = 0; i < rd_count; i++)
134 { 134 {
135 rd[i].data = "Hello World"; 135 rd[i].data = "Hello World";
136 rd[i].data_size = id % 10; 136 rd[i].data_size = id % 10;
137 rd[i].expiration_time = 137 rd[i].expiration_time =
138 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us; 138 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES).abs_value_us;
139 rd[i].record_type = TEST_RECORD_TYPE; 139 rd[i].record_type = TEST_RECORD_TYPE;
140 rd[i].flags = 0; 140 rd[i].flags = 0;
141 } 141 }
142 memset (&zone_private_key, (id % 241), sizeof (zone_private_key)); 142 memset(&zone_private_key, (id % 241), sizeof(zone_private_key));
143 memset (&signature, (id % 243), sizeof (signature)); 143 memset(&signature, (id % 243), sizeof(signature));
144 GNUNET_assert ( 144 GNUNET_assert(
145 GNUNET_OK == 145 GNUNET_OK ==
146 nsp->store_records (nsp->cls, &zone_private_key, label, rd_count, rd)); 146 nsp->store_records(nsp->cls, &zone_private_key, label, rd_count, rd));
147} 147}
148 148
149 149
150static void 150static void
151run (void *cls, 151run(void *cls,
152 char *const *args, 152 char *const *args,
153 const char *cfgfile, 153 const char *cfgfile,
154 const struct GNUNET_CONFIGURATION_Handle *cfg) 154 const struct GNUNET_CONFIGURATION_Handle *cfg)
155{ 155{
156 struct GNUNET_NAMESTORE_PluginFunctions *nsp; 156 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
157 157
158 ok = 0; 158 ok = 0;
159 nsp = load_plugin (cfg); 159 nsp = load_plugin(cfg);
160 if (NULL == nsp) 160 if (NULL == nsp)
161 { 161 {
162 fprintf ( 162 fprintf(
163 stderr, 163 stderr,
164 "%s", 164 "%s",
165 "Failed to initialize namestore. Database likely not setup, skipping test.\n"); 165 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
166 return; 166 return;
167 } 167 }
168 put_record (nsp, 1); 168 put_record(nsp, 1);
169 get_record (nsp, 1); 169 get_record(nsp, 1);
170 170
171 unload_plugin (nsp); 171 unload_plugin(nsp);
172} 172}
173 173
174 174
175int 175int
176main (int argc, char *argv[]) 176main(int argc, char *argv[])
177{ 177{
178 char cfg_name[PATH_MAX]; 178 char cfg_name[PATH_MAX];
179 char *const xargv[] = {"test-plugin-namestore", "-c", cfg_name, NULL}; 179 char *const xargv[] = { "test-plugin-namestore", "-c", cfg_name, NULL };
180 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; 180 struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END };
181 181
182 GNUNET_log_setup ("test-plugin-namestore", "WARNING", NULL); 182 GNUNET_log_setup("test-plugin-namestore", "WARNING", NULL);
183 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 183 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]);
184 GNUNET_snprintf (cfg_name, 184 GNUNET_snprintf(cfg_name,
185 sizeof (cfg_name), 185 sizeof(cfg_name),
186 "test_plugin_namestore_%s.conf", 186 "test_plugin_namestore_%s.conf",
187 plugin_name); 187 plugin_name);
188 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP"); 188 GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TMP");
189 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 189 GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1,
190 xargv, 190 xargv,
191 "test-plugin-namestore", 191 "test-plugin-namestore",
192 "nohelp", 192 "nohelp",
193 options, 193 options,
194 &run, 194 &run,
195 NULL); 195 NULL);
196 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP"); 196 GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TMP");
197 if (ok != 0) 197 if (ok != 0)
198 fprintf (stderr, "Missed some testcases: %d\n", ok); 198 fprintf(stderr, "Missed some testcases: %d\n", ok);
199 return ok; 199 return ok;
200} 200}
201 201