22 #include "config-rest-api.h"
24 #include <config/config.h>
25 #include <rapidjson/document.h>
26 #include <rapidjson/pointer.h>
27 #include <webview/rest_api_manager.h>
40 :
Thread(
"ConfigurationRestApi",
Thread::OPMODE_WAITFORWAKEUP)
55 std::bind(&ConfigurationRestApi::cb_get_config,
57 std::placeholders::_1));
73 static rapidjson::Value
74 create_value(std::unique_ptr<fawkes::Configuration::ValueIterator> &i,
75 rapidjson::Document::AllocatorType & a)
83 for (
const auto &ivsv : ivs) {
84 v.PushBack(rapidjson::Value(ivsv).Move(), a);
87 std::vector<unsigned int> ivs = i->
get_uints();
88 for (
const auto &ivsv : ivs) {
89 v.PushBack(rapidjson::Value(ivsv).Move(), a);
92 std::vector<int> ivs = i->
get_ints();
93 for (
const auto &ivsv : ivs) {
94 v.PushBack(rapidjson::Value(ivsv).Move(), a);
98 for (
const auto &ivsv : ivs) {
99 v.PushBack(rapidjson::Value(ivsv).Move(), a);
103 for (
const auto &ivsv : ivs) {
104 v.PushBack(rapidjson::Value(ivsv, a).Move(), a);
126 std::string query{params.
query_arg(
"query")};
132 std::shared_ptr<rapidjson::Document> d = std::make_shared<rapidjson::Document>();
133 rapidjson::Document::AllocatorType & a = d->GetAllocator();
137 std::unique_ptr<fawkes::Configuration::ValueIterator> i{
config->
search(query.c_str())};
139 std::vector<std::string> path_elements{str_split(i->
path(),
'/')};
140 rapidjson::Value::MemberIterator parent = d->MemberEnd();
142 rapidjson::Value::MemberIterator m = d->MemberBegin();
143 rapidjson::Value::MemberIterator m_end = d->MemberEnd();
145 if (path_elements.size() > 1) {
146 for (
size_t p = 0; p < path_elements.size() - 1; ++p) {
147 m = std::find_if(m, m_end, [&path_elements, &p](
const auto &v) {
148 return path_elements[p] == v.name.GetString();
153 if (parent != d->MemberEnd()) {
154 parent->value.AddMember(rapidjson::Value(path_elements[p], a).Move(),
155 rapidjson::Value(rapidjson::kObjectType).Move(),
157 parent = parent->value.FindMember(path_elements[p].c_str());
159 d->AddMember(rapidjson::Value(path_elements[p], a).Move(),
160 rapidjson::Value(rapidjson::kObjectType).Move(),
162 parent = d->FindMember(path_elements[p].c_str());
165 m = parent->value.MemberBegin();
166 m_end = parent->value.MemberEnd();
169 if (parent == d->MemberEnd()) {
170 d->AddMember(rapidjson::Value(path_elements.back(), a).Move(),
171 create_value(i, a).Move(),
174 parent->value.AddMember(rapidjson::Value(path_elements.back(), a).Move(),
175 create_value(i, a).Move(),