/[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 1122 by aramv, Fri Nov 13 13:10:36 2009 UTC revision 1123 by aramv, Fri Nov 13 16:00:45 2009 UTC
# Line 5  extern FILE *               yyin; Line 5  extern FILE *               yyin;
5  extern int                  yylex_destroy(void);  extern int                  yylex_destroy(void);
6  extern int                  yyparse(void);  extern int                  yyparse(void);
7  extern int                  yylex(void);  extern int                  yylex(void);
8  extern int                  lineno;  extern unsigned int         lineno;
9  extern void                 delete_lex_buffer(void);  extern void                 delete_lex_buffer(void);
10    
11  /* internal data */  /* internal data */
# Line 22  rule_t*                     rules_list; Line 22  rule_t*                     rules_list;
22  rule_t*                     rules_list_last;  rule_t*                     rules_list_last;
23  rule_t*                     current_rule;  rule_t*                     current_rule;
24    
25    policy_t*                   policies_list;
26    policy_t*                   policies_list_last;
27    policy_t*                   current_policy;
28    
29  /*! initializes the parsing of the configuration file */  /*! initializes the parsing of the configuration file */
30  EES_RC pdl_init(const char* config_file_name){  EES_RC pdl_init(const char* config_file_name){
31    config_file_s = config_file_name;    config_file_s = config_file_name;
32    if((config_file_fp = fopen(config_file_s,"r")) != NULL){    if((config_file_fp = fopen(config_file_s,"r")) != NULL){
33      yyin = config_file_fp;      yyin = config_file_fp;
34      yyparse();      yyparse();
35        print_policies();
36      if(initialize_plugins() == EES_SUCCESS){      if(initialize_plugins() == EES_SUCCESS){
37        return EES_SUCCESS;        return EES_SUCCESS;
38      }      }
# Line 65  void set_modules_path(record_t* path){ Line 70  void set_modules_path(record_t* path){
70    
71  /*! Handles a variable representing a plug-in; creates a structure containing its values and adds it to the list of var_t structs variables_list */  /*! Handles a variable representing a plug-in; creates a structure containing its values and adds it to the list of var_t structs variables_list */
72  void add_variable(record_t* name, record_t* value){  void add_variable(record_t* name, record_t* value){
73    eef_log(LOG_DEBUG, "Added variable name: %s\n", name->string);    /*eef_log(LOG_DEBUG, "Added variable name: %s\n", name->string);*/
74    eef_log(LOG_DEBUG, "Added variable value: %s\n", value->string);    /*eef_log(LOG_DEBUG, "Added variable value: %s\n", value->string);*/
75    
76    /* allocate struct and populate fields */    /* allocate struct and populate fields */
77    if((current_variable = calloc(1,sizeof(var_t)))){    if((current_variable = calloc(1,sizeof(var_t)))){
# Line 104  rule_t* add_rule(record_t* state, record Line 109  rule_t* add_rule(record_t* state, record
109    } else {    } else {
110      /*find variables for rule */      /*find variables for rule */
111      if((temp_var = get_variable_by_name(state->string)) != NULL){      if((temp_var = get_variable_by_name(state->string)) != NULL){
       /*printf("Rule %s defines var %s\n", state->string, get_variable_by_name(state->string)->name);*/  
112        if((new_rule = calloc(1, sizeof(rule_t)))){        if((new_rule = calloc(1, sizeof(rule_t)))){
113          /* populate fields of current state */          /* populate fields of current state */
114          new_rule->state = strdup(state->string);          new_rule->state = strdup(state->string);
# Line 137  rule_t* add_rule(record_t* state, record Line 141  rule_t* add_rule(record_t* state, record
141              rules_list = new_rule;              rules_list = new_rule;
142            }            }
143            rules_list_last = new_rule;            rules_list_last = new_rule;
144            eef_log(LOG_DEBUG, "Added a new rule: %s\n", new_rule->state);            /*eef_log(LOG_DEBUG, "Added a new rule: %s\n", new_rule->state);*/
145          }          }
146    
147        } else {        } else {
# Line 232  rule_t* find_state(rule_t* rule, const c Line 236  rule_t* find_state(rule_t* rule, const c
236    
237  /* TODO */  /* TODO */
238  void add_policy(record_t* policy, rule_t* rule){  void add_policy(record_t* policy, rule_t* rule){
239    rule_t* temp_rule = rules_list;    policy_t* new_policy = NULL;
240    eef_log(LOG_DEBUG, "Found a new policy: %s\n", policy->string);    /*eef_log(LOG_DEBUG, "Found a new policy: %s\n", policy->string);*/
241    /*while(temp_rule){*/  
242    /*printf("Added rule %s to policy %s\n", temp_rule->state, policy->string);*/    if(new_policy = calloc(1, sizeof(policy_t))){
243    /*temp_rule = temp_rule->next;*/      new_policy->name = strdup(policy->string);
244    /*} */      new_policy->lineno = policy->lineno;
245        new_policy->rules = rule;
246      }
247    
248      /* append to the end of the list */
249      if(policies_list){
250        policies_list_last->next = new_policy;
251      } else {
252        policies_list = new_policy;
253      }
254      policies_list_last = new_policy;
255    
256      rules_list = NULL;
257    
258    free(policy->string);    free(policy->string);
259    free(policy);    free(policy);
260    }
261    
262    /*free(rule->true_branch);*/  void print_policies(){
263    /*free(rule->false_branch);*/    rule_t*   temp_rule = NULL;
264    /*free(rule);*/    policy_t* temp_policy = policies_list;
265    
266      while(temp_policy){
267        temp_rule = temp_policy->rules;
268        eef_log(LOG_DEBUG, "Policy: %s\n", temp_policy->name);
269        while(temp_rule){
270          eef_log(LOG_DEBUG, "  | Rule %s\n", temp_rule->state);
271          eef_log(LOG_DEBUG, "  -------------------------\n");
272          if(temp_rule->true_branch){
273            eef_log(LOG_DEBUG, "   True branch:  %s\n", temp_rule->true_branch->state);
274          }
275          /*if(temp_rule->true_branch && temp_rule->false_branch){*/
276          /*}*/
277          if(temp_rule->false_branch){
278            eef_log(LOG_DEBUG, "   False branch: %s\n", temp_rule->false_branch->state);
279          }
280          eef_log(LOG_DEBUG, "\n");
281          temp_rule = temp_rule->next;
282        }
283        temp_policy = temp_policy->next;
284      }
285  }  }
286    
287  /*! concatenates two strings */  /*! concatenates two strings */
288  record_t* concat_strings(record_t* r1, record_t* r2){  record_t* concat_strings(record_t* r1, record_t* r2){
289    record_t* new_record;    record_t* new_record;
290    eef_log(LOG_DEBUG, "Concating: %s with %s\n", r1->string, r2->string);    /*eef_log(LOG_DEBUG, "Concating: %s with %s\n", r1->string, r2->string);*/
291    if((new_record = malloc(sizeof(record_t)))){    if((new_record = malloc(sizeof(record_t)))){
292      if((new_record->string =      if((new_record->string =
293          calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){          calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){
# Line 269  record_t* concat_strings(record_t* r1, r Line 306  record_t* concat_strings(record_t* r1, r
306  /*! concatenates two strings with a space in between */  /*! concatenates two strings with a space in between */
307  record_t* concat_strings_with_space(record_t *r1, record_t* r2){  record_t* concat_strings_with_space(record_t *r1, record_t* r2){
308    record_t *r;    record_t *r;
309    eef_log(LOG_DEBUG, "Concating: %s with %s with spaces\n", r1->string, r2->string);    /*eef_log(LOG_DEBUG, "Concating: %s with %s with spaces\n", r1->string, r2->string);*/
310    if((r = malloc(sizeof(record_t)))){    if((r = malloc(sizeof(record_t)))){
311        r->string = calloc(1,(sizeof(char)*(strlen(r1->string)+strlen(r2->string)+2)));        r->string = calloc(1,(sizeof(char)*(strlen(r1->string)+strlen(r2->string)+2)));
312        strncat(r->string, r1->string, strlen(r1->string));        strncat(r->string, r1->string, strlen(r1->string));

Legend:
Removed from v.1122  
changed lines
  Added in v.1123

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