summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej@ahunt.org>2021-07-16 18:58:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-07-17 11:50:08 +0200
commit137744a25b26d86b9be16a107b3bd011f6ab4b07 (patch)
treea419a11c10eddf831ff1aaf9631987f9b73e9e3c /sd
parentd6078e02832d13054e6552c6e20277fd1f3e83f6 (diff)
sdremote: introduce early return to improve handleAcceptedConnection
This should make it easier to understand the handshake sequence. Change-Id: If06e98cdfe7295ed00efae61815a8696a90e9533 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119085 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r--sd/source/ui/remotecontrol/Server.cxx100
1 files changed, 51 insertions, 49 deletions
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index e3576bacd52e..83a80e9916df 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -112,67 +112,69 @@ void RemoteServer::execute()
void RemoteServer::handleAcceptedConnection( BufferedStreamSocket *pSocket )
{
OString aLine;
- if ( pSocket->readLine( aLine)
- && aLine == "LO_SERVER_CLIENT_PAIR"
- && pSocket->readLine( aLine ) )
+ if ( ! ( pSocket->readLine( aLine)
+ && aLine == "LO_SERVER_CLIENT_PAIR"
+ && pSocket->readLine( aLine ) ) )
{
- OString aName( aLine );
+ SAL_INFO( "sdremote", "client failed to send LO_SERVER_CLIENT_PAIR, ignoring" );
+ delete pSocket;
+ return;
+ }
- if ( ! pSocket->readLine( aLine ) )
- {
+ OString aName( aLine );
+
+ if ( ! pSocket->readLine( aLine ) )
+ {
+ delete pSocket;
+ return;
+ }
+ OString aPin( aLine );
+
+ SocketAddr aClientAddr;
+ pSocket->getPeerAddr( aClientAddr );
+
+ do
+ {
+ // Read off any additional non-empty lines
+ // We know that we at least have the empty termination line to read.
+ if ( ! pSocket->readLine( aLine ) ) {
delete pSocket;
return;
}
- OString aPin( aLine );
+ }
+ while ( aLine.getLength() > 0 );
- SocketAddr aClientAddr;
- pSocket->getPeerAddr( aClientAddr );
+ MutexGuard aGuard( sDataMutex );
+ std::shared_ptr< ClientInfoInternal > pClient =
+ std::make_shared<ClientInfoInternal>(
+ OStringToOUString( aName, RTL_TEXTENCODING_UTF8 ),
+ pSocket, OStringToOUString( aPin, RTL_TEXTENCODING_UTF8 ) );
+ mAvailableClients.push_back( pClient );
- do
+ // Check if we already have this server.
+ Reference< XNameAccess > const xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get();
+ const Sequence< OUString > aNames = xConfig->getElementNames();
+ for ( const auto& rName : aNames )
+ {
+ if ( rName == pClient->mName )
{
- // Read off any additional non-empty lines
- // We know that we at least have the empty termination line to read.
- if ( ! pSocket->readLine( aLine ) ) {
- delete pSocket;
+ Reference<XNameAccess> xSetItem( xConfig->getByName(rName), UNO_QUERY );
+ Any axPin(xSetItem->getByName("PIN"));
+ OUString sPin;
+ axPin >>= sPin;
+
+ if ( sPin == pClient->mPin ) {
+ SAL_INFO( "sdremote", "client found on validated list -- connecting" );
+ connectClient( pClient, sPin );
return;
}
}
- while ( aLine.getLength() > 0 );
-
- MutexGuard aGuard( sDataMutex );
- std::shared_ptr< ClientInfoInternal > pClient =
- std::make_shared<ClientInfoInternal>(
- OStringToOUString( aName, RTL_TEXTENCODING_UTF8 ),
- pSocket, OStringToOUString( aPin, RTL_TEXTENCODING_UTF8 ) );
- mAvailableClients.push_back( pClient );
-
- // Check if we already have this server.
- Reference< XNameAccess > const xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get();
- const Sequence< OUString > aNames = xConfig->getElementNames();
- for ( const auto& rName : aNames )
- {
- if ( rName == pClient->mName )
- {
- Reference<XNameAccess> xSetItem( xConfig->getByName(rName), UNO_QUERY );
- Any axPin(xSetItem->getByName("PIN"));
- OUString sPin;
- axPin >>= sPin;
-
- if ( sPin == pClient->mPin ) {
- SAL_INFO( "sdremote", "client found on validated list -- connecting" );
- connectClient( pClient, sPin );
- return;
- }
- }
- }
- // Pin not found so inform the client.
- SAL_INFO( "sdremote", "client not found on validated list" );
- pSocket->write( "LO_SERVER_VALIDATING_PIN\n\n",
- strlen( "LO_SERVER_VALIDATING_PIN\n\n" ) );
- } else {
- SAL_INFO( "sdremote", "client failed to send LO_SERVER_CLIENT_PAIR, ignoring" );
- delete pSocket;
}
+
+ // Pin not found so inform the client.
+ SAL_INFO( "sdremote", "client not found on validated list" );
+ pSocket->write( "LO_SERVER_VALIDATING_PIN\n\n",
+ strlen( "LO_SERVER_VALIDATING_PIN\n\n" ) );
}
RemoteServer *sd::RemoteServer::spServer = nullptr;