michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsNSSComponent.h" michael@0: #include "secerr.h" michael@0: #include "sslerr.h" michael@0: michael@0: const char * michael@0: nsNSSErrors::getDefaultErrorStringName(PRErrorCode err) michael@0: { michael@0: return PR_ErrorToName(err); michael@0: } michael@0: michael@0: const char * michael@0: nsNSSErrors::getOverrideErrorStringName(PRErrorCode aErrorCode) michael@0: { michael@0: const char *id_str = nullptr; michael@0: michael@0: switch (aErrorCode) { michael@0: case SSL_ERROR_SSL_DISABLED: michael@0: id_str = "PSMERR_SSL_Disabled"; michael@0: break; michael@0: michael@0: case SSL_ERROR_SSL2_DISABLED: michael@0: id_str = "PSMERR_SSL2_Disabled"; michael@0: break; michael@0: michael@0: case SEC_ERROR_REUSED_ISSUER_AND_SERIAL: michael@0: id_str = "PSMERR_HostReusedIssuerSerial"; michael@0: break; michael@0: } michael@0: michael@0: return id_str; michael@0: } michael@0: michael@0: nsresult michael@0: nsNSSErrors::getErrorMessageFromCode(PRErrorCode err, michael@0: nsINSSComponent *component, michael@0: nsString &returnedMessage) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(component); michael@0: returnedMessage.Truncate(); michael@0: michael@0: const char *nss_error_id_str = getDefaultErrorStringName(err); michael@0: const char *id_str = getOverrideErrorStringName(err); michael@0: michael@0: if (id_str || nss_error_id_str) michael@0: { michael@0: nsString defMsg; michael@0: nsresult rv; michael@0: if (id_str) michael@0: { michael@0: rv = component->GetPIPNSSBundleString(id_str, defMsg); michael@0: } michael@0: else michael@0: { michael@0: rv = component->GetNSSBundleString(nss_error_id_str, defMsg); michael@0: } michael@0: michael@0: if (NS_SUCCEEDED(rv)) michael@0: { michael@0: returnedMessage.Append(defMsg); michael@0: returnedMessage.Append(NS_LITERAL_STRING("\n")); michael@0: } michael@0: } michael@0: michael@0: if (returnedMessage.IsEmpty()) michael@0: { michael@0: // no localized string available, use NSS' internal michael@0: returnedMessage.AppendASCII(PR_ErrorToString(err, PR_LANGUAGE_EN)); michael@0: returnedMessage.Append(NS_LITERAL_STRING("\n")); michael@0: } michael@0: michael@0: if (nss_error_id_str) michael@0: { michael@0: nsresult rv; michael@0: nsCString error_id(nss_error_id_str); michael@0: ToLowerCase(error_id); michael@0: NS_ConvertASCIItoUTF16 idU(error_id); michael@0: michael@0: const char16_t *params[1]; michael@0: params[0] = idU.get(); michael@0: michael@0: nsString formattedString; michael@0: rv = component->PIPBundleFormatStringFromName("certErrorCodePrefix", michael@0: params, 1, michael@0: formattedString); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: returnedMessage.Append(NS_LITERAL_STRING("\n")); michael@0: returnedMessage.Append(formattedString); michael@0: returnedMessage.Append(NS_LITERAL_STRING("\n")); michael@0: } michael@0: else { michael@0: returnedMessage.Append(NS_LITERAL_STRING("(")); michael@0: returnedMessage.Append(idU); michael@0: returnedMessage.Append(NS_LITERAL_STRING(")")); michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: }