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.

183 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. inetapiu.cxx
  5. Abstract:
  6. Contains WinInet API utility & sub-API functions
  7. Contents:
  8. wInternetQueryDataAvailable
  9. Author:
  10. Richard L Firth (rfirth) 16-Feb-1996
  11. Environment:
  12. Win32 user-level
  13. Revision History:
  14. 16-Feb-1996 rfirth
  15. Created
  16. --*/
  17. #include <wininetp.h>
  18. //
  19. // functions
  20. //
  21. BOOL
  22. wInternetQueryDataAvailable(
  23. IN LPVOID hFileMapped,
  24. OUT LPDWORD lpdwNumberOfBytesAvailable,
  25. IN DWORD dwFlags,
  26. IN DWORD_PTR dwContext
  27. )
  28. /*++
  29. Routine Description:
  30. Part 2 of InternetQueryDataAvailabe. This function is called by the async
  31. worker thread in order to resume InternetQueryDataAvailable(), and by the
  32. app as the worker part of the API, post validation
  33. We can query available data for handle types that return data, either from
  34. a socket, or from a cache file:
  35. - HTTP request
  36. - FTP file
  37. - FTP find
  38. - FTP find HTML
  39. - gopher file
  40. - gopher find
  41. - gopher find HTML
  42. Arguments:
  43. hFileMapped - the mapped HINTERNET
  44. lpdwNumberOfBytesAvailable - where the number of bytes is returned
  45. dwFlags - flags controlling operation
  46. dwContext - context value for callbacks
  47. Return Value:
  48. DWORD
  49. Success - ERROR_SUCCESS
  50. Failure -
  51. --*/
  52. {
  53. UNREFERENCED_PARAMETER(dwFlags);
  54. UNREFERENCED_PARAMETER(dwContext);
  55. DEBUG_ENTER((DBG_INET,
  56. Bool,
  57. "wInternetQueryDataAvailable",
  58. "%#x, %#x, %#x, %#x",
  59. hFileMapped,
  60. lpdwNumberOfBytesAvailable,
  61. dwFlags,
  62. dwContext
  63. ));
  64. LPINTERNET_THREAD_INFO lpThreadInfo = InternetGetThreadInfo();
  65. DWORD error;
  66. DWORD bytesAvailable = 0;
  67. INET_ASSERT(hFileMapped);
  68. //
  69. // as usual, grab the per-thread info block
  70. //
  71. if (lpThreadInfo == NULL) {
  72. //informational INET_ASSERT(FALSE);
  73. error = ERROR_WINHTTP_INTERNAL_ERROR;
  74. goto quit;
  75. }
  76. //
  77. // if this is the async worker thread then set the handle, and
  78. // last-error info in the per-thread data block before we go any further
  79. // (we already did this on the sync path)
  80. //
  81. if (lpThreadInfo->IsAsyncWorkerThread) {
  82. _InternetSetObjectHandle(lpThreadInfo,
  83. ((HANDLE_OBJECT *)hFileMapped)->GetPseudoHandle(),
  84. hFileMapped
  85. );
  86. _InternetClearLastError(lpThreadInfo);
  87. //
  88. // we should only be here in async mode if there was no data immediately
  89. // available
  90. //
  91. INET_ASSERT(!((INTERNET_HANDLE_OBJECT *)hFileMapped)->IsDataAvailable());
  92. }
  93. //
  94. // we copy the number of bytes available to a local variable first, and
  95. // only update the caller's variable if we succeed
  96. //
  97. //
  98. // get the current data available
  99. //
  100. error = ((HTTP_REQUEST_HANDLE_OBJECT *)hFileMapped)
  101. ->QueryDataAvailable(&bytesAvailable);
  102. quit:
  103. BOOL success;
  104. if (error == ERROR_SUCCESS) {
  105. ((INTERNET_HANDLE_OBJECT *)hFileMapped)->SetAvailableDataLength(bytesAvailable);
  106. *lpdwNumberOfBytesAvailable = bytesAvailable;
  107. success = TRUE;
  108. DEBUG_PRINT(INET,
  109. INFO,
  110. ("%d bytes available\n",
  111. bytesAvailable
  112. ));
  113. DEBUG_PRINT_API(API,
  114. INFO,
  115. ("*lpdwNumberOfBytesAvailable (%#x) = %d\n",
  116. lpdwNumberOfBytesAvailable,
  117. bytesAvailable
  118. ));
  119. } else {
  120. success = FALSE;
  121. DEBUG_ERROR(INET, error);
  122. }
  123. SetLastError(error);
  124. DEBUG_LEAVE(success);
  125. return success;
  126. }