From: Miek Gieben Date: Thu, 23 Jun 2005 11:48:14 +0000 (+0000) Subject: adding some very lowlevel functionality. Makes you wonder why we didn't X-Git-Tag: release-0.70~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34c09be9c8e70a2893a110dbf5b9ac8dc3089d36;p=thirdparty%2Fldns.git adding some very lowlevel functionality. Makes you wonder why we didn't need them before... --- diff --git a/TODO b/TODO index 306e78e6..aca18aa3 100644 --- a/TODO +++ b/TODO @@ -24,6 +24,7 @@ o DNSSEC o init function? random - load_ssl_errors() - SSL_load_error_str()? o SERVER stuff; open connection and such - NOT DONE AT ALL - will happen in .90 +o const args for all functions To ponder and discuss: ---------------------- diff --git a/dname.c b/dname.c index c0738149..1d3efb84 100644 --- a/dname.c +++ b/dname.c @@ -3,6 +3,8 @@ * * dname specific rdata implementations * A dname is a rdf structure with type LDNS_RDF_TYPE_DNAME + * It is not a /real/ type! All function must therefor check + * for LDNS_RDF_TYPE_DNAME. * * a Net::DNS like library for C * @@ -20,7 +22,6 @@ #include #include - ldns_rdf * ldns_dname_cat_clone(ldns_rdf *rd1, ldns_rdf *rd2) { @@ -111,7 +112,7 @@ ldns_dname_left_chop(ldns_rdf *d) } uint8_t -ldns_dname_label_count(ldns_rdf *r) +ldns_dname_label_count(const ldns_rdf *r) { uint8_t src_pos; uint8_t len; @@ -168,3 +169,41 @@ ldns_dname2canonical(const ldns_rdf *rd) *rdd = (uint8_t)LDNS_DNAME_NORMALIZE((int)*rdd); } } + +bool +ldns_dname_is_subdomain(const ldns_rdf *sub, const ldns_rdf *parent) +{ + uint8_t sub_lab; + uint8_t par_lab; + int8_t i; + + if (ldns_rdf_get_type(sub) != LDNS_RDF_TYPE_DNAME || + ldns_rdf_get_type(parent) != LDNS_RDF_TYPE_DNAME) { + return false; + } + + sub_lab = ldns_dname_label_count(sub); + par_lab = ldns_dname_label_count(parent); + + /* if sub sits above parent, it cannot be a child/sub domain */ + if (sub_lab < par_lab) { + return false; + } + + /* check all labels the from the parent labels, from right to left. + * When they /all/ match we have found a subdomain + */ + for (i = par_lab; i > 0; i--) { + /* */ + } + return false; +} + +uint8_t * +ldns_dname_label(ldns_rdf *rdf, uint8_t labelpos) +{ + rdf = rdf; + labelpos = labelpos; + + return NULL; +} diff --git a/ldns/dname.h b/ldns/dname.h index 2786dd65..f5849281 100644 --- a/ldns/dname.h +++ b/ldns/dname.h @@ -37,7 +37,7 @@ ldns_rdf *ldns_dname_left_chop(ldns_rdf *d); * \param[in] *r the rdf * \return the number of labels */ -uint8_t ldns_dname_label_count(ldns_rdf *r); +uint8_t ldns_dname_label_count(const ldns_rdf *r); /** * Create a new dname rdf from a string @@ -53,11 +53,32 @@ ldns_rdf *ldns_dname_new_frm_str(const char *str); * \return ldns_rdf* */ ldns_rdf *ldns_dname_new_frm_data(uint16_t size, const void *data); + /** * Put a dname into canonical fmt - ie. lowercase it * \param[in] rdf the dname to lowercase * \return void */ -void ldns_dname2canonical(const ldns_rdf *rdf); +void ldns_dname2canonical(const ldns_rdf *rdf); + +/** + * test wether the name sub falls under parent (i.e. is a subdomain + * of parent. + * \param[in] sub the name to test + * \param[in] parent the parent's name + * \return true if sub falls under parent, otherwise false + */ +bool ldns_dname_is_subdomain(const ldns_rdf *sub, const ldns_rdf *parent); + +/** + * look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME + * try and retrieve a specific label. The labels are numbered + * starting from 0 (left most). + * \param[in] rdf the rdf to look in + * \param[in] labelpos return the label with this number + * \return a pointer to a newly allocated buffer with the + * label which is NULL terminated + */ +uint8_t * ldns_dname_label(ldns_rdf *rdf, uint8_t labelpos); #endif /* !_LDNS_DNAME_H */ diff --git a/ldns/zone.h b/ldns/zone.h index 18887089..b354e75a 100644 --- a/ldns/zone.h +++ b/ldns/zone.h @@ -80,5 +80,13 @@ bool ldns_zone_push_rr_list(ldns_zone *z, ldns_rr_list *list); */ bool ldns_zone_push_rr(ldns_zone *z, ldns_rr *rr); +/** + * find out if the rr is glue inside zone z + * \param[in] z the zone to look for glue + * \param[in] rr the rr to test + * \return true if rr is glue, otherwise false + */ +bool ldns_zone_rr_is_glue(ldns_zone *z, ldns_rr *rr); + #endif /* LDNS_ZONE_H */ diff --git a/zone.c b/zone.c index b04c22c8..3fd1c335 100644 --- a/zone.c +++ b/zone.c @@ -51,6 +51,15 @@ ldns_zone_push_rr(ldns_zone *z, ldns_rr *rr) ldns_zone_rrs(z), rr); } +bool +ldns_zone_rr_is_glue(ldns_zone *z, ldns_rr *rr) +{ + z = z; + rr = rr; + + return false; +} + #if 0 /** * ixfr function. Work on a ldns_zone and remove and add