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.y 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /* $Id$ */
  2. %{
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <unistd.h>
  6. #include <ctype.h>
  7. #include <errno.h>
  8. #include <stdarg.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <syslog.h>
  13. #include <netinet/in.h>
  14. #include <arpa/inet.h>
  15. #include <glib.h>
  16. #include "cfg_file.h"
  17. #define YYDEBUG 1
  18. extern struct config_file *cfg;
  19. extern int yylineno;
  20. extern char *yytext;
  21. LIST_HEAD (moduleoptq, module_opt) *cur_module_opt = NULL;
  22. struct metric *cur_metric = NULL;
  23. %}
  24. %union
  25. {
  26. char *string;
  27. size_t limit;
  28. char flag;
  29. unsigned int seconds;
  30. unsigned int number;
  31. double fract;
  32. }
  33. %token ERROR STRING QUOTEDSTRING FLAG
  34. %token FILENAME REGEXP QUOTE SEMICOLON OBRACE EBRACE COMMA EQSIGN
  35. %token BINDSOCK SOCKCRED DOMAIN IPADDR IPNETWORK HOSTPORT NUMBER CHECK_TIMEOUT
  36. %token MAXSIZE SIZELIMIT SECONDS BEANSTALK MYSQL USER PASSWORD DATABASE
  37. %token TEMPDIR PIDFILE SERVERS ERROR_TIME DEAD_TIME MAXERRORS CONNECT_TIMEOUT PROTOCOL RECONNECT_TIMEOUT
  38. %token READ_SERVERS WRITE_SERVER DIRECTORY_SERVERS MAILBOX_QUERY USERS_QUERY LASTLOGIN_QUERY
  39. %token MEMCACHED WORKERS REQUIRE MODULE
  40. %token MODULE_OPT PARAM VARIABLE
  41. %token HEADER_FILTERS MIME_FILTERS MESSAGE_FILTERS URL_FILTERS FACTORS METRIC NAME
  42. %token REQUIRED_SCORE FUNCTION FRACT
  43. %type <string> STRING
  44. %type <string> VARIABLE
  45. %type <string> QUOTEDSTRING MODULE_OPT PARAM
  46. %type <string> FILENAME
  47. %type <string> SOCKCRED
  48. %type <string> IPADDR IPNETWORK
  49. %type <string> HOSTPORT
  50. %type <string> DOMAIN
  51. %type <limit> SIZELIMIT
  52. %type <flag> FLAG
  53. %type <seconds> SECONDS
  54. %type <number> NUMBER
  55. %type <string> memcached_hosts bind_cred
  56. %type <fract> FRACT
  57. %%
  58. file : /* empty */
  59. | file command SEMICOLON { }
  60. ;
  61. command :
  62. bindsock
  63. | tempdir
  64. | pidfile
  65. | memcached
  66. | workers
  67. | require
  68. | header_filters
  69. | mime_filters
  70. | message_filters
  71. | url_filters
  72. | module_opt
  73. | variable
  74. | factors
  75. | metric
  76. ;
  77. tempdir :
  78. TEMPDIR EQSIGN QUOTEDSTRING {
  79. struct stat st;
  80. if (stat ($3, &st) == -1) {
  81. yyerror ("yyparse: cannot stat directory \"%s\": %s", $3, strerror (errno));
  82. YYERROR;
  83. }
  84. if (!S_ISDIR (st.st_mode)) {
  85. yyerror ("yyparse: \"%s\" is not a directory", $3);
  86. YYERROR;
  87. }
  88. cfg->temp_dir = memory_pool_strdup (cfg->cfg_pool, $3);
  89. free ($3);
  90. }
  91. ;
  92. pidfile :
  93. PIDFILE EQSIGN QUOTEDSTRING {
  94. cfg->pid_file = $3;
  95. }
  96. ;
  97. bindsock:
  98. BINDSOCK EQSIGN bind_cred {
  99. if (!parse_bind_line (cfg, $3)) {
  100. yyerror ("yyparse: parse_bind_line");
  101. YYERROR;
  102. }
  103. free ($3);
  104. }
  105. ;
  106. bind_cred:
  107. STRING {
  108. $$ = $1;
  109. }
  110. | IPADDR{
  111. $$ = $1;
  112. }
  113. | DOMAIN {
  114. $$ = $1;
  115. }
  116. | HOSTPORT {
  117. $$ = $1;
  118. }
  119. | QUOTEDSTRING {
  120. $$ = $1;
  121. }
  122. ;
  123. header_filters:
  124. HEADER_FILTERS EQSIGN QUOTEDSTRING {
  125. cfg->header_filters_str = memory_pool_strdup (cfg->cfg_pool, $3);
  126. free ($3);
  127. }
  128. ;
  129. mime_filters:
  130. MIME_FILTERS EQSIGN QUOTEDSTRING {
  131. cfg->mime_filters_str = memory_pool_strdup (cfg->cfg_pool, $3);
  132. free ($3);
  133. }
  134. ;
  135. message_filters:
  136. MESSAGE_FILTERS EQSIGN QUOTEDSTRING {
  137. cfg->message_filters_str = memory_pool_strdup (cfg->cfg_pool, $3);
  138. free ($3);
  139. }
  140. ;
  141. url_filters:
  142. URL_FILTERS EQSIGN QUOTEDSTRING {
  143. cfg->url_filters_str = memory_pool_strdup (cfg->cfg_pool, $3);
  144. free ($3);
  145. }
  146. ;
  147. memcached:
  148. MEMCACHED OBRACE memcachedbody EBRACE
  149. ;
  150. memcachedbody:
  151. memcachedcmd SEMICOLON
  152. | memcachedbody memcachedcmd SEMICOLON
  153. ;
  154. memcachedcmd:
  155. memcached_servers
  156. | memcached_connect_timeout
  157. | memcached_error_time
  158. | memcached_dead_time
  159. | memcached_maxerrors
  160. | memcached_protocol
  161. ;
  162. memcached_servers:
  163. SERVERS EQSIGN memcached_server
  164. ;
  165. memcached_server:
  166. memcached_params
  167. | memcached_server COMMA memcached_params
  168. ;
  169. memcached_params:
  170. memcached_hosts {
  171. if (!add_memcached_server (cfg, $1)) {
  172. yyerror ("yyparse: add_memcached_server");
  173. YYERROR;
  174. }
  175. free ($1);
  176. }
  177. ;
  178. memcached_hosts:
  179. STRING
  180. | IPADDR
  181. | DOMAIN
  182. | HOSTPORT
  183. ;
  184. memcached_error_time:
  185. ERROR_TIME EQSIGN NUMBER {
  186. cfg->memcached_error_time = $3;
  187. }
  188. ;
  189. memcached_dead_time:
  190. DEAD_TIME EQSIGN NUMBER {
  191. cfg->memcached_dead_time = $3;
  192. }
  193. ;
  194. memcached_maxerrors:
  195. MAXERRORS EQSIGN NUMBER {
  196. cfg->memcached_maxerrors = $3;
  197. }
  198. ;
  199. memcached_connect_timeout:
  200. CONNECT_TIMEOUT EQSIGN SECONDS {
  201. cfg->memcached_connect_timeout = $3;
  202. }
  203. ;
  204. memcached_protocol:
  205. PROTOCOL EQSIGN STRING {
  206. if (strncasecmp ($3, "udp", sizeof ("udp") - 1) == 0) {
  207. cfg->memcached_protocol = UDP_TEXT;
  208. }
  209. else if (strncasecmp ($3, "tcp", sizeof ("tcp") - 1) == 0) {
  210. cfg->memcached_protocol = TCP_TEXT;
  211. }
  212. else {
  213. yyerror ("yyparse: cannot recognize protocol: %s", $3);
  214. YYERROR;
  215. }
  216. }
  217. ;
  218. workers:
  219. WORKERS EQSIGN NUMBER {
  220. cfg->workers_number = $3;
  221. }
  222. ;
  223. metric:
  224. METRIC OBRACE metricbody EBRACE {
  225. if (cur_metric == NULL || cur_metric->name == NULL) {
  226. yyerror ("yyparse: not enough arguments in metric definition");
  227. YYERROR;
  228. }
  229. g_hash_table_insert (cfg->metrics, cur_metric->name, cur_metric);
  230. cur_metric = NULL;
  231. }
  232. ;
  233. metricbody:
  234. | metriccmd SEMICOLON
  235. | metricbody metriccmd SEMICOLON
  236. ;
  237. metriccmd:
  238. | metricname
  239. | metricfunction
  240. | metricscore
  241. ;
  242. metricname:
  243. NAME EQSIGN QUOTEDSTRING {
  244. if (cur_metric == NULL) {
  245. cur_metric = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct metric));
  246. }
  247. cur_metric->name = memory_pool_strdup (cfg->cfg_pool, $3);
  248. }
  249. ;
  250. metricfunction:
  251. FUNCTION EQSIGN QUOTEDSTRING {
  252. if (cur_metric == NULL) {
  253. cur_metric = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct metric));
  254. }
  255. cur_metric->func_name = memory_pool_strdup (cfg->cfg_pool, $3);
  256. }
  257. ;
  258. metricscore:
  259. REQUIRED_SCORE EQSIGN NUMBER {
  260. if (cur_metric == NULL) {
  261. cur_metric = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct metric));
  262. }
  263. cur_metric->required_score = $3;
  264. }
  265. | REQUIRED_SCORE EQSIGN FRACT {
  266. if (cur_metric == NULL) {
  267. cur_metric = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct metric));
  268. }
  269. cur_metric->required_score = $3;
  270. }
  271. ;
  272. factors:
  273. FACTORS OBRACE factorsbody EBRACE
  274. ;
  275. factorsbody:
  276. factorparam SEMICOLON
  277. | factorsbody factorparam SEMICOLON
  278. ;
  279. factorparam:
  280. QUOTEDSTRING EQSIGN FRACT {
  281. double *tmp = memory_pool_alloc (cfg->cfg_pool, sizeof (double));
  282. *tmp = $3;
  283. g_hash_table_insert (cfg->factors, $1, tmp);
  284. }
  285. | QUOTEDSTRING EQSIGN NUMBER {
  286. double *tmp = memory_pool_alloc (cfg->cfg_pool, sizeof (double));
  287. *tmp = $3;
  288. g_hash_table_insert (cfg->factors, $1, tmp);
  289. };
  290. require:
  291. REQUIRE OBRACE requirebody EBRACE
  292. ;
  293. requirebody:
  294. requirecmd SEMICOLON
  295. | requirebody requirecmd SEMICOLON
  296. ;
  297. requirecmd:
  298. MODULE EQSIGN QUOTEDSTRING {
  299. struct stat st;
  300. struct perl_module *cur;
  301. if (stat ($3, &st) == -1) {
  302. yyerror ("yyparse: cannot stat file %s, %m", $3);
  303. YYERROR;
  304. }
  305. cur = memory_pool_alloc (cfg->cfg_pool, sizeof (struct perl_module));
  306. if (cur == NULL) {
  307. yyerror ("yyparse: g_malloc: %s", strerror(errno));
  308. YYERROR;
  309. }
  310. cur->path = $3;
  311. LIST_INSERT_HEAD (&cfg->perl_modules, cur, next);
  312. }
  313. ;
  314. module_opt:
  315. MODULE_OPT OBRACE moduleoptbody EBRACE {
  316. g_hash_table_insert (cfg->modules_opts, $1, cur_module_opt);
  317. cur_module_opt = NULL;
  318. }
  319. ;
  320. moduleoptbody:
  321. optcmd SEMICOLON
  322. | moduleoptbody optcmd SEMICOLON
  323. ;
  324. optcmd:
  325. PARAM EQSIGN QUOTEDSTRING {
  326. struct module_opt *mopt;
  327. if (cur_module_opt == NULL) {
  328. cur_module_opt = g_malloc (sizeof (cur_module_opt));
  329. LIST_INIT (cur_module_opt);
  330. }
  331. mopt = memory_pool_alloc (cfg->cfg_pool, sizeof (struct module_opt));
  332. mopt->param = $1;
  333. mopt->value = $3;
  334. LIST_INSERT_HEAD (cur_module_opt, mopt, next);
  335. }
  336. ;
  337. variable:
  338. VARIABLE EQSIGN QUOTEDSTRING {
  339. g_hash_table_insert (cfg->variables, $1, $3);
  340. }
  341. ;
  342. %%
  343. /*
  344. * vi:ts=4
  345. */