]> git.ipfire.org Git - thirdparty/squid.git/blob - src/errorpage.h
Bug 2870: --disable-auth does not work
[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 z - dns server error message x
84 Z - Preformatted error message x
85 \endverbatim
86 */
87
88 class HttpReply;
89 class MemBuf;
90
91 /// \ingroup ErrorPageAPI
92 class ErrorState
93 {
94 public:
95 /**
96 * Allocates and initializes an error response
97 */
98 HttpReply *BuildHttpReply(void);
99
100 private:
101 /**
102 * Locates error page template to be used for this error
103 * and constructs the HTML page content from it.
104 */
105 MemBuf *BuildContent(void);
106
107 /**
108 * Convert the given template string into textual output
109 *
110 * \param text The string to be converted
111 * \param allowRecursion Whether to convert codes which output may contain codes
112 */
113 MemBuf *ConvertText(const char *text, bool allowRecursion);
114
115 /**
116 * Generates the Location: header value for a deny_info error page
117 * to be used for this error.
118 */
119 void DenyInfoLocation(const char *name, HttpRequest *request, MemBuf &result);
120
121 /**
122 * Map the Error page and deny_info template % codes into textual output.
123 *
124 * Several of the codes produce blocks of non-URL compatible results.
125 * When processing the deny_info location URL they will be skipped.
126 *
127 * \param token The token following % which need to be converted
128 * \param building_deny_info_url Perform special deny_info actions, such as URL-encoding and token skipping.
129 * \ allowRecursion True if the codes which do recursions should converted
130 */
131 const char *Convert(char token, bool building_deny_info_url, bool allowRecursion);
132
133 /**
134 * CacheManager / Debug dump of the ErrorState object.
135 * Writes output into the given MemBuf.
136 \retval 0 successful completion.
137 */
138 int Dump(MemBuf * mb);
139
140 public:
141 err_type type;
142 int page_id;
143 char *err_language;
144 http_status httpStatus;
145 #if USE_AUTH
146 AuthUserRequest::Pointer auth_user_request;
147 #endif
148 HttpRequest *request;
149 char *url;
150 int xerrno;
151 u_short port;
152 String dnsError; ///< DNS lookup error message
153 time_t ttl;
154
155 Ip::Address src_addr;
156 char *redirect_url;
157 ERCB *callback;
158 void *callback_data;
159
160 struct {
161 unsigned int flag_cbdata:1;
162 } flags;
163
164 struct {
165 wordlist *server_msg;
166 char *request;
167 char *reply;
168 char *cwd_msg;
169 MemBuf *listing;
170 } ftp;
171
172 char *request_hdrs;
173 char *err_msg; /* Preformatted error message from the cache */
174
175 #if USE_SSL
176 Ssl::ErrorDetail *detail;
177 #endif
178 private:
179 CBDATA_CLASS2(ErrorState);
180 };
181
182 /**
183 \ingroup ErrorPageAPI
184 *
185 * This function finds the error messages formats, and stores
186 * them in error_text[]
187 *
188 \par Global effects:
189 * error_text[] - is modified
190 */
191 SQUIDCEXTERN void errorInitialize(void);
192
193 /// \ingroup ErrorPageAPI
194 SQUIDCEXTERN void errorClean(void);
195
196 /**
197 \ingroup ErrorPageAPI
198 *
199 * This function generates a error page from the info contained
200 * by err and then sends it to the client.
201 * The callback function errorSendComplete() is called after
202 * the page has been written to the client socket (fd).
203 * errorSendComplete() deallocates err. We need to add
204 * err to the cbdata because comm_write() requires it
205 * for all callback data pointers.
206 *
207 \note normally errorSend() should only be called from
208 * routines in ssl.c and pass.c, where we don't have any
209 * StoreEntry's. In client_side.c we must allocate a StoreEntry
210 * for errors and use errorAppendEntry() to account for
211 * persistent/pipeline connections.
212 *
213 \param fd socket where page object is to be written
214 \param err This object is destroyed after use in this function.
215 */
216 SQUIDCEXTERN void errorSend(int fd, ErrorState *err);
217
218 /**
219 \ingroup ErrorPageAPI
220 *
221 * This function generates a error page from the info contained
222 * by err and then stores the text in the specified store
223 * entry.
224 * This function should only be called by "server
225 * side routines" which need to communicate errors to the
226 * client side. It should also be called from client_side.c
227 * because we now support persistent connections, and
228 * cannot assume that we can immediately write to the socket
229 * for an error.
230 *
231 \param entry ??
232 \param err This object is destroyed after use in this function.
233 */
234 SQUIDCEXTERN void errorAppendEntry(StoreEntry *entry, ErrorState *err);
235
236 /// \ingroup ErrorPageAPI
237 SQUIDCEXTERN void errorStateFree(ErrorState * err);
238
239 /// \ingroup ErrorPageAPI
240 SQUIDCEXTERN err_type errorReservePageId(const char *page_name);
241
242 /**
243 \ingroup ErrorPageAPI
244 *
245 * This function creates a ErrorState object.
246 */
247 SQUIDCEXTERN ErrorState *errorCon(err_type type, http_status, HttpRequest * request);
248 SQUIDCEXTERN const char *errorPageName(int pageId); ///< error ID to string
249
250 #endif /* SQUID_ERRORPAGE_H */