diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2012-01-16 12:47:36 +0100 |
---|---|---|
committer | Thomas Arnhold <thomas@arnhold.org> | 2012-01-16 12:55:29 +0100 |
commit | d799ac1320fb11439566a8a6c8215cfb3db10a00 (patch) | |
tree | ca683d2558b4f6464734c42e9ae614651b642c35 /vcl | |
parent | a18123fb97e7c69a7fac6724aaa3a8e2440dae98 (diff) |
Revert "Remove unused SalDisplay::IsLocal"
This reverts commit e9202ffeccdf6f669184f3f869d2e5b121bea9f3.
Conflicts:
vcl/inc/unx/saldisp.hxx
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/unx/saldisp.hxx | 6 | ||||
-rw-r--r-- | vcl/unx/generic/app/saldisp.cxx | 120 |
2 files changed, 126 insertions, 0 deletions
diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx index 23d54bd39fa1..d8ee2ec1a4c5 100644 --- a/vcl/inc/unx/saldisp.hxx +++ b/vcl/inc/unx/saldisp.hxx @@ -305,6 +305,10 @@ protected: srv_vendor_t meServerVendor; SalWM eWindowManager_; + sal_Bool bLocal_; // Server==Client? Init + // in SalDisplay::IsLocal() + sal_Bool mbLocalIsValid; // bLocal_ is valid ? + // until x bytes XLIB_Cursor aPointerCache_[POINTER_COUNT]; @@ -371,6 +375,8 @@ public: XLIB_Cursor GetPointer( int ePointerStyle ); virtual int CaptureMouse( SalFrame *pCapture ); + sal_Bool IsLocal(); + void Remove( XEvent *pEvent ); virtual ScreenData *initScreen( SalX11Screen nXScreen ) const; const ScreenData& getDataForScreen( SalX11Screen nXScreen ) const diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx index a8eac644d29e..23ff906c0330 100644 --- a/vcl/unx/generic/app/saldisp.cxx +++ b/vcl/unx/generic/app/saldisp.cxx @@ -227,6 +227,122 @@ static sal_Bool sal_GetVisualInfo( Display *pDisplay, XID nVID, XVisualInfo &rVI } // --------------------------------------------------------------------------- + +// check wether displaystring is in format N.M or N. or just N +// with N and M beeing natural numbers +static sal_Bool +sal_IsDisplayNumber( const char *pDisplayString ) +{ + if ( ! isdigit(*pDisplayString) ) + return sal_False; + while ( isdigit(*(++pDisplayString)) ) + ; /* do nothing */ + + if ( *pDisplayString == '.' ) + { + while ( isdigit(*(++pDisplayString)) ) + ; /* do nothing */ + } + + return (*pDisplayString == '\0'); +} + +// check whether host1 and host2 point to the same ip address +static sal_Bool +sal_EqualHosts( const OUString& Host1, const OUString& Host2) +{ + oslSocketAddr pHostAddr1; + oslSocketAddr pHostAddr2; + sal_Bool bEqualAddress = sal_False; + + if ( Host1.toChar() >= '0' && Host1.toChar() <= '9' ) + pHostAddr1 = osl_createInetSocketAddr( Host1.pData, 0 ); + else + pHostAddr1 = osl_resolveHostname( Host1.pData ); + + if ( Host2.toChar() >= '0' && Host2.toChar() <= '9' ) + pHostAddr2 = osl_createInetSocketAddr( Host2.pData, 0 ); + else + pHostAddr2 = osl_resolveHostname( Host2.pData ); + + if( pHostAddr1 && pHostAddr2 ) + bEqualAddress = osl_isEqualSocketAddr( pHostAddr1, pHostAddr2 ) ? sal_True : sal_False; + + if( pHostAddr1 ) + osl_destroySocketAddr( pHostAddr1 ); + if( pHostAddr2 ) + osl_destroySocketAddr( pHostAddr2 ); + + return bEqualAddress; +} + +static sal_Bool +sal_IsLocalDisplay( Display *pDisplay ) +{ + const char *pDisplayString = DisplayString( pDisplay ); + + // no string, no idea + if ( pDisplayString == NULL || pDisplayString[ 0 ] == '\0') + return sal_False; + + // check for ":x.y" + if ( pDisplayString[ 0 ] == ':' ) + return sal_IsDisplayNumber( pDisplayString + 1 ); + + // check for fixed token which all mean localhost:x.y + const char pLocal[] = "localhost:"; + const int nLocalLen = sizeof(pLocal) - 1; + if ( strncmp(pDisplayString, pLocal, nLocalLen) == 0 ) + return sal_IsDisplayNumber( pDisplayString + nLocalLen ); + + const char pUnix[] = "unix:"; + const int nUnixLen = sizeof(pUnix) - 1; + if ( strncmp(pDisplayString, pUnix, nUnixLen) == 0 ) + return sal_IsDisplayNumber( pDisplayString + nUnixLen ); + + const char pLoopback[] = "127.0.0.1:"; + const int nLoopbackLen= sizeof(pLoopback) - 1; + if ( strncmp(pDisplayString, pLoopback, nLoopbackLen) == 0 ) + return sal_IsDisplayNumber( pDisplayString + nLoopbackLen ); + + // compare local hostname to displaystring, both may be ip address or + // hostname + sal_Bool bEqual = sal_False; + char *pDisplayHost = strdup( pDisplayString ); + char *pPtr = strrchr( pDisplayHost, ':' ); + + if( pPtr != NULL ) + { + const OUString& rLocalHostname( GetGenericData()->GetHostname() ); + if( rLocalHostname.getLength() ) + { + *pPtr = '\0'; + OUString aDisplayHostname( pDisplayHost, strlen( pDisplayHost ), osl_getThreadTextEncoding() ); + bEqual = sal_EqualHosts( rLocalHostname, aDisplayHostname ); + bEqual = bEqual && sal_IsDisplayNumber( pPtr + 1 ); + } + } + free( pDisplayHost ); + + return bEqual; +} + +// --------------------------------------------------------------------------- +// IsLocal means soffice is running on the same host as the xserver +// since it is not called very often and sal_IsLocalDisplay() is relative +// expensive bLocal_ is initialized on first call + +sal_Bool SalDisplay::IsLocal() +{ + if ( ! mbLocalIsValid ) + { + bLocal_ = sal_IsLocalDisplay( pDisp_ ); + mbLocalIsValid = sal_True; + } + return (sal_Bool)bLocal_; +} + +// --------------------------------------------------------------------------- extern "C" srv_vendor_t sal_GetServerVendor( Display *p_display ) { @@ -701,6 +817,10 @@ void SalDisplay::Init() SetServerVendor(); X11SalBitmap::ImplCreateCache(); + bLocal_ = sal_False; /* dont care, initialize later by + calling SalDisplay::IsLocal() */ + mbLocalIsValid = sal_False; /* bLocal_ is not yet initialized */ + // - - - - - - - - - - Synchronize - - - - - - - - - - - - - if( getenv( "SAL_SYNCHRONIZE" ) ) XSynchronize( pDisp_, True ); |