annotate src/wflogs-config.h @ 0:0aa1171aebd2 stable-1-0-0

initial version
author Carl Byington <carl@five-ten-sg.com>
date Wed, 15 May 2013 13:15:59 -0700
parents
children 400b1de6e1c6
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
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
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 class CONFIG {
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 public:
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 // the only mutable stuff once it has been loaded from the config file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 int reference_count; // protected by the global config_mutex
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 // input side
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 int fd; // input fn syslog file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 struct stat openfdstat;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 int len; // bytes in the buffer
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 char buf[buflen];
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 // output side
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 int fdo; // output tempin wflogs file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 time_t open_time; // time when fdo opened
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 // all the rest is constant after loading from the config file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36 int generation;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 time_t load_time;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 string_set config_files;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 TOKEN *tokp;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 // our data
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 int period; // in seconds
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 int versions; // number to keep
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 // all strings owned by the string table
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 const char * output; // output file name pattern
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 const char * tempin; // temp wflogs input file name
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 const char * wflogs; // wflogs command line
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 const char * fn; // name of the syslog file
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 const char * pattern; // regex to filter lines
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 regex_t re; // internal regex to filter lines
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 CONFIG();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 ~CONFIG();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 void set_token(TOKEN &tok) { tokp = &tok; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 void set_period(int p) { period = p; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55 void set_versions(int v) { versions = v; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56 void set_output(const char * o) { output = o; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 void set_tempin(const char * t) { tempin = t; openo(true); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 void set_wflogs(const char * w) { wflogs = w; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 void set_file(const char * f) { fn = f; open(true); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 void set_pattern(const char * p) { pattern = p; };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 bool failedo() { return (fdo == -1); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 bool failed() { return (fd == -1); };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 void dump();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 void open(bool msg);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
65 void openo(bool msg);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 bool read();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 bool write(char *p);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 void process(char *p);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 void close();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70 void closeo();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 void sleep(int duration, time_t &previous);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 void check_wflog(); // time to call it?
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 void free_all();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 };
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 void discard(string_set &s);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 const char* register_string(string_set &s, const char *name);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 const char* register_string(const char *name);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79 void clear_strings();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 int ip_address(const char *have);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 bool load_conf(CONFIG &dc, const char *fn);
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 void token_init();
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 extern const char *token_file;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 extern const char *token_include;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 extern const char *token_lbrace;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 extern const char *token_output;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 extern const char *token_pattern;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 extern const char *token_period;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 extern const char *token_rbrace;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 extern const char *token_semi;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93 extern const char *token_tempin;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
94 extern const char *token_versions;
0aa1171aebd2 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 extern const char *token_wflogs;