Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stats: Split stats-connection.[ch] to lib-stats/ and plugin's mail-sp…
…ecific parts.
- Loading branch information
Showing
8 changed files
with
115 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef STATS_CONNECTION_H | ||
#define STATS_CONNECTION_H | ||
|
||
struct stats_connection *stats_connection_create(const char *path); | ||
void stats_connection_ref(struct stats_connection *conn); | ||
void stats_connection_unref(struct stats_connection **conn); | ||
|
||
void stats_connection_send(struct stats_connection *conn, const string_t *str); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Copyright (c) 2011-2016 Dovecot authors, see the included COPYING file */ | ||
|
||
#include "lib.h" | ||
#include "base64.h" | ||
#include "hostpid.h" | ||
#include "net.h" | ||
#include "str.h" | ||
#include "strescape.h" | ||
#include "mail-storage.h" | ||
#include "stats.h" | ||
#include "stats-plugin.h" | ||
#include "mail-stats-connection.h" | ||
|
||
void mail_stats_connection_connect(struct stats_connection *conn, | ||
struct mail_user *user) | ||
{ | ||
struct stats_user *suser = STATS_USER_CONTEXT(user); | ||
string_t *str = t_str_new(128); | ||
|
||
str_append(str, "CONNECT\t"); | ||
/* required fields */ | ||
str_append(str, suser->stats_session_id); | ||
str_append_c(str, '\t'); | ||
str_append_tabescaped(str, user->username); | ||
str_append_c(str, '\t'); | ||
str_append_tabescaped(str, user->service); | ||
str_printfa(str, "\t%s", my_pid); | ||
|
||
/* optional fields */ | ||
if (user->local_ip != NULL) { | ||
str_append(str, "\tlip="); | ||
str_append(str, net_ip2addr(user->local_ip)); | ||
} | ||
if (user->remote_ip != NULL) { | ||
str_append(str, "\trip="); | ||
str_append(str, net_ip2addr(user->remote_ip)); | ||
} | ||
str_append_c(str, '\n'); | ||
stats_connection_send(conn, str); | ||
} | ||
|
||
void mail_stats_connection_disconnect(struct stats_connection *conn, | ||
struct mail_user *user) | ||
{ | ||
struct stats_user *suser = STATS_USER_CONTEXT(user); | ||
string_t *str = t_str_new(128); | ||
|
||
str_append(str, "DISCONNECT\t"); | ||
str_append(str, suser->stats_session_id); | ||
str_append_c(str, '\n'); | ||
stats_connection_send(conn, str); | ||
} | ||
|
||
void mail_stats_connection_send_session(struct stats_connection *conn, | ||
struct mail_user *user, | ||
const struct stats *stats) | ||
{ | ||
struct stats_user *suser = STATS_USER_CONTEXT(user); | ||
string_t *str = t_str_new(256); | ||
buffer_t *buf; | ||
|
||
buf = buffer_create_dynamic(pool_datastack_create(), 128); | ||
stats_export(buf, stats); | ||
|
||
str_append(str, "UPDATE-SESSION\t"); | ||
str_append(str, suser->stats_session_id); | ||
str_append_c(str, '\t'); | ||
base64_encode(buf->data, buf->used, str); | ||
|
||
str_append_c(str, '\n'); | ||
stats_connection_send(conn, str); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef MAIL_STATS_CONNECTION_H | ||
#define MAIL_STATS_CONNECTION_H | ||
|
||
#include "stats-connection.h" | ||
|
||
struct mail_stats; | ||
struct mail_user; | ||
|
||
void mail_stats_connection_connect(struct stats_connection *conn, | ||
struct mail_user *user); | ||
void mail_stats_connection_disconnect(struct stats_connection *conn, | ||
struct mail_user *user); | ||
|
||
void mail_stats_connection_send_session(struct stats_connection *conn, | ||
struct mail_user *user, | ||
const struct stats *stats); | ||
void mail_stats_connection_send(struct stats_connection *conn, const string_t *str); | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters