Added ucix_get_list and ucix_set_list function (#780)

This commit is contained in:
Patrick Grimm
2024-09-24 23:24:28 +02:00
committed by GitHub
parent 93afcfe062
commit cd3f79d544
2 changed files with 77 additions and 0 deletions
+62
View File
@@ -107,6 +107,45 @@ const char *ucix_get_option(
return value;
}
int ucix_get_list(
char *value[254],
struct uci_context *ctx,
const char *p,
const char *s,
const char *o)
{
struct uci_element *e = NULL;
int n;
if (ucix_get_ptr(ctx, p, s, o, NULL)) {
return 0;
}
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
return 0;
}
e = ptr.last;
switch (e->type) {
case UCI_TYPE_OPTION:
switch (ptr.o->type) {
case UCI_TYPE_LIST:
n = 0;
uci_foreach_element(&ptr.o->v.list, e)
{
value[n] = e->name;
n++;
}
break;
default:
n = 0;
break;
}
break;
default:
return 0;
}
return n;
}
int ucix_get_option_int(
struct uci_context *ctx,
const char *p,
@@ -145,6 +184,29 @@ void ucix_add_option(
uci_set(ctx, &ptr);
}
void ucix_set_list(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o,
char value[254][64],
int l)
{
int i;
ucix_get_ptr(ctx, p, s, o, NULL);
uci_delete(ctx, &ptr);
uci_save(ctx, NULL);
for (i = 0; i < l; i++) {
if (value[i]) {
ucix_get_ptr(ctx, p, s, o, value[i]);
uci_add_list(ctx, &ptr);
} else {
ucix_get_ptr(ctx, p, s, o, NULL);
uci_add_list(ctx, &ptr);
}
}
}
void ucix_add_option_int(
struct uci_context *ctx, const char *p, const char *s, const char *o, int t)
{
+15
View File
@@ -24,6 +24,13 @@ BACNET_STACK_EXPORT
const char *ucix_get_option(
struct uci_context *ctx, const char *p, const char *s, const char *o);
BACNET_STACK_EXPORT
int ucix_get_list(
char *value[254],
struct uci_context *ctx,
const char *p,
const char *s,
const char *o);
BACNET_STACK_EXPORT
int ucix_get_option_int(
struct uci_context *ctx,
const char *p,
@@ -41,6 +48,14 @@ void ucix_add_option(
const char *o,
const char *t);
BACNET_STACK_EXPORT
BACNET_STACK_EXPORT
void ucix_set_list(
struct uci_context *ctx,
const char *p,
const char *s,
const char *o,
char value[254][64],
int l);
void ucix_add_option_int(
struct uci_context *ctx,
const char *p,