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