From: Eduard Bagdasaryan Date: Sun, 4 Dec 2022 22:00:20 +0000 (+0000) Subject: Avoid level-3 "failed to find or read error text file" WARNINGs (#1176) X-Git-Tag: SQUID_6_0_1~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b55c8e3fec201370aa9d97b56fc827670b11893;p=thirdparty%2Fsquid.git Avoid level-3 "failed to find or read error text file" WARNINGs (#1176) ... when (re)configuring ERR_REQUEST_PARSE_TIMEOUT and ERR_RELAY_REMOTE error templates. These errors cannot be customized externally and should have been listed as such in commits 9ce4a1e and f5e1794, respectively. Also polished hard-coded error storage code. --- diff --git a/src/errorpage.cc b/src/errorpage.cc index dc10a8efba..eab150d6fb 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -142,44 +142,49 @@ static void ValidateStaticError(const int page_id, const SBuf &inputLocation); /* local constant and vars */ -/** - \ingroup ErrorPageInternal - * - \note hard coded error messages are not appended with %S - * automagically to give you more control on the format - */ -static const struct { - int type; /* and page_id */ - const char *text; -} +/// an error page (or a part of an error page) with hard-coded template text +class HardCodedError { +public: + err_type type; ///< identifies the error (or a special error template part) + const char *text; ///< a string literal containing the error template +}; /// error messages that cannot be configured/customized externally -error_hard_text[] = { - - { - ERR_SQUID_SIGNATURE, - "\n
\n" - "
\n" - "
\n" - "Generated %T by %h (%s)\n" - "
\n" - "\n" - }, - { - TCP_RESET, - "reset" - }, +static const std::array HardCodedErrors = { { - ERR_CLIENT_GONE, - "unexpected client disconnect" - }, - { - ERR_SECURE_ACCEPT_FAIL, - "secure accept fail" - }, - { - ERR_REQUEST_START_TIMEOUT, - "request start timedout" + { + ERR_SQUID_SIGNATURE, + "\n
\n" + "
\n" + "
\n" + "Generated %T by %h (%s)\n" + "
\n" + "\n" + }, + { + TCP_RESET, + "reset" + }, + { + ERR_CLIENT_GONE, + "unexpected client disconnect" + }, + { + ERR_SECURE_ACCEPT_FAIL, + "secure accept fail" + }, + { + ERR_REQUEST_START_TIMEOUT, + "request start timedout" + }, + { + ERR_REQUEST_PARSE_TIMEOUT, + "request parse timedout" + }, + { + ERR_RELAY_REMOTE, + "relay server response" + } } }; @@ -188,9 +193,6 @@ static std::vector ErrorDynamicPages; /* local prototypes */ -/// \ingroup ErrorPageInternal -static const int error_hard_text_count = sizeof(error_hard_text) / sizeof(*error_hard_text); - /// \ingroup ErrorPageInternal static char **error_text = nullptr; @@ -336,12 +338,10 @@ errorClean(void) static const char * errorFindHardText(err_type type) { - int i; - - for (i = 0; i < error_hard_text_count; ++i) - if (error_hard_text[i].type == type) - return error_hard_text[i].text; - + for (const auto &m: HardCodedErrors) { + if (m.type == type) + return m.text; + } return nullptr; }