53 #define NB_MAJOR(i) ((i) >> K_SHF) 54 #define NB_MINOR(i) (((i) >> K_SHF) & (K_MIN - 1)) 100 #define DATA_LOCK() \ 101 if (pthread_mutex_lock(&hdata.mutex) != 0) { \ 102 ZE_LogSysError("pthread_mutex_lock"); \ 105 #define DATA_UNLOCK() \ 106 if (pthread_mutex_unlock(&hdata.mutex) != 0) { \ 107 ZE_LogSysError("pthread_mutex_unlock"); \ 115 livehistory_cmp(a, b)
126 if ((ta == NULL) && (tb == NULL))
148 hdata.last = time(NULL);
149 memset(hdata.bucket, 0, sizeof (hdata.bucket));
177 select_function(vp, arg)
185 tnow = (time_t *) arg;
198 if (p->
update + 3600 > now)
201 for (i = 0; i <
K_MIN; i++) {
202 if (p->
bucket[i].
t + K_MIN >= tr)
216 time_t now = time(NULL);
218 if (!livehistory_init())
229 if (
zeBTree_Cpy(&tmp, &hdata.db_empty, select_function, (
void *) &now)) {
231 hdata.db_empty = tmp;
267 if (now == (time_t) 0)
273 if (!livehistory_init())
276 if (what < 0 || what >=
LH_MAX)
284 memset(&p, 0,
sizeof (p));
297 for (i = 0; i <
K_MIN; i++) {
298 if (ptr->
bucket[i].
t + K_MIN >= tr)
302 memset(&p, 0,
sizeof (p));
316 if (hdata.bucket[ti].t != tr) {
317 memset(&hdata.bucket[ti], 0, sizeof (hdata.bucket[ti]));
318 hdata.bucket[ti].t = tr;
321 hdata.bucket[ti].count[what] += n;
345 time_t now = time(NULL);
359 if (!livehistory_init())
362 if (what < 0 || what >=
LH_MAX)
370 memset(&p, 0,
sizeof (p));
371 strlcpy(p.ip, ip, sizeof (p.ip));
376 for (i = 0; i <
K_MIN; i++) {
377 if (ptr->
bucket[i].
t + K_MIN >= tr)
408 log_rec(
void *data,
void *arg)
411 time_t now = time(NULL);
434 memset(count, 0,
sizeof (count));
435 for (i = 0; i <
K_MIN; i++) {
436 if (p->
bucket[i].
t + K_MIN >= tr) {
437 for (j = 0; j <
LH_MAX; j++) {
443 for (j = 0; j <
LH_MAX; j++)
448 char *s =
"", nodename[128];
451 for (j = 1; j <
LH_MAX; j++)
474 time_t now = time(NULL);
479 if (!livehistory_init())
487 memset(&results, 0,
sizeof (results));
495 FD_PRINTF(fd,
"*** LIVE HISTORY %s\n", buf);
496 FD_PRINTF(fd,
" %-17s : %s\n",
"HOST IP",
497 "..BADRCPT .SPAMTRAP EMPTYCONN EMPTYMSGS ....BADMX .LONGCONN");
509 for (i = 1; i <
LH_MAX; i++)
513 "..BADRCPT .SPAMTRAP EMPTYCONN EMPTYMSGS ....BADMX .LONGCONN");
520 FD_PRINTF(fd,
"\n %d/%d entries on database\n", nb, nbt);
void livehistory_log_table(int fd, bool resolve)
struct Bucket_T bucket[K_MIN]
#define CACHE_GETHOSTNAMEBYADDR(ip, name, size, query)
void * zeBTree_Get(ZEBT_T *, void *)
bool zeBTree_Init(ZEBT_T *, size_t, ZEBT_CMP_F)
bool livehistory_clean_table()
int livehistory_add_entry(char *ip, time_t now, int n, int what)
int livehistory_check_host(char *ip, time_t win, int what)
bool zeBTree_Add(ZEBT_T *, void *)
#define ZE_LogMsgError(level,...)
struct Bucket_T bucket[K_MIN]
int ip_strcmp(char *, char *)
bool zeBTree_Destroy(ZEBT_T *)
#define FD_PRINTF(fdp,...)
int zeBTree_Count(ZEBT_T *)
char * zeStrSet(char *, int, int)
bool zeBTree_Cpy(ZEBT_T *, ZEBT_T *, ZEBT_SEL_F, void *)
struct ShortHist_T ShortHist_T
int zeBTree_Browse(ZEBT_T *, ZEBT_BROWSE_F, void *)