#include "smtpd.h"
extern struct stat_backend stat_backend_ramstat;
struct stat_backend *
stat_backend_lookup(const char *name)
{
return &stat_backend_ramstat;
}
void
stat_increment(const char *key, size_t count)
{
struct stat_value *value;
if (count == 0)
return;
value = stat_counter(count);
m_create(p_control, IMSG_STAT_INCREMENT, 0, 0, -1);
m_add_string(p_control, key);
m_add_data(p_control, value, sizeof(*value));
m_close(p_control);
}
void
stat_decrement(const char *key, size_t count)
{
struct stat_value *value;
if (count == 0)
return;
value = stat_counter(count);
m_create(p_control, IMSG_STAT_DECREMENT, 0, 0, -1);
m_add_string(p_control, key);
m_add_data(p_control, value, sizeof(*value));
m_close(p_control);
}
void
stat_set(const char *key, const struct stat_value *value)
{
m_create(p_control, IMSG_STAT_SET, 0, 0, -1);
m_add_string(p_control, key);
m_add_data(p_control, value, sizeof(*value));
m_close(p_control);
}
struct stat_value *
stat_counter(size_t counter)
{
static struct stat_value value;
value.type = STAT_COUNTER;
value.u.counter = counter;
return &value;
}
struct stat_value *
stat_timestamp(time_t timestamp)
{
static struct stat_value value;
value.type = STAT_TIMESTAMP;
value.u.timestamp = timestamp;
return &value;
}
struct stat_value *
stat_timeval(struct timeval *tv)
{
static struct stat_value value;
value.type = STAT_TIMEVAL;
value.u.tv = *tv;
return &value;
}
struct stat_value *
stat_timespec(struct timespec *ts)
{
static struct stat_value value;
value.type = STAT_TIMESPEC;
value.u.ts = *ts;
return &value;
}