46 #include <ldns/ldns.h>
50 static const char* adapter_str =
"adapter";
59 adfile_read_rr(FILE* fd,
zone_type* zone,
char* line, ldns_rdf** orig,
60 ldns_rdf** prev, uint32_t* ttl, ldns_status* status,
unsigned int* l)
64 FILE* fd_include = NULL;
81 if (strncmp(line,
"$ORIGIN", 7) == 0 && isspace((
int)line[7])) {
84 ldns_rdf_deep_free(*orig);
88 while (isspace((
int)line[offset])) {
91 tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
95 *status = LDNS_STATUS_SYNTAX_DNAME_ERR;
100 goto adfile_read_line;
102 }
else if (strncmp(line,
"$TTL", 4) == 0 &&
103 isspace((
int)line[4])) {
106 while (isspace((
int)line[offset])) {
110 *ttl = ldns_str2period(line + offset, &endptr);
113 goto adfile_read_line;
115 }
else if (strncmp(line,
"$INCLUDE", 8) == 0 &&
116 isspace((
int)line[8])) {
119 while (isspace((
int)line[offset])) {
122 fd_include =
ods_fopen(line + offset, NULL,
"r");
124 s = adfile_read_file(fd_include, zone);
128 adapter_str, (line+offset));
129 *status = LDNS_STATUS_SYNTAX_ERR;
133 *status = LDNS_STATUS_SYNTAX_ERR;
135 adapter_str, (line+offset));
142 goto adfile_read_line;
150 goto adfile_read_line;
156 goto adfile_read_line;
159 *status = ldns_rr_new_frm_str(&rr, line, new_ttl, *orig, prev);
160 if (*status == LDNS_STATUS_OK) {
162 }
else if (*status == LDNS_STATUS_SYNTAX_EMPTY) {
167 *status = LDNS_STATUS_OK;
168 goto adfile_read_line;
172 adapter_str, l&&*l?*l:0,
173 ldns_get_errorstr_by_id(*status), line);
187 *status = LDNS_STATUS_OK;
197 adfile_read_file(FILE* fd,
zone_type* zone)
201 ldns_rdf* prev = NULL;
202 ldns_rdf* orig = NULL;
203 ldns_rdf* dname = NULL;
205 uint32_t new_serial = 0;
206 ldns_status status = LDNS_STATUS_OK;
208 unsigned int line_update_interval = 100000;
209 unsigned int line_update = line_update_interval;
218 ods_log_error(
"[%s] error getting default value for $ORIGIN",
222 orig = ldns_rdf_clone(dname);
224 ods_log_error(
"[%s] error setting default value for $ORIGIN",
231 while ((rr = adfile_read_rr(fd, zone, line, &orig, &prev, &ttl,
232 &status, &l)) != NULL) {
234 if (status != LDNS_STATUS_OK) {
236 adapter_str, l, ldns_get_errorstr_by_id(status), line);
241 if (l > line_update) {
242 ods_log_debug(
"[%s] ...at line %i: %s", adapter_str, l, line);
243 line_update += line_update_interval;
246 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
254 adapter_str, l, line);
261 adapter_str, l, line);
269 ldns_rdf_deep_free(orig);
273 ldns_rdf_deep_free(prev);
278 adapter_str, l, ldns_get_errorstr_by_id(status), line);
285 ods_log_error(
"[%s] unable to read file: zonefile contains errors",
314 status = adfile_read_file(fd, adzone);
331 char* tmpname = NULL;
337 ods_log_error(
"[%s] unable to write file: no output adapter",
342 ods_log_error(
"[%s] unable to write file: no filename given",
359 ods_log_error(
"[%s] unable to write zone %s file %s: one or "
360 "more RR print failed", adapter_str, adzone->
name,
372 if (rename((
const char*) tmpname, filename) != 0) {
373 ods_log_error(
"[%s] unable to write file: failed to rename %s "
374 "to %s (%s)", adapter_str, tmpname, filename, strerror(errno));
void ods_log_debug(const char *format,...)
enum ods_enum_status ods_status
void ods_log_error(const char *format,...)
#define SE_SOA_RDATA_SERIAL
adapter_type * adoutbound
FILE * ods_fopen(const char *file, const char *dir, const char *mode)
ods_status adfile_read(void *zone)
void adapi_set_serial(zone_type *zone, uint32_t serial)
ods_status adfile_write(void *zone, const char *filename)
ldns_rdf * adapi_get_origin(zone_type *zone)
int adutil_whitespace_line(char *line, int line_len)
void adutil_rtrim_line(char *line, int *line_len)
ods_status adapi_printzone(FILE *fd, zone_type *zone)
char * ods_build_path(const char *file, const char *suffix, int dir, int no_slash)
void adapi_trans_full(zone_type *zone, unsigned more_coming)
void ods_fclose(FILE *fd)
ods_status namedb_examine(namedb_type *db)
ods_status adapi_add_rr(zone_type *zone, ldns_rr *rr, int backup)
#define SE_ADFILE_MAXLINE
int adutil_readline_frm_file(FILE *fd, char *line, unsigned int *l, int keep_comments)
uint32_t adapi_get_ttl(zone_type *zone)
#define ods_log_assert(x)