riched20: Move run extent calculation to wrap.c.
[wine/testsucceed.git] / dlls / urlmon / urlmon_main.h
blob01de984191d57337ede244961311ea3666a5b0f7
1 /*
2 * Copyright 2002 Huw D M Davies for CodeWeavers
3 * Copyright 2009 Jacek Caban for CodeWeavers
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.
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.
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
20 #ifndef __WINE_URLMON_MAIN_H
21 #define __WINE_URLMON_MAIN_H
23 #include <stdarg.h>
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "ole2.h"
33 #include "urlmon.h"
34 #include "wininet.h"
36 #include "wine/unicode.h"
37 #include "wine/list.h"
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 extern HRESULT Uri_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) DECLSPEC_HIDDEN;
52 extern BOOL WINAPI URLMON_DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) DECLSPEC_HIDDEN;
53 extern HRESULT WINAPI URLMON_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv) DECLSPEC_HIDDEN;
54 extern HRESULT WINAPI URLMON_DllRegisterServer(void) DECLSPEC_HIDDEN;
55 extern HRESULT WINAPI URLMON_DllUnregisterServer(void) DECLSPEC_HIDDEN;
57 extern GUID const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN;
58 extern GUID const CLSID_CUri DECLSPEC_HIDDEN;
60 /**********************************************************************
61 * Dll lifetime tracking declaration for urlmon.dll
63 extern LONG URLMON_refCount DECLSPEC_HIDDEN;
64 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
65 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
67 extern HINSTANCE urlmon_instance;
69 IInternetProtocolInfo *get_protocol_info(LPCWSTR) DECLSPEC_HIDDEN;
70 HRESULT get_protocol_handler(IUri*,CLSID*,BOOL*,IClassFactory**) DECLSPEC_HIDDEN;
71 IInternetProtocol *get_mime_filter(LPCWSTR) DECLSPEC_HIDDEN;
72 BOOL is_registered_protocol(LPCWSTR) DECLSPEC_HIDDEN;
73 HRESULT register_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL) DECLSPEC_HIDDEN;
74 HINTERNET get_internet_session(IInternetBindInfo*) DECLSPEC_HIDDEN;
75 LPWSTR get_useragent(void) DECLSPEC_HIDDEN;
76 void free_session(void) DECLSPEC_HIDDEN;
78 HRESULT bind_to_storage(IUri*,IBindCtx*,REFIID,void**) DECLSPEC_HIDDEN;
79 HRESULT bind_to_object(IMoniker*,IUri*,IBindCtx*,REFIID,void**ppv) DECLSPEC_HIDDEN;
81 HRESULT create_default_callback(IBindStatusCallback**) DECLSPEC_HIDDEN;
82 HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**) DECLSPEC_HIDDEN;
83 IBindStatusCallback *bsc_from_bctx(IBindCtx*) DECLSPEC_HIDDEN;
85 typedef HRESULT (*stop_cache_binding_proc_t)(void*,const WCHAR*,HRESULT,const WCHAR*);
86 HRESULT download_to_cache(IUri*,stop_cache_binding_proc_t,void*,IBindStatusCallback*) DECLSPEC_HIDDEN;
88 typedef struct ProtocolVtbl ProtocolVtbl;
90 typedef struct {
91 const ProtocolVtbl *vtbl;
93 IInternetProtocol *protocol;
94 IInternetProtocolSink *protocol_sink;
96 DWORD bindf;
97 BINDINFO bind_info;
99 HINTERNET request;
100 HINTERNET connection;
101 DWORD flags;
102 HANDLE lock;
104 ULONG current_position;
105 ULONG content_length;
106 ULONG available_bytes;
108 IStream *post_stream;
110 LONG priority;
111 } Protocol;
113 struct ProtocolVtbl {
114 HRESULT (*open_request)(Protocol*,IUri*,DWORD,HINTERNET,IInternetBindInfo*);
115 HRESULT (*end_request)(Protocol*);
116 HRESULT (*start_downloading)(Protocol*);
117 void (*close_connection)(Protocol*);
118 void (*on_error)(Protocol*,DWORD);
121 /* Flags are needed for, among other things, return HRESULTs from the Read function
122 * to conform to native. For example, Read returns:
124 * 1. E_PENDING if called before the request has completed,
125 * (flags = 0)
126 * 2. S_FALSE after all data has been read and S_OK has been reported,
127 * (flags = FLAG_REQUEST_COMPLETE | FLAG_ALL_DATA_READ | FLAG_RESULT_REPORTED)
128 * 3. INET_E_DATA_NOT_AVAILABLE if InternetQueryDataAvailable fails. The first time
129 * this occurs, INET_E_DATA_NOT_AVAILABLE will also be reported to the sink,
130 * (flags = FLAG_REQUEST_COMPLETE)
131 * but upon subsequent calls to Read no reporting will take place, yet
132 * InternetQueryDataAvailable will still be called, and, on failure,
133 * INET_E_DATA_NOT_AVAILABLE will still be returned.
134 * (flags = FLAG_REQUEST_COMPLETE | FLAG_RESULT_REPORTED)
136 * FLAG_FIRST_DATA_REPORTED and FLAG_LAST_DATA_REPORTED are needed for proper
137 * ReportData reporting. For example, if OnResponse returns S_OK, Continue will
138 * report BSCF_FIRSTDATANOTIFICATION, and when all data has been read Read will
139 * report BSCF_INTERMEDIATEDATANOTIFICATION|BSCF_LASTDATANOTIFICATION. However,
140 * if OnResponse does not return S_OK, Continue will not report data, and Read
141 * will report BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION when all
142 * data has been read.
144 #define FLAG_REQUEST_COMPLETE 0x0001
145 #define FLAG_FIRST_CONTINUE_COMPLETE 0x0002
146 #define FLAG_FIRST_DATA_REPORTED 0x0004
147 #define FLAG_ALL_DATA_READ 0x0008
148 #define FLAG_LAST_DATA_REPORTED 0x0010
149 #define FLAG_RESULT_REPORTED 0x0020
150 #define FLAG_ERROR 0x0040
152 HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
153 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*) DECLSPEC_HIDDEN;
154 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*) DECLSPEC_HIDDEN;
155 HRESULT protocol_lock_request(Protocol*) DECLSPEC_HIDDEN;
156 HRESULT protocol_unlock_request(Protocol*) DECLSPEC_HIDDEN;
157 HRESULT protocol_abort(Protocol*,HRESULT) DECLSPEC_HIDDEN;
158 void protocol_close_connection(Protocol*) DECLSPEC_HIDDEN;
160 void find_domain_name(const WCHAR*,DWORD,INT*) DECLSPEC_HIDDEN;
162 typedef struct _task_header_t task_header_t;
164 typedef struct {
165 IInternetProtocolEx IInternetProtocolEx_iface;
166 IInternetBindInfo IInternetBindInfo_iface;
167 IInternetPriority IInternetPriority_iface;
168 IServiceProvider IServiceProvider_iface;
169 IInternetProtocolSink IInternetProtocolSink_iface;
170 IWinInetHttpInfo IWinInetHttpInfo_iface;
172 LONG ref;
174 IInternetProtocol *protocol;
175 IInternetBindInfo *bind_info;
176 IInternetProtocolSink *protocol_sink;
177 IServiceProvider *service_provider;
178 IWinInetInfo *wininet_info;
179 IWinInetHttpInfo *wininet_http_info;
181 struct {
182 IInternetProtocol IInternetProtocol_iface;
183 IInternetProtocolSink IInternetProtocolSink_iface;
184 } default_protocol_handler;
185 IInternetProtocol *protocol_handler;
186 IInternetProtocolSink *protocol_sink_handler;
188 LONG priority;
190 BOOL reported_result;
191 BOOL reported_mime;
192 BOOL from_urlmon;
193 DWORD pi;
195 DWORD bscf;
196 ULONG progress;
197 ULONG progress_max;
199 DWORD apartment_thread;
200 HWND notif_hwnd;
201 DWORD continue_call;
203 CRITICAL_SECTION section;
204 task_header_t *task_queue_head, *task_queue_tail;
206 BYTE *buf;
207 DWORD buf_size;
208 LPWSTR mime;
209 IUri *uri;
210 BSTR display_uri;
211 } BindProtocol;
213 HRESULT create_binding_protocol(BOOL,BindProtocol**) DECLSPEC_HIDDEN;
214 void set_binding_sink(BindProtocol*,IInternetProtocolSink*,IInternetBindInfo*) DECLSPEC_HIDDEN;
216 typedef struct {
217 HWND notif_hwnd;
218 DWORD notif_hwnd_cnt;
220 struct list entry;
221 } tls_data_t;
223 tls_data_t *get_tls_data(void) DECLSPEC_HIDDEN;
225 HWND get_notif_hwnd(void) DECLSPEC_HIDDEN;
226 void release_notif_hwnd(HWND) DECLSPEC_HIDDEN;
228 const char *debugstr_bindstatus(ULONG) DECLSPEC_HIDDEN;
230 static inline void *heap_alloc(size_t len)
232 return HeapAlloc(GetProcessHeap(), 0, len);
235 static inline void *heap_alloc_zero(size_t len)
237 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
240 static inline void *heap_realloc(void *mem, size_t len)
242 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
245 static inline void *heap_realloc_zero(void *mem, size_t len)
247 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
250 static inline BOOL heap_free(void *mem)
252 return HeapFree(GetProcessHeap(), 0, mem);
255 static inline LPWSTR heap_strdupW(LPCWSTR str)
257 LPWSTR ret = NULL;
259 if(str) {
260 DWORD size;
262 size = (strlenW(str)+1)*sizeof(WCHAR);
263 ret = heap_alloc(size);
264 if(ret)
265 memcpy(ret, str, size);
268 return ret;
271 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
273 LPWSTR ret = NULL;
275 if(str) {
276 ret = heap_alloc((len+1)*sizeof(WCHAR));
277 if(ret) {
278 memcpy(ret, str, len*sizeof(WCHAR));
279 ret[len] = 0;
283 return ret;
286 static inline LPWSTR heap_strdupAtoW(const char *str)
288 LPWSTR ret = NULL;
290 if(str) {
291 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
292 ret = heap_alloc(len*sizeof(WCHAR));
293 if(ret)
294 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
297 return ret;
300 static inline char *heap_strdupWtoA(const WCHAR *str)
302 char *ret = NULL;
304 if(str) {
305 size_t size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
306 ret = heap_alloc(size);
307 if(ret)
308 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
311 return ret;
314 #endif /* __WINE_URLMON_MAIN_H */