18590a0fdSAndre Fischer /************************************************************** 28590a0fdSAndre Fischer * 38590a0fdSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 48590a0fdSAndre Fischer * or more contributor license agreements. See the NOTICE file 58590a0fdSAndre Fischer * distributed with this work for additional information 68590a0fdSAndre Fischer * regarding copyright ownership. The ASF licenses this file 78590a0fdSAndre Fischer * to you under the Apache License, Version 2.0 (the 88590a0fdSAndre Fischer * "License"); you may not use this file except in compliance 98590a0fdSAndre Fischer * with the License. You may obtain a copy of the License at 108590a0fdSAndre Fischer * 118590a0fdSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 128590a0fdSAndre Fischer * 138590a0fdSAndre Fischer * Unless required by applicable law or agreed to in writing, 148590a0fdSAndre Fischer * software distributed under the License is distributed on an 158590a0fdSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 168590a0fdSAndre Fischer * KIND, either express or implied. See the License for the 178590a0fdSAndre Fischer * specific language governing permissions and limitations 188590a0fdSAndre Fischer * under the License. 198590a0fdSAndre Fischer * 208590a0fdSAndre Fischer *************************************************************/ 218590a0fdSAndre Fischer 228590a0fdSAndre Fischer // MARKER(update_precomp.py): autogen include statement, do not remove 238590a0fdSAndre Fischer #include "precompiled_ucb.hxx" 248590a0fdSAndre Fischer 258590a0fdSAndre Fischer #include <SerfPostReqProcImpl.hxx> 268590a0fdSAndre Fischer 278590a0fdSAndre Fischer #include <serf.h> 288590a0fdSAndre Fischer 298590a0fdSAndre Fischer using namespace com::sun::star; 308590a0fdSAndre Fischer 318590a0fdSAndre Fischer namespace http_dav_ucp 328590a0fdSAndre Fischer { 338590a0fdSAndre Fischer 348590a0fdSAndre Fischer SerfPostReqProcImpl::SerfPostReqProcImpl( const char* inPath, 35e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders, 368590a0fdSAndre Fischer const char* inData, 378590a0fdSAndre Fischer apr_size_t inDataLen, 388590a0fdSAndre Fischer const char* inContentType, 398590a0fdSAndre Fischer const char* inReferer, 408590a0fdSAndre Fischer const com::sun::star::uno::Reference< SerfInputStream > & xioInStrm ) 41e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders ) 428590a0fdSAndre Fischer , mpPostData( inData ) 438590a0fdSAndre Fischer , mnPostDataLen( inDataLen ) 448590a0fdSAndre Fischer , mpContentType( inContentType ) 458590a0fdSAndre Fischer , mpReferer( inReferer ) 468590a0fdSAndre Fischer , xInputStream( xioInStrm ) 478590a0fdSAndre Fischer , xOutputStream() 488590a0fdSAndre Fischer { 498590a0fdSAndre Fischer } 508590a0fdSAndre Fischer 518590a0fdSAndre Fischer SerfPostReqProcImpl::SerfPostReqProcImpl( const char* inPath, 52e9ff7e89SOliver-Rainer Wittmann const DAVRequestHeaders& inRequestHeaders, 538590a0fdSAndre Fischer const char* inData, 548590a0fdSAndre Fischer apr_size_t inDataLen, 558590a0fdSAndre Fischer const char* inContentType, 568590a0fdSAndre Fischer const char* inReferer, 578590a0fdSAndre Fischer const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > & xioOutStrm ) 58e9ff7e89SOliver-Rainer Wittmann : SerfRequestProcessorImpl( inPath, inRequestHeaders ) 598590a0fdSAndre Fischer , mpPostData( inData ) 608590a0fdSAndre Fischer , mnPostDataLen( inDataLen ) 618590a0fdSAndre Fischer , mpContentType( inContentType ) 628590a0fdSAndre Fischer , mpReferer( inReferer ) 638590a0fdSAndre Fischer , xInputStream() 648590a0fdSAndre Fischer , xOutputStream( xioOutStrm ) 658590a0fdSAndre Fischer { 668590a0fdSAndre Fischer } 678590a0fdSAndre Fischer 688590a0fdSAndre Fischer SerfPostReqProcImpl::~SerfPostReqProcImpl() 698590a0fdSAndre Fischer { 708590a0fdSAndre Fischer } 718590a0fdSAndre Fischer 728590a0fdSAndre Fischer serf_bucket_t * SerfPostReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) 738590a0fdSAndre Fischer { 748590a0fdSAndre Fischer serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest ); 758590a0fdSAndre Fischer 768590a0fdSAndre Fischer // create body bucket 778590a0fdSAndre Fischer serf_bucket_t* body_bkt = 0; 788590a0fdSAndre Fischer if ( mpPostData != 0 && mnPostDataLen > 0 ) 798590a0fdSAndre Fischer { 808590a0fdSAndre Fischer body_bkt = SERF_BUCKET_SIMPLE_STRING_LEN( mpPostData, mnPostDataLen, pSerfBucketAlloc ); 818590a0fdSAndre Fischer } 828590a0fdSAndre Fischer 838590a0fdSAndre Fischer // create serf request 848590a0fdSAndre Fischer serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, 858590a0fdSAndre Fischer "POST", 868590a0fdSAndre Fischer getPathStr(), 878590a0fdSAndre Fischer body_bkt, 888590a0fdSAndre Fischer serf_request_get_alloc( inSerfRequest ) ); 89*10e20387SAndre Fischer handleChunkedEncoding(req_bkt, mnPostDataLen); 908590a0fdSAndre Fischer 918590a0fdSAndre Fischer // set request header fields 928590a0fdSAndre Fischer serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); 93e9ff7e89SOliver-Rainer Wittmann // general header fields provided by caller 94e9ff7e89SOliver-Rainer Wittmann setRequestHeaders( hdrs_bkt ); 958590a0fdSAndre Fischer 968590a0fdSAndre Fischer // request specific header fields 978590a0fdSAndre Fischer if ( mpContentType != 0 ) 988590a0fdSAndre Fischer { 99e9ff7e89SOliver-Rainer Wittmann serf_bucket_headers_set( hdrs_bkt, "Content-Type", mpContentType ); 1008590a0fdSAndre Fischer } 1018590a0fdSAndre Fischer if ( mpReferer != 0 ) 1028590a0fdSAndre Fischer { 103e9ff7e89SOliver-Rainer Wittmann serf_bucket_headers_set( hdrs_bkt, "Referer", mpReferer ); 1048590a0fdSAndre Fischer } 1058590a0fdSAndre Fischer 1068590a0fdSAndre Fischer return req_bkt; 1078590a0fdSAndre Fischer } 1088590a0fdSAndre Fischer 10949989859SOliver-Rainer Wittmann void SerfPostReqProcImpl::processChunkOfResponseData( const char* data, 11049989859SOliver-Rainer Wittmann apr_size_t len ) 1118590a0fdSAndre Fischer { 11249989859SOliver-Rainer Wittmann if ( xInputStream.is() ) 11349989859SOliver-Rainer Wittmann { 11449989859SOliver-Rainer Wittmann xInputStream->AddToStream( data, len ); 11549989859SOliver-Rainer Wittmann } 11649989859SOliver-Rainer Wittmann else if ( xOutputStream.is() ) 11749989859SOliver-Rainer Wittmann { 11849989859SOliver-Rainer Wittmann const uno::Sequence< sal_Int8 > aDataSeq( (sal_Int8 *)data, len ); 11949989859SOliver-Rainer Wittmann xOutputStream->writeBytes( aDataSeq ); 1208590a0fdSAndre Fischer } 12149989859SOliver-Rainer Wittmann } 1228590a0fdSAndre Fischer 12349989859SOliver-Rainer Wittmann void SerfPostReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ ) 12449989859SOliver-Rainer Wittmann { 12549989859SOliver-Rainer Wittmann // nothing to do; 1268590a0fdSAndre Fischer } 127307c6619SOliver-Rainer Wittmann 1288590a0fdSAndre Fischer } // namespace http_dav_ucp 129