1
/* Copyright (c) 2002-2009 Dovecot Sieve authors, see the included COPYING file
7
#include "sieve-common.h"
8
#include "sieve-error-private.h"
10
#include "testsuite-log.h"
13
* Testsuite error handler
16
struct sieve_error_handler *testsuite_log_ehandler = NULL;
18
struct _testsuite_log_message {
23
bool _testsuite_log_stdout = FALSE;
25
unsigned int _testsuite_log_error_index = 0;
27
static pool_t _testsuite_logmsg_pool = NULL;
28
ARRAY_DEFINE(_testsuite_log_errors, struct _testsuite_log_message);
30
static void _testsuite_log_verror
31
(struct sieve_error_handler *ehandler ATTR_UNUSED, const char *location,
32
const char *fmt, va_list args)
34
pool_t pool = _testsuite_logmsg_pool;
35
struct _testsuite_log_message msg;
37
if ( _testsuite_log_stdout )
40
VA_COPY(args_copy, args);
41
printf("error: %s: %s.\n", location, t_strdup_vprintf(fmt, args_copy));
44
msg.location = p_strdup(pool, location);
45
msg.message = p_strdup_vprintf(pool, fmt, args);
47
array_append(&_testsuite_log_errors, &msg, 1);
50
static struct sieve_error_handler *_testsuite_log_ehandler_create(void)
53
struct sieve_error_handler *ehandler;
55
/* Pool is not strictly necessary, but other handler types will need a pool,
56
* so this one will have one too.
58
pool = pool_alloconly_create
59
("testsuite_log_handler", sizeof(struct sieve_error_handler));
60
ehandler = p_new(pool, struct sieve_error_handler, 1);
61
sieve_error_handler_init(ehandler, pool, 0);
63
ehandler->verror = _testsuite_log_verror;
68
void testsuite_log_clear_messages(void)
70
if ( _testsuite_logmsg_pool != NULL ) {
71
if ( array_count(&_testsuite_log_errors) == 0 )
73
pool_unref(&_testsuite_logmsg_pool);
76
_testsuite_logmsg_pool = pool_alloconly_create
77
("testsuite_log_messages", 8192);
79
p_array_init(&_testsuite_log_errors, _testsuite_logmsg_pool, 128);
81
sieve_error_handler_reset(testsuite_log_ehandler);
84
void testsuite_log_get_error_init(void)
86
_testsuite_log_error_index = 0;
89
const char *testsuite_log_get_error_next(bool location)
91
const struct _testsuite_log_message *msg;
93
if ( _testsuite_log_error_index >= array_count(&_testsuite_log_errors) )
96
msg = array_idx(&_testsuite_log_errors, _testsuite_log_error_index++);
104
void testsuite_log_init(void)
106
testsuite_log_ehandler = _testsuite_log_ehandler_create();
107
sieve_error_handler_accept_infolog(testsuite_log_ehandler, TRUE);
109
sieve_system_ehandler_set(testsuite_log_ehandler);
111
testsuite_log_clear_messages();
114
void testsuite_log_deinit(void)
116
sieve_system_ehandler_reset();
118
sieve_error_handler_unref(&testsuite_log_ehandler);
120
pool_unref(&_testsuite_logmsg_pool);