1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "DAVProperties.hxx"
23 using namespace http_dav_ucp
;
25 const ::rtl::OUString
DAVProperties::CREATIONDATE
=
26 ::rtl::OUString::createFromAscii( "DAV:creationdate" );
27 const ::rtl::OUString
DAVProperties::DISPLAYNAME
=
28 ::rtl::OUString::createFromAscii( "DAV:displayname" );
29 const ::rtl::OUString
DAVProperties::GETCONTENTLANGUAGE
=
30 ::rtl::OUString::createFromAscii( "DAV:getcontentlanguage" );
31 const ::rtl::OUString
DAVProperties::GETCONTENTLENGTH
=
32 ::rtl::OUString::createFromAscii( "DAV:getcontentlength" );
33 const ::rtl::OUString
DAVProperties::GETCONTENTTYPE
=
34 ::rtl::OUString::createFromAscii( "DAV:getcontenttype" );
35 const ::rtl::OUString
DAVProperties::GETETAG
=
36 ::rtl::OUString::createFromAscii( "DAV:getetag" );
37 const ::rtl::OUString
DAVProperties::GETLASTMODIFIED
=
38 ::rtl::OUString::createFromAscii( "DAV:getlastmodified" );
39 const ::rtl::OUString
DAVProperties::LOCKDISCOVERY
=
40 ::rtl::OUString::createFromAscii( "DAV:lockdiscovery" );
41 const ::rtl::OUString
DAVProperties::RESOURCETYPE
=
42 ::rtl::OUString::createFromAscii( "DAV:resourcetype" );
43 const ::rtl::OUString
DAVProperties::SUPPORTEDLOCK
=
44 ::rtl::OUString::createFromAscii( "DAV:supportedlock" );
46 const ::rtl::OUString
DAVProperties::EXECUTABLE
=
47 ::rtl::OUString::createFromAscii(
48 "http://apache.org/dav/props/executable" );
50 // -------------------------------------------------------------------
52 void DAVProperties::createSerfPropName( const rtl::OUString
& rFullName
,
53 SerfPropName
& rName
)
55 if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DAV:" ) ) == 0 )
57 rName
.nspace
= "DAV:";
59 = strdup( rtl::OUStringToOString(
60 rFullName
.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
61 RTL_TEXTENCODING_UTF8
) );
63 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
64 "http://apache.org/dav/props/" ) ) == 0 )
66 rName
.nspace
= "http://apache.org/dav/props/";
68 = strdup( rtl::OUStringToOString(
70 RTL_CONSTASCII_LENGTH(
71 "http://apache.org/dav/props/" ) ),
72 RTL_TEXTENCODING_UTF8
) );
74 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
75 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
77 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
79 = strdup( rtl::OUStringToOString(
81 RTL_CONSTASCII_LENGTH(
82 "http://ucb.openoffice.org/dav/props/" ) ),
83 RTL_TEXTENCODING_UTF8
) );
85 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
88 // Support for 3rd party namespaces/props
90 rtl::OString aFullName
91 = rtl::OUStringToOString( rFullName
, RTL_TEXTENCODING_UTF8
);
93 // Format: <prop:the_propname xmlns:prop="the_namespace">
95 sal_Int32 nStart
= RTL_CONSTASCII_LENGTH( "<prop:" );
96 sal_Int32 nLen
= aFullName
.indexOf( ' ' ) - nStart
;
97 rName
.name
= strdup( aFullName
.copy( nStart
, nLen
) );
99 nStart
= aFullName
.indexOf( '=', nStart
+ nLen
) + 2; // after ="
100 nLen
= aFullName
.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart
;
101 rName
.nspace
= strdup( aFullName
.copy( nStart
, nLen
) );
105 // Add our namespace to our own properties.
106 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
108 = strdup( rtl::OUStringToOString( rFullName
,
109 RTL_TEXTENCODING_UTF8
) );
113 // -------------------------------------------------------------------
115 void DAVProperties::createUCBPropName( const char * nspace
,
117 rtl::OUString
& rFullName
)
119 rtl::OUString aNameSpace
120 = rtl::OStringToOUString( nspace
, RTL_TEXTENCODING_UTF8
);
122 = rtl::OStringToOUString( name
, RTL_TEXTENCODING_UTF8
);
124 if ( !aNameSpace
.getLength() )
126 // Some servers send XML without proper namespaces. Assume "DAV:"
127 // in this case, if name is a well-known dav property name.
128 // Although this is not 100% correct, it solves many problems.
130 if ( DAVProperties::RESOURCETYPE
.matchIgnoreAsciiCase( aName
, 4 ) ||
131 DAVProperties::SUPPORTEDLOCK
.matchIgnoreAsciiCase( aName
, 4 ) ||
132 DAVProperties::LOCKDISCOVERY
.matchIgnoreAsciiCase( aName
, 4 ) ||
133 DAVProperties::CREATIONDATE
.matchIgnoreAsciiCase( aName
, 4 ) ||
134 DAVProperties::DISPLAYNAME
.matchIgnoreAsciiCase( aName
, 4 ) ||
135 DAVProperties::GETCONTENTLANGUAGE
.matchIgnoreAsciiCase( aName
, 4 ) ||
136 DAVProperties::GETCONTENTLENGTH
.matchIgnoreAsciiCase( aName
, 4 ) ||
137 DAVProperties::GETCONTENTTYPE
.matchIgnoreAsciiCase( aName
, 4 ) ||
138 DAVProperties::GETETAG
.matchIgnoreAsciiCase( aName
, 4 ) ||
139 DAVProperties::GETLASTMODIFIED
.matchIgnoreAsciiCase( aName
, 4 ) )
141 aNameSpace
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DAV:" ) );
145 // Note: Concatenating strings BEFORE comparing against known namespaces
146 // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
147 rFullName
= aNameSpace
;
150 if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
153 // Okay, Just concat strings.
155 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
156 "http://apache.org/dav/props/" ) ) == 0 )
158 // Okay, Just concat strings.
160 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
161 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
163 // Remove namespace from our own properties.
164 rFullName
= rFullName
.copy(
165 RTL_CONSTASCII_LENGTH(
166 "http://ucb.openoffice.org/dav/props/" ) );
170 // Create property name that encodes, namespace and name ( XML ).
171 rFullName
= rtl::OUString::createFromAscii( "<prop:" );
173 rFullName
+= rtl::OUString::createFromAscii( " xmlns:prop=\"" );
174 rFullName
+= aNameSpace
;
175 rFullName
+= rtl::OUString::createFromAscii( "\">" );
179 // -------------------------------------------------------------------
181 bool DAVProperties::isUCBDeadProperty( const SerfPropName
& rName
)
183 return ( rName
.nspace
&&
184 ( rtl_str_compareIgnoreAsciiCase(
185 rName
.nspace
, "http://ucb.openoffice.org/dav/props/" )
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */