From d1d6859e2a50a78f57388ebf0a06f0636d4d0910 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 12 Jul 2024 20:38:16 +0200 Subject: feat: add some ui apis to sdk --- src/sdk/private/CommonUtils.cpp | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/sdk/private/CommonUtils.cpp (limited to 'src/sdk/private/CommonUtils.cpp') diff --git a/src/sdk/private/CommonUtils.cpp b/src/sdk/private/CommonUtils.cpp new file mode 100644 index 00000000..7d72415e --- /dev/null +++ b/src/sdk/private/CommonUtils.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (C) 2021 Saturneric + * + * 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 . + * + * 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 starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "CommonUtils.h" + +#include + +auto GFStrDup(const QString& str) -> char* { + auto utf8_str = str.toUtf8(); + auto* c_str = static_cast( + GpgFrontend::SecureMalloc((utf8_str.size() + 1) * sizeof(char))); + + memcpy(c_str, utf8_str.constData(), utf8_str.size()); + c_str[utf8_str.size()] = '\0'; + return c_str; +} + +auto GFUnStrDup(char* str) -> QString { + auto qt_str = QString::fromUtf8(str); + GpgFrontend::SecureFree(static_cast(const_cast(str))); + return qt_str; +} + +auto GFUnStrDup(const char* str) -> QString { + return GFUnStrDup(const_cast(str)); +} + +auto CharArrayToQMap(char** char_array, int size) -> QMap { + QMap map; + for (int i = 0; i < size; i += 2) { + QString const key = GFUnStrDup(char_array[i]); + QString const value = QString::fromUtf8(char_array[i + 1]); + map.insert(key, value); + } + return map; +} + +auto QMapToCharArray(const QMap& map, int& size) -> char** { + size = map.size() * 2; + char** char_array = new char*[size]; + + int index = 0; + for (auto it = map.begin(); it != map.end(); ++it) { + QByteArray const key = it.key().toUtf8(); + QByteArray const value = it.value().toUtf8(); + + char_array[index] = new char[key.size() + 1]; + std::strcpy(char_array[index], key.constData()); + index++; + + char_array[index] = new char[value.size() + 1]; + std::strcpy(char_array[index], value.constData()); + index++; + } + + return char_array; +} \ No newline at end of file -- cgit v1.2.3 From 71ca9724b8cc8b6041641121776177b088935919 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 24 Jul 2024 16:00:36 +0200 Subject: feat: move out GnuPGTab --- src/sdk/private/CommonUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sdk/private/CommonUtils.cpp') diff --git a/src/sdk/private/CommonUtils.cpp b/src/sdk/private/CommonUtils.cpp index 7d72415e..16dc2db6 100644 --- a/src/sdk/private/CommonUtils.cpp +++ b/src/sdk/private/CommonUtils.cpp @@ -79,4 +79,4 @@ auto QMapToCharArray(const QMap& map, int& size) -> char** { } return char_array; -} \ No newline at end of file +} -- cgit v1.2.3 From 5be04d1602355278814bc86c69ec9f648978be8c Mon Sep 17 00:00:00 2001 From: saturneric Date: Sat, 27 Jul 2024 14:18:26 +0200 Subject: feat: improve sdk api for pinentry module --- src/sdk/private/CommonUtils.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/sdk/private/CommonUtils.cpp') diff --git a/src/sdk/private/CommonUtils.cpp b/src/sdk/private/CommonUtils.cpp index 16dc2db6..d6fec3db 100644 --- a/src/sdk/private/CommonUtils.cpp +++ b/src/sdk/private/CommonUtils.cpp @@ -30,6 +30,8 @@ #include +#include "GFSDKModule.h" + auto GFStrDup(const QString& str) -> char* { auto utf8_str = str.toUtf8(); auto* c_str = static_cast( @@ -80,3 +82,20 @@ auto QMapToCharArray(const QMap& map, int& size) -> char** { return char_array; } + +auto ConvertEventParamsToMap(GFModuleEventParam* params) + -> QMap { + QMap param_map; + GFModuleEventParam* current = params; + GFModuleEventParam* last; + + while (current != nullptr) { + param_map[current->name] = GFUnStrDup(current->value); + + last = current; + current = current->next; + GpgFrontend::SecureFree(last); + } + + return param_map; +} \ No newline at end of file -- cgit v1.2.3 From 3dccd8cff1c3b063110e00112b0878de887daca3 Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 29 Jul 2024 03:48:21 +0200 Subject: fix: solve qt5 problems --- src/sdk/private/CommonUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/sdk/private/CommonUtils.cpp') diff --git a/src/sdk/private/CommonUtils.cpp b/src/sdk/private/CommonUtils.cpp index d6fec3db..31092a3e 100644 --- a/src/sdk/private/CommonUtils.cpp +++ b/src/sdk/private/CommonUtils.cpp @@ -30,6 +30,8 @@ #include +#include + #include "GFSDKModule.h" auto GFStrDup(const QString& str) -> char* { -- cgit v1.2.3