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.

170 lines
5.0 KiB

  1. /*
  2. * _ F S R I . H
  3. *
  4. * Resource information helper class
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #ifndef __FSRI_H_
  9. #define __FSRI_H_
  10. /*
  11. * CResourceInfo -------------------------------------------------------------
  12. *
  13. * The CResourceInfo object is intended to function as an abstraction
  14. * to the file information available to the impl. Namely, it should
  15. * be used in such a way that file information calls to the Win32 kernel
  16. * are kept to a minimum -- the ideal is once and only once.
  17. *
  18. * The other issue is the efficiency of how this information is obtained.
  19. * So if I need to know the attributes of a file, then I do not want to
  20. * have to make a call to FindFirstFile()/CloseFind() just to get the
  21. * attributes. This is a tremendously expensive method for doing so.
  22. * However, there are times that information beyond the information
  23. * returned by GetFileAttributesEx() is desired, and in those instances,
  24. * a more expensive mechanism should be employed to get that data.
  25. *
  26. * Regardless of how the data was obtained, the caller wants unified
  27. * access to the information. This helper class provides that.
  28. *
  29. * The object itself knows how the file information held there was
  30. * obtained. So to access the file information, the caller calls the
  31. * accessor to obtain the values. The accessors switch off of the mode
  32. * indicator that describes how the information was filled in.
  33. *
  34. */
  35. class CResourceInfo
  36. {
  37. enum { NODATA, BY_ATTRIBUTE, BY_FIND };
  38. UINT m_lmode;
  39. union {
  40. WIN32_FILE_ATTRIBUTE_DATA ad;
  41. WIN32_FIND_DATAW fd;
  42. } m_u;
  43. public:
  44. CResourceInfo()
  45. : m_lmode(NODATA)
  46. {
  47. memset(&m_u, 0, sizeof(m_u));
  48. }
  49. // Resource information initialization
  50. //
  51. SCODE ScGetResourceInfo (LPCWSTR pwszFile);
  52. BOOL FLoaded() { return m_lmode != NODATA; }
  53. // Data access
  54. //
  55. DWORD DwAttributes() const
  56. {
  57. Assert (m_lmode != NODATA);
  58. return (m_lmode == BY_ATTRIBUTE)
  59. ? m_u.ad.dwFileAttributes
  60. : m_u.fd.dwFileAttributes;
  61. }
  62. BOOL FCollection() const
  63. {
  64. return !!(DwAttributes() & FILE_ATTRIBUTE_DIRECTORY);
  65. }
  66. BOOL FHidden() const
  67. {
  68. return !!(DwAttributes() & FILE_ATTRIBUTE_HIDDEN);
  69. }
  70. BOOL FRemote() const
  71. {
  72. return !!(DwAttributes() & FILE_ATTRIBUTE_OFFLINE);
  73. }
  74. FILETIME * PftCreation()
  75. {
  76. Assert (m_lmode != NODATA);
  77. return (m_lmode == BY_ATTRIBUTE)
  78. ? &m_u.ad.ftCreationTime
  79. : &m_u.fd.ftCreationTime;
  80. }
  81. FILETIME * PftLastModified()
  82. {
  83. Assert (m_lmode != NODATA);
  84. return (m_lmode == BY_ATTRIBUTE)
  85. ? &m_u.ad.ftLastWriteTime
  86. : &m_u.fd.ftLastWriteTime;
  87. }
  88. void FileSize (LARGE_INTEGER& li)
  89. {
  90. Assert (m_lmode != NODATA);
  91. if (m_lmode == BY_ATTRIBUTE)
  92. {
  93. li.LowPart = m_u.ad.nFileSizeLow;
  94. li.HighPart = m_u.ad.nFileSizeHigh;
  95. }
  96. else
  97. {
  98. li.LowPart = m_u.fd.nFileSizeLow;
  99. li.HighPart = m_u.fd.nFileSizeHigh;
  100. }
  101. }
  102. WIN32_FIND_DATAW * PfdLoad()
  103. {
  104. m_lmode = BY_FIND;
  105. return &m_u.fd;
  106. }
  107. WIN32_FIND_DATAW& Fd()
  108. {
  109. Assert (m_lmode == BY_FIND);
  110. return m_u.fd;
  111. }
  112. BOOL FFindData() const { return (m_lmode == BY_FIND); }
  113. void Reset() { m_lmode = NODATA; }
  114. };
  115. /* Resource locations --------------------------------------------------------
  116. *
  117. * DAVFS allows for the client to be somewhat lax in its url's when
  118. * specifying a resource. Namely, if the caller specifies a resource
  119. * that is a collection, and the url does not end in a trailing slash,
  120. * in most cases we will simply go ahead and succeed the call while
  121. * making sure that we return the properly qualified url in the location
  122. * header. The FTrailingSlash() and the ScCheckForLocationCorrectness()
  123. * methods provide for this lax checking.
  124. *
  125. * FTrailingSlash() simply returns TRUE if (and only if) the url ends in
  126. * a trailing slash.
  127. *
  128. * ScCheckForLocationCorrectness() will check the url against the
  129. * resource and either add the appropriate location header, or it will
  130. * request a redirect if the url and the resource do not agree. The
  131. * caller has the control over whether or not a true redirect is desired.
  132. * As an informational return, if a location header has been added S_FALSE
  133. * will be returned to the caller.
  134. */
  135. enum { NO_REDIRECT = FALSE, REDIRECT = TRUE };
  136. inline BOOL FTrailingSlash (LPCWSTR pwsz)
  137. {
  138. Assert (pwsz);
  139. UINT cch = static_cast<UINT>(wcslen (pwsz));
  140. return ((0 != cch) && (L'/' == pwsz[cch - 1]));
  141. }
  142. SCODE ScCheckForLocationCorrectness (IMethUtil*,
  143. CResourceInfo&,
  144. UINT mode = NO_REDIRECT);
  145. /*
  146. * If-xxx header helper functions --------------------------------------------
  147. *
  148. * The current ScCheckIfHeaders() implementation in the common code
  149. * takes the last modified time of the resource as the second parameter.
  150. * This version helper function takes the actual path to the resource.
  151. * It is implemented by getting the resource information for the file
  152. * and then calling the common implementation of ScCheckIfHeaders().
  153. */
  154. SCODE ScCheckIfHeaders (IMethUtil* pmu, LPCWSTR pwszPath, BOOL fGetMethod);
  155. #endif // __FSRI_H_