diff options
author | Ariel Constenla-Haile <arielch@apache.org> | 2013-03-24 12:21:32 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-27 20:25:38 +0100 |
commit | 7056e8ef89e938e38fc5b2b8a7493f0c79d5efd4 (patch) | |
tree | eccbebe77941201ef856be90d3c22e7668824ae6 /ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx | |
parent | 3c18e25efdbbc13be3a0c6ed354d5e7a46feb451 (diff) |
Resolves@ #i121926# fix malformed PROPFIND/PROPPATCH request body
(cherry picked from commit 3c83ceae5e4ff5afe20ea76aeaaae6303cdaec2d)
Conflicts:
ucb/source/ucp/webdav/SerfPropFindReqProcImpl.cxx
ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx
Change-Id: I13dab5fb80235e2ab968a1492c05bf579ba08d40
Diffstat (limited to 'ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx')
-rw-r--r-- | ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx | 77 |
1 files changed, 43 insertions, 34 deletions
diff --git a/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx b/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx index d504a6658a3d..c3e95b4a60d9 100644 --- a/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx +++ b/ucb/source/ucp/webdav/SerfPropPatchReqProcImpl.cxx @@ -18,6 +18,7 @@ */ #include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> #include "DAVProperties.hxx" #include "UCBDeadPropertyValue.hxx" @@ -48,20 +49,33 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_ // body bucket serf_bucket_t* body_bkt = 0; - OUString aBodyText; + OString aBodyText; { // 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 ) ? mpProperties->size() : 0; if ( nPropCount > 0 ) { + rtl::OUStringBuffer aBuffer; + // add PropPatch xml header in front + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPPATCH_HEADER )); + // <*operation code*><prop> + ProppatchOperation lastOp = (*mpProperties)[ 0 ].operation; - aBodyText += OUString::createFromAscii( "<" ); - aBodyText += OUString::createFromAscii( OpCodes[lastOp] ); - aBodyText += OUString::createFromAscii( "><prop>" ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<" )); + aBuffer.appendAscii( OpCode[lastOp].str, OpCode[lastOp].len ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "><prop>" )); SerfPropName thePropName; for ( int n = 0; n < nPropCount; ++n ) @@ -74,24 +88,24 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_ if ( rProperty.operation != lastOp ) { // </prop></*last operation code*><*operation code><prop> - aBodyText += OUString::createFromAscii( "</prop></" ); - aBodyText += OUString::createFromAscii( OpCodes[lastOp] ); - aBodyText += OUString::createFromAscii( "><" ); - aBodyText += OUString::createFromAscii( OpCodes[rProperty.operation] ); - aBodyText += OUString::createFromAscii( "><prop>" ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</prop></" )); + aBuffer.appendAscii( OpCode[lastOp].str, OpCode[lastOp].len ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "><" )); + aBuffer.appendAscii( OpCode[rProperty.operation].str, OpCode[rProperty.operation].len ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "><prop>" )); } // <*propname* xmlns="*propns*" - aBodyText += OUString::createFromAscii( "<" ); - aBodyText += OUString::createFromAscii( thePropName.name ); - aBodyText += OUString::createFromAscii( " xmlns=\"" ); - aBodyText += OUString::createFromAscii( thePropName.nspace ); - aBodyText += OUString::createFromAscii( "\"" ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<" )); + aBuffer.appendAscii( thePropName.name ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " xmlns=\"" )); + aBuffer.appendAscii( thePropName.nspace ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\"" )); if ( rProperty.operation == PROPSET ) { // >*property value*</*propname*> - aBodyText += OUString::createFromAscii( ">" ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( ">" )); OUString aStringValue; if ( DAVProperties::isUCBDeadProperty( thePropName ) ) @@ -103,37 +117,32 @@ serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_ { rProperty.value >>= aStringValue; } - aBodyText += aStringValue; - aBodyText += OUString::createFromAscii( "</" ); - aBodyText += OUString::createFromAscii( thePropName.name ); - aBodyText += OUString::createFromAscii( ">" ); + aBuffer.append( aStringValue ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</" )); + aBuffer.appendAscii( thePropName.name ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( ">" )); } else { // /> - aBodyText += OUString::createFromAscii( "/>" ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "/>" )); } lastOp = rProperty.operation; } // </prop></*last operation code*> - aBodyText += OUString::createFromAscii( "</prop></" ); - aBodyText += OUString::createFromAscii( OpCodes[lastOp] ); - aBodyText += OUString::createFromAscii( ">" ); - - // add PropPatch xml header in front - aBodyText = OUString::createFromAscii( PROPPATCH_HEADER ) + aBodyText; + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</prop></" )); + aBuffer.appendAscii( OpCode[lastOp].str, OpCode[lastOp].len ); + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( ">" )); // 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 ), - pSerfBucketAlloc ); - if ( useChunkedEncoding() ) - { - body_bkt = serf_bucket_chunk_create( body_bkt, pSerfBucketAlloc ); - } + aBodyText = rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ); + body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(), + aBodyText.getLength(), + pSerfBucketAlloc ); } } |