| 1 |
// DynamicIPList - maintains a sorted list of IP addresses, for checking & |
| 2 |
// limiting the number of concurrent proxy users. |
| 3 |
|
| 4 |
// For all support, instructions and copyright go to: |
| 5 |
// http://e2guardian.org/ |
| 6 |
// Released under the GPL v2, with the OpenSSL exception described in the README file. |
| 7 |
|
| 8 |
#ifndef __HPP_DYNAMICIPLIST |
| 9 |
#define __HPP_DYNAMICIPLIST |
| 10 |
|
| 11 |
// DECLARATIONS |
| 12 |
|
| 13 |
class DynamicIPList |
| 14 |
{ |
| 15 |
public: |
| 16 |
DynamicIPList(int maxitems, int maxitemage); |
| 17 |
~DynamicIPList(); |
| 18 |
|
| 19 |
#ifdef DEBUG_LOW |
| 20 |
int getListSize() |
| 21 |
{ |
| 22 |
return size; |
| 23 |
}; |
| 24 |
#endif |
| 25 |
int getNumberOfItems() |
| 26 |
{ |
| 27 |
return items; |
| 28 |
}; |
| 29 |
|
| 30 |
// return whether or not given IP is in/could be added to list |
| 31 |
// (i.e. returns false if list already full & this IP's not in it) |
| 32 |
bool inList(unsigned long int ip); |
| 33 |
|
| 34 |
// remove entries older than maxage |
| 35 |
void purgeOldEntries(); |
| 36 |
|
| 37 |
private: |
| 38 |
// IPs and their ages |
| 39 |
unsigned long int *data; |
| 40 |
unsigned long int *datatime; |
| 41 |
|
| 42 |
// list size; no. of items currently in list; max. allowed item age |
| 43 |
int size; |
| 44 |
int items; |
| 45 |
int maxage; |
| 46 |
|
| 47 |
void stamp(unsigned int pos); |
| 48 |
|
| 49 |
// binary search for given ip |
| 50 |
int search(int a, int s, unsigned long int ip); |
| 51 |
|
| 52 |
// compacts list removing blanks |
| 53 |
void empties(); |
| 54 |
|
| 55 |
// returns position of given IP in list, or (0-pos)-1 where pos is where |
| 56 |
// IP should be inserted to retain sorting. |
| 57 |
int posInList(unsigned long int ip); |
| 58 |
}; |
| 59 |
|
| 60 |
#endif |