LibreOffice Module ucb (master)  1
SerfHeadReqProcImpl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include "SerfHeadReqProcImpl.hxx"
21 
22 using namespace com::sun::star;
23 
24 namespace http_dav_ucp
25 {
26 
27 SerfHeadReqProcImpl::SerfHeadReqProcImpl( const char* inPath,
28  const DAVRequestHeaders& inRequestHeaders,
29  const std::vector< OUString > & inHeaderNames,
30  DAVResource & ioResource )
31  : SerfRequestProcessorImpl( inPath, inRequestHeaders )
32  , mpHeaderNames( &inHeaderNames )
33  , mpResource( &ioResource )
34 {
35 }
36 
38 {
39 }
40 
41 serf_bucket_t * SerfHeadReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
42 {
43  // create serf request
44  serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
45  "HEAD",
46  getPathStr(),
47 
48  nullptr,
49  serf_request_get_alloc( inSerfRequest ) );
50 
51  // set request header fields
52  serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
53  // general header fields provided by caller
54  setRequestHeaders( hdrs_bkt );
55 
56  return req_bkt;
57 }
58 
60  apr_size_t /*len*/ )
61 {
62  // nothing to do
63 }
64 
65 namespace
66 {
67  apr_status_t Serf_ProcessResponseHeader( void* inUserData,
68  const char* inHeaderName,
69  const char* inHeaderValue )
70  {
71  SerfHeadReqProcImpl* pReqProcImpl = static_cast< SerfHeadReqProcImpl* >( inUserData );
72  pReqProcImpl->processSingleResponseHeader( inHeaderName,
73  inHeaderValue );
74 
75  return APR_SUCCESS;
76  }
77 } // end of anonymous namespace
78 
79 void SerfHeadReqProcImpl::handleEndOfResponseData( serf_bucket_t * inSerfResponseBucket )
80 {
81  // read response header, if requested
82  if ( mpHeaderNames != nullptr && mpResource != nullptr )
83  {
84  serf_bucket_t* SerfHeaderBucket = serf_bucket_response_get_headers( inSerfResponseBucket );
85  if ( SerfHeaderBucket != nullptr )
86  {
87  serf_bucket_headers_do( SerfHeaderBucket,
88  Serf_ProcessResponseHeader,
89  this );
90  }
91  }
92 }
93 
94 void SerfHeadReqProcImpl::processSingleResponseHeader( const char* inHeaderName,
95  const char* inHeaderValue )
96 {
97  OUString aHeaderName( OUString::createFromAscii( inHeaderName ) );
98 
99  bool bStoreHeaderField = false;
100 
101  if ( mpHeaderNames->empty() )
102  {
103  // store all header fields
104  bStoreHeaderField = true;
105  }
106  else
107  {
108  // store only header fields which are requested
109  bStoreHeaderField = std::any_of(mpHeaderNames->begin(), mpHeaderNames->end(),
110  [&aHeaderName](const OUString& rHeaderName) {
111  // header names are case insensitive
112  return rHeaderName.equalsIgnoreAsciiCase( aHeaderName );
113  });
114  }
115 
116  if ( bStoreHeaderField )
117  {
118  DAVPropertyValue thePropertyValue;
119  thePropertyValue.IsCaseSensitive = false;
120  thePropertyValue.Name = aHeaderName;
121  thePropertyValue.Value <<= OUString::createFromAscii( inHeaderValue );
122  mpResource->properties.push_back( thePropertyValue );
123  }
124 }
125 
126 } // namespace http_dav_ucp
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< DAVRequestHeader > DAVRequestHeaders
void setRequestHeaders(serf_bucket_t *inoutSerfHeaderBucket)
const std::vector< OUString > * mpHeaderNames
void processSingleResponseHeader(const char *inHeaderName, const char *inHeaderValue)
virtual void handleEndOfResponseData(serf_bucket_t *inSerfResponseBucket) override
virtual serf_bucket_t * createSerfRequestBucket(serf_request_t *inSerfRequest) override
std::vector< DAVPropertyValue > properties
Definition: DAVResource.hxx:44
virtual void processChunkOfResponseData(const char *data, apr_size_t len) override