2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_SSL_ERRORDETAILMANAGER_H
10 #define SQUID_SRC_SSL_ERRORDETAILMANAGER_H
12 #include "base/RefCount.h"
13 #include "HttpRequest.h"
14 #include "sbuf/SBuf.h"
15 #include "ssl/support.h"
24 class ErrorDetailEntry
27 /// extracts quoted detail and descr fields from the given header
28 ErrorDetailEntry(const SBuf
&aName
, const HttpHeader
&);
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)
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).
39 class ErrorDetailsList
: public RefCountable
42 typedef RefCount
<ErrorDetailsList
> Pointer
;
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;
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
54 * It is used to load, manage and query multiple ErrorDetailLists
57 class ErrorDetailsManager
60 ErrorDetailsManager();
62 static ErrorDetailsManager
&GetInstance(); ///< Instance class
63 static void Shutdown(); ///< reset the ErrorDetailsManager instance
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.
72 const ErrorDetailEntry
*findDetail(Security::ErrorCode value
, const HttpRequest::Pointer
&request
) const;
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;
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;
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
89 /// An instance of ErrorDetailsManager to be used by squid (ssl/ErrorDetails.*)
90 static ErrorDetailsManager
*TheDetailsManager
;
93 void errorDetailInitialize();
94 void errorDetailClean();
96 #endif /* SQUID_SRC_SSL_ERRORDETAILMANAGER_H */