[Opendnssec-commits] [svn.opendnssec.org/svn/dnssec] r5434 - branches/OpenDNSSEC-adapters/signer/src/signer

Matthijs Mekking matthijs at nlnetlabs.nl
Mon Aug 22 15:21:21 CEST 2011


Author: matthijs
Date: 2011-08-22 15:21:21 +0200 (Mon, 22 Aug 2011)
New Revision: 5434

Modified:
   branches/OpenDNSSEC-adapters/signer/src/signer/zonelist.c
Log:
adjust log messages, code style



Modified: branches/OpenDNSSEC-adapters/signer/src/signer/zonelist.c
===================================================================
--- branches/OpenDNSSEC-adapters/signer/src/signer/zonelist.c	2011-08-22 12:55:27 UTC (rev 5433)
+++ branches/OpenDNSSEC-adapters/signer/src/signer/zonelist.c	2011-08-22 13:21:21 UTC (rev 5434)
@@ -57,10 +57,8 @@
 {
     zone_type* x = (zone_type*)a;
     zone_type* y = (zone_type*)b;
-
     ods_log_assert(x);
     ods_log_assert(y);
-
     if (x->klass != y->klass) {
         if (x->klass < y->klass) {
             return -1;
@@ -78,22 +76,23 @@
 zonelist_type*
 zonelist_create(allocator_type* allocator)
 {
-    zonelist_type* zlist;
-    if (!allocator) {
-        ods_log_error("[%s] cannot create: no allocator available", zl_str);
-        return NULL;
+    zonelist_type* zlist = NULL;
+    if (allocator) {
+        zlist = (zonelist_type*) allocator_alloc(allocator, sizeof(zonelist_type));
     }
-    ods_log_assert(allocator);
-
-    zlist = (zonelist_type*) allocator_alloc(allocator, sizeof(zonelist_type));
     if (!zlist) {
-        ods_log_error("[%s] cannot create: allocator failed", zl_str);
+        ods_log_error("[%s] unable to create zonelist: allocator_alloc() "
+            "failed", zl_str);
         return NULL;
     }
-    ods_log_assert(zlist);
-
     zlist->allocator = allocator;
     zlist->zones = ldns_rbtree_create(zone_compare);
+    if (!zlist->zones) {
+        ods_log_error("[%s] unable to create zonelist: ldns_rbtree_create() "
+            "failed", zl_str);
+        allocator_deallocate(allocator, (void*) zlist);
+        return NULL;
+    }
     zlist->last_modified = 0;
     lock_basic_init(&zlist->zl_lock);
     return zlist;
@@ -109,19 +108,14 @@
 {
     const char* rngfile = ODS_SE_RNGDIR "/zonelist.rng";
     ods_status status = ODS_STATUS_OK;
-
     ods_log_assert(zlfile);
     ods_log_verbose("[%s] read file %s", zl_str, zlfile);
-
-    /* does the file have no parse errors? */
     status = parse_file_check(zlfile, rngfile);
     if (status != ODS_STATUS_OK) {
-        ods_log_error("[%s] unable to parse file %s: %s", zl_str,
-            zlfile, ods_status2str(status));
+        ods_log_error("[%s] unable to read file: parse error in %s", zl_str,
+            zlfile);
         return status;
     }
-
-    /* ok, parse it */
     return parse_zonelist_zones((struct zonelist_struct*) zl, zlfile);
 }
 
@@ -151,23 +145,12 @@
 zonelist_lookup_zone(zonelist_type* zonelist, zone_type* zone)
 {
     ldns_rbnode_t* node = LDNS_RBTREE_NULL;
-
-    if (!zonelist || !zonelist->zones) {
-        ods_log_error("[%s] unable to lookup zone: no zonelist", zl_str);
-        return NULL;
+    if (zonelist && zonelist->zones && zone) {
+        node = ldns_rbtree_search(zonelist->zones, zone);
+        if (node) {
+            return (zone_type*) node->data;
+        }
     }
-    ods_log_assert(zonelist);
-    ods_log_assert(zonelist->zones);
-    if (!zone) {
-        ods_log_error("[%s] unable to lookup zone: zone is null", zl_str);
-        return NULL;
-    }
-    ods_log_assert(zone);
-
-    node = ldns_rbtree_search(zonelist->zones, zone);
-    if (node) {
-        return (zone_type*) node->data;
-    }
     return NULL;
 }
 
@@ -182,22 +165,17 @@
 {
     zone_type* zone = NULL;
     zone_type* result = NULL;
-
-    if (!zonelist || !zonelist->zones || !name || !klass) {
-        return NULL;
+    if (zonelist && zonelist->zones && name  && klass) {
+        zone = zone_create((char*) name, klass);
+        if (!zone) {
+            ods_log_error("[%s] unable to lookup zone %s: "
+                "zone_create() failed", zl_str, name);
+            /* result stays NULL */
+        } else {
+            result = zonelist_lookup_zone(zonelist, zone);
+            zone_cleanup(zone);
+        }
     }
-    ods_log_assert(zonelist);
-    ods_log_assert(zonelist->zones);
-    ods_log_assert(name);
-    ods_log_assert(klass);
-
-    zone = zone_create((char*) name, klass);
-    if (!zone) {
-        ods_log_error("[%s] unable to lookup zone: create zone failed", zl_str);
-        return NULL;
-    }
-    result = zonelist_lookup_zone(zonelist, zone);
-    zone_cleanup(zone);
     return result;
 }
 
@@ -210,32 +188,25 @@
 zonelist_add_zone(zonelist_type* zlist, zone_type* zone)
 {
     ldns_rbnode_t* new_node = NULL;
-
     if (!zone) {
-        ods_log_error("[%s] unable to add zone: zone is null", zl_str);
         return NULL;
     }
-    ods_log_assert(zone);
     if (!zlist || !zlist->zones) {
-        ods_log_error("[%s] unable to add zone %s: no zonelist", zl_str,
-            zone->name);
         zone_cleanup(zone);
         return NULL;
     }
-    ods_log_assert(zlist);
-    ods_log_assert(zlist->zones);
-
+    /* look up */
     if (zonelist_lookup_zone(zlist, zone) != NULL) {
         ods_log_warning("[%s] unable to add zone %s: already present", zl_str,
             zone->name);
         zone_cleanup(zone);
         return NULL;
     }
-
+    /* add */
     new_node = zone2node(zone);
     if (ldns_rbtree_insert(zlist->zones, new_node) == NULL) {
-        ods_log_error("[%s] unable to add zone %s: rbtree insert failed",
-            zl_str, zone->name);
+        ods_log_error("[%s] unable to add zone %s: ldns_rbtree_insert() "
+            "failed", zl_str, zone->name);
         free((void*) new_node);
         zone_cleanup(zone);
         return NULL;
@@ -254,28 +225,23 @@
 zonelist_del_zone(zonelist_type* zlist, zone_type* zone)
 {
     ldns_rbnode_t* old_node = LDNS_RBTREE_NULL;
-
     if (!zone) {
-        ods_log_warning("[%s] unable to delete zone: zone is null", zl_str);
         return NULL;
     }
-    ods_log_assert(zone);
     if (!zlist || !zlist->zones) {
-        ods_log_error("[%s] unable to delete zone %s: no zone list", zl_str,
-            zone->name);
-        return zone;
+        goto zone_not_present;
     }
-    ods_log_assert(zlist);
-    ods_log_assert(zlist->zones);
-
     old_node = ldns_rbtree_delete(zlist->zones, zone);
     if (!old_node) {
-        ods_log_warning("[%s] unable to delete zone %s: not present", zl_str,
-            zone->name);
-        return zone;
+        goto zone_not_present;
     }
     free((void*) old_node);
     return zone;
+
+zone_not_present:
+    ods_log_warning("[%s] unable to delete zone %s: not present", zl_str,
+        zone->name);
+    return zone;
 }
 
 
@@ -307,7 +273,6 @@
         } else {
             z1 = NULL;
         }
-
         if (!z2) {
             /* no more zones to merge into zl1 */
             return;
@@ -315,7 +280,7 @@
             /* just add remaining zones from zl2 */
             z2 = zonelist_add_zone(zl1, z2);
             if (!z2) {
-                ods_log_error("[%s] merge failed: z2 not added", zl_str);
+                ods_log_crit("[%s] merge failed: z2 not added", zl_str);
                 return;
             }
             n2 = ldns_rbtree_next(n2);
@@ -331,7 +296,7 @@
                 /* add the new zone z2 */
                 z2 = zonelist_add_zone(zl1, z2);
                 if (!z2) {
-                    ods_log_error("[%s] merge failed: z2 not added", zl_str);
+                    ods_log_crit("[%s] merge failed: z2 not added", zl_str);
                     return;
                 }
                 n2 = ldns_rbtree_next(n2);
@@ -348,7 +313,6 @@
             }
         }
     }
-
     /* remove remaining zones from z1 */
     while (n1 && n1 != LDNS_RBTREE_NULL) {
         z1 = (zone_type*) n1->data;
@@ -356,7 +320,6 @@
         zl1->just_removed++;
         n1 = ldns_rbtree_next(n1);
     }
-
     zl1->last_modified = zl2->last_modified;
     return;
 }
@@ -377,18 +340,9 @@
     uint32_t ustamp = 0;
 
     ods_log_debug("[%s] update zone list", zl_str);
-    if (!zl|| !zl->zones) {
-        ods_log_error("[%s] cannot update: no zonelist storaga", zl_str);
+    if (!zl|| !zl->zones || !zlfile) {
         return ODS_STATUS_ASSERT_ERR;
     }
-    ods_log_assert(zl);
-    ods_log_assert(zl->zones);
-    if (!zlfile) {
-        ods_log_error("[%s] cannot update: no filename", zl_str);
-        return ODS_STATUS_ASSERT_ERR;
-    }
-    ods_log_assert(zlfile);
-
     /* is the file updated? */
     st_mtime = ods_file_lastmodified(zlfile);
     if (st_mtime <= zl->last_modified) {
@@ -399,21 +353,18 @@
         free((void*)datestamp);
         return ODS_STATUS_UNCHANGED;
     }
-
     /* create new zonelist */
     tmp_alloc = allocator_create(malloc, free);
     if (!tmp_alloc) {
-        ods_log_error("[%s] error creating allocator for zone list",
-            zl_str);
-        return ODS_STATUS_ERR;
+        return ODS_STATUS_MALLOC_ERR;
     }
     new_zlist = zonelist_create(tmp_alloc);
     if (!new_zlist) {
-        ods_log_error("[%s] error creating new zone list", zl_str);
+        ods_log_error("[%s] unable to update zonelist: zonelist_create() "
+            "failed", zl_str);
         allocator_cleanup(tmp_alloc);
         return ODS_STATUS_ERR;
     }
-
     /* read zonelist */
     status = zonelist_read(new_zlist, zlfile);
     if (status == ODS_STATUS_OK) {
@@ -428,10 +379,9 @@
             datestamp?datestamp:"Unknown");
         free((void*)datestamp);
     } else {
-        ods_log_error("[%s] unable to read file %s: %s", zl_str, zlfile,
-            ods_status2str(status));
+        ods_log_error("[%s] unable to update zonelist: read file %s failed "
+            "(%s)", zl_str, zlfile, ods_status2str(status));
     }
-
     zonelist_free(new_zlist);
     allocator_cleanup(tmp_alloc);
     return status;
@@ -446,13 +396,11 @@
 zone_delfunc(ldns_rbnode_t* elem)
 {
     zone_type* zone;
-
     if (elem && elem != LDNS_RBTREE_NULL) {
         zone = (zone_type*) elem->data;
         zone_delfunc(elem->left);
         zone_delfunc(elem->right);
-
-        ods_log_debug("[%s] cleanup zone %s", zl_str, zone->name);
+        ods_log_deeebug("[%s] cleanup zone %s", zl_str, zone->name);
         zone_cleanup(zone);
         free((void*)elem);
     }
@@ -485,21 +433,17 @@
 {
     allocator_type* allocator;
     lock_basic_type zl_lock;
-
     if (!zl) {
         return;
     }
-
     ods_log_debug("[%s] cleanup zonelist", zl_str);
     if (zl->zones) {
         zone_delfunc(zl->zones->root);
         ldns_rbtree_free(zl->zones);
         zl->zones = NULL;
     }
-
     allocator = zl->allocator;
     zl_lock = zl->zl_lock;
-
     allocator_deallocate(allocator, (void*) zl);
     lock_basic_destroy(&zl_lock);
     return;
@@ -515,20 +459,16 @@
 {
     allocator_type* allocator;
     lock_basic_type zl_lock;
-
     if (!zl) {
         return;
     }
-
     if (zl->zones) {
         node_delfunc(zl->zones->root);
         ldns_rbtree_free(zl->zones);
         zl->zones = NULL;
     }
-
     allocator = zl->allocator;
     zl_lock = zl->zl_lock;
-
     allocator_deallocate(allocator, (void*) zl);
     lock_basic_destroy(&zl_lock);
     return;




More information about the Opendnssec-commits mailing list