Skip to content

Commit

Permalink
T6717: split validate and set functions
Browse files Browse the repository at this point in the history
Separate the application of validators from the cstore update.
  • Loading branch information
jestabro committed Oct 24, 2024
1 parent 9d47872 commit 39ec15b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/vy_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ vy_in_session(uint64_t handle)
return h->inSession() ? 1 : 0;
}

const char *
vy_validate_path(uint64_t handle, const void** path_ptr, size_t len)
{
Cstore *cstore = cstore_of_handle(handle);
const char **path = (const char **) path_ptr;
Cpath path_comps = Cpath(path, len);
const char *out_data;
std::string out_str = "";
int res;

out_stream = stdout;
stdout_redirect redirect = stdout_redirect();

res = cstore->validateSetPath(path_comps);
if (!res) {
out_str = "\nInvalid set path: " + path_comps.to_string() + "\n";
out_str.append(redirect.get_redirected_output());
}

out_data = out_data_copy(out_str);
out_stream = NULL;
return out_data;
}

const char *
vy_set_path(uint64_t handle, const void** path_ptr, size_t len)
{
Expand All @@ -148,6 +172,30 @@ vy_set_path(uint64_t handle, const void** path_ptr, size_t len)
out_stream = stdout;
stdout_redirect redirect = stdout_redirect();

res = cstore->setCfgPath(path_comps);
if (!res) {
out_str = "\nSet config path failed: " + path_comps.to_string() + "\n";
out_str.append(redirect.get_redirected_output());
}

out_data = out_data_copy(out_str);
out_stream = NULL;
return out_data;
}

const char *
vy_legacy_set_path(uint64_t handle, const void** path_ptr, size_t len)
{
Cstore *cstore = cstore_of_handle(handle);
const char **path = (const char **) path_ptr;
Cpath path_comps = Cpath(path, len);
const char *out_data;
std::string out_str = "";
int res;

out_stream = stdout;
stdout_redirect redirect = stdout_redirect();

res = cstore->validateSetPath(path_comps);
if (!res) {
out_str = "\nInvalid set path: " + path_comps.to_string() + "\n";
Expand Down
2 changes: 2 additions & 0 deletions src/vy_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ extern "C" {
uint64_t vy_cstore_init(void);
void vy_cstore_free(uint64_t);
int vy_in_session(uint64_t);
const char *vy_validate_path(uint64_t, const void **, size_t);
const char *vy_set_path(uint64_t, const void **, size_t);
const char *vy_legacy_set_path(uint64_t, const void **, size_t);
const char *vy_delete_path(uint64_t, const void **, size_t);

#ifdef __cplusplus
Expand Down

0 comments on commit 39ec15b

Please sign in to comment.