aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-07-28 09:30:55 +0000
committersaturneric <[email protected]>2024-07-28 09:30:55 +0000
commitb6f464771937891f120fa8ec635a76f8cd073635 (patch)
tree06625bdc3e14f09a209410b12a23507d897e41a9
parentfeat: add pinentry module and paper key module (diff)
downloadModules-b6f464771937891f120fa8ec635a76f8cd073635.tar.gz
Modules-b6f464771937891f120fa8ec635a76f8cd073635.zip
feat: upgrade infrastructure to simplify code
-rw-r--r--include/GFModuleCommonUtils.hpp57
-rw-r--r--include/GFModuleDeclare.h47
-rw-r--r--include/GFModuleDefine.h49
-rw-r--r--src/m_gpg_info/GnuPGInfoGatheringModule.cpp44
-rw-r--r--src/m_gpg_info/GnuPGInfoGatheringModule.h27
-rw-r--r--src/m_paper_key/PaperKeyModule.cpp91
-rw-r--r--src/m_paper_key/PaperKeyModule.h27
-rw-r--r--src/m_pinentry/PinentryModule.cpp36
-rw-r--r--src/m_pinentry/PinentryModule.h27
-rw-r--r--src/m_ver_check/VersionCheckingModule.cpp46
-rw-r--r--src/m_ver_check/VersionCheckingModule.h27
11 files changed, 211 insertions, 267 deletions
diff --git a/include/GFModuleCommonUtils.hpp b/include/GFModuleCommonUtils.hpp
index d65b356..3176784 100644
--- a/include/GFModuleCommonUtils.hpp
+++ b/include/GFModuleCommonUtils.hpp
@@ -43,17 +43,41 @@
#define UDUP(v) UnStrDup(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 MLogInfo(const QString& s) { GFModuleLogInfo(s.toUtf8()); }
inline void MLogWarn(const QString& s) { GFModuleLogWarn(s.toUtf8()); }
inline void MLogError(const QString& s) { GFModuleLogError(s.toUtf8()); }
-#define MLogDebugS(format, ...) \
- MLogDebug(QString::asprintf(format, __VA_ARGS__))
-#define MLogInfoS(format, ...) MLogInfo(QString::asprintf(format, __VA_ARGS__))
-#define MLogWarnS(format, ...) MLogWarn(QString::asprintf(format, __VA_ARGS__))
-#define MLogErrorS(format, ...) \
- MLogError(QString::asprintf(format, __VA_ARGS__))
+#define LOG_DEBUG(format) MLogDebug(FormatString(QString(format)))
+#define LOG_INFO(format) MLogDebug(FormatString(QString(format)))
+#define LOG_WARN(format) MLogDebug(FormatString(QString(format)))
+#define LOG_ERROR(format) MLogDebug(FormatString(QString(format)))
+
+#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()); }
@@ -179,6 +203,12 @@ inline auto ConvertMapToEvent(QMap<QString, QString> event_map)
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* {
auto* p = static_cast<char*>(GFAllocateMemory(sizeof(char) * b.size()));
memcpy(p, b.constData(), b.size());
@@ -261,3 +291,18 @@ inline auto CharArrayToQStringList(char** pl_components,
GFFreeMemory(pl_components);
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...);
+} \ No newline at end of file
diff --git a/include/GFModuleDeclare.h b/include/GFModuleDeclare.h
new file mode 100644
index 0000000..ae30c4f
--- /dev/null
+++ b/include/GFModuleDeclare.h
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * 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 <[email protected]> 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; \
+ };
diff --git a/include/GFModuleDefine.h b/include/GFModuleDefine.h
new file mode 100644
index 0000000..594bbc5
--- /dev/null
+++ b/include/GFModuleDefine.h
@@ -0,0 +1,49 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * 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 <[email protected]> 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)}}); \
+ }
diff --git a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp
index 142a7d1..9339882 100644
--- a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp
+++ b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp
@@ -43,11 +43,12 @@
#include <optional>
#include "GFModuleCommonUtils.hpp"
+#include "GFModuleDefine.h"
#include "GpgInfo.h"
-class GTrC {
- Q_DECLARE_TR_FUNCTIONS(GTrC)
-};
+GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.gnupg_info_gathering",
+ "GatherGnupgInfo", "1.0.0",
+ "Try gathering gnupg informations.", "Saturneric")
extern auto CalculateBinaryChacksum(const QString &path)
-> std::optional<QString>;
@@ -68,25 +69,6 @@ using Context = struct {
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 {
MLogDebug("gnupg info gathering module registering");
@@ -98,25 +80,21 @@ auto GFRegisterModule() -> int {
}
auto GFActiveModule() -> int {
- MLogDebug("gnupg info gathering module activating");
- GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_GATHERING_GNUPG_INFO"));
+ LISTEN("REQUEST_GATHERING_GNUPG_INFO");
return 0;
}
-auto GFExecuteModule(GFModuleEvent *event) -> int {
- MLogDebug(QString("gnupg info gathering module executing, event id: %1")
- .arg(event->id));
+EXECUTE_MODULE() {
+ FLOG_DEBUG("gnupg info gathering module executing, event id: %1",
+ event["event_id"]);
StartGatheringGnuPGInfo();
- GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1,
- ConvertMapToParams({{"ret", "0"}}));
-
- MLogDebug("gnupg external info gathering done");
- return 0;
+ CB_SUCC(event);
}
+END_EXECUTE_MODULE()
-auto GFDeactiveModule() -> int { return 0; }
+auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int {
MLogDebug("gnupg info gathering module unregistering");
diff --git a/src/m_gpg_info/GnuPGInfoGatheringModule.h b/src/m_gpg_info/GnuPGInfoGatheringModule.h
index b8b73d0..3298ec5 100644
--- a/src/m_gpg_info/GnuPGInfoGatheringModule.h
+++ b/src/m_gpg_info/GnuPGInfoGatheringModule.h
@@ -28,29 +28,6 @@
#pragma once
-#include <GFSDKModule.h>
+#include "GFModuleDeclare.h"
-#include "GFModuleExport.h"
-
-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;
-}; \ No newline at end of file
+GF_MODULE_API_DECLARE \ No newline at end of file
diff --git a/src/m_paper_key/PaperKeyModule.cpp b/src/m_paper_key/PaperKeyModule.cpp
index c6eedb7..c118bd9 100644
--- a/src/m_paper_key/PaperKeyModule.cpp
+++ b/src/m_paper_key/PaperKeyModule.cpp
@@ -30,56 +30,30 @@
#include <QtCore>
-#include "GFModuleCommonUtils.hpp"
-#include "GFSDKBuildInfo.h"
+#include "GFModuleDefine.h"
#include "extract.h"
-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.paper_key");
-}
-
-auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
-
-auto GFGetModuleMetaData() -> GFModuleMetaData * {
- return QMapToGFModuleMetaDataList(
- {{"Name", "PaperKey"},
- {"Description", "Integrated PaperKey Functions."},
- {"Author", "Saturneric"}});
-}
+GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.paper_key", "PaperKey",
+ "1.0.0", "Integrated PaperKey Functions.", "Saturneric")
auto GFRegisterModule() -> int {
- MLogDebug("paper key module registering");
+ LOG_DEBUG("paper key module registering");
return 0;
}
auto GFActiveModule() -> int {
- MLogDebug("paper key module activating");
- GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_KEY_2_PAPER_KEY"));
- GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_PAPER_KEY_2_KEY"));
+ LISTEN("REQUEST_TRANS_KEY_2_PAPER_KEY");
+ LISTEN("REQUEST_TRANS_PAPER_KEY_2_KEY");
return 0;
}
-auto GFExecuteModule(GFModuleEvent *p_event) -> int {
- MLogDebug(
- QString("paper key module executing, event id: %1").arg(p_event->id));
-
- auto event = ConvertEventToMap(p_event);
+EXECUTE_MODULE() {
+ FLOG_DEBUG("paper key module executing, event id: %1", event["event_id"]);
if (event["event_id"] == "REQUEST_TRANS_KEY_2_PAPER_KEY") {
if (event["secret_key"].isEmpty() || event["output_path"].isEmpty()) {
- GFModuleTriggerModuleEventCallback(
- ConvertMapToEvent(event), GFGetModuleID(), 1,
- ConvertMapToParams(
- {{"ret", "-1"},
- {"reason", "secret key or output path is empty"}}));
- return -1;
+ CB_ERR(event, -1, "secret key or output path is empty");
}
QByteArray secret_key_data =
@@ -87,9 +61,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
QTemporaryFile secret_key_t_file;
if (!secret_key_t_file.open()) {
- qWarning() << "Unable to open temporary file";
- MLogWarn("unable to open temporary file");
- return -1;
+ CB_ERR(event, -1, "unable to open temporary file");
}
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");
if (file == nullptr) {
- qDebug() << "Unable to convert QTemporaryFile to FILE*";
- return -1;
+ CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
}
extract(file, event["output_path"].toUtf8(), AUTO);
@@ -107,12 +78,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
fclose(file);
} else if (event["event_id"] == "REQUEST_TRANS_PAPER_KEY_2_KEY") {
if (event["public_key"].isEmpty() || event["paper_key_secrets"].isEmpty()) {
- GFModuleTriggerModuleEventCallback(
- ConvertMapToEvent(event), GFGetModuleID(), 1,
- ConvertMapToParams(
- {{"ret", "-1"},
- {"reason", "public key or paper key secrets is empty"}}));
- return -1;
+ CB_ERR(event, -1, "public key or paper key secrets is empty");
}
QByteArray public_key_data =
@@ -120,11 +86,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
QTemporaryFile public_key_t_file;
if (!public_key_t_file.open()) {
- GFModuleTriggerModuleEventCallback(
- ConvertMapToEvent(event), GFGetModuleID(), 1,
- ConvertMapToParams(
- {{"ret", "-1"}, {"reason", "unable to open temporary file"}}));
- return -1;
+ CB_ERR(event, -1, "unable to open temporary file");
}
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");
if (pubring == nullptr) {
- GFModuleTriggerModuleEventCallback(
- ConvertMapToEvent(event), GFGetModuleID(), 1,
- ConvertMapToParams(
- {{"ret", "-1"},
- {"reason", "unable to convert QTemporaryFile to FILE*"}}));
- return -1;
+ CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
}
QByteArray secrets_data =
@@ -146,11 +103,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
QTemporaryFile secrets_data_file;
if (!secrets_data_file.open()) {
- GFModuleTriggerModuleEventCallback(
- ConvertMapToEvent(event), GFGetModuleID(), 1,
- ConvertMapToParams(
- {{"ret", "-1"}, {"reason", "unable to open temporary file"}}));
- return -1;
+ CB_ERR(event, -1, "unable to open temporary file");
}
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");
if (secrets == nullptr) {
- GFModuleTriggerModuleEventCallback(
- ConvertMapToEvent(event), GFGetModuleID(), 1,
- ConvertMapToParams(
- {{"ret", "-1"},
- {"reason", "unable to convert QTemporaryFile to FILE*"}}));
- return -1;
+ CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
}
restore(pubring, secrets, AUTO, )
}
- GFModuleTriggerModuleEventCallback(ConvertMapToEvent(event), GFGetModuleID(),
- 1, ConvertMapToParams({{"ret", "0"}}));
- return 0;
+ CB_SUCC(event);
}
+END_EXECUTE_MODULE()
-auto GFDeactiveModule() -> int { return 0; }
+auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int {
MLogDebug("paper key module unregistering");
diff --git a/src/m_paper_key/PaperKeyModule.h b/src/m_paper_key/PaperKeyModule.h
index 35ee4ac..88836da 100644
--- a/src/m_paper_key/PaperKeyModule.h
+++ b/src/m_paper_key/PaperKeyModule.h
@@ -28,29 +28,6 @@
#pragma once
-#include <GFSDKModule.h>
+#include "GFModuleDeclare.h"
-#include "GFModuleExport.h"
-
-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;
-};
+GF_MODULE_API_DECLARE
diff --git a/src/m_pinentry/PinentryModule.cpp b/src/m_pinentry/PinentryModule.cpp
index da022c4..5b45a67 100644
--- a/src/m_pinentry/PinentryModule.cpp
+++ b/src/m_pinentry/PinentryModule.cpp
@@ -33,27 +33,12 @@
#include <qthread.h>
#include "GFModuleCommonUtils.hpp"
-#include "GFSDKBuildInfo.h"
+#include "GFModuleDefine.h"
#include "GpgPassphraseContext.h"
#include "RaisePinentry.h"
-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.pinentry");
-}
-
-auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
-
-auto GFGetModuleMetaData() -> GFModuleMetaData * {
- return QMapToGFModuleMetaDataList({{"Name", "Pinentry"},
- {"Description", "A simple tiny pinentry."},
- {"Author", "Saturneric"}});
-}
+GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.pinentry", "Pinentry",
+ "1.0.0", "A simple tiny pinentry.", "Saturneric")
auto GFRegisterModule() -> int {
MLogDebug("pinentry module registering");
@@ -62,9 +47,7 @@ auto GFRegisterModule() -> int {
}
auto GFActiveModule() -> int {
- MLogDebug("pinentry module activating");
-
- GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_PIN_ENTRY"));
+ LISTEN("REQUEST_PIN_ENTRY");
return 0;
}
@@ -74,6 +57,13 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
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(
QApplication::instance()->thread(), [p_event, event]() -> int {
auto *p = new RaisePinentry(
@@ -86,7 +76,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
p, &RaisePinentry::SignalUserInputPassphraseCallback, p,
[event](const QSharedPointer<GpgPassphraseContext> &c) {
GFModuleTriggerModuleEventCallback(
- ConvertMapToEvent(event), GFGetModuleID(), 1,
+ ConvertMapToEvent(event), GFGetModuleID(),
ConvertMapToParams({{"passphrase", c->GetPassphrase()}}));
});
@@ -97,7 +87,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
return 0;
}
-auto GFDeactiveModule() -> int { return 0; }
+auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int {
MLogDebug("pinentry module unregistering");
diff --git a/src/m_pinentry/PinentryModule.h b/src/m_pinentry/PinentryModule.h
index b8b73d0..3298ec5 100644
--- a/src/m_pinentry/PinentryModule.h
+++ b/src/m_pinentry/PinentryModule.h
@@ -28,29 +28,6 @@
#pragma once
-#include <GFSDKModule.h>
+#include "GFModuleDeclare.h"
-#include "GFModuleExport.h"
-
-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;
-}; \ No newline at end of file
+GF_MODULE_API_DECLARE \ No newline at end of file
diff --git a/src/m_ver_check/VersionCheckingModule.cpp b/src/m_ver_check/VersionCheckingModule.cpp
index b674e8f..6bb4f45 100644
--- a/src/m_ver_check/VersionCheckingModule.cpp
+++ b/src/m_ver_check/VersionCheckingModule.cpp
@@ -38,32 +38,13 @@
#include <QtNetwork>
#include "GFModuleCommonUtils.hpp"
+#include "GFModuleDefine.h"
#include "SoftwareVersion.h"
#include "UpdateTab.h"
#include "VersionCheckTask.h"
-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("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"}});
-}
+GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.VersionChecking", "Pinentry",
+ "1.0.0", "Try checking GpgFrontend version.", "Saturneric")
auto GFRegisterModule() -> int {
MLogInfo("version checking module registering");
@@ -73,15 +54,15 @@ auto GFRegisterModule() -> int {
auto GFActiveModule() -> int {
MLogInfo("version checking module activating");
- GFModuleListenEvent(GFGetModuleID(), DUP("APPLICATION_LOADED"));
- GFModuleListenEvent(GFGetModuleID(), DUP("CHECK_APPLICATION_VERSION"));
+ LISTEN("APPLICATION_LOADED");
+ LISTEN("CHECK_APPLICATION_VERSION");
// load translations
QFile f(
QString(":/i18n/ModuleVersionChecking.%1.qm").arg(GFAppActiveLocale()));
if (f.exists() && f.open(QIODevice::ReadOnly)) {
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());
auto b = f.readAll();
GFAppRegisterTranslator(AllocBufferAndCopy(b), b.size());
@@ -94,23 +75,22 @@ auto GFActiveModule() -> int {
return 0;
}
-auto GFExecuteModule(GFModuleEvent* event) -> int {
- MLogInfoS("version checking module executing, event id: %s", event->id);
+EXECUTE_MODULE() {
+ FLOG_INFO("version checking module executing, event id: %s",
+ event["event_id"]);
auto* task = new VersionCheckTask();
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion,
- QThread::currentThread(), [event](const SoftwareVersion&) {
- GFModuleTriggerModuleEventCallback(
- event, GFGetModuleID(), 1,
- ConvertMapToParams({{"ret", "0"}}));
- });
+ QThread::currentThread(),
+ [event](const SoftwareVersion&) { CB_SUCC(event); });
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion, task,
&QObject::deleteLater);
task->Run();
return 0;
}
+END_EXECUTE_MODULE()
-auto GFDeactiveModule() -> int { return 0; }
+auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int { return 0; } \ No newline at end of file
diff --git a/src/m_ver_check/VersionCheckingModule.h b/src/m_ver_check/VersionCheckingModule.h
index 35ee4ac..88836da 100644
--- a/src/m_ver_check/VersionCheckingModule.h
+++ b/src/m_ver_check/VersionCheckingModule.h
@@ -28,29 +28,6 @@
#pragma once
-#include <GFSDKModule.h>
+#include "GFModuleDeclare.h"
-#include "GFModuleExport.h"
-
-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;
-};
+GF_MODULE_API_DECLARE