winex11.drv: Map coordinates before calling send_mouse_input.
[wine/zf.git] / dlls / hnetcfg / apps.c
blobb6447cf4d639a37906d331922b17eecdf823ffea
1 /*
2 * Copyright 2009 Hans Leidekker for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28 #include "netfw.h"
29 #include "natupnp.h"
31 #include "wine/debug.h"
32 #include "wine/heap.h"
33 #include "hnetcfg_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(hnetcfg);
37 typedef struct fw_app
39 INetFwAuthorizedApplication INetFwAuthorizedApplication_iface;
40 LONG refs;
41 BSTR filename;
42 } fw_app;
44 static inline fw_app *impl_from_INetFwAuthorizedApplication( INetFwAuthorizedApplication *iface )
46 return CONTAINING_RECORD(iface, fw_app, INetFwAuthorizedApplication_iface);
49 static ULONG WINAPI fw_app_AddRef(
50 INetFwAuthorizedApplication *iface )
52 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface );
53 return InterlockedIncrement( &fw_app->refs );
56 static ULONG WINAPI fw_app_Release(
57 INetFwAuthorizedApplication *iface )
59 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface );
60 LONG refs = InterlockedDecrement( &fw_app->refs );
61 if (!refs)
63 TRACE("destroying %p\n", fw_app);
64 SysFreeString( fw_app->filename );
65 HeapFree( GetProcessHeap(), 0, fw_app );
67 return refs;
70 static HRESULT WINAPI fw_app_QueryInterface(
71 INetFwAuthorizedApplication *iface,
72 REFIID riid,
73 void **ppvObject )
75 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
77 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
79 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplication ) ||
80 IsEqualGUID( riid, &IID_IDispatch ) ||
81 IsEqualGUID( riid, &IID_IUnknown ) )
83 *ppvObject = iface;
85 else
87 FIXME("interface %s not implemented\n", debugstr_guid(riid));
88 return E_NOINTERFACE;
90 INetFwAuthorizedApplication_AddRef( iface );
91 return S_OK;
94 static HRESULT WINAPI fw_app_GetTypeInfoCount(
95 INetFwAuthorizedApplication *iface,
96 UINT *pctinfo )
98 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
100 TRACE("%p %p\n", This, pctinfo);
101 *pctinfo = 1;
102 return S_OK;
105 static ITypeLib *typelib;
106 static ITypeInfo *typeinfo[last_tid];
108 static REFIID tid_id[] =
110 &IID_INetFwAuthorizedApplication,
111 &IID_INetFwAuthorizedApplications,
112 &IID_INetFwMgr,
113 &IID_INetFwOpenPort,
114 &IID_INetFwOpenPorts,
115 &IID_INetFwPolicy,
116 &IID_INetFwPolicy2,
117 &IID_INetFwProfile,
118 &IID_IUPnPNAT
121 HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret )
123 HRESULT hr;
125 if (!typelib)
127 ITypeLib *lib;
129 hr = LoadRegTypeLib( &LIBID_NetFwPublicTypeLib, 1, 0, LOCALE_SYSTEM_DEFAULT, &lib );
130 if (FAILED(hr))
132 ERR("LoadRegTypeLib failed: %08x\n", hr);
133 return hr;
135 if (InterlockedCompareExchangePointer( (void **)&typelib, lib, NULL ))
136 ITypeLib_Release( lib );
138 if (!typeinfo[tid])
140 ITypeInfo *info;
142 hr = ITypeLib_GetTypeInfoOfGuid( typelib, tid_id[tid], &info );
143 if (FAILED(hr))
145 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_id[tid]), hr);
146 return hr;
148 if (InterlockedCompareExchangePointer( (void **)(typeinfo + tid), info, NULL ))
149 ITypeInfo_Release( info );
151 *ret = typeinfo[tid];
152 ITypeInfo_AddRef(typeinfo[tid]);
153 return S_OK;
156 void release_typelib(void)
158 unsigned i;
160 for (i = 0; i < ARRAY_SIZE(typeinfo); i++)
161 if (typeinfo[i])
162 ITypeInfo_Release(typeinfo[i]);
164 if (typelib)
165 ITypeLib_Release(typelib);
168 static HRESULT WINAPI fw_app_GetTypeInfo(
169 INetFwAuthorizedApplication *iface,
170 UINT iTInfo,
171 LCID lcid,
172 ITypeInfo **ppTInfo )
174 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
176 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
177 return get_typeinfo( INetFwAuthorizedApplication_tid, ppTInfo );
180 static HRESULT WINAPI fw_app_GetIDsOfNames(
181 INetFwAuthorizedApplication *iface,
182 REFIID riid,
183 LPOLESTR *rgszNames,
184 UINT cNames,
185 LCID lcid,
186 DISPID *rgDispId )
188 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
189 ITypeInfo *typeinfo;
190 HRESULT hr;
192 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
194 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo );
195 if (SUCCEEDED(hr))
197 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
198 ITypeInfo_Release( typeinfo );
200 return hr;
203 static HRESULT WINAPI fw_app_Invoke(
204 INetFwAuthorizedApplication *iface,
205 DISPID dispIdMember,
206 REFIID riid,
207 LCID lcid,
208 WORD wFlags,
209 DISPPARAMS *pDispParams,
210 VARIANT *pVarResult,
211 EXCEPINFO *pExcepInfo,
212 UINT *puArgErr )
214 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
215 ITypeInfo *typeinfo;
216 HRESULT hr;
218 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
219 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
221 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo );
222 if (SUCCEEDED(hr))
224 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplication_iface, dispIdMember,
225 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
226 ITypeInfo_Release( typeinfo );
228 return hr;
231 static HRESULT WINAPI fw_app_get_Name(
232 INetFwAuthorizedApplication *iface,
233 BSTR *name )
235 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
237 FIXME("%p, %p\n", This, name);
238 return E_NOTIMPL;
241 static HRESULT WINAPI fw_app_put_Name(
242 INetFwAuthorizedApplication *iface,
243 BSTR name )
245 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
247 FIXME("%p, %s\n", This, debugstr_w(name));
248 return S_OK;
251 static HRESULT WINAPI fw_app_get_ProcessImageFileName(
252 INetFwAuthorizedApplication *iface,
253 BSTR *imageFileName )
255 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
257 FIXME("%p, %p\n", This, imageFileName);
259 if (!imageFileName)
260 return E_POINTER;
262 *imageFileName = SysAllocString( This->filename );
263 return *imageFileName || !This->filename ? S_OK : E_OUTOFMEMORY;
266 static HRESULT WINAPI fw_app_put_ProcessImageFileName(
267 INetFwAuthorizedApplication *iface, BSTR image )
269 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
270 UNIVERSAL_NAME_INFOW *info;
271 DWORD sz, longsz;
272 WCHAR *path;
273 DWORD res;
275 FIXME("%p, %s\n", This, debugstr_w(image));
277 if (!image || !image[0])
278 return E_INVALIDARG;
280 sz = 0;
281 res = WNetGetUniversalNameW(image, UNIVERSAL_NAME_INFO_LEVEL, NULL, &sz);
282 if (res == WN_MORE_DATA)
284 if (!(path = heap_alloc(sz)))
285 return E_OUTOFMEMORY;
287 info = (UNIVERSAL_NAME_INFOW *)&path;
288 res = WNetGetUniversalNameW(image, UNIVERSAL_NAME_INFO_LEVEL, &info, &sz);
289 if (res == NO_ERROR)
291 SysFreeString(This->filename);
292 This->filename = SysAllocString(info->lpUniversalName);
294 heap_free(path);
295 return HRESULT_FROM_WIN32(res);
298 sz = GetFullPathNameW(image, 0, NULL, NULL);
299 if (!(path = heap_alloc(++sz * sizeof(WCHAR))))
300 return E_OUTOFMEMORY;
301 GetFullPathNameW(image, sz, path, NULL);
303 longsz = GetLongPathNameW(path, path, sz);
304 if (longsz > sz)
306 if (!(path = heap_realloc(path, longsz * sizeof(WCHAR))))
308 heap_free(path);
309 return E_OUTOFMEMORY;
311 GetLongPathNameW(path, path, longsz);
314 SysFreeString( This->filename );
315 This->filename = SysAllocString(path);
316 heap_free(path);
317 return This->filename ? S_OK : E_OUTOFMEMORY;
320 static HRESULT WINAPI fw_app_get_IpVersion(
321 INetFwAuthorizedApplication *iface,
322 NET_FW_IP_VERSION *ipVersion )
324 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
326 TRACE("%p, %p\n", This, ipVersion);
328 if (!ipVersion)
329 return E_POINTER;
330 *ipVersion = NET_FW_IP_VERSION_ANY;
331 return S_OK;
334 static HRESULT WINAPI fw_app_put_IpVersion(
335 INetFwAuthorizedApplication *iface,
336 NET_FW_IP_VERSION ipVersion )
338 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
340 TRACE("%p, %u\n", This, ipVersion);
341 return S_OK;
344 static HRESULT WINAPI fw_app_get_Scope(
345 INetFwAuthorizedApplication *iface,
346 NET_FW_SCOPE *scope )
348 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
350 FIXME("%p, %p\n", This, scope);
351 return E_NOTIMPL;
354 static HRESULT WINAPI fw_app_put_Scope(
355 INetFwAuthorizedApplication *iface,
356 NET_FW_SCOPE scope )
358 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
360 FIXME("%p, %u\n", This, scope);
361 return S_OK;
364 static HRESULT WINAPI fw_app_get_RemoteAddresses(
365 INetFwAuthorizedApplication *iface,
366 BSTR *remoteAddrs )
368 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
370 FIXME("%p, %p\n", This, remoteAddrs);
371 return E_NOTIMPL;
374 static HRESULT WINAPI fw_app_put_RemoteAddresses(
375 INetFwAuthorizedApplication *iface,
376 BSTR remoteAddrs )
378 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
380 FIXME("%p, %s\n", This, debugstr_w(remoteAddrs));
381 return E_NOTIMPL;
384 static HRESULT WINAPI fw_app_get_Enabled(
385 INetFwAuthorizedApplication *iface,
386 VARIANT_BOOL *enabled )
388 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
390 FIXME("%p, %p\n", This, enabled);
392 *enabled = VARIANT_FALSE;
393 return S_OK;
396 static HRESULT WINAPI fw_app_put_Enabled(
397 INetFwAuthorizedApplication *iface,
398 VARIANT_BOOL enabled )
400 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
402 FIXME("%p, %d\n", This, enabled);
403 return S_OK;
406 static const struct INetFwAuthorizedApplicationVtbl fw_app_vtbl =
408 fw_app_QueryInterface,
409 fw_app_AddRef,
410 fw_app_Release,
411 fw_app_GetTypeInfoCount,
412 fw_app_GetTypeInfo,
413 fw_app_GetIDsOfNames,
414 fw_app_Invoke,
415 fw_app_get_Name,
416 fw_app_put_Name,
417 fw_app_get_ProcessImageFileName,
418 fw_app_put_ProcessImageFileName,
419 fw_app_get_IpVersion,
420 fw_app_put_IpVersion,
421 fw_app_get_Scope,
422 fw_app_put_Scope,
423 fw_app_get_RemoteAddresses,
424 fw_app_put_RemoteAddresses,
425 fw_app_get_Enabled,
426 fw_app_put_Enabled
429 HRESULT NetFwAuthorizedApplication_create( IUnknown *pUnkOuter, LPVOID *ppObj )
431 fw_app *fa;
433 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
435 fa = HeapAlloc( GetProcessHeap(), 0, sizeof(*fa) );
436 if (!fa) return E_OUTOFMEMORY;
438 fa->INetFwAuthorizedApplication_iface.lpVtbl = &fw_app_vtbl;
439 fa->refs = 1;
440 fa->filename = NULL;
442 *ppObj = &fa->INetFwAuthorizedApplication_iface;
444 TRACE("returning iface %p\n", *ppObj);
445 return S_OK;
447 typedef struct fw_apps
449 INetFwAuthorizedApplications INetFwAuthorizedApplications_iface;
450 LONG refs;
451 } fw_apps;
453 static inline fw_apps *impl_from_INetFwAuthorizedApplications( INetFwAuthorizedApplications *iface )
455 return CONTAINING_RECORD(iface, fw_apps, INetFwAuthorizedApplications_iface);
458 static ULONG WINAPI fw_apps_AddRef(
459 INetFwAuthorizedApplications *iface )
461 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface );
462 return InterlockedIncrement( &fw_apps->refs );
465 static ULONG WINAPI fw_apps_Release(
466 INetFwAuthorizedApplications *iface )
468 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface );
469 LONG refs = InterlockedDecrement( &fw_apps->refs );
470 if (!refs)
472 TRACE("destroying %p\n", fw_apps);
473 HeapFree( GetProcessHeap(), 0, fw_apps );
475 return refs;
478 static HRESULT WINAPI fw_apps_QueryInterface(
479 INetFwAuthorizedApplications *iface,
480 REFIID riid,
481 void **ppvObject )
483 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
485 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
487 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplications ) ||
488 IsEqualGUID( riid, &IID_IDispatch ) ||
489 IsEqualGUID( riid, &IID_IUnknown ) )
491 *ppvObject = iface;
493 else
495 FIXME("interface %s not implemented\n", debugstr_guid(riid));
496 return E_NOINTERFACE;
498 INetFwAuthorizedApplications_AddRef( iface );
499 return S_OK;
502 static HRESULT WINAPI fw_apps_GetTypeInfoCount(
503 INetFwAuthorizedApplications *iface,
504 UINT *pctinfo )
506 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
508 FIXME("%p %p\n", This, pctinfo);
509 return E_NOTIMPL;
512 static HRESULT WINAPI fw_apps_GetTypeInfo(
513 INetFwAuthorizedApplications *iface,
514 UINT iTInfo,
515 LCID lcid,
516 ITypeInfo **ppTInfo )
518 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
520 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
521 return get_typeinfo( INetFwAuthorizedApplications_tid, ppTInfo );
524 static HRESULT WINAPI fw_apps_GetIDsOfNames(
525 INetFwAuthorizedApplications *iface,
526 REFIID riid,
527 LPOLESTR *rgszNames,
528 UINT cNames,
529 LCID lcid,
530 DISPID *rgDispId )
532 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
533 ITypeInfo *typeinfo;
534 HRESULT hr;
536 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
538 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo );
539 if (SUCCEEDED(hr))
541 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
542 ITypeInfo_Release( typeinfo );
544 return hr;
547 static HRESULT WINAPI fw_apps_Invoke(
548 INetFwAuthorizedApplications *iface,
549 DISPID dispIdMember,
550 REFIID riid,
551 LCID lcid,
552 WORD wFlags,
553 DISPPARAMS *pDispParams,
554 VARIANT *pVarResult,
555 EXCEPINFO *pExcepInfo,
556 UINT *puArgErr )
558 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
559 ITypeInfo *typeinfo;
560 HRESULT hr;
562 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
563 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
565 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo );
566 if (SUCCEEDED(hr))
568 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplications_iface, dispIdMember,
569 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
570 ITypeInfo_Release( typeinfo );
572 return hr;
575 static HRESULT WINAPI fw_apps_get_Count(
576 INetFwAuthorizedApplications *iface,
577 LONG *count )
579 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
581 FIXME("%p, %p\n", This, count);
582 return E_NOTIMPL;
585 static HRESULT WINAPI fw_apps_Add(
586 INetFwAuthorizedApplications *iface,
587 INetFwAuthorizedApplication *app )
589 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
591 FIXME("%p, %p\n", This, app);
592 return S_OK;
595 static HRESULT WINAPI fw_apps_Remove(
596 INetFwAuthorizedApplications *iface,
597 BSTR imageFileName )
599 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
601 FIXME("%p, %s\n", This, debugstr_w(imageFileName));
602 return S_OK;
605 static HRESULT WINAPI fw_apps_Item(
606 INetFwAuthorizedApplications *iface,
607 BSTR imageFileName,
608 INetFwAuthorizedApplication **app )
610 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
612 TRACE("%p, %s, %p\n", This, debugstr_w(imageFileName), app);
613 return NetFwAuthorizedApplication_create( NULL, (void **)app );
616 static HRESULT WINAPI fw_apps_get__NewEnum(
617 INetFwAuthorizedApplications *iface,
618 IUnknown **newEnum )
620 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
622 FIXME("%p, %p\n", This, newEnum);
623 return E_NOTIMPL;
626 static const struct INetFwAuthorizedApplicationsVtbl fw_apps_vtbl =
628 fw_apps_QueryInterface,
629 fw_apps_AddRef,
630 fw_apps_Release,
631 fw_apps_GetTypeInfoCount,
632 fw_apps_GetTypeInfo,
633 fw_apps_GetIDsOfNames,
634 fw_apps_Invoke,
635 fw_apps_get_Count,
636 fw_apps_Add,
637 fw_apps_Remove,
638 fw_apps_Item,
639 fw_apps_get__NewEnum
642 HRESULT NetFwAuthorizedApplications_create( IUnknown *pUnkOuter, LPVOID *ppObj )
644 fw_apps *fa;
646 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
648 fa = HeapAlloc( GetProcessHeap(), 0, sizeof(*fa) );
649 if (!fa) return E_OUTOFMEMORY;
651 fa->INetFwAuthorizedApplications_iface.lpVtbl = &fw_apps_vtbl;
652 fa->refs = 1;
654 *ppObj = &fa->INetFwAuthorizedApplications_iface;
656 TRACE("returning iface %p\n", *ppObj);
657 return S_OK;