You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cfg_file.l 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. %x incl
  2. %x module
  3. %x lua
  4. %x worker
  5. %{
  6. #define NO_GMIME
  7. #include "config.h"
  8. #include "cfg_file.h"
  9. #include "cfg_yacc.h"
  10. #ifdef WITH_LUA
  11. extern void add_luabuf (const char *line);
  12. #else
  13. #define add_luabuf(x) yyerror ("lua support diabled")
  14. #endif
  15. #define ECHO do {} while(0)
  16. #define MAX_INCLUDE_DEPTH 10
  17. YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
  18. int line_stack[MAX_INCLUDE_DEPTH];
  19. int include_stack_ptr = 0;
  20. extern struct config_file *cfg;
  21. %}
  22. %option noyywrap
  23. %option yylineno
  24. %%
  25. [ \t]*#.* /* ignore comments */;
  26. .include BEGIN(incl);
  27. .module BEGIN(module);
  28. .lua BEGIN(lua);
  29. worker BEGIN(worker); return WORKER;
  30. composites return COMPOSITES;
  31. tempdir return TEMPDIR;
  32. pidfile return PIDFILE;
  33. view return VIEW;
  34. ip return IP;
  35. from return FROM;
  36. symbols return SYMBOLS;
  37. error_time return ERROR_TIME;
  38. dead_time return DEAD_TIME;
  39. maxerrors return MAXERRORS;
  40. reconnect_timeout return RECONNECT_TIMEOUT;
  41. connect_timeout return CONNECT_TIMEOUT;
  42. protocol return PROTOCOL;
  43. memcached return MEMCACHED;
  44. servers return SERVERS;
  45. modules return MODULES;
  46. module_path return MODULE_PATH;
  47. filters return FILTERS;
  48. factors return FACTORS;
  49. metric return METRIC;
  50. name return NAME;
  51. required_score return REQUIRED_SCORE;
  52. function return FUNCTION;
  53. cache_file return CACHE_FILE;
  54. control return CONTROL;
  55. password return PASSWORD;
  56. lmtp return LMTP;
  57. raw_mode return RAW_MODE;
  58. enabled return ENABLED;
  59. delivery return DELIVERY;
  60. agent return AGENT;
  61. statfile return STATFILE;
  62. alias return ALIAS;
  63. pattern return PATTERN;
  64. weight return WEIGHT;
  65. size return SIZE;
  66. tokenizer return TOKENIZER;
  67. classifier return CLASSIFIER;
  68. section return SECTION;
  69. autolearn return AUTOLEARN;
  70. min_mark return MIN_MARK;
  71. max_mark return MAX_MARK;
  72. logging return LOGGING;
  73. log_type return LOG_TYPE;
  74. console return LOG_TYPE_CONSOLE;
  75. syslog return LOG_TYPE_SYSLOG;
  76. file return LOG_TYPE_FILE;
  77. log_level return LOG_LEVEL;
  78. DEBUG return LOG_LEVEL_DEBUG;
  79. INFO return LOG_LEVEL_INFO;
  80. WARNING return LOG_LEVEL_WARNING;
  81. ERROR return LOG_LEVEL_ERROR;
  82. log_facility return LOG_FACILITY;
  83. log_file return LOG_FILENAME;
  84. profile_file return PROFILE_FILE;
  85. statfile_pool_size return STATFILE_POOL_SIZE;
  86. \{ return OBRACE;
  87. \} return EBRACE;
  88. ; return SEMICOLON;
  89. , return COMMA;
  90. = return EQSIGN;
  91. yes|YES|no|NO|[yY]|[nN] yylval.flag=parse_flag(yytext); return FLAG;
  92. \n /* ignore EOL */;
  93. [ \t]+ /* ignore whitespace */;
  94. \".+[^\\]\" yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;
  95. \" return QUOTE;
  96. \$[a-zA-Z_][a-zA-Z0-9_]+ yylval.string=strdup(yytext + 1); return VARIABLE;
  97. [0-9]+ yylval.number=strtol(yytext, NULL, 10); return NUMBER;
  98. -?[0-9]+\.?[0-9]* yylval.fract=strtod(yytext, NULL); return FRACT;
  99. [0-9]+[kKmMgG]? yylval.limit=parse_limit(yytext); return SIZELIMIT;
  100. [0-9]+[sS]|[0-9]+[mM][sS] yylval.seconds=parse_seconds(yytext); return SECONDS;
  101. [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string=strdup(yytext); return IPADDR;
  102. [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2} yylval.string=strdup(yytext); return IPNETWORK;
  103. [*a-zA-Z0-9.-]+:[0-9]{1,5} yylval.string=strdup(yytext); return HOSTPORT;
  104. [a-zA-Z<][a-zA-Z@+>_-]* yylval.string=strdup(yytext); return STRING;
  105. \/[^/\n]+\/ yylval.string=strdup(yytext); return REGEXP;
  106. [a-zA-Z0-9].[a-zA-Z0-9\/.-]+ yylval.string=strdup(yytext); return DOMAINNAME;
  107. <incl>[ \t]* /* eat the whitespace */
  108. <incl>[^ \t\n]+ { /* got the include file name */
  109. /* got the include file name */
  110. if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
  111. yyerror ("yylex: includes nested too deeply" );
  112. return -1;
  113. }
  114. line_stack[include_stack_ptr] = yylineno;
  115. include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
  116. yylineno = 1;
  117. yyin = fopen (yytext, "r");
  118. if (!yyin) {
  119. yyerror ("yylex: cannot open include file");
  120. return -1;
  121. }
  122. yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
  123. BEGIN(INITIAL);
  124. }
  125. <<EOF>> {
  126. if ( --include_stack_ptr < 0 ) {
  127. include_stack_ptr = 0;
  128. yylineno = 1;
  129. post_load_config (cfg);
  130. yyterminate ();
  131. }
  132. else {
  133. yy_delete_buffer (YY_CURRENT_BUFFER);
  134. yy_switch_to_buffer (include_stack[include_stack_ptr] );
  135. yylineno = line_stack[include_stack_ptr];
  136. }
  137. }
  138. <module>\n /* ignore EOL */;
  139. <module>[ \t]+ /* ignore whitespace */;
  140. <module>[ \t]*#.* /* ignore comments */;
  141. <module>\'[a-zA-Z0-9_-]+\' yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; return MODULE_OPT;
  142. <module>\{ return OBRACE;
  143. <module>\} BEGIN(INITIAL); return EBRACE;
  144. <module>\; return SEMICOLON;
  145. <module>= return EQSIGN;
  146. <module>\$[a-zA-Z_][a-zA-Z0-9_]+ yylval.string=strdup(yytext + 1); return VARIABLE;
  147. <module>[a-zA-Z0-9_%-]+ yylval.string=strdup(yytext); return PARAM;
  148. <module>\".+[^\\]\" yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;
  149. <worker>\n /* ignore EOL */;
  150. <worker>[ \t]+ /* ignore whitespace */;
  151. <worker>[ \t]*#.* /* ignore comments */;
  152. <worker>\{ return OBRACE;
  153. <worker>\} BEGIN(INITIAL); return EBRACE;
  154. <worker>\; return SEMICOLON;
  155. <worker>= return EQSIGN;
  156. <worker>type return TYPE;
  157. <worker>bind_socket return BINDSOCK;
  158. <worker>count return COUNT;
  159. <worker>[0-9]+ yylval.number=strtol(yytext, NULL, 10); return NUMBER;
  160. <worker>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string=strdup(yytext); return IPADDR;
  161. <worker>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2} yylval.string=strdup(yytext); return IPNETWORK;
  162. <worker>[*a-zA-Z0-9.-]+:[0-9]{1,5} yylval.string=strdup(yytext); return HOSTPORT;
  163. <worker>[a-zA-Z<][a-zA-Z@+>_-]* yylval.string=strdup(yytext); return STRING;
  164. <worker>\$[a-zA-Z_][a-zA-Z0-9_]+ yylval.string=strdup(yytext + 1); return VARIABLE;
  165. <worker>\".+[^\\]\" yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;
  166. <lua>\n /* ignore EOL */;
  167. <lua>[ \t]+ /* ignore whitespace */;
  168. <lua>[ \t]*#.* /* ignore comments */;
  169. <lua>^.endlua$ BEGIN(INITIAL);
  170. <lua>.* add_luabuf(yytext); return LUACODE;
  171. %%
  172. /*
  173. * vi:ts=4
  174. */