#include #include #include "pdl.h" #include "ng_log.h" #include "ees_config.h" NG_RC pdl_init(const char* name){ if((file = fopen(name,"r")) != NULL){ yyin = file; return NG_SUCCESS; } else { ng_log(LOG_ERR, "Failed to open policy file"); return NG_FAILURE; } } record_t* concat_strings(record_t* r1, record_t* r2){ record_t* new_record; if((new_record = malloc(sizeof(record_t)))){ if((new_record->string = calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){ strcat(new_record->string, r1->string); strcat(new_record->string, r2->string); free(r1->string); free(r1); free(r2->string); free(r2); return new_record; } } return NULL; } record_t* concat_strings_with_space(record_t *r1, record_t* r2){ ng_log(LOG_NOTICE, "Concating: %s with %s", r1->string, r2->string); record_t *r; if((r = malloc(sizeof(record_t)))){ if((r1->string[strlen(r1->string)-1]=='"') && (r2->string[strlen(r2->string)-1]=='"')){ r = concat_strings(r1, r2); } else { r->string = calloc(1,(sizeof(char)*(strlen(r1->string)+strlen(r2->string)+2))); strcat(r->string, r1->string); strcat(r->string, " "); strcat(r->string, r2->string); } free(r1->string); free(r1); free(r2->string); free(r2); return r; } return NULL; } int yyerror(const char* string){ return ng_log(LOG_ERR, string); } void set_path(record_t* path){ ng_log(LOG_ERR, "Found a new path: %s\n", path->string); free(path->string); free(path); } void add_policy(record_t* policy, rule_t* rule){ ng_log(LOG_ERR, "Found a new policy: %s\n", policy->string); /*ng_log(LOG_ERR, "Found a new rule: %s\n", rule->string);*/ free(policy->string); free(policy); /*free(rule->true_branch);*/ /*free(rule->false_branch);*/ /*free(rule);*/ } const char* pdl_path(){ return _pdl_path; } rule_t* add_rule(record_t* state, record_t* true_branch, record_t* false_branch){ rule_t* new_rule = malloc(sizeof(rule_t)); if(state != NULL){ ng_log(LOG_ERR, "Added a new rule: %s\n", state->string); } if(true_branch != NULL){ ng_log(LOG_ERR, "True branch: %s\n", true_branch->string); } if(false_branch != NULL){ ng_log(LOG_ERR, "False branch: %s\n", false_branch->string); } if(state != NULL){ free(state->string); } free(state); if(true_branch != NULL){ free(true_branch->string); } free(true_branch); if(false_branch != NULL){ free(false_branch->string); } free(false_branch); free(new_rule); return new_rule; } void remove_policy(record_t* policy){ ng_log(LOG_ERR, "Deleted policy: %s\n", policy->string); free(policy->string); free(policy); } char** _var_to_argv(char* value){ printf("Value: %s", value); } void add_variable(record_t* name, record_t* value){ ng_log(LOG_ERR, "Added variable name: %s\n", name->string); ng_log(LOG_ERR, "Added variable value: %s\n", value->string); free(name->string); free(name); free(value->string); free(value); } NG_RC pdl_term(){ if((fclose(file)==0) ){ #if HAVE_YYLEX_DESTROY yylex_destroy(); #endif return NG_SUCCESS; } else { return NG_FAILURE; } } NG_RC allow_rules(int val){ return NG_SUCCESS; } NG_RC allowed_policy_rule(const char* label){ return NG_SUCCESS; }