2 * DEBUG: section 04 Error Generation
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
31 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
34 #ifndef SQUID_ERRORPAGE_H
35 #define SQUID_ERRORPAGE_H
39 #include "auth/UserRequest.h"
42 #include "ip/Address.h"
44 #include "ssl/ErrorDetail.h"
48 \defgroup ErrorPageAPI Error Pages API
50 \section ErrorPageStringCodes Error Page % codes for text insertion.
54 B - URL with FTP %2f hack x
55 c - Squid error code x
56 d - seconds elapsed since request received x
60 f - FTP request line x
62 g - FTP server message 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
70 m - Error message returned by auth helper x
71 o - Message returned external acl helper x
74 R - Full HTTP Request x
75 S - squid signature from ERR_SIGNATURE x
76 s - caching proxy software with version 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)
84 z - dns server error message x
85 Z - Preformatted error message x
92 /// \ingroup ErrorPageAPI
97 * Allocates and initializes an error response
99 HttpReply
*BuildHttpReply(void);
103 * Locates error page template to be used for this error
104 * and constructs the HTML page content from it.
106 MemBuf
*BuildContent(void);
109 * Convert the given template string into textual output
111 * \param text The string to be converted
112 * \param allowRecursion Whether to convert codes which output may contain codes
114 MemBuf
*ConvertText(const char *text
, bool allowRecursion
);
117 * Generates the Location: header value for a deny_info error page
118 * to be used for this error.
120 void DenyInfoLocation(const char *name
, HttpRequest
*request
, MemBuf
&result
);
123 * Map the Error page and deny_info template % codes into textual output.
125 * Several of the codes produce blocks of non-URL compatible results.
126 * When processing the deny_info location URL they will be skipped.
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
132 const char *Convert(char token
, bool building_deny_info_url
, bool allowRecursion
);
135 * CacheManager / Debug dump of the ErrorState object.
136 * Writes output into the given MemBuf.
137 \retval 0 successful completion.
139 int Dump(MemBuf
* mb
);
145 http_status httpStatus
;
147 AuthUserRequest::Pointer auth_user_request
;
149 HttpRequest
*request
;
153 String dnsError
; ///< DNS lookup error message
156 Ip::Address src_addr
;
162 unsigned int flag_cbdata
:1;
166 wordlist
*server_msg
;
174 char *err_msg
; /* Preformatted error message from the cache */
177 Ssl::ErrorDetail
*detail
;
180 CBDATA_CLASS2(ErrorState
);
184 \ingroup ErrorPageAPI
186 * This function finds the error messages formats, and stores
187 * them in error_text[]
190 * error_text[] - is modified
192 SQUIDCEXTERN
void errorInitialize(void);
194 /// \ingroup ErrorPageAPI
195 SQUIDCEXTERN
void errorClean(void);
198 * \ingroup ErrorPageAPI
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.
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.
214 \param fd socket where page object is to be written
215 \param err This object is destroyed after use in this function.
217 SQUIDCEXTERN
void errorSend(int fd
, ErrorState
*err
);
220 \ingroup ErrorPageAPI
222 * This function generates a error page from the info contained
223 * by err and then stores the text in the specified store
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
233 \param err This object is destroyed after use in this function.
235 SQUIDCEXTERN
void errorAppendEntry(StoreEntry
*entry
, ErrorState
*err
);
237 /// \ingroup ErrorPageAPI
238 SQUIDCEXTERN
void errorStateFree(ErrorState
* err
);
240 /// \ingroup ErrorPageAPI
241 SQUIDCEXTERN err_type
errorReservePageId(const char *page_name
);
244 \ingroup ErrorPageAPI
246 * This function creates a ErrorState object.
248 SQUIDCEXTERN ErrorState
*errorCon(err_type type
, http_status
, HttpRequest
* request
);
249 SQUIDCEXTERN
const char *errorPageName(int pageId
); ///< error ID to string
251 #endif /* SQUID_ERRORPAGE_H */