File: s3_paginator.h

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (168 lines) | stat: -rw-r--r-- 5,117 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef AWS_S3_PAGINATOR_H
#define AWS_S3_PAGINATOR_H

/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/auth/signing_config.h>
#include <aws/s3/exports.h>
#include <aws/s3/s3_client.h>

#include <aws/common/common.h>
#include <aws/common/xml_parser.h>

/**
 * Wrapper for a generic paginated operation.
 * Provides implementations for how to construct next paginated and how to read the request.
 * Can be used with either paginator or plugged into request loop.
 */
struct aws_s3_paginated_operation;

/**
 * Generic driver for paginated operations.
 * Provides functionality to send requests to iterate over pages of the operation.
 */
struct aws_s3_paginator;

typedef int(aws_s3_next_http_message_fn)(
    struct aws_byte_cursor *continuation_token,
    void *user_data,
    struct aws_http_message **out_message);

typedef int(aws_s3_on_result_node_encountered_fn)(struct aws_xml_node *node, void *user_data);

typedef void(aws_s3_on_page_finished_fn)(struct aws_s3_paginator *paginator, int error_code, void *user_data);

typedef void(aws_s3_on_paginated_operation_cleanup_fn)(void *user_data);

/**
 * Parameters for initiating paginator. All values are copied out or re-seated and reference counted.
 */
struct aws_s3_paginator_params {
    /**
     * Must not be NULL. The internal call will increment the reference count on client.
     */
    struct aws_s3_client *client;

    /**
     * Underlying paginated operation. Must not be NULL.
     */
    struct aws_s3_paginated_operation *operation;

    /**
     * Optional. The continuation token for fetching the next page. You likely shouldn't set this
     * unless you have a special use case.
     */
    struct aws_byte_cursor continuation_token;

    /**
     * Must not be empty. Name of the bucket to list.
     */
    struct aws_byte_cursor bucket_name;

    /**
     * Must not be empty. Key with which multipart upload was initiated.
     */
    struct aws_byte_cursor endpoint;

    /**
     * Callback to invoke on each part that's listed.
     */
    aws_s3_on_page_finished_fn *on_page_finished_fn;

    /**
     * User data passed back into callbacks.
     */
    void *user_data;
};

/**
 * Parameters for initiating paginated operation. All values are copied out or re-seated and reference counted.
 */
struct aws_s3_paginated_operation_params {
    /**
     * Name of the top level result node. Must not be empty.
     */
    struct aws_byte_cursor result_xml_node_name;

    /**
     * Name of the continuation token node. Must not be empty.
     */
    struct aws_byte_cursor continuation_token_node_name;

    /**
     * Function to generate next message.
     */
    aws_s3_next_http_message_fn *next_message;

    /**
     * Function to parse result node.
     */
    aws_s3_on_result_node_encountered_fn *on_result_node_encountered_fn;

    /**
     * Callback for when operation is cleaned.
     */
    aws_s3_on_paginated_operation_cleanup_fn *on_paginated_operation_cleanup;

    /**
     * Associated user data.
     */
    void *user_data;
};

AWS_EXTERN_C_BEGIN

AWS_S3_API struct aws_s3_paginator *aws_s3_initiate_paginator(
    struct aws_allocator *allocator,
    const struct aws_s3_paginator_params *params);

AWS_S3_API void aws_s3_paginator_acquire(struct aws_s3_paginator *paginator);
AWS_S3_API void aws_s3_paginator_release(struct aws_s3_paginator *paginator);

AWS_S3_API struct aws_s3_paginated_operation *aws_s3_paginated_operation_new(
    struct aws_allocator *allocator,
    const struct aws_s3_paginated_operation_params *params);

AWS_S3_API void aws_s3_paginated_operation_acquire(struct aws_s3_paginated_operation *operation);
AWS_S3_API void aws_s3_paginated_operation_release(struct aws_s3_paginated_operation *operation);

/**
 * Start the paginated operation. If there are more results to fetch, it will begin that work.
 *
 * Signing_config contains information for SigV4 signing for the operation. It must not be NULL. It will be copied.
 *
 * Returns AWS_OP_SUCCESS on successful start of the operation, and AWS_OP_ERR otherwise. Check aws_last_error() for
 * more information on the error that occurred.
 */
AWS_S3_API int aws_s3_paginator_continue(
    struct aws_s3_paginator *paginator,
    const struct aws_signing_config_aws *signing_config);

/**
 * If the paginator has more results to fetch, returns true.
 */
AWS_S3_API bool aws_s3_paginator_has_more_results(const struct aws_s3_paginator *paginator);

/**
 * Construct next message for the given operation.
 */
AWS_S3_API int aws_s3_construct_next_paginated_request_http_message(
    struct aws_s3_paginated_operation *operation,
    struct aws_byte_cursor *continuation_token,
    struct aws_http_message **out_message);

/**
 * Parse received response for operation.
 */
AWS_S3_API int aws_s3_paginated_operation_on_response(
    struct aws_s3_paginated_operation *operation,
    struct aws_byte_cursor *response_body,
    struct aws_string **continuation_token_out,
    bool *has_more_results_out);

AWS_EXTERN_C_END

#endif /* AWS_S3_PAGINATOR_H */