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.

224 lines
4.9 KiB

  1. class CFile;
  2. enum UPLOAD_STATE
  3. {
  4. UPLOAD_STATE_CREATE_SESSION,
  5. UPLOAD_STATE_SEND_DATA,
  6. UPLOAD_STATE_GET_REPLY,
  7. UPLOAD_STATE_CLOSE_SESSION,
  8. UPLOAD_STATE_CLOSED,
  9. UPLOAD_STATE_CANCEL_SESSION,
  10. UPLOAD_STATE_CANCELLED
  11. };
  12. struct UPLOAD_DATA
  13. {
  14. UPLOAD_STATE State;
  15. bool fSchedulable;
  16. GUID Protocol;
  17. StringHandle SessionId;
  18. StringHandle ReplyUrl;
  19. StringHandle HostId;
  20. DWORD HostIdFallbackTimeout;
  21. FILETIME HostIdNoProgressStartTime;
  22. //---------------------------
  23. UPLOAD_DATA();
  24. ~UPLOAD_DATA();
  25. void Serialize( HANDLE hFile );
  26. void Unserialize( HANDLE hFile );
  27. void SetUploadState( UPLOAD_STATE NewState );
  28. };
  29. class Uploader
  30. /*
  31. This class handles a particular upload attempt, updating the upload state
  32. and the job progress data as appropriate.
  33. It uses the UPLOAD_DATA in a CUploadJob to determine the starting state.
  34. Then it runs the upload state machine until the job is complete or is interrupted.
  35. */
  36. {
  37. public:
  38. Uploader(
  39. Downloader * dl,
  40. CNetworkInterface & net,
  41. CUploadJob * job,
  42. HANDLE Token,
  43. ITransferCallback * CallBacks,
  44. QMErrInfo & ErrorInfo
  45. );
  46. ~Uploader();
  47. void Transfer();
  48. bool InTerminalState() { return (m_data.State == UPLOAD_STATE_CLOSED || m_data.State == UPLOAD_STATE_CANCELLED); }
  49. void SetState( UPLOAD_STATE state ) { m_data.State = state; }
  50. static void
  51. SetResult(
  52. QMErrInfo & err,
  53. ERROR_SOURCE source,
  54. ERROR_STYLE style,
  55. DWORD code,
  56. char * comment = 0
  57. );
  58. private:
  59. //
  60. // Uploader objects are created on the stack, so member data must be kept small (under 200 bytes on x86).
  61. //
  62. CNetworkInterface & m_Network;
  63. ITransferCallback * m_Callbacks;
  64. Downloader * m_Downloader;
  65. HANDLE m_Token;
  66. CUploadJob * m_job;
  67. CFile * m_file;
  68. BG_JOB_TYPE m_JobType;
  69. UPLOAD_DATA & m_data;
  70. auto_ptr<URL_INFO> m_UrlInfo;
  71. QMErrInfo & m_ErrorInfo;
  72. HANDLE m_hFile;
  73. DWORD m_ExpectedServerOffset;
  74. long m_Restarts;
  75. const CCredentialsContainer * m_Credentials;
  76. typedef void (Uploader::* RESPONSE_FN )( CBitsCommandRequest & request, DWORD result );
  77. struct ResponseEntry
  78. {
  79. DWORD Code;
  80. RESPONSE_FN Fn;
  81. };
  82. #pragma warning( disable:4200 )
  83. struct ResponseTable
  84. {
  85. RESPONSE_FN DefaultFn;
  86. ResponseEntry Entries[];
  87. };
  88. static ResponseTable Ping_ResponseTable;
  89. static ResponseTable CreateSession_ResponseTable;
  90. static ResponseTable SendData_ResponseTable;
  91. static ResponseTable CloseSession_ResponseTable;
  92. static ResponseTable CancelSession_ResponseTable;
  93. #pragma warning( default:4200 )
  94. //---------------------------------------------------------------------
  95. auto_ptr<URL_INFO> ContactServer();
  96. void
  97. AnalyzeResponse(
  98. CBitsCommandRequest & request,
  99. DWORD result,
  100. ResponseTable & table
  101. );
  102. //
  103. // fns to send data to the server
  104. //
  105. void Ping();
  106. void CreateSession();
  107. void SendData();
  108. void GetReply();
  109. void CloseSession();
  110. void CancelSession();
  111. //
  112. // fns to react to server responses
  113. //
  114. void
  115. Ping_Success(
  116. CBitsCommandRequest & request,
  117. DWORD result
  118. );
  119. void
  120. CreateSession_NewSession(
  121. CBitsCommandRequest & request,
  122. DWORD result
  123. );
  124. void
  125. CreateSession_InProgress(
  126. CBitsCommandRequest & request,
  127. DWORD result
  128. );
  129. void
  130. SendData_Success(
  131. CBitsCommandRequest & request,
  132. DWORD result
  133. );
  134. void
  135. SendData_Failure(
  136. CBitsCommandRequest & request,
  137. DWORD result
  138. );
  139. void
  140. CloseSession_Success(
  141. CBitsCommandRequest & request,
  142. DWORD result
  143. );
  144. void
  145. CloseSession_Failure(
  146. CBitsCommandRequest & request,
  147. DWORD result
  148. );
  149. void
  150. CancelSession_Success(
  151. CBitsCommandRequest & request,
  152. DWORD result
  153. );
  154. void
  155. CancelSession_Failure(
  156. CBitsCommandRequest & request,
  157. DWORD result
  158. );
  159. void
  160. GenericServerError(
  161. CBitsCommandRequest & request,
  162. DWORD result
  163. );
  164. //--------------------------------------------------------------------
  165. void
  166. ReadReplyData(
  167. CBitsCommandRequest & request,
  168. bool fKeep
  169. );
  170. };
  171. FILE_DOWNLOAD_RESULT
  172. CategorizeError(
  173. QMErrInfo & ErrInfo
  174. );