From 82691c78eb5291a015b187f572f9a9a0435a4a0b Mon Sep 17 00:00:00 2001 From: wessels <> Date: Tue, 17 Jun 1997 09:03:19 +0000 Subject: [PATCH] generic callback support --- src/Makefile.in | 3 ++- src/acl.cc | 8 +++--- src/comm.cc | 10 +++---- src/ipcache.cc | 62 ++++++++++++++++---------------------------- src/main.cc | 4 +-- src/neighbors.cc | 13 +++------- src/net_db.cc | 8 +++--- src/send-announce.cc | 4 +-- src/squid.h | 3 ++- 9 files changed, 47 insertions(+), 68 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index 0d130f044f..24e121f566 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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 \ diff --git a/src/acl.cc b/src/acl.cc index 836a938000..39506a3f43 100644 --- a/src/acl.cc +++ b/src/acl.cc @@ -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); } diff --git a/src/comm.cc b/src/comm.cc index a8a55c7aae..11930bc435 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -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); diff --git a/src/ipcache.cc b/src/ipcache.cc index 1f173e1ebf..aa1c0c9dbc 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -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 @@ -108,7 +108,7 @@ 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; } diff --git a/src/main.cc b/src/main.cc index b3f6ae8806..430e5fa05b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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); diff --git a/src/neighbors.cc b/src/neighbors.cc index 0f53c532a6..c0b584b06c 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -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, diff --git a/src/net_db.cc b/src/net_db.cc index 9fe4d93e85..0d212e9e24 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -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 } diff --git a/src/send-announce.cc b/src/send-announce.cc index 34655d4fa3..aa543f7417 100644 --- a/src/send-announce.cc +++ b/src/send-announce.cc @@ -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); } diff --git a/src/squid.h b/src/squid.h index b1a9c9227d..d6fec7fe01 100644 --- a/src/squid.h +++ b/src/squid.h @@ -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" -- 2.47.3