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