]> git.ipfire.org Git - thirdparty/squid.git/blob - src/errorpage.h
Cleanup: polish some code comments
[thirdparty/squid.git] / src / errorpage.h
1 /*
2 * DEBUG: section 04 Error Generation
3 * AUTHOR: Duane Wessels
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.
21 *
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.
26 *
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
37 #include "squid.h"
38 #if USE_AUTH
39 #include "auth/UserRequest.h"
40 #endif
41 #include "cbdata.h"
42 #include "ip/Address.h"
43 #if USE_SSL
44 #include "ssl/ErrorDetail.h"
45 #endif
46
47 /**
48 \defgroup ErrorPageAPI Error Pages API
49 \ingroup Components
50 \section ErrorPageStringCodes Error Page % codes for text insertion.
51 *
52 \verbatim
53 a - User identity x
54 B - URL with FTP %2f hack x
55 c - Squid error code x
56 d - seconds elapsed since request received x
57 D - Error details x
58 e - errno x
59 E - strerror() x
60 f - FTP request line x
61 F - FTP reply line x
62 g - FTP server message x
63 h - cache hostname x
64 H - server host name x
65 i - client IP address x
66 I - server IP address x
67 l - HREF link for CSS stylesheet inclusion x
68 L - HREF link for more info/contact x
69 M - Request Method x
70 m - Error message returned by auth helper x
71 o - Message returned external acl helper x
72 p - URL port # x
73 P - Protocol x
74 R - Full HTTP Request x
75 S - squid signature from ERR_SIGNATURE x
76 s - caching proxy software with version x
77 t - local time x
78 T - UTC x
79 U - URL without password x
80 u - URL with password x
81 w - cachemgr email address x
82 W - error data (to be included in the mailto links)
83 x - error name x
84 z - dns server error message x
85 Z - Preformatted error message x
86 \endverbatim
87 */
88
89 class HttpReply;
90 class MemBuf;
91
92 /// \ingroup ErrorPageAPI
93 class ErrorState
94 {
95 public:
96 /**
97 * Allocates and initializes an error response
98 */
99 HttpReply *BuildHttpReply(void);
100
101 private:
102 /**
103 * Locates error page template to be used for this error
104 * and constructs the HTML page content from it.
105 */
106 MemBuf *BuildContent(void);
107
108 /**
109 * Convert the given template string into textual output
110 *
111 * \param text The string to be converted
112 * \param allowRecursion Whether to convert codes which output may contain codes
113 */
114 MemBuf *ConvertText(const char *text, bool allowRecursion);
115
116 /**
117 * Generates the Location: header value for a deny_info error page
118 * to be used for this error.
119 */
120 void DenyInfoLocation(const char *name, HttpRequest *request, MemBuf &result);
121
122 /**
123 * Map the Error page and deny_info template % codes into textual output.
124 *
125 * Several of the codes produce blocks of non-URL compatible results.
126 * When processing the deny_info location URL they will be skipped.
127 *
128 * \param token The token following % which need to be converted
129 * \param building_deny_info_url Perform special deny_info actions, such as URL-encoding and token skipping.
130 * \ allowRecursion True if the codes which do recursions should converted
131 */
132 const char *Convert(char token, bool building_deny_info_url, bool allowRecursion);
133
134 /**
135 * CacheManager / Debug dump of the ErrorState object.
136 * Writes output into the given MemBuf.
137 \retval 0 successful completion.
138 */
139 int Dump(MemBuf * mb);
140
141 public:
142 err_type type;
143 int page_id;
144 char *err_language;
145 http_status httpStatus;
146 #if USE_AUTH
147 AuthUserRequest::Pointer auth_user_request;
148 #endif
149 HttpRequest *request;
150 char *url;
151 int xerrno;
152 u_short port;
153 String dnsError; ///< DNS lookup error message
154 time_t ttl;
155
156 Ip::Address src_addr;
157 char *redirect_url;
158 ERCB *callback;
159 void *callback_data;
160
161 struct {
162 unsigned int flag_cbdata:1;
163 } flags;
164
165 struct {
166 wordlist *server_msg;
167 char *request;
168 char *reply;
169 char *cwd_msg;
170 MemBuf *listing;
171 } ftp;
172
173 char *request_hdrs;
174 char *err_msg; /* Preformatted error message from the cache */
175
176 #if USE_SSL
177 Ssl::ErrorDetail *detail;
178 #endif
179 private:
180 CBDATA_CLASS2(ErrorState);
181 };
182
183 /**
184 \ingroup ErrorPageAPI
185 *
186 * This function finds the error messages formats, and stores
187 * them in error_text[]
188 *
189 \par Global effects:
190 * error_text[] - is modified
191 */
192 SQUIDCEXTERN void errorInitialize(void);
193
194 /// \ingroup ErrorPageAPI
195 SQUIDCEXTERN void errorClean(void);
196
197 /**
198 * \ingroup ErrorPageAPI
199 *
200 * This function generates a error page from the info contained
201 * by err and then sends it to the client.
202 * The callback function errorSendComplete() is called after
203 * the page has been written to the client socket (fd).
204 * errorSendComplete() deallocates err. We need to add
205 * err to the cbdata because comm_write() requires it
206 * for all callback data pointers.
207 *
208 \note normally errorSend() should only be called from
209 * routines in ssl.c and pass.c, where we don't have any
210 * StoreEntry's. In client_side.c we must allocate a StoreEntry
211 * for errors and use errorAppendEntry() to account for
212 * persistent/pipeline connections.
213 *
214 \param fd socket where page object is to be written
215 \param err This object is destroyed after use in this function.
216 */
217 SQUIDCEXTERN void errorSend(int fd, ErrorState *err);
218
219 /**
220 \ingroup ErrorPageAPI
221 *
222 * This function generates a error page from the info contained
223 * by err and then stores the text in the specified store
224 * entry.
225 * This function should only be called by "server
226 * side routines" which need to communicate errors to the
227 * client side. It should also be called from client_side.c
228 * because we now support persistent connections, and
229 * cannot assume that we can immediately write to the socket
230 * for an error.
231 *
232 \param entry ??
233 \param err This object is destroyed after use in this function.
234 */
235 SQUIDCEXTERN void errorAppendEntry(StoreEntry *entry, ErrorState *err);
236
237 /// \ingroup ErrorPageAPI
238 SQUIDCEXTERN void errorStateFree(ErrorState * err);
239
240 /// \ingroup ErrorPageAPI
241 SQUIDCEXTERN err_type errorReservePageId(const char *page_name);
242
243 /**
244 \ingroup ErrorPageAPI
245 *
246 * This function creates a ErrorState object.
247 */
248 SQUIDCEXTERN ErrorState *errorCon(err_type type, http_status, HttpRequest * request);
249 SQUIDCEXTERN const char *errorPageName(int pageId); ///< error ID to string
250
251 #endif /* SQUID_ERRORPAGE_H */