PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/syslog-ng-3.2.5/lib/pragma-grammar.y

#
Happy | 499 lines | 406 code | 93 blank | 0 comment | 0 complexity | 663a1c3143965a78ef96678204b1d816 MD5 | raw file
  1. /*
  2. * Copyright (c) 2002-2010 BalaBit IT Ltd, Budapest, Hungary
  3. * Copyright (c) 1998-2010 Bal??zs Scheidler
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * As an additional exemption you are allowed to compile & link against the
  20. * OpenSSL libraries as published by the OpenSSL project. See the file
  21. * COPYING for details.
  22. *
  23. */
  24. %code requires {
  25. #include "pragma-parser.h"
  26. #include "plugin.h"
  27. #include <string.h>
  28. }
  29. %name-prefix "pragma_"
  30. %lex-param {CfgLexer *lexer}
  31. %parse-param {CfgLexer *lexer}
  32. %parse-param {gpointer *result}
  33. %require "2.4.1"
  34. %locations
  35. %define api.pure
  36. %pure-parser
  37. %error-verbose
  38. %code {
  39. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  40. do { \
  41. if (YYID (N)) \
  42. { \
  43. (Current).level = YYRHSLOC(Rhs, 1).level; \
  44. (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  45. (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  46. (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  47. (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  48. } \
  49. else \
  50. { \
  51. (Current).level = YYRHSLOC(Rhs, 0).level; \
  52. (Current).first_line = (Current).last_line = \
  53. YYRHSLOC (Rhs, 0).last_line; \
  54. (Current).first_column = (Current).last_column = \
  55. YYRHSLOC (Rhs, 0).last_column; \
  56. } \
  57. } while (YYID (0))
  58. #define CHECK_ERROR(val, token, errorfmt, ...) do { \
  59. if (!(val)) \
  60. { \
  61. if (errorfmt) \
  62. { \
  63. gchar __buf[256]; \
  64. g_snprintf(__buf, sizeof(__buf), errorfmt ? errorfmt : "x", ## __VA_ARGS__); \
  65. yyerror(& (token), lexer, NULL, __buf); \
  66. } \
  67. YYERROR; \
  68. } \
  69. } while (0)
  70. #define YYMAXDEPTH 20000
  71. }
  72. /* plugin types, must be equal to the numerical values of the plugin type in plugin.h */
  73. %token LL_CONTEXT_ROOT 1
  74. %token LL_CONTEXT_DESTINATION 2
  75. %token LL_CONTEXT_SOURCE 3
  76. %token LL_CONTEXT_PARSER 4
  77. %token LL_CONTEXT_REWRITE 5
  78. %token LL_CONTEXT_FILTER 6
  79. %token LL_CONTEXT_LOG 7
  80. %token LL_CONTEXT_BLOCK_DEF 8
  81. %token LL_CONTEXT_BLOCK_REF 9
  82. %token LL_CONTEXT_BLOCK_CONTENT 10
  83. %token LL_CONTEXT_PRAGMA 11
  84. %token LL_CONTEXT_FORMAT 12
  85. %token LL_CONTEXT_TEMPLATE_FUNC 13
  86. /* statements */
  87. %token KW_SOURCE 10000
  88. %token KW_FILTER 10001
  89. %token KW_PARSER 10002
  90. %token KW_DESTINATION 10003
  91. %token KW_LOG 10004
  92. %token KW_OPTIONS 10005
  93. %token KW_INCLUDE 10006
  94. %token KW_BLOCK 10007
  95. /* source & destination items */
  96. %token KW_INTERNAL 10010
  97. %token KW_FILE 10011
  98. %token KW_SQL 10030
  99. %token KW_TYPE 10031
  100. %token KW_COLUMNS 10032
  101. %token KW_INDEXES 10033
  102. %token KW_VALUES 10034
  103. %token KW_PASSWORD 10035
  104. %token KW_DATABASE 10036
  105. %token KW_USERNAME 10037
  106. %token KW_TABLE 10038
  107. %token KW_ENCODING 10039
  108. %token KW_SESSION_STATEMENTS 10040
  109. %token KW_DELIMITERS 10050
  110. %token KW_QUOTES 10051
  111. %token KW_QUOTE_PAIRS 10052
  112. %token KW_NULL 10053
  113. %token KW_SYSLOG 10060
  114. /* option items */
  115. %token KW_MARK_FREQ 10071
  116. %token KW_STATS_FREQ 10072
  117. %token KW_STATS_LEVEL 10073
  118. %token KW_FLUSH_LINES 10074
  119. %token KW_SUPPRESS 10075
  120. %token KW_FLUSH_TIMEOUT 10076
  121. %token KW_LOG_MSG_SIZE 10077
  122. %token KW_FILE_TEMPLATE 10078
  123. %token KW_PROTO_TEMPLATE 10079
  124. %token KW_CHAIN_HOSTNAMES 10090
  125. %token KW_NORMALIZE_HOSTNAMES 10091
  126. %token KW_KEEP_HOSTNAME 10092
  127. %token KW_CHECK_HOSTNAME 10093
  128. %token KW_BAD_HOSTNAME 10094
  129. %token KW_KEEP_TIMESTAMP 10100
  130. %token KW_USE_DNS 10110
  131. %token KW_USE_FQDN 10111
  132. %token KW_DNS_CACHE 10120
  133. %token KW_DNS_CACHE_SIZE 10121
  134. %token KW_DNS_CACHE_EXPIRE 10130
  135. %token KW_DNS_CACHE_EXPIRE_FAILED 10131
  136. %token KW_DNS_CACHE_HOSTS 10132
  137. %token KW_PERSIST_ONLY 10140
  138. %token KW_TZ_CONVERT 10150
  139. %token KW_TS_FORMAT 10151
  140. %token KW_FRAC_DIGITS 10152
  141. %token KW_LOG_FIFO_SIZE 10160
  142. %token KW_LOG_FETCH_LIMIT 10162
  143. %token KW_LOG_IW_SIZE 10163
  144. %token KW_LOG_PREFIX 10164
  145. %token KW_PROGRAM_OVERRIDE 10165
  146. %token KW_HOST_OVERRIDE 10166
  147. %token KW_THROTTLE 10170
  148. /* log statement options */
  149. %token KW_FLAGS 10190
  150. /* reader options */
  151. %token KW_PAD_SIZE 10200
  152. %token KW_TIME_ZONE 10201
  153. %token KW_RECV_TIME_ZONE 10202
  154. %token KW_SEND_TIME_ZONE 10203
  155. %token KW_LOCAL_TIME_ZONE 10204
  156. %token KW_FORMAT 10205
  157. /* timers */
  158. %token KW_TIME_REOPEN 10210
  159. %token KW_TIME_REAP 10211
  160. %token KW_TIME_SLEEP 10212
  161. /* destination options */
  162. %token KW_TMPL_ESCAPE 10220
  163. /* driver specific options */
  164. %token KW_OPTIONAL 10230
  165. /* file related options */
  166. %token KW_CREATE_DIRS 10240
  167. %token KW_OWNER 10250
  168. %token KW_GROUP 10251
  169. %token KW_PERM 10252
  170. %token KW_DIR_OWNER 10260
  171. %token KW_DIR_GROUP 10261
  172. %token KW_DIR_PERM 10262
  173. %token KW_TEMPLATE 10270
  174. %token KW_TEMPLATE_ESCAPE 10271
  175. %token KW_DEFAULT_FACILITY 10300
  176. %token KW_DEFAULT_LEVEL 10301
  177. %token KW_PORT 10323
  178. /* misc options */
  179. %token KW_USE_TIME_RECVD 10340
  180. /* filter items*/
  181. %token KW_FACILITY 10350
  182. %token KW_LEVEL 10351
  183. %token KW_HOST 10352
  184. %token KW_MATCH 10353
  185. %token KW_MESSAGE 10354
  186. %token KW_NETMASK 10355
  187. %token KW_TAGS 10356
  188. /* parser items */
  189. %token KW_VALUE 10361
  190. /* rewrite items */
  191. %token KW_REWRITE 10370
  192. %token KW_SET 10371
  193. %token KW_SUBST 10372
  194. /* yes/no switches */
  195. %token KW_YES 10380
  196. %token KW_NO 10381
  197. %token KW_IFDEF 10410
  198. %token KW_ENDIF 10411
  199. %token LL_DOTDOT 10420
  200. %token <cptr> LL_IDENTIFIER 10421
  201. %token <num> LL_NUMBER 10422
  202. %token <fnum> LL_FLOAT 10423
  203. %token <cptr> LL_STRING 10424
  204. %token <token> LL_TOKEN 10425
  205. %token <cptr> LL_BLOCK 10426
  206. %token LL_PRAGMA 10427
  207. %token LL_EOL 10428
  208. %token LL_ERROR 10429
  209. %type <num> yesno
  210. %type <num> dnsmode
  211. %type <num> regexp_option_flags
  212. %type <num> dest_writer_options_flags
  213. %type <cptr> string
  214. %type <cptr> string_or_number
  215. %type <ptr> string_list
  216. %type <ptr> string_list_build
  217. %type <num> facility_string
  218. %type <num> level_string
  219. %token KW_VERSION
  220. %token KW_DEFINE
  221. %token KW_MODULE
  222. %code {
  223. #include <stdlib.h>
  224. CfgArgs *last_module_args = NULL;
  225. gint
  226. __process_version_string(gchar *value)
  227. {
  228. gchar *p, *end;
  229. gint major, minor;
  230. p = strchr(value, '.');
  231. if (p)
  232. {
  233. major = strtol(value, &end, 10);
  234. if (end == p)
  235. {
  236. minor = strtol(p+1, &end, 10);
  237. if (end)
  238. {
  239. return (major << 8) + minor;
  240. }
  241. }
  242. }
  243. return 0;
  244. }
  245. }
  246. %%
  247. start
  248. : { lexer->tokenize_eol++; }
  249. stmt_and_eol { lexer->tokenize_eol--; if (yychar != YYEMPTY) { cfg_lexer_unput_token(lexer, &yylval); } YYACCEPT; }
  250. stmt_and_eol
  251. : pragma_stmt LL_EOL
  252. | include_stmt
  253. ;
  254. pragma_stmt
  255. : KW_VERSION ':' string_or_number { configuration->parsed_version = __process_version_string($3); free($3); }
  256. | define_stmt
  257. | module_stmt
  258. ;
  259. include_stmt
  260. : KW_INCLUDE string LL_EOL
  261. {
  262. CHECK_ERROR(cfg_lexer_include_file(lexer, $2), @2, "Error including %s", $2);
  263. free($2);
  264. }
  265. ;
  266. define_stmt
  267. : KW_DEFINE LL_IDENTIFIER string_or_number { msg_debug("Global value changed",
  268. evt_tag_str("define", $2),
  269. evt_tag_str("value", $3),
  270. NULL);
  271. cfg_args_set(lexer->globals, $2, $3); free($2); free($3); }
  272. module_stmt
  273. : KW_MODULE string { last_module_args = cfg_args_new(); } module_params
  274. {
  275. plugin_load_module($2, configuration, last_module_args);
  276. free($2);
  277. cfg_args_free(last_module_args);
  278. last_module_args = NULL;
  279. }
  280. ;
  281. module_params
  282. : module_param module_params
  283. |
  284. ;
  285. module_param
  286. : LL_IDENTIFIER '(' string_or_number ')' { cfg_args_set(last_module_args, $1, $3); free($1); free($3); }
  287. ;
  288. string
  289. : LL_IDENTIFIER
  290. | LL_STRING
  291. ;
  292. yesno
  293. : KW_YES { $$ = 1; }
  294. | KW_NO { $$ = 0; }
  295. | LL_NUMBER { $$ = $1; }
  296. ;
  297. dnsmode
  298. : yesno { $$ = $1; }
  299. | KW_PERSIST_ONLY { $$ = 2; }
  300. ;
  301. string_or_number
  302. : string { $$ = $1; }
  303. | LL_NUMBER { $$ = strdup(lexer->token_text->str); }
  304. | LL_FLOAT { $$ = strdup(lexer->token_text->str); }
  305. ;
  306. string_list
  307. : string_list_build { $$ = g_list_reverse($1); }
  308. ;
  309. string_list_build
  310. : string string_list_build { $$ = g_list_append($2, g_strdup($1)); free($1); }
  311. | { $$ = NULL; }
  312. ;
  313. level_string
  314. : string
  315. {
  316. /* return the numeric value of the "level" */
  317. int n = syslog_name_lookup_level_by_name($1);
  318. CHECK_ERROR((n != -1), @1, "Unknown priority level\"%s\"", $1);
  319. free($1);
  320. $$ = n;
  321. }
  322. ;
  323. facility_string
  324. : string
  325. {
  326. /* return the numeric value of facility */
  327. int n = syslog_name_lookup_facility_by_name($1);
  328. CHECK_ERROR((n != -1), @1, "Unknown facility \"%s\"", $1);
  329. free($1);
  330. $$ = n;
  331. }
  332. | KW_SYSLOG { $$ = LOG_SYSLOG; }
  333. ;
  334. regexp_option_flags
  335. : string regexp_option_flags { $$ = log_matcher_lookup_flag($1) | $2; free($1); }
  336. | { $$ = 0; }
  337. ;
  338. source_reader_options
  339. : source_reader_option source_reader_options
  340. |
  341. ;
  342. source_reader_option
  343. : KW_LOG_IW_SIZE '(' LL_NUMBER ')' { last_reader_options->super.init_window_size = $3; }
  344. | KW_CHAIN_HOSTNAMES '(' yesno ')' { last_reader_options->super.chain_hostnames = $3; }
  345. | KW_NORMALIZE_HOSTNAMES '(' yesno ')' { last_reader_options->super.normalize_hostnames = $3; }
  346. | KW_KEEP_HOSTNAME '(' yesno ')' { last_reader_options->super.keep_hostname = $3; }
  347. | KW_USE_FQDN '(' yesno ')' { last_reader_options->super.use_fqdn = $3; }
  348. | KW_USE_DNS '(' dnsmode ')' { last_reader_options->super.use_dns = $3; }
  349. | KW_DNS_CACHE '(' yesno ')' { last_reader_options->super.use_dns_cache = $3; }
  350. | KW_PROGRAM_OVERRIDE '(' string ')' { last_reader_options->super.program_override = g_strdup($3); free($3); }
  351. | KW_HOST_OVERRIDE '(' string ')' { last_reader_options->super.host_override = g_strdup($3); free($3); }
  352. | KW_LOG_PREFIX '(' string ')' { gchar *p = strrchr($3, ':'); if (p) *p = 0; last_reader_options->super.program_override = g_strdup($3); free($3); }
  353. | KW_TIME_ZONE '(' string ')' { last_reader_options->parse_options.recv_time_zone = g_strdup($3); free($3); }
  354. | KW_CHECK_HOSTNAME '(' yesno ')' { last_reader_options->check_hostname = $3; }
  355. | KW_FLAGS '(' source_reader_option_flags ')'
  356. | KW_LOG_MSG_SIZE '(' LL_NUMBER ')' { last_reader_options->msg_size = $3; }
  357. | KW_LOG_FETCH_LIMIT '(' LL_NUMBER ')' { last_reader_options->fetch_limit = $3; }
  358. | KW_PAD_SIZE '(' LL_NUMBER ')' { last_reader_options->padding = $3; }
  359. | KW_KEEP_TIMESTAMP '(' yesno ')' { last_reader_options->super.keep_timestamp = $3; }
  360. | KW_ENCODING '(' string ')' { last_reader_options->text_encoding = g_strdup($3); free($3); }
  361. | KW_TAGS '(' string_list ')' { log_reader_options_set_tags(last_reader_options, $3); }
  362. | KW_FORMAT '(' string ')' { last_reader_options->parse_options.format = g_strdup($3); free($3); }
  363. | KW_DEFAULT_LEVEL '(' level_string ')'
  364. {
  365. if (last_reader_options->parse_options.default_pri == 0xFFFF)
  366. last_reader_options->parse_options.default_pri = LOG_USER;
  367. last_reader_options->parse_options.default_pri = (last_reader_options->parse_options.default_pri & ~7) | $3;
  368. }
  369. | KW_DEFAULT_FACILITY '(' facility_string ')'
  370. {
  371. if (last_reader_options->parse_options.default_pri == 0xFFFF)
  372. last_reader_options->parse_options.default_pri = LOG_NOTICE;
  373. last_reader_options->parse_options.default_pri = (last_reader_options->parse_options.default_pri & 7) | $3;
  374. }
  375. ;
  376. source_reader_option_flags
  377. : string source_reader_option_flags { CHECK_ERROR(log_reader_options_process_flag(last_reader_options, $1), @1, "Unknown flag %s", $1); free($1); }
  378. |
  379. ;
  380. dest_writer_options
  381. : dest_writer_option dest_writer_options
  382. |
  383. ;
  384. dest_writer_option
  385. : KW_FLAGS '(' dest_writer_options_flags ')' { last_writer_options->options = $3; }
  386. | KW_LOG_FIFO_SIZE '(' LL_NUMBER ')' { last_writer_options->mem_fifo_size = $3; }
  387. | KW_FLUSH_LINES '(' LL_NUMBER ')' { last_writer_options->flush_lines = $3; }
  388. | KW_FLUSH_TIMEOUT '(' LL_NUMBER ')' { last_writer_options->flush_timeout = $3; }
  389. | KW_SUPPRESS '(' LL_NUMBER ')' { last_writer_options->suppress = $3; }
  390. | KW_TEMPLATE '(' string ')' {
  391. GError *error = NULL;
  392. last_writer_options->template = cfg_check_inline_template(configuration, $3);
  393. CHECK_ERROR(log_template_compile(last_writer_options->template, &error), @3, "Error compiling template (%s)", error->message);
  394. free($3);
  395. }
  396. | KW_TEMPLATE_ESCAPE '(' yesno ')' { log_writer_options_set_template_escape(last_writer_options, $3); }
  397. | KW_TIME_ZONE '(' string ')' { last_writer_options->template_options.time_zone[LTZ_SEND] = g_strdup($3); free($3); }
  398. | KW_TS_FORMAT '(' string ')' { last_writer_options->template_options.ts_format = cfg_ts_format_value($3); free($3); }
  399. | KW_FRAC_DIGITS '(' LL_NUMBER ')' { last_writer_options->template_options.frac_digits = $3; }
  400. | KW_THROTTLE '(' LL_NUMBER ')' { last_writer_options->throttle = $3; }
  401. ;
  402. dest_writer_options_flags
  403. : string dest_writer_options_flags { $$ = log_writer_options_lookup_flag($1) | $2; free($1); }
  404. | { $$ = 0; }
  405. ;
  406. %%