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
35 #include "netlistmgr.h"
38 #include "wine/debug.h"
39 #include "wine/heap.h"
40 #include "wine/list.h"
41 #include "netprofm_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(netprofm
);
47 INetwork INetwork_iface
;
51 VARIANT_BOOL connected_to_internet
;
52 VARIANT_BOOL connected
;
57 INetworkConnection INetworkConnection_iface
;
58 INetworkConnectionCost INetworkConnectionCost_iface
;
63 VARIANT_BOOL connected_to_internet
;
64 VARIANT_BOOL connected
;
67 struct connection_point
69 IConnectionPoint IConnectionPoint_iface
;
70 IConnectionPointContainer
*container
;
78 INetworkListManager INetworkListManager_iface
;
79 INetworkCostManager INetworkCostManager_iface
;
80 IConnectionPointContainer IConnectionPointContainer_iface
;
83 struct list connections
;
84 struct connection_point list_mgr_cp
;
85 struct connection_point cost_mgr_cp
;
86 struct connection_point conn_mgr_cp
;
87 struct connection_point events_cp
;
97 static inline struct list_manager
*impl_from_IConnectionPointContainer(IConnectionPointContainer
*iface
)
99 return CONTAINING_RECORD(iface
, struct list_manager
, IConnectionPointContainer_iface
);
102 static inline struct list_manager
*impl_from_INetworkCostManager(
103 INetworkCostManager
*iface
)
105 return CONTAINING_RECORD( iface
, struct list_manager
, INetworkCostManager_iface
);
108 static inline struct connection_point
*impl_from_IConnectionPoint(
109 IConnectionPoint
*iface
)
111 return CONTAINING_RECORD( iface
, struct connection_point
, IConnectionPoint_iface
);
114 static HRESULT WINAPI
connection_point_QueryInterface(
115 IConnectionPoint
*iface
,
119 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
120 TRACE( "%p, %s, %p\n", cp
, debugstr_guid(riid
), obj
);
122 if (IsEqualGUID( riid
, &IID_IConnectionPoint
) ||
123 IsEqualGUID( riid
, &IID_IUnknown
))
129 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
131 return E_NOINTERFACE
;
133 IConnectionPoint_AddRef( iface
);
137 static ULONG WINAPI
connection_point_AddRef(
138 IConnectionPoint
*iface
)
140 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
141 return IConnectionPointContainer_AddRef( cp
->container
);
144 static ULONG WINAPI
connection_point_Release(
145 IConnectionPoint
*iface
)
147 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
148 return IConnectionPointContainer_Release( cp
->container
);
151 static HRESULT WINAPI
connection_point_GetConnectionInterface(
152 IConnectionPoint
*iface
,
155 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
156 TRACE( "%p, %p\n", cp
, iid
);
161 memcpy( iid
, &cp
->iid
, sizeof(*iid
) );
165 static HRESULT WINAPI
connection_point_GetConnectionPointContainer(
166 IConnectionPoint
*iface
,
167 IConnectionPointContainer
**container
)
169 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
170 TRACE( "%p, %p\n", cp
, container
);
175 IConnectionPointContainer_AddRef( cp
->container
);
176 *container
= cp
->container
;
180 static HRESULT WINAPI
connection_point_Advise(
181 IConnectionPoint
*iface
,
185 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
186 struct sink_entry
*sink_entry
;
190 FIXME( "%p, %p, %p - semi-stub\n", cp
, sink
, cookie
);
192 if (!sink
|| !cookie
)
195 hr
= IUnknown_QueryInterface( sink
, &cp
->iid
, (void**)&unk
);
198 WARN( "iface %s not implemented by sink\n", debugstr_guid(&cp
->iid
) );
199 return CO_E_FAILEDTOOPENTHREADTOKEN
;
202 sink_entry
= heap_alloc( sizeof(*sink_entry
) );
205 IUnknown_Release( unk
);
206 return E_OUTOFMEMORY
;
209 sink_entry
->unk
= unk
;
210 *cookie
= sink_entry
->cookie
= ++cp
->cookie
;
211 list_add_tail( &cp
->sinks
, &sink_entry
->entry
);
215 static void sink_entry_release( struct sink_entry
*entry
)
217 list_remove( &entry
->entry
);
218 IUnknown_Release( entry
->unk
);
222 static HRESULT WINAPI
connection_point_Unadvise(
223 IConnectionPoint
*iface
,
226 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
227 struct sink_entry
*iter
;
229 TRACE( "%p, %d\n", cp
, cookie
);
231 LIST_FOR_EACH_ENTRY( iter
, &cp
->sinks
, struct sink_entry
, entry
)
233 if (iter
->cookie
!= cookie
) continue;
234 sink_entry_release( iter
);
238 WARN( "invalid cookie\n" );
239 return OLE_E_NOCONNECTION
;
242 static HRESULT WINAPI
connection_point_EnumConnections(
243 IConnectionPoint
*iface
,
244 IEnumConnections
**connections
)
246 struct connection_point
*cp
= impl_from_IConnectionPoint( iface
);
247 FIXME( "%p, %p - stub\n", cp
, connections
);
252 static const IConnectionPointVtbl connection_point_vtbl
=
254 connection_point_QueryInterface
,
255 connection_point_AddRef
,
256 connection_point_Release
,
257 connection_point_GetConnectionInterface
,
258 connection_point_GetConnectionPointContainer
,
259 connection_point_Advise
,
260 connection_point_Unadvise
,
261 connection_point_EnumConnections
264 static void connection_point_init(
265 struct connection_point
*cp
,
267 IConnectionPointContainer
*container
)
269 cp
->IConnectionPoint_iface
.lpVtbl
= &connection_point_vtbl
;
270 cp
->container
= container
;
273 list_init( &cp
->sinks
);
276 static void connection_point_release( struct connection_point
*cp
)
278 while (!list_empty( &cp
->sinks
))
279 sink_entry_release( LIST_ENTRY( list_head( &cp
->sinks
), struct sink_entry
, entry
) );
282 static inline struct network
*impl_from_INetwork(
285 return CONTAINING_RECORD( iface
, struct network
, INetwork_iface
);
288 static HRESULT WINAPI
network_QueryInterface(
289 INetwork
*iface
, REFIID riid
, void **obj
)
291 struct network
*network
= impl_from_INetwork( iface
);
293 TRACE( "%p, %s, %p\n", network
, debugstr_guid(riid
), obj
);
295 if (IsEqualIID( riid
, &IID_INetwork
) ||
296 IsEqualIID( riid
, &IID_IDispatch
) ||
297 IsEqualIID( riid
, &IID_IUnknown
))
300 INetwork_AddRef( iface
);
305 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
307 return E_NOINTERFACE
;
311 static ULONG WINAPI
network_AddRef(
314 struct network
*network
= impl_from_INetwork( iface
);
316 TRACE( "%p\n", network
);
317 return InterlockedIncrement( &network
->refs
);
320 static ULONG WINAPI
network_Release(
323 struct network
*network
= impl_from_INetwork( iface
);
326 TRACE( "%p\n", network
);
328 if (!(refs
= InterlockedDecrement( &network
->refs
)))
330 list_remove( &network
->entry
);
331 heap_free( network
);
336 static HRESULT WINAPI
network_GetTypeInfoCount(
344 static HRESULT WINAPI
network_GetTypeInfo(
354 static HRESULT WINAPI
network_GetIDsOfNames(
366 static HRESULT WINAPI
network_Invoke(
374 EXCEPINFO
*excep_info
,
381 static HRESULT WINAPI
network_GetName(
383 BSTR
*pszNetworkName
)
385 FIXME( "%p, %p\n", iface
, pszNetworkName
);
389 static HRESULT WINAPI
network_SetName(
391 BSTR szNetworkNewName
)
393 FIXME( "%p, %s\n", iface
, debugstr_w(szNetworkNewName
) );
397 static HRESULT WINAPI
network_GetDescription(
399 BSTR
*pszDescription
)
401 FIXME( "%p, %p\n", iface
, pszDescription
);
405 static HRESULT WINAPI
network_SetDescription(
409 FIXME( "%p, %s\n", iface
, debugstr_w(szDescription
) );
413 static HRESULT WINAPI
network_GetNetworkId(
415 GUID
*pgdGuidNetworkId
)
417 struct network
*network
= impl_from_INetwork( iface
);
419 TRACE( "%p, %p\n", iface
, pgdGuidNetworkId
);
421 *pgdGuidNetworkId
= network
->id
;
425 static HRESULT WINAPI
network_GetDomainType(
427 NLM_DOMAIN_TYPE
*pDomainType
)
429 FIXME( "%p, %p\n", iface
, pDomainType
);
431 *pDomainType
= NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK
;
435 static HRESULT WINAPI
network_GetNetworkConnections(
437 IEnumNetworkConnections
**ppEnumNetworkConnection
)
439 FIXME( "%p, %p\n", iface
, ppEnumNetworkConnection
);
443 static HRESULT WINAPI
network_GetTimeCreatedAndConnected(
445 DWORD
*pdwLowDateTimeCreated
,
446 DWORD
*pdwHighDateTimeCreated
,
447 DWORD
*pdwLowDateTimeConnected
,
448 DWORD
*pdwHighDateTimeConnected
)
450 FIXME( "%p, %p, %p, %p, %p\n", iface
, pdwLowDateTimeCreated
, pdwHighDateTimeCreated
,
451 pdwLowDateTimeConnected
, pdwHighDateTimeConnected
);
455 static HRESULT WINAPI
network_get_IsConnectedToInternet(
457 VARIANT_BOOL
*pbIsConnected
)
459 struct network
*network
= impl_from_INetwork( iface
);
461 TRACE( "%p, %p\n", iface
, pbIsConnected
);
463 *pbIsConnected
= network
->connected_to_internet
;
467 static HRESULT WINAPI
network_get_IsConnected(
469 VARIANT_BOOL
*pbIsConnected
)
471 struct network
*network
= impl_from_INetwork( iface
);
473 TRACE( "%p, %p\n", iface
, pbIsConnected
);
475 *pbIsConnected
= network
->connected
;
479 static HRESULT WINAPI
network_GetConnectivity(
481 NLM_CONNECTIVITY
*pConnectivity
)
483 FIXME( "%p, %p\n", iface
, pConnectivity
);
485 *pConnectivity
= NLM_CONNECTIVITY_IPV4_INTERNET
;
489 static HRESULT WINAPI
network_GetCategory(
491 NLM_NETWORK_CATEGORY
*pCategory
)
493 FIXME( "%p, %p\n", iface
, pCategory
);
495 *pCategory
= NLM_NETWORK_CATEGORY_PUBLIC
;
499 static HRESULT WINAPI
network_SetCategory(
501 NLM_NETWORK_CATEGORY NewCategory
)
503 FIXME( "%p, %u\n", iface
, NewCategory
);
507 static const struct INetworkVtbl network_vtbl
=
509 network_QueryInterface
,
512 network_GetTypeInfoCount
,
514 network_GetIDsOfNames
,
518 network_GetDescription
,
519 network_SetDescription
,
520 network_GetNetworkId
,
521 network_GetDomainType
,
522 network_GetNetworkConnections
,
523 network_GetTimeCreatedAndConnected
,
524 network_get_IsConnectedToInternet
,
525 network_get_IsConnected
,
526 network_GetConnectivity
,
531 static struct network
*create_network( const GUID
*id
)
535 if (!(ret
= heap_alloc( sizeof(*ret
) ))) return NULL
;
537 ret
->INetwork_iface
.lpVtbl
= &network_vtbl
;
540 ret
->connected
= VARIANT_FALSE
;
541 ret
->connected_to_internet
= VARIANT_FALSE
;
542 list_init( &ret
->entry
);
547 static HRESULT WINAPI
cost_manager_QueryInterface(
548 INetworkCostManager
*iface
,
552 struct list_manager
*mgr
= impl_from_INetworkCostManager( iface
);
553 return INetworkListManager_QueryInterface( &mgr
->INetworkListManager_iface
, riid
, obj
);
556 static ULONG WINAPI
cost_manager_AddRef(
557 INetworkCostManager
*iface
)
559 struct list_manager
*mgr
= impl_from_INetworkCostManager( iface
);
560 return INetworkListManager_AddRef( &mgr
->INetworkListManager_iface
);
563 static ULONG WINAPI
cost_manager_Release(
564 INetworkCostManager
*iface
)
566 struct list_manager
*mgr
= impl_from_INetworkCostManager( iface
);
567 return INetworkListManager_Release( &mgr
->INetworkListManager_iface
);
570 static HRESULT WINAPI
cost_manager_GetCost(
571 INetworkCostManager
*iface
, DWORD
*pCost
, NLM_SOCKADDR
*pDestIPAddr
)
573 FIXME( "%p, %p, %p\n", iface
, pCost
, pDestIPAddr
);
575 if (!pCost
) return E_POINTER
;
577 *pCost
= NLM_CONNECTION_COST_UNRESTRICTED
;
581 static BOOL
map_address_6to4( const SOCKADDR_IN6
*addr6
, SOCKADDR_IN
*addr4
)
585 if (addr6
->sin6_family
!= AF_INET6
) return FALSE
;
587 for (i
= 0; i
< 5; i
++)
588 if (addr6
->sin6_addr
.u
.Word
[i
]) return FALSE
;
590 if (addr6
->sin6_addr
.u
.Word
[5] != 0xffff) return FALSE
;
592 addr4
->sin_family
= AF_INET
;
593 addr4
->sin_port
= addr6
->sin6_port
;
594 addr4
->sin_addr
.S_un
.S_addr
= addr6
->sin6_addr
.u
.Word
[6] << 16 | addr6
->sin6_addr
.u
.Word
[7];
595 memset( &addr4
->sin_zero
, 0, sizeof(addr4
->sin_zero
) );
600 static HRESULT WINAPI
cost_manager_GetDataPlanStatus(
601 INetworkCostManager
*iface
, NLM_DATAPLAN_STATUS
*pDataPlanStatus
,
602 NLM_SOCKADDR
*pDestIPAddr
)
606 SOCKADDR
*dst
= (SOCKADDR
*)pDestIPAddr
;
607 SOCKADDR_IN addr4
, *dst4
;
609 FIXME( "%p, %p, %p\n", iface
, pDataPlanStatus
, pDestIPAddr
);
611 if (!pDataPlanStatus
) return E_POINTER
;
613 if (dst
&& ((dst
->sa_family
== AF_INET
&& (dst4
= (SOCKADDR_IN
*)dst
)) ||
614 ((dst
->sa_family
== AF_INET6
&& map_address_6to4( (const SOCKADDR_IN6
*)dst
, &addr4
)
615 && (dst4
= &addr4
)))))
617 if ((ret
= GetBestInterface( dst4
->sin_addr
.S_un
.S_addr
, &index
)))
618 return HRESULT_FROM_WIN32( ret
);
620 if ((ret
= ConvertInterfaceIndexToLuid( index
, &luid
)))
621 return HRESULT_FROM_WIN32( ret
);
623 if ((ret
= ConvertInterfaceLuidToGuid( &luid
, &pDataPlanStatus
->InterfaceGuid
)))
624 return HRESULT_FROM_WIN32( ret
);
628 FIXME( "interface guid not found\n" );
629 memset( &pDataPlanStatus
->InterfaceGuid
, 0, sizeof(pDataPlanStatus
->InterfaceGuid
) );
632 pDataPlanStatus
->UsageData
.UsageInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
633 memset( &pDataPlanStatus
->UsageData
.LastSyncTime
, 0, sizeof(pDataPlanStatus
->UsageData
.LastSyncTime
) );
634 pDataPlanStatus
->DataLimitInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
635 pDataPlanStatus
->InboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
636 pDataPlanStatus
->OutboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
637 memset( &pDataPlanStatus
->NextBillingCycle
, 0, sizeof(pDataPlanStatus
->NextBillingCycle
) );
638 pDataPlanStatus
->MaxTransferSizeInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
639 pDataPlanStatus
->Reserved
= 0;
644 static HRESULT WINAPI
cost_manager_SetDestinationAddresses(
645 INetworkCostManager
*iface
, UINT32 length
, NLM_SOCKADDR
*pDestIPAddrList
,
646 VARIANT_BOOL bAppend
)
648 FIXME( "%p, %u, %p, %x\n", iface
, length
, pDestIPAddrList
, bAppend
);
652 static const INetworkCostManagerVtbl cost_manager_vtbl
=
654 cost_manager_QueryInterface
,
656 cost_manager_Release
,
657 cost_manager_GetCost
,
658 cost_manager_GetDataPlanStatus
,
659 cost_manager_SetDestinationAddresses
664 IEnumNetworks IEnumNetworks_iface
;
666 struct list_manager
*mgr
;
670 static inline struct networks_enum
*impl_from_IEnumNetworks(
671 IEnumNetworks
*iface
)
673 return CONTAINING_RECORD( iface
, struct networks_enum
, IEnumNetworks_iface
);
676 static HRESULT WINAPI
networks_enum_QueryInterface(
677 IEnumNetworks
*iface
, REFIID riid
, void **obj
)
679 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
681 TRACE( "%p, %s, %p\n", iter
, debugstr_guid(riid
), obj
);
683 if (IsEqualIID( riid
, &IID_IEnumNetworks
) ||
684 IsEqualIID( riid
, &IID_IDispatch
) ||
685 IsEqualIID( riid
, &IID_IUnknown
))
688 IEnumNetworks_AddRef( iface
);
693 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
695 return E_NOINTERFACE
;
699 static ULONG WINAPI
networks_enum_AddRef(
700 IEnumNetworks
*iface
)
702 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
704 TRACE( "%p\n", iter
);
705 return InterlockedIncrement( &iter
->refs
);
708 static ULONG WINAPI
networks_enum_Release(
709 IEnumNetworks
*iface
)
711 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
714 TRACE( "%p\n", iter
);
716 if (!(refs
= InterlockedDecrement( &iter
->refs
)))
718 INetworkListManager_Release( &iter
->mgr
->INetworkListManager_iface
);
724 static HRESULT WINAPI
networks_enum_GetTypeInfoCount(
725 IEnumNetworks
*iface
,
732 static HRESULT WINAPI
networks_enum_GetTypeInfo(
733 IEnumNetworks
*iface
,
742 static HRESULT WINAPI
networks_enum_GetIDsOfNames(
743 IEnumNetworks
*iface
,
754 static HRESULT WINAPI
networks_enum_Invoke(
755 IEnumNetworks
*iface
,
762 EXCEPINFO
*excep_info
,
769 static HRESULT WINAPI
networks_enum_get__NewEnum(
770 IEnumNetworks
*iface
, IEnumVARIANT
**ppEnumVar
)
776 static HRESULT WINAPI
networks_enum_Next(
777 IEnumNetworks
*iface
, ULONG count
, INetwork
**ret
, ULONG
*fetched
)
779 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
782 TRACE( "%p, %u %p %p\n", iter
, count
, ret
, fetched
);
784 if (fetched
) *fetched
= 0;
785 if (!count
) return S_OK
;
787 while (iter
->cursor
&& i
< count
)
789 struct network
*network
= LIST_ENTRY( iter
->cursor
, struct network
, entry
);
790 ret
[i
] = &network
->INetwork_iface
;
791 INetwork_AddRef( ret
[i
] );
792 iter
->cursor
= list_next( &iter
->mgr
->networks
, iter
->cursor
);
795 if (fetched
) *fetched
= i
;
797 return i
< count
? S_FALSE
: S_OK
;
800 static HRESULT WINAPI
networks_enum_Skip(
801 IEnumNetworks
*iface
, ULONG count
)
803 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
805 TRACE( "%p, %u\n", iter
, count
);
807 if (!count
) return S_OK
;
808 if (!iter
->cursor
) return S_FALSE
;
812 iter
->cursor
= list_next( &iter
->mgr
->networks
, iter
->cursor
);
813 if (!iter
->cursor
) break;
816 return count
? S_FALSE
: S_OK
;
819 static HRESULT WINAPI
networks_enum_Reset(
820 IEnumNetworks
*iface
)
822 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
824 TRACE( "%p\n", iter
);
826 iter
->cursor
= list_head( &iter
->mgr
->networks
);
830 static HRESULT
create_networks_enum(
831 struct list_manager
*, IEnumNetworks
** );
833 static HRESULT WINAPI
networks_enum_Clone(
834 IEnumNetworks
*iface
, IEnumNetworks
**ret
)
836 struct networks_enum
*iter
= impl_from_IEnumNetworks( iface
);
838 TRACE( "%p, %p\n", iter
, ret
);
839 return create_networks_enum( iter
->mgr
, ret
);
842 static const IEnumNetworksVtbl networks_enum_vtbl
=
844 networks_enum_QueryInterface
,
845 networks_enum_AddRef
,
846 networks_enum_Release
,
847 networks_enum_GetTypeInfoCount
,
848 networks_enum_GetTypeInfo
,
849 networks_enum_GetIDsOfNames
,
850 networks_enum_Invoke
,
851 networks_enum_get__NewEnum
,
858 static HRESULT
create_networks_enum(
859 struct list_manager
*mgr
, IEnumNetworks
**ret
)
861 struct networks_enum
*iter
;
864 if (!(iter
= heap_alloc( sizeof(*iter
) ))) return E_OUTOFMEMORY
;
866 iter
->IEnumNetworks_iface
.lpVtbl
= &networks_enum_vtbl
;
867 iter
->cursor
= list_head( &mgr
->networks
);
869 INetworkListManager_AddRef( &mgr
->INetworkListManager_iface
);
872 *ret
= &iter
->IEnumNetworks_iface
;
876 static inline struct list_manager
*impl_from_INetworkListManager(
877 INetworkListManager
*iface
)
879 return CONTAINING_RECORD( iface
, struct list_manager
, INetworkListManager_iface
);
882 struct connections_enum
884 IEnumNetworkConnections IEnumNetworkConnections_iface
;
886 struct list_manager
*mgr
;
890 static inline struct connections_enum
*impl_from_IEnumNetworkConnections(
891 IEnumNetworkConnections
*iface
)
893 return CONTAINING_RECORD( iface
, struct connections_enum
, IEnumNetworkConnections_iface
);
896 static HRESULT WINAPI
connections_enum_QueryInterface(
897 IEnumNetworkConnections
*iface
, REFIID riid
, void **obj
)
899 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
901 TRACE( "%p, %s, %p\n", iter
, debugstr_guid(riid
), obj
);
903 if (IsEqualIID( riid
, &IID_IEnumNetworkConnections
) ||
904 IsEqualIID( riid
, &IID_IDispatch
) ||
905 IsEqualIID( riid
, &IID_IUnknown
))
908 IEnumNetworkConnections_AddRef( iface
);
913 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
915 return E_NOINTERFACE
;
919 static ULONG WINAPI
connections_enum_AddRef(
920 IEnumNetworkConnections
*iface
)
922 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
924 TRACE( "%p\n", iter
);
925 return InterlockedIncrement( &iter
->refs
);
928 static ULONG WINAPI
connections_enum_Release(
929 IEnumNetworkConnections
*iface
)
931 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
934 TRACE( "%p\n", iter
);
936 if (!(refs
= InterlockedDecrement( &iter
->refs
)))
938 INetworkListManager_Release( &iter
->mgr
->INetworkListManager_iface
);
944 static HRESULT WINAPI
connections_enum_GetTypeInfoCount(
945 IEnumNetworkConnections
*iface
,
952 static HRESULT WINAPI
connections_enum_GetTypeInfo(
953 IEnumNetworkConnections
*iface
,
962 static HRESULT WINAPI
connections_enum_GetIDsOfNames(
963 IEnumNetworkConnections
*iface
,
974 static HRESULT WINAPI
connections_enum_Invoke(
975 IEnumNetworkConnections
*iface
,
982 EXCEPINFO
*excep_info
,
989 static HRESULT WINAPI
connections_enum_get__NewEnum(
990 IEnumNetworkConnections
*iface
, IEnumVARIANT
**ppEnumVar
)
996 static HRESULT WINAPI
connections_enum_Next(
997 IEnumNetworkConnections
*iface
, ULONG count
, INetworkConnection
**ret
, ULONG
*fetched
)
999 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1002 TRACE( "%p, %u %p %p\n", iter
, count
, ret
, fetched
);
1004 if (fetched
) *fetched
= 0;
1005 if (!count
) return S_OK
;
1007 while (iter
->cursor
&& i
< count
)
1009 struct connection
*connection
= LIST_ENTRY( iter
->cursor
, struct connection
, entry
);
1010 ret
[i
] = &connection
->INetworkConnection_iface
;
1011 INetworkConnection_AddRef( ret
[i
] );
1012 iter
->cursor
= list_next( &iter
->mgr
->connections
, iter
->cursor
);
1015 if (fetched
) *fetched
= i
;
1017 return i
< count
? S_FALSE
: S_OK
;
1020 static HRESULT WINAPI
connections_enum_Skip(
1021 IEnumNetworkConnections
*iface
, ULONG count
)
1023 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1025 TRACE( "%p, %u\n", iter
, count
);
1027 if (!count
) return S_OK
;
1028 if (!iter
->cursor
) return S_FALSE
;
1032 iter
->cursor
= list_next( &iter
->mgr
->connections
, iter
->cursor
);
1033 if (!iter
->cursor
) break;
1036 return count
? S_FALSE
: S_OK
;
1039 static HRESULT WINAPI
connections_enum_Reset(
1040 IEnumNetworkConnections
*iface
)
1042 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1044 TRACE( "%p\n", iter
);
1046 iter
->cursor
= list_head( &iter
->mgr
->connections
);
1050 static HRESULT
create_connections_enum(
1051 struct list_manager
*, IEnumNetworkConnections
** );
1053 static HRESULT WINAPI
connections_enum_Clone(
1054 IEnumNetworkConnections
*iface
, IEnumNetworkConnections
**ret
)
1056 struct connections_enum
*iter
= impl_from_IEnumNetworkConnections( iface
);
1058 TRACE( "%p, %p\n", iter
, ret
);
1059 return create_connections_enum( iter
->mgr
, ret
);
1062 static const IEnumNetworkConnectionsVtbl connections_enum_vtbl
=
1064 connections_enum_QueryInterface
,
1065 connections_enum_AddRef
,
1066 connections_enum_Release
,
1067 connections_enum_GetTypeInfoCount
,
1068 connections_enum_GetTypeInfo
,
1069 connections_enum_GetIDsOfNames
,
1070 connections_enum_Invoke
,
1071 connections_enum_get__NewEnum
,
1072 connections_enum_Next
,
1073 connections_enum_Skip
,
1074 connections_enum_Reset
,
1075 connections_enum_Clone
1078 static HRESULT
create_connections_enum(
1079 struct list_manager
*mgr
, IEnumNetworkConnections
**ret
)
1081 struct connections_enum
*iter
;
1084 if (!(iter
= heap_alloc( sizeof(*iter
) ))) return E_OUTOFMEMORY
;
1086 iter
->IEnumNetworkConnections_iface
.lpVtbl
= &connections_enum_vtbl
;
1088 INetworkListManager_AddRef( &mgr
->INetworkListManager_iface
);
1089 iter
->cursor
= list_head( &iter
->mgr
->connections
);
1092 *ret
= &iter
->IEnumNetworkConnections_iface
;
1096 static ULONG WINAPI
list_manager_AddRef(
1097 INetworkListManager
*iface
)
1099 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1100 return InterlockedIncrement( &mgr
->refs
);
1103 static ULONG WINAPI
list_manager_Release(
1104 INetworkListManager
*iface
)
1106 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1107 LONG refs
= InterlockedDecrement( &mgr
->refs
);
1112 TRACE( "destroying %p\n", mgr
);
1114 connection_point_release( &mgr
->events_cp
);
1115 connection_point_release( &mgr
->conn_mgr_cp
);
1116 connection_point_release( &mgr
->cost_mgr_cp
);
1117 connection_point_release( &mgr
->list_mgr_cp
);
1118 while ((ptr
= list_head( &mgr
->networks
)))
1120 struct network
*network
= LIST_ENTRY( ptr
, struct network
, entry
);
1121 list_remove( &network
->entry
);
1122 INetwork_Release( &network
->INetwork_iface
);
1124 while ((ptr
= list_head( &mgr
->connections
)))
1126 struct connection
*connection
= LIST_ENTRY( ptr
, struct connection
, entry
);
1127 list_remove( &connection
->entry
);
1128 INetworkConnection_Release( &connection
->INetworkConnection_iface
);
1135 static HRESULT WINAPI
list_manager_QueryInterface(
1136 INetworkListManager
*iface
,
1140 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1142 TRACE( "%p, %s, %p\n", mgr
, debugstr_guid(riid
), obj
);
1144 if (IsEqualGUID( riid
, &IID_INetworkListManager
) ||
1145 IsEqualGUID( riid
, &IID_IDispatch
) ||
1146 IsEqualGUID( riid
, &IID_IUnknown
))
1150 else if (IsEqualGUID( riid
, &IID_INetworkCostManager
))
1152 *obj
= &mgr
->INetworkCostManager_iface
;
1154 else if (IsEqualGUID( riid
, &IID_IConnectionPointContainer
))
1156 *obj
= &mgr
->IConnectionPointContainer_iface
;
1160 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
1162 return E_NOINTERFACE
;
1164 INetworkListManager_AddRef( iface
);
1168 static HRESULT WINAPI
list_manager_GetTypeInfoCount(
1169 INetworkListManager
*iface
,
1176 static HRESULT WINAPI
list_manager_GetTypeInfo(
1177 INetworkListManager
*iface
,
1186 static HRESULT WINAPI
list_manager_GetIDsOfNames(
1187 INetworkListManager
*iface
,
1198 static HRESULT WINAPI
list_manager_Invoke(
1199 INetworkListManager
*iface
,
1206 EXCEPINFO
*excep_info
,
1213 static HRESULT WINAPI
list_manager_GetNetworks(
1214 INetworkListManager
*iface
,
1215 NLM_ENUM_NETWORK Flags
,
1216 IEnumNetworks
**ppEnumNetwork
)
1218 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1220 TRACE( "%p, %x, %p\n", iface
, Flags
, ppEnumNetwork
);
1221 if (Flags
) FIXME( "flags %08x not supported\n", Flags
);
1223 return create_networks_enum( mgr
, ppEnumNetwork
);
1226 static HRESULT WINAPI
list_manager_GetNetwork(
1227 INetworkListManager
*iface
,
1229 INetwork
**ppNetwork
)
1231 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1232 struct network
*network
;
1234 TRACE( "%p, %s, %p\n", iface
, debugstr_guid(&gdNetworkId
), ppNetwork
);
1236 LIST_FOR_EACH_ENTRY( network
, &mgr
->networks
, struct network
, entry
)
1238 if (IsEqualGUID( &network
->id
, &gdNetworkId
))
1240 *ppNetwork
= &network
->INetwork_iface
;
1241 INetwork_AddRef( *ppNetwork
);
1249 static HRESULT WINAPI
list_manager_GetNetworkConnections(
1250 INetworkListManager
*iface
,
1251 IEnumNetworkConnections
**ppEnum
)
1253 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1255 TRACE( "%p, %p\n", iface
, ppEnum
);
1256 return create_connections_enum( mgr
, ppEnum
);
1259 static HRESULT WINAPI
list_manager_GetNetworkConnection(
1260 INetworkListManager
*iface
,
1261 GUID gdNetworkConnectionId
,
1262 INetworkConnection
**ppNetworkConnection
)
1264 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1265 struct connection
*connection
;
1267 TRACE( "%p, %s, %p\n", iface
, debugstr_guid(&gdNetworkConnectionId
),
1268 ppNetworkConnection
);
1270 LIST_FOR_EACH_ENTRY( connection
, &mgr
->connections
, struct connection
, entry
)
1272 if (IsEqualGUID( &connection
->id
, &gdNetworkConnectionId
))
1274 *ppNetworkConnection
= &connection
->INetworkConnection_iface
;
1275 INetworkConnection_AddRef( *ppNetworkConnection
);
1283 static HRESULT WINAPI
list_manager_IsConnectedToInternet(
1284 INetworkListManager
*iface
,
1285 VARIANT_BOOL
*pbIsConnected
)
1287 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1288 struct network
*network
;
1290 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1292 LIST_FOR_EACH_ENTRY( network
, &mgr
->networks
, struct network
, entry
)
1294 if (network
->connected_to_internet
)
1296 *pbIsConnected
= VARIANT_TRUE
;
1301 *pbIsConnected
= VARIANT_FALSE
;
1305 static HRESULT WINAPI
list_manager_IsConnected(
1306 INetworkListManager
*iface
,
1307 VARIANT_BOOL
*pbIsConnected
)
1309 struct list_manager
*mgr
= impl_from_INetworkListManager( iface
);
1310 struct network
*network
;
1312 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1314 LIST_FOR_EACH_ENTRY( network
, &mgr
->networks
, struct network
, entry
)
1316 if (network
->connected
)
1318 *pbIsConnected
= VARIANT_TRUE
;
1323 *pbIsConnected
= VARIANT_FALSE
;
1327 static HRESULT WINAPI
list_manager_GetConnectivity(
1328 INetworkListManager
*iface
,
1329 NLM_CONNECTIVITY
*pConnectivity
)
1331 FIXME( "%p, %p\n", iface
, pConnectivity
);
1333 *pConnectivity
= NLM_CONNECTIVITY_IPV4_INTERNET
;
1337 static const INetworkListManagerVtbl list_manager_vtbl
=
1339 list_manager_QueryInterface
,
1340 list_manager_AddRef
,
1341 list_manager_Release
,
1342 list_manager_GetTypeInfoCount
,
1343 list_manager_GetTypeInfo
,
1344 list_manager_GetIDsOfNames
,
1345 list_manager_Invoke
,
1346 list_manager_GetNetworks
,
1347 list_manager_GetNetwork
,
1348 list_manager_GetNetworkConnections
,
1349 list_manager_GetNetworkConnection
,
1350 list_manager_IsConnectedToInternet
,
1351 list_manager_IsConnected
,
1352 list_manager_GetConnectivity
1355 static HRESULT WINAPI
ConnectionPointContainer_QueryInterface(IConnectionPointContainer
*iface
,
1356 REFIID riid
, void **ppv
)
1358 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1359 return INetworkListManager_QueryInterface(&This
->INetworkListManager_iface
, riid
, ppv
);
1362 static ULONG WINAPI
ConnectionPointContainer_AddRef(IConnectionPointContainer
*iface
)
1364 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1365 return INetworkListManager_AddRef(&This
->INetworkListManager_iface
);
1368 static ULONG WINAPI
ConnectionPointContainer_Release(IConnectionPointContainer
*iface
)
1370 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1371 return INetworkListManager_Release(&This
->INetworkListManager_iface
);
1374 static HRESULT WINAPI
ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer
*iface
,
1375 IEnumConnectionPoints
**ppEnum
)
1377 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1378 FIXME("(%p)->(%p): stub\n", This
, ppEnum
);
1382 static HRESULT WINAPI
ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer
*iface
,
1383 REFIID riid
, IConnectionPoint
**cp
)
1385 struct list_manager
*This
= impl_from_IConnectionPointContainer( iface
);
1386 struct connection_point
*ret
;
1388 TRACE( "%p, %s, %p\n", This
, debugstr_guid(riid
), cp
);
1393 if (IsEqualGUID( riid
, &IID_INetworkListManagerEvents
))
1394 ret
= &This
->list_mgr_cp
;
1395 else if (IsEqualGUID( riid
, &IID_INetworkCostManagerEvents
))
1396 ret
= &This
->cost_mgr_cp
;
1397 else if (IsEqualGUID( riid
, &IID_INetworkConnectionEvents
))
1398 ret
= &This
->conn_mgr_cp
;
1399 else if (IsEqualGUID( riid
, &IID_INetworkEvents
))
1400 ret
= &This
->events_cp
;
1403 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
1405 return E_NOINTERFACE
;
1408 IConnectionPoint_AddRef( *cp
= &ret
->IConnectionPoint_iface
);
1412 static const struct IConnectionPointContainerVtbl cpc_vtbl
=
1414 ConnectionPointContainer_QueryInterface
,
1415 ConnectionPointContainer_AddRef
,
1416 ConnectionPointContainer_Release
,
1417 ConnectionPointContainer_EnumConnectionPoints
,
1418 ConnectionPointContainer_FindConnectionPoint
1421 static inline struct connection
*impl_from_INetworkConnection(
1422 INetworkConnection
*iface
)
1424 return CONTAINING_RECORD( iface
, struct connection
, INetworkConnection_iface
);
1427 static HRESULT WINAPI
connection_QueryInterface(
1428 INetworkConnection
*iface
, REFIID riid
, void **obj
)
1430 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1432 TRACE( "%p, %s, %p\n", connection
, debugstr_guid(riid
), obj
);
1434 if (IsEqualIID( riid
, &IID_INetworkConnection
) ||
1435 IsEqualIID( riid
, &IID_IDispatch
) ||
1436 IsEqualIID( riid
, &IID_IUnknown
))
1440 else if (IsEqualIID( riid
, &IID_INetworkConnectionCost
))
1442 *obj
= &connection
->INetworkConnectionCost_iface
;
1446 WARN( "interface not supported %s\n", debugstr_guid(riid
) );
1448 return E_NOINTERFACE
;
1450 INetworkConnection_AddRef( iface
);
1454 static ULONG WINAPI
connection_AddRef(
1455 INetworkConnection
*iface
)
1457 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1459 TRACE( "%p\n", connection
);
1460 return InterlockedIncrement( &connection
->refs
);
1463 static ULONG WINAPI
connection_Release(
1464 INetworkConnection
*iface
)
1466 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1469 TRACE( "%p\n", connection
);
1471 if (!(refs
= InterlockedDecrement( &connection
->refs
)))
1473 INetwork_Release( connection
->network
);
1474 list_remove( &connection
->entry
);
1475 heap_free( connection
);
1480 static HRESULT WINAPI
connection_GetTypeInfoCount(
1481 INetworkConnection
*iface
,
1488 static HRESULT WINAPI
connection_GetTypeInfo(
1489 INetworkConnection
*iface
,
1498 static HRESULT WINAPI
connection_GetIDsOfNames(
1499 INetworkConnection
*iface
,
1510 static HRESULT WINAPI
connection_Invoke(
1511 INetworkConnection
*iface
,
1518 EXCEPINFO
*excep_info
,
1525 static HRESULT WINAPI
connection_GetNetwork(
1526 INetworkConnection
*iface
,
1527 INetwork
**ppNetwork
)
1529 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1531 TRACE( "%p, %p\n", iface
, ppNetwork
);
1533 *ppNetwork
= connection
->network
;
1534 INetwork_AddRef( *ppNetwork
);
1538 static HRESULT WINAPI
connection_get_IsConnectedToInternet(
1539 INetworkConnection
*iface
,
1540 VARIANT_BOOL
*pbIsConnected
)
1542 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1544 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1546 *pbIsConnected
= connection
->connected_to_internet
;
1550 static HRESULT WINAPI
connection_get_IsConnected(
1551 INetworkConnection
*iface
,
1552 VARIANT_BOOL
*pbIsConnected
)
1554 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1556 TRACE( "%p, %p\n", iface
, pbIsConnected
);
1558 *pbIsConnected
= connection
->connected
;
1562 static HRESULT WINAPI
connection_GetConnectivity(
1563 INetworkConnection
*iface
,
1564 NLM_CONNECTIVITY
*pConnectivity
)
1566 FIXME( "%p, %p\n", iface
, pConnectivity
);
1568 *pConnectivity
= NLM_CONNECTIVITY_IPV4_INTERNET
;
1572 static HRESULT WINAPI
connection_GetConnectionId(
1573 INetworkConnection
*iface
,
1574 GUID
*pgdConnectionId
)
1576 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1578 TRACE( "%p, %p\n", iface
, pgdConnectionId
);
1580 *pgdConnectionId
= connection
->id
;
1584 static HRESULT WINAPI
connection_GetAdapterId(
1585 INetworkConnection
*iface
,
1586 GUID
*pgdAdapterId
)
1588 struct connection
*connection
= impl_from_INetworkConnection( iface
);
1590 FIXME( "%p, %p\n", iface
, pgdAdapterId
);
1592 *pgdAdapterId
= connection
->id
;
1596 static HRESULT WINAPI
connection_GetDomainType(
1597 INetworkConnection
*iface
,
1598 NLM_DOMAIN_TYPE
*pDomainType
)
1600 FIXME( "%p, %p\n", iface
, pDomainType
);
1602 *pDomainType
= NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK
;
1606 static const struct INetworkConnectionVtbl connection_vtbl
=
1608 connection_QueryInterface
,
1611 connection_GetTypeInfoCount
,
1612 connection_GetTypeInfo
,
1613 connection_GetIDsOfNames
,
1615 connection_GetNetwork
,
1616 connection_get_IsConnectedToInternet
,
1617 connection_get_IsConnected
,
1618 connection_GetConnectivity
,
1619 connection_GetConnectionId
,
1620 connection_GetAdapterId
,
1621 connection_GetDomainType
1624 static inline struct connection
*impl_from_INetworkConnectionCost(
1625 INetworkConnectionCost
*iface
)
1627 return CONTAINING_RECORD( iface
, struct connection
, INetworkConnectionCost_iface
);
1630 static HRESULT WINAPI
connection_cost_QueryInterface(
1631 INetworkConnectionCost
*iface
,
1635 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1636 return INetworkConnection_QueryInterface( &conn
->INetworkConnection_iface
, riid
, obj
);
1639 static ULONG WINAPI
connection_cost_AddRef(
1640 INetworkConnectionCost
*iface
)
1642 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1643 return INetworkConnection_AddRef( &conn
->INetworkConnection_iface
);
1646 static ULONG WINAPI
connection_cost_Release(
1647 INetworkConnectionCost
*iface
)
1649 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1650 return INetworkConnection_Release( &conn
->INetworkConnection_iface
);
1653 static HRESULT WINAPI
connection_cost_GetCost(
1654 INetworkConnectionCost
*iface
, DWORD
*pCost
)
1656 FIXME( "%p, %p\n", iface
, pCost
);
1658 if (!pCost
) return E_POINTER
;
1660 *pCost
= NLM_CONNECTION_COST_UNRESTRICTED
;
1664 static HRESULT WINAPI
connection_cost_GetDataPlanStatus(
1665 INetworkConnectionCost
*iface
, NLM_DATAPLAN_STATUS
*pDataPlanStatus
)
1667 struct connection
*conn
= impl_from_INetworkConnectionCost( iface
);
1669 FIXME( "%p, %p\n", iface
, pDataPlanStatus
);
1671 if (!pDataPlanStatus
) return E_POINTER
;
1673 memcpy( &pDataPlanStatus
->InterfaceGuid
, &conn
->id
, sizeof(conn
->id
) );
1674 pDataPlanStatus
->UsageData
.UsageInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1675 memset( &pDataPlanStatus
->UsageData
.LastSyncTime
, 0, sizeof(pDataPlanStatus
->UsageData
.LastSyncTime
) );
1676 pDataPlanStatus
->DataLimitInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1677 pDataPlanStatus
->InboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1678 pDataPlanStatus
->OutboundBandwidthInKbps
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1679 memset( &pDataPlanStatus
->NextBillingCycle
, 0, sizeof(pDataPlanStatus
->NextBillingCycle
) );
1680 pDataPlanStatus
->MaxTransferSizeInMegabytes
= NLM_UNKNOWN_DATAPLAN_STATUS
;
1681 pDataPlanStatus
->Reserved
= 0;
1686 static const INetworkConnectionCostVtbl connection_cost_vtbl
=
1688 connection_cost_QueryInterface
,
1689 connection_cost_AddRef
,
1690 connection_cost_Release
,
1691 connection_cost_GetCost
,
1692 connection_cost_GetDataPlanStatus
1695 static struct connection
*create_connection( const GUID
*id
)
1697 struct connection
*ret
;
1699 if (!(ret
= heap_alloc( sizeof(*ret
) ))) return NULL
;
1701 ret
->INetworkConnection_iface
.lpVtbl
= &connection_vtbl
;
1702 ret
->INetworkConnectionCost_iface
.lpVtbl
= &connection_cost_vtbl
;
1705 ret
->network
= NULL
;
1706 ret
->connected
= VARIANT_FALSE
;
1707 ret
->connected_to_internet
= VARIANT_FALSE
;
1708 list_init( &ret
->entry
);
1713 static void init_networks( struct list_manager
*mgr
)
1716 IP_ADAPTER_ADDRESSES
*buf
, *aa
;
1718 ULONG ret
, flags
= GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
|
1719 GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_INCLUDE_ALL_GATEWAYS
;
1721 list_init( &mgr
->networks
);
1722 list_init( &mgr
->connections
);
1724 ret
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, NULL
, &size
);
1725 if (ret
!= ERROR_BUFFER_OVERFLOW
) return;
1727 if (!(buf
= heap_alloc( size
))) return;
1728 if (GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, buf
, &size
))
1734 memset( &id
, 0, sizeof(id
) );
1735 for (aa
= buf
; aa
; aa
= aa
->Next
)
1737 struct network
*network
;
1738 struct connection
*connection
;
1740 id
.Data1
= aa
->u
.s
.IfIndex
;
1742 /* assume a one-to-one mapping between networks and connections */
1743 if (!(network
= create_network( &id
))) goto done
;
1744 if (!(connection
= create_connection( &id
)))
1746 INetwork_Release( &network
->INetwork_iface
);
1750 if (aa
->FirstUnicastAddress
)
1752 network
->connected
= VARIANT_TRUE
;
1753 connection
->connected
= VARIANT_TRUE
;
1755 if (aa
->FirstGatewayAddress
)
1757 network
->connected_to_internet
= VARIANT_TRUE
;
1758 connection
->connected_to_internet
= VARIANT_TRUE
;
1761 connection
->network
= &network
->INetwork_iface
;
1762 INetwork_AddRef( connection
->network
);
1764 list_add_tail( &mgr
->networks
, &network
->entry
);
1765 list_add_tail( &mgr
->connections
, &connection
->entry
);
1772 HRESULT
list_manager_create( void **obj
)
1774 struct list_manager
*mgr
;
1776 TRACE( "%p\n", obj
);
1778 if (!(mgr
= heap_alloc( sizeof(*mgr
) ))) return E_OUTOFMEMORY
;
1779 mgr
->INetworkListManager_iface
.lpVtbl
= &list_manager_vtbl
;
1780 mgr
->INetworkCostManager_iface
.lpVtbl
= &cost_manager_vtbl
;
1781 mgr
->IConnectionPointContainer_iface
.lpVtbl
= &cpc_vtbl
;
1782 init_networks( mgr
);
1785 connection_point_init( &mgr
->list_mgr_cp
, &IID_INetworkListManagerEvents
,
1786 &mgr
->IConnectionPointContainer_iface
);
1787 connection_point_init( &mgr
->cost_mgr_cp
, &IID_INetworkCostManagerEvents
,
1788 &mgr
->IConnectionPointContainer_iface
);
1789 connection_point_init( &mgr
->conn_mgr_cp
, &IID_INetworkConnectionEvents
,
1790 &mgr
->IConnectionPointContainer_iface
);
1791 connection_point_init( &mgr
->events_cp
, &IID_INetworkEvents
,
1792 &mgr
->IConnectionPointContainer_iface
);
1794 *obj
= &mgr
->INetworkListManager_iface
;
1795 TRACE( "returning iface %p\n", *obj
);