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.

201 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. write.cxx
  5. Abstract:
  6. This file contains the implementation of the HttpWriteData API.
  7. Contents:
  8. HttpWriteData
  9. HTTP_REQUEST_HANDLE_OBJECT::WriteData
  10. Author:
  11. Arthur Bierer (arthurbi) 07-Apr-1997
  12. Revision History:
  13. --*/
  14. #include <wininetp.h>
  15. #include "httpp.h"
  16. //
  17. // functions
  18. //
  19. DWORD
  20. HttpWriteData(
  21. IN HINTERNET hRequest,
  22. IN LPVOID lpBuffer,
  23. IN DWORD dwNumberOfBytesToWrite,
  24. OUT LPDWORD lpdwNumberOfBytesWritten,
  25. IN DWORD dwSocketFlags
  26. )
  27. /*++
  28. Routine Description:
  29. Writes a block of data for an outstanding HTTP request
  30. Assumes: 1. this function can only be called from InternetWriteFile() which
  31. globally validates parameters for all Internet data write
  32. functions
  33. 2. That we the caller has called HttpBeginSendRequest but not HttpEndSendRequest
  34. Arguments:
  35. hRequest - an open HTTP request handle returned by
  36. HttpOpenRequest()
  37. lpBuffer - pointer to the buffer to receive the data
  38. dwNumberOfBytesToWrite - number of bytes to write from user's buffer
  39. lpdwNumberOfBytesWritten - number of bytes actually written
  40. dwSocketFlags - controlling socket operation
  41. Return Value:
  42. TRUE - The data was written successfully. lpdwNumberOfBytesRead points to the
  43. number of BYTEs actually read. This value will be set to zero
  44. when the transfer has completed.
  45. FALSE - The operation failed. Error status is available by calling
  46. GetLastError().
  47. --*/
  48. {
  49. DEBUG_ENTER((DBG_HTTP,
  50. Dword,
  51. "HttpWriteData",
  52. "%#x, %#x, %d, %#x, %#x",
  53. hRequest,
  54. lpBuffer,
  55. dwNumberOfBytesToWrite,
  56. lpdwNumberOfBytesWritten,
  57. dwSocketFlags
  58. ));
  59. DWORD error = DoFsm(New CFsm_HttpWriteData(lpBuffer,
  60. dwNumberOfBytesToWrite,
  61. lpdwNumberOfBytesWritten,
  62. dwSocketFlags,
  63. (HTTP_REQUEST_HANDLE_OBJECT *)hRequest
  64. ));
  65. DEBUG_LEAVE(error);
  66. return error;
  67. }
  68. DWORD
  69. CFsm_HttpWriteData::RunSM(
  70. IN CFsm * Fsm
  71. )
  72. {
  73. DEBUG_ENTER((DBG_HTTP,
  74. Dword,
  75. "CFsm_HttpWriteData::RunSM",
  76. "%#x",
  77. Fsm
  78. ));
  79. DWORD error;
  80. HTTP_REQUEST_HANDLE_OBJECT * pRequest;
  81. CFsm_HttpWriteData * stateMachine = (CFsm_HttpWriteData *)Fsm;
  82. pRequest = (HTTP_REQUEST_HANDLE_OBJECT *)Fsm->GetContext();
  83. switch (Fsm->GetState()) {
  84. case FSM_STATE_INIT:
  85. pRequest->SetAddCRLF(TRUE);
  86. //
  87. // Fall through
  88. //
  89. case FSM_STATE_CONTINUE:
  90. error = pRequest->HttpWriteData_Fsm(stateMachine);
  91. break;
  92. default:
  93. error = ERROR_WINHTTP_INTERNAL_ERROR;
  94. Fsm->SetDone(ERROR_WINHTTP_INTERNAL_ERROR);
  95. INET_ASSERT(FALSE);
  96. break;
  97. }
  98. DEBUG_LEAVE(error);
  99. return error;
  100. }
  101. DWORD
  102. HTTP_REQUEST_HANDLE_OBJECT::HttpWriteData_Fsm(
  103. IN CFsm_HttpWriteData * Fsm
  104. )
  105. {
  106. DEBUG_ENTER((DBG_HTTP,
  107. Dword,
  108. "HTTP_REQUEST_HANDLE_OBJECT::HttpWriteData_Fsm",
  109. "%#x",
  110. Fsm
  111. ));
  112. CFsm_HttpWriteData & fsm = *Fsm;
  113. DWORD error = fsm.GetError();
  114. if (fsm.GetState() == FSM_STATE_INIT) {
  115. if (!IsValidHttpState(WRITE)) {
  116. error = ERROR_WINHTTP_INCORRECT_HANDLE_STATE;
  117. goto quit;
  118. }
  119. error = _Socket->Send(
  120. fsm.m_lpBuffer,
  121. fsm.m_dwNumberOfBytesToWrite,
  122. SF_INDICATE
  123. );
  124. }
  125. if (error == ERROR_SUCCESS)
  126. {
  127. *fsm.m_lpdwNumberOfBytesWritten = fsm.m_dwNumberOfBytesToWrite;
  128. }
  129. quit:
  130. if (error != ERROR_IO_PENDING) {
  131. fsm.SetDone();
  132. }
  133. DEBUG_LEAVE(error);
  134. return error;
  135. }