s3_request.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "aws/s3/private/s3_request.h"
  2. #include "aws/s3/private/s3_meta_request_impl.h"
  3. #include <aws/auth/signable.h>
  4. #include <aws/io/stream.h>
  5. static void s_s3_request_destroy(void *user_data);
  6. struct aws_s3_request *aws_s3_request_new(
  7. struct aws_s3_meta_request *meta_request,
  8. int request_tag,
  9. uint32_t part_number,
  10. uint32_t flags) {
  11. AWS_PRECONDITION(meta_request);
  12. AWS_PRECONDITION(meta_request->allocator);
  13. struct aws_s3_request *request = aws_mem_calloc(meta_request->allocator, 1, sizeof(struct aws_s3_request));
  14. aws_ref_count_init(&request->ref_count, request, (aws_simple_completion_callback *)s_s3_request_destroy);
  15. request->allocator = meta_request->allocator;
  16. request->meta_request = aws_s3_meta_request_acquire(meta_request);
  17. request->request_tag = request_tag;
  18. request->part_number = part_number;
  19. request->record_response_headers = (flags & AWS_S3_REQUEST_FLAG_RECORD_RESPONSE_HEADERS) != 0;
  20. request->part_size_response_body = (flags & AWS_S3_REQUEST_FLAG_PART_SIZE_RESPONSE_BODY) != 0;
  21. request->always_send = (flags & AWS_S3_REQUEST_FLAG_ALWAYS_SEND) != 0;
  22. return request;
  23. }
  24. void aws_s3_request_setup_send_data(struct aws_s3_request *request, struct aws_http_message *message) {
  25. AWS_PRECONDITION(request);
  26. AWS_PRECONDITION(message);
  27. aws_s3_request_clean_up_send_data(request);
  28. request->send_data.message = message;
  29. aws_http_message_acquire(message);
  30. }
  31. static void s_s3_request_clean_up_send_data_message(struct aws_s3_request *request) {
  32. AWS_PRECONDITION(request);
  33. struct aws_http_message *message = request->send_data.message;
  34. if (message == NULL) {
  35. return;
  36. }
  37. request->send_data.message = NULL;
  38. aws_http_message_release(message);
  39. }
  40. void aws_s3_request_clean_up_send_data(struct aws_s3_request *request) {
  41. AWS_PRECONDITION(request);
  42. s_s3_request_clean_up_send_data_message(request);
  43. aws_signable_destroy(request->send_data.signable);
  44. request->send_data.signable = NULL;
  45. aws_http_headers_release(request->send_data.response_headers);
  46. request->send_data.response_headers = NULL;
  47. aws_byte_buf_clean_up(&request->send_data.response_body);
  48. AWS_ZERO_STRUCT(request->send_data);
  49. }
  50. void aws_s3_request_acquire(struct aws_s3_request *request) {
  51. AWS_PRECONDITION(request);
  52. aws_ref_count_acquire(&request->ref_count);
  53. }
  54. void aws_s3_request_release(struct aws_s3_request *request) {
  55. if (request == NULL) {
  56. return;
  57. }
  58. aws_ref_count_release(&request->ref_count);
  59. }
  60. static void s_s3_request_destroy(void *user_data) {
  61. struct aws_s3_request *request = user_data;
  62. if (request == NULL) {
  63. return;
  64. }
  65. aws_s3_request_clean_up_send_data(request);
  66. aws_byte_buf_clean_up(&request->request_body);
  67. aws_s3_meta_request_release(request->meta_request);
  68. aws_mem_release(request->allocator, request);
  69. }