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