From cd3f79d54479574b4e5a85a86b53b4bde5c3631d Mon Sep 17 00:00:00 2001 From: Patrick Grimm Date: Tue, 24 Sep 2024 23:24:28 +0200 Subject: [PATCH] Added ucix_get_list and ucix_set_list function (#780) --- src/bacnet/basic/ucix/ucix.c | 62 ++++++++++++++++++++++++++++++++++++ src/bacnet/basic/ucix/ucix.h | 15 +++++++++ 2 files changed, 77 insertions(+) diff --git a/src/bacnet/basic/ucix/ucix.c b/src/bacnet/basic/ucix/ucix.c index 1ba2cb4d..52565355 100644 --- a/src/bacnet/basic/ucix/ucix.c +++ b/src/bacnet/basic/ucix/ucix.c @@ -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) { diff --git a/src/bacnet/basic/ucix/ucix.h b/src/bacnet/basic/ucix/ucix.h index 9c5ea402..3226ff1c 100644 --- a/src/bacnet/basic/ucix/ucix.h +++ b/src/bacnet/basic/ucix/ucix.h @@ -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,