-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoffEntry.h
126 lines (104 loc) · 3.87 KB
/
offEntry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/***************************************************************************
* Copyright (C) 2019 by John D. Robertson *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OFFENTRY_H
#define OFFENTRY_H
#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#include <zlib.h>
#include "map.h"
#include "pdns.h"
/* One of these for each offense found in a log file */
typedef struct _OFFENTRY {
unsigned count,
severity;
time_t latest;
char addr[46],
cntry[3];
/* This data populated by PDNS_lookup() */
struct {
enum PDNS_flags flags;
char *name;
} dns;
} OFFENTRY;
#if 0
struct OFFENTRY_cacheWrite {
FILE *fh;
DB *dbh;
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define OFFENTRY_addr_create(p, addr) \
((p)=(OFFENTRY_addr_constructor((p)=malloc(sizeof(OFFENTRY)), addr) ? (p) : ( p ? realloc(OFFENTRY_destructor(p),0) : 0 )))
OFFENTRY*
OFFENTRY_addr_constructor(OFFENTRY *self, const char *addr);
/********************************************************
* Prepare for use from an address found in a log entry.
*/
#define OFFENTRY_cache_create(p, cacheFileEntry) \
((p)=(OFFENTRY_cache_constructor((p)=malloc(sizeof(OFFENTRY)), cacheFileEntry) ? (p) : ( p ? realloc(OFFENTRY_destructor(p),0) : 0 )))
OFFENTRY*
OFFENTRY_cache_constructor(OFFENTRY *self, const char *cacheFileEntry);
/********************************************************
* Prepare for use with entry from cache file.
*/
#define OFFENTRY_destroy(s) \
{if(OFFENTRY_destructor(s)) {free(s); (s)=0;}}
void*
OFFENTRY_destructor(OFFENTRY *self);
/********************************************************
* Free resources.
*/
void
OFFENTRY_register(OFFENTRY *self, unsigned severity, time_t when);
/********************************************************
* Register the current failure try.
*/
int
OFFENTRY_cacheWrite(OFFENTRY *self, FILE *fh);
/********************************************************
* Write to the cache file in a form we can read later.
*/
int
OFFENTRY_print(OFFENTRY *self, FILE *fh);
/********************************************************
* Print a human readable representation of *self.
*/
int
OFFENTRY_list(OFFENTRY *self, FILE *fh, int flags, unsigned nAllowed);
/********************************************************
* Print in listing form
*/
int
OFFENTRY_map_addr(OFFENTRY *self, MAP *h_rtnMap);
/********************************************************
* Create a map of OFFENTRY objects with composite
* counts by address.
*/
int
OFFENTRY_offenseCount(OFFENTRY *self, unsigned *h_sum);
/********************************************************
* Get a count of all offenses for this entry.
*/
#ifdef __cplusplus
}
#endif
#endif