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 "SerfPostReqProcImpl.hxx"
24 using namespace com::sun::star
;
26 namespace http_dav_ucp
29 SerfPostReqProcImpl::SerfPostReqProcImpl( const char* inPath
,
30 const DAVRequestHeaders
& inRequestHeaders
,
33 const char* inContentType
,
34 const char* inReferer
,
35 const com::sun::star::uno::Reference
< SerfInputStream
> & xioInStrm
)
36 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
37 , mpPostData( inData
)
38 , mnPostDataLen( inDataLen
)
39 , mpContentType( inContentType
)
40 , mpReferer( inReferer
)
41 , xInputStream( xioInStrm
)
46 SerfPostReqProcImpl::SerfPostReqProcImpl( const char* inPath
,
47 const DAVRequestHeaders
& inRequestHeaders
,
50 const char* inContentType
,
51 const char* inReferer
,
52 const com::sun::star::uno::Reference
< com::sun::star::io::XOutputStream
> & xioOutStrm
)
53 : SerfRequestProcessorImpl( inPath
, inRequestHeaders
)
54 , mpPostData( inData
)
55 , mnPostDataLen( inDataLen
)
56 , mpContentType( inContentType
)
57 , mpReferer( inReferer
)
59 , xOutputStream( xioOutStrm
)
63 SerfPostReqProcImpl::~SerfPostReqProcImpl()
67 serf_bucket_t
* SerfPostReqProcImpl::createSerfRequestBucket( serf_request_t
* inSerfRequest
)
69 serf_bucket_alloc_t
* pSerfBucketAlloc
= serf_request_get_alloc( inSerfRequest
);
72 serf_bucket_t
* body_bkt
= 0;
73 if ( mpPostData
!= 0 && mnPostDataLen
> 0 )
75 body_bkt
= SERF_BUCKET_SIMPLE_STRING_LEN( mpPostData
, mnPostDataLen
, pSerfBucketAlloc
);
78 // create serf request
79 serf_bucket_t
*req_bkt
= serf_request_bucket_request_create( inSerfRequest
,
83 serf_request_get_alloc( inSerfRequest
) );
85 // set request header fields
86 serf_bucket_t
* hdrs_bkt
= serf_bucket_request_get_headers( req_bkt
);
87 // general header fields provided by caller
88 setRequestHeaders( hdrs_bkt
);
90 handleChunkedEncoding(req_bkt
, mnPostDataLen
);
92 // request specific header fields
93 if ( mpContentType
!= 0 )
95 serf_bucket_headers_set( hdrs_bkt
, "Content-Type", mpContentType
);
99 serf_bucket_headers_set( hdrs_bkt
, "Referer", mpReferer
);
105 void SerfPostReqProcImpl::processChunkOfResponseData( const char* data
,
108 if ( xInputStream
.is() )
110 xInputStream
->AddToStream( data
, len
);
112 else if ( xOutputStream
.is() )
114 const uno::Sequence
< sal_Int8
> aDataSeq( (sal_Int8
*)data
, len
);
115 xOutputStream
->writeBytes( aDataSeq
);
119 void SerfPostReqProcImpl::handleEndOfResponseData( serf_bucket_t
* /*inSerfResponseBucket*/ )
124 } // namespace http_dav_ucp
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */