LibreOffice Module ucb (master)  1
SerfPostReqProcImpl.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 "SerfPostReqProcImpl.hxx"
21 
22 #include <serf.h>
23 
24 using namespace com::sun::star;
25 
26 namespace http_dav_ucp
27 {
28 
29 SerfPostReqProcImpl::SerfPostReqProcImpl( const char* inPath,
30  const DAVRequestHeaders& inRequestHeaders,
31  const char* inData,
32  apr_size_t inDataLen,
33  const char* inContentType,
34  const char* inReferer,
35  const rtl::Reference< SerfInputStream > & xioInStrm )
36  : SerfRequestProcessorImpl( inPath, inRequestHeaders )
37  , mpPostData( inData )
38  , mnPostDataLen( inDataLen )
39  , mpContentType( inContentType )
40  , mpReferer( inReferer )
41  , xInputStream( xioInStrm )
42  , xOutputStream()
43 {
44 }
45 
47  const DAVRequestHeaders& inRequestHeaders,
48  const char* inData,
49  apr_size_t inDataLen,
50  const char* inContentType,
51  const char* inReferer,
52  const css::uno::Reference< css::io::XOutputStream > & xioOutStrm )
53  : SerfRequestProcessorImpl( inPath, inRequestHeaders )
54  , mpPostData( inData )
55  , mnPostDataLen( inDataLen )
56  , mpContentType( inContentType )
57  , mpReferer( inReferer )
58  , xInputStream()
59  , xOutputStream( xioOutStrm )
60 {
61 }
62 
64 {
65 }
66 
67 serf_bucket_t * SerfPostReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
68 {
69  serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest );
70 
71  // create body bucket
72  serf_bucket_t* body_bkt = nullptr;
73  if ( mpPostData != nullptr && mnPostDataLen > 0 )
74  {
75  body_bkt = SERF_BUCKET_SIMPLE_STRING_LEN( mpPostData, mnPostDataLen, pSerfBucketAlloc );
76  }
77 
78  // create serf request
79  serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
80  "POST",
81  getPathStr(),
82  body_bkt,
83  serf_request_get_alloc( inSerfRequest ) );
84 
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 );
89 
91 
92  // request specific header fields
93  if ( mpContentType != nullptr )
94  {
95  serf_bucket_headers_set( hdrs_bkt, "Content-Type", mpContentType );
96  }
97  if ( mpReferer != nullptr )
98  {
99  serf_bucket_headers_set( hdrs_bkt, "Referer", mpReferer );
100  }
101 
102  return req_bkt;
103 }
104 
106  apr_size_t len )
107 {
108  if ( xInputStream.is() )
109  {
110  xInputStream->AddToStream( data, len );
111  }
112  else if ( xOutputStream.is() )
113  {
114  const uno::Sequence< sal_Int8 > aDataSeq( reinterpret_cast<const sal_Int8 *>(data), len );
115  xOutputStream->writeBytes( aDataSeq );
116  }
117 }
118 
119 void SerfPostReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ )
120 {
121  // nothing to do;
122 }
123 
124 } // namespace http_dav_ucp
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< DAVRequestHeader > DAVRequestHeaders
virtual void handleEndOfResponseData(serf_bucket_t *inSerfResponseBucket) override
void setRequestHeaders(serf_bucket_t *inoutSerfHeaderBucket)
rtl::Reference< SerfInputStream > xInputStream
css::uno::Reference< css::io::XOutputStream > xOutputStream
void handleChunkedEncoding(serf_bucket_t *pRequestBucket, apr_int64_t nLength) const
Turn chunked encoding on or off, depending on the result of useChunkedEncoding(). ...
SerfPostReqProcImpl(const char *inPath, const DAVRequestHeaders &inRequestHeaders, const char *inData, apr_size_t inDataLen, const char *inContentType, const char *inReferer, const rtl::Reference< SerfInputStream > &xioInStrm)
virtual serf_bucket_t * createSerfRequestBucket(serf_request_t *inSerfRequest) override
virtual void processChunkOfResponseData(const char *data, apr_size_t len) override