|
reSIProcate/rutil
9694
|
00001 #ifndef RESIP_RRCACHE_HXX 00002 #define RESIP_RRCACHE_HXX 00003 00004 #include <map> 00005 #include <set> 00006 #include <memory> 00007 00008 #include "rutil/dns/RRFactory.hxx" 00009 #include "rutil/dns/DnsResourceRecord.hxx" 00010 #include "rutil/dns/DnsAAAARecord.hxx" 00011 #include "rutil/dns/DnsHostRecord.hxx" 00012 #include "rutil/dns/DnsNaptrRecord.hxx" 00013 #include "rutil/dns/DnsSrvRecord.hxx" 00014 #include "rutil/dns/DnsCnameRecord.hxx" 00015 #include "rutil/dns/RRList.hxx" 00016 00017 namespace resip 00018 { 00019 class RROverlay; 00020 00021 class RRCache 00022 { 00023 public: 00024 typedef RRList::Protocol Protocol; 00025 typedef RRList::LruList LruListType; 00026 typedef RRList::Records Result; 00027 typedef std::vector<RROverlay>::const_iterator Itr; 00028 typedef std::vector<Data> DataArr; 00029 00030 RRCache(); 00031 ~RRCache(); 00032 void setTTL(int ttl) { if (ttl > 0) mUserDefinedTTL = ttl * MIN_TO_SEC; } 00033 void setSize(int size) { mSize = size; } 00034 // Update existing cache record, or add a new one 00035 void updateCache(const Data& target, 00036 const int rrType, 00037 Itr begin, 00038 Itr end); 00039 void updateCacheFromHostFile(const DnsHostRecord&); 00040 // Called to update the cache when there are DNS server errors (ie. record not found) 00041 void cacheTTL(const Data& target, 00042 const int rrType, 00043 const int status, 00044 RROverlay overlay); 00045 bool lookup(const Data& target, const int type, const int proto, Result& records, int& status); 00046 void clearCache(); 00047 void logCache(); 00048 void getCacheDump(Data& dnsCacheDump); 00049 00050 private: 00051 static const int MIN_TO_SEC = 60; 00052 static const int DEFAULT_USER_DEFINED_TTL = 10; // in seconds. 00053 00054 static const int DEFAULT_SIZE = 512; 00055 class CompareT : public std::binary_function<const RRList*, const RRList*, bool> 00056 { 00057 public: 00058 bool operator()(RRList* lhs, RRList* rhs) const 00059 { 00060 if (lhs->rrType() < rhs->rrType()) 00061 { 00062 return true; 00063 } 00064 else if (lhs->rrType() > rhs->rrType()) 00065 { 00066 return false; 00067 } 00068 else 00069 { 00070 return lhs->key() < rhs->key(); 00071 } 00072 } 00073 }; 00074 00075 void touch(RRList* node); 00076 void cleanup(); 00077 int getTTL(const RROverlay& overlay); 00078 void purge(); 00079 00080 RRList mHead; 00081 LruListType* mLruHead; 00082 Result Empty; 00083 00084 typedef std::set<RRList*, CompareT> RRSet; 00085 RRSet mRRSet; 00086 00087 RRFactory<DnsHostRecord> mHostRecordFactory; 00088 RRFactory<DnsSrvRecord> mSrvRecordFactory; 00089 RRFactory<DnsAAAARecord> mAAAARecordFactory; 00090 RRFactory<DnsNaptrRecord> mNaptrRecordFacotry; 00091 RRFactory<DnsCnameRecord> mCnameRecordFactory; 00092 00093 typedef std::map<int, resip::RRFactoryBase*> FactoryMap; 00094 FactoryMap mFactoryMap; 00095 00096 int mUserDefinedTTL; // used when the ttl in RR is 0 or less than default(60). in seconds. 00097 unsigned int mSize; 00098 }; 00099 00100 } 00101 00102 #endif 00103 00104 00105 /* ==================================================================== 00106 * The Vovida Software License, Version 1.0 00107 * 00108 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00109 * Copyright (c) 2010 SIP Spectrum, Inc. All rights reserved. 00110 * 00111 * Redistribution and use in source and binary forms, with or without 00112 * modification, are permitted provided that the following conditions 00113 * are met: 00114 * 00115 * 1. Redistributions of source code must retain the above copyright 00116 * notice, this list of conditions and the following disclaimer. 00117 * 00118 * 2. Redistributions in binary form must reproduce the above copyright 00119 * notice, this list of conditions and the following disclaimer in 00120 * the documentation and/or other materials provided with the 00121 * distribution. 00122 * 00123 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00124 * and "Vovida Open Communication Application Library (VOCAL)" must 00125 * not be used to endorse or promote products derived from this 00126 * software without prior written permission. For written 00127 * permission, please contact vocal@vovida.org. 00128 * 00129 * 4. Products derived from this software may not be called "VOCAL", nor 00130 * may "VOCAL" appear in their name, without prior written 00131 * permission of Vovida Networks, Inc. 00132 * 00133 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00134 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00135 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00136 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00137 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00138 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00139 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00140 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00141 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00142 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00144 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00145 * DAMAGE. 00146 * 00147 * ==================================================================== 00148 * 00149 * This software consists of voluntary contributions made by Vovida 00150 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00151 * Inc. For more information on Vovida Networks, Inc., please see 00152 * <http://www.vovida.org/>. 00153 * 00154 */
1.7.5.1