]> git.ipfire.org Git - thirdparty/squid.git/blame - src/errorpage.h
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / errorpage.h
CommitLineData
aa839030 1/*
b510f3a1 2 * DEBUG: section 04 Error Generation
63be0a78 3 * AUTHOR: Duane Wessels
aa839030 4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
26ac0430 21 *
aa839030 22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26ac0430 26 *
aa839030 27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
32 */
33
34#ifndef SQUID_ERRORPAGE_H
35#define SQUID_ERRORPAGE_H
36
f7f3304a 37#include "squid-old.h"
2f1431ea 38#if USE_AUTH
a33a428a 39#include "auth/UserRequest.h"
2f1431ea 40#endif
aa839030 41#include "cbdata.h"
e0d28505 42#include "comm/forward.h"
96d89ea0 43#include "ip/Address.h"
02259ff8 44#include "MemBuf.h"
4d16918e
CT
45#if USE_SSL
46#include "ssl/ErrorDetail.h"
47#endif
aa839030 48
63be0a78 49/**
50 \defgroup ErrorPageAPI Error Pages API
51 \ingroup Components
52 \section ErrorPageStringCodes Error Page % codes for text insertion.
53 *
54 \verbatim
55 a - User identity x
56 B - URL with FTP %2f hack x
57 c - Squid error code x
58 d - seconds elapsed since request received x
4d16918e 59 D - Error details x
63be0a78 60 e - errno x
61 E - strerror() x
62 f - FTP request line x
63 F - FTP reply line x
64 g - FTP server message x
65 h - cache hostname x
66 H - server host name x
67 i - client IP address x
68 I - server IP address x
8e1a6bde 69 l - HREF link for CSS stylesheet inclusion x
63be0a78 70 L - HREF link for more info/contact x
71 M - Request Method x
72 m - Error message returned by auth helper x
73 o - Message returned external acl helper x
74 p - URL port # x
75 P - Protocol x
76 R - Full HTTP Request x
77 S - squid signature from ERR_SIGNATURE x
78 s - caching proxy software with version x
79 t - local time x
80 T - UTC x
81 U - URL without password x
82 u - URL with password x
83 w - cachemgr email address x
84 W - error data (to be included in the mailto links)
e4a8468d 85 x - error name x
63be0a78 86 z - dns server error message x
87 Z - Preformatted error message x
88 \endverbatim
89 */
90
c70281f8
AJ
91class HttpReply;
92class MemBuf;
9554bbf2 93
63be0a78 94/// \ingroup ErrorPageAPI
aa839030 95class ErrorState
96{
c70281f8 97public:
913524f0
AJ
98 ErrorState(err_type type, http_status, HttpRequest * request);
99 ErrorState(); // not implemented.
100 ~ErrorState();
101
c70281f8
AJ
102 /**
103 * Allocates and initializes an error response
104 */
105 HttpReply *BuildHttpReply(void);
106
107private:
108 /**
109 * Locates error page template to be used for this error
110 * and constructs the HTML page content from it.
111 */
112 MemBuf *BuildContent(void);
113
4d16918e
CT
114 /**
115 * Convert the given template string into textual output
116 *
117 * \param text The string to be converted
118 * \param allowRecursion Whether to convert codes which output may contain codes
119 */
120 MemBuf *ConvertText(const char *text, bool allowRecursion);
121
c70281f8 122 /**
15b02e9a
AJ
123 * Generates the Location: header value for a deny_info error page
124 * to be used for this error.
c70281f8 125 */
15b02e9a
AJ
126 void DenyInfoLocation(const char *name, HttpRequest *request, MemBuf &result);
127
128 /**
129 * Map the Error page and deny_info template % codes into textual output.
05320519 130 *
15b02e9a
AJ
131 * Several of the codes produce blocks of non-URL compatible results.
132 * When processing the deny_info location URL they will be skipped.
133 *
1e98e28b
AJ
134 * \param token The token following % which need to be converted
135 * \param building_deny_info_url Perform special deny_info actions, such as URL-encoding and token skipping.
4d16918e 136 * \ allowRecursion True if the codes which do recursions should converted
15b02e9a 137 */
4d16918e 138 const char *Convert(char token, bool building_deny_info_url, bool allowRecursion);
c70281f8
AJ
139
140 /**
141 * CacheManager / Debug dump of the ErrorState object.
142 * Writes output into the given MemBuf.
143 \retval 0 successful completion.
144 */
145 int Dump(MemBuf * mb);
2cc81f1f 146
147public:
aa839030 148 err_type type;
149 int page_id;
ccb24616 150 char *err_language;
aa839030 151 http_status httpStatus;
2f1431ea 152#if USE_AUTH
c7baff40 153 Auth::UserRequest::Pointer auth_user_request;
2f1431ea 154#endif
aa839030 155 HttpRequest *request;
156 char *url;
157 int xerrno;
f45dd259 158 unsigned short port;
3ff65596 159 String dnsError; ///< DNS lookup error message
aa839030 160 time_t ttl;
161
b7ac5457 162 Ip::Address src_addr;
aa839030 163 char *redirect_url;
164 ERCB *callback;
165 void *callback_data;
166
26ac0430 167 struct {
3d0ac046
HN
168 unsigned int flag_cbdata:1;
169 } flags;
aa839030 170
26ac0430 171 struct {
aa839030 172 wordlist *server_msg;
173 char *request;
174 char *reply;
0477a072
AJ
175 char *cwd_msg;
176 MemBuf *listing;
3d0ac046 177 } ftp;
aa839030 178
aa839030 179 char *request_hdrs;
180 char *err_msg; /* Preformatted error message from the cache */
2cc81f1f 181
4d16918e
CT
182#if USE_SSL
183 Ssl::ErrorDetail *detail;
184#endif
2cc81f1f 185private:
aa839030 186 CBDATA_CLASS2(ErrorState);
187};
188
63be0a78 189/**
190 \ingroup ErrorPageAPI
191 *
192 * This function finds the error messages formats, and stores
193 * them in error_text[]
194 *
195 \par Global effects:
196 * error_text[] - is modified
197 */
aa839030 198SQUIDCEXTERN void errorInitialize(void);
63be0a78 199
200/// \ingroup ErrorPageAPI
aa839030 201SQUIDCEXTERN void errorClean(void);
63be0a78 202
63be0a78 203/**
27774cee 204 * \ingroup ErrorPageAPI
63be0a78 205 *
206 * This function generates a error page from the info contained
207 * by err and then sends it to the client.
208 * The callback function errorSendComplete() is called after
e0d28505 209 * the page has been written to the client (clientConn).
63be0a78 210 * errorSendComplete() deallocates err. We need to add
211 * err to the cbdata because comm_write() requires it
212 * for all callback data pointers.
213 *
214 \note normally errorSend() should only be called from
215 * routines in ssl.c and pass.c, where we don't have any
216 * StoreEntry's. In client_side.c we must allocate a StoreEntry
217 * for errors and use errorAppendEntry() to account for
218 * persistent/pipeline connections.
219 *
1b76e6c1
AJ
220 \param clientConn socket where page object is to be written
221 \param err This object is destroyed after use in this function.
63be0a78 222 */
e0d28505 223SQUIDCEXTERN void errorSend(const Comm::ConnectionPointer &conn, ErrorState *err);
63be0a78 224
225/**
226 \ingroup ErrorPageAPI
227 *
228 * This function generates a error page from the info contained
229 * by err and then stores the text in the specified store
230 * entry.
231 * This function should only be called by "server
232 * side routines" which need to communicate errors to the
233 * client side. It should also be called from client_side.c
234 * because we now support persistent connections, and
235 * cannot assume that we can immediately write to the socket
236 * for an error.
237 *
238 \param entry ??
239 \param err This object is destroyed after use in this function.
240 */
241SQUIDCEXTERN void errorAppendEntry(StoreEntry *entry, ErrorState *err);
242
63be0a78 243/// \ingroup ErrorPageAPI
aa839030 244SQUIDCEXTERN err_type errorReservePageId(const char *page_name);
aa839030 245
64b66b76 246SQUIDCEXTERN const char *errorPageName(int pageId); ///< error ID to string
aa839030 247
02259ff8
CT
248/**
249 \ingroup ErrorPageAPI
250 *
251 * loads text templates used for error pages and details;
252 * supports translation of templates
253 */
dc49061a
A
254class TemplateFile
255{
02259ff8
CT
256public:
257 TemplateFile(const char *name);
dc49061a 258 virtual ~TemplateFile() {}
02259ff8
CT
259
260 /// return true if the data loaded from disk without any problem
261 bool loaded() const {return wasLoaded;}
262
263 /**
264 * Load the page_name template from a file which probably exist at:
265 * (a) admin specified custom directory (error_directory)
266 * (b) default language translation directory (error_default_language)
267 * (c) English sub-directory where errors should ALWAYS exist
268 */
269 bool loadDefault();
270
271 /**
272 * Load an error template for a given HTTP request. This function examines the
273 * Accept-Language header and select the first available template. If the default
274 * template selected (eg because of a "Accept-Language: *"), or not available
275 * template found this function return false.
276 */
277 bool loadFor(HttpRequest *request);
278
279 /**
280 * Load the file given by "path". It uses the "parse()" method.
281 * On success return true and sets the "defined" member
282 */
283 bool loadFromFile(const char *path);
284
285 /// The language used for the template
286 const char *language() {return errLanguage.termedBuf();}
287
288 bool silent; ///< Whether to print error messages on cache.log file or not. It is user defined.
289
290protected:
291 /// Used to parse (if parsing required) the template data .
292 virtual bool parse(const char *buf, int len, bool eof) = 0;
293
294 /**
295 * Try to load the "page_name" template for a given language "lang"
296 * from squid errors directory
297 \return true on success false otherwise
298 */
299 bool tryLoadTemplate(const char *lang);
300
301 bool wasLoaded; ///< True if the template data read from disk without any problem
302 String errLanguage; ///< The error language of the template.
303 String templateName; ///< The name of the template
304};
305
306/**
307 * Parses the Accept-Language header value and return one language item on
308 * each call.
309 * \param hdr is the Accept-Language header value
310 * \param lang a buffer given by the user to store parsed language
311 * \param langlen the length of the lang buffer
312 * \param pos it is used to store the state of parsing. Must be "0" on first call
313 * \return true on success, false otherwise
314 */
315bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos);
aa839030 316#endif /* SQUID_ERRORPAGE_H */