Added cf_section_find_name2() API
authorAlan T. DeKok <aland@freeradius.org>
Sun, 13 Mar 2011 09:02:06 +0000 (10:02 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 13 Mar 2011 09:02:06 +0000 (10:02 +0100)
This lets us find the next section by name1 and name2

src/include/conffile.h
src/main/conffile.c

index 55d4177..ee899a9 100644 (file)
@@ -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);
index fdeb7b3..0e57dda 100644 (file)
@@ -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