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