1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_ucb.hxx" 24 25 #include <SerfPostReqProcImpl.hxx> 26 27 #include <serf.h> 28 29 using namespace com::sun::star; 30 31 namespace http_dav_ucp 32 { 33 34 SerfPostReqProcImpl::SerfPostReqProcImpl( const char* inPath, 35 const char* inData, 36 apr_size_t inDataLen, 37 const char* inContentType, 38 const char* inReferer, 39 const com::sun::star::uno::Reference< SerfInputStream > & xioInStrm ) 40 : SerfRequestProcessorImpl( inPath ) 41 , mpPostData( inData ) 42 , mnPostDataLen( inDataLen ) 43 , mpContentType( inContentType ) 44 , mpReferer( inReferer ) 45 , xInputStream( xioInStrm ) 46 , xOutputStream() 47 { 48 } 49 50 SerfPostReqProcImpl::SerfPostReqProcImpl( const char* inPath, 51 const char* inData, 52 apr_size_t inDataLen, 53 const char* inContentType, 54 const char* inReferer, 55 const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > & xioOutStrm ) 56 : SerfRequestProcessorImpl( inPath ) 57 , mpPostData( inData ) 58 , mnPostDataLen( inDataLen ) 59 , mpContentType( inContentType ) 60 , mpReferer( inReferer ) 61 , xInputStream() 62 , xOutputStream( xioOutStrm ) 63 { 64 } 65 66 SerfPostReqProcImpl::~SerfPostReqProcImpl() 67 { 68 } 69 70 serf_bucket_t * SerfPostReqProcImpl::createSerfRequestBucket( serf_request_t * inSerfRequest ) 71 { 72 serf_bucket_alloc_t* pSerfBucketAlloc = serf_request_get_alloc( inSerfRequest ); 73 74 // create body bucket 75 serf_bucket_t* body_bkt = 0; 76 if ( mpPostData != 0 && mnPostDataLen > 0 ) 77 { 78 body_bkt = SERF_BUCKET_SIMPLE_STRING_LEN( mpPostData, mnPostDataLen, pSerfBucketAlloc ); 79 if ( useChunkedEncoding() ) 80 { 81 body_bkt = serf_bucket_chunk_create( body_bkt, pSerfBucketAlloc ); 82 } 83 } 84 85 // create serf request 86 serf_bucket_t *req_bkt = serf_request_bucket_request_create( inSerfRequest, 87 "POST", 88 getPathStr(), 89 body_bkt, 90 serf_request_get_alloc( inSerfRequest ) ); 91 92 // TODO - correct headers 93 // set request header fields 94 serf_bucket_t* hdrs_bkt = serf_bucket_request_get_headers( req_bkt ); 95 serf_bucket_headers_setn( hdrs_bkt, "User-Agent", "www.openoffice.org/ucb/" ); 96 serf_bucket_headers_setn( hdrs_bkt, "Accept-Encoding", "gzip"); 97 98 // request specific header fields 99 if ( body_bkt != 0 ) 100 { 101 if ( useChunkedEncoding() ) 102 { 103 serf_bucket_headers_setn( hdrs_bkt, "Transfer-Encoding", "chunked"); 104 } 105 serf_bucket_headers_setn( hdrs_bkt, "Content-Length", 106 rtl::OUStringToOString( rtl::OUString::valueOf( (sal_Int32)mnPostDataLen ), RTL_TEXTENCODING_UTF8 ) ); 107 } 108 if ( mpContentType != 0 ) 109 { 110 serf_bucket_headers_setn( hdrs_bkt, "Content-Type", mpContentType ); 111 } 112 if ( mpReferer != 0 ) 113 { 114 serf_bucket_headers_setn( hdrs_bkt, "Referer", mpReferer ); 115 } 116 117 return req_bkt; 118 } 119 120 void SerfPostReqProcImpl::processChunkOfResponseData( const char* data, 121 apr_size_t len ) 122 { 123 if ( xInputStream.is() ) 124 { 125 xInputStream->AddToStream( data, len ); 126 } 127 else if ( xOutputStream.is() ) 128 { 129 const uno::Sequence< sal_Int8 > aDataSeq( (sal_Int8 *)data, len ); 130 xOutputStream->writeBytes( aDataSeq ); 131 } 132 } 133 134 void SerfPostReqProcImpl::handleEndOfResponseData( serf_bucket_t * /*inSerfResponseBucket*/ ) 135 { 136 // nothing to do; 137 } 138 139 } // namespace http_dav_ucp 140