Skip to content

Commit 158fbec

Browse files
committed
feat(bindings/c): support presign
1 parent db2308a commit 158fbec

File tree

12 files changed

+1155
-5
lines changed

12 files changed

+1155
-5
lines changed

.github/workflows/test_behavior_binding_c.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Install build tools
5555
run: |
5656
sudo apt-get update
57-
sudo apt-get install -y build-essential pkg-config uuid-dev
57+
sudo apt-get install -y build-essential pkg-config uuid-dev libcurl4-gnutls-dev
5858
5959
- name: Build OpenDAL C library
6060
working-directory: "bindings/c"

bindings/c/include/opendal.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ typedef enum opendal_code {
8787
OPENDAL_RANGE_NOT_SATISFIED,
8888
} opendal_code;
8989

90+
typedef struct opendal_presigned_request_inner opendal_presigned_request_inner;
91+
9092
/**
9193
* \brief opendal_bytes carries raw-bytes with its length
9294
*
@@ -577,12 +579,52 @@ typedef struct opendal_capability {
577579
* If operator supports presign write.
578580
*/
579581
bool presign_write;
582+
/**
583+
* If operator supports presign delete.
584+
*/
585+
bool presign_delete;
580586
/**
581587
* If operator supports shared.
582588
*/
583589
bool shared;
584590
} opendal_capability;
585591

592+
/**
593+
* \brief The underlying presigned request, which contains the HTTP method, URI, and headers.
594+
* This is an opaque struct, please use the accessor functions to get the fields.
595+
*/
596+
typedef struct opendal_presigned_request {
597+
struct opendal_presigned_request_inner *inner;
598+
} opendal_presigned_request;
599+
600+
/**
601+
* @brief The result of a presign operation.
602+
*/
603+
typedef struct opendal_result_presign {
604+
/**
605+
* The presigned request.
606+
*/
607+
struct opendal_presigned_request *req;
608+
/**
609+
* The error.
610+
*/
611+
struct opendal_error *error;
612+
} opendal_result_presign;
613+
614+
/**
615+
* \brief The key-value pair for the headers of the presigned request.
616+
*/
617+
typedef struct opendal_http_header_pair {
618+
/**
619+
* The key of the header.
620+
*/
621+
const char *key;
622+
/**
623+
* The value of the header.
624+
*/
625+
const char *value;
626+
} opendal_http_header_pair;
627+
586628
/**
587629
* \brief The is the result type returned by opendal_reader_read().
588630
* The result type contains a size field, which is the size of the data read,
@@ -1376,6 +1418,59 @@ struct opendal_capability opendal_operator_info_get_full_capability(const struct
13761418
*/
13771419
struct opendal_capability opendal_operator_info_get_native_capability(const struct opendal_operator_info *self);
13781420

1421+
/**
1422+
* \brief Presign a read operation.
1423+
*/
1424+
struct opendal_result_presign opendal_operator_presign_read(const struct opendal_operator *op,
1425+
const char *path,
1426+
uint64_t expire_secs);
1427+
1428+
/**
1429+
* \brief Presign a write operation.
1430+
*/
1431+
struct opendal_result_presign opendal_operator_presign_write(const struct opendal_operator *op,
1432+
const char *path,
1433+
uint64_t expire_secs);
1434+
1435+
/**
1436+
* \brief Presign a delete operation.
1437+
*/
1438+
struct opendal_result_presign opendal_operator_presign_delete(const struct opendal_operator *op,
1439+
const char *path,
1440+
uint64_t expire_secs);
1441+
1442+
/**
1443+
* \brief Presign a stat operation.
1444+
*/
1445+
struct opendal_result_presign opendal_operator_presign_stat(const struct opendal_operator *op,
1446+
const char *path,
1447+
uint64_t expire_secs);
1448+
1449+
/**
1450+
* Get the method of the presigned request.
1451+
*/
1452+
const char *opendal_presigned_request_method(const struct opendal_presigned_request *req);
1453+
1454+
/**
1455+
* Get the URI of the presigned request.
1456+
*/
1457+
const char *opendal_presigned_request_uri(const struct opendal_presigned_request *req);
1458+
1459+
/**
1460+
* Get the headers of the presigned request.
1461+
*/
1462+
const struct opendal_http_header_pair *opendal_presigned_request_headers(const struct opendal_presigned_request *req);
1463+
1464+
/**
1465+
* Get the length of the headers of the presigned request.
1466+
*/
1467+
uintptr_t opendal_presigned_request_headers_len(const struct opendal_presigned_request *req);
1468+
1469+
/**
1470+
* \brief Free the presigned request.
1471+
*/
1472+
void opendal_presigned_request_free(struct opendal_presigned_request *req);
1473+
13791474
/**
13801475
* \brief Frees the heap memory used by the opendal_bytes
13811476
*/

bindings/c/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ pub use operator::opendal_operator;
4747

4848
mod operator_info;
4949

50+
mod presign;
51+
pub use presign::opendal_http_header_pair;
52+
pub use presign::opendal_presigned_request;
53+
pub use presign::opendal_result_presign;
54+
5055
mod result;
5156
pub use result::opendal_result_exists;
5257
pub use result::opendal_result_is_exist;

bindings/c/src/operator_info.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub struct opendal_capability {
125125
pub presign_stat: bool,
126126
/// If operator supports presign write.
127127
pub presign_write: bool,
128+
/// If operator supports presign delete.
129+
pub presign_delete: bool,
128130

129131
/// If operator supports shared.
130132
pub shared: bool,
@@ -253,6 +255,7 @@ impl From<core::Capability> for opendal_capability {
253255
presign_read: value.presign_read,
254256
presign_stat: value.presign_stat,
255257
presign_write: value.presign_write,
258+
presign_delete: value.presign_delete,
256259
shared: value.shared,
257260
}
258261
}

0 commit comments

Comments
 (0)