Skip to content
Snippets Groups Projects
Commit 8b47f293 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Added strbuf error handler.

parent 3cc0395d
No related branches found
No related tags found
No related merge requests found
......@@ -188,6 +188,69 @@ struct sieve_error_handler *sieve_stderr_ehandler_create( void )
return ehandler;
}
/* Output errors to a string buffer */
struct sieve_strbuf_ehandler {
struct sieve_error_handler handler;
string_t *errors;
};
static void sieve_strbuf_verror
(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, va_list args)
{
struct sieve_strbuf_ehandler *handler =
(struct sieve_strbuf_ehandler *) ehandler;
str_printfa(handler->errors, "%s: error: ", location);
str_vprintfa(handler->errors, fmt, args);
str_append(handler->errors, ".\n");
}
static void sieve_strbuf_vwarning
(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, va_list args)
{
struct sieve_strbuf_ehandler *handler =
(struct sieve_strbuf_ehandler *) ehandler;
str_printfa(handler->errors, "%s: warning: ", location);
str_vprintfa(handler->errors, fmt, args);
str_append(handler->errors, ".\n");
}
static void sieve_strbuf_vinfo
(struct sieve_error_handler *ehandler, const char *location,
const char *fmt, va_list args)
{
struct sieve_strbuf_ehandler *handler =
(struct sieve_strbuf_ehandler *) ehandler;
str_printfa(handler->errors, "%s: info: ", location);
str_vprintfa(handler->errors, fmt, args);
str_append(handler->errors, ".\n");
}
struct sieve_error_handler *sieve_strbuf_ehandler_create
(string_t *strbuf)
{
pool_t pool;
struct sieve_strbuf_ehandler *ehandler;
pool = pool_alloconly_create("strbuf_error_handler", 256);
ehandler = p_new(pool, struct sieve_strbuf_ehandler, 1);
ehandler->errors = strbuf;
ehandler->handler.pool = pool;
ehandler->handler.errors = 0;
ehandler->handler.warnings = 0;
ehandler->handler.verror = sieve_strbuf_verror;
ehandler->handler.vwarning = sieve_strbuf_vwarning;
ehandler->handler.vinfo = sieve_strbuf_vinfo;
return &(ehandler->handler);
}
/* Output errors to a log file */
struct sieve_logfile_ehandler {
......
......@@ -102,6 +102,7 @@ void sieve_error_handler_free(struct sieve_error_handler **ehandler);
/* Error handlers */
struct sieve_error_handler *sieve_stderr_ehandler_create(void);
struct sieve_error_handler *sieve_strbuf_ehandler_create(string_t *strbuf);
struct sieve_error_handler *sieve_logfile_ehandler_create(const char *logfile);
#endif /* __SIEVE_ERROR_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.