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 <SerfPropFindReqProcImpl.hxx> 268590a0fdSAndre Fischer #include <SerfTypes.hxx> 278590a0fdSAndre Fischer #include <DAVProperties.hxx> 288590a0fdSAndre Fischer 298590a0fdSAndre Fischer #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, 388590a0fdSAndre Fischer const Depth inDepth, 398590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inPropNames, 408590a0fdSAndre Fischer std::vector< DAVResource > & ioResources ) 418590a0fdSAndre Fischer : SerfRequestProcessorImpl( inPath ) 428590a0fdSAndre Fischer , mDepthStr( 0 ) 438590a0fdSAndre Fischer , mpPropNames( &inPropNames ) 448590a0fdSAndre Fischer , mpResources( &ioResources ) 458590a0fdSAndre Fischer , mpResInfo( 0 ) 468590a0fdSAndre Fischer , mbOnlyPropertyNames( false ) 478590a0fdSAndre Fischer , xInputStream( new SerfInputStream() ) 488590a0fdSAndre Fischer { 498590a0fdSAndre Fischer init( inDepth ); 508590a0fdSAndre Fischer } 518590a0fdSAndre Fischer 528590a0fdSAndre Fischer SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath, 538590a0fdSAndre Fischer const Depth inDepth, 548590a0fdSAndre Fischer std::vector< DAVResourceInfo > & ioResInfo ) 558590a0fdSAndre Fischer : SerfRequestProcessorImpl( inPath ) 568590a0fdSAndre Fischer , mDepthStr( 0 ) 578590a0fdSAndre Fischer , mpPropNames( 0 ) 588590a0fdSAndre Fischer , mpResources( 0 ) 598590a0fdSAndre Fischer , mpResInfo( &ioResInfo ) 608590a0fdSAndre Fischer , mbOnlyPropertyNames( true ) 618590a0fdSAndre Fischer , xInputStream( new SerfInputStream() ) 628590a0fdSAndre Fischer { 638590a0fdSAndre Fischer init( inDepth ); 648590a0fdSAndre Fischer } 658590a0fdSAndre Fischer 668590a0fdSAndre Fischer void SerfPropFindReqProcImpl::init( const Depth inDepth ) 678590a0fdSAndre Fischer { 688590a0fdSAndre Fischer switch ( inDepth ) 698590a0fdSAndre Fischer { 708590a0fdSAndre Fischer case DAVZERO: 718590a0fdSAndre Fischer mDepthStr = "0"; 728590a0fdSAndre Fischer break; 738590a0fdSAndre Fischer case DAVONE: 748590a0fdSAndre Fischer mDepthStr = "1"; 758590a0fdSAndre Fischer break; 768590a0fdSAndre Fischer case DAVINFINITY: 778590a0fdSAndre Fischer mDepthStr = "infinity"; 788590a0fdSAndre Fischer break; 798590a0fdSAndre Fischer } 808590a0fdSAndre Fischer } 818590a0fdSAndre Fischer 828590a0fdSAndre Fischer SerfPropFindReqProcImpl::~SerfPropFindReqProcImpl() 838590a0fdSAndre Fischer { 848590a0fdSAndre Fischer } 858590a0fdSAndre Fischer 868590a0fdSAndre Fischer #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">" 878590a0fdSAndre Fischer #define PROPFIND_TRAILER "</propfind>" 888590a0fdSAndre Fischer 898590a0fdSAndre Fischer serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) 908590a0fdSAndre Fischer { 918590a0fdSAndre Fischer serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest ); 928590a0fdSAndre Fischer 938590a0fdSAndre Fischer // body bucket - certain properties OR all properties OR only property names 948590a0fdSAndre Fischer serf_bucket_t* body_bkt = 0; 95353980d1SOliver-Rainer Wittmann rtl::OUString aBodyText; 968590a0fdSAndre Fischer { 978590a0fdSAndre Fischer // create and fill body bucket with requested properties 988590a0fdSAndre Fischer const int nPropCount = ( !mbOnlyPropertyNames && mpPropNames ) 998590a0fdSAndre Fischer ? mpPropNames->size() 1008590a0fdSAndre Fischer : 0; 1018590a0fdSAndre Fischer if ( nPropCount > 0 ) 1028590a0fdSAndre Fischer { 1038590a0fdSAndre Fischer SerfPropName thePropName; 1048590a0fdSAndre Fischer for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ ) 1058590a0fdSAndre Fischer { 1068590a0fdSAndre Fischer // split fullname into namespace and name! 1078590a0fdSAndre Fischer DAVProperties::createSerfPropName( (*mpPropNames)[ theIndex ], 1088590a0fdSAndre Fischer thePropName ); 1098590a0fdSAndre Fischer 1108590a0fdSAndre Fischer /* <*propname* xmlns="*propns*" /> */ 111353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( "<" ); 112353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( thePropName.name ); 113353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( " xmlnx=\"" ); 114353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( thePropName.nspace ); 115353980d1SOliver-Rainer Wittmann aBodyText += rtl::OUString::createFromAscii( "\"/>" ); 1168590a0fdSAndre Fischer } 1178590a0fdSAndre Fischer 118353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( "<prop>" ) + 119353980d1SOliver-Rainer Wittmann aBodyText + 120353980d1SOliver-Rainer Wittmann rtl::OUString::createFromAscii( "</prop>" ); 1218590a0fdSAndre Fischer } 1228590a0fdSAndre Fischer else 1238590a0fdSAndre Fischer { 1248590a0fdSAndre Fischer if ( mbOnlyPropertyNames ) 1258590a0fdSAndre Fischer { 126353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( "<propname/>" ); 1278590a0fdSAndre Fischer } 1288590a0fdSAndre Fischer else 1298590a0fdSAndre Fischer { 130353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( "<allprop/>" ); 1318590a0fdSAndre Fischer } 1328590a0fdSAndre Fischer } 1338590a0fdSAndre Fischer 134353980d1SOliver-Rainer Wittmann aBodyText = rtl::OUString::createFromAscii( PROPFIND_HEADER ) + 135353980d1SOliver-Rainer Wittmann aBodyText + 136353980d1SOliver-Rainer Wittmann rtl::OUString::createFromAscii( PROPFIND_TRAILER ); 137353980d1SOliver-Rainer Wittmann body_bkt = SERF_BUCKET_SIMPLE_STRING( rtl::OUStringToOString( aBodyText, RTL_TEXTENCODING_UTF8 ), 1388590a0fdSAndre Fischer pSerfBucketAlloc ); 1398590a0fdSAndre Fischer } 1408590a0fdSAndre Fischer 1418590a0fdSAndre Fischer // create serf request 1428590a0fdSAndre Fischer serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, 1438590a0fdSAndre Fischer "PROPFIND", 1448590a0fdSAndre Fischer getPathStr(), 1458590a0fdSAndre Fischer body_bkt, 146*25eaca47SOliver-Rainer Wittmann pSerfBucketAlloc ); 1478590a0fdSAndre Fischer 1488590a0fdSAndre Fischer // TODO - correct header data 1498590a0fdSAndre Fischer // set request header fields 1508590a0fdSAndre Fischer serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); 1518590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "User-Agent", "www.openoffice.org/ucb/" ); 1528590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "Accept-Encoding", "gzip"); 1538590a0fdSAndre Fischer 1548590a0fdSAndre Fischer // request specific header fields 155353980d1SOliver-Rainer Wittmann // request specific header fields 1568590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "Depth", mDepthStr ); 157353980d1SOliver-Rainer Wittmann if ( body_bkt != 0 && aBodyText.getLength() > 0 ) 158353980d1SOliver-Rainer Wittmann { 1598590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "Content-Type", "application/xml" ); 1608590a0fdSAndre Fischer serf_bucket_headers_setn( hdrs_bkt, "Content-Length", 161353980d1SOliver-Rainer Wittmann rtl::OUStringToOString( rtl::OUString::valueOf( aBodyText.getLength() ), RTL_TEXTENCODING_UTF8 ) ); 162353980d1SOliver-Rainer Wittmann } 1638590a0fdSAndre Fischer 1648590a0fdSAndre Fischer return req_bkt; 1658590a0fdSAndre Fischer } 1668590a0fdSAndre Fischer 1678590a0fdSAndre Fischer 1688590a0fdSAndre Fischer bool SerfPropFindReqProcImpl::processSerfResponseBucket( serf_request_t * /*inSerfRequest*/, 1698590a0fdSAndre Fischer serf_bucket_t * inSerfResponseBucket, 1708590a0fdSAndre Fischer apr_pool_t * /*inAprPool*/, 1718590a0fdSAndre Fischer apr_status_t & outStatus ) 1728590a0fdSAndre Fischer { 1738590a0fdSAndre Fischer const char* data; 1748590a0fdSAndre Fischer apr_size_t len; 1758590a0fdSAndre Fischer 1768590a0fdSAndre Fischer while (1) { 1778590a0fdSAndre Fischer outStatus = serf_bucket_read(inSerfResponseBucket, 2048, &data, &len); 1788590a0fdSAndre Fischer if (SERF_BUCKET_READ_ERROR(outStatus)) 1798590a0fdSAndre Fischer { 1808590a0fdSAndre Fischer return true; 1818590a0fdSAndre Fischer } 1828590a0fdSAndre Fischer 1838590a0fdSAndre Fischer if ( len > 0 ) 1848590a0fdSAndre Fischer { 1858590a0fdSAndre Fischer xInputStream->AddToStream( data, len ); 1868590a0fdSAndre Fischer } 1878590a0fdSAndre Fischer 1888590a0fdSAndre Fischer /* are we done yet? */ 1898590a0fdSAndre Fischer if (APR_STATUS_IS_EOF(outStatus)) 1908590a0fdSAndre Fischer { 1918590a0fdSAndre Fischer if ( mbOnlyPropertyNames ) 1928590a0fdSAndre Fischer { 1938590a0fdSAndre Fischer const std::vector< DAVResourceInfo > rResInfo( parseWebDAVPropNameResponse( xInputStream.get() ) ); 1948590a0fdSAndre Fischer *mpResInfo = rResInfo; 1958590a0fdSAndre Fischer } 1968590a0fdSAndre Fischer else 1978590a0fdSAndre Fischer { 1988590a0fdSAndre Fischer const std::vector< DAVResource > rResources( parseWebDAVPropFindResponse( xInputStream.get() ) ); 1998590a0fdSAndre Fischer *mpResources = rResources; 2008590a0fdSAndre Fischer } 2018590a0fdSAndre Fischer 2028590a0fdSAndre Fischer outStatus = APR_EOF; 2038590a0fdSAndre Fischer return true; 2048590a0fdSAndre Fischer } 2058590a0fdSAndre Fischer 2068590a0fdSAndre Fischer /* have we drained the response so far? */ 2078590a0fdSAndre Fischer if ( APR_STATUS_IS_EAGAIN( outStatus ) ) 2088590a0fdSAndre Fischer { 2098590a0fdSAndre Fischer return false; 2108590a0fdSAndre Fischer } 2118590a0fdSAndre Fischer } 2128590a0fdSAndre Fischer 2138590a0fdSAndre Fischer /* NOTREACHED */ 2148590a0fdSAndre Fischer return true; 2158590a0fdSAndre Fischer } 2168590a0fdSAndre Fischer 2178590a0fdSAndre Fischer } // namespace http_dav_ucp 218