对外API增加USERTAG

This commit is contained in:
zhangchengwei
2018-09-23 15:35:13 +08:00
parent 8d71ab8173
commit 20045a7493
10 changed files with 144 additions and 80 deletions

View File

@@ -54,9 +54,14 @@ void tango_cache_get_statistics(const struct tango_cache_instance *instance, str
out->memory_used = instance->statistic.memory_used;
}
struct tango_cache_result *tango_cache_read_result(void *promise_result)
{
return (struct tango_cache_result *)promise_result;
}
const char *tango_cache_get_object_key(struct tango_cache_ctx *ctx)
{
return ctx->file_key;
return ctx->object_key;
}
static inline void update_statistics(enum CACHE_REQUEST_METHOD method, bool fail_state, struct cache_statistics *statistic)
@@ -100,7 +105,7 @@ void easy_string_savedata(struct easy_string *estr, const char *data, size_t len
if(estr->size-estr->len < len+1)
{
estr->size += len*4+1;
estr->buff = (char*)realloc(estr->buff,estr->size);
estr->buff = (char*)realloc(estr->buff, estr->size);
}
memcpy(estr->buff+estr->len, data, len);
@@ -117,7 +122,11 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx)
}
easy_string_destroy(&ctx->response);
if(ctx->method == CACHE_REQUEST_PUT)
if(ctx->method == CACHE_REQUEST_GET)
{
easy_string_destroy(&ctx->response_tag);
}
else
{
struct multipart_etag_list *etag;
@@ -208,7 +217,6 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
{
struct tango_cache_ctx *ctx;
char buffer[256]={0};
int other_len;
time_t expires, now, last_modify;
if((u_int64_t)instance->statistic.memory_used >= instance->cache_limit_size)
@@ -227,11 +235,11 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
if(instance->hash_object_key)
{
caculate_sha256(meta->url, strlen(meta->url), buffer, 72);
snprintf(ctx->file_key, 72, "%c%c/%c%c/%s", buffer[0], buffer[1], buffer[2], buffer[3], buffer+4);
snprintf(ctx->object_key, 256, "%c%c/%c%c/%s", buffer[0], buffer[1], buffer[2], buffer[3], buffer+4);
}
else
{
snprintf(ctx->file_key, 72, "%s", meta->url);
snprintf(ctx->object_key, 256, "%s", meta->url);
}
//Expires<65>ֶΣ<D6B6><CEA3><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʱ
@@ -258,11 +266,11 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>GETʱ<54><CAB1>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(meta->other_hdr!=NULL && (other_len = strlen(meta->other_hdr))<1535)
if(meta->usertag_len>0 && meta->usertag_len<=USER_TAG_MAX_LEN)
{
char *p = (char *)malloc((other_len/3 + 1)*4 + 18); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ䣻18=17+1: ͷ<><CDB7>+<2B>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char *p = (char *)malloc((meta->usertag_len/3 + 1)*4 + 18); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ䣻18=17+1: ͷ<><CDB7>+<2B>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
memcpy(p, "x-amz-meta-user: ", 17);
Base64_EncodeBlock((unsigned char*)meta->other_hdr, other_len, (unsigned char*)p+17);
Base64_EncodeBlock((const unsigned char*)meta->usertag, meta->usertag_len, (unsigned char*)p+17);
ctx->headers = curl_slist_append(ctx->headers, p);
free(p);
}
@@ -297,7 +305,7 @@ int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct f
}
if(objectkey != NULL)
{
snprintf(objectkey, keysize, "%s", ctx->file_key);
snprintf(objectkey, keysize, "%s", ctx->object_key);
}
return tango_cache_upload_once_start_data(ctx, way, data, size);
@@ -315,7 +323,7 @@ int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct
}
if(objectkey != NULL)
{
snprintf(objectkey, keysize, "%s", ctx->file_key);
snprintf(objectkey, keysize, "%s", ctx->object_key);
}
return tango_cache_upload_once_start_evbuf(ctx, way, evbuf);
@@ -338,11 +346,11 @@ struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *i
if(instance->hash_object_key)
{
caculate_sha256(meta->url, strlen(meta->url), sha256, 72);
snprintf(ctx->file_key, 72, "%c%c/%c%c/%s", sha256[0], sha256[1], sha256[2], sha256[3], sha256+4);
snprintf(ctx->object_key, 256, "%c%c/%c%c/%s", sha256[0], sha256[1], sha256[2], sha256[3], sha256+4);
}
else
{
snprintf(ctx->file_key, 72, "%s", meta->url);
snprintf(ctx->object_key, 256, "%s", meta->url);
}
return ctx;