@@ -2686,25 +2686,44 @@ Result<ConfigStore> ConfigStore::open(std::string_view name) {
2686
2686
}
2687
2687
2688
2688
Result<std::optional<HostString>> ConfigStore::get (std::string_view name) {
2689
+ return this ->get (name, CONFIG_STORE_INITIAL_BUF_LEN);
2690
+ }
2691
+
2692
+ Result<std::optional<HostString>> ConfigStore::get (std::string_view name, uint32_t initial_buf_len) {
2689
2693
TRACE_CALL ()
2690
2694
Result<std::optional<HostString>> res;
2691
2695
2692
2696
auto name_str = string_view_to_world_string (name);
2693
2697
fastly::fastly_world_string ret;
2694
2698
fastly::fastly_host_error err;
2695
- ret.ptr = static_cast <uint8_t *>(cabi_malloc (CONFIG_STORE_ENTRY_MAX_LEN, 1 ));
2696
- if (!convert_result (fastly::config_store_get (this ->handle , reinterpret_cast <char *>(name_str.ptr ),
2699
+ uint32_t buf_len{initial_buf_len};
2700
+
2701
+ ret.ptr = static_cast <uint8_t *>(cabi_malloc (buf_len, 1 ));
2702
+
2703
+ bool succeeded{convert_result (fastly::config_store_get (this ->handle , reinterpret_cast <char *>(name_str.ptr ),
2697
2704
name_str.len , reinterpret_cast <char *>(ret.ptr ),
2698
- CONFIG_STORE_ENTRY_MAX_LEN, &ret.len ),
2699
- &err)) {
2705
+ buf_len, &ret.len ),
2706
+ &err)};
2707
+
2708
+ if (!succeeded && err == FASTLY_HOST_ERROR_BUFFER_LEN) {
2709
+ buf_len = ret.len ;
2710
+ ret.len = 0 ;
2711
+ ret.ptr = static_cast <uint8_t *>(cabi_realloc (ret.ptr , initial_buf_len, 1 , buf_len));
2712
+ succeeded = convert_result (fastly::config_store_get (this ->handle , reinterpret_cast <char *>(name_str.ptr ),
2713
+ name_str.len , reinterpret_cast <char *>(ret.ptr ),
2714
+ buf_len, &ret.len ),
2715
+ &err);
2716
+ }
2717
+
2718
+ if (!succeeded) {
2700
2719
cabi_free (ret.ptr );
2701
2720
if (error_is_optional_none (err)) {
2702
2721
res.emplace (std::nullopt );
2703
2722
} else {
2704
2723
res.emplace_err (err);
2705
2724
}
2706
2725
} else {
2707
- ret.ptr = static_cast <uint8_t *>(cabi_realloc (ret.ptr , CONFIG_STORE_ENTRY_MAX_LEN , 1 , ret.len ));
2726
+ ret.ptr = static_cast <uint8_t *>(cabi_realloc (ret.ptr , buf_len , 1 , ret.len ));
2708
2727
res.emplace (make_host_string (ret));
2709
2728
}
2710
2729
0 commit comments