/[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 1069 by aramv, Mon Nov 9 13:34:12 2009 UTC revision 1070 by aramv, Tue Nov 10 09:34:50 2009 UTC
# Line 16  static var_t*               plugin_list_ Line 16  static var_t*               plugin_list_
16  static var_t*               current_plugin;  static var_t*               current_plugin;
17  EES_RC                      config_file_ok;  EES_RC                      config_file_ok;
18    
19    /*! initializes the parsing of the configuration file */
20  EES_RC pdl_init(const char* name){  EES_RC pdl_init(const char* name){
21    if((config_file = fopen(name,"r")) != NULL){    if((config_file = fopen(name,"r")) != NULL){
22      yyin = config_file;      yyin = config_file;
# Line 30  EES_RC pdl_init(const char* name){ Line 31  EES_RC pdl_init(const char* name){
31    }    }
32  }  }
33    
34    /*! concatenates two strings */
35  record_t* concat_strings(record_t* r1, record_t* r2){  record_t* concat_strings(record_t* r1, record_t* r2){
36    record_t* new_record;    record_t* new_record;
37    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);*/
38    if((new_record = malloc(sizeof(record_t)))){    if((new_record = malloc(sizeof(record_t)))){
39      if((new_record->string =      if((new_record->string =
40          calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){          calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){
# Line 48  record_t* concat_strings(record_t* r1, r Line 50  record_t* concat_strings(record_t* r1, r
50    return NULL;    return NULL;
51  }  }
52    
53    /*! concatenates two strings with a space in between */
54  record_t* concat_strings_with_space(record_t *r1, record_t* r2){  record_t* concat_strings_with_space(record_t *r1, record_t* r2){
55    record_t *r;    record_t *r;
56    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);*/
57    if((r = malloc(sizeof(record_t)))){    if((r = malloc(sizeof(record_t)))){
58        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)));
59        strncat(r->string, r1->string, strlen(r1->string));        strncat(r->string, r1->string, strlen(r1->string));
# Line 65  record_t* concat_strings_with_space(reco Line 68  record_t* concat_strings_with_space(reco
68    return NULL;    return NULL;
69  }  }
70    
71    /*! logs errors encountered during parsing */
72  int yyerror(char* string){  int yyerror(char* string){
73    eef_log(LOG_ERR, string);    eef_log(LOG_ERR, string);
74    return 0;    return 0;
75  }  }
76    
77  void set_path(record_t* path){  /*! sets the path to modules directory */
78    void set_modules_path(record_t* path){
79    size_t path_size = 0;    size_t path_size = 0;
80    size_t string_size = (sizeof(char) * (strlen(path->string)+2)); /* size of string + extra slash + null byte */    size_t string_size = (sizeof(char) * (strlen(path->string)+2)); /* size of string + extra slash + null byte */
81    _pdl_path = "";    _pdl_path = "";
# Line 78  void set_path(record_t* path){ Line 83  void set_path(record_t* path){
83    /*struct stat sb;*/    /*struct stat sb;*/
84    /*if stat(MODUL*/    /*if stat(MODUL*/
85    
   eef_log(LOG_DEBUG, "Found a new path: %s\n", path->string);  
86    if(string_size < FILENAME_MAX){    if(string_size < FILENAME_MAX){
87      path_size = string_size;      path_size = string_size;
88    } else {    } else {
89      path_size = FILENAME_MAX;      path_size = FILENAME_MAX;
90    }    }
91    
   eef_log(LOG_DEBUG,"Modules path: %s\n", path->string);  
   
92    if((_pdl_path = calloc(1, path_size))){    if((_pdl_path = calloc(1, path_size))){
93      strncpy(_pdl_path, path->string, path_size);      strncpy(_pdl_path, path->string, path_size);
94                  strncat(_pdl_path, "/", 1);                  strncat(_pdl_path, "/", 1);
95    }    }
96    
97      eef_log(LOG_DEBUG, "Found a new modules path: %s\n", _pdl_path);
98    
99    free(path->string);    free(path->string);
100    free(path);    free(path);
101  }  }
# Line 112  const char* get_pdl_path(){ Line 117  const char* get_pdl_path(){
117    return _pdl_path;    return _pdl_path;
118  }  }
119    
120    /*! Adds a rule */
121    /*TODO describe function better*/
122  rule_t* add_rule(record_t* rule, record_t* true_branch, record_t* false_branch){  rule_t* add_rule(record_t* rule, record_t* true_branch, record_t* false_branch){
123    rule_t* new_rule = malloc(sizeof(rule_t));    rule_t* new_rule = malloc(sizeof(rule_t));
124    if(rule != NULL){    if(rule != NULL){
# Line 123  rule_t* add_rule(record_t* rule, record_ Line 130  rule_t* add_rule(record_t* rule, record_
130    if(false_branch != NULL){    if(false_branch != NULL){
131      eef_log(LOG_DEBUG, "False branch: %s\n", false_branch->string);      eef_log(LOG_DEBUG, "False branch: %s\n", false_branch->string);
132    }    }
133    
134      /* TODO check for recursion */
135    
136    if(rule != NULL){    if(rule != NULL){
137      free(rule->string);      free(rule->string);
138    }    }
# Line 139  rule_t* add_rule(record_t* rule, record_ Line 149  rule_t* add_rule(record_t* rule, record_
149    return new_rule;    return new_rule;
150  }  }
151    
152    /*TODO*/
153    /*! Removes a policy from the list of policies */
154  void remove_policy(record_t* policy){  void remove_policy(record_t* policy){
155    eef_log(LOG_DEBUG, "Deleted policy: %s\n", policy->string);    eef_log(LOG_DEBUG, "Deleted policy: %s\n", policy->string);
156    free(policy->string);    free(policy->string);
157    free(policy);    free(policy);
158  }  }
159    
160    /*! converts a string to an array of strings by splitting it at each \t delimiter
161      - overwrites the second argument with a pointer to the number of elements in the array */
162  char** _var_to_argv(char* value, int *argc){  char** _var_to_argv(char* value, int *argc){
163    char *start_of_arg = NULL, *copy_of_value = NULL, **argv = NULL;    char *start_of_arg = NULL, *copy_of_value = NULL, **argv = NULL;
164    char *delimiters = " \t";    char *delimiters = " \t";
# Line 172  char** _var_to_argv(char* value, int *ar Line 186  char** _var_to_argv(char* value, int *ar
186    return argv;    return argv;
187  }  }
188    
189    /*! Handles a variable representing a plug-in; creates a structure containing its values and adds it to the list of plug-in structs */
190  void add_variable(record_t* name, record_t* value){  void add_variable(record_t* name, record_t* value){
191    eef_log(LOG_DEBUG, "Added variable name: %s\n", name->string);    eef_log(LOG_DEBUG, "Added variable name: %s\n", name->string);
192    eef_log(LOG_DEBUG, "Added variable value: %s\n", value->string);    eef_log(LOG_DEBUG, "Added variable value: %s\n", value->string);
# Line 204  void add_variable(record_t* name, record Line 219  void add_variable(record_t* name, record
219    free(value);    free(value);
220  }  }
221    
222    /*! Iterates the list of plug-in structures and tries to initialize the specified plug-ins */
223  EES_RC initialize_plugins(){  EES_RC initialize_plugins(){
224    char** argv;    char** argv;
225    int argc;    int argc;
# Line 213  EES_RC initialize_plugins(){ Line 229  EES_RC initialize_plugins(){
229    while(current_plugin && config_file_ok){    while(current_plugin && config_file_ok){
230      /* prepare arguments and add to plug-in manager */      /* prepare arguments and add to plug-in manager */
231      argv = _var_to_argv(current_plugin->value, &argc);      argv = _var_to_argv(current_plugin->value, &argc);
232        /* TODO rename addPlugin to something more uniform */
233      config_file_ok = addPlugin(argc, argv);      config_file_ok = addPlugin(argc, argv);
234      last_plugin = current_plugin;      last_plugin = current_plugin;
235      current_plugin = current_plugin->next;      current_plugin = current_plugin->next;
236    }    }
237    return EES_SUCCESS;    /*return EES_SUCCESS;*/
238      return config_file_ok;
239  }  }
240    
241    /*! Iterates the list of plug-in structures and tries to free them */
242  EES_RC clean_variables(){  EES_RC clean_variables(){
243    var_t* last_plugin = NULL;    var_t* last_plugin = NULL;
244    current_plugin = plugin_list;    current_plugin = plugin_list;
# Line 231  EES_RC clean_variables(){ Line 250  EES_RC clean_variables(){
250    return EES_SUCCESS;    return EES_SUCCESS;
251  }  }
252    
253    /*! Terminates the parser and tries to free all used memory */
254  EES_RC pdl_term(){  EES_RC pdl_term(){
255    free(_pdl_path);    free(_pdl_path);
256    clean_variables();    clean_variables();
# Line 242  EES_RC pdl_term(){ Line 262  EES_RC pdl_term(){
262        eef_log(LOG_WARNING, "Lex function yylex_destroy() not available - possibly unable to free allocated memory for evaluation manager\n");        eef_log(LOG_WARNING, "Lex function yylex_destroy() not available - possibly unable to free allocated memory for evaluation manager\n");
263        #if HAVE_FLEX        #if HAVE_FLEX
264          delete_lex_buffer();          delete_lex_buffer();
265            /* eef_log(LOG_INFO, "Managed to free allocated memory for evaluation manager\n"); */
266        #endif        #endif
267      #endif      #endif
268      if((fclose(config_file)==0) ){      if((fclose(config_file)==0) ){
# Line 251  EES_RC pdl_term(){ Line 272  EES_RC pdl_term(){
272    return EES_FAILURE;    return EES_FAILURE;
273  }  }
274    
275    /*! TODO */
276  EES_RC allow_rules(int val){  EES_RC allow_rules(int val){
277    return EES_SUCCESS;    return EES_SUCCESS;
278  }  }
279    
280    /*! TODO */
281  EES_RC allowed_policy_rule(const char* label){  EES_RC allowed_policy_rule(const char* label){
282    return EES_SUCCESS;      return EES_SUCCESS;  
283  }  }

Legend:
Removed from v.1069  
changed lines
  Added in v.1070

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