Kaydet (Commit) 7056e8ef authored tarafından Ariel Constenla-Haile's avatar Ariel Constenla-Haile Kaydeden (comit) Caolán McNamara

Resolves@ #i121926# fix malformed PROPFIND/PROPPATCH request body

(cherry picked from commit 3c83ceae)

Conflicts:
	ucb/source/ucp/webdav/SerfPropFindReqProcImpl.cxx
	ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx

Change-Id: I13dab5fb80235e2ab968a1492c05bf579ba08d40
üst 3c18e25e
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "webdavresponseparser.hxx" #include "webdavresponseparser.hxx"
#include <comphelper/seqstream.hxx> #include <comphelper/seqstream.hxx>
#include <rtl/ustrbuf.hxx>
using namespace com::sun::star; using namespace com::sun::star;
...@@ -89,14 +91,20 @@ serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t ...@@ -89,14 +91,20 @@ serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t
// body bucket - certain properties OR all properties OR only property names // body bucket - certain properties OR all properties OR only property names
serf_bucket_t* body_bkt = 0; serf_bucket_t* body_bkt = 0;
OUString aBodyText; OString aBodyText;
{ {
// TODO is it really needed a Unicode string buffer?
// All properties and property names aren't supposed to be ASCII?
rtl::OUStringBuffer aBuffer;
aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPFIND_HEADER ));
// create and fill body bucket with requested properties // create and fill body bucket with requested properties
const int nPropCount = ( !mbOnlyPropertyNames && mpPropNames ) const int nPropCount = ( !mbOnlyPropertyNames && mpPropNames )
? mpPropNames->size() ? mpPropNames->size()
: 0; : 0;
if ( nPropCount > 0 ) if ( nPropCount > 0 )
{ {
aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<prop>" ) );
SerfPropName thePropName; SerfPropName thePropName;
for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ ) for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ )
{ {
...@@ -120,23 +128,19 @@ serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t ...@@ -120,23 +128,19 @@ serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t
{ {
if ( mbOnlyPropertyNames ) if ( mbOnlyPropertyNames )
{ {
aBodyText = OUString::createFromAscii( "<propname/>" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<propname/>" ));
} }
else else
{ {
aBodyText = OUString::createFromAscii( "<allprop/>" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<allprop/>" ));
} }
} }
aBodyText = OUString::createFromAscii( PROPFIND_HEADER ) + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPFIND_TRAILER ));
aBodyText + aBodyText = rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
OUString::createFromAscii( PROPFIND_TRAILER ); body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(),
body_bkt = SERF_BUCKET_SIMPLE_STRING( OUStringToOString( aBodyText, RTL_TEXTENCODING_UTF8 ), aBodyText.getLength(),
pSerfBucketAlloc ); pSerfBucketAlloc );
if ( useChunkedEncoding() )
{
body_bkt = serf_bucket_chunk_create( body_bkt, pSerfBucketAlloc );
}
} }
// create serf request // create serf request
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include "DAVProperties.hxx" #include "DAVProperties.hxx"
#include "UCBDeadPropertyValue.hxx" #include "UCBDeadPropertyValue.hxx"
...@@ -48,20 +49,33 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_ ...@@ -48,20 +49,33 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_
// body bucket // body bucket
serf_bucket_t* body_bkt = 0; serf_bucket_t* body_bkt = 0;
OUString aBodyText; OString aBodyText;
{ {
// create and fill body bucket with properties to be set or removed // create and fill body bucket with properties to be set or removed
static const char* OpCodes[2] = { "set", "remove" }; static const struct
{
const char *str;
sal_Int32 len;
}
OpCode [] = {
{ RTL_CONSTASCII_STRINGPARAM( "set" ) },
{ RTL_CONSTASCII_STRINGPARAM( "remove" ) }
};
const int nPropCount = ( mpProperties != 0 ) const int nPropCount = ( mpProperties != 0 )
? mpProperties->size() ? mpProperties->size()
: 0; : 0;
if ( nPropCount > 0 ) if ( nPropCount > 0 )
{ {
rtl::OUStringBuffer aBuffer;
// add PropPatch xml header in front
aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPPATCH_HEADER ));
// <*operation code*><prop> // <*operation code*><prop>
ProppatchOperation lastOp = (*mpProperties)[ 0 ].operation; ProppatchOperation lastOp = (*mpProperties)[ 0 ].operation;
aBodyText += OUString::createFromAscii( "<" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<" ));
aBodyText += OUString::createFromAscii( OpCodes[lastOp] ); aBuffer.appendAscii( OpCode[lastOp].str, OpCode[lastOp].len );
aBodyText += OUString::createFromAscii( "><prop>" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "><prop>" ));
SerfPropName thePropName; SerfPropName thePropName;
for ( int n = 0; n < nPropCount; ++n ) for ( int n = 0; n < nPropCount; ++n )
...@@ -74,24 +88,24 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_ ...@@ -74,24 +88,24 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_
if ( rProperty.operation != lastOp ) if ( rProperty.operation != lastOp )
{ {
// </prop></*last operation code*><*operation code><prop> // </prop></*last operation code*><*operation code><prop>
aBodyText += OUString::createFromAscii( "</prop></" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</prop></" ));
aBodyText += OUString::createFromAscii( OpCodes[lastOp] ); aBuffer.appendAscii( OpCode[lastOp].str, OpCode[lastOp].len );
aBodyText += OUString::createFromAscii( "><" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "><" ));
aBodyText += OUString::createFromAscii( OpCodes[rProperty.operation] ); aBuffer.appendAscii( OpCode[rProperty.operation].str, OpCode[rProperty.operation].len );
aBodyText += OUString::createFromAscii( "><prop>" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "><prop>" ));
} }
// <*propname* xmlns="*propns*" // <*propname* xmlns="*propns*"
aBodyText += OUString::createFromAscii( "<" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<" ));
aBodyText += OUString::createFromAscii( thePropName.name ); aBuffer.appendAscii( thePropName.name );
aBodyText += OUString::createFromAscii( " xmlns=\"" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " xmlns=\"" ));
aBodyText += OUString::createFromAscii( thePropName.nspace ); aBuffer.appendAscii( thePropName.nspace );
aBodyText += OUString::createFromAscii( "\"" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\"" ));
if ( rProperty.operation == PROPSET ) if ( rProperty.operation == PROPSET )
{ {
// >*property value*</*propname*> // >*property value*</*propname*>
aBodyText += OUString::createFromAscii( ">" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( ">" ));
OUString aStringValue; OUString aStringValue;
if ( DAVProperties::isUCBDeadProperty( thePropName ) ) if ( DAVProperties::isUCBDeadProperty( thePropName ) )
...@@ -103,37 +117,32 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_ ...@@ -103,37 +117,32 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_
{ {
rProperty.value >>= aStringValue; rProperty.value >>= aStringValue;
} }
aBodyText += aStringValue; aBuffer.append( aStringValue );
aBodyText += OUString::createFromAscii( "</" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</" ));
aBodyText += OUString::createFromAscii( thePropName.name ); aBuffer.appendAscii( thePropName.name );
aBodyText += OUString::createFromAscii( ">" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( ">" ));
} }
else else
{ {
// /> // />
aBodyText += OUString::createFromAscii( "/>" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "/>" ));
} }
lastOp = rProperty.operation; lastOp = rProperty.operation;
} }
// </prop></*last operation code*> // </prop></*last operation code*>
aBodyText += OUString::createFromAscii( "</prop></" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</prop></" ));
aBodyText += OUString::createFromAscii( OpCodes[lastOp] ); aBuffer.appendAscii( OpCode[lastOp].str, OpCode[lastOp].len );
aBodyText += OUString::createFromAscii( ">" ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( ">" ));
// add PropPatch xml header in front
aBodyText = OUString::createFromAscii( PROPPATCH_HEADER ) + aBodyText;
// add PropPatch xml trailer at end // add PropPatch xml trailer at end
aBodyText += OUString::createFromAscii( PROPPATCH_TRAILER ); aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPPATCH_TRAILER ));
body_bkt = SERF_BUCKET_SIMPLE_STRING( OUStringToOString( aBodyText, RTL_TEXTENCODING_UTF8 ), aBodyText = rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
pSerfBucketAlloc ); body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(),
if ( useChunkedEncoding() ) aBodyText.getLength(),
{ pSerfBucketAlloc );
body_bkt = serf_bucket_chunk_create( body_bkt, pSerfBucketAlloc );
}
} }
} }
......
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