From: Amos Jeffries Date: Tue, 29 Nov 2011 06:52:23 +0000 (-0700) Subject: SourceLayout: ErrorState constructor/destructor X-Git-Tag: SQUID_3_2_0_14~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0e927fa4fed127915d3ed6681ae2f403695a267;p=thirdparty%2Fsquid.git SourceLayout: ErrorState constructor/destructor --- diff --git a/src/Server.cc b/src/Server.cc index 903e3a2134..be3ad71a12 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -380,7 +380,7 @@ ServerStateData::sentRequestBody(const CommIoCbParams &io) if (io.flag) { debugs(11, 1, "sentRequestBody error: FD " << io.fd << ": " << xstrerr(io.xerrno)); ErrorState *err; - err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request); + err = new ErrorState(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request); err->xerrno = io.xerrno; fwd->fail(err); abortTransaction("I/O error while sending request body"); @@ -830,7 +830,7 @@ ServerStateData::handleAdaptationAborted(bool bypassable) if (entry->isEmpty()) { debugs(11,9, HERE << "creating ICAP error entry after ICAP failure"); - ErrorState *err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, request); + ErrorState *err = new ErrorState(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, request); err->xerrno = ERR_DETAIL_ICAP_RESPMOD_EARLY; fwd->fail(err); fwd->dontRetry(true); @@ -864,7 +864,7 @@ ServerStateData::handleAdaptationBlocked(const Adaptation::Answer &answer) if (page_id == ERR_NONE) page_id = ERR_ACCESS_DENIED; - ErrorState *err = errorCon(page_id, HTTP_FORBIDDEN, request); + ErrorState *err = new ErrorState(page_id, HTTP_FORBIDDEN, request); err->xerrno = ERR_DETAIL_RESPMOD_BLOCK_EARLY; fwd->fail(err); fwd->dontRetry(true); @@ -903,7 +903,7 @@ ServerStateData::noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer grou void ServerStateData::sendBodyIsTooLargeError() { - ErrorState *err = errorCon(ERR_TOO_BIG, HTTP_FORBIDDEN, request); + ErrorState *err = new ErrorState(ERR_TOO_BIG, HTTP_FORBIDDEN, request); err->xerrno = errno; fwd->fail(err); fwd->dontRetry(true); diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 08492cd9c6..1197a7adac 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -320,12 +320,11 @@ CacheManager::CheckPassword(const Mgr::Command &cmd) void CacheManager::Start(const Comm::ConnectionPointer &client, HttpRequest * request, StoreEntry * entry) { - ErrorState *err = NULL; debugs(16, 3, "CacheManager::Start: '" << entry->url() << "'" ); Mgr::Command::Pointer cmd = ParseUrl(entry->url()); if (!cmd) { - err = errorCon(ERR_INVALID_URL, HTTP_NOT_FOUND, request); + ErrorState *err = new ErrorState(ERR_INVALID_URL, HTTP_NOT_FOUND, request); err->url = xstrdup(entry->url()); errorAppendEntry(entry, err); entry->expires = squid_curtime; @@ -348,9 +347,7 @@ CacheManager::Start(const Comm::ConnectionPointer &client, HttpRequest * request if (CheckPassword(*cmd) != 0) { /* build error message */ - ErrorState *errState; - HttpReply *rep; - errState = errorCon(ERR_CACHE_MGR_ACCESS_DENIED, HTTP_UNAUTHORIZED, request); + ErrorState errState(ERR_CACHE_MGR_ACCESS_DENIED, HTTP_UNAUTHORIZED, request); /* warn if user specified incorrect password */ if (cmd->params.password.size()) { @@ -365,9 +362,7 @@ CacheManager::Start(const Comm::ConnectionPointer &client, HttpRequest * request actionName << "'" ); } - rep = errState->BuildHttpReply(); - - errorStateFree(errState); + HttpReply *rep = errState.BuildHttpReply(); #if HAVE_AUTH_MODULE_BASIC /* diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 0014fa07cd..6577c8755d 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -2193,7 +2193,7 @@ ErrorState * clientBuildError(err_type page_id, http_status status, char const *url, Ip::Address &src_addr, HttpRequest * request) { - ErrorState *err = errorCon(page_id, status, request); + ErrorState *err = new ErrorState(page_id, status, request); err->src_addr = src_addr; if (url) diff --git a/src/errorpage.cc b/src/errorpage.cc index 22391ce338..c6afacb569 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -557,24 +557,41 @@ errorPageName(int pageId) return "ERR_UNKNOWN"; /* should not happen */ } -ErrorState * -errorCon(err_type type, http_status status, HttpRequest * request) +ErrorState::ErrorState(err_type t, http_status status, HttpRequest * req) : + type(t), + page_id(t), + err_language(NULL), + httpStatus(status), +#if USE_AUTH + auth_user_request (NULL), +#endif + request(NULL), + url(NULL), + xerrno(0), + port(0), + dnsError(), + ttl(0), + src_addr(), + redirect_url(NULL), + callback(NULL), + callback_data(NULL), + request_hdrs(NULL), + err_msg(NULL) +#if USE_SSL + , detail(NULL) +#endif { - ErrorState *err = new ErrorState; - err->page_id = type; /* has to be reset manually if needed */ - err->err_language = NULL; - err->type = type; - err->httpStatus = status; - if (err->page_id >= ERR_MAX && ErrorDynamicPages.items[err->page_id - ERR_MAX]->page_redirect != HTTP_STATUS_NONE) - err->httpStatus = ErrorDynamicPages.items[err->page_id - ERR_MAX]->page_redirect; - - if (request != NULL) { - err->request = HTTPMSGLOCK(request); - err->src_addr = request->client_addr; + memset(&flags, 0, sizeof(flags)); + memset(&ftp, 0, sizeof(ftp)); + + if (page_id >= ERR_MAX && ErrorDynamicPages.items[page_id - ERR_MAX]->page_redirect != HTTP_STATUS_NONE) + httpStatus = ErrorDynamicPages.items[page_id - ERR_MAX]->page_redirect; + + if (req != NULL) { + request = HTTPMSGLOCK(req); + src_addr = req->client_addr; request->detailError(type, ERR_DETAIL_NONE); } - - return err; } void @@ -595,7 +612,7 @@ errorAppendEntry(StoreEntry * entry, ErrorState * err) */ assert(EBIT_TEST(entry->flags, ENTRY_ABORTED)); assert(entry->mem_obj->nclients == 0); - errorStateFree(err); + delete err; return; } @@ -615,7 +632,7 @@ errorAppendEntry(StoreEntry * entry, ErrorState * err) entry->negativeCache(); entry->releaseRequest(); entry->unlock(); - errorStateFree(err); + delete err; } void @@ -671,31 +688,29 @@ errorSendComplete(const Comm::ConnectionPointer &conn, char *bufnotused, size_t } } - errorStateFree(err); + delete err; } -void -errorStateFree(ErrorState * err) +ErrorState::~ErrorState() { - HTTPMSGUNLOCK(err->request); - safe_free(err->redirect_url); - safe_free(err->url); - safe_free(err->request_hdrs); - wordlistDestroy(&err->ftp.server_msg); - safe_free(err->ftp.request); - safe_free(err->ftp.reply); + HTTPMSGUNLOCK(request); + safe_free(redirect_url); + safe_free(url); + safe_free(request_hdrs); + wordlistDestroy(&ftp.server_msg); + safe_free(ftp.request); + safe_free(ftp.reply); #if USE_AUTH - err->auth_user_request = NULL; + auth_user_request = NULL; #endif - safe_free(err->err_msg); + safe_free(err_msg); #if USE_ERR_LOCALES - if (err->err_language != Config.errorDefaultLanguage) + if (err_language != Config.errorDefaultLanguage) #endif - safe_free(err->err_language); + safe_free(err_language); #if USE_SSL - delete err->detail; + delete detail; #endif - cbdataFree(err); } int diff --git a/src/errorpage.h b/src/errorpage.h index 5d76575e80..9c9102adb5 100644 --- a/src/errorpage.h +++ b/src/errorpage.h @@ -95,6 +95,10 @@ class MemBuf; class ErrorState { public: + ErrorState(err_type type, http_status, HttpRequest * request); + ErrorState(); // not implemented. + ~ErrorState(); + /** * Allocates and initializes an error response */ @@ -236,18 +240,9 @@ SQUIDCEXTERN void errorSend(const Comm::ConnectionPointer &conn, ErrorState *err */ SQUIDCEXTERN void errorAppendEntry(StoreEntry *entry, ErrorState *err); -/// \ingroup ErrorPageAPI -SQUIDCEXTERN void errorStateFree(ErrorState * err); - /// \ingroup ErrorPageAPI SQUIDCEXTERN err_type errorReservePageId(const char *page_name); -/** - \ingroup ErrorPageAPI - * - * This function creates a ErrorState object. - */ -SQUIDCEXTERN ErrorState *errorCon(err_type type, http_status, HttpRequest * request); SQUIDCEXTERN const char *errorPageName(int pageId); ///< error ID to string /** diff --git a/src/forward.cc b/src/forward.cc index c721013790..5e69efb06f 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -184,8 +184,7 @@ FwdState::~FwdState() HTTPMSGUNLOCK(request); - if (err) - errorStateFree(err); + delete err; entry->unregisterAbort(); @@ -238,10 +237,8 @@ FwdState::fwdStart(const Comm::ConnectionPointer &clientConn, StoreEntry *entry, if (page_id == ERR_NONE) page_id = ERR_FORWARDING_DENIED; - ErrorState *anErr = errorCon(page_id, HTTP_FORBIDDEN, request); - + ErrorState *anErr = new ErrorState(page_id, HTTP_FORBIDDEN, request); errorAppendEntry(entry, anErr); // frees anErr - return; } } @@ -259,7 +256,7 @@ FwdState::fwdStart(const Comm::ConnectionPointer &clientConn, StoreEntry *entry, if (shutting_down) { /* more yuck */ - ErrorState *anErr = errorCon(ERR_SHUTTING_DOWN, HTTP_SERVICE_UNAVAILABLE, request); + ErrorState *anErr = new ErrorState(ERR_SHUTTING_DOWN, HTTP_SERVICE_UNAVAILABLE, request); errorAppendEntry(entry, anErr); // frees anErr return; } @@ -295,10 +292,8 @@ FwdState::startConnectionOrFail() if (serverDestinations.size() > 0) { // Ditch error page if it was created before. // A new one will be created if there's another problem - if (err) { - errorStateFree(err); - err = NULL; - } + delete err; + err = NULL; // Update the logging information about this new server connection. // Done here before anything else so the errors get logged for @@ -310,8 +305,7 @@ FwdState::startConnectionOrFail() } else { debugs(17, 3, HERE << "Connection failed: " << entry->url()); if (!err) { - ErrorState *anErr = NULL; - anErr = errorCon(ERR_CANNOT_FORWARD, HTTP_INTERNAL_SERVER_ERROR, request); + ErrorState *anErr = new ErrorState(ERR_CANNOT_FORWARD, HTTP_INTERNAL_SERVER_ERROR, request); anErr->xerrno = errno; fail(anErr); } // else use actual error from last connection attempt @@ -324,9 +318,7 @@ FwdState::fail(ErrorState * errorState) { debugs(17, 3, HERE << err_type_str[errorState->type] << " \"" << httpStatusString(errorState->httpStatus) << "\"\n\t" << entry->url() ); - if (err) - errorStateFree(err); - + delete err; err = errorState; if (!errorState->request) @@ -551,7 +543,7 @@ FwdState::retryOrBail() doneWithRetries(); if (self != NULL && !err && shutting_down) { - ErrorState *anErr = errorCon(ERR_SHUTTING_DOWN, HTTP_SERVICE_UNAVAILABLE, request); + ErrorState *anErr = new ErrorState(ERR_SHUTTING_DOWN, HTTP_SERVICE_UNAVAILABLE, request); errorAppendEntry(entry, anErr); } @@ -677,7 +669,7 @@ FwdState::initiateSSL() if ((ssl = SSL_new(sslContext)) == NULL) { debugs(83, 1, "fwdInitiateSSL: Error allocating handle: " << ERR_error_string(ERR_get_error(), NULL) ); - ErrorState *anErr = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR, request); + ErrorState *anErr = new ErrorState(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR, request); anErr->xerrno = errno; fail(anErr); self = NULL; // refcounted @@ -775,7 +767,7 @@ FwdState::connectTimeout(int fd) assert(fd == serverDestinations[0]->fd); if (entry->isEmpty()) { - ErrorState *anErr = errorCon(ERR_CONNECT_FAIL, HTTP_GATEWAY_TIMEOUT, request); + ErrorState *anErr = new ErrorState(ERR_CONNECT_FAIL, HTTP_GATEWAY_TIMEOUT, request); anErr->xerrno = ETIMEDOUT; fail(anErr); @@ -823,7 +815,7 @@ FwdState::connectStart() if (serverDestinations[0]->getPeer() && request->flags.sslBumped == true) { debugs(50, 4, "fwdConnectStart: Ssl bumped connections through parrent proxy are not allowed"); - ErrorState *anErr = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE, request); + ErrorState *anErr = new ErrorState(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE, request); fail(anErr); self = NULL; // refcounted return; @@ -1006,7 +998,7 @@ FwdState::dispatch() default: debugs(17, 1, "fwdDispatch: Cannot retrieve '" << entry->url() << "'" ); - ErrorState *anErr = errorCon(ERR_UNSUP_REQ, HTTP_BAD_REQUEST, request); + ErrorState *anErr = new ErrorState(ERR_UNSUP_REQ, HTTP_BAD_REQUEST, request); fail(anErr); /* * Force a persistent connection to be closed because @@ -1089,8 +1081,8 @@ FwdState::reforward() ErrorState * FwdState::makeConnectingError(const err_type type) const { - return errorCon(type, request->flags.need_validation ? - HTTP_GATEWAY_TIMEOUT : HTTP_SERVICE_UNAVAILABLE, request); + return new ErrorState(type, request->flags.need_validation ? + HTTP_GATEWAY_TIMEOUT : HTTP_SERVICE_UNAVAILABLE, request); } static void diff --git a/src/ftp.cc b/src/ftp.cc index 8b8e70d0b1..7fdc67bba6 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1897,16 +1897,16 @@ FtpStateData::loginFailed() if ((state == SENT_USER || state == SENT_PASS) && ctrl.replycode >= 400) { if (ctrl.replycode == 421 || ctrl.replycode == 426) { // 421/426 - Service Overload - retry permitted. - err = errorCon(ERR_FTP_UNAVAILABLE, HTTP_SERVICE_UNAVAILABLE, fwd->request); + err = new ErrorState(ERR_FTP_UNAVAILABLE, HTTP_SERVICE_UNAVAILABLE, fwd->request); } else if (ctrl.replycode >= 430 && ctrl.replycode <= 439) { // 43x - Invalid or Credential Error - retry challenge required. - err = errorCon(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request); + err = new ErrorState(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request); } else if (ctrl.replycode >= 530 && ctrl.replycode <= 539) { // 53x - Credentials Missing - retry challenge required if (password_url) // but they were in the URI! major fail. - err = errorCon(ERR_FTP_FORBIDDEN, HTTP_FORBIDDEN, fwd->request); + err = new ErrorState(ERR_FTP_FORBIDDEN, HTTP_FORBIDDEN, fwd->request); else - err = errorCon(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request); + err = new ErrorState(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request); } } @@ -1941,7 +1941,7 @@ FtpStateData::loginFailed() HttpReply *newrep = err->BuildHttpReply(); - errorStateFree(err); + delete err; #if HAVE_AUTH_MODULE_BASIC /* add Authenticate header */ @@ -3263,13 +3263,12 @@ FtpStateData::completedListing() { assert(entry); entry->lock(); - ErrorState *ferr = errorCon(ERR_DIR_LISTING, HTTP_OK, request); - ferr->ftp.listing = &listing; - ferr->ftp.cwd_msg = xstrdup(cwd_message.size()? cwd_message.termedBuf() : ""); - ferr->ftp.server_msg = ctrl.message; + ErrorState ferr(ERR_DIR_LISTING, HTTP_OK, request); + ferr.ftp.listing = &listing; + ferr.ftp.cwd_msg = xstrdup(cwd_message.size()? cwd_message.termedBuf() : ""); + ferr.ftp.server_msg = ctrl.message; ctrl.message = NULL; - entry->replaceHttpReply( ferr->BuildHttpReply() ); - errorStateFree(ferr); + entry->replaceHttpReply( ferr.BuildHttpReply() ); EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT); entry->flush(); entry->unlock(); @@ -3471,12 +3470,10 @@ FtpStateData::failed(err_type error, int xerrno) void FtpStateData::failedErrorMessage(err_type error, int xerrno) { - ErrorState *ftperr; + ErrorState *ftperr = NULL; const char *command, *reply; /* Translate FTP errors into HTTP errors */ - ftperr = NULL; - switch (error) { case ERR_NONE: @@ -3489,12 +3486,12 @@ FtpStateData::failedErrorMessage(err_type error, int xerrno) if (ctrl.replycode > 500) if (password_url) - ftperr = errorCon(ERR_FTP_FORBIDDEN, HTTP_FORBIDDEN, fwd->request); + ftperr = new ErrorState(ERR_FTP_FORBIDDEN, HTTP_FORBIDDEN, fwd->request); else - ftperr = errorCon(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request); + ftperr = new ErrorState(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request); else if (ctrl.replycode == 421) - ftperr = errorCon(ERR_FTP_UNAVAILABLE, HTTP_SERVICE_UNAVAILABLE, fwd->request); + ftperr = new ErrorState(ERR_FTP_UNAVAILABLE, HTTP_SERVICE_UNAVAILABLE, fwd->request); break; @@ -3502,7 +3499,7 @@ FtpStateData::failedErrorMessage(err_type error, int xerrno) case SENT_RETR: if (ctrl.replycode == 550) - ftperr = errorCon(ERR_FTP_NOT_FOUND, HTTP_NOT_FOUND, fwd->request); + ftperr = new ErrorState(ERR_FTP_NOT_FOUND, HTTP_NOT_FOUND, fwd->request); break; @@ -3513,16 +3510,16 @@ FtpStateData::failedErrorMessage(err_type error, int xerrno) break; case ERR_READ_TIMEOUT: - ftperr = errorCon(error, HTTP_GATEWAY_TIMEOUT, fwd->request); + ftperr = new ErrorState(error, HTTP_GATEWAY_TIMEOUT, fwd->request); break; default: - ftperr = errorCon(error, HTTP_BAD_GATEWAY, fwd->request); + ftperr = new ErrorState(error, HTTP_BAD_GATEWAY, fwd->request); break; } if (ftperr == NULL) - ftperr = errorCon(ERR_FTP_FAILURE, HTTP_BAD_GATEWAY, fwd->request); + ftperr = new ErrorState(ERR_FTP_FAILURE, HTTP_BAD_GATEWAY, fwd->request); ftperr->xerrno = xerrno; @@ -3549,14 +3546,13 @@ FtpStateData::failedErrorMessage(err_type error, int xerrno) ftperr->ftp.reply = xstrdup(reply); entry->replaceHttpReply( ftperr->BuildHttpReply() ); - errorStateFree(ftperr); + delete ftperr; } /// \ingroup ServerProtocolFTPInternal static void ftpSendReply(FtpStateData * ftpState) { - ErrorState *err; int code = ftpState->ctrl.replycode; http_status http_code; err_type err_code = ERR_NONE; @@ -3580,22 +3576,21 @@ ftpSendReply(FtpStateData * ftpState) if (ftpState->request) ftpState->request->detailError(err_code, code); - err = errorCon(err_code, http_code, ftpState->request); + ErrorState err(err_code, http_code, ftpState->request); if (ftpState->old_request) - err->ftp.request = xstrdup(ftpState->old_request); + err.ftp.request = xstrdup(ftpState->old_request); else - err->ftp.request = xstrdup(ftpState->ctrl.last_command); + err.ftp.request = xstrdup(ftpState->ctrl.last_command); if (ftpState->old_reply) - err->ftp.reply = xstrdup(ftpState->old_reply); + err.ftp.reply = xstrdup(ftpState->old_reply); else if (ftpState->ctrl.last_reply) - err->ftp.reply = xstrdup(ftpState->ctrl.last_reply); + err.ftp.reply = xstrdup(ftpState->ctrl.last_reply); else - err->ftp.reply = xstrdup(""); + err.ftp.reply = xstrdup(""); - ftpState->entry->replaceHttpReply( err->BuildHttpReply() ); - errorStateFree(err); + ftpState->entry->replaceHttpReply( err.BuildHttpReply() ); ftpSendQuit(ftpState); } @@ -3705,9 +3700,8 @@ FtpStateData::haveParsedReplyHeaders() HttpReply * FtpStateData::ftpAuthRequired(HttpRequest * request, const char *realm) { - ErrorState *err = errorCon(ERR_CACHE_ACCESS_DENIED, HTTP_UNAUTHORIZED, request); - HttpReply *newrep = err->BuildHttpReply(); - errorStateFree(err); + ErrorState err(ERR_CACHE_ACCESS_DENIED, HTTP_UNAUTHORIZED, request); + HttpReply *newrep = err.BuildHttpReply(); #if HAVE_AUTH_MODULE_BASIC /* add Authenticate header */ newrep->header.putAuth("Basic", realm); diff --git a/src/gopher.cc b/src/gopher.cc index 0eb0d1e646..5a527b0853 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -721,7 +721,7 @@ gopherTimeout(const CommTimeoutCbParams &io) GopherStateData *gopherState = static_cast(io.data); debugs(10, 4, HERE << io.conn << ": '" << gopherState->entry->url() << "'" ); - gopherState->fwd->fail(errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, gopherState->fwd->request)); + gopherState->fwd->fail(new ErrorState(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, gopherState->fwd->request)); if (Comm::IsConnOpen(io.conn)) io.conn->close(); @@ -800,14 +800,13 @@ gopherReadReply(const Comm::ConnectionPointer &conn, char *buf, size_t len, comm CommIoCbPtrFun(gopherReadReply, gopherState)); comm_read(conn, buf, read_sz, call); } else { - ErrorState *err; - err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, gopherState->fwd->request); + ErrorState *err = new ErrorState(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, gopherState->fwd->request); err->xerrno = errno; gopherState->fwd->fail(err); gopherState->serverConn->close(); } } else if (len == 0 && entry->isEmpty()) { - gopherState->fwd->fail(errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE, gopherState->fwd->request)); + gopherState->fwd->fail(new ErrorState(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE, gopherState->fwd->request)); gopherState->serverConn->close(); } else if (len == 0) { /* Connection closed; retrieval done. */ @@ -851,7 +850,7 @@ gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size, if (errflag) { ErrorState *err; - err = errorCon(ERR_WRITE_ERROR, HTTP_SERVICE_UNAVAILABLE, gopherState->fwd->request); + err = new ErrorState(ERR_WRITE_ERROR, HTTP_SERVICE_UNAVAILABLE, gopherState->fwd->request); err->xerrno = errno; err->port = gopherState->fwd->request->port; err->url = xstrdup(entry->url()); diff --git a/src/http.cc b/src/http.cc index 232cbf1973..bfebc22bad 100644 --- a/src/http.cc +++ b/src/http.cc @@ -180,7 +180,7 @@ HttpStateData::httpTimeout(const CommTimeoutCbParams ¶ms) debugs(11, 4, HERE << serverConnection << ": '" << entry->url() << "'" ); if (entry->store_status == STORE_PENDING) { - fwd->fail(errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, fwd->request)); + fwd->fail(new ErrorState(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, fwd->request)); } serverConnection->close(); @@ -1076,8 +1076,7 @@ HttpStateData::readReply(const CommIoCbParams &io) if (ignoreErrno(io.xerrno)) { flags.do_next_read = 1; } else { - ErrorState *err; - err = errorCon(ERR_READ_ERROR, HTTP_BAD_GATEWAY, fwd->request); + ErrorState *err = new ErrorState(ERR_READ_ERROR, HTTP_BAD_GATEWAY, fwd->request); err->xerrno = io.xerrno; fwd->fail(err); flags.do_next_read = 0; @@ -1246,7 +1245,7 @@ HttpStateData::continueAfterParsingHeader() assert(error != ERR_NONE); entry->reset(); - fwd->fail(errorCon(error, HTTP_BAD_GATEWAY, fwd->request)); + fwd->fail(new ErrorState(error, HTTP_BAD_GATEWAY, fwd->request)); flags.do_next_read = 0; serverConnection->close(); return false; // quit on error @@ -1474,8 +1473,7 @@ HttpStateData::wroteLast(const CommIoCbParams &io) return; if (io.flag) { - ErrorState *err; - err = errorCon(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request); + ErrorState *err = new ErrorState(ERR_WRITE_ERROR, HTTP_BAD_GATEWAY, fwd->request); err->xerrno = io.xerrno; fwd->fail(err); serverConnection->close(); @@ -2298,12 +2296,11 @@ HttpStateData::handleRequestBodyProducerAborted() ServerStateData::handleRequestBodyProducerAborted(); if (entry->isEmpty()) { debugs(11, 3, "request body aborted: " << serverConnection); - ErrorState *err; // We usually get here when ICAP REQMOD aborts during body processing. // We might also get here if client-side aborts, but then our response // should not matter because either client-side will provide its own or // there will be no response at all (e.g., if the the client has left). - err = errorCon(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, fwd->request); + ErrorState *err = new ErrorState(ERR_ICAP_FAILURE, HTTP_INTERNAL_SERVER_ERROR, fwd->request); err->xerrno = ERR_DETAIL_SRV_REQMOD_REQ_BODY; fwd->fail(err); } diff --git a/src/internal.cc b/src/internal.cc index 8976164b5b..86ee69c676 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -76,7 +76,7 @@ internalStart(const Comm::ConnectionPointer &clientConn, HttpRequest * request, } else { debugObj(76, 1, "internalStart: unknown request:\n", request, (ObjPackMethod) & httpRequestPack); - err = errorCon(ERR_INVALID_REQ, HTTP_NOT_FOUND, request); + err = new ErrorState(ERR_INVALID_REQ, HTTP_NOT_FOUND, request); errorAppendEntry(entry, err); } } diff --git a/src/mgr/Forwarder.cc b/src/mgr/Forwarder.cc index 29e4d289d5..8c384725de 100644 --- a/src/mgr/Forwarder.cc +++ b/src/mgr/Forwarder.cc @@ -72,14 +72,14 @@ void Mgr::Forwarder::handleError() { debugs(16, DBG_CRITICAL, "ERROR: uri " << entry->url() << " exceeds buffer size"); - sendError(errorCon(ERR_INVALID_URL, HTTP_REQUEST_URI_TOO_LARGE, httpRequest)); + sendError(new ErrorState(ERR_INVALID_URL, HTTP_REQUEST_URI_TOO_LARGE, httpRequest)); mustStop("long URI"); } void Mgr::Forwarder::handleTimeout() { - sendError(errorCon(ERR_LIFETIME_EXP, HTTP_REQUEST_TIMEOUT, httpRequest)); + sendError(new ErrorState(ERR_LIFETIME_EXP, HTTP_REQUEST_TIMEOUT, httpRequest)); Ipc::Forwarder::handleTimeout(); } @@ -87,7 +87,7 @@ void Mgr::Forwarder::handleException(const std::exception& e) { if (entry != NULL && httpRequest != NULL && Comm::IsConnOpen(conn)) - sendError(errorCon(ERR_INVALID_RESP, HTTP_INTERNAL_SERVER_ERROR, httpRequest)); + sendError(new ErrorState(ERR_INVALID_RESP, HTTP_INTERNAL_SERVER_ERROR, httpRequest)); Ipc::Forwarder::handleException(e); } @@ -124,7 +124,7 @@ Mgr::Forwarder::sendError(ErrorState *error) entry->buffer(); entry->replaceHttpReply(error->BuildHttpReply()); entry->expires = squid_curtime; - errorStateFree(error); + delete error; entry->flush(); entry->complete(); } diff --git a/src/mgr/Inquirer.cc b/src/mgr/Inquirer.cc index 9c7432cc73..2c338b284f 100644 --- a/src/mgr/Inquirer.cc +++ b/src/mgr/Inquirer.cc @@ -75,10 +75,9 @@ Mgr::Inquirer::start() LOCAL_ARRAY(char, url, MAX_URL); snprintf(url, MAX_URL, "%s", aggrAction->command().params.httpUri.termedBuf()); HttpRequest *req = HttpRequest::CreateFromUrl(url); - ErrorState *err = errorCon(ERR_INVALID_URL, HTTP_NOT_FOUND, req); - std::auto_ptr reply(err->BuildHttpReply()); + ErrorState err(ERR_INVALID_URL, HTTP_NOT_FOUND, req); + std::auto_ptr reply(err.BuildHttpReply()); replyBuf.reset(reply->pack()); - errorStateFree(err); } else { std::auto_ptr reply(new HttpReply); reply->setHeaders(HTTP_OK, NULL, "text/plain", -1, squid_curtime, squid_curtime); diff --git a/src/tunnel.cc b/src/tunnel.cc index 8c3cc4b05c..67c0b5e0e4 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -556,7 +556,7 @@ tunnelConnectDone(const Comm::ConnectionPointer &conn, comm_err_t status, int xe AsyncJob::Start(cs); } else { debugs(26, 4, HERE << "terminate with error."); - ErrorState *err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE, tunnelState->request); + ErrorState *err = new ErrorState(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE, tunnelState->request); *tunnelState->status_ptr = HTTP_SERVICE_UNAVAILABLE; err->xerrno = xerrno; // on timeout is this still: err->xerrno = ETIMEDOUT; @@ -629,7 +629,7 @@ tunnelStart(ClientHttpRequest * http, int64_t * size_ptr, int *status_ptr) ch.my_addr = request->my_addr; if (ch.fastCheck() == ACCESS_DENIED) { debugs(26, 4, HERE << "MISS access forbidden."); - err = errorCon(ERR_FORWARDING_DENIED, HTTP_FORBIDDEN, request); + err = new ErrorState(ERR_FORWARDING_DENIED, HTTP_FORBIDDEN, request); *status_ptr = HTTP_FORBIDDEN; errorSend(http->getConn()->clientConnection, err); return; @@ -704,7 +704,7 @@ tunnelPeerSelectComplete(Comm::ConnectionList *peer_paths, ErrorState *err, void if (peer_paths == NULL || peer_paths->size() < 1) { debugs(26, 3, HERE << "No paths found. Aborting CONNECT"); if (!err) { - err = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE, tunnelState->request); + err = new ErrorState(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE, tunnelState->request); } *tunnelState->status_ptr = err->httpStatus; err->callback = tunnelErrorComplete; diff --git a/src/urn.cc b/src/urn.cc index 64c942c6e2..58d220967e 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -221,7 +221,7 @@ UrnState::setUriResFromRequest(HttpRequest *r) if (urlres_r == NULL) { debugs(52, 3, "urnStart: Bad uri-res URL " << urlres); - ErrorState *err = errorCon(ERR_URN_RESOLVE, HTTP_NOT_FOUND, r); + ErrorState *err = new ErrorState(ERR_URN_RESOLVE, HTTP_NOT_FOUND, r); err->url = urlres; urlres = NULL; errorAppendEntry(entry, err); @@ -373,7 +373,7 @@ urnHandleReply(void *data, StoreIOBuffer result) if (rep->sline.status != HTTP_OK) { debugs(52, 3, "urnHandleReply: failed."); - err = errorCon(ERR_URN_RESOLVE, HTTP_NOT_FOUND, urnState->request); + err = new ErrorState(ERR_URN_RESOLVE, HTTP_NOT_FOUND, urnState->request); err->url = xstrdup(e->url()); errorAppendEntry(e, err); delete rep; @@ -395,7 +395,7 @@ urnHandleReply(void *data, StoreIOBuffer result) if (urls == NULL) { /* unkown URN error */ debugs(52, 3, "urnTranslateDone: unknown URN " << e->url() ); - err = errorCon(ERR_URN_RESOLVE, HTTP_NOT_FOUND, urnState->request); + err = new ErrorState(ERR_URN_RESOLVE, HTTP_NOT_FOUND, urnState->request); err->url = xstrdup(e->url()); errorAppendEntry(e, err); urnHandleReplyError(urnState, urlres_e); diff --git a/src/whois.cc b/src/whois.cc index ad30fbfba0..27217e9fc1 100644 --- a/src/whois.cc +++ b/src/whois.cc @@ -157,8 +157,7 @@ WhoisState::readReply(const Comm::ConnectionPointer &conn, char *aBuffer, size_t CommIoCbPtrFun(whoisReadReply, this)); comm_read(conn, aBuffer, BUFSIZ, call); } else { - ErrorState *err; - err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, fwd->request); + ErrorState *err = new ErrorState(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR, fwd->request); err->xerrno = errno; fwd->fail(err); conn->close();