Origin is constantly checking the connections status, which produces a lot of fixme's. To get rid of this, improve the existing implementation and lower the log-level from fixme to trace. For now we announce only IPV4 connection status, since we have to extend the structures for IPV6.
Since we actually have used a similar functionality at three different places. To get rid of this we introduce a new helper function which returns us the status of a network object. This is then used at all occurrences.
We also drop the status flags from the connection structure, since the status of a connection is equal to the status of the attached network object. This way we avoid code/data duplication. Instead we query the info directly from the attached network using the newly added function mentioned above.
Finally we rework the code, which loops over all network objects to determine the best available connection.
Signed-off-by: Soeren Grunewald soeren.grunewald@gmx.net --- dlls/netprofm/list.c | 60 +++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 14 deletions(-)
diff --git a/dlls/netprofm/list.c b/dlls/netprofm/list.c index f6823f09cf..40a3710365 100644 --- a/dlls/netprofm/list.c +++ b/dlls/netprofm/list.c @@ -62,8 +62,6 @@ struct connection struct list entry; GUID id; INetwork *network; - VARIANT_BOOL connected_to_internet; - VARIANT_BOOL connected; };
struct connection_point @@ -477,13 +475,26 @@ static HRESULT WINAPI network_get_IsConnected( return S_OK; }
+static NLM_CONNECTIVITY connectivitystate_from_network( struct network *network ) +{ + if ( network->connected_to_internet ) + return NLM_CONNECTIVITY_IPV4_INTERNET; + + if ( network->connected ) + return NLM_CONNECTIVITY_IPV4_SUBNET; + + return NLM_CONNECTIVITY_DISCONNECTED; +} + static HRESULT WINAPI network_GetConnectivity( INetwork *iface, NLM_CONNECTIVITY *pConnectivity ) { - FIXME( "%p, %p\n", iface, pConnectivity ); + struct network *network = impl_from_INetwork( iface ); + + TRACE( "%p, %p\n", iface, pConnectivity );
- *pConnectivity = NLM_CONNECTIVITY_IPV4_INTERNET; + *pConnectivity = connectivitystate_from_network( network ); return S_OK; }
@@ -1328,9 +1339,29 @@ static HRESULT WINAPI list_manager_GetConnectivity( INetworkListManager *iface, NLM_CONNECTIVITY *pConnectivity ) { - FIXME( "%p, %p\n", iface, pConnectivity ); + struct list_manager *mgr = impl_from_INetworkListManager( iface ); + struct network *network; + + NLM_CONNECTIVITY best = NLM_CONNECTIVITY_DISCONNECTED; + NLM_CONNECTIVITY state;
- *pConnectivity = NLM_CONNECTIVITY_IPV4_INTERNET; + TRACE( "%p, %p\n", iface, pConnectivity ); + + LIST_FOR_EACH_ENTRY( network, &mgr->networks, struct network, entry ) + { + state = connectivitystate_from_network( network ); + if ( state == NLM_CONNECTIVITY_IPV4_INTERNET ) + { + best = state; + break; + } + if ( state == NLM_CONNECTIVITY_IPV4_SUBNET ) + { + best = state; + } + } + + *pConnectivity = best; return S_OK; }
@@ -1538,10 +1569,11 @@ static HRESULT WINAPI connection_get_IsConnectedToInternet( VARIANT_BOOL *pbIsConnected ) { struct connection *connection = impl_from_INetworkConnection( iface ); + struct network *network = impl_from_INetwork( connection->network );
TRACE( "%p, %p\n", iface, pbIsConnected );
- *pbIsConnected = connection->connected_to_internet; + *pbIsConnected = network->connected_to_internet; return S_OK; }
@@ -1550,10 +1582,11 @@ static HRESULT WINAPI connection_get_IsConnected( VARIANT_BOOL *pbIsConnected ) { struct connection *connection = impl_from_INetworkConnection( iface ); + struct network *network = impl_from_INetwork( connection->network );
TRACE( "%p, %p\n", iface, pbIsConnected );
- *pbIsConnected = connection->connected; + *pbIsConnected = network->connected; return S_OK; }
@@ -1561,9 +1594,12 @@ static HRESULT WINAPI connection_GetConnectivity( INetworkConnection *iface, NLM_CONNECTIVITY *pConnectivity ) { - FIXME( "%p, %p\n", iface, pConnectivity ); + struct connection *connection = impl_from_INetworkConnection( iface ); + struct network *network = impl_from_INetwork( connection->network );
- *pConnectivity = NLM_CONNECTIVITY_IPV4_INTERNET; + TRACE( "%p, %p\n", iface, pConnectivity ); + + *pConnectivity = connectivitystate_from_network( network ); return S_OK; }
@@ -1701,8 +1737,6 @@ static struct connection *create_connection( const GUID *id ) ret->refs = 1; ret->id = *id; ret->network = NULL; - ret->connected = VARIANT_FALSE; - ret->connected_to_internet = VARIANT_FALSE; list_init( &ret->entry );
return ret; @@ -1748,12 +1782,10 @@ static void init_networks( struct list_manager *mgr ) if (aa->FirstUnicastAddress) { network->connected = VARIANT_TRUE; - connection->connected = VARIANT_TRUE; } if (aa->FirstGatewayAddress) { network->connected_to_internet = VARIANT_TRUE; - connection->connected_to_internet = VARIANT_TRUE; }
connection->network = &network->INetwork_iface; -- 2.20.1