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: NeonPropFindRequest.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 "NeonTypes.hxx"
35 #include "DAVException.hxx"
36 #include "DAVProperties.hxx"
37 #include "NeonPropFindRequest.hxx"
38 #ifndef _LINKSEQUENCE_HXX_
39 #include "LinkSequence.hxx"
41 #include "LockSequence.hxx"
42 #include "LockEntrySequence.hxx"
43 #include "UCBDeadPropertyValue.hxx"
46 using namespace com::sun::star::uno
;
47 using namespace com::sun::star::ucb
;
49 using namespace webdav_ucp
;
51 // -------------------------------------------------------------------
52 extern "C" int NPFR_propfind_iter( void* userdata
,
53 const NeonPropName
* pname
,
55 const HttpStatus
* status
)
58 HTTP Response Status Classes:
60 - 1: Informational - Request received, continuing process
62 - 2: Success - The action was successfully received,
63 understood, and accepted
65 - 3: Redirection - Further action must be taken in order to
68 - 4: Client Error - The request contains bad syntax or cannot
71 - 5: Server Error - The server failed to fulfill an apparently
75 if ( status
->klass
> 2 )
76 return 0; // Error getting this property. Go on.
78 // Create & set the PropertyValue
79 DAVPropertyValue thePropertyValue
;
80 thePropertyValue
.IsCaseSensitive
= true;
82 DAVProperties::createUCBPropName( pname
->nspace
,
84 thePropertyValue
.Name
);
85 bool bHasValue
= false;
86 if ( DAVProperties::isUCBDeadProperty( *pname
) )
88 // DAV dead property added by WebDAV UCP?
89 if ( UCBDeadPropertyValue::createFromXML(
90 value
, thePropertyValue
.Value
) )
91 OSL_ENSURE( thePropertyValue
.Value
.hasValue(),
92 "NeonPropFindRequest::propfind_iter - No value!" );
98 if ( rtl_str_compareIgnoreAsciiCase(
99 pname
->name
, "resourcetype" ) == 0 )
101 OString
aValue( value
);
102 aValue
= aValue
.trim(); // #107358# remove leading/trailing spaces
103 if ( aValue
.getLength() )
105 aValue
= aValue
.toAsciiLowerCase();
108 RTL_CONSTASCII_STRINGPARAM( "<collection" ) ) == 0 ) ||
110 RTL_CONSTASCII_STRINGPARAM( "<dav:collection" ) ) == 0 )
113 thePropertyValue
.Value
114 <<= OUString::createFromAscii( "collection" );
118 if ( !thePropertyValue
.Value
.hasValue() )
120 // Take over the value exactly as supplied by the server.
121 thePropertyValue
.Value
<<= OUString::createFromAscii( value
);
124 else if ( rtl_str_compareIgnoreAsciiCase(
125 pname
->name
, "supportedlock" ) == 0 )
127 Sequence
< LockEntry
> aEntries
;
128 LockEntrySequence::createFromXML( value
, aEntries
);
129 thePropertyValue
.Value
<<= aEntries
;
131 else if ( rtl_str_compareIgnoreAsciiCase(
132 pname
->name
, "lockdiscovery" ) == 0 )
134 Sequence
< Lock
> aLocks
;
135 LockSequence::createFromXML( value
, aLocks
);
136 thePropertyValue
.Value
<<= aLocks
;
138 else if ( rtl_str_compareIgnoreAsciiCase( pname
->name
, "source" ) == 0 )
140 Sequence
< Link
> aLinks
;
141 LinkSequence::createFromXML( value
, aLinks
);
142 thePropertyValue
.Value
<<= aLinks
;
146 thePropertyValue
.Value
147 <<= OStringToOUString( value
, RTL_TEXTENCODING_UTF8
);
151 // Add the newly created PropertyValue
152 DAVResource
* theResource
= static_cast< DAVResource
* >( userdata
);
153 theResource
->properties
.push_back( thePropertyValue
);
158 // -------------------------------------------------------------------
159 extern "C" void NPFR_propfind_results( void* userdata
,
160 #if NEON_VERSION >= 0x0260
165 const NeonPropFindResultSet
* set
)
167 // @@@ href is not the uri! DAVResource ctor wants uri!
169 #if NEON_VERSION >= 0x0260
170 DAVResource
theResource(
171 OStringToOUString( uri
->path
, RTL_TEXTENCODING_UTF8
) );
173 DAVResource
theResource(
174 OStringToOUString( href
, RTL_TEXTENCODING_UTF8
) );
177 ne_propset_iterate( set
, NPFR_propfind_iter
, &theResource
);
179 // Add entry to resources list.
180 vector
< DAVResource
> * theResources
181 = static_cast< vector
< DAVResource
> * >( userdata
);
182 theResources
->push_back( theResource
);
184 // -------------------------------------------------------------------
185 extern "C" int NPFR_propnames_iter( void* userdata
,
186 const NeonPropName
* pname
,
187 const char* /*value*/,
188 const HttpStatus
* /*status*/ )
191 DAVProperties::createUCBPropName( pname
->nspace
,
195 DAVResourceInfo
* theResource
= static_cast< DAVResourceInfo
* >( userdata
);
196 theResource
->properties
.push_back( aFullName
);
200 // -------------------------------------------------------------------
201 extern "C" void NPFR_propnames_results( void* userdata
,
202 #if NEON_VERSION >= 0x0260
207 const NeonPropFindResultSet
* results
)
209 // @@@ href is not the uri! DAVResourceInfo ctor wants uri!
210 // Create entry for the resource.
211 #if NEON_VERSION >= 0x0260
212 DAVResourceInfo
theResource(
213 OStringToOUString( uri
->path
, RTL_TEXTENCODING_UTF8
) );
215 DAVResourceInfo
theResource(
216 OStringToOUString( href
, RTL_TEXTENCODING_UTF8
) );
220 ne_propset_iterate( results
, NPFR_propnames_iter
, &theResource
);
222 // Add entry to resources list.
223 vector
< DAVResourceInfo
> * theResources
224 = static_cast< vector
< DAVResourceInfo
> * >( userdata
);
225 theResources
->push_back( theResource
);
228 // -------------------------------------------------------------------
230 // -------------------------------------------------------------------
232 NeonPropFindRequest::NeonPropFindRequest( HttpSession
* inSession
,
235 const vector
< OUString
>& inPropNames
,
236 vector
< DAVResource
>& ioResources
,
239 // Generate the list of properties we're looking for
240 int thePropCount
= inPropNames
.size();
241 if ( thePropCount
> 0 )
243 NeonPropName
* thePropNames
= new NeonPropName
[ thePropCount
+ 1 ];
246 for ( theIndex
= 0; theIndex
< thePropCount
; theIndex
++ )
248 // Split fullname into namespace and name!
249 DAVProperties::createNeonPropName(
250 inPropNames
[ theIndex
], thePropNames
[ theIndex
] );
252 thePropNames
[ theIndex
].nspace
= NULL
;
253 thePropNames
[ theIndex
].name
= NULL
;
255 nError
= ne_simple_propfind( inSession
,
259 NPFR_propfind_results
,
262 for ( theIndex
= 0; theIndex
< thePropCount
; theIndex
++ )
263 free( (void *)thePropNames
[ theIndex
].name
);
265 delete [] thePropNames
;
270 nError
= ne_simple_propfind( inSession
,
273 NULL
, // 0 == allprop
274 NPFR_propfind_results
,
278 // #87585# - Sometimes neon lies (because some servers lie).
279 if ( ( nError
== NE_OK
) && ioResources
.empty() )
283 // -------------------------------------------------------------------
285 // - obtains property names
286 // -------------------------------------------------------------------
288 NeonPropFindRequest::NeonPropFindRequest(
289 HttpSession
* inSession
,
292 std::vector
< DAVResourceInfo
> & ioResInfo
,
295 nError
= ne_propnames( inSession
,
298 NPFR_propnames_results
,
301 // #87585# - Sometimes neon lies (because some servers lie).
302 if ( ( nError
== NE_OK
) && ioResInfo
.empty() )
306 // -------------------------------------------------------------------
308 // -------------------------------------------------------------------
309 NeonPropFindRequest::~NeonPropFindRequest( )