]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
use cached_error() instead of CACHED_RETRIEVE_ERROR_MSG
authorwessels <>
Sat, 23 Mar 1996 07:03:01 +0000 (07:03 +0000)
committerwessels <>
Sat, 23 Mar 1996 07:03:01 +0000 (07:03 +0000)
src/gopher.cc
src/http.cc
src/store.cc
src/wais.cc

index 9bbe7ca1195cfebd84c41add0db2d1b1d2f4bbe2..ec3a37908f00f377f9ff38d295b1973d3594aaf2 100644 (file)
@@ -1,4 +1,4 @@
-/* $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>
@@ -19,6 +19,7 @@
 #include "stmem.h"
 #include "ipcache.h"
 #include "icp.h"
+#include "cached_error.h"
 
 extern char *dns_error_message;
 extern time_t cached_curtime;
@@ -582,29 +583,12 @@ int gopherReadReplyTimeout(fd, data)
     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;
 }
@@ -617,30 +601,16 @@ void gopherLifetimeExpire(fd, data)
     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);
 }
 
@@ -694,25 +664,8 @@ int gopherReadReply(fd, 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;
        }
@@ -724,27 +677,9 @@ int gopherReadReply(fd, data)
     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. */
@@ -778,30 +713,12 @@ int gopherReadReply(fd, data)
        } 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);
@@ -830,25 +747,8 @@ int gopherSendComplete(fd, buf, size, errflag, data)
     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. */
@@ -960,50 +860,15 @@ int gopherStart(unusedfd, url, entry)
     /* 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;
     }
@@ -1013,24 +878,7 @@ int gopherStart(unusedfd, url, entry)
     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;
     }
@@ -1060,24 +908,7 @@ int gopherStart(unusedfd, url, entry)
     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 {
@@ -1085,10 +916,14 @@ int gopherStart(unusedfd, url, entry)
        }
     }
     /* 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;
 }
index fd868cb05c42fa4f4a10d8ca995defdf4e657487..70a0b1369d1c310f325d7bdb66e0e37b51d2b2eb 100644 (file)
@@ -1,4 +1,4 @@
-/* $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>
@@ -16,6 +16,7 @@
 #include "ttl.h"
 #include "icp.h"
 #include "util.h"
+#include "cached_error.h"
 
 #define HTTP_PORT         80
 #define HTTP_DELETE_GAP   (64*1024)
@@ -107,33 +108,15 @@ void httpReadReplyTimeout(fd, data)
 
     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);
 }
 
@@ -147,33 +130,15 @@ void httpLifetimeExpire(fd, 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);
 }
 
@@ -228,25 +193,8 @@ void httpReadReply(fd, 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;
        }
@@ -267,26 +215,9 @@ void httpReadReply(fd, data)
            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. */
@@ -309,25 +240,8 @@ void httpReadReply(fd, data)
     } 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);
@@ -361,25 +275,8 @@ void httpSendComplete(fd, buf, size, errflag, data)
     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 {
@@ -485,24 +382,7 @@ void httpConnInProgress(fd, data)
            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;
        }
@@ -541,24 +421,7 @@ int proxyhttpStart(e, url, entry)
     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;
     }
@@ -568,24 +431,7 @@ int proxyhttpStart(e, url, entry)
     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;
     }
@@ -593,24 +439,7 @@ int proxyhttpStart(e, url, entry)
     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;
@@ -655,24 +484,7 @@ int httpStart(unusedfd, url, type, mime_hdr, entry)
 
     /* 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;
     }
@@ -680,24 +492,7 @@ int httpStart(unusedfd, url, type, mime_hdr, entry)
     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;
     }
@@ -707,24 +502,7 @@ int httpStart(unusedfd, url, type, mime_hdr, entry)
     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;
     }
@@ -732,24 +510,7 @@ int httpStart(unusedfd, url, type, mime_hdr, entry)
     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 {
index b517912f1a6d1efb1342ba0bb045b8cfbed17747..065befbcbfd22f887a1bd1e211fc2432b8ba2737 100644 (file)
@@ -1,5 +1,5 @@
 
-/* $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:
@@ -54,6 +54,7 @@
 #include "filemap.h"
 #include "stmem.h"
 #include "mime.h"
+#include "cached_error.h"
 
 extern time_t cached_curtime;
 extern char *storeToString _PARAMS((StoreEntry * e));
@@ -2552,16 +2553,7 @@ int swapInError(fd_unused, entry)
      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;
 }
 
index 6e7d78fc5f902e697c980a236d5fa7cc0cffa565..f2915ce257cf088ebe3fe4746579882ce86e7221 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -15,6 +15,7 @@
 #include "ipcache.h"
 #include "cache_cf.h"
 #include "util.h"
+#include "cached_error.h"
 
 #define  WAIS_DELETE_GAP  (64*1024)
 
@@ -54,26 +55,9 @@ void waisReadReplyTimeout(fd, data)
 
     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);
 }
 
@@ -86,26 +70,9 @@ void waisLifetimeExpire(fd, 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);
 }
 
@@ -141,25 +108,8 @@ void waisReadReply(fd, 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;
        }
@@ -179,26 +129,9 @@ void waisReadReply(fd, data)
            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. */
@@ -238,25 +171,8 @@ void waisSendComplete(fd, buf, size, errflag, data)
     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. */
@@ -314,25 +230,7 @@ int waisStart(unusedfd, url, type, mime_hdr, entry)
 
     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;
     }
@@ -345,24 +243,7 @@ int waisStart(unusedfd, url, type, mime_hdr, entry)
     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;
     }
@@ -372,24 +253,7 @@ int waisStart(unusedfd, url, type, mime_hdr, entry)
     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;
     }
@@ -397,24 +261,7 @@ int waisStart(unusedfd, url, type, mime_hdr, entry)
     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 {