00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __LocalDB_hpp_
00022 #define __LocalDB_hpp_
00023 #include <map>
00024 #include <list>
00025 #include <boost/thread/shared_mutex.hpp>
00026
00027 #define LIMIT_SERVER_USER_NOT_FOUND 2
00028 #define LIMIT_SERVER_ACCESS_GRANT 3
00029 #define LIMIT_SERVER_ACCESS_DENY 4
00030
00031 #include "types.hpp"
00032 #include "hashtable.hpp"
00033
00034 class DataDB;
00035
00036 typedef std::list<std::pair<t_uid, t_traffic> > listL;
00037 typedef HashMap<t_uid, DataDB> mapL;
00038 typedef std::pair<t_uid, DataDB> pairL;
00039 typedef std::pair<t_uid, t_traffic> pairLL;
00043 class DataDB{
00044 public :
00045
00046 t_traffic traffic;
00047 t_traffic specyfic_traffic;
00048 bool always_allow;
00049 bool ban;
00050 unsigned char zone_index;
00051
00052 long long last_up;
00053 listL::iterator ptr;
00054 DataDB();
00055 DataDB(t_traffic _traffic);
00056 DataDB(const DataDB& ref)
00057 {
00058 traffic = ref.traffic;
00059 specyfic_traffic = ref.specyfic_traffic;
00060 last_up = ref.last_up;
00061 ptr = ref.ptr;
00062 }
00063 DataDB& operator=(const DataDB& ref)
00064 {
00065 if(&ref == this) return *this;
00066
00067 traffic = ref.traffic;
00068 specyfic_traffic = ref.specyfic_traffic;
00069 last_up = ref.last_up;
00070 ptr = ref.ptr;
00071 return *this;
00072 }
00073 t_traffic add(t_traffic_int size);
00074 };
00078 class LocalDB {
00079 long long pos;
00080 public:
00081 mapL *DB;
00082 listL update;
00083 boost::mutex list_mutex;
00084 long long last_up;
00085
00086 LocalDB();
00087 ~LocalDB();
00088
00089
00090
00091 void add_new_user(const t_uid& uid, t_traffic traffic = 0, t_traffic limit = 0, bool always_allow = false);
00092 void add_new_user(const t_uid& uid, t_traffic traffic, t_traffic limit, bool always_allow, bool ban);
00093 void add_new_user_no_update(const t_uid& uid, t_traffic traffic, t_traffic limit, bool always_allow, bool ban);
00094 void add_full_traffic_to_user(const t_uid& uid, const t_traffic& diff);
00095 int add_traffic_to_user(const t_uid& context, const t_uid& uid, t_traffic_int diff);
00096 t_traffic get_traffic_by_uid(const t_uid& uid);
00097 int get_access_by_uid(const t_uid& context, const t_uid& uid, t_traffic limit);
00098 int update_base();
00099 int lock_base();
00100 int unlock_base();
00101 void set_specyfic_data(const t_uid& uid, const config_entry& config);
00102 void reset_specyfic_data(const t_uid& uid);
00103 void set_data(const t_uid& uid, t_traffic traffic);
00104 int next(std::pair<t_uid, DataDB> &next);
00105 size_t size(){return DB->size(); }
00106
00107 void request_data(const t_uid& context, const t_uid& uid);
00108 void drop_outdated(int ttl);
00109 };
00110 #endif