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.

185 lines
5.3 KiB

  1. /******************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. dlutil.h
  5. Abstract:
  6. header for download library
  7. ******************************************************************************/
  8. #ifndef DLUTIL_H
  9. #define DLUTIL_H
  10. #include <strsafe.h>
  11. #include <wusafefn.h>
  12. #include <mistsafe.h>
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // const defines & typedefs
  15. #define UNLEN 256
  16. // need to define this here cuz winhttp.h doesn't define it and we get dupe
  17. // definitions if we try to include wininet.h just to get it.
  18. #ifndef INTERNET_MAX_URL_LENGTH
  19. #define INTERNET_MAX_URL_LENGTH 2200
  20. #endif
  21. const DWORD c_cbDownloadBuffer = 32 * 1024; // 32k
  22. const DWORD c_cbDownloadBufferLite = 4 * 1024; // 4k
  23. const DWORD c_dwRetryTimeLimitInmsWinHttp = 2 * 60 * 1000; // 120s (2m)
  24. const DWORD c_dwRetryTimeLimitInmsWiuInet = 10 * 1000; // 10s
  25. const DWORD c_cMaxRetries = 3;
  26. const WCHAR c_wszUserAgent[] = L"Industry Update Control";
  27. const char c_szUserAgent[] = "Industry Update Control";
  28. const DWORD c_cchMaxURLSize = INTERNET_MAX_URL_LENGTH;
  29. #ifdef UNICODE
  30. #define c_tszUserAgent c_wszUserAgent
  31. #else
  32. #define c_tszUserAgent c_szUserAgent
  33. #endif
  34. typedef BOOL (__stdcall *pfn_ReadDataFromSite)(HINTERNET, LPVOID, DWORD, LPDWORD);
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // macro defines
  37. #define sizeofSTRW(wsz) (sizeof(wsz) / sizeof(WCHAR))
  38. #define sizeofSTRA(sz) (sizeof(sz))
  39. #define sizeofSTRT(sz) (sizeof(sz) / sizeof(TCHAR))
  40. ///////////////////////////////////////////////////////////////////////////////
  41. // necessary classes
  42. class CAutoCritSec
  43. {
  44. private:
  45. #if defined(DEBUG) || defined(DBG)
  46. DWORD m_dwOwningThread;
  47. DWORD m_cLocks;
  48. #endif
  49. CRITICAL_SECTION m_cs;
  50. BOOL m_fInit;
  51. public:
  52. CAutoCritSec(void)
  53. {
  54. m_fInit = WUInitializeCriticalSectionAndSpinCount(&m_cs, 0x8000FA0);
  55. #if defined(DEBUG) || defined(DBG)
  56. m_cLocks = 0;
  57. m_dwOwningThread = 0;
  58. #endif
  59. }
  60. ~CAutoCritSec(void)
  61. {
  62. #if defined(DEBUG) || defined(DBG)
  63. if (m_cLocks > 0 || m_dwOwningThread != 0)
  64. {
  65. // can't do logging here cuz this could be run during DllMain
  66. }
  67. #endif
  68. if (m_fInit)
  69. DeleteCriticalSection(&m_cs);
  70. }
  71. BOOL Lock(void)
  72. {
  73. LOG_Block("CAutoCritSec::Lock()");
  74. if (m_fInit)
  75. {
  76. EnterCriticalSection(&m_cs);
  77. #if defined(DEBUG) || defined(DBG)
  78. m_cLocks++;
  79. m_dwOwningThread = GetCurrentThreadId();
  80. #endif
  81. }
  82. else
  83. {
  84. LOG_Internet(_T("CAutoCritSec not initialized during Lock."));
  85. }
  86. return m_fInit;
  87. }
  88. BOOL Unlock(void)
  89. {
  90. LOG_Block("CAutoCritSec::Unlock()");
  91. if (m_fInit)
  92. {
  93. #if defined(DEBUG) || defined(DBG)
  94. if (m_cLocks == 0)
  95. LOG_Internet(_T("CAutoCritSec: trying to unlock when lock count is 0"));
  96. else
  97. m_cLocks--;
  98. if (m_dwOwningThread != GetCurrentThreadId())
  99. {
  100. LOG_Internet(_T("CAutoCritSec: lock not owned by current thread: Owning thread: %d. Current thread: %d"),
  101. m_dwOwningThread, GetCurrentThreadId());
  102. }
  103. if (m_cLocks == 0)
  104. m_dwOwningThread = 0;
  105. #endif
  106. LeaveCriticalSection(&m_cs);
  107. }
  108. else
  109. {
  110. LOG_Internet(_T("CAutoCritSec not initialized during Unlock."));
  111. }
  112. return m_fInit;
  113. }
  114. };
  115. ///////////////////////////////////////////////////////////////////////////////
  116. // prototypes
  117. BOOL IsServerFileDifferentW(FILETIME &ftServerTime, DWORD dwServerFileSize,
  118. LPCWSTR wszLocalFile);
  119. BOOL IsServerFileDifferentA(FILETIME &ftServerTime, DWORD dwServerFileSize,
  120. LPCSTR szLocalFile);
  121. #ifdef UNICODE
  122. #define IsServerFileDifferent IsServerFileDifferentW
  123. #else
  124. #define IsServerFileDifferent IsServerFileDifferentA
  125. #endif // !UNICODE
  126. HRESULT PerformDownloadToFile(pfn_ReadDataFromSite pfnRead,
  127. HINTERNET hRequest,
  128. HANDLE hFile, DWORD cbFile,
  129. DWORD cbBuffer,
  130. HANDLE *rghEvents, DWORD cEvents,
  131. PFNDownloadCallback fpnCallback, LPVOID pCallbackData,
  132. DWORD *pcbDownloaded);
  133. HRESULT StartWinInetDownload(HMODULE hmodWinInet,
  134. LPCTSTR pszServerUrl,
  135. LPCTSTR pszLocalPath,
  136. DWORD *pdwDownloadedBytes,
  137. HANDLE *hQuitEvents,
  138. UINT nQuitEventCount,
  139. PFNDownloadCallback fpnCallback,
  140. LPVOID pCallbackData,
  141. DWORD dwFlags,
  142. DWORD cbDownloadBuffer);
  143. HRESULT IsFileHtml(LPCTSTR pszFileName);
  144. #endif