1d548b41a940a1a5b11a9a401675e7749cb238cc
[reactos.git] / dll / win32 / hnetcfg / manager.c
1 /*
2 * Copyright 2009 Hans Leidekker 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 #include "config.h"
20 #include <stdarg.h>
21 #include <stdio.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "initguid.h"
29 #include "ole2.h"
30 #include "netfw.h"
31
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
34 #include "hnetcfg_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(hnetcfg);
37
38 typedef struct fw_manager
39 {
40 INetFwMgr INetFwMgr_iface;
41 LONG refs;
42 } fw_manager;
43
44 static inline fw_manager *impl_from_INetFwMgr( INetFwMgr *iface )
45 {
46 return CONTAINING_RECORD(iface, fw_manager, INetFwMgr_iface);
47 }
48
49 static ULONG WINAPI fw_manager_AddRef(
50 INetFwMgr *iface )
51 {
52 fw_manager *fw_manager = impl_from_INetFwMgr( iface );
53 return InterlockedIncrement( &fw_manager->refs );
54 }
55
56 static ULONG WINAPI fw_manager_Release(
57 INetFwMgr *iface )
58 {
59 fw_manager *fw_manager = impl_from_INetFwMgr( iface );
60 LONG refs = InterlockedDecrement( &fw_manager->refs );
61 if (!refs)
62 {
63 TRACE("destroying %p\n", fw_manager);
64 HeapFree( GetProcessHeap(), 0, fw_manager );
65 }
66 return refs;
67 }
68
69 static HRESULT WINAPI fw_manager_QueryInterface(
70 INetFwMgr *iface,
71 REFIID riid,
72 void **ppvObject )
73 {
74 fw_manager *This = impl_from_INetFwMgr( iface );
75
76 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
77
78 if ( IsEqualGUID( riid, &IID_INetFwMgr ) ||
79 IsEqualGUID( riid, &IID_IDispatch ) ||
80 IsEqualGUID( riid, &IID_IUnknown ) )
81 {
82 *ppvObject = iface;
83 }
84 else
85 {
86 FIXME("interface %s not implemented\n", debugstr_guid(riid));
87 return E_NOINTERFACE;
88 }
89 INetFwMgr_AddRef( iface );
90 return S_OK;
91 }
92
93 static HRESULT WINAPI fw_manager_GetTypeInfoCount(
94 INetFwMgr *iface,
95 UINT *pctinfo )
96 {
97 fw_manager *This = impl_from_INetFwMgr( iface );
98
99 TRACE("%p %p\n", This, pctinfo);
100 *pctinfo = 1;
101 return S_OK;
102 }
103
104 static HRESULT WINAPI fw_manager_GetTypeInfo(
105 INetFwMgr *iface,
106 UINT iTInfo,
107 LCID lcid,
108 ITypeInfo **ppTInfo )
109 {
110 fw_manager *This = impl_from_INetFwMgr( iface );
111
112 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
113 return get_typeinfo( INetFwMgr_tid, ppTInfo );
114 }
115
116 static HRESULT WINAPI fw_manager_GetIDsOfNames(
117 INetFwMgr *iface,
118 REFIID riid,
119 LPOLESTR *rgszNames,
120 UINT cNames,
121 LCID lcid,
122 DISPID *rgDispId )
123 {
124 fw_manager *This = impl_from_INetFwMgr( iface );
125 ITypeInfo *typeinfo;
126 HRESULT hr;
127
128 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
129
130 hr = get_typeinfo( INetFwMgr_tid, &typeinfo );
131 if (SUCCEEDED(hr))
132 {
133 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
134 ITypeInfo_Release( typeinfo );
135 }
136 return hr;
137 }
138
139 static HRESULT WINAPI fw_manager_Invoke(
140 INetFwMgr *iface,
141 DISPID dispIdMember,
142 REFIID riid,
143 LCID lcid,
144 WORD wFlags,
145 DISPPARAMS *pDispParams,
146 VARIANT *pVarResult,
147 EXCEPINFO *pExcepInfo,
148 UINT *puArgErr )
149 {
150 fw_manager *This = impl_from_INetFwMgr( iface );
151 ITypeInfo *typeinfo;
152 HRESULT hr;
153
154 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
155 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
156
157 hr = get_typeinfo( INetFwMgr_tid, &typeinfo );
158 if (SUCCEEDED(hr))
159 {
160 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwMgr_iface, dispIdMember,
161 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
162 ITypeInfo_Release( typeinfo );
163 }
164 return hr;
165 }
166
167 static HRESULT WINAPI fw_manager_get_LocalPolicy(
168 INetFwMgr *iface,
169 INetFwPolicy **localPolicy )
170 {
171 fw_manager *This = impl_from_INetFwMgr( iface );
172
173 TRACE("%p, %p\n", This, localPolicy);
174 return NetFwPolicy_create( NULL, (void **)localPolicy );
175 }
176
177 static HRESULT WINAPI fw_manager_get_CurrentProfileType(
178 INetFwMgr *iface,
179 NET_FW_PROFILE_TYPE *profileType )
180 {
181 fw_manager *This = impl_from_INetFwMgr( iface );
182
183 FIXME("%p, %p\n", This, profileType);
184 return E_NOTIMPL;
185 }
186
187 static HRESULT WINAPI fw_manager_RestoreDefaults(
188 INetFwMgr *iface )
189 {
190 fw_manager *This = impl_from_INetFwMgr( iface );
191
192 FIXME("%p\n", This);
193 return E_NOTIMPL;
194 }
195
196 static HRESULT WINAPI fw_manager_IsPortAllowed(
197 INetFwMgr *iface,
198 BSTR imageFileName,
199 NET_FW_IP_VERSION ipVersion,
200 LONG portNumber,
201 BSTR localAddress,
202 NET_FW_IP_PROTOCOL ipProtocol,
203 VARIANT *allowed,
204 VARIANT *restricted )
205 {
206 fw_manager *This = impl_from_INetFwMgr( iface );
207
208 FIXME("%p, %s, %u, %d, %s, %u, %p, %p\n", This, debugstr_w(imageFileName),
209 ipVersion, portNumber, debugstr_w(localAddress), ipProtocol, allowed, restricted);
210 return E_NOTIMPL;
211 }
212
213 static HRESULT WINAPI fw_manager_IsIcmpTypeAllowed(
214 INetFwMgr *iface,
215 NET_FW_IP_VERSION ipVersion,
216 BSTR localAddress,
217 BYTE type,
218 VARIANT *allowed,
219 VARIANT *restricted )
220 {
221 fw_manager *This = impl_from_INetFwMgr( iface );
222
223 FIXME("%p, %u, %s, %u, %p, %p\n", This, ipVersion, debugstr_w(localAddress),
224 type, allowed, restricted);
225 return E_NOTIMPL;
226 }
227
228 static const struct INetFwMgrVtbl fw_manager_vtbl =
229 {
230 fw_manager_QueryInterface,
231 fw_manager_AddRef,
232 fw_manager_Release,
233 fw_manager_GetTypeInfoCount,
234 fw_manager_GetTypeInfo,
235 fw_manager_GetIDsOfNames,
236 fw_manager_Invoke,
237 fw_manager_get_LocalPolicy,
238 fw_manager_get_CurrentProfileType,
239 fw_manager_RestoreDefaults,
240 fw_manager_IsPortAllowed,
241 fw_manager_IsIcmpTypeAllowed
242 };
243
244 HRESULT NetFwMgr_create( IUnknown *pUnkOuter, LPVOID *ppObj )
245 {
246 fw_manager *fm;
247
248 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
249
250 fm = HeapAlloc( GetProcessHeap(), 0, sizeof(*fm) );
251 if (!fm) return E_OUTOFMEMORY;
252
253 fm->INetFwMgr_iface.lpVtbl = &fw_manager_vtbl;
254 fm->refs = 1;
255
256 *ppObj = &fm->INetFwMgr_iface;
257
258 TRACE("returning iface %p\n", *ppObj);
259 return S_OK;
260 }