Add comments to s3.h
This commit is contained in:
@@ -541,7 +541,7 @@ int s3_presign_url(
|
|||||||
|
|
||||||
struct tm unpacked_now;
|
struct tm unpacked_now;
|
||||||
if (unpack_time(now, &unpacked_now))
|
if (unpack_time(now, &unpacked_now))
|
||||||
return -1; // TODO
|
return S3_OTHER_ERROR;
|
||||||
|
|
||||||
char date_buf_0[sizeof("YYYYMMDD")];
|
char date_buf_0[sizeof("YYYYMMDD")];
|
||||||
char date_buf_1[sizeof("YYYYMMDDthhmmssz")];
|
char date_buf_1[sizeof("YYYYMMDDthhmmssz")];
|
||||||
@@ -549,7 +549,7 @@ int s3_presign_url(
|
|||||||
int ret = strftime(date_buf_0, sizeof(date_buf_0),
|
int ret = strftime(date_buf_0, sizeof(date_buf_0),
|
||||||
"%Y%m%d", &unpacked_now);
|
"%Y%m%d", &unpacked_now);
|
||||||
if (ret != sizeof(date_buf_0)-1)
|
if (ret != sizeof(date_buf_0)-1)
|
||||||
return -1; // TODO
|
return S3_OTHER_ERROR;
|
||||||
S3_String yyyymmdd = {
|
S3_String yyyymmdd = {
|
||||||
date_buf_0,
|
date_buf_0,
|
||||||
sizeof(date_buf_0)-1
|
sizeof(date_buf_0)-1
|
||||||
@@ -558,7 +558,7 @@ int s3_presign_url(
|
|||||||
ret = strftime(date_buf_1, sizeof(date_buf_1),
|
ret = strftime(date_buf_1, sizeof(date_buf_1),
|
||||||
"%Y%m%dT%H%M%SZ", &unpacked_now);
|
"%Y%m%dT%H%M%SZ", &unpacked_now);
|
||||||
if (ret != sizeof(date_buf_1)-1)
|
if (ret != sizeof(date_buf_1)-1)
|
||||||
return -1; // TODO
|
return S3_OTHER_ERROR;
|
||||||
S3_String yyyymmddthhmmssz = {
|
S3_String yyyymmddthhmmssz = {
|
||||||
date_buf_1,
|
date_buf_1,
|
||||||
sizeof(date_buf_1)-1
|
sizeof(date_buf_1)-1
|
||||||
@@ -567,14 +567,14 @@ int s3_presign_url(
|
|||||||
char hash_buf[32];
|
char hash_buf[32];
|
||||||
if (payload.len > 0) {
|
if (payload.len > 0) {
|
||||||
if (sha256(payload.ptr, payload.len, hash_buf) < 0)
|
if (sha256(payload.ptr, payload.len, hash_buf) < 0)
|
||||||
return -1;
|
return S3_LIB_ERROR;
|
||||||
}
|
}
|
||||||
S3_String hash = { hash_buf, sizeof(hash_buf) };
|
S3_String hash = { hash_buf, sizeof(hash_buf) };
|
||||||
|
|
||||||
char expire_buf[11];
|
char expire_buf[11];
|
||||||
ret = snprintf(expire_buf, sizeof(expire_buf), "%d", expire);
|
ret = snprintf(expire_buf, sizeof(expire_buf), "%d", expire);
|
||||||
if (ret < 0 || ret >= (int) sizeof(expire_buf))
|
if (ret < 0 || ret >= (int) sizeof(expire_buf))
|
||||||
return -1;
|
return S3_OTHER_ERROR;
|
||||||
S3_String expire_str = { expire_buf, ret };
|
S3_String expire_str = { expire_buf, ret };
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
|
|||||||
@@ -3,18 +3,33 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define S3_S(X) (S3_String) { (X), sizeof(X)-1 }
|
|
||||||
|
|
||||||
enum {
|
|
||||||
S3_OUT_OF_MEMORY = -1,
|
|
||||||
S3_LIB_ERROR = -2,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int len;
|
int len;
|
||||||
} S3_String;
|
} S3_String;
|
||||||
|
|
||||||
|
// Utility to translate string literals to S3_Strings
|
||||||
|
#define S3_S(X) (S3_String) { (X), sizeof(X)-1 }
|
||||||
|
|
||||||
|
enum {
|
||||||
|
S3_OUT_OF_MEMORY = -1,
|
||||||
|
S3_LIB_ERROR = -2,
|
||||||
|
S3_OTHER_ERROR = -3,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Writes the presigned URL in the dst buffer and
|
||||||
|
// returns the number of bytes written. No more than
|
||||||
|
// "cap" bytes are ever written. On error, a negative
|
||||||
|
// status code is returned:
|
||||||
|
//
|
||||||
|
// S3_OUT_OF_MEMORY
|
||||||
|
// An allocation failed or the output buffer is too small
|
||||||
|
//
|
||||||
|
// S3_LIB_ERROR
|
||||||
|
// The underlying crypto library failed
|
||||||
|
//
|
||||||
|
// S3_OTHER_ERROR
|
||||||
|
// Some other error
|
||||||
int s3_presign_url(
|
int s3_presign_url(
|
||||||
S3_String bucket,
|
S3_String bucket,
|
||||||
S3_String object,
|
S3_String object,
|
||||||
|
|||||||
Reference in New Issue
Block a user