MCPcopy Create free account
hub / github.com/baidu/openrasp / fetch_string

Method fetch_string

agent/php5/utils/json_reader.cc:53–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53std::string JsonReader::fetch_string(const std::vector<std::string> &keys, const std::string &default_value,
54 const std::function<std::string(const std::string &value)> &validator)
55{
56 json::json_pointer ptr = json::json_pointer(to_json_pointer(keys));
57 try
58 {
59 std::string result;
60 if (j.at(ptr).is_string())
61 {
62 result = j.at(ptr).get<std::string>();
63 }
64 else if (j.at(ptr).is_number())
65 {
66 result = std::to_string(j.at(ptr).get<int64_t>());
67 }
68 else
69 {
70 throw nlohmann::detail::other_error::create(900, "type should be string");
71 }
72 if (nullptr != validator)
73 {
74 std::string error_description = validator(result);
75 if (!error_description.empty())
76 {
77 throw nlohmann::detail::other_error::create(901, error_description);
78 }
79 }
80 return result;
81 }
82 catch (const nlohmann::detail::exception &e)
83 {
84 if (get_exception_report())
85 {
86 openrasp_error(LEVEL_WARNING, CONFIG_ERROR, _("%s, config \"%s\" use the default value \"%s\""),
87 e.what(), BaseReader::stringfy_keys(keys).c_str(), default_value.c_str());
88 }
89 }
90 return default_value;
91}
92
93int64_t JsonReader::fetch_int64(const std::vector<std::string> &keys, const int64_t &default_value,
94 const std::function<std::string(int64_t value)> &validator)

Callers 8

updateMethod · 0.45
agent_remote_registerMethod · 0.45
LogCollectItemMethod · 0.45
log_content_qualifiedMethod · 0.45
do_heartbeatMethod · 0.45
get_dependencyMethod · 0.45

Calls 5

to_json_pointerFunction · 0.70
openrasp_errorFunction · 0.50
_Function · 0.50
emptyMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected