From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed by Just Cause 4. --- .../network_information.c | 53 ++++++++++++++++--- .../tests/connectivity.c | 7 --- 2 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/dlls/windows.networking.connectivity/network_information.c b/dlls/windows.networking.connectivity/network_information.c index 2800e4d0043..dce35d9017d 100644 --- a/dlls/windows.networking.connectivity/network_information.c +++ b/dlls/windows.networking.connectivity/network_information.c @@ -123,7 +123,7 @@ struct connection_profile IConnectionProfile IConnectionProfile_iface; LONG ref;
- NetworkConnectivityLevel network_connectivity_level; + INetworkListManager *network_list_manager; };
static inline struct connection_profile *impl_from_IConnectionProfile( IConnectionProfile *iface ) @@ -167,7 +167,11 @@ static ULONG WINAPI connection_profile_Release( IConnectionProfile *iface )
TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref );
- if (!ref) free( impl ); + if (!ref) + { + INetworkListManager_Release( impl->network_list_manager ); + free( impl ); + } return ref; }
@@ -197,8 +201,27 @@ static HRESULT WINAPI connection_profile_get_ProfileName( IConnectionProfile *if
static HRESULT WINAPI connection_profile_GetNetworkConnectivityLevel( IConnectionProfile *iface, NetworkConnectivityLevel *value ) { - FIXME( "iface %p, value %p stub!\n", iface, value ); - return E_NOTIMPL; + struct connection_profile *impl = impl_from_IConnectionProfile( iface ); + NetworkConnectivityLevel network_connectivity_level; + NLM_CONNECTIVITY connectivity = 0xdeadbeef; + HRESULT hr; + + TRACE( "iface %p, value %p\n", iface, value ); + + if (!value) return E_POINTER; + if (FAILED(hr = INetworkListManager_GetConnectivity( impl->network_list_manager, &connectivity ))) return hr; + + if (connectivity == NLM_CONNECTIVITY_DISCONNECTED) + network_connectivity_level = NetworkConnectivityLevel_None; + else if (connectivity & ( NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET )) + network_connectivity_level = NetworkConnectivityLevel_InternetAccess; + else if (connectivity & ( NLM_CONNECTIVITY_IPV4_LOCALNETWORK | NLM_CONNECTIVITY_IPV6_LOCALNETWORK | NLM_CONNECTIVITY_IPV4_NOTRAFFIC | NLM_CONNECTIVITY_IPV6_NOTRAFFIC )) + network_connectivity_level = NetworkConnectivityLevel_LocalAccess; + else + network_connectivity_level = NetworkConnectivityLevel_ConstrainedInternetAccess; + + *value = network_connectivity_level; + return S_OK; }
static HRESULT WINAPI connection_profile_GetNetworkNames( IConnectionProfile *iface, IVectorView_HSTRING **value ) @@ -274,20 +297,36 @@ static HRESULT WINAPI network_information_statics_GetConnectionProfiles( INetwor
static HRESULT WINAPI network_information_statics_GetInternetConnectionProfile( INetworkInformationStatics *iface, IConnectionProfile **value ) { + NetworkConnectivityLevel network_connectivity_level = 0xdeadbeef; + INetworkListManager *network_list_manager = NULL; struct connection_profile *impl; + HRESULT hr;
TRACE( "iface %p, value %p\n", iface, value );
*value = NULL; - if (!(impl = calloc( 1, sizeof( *impl ) ))) return E_OUTOFMEMORY; + if (FAILED(hr = CoCreateInstance( &CLSID_NetworkListManager, NULL, CLSCTX_INPROC_SERVER, &IID_INetworkListManager, (void **)&network_list_manager ))) return hr; + if (!(impl = calloc( 1, sizeof( *impl ) ))) + { + INetworkListManager_Release( network_list_manager ); + return E_OUTOFMEMORY; + }
impl->IConnectionProfile_iface.lpVtbl = &connection_profile_vtbl; impl->ref = 1; - impl->network_connectivity_level = NetworkConnectivityLevel_None; + impl->network_list_manager = network_list_manager; + + hr = IConnectionProfile_GetNetworkConnectivityLevel( &impl->IConnectionProfile_iface, &network_connectivity_level ); + if (FAILED(hr) || network_connectivity_level == NetworkConnectivityLevel_None) + { + free( impl ); + INetworkListManager_Release( network_list_manager ); + return hr; + }
*value = &impl->IConnectionProfile_iface; TRACE( "created IConnectionProfile %p.\n", *value ); - return S_OK; + return hr; }
static HRESULT WINAPI network_information_statics_GetLanIdentifiers( INetworkInformationStatics *iface, IVectorView_LanIdentifier **value ) diff --git a/dlls/windows.networking.connectivity/tests/connectivity.c b/dlls/windows.networking.connectivity/tests/connectivity.c index 8cb719c9e20..cbeda9ade0f 100644 --- a/dlls/windows.networking.connectivity/tests/connectivity.c +++ b/dlls/windows.networking.connectivity/tests/connectivity.c @@ -103,13 +103,10 @@ static void test_NetworkInformationStatics(void) }
hr = IConnectionProfile_GetNetworkConnectivityLevel( connection_profile, NULL ); - todo_wine ok( hr == E_POINTER, "got hr %#lx.\n", hr ); network_connectivity_level = 0xdeadbeef; hr = IConnectionProfile_GetNetworkConnectivityLevel( connection_profile, &network_connectivity_level ); - todo_wine ok( hr == S_OK || hr == 0x8007023e /* Internet disconnect after GetInternetConnectionProfile */, "got hr %#lx.\n", hr ); - todo_wine ok( network_connectivity_level != 0xdeadbeef, "failed to get network_connectivity_level\n" );
connectivity = 0xdeadbeef; @@ -119,16 +116,12 @@ static void test_NetworkInformationStatics(void) trace( "GetConnectivity: %08x\n", connectivity );
if (connectivity == NLM_CONNECTIVITY_DISCONNECTED) - todo_wine ok( network_connectivity_level == NetworkConnectivityLevel_None, "got network_connectivity_level %d.\n", network_connectivity_level ); else if (connectivity & ( NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET )) - todo_wine ok( network_connectivity_level == NetworkConnectivityLevel_InternetAccess, "got network_connectivity_level %d.\n", network_connectivity_level ); else if (connectivity & ( NLM_CONNECTIVITY_IPV4_LOCALNETWORK | NLM_CONNECTIVITY_IPV6_LOCALNETWORK | NLM_CONNECTIVITY_IPV4_NOTRAFFIC | NLM_CONNECTIVITY_IPV6_NOTRAFFIC )) - todo_wine ok( network_connectivity_level == NetworkConnectivityLevel_LocalAccess, "got network_connectivity_level %d.\n", network_connectivity_level ); else - todo_wine ok( network_connectivity_level == NetworkConnectivityLevel_ConstrainedInternetAccess, "got network_connectivity_level %d.\n", network_connectivity_level );
ref = IConnectionProfile_Release( connection_profile );