Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 PocoXML PocoFoundation)
if (${OS_TYPE} STREQUAL "WINDOWS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(BUILD_TARGET "Win32")
Expand All @@ -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 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 ssl crypto)
# 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()
Expand Down
6 changes: 3 additions & 3 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion include/cos_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/";
Expand Down
3 changes: 3 additions & 0 deletions include/op/file_copy_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class FileCopyTask : public Poco::Runnable {

void SetHeaders(const std::map<std::string, std::string>& headers);

void SetCaLocation(const std::string& ca_location);

std::string GetErrMsg() const { return m_err_msg; }

std::string GetEtag() const { return m_etag; }
Expand All @@ -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
6 changes: 5 additions & 1 deletion include/op/file_download_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand All @@ -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();
Expand Down Expand Up @@ -65,6 +67,8 @@ class FileDownTask : public Poco::Runnable {
std::map<std::string, std::string> m_resp_headers;
std::string m_err_msg;

std::string m_ca_location;

SharedConfig m_config;
};

Expand Down
12 changes: 9 additions & 3 deletions include/op/file_upload_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string>& headers,
const std::map<std::string, std::string>& 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<std::string, std::string>& headers,
const std::map<std::string, std::string>& 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() {}

Expand Down Expand Up @@ -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<std::string, std::string> m_headers;
Expand All @@ -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
2 changes: 1 addition & 1 deletion include/op/object_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class ObjectOp : public BaseOp {
const std::string& range,
const std::map<std::string, std::string>& headers,
const std::map<std::string, std::string>& params,
FileCopyTask* task);
const std::string& ca_location, FileCopyTask* task);

/// \brief 检查是否可以走断点下载
/// \param req PutObjectByFile请求
Expand Down
5 changes: 5 additions & 0 deletions include/request/base_req.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
15 changes: 10 additions & 5 deletions include/util/http_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class HttpSender {
uint64_t recv_timeout_in_ms,
std::map<std::string, std::string>* 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,
Expand All @@ -42,7 +43,8 @@ class HttpSender {
uint64_t recv_timeout_in_ms,
std::map<std::string, std::string>* 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,
Expand All @@ -53,7 +55,8 @@ class HttpSender {
uint64_t recv_timeout_in_ms,
std::map<std::string, std::string>* 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,
Expand All @@ -64,7 +67,8 @@ class HttpSender {
uint64_t recv_timeout_in_ms,
std::map<std::string, std::string>* 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,
Expand All @@ -77,7 +81,8 @@ class HttpSender {
std::map<std::string, std::string>* 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
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions src/op/base_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/op/file_copy_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions src/op/file_download_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 = "";
Expand All @@ -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; }
Expand Down Expand Up @@ -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) {
Expand Down
Loading