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