Mercurial > wflogs-daemon
annotate src/wflogs-config.h @ 11:1b7813f588ba stable-1-0-1
fix type in config file
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 17 May 2013 13:29:14 -0700 |
parents | 306059d0f677 |
children |
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 | |
4
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
34 tm open_tm; |
0 | 35 TOKEN *tokp; |
36 // our data | |
37 int period; // in seconds | |
38 int versions; // number to keep | |
39 // all strings owned by the string table | |
4
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
40 const char * trigger; // trigger token or NULL |
0 | 41 const char * output; // output file name pattern |
42 const char * tempin; // temp wflogs input file name | |
43 const char * wflogs; // wflogs command line | |
44 const char * fn; // name of the syslog file | |
45 const char * pattern; // regex to filter lines | |
46 regex_t re; // internal regex to filter lines | |
47 | |
2
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
48 CONTEXT(const char *nam); |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
49 ~CONTEXT(); |
0 | 50 void set_token(TOKEN &tok) { tokp = &tok; }; |
51 void set_period(int p) { period = p; }; | |
52 void set_versions(int v) { versions = v; }; | |
53 void set_output(const char * o) { output = o; }; | |
54 void set_tempin(const char * t) { tempin = t; openo(true); }; | |
55 void set_wflogs(const char * w) { wflogs = w; }; | |
56 void set_file(const char * f) { fn = f; open(true); }; | |
57 void set_pattern(const char * p) { pattern = p; }; | |
58 bool failedo() { return (fdo == -1); }; | |
59 bool failed() { return (fd == -1); }; | |
60 void dump(); | |
2
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
61 void openo(bool msg); |
0 | 62 void open(bool msg); |
8
306059d0f677
fix missing return statement
Carl Byington <carl@five-ten-sg.com>
parents:
4
diff
changeset
|
63 void write(char *p); |
0 | 64 bool read(); |
2
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
65 void closeo(); |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
66 void close(); |
0 | 67 void process(char *p); |
4
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
68 bool check_wflog_time(); |
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
69 void check_wflog(); |
2
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
70 void free_all(); |
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 typedef CONTEXT * CONTEXTP; |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
73 typedef list<CONTEXTP> context_list; |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
74 |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
75 |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
76 class CONFIG { |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
77 public: |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
78 // 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
|
79 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
|
80 // 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
|
81 int generation; |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
82 time_t load_time; |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
83 string_set config_files; |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
84 context_list contexts; |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
85 |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
86 CONFIG(); |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
87 ~CONFIG(); |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
88 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
|
89 void dump(); |
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
90 bool read(); |
0 | 91 void sleep(int duration, time_t &previous); |
92 void free_all(); | |
93 }; | |
94 | |
95 void discard(string_set &s); | |
96 const char* register_string(string_set &s, const char *name); | |
97 const char* register_string(const char *name); | |
98 void clear_strings(); | |
99 bool load_conf(CONFIG &dc, const char *fn); | |
100 void token_init(); | |
101 | |
102 | |
2
400b1de6e1c6
allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
103 extern const char *token_context; |
4
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
104 extern const char *token_daily; |
0 | 105 extern const char *token_file; |
4
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
106 extern const char *token_hourly; |
0 | 107 extern const char *token_include; |
108 extern const char *token_lbrace; | |
109 extern const char *token_output; | |
110 extern const char *token_pattern; | |
111 extern const char *token_period; | |
112 extern const char *token_rbrace; | |
113 extern const char *token_semi; | |
114 extern const char *token_tempin; | |
4
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
115 extern const char *token_trigger; |
0 | 116 extern const char *token_versions; |
4
37eace15ef87
allow hourly/daily/weekly triggers for output generation, append to temp wflogs input files so daemon restart won't drop as much data
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
117 extern const char *token_weekly; |
0 | 118 extern const char *token_wflogs; |