merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / ucp / webdav / NeonHeadRequest.cxx
blob36208be7b03ce939ba2743929b40e58cbc0d2428
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NeonHeadRequest.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include <osl/diagnose.h>
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <com/sun/star/beans/PropertyState.hpp>
36 #include "NeonHeadRequest.hxx"
38 using namespace webdav_ucp;
39 using namespace com::sun::star;
41 namespace {
43 #if NEON_VERSION >= 0x0250
44 void process_headers(ne_request *req,
45 DAVResource &rResource,
46 const std::vector< ::rtl::OUString > &rHeaderNames)
48 void *cursor = NULL;
49 const char *name, *value;
51 while ((cursor = ne_response_header_iterate(req, cursor,
52 &name, &value)) != NULL) {
53 rtl::OUString aHeaderName( rtl::OUString::createFromAscii( name ) );
54 rtl::OUString aHeaderValue( rtl::OUString::createFromAscii( value ) );
56 // Note: Empty vector means that all headers are requested.
57 bool bIncludeIt = ( rHeaderNames.size() == 0 );
59 if ( !bIncludeIt )
61 // Check whether this header was requested.
62 std::vector< ::rtl::OUString >::const_iterator it(
63 rHeaderNames.begin() );
64 const std::vector< ::rtl::OUString >::const_iterator end(
65 rHeaderNames.end() );
67 while ( it != end )
69 if ( (*it) == aHeaderName )
70 break;
72 ++it;
75 if ( it != end )
76 bIncludeIt = true;
79 if ( bIncludeIt )
81 // Create & set the PropertyValue
82 DAVPropertyValue thePropertyValue;
83 thePropertyValue.Name = aHeaderName;
84 thePropertyValue.IsCaseSensitive = false;
85 thePropertyValue.Value <<= aHeaderValue;
87 // Add the newly created PropertyValue
88 rResource.properties.push_back( thePropertyValue );
92 #else
93 struct NeonHeadRequestContext
95 DAVResource * pResource;
96 const std::vector< ::rtl::OUString > * pHeaderNames;
98 NeonHeadRequestContext( DAVResource * p,
99 const std::vector< ::rtl::OUString > * pHeaders )
100 : pResource( p ), pHeaderNames( pHeaders ) {}
103 extern "C" void NHR_ResponseHeaderCatcher( void * userdata,
104 const char * value )
106 rtl::OUString aHeader( rtl::OUString::createFromAscii( value ) );
107 sal_Int32 nPos = aHeader.indexOf( ':' );
109 if ( nPos != -1 )
111 rtl::OUString aHeaderName( aHeader.copy( 0, nPos ) );
113 NeonHeadRequestContext * pCtx
114 = static_cast< NeonHeadRequestContext * >( userdata );
116 // Note: Empty vector means that all headers are requested.
117 bool bIncludeIt = ( pCtx->pHeaderNames->size() == 0 );
119 if ( !bIncludeIt )
121 // Check whether this header was requested.
122 std::vector< ::rtl::OUString >::const_iterator it(
123 pCtx->pHeaderNames->begin() );
124 const std::vector< ::rtl::OUString >::const_iterator end(
125 pCtx->pHeaderNames->end() );
127 while ( it != end )
129 if ( (*it) == aHeaderName )
130 break;
132 ++it;
135 if ( it != end )
136 bIncludeIt = true;
139 if ( bIncludeIt )
141 // Create & set the PropertyValue
142 DAVPropertyValue thePropertyValue;
143 thePropertyValue.Name = aHeaderName;
144 thePropertyValue.IsCaseSensitive = false;
146 if ( nPos < aHeader.getLength() )
147 thePropertyValue.Value <<= aHeader.copy( nPos + 1 ).trim();
149 // Add the newly created PropertyValue
150 pCtx->pResource->properties.push_back( thePropertyValue );
154 #endif
156 } // namespace
158 // -------------------------------------------------------------------
159 // Constructor
160 // -------------------------------------------------------------------
162 NeonHeadRequest::NeonHeadRequest( HttpSession* inSession,
163 const rtl::OUString & inPath,
164 const std::vector< ::rtl::OUString > &
165 inHeaderNames,
166 DAVResource & ioResource,
167 int & nError )
169 ioResource.uri = inPath;
170 ioResource.properties.clear();
172 // Create and dispatch HEAD request. Install catcher for all response
173 // header fields.
174 ne_request * req = ne_request_create( inSession,
175 "HEAD",
176 rtl::OUStringToOString(
177 inPath,
178 RTL_TEXTENCODING_UTF8 ) );
180 #if NEON_VERSION < 0x0250
181 NeonHeadRequestContext aCtx( &ioResource, &inHeaderNames );
182 ne_add_response_header_catcher( req, NHR_ResponseHeaderCatcher, &aCtx );
183 #endif
185 nError = ne_request_dispatch( req );
187 #if NEON_VERSION >= 0x0250
188 process_headers(req, ioResource, inHeaderNames);
189 #endif
191 if ( nError == NE_OK && ne_get_status( req )->klass != 2 )
192 nError = NE_ERROR;
194 ne_request_destroy( req );
197 // -------------------------------------------------------------------
198 // Destructor
199 // -------------------------------------------------------------------
200 NeonHeadRequest::~NeonHeadRequest()