Squid Web Cache master
Loading...
Searching...
No Matches
errorpage.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 04 Error Generation */
10
11#include "squid.h"
12#include "AccessLogEntry.h"
13#include "base/CharacterSet.h"
14#include "base/IoManip.h"
15#include "cache_cf.h"
16#include "clients/forward.h"
17#include "comm/Connection.h"
18#include "comm/Write.h"
19#include "error/Detail.h"
21#include "errorpage.h"
22#include "fde.h"
23#include "format/Format.h"
24#include "fs_io.h"
25#include "html/Quoting.h"
26#include "HttpHeaderTools.h"
27#include "HttpReply.h"
28#include "HttpRequest.h"
29#include "MemBuf.h"
30#include "MemObject.h"
31#include "rfc1738.h"
32#include "sbuf/Stream.h"
33#include "SquidConfig.h"
34#include "Store.h"
35#include "tools.h"
36#include "wordlist.h"
37#if USE_AUTH
38#include "auth/UserRequest.h"
39#endif
40#if USE_OPENSSL
42#endif
43
44#include <array>
45
57#if !defined(DEFAULT_SQUID_ERROR_DIR)
61#define DEFAULT_SQUID_ERROR_DIR DEFAULT_SQUID_DATA_DIR"/errors"
62#endif
63
66
67const SBuf ErrorState::LogformatMagic("@Squid{");
68
69/* local types */
70
73public:
74 ErrorDynamicPageInfo(const int anId, const char *aName, const SBuf &aCfgLocation);
76
78 int id;
79
83 char *page_name;
84
86 const char *uri;
87
89 const char *filename;
90
93
94 // XXX: Misnamed. Not just for redirects.
97
98private:
99 // no copying of any kind
101};
102
103namespace ErrorPage {
104
106class Build
107{
108public:
110 const char *input = nullptr;
112 bool allowRecursion = false;
113};
114
117{
118public:
119 BuildErrorPrinter(const SBuf &anInputLocation, int aPage, const char *aMsg, const char *anErrorLocation):
120 inputLocation(anInputLocation),
121 page_id(aPage),
122 msg(aMsg),
123 errorLocation(anErrorLocation)
124 {}
125
127 std::ostream &print(std::ostream &) const;
128
130 std::ostream &printLocation(std::ostream &os) const;
131
132 /* saved constructor parameters */
134 const int page_id;
135 const char *msg;
136 const char *errorLocation;
137};
138
139static inline std::ostream &
140operator <<(std::ostream &os, const BuildErrorPrinter &context)
141{
142 return context.print(os);
143}
144
145static const char *IsDenyInfoUri(const int page_id);
146
147static void ImportStaticErrorText(const int page_id, const char *text, const SBuf &inputLocation);
148static void ValidateStaticError(const int page_id, const SBuf &inputLocation);
149
150} // namespace ErrorPage
151
152/* local constant and vars */
153
156public:
158 const char *text;
159};
160
162static const std::array<HardCodedError, 7> HardCodedErrors = {
163 {
164 {
166 "\n<br>\n"
167 "<hr>\n"
168 "<div id=\"footer\">\n"
169 "Generated %T by %h (%s)\n"
170 "</div>\n"
171 "</body></html>\n"
172 },
173 {
174 TCP_RESET,
175 "reset"
176 },
177 {
179 "unexpected client disconnect"
180 },
181 {
183 "secure accept fail"
184 },
185 {
187 "request start timedout"
188 },
189 {
191 "request parse timedout"
192 },
193 {
195 "relay server response"
196 }
197 }
198};
199
201static std::vector<ErrorDynamicPageInfo *> ErrorDynamicPages;
202
203/* local prototypes */
204
206static char **error_text = nullptr;
207
209static int error_page_count = 0;
210
213
214static const char *errorFindHardText(err_type type);
216
220{
221public:
222 ErrorPageFile(const char *name, const err_type code) : TemplateFile(name, code) {}
223
225 const char *text() { return template_.c_str(); }
226
227protected:
228 void setDefault() override {
229 template_ = "Internal Error: Missing Template ";
230 template_.append(templateName.termedBuf());
231 }
232};
233
235static err_type &
237{
238 int tmp = (int)anErr;
239 anErr = (err_type)(++tmp);
240 return anErr;
241}
242
244static int
245operator -(err_type const &anErr, err_type const &anErr2)
246{
247 return (int)anErr - (int)anErr2;
248}
249
252static const char *
253ErrorPage::IsDenyInfoUri(const int page_id)
254{
255 if (ERR_MAX <= page_id && page_id < error_page_count)
256 return ErrorDynamicPages.at(page_id - ERR_MAX)->uri; // may be nil
257 return nullptr;
258}
259
260void
262{
264
265 err_type i;
266 const char *text;
268 error_text = static_cast<char **>(xcalloc(error_page_count, sizeof(char *)));
269
270 for (i = ERR_NONE, ++i; i < error_page_count; ++i) {
272
273 if ((text = errorFindHardText(i))) {
277 static const SBuf builtIn("built-in");
278 ImportStaticErrorText(i, text, builtIn);
279
280 } else if (i < ERR_MAX) {
286 ErrorPageFile errTmpl(err_type_str[i], i);
287 errTmpl.loadDefault();
288 ImportStaticErrorText(i, errTmpl.text(), errTmpl.filename);
289 } else {
294 assert(info && info->id == i && info->page_name);
295
296 if (info->filename) {
298 ErrorPageFile errTmpl(info->filename, ERR_MAX);
299 errTmpl.loadDefault();
300 ImportStaticErrorText(i, errTmpl.text(), errTmpl.filename);
301 } else {
302 assert(info->uri);
304 }
305 }
306 }
307
309
310 // look for and load stylesheet into global MemBuf for it.
312 ErrorPageFile tmpl("StylesSheet", ERR_MAX);
314 error_stylesheet.appendf("%s",tmpl.text());
315 }
316
317#if USE_OPENSSL
319#endif
320}
321
322void
324{
325 if (error_text) {
326 int i;
327
328 for (i = ERR_NONE + 1; i < error_page_count; ++i)
330
332 }
333
334 while (!ErrorDynamicPages.empty()) {
335 delete ErrorDynamicPages.back();
336 ErrorDynamicPages.pop_back();
337 }
338
340
341#if USE_OPENSSL
343#endif
344}
345
347static const char *
349{
350 for (const auto &m: HardCodedErrors) {
351 if (m.type == type)
352 return m.text;
353 }
354 return nullptr;
355}
356
357TemplateFile::TemplateFile(const char *name, const err_type code): silent(false), wasLoaded(false), templateName(name), templateCode(code)
358{
359 assert(name);
360}
361
362void
364{
365 if (loaded()) // already loaded?
366 return;
367
370 char path[MAXPATHLEN];
371 snprintf(path, sizeof(path), "%s/%s", Config.errorDirectory, templateName.termedBuf());
372 loadFromFile(path);
373 }
374
375#if USE_ERR_LOCALES
379 debugs(1, (templateCode < TCP_RESET ? DBG_CRITICAL : 3), "ERROR: Unable to load default error language files. Reset to backups.");
380 }
381 }
382#endif
383
384 /* test default location if failed (templates == English translation base templates) */
385 if (!loaded()) {
386 tryLoadTemplate("templates");
387 }
388
389 /* giving up if failed */
390 if (!loaded()) {
391 debugs(1, (templateCode < TCP_RESET ? DBG_CRITICAL : 3), "WARNING: failed to find or read error text file " << templateName);
392 template_.clear();
393 setDefault();
394 wasLoaded = true;
395 }
396}
397
398bool
400{
401 assert(lang);
402
403 char path[MAXPATHLEN];
404 /* TODO: prep the directory path string to prevent snprintf ... */
405 snprintf(path, sizeof(path), "%s/%s/%s",
407 path[MAXPATHLEN-1] = '\0';
408
409 if (loadFromFile(path))
410 return true;
411
412#if HAVE_GLOB
413 if ( strlen(lang) == 2) {
414 /* TODO glob the error directory for sub-dirs matching: <tag> '-*' */
415 /* use first result. */
416 debugs(4,2, "wildcard fallback errors not coded yet.");
417 }
418#endif
419
420 return false;
421}
422
423bool
425{
426 int fd;
427 char buf[4096];
428 ssize_t len;
429
430 if (loaded()) // already loaded?
431 return true;
432
433 fd = file_open(path, O_RDONLY | O_TEXT);
434
435 if (fd < 0) {
436 /* with dynamic locale negotiation we may see some failures before a success. */
437 if (!silent && templateCode < TCP_RESET) {
438 int xerrno = errno;
439 debugs(4, DBG_CRITICAL, "ERROR: loading file '" << path << "': " << xstrerr(xerrno));
440 }
441 wasLoaded = false;
442 return wasLoaded;
443 }
444
445 template_.clear();
446 while ((len = FD_READ_METHOD(fd, buf, sizeof(buf))) > 0) {
447 template_.append(buf, len);
448 }
449
450 if (len < 0) {
451 int xerrno = errno;
452 file_close(fd);
453 debugs(4, DBG_CRITICAL, MYNAME << "ERROR: failed to fully read: '" << path << "': " << xstrerr(xerrno));
454 wasLoaded = false;
455 return false;
456 }
457
458 file_close(fd);
459
460 filename = SBuf(path);
461
462 if (!parse()) {
463 debugs(4, DBG_CRITICAL, "ERROR: parsing error in template file: " << path);
464 wasLoaded = false;
465 return false;
466 }
467
468 wasLoaded = true;
469 return wasLoaded;
470}
471
472bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos)
473{
474 while (pos < hdr.size()) {
475
476 /* skip any initial whitespace. */
477 while (pos < hdr.size() && xisspace(hdr[pos]))
478 ++pos;
479
480 /*
481 * Header value format:
482 * - sequence of whitespace delimited tags
483 * - each tag may suffix with ';'.* which we can ignore.
484 * - IFF a tag contains only two characters we can wildcard ANY translations matching: <it> '-'? .*
485 * with preference given to an exact match.
486 */
487 bool invalid_byte = false;
488 char *dt = lang;
489 while (pos < hdr.size() && hdr[pos] != ';' && hdr[pos] != ',' && !xisspace(hdr[pos]) && dt < (lang + (langLen -1)) ) {
490 if (!invalid_byte) {
491#if USE_HTTP_VIOLATIONS
492 // if accepting violations we may as well accept some broken browsers
493 // which may send us the right code, wrong ISO formatting.
494 if (hdr[pos] == '_')
495 *dt = '-';
496 else
497#endif
498 *dt = xtolower(hdr[pos]);
499 // valid codes only contain A-Z, hyphen (-) and *
500 if (*dt != '-' && *dt != '*' && (*dt < 'a' || *dt > 'z') )
501 invalid_byte = true;
502 else
503 ++dt; // move to next destination byte.
504 }
505 ++pos;
506 }
507 *dt = '\0'; // nul-terminated the filename content string before system use.
508
509 // if we terminated the tag on garbage or ';' we need to skip to the next ',' or end of header.
510 while (pos < hdr.size() && hdr[pos] != ',')
511 ++pos;
512
513 if (pos < hdr.size() && hdr[pos] == ',')
514 ++pos;
515
516 debugs(4, 9, "STATE: lang=" << lang << ", pos=" << pos << ", buf='" << ((pos < hdr.size()) ? hdr.substr(pos,hdr.size()) : "") << "'");
517
518 /* if we found anything we might use, try it. */
519 if (*lang != '\0' && !invalid_byte)
520 return true;
521 }
522 return false;
523}
524
525bool
527{
528 String hdr;
529
530#if USE_ERR_LOCALES
531 if (loaded()) // already loaded?
532 return true;
533
534 if (!request || !request->header.getList(Http::HdrType::ACCEPT_LANGUAGE, &hdr))
535 return false;
536
537 char lang[256];
538 size_t pos = 0; // current parsing position in header string
539
540 debugs(4, 6, "Testing Header: '" << hdr << "'");
541
542 while ( strHdrAcptLangGetItem(hdr, lang, 256, pos) ) {
543
544 /* wildcard uses the configured default language */
545 if (lang[0] == '*' && lang[1] == '\0') {
546 debugs(4, 6, "Found language '" << lang << "'. Using configured default.");
547 return false;
548 }
549
550 debugs(4, 6, "Found language '" << lang << "', testing for available template");
551
552 if (tryLoadTemplate(lang)) {
553 /* store the language we found for the Content-Language reply header */
554 errLanguage = lang;
555 break;
556 } else if (Config.errorLogMissingLanguages) {
557 debugs(4, DBG_IMPORTANT, "WARNING: Error Pages Missing Language: " << lang);
558 }
559 }
560#else
561 (void)request;
562#endif
563
564 return loaded();
565}
566
567ErrorDynamicPageInfo::ErrorDynamicPageInfo(const int anId, const char *aName, const SBuf &aCfgLocation):
568 id(anId),
569 page_name(xstrdup(aName)),
570 uri(nullptr),
571 filename(nullptr),
572 cfgLocation(aCfgLocation),
573 page_redirect(static_cast<Http::StatusCode>(atoi(page_name)))
574{
575 const char *filenameOrUri = nullptr;
576 if (xisdigit(*page_name)) {
577 if (const char *statusCodeEnd = strchr(page_name, ':'))
578 filenameOrUri = statusCodeEnd + 1;
579 } else {
581 filenameOrUri = page_name;
582 }
583
584 // Guessed uri, filename, or both values may be nil or malformed.
585 // They are validated later.
586 if (!page_redirect) {
587 if (filenameOrUri && strchr(filenameOrUri, ':')) // looks like a URL
588 uri = filenameOrUri;
589 else
590 filename = filenameOrUri;
591 }
592 else if (page_redirect/100 == 3) {
593 // redirects imply a URL
594 uri = filenameOrUri;
595 } else {
596 // non-redirects imply an error page name
597 filename = filenameOrUri;
598 }
599
600 const auto info = this; // source code change reduction hack
601 // TODO: Move and refactor to avoid self_destruct()s in reconfigure.
602
603 /* WARNING on redirection status:
604 * 2xx are permitted, but not documented officially.
605 * - might be useful for serving static files (PAC etc) in special cases
606 * 3xx require a URL suitable for Location: header.
607 * - the current design does not allow for a Location: URI as well as a local file template
608 * although this possibility is explicitly permitted in the specs.
609 * 4xx-5xx require a local file template.
610 * - sending Location: on these codes with no body is invalid by the specs.
611 * - current result is Squid crashing or XSS problems as dynamic deny_info load random disk files.
612 * - a future redesign of the file loading may result in loading remote objects sent inline as local body.
613 */
614 if (info->page_redirect == Http::scNone)
615 ; // special case okay.
616 else if (info->page_redirect < 200 || info->page_redirect > 599) {
617 // out of range
618 debugs(0, DBG_CRITICAL, "FATAL: status " << info->page_redirect << " is not valid on '" << page_name << "'");
620 } else if ( /* >= 200 && */ info->page_redirect < 300 && strchr(&(page_name[4]), ':')) {
621 // 2xx require a local template file
622 debugs(0, DBG_CRITICAL, "FATAL: status " << info->page_redirect << " requires a template on '" << page_name << "'");
624 } else if (info->page_redirect >= 300 && info->page_redirect <= 399 && !strchr(&(page_name[4]), ':')) {
625 // 3xx require an absolute URL
626 debugs(0, DBG_CRITICAL, "FATAL: status " << info->page_redirect << " requires a URL on '" << page_name << "'");
628 } else if (info->page_redirect >= 400 /* && <= 599 */ && strchr(&(page_name[4]), ':')) {
629 // 4xx/5xx require a local template file
630 debugs(0, DBG_CRITICAL, "FATAL: status " << info->page_redirect << " requires a template on '" << page_name << "'");
632 }
633 // else okay.
634}
635
637static int
638errorPageId(const char *page_name)
639{
640 for (int i = 0; i < ERR_MAX; ++i) {
641 if (strcmp(err_type_str[i], page_name) == 0)
642 return i;
643 }
644
645 for (size_t j = 0; j < ErrorDynamicPages.size(); ++j) {
646 if (strcmp(ErrorDynamicPages[j]->page_name, page_name) == 0)
647 return j + ERR_MAX;
648 }
649
650 return ERR_NONE;
651}
652
654errorReservePageId(const char *page_name, const SBuf &cfgLocation)
655{
656 int id = errorPageId(page_name);
657
658 if (id == ERR_NONE) {
659 id = ERR_MAX + ErrorDynamicPages.size();
660 const auto info = new ErrorDynamicPageInfo(id, page_name, cfgLocation);
661 ErrorDynamicPages.push_back(info);
662 }
663
664 return (err_type)id;
665}
666
668const char *
669errorPageName(int pageId)
670{
671 if (pageId >= ERR_NONE && pageId < ERR_MAX) /* common case */
672 return err_type_str[pageId];
673
674 if (pageId >= ERR_MAX && pageId - ERR_MAX < (ssize_t)ErrorDynamicPages.size())
675 return ErrorDynamicPages[pageId - ERR_MAX]->page_name;
676
677 return "ERR_UNKNOWN"; /* should not happen */
678}
679
681static std::ostream &
682operator <<(std::ostream &os, const ErrorState &err)
683{
684 os << errorPageName(err.type);
685 if (err.httpStatus != Http::scNone)
686 os << "/http_status=" << err.httpStatus;
687 return os;
688}
689
697
699 type(t),
700 page_id(t),
701 callback(nullptr),
702 ale(anAle)
703{
704}
705
707 ErrorState(t, anAle)
708{
709 if (page_id >= ERR_MAX && ErrorDynamicPages[page_id - ERR_MAX]->page_redirect != Http::scNone)
710 httpStatus = ErrorDynamicPages[page_id - ERR_MAX]->page_redirect;
711 else
712 httpStatus = status;
713
714 if (req) {
715 request = req;
716 src_addr = req->client_addr;
717 }
718
719 debugs(4, 3, "constructed, this=" << static_cast<void*>(this) << ' ' << *this);
720}
721
724{
725 Must(errorReply);
726 response_ = errorReply;
727 httpStatus = errorReply->sline.status();
728
729 if (req) {
730 request = req;
731 src_addr = req->client_addr;
732 }
733
734 debugs(4, 3, "constructed, this=" << static_cast<void*>(this) << " relaying " << *this);
735}
736
737void
739{
740 assert(entry->mem_obj != nullptr);
741 assert (entry->isEmpty());
742 debugs(4, 4, "storing " << err << " in " << *entry);
743
744 if (const auto &request = err->request) {
745 if (const auto &bodyPipe = request->body_pipe) {
746 // We cannot expectNoConsumption() here (yet): This request may be a
747 // virgin request being consumed by adaptation that should continue
748 // even in error-handling cases. startAutoConsumptionIfNeeded() call
749 // triggered by enableAutoConsumption() below skips such requests.
750 //
751 // Today, we also cannot enableAutoConsumption() earlier because it
752 // could result in premature consumption in BodyPipe::postAppend()
753 // followed by an unwanted setConsumerIfNotLate() failure.
754 //
755 // TODO: Simplify BodyPipe auto-consumption by automatically
756 // enabling it when no new consumers are expected, removing the need
757 // for explicit enableAutoConsumption() calls like the one below.
758 //
759 // Code like clientReplyContext::sendClientOldEntry() might use
760 // another StoreEntry for this master transaction, but we want to
761 // consume this request body even in those hypothetical error cases
762 // to prevent stuck (client-Squid or REQMOD) transactions.
763 bodyPipe->enableAutoConsumption();
764 }
765 }
766
767 if (entry->store_status != STORE_PENDING) {
768 debugs(4, 2, "Skipping error page due to store_status: " << entry->store_status);
769 /*
770 * If the entry is not STORE_PENDING, then no clients
771 * care about it, and we don't need to generate an
772 * error message
773 */
775 assert(entry->mem_obj->nclients == 0);
776 delete err;
777 return;
778 }
779
780 if (err->page_id == TCP_RESET) {
781 if (err->request) {
782 debugs(4, 2, "RSTing this reply");
783 err->request->flags.resetTcp = true;
784 }
785 }
786
787 entry->storeErrorResponse(err->BuildHttpReply());
788 delete err;
789}
790
791void
793{
794 debugs(4, 3, conn << ", err=" << err);
796
798
799 MemBuf *mb = rep->pack();
800 AsyncCall::Pointer call = commCbCall(78, 5, "errorSendComplete",
802 Comm::Write(conn, mb, call);
803 delete mb;
804}
805
815static void
816errorSendComplete(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag errflag, int, void *data)
817{
818 ErrorState *err = static_cast<ErrorState *>(data);
819 debugs(4, 3, conn << ", size=" << size);
820
821 if (errflag != Comm::ERR_CLOSING) {
822 if (err->callback) {
823 debugs(4, 3, "errorSendComplete: callback");
824 err->callback(conn->fd, err->callback_data, size);
825 } else {
826 debugs(4, 3, "errorSendComplete: comm_close");
827 conn->close();
828 }
829 }
830
831 delete err;
832}
833
835{
836 debugs(4, 7, "destructing, this=" << static_cast<void*>(this));
837
839 safe_free(url);
840 wordlistDestroy(&ftp.server_msg);
841 safe_free(ftp.request);
842 safe_free(ftp.reply);
843 safe_free(ftp.cwd_msg);
845#if USE_ERR_LOCALES
847#endif
849}
850
851int
853{
854 PackableStream out(*mb);
855 const auto &encoding = CharacterSet::RFC3986_UNRESERVED();
856
857 out << "?subject=" <<
858 AnyP::Uri::Encode(SBuf("CacheErrorInfo - "),encoding) <<
860
861 SBufStream body;
862 body << "CacheHost: " << getMyHostname() << "\r\n" <<
863 "ErrPage: " << errorPageName(type) << "\r\n" <<
864 "TimeStamp: " << Time::FormatRfc1123(squid_curtime) << "\r\n" <<
865 "\r\n";
866
867 body << "ClientIP: " << src_addr << "\r\n";
868
869 if (request && request->hier.host[0] != '\0')
870 body << "ServerIP: " << request->hier.host << "\r\n";
871
872 if (xerrno)
873 body << "Err: (" << xerrno << ") " << strerror(xerrno) << "\r\n";
874
875#if USE_AUTH
877 body << "Auth ErrMsg: " << auth_user_request->denyMessage() << "\r\n";
878#endif
879
880 if (dnsError)
881 body << "DNS ErrMsg: " << *dnsError << "\r\n";
882
883 body << "\r\n";
884
885 if (request) {
886 body << "HTTP Request:\r\n";
887 MemBuf r;
888 r.init();
889 request->pack(&r, true /* hide authorization data */);
890 body << r.content();
891 }
892
893 /* - FTP stuff */
894
895 if (ftp.request) {
896 body << "FTP Request: " << ftp.request << "\r\n";
897 if (ftp.reply)
898 body << "FTP Reply: " << ftp.reply << "\r\n";
899 if (ftp.server_msg)
900 body << "FTP Msg: " << AsList(*ftp.server_msg).delimitedBy("\n") << "\r\n";
901 body << "\r\n";
902 }
903
904 out << "&body=" << AnyP::Uri::Encode(body.buf(), encoding);
905
906 return 0;
907}
908
910#define CVT_BUF_SZ 512
911
912void
914{
916
917 try {
918 const auto logformat = build.input + LogformatMagic.length();
919
920 // Logformat supports undocumented "external" encoding specifications
921 // like [%>h] or "%<a". To preserve the possibility of extending
922 // @Squid{} syntax to non-logformat sequences, we require logformat
923 // sequences to start with '%'. This restriction does not limit
924 // logformat quoting abilities. TODO: Deprecate "external" encoding?
925 if (*logformat != '%')
926 throw TexcHere("logformat expressions that do not start with % are not supported");
927
928 static MemBuf result;
929 result.reset();
930 const auto logformatLen = Format::AssembleOne(logformat, result, ale);
931 assert(logformatLen > 0);
932 const auto closure = logformat + logformatLen;
933 if (*closure != '}')
934 throw TexcHere("Missing closing brace (})");
935 build.output.append(result.content(), result.contentSize());
936 build.input = closure + 1;
937 return;
938 } catch (...) {
939 noteBuildError("Bad @Squid{logformat} sequence", build.input);
940 }
941
942 // we cannot recover reliably so stop interpreting the rest of input
943 const auto remainingSize = strlen(build.input);
944 build.output.append(build.input, remainingSize);
945 build.input += remainingSize;
946}
947
948void
950{
951 static MemBuf mb;
952 const char *p = nullptr; /* takes priority over mb if set */
953 int do_quote = 1;
954 int no_urlescape = 0; /* if true then item is NOT to be further URL-encoded */
955 char ntoabuf[MAX_IPSTRLEN];
956
957 mb.reset();
958
959 const auto &building_deny_info_url = build.building_deny_info_url; // a change reduction hack
960
961 const auto letter = build.input[1];
962
963 switch (letter) {
964
965 case 'a':
966#if USE_AUTH
969 if (!p)
970#endif
971 p = "-";
972 break;
973
974 case 'A':
975 // TODO: When/if we get ALE here, pass it as well
976 if (const auto addr = FindListeningPortAddress(request.getRaw(), nullptr))
977 mb.appendf("%s", addr->toStr(ntoabuf, MAX_IPSTRLEN));
978 else
979 p = "-";
980 break;
981
982 case 'b':
983 mb.appendf("%u", getMyPort());
984 break;
985
986 case 'B':
987 if (building_deny_info_url) break;
988 if (request) {
989 const SBuf &tmp = Ftp::UrlWith2f(request.getRaw());
990 mb.append(tmp.rawContent(), tmp.length());
991 } else
992 p = "[no URL]";
993 break;
994
995 case 'c':
996 if (building_deny_info_url) break;
997 p = errorPageName(type);
998 break;
999
1000 case 'D':
1001 if (!build.allowRecursion)
1002 p = "%D"; // if recursion is not allowed, do not convert
1003 else if (detail) {
1004 auto rawDetail = detail->verbose(request);
1005 // XXX: Performance regression. c_str() reallocates
1006 const auto compiledDetail = compileBody(rawDetail.c_str(), false);
1007 mb.append(compiledDetail.rawContent(), compiledDetail.length());
1008 do_quote = 0;
1009 }
1010 if (!mb.contentSize())
1011 mb.append("[No Error Detail]", 17);
1012 break;
1013
1014 case 'e':
1015 mb.appendf("%d", xerrno);
1016 break;
1017
1018 case 'E':
1019 if (xerrno)
1020 mb.appendf("(%d) %s", xerrno, strerror(xerrno));
1021 else
1022 mb.append("[No Error]", 10);
1023 break;
1024
1025 case 'f':
1026 if (building_deny_info_url) break;
1027 /* FTP REQUEST LINE */
1028 if (ftp.request)
1029 p = ftp.request;
1030 else
1031 p = "nothing";
1032 break;
1033
1034 case 'F':
1035 if (building_deny_info_url) break;
1036 /* FTP REPLY LINE */
1037 if (ftp.reply)
1038 p = ftp.reply;
1039 else
1040 p = "nothing";
1041 break;
1042
1043 case 'g':
1044 if (building_deny_info_url) break;
1045 /* FTP SERVER RESPONSE */
1046 if (ftp.listing) {
1047 mb.append(ftp.listing->content(), ftp.listing->contentSize());
1048 do_quote = 0;
1049 } else if (ftp.server_msg) {
1050 wordlistCat(ftp.server_msg, &mb);
1051 }
1052 break;
1053
1054 case 'h':
1055 mb.appendf("%s", getMyHostname());
1056 break;
1057
1058 case 'H':
1059 if (request) {
1060 if (request->hier.host[0] != '\0') // if non-empty string.
1061 p = request->hier.host;
1062 else
1063 p = request->url.host();
1064 } else if (!building_deny_info_url)
1065 p = "[unknown host]";
1066 break;
1067
1068 case 'i':
1069 mb.appendf("%s", src_addr.toStr(ntoabuf,MAX_IPSTRLEN));
1070 break;
1071
1072 case 'I':
1073 if (request && request->hier.tcpServer)
1075 else if (!building_deny_info_url)
1076 p = "[unknown]";
1077 break;
1078
1079 case 'l':
1080 if (building_deny_info_url) break;
1082 do_quote = 0;
1083 break;
1084
1085 case 'L':
1086 if (building_deny_info_url) break;
1087 if (Config.errHtmlText) {
1088 mb.appendf("%s", Config.errHtmlText);
1089 do_quote = 0;
1090 } else
1091 p = "[not available]";
1092 break;
1093
1094 case 'm':
1095 if (building_deny_info_url) break;
1096#if USE_AUTH
1098 p = auth_user_request->denyMessage("[not available]");
1099 else
1100 p = "[not available]";
1101#else
1102 p = "-";
1103#endif
1104 break;
1105
1106 case 'M':
1107 if (request) {
1108 const SBuf &m = request->method.image();
1109 mb.append(m.rawContent(), m.length());
1110 } else if (!building_deny_info_url)
1111 p = "[unknown method]";
1112 break;
1113
1114 case 'O':
1115 if (!building_deny_info_url)
1116 do_quote = 0;
1117 [[fallthrough]];
1118 case 'o':
1120 if (!p && !building_deny_info_url)
1121 p = "[not available]";
1122 break;
1123
1124 case 'p':
1125 if (request && request->url.port()) {
1126 mb.appendf("%hu", *request->url.port());
1127 } else if (!building_deny_info_url) {
1128 p = "[unknown port]";
1129 }
1130 break;
1131
1132 case 'P':
1133 if (request) {
1134 const SBuf &m = request->url.getScheme().image();
1135 mb.append(m.rawContent(), m.length());
1136 } else if (!building_deny_info_url) {
1137 p = "[unknown protocol]";
1138 }
1139 break;
1140
1141 case 'R':
1142 if (building_deny_info_url) {
1143 if (request != nullptr) {
1144 const SBuf &tmp = request->url.absolutePath();
1145 mb.append(tmp.rawContent(), tmp.length());
1146 no_urlescape = 1;
1147 } else
1148 p = "[no request]";
1149 break;
1150 }
1151 else if (request)
1152 request->pack(&mb, true /* hide authorization data */);
1153 else
1154 p = "[no request]";
1155 break;
1156
1157 case 's':
1158 /* for backward compat we make %s show the full URL. Drop this in some future release. */
1159 if (building_deny_info_url) {
1160 if (request) {
1161 const SBuf &tmp = request->effectiveRequestUri();
1162 mb.append(tmp.rawContent(), tmp.length());
1163 } else
1164 p = url;
1165 debugs(0, DBG_CRITICAL, "WARNING: deny_info now accepts coded tags. Use %u to get the full URL instead of %s");
1166 } else
1168 break;
1169
1170 case 'S':
1171 if (building_deny_info_url) {
1173 break;
1174 }
1175 /* signature may contain %-escapes, recursion */
1177 const int saved_id = page_id;
1179 const auto signature = buildBody();
1180 mb.append(signature.rawContent(), signature.length());
1181 page_id = saved_id;
1182 do_quote = 0;
1183 } else {
1184 /* wow, somebody put %S into ERR_SIGNATURE, stop recursion */
1185 p = "[%S]";
1186 }
1187 break;
1188
1189 case 't':
1191 break;
1192
1193 case 'T':
1195 break;
1196
1197 case 'U':
1198 /* Using the fake-https version of absolute-URI so error pages see https:// */
1199 /* even when the url-path cannot be shown as more than '*' */
1200 if (request)
1202 else if (url)
1203 p = url;
1204 else if (!building_deny_info_url)
1205 p = "[no URL]";
1206 break;
1207
1208 case 'u':
1209 if (request) {
1210 const SBuf &tmp = request->effectiveRequestUri();
1211 mb.append(tmp.rawContent(), tmp.length());
1212 } else if (url)
1213 p = url;
1214 else if (!building_deny_info_url)
1215 p = "[no URL]";
1216 break;
1217
1218 case 'w':
1219 if (Config.adminEmail)
1220 mb.appendf("%s", Config.adminEmail);
1221 else if (!building_deny_info_url)
1222 p = "[unknown]";
1223 break;
1224
1225 case 'W':
1226 if (building_deny_info_url) break;
1228 Dump(&mb);
1229 no_urlescape = 1;
1230 do_quote = 0;
1231 break;
1232
1233 case 'x':
1234 if (detail) {
1235 const auto brief = detail->brief();
1236 mb.append(brief.rawContent(), brief.length());
1237 } else if (!building_deny_info_url) {
1238 p = "[Unknown Error Code]";
1239 }
1240 break;
1241
1242 case 'z':
1243 if (building_deny_info_url) break;
1244 if (dnsError)
1245 p = dnsError->c_str();
1246 else if (ftp.cwd_msg)
1247 p = ftp.cwd_msg;
1248 else
1249 p = "[unknown]";
1250 break;
1251
1252 case 'Z':
1253 if (building_deny_info_url) break;
1254 if (err_msg)
1255 p = err_msg;
1256 else
1257 p = "[unknown]";
1258 break;
1259
1260 case '%':
1261 p = "%";
1262 break;
1263
1264 default:
1265 if (building_deny_info_url)
1266 bypassBuildErrorXXX("Unsupported deny_info %code", build.input);
1267 else if (letter != ';')
1268 bypassBuildErrorXXX("Unsupported error page %code", build.input);
1269 // else too many "font-size: 100%;" template errors to report
1270
1271 mb.append(build.input, 2);
1272 do_quote = 0;
1273 break;
1274 }
1275
1276 if (!p)
1277 p = mb.buf; /* do not use mb after this assignment! */
1278
1279 assert(p);
1280
1281 debugs(4, 3, "%" << letter << " --> '" << p << "'" );
1282
1283 if (do_quote)
1284 p = html_quote(p);
1285
1286 if (building_deny_info_url && !no_urlescape)
1287 p = rfc1738_escape_part(p);
1288
1289 // TODO: Optimize by replacing mb with direct build.output usage.
1290 build.output.append(p, strlen(p));
1291 build.input += 2;
1292}
1293
1294void
1296{
1297 if (const auto urlTemplate = ErrorPage::IsDenyInfoUri(page_id)) {
1298 (void)compile(urlTemplate, true, true);
1299 } else {
1302 (void)compileBody(error_text[page_id], true);
1303 }
1304}
1305
1306HttpReply *
1308{
1309 // Make sure error codes get back to the client side for logging and
1310 // error tracking.
1311 if (request) {
1314 } else if (ale) {
1315 Error err(type, detail);
1317 ale->updateError(err);
1318 }
1319
1320 if (response_)
1321 return response_.getRaw();
1322
1323 HttpReply *rep = new HttpReply;
1324 const char *name = errorPageName(page_id);
1325 /* no LMT for error pages; error pages expire immediately */
1326
1327 if (const auto urlTemplate = ErrorPage::IsDenyInfoUri(page_id)) {
1328 /* Redirection */
1330 // Use configured 3xx reply status if set.
1331 if (name[0] == '3')
1332 status = httpStatus;
1333 else {
1334 // Use 307 for HTTP/1.1 non-GET/HEAD requests.
1337 }
1338
1339 rep->setHeaders(status, nullptr, "text/html;charset=utf-8", 0, 0, -1);
1340
1341 if (request) {
1342 auto location = compile(urlTemplate, true, true);
1343 rep->header.putStr(Http::HdrType::LOCATION, location.c_str());
1344 }
1345
1346 httpHeaderPutStrf(&rep->header, Http::HdrType::X_SQUID_ERROR, "%d %s", httpStatus, "Access Denied");
1347 } else {
1348 const auto body = buildBody();
1349 rep->setHeaders(httpStatus, nullptr, "text/html;charset=utf-8", body.length(), 0, -1);
1350 /*
1351 * include some information for downstream caches. Implicit
1352 * replaceable content. This isn't quite sufficient. xerrno is not
1353 * necessarily meaningful to another system, so we really should
1354 * expand it. Additionally, we should identify ourselves. Someone
1355 * might want to know. Someone _will_ want to know OTOH, the first
1356 * X-CACHE-MISS entry should tell us who.
1357 */
1359
1360#if USE_ERR_LOCALES
1361 /*
1362 * If error page auto-negotiate is enabled in any way, send the Vary.
1363 * RFC 2616 section 13.6 and 14.44 says MAY and SHOULD do this.
1364 * We have even better reasons though:
1365 * see https://wiki.squid-cache.org/KnowledgeBase/VaryNotCaching
1366 */
1367 if (!Config.errorDirectory) {
1368 /* We 'negotiated' this ONLY from the Accept-Language. */
1369 static const SBuf acceptLanguage("Accept-Language");
1370 rep->header.updateOrAddStr(Http::HdrType::VARY, acceptLanguage);
1371 }
1372
1373 /* add the Content-Language header according to RFC section 14.12 */
1374 if (err_language) {
1376 } else
1377#endif /* USE_ERROR_LOCALES */
1378 {
1379 /* default templates are in English */
1380 /* language is known unless error_directory override used */
1383 }
1384
1385 rep->body.set(body);
1386 }
1387
1388 return rep;
1389}
1390
1391SBuf
1393{
1395
1396#if USE_ERR_LOCALES
1404
1405 ErrorPageFile localeTmpl(err_type_str[page_id], static_cast<err_type>(page_id));
1406 if (localeTmpl.loadFor(request.getRaw())) {
1407 inputLocation = localeTmpl.filename;
1408 assert(localeTmpl.language());
1409 err_language = xstrdup(localeTmpl.language());
1410 return compileBody(localeTmpl.text(), true);
1411 }
1412 }
1413#endif /* USE_ERR_LOCALES */
1414
1419#if USE_ERR_LOCALES
1422#endif
1423 debugs(4, 2, "No existing error page language negotiated for " << this << ". Using default error file.");
1424 return compileBody(error_text[page_id], true);
1425}
1426
1427SBuf
1428ErrorState::compileBody(const char *input, bool allowRecursion)
1429{
1430 return compile(input, false, allowRecursion);
1431}
1432
1433SBuf
1434ErrorState::compile(const char *input, bool building_deny_info_url, bool allowRecursion)
1435{
1436 assert(input);
1437
1438 Build build;
1439 build.building_deny_info_url = building_deny_info_url;
1440 build.allowRecursion = allowRecursion;
1441 build.input = input;
1442
1443 auto blockStart = build.input;
1444 while (const auto letter = *build.input) {
1445 if (letter == '%') {
1446 build.output.append(blockStart, build.input - blockStart);
1447 compileLegacyCode(build);
1448 blockStart = build.input;
1449 }
1450 else if (letter == '@' && LogformatMagic.cmp(build.input, LogformatMagic.length()) == 0) {
1451 build.output.append(blockStart, build.input - blockStart);
1452 compileLogformatCode(build);
1453 blockStart = build.input;
1454 } else {
1455 ++build.input;
1456 }
1457 }
1458 build.output.append(blockStart, build.input - blockStart);
1459 return build.output;
1460}
1461
1469void
1470ErrorState::noteBuildError_(const char *const msg, const char * const errorLocation, const bool forceBypass)
1471{
1473 const auto runtime = !starting_up;
1474 if (runtime || forceBypass) {
1475 // swallow this problem because the admin may not be (and/or the page
1476 // building code is not) ready to handle throwing consequences
1477
1478 static unsigned int seenErrors = 0;
1479 ++seenErrors;
1480
1481 const auto debugLevel =
1482 (seenErrors > 100) ? DBG_DATA:
1484 3; // most other errors have been reported as configuration errors
1485
1486 // Error fatality depends on the error context: Reconfiguration errors
1487 // are, like startup ones, DBG_CRITICAL but will never become FATAL.
1488 if (starting_up && seenErrors <= 10)
1489 debugs(4, debugLevel, "WARNING: The following configuration error will be fatal in future Squid versions");
1490
1491 debugs(4, debugLevel, "ERROR: " << BuildErrorPrinter(inputLocation, page_id, msg, errorLocation));
1492 } else {
1493 throw TexcHere(ToSBuf(BuildErrorPrinter(inputLocation, page_id, msg, errorLocation)));
1494 }
1495}
1496
1497/* ErrorPage::BuildErrorPrinter */
1498
1499std::ostream &
1501 if (!inputLocation.isEmpty())
1502 return os << inputLocation;
1503
1504 if (page_id < ERR_NONE || page_id >= error_page_count)
1505 return os << "[error page " << page_id << "]"; // should not happen
1506
1507 if (page_id < ERR_MAX)
1508 return os << err_type_str[page_id];
1509
1510 return os << "deny_info " << ErrorDynamicPages.at(page_id - ERR_MAX)->page_name;
1511}
1512
1513std::ostream &
1515 printLocation(os) << ": " << msg << " near ";
1516
1517 // TODO: Add support for prefix printing to Raw
1518 const size_t maxContextLength = 15; // plus "..."
1519 if (strlen(errorLocation) > maxContextLength) {
1520 os.write(errorLocation, maxContextLength);
1521 os << "...";
1522 } else {
1523 os << errorLocation;
1524 }
1525
1526 // XXX: We should not be converting (inner) exception to text if we are
1527 // going to throw again. See "add arbitrary (re)thrower-supplied details"
1528 // TODO in TextException.h for a long-term in-catcher solution.
1529 if (std::current_exception())
1530 os << "\n additional info: " << CurrentException;
1531
1532 return os;
1533}
1534
1536static void
1537ErrorPage::ImportStaticErrorText(const int page_id, const char *text, const SBuf &inputLocation)
1538{
1539 assert(!error_text[page_id]);
1540 error_text[page_id] = xstrdup(text);
1541 ValidateStaticError(page_id, inputLocation);
1542}
1543
1545static void
1546ErrorPage::ValidateStaticError(const int page_id, const SBuf &inputLocation)
1547{
1548 // Supplying nil ALE pointer limits validation to logformat %code
1549 // recognition by Format::Token::parse(). This is probably desirable
1550 // because actual %code assembly is slow and should not affect validation
1551 // when our ALE cannot have any real data (this code is not associated
1552 // with any real transaction).
1553 ErrorState anErr(err_type(page_id), Http::scNone, nullptr, nullptr);
1554 anErr.inputLocation = inputLocation;
1555 anErr.validate();
1556}
1557
1558std::ostream &
1559operator <<(std::ostream &os, const ErrorState *err)
1560{
1561 os << RawPointer(err).orNil();
1562 return os;
1563}
1564
CommCbFunPtrCallT< Dialer > * commCbCall(int debugSection, int debugLevel, const char *callName, const Dialer &dialer)
Definition CommCalls.h:312
void IOCB(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag flag, int xerrno, void *data)
Definition CommCalls.h:34
const char * err_type_str[]
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
const Ip::Address * FindListeningPortAddress(const HttpRequest *callerRequest, const AccessLogEntry *ale)
RawPointerT< Pointer > RawPointer(const char *label, const Pointer &ptr)
convenience wrapper for creating RawPointerT<> objects
Definition IoManip.h:73
int size
Definition ModDevPoll.cc:70
time_t squid_curtime
class SquidConfig Config
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
#define Must(condition)
const char * urlCanonicalFakeHttps(const HttpRequest *request)
Definition Uri.cc:819
#define assert(EX)
Definition assert.h:17
void self_destruct(void)
Definition cache_cf.cc:275
#define CBDATA_CLASS_INIT(type)
Definition cbdata.h:325
void updateError(const Error &)
sets (or updates the already stored) transaction error as needed
SBuf image() const
Definition UriScheme.h:57
AnyP::UriScheme const & getScheme() const
Definition Uri.h:58
SBuf & absolutePath() const
RFC 3986 section 4.2 relative reference called 'absolute-path'.
Definition Uri.cc:775
void port(const Port p)
reset authority port subcomponent
Definition Uri.h:90
void host(const char *src)
Definition Uri.cc:154
static SBuf Encode(const SBuf &, const CharacterSet &expected)
Definition Uri.cc:76
std::ostream manipulator to print containers as flat lists
Definition IoManip.h:177
auto & delimitedBy(const char *const d)
a c-string to print between consecutive items (if any). Caller must ensure lifetime.
Definition IoManip.h:188
char const * denyMessage(char const *const default_message=nullptr) const
char const * username() const
static const CharacterSet & RFC3986_UNRESERVED()
allowed URI characters that do not have a reserved purpose, RFC 3986
Ip::Address remote
Definition Connection.h:152
virtual SBuf verbose(const HttpRequestPointer &) const =0
virtual SBuf brief() const =0
an error page created from admin-configurable metadata (e.g. deny_info)
Definition errorpage.cc:72
const char * uri
admin-configured HTTP Location header value for redirection responses
Definition errorpage.cc:86
ErrorDynamicPageInfo(ErrorDynamicPageInfo &&)=delete
Http::StatusCode page_redirect
admin-configured HTTP status code
Definition errorpage.cc:96
SBuf cfgLocation
deny_info directive position in squid.conf (for reporting)
Definition errorpage.cc:92
ErrorDynamicPageInfo(const int anId, const char *aName, const SBuf &aCfgLocation)
Definition errorpage.cc:567
int id
error_text[] index for response body (unused in redirection responses)
Definition errorpage.cc:78
const char * filename
admin-configured name for the error page template (custom or standard)
Definition errorpage.cc:89
void setDefault() override
recover from loadDefault() failure to load or parse() a template
Definition errorpage.cc:228
const char * text()
The template text data read from disk.
Definition errorpage.cc:225
ErrorPageFile(const char *name, const err_type code)
Definition errorpage.cc:222
pretty-prints error page/deny_info building error
Definition errorpage.cc:117
std::ostream & printLocation(std::ostream &os) const
print() helper to report where the error was found
std::ostream & print(std::ostream &) const
reports error details (for admin-visible exceptions and debugging)
BuildErrorPrinter(const SBuf &anInputLocation, int aPage, const char *aMsg, const char *anErrorLocation)
Definition errorpage.cc:119
state and parameters shared by several ErrorState::compile*() methods
Definition errorpage.cc:107
bool allowRecursion
whether top-level compile() calls are OK
Definition errorpage.cc:112
bool building_deny_info_url
whether we compile deny_info URI
Definition errorpage.cc:111
const char * input
template bytes that need to be compiled
Definition errorpage.cc:110
SBuf output
compilation result
Definition errorpage.cc:109
static ErrorState * NewForwarding(err_type, HttpRequestPointer &, const AccessLogEntryPointer &)
Creates a general request forwarding error with the right http_status.
Definition errorpage.cc:691
SBuf compile(const char *input, bool building_deny_info_url, bool allowRecursion)
char * redirect_url
Definition errorpage.h:184
char * err_msg
Definition errorpage.h:196
void validate()
ensures that a future BuildHttpReply() is likely to succeed
err_type type
Definition errorpage.h:170
void compileLegacyCode(Build &build)
compile a single-letter code like D
Definition errorpage.cc:949
void noteBuildError_(const char *msg, const char *errorLocation, bool forceBypass)
AccessLogEntryPointer ale
transaction details (or nil)
Definition errorpage.h:198
ERCB * callback
Definition errorpage.h:185
std::optional< SBuf > dnsError
DNS lookup error message.
Definition errorpage.h:180
void bypassBuildErrorXXX(const char *const msg, const char *const errorLocation)
Definition errorpage.h:158
int Dump(MemBuf *mb)
Definition errorpage.cc:852
ErrorDetail::Pointer detail
Definition errorpage.h:204
char * err_language
Definition errorpage.h:172
void compileLogformatCode(Build &build)
compile @Squid{code} sequence containing a single logformat code
Definition errorpage.cc:913
char * url
Definition errorpage.h:178
Auth::UserRequest::Pointer auth_user_request
Definition errorpage.h:175
SBuf inputLocation
the source of the error template (for reporting purposes)
Definition errorpage.h:117
Ip::Address src_addr
Definition errorpage.h:183
static const SBuf LogformatMagic
marks each embedded logformat entry
Definition errorpage.h:211
HttpRequestPointer request
Definition errorpage.h:177
SBuf compileBody(const char *text, bool allowRecursion)
HttpReply * BuildHttpReply(void)
struct ErrorState::@47 ftp
void * callback_data
Definition errorpage.h:186
SBuf buildBody()
locates the right error page template for this error and compiles it
HttpReplyPointer response_
Definition errorpage.h:206
ErrorState()=delete
Http::StatusCode httpStatus
Definition errorpage.h:173
void noteBuildError(const char *const msg, const char *const errorLocation)
Definition errorpage.h:149
a transaction problem
Definition Error.h:27
void update(const Error &)
if necessary, stores the given error information (if any)
Definition Error.cc:51
an error page (or a part of an error page) with hard-coded template text
Definition errorpage.cc:155
const char * text
a string literal containing the error template
Definition errorpage.cc:158
err_type type
identifies the error (or a special error template part)
Definition errorpage.cc:157
char host[SQUIDHOSTNAMELEN]
Comm::ConnectionPointer tcpServer
TCP/IP level details of the last peer/server connection.
void set(const SBuf &newContent)
Definition HttpBody.h:26
void putStr(Http::HdrType id, const char *str)
String getList(Http::HdrType id) const
void updateOrAddStr(Http::HdrType, const SBuf &)
Http::StatusLine sline
Definition HttpReply.h:56
MemBuf * pack() const
Definition HttpReply.cc:112
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition HttpReply.cc:170
HttpBody body
Definition HttpReply.h:58
const SBuf & image() const
HttpRequestMethod method
void pack(Packable *p, bool maskSensitiveInfo=false) const
HierarchyLogEntry hier
String extacl_message
RequestFlags flags
Auth::UserRequest::Pointer auth_user_request
Error error
the first transaction problem encountered (or falsy)
AnyP::Uri url
the request URI
Ip::Address client_addr
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
HttpHeader header
Definition Message.h:74
AnyP::ProtocolVersion http_ver
Definition Message.h:72
Http::StatusCode status() const
retrieve the status code for this status line
Definition StatusLine.h:45
char * toStr(char *buf, const unsigned int blen, int force=AF_UNSPEC) const
Definition Address.cc:804
void append(const char *c, int sz) override
Definition MemBuf.cc:209
void init(mb_size_t szInit, mb_size_t szMax)
Definition MemBuf.cc:93
char * buf
Definition MemBuf.h:134
char * content()
start of the added data
Definition MemBuf.h:41
mb_size_t contentSize() const
available data size
Definition MemBuf.h:47
void reset()
Definition MemBuf.cc:129
int nclients
Definition MemObject.h:156
void appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
Append operation with printf-style arguments.
Definition Packable.h:61
C * getRaw() const
Definition RefCount.h:89
bool needValidation
SBuf buf()
bytes written so far
Definition Stream.h:41
Definition SBuf.h:94
const char * rawContent() const
Definition SBuf.cc:509
char at(size_type pos) const
Definition SBuf.h:253
size_type length() const
Returns the number of bytes stored in SBuf.
Definition SBuf.h:419
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition SBuf.h:279
bool isEmpty() const
Definition SBuf.h:435
SBuf & append(const SBuf &S)
Definition SBuf.cc:185
char * errHtmlText
char * errorStylesheet
int errorLogMissingLanguages
char * errorDirectory
char * errorDefaultLanguage
struct SquidConfig::@90 onoff
char * adminEmail
uint16_t flags
Definition Store.h:231
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition store.cc:1688
MemObject * mem_obj
Definition Store.h:220
store_status_t store_status
Definition Store.h:243
bool isEmpty() const
Definition Store.h:65
String substr(size_type from, size_type to) const
Definition String.cc:197
char const * termedBuf() const
Definition SquidString.h:93
size_type size() const
Definition SquidString.h:74
static ErrorDetail::Pointer NewIfAny(const int errorNo)
virtual void setDefault()
recover from loadDefault() failure to load or parse() a template
Definition errorpage.h:323
bool loadFromFile(const char *path)
Definition errorpage.cc:424
SBuf template_
raw template contents
Definition errorpage.h:332
SBuf filename
where the template was loaded from
Definition errorpage.h:314
bool loaded() const
return true if the data loaded from disk without any problem
Definition errorpage.h:286
TemplateFile(const char *name, const err_type code)
Definition errorpage.cc:357
bool wasLoaded
True if the template data read from disk without any problem.
Definition errorpage.h:333
bool tryLoadTemplate(const char *lang)
Definition errorpage.cc:399
String templateName
The name of the template.
Definition errorpage.h:335
void loadDefault()
Definition errorpage.cc:363
const char * language()
The language used for the template.
Definition errorpage.h:312
virtual bool parse()
post-process the loaded template
Definition errorpage.h:320
err_type templateCode
The internal code for this template.
Definition errorpage.h:336
String errLanguage
The error language of the template.
Definition errorpage.h:334
bool silent
Whether to print error messages on cache.log file or not. It is user defined.
Definition errorpage.h:316
bool loadFor(const HttpRequest *request)
Definition errorpage.cc:526
#define DBG_DATA
Definition Stream.h:40
#define MYNAME
Definition Stream.h:219
#define DBG_IMPORTANT
Definition Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define DBG_CRITICAL
Definition Stream.h:37
#define O_TEXT
Definition defines.h:131
#define EBIT_TEST(flag, bit)
Definition defines.h:67
@ ENTRY_ABORTED
Definition enums.h:110
@ STORE_PENDING
Definition enums.h:46
err_type
Definition forward.h:14
@ ERR_SECURE_ACCEPT_FAIL
Definition forward.h:80
@ TCP_RESET
Definition forward.h:77
@ ERR_MAX
Definition forward.h:88
@ ERR_NONE
Definition forward.h:15
@ ERR_REQUEST_PARSE_TIMEOUT
Definition forward.h:82
@ ERR_REQUEST_START_TIMEOUT
Definition forward.h:81
@ ERR_CLIENT_GONE
Definition forward.h:79
@ ERR_SQUID_SIGNATURE
Definition forward.h:71
@ ERR_RELAY_REMOTE
Definition forward.h:83
static const std::array< HardCodedError, 7 > HardCodedErrors
error messages that cannot be configured/customized externally
Definition errorpage.cc:162
static std::ostream & operator<<(std::ostream &os, const ErrorState &err)
compactly prints top-level ErrorState information (for debugging)
Definition errorpage.cc:682
err_type errorReservePageId(const char *page_name, const SBuf &cfgLocation)
allocates a new slot for the error page
Definition errorpage.cc:654
static IOCB errorSendComplete
Definition errorpage.cc:215
#define DEFAULT_SQUID_ERROR_DIR
Definition errorpage.cc:61
bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos)
Definition errorpage.cc:472
bool strHdrAcptLangGetItem(const String &hdr, char *lang, int langLen, size_t &pos)
Definition errorpage.cc:472
int FD_READ_METHOD(int fd, char *buf, int len)
Definition fde.h:194
int file_open(const char *path, int mode)
Definition fs_io.cc:66
void file_close(int fd)
Definition fs_io.cc:92
char const * visible_appname_string
const char * external_acl_message
int starting_up
int reconfiguring
void errorInitialize(void)
Definition errorpage.cc:261
void errorSend(const Comm::ConnectionPointer &conn, ErrorState *err)
Definition errorpage.cc:792
void errorClean(void)
Definition errorpage.cc:323
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition errorpage.cc:738
const char * errorPageName(int pageId)
error ID to string
Definition errorpage.cc:669
static char ** error_text
Definition errorpage.cc:206
static const char * errorFindHardText(err_type type)
Definition errorpage.cc:348
static std::vector< ErrorDynamicPageInfo * > ErrorDynamicPages
Definition errorpage.cc:201
static err_type & operator++(err_type &anErr)
Definition errorpage.cc:236
static int operator-(err_type const &anErr, err_type const &anErr2)
Definition errorpage.cc:245
static int errorPageId(const char *page_name)
Definition errorpage.cc:638
static int error_page_count
Definition errorpage.cc:209
static MemBuf error_stylesheet
Definition errorpage.cc:212
char * html_quote(const char *string)
Definition Quoting.cc:42
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition forward.h:25
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition Connection.cc:27
void Write(const Comm::ConnectionPointer &conn, const char *buf, int size, AsyncCall::Pointer &callback, FREE *free_func)
Definition Write.cc:33
Flag
Definition Flag.h:15
@ ERR_CLOSING
Definition Flag.h:24
static const char * IsDenyInfoUri(const int page_id)
Definition errorpage.cc:253
static void ImportStaticErrorText(const int page_id, const char *text, const SBuf &inputLocation)
add error page template to the global index
static void ValidateStaticError(const int page_id, const SBuf &inputLocation)
validate static error page
static std::ostream & operator<<(std::ostream &os, const BuildErrorPrinter &context)
Definition errorpage.cc:140
size_t AssembleOne(const char *start, MemBuf &buf, const AccessLogEntryPointer &ale)
Definition Format.cc:99
const SBuf & UrlWith2f(HttpRequest *)
Definition forward.h:18
StatusCode
Definition StatusCode.h:20
@ scGatewayTimeout
Definition StatusCode.h:77
@ scFound
Definition StatusCode.h:39
@ scNone
Definition StatusCode.h:21
@ scTemporaryRedirect
Definition StatusCode.h:43
@ scServiceUnavailable
Definition StatusCode.h:76
@ METHOD_GET
Definition MethodType.h:25
@ METHOD_HEAD
Definition MethodType.h:28
AnyP::ProtocolVersion ProtocolVersion()
void errorDetailClean()
void errorDetailInitialize()
const char * FormatRfc1123(time_t)
Definition rfc1123.cc:202
const char * FormatHttpd(time_t)
Definition gadgets.cc:116
#define xfree
#define xstrdup
#define rfc1738_escape_part(x)
Definition rfc1738.h:55
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition Stream.h:63
#define MAXPATHLEN
Definition stdio.h:62
char * strerror(int ern)
Definition strerror.c:22
int unsigned int
Definition stub_fd.cc:19
SBuf text("GET http://resource.com/path HTTP/1.1\r\n" "Host: resource.com\r\n" "Cookie: laijkpk3422r j1noin \r\n" "\r\n")
const char * getMyHostname(void)
Definition tools.cc:468
int getMyPort(void)
Definition tools.cc:1042
void wordlistDestroy(wordlist **list)
destroy a wordlist
Definition wordlist.cc:16
void wordlistCat(const wordlist *w, MemBuf *mb)
Definition wordlist.cc:35
void * xcalloc(size_t n, size_t sz)
Definition xalloc.cc:71
#define safe_free(x)
Definition xalloc.h:73
#define xisspace(x)
Definition xis.h:15
#define xisdigit(x)
Definition xis.h:18
#define xtolower(x)
Definition xis.h:17
const char * xstrerr(int error)
Definition xstrerror.cc:83