Log GpgME errors.
In file WT_APP_ROOT/gpgme.log. Independently of usual Wt logging.
This commit is contained in:
39
GpgMELogger.h
Normal file
39
GpgMELogger.h
Normal file
@@ -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 <Wt/WLogger.h>
|
||||
#include <Wt/WApplication.h>
|
||||
#include <Wt/WEnvironment.h>
|
||||
#include <gpgme++/error.h>
|
||||
#include <mutex>
|
||||
|
||||
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<std::mutex> 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 */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <Wt/WStandardItem.h>
|
||||
#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
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "Tools.h"
|
||||
#include <Wt/WLink.h>
|
||||
#include <strstream>
|
||||
#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);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <Wt/WRadioButton.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include "GpgMELogger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -135,6 +136,7 @@ void PopupCertifyUserId::FillPrivateKeyComboBox(vector<WString>& 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)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Tools.h"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#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());
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
projectFiles="true">
|
||||
<itemPath>AppConfig.h</itemPath>
|
||||
<itemPath>GpgMECWorker.h</itemPath>
|
||||
<itemPath>GpgMELogger.h</itemPath>
|
||||
<itemPath>GpgMEWorker.h</itemPath>
|
||||
<itemPath>K7Main.h</itemPath>
|
||||
<itemPath>KeyEdit.h</itemPath>
|
||||
@@ -102,6 +103,8 @@
|
||||
</item>
|
||||
<item path="GpgMECWorker.h" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMELogger.h" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMEWorker.cpp" ex="false" tool="1" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMEWorker.h" ex="false" tool="3" flavor2="0">
|
||||
@@ -218,6 +221,8 @@
|
||||
</item>
|
||||
<item path="GpgMECWorker.h" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMELogger.h" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMEWorker.cpp" ex="false" tool="1" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMEWorker.h" ex="false" tool="3" flavor2="0">
|
||||
@@ -338,6 +343,8 @@
|
||||
</item>
|
||||
<item path="GpgMECWorker.h" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMELogger.h" ex="false" tool="3" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMEWorker.cpp" ex="false" tool="1" flavor2="0">
|
||||
</item>
|
||||
<item path="GpgMEWorker.h" ex="false" tool="3" flavor2="0">
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
<gdb_interceptlist>
|
||||
<gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
|
||||
</gdb_interceptlist>
|
||||
<gdb_signals>
|
||||
</gdb_signals>
|
||||
<gdb_options>
|
||||
<DebugOptions>
|
||||
</DebugOptions>
|
||||
|
||||
Reference in New Issue
Block a user