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 25*c1c10f68SAriel Constenla-Haile #include "SerfPropFindReqProcImpl.hxx" 26*c1c10f68SAriel Constenla-Haile #include "SerfTypes.hxx" 27*c1c10f68SAriel Constenla-Haile #include "DAVProperties.hxx" 288590a0fdSAndre Fischer 29*c1c10f68SAriel Constenla-Haile #include "webdavresponseparser.hxx" 308590a0fdSAndre Fischer #include <comphelper/seqstream.hxx> 318590a0fdSAndre Fischer 328590a0fdSAndre Fischer using namespace com::sun::star; 338590a0fdSAndre Fischer 348590a0fdSAndre Fischer namespace http_dav_ucp 358590a0fdSAndre Fischer { 368590a0fdSAndre Fischer 378590a0fdSAndre Fischer SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath, 38e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders, 398590a0fdSAndre Fischer const Depth inDepth, 408590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inPropNames, 418590a0fdSAndre Fischer std::vector< DAVResource > & ioResources ) 42e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders ) 438590a0fdSAndre Fischer , mDepthStr( 0 ) 448590a0fdSAndre Fischer , mpPropNames( &inPropNames ) 458590a0fdSAndre Fischer , mpResources( &ioResources ) 468590a0fdSAndre Fischer , mpResInfo( 0 ) 478590a0fdSAndre Fischer , mbOnlyPropertyNames( false ) 488590a0fdSAndre Fischer , xInputStream( new SerfInputStream() ) 498590a0fdSAndre Fischer { 508590a0fdSAndre Fischer init( inDepth ); 518590a0fdSAndre Fischer } 528590a0fdSAndre Fischer 538590a0fdSAndre Fischer SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath, 54e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders, 558590a0fdSAndre Fischer const Depth inDepth, 568590a0fdSAndre Fischer std::vector< DAVResourceInfo > & ioResInfo ) 57e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders ) 588590a0fdSAndre Fischer , mDepthStr( 0 ) 598590a0fdSAndre Fischer , mpPropNames( 0 ) 608590a0fdSAndre Fischer , mpResources( 0 ) 618590a0fdSAndre Fischer , mpResInfo( &ioResInfo ) 628590a0fdSAndre Fischer , mbOnlyPropertyNames( true ) 638590a0fdSAndre Fischer , xInputStream( new SerfInputStream() ) 648590a0fdSAndre Fischer { 658590a0fdSAndre Fischer init( inDepth ); 668590a0fdSAndre Fischer } 678590a0fdSAndre Fischer 688590a0fdSAndre Fischer void SerfPropFindReqProcImpl::init( const Depth inDepth ) 698590a0fdSAndre Fischer { 708590a0fdSAndre Fischer switch ( inDepth ) 718590a0fdSAndre Fischer { 728590a0fdSAndre Fischer case DAVZERO: 738590a0fdSAndre Fischer mDepthStr = "0"; 748590a0fdSAndre Fischer break; 758590a0fdSAndre Fischer case DAVONE: 768590a0fdSAndre Fischer mDepthStr = "1"; 778590a0fdSAndre Fischer break; 788590a0fdSAndre Fischer case DAVINFINITY: 798590a0fdSAndre Fischer mDepthStr = "infinity"; 808590a0fdSAndre Fischer break; 818590a0fdSAndre Fischer } 828590a0fdSAndre Fischer } 838590a0fdSAndre Fischer 848590a0fdSAndre Fischer SerfPropFindReqProcImpl::~SerfPropFindReqProcImpl() 858590a0fdSAndre Fischer { 868590a0fdSAndre Fischer } 878590a0fdSAndre Fischer 888590a0fdSAndre Fischer #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">" 898590a0fdSAndre Fischer #define PROPFIND_TRAILER "</propfind>" 908590a0fdSAndre Fischer 918590a0fdSAndre Fischer serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) 928590a0fdSAndre Fischer { 938590a0fdSAndre Fischer serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest ); 948590a0fdSAndre Fischer 958590a0fdSAndre Fischer // body bucket - certain properties OR all properties OR only property names 968590a0fdSAndre Fischer serf_bucket_t* body_bkt = 0; 97353980d1SOliver-Rainer Wittmann rtl::OUString aBodyText; 988590a0fdSAndre Fischer { 998590a0fdSAndre Fischer // create and fill body bucket with requested properties 1008590a0fdSAndre Fischer const int nPropCount = ( !mbOnlyPropertyNames && mpPropNames ) 1018590a0fdSAndre Fischer ? mpPropNames->size() 1028590a0fdSAndre Fischer : 0; 1038590a0fdSAndre Fischer if ( nPropCount > 0 ) 1048590a0fdSAndre Fischer { 1058590a0fdSAndre Fischer SerfPropName thePropName; 1068590a0fdSAndre Fischer for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ ) 1078590a0fdSAndre Fischer { 1088590a0fdSAndre Fischer // split fullname into namespace and name! 1098590a0fdSAndre Fischer DAVProperties::createSerfPropName( (*mpPropNames)[ theIndex ], 1108590a0fdSAndre Fischer thePropName ); 1118590a0fdSAndre Fischer 1128590a0fdSAndre Fischer /* <*propname* xmlns="*propns*" /> */ 113353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( "<" ); 114353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( thePropName.name ); 115353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( " xmlnx=\"" ); 116353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( thePropName.nspace ); 117353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( "\"/>" ); 1188590a0fdSAndre Fischer } 1198590a0fdSAndre Fischer 120353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( "<prop>" ) + 121353980d1SOliver-Rainer Wittmann aBodyText + 122353980d1SOliver-Rainer Wittmann rtl::OUString::createFromAscii( "</prop>" ); 1238590a0fdSAndre Fischer } 1248590a0fdSAndre Fischer else 1258590a0fdSAndre Fischer { 1268590a0fdSAndre Fischer if ( mbOnlyPropertyNames ) 1278590a0fdSAndre Fischer { 128353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( "<propname/>" ); 1298590a0fdSAndre Fischer } 1308590a0fdSAndre Fischer else 1318590a0fdSAndre Fischer { 132353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( "<allprop/>" ); 1338590a0fdSAndre Fischer } 1348590a0fdSAndre Fischer } 1358590a0fdSAndre Fischer 136353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( PROPFIND_HEADER ) + 137353980d1SOliver-Rainer Wittmann aBodyText + 138353980d1SOliver-Rainer Wittmann rtl::OUString::createFromAscii( PROPFIND_TRAILER ); 139353980d1SOliver-Rainer Wittmann body_bkt = SERF_BUCKET_SIMPLE_STRING( rtl::OUStringToOString( aBodyText, RTL_TEXTENCODING_UTF8 ), 1408590a0fdSAndre Fischer pSerfBucketAlloc ); 1418590a0fdSAndre Fischer } 1428590a0fdSAndre Fischer 1438590a0fdSAndre Fischer // create serf request 1448590a0fdSAndre Fischer serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, 1458590a0fdSAndre Fischer "PROPFIND", 1468590a0fdSAndre Fischer getPathStr(), 1478590a0fdSAndre Fischer body_bkt, 14825eaca47SOliver-Rainer Wittmann pSerfBucketAlloc ); 14910e20387SAndre Fischer handleChunkedEncoding(req_bkt, aBodyText.getLength()); 1508590a0fdSAndre Fischer 1518590a0fdSAndre Fischer // set request header fields 1528590a0fdSAndre Fischer serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); 15310e20387SAndre Fischer if (hdrs_bkt != NULL) 15410e20387SAndre Fischer { 155e9ff7e89SOliver-Rainer Wittmann // general header fields provided by caller 156e9ff7e89SOliver-Rainer Wittmann setRequestHeaders( hdrs_bkt ); 1578590a0fdSAndre Fischer 1588590a0fdSAndre Fischer // request specific header fields 159e9ff7e89SOliver-Rainer Wittmann serf_bucket_headers_set( hdrs_bkt, "Depth", mDepthStr ); 16010e20387SAndre Fischer if (hdrs_bkt!=NULL && body_bkt != 0 && aBodyText.getLength() > 0 ) 161353980d1SOliver-Rainer Wittmann { 162e9ff7e89SOliver-Rainer Wittmann serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" ); 16310e20387SAndre Fischer } 16410e20387SAndre Fischer } 16510e20387SAndre Fischer else 16610e20387SAndre Fischer { 16710e20387SAndre Fischer OSL_ASSERT("Headers Bucket missing"); 168353980d1SOliver-Rainer Wittmann } 1698590a0fdSAndre Fischer 1708590a0fdSAndre Fischer return req_bkt; 1718590a0fdSAndre Fischer } 1728590a0fdSAndre Fischer 17349989859SOliver-Rainer Wittmann void SerfPropFindReqProcImpl::processChunkOfResponseData( const char* data, 17449989859SOliver-Rainer Wittmann apr_size_t len ) 1758590a0fdSAndre Fischer { 17649989859SOliver-Rainer Wittmann if ( xInputStream.is() ) 1778590a0fdSAndre Fischer { 1788590a0fdSAndre Fischer xInputStream->AddToStream( data, len ); 1798590a0fdSAndre Fischer } 18049989859SOliver-Rainer Wittmann } 1818590a0fdSAndre Fischer 18249989859SOliver-Rainer Wittmann void SerfPropFindReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ ) 1838590a0fdSAndre Fischer { 1848590a0fdSAndre Fischer if ( mbOnlyPropertyNames ) 1858590a0fdSAndre Fischer { 1868590a0fdSAndre Fischer const std::vector< DAVResourceInfo > rResInfo( parseWebDAVPropNameResponse( xInputStream.get() ) ); 1878590a0fdSAndre Fischer *mpResInfo = rResInfo; 1888590a0fdSAndre Fischer } 1898590a0fdSAndre Fischer else 1908590a0fdSAndre Fischer { 1918590a0fdSAndre Fischer const std::vector< DAVResource > rResources( parseWebDAVPropFindResponse( xInputStream.get() ) ); 1928590a0fdSAndre Fischer *mpResources = rResources; 1938590a0fdSAndre Fischer } 1948590a0fdSAndre Fischer } 1958590a0fdSAndre Fischer 1968590a0fdSAndre Fischer } // namespace http_dav_ucp 197