equal
deleted
inserted
replaced
63 // this if is probably not needed |
63 // this if is probably not needed |
64 if (filter->regexp) |
64 if (filter->regexp) |
65 pcre_free(filter->regexp); |
65 pcre_free(filter->regexp); |
66 |
66 |
67 // release the logwatch_chan ref |
67 // release the logwatch_chan ref |
68 logwatch_put_chan(filter->chan); |
68 logwatch_chan_put(filter->chan); |
69 |
69 |
70 // free misc |
70 // free misc |
71 free(filter->format); |
71 free(filter->format); |
72 free(filter->name); |
72 free(filter->name); |
73 free(filter); |
73 free(filter); |
139 #define LOGWATCH_FILTER_OUT_PREFIX_LEN 16 |
139 #define LOGWATCH_FILTER_OUT_PREFIX_LEN 16 |
140 |
140 |
141 err_t logwatch_filter_apply (const struct logwatch_filter *filter, const struct logwatch_source *source, const char *line, struct error_info *err) |
141 err_t logwatch_filter_apply (const struct logwatch_filter *filter, const struct logwatch_source *source, const char *line, struct error_info *err) |
142 { |
142 { |
143 int ovec[LOGWATCH_FILTER_OVEC_ITEMS], ret; |
143 int ovec[LOGWATCH_FILTER_OVEC_ITEMS], ret; |
144 char buf[LOGWATCH_FILTER_OUT_PREFIX_LEN + LOGWATCH_FILTER_OUT_MAX + 1], *buf_ptr = buf; |
144 char buf[LOGWATCH_FILTER_OUT_MAX + 1], *buf_ptr = buf; |
145 size_t buf_size = LOGWATCH_FILTER_OUT_PREFIX_LEN + LOGWATCH_FILTER_OUT_MAX + 1; |
145 size_t buf_size = sizeof(buf); |
146 |
146 |
147 // XXX: what to do for truncated data? |
147 // XXX: what to do for truncated data? |
148 |
148 |
149 // discard based on source? |
149 // discard based on source? |
150 if (filter->source && source != filter->source) |
150 if (filter->source && source != filter->source) |
162 |
162 |
163 else |
163 else |
164 // misc. error |
164 // misc. error |
165 RETURN_SET_ERROR_EXTRA(err, ERR_PCRE_EXEC, ret); |
165 RETURN_SET_ERROR_EXTRA(err, ERR_PCRE_EXEC, ret); |
166 } |
166 } |
167 |
|
168 // format header |
|
169 buf_ptr += str_advance(NULL, &buf_size, str_append_fmt(buf_ptr, LOGWATCH_FILTER_OUT_PREFIX_LEN + 1, "[%.12s] ", filter->name)); |
|
170 |
167 |
171 // format? |
168 // format? |
172 if (filter->format) { |
169 if (filter->format) { |
173 // setup the ctx |
170 // setup the ctx |
174 struct logwatch_filter_str_format_ctx ctx = { |
171 struct logwatch_filter_str_format_ctx ctx = { |
182 if ((ERROR_CODE(err) = str_format(buf_ptr, buf_size, filter->format, logwatch_filter_str_format_cb, &ctx))) |
179 if ((ERROR_CODE(err) = str_format(buf_ptr, buf_size, filter->format, logwatch_filter_str_format_cb, &ctx))) |
183 goto error; |
180 goto error; |
184 |
181 |
185 } else { |
182 } else { |
186 // quote the entire line |
183 // quote the entire line |
|
184 // XXX: overflow |
187 buf_ptr += str_advance(NULL, &buf_size, str_quote(buf_ptr, buf_size, line, -1)); |
185 buf_ptr += str_advance(NULL, &buf_size, str_quote(buf_ptr, buf_size, line, -1)); |
|
186 |
188 } |
187 } |
189 |
188 |
|
189 // log |
190 log_info("<%s>:%s -> %s:%s", source->name, line, irc_chan_name(filter->chan->irc_chan), buf); |
190 log_info("<%s>:%s -> %s:%s", source->name, line, irc_chan_name(filter->chan->irc_chan), buf); |
191 |
191 |
192 // then send it as a notice |
192 // send it |
193 if ((ERROR_CODE(err) = irc_chan_NOTICE(filter->chan->irc_chan, buf))) |
193 if ((ERROR_CODE(err) = logwatch_chan_msg(filter->chan, "[%s] %s", filter->name, buf))) |
194 goto error; |
194 goto error; |
195 |
195 |
196 // ok |
196 // ok |
197 return SUCCESS; |
197 return SUCCESS; |
198 |
198 |