Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Cache.h

Go to the documentation of this file.
00001 #ifndef WHOISCACHEIMPL_H
00002 #define WHOISCACHEIMPL_H
00003 #include <abuse/WhoisCache.h>
00004 #include <abuse/CriticalSection.h>
00005 #include <map>
00006 #include "MsXml.h"
00007 
00008 class File;
00009 class InternalCacheEntry;
00010 
00011 class Cache: public WhoisCache
00012 {
00013 public:
00014         Cache(const std::string& filename)throw(std::runtime_error);
00015         virtual ~Cache();
00016         virtual CacheResult get(const Url& url)const;
00017         virtual void addRir(const UrlRange& nr, const std::string& rir)throw(std::runtime_error);
00018         virtual void add(const ZeWhois::WhoisList& lst)throw(std::runtime_error);
00019         virtual void remove(const UrlRange& range);
00020         //Extended Whois Cache
00021         virtual const CacheMap& getTree()const;
00022 #ifdef _DEBUG
00023         //dumps the cache on the stdout, useful for debugging
00024         void dumpCache();
00025 #endif
00026         //save the cache index in xml format, called by the dtor
00027         void save()throw(std::runtime_error);
00028 private:
00029         //called by ctor, parse the xml index file creating the cache structure
00030         void initTree()throw(std::runtime_error);
00031         //check the version of the xml index file
00032         void checkVersion(const DocumentPtr&)throw(std::runtime_error);
00033         //called by initTree to create the cache structure, recursive
00034         //cannot be static, as it uses createEntry
00035         void recursiveBuild(const NodeListPtr& elements,CacheMap& _map)const throw(std::runtime_error);
00036         //extract from a <RANGE FROM=xxx TO=xxx> xml element a UrlRange
00037         static UrlRange getRange(const ElementPtr& el) throw(std::runtime_error);
00038         //creates an entry in the cache
00039         //cannot be static, as it needs to pass m_path to DataEntry ctor
00040         CacheEntry* createEntry(const ElementPtr& el)const throw(std::runtime_error);
00041         //find recursively an Url in the cache tree
00042         void recursiveFind(const Url& url,const CacheMap& _map,CacheResult& cr)const throw(std::runtime_error);
00043         //find a range containing (or equal to) range in _map -> const version
00044         static CacheMap::const_iterator fastfind(const UrlRange& range,const CacheMap& _map);
00045         //find a range containing (or equal to) range in _map 
00046         static CacheMap::iterator fastfind(const UrlRange& range,CacheMap& _map);
00047         //find a range containing url in _map
00048         static CacheMap::const_iterator fastfind(const Url& url,const CacheMap& _map);
00049         //called by save to convert the in memory structure to an xml file.
00050         static void recursiveSave(ElementPtr& pEl, const CacheMap& _map)throw(std::runtime_error);
00051         //called by add to insert new cache elements
00052         static void recursiveAdd(const UrlRange& range,const InternalCacheEntry* pEntry,CacheMap& _map)throw(std::runtime_error);
00053         //called by remove to delete entries having an UrlRange==range
00054         static void recursiveDelete(const UrlRange& range,CacheMap& _map);
00055         //locks the tree while we modify it
00056         void writeLock();
00057         //head of the structure, see Cache.cpp for details
00058         CacheMap m_head;
00059         //xml index filename
00060         std::string m_filename;
00061         //path to the whois cache
00062         std::string m_path;
00063         //sync object, locked while we're writing
00064         mutable CriticalSection m_mutex;
00065         //number of queries actually processed by the cache:
00066         //if m_nReads>0, the structure cannot be modified
00067         mutable int m_nReads;
00068         //flag, true if the cache has been modified (used by save())
00069         bool m_bDirty;
00070 };
00071 
00072 #endif

Generated on Thu Jun 16 00:13:24 2005 for Abuse! by  doxygen 1.4.3