14#include <officecfg/Office/Impress.hxx>
16#include <com/sun/star/container/XNameAccess.hpp>
17#include <com/sun/star/container/XNameContainer.hpp>
18#include <com/sun/star/uno/Sequence.hxx>
19#include <com/sun/star/lang/XSingleServiceFactory.hpp>
26#include <osl/socket.hxx>
66RemoteServer::RemoteServer() :
67 Thread(
"RemoteServerThread" )
69 SAL_INFO(
"sdremote",
"Instantiated RemoteServer" );
78 SAL_INFO(
"sdremote",
"RemoteServer::execute called" );
79 osl::SocketAddr aAddr(
"0.0.0.0",
PORT );
96 SAL_INFO(
"sdremote",
"waiting on accept" );
97 if (
mSocket.acceptConnection( aSocket ) == osl_Socket_Error )
106 SAL_INFO(
"sdremote",
"shutting down RemoteServer" );
114 && aLine ==
"LO_SERVER_CLIENT_PAIR"
117 SAL_INFO(
"sdremote",
"client failed to send LO_SERVER_CLIENT_PAIR, ignoring" );
122 OString
aName( aLine );
129 OString aPin( aLine );
131 SocketAddr aClientAddr;
138 if ( ! pSocket->
readLine( aLine ) ) {
143 while ( aLine.getLength() > 0 );
146 std::shared_ptr< ClientInfoInternal > pClient =
147 std::make_shared<ClientInfoInternal>(
148 OStringToOUString(
aName, RTL_TEXTENCODING_UTF8 ),
149 pSocket, OStringToOUString( aPin, RTL_TEXTENCODING_UTF8 ) );
153 Reference< XNameAccess >
const xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get();
154 const Sequence< OUString > aNames = xConfig->getElementNames();
155 for (
const auto& rName : aNames )
157 if ( rName == pClient->mName )
159 Reference<XNameAccess> xSetItem( xConfig->getByName(rName), UNO_QUERY );
160 Any axPin(xSetItem->getByName(
"PIN"));
164 if ( sPin == pClient->mPin ) {
165 SAL_INFO(
"sdremote",
"client found on validated list -- connecting" );
173 SAL_INFO(
"sdremote",
"client not found on validated list" );
174 pSocket->
write(
"LO_SERVER_VALIDATING_PIN\n\n",
175 strlen(
"LO_SERVER_VALIDATING_PIN\n\n" ) );
190#ifdef ENABLE_SDREMOTE_BLUETOOTH
196 css::presentation::XSlideShowController > &rController )
203 rpCommunicator->presentationStarted( rController );
213 rpCommunicator->disposeListener();
229 SAL_INFO(
"sdremote",
"RemoteServer::getClients() called" );
230 std::vector< std::shared_ptr< ClientInfo > > aClients;
239 SAL_INFO(
"sdremote",
"No remote server instance => no remote clients" );
250 Reference< XNameAccess >
const xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get();
251 const Sequence< OUString > aNames = xConfig->getElementNames();
252 std::transform(aNames.begin(), aNames.end(), std::back_inserter(aClients),
253 [](
const OUString& rName) -> std::shared_ptr<ClientInfo> {
254 return std::make_shared<ClientInfo>(rName, true); });
261 SAL_INFO(
"sdremote",
"RemoteServer::connectClient called" );
272 if ( apClient->
mPin == aPin )
275 std::shared_ptr< ConfigurationChanges > aChanges = ConfigurationChanges::create();
276 Reference< XNameContainer >
const xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get( aChanges );
278 Reference<XSingleServiceFactory> xChildFactory (
280 Reference<XNameReplace> xChild( xChildFactory->createInstance(), UNO_QUERY);
285 Sequence< OUString > aNames = xConfig->getElementNames();
287 xConfig->replaceByName( apClient->
mName,
Any( xChild ) );
289 xConfig->insertByName( apClient->
mName,
Any( xChild ) );
290 aValue <<= apClient->
mPin;
291 xChild->replaceByName(
"PIN", aValue);
318 SAL_INFO(
"sdremote",
"RemoteServer::deauthoriseClient called" );
320 if ( !pClient->mbIsAlreadyAuthorised )
326 std::shared_ptr< ConfigurationChanges > aChanges = ConfigurationChanges::create();
327 Reference< XNameContainer >
const xConfig =
328 officecfg::Office::Impress::Misc::AuthorisedRemotes::get( aChanges );
330 xConfig->removeByName( pClient->mName );
334void SdDLL::RegisterRemotes()
336 SAL_INFO(
"sdremote",
"SdDLL::RegisterRemotes called" );
352 if ( !officecfg::Office::Impress::Misc::Start::EnableSdremote::get() )
363#ifdef ENABLE_SDREMOTE_BLUETOOTH
370#ifdef ENABLE_SDREMOTE_BLUETOOTH
#define PORT
The port for use for the main communication between LibO and remote control app.
static bool IsHeadlessModeEnabled()
static void restoreDiscoverable()
restore the state of discoverability from before ensureDiscoverable
static void setup(std::vector< Communicator * > *pCommunicators)
static void ensureDiscoverable()
ensure that Bluetooth discoverability is on
[A wrapper for an osl StreamSocket to allow reading lines.
virtual sal_Int32 write(const void *pBuffer, sal_uInt32 n) override
Write a number of bytes.
void getPeerAddr(osl::SocketAddr &)
virtual sal_Int32 readLine(OString &aLine) override
Blocks until a line is read.
Class used for communication with one single client, dealing with all tasks specific to this client.
static SD_DLLPUBLIC bool connectClient(const std::shared_ptr< ClientInfo > &pClient, std::u16string_view aPin)
static RemoteServer * spServer
void handleAcceptedConnection(BufferedStreamSocket *pSocket)
static SD_DLLPUBLIC void restoreDiscoverable()
restore the state of discoverability from before ensureDiscoverable
static void presentationStopped()
osl::AcceptorSocket mSocket
static ::std::vector< Communicator * > sCommunicators
static SD_DLLPUBLIC std::vector< std::shared_ptr< ClientInfo > > getClients()
static SD_DLLPUBLIC void deauthoriseClient(const std::shared_ptr< ClientInfo > &pClient)
::std::vector< std::shared_ptr< ClientInfoInternal > > mAvailableClients
static void removeCommunicator(Communicator const *pCommunicator)
virtual ~RemoteServer() override
static SD_DLLPUBLIC void ensureDiscoverable()
ensure that discoverability (eg. for Bluetooth) is enabled
static void presentationStarted(const css::uno::Reference< css::presentation::XSlideShowController > &rController)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
Used to keep track of clients that have attempted to connect, but haven't yet been approved.
ClientInfoInternal(const OUString &rName, BufferedStreamSocket *pSocket, OUString aPin)
BufferedStreamSocket * mpStreamSocket