#define LDNS_PARSE_SKIP_SPACE "\f\n\r\v"
#define LDNS_PARSE_NORMAL " \f\n\r\t\v"
#define LDNS_PARSE_NO_NL " \t"
-#define LDNS_MAX_LINELEN 512
+#define LDNS_MAX_LINELEN 4096
#define LDNS_MAX_KEYWORDLEN 32
/**
ldns_zone *
ldns_zone_new_frm_fp(FILE *fp, ldns_rdf *origin, uint16_t ttl, ldns_rr_class c);
+/**
+ * Frees the allocated memory for the zone, and the rr_list structure in it
+ */
+void ldns_zone_free(ldns_zone *zone);
+
+/**
+ * Frees the allocated memory for the zone, the soa rr in it,
+ * and the rr_list structure in it, including the rr's in that. etc.
+ */
+void ldns_zone_free(ldns_zone *zone);
+
+
#endif /* LDNS_ZONE_H */
*t++ = c;
i++;
- if (limit > 0 && i > limit) {
+ if (limit > 0 && i >= limit) {
*t = '\0';
return -1;
}
*t++ = c;
i++;
- if (limit > 0 && i > limit) {
+ if (limit > 0 && i >= limit - 1) {
*t = '\0';
return -1;
}
*/
if (clas_val == 0) {
clas_val = LDNS_RR_CLASS_IN;
- type = LDNS_XMALLOC(char, strlen(ttl));
+ type = LDNS_XMALLOC(char, strlen(ttl) + 1);
strncpy(type, ttl, strlen(ttl) + 1);
}
} else {
*/
if (clas_val == 0) {
clas_val = LDNS_RR_CLASS_IN;
- type = LDNS_XMALLOC(char, strlen(clas));
+ type = LDNS_XMALLOC(char, strlen(clas) + 1);
strncpy(type, clas, strlen(clas) + 1);
}
}
r = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_HEX, hex_data_str);
/* correct the rdf type */
ldns_rdf_set_type(r, ldns_rr_descriptor_field_type(desc, r_cnt));
-
+ LDNS_FREE(hex_data_str);
ldns_rr_push_rdf(new, r);
} else {
ldns_rr_new_frm_fp(FILE *fp, uint16_t ttl, ldns_rdf *origin)
{
char *line;
+ ldns_rr *rr;
line = LDNS_XMALLOC(char, LDNS_MAX_LINELEN + 1);
if (!line) {
if (ldns_fget_token(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN) == -1) {
return NULL;
}
- return ldns_rr_new_frm_str((const char*) line, ttl, origin);
+
+ rr = ldns_rr_new_frm_str((const char*) line, ttl, origin);
+
+ LDNS_FREE(line);
+ return rr;
}
void
ldns_rr_print(stdout, orig_soa);
ldns_rr_list_print(stdout, orig_rrs);
- ldns_rr_free(orig_soa);
- ldns_rr_list_free(orig_rrs);
+ ldns_zone_deep_free(orig_zone);
}
fclose(zonefile);
}
- ldns_rdf_free(origin);
+ ldns_rdf_deep_free(origin);
return 0;
}
data[0] = strlen(str);
memcpy(data + 1, str, strlen(str));
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_STR, strlen(str) + 1, data);
+ LDNS_FREE(data);
return LDNS_STATUS_OK;
}
}
t = t_orig;
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_HEX, len / 2, t);
+ LDNS_FREE(t);
}
return LDNS_STATUS_OK;
}
{
ldns_zone *newzone;
ldns_rr *rr;
- ldns_rdf *my_origin;
- uint16_t my_ttl;
- ldns_rr_class my_class;
+ ldns_rdf *my_origin = origin;
+ uint16_t my_ttl = ttl;
+ ldns_rr_class my_class = c;
uint8_t i;
i = 0;
do {
- rr = ldns_rr_new_frm_fp(fp, ttl, origin);
+ rr = ldns_rr_new_frm_fp(fp, my_ttl, my_origin);
i++;
} while (!rr && i <= 9);
if (i > 9) {
/* there is a lot of crap here, bail out before somebody gets
* hurt */
+ ldns_rr_free(rr);
return NULL;
}
if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
/* first rr MUST be the soa */
+ ldns_rr_free(rr);
return NULL;
}
ldns_zone_set_soa(newzone, rr);
while(!feof(fp)) {
- rr = ldns_rr_new_frm_fp(fp, ttl, origin);
+ rr = ldns_rr_new_frm_fp(fp, my_ttl, my_origin);
if (rr) {
if (!ldns_zone_push_rr(newzone, rr)) {
printf("error pushing rr\n");
my_ttl = ldns_rr_ttl(rr);
my_class = ldns_rr_get_class(rr);
+ } else {
+ fprintf(stderr, "Error in file, unable to read RR\n");
}
}
return newzone;
}
#endif
+
+void
+ldns_zone_free(ldns_zone *zone) {
+ ldns_rr_list_free(zone->_rrs);
+ LDNS_FREE(zone);
+}
+
+void
+ldns_zone_deep_free(ldns_zone *zone) {
+ ldns_rr_free(zone->_soa);
+ ldns_rr_list_deep_free(zone->_rrs);
+ LDNS_FREE(zone);
+}