|
|
|
@ -8,16 +8,36 @@
|
|
|
|
|
#define F2B_MATCHES_H_ |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
size_t hits; |
|
|
|
|
size_t max; |
|
|
|
|
size_t used; |
|
|
|
|
time_t *times; |
|
|
|
|
size_t hits; /**< how many times this ip matched by filter */ |
|
|
|
|
size_t max; /**< max matches that this in struct can contain */ |
|
|
|
|
size_t used; /**< currently used matches count */ |
|
|
|
|
time_t *times; /**< dynamic unix timestamps array */ |
|
|
|
|
} f2b_matches_t; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Init matches struct, allocate memory for @a hits |
|
|
|
|
* @param m Pointer to struct |
|
|
|
|
* @param max Max expected matches count |
|
|
|
|
* @returns true on success, false otherwise |
|
|
|
|
*/ |
|
|
|
|
bool f2b_matches_create (f2b_matches_t *m, size_t max); |
|
|
|
|
/**
|
|
|
|
|
* @brief Destroy matches struct and free memory |
|
|
|
|
* @param m Pointer to struct |
|
|
|
|
*/ |
|
|
|
|
void f2b_matches_destroy(f2b_matches_t *m); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Push new match time to struct |
|
|
|
|
* @param m Pointer to struct |
|
|
|
|
* @param t Match time |
|
|
|
|
* @returns true on success, false if capacity exceeded |
|
|
|
|
*/ |
|
|
|
|
bool f2b_matches_append (f2b_matches_t *m, time_t t); |
|
|
|
|
/**
|
|
|
|
|
* @brief Remove matches before given time |
|
|
|
|
* @param m Pointer to struct |
|
|
|
|
* @param t Start time |
|
|
|
|
*/ |
|
|
|
|
void f2b_matches_expire (f2b_matches_t *m, time_t t); |
|
|
|
|
|
|
|
|
|
#endif /* F2B_MATCHES_H_ */ |
|
|
|
|