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. DEBUG_ENTER((DBG_INET,
  54. Bool,
  55. "wInternetQueryDataAvailable",
  56. "%#x, %#x, %#x, %#x",
  57. hFileMapped,
  58. lpdwNumberOfBytesAvailable,
  59. dwFlags,
  60. dwContext
  61. ));
  62. LPINTERNET_THREAD_INFO lpThreadInfo = InternetGetThreadInfo();
  63. DWORD error;
  64. HINTERNET_HANDLE_TYPE handleType;
  65. INET_ASSERT(hFileMapped);
  66. //
  67. // as usual, grab the per-thread info block
  68. //
  69. if (lpThreadInfo == NULL) {
  70. INET_ASSERT(FALSE);
  71. error = ERROR_WINHTTP_INTERNAL_ERROR;
  72. goto quit;
  73. }
  74. //
  75. // if this is the async worker thread then set the handle, and
  76. // last-error info in the per-thread data block before we go any further
  77. // (we already did this on the sync path)
  78. //
  79. if (lpThreadInfo->IsAsyncWorkerThread) {
  80. _InternetSetObjectHandle(lpThreadInfo,
  81. ((HANDLE_OBJECT *)hFileMapped)->GetPseudoHandle(),
  82. hFileMapped
  83. );
  84. _InternetClearLastError(lpThreadInfo);
  85. //
  86. // we should only be here in async mode if there was no data immediately
  87. // available
  88. //
  89. INET_ASSERT(!((INTERNET_HANDLE_OBJECT *)hFileMapped)->IsDataAvailable());
  90. }
  91. //
  92. // we copy the number of bytes available to a local variable first, and
  93. // only update the caller's variable if we succeed
  94. //
  95. DWORD bytesAvailable;
  96. //
  97. // get the current data available
  98. //
  99. error = ((HTTP_REQUEST_HANDLE_OBJECT *)hFileMapped)
  100. ->QueryDataAvailable(&bytesAvailable);
  101. quit:
  102. BOOL success;
  103. if (error == ERROR_SUCCESS) {
  104. ((INTERNET_HANDLE_OBJECT *)hFileMapped)->SetAvailableDataLength(bytesAvailable);
  105. *lpdwNumberOfBytesAvailable = bytesAvailable;
  106. success = TRUE;
  107. DEBUG_PRINT(INET,
  108. INFO,
  109. ("%d bytes available\n",
  110. bytesAvailable
  111. ));
  112. DEBUG_PRINT_API(API,
  113. INFO,
  114. ("*lpdwNumberOfBytesAvailable (%#x) = %d\n",
  115. lpdwNumberOfBytesAvailable,
  116. bytesAvailable
  117. ));
  118. } else {
  119. success = FALSE;
  120. DEBUG_ERROR(INET, error);
  121. }
  122. SetLastError(error);
  123. DEBUG_LEAVE(success);
  124. return success;
  125. }