]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ssl/ErrorDetailManager.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ssl / ErrorDetailManager.h
1 /*
2 * Copyright (C) 1996-2017 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_SSL_ERRORDETAILMANAGER_H
10 #define _SQUID_SSL_ERRORDETAILMANAGER_H
11
12 #include "base/RefCount.h"
13 #include "HttpRequest.h"
14 #include "SquidString.h"
15 #include "ssl/support.h"
16
17 #include <map>
18 #include <string>
19
20 class HttpRequest;
21
22 namespace Ssl
23 {
24
25 class ErrorDetailEntry
26 {
27 public:
28 Security::ErrorCode error_no; ///< The SSL error code
29 String name; ///< a name for the error
30 String detail; ///< for error page %D macro expansion; may contain macros
31 String descr; ///< short error description (for use in debug messages or error pages)
32 };
33
34 /**
35 * Used to hold an error-details.txt template in ram. An error-details,.txt is represented
36 * by a list of error detail entries (ErrorDetailEntry objects).
37 */
38 class ErrorDetailsList : public RefCountable
39 {
40 public:
41 typedef RefCount<ErrorDetailsList> Pointer;
42 /**
43 * Retrieves the error details for a given error to "entry" object
44 * \return true on success, false otherwise
45 */
46 bool getRecord(Security::ErrorCode value, ErrorDetailEntry &entry);
47 const char *getErrorDescr(Security::ErrorCode value); ///< an error description for an error if exist in list.
48 const char *getErrorDetail(Security::ErrorCode value); ///< an error details for an error if exist in list.
49
50 String errLanguage; ///< The language of the error-details.txt template, if any
51 typedef std::map<Security::ErrorCode, ErrorDetailEntry> ErrorDetails;
52 ErrorDetails theList; ///< The list of error details entries
53 };
54
55 /**
56 * It is used to load, manage and query multiple ErrorDetailLists
57 * objects.
58 */
59 class ErrorDetailsManager
60 {
61 public:
62 ErrorDetailsManager();
63
64 static ErrorDetailsManager &GetInstance(); ///< Instance class
65 static void Shutdown(); ///< reset the ErrorDetailsManager instance
66
67 /**
68 * Retrieve error details for an error. This method examine the Accept-Language
69 * of the request to retrieve the error details for requested language else return
70 * the default error details.
71 * \param vale the error code
72 * \param request the current HTTP request.
73 * \param entry where to store error details
74 * \return true on success, false otherwise
75 */
76 bool getErrorDetail(Security::ErrorCode value, const HttpRequest::Pointer &request, ErrorDetailEntry &entry);
77 const char *getDefaultErrorDescr(Security::ErrorCode value); ///< the default error description for a given error
78 const char *getDefaultErrorDetail(Security::ErrorCode value); ///< the default error details for a given error
79
80 private:
81 /// Return cached error details list for a given language if exist
82 ErrorDetailsList::Pointer getCachedDetails(const char *lang);
83 /// cache the given error details list.
84 void cacheDetails(ErrorDetailsList::Pointer &errorDetails);
85
86 typedef std::map<std::string, ErrorDetailsList::Pointer> Cache;
87 Cache cache; ///< the error details list cache
88 ErrorDetailsList::Pointer theDefaultErrorDetails; ///< the default error details list
89
90 /// An instance of ErrorDetailsManager to be used by squid (ssl/ErrorDetails.*)
91 static ErrorDetailsManager *TheDetailsManager;
92 };
93
94 void errorDetailInitialize();
95 void errorDetailClean();
96 } //namespace Ssl
97 #endif
98