Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / webdav / SerfRequestProcessorImpl.cxx
blobd27064c60ab772b1f8a561684f5000ef1c6de2ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <SerfRequestProcessorImpl.hxx>
22 namespace http_dav_ucp
25 SerfRequestProcessorImpl::SerfRequestProcessorImpl( const char* inPath,
26 const DAVRequestHeaders& inRequestHeaders )
27 : mPathStr( inPath )
28 , mrRequestHeaders( inRequestHeaders )
29 , mbUseChunkedEncoding( false )
33 SerfRequestProcessorImpl::~SerfRequestProcessorImpl()
37 const char* SerfRequestProcessorImpl::getPathStr() const
39 return mPathStr;
42 void SerfRequestProcessorImpl::activateChunkedEncoding()
44 mbUseChunkedEncoding = true;
47 const bool SerfRequestProcessorImpl::useChunkedEncoding() const
49 return mbUseChunkedEncoding;
52 void SerfRequestProcessorImpl::setRequestHeaders( serf_bucket_t* inoutSerfHeaderBucket )
54 DAVRequestHeaders::const_iterator aHeaderIter( mrRequestHeaders.begin() );
55 const DAVRequestHeaders::const_iterator aEnd( mrRequestHeaders.end() );
57 while ( aHeaderIter != aEnd )
59 const rtl::OString aHeader = rtl::OUStringToOString( (*aHeaderIter).first,
60 RTL_TEXTENCODING_UTF8 );
61 const rtl::OString aValue = rtl::OUStringToOString( (*aHeaderIter).second,
62 RTL_TEXTENCODING_UTF8 );
64 serf_bucket_headers_set( inoutSerfHeaderBucket,
65 aHeader.getStr(),
66 aValue.getStr() );
68 ++aHeaderIter;
71 serf_bucket_headers_set( inoutSerfHeaderBucket, "Accept-Encoding", "gzip");
74 bool SerfRequestProcessorImpl::processSerfResponseBucket( serf_request_t * /*inSerfRequest*/,
75 serf_bucket_t * inSerfResponseBucket,
76 apr_pool_t * /*inAprPool*/,
77 apr_status_t & outStatus )
79 const char* data;
80 apr_size_t len;
82 while (1) {
83 outStatus = serf_bucket_read(inSerfResponseBucket, 8096, &data, &len);
84 if (SERF_BUCKET_READ_ERROR(outStatus))
86 return true;
89 if ( len > 0 )
91 processChunkOfResponseData( data, len );
94 /* are we done yet? */
95 if (APR_STATUS_IS_EOF(outStatus))
97 handleEndOfResponseData( inSerfResponseBucket );
99 outStatus = APR_EOF;
100 return true;
103 /* have we drained the response so far? */
104 if ( APR_STATUS_IS_EAGAIN( outStatus ) )
106 return false;
110 /* NOTREACHED */
111 return true;
114 } // namespace http_dav_ucp
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */