File: servparse.y

package info (click to toggle)
dictd 1.9.15-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,760 kB
  • ctags: 3,266
  • sloc: ansic: 28,734; sh: 4,576; makefile: 1,002; perl: 410; yacc: 280; cpp: 275; lex: 217
file content (293 lines) | stat: -rw-r--r-- 8,699 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* servparse.y -- Parser for dictd server configuration file
 * Created: Fri Feb 28 08:31:38 1997 by faith@cs.unc.edu
 * Revised: Fri Jul 11 11:42:51 1997 by faith@acm.org
 * Copyright 1997 Rickard E. Faith (faith@cs.unc.edu)
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 1, or (at your option) any
 * later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 * $Id: servparse.y,v 1.20 2004/10/12 14:39:03 cheusov Exp $
 * 
 */

%{
#include "dictd.h"
#include "strategy.h"
#define YYDEBUG 1
#define YYERROR_VERBOSE

static dictDatabase *db;

#define SET(field,s,t) do {                                   \
   if (db->field)                                             \
      src_parse_error( stderr, s.src, #field "already set" ); \
   db->field = t.string;                                      \
} while(0);
%}

%union {
   dictToken     token;
   dictDatabase  *db;
   dictAccess    *access;
   lst_List      list;
   hsh_HashTable hash;
}

				/* Terminals */

%token <token> '{' '}' TOKEN_ACCESS TOKEN_ALLOW TOKEN_DENY TOKEN_GROUP TOKEN_DATABASE TOKEN_DATA
%token <token> TOKEN_INDEX TOKEN_INDEX_SUFFIX TOKEN_INDEX_WORD
%token <token> TOKEN_FILTER TOKEN_PREFILTER TOKEN_POSTFILTER TOKEN_NAME TOKEN_INFO
%token <token> TOKEN_USER TOKEN_AUTHONLY TOKEN_SITE TOKEN_DATABASE_EXIT
%token <token> TOKEN_STRING
%token <token> TOKEN_INVISIBLE TOKEN_DISABLE_STRAT
%token <token> TOKEN_DATABASE_VIRTUAL TOKEN_DATABASE_LIST
%token <token> TOKEN_DATABASE_PLUGIN TOKEN_PLUGIN
%token <token> TOKEN_DEFAULT_STRAT

%type  <token>  Site
%type  <access> AccessSpec
%type  <db>     Database
%type  <list>   DatabaseList Access AccessSpecList
%type  <hash>   UserList

%%

Program : DatabaseList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->dbl = $1;
	  }
        | Access DatabaseList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->acl = $1;
	    DictConfig->dbl = $2;
	  }
        | DatabaseList UserList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->dbl = $1;
	    DictConfig->usl = $2;
	  }
        | Access DatabaseList UserList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->acl = $1;
	    DictConfig->dbl = $2;
	    DictConfig->usl = $3;
	  }
        | Site DatabaseList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->site = $1.string;
	    DictConfig->dbl  = $2;
	  }
        | Site Access DatabaseList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->site = $1.string;
	    DictConfig->acl  = $2;
	    DictConfig->dbl  = $3;
	  }
        | Site DatabaseList UserList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->site = $1.string;
	    DictConfig->dbl  = $2;
	    DictConfig->usl  = $3;
	  }
        | Site Access DatabaseList UserList
          { DictConfig = xmalloc(sizeof(struct dictConfig));
	    memset( DictConfig, 0, sizeof(struct dictConfig) );
	    DictConfig->site = $1.string;
	    DictConfig->acl  = $2;
	    DictConfig->dbl  = $3;
	    DictConfig->usl  = $4;
	  }
        ;


Access : TOKEN_ACCESS '{' AccessSpecList '}' { $$ = $3; }
       ;

DatabaseList : Database { $$ = lst_create(); lst_append($$, $1); }
             | DatabaseList Database { lst_append($1, $2); $$ = $1; }
             ;

AccessSpecList : AccessSpec { $$ = lst_create(); lst_append($$, $1); }
               | AccessSpecList AccessSpec { lst_append($1, $2); $$ = $1; }
               ;

Site : TOKEN_SITE TOKEN_STRING { $$ = $2; }
     ;

UserList : TOKEN_USER TOKEN_STRING TOKEN_STRING
           { $$ = hsh_create(NULL,NULL);
	     hsh_insert( $$, $2.string, $3.string );
	   }
         | UserList TOKEN_USER TOKEN_STRING TOKEN_STRING
           { hsh_insert( $1, $3.string, $4.string ); $$ = $1; }
         ;

AccessSpec : TOKEN_ALLOW TOKEN_STRING
             {
		dictAccess *a = xmalloc(sizeof(struct dictAccess));
		a->type = DICT_ALLOW;
		a->spec = $2.string;
		$$ = a;
	     }
           | TOKEN_DENY TOKEN_STRING
             {
		dictAccess *a = xmalloc(sizeof(struct dictAccess));
		a->type = DICT_DENY;
		a->spec = $2.string;
		$$ = a;
	     }
           | TOKEN_AUTHONLY TOKEN_STRING
             {
		dictAccess *a = xmalloc(sizeof(struct dictAccess));
		a->type = DICT_AUTHONLY;
		a->spec = $2.string;
		$$ = a;
	     }
           | TOKEN_USER TOKEN_STRING
             {
		dictAccess *a = xmalloc(sizeof(struct dictAccess));
		a->type = DICT_USER;
		a->spec = $2.string;
		$$ = a;
	     }
           ;

Database : TOKEN_DATABASE TOKEN_STRING
           {
	      db = xmalloc(sizeof(struct dictDatabase));
	      memset( db, 0, sizeof(struct dictDatabase));
	      db->databaseName = $2.string;
	      db->normal_db    = 1;
	   }
           '{' SpecList '}' { $$ = db; }
           |
           TOKEN_DATABASE_VIRTUAL TOKEN_STRING
           {
	      db = xmalloc(sizeof(struct dictDatabase));
	      memset( db, 0, sizeof(struct dictDatabase));
	      db->databaseName = $2.string;
	      db->virtual_db   = 1;
	   }
           '{' SpecList_virtual '}' { $$ = db; }
           |
           TOKEN_DATABASE_PLUGIN TOKEN_STRING
           {
	      db = xmalloc(sizeof(struct dictDatabase));
	      memset( db, 0, sizeof(struct dictDatabase));
	      db->databaseName = $2.string;
	      db->plugin_db    = 1;
	   }
           '{' SpecList_plugin '}' { $$ = db; }
           |
	   TOKEN_DATABASE_EXIT
	   {
	      db = xmalloc(sizeof(struct dictDatabase));
	      memset( db, 0, sizeof(struct dictDatabase));
	      db -> databaseName  = strdup("--exit--");
	      db -> databaseShort = strdup("Stop default search here.");
	      db -> exit_db       = 1;
	      $$ = db;
	   }
         ;

SpecList_virtual : Spec_virtual
         | SpecList_virtual Spec_virtual
         ;

Spec_virtual : Spec__name
     | Spec__info
     | TOKEN_DATABASE_LIST TOKEN_STRING      { SET(database_list,$1,$2);}
     | Spec__invisible
     | Spec__disable_strat
     | Spec__access
     ;

SpecList_plugin : Spec_plugin
         | SpecList_plugin Spec_plugin
         ;

Spec_plugin : Spec__name
     | Spec__info
     | TOKEN_PLUGIN TOKEN_STRING      { SET(pluginFilename,$1,$2);}
     | TOKEN_DATA TOKEN_STRING        { SET(plugin_data,$1,$2);}
     | Spec__invisible
     | Spec__disable_strat
     | Spec__access
     ;

SpecList : Spec
         | SpecList Spec
         ;

Spec : Spec__data
     | Spec__index
     | Spec__index_suffix
     | Spec__index_word
     | Spec__filter
     | Spec__prefilter
     | Spec__postfilter
     | Spec__name
     | Spec__info
     | Spec__invisible
     | Spec__disable_strat
     | Spec__default_strat
     | Spec__access
     ;

Spec__access : Access
     {  db->acl = $1;  };

Spec__data : TOKEN_DATA TOKEN_STRING
     {	SET(dataFilename,$1,$2);  };

Spec__index : TOKEN_INDEX TOKEN_STRING
     {  SET(indexFilename,$1,$2);  };

Spec__index_suffix : TOKEN_INDEX_SUFFIX TOKEN_STRING
     {  SET(indexsuffixFilename,$1,$2); };

Spec__index_word : TOKEN_INDEX_WORD TOKEN_STRING
     {  SET(indexwordFilename,$1,$2);  };

Spec__filter : TOKEN_FILTER TOKEN_STRING
     {  SET(filter,$1,$2);  };

Spec__prefilter : TOKEN_PREFILTER TOKEN_STRING
     {  SET(prefilter,$1,$2);  };

Spec__postfilter : TOKEN_POSTFILTER TOKEN_STRING
     {  SET(postfilter,$1,$2);  };

Spec__name : TOKEN_NAME TOKEN_STRING
     {  SET(databaseShort,$1,$2);  };

Spec__info : TOKEN_INFO TOKEN_STRING
     {  SET(databaseInfo,$1,$2);  };

Spec__invisible : TOKEN_INVISIBLE 
     {  db->invisible = 1;  };

Spec__disable_strat : TOKEN_DISABLE_STRAT TOKEN_STRING
     {  dict_disable_strat (db, $2.string);  };

Spec__default_strat : TOKEN_DEFAULT_STRAT TOKEN_STRING
     {  db -> default_strategy = lookup_strategy_ex ($2.string);  };