Kaydet (Commit) 510da291 authored tarafından Caolán McNamara's avatar Caolán McNamara

forced to make certain neon api calls thread-safe due to cups

rhbz#637738 libgcrypt that's been initialized already by cups to be
non-threadsafe is therefore then also non-threadsafe. neon uses
libgcrypt. So in the (as this is the usual circumstance) case that
cups is initialized before neon, then libgcrypt is not threadsafe
even though neon attempt to initialize it as such.
üst 5175ae0f
...@@ -156,6 +156,8 @@ extern "C" void NHR_ResponseHeaderCatcher( void * userdata, ...@@ -156,6 +156,8 @@ extern "C" void NHR_ResponseHeaderCatcher( void * userdata,
// Constructor // Constructor
// ------------------------------------------------------------------- // -------------------------------------------------------------------
extern osl::Mutex aGlobalNeonMutex;
NeonHeadRequest::NeonHeadRequest( HttpSession* inSession, NeonHeadRequest::NeonHeadRequest( HttpSession* inSession,
const rtl::OUString & inPath, const rtl::OUString & inPath,
const std::vector< ::rtl::OUString > & const std::vector< ::rtl::OUString > &
...@@ -179,7 +181,10 @@ NeonHeadRequest::NeonHeadRequest( HttpSession* inSession, ...@@ -179,7 +181,10 @@ NeonHeadRequest::NeonHeadRequest( HttpSession* inSession,
ne_add_response_header_catcher( req, NHR_ResponseHeaderCatcher, &aCtx ); ne_add_response_header_catcher( req, NHR_ResponseHeaderCatcher, &aCtx );
#endif #endif
{
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
nError = ne_request_dispatch( req ); nError = ne_request_dispatch( req );
}
#if NEON_VERSION >= 0x0250 #if NEON_VERSION >= 0x0250
process_headers(req, ioResource, inHeaderNames); process_headers(req, ioResource, inHeaderNames);
......
...@@ -618,7 +618,12 @@ extern "C" void NeonSession_PreSendRequest( ne_request * req, ...@@ -618,7 +618,12 @@ extern "C" void NeonSession_PreSendRequest( ne_request * req,
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// static members! // static members!
bool NeonSession::m_bGlobalsInited = false; bool NeonSession::m_bGlobalsInited = false;
osl::Mutex NeonSession::m_aGlobalMutex; //See https://bugzilla.redhat.com/show_bug.cgi?id=544619#c4
//neon is threadsafe, but uses gnutls which is only thread-safe
//if initialized to be thread-safe. cups, unfortunately, generally
//initializes it first, and as non-thread-safe, leaving the entire
//stack unsafe
osl::Mutex aGlobalNeonMutex;
NeonLockStore NeonSession::m_aNeonLockStore; NeonLockStore NeonSession::m_aNeonLockStore;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -647,7 +652,10 @@ NeonSession::~NeonSession( ) ...@@ -647,7 +652,10 @@ NeonSession::~NeonSession( )
{ {
if ( m_pHttpSession ) if ( m_pHttpSession )
{ {
{
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
ne_session_destroy( m_pHttpSession ); ne_session_destroy( m_pHttpSession );
}
m_pHttpSession = 0; m_pHttpSession = 0;
} }
delete static_cast< RequestDataMap * >( m_pRequestData ); delete static_cast< RequestDataMap * >( m_pRequestData );
...@@ -673,11 +681,7 @@ void NeonSession::Init() ...@@ -673,11 +681,7 @@ void NeonSession::Init()
if ( m_pHttpSession == 0 ) if ( m_pHttpSession == 0 )
{ {
// Ensure that Neon sockets are initialized // Ensure that Neon sockets are initialized
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
// --> tkr #151111# crashed if copy and pasted pictures from the internet
// ne_sock_init() was executed by two threads at the same time.
osl::Guard< osl::Mutex > theGlobalGuard( m_aGlobalMutex );
// <--
if ( !m_bGlobalsInited ) if ( !m_bGlobalsInited )
{ {
if ( ne_sock_init() != 0 ) if ( ne_sock_init() != 0 )
...@@ -726,7 +730,10 @@ void NeonSession::Init() ...@@ -726,7 +730,10 @@ void NeonSession::Init()
m_nProxyPort = rProxyCfg.nPort; m_nProxyPort = rProxyCfg.nPort;
// new session needed, destroy old first // new session needed, destroy old first
{
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
ne_session_destroy( m_pHttpSession ); ne_session_destroy( m_pHttpSession );
}
m_pHttpSession = 0; m_pHttpSession = 0;
bCreateNewSession = true; bCreateNewSession = true;
} }
...@@ -739,14 +746,15 @@ void NeonSession::Init() ...@@ -739,14 +746,15 @@ void NeonSession::Init()
// currently (0.22.0) neon does not allow to pass the user info // currently (0.22.0) neon does not allow to pass the user info
// to the session // to the session
{
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
m_pHttpSession = ne_session_create( m_pHttpSession = ne_session_create(
rtl::OUStringToOString( m_aScheme, rtl::OUStringToOString( m_aScheme, RTL_TEXTENCODING_UTF8 ).getStr(),
RTL_TEXTENCODING_UTF8 ).getStr(),
/* theUri.GetUserInfo(), /* theUri.GetUserInfo(),
@@@ for FTP via HTTP proxy, but not supported by Neon */ @@@ for FTP via HTTP proxy, but not supported by Neon */
rtl::OUStringToOString( m_aHostName, rtl::OUStringToOString( m_aHostName, RTL_TEXTENCODING_UTF8 ).getStr(),
RTL_TEXTENCODING_UTF8 ).getStr(),
m_nPort ); m_nPort );
}
if ( m_pHttpSession == 0 ) if ( m_pHttpSession == 0 )
throw DAVException( DAVException::DAV_SESSION_CREATE, throw DAVException( DAVException::DAV_SESSION_CREATE,
...@@ -1638,12 +1646,11 @@ bool NeonSession::UNLOCK( NeonLock * pLock ) ...@@ -1638,12 +1646,11 @@ bool NeonSession::UNLOCK( NeonLock * pLock )
void NeonSession::abort() void NeonSession::abort()
throw ( DAVException ) throw ( DAVException )
{ {
// 11.11.09 (tkr): The following code lines causing crashes if if ( m_pHttpSession )
// closing a ongoing connection. It turned out that this existing {
// solution doesn't work in multi-threading environments. osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
// So I disabled them in 3.2. . Issue #73893# should fix it in OOo 3.3. ne_close_connection( m_pHttpSession );
//if ( m_pHttpSession ) }
// ne_close_connection( m_pHttpSession );
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -1934,7 +1941,10 @@ int NeonSession::GET( ne_session * sess, ...@@ -1934,7 +1941,10 @@ int NeonSession::GET( ne_session * sess,
ne_decompress * dc ne_decompress * dc
= ne_decompress_reader( req, ne_accept_2xx, reader, userdata ); = ne_decompress_reader( req, ne_accept_2xx, reader, userdata );
{
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
ret = ne_request_dispatch( req ); ret = ne_request_dispatch( req );
}
#if NEON_VERSION >= 0x0250 #if NEON_VERSION >= 0x0250
if ( getheaders ) if ( getheaders )
...@@ -1974,7 +1984,10 @@ int NeonSession::PUT( ne_session * sess, ...@@ -1974,7 +1984,10 @@ int NeonSession::PUT( ne_session * sess,
ne_set_request_body_buffer( req, buffer, size ); ne_set_request_body_buffer( req, buffer, size );
{
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
ret = ne_request_dispatch( req ); ret = ne_request_dispatch( req );
}
if ( ret == NE_OK && ne_get_status( req )->klass != 2 ) if ( ret == NE_OK && ne_get_status( req )->klass != 2 )
ret = NE_ERROR; ret = NE_ERROR;
...@@ -2019,7 +2032,10 @@ int NeonSession::POST( ne_session * sess, ...@@ -2019,7 +2032,10 @@ int NeonSession::POST( ne_session * sess,
ne_set_request_body_buffer( req, buffer, strlen( buffer ) ); ne_set_request_body_buffer( req, buffer, strlen( buffer ) );
{
osl::Guard< osl::Mutex > theGlobalGuard( aGlobalNeonMutex );
ret = ne_request_dispatch( req ); ret = ne_request_dispatch( req );
}
//if ( ctx.error ) //if ( ctx.error )
// ret = NE_ERROR; // ret = NE_ERROR;
......
...@@ -66,7 +66,6 @@ private: ...@@ -66,7 +66,6 @@ private:
DAVRequestEnvironment m_aEnv; DAVRequestEnvironment m_aEnv;
static bool m_bGlobalsInited; static bool m_bGlobalsInited;
static osl::Mutex m_aGlobalMutex;
static NeonLockStore m_aNeonLockStore; static NeonLockStore m_aNeonLockStore;
protected: protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment