Skip to content

Commit d3555e6

Browse files
chen-hongganggavinhgchen
andauthored
support android&ios mobile (#118)
* modify CMake to support android & ios * 支持指定根证书文件 * 支持cossdk动态库 * add third_party iOS&Android Co-authored-by: gavinhgchen <[email protected]>
1 parent 06043f1 commit d3555e6

File tree

22 files changed

+124
-51
lines changed

22 files changed

+124
-51
lines changed

CMakeLists.txt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ elseif(WIN32)
1616
else()
1717
message(FATAL_ERROR "unkonwn os type")
1818
endif()
19+
20+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
21+
set(OS_TYPE "Android")
22+
message(STATUS "SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
23+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
24+
set(OS_TYPE "iOS")
25+
message(STATUS "SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
26+
endif()
27+
1928
message(STATUS "OS type: ${OS_TYPE}")
2029

30+
set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/)
31+
set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoXML PocoFoundation)
2132
if (${OS_TYPE} STREQUAL "WINDOWS")
2233
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
2334
set(BUILD_TARGET "Win32")
@@ -31,22 +42,31 @@ if (${OS_TYPE} STREQUAL "WINDOWS")
3142
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
3243

3344
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${BUILD_TARGET}/poco)
34-
set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/)
35-
set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoFoundation PocoXML)
3645

3746
set(SYSTEM_LIBS "")
3847
#需要加该参数,不然VS会报错
3948
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
49+
elseif(${OS_TYPE} STREQUAL "iOS")
50+
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/poco/)
51+
set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/)
52+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
53+
set(SYSTEM_LIBS stdc++ pthread)
54+
set(OPENSSL_LIBS ssl crypto)
55+
elseif(${OS_TYPE} STREQUAL "Android")
56+
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/poco/)
57+
set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/)
58+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
59+
set(SYSTEM_LIBS stdc++)
60+
set(OPENSSL_LIBS ssl crypto)
61+
# Linux or MacOs
4062
else()
41-
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/linux/poco/)
4263
if (${OS_TYPE} STREQUAL "APPLE")
4364
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/macOS/poco/)
4465
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
4566
else()
46-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wextra")
67+
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/linux/poco/)
68+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
4769
endif()
48-
set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/)
49-
set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoFoundation PocoXML)
5070

5171
set(SYSTEM_LIBS stdc++ pthread)
5272
endif()

demo/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ endif()
66
file(GLOB demo_src "${CMAKE_SOURCE_DIR}/demo/cos_demo.cpp")
77
file(GLOB stable_test_src "${CMAKE_SOURCE_DIR}/demo/stable_test.cpp")
88

9-
link_directories(${POCO_LINK_DIR}) #这一行要放到add_executable前面
9+
link_directories(${POCO_LINK_DIR} ${OPENSSL_LINK_DIR}) #这一行要放到add_executable前面
1010
add_executable(${PROJECT_NAME} ${demo_src})
1111
add_executable(stable_test ${stable_test_src})
1212
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
13-
target_link_libraries(${PROJECT_NAME} cossdk ${POCO_LIBS} ${SYSTEM_LIBS})
14-
target_link_libraries(stable_test cossdk ${POCO_LIBS} ${SYSTEM_LIBS})
13+
target_link_libraries(${PROJECT_NAME} cossdk ${POCO_LIBS} ${OPENSSL_LIBS} ${SYSTEM_LIBS})
14+
target_link_libraries(stable_test cossdk ${POCO_LIBS} ${OPENSSL_LIBS} ${SYSTEM_LIBS})
1515
include_directories(${CMAKE_SOURCE_DIR}/include/ ${POCO_INCLUDE_DIR})
1616

1717
if(${OS_TYPE} STREQUAL "WINDOWS")

include/cos_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace qcloud_cos {
1313

14-
#define COS_CPP_SDK_VERSON "v5.5.8"
14+
#define COS_CPP_SDK_VERSON "v5.5.9"
1515

1616
/// 路径分隔符
1717
const std::string kPathDelimiter = "/";

include/op/file_copy_task.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class FileCopyTask : public Poco::Runnable {
3333

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

36+
void SetCaLocation(const std::string& ca_location);
37+
3638
std::string GetErrMsg() const { return m_err_msg; }
3739

3840
std::string GetEtag() const { return m_etag; }
@@ -52,6 +54,7 @@ class FileCopyTask : public Poco::Runnable {
5254
std::string m_err_msg;
5355
std::string m_etag;
5456
std::string m_last_modified;
57+
std::string m_ca_location;
5558
};
5659

5760
} // namespace qcloud_cos

include/op/file_download_task.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FileDownTask : public Poco::Runnable {
2626
uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms,
2727
const SharedTransferHandler& handler = nullptr,
2828
uint64_t offset = 0, unsigned char* pbuf = NULL,
29-
const size_t data_len = 0);
29+
const size_t data_len = 0, const std::string& ca_lication = "");
3030

3131
~FileDownTask() {}
3232

@@ -36,6 +36,8 @@ class FileDownTask : public Poco::Runnable {
3636

3737
void SetDownParams(unsigned char* pdatabuf, size_t datalen, uint64_t offset);
3838

39+
void SetCaLocation(const std::string& ca_location);
40+
3941
std::string GetTaskResp();
4042

4143
size_t GetDownLoadLen();
@@ -65,6 +67,8 @@ class FileDownTask : public Poco::Runnable {
6567
std::map<std::string, std::string> m_resp_headers;
6668
std::string m_err_msg;
6769

70+
std::string m_ca_location;
71+
6872
SharedConfig m_config;
6973
};
7074

include/op/file_upload_task.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ class FileUploadTask : public Poco::Runnable {
1414
public:
1515
FileUploadTask(const std::string& full_url, uint64_t conn_timeout_in_ms,
1616
uint64_t recv_timeout_in_ms, unsigned char* pbuf = NULL,
17-
const size_t data_len = 0);
17+
const size_t data_len = 0, const std::string& ca_location = "");
1818

1919
FileUploadTask(const std::string& full_url,
2020
const std::map<std::string, std::string>& headers,
2121
const std::map<std::string, std::string>& params,
2222
uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms,
23-
const SharedTransferHandler& handler);
23+
const SharedTransferHandler& handler,
24+
const std::string& ca_location = "");
2425

2526
FileUploadTask(const std::string& full_url,
2627
const std::map<std::string, std::string>& headers,
2728
const std::map<std::string, std::string>& params,
2829
uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms,
29-
unsigned char* pbuf = NULL, const size_t data_len = 0);
30+
unsigned char* pbuf = NULL, const size_t data_len = 0,
31+
const std::string& ca_location = "");
3032

3133
~FileUploadTask() {}
3234

@@ -66,6 +68,8 @@ class FileUploadTask : public Poco::Runnable {
6668

6769
uint64_t GetPartNumber() const { return m_part_number; }
6870

71+
void SetCaLocation(const std::string& ca_location);
72+
6973
private:
7074
std::string m_full_url;
7175
std::map<std::string, std::string> m_headers;
@@ -83,6 +87,8 @@ class FileUploadTask : public Poco::Runnable {
8387
std::string m_resume_etag;
8488
uint64_t m_part_number;
8589
SharedTransferHandler m_handler;
90+
91+
std::string m_ca_location;
8692
};
8793

8894
} // namespace qcloud_cos

include/op/object_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class ObjectOp : public BaseOp {
390390
const std::string& range,
391391
const std::map<std::string, std::string>& headers,
392392
const std::map<std::string, std::string>& params,
393-
FileCopyTask* task);
393+
const std::string& ca_location, FileCopyTask* task);
394394

395395
/// \brief 检查是否可以走断点下载
396396
/// \param req PutObjectByFile请求

include/request/base_req.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class BaseReq {
9090
void SetCheckCRC64(bool check_crc64) { mb_check_crc64 = check_crc64; }
9191
bool CheckCRC64() const { return mb_check_crc64; }
9292

93+
void SetCaLocation(const std::string& ca_location) { m_ca_location = ca_location; }
94+
const std::string& GetCaLocation() const { return m_ca_location; }
95+
9396
/// \brief 输出请求的header和param信息
9497
std::string DebugString() const;
9598

@@ -110,6 +113,8 @@ class BaseReq {
110113
bool m_is_https;
111114
bool mb_check_md5; // default is true
112115
bool mb_check_crc64; // default is false
116+
117+
std::string m_ca_location;
113118
};
114119

115120
} // namespace qcloud_cos

include/util/http_sender.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class HttpSender {
3030
uint64_t recv_timeout_in_ms,
3131
std::map<std::string, std::string>* resp_headers,
3232
std::string* resp_body, std::string* err_msg,
33-
bool is_check_md5 = false);
33+
bool is_check_md5 = false,
34+
const std::string& ca_location = "");
3435

3536
static int SendRequest(const SharedTransferHandler& handler,
3637
const std::string& http_method,
@@ -42,7 +43,8 @@ class HttpSender {
4243
uint64_t recv_timeout_in_ms,
4344
std::map<std::string, std::string>* resp_headers,
4445
std::ostream& resp_stream, std::string* err_msg,
45-
bool is_check_md5 = false);
46+
bool is_check_md5 = false,
47+
const std::string& ca_location = "");
4648

4749
static int SendRequest(const SharedTransferHandler& handler,
4850
const std::string& http_method,
@@ -53,7 +55,8 @@ class HttpSender {
5355
uint64_t recv_timeout_in_ms,
5456
std::map<std::string, std::string>* resp_headers,
5557
std::string* resp_body, std::string* err_msg,
56-
bool is_check_md5 = false);
58+
bool is_check_md5 = false,
59+
const std::string& ca_location = "");
5760

5861
static int SendRequest(const SharedTransferHandler& handler,
5962
const std::string& http_method,
@@ -64,7 +67,8 @@ class HttpSender {
6467
uint64_t recv_timeout_in_ms,
6568
std::map<std::string, std::string>* resp_headers,
6669
std::ostream& resp_stream, std::string* err_msg,
67-
bool is_check_md5 = false);
70+
bool is_check_md5 = false,
71+
const std::string& ca_location = "");
6872

6973
static int SendRequest(const SharedTransferHandler& handler,
7074
const std::string& http_method,
@@ -77,7 +81,8 @@ class HttpSender {
7781
std::map<std::string, std::string>* resp_headers,
7882
std::string* xml_err_str, std::ostream& resp_stream,
7983
std::string* err_msg, uint64_t* real_byte,
80-
bool is_check_md5 = false);
84+
bool is_check_md5 = false,
85+
const std::string& ca_location = "");
8186
};
8287

8388
} // namespace qcloud_cos

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "cossdk")
4040

4141
if(BUILD_SHARED_LIB)
4242
message(STATUS "Build shared lib")
43-
link_directories(${POCO_LINK_DIR}) #这一行要放到add_library前面
43+
link_directories(${POCO_LINK_DIR} ${OPENSSL_LINK_DIR}) #这一行要放到add_library前面
4444
add_library(${PROJECT_NAME}-shared SHARED ${sdk_src})
4545
include_directories(${CMAKE_SOURCE_DIR}/include/ ${POCO_INCLUDE_DIR})
46-
target_link_libraries(${PROJECT_NAME}-shared ${POCO_LIBS} ${SYSTEM_LIBS})
46+
target_link_libraries(${PROJECT_NAME}-shared ${POCO_LIBS} ${OPENSSL_LIBS} ${SYSTEM_LIBS})
4747
endif()

0 commit comments

Comments
 (0)