d3d10/tests: Add a test for effect compilation containing empty buffers.
[wine.git] / dlls / hnetcfg / apps.c
blob842ead499fbcb2d5889b5cea4f2b2fc1ad173b9a
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 "hnetcfg_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(hnetcfg);
36 typedef struct fw_app
38 INetFwAuthorizedApplication INetFwAuthorizedApplication_iface;
39 LONG refs;
40 BSTR filename;
41 } fw_app;
43 static inline fw_app *impl_from_INetFwAuthorizedApplication( INetFwAuthorizedApplication *iface )
45 return CONTAINING_RECORD(iface, fw_app, INetFwAuthorizedApplication_iface);
48 static ULONG WINAPI fw_app_AddRef(
49 INetFwAuthorizedApplication *iface )
51 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface );
52 return InterlockedIncrement( &fw_app->refs );
55 static ULONG WINAPI fw_app_Release(
56 INetFwAuthorizedApplication *iface )
58 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface );
59 LONG refs = InterlockedDecrement( &fw_app->refs );
60 if (!refs)
62 TRACE("destroying %p\n", fw_app);
63 SysFreeString( fw_app->filename );
64 free( fw_app );
66 return refs;
69 static HRESULT WINAPI fw_app_QueryInterface(
70 INetFwAuthorizedApplication *iface,
71 REFIID riid,
72 void **ppvObject )
74 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
76 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
78 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplication ) ||
79 IsEqualGUID( riid, &IID_IDispatch ) ||
80 IsEqualGUID( riid, &IID_IUnknown ) )
82 *ppvObject = iface;
84 else
86 FIXME("interface %s not implemented\n", debugstr_guid(riid));
87 return E_NOINTERFACE;
89 INetFwAuthorizedApplication_AddRef( iface );
90 return S_OK;
93 static HRESULT WINAPI fw_app_GetTypeInfoCount(
94 INetFwAuthorizedApplication *iface,
95 UINT *pctinfo )
97 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
99 TRACE("%p %p\n", This, pctinfo);
100 *pctinfo = 1;
101 return S_OK;
104 static ITypeLib *typelib;
105 static ITypeInfo *typeinfo[last_tid];
107 static REFIID tid_id[] =
109 &IID_INetFwAuthorizedApplication,
110 &IID_INetFwAuthorizedApplications,
111 &IID_INetFwMgr,
112 &IID_INetFwOpenPort,
113 &IID_INetFwOpenPorts,
114 &IID_INetFwPolicy,
115 &IID_INetFwPolicy2,
116 &IID_INetFwProfile,
117 &IID_IUPnPNAT,
118 &IID_IStaticPortMappingCollection,
119 &IID_IStaticPortMapping,
122 HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret )
124 HRESULT hr;
126 if (!typelib)
128 ITypeLib *lib;
130 hr = LoadRegTypeLib( &LIBID_NetFwPublicTypeLib, 1, 0, LOCALE_SYSTEM_DEFAULT, &lib );
131 if (FAILED(hr))
133 ERR("LoadRegTypeLib failed: %08lx\n", hr);
134 return hr;
136 if (InterlockedCompareExchangePointer( (void **)&typelib, lib, NULL ))
137 ITypeLib_Release( lib );
139 if (!typeinfo[tid])
141 ITypeInfo *info;
143 hr = ITypeLib_GetTypeInfoOfGuid( typelib, tid_id[tid], &info );
144 if (FAILED(hr))
146 ERR("GetTypeInfoOfGuid(%s) failed: %08lx\n", debugstr_guid(tid_id[tid]), hr);
147 return hr;
149 if (InterlockedCompareExchangePointer( (void **)(typeinfo + tid), info, NULL ))
150 ITypeInfo_Release( info );
152 *ret = typeinfo[tid];
153 ITypeInfo_AddRef(typeinfo[tid]);
154 return S_OK;
157 void release_typelib(void)
159 unsigned i;
161 for (i = 0; i < ARRAY_SIZE(typeinfo); i++)
162 if (typeinfo[i])
163 ITypeInfo_Release(typeinfo[i]);
165 if (typelib)
166 ITypeLib_Release(typelib);
169 static HRESULT WINAPI fw_app_GetTypeInfo(
170 INetFwAuthorizedApplication *iface,
171 UINT iTInfo,
172 LCID lcid,
173 ITypeInfo **ppTInfo )
175 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
177 TRACE("%p %u %lu %p\n", This, iTInfo, lcid, ppTInfo);
178 return get_typeinfo( INetFwAuthorizedApplication_tid, ppTInfo );
181 static HRESULT WINAPI fw_app_GetIDsOfNames(
182 INetFwAuthorizedApplication *iface,
183 REFIID riid,
184 LPOLESTR *rgszNames,
185 UINT cNames,
186 LCID lcid,
187 DISPID *rgDispId )
189 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
190 ITypeInfo *typeinfo;
191 HRESULT hr;
193 TRACE("%p %s %p %u %lu %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
195 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo );
196 if (SUCCEEDED(hr))
198 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
199 ITypeInfo_Release( typeinfo );
201 return hr;
204 static HRESULT WINAPI fw_app_Invoke(
205 INetFwAuthorizedApplication *iface,
206 DISPID dispIdMember,
207 REFIID riid,
208 LCID lcid,
209 WORD wFlags,
210 DISPPARAMS *pDispParams,
211 VARIANT *pVarResult,
212 EXCEPINFO *pExcepInfo,
213 UINT *puArgErr )
215 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
216 ITypeInfo *typeinfo;
217 HRESULT hr;
219 TRACE("%p %ld %s %ld %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
220 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
222 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo );
223 if (SUCCEEDED(hr))
225 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplication_iface, dispIdMember,
226 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
227 ITypeInfo_Release( typeinfo );
229 return hr;
232 static HRESULT WINAPI fw_app_get_Name(
233 INetFwAuthorizedApplication *iface,
234 BSTR *name )
236 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
238 FIXME("%p, %p\n", This, name);
239 return E_NOTIMPL;
242 static HRESULT WINAPI fw_app_put_Name(
243 INetFwAuthorizedApplication *iface,
244 BSTR name )
246 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
248 FIXME("%p, %s\n", This, debugstr_w(name));
249 return S_OK;
252 static HRESULT WINAPI fw_app_get_ProcessImageFileName(
253 INetFwAuthorizedApplication *iface,
254 BSTR *imageFileName )
256 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
258 FIXME("%p, %p\n", This, imageFileName);
260 if (!imageFileName)
261 return E_POINTER;
263 *imageFileName = SysAllocString( This->filename );
264 return *imageFileName || !This->filename ? S_OK : E_OUTOFMEMORY;
267 static HRESULT WINAPI fw_app_put_ProcessImageFileName(
268 INetFwAuthorizedApplication *iface, BSTR image )
270 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
271 UNIVERSAL_NAME_INFOW *info;
272 DWORD sz, longsz;
273 WCHAR *path, *new_path;
274 DWORD res;
276 FIXME("%p, %s\n", This, debugstr_w(image));
278 if (!image || !image[0])
279 return E_INVALIDARG;
281 sz = 0;
282 res = WNetGetUniversalNameW(image, UNIVERSAL_NAME_INFO_LEVEL, NULL, &sz);
283 if (res == WN_MORE_DATA)
285 if (!(path = malloc(sz)))
286 return E_OUTOFMEMORY;
288 info = (UNIVERSAL_NAME_INFOW *)&path;
289 res = WNetGetUniversalNameW(image, UNIVERSAL_NAME_INFO_LEVEL, &info, &sz);
290 if (res == NO_ERROR)
292 SysFreeString(This->filename);
293 This->filename = SysAllocString(info->lpUniversalName);
295 free(path);
296 return HRESULT_FROM_WIN32(res);
299 sz = GetFullPathNameW(image, 0, NULL, NULL);
300 if (!(path = malloc(++sz * sizeof(WCHAR))))
301 return E_OUTOFMEMORY;
302 GetFullPathNameW(image, sz, path, NULL);
304 longsz = GetLongPathNameW(path, path, sz);
305 if (longsz > sz)
307 if (!(new_path = realloc(path, longsz * sizeof(WCHAR))))
309 free(path);
310 return E_OUTOFMEMORY;
312 path = new_path;
313 GetLongPathNameW(path, path, longsz);
316 SysFreeString( This->filename );
317 This->filename = SysAllocString(path);
318 free(path);
319 return This->filename ? S_OK : E_OUTOFMEMORY;
322 static HRESULT WINAPI fw_app_get_IpVersion(
323 INetFwAuthorizedApplication *iface,
324 NET_FW_IP_VERSION *ipVersion )
326 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
328 TRACE("%p, %p\n", This, ipVersion);
330 if (!ipVersion)
331 return E_POINTER;
332 *ipVersion = NET_FW_IP_VERSION_ANY;
333 return S_OK;
336 static HRESULT WINAPI fw_app_put_IpVersion(
337 INetFwAuthorizedApplication *iface,
338 NET_FW_IP_VERSION ipVersion )
340 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
342 TRACE("%p, %u\n", This, ipVersion);
343 return S_OK;
346 static HRESULT WINAPI fw_app_get_Scope(
347 INetFwAuthorizedApplication *iface,
348 NET_FW_SCOPE *scope )
350 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
352 FIXME("%p, %p\n", This, scope);
353 return E_NOTIMPL;
356 static HRESULT WINAPI fw_app_put_Scope(
357 INetFwAuthorizedApplication *iface,
358 NET_FW_SCOPE scope )
360 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
362 FIXME("%p, %u\n", This, scope);
363 return S_OK;
366 static HRESULT WINAPI fw_app_get_RemoteAddresses(
367 INetFwAuthorizedApplication *iface,
368 BSTR *remoteAddrs )
370 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
372 FIXME("%p, %p\n", This, remoteAddrs);
373 return E_NOTIMPL;
376 static HRESULT WINAPI fw_app_put_RemoteAddresses(
377 INetFwAuthorizedApplication *iface,
378 BSTR remoteAddrs )
380 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
382 FIXME("%p, %s\n", This, debugstr_w(remoteAddrs));
383 return E_NOTIMPL;
386 static HRESULT WINAPI fw_app_get_Enabled(
387 INetFwAuthorizedApplication *iface,
388 VARIANT_BOOL *enabled )
390 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
392 FIXME("%p, %p\n", This, enabled);
394 *enabled = VARIANT_FALSE;
395 return S_OK;
398 static HRESULT WINAPI fw_app_put_Enabled(
399 INetFwAuthorizedApplication *iface,
400 VARIANT_BOOL enabled )
402 fw_app *This = impl_from_INetFwAuthorizedApplication( iface );
404 FIXME("%p, %d\n", This, enabled);
405 return S_OK;
408 static const struct INetFwAuthorizedApplicationVtbl fw_app_vtbl =
410 fw_app_QueryInterface,
411 fw_app_AddRef,
412 fw_app_Release,
413 fw_app_GetTypeInfoCount,
414 fw_app_GetTypeInfo,
415 fw_app_GetIDsOfNames,
416 fw_app_Invoke,
417 fw_app_get_Name,
418 fw_app_put_Name,
419 fw_app_get_ProcessImageFileName,
420 fw_app_put_ProcessImageFileName,
421 fw_app_get_IpVersion,
422 fw_app_put_IpVersion,
423 fw_app_get_Scope,
424 fw_app_put_Scope,
425 fw_app_get_RemoteAddresses,
426 fw_app_put_RemoteAddresses,
427 fw_app_get_Enabled,
428 fw_app_put_Enabled
431 HRESULT NetFwAuthorizedApplication_create( IUnknown *pUnkOuter, LPVOID *ppObj )
433 fw_app *fa;
435 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
437 fa = malloc( sizeof(*fa) );
438 if (!fa) return E_OUTOFMEMORY;
440 fa->INetFwAuthorizedApplication_iface.lpVtbl = &fw_app_vtbl;
441 fa->refs = 1;
442 fa->filename = NULL;
444 *ppObj = &fa->INetFwAuthorizedApplication_iface;
446 TRACE("returning iface %p\n", *ppObj);
447 return S_OK;
449 typedef struct fw_apps
451 INetFwAuthorizedApplications INetFwAuthorizedApplications_iface;
452 LONG refs;
453 } fw_apps;
455 static inline fw_apps *impl_from_INetFwAuthorizedApplications( INetFwAuthorizedApplications *iface )
457 return CONTAINING_RECORD(iface, fw_apps, INetFwAuthorizedApplications_iface);
460 static ULONG WINAPI fw_apps_AddRef(
461 INetFwAuthorizedApplications *iface )
463 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface );
464 return InterlockedIncrement( &fw_apps->refs );
467 static ULONG WINAPI fw_apps_Release(
468 INetFwAuthorizedApplications *iface )
470 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface );
471 LONG refs = InterlockedDecrement( &fw_apps->refs );
472 if (!refs)
474 TRACE("destroying %p\n", fw_apps);
475 free( fw_apps );
477 return refs;
480 static HRESULT WINAPI fw_apps_QueryInterface(
481 INetFwAuthorizedApplications *iface,
482 REFIID riid,
483 void **ppvObject )
485 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
487 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
489 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplications ) ||
490 IsEqualGUID( riid, &IID_IDispatch ) ||
491 IsEqualGUID( riid, &IID_IUnknown ) )
493 *ppvObject = iface;
495 else
497 FIXME("interface %s not implemented\n", debugstr_guid(riid));
498 return E_NOINTERFACE;
500 INetFwAuthorizedApplications_AddRef( iface );
501 return S_OK;
504 static HRESULT WINAPI fw_apps_GetTypeInfoCount(
505 INetFwAuthorizedApplications *iface,
506 UINT *pctinfo )
508 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
510 FIXME("%p %p\n", This, pctinfo);
511 return E_NOTIMPL;
514 static HRESULT WINAPI fw_apps_GetTypeInfo(
515 INetFwAuthorizedApplications *iface,
516 UINT iTInfo,
517 LCID lcid,
518 ITypeInfo **ppTInfo )
520 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
522 TRACE("%p %u %lu %p\n", This, iTInfo, lcid, ppTInfo);
523 return get_typeinfo( INetFwAuthorizedApplications_tid, ppTInfo );
526 static HRESULT WINAPI fw_apps_GetIDsOfNames(
527 INetFwAuthorizedApplications *iface,
528 REFIID riid,
529 LPOLESTR *rgszNames,
530 UINT cNames,
531 LCID lcid,
532 DISPID *rgDispId )
534 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
535 ITypeInfo *typeinfo;
536 HRESULT hr;
538 TRACE("%p %s %p %u %lu %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
540 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo );
541 if (SUCCEEDED(hr))
543 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
544 ITypeInfo_Release( typeinfo );
546 return hr;
549 static HRESULT WINAPI fw_apps_Invoke(
550 INetFwAuthorizedApplications *iface,
551 DISPID dispIdMember,
552 REFIID riid,
553 LCID lcid,
554 WORD wFlags,
555 DISPPARAMS *pDispParams,
556 VARIANT *pVarResult,
557 EXCEPINFO *pExcepInfo,
558 UINT *puArgErr )
560 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
561 ITypeInfo *typeinfo;
562 HRESULT hr;
564 TRACE("%p %ld %s %ld %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
565 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
567 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo );
568 if (SUCCEEDED(hr))
570 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplications_iface, dispIdMember,
571 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
572 ITypeInfo_Release( typeinfo );
574 return hr;
577 static HRESULT WINAPI fw_apps_get_Count(
578 INetFwAuthorizedApplications *iface,
579 LONG *count )
581 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
583 FIXME("%p, %p\n", This, count);
584 return E_NOTIMPL;
587 static HRESULT WINAPI fw_apps_Add(
588 INetFwAuthorizedApplications *iface,
589 INetFwAuthorizedApplication *app )
591 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
593 FIXME("%p, %p\n", This, app);
594 return S_OK;
597 static HRESULT WINAPI fw_apps_Remove(
598 INetFwAuthorizedApplications *iface,
599 BSTR imageFileName )
601 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
603 FIXME("%p, %s\n", This, debugstr_w(imageFileName));
604 return S_OK;
607 static HRESULT WINAPI fw_apps_Item(
608 INetFwAuthorizedApplications *iface,
609 BSTR imageFileName,
610 INetFwAuthorizedApplication **app )
612 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
614 TRACE("%p, %s, %p\n", This, debugstr_w(imageFileName), app);
615 return NetFwAuthorizedApplication_create( NULL, (void **)app );
618 static HRESULT WINAPI fw_apps_get__NewEnum(
619 INetFwAuthorizedApplications *iface,
620 IUnknown **newEnum )
622 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface );
624 FIXME("%p, %p\n", This, newEnum);
625 return E_NOTIMPL;
628 static const struct INetFwAuthorizedApplicationsVtbl fw_apps_vtbl =
630 fw_apps_QueryInterface,
631 fw_apps_AddRef,
632 fw_apps_Release,
633 fw_apps_GetTypeInfoCount,
634 fw_apps_GetTypeInfo,
635 fw_apps_GetIDsOfNames,
636 fw_apps_Invoke,
637 fw_apps_get_Count,
638 fw_apps_Add,
639 fw_apps_Remove,
640 fw_apps_Item,
641 fw_apps_get__NewEnum
644 HRESULT NetFwAuthorizedApplications_create( IUnknown *pUnkOuter, LPVOID *ppObj )
646 fw_apps *fa;
648 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
650 fa = malloc( sizeof(*fa) );
651 if (!fa) return E_OUTOFMEMORY;
653 fa->INetFwAuthorizedApplications_iface.lpVtbl = &fw_apps_vtbl;
654 fa->refs = 1;
656 *ppObj = &fa->INetFwAuthorizedApplications_iface;
658 TRACE("returning iface %p\n", *ppObj);
659 return S_OK;