diff --git a/GpgMELogger.h b/GpgMELogger.h new file mode 100644 index 0000000..f0777dd --- /dev/null +++ b/GpgMELogger.h @@ -0,0 +1,39 @@ +/* + * File: GpgMELogger.h + * Author: SET - nmset@yandex.com + * License : GPL v2 + * Copyright SET - © 2019 + * + * Created on November 23, 2020, 4:00 PM + */ + +#ifndef GPGMELOGGER_H +#define GPGMELOGGER_H + +#include +#include +#include +#include +#include + +using namespace Wt; + +static std::mutex gs_logGpgMEError; +#define LGE(e) LogGpgMEError(e) + +static void LogGpgMEError(const GpgME::Error& e) +{ + if (e.code() == 0) + return; + std::unique_lock lock(gs_logGpgMEError); + const string logfile = WApplication::appRoot() + string("gpgme.log"); + WLogger logger; + logger.setFile(logfile); + logger.entry("") << WLogger::timestamp + << WLogger::sep << WApplication::instance()->environment().userAgent() + << WLogger::sep << std::to_string(e.code()) + << WLogger::sep << e.asString(); +} + +#endif /* GPGMELOGGER_H */ + diff --git a/K7Main.cpp b/K7Main.cpp index 6ca86eb..7366ecc 100644 --- a/K7Main.cpp +++ b/K7Main.cpp @@ -21,6 +21,7 @@ #include "GpgMECWorker.h" #include "Tools.h" #include "SensitiveTreeTableNodeText.h" +#include "GpgMELogger.h" using namespace std; @@ -207,6 +208,7 @@ void K7Main::Search() { privkList.clear(); m_tmwMessage->SetText(e.asString()); + LGE(e); return; } /* @@ -232,6 +234,7 @@ void K7Main::Search() { pubkList.clear(); m_tmwMessage->SetText(e.asString()); + LGE(e); return; } } @@ -334,6 +337,7 @@ void K7Main::DisplayUids(const WString& fullKeyID, bool secret) if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } if (m_ttbUids->columnCount() == 1) @@ -408,6 +412,7 @@ void K7Main::DisplaySubKeys(const WString& fullKeyID, bool secret) if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } if (m_ttbSubKeys->columnCount() == 1) diff --git a/KeyEdit.cpp b/KeyEdit.cpp index 62c3c75..822cc66 100644 --- a/KeyEdit.cpp +++ b/KeyEdit.cpp @@ -13,6 +13,7 @@ #include #include "GpgMEWorker.h" #include "Tools.h" +#include "GpgMELogger.h" using namespace std; @@ -91,6 +92,7 @@ void KeyEdit::OnOwnerTrustBlurred(WTreeTableNode* keyNode, bool keyHasSecret) { lblOwnerTrust->setText(previousTrustLevel); m_owner->m_tmwMessage->SetText(TR("OwnerTrustFailure")); + LGE(e); return; } m_owner->m_tmwMessage->SetText(TR("OwnerTrustSuccess")); @@ -174,6 +176,7 @@ void KeyEdit::EditUidValidity() } if (e.code() != 0) { + LGE(e); if (m_popupCertifyUid->WhatToDo() == PopupCertifyUserId::CertifyUid) { m_owner->m_tmwMessage->SetText(e.asString()); @@ -226,6 +229,7 @@ void KeyEdit::SetKeyExpiryTime() { m_owner->m_tmwMessage->SetText(TR("SetExpirationTimeFailure")); m_popupExpiryTime->ShowPassphrase(true); + LGE(e); return; } m_owner->m_tmwMessage->SetText(TR("SetExpirationTimeSuccess")); @@ -282,6 +286,7 @@ void KeyEdit::AddOrRevokeUid() { m_popupAddUid->ShowPassphrase(true); m_owner->m_tmwMessage->SetText(e.asString()); + LGE(e); } else { diff --git a/KeyringIO.cpp b/KeyringIO.cpp index 0914bf7..1bc6900 100644 --- a/KeyringIO.cpp +++ b/KeyringIO.cpp @@ -13,6 +13,7 @@ #include "Tools.h" #include #include +#include "GpgMELogger.h" using namespace std; @@ -80,6 +81,7 @@ void KeyringIO::DoImportKey() if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } if (fpr.empty()) @@ -92,6 +94,7 @@ void KeyringIO::DoImportKey() if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } m_tmwMessage->SetText(TR("ImportSuccess") + fpr + WString(" - ") + WString(k.userID(0).name())); @@ -110,6 +113,7 @@ bool KeyringIO::CanKeyBeDeleted(const WString& fullKeyID) if (e.code() != 0 && e.code() != 16383) { // 16383 : end of file, when key is not private m_tmwMessage->SetText(e.asString()); + LGE(e); return false; } // k can now be secret or public @@ -167,6 +171,7 @@ void KeyringIO::DoDeleteKey() if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } // Delete the key using the C API @@ -233,6 +238,7 @@ void KeyringIO::DoCreateKey() if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); } else { @@ -311,6 +317,7 @@ void ExportKeyStreamResource::handleRequest(const Http::Request& request, if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } suggestFileName(m_fpr + WString(".asc"), ContentDisposition::Attachment); diff --git a/PopupCertifyUserId.cpp b/PopupCertifyUserId.cpp index bef647a..8be0ebe 100644 --- a/PopupCertifyUserId.cpp +++ b/PopupCertifyUserId.cpp @@ -15,6 +15,7 @@ #include #include #include +#include "GpgMELogger.h" using namespace std; @@ -135,6 +136,7 @@ void PopupCertifyUserId::FillPrivateKeyComboBox(vector& privateKeys) if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } /* @@ -177,6 +179,7 @@ void PopupCertifyUserId::PresentEmail() if (e.code() != 0) { m_tmwMessage->SetText(e.asString()); + LGE(e); return; } if (lst.size() != 1) diff --git a/Tools.cpp b/Tools.cpp index b4d5466..e37befc 100644 --- a/Tools.cpp +++ b/Tools.cpp @@ -10,6 +10,7 @@ #include "Tools.h" #include #include +#include "GpgMELogger.h" using namespace std; @@ -101,6 +102,7 @@ bool Tools::KeyHasSecret(const WString& fpr) GpgME::Key k = gpgw.FindKey(fpr.toUTF8().c_str(), e, true); // Look for a private key if (e.code() != 0 && e.code() != 16383) { // 16383 : end of file, when key is not private + LGE(e); return false; } return (!k.isNull()); diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index d5d6ae2..8f4d4b7 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -6,6 +6,7 @@ projectFiles="true"> AppConfig.h GpgMECWorker.h + GpgMELogger.h GpgMEWorker.h K7Main.h KeyEdit.h @@ -102,6 +103,8 @@ + + @@ -218,6 +221,8 @@ + + @@ -338,6 +343,8 @@ + + diff --git a/nbproject/private/configurations.xml b/nbproject/private/configurations.xml index 1f82c50..2c9b830 100644 --- a/nbproject/private/configurations.xml +++ b/nbproject/private/configurations.xml @@ -13,8 +13,6 @@ - -