1 #ifndef MAIL_STATS_H 2 #define MAIL_STATS_H 3 4 #include <sys/time.h> 5 6 #include "net.h" 7 #include "guid.h" 8 #include "stats.h" 9 10 struct stats_send_ctx; 11 12 struct mail_command { 13 struct mail_command *stable_prev, *stable_next; 14 struct mail_command *session_prev, *session_next; 15 16 struct mail_session *session; 17 char *name, *args; 18 /* non-zero id means the command is still running */ 19 unsigned int id; 20 21 struct timeval last_update; 22 struct stats *stats; 23 24 int refcount; 25 }; 26 27 struct mail_session { 28 struct mail_session *stable_prev, *stable_next; 29 struct mail_session *sorted_prev, *sorted_next; 30 struct mail_session *user_prev, *user_next; 31 struct mail_session *ip_prev, *ip_next; 32 33 /* if id="", the session no longer exists */ 34 char *id; 35 struct mail_user *user; 36 const char *service; 37 pid_t pid; 38 /* ip address may be NULL if there's none */ 39 struct mail_ip *ip; 40 struct timeout *to_idle; 41 42 struct stats *stats; 43 struct timeval last_update; 44 unsigned int num_cmds; 45 46 bool disconnected; 47 unsigned int highest_cmd_id; 48 int refcount; 49 struct mail_command *commands; 50 }; 51 52 struct mail_user { 53 struct mail_user *stable_prev, *stable_next; 54 struct mail_user *sorted_prev, *sorted_next; 55 struct mail_user *domain_prev, *domain_next; 56 char *name; 57 struct mail_domain *domain; 58 time_t reset_timestamp; 59 60 struct timeval last_update; 61 struct stats *stats; 62 unsigned int num_logins; 63 unsigned int num_cmds; 64 65 int refcount; 66 struct mail_session *sessions; 67 }; 68 69 struct mail_domain { 70 struct mail_domain *stable_prev, *stable_next; 71 struct mail_domain *sorted_prev, *sorted_next; 72 char *name; 73 time_t reset_timestamp; 74 75 struct timeval last_update; 76 struct stats *stats; 77 unsigned int num_logins; 78 unsigned int num_cmds; 79 unsigned int num_connected_sessions; 80 81 int refcount; 82 struct mail_user *users; 83 }; 84 85 struct mail_ip { 86 struct mail_ip *stable_prev, *stable_next; 87 struct mail_ip *sorted_prev, *sorted_next; 88 struct ip_addr ip; 89 time_t reset_timestamp; 90 91 struct timeval last_update; 92 struct stats *stats; 93 unsigned int num_logins; 94 unsigned int num_cmds; 95 unsigned int num_connected_sessions; 96 97 int refcount; 98 struct mail_session *sessions; 99 }; 100 101 struct mail_global { 102 time_t reset_timestamp; 103 104 struct timeval last_update; 105 struct stats *stats; 106 unsigned int num_logins; 107 unsigned int num_cmds; 108 unsigned int num_connected_sessions; 109 110 struct timeout *to_stats_send; 111 struct stats_send_ctx *stats_send_ctx; 112 }; 113 114 extern struct mail_global mail_global_stats; 115 116 void mail_global_init(void); 117 void mail_global_deinit(void); 118 119 void mail_global_login(void); 120 void mail_global_disconnected(void); 121 void mail_global_refresh(const struct stats *diff_stats); 122 123 #endif 124