fix: adapt to new sdk apis

This commit is contained in:
saturneric 2024-12-02 23:53:18 +01:00
parent 7df6721244
commit ec7541da65
4 changed files with 93 additions and 53 deletions

View File

@ -401,7 +401,7 @@ inline auto CharArrayToQStringList(char** pl_components,
return list;
}
inline auto QListToCharArray(const QStringList& list) -> char** {
inline auto QStringListToCharArray(const QStringList& list) -> char** {
char** char_array =
static_cast<char**>(GFAllocateMemory(list.size() * sizeof(char*)));
@ -416,6 +416,34 @@ inline auto QListToCharArray(const QStringList& list) -> char** {
return char_array;
}
template <typename T>
inline auto ArrayToQList(T** pl_components, int size) -> QList<T> {
if (pl_components == nullptr || size <= 0) {
return QList<T>();
}
QList<T> list;
for (int i = 0; i < size; ++i) {
list.append(*pl_components[i]);
GFFreeMemory(pl_components[i]);
}
GFFreeMemory(pl_components);
return list;
}
template <typename T>
inline auto QListToArray(const QList<T>& list) -> T** {
T** array = static_cast<T**>(GFAllocateMemory(list.size() * sizeof(T*)));
int index = 0;
for (const T& item : list) {
auto mem = static_cast<T*>(GFAllocateMemory(sizeof(T)));
array[index] = new (mem) T(item);
index++;
}
return array;
}
inline auto ConvertQVariantToVoidPtr(const QVariant& variant) -> void* {
void* mem = GFAllocateMemory(sizeof(QVariant));
auto* variant_ptr = new (mem) QVariant(variant);

View File

@ -51,8 +51,8 @@ auto EncryptPlainText(int channel, const QStringList& keys,
try {
GFGpgEncryptionResult* s = nullptr;
auto ret = GFGpgEncryptData(channel, QListToCharArray(keys), keys.size(),
QDUP(body_data), 1, &s);
auto ret = GFGpgEncryptData(channel, QStringListToCharArray(keys),
keys.size(), QDUP(body_data), 1, &s);
auto encrypted_data = UDUP(s->encrypted_data);
auto gpg_error_string = UDUP(s->error_string);
@ -268,8 +268,8 @@ auto EncryptEMLData(int channel, const QStringList& keys,
plain_raw_data.replace("\n", "\r\n");
GFGpgEncryptionResult* s = nullptr;
auto ret = GFGpgEncryptData(channel, QListToCharArray(keys), keys.size(),
QDUP(plain_raw_data), 1, &s);
auto ret = GFGpgEncryptData(channel, QStringListToCharArray(keys),
keys.size(), QDUP(plain_raw_data), 1, &s);
auto encrypted_data = UDUP(s->encrypted_data);
capsule_id = UDUP(s->capsule_id);
@ -573,7 +573,7 @@ auto SignPlainText(int channel, const QString& key,
FLOG_DEBUG("Signature Channel: %1, Sign Key: %2", channel, key);
GFGpgSignResult* s;
auto ret = GFGpgSignData(channel, QListToCharArray({key}), 1,
auto ret = GFGpgSignData(channel, QStringListToCharArray({key}), 1,
QDUP(container_raw_data), 1, 1, &s);
auto signature = UDUP(s->signature);
@ -792,7 +792,7 @@ auto SignEMLData(int channel, const QString& key,
FLOG_DEBUG("Signature Channel: %1, Sign Key: %2", channel, key);
GFGpgSignResult* s;
auto ret = GFGpgSignData(channel, QListToCharArray({key}), 1,
auto ret = GFGpgSignData(channel, QStringListToCharArray({key}), 1,
QDUP(container_raw_data), 1, 1, &s);
capsule_id = UDUP(s->capsule_id);

View File

@ -46,8 +46,8 @@
#include "GFModuleDefine.h"
#include "GpgInfo.h"
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.gnupg_info_gathering",
"GatherGnupgInfo", "1.1.0",
GF_MODULE_API_DEFINE_V2("com.bktus.gpgfrontend.module.gnupg_info_gathering",
"GatherGnupgInfo", "1.2.0",
"Try gathering gnupg information.", "Saturneric")
DEFINE_TRANSLATIONS_STRUCTURE(ModuleGnuPGInfoGathering);
@ -61,7 +61,10 @@ extern void GetGpgDirectoryInfos(void *, int, const char *, const char *);
extern void GetGpgOptionInfos(void *, int, const char *, const char *);
extern auto StartGatheringGnuPGInfo() -> int;
extern auto StartGatheringAllGnuPGInfo() -> int;
extern auto StartStartGatheringGnuPGComponentsInfo(
const QString &gpgme_version, const QString &gpgconf_path) -> int;
extern auto GnupgTabFactory(void *id) -> void *;
@ -86,20 +89,30 @@ auto GFRegisterModule() -> int {
}
auto GFActiveModule() -> int {
LISTEN("REQUEST_GATHERING_GNUPG_INFO");
LISTEN("APPLICATION_LOADED");
LISTEN("REQUEST_GATHERING_ALL_GNUPG_INFO");
return 0;
}
EXECUTE_MODULE() {
FLOG_DEBUG("gnupg info gathering module executing, event id: %1",
event["event_id"]);
REGISTER_EVENT_HANDLER(APPLICATION_LOADED, [](const MEvent &event) -> int {
const auto gpgme_version = UDUP(GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.version"), DUP("0.0.0")));
MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version));
StartGatheringGnuPGInfo();
const auto gpgconf_path = UDUP(GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.ctx.gpgconf_path"), DUP("")));
MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path));
StartStartGatheringGnuPGComponentsInfo(gpgme_version, gpgconf_path);
CB_SUCC(event);
});
REGISTER_EVENT_HANDLER(REQUEST_GATHERING_ALL_GNUPG_INFO,
[](const MEvent &event) -> int {
StartGatheringAllGnuPGInfo();
CB_SUCC(event);
}
END_EXECUTE_MODULE()
});
auto GFDeactivateModule() -> int { return 0; }
@ -109,36 +122,36 @@ auto GFUnregisterModule() -> int {
return 0;
}
auto StartGatheringGnuPGInfo() -> int {
MLogDebug("start to load extra info at module gnupginfogathering...");
const auto *const gpgme_version = GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.version"), DUP("0.0.0"));
MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version));
const auto *const gpgconf_path = GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.ctx.gpgconf_path"), DUP(""));
MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path));
auto StartStartGatheringGnuPGComponentsInfo(
const QString &gpgme_version, const QString &gpgconf_path) -> int {
auto context = Context{gpgme_version, gpgconf_path};
// get all components
const char *argv[] = {DUP("--list-components")};
GFExecuteCommandSync(gpgconf_path, 1, argv, GetGpgComponentInfos, &context);
MLogDebug("load gnupg component info done.");
GFExecuteCommandSync(QDUP(gpgconf_path), 1,
QStringListToCharArray({"--list-components"}),
GetGpgComponentInfos, &context);
MLogDebug("loading gnupg component info done.");
return 0;
}
auto StartGatheringAllGnuPGInfo() -> int {
const auto gpgme_version = UDUP(GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.version"), DUP("0.0.0")));
MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version));
const auto gpgconf_path = UDUP(GFModuleRetrieveRTValueOrDefault(
DUP("core"), DUP("gpgme.ctx.gpgconf_path"), DUP("")));
MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path));
// get components infos
StartStartGatheringGnuPGComponentsInfo(gpgme_version, gpgconf_path);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
QList<GFCommandExecuteContext> exec_contexts;
#else
QVector<GFCommandExecuteContext> exec_contexts;
#endif
const char **argv_0 =
static_cast<const char **>(GFAllocateMemory(sizeof(const char *)));
argv_0[0] = DUP("--list-dirs");
exec_contexts.push_back(
{gpgconf_path, 1, argv_0, GetGpgDirectoryInfos, nullptr});
auto exec_context = GFCommandExecuteContext{
QDUP(gpgconf_path), 1, QStringListToCharArray({"--list-dirs"}),
GetGpgDirectoryInfos, nullptr};
exec_contexts.push_back(exec_context);
char **components_c_array;
int ret = GFModuleListRTChildKeys(GFGetModuleID(), DUP("gnupg.components"),
@ -171,16 +184,15 @@ auto StartGatheringGnuPGInfo() -> int {
auto *context = new (GFAllocateMemory(sizeof(Context)))
Context{gpgme_version, gpgconf_path, component_info};
const char **argv_0 =
static_cast<const char **>(GFAllocateMemory(sizeof(const char *) * 2));
argv_0[0] = DUP("--list-options"),
argv_0[1] = DUP(component_info.name.toUtf8());
exec_contexts.push_back(
{gpgconf_path, 2, argv_0, GetGpgOptionInfos, context});
auto exec_context = GFCommandExecuteContext{
QDUP(gpgconf_path), 2,
QStringListToCharArray({"--list-options", component_info.name}),
GetGpgOptionInfos, context};
exec_contexts.push_back(exec_context);
}
GFExecuteCommandBatchSync(static_cast<int32_t>(exec_contexts.size()),
exec_contexts.constData());
GFExecuteCommandBatchSync(QListToArray(exec_contexts),
static_cast<int>(exec_contexts.size()));
GFModuleUpsertRTValueBool(GFGetModuleID(), DUP("gnupg.gathering_done"), 1);
return 0;

View File

@ -39,7 +39,7 @@
#include "GnuPGInfoGatheringModule.h"
#include "ui_GnuPGInfo.h"
extern auto StartGatheringGnuPGInfo() -> int;
extern auto StartGatheringAllGnuPGInfo() -> int;
GnupgTab::GnupgTab(QWidget* parent)
: QWidget(parent), ui_(SecureCreateSharedObject<Ui_GnuPGInfo>()) {
@ -326,7 +326,7 @@ void GnupgTab::gather_gnupg_info() {
ui_->loadProgressBar->show();
ui_->tabWidget->setDisabled(true);
if (StartGatheringGnuPGInfo() >= 0) {
if (StartGatheringAllGnuPGInfo() >= 0) {
GFModuleUpsertRTValueBool(DUP("ui"), DUP("env.state.gnupg_info_gathering"),
1);
process_software_info();