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