[URLMON] Sync with Wine Staging 2.16. CORE-13762
[reactos.git] / reactos / 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
25 #define WIN32_NO_STATUS
26 #define _INC_WINDOWS
27 #define COM_NO_WINDOWS_H
28
29 #define COBJMACROS
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
32
33 #include <windef.h>
34 #include <winbase.h>
35 #include <winreg.h>
36 #include <objbase.h>
37 #include <oleauto.h>
38 #include <urlmon.h>
39 #include <wininet.h>
40 #include <advpub.h>
41 #define NO_SHLWAPI_REG
42 #include <shlwapi.h>
43
44 #include <wine/debug.h>
45 #include <wine/list.h>
46 #include <wine/unicode.h>
47
48 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
49
50 extern HINSTANCE hProxyDll DECLSPEC_HIDDEN;
51 extern HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
52 extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
53 extern HRESULT StdURLMoniker_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
54 extern HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
55 extern HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
56 extern HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
57 extern HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
58 extern HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
59 extern HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
60 extern HRESULT MimeFilter_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
61 extern HRESULT Uri_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
62
63 extern BOOL WINAPI URLMON_DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) DECLSPEC_HIDDEN;
64 extern HRESULT WINAPI URLMON_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv) DECLSPEC_HIDDEN;
65 extern HRESULT WINAPI URLMON_DllRegisterServer(void) DECLSPEC_HIDDEN;
66 extern HRESULT WINAPI URLMON_DllUnregisterServer(void) DECLSPEC_HIDDEN;
67
68 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
69 extern GUID const CLSID_CUri DECLSPEC_HIDDEN;
70
71 /**********************************************************************
72 * Dll lifetime tracking declaration for urlmon.dll
73 */
74 extern LONG URLMON_refCount DECLSPEC_HIDDEN;
75 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
76 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
77
78 extern HINSTANCE urlmon_instance;
79
80 IInternetProtocolInfo *get_protocol_info(LPCWSTR) DECLSPEC_HIDDEN;
81 HRESULT get_protocol_handler(IUri*,CLSID*,BOOL*,IClassFactory**) DECLSPEC_HIDDEN;
82 IInternetProtocol *get_mime_filter(LPCWSTR) DECLSPEC_HIDDEN;
83 BOOL is_registered_protocol(LPCWSTR) DECLSPEC_HIDDEN;
84 HRESULT register_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL) DECLSPEC_HIDDEN;
85 HINTERNET get_internet_session(IInternetBindInfo*) DECLSPEC_HIDDEN;
86 WCHAR *get_useragent(void) DECLSPEC_HIDDEN;
87 void update_user_agent(WCHAR*) DECLSPEC_HIDDEN;
88 void free_session(void) DECLSPEC_HIDDEN;
89
90 HRESULT find_mime_from_ext(const WCHAR*,WCHAR**) DECLSPEC_HIDDEN;
91
92 HRESULT bind_to_storage(IUri*,IBindCtx*,REFIID,void**) DECLSPEC_HIDDEN;
93 HRESULT bind_to_object(IMoniker*,IUri*,IBindCtx*,REFIID,void**ppv) DECLSPEC_HIDDEN;
94
95 HRESULT create_default_callback(IBindStatusCallback**) DECLSPEC_HIDDEN;
96 HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**) DECLSPEC_HIDDEN;
97 IBindStatusCallback *bsc_from_bctx(IBindCtx*) DECLSPEC_HIDDEN;
98
99 typedef HRESULT (*stop_cache_binding_proc_t)(void*,const WCHAR*,HRESULT,const WCHAR*);
100 HRESULT download_to_cache(IUri*,stop_cache_binding_proc_t,void*,IBindStatusCallback*) DECLSPEC_HIDDEN;
101
102 typedef struct ProtocolVtbl ProtocolVtbl;
103
104 typedef struct {
105 const ProtocolVtbl *vtbl;
106
107 IInternetProtocol *protocol;
108 IInternetProtocolSink *protocol_sink;
109
110 DWORD bindf;
111 BINDINFO bind_info;
112
113 HINTERNET request;
114 HINTERNET connection;
115 DWORD flags;
116 HANDLE lock;
117
118 ULONG current_position;
119 ULONG content_length;
120 ULONG available_bytes;
121 ULONG query_available;
122
123 IStream *post_stream;
124
125 LONG priority;
126 } Protocol;
127
128 struct ProtocolVtbl {
129 HRESULT (*open_request)(Protocol*,IUri*,DWORD,HINTERNET,IInternetBindInfo*);
130 HRESULT (*end_request)(Protocol*);
131 HRESULT (*start_downloading)(Protocol*);
132 void (*close_connection)(Protocol*);
133 void (*on_error)(Protocol*,DWORD);
134 };
135
136 /* Flags are needed for, among other things, return HRESULTs from the Read function
137 * to conform to native. For example, Read returns:
138 *
139 * 1. E_PENDING if called before the request has completed,
140 * (flags = 0)
141 * 2. S_FALSE after all data has been read and S_OK has been reported,
142 * (flags = FLAG_REQUEST_COMPLETE | FLAG_ALL_DATA_READ | FLAG_RESULT_REPORTED)
143 * 3. INET_E_DATA_NOT_AVAILABLE if InternetQueryDataAvailable fails. The first time
144 * this occurs, INET_E_DATA_NOT_AVAILABLE will also be reported to the sink,
145 * (flags = FLAG_REQUEST_COMPLETE)
146 * but upon subsequent calls to Read no reporting will take place, yet
147 * InternetQueryDataAvailable will still be called, and, on failure,
148 * INET_E_DATA_NOT_AVAILABLE will still be returned.
149 * (flags = FLAG_REQUEST_COMPLETE | FLAG_RESULT_REPORTED)
150 *
151 * FLAG_FIRST_DATA_REPORTED and FLAG_LAST_DATA_REPORTED are needed for proper
152 * ReportData reporting. For example, if OnResponse returns S_OK, Continue will
153 * report BSCF_FIRSTDATANOTIFICATION, and when all data has been read Read will
154 * report BSCF_INTERMEDIATEDATANOTIFICATION|BSCF_LASTDATANOTIFICATION. However,
155 * if OnResponse does not return S_OK, Continue will not report data, and Read
156 * will report BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION when all
157 * data has been read.
158 */
159 #define FLAG_REQUEST_COMPLETE 0x0001
160 #define FLAG_FIRST_CONTINUE_COMPLETE 0x0002
161 #define FLAG_FIRST_DATA_REPORTED 0x0004
162 #define FLAG_ALL_DATA_READ 0x0008
163 #define FLAG_LAST_DATA_REPORTED 0x0010
164 #define FLAG_RESULT_REPORTED 0x0020
165 #define FLAG_ERROR 0x0040
166 #define FLAG_SYNC_READ 0x0080
167
168 HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
169 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*) DECLSPEC_HIDDEN;
170 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*) DECLSPEC_HIDDEN;
171 HRESULT protocol_lock_request(Protocol*) DECLSPEC_HIDDEN;
172 HRESULT protocol_unlock_request(Protocol*) DECLSPEC_HIDDEN;
173 HRESULT protocol_abort(Protocol*,HRESULT) DECLSPEC_HIDDEN;
174 HRESULT protocol_syncbinding(Protocol*) DECLSPEC_HIDDEN;
175 void protocol_close_connection(Protocol*) DECLSPEC_HIDDEN;
176
177 void find_domain_name(const WCHAR*,DWORD,INT*) DECLSPEC_HIDDEN;
178
179 typedef struct _task_header_t task_header_t;
180
181 typedef struct {
182 IInternetProtocolEx IInternetProtocolEx_iface;
183 IInternetBindInfo IInternetBindInfo_iface;
184 IInternetPriority IInternetPriority_iface;
185 IServiceProvider IServiceProvider_iface;
186 IInternetProtocolSink IInternetProtocolSink_iface;
187 IWinInetHttpInfo IWinInetHttpInfo_iface;
188
189 LONG ref;
190
191 IInternetProtocol *protocol;
192 IWinInetInfo *wininet_info;
193 IWinInetHttpInfo *wininet_http_info;
194
195 IInternetBindInfo *bind_info;
196 IInternetProtocolSink *protocol_sink;
197 IServiceProvider *service_provider;
198 IBindCallbackRedirect *redirect_callback;
199
200 struct {
201 IInternetProtocol IInternetProtocol_iface;
202 IInternetProtocolSink IInternetProtocolSink_iface;
203 } default_protocol_handler;
204 IInternetProtocol *protocol_handler;
205 IInternetProtocolSink *protocol_sink_handler;
206
207 LONG priority;
208
209 BOOL reported_result;
210 BOOL reported_mime;
211 BOOL from_urlmon;
212 DWORD pi;
213
214 DWORD bscf;
215 ULONG progress;
216 ULONG progress_max;
217
218 DWORD apartment_thread;
219 HWND notif_hwnd;
220 DWORD continue_call;
221
222 CRITICAL_SECTION section;
223 task_header_t *task_queue_head, *task_queue_tail;
224
225 BYTE *buf;
226 DWORD buf_size;
227 LPWSTR mime;
228 IUri *uri;
229 BSTR display_uri;
230 } BindProtocol;
231
232 HRESULT create_binding_protocol(BOOL,BindProtocol**) DECLSPEC_HIDDEN;
233 void set_binding_sink(BindProtocol*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
234
235 typedef struct {
236 HWND notif_hwnd;
237 DWORD notif_hwnd_cnt;
238
239 struct list entry;
240 } tls_data_t;
241
242 tls_data_t *get_tls_data(void) DECLSPEC_HIDDEN;
243
244 void unregister_notif_wnd_class(void) DECLSPEC_HIDDEN;
245 HWND get_notif_hwnd(void) DECLSPEC_HIDDEN;
246 void release_notif_hwnd(HWND) DECLSPEC_HIDDEN;
247
248 const char *debugstr_bindstatus(ULONG) DECLSPEC_HIDDEN;
249
250 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
251 {
252 return HeapAlloc(GetProcessHeap(), 0, size);
253 }
254
255 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size)
256 {
257 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
258 }
259
260 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t size)
261 {
262 return HeapReAlloc(GetProcessHeap(), 0, mem, size);
263 }
264
265 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t size)
266 {
267 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
268 }
269
270 static inline BOOL heap_free(void *mem)
271 {
272 return HeapFree(GetProcessHeap(), 0, mem);
273 }
274
275 static inline LPWSTR heap_strdupW(LPCWSTR str)
276 {
277 LPWSTR ret = NULL;
278
279 if(str) {
280 DWORD size;
281
282 size = (strlenW(str)+1)*sizeof(WCHAR);
283 ret = heap_alloc(size);
284 if(ret)
285 memcpy(ret, str, size);
286 }
287
288 return ret;
289 }
290
291 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
292 {
293 LPWSTR ret = NULL;
294
295 if(str) {
296 ret = heap_alloc((len+1)*sizeof(WCHAR));
297 if(ret) {
298 memcpy(ret, str, len*sizeof(WCHAR));
299 ret[len] = 0;
300 }
301 }
302
303 return ret;
304 }
305
306 static inline LPWSTR heap_strdupAtoW(const char *str)
307 {
308 LPWSTR ret = NULL;
309
310 if(str) {
311 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
312 ret = heap_alloc(len*sizeof(WCHAR));
313 if(ret)
314 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
315 }
316
317 return ret;
318 }
319
320 static inline char *heap_strdupWtoA(const WCHAR *str)
321 {
322 char *ret = NULL;
323
324 if(str) {
325 size_t size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
326 ret = heap_alloc(size);
327 if(ret)
328 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
329 }
330
331 return ret;
332 }
333
334 #endif /* __WINE_URLMON_MAIN_H */