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
25 #define WIN32_NO_STATUS
27 #define COM_NO_WINDOWS_H
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
41 #define NO_SHLWAPI_REG
44 #include <wine/debug.h>
45 #include <wine/list.h>
46 #include <wine/unicode.h>
48 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
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
;
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
;
68 extern GUID
const CLSID_PSFactoryBuffer DECLSPEC_HIDDEN
;
69 extern GUID
const CLSID_CUri DECLSPEC_HIDDEN
;
71 /**********************************************************************
72 * Dll lifetime tracking declaration for urlmon.dll
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
); }
78 extern HINSTANCE urlmon_instance
;
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
;
89 HRESULT
bind_to_storage(IUri
*,IBindCtx
*,REFIID
,void**) DECLSPEC_HIDDEN
;
90 HRESULT
bind_to_object(IMoniker
*,IUri
*,IBindCtx
*,REFIID
,void**ppv
) DECLSPEC_HIDDEN
;
92 HRESULT
create_default_callback(IBindStatusCallback
**) DECLSPEC_HIDDEN
;
93 HRESULT
wrap_callback(IBindStatusCallback
*,IBindStatusCallback
**) DECLSPEC_HIDDEN
;
94 IBindStatusCallback
*bsc_from_bctx(IBindCtx
*) DECLSPEC_HIDDEN
;
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
;
99 typedef struct ProtocolVtbl ProtocolVtbl
;
102 const ProtocolVtbl
*vtbl
;
104 IInternetProtocol
*protocol
;
105 IInternetProtocolSink
*protocol_sink
;
111 HINTERNET connection
;
115 ULONG current_position
;
116 ULONG content_length
;
117 ULONG available_bytes
;
118 ULONG query_available
;
120 IStream
*post_stream
;
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
);
133 /* Flags are needed for, among other things, return HRESULTs from the Read function
134 * to conform to native. For example, Read returns:
136 * 1. E_PENDING if called before the request has completed,
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)
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.
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
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
;
174 void find_domain_name(const WCHAR
*,DWORD
,INT
*) DECLSPEC_HIDDEN
;
176 typedef struct _task_header_t task_header_t
;
179 IInternetProtocolEx IInternetProtocolEx_iface
;
180 IInternetBindInfo IInternetBindInfo_iface
;
181 IInternetPriority IInternetPriority_iface
;
182 IServiceProvider IServiceProvider_iface
;
183 IInternetProtocolSink IInternetProtocolSink_iface
;
184 IWinInetHttpInfo IWinInetHttpInfo_iface
;
188 IInternetProtocol
*protocol
;
189 IInternetBindInfo
*bind_info
;
190 IInternetProtocolSink
*protocol_sink
;
191 IServiceProvider
*service_provider
;
192 IWinInetInfo
*wininet_info
;
193 IWinInetHttpInfo
*wininet_http_info
;
196 IInternetProtocol IInternetProtocol_iface
;
197 IInternetProtocolSink IInternetProtocolSink_iface
;
198 } default_protocol_handler
;
199 IInternetProtocol
*protocol_handler
;
200 IInternetProtocolSink
*protocol_sink_handler
;
204 BOOL reported_result
;
213 DWORD apartment_thread
;
217 CRITICAL_SECTION section
;
218 task_header_t
*task_queue_head
, *task_queue_tail
;
227 HRESULT
create_binding_protocol(BOOL
,BindProtocol
**) DECLSPEC_HIDDEN
;
228 void set_binding_sink(BindProtocol
*,IInternetProtocolSink
*,IInternetBindInfo
*) DECLSPEC_HIDDEN
;
232 DWORD notif_hwnd_cnt
;
237 tls_data_t
*get_tls_data(void) DECLSPEC_HIDDEN
;
239 HWND
get_notif_hwnd(void) DECLSPEC_HIDDEN
;
240 void release_notif_hwnd(HWND
) DECLSPEC_HIDDEN
;
242 const char *debugstr_bindstatus(ULONG
) DECLSPEC_HIDDEN
;
244 static inline void *heap_alloc(size_t len
)
246 return HeapAlloc(GetProcessHeap(), 0, len
);
249 static inline void *heap_alloc_zero(size_t len
)
251 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
254 static inline void *heap_realloc(void *mem
, size_t len
)
256 return HeapReAlloc(GetProcessHeap(), 0, mem
, len
);
259 static inline void *heap_realloc_zero(void *mem
, size_t len
)
261 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, len
);
264 static inline BOOL
heap_free(void *mem
)
266 return HeapFree(GetProcessHeap(), 0, mem
);
269 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
276 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
277 ret
= heap_alloc(size
);
279 memcpy(ret
, str
, size
);
285 static inline LPWSTR
heap_strndupW(LPCWSTR str
, int len
)
290 ret
= heap_alloc((len
+1)*sizeof(WCHAR
));
292 memcpy(ret
, str
, len
*sizeof(WCHAR
));
300 static inline LPWSTR
heap_strdupAtoW(const char *str
)
305 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
306 ret
= heap_alloc(len
*sizeof(WCHAR
));
308 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
314 static inline char *heap_strdupWtoA(const WCHAR
*str
)
319 size_t size
= WideCharToMultiByte(CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
320 ret
= heap_alloc(size
);
322 WideCharToMultiByte(CP_ACP
, 0, str
, -1, ret
, size
, NULL
, NULL
);
328 #endif /* __WINE_URLMON_MAIN_H */