/*
- * $Id: client_side.cc,v 1.135 1997/10/28 20:42:50 wessels Exp $
+ * $Id: client_side.cc,v 1.136 1997/10/30 02:40:57 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
} else {
debug(33, 5) ("Access Denied: %s\n", http->url);
redirectUrl = aclGetDenyInfoUrl(&Config.denyInfoList, AclMatchedName);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_ACCESS_DENIED;
- err->request = requestLink(http->request);
- err->src_addr = http->conn->peer.sin_addr;
if (redirectUrl) {
- err->http_status = HTTP_MOVED_TEMPORARILY;
+ err = errorCon(ERR_ACCESS_DENIED, HTTP_MOVED_TEMPORARILY);
+ err->request = requestLink(http->request);
+ err->src_addr = http->conn->peer.sin_addr;
err->redirect_url = xstrdup(redirectUrl);
+ errorSend(fd, err);
+
} else {
/* NOTE: don't use HTTP_UNAUTHORIZED because then the
* stupid browser wants us to authenticate */
- err->http_status = HTTP_FORBIDDEN;
+ err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN);
+ err->request = requestLink(http->request);
+ err->src_addr = http->conn->peer.sin_addr;
+ errorSend(fd, err);
}
- errorSend(fd, err);
}
}
ErrorState *err = NULL;
debug(33, 3) ("Config.onoff.enable_purge = %d\n", Config.onoff.enable_purge);
if (!Config.onoff.enable_purge) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_ACCESS_DENIED;
+ err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN);
err->request = requestLink(http->request);
err->src_addr = http->conn->peer.sin_addr;
- err->http_status = HTTP_FORBIDDEN;
errorSend(fd, err);
return;
}
/*
- * $Id: errorpage.cc,v 1.94 1997/10/30 00:51:04 wessels Exp $
+ * $Id: errorpage.cc,v 1.95 1997/10/30 02:40:58 wessels Exp $
*
* DEBUG: section 4 Error Generation
* AUTHOR: Duane Wessels
*
*/
+/*
+ * Abstract: These routines are used to generate error messages to be
+ * sent to clients. The error type is used to select between
+ * the various message formats. (formats are stored in the
+ * Config.errorDirectory)
+ */
+
#include "squid.h"
-const char *err_string[] =
+static const char *err_string[] =
{
"ERR_NONE",
"ERR_READ_TIMEOUT",
static char *error_text[ERR_MAX];
static void errorStateFree(ErrorState * err);
-static char *errorConvert(char token, ErrorState * err);
-static char *errorBuildBuf(ErrorState * err, int *len);
+static const char *errorConvert(char token, ErrorState * err);
+static const char *errorBuildBuf(ErrorState * err, int *len);
static CWCB errorSendComplete;
+/*
+ * Function: errorInitialize
+ *
+ * Abstract: This function reads in the error messages formats, and stores
+ * them in error_text[];
+ *
+ * Global effects:
+ * error_text[] - is modified
+ */
void
errorInitialize(void)
{
fatal("Failed to open error text file");
}
if (fstat(fd, &sb) < 0)
- fatal_dump("stat() failed on error text file");
+ fatal("fstat() failed on error text file");
safe_free(error_text[i]);
error_text[i] = xcalloc(sb.st_size + 1, 1);
if (read(fd, error_text[i], sb.st_size) != sb.st_size)
- fatal_dump("failed to fully read error text file");
+ fatal("failed to fully read error text file");
file_close(fd);
}
}
+/*
+ * Function: errorCon
+ *
+ * Abstract: This function creates a ErrorState object.
+ */
+ErrorState *
+errorCon(err_type type, http_status status)
+{
+ ErrorState *err = xcalloc(1, sizeof(ErrorState));
+ err->type = type;
+ err->http_status = status;
+ return err;
+}
+
+/*
+ * Function: errorAppendEntry
+ *
+ * Arguments: err - This object is destroyed after use in this function.
+ *
+ * Abstract: This function generates a error page from the info contained
+ * by 'err' and then attaches it to the specified 'entry'
+ *
+ * Note: The above abstract is should be check for correctness!!!!
+ */
+void
+errorAppendEntry(StoreEntry * entry, ErrorState * err)
+{
+ const char *buf;
+ MemObject *mem = entry->mem_obj;
+ int len;
+ assert(entry->store_status == STORE_PENDING);
+ buf = errorBuildBuf(err, &len);
+ storeAppend(entry, buf, len);
+ if (mem)
+ mem->reply->code = err->http_status;
+ errorStateFree(err);
+ xfree(err);
+}
+
+/*
+ * Function: errorSend
+ *
+ * Arguments: err - This object is destroyed after use in this function.
+ *
+ * Abstract: This function generates a error page from the info contained
+ * by 'err' and then sends it to the client.
+ *
+ * Note: The callback function errorSendComplete() cleans up 'err'
+ *
+ * Note: I don't think we need to add 'err' to the callback table
+ * since the only path ends up a errorSendComplete().
+ */
+void
+errorSend(int fd, ErrorState * err)
+{
+ const char *buf;
+ int len;
+ debug(4, 3) ("errorSend: FD %d, err=%p\n", fd, err);
+ assert(fd >= 0);
+ buf = errorBuildBuf(err, &len);
+ cbdataAdd(err);
+ comm_write(fd, xstrdup(buf), len, errorSendComplete, err, xfree);
+}
+
+/*
+ * Function: errorSendComplete
+ *
+ * Abstract: This function
+ *
+ * Note: If there is a callback, the callback is responsible for
+ * closeing the FD, otherwise we do it ourseves.
+ */
+static void
+errorSendComplete(int fd, char *buf, int size, int errflag, void *data)
+{
+ ErrorState *err = data;
+ debug(4, 3) ("errorSendComplete: FD %d, size=%d\n", fd, size);
+ if (errflag != COMM_ERR_CLOSING) {
+ if (err->callback)
+ err->callback(fd, err->callback_data, size);
+ else
+ comm_close(fd);
+ }
+ errorStateFree(err);
+ cbdataFree(err);
+}
+
static void
errorStateFree(ErrorState * err)
{
}
#define CVT_BUF_SZ 512
-static char *
+
+/*
+ * c - Squid error code
+ * d - seconds elapsed since request received
+ * e - errno x
+ * E - strerror() x
+ * F - FTP reply line x
+ * f - FTP request line x
+ * h - cache hostname x
+ * i - client IP address x
+ * I - server IP address x
+ * L - HREF link for more info/contact x
+ * M - Request Method x
+ * p - URL port # x
+ * P - Protocol x
+ * t - local time x
+ * T - UTC x
+ * w - cachemgr email address x
+ * z - dns server error message x
+ */
+
+static const char *
errorConvert(char token, ErrorState * err)
{
- char *p = NULL;
request_t *r = err->request;
static char buf[CVT_BUF_SZ];
+ const char *p = buf;
switch (token) {
- case 'U':
- p = r ? urlCanonicalClean(r) : err->url;
- break;
- case 'H':
- p = r ? r->host : "[unknown host]";
- break;
- case 'p':
- if (r) {
- snprintf(buf, CVT_BUF_SZ, "%d", (int) r->port);
- p = buf;
- } else {
- p = "[unknown port]";
- }
- break;
- case 'P':
- p = r ? (char *) ProtocolStr[r->protocol] : "[unkown protocol]";
- break;
- case 'M':
- p = r ? (char *) RequestMethodStr[r->method] : "[unkown method]";
- break;
- case 'z':
- if (err->dnsserver_msg)
- p = err->dnsserver_msg;
- else
- p = "UNKNOWN\n";
- break;
case 'e':
snprintf(buf, CVT_BUF_SZ, "%d", err->xerrno);
- p = buf;
break;
case 'E':
snprintf(buf, CVT_BUF_SZ, "(%d) %s", err->xerrno, strerror(err->xerrno));
- p = buf;
break;
- case 'w':
- if (Config.adminEmail) {
- snprintf(buf, CVT_BUF_SZ, "%s", Config.adminEmail);
- p = buf;
- } else
- p = "UNKNOWN";
+ case 'f':
+ /* FTP REQUEST LINE */
+ if (err->ftp.request)
+ p = err->ftp.request;
+ else
+ p = "<none>";
+ break;
+ case 'F':
+ /* FTP REPLY LINE */
+ if (err->ftp.request)
+ p = err->ftp.reply;
+ else
+ p = "<none>";
break;
case 'h':
snprintf(buf, CVT_BUF_SZ, "%s", getMyHostname());
- p = buf;
- break;
- case 't':
- xstrncpy(buf, mkhttpdlogtime(&squid_curtime), 128);
- p = buf;
break;
- case 'L':
- if (Config.errHtmlText) {
- snprintf(buf, CVT_BUF_SZ, "%s", Config.errHtmlText);
- p = buf;
- } else
- p = "[not available]";
+ case 'H':
+ p = r ? r->host : "[unknown host]";
break;
case 'i':
snprintf(buf, CVT_BUF_SZ, "%s", inet_ntoa(err->src_addr));
- p = buf;
break;
case 'I':
if (err->host) {
snprintf(buf, CVT_BUF_SZ, "%s", err->host);
- p = buf;
} else
- p = "unknown\n";
+ p = "[unknown]";
+ break;
+ case 'L':
+ if (Config.errHtmlText) {
+ snprintf(buf, CVT_BUF_SZ, "%s", Config.errHtmlText);
+ } else
+ p = "[not available]";
+ break;
+ case 'M':
+ p = r ? RequestMethodStr[r->method] : "[unkown method]";
+ break;
+ case 'p':
+ if (r) {
+ snprintf(buf, CVT_BUF_SZ, "%d", (int) r->port);
+ } else {
+ p = "[unknown port]";
+ }
+ break;
+ case 'P':
+ p = r ? ProtocolStr[r->protocol] : "[unkown protocol]";
+ break;
+ case 't':
+ xstrncpy(buf, mkhttpdlogtime(&squid_curtime), 128);
break;
case 'T':
snprintf(buf, CVT_BUF_SZ, "%s", mkrfc1123(squid_curtime));
- p = buf;
break;
- case 'f':
- /* FTP REQUEST LINE */
- if (err->ftp.request)
- p = err->ftp.request;
- else
- p = "<none>";
+ case 'U':
+ p = r ? urlCanonicalClean(r) : err->url;
break;
- case 'F':
- /* FTP REPLY LINE */
- if (err->ftp.request)
- p = err->ftp.reply;
+ case 'w':
+ if (Config.adminEmail) {
+ snprintf(buf, CVT_BUF_SZ, "%s", Config.adminEmail);
+ } else
+ p = "[unknown]";
+ break;
+ case 'z':
+ if (err->dnsserver_msg)
+ p = err->dnsserver_msg;
else
- p = "<none>";
+ p = "[unknown]";
break;
-/*
- * e - errno x
- * E - strerror() x
- * t - local time x
- * T - UTC x
- * c - Squid error code
- * I - server IP address x
- * i - client IP address x
- * L - HREF link for more info/contact x
- * w - cachemgr email address x
- * h - cache hostname x
- * d - seconds elapsed since request received
- * p - URL port # x
- * f - FTP request line x
- * F - FTP reply line x
- */
default:
p = "%UNKNOWN%";
break;
return p;
}
-static char *
+static const char *
errorBuildBuf(ErrorState * err, int *len)
{
LOCAL_ARRAY(char, buf, ERROR_BUF_SZ);
char *m;
char *mx;
char *p;
- char *t;
+ const char *t;
assert(err != NULL);
assert(err->type > ERR_NONE && err->type < ERR_MAX);
mx = m = xstrdup(error_text[err->type]);
xfree(mx);
return buf;
}
-
-void
-errorSend(int fd, ErrorState * err)
-{
- char *buf;
- int len;
- debug(4, 3) ("errorSend: FD %d, err=%p\n", fd, err);
- assert(fd >= 0);
- buf = errorBuildBuf(err, &len);
- cbdataAdd(err);
- cbdataLock(err);
- BIT_SET(err->flags, ERR_FLAG_CBDATA);
- comm_write(fd, xstrdup(buf), len, errorSendComplete, err, xfree);
-}
-
-void
-errorAppendEntry(StoreEntry * entry, ErrorState * err)
-{
- char *buf;
- MemObject *mem = entry->mem_obj;
- int len;
- assert(entry->store_status == STORE_PENDING);
- buf = errorBuildBuf(err, &len);
- storeAppend(entry, buf, len);
- if (mem)
- mem->reply->code = err->http_status;
- errorStateFree(err);
-}
-
-/* If there is a callback, the callback is responsible to close
- * the FD, otherwise we do it ourseves. */
-static void
-errorSendComplete(int fd, char *buf, int size, int errflag, void *data)
-{
- ErrorState *err = data;
- debug(4, 3) ("errorSendComplete: FD %d, size=%d\n", fd, size);
- if (errflag != COMM_ERR_CLOSING) {
- if (err->callback)
- err->callback(fd, err->callback_data, size);
- else
- comm_close(fd);
- }
- cbdataUnlock(err);
- errorStateFree(err);
-}
/*
- * $Id: fqdncache.cc,v 1.63 1997/10/29 15:18:20 wessels Exp $
+ * $Id: fqdncache.cc,v 1.64 1997/10/30 02:40:59 wessels Exp $
*
* DEBUG: section 35 FQDN Cache
* AUTHOR: Harvest Derived
{
char *name = inet_ntoa(addr);
fqdncache_entry *f = NULL;
- const struct hostent *hp = NULL;
struct in_addr ip;
- static char *static_name = NULL;
if (!name)
fatal_dump("fqdncache_gethostbyaddr: NULL name");
/*
- * $Id: ftp.cc,v 1.157 1997/10/30 00:47:48 wessels Exp $
+ * $Id: ftp.cc,v 1.158 1997/10/30 02:40:59 wessels Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
debug(9, 4) ("ftpTimeout: FD %d: '%s'\n", fd, entry->url);
if (entry->store_status == STORE_PENDING) {
if (entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_TIMEOUT;
- err->http_status = HTTP_GATEWAY_TIMEOUT;
+ err = errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT);
err->request = requestLink(ftpState->request);
errorAppendEntry(entry, err);
}
commSetSelect(fd, COMM_SELECT_READ, ftpReadData, data, Config.Timeout.read);
} else {
if (entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_ERROR;
+ err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
err->request = requestLink(ftpState->request);
errorAppendEntry(entry, err);
}
ftpDataTransferDone(ftpState);
}
} else if (len == 0 && entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_ZERO_SIZE_OBJECT;
+ err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
err->request = requestLink(ftpState->request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
ftpDataTransferDone(ftpState);
} else if (len == 0) {
url);
if (fd == COMM_ERROR) {
debug(9, 4) ("ftpStart: Failed to open a socket.\n");
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_SOCKET_FAILURE;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+
+ err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
err->request = requestLink(ftpState->request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
return;
}
debug(9, 3) ("ftpConnectDone, status = %d\n", status);
if (status == COMM_ERR_DNS) {
debug(9, 4) ("ftpConnectDone: Unknown host: %s\n", request->host);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_DNS_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+
+ err = errorCon(ERR_DNS_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->dnsserver_msg = xstrdup(dns_error_message);
err->request = requestLink(request);
errorAppendEntry(ftpState->entry, err);
+
storeAbort(ftpState->entry, 0);
comm_close(fd);
} else if (status != COMM_OK) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(request->host);
err->port = request->port;
err->request = requestLink(request);
errorAppendEntry(ftpState->entry, err);
+
storeAbort(ftpState->entry, 0);
comm_close(fd);
} else {
if (errflag) {
debug(50, 1) ("ftpWriteCommandCallback: FD %d: %s\n", fd, xstrerror());
if (entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_WRITE_ERROR;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ err = errorCon(ERR_WRITE_ERROR, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->request = requestLink(ftpState->request);
errorAppendEntry(entry, err);
Config.Timeout.read);
} else {
if (entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_ERROR;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+ err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
err->request = requestLink(ftpState->request);
errorAppendEntry(entry, err);
if (entry->store_status == STORE_PENDING) {
storeReleaseRequest(entry);
if (entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_ERROR;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+ err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
err->request = requestLink(ftpState->request);
errorAppendEntry(entry, err);
ErrorState *err;
debug(9, 3) ("ftpPasvCallback\n");
if (status != COMM_OK) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(ftpState->data.host);
err->port = ftpState->data.port;
err->request = requestLink(request);
errorAppendEntry(ftpState->entry, err);
+
storeAbort(ftpState->entry, 0);
comm_close(fd);
return;
/*
- * $Id: gopher.cc,v 1.108 1997/10/28 21:59:06 wessels Exp $
+ * $Id: gopher.cc,v 1.109 1997/10/30 02:41:01 wessels Exp $
*
* DEBUG: section 10 Gopher
* AUTHOR: Harvest Derived
ErrorState *err;
debug(10, 4) ("gopherTimeout: FD %d: '%s'\n", fd, entry->url);
if (entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_TIMEOUT;
- err->http_status = HTTP_GATEWAY_TIMEOUT;
+ err = errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT);
err->url = xstrdup(gopherState->request);
errorAppendEntry(entry, err);
}
} else {
/* was assert */
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_ERROR;
+ err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
err->url = xstrdup(entry->url);
errorAppendEntry(entry, err);
storeAbort(entry, 0);
}
} else if (len == 0 && entry->mem_obj->inmem_hi == 0) {
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_ZERO_SIZE_OBJECT;
+ err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
err->url = xstrdup(gopherState->request);
errorAppendEntry(entry, err);
storeAbort(entry, 0);
fd, size, errflag);
if (errflag) {
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(gopherState->host);
err->port = gopherState->port;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
err->url = xstrdup(entry->url);
errorAppendEntry(entry, err);
if (gopher_url_parser(entry->url, gopherState->host, &gopherState->port,
&gopherState->type_id, gopherState->request)) {
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_INVALID_URL;
- err->http_status = HTTP_BAD_REQUEST;
+ err = errorCon(ERR_INVALID_URL, HTTP_BAD_REQUEST);
err->url = xstrdup(entry->url);
errorAppendEntry(entry, err);
storeAbort(entry, 0);
entry->url);
if (fd == COMM_ERROR) {
debug(10, 4) ("gopherStart: Failed because we're out of sockets.\n");
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_SOCKET_FAILURE;
+ err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
err->url = xstrdup(entry->url);
errorAppendEntry(entry, err);
storeAbort(entry, 0);
ErrorState *err;
if (status == COMM_ERR_DNS) {
debug(10, 4) ("gopherConnectDone: Unknown host: %s\n", gopherState->host);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_DNS_FAIL;
+ err = errorCon(ERR_DNS_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->dnsserver_msg = xstrdup(dns_error_message);
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
err->url = xstrdup(entry->url);
errorAppendEntry(entry, err);
storeAbort(gopherState->entry, 0);
comm_close(fd);
} else if (status != COMM_OK) {
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(gopherState->host);
err->port = gopherState->port;
/*
- * $Id: http.cc,v 1.206 1997/10/28 21:59:08 wessels Exp $
+ * $Id: http.cc,v 1.207 1997/10/30 02:41:02 wessels Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
debug(11, 4) ("httpTimeout: FD %d: '%s'\n", fd, entry->url);
assert(entry->store_status == STORE_PENDING);
if (entry->mem_obj->inmem_hi == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_TIMEOUT;
- err->http_status = HTTP_GATEWAY_TIMEOUT;
+ err = errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT);
err->request = requestLink(httpState->request);
errorAppendEntry(entry, err);
}
commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0);
} else {
if (clen == 0) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_ERROR;
+ err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
err->request = requestLink(httpState->request);
errorAppendEntry(entry, err);
}
httpRestart(httpState);
} else {
httpState->eof = 1;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_ZERO_SIZE_OBJECT;
+
+ err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
err->request = requestLink(httpState->request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
comm_close(fd);
}
if (errflag == COMM_ERR_CLOSING)
return;
if (errflag) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_WRITE_ERROR;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+ err = errorCon(ERR_WRITE_ERROR, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
err->request = requestLink(httpState->request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
comm_close(fd);
return;
entry->url);
if (fd < 0) {
debug(11, 4) ("httpSocketOpen: Failed because we're out of sockets.\n");
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_SOCKET_FAILURE;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+
+ err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
if (request)
err->request = requestLink(request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
}
return fd;
ErrorState *err;
if (status == COMM_ERR_DNS) {
debug(11, 4) ("httpConnectDone: Unknown host: %s\n", request->host);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_DNS_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+
+ err = errorCon(ERR_DNS_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->dnsserver_msg = xstrdup(dns_error_message);
err->request = requestLink(request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
comm_close(fd);
} else if (status != COMM_OK) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(request->host);
err->port = request->port;
err->request = requestLink(request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
if (httpState->neighbor)
peerCheckConnectStart(httpState->neighbor);
/*
- * $Id: ipcache.cc,v 1.139 1997/10/28 20:42:53 wessels Exp $
+ * $Id: ipcache.cc,v 1.140 1997/10/30 02:41:04 wessels Exp $
*
* DEBUG: section 14 IP Cache
* AUTHOR: Harvest Derived
{
ipcache_entry *i = NULL;
ipcache_addrs *addrs;
- const struct hostent *hp;
if (!name)
fatal_dump("ipcache_gethostbyname: NULL name");
/*
- * $Id: pconn.cc,v 1.7 1997/10/26 02:35:36 wessels Exp $
+ * $Id: pconn.cc,v 1.8 1997/10/30 02:41:06 wessels Exp $
*
* DEBUG: section 48 Persistent Connections
* AUTHOR: Duane Wessels
pconnPush(int fd, const char *host, u_short port)
{
struct _pconn *p;
- LOCAL_ARRAY(char, key, SQUIDHOSTNAMELEN + 10);
+ LOCAL_ARRAY(char, key, SQUIDHOSTNAMELEN + 10); /* MO why static array? */
assert(table != NULL);
strcpy(key, pconnKey(host, port));
p = (struct _pconn *) hash_lookup(table, key);
struct _pconn *p;
hash_link *hptr;
int fd = -1;
- LOCAL_ARRAY(char, key, SQUIDHOSTNAMELEN + 10);
+ LOCAL_ARRAY(char, key, SQUIDHOSTNAMELEN + 10); /* MO why static array? */
assert(table != NULL);
strcpy(key, pconnKey(host, port));
hptr = hash_lookup(table, key);
extern void errorSend(int fd, ErrorState *);
extern void errorAppendEntry(StoreEntry *, ErrorState *);
extern void errorInitialize(void);
+extern ErrorState *errorCon(err_type, http_status);
extern OBJH stat_io_get;
extern OBJH stat_objects_get;
extern void pconnPush(int, const char *host, u_short port);
extern int pconnPop(const char *host, u_short port);
extern void pconnInit(void);
+
/*
- * $Id: ssl.cc,v 1.65 1997/10/25 17:22:58 wessels Exp $
+ * $Id: ssl.cc,v 1.66 1997/10/30 02:41:08 wessels Exp $
*
* DEBUG: section 26 Secure Sockets Layer Proxy
* AUTHOR: Duane Wessels
ErrorState *err = NULL;
if (status == COMM_ERR_DNS) {
debug(26, 4) ("sslConnect: Unknown host: %s\n", sslState->host);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_DNS_FAIL;
- err->http_status = HTTP_NOT_FOUND;
+
+ err = errorCon(ERR_DNS_FAIL, HTTP_NOT_FOUND);
err->request = requestLink(request);
err->dnsserver_msg = xstrdup(dns_error_message);
err->callback = sslErrorComplete;
err->callback_data = sslState;
errorSend(sslState->client.fd, err);
- return;
+
} else if (status != COMM_OK) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(sslState->host);
err->port = sslState->port;
err->callback = sslErrorComplete;
err->callback_data = sslState;
errorSend(sslState->client.fd, err);
- return;
+
+ } else {
+ if (sslState->proxying)
+ sslProxyConnected(sslState->server.fd, sslState);
+ else
+ sslConnected(sslState->server.fd, sslState);
}
- if (sslState->proxying)
- sslProxyConnected(sslState->server.fd, sslState);
- else
- sslConnected(sslState->server.fd, sslState);
}
void
url);
if (sock == COMM_ERROR) {
debug(26, 4) ("sslStart: Failed because we're out of sockets.\n");
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_SOCKET_FAILURE;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+
+ err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
err->request = requestLink(request);
errorSend(fd, err);
sslPeerSelectFail(peer * p, void *data)
{
SslStateData *sslState = data;
- ErrorState *err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CANNOT_FORWARD;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ ErrorState *err;
+
+ err = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE);
err->request = requestLink(sslState->request);
err->callback = sslErrorComplete;
err->callback_data = sslState;
/*
- * $Id: tunnel.cc,v 1.65 1997/10/25 17:22:58 wessels Exp $
+ * $Id: tunnel.cc,v 1.66 1997/10/30 02:41:08 wessels Exp $
*
* DEBUG: section 26 Secure Sockets Layer Proxy
* AUTHOR: Duane Wessels
ErrorState *err = NULL;
if (status == COMM_ERR_DNS) {
debug(26, 4) ("sslConnect: Unknown host: %s\n", sslState->host);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_DNS_FAIL;
- err->http_status = HTTP_NOT_FOUND;
+
+ err = errorCon(ERR_DNS_FAIL, HTTP_NOT_FOUND);
err->request = requestLink(request);
err->dnsserver_msg = xstrdup(dns_error_message);
err->callback = sslErrorComplete;
err->callback_data = sslState;
errorSend(sslState->client.fd, err);
- return;
+
} else if (status != COMM_OK) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(sslState->host);
err->port = sslState->port;
err->callback = sslErrorComplete;
err->callback_data = sslState;
errorSend(sslState->client.fd, err);
- return;
+
+ } else {
+ if (sslState->proxying)
+ sslProxyConnected(sslState->server.fd, sslState);
+ else
+ sslConnected(sslState->server.fd, sslState);
}
- if (sslState->proxying)
- sslProxyConnected(sslState->server.fd, sslState);
- else
- sslConnected(sslState->server.fd, sslState);
}
void
url);
if (sock == COMM_ERROR) {
debug(26, 4) ("sslStart: Failed because we're out of sockets.\n");
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_SOCKET_FAILURE;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+
+ err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
err->xerrno = errno;
err->request = requestLink(request);
errorSend(fd, err);
sslPeerSelectFail(peer * p, void *data)
{
SslStateData *sslState = data;
- ErrorState *err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CANNOT_FORWARD;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ ErrorState *err;
+
+ err = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE);
err->request = requestLink(sslState->request);
err->callback = sslErrorComplete;
err->callback_data = sslState;
/*
- * $Id: wais.cc,v 1.92 1997/10/28 21:59:14 wessels Exp $
+ * $Id: wais.cc,v 1.93 1997/10/30 02:41:09 wessels Exp $
*
* DEBUG: section 24 WAIS Relay
* AUTHOR: Harvest Derived
ErrorState *err;
StoreEntry *entry = waisState->entry;
debug(24, 4) ("waisTimeout: FD %d: '%s'\n", fd, entry->url);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_TIMEOUT;
- err->http_status = HTTP_GATEWAY_TIMEOUT;
+ err = errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT);
err->request = urlParse(METHOD_CONNECT, waisState->request);
errorAppendEntry(entry, err);
storeAbort(entry, 0);
int bin;
if (protoAbortFetch(entry)) {
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CLIENT_ABORT;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+
+ err = errorCon(ERR_CLIENT_ABORT, HTTP_INTERNAL_SERVER_ERROR);
err->request = urlParse(METHOD_CONNECT, waisState->request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
comm_close(fd);
return;
ErrorState *err;
BIT_CLR(entry->flag, ENTRY_CACHABLE);
storeReleaseRequest(entry);
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_READ_ERROR;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+ err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR);
+ err->xerrno = errno;
err->request = urlParse(METHOD_CONNECT, waisState->request);
errorAppendEntry(entry, err);
}
} else if (len == 0 && entry->mem_obj->inmem_hi == 0) {
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_ZERO_SIZE_OBJECT;
+ err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
err->request = urlParse(METHOD_CONNECT, waisState->request);
errorAppendEntry(entry, err);
+
storeAbort(entry, 0);
comm_close(fd);
} else if (len == 0) {
return;
if (errflag) {
ErrorState *err;
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(waisState->relayhost);
err->port = waisState->relayport;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
err->request = urlParse(METHOD_CONNECT, waisState->request);
errorAppendEntry(entry, err);
storeAbort(entry, 0);
if (!Config.Wais.relayHost) {
ErrorState *err;
debug(24, 0) ("waisStart: Failed because no relay host defined!\n");
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_NO_RELAY;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+ err = errorCon(ERR_NO_RELAY, HTTP_INTERNAL_SERVER_ERROR);
err->request = urlParse(METHOD_CONNECT, waisState->request);
errorAppendEntry(entry, err);
if (fd == COMM_ERROR) {
ErrorState *err;
debug(24, 4) ("waisStart: Failed because we're out of sockets.\n");
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_SOCKET_FAILURE;
- err->http_status = HTTP_INTERNAL_SERVER_ERROR;
+ err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR);
err->request = urlParse(METHOD_CONNECT, waisState->request);
errorAppendEntry(entry, err);
storeAbort(entry, 0);
ErrorState *err;
if (status == COMM_ERR_DNS) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_DNS_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ err = errorCon(ERR_DNS_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->dnsserver_msg = xstrdup(dns_error_message);
err->request = urlParse(METHOD_CONNECT, request);
errorAppendEntry(waisState->entry, err);
storeAbort(waisState->entry, 0);
comm_close(fd);
} else if (status != COMM_OK) {
- err = xcalloc(1, sizeof(ErrorState));
- err->type = ERR_CONNECT_FAIL;
- err->http_status = HTTP_SERVICE_UNAVAILABLE;
+ err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE);
err->xerrno = errno;
err->host = xstrdup(waisState->relayhost);
err->port = waisState->relayport;