]> git.ipfire.org Git - thirdparty/squid.git/blob - src/errorpage.h
Merged from trunk.
[thirdparty/squid.git] / src / errorpage.h
1 /*
2 * $Id: errorpage.h,v 1.6 2008/02/26 21:49:34 amosjeffries Exp $
3 *
4 * DEBUG: section 4 Error Generation
5 * AUTHOR: Duane Wessels
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
34 */
35
36 #ifndef SQUID_ERRORPAGE_H
37 #define SQUID_ERRORPAGE_H
38
39 #include "squid.h"
40 #include "cbdata.h"
41 #include "IPAddress.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 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 AuthUserRequest;
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 * Convert an error template into an error page.
104 */
105 const char *Convert(char token);
106
107 /**
108 * CacheManager / Debug dump of the ErrorState object.
109 * Writes output into the given MemBuf.
110 \retval 0 successful completion.
111 */
112 int Dump(MemBuf * mb);
113
114 public:
115 err_type type;
116 int page_id;
117 char *err_language;
118 http_status httpStatus;
119 AuthUserRequest *auth_user_request;
120 HttpRequest *request;
121 char *url;
122 int xerrno;
123 u_short port;
124 char *dnsserver_msg;
125 time_t ttl;
126
127 IPAddress src_addr;
128 char *redirect_url;
129 ERCB *callback;
130 void *callback_data;
131
132 struct
133 {
134 unsigned int flag_cbdata:1;
135 } flags;
136
137 struct
138 {
139 wordlist *server_msg;
140 char *request;
141 char *reply;
142 } ftp;
143
144 char *request_hdrs;
145 char *err_msg; /* Preformatted error message from the cache */
146
147 private:
148 CBDATA_CLASS2(ErrorState);
149 };
150
151 /**
152 \ingroup ErrorPageAPI
153 *
154 * This function finds the error messages formats, and stores
155 * them in error_text[]
156 *
157 \par Global effects:
158 * error_text[] - is modified
159 */
160 SQUIDCEXTERN void errorInitialize(void);
161
162 /// \ingroup ErrorPageAPI
163 SQUIDCEXTERN void errorClean(void);
164
165 /**
166 \ingroup ErrorPageAPI
167 *
168 * This function generates a error page from the info contained
169 * by err and then sends it to the client.
170 * The callback function errorSendComplete() is called after
171 * the page has been written to the client socket (fd).
172 * errorSendComplete() deallocates err. We need to add
173 * err to the cbdata because comm_write() requires it
174 * for all callback data pointers.
175 *
176 \note normally errorSend() should only be called from
177 * routines in ssl.c and pass.c, where we don't have any
178 * StoreEntry's. In client_side.c we must allocate a StoreEntry
179 * for errors and use errorAppendEntry() to account for
180 * persistent/pipeline connections.
181 *
182 \param fd socket where page object is to be written
183 \param err This object is destroyed after use in this function.
184 */
185 SQUIDCEXTERN void errorSend(int fd, ErrorState *err);
186
187 /**
188 \ingroup ErrorPageAPI
189 *
190 * This function generates a error page from the info contained
191 * by err and then stores the text in the specified store
192 * entry.
193 * This function should only be called by "server
194 * side routines" which need to communicate errors to the
195 * client side. It should also be called from client_side.c
196 * because we now support persistent connections, and
197 * cannot assume that we can immediately write to the socket
198 * for an error.
199 *
200 \param entry ??
201 \param err This object is destroyed after use in this function.
202 */
203 SQUIDCEXTERN void errorAppendEntry(StoreEntry *entry, ErrorState *err);
204
205 /// \ingroup ErrorPageAPI
206 SQUIDCEXTERN void errorStateFree(ErrorState * err);
207
208 /// \ingroup ErrorPageAPI
209 SQUIDCEXTERN err_type errorReservePageId(const char *page_name);
210
211 /**
212 \ingroup ErrorPageAPI
213 *
214 * This function creates a ErrorState object.
215 */
216 SQUIDCEXTERN ErrorState *errorCon(err_type type, http_status, HttpRequest * request);
217
218 #endif /* SQUID_ERRORPAGE_H */