/*
- * DEBUG: section 04 Error Generation
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+
+/* DEBUG: section 04 Error Generation */
+
#include "squid.h"
#include "cache_cf.h"
+#include "clients/forward.h"
#include "comm/Connection.h"
#include "comm/Write.h"
#include "disk.h"
#include "err_detail_type.h"
#include "errorpage.h"
#include "fde.h"
-#include "ftp.h"
#include "html_quote.h"
#include "HttpHeaderTools.h"
#include "HttpReply.h"
#include "auth/UserRequest.h"
#endif
#include "SquidTime.h"
-#if USE_SSL
+#if USE_OPENSSL
#include "ssl/ErrorDetailManager.h"
#endif
* automagically to give you more control on the format
*/
static const struct {
- int type; /* and page_id */
+ int type; /* and page_id */
const char *text;
}
};
/// \ingroup ErrorPageInternal
-static Vector<ErrorDynamicPageInfo *> ErrorDynamicPages;
+static std::vector<ErrorDynamicPageInfo *> ErrorDynamicPages;
/* local prototypes */
class ErrorPageFile: public TemplateFile
{
public:
- ErrorPageFile(const char *name, const err_type code): TemplateFile(name,code) { textBuf.init();}
+ ErrorPageFile(const char *name, const err_type code) : TemplateFile(name,code) {textBuf.init();}
/// The template text data read from disk
const char *text() { return textBuf.content(); }
private:
/// stores the data read from disk to a local buffer
- virtual bool parse(const char *buf, int len, bool eof) {
+ virtual bool parse(const char *buf, int len, bool) {
if (len)
textBuf.append(buf, len);
return true;
error_stylesheet.Printf("%s",tmpl.text());
}
-#if USE_SSL
+#if USE_OPENSSL
Ssl::errorDetailInitialize();
#endif
}
error_page_count = 0;
-#if USE_SSL
+#if USE_OPENSSL
Ssl::errorDetailClean();
#endif
}
const char *
errorPageName(int pageId)
{
- if (pageId >= ERR_NONE && pageId < ERR_MAX) /* common case */
+ if (pageId >= ERR_NONE && pageId < ERR_MAX) /* common case */
return err_type_str[pageId];
if (pageId >= ERR_MAX && pageId - ERR_MAX < (ssize_t)ErrorDynamicPages.size())
return ErrorDynamicPages[pageId - ERR_MAX]->page_name;
- return "ERR_UNKNOWN"; /* should not happen */
+ return "ERR_UNKNOWN"; /* should not happen */
+}
+
+ErrorState *
+ErrorState::NewForwarding(err_type type, HttpRequest *request)
+{
+ assert(request);
+ const Http::StatusCode status = request->flags.needValidation ?
+ Http::scGatewayTimeout : Http::scServiceUnavailable;
+ return new ErrorState(type, status, request);
}
ErrorState::ErrorState(err_type t, Http::StatusCode status, HttpRequest * req) :
- type(t),
- page_id(t),
- err_language(NULL),
- httpStatus(status),
+ type(t),
+ page_id(t),
+ err_language(NULL),
+ httpStatus(status),
#if USE_AUTH
- auth_user_request (NULL),
+ 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),
+ 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_OPENSSL
+ detail(NULL),
#endif
- detailCode(ERR_DETAIL_NONE)
+ detailCode(ERR_DETAIL_NONE)
{
memset(&ftp, 0, sizeof(ftp));
}
}
- entry->lock("errorAppendEntry");
- entry->buffer();
- entry->replaceHttpReply( err->BuildHttpReply() );
- entry->flush();
- entry->complete();
- entry->negativeCache();
- entry->releaseRequest();
- entry->unlock("errorAppendEntry");
+ entry->storeErrorResponse(err->BuildHttpReply());
delete err;
}
* closing the FD, otherwise we do it ourselves.
*/
static void
-errorSendComplete(const Comm::ConnectionPointer &conn, char *bufnotused, size_t size, comm_err_t errflag, int xerrno, void *data)
+errorSendComplete(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag errflag, int, void *data)
{
ErrorState *err = static_cast<ErrorState *>(data);
debugs(4, 3, HERE << conn << ", size=" << size);
- if (errflag != COMM_ERR_CLOSING) {
+ if (errflag != Comm::ERR_CLOSING) {
if (err->callback) {
debugs(4, 3, "errorSendComplete: callback");
err->callback(conn->fd, err->callback_data, size);
if (err_language != Config.errorDefaultLanguage)
#endif
safe_free(err_language);
-#if USE_SSL
+#if USE_OPENSSL
delete detail;
#endif
}
str.Printf("Err: [none]\r\n");
}
#if USE_AUTH
- if (auth_user_request->denyMessage())
+ if (auth_user_request.getRaw() && auth_user_request->denyMessage())
str.Printf("Auth ErrMsg: %s\r\n", auth_user_request->denyMessage());
#endif
if (dnsError.size() > 0)
else
urlpath_or_slash = "/";
- str.Printf("%s " SQUIDSTRINGPH " %s/%d.%d\n",
- RequestMethodStr(request->method),
+ str.Printf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n",
+ SQUIDSBUFPRINT(request->method.image()),
SQUIDSTRINGPRINT(urlpath_or_slash),
AnyP::ProtocolType_str[request->http_ver.protocol],
request->http_ver.major, request->http_ver.minor);
ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion)
{
static MemBuf mb;
- const char *p = NULL; /* takes priority over mb if set */
+ const char *p = NULL; /* takes priority over mb if set */
int do_quote = 1;
int no_urlescape = 0; /* if true then item is NOT to be further URL-encoded */
char ntoabuf[MAX_IPSTRLEN];
case 'B':
if (building_deny_info_url) break;
- p = request ? ftpUrlWith2f(request) : "[no URL]";
+ p = request ? Ftp::UrlWith2f(request) : "[no URL]";
break;
case 'c':
case 'D':
if (!allowRecursion)
p = "%D"; // if recursion is not allowed, do not convert
-#if USE_SSL
+#if USE_OPENSSL
// currently only SSL error details implemented
else if (detail) {
detail->useRequest(request);
break;
case 'M':
- if (request)
- p = RequestMethodStr(request->method);
- else if (!building_deny_info_url)
- p= "[unknown method]";
+ if (request) {
+ const SBuf &m = request->method.image();
+ mb.append(m.rawContent(), m.length());
+ } else if (!building_deny_info_url)
+ p = "[unknown method]";
break;
case 'o':
case 'P':
if (request) {
- p = AnyP::ProtocolType_str[request->protocol];
+ p = request->url.getScheme().c_str();
} else if (!building_deny_info_url) {
p = "[unknown protocol]";
}
else
urlpath_or_slash = "/";
- mb.Printf("%s " SQUIDSTRINGPH " %s/%d.%d\n",
- RequestMethodStr(request->method),
+ mb.Printf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n",
+ SQUIDSBUFPRINT(request->method.image()),
SQUIDSTRINGPRINT(urlpath_or_slash),
AnyP::ProtocolType_str[request->http_ver.protocol],
request->http_ver.major, request->http_ver.minor);
break;
case 'x':
-#if USE_SSL
+#if USE_OPENSSL
if (detail)
mb.Printf("%s", detail->errorName());
else
}
if (!p)
- p = mb.buf; /* do not use mb after this assignment! */
+ p = mb.buf; /* do not use mb after this assignment! */
assert(p);
}
void
-ErrorState::DenyInfoLocation(const char *name, HttpRequest *aRequest, MemBuf &result)
+ErrorState::DenyInfoLocation(const char *name, HttpRequest *, MemBuf &result)
{
char const *m = name;
char const *p = m;
if (name[0] == '3' || (name[0] != '2' && name[0] != '4' && name[0] != '5' && strchr(name, ':'))) {
/* Redirection */
- Http::StatusCode status = Http::scMovedTemporarily;
+ Http::StatusCode status = Http::scFound;
// Use configured 3xx reply status if set.
if (name[0] == '3')
status = httpStatus;
// error tracking.
if (request) {
int edc = ERR_DETAIL_NONE; // error detail code
-#if USE_SSL
+#if USE_OPENSSL
if (detail)
edc = detail->errorNo();
else
content->init();
while ((p = strchr(m, '%'))) {
- content->append(m, p - m); /* copy */
- const char *t = Convert(*++p, false, allowRecursion); /* convert */
- content->Printf("%s", t); /* copy */
- m = p + 1; /* advance */
+ content->append(m, p - m); /* copy */
+ const char *t = Convert(*++p, false, allowRecursion); /* convert */
+ content->Printf("%s", t); /* copy */
+ m = p + 1; /* advance */
}
if (*m)
- content->Printf("%s", m); /* copy tail */
+ content->Printf("%s", m); /* copy tail */
content->terminate();
return content;
}
+