PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/syslog-ng-3.2.5/lib/parser-expr-grammar.y

#
Happy | 462 lines | 372 code | 90 blank | 0 comment | 0 complexity | d5ef6291c438de859702bc00aacd7254 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 "parser-expr-parser.h"
  26. }
  27. %code {
  28. #include "syslog-names.h"
  29. #include "parser-expr-grammar.h"
  30. #include "plugin.h"
  31. LogParser *last_parser;
  32. }
  33. %name-prefix "parser_expr_"
  34. %lex-param {CfgLexer *lexer}
  35. %parse-param {CfgLexer *lexer}
  36. %parse-param {GList **result}
  37. %type <ptr> parser_expr
  38. %type <ptr> parser_expr_list
  39. %type <ptr> parser_expr_list_build
  40. %require "2.4.1"
  41. %locations
  42. %define api.pure
  43. %pure-parser
  44. %error-verbose
  45. %code {
  46. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  47. do { \
  48. if (YYID (N)) \
  49. { \
  50. (Current).level = YYRHSLOC(Rhs, 1).level; \
  51. (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  52. (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  53. (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  54. (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  55. } \
  56. else \
  57. { \
  58. (Current).level = YYRHSLOC(Rhs, 0).level; \
  59. (Current).first_line = (Current).last_line = \
  60. YYRHSLOC (Rhs, 0).last_line; \
  61. (Current).first_column = (Current).last_column = \
  62. YYRHSLOC (Rhs, 0).last_column; \
  63. } \
  64. } while (YYID (0))
  65. #define CHECK_ERROR(val, token, errorfmt, ...) do { \
  66. if (!(val)) \
  67. { \
  68. if (errorfmt) \
  69. { \
  70. gchar __buf[256]; \
  71. g_snprintf(__buf, sizeof(__buf), errorfmt ? errorfmt : "x", ## __VA_ARGS__); \
  72. yyerror(& (token), lexer, NULL, __buf); \
  73. } \
  74. YYERROR; \
  75. } \
  76. } while (0)
  77. #define YYMAXDEPTH 20000
  78. }
  79. /* plugin types, must be equal to the numerical values of the plugin type in plugin.h */
  80. %token LL_CONTEXT_ROOT 1
  81. %token LL_CONTEXT_DESTINATION 2
  82. %token LL_CONTEXT_SOURCE 3
  83. %token LL_CONTEXT_PARSER 4
  84. %token LL_CONTEXT_REWRITE 5
  85. %token LL_CONTEXT_FILTER 6
  86. %token LL_CONTEXT_LOG 7
  87. %token LL_CONTEXT_BLOCK_DEF 8
  88. %token LL_CONTEXT_BLOCK_REF 9
  89. %token LL_CONTEXT_BLOCK_CONTENT 10
  90. %token LL_CONTEXT_PRAGMA 11
  91. %token LL_CONTEXT_FORMAT 12
  92. %token LL_CONTEXT_TEMPLATE_FUNC 13
  93. /* statements */
  94. %token KW_SOURCE 10000
  95. %token KW_FILTER 10001
  96. %token KW_PARSER 10002
  97. %token KW_DESTINATION 10003
  98. %token KW_LOG 10004
  99. %token KW_OPTIONS 10005
  100. %token KW_INCLUDE 10006
  101. %token KW_BLOCK 10007
  102. /* source & destination items */
  103. %token KW_INTERNAL 10010
  104. %token KW_FILE 10011
  105. %token KW_SQL 10030
  106. %token KW_TYPE 10031
  107. %token KW_COLUMNS 10032
  108. %token KW_INDEXES 10033
  109. %token KW_VALUES 10034
  110. %token KW_PASSWORD 10035
  111. %token KW_DATABASE 10036
  112. %token KW_USERNAME 10037
  113. %token KW_TABLE 10038
  114. %token KW_ENCODING 10039
  115. %token KW_SESSION_STATEMENTS 10040
  116. %token KW_DELIMITERS 10050
  117. %token KW_QUOTES 10051
  118. %token KW_QUOTE_PAIRS 10052
  119. %token KW_NULL 10053
  120. %token KW_SYSLOG 10060
  121. /* option items */
  122. %token KW_MARK_FREQ 10071
  123. %token KW_STATS_FREQ 10072
  124. %token KW_STATS_LEVEL 10073
  125. %token KW_FLUSH_LINES 10074
  126. %token KW_SUPPRESS 10075
  127. %token KW_FLUSH_TIMEOUT 10076
  128. %token KW_LOG_MSG_SIZE 10077
  129. %token KW_FILE_TEMPLATE 10078
  130. %token KW_PROTO_TEMPLATE 10079
  131. %token KW_CHAIN_HOSTNAMES 10090
  132. %token KW_NORMALIZE_HOSTNAMES 10091
  133. %token KW_KEEP_HOSTNAME 10092
  134. %token KW_CHECK_HOSTNAME 10093
  135. %token KW_BAD_HOSTNAME 10094
  136. %token KW_KEEP_TIMESTAMP 10100
  137. %token KW_USE_DNS 10110
  138. %token KW_USE_FQDN 10111
  139. %token KW_DNS_CACHE 10120
  140. %token KW_DNS_CACHE_SIZE 10121
  141. %token KW_DNS_CACHE_EXPIRE 10130
  142. %token KW_DNS_CACHE_EXPIRE_FAILED 10131
  143. %token KW_DNS_CACHE_HOSTS 10132
  144. %token KW_PERSIST_ONLY 10140
  145. %token KW_TZ_CONVERT 10150
  146. %token KW_TS_FORMAT 10151
  147. %token KW_FRAC_DIGITS 10152
  148. %token KW_LOG_FIFO_SIZE 10160
  149. %token KW_LOG_FETCH_LIMIT 10162
  150. %token KW_LOG_IW_SIZE 10163
  151. %token KW_LOG_PREFIX 10164
  152. %token KW_PROGRAM_OVERRIDE 10165
  153. %token KW_HOST_OVERRIDE 10166
  154. %token KW_THROTTLE 10170
  155. /* log statement options */
  156. %token KW_FLAGS 10190
  157. /* reader options */
  158. %token KW_PAD_SIZE 10200
  159. %token KW_TIME_ZONE 10201
  160. %token KW_RECV_TIME_ZONE 10202
  161. %token KW_SEND_TIME_ZONE 10203
  162. %token KW_LOCAL_TIME_ZONE 10204
  163. %token KW_FORMAT 10205
  164. /* timers */
  165. %token KW_TIME_REOPEN 10210
  166. %token KW_TIME_REAP 10211
  167. %token KW_TIME_SLEEP 10212
  168. /* destination options */
  169. %token KW_TMPL_ESCAPE 10220
  170. /* driver specific options */
  171. %token KW_OPTIONAL 10230
  172. /* file related options */
  173. %token KW_CREATE_DIRS 10240
  174. %token KW_OWNER 10250
  175. %token KW_GROUP 10251
  176. %token KW_PERM 10252
  177. %token KW_DIR_OWNER 10260
  178. %token KW_DIR_GROUP 10261
  179. %token KW_DIR_PERM 10262
  180. %token KW_TEMPLATE 10270
  181. %token KW_TEMPLATE_ESCAPE 10271
  182. %token KW_DEFAULT_FACILITY 10300
  183. %token KW_DEFAULT_LEVEL 10301
  184. %token KW_PORT 10323
  185. /* misc options */
  186. %token KW_USE_TIME_RECVD 10340
  187. /* filter items*/
  188. %token KW_FACILITY 10350
  189. %token KW_LEVEL 10351
  190. %token KW_HOST 10352
  191. %token KW_MATCH 10353
  192. %token KW_MESSAGE 10354
  193. %token KW_NETMASK 10355
  194. %token KW_TAGS 10356
  195. /* parser items */
  196. %token KW_VALUE 10361
  197. /* rewrite items */
  198. %token KW_REWRITE 10370
  199. %token KW_SET 10371
  200. %token KW_SUBST 10372
  201. /* yes/no switches */
  202. %token KW_YES 10380
  203. %token KW_NO 10381
  204. %token KW_IFDEF 10410
  205. %token KW_ENDIF 10411
  206. %token LL_DOTDOT 10420
  207. %token <cptr> LL_IDENTIFIER 10421
  208. %token <num> LL_NUMBER 10422
  209. %token <fnum> LL_FLOAT 10423
  210. %token <cptr> LL_STRING 10424
  211. %token <token> LL_TOKEN 10425
  212. %token <cptr> LL_BLOCK 10426
  213. %token LL_PRAGMA 10427
  214. %token LL_EOL 10428
  215. %token LL_ERROR 10429
  216. %type <num> yesno
  217. %type <num> dnsmode
  218. %type <num> regexp_option_flags
  219. %type <num> dest_writer_options_flags
  220. %type <cptr> string
  221. %type <cptr> string_or_number
  222. %type <ptr> string_list
  223. %type <ptr> string_list_build
  224. %type <num> facility_string
  225. %type <num> level_string
  226. %%
  227. start
  228. : parser_expr_list { *result = $1; if (yychar != YYEMPTY) { cfg_lexer_unput_token(lexer, &yylval); } YYACCEPT; }
  229. ;
  230. parser_expr_list
  231. : parser_expr_list_build { $$ = g_list_reverse($1); }
  232. ;
  233. parser_expr_list_build
  234. : parser_expr ';' parser_expr_list_build { $$ = g_list_append($3, $1); }
  235. | ';' parser_expr_list_build { $$ = $2; }
  236. | { $$ = NULL; }
  237. ;
  238. parser_expr
  239. : LL_IDENTIFIER
  240. {
  241. Plugin *p;
  242. gint context = LL_CONTEXT_PARSER;
  243. p = plugin_find(configuration, context, $1);
  244. CHECK_ERROR(p, @1, "%s plugin %s not found", cfg_lexer_lookup_context_name_by_type(context), $1);
  245. last_parser = (LogParser *) plugin_parse_config(p, configuration, &@1);
  246. free($1);
  247. if (!last_parser)
  248. {
  249. YYERROR;
  250. }
  251. $$ = last_parser;
  252. }
  253. ;
  254. string
  255. : LL_IDENTIFIER
  256. | LL_STRING
  257. ;
  258. yesno
  259. : KW_YES { $$ = 1; }
  260. | KW_NO { $$ = 0; }
  261. | LL_NUMBER { $$ = $1; }
  262. ;
  263. dnsmode
  264. : yesno { $$ = $1; }
  265. | KW_PERSIST_ONLY { $$ = 2; }
  266. ;
  267. string_or_number
  268. : string { $$ = $1; }
  269. | LL_NUMBER { $$ = strdup(lexer->token_text->str); }
  270. | LL_FLOAT { $$ = strdup(lexer->token_text->str); }
  271. ;
  272. string_list
  273. : string_list_build { $$ = g_list_reverse($1); }
  274. ;
  275. string_list_build
  276. : string string_list_build { $$ = g_list_append($2, g_strdup($1)); free($1); }
  277. | { $$ = NULL; }
  278. ;
  279. level_string
  280. : string
  281. {
  282. /* return the numeric value of the "level" */
  283. int n = syslog_name_lookup_level_by_name($1);
  284. CHECK_ERROR((n != -1), @1, "Unknown priority level\"%s\"", $1);
  285. free($1);
  286. $$ = n;
  287. }
  288. ;
  289. facility_string
  290. : string
  291. {
  292. /* return the numeric value of facility */
  293. int n = syslog_name_lookup_facility_by_name($1);
  294. CHECK_ERROR((n != -1), @1, "Unknown facility \"%s\"", $1);
  295. free($1);
  296. $$ = n;
  297. }
  298. | KW_SYSLOG { $$ = LOG_SYSLOG; }
  299. ;
  300. regexp_option_flags
  301. : string regexp_option_flags { $$ = log_matcher_lookup_flag($1) | $2; free($1); }
  302. | { $$ = 0; }
  303. ;
  304. source_reader_options
  305. : source_reader_option source_reader_options
  306. |
  307. ;
  308. source_reader_option
  309. : KW_LOG_IW_SIZE '(' LL_NUMBER ')' { last_reader_options->super.init_window_size = $3; }
  310. | KW_CHAIN_HOSTNAMES '(' yesno ')' { last_reader_options->super.chain_hostnames = $3; }
  311. | KW_NORMALIZE_HOSTNAMES '(' yesno ')' { last_reader_options->super.normalize_hostnames = $3; }
  312. | KW_KEEP_HOSTNAME '(' yesno ')' { last_reader_options->super.keep_hostname = $3; }
  313. | KW_USE_FQDN '(' yesno ')' { last_reader_options->super.use_fqdn = $3; }
  314. | KW_USE_DNS '(' dnsmode ')' { last_reader_options->super.use_dns = $3; }
  315. | KW_DNS_CACHE '(' yesno ')' { last_reader_options->super.use_dns_cache = $3; }
  316. | KW_PROGRAM_OVERRIDE '(' string ')' { last_reader_options->super.program_override = g_strdup($3); free($3); }
  317. | KW_HOST_OVERRIDE '(' string ')' { last_reader_options->super.host_override = g_strdup($3); free($3); }
  318. | KW_LOG_PREFIX '(' string ')' { gchar *p = strrchr($3, ':'); if (p) *p = 0; last_reader_options->super.program_override = g_strdup($3); free($3); }
  319. | KW_TIME_ZONE '(' string ')' { last_reader_options->parse_options.recv_time_zone = g_strdup($3); free($3); }
  320. | KW_CHECK_HOSTNAME '(' yesno ')' { last_reader_options->check_hostname = $3; }
  321. | KW_FLAGS '(' source_reader_option_flags ')'
  322. | KW_LOG_MSG_SIZE '(' LL_NUMBER ')' { last_reader_options->msg_size = $3; }
  323. | KW_LOG_FETCH_LIMIT '(' LL_NUMBER ')' { last_reader_options->fetch_limit = $3; }
  324. | KW_PAD_SIZE '(' LL_NUMBER ')' { last_reader_options->padding = $3; }
  325. | KW_KEEP_TIMESTAMP '(' yesno ')' { last_reader_options->super.keep_timestamp = $3; }
  326. | KW_ENCODING '(' string ')' { last_reader_options->text_encoding = g_strdup($3); free($3); }
  327. | KW_TAGS '(' string_list ')' { log_reader_options_set_tags(last_reader_options, $3); }
  328. | KW_FORMAT '(' string ')' { last_reader_options->parse_options.format = g_strdup($3); free($3); }
  329. | KW_DEFAULT_LEVEL '(' level_string ')'
  330. {
  331. if (last_reader_options->parse_options.default_pri == 0xFFFF)
  332. last_reader_options->parse_options.default_pri = LOG_USER;
  333. last_reader_options->parse_options.default_pri = (last_reader_options->parse_options.default_pri & ~7) | $3;
  334. }
  335. | KW_DEFAULT_FACILITY '(' facility_string ')'
  336. {
  337. if (last_reader_options->parse_options.default_pri == 0xFFFF)
  338. last_reader_options->parse_options.default_pri = LOG_NOTICE;
  339. last_reader_options->parse_options.default_pri = (last_reader_options->parse_options.default_pri & 7) | $3;
  340. }
  341. ;
  342. source_reader_option_flags
  343. : string source_reader_option_flags { CHECK_ERROR(log_reader_options_process_flag(last_reader_options, $1), @1, "Unknown flag %s", $1); free($1); }
  344. |
  345. ;
  346. dest_writer_options
  347. : dest_writer_option dest_writer_options
  348. |
  349. ;
  350. dest_writer_option
  351. : KW_FLAGS '(' dest_writer_options_flags ')' { last_writer_options->options = $3; }
  352. | KW_LOG_FIFO_SIZE '(' LL_NUMBER ')' { last_writer_options->mem_fifo_size = $3; }
  353. | KW_FLUSH_LINES '(' LL_NUMBER ')' { last_writer_options->flush_lines = $3; }
  354. | KW_FLUSH_TIMEOUT '(' LL_NUMBER ')' { last_writer_options->flush_timeout = $3; }
  355. | KW_SUPPRESS '(' LL_NUMBER ')' { last_writer_options->suppress = $3; }
  356. | KW_TEMPLATE '(' string ')' {
  357. GError *error = NULL;
  358. last_writer_options->template = cfg_check_inline_template(configuration, $3);
  359. CHECK_ERROR(log_template_compile(last_writer_options->template, &error), @3, "Error compiling template (%s)", error->message);
  360. free($3);
  361. }
  362. | KW_TEMPLATE_ESCAPE '(' yesno ')' { log_writer_options_set_template_escape(last_writer_options, $3); }
  363. | KW_TIME_ZONE '(' string ')' { last_writer_options->template_options.time_zone[LTZ_SEND] = g_strdup($3); free($3); }
  364. | KW_TS_FORMAT '(' string ')' { last_writer_options->template_options.ts_format = cfg_ts_format_value($3); free($3); }
  365. | KW_FRAC_DIGITS '(' LL_NUMBER ')' { last_writer_options->template_options.frac_digits = $3; }
  366. | KW_THROTTLE '(' LL_NUMBER ')' { last_writer_options->throttle = $3; }
  367. ;
  368. dest_writer_options_flags
  369. : string dest_writer_options_flags { $$ = log_writer_options_lookup_flag($1) | $2; free($1); }
  370. | { $$ = 0; }
  371. ;
  372. %%