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> 268590a0fdSAndre Fischer #include <DAVProperties.hxx> 278590a0fdSAndre Fischer #include <UCBDeadPropertyValue.hxx> 288590a0fdSAndre Fischer 298590a0fdSAndre Fischer #include <SerfPropPatchReqProcImpl.hxx> 308590a0fdSAndre Fischer #include <SerfTypes.hxx> 318590a0fdSAndre Fischer 328590a0fdSAndre Fischer namespace http_dav_ucp 338590a0fdSAndre Fischer { 348590a0fdSAndre Fischer 358590a0fdSAndre Fischer SerfPropPatchReqProcImpl::SerfPropPatchReqProcImpl( const char* inPath, 368590a0fdSAndre Fischer const std::vector< ProppatchValue > & inProperties ) 378590a0fdSAndre Fischer : SerfRequestProcessorImpl( inPath ) 388590a0fdSAndre Fischer , mpProperties( &inProperties ) 398590a0fdSAndre Fischer { 408590a0fdSAndre Fischer } 418590a0fdSAndre Fischer 428590a0fdSAndre Fischer SerfPropPatchReqProcImpl::~SerfPropPatchReqProcImpl() 438590a0fdSAndre Fischer { 448590a0fdSAndre Fischer } 458590a0fdSAndre Fischer 468590a0fdSAndre Fischer #define PROPPATCH_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propertyupdate xmlns=\"DAV:\">" 478590a0fdSAndre Fischer #define PROPPATCH_TRAILER "</propertyupdate>" 488590a0fdSAndre Fischer 498590a0fdSAndre Fischer serf_bucket_t * SerfPropPatchReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) 508590a0fdSAndre Fischer { 518590a0fdSAndre Fischer serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest ); 528590a0fdSAndre Fischer 538590a0fdSAndre Fischer // body bucket 548590a0fdSAndre Fischer serf_bucket_t* body_bkt = 0; 558590a0fdSAndre Fischer rtl::OUString aBodyText; 568590a0fdSAndre Fischer { 578590a0fdSAndre Fischer // create and fill body bucket with properties to be set or removed 588590a0fdSAndre Fischer static const char* OpCodes[2] = { "set", "remove" }; 598590a0fdSAndre Fischer const int nPropCount = ( mpProperties != 0 ) 608590a0fdSAndre Fischer ? mpProperties->size() 618590a0fdSAndre Fischer : 0; 628590a0fdSAndre Fischer if ( nPropCount > 0 ) 638590a0fdSAndre Fischer { 648590a0fdSAndre Fischer // <*operation code*><prop> 658590a0fdSAndre Fischer ProppatchOperation lastOp = (*mpProperties)[ 0 ].operation; 668590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "<" ); 678590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[lastOp] ); 688590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "><prop>" ); 698590a0fdSAndre Fischer 708590a0fdSAndre Fischer SerfPropName thePropName; 718590a0fdSAndre Fischer for ( int n = 0; n < nPropCount; ++n ) 728590a0fdSAndre Fischer { 738590a0fdSAndre Fischer const ProppatchValue & rProperty = (*mpProperties)[ n ]; 748590a0fdSAndre Fischer // split fullname into namespace and name! 758590a0fdSAndre Fischer DAVProperties::createSerfPropName( rProperty.name, 768590a0fdSAndre Fischer thePropName ); 778590a0fdSAndre Fischer 788590a0fdSAndre Fischer if ( rProperty.operation != lastOp ) 798590a0fdSAndre Fischer { 808590a0fdSAndre Fischer // </prop></*last operation code*><*operation code><prop> 81*25eaca47SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( "</prop></" 828590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[lastOp] ); 838590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "><" ); 848590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[rProperty.operation] ); 858590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "><prop>" ); 868590a0fdSAndre Fischer } 878590a0fdSAndre Fischer 888590a0fdSAndre Fischer // <*propname* xmlns="*propns*" 898590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "<" ); 908590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( thePropName.name ); 918590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( " xmlns=\"" ); 928590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( thePropName.nspace ); 938590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "\"" ); 948590a0fdSAndre Fischer 958590a0fdSAndre Fischer if ( rProperty.operation == PROPSET ) 968590a0fdSAndre Fischer { 978590a0fdSAndre Fischer // >*property value*</*propname*> 988590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( ">" ); 998590a0fdSAndre Fischer 1008590a0fdSAndre Fischer rtl::OUString aStringValue; 1018590a0fdSAndre Fischer if ( DAVProperties::isUCBDeadProperty( thePropName ) ) 1028590a0fdSAndre Fischer { 1038590a0fdSAndre Fischer UCBDeadPropertyValue::toXML( rProperty.value, 1048590a0fdSAndre Fischer aStringValue ); 1058590a0fdSAndre Fischer } 1068590a0fdSAndre Fischer else 1078590a0fdSAndre Fischer { 1088590a0fdSAndre Fischer rProperty.value >>= aStringValue; 1098590a0fdSAndre Fischer } 1108590a0fdSAndre Fischer aBodyText += aStringValue; 1118590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "</" ); 1128590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( thePropName.name ); 1138590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( ">" ); 1148590a0fdSAndre Fischer } 1158590a0fdSAndre Fischer else 1168590a0fdSAndre Fischer { 1178590a0fdSAndre Fischer // /> 1188590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "/>" ); 1198590a0fdSAndre Fischer } 1208590a0fdSAndre Fischer 1218590a0fdSAndre Fischer lastOp = rProperty.operation; 1228590a0fdSAndre Fischer } 1238590a0fdSAndre Fischer 1248590a0fdSAndre Fischer // </prop></*last operation code*> 1258590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( "</prop></" ); 1268590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( OpCodes[lastOp] ); 1278590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( ">" ); 1288590a0fdSAndre Fischer 1298590a0fdSAndre Fischer // add PropPatch xml header in front 1308590a0fdSAndre Fischer aBodyText = rtl::OUString::createFromAscii( PROPPATCH_HEADER ) + aBodyText; 1318590a0fdSAndre Fischer 1328590a0fdSAndre Fischer // add PropPatch xml trailer at end 1338590a0fdSAndre Fischer aBodyText += rtl::OUString::createFromAscii( PROPPATCH_TRAILER ); 1348590a0fdSAndre Fischer 1358590a0fdSAndre Fischer body_bkt = SERF_BUCKET_SIMPLE_STRING( rtl::OUStringToOString( aBodyText, RTL_TEXTENCODING_UTF8 ), 1368590a0fdSAndre Fischer pSerfBucketAlloc ); 1378590a0fdSAndre Fischer } 1388590a0fdSAndre Fischer } 1398590a0fdSAndre Fischer 1408590a0fdSAndre Fischer // create serf request 1418590a0fdSAndre Fischer serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, 1428590a0fdSAndre Fischer "PROPPATCH", 1438590a0fdSAndre Fischer getPathStr(), 1448590a0fdSAndre Fischer body_bkt, 145*25eaca47SOliver-Rainer Wittmann pSerfBucketAlloc ) ; 1468590a0fdSAndre Fischer 1478590a0fdSAndre Fischer // TODO - correct header data 1488590a0fdSAndre Fischer // set request header fields 1498590a0fdSAndre Fischer serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); 1508590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "User-Agent", "www.openoffice.org/ucb/" ); 1518590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "Accept-Encoding", "gzip"); 1528590a0fdSAndre Fischer 1538590a0fdSAndre Fischer // request specific header fields 1548590a0fdSAndre Fischer if ( body_bkt != 0 && aBodyText.getLength() > 0 ) 1558590a0fdSAndre Fischer { 1568590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "Content-Type", "application/xml" ); 1578590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "Content-Length", 1588590a0fdSAndre Fischer rtl::OUStringToOString( rtl::OUString::valueOf( aBodyText.getLength() ), RTL_TEXTENCODING_UTF8 ) ); 1598590a0fdSAndre Fischer } 1608590a0fdSAndre Fischer 1618590a0fdSAndre Fischer return req_bkt; 1628590a0fdSAndre Fischer } 1638590a0fdSAndre Fischer 1648590a0fdSAndre Fischer 1658590a0fdSAndre Fischer bool SerfPropPatchReqProcImpl::processSerfResponseBucket( serf_request_t * /*inSerfRequest*/, 1668590a0fdSAndre Fischer serf_bucket_t * inSerfResponseBucket, 1678590a0fdSAndre Fischer apr_pool_t * /*inAprPool*/, 1688590a0fdSAndre Fischer apr_status_t & outStatus ) 1698590a0fdSAndre Fischer { 1708590a0fdSAndre Fischer const char* data; 1718590a0fdSAndre Fischer apr_size_t len; 1728590a0fdSAndre Fischer 1738590a0fdSAndre Fischer while (1) { 1748590a0fdSAndre Fischer outStatus = serf_bucket_read(inSerfResponseBucket, 2048, &data, &len); 1758590a0fdSAndre Fischer if (SERF_BUCKET_READ_ERROR(outStatus)) 1768590a0fdSAndre Fischer { 1778590a0fdSAndre Fischer return true; 1788590a0fdSAndre Fischer } 1798590a0fdSAndre Fischer 1808590a0fdSAndre Fischer /* are we done yet? */ 1818590a0fdSAndre Fischer if (APR_STATUS_IS_EOF(outStatus)) 1828590a0fdSAndre Fischer { 1838590a0fdSAndre Fischer outStatus = APR_EOF; 1848590a0fdSAndre Fischer return true; 1858590a0fdSAndre Fischer } 1868590a0fdSAndre Fischer 1878590a0fdSAndre Fischer /* have we drained the response so far? */ 1888590a0fdSAndre Fischer if ( APR_STATUS_IS_EAGAIN( outStatus ) ) 1898590a0fdSAndre Fischer { 1908590a0fdSAndre Fischer return false; 1918590a0fdSAndre Fischer } 1928590a0fdSAndre Fischer } 1938590a0fdSAndre Fischer 1948590a0fdSAndre Fischer /* NOTREACHED */ 1958590a0fdSAndre Fischer return true; 1968590a0fdSAndre Fischer } 1978590a0fdSAndre Fischer 1988590a0fdSAndre Fischer } // namespace http_dav_ucp 199