]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
generic callback support
authorwessels <>
Tue, 17 Jun 1997 09:03:19 +0000 (09:03 +0000)
committerwessels <>
Tue, 17 Jun 1997 09:03:19 +0000 (09:03 +0000)
src/Makefile.in
src/acl.cc
src/comm.cc
src/ipcache.cc
src/main.cc
src/neighbors.cc
src/net_db.cc
src/send-announce.cc
src/squid.h

index 0d130f044fc92a65be24e8494f242dff7df13beb..24e121f566976c977e65a35c9faf08e8b1c8e542 100644 (file)
@@ -1,7 +1,7 @@
 #
 #  Makefile for the Squid Object Cache server
 #
-#  $Id: Makefile.in,v 1.75 1997/06/16 22:01:42 wessels Exp $
+#  $Id: Makefile.in,v 1.76 1997/06/17 03:03:19 wessels Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -78,6 +78,7 @@ OBJS          = \
                aiops.o \
                async_io.o \
                cache_cf.o \
+               callback.o \
                client_db.o \
                client_side.o \
                comm.o \
index 836a938000c2291dbfc2ef06c0bd6e20e0fb93d9..39506a3f43c6be9b7a6487c83a5debae5c47caa7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: acl.cc,v 1.97 1997/06/16 22:01:43 wessels Exp $
+ * $Id: acl.cc,v 1.98 1997/06/17 03:03:20 wessels Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Duane Wessels
@@ -1176,7 +1176,8 @@ aclCheck(aclCheck_t * checklist)
            checklist->state[ACL_DST_IP] = ACL_LOOKUP_PENDING;
            ipcache_nbgethostbyname(checklist->request->host,
                aclLookupDstIPDone,
-               checklist);
+               checklist,
+               &checklist->cbm_list);
            return;
        } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NEEDED) {
            checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_PENDING;
@@ -1215,9 +1216,8 @@ aclChecklistFree(aclCheck_t * checklist)
        fqdncacheUnregister(checklist->src_addr, checklist);
     if (checklist->state[ACL_DST_DOMAIN] == ACL_LOOKUP_PENDING)
        fqdncacheUnregister(checklist->dst_addr, checklist);
-    if (checklist->state[ACL_DST_IP] == ACL_LOOKUP_PENDING)
-       ipcacheUnregister(checklist->request->host, checklist);
     requestUnlink(checklist->request);
+    callbackUnlinkList(checklist->cbm_list);
     xfree(checklist);
 }
 
index a8a55c7aae287b02f41433eb4d774ed185f4054c..11930bc43564f374760a5f58542a3798f55fb571 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.162 1997/06/16 22:01:44 wessels Exp $
+ * $Id: comm.cc,v 1.163 1997/06/17 03:03:21 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -140,6 +140,7 @@ typedef struct {
     struct in_addr in_addr;
     int locks;
     int fd;
+    callback_meta *cbm_list;
 } ConnectStateData;
 
 /* GLOBAL */
@@ -337,7 +338,7 @@ commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *
     cs->data = data;
     comm_add_close_handler(fd, commConnectFree, cs);
     cs->locks++;
-    ipcache_nbgethostbyname(host, commConnectDnsHandle, cs);
+    ipcache_nbgethostbyname(host, commConnectDnsHandle, cs, &cs->cbm_list);
 }
 
 static void
@@ -370,8 +371,7 @@ static void
 commConnectFree(int fdunused, void *data)
 {
     ConnectStateData *cs = data;
-    if (cs->locks)
-       ipcacheUnregister(cs->host, cs);
+    callbackUnlinkList(cs->cbm_list);
     xfree(cs->host);
     xfree(cs);
 }
@@ -425,7 +425,7 @@ commConnectHandle(int fd, void *data)
            cs->S.sin_addr.s_addr = 0;
            ipcacheCycleAddr(cs->host);
            cs->locks++;
-           ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs);
+           ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs, &cs->cbm_list);
        } else {
            ipcacheRemoveBadAddr(cs->host, cs->S.sin_addr);
            commConnectCallback(cs, COMM_ERR_CONNECT);
index 1f173e1ebfab6c48921966e39c6402a83e72e994..aa1c0c9dbc9821b98fbb06fc941833ac7edfb54c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ipcache.cc,v 1.121 1997/06/16 22:01:48 wessels Exp $
+ * $Id: ipcache.cc,v 1.122 1997/06/17 03:03:22 wessels Exp $
  *
  * DEBUG: section 14    IP Cache
  * AUTHOR: Harvest Derived
 
 struct _ip_pending {
     IPH *handler;
-    void *handlerData;
+    callback_meta *cbm;
     struct _ip_pending *next;
 };
 
@@ -147,7 +147,7 @@ static int ipcacheHasPending _PARAMS((ipcache_entry *));
 static ipcache_entry *ipcache_get _PARAMS((const char *));
 static IPH dummy_handler;
 static int ipcacheExpiredEntry _PARAMS((ipcache_entry *));
-static void ipcacheAddPending _PARAMS((ipcache_entry *, IPH *, void *));
+static void ipcacheAddPending _PARAMS((ipcache_entry *, IPH *, void *, callback_meta **));
 static void ipcacheEnqueue _PARAMS((ipcache_entry *));
 static void *ipcacheDequeue _PARAMS((void));
 static void ipcache_dnsDispatch _PARAMS((dnsserver_t *, ipcache_entry *));
@@ -156,6 +156,7 @@ static void ipcacheUnlockEntry _PARAMS((ipcache_entry *));
 static void ipcacheLockEntry _PARAMS((ipcache_entry *));
 static void ipcacheNudgeQueue _PARAMS((void));
 static void ipcacheChangeKey _PARAMS((ipcache_entry * i));
+static UNREG ipcacheUnregister;
 
 static ipcache_addrs static_addrs;
 static HashID ip_table = 0;
@@ -238,13 +239,11 @@ static void
 ipcache_release(ipcache_entry * i)
 {
     hash_link *table_entry = NULL;
-
     if ((table_entry = hash_lookup(ip_table, i->name)) == NULL) {
        debug(14, 0) ("ipcache_release: Could not find key '%s'\n", i->name);
        return;
     }
-    if (i != (ipcache_entry *) table_entry)
-       fatal_dump("ipcache_release: i != table_entry!");
+    assert (i == (ipcache_entry *) table_entry);
     if (i->locks) {
        i->expires = squid_curtime;
        ipcacheChangeKey(i);
@@ -449,19 +448,19 @@ ipcache_call_pending(ipcache_entry * i)
 {
     struct _ip_pending *p = NULL;
     int nhandler = 0;
-
+    void *handlerData;
     i->lastref = squid_curtime;
-
     ipcacheLockEntry(i);
     while (i->pending_head != NULL) {
        p = i->pending_head;
        i->pending_head = p->next;
-       if (p->handler) {
+       handlerData = callbackCheck(p->cbm);
+       if (p->handler && handlerData) {
            nhandler++;
            dns_error_message = i->error_message;
-           p->handler(i->status == IP_CACHED ? &i->addrs : NULL,
-               p->handlerData);
+           p->handler(i->status == IP_CACHED ? &i->addrs : NULL, handlerData);
        }
+        callbackUnlink(p->cbm);
        safe_free(p);
     }
     i->pending_head = NULL;    /* nuke list */
@@ -628,13 +627,13 @@ ipcache_dnsHandleRead(int fd, void *data)
 }
 
 static void
-ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData)
+ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData, callback_meta **head)
 {
     struct _ip_pending *pending = xcalloc(1, sizeof(struct _ip_pending));
     struct _ip_pending **I = NULL;
     i->lastref = squid_curtime;
     pending->handler = handler;
-    pending->handlerData = handlerData;
+    pending->cbm = callbackRegister(handlerData, ipcacheUnregister, pending, head);
     for (I = &(i->pending_head); *I; I = &((*I)->next));
     *I = pending;
     if (i->status == IP_PENDING)
@@ -642,7 +641,7 @@ ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData)
 }
 
 void
-ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData)
+ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData, callback_meta **cbmhead)
 {
     ipcache_entry *i = NULL;
     dnsserver_t *dnsData = NULL;
@@ -674,7 +673,7 @@ ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData)
        debug(14, 5) ("ipcache_nbgethostbyname: MISS for '%s'\n", name);
        IpcacheStats.misses++;
        i = ipcacheAddNew(name, NULL, IP_PENDING);
-       ipcacheAddPending(i, handler, handlerData);
+       ipcacheAddPending(i, handler, handlerData, cbmhead);
     } else if (i->status == IP_CACHED || i->status == IP_NEGATIVE_CACHED) {
        /* HIT */
        debug(14, 4) ("ipcache_nbgethostbyname: HIT for '%s'\n", name);
@@ -682,13 +681,13 @@ ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData)
            IpcacheStats.negative_hits++;
        else
            IpcacheStats.hits++;
-       ipcacheAddPending(i, handler, handlerData);
+       ipcacheAddPending(i, handler, handlerData, cbmhead);
        ipcache_call_pending(i);
        return;
     } else if (i->status == IP_PENDING || i->status == IP_DISPATCHED) {
        debug(14, 4) ("ipcache_nbgethostbyname: PENDING for '%s'\n", name);
        IpcacheStats.pending_hits++;
-       ipcacheAddPending(i, handler, handlerData);
+       ipcacheAddPending(i, handler, handlerData, cbmhead);
        if (squid_curtime - i->expires > 600) {
            debug(14, 0) ("ipcache_nbgethostbyname: '%s' PENDING for %d seconds, aborting\n", name, squid_curtime + Config.negativeDnsTtl - i->expires);
            ipcacheChangeKey(i);
@@ -779,29 +778,12 @@ ipcache_init(void)
            (float) Config.ipcache.low) / (float) 100);
 }
 
-/* clean up the pending entries in dnsserver */
-/* return 1 if we found the host, 0 otherwise */
-int
-ipcacheUnregister(const char *name, void *data)
+static void
+ipcacheUnregister(void *data)
 {
-    ipcache_entry *i = NULL;
-    struct _ip_pending *p = NULL;
-    int n = 0;
-    debug(14, 3) ("ipcacheUnregister: FD %d, name '%s'\n", name);
-    if ((i = ipcache_get(name)) == NULL)
-       return 0;
-    if (i->status == IP_PENDING || i->status == IP_DISPATCHED) {
-       for (p = i->pending_head; p; p = p->next) {
-           if (p->handlerData != data)
-               continue;
-           p->handler = NULL;
-           n++;
-       }
-    }
-    if (n == 0)
-       debug_trap("ipcacheUnregister: callback data not found");
-    debug(14, 3) ("ipcacheUnregister: unregistered %d handlers\n", n);
-    return n;
+    struct _ip_pending *p = data;
+    p->handler = NULL;
+    debug(14, 3) ("ipcacheUnregister: unregistered something\n");
 }
 
 const ipcache_addrs *
@@ -876,7 +858,7 @@ ipcache_gethostbyname(const char *name, int flags)
        }
     }
     if (flags & IP_LOOKUP_IF_MISS)
-       ipcache_nbgethostbyname(name, dummy_handler, NULL);
+       ipcache_nbgethostbyname(name, dummy_handler, NULL, NULL);
     return NULL;
 }
 
index b3f6ae88063d400cbf6935e32f3af4568e1e0572..430e5fa05b9b0c651b4e929f16b9ec0da28e2fc8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.cc,v 1.153 1997/06/16 22:01:49 wessels Exp $
+ * $Id: main.cc,v 1.154 1997/06/17 03:03:23 wessels Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -390,7 +390,7 @@ serverConnectionsOpen(void)
                icpHandleUdp,
                NULL, 0);
            for (s = Config.mcast_group_list; s; s = s->next)
-               ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
+               ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL, NULL);
            debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n",
                (int) port, theInIcpConnection);
 
index 0f53c532a6f2392ec18928dfa512be606196b54b..c0b584b06c93008a13e1a7d0c32449a3783c807e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: neighbors.cc,v 1.144 1997/06/16 22:01:50 wessels Exp $
+ * $Id: neighbors.cc,v 1.145 1997/06/17 03:03:24 wessels Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -923,8 +923,7 @@ peerDestroy(peer * p)
        safe_free(l->domain);
        safe_free(l);
     }
-    if (p->ip_lookup_pending)
-       ipcacheUnregister(p->host, p);
+    callbackUnlinkList(p->cbm_list);
     safe_free(p->host);
     safe_free(p);
 }
@@ -935,7 +934,6 @@ peerDNSConfigure(const ipcache_addrs * ia, void *data)
     peer *p = data;
     struct sockaddr_in *ap;
     int j;
-    p->ip_lookup_pending = 0;
     if (p->n_addresses == 0) {
        debug(15, 1) ("Configuring %s %s/%d/%d\n", neighborTypeStr(p),
            p->host, p->http_port, p->icp_port);
@@ -972,10 +970,9 @@ peerRefreshDNS(void *junk)
     peer *next = Peers.peers_head;
     while ((p = next)) {
        next = p->next;
-       p->ip_lookup_pending = 1;
        /* some random, bogus FD for ipcache */
        p->test_fd = Squid_MaxFD + current_time.tv_usec;
-       ipcache_nbgethostbyname(p->host, peerDNSConfigure, p);
+       ipcache_nbgethostbyname(p->host, peerDNSConfigure, p, &p->cbm_list);
     }
     /* Reconfigure the peers every hour */
     eventAdd("peerRefreshDNS", peerRefreshDNS, NULL, 3600);
@@ -990,16 +987,14 @@ peerCheckConnect(void *data)
        0, COMM_NONBLOCKING, p->host);
     if (fd < 0)
        return;
-    p->ip_lookup_pending = 1;
     p->test_fd = fd;
-    ipcache_nbgethostbyname(p->host, peerCheckConnect2, p);
+    ipcache_nbgethostbyname(p->host, peerCheckConnect2, p, &p->cbm_list);
 }
 
 static void
 peerCheckConnect2(const ipcache_addrs * ia, void *data)
 {
     peer *p = data;
-    p->ip_lookup_pending = 0;
     commConnectStart(p->test_fd,
        p->host,
        p->http_port,
index 9fe4d93e8556474670a7c302789365cc6627403b..0d212e9e241e4fc12235e6c4e696902b1e4b2250 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: net_db.cc,v 1.39 1997/06/04 07:00:32 wessels Exp $
+ * $Id: net_db.cc,v 1.40 1997/06/17 03:03:25 wessels Exp $
  *
  * DEBUG: section 37    Network Measurement Database
  * AUTHOR: Duane Wessels
@@ -207,7 +207,7 @@ netdbAdd(struct in_addr addr, const char *hostname)
 }
 
 static void
-netdbSendPing(int fdunused, const ipcache_addrs * ia, void *data)
+netdbSendPing(const ipcache_addrs * ia, void *data)
 {
     struct in_addr addr;
     char *hostname = data;
@@ -453,9 +453,9 @@ netdbPingSite(const char *hostname)
        if (n->next_ping_time > squid_curtime)
            return;
     ipcache_nbgethostbyname(hostname,
-       -1,
        netdbSendPing,
-       (void *) xstrdup(hostname));
+       (void *) xstrdup(hostname),
+       NULL);
 #endif
 }
 
index 34655d4fa3226b1d239e9c20f08f765b25d73d5c..aa543f7417c94c43569c3d4910c0eca4f359f1c6 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: send-announce.cc,v 1.37 1997/06/16 22:01:51 wessels Exp $
+ * $Id: send-announce.cc,v 1.38 1997/06/17 03:03:26 wessels Exp $
  *
  * DEBUG: section 27    Cache Announcer
  * AUTHOR: Duane Wessels
@@ -38,7 +38,7 @@ start_announce(void *unused)
 {
     if (!Config.Announce.on)
        return;
-    ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL);
+    ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL, NULL);
     eventAdd("send_announce", start_announce, NULL, Config.Announce.rate);
 }
 
index b1a9c9227d45412210beed06df1ef5a13ce66a5c..d6fec7fe0145c5257e15c279360bca4268a6b13c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: squid.h,v 1.120 1997/06/16 22:01:52 wessels Exp $
+ * $Id: squid.h,v 1.121 1997/06/17 03:03:26 wessels Exp $
  *
  * AUTHOR: Duane Wessels
  *
@@ -273,6 +273,7 @@ typedef void STCB _PARAMS((void *, char *, size_t));        /* store callback */
 
 #include "cache_cf.h"
 #include "fd.h"
+#include "callback.h"
 #include "comm.h"
 #include "disk.h"
 #include "debug.h"