forked from ufilesdk-dev/ufile-csdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gan.wu
committed
Dec 3, 2024
1 parent
879a493
commit cf26f31
Showing
11 changed files
with
478 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "../lib/api.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
|
||
void help(char *program_name) { | ||
printf("Usage: %s <bucket_name> [prefix=""]\n", program_name); | ||
} | ||
|
||
int main(int argc, char *argv[]){ | ||
if(argc < 2 || argc > 3){ | ||
help(argv[0]); | ||
return 1; | ||
} | ||
|
||
const char *bucket_name = argv[1]; | ||
const char *prefix = ""; | ||
if (argc > 2) { | ||
prefix = argv[2]; | ||
} | ||
|
||
struct ufile_config cfg; | ||
cfg.public_key = getenv("UFILE_PUBLIC_KEY"); | ||
cfg.private_key = getenv("UFILE_PRIVATE_KEY"); | ||
cfg.bucket_host = "api.ucloud.cn"; | ||
cfg.file_host = "cn-bj.ufileos.com"; | ||
|
||
struct ufile_error error; | ||
error = ufile_sdk_initialize(cfg, 1); | ||
if(UFILE_HAS_ERROR(error.code)){ | ||
ufile_sdk_cleanup(); | ||
printf("Initialize SDK failed: %s\n", error.message); | ||
return 1; | ||
} | ||
|
||
int once_list_count = 5; | ||
char *marker = ""; | ||
char is_truncated = 1; | ||
struct ufile_list_result result; | ||
memset(&result, 0, sizeof(result)); | ||
while (is_truncated) { | ||
error = ufile_list(bucket_name, prefix, "", once_list_count, marker, &result); | ||
if(UFILE_HAS_ERROR(error.code)){ | ||
printf("List failed, error message: %s\n", error.message); | ||
return 1; | ||
} else{ | ||
int i = 0; | ||
for (i = 0; i < result.entry_num; i++) { | ||
printf("key: %s, size: %ld, mime_type: %s, last_modified: %ld, create_time: %ld, etag: %s, storage_class: %s\n", | ||
result.entries[i].filename, result.entries[i].size, result.entries[i].mime_type, result.entries[i].last_modified, | ||
result.entries[i].create_time, result.entries[i].etag, result.entries[i].storage_class); | ||
} | ||
marker = result.next_marker; | ||
is_truncated = result.is_truncated; | ||
} | ||
} | ||
|
||
ufile_free_list_result(result); | ||
|
||
ufile_sdk_cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <string.h> | ||
#include "json.h" | ||
|
||
int JsonGetBool(cJSON *root, const char *key, char *value) { | ||
cJSON *item = cJSON_GetObjectItemCaseSensitive(root, key); | ||
if (!cJSON_IsBool(item)) { | ||
return -1; // Error | ||
} | ||
*value = cJSON_IsTrue(item) ? 1 : 0; | ||
return 0; | ||
} | ||
|
||
int JsonGetString(cJSON *root, const char *key, char **value) { | ||
cJSON *item = cJSON_GetObjectItemCaseSensitive(root, key); | ||
if (!cJSON_IsString(item)) { | ||
return -1; // Error | ||
} | ||
*value = strdup(item->valuestring); | ||
return 0; | ||
} | ||
|
||
int JsonGetArray(cJSON *root, const char *key, cJSON **array) { | ||
*array = cJSON_GetObjectItemCaseSensitive(root, key); | ||
if (!cJSON_IsArray(*array)) { | ||
return -1; // Error | ||
} | ||
return 0; | ||
} | ||
|
||
int JsonGetInt64(cJSON *root, const char *key, long long *value) { | ||
cJSON *item = cJSON_GetObjectItemCaseSensitive(root, key); | ||
if (!cJSON_IsNumber(item)) { | ||
return -1; // Error | ||
} | ||
*value = (long long)item->valuedouble; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "cJSON.h" | ||
|
||
int JsonGetBool(cJSON *root, const char *key, char *value); | ||
|
||
int JsonGetString(cJSON *root, const char *key, char **value); | ||
|
||
int JsonGetArray(cJSON *root, const char *key, cJSON **array); | ||
|
||
int JsonGetInt64(cJSON *root, const char *key, long long *value); |
Oops, something went wrong.