From: wessels <> Date: Fri, 20 Jun 1997 04:51:48 +0000 (+0000) Subject: Mucking about with storeAbort. Removed squid_error_entry() (need X-Git-Tag: SQUID_3_0_PRE1~4925 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=474cac1b462e783942f31577d3c30ac359a1f543;p=thirdparty%2Fsquid.git Mucking about with storeAbort. Removed squid_error_entry() (need to replace it later!) and just call storeAbort directly now. --- diff --git a/src/errorpage.cc b/src/errorpage.cc index 1df45cf648..484de8a79a 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.56 1997/06/04 06:15:51 wessels Exp $ + * $Id: errorpage.cc,v 1.57 1997/06/19 22:51:48 wessels Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -155,44 +155,6 @@ errorInitialize(void) meta_data.misc += MAX_URL * 3; } -void -squid_error_entry(StoreEntry * entry, log_type type, const char *msg) -{ - int error_index; - - if (entry == NULL) - return; - if (entry->store_status != STORE_PENDING) - return; - if (type < ERR_MIN || type > ERR_MAX) - fatal_dump("squid_error_entry: type out of range."); - error_index = (int) (type - ERR_MIN); - debug(4, 1) ("%s: %s\n", ErrorData[error_index].tag, entry->url); - sprintf(tmp_error_buf, SQUID_ERROR_MSG_P1, - entry->url, - entry->url, - ErrorData[error_index].shrt); - if (msg) { - sprintf(tbuf, SQUID_ERROR_MSG_P2, msg); - strcat(tmp_error_buf, tbuf); - } - sprintf(tbuf, SQUID_ERROR_MSG_P3, - ErrorData[error_index].lng, - Config.errHtmlText, - appname, - version_string, - getMyHostname()); - strcat(tmp_error_buf, tbuf); - if (entry->mem_obj) { - entry->mem_obj->abort_code = type; - if (entry->mem_obj->reply->code == 0) - entry->mem_obj->reply->code = 400; - } - storeAbort(entry, tmp_error_buf); -} - - - char * squid_error_url(const char *url, int method, int type, const char *address, int code, const char *msg) { diff --git a/src/ftp.cc b/src/ftp.cc index 532acb3482..02906c4d14 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.124 1997/06/18 04:04:13 wessels Exp $ + * $Id: ftp.cc,v 1.125 1997/06/19 22:51:50 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -226,7 +226,7 @@ ftpTimeout(int fd, void *data) FtpStateData *ftpState = data; StoreEntry *entry = ftpState->entry; debug(9, 4) ("ftpLifeTimeExpire: FD %d: '%s'\n", fd, entry->url); - squid_error_entry(entry, ERR_READ_TIMEOUT, NULL); + storeAbort(entry, ERR_READ_TIMEOUT, NULL, 0); if (ftpState->data.fd >= 0) comm_close(ftpState->data.fd); comm_close(ftpState->ctrl.fd); @@ -601,7 +601,7 @@ ftpReadData(int fd, void *data) StoreEntry *entry = ftpState->entry; assert(fd == ftpState->data.fd); if (protoAbortFetch(entry)) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + storeAbort(entry, ERR_CLIENT_ABORT, NULL, 0); ftpDataTransferDone(ftpState); return; } @@ -649,13 +649,11 @@ ftpReadData(int fd, void *data) } else { BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); - squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); + storeAbort(entry, ERR_READ_ERROR, xstrerror(), 0); ftpDataTransferDone(ftpState); } } else if (len == 0 && entry->mem_obj->e_current_len == 0) { - squid_error_entry(entry, - ERR_ZERO_SIZE_OBJECT, - errno ? xstrerror() : NULL); + storeAbort(entry, ERR_ZERO_SIZE_OBJECT, errno ? xstrerror() : NULL, 0); ftpDataTransferDone(ftpState); } else if (len == 0) { /* Connection closed; retrieval done. */ @@ -853,7 +851,7 @@ ftpStart(request_t * request, StoreEntry * entry) url); if (fd == COMM_ERROR) { debug(9, 4) ("ftpStart: Failed because we're out of sockets.\n"); - squid_error_entry(entry, ERR_NO_FDS, xstrerror()); + storeAbort(entry, ERR_NO_FDS, xstrerror(), 0); return; } ftpState->ctrl.fd = fd; @@ -873,7 +871,7 @@ ftpConnectDone(int fd, int status, void *data) FtpStateData *ftpState = data; debug(9, 3) ("ftpConnectDone\n"); if (status == COMM_ERROR) { - squid_error_entry(ftpState->entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(ftpState->entry, ERR_CONNECT_FAIL, xstrerror(), 0); comm_close(fd); return; } @@ -917,7 +915,7 @@ ftpWriteCommandCallback(int fd, char *buf, int size, int errflag, void *data) if (errflag) { BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); - squid_error_entry(entry, ERR_WRITE_ERROR, xstrerror()); + storeAbort(entry, ERR_WRITE_ERROR, xstrerror(), 0); comm_close(fd); } } @@ -988,7 +986,7 @@ ftpReadControlReply(int fd, void *data) } else { BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); - squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); + storeAbort(entry, ERR_READ_ERROR, xstrerror(), 0); comm_close(fd); } return; @@ -997,7 +995,7 @@ ftpReadControlReply(int fd, void *data) debug(9, 1) ("Read 0 bytes from FTP control socket?\n"); BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); - squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); + storeAbort(entry, ERR_READ_ERROR, xstrerror(), 0); comm_close(fd); return; } @@ -1283,7 +1281,7 @@ ftpPasvCallback(int fd, int status, void *data) FtpStateData *ftpState = data; debug(9, 3) ("ftpPasvCallback\n"); if (status == COMM_ERROR) { - squid_error_entry(ftpState->entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(ftpState->entry, ERR_CONNECT_FAIL, xstrerror(), 0); comm_close(fd); return; } diff --git a/src/gopher.cc b/src/gopher.cc index b7fb7d9f42..043257d88e 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,5 +1,5 @@ /* - * $Id: gopher.cc,v 1.85 1997/06/18 01:43:43 wessels Exp $ + * $Id: gopher.cc,v 1.86 1997/06/19 22:51:50 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -647,7 +647,7 @@ gopherTimeout(int fd, void *data) GopherStateData *gopherState = data; StoreEntry *entry = gopherState->entry; debug(10, 4) ("gopherTimeout: FD %d: '%s'\n", fd, entry->url); - squid_error_entry(entry, ERR_READ_TIMEOUT, NULL); + storeAbort(entry, ERR_READ_TIMEOUT, NULL, 0); comm_close(fd); } @@ -664,7 +664,7 @@ gopherReadReply(int fd, void *data) int off; int bin; if (protoAbortFetch(entry)) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + storeAbort(entry, ERR_CLIENT_ABORT, NULL, 0); comm_close(fd); return; } @@ -718,13 +718,11 @@ gopherReadReply(int fd, void *data) } else { BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); - squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); + storeAbort(entry, ERR_READ_ERROR, xstrerror(), 0); comm_close(fd); } } else if (len == 0 && entry->mem_obj->e_current_len == 0) { - squid_error_entry(entry, - ERR_ZERO_SIZE_OBJECT, - errno ? xstrerror() : NULL); + storeAbort(entry, ERR_ZERO_SIZE_OBJECT, errno ? xstrerror() : NULL, 0); comm_close(fd); } else if (len == 0) { /* Connection closed; retrieval done. */ @@ -761,7 +759,7 @@ gopherSendComplete(int fd, char *buf, int size, int errflag, void *data) debug(10, 5) ("gopherSendComplete: FD %d size: %d errflag: %d\n", fd, size, errflag); if (errflag) { - squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(entry, ERR_CONNECT_FAIL, xstrerror(), 0); comm_close(fd); if (buf) put_free_4k_page(buf); /* Allocated by gopherSendRequest. */ @@ -854,7 +852,7 @@ gopherStart(StoreEntry * entry) /* Parse url. */ if (gopher_url_parser(url, gopherState->host, &gopherState->port, &gopherState->type_id, gopherState->request)) { - squid_error_entry(entry, ERR_INVALID_URL, NULL); + storeAbort(entry, ERR_INVALID_URL, NULL, 0); gopherStateFree(-1, gopherState); return; } @@ -867,7 +865,7 @@ gopherStart(StoreEntry * entry) url); if (fd == COMM_ERROR) { debug(10, 4) ("gopherStart: Failed because we're out of sockets.\n"); - squid_error_entry(entry, ERR_NO_FDS, xstrerror()); + storeAbort(entry, ERR_NO_FDS, xstrerror(), 0); gopherStateFree(-1, gopherState); return; } @@ -878,7 +876,7 @@ gopherStart(StoreEntry * entry) * Otherwise, we cannot check return code for connect. */ if (!ipcache_gethostbyname(gopherState->host, 0)) { debug(10, 4) ("gopherStart: Called without IP entry in ipcache. OR lookup failed.\n"); - squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message); + storeAbort(entry, ERR_DNS_FAIL, dns_error_message, 0); comm_close(fd); return; } @@ -916,7 +914,7 @@ gopherConnectDone(int fd, int status, void *data) { GopherStateData *gopherState = data; if (status == COMM_ERROR) { - squid_error_entry(gopherState->entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(gopherState->entry, ERR_CONNECT_FAIL, xstrerror(), 0); comm_close(fd); return; } diff --git a/src/http.cc b/src/http.cc index 8a7f2e344d..19c52e8ac9 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.173 1997/06/18 04:04:14 wessels Exp $ + * $Id: http.cc,v 1.174 1997/06/19 22:51:51 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -245,7 +245,7 @@ httpTimeout(int fd, void *data) HttpStateData *httpState = data; StoreEntry *entry = httpState->entry; debug(11, 4) ("httpTimeout: FD %d: '%s'\n", fd, entry->url); - squid_error_entry(entry, ERR_READ_TIMEOUT, NULL); + storeAbort(entry, ERR_READ_TIMEOUT, NULL, 0); comm_close(fd); } @@ -531,7 +531,7 @@ httpReadReply(int fd, void *data) int clen; int off; if (protoAbortFetch(entry)) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + storeAbort(entry, ERR_CLIENT_ABORT, NULL, 0); comm_close(fd); return; } @@ -580,16 +580,14 @@ httpReadReply(int fd, void *data) } else { BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); - squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); + storeAbort(entry, ERR_READ_ERROR, xstrerror(), 0); comm_close(fd); } debug(50, 2) ("httpReadReply: FD %d: read failure: %s.\n", fd, xstrerror()); } else if (len == 0 && entry->mem_obj->e_current_len == 0) { httpState->eof = 1; - squid_error_entry(entry, - ERR_ZERO_SIZE_OBJECT, - errno ? xstrerror() : NULL); + storeAbort(entry, ERR_ZERO_SIZE_OBJECT, errno ? xstrerror() : NULL, 0); comm_close(fd); } else if (len == 0) { /* Connection closed; retrieval done. */ @@ -623,7 +621,7 @@ httpSendComplete(int fd, char *buf, int size, int errflag, void *data) fd, size, errflag); if (errflag) { - squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(entry, ERR_CONNECT_FAIL, xstrerror(), 0); comm_close(fd); return; } else { @@ -850,7 +848,7 @@ proxyhttpStart(request_t * orig_request, entry->url); if (fd == COMM_ERROR) { debug(11, 4) ("proxyhttpStart: Failed because we're out of sockets.\n"); - squid_error_entry(entry, ERR_NO_FDS, xstrerror()); + storeAbort(entry, ERR_NO_FDS, xstrerror(), 0); return; } storeLockObject(entry); @@ -887,10 +885,10 @@ httpConnectDone(int fd, int status, void *data) StoreEntry *entry = httpState->entry; if (status == COMM_ERR_DNS) { debug(11, 4) ("httpConnectDone: Unknown host: %s\n", request->host); - squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message); + storeAbort(entry, ERR_DNS_FAIL, dns_error_message, 0); comm_close(fd); } else if (status != COMM_OK) { - squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(entry, ERR_CONNECT_FAIL, xstrerror(), 0); if (httpState->neighbor) peerCheckConnectStart(httpState->neighbor); comm_close(fd); @@ -918,7 +916,7 @@ httpStart(request_t * request, StoreEntry * entry) entry->url); if (fd == COMM_ERROR) { debug(11, 4) ("httpStart: Failed because we're out of sockets.\n"); - squid_error_entry(entry, ERR_NO_FDS, xstrerror()); + storeAbort(entry, ERR_NO_FDS, xstrerror(), 0); return; } storeLockObject(entry); diff --git a/src/store.cc b/src/store.cc index 96cef5b3ad..5d662572e1 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.259 1997/06/18 16:15:53 wessels Exp $ + * $Id: store.cc,v 1.260 1997/06/19 22:51:55 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -1659,58 +1659,42 @@ storeComplete(StoreEntry * e) } /* - * Fetch aborted. Tell all clients to go home. Negatively cache - * abort message, freeing the data for this object + * Someone wants to abort this transfer. Set the reason in the + * request structure, call the server-side callback and mark the + * entry for releasing */ void -storeAbort(StoreEntry * e, const char *msg) +storeAbort(StoreEntry * e, log_type abort_code, const char *msg, int cbflag) { - LOCAL_ARRAY(char, mime_hdr, 300); - char *abort_msg; MemObject *mem = e->mem_obj; assert(e->store_status == STORE_PENDING); assert(mem != NULL); - /*assert(ping_status != PING_WAITING); */ - debug(20, 6) ("storeAbort: '%s'\n", e->key); + safe_free(mem->e_abort_msg); + mem->e_abort_msg = xstrdup(msg); + debug(20, 6) ("storeAbort: %s %s\n", log_tags[abort_code], e->key); storeNegativeCache(e); + storeReleaseRequest(e); e->store_status = STORE_ABORTED; storeSetMemStatus(e, IN_MEMORY); /* No DISK swap for negative cached object */ e->swap_status = NO_SWAP; e->lastref = squid_curtime; - storeLockObject(e); /* Count bytes faulted through cache but not moved to disk */ HTTPCacheInfo->proto_touchobject(HTTPCacheInfo, mem->request ? mem->request->protocol : PROTO_NONE, mem->e_current_len); - if (msg) { - abort_msg = get_free_8k_page(); - strcpy(abort_msg, "HTTP/1.0 400 Cache Detected Error\r\n"); - mk_mime_hdr(mime_hdr, - "text/html", - strlen(msg), - (time_t) Config.negativeTtl, - squid_curtime); - strcat(abort_msg, mime_hdr); - strcat(abort_msg, "\r\n"); - strncat(abort_msg, msg, 8191 - strlen(abort_msg)); - storeAppend(e, abort_msg, strlen(abort_msg)); - safe_free(mem->e_abort_msg); - mem->e_abort_msg = xstrdup(abort_msg); - /* Set up object for negative caching */ - BIT_SET(e->flag, ABORT_MSG_PENDING); - put_free_8k_page(abort_msg); - } /* We assign an object length here--The only other place we assign the * object length is in storeComplete() */ + storeLockObject(e); e->object_len = mem->e_current_len; - if (mem->abort.callback) { + /* Notify the server side */ + if (cbflag && mem->abort.callback) { mem->abort.callback(mem->abort.data); mem->abort.callback = NULL; } + /* Notify the client side */ InvokeHandlers(e); storeUnlockObject(e); - return; } /* get the first in memory object entry in the storage */ @@ -2533,7 +2517,7 @@ storeWriteCleanLogs(void) static int swapInError(int fd_unused, StoreEntry * entry) { - squid_error_entry(entry, ERR_DISK_IO, xstrerror()); + storeAbort(entry, ERR_DISK_IO, xstrerror(), 1); return 0; } diff --git a/src/wais.cc b/src/wais.cc index 20cd27c83e..3388d458c1 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,6 +1,6 @@ /* - * $Id: wais.cc,v 1.77 1997/06/18 01:43:46 wessels Exp $ + * $Id: wais.cc,v 1.78 1997/06/19 22:51:57 wessels Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -144,7 +144,7 @@ waisTimeout(int fd, void *data) WaisStateData *waisState = data; StoreEntry *entry = waisState->entry; debug(24, 4) ("waisTimeout: FD %d: '%s'\n", fd, entry->url); - squid_error_entry(entry, ERR_READ_TIMEOUT, NULL); + storeAbort(entry, ERR_READ_TIMEOUT, NULL, 0); comm_close(fd); } @@ -163,13 +163,13 @@ waisReadReply(int fd, void *data) int off; int bin; if (protoAbortFetch(entry)) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + storeAbort(entry, ERR_CLIENT_ABORT, NULL, 0); comm_close(fd); return; } if (entry->flag & DELETE_BEHIND && !storeClientWaiting(entry)) { /* we can terminate connection right now */ - squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL); + storeAbort(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL, 0); comm_close(fd); return; } @@ -218,13 +218,11 @@ waisReadReply(int fd, void *data) } else { BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); - squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); + storeAbort(entry, ERR_READ_ERROR, xstrerror(), 0); comm_close(fd); } } else if (len == 0 && entry->mem_obj->e_current_len == 0) { - squid_error_entry(entry, - ERR_ZERO_SIZE_OBJECT, - errno ? xstrerror() : NULL); + storeAbort(entry, ERR_ZERO_SIZE_OBJECT, errno ? xstrerror() : NULL, 0); comm_close(fd); } else if (len == 0) { /* Connection closed; retrieval done. */ @@ -250,7 +248,7 @@ waisSendComplete(int fd, char *buf, int size, int errflag, void *data) debug(24, 5) ("waisSendComplete: FD %d size: %d errflag: %d\n", fd, size, errflag); if (errflag) { - squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(entry, ERR_CONNECT_FAIL, xstrerror(), 0); comm_close(fd); } else { /* Schedule read reply. */ @@ -305,7 +303,7 @@ waisStart(request_t * request, StoreEntry * entry) debug(24, 3) ("waisStart: \"%s %s\"\n", RequestMethodStr[method], url); if (!Config.Wais.relayHost) { debug(24, 0) ("waisStart: Failed because no relay host defined!\n"); - squid_error_entry(entry, ERR_NO_RELAY, NULL); + storeAbort(entry, ERR_NO_RELAY, NULL, 0); return; } fd = comm_open(SOCK_STREAM, @@ -316,7 +314,7 @@ waisStart(request_t * request, StoreEntry * entry) url); if (fd == COMM_ERROR) { debug(24, 4) ("waisStart: Failed because we're out of sockets.\n"); - squid_error_entry(entry, ERR_NO_FDS, xstrerror()); + storeAbort(entry, ERR_NO_FDS, xstrerror(), 0); return; } waisState = xcalloc(1, sizeof(WaisStateData)); @@ -344,11 +342,11 @@ waisConnectDone(int fd, int status, void *data) { WaisStateData *waisState = data; if (status == COMM_ERR_DNS) { - squid_error_entry(waisState->entry, ERR_DNS_FAIL, dns_error_message); + storeAbort(waisState->entry, ERR_DNS_FAIL, dns_error_message, 0); comm_close(fd); return; } else if (status != COMM_OK) { - squid_error_entry(waisState->entry, ERR_CONNECT_FAIL, xstrerror()); + storeAbort(waisState->entry, ERR_CONNECT_FAIL, xstrerror(), 0); comm_close(fd); return; }