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