]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add a helper function to facilitate preparing dns_diff_t structures
authorMichał Kępień <michal@isc.org>
Tue, 13 Mar 2018 13:06:06 +0000 (14:06 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 9 May 2018 11:21:01 +0000 (13:21 +0200)
Implement dns_test_difffromchanges(), a function which enables preparing
a dns_diff_t structure from a mostly-textual representation of zone
database changes to be applied.  This will improve readability of test
case definitions by allowing contents of a dns_diff_t structure, passed
e.g. to update_sigs(), to be represented in a human-friendly manner.

lib/dns/tests/dnstest.c
lib/dns/tests/dnstest.h

index 83e40256d4cfafa4427ddbbf0e80d435674507d8..acec5ec753662ffce4e2d6952fb03321aae2e098 100644 (file)
@@ -516,3 +516,72 @@ dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname) {
 
        isc_buffer_free(&b);
 }
+
+isc_result_t
+dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes) {
+       isc_result_t result = ISC_R_SUCCESS;
+       unsigned char rdata_buf[1024];
+       dns_difftuple_t *tuple = NULL;
+       isc_consttextregion_t region;
+       dns_rdatatype_t rdatatype;
+       dns_fixedname_t fixedname;
+       dns_rdata_t rdata;
+       dns_name_t *name;
+       size_t i;
+
+       REQUIRE(diff != NULL);
+       REQUIRE(changes != NULL);
+
+       dns_diff_init(mctx, diff);
+
+       for (i = 0; changes[i].owner != NULL; i++) {
+               /*
+                * Parse owner name.
+                */
+               name = dns_fixedname_initname(&fixedname);
+               result = dns_name_fromstring(name, changes[i].owner, 0, mctx);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+
+               /*
+                * Parse RDATA type.
+                */
+               region.base = changes[i].type;
+               region.length = strlen(changes[i].type);
+               result = dns_rdatatype_fromtext(&rdatatype,
+                                               (isc_textregion_t *)&region);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+
+               /*
+                * Parse RDATA.
+                */
+               dns_rdata_init(&rdata);
+               result = dns_test_rdatafromstring(&rdata, dns_rdataclass_in,
+                                                 rdatatype, rdata_buf,
+                                                 sizeof(rdata_buf),
+                                                 changes[i].rdata);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+
+               /*
+                * Create a diff tuple for the parsed change and append it to
+                * the diff.
+                */
+               result = dns_difftuple_create(mctx, changes[i].op, name,
+                                             changes[i].ttl, &rdata, &tuple);
+               if (result != ISC_R_SUCCESS) {
+                       break;
+               }
+               dns_diff_append(diff, &tuple);
+       }
+
+       if (result != ISC_R_SUCCESS) {
+               dns_diff_clear(diff);
+       }
+
+       return (result);
+}
index 492bc42a38564caa0c9d2e1eab041fd008e29edf..8487c4f0d478375ee0c222f442e69ae13625b059 100644 (file)
@@ -23,6 +23,7 @@
 #include <isc/timer.h>
 #include <isc/util.h>
 
+#include <dns/diff.h>
 #include <dns/result.h>
 #include <dns/zone.h>
 
                        goto cleanup; \
        } while (0)
 
+typedef struct {
+       dns_diffop_t op;
+       const char *owner;
+       dns_ttl_t ttl;
+       const char *type;
+       const char *rdata;
+} zonechange_t;
+
+#define ZONECHANGE_SENTINEL { 0, NULL, 0, NULL, NULL }
+
 extern isc_mem_t *mctx;
 extern isc_entropy_t *ectx;
 extern isc_log_t *lctx;
@@ -112,3 +123,10 @@ dns_test_rdatafromstring(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
 
 void
 dns_test_namefromstring(const char *namestr, dns_fixedname_t *fname);
+
+/*%
+ * Given a pointer to an uninitialized dns_diff_t structure in 'diff', make it
+ * contain diff tuples representing zone database changes listed in 'changes'.
+ */
+isc_result_t
+dns_test_difffromchanges(dns_diff_t *diff, const zonechange_t *changes);