aboutsummaryrefslogtreecommitdiff
path: root/exceptions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'exceptions.cpp')
-rw-r--r--exceptions.cpp71
1 files changed, 71 insertions, 0 deletions
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 <stdlib.h>
+#include <iostream>
+
+#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<ex_type_name*>(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<vmime::exceptions::ex_type_name*>(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();
+}