crypt32/tests: Fix some test failures on Win9x.
[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
38 extern HINSTANCE URLMON_hInstance;
39 extern HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
40 extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
41 extern HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
42 extern HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
43 extern HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
44 extern HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
45 extern HRESULT GopherProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
46 extern HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
47
48 /**********************************************************************
49  * Dll lifetime tracking declaration for urlmon.dll
50  */
51 extern LONG URLMON_refCount;
52 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
53 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
54
55 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
56 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
57 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
58
59 IInternetProtocolInfo *get_protocol_info(LPCWSTR url);
60 HRESULT get_protocol_handler(LPCWSTR url, CLSID *clsid, IClassFactory **ret);
61 BOOL is_registered_protocol(LPCWSTR);
62 void register_urlmon_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL);
63
64 HRESULT bind_to_storage(LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
65 HRESULT bind_to_object(IMoniker *mon, LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
66
67 HRESULT create_binding_protocol(LPCWSTR url, BOOL from_urlmon, IInternetProtocol **protocol);
68 void set_binding_sink(IInternetProtocol *bind_protocol, IInternetProtocolSink *sink);
69
70 typedef struct ProtocolVtbl ProtocolVtbl;
71
72 typedef struct {
73     const ProtocolVtbl *vtbl;
74
75     IInternetProtocol *protocol;
76     IInternetProtocolSink *protocol_sink;
77
78     DWORD bindf;
79     BINDINFO bind_info;
80
81     HINTERNET internet;
82     HINTERNET request;
83     HINTERNET connection;
84     DWORD flags;
85     HANDLE lock;
86
87     ULONG current_position;
88     ULONG content_length;
89     ULONG available_bytes;
90
91     LONG priority;
92 } Protocol;
93
94 struct ProtocolVtbl {
95     HRESULT (*open_request)(Protocol*,LPCWSTR,DWORD,IInternetBindInfo*);
96     HRESULT (*start_downloading)(Protocol*);
97     void (*close_connection)(Protocol*);
98 };
99
100 HRESULT protocol_start(Protocol*,IInternetProtocol*,LPCWSTR,IInternetProtocolSink*,IInternetBindInfo*);
101 HRESULT protocol_continue(Protocol*,PROTOCOLDATA*);
102 HRESULT protocol_read(Protocol*,void*,ULONG,ULONG*);
103 HRESULT protocol_lock_request(Protocol*);
104 HRESULT protocol_unlock_request(Protocol*);
105 void protocol_close_connection(Protocol*);
106
107 static inline void *heap_alloc(size_t len)
108 {
109     return HeapAlloc(GetProcessHeap(), 0, len);
110 }
111
112 static inline void *heap_alloc_zero(size_t len)
113 {
114     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
115 }
116
117 static inline void *heap_realloc(void *mem, size_t len)
118 {
119     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
120 }
121
122 static inline BOOL heap_free(void *mem)
123 {
124     return HeapFree(GetProcessHeap(), 0, mem);
125 }
126
127 static inline LPWSTR heap_strdupW(LPCWSTR str)
128 {
129     LPWSTR ret = NULL;
130
131     if(str) {
132         DWORD size;
133
134         size = (strlenW(str)+1)*sizeof(WCHAR);
135         ret = heap_alloc(size);
136         memcpy(ret, str, size);
137     }
138
139     return ret;
140 }
141
142 static inline LPWSTR heap_strndupW(LPCWSTR str, int len)
143 {
144     LPWSTR ret = NULL;
145
146     if(str) {
147         ret = heap_alloc((len+1)*sizeof(WCHAR));
148         if(ret) {
149             memcpy(ret, str, len*sizeof(WCHAR));
150             ret[len] = 0;
151         }
152     }
153
154     return ret;
155 }
156
157 static inline LPWSTR heap_strdupAtoW(const char *str)
158 {
159     LPWSTR ret = NULL;
160
161     if(str) {
162         DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
163         ret = heap_alloc(len*sizeof(WCHAR));
164         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
165     }
166
167     return ret;
168 }
169
170 #endif /* __WINE_URLMON_MAIN_H */