comparison src/wflogs-config.h @ 2:400b1de6e1c6

allow multiple config contexts
author Carl Byington <carl@five-ten-sg.com>
date Fri, 17 May 2013 10:32:12 -0700
parents 0aa1171aebd2
children 37eace15ef87
comparison
equal deleted inserted replaced
1:964c1127ae65 2:400b1de6e1c6
1 /* 1 /*
2 2
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under 3 Copyright (c) 2013 Carl Byington - 510 Software Group, released under
4 the GPL version 3 or any later version at your choice available at 4 the GPL version 3 or any later version at your choice available at
5 http://www.gnu.org/licenses/gpl-3.0.txt 5 http://www.gnu.org/licenses/gpl-3.0.txt
6 6
7 */ 7 */
8 8
18 18
19 19
20 const int buflen = 1024; 20 const int buflen = 1024;
21 21
22 22
23 class CONFIG { 23 class CONTEXT {
24 public: 24 public:
25 // the only mutable stuff once it has been loaded from the config file 25 const char * name; // name of this context
26 int reference_count; // protected by the global config_mutex
27 // input side 26 // input side
28 int fd; // input fn syslog file 27 int fd; // input fn syslog file
29 struct stat openfdstat; 28 struct stat openfdstat;
30 int len; // bytes in the buffer 29 int len; // bytes in the buffer
31 char buf[buflen]; 30 char buf[buflen];
32 // output side 31 // output side
33 int fdo; // output tempin wflogs file 32 int fdo; // output tempin wflogs file
34 time_t open_time; // time when fdo opened 33 time_t open_time; // time when fdo opened
35 // all the rest is constant after loading from the config file
36 int generation;
37 time_t load_time;
38 string_set config_files;
39 TOKEN *tokp; 34 TOKEN *tokp;
40 // our data 35 // our data
41 int period; // in seconds 36 int period; // in seconds
42 int versions; // number to keep 37 int versions; // number to keep
43 // all strings owned by the string table 38 // all strings owned by the string table
46 const char * wflogs; // wflogs command line 41 const char * wflogs; // wflogs command line
47 const char * fn; // name of the syslog file 42 const char * fn; // name of the syslog file
48 const char * pattern; // regex to filter lines 43 const char * pattern; // regex to filter lines
49 regex_t re; // internal regex to filter lines 44 regex_t re; // internal regex to filter lines
50 45
51 CONFIG(); 46 CONTEXT(const char *nam);
52 ~CONFIG(); 47 ~CONTEXT();
53 void set_token(TOKEN &tok) { tokp = &tok; }; 48 void set_token(TOKEN &tok) { tokp = &tok; };
54 void set_period(int p) { period = p; }; 49 void set_period(int p) { period = p; };
55 void set_versions(int v) { versions = v; }; 50 void set_versions(int v) { versions = v; };
56 void set_output(const char * o) { output = o; }; 51 void set_output(const char * o) { output = o; };
57 void set_tempin(const char * t) { tempin = t; openo(true); }; 52 void set_tempin(const char * t) { tempin = t; openo(true); };
59 void set_file(const char * f) { fn = f; open(true); }; 54 void set_file(const char * f) { fn = f; open(true); };
60 void set_pattern(const char * p) { pattern = p; }; 55 void set_pattern(const char * p) { pattern = p; };
61 bool failedo() { return (fdo == -1); }; 56 bool failedo() { return (fdo == -1); };
62 bool failed() { return (fd == -1); }; 57 bool failed() { return (fd == -1); };
63 void dump(); 58 void dump();
59 void openo(bool msg);
64 void open(bool msg); 60 void open(bool msg);
65 void openo(bool msg); 61 bool write(char *p);
66 bool read(); 62 bool read();
67 bool write(char *p); 63 void closeo();
64 void close();
68 void process(char *p); 65 void process(char *p);
69 void close(); 66 void check_wflog(); // time to call it?
70 void closeo(); 67 void free_all();
68 };
69 typedef CONTEXT * CONTEXTP;
70 typedef list<CONTEXTP> context_list;
71
72
73 class CONFIG {
74 public:
75 // the only mutable stuff once it has been loaded from the config file
76 int reference_count; // protected by the global config_mutex
77 // all the rest is constant after loading from the config file
78 int generation;
79 time_t load_time;
80 string_set config_files;
81 context_list contexts;
82
83 CONFIG();
84 ~CONFIG();
85 void add_context(CONTEXTP con) {contexts.push_back(con);} ;
86 void dump();
87 bool read();
71 void sleep(int duration, time_t &previous); 88 void sleep(int duration, time_t &previous);
72 void check_wflog(); // time to call it?
73 void free_all(); 89 void free_all();
74 }; 90 };
75 91
76 void discard(string_set &s); 92 void discard(string_set &s);
77 const char* register_string(string_set &s, const char *name); 93 const char* register_string(string_set &s, const char *name);
78 const char* register_string(const char *name); 94 const char* register_string(const char *name);
79 void clear_strings(); 95 void clear_strings();
80 int ip_address(const char *have);
81 bool load_conf(CONFIG &dc, const char *fn); 96 bool load_conf(CONFIG &dc, const char *fn);
82 void token_init(); 97 void token_init();
83 98
84 99
100 extern const char *token_context;
85 extern const char *token_file; 101 extern const char *token_file;
86 extern const char *token_include; 102 extern const char *token_include;
87 extern const char *token_lbrace; 103 extern const char *token_lbrace;
88 extern const char *token_output; 104 extern const char *token_output;
89 extern const char *token_pattern; 105 extern const char *token_pattern;