Skip to content

Commit e4a1aea

Browse files
committed
now sdk could store multiple regions cache entries
1 parent 61a722c commit e4a1aea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2828
-1170
lines changed

CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ ENDIF()
1919

2020
AUX_SOURCE_DIRECTORY(b64 DIR_SRCS_B64)
2121
AUX_SOURCE_DIRECTORY(cJSON DIR_SRCS_CJSON)
22+
AUX_SOURCE_DIRECTORY(hashmap DIR_SRCS_HASHMAP)
2223
AUX_SOURCE_DIRECTORY(qiniu DIR_SRCS_QINIU)
23-
MESSAGE(STATUS "Src file: ${DIR_SRCS_B64} ${DIR_SRCS_CJSON} ${DIR_SRCS_QINIU}")
24+
MESSAGE(STATUS "Src file: ${DIR_SRCS_B64} ${DIR_SRCS_CJSON} ${DIR_SRCS_HASHMAP} ${DIR_SRCS_QINIU}")
2425

2526
# 编译可执行程序
2627
# ADD_EXECUTABLE(${PROJECT_NAME} ${DIR_SRCS})
2728
# 如果要生成静态链接库
28-
ADD_LIBRARY(${PROJECT_NAME}_static STATIC ${DIR_SRCS_B64} ${DIR_SRCS_CJSON} ${DIR_SRCS_QINIU})
29+
ADD_LIBRARY(${PROJECT_NAME}_static STATIC ${DIR_SRCS_B64} ${DIR_SRCS_CJSON} ${DIR_SRCS_HASHMAP} ${DIR_SRCS_QINIU})
2930

3031
# 如果要生成动态链接库
31-
ADD_LIBRARY(${PROJECT_NAME} SHARED ${DIR_SRCS_B64} ${DIR_SRCS_CJSON} ${DIR_SRCS_QINIU})
32+
ADD_LIBRARY(${PROJECT_NAME} SHARED ${DIR_SRCS_B64} ${DIR_SRCS_CJSON} ${DIR_SRCS_HASHMAP} ${DIR_SRCS_QINIU})
3233
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
3334

3435
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

docs/README.md

+45-25
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ C-SDK 使用 [cURL](http://curl.haxx.se/) 进行网络相关操作。无论是
6868

6969
如果在项目构建过程中出现环境相关的编译错误和链接错误,请确认这些选项是否都已经正确配置,以及所依赖的库是否都已经正确的安装。
7070

71+
#### 通过 CMake 编译
72+
73+
如果想在 CMake 项目里使用 C-SDK,可以直接在 CMake 里导入 C-SDK:
74+
75+
```cmake
76+
INCLUDE(FetchContent)
77+
FetchContent_Declare(
78+
qiniu
79+
GIT_REPOSITORY https://github.com/qiniu/c-sdk.git
80+
GIT_TAG v7.7.0
81+
)
82+
FetchContent_MakeAvailable(qiniu)
83+
84+
FIND_PACKAGE(CURL REQUIRED)
85+
FIND_PACKAGE(OpenSSL REQUIRED)
86+
87+
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE qiniu m)
88+
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${CURL_LIBRARIES})
89+
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${OPENSSL_LIBRARIES})
90+
```
7191

7292
<a name="appkey"></a>
7393

@@ -146,7 +166,7 @@ void stat(Qiniu_Client* client, const char* bucket, const char* key)
146166
{
147167
Qiniu_RS_StatRet ret;
148168
Qiniu_Error err = Qiniu_RS_Stat(client, &ret, bucket, key);
149-
if (err.code != 200) {
169+
if (err.code != Qiniu_OK.code) {
150170
debug(client, err);
151171
return;
152172
}
@@ -169,7 +189,7 @@ typedef struct _Qiniu_Error {
169189
typedef struct _Qiniu_RS_StatRet {
170190
const char* hash;
171191
const char* mimeType;
172-
Qiniu_Int64 fsize;
192+
Qiniu_Int64 fsize;
173193
Qiniu_Int64 putTime;
174194
} Qiniu_RS_StatRet;
175195
```
@@ -259,7 +279,7 @@ char* upload(Qiniu_Client* client, char* uptoken, const char* key, const char* l
259279
Qiniu_Error err;
260280
Qiniu_Io_PutRet putRet;
261281
err = Qiniu_Io_PutFile(client, &putRet, uptoken, key, localFile, NULL);
262-
if (err.code != 200) {
282+
if (err.code != Qiniu_OK.code) {
263283
debug(client, err);
264284
return NULL;
265285
}
@@ -413,7 +433,7 @@ void stat(Qiniu_Client* client, const char* bucket, const char* key)
413433
{
414434
Qiniu_RS_StatRet ret;
415435
Qiniu_Error err = Qiniu_RS_Stat(client, &ret, bucket, key);
416-
if (err.code != 200) {
436+
if (err.code != Qiniu_OK.code) {
417437
debug(client, err);
418438
return;
419439
}
@@ -427,7 +447,7 @@ void stat(Qiniu_Client* client, const char* bucket, const char* key)
427447
typedef struct _Qiniu_RS_StatRet {
428448
const char* hash;
429449
const char* mimeType;
430-
Qiniu_Int64 fsize;
450+
Qiniu_Int64 fsize;
431451
Qiniu_Int64 putTime;
432452
} Qiniu_RS_StatRet;
433453
```
@@ -442,7 +462,7 @@ typedef struct _Qiniu_RS_StatRet {
442462
void delete(Qiniu_Client* client, const char* bucket, const char* key)
443463
{
444464
Qiniu_Error err = Qiniu_RS_Delete(client, bucket, key);
445-
if (err.code != 200) {
465+
if (err.code != Qiniu_OK.code) {
446466
debug(client, err);
447467
return;
448468
}
@@ -456,12 +476,12 @@ void delete(Qiniu_Client* client, const char* bucket, const char* key)
456476
复制和移动操作,需要指定源路径和目标路径。
457477

458478
```{c}
459-
void copy(Qiniu_Client* client,
460-
const char* bucketSrc, const char* keySrc,
479+
void copy(Qiniu_Client* client,
480+
const char* bucketSrc, const char* keySrc,
461481
const char* bucketDest, const char* keyDest)
462482
{
463483
Qiniu_Error err = Qiniu_RS_Copy(client, bucketSrc, keySrc, bucketDest, keyDest);
464-
if (err.code != 200) {
484+
if (err.code != Qiniu_OK.code) {
465485
debug(client, err);
466486
return;
467487
}
@@ -470,12 +490,12 @@ void copy(Qiniu_Client* client,
470490
```
471491

472492
```{c}
473-
void move(Qiniu_Client* client,
474-
const char* bucketSrc, const char* keySrc,
493+
void move(Qiniu_Client* client,
494+
const char* bucketSrc, const char* keySrc,
475495
const char* bucketDest, const char* keyDest)
476496
{
477497
Qiniu_Error err = Qiniu_RS_Move(client, bucketSrc, keySrc, bucketDest, keyDest);
478-
if (err.code != 200) {
498+
if (err.code != Qiniu_OK.code) {
479499
debug(client, err);
480500
return;
481501
}
@@ -494,7 +514,7 @@ void move(Qiniu_Client* client,
494514
调用`Qiniu_RS_BatchStat`可以批量查看多个文件的属性信息。
495515

496516
```{c}
497-
void batchStat(Qiniu_Client* client,
517+
void batchStat(Qiniu_Client* client,
498518
Qiniu_RS_EntryPath* entries, Qiniu_ItemCount entryCount)
499519
{
500520
Qiniu_RS_BatchStatRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchStatRet));
@@ -504,7 +524,7 @@ void batchStat(Qiniu_Client* client,
504524
while (curr < entryCount) {
505525
printf("\ncode: %d\n", rets[curr].code);
506526
507-
if (rets[curr].code != 200) {
527+
if (rets[curr].code != Qiniu_OK.code) {
508528
printf("error: %s\n", rets[curr].error);
509529
} else {
510530
printf("hash: %s\n", rets[curr].data.hash);
@@ -517,7 +537,7 @@ void batchStat(Qiniu_Client* client,
517537
518538
free(rets);
519539
520-
if (err.code != 200) {
540+
if (err.code != Qiniu_OK.code) {
521541
debug(client, err);
522542
return;
523543
}
@@ -551,7 +571,7 @@ typedef struct _Qiniu_RS_BatchStatRet {
551571
typedef struct _Qiniu_RS_StatRet {
552572
const char* hash;
553573
const char* mimeType;
554-
Qiniu_Int64 fsize;
574+
Qiniu_Int64 fsize;
555575
Qiniu_Int64 putTime;
556576
} Qiniu_RS_StatRet;
557577
```
@@ -563,7 +583,7 @@ typedef struct _Qiniu_RS_StatRet {
563583
调用`Qiniu_RS_BatchDelete`可以批量删除多个文件。
564584

565585
```{c}
566-
void batchDelete(Qiniu_Client* client,
586+
void batchDelete(Qiniu_Client* client,
567587
Qiniu_RS_EntryPath* entries, Qiniu_ItemCount entryCount)
568588
{
569589
Qiniu_RS_BatchItemRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchItemRet));
@@ -573,15 +593,15 @@ void batchDelete(Qiniu_Client* client,
573593
while (curr < entryCount) {
574594
printf("\ncode: %d\n", rets[curr].code);
575595
576-
if (rets[curr].code != 200) {
596+
if (rets[curr].code != Qiniu_OK.code) {
577597
printf("error: %s\n", rets[curr].error);
578598
}
579599
curr++;
580600
}
581601
582602
free(rets);
583603
584-
if (err.code != 200) {
604+
if (err.code != Qiniu_OK.code) {
585605
debug(client, err);
586606
return;
587607
}
@@ -604,7 +624,7 @@ typedef struct _Qiniu_RS_BatchItemRet {
604624
调用`Qiniu_RS_BatchCopy`可以批量复制多个文件。
605625

606626
```{c}
607-
void batchCopy(Qiniu_Client* client,
627+
void batchCopy(Qiniu_Client* client,
608628
Qiniu_RS_EntryPathPair* entryPairs, Qiniu_ItemCount entryCount)
609629
{
610630
Qiniu_RS_BatchItemRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchItemRet));
@@ -614,14 +634,14 @@ void batchCopy(Qiniu_Client* client,
614634
while (curr < entryCount) {
615635
printf("\ncode: %d\n", rets[curr].code);
616636
617-
if (rets[curr].code != 200) {
637+
if (rets[curr].code != Qiniu_OK.code) {
618638
printf("error: %s\n", rets[curr].error);
619639
}
620640
curr++;
621641
}
622642
free(rets);
623643
624-
if (err.code != 200) {
644+
if (err.code != Qiniu_OK.code) {
625645
debug(client, err);
626646
return;
627647
}
@@ -644,7 +664,7 @@ typedef struct _Qiniu_RS_EntryPathPair {
644664
批量移动和批量复制很类似,唯一的区别就是调用`Qiniu_RS_BatchMove`
645665

646666
```{c}
647-
void batchMove(Qiniu_Client* client,
667+
void batchMove(Qiniu_Client* client,
648668
Qiniu_RS_EntryPathPair* entryPairs, Qiniu_ItemCount entryCount)
649669
{
650670
Qiniu_RS_BatchItemRet* rets = calloc(entryCount, sizeof(Qiniu_RS_BatchItemRet));
@@ -654,15 +674,15 @@ void batchMove(Qiniu_Client* client,
654674
while (curr < entryCount) {
655675
printf("\ncode: %d\n", rets[curr].code);
656676
657-
if (rets[curr].code != 200) {
677+
if (rets[curr].code != Qiniu_OK.code) {
658678
printf("error: %s\n", rets[curr].error);
659679
}
660680
curr++;
661681
}
662682
663683
free(rets);
664684
665-
if (err.code != 200) {
685+
if (err.code != Qiniu_OK.code) {
666686
debug(client, err);
667687
return;
668688
}

docs/gist/client.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const char bucket[] = "a";
55

66
/* @gist debug */
7-
void debug(Qiniu_Client* client, Qiniu_Error err)
7+
void debug(Qiniu_Client *client, Qiniu_Error err)
88
{
99
printf("error code: %d, message: %s\n", err.code, err.message);
1010
printf("respose header:\n%s", Qiniu_Buffer_CStr(&client->respHeader));
@@ -13,12 +13,13 @@ void debug(Qiniu_Client* client, Qiniu_Error err)
1313
/* @endgist */
1414

1515
/* @gist upload */
16-
char* upload(Qiniu_Client* client, char* uptoken, const char* key, const char* localFile)
16+
char *upload(Qiniu_Client *client, char *uptoken, const char *key, const char *localFile)
1717
{
1818
Qiniu_Error err;
1919
Qiniu_Io_PutRet putRet;
2020
err = Qiniu_Io_PutFile(client, &putRet, uptoken, key, localFile, NULL);
21-
if (err.code != 200) {
21+
if (err.code != Qiniu_OK.code)
22+
{
2223
debug(client, err);
2324
return NULL;
2425
}
@@ -27,7 +28,7 @@ char* upload(Qiniu_Client* client, char* uptoken, const char* key, const char* l
2728
/* @endgist */
2829

2930
/* @gist simple-upload */
30-
int simple_upload(Qiniu_Client* client, char* uptoken, const char* key, const char* localFile)
31+
int simple_upload(Qiniu_Client *client, char *uptoken, const char *key, const char *localFile)
3132
{
3233
Qiniu_Error err;
3334
err = Qiniu_Io_PutFile(client, NULL, uptoken, key, localFile, NULL);
@@ -36,7 +37,7 @@ int simple_upload(Qiniu_Client* client, char* uptoken, const char* key, const ch
3637
/* @endgist */
3738

3839
/* @gist resumable-upload */
39-
int resumable_upload(Qiniu_Client* client, char* uptoken, const char* key, const char* localFile)
40+
int resumable_upload(Qiniu_Client *client, char *uptoken, const char *key, const char *localFile)
4041
{
4142
Qiniu_Error err;
4243
Qiniu_Rio_PutExtra extra;
@@ -52,13 +53,15 @@ int main()
5253
/* @gist init */
5354
Qiniu_Client client;
5455

55-
Qiniu_Global_Init(-1); /* 全局初始化函数,整个进程只需要调用一次 */
56+
Qiniu_Global_Init(-1); /* 全局初始化函数,整个进程只需要调用一次 */
5657
Qiniu_Client_InitNoAuth(&client, 1024); /* HTTP客户端初始化。HTTP客户端是线程不安全的,不要在多个线程间共用 */
58+
5759
/* @endgist */
5860

5961
/* @gist init */
60-
Qiniu_Client_Cleanup(&client); /* 每个HTTP客户端使用完后释放 */
61-
Qiniu_Global_Cleanup(); /* 全局清理函数,只需要在进程退出时调用一次 */
62+
63+
Qiniu_Client_Cleanup(&client); /* 每个HTTP客户端使用完后释放 */
64+
Qiniu_Global_Cleanup(); /* 全局清理函数,只需要在进程退出时调用一次 */
65+
6266
/* @endgist */
6367
}
64-

0 commit comments

Comments
 (0)