#
# Makefile for the Squid Object Cache server
#
-# $Id: Makefile.in,v 1.76 1997/06/17 03:03:19 wessels Exp $
+# $Id: Makefile.in,v 1.77 1997/06/18 00:19:50 wessels Exp $
#
# Uncomment and customize the following to suit your needs:
#
aiops.o \
async_io.o \
cache_cf.o \
- callback.o \
+ cbdata.o \
client_db.o \
client_side.o \
comm.o \
/*
- * $Id: acl.cc,v 1.98 1997/06/17 03:03:20 wessels Exp $
+ * $Id: acl.cc,v 1.99 1997/06/18 00:19:51 wessels Exp $
*
* DEBUG: section 28 Access Control
* AUTHOR: Duane Wessels
checklist->state[ACL_DST_IP] = ACL_LOOKUP_PENDING;
ipcache_nbgethostbyname(checklist->request->host,
aclLookupDstIPDone,
- checklist,
- &checklist->cbm_list);
+ checklist);
return;
} else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NEEDED) {
checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_PENDING;
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);
+ checklist->request = NULL;
+ cbdataFree(checklist);
}
static void
aclCheckCallback(aclCheck_t * checklist, int answer)
{
debug(28, 3) ("aclCheckCallback: answer=%d\n", answer);
- checklist->callback(answer, checklist->callback_data);
+ if (cbdataValid(checklist->callback_data))
+ checklist->callback(answer, checklist->callback_data);
+ cbdataUnlock(checklist->callback_data);
checklist->callback = NULL;
checklist->callback_data = NULL;
aclChecklistFree(checklist);
char *ident)
{
aclCheck_t *checklist = xcalloc(1, sizeof(aclCheck_t));;
+ cbdataAdd(checklist);
checklist->access_list = A;
checklist->request = requestLink(request);
checklist->src_addr = src_addr;
{
checklist->callback = callback;
checklist->callback_data = callback_data;
+ cbdataLock(callback_data);
aclCheck(checklist);
}
/*
- * $Id: comm.cc,v 1.163 1997/06/17 03:03:21 wessels Exp $
+ * $Id: comm.cc,v 1.164 1997/06/18 00:19:52 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
struct in_addr in_addr;
int locks;
int fd;
- callback_meta *cbm_list;
} ConnectStateData;
/* GLOBAL */
commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data)
{
ConnectStateData *cs = xcalloc(1, sizeof(ConnectStateData));
+ cbdataAdd(cs);
cs->fd = fd;
cs->host = xstrdup(host);
cs->port = port;
cs->callback = callback;
cs->data = data;
+ cbdataLock(data);
comm_add_close_handler(fd, commConnectFree, cs);
cs->locks++;
- ipcache_nbgethostbyname(host, commConnectDnsHandle, cs, &cs->cbm_list);
+ ipcache_nbgethostbyname(host, commConnectDnsHandle, cs);
}
static void
int fd = cs->fd;
comm_remove_close_handler(fd, commConnectFree, cs);
commConnectFree(fd, cs);
- callback(fd, status, data);
+ if (cbdataValid(data))
+ callback(fd, status, data);
+ cbdataUnlock(data);
}
static void
commConnectFree(int fdunused, void *data)
{
ConnectStateData *cs = data;
- callbackUnlinkList(cs->cbm_list);
- xfree(cs->host);
- xfree(cs);
+ if (cs->locks)
+ ipcacheUnregister(cs->host, cs);
+ safe_free(cs->host);
+ cbdataFree(cs);
}
static int
cs->S.sin_addr.s_addr = 0;
ipcacheCycleAddr(cs->host);
cs->locks++;
- ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs, &cs->cbm_list);
+ ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs);
} else {
ipcacheRemoveBadAddr(cs->host, cs->S.sin_addr);
commConnectCallback(cs, COMM_ERR_CONNECT);
/*
- * $Id: http.cc,v 1.170 1997/06/04 06:15:57 wessels Exp $
+ * $Id: http.cc,v 1.171 1997/06/18 00:19:53 wessels Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
url = entry ? entry->url : urlCanonical(orig_request, NULL);
sprintf(ybuf, "Cache-control: Max-age=%d", (int) getMaxAge(url));
httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz);
+if (request->urlpath) {
+ assert(strstr(url, request->urlpath));
+}
}
httpAppendRequestHeader(hdr_out, null_string, &len, out_sz);
put_free_4k_page(xbuf);
/*
- * $Id: ipcache.cc,v 1.123 1997/06/17 04:54:11 wessels Exp $
+ * $Id: ipcache.cc,v 1.124 1997/06/18 00:19:56 wessels Exp $
*
* DEBUG: section 14 IP Cache
* AUTHOR: Harvest Derived
struct _ip_pending {
IPH *handler;
- callback_meta *cbm;
+ void *handlerData;
struct _ip_pending *next;
};
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 *, callback_meta **));
+static void ipcacheAddPending _PARAMS((ipcache_entry *, IPH *, void *));
static void ipcacheEnqueue _PARAMS((ipcache_entry *));
static void *ipcacheDequeue _PARAMS((void));
static void ipcache_dnsDispatch _PARAMS((dnsserver_t *, 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 hash_table * ip_table = NULL;
{
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;
- handlerData = callbackCheck(p->cbm);
- if (p->handler && handlerData) {
- nhandler++;
- dns_error_message = i->error_message;
- p->handler(i->status == IP_CACHED ? &i->addrs : NULL, handlerData);
- }
- callbackUnlink(p->cbm);
- safe_free(p);
+ p = i->pending_head;
+ i->pending_head = p->next;
+ if (p->handler) {
+ nhandler++;
+ dns_error_message = i->error_message;
+ if (cbdataValid(p->handlerData)) {
+ p->handler(i->status == IP_CACHED ? &i->addrs : NULL,
+ p->handlerData);
+ }
+ cbdataUnlock(p->handlerData);
+ }
+ safe_free(p);
}
- i->pending_head = NULL; /* nuke list */
+ i->pending_head = NULL; /* nuke list */
debug(14, 10) ("ipcache_call_pending: Called %d handlers.\n", nhandler);
ipcacheUnlockEntry(i);
}
+
static ipcache_entry *
ipcache_parsebuffer(const char *inbuf, dnsserver_t * dnsData)
{
}
static void
-ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData, callback_meta **head)
+ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData)
{
struct _ip_pending *pending = xcalloc(1, sizeof(struct _ip_pending));
struct _ip_pending **I = NULL;
i->lastref = squid_curtime;
pending->handler = handler;
- pending->cbm = callbackRegister(handlerData, ipcacheUnregister, pending, head);
+ pending->handlerData = handlerData;
+ cbdataLock(handlerData);
for (I = &(i->pending_head); *I; I = &((*I)->next));
*I = pending;
if (i->status == IP_PENDING)
}
void
-ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData, callback_meta **cbmhead)
+ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData)
{
ipcache_entry *i = NULL;
dnsserver_t *dnsData = NULL;
debug(14, 5) ("ipcache_nbgethostbyname: MISS for '%s'\n", name);
IpcacheStats.misses++;
i = ipcacheAddNew(name, NULL, IP_PENDING);
- ipcacheAddPending(i, handler, handlerData, cbmhead);
+ ipcacheAddPending(i, handler, handlerData);
} else if (i->status == IP_CACHED || i->status == IP_NEGATIVE_CACHED) {
/* HIT */
debug(14, 4) ("ipcache_nbgethostbyname: HIT for '%s'\n", name);
IpcacheStats.negative_hits++;
else
IpcacheStats.hits++;
- ipcacheAddPending(i, handler, handlerData, cbmhead);
+ ipcacheAddPending(i, handler, handlerData);
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, cbmhead);
+ ipcacheAddPending(i, handler, handlerData);
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);
(float) Config.ipcache.low) / (float) 100);
}
-static void
-ipcacheUnregister(void *data)
+int
+ipcacheUnregister(const char *name, void *data)
{
- struct _ip_pending *p = data;
- p->handler = NULL;
- debug(14, 3) ("ipcacheUnregister: unregistered something\n");
+ 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;
}
const ipcache_addrs *
}
}
if (flags & IP_LOOKUP_IF_MISS)
- ipcache_nbgethostbyname(name, dummy_handler, NULL, NULL);
+ ipcache_nbgethostbyname(name, dummy_handler, NULL);
return NULL;
}
/*
- * $Id: main.cc,v 1.154 1997/06/17 03:03:23 wessels Exp $
+ * $Id: main.cc,v 1.155 1997/06/18 00:19:57 wessels Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
icpHandleUdp,
NULL, 0);
for (s = Config.mcast_group_list; s; s = s->next)
- ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL, NULL);
+ ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n",
(int) port, theInIcpConnection);
squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART);
+ if (!configured_once)
+ cbdataInit();
if (ConfigFile == NULL)
ConfigFile = xstrdup(DefaultConfigFile);
parseConfigFile(ConfigFile);
/*
- * $Id: neighbors.cc,v 1.145 1997/06/17 03:03:24 wessels Exp $
+ * $Id: neighbors.cc,v 1.146 1997/06/18 00:19:58 wessels Exp $
*
* DEBUG: section 15 Neighbor Routines
* AUTHOR: Harvest Derived
}
}
p = xcalloc(1, sizeof(peer));
+ cbdataAdd(p);
p->http_port = http_port;
p->icp_port = icp_port;
p->mcast.ttl = mcast_ttl;
safe_free(l->domain);
safe_free(l);
}
- callbackUnlinkList(p->cbm_list);
+ if (p->ip_lookup_pending)
+ ipcacheUnregister(p->host, p);
safe_free(p->host);
- safe_free(p);
+ cbdataFree(p);
}
static void
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);
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, &p->cbm_list);
+ ipcache_nbgethostbyname(p->host, peerDNSConfigure, p);
}
/* Reconfigure the peers every hour */
eventAdd("peerRefreshDNS", peerRefreshDNS, NULL, 3600);
0, COMM_NONBLOCKING, p->host);
if (fd < 0)
return;
+ p->ip_lookup_pending = 1;
p->test_fd = fd;
- ipcache_nbgethostbyname(p->host, peerCheckConnect2, p, &p->cbm_list);
+ ipcache_nbgethostbyname(p->host, peerCheckConnect2, p);
}
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,
/*
- * $Id: peer_select.cc,v 1.13 1997/06/04 06:16:05 wessels Exp $
+ * $Id: peer_select.cc,v 1.14 1997/06/18 00:20:01 wessels Exp $
*
* DEBUG: section 44 Peer Selection Algorithm
* AUTHOR: Duane Wessels
aclChecklistFree(psstate->acl_checklist);
}
requestUnlink(psstate->request);
- xfree(psstate);
+ psstate->request = NULL;
+ cbdataFree(psstate);
}
int
void *callback_data)
{
ps_state *psstate = xcalloc(1, sizeof(ps_state));
+ cbdataAdd(psstate);
psstate->request = requestLink(request);
psstate->entry = entry;
psstate->callback = callback;
psstate->fail_callback = fail_callback;
psstate->callback_data = callback_data;
+ cbdataLock(callback_data);
psstate->icp.start = current_time;
peerSelectFoo(psstate);
}
peerSelectCallback(ps_state * psstate, peer * p)
{
StoreEntry *entry = psstate->entry;
+ void *data = psstate->callback_data;
if (entry) {
if (entry->ping_status == PING_WAITING)
eventDelete(peerPingTimeout, psstate);
entry->ping_status = PING_DONE;
}
- psstate->callback(p, psstate->callback_data);
+ if (cbdataValid(data))
+ psstate->callback(p, data);
+ cbdataUnlock(data);
peerSelectStateFree(psstate);
}
peerSelectCallbackFail(ps_state * psstate)
{
request_t *request = psstate->request;
+ void *data = psstate->callback_data;
char *url = psstate->entry ? psstate->entry->url : urlCanonical(request, NULL);
debug(44, 1) ("Failed to select source for '%s'\n", url);
debug(44, 1) (" always_direct = %d\n", psstate->always_direct);
debug(44, 1) (" never_direct = %d\n", psstate->never_direct);
debug(44, 1) (" timeout = %d\n", psstate->icp.timeout);
- psstate->fail_callback(NULL, psstate->callback_data);
+ if (cbdataValid(data))
+ psstate->fail_callback(NULL, data);
+ cbdataUnlock(data);
peerSelectStateFree(psstate);
}
/*
- * $Id: send-announce.cc,v 1.38 1997/06/17 03:03:26 wessels Exp $
+ * $Id: send-announce.cc,v 1.39 1997/06/18 00:20:02 wessels Exp $
*
* DEBUG: section 27 Cache Announcer
* AUTHOR: Duane Wessels
{
if (!Config.Announce.on)
return;
- ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL, NULL);
+ ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL);
eventAdd("send_announce", start_announce, NULL, Config.Announce.rate);
}
/*
- * $Id: squid.h,v 1.121 1997/06/17 03:03:26 wessels Exp $
+ * $Id: squid.h,v 1.122 1997/06/18 00:20:03 wessels Exp $
*
* AUTHOR: Duane Wessels
*
#include "cache_cf.h"
#include "fd.h"
-#include "callback.h"
#include "comm.h"
#include "disk.h"
#include "debug.h"
#include "refresh.h"
#include "unlinkd.h"
#include "multicast.h"
+#include "cbdata.h"
#if !HAVE_TEMPNAM
#include "tempnam.h"
/*
- * $Id: stat.cc,v 1.142 1997/06/04 07:00:33 wessels Exp $
+ * $Id: stat.cc,v 1.143 1997/06/18 00:20:04 wessels Exp $
*
* DEBUG: section 18 Cache Manager Statistics
* AUTHOR: Harvest Derived
netdbDump(sentry);
} else if (strcmp(req, "storedir") == 0) {
storeDirStats(sentry);
+ } else if (strcmp(req, "cbdata") == 0) {
+ cbdataDump(sentry);
}
}