backend.h (2232B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef VIADUCT_NECKO_H 6 #define VIADUCT_NECKO_H 7 8 #include <stdint.h> 9 #include <stddef.h> 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 // HTTP Method enumeration (must match Rust side) 16 enum ViaductMethod : uint8_t { 17 VIADUCT_METHOD_GET = 0, 18 VIADUCT_METHOD_HEAD = 1, 19 VIADUCT_METHOD_POST = 2, 20 VIADUCT_METHOD_PUT = 3, 21 VIADUCT_METHOD_DELETE = 4, 22 VIADUCT_METHOD_CONNECT = 5, 23 VIADUCT_METHOD_OPTIONS = 6, 24 VIADUCT_METHOD_TRACE = 7, 25 VIADUCT_METHOD_PATCH = 8, 26 }; 27 28 // Header structure 29 struct ViaductHeader { 30 const char* key; 31 const char* value; 32 }; 33 34 // Request structure 35 struct ViaductRequest { 36 uint32_t timeout; 37 uint32_t redirect_limit; 38 ViaductMethod method; 39 const char* url; 40 const ViaductHeader* headers; 41 size_t header_count; 42 const uint8_t* body; // Body remains uint8_t* since it's binary data 43 size_t body_len; 44 }; 45 46 // Opaque result pointer (points to Rust FfiResult) 47 struct ViaductResult; 48 49 // Functions that C++ must implement 50 void viaduct_necko_backend_init(); 51 void viaduct_necko_backend_send_request(const ViaductRequest* request, 52 ViaductResult* result); 53 54 // Functions that Rust provides for C++ to call 55 void viaduct_necko_result_set_url(ViaductResult* result, const char* url, 56 size_t length); 57 void viaduct_necko_result_set_status_code(ViaductResult* result, uint16_t code); 58 void viaduct_necko_result_add_header(ViaductResult* result, const char* key, 59 size_t key_length, const char* value, 60 size_t value_length); 61 void viaduct_necko_result_extend_body(ViaductResult* result, 62 const uint8_t* data, size_t length); 63 void viaduct_necko_result_complete(ViaductResult* result); 64 void viaduct_necko_result_complete_error(ViaductResult* result, 65 uint32_t error_code, 66 const char* message); 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #endif // VIADUCT_NECKO_H