regedit: Update the listview path when renaming a treeview node.
[wine.git] / dlls / netprofm / list.c
blobd82ae3661545898288a0e934d0223fce05ab1fee
1 /*
2 * Copyright 2014 Hans Leidekker for CodeWeavers
3 * Copyright 2015 Michael Müller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
24 #include "config.h"
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #define USE_WS_PREFIX
29 #include "winsock2.h"
30 #include "ws2ipdef.h"
31 #include "iphlpapi.h"
32 #include "ifdef.h"
33 #include "netioapi.h"
34 #include "initguid.h"
35 #include "objbase.h"
36 #include "ocidl.h"
37 #include "netlistmgr.h"
38 #include "olectl.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
42 #include "netprofm_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(netprofm);
46 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
48 return HeapAlloc(GetProcessHeap(), 0, size);
51 static inline BOOL heap_free(void *mem)
53 return HeapFree(GetProcessHeap(), 0, mem);
56 struct network
58 INetwork INetwork_iface;
59 LONG refs;
60 struct list entry;
61 GUID id;
62 VARIANT_BOOL connected_to_internet;
63 VARIANT_BOOL connected;
66 struct connection
68 INetworkConnection INetworkConnection_iface;
69 INetworkConnectionCost INetworkConnectionCost_iface;
70 LONG refs;
71 struct list entry;
72 GUID id;
73 INetwork *network;
74 VARIANT_BOOL connected_to_internet;
75 VARIANT_BOOL connected;
78 struct list_manager
80 INetworkListManager INetworkListManager_iface;
81 INetworkCostManager INetworkCostManager_iface;
82 IConnectionPointContainer IConnectionPointContainer_iface;
83 LONG refs;
84 struct list networks;
85 struct list connections;
88 struct connection_point
90 IConnectionPoint IConnectionPoint_iface;
91 IConnectionPointContainer *container;
92 LONG refs;
93 IID iid;
96 static inline struct list_manager *impl_from_IConnectionPointContainer(IConnectionPointContainer *iface)
98 return CONTAINING_RECORD(iface, struct list_manager, IConnectionPointContainer_iface);
101 static inline struct list_manager *impl_from_INetworkCostManager(
102 INetworkCostManager *iface )
104 return CONTAINING_RECORD( iface, struct list_manager, INetworkCostManager_iface );
107 static inline struct connection_point *impl_from_IConnectionPoint(
108 IConnectionPoint *iface )
110 return CONTAINING_RECORD( iface, struct connection_point, IConnectionPoint_iface );
113 static HRESULT WINAPI connection_point_QueryInterface(
114 IConnectionPoint *iface,
115 REFIID riid,
116 void **obj )
118 struct connection_point *cp = impl_from_IConnectionPoint( iface );
119 TRACE( "%p, %s, %p\n", cp, debugstr_guid(riid), obj );
121 if (IsEqualGUID( riid, &IID_IConnectionPoint ) ||
122 IsEqualGUID( riid, &IID_IUnknown ))
124 *obj = iface;
126 else
128 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
129 *obj = NULL;
130 return E_NOINTERFACE;
132 IConnectionPoint_AddRef( iface );
133 return S_OK;
136 static ULONG WINAPI connection_point_AddRef(
137 IConnectionPoint *iface )
139 struct connection_point *cp = impl_from_IConnectionPoint( iface );
140 return InterlockedIncrement( &cp->refs );
143 static ULONG WINAPI connection_point_Release(
144 IConnectionPoint *iface )
146 struct connection_point *cp = impl_from_IConnectionPoint( iface );
147 LONG refs = InterlockedDecrement( &cp->refs );
148 if (!refs)
150 TRACE( "destroying %p\n", cp );
151 IConnectionPointContainer_Release( cp->container );
152 heap_free( cp );
154 return refs;
157 static HRESULT WINAPI connection_point_GetConnectionInterface(
158 IConnectionPoint *iface,
159 IID *iid )
161 struct connection_point *cp = impl_from_IConnectionPoint( iface );
162 TRACE( "%p, %p\n", cp, iid );
164 if (!iid)
165 return E_POINTER;
167 memcpy( iid, &cp->iid, sizeof(*iid) );
168 return S_OK;
171 static HRESULT WINAPI connection_point_GetConnectionPointContainer(
172 IConnectionPoint *iface,
173 IConnectionPointContainer **container )
175 struct connection_point *cp = impl_from_IConnectionPoint( iface );
176 TRACE( "%p, %p\n", cp, container );
178 if (!container)
179 return E_POINTER;
181 IConnectionPointContainer_AddRef( cp->container );
182 *container = cp->container;
183 return S_OK;
186 static HRESULT WINAPI connection_point_Advise(
187 IConnectionPoint *iface,
188 IUnknown *sink,
189 DWORD *cookie )
191 struct connection_point *cp = impl_from_IConnectionPoint( iface );
192 FIXME( "%p, %p, %p - stub\n", cp, sink, cookie );
194 if (!sink || !cookie)
195 return E_POINTER;
197 return CONNECT_E_CANNOTCONNECT;
200 static HRESULT WINAPI connection_point_Unadvise(
201 IConnectionPoint *iface,
202 DWORD cookie )
204 struct connection_point *cp = impl_from_IConnectionPoint( iface );
205 FIXME( "%p, %d - stub\n", cp, cookie );
207 return E_POINTER;
210 static HRESULT WINAPI connection_point_EnumConnections(
211 IConnectionPoint *iface,
212 IEnumConnections **connections )
214 struct connection_point *cp = impl_from_IConnectionPoint( iface );
215 FIXME( "%p, %p - stub\n", cp, connections );
217 return E_NOTIMPL;
220 static const IConnectionPointVtbl connection_point_vtbl =
222 connection_point_QueryInterface,
223 connection_point_AddRef,
224 connection_point_Release,
225 connection_point_GetConnectionInterface,
226 connection_point_GetConnectionPointContainer,
227 connection_point_Advise,
228 connection_point_Unadvise,
229 connection_point_EnumConnections
232 static HRESULT connection_point_create(
233 IConnectionPoint **obj,
234 REFIID riid,
235 IConnectionPointContainer *container )
237 struct connection_point *cp;
238 TRACE( "%p, %s, %p\n", obj, debugstr_guid(riid), container );
240 if (!(cp = heap_alloc( sizeof(*cp) ))) return E_OUTOFMEMORY;
241 cp->IConnectionPoint_iface.lpVtbl = &connection_point_vtbl;
242 cp->container = container;
243 cp->refs = 1;
245 memcpy( &cp->iid, riid, sizeof(*riid) );
246 IConnectionPointContainer_AddRef( container );
248 *obj = &cp->IConnectionPoint_iface;
249 TRACE( "returning iface %p\n", *obj );
250 return S_OK;
253 static inline struct network *impl_from_INetwork(
254 INetwork *iface )
256 return CONTAINING_RECORD( iface, struct network, INetwork_iface );
259 static HRESULT WINAPI network_QueryInterface(
260 INetwork *iface, REFIID riid, void **obj )
262 struct network *network = impl_from_INetwork( iface );
264 TRACE( "%p, %s, %p\n", network, debugstr_guid(riid), obj );
266 if (IsEqualIID( riid, &IID_INetwork ) ||
267 IsEqualIID( riid, &IID_IDispatch ) ||
268 IsEqualIID( riid, &IID_IUnknown ))
270 *obj = iface;
271 INetwork_AddRef( iface );
272 return S_OK;
274 else
276 WARN( "interface not supported %s\n", debugstr_guid(riid) );
277 *obj = NULL;
278 return E_NOINTERFACE;
282 static ULONG WINAPI network_AddRef(
283 INetwork *iface )
285 struct network *network = impl_from_INetwork( iface );
287 TRACE( "%p\n", network );
288 return InterlockedIncrement( &network->refs );
291 static ULONG WINAPI network_Release(
292 INetwork *iface )
294 struct network *network = impl_from_INetwork( iface );
295 LONG refs;
297 TRACE( "%p\n", network );
299 if (!(refs = InterlockedDecrement( &network->refs )))
301 list_remove( &network->entry );
302 heap_free( network );
304 return refs;
307 static HRESULT WINAPI network_GetTypeInfoCount(
308 INetwork *iface,
309 UINT *count )
311 FIXME("\n");
312 return E_NOTIMPL;
315 static HRESULT WINAPI network_GetTypeInfo(
316 INetwork *iface,
317 UINT index,
318 LCID lcid,
319 ITypeInfo **info )
321 FIXME("\n");
322 return E_NOTIMPL;
325 static HRESULT WINAPI network_GetIDsOfNames(
326 INetwork *iface,
327 REFIID riid,
328 LPOLESTR *names,
329 UINT count,
330 LCID lcid,
331 DISPID *dispid )
333 FIXME("\n");
334 return E_NOTIMPL;
337 static HRESULT WINAPI network_Invoke(
338 INetwork *iface,
339 DISPID member,
340 REFIID riid,
341 LCID lcid,
342 WORD flags,
343 DISPPARAMS *params,
344 VARIANT *result,
345 EXCEPINFO *excep_info,
346 UINT *arg_err )
348 FIXME("\n");
349 return E_NOTIMPL;
352 static HRESULT WINAPI network_GetName(
353 INetwork *iface,
354 BSTR *pszNetworkName )
356 FIXME( "%p, %p\n", iface, pszNetworkName );
357 return E_NOTIMPL;
360 static HRESULT WINAPI network_SetName(
361 INetwork *iface,
362 BSTR szNetworkNewName )
364 FIXME( "%p, %s\n", iface, debugstr_w(szNetworkNewName) );
365 return E_NOTIMPL;
368 static HRESULT WINAPI network_GetDescription(
369 INetwork *iface,
370 BSTR *pszDescription )
372 FIXME( "%p, %p\n", iface, pszDescription );
373 return E_NOTIMPL;
376 static HRESULT WINAPI network_SetDescription(
377 INetwork *iface,
378 BSTR szDescription )
380 FIXME( "%p, %s\n", iface, debugstr_w(szDescription) );
381 return E_NOTIMPL;
384 static HRESULT WINAPI network_GetNetworkId(
385 INetwork *iface,
386 GUID *pgdGuidNetworkId )
388 struct network *network = impl_from_INetwork( iface );
390 TRACE( "%p, %p\n", iface, pgdGuidNetworkId );
392 *pgdGuidNetworkId = network->id;
393 return S_OK;
396 static HRESULT WINAPI network_GetDomainType(
397 INetwork *iface,
398 NLM_DOMAIN_TYPE *pDomainType )
400 FIXME( "%p, %p\n", iface, pDomainType );
402 *pDomainType = NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK;
403 return S_OK;
406 static HRESULT WINAPI network_GetNetworkConnections(
407 INetwork *iface,
408 IEnumNetworkConnections **ppEnumNetworkConnection )
410 FIXME( "%p, %p\n", iface, ppEnumNetworkConnection );
411 return E_NOTIMPL;
414 static HRESULT WINAPI network_GetTimeCreatedAndConnected(
415 INetwork *iface,
416 DWORD *pdwLowDateTimeCreated,
417 DWORD *pdwHighDateTimeCreated,
418 DWORD *pdwLowDateTimeConnected,
419 DWORD *pdwHighDateTimeConnected )
421 FIXME( "%p, %p, %p, %p, %p\n", iface, pdwLowDateTimeCreated, pdwHighDateTimeCreated,
422 pdwLowDateTimeConnected, pdwHighDateTimeConnected );
423 return E_NOTIMPL;
426 static HRESULT WINAPI network_get_IsConnectedToInternet(
427 INetwork *iface,
428 VARIANT_BOOL *pbIsConnected )
430 struct network *network = impl_from_INetwork( iface );
432 TRACE( "%p, %p\n", iface, pbIsConnected );
434 *pbIsConnected = network->connected_to_internet;
435 return S_OK;
438 static HRESULT WINAPI network_get_IsConnected(
439 INetwork *iface,
440 VARIANT_BOOL *pbIsConnected )
442 struct network *network = impl_from_INetwork( iface );
444 TRACE( "%p, %p\n", iface, pbIsConnected );
446 *pbIsConnected = network->connected;
447 return S_OK;
450 static HRESULT WINAPI network_GetConnectivity(
451 INetwork *iface,
452 NLM_CONNECTIVITY *pConnectivity )
454 FIXME( "%p, %p\n", iface, pConnectivity );
456 *pConnectivity = NLM_CONNECTIVITY_IPV4_INTERNET;
457 return S_OK;
460 static HRESULT WINAPI network_GetCategory(
461 INetwork *iface,
462 NLM_NETWORK_CATEGORY *pCategory )
464 FIXME( "%p, %p\n", iface, pCategory );
466 *pCategory = NLM_NETWORK_CATEGORY_PUBLIC;
467 return S_OK;
470 static HRESULT WINAPI network_SetCategory(
471 INetwork *iface,
472 NLM_NETWORK_CATEGORY NewCategory )
474 FIXME( "%p, %u\n", iface, NewCategory );
475 return E_NOTIMPL;
478 static const struct INetworkVtbl network_vtbl =
480 network_QueryInterface,
481 network_AddRef,
482 network_Release,
483 network_GetTypeInfoCount,
484 network_GetTypeInfo,
485 network_GetIDsOfNames,
486 network_Invoke,
487 network_GetName,
488 network_SetName,
489 network_GetDescription,
490 network_SetDescription,
491 network_GetNetworkId,
492 network_GetDomainType,
493 network_GetNetworkConnections,
494 network_GetTimeCreatedAndConnected,
495 network_get_IsConnectedToInternet,
496 network_get_IsConnected,
497 network_GetConnectivity,
498 network_GetCategory,
499 network_SetCategory
502 static struct network *create_network( const GUID *id )
504 struct network *ret;
506 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
508 ret->INetwork_iface.lpVtbl = &network_vtbl;
509 ret->refs = 1;
510 ret->id = *id;
511 ret->connected = VARIANT_FALSE;
512 ret->connected_to_internet = VARIANT_FALSE;
513 list_init( &ret->entry );
515 return ret;
518 static HRESULT WINAPI cost_manager_QueryInterface(
519 INetworkCostManager *iface,
520 REFIID riid,
521 void **obj )
523 struct list_manager *mgr = impl_from_INetworkCostManager( iface );
524 return INetworkListManager_QueryInterface( &mgr->INetworkListManager_iface, riid, obj );
527 static ULONG WINAPI cost_manager_AddRef(
528 INetworkCostManager *iface )
530 struct list_manager *mgr = impl_from_INetworkCostManager( iface );
531 return INetworkListManager_AddRef( &mgr->INetworkListManager_iface );
534 static ULONG WINAPI cost_manager_Release(
535 INetworkCostManager *iface )
537 struct list_manager *mgr = impl_from_INetworkCostManager( iface );
538 return INetworkListManager_Release( &mgr->INetworkListManager_iface );
541 static HRESULT WINAPI cost_manager_GetCost(
542 INetworkCostManager *iface, DWORD *pCost, NLM_SOCKADDR *pDestIPAddr)
544 FIXME( "%p, %p, %p\n", iface, pCost, pDestIPAddr );
546 if (!pCost) return E_POINTER;
548 *pCost = NLM_CONNECTION_COST_UNRESTRICTED;
549 return S_OK;
552 static BOOL map_address_6to4( const SOCKADDR_IN6 *addr6, SOCKADDR_IN *addr4 )
554 ULONG i;
556 if (addr6->sin6_family != WS_AF_INET6) return FALSE;
558 for (i = 0; i < 5; i++)
559 if (addr6->sin6_addr.u.Word[i]) return FALSE;
561 if (addr6->sin6_addr.u.Word[5] != 0xffff) return FALSE;
563 addr4->sin_family = WS_AF_INET;
564 addr4->sin_port = addr6->sin6_port;
565 addr4->sin_addr.S_un.S_addr = addr6->sin6_addr.u.Word[6] << 16 | addr6->sin6_addr.u.Word[7];
566 memset( &addr4->sin_zero, 0, sizeof(addr4->sin_zero) );
568 return TRUE;
571 static HRESULT WINAPI cost_manager_GetDataPlanStatus(
572 INetworkCostManager *iface, NLM_DATAPLAN_STATUS *pDataPlanStatus,
573 NLM_SOCKADDR *pDestIPAddr)
575 DWORD ret, index;
576 NET_LUID luid;
577 SOCKADDR *dst = (SOCKADDR *)pDestIPAddr;
578 SOCKADDR_IN addr4, *dst4;
580 FIXME( "%p, %p, %p\n", iface, pDataPlanStatus, pDestIPAddr );
582 if (!pDataPlanStatus) return E_POINTER;
584 if (dst && ((dst->sa_family == WS_AF_INET && (dst4 = (SOCKADDR_IN *)dst)) ||
585 ((dst->sa_family == WS_AF_INET6 && map_address_6to4( (const SOCKADDR_IN6 *)dst, &addr4 )
586 && (dst4 = &addr4)))))
588 if ((ret = GetBestInterface( dst4->sin_addr.S_un.S_addr, &index )))
589 return HRESULT_FROM_WIN32( ret );
591 if ((ret = ConvertInterfaceIndexToLuid( index, &luid )))
592 return HRESULT_FROM_WIN32( ret );
594 if ((ret = ConvertInterfaceLuidToGuid( &luid, &pDataPlanStatus->InterfaceGuid )))
595 return HRESULT_FROM_WIN32( ret );
597 else
599 FIXME( "interface guid not found\n" );
600 memset( &pDataPlanStatus->InterfaceGuid, 0, sizeof(pDataPlanStatus->InterfaceGuid) );
603 pDataPlanStatus->UsageData.UsageInMegabytes = NLM_UNKNOWN_DATAPLAN_STATUS;
604 memset( &pDataPlanStatus->UsageData.LastSyncTime, 0, sizeof(pDataPlanStatus->UsageData.LastSyncTime) );
605 pDataPlanStatus->DataLimitInMegabytes = NLM_UNKNOWN_DATAPLAN_STATUS;
606 pDataPlanStatus->InboundBandwidthInKbps = NLM_UNKNOWN_DATAPLAN_STATUS;
607 pDataPlanStatus->OutboundBandwidthInKbps = NLM_UNKNOWN_DATAPLAN_STATUS;
608 memset( &pDataPlanStatus->NextBillingCycle, 0, sizeof(pDataPlanStatus->NextBillingCycle) );
609 pDataPlanStatus->MaxTransferSizeInMegabytes = NLM_UNKNOWN_DATAPLAN_STATUS;
610 pDataPlanStatus->Reserved = 0;
612 return S_OK;
615 static HRESULT WINAPI cost_manager_SetDestinationAddresses(
616 INetworkCostManager *iface, UINT32 length, NLM_SOCKADDR *pDestIPAddrList,
617 VARIANT_BOOL bAppend)
619 FIXME( "%p, %u, %p, %x\n", iface, length, pDestIPAddrList, bAppend );
620 return E_NOTIMPL;
623 static const INetworkCostManagerVtbl cost_manager_vtbl =
625 cost_manager_QueryInterface,
626 cost_manager_AddRef,
627 cost_manager_Release,
628 cost_manager_GetCost,
629 cost_manager_GetDataPlanStatus,
630 cost_manager_SetDestinationAddresses
633 struct networks_enum
635 IEnumNetworks IEnumNetworks_iface;
636 LONG refs;
637 struct list_manager *mgr;
638 struct list *cursor;
641 static inline struct networks_enum *impl_from_IEnumNetworks(
642 IEnumNetworks *iface )
644 return CONTAINING_RECORD( iface, struct networks_enum, IEnumNetworks_iface );
647 static HRESULT WINAPI networks_enum_QueryInterface(
648 IEnumNetworks *iface, REFIID riid, void **obj )
650 struct networks_enum *iter = impl_from_IEnumNetworks( iface );
652 TRACE( "%p, %s, %p\n", iter, debugstr_guid(riid), obj );
654 if (IsEqualIID( riid, &IID_IEnumNetworks ) ||
655 IsEqualIID( riid, &IID_IDispatch ) ||
656 IsEqualIID( riid, &IID_IUnknown ))
658 *obj = iface;
659 IEnumNetworks_AddRef( iface );
660 return S_OK;
662 else
664 WARN( "interface not supported %s\n", debugstr_guid(riid) );
665 *obj = NULL;
666 return E_NOINTERFACE;
670 static ULONG WINAPI networks_enum_AddRef(
671 IEnumNetworks *iface )
673 struct networks_enum *iter = impl_from_IEnumNetworks( iface );
675 TRACE( "%p\n", iter );
676 return InterlockedIncrement( &iter->refs );
679 static ULONG WINAPI networks_enum_Release(
680 IEnumNetworks *iface )
682 struct networks_enum *iter = impl_from_IEnumNetworks( iface );
683 LONG refs;
685 TRACE( "%p\n", iter );
687 if (!(refs = InterlockedDecrement( &iter->refs )))
689 INetworkListManager_Release( &iter->mgr->INetworkListManager_iface );
690 heap_free( iter );
692 return refs;
695 static HRESULT WINAPI networks_enum_GetTypeInfoCount(
696 IEnumNetworks *iface,
697 UINT *count )
699 FIXME("\n");
700 return E_NOTIMPL;
703 static HRESULT WINAPI networks_enum_GetTypeInfo(
704 IEnumNetworks *iface,
705 UINT index,
706 LCID lcid,
707 ITypeInfo **info )
709 FIXME("\n");
710 return E_NOTIMPL;
713 static HRESULT WINAPI networks_enum_GetIDsOfNames(
714 IEnumNetworks *iface,
715 REFIID riid,
716 LPOLESTR *names,
717 UINT count,
718 LCID lcid,
719 DISPID *dispid )
721 FIXME("\n");
722 return E_NOTIMPL;
725 static HRESULT WINAPI networks_enum_Invoke(
726 IEnumNetworks *iface,
727 DISPID member,
728 REFIID riid,
729 LCID lcid,
730 WORD flags,
731 DISPPARAMS *params,
732 VARIANT *result,
733 EXCEPINFO *excep_info,
734 UINT *arg_err )
736 FIXME("\n");
737 return E_NOTIMPL;
740 static HRESULT WINAPI networks_enum_get__NewEnum(
741 IEnumNetworks *iface, IEnumVARIANT **ppEnumVar )
743 FIXME("\n");
744 return E_NOTIMPL;
747 static HRESULT WINAPI networks_enum_Next(
748 IEnumNetworks *iface, ULONG count, INetwork **ret, ULONG *fetched )
750 struct networks_enum *iter = impl_from_IEnumNetworks( iface );
751 ULONG i = 0;
753 TRACE( "%p, %u %p %p\n", iter, count, ret, fetched );
755 if (fetched) *fetched = 0;
756 if (!count) return S_OK;
758 while (iter->cursor && i < count)
760 struct network *network = LIST_ENTRY( iter->cursor, struct network, entry );
761 ret[i] = &network->INetwork_iface;
762 INetwork_AddRef( ret[i] );
763 iter->cursor = list_next( &iter->mgr->networks, iter->cursor );
764 i++;
766 if (fetched) *fetched = i;
768 return i < count ? S_FALSE : S_OK;
771 static HRESULT WINAPI networks_enum_Skip(
772 IEnumNetworks *iface, ULONG count )
774 struct networks_enum *iter = impl_from_IEnumNetworks( iface );
776 TRACE( "%p, %u\n", iter, count);
778 if (!count) return S_OK;
779 if (!iter->cursor) return S_FALSE;
781 while (count--)
783 iter->cursor = list_next( &iter->mgr->networks, iter->cursor );
784 if (!iter->cursor) break;
787 return count ? S_FALSE : S_OK;
790 static HRESULT WINAPI networks_enum_Reset(
791 IEnumNetworks *iface )
793 struct networks_enum *iter = impl_from_IEnumNetworks( iface );
795 TRACE( "%p\n", iter );
797 iter->cursor = list_head( &iter->mgr->networks );
798 return S_OK;
801 static HRESULT create_networks_enum(
802 struct list_manager *, IEnumNetworks** );
804 static HRESULT WINAPI networks_enum_Clone(
805 IEnumNetworks *iface, IEnumNetworks **ret )
807 struct networks_enum *iter = impl_from_IEnumNetworks( iface );
809 TRACE( "%p, %p\n", iter, ret );
810 return create_networks_enum( iter->mgr, ret );
813 static const IEnumNetworksVtbl networks_enum_vtbl =
815 networks_enum_QueryInterface,
816 networks_enum_AddRef,
817 networks_enum_Release,
818 networks_enum_GetTypeInfoCount,
819 networks_enum_GetTypeInfo,
820 networks_enum_GetIDsOfNames,
821 networks_enum_Invoke,
822 networks_enum_get__NewEnum,
823 networks_enum_Next,
824 networks_enum_Skip,
825 networks_enum_Reset,
826 networks_enum_Clone
829 static HRESULT create_networks_enum(
830 struct list_manager *mgr, IEnumNetworks **ret )
832 struct networks_enum *iter;
834 *ret = NULL;
835 if (!(iter = heap_alloc( sizeof(*iter) ))) return E_OUTOFMEMORY;
837 iter->IEnumNetworks_iface.lpVtbl = &networks_enum_vtbl;
838 iter->cursor = list_head( &mgr->networks );
839 iter->mgr = mgr;
840 INetworkListManager_AddRef( &mgr->INetworkListManager_iface );
841 iter->refs = 1;
843 *ret = &iter->IEnumNetworks_iface;
844 return S_OK;
847 static inline struct list_manager *impl_from_INetworkListManager(
848 INetworkListManager *iface )
850 return CONTAINING_RECORD( iface, struct list_manager, INetworkListManager_iface );
853 struct connections_enum
855 IEnumNetworkConnections IEnumNetworkConnections_iface;
856 LONG refs;
857 struct list_manager *mgr;
858 struct list *cursor;
861 static inline struct connections_enum *impl_from_IEnumNetworkConnections(
862 IEnumNetworkConnections *iface )
864 return CONTAINING_RECORD( iface, struct connections_enum, IEnumNetworkConnections_iface );
867 static HRESULT WINAPI connections_enum_QueryInterface(
868 IEnumNetworkConnections *iface, REFIID riid, void **obj )
870 struct connections_enum *iter = impl_from_IEnumNetworkConnections( iface );
872 TRACE( "%p, %s, %p\n", iter, debugstr_guid(riid), obj );
874 if (IsEqualIID( riid, &IID_IEnumNetworkConnections ) ||
875 IsEqualIID( riid, &IID_IDispatch ) ||
876 IsEqualIID( riid, &IID_IUnknown ))
878 *obj = iface;
879 IEnumNetworkConnections_AddRef( iface );
880 return S_OK;
882 else
884 WARN( "interface not supported %s\n", debugstr_guid(riid) );
885 *obj = NULL;
886 return E_NOINTERFACE;
890 static ULONG WINAPI connections_enum_AddRef(
891 IEnumNetworkConnections *iface )
893 struct connections_enum *iter = impl_from_IEnumNetworkConnections( iface );
895 TRACE( "%p\n", iter );
896 return InterlockedIncrement( &iter->refs );
899 static ULONG WINAPI connections_enum_Release(
900 IEnumNetworkConnections *iface )
902 struct connections_enum *iter = impl_from_IEnumNetworkConnections( iface );
903 LONG refs;
905 TRACE( "%p\n", iter );
907 if (!(refs = InterlockedDecrement( &iter->refs )))
909 INetworkListManager_Release( &iter->mgr->INetworkListManager_iface );
910 heap_free( iter );
912 return refs;
915 static HRESULT WINAPI connections_enum_GetTypeInfoCount(
916 IEnumNetworkConnections *iface,
917 UINT *count )
919 FIXME("\n");
920 return E_NOTIMPL;
923 static HRESULT WINAPI connections_enum_GetTypeInfo(
924 IEnumNetworkConnections *iface,
925 UINT index,
926 LCID lcid,
927 ITypeInfo **info )
929 FIXME("\n");
930 return E_NOTIMPL;
933 static HRESULT WINAPI connections_enum_GetIDsOfNames(
934 IEnumNetworkConnections *iface,
935 REFIID riid,
936 LPOLESTR *names,
937 UINT count,
938 LCID lcid,
939 DISPID *dispid )
941 FIXME("\n");
942 return E_NOTIMPL;
945 static HRESULT WINAPI connections_enum_Invoke(
946 IEnumNetworkConnections *iface,
947 DISPID member,
948 REFIID riid,
949 LCID lcid,
950 WORD flags,
951 DISPPARAMS *params,
952 VARIANT *result,
953 EXCEPINFO *excep_info,
954 UINT *arg_err )
956 FIXME("\n");
957 return E_NOTIMPL;
960 static HRESULT WINAPI connections_enum_get__NewEnum(
961 IEnumNetworkConnections *iface, IEnumVARIANT **ppEnumVar )
963 FIXME("\n");
964 return E_NOTIMPL;
967 static HRESULT WINAPI connections_enum_Next(
968 IEnumNetworkConnections *iface, ULONG count, INetworkConnection **ret, ULONG *fetched )
970 struct connections_enum *iter = impl_from_IEnumNetworkConnections( iface );
971 ULONG i = 0;
973 TRACE( "%p, %u %p %p\n", iter, count, ret, fetched );
975 if (fetched) *fetched = 0;
976 if (!count) return S_OK;
978 while (iter->cursor && i < count)
980 struct connection *connection = LIST_ENTRY( iter->cursor, struct connection, entry );
981 ret[i] = &connection->INetworkConnection_iface;
982 INetworkConnection_AddRef( ret[i] );
983 iter->cursor = list_next( &iter->mgr->connections, iter->cursor );
984 i++;
986 if (fetched) *fetched = i;
988 return i < count ? S_FALSE : S_OK;
991 static HRESULT WINAPI connections_enum_Skip(
992 IEnumNetworkConnections *iface, ULONG count )
994 struct connections_enum *iter = impl_from_IEnumNetworkConnections( iface );
996 TRACE( "%p, %u\n", iter, count);
998 if (!count) return S_OK;
999 if (!iter->cursor) return S_FALSE;
1001 while (count--)
1003 iter->cursor = list_next( &iter->mgr->connections, iter->cursor );
1004 if (!iter->cursor) break;
1007 return count ? S_FALSE : S_OK;
1010 static HRESULT WINAPI connections_enum_Reset(
1011 IEnumNetworkConnections *iface )
1013 struct connections_enum *iter = impl_from_IEnumNetworkConnections( iface );
1015 TRACE( "%p\n", iter );
1017 iter->cursor = list_head( &iter->mgr->connections );
1018 return S_OK;
1021 static HRESULT create_connections_enum(
1022 struct list_manager *, IEnumNetworkConnections** );
1024 static HRESULT WINAPI connections_enum_Clone(
1025 IEnumNetworkConnections *iface, IEnumNetworkConnections **ret )
1027 struct connections_enum *iter = impl_from_IEnumNetworkConnections( iface );
1029 TRACE( "%p, %p\n", iter, ret );
1030 return create_connections_enum( iter->mgr, ret );
1033 static const IEnumNetworkConnectionsVtbl connections_enum_vtbl =
1035 connections_enum_QueryInterface,
1036 connections_enum_AddRef,
1037 connections_enum_Release,
1038 connections_enum_GetTypeInfoCount,
1039 connections_enum_GetTypeInfo,
1040 connections_enum_GetIDsOfNames,
1041 connections_enum_Invoke,
1042 connections_enum_get__NewEnum,
1043 connections_enum_Next,
1044 connections_enum_Skip,
1045 connections_enum_Reset,
1046 connections_enum_Clone
1049 static HRESULT create_connections_enum(
1050 struct list_manager *mgr, IEnumNetworkConnections **ret )
1052 struct connections_enum *iter;
1054 *ret = NULL;
1055 if (!(iter = heap_alloc( sizeof(*iter) ))) return E_OUTOFMEMORY;
1057 iter->IEnumNetworkConnections_iface.lpVtbl = &connections_enum_vtbl;
1058 iter->mgr = mgr;
1059 INetworkListManager_AddRef( &mgr->INetworkListManager_iface );
1060 iter->cursor = list_head( &iter->mgr->connections );
1061 iter->refs = 1;
1063 *ret = &iter->IEnumNetworkConnections_iface;
1064 return S_OK;
1067 static ULONG WINAPI list_manager_AddRef(
1068 INetworkListManager *iface )
1070 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1071 return InterlockedIncrement( &mgr->refs );
1074 static ULONG WINAPI list_manager_Release(
1075 INetworkListManager *iface )
1077 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1078 LONG refs = InterlockedDecrement( &mgr->refs );
1079 if (!refs)
1081 struct list *ptr;
1083 TRACE( "destroying %p\n", mgr );
1085 while ((ptr = list_head( &mgr->networks )))
1087 struct network *network = LIST_ENTRY( ptr, struct network, entry );
1088 list_remove( &network->entry );
1089 INetwork_Release( &network->INetwork_iface );
1091 while ((ptr = list_head( &mgr->connections )))
1093 struct connection *connection = LIST_ENTRY( ptr, struct connection, entry );
1094 list_remove( &connection->entry );
1095 INetworkConnection_Release( &connection->INetworkConnection_iface );
1097 heap_free( mgr );
1099 return refs;
1102 static HRESULT WINAPI list_manager_QueryInterface(
1103 INetworkListManager *iface,
1104 REFIID riid,
1105 void **obj )
1107 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1109 TRACE( "%p, %s, %p\n", mgr, debugstr_guid(riid), obj );
1111 if (IsEqualGUID( riid, &IID_INetworkListManager ) ||
1112 IsEqualGUID( riid, &IID_IDispatch ) ||
1113 IsEqualGUID( riid, &IID_IUnknown ))
1115 *obj = iface;
1117 else if (IsEqualGUID( riid, &IID_INetworkCostManager ))
1119 *obj = &mgr->INetworkCostManager_iface;
1121 else if (IsEqualGUID( riid, &IID_IConnectionPointContainer ))
1123 *obj = &mgr->IConnectionPointContainer_iface;
1125 else
1127 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
1128 *obj = NULL;
1129 return E_NOINTERFACE;
1131 INetworkListManager_AddRef( iface );
1132 return S_OK;
1135 static HRESULT WINAPI list_manager_GetTypeInfoCount(
1136 INetworkListManager *iface,
1137 UINT *count )
1139 FIXME("\n");
1140 return E_NOTIMPL;
1143 static HRESULT WINAPI list_manager_GetTypeInfo(
1144 INetworkListManager *iface,
1145 UINT index,
1146 LCID lcid,
1147 ITypeInfo **info )
1149 FIXME("\n");
1150 return E_NOTIMPL;
1153 static HRESULT WINAPI list_manager_GetIDsOfNames(
1154 INetworkListManager *iface,
1155 REFIID riid,
1156 LPOLESTR *names,
1157 UINT count,
1158 LCID lcid,
1159 DISPID *dispid )
1161 FIXME("\n");
1162 return E_NOTIMPL;
1165 static HRESULT WINAPI list_manager_Invoke(
1166 INetworkListManager *iface,
1167 DISPID member,
1168 REFIID riid,
1169 LCID lcid,
1170 WORD flags,
1171 DISPPARAMS *params,
1172 VARIANT *result,
1173 EXCEPINFO *excep_info,
1174 UINT *arg_err )
1176 FIXME("\n");
1177 return E_NOTIMPL;
1180 static HRESULT WINAPI list_manager_GetNetworks(
1181 INetworkListManager *iface,
1182 NLM_ENUM_NETWORK Flags,
1183 IEnumNetworks **ppEnumNetwork )
1185 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1187 TRACE( "%p, %x, %p\n", iface, Flags, ppEnumNetwork );
1188 if (Flags) FIXME( "flags %08x not supported\n", Flags );
1190 return create_networks_enum( mgr, ppEnumNetwork );
1193 static HRESULT WINAPI list_manager_GetNetwork(
1194 INetworkListManager *iface,
1195 GUID gdNetworkId,
1196 INetwork **ppNetwork )
1198 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1199 struct network *network;
1201 TRACE( "%p, %s, %p\n", iface, debugstr_guid(&gdNetworkId), ppNetwork );
1203 LIST_FOR_EACH_ENTRY( network, &mgr->networks, struct network, entry )
1205 if (IsEqualGUID( &network->id, &gdNetworkId ))
1207 *ppNetwork = &network->INetwork_iface;
1208 INetwork_AddRef( *ppNetwork );
1209 return S_OK;
1213 return S_FALSE;
1216 static HRESULT WINAPI list_manager_GetNetworkConnections(
1217 INetworkListManager *iface,
1218 IEnumNetworkConnections **ppEnum )
1220 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1222 TRACE( "%p, %p\n", iface, ppEnum );
1223 return create_connections_enum( mgr, ppEnum );
1226 static HRESULT WINAPI list_manager_GetNetworkConnection(
1227 INetworkListManager *iface,
1228 GUID gdNetworkConnectionId,
1229 INetworkConnection **ppNetworkConnection )
1231 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1232 struct connection *connection;
1234 TRACE( "%p, %s, %p\n", iface, debugstr_guid(&gdNetworkConnectionId),
1235 ppNetworkConnection );
1237 LIST_FOR_EACH_ENTRY( connection, &mgr->connections, struct connection, entry )
1239 if (IsEqualGUID( &connection->id, &gdNetworkConnectionId ))
1241 *ppNetworkConnection = &connection->INetworkConnection_iface;
1242 INetworkConnection_AddRef( *ppNetworkConnection );
1243 return S_OK;
1247 return S_FALSE;
1250 static HRESULT WINAPI list_manager_IsConnectedToInternet(
1251 INetworkListManager *iface,
1252 VARIANT_BOOL *pbIsConnected )
1254 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1255 struct network *network;
1257 TRACE( "%p, %p\n", iface, pbIsConnected );
1259 LIST_FOR_EACH_ENTRY( network, &mgr->networks, struct network, entry )
1261 if (network->connected_to_internet)
1263 *pbIsConnected = VARIANT_TRUE;
1264 return S_OK;
1268 *pbIsConnected = VARIANT_FALSE;
1269 return S_OK;
1272 static HRESULT WINAPI list_manager_IsConnected(
1273 INetworkListManager *iface,
1274 VARIANT_BOOL *pbIsConnected )
1276 struct list_manager *mgr = impl_from_INetworkListManager( iface );
1277 struct network *network;
1279 TRACE( "%p, %p\n", iface, pbIsConnected );
1281 LIST_FOR_EACH_ENTRY( network, &mgr->networks, struct network, entry )
1283 if (network->connected)
1285 *pbIsConnected = VARIANT_TRUE;
1286 return S_OK;
1290 *pbIsConnected = VARIANT_FALSE;
1291 return S_OK;
1294 static HRESULT WINAPI list_manager_GetConnectivity(
1295 INetworkListManager *iface,
1296 NLM_CONNECTIVITY *pConnectivity )
1298 FIXME( "%p, %p\n", iface, pConnectivity );
1300 *pConnectivity = NLM_CONNECTIVITY_IPV4_INTERNET;
1301 return S_OK;
1304 static const INetworkListManagerVtbl list_manager_vtbl =
1306 list_manager_QueryInterface,
1307 list_manager_AddRef,
1308 list_manager_Release,
1309 list_manager_GetTypeInfoCount,
1310 list_manager_GetTypeInfo,
1311 list_manager_GetIDsOfNames,
1312 list_manager_Invoke,
1313 list_manager_GetNetworks,
1314 list_manager_GetNetwork,
1315 list_manager_GetNetworkConnections,
1316 list_manager_GetNetworkConnection,
1317 list_manager_IsConnectedToInternet,
1318 list_manager_IsConnected,
1319 list_manager_GetConnectivity
1322 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
1323 REFIID riid, void **ppv)
1325 struct list_manager *This = impl_from_IConnectionPointContainer( iface );
1326 return INetworkListManager_QueryInterface(&This->INetworkListManager_iface, riid, ppv);
1329 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
1331 struct list_manager *This = impl_from_IConnectionPointContainer( iface );
1332 return INetworkListManager_AddRef(&This->INetworkListManager_iface);
1335 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
1337 struct list_manager *This = impl_from_IConnectionPointContainer( iface );
1338 return INetworkListManager_Release(&This->INetworkListManager_iface);
1341 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
1342 IEnumConnectionPoints **ppEnum)
1344 struct list_manager *This = impl_from_IConnectionPointContainer( iface );
1345 FIXME("(%p)->(%p): stub\n", This, ppEnum);
1346 return E_NOTIMPL;
1349 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
1350 REFIID riid, IConnectionPoint **cp)
1352 struct list_manager *This = impl_from_IConnectionPointContainer( iface );
1354 TRACE( "%p, %s, %p\n", This, debugstr_guid(riid), cp );
1356 if (!riid || !cp)
1357 return E_POINTER;
1359 if (IsEqualGUID( riid, &IID_INetworkListManagerEvents ) ||
1360 IsEqualGUID( riid, &IID_INetworkCostManagerEvents ) ||
1361 IsEqualGUID( riid, &IID_INetworkConnectionEvents ))
1362 return connection_point_create( cp, riid, iface );
1364 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
1366 *cp = NULL;
1367 return E_NOINTERFACE;
1370 static const struct IConnectionPointContainerVtbl cpc_vtbl =
1372 ConnectionPointContainer_QueryInterface,
1373 ConnectionPointContainer_AddRef,
1374 ConnectionPointContainer_Release,
1375 ConnectionPointContainer_EnumConnectionPoints,
1376 ConnectionPointContainer_FindConnectionPoint
1379 static inline struct connection *impl_from_INetworkConnection(
1380 INetworkConnection *iface )
1382 return CONTAINING_RECORD( iface, struct connection, INetworkConnection_iface );
1385 static HRESULT WINAPI connection_QueryInterface(
1386 INetworkConnection *iface, REFIID riid, void **obj )
1388 struct connection *connection = impl_from_INetworkConnection( iface );
1390 TRACE( "%p, %s, %p\n", connection, debugstr_guid(riid), obj );
1392 if (IsEqualIID( riid, &IID_INetworkConnection ) ||
1393 IsEqualIID( riid, &IID_IDispatch ) ||
1394 IsEqualIID( riid, &IID_IUnknown ))
1396 *obj = iface;
1398 else if (IsEqualIID( riid, &IID_INetworkConnectionCost ))
1400 *obj = &connection->INetworkConnectionCost_iface;
1402 else
1404 WARN( "interface not supported %s\n", debugstr_guid(riid) );
1405 *obj = NULL;
1406 return E_NOINTERFACE;
1408 INetworkConnection_AddRef( iface );
1409 return S_OK;
1412 static ULONG WINAPI connection_AddRef(
1413 INetworkConnection *iface )
1415 struct connection *connection = impl_from_INetworkConnection( iface );
1417 TRACE( "%p\n", connection );
1418 return InterlockedIncrement( &connection->refs );
1421 static ULONG WINAPI connection_Release(
1422 INetworkConnection *iface )
1424 struct connection *connection = impl_from_INetworkConnection( iface );
1425 LONG refs;
1427 TRACE( "%p\n", connection );
1429 if (!(refs = InterlockedDecrement( &connection->refs )))
1431 INetwork_Release( connection->network );
1432 list_remove( &connection->entry );
1433 heap_free( connection );
1435 return refs;
1438 static HRESULT WINAPI connection_GetTypeInfoCount(
1439 INetworkConnection *iface,
1440 UINT *count )
1442 FIXME("\n");
1443 return E_NOTIMPL;
1446 static HRESULT WINAPI connection_GetTypeInfo(
1447 INetworkConnection *iface,
1448 UINT index,
1449 LCID lcid,
1450 ITypeInfo **info )
1452 FIXME("\n");
1453 return E_NOTIMPL;
1456 static HRESULT WINAPI connection_GetIDsOfNames(
1457 INetworkConnection *iface,
1458 REFIID riid,
1459 LPOLESTR *names,
1460 UINT count,
1461 LCID lcid,
1462 DISPID *dispid )
1464 FIXME("\n");
1465 return E_NOTIMPL;
1468 static HRESULT WINAPI connection_Invoke(
1469 INetworkConnection *iface,
1470 DISPID member,
1471 REFIID riid,
1472 LCID lcid,
1473 WORD flags,
1474 DISPPARAMS *params,
1475 VARIANT *result,
1476 EXCEPINFO *excep_info,
1477 UINT *arg_err )
1479 FIXME("\n");
1480 return E_NOTIMPL;
1483 static HRESULT WINAPI connection_GetNetwork(
1484 INetworkConnection *iface,
1485 INetwork **ppNetwork )
1487 struct connection *connection = impl_from_INetworkConnection( iface );
1489 TRACE( "%p, %p\n", iface, ppNetwork );
1491 *ppNetwork = connection->network;
1492 INetwork_AddRef( *ppNetwork );
1493 return S_OK;
1496 static HRESULT WINAPI connection_get_IsConnectedToInternet(
1497 INetworkConnection *iface,
1498 VARIANT_BOOL *pbIsConnected )
1500 struct connection *connection = impl_from_INetworkConnection( iface );
1502 TRACE( "%p, %p\n", iface, pbIsConnected );
1504 *pbIsConnected = connection->connected_to_internet;
1505 return S_OK;
1508 static HRESULT WINAPI connection_get_IsConnected(
1509 INetworkConnection *iface,
1510 VARIANT_BOOL *pbIsConnected )
1512 struct connection *connection = impl_from_INetworkConnection( iface );
1514 TRACE( "%p, %p\n", iface, pbIsConnected );
1516 *pbIsConnected = connection->connected;
1517 return S_OK;
1520 static HRESULT WINAPI connection_GetConnectivity(
1521 INetworkConnection *iface,
1522 NLM_CONNECTIVITY *pConnectivity )
1524 FIXME( "%p, %p\n", iface, pConnectivity );
1526 *pConnectivity = NLM_CONNECTIVITY_IPV4_INTERNET;
1527 return S_OK;
1530 static HRESULT WINAPI connection_GetConnectionId(
1531 INetworkConnection *iface,
1532 GUID *pgdConnectionId )
1534 struct connection *connection = impl_from_INetworkConnection( iface );
1536 TRACE( "%p, %p\n", iface, pgdConnectionId );
1538 *pgdConnectionId = connection->id;
1539 return S_OK;
1542 static HRESULT WINAPI connection_GetAdapterId(
1543 INetworkConnection *iface,
1544 GUID *pgdAdapterId )
1546 struct connection *connection = impl_from_INetworkConnection( iface );
1548 FIXME( "%p, %p\n", iface, pgdAdapterId );
1550 *pgdAdapterId = connection->id;
1551 return S_OK;
1554 static HRESULT WINAPI connection_GetDomainType(
1555 INetworkConnection *iface,
1556 NLM_DOMAIN_TYPE *pDomainType )
1558 FIXME( "%p, %p\n", iface, pDomainType );
1560 *pDomainType = NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK;
1561 return S_OK;
1564 static const struct INetworkConnectionVtbl connection_vtbl =
1566 connection_QueryInterface,
1567 connection_AddRef,
1568 connection_Release,
1569 connection_GetTypeInfoCount,
1570 connection_GetTypeInfo,
1571 connection_GetIDsOfNames,
1572 connection_Invoke,
1573 connection_GetNetwork,
1574 connection_get_IsConnectedToInternet,
1575 connection_get_IsConnected,
1576 connection_GetConnectivity,
1577 connection_GetConnectionId,
1578 connection_GetAdapterId,
1579 connection_GetDomainType
1582 static inline struct connection *impl_from_INetworkConnectionCost(
1583 INetworkConnectionCost *iface )
1585 return CONTAINING_RECORD( iface, struct connection, INetworkConnectionCost_iface );
1588 static HRESULT WINAPI connection_cost_QueryInterface(
1589 INetworkConnectionCost *iface,
1590 REFIID riid,
1591 void **obj )
1593 struct connection *conn = impl_from_INetworkConnectionCost( iface );
1594 return INetworkConnection_QueryInterface( &conn->INetworkConnection_iface, riid, obj );
1597 static ULONG WINAPI connection_cost_AddRef(
1598 INetworkConnectionCost *iface )
1600 struct connection *conn = impl_from_INetworkConnectionCost( iface );
1601 return INetworkConnection_AddRef( &conn->INetworkConnection_iface );
1604 static ULONG WINAPI connection_cost_Release(
1605 INetworkConnectionCost *iface )
1607 struct connection *conn = impl_from_INetworkConnectionCost( iface );
1608 return INetworkConnection_Release( &conn->INetworkConnection_iface );
1611 static HRESULT WINAPI connection_cost_GetCost(
1612 INetworkConnectionCost *iface, DWORD *pCost )
1614 FIXME( "%p, %p\n", iface, pCost );
1616 if (!pCost) return E_POINTER;
1618 *pCost = NLM_CONNECTION_COST_UNRESTRICTED;
1619 return S_OK;
1622 static HRESULT WINAPI connection_cost_GetDataPlanStatus(
1623 INetworkConnectionCost *iface, NLM_DATAPLAN_STATUS *pDataPlanStatus )
1625 struct connection *conn = impl_from_INetworkConnectionCost( iface );
1627 FIXME( "%p, %p\n", iface, pDataPlanStatus );
1629 if (!pDataPlanStatus) return E_POINTER;
1631 memcpy( &pDataPlanStatus->InterfaceGuid, &conn->id, sizeof(conn->id) );
1632 pDataPlanStatus->UsageData.UsageInMegabytes = NLM_UNKNOWN_DATAPLAN_STATUS;
1633 memset( &pDataPlanStatus->UsageData.LastSyncTime, 0, sizeof(pDataPlanStatus->UsageData.LastSyncTime) );
1634 pDataPlanStatus->DataLimitInMegabytes = NLM_UNKNOWN_DATAPLAN_STATUS;
1635 pDataPlanStatus->InboundBandwidthInKbps = NLM_UNKNOWN_DATAPLAN_STATUS;
1636 pDataPlanStatus->OutboundBandwidthInKbps = NLM_UNKNOWN_DATAPLAN_STATUS;
1637 memset( &pDataPlanStatus->NextBillingCycle, 0, sizeof(pDataPlanStatus->NextBillingCycle) );
1638 pDataPlanStatus->MaxTransferSizeInMegabytes = NLM_UNKNOWN_DATAPLAN_STATUS;
1639 pDataPlanStatus->Reserved = 0;
1641 return S_OK;
1644 static const INetworkConnectionCostVtbl connection_cost_vtbl =
1646 connection_cost_QueryInterface,
1647 connection_cost_AddRef,
1648 connection_cost_Release,
1649 connection_cost_GetCost,
1650 connection_cost_GetDataPlanStatus
1653 static struct connection *create_connection( const GUID *id )
1655 struct connection *ret;
1657 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
1659 ret->INetworkConnection_iface.lpVtbl = &connection_vtbl;
1660 ret->INetworkConnectionCost_iface.lpVtbl = &connection_cost_vtbl;
1661 ret->refs = 1;
1662 ret->id = *id;
1663 ret->network = NULL;
1664 ret->connected = VARIANT_FALSE;
1665 ret->connected_to_internet = VARIANT_FALSE;
1666 list_init( &ret->entry );
1668 return ret;
1671 static void init_networks( struct list_manager *mgr )
1673 DWORD size = 0;
1674 IP_ADAPTER_ADDRESSES *buf, *aa;
1675 GUID id;
1676 ULONG ret, flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
1677 GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_INCLUDE_ALL_GATEWAYS;
1679 list_init( &mgr->networks );
1680 list_init( &mgr->connections );
1682 ret = GetAdaptersAddresses( WS_AF_UNSPEC, flags, NULL, NULL, &size );
1683 if (ret != ERROR_BUFFER_OVERFLOW) return;
1685 if (!(buf = heap_alloc( size ))) return;
1686 if (GetAdaptersAddresses( WS_AF_UNSPEC, flags, NULL, buf, &size ))
1688 heap_free( buf );
1689 return;
1692 memset( &id, 0, sizeof(id) );
1693 for (aa = buf; aa; aa = aa->Next)
1695 struct network *network;
1696 struct connection *connection;
1698 id.Data1 = aa->u.s.IfIndex;
1700 /* assume a one-to-one mapping between networks and connections */
1701 if (!(network = create_network( &id ))) goto done;
1702 if (!(connection = create_connection( &id )))
1704 INetwork_Release( &network->INetwork_iface );
1705 goto done;
1708 if (aa->FirstUnicastAddress)
1710 network->connected = VARIANT_TRUE;
1711 connection->connected = VARIANT_TRUE;
1713 if (aa->FirstGatewayAddress)
1715 network->connected_to_internet = VARIANT_TRUE;
1716 connection->connected_to_internet = VARIANT_TRUE;
1719 connection->network = &network->INetwork_iface;
1720 INetwork_AddRef( connection->network );
1722 list_add_tail( &mgr->networks, &network->entry );
1723 list_add_tail( &mgr->connections, &connection->entry );
1726 done:
1727 heap_free( buf );
1730 HRESULT list_manager_create( void **obj )
1732 struct list_manager *mgr;
1734 TRACE( "%p\n", obj );
1736 if (!(mgr = heap_alloc( sizeof(*mgr) ))) return E_OUTOFMEMORY;
1737 mgr->INetworkListManager_iface.lpVtbl = &list_manager_vtbl;
1738 mgr->INetworkCostManager_iface.lpVtbl = &cost_manager_vtbl;
1739 mgr->IConnectionPointContainer_iface.lpVtbl = &cpc_vtbl;
1740 init_networks( mgr );
1741 mgr->refs = 1;
1743 *obj = &mgr->INetworkListManager_iface;
1744 TRACE( "returning iface %p\n", *obj );
1745 return S_OK;