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 WCHAR
*get_useragent(void) DECLSPEC_HIDDEN
;
87 void update_user_agent(WCHAR
*) DECLSPEC_HIDDEN
;
88 void free_session(void) DECLSPEC_HIDDEN
;
90 HRESULT
find_mime_from_ext(const WCHAR
*,WCHAR
**) DECLSPEC_HIDDEN
;
92 HRESULT
bind_to_storage(IUri
*,IBindCtx
*,REFIID
,void**) DECLSPEC_HIDDEN
;
93 HRESULT
bind_to_object(IMoniker
*,IUri
*,IBindCtx
*,REFIID
,void**ppv
) DECLSPEC_HIDDEN
;
95 HRESULT
create_default_callback(IBindStatusCallback
**) DECLSPEC_HIDDEN
;
96 HRESULT
wrap_callback(IBindStatusCallback
*,IBindStatusCallback
**) DECLSPEC_HIDDEN
;
97 IBindStatusCallback
*bsc_from_bctx(IBindCtx
*) DECLSPEC_HIDDEN
;
99 typedef HRESULT (*stop_cache_binding_proc_t
)(void*,const WCHAR
*,HRESULT
,const WCHAR
*);
100 HRESULT
download_to_cache(IUri
*,stop_cache_binding_proc_t
,void*,IBindStatusCallback
*) DECLSPEC_HIDDEN
;
102 typedef struct ProtocolVtbl ProtocolVtbl
;
105 const ProtocolVtbl
*vtbl
;
107 IInternetProtocol
*protocol
;
108 IInternetProtocolSink
*protocol_sink
;
114 HINTERNET connection
;
118 ULONG current_position
;
119 ULONG content_length
;
120 ULONG available_bytes
;
121 ULONG query_available
;
123 IStream
*post_stream
;
128 struct ProtocolVtbl
{
129 HRESULT (*open_request
)(Protocol
*,IUri
*,DWORD
,HINTERNET
,IInternetBindInfo
*);
130 HRESULT (*end_request
)(Protocol
*);
131 HRESULT (*start_downloading
)(Protocol
*);
132 void (*close_connection
)(Protocol
*);
133 void (*on_error
)(Protocol
*,DWORD
);
136 /* Flags are needed for, among other things, return HRESULTs from the Read function
137 * to conform to native. For example, Read returns:
139 * 1. E_PENDING if called before the request has completed,
141 * 2. S_FALSE after all data has been read and S_OK has been reported,
142 * (flags = FLAG_REQUEST_COMPLETE | FLAG_ALL_DATA_READ | FLAG_RESULT_REPORTED)
143 * 3. INET_E_DATA_NOT_AVAILABLE if InternetQueryDataAvailable fails. The first time
144 * this occurs, INET_E_DATA_NOT_AVAILABLE will also be reported to the sink,
145 * (flags = FLAG_REQUEST_COMPLETE)
146 * but upon subsequent calls to Read no reporting will take place, yet
147 * InternetQueryDataAvailable will still be called, and, on failure,
148 * INET_E_DATA_NOT_AVAILABLE will still be returned.
149 * (flags = FLAG_REQUEST_COMPLETE | FLAG_RESULT_REPORTED)
151 * FLAG_FIRST_DATA_REPORTED and FLAG_LAST_DATA_REPORTED are needed for proper
152 * ReportData reporting. For example, if OnResponse returns S_OK, Continue will
153 * report BSCF_FIRSTDATANOTIFICATION, and when all data has been read Read will
154 * report BSCF_INTERMEDIATEDATANOTIFICATION|BSCF_LASTDATANOTIFICATION. However,
155 * if OnResponse does not return S_OK, Continue will not report data, and Read
156 * will report BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION when all
157 * data has been read.
159 #define FLAG_REQUEST_COMPLETE 0x0001
160 #define FLAG_FIRST_CONTINUE_COMPLETE 0x0002
161 #define FLAG_FIRST_DATA_REPORTED 0x0004
162 #define FLAG_ALL_DATA_READ 0x0008
163 #define FLAG_LAST_DATA_REPORTED 0x0010
164 #define FLAG_RESULT_REPORTED 0x0020
165 #define FLAG_ERROR 0x0040
166 #define FLAG_SYNC_READ 0x0080
168 HRESULT
protocol_start(Protocol
*,IInternetProtocol
*,IUri
*,IInternetProtocolSink
*,IInternetBindInfo
*) DECLSPEC_HIDDEN
;
169 HRESULT
protocol_continue(Protocol
*,PROTOCOLDATA
*) DECLSPEC_HIDDEN
;
170 HRESULT
protocol_read(Protocol
*,void*,ULONG
,ULONG
*) DECLSPEC_HIDDEN
;
171 HRESULT
protocol_lock_request(Protocol
*) DECLSPEC_HIDDEN
;
172 HRESULT
protocol_unlock_request(Protocol
*) DECLSPEC_HIDDEN
;
173 HRESULT
protocol_abort(Protocol
*,HRESULT
) DECLSPEC_HIDDEN
;
174 HRESULT
protocol_syncbinding(Protocol
*) DECLSPEC_HIDDEN
;
175 void protocol_close_connection(Protocol
*) DECLSPEC_HIDDEN
;
177 void find_domain_name(const WCHAR
*,DWORD
,INT
*) DECLSPEC_HIDDEN
;
179 typedef struct _task_header_t task_header_t
;
182 IInternetProtocolEx IInternetProtocolEx_iface
;
183 IInternetBindInfo IInternetBindInfo_iface
;
184 IInternetPriority IInternetPriority_iface
;
185 IServiceProvider IServiceProvider_iface
;
186 IInternetProtocolSink IInternetProtocolSink_iface
;
187 IWinInetHttpInfo IWinInetHttpInfo_iface
;
191 IInternetProtocol
*protocol
;
192 IWinInetInfo
*wininet_info
;
193 IWinInetHttpInfo
*wininet_http_info
;
195 IInternetBindInfo
*bind_info
;
196 IInternetProtocolSink
*protocol_sink
;
197 IServiceProvider
*service_provider
;
198 IBindCallbackRedirect
*redirect_callback
;
201 IInternetProtocol IInternetProtocol_iface
;
202 IInternetProtocolSink IInternetProtocolSink_iface
;
203 } default_protocol_handler
;
204 IInternetProtocol
*protocol_handler
;
205 IInternetProtocolSink
*protocol_sink_handler
;
209 BOOL reported_result
;
218 DWORD apartment_thread
;
222 CRITICAL_SECTION section
;
223 task_header_t
*task_queue_head
, *task_queue_tail
;
232 HRESULT
create_binding_protocol(BOOL
,BindProtocol
**) DECLSPEC_HIDDEN
;
233 void set_binding_sink(BindProtocol
*,IInternetProtocolSink
*,IInternetBindInfo
*) DECLSPEC_HIDDEN
;
237 DWORD notif_hwnd_cnt
;
242 tls_data_t
*get_tls_data(void) DECLSPEC_HIDDEN
;
244 void unregister_notif_wnd_class(void) DECLSPEC_HIDDEN
;
245 HWND
get_notif_hwnd(void) DECLSPEC_HIDDEN
;
246 void release_notif_hwnd(HWND
) DECLSPEC_HIDDEN
;
248 const char *debugstr_bindstatus(ULONG
) DECLSPEC_HIDDEN
;
250 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size
)
252 return HeapAlloc(GetProcessHeap(), 0, size
);
255 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size
)
257 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
260 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc(void *mem
, size_t size
)
262 return HeapReAlloc(GetProcessHeap(), 0, mem
, size
);
265 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem
, size_t size
)
267 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
270 static inline BOOL
heap_free(void *mem
)
272 return HeapFree(GetProcessHeap(), 0, mem
);
275 static inline LPWSTR
heap_strdupW(LPCWSTR str
)
282 size
= (strlenW(str
)+1)*sizeof(WCHAR
);
283 ret
= heap_alloc(size
);
285 memcpy(ret
, str
, size
);
291 static inline LPWSTR
heap_strndupW(LPCWSTR str
, int len
)
296 ret
= heap_alloc((len
+1)*sizeof(WCHAR
));
298 memcpy(ret
, str
, len
*sizeof(WCHAR
));
306 static inline LPWSTR
heap_strdupAtoW(const char *str
)
311 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
312 ret
= heap_alloc(len
*sizeof(WCHAR
));
314 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
320 static inline char *heap_strdupWtoA(const WCHAR
*str
)
325 size_t size
= WideCharToMultiByte(CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
326 ret
= heap_alloc(size
);
328 WideCharToMultiByte(CP_ACP
, 0, str
, -1, ret
, size
, NULL
, NULL
);
334 #endif /* __WINE_URLMON_MAIN_H */