-
Notifications
You must be signed in to change notification settings - Fork 2
/
syslog_parser.h
146 lines (121 loc) · 2.86 KB
/
syslog_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* */
/*
* Copyright (c) 2015 David Gwynne <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SYSLOG_PARSER_H_
#define SYSLOG_PARSER_H_
#include <time.h>
#include <sys/types.h>
enum syslog_parser_state {
S_STREAM_BEGINNING,
S_STREAM_SIZE,
S_PRI_BEGINNING,
S_PRI_FIRST,
S_PRI,
S_TS_BEGINNING,
S_TS_NIL_SP,
S_TS_RFC_YY,
S_TS_RFC_YYY,
S_TS_RFC_YYYY,
S_TS_RFC_YYYY_,
S_TS_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tm has year and tz */
#define SYSLOG_PARSER_TM_MS (1<<2) /* tm has ms */
struct timespec begin_ts;
struct tm tm;
unsigned int fs;
unsigned int fs_width;
int digits;
};
struct syslog_parser_settings {
int (*syslog_pri)(void *, int, int);
int (*syslog_tm)(void *, const struct tm *);
int (*syslog_msg)(void *, const char *, size_t);
int (*syslog_end)(void *);
};
void syslog_parser_init(struct syslog_parser *, int, void *);
ssize_t syslog_parser_exec(struct syslog_parser *,
const struct syslog_parser_settings *,
const char *, ssize_t);
int syslog_parser_done(struct syslog_parser *);
#endif /* SYSLOG_PARSER_H_ */