Source code of Windows XP (NT5)
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.

192 lines
6.0 KiB

  1. #ifndef _ANYCON_HXX
  2. #define _ANYCON_HXX
  3. class CStream;
  4. class CAnyConnection {
  5. public:
  6. CAnyConnection (
  7. BOOL bSecure,
  8. INTERNET_PORT nServerPort,
  9. BOOL bIgnoreSecurityDlg,
  10. DWORD dwAuthMethod);
  11. virtual ~CAnyConnection ();
  12. virtual HINTERNET OpenSession ();
  13. virtual BOOL CloseSession ();
  14. virtual HINTERNET Connect(
  15. LPTSTR lpszServerName);
  16. virtual BOOL Disconnect ();
  17. virtual HINTERNET OpenRequest (
  18. LPTSTR lpszUrl);
  19. virtual BOOL CloseRequest (HINTERNET hReq);
  20. virtual BOOL SendRequest(
  21. HINTERNET hReq,
  22. LPCTSTR lpszHdr,
  23. DWORD cbData,
  24. LPBYTE pidi);
  25. virtual BOOL SendRequest(
  26. HINTERNET hReq,
  27. LPCTSTR lpszHdr,
  28. CStream *pStream);
  29. virtual BOOL ReadFile (
  30. HINTERNET hReq,
  31. LPVOID lpvBuffer,
  32. DWORD cbBuffer,
  33. LPDWORD lpcbRd);
  34. BOOL IsValid () {return m_bValid;}
  35. BOOL SetPassword (
  36. HINTERNET hReq,
  37. LPTSTR lpszUserName,
  38. LPTSTR lpszPassword);
  39. BOOL GetAuthSchem (
  40. HINTERNET hReq,
  41. LPSTR lpszScheme,
  42. DWORD dwSize);
  43. void SetShowSecurityDlg (
  44. BOOL bShowSecDlg);
  45. inline DWORD GetAuthMethod (VOID) const {
  46. return m_dwAuthMethod;
  47. }
  48. protected:
  49. #ifndef WINNT32 // This needs only to work on Win9X, we can use sync calls in NT
  50. /********************************************************************************************
  51. ** Class - CAnyConnection::CAsyncContext
  52. ** Description - This class provides an abstract way for the asynchronous callback between
  53. ** the WinInet API and the Http connection to be expressed
  54. ********************************************************************************************/
  55. class CAsyncContext {
  56. public:
  57. CAsyncContext(void); // Allocate the event and clear the return status
  58. inline BOOL bValid(void); // Return true if there is a failure
  59. BOOL TimeoutWait( IN OUT BOOL & bSuccess);
  60. // Wait for a particular timeout, we use the
  61. // passed in BOOL to see if the call was asynchronous
  62. ~CAsyncContext(); // Close the handle if it exists
  63. static void CALLBACK InternetCallback( // This callback is used to send an event back to
  64. IN HINTERNET hInternet, // the calling thread, this prevents the calling
  65. IN DWORD_PTR dwContext, // thread from blocking indefinitely, it will
  66. IN DWORD dwInternetStatus, // simply time out
  67. IN LPVOID lpvStatusInformation,
  68. IN DWORD dwStatusInformationLength);
  69. private:
  70. DWORD m_dwRet; // This is the return value for non-handle calls
  71. DWORD m_dwError; // This is the last error code that was given to
  72. // the function
  73. HANDLE m_hEvent; // This is the event used for the synchronisation
  74. };
  75. #endif // #ifndef WINNT32
  76. #ifndef WINNT32 // These are meaningless in sync code
  77. static BOOL AsynchronousWait( IN HINTERNET hInternet, IN OUT BOOL & bSuccess);
  78. // Wait for an asyncronous operation where we
  79. // only know the internet handle and want a BOOL
  80. static CAsyncContext *GetAsyncContext( IN HINTERNET hInternet);
  81. // Get the context associated with this handle
  82. #endif // #ifndef WINNT32
  83. LPTSTR m_lpszPassword;
  84. LPTSTR m_lpszUserName;
  85. BOOL m_bValid;
  86. BOOL m_bSecure;
  87. HINTERNET m_hSession;
  88. HINTERNET m_hConnect;
  89. INTERNET_PORT m_nServerPort;
  90. BOOL m_bIgnoreSecurityDlg;
  91. private:
  92. DWORD m_dwAccessFlag;
  93. BOOL m_bShowSecDlg;
  94. DWORD m_dwAuthMethod;
  95. static const DWORD gm_dwConnectTimeout; // The connection timeout
  96. static const DWORD gm_dwSendTimeout; // The send timeout
  97. static const DWORD gm_dwReceiveTimeout; // The receive timeout
  98. static const DWORD gm_dwSendSize; // The size of the blocks we send to the server
  99. };
  100. ////////////////////////////////////////////////////////////////////////////////////////////////
  101. // INLINE METHODS
  102. ////////////////////////////////////////////////////////////////////////////////////////////////
  103. #ifndef WINNT32
  104. inline BOOL CAnyConnection::CAsyncContext::bValid(void) {
  105. return m_hEvent != INVALID_HANDLE_VALUE;
  106. }
  107. #endif // #ifndef WINNT32
  108. ////////////////////////////////////////////////////////////////////////////////////////////////
  109. // MACROS FOR SYNCHRONOUS CODE
  110. ///////////////////////////////////////////////////////////////////////////////////////////////
  111. #ifdef WINNT32
  112. #define WIN9X_OP_ASYNC(OpX)
  113. #define WIN9X_NEW_ASYNC(NewX)
  114. #define WIN9X_GET_ASYNC(GetX, HandleX)
  115. #define WIN9X_IF_ASYNC(ExprX)
  116. #define WIN9X_BREAK_ASYNC(RetX)
  117. #define WIN9X_ELSE_ASYNC(ExprX)
  118. #define WIN9X_WAIT_ASYNC(HandleX, BoolX) (BoolX)
  119. #define WIN9X_TIMEOUT_ASYNC(ContextX, BoolX) (BoolX)
  120. #define WIN9X_CONTEXT_ASYNC(acX) 0
  121. #else // #ifndef WINNT32
  122. #define WIN9X_OP_ASYNC(OpX) \
  123. OpX
  124. #define WIN9X_NEW_ASYNC(NewX) \
  125. CAsyncContext *(NewX) = new CAsyncContext
  126. #define WIN9X_GET_ASYNC(GetX, HandleX) \
  127. CAsyncContext *(GetX) = GetAsyncContext(HandleX)
  128. #define WIN9X_IF_ASYNC(ExprX) \
  129. if (ExprX)
  130. #define WIN9X_BREAK_ASYNC(RetX) \
  131. break; bRet = (RetX)
  132. #define WIN9X_ELSE_ASYNC(ExprX) \
  133. else (ExprX)
  134. #define WIN9X_WAIT_ASYNC(HandleX, BoolX) \
  135. (AsynchronousWait( HandleX, BoolX))
  136. #define WIN9X_TIMEOUT_ASYNC(ContextX, BoolX) \
  137. (ContextX)->TimeoutWait(BoolX)
  138. #define WIN9X_CONTEXT_ASYNC(acX) \
  139. ((DWORD_PTR)acX)
  140. #endif // #ifdef WINNT32
  141. #endif