/[pdpsoft]/trunk/grid-mw-security/ees/src/eval_man/pdl.c
ViewVC logotype

Diff of /trunk/grid-mw-security/ees/src/eval_man/pdl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1145 by aramv, Thu Nov 19 14:40:54 2009 UTC revision 1146 by aramv, Thu Nov 19 16:35:31 2009 UTC
# Line 43  EES_RC pdl_init(const char* config_file_ Line 43  EES_RC pdl_init(const char* config_file_
43        if(initialize_plugins() == EES_SUCCESS){        if(initialize_plugins() == EES_SUCCESS){
44          temp_plugin = build_plugin_tree(policies_list);          temp_plugin = build_plugin_tree(policies_list);
45          print_plugin_tree_recursive(temp_plugin, 0);          print_plugin_tree_recursive(temp_plugin, 0);
   
46          return EES_SUCCESS;          return EES_SUCCESS;
47        } else {        } else {
48          eef_log(LOG_ERR, "Failed to initialize plug-ins from policy config file %s\n", config_file_s);          eef_log(LOG_ERR, "Failed to initialize plug-ins from policy config file %s\n", config_file_s);
# Line 57  EES_RC pdl_init(const char* config_file_ Line 56  EES_RC pdl_init(const char* config_file_
56    return EES_FAILURE;    return EES_FAILURE;
57  }  }
58    
59  /* TODO fix this */  /* TODO the retrieving of plugins could really be more efficient - it should be possible to only store argv[0] in the string-based policy tree */
60  /* builds a tree of eef_plugindl_t structs, which hold pointers to initialized plugins retrieved from the plugin manager */  /* builds a tree of eef_plugindl_t structs, which hold pointers to initialized plugins retrieved from the plugin manager */
61  eef_plugindl_t* build_plugin_tree(policy_t* policies){  eef_plugindl_t* build_plugin_tree(policy_t* policies){
62    policy_t        *temp_policy        = policies;    policy_t        *temp_policy        = policies;
63    eef_plugindl_t  *temp_plugin_rule   = NULL , *temp_plugin_rule_last = NULL, *plugin_tree  = NULL, *plugin_tree_last = NULL, *temp_plugin_node = NULL;    eef_plugindl_t  *temp_plugin_rules  = NULL , *temp_plugin_rules_last = NULL, *plugin_tree  = NULL, *plugin_tree_last = NULL, *temp_plugin_node = NULL;
64    rule_t          *temp_rule          = NULL;    rule_t          *temp_rule          = NULL;
   /*plugin_tree = calloc(1,sizeof(eef_plugindl_t));*/  
65    char**    argv;    char**    argv;
66    int       argc;    int       argc;
67    
68    while(temp_policy){    while(temp_policy){
69      temp_rule = temp_policy->rules;      temp_rule = temp_policy->rules;
     eef_log(LOG_DEBUG, "Policy: %s\n", temp_policy->name);  
70      while(temp_rule){      while(temp_rule){
71          /* find plug-in described by rule */
72        argv = _var_to_argv(get_variable_by_name(temp_rule->state)->value, &argc);        argv = _var_to_argv(get_variable_by_name(temp_rule->state)->value, &argc);
73        temp_plugin_node = get_plugin(argv[0]);        temp_plugin_node = get_plugin(argv[0]);
74        free_args(argc, argv);        free_args(argc, argv);
       if(temp_plugin_rule){  
         temp_plugin_rule_last->next = temp_plugin_node;  
       } else {  
         temp_plugin_rule = temp_plugin_node;  
       }  
       temp_plugin_rule_last = temp_plugin_node;  
75    
76        eef_log(LOG_DEBUG, "  | Rule %s\n", temp_rule->state);        /* link branch pointers to plugin */
77        /*eef_log(LOG_DEBUG, "ARGV[0]: %s\n", argv[0]);*/        if(temp_plugin_node){
       eef_log(LOG_DEBUG, "  -------------------------\n");  
   
       if(temp_plugin_rule_last){  
78          if(temp_rule->true_branch){          if(temp_rule->true_branch){
           eef_log(LOG_DEBUG, "   True branch:  %s\n", temp_rule->true_branch->state);  
79            argv = _var_to_argv(get_variable_by_name(temp_rule->true_branch->state)->value, &argc);            argv = _var_to_argv(get_variable_by_name(temp_rule->true_branch->state)->value, &argc);
80            /*eef_log(LOG_DEBUG, "ARGV[0]: %s\n", argv[0]);*/            temp_plugin_node->true_branch = get_plugin(argv[0]);
           temp_plugin_rule_last->true_branch = get_plugin(argv[0]);  
81            free_args(argc, argv);            free_args(argc, argv);
82          }          }
83    
84          if(temp_rule->false_branch){          if(temp_rule->false_branch){
           eef_log(LOG_DEBUG, "   False branch: %s\n", temp_rule->false_branch->state);  
85            argv = _var_to_argv(get_variable_by_name(temp_rule->false_branch->state)->value, &argc);            argv = _var_to_argv(get_variable_by_name(temp_rule->false_branch->state)->value, &argc);
86            /*eef_log(LOG_DEBUG, "ARGV[0]: %s\n", argv[0]);*/            temp_plugin_node->false_branch = get_plugin(argv[0]);
           temp_plugin_rule_last->false_branch = get_plugin(argv[0]);  
87            free_args(argc, argv);            free_args(argc, argv);
88          }          }
89        }        }
90    
91        eef_log(LOG_DEBUG, "\n");        /* append rule plugin to list of rules */
92          if(temp_plugin_rules){
93            temp_plugin_rules_last->next = temp_plugin_node;
94          } else {
95            temp_plugin_rules = temp_plugin_node;
96          }
97          temp_plugin_rules_last = temp_plugin_node;
98    
99        /* iterate to next rule */        /* iterate to next rule */
100        temp_rule = temp_rule->next;        temp_rule = temp_rule->next;
101      }      }
102    
103      /* iterate to next policy */      /* at this point the tree describing a single policy with branches of rules has been created */
     temp_policy = temp_policy->next;  
104    
105      /* append to the end of the list */      /* append rule plugin tree (policy) to the list of policies */
106      if(plugin_tree){      if(plugin_tree){
107        plugin_tree_last->next = temp_plugin_rule;        plugin_tree_last->next_policy = temp_plugin_rules;
108      } else {      } else {
109        plugin_tree = temp_plugin_rule;        plugin_tree = temp_plugin_rules;
110      }      }
111      plugin_tree_last = temp_plugin_rule;      plugin_tree_last = temp_plugin_rules;
112    
113        /* start a new rules tree for the next policy */
114        temp_plugin_rules = NULL;
115    
116        /* iterate to next policy */
117        temp_policy = temp_policy->next;
118    
119    }    }
120    return plugin_tree;    return plugin_tree;
# Line 132  void free_args(int argc, char** argv){ Line 128  void free_args(int argc, char** argv){
128  }  }
129    
130  void print_plugin_tree_recursive(eef_plugindl_t* plugin_tree, int depth){  void print_plugin_tree_recursive(eef_plugindl_t* plugin_tree, int depth){
   int depth_cache;  
131    int num_policy = 1;    int num_policy = 1;
132    
133    while(plugin_tree){    while(plugin_tree){
# Line 140  void print_plugin_tree_recursive(eef_plu Line 135  void print_plugin_tree_recursive(eef_plu
135        printf("Policy %i\n", num_policy);        printf("Policy %i\n", num_policy);
136      }      }
137    
138      for(depth_cache = depth; depth_cache > 0; depth_cache--){      indent_stdout(depth);
139        printf("  ");      printf("rule %s\n", plugin_tree->pluginname);
140      }      indent_stdout(depth);
     printf("| Rule %s\n", plugin_tree->pluginname);  
     for(depth_cache = depth; depth_cache > 0; depth_cache--){  
       printf("  ");  
     }  
141      printf("-------------------------\n");      printf("-------------------------\n");
142    
143      if(plugin_tree->true_branch){      if(plugin_tree->true_branch){
144        printf("True: \n");        indent_stdout(depth+1);
145          printf("True: ");
146        print_plugin_tree_recursive(plugin_tree->true_branch, depth+1);        print_plugin_tree_recursive(plugin_tree->true_branch, depth+1);
147      }      }
148    
149      if(plugin_tree->false_branch){      if(plugin_tree->false_branch){
150        printf("False: \n");        indent_stdout(depth+1);
151          printf("False: ");
152        print_plugin_tree_recursive(plugin_tree->false_branch, depth+1);        print_plugin_tree_recursive(plugin_tree->false_branch, depth+1);
153      }      }
154      printf("\n");      printf("\n");
155    
156        /* code to break from the loop */
157      if(depth==0){      if(depth==0){
158          /* top level plugin - a policy */
159        num_policy++;        num_policy++;
160        /* only iterate top level plugins as only they can be considered policies - that is, they have branches */        /* iterate to next policy */
161        if(plugin_tree->next){        plugin_tree = plugin_tree->next_policy;
         if(!plugin_tree->next->true_branch || !plugin_tree->next->false_branch){  
           plugin_tree = NULL;  
         } else {  
           plugin_tree = plugin_tree->next;  
         }  
       }  
162      } else {      } else {
163        /* prevent recursive printing of everything below top level plugins */        /* prevent recursive printing of everything below top level plugins */
164        plugin_tree = NULL;        plugin_tree = NULL;
165      }      }
166    }    }
167    
168      return;
169    
170    }
171    
172    void indent_stdout(depth){
173      int depth_cache;
174      for(depth_cache = depth; depth_cache > 0; depth_cache--){
175        printf("  ");
176      }
177      return;
178  }  }
179    
180  /*! sets the path to modules directory */  /*! sets the path to modules directory */

Legend:
Removed from v.1145  
changed lines
  Added in v.1146

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28