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