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