comparison s3/s3_uploader.c @ 255:5ec271d612ae

[dowa] Enforce arena ownership Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Tue, 04 Aug 2026 15:12:18 -0700
parents 240337164a80
children
comparison
equal deleted inserted replaced
254:2b6e732087ff 255:5ec271d612ae
71 const char *local_path, 71 const char *local_path,
72 const char *s3_key, 72 const char *s3_key,
73 const char *content_type) 73 const char *content_type)
74 { 74 {
75 S3_Result result = {0}; 75 S3_Result result = {0};
76 result.p_arena = Dowa_Arena_Create(S3_RESULT_ARENA_SIZE);
77 76
78 size_t file_size = 0; 77 size_t file_size = 0;
79 uint8 *file_data = s3__load_file(local_path, &file_size); 78 uint8 *file_data = s3__load_file(local_path, &file_size);
80 if (!file_data) 79 if (!file_data)
81 { 80 {
81 result.p_arena = Dowa_Arena_Create(S3_RESULT_ARENA_SIZE);
82 result.success = FALSE; 82 result.success = FALSE;
83 result.status_code = 0; 83 result.status_code = 0;
84 result.error_message = Dowa_String_Copy_Arena("Failed to read file", result.p_arena); 84 result.error_message = Dowa_String_Copy_Arena("Failed to read file", result.p_arena);
85 return result; 85 return result;
86 } 86 }
87 87
88 result = S3_Upload_Data(p_config, file_data, file_size, s3_key, content_type); 88 result = S3_Upload_Data(p_config, file_data, file_size, s3_key, content_type);
89 free(file_data); 89 Dowa_Free(file_data);
90 90
91 return result; 91 return result;
92 } 92 }
93 93
94 S3_Result S3_Upload_Data(const S3_Config *p_config, 94 S3_Result S3_Upload_Data(const S3_Config *p_config,
704 (const uint8 *)S3_SERVICE_NAME, strlen(S3_SERVICE_NAME), k_service); 704 (const uint8 *)S3_SERVICE_NAME, strlen(S3_SERVICE_NAME), k_service);
705 705
706 s3__hmac_sha256(k_service, 32, 706 s3__hmac_sha256(k_service, 32,
707 (const uint8 *)S3_AWS4_REQUEST, strlen(S3_AWS4_REQUEST), out); 707 (const uint8 *)S3_AWS4_REQUEST, strlen(S3_AWS4_REQUEST), out);
708 708
709 free(k_secret); 709 Dowa_Free(k_secret);
710 } 710 }
711 711
712 static char *s3__build_authorization_header(const char *access_key, 712 static char *s3__build_authorization_header(const char *access_key,
713 const char *date, 713 const char *date,
714 const char *region, 714 const char *region,
775 size_t read = fread(data, 1, (size_t)size, f); 775 size_t read = fread(data, 1, (size_t)size, f);
776 fclose(f); 776 fclose(f);
777 777
778 if (read != (size_t)size) 778 if (read != (size_t)size)
779 { 779 {
780 free(data); 780 Dowa_Free(data);
781 *p_size = 0; 781 *p_size = 0;
782 return NULL; 782 return NULL;
783 } 783 }
784 784
785 *p_size = (size_t)size; 785 *p_size = (size_t)size;