59 lines
1.0 KiB
C++
59 lines
1.0 KiB
C++
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2012, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#ifndef headerfile_winix_core_ipbancontainer
|
|
#define headerfile_winix_core_ipbancontainer
|
|
|
|
#include <vector>
|
|
#include "ipban.h"
|
|
|
|
|
|
|
|
class IPBanContainer
|
|
{
|
|
public:
|
|
|
|
IPBanContainer();
|
|
|
|
IPBan & AddIP(int ip);
|
|
IPBan * FindIP(int ip);
|
|
void Sort();
|
|
size_t Size();
|
|
IPBan & GetIPBan(size_t index);
|
|
void SetMaxSize(size_t soft_size, size_t size);
|
|
void RemoveIP(int ip);
|
|
void Clear();
|
|
bool IsSorted();
|
|
|
|
private:
|
|
|
|
std::vector<IPBan> ipban_tab;
|
|
bool is_ipban_tab_sorted;
|
|
size_t soft_max_size, max_size;
|
|
std::vector<size_t> sort_helper_tab;
|
|
|
|
static bool SortIPBansFunction(const IPBan & ip1, const IPBan & ip2);
|
|
void RemoveOldRecords();
|
|
void PrintTab();
|
|
void PrintTab2();
|
|
|
|
struct SortByLastUsedHelper
|
|
{
|
|
IPBanContainer * container;
|
|
|
|
SortByLastUsedHelper(IPBanContainer * c) : container(c) {}
|
|
bool operator()(size_t index1, size_t index2);
|
|
};
|
|
|
|
};
|
|
|
|
|
|
#endif
|
|
|