From 20f59ee12e141cbf47f64ff7cd072a1e9363e0c8 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 12 May 2016 15:38:22 -0700 Subject: [PATCH] conf: Add configuration file iteration functions These allow linear searches of the configuration file sections. Change-Id: I8d8b9594bc8a974c16d999689a6195434c1efac8 Signed-off-by: Ben Walker --- include/spdk/conf.h | 4 ++++ lib/conf/conf.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/spdk/conf.h b/include/spdk/conf.h index 00d20efe0..63beea2ca 100644 --- a/include/spdk/conf.h +++ b/include/spdk/conf.h @@ -70,6 +70,10 @@ void spdk_conf_free(struct spdk_conf *cp); int spdk_conf_read(struct spdk_conf *cp, const char *file); struct spdk_conf_section *spdk_conf_find_section(struct spdk_conf *cp, const char *name); +/* Configuration file iteration */ +struct spdk_conf_section *spdk_conf_first_section(struct spdk_conf *cp); +struct spdk_conf_section *spdk_conf_next_section(struct spdk_conf_section *sp); + bool spdk_conf_section_match_prefix(const struct spdk_conf_section *sp, const char *name_prefix); char *spdk_conf_section_get_nmval(struct spdk_conf_section *sp, const char *key, int idx1, int idx2); diff --git a/lib/conf/conf.c b/lib/conf/conf.c index 146ec252d..0ed07891f 100644 --- a/lib/conf/conf.c +++ b/lib/conf/conf.c @@ -215,6 +215,27 @@ spdk_conf_find_section(struct spdk_conf *cp, const char *name) return NULL; } +struct spdk_conf_section * +spdk_conf_first_section(struct spdk_conf *cp) +{ + cp = CHECK_CP_OR_USE_DEFAULT(cp); + if (cp == NULL) { + return NULL; + } + + return cp->section; +} + +struct spdk_conf_section * +spdk_conf_next_section(struct spdk_conf_section *sp) +{ + if (sp == NULL) { + return NULL; + } + + return sp->next; +} + static void append_cf_section(struct spdk_conf *cp, struct spdk_conf_section *sp) {