Skip to content

Commit

Permalink
make process_template() take stack
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Nov 11, 2019
1 parent 767f1b7 commit 12264a0
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/lib/server/cf_file.c
Expand Up @@ -991,39 +991,43 @@ static int process_include(cf_stack_t *stack, CONF_SECTION *parent, char const *
}


static int process_template(CONF_SECTION *parent, char const *ptr, char *buff[static 4], char const *filename, int lineno)
static int process_template(cf_stack_t *stack)
{
CONF_ITEM *ci;
CONF_SECTION *parent_cs, *templatecs;
FR_TOKEN token;
cf_stack_frame_t *frame = &stack->frame[stack->depth];
CONF_SECTION *parent = frame->current;

token = getword(&ptr, buff[2], talloc_array_length(buff[2]), true);
token = getword(&stack->ptr, stack->buff[2], stack->bufsize, true);
if (token != T_EOL) {
ERROR("%s[%d]: Unexpected text after $TEMPLATE", filename, lineno);
ERROR("%s[%d]: Unexpected text after $TEMPLATE", frame->filename, frame->lineno);
return -1;
}

parent_cs = cf_root(parent);

templatecs = cf_section_find(parent_cs, "templates", NULL);
if (!templatecs) {
ERROR("%s[%d]: No \"templates\" section for reference \"%s\"", filename, lineno, buff[2]);
if (!parent) {
ERROR("%s[%d]: Internal sanity check error in template reference", frame->filename, frame->lineno);
return -1;
}

ci = cf_reference_item(parent_cs, templatecs, buff[2]);
if (!ci || (ci->type != CONF_ITEM_SECTION)) {
ERROR("%s[%d]: Reference \"%s\" not found", filename, lineno, buff[2]);
if (parent->template) {
ERROR("%s[%d]: Section already has a template", frame->filename, frame->lineno);
return -1;
}

if (!parent) {
ERROR("%s[%d]: Internal sanity check error in template reference", filename, lineno);
parent_cs = cf_root(parent);

templatecs = cf_section_find(parent_cs, "templates", NULL);
if (!templatecs) {
ERROR("%s[%d]: No \"templates\" section for reference \"%s\"",
frame->filename, frame->lineno, stack->buff[2]);
return -1;
}

if (parent->template) {
ERROR("%s[%d]: Section already has a template", filename, lineno);
ci = cf_reference_item(parent_cs, templatecs, stack->buff[2]);
if (!ci || (ci->type != CONF_ITEM_SECTION)) {
ERROR("%s[%d]: Reference \"%s\" not found",
frame->filename, frame->lineno, stack->buff[2]);
return -1;
}

Expand Down Expand Up @@ -1888,7 +1892,9 @@ static int cf_file_include(cf_stack_t *stack)
ptr += 9;
fr_skip_whitespace(ptr);

if (process_template(parent, ptr, buff, frame->filename, frame->lineno) < 0) goto error;
stack->ptr = ptr;
if (process_template(stack) < 0) goto error;
ptr = stack->ptr;
continue;
}

Expand Down

0 comments on commit 12264a0

Please sign in to comment.