urlmon: Store BindProtocol as IInternetProtocolEx.
[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_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
66 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
67
68 IInternetProtocolInfo *get_protocol_info(LPCWSTR);
69 HRESULT get_protocol_handler(LPCWSTR,CLSID*,BOOL*,IClassFactory**);
70 IInternetProtocol *get_mime_filter(LPCWSTR);
71 BOOL is_registered_protocol(LPCWSTR);
72 void register_urlmon_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL);
73 HINTERNET get_internet_session(IInternetBindInfo*);
74 LPWSTR get_useragent(void);
75 void free_session(void);
76
77 HRESULT bind_to_storage(LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
78 HRESULT bind_to_object(IMoniker *mon, LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
79
80 HRESULT create_binding_protocol(BOOL,IInternetProtocolEx**);
81 void set_binding_sink(IInternetProtocolEx*,IInternetProtocolSink*,IInternetBindInfo*);
82 IWinInetInfo *get_wininet_info(IInternetProtocolEx*);
83 HRESULT create_default_callback(IBindStatusCallback**);
84 HRESULT wrap_callback(IBindStatusCallback*,IBindStatusCallback**);
85
86 typedef struct ProtocolVtbl ProtocolVtbl;
87
88 typedef struct {
89     const ProtocolVtbl *vtbl;
90
91     IInternetProtocol *protocol;
92     IInternetProtocolSink *protocol_sink;
93
94     DWORD bindf;
95     BINDINFO bind_info;
96
97     HINTERNET request;
98     HINTERNET connection;
99     DWORD flags;
100     HANDLE lock;
101
102     ULONG current_position;
103     ULONG content_length;
104     ULONG available_bytes;
105
106     IStream *post_stream;
107
108     LONG priority;
109 } Protocol;
110
111 struct ProtocolVtbl {
112     HRESULT (*open_request)(Protocol*,IUri*,DWORD,HINTERNET,IInternetBindInfo*);
113     HRESULT (*end_request)(Protocol*);
114     HRESULT (*start_downloading)(Protocol*);
115     void (*close_connection)(Protocol*);
116 };
117
118 HRESULT protocol_start(Protocol*,IInternetProtocol*,IUri*,IInternetProtocolSink*,IInternetBindInfo*);
119 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*);
120 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*);
121 HRESULT protocol_lock_request(Protocol*);
122 HRESULT protocol_unlock_request(Protocol*);
123 HRESULT protocol_abort(Protocol*,HRESULT);
124 void protocol_close_connection(Protocol*);
125
126 typedef struct {
127     const IInternetProtocolVtbl      *lpIInternetProtocolVtbl;
128     const IInternetProtocolSinkVtbl  *lpIInternetProtocolSinkVtbl;
129
130     LONG ref;
131
132     IInternetProtocolSink *protocol_sink;
133     IInternetProtocol *protocol;
134 } ProtocolProxy;
135
136 #define PROTOCOL(x)  ((IInternetProtocol*)       &(x)->lpIInternetProtocolVtbl)
137 #define PROTSINK(x)  ((IInternetProtocolSink*)   &(x)->lpIInternetProtocolSinkVtbl)
138
139 HRESULT create_protocol_proxy(IInternetProtocol*,IInternetProtocolSink*,ProtocolProxy**);
140
141 typedef struct {
142     HWND notif_hwnd;
143     DWORD notif_hwnd_cnt;
144
145     struct list entry;
146 } tls_data_t;
147
148 tls_data_t *get_tls_data(void);
149
150 HWND get_notif_hwnd(void);
151 void release_notif_hwnd(HWND);
152
153 static inline void *heap_alloc(size_t len)
154 {
155     return HeapAlloc(GetProcessHeap(), 0, len);
156 }
157
158 static inline void *heap_alloc_zero(size_t len)
159 {
160     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
161 }
162
163 static inline void *heap_realloc(void *mem, size_t len)
164 {
165     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
166 }
167
168 static inline void *heap_realloc_zero(void *mem, size_t len)
169 {
170     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
171 }
172
173 static inline BOOL heap_free(void *mem)
174 {
175     return HeapFree(GetProcessHeap(), 0, mem);
176 }
177
178 static inline LPWSTR heap_strdupW(LPCWSTR str)
179 {
180     LPWSTR ret = NULL;
181
182     if(str) {
183         DWORD size;
184
185         size = (strlenW(str)+1)*sizeof(WCHAR);
186         ret = heap_alloc(size);
187         memcpy(ret, str, size);
188     }
189
190     return ret;
191 }
192
193 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
194 {
195     LPWSTR ret = NULL;
196
197     if(str) {
198         ret = heap_alloc((len+1)*sizeof(WCHAR));
199         if(ret) {
200             memcpy(ret, str, len*sizeof(WCHAR));
201             ret[len] = 0;
202         }
203     }
204
205     return ret;
206 }
207
208 static inline LPWSTR heap_strdupAtoW(const char *str)
209 {
210     LPWSTR ret = NULL;
211
212     if(str) {
213         DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
214         ret = heap_alloc(len*sizeof(WCHAR));
215         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
216     }
217
218     return ret;
219 }
220
221 #endif /* __WINE_URLMON_MAIN_H */