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
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
37 #include "netlistmgr.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
);
58 INetwork INetwork_iface
;
62 VARIANT_BOOL connected_to_internet
;
63 VARIANT_BOOL connected
;
68 INetworkConnection INetworkConnection_iface
;
69 INetworkConnectionCost INetworkConnectionCost_iface
;
74 VARIANT_BOOL connected_to_internet
;
75 VARIANT_BOOL connected
;
78 struct connection_point
80 IConnectionPoint IConnectionPoint_iface
;
81 IConnectionPointContainer
*container
;
89 INetworkListManager INetworkListManager_iface
;
90 INetworkCostManager INetworkCostManager_iface
;
91 IConnectionPointContainer IConnectionPointContainer_iface
;
94 struct list connections
;
95 struct connection_point list_mgr_cp
;
96 struct connection_point cost_mgr_cp
;
97 struct connection_point conn_mgr_cp
;
107 static inline struct list_manager
*impl_from_IConnectionPointContainer(IConnectionPointContainer
*iface
)
109 return CONTAINING_RECORD(iface
, struct list_manager
, IConnectionPointContainer_iface
);
112 static inline struct list_manager
*impl_from_INetworkCostManager(
113 INetworkCostManager
*iface
)
115 return CONTAINING_RECORD( iface
, struct list_manager
, INetworkCostManager_iface
);
118 static inline struct connection_point
*impl_from_IConnectionPoint(
119 IConnectionPoint
*iface
)
121 return CONTAINING_RECORD( iface
, struct connection_point
, IConnectionPoint_iface
);
124 static HRESULT WINAPI
connection_point_QueryInterface(
125 IConnectionPoint
*iface
,
129 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
130 TRACE( "%p, %s, %p\n", cp
, debugstr_guid(riid
), obj
);
132 if (IsEqualGUID( riid
, &IID_IConnectionPoint
) ||
133 IsEqualGUID( riid
, &IID_IUnknown
))
139 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
141 return E_NOINTERFACE
;
143 IConnectionPoint_AddRef( iface
);
147 static ULONG WINAPI
connection_point_AddRef(
148 IConnectionPoint
*iface
)
150 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
151 return IConnectionPointContainer_AddRef( cp
->container
);
154 static ULONG WINAPI
connection_point_Release(
155 IConnectionPoint
*iface
)
157 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
158 return IConnectionPointContainer_Release( cp
->container
);
161 static HRESULT WINAPI
connection_point_GetConnectionInterface(
162 IConnectionPoint
*iface
,
165 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
166 TRACE( "%p, %p\n", cp
, iid
);
171 memcpy( iid
, &cp
->iid
, sizeof(*iid
) );
175 static HRESULT WINAPI
connection_point_GetConnectionPointContainer(
176 IConnectionPoint
*iface
,
177 IConnectionPointContainer
**container
)
179 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
180 TRACE( "%p, %p\n", cp
, container
);
185 IConnectionPointContainer_AddRef( cp
->container
);
186 *container
= cp
->container
;
190 static HRESULT WINAPI
connection_point_Advise(
191 IConnectionPoint
*iface
,
195 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
196 struct sink_entry
*sink_entry
;
200 FIXME( "%p, %p, %p - semi-stub\n", cp
, sink
, cookie
);
202 if (!sink
|| !cookie
)
205 hr
= IUnknown_QueryInterface( sink
, &cp
->iid
, (void**)&unk
);
208 WARN( "iface %s not implemented by sink\n", debugstr_guid(&cp
->iid
) );
209 return CO_E_FAILEDTOOPENTHREADTOKEN
;
212 sink_entry
= heap_alloc( sizeof(*sink_entry
) );
215 IUnknown_Release( unk
);
216 return E_OUTOFMEMORY
;
219 sink_entry
->unk
= unk
;
220 *cookie
= sink_entry
->cookie
= ++cp
->cookie
;
221 list_add_tail( &cp
->sinks
, &sink_entry
->entry
);
225 static void sink_entry_release( struct sink_entry
*entry
)
227 list_remove( &entry
->entry
);
228 IUnknown_Release( entry
->unk
);
232 static HRESULT WINAPI
connection_point_Unadvise(
233 IConnectionPoint
*iface
,
236 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
237 struct sink_entry
*iter
;
239 TRACE( "%p, %d\n", cp
, cookie
);
241 LIST_FOR_EACH_ENTRY( iter
, &cp
->sinks
, struct sink_entry
, entry
)
243 if (iter
->cookie
!= cookie
) continue;
244 sink_entry_release( iter
);
248 WARN( "invalid cookie\n" );
249 return OLE_E_NOCONNECTION
;
252 static HRESULT WINAPI
connection_point_EnumConnections(
253 IConnectionPoint
*iface
,
254 IEnumConnections
**connections
)
256 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
257 FIXME( "%p, %p - stub\n", cp
, connections
);
262 static const IConnectionPointVtbl connection_point_vtbl
=
264 connection_point_QueryInterface
,
265 connection_point_AddRef
,
266 connection_point_Release
,
267 connection_point_GetConnectionInterface
,
268 connection_point_GetConnectionPointContainer
,
269 connection_point_Advise
,
270 connection_point_Unadvise
,
271 connection_point_EnumConnections
274 static void connection_point_init(
275 struct connection_point
*cp
,
277 IConnectionPointContainer
*container
)
279 cp
->IConnectionPoint_iface
.lpVtbl
= &connection_point_vtbl
;
280 cp
->container
= container
;
283 list_init( &cp
->sinks
);
286 static void connection_point_release( struct connection_point
*cp
)
288 while (!list_empty( &cp
->sinks
))
289 sink_entry_release( LIST_ENTRY( list_head( &cp
->sinks
), struct sink_entry
, entry
) );
292 static inline struct network
*impl_from_INetwork(
295 return CONTAINING_RECORD( iface
, struct network
, INetwork_iface
);
298 static HRESULT WINAPI
network_QueryInterface(
299 INetwork
*iface
, REFIID riid
, void **obj
)
301 struct network
*network
= impl_from_INetwork( iface
);
303 TRACE( "%p, %s, %p\n", network
, debugstr_guid(riid
), obj
);
305 if (IsEqualIID( riid
, &IID_INetwork
) ||
306 IsEqualIID( riid
, &IID_IDispatch
) ||
307 IsEqualIID( riid
, &IID_IUnknown
))
310 INetwork_AddRef( iface
);
315 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
317 return E_NOINTERFACE
;
321 static ULONG WINAPI
network_AddRef(
324 struct network
*network
= impl_from_INetwork( iface
);
326 TRACE( "%p\n", network
);
327 return InterlockedIncrement( &network
->refs
);
330 static ULONG WINAPI
network_Release(
333 struct network
*network
= impl_from_INetwork( iface
);
336 TRACE( "%p\n", network
);
338 if (!(refs
= InterlockedDecrement( &network
->refs
)))
340 list_remove( &network
->entry
);
341 heap_free( network
);
346 static HRESULT WINAPI
network_GetTypeInfoCount(
354 static HRESULT WINAPI
network_GetTypeInfo(
364 static HRESULT WINAPI
network_GetIDsOfNames(
376 static HRESULT WINAPI
network_Invoke(
384 EXCEPINFO
*excep_info
,
391 static HRESULT WINAPI
network_GetName(
393 BSTR
*pszNetworkName
)
395 FIXME( "%p, %p\n", iface
, pszNetworkName
);
399 static HRESULT WINAPI
network_SetName(
401 BSTR szNetworkNewName
)
403 FIXME( "%p, %s\n", iface
, debugstr_w(szNetworkNewName
) );
407 static HRESULT WINAPI
network_GetDescription(
409 BSTR
*pszDescription
)
411 FIXME( "%p, %p\n", iface
, pszDescription
);
415 static HRESULT WINAPI
network_SetDescription(
419 FIXME( "%p, %s\n", iface
, debugstr_w(szDescription
) );
423 static HRESULT WINAPI
network_GetNetworkId(
425 GUID
*pgdGuidNetworkId
)
427 struct network
*network
= impl_from_INetwork( iface
);
429 TRACE( "%p, %p\n", iface
, pgdGuidNetworkId
);
431 *pgdGuidNetworkId
= network
->id
;
435 static HRESULT WINAPI
network_GetDomainType(
437 NLM_DOMAIN_TYPE
*pDomainType
)
439 FIXME( "%p, %p\n", iface
, pDomainType
);
441 *pDomainType
= NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK
;
445 static HRESULT WINAPI
network_GetNetworkConnections(
447 IEnumNetworkConnections
**ppEnumNetworkConnection
)
449 FIXME( "%p, %p\n", iface
, ppEnumNetworkConnection
);
453 static HRESULT WINAPI
network_GetTimeCreatedAndConnected(
455 DWORD
*pdwLowDateTimeCreated
,
456 DWORD
*pdwHighDateTimeCreated
,
457 DWORD
*pdwLowDateTimeConnected
,
458 DWORD
*pdwHighDateTimeConnected
)
460 FIXME( "%p, %p, %p, %p, %p\n", iface
, pdwLowDateTimeCreated
, pdwHighDateTimeCreated
,
461 pdwLowDateTimeConnected
, pdwHighDateTimeConnected
);
465 static HRESULT WINAPI
network_get_IsConnectedToInternet(
467 VARIANT_BOOL
*pbIsConnected
)
469 struct network
*network
= impl_from_INetwork( iface
);
471 TRACE( "%p, %p\n", iface
, pbIsConnected
);
473 *pbIsConnected
= network
->connected_to_internet
;
477 static HRESULT WINAPI
network_get_IsConnected(
479 VARIANT_BOOL
*pbIsConnected
)
481 struct network
*network
= impl_from_INetwork( iface
);
483 TRACE( "%p, %p\n", iface
, pbIsConnected
);
485 *pbIsConnected
= network
->connected
;
489 static HRESULT WINAPI
network_GetConnectivity(
491 NLM_CONNECTIVITY
*pConnectivity
)
493 FIXME( "%p, %p\n", iface
, pConnectivity
);
495 *pConnectivity
= NLM_CONNECTIVITY_IPV4_INTERNET
;
499 static HRESULT WINAPI
network_GetCategory(
501 NLM_NETWORK_CATEGORY
*pCategory
)
503 FIXME( "%p, %p\n", iface
, pCategory
);
505 *pCategory
= NLM_NETWORK_CATEGORY_PUBLIC
;
509 static HRESULT WINAPI
network_SetCategory(
511 NLM_NETWORK_CATEGORY NewCategory
)
513 FIXME( "%p, %u\n", iface
, NewCategory
);
517 static const struct INetworkVtbl network_vtbl
=
519 network_QueryInterface
,
522 network_GetTypeInfoCount
,
524 network_GetIDsOfNames
,
528 network_GetDescription
,
529 network_SetDescription
,
530 network_GetNetworkId
,
531 network_GetDomainType
,
532 network_GetNetworkConnections
,
533 network_GetTimeCreatedAndConnected
,
534 network_get_IsConnectedToInternet
,
535 network_get_IsConnected
,
536 network_GetConnectivity
,
541 static struct network
*create_network( const GUID
*id
)
545 if (!(ret
= heap_alloc( sizeof(*ret
) ))) return NULL
;
547 ret
->INetwork_iface
.lpVtbl
= &network_vtbl
;
550 ret
->connected
= VARIANT_FALSE
;
551 ret
->connected_to_internet
= VARIANT_FALSE
;
552 list_init( &ret
->entry
);
557 static HRESULT WINAPI
cost_manager_QueryInterface(
558 INetworkCostManager
*iface
,
562 struct list_manager
*mgr
= impl_from_INetworkCostManager( iface
);
563 return INetworkListManager_QueryInterface( &mgr
->INetworkListManager_iface
, riid
, obj
);
566 static ULONG WINAPI
cost_manager_AddRef(
567 INetworkCostManager
*iface
)
569 struct list_manager
*mgr
= impl_from_INetworkCostManager( iface
);
570 return INetworkListManager_AddRef( &mgr
->INetworkListManager_iface
);
573 static ULONG WINAPI
cost_manager_Release(
574 INetworkCostManager
*iface
)
576 struct list_manager
*mgr
= impl_from_INetworkCostManager( iface
);
577 return INetworkListManager_Release( &mgr
->INetworkListManager_iface
);
580 static HRESULT WINAPI
cost_manager_GetCost(
581 INetworkCostManager
*iface
, DWORD
*pCost
, NLM_SOCKADDR
*pDestIPAddr
)
583 FIXME( "%p, %p, %p\n", iface
, pCost
, pDestIPAddr
);
585 if (!pCost
) return E_POINTER
;
587 *pCost
= NLM_CONNECTION_COST_UNRESTRICTED
;
591 static BOOL
map_address_6to4( const SOCKADDR_IN6
*addr6
, SOCKADDR_IN
*addr4
)
595 if (addr6
->sin6_family
!= WS_AF_INET6
) return FALSE
;
597 for (i
= 0; i
< 5; i
++)
598 if (addr6
->sin6_addr
.u
.Word
[i
]) return FALSE
;
600 if (addr6
->sin6_addr
.u
.Word
[5] != 0xffff) return FALSE
;
602 addr4
->sin_family
= WS_AF_INET
;
603 addr4
->sin_port
= addr6
->sin6_port
;
604 addr4
->sin_addr
.S_un
.S_addr
= addr6
->sin6_addr
.u
.Word
[6] << 16 | addr6
->sin6_addr
.u
.Word
[7];
605 memset( &addr4
->sin_zero
, 0, sizeof(addr4
->sin_zero
) );
610 static HRESULT WINAPI
cost_manager_GetDataPlanStatus(
611 INetworkCostManager
*iface
, NLM_DATAPLAN_STATUS
*pDataPlanStatus
,
612 NLM_SOCKADDR
*pDestIPAddr
)
616 SOCKADDR
*dst
= (SOCKADDR
*)pDestIPAddr
;
617 SOCKADDR_IN addr4
, *dst4
;
619 FIXME( "%p, %p, %p\n", iface
, pDataPlanStatus
, pDestIPAddr
);
621 if (!pDataPlanStatus
) return E_POINTER
;
623 if (dst
&& ((dst
->sa_family
== WS_AF_INET
&& (dst4
= (SOCKADDR_IN
*)dst
)) ||
624 ((dst
->sa_family
== WS_AF_INET6
&& map_address_6to4( (const SOCKADDR_IN6
*)dst
, &addr4
)
625 && (dst4
= &addr4
)))))
627 if ((ret
= GetBestInterface( dst4
->sin_addr
.S_un
.S_addr
, &index
)))
628 return HRESULT_FROM_WIN32( ret
);
630 if ((ret
= ConvertInterfaceIndexToLuid( index
, &luid
)))
631 return HRESULT_FROM_WIN32( ret
);
633 if ((ret
= ConvertInterfaceLuidToGuid( &luid
, &pDataPlanStatus
->InterfaceGuid
)))
634 return HRESULT_FROM_WIN32( ret
);
638 FIXME( "interface guid not found\n" );
639 memset( &pDataPlanStatus
->InterfaceGuid
, 0, sizeof(pDataPlanStatus
->InterfaceGuid
) );
642 pDataPlanStatus
->UsageData
.UsageInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
643 memset( &pDataPlanStatus
->UsageData
.LastSyncTime
, 0, sizeof(pDataPlanStatus
->UsageData
.LastSyncTime
) );
644 pDataPlanStatus
->DataLimitInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
645 pDataPlanStatus
->InboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
646 pDataPlanStatus
->OutboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
647 memset( &pDataPlanStatus
->NextBillingCycle
, 0, sizeof(pDataPlanStatus
->NextBillingCycle
) );
648 pDataPlanStatus
->MaxTransferSizeInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
649 pDataPlanStatus
->Reserved
= 0;
654 static HRESULT WINAPI
cost_manager_SetDestinationAddresses(
655 INetworkCostManager
*iface
, UINT32 length
, NLM_SOCKADDR
*pDestIPAddrList
,
656 VARIANT_BOOL bAppend
)
658 FIXME( "%p, %u, %p, %x\n", iface
, length
, pDestIPAddrList
, bAppend
);
662 static const INetworkCostManagerVtbl cost_manager_vtbl
=
664 cost_manager_QueryInterface
,
666 cost_manager_Release
,
667 cost_manager_GetCost
,
668 cost_manager_GetDataPlanStatus
,
669 cost_manager_SetDestinationAddresses
674 IEnumNetworks IEnumNetworks_iface
;
676 struct list_manager
*mgr
;
680 static inline struct networks_enum
*impl_from_IEnumNetworks(
681 IEnumNetworks
*iface
)
683 return CONTAINING_RECORD( iface
, struct networks_enum
, IEnumNetworks_iface
);
686 static HRESULT WINAPI
networks_enum_QueryInterface(
687 IEnumNetworks
*iface
, REFIID riid
, void **obj
)
689 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
691 TRACE( "%p, %s, %p\n", iter
, debugstr_guid(riid
), obj
);
693 if (IsEqualIID( riid
, &IID_IEnumNetworks
) ||
694 IsEqualIID( riid
, &IID_IDispatch
) ||
695 IsEqualIID( riid
, &IID_IUnknown
))
698 IEnumNetworks_AddRef( iface
);
703 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
705 return E_NOINTERFACE
;
709 static ULONG WINAPI
networks_enum_AddRef(
710 IEnumNetworks
*iface
)
712 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
714 TRACE( "%p\n", iter
);
715 return InterlockedIncrement( &iter
->refs
);
718 static ULONG WINAPI
networks_enum_Release(
719 IEnumNetworks
*iface
)
721 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
724 TRACE( "%p\n", iter
);
726 if (!(refs
= InterlockedDecrement( &iter
->refs
)))
728 INetworkListManager_Release( &iter
->mgr
->INetworkListManager_iface
);
734 static HRESULT WINAPI
networks_enum_GetTypeInfoCount(
735 IEnumNetworks
*iface
,
742 static HRESULT WINAPI
networks_enum_GetTypeInfo(
743 IEnumNetworks
*iface
,
752 static HRESULT WINAPI
networks_enum_GetIDsOfNames(
753 IEnumNetworks
*iface
,
764 static HRESULT WINAPI
networks_enum_Invoke(
765 IEnumNetworks
*iface
,
772 EXCEPINFO
*excep_info
,
779 static HRESULT WINAPI
networks_enum_get__NewEnum(
780 IEnumNetworks
*iface
, IEnumVARIANT
**ppEnumVar
)
786 static HRESULT WINAPI
networks_enum_Next(
787 IEnumNetworks
*iface
, ULONG count
, INetwork
**ret
, ULONG
*fetched
)
789 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
792 TRACE( "%p, %u %p %p\n", iter
, count
, ret
, fetched
);
794 if (fetched
) *fetched
= 0;
795 if (!count
) return S_OK
;
797 while (iter
->cursor
&& i
< count
)
799 struct network
*network
= LIST_ENTRY( iter
->cursor
, struct network
, entry
);
800 ret
[i
] = &network
->INetwork_iface
;
801 INetwork_AddRef( ret
[i
] );
802 iter
->cursor
= list_next( &iter
->mgr
->networks
, iter
->cursor
);
805 if (fetched
) *fetched
= i
;
807 return i
< count
? S_FALSE
: S_OK
;
810 static HRESULT WINAPI
networks_enum_Skip(
811 IEnumNetworks
*iface
, ULONG count
)
813 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
815 TRACE( "%p, %u\n", iter
, count
);
817 if (!count
) return S_OK
;
818 if (!iter
->cursor
) return S_FALSE
;
822 iter
->cursor
= list_next( &iter
->mgr
->networks
, iter
->cursor
);
823 if (!iter
->cursor
) break;
826 return count
? S_FALSE
: S_OK
;
829 static HRESULT WINAPI
networks_enum_Reset(
830 IEnumNetworks
*iface
)
832 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
834 TRACE( "%p\n", iter
);
836 iter
->cursor
= list_head( &iter
->mgr
->networks
);
840 static HRESULT
create_networks_enum(
841 struct list_manager
*, IEnumNetworks
** );
843 static HRESULT WINAPI
networks_enum_Clone(
844 IEnumNetworks
*iface
, IEnumNetworks
**ret
)
846 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
848 TRACE( "%p, %p\n", iter
, ret
);
849 return create_networks_enum( iter
->mgr
, ret
);
852 static const IEnumNetworksVtbl networks_enum_vtbl
=
854 networks_enum_QueryInterface
,
855 networks_enum_AddRef
,
856 networks_enum_Release
,
857 networks_enum_GetTypeInfoCount
,
858 networks_enum_GetTypeInfo
,
859 networks_enum_GetIDsOfNames
,
860 networks_enum_Invoke
,
861 networks_enum_get__NewEnum
,
868 static HRESULT
create_networks_enum(
869 struct list_manager
*mgr
, IEnumNetworks
**ret
)
871 struct networks_enum
*iter
;
874 if (!(iter
= heap_alloc( sizeof(*iter
) ))) return E_OUTOFMEMORY
;
876 iter
->IEnumNetworks_iface
.lpVtbl
= &networks_enum_vtbl
;
877 iter
->cursor
= list_head( &mgr
->networks
);
879 INetworkListManager_AddRef( &mgr
->INetworkListManager_iface
);
882 *ret
= &iter
->IEnumNetworks_iface
;
886 static inline struct list_manager
*impl_from_INetworkListManager(
887 INetworkListManager
*iface
)
889 return CONTAINING_RECORD( iface
, struct list_manager
, INetworkListManager_iface
);
892 struct connections_enum
894 IEnumNetworkConnections IEnumNetworkConnections_iface
;
896 struct list_manager
*mgr
;
900 static inline struct connections_enum
*impl_from_IEnumNetworkConnections(
901 IEnumNetworkConnections
*iface
)
903 return CONTAINING_RECORD( iface
, struct connections_enum
, IEnumNetworkConnections_iface
);
906 static HRESULT WINAPI
connections_enum_QueryInterface(
907 IEnumNetworkConnections
*iface
, REFIID riid
, void **obj
)
909 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
911 TRACE( "%p, %s, %p\n", iter
, debugstr_guid(riid
), obj
);
913 if (IsEqualIID( riid
, &IID_IEnumNetworkConnections
) ||
914 IsEqualIID( riid
, &IID_IDispatch
) ||
915 IsEqualIID( riid
, &IID_IUnknown
))
918 IEnumNetworkConnections_AddRef( iface
);
923 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
925 return E_NOINTERFACE
;
929 static ULONG WINAPI
connections_enum_AddRef(
930 IEnumNetworkConnections
*iface
)
932 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
934 TRACE( "%p\n", iter
);
935 return InterlockedIncrement( &iter
->refs
);
938 static ULONG WINAPI
connections_enum_Release(
939 IEnumNetworkConnections
*iface
)
941 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
944 TRACE( "%p\n", iter
);
946 if (!(refs
= InterlockedDecrement( &iter
->refs
)))
948 INetworkListManager_Release( &iter
->mgr
->INetworkListManager_iface
);
954 static HRESULT WINAPI
connections_enum_GetTypeInfoCount(
955 IEnumNetworkConnections
*iface
,
962 static HRESULT WINAPI
connections_enum_GetTypeInfo(
963 IEnumNetworkConnections
*iface
,
972 static HRESULT WINAPI
connections_enum_GetIDsOfNames(
973 IEnumNetworkConnections
*iface
,
984 static HRESULT WINAPI
connections_enum_Invoke(
985 IEnumNetworkConnections
*iface
,
992 EXCEPINFO
*excep_info
,
999 static HRESULT WINAPI
connections_enum_get__NewEnum(
1000 IEnumNetworkConnections
*iface
, IEnumVARIANT
**ppEnumVar
)
1006 static HRESULT WINAPI
connections_enum_Next(
1007 IEnumNetworkConnections
*iface
, ULONG count
, INetworkConnection
**ret
, ULONG
*fetched
)
1009 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1012 TRACE( "%p, %u %p %p\n", iter
, count
, ret
, fetched
);
1014 if (fetched
) *fetched
= 0;
1015 if (!count
) return S_OK
;
1017 while (iter
->cursor
&& i
< count
)
1019 struct connection
*connection
= LIST_ENTRY( iter
->cursor
, struct connection
, entry
);
1020 ret
[i
] = &connection
->INetworkConnection_iface
;
1021 INetworkConnection_AddRef( ret
[i
] );
1022 iter
->cursor
= list_next( &iter
->mgr
->connections
, iter
->cursor
);
1025 if (fetched
) *fetched
= i
;
1027 return i
< count
? S_FALSE
: S_OK
;
1030 static HRESULT WINAPI
connections_enum_Skip(
1031 IEnumNetworkConnections
*iface
, ULONG count
)
1033 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1035 TRACE( "%p, %u\n", iter
, count
);
1037 if (!count
) return S_OK
;
1038 if (!iter
->cursor
) return S_FALSE
;
1042 iter
->cursor
= list_next( &iter
->mgr
->connections
, iter
->cursor
);
1043 if (!iter
->cursor
) break;
1046 return count
? S_FALSE
: S_OK
;
1049 static HRESULT WINAPI
connections_enum_Reset(
1050 IEnumNetworkConnections
*iface
)
1052 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1054 TRACE( "%p\n", iter
);
1056 iter
->cursor
= list_head( &iter
->mgr
->connections
);
1060 static HRESULT
create_connections_enum(
1061 struct list_manager
*, IEnumNetworkConnections
** );
1063 static HRESULT WINAPI
connections_enum_Clone(
1064 IEnumNetworkConnections
*iface
, IEnumNetworkConnections
**ret
)
1066 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1068 TRACE( "%p, %p\n", iter
, ret
);
1069 return create_connections_enum( iter
->mgr
, ret
);
1072 static const IEnumNetworkConnectionsVtbl connections_enum_vtbl
=
1074 connections_enum_QueryInterface
,
1075 connections_enum_AddRef
,
1076 connections_enum_Release
,
1077 connections_enum_GetTypeInfoCount
,
1078 connections_enum_GetTypeInfo
,
1079 connections_enum_GetIDsOfNames
,
1080 connections_enum_Invoke
,
1081 connections_enum_get__NewEnum
,
1082 connections_enum_Next
,
1083 connections_enum_Skip
,
1084 connections_enum_Reset
,
1085 connections_enum_Clone
1088 static HRESULT
create_connections_enum(
1089 struct list_manager
*mgr
, IEnumNetworkConnections
**ret
)
1091 struct connections_enum
*iter
;
1094 if (!(iter
= heap_alloc( sizeof(*iter
) ))) return E_OUTOFMEMORY
;
1096 iter
->IEnumNetworkConnections_iface
.lpVtbl
= &connections_enum_vtbl
;
1098 INetworkListManager_AddRef( &mgr
->INetworkListManager_iface
);
1099 iter
->cursor
= list_head( &iter
->mgr
->connections
);
1102 *ret
= &iter
->IEnumNetworkConnections_iface
;
1106 static ULONG WINAPI
list_manager_AddRef(
1107 INetworkListManager
*iface
)
1109 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1110 return InterlockedIncrement( &mgr
->refs
);
1113 static ULONG WINAPI
list_manager_Release(
1114 INetworkListManager
*iface
)
1116 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1117 LONG refs
= InterlockedDecrement( &mgr
->refs
);
1122 TRACE( "destroying %p\n", mgr
);
1124 connection_point_release( &mgr
->conn_mgr_cp
);
1125 connection_point_release( &mgr
->cost_mgr_cp
);
1126 connection_point_release( &mgr
->list_mgr_cp
);
1127 while ((ptr
= list_head( &mgr
->networks
)))
1129 struct network
*network
= LIST_ENTRY( ptr
, struct network
, entry
);
1130 list_remove( &network
->entry
);
1131 INetwork_Release( &network
->INetwork_iface
);
1133 while ((ptr
= list_head( &mgr
->connections
)))
1135 struct connection
*connection
= LIST_ENTRY( ptr
, struct connection
, entry
);
1136 list_remove( &connection
->entry
);
1137 INetworkConnection_Release( &connection
->INetworkConnection_iface
);
1144 static HRESULT WINAPI
list_manager_QueryInterface(
1145 INetworkListManager
*iface
,
1149 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1151 TRACE( "%p, %s, %p\n", mgr
, debugstr_guid(riid
), obj
);
1153 if (IsEqualGUID( riid
, &IID_INetworkListManager
) ||
1154 IsEqualGUID( riid
, &IID_IDispatch
) ||
1155 IsEqualGUID( riid
, &IID_IUnknown
))
1159 else if (IsEqualGUID( riid
, &IID_INetworkCostManager
))
1161 *obj
= &mgr
->INetworkCostManager_iface
;
1163 else if (IsEqualGUID( riid
, &IID_IConnectionPointContainer
))
1165 *obj
= &mgr
->IConnectionPointContainer_iface
;
1169 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
1171 return E_NOINTERFACE
;
1173 INetworkListManager_AddRef( iface
);
1177 static HRESULT WINAPI
list_manager_GetTypeInfoCount(
1178 INetworkListManager
*iface
,
1185 static HRESULT WINAPI
list_manager_GetTypeInfo(
1186 INetworkListManager
*iface
,
1195 static HRESULT WINAPI
list_manager_GetIDsOfNames(
1196 INetworkListManager
*iface
,
1207 static HRESULT WINAPI
list_manager_Invoke(
1208 INetworkListManager
*iface
,
1215 EXCEPINFO
*excep_info
,
1222 static HRESULT WINAPI
list_manager_GetNetworks(
1223 INetworkListManager
*iface
,
1224 NLM_ENUM_NETWORK Flags
,
1225 IEnumNetworks
**ppEnumNetwork
)
1227 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1229 TRACE( "%p, %x, %p\n", iface
, Flags
, ppEnumNetwork
);
1230 if (Flags
) FIXME( "flags %08x not supported\n", Flags
);
1232 return create_networks_enum( mgr
, ppEnumNetwork
);
1235 static HRESULT WINAPI
list_manager_GetNetwork(
1236 INetworkListManager
*iface
,
1238 INetwork
**ppNetwork
)
1240 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1241 struct network
*network
;
1243 TRACE( "%p, %s, %p\n", iface
, debugstr_guid(&gdNetworkId
), ppNetwork
);
1245 LIST_FOR_EACH_ENTRY( network
, &mgr
->networks
, struct network
, entry
)
1247 if (IsEqualGUID( &network
->id
, &gdNetworkId
))
1249 *ppNetwork
= &network
->INetwork_iface
;
1250 INetwork_AddRef( *ppNetwork
);
1258 static HRESULT WINAPI
list_manager_GetNetworkConnections(
1259 INetworkListManager
*iface
,
1260 IEnumNetworkConnections
**ppEnum
)
1262 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1264 TRACE( "%p, %p\n", iface
, ppEnum
);
1265 return create_connections_enum( mgr
, ppEnum
);
1268 static HRESULT WINAPI
list_manager_GetNetworkConnection(
1269 INetworkListManager
*iface
,
1270 GUID gdNetworkConnectionId
,
1271 INetworkConnection
**ppNetworkConnection
)
1273 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1274 struct connection
*connection
;
1276 TRACE( "%p, %s, %p\n", iface
, debugstr_guid(&gdNetworkConnectionId
),
1277 ppNetworkConnection
);
1279 LIST_FOR_EACH_ENTRY( connection
, &mgr
->connections
, struct connection
, entry
)
1281 if (IsEqualGUID( &connection
->id
, &gdNetworkConnectionId
))
1283 *ppNetworkConnection
= &connection
->INetworkConnection_iface
;
1284 INetworkConnection_AddRef( *ppNetworkConnection
);
1292 static HRESULT WINAPI
list_manager_IsConnectedToInternet(
1293 INetworkListManager
*iface
,
1294 VARIANT_BOOL
*pbIsConnected
)
1296 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1297 struct network
*network
;
1299 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1301 LIST_FOR_EACH_ENTRY( network
, &mgr
->networks
, struct network
, entry
)
1303 if (network
->connected_to_internet
)
1305 *pbIsConnected
= VARIANT_TRUE
;
1310 *pbIsConnected
= VARIANT_FALSE
;
1314 static HRESULT WINAPI
list_manager_IsConnected(
1315 INetworkListManager
*iface
,
1316 VARIANT_BOOL
*pbIsConnected
)
1318 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1319 struct network
*network
;
1321 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1323 LIST_FOR_EACH_ENTRY( network
, &mgr
->networks
, struct network
, entry
)
1325 if (network
->connected
)
1327 *pbIsConnected
= VARIANT_TRUE
;
1332 *pbIsConnected
= VARIANT_FALSE
;
1336 static HRESULT WINAPI
list_manager_GetConnectivity(
1337 INetworkListManager
*iface
,
1338 NLM_CONNECTIVITY
*pConnectivity
)
1340 FIXME( "%p, %p\n", iface
, pConnectivity
);
1342 *pConnectivity
= NLM_CONNECTIVITY_IPV4_INTERNET
;
1346 static const INetworkListManagerVtbl list_manager_vtbl
=
1348 list_manager_QueryInterface
,
1349 list_manager_AddRef
,
1350 list_manager_Release
,
1351 list_manager_GetTypeInfoCount
,
1352 list_manager_GetTypeInfo
,
1353 list_manager_GetIDsOfNames
,
1354 list_manager_Invoke
,
1355 list_manager_GetNetworks
,
1356 list_manager_GetNetwork
,
1357 list_manager_GetNetworkConnections
,
1358 list_manager_GetNetworkConnection
,
1359 list_manager_IsConnectedToInternet
,
1360 list_manager_IsConnected
,
1361 list_manager_GetConnectivity
1364 static HRESULT WINAPI
ConnectionPointContainer_QueryInterface(IConnectionPointContainer
*iface
,
1365 REFIID riid
, void **ppv
)
1367 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1368 return INetworkListManager_QueryInterface(&This
->INetworkListManager_iface
, riid
, ppv
);
1371 static ULONG WINAPI
ConnectionPointContainer_AddRef(IConnectionPointContainer
*iface
)
1373 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1374 return INetworkListManager_AddRef(&This
->INetworkListManager_iface
);
1377 static ULONG WINAPI
ConnectionPointContainer_Release(IConnectionPointContainer
*iface
)
1379 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1380 return INetworkListManager_Release(&This
->INetworkListManager_iface
);
1383 static HRESULT WINAPI
ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer
*iface
,
1384 IEnumConnectionPoints
**ppEnum
)
1386 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1387 FIXME("(%p)->(%p): stub\n", This
, ppEnum
);
1391 static HRESULT WINAPI
ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer
*iface
,
1392 REFIID riid
, IConnectionPoint
**cp
)
1394 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1395 struct connection_point
*ret
;
1397 TRACE( "%p, %s, %p\n", This
, debugstr_guid(riid
), cp
);
1402 if (IsEqualGUID( riid
, &IID_INetworkListManagerEvents
))
1403 ret
= &This
->list_mgr_cp
;
1404 else if (IsEqualGUID( riid
, &IID_INetworkCostManagerEvents
))
1405 ret
= &This
->cost_mgr_cp
;
1406 else if (IsEqualGUID( riid
, &IID_INetworkConnectionEvents
))
1407 ret
= &This
->conn_mgr_cp
;
1410 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
1412 return E_NOINTERFACE
;
1415 IConnectionPoint_AddRef( *cp
= &ret
->IConnectionPoint_iface
);
1419 static const struct IConnectionPointContainerVtbl cpc_vtbl
=
1421 ConnectionPointContainer_QueryInterface
,
1422 ConnectionPointContainer_AddRef
,
1423 ConnectionPointContainer_Release
,
1424 ConnectionPointContainer_EnumConnectionPoints
,
1425 ConnectionPointContainer_FindConnectionPoint
1428 static inline struct connection
*impl_from_INetworkConnection(
1429 INetworkConnection
*iface
)
1431 return CONTAINING_RECORD( iface
, struct connection
, INetworkConnection_iface
);
1434 static HRESULT WINAPI
connection_QueryInterface(
1435 INetworkConnection
*iface
, REFIID riid
, void **obj
)
1437 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1439 TRACE( "%p, %s, %p\n", connection
, debugstr_guid(riid
), obj
);
1441 if (IsEqualIID( riid
, &IID_INetworkConnection
) ||
1442 IsEqualIID( riid
, &IID_IDispatch
) ||
1443 IsEqualIID( riid
, &IID_IUnknown
))
1447 else if (IsEqualIID( riid
, &IID_INetworkConnectionCost
))
1449 *obj
= &connection
->INetworkConnectionCost_iface
;
1453 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
1455 return E_NOINTERFACE
;
1457 INetworkConnection_AddRef( iface
);
1461 static ULONG WINAPI
connection_AddRef(
1462 INetworkConnection
*iface
)
1464 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1466 TRACE( "%p\n", connection
);
1467 return InterlockedIncrement( &connection
->refs
);
1470 static ULONG WINAPI
connection_Release(
1471 INetworkConnection
*iface
)
1473 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1476 TRACE( "%p\n", connection
);
1478 if (!(refs
= InterlockedDecrement( &connection
->refs
)))
1480 INetwork_Release( connection
->network
);
1481 list_remove( &connection
->entry
);
1482 heap_free( connection
);
1487 static HRESULT WINAPI
connection_GetTypeInfoCount(
1488 INetworkConnection
*iface
,
1495 static HRESULT WINAPI
connection_GetTypeInfo(
1496 INetworkConnection
*iface
,
1505 static HRESULT WINAPI
connection_GetIDsOfNames(
1506 INetworkConnection
*iface
,
1517 static HRESULT WINAPI
connection_Invoke(
1518 INetworkConnection
*iface
,
1525 EXCEPINFO
*excep_info
,
1532 static HRESULT WINAPI
connection_GetNetwork(
1533 INetworkConnection
*iface
,
1534 INetwork
**ppNetwork
)
1536 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1538 TRACE( "%p, %p\n", iface
, ppNetwork
);
1540 *ppNetwork
= connection
->network
;
1541 INetwork_AddRef( *ppNetwork
);
1545 static HRESULT WINAPI
connection_get_IsConnectedToInternet(
1546 INetworkConnection
*iface
,
1547 VARIANT_BOOL
*pbIsConnected
)
1549 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1551 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1553 *pbIsConnected
= connection
->connected_to_internet
;
1557 static HRESULT WINAPI
connection_get_IsConnected(
1558 INetworkConnection
*iface
,
1559 VARIANT_BOOL
*pbIsConnected
)
1561 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1563 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1565 *pbIsConnected
= connection
->connected
;
1569 static HRESULT WINAPI
connection_GetConnectivity(
1570 INetworkConnection
*iface
,
1571 NLM_CONNECTIVITY
*pConnectivity
)
1573 FIXME( "%p, %p\n", iface
, pConnectivity
);
1575 *pConnectivity
= NLM_CONNECTIVITY_IPV4_INTERNET
;
1579 static HRESULT WINAPI
connection_GetConnectionId(
1580 INetworkConnection
*iface
,
1581 GUID
*pgdConnectionId
)
1583 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1585 TRACE( "%p, %p\n", iface
, pgdConnectionId
);
1587 *pgdConnectionId
= connection
->id
;
1591 static HRESULT WINAPI
connection_GetAdapterId(
1592 INetworkConnection
*iface
,
1593 GUID
*pgdAdapterId
)
1595 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1597 FIXME( "%p, %p\n", iface
, pgdAdapterId
);
1599 *pgdAdapterId
= connection
->id
;
1603 static HRESULT WINAPI
connection_GetDomainType(
1604 INetworkConnection
*iface
,
1605 NLM_DOMAIN_TYPE
*pDomainType
)
1607 FIXME( "%p, %p\n", iface
, pDomainType
);
1609 *pDomainType
= NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK
;
1613 static const struct INetworkConnectionVtbl connection_vtbl
=
1615 connection_QueryInterface
,
1618 connection_GetTypeInfoCount
,
1619 connection_GetTypeInfo
,
1620 connection_GetIDsOfNames
,
1622 connection_GetNetwork
,
1623 connection_get_IsConnectedToInternet
,
1624 connection_get_IsConnected
,
1625 connection_GetConnectivity
,
1626 connection_GetConnectionId
,
1627 connection_GetAdapterId
,
1628 connection_GetDomainType
1631 static inline struct connection
*impl_from_INetworkConnectionCost(
1632 INetworkConnectionCost
*iface
)
1634 return CONTAINING_RECORD( iface
, struct connection
, INetworkConnectionCost_iface
);
1637 static HRESULT WINAPI
connection_cost_QueryInterface(
1638 INetworkConnectionCost
*iface
,
1642 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1643 return INetworkConnection_QueryInterface( &conn
->INetworkConnection_iface
, riid
, obj
);
1646 static ULONG WINAPI
connection_cost_AddRef(
1647 INetworkConnectionCost
*iface
)
1649 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1650 return INetworkConnection_AddRef( &conn
->INetworkConnection_iface
);
1653 static ULONG WINAPI
connection_cost_Release(
1654 INetworkConnectionCost
*iface
)
1656 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1657 return INetworkConnection_Release( &conn
->INetworkConnection_iface
);
1660 static HRESULT WINAPI
connection_cost_GetCost(
1661 INetworkConnectionCost
*iface
, DWORD
*pCost
)
1663 FIXME( "%p, %p\n", iface
, pCost
);
1665 if (!pCost
) return E_POINTER
;
1667 *pCost
= NLM_CONNECTION_COST_UNRESTRICTED
;
1671 static HRESULT WINAPI
connection_cost_GetDataPlanStatus(
1672 INetworkConnectionCost
*iface
, NLM_DATAPLAN_STATUS
*pDataPlanStatus
)
1674 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1676 FIXME( "%p, %p\n", iface
, pDataPlanStatus
);
1678 if (!pDataPlanStatus
) return E_POINTER
;
1680 memcpy( &pDataPlanStatus
->InterfaceGuid
, &conn
->id
, sizeof(conn
->id
) );
1681 pDataPlanStatus
->UsageData
.UsageInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1682 memset( &pDataPlanStatus
->UsageData
.LastSyncTime
, 0, sizeof(pDataPlanStatus
->UsageData
.LastSyncTime
) );
1683 pDataPlanStatus
->DataLimitInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1684 pDataPlanStatus
->InboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1685 pDataPlanStatus
->OutboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1686 memset( &pDataPlanStatus
->NextBillingCycle
, 0, sizeof(pDataPlanStatus
->NextBillingCycle
) );
1687 pDataPlanStatus
->MaxTransferSizeInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1688 pDataPlanStatus
->Reserved
= 0;
1693 static const INetworkConnectionCostVtbl connection_cost_vtbl
=
1695 connection_cost_QueryInterface
,
1696 connection_cost_AddRef
,
1697 connection_cost_Release
,
1698 connection_cost_GetCost
,
1699 connection_cost_GetDataPlanStatus
1702 static struct connection
*create_connection( const GUID
*id
)
1704 struct connection
*ret
;
1706 if (!(ret
= heap_alloc( sizeof(*ret
) ))) return NULL
;
1708 ret
->INetworkConnection_iface
.lpVtbl
= &connection_vtbl
;
1709 ret
->INetworkConnectionCost_iface
.lpVtbl
= &connection_cost_vtbl
;
1712 ret
->network
= NULL
;
1713 ret
->connected
= VARIANT_FALSE
;
1714 ret
->connected_to_internet
= VARIANT_FALSE
;
1715 list_init( &ret
->entry
);
1720 static void init_networks( struct list_manager
*mgr
)
1723 IP_ADAPTER_ADDRESSES
*buf
, *aa
;
1725 ULONG ret
, flags
= GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
|
1726 GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_INCLUDE_ALL_GATEWAYS
;
1728 list_init( &mgr
->networks
);
1729 list_init( &mgr
->connections
);
1731 ret
= GetAdaptersAddresses( WS_AF_UNSPEC
, flags
, NULL
, NULL
, &size
);
1732 if (ret
!= ERROR_BUFFER_OVERFLOW
) return;
1734 if (!(buf
= heap_alloc( size
))) return;
1735 if (GetAdaptersAddresses( WS_AF_UNSPEC
, flags
, NULL
, buf
, &size
))
1741 memset( &id
, 0, sizeof(id
) );
1742 for (aa
= buf
; aa
; aa
= aa
->Next
)
1744 struct network
*network
;
1745 struct connection
*connection
;
1747 id
.Data1
= aa
->u
.s
.IfIndex
;
1749 /* assume a one-to-one mapping between networks and connections */
1750 if (!(network
= create_network( &id
))) goto done
;
1751 if (!(connection
= create_connection( &id
)))
1753 INetwork_Release( &network
->INetwork_iface
);
1757 if (aa
->FirstUnicastAddress
)
1759 network
->connected
= VARIANT_TRUE
;
1760 connection
->connected
= VARIANT_TRUE
;
1762 if (aa
->FirstGatewayAddress
)
1764 network
->connected_to_internet
= VARIANT_TRUE
;
1765 connection
->connected_to_internet
= VARIANT_TRUE
;
1768 connection
->network
= &network
->INetwork_iface
;
1769 INetwork_AddRef( connection
->network
);
1771 list_add_tail( &mgr
->networks
, &network
->entry
);
1772 list_add_tail( &mgr
->connections
, &connection
->entry
);
1779 HRESULT
list_manager_create( void **obj
)
1781 struct list_manager
*mgr
;
1783 TRACE( "%p\n", obj
);
1785 if (!(mgr
= heap_alloc( sizeof(*mgr
) ))) return E_OUTOFMEMORY
;
1786 mgr
->INetworkListManager_iface
.lpVtbl
= &list_manager_vtbl
;
1787 mgr
->INetworkCostManager_iface
.lpVtbl
= &cost_manager_vtbl
;
1788 mgr
->IConnectionPointContainer_iface
.lpVtbl
= &cpc_vtbl
;
1789 init_networks( mgr
);
1792 connection_point_init( &mgr
->list_mgr_cp
, &IID_INetworkListManagerEvents
,
1793 &mgr
->IConnectionPointContainer_iface
);
1794 connection_point_init( &mgr
->cost_mgr_cp
, &IID_INetworkCostManagerEvents
,
1795 &mgr
->IConnectionPointContainer_iface
);
1796 connection_point_init( &mgr
->conn_mgr_cp
, &IID_INetworkConnectionEvents
,
1797 &mgr
->IConnectionPointContainer_iface
);
1799 *obj
= &mgr
->INetworkListManager_iface
;
1800 TRACE( "returning iface %p\n", *obj
);