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 "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
)
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
)
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
)
56 , xOutputStream( xioOutStrm
)
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
)
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
,
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
);
96 void SerfGetReqProcImpl::processChunkOfResponseData( const char* data
,
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
);
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
,
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
,
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;
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() );
159 // header names are case insensitive
160 if ( (*it
).equalsIgnoreAsciiCase( aHeaderName
) )
162 bStoreHeaderField
= true;
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: */