ReactOS  0.4.15-dev-1397-g19779b3
asyncinet.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  __AsyncInet
 

Typedefs

typedef struct __AsyncInet ASYNCINET
 
typedef struct __AsyncInetpASYNCINET
 
typedef int(* ASYNCINET_CALLBACK) (pASYNCINET AsyncInet, ASYNC_EVENT Event, WPARAM wParam, LPARAM lParam, VOID *Extension)
 

Enumerations

enum  ASYNC_EVENT { ASYNCINET_DATA, ASYNCINET_COMPLETE, ASYNCINET_CANCELLED, ASYNCINET_ERROR }
 

Functions

pASYNCINET AsyncInetDownload (LPCWSTR lpszAgent, DWORD dwAccessType, LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, LPCWSTR lpszUrl, BOOL bAllowCache, ASYNCINET_CALLBACK Callback, VOID *Extension)
 
BOOL AsyncInetCancel (pASYNCINET AsyncInet)
 
VOID AsyncInetRelease (pASYNCINET AsyncInet)
 

Typedef Documentation

◆ ASYNCINET

Definition at line 19 of file asyncinet.h.

◆ ASYNCINET_CALLBACK

typedef int(* ASYNCINET_CALLBACK) (pASYNCINET AsyncInet, ASYNC_EVENT Event, WPARAM wParam, LPARAM lParam, VOID *Extension)

Definition at line 22 of file asyncinet.h.

◆ pASYNCINET

Definition at line 19 of file asyncinet.h.

Enumeration Type Documentation

◆ ASYNC_EVENT

Enumerator
ASYNCINET_DATA 
ASYNCINET_COMPLETE 
ASYNCINET_CANCELLED 
ASYNCINET_ERROR 

Definition at line 5 of file asyncinet.h.

6 {
7  ASYNCINET_DATA, // wParam is the Data retrieved from the internet, lParam is the length of Data
8 
9  ASYNCINET_COMPLETE, // wParam and lParam are not used.
10  // when receiving this, AsyncInet will be free soon and should not used anymore
11 
12  ASYNCINET_CANCELLED, // wParam and lParam are not used.
13  // when receiving this, AsyncInet will be free soon and should not used anymore
14 
15  ASYNCINET_ERROR // wParam is not used. lParam specify the error code (if there is one).
16  // when receiving this, AsyncInet will be free soon and should not used anymore
17 };

Function Documentation

◆ AsyncInetCancel()

BOOL AsyncInetCancel ( pASYNCINET  AsyncInet)

Definition at line 126 of file asyncinet.cpp.

127 {
128  if (AsyncInet)
129  {
130  HINTERNET hInetFile;
131  EnterCriticalSection(&(AsyncInet->CriticalSection));
132  AsyncInet->bCancelled = TRUE;
133  hInetFile = AsyncInet->hInetFile;
134  AsyncInet->hInetFile = NULL;
135  LeaveCriticalSection(&(AsyncInet->CriticalSection));
136 
137  if (hInetFile)
138  {
139  InternetCloseHandle(hInetFile);
140  return TRUE;
141  }
142  }
143 
144  return FALSE;
145 }
#define TRUE
Definition: types.h:120
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1436
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
BOOL bCancelled
Definition: asyncinet.h:43
#define FALSE
Definition: types.h:117
CRITICAL_SECTION CriticalSection
Definition: asyncinet.h:38
#define NULL
Definition: types.h:112
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
HINTERNET hInetFile
Definition: asyncinet.h:33

Referenced by CAppScrnshotPreview::PreviousDisplayCleanup().

◆ AsyncInetDownload()

pASYNCINET AsyncInetDownload ( LPCWSTR  lpszAgent,
DWORD  dwAccessType,
LPCWSTR  lpszProxy,
LPCWSTR  lpszProxyBypass,
LPCWSTR  lpszUrl,
BOOL  bAllowCache,
ASYNCINET_CALLBACK  Callback,
VOID Extension 
)

Definition at line 33 of file asyncinet.cpp.

42 {
43  pASYNCINET AsyncInet = NULL;
45  DWORD InetOpenUrlFlag = 0;
46  INTERNET_STATUS_CALLBACK OldCallbackFunc;
47 
49  if (!AsyncInet)
50  {
51  OutputDebugStringA("At File: " __FILE__ " HeapAlloc returned 0\n");
52  return 0;
53  }
54 
55  AsyncInet->bCancelled = FALSE;
56 
57  AsyncInet->hInternet = NULL;
58  AsyncInet->hInetFile = NULL;
59 
60  AsyncInet->Callback = Callback;
61  AsyncInet->Extension = Extension;
62 
64 
66  AsyncInet->ReferenceCnt = 1; // 1 for callee itself
68 
69  if (AsyncInet->hEventHandleCreated && AsyncInet->hEventHandleClose)
70  {
71  AsyncInet->hInternet = InternetOpenW(lpszAgent, dwAccessType, lpszProxy, lpszProxyBypass, INTERNET_FLAG_ASYNC);
72 
73  if (AsyncInet->hInternet)
74  {
75  OldCallbackFunc = InternetSetStatusCallbackW(AsyncInet->hInternet, AsyncInetStatusCallback);
76  if (OldCallbackFunc != INTERNET_INVALID_STATUS_CALLBACK)
77  {
79  if (!bAllowCache)
80  {
82  }
83 
84  AsyncInet->hInetFile = InternetOpenUrlW(AsyncInet->hInternet, lpszUrl, 0, 0, InetOpenUrlFlag, (DWORD_PTR)AsyncInet);
85 
86  if (AsyncInet->hInetFile)
87  {
88  // operate complete synchronously
89  bSuccess = TRUE;
90  AsyncInetReadFileLoop(AsyncInet);
91  }
92  else
93  {
95  {
96  // everything fine. waiting for handle created
98  {
99  case WAIT_OBJECT_0:
100  if (AsyncInet->hInetFile)
101  {
102  bSuccess = TRUE;
103  }
104  }
105  }
106  }
107  }
108  }
109  }
110 
111  if (!bSuccess)
112  {
113  AsyncInetFree(AsyncInet);
114  AsyncInet = NULL;
115  }
116 
117  if (AsyncInet)
118  {
119  // add reference count for caller.
120  // the caller is responsible for call AsyncInetRelease when no longer using it.
121  AsyncInetAcquire(AsyncInet);
122  }
123  return AsyncInet;
124 }
#define CreateEvent
Definition: winbase.h:3588
#define TRUE
Definition: types.h:120
VOID(CALLBACK * INTERNET_STATUS_CALLBACK)(_In_ HINTERNET, _In_opt_ DWORD_PTR, _In_ DWORD, _In_opt_ LPVOID, _In_ DWORD)
Definition: wininet.h:859
#define INTERNET_FLAG_RELOAD
Definition: wininet.h:61
#define INTERNET_FLAG_RESYNCHRONIZE
Definition: wininet.h:82
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
VOID CALLBACK AsyncInetStatusCallback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
Definition: asyncinet.cpp:220
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define INTERNET_FLAG_DONT_CACHE
Definition: wininet.h:67
static BOOLEAN bSuccess
Definition: drive.cpp:419
BOOL bCancelled
Definition: asyncinet.h:43
HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl, LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3605
VOID * Extension
Definition: asyncinet.h:49
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
VOID AsyncInetFree(pASYNCINET AsyncInet)
Definition: asyncinet.cpp:425
ASYNCINET_CALLBACK Callback
Definition: asyncinet.h:48
HANDLE hEventHandleCreated
Definition: asyncinet.h:35
#define INTERNET_INVALID_STATUS_CALLBACK
Definition: wininet.h:915
#define WAIT_OBJECT_0
Definition: winbase.h:387
struct __AsyncInet ASYNCINET
Definition: asyncinet.h:19
#define GetProcessHeap()
Definition: compat.h:595
INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(HINTERNET hInternet, INTERNET_STATUS_CALLBACK lpfnIntCB)
Definition: internet.c:2097
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
struct __AsyncInet * pASYNCINET
Definition: asyncinet.h:19
HINTERNET hInternet
Definition: asyncinet.h:32
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INTERNET_FLAG_ASYNC
Definition: wininet.h:64
CRITICAL_SECTION CriticalSection
Definition: asyncinet.h:38
uint32_t DWORD_PTR
Definition: typedefs.h:65
UINT ReferenceCnt
Definition: asyncinet.h:37
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
#define INTERNET_FLAG_PASSIVE
Definition: wininet.h:65
#define INTERNET_FLAG_PRAGMA_NOCACHE
Definition: wininet.h:85
BOOL AsyncInetAcquire(pASYNCINET AsyncInet)
Definition: asyncinet.cpp:162
HANDLE hEventHandleClose
Definition: asyncinet.h:39
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define INFINITE
Definition: serial.h:102
HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
Definition: internet.c:1001
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
HINTERNET hInetFile
Definition: asyncinet.h:33
VOID AsyncInetReadFileLoop(pASYNCINET AsyncInet)
Definition: asyncinet.cpp:314

Referenced by CAppScrnshotPreview::DisplayImage().

◆ AsyncInetRelease()

VOID AsyncInetRelease ( pASYNCINET  AsyncInet)

Definition at line 184 of file asyncinet.cpp.

185 {
186  BOOL bCleanUp = FALSE;
187  if (AsyncInet)
188  {
189  EnterCriticalSection(&(AsyncInet->CriticalSection));
190 
191  ATLASSERT(AsyncInet->ReferenceCnt);
192  AsyncInet->ReferenceCnt--;
193  if (AsyncInet->ReferenceCnt == 0)
194  {
195  bCleanUp = TRUE;
196  }
197 
198  LeaveCriticalSection(&(AsyncInet->CriticalSection));
199 
200  if (bCleanUp)
201  {
202  AsyncInetCleanUp(AsyncInet);
203  }
204  }
205 }
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
#define TRUE
Definition: types.h:120
BOOL AsyncInetCleanUp(pASYNCINET AsyncInet)
Definition: asyncinet.cpp:388
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
CRITICAL_SECTION CriticalSection
Definition: asyncinet.h:38
UINT ReferenceCnt
Definition: asyncinet.h:37
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by AsyncInetReadFileLoop(), AsyncInetStatusCallback(), and CAppScrnshotPreview::ProcessWindowMessage().