comparison src/syslogconfig.h @ 4:2737ab01659a

initial coding
author carl
date Thu, 01 Dec 2005 17:17:37 -0800
parents 8fe310e5cd44
children d76f9ff42487
comparison
equal deleted inserted replaced
3:8fe310e5cd44 4:2737ab01659a
22 #define syslogconfig_include 22 #define syslogconfig_include
23 23
24 #include "tokenizer.h" 24 #include "tokenizer.h"
25 #include <map> 25 #include <map>
26 #include <regex.h> 26 #include <regex.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
27 29
28 30
29 class SYSLOGCONFIG; 31 class SYSLOGCONFIG;
30 class CONFIG; 32 class CONFIG;
31 33
37 39
38 class PATTERN { 40 class PATTERN {
39 char * pattern; // owned by the string table 41 char * pattern; // owned by the string table
40 regex_t re; 42 regex_t re;
41 int index; // zero based substring of the regex match that contains the ip address or hostname 43 int index; // zero based substring of the regex match that contains the ip address or hostname
42 int bucket; // count to add to the ip address leaky bucket 44 int amount; // count to add to the ip address leaky bucket
43 public: 45 public:
44 ~PATTERN(); 46 ~PATTERN();
45 PATTERN(TOKEN &tok, char *pattern_, int index_, int bucket_); 47 PATTERN(TOKEN &tok, char *pattern_, int index_, int amount_);
46 bool process(char *buf, CONFIG &con); 48 bool process(char *buf, CONFIG &con);
47 void dump(int level); 49 void dump(int level);
48 }; 50 };
49 51
50 typedef SYSLOGCONFIG * SYSLOGCONFIGP; 52 typedef SYSLOGCONFIG * SYSLOGCONFIGP;
53 typedef list<IPPAIR> ippair_list; 55 typedef list<IPPAIR> ippair_list;
54 typedef list<PATTERNP> pattern_list; 56 typedef list<PATTERNP> pattern_list;
55 const int buflen = 1024; 57 const int buflen = 1024;
56 58
57 class SYSLOGCONFIG { 59 class SYSLOGCONFIG {
60 TOKEN * tokp;
58 char * file_name; // name of the syslog file 61 char * file_name; // name of the syslog file
59 pattern_list patterns; // owns the patterns 62 pattern_list patterns; // owns the patterns
60 int fd; 63 int fd;
64 struct stat openfdstat;
61 int len; // bytes in the buffer 65 int len; // bytes in the buffer
62 char buf[buflen]; 66 char buf[buflen];
63 public: 67 public:
64 SYSLOGCONFIG(TOKEN &tok, char *file_name_); 68 SYSLOGCONFIG(TOKEN &tok, char *file_name_);
65 ~SYSLOGCONFIG(); 69 ~SYSLOGCONFIG();
70 bool failed() { return (fd == -1); };
71 void open(bool msg);
72 bool read(CONFIG &con);
73 void close();
66 void add_pattern(PATTERNP pat); 74 void add_pattern(PATTERNP pat);
67 bool failed() { return (fd == -1); };
68 bool read(CONFIG &con);
69 void process(CONFIG &con); 75 void process(CONFIG &con);
70 void dump(int level); 76 void dump(int level);
71 }; 77 };
72 78
73 class CONFIG { 79 class CONFIG {
88 int get_threshold() { return threshold; }; 94 int get_threshold() { return threshold; };
89 void add_syslogconfig(SYSLOGCONFIGP con); 95 void add_syslogconfig(SYSLOGCONFIGP con);
90 void add_pair(IPPAIR pair); 96 void add_pair(IPPAIR pair);
91 void dump(); 97 void dump();
92 void read(); 98 void read();
93 void sleep(int duration); 99 void sleep(int duration, time_t &previous);
94 bool looking(int ip); 100 bool looking(int ip);
95 }; 101 };
96 102
97 void discard(string_set &s); 103 void discard(string_set &s);
98 char* register_string(string_set &s, char *name); 104 char* register_string(string_set &s, char *name);