1: 
   2: 
   3: /*************
   4: *            *
   5: *  SENTINEL  *
   6: *            *
   7: *************/
   8: 
   9: 
  10: #ifndef WWWI_MIND_RRCACHE_H 
  11: #define WWWI_MIND_RRCACHE_H 
  12: 
  13: 
  14: /**********************
  15: *                     *
  16: *  COMPILER INCLUDES  *
  17: *                     *
  18: **********************/
  19: 
  20: 
  21: #include <map> 
  22: 
  23: 
  24: /*********************
  25: *                    *
  26: *  PROJECT INCLUDES  *
  27: *                    *
  28: *********************/
  29: 
  30: 
  31: #include "labellist.h" 
  32: #include "request.h" 
  33: #include "response.h" 
  34: #include "rrlist.h" 
  35: #include "wwwi/mutex.h" 
  36: #include "wwwi/rwlock.h" 
  37: 
  38: 
  39: using std::map;
  40: using WWWI::Mutex;
  41: using WWWI::RWLock;
  42: 
  43: 
  44: /**********************
  45: *                     *
  46: *  TYPE DECLARATIONS  *
  47: *                     *
  48: **********************/
  49: 
  50: 
  51: class CacheNode {
  52: public:
  53:   CacheNode() { cspEntries = new CacheRRList; }
  54:   unsigned Expire(time_t i_tmNow, time_t &io_tmrNextExpire);
  55:   void Walk(ostream &io_smr, int iDepth) const;
  56:   ~CacheNode();
  57: 
  58:   friend class RRCache;
  59: 
  60: protected:
  61:   CacheRRListPtr        cspEntries;
  62:   map<Label,CacheNode*> cmTree;
  63: 
  64: };
  65: typedef CacheNode* CacheNodePtr;
  66: typedef map<Label,CacheNode*> CacheMap;
  67: typedef CacheMap *CacheMapPtr;
  68: typedef const CacheMap *CacheMapConstPtr;
  69: 
  70: 
  71: /******************
  72: *                 *
  73: *  CLASS RRCACHE  *
  74: *                 *
  75: ******************/
  76: 
  77: 
  78: class RRCache {
  79: public:
  80:                       RRCache(void);
  81:   void                Add(ResponseConstPtr ci_rsp);
  82:   bool                Add(RRConstPtr ci_rrp);
  83:   void                Add(RRListConstPtr ci_rlp);
  84:   bool                AddRecord(const char *i_strName, RRType i_ty, RRClass i_cl, unsigned i_uTTL, const char *i_strRData);
  85:   bool                AddRecord(LabelListConstPtr i_llpName, RRType i_ty, RRClass i_cl, unsigned i_uTTL, const char *ci_strRData);
  86:   void                AddRootServer(const char *i_strName, const char *ci_strIP);
  87:   void                Expire(void);
  88:   inline ResponsePtr  Get(QuestionConstPtr ci_qnp);
  89:   inline ResponsePtr  Get(const char *ci_strName, RRType i_ty, RRClass i_cl);
  90:   ResponsePtr         Get(LabelListConstPtr ci_llpName, RRType i_ty, RRClass i_cl);
  91:   RRListPtr           GetAR(RRListPtr i_rlp);
  92:   void                GetAR(RRListPtr o_rlp, RRPtr i_rrp);
  93:   RRListPtr           GetBestAuthority(LabelListConstPtr ci_llp) const;
  94:   RRListPtr           GetNS(RRListPtr i_rlp) const;
  95:   inline RRListPtr    GetSimple(const char *i_strName, RRType i_ty, RRClass i_cl);
  96:   RRListPtr           GetSimple(LabelListConstPtr i_llpName, RRType i_ty, RRClass i_cl);
  97:   inline void         SetMaxEntries(unsigned i_uMaxEntries);
  98:   inline void         SetNextExpire(time_t i_tmWhenExpire);
  99:   inline bool         ShouldExpire(void) const;
 100:   void                Walk(ostream &io_smr) const;
 101:                      ~RRCache(void);
 102: 
 103: protected:
 104:   bool                Add(CacheRRListPtr io_csp, CacheRRPtr &i_crpr);
 105:   CacheRRListPtr      GetNameList(LabelListConstPtr i_llpName, bool i_bCreate);
 106:   CacheRRListConstPtr GetNameList(LabelListPtr o_llpMatch, LabelListConstPtr i_llpName, RRType i_ty, RRClass i_cl, bool i_bBest) const;
 107:   void                GetNS(RRListPtr o_rlp, LabelListConstPtr i_llpName) const;
 108: 
 109: protected:
 110:   CacheNode      m_cn;
 111:   mutable RWLock m_rw;
 112:   unsigned       m_uEntries;
 113:   unsigned       m_uMaxEntries;
 114:   time_t         m_tmNextExpire;
 115:   mutable Mutex  m_mxExpire;
 116: };
 117: typedef RRCache* RRCachePtr;
 118: 
 119: 
 120: /*********************
 121: *                    *
 122: *  INLINE FUNCTIONS  *
 123: *                    *
 124: *********************/
 125: 
 126: 
 127: #include "rrcache.i" 
 128: 
 129: 
 130: /************
 131: *           *
 132: *  THE END  *
 133: *           *
 134: ************/
 135: 
 136: 
 137: #endif 
 138: 
 139: 
 140: 
 141: 
 142: