hlink: Use ifaces instead of vtbl pointers in ExtensionService.
[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);
41 extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
42 extern HRESULT StdURLMoniker_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
43 extern HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
44 extern HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
45 extern HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
46 extern HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
47 extern HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
48 extern HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
49 extern HRESULT MimeFilter_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
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
58 /**********************************************************************
59  * Dll lifetime tracking declaration for urlmon.dll
60  */
61 extern LONG URLMON_refCount;
62 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
63 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
64
65 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
66
67 IInternetProtocolInfo *get_protocol_info(LPCWSTR);
68 HRESULT get_protocol_handler(IUri*,CLSID*,BOOL*,IClassFactory**);
69 IInternetProtocol *get_mime_filter(LPCWSTR);
70 BOOL is_registered_protocol(LPCWSTR);
71 void register_urlmon_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL);
72 HINTERNET get_internet_session(IInternetBindInfo*);
73 LPWSTR get_useragent(void);
74 void free_session(void);
75
76 HRESULT bind_to_storage(IUri*,IBindCtx*,REFIID,void**);
77 HRESULT bind_to_object(IMoniker*,IUri*,IBindCtx*,REFIID,void**ppv);
78
79 HRESULT create_binding_protocol(BOOL,IInternetProtocolEx**);
80 void set_binding_sink(IInternetProtocolEx*,IInternetProtocolSink*,IInternetBindInfo*);
81 IWinInetInfo *get_wininet_info(IInternetProtocolEx*);
82 HRESULT create_default_callback(IBindStatusCallback**);
83 HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**);
84
85 typedef struct ProtocolVtbl ProtocolVtbl;
86
87 typedef struct {
88     const ProtocolVtbl *vtbl;
89
90     IInternetProtocol *protocol;
91     IInternetProtocolSink *protocol_sink;
92
93     DWORD bindf;
94     BINDINFO bind_info;
95
96     HINTERNET request;
97     HINTERNET connection;
98     DWORD flags;
99     HANDLE lock;
100
101     ULONG current_position;
102     ULONG content_length;
103     ULONG available_bytes;
104
105     IStream *post_stream;
106
107     LONG priority;
108 } Protocol;
109
110 struct ProtocolVtbl {
111     HRESULT (*open_request)(Protocol*,IUri*,DWORD,HINTERNET,IInternetBindInfo*);
112     HRESULT (*end_request)(Protocol*);
113     HRESULT (*start_downloading)(Protocol*);
114     void (*close_connection)(Protocol*);
115     void (*on_error)(Protocol*,DWORD);
116 };
117
118 /* Flags are needed for, among other things, return HRESULTs from the Read function
119  * to conform to native. For example, Read returns:
120  *
121  * 1. E_PENDING if called before the request has completed,
122  *        (flags = 0)
123  * 2. S_FALSE after all data has been read and S_OK has been reported,
124  *        (flags = FLAG_REQUEST_COMPLETE | FLAG_ALL_DATA_READ | FLAG_RESULT_REPORTED)
125  * 3. INET_E_DATA_NOT_AVAILABLE if InternetQueryDataAvailable fails. The first time
126  *    this occurs, INET_E_DATA_NOT_AVAILABLE will also be reported to the sink,
127  *        (flags = FLAG_REQUEST_COMPLETE)
128  *    but upon subsequent calls to Read no reporting will take place, yet
129  *    InternetQueryDataAvailable will still be called, and, on failure,
130  *    INET_E_DATA_NOT_AVAILABLE will still be returned.
131  *        (flags = FLAG_REQUEST_COMPLETE | FLAG_RESULT_REPORTED)
132  *
133  * FLAG_FIRST_DATA_REPORTED and FLAG_LAST_DATA_REPORTED are needed for proper
134  * ReportData reporting. For example, if OnResponse returns S_OK, Continue will
135  * report BSCF_FIRSTDATANOTIFICATION, and when all data has been read Read will
136  * report BSCF_INTERMEDIATEDATANOTIFICATION|BSCF_LASTDATANOTIFICATION. However,
137  * if OnResponse does not return S_OK, Continue will not report data, and Read
138  * will report BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION when all
139  * data has been read.
140  */
141 #define FLAG_REQUEST_COMPLETE         0x0001
142 #define FLAG_FIRST_CONTINUE_COMPLETE  0x0002
143 #define FLAG_FIRST_DATA_REPORTED      0x0004
144 #define FLAG_ALL_DATA_READ            0x0008
145 #define FLAG_LAST_DATA_REPORTED       0x0010
146 #define FLAG_RESULT_REPORTED          0x0020
147 #define FLAG_ERROR                    0x0040
148
149 HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*);
150 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*);
151 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*);
152 HRESULT protocol_lock_request(Protocol*);
153 HRESULT protocol_unlock_request(Protocol*);
154 HRESULT protocol_abort(Protocol*,HRESULT);
155 void protocol_close_connection(Protocol*);
156
157 typedef struct {
158     const IInternetProtocolVtbl      *lpIInternetProtocolVtbl;
159     const IInternetProtocolSinkVtbl  *lpIInternetProtocolSinkVtbl;
160
161     LONG ref;
162
163     IInternetProtocolSink *protocol_sink;
164     IInternetProtocol *protocol;
165 } ProtocolProxy;
166
167 #define PROTOCOL(x)  ((IInternetProtocol*)       &(x)->lpIInternetProtocolVtbl)
168 #define PROTSINK(x)  ((IInternetProtocolSink*)   &(x)->lpIInternetProtocolSinkVtbl)
169
170 HRESULT create_protocol_proxy(IInternetProtocol*,IInternetProtocolSink*,ProtocolProxy**);
171
172 typedef struct {
173     HWND notif_hwnd;
174     DWORD notif_hwnd_cnt;
175
176     struct list entry;
177 } tls_data_t;
178
179 tls_data_t *get_tls_data(void);
180
181 HWND get_notif_hwnd(void);
182 void release_notif_hwnd(HWND);
183
184 static inline void *heap_alloc(size_t len)
185 {
186     return HeapAlloc(GetProcessHeap(), 0, len);
187 }
188
189 static inline void *heap_alloc_zero(size_t len)
190 {
191     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
192 }
193
194 static inline void *heap_realloc(void *mem, size_t len)
195 {
196     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
197 }
198
199 static inline void *heap_realloc_zero(void *mem, size_t len)
200 {
201     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
202 }
203
204 static inline BOOL heap_free(void *mem)
205 {
206     return HeapFree(GetProcessHeap(), 0, mem);
207 }
208
209 static inline LPWSTR heap_strdupW(LPCWSTR str)
210 {
211     LPWSTR ret = NULL;
212
213     if(str) {
214         DWORD size;
215
216         size = (strlenW(str)+1)*sizeof(WCHAR);
217         ret = heap_alloc(size);
218         memcpy(ret, str, size);
219     }
220
221     return ret;
222 }
223
224 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
225 {
226     LPWSTR ret = NULL;
227
228     if(str) {
229         ret = heap_alloc((len+1)*sizeof(WCHAR));
230         if(ret) {
231             memcpy(ret, str, len*sizeof(WCHAR));
232             ret[len] = 0;
233         }
234     }
235
236     return ret;
237 }
238
239 static inline LPWSTR heap_strdupAtoW(const char *str)
240 {
241     LPWSTR ret = NULL;
242
243     if(str) {
244         DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
245         ret = heap_alloc(len*sizeof(WCHAR));
246         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
247     }
248
249     return ret;
250 }
251
252 #endif /* __WINE_URLMON_MAIN_H */