]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/icmp/net_db.cc
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / icmp / net_db.cc
index a5da2f7808f8152b04e7b4b22dacf2e93e88a651..d7ed9ee906abc501b54a65b76c8874f0451b0fc4 100644 (file)
@@ -90,8 +90,8 @@ public:
 
 CBDATA_CLASS_INIT(netdbExchangeState);
 
-static hash_table *addr_table = NULL;
-static hash_table *host_table = NULL;
+static hash_table *addr_table = nullptr;
+static hash_table *host_table = nullptr;
 
 Ip::Address networkFromInaddr(const Ip::Address &a);
 static void netdbRelease(netdbEntry * n);
@@ -114,14 +114,14 @@ static STCB netdbExchangeHandleReply;
  * gets freed during a reconfigure.  We want this database to
  * remain persisitent, so _net_db_peer->peername points into this
  * linked list */
-static wordlist *peer_names = NULL;
+static wordlist *peer_names = nullptr;
 
 static void
 netdbHashInsert(netdbEntry * n, Ip::Address &addr)
 {
     networkFromInaddr(addr).toStr(n->network, MAX_IPSTRLEN);
     n->key = n->network;
-    assert(hash_lookup(addr_table, n->network) == NULL);
+    assert(hash_lookup(addr_table, n->network) == nullptr);
     hash_join(addr_table, n);
 }
 
@@ -130,7 +130,7 @@ netdbHashDelete(const char *key)
 {
     hash_link *hptr = (hash_link *)hash_lookup(addr_table, key);
 
-    if (hptr == NULL) {
+    if (hptr == nullptr) {
         debug_trap("netdbHashDelete: key not found");
         return;
     }
@@ -153,15 +153,15 @@ static void
 netdbHostInsert(netdbEntry * n, const char *hostname)
 {
     net_db_name *x = new net_db_name(hostname, n);
-    assert(hash_lookup(host_table, hostname) == NULL);
+    assert(hash_lookup(host_table, hostname) == nullptr);
     hash_join(host_table, x);
 }
 
 static void
 netdbHostDelete(const net_db_name * x)
 {
-    assert(x != NULL);
-    assert(x->net_db_entry != NULL);
+    assert(x != nullptr);
+    assert(x->net_db_entry != nullptr);
 
     netdbEntry *n = x->net_db_entry;
     -- n->link_count;
@@ -181,7 +181,7 @@ static netdbEntry *
 netdbLookupHost(const char *key)
 {
     net_db_name *x = (net_db_name *) hash_lookup(host_table, key);
-    return x ? x->net_db_entry : NULL;
+    return x ? x->net_db_entry : nullptr;
 }
 
 static void
@@ -195,9 +195,9 @@ netdbRelease(netdbEntry * n)
         netdbHostDelete(x);
     }
 
-    n->hosts = NULL;
+    n->hosts = nullptr;
     safe_free(n->peers);
-    n->peers = NULL;
+    n->peers = nullptr;
     n->n_peers = 0;
     n->n_peers_alloc = 0;
 
@@ -275,7 +275,7 @@ netdbAdd(Ip::Address &addr)
     if (netdbEntry::UseCount() > Config.Netdb.high)
         netdbPurgeLRU();
 
-    if ((n = netdbLookupAddr(addr)) == NULL) {
+    if ((n = netdbLookupAddr(addr)) == nullptr) {
         n = new netdbEntry;
         netdbHashInsert(n, addr);
     }
@@ -287,21 +287,21 @@ static void
 netdbSendPing(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data)
 {
     Ip::Address addr;
-    char *hostname = NULL;
+    char *hostname = nullptr;
     static_cast<generic_cbdata *>(data)->unwrap(&hostname);
     netdbEntry *n;
     netdbEntry *na;
     net_db_name *x;
     net_db_name **X;
 
-    if (ia == NULL) {
+    if (ia == nullptr) {
         xfree(hostname);
         return;
     }
 
     addr = ia->current();
 
-    if ((n = netdbLookupHost(hostname)) == NULL) {
+    if ((n = netdbLookupHost(hostname)) == nullptr) {
         n = netdbAdd(addr);
         netdbHostInsert(n, hostname);
     } else if ((na = netdbLookupAddr(addr)) != n) {
@@ -309,14 +309,14 @@ netdbSendPing(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data)
          *hostname moved from 'network n' to 'network na'!
          */
 
-        if (na == NULL)
+        if (na == nullptr)
             na = netdbAdd(addr);
 
         debugs(38, 3, "netdbSendPing: " << hostname << " moved from " << n->network << " to " << na->network);
 
         x = (net_db_name *) hash_lookup(host_table, hostname);
 
-        if (x == NULL) {
+        if (x == nullptr) {
             debugs(38, DBG_IMPORTANT, "ERROR: Squid BUG: net_db_name list bug: " << hostname << " not found");
             xfree(hostname);
             return;
@@ -415,7 +415,7 @@ netdbPeerByName(const netdbEntry * n, const char *peername)
             return p;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 static net_db_peer *
@@ -528,7 +528,7 @@ netdbSaveState(void *)
     debugs(38, DBG_IMPORTANT, "NETDB state saved; " <<
            count << " entries, " <<
            tvSubMsec(start, current_time) << " msec" );
-    eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1);
+    eventAddIsh("netdbSaveState", netdbSaveState, nullptr, 3600.0, 1);
 }
 
 static void
@@ -583,21 +583,21 @@ netdbReloadState(void)
         q = strtok(t, w_space);
         t = s + 1;
 
-        if (NULL == q)
+        if (nullptr == q)
             continue;
 
         if (! (addr = q) )
             continue;
 
-        if (netdbLookupAddr(addr) != NULL)  /* no dups! */
+        if (netdbLookupAddr(addr) != nullptr)  /* no dups! */
             continue;
 
-        if ((q = strtok(NULL, w_space)) == NULL)
+        if ((q = strtok(nullptr, w_space)) == nullptr)
             continue;
 
         N.pings_sent = atoi(q);
 
-        if ((q = strtok(NULL, w_space)) == NULL)
+        if ((q = strtok(nullptr, w_space)) == nullptr)
             continue;
 
         N.pings_recv = atoi(q);
@@ -610,22 +610,22 @@ netdbReloadState(void)
 
         N.pings_recv = 1;
 
-        if ((q = strtok(NULL, w_space)) == NULL)
+        if ((q = strtok(nullptr, w_space)) == nullptr)
             continue;
 
         N.hops = atof(q);
 
-        if ((q = strtok(NULL, w_space)) == NULL)
+        if ((q = strtok(nullptr, w_space)) == nullptr)
             continue;
 
         N.rtt = atof(q);
 
-        if ((q = strtok(NULL, w_space)) == NULL)
+        if ((q = strtok(nullptr, w_space)) == nullptr)
             continue;
 
         N.next_ping_time = (time_t) atoi(q);
 
-        if ((q = strtok(NULL, w_space)) == NULL)
+        if ((q = strtok(nullptr, w_space)) == nullptr)
             continue;
 
         N.last_use_time = (time_t) atoi(q);
@@ -636,8 +636,8 @@ netdbReloadState(void)
 
         netdbHashInsert(n, addr);
 
-        while ((q = strtok(NULL, w_space)) != NULL) {
-            if (netdbLookupHost(q) != NULL) /* no dups! */
+        while ((q = strtok(nullptr, w_space)) != nullptr) {
+            if (netdbLookupHost(q) != nullptr) /* no dups! */
                 continue;
 
             netdbHostInsert(n, q);
@@ -896,7 +896,7 @@ netdbInit(void)
 
     host_table = hash_create((HASHCMP *) strcmp, n, hash_string);
 
-    eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1);
+    eventAddIsh("netdbSaveState", netdbSaveState, nullptr, 3600.0, 1);
 
     netdbReloadState();
 
@@ -909,7 +909,7 @@ netdbPingSite(const char *hostname)
 #if USE_ICMP
     netdbEntry *n;
 
-    if ((n = netdbLookupHost(hostname)) != NULL)
+    if ((n = netdbLookupHost(hostname)) != nullptr)
         if (n->next_ping_time > squid_curtime)
             return;
 
@@ -928,7 +928,7 @@ netdbHandlePingReply(const Ip::Address &from, int hops, int rtt)
     int N;
     debugs(38, 3, "netdbHandlePingReply: from " << from);
 
-    if ((n = netdbLookupAddr(from)) == NULL)
+    if ((n = netdbLookupAddr(from)) == nullptr)
         return;
 
     N = ++n->pings_recv;
@@ -959,12 +959,12 @@ netdbFreeMemory(void)
 #if USE_ICMP
     hashFreeItems(addr_table, netdbFreeNetdbEntry);
     hashFreeMemory(addr_table);
-    addr_table = NULL;
+    addr_table = nullptr;
     hashFreeItems(host_table, netdbFreeNameEntry);
     hashFreeMemory(host_table);
-    host_table = NULL;
+    host_table = nullptr;
     wordlistDestroy(&peer_names);
-    peer_names = NULL;
+    peer_names = nullptr;
 #endif
 }
 
@@ -1074,7 +1074,7 @@ netdbHostData(const char *host, int *samp, int *rtt, int *hops)
 #if USE_ICMP
     netdbEntry *n = netdbLookupHost(host);
 
-    if (n == NULL)
+    if (n == nullptr)
         return;
 
     *samp = n->pings_recv;
@@ -1104,12 +1104,12 @@ netdbUpdatePeer(const AnyP::Uri &url, CachePeer *e, int irtt, int ihops)
     debugs(38, 3, url.host() << ", " << ihops << " hops, " << irtt << " rtt");
     n = netdbLookupHost(url.host());
 
-    if (n == NULL) {
+    if (n == nullptr) {
         debugs(38, 3, "host " << url.host() << " not found");
         return;
     }
 
-    if ((p = netdbPeerByName(n, e->host)) == NULL)
+    if ((p = netdbPeerByName(n, e->host)) == nullptr)
         p = netdbPeerAdd(n, e);
 
     p->rtt = rtt;
@@ -1151,12 +1151,12 @@ netdbExchangeUpdatePeer(Ip::Address &addr, CachePeer * e, double rtt, double hop
 
     n = netdbLookupAddr(addr);
 
-    if (n == NULL)
+    if (n == nullptr)
         n = netdbAdd(addr);
 
-    assert(NULL != n);
+    assert(nullptr != n);
 
-    if ((p = netdbPeerByName(n, e->host)) == NULL)
+    if ((p = netdbPeerByName(n, e->host)) == nullptr)
         p = netdbPeerAdd(n, e);
 
     p->rtt = rtt;
@@ -1187,7 +1187,7 @@ netdbDeleteAddrNetwork(Ip::Address &addr)
 #if USE_ICMP
     netdbEntry *n = netdbLookupAddr(addr);
 
-    if (n == NULL)
+    if (n == nullptr)
         return;
 
     debugs(38, 3, "netdbDeleteAddrNetwork: " << n->network);
@@ -1214,7 +1214,7 @@ netdbBinaryExchange(StoreEntry * s)
 
     struct in_addr line_addr;
     s->buffer();
-    reply->setHeaders(Http::scOkay, "OK", NULL, -1, squid_curtime, -2);
+    reply->setHeaders(Http::scOkay, "OK", nullptr, -1, squid_curtime, -2);
     s->replaceHttpReply(reply);
     rec_sz = 0;
     rec_sz += 1 + sizeof(struct in_addr);
@@ -1306,7 +1306,7 @@ netdbExchangeStart(void *data)
 
     netdbExchangeState *ex = new netdbExchangeState(p, req);
     ex->e = storeCreateEntry(uri, uri, RequestFlags(), Http::METHOD_GET);
-    assert(NULL != ex->e);
+    assert(nullptr != ex->e);
 
     StoreIOBuffer tempBuffer;
     tempBuffer.length = ex->buf_sz;
@@ -1335,26 +1335,26 @@ netdbClosestParent(PeerSelector *ps)
     assert(ps);
     HttpRequest *request = ps->request;
 
-    CachePeer *p = NULL;
+    CachePeer *p = nullptr;
     netdbEntry *n;
     const ipcache_addrs *ia;
     net_db_peer *h;
     int i;
     n = netdbLookupHost(request->url.host());
 
-    if (NULL == n) {
+    if (nullptr == n) {
         /* try IP addr */
         ia = ipcache_gethostbyname(request->url.host(), 0);
 
-        if (NULL != ia)
+        if (nullptr != ia)
             n = netdbLookupAddr(ia->current());
     }
 
-    if (NULL == n)
-        return NULL;
+    if (nullptr == n)
+        return nullptr;
 
     if (0 == n->n_peers)
-        return NULL;
+        return nullptr;
 
     n->last_use_time = squid_curtime;
 
@@ -1372,7 +1372,7 @@ netdbClosestParent(PeerSelector *ps)
 
         p = peerFindByName(h->peername);
 
-        if (NULL == p)      /* not found */
+        if (nullptr == p)      /* not found */
             continue;
 
         if (neighborType(p, request->url) != PEER_PARENT)
@@ -1387,6 +1387,6 @@ netdbClosestParent(PeerSelector *ps)
 #else
     (void)ps;
 #endif
-    return NULL;
+    return nullptr;
 }