* Sync up to trunk HEAD (r62975).
[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
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 LPWSTR get_useragent(void) DECLSPEC_HIDDEN;
87 void free_session(void) DECLSPEC_HIDDEN;
88
89 HRESULT bind_to_storage(IUri*,IBindCtx*,REFIID,void**) DECLSPEC_HIDDEN;
90 HRESULT bind_to_object(IMoniker*,IUri*,IBindCtx*,REFIID,void**ppv) DECLSPEC_HIDDEN;
91
92 HRESULT create_default_callback(IBindStatusCallback**) DECLSPEC_HIDDEN;
93 HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**) DECLSPEC_HIDDEN;
94 IBindStatusCallback *bsc_from_bctx(IBindCtx*) DECLSPEC_HIDDEN;
95
96 typedef HRESULT (*stop_cache_binding_proc_t)(void*,const WCHAR*,HRESULT,const WCHAR*);
97 HRESULT download_to_cache(IUri*,stop_cache_binding_proc_t,void*,IBindStatusCallback*) DECLSPEC_HIDDEN;
98
99 typedef struct ProtocolVtbl ProtocolVtbl;
100
101 typedef struct {
102 const ProtocolVtbl *vtbl;
103
104 IInternetProtocol *protocol;
105 IInternetProtocolSink *protocol_sink;
106
107 DWORD bindf;
108 BINDINFO bind_info;
109
110 HINTERNET request;
111 HINTERNET connection;
112 DWORD flags;
113 HANDLE lock;
114
115 ULONG current_position;
116 ULONG content_length;
117 ULONG available_bytes;
118 ULONG query_available;
119
120 IStream *post_stream;
121
122 LONG priority;
123 } Protocol;
124
125 struct ProtocolVtbl {
126 HRESULT (*open_request)(Protocol*,IUri*,DWORD,HINTERNET,IInternetBindInfo*);
127 HRESULT (*end_request)(Protocol*);
128 HRESULT (*start_downloading)(Protocol*);
129 void (*close_connection)(Protocol*);
130 void (*on_error)(Protocol*,DWORD);
131 };
132
133 /* Flags are needed for, among other things, return HRESULTs from the Read function
134 * to conform to native. For example, Read returns:
135 *
136 * 1. E_PENDING if called before the request has completed,
137 * (flags = 0)
138 * 2. S_FALSE after all data has been read and S_OK has been reported,
139 * (flags = FLAG_REQUEST_COMPLETE | FLAG_ALL_DATA_READ | FLAG_RESULT_REPORTED)
140 * 3. INET_E_DATA_NOT_AVAILABLE if InternetQueryDataAvailable fails. The first time
141 * this occurs, INET_E_DATA_NOT_AVAILABLE will also be reported to the sink,
142 * (flags = FLAG_REQUEST_COMPLETE)
143 * but upon subsequent calls to Read no reporting will take place, yet
144 * InternetQueryDataAvailable will still be called, and, on failure,
145 * INET_E_DATA_NOT_AVAILABLE will still be returned.
146 * (flags = FLAG_REQUEST_COMPLETE | FLAG_RESULT_REPORTED)
147 *
148 * FLAG_FIRST_DATA_REPORTED and FLAG_LAST_DATA_REPORTED are needed for proper
149 * ReportData reporting. For example, if OnResponse returns S_OK, Continue will
150 * report BSCF_FIRSTDATANOTIFICATION, and when all data has been read Read will
151 * report BSCF_INTERMEDIATEDATANOTIFICATION|BSCF_LASTDATANOTIFICATION. However,
152 * if OnResponse does not return S_OK, Continue will not report data, and Read
153 * will report BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION when all
154 * data has been read.
155 */
156 #define FLAG_REQUEST_COMPLETE 0x0001
157 #define FLAG_FIRST_CONTINUE_COMPLETE 0x0002
158 #define FLAG_FIRST_DATA_REPORTED 0x0004
159 #define FLAG_ALL_DATA_READ 0x0008
160 #define FLAG_LAST_DATA_REPORTED 0x0010
161 #define FLAG_RESULT_REPORTED 0x0020
162 #define FLAG_ERROR 0x0040
163 #define FLAG_SYNC_READ 0x0080
164
165 HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
166 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*) DECLSPEC_HIDDEN;
167 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*) DECLSPEC_HIDDEN;
168 HRESULT protocol_lock_request(Protocol*) DECLSPEC_HIDDEN;
169 HRESULT protocol_unlock_request(Protocol*) DECLSPEC_HIDDEN;
170 HRESULT protocol_abort(Protocol*,HRESULT) DECLSPEC_HIDDEN;
171 HRESULT protocol_syncbinding(Protocol*) DECLSPEC_HIDDEN;
172 void protocol_close_connection(Protocol*) DECLSPEC_HIDDEN;
173
174 void find_domain_name(const WCHAR*,DWORD,INT*) DECLSPEC_HIDDEN;
175
176 typedef struct _task_header_t task_header_t;
177
178 typedef struct {
179 IInternetProtocolEx IInternetProtocolEx_iface;
180 IInternetBindInfo IInternetBindInfo_iface;
181 IInternetPriority IInternetPriority_iface;
182 IServiceProvider IServiceProvider_iface;
183 IInternetProtocolSink IInternetProtocolSink_iface;
184 IWinInetHttpInfo IWinInetHttpInfo_iface;
185
186 LONG ref;
187
188 IInternetProtocol *protocol;
189 IInternetBindInfo *bind_info;
190 IInternetProtocolSink *protocol_sink;
191 IServiceProvider *service_provider;
192 IWinInetInfo *wininet_info;
193 IWinInetHttpInfo *wininet_http_info;
194
195 struct {
196 IInternetProtocol IInternetProtocol_iface;
197 IInternetProtocolSink IInternetProtocolSink_iface;
198 } default_protocol_handler;
199 IInternetProtocol *protocol_handler;
200 IInternetProtocolSink *protocol_sink_handler;
201
202 LONG priority;
203
204 BOOL reported_result;
205 BOOL reported_mime;
206 BOOL from_urlmon;
207 DWORD pi;
208
209 DWORD bscf;
210 ULONG progress;
211 ULONG progress_max;
212
213 DWORD apartment_thread;
214 HWND notif_hwnd;
215 DWORD continue_call;
216
217 CRITICAL_SECTION section;
218 task_header_t *task_queue_head, *task_queue_tail;
219
220 BYTE *buf;
221 DWORD buf_size;
222 LPWSTR mime;
223 IUri *uri;
224 BSTR display_uri;
225 } BindProtocol;
226
227 HRESULT create_binding_protocol(BOOL,BindProtocol**) DECLSPEC_HIDDEN;
228 void set_binding_sink(BindProtocol*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
229
230 typedef struct {
231 HWND notif_hwnd;
232 DWORD notif_hwnd_cnt;
233
234 struct list entry;
235 } tls_data_t;
236
237 tls_data_t *get_tls_data(void) DECLSPEC_HIDDEN;
238
239 HWND get_notif_hwnd(void) DECLSPEC_HIDDEN;
240 void release_notif_hwnd(HWND) DECLSPEC_HIDDEN;
241
242 const char *debugstr_bindstatus(ULONG) DECLSPEC_HIDDEN;
243
244 static inline void *heap_alloc(size_t len)
245 {
246 return HeapAlloc(GetProcessHeap(), 0, len);
247 }
248
249 static inline void *heap_alloc_zero(size_t len)
250 {
251 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
252 }
253
254 static inline void *heap_realloc(void *mem, size_t len)
255 {
256 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
257 }
258
259 static inline void *heap_realloc_zero(void *mem, size_t len)
260 {
261 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
262 }
263
264 static inline BOOL heap_free(void *mem)
265 {
266 return HeapFree(GetProcessHeap(), 0, mem);
267 }
268
269 static inline LPWSTR heap_strdupW(LPCWSTR str)
270 {
271 LPWSTR ret = NULL;
272
273 if(str) {
274 DWORD size;
275
276 size = (strlenW(str)+1)*sizeof(WCHAR);
277 ret = heap_alloc(size);
278 if(ret)
279 memcpy(ret, str, size);
280 }
281
282 return ret;
283 }
284
285 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
286 {
287 LPWSTR ret = NULL;
288
289 if(str) {
290 ret = heap_alloc((len+1)*sizeof(WCHAR));
291 if(ret) {
292 memcpy(ret, str, len*sizeof(WCHAR));
293 ret[len] = 0;
294 }
295 }
296
297 return ret;
298 }
299
300 static inline LPWSTR heap_strdupAtoW(const char *str)
301 {
302 LPWSTR ret = NULL;
303
304 if(str) {
305 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
306 ret = heap_alloc(len*sizeof(WCHAR));
307 if(ret)
308 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
309 }
310
311 return ret;
312 }
313
314 static inline char *heap_strdupWtoA(const WCHAR *str)
315 {
316 char *ret = NULL;
317
318 if(str) {
319 size_t size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
320 ret = heap_alloc(size);
321 if(ret)
322 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
323 }
324
325 return ret;
326 }
327
328 #endif /* __WINE_URLMON_MAIN_H */