Team Fortress 2 Source Code as on 22/4/2020
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.

98 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // See download overview in src/engine/download_internal.h.
  4. //
  5. //=======================================================================================//
  6. #ifndef REQUESTCONTEXT_H
  7. #define REQUESTCONTEXT_H
  8. //--------------------------------------------------------------------------------------------------------------
  9. #include "engine/http.h"
  10. //--------------------------------------------------------------------------------------------------------------
  11. enum { BufferSize = 256 }; ///< BufferSize is used extensively within the download system to size char buffers.
  12. //--------------------------------------------------------------------------------------------------------------
  13. #ifdef POSIX
  14. typedef void *LPVOID;
  15. #endif
  16. #if defined( _X360 ) || defined( POSIX )
  17. typedef LPVOID HINTERNET;
  18. #endif
  19. //--------------------------------------------------------------------------------------------------------------
  20. struct RequestContext_t
  21. {
  22. inline RequestContext_t()
  23. {
  24. memset( this, 0, sizeof( RequestContext_t ) );
  25. }
  26. /**
  27. * The main thread sets this when it wants to abort the download,
  28. * or it is done reading data from a finished download.
  29. */
  30. bool shouldStop;
  31. /**
  32. * The download thread sets this when it is exiting, so the main thread
  33. * can delete the RequestContext_t.
  34. */
  35. bool threadDone;
  36. bool bIsBZ2; ///< true if the file is a .bz2 file that should be uncompressed at the end of the download. Set and used by main thread.
  37. bool bAsHTTP; ///< true if downloaded via HTTP and not ingame protocol. Set and used by main thread
  38. unsigned int nRequestID; ///< request ID for ingame download
  39. HTTPStatus_t status; ///< Download thread status
  40. DWORD fetchStatus; ///< Detailed status info for the download
  41. HTTPError_t error; ///< Detailed error info
  42. char baseURL[BufferSize]; ///< Base URL (including http://). Set by main thread.
  43. char urlPath[BufferSize]; ///< Path to be appended to base URL. Set by main thread.
  44. char absLocalPath[BufferSize]; ///< Full local path where the file should go. Set by main thread.
  45. char gamePath[BufferSize]; ///< Game path to be appended to base path. Set by main thread.
  46. char serverURL[BufferSize]; ///< Server URL (IP:port, loopback, etc). Set by main thread, and used for HTTP Referer header.
  47. bool bSuppressFileWrite; ///< Set to true by main thread if we do not wish to write the file to disk
  48. /**
  49. * The file's timestamp, as returned in the HTTP Last-Modified header.
  50. * Saved to ensure partial download resumes match the original cached data.
  51. */
  52. char cachedTimestamp[BufferSize];
  53. DWORD nBytesTotal; ///< Total bytes in the file
  54. DWORD nBytesCurrent; ///< Current bytes downloaded
  55. DWORD nBytesCached; ///< Amount of data present in cacheData.
  56. /**
  57. * Buffer for the full file data. Allocated/deleted by the download thread
  58. * (which idles until the data is not needed anymore)
  59. */
  60. unsigned char *data;
  61. /**
  62. * Buffer for partial data from previous failed downloads.
  63. * Allocated/deleted by the main thread (deleted after download thread is done)
  64. */
  65. unsigned char *cacheData;
  66. // Used purely by the download thread - internal data -------------------
  67. HINTERNET hOpenResource; ///< Handle created by InternetOpen
  68. HINTERNET hDataResource; ///< Handle created by InternetOpenUrl
  69. /**
  70. * For any user data we may want to attach to a context
  71. */
  72. void *pUserData;
  73. };
  74. //--------------------------------------------------------------------------------------------------------------
  75. #endif // REQUESTCONTEXT_H