errorpage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 
28 typedef void ERCB(int fd, void *, size_t);
29 
75 class MemBuf;
76 class StoreEntry;
77 class wordlist;
78 
79 namespace ErrorPage {
80 
81 class Build;
82 
83 } // namespace ErrorPage
84 
87 {
89 
90 public:
93  ErrorState() = delete; // not implemented.
94 
97 
98  ~ErrorState();
99 
102 
106  HttpReply *BuildHttpReply(void);
107 
109  void detailError(const ErrorDetail::Pointer &dCode) { detail = dCode; }
110 
112  void validate();
113 
116 
117 private:
119 
121  explicit ErrorState(err_type type);
122 
124  SBuf buildBody();
125 
129  SBuf compileBody(const char *text, bool allowRecursion);
130 
132  void compileLegacyCode(Build &build);
133 
135  void compileLogformatCode(Build &build);
136 
142  SBuf compile(const char *input, bool building_deny_info_url, bool allowRecursion);
143 
147  void noteBuildError(const char *msg, const char *near) {
148  noteBuildError_(msg, near, false);
149  }
150 
156  void bypassBuildErrorXXX(const char *msg, const char *near) {
157  noteBuildError_(msg, near, true);
158  }
159 
165  int Dump(MemBuf * mb);
166 
167 public:
170  char *err_language = nullptr;
172 #if USE_AUTH
174 #endif
176  char *url = nullptr;
177  int xerrno = 0;
178  unsigned short port = 0;
180  time_t ttl = 0;
181 
183  char *redirect_url = nullptr;
185  void *callback_data = nullptr;
186 
187  struct {
188  wordlist *server_msg = nullptr;
189  char *request = nullptr;
190  char *reply = nullptr;
191  char *cwd_msg = nullptr;
192  MemBuf *listing = nullptr;
193  } ftp;
194 
195  char *request_hdrs = nullptr;
196  char *err_msg = nullptr; /* Preformatted error message from the cache */
197 
199 
200  // TODO: Replace type, xerrno and detail with Error while adding a virtual
201  // Error::Detail::sysError() method to extract errno in detailError().
205 
207 
208 private:
209  void noteBuildError_(const char *msg, const char *near, const bool forceBypass);
210 
211  static const SBuf LogformatMagic;
212 };
213 
223 void errorInitialize(void);
224 
226 void errorClean(void);
227 
249 
266 void errorAppendEntry(StoreEntry *entry, ErrorState *err);
267 
269 err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation);
270 
271 const char *errorPageName(int pageId);
272 
280 {
281 public:
282  TemplateFile(const char *name, const err_type code);
283  virtual ~TemplateFile() {}
284 
286  bool loaded() const {return wasLoaded;}
287 
295  void loadDefault();
296 
303  bool loadFor(const HttpRequest *request);
304 
309  bool loadFromFile(const char *path);
310 
312  const char *language() {return errLanguage.termedBuf();}
313 
315 
316  bool silent;
317 
318 protected:
320  virtual bool parse() { return true; }
321 
323  virtual void setDefault() {}
324 
330  bool tryLoadTemplate(const char *lang);
331 
333  bool wasLoaded;
337 };
338 
352 bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos);
353 
354 std::ostream &operator <<(std::ostream &, const ErrorState *);
355 
356 #endif /* SQUID_ERRORPAGE_H */
357 
void ERCB(int fd, void *, size_t)
error page callback
Definition: errorpage.h:28
char * cwd_msg
Definition: errorpage.h:191
MemBuf * listing
Definition: errorpage.h:192
ERCB * callback
Definition: errorpage.h:184
@ scNone
Definition: StatusCode.h:21
String templateName
The name of the template.
Definition: errorpage.h:335
bool loadFromFile(const char *path)
Definition: errorpage.cc:419
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:720
bool loaded() const
return true if the data loaded from disk without any problem
Definition: errorpage.h:286
int Dump(MemBuf *mb)
Definition: errorpage.cc:809
char * reply
Definition: errorpage.h:190
bool wasLoaded
True if the template data read from disk without any problem.
Definition: errorpage.h:333
err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation)
allocates a new slot for the error page
Definition: errorpage.cc:649
HttpReplyPointer response_
Definition: errorpage.h:206
HttpReply * BuildHttpReply(void)
Definition: errorpage.cc:1280
struct ErrorState::@59 ftp
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
Definition: SBuf.h:87
AccessLogEntryPointer ale
transaction details (or nil)
Definition: errorpage.h:198
String errLanguage
The error language of the template.
Definition: errorpage.h:334
int page_id
Definition: errorpage.h:169
const char * errorPageName(int pageId)
error ID to string
Definition: errorpage.cc:664
void detailError(const ErrorDetail::Pointer &dCode)
set error type-specific detail code
Definition: errorpage.h:109
@ ERR_NONE
Definition: forward.h:15
StatusCode
Definition: StatusCode.h:20
err_type
Definition: forward.h:14
err_type templateCode
The internal code for this template.
Definition: errorpage.h:336
void bypassBuildErrorXXX(const char *msg, const char *near)
Definition: errorpage.h:156
unsigned short port
Definition: errorpage.h:178
time_t ttl
Definition: errorpage.h:180
void compileLogformatCode(Build &build)
compile @Squid{code} sequence containing a single logformat code
Definition: errorpage.cc:879
TemplateFile(const char *name, const err_type code)
Definition: errorpage.cc:352
void noteBuildError_(const char *msg, const char *near, const bool forceBypass)
Definition: errorpage.cc:1441
bool silent
Whether to print error messages on cache.log file or not. It is user defined.
Definition: errorpage.h:316
virtual void setDefault()
recover from loadDefault() failure to load or parse() a template
Definition: errorpage.h:323
void loadDefault()
Definition: errorpage.cc:358
wordlist * server_msg
Definition: errorpage.h:188
void errorSend(const Comm::ConnectionPointer &conn, ErrorState *err)
Definition: errorpage.cc:751
ErrorState()=delete
err_type type
Definition: errorpage.h:168
const char * text
Definition: errorpage.cc:154
HttpRequestPointer request
Definition: errorpage.h:175
char * request_hdrs
Definition: errorpage.h:195
Definition: MemBuf.h:24
unsigned char code
Definition: html_quote.c:20
bool tryLoadTemplate(const char *lang)
Definition: errorpage.cc:394
virtual bool parse()
post-process the loaded template
Definition: errorpage.h:320
void validate()
ensures that a future BuildHttpReply() is likely to succeed
Definition: errorpage.cc:1268
Ip::Address src_addr
Definition: errorpage.h:182
state and parameters shared by several ErrorState::compile*() methods
Definition: errorpage.cc:104
char * err_msg
Definition: errorpage.h:196
int conn
the current server connection FD
Definition: Transport.cc:26
char const * termedBuf() const
Definition: SquidString.h:92
SBuf compileBody(const char *text, bool allowRecursion)
Definition: errorpage.cc:1399
char * err_language
Definition: errorpage.h:170
ErrorDetail::Pointer detail
Definition: errorpage.h:204
String dnsError
DNS lookup error message.
Definition: errorpage.h:179
int xerrno
Definition: errorpage.h:177
virtual ~TemplateFile()
Definition: errorpage.h:283
void compileLegacyCode(Build &build)
compile a single-letter code like D
Definition: errorpage.cc:915
const char * language()
The language used for the template.
Definition: errorpage.h:312
char * redirect_url
Definition: errorpage.h:183
SBuf inputLocation
the source of the error template (for reporting purposes)
Definition: errorpage.h:115
SBuf filename
where the template was loaded from
Definition: errorpage.h:314
char * url
Definition: errorpage.h:176
static ErrorState * NewForwarding(err_type, HttpRequestPointer &, const AccessLogEntryPointer &)
Creates a general request forwarding error with the right http_status.
Definition: errorpage.cc:676
std::ostream & operator<<(std::ostream &, const ErrorState *)
Definition: errorpage.cc:1530
ErrorPage::Build Build
Definition: errorpage.h:118
bool loadFor(const HttpRequest *request)
Definition: errorpage.cc:521
SBuf buildBody()
locates the right error page template for this error and compiles it
Definition: errorpage.cc:1363
SBuf template_
raw template contents
Definition: errorpage.h:332
void * callback_data
Definition: errorpage.h:185
void errorClean(void)
Definition: errorpage.cc:316
SBuf compile(const char *input, bool building_deny_info_url, bool allowRecursion)
Definition: errorpage.cc:1405
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos)
Definition: errorpage.cc:467
static const SBuf LogformatMagic
marks each embedded logformat entry
Definition: errorpage.h:211
Http::StatusCode httpStatus
Definition: errorpage.h:171
Auth::UserRequest::Pointer auth_user_request
Definition: errorpage.h:173
void errorInitialize(void)
Definition: errorpage.cc:254
void noteBuildError(const char *msg, const char *near)
Definition: errorpage.h:147

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors