Skip to content

Commit

Permalink
make unlang_compile_subsectio() take a CONF_SECTION
Browse files Browse the repository at this point in the history
instead of name1/name2.
  • Loading branch information
alandekok committed Apr 18, 2019
1 parent 9bb891f commit 9b37972
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
46 changes: 29 additions & 17 deletions src/lib/server/virtual_servers.c
Expand Up @@ -1085,6 +1085,7 @@ int fr_app_process_instantiate(UNUSED CONF_SECTION *server, dl_instance_t **type
int virtual_server_compile_sections(CONF_SECTION *server, virtual_server_compile_t *list, vp_tmpl_rules_t const *rules)
{
int i;
CONF_SECTION *subcs = NULL;

/*
* The sections are in trees, so this isn't as bad as it
Expand All @@ -1094,28 +1095,39 @@ int virtual_server_compile_sections(CONF_SECTION *server, virtual_server_compile
for (i = 0; list[i].name != NULL; i++) {
int rcode;

/*
* We are looking for a specific subsection.
* Warn if it isn't found, or compile it if
* found.
*/
if (list[i].name2 != CF_IDENT_ANY) {
rcode = unlang_compile_subsection(server, list[i].name, list[i].name2, list[i].component, rules);
subcs = cf_section_find(server, list[i].name, list[i].name2);
if (!subcs) {
DEBUG3("Warning: Skipping %s %s { ... } as it was not found.",
list[i].name, list[i].name2);
continue;
}

rcode = unlang_compile_subsection(server, subcs, list[i].component, rules);
if (rcode < 0) return -1;
} else {
CONF_SECTION *subcs = NULL;
continue;
}

/*
* Find all subsections with the given first name.
*/
while ((subcs = cf_section_find_next(server, subcs, list[i].name, CF_IDENT_ANY))) {
char const *name2;
/*
* Find all subsections with the given first name
* and compile them.
*/
while ((subcs = cf_section_find_next(server, subcs, list[i].name, CF_IDENT_ANY))) {
char const *name2;

name2 = cf_section_name2(subcs);
if (!name2) {
cf_log_err(subcs, "Invalid '%s { ... }' section, it must have a name", list[i].name);
return -1;
}

// @todo - pass subcs here, so that we don't need to search for it by name
rcode = unlang_compile_subsection(server, list[i].name, name2, list[i].component, rules);
if (rcode < 0) return -1;
name2 = cf_section_name2(subcs);
if (!name2) {
cf_log_err(subcs, "Invalid '%s { ... }' section, it must have a name", list[i].name);
return -1;
}

rcode = unlang_compile_subsection(server, subcs, list[i].component, rules);
if (rcode < 0) return -1;
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/lib/unlang/compile.c
Expand Up @@ -3422,22 +3422,23 @@ int unlang_compile(CONF_SECTION *cs, rlm_components_t component, vp_tmpl_rules_t
* - 1 on successfully compiled
*
*/
int unlang_compile_subsection(CONF_SECTION *server_cs, char const *name1, char const *name2, rlm_components_t component,
int unlang_compile_subsection(CONF_SECTION *server_cs, CONF_SECTION *cs, rlm_components_t component,
vp_tmpl_rules_t const *rules)
{
CONF_SECTION *cs;

cs = cf_section_find(server_cs, name1, name2);
if (!cs) return 0;
char const *name1, *name2;

/*
* Don't print out debug messages twice.
* Don't compile it twice, and don't print out debug
* messages twice.
*/
if (cf_data_find(cs, unlang_group_t, NULL) != NULL) return 1;

name1 = cf_section_name1(cs);
name2 = cf_section_name2(cs);

if (!name2) name2 = "";

cf_log_debug(cs, "Compiling policies - %s %s {...}", name1, name2);
cf_log_debug(cs, "Compiling policies in - %s %s {...}", name1, name2);

if (unlang_compile(cs, component, rules) < 0) {
cf_log_err(cs, "Failed compiling '%s %s { ... }' section", name1, name2);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/unlang/compile.h
Expand Up @@ -34,7 +34,7 @@ extern "C" {

int unlang_compile(CONF_SECTION *cs, rlm_components_t component, vp_tmpl_rules_t const *rules);

int unlang_compile_subsection(CONF_SECTION *server_cs, char const *name1, char const *name2,
int unlang_compile_subsection(CONF_SECTION *server_cs, CONF_SECTION *subsection,
rlm_components_t component, vp_tmpl_rules_t const *rules);

bool unlang_compile_is_keyword(const char *name);
Expand Down

0 comments on commit 9b37972

Please sign in to comment.