Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

331 lines
6.0 KiB

  1. /*++
  2. Copyright (C) 2001 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. NCnamecache.hxx
  6. Abstract:
  7. DEclaration of classes that build the name resolution cache.
  8. Author:
  9. Felix Maxa (AMaxa) 16 May 2001
  10. Revision History:
  11. --*/
  12. #ifndef _NCNAMECACHE_HXX_
  13. #define _NCNAMECACHE_HXX_
  14. enum
  15. {
  16. kTTLinNameCache = 120000, // 2 minutes
  17. kTTLinFailedCache = 60000, // 1 minute
  18. kFailedCacheSize = 10, // 10 entries in the cache
  19. kFailedCacheMaxStrLen = INTERNET_MAX_HOST_NAME_LENGTH
  20. };
  21. class TFastCacheElement
  22. {
  23. public:
  24. TFastCacheElement(
  25. VOID
  26. );
  27. ~TFastCacheElement(
  28. VOID
  29. );
  30. HRESULT
  31. UpdateElement(
  32. IN PCSTR pszString
  33. );
  34. PSTR m_pszString;
  35. DWORD m_TimeStamp;
  36. private:
  37. //
  38. // Copying and assignment are not defined.
  39. //
  40. NO_COPY(TFastCacheElement);
  41. };
  42. class TFastCache
  43. {
  44. public:
  45. TFastCache(
  46. IN DWORD TimeToLive = kTTLinFailedCache,
  47. IN DWORD Cachesize = kFailedCacheSize,
  48. IN DWORD MaxStrLen = kFailedCacheMaxStrLen
  49. );
  50. ~TFastCache(
  51. VOID
  52. );
  53. HRESULT
  54. IsValid(
  55. VOID
  56. );
  57. HRESULT
  58. IsStringInCache(
  59. IN PCSTR pszString
  60. );
  61. HRESULT
  62. AddString(
  63. IN PCSTR pszString
  64. );
  65. private:
  66. //
  67. // Copying and assignment are not defined.
  68. //
  69. NO_COPY(TFastCache);
  70. HRESULT m_hr;
  71. DWORD m_ArraySize;
  72. DWORD m_CurrentCount;
  73. DWORD m_TTL;
  74. DWORD m_MaxStrLen;
  75. TFastCacheElement *m_pArray;
  76. NCoreLibrary::TCriticalSection m_Lock;
  77. };
  78. //
  79. // Forward declarations
  80. //
  81. class TResolutionCacheNode;
  82. class TStringNode : public NCoreLibrary::TLink
  83. {
  84. SIGNATURE('TSNO');
  85. public:
  86. friend class TResolutionCacheNode;
  87. friend class TNameResolutionCache;
  88. TStringNode(
  89. IN LPCWSTR pszString
  90. );
  91. ~TStringNode(
  92. VOID
  93. );
  94. VOID
  95. RefreshTimeStamp(
  96. VOID
  97. );
  98. HRESULT
  99. Valid(
  100. VOID
  101. ) const;
  102. private:
  103. //
  104. // Copying and assignment are not defined.
  105. //
  106. NO_COPY(TStringNode);
  107. TString m_String;
  108. DWORD m_Time;
  109. HRESULT m_hr;
  110. };
  111. class TResolutionCacheNode : public NCoreLibrary::TLink
  112. {
  113. SIGNATURE('RCNO');
  114. public:
  115. friend class TNameResolutionCache;
  116. TResolutionCacheNode(
  117. IN LPCWSTR pszName,
  118. IN BOOL bClusterNode
  119. );
  120. ~TResolutionCacheNode(
  121. VOID
  122. );
  123. HRESULT
  124. Valid(
  125. VOID
  126. ) const;
  127. HRESULT
  128. IsSameName(
  129. IN LPCWSTR pszName
  130. );
  131. HRESULT
  132. IsNameInNodeCache(
  133. IN LPCWSTR pszName
  134. );
  135. HRESULT
  136. GetStringNodeFromName(
  137. IN LPCWSTR pszName,
  138. OUT TStringNode **pStringNode
  139. );
  140. private:
  141. //
  142. // Copying and assignment are not defined.
  143. //
  144. NO_COPY(TResolutionCacheNode);
  145. TString m_Name;
  146. BOOL m_bClusterNode;
  147. NCoreLibrary::TList<TStringNode> *m_pIPAddresses;
  148. NCoreLibrary::TList<TStringNode> *m_pAlternateNames;
  149. HRESULT m_hr;
  150. };
  151. class TNameResolutionCache
  152. {
  153. SIGNATURE('NRCH');
  154. public:
  155. TNameResolutionCache(
  156. IN DWORD AgingTime = kTTLinNameCache
  157. );
  158. ~TNameResolutionCache(
  159. VOID
  160. );
  161. HRESULT
  162. AddName(
  163. IN LPCWSTR pszName
  164. );
  165. HRESULT
  166. CreateAndAddNode(
  167. IN LPCWSTR pszName,
  168. IN BOOL bClusterNode
  169. );
  170. HRESULT
  171. CreateAndAddNodeWithIPAddresses(
  172. IN LPCWSTR pszName,
  173. IN BOOL bClusterNode,
  174. IN LPCWSTR *ppszIPAddresses,
  175. IN DWORD cIPAddresses
  176. );
  177. HRESULT
  178. DeleteNode(
  179. IN LPCWSTR pszNode
  180. );
  181. HRESULT
  182. RefreshNode(
  183. IN LPCWSTR pszName
  184. );
  185. HRESULT
  186. IsNameInNodeCache(
  187. IN LPCWSTR pszNode,
  188. IN LPCWSTR pszName
  189. );
  190. HRESULT
  191. IsNameInCache(
  192. IN LPCWSTR pszName
  193. );
  194. HRESULT
  195. IsNodeInCache(
  196. IN LPCWSTR pszNode
  197. );
  198. HRESULT
  199. Purge(
  200. VOID
  201. );
  202. HRESULT
  203. IsValid(
  204. VOID
  205. );
  206. private:
  207. HRESULT
  208. AddNetBiosName(
  209. IN LPCWSTR pszNode,
  210. IN LPCWSTR pszAlias
  211. );
  212. HRESULT
  213. AddNameUsingIPList(
  214. IN LPCWSTR pszAdditionalName,
  215. IN NCoreLibrary::TList<TStringNode>& pIPAddresses
  216. );
  217. HRESULT
  218. FindNameInCacheAndAgeOut(
  219. IN LPCWSTR pszName
  220. );
  221. HRESULT
  222. ResolveNameToAddress(
  223. IN LPCSTR pszName,
  224. IN NCoreLibrary::TList<TStringNode> *pAddresses,
  225. IN NCoreLibrary::TList<TStringNode> *pNames
  226. );
  227. static
  228. HRESULT
  229. GetAddrInfo(
  230. IN LPCSTR pszName,
  231. IN NCoreLibrary::TList<TStringNode> *pIPAddresses,
  232. IN NCoreLibrary::TList<TStringNode> *pAlternateNames
  233. );
  234. static
  235. HRESULT
  236. GetNetBiosInfo(
  237. IN LPCSTR pszName,
  238. IN TString *pAliasedServer
  239. );
  240. static
  241. HRESULT
  242. ExcludeIPsUsedByCluster(
  243. IN NCoreLibrary::TList<TStringNode> *pClusterIPs,
  244. IN NCoreLibrary::TList<TStringNode> *pList
  245. );
  246. //
  247. // Copying and assignment are not defined.
  248. //
  249. NO_COPY(TNameResolutionCache);
  250. NCoreLibrary::TList<TResolutionCacheNode> m_NodeList;
  251. NCoreLibrary::TCriticalSection m_Lock;
  252. DWORD m_AgingTime;
  253. TFastCache m_FailedCache;
  254. };
  255. #endif // _NCNAMECACHE_HXX_