]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
subdomain testing works. The first step in determening glue. After which we may be...
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 23 Jun 2005 13:18:25 +0000 (13:18 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 23 Jun 2005 13:18:25 +0000 (13:18 +0000)
dname.c
rdata.c
tests/dname-label-test.c

diff --git a/dname.c b/dname.c
index 70d8844f28101fd2ac1ba001aaacb591f50da654..2f8fec7727ebcc0f7196b256e7b53367ed614122 100644 (file)
--- a/dname.c
+++ b/dname.c
@@ -195,8 +195,8 @@ ldns_dname_is_subdomain(const ldns_rdf *sub, const ldns_rdf *parent)
        /* check all labels the from the parent labels, from right to left. 
         * When they /all/ match we have found a subdomain
         */
-       j = sub_lab;
-       for (i = par_lab; i >= 0; i--) {
+       j = sub_lab - 1; /* we count from zero, thank you */
+       for (i = par_lab -1; i >= 0; i--) {
                tmp_sub = ldns_dname_label(sub, j);
                tmp_par = ldns_dname_label(parent, i);
 
@@ -205,12 +205,18 @@ ldns_dname_is_subdomain(const ldns_rdf *sub, const ldns_rdf *parent)
                ldns_rdf_print(stdout, tmp_par);
                printf("\n");
 
+               if (ldns_rdf_compare(tmp_sub, tmp_par) != 0) {
+                       /* they are not equal */
+                       ldns_rdf_deep_free(tmp_sub);
+                       ldns_rdf_deep_free(tmp_par);
+                       return false;
+               }
+
                ldns_rdf_deep_free(tmp_sub);
                ldns_rdf_deep_free(tmp_par);
                j--;
-                       
        }
-       return false;
+       return true; 
 }
 
 ldns_rdf *
diff --git a/rdata.c b/rdata.c
index 4bbed038305d8eb1e1ffc22a0013a8f713842162..31c74143135a359c719df07d102aafe44dfa8780 100644 (file)
--- a/rdata.c
+++ b/rdata.c
@@ -523,6 +523,12 @@ ldns_rdf_compare(const ldns_rdf *rd1, const ldns_rdf *rd2)
 {
        uint16_t i1, i2, i;
        uint8_t *d1, *d2;
+
+       /* only when both are NULL we can say anything about them */
+       if (!rd1 && !rd2) {
+               return 0;
+       }
+       
        i1 = ldns_rdf_size(rd1);
        i2 = ldns_rdf_size(rd1);
 
index ae505806da701af17462acb6f0d2823266dc82db..d00d597096b8d431afa30a9ad82f3f312eb8f499 100644 (file)
@@ -19,11 +19,16 @@ main(int argc, char **argv)
 {
        ldns_rdf *test;
        ldns_rdf *test2;
+       ldns_rdf *parent;
+       ldns_rdf *child;
        ldns_rdf *newlabel;
 
        test = ldns_dname_new_frm_str("bla.miek.nl");
        test2 = ldns_dname_new_frm_str("www.bla.miek.nl");
 
+       parent = ldns_dname_new_frm_str("yahoo.com");
+       child = ldns_dname_new_frm_str("miek.nl");
+
        ldns_rdf_print(stdout, test);
        printf("\n");
 
@@ -62,7 +67,17 @@ main(int argc, char **argv)
        printf("\n");
        ldns_rdf_deep_free(newlabel);
 
-       (void)ldns_dname_is_subdomain(test2, test);
+       if (ldns_dname_is_subdomain(test2, test)) {
+               printf("Yes, it's a subdomain\n");
+       } else {
+               printf("Go fuck your self\n");
+       }
+
+       if (ldns_dname_is_subdomain(child, parent)) {
+               printf("Yes, it's a subdomain\n");
+       } else {
+               printf("Go fuck your self\n");
+       }
        
        return 0;
 }