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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
|
/* servparse.y -- Parser for dictd server configuration file
* Created: Fri Feb 28 08:31:38 1997 by faith@cs.unc.edu
* Copyright 1997 Rickard E. Faith (faith@cs.unc.edu)
* Copyright 2002-2008 Aleksey Cheusov (vle@gmx.net)
*
* 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.
*/
%{
#include "dictd.h"
#include "strategy.h"
#include "index.h"
#include "data.h"
#include "maa.h"
#define YYDEBUG 1
#define YYERROR_VERBOSE
extern int yylex( void );
extern int yydebug;
extern void yyerror( const char *message );
static dictDatabase *db;
static int string2bool (const char *str)
{
if (
!strcasecmp ("1", str)
|| !strcasecmp ("true", str)
|| !strcasecmp ("yes", str))
{
return 1;
}else{
return 0;
}
}
#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.integer> TOKEN_NUMBER
%token <token> '{' '}' TOKEN_ACCESS TOKEN_ALLOW TOKEN_DENY
%token <token> 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_DATABASE_EXIT
%token <token> TOKEN_SITE TOKEN_SITE_NO_BANNER TOKEN_SITE_NO_UPTIME
%token <token> TOKEN_SITE_NO_DBLIST
%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_DATABASE_MIME
%token <token> TOKEN_DEFAULT_STRAT
%token <token> TOKEN_GLOBAL
%token <token> TOKEN_PORT
%token <token> TOKEN_DELAY
%token <token> TOKEN_DEPTH
%token <token> TOKEN_TIMESTAMP
%token <token> TOKEN_LOG_OPTION
%token <token> TOKEN_DEBUG_OPTION
%token <token> TOKEN_LOCALE
%token <token> TOKEN_ADD_STRAT
%token <token> TOKEN_LISTEN_TO
%token <token> TOKEN_ADDRESS_FAMILY
%token <token> TOKEN_SYSLOG
%token <token> TOKEN_SYSLOG_FACILITY
%token <token> TOKEN_LOG_FILE
%token <token> TOKEN_PID_FILE
%token <token> TOKEN_FAST_START
%token <token> TOKEN_WITHOUT_MMAP
%token <token> TOKEN_LIMIT_CHILDS
%token <token> TOKEN_LIMIT_MATCHES
%token <token> TOKEN_LIMIT_DEFS
%token <token> TOKEN_LIMIT_TIME
%token <token> TOKEN_LIMIT_QUERIES
%token <token> TOKEN_MIME_DBNAME
%token <token> TOKEN_NOMIME_DBNAME
%type <token> Site
%type <access> AccessSpec
%type <db> Database
%type <list> DatabaseList Access AccessSpecList
%type <hash> UserList
%type <token> Global
%%
Program : Global DatabaseList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
DictConfig->dbl = $2;
}
| Global Access DatabaseList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
DictConfig->acl = $2;
DictConfig->dbl = $3;
}
| Global DatabaseList UserList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
DictConfig->dbl = $2;
DictConfig->usl = $3;
}
| Global Access DatabaseList UserList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
DictConfig->acl = $2;
DictConfig->dbl = $3;
DictConfig->usl = $4;
}
| Global Site DatabaseList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
site_info = $2.string;
DictConfig->dbl = $3;
}
| Global Site Access DatabaseList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
site_info = $2.string;
DictConfig->acl = $3;
DictConfig->dbl = $4;
}
| Global Site DatabaseList UserList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
site_info = $2.string;
DictConfig->dbl = $3;
DictConfig->usl = $4;
}
| Global Site Access DatabaseList UserList
{ DictConfig = xmalloc(sizeof(struct dictConfig));
memset( DictConfig, 0, sizeof(struct dictConfig) );
site_info = $2.string;
DictConfig->acl = $3;
DictConfig->dbl = $4;
DictConfig->usl = $5;
}
;
Global : {}
| TOKEN_GLOBAL '{' GlobalSpecList '}' {}
;
GlobalSpecList :
| GlobalSpecList GlobalSpec
;
GlobalSpec : TOKEN_PORT TOKEN_STRING
{
if (!daemon_service_set)
daemon_service = str_copy($2.string);
}
| TOKEN_SITE TOKEN_STRING
{
if (site_info){
/* site is specified twice */
xfree ((void *) site_info);
}
site_info = $2.string;
}
| TOKEN_SITE_NO_BANNER TOKEN_STRING
{
site_info_no_banner = string2bool ($2.string);
fprintf (stderr, "site_info_no_banner=%d\n", site_info_no_banner);
}
| TOKEN_SITE_NO_UPTIME TOKEN_STRING
{
site_info_no_uptime = string2bool ($2.string);
}
| TOKEN_SITE_NO_DBLIST TOKEN_STRING
{
site_info_no_dblist = string2bool ($2.string);
}
| TOKEN_PORT TOKEN_NUMBER
{
if (!daemon_service_set){
char number [40] = "";
snprintf (number, sizeof (number), "%d", $2);
daemon_service = str_copy (number);
}
}
| TOKEN_DELAY TOKEN_NUMBER
{
if (!client_delay_set)
client_delay = $2;
_dict_daemon_limit_time = 0;
}
| TOKEN_DEPTH TOKEN_NUMBER
{
if (!depth_set)
depth = $2;
}
| TOKEN_LIMIT_CHILDS TOKEN_NUMBER
{
if (!_dict_daemon_limit_childs_set)
_dict_daemon_limit_childs = $2;
}
| TOKEN_LIMIT_MATCHES TOKEN_NUMBER
{
_dict_daemon_limit_matches = $2;
}
| TOKEN_LIMIT_DEFS TOKEN_NUMBER
{
_dict_daemon_limit_defs = $2;
}
| TOKEN_LIMIT_TIME TOKEN_NUMBER
{
_dict_daemon_limit_time = $2;
client_delay = 0;
}
| TOKEN_LIMIT_QUERIES TOKEN_NUMBER
{
_dict_daemon_limit_queries = $2;
}
| TOKEN_TIMESTAMP TOKEN_NUMBER
{
if (!_dict_markTime_set)
_dict_markTime = 60*$2;
}
| TOKEN_LOG_OPTION TOKEN_STRING
{
++logOptions;
flg_set ($2.string);
if (flg_test (LOG_MIN))
set_minimal ();
}
| TOKEN_DEBUG_OPTION TOKEN_STRING
{
dbg_set ($2.string);
}
| TOKEN_LOCALE TOKEN_STRING
{
if (!locale_set)
locale = str_copy ($2.string);
}
| TOKEN_DEFAULT_STRAT TOKEN_STRING
{
if (!default_strategy_set)
default_strategy = lookup_strategy_ex ($2.string);
}
| TOKEN_DISABLE_STRAT TOKEN_STRING
{
dict_disable_strategies ($2.string);
}
| TOKEN_ADD_STRAT TOKEN_STRING TOKEN_STRING
{
dict_add_strategy ($2.string, $3.string);
}
| TOKEN_LISTEN_TO TOKEN_STRING
{
if (!bind_to_set)
if ($2.string[0] != '*' || $2.string[1] != '\0')
bind_to = str_copy ($2.string);
}
| TOKEN_ADDRESS_FAMILY TOKEN_NUMBER
{
if (!dictd_address_family_set){
if ($2 == 4)
dictd_address_family = AF_INET;
else if ($2 == 6)
dictd_address_family = AF_INET6;
else {
log_error (NULL, ":E: Incorrect value '%d' for global option 'address_family'\n", $2);
exit(1);
}
}
}
| TOKEN_SYSLOG
{
++useSyslog;
}
| TOKEN_SYSLOG_FACILITY TOKEN_STRING
{
++useSyslog;
if (!syslog_facility_set){
log_set_facility ($2.string);
}
}
| TOKEN_LOG_FILE TOKEN_STRING
{
if (!logFile_set){
logFile = str_copy ($2.string);
}
}
| TOKEN_PID_FILE TOKEN_STRING
{
if (!pidFile_set){
pidFile = str_copy ($2.string);
}
}
| TOKEN_FAST_START
{
optStart_mode = 0;
}
| TOKEN_WITHOUT_MMAP
{
mmap_mode = 0;
}
;
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;
log_error (NULL, ":E: Move \"site\" directive to section \"global\" of the configuration file!\n");
}
;
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_MIME TOKEN_STRING
{
db = xmalloc (sizeof (struct dictDatabase));
memset (db, 0, sizeof (struct dictDatabase));
db->databaseName = $2.string;
db->mime_db = 1;
}
'{' SpecList_mime '}' { $$ = 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
;
SpecList_mime : Spec_mime
| SpecList_mime Spec_mime
;
Spec_mime : Spec__name
| Spec__info
| Spec__dbname_mime
| Spec__dbname_nomime
| Spec__invisible
| Spec__disable_strat
| Spec__default_strat
| Spec__access
;
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__default_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); };
Spec__dbname_mime : TOKEN_MIME_DBNAME TOKEN_STRING
{ SET(mime_mimeDbname,$1,$2); };
Spec__dbname_nomime : TOKEN_NOMIME_DBNAME TOKEN_STRING
{ SET(mime_nomimeDbname,$1,$2); };
|