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:
96  ErrorState() = delete; // not implemented.
97 
100 
101  ~ErrorState();
102 
104  static ErrorState *NewForwarding(err_type, HttpRequestPointer &, const AccessLogEntryPointer &);
105 
109  HttpReply *BuildHttpReply(void);
110 
112  void detailError(int dCode) {detailCode = dCode;}
113 
115  void validate();
116 
119 
120 private:
122 
124  explicit ErrorState(err_type type);
125 
127  SBuf buildBody();
128 
132  SBuf compileBody(const char *text, bool allowRecursion);
133 
135  void compileLegacyCode(Build &build);
136 
138  void compileLogformatCode(Build &build);
139 
145  SBuf compile(const char *input, bool building_deny_info_url, bool allowRecursion);
146 
150  void noteBuildError(const char *msg, const char *near) {
151  noteBuildError_(msg, near, false);
152  }
153 
159  void bypassBuildErrorXXX(const char *msg, const char *near) {
160  noteBuildError_(msg, near, true);
161  }
162 
168  int Dump(MemBuf * mb);
169 
170 public:
172  int page_id = ERR_NONE;
173  char *err_language = nullptr;
175 #if USE_AUTH
177 #endif
179  char *url = nullptr;
180  int xerrno = 0;
181  unsigned short port = 0;
183  time_t ttl = 0;
184 
186  char *redirect_url = nullptr;
188  void *callback_data = nullptr;
189 
190  struct {
191  wordlist *server_msg = nullptr;
192  char *request = nullptr;
193  char *reply = nullptr;
194  char *cwd_msg = nullptr;
195  MemBuf *listing = nullptr;
196  } ftp;
197 
198  char *request_hdrs = nullptr;
199  char *err_msg = nullptr; /* Preformatted error message from the cache */
200 
202 
203 #if USE_OPENSSL
204  Ssl::ErrorDetail *detail = nullptr;
205 #endif
206  int detailCode = ERR_DETAIL_NONE;
209 
211 
212 private:
213  void noteBuildError_(const char *msg, const char *near, const bool forceBypass);
214 
215  static const SBuf LogformatMagic;
216 };
217 
227 void errorInitialize(void);
228 
230 void errorClean(void);
231 
253 
270 void errorAppendEntry(StoreEntry *entry, ErrorState *err);
271 
273 err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation);
274 
275 const char *errorPageName(int pageId);
276 
284 {
285 public:
286  TemplateFile(const char *name, const err_type code);
287  virtual ~TemplateFile() {}
288 
290  bool loaded() const {return wasLoaded;}
291 
299  void loadDefault();
300 
307  bool loadFor(const HttpRequest *request);
308 
313  bool loadFromFile(const char *path);
314 
316  const char *language() {return errLanguage.termedBuf();}
317 
319 
320  bool silent;
321 
322 protected:
324  virtual bool parse() { return true; }
325 
327  virtual void setDefault() {}
328 
334  bool tryLoadTemplate(const char *lang);
335 
337  bool wasLoaded;
341 };
342 
356 bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos);
357 
358 #endif /* SQUID_ERRORPAGE_H */
359 
HttpReplyPointer response_
Definition: errorpage.h:210
void bypassBuildErrorXXX(const char *msg, const char *near)
Definition: errorpage.h:159
void noteBuildError(const char *msg, const char *near)
Definition: errorpage.h:150
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:338
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
ERCB * callback
Definition: errorpage.h:187
Auth::UserRequest::Pointer auth_user_request
Definition: errorpage.h:176
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:290
bool wasLoaded
True if the template data read from disk without any problem.
Definition: errorpage.h:337
void errorSend(const Comm::ConnectionPointer &conn, ErrorState *err)
Definition: errorpage.cc:744
bool silent
Whether to print error messages on cache.log file or not. It is user defined.
Definition: errorpage.h:320
err_type templateCode
The internal code for this template.
Definition: errorpage.h:340
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:118
virtual bool parse()
post-process the loaded template
Definition: errorpage.h:324
#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:287
static const SBuf LogformatMagic
marks each embedded logformat entry
Definition: errorpage.h:215
virtual void setDefault()
recover from loadDefault() failure to load or parse() a template
Definition: errorpage.h:327
SBuf filename
where the template was loaded from
Definition: errorpage.h:318
static int port
Definition: ldap_backend.cc:69
ErrorPage::Build Build
Definition: errorpage.h:121
unsigned char code
Definition: html_quote.c:20
String dnsError
DNS lookup error message.
Definition: errorpage.h:182
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:178
Definition: MemBuf.h:23
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:711
AccessLogEntryPointer ale
transaction details (or nil)
Definition: errorpage.h:201
void detailError(int dCode)
set error type-specific detail code
Definition: errorpage.h:112
const char * language()
The language used for the template.
Definition: errorpage.h:316
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:185
SBuf template_
raw template contents
Definition: errorpage.h:336
const char * text
Definition: errorpage.cc:153
String templateName
The name of the template.
Definition: errorpage.h:339
err_type
Definition: err_type.h:12

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors