-/* $Id: gopher.cc,v 1.4 1996/02/29 07:23:13 wessels Exp $ */
+/* $Id: gopher.cc,v 1.5 1996/03/23 00:03:01 wessels Exp $ */
#include "config.h"
#include <errno.h>
#include "stmem.h"
#include "ipcache.h"
#include "icp.h"
+#include "cached_error.h"
extern char *dns_error_message;
extern time_t cached_curtime;
StoreEntry *entry = NULL;
entry = data->entry;
debug(4, "GopherReadReplyTimeout: Timeout on %d\n url: %s\n", fd, entry->url);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 203,
- "Read timeout",
- "Network/Remote site may be down. Try again later.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_READ_TIMEOUT);
if (data->icp_page_ptr)
put_free_4k_page(data->icp_page_ptr);
if (data->icp_rwd_ptr)
safe_free(data->icp_rwd_ptr);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_203", /* GOPHER READ TIMEOUT */
- "GET");
-#endif
freeGopherData(data);
return 0;
}
StoreEntry *entry = NULL;
entry = data->entry;
debug(4, "gopherLifeTimeExpire: FD %d: <URL:%s>\n", fd, entry->url);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "GOPHER",
- 210,
- "Transaction Timeout",
- "The Network/Remote site may be down or too slow. Try again later.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_LIFETIME_EXP);
if (data->icp_page_ptr)
put_free_4k_page(data->icp_page_ptr);
if (data->icp_rwd_ptr)
safe_free(data->icp_rwd_ptr);
- comm_set_select_handler(fd, COMM_SELECT_READ | COMM_SELECT_WRITE, 0, 0);
+ comm_set_select_handler(fd,
+ COMM_SELECT_READ | COMM_SELECT_WRITE,
+ 0,
+ 0);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_210", /* GOPHER LIFETIME EXPIRE */
- "GET");
-#endif
freeGopherData(data);
}
}
} else {
/* we can terminate connection right now */
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 219,
- "No Client",
- "All Clients went away before tranmission is complete and object is too big to cache.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_NO_CLIENTS_BIG_OBJ);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_219", /* GOPHER NO CLIENTS, BIG OBJ */
- "GET");
-#endif
freeGopherData(data);
return 0;
}
if (len < 0 || ((len == 0) && (entry->mem_obj->e_current_len == 0))) {
debug(1, "gopherReadReply - error reading: %s\n",
xstrerror());
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 205,
- "Read error",
- "Network/Remote Site is down. Try again later.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_READ_ERROR);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_205", /* GOPHER READ FAIL */
- "GET");
-#endif
freeGopherData(data);
-
} else if (len == 0) {
/* Connection closed; retrieval done. */
/* flush the rest of data in temp buf if there is one. */
} else {
storeAppend(entry, buf, len);
}
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 207,
- "Client Aborted",
- "Client(s) dropped connection before transmission is complete.\nObject fetching is aborted.\n",
- SQUID_VERSION,
- comm_hostname());
+ cached_error(entry, ERR_CLIENT_ABORT);
if (data->conversion != NORMAL)
gopherEndHTML(data);
BIT_RESET(entry->flag, DELAY_SENDING);
- storeAbort(entry, tmp_error_buf);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_207", /* GOPHER CLIENT ABORT */
- "GET");
-#endif
freeGopherData(data);
-
} else {
if (data->conversion != NORMAL) {
gopherToHTML(data, buf, len);
debug(5, "gopherSendComplete - fd: %d size: %d errflag: %d\n",
fd, size, errflag);
if (errflag) {
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 201,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_CONNECT_FAIL, xstrerror());
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_201", /* GOPHER CONNECT FAIL */
- "GET");
-#endif
freeGopherData(data);
if (buf)
put_free_4k_page(buf); /* Allocated by gopherSendRequest. */
/* Parse url. */
if (gopher_url_parser(url, data->host, &data->port,
&data->type_id, data->request)) {
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 208,
- "Invalid URL syntax: Cannot parse.",
- "Contact your system adminstrator for further help.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_208", /* GOPHER INVALID URL */
- "GET");
-#endif
+ cached_error(entry, ERR_INVALID_URL);
freeGopherData(data);
return COMM_ERROR;
}
/* Create socket. */
sock = comm_open(COMM_NONBLOCKING, 0, 0, url);
-
if (sock == COMM_ERROR) {
debug(4, "gopherStart: Failed because we're out of sockets.\n");
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 211,
- "Cached short of file-descriptors, sorry",
- "",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_211", /* GOPHER NO FD'S */
- "GET");
-#endif
+ cached_error(entry, ERR_NO_FDS);
freeGopherData(data);
return COMM_ERROR;
}
if (!ipcache_gethostbyname(data->host)) {
debug(4, "gopherStart: Called without IP entry in ipcache. OR lookup failed.\n");
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 202,
- "DNS name lookup failure",
- dns_error_message,
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_202", /* GOPHER DNS FAIL */
- "GET");
-#endif
+ cached_error(entry, ERR_DNS_FAIL, dns_error_message);
freeGopherData(data);
return COMM_ERROR;
}
if ((status = comm_connect(sock, data->host, data->port)) != 0) {
if (status != EINPROGRESS) {
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "Gopher",
- 204,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_204", /* GOPHER CONNECT FAIL */
- "GET");
-#endif
+ cached_error(entry, ERR_CONNECT_FAIL, xstrerror());
freeGopherData(data);
return COMM_ERROR;
} else {
}
}
/* Install connection complete handler. */
- comm_set_select_handler(sock, COMM_SELECT_LIFETIME,
- (PF) gopherLifetimeExpire, (caddr_t) data);
- comm_set_select_handler(sock, COMM_SELECT_WRITE,
- (PF) gopherSendRequest, (caddr_t) data);
+ comm_set_select_handler(sock,
+ COMM_SELECT_LIFETIME,
+ (PF) gopherLifetimeExpire,
+ (caddr_t) data);
+ comm_set_select_handler(sock,
+ COMM_SELECT_WRITE,
+ (PF) gopherSendRequest,
+ (caddr_t) data);
return COMM_OK;
}
-/* $Id: http.cc,v 1.5 1996/03/22 06:38:28 wessels Exp $ */
+/* $Id: http.cc,v 1.6 1996/03/23 00:03:02 wessels Exp $ */
#include "config.h"
#include <sys/errno.h>
#include "ttl.h"
#include "icp.h"
#include "util.h"
+#include "cached_error.h"
#define HTTP_PORT 80
#define HTTP_DELETE_GAP (64*1024)
entry = data->entry;
debug(4, "httpReadReplyTimeout: FD %d: <URL:%s>\n", fd, entry->url);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 103,
- "Read timeout",
- "The Network/Remote site may be down. Try again later.",
- SQUID_VERSION,
- comm_hostname());
-
+ cached_error(entry, ERR_READ_TIMEOUT);
if (data->icp_rwd_ptr)
safe_free(data->icp_rwd_ptr);
if (data->icp_page_ptr) {
put_free_8k_page(data->icp_page_ptr);
data->icp_page_ptr = NULL;
}
- storeAbort(entry, tmp_error_buf);
comm_set_select_handler(fd, COMM_SELECT_READ, 0, 0);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_103", /* HTTP READ TIMEOUT */
- data->type ? data->type : "NULL");
-#endif
safe_free(data);
}
entry = data->entry;
debug(4, "httpLifeTimeExpire: FD %d: <URL:%s>\n", fd, entry->url);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 110,
- "Transaction Timeout",
- "The Network/Remote site may be down or too slow. Try again later.",
- SQUID_VERSION,
- comm_hostname());
-
+ cached_error(entry, ERR_LIFETIME_EXP);
if (data->icp_page_ptr) {
put_free_8k_page(data->icp_page_ptr);
data->icp_page_ptr = NULL;
}
if (data->icp_rwd_ptr)
safe_free(data->icp_rwd_ptr);
- storeAbort(entry, tmp_error_buf);
comm_set_select_handler(fd, COMM_SELECT_READ | COMM_SELECT_WRITE, 0, 0);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_110", /* HTTP LIFETIME EXPIRE */
- data->type ? data->type : "NULL");
-#endif
safe_free(data);
}
}
} else {
/* we can terminate connection right now */
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 119,
- "No Client",
- "All Clients went away before tranmission is complete and object is too big to cache.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_NO_CLIENTS_BIG_OBJ);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_119", /* HTTP NO CLIENTS, BIG OBJ */
- data->type ? data->type : "NULL");
-#endif
safe_free(data);
return;
}
storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
storeComplete(entry);
} else {
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 105,
- "Read error",
- "Network/Remote site is down. Try again later.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_READ_ERROR);
}
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_105", /* HTTP READ ERROR */
- data->type ? data->type : "NULL");
-#endif
safe_free(data);
} else if (len == 0) {
/* Connection closed; retrieval done. */
} else if (entry->flag & CLIENT_ABORT_REQUEST) {
/* append the last bit of info we get */
storeAppend(entry, buf, len);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 107,
- "Client Aborted",
- "Client(s) dropped connection before transmission is complete.\nObject fetching is aborted.\n",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_CLIENT_ABORT);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_107", /* HTTP CLIENT ABORT */
- data->type ? data->type : "NULL");
-#endif
safe_free(data);
} else {
storeAppend(entry, buf, len);
data->icp_rwd_ptr = NULL; /* Don't double free in lifetimeexpire */
if (errflag) {
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 101,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_CONNECT_FAIL);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_101", /* HTTP CONNECT FAIL */
- data->type ? data->type : "NULL");
-#endif
safe_free(data);
return;
} else {
break; /* cool, we're connected */
default:
comm_close(fd);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 104,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_104", /* HTTP CONNECT FAIL */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_CONNECT_FAIL);
safe_free(data);
return;
}
sock = comm_open(COMM_NONBLOCKING, 0, 0, url);
if (sock == COMM_ERROR) {
debug(4, "proxyhttpStart: Failed because we're out of sockets.\n");
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 111,
- "Cached short of file-descriptors, sorry",
- "",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_111", /* HTTP NO FD'S */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_NO_FDS);
safe_free(data);
return COMM_ERROR;
}
if (!ipcache_gethostbyname(data->host)) {
debug(4, "proxyhttpstart: Called without IP entry in ipcache. OR lookup failed.\n");
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 102,
- "DNS name lookup failure",
- dns_error_message,
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_102", /* HTTP DNS FAIL */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_DNS_FAIL, dns_error_message);
safe_free(data);
return COMM_ERROR;
}
if ((status = comm_connect(sock, data->host, data->port))) {
if (status != EINPROGRESS) {
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 104,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_104", /* HTTP CONNECT FAIL */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_CONNECT_FAIL);
safe_free(data);
e->last_fail_time = cached_curtime;
e->neighbor_up = 0;
/* Parse url. */
if (http_url_parser(url, data->host, &data->port, data->request)) {
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 110,
- "Invalid URL syntax: Cannot parse.",
- "Contact your system administrator for further help.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_110", /* HTTP INVALID URL */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_INVALID_URL);
safe_free(data);
return COMM_ERROR;
}
sock = comm_open(COMM_NONBLOCKING, 0, 0, url);
if (sock == COMM_ERROR) {
debug(4, "httpStart: Failed because we're out of sockets.\n");
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 111,
- "Cached short of file-descriptors, sorry",
- "",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_111", /* HTTP NO FD'S */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_NO_FDS);
safe_free(data);
return COMM_ERROR;
}
if (!ipcache_gethostbyname(data->host)) {
debug(4, "httpstart: Called without IP entry in ipcache. OR lookup failed.\n");
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 108,
- "DNS name lookup failure",
- dns_error_message,
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_108", /* HTTP DNS FAIL */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_DNS_FAIL, dns_error_message);
safe_free(data);
return COMM_ERROR;
}
if ((status = comm_connect(sock, data->host, data->port))) {
if (status != EINPROGRESS) {
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "HTTP",
- 109,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_109", /* HTTP CONNECT FAIL */
- data->type ? data->type : "NULL");
-#endif
+ cached_error(entry, ERR_CONNECT_FAIL);
safe_free(data);
return COMM_ERROR;
} else {
-/* $Id: store.cc,v 1.5 1996/03/22 17:48:18 wessels Exp $ */
+/* $Id: store.cc,v 1.6 1996/03/23 00:03:04 wessels Exp $ */
/*
* Here is a summary of the routines which change mem_status and swap_status:
#include "filemap.h"
#include "stmem.h"
#include "mime.h"
+#include "cached_error.h"
extern time_t cached_curtime;
extern char *storeToString _PARAMS((StoreEntry * e));
int fd_unused;
StoreEntry *entry;
{
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "DISK I/O",
- 102,
- "Cache Disk I/O Failure",
- "",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_DISK_IO, xstrerror());
return 0;
}
-/* $Id: wais.cc,v 1.5 1996/03/22 06:38:29 wessels Exp $ */
+/* $Id: wais.cc,v 1.6 1996/03/23 00:03:05 wessels Exp $ */
#include "config.h"
#if USE_WAIS_RELAY
#include "ipcache.h"
#include "cache_cf.h"
#include "util.h"
+#include "cached_error.h"
#define WAIS_DELETE_GAP (64*1024)
entry = data->entry;
debug(4, "waisReadReplyTimeout: Timeout on %d\n url: %s\n", fd, entry->url);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 403,
- "Read timeout",
- "The Network/Remote site may be down. Try again later.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_READ_TIMEOUT);
comm_set_select_handler(fd, COMM_SELECT_READ, 0, 0);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_403", /* WAIS READ TIMEOUT */
- "GET");
-#endif
safe_free(data);
}
entry = data->entry;
debug(4, "waisLifeTimeExpire: FD %d: <URL:%s>\n", fd, entry->url);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 410,
- "Transaction Timeout",
- "The Network/Remote site may be down or too slow. Try again later.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_LIFETIME_EXP);
comm_set_select_handler(fd, COMM_SELECT_READ | COMM_SELECT_WRITE, 0, 0);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_410", /* WAIS LIFETIME EXPIRE */
- "GET");
-#endif
safe_free(data);
}
}
} else {
/* we can terminate connection right now */
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 419,
- "No Client",
- "All Clients went away before tranmission is complete and object is too big to cache.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_NO_CLIENTS_BIG_OBJ);
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_419", /* WAIS NO CLIENTS, BIG OBJECT */
- "GET");
-#endif
safe_free(data);
return;
}
storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
storeComplete(entry);
} else {
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 405,
- "Read error",
- "Network/Remote site is down. Try again later.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_READ_ERROR);
}
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_405", /* WAIS READ ERROR */
- "GET");
-#endif
safe_free(data);
} else if (len == 0) {
/* Connection closed; retrieval done. */
debug(5, "waisSendComplete - fd: %d size: %d errflag: %d\n",
fd, size, errflag);
if (errflag) {
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 401,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
+ cached_error(entry, ERR_CONNECT_FAIL, xstrerror());
comm_close(fd);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_401", /* WAIS CONNECT FAILURE */
- "GET");
-#endif
safe_free(data);
} else {
/* Schedule read reply. */
if (!getWaisRelayHost()) {
debug(0, "waisStart: Failed because no relay host defined!\n");
- sprintf(tmp_error_buf,
- CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 412,
- "Configuration error. No WAIS relay host is defined.",
- "",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_412", /* WAIS NO RELAY */
- "GET");
-#endif
+ cached_error(entry, ERR_NO_RELAY);
safe_free(data);
return COMM_ERROR;
}
sock = comm_open(COMM_NONBLOCKING, 0, 0, url);
if (sock == COMM_ERROR) {
debug(4, "waisStart: Failed because we're out of sockets.\n");
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 411,
- "Cached short of file-descriptors, sorry",
- "",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_411", /* WAIS NO FD'S */
- "GET");
-#endif
+ cached_error(entry, ERR_NO_FDS);
safe_free(data);
return COMM_ERROR;
}
if (!ipcache_gethostbyname(data->host)) {
debug(4, "waisstart: Called without IP entry in ipcache. OR lookup failed.\n");
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 402,
- "DNS name lookup failure",
- dns_error_message,
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_402", /* WAIS DNS FAILURE */
- "GET");
-#endif
+ cached_error(entry, ERR_DNS_FAIL, dns_error_message);
safe_free(data);
return COMM_ERROR;
}
if ((status = comm_connect(sock, data->host, data->port))) {
if (status != EINPROGRESS) {
comm_close(sock);
- sprintf(tmp_error_buf, CACHED_RETRIEVE_ERROR_MSG,
- entry->url,
- entry->url,
- "WAIS",
- 401,
- "Cannot connect to the original site",
- "The remote site may be down.",
- SQUID_VERSION,
- comm_hostname());
- storeAbort(entry, tmp_error_buf);
-#ifdef LOG_ERRORS
- CacheInfo->log_append(CacheInfo,
- entry->url,
- "0.0.0.0",
- entry->mem_obj->e_current_len,
- "ERR_401", /* WAIS CONNECT FAIL */
- "GET");
-#endif
+ cached_error(entry, ERR_CONNECT_FAIL, xstrerror());
safe_free(data);
return COMM_ERROR;
} else {