Debian Codegraph @

crt/aws-c-s3/include/aws/s3/private/s3_paginator.h

raw symbols SCIP
1 #ifndef AWS_S3_PAGINATOR_H
2 #define AWS_S3_PAGINATOR_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/auth/signing_config.h>
10 #include <aws/s3/exports.h>
11 #include <aws/s3/s3_client.h>
12
13 #include <aws/common/common.h>
14 #include <aws/common/xml_parser.h>
15
16 /**
17 * Wrapper for a generic paginated operation.
18 * Provides implementations for how to construct next paginated and how to read the request.
19 * Can be used with either paginator or plugged into request loop.
20 */
21 struct aws_s3_paginated_operation;
22
23 /**
24 * Generic driver for paginated operations.
25 * Provides functionality to send requests to iterate over pages of the operation.
26 */
27 struct aws_s3_paginator;
28
29 typedef int(aws_s3_next_http_message_fn)(
30 struct aws_byte_cursor *continuation_token,
31 void *user_data,
32 struct aws_http_message **out_message);
33
34 typedef int(aws_s3_on_result_node_encountered_fn)(struct aws_xml_node *node, void *user_data);
35
36 typedef void(aws_s3_on_page_finished_fn)(struct aws_s3_paginator *paginator, int error_code, void *user_data);
37
38 typedef void(aws_s3_on_paginated_operation_cleanup_fn)(void *user_data);
39
40 /**
41 * Parameters for initiating paginator. All values are copied out or re-seated and reference counted.
42 */
43 struct aws_s3_paginator_params {
44 /**
45 * Must not be NULL. The internal call will increment the reference count on client.
46 */
47 struct aws_s3_client *client;
48
49 /**
50 * Underlying paginated operation. Must not be NULL.
51 */
52 struct aws_s3_paginated_operation *operation;
53
54 /**
55 * Optional. The continuation token for fetching the next page. You likely shouldn't set this
56 * unless you have a special use case.
57 */
58 struct aws_byte_cursor continuation_token;
59
60 /**
61 * Must not be empty. Name of the bucket to list.
62 */
63 struct aws_byte_cursor bucket_name;
64
65 /**
66 * Must not be empty. Key with which multipart upload was initiated.
67 */
68 struct aws_byte_cursor endpoint;
69
70 /**
71 * Callback to invoke on each part that's listed.
72 */
73 aws_s3_on_page_finished_fn *on_page_finished_fn;
74
75 /**
76 * User data passed back into callbacks.
77 */
78 void *user_data;
79 };
80
81 /**
82 * Parameters for initiating paginated operation. All values are copied out or re-seated and reference counted.
83 */
84 struct aws_s3_paginated_operation_params {
85 /**
86 * The S3 operation name (e.g. "ListParts"). Must not be empty.
87 */
88 struct aws_byte_cursor operation_name;
89
90 /**
91 * Name of the top level result node. Must not be empty.
92 */
93 struct aws_byte_cursor result_xml_node_name;
94
95 /**
96 * Name of the continuation token node. Must not be empty.
97 */
98 struct aws_byte_cursor continuation_token_node_name;
99
100 /**
101 * Function to generate next message.
102 */
103 aws_s3_next_http_message_fn *next_message;
104
105 /**
106 * Function to parse result node.
107 */
108 aws_s3_on_result_node_encountered_fn *on_result_node_encountered_fn;
109
110 /**
111 * Callback for when operation is cleaned.
112 */
113 aws_s3_on_paginated_operation_cleanup_fn *on_paginated_operation_cleanup;
114
115 /**
116 * Associated user data.
117 */
118 void *user_data;
119 };
120
121 AWS_EXTERN_C_BEGIN
122
123 AWS_S3_API struct aws_s3_paginator *aws_s3_initiate_paginator(
124 struct aws_allocator *allocator,
125 const struct aws_s3_paginator_params *params);
126
127 AWS_S3_API void aws_s3_paginator_acquire(struct aws_s3_paginator *paginator);
128 AWS_S3_API void aws_s3_paginator_release(struct aws_s3_paginator *paginator);
129
130 AWS_S3_API struct aws_s3_paginated_operation *aws_s3_paginated_operation_new(
131 struct aws_allocator *allocator,
132 const struct aws_s3_paginated_operation_params *params);
133
134 AWS_S3_API void aws_s3_paginated_operation_acquire(struct aws_s3_paginated_operation *operation);
135 AWS_S3_API void aws_s3_paginated_operation_release(struct aws_s3_paginated_operation *operation);
136
137 /**
138 * Start the paginated operation. If there are more results to fetch, it will begin that work.
139 *
140 * Signing_config contains information for SigV4 signing for the operation. It must not be NULL. It will be copied.
141 *
142 * Returns AWS_OP_SUCCESS on successful start of the operation, and AWS_OP_ERR otherwise. Check aws_last_error() for
143 * more information on the error that occurred.
144 */
145 AWS_S3_API int aws_s3_paginator_continue(
146 struct aws_s3_paginator *paginator,
147 const struct aws_signing_config_aws *signing_config);
148
149 /**
150 * If the paginator has more results to fetch, returns true.
151 */
152 AWS_S3_API bool aws_s3_paginator_has_more_results(const struct aws_s3_paginator *paginator);
153
154 /**
155 * Construct next message for the given operation.
156 */
157 AWS_S3_API int aws_s3_construct_next_paginated_request_http_message(
158 struct aws_s3_paginated_operation *operation,
159 struct aws_byte_cursor *continuation_token,
160 struct aws_http_message **out_message);
161
162 /**
163 * Parse received response for operation.
164 */
165 AWS_S3_API int aws_s3_paginated_operation_on_response(
166 struct aws_s3_paginated_operation *operation,
167 struct aws_byte_cursor *response_body,
168 struct aws_string **continuation_token_out,
169 bool *has_more_results_out);
170
171 AWS_EXTERN_C_END
172
173 #endif /* AWS_S3_PAGINATOR_H */