]> git.ipfire.org Git - thirdparty/squid.git/blob - src/error/Detail.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / error / Detail.cc
1 /*
2 * Copyright (C) 1996-2021 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 #include "squid.h"
10 #include "error/Detail.h"
11 #include "HttpRequest.h"
12 #include "sbuf/SBuf.h"
13 #include "sbuf/Stream.h"
14
15 /// details an error by tying it to a uniquely named circumstance
16 class NamedErrorDetail: public ErrorDetail
17 {
18 public:
19 // convert from c-string to SBuf to simplify creation and optimize usage
20 /// \param aName must not contain characters that require quoting in access logs or HTML
21 explicit NamedErrorDetail(const char *aName): name(aName) {}
22
23 /* ErrorDetail API */
24 virtual SBuf brief() const override { return name; }
25 virtual SBuf verbose(const HttpRequestPointer &) const override { return name; }
26
27 private:
28 /// distinguishes us from all other NamedErrorDetail objects
29 SBuf name;
30 };
31
32 /* ErrorDetail */
33
34 std::ostream &
35 operator <<(std::ostream &os, const ErrorDetail &detail)
36 {
37 os << detail.brief();
38 return os;
39 }
40
41 std::ostream &
42 operator <<(std::ostream &os, const ErrorDetail::Pointer &detail)
43 {
44 if (detail)
45 os << *detail;
46 else
47 os << "[no details]";
48 return os;
49 }
50
51 /* NamedErrorDetail */
52
53 ErrorDetail::Pointer
54 MakeNamedErrorDetail(const char *name)
55 {
56 return new NamedErrorDetail(name);
57 }
58