From: Miek Gieben Date: Tue, 26 Jul 2005 12:47:03 +0000 (+0000) Subject: read/write/print zones is there X-Git-Tag: release-0.70~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b09612d3bb540df7fabeceef782c0dfca81cb8a6;p=thirdparty%2Fldns.git read/write/print zones is there --- diff --git a/doc/CodingStyle b/doc/CodingStyle index fc50f72f..aaada395 100644 --- a/doc/CodingStyle +++ b/doc/CodingStyle @@ -7,7 +7,7 @@ The libdns coding style guide * prefix (exported) identifiers with 'ldns_' * no unneeded parentheses after 'return' * always curly brackets in if-statements -* use defines voor (weird) constants, and masks +* use defines for (weird) constants, and masks * type 'bool', constants 'true'/'false'. Don't compare bools for equality. diff --git a/ldns/zone.h b/ldns/zone.h index a0189f24..cf704a0e 100644 --- a/ldns/zone.h +++ b/ldns/zone.h @@ -37,6 +37,10 @@ struct ldns_struct_zone }; typedef struct ldns_struct_zone ldns_zone; +/** + * create a new ldns_zone structure + */ +ldns_zone * ldns_zone_new(void); /** * \param[in] z the zone to read from @@ -90,6 +94,6 @@ bool ldns_zone_rr_is_glue(ldns_zone *z, ldns_rr *rr); ldns_zone * -ldns_zone_new_frm_fp(FILE *fp, ldns_rdf **origin, uint16_t *ttl, ldns_rr_class *c); +ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c); #endif /* LDNS_ZONE_H */ diff --git a/zone.c b/zone.c index 4dc47561..df62019d 100644 --- a/zone.c +++ b/zone.c @@ -60,29 +60,78 @@ ldns_zone_rr_is_glue(ldns_zone *z, ldns_rr *rr) return false; } -/* we don't want state, so we have to give it as arguments */ +ldns_zone * +ldns_zone_new(void) +{ + ldns_zone *z; + + z = LDNS_MALLOC(ldns_zone); + if (!z) { + return NULL; + } + + z->_rrs = ldns_rr_list_new(); + ldns_zone_set_soa(z, NULL); + return z; +} + /* we regocnize: * $TTL, $ORIGIN */ ldns_zone * -ldns_zone_new_frm_fp(FILE *fp, ldns_rdf **origin, uint16_t *ttl, ldns_rr_class *c) +ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c) { -#if 0 ldns_zone *newzone; ldns_rr *rr; -#endif + ldns_rdf *my_origin; + uint16_t my_ttl; + ldns_rr_class my_class; + + uint8_t i; + newzone = ldns_zone_new(); + my_origin = origin; + my_ttl = ttl; + my_class = c; + /* read until we got a soa, all crap above is discarded * except $directives */ - fp = fp; - origin = origin; - ttl = ttl; - c = c; - - /* re-order stuff with rrsets */ - return NULL; + i = 0; + do { + rr = ldns_rr_new_frm_fp(fp); + i++; + } while (!rr && i <= 9); + + if (i > 9) { + /* there is a lot of crap here, bail out before somebody gets + * hurt */ + return NULL; + } + + if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) { + /* first rr MUST be the soa */ + return NULL; + } + + ldns_zone_set_soa(newzone, rr); + + while(!feof(fp)) { + rr = ldns_rr_new_frm_fp(fp); + if (rr) { + if (!ldns_zone_push_rr(newzone, rr)) { + printf("error pushing rr\n"); + return NULL; + } + + my_origin = ldns_rr_owner(rr); + my_ttl = ldns_rr_ttl(rr); + my_class = ldns_rr_get_class(rr); + + } + } + return newzone; } #if 0