From e5185e0b2c5c7a9f122bfdaaff52eb1ed24a2a19 Mon Sep 17 00:00:00 2001 From: gavinhgchen Date: Wed, 7 Sep 2022 19:16:23 +0800 Subject: [PATCH 1/4] modify CMake to support android & ios --- CMakeLists.txt | 32 ++++++++++++++++++++++++++------ demo/CMakeLists.txt | 6 +++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 363aa33..866812f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,19 @@ elseif(WIN32) else() message(FATAL_ERROR "unkonwn os type") endif() + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") + set(OS_TYPE "Android") + message(STATUS "SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "iOS") + set(OS_TYPE "iOS") + message(STATUS "SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") +endif() + message(STATUS "OS type: ${OS_TYPE}") +set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/) +set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoFoundation PocoXML) if (${OS_TYPE} STREQUAL "WINDOWS") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(BUILD_TARGET "Win32") @@ -31,22 +42,31 @@ if (${OS_TYPE} STREQUAL "WINDOWS") message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${BUILD_TARGET}/poco) - set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/) - set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoFoundation PocoXML) set(SYSTEM_LIBS "") #需要加该参数,不然VS会报错 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") +elseif(${OS_TYPE} STREQUAL "iOS") + set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/poco/) + set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") + set(SYSTEM_LIBS stdc++ pthread) + set(OPENSSL_LIBS crypto ssl) +elseif(${OS_TYPE} STREQUAL "Android") + set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/poco/) + set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") + set(SYSTEM_LIBS stdc++) + set(OPENSSL_LIBS crypto ssl) +# Linux or MacOs else() - set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/linux/poco/) if (${OS_TYPE} STREQUAL "APPLE") set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/macOS/poco/) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wextra") + set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/linux/poco/) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") endif() - set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/) - set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoFoundation PocoXML) set(SYSTEM_LIBS stdc++ pthread) endif() diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index d8714e7..576675a 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -6,12 +6,12 @@ endif() file(GLOB demo_src "${CMAKE_SOURCE_DIR}/demo/cos_demo.cpp") file(GLOB stable_test_src "${CMAKE_SOURCE_DIR}/demo/stable_test.cpp") -link_directories(${POCO_LINK_DIR}) #这一行要放到add_executable前面 +link_directories(${POCO_LINK_DIR} ${OPENSSL_LINK_DIR}) #这一行要放到add_executable前面 add_executable(${PROJECT_NAME} ${demo_src}) add_executable(stable_test ${stable_test_src}) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) -target_link_libraries(${PROJECT_NAME} cossdk ${POCO_LIBS} ${SYSTEM_LIBS}) -target_link_libraries(stable_test cossdk ${POCO_LIBS} ${SYSTEM_LIBS}) +target_link_libraries(${PROJECT_NAME} cossdk ${POCO_LIBS} ${OPENSSL_LIBS} ${SYSTEM_LIBS}) +target_link_libraries(stable_test cossdk ${POCO_LIBS} ${OPENSSL_LIBS} ${SYSTEM_LIBS}) include_directories(${CMAKE_SOURCE_DIR}/include/ ${POCO_INCLUDE_DIR}) if(${OS_TYPE} STREQUAL "WINDOWS") From 3a6da581fd379fa97c1fb69fffc41b19652af1c0 Mon Sep 17 00:00:00 2001 From: gavinhgchen Date: Thu, 8 Sep 2022 16:31:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=A0=B9=E8=AF=81=E4=B9=A6=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 ++-- include/cos_defines.h | 2 +- include/op/file_copy_task.h | 3 +++ include/op/file_download_task.h | 6 +++++- include/op/file_upload_task.h | 12 +++++++++--- include/op/object_op.h | 2 +- include/request/base_req.h | 5 +++++ include/util/http_sender.h | 15 ++++++++++----- src/op/base_op.cpp | 6 +++--- src/op/file_copy_task.cpp | 7 ++++++- src/op/file_download_task.cpp | 12 +++++++++--- src/op/file_upload_task.cpp | 23 ++++++++++++++++------- src/op/object_op.cpp | 8 +++++--- src/util/http_sender.cpp | 32 ++++++++++++++++++++------------ 14 files changed, 95 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 866812f..1dbc6d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,13 +51,13 @@ elseif(${OS_TYPE} STREQUAL "iOS") set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") set(SYSTEM_LIBS stdc++ pthread) - set(OPENSSL_LIBS crypto ssl) + set(OPENSSL_LIBS ssl crypto) elseif(${OS_TYPE} STREQUAL "Android") set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/poco/) set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") set(SYSTEM_LIBS stdc++) - set(OPENSSL_LIBS crypto ssl) + set(OPENSSL_LIBS ssl crypto) # Linux or MacOs else() if (${OS_TYPE} STREQUAL "APPLE") diff --git a/include/cos_defines.h b/include/cos_defines.h index c3d46ae..407f6d6 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.8" +#define COS_CPP_SDK_VERSON "v5.5.9" /// 路径分隔符 const std::string kPathDelimiter = "/"; diff --git a/include/op/file_copy_task.h b/include/op/file_copy_task.h index aa68e46..61ab025 100644 --- a/include/op/file_copy_task.h +++ b/include/op/file_copy_task.h @@ -33,6 +33,8 @@ class FileCopyTask : public Poco::Runnable { void SetHeaders(const std::map& headers); + void SetCaLocation(const std::string& ca_location); + std::string GetErrMsg() const { return m_err_msg; } std::string GetEtag() const { return m_etag; } @@ -52,6 +54,7 @@ class FileCopyTask : public Poco::Runnable { std::string m_err_msg; std::string m_etag; std::string m_last_modified; + std::string m_ca_location; }; } // namespace qcloud_cos \ No newline at end of file diff --git a/include/op/file_download_task.h b/include/op/file_download_task.h index e55b949..e49290a 100644 --- a/include/op/file_download_task.h +++ b/include/op/file_download_task.h @@ -26,7 +26,7 @@ class FileDownTask : public Poco::Runnable { uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, const SharedTransferHandler& handler = nullptr, uint64_t offset = 0, unsigned char* pbuf = NULL, - const size_t data_len = 0); + const size_t data_len = 0, const std::string& ca_lication = ""); ~FileDownTask() {} @@ -36,6 +36,8 @@ class FileDownTask : public Poco::Runnable { void SetDownParams(unsigned char* pdatabuf, size_t datalen, uint64_t offset); + void SetCaLocation(const std::string& ca_location); + std::string GetTaskResp(); size_t GetDownLoadLen(); @@ -65,6 +67,8 @@ class FileDownTask : public Poco::Runnable { std::map m_resp_headers; std::string m_err_msg; + std::string m_ca_location; + SharedConfig m_config; }; diff --git a/include/op/file_upload_task.h b/include/op/file_upload_task.h index 973474a..e1a0632 100644 --- a/include/op/file_upload_task.h +++ b/include/op/file_upload_task.h @@ -14,19 +14,21 @@ class FileUploadTask : public Poco::Runnable { public: FileUploadTask(const std::string& full_url, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, unsigned char* pbuf = NULL, - const size_t data_len = 0); + const size_t data_len = 0, const std::string& ca_location = ""); FileUploadTask(const std::string& full_url, const std::map& headers, const std::map& params, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, - const SharedTransferHandler& handler); + const SharedTransferHandler& handler, + const std::string& ca_location = ""); FileUploadTask(const std::string& full_url, const std::map& headers, const std::map& params, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, - unsigned char* pbuf = NULL, const size_t data_len = 0); + unsigned char* pbuf = NULL, const size_t data_len = 0, + const std::string& ca_location = ""); ~FileUploadTask() {} @@ -66,6 +68,8 @@ class FileUploadTask : public Poco::Runnable { uint64_t GetPartNumber() const { return m_part_number; } + void SetCaLocation(const std::string& ca_location); + private: std::string m_full_url; std::map m_headers; @@ -83,6 +87,8 @@ class FileUploadTask : public Poco::Runnable { std::string m_resume_etag; uint64_t m_part_number; SharedTransferHandler m_handler; + + std::string m_ca_location; }; } // namespace qcloud_cos diff --git a/include/op/object_op.h b/include/op/object_op.h index 66853dc..be1afc5 100644 --- a/include/op/object_op.h +++ b/include/op/object_op.h @@ -390,7 +390,7 @@ class ObjectOp : public BaseOp { const std::string& range, const std::map& headers, const std::map& params, - FileCopyTask* task); + const std::string& ca_location, FileCopyTask* task); /// \brief 检查是否可以走断点下载 /// \param req PutObjectByFile请求 diff --git a/include/request/base_req.h b/include/request/base_req.h index 123d7ed..ccdb318 100644 --- a/include/request/base_req.h +++ b/include/request/base_req.h @@ -90,6 +90,9 @@ class BaseReq { void SetCheckCRC64(bool check_crc64) { mb_check_crc64 = check_crc64; } bool CheckCRC64() const { return mb_check_crc64; } + void SetCaLocation(const std::string& ca_location) { m_ca_location = ca_location; } + const std::string& GetCaLocation() const { return m_ca_location; } + /// \brief 输出请求的header和param信息 std::string DebugString() const; @@ -110,6 +113,8 @@ class BaseReq { bool m_is_https; bool mb_check_md5; // default is true bool mb_check_crc64; // default is false + + std::string m_ca_location; }; } // namespace qcloud_cos diff --git a/include/util/http_sender.h b/include/util/http_sender.h index c93c41e..df0a1c2 100644 --- a/include/util/http_sender.h +++ b/include/util/http_sender.h @@ -30,7 +30,8 @@ class HttpSender { uint64_t recv_timeout_in_ms, std::map* resp_headers, std::string* resp_body, std::string* err_msg, - bool is_check_md5 = false); + bool is_check_md5 = false, + const std::string& ca_location = ""); static int SendRequest(const SharedTransferHandler& handler, const std::string& http_method, @@ -42,7 +43,8 @@ class HttpSender { uint64_t recv_timeout_in_ms, std::map* resp_headers, std::ostream& resp_stream, std::string* err_msg, - bool is_check_md5 = false); + bool is_check_md5 = false, + const std::string& ca_location = ""); static int SendRequest(const SharedTransferHandler& handler, const std::string& http_method, @@ -53,7 +55,8 @@ class HttpSender { uint64_t recv_timeout_in_ms, std::map* resp_headers, std::string* resp_body, std::string* err_msg, - bool is_check_md5 = false); + bool is_check_md5 = false, + const std::string& ca_location = ""); static int SendRequest(const SharedTransferHandler& handler, const std::string& http_method, @@ -64,7 +67,8 @@ class HttpSender { uint64_t recv_timeout_in_ms, std::map* resp_headers, std::ostream& resp_stream, std::string* err_msg, - bool is_check_md5 = false); + bool is_check_md5 = false, + const std::string& ca_location = ""); static int SendRequest(const SharedTransferHandler& handler, const std::string& http_method, @@ -77,7 +81,8 @@ class HttpSender { std::map* resp_headers, std::string* xml_err_str, std::ostream& resp_stream, std::string* err_msg, uint64_t* real_byte, - bool is_check_md5 = false); + bool is_check_md5 = false, + const std::string& ca_location = ""); }; } // namespace qcloud_cos diff --git a/src/op/base_op.cpp b/src/op/base_op.cpp index 058f50f..aba1837 100644 --- a/src/op/base_op.cpp +++ b/src/op/base_op.cpp @@ -104,7 +104,7 @@ CosResult BaseOp::NormalAction( int http_code = HttpSender::SendRequest(nullptr, req.GetMethod(), dest_url, req_params, req_headers, req_body, req.GetConnTimeoutInms(), req.GetRecvTimeoutInms(), &resp_headers, - &resp_body, &err_msg); + &resp_body, &err_msg, false, req.GetCaLocation()); if (http_code == -1) { result.SetErrorMsg(err_msg); return result; @@ -185,7 +185,7 @@ CosResult BaseOp::DownloadAction(const std::string& host, int http_code = HttpSender::SendRequest( handler, req.GetMethod(), dest_url, req_params, req_headers, "", req.GetConnTimeoutInms(), req.GetRecvTimeoutInms(), &resp_headers, - &xml_err_str, os, &err_msg, &real_byte, req.CheckMD5()); + &xml_err_str, os, &err_msg, &real_byte, req.CheckMD5(), req.GetCaLocation()); if (http_code == -1) { result.SetErrorMsg(err_msg); return result; @@ -270,7 +270,7 @@ CosResult BaseOp::UploadAction( int http_code = HttpSender::SendRequest( handler, req.GetMethod(), dest_url, req_params, req_headers, is, req.GetConnTimeoutInms(), req.GetRecvTimeoutInms(), &resp_headers, - &resp_body, &err_msg); + &resp_body, &err_msg, false, req.GetCaLocation()); if (http_code == -1) { result.SetErrorMsg(err_msg); return result; diff --git a/src/op/file_copy_task.cpp b/src/op/file_copy_task.cpp index b9b3c3c..38eadb4 100644 --- a/src/op/file_copy_task.cpp +++ b/src/op/file_copy_task.cpp @@ -37,6 +37,10 @@ void FileCopyTask::SetHeaders( m_headers.insert(headers.begin(), headers.end()); } +void FileCopyTask::SetCaLocation(const std::string& ca_location) { + m_ca_location = ca_location; +} + void FileCopyTask::run() { m_is_task_success = false; CopyTask(); @@ -51,7 +55,8 @@ void FileCopyTask::CopyTask() { m_http_status = HttpSender::SendRequest(nullptr, "PUT", m_full_url, m_params, m_headers, "", m_conn_timeout_in_ms, - m_recv_timeout_in_ms, &m_resp_headers, &m_resp, &m_err_msg); + m_recv_timeout_in_ms, &m_resp_headers, &m_resp, &m_err_msg, + false, m_ca_location); if (m_http_status != 200) { SDK_LOG_ERR("FileUpload: url(%s) fail, httpcode:%d, resp: %s", diff --git a/src/op/file_download_task.cpp b/src/op/file_download_task.cpp index 4e431d5..5235e32 100644 --- a/src/op/file_download_task.cpp +++ b/src/op/file_download_task.cpp @@ -16,7 +16,8 @@ FileDownTask::FileDownTask(const std::string& full_url, uint64_t recv_timeout_in_ms, const SharedTransferHandler& handler, uint64_t offset, unsigned char* pbuf, - const size_t data_len) + const size_t data_len, + const std::string& ca_lication) : m_full_url(full_url), m_headers(headers), m_params(params), @@ -28,7 +29,8 @@ FileDownTask::FileDownTask(const std::string& full_url, m_data_len(data_len), m_resp(""), m_is_task_success(false), - m_real_down_len(0) {} + m_real_down_len(0), + m_ca_location(ca_lication) {} void FileDownTask::run() { m_resp = ""; @@ -43,6 +45,10 @@ void FileDownTask::SetDownParams(unsigned char* pbuf, size_t data_len, m_offset = offset; } +void FileDownTask::SetCaLocation(const std::string& ca_location) { + m_ca_location = ca_location; +} + size_t FileDownTask::GetDownLoadLen() { return m_real_down_len; } bool FileDownTask::IsTaskSuccess() { return m_is_task_success; } @@ -80,7 +86,7 @@ void FileDownTask::DownTask() { m_http_status = HttpSender::SendRequest( m_handler, "GET", m_full_url, m_params, m_headers, "", m_conn_timeout_in_ms, m_recv_timeout_in_ms, &m_resp_headers, &m_resp, - &m_err_msg); + &m_err_msg, false, m_ca_location); //} //当实际长度小于请求的数据长度时httpcode为206 if (m_http_status != 200 && m_http_status != 206) { diff --git a/src/op/file_upload_task.cpp b/src/op/file_upload_task.cpp index 669670d..88ec892 100644 --- a/src/op/file_upload_task.cpp +++ b/src/op/file_upload_task.cpp @@ -12,7 +12,7 @@ namespace qcloud_cos { FileUploadTask::FileUploadTask(const std::string& full_url, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, unsigned char* pbuf, - const size_t data_len) + const size_t data_len, const std::string& ca_location) : m_full_url(full_url), m_conn_timeout_in_ms(conn_timeout_in_ms), m_recv_timeout_in_ms(recv_timeout_in_ms), @@ -21,14 +21,16 @@ FileUploadTask::FileUploadTask(const std::string& full_url, m_resp(""), m_is_task_success(false), m_is_resume(false), - m_handler(NULL) {} + m_handler(NULL), + m_ca_location(ca_location) {} FileUploadTask::FileUploadTask( const std::string& full_url, const std::map& headers, const std::map& params, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, - const SharedTransferHandler& handler) + const SharedTransferHandler& handler, + const std::string& ca_location) : m_full_url(full_url), m_headers(headers), m_params(params), @@ -39,14 +41,16 @@ FileUploadTask::FileUploadTask( m_resp(""), m_is_task_success(false), m_is_resume(false), - m_handler(handler) {} + m_handler(handler), + m_ca_location(ca_location) {} FileUploadTask::FileUploadTask( const std::string& full_url, const std::map& headers, const std::map& params, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, - unsigned char* pbuf, const size_t data_len) + unsigned char* pbuf, const size_t data_len, + const std::string& ca_location) : m_full_url(full_url), m_headers(headers), m_params(params), @@ -57,7 +61,8 @@ FileUploadTask::FileUploadTask( m_resp(""), m_is_task_success(false), m_is_resume(false), - m_handler(NULL) {} + m_handler(NULL), + m_ca_location(ca_location) {} void FileUploadTask::run() { m_resp = ""; @@ -112,6 +117,10 @@ void FileUploadTask::SetPartNumber(uint64_t part_number) { m_part_number = part_number; } +void FileUploadTask::SetCaLocation(const std::string& ca_location) { + m_ca_location = ca_location; +} + void FileUploadTask::UploadTask() { std::string body((const char*)m_data_buf_ptr, m_data_len); // 计算上传的md5 @@ -141,7 +150,7 @@ void FileUploadTask::UploadTask() { m_http_status = HttpSender::SendRequest( m_handler, "PUT", m_full_url, m_params, m_headers, body, m_conn_timeout_in_ms, m_recv_timeout_in_ms, &m_resp_headers, &m_resp, - &m_err_msg); + &m_err_msg, false, m_ca_location); //} if (m_http_status != 200) { diff --git a/src/op/object_op.cpp b/src/op/object_op.cpp index 11a8bd8..971f59a 100644 --- a/src/op/object_op.cpp +++ b/src/op/object_op.cpp @@ -1010,7 +1010,7 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { FileCopyTask* ptask = pptaskArr[task_index]; FillCopyTask(upload_id, host, path, part_number, range, - part_copy_headers, req.GetParams(), ptask); + part_copy_headers, req.GetParams(), req.GetCaLocation(), ptask); tp.start(*ptask); part_numbers.push_back(part_number); ++part_number; @@ -1257,6 +1257,7 @@ ObjectOp::MultiThreadDownload(const GetObjectByFileReq& req, left_size = file_size - offset; part_len = slice_size < left_size ? slice_size : left_size; ptask->SetDownParams(file_content_buf[task_index], part_len, offset); + ptask->SetCaLocation(req.GetCaLocation()); tp.start(*ptask); vec_offset[task_index] = offset; offset += part_len; @@ -1450,7 +1451,7 @@ CosResult ObjectOp::MultiThreadUpload( for (int i = 0; i < pool_size; ++i) { pptaskArr[i] = new FileUploadTask(dest_url, headers, params, req.GetConnTimeoutInms(), - req.GetRecvTimeoutInms(), handler); + req.GetRecvTimeoutInms(), handler, req.GetCaLocation()); } SDK_LOG_DBG("upload data, url=%s, poolsize=%u, part_size=%" PRIu64 @@ -1621,7 +1622,7 @@ void ObjectOp::FillCopyTask(const std::string& upload_id, uint64_t part_number, const std::string& range, const std::map& headers, const std::map& params, - FileCopyTask* task_ptr) { + const std::string& ca_location, FileCopyTask* task_ptr) { std::map req_params = params; req_params.insert(std::make_pair("uploadId", upload_id)); req_params.insert( @@ -1645,6 +1646,7 @@ void ObjectOp::FillCopyTask(const std::string& upload_id, task_ptr->SetParams(req_params); task_ptr->SetHeaders(req_headers); + task_ptr->SetCaLocation(ca_location); } std::string ObjectOp::GeneratePresignedUrl(const GeneratePresignedUrlReq& req) { diff --git a/src/util/http_sender.cpp b/src/util/http_sender.cpp index baf3c7e..7631513 100644 --- a/src/util/http_sender.cpp +++ b/src/util/http_sender.cpp @@ -37,12 +37,12 @@ int HttpSender::SendRequest( const std::string& req_body, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, std::map* resp_headers, std::string* resp_body, - std::string* err_msg, bool is_check_md5) { + std::string* err_msg, bool is_check_md5, const std::string& ca_location) { std::istringstream is(req_body); std::ostringstream oss; int ret = SendRequest(handler, http_method, url_str, req_params, req_headers, is, conn_timeout_in_ms, recv_timeout_in_ms, - resp_headers, oss, err_msg, is_check_md5); + resp_headers, oss, err_msg, is_check_md5, ca_location); *resp_body = oss.str(); return ret; } @@ -55,11 +55,11 @@ int HttpSender::SendRequest( const std::string& req_body, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, std::map* resp_headers, std::ostream& resp_stream, - std::string* err_msg, bool is_check_md5) { + std::string* err_msg, bool is_check_md5, const std::string& ca_location) { std::istringstream is(req_body); int ret = SendRequest(handler, http_method, url_str, req_params, req_headers, is, conn_timeout_in_ms, recv_timeout_in_ms, - resp_headers, resp_stream, err_msg, is_check_md5); + resp_headers, resp_stream, err_msg, is_check_md5, ca_location); return ret; } @@ -70,11 +70,11 @@ int HttpSender::SendRequest( const std::map& req_headers, std::istream& is, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, std::map* resp_headers, std::string* resp_body, - std::string* err_msg, bool is_check_md5) { + std::string* err_msg, bool is_check_md5, const std::string& ca_location) { std::ostringstream oss; int ret = SendRequest(handler, http_method, url_str, req_params, req_headers, is, conn_timeout_in_ms, recv_timeout_in_ms, - resp_headers, oss, err_msg, is_check_md5); + resp_headers, oss, err_msg, is_check_md5, ca_location); *resp_body = oss.str(); return ret; } @@ -86,16 +86,20 @@ int HttpSender::SendRequest( const std::map& req_headers, std::istream& is, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, std::map* resp_headers, std::ostream& resp_stream, - std::string* err_msg, bool is_check_md5) { + std::string* err_msg, bool is_check_md5, const std::string& ca_location) { Poco::Net::HTTPResponse res; try { SDK_LOG_INFO("send request to [%s]", url_str.c_str()); Poco::URI url(url_str); std::unique_ptr session; if (StringUtil::StringStartsWithIgnoreCase(url_str, "https")) { + bool load_default_ca = true; + if (!ca_location.empty()) { + load_default_ca = false; + } Poco::Net::Context::Ptr context = - new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", - Poco::Net::Context::VERIFY_RELAXED, 9, true, + new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", ca_location, + Poco::Net::Context::VERIFY_RELAXED, 9, load_default_ca, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); session.reset(new Poco::Net::HTTPSClientSession(url.getHost(), url.getPort(), context)); @@ -298,16 +302,20 @@ int HttpSender::SendRequest( uint64_t recv_timeout_in_ms, std::map* resp_headers, std::string* xml_err_str, std::ostream& resp_stream, std::string* err_msg, uint64_t* real_byte, - bool is_check_md5) { + bool is_check_md5, const std::string& ca_location) { Poco::Net::HTTPResponse res; try { SDK_LOG_INFO("send request to [%s]", url_str.c_str()); Poco::URI url(url_str); std::unique_ptr session; if (StringUtil::StringStartsWithIgnoreCase(url_str, "https")) { + bool load_default_ca = true; + if (!ca_location.empty()) { + load_default_ca = false; + } Poco::Net::Context::Ptr context = - new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", - Poco::Net::Context::VERIFY_RELAXED, 9, true, + new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", ca_location, + Poco::Net::Context::VERIFY_RELAXED, 9, load_default_ca, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); session.reset(new Poco::Net::HTTPSClientSession(url.getHost(), url.getPort(), context)); From f2bd051662b97b3c501685437bdb3a769e646372 Mon Sep 17 00:00:00 2001 From: gavinhgchen Date: Thu, 8 Sep 2022 17:41:14 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=94=AF=E6=8C=81cossdk=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dbc6d0..4663047 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ endif() message(STATUS "OS type: ${OS_TYPE}") set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/) -set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoFoundation PocoXML) +set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoXML PocoFoundation) if (${OS_TYPE} STREQUAL "WINDOWS") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(BUILD_TARGET "Win32") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0b1521..c9b23d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,8 +40,8 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "cossdk") if(BUILD_SHARED_LIB) message(STATUS "Build shared lib") - link_directories(${POCO_LINK_DIR}) #这一行要放到add_library前面 + link_directories(${POCO_LINK_DIR} ${OPENSSL_LINK_DIR}) #这一行要放到add_library前面 add_library(${PROJECT_NAME}-shared SHARED ${sdk_src}) include_directories(${CMAKE_SOURCE_DIR}/include/ ${POCO_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME}-shared ${POCO_LIBS} ${SYSTEM_LIBS}) + target_link_libraries(${PROJECT_NAME}-shared ${POCO_LIBS} ${OPENSSL_LIBS} ${SYSTEM_LIBS}) endif() \ No newline at end of file From 03ff7a0c059184f71794282d83ca4f6234d85b66 Mon Sep 17 00:00:00 2001 From: gavinhgchen Date: Thu, 8 Sep 2022 23:07:09 +0800 Subject: [PATCH 4/4] add third_party iOS&Android --- third_party/lib/Android/aarch64/openssl/.gitkeep | 0 third_party/lib/Android/aarch64/poco/.gitkeep | 0 third_party/lib/Android/armv7-a/openssl/.gitkeep | 0 third_party/lib/Android/armv7-a/poco/.gitkeep | 0 third_party/lib/iOS/aarch64/openssl/.gitkeep | 0 third_party/lib/iOS/aarch64/poco/.gitkeep | 0 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 third_party/lib/Android/aarch64/openssl/.gitkeep create mode 100644 third_party/lib/Android/aarch64/poco/.gitkeep create mode 100644 third_party/lib/Android/armv7-a/openssl/.gitkeep create mode 100644 third_party/lib/Android/armv7-a/poco/.gitkeep create mode 100644 third_party/lib/iOS/aarch64/openssl/.gitkeep create mode 100644 third_party/lib/iOS/aarch64/poco/.gitkeep diff --git a/third_party/lib/Android/aarch64/openssl/.gitkeep b/third_party/lib/Android/aarch64/openssl/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/third_party/lib/Android/aarch64/poco/.gitkeep b/third_party/lib/Android/aarch64/poco/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/third_party/lib/Android/armv7-a/openssl/.gitkeep b/third_party/lib/Android/armv7-a/openssl/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/third_party/lib/Android/armv7-a/poco/.gitkeep b/third_party/lib/Android/armv7-a/poco/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/third_party/lib/iOS/aarch64/openssl/.gitkeep b/third_party/lib/iOS/aarch64/openssl/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/third_party/lib/iOS/aarch64/poco/.gitkeep b/third_party/lib/iOS/aarch64/poco/.gitkeep new file mode 100644 index 0000000..e69de29