/*
- * $Id: client_side.cc,v 1.101 1997/05/05 03:43:38 wessels Exp $
+ * $Id: client_side.cc,v 1.102 1997/05/08 07:22:01 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
#include "squid.h"
static RH clientRedirectDone;
-static PIF icpHandleIMSReply;
+static STCB icpHandleIMSReply;
static int clientGetsOldEntry _PARAMS((StoreEntry * new, StoreEntry * old, request_t * request));
-static int checkAccelOnly _PARAMS((icpStateData * icpState));
-
-static void
-clientLookupIdentDone(void *data)
-{
- icpStateData *icpState = data;
- clientAccessCheck(icpState, icpState->aclHandler);
-}
+static int checkAccelOnly _PARAMS((clientHttpRequest *));
#if USE_PROXY_AUTH
/* ProxyAuth code by Jon Thackray <jrmt@uk.gdscorp.com> */
/* return 1 if allowed, 0 if denied */
static int
-clientProxyAuthCheck(icpStateData * icpState)
+clientProxyAuthCheck(clientHttpRequest * http)
{
const char *proxy_user;
* an object of type cacheobj:// */
if (Config.proxyAuth.File == NULL)
return 1;
- if (urlParseProtocol(icpState->url) == PROTO_CACHEOBJ)
+ if (urlParseProtocol(http->url) == PROTO_CACHEOBJ)
return 1;
if (Config.proxyAuth.IgnoreDomains) {
- if (aclMatchRegex(Config.proxyAuth.IgnoreDomains, icpState->request->host)) {
- debug(33, 2, "clientProxyAuthCheck: host \"%s\" matched proxyAuthIgnoreDomains\n", icpState->request->host);
+ if (aclMatchRegex(Config.proxyAuth.IgnoreDomains, http->request->host)) {
+ debug(33, 2, "clientProxyAuthCheck: host \"%s\" matched proxyAuthIgnoreDomains\n", http->request->host);
return 1;
}
}
- proxy_user = proxyAuthenticate(icpState->request_hdr);
- xstrncpy(icpState->ident.ident, proxy_user, ICP_IDENT_SZ);
- debug(33, 6, "clientProxyAuthCheck: user = %s\n", icpState->ident.ident);
+ proxy_user = proxyAuthenticate(http->request_hdr);
+ xstrncpy(http->ident.ident, proxy_user, ICP_IDENT_SZ);
+ debug(33, 6, "clientProxyAuthCheck: user = %s\n", http->ident.ident);
- if (strcmp(icpState->ident.ident, dash_str) == 0)
+ if (strcmp(http->ident.ident, dash_str) == 0)
return 0;
return 1;
}
#endif /* USE_PROXY_AUTH */
static int
-checkAccelOnly(icpStateData * icpState)
+checkAccelOnly(clientHttpRequest * http)
{
/* return TRUE if someone makes a proxy request to us and
* we are in httpd-accel only mode */
return 0;
if (Config.Accel.withProxy)
return 0;
- if (icpState->request->protocol == PROTO_CACHEOBJ)
+ if (http->request->protocol == PROTO_CACHEOBJ)
return 0;
- if (icpState->accel)
+ if (http->accel)
return 0;
return 1;
}
void
-clientAccessCheck(icpStateData * icpState, PF handler)
+clientAccessCheck(void *data)
{
+ clientHttpRequest *http = data;
+ ConnStateData *conn = http->conn;
char *browser;
- if (Config.identLookup && icpState->ident.state == IDENT_NONE) {
- icpState->aclHandler = handler;
- identStart(-1, icpState, clientLookupIdentDone);
+ if (Config.identLookup && conn->ident.state == IDENT_NONE) {
+ identStart(-1, conn, clientAccessCheck);
return;
}
#if USE_PROXY_AUTH
- if (clientProxyAuthCheck(icpState) == 0) {
+ if (clientProxyAuthCheck(http) == 0) {
char *wbuf = NULL;
- int fd = icpState->fd;
- debug(33, 4, "Proxy Denied: %s\n", icpState->url);
- icpState->log_type = ERR_PROXY_DENIED;
- icpState->http_code = 407;
- wbuf = xstrdup(proxy_denied_msg(icpState->http_code,
- icpState->method,
- icpState->url,
+ int fd = conn->fd;
+ debug(33, 4, "Proxy Denied: %s\n", http->url);
+ http->log_type = ERR_PROXY_DENIED;
+ http->http_code = 407;
+ wbuf = xstrdup(proxy_denied_msg(http->http_code,
+ http->request->method,
+ http->url,
fd_table[fd].ipaddr));
- icpSendERROR(fd, icpState->log_type, wbuf, icpState, icpState->http_code);
- safe_free(icpState->aclChecklist);
+ icpSendERROR(fd, http->log_type, wbuf, conn, http->http_code);
+ safe_free(http->aclChecklist);
return;
}
#endif /* USE_PROXY_AUTH */
- if (checkAccelOnly(icpState)) {
- clientAccessCheckDone(0, icpState);
+ if (checkAccelOnly(http)) {
+ clientAccessCheckDone(0, http);
return;
}
- browser = mime_get_header(icpState->request_hdr, "User-Agent");
- icpState->acl_checklist = aclChecklistCreate(Config.accessList.HTTP,
- icpState->request,
- icpState->peer.sin_addr,
+ browser = mime_get_header(http->request_hdr, "User-Agent");
+ http->acl_checklist = aclChecklistCreate(Config.accessList.HTTP,
+ http->request,
+ conn->peer.sin_addr,
browser,
- icpState->ident.ident);
- aclNBCheck(icpState->acl_checklist, handler, icpState);
+ conn->ident.ident);
+ aclNBCheck(http->acl_checklist, clientAccessCheckDone, http);
}
void
clientAccessCheckDone(int answer, void *data)
{
- icpStateData *icpState = data;
- int fd = icpState->fd;
+ clientHttpRequest *http = data;
+ ConnStateData *conn = http->conn;
+ int fd = conn->fd;
char *buf = NULL;
char *redirectUrl = NULL;
- debug(33, 5, "clientAccessCheckDone: '%s' answer=%d\n", icpState->url, answer);
- icpState->acl_checklist = NULL;
+ debug(33, 5, "clientAccessCheckDone: '%s' answer=%d\n", http->url, answer);
+ http->acl_checklist = NULL;
if (answer) {
- urlCanonical(icpState->request, icpState->url);
- if (icpState->redirect_state != REDIRECT_NONE)
+ urlCanonical(http->request, http->url);
+ if (http->redirect_state != REDIRECT_NONE)
fatal_dump("clientAccessCheckDone: wrong redirect_state");
- icpState->redirect_state = REDIRECT_PENDING;
- redirectStart(fd, icpState, clientRedirectDone, icpState);
+ http->redirect_state = REDIRECT_PENDING;
+ redirectStart(http, clientRedirectDone, http);
} else {
- debug(33, 5, "Access Denied: %s\n", icpState->url);
+ debug(33, 5, "Access Denied: %s\n", http->url);
redirectUrl = aclGetDenyInfoUrl(&Config.denyInfoList, AclMatchedName);
if (redirectUrl) {
- icpState->http_code = 302,
- buf = access_denied_redirect(icpState->http_code,
- icpState->method,
- icpState->url,
+ http->http_code = 302,
+ buf = access_denied_redirect(http->http_code,
+ http->request->method,
+ http->url,
fd_table[fd].ipaddr,
redirectUrl);
} else {
- icpState->http_code = 400;
- buf = access_denied_msg(icpState->http_code,
- icpState->method,
- icpState->url,
+ http->http_code = 400;
+ buf = access_denied_msg(http->http_code,
+ http->request->method,
+ http->url,
fd_table[fd].ipaddr);
}
- icpSendERROR(fd, LOG_TCP_DENIED, buf, icpState, icpState->http_code);
+ icpSendERROR(fd, LOG_TCP_DENIED, buf, http, http->http_code);
}
}
static void
clientRedirectDone(void *data, char *result)
{
- icpStateData *icpState = data;
- int fd = icpState->fd;
+ clientHttpRequest *http = data;
+ int fd = http->conn->fd;
request_t *new_request = NULL;
- request_t *old_request = icpState->request;
- debug(33, 5, "clientRedirectDone: '%s' result=%s\n", icpState->url,
+ request_t *old_request = http->request;
+ debug(33, 5, "clientRedirectDone: '%s' result=%s\n", http->url,
result ? result : "NULL");
- if (icpState->redirect_state != REDIRECT_PENDING)
+ if (http->redirect_state != REDIRECT_PENDING)
fatal_dump("clientRedirectDone: wrong redirect_state");
- icpState->redirect_state = REDIRECT_DONE;
+ http->redirect_state = REDIRECT_DONE;
if (result)
new_request = urlParse(old_request->method, result);
if (new_request) {
- safe_free(icpState->url);
- icpState->url = xstrdup(result);
+ safe_free(http->url);
+ http->url = xstrdup(result);
new_request->http_ver = old_request->http_ver;
requestUnlink(old_request);
- icpState->request = requestLink(new_request);
- urlCanonical(icpState->request, icpState->url);
+ http->request = requestLink(new_request);
+ urlCanonical(http->request, http->url);
}
- icpParseRequestHeaders(icpState);
- fd_note(fd, icpState->url);
- icpProcessRequest(fd, icpState);
+ icpParseRequestHeaders(http);
+ fd_note(fd, http->url);
+ icpProcessRequest(fd, http);
}
#if USE_PROXY_AUTH
void
icpProcessExpired(int fd, void *data)
{
- icpStateData *icpState = data;
- char *url = icpState->url;
- char *request_hdr = icpState->request_hdr;
+ clientHttpRequest *http = data;
+ char *url = http->url;
+ char *request_hdr = http->request_hdr;
StoreEntry *entry = NULL;
- debug(33, 3, "icpProcessExpired: FD %d '%s'\n", fd, icpState->url);
+ debug(33, 3, "icpProcessExpired: FD %d '%s'\n", fd, http->url);
- BIT_SET(icpState->request->flags, REQ_REFRESH);
- icpState->old_entry = icpState->entry;
+ BIT_SET(http->request->flags, REQ_REFRESH);
+ http->old_entry = http->entry;
entry = storeCreateEntry(url,
request_hdr,
- icpState->req_hdr_sz,
- icpState->request->flags,
- icpState->method);
+ http->req_hdr_sz,
+ http->request->flags,
+ http->request->method);
/* NOTE, don't call storeLockObject(), storeCreateEntry() does it */
- storeClientListAdd(entry, fd, 0);
- storeClientListAdd(icpState->old_entry, fd, 0);
+ storeClientListAdd(entry, http, 0);
+ storeClientListAdd(http->old_entry, http, 0);
- entry->lastmod = icpState->old_entry->lastmod;
+ entry->lastmod = http->old_entry->lastmod;
debug(33, 5, "icpProcessExpired: setting lmt = %d\n",
entry->lastmod);
entry->refcount++; /* EXPIRED CASE */
- icpState->entry = entry;
- icpState->out_offset = 0;
+ http->entry = entry;
+ http->out.offset = 0;
/* Register with storage manager to receive updates when data comes in. */
- storeRegister(entry, fd, icpHandleIMSReply, icpState);
- protoDispatch(fd, icpState->entry, icpState->request);
+ storeRegister(entry, fd, icpHandleIMSReply, http);
+ protoDispatch(fd, http->entry, http->request);
}
static int
static void
-icpHandleIMSReply(int fd, StoreEntry * entry, void *data)
+icpHandleIMSReply(void *data)
{
- icpStateData *icpState = data;
+ clientHttpRequest *http = data;
+ int fd = http->conn->fd;
+ StoreEntry *entry = http->entry;
MemObject *mem = entry->mem_obj;
char *hbuf;
int len;
log_tags[entry->mem_obj->abort_code], entry->url);
/* We have an existing entry, but failed to validate it,
* so send the old one anyway */
- icpState->log_type = LOG_TCP_REFRESH_FAIL_HIT;
- storeUnregister(entry, fd);
+ http->log_type = LOG_TCP_REFRESH_FAIL_HIT;
+ storeUnregister(entry, http);
storeUnlockObject(entry);
- icpState->entry = icpState->old_entry;
- icpState->entry->refcount++;
+ http->entry = http->old_entry;
+ http->entry->refcount++;
} else if (mem->reply->code == 0) {
debug(33, 3, "icpHandleIMSReply: Incomplete headers for '%s'\n",
entry->url);
storeRegister(entry,
fd,
icpHandleIMSReply,
- icpState);
+ http);
return;
- } else if (clientGetsOldEntry(entry, icpState->old_entry, icpState->request)) {
+ } else if (clientGetsOldEntry(entry, http->old_entry, http->request)) {
/* We initiated the IMS request, the client is not expecting
* 304, so put the good one back. First, make sure the old entry
* headers have been loaded from disk. */
- oldentry = icpState->old_entry;
+ oldentry = http->old_entry;
if (oldentry->mem_obj->e_current_len == 0) {
storeRegister(entry,
fd,
icpHandleIMSReply,
- icpState);
+ http);
return;
}
- icpState->log_type = LOG_TCP_REFRESH_HIT;
+ http->log_type = LOG_TCP_REFRESH_HIT;
hbuf = get_free_8k_page();
- if (storeClientCopy(oldentry, 0, 8191, hbuf, &len, fd) < 0) {
+ if (storeClientCopy(oldentry, 0, 8191, hbuf, &len, http) < 0) {
debug(33, 1, "icpHandleIMSReply: Couldn't copy old entry\n");
} else {
if (oldentry->mem_obj->request == NULL) {
unlink_request = 1;
}
}
- storeUnregister(entry, fd);
+ storeUnregister(entry, http);
storeUnlockObject(entry);
- entry = icpState->entry = oldentry;
+ entry = http->entry = oldentry;
if (mime_headers_end(hbuf)) {
httpParseReplyHeaders(hbuf, entry->mem_obj->reply);
storeTimestampsSet(entry);
}
} else {
/* the client can handle this reply, whatever it is */
- icpState->log_type = LOG_TCP_REFRESH_MISS;
+ http->log_type = LOG_TCP_REFRESH_MISS;
if (mem->reply->code == 304) {
- icpState->old_entry->timestamp = squid_curtime;
- icpState->old_entry->refcount++;
- icpState->log_type = LOG_TCP_REFRESH_HIT;
+ http->old_entry->timestamp = squid_curtime;
+ http->old_entry->refcount++;
+ http->log_type = LOG_TCP_REFRESH_HIT;
}
- storeUnregister(icpState->old_entry, fd);
- storeUnlockObject(icpState->old_entry);
+ storeUnregister(http->old_entry, http);
+ storeUnlockObject(http->old_entry);
}
- icpState->old_entry = NULL; /* done with old_entry */
- icpSendMoreData(fd, icpState); /* give data to the client */
+ http->old_entry = NULL; /* done with old_entry */
+ icpSendMoreData(fd, http); /* give data to the client */
}
int
}
char *
-clientConstructTraceEcho(icpStateData * icpState)
+clientConstructTraceEcho(clientHttpRequest * http)
{
LOCAL_ARRAY(char, line, 256);
LOCAL_ARRAY(char, buf, 8192);
strcat(buf, line);
strcat(buf, "\r\n");
len = strlen(buf);
- httpBuildRequestHeader(icpState->request,
- icpState->request,
+ httpBuildRequestHeader(http->request,
+ http->request,
NULL, /* entry */
- icpState->request_hdr,
+ http->request_hdr,
NULL, /* in_len */
buf + len,
8192 - len,
- icpState->fd);
- icpState->log_type = LOG_TCP_MISS;
- icpState->http_code = 200;
+ http->conn->fd);
+ http->log_type = LOG_TCP_MISS;
+ http->http_code = 200;
return buf;
}
void
-clientPurgeRequest(icpStateData * icpState)
+clientPurgeRequest(clientHttpRequest * http)
{
char *buf;
- int fd = icpState->fd;
+ int fd = http->conn->fd;
LOCAL_ARRAY(char, msg, 8192);
LOCAL_ARRAY(char, line, 256);
StoreEntry *entry;
debug(0, 0, "Config.Options.enable_purge = %d\n", Config.Options.enable_purge);
if (!Config.Options.enable_purge) {
- buf = access_denied_msg(icpState->http_code = 401,
- icpState->method,
- icpState->url,
+ buf = access_denied_msg(http->http_code = 401,
+ http->request->method,
+ http->url,
fd_table[fd].ipaddr);
- icpSendERROR(fd, LOG_TCP_DENIED, buf, icpState, icpState->http_code);
+ icpSendERROR(fd, LOG_TCP_DENIED, buf, http, http->http_code);
return;
}
- icpState->log_type = LOG_TCP_MISS;
- if ((entry = storeGet(icpState->url)) == NULL) {
+ http->log_type = LOG_TCP_MISS;
+ if ((entry = storeGet(http->url)) == NULL) {
sprintf(msg, "HTTP/1.0 404 Not Found\r\n");
- icpState->http_code = 404;
+ http->http_code = 404;
} else {
storeRelease(entry);
sprintf(msg, "HTTP/1.0 200 OK\r\n");
- icpState->http_code = 200;
+ http->http_code = 200;
}
sprintf(line, "Date: %s\r\n", mkrfc1123(squid_curtime));
strcat(msg, line);
msg,
strlen(msg),
icpSendERRORComplete,
- icpState,
+ http,
NULL);
}
/*
- * $Id: ident.cc,v 1.28 1997/04/30 18:30:55 wessels Exp $
+ * $Id: ident.cc,v 1.29 1997/05/08 07:22:05 wessels Exp $
*
* DEBUG: section 30 Ident (RFC 931)
* AUTHOR: Duane Wessels
#define IDENT_PORT 113
-static void identRequestComplete _PARAMS((int, char *, int, int, void *));
+static CWCB identRequestComplete;
static PF identReadReply;
static PF identClose;
static CNCB identConnectDone;
-static void identCallback _PARAMS((icpStateData * icpState));
+static void identCallback _PARAMS((ConnStateData * connState));
static void
identClose(int fd, void *data)
{
- icpStateData *icpState = data;
- icpState->ident.fd = -1;
+ ConnStateData *connState = data;
+ connState->ident.fd = -1;
}
/* start a TCP connection to the peer host on port 113 */
void
-identStart(int fd, icpStateData * icpState, void (*callback) _PARAMS((void *)))
+identStart(int fd, ConnStateData * connState, IDCB * callback)
{
- icpState->ident.callback = callback;
- icpState->ident.state = IDENT_PENDING;
+ connState->ident.callback = callback;
+ connState->ident.state = IDENT_PENDING;
if (fd < 0) {
fd = comm_open(SOCK_STREAM,
0,
- icpState->me.sin_addr,
+ connState->me.sin_addr,
0,
COMM_NONBLOCKING,
"ident");
if (fd == COMM_ERROR) {
- identCallback(icpState);
+ identCallback(connState);
return;
}
}
- icpState->ident.fd = fd;
+ connState->ident.fd = fd;
comm_add_close_handler(fd,
identClose,
- icpState);
+ connState);
commConnectStart(fd,
- inet_ntoa(icpState->peer.sin_addr),
+ inet_ntoa(connState->peer.sin_addr),
IDENT_PORT,
identConnectDone,
- icpState);
+ connState);
}
static void
identConnectDone(int fd, int status, void *data)
{
- icpStateData *icpState = data;
+ ConnStateData *connState = data;
LOCAL_ARRAY(char, reqbuf, BUFSIZ);
if (status == COMM_ERROR) {
comm_close(fd);
- identCallback(icpState);
+ identCallback(connState);
return;
}
sprintf(reqbuf, "%d, %d\r\n",
- ntohs(icpState->peer.sin_port),
- ntohs(icpState->me.sin_port));
+ ntohs(connState->peer.sin_port),
+ ntohs(connState->me.sin_port));
comm_write(fd,
reqbuf,
strlen(reqbuf),
identRequestComplete,
- icpState,
+ connState,
NULL);
commSetSelect(fd,
COMM_SELECT_READ,
identReadReply,
- icpState, 0);
+ connState, 0);
}
static void
static void
identReadReply(int fd, void *data)
{
- icpStateData *icpState = data;
+ ConnStateData *connState = data;
LOCAL_ARRAY(char, buf, BUFSIZ);
char *t = NULL;
int len = -1;
if (strstr(buf, "USERID")) {
if ((t = strrchr(buf, ':'))) {
while (isspace(*++t));
- xstrncpy(icpState->ident.ident, t, ICP_IDENT_SZ);
+ xstrncpy(connState->ident.ident, t, ICP_IDENT_SZ);
}
}
}
comm_close(fd);
- identCallback(icpState);
+ identCallback(connState);
}
static void
-identCallback(icpStateData * icpState)
+identCallback(ConnStateData * connState)
{
- icpState->ident.state = IDENT_DONE;
- if (icpState->ident.callback)
- icpState->ident.callback(icpState);
+ connState->ident.state = IDENT_DONE;
+ if (connState->ident.callback)
+ connState->ident.callback(connState);
}
/*
- * $Id: store.cc,v 1.229 1997/05/05 03:43:49 wessels Exp $
+ * $Id: store.cc,v 1.230 1997/05/08 07:22:08 wessels Exp $
*
* DEBUG: section 20 Storeage Manager
* AUTHOR: Harvest Derived
static int compareBucketOrder _PARAMS((struct _bucketOrder *, struct _bucketOrder *));
static int storeCheckExpired _PARAMS((const StoreEntry *, int flag));
static int storeCheckPurgeMem _PARAMS((const StoreEntry *));
-static int storeClientListSearch _PARAMS((const MemObject *, int));
+static int storeClientListSearch _PARAMS((const MemObject *, void *));
static int storeCopy _PARAMS((const StoreEntry *, int, int, char *, int *));
static void storeLockObjectComplete _PARAMS((void *, int));
static int storeEntryLocked _PARAMS((const StoreEntry *));
/* allocate client list */
mem->nclients = MIN_CLIENT;
mem->clients = xcalloc(mem->nclients, sizeof(struct _store_client));
- for (i = 0; i < mem->nclients; i++)
- mem->clients[i].fd = -1;
/* storeLog(STORE_LOG_CREATE, e); */
return e;
}
/* Register interest in an object currently being retrieved. */
int
-storeRegister(StoreEntry * e, int fd, PIF * handler, void *data)
+storeRegister(StoreEntry * e, int fd, STCB * handler, void *data)
{
int i;
MemObject *mem = e->mem_obj;
debug(20, 3, "storeRegister: FD %d '%s'\n", fd, e->key);
- if ((i = storeClientListSearch(mem, fd)) < 0)
+ if ((i = storeClientListSearch(mem, data)) < 0)
i = storeClientListAdd(e, fd, 0);
if (mem->clients[i].callback)
fatal_dump("storeRegister: handler already exists");
}
int
-storeUnregister(StoreEntry * e, int fd)
+storeUnregister(StoreEntry * e, void *data)
{
int i;
MemObject *mem = e->mem_obj;
if (mem == NULL)
return 0;
- debug(20, 3, "storeUnregister: called for FD %d '%s'\n", fd, e->key);
- if ((i = storeClientListSearch(mem, fd)) < 0)
+ debug(20, 3, "storeUnregister: called for '%s'\n", e->key);
+ if ((i = storeClientListSearch(mem, data)) < 0)
return 0;
- mem->clients[i].fd = -1;
mem->clients[i].last_offset = 0;
mem->clients[i].callback = NULL;
mem->clients[i].callback_data = NULL;
int lowest = mem->e_current_len;
int i;
for (i = 0; i < mem->nclients; i++) {
- if (mem->clients[i].fd == -1)
+ if (mem->clients[i].callback_data == NULL)
continue;
if (mem->clients[i].last_offset < lowest)
lowest = mem->clients[i].last_offset;
{
int i;
MemObject *mem = e->mem_obj;
- PIF *handler = NULL;
+ STCB *handler = NULL;
void *data = NULL;
struct _store_client *sc;
if (mem->clients == NULL && mem->nclients) {
/* walk the entire list looking for valid handlers */
for (i = 0; i < mem->nclients; i++) {
sc = &mem->clients[i];
- if (sc->fd == -1)
+ if (sc->callback_data == NULL)
continue;
if ((handler = sc->callback) == NULL)
continue;
data = sc->callback_data;
sc->callback = NULL;
- sc->callback_data = NULL;
- handler(sc->fd, e, data);
+ /* Don't NULL the callback_data, its used to identify the client */
+ handler(data);
}
}
MemObject *mem = e->mem_obj;
if (mem->clients) {
for (i = 0; i < mem->nclients; i++) {
- if (mem->clients[i].fd != -1)
+ if (mem->clients[i].callback_data != NULL)
return 1;
}
}
}
static int
-storeClientListSearch(const MemObject * mem, int fd)
+storeClientListSearch(const MemObject * mem, void *data)
{
int i;
if (mem->clients) {
for (i = 0; i < mem->nclients; i++) {
- if (mem->clients[i].fd == -1)
- continue;
- if (mem->clients[i].fd != fd)
+ if (mem->clients[i].callback_data != data)
continue;
return i;
}
/* add client with fd to client list */
int
-storeClientListAdd(StoreEntry * e, int fd, int last_offset)
+storeClientListAdd(StoreEntry * e, void *data, int last_offset)
{
int i;
MemObject *mem = e->mem_obj;
if (mem->clients == NULL) {
mem->nclients = MIN_CLIENT;
mem->clients = xcalloc(mem->nclients, sizeof(struct _store_client));
- for (i = 0; i < mem->nclients; i++)
- mem->clients[i].fd = -1;
}
for (i = 0; i < mem->nclients; i++) {
- if (mem->clients[i].fd == fd)
+ if (mem->clients[i].callback_data == data)
return i; /* its already here */
- if (mem->clients[i].fd == -1)
+ if (mem->clients[i].callback_data == NULL)
break;
}
if (i == mem->nclients) {
- debug(20, 3, "storeClientListAdd: FD %d Growing clients for '%s'\n",
- fd, e->url);
+ debug(20, 3, "storeClientListAdd: Growing clients for '%s'\n", e->url);
oldlist = mem->clients;
oldsize = mem->nclients;
mem->nclients <<= 1;
mem->clients = xcalloc(mem->nclients, sizeof(struct _store_client));
for (i = 0; i < oldsize; i++)
mem->clients[i] = oldlist[i];
- for (; i < mem->nclients; i++)
- mem->clients[i].fd = -1;
safe_free(oldlist);
i = oldsize;
}
- mem->clients[i].fd = fd;
+ mem->clients[i].callback_data = data;
mem->clients[i].last_offset = last_offset;
return i;
}
int maxSize,
char *buf,
int *size,
- int fd)
+ void *data)
{
int ci;
int sz;
*size = 0;
return 0;
}
- if ((ci = storeClientListSearch(mem, fd)) < 0) {
+ if ((ci = storeClientListSearch(mem, data)) < 0) {
debug_trap("storeClientCopy: Unregistered client");
debug(20, 0, "--> '%s'\n", e->url);
*size = 0;
if (mem == NULL)
return 0;
for (i = 0; i < mem->nclients; i++) {
- if (mem->clients[i].fd == -1)
+ if (mem->clients[i].callback_data == NULL)
continue;
npend++;
}
return 1;
}
-int
-storeFirstClientFD(MemObject * mem)
-{
- int i;
- if (mem == NULL)
- return -1;
- if (mem->clients == NULL)
- return -1;
- for (i = 0; i < mem->nclients; i++) {
- if (mem->clients[i].fd > -1)
- return mem->clients[i].fd;
- }
- return -1;
-}
-
void
storeTimestampsSet(StoreEntry * entry)
{