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)
83 z - dns server error message x
84 Z - Preformatted error message x
91 /// \ingroup ErrorPageAPI
96 * Allocates and initializes an error response
98 HttpReply
*BuildHttpReply(void);
102 * Locates error page template to be used for this error
103 * and constructs the HTML page content from it.
105 MemBuf
*BuildContent(void);
108 * Convert the given template string into textual output
110 * \param text The string to be converted
111 * \param allowRecursion Whether to convert codes which output may contain codes
113 MemBuf
*ConvertText(const char *text
, bool allowRecursion
);
116 * Generates the Location: header value for a deny_info error page
117 * to be used for this error.
119 void DenyInfoLocation(const char *name
, HttpRequest
*request
, MemBuf
&result
);
122 * Map the Error page and deny_info template % codes into textual output.
124 * Several of the codes produce blocks of non-URL compatible results.
125 * When processing the deny_info location URL they will be skipped.
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
131 const char *Convert(char token
, bool building_deny_info_url
, bool allowRecursion
);
134 * CacheManager / Debug dump of the ErrorState object.
135 * Writes output into the given MemBuf.
136 \retval 0 successful completion.
138 int Dump(MemBuf
* mb
);
144 http_status httpStatus
;
146 AuthUserRequest::Pointer auth_user_request
;
148 HttpRequest
*request
;
152 String dnsError
; ///< DNS lookup error message
155 Ip::Address src_addr
;
161 unsigned int flag_cbdata
:1;
165 wordlist
*server_msg
;
173 char *err_msg
; /* Preformatted error message from the cache */
176 Ssl::ErrorDetail
*detail
;
179 CBDATA_CLASS2(ErrorState
);
183 \ingroup ErrorPageAPI
185 * This function finds the error messages formats, and stores
186 * them in error_text[]
189 * error_text[] - is modified
191 SQUIDCEXTERN
void errorInitialize(void);
193 /// \ingroup ErrorPageAPI
194 SQUIDCEXTERN
void errorClean(void);
197 \ingroup ErrorPageAPI
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.
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.
213 \param fd socket where page object is to be written
214 \param err This object is destroyed after use in this function.
216 SQUIDCEXTERN
void errorSend(int fd
, ErrorState
*err
);
219 \ingroup ErrorPageAPI
221 * This function generates a error page from the info contained
222 * by err and then stores the text in the specified store
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
232 \param err This object is destroyed after use in this function.
234 SQUIDCEXTERN
void errorAppendEntry(StoreEntry
*entry
, ErrorState
*err
);
236 /// \ingroup ErrorPageAPI
237 SQUIDCEXTERN
void errorStateFree(ErrorState
* err
);
239 /// \ingroup ErrorPageAPI
240 SQUIDCEXTERN err_type
errorReservePageId(const char *page_name
);
243 \ingroup ErrorPageAPI
245 * This function creates a ErrorState object.
247 SQUIDCEXTERN ErrorState
*errorCon(err_type type
, http_status
, HttpRequest
* request
);
248 SQUIDCEXTERN
const char *errorPageName(int pageId
); ///< error ID to string
250 #endif /* SQUID_ERRORPAGE_H */