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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 566 - (show annotations) (download) (as text)
Mon Jul 20 09:41:59 2009 UTC (12 years, 10 months ago) by aramv
File MIME type: text/x-chdr
File size: 3252 byte(s)
Managed to build the evaluation manager without memory leaks
1 #include <stdio.h>
2 #include "pdl.h"
3 #include "ng_log.h"
4 #include <stdlib.h>
5
6 NG_RC pdl_init(const char* name){
7 if((file = fopen(name,"r")) != NULL){
8 yyin = file;
9 return NG_SUCCESS;
10 } else {
11 ng_log(LOG_ERR, "Failed to open policy file");
12 return NG_FAILURE;
13 }
14 }
15
16 record_t* concat_strings(record_t* r1, record_t* r2){
17 record_t* new_record;
18 if((new_record = malloc(sizeof(record_t)))){
19 if((new_record->string =
20 calloc(1, sizeof(char)*(strlen(r1->string) + strlen(r2->string)+1)))){
21 strcat(new_record->string, r1->string);
22 strcat(new_record->string, r2->string);
23 free(r1->string);
24 free(r1);
25 free(r2->string);
26 free(r2);
27 return new_record;
28 }
29 }
30 return NULL;
31 }
32
33 record_t* concat_strings_with_space(record_t *r1, record_t* r2){
34 ng_log(LOG_NOTICE, "Concating: %s with %s", r1->string, r2->string);
35 record_t *r;
36 if((r = malloc(sizeof(record_t)))){
37 if((r1->string[strlen(r1->string)-1]=='"') &&
38 (r2->string[strlen(r2->string)-1]=='"')){
39 r = concat_strings(r1, r2);
40 } else {
41 r->string = calloc(1,(sizeof(char)*(strlen(r1->string)+strlen(r2->string)+2)));
42 strcat(r->string, r1->string);
43 strcat(r->string, " ");
44 strcat(r->string, r2->string);
45 }
46 free(r1->string);
47 free(r1);
48 free(r2->string);
49 free(r2);
50 return r;
51 }
52 return NULL;
53 }
54
55 int yyerror(const char* string){
56 return ng_log(LOG_ERR, string);
57 }
58
59 void set_path(record_t* path){
60 ng_log(LOG_ERR, "Found a new path: %s\n", path->string);
61 free(path->string);
62 free(path);
63 }
64
65 void add_policy(record_t* policy, rule_t* rule){
66 ng_log(LOG_ERR, "Found a new policy: %s\n", policy->string);
67 /*ng_log(LOG_ERR, "Found a new rule: %s\n", rule->string);*/
68 free(policy->string);
69 free(policy);
70
71 /*free(rule->true_branch);*/
72 /*free(rule->false_branch);*/
73 /*free(rule);*/
74 }
75
76 const char* pdl_path(){
77 return _pdl_path;
78 }
79
80 rule_t* add_rule(record_t* state, record_t* true_branch, record_t* false_branch){
81 rule_t* new_rule = malloc(sizeof(rule_t));
82 if(state != NULL){
83 ng_log(LOG_ERR, "Added a new rule: %s\n", state->string);
84 }
85 if(true_branch != NULL){
86 ng_log(LOG_ERR, "True branch: %s\n", true_branch->string);
87 }
88 if(false_branch != NULL){
89 ng_log(LOG_ERR, "False branch: %s\n", false_branch->string);
90 }
91 if(state != NULL){
92 free(state->string);
93 }
94 free(state);
95 if(true_branch != NULL){
96 free(true_branch->string);
97 }
98 free(true_branch);
99 if(false_branch != NULL){
100 free(false_branch->string);
101 }
102 free(false_branch);
103 free(new_rule);
104 return new_rule;
105 }
106
107 void remove_policy(record_t* policy){
108 ng_log(LOG_ERR, "Deleted policy: %s\n", policy->string);
109 free(policy->string);
110 free(policy);
111 }
112
113 void add_variable(record_t* name, record_t* value){
114 ng_log(LOG_ERR, "Added variable name: %s\n", name->string);
115 ng_log(LOG_ERR, "Added variable value: %s\n", value->string);
116 free(name->string);
117 free(name);
118 free(value->string);
119 free(value);
120 }
121
122 NG_RC pdl_term(){
123 if((fclose(file)==0) ){
124 yylex_destroy();
125 return NG_SUCCESS;
126 } else {
127 return NG_FAILURE;
128 }
129 }
130
131 NG_RC allow_rules(int val){
132 return NG_SUCCESS;
133 }
134
135 NG_RC allowed_policy_rule(const char* label){
136 return NG_SUCCESS;
137 }

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