diff --git a/include/cos_config.h b/include/cos_config.h index 14eef56..2679cfa 100644 --- a/include/cos_config.h +++ b/include/cos_config.h @@ -25,6 +25,7 @@ class CosConfig { m_secret_key(""), m_region(""), m_tmp_token(""), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) {} @@ -42,6 +43,7 @@ class CosConfig { m_secret_key(secret_key), m_region(region), m_tmp_token(""), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) {} @@ -60,6 +62,7 @@ class CosConfig { m_secret_key(secret_key), m_region(region), m_tmp_token(tmp_token), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) {} @@ -73,6 +76,7 @@ class CosConfig { m_secret_key = config.m_secret_key; m_region = config.m_region; m_tmp_token = config.m_tmp_token; + m_set_intranet_once = config.m_set_intranet_once; m_is_use_intranet = config.m_is_use_intranet; m_intranet_addr = config.m_intranet_addr; m_config_parsed = config.m_config_parsed; @@ -87,6 +91,7 @@ class CosConfig { m_secret_key = config.m_secret_key; m_region = config.m_region; m_tmp_token = config.m_tmp_token; + m_set_intranet_once = config.m_set_intranet_once; m_is_use_intranet = config.m_is_use_intranet; m_intranet_addr = config.m_intranet_addr; m_config_parsed = config.m_config_parsed; @@ -159,6 +164,8 @@ class CosConfig { std::string GetIntranetAddr(); + bool GetSetIntranetOnce() const {return m_set_intranet_once;} + /// \brief 设置日志回调 void SetLogCallback(const LogCallback log_callback); @@ -179,6 +186,7 @@ class CosConfig { std::string m_region; std::string m_tmp_token; + bool m_set_intranet_once; bool m_is_use_intranet; std::string m_intranet_addr; bool m_config_parsed; diff --git a/include/cos_defines.h b/include/cos_defines.h index 00c32c6..9479e78 100644 --- a/include/cos_defines.h +++ b/include/cos_defines.h @@ -11,7 +11,7 @@ namespace qcloud_cos { -#define COS_CPP_SDK_VERSON "v5.5.6" +#define COS_CPP_SDK_VERSON "v5.5.7" /// 路径分隔符 const std::string kPathDelimiter = "/"; diff --git a/src/cos_config.cpp b/src/cos_config.cpp index 033dc00..fae2a4a 100644 --- a/src/cos_config.cpp +++ b/src/cos_config.cpp @@ -15,6 +15,7 @@ CosConfig::CosConfig(const std::string& config_file) m_secret_key(""), m_region(""), m_tmp_token(""), + m_set_intranet_once(false), m_is_use_intranet(false), m_intranet_addr(""), m_config_parsed(false) { @@ -191,11 +192,13 @@ bool CosConfig::InitConf(const std::string& config_file) { if (JsonObjectGetBoolValue(object, "IsUseIntranet", &bool_value)) { CosSysConfig::SetIsUseIntranet(bool_value); m_is_use_intranet = bool_value; + m_set_intranet_once = true; } if (JsonObjectGetStringValue(object, "IntranetAddr", &str_value)) { CosSysConfig::SetIntranetAddr(str_value); m_intranet_addr = str_value; + m_set_intranet_once = true; } CosSysConfig::PrintValue(); @@ -236,6 +239,8 @@ void CosConfig::SetConfigCredentail(const std::string& access_key, void CosConfig::SetIsUseIntranetAddr(bool is_use_intranet) { CosSysConfig::SetIsUseIntranet(is_use_intranet); m_is_use_intranet = is_use_intranet; + + m_set_intranet_once = true; } bool CosConfig::IsUseIntranet() { @@ -245,6 +250,8 @@ bool CosConfig::IsUseIntranet() { void CosConfig::SetIntranetAddr(const std::string& intranet_addr) { CosSysConfig::SetIntranetAddr(intranet_addr); m_intranet_addr = intranet_addr; + + m_set_intranet_once = true; } std::string CosConfig::GetIntranetAddr() { diff --git a/src/cos_sys_config.cpp b/src/cos_sys_config.cpp index e0afb73..6e7fcd7 100644 --- a/src/cos_sys_config.cpp +++ b/src/cos_sys_config.cpp @@ -57,6 +57,8 @@ unsigned CosSysConfig::m_dns_cache_expire_seconds = 600; // dns cache大小 unsigned CosSysConfig::m_dns_cache_size = 1000; +std::mutex m_intranet_addr_lock; + void CosSysConfig::PrintValue() { std::cout << "upload_part_size:" << m_upload_part_size << std::endl; std::cout << "upload_copy_part_size:" << m_upload_copy_part_size << std::endl; @@ -213,6 +215,7 @@ void CosSysConfig::SetIsUseIntranet(bool is_use_intranet) { bool CosSysConfig::IsUseIntranet() { return m_is_use_intranet; } void CosSysConfig::SetIntranetAddr(const std::string& intranet_addr) { + std::lock_guard lock(m_intranet_addr_lock); m_intranet_addr = intranet_addr; } @@ -248,7 +251,10 @@ std::string CosSysConfig::GetCIHost(const std::string& bucket_name, std::string CosSysConfig::GetDestDomain() { return m_dest_domain; } -std::string CosSysConfig::GetIntranetAddr() { return m_intranet_addr; } +std::string CosSysConfig::GetIntranetAddr() { + std::lock_guard lock(m_intranet_addr_lock); + return m_intranet_addr; +} LogCallback CosSysConfig::GetLogCallback() { return m_log_callback; } diff --git a/src/op/base_op.cpp b/src/op/base_op.cpp index bf39273..143ec32 100644 --- a/src/op/base_op.cpp +++ b/src/op/base_op.cpp @@ -305,9 +305,13 @@ std::string BaseOp::GetRealUrl(const std::string& host, const std::string& path, dest_path = "/" + dest_path; } - if (m_config->IsUseIntranet() && + if (m_config->GetSetIntranetOnce() && + m_config->IsUseIntranet() && !m_config->GetIntranetAddr().empty()) { dest_host = m_config->GetIntranetAddr(); + } else if (CosSysConfig::IsUseIntranet() && + !CosSysConfig::GetIntranetAddr().empty()) { + dest_host = CosSysConfig::GetIntranetAddr(); } else if (!CosSysConfig::GetDestDomain().empty()) { dest_host = CosSysConfig::GetDestDomain(); } else if (CosSysConfig::GetUseDnsCache()) {