bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenstatic struct stats_parser_field auth_stats_fields[] = {
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen#define E(parsename, name, type) { parsename, offsetof(struct auth_stats, name), sizeof(((struct auth_stats *)0)->name), type }
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen#define EN(parsename, name) E(parsename, name, STATS_PARSER_TYPE_UINT)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen EN("auth_master_successes", auth_master_success_count),
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen EN("auth_db_tempfails", auth_db_tempfail_count),
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen EN("auth_cache_misses", auth_cache_miss_count)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen return sizeof(struct auth_stats);
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenstatic unsigned int auth_stats_field_count(void)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenstatic const char *auth_stats_field_name(unsigned int n)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenauth_stats_field_value(string_t *str, const struct stats *stats,
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen unsigned int n)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen stats_parser_value(str, &auth_stats_fields[n], stats);
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenauth_stats_diff(const struct stats *stats1, const struct stats *stats2,
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen struct stats *diff_stats_r, const char **error_r)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen return stats_parser_diff(auth_stats_fields, N_ELEMENTS(auth_stats_fields),
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenstatic void auth_stats_add(struct stats *dest, const struct stats *src)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen stats_parser_add(auth_stats_fields, N_ELEMENTS(auth_stats_fields),
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenauth_stats_have_changed(const struct stats *_prev, const struct stats *_cur)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen return memcmp(_prev, _cur, sizeof(struct auth_stats)) != 0;
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenstatic void auth_stats_export(buffer_t *buf, const struct stats *_stats)
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen const struct auth_stats *stats = (const struct auth_stats *)_stats;
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenauth_stats_import(const unsigned char *data, size_t size, size_t *pos_r,
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen struct auth_stats *stats = (struct auth_stats *)_stats;
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainenconst struct stats_vfuncs auth_stats_vfuncs = {
44cf91b7a701a9b4d9f59a990552eab4f7f64fbcTimo Sirainen/* for the stats_auth plugin: */