fix some bug

This commit is contained in:
wjyLearn
2025-10-24 17:20:44 +08:00
parent 81ea36fdd8
commit 82268132e9
352 changed files with 33179 additions and 13515 deletions

View File

@@ -11,7 +11,8 @@
#include "slic3r/Utils/QDTUtil.hpp"
#include "NetworkAgent.hpp"
#include "slic3r/Utils/FileTransferUtils.hpp"
#include "slic3r/Utils/CertificateVerify.hpp"
using namespace QDT;
@@ -76,6 +77,7 @@ func_build_logout_cmd NetworkAgent::build_logout_cmd_ptr = nullptr
func_build_login_info NetworkAgent::build_login_info_ptr = nullptr;
func_ping_bind NetworkAgent::ping_bind_ptr = nullptr;
func_bind_detect NetworkAgent::bind_detect_ptr = nullptr;
func_report_consent NetworkAgent::report_consent_ptr = nullptr;
func_set_server_callback NetworkAgent::set_server_callback_ptr = nullptr;
func_bind NetworkAgent::bind_ptr = nullptr;
func_unbind NetworkAgent::unbind_ptr = nullptr;
@@ -115,6 +117,7 @@ func_get_model_mall_home_url NetworkAgent::get_model_mall_home_url_ptr =
func_get_model_mall_detail_url NetworkAgent::get_model_mall_detail_url_ptr = nullptr;
func_get_subtask NetworkAgent::get_subtask_ptr = nullptr;
func_get_my_profile NetworkAgent::get_my_profile_ptr = nullptr;
func_get_my_token NetworkAgent::get_my_token_ptr = nullptr;
func_track_enable NetworkAgent::track_enable_ptr = nullptr;
func_track_remove_files NetworkAgent::track_remove_files_ptr = nullptr;
func_track_event NetworkAgent::track_event_ptr = nullptr;
@@ -171,7 +174,7 @@ std::string NetworkAgent::get_libpath_in_current_directory(std::string library_n
}
int NetworkAgent::initialize_network_module(bool using_backup)
int NetworkAgent::initialize_network_module(bool using_backup, bool validate_cert)
{
//int ret = -1;
std::string library;
@@ -182,6 +185,13 @@ int NetworkAgent::initialize_network_module(bool using_backup)
if (using_backup) {
plugin_folder = plugin_folder/"backup";
}
std::optional<SignerSummary> self_cert_summary, module_cert_summary;
if (validate_cert)
self_cert_summary = SummarizeSelf();
else
BOOST_LOG_TRIVIAL(info) << "wouldn't validate networking dll cert";
if (!self_cert_summary)
BOOST_LOG_TRIVIAL(info) << "self cert not exist";
//first load the library
#if defined(_MSC_VER) || defined(_WIN32)
@@ -189,13 +199,18 @@ int NetworkAgent::initialize_network_module(bool using_backup)
wchar_t lib_wstr[128];
memset(lib_wstr, 0, sizeof(lib_wstr));
::MultiByteToWideChar(CP_UTF8, NULL, library.c_str(), strlen(library.c_str())+1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0]));
netwoking_module = LoadLibrary(lib_wstr);
/*if (!netwoking_module) {
library = std::string(QIDI_NETWORK_LIBRARY) + ".dll";
memset(lib_wstr, 0, sizeof(lib_wstr));
::MultiByteToWideChar(CP_UTF8, NULL, library.c_str(), strlen(library.c_str()) + 1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0]));
if (self_cert_summary) {
module_cert_summary = SummarizeModule(library);
if (module_cert_summary) {
if (IsSamePublisher(*self_cert_summary, *module_cert_summary))
netwoking_module = LoadLibrary(lib_wstr);
else
BOOST_LOG_TRIVIAL(info) << "module is from another publisher:" << module_cert_summary->as_print();
}
else
BOOST_LOG_TRIVIAL(info) << "module_cert is null";
} else
netwoking_module = LoadLibrary(lib_wstr);
}*/
if (!netwoking_module) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", try load library directly from current directory");
@@ -204,10 +219,21 @@ int NetworkAgent::initialize_network_module(bool using_backup)
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", can not get path in current directory for %1%") % QIDI_NETWORK_LIBRARY;
return -1;
}
//BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", current path %1%")%library_path;
memset(lib_wstr, 0, sizeof(lib_wstr));
::MultiByteToWideChar(CP_UTF8, NULL, library_path.c_str(), strlen(library_path.c_str())+1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0]));
netwoking_module = LoadLibrary(lib_wstr);
if (self_cert_summary) {
module_cert_summary = SummarizeModule(library_path);
if (module_cert_summary) {
if (IsSamePublisher(*self_cert_summary, *module_cert_summary))
netwoking_module = LoadLibrary(lib_wstr);
else
BOOST_LOG_TRIVIAL(info) << "module is from another publisher:" << module_cert_summary->as_print();
}
else
BOOST_LOG_TRIVIAL(info) << "module_cert is null";
}
else
netwoking_module = LoadLibrary(lib_wstr);
}
#else
#if defined(__WXMAC__)
@@ -216,17 +242,24 @@ int NetworkAgent::initialize_network_module(bool using_backup)
library = plugin_folder.string() + "/" + std::string("lib") + std::string(QIDI_NETWORK_LIBRARY) + ".so";
#endif
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", line %1%, loading network module, using_backup %2%\n")%__LINE__ %using_backup;
netwoking_module = dlopen( library.c_str(), RTLD_LAZY);
module_cert_summary = SummarizeModule(library);
if (self_cert_summary) {
module_cert_summary = SummarizeModule(library);
if (module_cert_summary) {
if (IsSamePublisher(*self_cert_summary, *module_cert_summary))
netwoking_module = dlopen(library.c_str(), RTLD_LAZY);
else
BOOST_LOG_TRIVIAL(info) << "module is from another publisher:" << module_cert_summary->as_print();
}
else
BOOST_LOG_TRIVIAL(info) << "module_cert is null";
}
else
netwoking_module = dlopen( library.c_str(), RTLD_LAZY);
if (!netwoking_module) {
/*#if defined(__WXMAC__)
library = std::string("lib") + QIDI_NETWORK_LIBRARY + ".dylib";
#else
library = std::string("lib") + QIDI_NETWORK_LIBRARY + ".so";
#endif*/
//netwoking_module = dlopen( library.c_str(), RTLD_LAZY);
char* dll_error = dlerror();
printf("error, dlerror is %s\n", dll_error);
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", error, dlerror is %1%")%dll_error;
std::string err = dll_error ? std::string(dll_error) : std::string("(null)");
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", error, dlerror is %1%") % err;
}
printf("after dlopen, network_module is %p\n", netwoking_module);
#endif
@@ -237,6 +270,9 @@ int NetworkAgent::initialize_network_module(bool using_backup)
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", line %1%, successfully loaded library, using_backup %2%, module %3%")%__LINE__ %using_backup %netwoking_module;
// load file transfer interface
InitFTModule(netwoking_module);
//load the functions
check_debug_consistent_ptr = reinterpret_cast<func_check_debug_consistent>(get_network_function("qidi_network_check_debug_consistent"));
get_version_ptr = reinterpret_cast<func_get_version>(get_network_function("qidi_network_get_version"));
@@ -286,6 +322,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
build_login_info_ptr = reinterpret_cast<func_build_login_info>(get_network_function("qidi_network_build_login_info"));
ping_bind_ptr = reinterpret_cast<func_ping_bind>(get_network_function("qidi_network_ping_bind"));
bind_detect_ptr = reinterpret_cast<func_bind_detect>(get_network_function("qidi_network_bind_detect"));
report_consent_ptr = reinterpret_cast<func_report_consent>(get_network_function("qidi_network_report_consent"));
set_server_callback_ptr = reinterpret_cast<func_set_server_callback>(get_network_function("qidi_network_set_server_callback"));
bind_ptr = reinterpret_cast<func_bind>(get_network_function("qidi_network_bind"));
unbind_ptr = reinterpret_cast<func_unbind>(get_network_function("qidi_network_unbind"));
@@ -325,6 +362,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
get_model_mall_home_url_ptr = reinterpret_cast<func_get_model_mall_home_url>(get_network_function("qidi_network_get_model_mall_home_url"));
get_model_mall_detail_url_ptr = reinterpret_cast<func_get_model_mall_detail_url>(get_network_function("qidi_network_get_model_mall_detail_url"));
get_my_profile_ptr = reinterpret_cast<func_get_my_profile>(get_network_function("qidi_network_get_my_profile"));
get_my_token_ptr = reinterpret_cast<func_get_my_profile>(get_network_function("qidi_network_get_my_token"));
track_enable_ptr = reinterpret_cast<func_track_enable>(get_network_function("qidi_network_track_enable"));
track_remove_files_ptr = reinterpret_cast<func_track_remove_files>(get_network_function("qidi_network_track_remove_files"));
track_event_ptr = reinterpret_cast<func_track_event>(get_network_function("qidi_network_track_event"));
@@ -345,6 +383,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
int NetworkAgent::unload_network_module()
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", network module %1%")%netwoking_module;
UnloadFTModule();
#if defined(_MSC_VER) || defined(_WIN32)
if (netwoking_module) {
FreeLibrary(netwoking_module);
@@ -445,6 +484,7 @@ int NetworkAgent::unload_network_module()
get_model_mall_home_url_ptr = nullptr;
get_model_mall_detail_url_ptr = nullptr;
get_my_profile_ptr = nullptr;
get_my_token_ptr = nullptr;
track_enable_ptr = nullptr;
track_remove_files_ptr = nullptr;
track_event_ptr = nullptr;
@@ -1018,6 +1058,17 @@ int NetworkAgent::bind_detect(std::string dev_ip, std::string sec_link, detectRe
return ret;
}
int NetworkAgent::report_consent(std::string expand)
{
int ret = 0;
if (network_agent && report_consent_ptr) {
ret = report_consent_ptr(network_agent, expand);
if (ret)
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%") % network_agent % ret;
}
return ret;
}
int NetworkAgent::set_server_callback(OnServerErrFn fn)
{
int ret = 0;
@@ -1454,6 +1505,17 @@ int NetworkAgent::get_my_profile(std::string token, unsigned int *http_code, std
return ret;
}
int NetworkAgent::get_my_token(std::string ticket, unsigned int* http_code, std::string* http_body)
{
int ret = 0;
if (network_agent && get_my_token_ptr) {
ret = get_my_token_ptr(network_agent, ticket, http_code, http_body);
if (ret)
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format("error network_agnet=%1%, ret = %2%") % network_agent % ret;
}
return ret;
}
int NetworkAgent::track_enable(bool enable)
{
enable_track = enable;