fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / webdav / SerfGetReqProcImpl.cxx
blob03c686fd725db3f7494510539347cba8fc6a7ebb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "SerfGetReqProcImpl.hxx"
22 using namespace com::sun::star;
24 namespace http_dav_ucp
27 SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
28 const DAVRequestHeaders& inRequestHeaders,
29 const com::sun::star::uno::Reference< SerfInputStream > & xioInStrm )
30 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
31 , xInputStream( xioInStrm )
32 , xOutputStream()
33 , mpHeaderNames( 0 )
34 , mpResource( 0 )
38 SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
39 const DAVRequestHeaders& inRequestHeaders,
40 const com::sun::star::uno::Reference< SerfInputStream > & xioInStrm,
41 const std::vector< OUString > & inHeaderNames,
42 DAVResource & ioResource )
43 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
44 , xInputStream( xioInStrm )
45 , xOutputStream()
46 , mpHeaderNames( &inHeaderNames )
47 , mpResource( &ioResource )
51 SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
52 const DAVRequestHeaders& inRequestHeaders,
53 const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > & xioOutStrm )
54 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
55 , xInputStream()
56 , xOutputStream( xioOutStrm )
57 , mpHeaderNames( 0 )
58 , mpResource( 0 )
62 SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
63 const DAVRequestHeaders& inRequestHeaders,
64 const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > & xioOutStrm,
65 const std::vector< OUString > & inHeaderNames,
66 DAVResource & ioResource )
67 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
68 , xInputStream()
69 , xOutputStream( xioOutStrm )
70 , mpHeaderNames( &inHeaderNames )
71 , mpResource( &ioResource )
75 SerfGetReqProcImpl::~SerfGetReqProcImpl()
79 serf_bucket_t * SerfGetReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
81 // create serf request
82 serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
83 "GET",
84 getPathStr(),
86 serf_request_get_alloc( inSerfRequest ) );
88 // set request header fields
89 serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
90 // general header fields provided by caller
91 setRequestHeaders( hdrs_bkt );
93 return req_bkt;
96 void SerfGetReqProcImpl::processChunkOfResponseData( const char* data,
97 apr_size_t len )
99 if ( xInputStream.is() )
101 xInputStream->AddToStream( data, len );
103 else if ( xOutputStream.is() )
105 const uno::Sequence< sal_Int8 > aDataSeq( (sal_Int8 *)data, len );
106 xOutputStream->writeBytes( aDataSeq );
110 namespace
112 apr_status_t Serf_ProcessResponseHeader( void* inUserData,
113 const char* inHeaderName,
114 const char* inHeaderValue )
116 SerfGetReqProcImpl* pReqProcImpl = static_cast< SerfGetReqProcImpl* >( inUserData );
117 pReqProcImpl->processSingleResponseHeader( inHeaderName,
118 inHeaderValue );
120 return APR_SUCCESS;
122 } // end of anonymous namespace
124 void SerfGetReqProcImpl::handleEndOfResponseData( serf_bucket_t * inSerfResponseBucket )
126 // read response header, if requested
127 if ( mpHeaderNames != 0 && mpResource != 0 )
129 serf_bucket_t* SerfHeaderBucket = serf_bucket_response_get_headers( inSerfResponseBucket );
130 if ( SerfHeaderBucket != 0 )
132 serf_bucket_headers_do( SerfHeaderBucket,
133 Serf_ProcessResponseHeader,
134 this );
139 void SerfGetReqProcImpl::processSingleResponseHeader( const char* inHeaderName,
140 const char* inHeaderValue )
142 OUString aHeaderName( OUString::createFromAscii( inHeaderName ) );
144 bool bStoreHeaderField = false;
146 if ( mpHeaderNames->size() == 0 )
148 // store all header fields
149 bStoreHeaderField = true;
151 else
153 // store only header fields which are requested
154 std::vector< OUString >::const_iterator it( mpHeaderNames->begin() );
155 const std::vector< OUString >::const_iterator end( mpHeaderNames->end() );
157 while ( it != end )
159 // header names are case insensitive
160 if ( (*it).equalsIgnoreAsciiCase( aHeaderName ) )
162 bStoreHeaderField = true;
163 break;
165 else
167 ++it;
172 if ( bStoreHeaderField )
174 DAVPropertyValue thePropertyValue;
175 thePropertyValue.IsCaseSensitive = false;
176 thePropertyValue.Name = aHeaderName;
177 thePropertyValue.Value <<= OUString::createFromAscii( inHeaderValue );
178 mpResource->properties.push_back( thePropertyValue );
182 } // namespace http_dav_ucp
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */