Skip to content

Commit 795a81b

Browse files
committed
fix: according to issues and test, apply some fixes
2 parents 8e99ff1 + 52be475 commit 795a81b

27 files changed

+4806
-735
lines changed

.github/workflows/codeql-analysis.yml

-9
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ jobs:
8383
sudo make install
8484
cd ${{github.workspace}}
8585
86-
- name: Build mimalloc (Linux)
87-
run: |
88-
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
89-
cd ${{github.workspace}}/third_party/mimalloc
90-
mkdir build && cd build
91-
cmake -G Ninja -DMI_SECURE=ON ..
92-
ninja
93-
sudo ninja install
94-
9586
- name: Build googletest (Linux)
9687
run: |
9788
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest

.github/workflows/release-qt5.yml

-20
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,6 @@ jobs:
138138
cd ${{github.workspace}}
139139
if: matrix.os == 'ubuntu-20.04'
140140

141-
- name: Build mimalloc (Linux)
142-
run: |
143-
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
144-
cd ${{github.workspace}}/third_party/mimalloc
145-
mkdir build && cd build
146-
cmake -G Ninja -DMI_SECURE=ON ..
147-
ninja
148-
sudo ninja install
149-
if: matrix.os == 'ubuntu-20.04'
150-
151-
- name: Build mimalloc (Windows)
152-
shell: msys2 {0}
153-
run: |
154-
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
155-
cd ${{github.workspace}}/third_party/mimalloc
156-
mkdir build && cd build
157-
cmake -G Ninja -DMI_SECURE=ON -DCMAKE_INSTALL_PREFIX=$MSYSTEM_PREFIX .. && ninja
158-
ninja install
159-
if: matrix.os == 'windows-2019'
160-
161141
- name: Build googletest (Linux)
162142
run: |
163143
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest

.github/workflows/release.yml

-20
Original file line numberDiff line numberDiff line change
@@ -164,26 +164,6 @@ jobs:
164164
make install
165165
if: matrix.os == 'windows-2019'
166166

167-
- name: Build mimalloc (Linux)
168-
run: |
169-
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
170-
cd ${{github.workspace}}/third_party/mimalloc
171-
mkdir build && cd build
172-
cmake -G Ninja -DMI_SECURE=ON ..
173-
ninja
174-
sudo ninja install
175-
if: matrix.os == 'ubuntu-20.04'
176-
177-
- name: Build mimalloc (Windows)
178-
shell: msys2 {0}
179-
run: |
180-
git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
181-
cd ${{github.workspace}}/third_party/mimalloc
182-
mkdir build && cd build
183-
cmake -G Ninja -DMI_SECURE=ON -DCMAKE_INSTALL_PREFIX=$MSYSTEM_PREFIX .. && ninja
184-
ninja install
185-
if: matrix.os == 'windows-2019'
186-
187167
- name: Build googletest (Linux)
188168
run: |
189169
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest

gpgfrontend.qrc

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<file alias="stairs.png">resource/lfs/icons/stairs.png</file>
9999
<file alias="detail.png">resource/lfs/icons/detail.png</file>
100100
<file alias="filter.png">resource/lfs/icons/filter.png</file>
101+
<file alias="setting.png">resource/lfs/icons/setting.png</file>
101102
</qresource>
102103
<qresource prefix="/test/key">
103104
<file alias="pv1.key">resource/lfs/test/data/pv1.key</file>

resource/lfs/icons/setting.png

5.16 KB
Loading

resource/lfs/locale/ts/GpgFrontend.de_DE.ts

+2,366-302
Large diffs are not rendered by default.

resource/lfs/locale/ts/GpgFrontend.zh_CN.ts

+2,365-301
Large diffs are not rendered by default.

src/CMakeLists.txt

-13
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ endif()
5555

5656
find_package(OpenSSL REQUIRED)
5757

58-
# mimalloc
59-
if(NOT APPLE)
60-
find_package(mimalloc REQUIRED)
61-
endif()
62-
6358
# Set Build Information
6459
configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontend.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontend.h @ONLY)
6560
configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h @ONLY)
@@ -283,14 +278,6 @@ if(BUILD_APPLICATION AND MINGW)
283278
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libgpgfrontend_*.dll")
284279
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
285280

286-
unset(_libDllPath)
287-
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libmimalloc*.dll")
288-
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
289-
290-
unset(_libDllPath)
291-
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/mimalloc*.dll")
292-
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
293-
294281
unset(_libDllPath)
295282
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libarchive*.dll")
296283
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})

src/core/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}")
5050
# compile definitions
5151
target_compile_definitions(gpgfrontend_core PRIVATE GF_CORE_PRIVATE)
5252

53-
# mimalloc (except apple macos)
54-
if(NOT APPLE)
55-
target_link_libraries(gpgfrontend_core PUBLIC mimalloc)
56-
endif()
57-
5853
# qt-aes
5954
target_sources(gpgfrontend_core PRIVATE
6055
${CMAKE_SOURCE_DIR}/third_party/qt-aes/qaesencryption.cpp)

src/core/GpgCoreInit.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,6 @@ void InitGpgFrontendCore(CoreInitArgs args) {
304304
auto custom_key_database_path =
305305
settings.value("gnupg/custom_key_database_path", QString{}).toString();
306306

307-
auto custom_gnupg_install_path =
308-
settings.value("gnupg/custom_gnupg_install_path", QString{}).toString();
309-
310307
auto use_pinentry_as_password_input_dialog =
311308
settings
312309
.value("gnupg/use_pinentry_as_password_input_dialog",
@@ -327,10 +324,14 @@ void InitGpgFrontendCore(CoreInitArgs args) {
327324
!custom_key_database_path.isEmpty()) {
328325
if (VerifyKeyDatabasePath(QFileInfo(custom_key_database_path))) {
329326
key_database_fs_path =
330-
QFileInfo(custom_gnupg_install_path).absoluteFilePath();
327+
QFileInfo(custom_key_database_path).absoluteFilePath();
328+
LOG_D() << "use custom gpg key database: " << key_database_fs_path
329+
<< "raw:" << custom_key_database_path;
330+
331331
} else {
332332
LOG_W() << "custom gpg key database path is not suitable: "
333-
<< key_database_fs_path;
333+
<< key_database_fs_path
334+
<< "raw:" << custom_key_database_path;
334335
}
335336
} else {
336337

@@ -354,8 +355,7 @@ void InitGpgFrontendCore(CoreInitArgs args) {
354355

355356
// set custom gnupg path
356357
if (!gnupg_install_fs_path.isEmpty()) {
357-
args.custom_gpgconf = true;
358-
args.custom_gpgconf_path = gnupg_install_fs_path;
358+
args.gpgconf_path = gnupg_install_fs_path;
359359
}
360360

361361
args.offline_mode = forbid_all_gnupg_connection;

src/core/function/SecureMemoryAllocator.cpp

+5-25
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,22 @@
2828

2929
#include "SecureMemoryAllocator.h"
3030

31-
namespace GpgFrontend {
31+
#include <cstdlib>
3232

33-
#if defined(__APPLE__) && defined(__MACH__)
33+
namespace GpgFrontend {
3434

3535
auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* {
36-
auto* addr = malloc(size);
36+
auto* addr = std::malloc(size);
3737
if (addr == nullptr) FLOG_F("malloc failed!");
3838
return addr;
3939
}
4040

4141
auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
42-
auto* addr = realloc(ptr, size);
42+
auto* addr = std::realloc(ptr, size);
4343
if (addr == nullptr) FLOG_F("realloc failed!");
4444
return addr;
4545
}
4646

47-
void SecureMemoryAllocator::Deallocate(void* p) { free(p); }
48-
49-
#else
50-
51-
#include <mimalloc.h>
52-
53-
auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* {
54-
auto* addr = mi_malloc(size);
55-
if (addr == nullptr) FLOG_F("malloc failed!");
56-
return addr;
57-
}
58-
59-
auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
60-
auto* addr = mi_realloc(ptr, size);
61-
if (addr == nullptr) FLOG_F("realloc memory failed!");
62-
return addr;
63-
}
64-
65-
void SecureMemoryAllocator::Deallocate(void* p) { mi_free(p); }
66-
67-
#endif
47+
void SecureMemoryAllocator::Deallocate(void* p) { std::free(p); }
6848

6949
} // namespace GpgFrontend

src/core/function/gpg/GpgContext.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,10 @@ class GpgContext::Impl {
236236
const GpgContextInitArgs &args) -> bool {
237237
assert(ctx != nullptr);
238238

239-
if (args.custom_gpgconf && !args.custom_gpgconf_path.isEmpty()) {
240-
LOG_D() << "set custom gpgconf path: " << args.custom_gpgconf_path;
241-
auto err =
242-
gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_GPGCONF,
243-
args.custom_gpgconf_path.toUtf8(), nullptr);
239+
if (!args.gpgconf_path.isEmpty()) {
240+
LOG_D() << "set custom gpgconf path: " << args.gpgconf_path;
241+
auto err = gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_GPGCONF,
242+
args.gpgconf_path.toUtf8(), nullptr);
244243

245244
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
246245
LOG_W() << "set gpg context engine info error: "
@@ -284,6 +283,7 @@ class GpgContext::Impl {
284283

285284
// set custom gpg key db path
286285
if (!args_.db_path.isEmpty()) {
286+
LOG_D() << "set context database path to" << args_.db_path;
287287
Module::UpsertRTValue("core", "gpgme.ctx.database_path", args_.db_path);
288288
}
289289

src/core/function/gpg/GpgContext.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ struct GpgContextInitArgs {
4646
bool offline_mode = false; ///<
4747
bool auto_import_missing_key = false; ///<
4848

49-
bool custom_gpgconf = false; ///<
50-
QString custom_gpgconf_path; ///<
49+
QString gpgconf_path; ///<
5150

5251
bool use_pinentry = false; ///<
5352
};

src/core/thread/Task.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ class Task::Impl {
164164
}
165165
};
166166

167-
Task::Task(QString name) : p_(new Impl(this, name)) {}
167+
Task::Task(QString name)
168+
: p_(SecureCreateUniqueObject<Task::Impl>(this, name)) {}
168169

169170
Task::Task(TaskRunnable runnable, QString name, DataObjectPtr data_object)
170171
: p_(SecureCreateUniqueObject<Impl>(this, runnable, name, data_object)) {}

src/ui/GpgFrontendUIInit.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ QList<QByteArray> loaded_qm_datum;
4848
extern void InitUITranslations();
4949

5050
void WaitEnvCheckingProcess() {
51-
FLOG_D("need to waiting for env checking process");
51+
FLOG_D("need to wait for env checking process");
5252

5353
// create and show loading window before starting the main window
5454
auto* waiting_dialog = new QProgressDialog();
@@ -86,8 +86,7 @@ void WaitEnvCheckingProcess() {
8686

8787
auto env_state =
8888
Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.all", 0);
89-
FLOG_D("ui is ready to waiting for env initialized, env_state: %d",
90-
env_state);
89+
FLOG_D("ui is ready to wait for env initialized, env_state: %d", env_state);
9190

9291
// check twice to avoid some unlucky sitations
9392
if (env_state == 1) {
@@ -200,7 +199,7 @@ void InitGpgFrontendUI(QApplication* /*app*/) {
200199
void WaitingAllInitializationFinished() {
201200
if (Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.all", 0) ==
202201
0) {
203-
LOG_D() << "ui init is done, but cor doesn't, going to waiting for core...";
202+
LOG_D() << "ui init is done, but core doesn't, going to wait for core...";
204203
WaitEnvCheckingProcess();
205204
}
206205
LOG_D() << "application fully initialized...";

src/ui/UserInterfaceUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ void CommonUtils::RemoveKeyFromFavourite(const GpgKey &key) {
560560
*
561561
*/
562562
void CommonUtils::ImportKeyFromKeyServer(const KeyIdArgsList &key_ids) {
563-
KeyServerSO key_server(SettingsObject("general_settings_state"));
563+
KeyServerSO key_server(SettingsObject("key_server"));
564564
auto target_keyserver = key_server.GetTargetServer();
565565

566566
auto *task = new KeyServerImportTask(target_keyserver, key_ids);

src/ui/dialog/controller/GnuPGControllerDialog.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent)
149149
this->slot_set_restart_needed(kDeepRestartCode);
150150
});
151151

152+
connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this,
153+
[=](int) {
154+
// announce the restart
155+
this->slot_set_restart_needed(kDeepRestartCode);
156+
});
157+
158+
connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged,
159+
this, [=](int) {
160+
// announce the restart
161+
this->slot_set_restart_needed(kDeepRestartCode);
162+
});
163+
152164
#if defined(__APPLE__) && defined(__MACH__)
153165
// macOS style settings
154166
ui_->buttonBox->setDisabled(true);

src/ui/dialog/import_export/KeyServerImportDialog.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,15 @@ auto KeyServerImportDialog::create_combo_box() -> QComboBox* {
125125
combo_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
126126

127127
try {
128-
KeyServerSO key_server(SettingsObject("general_settings_state"));
128+
KeyServerSO key_server(SettingsObject("key_server"));
129129
const auto& key_server_list = key_server.server_list;
130130
for (const auto& key_server : key_server_list) {
131131
combo_box->addItem(key_server);
132132
}
133-
combo_box->setCurrentText(key_server.GetTargetServer());
133+
auto target_key_server = key_server.GetTargetServer();
134+
LOG_D() << "set combo box to key server: " << target_key_server;
135+
136+
combo_box->setCurrentText(target_key_server);
134137
} catch (...) {
135138
FLOG_W("setting operation error server_list default_server");
136139
}
@@ -207,7 +210,7 @@ void KeyServerImportDialog::slot_search() {
207210
}
208211

209212
void KeyServerImportDialog::slot_search_finished(
210-
QNetworkReply::NetworkError error, QByteArray buffer) {
213+
QNetworkReply::NetworkError error, QString err_string, QByteArray buffer) {
211214
keys_table_->clearContents();
212215
keys_table_->setRowCount(0);
213216

@@ -226,6 +229,7 @@ void KeyServerImportDialog::slot_search_finished(
226229
break;
227230
default:
228231
set_message(tr("Connection Error"), true);
232+
QMessageBox::critical(this, tr("Connection Error"), err_string);
229233
}
230234
return;
231235
}
@@ -380,7 +384,7 @@ void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) {
380384
target_keyserver = key_server_combo_box_->currentText();
381385
}
382386
if (target_keyserver.isEmpty()) {
383-
KeyServerSO key_server(SettingsObject("general_settings_state"));
387+
KeyServerSO key_server(SettingsObject("key_server"));
384388
target_keyserver = key_server.GetTargetServer();
385389
}
386390
std::vector<QString> key_ids;

src/ui/dialog/import_export/KeyServerImportDialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class KeyServerImportDialog : public GeneralDialog {
9090
*
9191
*/
9292
void slot_search_finished(QNetworkReply::NetworkError reply,
93-
QByteArray buffer);
93+
QString err_string, QByteArray buffer);
9494

9595
/**
9696
* @brief

src/ui/dialog/import_export/KeyUploadDialog.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ void KeyUploadDialog::SlotUpload() {
9494

9595
void KeyUploadDialog::slot_upload_key_to_server(
9696
const GpgFrontend::GFBuffer& keys_data) {
97-
KeyServerSO key_server(SettingsObject("general_settings_state"));
98-
auto target_keyserver = key_server.GetTargetServer();
97+
KeyServerSO key_server(SettingsObject("key_server"));
98+
auto target_key_server = key_server.GetTargetServer();
9999

100-
QUrl req_url(target_keyserver + "/pks/add");
101-
auto* qnam = new QNetworkAccessManager(this);
100+
LOG_D() << "upload public key using key server" << target_key_server;
101+
QUrl req_url(target_key_server + "/pks/add");
102+
auto* q_nam = new QNetworkAccessManager(this);
102103

103104
// Building Post Data
104105
QByteArray post_data;
@@ -124,7 +125,7 @@ void KeyUploadDialog::slot_upload_key_to_server(
124125
post_data.append("keytext").append("=").append(data);
125126

126127
// Send Post Data
127-
QNetworkReply* reply = qnam->post(request, post_data);
128+
QNetworkReply* reply = q_nam->post(request, post_data);
128129
connect(reply, &QNetworkReply::finished, this,
129130
&KeyUploadDialog::slot_upload_finished);
130131

0 commit comments

Comments
 (0)