| 1 | #ifndef AWS_S3_LIST_OBJECTS_H |
| 2 | #define AWS_S3_LIST_OBJECTS_H |
| 3 | |
| 4 | /** |
| 5 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | * SPDX-License-Identifier: Apache-2.0. |
| 7 | */ |
| 8 | |
| 9 | #include <aws/s3/s3_client.h> |
| 10 | |
| 11 | #include <aws/common/date_time.h> |
| 12 | #include <aws/common/string.h> |
| 13 | |
| 14 | #include <aws/s3/private/s3_paginator.h> |
| 15 | |
| 16 | /** Struct representing the file system relevant data for an object returned from a ListObjectsV2 API call. */ |
| 17 | struct aws_s3_object_info { |
| 18 | /** |
| 19 | * When a delimiter is specified in the request, S3 groups the common prefixes that contain the delimiter. |
| 20 | * This member is set to the prefix substring ending at the first occurrence of the specified delimiter, |
| 21 | * analogous to a directory entry of a file system. |
| 22 | */ |
| 23 | struct aws_byte_cursor prefix; |
| 24 | /** |
| 25 | * Prefix is not included. This is the object name for use with prefix for a call to GetObject() |
| 26 | */ |
| 27 | struct aws_byte_cursor key; |
| 28 | /** |
| 29 | * Size of the object in bytes. |
| 30 | */ |
| 31 | uint64_t size; |
| 32 | /** |
| 33 | * Timestamp from S3 on the latest modification, if you have a reliable clock on your machine, you COULD use this |
| 34 | * to implement caching. |
| 35 | */ |
| 36 | struct aws_date_time last_modified; |
| 37 | /** |
| 38 | * Etag for the object, usually an MD5 hash. you COULD also use this to implement caching. |
| 39 | */ |
| 40 | struct aws_byte_cursor e_tag; |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * Invoked when an object or prefix is encountered during a ListObjectsV2 API call. Return false, to immediately |
| 45 | * terminate the list operation. Returning true will continue until at least the current page is iterated. |
| 46 | */ |
| 47 | typedef int(aws_s3_on_object_fn)(const struct aws_s3_object_info *info, void *user_data); |
| 48 | |
| 49 | /** |
| 50 | * Invoked upon the complete fetch and parsing of a page. If error_code is AWS_OP_SUCCESS and |
| 51 | * aws_s3_paginator_has_more_results() returns true, you may want to call, |
| 52 | * aws_s3_paginator_continue() from here to fetch the rest of the bucket contents. |
| 53 | */ |
| 54 | typedef void(aws_s3_on_object_list_finished_fn)(struct aws_s3_paginator *paginator, int error_code, void *user_data); |
| 55 | |
| 56 | /** |
| 57 | * Parameters for calling aws_s3_initiate_list_objects(). All values are copied out or re-seated and reference counted. |
| 58 | */ |
| 59 | struct aws_s3_list_objects_params { |
| 60 | /** |
| 61 | * Must not be NULL. The internal call will increment the reference count on client. |
| 62 | */ |
| 63 | struct aws_s3_client *client; |
| 64 | /** |
| 65 | * Must not be empty. Name of the bucket to list. |
| 66 | */ |
| 67 | struct aws_byte_cursor bucket_name; |
| 68 | /** |
| 69 | * Optional. The prefix to list. By default, this will be the root of the bucket. If you would like to start the |
| 70 | * list operation at a prefix (similar to a file system directory), specify that here. |
| 71 | */ |
| 72 | struct aws_byte_cursor prefix; |
| 73 | /** |
| 74 | * Optional. The prefix delimiter. By default, this is the '/' character. |
| 75 | */ |
| 76 | struct aws_byte_cursor delimiter; |
| 77 | /** |
| 78 | * Optional. The continuation token for fetching the next page for ListBucketV2. You likely shouldn't set this |
| 79 | * unless you have a special use case. |
| 80 | */ |
| 81 | struct aws_byte_cursor continuation_token; |
| 82 | /** |
| 83 | * Must not be empty. The endpoint for the S3 bucket to hit. Can be virtual or path style. |
| 84 | */ |
| 85 | struct aws_byte_cursor endpoint; |
| 86 | /** |
| 87 | * Callback to invoke on each object that's listed. |
| 88 | */ |
| 89 | aws_s3_on_object_fn *on_object; |
| 90 | /** |
| 91 | * Callback to invoke when each page of the bucket listing completes. |
| 92 | */ |
| 93 | aws_s3_on_object_list_finished_fn *on_list_finished; |
| 94 | void *user_data; |
| 95 | }; |
| 96 | |
| 97 | AWS_EXTERN_C_BEGIN |
| 98 | |
| 99 | /** |
| 100 | * Initiates a list objects command (without executing it), and returns a paginator object to iterate the bucket with if |
| 101 | * successful. |
| 102 | * |
| 103 | * Returns NULL on failure. Check aws_last_error() for details on the error that occurred. |
| 104 | * |
| 105 | * this is a reference counted object. It is returned with a reference count of 1. You must call |
| 106 | * aws_s3_paginator_release() on this object when you are finished with it. |
| 107 | * |
| 108 | * This does not start the actual list operation. You need to call aws_s3_paginator_continue() to start |
| 109 | * the operation. |
| 110 | */ |
| 111 | AWS_S3_API struct aws_s3_paginator *aws_s3_initiate_list_objects( |
| 112 | struct aws_allocator *allocator, |
| 113 | const struct aws_s3_list_objects_params *params); |
| 114 | |
| 115 | AWS_EXTERN_C_END |
| 116 | |
| 117 | #endif /* AWS_S3_LIST_OBJECTS_H */ |