Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #ifndef __P_CACHE_HOSTING_H__
00025 #define __P_CACHE_HOSTING_H__
00026 #include "P_Cache.h"
00027 
00028 #define CACHE_MEM_FREE_TIMEOUT     HRTIME_SECONDS(1)
00029 
00030 struct Vol;
00031 struct CacheVol;
00032 
00033 struct CacheHostResult;
00034 struct Cache;
00035 
00036 struct CacheHostRecord
00037 {
00038   int Init(CacheType typ);
00039   int Init(matcher_line *line_info, CacheType typ);
00040   void UpdateMatch(CacheHostResult *r, char *rd);
00041   void Print();
00042   ~CacheHostRecord()
00043   {
00044     ats_free(vols);
00045     ats_free(vol_hash_table);
00046     ats_free(cp);
00047   }
00048 
00049   CacheType type;
00050   Vol **vols;
00051   volatile int good_num_vols;
00052   volatile int num_vols;
00053   int num_initialized;
00054   unsigned short *vol_hash_table;
00055   CacheVol **cp;
00056   int num_cachevols;
00057 
00058   CacheHostRecord():
00059     type(CACHE_NONE_TYPE), vols(NULL), good_num_vols(0), num_vols(0),
00060     num_initialized(0), vol_hash_table(0), cp(NULL), num_cachevols(0)
00061   { }
00062 
00063 };
00064 
00065 void build_vol_hash_table(CacheHostRecord *cp);
00066 
00067 struct CacheHostResult
00068 {
00069   CacheHostRecord *record;
00070 
00071   CacheHostResult()
00072     : record(NULL)
00073   { }
00074 };
00075 
00076 
00077 class CacheHostMatcher
00078 {
00079 public:
00080   CacheHostMatcher(const char * name, CacheType typ);
00081   ~CacheHostMatcher();
00082 
00083   void Match(char const* rdata, int rlen, CacheHostResult *result);
00084   void AllocateSpace(int num_entries);
00085   void NewEntry(matcher_line *line_info);
00086   void Print();
00087 
00088   int getNumElements() const { return num_el; }
00089   CacheHostRecord *getDataArray() const { return data_array; }
00090   HostLookup *getHLookup() const { return host_lookup; }
00091 
00092 private:
00093   static void PrintFunc(void *opaque_data);
00094   HostLookup *host_lookup;      
00095   CacheHostRecord *data_array;  
00096   int array_len;                
00097   int num_el;                   
00098   CacheType type;
00099 };
00100 
00101 class CacheHostTable
00102 {
00103 public:
00104   
00105   
00106   CacheHostTable(Cache *c, CacheType typ);
00107    ~CacheHostTable();
00108   int BuildTable(const char * config_file_path);
00109   int BuildTableFromString(const char * config_file_path, char *str);
00110   void Match(char const* rdata, int rlen, CacheHostResult *result);
00111   void Print();
00112 
00113   int getEntryCount() const { return m_numEntries; }
00114   CacheHostMatcher *getHostMatcher() const { return hostMatch; }
00115 
00116   static int config_callback(const char *, RecDataT, RecData, void *);
00117 
00118   void register_config_callback(CacheHostTable ** p)
00119   {
00120     REC_RegisterConfigUpdateFunc("proxy.config.cache.hosting_filename", CacheHostTable::config_callback, (void *) p);
00121   }
00122 
00123   CacheType type;
00124   Cache *cache;
00125   int m_numEntries;
00126   CacheHostRecord gen_host_rec;
00127 
00128 private:
00129   CacheHostMatcher *hostMatch;
00130   const matcher_tags *config_tags;
00131   const char *matcher_name;     
00132 };
00133 
00134 struct CacheHostTableConfig;
00135 typedef int (CacheHostTableConfig::*CacheHostTabHandler) (int, void *);
00136 struct CacheHostTableConfig: public Continuation
00137 {
00138   CacheHostTable **ppt;
00139   CacheHostTableConfig(CacheHostTable ** appt)
00140     : Continuation(NULL), ppt(appt)
00141   {
00142     SET_HANDLER((CacheHostTabHandler) & CacheHostTableConfig::mainEvent);
00143   }
00144 
00145   int mainEvent(int event, Event *e)
00146   {
00147     (void) e;
00148     (void) event;
00149     CacheHostTable *t = new CacheHostTable((*ppt)->cache, (*ppt)->type);
00150     CacheHostTable *old = (CacheHostTable *) ink_atomic_swap(&t, *ppt);
00151     new_Deleter(old, CACHE_MEM_FREE_TIMEOUT);
00152     return EVENT_DONE;
00153   }
00154 };
00155 
00156 
00157 
00158 struct ConfigVol
00159 {
00160   int number;
00161   CacheType scheme;
00162   off_t size;
00163   bool in_percent;
00164   int percent;
00165   CacheVol *cachep;
00166   LINK(ConfigVol, link);
00167 };
00168 
00169 struct ConfigVolumes
00170 {
00171   int num_volumes;
00172   int num_http_volumes;
00173   int num_stream_volumes;
00174   Queue<ConfigVol> cp_queue;
00175   void read_config_file();
00176   void BuildListFromString(char *config_file_path, char *file_buf);
00177 
00178   void clear_all(void)
00179   {
00180     
00181     for (int i = 0; i < num_volumes; i++) {
00182       cp_queue.pop();
00183     }
00184     
00185     num_volumes = 0;
00186     num_http_volumes = 0;
00187     num_stream_volumes = 0;
00188   }
00189 };
00190 
00191 #endif