comparison src/syslogconfig.h @ 48:ba0259c9e411 stable-1-0-11

Fixes to compile on Fedora 9 and for const correctness
author Carl Byington <carl@five-ten-sg.com>
date Thu, 29 May 2008 11:38:42 -0700
parents 26c29da3fbdf
children 206448c00b55
comparison
equal deleted inserted replaced
47:a4861687fbd1 48:ba0259c9e411
9 9
10 class SYSLOGCONFIG; 10 class SYSLOGCONFIG;
11 class CONFIG; 11 class CONFIG;
12 12
13 struct IPPAIR { 13 struct IPPAIR {
14 int first; 14 int first;
15 int last; 15 int last;
16 int cidr; 16 int cidr;
17 }; 17 };
18 18
19 class PATTERN { 19 class PATTERN {
20 char * pattern; // owned by the string table 20 const char * pattern; // owned by the string table
21 regex_t re; 21 regex_t re;
22 int index; // zero based substring of the regex match that contains the ip address or hostname 22 int index; // zero based substring of the regex match that contains the ip address or hostname
23 int amount; // count to add to the ip address leaky bucket 23 int amount; // count to add to the ip address leaky bucket
24 char * message; // for logging, owned by the string table 24 const char * message; // for logging, owned by the string table
25 public: 25 public:
26 ~PATTERN(); 26 ~PATTERN();
27 PATTERN(TOKEN &tok, char *pattern_, int index_, int amount_, char *msg_); 27 PATTERN(TOKEN &tok, const char *pattern_, int index_, int amount_, const char *msg_);
28 bool process(char *buf, CONFIG &con, char *file_name, int pattern_index); 28 bool process(char *buf, CONFIG &con, const char *file_name, int pattern_index);
29 void dump(int level); 29 void dump(int level);
30 }; 30 };
31 31
32 typedef SYSLOGCONFIG * SYSLOGCONFIGP; 32 typedef SYSLOGCONFIG * SYSLOGCONFIGP;
33 typedef PATTERN * PATTERNP; 33 typedef PATTERN * PATTERNP;
34 typedef list<SYSLOGCONFIGP> syslogconfig_list; 34 typedef list<SYSLOGCONFIGP> syslogconfig_list;
35 typedef list<IPPAIR> ippair_list; 35 typedef list<IPPAIR> ippair_list;
36 typedef list<PATTERNP> pattern_list; 36 typedef list<PATTERNP> pattern_list;
37 const int buflen = 1024; 37 const int buflen = 1024;
38 38
39 class SYSLOGCONFIG { 39 class SYSLOGCONFIG {
40 TOKEN * tokp; 40 TOKEN * tokp;
41 char * file_name; // name of the syslog file 41 const char * file_name; // name of the syslog file
42 pattern_list patterns; // owns the patterns 42 pattern_list patterns; // owns the patterns
43 int fd; 43 int fd;
44 struct stat openfdstat; 44 struct stat openfdstat;
45 int len; // bytes in the buffer 45 int len; // bytes in the buffer
46 char buf[buflen]; 46 char buf[buflen];
47 public: 47 public:
48 SYSLOGCONFIG(TOKEN &tok, char *file_name_); 48 SYSLOGCONFIG(TOKEN &tok, const char *file_name_);
49 ~SYSLOGCONFIG(); 49 ~SYSLOGCONFIG();
50 bool failed() { return (fd == -1); }; 50 bool failed() { return (fd == -1); };
51 void open(bool msg); 51 void open(bool msg);
52 bool read(CONFIG &con); 52 bool read(CONFIG &con);
53 void close(); 53 void close();
54 void add_pattern(PATTERNP pat); 54 void add_pattern(PATTERNP pat);
55 void process(CONFIG &con); 55 void process(CONFIG &con);
56 void dump(int level); 56 void dump(int level);
57 }; 57 };
58 58
59 class CONFIG { 59 class CONFIG {
60 public: 60 public:
61 // the only mutable stuff once it has been loaded from the config file 61 // the only mutable stuff once it has been loaded from the config file
62 int reference_count; // protected by the global config_mutex 62 int reference_count; // protected by the global config_mutex
63 // all the rest is constant after loading from the config file 63 // all the rest is constant after loading from the config file
64 int generation; 64 int generation;
65 time_t load_time; 65 time_t load_time;
66 string_set config_files; 66 string_set config_files;
67 int threshold; 67 int threshold;
68 ippair_list ignore; // owns all the ippairs 68 ippair_list ignore; // owns all the ippairs
69 char * add_command; // owned by the string table 69 const char * add_command; // owned by the string table
70 char * remove_command; // "" 70 const char * remove_command; // ""
71 syslogconfig_list syslogconfigs; // owns all the syslogconfigs 71 syslogconfig_list syslogconfigs; // owns all the syslogconfigs
72 72
73 CONFIG(); 73 CONFIG();
74 ~CONFIG(); 74 ~CONFIG();
75 void set_add(char *add) { add_command = add; }; 75 void set_add(const char *add) { add_command = add; };
76 void set_remove(char *remove) { remove_command = remove; }; 76 void set_remove(const char *remove) { remove_command = remove; };
77 void set_threshold(int threshold_) { threshold = threshold_; }; 77 void set_threshold(int threshold_) { threshold = threshold_; };
78 int get_threshold() { return threshold; }; 78 int get_threshold() { return threshold; };
79 void add_syslogconfig(SYSLOGCONFIGP con); 79 void add_syslogconfig(SYSLOGCONFIGP con);
80 void add_pair(IPPAIR pair); 80 void add_pair(IPPAIR pair);
81 void dump(); 81 void dump();
82 void read(); 82 void read();
83 void sleep(int duration, time_t &previous); 83 void sleep(int duration, time_t &previous);
84 void free_all(); 84 void free_all();
85 bool looking(int ip); 85 bool looking(int ip);
86 }; 86 };
87 87
88 void discard(string_set &s); 88 void discard(string_set &s);
89 char* register_string(string_set &s, char *name); 89 const char* register_string(string_set &s, const char *name);
90 char* register_string(char *name); 90 const char* register_string(const char *name);
91 void clear_strings(); 91 void clear_strings();
92 int ip_address(char *have); 92 int ip_address(const char *have);
93 bool load_conf(CONFIG &dc, char *fn); 93 bool load_conf(CONFIG &dc, const char *fn);
94 void token_init(); 94 void token_init();
95 95
96 extern char *token_add; 96 extern const char *token_add;
97 extern char *token_bucket; 97 extern const char *token_bucket;
98 extern char *token_file; 98 extern const char *token_file;
99 extern char *token_ignore; 99 extern const char *token_ignore;
100 extern char *token_include; 100 extern const char *token_include;
101 extern char *token_index; 101 extern const char *token_index;
102 extern char *token_lbrace; 102 extern const char *token_lbrace;
103 extern char *token_pattern; 103 extern const char *token_pattern;
104 extern char *token_rbrace; 104 extern const char *token_rbrace;
105 extern char *token_remove; 105 extern const char *token_remove;
106 extern char *token_semi; 106 extern const char *token_semi;
107 extern char *token_slash; 107 extern const char *token_slash;
108 extern char *token_threshold; 108 extern const char *token_threshold;
109 109