From 8435926d43f0b7fbaf70d1a1d16d8cb83f327ced Mon Sep 17 00:00:00 2001 From: Rong Zhou Date: Mon, 19 Aug 2024 08:05:39 +0000 Subject: [PATCH] support dora idle tasks --- CHANGELOG.md | 4 + CMakeLists.txt | 2 +- examples/fop_video_avthumb.c | 43 ++++- qiniu/base.c | 5 +- qiniu/base.h | 4 + qiniu/base_io.c | 2 +- qiniu/cdn.c | 4 +- qiniu/cdn.h | 8 + qiniu/conf.h | 8 + qiniu/emu_posix.h | 8 + qiniu/fop.c | 124 ++++++++++++-- qiniu/fop.h | 62 ++++++- qiniu/http.h | 9 +- qiniu/io.c | 2 +- qiniu/io.h | 6 +- qiniu/multipart_upload.h | 2 + qiniu/private/region.h | 5 +- qiniu/qetag.c | 8 +- qiniu/qetag.h | 34 ++-- qiniu/reader.h | 6 +- qiniu/recorder.h | 4 + qiniu/recorder_key.h | 4 + qiniu/recorder_utils.h | 4 + qiniu/region.c | 10 +- qiniu/region.h | 14 +- qiniu/resumable_io.c | 6 +- qiniu/resumable_io.h | 4 + qiniu/rfc3339.c | 319 +++++++++++++++++++++++++++++++++++ qiniu/rfc3339.h | 57 +++++++ qiniu/rs.c | 4 + qiniu/rs.h | 5 + qiniu/rsf.h | 4 + qiniu/tm.h | 8 + vcpkg.json | 2 +- 34 files changed, 719 insertions(+), 72 deletions(-) create mode 100644 qiniu/rfc3339.c create mode 100644 qiniu/rfc3339.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e01b9d3..d8f715d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGE LOG +## v7.8.0 (2024-08-20) + +- 支持闲时任务 + ## v7.7.0 (2023-12-25) - 支持归档直读存储类型 diff --git a/CMakeLists.txt b/CMakeLists.txt index 18b8ac3d..41c5b580 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ CMAKE_POLICY(SET CMP0074 NEW) SET(PROJECT_NAME qiniu) # 建立项目 -PROJECT(${PROJECT_NAME} VERSION 7.7.0 LANGUAGES C) +PROJECT(${PROJECT_NAME} VERSION 7.8.0 LANGUAGES C) set(CMAKE_C_STANDARD 99) diff --git a/examples/fop_video_avthumb.c b/examples/fop_video_avthumb.c index 36857c14..8a41f9cc 100644 --- a/examples/fop_video_avthumb.c +++ b/examples/fop_video_avthumb.c @@ -43,7 +43,16 @@ int main(int argc, char **argv) { char *fops[] = {avthumbMp4Fop, vframeJpgFop}; - Qiniu_Error error = Qiniu_FOP_Pfop(&client, &pfopRet, bucket, key, fops, 2, pipeline, notifyURL, force); + Qiniu_FOP_PfopParams params = { + .bucket = bucket, + .key = key, + .pipeline = pipeline, + .notifyURL = notifyURL, + .fops = fops, + .fopCount = 2, + .force = force, + }; + Qiniu_Error error = Qiniu_FOP_Pfop_v2(&client, &pfopRet, ¶ms); if (error.code != 200) { printf("video file pfop %s:%s error.\n", bucket, key); debug_log(&client, error); @@ -52,7 +61,37 @@ int main(int argc, char **argv) { printf("video file pfop %s:%s success, persistentId: %s .\n\n", bucket, key, pfopRet.persistentId); } + Qiniu_FOP_PrefopRet prefopRet; + Qiniu_FOP_PrefopItemRet prefopItemRet[2]; + Qiniu_ItemCount itemsCount; + error = Qiniu_FOP_Prefop(&client, &prefopRet, (Qiniu_FOP_PrefopItemRet *)&prefopItemRet, &itemsCount, pfopRet.persistentId, 2); + if (error.code != 200) + { + debug_log(&client, error); + } + else + { + printf("ID: %s\n", prefopRet.id); + printf("Code: %d\n", prefopRet.code); + printf("Desc: %s\n", prefopRet.desc); + printf("InputBucket: %s\n", prefopRet.inputBucket); + printf("InputKey: %s\n", prefopRet.inputKey); + printf("Type: %d\n", prefopRet.type); + + for (Qiniu_ItemCount i = 0; i < itemsCount; i++) + { + printf("\tIndex: %d\n", i); + printf("\tCmd: %s\n", prefopItemRet[i].cmd); + printf("\tCode: %d\n", prefopItemRet[i].code); + printf("\tDesc: %s\n", prefopItemRet[i].desc); + printf("\tError: %s\n", prefopItemRet[i].error); + printf("\tHash: %s\n", prefopItemRet[i].hash); + printf("\tKey: %s\n", prefopItemRet[i].key); + printf("\tReturnOld: %d\n", prefopItemRet[i].returnOld); + } + } + Qiniu_Free(avthumbMp4Fop); Qiniu_Free(vframeJpgFop); Qiniu_Client_Cleanup(&client); -} \ No newline at end of file +} diff --git a/qiniu/base.c b/qiniu/base.c index 76b1f313..00adda91 100644 --- a/qiniu/base.c +++ b/qiniu/base.c @@ -130,7 +130,7 @@ static char *Qiniu_escape(const char *s, escapeMode mode, Qiniu_Bool *fesc) { int spaceCount = 0; int hexCount = 0; - int i, j, len = strlen(s); + size_t i, j, len = strlen(s); int c; char *t; @@ -674,8 +674,7 @@ Qiniu_Writer Qiniu_FILE_Writer(FILE *fp) /*============================================================================*/ /* func Qiniu_Copy */ -Qiniu_Error Qiniu_OK = { - 200, "OK"}; +Qiniu_Error Qiniu_OK = {200, "OK"}; Qiniu_Error Qiniu_Copy(Qiniu_Writer w, Qiniu_Reader r, void *buf, size_t n, Qiniu_Int64 *ret) { diff --git a/qiniu/base.h b/qiniu/base.h index e57cac61..d3d85875 100644 --- a/qiniu/base.h +++ b/qiniu/base.h @@ -43,7 +43,9 @@ typedef off_t Qiniu_Off_T; #endif +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -357,7 +359,9 @@ typedef struct stat Qiniu_FileInfo; /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/base_io.c b/qiniu/base_io.c index 42ea25e3..572fef29 100644 --- a/qiniu/base_io.c +++ b/qiniu/base_io.c @@ -135,7 +135,7 @@ static ssize_t Qiniu_ReadBuf_ReadAt(Qiniu_ReadBuf *self, void *buf, size_t n, Qi n = max & (~(size_t)0L); } memcpy(buf, self->buf + off, n); - return n; + return (ssize_t)n; } Qiniu_Reader Qiniu_BufReader(Qiniu_ReadBuf *self, const char *buf, size_t bytes) diff --git a/qiniu/cdn.c b/qiniu/cdn.c index fa74dce9..13d932a8 100644 --- a/qiniu/cdn.c +++ b/qiniu/cdn.c @@ -13,7 +13,7 @@ char *Qiniu_CDN_CreateTimestampAntiLeechURL(const char *host, const char *fileNa char *queryStrEscaped = NULL; char expireHex[20]; - sprintf(expireHex, "%0llx", deadline); + snprintf(expireHex, 20, "%0llx", deadline); if (queryStr != NULL && strcmp("", queryStr) != 0) { queryStrEscaped = Qiniu_PathEscape(queryStr, &queryStrEscapeOk); @@ -611,4 +611,4 @@ void Qiniu_Free_CDNLogListRet(Qiniu_CDN_LogListRet *ret) { } Qiniu_Free(ret->data); } -} \ No newline at end of file +} diff --git a/qiniu/cdn.h b/qiniu/cdn.h index efd17924..1a883333 100644 --- a/qiniu/cdn.h +++ b/qiniu/cdn.h @@ -14,6 +14,10 @@ #include "macro.h" #include "http.h" +#if defined(_WIN32) +#pragma pack(1) +#endif + #ifdef __cplusplus extern "C" { @@ -164,6 +168,10 @@ QINIU_DLLAPI extern void Qiniu_Free_CDNLogListRet(Qiniu_CDN_LogListRet *ret); //===================================================================== +#if defined(_WIN32) +#pragma pack() +#endif + #ifdef __cplusplus } #endif diff --git a/qiniu/conf.h b/qiniu/conf.h index b8aaba60..f662d530 100644 --- a/qiniu/conf.h +++ b/qiniu/conf.h @@ -13,6 +13,10 @@ #include "macro.h" #include "base.h" +#if defined(_WIN32) +#pragma pack(1) +#endif + #ifdef __cplusplus extern "C" { @@ -64,6 +68,10 @@ extern "C" // 不再推荐使用,建议使用 Qiniu_Use_Region("cn-east-2") 方法替代 QINIU_DLLAPI extern void Qiniu_Use_Zone_Cn_East_2(Qiniu_Bool useHttps); +#if defined(_WIN32) +#pragma pack() +#endif + #ifdef __cplusplus } #endif diff --git a/qiniu/emu_posix.h b/qiniu/emu_posix.h index 5580865a..fee1acff 100644 --- a/qiniu/emu_posix.h +++ b/qiniu/emu_posix.h @@ -14,6 +14,10 @@ #include "macro.h" +#if defined(_WIN32) +#pragma pack(1) +#endif + #ifdef __cplusplus extern "C" { @@ -51,6 +55,10 @@ QINIU_DLLAPI extern char* Qiniu_Posix_strndup(const char *, size_t n); /*============================================================================*/ +#if defined(_WIN32) +#pragma pack() +#endif + #ifdef __cplusplus } #endif diff --git a/qiniu/fop.c b/qiniu/fop.c index 3fdefe90..2303c3a3 100644 --- a/qiniu/fop.c +++ b/qiniu/fop.c @@ -13,8 +13,9 @@ #include "private/region.h" #include "../cJSON/cJSON.h" -Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const char *bucket, const char *key, - char *fops[], int fopCount, const char *pipeline, const char *notifyURL, int force) +void _Qiniu_Parse_Date_Time(char *datetime_string, Qiniu_DateTime *dt); + +Qiniu_Error Qiniu_FOP_Pfop_v2(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, Qiniu_FOP_PfopParams *params) { Qiniu_Error err; cJSON *root; @@ -25,6 +26,7 @@ Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const cha char *encodedNotifyURL = NULL; char *encodedPipeline = NULL; char *forceStr = NULL; + char *typeStr = NULL; char *url = NULL; char *body = NULL; Qiniu_Bool escapeBucketOk; @@ -34,29 +36,29 @@ Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const cha Qiniu_Bool escapeNotifyURLOk; // Add encoded bucket - encodedBucket = Qiniu_QueryEscape(bucket, &escapeBucketOk); - encodedKey = Qiniu_QueryEscape(key, &escapeKeyOk); - fopsStr = Qiniu_String_Join(";", fops, fopCount); + encodedBucket = Qiniu_QueryEscape(params->bucket, &escapeBucketOk); + encodedKey = Qiniu_QueryEscape(params->key, &escapeKeyOk); + fopsStr = Qiniu_String_Join(";", params->fops, params->fopCount); encodedFops = Qiniu_QueryEscape(fopsStr, &escapeFopsOk); Qiniu_Free(fopsStr); - if (pipeline) + if (params->pipeline) { - encodedPipeline = Qiniu_QueryEscape(pipeline, &escapePipelineOk); + encodedPipeline = Qiniu_QueryEscape(params->pipeline, &escapePipelineOk); } else { encodedPipeline = ""; } - if (notifyURL) + if (params->notifyURL) { - encodedNotifyURL = Qiniu_QueryEscape(notifyURL, &escapeNotifyURLOk); + encodedNotifyURL = Qiniu_QueryEscape(params->notifyURL, &escapeNotifyURLOk); } else { encodedNotifyURL = ""; } - if (force == 1) + if (params->force == 1) { forceStr = "1"; } @@ -64,9 +66,18 @@ Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const cha { forceStr = "0"; } + if (params->type == 1) + { + typeStr = "1"; + } + else + { + typeStr = "0"; + } body = Qiniu_String_Concat("bucket=", encodedBucket, "&key=", encodedKey, "&fops=", encodedFops, - "&pipeline=", encodedPipeline, "¬ifyURL=", encodedNotifyURL, "&force=", forceStr, NULL); + "&pipeline=", encodedPipeline, "¬ifyURL=", encodedNotifyURL, "&force=", forceStr, + "&type=", typeStr, NULL); if (escapeBucketOk) { Qiniu_Free(encodedBucket); @@ -82,23 +93,22 @@ Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const cha Qiniu_Free(encodedFops); } - if (pipeline && escapePipelineOk) + if (params->pipeline && escapePipelineOk) { Qiniu_Free(encodedPipeline); } - if (notifyURL && escapeNotifyURLOk) + if (params->notifyURL && escapeNotifyURLOk) { Qiniu_Free(encodedNotifyURL); } const char *apiHost; - err = _Qiniu_Region_Get_Api_Host(self, NULL, bucket, &apiHost); + err = _Qiniu_Region_Get_Api_Host(self, NULL, NULL, &apiHost); if (err.code != 200) { goto error; } - url = Qiniu_String_Concat2(apiHost, "/pfop/"); err = Qiniu_Client_CallWithBuffer( self, @@ -116,4 +126,88 @@ Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const cha Qiniu_Free(body); Qiniu_Free(url); return err; +} + +Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const char *bucket, const char *key, + char *fops[], int fopCount, const char *pipeline, const char *notifyURL, int force) +{ + Qiniu_FOP_PfopParams params; + Qiniu_Zero(params); + params.bucket = bucket; + params.key = key; + params.fops = (char **)fops; + params.fopCount = fopCount; + params.pipeline = pipeline; + params.notifyURL = notifyURL; + params.force = force; + return Qiniu_FOP_Pfop_v2(self, ret, ¶ms); } // Qiniu_FOP_Pfop + +Qiniu_Error Qiniu_FOP_Prefop(Qiniu_Client *self, Qiniu_FOP_PrefopRet *ret, Qiniu_FOP_PrefopItemRet *itemsRet, Qiniu_ItemCount *itemsCount, const char *persistentId, Qiniu_ItemCount maxItemsCount) +{ + Qiniu_Error err; + cJSON *root, *items, *item; + Qiniu_ItemCount curIndex; + char *encodedPersistentId = NULL, *url = NULL, *creationDateStr = NULL; + Qiniu_ReadBuf emptyBodyBuf = {NULL, 0, 0}; + Qiniu_Reader emptyBody = Qiniu_BufReader(&emptyBodyBuf, 0, 0); + Qiniu_Bool escapePersistentIdOk; + + encodedPersistentId = Qiniu_QueryEscape(persistentId, &escapePersistentIdOk); + + const char *apiHost; + err = _Qiniu_Region_Get_Api_Host(self, NULL, NULL, &apiHost); + if (err.code != 200) + { + goto error; + } + url = Qiniu_String_Concat(apiHost, "/status/get/prefop?id=", encodedPersistentId, NULL); + if (escapePersistentIdOk) + { + Qiniu_Free(encodedPersistentId); + } + + err = Qiniu_Client_CallWithMethod( + self, + &root, + url, + emptyBody, + 0, + "application/x-www-form-urlencoded", + "GET", + NULL); + if (err.code != 200) + { + goto error; + } + + ret->id = Qiniu_Json_GetString(root, "id", NULL); + ret->code = Qiniu_Json_GetInt(root, "code", 0); + ret->desc = Qiniu_Json_GetString(root, "desc", NULL); + ret->inputBucket = Qiniu_Json_GetString(root, "inputBucket", NULL); + ret->inputKey = Qiniu_Json_GetString(root, "inputBucket", NULL); + ret->type = Qiniu_Json_GetInt(root, "type", 0); + creationDateStr = (char *)Qiniu_Json_GetString(root, "creationDate", NULL); + if (creationDateStr != NULL) + { + _Qiniu_Parse_Date_Time(creationDateStr, &ret->creationDate); + } + + *itemsCount = Qiniu_Json_GetArraySize(root, "items", 0); + items = Qiniu_Json_GetObjectItem(root, "items", 0); + for (curIndex = 0; curIndex < *itemsCount && curIndex < maxItemsCount; curIndex++) + { + item = cJSON_GetArrayItem(items, curIndex); + itemsRet[curIndex].cmd = Qiniu_Json_GetString(item, "cmd", NULL); + itemsRet[curIndex].code = Qiniu_Json_GetInt(item, "code", 0); + itemsRet[curIndex].desc = Qiniu_Json_GetString(item, "desc", NULL); + itemsRet[curIndex].error = Qiniu_Json_GetString(item, "error", NULL); + itemsRet[curIndex].hash = Qiniu_Json_GetString(item, "hash", NULL); + itemsRet[curIndex].key = Qiniu_Json_GetString(item, "key", NULL); + itemsRet[curIndex].returnOld = Qiniu_Json_GetInt(item, "returnOld", 0); + } + +error: + Qiniu_Free(url); + return err; +} diff --git a/qiniu/fop.h b/qiniu/fop.h index 9300671f..27d4554d 100644 --- a/qiniu/fop.h +++ b/qiniu/fop.h @@ -3,16 +3,19 @@ Name : fop.h Author : Qiniu.com Copyright : 2012(c) Shanghai Qiniu Information Technologies Co., Ltd. - Description : + Description : ============================================================================ */ #ifndef QINIU_FOP_H #define QINIU_FOP_H -#include "http.h" +#include "rs.h" +#include "rfc3339.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -22,6 +25,22 @@ extern "C" /*============================================================================*/ /* func Qiniu_FOP_Pfop */ +/* @gist pfop */ + +typedef struct _Qiniu_FOP_PfopParams +{ + const char *bucket; + const char *key; + const char *pipeline; + const char *notifyURL; + char **fops; + int fopCount; + int force; + int type; +} Qiniu_FOP_PfopParams; + +/* @endgist */ + /* @gist pfopret */ typedef struct _Qiniu_FOP_PfopRet { @@ -30,13 +49,46 @@ typedef struct _Qiniu_FOP_PfopRet { /* @endgist */ -QINIU_DLLAPI extern Qiniu_Error Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const char *bucket, - const char *key, char *fops[], int fopCount, const char *pipeline, - const char *notifyURL, int force); +/* @gist prefopret */ + +typedef struct _Qiniu_FOP_PrefopRet +{ + const char *id; + const char *desc; + const char *inputBucket; + const char *inputKey; + int code; + int type; + Qiniu_DateTime creationDate; +} Qiniu_FOP_PrefopRet; + +typedef struct _Qiniu_FOP_PrefopItemRet +{ + const char *cmd; + const char *desc; + const char *error; + const char *hash; + const char *key; + int code; + int returnOld; +} Qiniu_FOP_PrefopItemRet; + +/* @endgist */ + +QINIU_DLLAPI extern Qiniu_Error +Qiniu_FOP_Pfop(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, const char *bucket, + const char *key, char *fops[], int fopCount, const char *pipeline, + const char *notifyURL, int force); +QINIU_DLLAPI extern Qiniu_Error Qiniu_FOP_Pfop_v2(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, Qiniu_FOP_PfopParams *params); +QINIU_DLLAPI extern Qiniu_Error +Qiniu_FOP_Prefop(Qiniu_Client *self, Qiniu_FOP_PrefopRet *ret, Qiniu_FOP_PrefopItemRet *itemsRet, + Qiniu_ItemCount *itemsCount, const char *persistentId, Qiniu_ItemCount maxItemsCount); /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/http.h b/qiniu/http.h index 240082b1..d7fd7766 100644 --- a/qiniu/http.h +++ b/qiniu/http.h @@ -79,7 +79,9 @@ extern "C" /*============================================================================*/ /* type Qiniu_Auth */ +#if defined(_WIN32) #pragma pack(1) +#endif typedef struct curl_slist Qiniu_Header; @@ -106,7 +108,7 @@ extern "C" typedef struct _Qiniu_Region Qiniu_Region; QINIU_DLLAPI extern void Qiniu_Region_Free(Qiniu_Region *region); - struct _Qiniu_Client + typedef struct _Qiniu_Client { void *curl; Qiniu_Auth auth; @@ -138,8 +140,7 @@ extern "C" // Millisecond timeout for the connection phase. long connectTimeoutMs; - }; - typedef struct _Qiniu_Client Qiniu_Client; + } Qiniu_Client; QINIU_DLLAPI extern void Qiniu_Client_InitEx(Qiniu_Client *self, Qiniu_Auth auth, size_t bufSize); QINIU_DLLAPI extern void Qiniu_Client_Cleanup(Qiniu_Client *self); @@ -185,7 +186,9 @@ extern "C" /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/io.c b/qiniu/io.c index 31ea14e2..b024b115 100644 --- a/qiniu/io.c +++ b/qiniu/io.c @@ -63,7 +63,7 @@ static Qiniu_Error Get_Qiniu_UpHost(Qiniu_Client *client, const char *accessKey, if (extra && extra->ipCount != 0) { Qiniu_Count oldIndex = Qiniu_Count_Inc(&extra->ipIndex); - *upHost = extra->upIps[abs(oldIndex % extra->ipCount)]; + *upHost = extra->upIps[labs(oldIndex % extra->ipCount)]; } else if (extra && extra->upHost != NULL) { diff --git a/qiniu/io.h b/qiniu/io.h index 2329bcaa..c583cd82 100644 --- a/qiniu/io.h +++ b/qiniu/io.h @@ -3,7 +3,7 @@ Name : io.h Author : Qiniu.com Copyright : 2012(c) Shanghai Qiniu Information Technologies Co., Ltd. - Description : + Description : ============================================================================ */ @@ -13,7 +13,9 @@ #include "http.h" #include "reader.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -98,7 +100,9 @@ extern "C" void *self, Qiniu_Header **header, const char *url, const char *addition, size_t addlen); /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/multipart_upload.h b/qiniu/multipart_upload.h index 3d265ca7..49394b3a 100644 --- a/qiniu/multipart_upload.h +++ b/qiniu/multipart_upload.h @@ -17,7 +17,9 @@ #include "stdio.h" #include "recorder.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" diff --git a/qiniu/private/region.h b/qiniu/private/region.h index 8a5cc465..1e496e8d 100644 --- a/qiniu/private/region.h +++ b/qiniu/private/region.h @@ -1,16 +1,13 @@ #ifndef QINIU_PRIVATE_REGION_H #define QINIU_PRIVATE_REGION_H #include -#include "../base.h" +#include "../http.h" #ifdef __cplusplus extern "C" { #endif - struct _Qiniu_Client; - typedef struct _Qiniu_Client Qiniu_Client; - struct _Qiniu_Region_Hosts { const char *const *hosts; diff --git a/qiniu/qetag.c b/qiniu/qetag.c index 9e9bcaa5..5a87823e 100644 --- a/qiniu/qetag.c +++ b/qiniu/qetag.c @@ -10,7 +10,9 @@ extern "C" { #endif +#if defined(_WIN32) #pragma pack(1) +#endif #define BLOCK_ELEMENT_MAX_COUNT 16 #define BLOCK_MAX_SIZE (1 << 22) @@ -60,7 +62,7 @@ static Qiniu_Error Qiniu_Qetag_mergeBlocks(struct _Qiniu_Qetag_Context * ctx) { } blk->done = NO; - + ctx->blkBegin += 1; if (ctx->blkBegin >= ctx->blkElementCount) { ctx->blkBegin = 0; @@ -266,7 +268,7 @@ Qiniu_Error Qiniu_Qetag_Final(struct _Qiniu_Qetag_Context * ctx, char ** digest) Qiniu_Error Qiniu_Qetag_AllocateBlock(struct _Qiniu_Qetag_Context * ctx, struct _Qiniu_Qetag_Block ** blk, size_t * remainderSize) { Qiniu_Error err; - + if (ctx->blk) { *blk = ctx->blk; ctx->blk = NULL; @@ -394,7 +396,9 @@ Qiniu_Error Qiniu_Qetag_DigestBuffer(const char * buf, size_t bufSize, char ** d return err; } // Qiniu_Qetag_DigestBuffer +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/qetag.h b/qiniu/qetag.h index 165b8821..ef12ed99 100644 --- a/qiniu/qetag.h +++ b/qiniu/qetag.h @@ -3,7 +3,7 @@ Name : qetag.h Author : Qiniu.com Copyright : 2012(c) Shanghai Qiniu Information Technologies Co., Ltd. - Description : + Description : ============================================================================ */ @@ -18,27 +18,31 @@ extern "C" { #endif +#if defined(_WIN32) #pragma pack(1) +#endif -struct _Qiniu_Qetag_Context; -struct _Qiniu_Qetag_Block; + struct _Qiniu_Qetag_Context; + struct _Qiniu_Qetag_Block; -// 底层函数 -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_New(struct _Qiniu_Qetag_Context ** ctx, unsigned int concurrency); -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_Reset(struct _Qiniu_Qetag_Context * ctx); -QINIU_DLLAPI extern void Qiniu_Qetag_Destroy(struct _Qiniu_Qetag_Context * ctx); -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_Update(struct _Qiniu_Qetag_Context * ctx, const char * buf, size_t bufSize); -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_Final(struct _Qiniu_Qetag_Context * ctx, char ** digest); + // 底层函数 + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_New(struct _Qiniu_Qetag_Context **ctx, unsigned int concurrency); + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_Reset(struct _Qiniu_Qetag_Context *ctx); + QINIU_DLLAPI extern void Qiniu_Qetag_Destroy(struct _Qiniu_Qetag_Context *ctx); + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_Update(struct _Qiniu_Qetag_Context *ctx, const char *buf, size_t bufSize); + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_Final(struct _Qiniu_Qetag_Context *ctx, char **digest); -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_AllocateBlock(struct _Qiniu_Qetag_Context * ctx, struct _Qiniu_Qetag_Block ** blk, size_t * blkCapacity); -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_UpdateBlock(struct _Qiniu_Qetag_Block * blk, const char * buf, size_t bufSize, size_t * blkCapacity); -QINIU_DLLAPI extern void Qiniu_Qetag_CommitBlock(struct _Qiniu_Qetag_Context * ctx, struct _Qiniu_Qetag_Block * blk); + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_AllocateBlock(struct _Qiniu_Qetag_Context *ctx, struct _Qiniu_Qetag_Block **blk, size_t *blkCapacity); + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_UpdateBlock(struct _Qiniu_Qetag_Block *blk, const char *buf, size_t bufSize, size_t *blkCapacity); + QINIU_DLLAPI extern void Qiniu_Qetag_CommitBlock(struct _Qiniu_Qetag_Context *ctx, struct _Qiniu_Qetag_Block *blk); -// 单线程计算 QETAG -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_DigestFile(const char * localFile, char ** digest); -QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_DigestBuffer(const char * buf, size_t fsize, char ** digest); + // 单线程计算 QETAG + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_DigestFile(const char *localFile, char **digest); + QINIU_DLLAPI extern Qiniu_Error Qiniu_Qetag_DigestBuffer(const char *buf, size_t fsize, char **digest); +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/reader.h b/qiniu/reader.h index 8515475f..2a07f5ca 100644 --- a/qiniu/reader.h +++ b/qiniu/reader.h @@ -3,7 +3,7 @@ Name : reader.h Author : Qiniu.com Copyright : 2012-2016(c) Shanghai Qiniu Information Technologies Co., Ltd. - Description : + Description : ============================================================================ */ @@ -12,7 +12,9 @@ #include "base.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -47,7 +49,9 @@ QINIU_DLLAPI extern void Qiniu_Rd_Reader_Close(Qiniu_Rd_Reader * rdr); QINIU_DLLAPI extern size_t Qiniu_Rd_Reader_Callback(char * buffer, size_t size, size_t nitems, void * rdr); +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/recorder.h b/qiniu/recorder.h index 08ae4fe0..49698b32 100644 --- a/qiniu/recorder.h +++ b/qiniu/recorder.h @@ -14,7 +14,9 @@ #define Qiniu_Recorder_Read_Error 9801 #define Qiniu_Recorder_Write_Error 9802 +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -45,7 +47,9 @@ extern "C" QINIU_DLLAPI extern Qiniu_Error Qiniu_FileSystem_Recorder_New(const char *rootPath, struct Qiniu_Recorder *recorder); /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/recorder_key.h b/qiniu/recorder_key.h index a7f56602..c5d10e55 100644 --- a/qiniu/recorder_key.h +++ b/qiniu/recorder_key.h @@ -13,7 +13,9 @@ #include "base.h" #include "private/crypto.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -36,7 +38,9 @@ QINIU_DLLAPI extern void Qiniu_Recorder_Key_Generator_Free(Qiniu_Recorder_Key_Ge /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/recorder_utils.h b/qiniu/recorder_utils.h index a8623805..4b717f46 100644 --- a/qiniu/recorder_utils.h +++ b/qiniu/recorder_utils.h @@ -13,7 +13,9 @@ #include "base.h" #include "recorder.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -29,7 +31,9 @@ extern "C" /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/region.c b/qiniu/region.c index 821a69b5..379af08f 100644 --- a/qiniu/region.c +++ b/qiniu/region.c @@ -1216,7 +1216,7 @@ Qiniu_Error _Qiniu_Region_Get_Up_Host(Qiniu_Client *self, const char *accessKey, foundRegion = &self->specifiedRegion; goto foundCache; } - else if (self->autoQueryRegion) + else if (self->autoQueryRegion && bucketName != NULL) { if (self->cachedRegion != NULL) { @@ -1268,7 +1268,7 @@ Qiniu_Error _Qiniu_Region_Get_Io_Host(Qiniu_Client *self, const char *accessKey, foundRegion = &self->specifiedRegion; goto foundCache; } - else if (self->autoQueryRegion) + else if (self->autoQueryRegion && bucketName != NULL) { if (self->cachedRegion != NULL) { @@ -1320,7 +1320,7 @@ Qiniu_Error _Qiniu_Region_Get_Rs_Host(Qiniu_Client *self, const char *accessKey, foundRegion = &self->specifiedRegion; goto foundCache; } - else if (self->autoQueryRegion) + else if (self->autoQueryRegion && bucketName != NULL) { if (self->cachedRegion != NULL) { @@ -1372,7 +1372,7 @@ Qiniu_Error _Qiniu_Region_Get_Rsf_Host(Qiniu_Client *self, const char *accessKey foundRegion = &self->specifiedRegion; goto foundCache; } - else if (self->autoQueryRegion) + else if (self->autoQueryRegion && bucketName != NULL) { if (self->cachedRegion != NULL) { @@ -1424,7 +1424,7 @@ Qiniu_Error _Qiniu_Region_Get_Api_Host(Qiniu_Client *self, const char *accessKey foundRegion = &self->specifiedRegion; goto foundCache; } - else if (self->autoQueryRegion) + else if (self->autoQueryRegion && bucketName != NULL) { if (self->cachedRegion != NULL) { diff --git a/qiniu/region.h b/qiniu/region.h index 9d3d0194..bcc6888c 100644 --- a/qiniu/region.h +++ b/qiniu/region.h @@ -11,17 +11,15 @@ #define QINIU_REGION_H #include "http.h" +#if defined(_WIN32) +#pragma pack(1) +#endif + #ifdef __cplusplus extern "C" { #endif - struct _Qiniu_Client; - typedef struct _Qiniu_Client Qiniu_Client; - - struct _Qiniu_Region; - typedef struct _Qiniu_Region Qiniu_Region; - QINIU_DLLAPI extern const char *const *Qiniu_Region_Get_Up_Preferred_Hosts(Qiniu_Region *region, size_t *count); QINIU_DLLAPI extern const char *const *Qiniu_Region_Get_Up_Alternative_Hosts(Qiniu_Region *region, size_t *count); QINIU_DLLAPI extern const char *const *Qiniu_Region_Get_Io_Preferred_Hosts(Qiniu_Region *region, size_t *count); @@ -60,6 +58,10 @@ extern "C" QINIU_DLLAPI extern Qiniu_Region *Qiniu_Use_Region(const char *const regionId, Qiniu_Bool useHttps); QINIU_DLLAPI extern Qiniu_Error Qiniu_Region_Query(Qiniu_Client *self, Qiniu_Region **region, const char *const bucketName, Qiniu_Bool useHttps); +#if defined(_WIN32) +#pragma pack() +#endif + #ifdef __cplusplus } #endif diff --git a/qiniu/resumable_io.c b/qiniu/resumable_io.c index e916c458..074334b0 100644 --- a/qiniu/resumable_io.c +++ b/qiniu/resumable_io.c @@ -740,10 +740,8 @@ static void Qiniu_Rio_doTask(void *params) /*============================================================================*/ /* func Qiniu_Rio_PutXXX */ -static Qiniu_Error ErrPutFailed = { - Qiniu_Rio_PutFailed, "resumable put failed"}; -static Qiniu_Error ErrPutInterrupted = { - Qiniu_Rio_PutInterrupted, "resumable put interrupted"}; +static Qiniu_Error ErrPutFailed; +static Qiniu_Error ErrPutInterrupted; static Qiniu_Error Qiniu_Rio_loadProgresses(Qiniu_Rio_PutRet *ret, Qiniu_Rio_PutExtra *extra, Qiniu_Rio_Recorder *recorder) { diff --git a/qiniu/resumable_io.h b/qiniu/resumable_io.h index a1efacf7..9a4073da 100644 --- a/qiniu/resumable_io.h +++ b/qiniu/resumable_io.h @@ -14,7 +14,9 @@ #include "io.h" #include "recorder.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -166,7 +168,9 @@ extern "C" /*============================================================================*/ +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/rfc3339.c b/qiniu/rfc3339.c new file mode 100644 index 00000000..39e42a74 --- /dev/null +++ b/qiniu/rfc3339.c @@ -0,0 +1,319 @@ +#include "rfc3339.h" + +static void _Strip_Spaces(char *source) +{ + char *i = source; + + while (*source != 0) + { + *i = *source++; + if (*i != ' ') + i++; + } + + *i = 0; +} + +static void _Qiniu_Parse_Date(char *date_string, Qiniu_Date *d) +{ + char *const tokens = strdup(date_string); + _Strip_Spaces(tokens); + d->ok = 0; + + if (strlen(tokens) < 10) + { + return; + } + + int status = sscanf( + tokens, "%04d-%02d-%02d", &(d->year), &(d->month), &(d->day)); + free((char *)tokens); + + if (status != 3) + { + return; + } + if (d->year < 1 || d->year > 9999) + { + return; + } + if (d->month < 1 || d->month > 12) + { + return; + } + if (d->day < 1 || d->day > 31) + { + return; + } + + unsigned int leap = (d->year % 4 == 0) && + (d->year % 100 || (d->year % 400 == 0)); + + switch (d->month) + { + case 1: + if (d->day > 31) + { + return; + } + break; + case 2: + if (leap > 0) + { + if (d->day > 29) + { + return; + } + } + else + { + if (d->day > 28) + { + return; + } + } + break; + case 3: + if (d->day > 31) + { + return; + } + break; + case 4: + if (d->day > 30) + { + return; + } + break; + case 5: + if (d->day > 31) + { + return; + } + break; + case 6: + if (d->day > 30) + { + return; + } + break; + case 7: + if (d->day > 31) + { + return; + } + break; + case 8: + if (d->day > 31) + { + return; + } + break; + case 9: + if (d->day > 30) + { + return; + } + break; + case 10: + if (d->day > 31) + { + return; + } + break; + case 11: + if (d->day > 30) + { + return; + } + break; + case 12: + if (d->day > 31) + { + return; + } + break; + } + + d->ok = 1; +} + +static void _Qiniu_Parse_Time(char *time_string, Qiniu_Time *t) +{ + char *tokens = strdup(time_string); + char *token_ptr = tokens; + + _Strip_Spaces(tokens); + + t->ok = 0; + + if (strlen(tokens) < 8) + { + goto cleanup; + } + + if ((strlen(tokens) > 11) && ((*(tokens + 10) == 'T') || (*(tokens + 10) == 't'))) + { + tokens += 11; + } + + int status = sscanf( + tokens, "%02d:%02d:%02d", &(t->hour), &(t->minute), &(t->second)); + + if (status != 3) + { + goto cleanup; + } + if (t->hour < 0 || t->hour > 23) + { + goto cleanup; + } + if (t->minute < 0 || t->minute > 59) + { + goto cleanup; + } + if (t->second < 0 || t->second > 59) + { + goto cleanup; + } + + if (strlen(tokens) == 8) + { + t->offset = 0; + t->ok = 1; + goto cleanup; + } + else + { + tokens += 8; + } + + if (*tokens == '.') + { + tokens++; + char fractions[7] = {0}; + + for (unsigned int i = 0; i < 6; i++) + { + if ((*(tokens + i) >= 48) && (*(tokens + i) <= 57)) + { + fractions[i] = *(tokens + i); + } + else + { + break; + } + } + + status = sscanf(fractions, "%d", &(t->fraction)); + + if (strlen(fractions) < 6 && strlen(fractions) > 0) + { + t->fraction = t->fraction * pow(10, 6 - strlen(fractions)); // convert msec to usec + } + else if (strlen(fractions) == 6) + { + // all fine, already in usec + } + else + { + // Invalid fractions must be msec or usec + goto cleanup; + } + + if (status != 1) + { + goto cleanup; + } + if (t->fraction < 0 || t->fraction > 999999) + { + goto cleanup; + } + + tokens += strlen(fractions); + + if (strlen(tokens) == 0) + { + t->offset = 0; + t->ok = 1; + goto cleanup; + } + } + + if ((*tokens == 'Z') || (*tokens == 'z')) + { + t->offset = 0; + + tokens++; + if (strlen(tokens) == 0) + { + t->ok = 1; + } + else + { + t->ok = 0; + } + goto cleanup; + } + else if ((*tokens == '+') || (*tokens == '-')) + { + unsigned int tz_hour, tz_minute; + + status = sscanf(tokens + 1, "%02d:%02d", &tz_hour, &tz_minute); + + if (status != 2) + { + goto cleanup; + } + if ((tz_hour < 0) || (tz_hour > 23)) + { + goto cleanup; + } + if ((tz_minute < 0) || (tz_minute > 59)) + { + goto cleanup; + } + + int tz_offset = (tz_hour * HOUR_IN_MINS) + tz_minute; + + if (*tokens == '-') + { + tz_offset = tz_offset * -1; + } + + t->offset = tz_offset; + + tokens = tokens + 6; + if (strlen(tokens) == 0) + { + t->ok = 1; + } + else + { + t->ok = 0; + } + } + +cleanup: + free(token_ptr); + tokens = NULL; + token_ptr = NULL; + return; +} + +void _Qiniu_Parse_Date_Time(char *datetime_string, Qiniu_DateTime *dt) +{ + _Qiniu_Parse_Date(datetime_string, &(dt->date)); + if (dt->date.ok == 0) + { + return; + } + + _Qiniu_Parse_Time(datetime_string, &(dt->time)); + if (dt->time.ok == 0) + { + return; + } + + dt->ok = 1; +} diff --git a/qiniu/rfc3339.h b/qiniu/rfc3339.h new file mode 100644 index 00000000..d1f25cc1 --- /dev/null +++ b/qiniu/rfc3339.h @@ -0,0 +1,57 @@ +#ifndef QINIU_RFC3339_H +#define QINIU_RFC3339_H + +#include +#include +#include +#include + +#define DAY_IN_SECS 86400 +#define HOUR_IN_SECS 3600 +#define MINUTE_IN_SECS 60 +#define HOUR_IN_MINS 60 + +#if defined(_WIN32) +#pragma pack(1) +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct _Qiniu_Date + { + unsigned int year; + unsigned int month; + unsigned int day; + unsigned int wday; + char ok; + } Qiniu_Date; + + typedef struct _Qiniu_Time + { + unsigned int hour; + unsigned int minute; + unsigned int second; + unsigned int fraction; + int offset; // UTC offset in minutes + char ok; + } Qiniu_Time; + + typedef struct _Qiniu_DateTime + { + Qiniu_Date date; + Qiniu_Time time; + char ok; + } Qiniu_DateTime; + +#if defined(_WIN32) +#pragma pack() +#endif + +#ifdef __cplusplus +} +#endif + +#endif // QINIU_RFC3339_H diff --git a/qiniu/rs.c b/qiniu/rs.c index a6da08c9..1b0c4e99 100644 --- a/qiniu/rs.c +++ b/qiniu/rs.c @@ -108,6 +108,10 @@ char *Qiniu_RS_PutPolicy_Token(Qiniu_RS_PutPolicy *auth, Qiniu_Mac *mac) { cJSON_AddNumberToObject(root, "fileType", auth->fileType); } + if (auth->persistentType) + { + cJSON_AddNumberToObject(root, "persistentType", auth->persistentType); + } if (auth->expires) { diff --git a/qiniu/rs.h b/qiniu/rs.h index 474144af..ee0da67d 100644 --- a/qiniu/rs.h +++ b/qiniu/rs.h @@ -12,7 +12,9 @@ #include "http.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -55,6 +57,7 @@ typedef struct _Qiniu_RS_PutPolicy { Qiniu_Uint32 expires; Qiniu_Uint32 deleteAfterDays; Qiniu_Uint32 fileType; + Qiniu_Uint32 persistentType; } Qiniu_RS_PutPolicy; /* @endgist */ @@ -245,7 +248,9 @@ QINIU_DLLAPI extern Qiniu_Error Qiniu_RS_BatchRestoreArchive(Qiniu_Client *self, Qiniu_RS_EntryRestoreArchive *entries, Qiniu_ItemCount entryCount); +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/rsf.h b/qiniu/rsf.h index 66acbb86..f0723f15 100644 --- a/qiniu/rsf.h +++ b/qiniu/rsf.h @@ -7,7 +7,9 @@ #include "http.h" +#if defined(_WIN32) #pragma pack(1) +#endif #ifdef __cplusplus extern "C" @@ -37,7 +39,9 @@ extern "C" const char *prefix, const char *delimiter, const char *marker, int limit); QINIU_DLLAPI extern void Qiniu_RSF_ListRet_Cleanup(Qiniu_RSF_ListRet *self); +#if defined(_WIN32) #pragma pack() +#endif #ifdef __cplusplus } diff --git a/qiniu/tm.h b/qiniu/tm.h index 6f0db071..7d1fbe11 100644 --- a/qiniu/tm.h +++ b/qiniu/tm.h @@ -12,6 +12,10 @@ #include "base.h" +#if defined(_WIN32) +#pragma pack(1) +#endif + #ifdef __cplusplus extern "C" { @@ -22,6 +26,10 @@ extern "C" QINIU_DLLAPI extern const char *Qiniu_MD5_HexStr(const char *src); QINIU_DLLAPI extern const char *Qiniu_MD5_HexStr_From_Reader(Qiniu_Reader r); +#if defined(_WIN32) +#pragma pack() +#endif + #ifdef __cplusplus } #endif diff --git a/vcpkg.json b/vcpkg.json index 845d5be2..e70e89d3 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "qiniu-c-sdk", - "version-string": "7.7.0", + "version-string": "7.8.0", "dependencies": [ "curl", "openssl"