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.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * $Id$
  3. */
  4. #ifndef CFG_FILE_H
  5. #define CFG_FILE_H
  6. #include "config.h"
  7. #include <sys/types.h>
  8. #ifndef OWN_QUEUE_H
  9. #include <sys/queue.h>
  10. #else
  11. #include "queue.h"
  12. #endif
  13. #include <netinet/in.h>
  14. #include <sys/un.h>
  15. #include <event.h>
  16. #include <glib.h>
  17. #include "upstream.h"
  18. #include "memcached.h"
  19. #define DEFAULT_BIND_PORT 768
  20. #define MAX_MEMCACHED_SERVERS 48
  21. #define DEFAULT_MEMCACHED_PORT 11211
  22. /* Memcached timeouts */
  23. #define DEFAULT_MEMCACHED_CONNECT_TIMEOUT 1000
  24. /* Upstream timeouts */
  25. #define DEFAULT_UPSTREAM_ERROR_TIME 10
  26. #define DEFAULT_UPSTREAM_ERROR_TIME 10
  27. #define DEFAULT_UPSTREAM_DEAD_TIME 300
  28. #define DEFAULT_UPSTREAM_MAXERRORS 10
  29. /* 1 worker by default */
  30. #define DEFAULT_WORKERS_NUM 1
  31. #define yyerror(fmt, ...) \
  32. fprintf (stderr, "Config file parse error!\non line: %d\n", yylineno); \
  33. fprintf (stderr, "while reading text: %s\nreason: ", yytext); \
  34. fprintf (stderr, fmt, ##__VA_ARGS__); \
  35. fprintf (stderr, "\n")
  36. #define yywarn(fmt, ...) \
  37. fprintf (stderr, "Config file parse warning!\non line %d\n", yylineno); \
  38. fprintf (stderr, "while reading text: %s\nreason: ", yytext); \
  39. fprintf (stderr, fmt, ##__VA_ARGS__); \
  40. fprintf (stderr, "\n")
  41. enum { VAL_UNDEF=0, VAL_TRUE, VAL_FALSE };
  42. enum script_type {
  43. SCRIPT_HEADER,
  44. SCRIPT_MIME,
  45. SCRIPT_URL,
  46. SCRIPT_MESSAGE,
  47. SCRIPT_CHAIN,
  48. };
  49. struct memcached_server {
  50. struct upstream up;
  51. struct in_addr addr;
  52. uint16_t port;
  53. short alive;
  54. short int num;
  55. };
  56. struct perl_module {
  57. char *path;
  58. LIST_ENTRY (perl_module) next;
  59. };
  60. struct script_param {
  61. char *symbol;
  62. char *function;
  63. enum script_type type;
  64. LIST_ENTRY (script_param) next;
  65. };
  66. struct filter_chain {
  67. unsigned int metric;
  68. unsigned int scripts_number;
  69. LIST_HEAD (scriptq, script_param) *scripts;
  70. LIST_ENTRY (filter_chain) next;
  71. };
  72. struct module_opt {
  73. char *param;
  74. char *value;
  75. LIST_ENTRY (module_opt) next;
  76. };
  77. struct config_file {
  78. char *cfg_name;
  79. char *pid_file;
  80. char *temp_dir;
  81. char *bind_host;
  82. struct in_addr bind_addr;
  83. uint16_t bind_port;
  84. uint16_t bind_family;
  85. char no_fork;
  86. unsigned int workers_number;
  87. struct memcached_server memcached_servers[MAX_MEMCACHED_SERVERS];
  88. size_t memcached_servers_num;
  89. memc_proto_t memcached_protocol;
  90. unsigned int memcached_error_time;
  91. unsigned int memcached_dead_time;
  92. unsigned int memcached_maxerrors;
  93. unsigned int memcached_connect_timeout;
  94. LIST_HEAD (perlq, filter_chain) filters;
  95. LIST_HEAD (modulesq, perl_module) perl_modules;
  96. LIST_HEAD (cmodulesq, c_module) c_modules;
  97. GHashTable* modules_opts;
  98. GHashTable* variables;
  99. };
  100. int add_memcached_server (struct config_file *cf, char *str);
  101. int parse_bind_line (struct config_file *cf, char *str);
  102. void init_defaults (struct config_file *cfg);
  103. void free_config (struct config_file *cfg);
  104. int parse_script (char *str, struct script_param *param, enum script_type type);
  105. char* get_module_opt (struct config_file *cfg, char *module_name, char *opt_name);
  106. size_t parse_limit (const char *limit);
  107. unsigned int parse_seconds (const char *t);
  108. char parse_flag (const char *str);
  109. char* substitute_variable (struct config_file *cfg, char *str, u_char recursive);
  110. void post_load_config (struct config_file *cfg);
  111. int yylex (void);
  112. int yyparse (void);
  113. void yyrestart (FILE *);
  114. #endif /* ifdef CFG_FILE_H */
  115. /*
  116. * vi:ts=4
  117. */