45 #include <ldns/ldns.h>
48 static const char* zl_str =
"zonelist";
56 zone_compare(
const void* a,
const void* b)
68 return ldns_dname_compare(x->
apex, y->
apex);
84 ods_log_error(
"[%s] unable to create zonelist: allocator_alloc() "
89 zlist->
zones = ldns_rbtree_create(zone_compare);
91 ods_log_error(
"[%s] unable to create zonelist: ldns_rbtree_create() "
109 const char* rngfile = ODS_SE_RNGDIR
"/zonelist.rng";
115 ods_log_error(
"[%s] unable to read file: parse error in %s", zl_str,
127 static ldns_rbnode_t*
130 ldns_rbnode_t* node = (ldns_rbnode_t*) malloc(
sizeof(ldns_rbnode_t));
147 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
148 if (zonelist && zonelist->
zones && zone) {
149 node = ldns_rbtree_search(zonelist->
zones, zone);
168 if (zonelist && zonelist->
zones && name && klass) {
172 "zone_create() failed", zl_str, name);
175 result = zonelist_lookup_zone(zonelist, zone);
193 if (zonelist && zonelist->
zones && dname && klass) {
194 name = ldns_rdf2str(dname);
209 ldns_rbnode_t* new_node = NULL;
213 if (!zlist || !zlist->
zones) {
218 if (zonelist_lookup_zone(zlist, zone) != NULL) {
225 new_node = zone2node(zone);
226 if (ldns_rbtree_insert(zlist->
zones, new_node) == NULL) {
227 ods_log_error(
"[%s] unable to add zone %s: ldns_rbtree_insert() "
228 "failed", zl_str, zone->
name);
229 free((
void*) new_node);
246 ldns_rbnode_t* old_node = LDNS_RBTREE_NULL;
250 if (!zlist || !zlist->
zones) {
251 goto zone_not_present;
253 old_node = ldns_rbtree_delete(zlist->
zones, zone);
255 goto zone_not_present;
257 free((
void*) old_node);
276 ldns_rbnode_t* n1 = LDNS_RBTREE_NULL;
277 ldns_rbnode_t* n2 = LDNS_RBTREE_NULL;
286 n1 = ldns_rbtree_first(zl1->
zones);
287 n2 = ldns_rbtree_first(zl2->
zones);
288 while (n2 && n2 != LDNS_RBTREE_NULL) {
290 if (n1 && n1 != LDNS_RBTREE_NULL) {
302 ods_log_crit(
"[%s] merge failed: z2 not added", zl_str);
305 n2 = ldns_rbtree_next(n2);
308 ret = zone_compare(z1, z2);
313 n1 = ldns_rbtree_next(n1);
314 }
else if (ret > 0) {
318 ods_log_crit(
"[%s] merge failed: z2 not added", zl_str);
321 n2 = ldns_rbtree_next(n2);
324 n1 = ldns_rbtree_next(n1);
325 n2 = ldns_rbtree_next(n2);
336 while (n1 && n1 != LDNS_RBTREE_NULL) {
340 n1 = ldns_rbtree_next(n1);
358 char* datestamp = NULL;
361 if (!zl|| !zl->
zones || !zlfile) {
366 if (st_mtime <= zl->last_modified) {
369 zl_str, zlfile, datestamp?datestamp:
"Unknown");
370 free((
void*)datestamp);
380 ods_log_error(
"[%s] unable to update zonelist: zonelist_create() "
386 status = zonelist_read(new_zlist, zlfile);
392 zonelist_merge(zl, new_zlist);
394 ods_log_debug(
"[%s] file %s is modified since %s", zl_str, zlfile,
395 datestamp?datestamp:
"Unknown");
396 free((
void*)datestamp);
398 ods_log_error(
"[%s] unable to update zonelist: read file %s failed "
412 zone_delfunc(ldns_rbnode_t* elem)
415 if (elem && elem != LDNS_RBTREE_NULL) {
417 zone_delfunc(elem->left);
418 zone_delfunc(elem->right);
432 node_delfunc(ldns_rbnode_t* elem)
434 if (elem && elem != LDNS_RBTREE_NULL) {
435 node_delfunc(elem->left);
436 node_delfunc(elem->right);
457 zone_delfunc(zl->
zones->root);
458 ldns_rbtree_free(zl->
zones);
482 node_delfunc(zl->
zones->root);
483 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,...)