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.

196 lines
6.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: gibralt.cxx
  7. //
  8. // Contents: Abstraction of the interface to gibraltar
  9. //
  10. // History: 96/Jan/3 DwightKr Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <gibralt.hxx>
  16. #include <cgiesc.hxx>
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Member: CWebServer::GetPhysicalPath - public
  20. //
  21. // Synopsis: Converts a virtual path to a physical path
  22. //
  23. // Arguments: [wcsVirtualPath] - virtual path to convert
  24. // [wcsPhysicalPath] - resulting physical path
  25. // [cwcPhysicalPath] - length of string
  26. // [dwAccessMask] - HSE_URL_FLAGS_* required,
  27. // or 0 for any access
  28. //
  29. // Returns: Flags for the virtual path (HSE_URL_FLAGS_*)
  30. //
  31. // History: 96/Feb/29 DwightKr Created.
  32. //
  33. //----------------------------------------------------------------------------
  34. DWORD CWebServer::GetPhysicalPath(
  35. WCHAR const * wcsVirtualPath,
  36. WCHAR * wcsPhysicalPath,
  37. ULONG cwcPhysicalPath,
  38. DWORD dwAccessMask )
  39. {
  40. Win4Assert( 0 != wcsVirtualPath );
  41. ULONG cwcVirtualPath = wcslen( wcsVirtualPath ) + 1;
  42. //
  43. // We only support paths up to MAX_PATH for now
  44. //
  45. if ( cwcVirtualPath >= ( MAX_PATH - 1 ) )
  46. THROW( CException( QUTIL_E_CANT_CONVERT_VROOT ) );
  47. CHAR pszVirtualPath[_MAX_PATH];
  48. ULONG cbVirtualPath = _MAX_PATH;
  49. ULONG cbConverted = ::WideCharToMultiByte( _codePage,
  50. WC_COMPOSITECHECK,
  51. wcsVirtualPath,
  52. cwcVirtualPath,
  53. (CHAR *) pszVirtualPath,
  54. cbVirtualPath,
  55. NULL,
  56. NULL );
  57. HSE_URL_MAPEX_INFO MapInfo;
  58. DWORD cbMappedPath = sizeof pszVirtualPath;
  59. //
  60. // Note: if the mapped path is >= MAX_PATH the function succeeds and
  61. // truncates the physical path without null-terminating it. But
  62. // the mapped size is > MAX_PATH, so key off that to check for overflow.
  63. //
  64. if ( (0 == cbConverted) ||
  65. ( !_pEcb->ServerSupportFunction( _pEcb->ConnID,
  66. HSE_REQ_MAP_URL_TO_PATH_EX,
  67. pszVirtualPath,
  68. &cbMappedPath,
  69. (PDWORD) &MapInfo ) ) ||
  70. ( cbMappedPath >= ( _MAX_PATH - 1 ) ) ||
  71. ( ( 0 != dwAccessMask ) &&
  72. ( 0 == ( dwAccessMask & MapInfo.dwFlags ) ) )
  73. )
  74. {
  75. //
  76. // We could not translate the virtual path to a real path,
  77. // or the access permissions didn't match, so this must be a
  78. // bogus virtual path.
  79. //
  80. qutilDebugOut(( DEB_ERROR,
  81. "Could not translate vpath=>ppath, mask 0x%x, flags 0x%x, '%ws'\n",
  82. dwAccessMask, MapInfo.dwFlags, wcsVirtualPath ));
  83. THROW( CException( QUTIL_E_CANT_CONVERT_VROOT ) );
  84. }
  85. if ( 0 == MultiByteToWideChar( _codePage,
  86. 0,
  87. MapInfo.lpszPath,
  88. strlen( MapInfo.lpszPath) + 1,
  89. wcsPhysicalPath,
  90. cwcPhysicalPath) )
  91. {
  92. //
  93. // We could not translate the ASCII string to WCHAR
  94. //
  95. qutilDebugOut(( DEB_ERROR,
  96. "Gibraltar could not convert ppath to unicode '%ws'\n",
  97. wcsVirtualPath ));
  98. THROW( CException( QUTIL_E_CANT_CONVERT_VROOT ) );
  99. }
  100. return MapInfo.dwFlags;
  101. } //GetPhysicalPath
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Member: CWebServer::GetCGIVariable - public
  105. //
  106. // Synopsis: Gets the CHAR version of a CGI variable
  107. //
  108. // Arguments: [pszVariableName] - name of variable to lookup
  109. // [wcsValue] - resulting variable
  110. // [cwcValue] - length of variable
  111. //
  112. // History: 96/Feb/29 DwightKr Created.
  113. //
  114. //----------------------------------------------------------------------------
  115. BOOL CWebServer::GetCGIVariable( CHAR const * pszVariableName,
  116. XArray<WCHAR> & wcsValue,
  117. ULONG & cwcValue )
  118. {
  119. Win4Assert ( IsValid() );
  120. BYTE pbBuffer[512];
  121. ULONG cbBuffer = sizeof( pbBuffer );
  122. if ( !_pEcb->GetServerVariable( _pEcb->ConnID,
  123. (char *) pszVariableName,
  124. pbBuffer,
  125. &cbBuffer ) )
  126. {
  127. return FALSE;
  128. }
  129. cwcValue = MultiByteToXArrayWideChar(
  130. (BYTE * const) pbBuffer,
  131. cbBuffer,
  132. _codePage,
  133. wcsValue );
  134. return cwcValue > 0;
  135. } //GetCGIVariable
  136. //+---------------------------------------------------------------------------
  137. //
  138. // Member: CWebServer::GetCGIVariable - public
  139. //
  140. // Synopsis: Gets the WCHAR version of a CGI variable
  141. //
  142. // Arguments: [wcsVariableName] - name of variable to lookup
  143. // [wcsValue] - resulting variable
  144. // [cwcValue] - length of variable (out only)
  145. //
  146. // History: 96/Mar/29 DwightKr Created.
  147. //
  148. //----------------------------------------------------------------------------
  149. BOOL CWebServer::GetCGIVariableW( WCHAR const * wcsVariableName,
  150. XArray<WCHAR> & wcsValue,
  151. ULONG & cwcBuffer )
  152. {
  153. ULONG cwcVariableName = wcslen( wcsVariableName ) + 1;
  154. XArray<BYTE> pszVariableName( cwcVariableName*2 );
  155. if ( 0 == WideCharToXArrayMultiByte( wcsVariableName,
  156. cwcVariableName,
  157. _codePage,
  158. pszVariableName )
  159. )
  160. {
  161. //
  162. // We could not translate the WCHAR string to ASCII
  163. //
  164. return FALSE;
  165. }
  166. return GetCGIVariable( (const char *) pszVariableName.GetPointer(),
  167. wcsValue,
  168. cwcBuffer );
  169. }