/[pdpsoft]/trunk/grid-mw-security/ees/src/eval_man/pdl_lex.l
ViewVC logotype

Contents of /trunk/grid-mw-security/ees/src/eval_man/pdl_lex.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations) (download)
Fri Nov 20 14:04:55 2009 UTC (12 years, 2 months ago) by aramv
File size: 4841 byte(s)
Added code to specify allowed policies and clean those not allowed
1 %{
2 #include "pdl.h"
3 #include "pdl_yacc.h"
4 #include "eef_log.h"
5 #include <string.h>
6 unsigned int lineno = 1;
7
8 /*static int no_valid_rule=0;*/
9 %}
10
11 ws [\t ]+
12 nl \n
13 term [a-zA-Z_.0-9]+
14 label {term}:
15 trans "->"
16 comment #.*\n
17 tokens [\~=\|]
18 pvar "path"
19 path \.*\/[^\/ \t\n]*
20 pdlstr \"[^\"\n]*[\"\n]
21
22
23 %x linecom path pathcom mq
24 %%
25
26 {ws} ;
27 {pvar} { return PVAR; }
28 {term} { if ((yylval.record = (record_t*)malloc(sizeof(record_t))))
29 if (((yylval.record)->string = (char*) strdup(yytext))) {
30 (yylval.record)->lineno = lineno;
31 return TERM;
32 }
33 eef_log(LOG_ERR, "out of memory.");
34 return 0;
35 }
36 {label} { yytext[yyleng-1] = '\0'; /* remove trailing ':' */
37
38 /* Check if this policy rule is allowed or not. */
39 /*
40 if (allowed_policy_rule(yytext)) {
41 allow_rules(TRUE);
42 } else {
43 */
44 /* This label should not be added, however normal parsing
45 * must continue. */
46 /* allow_rules(FALSE);*/
47 /* } */
48 if ((yylval.record = (record_t*)malloc(sizeof(record_t))))
49 if (((yylval.record)->string = (char *) strdup(yytext))) {
50 (yylval.record)->lineno = lineno;
51 return LABEL;
52 }
53 eef_log(LOG_ERR, "out of memory.");
54 return 0;
55 }
56 {path} { if ((yylval.record = (record_t *)malloc(sizeof(record_t))))
57 if (((yylval.record)->string = strdup(yytext))) {
58 (yylval.record)->lineno = lineno;
59 BEGIN path;
60 return PATH;
61 }
62 eef_log(LOG_ERR, "out of memory.");
63 return 0;
64 }
65 <path>{path} { if ((yylval.record = (record_t *)malloc(sizeof(record_t))))
66 if (((yylval.record)->string = strdup(yytext))) {
67 (yylval.record)->lineno = lineno;
68 return PATH;
69 }
70 eef_log(LOG_ERR, "out of memory.");
71 return 0;
72 }
73 <path># { BEGIN pathcom; }
74 <path>[ \t]* ;
75 <path>\n { BEGIN INITIAL; yyless(0); return '\n'; }
76 <path>. { eef_log(LOG_ERR, "unrecognized tokens in path name."); }
77 <pathcom>. ;
78 <pathcom>\n { BEGIN INITIAL; yyless(0); return '\n'; }
79 {nl} { ++lineno; }
80 {tokens} { return yytext[0]; }
81 {trans} { return TRANS; }
82 {comment} { ++lineno; BEGIN INITIAL ; }
83 {pdlstr} { if ((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
84 if (yytext[yyleng-2] == '\\') {
85 if (((yylval.record)->string = strdup(yytext+1))) {
86 (yylval.record)->string[yyleng-2] = '\0';
87 (yylval.record)->string[yyleng-3] = '\"';
88 (yylval.record)->lineno = lineno;
89 yyless(yyleng-1); /* make the next string start with " */
90 BEGIN mq;
91 return STRING;
92 }
93 } else {
94 if (yytext[yyleng-1] == '\"') {
95 if (((yylval.record)->string = strdup(yytext+1))) {
96 (yylval.record)->string[yyleng-2] = '\0';
97 (yylval.record)->lineno = lineno;
98 return STRING;
99 }
100 }
101 }
102 eef_log(LOG_ERR, "out of memory.");
103 return 0;
104 } else
105 eef_log(LOG_ERR, "string contains a newline.");
106 }
107 <mq>{pdlstr} { if ((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
108 if (yytext[yyleng-2] == '\\') {
109 if (((yylval.record)->string = strdup(yytext+1))) {
110 (yylval.record)->string[yyleng-2] = '\0';
111 (yylval.record)->string[yyleng-3] = '\"';
112 (yylval.record)->lineno = lineno;
113 yyless(yyleng-1); /* make the next string start with " */
114 BEGIN INITIAL;
115 return STRING;
116 }
117 } else {
118 eef_log(LOG_ERR, "Unballanced quotes.");
119 return 0;
120 }
121 }
122 eef_log(LOG_ERR, "out of memory.");
123 return 0;
124 }
125 . { eef_log(LOG_WARNING, "unrecoginzed token '%c'.", yytext[0]);
126 return yytext[0];
127 }
128 %%
129
130 #if HAVE_FLEX
131
132 void delete_lex_buffer(void)
133 {
134 yy_delete_buffer(YY_CURRENT_BUFFER);
135 yy_init = 1;
136 }
137
138 #endif

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