]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/errorpage.cc
4 * DEBUG: section 04 Error Generation
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
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.
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.
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.
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.
36 #include "errorpage.h"
37 #include "auth/UserRequest.h"
38 #include "SquidTime.h"
40 #include "HttpReply.h"
41 #include "HttpRequest.h"
42 #include "MemObject.h"
46 #include "URLScheme.h"
50 \defgroup ErrorPageInternal Error Page Internals
53 \section Abstract Abstract:
54 * These routines are used to generate error messages to be
55 * sent to clients. The error type is used to select between
56 * the various message formats. (formats are stored in the
57 * Config.errorDirectory)
61 #ifndef DEFAULT_SQUID_ERROR_DIR
62 /** Where to look for errors if config path fails.
63 \note Please use ./configure --datadir=/path instead of patching
65 #define DEFAULT_SQUID_ERROR_DIR DEFAULT_SQUID_DATA_DIR"/errors"
68 /// \ingroup ErrorPageInternal
69 CBDATA_CLASS_INIT(ErrorState
);
73 /// \ingroup ErrorPageInternal
77 } ErrorDynamicPageInfo
;
79 /* local constant and vars */
82 \ingroup ErrorPageInternal
84 \note hard coded error messages are not appended with %S
85 * automagically to give you more control on the format
88 int type
; /* and page_id */
98 "<div id=\"footer\">\n"
99 "Generated %T by %h (%s)\n"
109 /// \ingroup ErrorPageInternal
110 static Vector
<ErrorDynamicPageInfo
*> ErrorDynamicPages
;
112 /* local prototypes */
114 /// \ingroup ErrorPageInternal
115 static const int error_hard_text_count
= sizeof(error_hard_text
) / sizeof(*error_hard_text
);
117 /// \ingroup ErrorPageInternal
118 static char **error_text
= NULL
;
120 /// \ingroup ErrorPageInternal
121 static int error_page_count
= 0;
123 /// \ingroup ErrorPageInternal
124 static MemBuf error_stylesheet
;
126 static char *errorTryLoadText(const char *page_name
, const char *dir
, bool silent
= false);
127 static char *errorLoadText(const char *page_name
);
128 static const char *errorFindHardText(err_type type
);
129 static ErrorDynamicPageInfo
*errorDynamicPageInfoCreate(int id
, const char *page_name
);
130 static void errorDynamicPageInfoDestroy(ErrorDynamicPageInfo
* info
);
131 static IOCB errorSendComplete
;
134 /// \ingroup ErrorPageInternal
135 err_type
&operator++ (err_type
&anErr
)
137 int tmp
= (int)anErr
;
138 anErr
= (err_type
)(++tmp
);
142 /// \ingroup ErrorPageInternal
143 int operator - (err_type
const &anErr
, err_type
const &anErr2
)
145 return (int)anErr
- (int)anErr2
;
149 errorInitialize(void)
153 error_page_count
= ERR_MAX
+ ErrorDynamicPages
.size();
154 error_text
= static_cast<char **>(xcalloc(error_page_count
, sizeof(char *)));
156 for (i
= ERR_NONE
, ++i
; i
< error_page_count
; ++i
) {
157 safe_free(error_text
[i
]);
159 if ((text
= errorFindHardText(i
))) {
161 * Index any hard-coded error text into defaults.
163 error_text
[i
] = xstrdup(text
);
165 } else if (i
< ERR_MAX
) {
167 * Index precompiled fixed template files from one of two sources:
168 * (a) default language translation directory (error_default_language)
169 * (b) admin specified custom directory (error_directory)
171 error_text
[i
] = errorLoadText(err_type_str
[i
]);
175 * Index any unknown file names used by deny_info.
177 ErrorDynamicPageInfo
*info
= ErrorDynamicPages
.items
[i
- ERR_MAX
];
178 assert(info
&& info
->id
== i
&& info
->page_name
);
180 if (strchr(info
->page_name
, ':') == NULL
) {
181 /** But only if they are not redirection URL. */
182 error_text
[i
] = errorLoadText(info
->page_name
);
187 error_stylesheet
.reset();
189 // look for and load stylesheet into global MemBuf for it.
190 if (Config
.errorStylesheet
) {
191 char *temp
= errorTryLoadText(Config
.errorStylesheet
,NULL
);
193 error_stylesheet
.Printf("%s",temp
);
205 for (i
= ERR_NONE
+ 1; i
< error_page_count
; i
++)
206 safe_free(error_text
[i
]);
208 safe_free(error_text
);
211 while (ErrorDynamicPages
.size())
212 errorDynamicPageInfoDestroy(ErrorDynamicPages
.pop_back());
214 error_page_count
= 0;
217 /// \ingroup ErrorPageInternal
219 errorFindHardText(err_type type
)
223 for (i
= 0; i
< error_hard_text_count
; i
++)
224 if (error_hard_text
[i
].type
== type
)
225 return error_hard_text
[i
].text
;
231 * \ingroup ErrorPageInternal
233 * Load into the in-memory error text Index a file probably available at:
234 * (a) admin specified custom directory (error_directory)
235 * (b) default language translation directory (error_default_language)
236 * (c) English sub-directory where errors should ALWAYS exist
239 errorLoadText(const char *page_name
)
243 /** test error_directory configured location */
244 if (Config
.errorDirectory
)
245 text
= errorTryLoadText(page_name
, Config
.errorDirectory
);
248 /** test error_default_language location */
249 if (!text
&& Config
.errorDefaultLanguage
) {
251 snprintf(dir
,256,"%s/%s", DEFAULT_SQUID_ERROR_DIR
, Config
.errorDefaultLanguage
);
252 text
= errorTryLoadText(page_name
, dir
);
254 debugs(1, DBG_CRITICAL
, "Unable to load default error language files. Reset to backups.");
259 /* test default location if failed (templates == English translation base templates) */
261 text
= errorTryLoadText(page_name
, DEFAULT_SQUID_ERROR_DIR
"/templates");
264 /* giving up if failed */
266 fatal("failed to find or read error text file.");
271 /// \ingroup ErrorPageInternal
273 errorTryLoadText(const char *page_name
, const char *dir
, bool silent
)
276 char path
[MAXPATHLEN
];
282 // maybe received compound parts, maybe an absolute page_name and no dir
284 snprintf(path
, sizeof(path
), "%s/%s", dir
, page_name
);
286 snprintf(path
, sizeof(path
), "%s", page_name
);
288 fd
= file_open(path
, O_RDONLY
| O_TEXT
);
291 /* with dynamic locale negotiation we may see some failures before a success. */
293 debugs(4, DBG_CRITICAL
, HERE
<< "'" << path
<< "': " << xstrerror());
299 while ((len
= FD_READ_METHOD(fd
, buf
, sizeof(buf
))) > 0) {
300 textbuf
.append(buf
, len
);
304 debugs(4, DBG_CRITICAL
, HERE
<< "failed to fully read: '" << path
<< "': " << xstrerror());
309 /* Shrink memory size down to exact size. MemBuf has a tencendy
310 * to be rather large..
312 text
= xstrdup(textbuf
.buf
);
319 /// \ingroup ErrorPageInternal
320 static ErrorDynamicPageInfo
*
321 errorDynamicPageInfoCreate(int id
, const char *page_name
)
323 ErrorDynamicPageInfo
*info
= new ErrorDynamicPageInfo
;
325 info
->page_name
= xstrdup(page_name
);
329 /// \ingroup ErrorPageInternal
331 errorDynamicPageInfoDestroy(ErrorDynamicPageInfo
* info
)
334 safe_free(info
->page_name
);
338 /// \ingroup ErrorPageInternal
340 errorPageId(const char *page_name
)
342 for (int i
= 0; i
< ERR_MAX
; i
++) {
343 if (strcmp(err_type_str
[i
], page_name
) == 0)
347 for (size_t j
= 0; j
< ErrorDynamicPages
.size(); j
++) {
348 if (strcmp(ErrorDynamicPages
.items
[j
]->page_name
, page_name
) == 0)
356 errorReservePageId(const char *page_name
)
358 ErrorDynamicPageInfo
*info
;
359 int id
= errorPageId(page_name
);
361 if (id
== ERR_NONE
) {
362 info
= errorDynamicPageInfoCreate(ERR_MAX
+ ErrorDynamicPages
.size(), page_name
);
363 ErrorDynamicPages
.push_back(info
);
370 /// \ingroup ErrorPageInternal
372 errorPageName(int pageId
)
374 if (pageId
>= ERR_NONE
&& pageId
< ERR_MAX
) /* common case */
375 return err_type_str
[pageId
];
377 if (pageId
>= ERR_MAX
&& pageId
- ERR_MAX
< (ssize_t
)ErrorDynamicPages
.size())
378 return ErrorDynamicPages
.items
[pageId
- ERR_MAX
]->page_name
;
380 return "ERR_UNKNOWN"; /* should not happen */
384 errorCon(err_type type
, http_status status
, HttpRequest
* request
)
386 ErrorState
*err
= new ErrorState
;
387 err
->page_id
= type
; /* has to be reset manually if needed */
388 err
->err_language
= NULL
;
390 err
->httpStatus
= status
;
392 if (request
!= NULL
) {
393 err
->request
= HTTPMSGLOCK(request
);
394 err
->src_addr
= request
->client_addr
;
401 errorAppendEntry(StoreEntry
* entry
, ErrorState
* err
)
403 assert(entry
->mem_obj
!= NULL
);
404 assert (entry
->isEmpty());
405 debugs(4, 4, "Creating an error page for entry " << entry
<<
406 " with errorstate " << err
<<
407 " page id " << err
->page_id
);
409 if (entry
->store_status
!= STORE_PENDING
) {
410 debugs(4, 2, "Skipping error page due to store_status: " << entry
->store_status
);
412 * If the entry is not STORE_PENDING, then no clients
413 * care about it, and we don't need to generate an
416 assert(EBIT_TEST(entry
->flags
, ENTRY_ABORTED
));
417 assert(entry
->mem_obj
->nclients
== 0);
422 if (err
->page_id
== TCP_RESET
) {
424 debugs(4, 2, "RSTing this reply");
425 err
->request
->flags
.setResetTCP();
431 entry
->replaceHttpReply( err
->BuildHttpReply() );
432 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
435 entry
->negativeCache();
436 entry
->releaseRequest();
442 errorSend(int fd
, ErrorState
* err
)
445 debugs(4, 3, "errorSend: FD " << fd
<< ", err=" << err
);
448 * ugh, this is how we make sure error codes get back to
449 * the client side for logging and error tracking.
453 err
->request
->errType
= err
->type
;
455 /* moved in front of errorBuildBuf @?@ */
456 err
->flags
.flag_cbdata
= 1;
458 rep
= err
->BuildHttpReply();
460 comm_write_mbuf(fd
, rep
->pack(), errorSendComplete
, err
);
466 \ingroup ErrorPageAPI
468 * Called by commHandleWrite() after data has been written
469 * to the client socket.
471 \note If there is a callback, the callback is responsible for
472 * closing the FD, otherwise we do it ourselves.
475 errorSendComplete(int fd
, char *bufnotused
, size_t size
, comm_err_t errflag
, int xerrno
, void *data
)
477 ErrorState
*err
= static_cast<ErrorState
*>(data
);
478 debugs(4, 3, "errorSendComplete: FD " << fd
<< ", size=" << size
);
480 if (errflag
!= COMM_ERR_CLOSING
) {
482 debugs(4, 3, "errorSendComplete: callback");
483 err
->callback(fd
, err
->callback_data
, size
);
486 debugs(4, 3, "errorSendComplete: comm_close");
494 errorStateFree(ErrorState
* err
)
496 HTTPMSGUNLOCK(err
->request
);
497 safe_free(err
->redirect_url
);
499 safe_free(err
->request_hdrs
);
500 wordlistDestroy(&err
->ftp
.server_msg
);
501 safe_free(err
->ftp
.request
);
502 safe_free(err
->ftp
.reply
);
503 AUTHUSERREQUESTUNLOCK(err
->auth_user_request
, "errstate");
504 safe_free(err
->err_msg
);
506 if (err
->err_language
!= Config
.errorDefaultLanguage
)
508 safe_free(err
->err_language
);
513 ErrorState::Dump(MemBuf
* mb
)
516 const char *p
= NULL
; /* takes priority over mb if set */
517 char ntoabuf
[MAX_IPSTRLEN
];
520 /* email subject line */
521 str
.Printf("CacheErrorInfo - %s", errorPageName(type
));
522 mb
->Printf("?subject=%s", rfc1738_escape_part(str
.buf
));
525 str
.Printf("CacheHost: %s\r\n", getMyHostname());
527 str
.Printf("ErrPage: %s\r\n", errorPageName(type
));
530 str
.Printf("Err: (%d) %s\r\n", xerrno
, strerror(xerrno
));
532 str
.Printf("Err: [none]\r\n");
535 if (auth_user_request
->denyMessage())
536 str
.Printf("Auth ErrMsg: %s\r\n", auth_user_request
->denyMessage());
538 if (dnsError
.size() > 0)
539 str
.Printf("DNS ErrMsg: %s\r\n", dnsError
.termedBuf());
542 str
.Printf("TimeStamp: %s\r\n\r\n", mkrfc1123(squid_curtime
));
545 str
.Printf("ClientIP: %s\r\n", src_addr
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
547 if (request
&& request
->hier
.host
[0] != '\0') {
548 str
.Printf("ServerIP: %s\r\n", request
->hier
.host
);
553 str
.Printf("HTTP Request:\r\n");
555 if (NULL
!= request
) {
557 String urlpath_or_slash
;
559 if (request
->urlpath
.size() != 0)
560 urlpath_or_slash
= request
->urlpath
;
562 urlpath_or_slash
= "/";
564 str
.Printf("%s " SQUIDSTRINGPH
" HTTP/%d.%d\n",
565 RequestMethodStr(request
->method
),
566 SQUIDSTRINGPRINT(urlpath_or_slash
),
567 request
->http_ver
.major
, request
->http_ver
.minor
);
568 packerToMemInit(&pck
, &str
);
569 request
->header
.packInto(&pck
);
571 } else if (request_hdrs
) {
581 str
.Printf("FTP Request: %s\r\n", ftp
.request
);
582 str
.Printf("FTP Reply: %s\r\n", ftp
.reply
);
583 str
.Printf("FTP Msg: ");
584 wordlistCat(ftp
.server_msg
, &str
);
589 mb
->Printf("&body=%s", rfc1738_escape_part(str
.buf
));
594 /// \ingroup ErrorPageInternal
595 #define CVT_BUF_SZ 512
598 ErrorState::Convert(char token
, bool url_presentable
)
601 const char *p
= NULL
; /* takes priority over mb if set */
603 int no_urlescape
= 1; /* item is NOT to be further URL-encoded */
604 char ntoabuf
[MAX_IPSTRLEN
];
611 if (request
&& request
->auth_user_request
)
612 p
= request
->auth_user_request
->username();
618 if (url_presentable
) break;
619 p
= request
? ftpUrlWith2f(request
) : "[no URL]";
624 if (url_presentable
) break;
625 p
= errorPageName(type
);
629 mb
.Printf("%d", xerrno
);
634 mb
.Printf("(%d) %s", xerrno
, strerror(xerrno
));
636 mb
.Printf("[No Error]");
640 if (url_presentable
) break;
641 /* FTP REQUEST LINE */
649 if (url_presentable
) break;
658 if (url_presentable
) break;
659 /* FTP SERVER MESSAGE */
661 wordlistCat(ftp
.server_msg
, &mb
);
662 else if (ftp
.listing
) {
663 mb
.append(ftp
.listing
->content(), ftp
.listing
->contentSize());
669 mb
.Printf("%s", getMyHostname());
674 if (request
->hier
.host
[0] != '\0') // if non-empty string.
675 p
= request
->hier
.host
;
677 p
= request
->GetHost();
678 } else if (!url_presentable
)
679 p
= "[unknown host]";
683 mb
.Printf("%s", src_addr
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
687 if (request
&& request
->hier
.host
[0] != '\0') // if non-empty string
688 mb
.Printf("%s", request
->hier
.host
);
689 else if (!url_presentable
)
694 if (url_presentable
) break;
695 mb
.append(error_stylesheet
.content(), error_stylesheet
.contentSize());
700 if (url_presentable
) break;
701 if (Config
.errHtmlText
) {
702 mb
.Printf("%s", Config
.errHtmlText
);
704 } else if (!url_presentable
)
705 p
= "[not available]";
709 if (url_presentable
) break;
710 p
= auth_user_request
->denyMessage("[not available]");
714 p
= request
? RequestMethodStr(request
->method
) : "[unknown method]";
718 p
= request
? request
->extacl_message
.termedBuf() : external_acl_message
;
720 p
= "[not available]";
725 mb
.Printf("%d", (int) request
->port
);
726 } else if (!url_presentable
) {
727 p
= "[unknown port]";
732 p
= request
? ProtocolStr
[request
->protocol
] : "[unknown protocol]";
736 if (url_presentable
) {
737 p
= (request
->urlpath
.size() != 0 ? request
->urlpath
.termedBuf() : "/");
740 if (NULL
!= request
) {
742 String urlpath_or_slash
;
744 if (request
->urlpath
.size() != 0)
745 urlpath_or_slash
= request
->urlpath
;
747 urlpath_or_slash
= "/";
749 mb
.Printf("%s " SQUIDSTRINGPH
" HTTP/%d.%d\n",
750 RequestMethodStr(request
->method
),
751 SQUIDSTRINGPRINT(urlpath_or_slash
),
752 request
->http_ver
.major
, request
->http_ver
.minor
);
753 packerToMemInit(&pck
, &mb
);
754 request
->header
.packInto(&pck
);
756 } else if (request_hdrs
) {
764 /* for backward compat we make %s show the full URL. Drop this in some future release. */
765 if (url_presentable
) {
766 p
= request
? urlCanonical(request
) : url
;
767 debugs(0,0, "WARNING: deny_info now accepts coded tags. Use %u to get the full URL instead of %s");
769 p
= visible_appname_string
;
773 if (url_presentable
) break;
774 /* signature may contain %-escapes, recursion */
775 if (page_id
!= ERR_SQUID_SIGNATURE
) {
776 const int saved_id
= page_id
;
777 page_id
= ERR_SQUID_SIGNATURE
;
778 MemBuf
*sign_mb
= BuildContent();
779 mb
.Printf("%s", sign_mb
->content());
785 /* wow, somebody put %S into ERR_SIGNATURE, stop recursion */
791 mb
.Printf("%s", mkhttpdlogtime(&squid_curtime
));
795 mb
.Printf("%s", mkrfc1123(squid_curtime
));
799 /* Using the fake-https version of canonical so error pages see https:// */
800 /* even when the url-path cannot be shown as more than '*' */
801 p
= request
? urlCanonicalFakeHttps(request
) : url
? url
: "[no URL]";
805 p
= request
? urlCanonical(request
) : url
? url
: "[no URL]";
809 if (Config
.adminEmail
)
810 mb
.Printf("%s", Config
.adminEmail
);
811 else if (!url_presentable
)
816 if (url_presentable
) break;
817 if (Config
.adminEmail
&& Config
.onoff
.emailErrData
)
822 if (url_presentable
) break;
823 if (dnsError
.size() > 0)
824 p
= dnsError
.termedBuf();
825 else if (ftp
.cwd_msg
)
832 if (url_presentable
) break;
844 mb
.Printf("%%%c", token
);
850 p
= mb
.buf
; /* do not use mb after this assignment! */
854 debugs(4, 3, "errorConvert: %%" << token
<< " --> '" << p
<< "'" );
859 if (url_presentable
&& !no_urlescape
)
860 p
= rfc1738_escape_part(p
);
866 ErrorState::DenyInfoLocation(const char *name
, HttpRequest
*aRequest
, MemBuf
&result
)
868 char const *m
= name
;
872 while ((p
= strchr(m
, '%'))) {
873 result
.append(m
, p
- m
); /* copy */
874 t
= Convert(*++p
, true); /* convert */
875 result
.Printf("%s", t
); /* copy */
876 m
= p
+ 1; /* advance */
880 result
.Printf("%s", m
); /* copy tail */
882 assert((size_t)result
.contentSize() == strlen(result
.content()));
886 ErrorState::BuildHttpReply()
888 HttpReply
*rep
= new HttpReply
;
889 const char *name
= errorPageName(page_id
);
890 /* no LMT for error pages; error pages expire immediately */
892 if (strchr(name
, ':')) {
894 rep
->setHeaders(HTTP_MOVED_TEMPORARILY
, NULL
, "text/html", 0, 0, -1);
897 MemBuf redirect_location
;
898 redirect_location
.init();
899 DenyInfoLocation(name
, request
, redirect_location
);
900 httpHeaderPutStrf(&rep
->header
, HDR_LOCATION
, "%s", redirect_location
.content() );
903 httpHeaderPutStrf(&rep
->header
, HDR_X_SQUID_ERROR
, "%d %s", httpStatus
, "Access Denied");
905 MemBuf
*content
= BuildContent();
906 rep
->setHeaders(httpStatus
, NULL
, "text/html", content
->contentSize(), 0, -1);
908 * include some information for downstream caches. Implicit
909 * replaceable content. This isn't quite sufficient. xerrno is not
910 * necessarily meaningful to another system, so we really should
911 * expand it. Additionally, we should identify ourselves. Someone
912 * might want to know. Someone _will_ want to know OTOH, the first
913 * X-CACHE-MISS entry should tell us who.
915 httpHeaderPutStrf(&rep
->header
, HDR_X_SQUID_ERROR
, "%s %d", name
, xerrno
);
919 * If error page auto-negotiate is enabled in any way, send the Vary.
920 * RFC 2616 section 13.6 and 14.44 says MAY and SHOULD do this.
921 * We have even better reasons though:
922 * see http://wiki.squid-cache.org/KnowledgeBase/VaryNotCaching
924 if (!Config
.errorDirectory
) {
925 /* We 'negotiated' this ONLY from the Accept-Language. */
926 rep
->header
.delById(HDR_VARY
);
927 rep
->header
.putStr(HDR_VARY
, "Accept-Language");
930 /* add the Content-Language header according to RFC section 14.12 */
932 rep
->header
.putStr(HDR_CONTENT_LANGUAGE
, err_language
);
934 #endif /* USE_ERROR_LOCALES */
936 /* default templates are in English */
937 /* language is known unless error_directory override used */
938 if (!Config
.errorDirectory
)
939 rep
->header
.putStr(HDR_CONTENT_LANGUAGE
, "en");
942 httpBodySet(&rep
->body
, content
);
943 /* do not memBufClean() or delete the content, it was absorbed by httpBody */
950 ErrorState::BuildContent()
952 MemBuf
*content
= new MemBuf
;
953 const char *m
= NULL
;
957 assert(page_id
> ERR_NONE
&& page_id
< error_page_count
);
964 /** error_directory option in squid.conf overrides translations.
965 * Custom errors are always found either in error_directory or the templates directory.
966 * Otherwise locate the Accept-Language header
968 if (!Config
.errorDirectory
&& page_id
< ERR_MAX
&& request
&& request
->header
.getList(HDR_ACCEPT_LANGUAGE
, &hdr
) ) {
970 size_t pos
= 0; // current parsing position in header string
971 char *reset
= NULL
; // where to reset the p pointer for each new tag file
974 /* prep the directory path string to prevent snprintf ... */
975 l
= strlen(DEFAULT_SQUID_ERROR_DIR
);
976 memcpy(dir
, DEFAULT_SQUID_ERROR_DIR
, l
);
978 reset
= dt
= dir
+ l
;
980 debugs(4, 6, HERE
<< "Testing Header: '" << hdr
<< "'");
982 while ( pos
< hdr
.size() ) {
984 /* skip any initial whitespace. */
985 while (pos
< hdr
.size() && xisspace(hdr
[pos
])) pos
++;
988 * Header value format:
989 * - sequence of whitespace delimited tags
990 * - each tag may suffix with ';'.* which we can ignore.
991 * - IFF a tag contains only two characters we can wildcard ANY translations matching: <it> '-'? .*
992 * with preference given to an exact match.
994 bool invalid_byte
= false;
995 while (pos
< hdr
.size() && hdr
[pos
] != ';' && hdr
[pos
] != ',' && !xisspace(hdr
[pos
]) && dt
< (dir
+256) ) {
997 #if USE_HTTP_VIOLATIONS
998 // if accepting violations we may as well accept some broken browsers
999 // which may send us the right code, wrong ISO formatting.
1000 if (hdr
[pos
] == '_')
1004 *dt
= xtolower(hdr
[pos
]);
1005 // valid codes only contain A-Z, hyphen (-) and *
1006 if (*dt
!= '-' && *dt
!= '*' && (*dt
< 'a' || *dt
> 'z') )
1007 invalid_byte
= true;
1009 dt
++; // move to next destination byte.
1013 *dt
++ = '\0'; // nul-terminated the filename content string before system use.
1015 debugs(4, 9, HERE
<< "STATE: dt='" << dt
<< "', reset='" << reset
<< "', pos=" << pos
<< ", buf='" << ((pos
< hdr
.size()) ? hdr
.substr(pos
,hdr
.size()) : "") << "'");
1017 /* if we found anything we might use, try it. */
1018 if (*reset
!= '\0' && !invalid_byte
) {
1020 /* wildcard uses the configured default language */
1021 if (reset
[0] == '*' && reset
[1] == '\0') {
1022 debugs(4, 6, HERE
<< "Found language '" << reset
<< "'. Using configured default.");
1023 m
= error_text
[page_id
];
1024 if (!Config
.errorDirectory
)
1025 err_language
= Config
.errorDefaultLanguage
;
1029 debugs(4, 6, HERE
<< "Found language '" << reset
<< "', testing for available template in: '" << dir
<< "'");
1031 m
= errorTryLoadText( err_type_str
[page_id
], dir
, false);
1034 /* store the language we found for the Content-Language reply header */
1035 err_language
= xstrdup(reset
);
1037 } else if (Config
.errorLogMissingLanguages
) {
1038 debugs(4, DBG_IMPORTANT
, "WARNING: Error Pages Missing Language: " << reset
);
1042 if ( (dt
- reset
) == 2) {
1043 /* TODO glob the error directory for sub-dirs matching: <tag> '-*' */
1044 /* use first result. */
1045 debugs(4,2, HERE
<< "wildcard fallback errors not coded yet.");
1050 dt
= reset
; // reset for next tag testing. we replace the failed name instead of cloning.
1052 // IFF we terminated the tag on whitespace or ';' we need to skip to the next ',' or end of header.
1053 while (pos
< hdr
.size() && hdr
[pos
] != ',') pos
++;
1054 if (hdr
[pos
] == ',') pos
++;
1057 #endif /* USE_ERR_LOCALES */
1060 * If client-specific error templates are not enabled or available.
1061 * fall back to the old style squid.conf settings.
1064 m
= error_text
[page_id
];
1066 if (!Config
.errorDirectory
)
1067 err_language
= Config
.errorDefaultLanguage
;
1069 debugs(4, 2, HERE
<< "No existing error page language negotiated for " << errorPageName(page_id
) << ". Using default error file.");
1075 while ((p
= strchr(m
, '%'))) {
1076 content
->append(m
, p
- m
); /* copy */
1077 t
= Convert(*++p
, false); /* convert */
1078 content
->Printf("%s", t
); /* copy */
1079 m
= p
+ 1; /* advance */
1083 content
->Printf("%s", m
); /* copy tail */
1085 assert((size_t)content
->contentSize() == strlen(content
->content()));