if (z) {
ldns_zone_print(stdout, z);
+ ldns_zone_deep_free(z);
}
fclose(fp);
* The string should be a fully filled-in rr, like
* ownername <space> TTL <space> CLASS <space> TYPE <space> RDATA.
* \param[in] str the string to convert
- * \param[in] default_ttl a default ttl for the rr. If 0 DEF_TTL will be used
+ * \param[in] default_ttl pointer to a default ttl for the rr. If 0 DEF_TTL will be used
* \param[in] origin when the owner is relative add this
* \return the new rr
*/
/**
* creates a new rr from a file containing a string.
* \param[in] fp the file pointer to use
- * \param[in] default_ttl a default ttl for the rr. If 0 DEF_TTL will be used
+ * \param[in] default_ttl pointer to a default ttl for the rr. If NULL DEF_TTL will be used
+ * the pointer will be updated if the file contains a $TTL directive
* \param[in] origin when the owner is relative add this
+ * the pointer will be updated if the file contains a $ORIGIN directive
* \return ldns_rr*
*/
-ldns_rr* ldns_rr_new_frm_fp(FILE *fp, uint16_t default_ttl, ldns_rdf *origin);
+ldns_rr* ldns_rr_new_frm_fp(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin);
/**
* creates a new rr from a file containing a string.
* \param[in] fp the file pointer to use
* \param[in] default_ttl a default ttl for the rr. If 0 DEF_TTL will be used
+ * the pointer will be updated if the file contains a $TTL directive
* \param[in] origin when the owner is relative add this
+ * the pointer will be updated if the file contains a $ORIGIN directive
* \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
* \return ldns_rr*
*/
-ldns_rr* ldns_rr_new_frm_fp_l(FILE *fp, uint16_t default_ttl, ldns_rdf *origin, int *line_nr);
+ldns_rr* ldns_rr_new_frm_fp_l(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, int *line_nr);
/**
* sets the owner in the rr structure.
LDNS_FREE(ttl);
LDNS_FREE(clas);
LDNS_FREE(type);
+ LDNS_FREE(rdata);
LDNS_FREE(rd);
LDNS_FREE(rd_buf);
ldns_buffer_free(rr_buf);
LDNS_FREE(ttl);
LDNS_FREE(clas);
LDNS_FREE(type);
+ LDNS_FREE(rdata);
LDNS_FREE(rd);
LDNS_FREE(rd_buf);
ldns_buffer_free(rr_buf);
}
ldns_rr *
-ldns_rr_new_frm_fp(FILE *fp, uint16_t ttl, ldns_rdf *origin)
+ldns_rr_new_frm_fp(FILE *fp, uint16_t *ttl, ldns_rdf **origin)
{
return ldns_rr_new_frm_fp_l(fp, ttl, origin, NULL);
}
ldns_rr *
-ldns_rr_new_frm_fp_l(FILE *fp, uint16_t ttl, ldns_rdf *origin, int *line_nr)
+ldns_rr_new_frm_fp_l(FILE *fp, uint16_t *default_ttl, ldns_rdf **origin, int *line_nr)
{
char *line;
ldns_rr *rr;
+ char *keyword;
+ uint16_t ttl;
+
+ if (default_ttl) {
+ ttl = *default_ttl;
+ } else {
+ ttl = 0;
+ }
line = LDNS_XMALLOC(char, LDNS_MAX_LINELEN + 1);
if (!line) {
return NULL;
}
- rr = ldns_rr_new_frm_str((const char*) line, ttl, origin);
+ rr = ldns_rr_new_frm_str((const char*) line, ttl, *origin);
+ if (!rr) {
+ if ((keyword = strstr(line, "$ORIGIN "))) {
+ if (*origin) {
+ ldns_rdf_free(*origin);
+ *origin = NULL;
+ }
+ *origin = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, keyword + 8);
+ } else if ((keyword = strstr(line, "$TTL "))) {
+ *default_ttl = atoi(keyword + 5);
+ }
+ }
LDNS_FREE(line);
return rr;
}
{
ldns_zone *newzone;
ldns_rr *rr;
- ldns_rdf *my_origin = origin;
+ ldns_rdf *my_origin = NULL;
uint16_t my_ttl = ttl;
ldns_rr_class my_class = c;
ldns_rr *last_rr = NULL;
* except $directives
*/
+ if (origin) {
+ my_origin = ldns_rdf_clone(origin);
+ }
+
i = 0;
do {
- rr = ldns_rr_new_frm_fp_l(fp, my_ttl, my_origin, line_nr);
+ rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, line_nr);
+printf("RR at %p\n", rr);
i++;
} while (!rr && i <= 9);
if (rr) {
ldns_rr_free(rr);
}
+ if (my_origin) {
+ ldns_rdf_free(my_origin);
+ }
+ ldns_zone_deep_free(newzone);
return NULL;
}
if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
/* first rr MUST be the soa */
ldns_rr_free(rr);
+ if (my_origin) {
+ ldns_rdf_free(my_origin);
+ }
+ ldns_zone_deep_free(newzone);
return NULL;
}
ldns_zone_set_soa(newzone, rr);
if (!my_origin) {
- my_origin = ldns_rr_owner(rr);
+ my_origin = ldns_rdf_clone(ldns_rr_owner(rr));
}
while(!feof(fp)) {
- rr = ldns_rr_new_frm_fp_l(fp, my_ttl, my_origin, line_nr);
+ rr = ldns_rr_new_frm_fp_l(fp, &my_ttl, &my_origin, line_nr);
if (rr) {
last_rr = rr;
if (!ldns_zone_push_rr(newzone, rr)) {
dprintf("%s", "error pushing rr\n");
+ if (my_origin) {
+ ldns_rdf_free(my_origin);
+ }
+ ldns_zone_deep_free(newzone);
return NULL;
}
dprintf("%s", "\n");
}
}
+ if (my_origin) {
+ ldns_rdf_deep_free(my_origin);
+ }
return newzone;
}