51 /** Our entry in logwatch::channels */ |
51 /** Our entry in logwatch::channels */ |
52 TAILQ_ENTRY(logwatch_chan) logwatch_channels; |
52 TAILQ_ENTRY(logwatch_chan) logwatch_channels; |
53 }; |
53 }; |
54 |
54 |
55 /** |
55 /** |
|
56 * Maximum length of a logwatch_chan message, not including NUL byte |
|
57 * |
|
58 * XXX: this is a bad way to handle truncation |
|
59 */ |
|
60 #define LOGWATCH_CHAN_MSG_MAX 470 |
|
61 |
|
62 /** |
56 * A filter specifies what lines to match, and how to then format the output. |
63 * A filter specifies what lines to match, and how to then format the output. |
57 */ |
64 */ |
58 struct logwatch_filter { |
65 struct logwatch_filter { |
59 /** The logwatch context we are registered to */ |
66 /** The logwatch context we are registered to */ |
60 struct logwatch *ctx; |
67 struct logwatch *ctx; |
88 * Maximum number of capture groups in the filter's regexp |
95 * Maximum number of capture groups in the filter's regexp |
89 */ |
96 */ |
90 #define LOGWATCH_FILTER_GROUPS_MAX 16 |
97 #define LOGWATCH_FILTER_GROUPS_MAX 16 |
91 |
98 |
92 /** |
99 /** |
93 * Maximum length of output string, not including NUL byte |
100 * Maximum length of logwatch_filter output |
94 */ |
101 */ |
95 #define LOGWATCH_FILTER_OUT_MAX 450 |
102 #define LOGWATCH_FILTER_OUT_MAX 450 |
96 |
103 |
97 /** |
104 /** |
98 * The logwatch module state |
105 * The logwatch module state |
132 * Lookup a logwatch_source by name |
139 * Lookup a logwatch_source by name |
133 */ |
140 */ |
134 const struct logwatch_source* logwatch_source_lookup (struct logwatch *ctx, const char *name); |
141 const struct logwatch_source* logwatch_source_lookup (struct logwatch *ctx, const char *name); |
135 |
142 |
136 /** |
143 /** |
|
144 * Returns true if the given chan is linked to the given source via at least one filter |
|
145 */ |
|
146 bool logwatch_chan_has_source (struct logwatch_chan *chan, const struct logwatch_source *source); |
|
147 |
|
148 /** |
|
149 * Look for an existing logwatch_chan entry, returning it if it exists |
|
150 */ |
|
151 struct logwatch_chan* logwatch_chan_lookup (struct logwatch *ctx, struct irc_chan *irc_chan); |
|
152 |
|
153 /** |
|
154 * Create a new irc_chan with an initial refcount of one. |
|
155 * |
|
156 * @returns NULL on ERR_CALLOC |
|
157 */ |
|
158 struct logwatch_chan* logwatch_chan_create (struct logwatch *ctx, struct irc_chan *irc_chan); |
|
159 |
|
160 /** |
|
161 * Returns a logwatch_chan reference, destroying as needed. |
|
162 */ |
|
163 void logwatch_chan_put (struct logwatch_chan *chan); |
|
164 |
|
165 /** |
|
166 * Send a notice of at most LOGWATCH_CHAN_MSG_MAX bytes to the channel using the given format string. |
|
167 */ |
|
168 err_t logwatch_chan_msg (struct logwatch_chan *chan, const char *fmt, ...); |
|
169 |
|
170 /** |
137 * Find an existing logwatch_chan for the given channel, or create a new one. Returns a real reference that should be |
171 * Find an existing logwatch_chan for the given channel, or create a new one. Returns a real reference that should be |
138 * returned using logwatch_put_chan(). |
172 * returned using logwatch_put_chan(). |
139 * |
173 * |
140 * @returns NULL on ERR_CALLOC |
174 * @returns NULL on ERR_CALLOC |
141 */ |
175 */ |
142 struct logwatch_chan* logwatch_get_chan (struct logwatch *ctx, struct irc_chan *irc_chan); |
176 struct logwatch_chan* logwatch_get_chan (struct logwatch *ctx, struct irc_chan *irc_chan); |
143 |
177 |
144 /** |
178 /** |
145 * Returns a reference aquired using logwatch_get_chan(). |
|
146 */ |
|
147 void logwatch_put_chan (struct logwatch_chan *chan); |
|
148 |
|
149 /** |
|
150 * Add a new filter. |
179 * Add a new filter. |
151 * |
180 * |
152 * The given logwatch_chan should be a new reference. |
181 * The given logwatch_chan should be a new reference. |
153 */ |
182 */ |
154 struct logwatch_filter* logwatch_filter (struct logwatch *ctx, const char *name, const struct logwatch_source *source, |
183 struct logwatch_filter* logwatch_filter (struct logwatch *ctx, const char *name, const struct logwatch_source *source, |
174 */ |
203 */ |
175 void logwatch_on_line (struct logwatch *ctx, const struct logwatch_source *source, const char *line); |
204 void logwatch_on_line (struct logwatch *ctx, const struct logwatch_source *source, const char *line); |
176 |
205 |
177 /** |
206 /** |
178 * Handle a disasterous error on a logwatch_source by notifying any irc_chan's that it is linked to via our filters. |
207 * Handle a disasterous error on a logwatch_source by notifying any irc_chan's that it is linked to via our filters. |
|
208 * |
|
209 * The logwatch_source will dispose of itself after this. |
179 */ |
210 */ |
180 void logwatch_on_error (struct logwatch *ctx, const struct logwatch_source *source, const struct error_info *err); |
211 void logwatch_on_error (struct logwatch *ctx, const struct logwatch_source *source, const struct error_info *err); |