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 25c1c10f68SAriel Constenla-Haile #include "SerfPropFindReqProcImpl.hxx" 26c1c10f68SAriel Constenla-Haile #include "SerfTypes.hxx" 27c1c10f68SAriel Constenla-Haile #include "DAVProperties.hxx" 288590a0fdSAndre Fischer 29c1c10f68SAriel Constenla-Haile #include "webdavresponseparser.hxx" 308590a0fdSAndre Fischer #include <comphelper/seqstream.hxx> 31*efc9b74fSAriel Constenla-Haile #include <rtl/ustrbuf.hxx> 32*efc9b74fSAriel Constenla-Haile 338590a0fdSAndre Fischer 348590a0fdSAndre Fischer using namespace com::sun::star; 358590a0fdSAndre Fischer 368590a0fdSAndre Fischer namespace http_dav_ucp 378590a0fdSAndre Fischer { 388590a0fdSAndre Fischer 398590a0fdSAndre Fischer SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath, 40e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders, 418590a0fdSAndre Fischer const Depth inDepth, 428590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inPropNames, 438590a0fdSAndre Fischer std::vector< DAVResource > & ioResources ) 44e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders ) 458590a0fdSAndre Fischer , mDepthStr( 0 ) 468590a0fdSAndre Fischer , mpPropNames( &inPropNames ) 478590a0fdSAndre Fischer , mpResources( &ioResources ) 488590a0fdSAndre Fischer , mpResInfo( 0 ) 498590a0fdSAndre Fischer , mbOnlyPropertyNames( false ) 508590a0fdSAndre Fischer , xInputStream( new SerfInputStream() ) 518590a0fdSAndre Fischer { 528590a0fdSAndre Fischer init( inDepth ); 538590a0fdSAndre Fischer } 548590a0fdSAndre Fischer 558590a0fdSAndre Fischer SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath, 56e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders, 578590a0fdSAndre Fischer const Depth inDepth, 588590a0fdSAndre Fischer std::vector< DAVResourceInfo > & ioResInfo ) 59e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders ) 608590a0fdSAndre Fischer , mDepthStr( 0 ) 618590a0fdSAndre Fischer , mpPropNames( 0 ) 628590a0fdSAndre Fischer , mpResources( 0 ) 638590a0fdSAndre Fischer , mpResInfo( &ioResInfo ) 648590a0fdSAndre Fischer , mbOnlyPropertyNames( true ) 658590a0fdSAndre Fischer , xInputStream( new SerfInputStream() ) 668590a0fdSAndre Fischer { 678590a0fdSAndre Fischer init( inDepth ); 688590a0fdSAndre Fischer } 698590a0fdSAndre Fischer 708590a0fdSAndre Fischer void SerfPropFindReqProcImpl::init( const Depth inDepth ) 718590a0fdSAndre Fischer { 728590a0fdSAndre Fischer switch ( inDepth ) 738590a0fdSAndre Fischer { 748590a0fdSAndre Fischer case DAVZERO: 758590a0fdSAndre Fischer mDepthStr = "0"; 768590a0fdSAndre Fischer break; 778590a0fdSAndre Fischer case DAVONE: 788590a0fdSAndre Fischer mDepthStr = "1"; 798590a0fdSAndre Fischer break; 808590a0fdSAndre Fischer case DAVINFINITY: 818590a0fdSAndre Fischer mDepthStr = "infinity"; 828590a0fdSAndre Fischer break; 838590a0fdSAndre Fischer } 848590a0fdSAndre Fischer } 858590a0fdSAndre Fischer 868590a0fdSAndre Fischer SerfPropFindReqProcImpl::~SerfPropFindReqProcImpl() 878590a0fdSAndre Fischer { 888590a0fdSAndre Fischer } 898590a0fdSAndre Fischer 908590a0fdSAndre Fischer #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">" 918590a0fdSAndre Fischer #define PROPFIND_TRAILER "</propfind>" 928590a0fdSAndre Fischer 938590a0fdSAndre Fischer serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) 948590a0fdSAndre Fischer { 958590a0fdSAndre Fischer serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest ); 968590a0fdSAndre Fischer 978590a0fdSAndre Fischer // body bucket - certain properties OR all properties OR only property names 988590a0fdSAndre Fischer serf_bucket_t* body_bkt = 0; 99*efc9b74fSAriel Constenla-Haile rtl::OString aBodyText; 1008590a0fdSAndre Fischer { 101*efc9b74fSAriel Constenla-Haile // TODO is it really needed a Unicode string buffer? 102*efc9b74fSAriel Constenla-Haile // All properties and property names aren't supposed to be ASCII? 103*efc9b74fSAriel Constenla-Haile rtl::OUStringBuffer aBuffer; 104*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPFIND_HEADER )); 105*efc9b74fSAriel Constenla-Haile 1068590a0fdSAndre Fischer // create and fill body bucket with requested properties 1078590a0fdSAndre Fischer const int nPropCount = ( !mbOnlyPropertyNames && mpPropNames ) 1088590a0fdSAndre Fischer ? mpPropNames->size() 1098590a0fdSAndre Fischer : 0; 1108590a0fdSAndre Fischer if ( nPropCount > 0 ) 1118590a0fdSAndre Fischer { 112*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<prop>" ) ); 1138590a0fdSAndre Fischer SerfPropName thePropName; 1148590a0fdSAndre Fischer for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ ) 1158590a0fdSAndre Fischer { 1168590a0fdSAndre Fischer // split fullname into namespace and name! 1178590a0fdSAndre Fischer DAVProperties::createSerfPropName( (*mpPropNames)[ theIndex ], 1188590a0fdSAndre Fischer thePropName ); 1198590a0fdSAndre Fischer 1208590a0fdSAndre Fischer /* <*propname* xmlns="*propns*" /> */ 121*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<" )); 122*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( thePropName.name ); 123*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " xmlnx=\"" )); 124*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( thePropName.nspace ); 125*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\"/>" )); 1268590a0fdSAndre Fischer } 1278590a0fdSAndre Fischer 128*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</prop>" )); 1298590a0fdSAndre Fischer } 1308590a0fdSAndre Fischer else 1318590a0fdSAndre Fischer { 1328590a0fdSAndre Fischer if ( mbOnlyPropertyNames ) 1338590a0fdSAndre Fischer { 134*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<propname/>" )); 1358590a0fdSAndre Fischer } 1368590a0fdSAndre Fischer else 1378590a0fdSAndre Fischer { 138*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<allprop/>" )); 1398590a0fdSAndre Fischer } 1408590a0fdSAndre Fischer } 1418590a0fdSAndre Fischer 142*efc9b74fSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPFIND_TRAILER )); 143*efc9b74fSAriel Constenla-Haile aBodyText = rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ); 144*efc9b74fSAriel Constenla-Haile body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(), 145*efc9b74fSAriel Constenla-Haile aBodyText.getLength(), 1468590a0fdSAndre Fischer pSerfBucketAlloc ); 1478590a0fdSAndre Fischer } 1488590a0fdSAndre Fischer 1498590a0fdSAndre Fischer // create serf request 1508590a0fdSAndre Fischer serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, 1518590a0fdSAndre Fischer "PROPFIND", 1528590a0fdSAndre Fischer getPathStr(), 1538590a0fdSAndre Fischer body_bkt, 15425eaca47SOliver-Rainer Wittmann pSerfBucketAlloc ); 15510e20387SAndre Fischer handleChunkedEncoding(req_bkt, aBodyText.getLength()); 1568590a0fdSAndre Fischer 1578590a0fdSAndre Fischer // set request header fields 1588590a0fdSAndre Fischer serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); 15910e20387SAndre Fischer if (hdrs_bkt != NULL) 16010e20387SAndre Fischer { 161e9ff7e89SOliver-Rainer Wittmann // general header fields provided by caller 162e9ff7e89SOliver-Rainer Wittmann setRequestHeaders( hdrs_bkt ); 1638590a0fdSAndre Fischer 1648590a0fdSAndre Fischer // request specific header fields 165e9ff7e89SOliver-Rainer Wittmann serf_bucket_headers_set( hdrs_bkt, "Depth", mDepthStr ); 16610e20387SAndre Fischer if (hdrs_bkt!=NULL && body_bkt != 0 && aBodyText.getLength() > 0 ) 167353980d1SOliver-Rainer Wittmann { 168e9ff7e89SOliver-Rainer Wittmann serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" ); 16910e20387SAndre Fischer } 17010e20387SAndre Fischer } 17110e20387SAndre Fischer else 17210e20387SAndre Fischer { 17310e20387SAndre Fischer OSL_ASSERT("Headers Bucket missing"); 174353980d1SOliver-Rainer Wittmann } 1758590a0fdSAndre Fischer 1768590a0fdSAndre Fischer return req_bkt; 1778590a0fdSAndre Fischer } 1788590a0fdSAndre Fischer 17949989859SOliver-Rainer Wittmann void SerfPropFindReqProcImpl::processChunkOfResponseData( const char* data, 18049989859SOliver-Rainer Wittmann apr_size_t len ) 1818590a0fdSAndre Fischer { 18249989859SOliver-Rainer Wittmann if ( xInputStream.is() ) 1838590a0fdSAndre Fischer { 1848590a0fdSAndre Fischer xInputStream->AddToStream( data, len ); 1858590a0fdSAndre Fischer } 18649989859SOliver-Rainer Wittmann } 1878590a0fdSAndre Fischer 18849989859SOliver-Rainer Wittmann void SerfPropFindReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ ) 1898590a0fdSAndre Fischer { 1908590a0fdSAndre Fischer if ( mbOnlyPropertyNames ) 1918590a0fdSAndre Fischer { 1928590a0fdSAndre Fischer const std::vector< DAVResourceInfo > rResInfo( parseWebDAVPropNameResponse( xInputStream.get() ) ); 1938590a0fdSAndre Fischer *mpResInfo = rResInfo; 1948590a0fdSAndre Fischer } 1958590a0fdSAndre Fischer else 1968590a0fdSAndre Fischer { 1978590a0fdSAndre Fischer const std::vector< DAVResource > rResources( parseWebDAVPropFindResponse( xInputStream.get() ) ); 1988590a0fdSAndre Fischer *mpResources = rResources; 1998590a0fdSAndre Fischer } 2008590a0fdSAndre Fischer } 2018590a0fdSAndre Fischer 2028590a0fdSAndre Fischer } // namespace http_dav_ucp 203