diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/auth/auth-request-stats.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/auth/auth-request-stats.c')
-rw-r--r-- | src/auth/auth-request-stats.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/auth/auth-request-stats.c b/src/auth/auth-request-stats.c new file mode 100644 index 0000000..7af4e9a --- /dev/null +++ b/src/auth/auth-request-stats.c @@ -0,0 +1,77 @@ +/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */ + +#include "auth-common.h" +#include "str.h" +#include "strescape.h" +#include "buffer.h" +#include "base64.h" +#include "stats.h" +#include "stats-connection.h" +#include "auth-stats.h" +#include "auth-request.h" +#include "auth-request-stats.h" + +#define USER_STATS_SOCKET_NAME "old-stats-user" + +static struct stats_connection *auth_stats_conn = NULL; +static struct stats_item *auth_stats_item; + +struct auth_stats *auth_request_stats_get(struct auth_request *request) +{ + if (request->stats == NULL) + request->stats = stats_alloc(request->pool); + return stats_fill_ptr(request->stats, auth_stats_item); +} + +void auth_request_stats_add_tempfail(struct auth_request *request) +{ + struct auth_stats *stats = auth_request_stats_get(request); + + stats->auth_db_tempfail_count++; +} + +void auth_request_stats_send(struct auth_request *request) +{ + string_t *str; + buffer_t *buf; + + /* we'll send stats only when the request is finished. this reduces + memory usage and is a bit simpler. auth requests are typically + pretty short lived anyway. */ + i_assert(!request->stats_sent); + request->stats_sent = TRUE; + + if (request->stats == NULL) { + /* nothing happened in this request - don't send it */ + return; + } + if (!request->set->stats) + return; + + buf = t_buffer_create(128); + stats_export(buf, request->stats); + + str = t_str_new(256); + str_append(str, "ADD-USER\t"); + if (request->fields.user != NULL) + str_append_tabescaped(str, request->fields.user); + str_append_c(str, '\t'); + str_append_tabescaped(str, request->fields.service); + str_append_c(str, '\t'); + base64_encode(buf->data, buf->used, str); + + str_append_c(str, '\n'); + stats_connection_send(auth_stats_conn, str); +} + +void auth_request_stats_init(void) +{ + auth_stats_conn = stats_connection_create(USER_STATS_SOCKET_NAME); + auth_stats_item = stats_register(&auth_stats_vfuncs); +} + +void auth_request_stats_deinit(void) +{ + stats_connection_unref(&auth_stats_conn); + stats_unregister(&auth_stats_item); +} |