ze-filter
(ze-filter-0.8.0-develop-180218)
mlfi_close.c
Go to the documentation of this file.
1
2
/*
3
*
4
* ze-filter - Mail Server Filter for sendmail
5
*
6
* Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7
*
8
* Auteur : Jose Marcio Martins da Cruz
9
* jose.marcio.mc@gmail.org
10
*
11
* Historique :
12
* Creation : janvier 2002
13
*
14
* This program is free software, but with restricted license :
15
*
16
*
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
*
21
* More details about ze-filter license can be found at ze-filter
22
* web site : http://foss.jose-marcio.org
23
*/
24
25
26
/* ****************************************************************************
27
* *
28
* *
29
******************************************************************************/
30
sfsistat
31
mlfi_close
(ctx)
32
SMFICTX *ctx;
33
34
{
35
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
36
time_t now;
37
int
result =
SMFIS_CONTINUE
;
38
39
INIT_CALLBACK_DELAY
();
40
INIT_CALLBACK
(priv,
CALLBACK_CLOSE
);
41
(void)
count_connections
(-1);
42
stats_inc
(
STAT_CLOSE
, 1);
43
if
(priv == NULL)
44
goto
fin;
45
sm_macro_update
(ctx, priv->
sm
);
46
#if HAVE_GETHRTIME
47
priv->
t_close
= gethrtime();
48
#else
49
priv->
t_close
=
zeTime_ms
();
50
#endif
51
now = time(NULL);
52
#if _FFR_MODULES
53
/*
54
** ze-filter modules
55
**
56
*/
57
if
(
do_module_callback
(ctx, 0, &result))
58
goto
fin;
59
if
(result !=
SMFIS_CONTINUE
)
60
goto
fin;
61
#endif
/* _FFR_MODULES */
62
if
((priv->
peer_addr
!= NULL) && (strlen(priv->
peer_addr
) > 0)
63
&& !
STRCASEEQUAL
(priv->
peer_addr
,
"unknown"
)) {
64
#if HAVE_GETHRTIME
65
long
dtms =
66
(long) ((priv->
t_close
- priv->
t_open
) / 1000000);
67
#else
68
long
dtms = (long) (priv->
t_close
- priv->
t_open
);
69
#endif
70
if
(dtms >
tlongconn
* 1000)
71
(void)
livehistory_add_entry
(priv->
peer_addr
, now, 1,
LH_LONGCONN
);
72
(void)
raw_history_add_entry
(ctx);
73
/*
74
* Let's update open connections for this address
75
*/
76
(void)
connopen_check_host
(priv->
peer_addr
, priv->
peer_name
, -1);
77
/*
78
** If this is an empty connection, update records
79
*/
80
if
(priv->
nb_spams
> 0)
81
(void)
livehistory_add_entry
(priv->
peer_addr
, now, priv->
nb_spams
,
82
LH_HI_SCORE
);
83
if
((priv->
nb_rcpt
> 0) && (priv->
nb_msgs
== 0))
84
(void)
livehistory_add_entry
(priv->
peer_addr
, now, 1,
LH_EMPTYCONN
);
85
if
(priv->
nb_cbadrcpt
> 0)
86
(void)
livehistory_add_entry
(priv->
peer_addr
, now, priv->
nb_cbadrcpt
,
87
LH_BADRCPT
);
88
}
89
90
CHECK_CALLBACK_DELAY
();
91
sm_macro_free
(priv->
sm
);
92
mlfi_cleanup
(ctx,
TRUE
);
93
fin:
94
return
result;
95
}
CTXPRIV_T::nb_spams
int nb_spams
Definition:
ze-filter-data.h:212
stats_inc
void stats_inc(int, long)
Definition:
ze-stats.c:401
CTXPRIV_T::nb_msgs
int nb_msgs
Definition:
ze-filter-data.h:209
sm_macro_free
void sm_macro_free(sm_mac_T *)
Definition:
ze-smmacros.c:132
mlfi_cleanup
sfsistat mlfi_cleanup(SMFICTX *ctx, bool ok)
Definition:
mlfi_cleanup.c:31
CTXPRIV_T::peer_addr
char * peer_addr
Definition:
ze-filter-data.h:145
zeTime_ms
uint64_t zeTime_ms()
Definition:
zeTime.c:34
mlfi_close
sfsistat mlfi_close(SMFICTX *ctx)
Definition:
mlfi_close.c:31
raw_history_add_entry
bool raw_history_add_entry(SMFICTX *)
Definition:
ze-history.c:309
SMFIS_CONTINUE
#define SMFIS_CONTINUE
Definition:
ze-smtp-divers.c:228
tlongconn
time_t tlongconn
Definition:
ze-filter.c:93
MLFIPRIV
#define MLFIPRIV(ctx)
Definition:
ze-filter-data.h:256
STAT_CLOSE
#define STAT_CLOSE
Definition:
ze-stats.h:31
INIT_CALLBACK
#define INIT_CALLBACK(p, which)
Definition:
ze-filter.c:125
LH_LONGCONN
#define LH_LONGCONN
Definition:
ze-livehistory.h:32
LH_EMPTYCONN
#define LH_EMPTYCONN
Definition:
ze-livehistory.h:29
sm_macro_update
void sm_macro_update(SMFICTX *, sm_mac_T *)
Definition:
ze-smmacros.c:150
count_connections
int count_connections(int)
Definition:
ze-filter.c:300
LH_BADRCPT
#define LH_BADRCPT
Definition:
ze-livehistory.h:27
INIT_CALLBACK_DELAY
#define INIT_CALLBACK_DELAY()
Definition:
ze-filter.c:135
CTXPRIV_T::nb_rcpt
int nb_rcpt
Definition:
ze-filter-data.h:203
CTXPRIV_T::nb_cbadrcpt
int nb_cbadrcpt
Definition:
ze-filter-data.h:224
CTXPRIV_T::t_open
time_t t_open
Definition:
ze-filter-data.h:100
TRUE
#define TRUE
Definition:
macros.h:157
CALLBACK_CLOSE
#define CALLBACK_CLOSE
Definition:
ze-callback.h:38
CTXPRIV_T::peer_name
char * peer_name
Definition:
ze-filter-data.h:146
connopen_check_host
int connopen_check_host(char *, char *, int)
Definition:
ze-connopen.c:151
do_module_callback
bool do_module_callback(SMFICTX *ctx, int step, int *result)
Definition:
ze-mod-tools.c:84
CTXPRIV_T::sm
sm_mac_T * sm
Definition:
ze-filter-data.h:138
CHECK_CALLBACK_DELAY
#define CHECK_CALLBACK_DELAY()
Definition:
ze-filter.c:146
STRCASEEQUAL
#define STRCASEEQUAL(a, b)
Definition:
macros.h:72
livehistory_add_entry
int livehistory_add_entry(char *, time_t, int, int)
Definition:
ze-livehistory.c:253
LH_HI_SCORE
#define LH_HI_SCORE
Definition:
ze-livehistory.h:33
CTXPRIV_T
Definition:
ze-filter-data.h:76
CTXPRIV_T::t_close
time_t t_close
Definition:
ze-filter-data.h:101
src
mlfi_close.c
Generated by
1.8.13