errorpage.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 04 Error Generation */
10
11#ifndef SQUID_ERRORPAGE_H
12#define SQUID_ERRORPAGE_H
13
14#include "cbdata.h"
15#include "comm/forward.h"
16#include "error/Detail.h"
17#include "error/forward.h"
18#include "http/forward.h"
19#include "http/StatusCode.h"
20#include "ip/Address.h"
21#include "log/forward.h"
22#include "sbuf/SBuf.h"
23#include "SquidString.h"
24/* auth/UserRequest.h is empty unless USE_AUTH is defined */
25#include "auth/UserRequest.h"
26
27#include <optional>
28
30typedef void ERCB(int fd, void *, size_t);
31
77class MemBuf;
78class StoreEntry;
79class wordlist;
80
81namespace ErrorPage {
82
83class Build;
84
85} // namespace ErrorPage
86
89{
91
92public:
95 ErrorState() = delete; // not implemented.
96
99
100 ~ErrorState();
101
104
109
111 void detailError(const ErrorDetail::Pointer &dCode) { detail = dCode; }
112
114 void validate();
115
118
119private:
121
124
126 SBuf buildBody();
127
131 SBuf compileBody(const char *text, bool allowRecursion);
132
134 void compileLegacyCode(Build &build);
135
137 void compileLogformatCode(Build &build);
138
144 SBuf compile(const char *input, bool building_deny_info_url, bool allowRecursion);
145
149 void noteBuildError(const char *msg, const char *near) {
150 noteBuildError_(msg, near, false);
151 }
152
158 void bypassBuildErrorXXX(const char *msg, const char *near) {
159 noteBuildError_(msg, near, true);
160 }
161
167 int Dump(MemBuf * mb);
168
169public:
172 char *err_language = nullptr;
174#if USE_AUTH
176#endif
178 char *url = nullptr;
179 int xerrno = 0;
180 std::optional<SBuf> dnsError;
181 time_t ttl = 0;
182
184 char *redirect_url = nullptr;
186 void *callback_data = nullptr;
187
188 struct {
190 char *request = nullptr;
191 char *reply = nullptr;
192 char *cwd_msg = nullptr;
193 MemBuf *listing = nullptr;
195
196 char *request_hdrs = nullptr;
197 char *err_msg = nullptr; /* Preformatted error message from the cache */
198
200
201 // TODO: Replace type, xerrno and detail with Error while adding a virtual
202 // Error::Detail::sysError() method to extract errno in detailError().
206
208
209private:
210 void noteBuildError_(const char *msg, const char *near, const bool forceBypass);
211
212 static const SBuf LogformatMagic;
213};
214
224void errorInitialize(void);
225
227void errorClean(void);
228
250
267void errorAppendEntry(StoreEntry *entry, ErrorState *err);
268
270err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation);
271
272const char *errorPageName(int pageId);
273
281{
282public:
283 TemplateFile(const char *name, const err_type code);
284 virtual ~TemplateFile() {}
285
287 bool loaded() const {return wasLoaded;}
288
296 void loadDefault();
297
304 bool loadFor(const HttpRequest *request);
305
310 bool loadFromFile(const char *path);
311
313 const char *language() {return errLanguage.termedBuf();}
314
316
317 bool silent;
318
319protected:
321 virtual bool parse() { return true; }
322
324 virtual void setDefault() {}
325
331 bool tryLoadTemplate(const char *lang);
332
338};
339
353bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos);
354
355std::ostream &operator <<(std::ostream &, const ErrorState *);
356
357#endif /* SQUID_ERRORPAGE_H */
358
int conn
the current server connection FD
Definition: Transport.cc:26
#define CBDATA_CLASS(type)
Definition: cbdata.h:289
state and parameters shared by several ErrorState::compile*() methods
Definition: errorpage.cc:105
static ErrorState * NewForwarding(err_type, HttpRequestPointer &, const AccessLogEntryPointer &)
Creates a general request forwarding error with the right http_status.
Definition: errorpage.cc:674
void bypassBuildErrorXXX(const char *msg, const char *near)
Definition: errorpage.h:158
SBuf compile(const char *input, bool building_deny_info_url, bool allowRecursion)
Definition: errorpage.cc:1404
char * redirect_url
Definition: errorpage.h:184
char * err_msg
Definition: errorpage.h:197
void validate()
ensures that a future BuildHttpReply() is likely to succeed
Definition: errorpage.cc:1265
err_type type
Definition: errorpage.h:170
void compileLegacyCode(Build &build)
compile a single-letter code like D
Definition: errorpage.cc:912
MemBuf * listing
Definition: errorpage.h:193
AccessLogEntryPointer ale
transaction details (or nil)
Definition: errorpage.h:199
ERCB * callback
Definition: errorpage.h:185
std::optional< SBuf > dnsError
DNS lookup error message.
Definition: errorpage.h:180
int Dump(MemBuf *mb)
Definition: errorpage.cc:806
ErrorDetail::Pointer detail
Definition: errorpage.h:205
int xerrno
Definition: errorpage.h:179
char * reply
Definition: errorpage.h:191
char * err_language
Definition: errorpage.h:172
char * cwd_msg
Definition: errorpage.h:192
void detailError(const ErrorDetail::Pointer &dCode)
set error type-specific detail code
Definition: errorpage.h:111
void compileLogformatCode(Build &build)
compile @Squid{code} sequence containing a single logformat code
Definition: errorpage.cc:876
wordlist * server_msg
Definition: errorpage.h:189
char * url
Definition: errorpage.h:178
int page_id
Definition: errorpage.h:171
Auth::UserRequest::Pointer auth_user_request
Definition: errorpage.h:175
SBuf inputLocation
the source of the error template (for reporting purposes)
Definition: errorpage.h:117
void noteBuildError_(const char *msg, const char *near, const bool forceBypass)
Definition: errorpage.cc:1440
char * request_hdrs
Definition: errorpage.h:196
Ip::Address src_addr
Definition: errorpage.h:183
void noteBuildError(const char *msg, const char *near)
Definition: errorpage.h:149
static const SBuf LogformatMagic
marks each embedded logformat entry
Definition: errorpage.h:212
HttpRequestPointer request
Definition: errorpage.h:177
SBuf compileBody(const char *text, bool allowRecursion)
Definition: errorpage.cc:1398
HttpReply * BuildHttpReply(void)
Definition: errorpage.cc:1277
void * callback_data
Definition: errorpage.h:186
SBuf buildBody()
locates the right error page template for this error and compiles it
Definition: errorpage.cc:1362
HttpReplyPointer response_
Definition: errorpage.h:207
ErrorState()=delete
Http::StatusCode httpStatus
Definition: errorpage.h:173
time_t ttl
Definition: errorpage.h:181
ErrorPage::Build Build
Definition: errorpage.h:120
struct ErrorState::@56 ftp
Definition: MemBuf.h:24
Definition: SBuf.h:94
char const * termedBuf() const
Definition: SquidString.h:92
virtual void setDefault()
recover from loadDefault() failure to load or parse() a template
Definition: errorpage.h:324
bool loadFromFile(const char *path)
Definition: errorpage.cc:417
SBuf template_
raw template contents
Definition: errorpage.h:333
SBuf filename
where the template was loaded from
Definition: errorpage.h:315
bool loaded() const
return true if the data loaded from disk without any problem
Definition: errorpage.h:287
TemplateFile(const char *name, const err_type code)
Definition: errorpage.cc:350
bool wasLoaded
True if the template data read from disk without any problem.
Definition: errorpage.h:334
bool tryLoadTemplate(const char *lang)
Definition: errorpage.cc:392
String templateName
The name of the template.
Definition: errorpage.h:336
void loadDefault()
Definition: errorpage.cc:356
const char * language()
The language used for the template.
Definition: errorpage.h:313
virtual bool parse()
post-process the loaded template
Definition: errorpage.h:321
virtual ~TemplateFile()
Definition: errorpage.h:284
err_type templateCode
The internal code for this template.
Definition: errorpage.h:337
String errLanguage
The error language of the template.
Definition: errorpage.h:335
bool silent
Whether to print error messages on cache.log file or not. It is user defined.
Definition: errorpage.h:317
bool loadFor(const HttpRequest *request)
Definition: errorpage.cc:519
err_type
Definition: forward.h:14
@ ERR_NONE
Definition: forward.h:15
void ERCB(int fd, void *, size_t)
error page callback
Definition: errorpage.h:30
err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation)
allocates a new slot for the error page
Definition: errorpage.cc:647
std::ostream & operator<<(std::ostream &, const ErrorState *)
Definition: errorpage.cc:1529
bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos)
Definition: errorpage.cc:465
void errorInitialize(void)
Definition: errorpage.cc:254
void errorSend(const Comm::ConnectionPointer &conn, ErrorState *err)
Definition: errorpage.cc:748
void errorClean(void)
Definition: errorpage.cc:316
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:717
const char * errorPageName(int pageId)
error ID to string
Definition: errorpage.cc:662
StatusCode
Definition: StatusCode.h:20
@ scNone
Definition: StatusCode.h:21
int code
Definition: smb-errors.c:145
SBuf text("GET http://resource.com/path HTTP/1.1\r\n" "Host: resource.com\r\n" "Cookie: laijkpk3422r j1noin \r\n" "\r\n")

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors