From: Alan T. DeKok Date: Sun, 13 Mar 2011 09:02:06 +0000 (+0100) Subject: Added cf_section_find_name2() API X-Git-Tag: release_2_1_11~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f5f36452d233dcc96d6f1847ef141c4017cbee5;p=thirdparty%2Ffreeradius-server.git Added cf_section_find_name2() API This lets us find the next section by name1 and name2 --- diff --git a/src/include/conffile.h b/src/include/conffile.h index 55d41779336..ee899a9205a 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -64,6 +64,8 @@ int cf_file_include(const char *file, CONF_SECTION *cs); CONF_PAIR *cf_pair_find(const CONF_SECTION *, const char *name); CONF_PAIR *cf_pair_find_next(const CONF_SECTION *, CONF_PAIR *, const char *name); CONF_SECTION *cf_section_find(const char *name); +CONF_SECTION *cf_section_find_name2(const CONF_SECTION *section, + const char *name1, const char *name2); CONF_SECTION *cf_section_sub_find(const CONF_SECTION *, const char *name); CONF_SECTION *cf_section_sub_find_name2(const CONF_SECTION *, const char *name1, const char *name2); const char *cf_section_value_find(const CONF_SECTION *, const char *attr); diff --git a/src/main/conffile.c b/src/main/conffile.c index fdeb7b38ff4..0e57ddaa116 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -1947,6 +1947,33 @@ const char *cf_section_value_find(const CONF_SECTION *cs, const char *attr) return (cp ? cp->value : NULL); } + +CONF_SECTION *cf_section_find_name2(const CONF_SECTION *section, + const char *name1, const char *name2) +{ + const char *their2; + CONF_ITEM *ci; + + if (!section || !name1) return NULL; + + for (ci = cf_sectiontoitem(section); ci; ci = ci->next) { + if (ci->type != CONF_ITEM_SECTION) + continue; + + if (strcmp(cf_itemtosection(ci)->name1, name1) != 0) + continue; + + their2 = cf_itemtosection(ci)->name2; + + if ((!name2 && !their2) || + (name2 && their2 && (strcmp(name2, their2) == 0))) { + return cf_itemtosection(ci); + } + } + + return NULL; +} + /* * Return the next pair after a CONF_PAIR * with a certain name (char *attr) If the requested