45 #include <ldns/ldns.h>
48 static const char* zl_str =
"zonelist";
56 zone_compare(
const void* a,
const void* b)
83 ods_log_error(
"[%s] cannot create: no allocator available", zl_str);
90 ods_log_error(
"[%s] cannot create: allocator failed", zl_str);
96 zlist->
zones = ldns_rbtree_create(zone_compare);
111 const char* rngfile = ODS_SE_RNGDIR
"/zonelist.rng";
134 static ldns_rbnode_t*
137 ldns_rbnode_t* node = (ldns_rbnode_t*) malloc(
sizeof(ldns_rbnode_t));
154 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
156 if (!zonelist || !zonelist->
zones) {
157 ods_log_error(
"[%s] unable to lookup zone: no zonelist", zl_str);
163 ods_log_error(
"[%s] unable to lookup zone: zone is null", zl_str);
168 node = ldns_rbtree_search(zonelist->
zones, zone);
187 if (!zonelist || !zonelist->
zones || !name || !klass) {
197 ods_log_error(
"[%s] unable to lookup zone: create zone failed", zl_str);
200 result = zonelist_lookup_zone(zonelist, zone);
213 ldns_rbnode_t* new_node = NULL;
216 ods_log_error(
"[%s] unable to add zone: zone is null", zl_str);
220 if (!zlist || !zlist->
zones) {
221 ods_log_error(
"[%s] unable to add zone %s: no zonelist", zl_str,
229 if (zonelist_lookup_zone(zlist, zone) != NULL) {
236 new_node = zone2node(zone);
237 if (ldns_rbtree_insert(zlist->
zones, new_node) == NULL) {
238 ods_log_error(
"[%s] unable to add zone %s: rbtree insert failed",
240 free((
void*) new_node);
257 ldns_rbnode_t* old_node = LDNS_RBTREE_NULL;
264 if (!zlist || !zlist->
zones) {
265 ods_log_error(
"[%s] unable to delete zone %s: no zone list", zl_str,
272 old_node = ldns_rbtree_delete(zlist->
zones, zone);
278 free((
void*) old_node);
292 ldns_rbnode_t* n1 = LDNS_RBTREE_NULL;
293 ldns_rbnode_t* n2 = LDNS_RBTREE_NULL;
302 n1 = ldns_rbtree_first(zl1->
zones);
303 n2 = ldns_rbtree_first(zl2->
zones);
304 while (n2 && n2 != LDNS_RBTREE_NULL) {
306 if (n1 && n1 != LDNS_RBTREE_NULL) {
322 n2 = ldns_rbtree_next(n2);
325 ret = zone_compare(z1, z2);
330 n1 = ldns_rbtree_next(n1);
331 }
else if (ret > 0) {
338 n2 = ldns_rbtree_next(n2);
341 n1 = ldns_rbtree_next(n1);
342 n2 = ldns_rbtree_next(n2);
354 while (n1 && n1 != LDNS_RBTREE_NULL) {
358 n1 = ldns_rbtree_next(n1);
377 char* datestamp = NULL;
381 if (!zl|| !zl->
zones) {
382 ods_log_error(
"[%s] cannot update: no zonelist storaga", zl_str);
395 if (st_mtime <= zl->last_modified) {
397 "%Y-%m-%d %T", &datestamp);
399 zl_str, zlfile, datestamp?datestamp:
"Unknown");
400 free((
void*)datestamp);
419 status = zonelist_read(new_zlist, zlfile);
425 zonelist_merge(zl, new_zlist);
428 ods_log_debug(
"[%s] file %s is modified since %s", zl_str, zlfile,
429 datestamp?datestamp:
"Unknown");
430 free((
void*)datestamp);
432 ods_log_error(
"[%s] unable to read file %s: %s", zl_str, zlfile,
447 zone_delfunc(ldns_rbnode_t* elem)
451 if (elem && elem != LDNS_RBTREE_NULL) {
453 zone_delfunc(elem->left);
454 zone_delfunc(elem->right);
469 node_delfunc(ldns_rbnode_t* elem)
471 if (elem && elem != LDNS_RBTREE_NULL) {
472 node_delfunc(elem->left);
473 node_delfunc(elem->right);
496 zone_delfunc(zl->
zones->root);
497 ldns_rbtree_free(zl->
zones);
525 node_delfunc(zl->
zones->root);
526 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)
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 *))
allocator_type * allocator
void ods_log_verbose(const char *format,...)
#define lock_basic_init(lock)
ods_status parse_zonelist_zones(struct zonelist_struct *zlist, const char *zlfile)
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 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,...)