]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SourceLayout: ErrorState constructor/destructor
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 27 Nov 2011 12:37:35 +0000 (01:37 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 27 Nov 2011 12:37:35 +0000 (01:37 +1300)
15 files changed:
src/Server.cc
src/cache_manager.cc
src/client_side_reply.cc
src/errorpage.cc
src/errorpage.h
src/forward.cc
src/ftp.cc
src/gopher.cc
src/http.cc
src/internal.cc
src/mgr/Forwarder.cc
src/mgr/Inquirer.cc
src/tunnel.cc
src/urn.cc
src/whois.cc

index 903e3a2134e8ff790871e00bd1cc3af0ba3e4f3e..be3ad71a122980e9d4c6880f28b1b5c4420f1e23 100644 (file)
@@ -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);
index 08492cd9c63406bb93a2f08c90e29f1e9f9fac41..1197a7adac63f2975e5c36e761a4252319267f03 100644 (file)
@@ -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
         /*
index 0014fa07cdcf06e6520338166b3d2cb7774b4749..6577c8755d1cb1fedf39c9d375e813876652c379 100644 (file)
@@ -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)
index 22391ce3380eb6900343d87db35ab011dcc6f3f4..c6afacb569108da416a1eb341cbec3a94677111e 100644 (file)
@@ -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
index 5d76575e80e5607590672e217cc30fe59200f4e3..9c9102adb58a7ea2ce891758dfcdc4ef95cd11c0 100644 (file)
@@ -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
 
 /**
index 56f3c65471cdf70e7533e00e588469d9566cfb63..0ee278c7ae0812042a2b0fabe7e3218b10f6a7c5 100644 (file)
@@ -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)
@@ -549,7 +541,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);
     }
 
@@ -675,7 +667,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
@@ -773,7 +765,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);
 
@@ -821,7 +813,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;
@@ -1004,7 +996,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
@@ -1087,8 +1079,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
index 8b8e70d0b1a8d8cc9c1b21e99a06c4e5d2bfc088..7fdc67bba6694aa44edd97a3eae494b3ac7cb29d 100644 (file)
@@ -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);
index 0eb0d1e6465357fbf0f57c6744712674e80ee1d8..5a527b085388ec7eb10f7539033f65817bd94899 100644 (file)
@@ -721,7 +721,7 @@ gopherTimeout(const CommTimeoutCbParams &io)
     GopherStateData *gopherState = static_cast<GopherStateData *>(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());
index 232cbf1973dc5f461b99ea62e03251b91d0223d3..bfebc22badf5d6455c8b44315128ed7bb37efe80 100644 (file)
@@ -180,7 +180,7 @@ HttpStateData::httpTimeout(const CommTimeoutCbParams &params)
     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);
     }
index 8976164b5b1681034d1686af49b761ba9a5c4751..86ee69c676867516661c68022efc3e50836dd6d9 100644 (file)
@@ -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);
     }
 }
index 29e4d289d53e6448aef33586ab7a273ddd238bba..8c384725deb255cdf879421b260cac97d5ca94a6 100644 (file)
@@ -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();
 }
index 769bd4e7b693a279abe709360bb1a3fb31bf44f6..c55b1dbae4543358be0906386a1d97819f2fcd9f 100644 (file)
@@ -79,14 +79,13 @@ 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);
+        ErrorState err(ERR_INVALID_URL, HTTP_NOT_FOUND, req);
 #if HAVE_UNIQUE_PTR
-        std::unique_ptr<HttpReply> reply(err->BuildHttpReply());
+        std::unique_ptr<HttpReply> reply(err.BuildHttpReply());
 #else
-        std::auto_ptr<HttpReply> reply(err->BuildHttpReply());
+        std::auto_ptr<HttpReply> reply(err.BuildHttpReply());
 #endif
         replyBuf.reset(reply->pack());
-        errorStateFree(err);
     } else {
 #if HAVE_UNIQUE_PTR
         std::unique_ptr<HttpReply> reply(new HttpReply);
index 3344f799260ffa1df4f9f742df1dc87c7440483d..e188f51d916689ee60bb6d16c8e82f481485d3b5 100644 (file)
@@ -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, void *data)
     if (peer_paths == NULL || peer_paths->size() < 1) {
         debugs(26, 3, HERE << "No paths found. Aborting CONNECT");
         ErrorState *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 = HTTP_SERVICE_UNAVAILABLE;
         err->callback = tunnelErrorComplete;
         err->callback_data = tunnelState;
index 64c942c6e27f59231b58ccae8da4478fac36d954..58d220967e9eca1138798f9f646d45175253022e 100644 (file)
@@ -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);
index ad30fbfba0ad434d5836ebcabbc02b5973d93af1..27217e9fc1fe17561426a0df3c72fc469aa7f9bc 100644 (file)
@@ -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();