feat: upgrade infrastructure to simplify code
This commit is contained in:
parent
c27c541257
commit
b6f4647719
@ -43,17 +43,41 @@
|
|||||||
#define UDUP(v) UnStrDup(v)
|
#define UDUP(v) UnStrDup(v)
|
||||||
#define QDUP(v) QStrDup(v)
|
#define QDUP(v) QStrDup(v)
|
||||||
|
|
||||||
|
#define LISTEN(event) GFModuleListenEvent(GFGetModuleID(), DUP(event));
|
||||||
|
|
||||||
|
#define EXECUTE_MODULE() \
|
||||||
|
auto GFExecuteModule(GFModuleEvent* p_event) -> int { \
|
||||||
|
auto event = ConvertEventToMap(p_event);
|
||||||
|
|
||||||
|
#define END_EXECUTE_MODULE() }
|
||||||
|
|
||||||
|
#define CB_SUCC(event) \
|
||||||
|
CB(event, GFGetModuleID(), {{"ret", "0"}}); \
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#define CB_ERR(event, ret, err) \
|
||||||
|
CB(event, GFGetModuleID(), \
|
||||||
|
{{"ret", QString::number(ret)}, {"reason", QString(err)}}); \
|
||||||
|
return ret;
|
||||||
|
|
||||||
inline void MLogDebug(const QString& s) { GFModuleLogDebug(s.toUtf8()); }
|
inline void MLogDebug(const QString& s) { GFModuleLogDebug(s.toUtf8()); }
|
||||||
inline void MLogInfo(const QString& s) { GFModuleLogInfo(s.toUtf8()); }
|
inline void MLogInfo(const QString& s) { GFModuleLogInfo(s.toUtf8()); }
|
||||||
inline void MLogWarn(const QString& s) { GFModuleLogWarn(s.toUtf8()); }
|
inline void MLogWarn(const QString& s) { GFModuleLogWarn(s.toUtf8()); }
|
||||||
inline void MLogError(const QString& s) { GFModuleLogError(s.toUtf8()); }
|
inline void MLogError(const QString& s) { GFModuleLogError(s.toUtf8()); }
|
||||||
|
|
||||||
#define MLogDebugS(format, ...) \
|
#define LOG_DEBUG(format) MLogDebug(FormatString(QString(format)))
|
||||||
MLogDebug(QString::asprintf(format, __VA_ARGS__))
|
#define LOG_INFO(format) MLogDebug(FormatString(QString(format)))
|
||||||
#define MLogInfoS(format, ...) MLogInfo(QString::asprintf(format, __VA_ARGS__))
|
#define LOG_WARN(format) MLogDebug(FormatString(QString(format)))
|
||||||
#define MLogWarnS(format, ...) MLogWarn(QString::asprintf(format, __VA_ARGS__))
|
#define LOG_ERROR(format) MLogDebug(FormatString(QString(format)))
|
||||||
#define MLogErrorS(format, ...) \
|
|
||||||
MLogError(QString::asprintf(format, __VA_ARGS__))
|
#define FLOG_DEBUG(format, ...) \
|
||||||
|
MLogDebug(FormatString(QString(format), __VA_ARGS__))
|
||||||
|
#define FLOG_INFO(format, ...) \
|
||||||
|
MLogInfo(FormatString(QString(format), __VA_ARGS__))
|
||||||
|
#define FLOG_WARN(format, ...) \
|
||||||
|
MLogWarn(FormatString(QString(format), __VA_ARGS__))
|
||||||
|
#define FLOG_ERROR(format, ...) \
|
||||||
|
MLogError(FormatString(QString(format), __VA_ARGS__))
|
||||||
|
|
||||||
inline auto QStrDup(QString str) -> char* { return DUP(str.toUtf8()); }
|
inline auto QStrDup(QString str) -> char* { return DUP(str.toUtf8()); }
|
||||||
|
|
||||||
@ -179,6 +203,12 @@ inline auto ConvertMapToEvent(QMap<QString, QString> event_map)
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void CB(const QMap<QString, QString>& event, const char* module,
|
||||||
|
const QMap<QString, QString>& params) {
|
||||||
|
GFModuleTriggerModuleEventCallback(ConvertMapToEvent(event), module,
|
||||||
|
ConvertMapToParams(params));
|
||||||
|
}
|
||||||
|
|
||||||
inline auto AllocBufferAndCopy(const QByteArray& b) -> char* {
|
inline auto AllocBufferAndCopy(const QByteArray& b) -> char* {
|
||||||
auto* p = static_cast<char*>(GFAllocateMemory(sizeof(char) * b.size()));
|
auto* p = static_cast<char*>(GFAllocateMemory(sizeof(char) * b.size()));
|
||||||
memcpy(p, b.constData(), b.size());
|
memcpy(p, b.constData(), b.size());
|
||||||
@ -261,3 +291,18 @@ inline auto CharArrayToQStringList(char** pl_components,
|
|||||||
GFFreeMemory(pl_components);
|
GFFreeMemory(pl_components);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
auto FormatString(const QString& format, Args... args) -> QString {
|
||||||
|
return FormatStringHelper(format, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto FormatStringHelper(const QString& format, T arg) -> QString {
|
||||||
|
return format.arg(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename... Args>
|
||||||
|
auto FormatStringHelper(const QString& format, T arg, Args... args) -> QString {
|
||||||
|
return FormatStringHelper(format.arg(arg), args...);
|
||||||
|
}
|
47
include/GFModuleDeclare.h
Normal file
47
include/GFModuleDeclare.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021 Saturneric <eric@bktus.com>
|
||||||
|
*
|
||||||
|
* This file is part of GpgFrontend.
|
||||||
|
*
|
||||||
|
* GpgFrontend is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GpgFrontend is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* The initial version of the source code is inherited from
|
||||||
|
* the gpg4usb project, which is under GPL-3.0-or-later.
|
||||||
|
*
|
||||||
|
* All the source code of GpgFrontend was modified and released by
|
||||||
|
* Saturneric <eric@bktus.com> starting on May 12, 2021.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <GFSDKModule.h>
|
||||||
|
|
||||||
|
#include "GFModuleExport.h"
|
||||||
|
|
||||||
|
#define GF_MODULE_API_DECLARE \
|
||||||
|
extern "C" { \
|
||||||
|
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *; \
|
||||||
|
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *; \
|
||||||
|
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *; \
|
||||||
|
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *; \
|
||||||
|
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *; \
|
||||||
|
auto GF_MODULE_EXPORT GFRegisterModule() -> int; \
|
||||||
|
auto GF_MODULE_EXPORT GFActiveModule() -> int; \
|
||||||
|
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int; \
|
||||||
|
auto GF_MODULE_EXPORT GFDeactivateModule() -> int; \
|
||||||
|
auto GF_MODULE_EXPORT GFUnregisterModule() -> int; \
|
||||||
|
};
|
49
include/GFModuleDefine.h
Normal file
49
include/GFModuleDefine.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021 Saturneric <eric@bktus.com>
|
||||||
|
*
|
||||||
|
* This file is part of GpgFrontend.
|
||||||
|
*
|
||||||
|
* GpgFrontend is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GpgFrontend is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* The initial version of the source code is inherited from
|
||||||
|
* the gpg4usb project, which is under GPL-3.0-or-later.
|
||||||
|
*
|
||||||
|
* All the source code of GpgFrontend was modified and released by
|
||||||
|
* Saturneric <eric@bktus.com> starting on May 12, 2021.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "GFModuleCommonUtils.hpp"
|
||||||
|
#include "GFSDKBuildInfo.h"
|
||||||
|
|
||||||
|
#define GF_MODULE_API_DEFINE(id, name, ver, desc, author) \
|
||||||
|
class GTrC { \
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(GTrC) \
|
||||||
|
}; \
|
||||||
|
auto GFGetModuleGFSDKVersion() -> const char* { \
|
||||||
|
return DUP(GF_SDK_VERSION_STR); \
|
||||||
|
} \
|
||||||
|
auto GFGetModuleQtEnvVersion() -> const char* { \
|
||||||
|
return DUP(QT_VERSION_STR); \
|
||||||
|
} \
|
||||||
|
auto GFGetModuleID() -> const char* { return DUP((id)); } \
|
||||||
|
auto GFGetModuleVersion() -> const char* { return DUP((ver)); } \
|
||||||
|
auto GFGetModuleMetaData() -> GFModuleMetaData* { \
|
||||||
|
return QMapToGFModuleMetaDataList( \
|
||||||
|
{{"Name", (name)}, {"Description", (desc)}, {"Author", (author)}}); \
|
||||||
|
}
|
@ -43,11 +43,12 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "GFModuleCommonUtils.hpp"
|
#include "GFModuleCommonUtils.hpp"
|
||||||
|
#include "GFModuleDefine.h"
|
||||||
#include "GpgInfo.h"
|
#include "GpgInfo.h"
|
||||||
|
|
||||||
class GTrC {
|
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.gnupg_info_gathering",
|
||||||
Q_DECLARE_TR_FUNCTIONS(GTrC)
|
"GatherGnupgInfo", "1.0.0",
|
||||||
};
|
"Try gathering gnupg informations.", "Saturneric")
|
||||||
|
|
||||||
extern auto CalculateBinaryChacksum(const QString &path)
|
extern auto CalculateBinaryChacksum(const QString &path)
|
||||||
-> std::optional<QString>;
|
-> std::optional<QString>;
|
||||||
@ -68,25 +69,6 @@ using Context = struct {
|
|||||||
GpgComponentInfo component_info;
|
GpgComponentInfo component_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto GFGetModuleGFSDKVersion() -> const char * {
|
|
||||||
return DUP(GF_SDK_VERSION_STR);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); }
|
|
||||||
|
|
||||||
auto GFGetModuleID() -> const char * {
|
|
||||||
return DUP("com.bktus.gpgfrontend.module.gnupg_info_gathering");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
|
|
||||||
|
|
||||||
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
|
||||||
return QMapToGFModuleMetaDataList(
|
|
||||||
{{"Name", "GatherGnupgInfo"},
|
|
||||||
{"Description", "Try gathering gnupg informations."},
|
|
||||||
{"Author", "Saturneric"}});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFRegisterModule() -> int {
|
auto GFRegisterModule() -> int {
|
||||||
MLogDebug("gnupg info gathering module registering");
|
MLogDebug("gnupg info gathering module registering");
|
||||||
|
|
||||||
@ -98,25 +80,21 @@ auto GFRegisterModule() -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GFActiveModule() -> int {
|
auto GFActiveModule() -> int {
|
||||||
MLogDebug("gnupg info gathering module activating");
|
LISTEN("REQUEST_GATHERING_GNUPG_INFO");
|
||||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_GATHERING_GNUPG_INFO"));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFExecuteModule(GFModuleEvent *event) -> int {
|
EXECUTE_MODULE() {
|
||||||
MLogDebug(QString("gnupg info gathering module executing, event id: %1")
|
FLOG_DEBUG("gnupg info gathering module executing, event id: %1",
|
||||||
.arg(event->id));
|
event["event_id"]);
|
||||||
|
|
||||||
StartGatheringGnuPGInfo();
|
StartGatheringGnuPGInfo();
|
||||||
|
|
||||||
GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1,
|
CB_SUCC(event);
|
||||||
ConvertMapToParams({{"ret", "0"}}));
|
|
||||||
|
|
||||||
MLogDebug("gnupg external info gathering done");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
END_EXECUTE_MODULE()
|
||||||
|
|
||||||
auto GFDeactiveModule() -> int { return 0; }
|
auto GFDeactivateModule() -> int { return 0; }
|
||||||
|
|
||||||
auto GFUnregisterModule() -> int {
|
auto GFUnregisterModule() -> int {
|
||||||
MLogDebug("gnupg info gathering module unregistering");
|
MLogDebug("gnupg info gathering module unregistering");
|
||||||
|
@ -28,29 +28,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <GFSDKModule.h>
|
#include "GFModuleDeclare.h"
|
||||||
|
|
||||||
#include "GFModuleExport.h"
|
GF_MODULE_API_DECLARE
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
|
||||||
};
|
|
@ -30,56 +30,30 @@
|
|||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
|
||||||
#include "GFModuleCommonUtils.hpp"
|
#include "GFModuleDefine.h"
|
||||||
#include "GFSDKBuildInfo.h"
|
|
||||||
#include "extract.h"
|
#include "extract.h"
|
||||||
|
|
||||||
auto GFGetModuleGFSDKVersion() -> const char * {
|
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.paper_key", "PaperKey",
|
||||||
return DUP(GF_SDK_VERSION_STR);
|
"1.0.0", "Integrated PaperKey Functions.", "Saturneric")
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); }
|
|
||||||
|
|
||||||
auto GFGetModuleID() -> const char * {
|
|
||||||
return DUP("com.bktus.gpgfrontend.module.paper_key");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
|
|
||||||
|
|
||||||
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
|
||||||
return QMapToGFModuleMetaDataList(
|
|
||||||
{{"Name", "PaperKey"},
|
|
||||||
{"Description", "Integrated PaperKey Functions."},
|
|
||||||
{"Author", "Saturneric"}});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFRegisterModule() -> int {
|
auto GFRegisterModule() -> int {
|
||||||
MLogDebug("paper key module registering");
|
LOG_DEBUG("paper key module registering");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFActiveModule() -> int {
|
auto GFActiveModule() -> int {
|
||||||
MLogDebug("paper key module activating");
|
LISTEN("REQUEST_TRANS_KEY_2_PAPER_KEY");
|
||||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_KEY_2_PAPER_KEY"));
|
LISTEN("REQUEST_TRANS_PAPER_KEY_2_KEY");
|
||||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_PAPER_KEY_2_KEY"));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
EXECUTE_MODULE() {
|
||||||
MLogDebug(
|
FLOG_DEBUG("paper key module executing, event id: %1", event["event_id"]);
|
||||||
QString("paper key module executing, event id: %1").arg(p_event->id));
|
|
||||||
|
|
||||||
auto event = ConvertEventToMap(p_event);
|
|
||||||
|
|
||||||
if (event["event_id"] == "REQUEST_TRANS_KEY_2_PAPER_KEY") {
|
if (event["event_id"] == "REQUEST_TRANS_KEY_2_PAPER_KEY") {
|
||||||
if (event["secret_key"].isEmpty() || event["output_path"].isEmpty()) {
|
if (event["secret_key"].isEmpty() || event["output_path"].isEmpty()) {
|
||||||
GFModuleTriggerModuleEventCallback(
|
CB_ERR(event, -1, "secret key or output path is empty");
|
||||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
|
||||||
ConvertMapToParams(
|
|
||||||
{{"ret", "-1"},
|
|
||||||
{"reason", "secret key or output path is empty"}}));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray secret_key_data =
|
QByteArray secret_key_data =
|
||||||
@ -87,9 +61,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
|
|
||||||
QTemporaryFile secret_key_t_file;
|
QTemporaryFile secret_key_t_file;
|
||||||
if (!secret_key_t_file.open()) {
|
if (!secret_key_t_file.open()) {
|
||||||
qWarning() << "Unable to open temporary file";
|
CB_ERR(event, -1, "unable to open temporary file");
|
||||||
MLogWarn("unable to open temporary file");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
secret_key_t_file.write(secret_key_data);
|
secret_key_t_file.write(secret_key_data);
|
||||||
@ -98,8 +70,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
|
|
||||||
FILE *file = fdopen(secret_key_t_file.handle(), "rb");
|
FILE *file = fdopen(secret_key_t_file.handle(), "rb");
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
qDebug() << "Unable to convert QTemporaryFile to FILE*";
|
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extract(file, event["output_path"].toUtf8(), AUTO);
|
extract(file, event["output_path"].toUtf8(), AUTO);
|
||||||
@ -107,12 +78,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
} else if (event["event_id"] == "REQUEST_TRANS_PAPER_KEY_2_KEY") {
|
} else if (event["event_id"] == "REQUEST_TRANS_PAPER_KEY_2_KEY") {
|
||||||
if (event["public_key"].isEmpty() || event["paper_key_secrets"].isEmpty()) {
|
if (event["public_key"].isEmpty() || event["paper_key_secrets"].isEmpty()) {
|
||||||
GFModuleTriggerModuleEventCallback(
|
CB_ERR(event, -1, "public key or paper key secrets is empty");
|
||||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
|
||||||
ConvertMapToParams(
|
|
||||||
{{"ret", "-1"},
|
|
||||||
{"reason", "public key or paper key secrets is empty"}}));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray public_key_data =
|
QByteArray public_key_data =
|
||||||
@ -120,11 +86,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
|
|
||||||
QTemporaryFile public_key_t_file;
|
QTemporaryFile public_key_t_file;
|
||||||
if (!public_key_t_file.open()) {
|
if (!public_key_t_file.open()) {
|
||||||
GFModuleTriggerModuleEventCallback(
|
CB_ERR(event, -1, "unable to open temporary file");
|
||||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
|
||||||
ConvertMapToParams(
|
|
||||||
{{"ret", "-1"}, {"reason", "unable to open temporary file"}}));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public_key_t_file.write(public_key_data);
|
public_key_t_file.write(public_key_data);
|
||||||
@ -133,12 +95,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
|
|
||||||
FILE *pubring = fdopen(public_key_t_file.handle(), "rb");
|
FILE *pubring = fdopen(public_key_t_file.handle(), "rb");
|
||||||
if (pubring == nullptr) {
|
if (pubring == nullptr) {
|
||||||
GFModuleTriggerModuleEventCallback(
|
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
|
||||||
ConvertMapToParams(
|
|
||||||
{{"ret", "-1"},
|
|
||||||
{"reason", "unable to convert QTemporaryFile to FILE*"}}));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray secrets_data =
|
QByteArray secrets_data =
|
||||||
@ -146,11 +103,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
|
|
||||||
QTemporaryFile secrets_data_file;
|
QTemporaryFile secrets_data_file;
|
||||||
if (!secrets_data_file.open()) {
|
if (!secrets_data_file.open()) {
|
||||||
GFModuleTriggerModuleEventCallback(
|
CB_ERR(event, -1, "unable to open temporary file");
|
||||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
|
||||||
ConvertMapToParams(
|
|
||||||
{{"ret", "-1"}, {"reason", "unable to open temporary file"}}));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
secrets_data_file.write(public_key_data);
|
secrets_data_file.write(public_key_data);
|
||||||
@ -159,23 +112,17 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
|
|
||||||
FILE *secrets = fdopen(secrets_data_file.handle(), "rb");
|
FILE *secrets = fdopen(secrets_data_file.handle(), "rb");
|
||||||
if (secrets == nullptr) {
|
if (secrets == nullptr) {
|
||||||
GFModuleTriggerModuleEventCallback(
|
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
|
||||||
ConvertMapToParams(
|
|
||||||
{{"ret", "-1"},
|
|
||||||
{"reason", "unable to convert QTemporaryFile to FILE*"}}));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
restore(pubring, secrets, AUTO, )
|
restore(pubring, secrets, AUTO, )
|
||||||
}
|
}
|
||||||
|
|
||||||
GFModuleTriggerModuleEventCallback(ConvertMapToEvent(event), GFGetModuleID(),
|
CB_SUCC(event);
|
||||||
1, ConvertMapToParams({{"ret", "0"}}));
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
END_EXECUTE_MODULE()
|
||||||
|
|
||||||
auto GFDeactiveModule() -> int { return 0; }
|
auto GFDeactivateModule() -> int { return 0; }
|
||||||
|
|
||||||
auto GFUnregisterModule() -> int {
|
auto GFUnregisterModule() -> int {
|
||||||
MLogDebug("paper key module unregistering");
|
MLogDebug("paper key module unregistering");
|
||||||
|
@ -28,29 +28,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <GFSDKModule.h>
|
#include "GFModuleDeclare.h"
|
||||||
|
|
||||||
#include "GFModuleExport.h"
|
GF_MODULE_API_DECLARE
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
|
||||||
};
|
|
||||||
|
@ -33,27 +33,12 @@
|
|||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
|
|
||||||
#include "GFModuleCommonUtils.hpp"
|
#include "GFModuleCommonUtils.hpp"
|
||||||
#include "GFSDKBuildInfo.h"
|
#include "GFModuleDefine.h"
|
||||||
#include "GpgPassphraseContext.h"
|
#include "GpgPassphraseContext.h"
|
||||||
#include "RaisePinentry.h"
|
#include "RaisePinentry.h"
|
||||||
|
|
||||||
auto GFGetModuleGFSDKVersion() -> const char * {
|
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.pinentry", "Pinentry",
|
||||||
return DUP(GF_SDK_VERSION_STR);
|
"1.0.0", "A simple tiny pinentry.", "Saturneric")
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); }
|
|
||||||
|
|
||||||
auto GFGetModuleID() -> const char * {
|
|
||||||
return DUP("com.bktus.gpgfrontend.module.pinentry");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
|
|
||||||
|
|
||||||
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
|
||||||
return QMapToGFModuleMetaDataList({{"Name", "Pinentry"},
|
|
||||||
{"Description", "A simple tiny pinentry."},
|
|
||||||
{"Author", "Saturneric"}});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFRegisterModule() -> int {
|
auto GFRegisterModule() -> int {
|
||||||
MLogDebug("pinentry module registering");
|
MLogDebug("pinentry module registering");
|
||||||
@ -62,9 +47,7 @@ auto GFRegisterModule() -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GFActiveModule() -> int {
|
auto GFActiveModule() -> int {
|
||||||
MLogDebug("pinentry module activating");
|
LISTEN("REQUEST_PIN_ENTRY");
|
||||||
|
|
||||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_PIN_ENTRY"));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +57,13 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
|
|
||||||
auto event = ConvertEventToMap(p_event);
|
auto event = ConvertEventToMap(p_event);
|
||||||
|
|
||||||
|
if (event["prev_was_bad"].isEmpty() || event["ask_for_new"].isEmpty()) {
|
||||||
|
GFModuleTriggerModuleEventCallback(
|
||||||
|
ConvertMapToEvent(event), GFGetModuleID(),
|
||||||
|
ConvertMapToParams({{"ret", "-1"}, {"passphrase", ""}}));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
QMetaObject::invokeMethod(
|
QMetaObject::invokeMethod(
|
||||||
QApplication::instance()->thread(), [p_event, event]() -> int {
|
QApplication::instance()->thread(), [p_event, event]() -> int {
|
||||||
auto *p = new RaisePinentry(
|
auto *p = new RaisePinentry(
|
||||||
@ -86,7 +76,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
p, &RaisePinentry::SignalUserInputPassphraseCallback, p,
|
p, &RaisePinentry::SignalUserInputPassphraseCallback, p,
|
||||||
[event](const QSharedPointer<GpgPassphraseContext> &c) {
|
[event](const QSharedPointer<GpgPassphraseContext> &c) {
|
||||||
GFModuleTriggerModuleEventCallback(
|
GFModuleTriggerModuleEventCallback(
|
||||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
ConvertMapToEvent(event), GFGetModuleID(),
|
||||||
ConvertMapToParams({{"passphrase", c->GetPassphrase()}}));
|
ConvertMapToParams({{"passphrase", c->GetPassphrase()}}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -97,7 +87,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFDeactiveModule() -> int { return 0; }
|
auto GFDeactivateModule() -> int { return 0; }
|
||||||
|
|
||||||
auto GFUnregisterModule() -> int {
|
auto GFUnregisterModule() -> int {
|
||||||
MLogDebug("pinentry module unregistering");
|
MLogDebug("pinentry module unregistering");
|
||||||
|
@ -28,29 +28,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <GFSDKModule.h>
|
#include "GFModuleDeclare.h"
|
||||||
|
|
||||||
#include "GFModuleExport.h"
|
GF_MODULE_API_DECLARE
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
|
||||||
};
|
|
@ -38,32 +38,13 @@
|
|||||||
#include <QtNetwork>
|
#include <QtNetwork>
|
||||||
|
|
||||||
#include "GFModuleCommonUtils.hpp"
|
#include "GFModuleCommonUtils.hpp"
|
||||||
|
#include "GFModuleDefine.h"
|
||||||
#include "SoftwareVersion.h"
|
#include "SoftwareVersion.h"
|
||||||
#include "UpdateTab.h"
|
#include "UpdateTab.h"
|
||||||
#include "VersionCheckTask.h"
|
#include "VersionCheckTask.h"
|
||||||
|
|
||||||
class GTrC {
|
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.VersionChecking", "Pinentry",
|
||||||
Q_DECLARE_TR_FUNCTIONS(GTrC)
|
"1.0.0", "Try checking GpgFrontend version.", "Saturneric")
|
||||||
};
|
|
||||||
|
|
||||||
auto GFGetModuleGFSDKVersion() -> const char* {
|
|
||||||
return DUP(GF_SDK_VERSION_STR);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleQtEnvVersion() -> const char* { return DUP(QT_VERSION_STR); }
|
|
||||||
|
|
||||||
auto GFGetModuleID() -> const char* {
|
|
||||||
return DUP("com.bktus.gpgfrontend.module.version_checking");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFGetModuleVersion() -> const char* { return DUP("1.0.0"); }
|
|
||||||
|
|
||||||
auto GFGetModuleMetaData() -> GFModuleMetaData* {
|
|
||||||
return QMapToGFModuleMetaDataList(
|
|
||||||
{{"Name", "VersionChecking"},
|
|
||||||
{"Description", "Try checking GpgFrontend version."},
|
|
||||||
{"Author", "Saturneric"}});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GFRegisterModule() -> int {
|
auto GFRegisterModule() -> int {
|
||||||
MLogInfo("version checking module registering");
|
MLogInfo("version checking module registering");
|
||||||
@ -73,15 +54,15 @@ auto GFRegisterModule() -> int {
|
|||||||
auto GFActiveModule() -> int {
|
auto GFActiveModule() -> int {
|
||||||
MLogInfo("version checking module activating");
|
MLogInfo("version checking module activating");
|
||||||
|
|
||||||
GFModuleListenEvent(GFGetModuleID(), DUP("APPLICATION_LOADED"));
|
LISTEN("APPLICATION_LOADED");
|
||||||
GFModuleListenEvent(GFGetModuleID(), DUP("CHECK_APPLICATION_VERSION"));
|
LISTEN("CHECK_APPLICATION_VERSION");
|
||||||
|
|
||||||
// load translations
|
// load translations
|
||||||
QFile f(
|
QFile f(
|
||||||
QString(":/i18n/ModuleVersionChecking.%1.qm").arg(GFAppActiveLocale()));
|
QString(":/i18n/ModuleVersionChecking.%1.qm").arg(GFAppActiveLocale()));
|
||||||
if (f.exists() && f.open(QIODevice::ReadOnly)) {
|
if (f.exists() && f.open(QIODevice::ReadOnly)) {
|
||||||
auto f_n = f.fileName().toUtf8();
|
auto f_n = f.fileName().toUtf8();
|
||||||
MLogInfoS("version checking module loading, locale: %s, path: %s",
|
FLOG_INFO("version checking module loading, locale: %1, path: %2",
|
||||||
GFAppActiveLocale(), f_n.data());
|
GFAppActiveLocale(), f_n.data());
|
||||||
auto b = f.readAll();
|
auto b = f.readAll();
|
||||||
GFAppRegisterTranslator(AllocBufferAndCopy(b), b.size());
|
GFAppRegisterTranslator(AllocBufferAndCopy(b), b.size());
|
||||||
@ -94,23 +75,22 @@ auto GFActiveModule() -> int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFExecuteModule(GFModuleEvent* event) -> int {
|
EXECUTE_MODULE() {
|
||||||
MLogInfoS("version checking module executing, event id: %s", event->id);
|
FLOG_INFO("version checking module executing, event id: %s",
|
||||||
|
event["event_id"]);
|
||||||
|
|
||||||
auto* task = new VersionCheckTask();
|
auto* task = new VersionCheckTask();
|
||||||
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion,
|
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion,
|
||||||
QThread::currentThread(), [event](const SoftwareVersion&) {
|
QThread::currentThread(),
|
||||||
GFModuleTriggerModuleEventCallback(
|
[event](const SoftwareVersion&) { CB_SUCC(event); });
|
||||||
event, GFGetModuleID(), 1,
|
|
||||||
ConvertMapToParams({{"ret", "0"}}));
|
|
||||||
});
|
|
||||||
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion, task,
|
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion, task,
|
||||||
&QObject::deleteLater);
|
&QObject::deleteLater);
|
||||||
task->Run();
|
task->Run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
END_EXECUTE_MODULE()
|
||||||
|
|
||||||
auto GFDeactiveModule() -> int { return 0; }
|
auto GFDeactivateModule() -> int { return 0; }
|
||||||
|
|
||||||
auto GFUnregisterModule() -> int { return 0; }
|
auto GFUnregisterModule() -> int { return 0; }
|
@ -28,29 +28,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <GFSDKModule.h>
|
#include "GFModuleDeclare.h"
|
||||||
|
|
||||||
#include "GFModuleExport.h"
|
GF_MODULE_API_DECLARE
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
|
||||||
|
|
||||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user