Skip to content

Commit

Permalink
support dora idle tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
bachue committed Aug 20, 2024
1 parent 65f7cb8 commit f2ea8f4
Show file tree
Hide file tree
Showing 32 changed files with 335 additions and 72 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGE LOG

## v7.8.0 (2024-08-20)

- 支持闲时任务

## v7.7.0 (2023-12-25)

- 支持归档直读存储类型
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
43 changes: 41 additions & 2 deletions examples/fop_video_avthumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params);
if (error.code != 200) {
printf("video file pfop %s:%s error.\n", bucket, key);
debug_log(&client, error);
Expand All @@ -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);
}
}
5 changes: 2 additions & 3 deletions qiniu/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions qiniu/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ typedef off_t Qiniu_Off_T;

#endif

#if defined(_WIN32)
#pragma pack(1)
#endif

#ifdef __cplusplus
extern "C"
Expand Down Expand Up @@ -357,7 +359,9 @@ typedef struct stat Qiniu_FileInfo;

/*============================================================================*/

#if defined(_WIN32)
#pragma pack()
#endif

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion qiniu/base_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions qiniu/cdn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -611,4 +611,4 @@ void Qiniu_Free_CDNLogListRet(Qiniu_CDN_LogListRet *ret) {
}
Qiniu_Free(ret->data);
}
}
}
8 changes: 8 additions & 0 deletions qiniu/cdn.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "macro.h"
#include "http.h"

#if defined(_WIN32)
#pragma pack(1)
#endif

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -164,6 +168,10 @@ QINIU_DLLAPI extern void Qiniu_Free_CDNLogListRet(Qiniu_CDN_LogListRet *ret);

//=====================================================================

#if defined(_WIN32)
#pragma pack()
#endif

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions qiniu/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "macro.h"
#include "base.h"

#if defined(_WIN32)
#pragma pack(1)
#endif

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions qiniu/emu_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

#include "macro.h"

#if defined(_WIN32)
#pragma pack(1)
#endif

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -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
Expand Down
118 changes: 103 additions & 15 deletions qiniu/fop.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#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)
Qiniu_Error Qiniu_FOP_Pfop_v2(Qiniu_Client *self, Qiniu_FOP_PfopRet *ret, Qiniu_FOP_PfopParams *params)
{
Qiniu_Error err;
cJSON *root;
Expand All @@ -25,6 +24,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;
Expand All @@ -34,39 +34,48 @@ 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";
}
else
{
forceStr = "0";
}
if (params->type == 1)
{
typeStr = "1";
}
else
{
typeStr = "0";
}

body = Qiniu_String_Concat("bucket=", encodedBucket, "&key=", encodedKey, "&fops=", encodedFops,
"&pipeline=", encodedPipeline, "&notifyURL=", encodedNotifyURL, "&force=", forceStr, NULL);
"&pipeline=", encodedPipeline, "&notifyURL=", encodedNotifyURL, "&force=", forceStr,
"&type=", typeStr, NULL);
if (escapeBucketOk)
{
Qiniu_Free(encodedBucket);
Expand All @@ -82,23 +91,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,
Expand All @@ -116,4 +124,84 @@ 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, &params);
} // 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;
char *url = 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);

*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;
}
Loading

0 comments on commit f2ea8f4

Please sign in to comment.