18590a0fdSAndre Fischer /************************************************************** 28590a0fdSAndre Fischer * 38590a0fdSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 48590a0fdSAndre Fischer * or more contributor license agreements. See the NOTICE file 58590a0fdSAndre Fischer * distributed with this work for additional information 68590a0fdSAndre Fischer * regarding copyright ownership. The ASF licenses this file 78590a0fdSAndre Fischer * to you under the Apache License, Version 2.0 (the 88590a0fdSAndre Fischer * "License"); you may not use this file except in compliance 98590a0fdSAndre Fischer * with the License. You may obtain a copy of the License at 108590a0fdSAndre Fischer * 118590a0fdSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 128590a0fdSAndre Fischer * 138590a0fdSAndre Fischer * Unless required by applicable law or agreed to in writing, 148590a0fdSAndre Fischer * software distributed under the License is distributed on an 158590a0fdSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 168590a0fdSAndre Fischer * KIND, either express or implied. See the License for the 178590a0fdSAndre Fischer * specific language governing permissions and limitations 188590a0fdSAndre Fischer * under the License. 198590a0fdSAndre Fischer * 208590a0fdSAndre Fischer *************************************************************/ 218590a0fdSAndre Fischer 228590a0fdSAndre Fischer // MARKER(update_precomp.py): autogen include statement, do not remove 238590a0fdSAndre Fischer #include "precompiled_ucb.hxx" 248590a0fdSAndre Fischer 258590a0fdSAndre Fischer #include <rtl/ustring.hxx> 26*c1c10f68SAriel Constenla-Haile #include "DAVProperties.hxx" 27*c1c10f68SAriel Constenla-Haile #include "UCBDeadPropertyValue.hxx" 288590a0fdSAndre Fischer 29*c1c10f68SAriel Constenla-Haile #include "SerfPropPatchReqProcImpl.hxx" 30*c1c10f68SAriel Constenla-Haile #include "SerfTypes.hxx" 318590a0fdSAndre Fischer 328590a0fdSAndre Fischer namespace http_dav_ucp 338590a0fdSAndre Fischer { 348590a0fdSAndre Fischer 358590a0fdSAndre Fischer SerfPropPatchReqProcImpl::SerfPropPatchReqProcImpl( const char* inPath, 36e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders, 378590a0fdSAndre Fischer const std::vector< ProppatchValue > & inProperties ) 38e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders ) 398590a0fdSAndre Fischer , mpProperties( &inProperties ) 408590a0fdSAndre Fischer { 418590a0fdSAndre Fischer } 428590a0fdSAndre Fischer 438590a0fdSAndre Fischer SerfPropPatchReqProcImpl::~SerfPropPatchReqProcImpl() 448590a0fdSAndre Fischer { 458590a0fdSAndre Fischer } 468590a0fdSAndre Fischer 478590a0fdSAndre Fischer #define PROPPATCH_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propertyupdate xmlns=\"DAV:\">" 488590a0fdSAndre Fischer #define PROPPATCH_TRAILER "</propertyupdate>" 498590a0fdSAndre Fischer 508590a0fdSAndre Fischer serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) 518590a0fdSAndre Fischer { 528590a0fdSAndre Fischer serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest ); 538590a0fdSAndre Fischer 548590a0fdSAndre Fischer // body bucket 558590a0fdSAndre Fischer serf_bucket_t* body_bkt = 0; 568590a0fdSAndre Fischer rtl::OUString aBodyText; 578590a0fdSAndre Fischer { 588590a0fdSAndre Fischer // create and fill body bucket with properties to be set or removed 598590a0fdSAndre Fischer static const char* OpCodes[2] = { "set", "remove" }; 608590a0fdSAndre Fischer const int nPropCount = ( mpProperties != 0 ) 618590a0fdSAndre Fischer ? mpProperties->size() 628590a0fdSAndre Fischer : 0; 638590a0fdSAndre Fischer if ( nPropCount > 0 ) 648590a0fdSAndre Fischer { 658590a0fdSAndre Fischer // <*operation code*><prop> 668590a0fdSAndre Fischer ProppatchOperation lastOp = (*mpProperties)[ 0 ].operation; 678590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "<" ); 688590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[lastOp] ); 698590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "><prop>" ); 708590a0fdSAndre Fischer 718590a0fdSAndre Fischer SerfPropName thePropName; 728590a0fdSAndre Fischer for ( int n = 0; n < nPropCount; ++n ) 738590a0fdSAndre Fischer { 748590a0fdSAndre Fischer const ProppatchValue & rProperty = (*mpProperties)[ n ]; 758590a0fdSAndre Fischer // split fullname into namespace and name! 768590a0fdSAndre Fischer DAVProperties::createSerfPropName( rProperty.name, 778590a0fdSAndre Fischer thePropName ); 788590a0fdSAndre Fischer 798590a0fdSAndre Fischer if ( rProperty.operation != lastOp ) 808590a0fdSAndre Fischer { 818590a0fdSAndre Fischer // </prop></*last operation code*><*operation code><prop> 8256e989c2SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( "</prop></" ); 838590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[lastOp] ); 848590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "><" ); 858590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[rProperty.operation] ); 868590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "><prop>" ); 878590a0fdSAndre Fischer } 888590a0fdSAndre Fischer 898590a0fdSAndre Fischer // <*propname* xmlns="*propns*" 908590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "<" ); 918590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( thePropName.name ); 928590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( " xmlns=\"" ); 938590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( thePropName.nspace ); 948590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "\"" ); 958590a0fdSAndre Fischer 968590a0fdSAndre Fischer if ( rProperty.operation == PROPSET ) 978590a0fdSAndre Fischer { 988590a0fdSAndre Fischer // >*property value*</*propname*> 998590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( ">" ); 1008590a0fdSAndre Fischer 1018590a0fdSAndre Fischer rtl::OUString aStringValue; 1028590a0fdSAndre Fischer if ( DAVProperties::isUCBDeadProperty( thePropName ) ) 1038590a0fdSAndre Fischer { 1048590a0fdSAndre Fischer UCBDeadPropertyValue::toXML( rProperty.value, 1058590a0fdSAndre Fischer aStringValue ); 1068590a0fdSAndre Fischer } 1078590a0fdSAndre Fischer else 1088590a0fdSAndre Fischer { 1098590a0fdSAndre Fischer rProperty.value >>= aStringValue; 1108590a0fdSAndre Fischer } 1118590a0fdSAndre Fischer aBodyText += aStringValue; 1128590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "</" ); 1138590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( thePropName.name ); 1148590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( ">" ); 1158590a0fdSAndre Fischer } 1168590a0fdSAndre Fischer else 1178590a0fdSAndre Fischer { 1188590a0fdSAndre Fischer // /> 1198590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "/>" ); 1208590a0fdSAndre Fischer } 1218590a0fdSAndre Fischer 1228590a0fdSAndre Fischer lastOp = rProperty.operation; 1238590a0fdSAndre Fischer } 1248590a0fdSAndre Fischer 1258590a0fdSAndre Fischer // </prop></*last operation code*> 1268590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "</prop></" ); 1278590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[lastOp] ); 1288590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( ">" ); 1298590a0fdSAndre Fischer 1308590a0fdSAndre Fischer // add PropPatch xml header in front 1318590a0fdSAndre Fischer aBodyText = rtl::OUString::createFromAscii( PROPPATCH_HEADER ) + aBodyText; 1328590a0fdSAndre Fischer 1338590a0fdSAndre Fischer // add PropPatch xml trailer at end 1348590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( PROPPATCH_TRAILER ); 1358590a0fdSAndre Fischer 1368590a0fdSAndre Fischer body_bkt = SERF_BUCKET_SIMPLE_STRING( rtl::OUStringToOString( aBodyText, RTL_TEXTENCODING_UTF8 ), 1378590a0fdSAndre Fischer pSerfBucketAlloc ); 1388590a0fdSAndre Fischer } 1398590a0fdSAndre Fischer } 1408590a0fdSAndre Fischer 1418590a0fdSAndre Fischer // create serf request 1428590a0fdSAndre Fischer serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, 1438590a0fdSAndre Fischer "PROPPATCH", 1448590a0fdSAndre Fischer getPathStr(), 1458590a0fdSAndre Fischer body_bkt, 14625eaca47SOliver-Rainer Wittmann pSerfBucketAlloc ) ; 14710e20387SAndre Fischer handleChunkedEncoding(req_bkt, aBodyText.getLength()); 1488590a0fdSAndre Fischer 1498590a0fdSAndre Fischer // set request header fields 1508590a0fdSAndre Fischer serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); 15110e20387SAndre Fischer if (hdrs_bkt != NULL) 15210e20387SAndre Fischer { 153e9ff7e89SOliver-Rainer Wittmann // general header fields provided by caller 154e9ff7e89SOliver-Rainer Wittmann setRequestHeaders( hdrs_bkt ); 1558590a0fdSAndre Fischer 1568590a0fdSAndre Fischer // request specific header fields 1578590a0fdSAndre Fischer if ( body_bkt != 0 && aBodyText.getLength() > 0 ) 1588590a0fdSAndre Fischer { 159e9ff7e89SOliver-Rainer Wittmann serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" ); 16010e20387SAndre Fischer } 16110e20387SAndre Fischer } 16210e20387SAndre Fischer else 16310e20387SAndre Fischer { 16410e20387SAndre Fischer OSL_ASSERT("Headers Bucket missing"); 1658590a0fdSAndre Fischer } 1668590a0fdSAndre Fischer 1678590a0fdSAndre Fischer return req_bkt; 1688590a0fdSAndre Fischer } 1698590a0fdSAndre Fischer 17049989859SOliver-Rainer Wittmann void SerfPropPatchReqProcImpl::processChunkOfResponseData( const char* /*data*/, 17149989859SOliver-Rainer Wittmann apr_size_t /*len*/ ) 1728590a0fdSAndre Fischer { 17349989859SOliver-Rainer Wittmann // nothing to do; 1748590a0fdSAndre Fischer } 1758590a0fdSAndre Fischer 17649989859SOliver-Rainer Wittmann void SerfPropPatchReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ ) 1778590a0fdSAndre Fischer { 17849989859SOliver-Rainer Wittmann // nothing to do; 1798590a0fdSAndre Fischer } 1808590a0fdSAndre Fischer 1818590a0fdSAndre Fischer } // namespace http_dav_ucp 182