From aa4d426b4d3527d7e166df1a05058c9a4a0f6683 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 30 Apr 2021 00:33:56 +0200 Subject: initial/final commit --- exceptions.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 exceptions.cpp (limited to 'exceptions.cpp') diff --git a/exceptions.cpp b/exceptions.cpp new file mode 100644 index 0000000..35fa37b --- /dev/null +++ b/exceptions.cpp @@ -0,0 +1,71 @@ +#include +#include + +#include "vmime/vmime.hpp" +#include "vmime/security/cert/certificateIssuerVerificationException.hpp" +#include "vmime/security/cert/unsupportedCertificateTypeException.hpp" +#include "vmime/security/cert/certificateNotTrustedException.hpp" +#include "vmime/security/cert/certificateExpiredException.hpp" +#include "vmime/security/cert/certificateNotYetValidException.hpp" +#include "vmime/exception.hpp" + +#include "exceptions.hpp" +#include "utilities.h" + +using namespace vmime::exceptions; +using namespace vmime::security::cert; + +#define EX_COMPATIBLE(ex_type_name) (dynamic_cast(e) != nullptr) + +void handle_vmime_exception(vmime::exception *e) +{ + if (EX_COMPATIBLE(authentication_error)) + FAIL(MSG_BAD_AUTHENTICATION); + if (EX_COMPATIBLE(certificateIssuerVerificationException)) + FAIL(MSG_CERT_VERIFICATION_FAIL); + if (EX_COMPATIBLE(unsupportedCertificateTypeException)) + FAIL(MSG_BAD_CERT_FORMAT); + if (EX_COMPATIBLE(certificateNotTrustedException)) + FAIL(MSG_UNKNOWN_CERT); + if (EX_COMPATIBLE(certificateExpiredException)) + FAIL(MSG_CERT_EXPIRED); + if (EX_COMPATIBLE(certificateNotYetValidException)) + FAIL(MSG_CERT_NOT_YET_VALID); + + if (EX_COMPATIBLE(connection_error)) + std::cerr << "Blad polaczenia z serwerem: "; + else + std::cerr << "Blad (biblioteka vmime): "; + std::cerr << e->what() << std::endl; + +#define PRINT_MORE(ex_type_name, text, more) \ + ex_type_name *ex_type_name = \ + dynamic_cast(e); \ + if (ex_type_name != nullptr) \ + std::cerr << text << ex_type_name->more << std::endl; + +#define PRINT_RESPONSE(ex_type_name) \ + PRINT_MORE(ex_type_name, "Odpowiedz serwera: ", response()) + + PRINT_RESPONSE(command_error); + PRINT_RESPONSE(connection_greeting_error); + PRINT_RESPONSE(authentication_error); + PRINT_RESPONSE(invalid_response); + PRINT_MORE(filesystem_exception, "Sciezka: ", + path().toString("\\", vmime::charsets::WINDOWS_1250)); + + FAIL_NOMSG(); +} + +void handle_std_exception(std::exception *e) +{ + if (EX_COMPATIBLE(silent_exception)) + FAIL_NOMSG(); + if (EX_COMPATIBLE(std::bad_alloc)) + FAIL(MSG_MALLOC_FAIL); + + std::cerr << "Blad (biblioteka standardowa): " + << e->what() << std::endl; + + FAIL_NOMSG(); +} -- cgit v1.2.3