bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / webdav / SerfGetReqProcImpl.cxx
blobc06b94f16b50fb2f8645f94dad6c87334cc837df
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 rtl::Reference< SerfInputStream > & xioInStrm )
30 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
31 , xInputStream( xioInStrm )
32 , xOutputStream()
33 , mpHeaderNames( nullptr )
34 , mpResource( nullptr )
38 SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
39 const DAVRequestHeaders& inRequestHeaders,
40 const rtl::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 css::uno::Reference< css::io::XOutputStream > & xioOutStrm )
54 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
55 , xInputStream()
56 , xOutputStream( xioOutStrm )
57 , mpHeaderNames( nullptr )
58 , mpResource( nullptr )
62 SerfGetReqProcImpl::SerfGetReqProcImpl( const char* inPath,
63 const DAVRequestHeaders& inRequestHeaders,
64 const css::uno::Reference< css::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(),
85 nullptr,
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( reinterpret_cast<const 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 != nullptr && mpResource != nullptr )
129 serf_bucket_t* SerfHeaderBucket = serf_bucket_response_get_headers( inSerfResponseBucket );
130 if ( SerfHeaderBucket != nullptr )
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->empty() )
148 // store all header fields
149 bStoreHeaderField = true;
151 else
153 // store only header fields which are requested
154 bStoreHeaderField = std::any_of(mpHeaderNames->begin(), mpHeaderNames->end(),
155 [&aHeaderName](const OUString& rHeaderName) {
156 // header names are case insensitive
157 return rHeaderName.equalsIgnoreAsciiCase( aHeaderName );
161 if ( bStoreHeaderField )
163 DAVPropertyValue thePropertyValue;
164 thePropertyValue.IsCaseSensitive = false;
165 thePropertyValue.Name = aHeaderName;
166 thePropertyValue.Value <<= OUString::createFromAscii( inHeaderValue );
167 mpResource->properties.push_back( thePropertyValue );
171 } // namespace http_dav_ucp
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */