fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / webdav / SerfPropFindReqProcImpl.cxx
blob8117b1b8122121002cfba7147e72f3773c89ee56
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 "DAVProperties.hxx"
23 #include "webdavresponseparser.hxx"
24 #include <comphelper/seqstream.hxx>
25 #include <rtl/strbuf.hxx>
28 using namespace com::sun::star;
30 namespace http_dav_ucp
33 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath,
34 const DAVRequestHeaders& inRequestHeaders,
35 const Depth inDepth,
36 const std::vector< OUString > & inPropNames,
37 std::vector< DAVResource > & ioResources )
38 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
39 , mDepthStr( 0 )
40 , mpPropNames( &inPropNames )
41 , mpResources( &ioResources )
42 , mpResInfo( 0 )
43 , mbOnlyPropertyNames( false )
44 , xInputStream( new SerfInputStream() )
46 init( inDepth );
49 SerfPropFindReqProcImpl::SerfPropFindReqProcImpl( const char* inPath,
50 const DAVRequestHeaders& inRequestHeaders,
51 const Depth inDepth,
52 std::vector< DAVResourceInfo > & ioResInfo )
53 : SerfRequestProcessorImpl( inPath, inRequestHeaders )
54 , mDepthStr( 0 )
55 , mpPropNames( 0 )
56 , mpResources( 0 )
57 , mpResInfo( &ioResInfo )
58 , mbOnlyPropertyNames( true )
59 , xInputStream( new SerfInputStream() )
61 init( inDepth );
64 void SerfPropFindReqProcImpl::init( const Depth inDepth )
66 switch ( inDepth )
68 case DAVZERO:
69 mDepthStr = "0";
70 break;
71 case DAVONE:
72 mDepthStr = "1";
73 break;
74 case DAVINFINITY:
75 mDepthStr = "infinity";
76 break;
80 SerfPropFindReqProcImpl::~SerfPropFindReqProcImpl()
84 #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">"
85 #define PROPFIND_TRAILER "</propfind>"
87 serf_bucket_t * SerfPropFindReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest )
89 serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest );
91 // body bucket - certain properties OR all properties OR only property names
92 serf_bucket_t* body_bkt = 0;
93 OString aBodyText;
95 OStringBuffer aBuffer;
96 aBuffer.append( PROPFIND_HEADER );
98 // create and fill body bucket with requested properties
99 const int nPropCount = ( !mbOnlyPropertyNames && mpPropNames )
100 ? mpPropNames->size()
101 : 0;
102 if ( nPropCount > 0 )
104 aBuffer.append( "<prop>" );
105 SerfPropName thePropName;
106 for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ )
108 // split fullname into namespace and name!
109 DAVProperties::createSerfPropName( (*mpPropNames)[ theIndex ],
110 thePropName );
112 /* <*propname* xmlns="*propns*" /> */
113 aBuffer.append( "<" );
114 aBuffer.append( thePropName.name );
115 aBuffer.append( " xmlnx=\"" );
116 aBuffer.append( thePropName.nspace );
117 aBuffer.append( "\"/>" );
120 aBuffer.append( "</prop>" );
122 else
124 if ( mbOnlyPropertyNames )
126 aBuffer.append( "<propname/>" );
128 else
130 aBuffer.append( "<allprop/>" );
134 aBuffer.append( PROPFIND_TRAILER );
135 aBodyText = aBuffer.makeStringAndClear();
136 body_bkt = serf_bucket_simple_copy_create( aBodyText.getStr(),
137 aBodyText.getLength(),
138 pSerfBucketAlloc );
141 // create serf request
142 serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest,
143 "PROPFIND",
144 getPathStr(),
145 body_bkt,
146 pSerfBucketAlloc );
147 handleChunkedEncoding(req_bkt, aBodyText.getLength());
149 // set request header fields
150 serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt );
151 if (hdrs_bkt != NULL)
153 // general header fields provided by caller
154 setRequestHeaders( hdrs_bkt );
156 // request specific header fields
157 serf_bucket_headers_set( hdrs_bkt, "Depth", mDepthStr );
158 if (hdrs_bkt!=NULL && body_bkt != 0 && aBodyText.getLength() > 0 )
160 serf_bucket_headers_set( hdrs_bkt, "Content-Type", "application/xml" );
163 else
165 assert("Headers Bucket missing");
168 return req_bkt;
171 void SerfPropFindReqProcImpl::processChunkOfResponseData( const char* data,
172 apr_size_t len )
174 if ( xInputStream.is() )
176 xInputStream->AddToStream( data, len );
180 void SerfPropFindReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ )
182 if ( mbOnlyPropertyNames )
184 const std::vector< DAVResourceInfo > rResInfo( parseWebDAVPropNameResponse( xInputStream.get() ) );
185 *mpResInfo = rResInfo;
187 else
189 const std::vector< DAVResource > rResources( parseWebDAVPropFindResponse( xInputStream.get() ) );
190 *mpResources = rResources;
194 } // namespace http_dav_ucp
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */