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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /*
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 the GPL version 3 or any later version at your choice available at
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 http://www.gnu.org/licenses/gpl-3.0.txt
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 */
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 struct ltint
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 {
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 bool operator()(const int s1, const int s2) const
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 {
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 return (unsigned)s1 < (unsigned)s2;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 }
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 const int buflen = 1024;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22
2
400b1de6e1c6 allow multiple config contexts
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
23 class CONTEXT {
0
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 // input side
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 int fd; // input fn syslog file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 struct stat openfdstat;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 int len; // bytes in the buffer
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 char buf[buflen];
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 // output side
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 int fdo; // output tempin wflogs file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 TOKEN *tokp;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36 // our data
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 int period; // in seconds
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 int versions; // number to keep
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 const char * output; // output file name pattern
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 const char * tempin; // temp wflogs input file name
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 const char * wflogs; // wflogs command line
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 const char * fn; // name of the syslog file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 const char * pattern; // regex to filter lines
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 regex_t re; // internal regex to filter lines
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 void set_token(TOKEN &tok) { tokp = &tok; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 void set_period(int p) { period = p; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 void set_versions(int v) { versions = v; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 void set_output(const char * o) { output = o; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 void set_tempin(const char * t) { tempin = t; openo(true); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55 void set_wflogs(const char * w) { wflogs = w; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56 void set_file(const char * f) { fn = f; open(true); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 void set_pattern(const char * p) { pattern = p; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 bool failedo() { return (fdo == -1); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 bool failed() { return (fd == -1); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 void sleep(int duration, time_t &previous);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 void free_all();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93 };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
94
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 void discard(string_set &s);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 const char* register_string(string_set &s, const char *name);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 const char* register_string(const char *name);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98 void clear_strings();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 bool load_conf(CONFIG &dc, const char *fn);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 void token_init();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 extern const char *token_include;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 extern const char *token_lbrace;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 extern const char *token_output;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 extern const char *token_pattern;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111 extern const char *token_period;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
112 extern const char *token_rbrace;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 extern const char *token_semi;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 extern const char *token_wflogs;