186fa0a11ae5238b34650ea64c030f9c3fc74147
[reactos.git] / reactos / dll / win32 / hnetcfg / port.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 "hnetcfg_private.h"
20
21 typedef struct fw_port
22 {
23 INetFwOpenPort INetFwOpenPort_iface;
24 LONG refs;
25 } fw_port;
26
27 static inline fw_port *impl_from_INetFwOpenPort( INetFwOpenPort *iface )
28 {
29 return CONTAINING_RECORD(iface, fw_port, INetFwOpenPort_iface);
30 }
31
32 static ULONG WINAPI fw_port_AddRef(
33 INetFwOpenPort *iface )
34 {
35 fw_port *fw_port = impl_from_INetFwOpenPort( iface );
36 return InterlockedIncrement( &fw_port->refs );
37 }
38
39 static ULONG WINAPI fw_port_Release(
40 INetFwOpenPort *iface )
41 {
42 fw_port *fw_port = impl_from_INetFwOpenPort( iface );
43 LONG refs = InterlockedDecrement( &fw_port->refs );
44 if (!refs)
45 {
46 TRACE("destroying %p\n", fw_port);
47 HeapFree( GetProcessHeap(), 0, fw_port );
48 }
49 return refs;
50 }
51
52 static HRESULT WINAPI fw_port_QueryInterface(
53 INetFwOpenPort *iface,
54 REFIID riid,
55 void **ppvObject )
56 {
57 fw_port *This = impl_from_INetFwOpenPort( iface );
58
59 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
60
61 if ( IsEqualGUID( riid, &IID_INetFwOpenPort ) ||
62 IsEqualGUID( riid, &IID_IDispatch ) ||
63 IsEqualGUID( riid, &IID_IUnknown ) )
64 {
65 *ppvObject = iface;
66 }
67 else
68 {
69 FIXME("interface %s not implemented\n", debugstr_guid(riid));
70 return E_NOINTERFACE;
71 }
72 INetFwOpenPort_AddRef( iface );
73 return S_OK;
74 }
75
76 static HRESULT WINAPI fw_port_GetTypeInfoCount(
77 INetFwOpenPort *iface,
78 UINT *pctinfo )
79 {
80 fw_port *This = impl_from_INetFwOpenPort( iface );
81
82 TRACE("%p %p\n", This, pctinfo);
83 *pctinfo = 1;
84 return S_OK;
85 }
86
87 static HRESULT WINAPI fw_port_GetTypeInfo(
88 INetFwOpenPort *iface,
89 UINT iTInfo,
90 LCID lcid,
91 ITypeInfo **ppTInfo )
92 {
93 fw_port *This = impl_from_INetFwOpenPort( iface );
94
95 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
96 return get_typeinfo( INetFwOpenPort_tid, ppTInfo );
97 }
98
99 static HRESULT WINAPI fw_port_GetIDsOfNames(
100 INetFwOpenPort *iface,
101 REFIID riid,
102 LPOLESTR *rgszNames,
103 UINT cNames,
104 LCID lcid,
105 DISPID *rgDispId )
106 {
107 fw_port *This = impl_from_INetFwOpenPort( iface );
108 ITypeInfo *typeinfo;
109 HRESULT hr;
110
111 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
112
113 hr = get_typeinfo( INetFwOpenPort_tid, &typeinfo );
114 if (SUCCEEDED(hr))
115 {
116 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
117 ITypeInfo_Release( typeinfo );
118 }
119 return hr;
120 }
121
122 static HRESULT WINAPI fw_port_Invoke(
123 INetFwOpenPort *iface,
124 DISPID dispIdMember,
125 REFIID riid,
126 LCID lcid,
127 WORD wFlags,
128 DISPPARAMS *pDispParams,
129 VARIANT *pVarResult,
130 EXCEPINFO *pExcepInfo,
131 UINT *puArgErr )
132 {
133 fw_port *This = impl_from_INetFwOpenPort( iface );
134 ITypeInfo *typeinfo;
135 HRESULT hr;
136
137 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
138 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
139
140 hr = get_typeinfo( INetFwOpenPort_tid, &typeinfo );
141 if (SUCCEEDED(hr))
142 {
143 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwOpenPort_iface, dispIdMember,
144 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
145 ITypeInfo_Release( typeinfo );
146 }
147 return hr;
148 }
149
150 static HRESULT WINAPI fw_port_get_Name(
151 INetFwOpenPort *iface,
152 BSTR *name)
153 {
154 fw_port *This = impl_from_INetFwOpenPort( iface );
155
156 FIXME("%p %p\n", This, name);
157 return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI fw_port_put_Name(
161 INetFwOpenPort *iface,
162 BSTR name)
163 {
164 fw_port *This = impl_from_INetFwOpenPort( iface );
165
166 FIXME("%p %s\n", This, debugstr_w(name));
167 return E_NOTIMPL;
168 }
169
170 static HRESULT WINAPI fw_port_get_IpVersion(
171 INetFwOpenPort *iface,
172 NET_FW_IP_VERSION *ipVersion)
173 {
174 fw_port *This = impl_from_INetFwOpenPort( iface );
175
176 FIXME("%p %p\n", This, ipVersion);
177 return E_NOTIMPL;
178 }
179
180 static HRESULT WINAPI fw_port_put_IpVersion(
181 INetFwOpenPort *iface,
182 NET_FW_IP_VERSION ipVersion)
183 {
184 fw_port *This = impl_from_INetFwOpenPort( iface );
185
186 FIXME("%p %u\n", This, ipVersion);
187 return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI fw_port_get_Protocol(
191 INetFwOpenPort *iface,
192 NET_FW_IP_PROTOCOL *ipProtocol)
193 {
194 fw_port *This = impl_from_INetFwOpenPort( iface );
195
196 FIXME("%p %p\n", This, ipProtocol);
197 return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI fw_port_put_Protocol(
201 INetFwOpenPort *iface,
202 NET_FW_IP_PROTOCOL ipProtocol)
203 {
204 fw_port *This = impl_from_INetFwOpenPort( iface );
205
206 FIXME("%p %u\n", This, ipProtocol);
207 return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI fw_port_get_Port(
211 INetFwOpenPort *iface,
212 LONG *portNumber)
213 {
214 fw_port *This = impl_from_INetFwOpenPort( iface );
215
216 FIXME("%p %p\n", This, portNumber);
217 return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI fw_port_put_Port(
221 INetFwOpenPort *iface,
222 LONG portNumber)
223 {
224 fw_port *This = impl_from_INetFwOpenPort( iface );
225
226 FIXME("%p %d\n", This, portNumber);
227 return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI fw_port_get_Scope(
231 INetFwOpenPort *iface,
232 NET_FW_SCOPE *scope)
233 {
234 fw_port *This = impl_from_INetFwOpenPort( iface );
235
236 FIXME("%p %p\n", This, scope);
237 return E_NOTIMPL;
238 }
239
240 static HRESULT WINAPI fw_port_put_Scope(
241 INetFwOpenPort *iface,
242 NET_FW_SCOPE scope)
243 {
244 fw_port *This = impl_from_INetFwOpenPort( iface );
245
246 FIXME("%p %u\n", This, scope);
247 return E_NOTIMPL;
248 }
249
250 static HRESULT WINAPI fw_port_get_RemoteAddresses(
251 INetFwOpenPort *iface,
252 BSTR *remoteAddrs)
253 {
254 fw_port *This = impl_from_INetFwOpenPort( iface );
255
256 FIXME("%p %p\n", This, remoteAddrs);
257 return E_NOTIMPL;
258 }
259
260 static HRESULT WINAPI fw_port_put_RemoteAddresses(
261 INetFwOpenPort *iface,
262 BSTR remoteAddrs)
263 {
264 fw_port *This = impl_from_INetFwOpenPort( iface );
265
266 FIXME("%p %s\n", This, debugstr_w(remoteAddrs));
267 return E_NOTIMPL;
268 }
269
270 static HRESULT WINAPI fw_port_get_Enabled(
271 INetFwOpenPort *iface,
272 VARIANT_BOOL *enabled)
273 {
274 fw_port *This = impl_from_INetFwOpenPort( iface );
275
276 FIXME("%p %p\n", This, enabled);
277
278 *enabled = VARIANT_TRUE;
279 return S_OK;
280 }
281
282 static HRESULT WINAPI fw_port_put_Enabled(
283 INetFwOpenPort *iface,
284 VARIANT_BOOL enabled)
285 {
286 fw_port *This = impl_from_INetFwOpenPort( iface );
287
288 FIXME("%p %d\n", This, enabled);
289 return E_NOTIMPL;
290 }
291
292 static HRESULT WINAPI fw_port_get_BuiltIn(
293 INetFwOpenPort *iface,
294 VARIANT_BOOL *builtIn)
295 {
296 fw_port *This = impl_from_INetFwOpenPort( iface );
297
298 FIXME("%p %p\n", This, builtIn);
299 return E_NOTIMPL;
300 }
301
302 static const struct INetFwOpenPortVtbl fw_port_vtbl =
303 {
304 fw_port_QueryInterface,
305 fw_port_AddRef,
306 fw_port_Release,
307 fw_port_GetTypeInfoCount,
308 fw_port_GetTypeInfo,
309 fw_port_GetIDsOfNames,
310 fw_port_Invoke,
311 fw_port_get_Name,
312 fw_port_put_Name,
313 fw_port_get_IpVersion,
314 fw_port_put_IpVersion,
315 fw_port_get_Protocol,
316 fw_port_put_Protocol,
317 fw_port_get_Port,
318 fw_port_put_Port,
319 fw_port_get_Scope,
320 fw_port_put_Scope,
321 fw_port_get_RemoteAddresses,
322 fw_port_put_RemoteAddresses,
323 fw_port_get_Enabled,
324 fw_port_put_Enabled,
325 fw_port_get_BuiltIn
326 };
327
328 HRESULT NetFwOpenPort_create( IUnknown *pUnkOuter, LPVOID *ppObj )
329 {
330 fw_port *fp;
331
332 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
333
334 fp = HeapAlloc( GetProcessHeap(), 0, sizeof(*fp) );
335 if (!fp) return E_OUTOFMEMORY;
336
337 fp->INetFwOpenPort_iface.lpVtbl = &fw_port_vtbl;
338 fp->refs = 1;
339
340 *ppObj = &fp->INetFwOpenPort_iface;
341
342 TRACE("returning iface %p\n", *ppObj);
343 return S_OK;
344 }
345
346 typedef struct fw_ports
347 {
348 INetFwOpenPorts INetFwOpenPorts_iface;
349 LONG refs;
350 } fw_ports;
351
352 static inline fw_ports *impl_from_INetFwOpenPorts( INetFwOpenPorts *iface )
353 {
354 return CONTAINING_RECORD(iface, fw_ports, INetFwOpenPorts_iface);
355 }
356
357 static ULONG WINAPI fw_ports_AddRef(
358 INetFwOpenPorts *iface )
359 {
360 fw_ports *fw_ports = impl_from_INetFwOpenPorts( iface );
361 return InterlockedIncrement( &fw_ports->refs );
362 }
363
364 static ULONG WINAPI fw_ports_Release(
365 INetFwOpenPorts *iface )
366 {
367 fw_ports *fw_ports = impl_from_INetFwOpenPorts( iface );
368 LONG refs = InterlockedDecrement( &fw_ports->refs );
369 if (!refs)
370 {
371 TRACE("destroying %p\n", fw_ports);
372 HeapFree( GetProcessHeap(), 0, fw_ports );
373 }
374 return refs;
375 }
376
377 static HRESULT WINAPI fw_ports_QueryInterface(
378 INetFwOpenPorts *iface,
379 REFIID riid,
380 void **ppvObject )
381 {
382 fw_ports *This = impl_from_INetFwOpenPorts( iface );
383
384 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
385
386 if ( IsEqualGUID( riid, &IID_INetFwOpenPorts ) ||
387 IsEqualGUID( riid, &IID_IDispatch ) ||
388 IsEqualGUID( riid, &IID_IUnknown ) )
389 {
390 *ppvObject = iface;
391 }
392 else
393 {
394 FIXME("interface %s not implemented\n", debugstr_guid(riid));
395 return E_NOINTERFACE;
396 }
397 INetFwOpenPorts_AddRef( iface );
398 return S_OK;
399 }
400
401 static HRESULT WINAPI fw_ports_GetTypeInfoCount(
402 INetFwOpenPorts *iface,
403 UINT *pctinfo )
404 {
405 fw_ports *This = impl_from_INetFwOpenPorts( iface );
406
407 FIXME("%p %p\n", This, pctinfo);
408 return E_NOTIMPL;
409 }
410
411 static HRESULT WINAPI fw_ports_GetTypeInfo(
412 INetFwOpenPorts *iface,
413 UINT iTInfo,
414 LCID lcid,
415 ITypeInfo **ppTInfo )
416 {
417 fw_ports *This = impl_from_INetFwOpenPorts( iface );
418
419 FIXME("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
420 return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI fw_ports_GetIDsOfNames(
424 INetFwOpenPorts *iface,
425 REFIID riid,
426 LPOLESTR *rgszNames,
427 UINT cNames,
428 LCID lcid,
429 DISPID *rgDispId )
430 {
431 fw_ports *This = impl_from_INetFwOpenPorts( iface );
432
433 FIXME("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
434 return E_NOTIMPL;
435 }
436
437 static HRESULT WINAPI fw_ports_Invoke(
438 INetFwOpenPorts *iface,
439 DISPID dispIdMember,
440 REFIID riid,
441 LCID lcid,
442 WORD wFlags,
443 DISPPARAMS *pDispParams,
444 VARIANT *pVarResult,
445 EXCEPINFO *pExcepInfo,
446 UINT *puArgErr )
447 {
448 fw_ports *This = impl_from_INetFwOpenPorts( iface );
449
450 FIXME("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
451 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
452 return E_NOTIMPL;
453 }
454
455 static HRESULT WINAPI fw_ports_get_Count(
456 INetFwOpenPorts *iface,
457 LONG *count)
458 {
459 fw_ports *This = impl_from_INetFwOpenPorts( iface );
460
461 FIXME("%p, %p\n", This, count);
462
463 *count = 0;
464 return S_OK;
465 }
466
467 static HRESULT WINAPI fw_ports_Add(
468 INetFwOpenPorts *iface,
469 INetFwOpenPort *port)
470 {
471 fw_ports *This = impl_from_INetFwOpenPorts( iface );
472
473 FIXME("%p, %p\n", This, port);
474 return E_NOTIMPL;
475 }
476
477 static HRESULT WINAPI fw_ports_Remove(
478 INetFwOpenPorts *iface,
479 LONG portNumber,
480 NET_FW_IP_PROTOCOL ipProtocol)
481 {
482 fw_ports *This = impl_from_INetFwOpenPorts( iface );
483
484 FIXME("%p, %d, %u\n", This, portNumber, ipProtocol);
485 return E_NOTIMPL;
486 }
487
488 static HRESULT WINAPI fw_ports_Item(
489 INetFwOpenPorts *iface,
490 LONG portNumber,
491 NET_FW_IP_PROTOCOL ipProtocol,
492 INetFwOpenPort **openPort)
493 {
494 HRESULT hr;
495 fw_ports *This = impl_from_INetFwOpenPorts( iface );
496
497 FIXME("%p, %d, %u, %p\n", This, portNumber, ipProtocol, openPort);
498
499 hr = NetFwOpenPort_create( NULL, (void **)openPort );
500 if (SUCCEEDED(hr))
501 {
502 INetFwOpenPort_put_Protocol( *openPort, ipProtocol );
503 INetFwOpenPort_put_Port( *openPort, portNumber );
504 }
505 return hr;
506 }
507
508 static HRESULT WINAPI fw_ports_get__NewEnum(
509 INetFwOpenPorts *iface,
510 IUnknown **newEnum)
511 {
512 fw_ports *This = impl_from_INetFwOpenPorts( iface );
513
514 FIXME("%p, %p\n", This, newEnum);
515 return E_NOTIMPL;
516 }
517
518 static const struct INetFwOpenPortsVtbl fw_ports_vtbl =
519 {
520 fw_ports_QueryInterface,
521 fw_ports_AddRef,
522 fw_ports_Release,
523 fw_ports_GetTypeInfoCount,
524 fw_ports_GetTypeInfo,
525 fw_ports_GetIDsOfNames,
526 fw_ports_Invoke,
527 fw_ports_get_Count,
528 fw_ports_Add,
529 fw_ports_Remove,
530 fw_ports_Item,
531 fw_ports_get__NewEnum
532 };
533
534 HRESULT NetFwOpenPorts_create( IUnknown *pUnkOuter, LPVOID *ppObj )
535 {
536 fw_ports *fp;
537
538 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
539
540 fp = HeapAlloc( GetProcessHeap(), 0, sizeof(*fp) );
541 if (!fp) return E_OUTOFMEMORY;
542
543 fp->INetFwOpenPorts_iface.lpVtbl = &fw_ports_vtbl;
544 fp->refs = 1;
545
546 *ppObj = &fp->INetFwOpenPorts_iface;
547
548 TRACE("returning iface %p\n", *ppObj);
549 return S_OK;
550 }