errorpage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 "err_detail_type.h"
17 #include "err_type.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 #if USE_OPENSSL
27 #include "ssl/ErrorDetail.h"
28 #endif
29 
31 typedef void ERCB(int fd, void *, size_t);
32 
78 class MemBuf;
79 class StoreEntry;
80 class wordlist;
81 
82 namespace ErrorPage {
83 
84 class Build;
85 
86 } // namespace ErrorPage
87 
90 {
92 
93 public:
95  ErrorState() = delete; // not implemented.
96  ~ErrorState();
97 
99  static ErrorState *NewForwarding(err_type, HttpRequestPointer &, const AccessLogEntryPointer &);
100 
104  HttpReply *BuildHttpReply(void);
105 
107  void detailError(int dCode) {detailCode = dCode;}
108 
110  void validate();
111 
114 
115 private:
117 
119  SBuf buildBody();
120 
124  SBuf compileBody(const char *text, bool allowRecursion);
125 
127  void compileLegacyCode(Build &build);
128 
130  void compileLogformatCode(Build &build);
131 
137  SBuf compile(const char *input, bool building_deny_info_url, bool allowRecursion);
138 
142  void noteBuildError(const char *msg, const char *near) {
143  noteBuildError_(msg, near, false);
144  }
145 
151  void bypassBuildErrorXXX(const char *msg, const char *near) {
152  noteBuildError_(msg, near, true);
153  }
154 
160  int Dump(MemBuf * mb);
161 
162 public:
164  int page_id = ERR_NONE;
165  char *err_language = nullptr;
167 #if USE_AUTH
169 #endif
171  char *url = nullptr;
172  int xerrno = 0;
173  unsigned short port = 0;
175  time_t ttl = 0;
176 
178  char *redirect_url = nullptr;
180  void *callback_data = nullptr;
181 
182  struct {
183  wordlist *server_msg = nullptr;
184  char *request = nullptr;
185  char *reply = nullptr;
186  char *cwd_msg = nullptr;
187  MemBuf *listing = nullptr;
188  } ftp;
189 
190  char *request_hdrs = nullptr;
191  char *err_msg = nullptr; /* Preformatted error message from the cache */
192 
194 
195 #if USE_OPENSSL
196  Ssl::ErrorDetail *detail = nullptr;
197 #endif
198  int detailCode = ERR_DETAIL_NONE;
201 
202 private:
203  void noteBuildError_(const char *msg, const char *near, const bool forceBypass);
204 
205  static const SBuf LogformatMagic;
206 };
207 
217 void errorInitialize(void);
218 
220 void errorClean(void);
221 
243 
260 void errorAppendEntry(StoreEntry *entry, ErrorState *err);
261 
263 err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation);
264 
265 const char *errorPageName(int pageId);
266 
274 {
275 public:
276  TemplateFile(const char *name, const err_type code);
277  virtual ~TemplateFile() {}
278 
280  bool loaded() const {return wasLoaded;}
281 
289  void loadDefault();
290 
297  bool loadFor(const HttpRequest *request);
298 
303  bool loadFromFile(const char *path);
304 
306  const char *language() {return errLanguage.termedBuf();}
307 
309 
310  bool silent;
311 
312 protected:
314  virtual bool parse() { return true; }
315 
317  virtual void setDefault() {}
318 
324  bool tryLoadTemplate(const char *lang);
325 
327  bool wasLoaded;
331 };
332 
346 bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos);
347 
348 #endif /* SQUID_ERRORPAGE_H */
349 
void bypassBuildErrorXXX(const char *msg, const char *near)
Definition: errorpage.h:151
void noteBuildError(const char *msg, const char *near)
Definition: errorpage.h:142
bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos)
Definition: errorpage.cc:460
int type
Definition: errorpage.cc:152
Definition: SBuf.h:86
String errLanguage
The error language of the template.
Definition: errorpage.h:328
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
ERCB * callback
Definition: errorpage.h:179
Auth::UserRequest::Pointer auth_user_request
Definition: errorpage.h:168
int conn
the current server connection FD
Definition: Transport.cc:26
bool loaded() const
return true if the data loaded from disk without any problem
Definition: errorpage.h:280
bool wasLoaded
True if the template data read from disk without any problem.
Definition: errorpage.h:327
void errorSend(const Comm::ConnectionPointer &conn, ErrorState *err)
Definition: errorpage.cc:724
bool silent
Whether to print error messages on cache.log file or not. It is user defined.
Definition: errorpage.h:310
err_type templateCode
The internal code for this template.
Definition: errorpage.h:330
void errorClean(void)
Definition: errorpage.cc:309
StatusCode
Definition: StatusCode.h:20
SBuf inputLocation
the source of the error template (for reporting purposes)
Definition: errorpage.h:113
virtual bool parse()
post-process the loaded template
Definition: errorpage.h:314
#define CBDATA_CLASS(type)
Definition: cbdata.h:302
const char * errorPageName(int pageId)
error ID to string
Definition: errorpage.cc:655
virtual ~TemplateFile()
Definition: errorpage.h:277
Http::StatusCode httpStatus
Definition: errorpage.h:166
static const SBuf LogformatMagic
marks each embedded logformat entry
Definition: errorpage.h:205
virtual void setDefault()
recover from loadDefault() failure to load or parse() a template
Definition: errorpage.h:317
SBuf filename
where the template was loaded from
Definition: errorpage.h:308
static int port
Definition: ldap_backend.cc:69
ErrorPage::Build Build
Definition: errorpage.h:116
unsigned char code
Definition: html_quote.c:20
String dnsError
DNS lookup error message.
Definition: errorpage.h:174
err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation)
allocates a new slot for the error page
Definition: errorpage.cc:640
HttpRequestPointer request
Definition: errorpage.h:170
Definition: MemBuf.h:23
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:691
AccessLogEntryPointer ale
transaction details (or nil)
Definition: errorpage.h:193
void detailError(int dCode)
set error type-specific detail code
Definition: errorpage.h:107
const char * language()
The language used for the template.
Definition: errorpage.h:306
void errorInitialize(void)
Definition: errorpage.cc:247
state and parameters shared by several ErrorState::compile*() methods
Definition: errorpage.cc:102
void ERCB(int fd, void *, size_t)
error page callback
Definition: errorpage.h:31
Ip::Address src_addr
Definition: errorpage.h:177
SBuf template_
raw template contents
Definition: errorpage.h:326
const char * text
Definition: errorpage.cc:153
String templateName
The name of the template.
Definition: errorpage.h:329
err_type
Definition: err_type.h:12

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors