]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ssl/ErrorDetailManager.h
Bug 5428: Warn if pkg-config is not found (#1902)
[thirdparty/squid.git] / src / ssl / ErrorDetailManager.h
1 /*
2 * Copyright (C) 1996-2023 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 #ifndef SQUID_SRC_SSL_ERRORDETAILMANAGER_H
10 #define SQUID_SRC_SSL_ERRORDETAILMANAGER_H
11
12 #include "base/RefCount.h"
13 #include "HttpRequest.h"
14 #include "sbuf/SBuf.h"
15 #include "ssl/support.h"
16
17 #include <map>
18
19 class HttpRequest;
20
21 namespace Ssl
22 {
23
24 class ErrorDetailEntry
25 {
26 public:
27 /// extracts quoted detail and descr fields from the given header
28 ErrorDetailEntry(const SBuf &aName, const HttpHeader &);
29
30 SBuf name; ///< a name for the error
31 SBuf detail; ///< for error page %D macro expansion; may contain macros
32 SBuf descr; ///< short error description (for use in debug messages or error pages)
33 };
34
35 /**
36 * Used to hold an error-details.txt template in ram. An error-details,.txt is represented
37 * by a list of error detail entries (ErrorDetailEntry objects).
38 */
39 class ErrorDetailsList : public RefCountable
40 {
41 public:
42 typedef RefCount<ErrorDetailsList> Pointer;
43
44 /// looks up metadata details for a given error (or nil); returned pointer
45 /// is invalidated by any non-constant operation on the list object
46 const ErrorDetailEntry *findRecord(Security::ErrorCode) const;
47
48 SBuf errLanguage; ///< The language of the error-details.txt template, if any
49 typedef std::map<Security::ErrorCode, ErrorDetailEntry> ErrorDetails;
50 ErrorDetails theList; ///< The list of error details entries
51 };
52
53 /**
54 * It is used to load, manage and query multiple ErrorDetailLists
55 * objects.
56 */
57 class ErrorDetailsManager
58 {
59 public:
60 ErrorDetailsManager();
61
62 static ErrorDetailsManager &GetInstance(); ///< Instance class
63 static void Shutdown(); ///< reset the ErrorDetailsManager instance
64
65 /**
66 * Retrieve error details for an error. This method examine the Accept-Language
67 * of the request to retrieve the error details for requested language else return
68 * the default error details.
69 * \param value the error code
70 * \param request the current HTTP request.
71 */
72 const ErrorDetailEntry *findDetail(Security::ErrorCode value, const HttpRequest::Pointer &request) const;
73
74 /// Default error details for the given TLS error known to Squid (or, if the
75 /// error is unknown, nil). Use findDetail() instead when the error is tied
76 /// to a specific request.
77 const ErrorDetailEntry *findDefaultDetail(Security::ErrorCode) const;
78
79 private:
80 /// Return cached error details list for a given language if exist
81 ErrorDetailsList::Pointer getCachedDetails(const char *lang) const;
82 /// cache the given error details list.
83 void cacheDetails(const ErrorDetailsList::Pointer &errorDetails) const;
84
85 using Cache = std::map<SBuf, ErrorDetailsList::Pointer>;
86 mutable Cache cache; ///< the error details list cache
87 ErrorDetailsList::Pointer theDefaultErrorDetails; ///< the default error details list
88
89 /// An instance of ErrorDetailsManager to be used by squid (ssl/ErrorDetails.*)
90 static ErrorDetailsManager *TheDetailsManager;
91 };
92
93 void errorDetailInitialize();
94 void errorDetailClean();
95 } //namespace Ssl
96 #endif /* SQUID_SRC_SSL_ERRORDETAILMANAGER_H */
97