1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NeonHeadRequest.cxx,v $
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
;
43 #if NEON_VERSION >= 0x0250
44 void process_headers(ne_request
*req
,
45 DAVResource
&rResource
,
46 const std::vector
< ::rtl::OUString
> &rHeaderNames
)
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 );
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(
69 if ( (*it
) == aHeaderName
)
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
);
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
,
106 rtl::OUString
aHeader( rtl::OUString::createFromAscii( value
) );
107 sal_Int32 nPos
= aHeader
.indexOf( ':' );
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 );
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() );
129 if ( (*it
) == aHeaderName
)
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
);
158 // -------------------------------------------------------------------
160 // -------------------------------------------------------------------
162 NeonHeadRequest::NeonHeadRequest( HttpSession
* inSession
,
163 const rtl::OUString
& inPath
,
164 const std::vector
< ::rtl::OUString
> &
166 DAVResource
& ioResource
,
169 ioResource
.uri
= inPath
;
170 ioResource
.properties
.clear();
172 // Create and dispatch HEAD request. Install catcher for all response
174 ne_request
* req
= ne_request_create( inSession
,
176 rtl::OUStringToOString(
178 RTL_TEXTENCODING_UTF8
) );
180 #if NEON_VERSION < 0x0250
181 NeonHeadRequestContext
aCtx( &ioResource
, &inHeaderNames
);
182 ne_add_response_header_catcher( req
, NHR_ResponseHeaderCatcher
, &aCtx
);
185 nError
= ne_request_dispatch( req
);
187 #if NEON_VERSION >= 0x0250
188 process_headers(req
, ioResource
, inHeaderNames
);
191 if ( nError
== NE_OK
&& ne_get_status( req
)->klass
!= 2 )
194 ne_request_destroy( req
);
197 // -------------------------------------------------------------------
199 // -------------------------------------------------------------------
200 NeonHeadRequest::~NeonHeadRequest()