3721b50878f1663092ba3ba5d3e9b7dac8c0277e
[reactos.git] / reactos / dll / win32 / hnetcfg / apps.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 #include <winnls.h>
22 #include <ole2.h>
23
24 typedef struct fw_app
25 {
26 INetFwAuthorizedApplication INetFwAuthorizedApplication_iface;
27 LONG refs;
28 } fw_app;
29
30 static inline fw_app *impl_from_INetFwAuthorizedApplication( INetFwAuthorizedApplication *iface )
31 {
32 return CONTAINING_RECORD(iface, fw_app, INetFwAuthorizedApplication_iface);
33 }
34
35 static ULONG WINAPI fw_app_AddRef(
36 INetFwAuthorizedApplication *iface )
37 {
38 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface );
39 return InterlockedIncrement( &fw_app->refs );
40 }
41
42 static ULONG WINAPI fw_app_Release(
43 INetFwAuthorizedApplication *iface )
44 {
45 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface );
46 LONG refs = InterlockedDecrement( &fw_app->refs );
47 if (!refs)
48 {
49 TRACE("destroying %p\n", fw_app);
50 HeapFree( GetProcessHeap(), 0, fw_app );
51 }
52 return refs;
53 }
54
55 static HRESULT WINAPI fw_app_QueryInterface(
56 INetFwAuthorizedApplication *iface,
57 REFIID riid,
58 void **ppvObject )
59 {
60 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
61
62 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
63
64 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplication ) ||
65 IsEqualGUID( riid, &IID_IDispatch ) ||
66 IsEqualGUID( riid, &IID_IUnknown ) )
67 {
68 *ppvObject = iface;
69 }
70 else
71 {
72 FIXME("interface %s not implemented\n", debugstr_guid(riid));
73 return E_NOINTERFACE;
74 }
75 INetFwAuthorizedApplication_AddRef( iface );
76 return S_OK;
77 }
78
79 static HRESULT WINAPI fw_app_GetTypeInfoCount(
80 INetFwAuthorizedApplication *iface,
81 UINT *pctinfo )
82 {
83 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
84
85 TRACE("%p %p\n", This, pctinfo);
86 *pctinfo = 1;
87 return S_OK;
88 }
89
90 static ITypeLib *typelib;
91 static ITypeInfo *typeinfo[last_tid];
92
93 static REFIID tid_id[] =
94 {
95 &IID_INetFwAuthorizedApplication,
96 &IID_INetFwAuthorizedApplications,
97 &IID_INetFwMgr,
98 &IID_INetFwOpenPort,
99 &IID_INetFwPolicy,
100 &IID_INetFwProfile
101 };
102
103 HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret )
104 {
105 HRESULT hr;
106
107 if (!typelib)
108 {
109 ITypeLib *lib;
110
111 hr = LoadRegTypeLib( &LIBID_NetFwPublicTypeLib, 1, 0, LOCALE_SYSTEM_DEFAULT, &lib );
112 if (FAILED(hr))
113 {
114 ERR("LoadRegTypeLib failed: %08x\n", hr);
115 return hr;
116 }
117 if (InterlockedCompareExchangePointer( (void **)&typelib, lib, NULL ))
118 ITypeLib_Release( lib );
119 }
120 if (!typeinfo[tid])
121 {
122 ITypeInfo *info;
123
124 hr = ITypeLib_GetTypeInfoOfGuid( typelib, tid_id[tid], &info );
125 if (FAILED(hr))
126 {
127 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_id[tid]), hr);
128 return hr;
129 }
130 if (InterlockedCompareExchangePointer( (void **)(typeinfo + tid), info, NULL ))
131 ITypeInfo_Release( info );
132 }
133 *ret = typeinfo[tid];
134 ITypeInfo_AddRef(typeinfo[tid]);
135 return S_OK;
136 }
137
138 void release_typelib(void)
139 {
140 unsigned i;
141
142 for (i = 0; i < sizeof(typeinfo)/sizeof(*typeinfo); i++)
143 if (typeinfo[i])
144 ITypeInfo_Release(typeinfo[i]);
145
146 if (typelib)
147 ITypeLib_Release(typelib);
148 }
149
150 static HRESULT WINAPI fw_app_GetTypeInfo(
151 INetFwAuthorizedApplication *iface,
152 UINT iTInfo,
153 LCID lcid,
154 ITypeInfo **ppTInfo )
155 {
156 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
157
158 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
159 return get_typeinfo( INetFwAuthorizedApplication_tid, ppTInfo );
160 }
161
162 static HRESULT WINAPI fw_app_GetIDsOfNames(
163 INetFwAuthorizedApplication *iface,
164 REFIID riid,
165 LPOLESTR *rgszNames,
166 UINT cNames,
167 LCID lcid,
168 DISPID *rgDispId )
169 {
170 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
171 ITypeInfo *typeinfo;
172 HRESULT hr;
173
174 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
175
176 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo );
177 if (SUCCEEDED(hr))
178 {
179 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
180 ITypeInfo_Release( typeinfo );
181 }
182 return hr;
183 }
184
185 static HRESULT WINAPI fw_app_Invoke(
186 INetFwAuthorizedApplication *iface,
187 DISPID dispIdMember,
188 REFIID riid,
189 LCID lcid,
190 WORD wFlags,
191 DISPPARAMS *pDispParams,
192 VARIANT *pVarResult,
193 EXCEPINFO *pExcepInfo,
194 UINT *puArgErr )
195 {
196 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
197 ITypeInfo *typeinfo;
198 HRESULT hr;
199
200 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
201 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
202
203 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo );
204 if (SUCCEEDED(hr))
205 {
206 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplication_iface, dispIdMember,
207 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
208 ITypeInfo_Release( typeinfo );
209 }
210 return hr;
211 }
212
213 static HRESULT WINAPI fw_app_get_Name(
214 INetFwAuthorizedApplication *iface,
215 BSTR *name )
216 {
217 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
218
219 FIXME("%p, %p\n", This, name);
220 return E_NOTIMPL;
221 }
222
223 static HRESULT WINAPI fw_app_put_Name(
224 INetFwAuthorizedApplication *iface,
225 BSTR name )
226 {
227 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
228
229 FIXME("%p, %s\n", This, debugstr_w(name));
230 return S_OK;
231 }
232
233 static HRESULT WINAPI fw_app_get_ProcessImageFileName(
234 INetFwAuthorizedApplication *iface,
235 BSTR *imageFileName )
236 {
237 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
238
239 FIXME("%p, %p\n", This, imageFileName);
240 return E_NOTIMPL;
241 }
242
243 static HRESULT WINAPI fw_app_put_ProcessImageFileName(
244 INetFwAuthorizedApplication *iface,
245 BSTR imageFileName )
246 {
247 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
248
249 FIXME("%p, %s\n", This, debugstr_w(imageFileName));
250 return S_OK;
251 }
252
253 static HRESULT WINAPI fw_app_get_IpVersion(
254 INetFwAuthorizedApplication *iface,
255 NET_FW_IP_VERSION *ipVersion )
256 {
257 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
258
259 TRACE("%p, %p\n", This, ipVersion);
260
261 if (!ipVersion)
262 return E_POINTER;
263 *ipVersion = NET_FW_IP_VERSION_ANY;
264 return S_OK;
265 }
266
267 static HRESULT WINAPI fw_app_put_IpVersion(
268 INetFwAuthorizedApplication *iface,
269 NET_FW_IP_VERSION ipVersion )
270 {
271 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
272
273 TRACE("%p, %u\n", This, ipVersion);
274 return S_OK;
275 }
276
277 static HRESULT WINAPI fw_app_get_Scope(
278 INetFwAuthorizedApplication *iface,
279 NET_FW_SCOPE *scope )
280 {
281 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
282
283 FIXME("%p, %p\n", This, scope);
284 return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI fw_app_put_Scope(
288 INetFwAuthorizedApplication *iface,
289 NET_FW_SCOPE scope )
290 {
291 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
292
293 FIXME("%p, %u\n", This, scope);
294 return S_OK;
295 }
296
297 static HRESULT WINAPI fw_app_get_RemoteAddresses(
298 INetFwAuthorizedApplication *iface,
299 BSTR *remoteAddrs )
300 {
301 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
302
303 FIXME("%p, %p\n", This, remoteAddrs);
304 return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI fw_app_put_RemoteAddresses(
308 INetFwAuthorizedApplication *iface,
309 BSTR remoteAddrs )
310 {
311 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
312
313 FIXME("%p, %s\n", This, debugstr_w(remoteAddrs));
314 return E_NOTIMPL;
315 }
316
317 static HRESULT WINAPI fw_app_get_Enabled(
318 INetFwAuthorizedApplication *iface,
319 VARIANT_BOOL *enabled )
320 {
321 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
322
323 FIXME("%p, %p\n", This, enabled);
324
325 *enabled = VARIANT_FALSE;
326 return S_OK;
327 }
328
329 static HRESULT WINAPI fw_app_put_Enabled(
330 INetFwAuthorizedApplication *iface,
331 VARIANT_BOOL enabled )
332 {
333 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
334
335 FIXME("%p, %d\n", This, enabled);
336 return S_OK;
337 }
338
339 static const struct INetFwAuthorizedApplicationVtbl fw_app_vtbl =
340 {
341 fw_app_QueryInterface,
342 fw_app_AddRef,
343 fw_app_Release,
344 fw_app_GetTypeInfoCount,
345 fw_app_GetTypeInfo,
346 fw_app_GetIDsOfNames,
347 fw_app_Invoke,
348 fw_app_get_Name,
349 fw_app_put_Name,
350 fw_app_get_ProcessImageFileName,
351 fw_app_put_ProcessImageFileName,
352 fw_app_get_IpVersion,
353 fw_app_put_IpVersion,
354 fw_app_get_Scope,
355 fw_app_put_Scope,
356 fw_app_get_RemoteAddresses,
357 fw_app_put_RemoteAddresses,
358 fw_app_get_Enabled,
359 fw_app_put_Enabled
360 };
361
362 HRESULT NetFwAuthorizedApplication_create( IUnknown *pUnkOuter, LPVOID *ppObj )
363 {
364 fw_app *fa;
365
366 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
367
368 fa = HeapAlloc( GetProcessHeap(), 0, sizeof(*fa) );
369 if (!fa) return E_OUTOFMEMORY;
370
371 fa->INetFwAuthorizedApplication_iface.lpVtbl = &fw_app_vtbl;
372 fa->refs = 1;
373
374 *ppObj = &fa->INetFwAuthorizedApplication_iface;
375
376 TRACE("returning iface %p\n", *ppObj);
377 return S_OK;
378 }
379 typedef struct fw_apps
380 {
381 INetFwAuthorizedApplications INetFwAuthorizedApplications_iface;
382 LONG refs;
383 } fw_apps;
384
385 static inline fw_apps *impl_from_INetFwAuthorizedApplications( INetFwAuthorizedApplications *iface )
386 {
387 return CONTAINING_RECORD(iface, fw_apps, INetFwAuthorizedApplications_iface);
388 }
389
390 static ULONG WINAPI fw_apps_AddRef(
391 INetFwAuthorizedApplications *iface )
392 {
393 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface );
394 return InterlockedIncrement( &fw_apps->refs );
395 }
396
397 static ULONG WINAPI fw_apps_Release(
398 INetFwAuthorizedApplications *iface )
399 {
400 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface );
401 LONG refs = InterlockedDecrement( &fw_apps->refs );
402 if (!refs)
403 {
404 TRACE("destroying %p\n", fw_apps);
405 HeapFree( GetProcessHeap(), 0, fw_apps );
406 }
407 return refs;
408 }
409
410 static HRESULT WINAPI fw_apps_QueryInterface(
411 INetFwAuthorizedApplications *iface,
412 REFIID riid,
413 void **ppvObject )
414 {
415 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
416
417 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
418
419 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplications ) ||
420 IsEqualGUID( riid, &IID_IDispatch ) ||
421 IsEqualGUID( riid, &IID_IUnknown ) )
422 {
423 *ppvObject = iface;
424 }
425 else
426 {
427 FIXME("interface %s not implemented\n", debugstr_guid(riid));
428 return E_NOINTERFACE;
429 }
430 INetFwAuthorizedApplications_AddRef( iface );
431 return S_OK;
432 }
433
434 static HRESULT WINAPI fw_apps_GetTypeInfoCount(
435 INetFwAuthorizedApplications *iface,
436 UINT *pctinfo )
437 {
438 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
439
440 FIXME("%p %p\n", This, pctinfo);
441 return E_NOTIMPL;
442 }
443
444 static HRESULT WINAPI fw_apps_GetTypeInfo(
445 INetFwAuthorizedApplications *iface,
446 UINT iTInfo,
447 LCID lcid,
448 ITypeInfo **ppTInfo )
449 {
450 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
451
452 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
453 return get_typeinfo( INetFwAuthorizedApplications_tid, ppTInfo );
454 }
455
456 static HRESULT WINAPI fw_apps_GetIDsOfNames(
457 INetFwAuthorizedApplications *iface,
458 REFIID riid,
459 LPOLESTR *rgszNames,
460 UINT cNames,
461 LCID lcid,
462 DISPID *rgDispId )
463 {
464 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
465 ITypeInfo *typeinfo;
466 HRESULT hr;
467
468 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
469
470 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo );
471 if (SUCCEEDED(hr))
472 {
473 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
474 ITypeInfo_Release( typeinfo );
475 }
476 return hr;
477 }
478
479 static HRESULT WINAPI fw_apps_Invoke(
480 INetFwAuthorizedApplications *iface,
481 DISPID dispIdMember,
482 REFIID riid,
483 LCID lcid,
484 WORD wFlags,
485 DISPPARAMS *pDispParams,
486 VARIANT *pVarResult,
487 EXCEPINFO *pExcepInfo,
488 UINT *puArgErr )
489 {
490 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
491 ITypeInfo *typeinfo;
492 HRESULT hr;
493
494 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
495 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
496
497 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo );
498 if (SUCCEEDED(hr))
499 {
500 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplications_iface, dispIdMember,
501 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
502 ITypeInfo_Release( typeinfo );
503 }
504 return hr;
505 }
506
507 static HRESULT WINAPI fw_apps_get_Count(
508 INetFwAuthorizedApplications *iface,
509 LONG *count )
510 {
511 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
512
513 FIXME("%p, %p\n", This, count);
514 return E_NOTIMPL;
515 }
516
517 static HRESULT WINAPI fw_apps_Add(
518 INetFwAuthorizedApplications *iface,
519 INetFwAuthorizedApplication *app )
520 {
521 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
522
523 FIXME("%p, %p\n", This, app);
524 return S_OK;
525 }
526
527 static HRESULT WINAPI fw_apps_Remove(
528 INetFwAuthorizedApplications *iface,
529 BSTR imageFileName )
530 {
531 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
532
533 FIXME("%p, %s\n", This, debugstr_w(imageFileName));
534 return S_OK;
535 }
536
537 static HRESULT WINAPI fw_apps_Item(
538 INetFwAuthorizedApplications *iface,
539 BSTR imageFileName,
540 INetFwAuthorizedApplication **app )
541 {
542 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
543
544 TRACE("%p, %s, %p\n", This, debugstr_w(imageFileName), app);
545 return NetFwAuthorizedApplication_create( NULL, (void **)app );
546 }
547
548 static HRESULT WINAPI fw_apps_get__NewEnum(
549 INetFwAuthorizedApplications *iface,
550 IUnknown **newEnum )
551 {
552 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
553
554 FIXME("%p, %p\n", This, newEnum);
555 return E_NOTIMPL;
556 }
557
558 static const struct INetFwAuthorizedApplicationsVtbl fw_apps_vtbl =
559 {
560 fw_apps_QueryInterface,
561 fw_apps_AddRef,
562 fw_apps_Release,
563 fw_apps_GetTypeInfoCount,
564 fw_apps_GetTypeInfo,
565 fw_apps_GetIDsOfNames,
566 fw_apps_Invoke,
567 fw_apps_get_Count,
568 fw_apps_Add,
569 fw_apps_Remove,
570 fw_apps_Item,
571 fw_apps_get__NewEnum
572 };
573
574 HRESULT NetFwAuthorizedApplications_create( IUnknown *pUnkOuter, LPVOID *ppObj )
575 {
576 fw_apps *fa;
577
578 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
579
580 fa = HeapAlloc( GetProcessHeap(), 0, sizeof(*fa) );
581 if (!fa) return E_OUTOFMEMORY;
582
583 fa->INetFwAuthorizedApplications_iface.lpVtbl = &fw_apps_vtbl;
584 fa->refs = 1;
585
586 *ppObj = &fa->INetFwAuthorizedApplications_iface;
587
588 TRACE("returning iface %p\n", *ppObj);
589 return S_OK;
590 }