Kaydet (Commit) 5ac1f17e authored tarafından Miklos Vajna's avatar Miklos Vajna

xmlsecurity: just two bools are fine, no need for bitfield complexity

Change-Id: I3e28ef5646ff39b0e3e8ed8962bfacf5b79176a7
Reviewed-on: https://gerrit.libreoffice.org/60069Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
üst e55afba0
...@@ -28,14 +28,8 @@ ...@@ -28,14 +28,8 @@
#include <libxml/uri.h> #include <libxml/uri.h>
#include <xmlsec-wrapper.h> #include <xmlsec-wrapper.h>
#define XMLSTREAMIO_INITIALIZED 0x01 static bool g_bInputCallbacksEnabled = false;
#define XMLSTREAMIO_REGISTERED 0x02 static bool g_bInputCallbacksRegistered = false;
/* Global variables */
/*-
* Enable stream I/O or not.
*/
static char enableXmlStreamIO = 0x00 ;
static css::uno::Reference< css::xml::crypto::XUriBinding > m_xUriBinding ; static css::uno::Reference< css::xml::crypto::XUriBinding > m_xUriBinding ;
...@@ -44,8 +38,8 @@ int xmlStreamMatch( const char* uri ) ...@@ -44,8 +38,8 @@ int xmlStreamMatch( const char* uri )
{ {
css::uno::Reference< css::io::XInputStream > xInputStream ; css::uno::Reference< css::io::XInputStream > xInputStream ;
if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) && if (g_bInputCallbacksEnabled && g_bInputCallbacksRegistered)
( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) { {
if( uri == nullptr || !m_xUriBinding.is() ) if( uri == nullptr || !m_xUriBinding.is() )
return 0 ; return 0 ;
//XMLSec first unescapes the uri and calls this function. For example, we pass the Uri //XMLSec first unescapes the uri and calls this function. For example, we pass the Uri
...@@ -76,8 +70,8 @@ void* xmlStreamOpen( const char* uri ) ...@@ -76,8 +70,8 @@ void* xmlStreamOpen( const char* uri )
{ {
css::uno::Reference< css::io::XInputStream > xInputStream ; css::uno::Reference< css::io::XInputStream > xInputStream ;
if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) && if (g_bInputCallbacksEnabled && g_bInputCallbacksRegistered)
( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) { {
if( uri == nullptr || !m_xUriBinding.is() ) if( uri == nullptr || !m_xUriBinding.is() )
return nullptr ; return nullptr ;
...@@ -113,8 +107,8 @@ int xmlStreamRead( void* context, char* buffer, int len ) ...@@ -113,8 +107,8 @@ int xmlStreamRead( void* context, char* buffer, int len )
css::uno::Sequence< sal_Int8 > outSeqs( len ) ; css::uno::Sequence< sal_Int8 > outSeqs( len ) ;
numbers = 0 ; numbers = 0 ;
if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) && if (g_bInputCallbacksEnabled && g_bInputCallbacksRegistered)
( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) { {
if( context != nullptr ) { if( context != nullptr ) {
xInputStream = static_cast<css::io::XInputStream*>(context); xInputStream = static_cast<css::io::XInputStream*>(context);
if( !xInputStream.is() ) if( !xInputStream.is() )
...@@ -133,8 +127,8 @@ int xmlStreamRead( void* context, char* buffer, int len ) ...@@ -133,8 +127,8 @@ int xmlStreamRead( void* context, char* buffer, int len )
extern "C" extern "C"
int xmlStreamClose( void * context ) int xmlStreamClose( void * context )
{ {
if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) && if (g_bInputCallbacksEnabled && g_bInputCallbacksRegistered)
( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) { {
if( context != nullptr ) { if( context != nullptr ) {
css::io::XInputStream* pInputStream ; css::io::XInputStream* pInputStream ;
pInputStream = static_cast<css::io::XInputStream*>(context); pInputStream = static_cast<css::io::XInputStream*>(context);
...@@ -147,8 +141,8 @@ int xmlStreamClose( void * context ) ...@@ -147,8 +141,8 @@ int xmlStreamClose( void * context )
XSECXMLSEC_DLLPUBLIC int xmlEnableStreamInputCallbacks() XSECXMLSEC_DLLPUBLIC int xmlEnableStreamInputCallbacks()
{ {
if (!g_bInputCallbacksEnabled)
if( !( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) ) { {
//Register the callbacks into xmlSec //Register the callbacks into xmlSec
//In order to make the xmlsec io finding the callbacks firstly, //In order to make the xmlsec io finding the callbacks firstly,
//I put the callbacks at the very beginning. //I put the callbacks at the very beginning.
...@@ -197,7 +191,7 @@ XSECXMLSEC_DLLPUBLIC int xmlEnableStreamInputCallbacks() ...@@ -197,7 +191,7 @@ XSECXMLSEC_DLLPUBLIC int xmlEnableStreamInputCallbacks()
} }
} }
enableXmlStreamIO |= XMLSTREAMIO_INITIALIZED ; g_bInputCallbacksEnabled = true;
} }
return 0 ; return 0 ;
...@@ -206,14 +200,14 @@ XSECXMLSEC_DLLPUBLIC int xmlEnableStreamInputCallbacks() ...@@ -206,14 +200,14 @@ XSECXMLSEC_DLLPUBLIC int xmlEnableStreamInputCallbacks()
XSECXMLSEC_DLLPUBLIC int xmlRegisterStreamInputCallbacks( XSECXMLSEC_DLLPUBLIC int xmlRegisterStreamInputCallbacks(
css::uno::Reference< css::xml::crypto::XUriBinding > const & aUriBinding css::uno::Reference< css::xml::crypto::XUriBinding > const & aUriBinding
) { ) {
if( !( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) ) { if (!g_bInputCallbacksEnabled)
{
if( xmlEnableStreamInputCallbacks() < 0 ) if( xmlEnableStreamInputCallbacks() < 0 )
return -1 ; return -1 ;
} }
if( !( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) { if (!g_bInputCallbacksRegistered)
enableXmlStreamIO |= XMLSTREAMIO_REGISTERED ; g_bInputCallbacksRegistered = true;
}
m_xUriBinding = aUriBinding ; m_xUriBinding = aUriBinding ;
...@@ -222,12 +216,13 @@ XSECXMLSEC_DLLPUBLIC int xmlRegisterStreamInputCallbacks( ...@@ -222,12 +216,13 @@ XSECXMLSEC_DLLPUBLIC int xmlRegisterStreamInputCallbacks(
XSECXMLSEC_DLLPUBLIC int xmlUnregisterStreamInputCallbacks() XSECXMLSEC_DLLPUBLIC int xmlUnregisterStreamInputCallbacks()
{ {
if( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) { if (g_bInputCallbacksRegistered)
{
//Clear the uri-stream binding //Clear the uri-stream binding
m_xUriBinding.clear() ; m_xUriBinding.clear() ;
//disable the registered flag //disable the registered flag
enableXmlStreamIO &= ~XMLSTREAMIO_REGISTERED ; g_bInputCallbacksRegistered = false;
} }
return 0 ; return 0 ;
...@@ -235,7 +230,7 @@ XSECXMLSEC_DLLPUBLIC int xmlUnregisterStreamInputCallbacks() ...@@ -235,7 +230,7 @@ XSECXMLSEC_DLLPUBLIC int xmlUnregisterStreamInputCallbacks()
XSECXMLSEC_DLLPUBLIC void xmlDisableStreamInputCallbacks() { XSECXMLSEC_DLLPUBLIC void xmlDisableStreamInputCallbacks() {
xmlUnregisterStreamInputCallbacks() ; xmlUnregisterStreamInputCallbacks() ;
enableXmlStreamIO &= ~XMLSTREAMIO_INITIALIZED ; g_bInputCallbacksEnabled = false;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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