aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-namestore.c
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/gnunet-namestore.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/namestore/gnunet-namestore.c')
-rw-r--r--src/namestore/gnunet-namestore.c1779
1 files changed, 891 insertions, 888 deletions
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