2020-10-17 14:29:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "xmlparams.h"
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
struct xml_params *alloc_xml_params()
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
return new xml_params;
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
void free_xml_params(struct xml_params *params)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
delete params;
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
void xml_params_resize(struct xml_params *params, int count)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
params->items.resize(count);
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
void xml_params_add(struct xml_params *params, const char *key, const char *value)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
params->items.push_back({ std::string(key), std::string(value) });
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
void xml_params_add_int(struct xml_params *params, const char *key, int value)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
params->items.push_back({ std::string(key), std::to_string(value) });
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
int xml_params_count(const struct xml_params *params)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
return (int)params->items.size();
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
const char *xml_params_get_key(const struct xml_params *params, int idx)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
return params->items[idx].first.c_str();
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
const char *xml_params_get_value(const struct xml_params *params, int idx)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
return params->items[idx].second.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void xml_params_set_value(struct xml_params *params, int idx, const char *value)
|
|
|
|
{
|
|
|
|
if (idx < 0 || idx >= (int)params->items.size())
|
|
|
|
return;
|
|
|
|
params->items[idx].second = value;
|
|
|
|
}
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
const char **xml_params_get(const struct xml_params *params)
|
2020-10-17 14:29:32 +00:00
|
|
|
{
|
|
|
|
if (!params)
|
|
|
|
return nullptr;
|
|
|
|
params->data.resize(params->items.size() * 2 + 1);
|
|
|
|
for (size_t i = 0; i < params->items.size(); ++i) {
|
|
|
|
params->data[i * 2] = params->items[i].first.c_str();
|
|
|
|
params->data[i * 2 + 1] = params->items[i].second.c_str();
|
|
|
|
}
|
|
|
|
params->data[params->items.size() * 2] = nullptr;
|
|
|
|
return params->data.data();
|
|
|
|
}
|