user32/tests: Fix the listbox delete test on NT4.
[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 URLMON_hInstance;
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 /**********************************************************************
52  * Dll lifetime tracking declaration for urlmon.dll
53  */
54 extern LONG URLMON_refCount;
55 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
56 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
57
58 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
59 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
60
61 IInternetProtocolInfo *get_protocol_info(LPCWSTR);
62 HRESULT get_protocol_handler(LPCWSTR,CLSID*,BOOL*,IClassFactory**);
63 IInternetProtocol *get_mime_filter(LPCWSTR);
64 BOOL is_registered_protocol(LPCWSTR);
65 void register_urlmon_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL);
66
67 HRESULT bind_to_storage(LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
68 HRESULT bind_to_object(IMoniker *mon, LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
69
70 HRESULT create_binding_protocol(LPCWSTR url, BOOL from_urlmon, IInternetProtocol **protocol);
71 void set_binding_sink(IInternetProtocol *bind_protocol, IInternetProtocolSink *sink);
72 IWinInetInfo *get_wininet_info(IInternetProtocol*);
73
74 typedef struct ProtocolVtbl ProtocolVtbl;
75
76 typedef struct {
77     const ProtocolVtbl *vtbl;
78
79     IInternetProtocol *protocol;
80     IInternetProtocolSink *protocol_sink;
81
82     DWORD bindf;
83     BINDINFO bind_info;
84
85     HINTERNET internet;
86     HINTERNET request;
87     HINTERNET connection;
88     DWORD flags;
89     HANDLE lock;
90
91     ULONG current_position;
92     ULONG content_length;
93     ULONG available_bytes;
94
95     LONG priority;
96 } Protocol;
97
98 struct ProtocolVtbl {
99     HRESULT (*open_request)(Protocol*,LPCWSTR,DWORD,IInternetBindInfo*);
100     HRESULT (*start_downloading)(Protocol*);
101     void (*close_connection)(Protocol*);
102 };
103
104 HRESULT protocol_start(Protocol*,IInternetProtocol*,LPCWSTR,IInternetProtocolSink*,IInternetBindInfo*);
105 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*);
106 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*);
107 HRESULT protocol_lock_request(Protocol*);
108 HRESULT protocol_unlock_request(Protocol*);
109 void protocol_close_connection(Protocol*);
110
111 typedef struct {
112     const IInternetProtocolVtbl      *lpIInternetProtocolVtbl;
113     const IInternetProtocolSinkVtbl  *lpIInternetProtocolSinkVtbl;
114
115     LONG ref;
116
117     IInternetProtocolSink *protocol_sink;
118     IInternetProtocol *protocol;
119 } ProtocolProxy;
120
121 #define PROTOCOL(x)  ((IInternetProtocol*)       &(x)->lpIInternetProtocolVtbl)
122 #define PROTSINK(x)  ((IInternetProtocolSink*)   &(x)->lpIInternetProtocolSinkVtbl)
123
124 HRESULT create_protocol_proxy(IInternetProtocol*,IInternetProtocolSink*,ProtocolProxy**);
125
126 typedef struct {
127     HWND notif_hwnd;
128     DWORD notif_hwnd_cnt;
129
130     struct list entry;
131 } tls_data_t;
132
133 tls_data_t *get_tls_data(void);
134
135 HWND get_notif_hwnd(void);
136 void release_notif_hwnd(HWND);
137
138 static inline void *heap_alloc(size_t len)
139 {
140     return HeapAlloc(GetProcessHeap(), 0, len);
141 }
142
143 static inline void *heap_alloc_zero(size_t len)
144 {
145     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
146 }
147
148 static inline void *heap_realloc(void *mem, size_t len)
149 {
150     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
151 }
152
153 static inline BOOL heap_free(void *mem)
154 {
155     return HeapFree(GetProcessHeap(), 0, mem);
156 }
157
158 static inline LPWSTR heap_strdupW(LPCWSTR str)
159 {
160     LPWSTR ret = NULL;
161
162     if(str) {
163         DWORD size;
164
165         size = (strlenW(str)+1)*sizeof(WCHAR);
166         ret = heap_alloc(size);
167         memcpy(ret, str, size);
168     }
169
170     return ret;
171 }
172
173 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
174 {
175     LPWSTR ret = NULL;
176
177     if(str) {
178         ret = heap_alloc((len+1)*sizeof(WCHAR));
179         if(ret) {
180             memcpy(ret, str, len*sizeof(WCHAR));
181             ret[len] = 0;
182         }
183     }
184
185     return ret;
186 }
187
188 static inline LPWSTR heap_strdupAtoW(const char *str)
189 {
190     LPWSTR ret = NULL;
191
192     if(str) {
193         DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
194         ret = heap_alloc(len*sizeof(WCHAR));
195         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
196     }
197
198     return ret;
199 }
200
201 #endif /* __WINE_URLMON_MAIN_H */