43 #include <ldns/ldns.h> 46 static const char* zl_str =
"zonelist";
54 zone_compare(
const void* a,
const void* b)
66 return ldns_dname_compare(x->
apex, y->
apex);
82 ods_log_error(
"[%s] unable to create zonelist: allocator_alloc() " 87 zlist->
zones = ldns_rbtree_create(zone_compare);
89 ods_log_error(
"[%s] unable to create zonelist: ldns_rbtree_create() " 107 const char* rngfile = ODS_SE_RNGDIR
"/zonelist.rng";
113 ods_log_error(
"[%s] unable to read file: parse error in %s", zl_str,
125 static ldns_rbnode_t*
128 ldns_rbnode_t* node = (ldns_rbnode_t*) malloc(
sizeof(ldns_rbnode_t));
145 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
146 if (zonelist && zonelist->
zones && zone) {
147 node = ldns_rbtree_search(zonelist->
zones, zone);
166 if (zonelist && zonelist->
zones && name && klass) {
170 "zone_create() failed", zl_str, name);
173 result = zonelist_lookup_zone(zonelist, zone);
191 if (zonelist && zonelist->
zones && dname && klass) {
192 name = ldns_rdf2str(dname);
207 ldns_rbnode_t* new_node = NULL;
211 if (!zlist || !zlist->
zones) {
216 if (zonelist_lookup_zone(zlist, zone) != NULL) {
223 new_node = zone2node(zone);
224 if (ldns_rbtree_insert(zlist->
zones, new_node) == NULL) {
225 ods_log_error(
"[%s] unable to add zone %s: ldns_rbtree_insert() " 226 "failed", zl_str, zone->
name);
227 free((
void*) new_node);
244 ldns_rbnode_t* old_node = LDNS_RBTREE_NULL;
248 if (!zlist || !zlist->
zones) {
249 goto zone_not_present;
251 old_node = ldns_rbtree_delete(zlist->
zones, zone);
253 goto zone_not_present;
255 free((
void*) old_node);
274 ldns_rbnode_t* n1 = LDNS_RBTREE_NULL;
275 ldns_rbnode_t* n2 = LDNS_RBTREE_NULL;
284 n1 = ldns_rbtree_first(zl1->
zones);
285 n2 = ldns_rbtree_first(zl2->
zones);
286 while (n2 && n2 != LDNS_RBTREE_NULL) {
288 if (n1 && n1 != LDNS_RBTREE_NULL) {
300 ods_log_crit(
"[%s] merge failed: z2 not added", zl_str);
303 n2 = ldns_rbtree_next(n2);
306 ret = zone_compare(z1, z2);
311 n1 = ldns_rbtree_next(n1);
312 }
else if (ret > 0) {
316 ods_log_crit(
"[%s] merge failed: z2 not added", zl_str);
319 n2 = ldns_rbtree_next(n2);
322 n1 = ldns_rbtree_next(n1);
323 n2 = ldns_rbtree_next(n2);
334 while (n1 && n1 != LDNS_RBTREE_NULL) {
338 n1 = ldns_rbtree_next(n1);
356 char* datestamp = NULL;
359 if (!zl|| !zl->
zones || !zlfile) {
364 if (st_mtime <= zl->last_modified) {
367 zl_str, zlfile, datestamp?datestamp:
"Unknown");
368 free((
void*)datestamp);
378 ods_log_error(
"[%s] unable to update zonelist: zonelist_create() " 384 status = zonelist_read(new_zlist, zlfile);
390 zonelist_merge(zl, new_zlist);
392 ods_log_debug(
"[%s] file %s is modified since %s", zl_str, zlfile,
393 datestamp?datestamp:
"Unknown");
394 free((
void*)datestamp);
396 ods_log_error(
"[%s] unable to update zonelist: read file %s failed " 410 zone_delfunc(ldns_rbnode_t* elem)
413 if (elem && elem != LDNS_RBTREE_NULL) {
415 zone_delfunc(elem->left);
416 zone_delfunc(elem->right);
430 node_delfunc(ldns_rbnode_t* elem)
432 if (elem && elem != LDNS_RBTREE_NULL) {
433 node_delfunc(elem->left);
434 node_delfunc(elem->right);
455 zone_delfunc(zl->
zones->root);
456 ldns_rbtree_free(zl->
zones);
480 node_delfunc(zl->
zones->root);
481 ldns_rbtree_free(zl->
zones);
void zone_cleanup(zone_type *zone)
void ods_log_debug(const char *format,...)
uint32_t time_datestamp(time_t tt, const char *format, char **str)
void zone_merge(zone_type *z1, zone_type *z2)
#define lock_basic_destroy(lock)
void * allocator_alloc(allocator_type *allocator, size_t size)
enum ods_enum_status ods_status
ods_status parse_file_check(const char *cfgfile, const char *rngfile)
time_t ods_file_lastmodified(const char *file)
void ods_log_error(const char *format,...)
const char * ods_status2str(ods_status status)
zone_type * zone_create(char *name, ldns_rr_class klass)
void ods_log_crit(const char *format,...)
zone_type * zonelist_add_zone(zonelist_type *zlist, zone_type *zone)
zone_type * zonelist_del_zone(zonelist_type *zlist, zone_type *zone)
allocator_type * allocator_create(void *(*allocator)(size_t size), void(*deallocator)(void *))
zone_type * zonelist_lookup_zone_by_dname(zonelist_type *zonelist, ldns_rdf *dname, ldns_rr_class klass)
ods_status parse_zonelist_zones(void *zlist, const char *zlfile)
allocator_type * allocator
void ods_log_verbose(const char *format,...)
#define lock_basic_init(lock)
zone_type * zonelist_lookup_zone_by_name(zonelist_type *zonelist, const char *name, ldns_rr_class klass)
void allocator_cleanup(allocator_type *allocator)
void zonelist_cleanup(zonelist_type *zl)
void ods_log_deeebug(const char *format,...)
void allocator_deallocate(allocator_type *allocator, void *data)
ods_status zonelist_update(zonelist_type *zl, const char *zlfile)
void zonelist_free(zonelist_type *zl)
zonelist_type * zonelist_create(allocator_type *allocator)
#define ods_log_assert(x)
void ods_log_warning(const char *format,...)