For -xxxx, print out the parsed sections of "unlang"
authorAlan T. DeKok <aland@freeradius.org>
Sun, 20 Apr 2014 21:11:47 +0000 (17:11 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 20 Apr 2014 21:11:47 +0000 (17:11 -0400)
So that we can see exactly what's been parsed, and what it has
been turned into

src/include/modcall.h
src/main/modcall.c
src/main/modules.c

index d6257a0..f14a1b5 100644 (file)
@@ -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
index f34c03a..a3fff9f 100644 (file)
@@ -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;
 }
 
@@ -3280,27 +3284,23 @@ 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;
@@ -3308,74 +3308,81 @@ static void modcall_print_internal(FILE *fp, modcallable *mc, int depth)
 #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
index 0156f10..10ed5ec 100644 (file)
@@ -920,6 +920,7 @@ static int load_component_section(CONF_SECTION *cs,
                                                               components,
                                                               da,
                                                               comp)) {
+
                                        return -1; /* FIXME: memleak? */
                                }
                                continue;
@@ -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;
 }
 
@@ -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.
@@ -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...