fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / ucb / source / ucp / webdav / SerfPropFindReqProcImpl.cxx
blob5fb7680fc55b95ded17383e7c0dd40c76196f9ff
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 <SerfPropFindReqProcImpl.hxx>
21 #include <SerfTypes.hxx>
22 #include <DAVProperties.hxx>
24 #include <webdavresponseparser.hxx>
25 #include <comphelper/seqstream.hxx>
27 using namespace com::sun::star;
29 namespace http_dav_ucp
32 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath,
33 const DAVRequestHeaders& inRequestHeaders,
34 const Depth inDepth,
35 const std::vector< OUString > & inPropNames,
36 std::vector< DAVResource > & ioResources )
37 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
38 , mDepthStr( 0 )
39 , mpPropNames( &inPropNames )
40 , mpResources( &ioResources )
41 , mpResInfo( 0 )
42 , mbOnlyPropertyNames( false )
43 , xInputStream( new SerfInputStream() )
45 init( inDepth );
48 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath,
49 const DAVRequestHeaders& inRequestHeaders,
50 const Depth inDepth,
51 std::vector< DAVResourceInfo > & ioResInfo )
52 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
53 , mDepthStr( 0 )
54 , mpPropNames( 0 )
55 , mpResources( 0 )
56 , mpResInfo( &ioResInfo )
57 , mbOnlyPropertyNames( true )
58 , xInputStream( new SerfInputStream() )
60 init( inDepth );
63 void SerfPropFindReqProcImpl::init( const Depth inDepth )
65 switch ( inDepth )
67 case DAVZERO:
68 mDepthStr = "0";
69 break;
70 case DAVONE:
71 mDepthStr = "1";
72 break;
73 case DAVINFINITY:
74 mDepthStr = "infinity";
75 break;
79 SerfPropFindReqProcImpl::~SerfPropFindReqProcImpl()
83 #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">"
84 #define PROPFIND_TRAILER "</propfind>"
86 serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
88 serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest );
90 // body bucket - certain properties OR all properties OR only property names
91 serf_bucket_t* body_bkt = 0;
92 OUString aBodyText;
94 // create and fill body bucket with requested properties
95 const int nPropCount = ( !mbOnlyPropertyNames && mpPropNames )
96 ? mpPropNames->size()
97 : 0;
98 if ( nPropCount > 0 )
100 SerfPropName thePropName;
101 for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ )
103 // split fullname into namespace and name!
104 DAVProperties::createSerfPropName( (*mpPropNames)[ theIndex ],
105 thePropName );
107 /* <*propname* xmlns="*propns*" /> */
108 aBodyText += OUString::createFromAscii( "<" );
109 aBodyText += OUString::createFromAscii( thePropName.name );
110 aBodyText += OUString::createFromAscii( " xmlnx=\"" );
111 aBodyText += OUString::createFromAscii( thePropName.nspace );
112 aBodyText += OUString::createFromAscii( "\"/>" );
115 aBodyText = OUString::createFromAscii( "<prop>" ) +
116 aBodyText +
117 OUString::createFromAscii( "</prop>" );
119 else
121 if ( mbOnlyPropertyNames )
123 aBodyText = OUString::createFromAscii( "<propname/>" );
125 else
127 aBodyText = OUString::createFromAscii( "<allprop/>" );
131 aBodyText = OUString::createFromAscii( PROPFIND_HEADER ) +
132 aBodyText +
133 OUString::createFromAscii( PROPFIND_TRAILER );
134 body_bkt = SERF_BUCKET_SIMPLE_STRING( OUStringToOString( aBodyText, RTL_TEXTENCODING_UTF8 ),
135 pSerfBucketAlloc );
136 if ( useChunkedEncoding() )
138 body_bkt = serf_bucket_chunk_create( body_bkt, pSerfBucketAlloc );
142 // create serf request
143 serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
144 "PROPFIND",
145 getPathStr(),
146 body_bkt,
147 pSerfBucketAlloc );
149 // set request header fields
150 serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
151 // general header fields provided by caller
152 setRequestHeaders( hdrs_bkt );
154 // request specific header fields
155 serf_bucket_headers_set( hdrs_bkt, "Depth", mDepthStr );
156 if ( body_bkt != 0 && aBodyText.getLength() > 0 )
158 if ( useChunkedEncoding() )
160 serf_bucket_headers_set( hdrs_bkt, "Transfer-Encoding", "chunked");
162 serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" );
163 serf_bucket_headers_set( hdrs_bkt, "Content-Length",
164 OUStringToOString( OUString::valueOf( aBodyText.getLength() ), RTL_TEXTENCODING_UTF8 ) );
167 return req_bkt;
170 void SerfPropFindReqProcImpl::processChunkOfResponseData( const char* data,
171 apr_size_t len )
173 if ( xInputStream.is() )
175 xInputStream->AddToStream( data, len );
179 void SerfPropFindReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ )
181 if ( mbOnlyPropertyNames )
183 const std::vector< DAVResourceInfo > rResInfo( parseWebDAVPropNameResponse( xInputStream.get() ) );
184 *mpResInfo = rResInfo;
186 else
188 const std::vector< DAVResource > rResources( parseWebDAVPropFindResponse( xInputStream.get() ) );
189 *mpResources = rResources;
193 } // namespace http_dav_ucp
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */