aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-05-13 14:28:03 +0000
committerChristian Grothoff <christian@grothoff.org>2014-05-13 14:28:03 +0000
commit3152ce783fb3c297af673e23297303c62f061a71 (patch)
tree98bef1ce45a698d11dc27918894dee6c36876155 /src/namestore
parent9948a0b7e77fa3ae2d6ed28d7dc50236e869fc93 (diff)
downloadgnunet-3152ce783fb3c297af673e23297303c62f061a71.tar.gz
gnunet-3152ce783fb3c297af673e23297303c62f061a71.zip
fixing #3302: match record type and value as well during deletion, if specified
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-namestore.c93
1 files changed, 87 insertions, 6 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 8dc35984e..07c79f033 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -537,6 +537,88 @@ handle_reverse_lookup (void *cls,
537 537
538 538
539/** 539/**
540 * We were asked to delete something; this function is called with
541 * the existing records. Now we should determine what should be
542 * deleted and then issue the deletion operation.
543 *
544 * @param cls NULL
545 * @param zone private key of the zone we are deleting from
546 * @param label name of the records we are editing
547 * @param rd_count size of the @a rd array
548 * @param rd existing records
549 */
550static void
551del_monitor (void *cls,
552 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
553 const char *label,
554 unsigned int rd_count,
555 const struct GNUNET_GNSRECORD_Data *rd)
556{
557 struct GNUNET_GNSRECORD_Data rdx[rd_count];
558 unsigned int rd_left;
559 unsigned int i;
560 uint32_t type;
561 char *vs;
562
563 del_qe = NULL;
564 if (0 == rd_count)
565 {
566 FPRINTF (stderr,
567 _("There are no records under label `%s' that could be deleted.\n"),
568 label);
569 test_finished ();
570 return;
571 }
572 if ( (NULL == value) &&
573 (NULL == typestring) )
574 {
575 /* delete everything */
576 del_qe = GNUNET_NAMESTORE_records_store (ns,
577 &zone_pkey,
578 name,
579 0, NULL,
580 &del_continuation,
581 NULL);
582 return;
583 }
584 rd_left = 0;
585 if (NULL != typestring)
586 type = GNUNET_GNSRECORD_typename_to_number (typestring);
587 else
588 type = GNUNET_GNSRECORD_TYPE_ANY;
589 for (i=0;i<rd_count;i++)
590 {
591 vs = NULL;
592 if (! ( ( (GNUNET_GNSRECORD_TYPE_ANY == type) ||
593 (rd[i].record_type == type) ) &&
594 ( (NULL == value) ||
595 (NULL == (vs = (GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
596 rd[i].data,
597 rd[i].data_size)))) ||
598 (0 == strcmp (vs, value)) ) ) )
599 rdx[rd_left++] = rd[i];
600 GNUNET_free_non_null (vs);
601 }
602 if (rd_count == rd_left)
603 {
604 /* nothing got deleted */
605 FPRINTF (stderr,
606 _("There are no records under label `%s' that match the request for deletion.\n"),
607 label);
608 test_finished ();
609 return;
610 }
611 /* delete everything but what we copied to 'rdx' */
612 del_qe = GNUNET_NAMESTORE_records_store (ns,
613 &zone_pkey,
614 name,
615 rd_left, rdx,
616 &del_continuation,
617 NULL);
618}
619
620
621/**
540 * Function called with the result from the check if the namestore 622 * Function called with the result from the check if the namestore
541 * service is actually running. If it is, we start the actual 623 * service is actually running. If it is, we start the actual
542 * operation. 624 * operation.
@@ -675,12 +757,11 @@ testservice_task (void *cls,
675 ret = 1; 757 ret = 1;
676 return; 758 return;
677 } 759 }
678 del_qe = GNUNET_NAMESTORE_records_store (ns, 760 del_qe = GNUNET_NAMESTORE_records_lookup (ns,
679 &zone_pkey, 761 &zone_pkey,
680 name, 762 name,
681 0, NULL, 763 &del_monitor,
682 &del_continuation, 764 NULL);
683 NULL);
684 } 765 }
685 if (list) 766 if (list)
686 { 767 {