urlmon: Make start_binding more generic.
[wine] / dlls / urlmon / urlmon_main.h
1 /*
2  * Copyright 2002 Huw D M Davies for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #ifndef __WINE_URLMON_MAIN_H
20 #define __WINE_URLMON_MAIN_H
21
22 #include <stdarg.h>
23
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "urlmon.h"
33
34 #include "wine/unicode.h"
35
36 extern HINSTANCE URLMON_hInstance;
37 extern HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
38 extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
39 extern HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
40 extern HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
41 extern HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
42 extern HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
43 extern HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
44
45 /**********************************************************************
46  * Dll lifetime tracking declaration for urlmon.dll
47  */
48 extern LONG URLMON_refCount;
49 static inline void URLMON_LockModule(void) { InterlockedIncrement( &URLMON_refCount ); }
50 static inline void URLMON_UnlockModule(void) { InterlockedDecrement( &URLMON_refCount ); }
51
52 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
53 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
54
55 typedef struct
56 {       
57         const IStreamVtbl       *lpVtbl;
58         LONG            ref;
59         HANDLE          handle;
60         BOOL            closed;
61         WCHAR           *pszFileName;
62         WCHAR           *pszURL;
63 } IUMCacheStream;
64
65 HRESULT UMCreateStreamOnCacheFile(LPCWSTR pszURL, DWORD dwSize, LPWSTR pszFileName, HANDLE *phfile, IUMCacheStream **ppstr);
66 void    UMCloseCacheFileStream(IUMCacheStream *pstr);
67
68 IInternetProtocolInfo *get_protocol_info(LPCWSTR url);
69 HRESULT get_protocol_handler(LPCWSTR url, CLSID *clsid, IClassFactory **ret);
70
71 HRESULT bind_to_storage(LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
72
73 HRESULT create_binding_protocol(LPCWSTR url, BOOL from_urlmon, IInternetProtocol **protocol);
74 void set_binding_sink(IInternetProtocol *bind_protocol, IInternetProtocolSink *sink);
75
76 static inline void *heap_alloc(size_t len)
77 {
78     return HeapAlloc(GetProcessHeap(), 0, len);
79 }
80
81 static inline void *heap_alloc_zero(size_t len)
82 {
83     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
84 }
85
86 static inline void *heap_realloc(void *mem, size_t len)
87 {
88     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
89 }
90
91 static inline BOOL heap_free(void *mem)
92 {
93     return HeapFree(GetProcessHeap(), 0, mem);
94 }
95
96 static inline LPWSTR heap_strdupW(LPCWSTR str)
97 {
98     LPWSTR ret = NULL;
99
100     if(str) {
101         DWORD size;
102
103         size = (strlenW(str)+1)*sizeof(WCHAR);
104         ret = heap_alloc(size);
105         memcpy(ret, str, size);
106     }
107
108     return ret;
109 }
110
111 #endif /* __WINE_URLMON_MAIN_H */