/[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 530 - (show annotations) (download)
Wed Jul 15 10:55:33 2009 UTC (12 years, 6 months ago) by aramv
File size: 5874 byte(s)
Made the parser work without memory leaks, for now.
1 /*
2 * Copyright (c) Members of the EGEE Collaboration. 2004.
3 * See http://eu-egee.org/partners/ for details on the copyright holders.
4 * For license conditions see the license file or
5 * http://eu-egee.org/license.html
6 */
7
8 /*
9 * Copyright (c) 2003 EU DataGrid http://www.eu-datagrid.org/
10 *
11 * $Id: pdl_lex.l,v 1.9 2004/12/07 08:41:11 venekamp Exp $
12 *
13 * Copyright (c) 2003 by
14 * G.M. Venekamp <venekamp@nikhef.nl>
15 * NIKHEF Amsterdam, the Netherlands
16 *
17 * This software is distributed under a BSD-style open source
18 * licence. For a complete description of the licence take a look
19 * at: http://eu-datagrid.web.cern.ch/eu-datagrid/license.html
20 *
21 */
22
23 %{
24 #include <string.h>
25 #include <syslog.h>
26
27 #include "pdl.h"
28 #include "pdl_yacc.h"
29 #include "ng_log.h"
30 /*#include "pdl_rule.h"
31 #include "pdl_yacc.h"
32 #include "pdl_policy.h"*/
33 unsigned int lineno = 1;
34 /* int yydebug=1; */
35
36 /*static int no_valid_rule=0;*/
37
38 %}
39
40 ws [\t ]+
41 nl \n
42 term [a-zA-Z_.0-9]+
43 label {term}:
44 trans "->"
45 comment #
46 tokens [\~=\|]
47 pvar "path"
48 path [\/\.][^\/ \t\n]*
49 pdlstr \"[^\"\n]*[\"\n]
50
51
52 %x linecom path pathcom mq
53 %%
54
55 {ws} ;
56 {pvar} { return PVAR; }
57 {term} { if((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
58 if(((yylval.record)->string = strdup(yytext))){
59 (yylval.record)->lineno = lineno;
60 return TERM;
61 }
62 }
63 ng_log(LOG_ERR, "out of memory.");
64 return 0;
65 }
66 {label} { yytext[yyleng-1] = '\0'; /* remove trailing ':' */
67 printf("Found label %s\n", yytext);
68
69 /* Check if this policy rule is allowed or not. */
70 if (allowed_policy_rule(yytext)) {
71 allow_rules(TRUE);
72 } else {
73 /* This label should not be added, however normal parsing
74 * must continue. */
75 allow_rules(FALSE);
76 }
77 if((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
78 if(((yylval.record)->string = strdup(yytext))) {
79 (yylval.record)->lineno = lineno;
80 return LABEL;
81 }
82 }
83 ng_log(LOG_ERR, "out of memory.");
84 return 0;
85 }
86 {path} {
87 if ((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
88 if(((yylval.record)->string = (yytext))){
89 (yylval.record)->lineno = lineno;
90 BEGIN path;
91 return PATH;
92 }
93 }
94 ng_log(LOG_ERR, "out of memory.");
95 return 0;
96 }
97 <path>{path} {
98 if ((yylval.record = (record_t *)malloc(sizeof(record_t)))) {
99 if(((yylval.record)->string = (yytext))){
100 (yylval.record)->lineno = lineno;
101 return PATH;
102 }
103 }
104 ng_log(LOG_ERR, "out of memory.");
105 return 0;
106 }
107 <path># { BEGIN pathcom; }
108 <path>[ \t]*/# ;
109 <path>\n { BEGIN INITIAL; yyless(0); return '\n'; }
110 <path>. { ng_log(LOG_ERR, "unrecognized tokens in path name."); }
111 <pathcom>. ;
112 <pathcom>\n { BEGIN INITIAL; yyless(0); return '\n'; }
113 {nl} { ++lineno; }
114 {tokens} { return yytext[0]; }
115 {trans} { return TRANS; }
116 {comment} { BEGIN linecom; }
117 <linecom>. ;
118 <linecom>\n { ++lineno; BEGIN INITIAL; }
119 {pdlstr} { if ((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
120 if (yytext[yyleng-2] == '\\') {
121 if (((yylval.record)->string = strdup(yytext))) {
122 (yylval.record)->string[yyleng-2] = '\0';
123 (yylval.record)->string[yyleng-3] = '\"';
124 (yylval.record)->lineno = lineno;
125 yyless(yyleng-1); /* make the next string start with " */
126 BEGIN mq;
127 return STRING;
128 }
129 } else {
130 if (yytext[yyleng-1] == '\"') {
131 if (((yylval.record)->string = (yytext))) {
132 (yylval.record)->string[yyleng-2] = '\0';
133 (yylval.record)->lineno = lineno;
134 return STRING;
135 }
136 }
137 }
138 ng_log(LOG_ERR, "out of memory.");
139 return 0;
140 } else {
141 ng_log(LOG_ERR, "string contains a newline.");
142 }
143 }
144 <mq>{pdlstr} { if ((yylval.record = (record_t*)malloc(sizeof(record_t)))) {
145 if (yytext[yyleng-2] == '\\') {
146 if (((yylval.record)->string = strdup(yytext))) {
147 (yylval.record)->string[yyleng-2] = '\0';
148 (yylval.record)->string[yyleng-3] = '\"';
149 (yylval.record)->lineno = lineno;
150 yyless(yyleng-1); /* make the next string start with " */
151 BEGIN INITIAL;
152 return STRING;
153 }
154 } else {
155 ng_log(LOG_ERR, "Unballanced quotes.");
156 return 0;
157 }
158 }
159 ng_log(LOG_ERR, "out of memory.");
160 return 0;
161 }
162 . { ng_log(LOG_WARNING, "unrecoginzed token '%c'.", yytext[0]);
163 return yytext[0];
164 }
165 %%

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