source: libabac/ort0.y @ e08bf83

mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2
Last change on this file since e08bf83 was e95d652, checked in by Mei <mei@…>, 13 years ago

1) added yap, flex, bison to bring in prolog backend

  • Property mode set to 100644
File size: 3.8 KB
Line 
1
2
3/* bison grammar rules for process old rt0 statements */
4/*
5   isi.employee <- ted
6   ted.friend <- mike
7   usc.employee <- isi.employee
8   usc.playground <- usc.employee.friend
9   query,
10      usc.playground <- ?Z
11      isi.playground <- mike
12*/
13
14%{
15/* C declarations */
16#include <stdio.h>
17#include <string.h>
18#include <abac_stack.h>
19
20extern char *abac_cn_with_sha(char*);
21
22FILE *abac_yyin = NULL;
23FILE *abac_yyout = NULL;
24char *abac_yap_clause = NULL;
25char *abac_yyfptr = NULL;
26char *tmp_cred_list = NULL;
27
28int sz_overhead = 0;
29
30%}
31/* Bison declarations */
32%union {
33int  number;
34char *string;   /* For returning char strings */
35}
36%type <string> keypart rolepart left right stmt
37
38%token <string> IDEN       /* keyname or rolename */
39
40%token  <operator>  DERIVE    "<-"
41%token  <operator>  DOT       "."
42
43%%
44/* Grammar rules */
45
46input:      /* empty */
47             { }
48        | stmt
49             { fprintf (abac_yyout,"stmt (%s)\n", $1);
50               abac_yap_clause = $1;
51             }
52 
53stmt : left DERIVE right
54             { int sz;
55               char *ptr=strstr($3,"role(");
56               char *tmp;
57               if(ptr==NULL) {
58                 sz=strlen($3)+strlen($1)+sz_overhead;
59                 tmp=(char *)abac_xmalloc(sz);
60                 printf("before.. (%s)\n", $3);
61                 sprintf(tmp,"isMember(%s,%s,['%s'])",$3,$1,abac_yyfptr);
62                 printf("after.. (%s)\n", tmp);
63               } else {
64                 sz=strlen($3)+strlen($1)+sz_overhead;
65                 tmp=(char *)abac_xmalloc(sz);
66                 if (tmp_cred_list==NULL) {
67                     sprintf(tmp,"isMember(X,%s,['%s']):-%s",
68                                        $1, abac_yyfptr, $3);
69                     } else {
70                     sprintf(tmp,"isMember(X,%s,['%s',%s]):-%s",
71                                        $1, abac_yyfptr, tmp_cred_list, $3);
72                     free(tmp_cred_list);
73                     tmp_cred_list=NULL;
74                 }
75               }
76               $$=tmp;
77               free($3);free($1);
78             }
79
80left : keypart DOT rolepart
81             {
82               int sz=strlen($1)+strlen($3)+sz_overhead;
83               char *tmp=(char *)abac_xmalloc(sz);
84               sprintf(tmp,"role(%s,%s)", $1, $3);
85               $$=tmp;
86               free($3);free($1);
87             }
88/* isi */
89keypart : IDEN
90             {
91             char *cn=abac_cn_with_sha($1);
92             $$=strdup(cn);
93             }
94
95/* friend */
96rolepart : IDEN
97             { $$=strdup($1); }
98
99right : keypart DOT IDEN DOT IDEN
100             {
101               int sz=strlen($1)+strlen($3)+strlen($5)+sz_overhead;
102               char *tmp=(char *)abac_xmalloc(sz);
103               sprintf(tmp,"isMember(Y,role(%s,%s),[C1]),isMember(X,role(Y,%s),[C2])",$1,$3,$5);
104               tmp_cred_list = strdup("C1,C2");
105               $$=tmp;
106               free($1);free($3);free($5);
107             }
108      | keypart DOT IDEN
109             {
110               int sz=strlen($1)+strlen($3)+sz_overhead;
111               char *tmp=(char *)abac_xmalloc(sz);
112               sprintf(tmp,"isMember(X,role(%s,%s),[C1])", $1, $3);
113               tmp_cred_list = strdup("C1");
114               $$=tmp;
115               free($1);free($3);
116             }
117      | keypart
118             {
119             $$=$1;
120             }
121
122%%
123#include "abac_rt0.h"
124
125/* Additional C code */
126int yywrap()
127{
128     /* exit when done lexing the current input */
129     return 1;
130}
131
132int yyerror (char *s)
133{
134     fprintf (abac_yyout,"yyerror: %s\n", s);
135}
136
137/* setting defaults */
138void abac_yyinit()
139{
140    abac_yyin=abac_get_yyin();
141    abac_yyout=abac_get_yyout();
142    abac_yyfptr = abac_get_yyfptr();
143    sz_overhead = strlen(abac_yyfptr)+2000;
144}
145
146char *abac_get_yap_clause()
147{
148    return abac_yap_clause;
149}
150
151char *abac_free_yap_clause()
152{
153    if (abac_yap_clause != NULL)
154        free(abac_yap_clause);
155}
Note: See TracBrowser for help on using the repository browser.