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 "SerfGetReqProcImpl.hxx"
268590a0fdSAndre Fischer
278590a0fdSAndre Fischer using namespace com::sun::star;
288590a0fdSAndre Fischer
298590a0fdSAndre Fischer namespace http_dav_ucp
308590a0fdSAndre Fischer {
318590a0fdSAndre Fischer
SerfGetReqProcImpl(const char * inPath,const DAVRequestHeaders & inRequestHeaders,const com::sun::star::uno::Reference<SerfInputStream> & xioInStrm)328590a0fdSAndre Fischer SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
33e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders,
348590a0fdSAndre Fischer const com::sun::star::uno::Reference< SerfInputStream > & xioInStrm )
35e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders )
368590a0fdSAndre Fischer , xInputStream( xioInStrm )
378590a0fdSAndre Fischer , xOutputStream()
388590a0fdSAndre Fischer , mpHeaderNames( 0 )
398590a0fdSAndre Fischer , mpResource( 0 )
408590a0fdSAndre Fischer {
418590a0fdSAndre Fischer }
428590a0fdSAndre Fischer
SerfGetReqProcImpl(const char * inPath,const DAVRequestHeaders & inRequestHeaders,const com::sun::star::uno::Reference<SerfInputStream> & xioInStrm,const std::vector<::rtl::OUString> & inHeaderNames,DAVResource & ioResource)438590a0fdSAndre Fischer SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
44e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders,
458590a0fdSAndre Fischer const com::sun::star::uno::Reference< SerfInputStream > & xioInStrm,
468590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames,
478590a0fdSAndre Fischer DAVResource & ioResource )
48e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders )
498590a0fdSAndre Fischer , xInputStream( xioInStrm )
508590a0fdSAndre Fischer , xOutputStream()
518590a0fdSAndre Fischer , mpHeaderNames( &inHeaderNames )
528590a0fdSAndre Fischer , mpResource( &ioResource )
538590a0fdSAndre Fischer {
548590a0fdSAndre Fischer }
558590a0fdSAndre Fischer
SerfGetReqProcImpl(const char * inPath,const DAVRequestHeaders & inRequestHeaders,const com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> & xioOutStrm)568590a0fdSAndre Fischer SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
57e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders,
588590a0fdSAndre Fischer const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > & xioOutStrm )
59e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders )
608590a0fdSAndre Fischer , xInputStream()
618590a0fdSAndre Fischer , xOutputStream( xioOutStrm )
628590a0fdSAndre Fischer , mpHeaderNames( 0 )
638590a0fdSAndre Fischer , mpResource( 0 )
648590a0fdSAndre Fischer {
658590a0fdSAndre Fischer }
668590a0fdSAndre Fischer
SerfGetReqProcImpl(const char * inPath,const DAVRequestHeaders & inRequestHeaders,const com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> & xioOutStrm,const std::vector<::rtl::OUString> & inHeaderNames,DAVResource & ioResource)678590a0fdSAndre Fischer SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
68e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders,
698590a0fdSAndre Fischer const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > & xioOutStrm,
708590a0fdSAndre Fischer const std::vector< ::rtl::OUString > & inHeaderNames,
718590a0fdSAndre Fischer DAVResource & ioResource )
72e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders )
738590a0fdSAndre Fischer , xInputStream()
748590a0fdSAndre Fischer , xOutputStream( xioOutStrm )
758590a0fdSAndre Fischer , mpHeaderNames( &inHeaderNames )
768590a0fdSAndre Fischer , mpResource( &ioResource )
778590a0fdSAndre Fischer {
788590a0fdSAndre Fischer }
798590a0fdSAndre Fischer
~SerfGetReqProcImpl()808590a0fdSAndre Fischer SerfGetReqProcImpl::~SerfGetReqProcImpl()
818590a0fdSAndre Fischer {
828590a0fdSAndre Fischer }
838590a0fdSAndre Fischer
createSerfRequestBucket(serf_request_t * inSerfRequest)848590a0fdSAndre Fischer serf_bucket_t * SerfGetReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
858590a0fdSAndre Fischer {
868590a0fdSAndre Fischer // create serf request
878590a0fdSAndre Fischer serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
888590a0fdSAndre Fischer "GET",
898590a0fdSAndre Fischer getPathStr(),
908590a0fdSAndre Fischer 0,
918590a0fdSAndre Fischer serf_request_get_alloc( inSerfRequest ) );
928590a0fdSAndre Fischer
938590a0fdSAndre Fischer // set request header fields
948590a0fdSAndre Fischer serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
95e9ff7e89SOliver-Rainer Wittmann // general header fields provided by caller
96e9ff7e89SOliver-Rainer Wittmann setRequestHeaders( hdrs_bkt );
978590a0fdSAndre Fischer
988590a0fdSAndre Fischer return req_bkt;
998590a0fdSAndre Fischer }
1008590a0fdSAndre Fischer
processChunkOfResponseData(const char * data,apr_size_t len)10149989859SOliver-Rainer Wittmann void SerfGetReqProcImpl::processChunkOfResponseData( const char* data,
10249989859SOliver-Rainer Wittmann apr_size_t len )
10349989859SOliver-Rainer Wittmann {
10449989859SOliver-Rainer Wittmann if ( xInputStream.is() )
10549989859SOliver-Rainer Wittmann {
10649989859SOliver-Rainer Wittmann xInputStream->AddToStream( data, len );
10749989859SOliver-Rainer Wittmann }
10849989859SOliver-Rainer Wittmann else if ( xOutputStream.is() )
10949989859SOliver-Rainer Wittmann {
11049989859SOliver-Rainer Wittmann const uno::Sequence< sal_Int8 > aDataSeq( (sal_Int8 *)data, len );
11149989859SOliver-Rainer Wittmann xOutputStream->writeBytes( aDataSeq );
11249989859SOliver-Rainer Wittmann }
11349989859SOliver-Rainer Wittmann }
11449989859SOliver-Rainer Wittmann
1158590a0fdSAndre Fischer namespace
1168590a0fdSAndre Fischer {
Serf_ProcessResponseHeader(void * inUserData,const char * inHeaderName,const char * inHeaderValue)1178590a0fdSAndre Fischer apr_status_t Serf_ProcessResponseHeader( void* inUserData,
1188590a0fdSAndre Fischer const char* inHeaderName,
1198590a0fdSAndre Fischer const char* inHeaderValue )
1208590a0fdSAndre Fischer {
1218590a0fdSAndre Fischer SerfGetReqProcImpl* pReqProcImpl = static_cast< SerfGetReqProcImpl* >( inUserData );
1228590a0fdSAndre Fischer pReqProcImpl->processSingleResponseHeader( inHeaderName,
1238590a0fdSAndre Fischer inHeaderValue );
1248590a0fdSAndre Fischer
1258590a0fdSAndre Fischer return APR_SUCCESS;
1268590a0fdSAndre Fischer }
1278590a0fdSAndre Fischer } // end of anonymous namespace
1288590a0fdSAndre Fischer
handleEndOfResponseData(serf_bucket_t * inSerfResponseBucket)12949989859SOliver-Rainer Wittmann void SerfGetReqProcImpl::handleEndOfResponseData( serf_bucket_t * inSerfResponseBucket )
1308590a0fdSAndre Fischer {
1318590a0fdSAndre Fischer // read response header, if requested
1328590a0fdSAndre Fischer if ( mpHeaderNames != 0 && mpResource != 0 )
1338590a0fdSAndre Fischer {
1348590a0fdSAndre Fischer serf_bucket_t* SerfHeaderBucket = serf_bucket_response_get_headers( inSerfResponseBucket );
1358590a0fdSAndre Fischer if ( SerfHeaderBucket != 0 )
1368590a0fdSAndre Fischer {
1378590a0fdSAndre Fischer serf_bucket_headers_do( SerfHeaderBucket,
1388590a0fdSAndre Fischer Serf_ProcessResponseHeader,
1398590a0fdSAndre Fischer this );
1408590a0fdSAndre Fischer }
1418590a0fdSAndre Fischer }
1428590a0fdSAndre Fischer }
1438590a0fdSAndre Fischer
processSingleResponseHeader(const char * inHeaderName,const char * inHeaderValue)1448590a0fdSAndre Fischer void SerfGetReqProcImpl::processSingleResponseHeader( const char* inHeaderName,
1458590a0fdSAndre Fischer const char* inHeaderValue )
1468590a0fdSAndre Fischer {
1478590a0fdSAndre Fischer rtl::OUString aHeaderName( rtl::OUString::createFromAscii( inHeaderName ) );
1488590a0fdSAndre Fischer
1498590a0fdSAndre Fischer bool bStoreHeaderField = false;
1508590a0fdSAndre Fischer
1518590a0fdSAndre Fischer if ( mpHeaderNames->size() == 0 )
1528590a0fdSAndre Fischer {
1538590a0fdSAndre Fischer // store all header fields
1548590a0fdSAndre Fischer bStoreHeaderField = true;
1558590a0fdSAndre Fischer }
1568590a0fdSAndre Fischer else
1578590a0fdSAndre Fischer {
1588590a0fdSAndre Fischer // store only header fields which are requested
1598590a0fdSAndre Fischer std::vector< ::rtl::OUString >::const_iterator it( mpHeaderNames->begin() );
1608590a0fdSAndre Fischer const std::vector< ::rtl::OUString >::const_iterator end( mpHeaderNames->end() );
1618590a0fdSAndre Fischer
1628590a0fdSAndre Fischer while ( it != end )
1638590a0fdSAndre Fischer {
1648590a0fdSAndre Fischer // header names are case insensitive
1658590a0fdSAndre Fischer if ( (*it).equalsIgnoreAsciiCase( aHeaderName ) )
1668590a0fdSAndre Fischer {
1678590a0fdSAndre Fischer bStoreHeaderField = true;
1688590a0fdSAndre Fischer break;
1698590a0fdSAndre Fischer }
1708590a0fdSAndre Fischer else
1718590a0fdSAndre Fischer {
1728590a0fdSAndre Fischer ++it;
1738590a0fdSAndre Fischer }
1748590a0fdSAndre Fischer }
1758590a0fdSAndre Fischer }
1768590a0fdSAndre Fischer
1778590a0fdSAndre Fischer if ( bStoreHeaderField )
1788590a0fdSAndre Fischer {
1798590a0fdSAndre Fischer DAVPropertyValue thePropertyValue;
1808590a0fdSAndre Fischer thePropertyValue.IsCaseSensitive = false;
1818590a0fdSAndre Fischer thePropertyValue.Name = aHeaderName;
1828590a0fdSAndre Fischer thePropertyValue.Value <<= rtl::OUString::createFromAscii( inHeaderValue );
1838590a0fdSAndre Fischer mpResource->properties.push_back( thePropertyValue );
1848590a0fdSAndre Fischer }
1858590a0fdSAndre Fischer }
1868590a0fdSAndre Fischer
1878590a0fdSAndre Fischer } // namespace http_dav_ucp
188