| 1 |
#ifndef AWS_S3_UTIL_H |
| 2 |
#define AWS_S3_UTIL_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#include <aws/auth/signing_config.h> |
| 12 |
#include <aws/common/byte_buf.h> |
| 13 |
#include <aws/s3/s3_client.h> |
| 14 |
|
| 15 |
#if ASSERT_LOCK_HELD |
| 16 |
# define ASSERT_SYNCED_DATA_LOCK_HELD(object) \ |
| 17 |
{ \ |
| 18 |
int cached_error = aws_last_error(); \ |
| 19 |
AWS_ASSERT(aws_mutex_try_lock(&(object)->synced_data.lock) == AWS_OP_ERR); \ |
| 20 |
aws_raise_error(cached_error); \ |
| 21 |
} |
| 22 |
#else |
| 23 |
# define ASSERT_SYNCED_DATA_LOCK_HELD(object) |
| 24 |
#endif |
| 25 |
#define KB_TO_BYTES(kb) ((kb) * 1024) |
| 26 |
#define MB_TO_BYTES(mb) ((mb) * 1024 * 1024) |
| 27 |
#define GB_TO_BYTES(gb) ((uint64_t)(gb) * 1024 * 1024 * 1024ULL) |
| 28 |
#define TB_TO_BYTES(tb) ((uint64_t)(tb) * 1024 * 1024 * 1024 * 1024ULL) |
| 29 |
|
| 30 |
#define MS_TO_NS(ms) ((uint64_t)(ms) * 1000000) |
| 31 |
#define SEC_TO_NS(ms) ((uint64_t)(ms) * 1000000000) |
| 32 |
|
| 33 |
struct aws_allocator; |
| 34 |
struct aws_http_stream; |
| 35 |
struct aws_http_headers; |
| 36 |
struct aws_http_message; |
| 37 |
struct aws_s3_client; |
| 38 |
struct aws_s3_request; |
| 39 |
struct aws_s3_meta_request; |
| 40 |
struct aws_s3_checksum; |
| 41 |
|
| 42 |
struct aws_cached_signing_config_aws { |
| 43 |
struct aws_allocator *allocator; |
| 44 |
struct aws_string *service; |
| 45 |
struct aws_string *region; |
| 46 |
struct aws_string *signed_body_value; |
| 47 |
|
| 48 |
struct aws_signing_config_aws config; |
| 49 |
}; |
| 50 |
|
| 51 |
AWS_EXTERN_C_BEGIN |
| 52 |
|
| 53 |
AWS_S3_API |
| 54 |
extern const struct aws_byte_cursor g_content_md5_header_name; |
| 55 |
|
| 56 |
AWS_S3_API |
| 57 |
extern const struct aws_byte_cursor g_trailer_header_name; |
| 58 |
|
| 59 |
AWS_S3_API |
| 60 |
extern const struct aws_byte_cursor g_request_validation_mode; |
| 61 |
|
| 62 |
AWS_S3_API |
| 63 |
extern const struct aws_byte_cursor g_enabled; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
AWS_S3_API |
| 69 |
extern const struct aws_byte_cursor g_checksum_algorithm_header_name; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
AWS_S3_API |
| 75 |
extern const struct aws_byte_cursor g_sdk_checksum_algorithm_header_name; |
| 76 |
|
| 77 |
AWS_S3_API |
| 78 |
extern const struct aws_byte_cursor g_s3_client_version; |
| 79 |
|
| 80 |
AWS_S3_API |
| 81 |
extern const struct aws_byte_cursor g_user_agent_header_name; |
| 82 |
|
| 83 |
AWS_S3_API |
| 84 |
extern const struct aws_byte_cursor g_user_agent_header_product_name; |
| 85 |
|
| 86 |
AWS_S3_API |
| 87 |
extern const struct aws_byte_cursor g_user_agent_header_platform; |
| 88 |
|
| 89 |
AWS_S3_API |
| 90 |
extern const struct aws_byte_cursor g_user_agent_header_unknown; |
| 91 |
|
| 92 |
AWS_S3_API |
| 93 |
extern const struct aws_byte_cursor g_acl_header_name; |
| 94 |
|
| 95 |
AWS_S3_API |
| 96 |
extern const struct aws_byte_cursor g_host_header_name; |
| 97 |
|
| 98 |
AWS_S3_API |
| 99 |
extern const struct aws_byte_cursor g_content_type_header_name; |
| 100 |
|
| 101 |
AWS_S3_API |
| 102 |
extern const struct aws_byte_cursor g_content_encoding_header_name; |
| 103 |
|
| 104 |
AWS_S3_API |
| 105 |
extern const struct aws_byte_cursor g_content_encoding_header_aws_chunked; |
| 106 |
|
| 107 |
AWS_S3_API |
| 108 |
extern const struct aws_byte_cursor g_content_length_header_name; |
| 109 |
|
| 110 |
AWS_S3_API |
| 111 |
extern const struct aws_byte_cursor g_decoded_content_length_header_name; |
| 112 |
|
| 113 |
AWS_S3_API |
| 114 |
extern const struct aws_byte_cursor g_etag_header_name; |
| 115 |
|
| 116 |
AWS_S3_API |
| 117 |
extern const size_t g_s3_min_upload_part_size; |
| 118 |
|
| 119 |
AWS_S3_API |
| 120 |
extern const struct aws_byte_cursor g_s3_service_name; |
| 121 |
|
| 122 |
AWS_S3_API |
| 123 |
extern const struct aws_byte_cursor g_s3express_service_name; |
| 124 |
|
| 125 |
AWS_S3_API |
| 126 |
extern const struct aws_byte_cursor g_range_header_name; |
| 127 |
|
| 128 |
extern const struct aws_byte_cursor g_if_match_header_name; |
| 129 |
|
| 130 |
extern const struct aws_byte_cursor g_request_id_header_name; |
| 131 |
extern const struct aws_byte_cursor g_amz_id_2_header_name; |
| 132 |
|
| 133 |
AWS_S3_API |
| 134 |
extern const struct aws_byte_cursor g_content_range_header_name; |
| 135 |
|
| 136 |
AWS_S3_API |
| 137 |
extern const struct aws_byte_cursor g_accept_ranges_header_name; |
| 138 |
|
| 139 |
AWS_S3_API |
| 140 |
extern const struct aws_byte_cursor g_mp_parts_count_header_name; |
| 141 |
|
| 142 |
AWS_S3_API |
| 143 |
extern const struct aws_byte_cursor g_post_method; |
| 144 |
|
| 145 |
AWS_S3_API |
| 146 |
extern const struct aws_byte_cursor g_head_method; |
| 147 |
|
| 148 |
AWS_S3_API |
| 149 |
extern const struct aws_byte_cursor g_delete_method; |
| 150 |
|
| 151 |
AWS_S3_API |
| 152 |
extern const uint32_t g_s3_max_num_upload_parts; |
| 153 |
|
| 154 |
AWS_S3_API |
| 155 |
|
| 156 |
extern const size_t g_streaming_buffer_size; |
| 157 |
|
| 158 |
AWS_S3_API |
| 159 |
extern const double g_default_throughput_target_gbps; |
| 160 |
|
| 161 |
AWS_S3_API |
| 162 |
extern const uint64_t g_streaming_object_size_threshold; |
| 163 |
|
| 164 |
AWS_S3_API |
| 165 |
extern const uint64_t g_default_part_size_fallback; |
| 166 |
|
| 167 |
AWS_S3_API |
| 168 |
extern const uint64_t g_default_max_part_size; |
| 169 |
|
| 170 |
AWS_S3_API |
| 171 |
extern const uint64_t g_s3_optimal_range_size_alignment; |
| 172 |
|
| 173 |
AWS_S3_API |
| 174 |
extern const uint32_t g_s3express_connection_limitation; |
| 175 |
AWS_S3_API |
| 176 |
extern const uint64_t g_s3express_connection_limitation_part_size_threshold; |
| 177 |
AWS_S3_API |
| 178 |
extern const uint64_t g_s3express_connection_limitation_object_size_threshold; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
AWS_S3_API |
| 184 |
enum aws_s3_request_type aws_s3_request_type_from_operation_name(struct aws_byte_cursor name); |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
AWS_S3_API |
| 195 |
struct aws_string *aws_s3_request_type_to_operation_name_static_string(enum aws_s3_request_type type); |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
struct aws_cached_signing_config_aws *aws_cached_signing_config_new( |
| 205 |
struct aws_s3_client *client, |
| 206 |
const struct aws_signing_config_aws *signing_config); |
| 207 |
|
| 208 |
void aws_cached_signing_config_destroy(struct aws_cached_signing_config_aws *cached_signing_config); |
| 209 |
|
| 210 |
|
| 211 |
AWS_S3_API |
| 212 |
void copy_http_headers(const struct aws_http_headers *src, struct aws_http_headers *dest); |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
AWS_S3_API |
| 233 |
int aws_xml_get_body_at_path( |
| 234 |
struct aws_allocator *allocator, |
| 235 |
struct aws_byte_cursor xml_doc, |
| 236 |
const char *path_name_array[], |
| 237 |
struct aws_byte_cursor *out_body); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
AWS_S3_API |
| 242 |
struct aws_string *aws_strip_quotes(struct aws_allocator *allocator, struct aws_byte_cursor in_cur); |
| 243 |
|
| 244 |
|
| 245 |
AWS_S3_API |
| 246 |
int aws_last_error_or_unknown(void); |
| 247 |
|
| 248 |
AWS_S3_API |
| 249 |
void aws_s3_add_user_agent_header(struct aws_allocator *allocator, struct aws_http_message *message); |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
AWS_S3_API |
| 254 |
int aws_s3_parse_content_range_response_header( |
| 255 |
struct aws_http_headers *response_headers, |
| 256 |
uint64_t *out_range_start, |
| 257 |
uint64_t *out_range_end, |
| 258 |
uint64_t *out_object_size); |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
AWS_S3_API |
| 263 |
int aws_s3_parse_content_range_cursor( |
| 264 |
struct aws_byte_cursor content_range_cursor, |
| 265 |
uint64_t *out_range_start, |
| 266 |
uint64_t *out_range_end, |
| 267 |
uint64_t *out_object_size); |
| 268 |
|
| 269 |
|
| 270 |
AWS_S3_API |
| 271 |
int aws_s3_parse_content_length_response_header( |
| 272 |
struct aws_allocator *allocator, |
| 273 |
struct aws_http_headers *response_headers, |
| 274 |
uint64_t *out_content_length); |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
AWS_S3_API |
| 281 |
int aws_s3_parse_request_range_header( |
| 282 |
struct aws_http_headers *request_headers, |
| 283 |
bool *out_has_start_range, |
| 284 |
bool *out_has_end_range, |
| 285 |
uint64_t *out_start_range, |
| 286 |
uint64_t *out_end_range); |
| 287 |
|
| 288 |
|
| 289 |
AWS_S3_API |
| 290 |
uint32_t aws_s3_calculate_auto_ranged_get_num_parts( |
| 291 |
size_t part_size, |
| 292 |
uint64_t first_part_size, |
| 293 |
uint64_t object_range_start, |
| 294 |
uint64_t object_range_end); |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
AWS_S3_API |
| 303 |
int aws_s3_calculate_optimal_mpu_part_size_and_num_parts( |
| 304 |
uint64_t content_length, |
| 305 |
size_t client_part_size, |
| 306 |
uint64_t client_max_part_size, |
| 307 |
size_t *out_part_size, |
| 308 |
uint32_t *out_num_parts); |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
AWS_S3_API |
| 315 |
void aws_s3_calculate_auto_ranged_get_part_range( |
| 316 |
uint64_t object_range_start, |
| 317 |
uint64_t object_range_end, |
| 318 |
size_t part_size, |
| 319 |
uint64_t first_part_size, |
| 320 |
uint32_t part_number, |
| 321 |
uint64_t *out_part_range_start, |
| 322 |
uint64_t *out_part_range_end); |
| 323 |
|
| 324 |
|
| 325 |
AWS_S3_API |
| 326 |
int aws_s3_crt_error_code_from_recoverable_server_error_code_string(struct aws_byte_cursor error_code_string); |
| 327 |
|
| 328 |
AWS_S3_API |
| 329 |
void aws_s3_request_finish_up_metrics_synced(struct aws_s3_request *request, struct aws_s3_meta_request *meta_request); |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
AWS_S3_API |
| 334 |
int aws_s3_check_headers_for_checksum( |
| 335 |
struct aws_s3_meta_request *meta_request, |
| 336 |
const struct aws_http_headers *headers, |
| 337 |
struct aws_s3_checksum **out_checksum, |
| 338 |
struct aws_byte_buf *out_checksum_buffer, |
| 339 |
bool meta_request_level); |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
AWS_S3_API |
| 353 |
int aws_s3_calculate_client_optimal_range_size( |
| 354 |
uint64_t memory_limit_in_bytes, |
| 355 |
uint32_t max_connections, |
| 356 |
uint64_t *out_client_optimal_range_size); |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
AWS_S3_API |
| 370 |
int aws_s3_calculate_request_optimal_range_size( |
| 371 |
uint64_t client_optimal_range_size, |
| 372 |
uint64_t estimated_object_stored_part_size, |
| 373 |
bool is_express, |
| 374 |
uint64_t *out_request_optimal_range_size); |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
AWS_S3_API |
| 386 |
int aws_s3_extract_parts_from_etag(struct aws_byte_cursor etag_header_value, uint32_t *out_num_parts); |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
AWS_S3_API |
| 394 |
bool aws_s3_is_checksum_value_header_name(struct aws_byte_cursor header_name); |
| 395 |
|
| 396 |
AWS_EXTERN_C_END |
| 397 |
|
| 398 |
#endif |