1 | #ifndef SH_LOGCHECK_H
|
---|
2 | #define SH_LOGCHECK_H
|
---|
3 |
|
---|
4 | #include <sys/types.h>
|
---|
5 | #include <time.h>
|
---|
6 |
|
---|
7 | /* Convert a struct tm to unix timestamp with caching
|
---|
8 | */
|
---|
9 | time_t conv_timestamp (struct tm * btime,
|
---|
10 | struct tm * old_tm, time_t * old_time);
|
---|
11 |
|
---|
12 | /* Definition of a log record entry, to be returned from parsing function.
|
---|
13 | */
|
---|
14 | #define PID_INVALID 0
|
---|
15 | struct sh_logrecord
|
---|
16 | {
|
---|
17 | char * filename;
|
---|
18 | sh_string * prefix; /* actually a string to group messages */
|
---|
19 | sh_string * host;
|
---|
20 | sh_string * timestr;
|
---|
21 | pid_t pid;
|
---|
22 | time_t timestamp;
|
---|
23 | sh_string * message;
|
---|
24 | };
|
---|
25 |
|
---|
26 | #define SH_LOGFILE_MOVED (1<<0)
|
---|
27 | #define SH_LOGFILE_REWIND (1<<1)
|
---|
28 |
|
---|
29 | struct sh_logfile
|
---|
30 | {
|
---|
31 | FILE * fp;
|
---|
32 | int flags;
|
---|
33 | char * filename;
|
---|
34 | dev_t device_id;
|
---|
35 | ino_t inode;
|
---|
36 | fpos_t offset;
|
---|
37 |
|
---|
38 | /* Info for the parser, e.g. a regular expression
|
---|
39 | */
|
---|
40 | void * fileinfo;
|
---|
41 |
|
---|
42 | /* Callback function to read the next record
|
---|
43 | */
|
---|
44 | sh_string * (*get_record) (sh_string * record,
|
---|
45 | struct sh_logfile * logfile);
|
---|
46 |
|
---|
47 | /* Callback function to parse the record into standard format
|
---|
48 | */
|
---|
49 | struct sh_logrecord * (*parse_record)(sh_string * logline, void * fileinfo);
|
---|
50 |
|
---|
51 | struct sh_logfile * next;
|
---|
52 | };
|
---|
53 |
|
---|
54 | /****************************************************************
|
---|
55 | **
|
---|
56 | ** Parsing and reading functions
|
---|
57 | **/
|
---|
58 |
|
---|
59 | /* Open file, position at stored offset. */
|
---|
60 | int sh_open_for_reader (struct sh_logfile * logfile);
|
---|
61 |
|
---|
62 | /* Simple line reader. */
|
---|
63 | sh_string * sh_default_reader (sh_string * record,
|
---|
64 | struct sh_logfile * logfile);
|
---|
65 |
|
---|
66 | /* Binary reader */
|
---|
67 | sh_string * sh_binary_reader (void * s, size_t size, struct sh_logfile * logfile);
|
---|
68 |
|
---|
69 | /* Parses a syslog-style line. */
|
---|
70 | struct sh_logrecord * sh_parse_syslog (sh_string * logline, void * fileinfo);
|
---|
71 |
|
---|
72 | /* Format info for apache log. */
|
---|
73 | void * sh_eval_fileinfo_apache(char * str);
|
---|
74 |
|
---|
75 | /* Parses a apache-style line. */
|
---|
76 | struct sh_logrecord * sh_parse_apache (sh_string * logline, void * fileinfo);
|
---|
77 |
|
---|
78 | /* Get a pacct record */
|
---|
79 | sh_string * sh_read_pacct (sh_string * record, struct sh_logfile * logfile);
|
---|
80 |
|
---|
81 | /* Parses a pacct record. */
|
---|
82 | struct sh_logrecord * sh_parse_pacct (sh_string * logline, void * fileinfo);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | *****************************************************************/
|
---|
86 |
|
---|
87 | int sh_get_hidepid();
|
---|
88 | int sh_set_hidepid(const char *s);
|
---|
89 |
|
---|
90 | #define SH_MAX_LCODE_SIZE 16
|
---|
91 |
|
---|
92 | struct sh_logfile_type
|
---|
93 | {
|
---|
94 | char code[SH_MAX_LCODE_SIZE];
|
---|
95 |
|
---|
96 | /* read callback */
|
---|
97 | /*@null@*/sh_string * (*get_record) (sh_string * record,
|
---|
98 | struct sh_logfile * logfile);
|
---|
99 | /* parsing callback */
|
---|
100 | struct sh_logrecord * (*parse_record)(sh_string * logline, void * fileinfo);
|
---|
101 |
|
---|
102 | /* evaluate fileinfo */
|
---|
103 | void * (*eval_fileinfo)(char * str);
|
---|
104 | };
|
---|
105 |
|
---|
106 |
|
---|
107 | #endif
|
---|