LibreOffice Module ucb (master)  1
SerfPutReqProcImpl.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 <rtl/ustring.hxx>
21 
22 #include "SerfPutReqProcImpl.hxx"
23 
24 #include <serf.h>
25 
26 namespace http_dav_ucp
27 {
28 
30  const DAVRequestHeaders& inRequestHeaders,
31  const char* inData,
32  apr_size_t inDataLen,
33  const OUString& sToken )
34  : SerfRequestProcessorImpl( inPath, inRequestHeaders )
35  , mpData( inData )
36  , mnDataLen( inDataLen )
37  , msToken( sToken )
38 {
39 }
40 
42 {
43 }
44 
45 serf_bucket_t * SerfPutReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
46 {
47  serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest );
48 
49  // create body bucket
50  serf_bucket_t* body_bkt = nullptr;
51  if ( mpData != nullptr && mnDataLen > 0 )
52  {
53  body_bkt = SERF_BUCKET_SIMPLE_STRING_LEN( mpData, mnDataLen, pSerfBucketAlloc );
54  }
55 
56  // create serf request
57  serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
58  "PUT",
59  getPathStr(),
60  body_bkt,
61  serf_request_get_alloc( inSerfRequest ) );
63 
64  // set request header fields
65  serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
66  // general header fields provided by caller
67  setRequestHeaders( hdrs_bkt );
68 
69  // 'If' header with token, so that we can save document locked by us
70  const OString sIfHeader( "<" + OString(getPathStr()) + "> (<" + OUStringToOString(
71  msToken, RTL_TEXTENCODING_UTF8) + ">)" );
72  serf_bucket_headers_set( hdrs_bkt, "If", sIfHeader.getStr() );
73 
74  return req_bkt;
75 }
76 
78  apr_size_t /*len*/ )
79 {
80  // nothing to do;
81 }
82 
83 void SerfPutReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ )
84 {
85  // nothing to do;
86 }
87 
88 } // namespace http_dav_ucp
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< DAVRequestHeader > DAVRequestHeaders
void setRequestHeaders(serf_bucket_t *inoutSerfHeaderBucket)
SerfPutReqProcImpl(const char *inPath, const DAVRequestHeaders &inRequestHeaders, const char *inData, apr_size_t inDataLen, const OUString &sToken)
virtual serf_bucket_t * createSerfRequestBucket(serf_request_t *inSerfRequest) override
virtual void processChunkOfResponseData(const char *data, apr_size_t len) override
void handleChunkedEncoding(serf_bucket_t *pRequestBucket, apr_int64_t nLength) const
Turn chunked encoding on or off, depending on the result of useChunkedEncoding(). ...
virtual void handleEndOfResponseData(serf_bucket_t *inSerfResponseBucket) override
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)