]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Split stats-connection.[ch] to lib-stats/ and plugin's mail-specific parts.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 5 Feb 2016 13:07:00 +0000 (15:07 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 5 Feb 2016 13:26:00 +0000 (15:26 +0200)
src/lib-stats/Makefile.am
src/lib-stats/stats-connection.c [moved from src/plugins/stats/stats-connection.c with 56% similarity]
src/lib-stats/stats-connection.h [new file with mode: 0644]
src/plugins/stats/Makefile.am
src/plugins/stats/mail-stats-connection.c [new file with mode: 0644]
src/plugins/stats/mail-stats-connection.h [new file with mode: 0644]
src/plugins/stats/stats-connection.h [deleted file]
src/plugins/stats/stats-plugin.c

index 48695dd30e10e7201e3ba373fdf9e21702dad1d3..d06f3bc0c8f31aafd07d6a891635705c5a6226f8 100644 (file)
@@ -1,14 +1,17 @@
 noinst_LTLIBRARIES = libstats.la
 
 AM_CPPFLAGS = \
-       -I$(top_srcdir)/src/lib
+       -I$(top_srcdir)/src/lib \
+       -I$(top_srcdir)/src/lib-master
 
 libstats_la_SOURCES = \
        stats.c \
+       stats-connection.c \
        stats-parser.c
 
 headers = \
        stats.h \
+       stats-connection.h \
        stats-parser.h
 
 pkginc_libdir = $(pkgincludedir)
similarity index 56%
rename from src/plugins/stats/stats-connection.c
rename to src/lib-stats/stats-connection.c
index 35d2ac9653c5bec26a922cd7142aa9059e3367a7..389ed861c4849235f35b0033bf49b94a2a2db4e2 100644 (file)
@@ -1,17 +1,13 @@
 /* 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 "master-service.h"
-#include "mail-storage.h"
-#include "stats.h"
-#include "stats-plugin.h"
 #include "stats-connection.h"
 
+#include <unistd.h>
+#include <fcntl.h>
+
 struct stats_connection {
        int refcount;
 
@@ -106,63 +102,3 @@ void stats_connection_send(struct stats_connection *conn, const string_t *str)
                conn->fd = -1;
        }
 }
-
-void 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 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 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);
-}
diff --git a/src/lib-stats/stats-connection.h b/src/lib-stats/stats-connection.h
new file mode 100644 (file)
index 0000000..7555f72
--- /dev/null
@@ -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
index ee26f3742116c307f9b2ce0d91ccb55288426336..fd7e5411c827420d8db0979b9b176ae9c041237a 100644 (file)
@@ -16,12 +16,12 @@ module_LTLIBRARIES = \
 lib90_stats_plugin_la_SOURCES = \
        mail-stats.c \
        mail-stats-fill.c \
-       stats-connection.c \
+       mail-stats-connection.c \
        stats-plugin.c
 
 noinst_HEADERS = \
        mail-stats.h \
-       stats-connection.h \
+       mail-stats-connection.h \
        stats-plugin.h
 
 stats_moduledir = $(moduledir)/stats
diff --git a/src/plugins/stats/mail-stats-connection.c b/src/plugins/stats/mail-stats-connection.c
new file mode 100644 (file)
index 0000000..f3103be
--- /dev/null
@@ -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);
+}
diff --git a/src/plugins/stats/mail-stats-connection.h b/src/plugins/stats/mail-stats-connection.h
new file mode 100644 (file)
index 0000000..3b3362b
--- /dev/null
@@ -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
diff --git a/src/plugins/stats/stats-connection.h b/src/plugins/stats/stats-connection.h
deleted file mode 100644 (file)
index 5ab37a1..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef STATS_CONNECTION_H
-#define STATS_CONNECTION_H
-
-struct mail_stats;
-struct mail_user;
-
-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_connect(struct stats_connection *conn,
-                             struct mail_user *user);
-void stats_connection_disconnect(struct stats_connection *conn,
-                                struct mail_user *user);
-
-void stats_connection_send_session(struct stats_connection *conn,
-                                  struct mail_user *user,
-                                  const struct stats *stats);
-void stats_connection_send(struct stats_connection *conn, const string_t *str);
-
-#endif
index b5db95815f9a9590d563962e58edd4284c44ebb3..fa65bb8c344b40e0df0d1de55ed7199cd13a98f3 100644 (file)
@@ -8,7 +8,7 @@
 #include "settings-parser.h"
 #include "mail-stats.h"
 #include "stats.h"
-#include "stats-connection.h"
+#include "mail-stats-connection.h"
 #include "stats-plugin.h"
 
 #define STATS_CONTEXT(obj) \
@@ -129,8 +129,8 @@ static void session_stats_refresh(struct mail_user *user)
                suser->session_sent_duplicate = !changed;
                suser->last_session_update = now;
                stats_copy(suser->last_sent_session_stats, suser->session_stats);
-               stats_connection_send_session(suser->stats_conn, user,
-                                             suser->session_stats);
+               mail_stats_connection_send_session(suser->stats_conn, user,
+                                                  suser->session_stats);
        }
 
        if (suser->to_stats_timeout != NULL)
@@ -333,7 +333,7 @@ static void stats_user_deinit(struct mail_user *user)
                                         stats_io_deactivate, user);
        /* send final stats before disconnection */
        session_stats_refresh(user);
-       stats_connection_disconnect(stats_conn, user);
+       mail_stats_connection_disconnect(stats_conn, user);
 
        if (suser->to_stats_timeout != NULL)
                timeout_remove(&suser->to_stats_timeout);
@@ -434,7 +434,7 @@ static void stats_user_created(struct mail_user *user)
        suser->last_sent_session_stats = stats_alloc(user->pool);
 
        MODULE_CONTEXT_SET(user, stats_user_module, suser);
-       stats_connection_connect(suser->stats_conn, user);
+       mail_stats_connection_connect(suser->stats_conn, user);
        suser->to_stats_timeout =
                timeout_add(suser->refresh_secs*1000,
                            session_stats_refresh_timeout, user);