00001 // $Id: XrdSutCache.hh 22437 2008-03-04 14:35:16Z rdm $ 00002 #ifndef __SUT_CACHE_H__ 00003 #define __SUT_CACHE_H__ 00004 /******************************************************************************/ 00005 /* */ 00006 /* X r d S u t C a c h e . h h */ 00007 /* */ 00008 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00009 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00010 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00011 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00012 /******************************************************************************/ 00013 00014 #include <XProtocol/XPtypes.hh> 00015 #include <XrdSut/XrdSutPFEntry.hh> 00016 #include <XrdOuc/XrdOucHash.hh> 00017 #include <XrdOuc/XrdOucString.hh> 00018 00019 /******************************************************************************/ 00020 /* */ 00021 /* For caching temporary information during the authentication handshake */ 00022 /* */ 00023 /******************************************************************************/ 00024 00025 class XrdSutCache 00026 { 00027 private: 00028 int cachesz; // Number of entries allocated 00029 int cachemx; // Largest Index of allocated entries 00030 XrdSutPFEntry **cachent; // Pointers to filled entries 00031 kXR_int32 utime; // time at which was last updated 00032 int lifetime; // lifetime (in secs) of the cache info 00033 XrdOucHash<kXR_int32> hashtable; // Reflects the file index structure 00034 kXR_int32 htmtime; // time at which hash table was last rebuild 00035 XrdOucString pfile; // file name (if loaded from file) 00036 00037 public: 00038 XrdSutCache() { cachemx = -1; cachesz = 0; cachent = 0; lifetime = 300; 00039 utime = -1; htmtime = -1; pfile = "";} 00040 virtual ~XrdSutCache(); 00041 00042 // Status 00043 int Entries() const { return (cachemx+1); } 00044 bool Empty() const { return (cachemx == -1); } 00045 00046 // Initialization methods 00047 int Init(int capacity = 100); 00048 int Reset(int newsz = -1); 00049 int Load(const char *pfname); // build cache of a pwd file 00050 int Flush(const char *pfname = 0); // flush content to pwd file 00051 int Refresh(); // refresh content from source file 00052 int Rehash(bool force = 0); // (re)build hash table 00053 void SetLifetime(int lifet = 300) { lifetime = lifet; } 00054 00055 // Cache management 00056 XrdSutPFEntry *Get(int i) const { return (i<=cachemx) ? cachent[i] : 00057 (XrdSutPFEntry *)0; } 00058 XrdSutPFEntry *Get(const char *ID, bool *wild = 0); 00059 XrdSutPFEntry *Add(const char *ID, bool force = 0); 00060 bool Remove(const char *ID, int opt = 1); 00061 int Trim(int lifet = 0); 00062 00063 // For debug purposes 00064 void Dump(const char *msg= 0); 00065 }; 00066 00067 #endif 00068