[MSI_WINETEST] Fix build with CMake 3.9.0 and higher (attempt #2)
[reactos.git] / dll / win32 / urlmon / urlmon_main.h
1 /*
2 * Copyright 2002 Huw D M Davies for CodeWeavers
3 * Copyright 2009 Jacek Caban for CodeWeavers
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #ifndef __WINE_URLMON_MAIN_H
21 #define __WINE_URLMON_MAIN_H
22
23 #include <stdarg.h>
24 #ifdef __REACTOS__
25 #include <wchar.h>
26 #endif
27
28 #define COBJMACROS
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #ifdef __REACTOS__
34 #include "winnls.h"
35 #endif
36 #include "ole2.h"
37 #include "urlmon.h"
38 #include "wininet.h"
39
40 #include "wine/heap.h"
41 #include "wine/list.h"
42
43 extern HINSTANCE hProxyDll DECLSPEC_HIDDEN;
44 extern HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
45 extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
46 extern HRESULT StdURLMoniker_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
47 extern HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
48 extern HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
49 extern HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
50 extern HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
51 extern HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
52 extern HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
53 extern HRESULT MimeFilter_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
54 extern HRESULT Uri_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
55
56 extern BOOL WINAPI URLMON_DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) DECLSPEC_HIDDEN;
57 extern HRESULT WINAPI URLMON_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv) DECLSPEC_HIDDEN;
58 extern HRESULT WINAPI URLMON_DllRegisterServer(void) DECLSPEC_HIDDEN;
59 extern HRESULT WINAPI URLMON_DllUnregisterServer(void) DECLSPEC_HIDDEN;
60
61 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
62 extern GUID const CLSID_CUri DECLSPEC_HIDDEN;
63
64 /**********************************************************************
65 * Dll lifetime tracking declaration for urlmon.dll
66 */
67 extern LONG URLMON_refCount DECLSPEC_HIDDEN;
68 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
69 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
70
71 extern HINSTANCE urlmon_instance;
72
73 IInternetProtocolInfo *get_protocol_info(LPCWSTR) DECLSPEC_HIDDEN;
74 HRESULT get_protocol_handler(IUri*,CLSID*,IClassFactory**) DECLSPEC_HIDDEN;
75 IInternetProtocol *get_mime_filter(LPCWSTR) DECLSPEC_HIDDEN;
76 BOOL is_registered_protocol(LPCWSTR) DECLSPEC_HIDDEN;
77 HRESULT register_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL) DECLSPEC_HIDDEN;
78 HINTERNET get_internet_session(IInternetBindInfo*) DECLSPEC_HIDDEN;
79 WCHAR *get_useragent(void) DECLSPEC_HIDDEN;
80 void update_user_agent(WCHAR*) DECLSPEC_HIDDEN;
81 void free_session(void) DECLSPEC_HIDDEN;
82
83 HRESULT find_mime_from_ext(const WCHAR*,WCHAR**) DECLSPEC_HIDDEN;
84
85 HRESULT bind_to_storage(IUri*,IBindCtx*,REFIID,void**) DECLSPEC_HIDDEN;
86 HRESULT bind_to_object(IMoniker*,IUri*,IBindCtx*,REFIID,void**ppv) DECLSPEC_HIDDEN;
87
88 HRESULT create_default_callback(IBindStatusCallback**) DECLSPEC_HIDDEN;
89 HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**) DECLSPEC_HIDDEN;
90 IBindStatusCallback *bsc_from_bctx(IBindCtx*) DECLSPEC_HIDDEN;
91
92 typedef HRESULT (*stop_cache_binding_proc_t)(void*,const WCHAR*,HRESULT,const WCHAR*);
93 HRESULT download_to_cache(IUri*,stop_cache_binding_proc_t,void*,IBindStatusCallback*) DECLSPEC_HIDDEN;
94
95 typedef struct ProtocolVtbl ProtocolVtbl;
96
97 typedef struct {
98 const ProtocolVtbl *vtbl;
99
100 IInternetProtocol *protocol;
101 IInternetProtocolSink *protocol_sink;
102
103 DWORD bindf;
104 BINDINFO bind_info;
105
106 HINTERNET request;
107 HINTERNET connection;
108 DWORD flags;
109 HANDLE lock;
110
111 ULONG current_position;
112 ULONG content_length;
113 ULONG available_bytes;
114 ULONG query_available;
115
116 IStream *post_stream;
117
118 LONG priority;
119 } Protocol;
120
121 struct ProtocolVtbl {
122 HRESULT (*open_request)(Protocol*,IUri*,DWORD,HINTERNET,IInternetBindInfo*);
123 HRESULT (*end_request)(Protocol*);
124 HRESULT (*start_downloading)(Protocol*);
125 void (*close_connection)(Protocol*);
126 void (*on_error)(Protocol*,DWORD);
127 };
128
129 /* Flags are needed for, among other things, return HRESULTs from the Read function
130 * to conform to native. For example, Read returns:
131 *
132 * 1. E_PENDING if called before the request has completed,
133 * (flags = 0)
134 * 2. S_FALSE after all data has been read and S_OK has been reported,
135 * (flags = FLAG_REQUEST_COMPLETE | FLAG_ALL_DATA_READ | FLAG_RESULT_REPORTED)
136 * 3. INET_E_DATA_NOT_AVAILABLE if InternetQueryDataAvailable fails. The first time
137 * this occurs, INET_E_DATA_NOT_AVAILABLE will also be reported to the sink,
138 * (flags = FLAG_REQUEST_COMPLETE)
139 * but upon subsequent calls to Read no reporting will take place, yet
140 * InternetQueryDataAvailable will still be called, and, on failure,
141 * INET_E_DATA_NOT_AVAILABLE will still be returned.
142 * (flags = FLAG_REQUEST_COMPLETE | FLAG_RESULT_REPORTED)
143 *
144 * FLAG_FIRST_DATA_REPORTED and FLAG_LAST_DATA_REPORTED are needed for proper
145 * ReportData reporting. For example, if OnResponse returns S_OK, Continue will
146 * report BSCF_FIRSTDATANOTIFICATION, and when all data has been read Read will
147 * report BSCF_INTERMEDIATEDATANOTIFICATION|BSCF_LASTDATANOTIFICATION. However,
148 * if OnResponse does not return S_OK, Continue will not report data, and Read
149 * will report BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION when all
150 * data has been read.
151 */
152 #define FLAG_REQUEST_COMPLETE 0x0001
153 #define FLAG_FIRST_CONTINUE_COMPLETE 0x0002
154 #define FLAG_FIRST_DATA_REPORTED 0x0004
155 #define FLAG_ALL_DATA_READ 0x0008
156 #define FLAG_LAST_DATA_REPORTED 0x0010
157 #define FLAG_RESULT_REPORTED 0x0020
158 #define FLAG_ERROR 0x0040
159 #define FLAG_SYNC_READ 0x0080
160
161 HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
162 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*) DECLSPEC_HIDDEN;
163 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*) DECLSPEC_HIDDEN;
164 HRESULT protocol_lock_request(Protocol*) DECLSPEC_HIDDEN;
165 HRESULT protocol_unlock_request(Protocol*) DECLSPEC_HIDDEN;
166 HRESULT protocol_abort(Protocol*,HRESULT) DECLSPEC_HIDDEN;
167 HRESULT protocol_syncbinding(Protocol*) DECLSPEC_HIDDEN;
168 void protocol_close_connection(Protocol*) DECLSPEC_HIDDEN;
169
170 void find_domain_name(const WCHAR*,DWORD,INT*) DECLSPEC_HIDDEN;
171
172 typedef struct _task_header_t task_header_t;
173
174 typedef struct {
175 IInternetProtocolEx IInternetProtocolEx_iface;
176 IInternetBindInfo IInternetBindInfo_iface;
177 IInternetPriority IInternetPriority_iface;
178 IServiceProvider IServiceProvider_iface;
179 IInternetProtocolSink IInternetProtocolSink_iface;
180
181 LONG ref;
182
183 IUnknown *protocol_unk;
184 IInternetProtocol *protocol;
185
186 IInternetBindInfo *bind_info;
187 IInternetProtocolSink *protocol_sink;
188 IServiceProvider *service_provider;
189 IBindCallbackRedirect *redirect_callback;
190
191 struct {
192 IInternetProtocol IInternetProtocol_iface;
193 IInternetProtocolSink IInternetProtocolSink_iface;
194 } default_protocol_handler;
195 IInternetProtocol *protocol_handler;
196 IInternetProtocolSink *protocol_sink_handler;
197
198 LONG priority;
199
200 BOOL reported_result;
201 BOOL reported_mime;
202 DWORD pi;
203
204 DWORD bscf;
205 ULONG progress;
206 ULONG progress_max;
207
208 DWORD apartment_thread;
209 HWND notif_hwnd;
210 DWORD continue_call;
211
212 CRITICAL_SECTION section;
213 task_header_t *task_queue_head, *task_queue_tail;
214
215 BYTE *buf;
216 DWORD buf_size;
217 LPWSTR mime;
218 IUri *uri;
219 BSTR display_uri;
220 } BindProtocol;
221
222 HRESULT create_binding_protocol(BindProtocol**) DECLSPEC_HIDDEN;
223 void set_binding_sink(BindProtocol*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
224
225 typedef struct {
226 HWND notif_hwnd;
227 DWORD notif_hwnd_cnt;
228
229 struct list entry;
230 } tls_data_t;
231
232 tls_data_t *get_tls_data(void) DECLSPEC_HIDDEN;
233
234 void unregister_notif_wnd_class(void) DECLSPEC_HIDDEN;
235 HWND get_notif_hwnd(void) DECLSPEC_HIDDEN;
236 void release_notif_hwnd(HWND) DECLSPEC_HIDDEN;
237
238 const char *debugstr_bindstatus(ULONG) DECLSPEC_HIDDEN;
239
240 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t size)
241 {
242 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
243 }
244
245 static inline LPWSTR heap_strdupW(LPCWSTR str)
246 {
247 LPWSTR ret = NULL;
248
249 if(str) {
250 DWORD size;
251
252 size = (lstrlenW(str)+1)*sizeof(WCHAR);
253 ret = heap_alloc(size);
254 if(ret)
255 memcpy(ret, str, size);
256 }
257
258 return ret;
259 }
260
261 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
262 {
263 LPWSTR ret = NULL;
264
265 if(str) {
266 ret = heap_alloc((len+1)*sizeof(WCHAR));
267 if(ret) {
268 memcpy(ret, str, len*sizeof(WCHAR));
269 ret[len] = 0;
270 }
271 }
272
273 return ret;
274 }
275
276 static inline LPWSTR heap_strdupAtoW(const char *str)
277 {
278 LPWSTR ret = NULL;
279
280 if(str) {
281 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
282 ret = heap_alloc(len*sizeof(WCHAR));
283 if(ret)
284 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
285 }
286
287 return ret;
288 }
289
290 static inline char *heap_strdupWtoA(const WCHAR *str)
291 {
292 char *ret = NULL;
293
294 if(str) {
295 size_t size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
296 ret = heap_alloc(size);
297 if(ret)
298 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
299 }
300
301 return ret;
302 }
303
304 #endif /* __WINE_URLMON_MAIN_H */