Skip to content

Commit

Permalink
For -xxxx, print out the parsed sections of "unlang"
Browse files Browse the repository at this point in the history
So that we can see exactly what's been parsed, and what it has
been turned into
  • Loading branch information
alandekok committed Apr 20, 2014
1 parent dc790e4 commit 78cb3fd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 38 deletions.
2 changes: 2 additions & 0 deletions src/include/modcall.h
Expand Up @@ -45,6 +45,8 @@ void add_to_modcallable(modcallable *parent, modcallable *this);
/* Free a tree returned by compile_modgroup or compile_modsingle */
void modcallable_free(modcallable **pc);

void modcall_debug(modcallable *mc, int depth);

#ifdef __cplusplus
}
#endif
Expand Down
77 changes: 42 additions & 35 deletions src/main/modcall.c
Expand Up @@ -2689,7 +2689,11 @@ modcallable *compile_modgroup(modcallable *parent,
modcallable *ret = do_compile_modgroup(parent, component, cs,
GROUPTYPE_SIMPLE,
GROUPTYPE_SIMPLE, MOD_GROUP);
dump_tree(component, ret);

if (debug_flag > 3) {
modcall_debug(ret, 2);
}

return ret;
}

Expand Down Expand Up @@ -3280,102 +3284,105 @@ bool modcall_pass2(modcallable *mc)
return true;
}

#if 0
/*
* Future debugging.
*/
static void modcall_print_internal(FILE *fp, modcallable *mc, int depth)
void modcall_debug(modcallable *mc, int depth)
{
modcallable *this;
modgroup *g;
value_pair_map_t *map;
const char *name1;
char buffer[1024];

for (this = mc; this != NULL; this = this->next) {
switch (this->type) {
default:
fprintf(fp, "FIXME %s\n", group_name[this->type]);
break;

case MOD_SINGLE: {
modsingle *single = mod_callabletosingle(this);

fprintf(fp, "%.*s%s\n", depth, modcall_spaces,
DEBUG("%.*s%s", depth, modcall_spaces,
single->modinst->name);
}
break;

#ifdef WITH_UNLANG
case MOD_UPDATE:
g = mod_callabletogroup(this);
fprintf(fp, "%.*s%s {\n", depth, modcall_spaces,
DEBUG("%.*s%s {", depth, modcall_spaces,
group_name[this->type]);

for (map = g->map; map != NULL; map = map->next) {
radius_map2str(buffer, sizeof(buffer), map);
fprintf(fp, "%.*s%s\n", depth + 1, modcall_spaces, buffer);
DEBUG("%.*s%s", depth + 1, modcall_spaces, buffer);
}

fprintf(fp, "%.*s}\n", depth, modcall_spaces);
DEBUG("%.*s}", depth, modcall_spaces);
break;

case MOD_ELSE:
fprintf(fp, "%.*s%s{\n", depth, modcall_spaces,
DEBUG("%.*s%s {", depth, modcall_spaces,
group_name[this->type]);
modcall_print_internal(fp, g->children, depth + 1);
fprintf(fp, "%.*s}\n", depth, modcall_spaces);
modcall_debug(g->children, depth + 1);
DEBUG("%.*s}", depth, modcall_spaces);
break;

case MOD_IF:
case MOD_ELSIF:
g = mod_callabletogroup(this);
fr_cond_sprint(buffer, sizeof(buffer), g->cond);
fprintf(fp, "%.*s%s (%s) {\n", depth, modcall_spaces,
DEBUG("%.*s%s (%s) {", depth, modcall_spaces,
group_name[this->type], buffer);
modcall_print_internal(fp, g->children, depth + 1);
fprintf(fp, "%.*s}\n", depth, modcall_spaces);
modcall_debug(g->children, depth + 1);
DEBUG("%.*s}", depth, modcall_spaces);
break;

case MOD_SWITCH:
case MOD_CASE:
g = mod_callabletogroup(this);
radius_tmpl2str(buffer, sizeof(buffer), g->vpt);
fprintf(fp, "%.*s%s %s {\n", depth, modcall_spaces,
DEBUG("%.*s%s %s {", depth, modcall_spaces,
group_name[this->type], buffer);
modcall_print_internal(fp, g->children, depth + 1);
fprintf(fp, "%.*s}\n", depth, modcall_spaces);
modcall_debug(g->children, depth + 1);
DEBUG("%.*s}", depth, modcall_spaces);
break;

case MOD_POLICY:
case MOD_FOREACH:
g = mod_callabletogroup(this);
fprintf(fp, "%.*s%s %s {\n", depth, modcall_spaces,
DEBUG("%.*s%s %s {", depth, modcall_spaces,
group_name[this->type], this->name);
modcall_print_internal(fp, g->children, depth + 1);
fprintf(fp, "%.*s}\n", depth, modcall_spaces);
modcall_debug(g->children, depth + 1);
DEBUG("%.*s}", depth, modcall_spaces);
break;

case MOD_BREAK:
fprintf(fp, "%.*sbreak\n", depth, modcall_spaces);
DEBUG("%.*sbreak", depth, modcall_spaces);
break;

#endif
case MOD_GROUP:
case MOD_REDUNDANT:
g = mod_callabletogroup(this);
name1 = cf_section_name1(g->cs);
if (strcmp(name1, "group") == 0) {
DEBUG("%.*s%s {", depth, modcall_spaces,
group_name[this->type]);
} else {
DEBUG("%.*s%s %s {", depth, modcall_spaces,
name1, cf_section_name2(g->cs));
}
modcall_debug(g->children, depth + 1);
DEBUG("%.*s}", depth, modcall_spaces);
break;


case MOD_LOAD_BALANCE:
case MOD_REDUNDANT_LOAD_BALANCE:
g = mod_callabletogroup(this);
fprintf(fp, "%.*s%s {\n", depth, modcall_spaces,
DEBUG("%.*s%s {", depth, modcall_spaces,
group_name[this->type]);
modcall_print_internal(fp, g->children, depth + 1);
fprintf(fp, "%.*s}\n", depth, modcall_spaces);
modcall_debug(g->children, depth + 1);
DEBUG("%.*s}", depth, modcall_spaces);
break;
}
}
}

void modcall_fprint(FILE *fp, modcallable *mc)
{
DEBUG("*****************************************");
return modcall_print_internal(fp, mc, 0);
}
#endif
18 changes: 15 additions & 3 deletions src/main/modules.c
Expand Up @@ -920,6 +920,7 @@ static int load_component_section(CONF_SECTION *cs,
components,
da,
comp)) {

return -1; /* FIXME: memleak? */
}
continue;
Expand Down Expand Up @@ -1018,9 +1019,12 @@ static int load_component_section(CONF_SECTION *cs,
return -1;
}

if (debug_flag > 2) modcall_debug(this, 2);

add_to_modcallable(subcomp->modulelist, this);
}


return 0;
}

Expand Down Expand Up @@ -1137,9 +1141,6 @@ static int load_byserver(CONF_SECTION *cs)

if (cf_item_find_next(subcs, NULL) == NULL) continue;

cf_log_module(cs, "Loading %s {...}",
section_type_value[comp].section);

/*
* Skip pre/post-proxy sections if we're not
* proxying.
Expand All @@ -1161,10 +1162,21 @@ static int load_byserver(CONF_SECTION *cs)
if (comp == RLM_COMPONENT_SESS) continue;
#endif

if (debug_flag <= 3) {
cf_log_module(cs, "Loading %s {...}",
section_type_value[comp].section);
} else {
DEBUG(" %s {", section_type_value[comp].section);
}

if (load_component_section(subcs, components, comp) < 0) {
goto error;
}

if (debug_flag > 3) {
DEBUG(" } # %s", section_type_value[comp].section);
}

/*
* Cache a default, if it exists. Some people
* put empty sections for some reason...
Expand Down

0 comments on commit 78cb3fd

Please sign in to comment.