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