1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "SerfHeadReqProcImpl.hxx"
22 using namespace com::sun::star
;
24 namespace http_dav_ucp
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
)
37 SerfHeadReqProcImpl::~SerfHeadReqProcImpl()
41 serf_bucket_t
* SerfHeadReqProcImpl::createSerfRequestBucket( serf_request_t
* inSerfRequest
)
43 // create serf request
44 serf_bucket_t
*req_bkt
= serf_request_bucket_request_create( inSerfRequest
,
48 serf_request_get_alloc( inSerfRequest
) );
50 // set request header fields
51 serf_bucket_t
* hdrs_bkt
= serf_bucket_request_get_headers( req_bkt
);
52 // general header fields provided by caller
53 setRequestHeaders( hdrs_bkt
);
58 void SerfHeadReqProcImpl::processChunkOfResponseData( const char* /*data*/,
66 apr_status_t
Serf_ProcessResponseHeader( void* inUserData
,
67 const char* inHeaderName
,
68 const char* inHeaderValue
)
70 SerfHeadReqProcImpl
* pReqProcImpl
= static_cast< SerfHeadReqProcImpl
* >( inUserData
);
71 pReqProcImpl
->processSingleResponseHeader( inHeaderName
,
76 } // end of anonymous namespace
78 void SerfHeadReqProcImpl::handleEndOfResponseData( serf_bucket_t
* inSerfResponseBucket
)
80 // read response header, if requested
81 if ( mpHeaderNames
!= 0 && mpResource
!= 0 )
83 serf_bucket_t
* SerfHeaderBucket
= serf_bucket_response_get_headers( inSerfResponseBucket
);
84 if ( SerfHeaderBucket
!= 0 )
86 serf_bucket_headers_do( SerfHeaderBucket
,
87 Serf_ProcessResponseHeader
,
93 void SerfHeadReqProcImpl::processSingleResponseHeader( const char* inHeaderName
,
94 const char* inHeaderValue
)
96 OUString
aHeaderName( OUString::createFromAscii( inHeaderName
) );
98 bool bStoreHeaderField
= false;
100 if ( mpHeaderNames
->size() == 0 )
102 // store all header fields
103 bStoreHeaderField
= true;
107 // store only header fields which are requested
108 std::vector
< OUString
>::const_iterator
it( mpHeaderNames
->begin() );
109 const std::vector
< OUString
>::const_iterator
end( mpHeaderNames
->end() );
113 // header names are case insensitive
114 if ( (*it
).equalsIgnoreAsciiCase( aHeaderName
) )
116 bStoreHeaderField
= true;
126 if ( bStoreHeaderField
)
128 DAVPropertyValue thePropertyValue
;
129 thePropertyValue
.IsCaseSensitive
= false;
130 thePropertyValue
.Name
= aHeaderName
;
131 thePropertyValue
.Value
<<= OUString::createFromAscii( inHeaderValue
);
132 mpResource
->properties
.push_back( thePropertyValue
);
136 } // namespace http_dav_ucp
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */