xref: /trunk/main/ucb/source/ucp/webdav/DAVProperties.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52f86921cSAndrew Rist  * distributed with this work for additional information
62f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist  * software distributed under the License is distributed on an
152f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
172f86921cSAndrew Rist  * specific language governing permissions and limitations
182f86921cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202f86921cSAndrew Rist  *************************************************************/
212f86921cSAndrew Rist 
222f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25421ed02eSdamjan #include "precompiled_webdav.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir #include "DAVProperties.hxx"
2906594b87SAriel Constenla-Haile #include <rtl/ustrbuf.hxx>
30cdf0e10cSrcweir 
3159ddfc10SAndre Fischer using namespace http_dav_ucp;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir const ::rtl::OUString DAVProperties::CREATIONDATE =
34cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:creationdate" );
35cdf0e10cSrcweir const ::rtl::OUString DAVProperties::DISPLAYNAME =
36cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:displayname" );
37cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETCONTENTLANGUAGE =
38cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getcontentlanguage" );
39cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETCONTENTLENGTH =
40cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getcontentlength" );
41cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETCONTENTTYPE =
42cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getcontenttype" );
43cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETETAG =
44cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getetag" );
45cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETLASTMODIFIED =
46cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getlastmodified" );
47cdf0e10cSrcweir const ::rtl::OUString DAVProperties::LOCKDISCOVERY =
48cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:lockdiscovery" );
49cdf0e10cSrcweir const ::rtl::OUString DAVProperties::RESOURCETYPE =
50cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:resourcetype" );
51cdf0e10cSrcweir const ::rtl::OUString DAVProperties::SUPPORTEDLOCK =
52cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:supportedlock" );
53cdf0e10cSrcweir 
54cdf0e10cSrcweir const ::rtl::OUString DAVProperties::EXECUTABLE =
55cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii(
56cdf0e10cSrcweir                                 "http://apache.org/dav/props/executable" );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // -------------------------------------------------------------------
59cdf0e10cSrcweir // static
createCurlPropName(const rtl::OUString & rFullName,CurlPropName & rName)60*51ba086bSDamjan Jovanovic void DAVProperties::createCurlPropName( const rtl::OUString & rFullName,
61*51ba086bSDamjan Jovanovic                                         CurlPropName & rName )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DAV:" ) ) == 0 )
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         rName.nspace = "DAV:";
66cdf0e10cSrcweir         rName.name
67cdf0e10cSrcweir             = strdup( rtl::OUStringToOString(
68cdf0e10cSrcweir                         rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
6924c56ab9SHerbert Dürr                                         RTL_TEXTENCODING_UTF8 ).getStr() );
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
72cdf0e10cSrcweir                 "http://apache.org/dav/props/" ) ) == 0 )
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir         rName.nspace = "http://apache.org/dav/props/";
75cdf0e10cSrcweir         rName.name
76cdf0e10cSrcweir             = strdup( rtl::OUStringToOString(
77cdf0e10cSrcweir                         rFullName.copy(
78cdf0e10cSrcweir                             RTL_CONSTASCII_LENGTH(
79cdf0e10cSrcweir                                 "http://apache.org/dav/props/" ) ),
8024c56ab9SHerbert Dürr                             RTL_TEXTENCODING_UTF8 ).getStr() );
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
83cdf0e10cSrcweir                 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         rName.nspace = "http://ucb.openoffice.org/dav/props/";
86cdf0e10cSrcweir         rName.name
87cdf0e10cSrcweir             = strdup( rtl::OUStringToOString(
88cdf0e10cSrcweir                         rFullName.copy(
89cdf0e10cSrcweir                             RTL_CONSTASCII_LENGTH(
90cdf0e10cSrcweir                                 "http://ucb.openoffice.org/dav/props/" ) ),
9124c56ab9SHerbert Dürr                             RTL_TEXTENCODING_UTF8 ).getStr() );
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
94cdf0e10cSrcweir                 "<prop:" ) ) == 0 )
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         // Support for 3rd party namespaces/props
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         rtl::OString aFullName
99cdf0e10cSrcweir             = rtl::OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         // Format: <prop:the_propname xmlns:prop="the_namespace">
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
104cdf0e10cSrcweir         sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart;
10524c56ab9SHerbert Dürr         rName.name = strdup( aFullName.copy( nStart, nLen ).getStr() );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after ="
108cdf0e10cSrcweir         nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart;
10924c56ab9SHerbert Dürr         rName.nspace = strdup( aFullName.copy( nStart, nLen ).getStr() );
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir     else
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         // Add our namespace to our own properties.
114cdf0e10cSrcweir         rName.nspace = "http://ucb.openoffice.org/dav/props/";
115cdf0e10cSrcweir         rName.name
116cdf0e10cSrcweir             = strdup( rtl::OUStringToOString( rFullName,
11724c56ab9SHerbert Dürr                                               RTL_TEXTENCODING_UTF8 ).getStr() );
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // -------------------------------------------------------------------
122cdf0e10cSrcweir // static
createUCBPropName(const char * nspace,const char * name,rtl::OUString & rFullName)123cdf0e10cSrcweir void DAVProperties::createUCBPropName( const char * nspace,
124cdf0e10cSrcweir                                        const char * name,
125cdf0e10cSrcweir                                        rtl::OUString & rFullName )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     rtl::OUString aNameSpace
128cdf0e10cSrcweir         = rtl::OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 );
129cdf0e10cSrcweir     rtl::OUString aName
130cdf0e10cSrcweir         = rtl::OStringToOUString( name,   RTL_TEXTENCODING_UTF8 );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     if ( !aNameSpace.getLength() )
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         // Some servers send XML without proper namespaces. Assume "DAV:"
135cdf0e10cSrcweir         // in this case, if name is a well-known dav property name.
136cdf0e10cSrcweir         // Although this is not 100% correct, it solves many problems.
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         if ( DAVProperties::RESOURCETYPE.matchIgnoreAsciiCase( aName, 4 )  ||
139cdf0e10cSrcweir              DAVProperties::SUPPORTEDLOCK.matchIgnoreAsciiCase( aName, 4 ) ||
140cdf0e10cSrcweir              DAVProperties::LOCKDISCOVERY.matchIgnoreAsciiCase( aName, 4 ) ||
141cdf0e10cSrcweir              DAVProperties::CREATIONDATE.matchIgnoreAsciiCase( aName, 4 ) ||
142cdf0e10cSrcweir              DAVProperties::DISPLAYNAME.matchIgnoreAsciiCase( aName, 4 ) ||
143cdf0e10cSrcweir              DAVProperties::GETCONTENTLANGUAGE.matchIgnoreAsciiCase( aName, 4 ) ||
144cdf0e10cSrcweir              DAVProperties::GETCONTENTLENGTH.matchIgnoreAsciiCase( aName, 4 ) ||
145cdf0e10cSrcweir              DAVProperties::GETCONTENTTYPE.matchIgnoreAsciiCase( aName, 4 ) ||
146cdf0e10cSrcweir              DAVProperties::GETETAG.matchIgnoreAsciiCase( aName, 4 ) ||
14759ddfc10SAndre Fischer              DAVProperties::GETLASTMODIFIED.matchIgnoreAsciiCase( aName, 4 ) )
14859ddfc10SAndre Fischer         {
149cdf0e10cSrcweir             aNameSpace = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DAV:" ) );
150cdf0e10cSrcweir         }
15159ddfc10SAndre Fischer     }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     // Note: Concatenating strings BEFORE comparing against known namespaces
154cdf0e10cSrcweir     //       is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
155cdf0e10cSrcweir     rFullName  = aNameSpace;
156cdf0e10cSrcweir     rFullName += aName;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
159cdf0e10cSrcweir                 "DAV:" ) ) == 0 )
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir         // Okay, Just concat strings.
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
164cdf0e10cSrcweir                 "http://apache.org/dav/props/" ) ) == 0 )
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         // Okay, Just concat strings.
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
169cdf0e10cSrcweir                 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         // Remove namespace from our own properties.
172cdf0e10cSrcweir         rFullName = rFullName.copy(
173cdf0e10cSrcweir                         RTL_CONSTASCII_LENGTH(
174cdf0e10cSrcweir                             "http://ucb.openoffice.org/dav/props/" ) );
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir     else
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir         // Create property name that encodes, namespace and name ( XML ).
179cdf0e10cSrcweir         rFullName  = rtl::OUString::createFromAscii( "<prop:" );
180cdf0e10cSrcweir         rFullName += aName;
181cdf0e10cSrcweir         rFullName += rtl::OUString::createFromAscii( " xmlns:prop=\"" );
182cdf0e10cSrcweir         rFullName += aNameSpace;
183cdf0e10cSrcweir         rFullName += rtl::OUString::createFromAscii( "\">" );
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // -------------------------------------------------------------------
188cdf0e10cSrcweir // static
isUCBDeadProperty(const CurlPropName & rName)189*51ba086bSDamjan Jovanovic bool DAVProperties::isUCBDeadProperty( const CurlPropName & rName )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     return ( rName.nspace &&
192cdf0e10cSrcweir              ( rtl_str_compareIgnoreAsciiCase(
193cdf0e10cSrcweir                  rName.nspace, "http://ucb.openoffice.org/dav/props/" )
194cdf0e10cSrcweir                == 0 ) );
195cdf0e10cSrcweir }
19606594b87SAriel Constenla-Haile 
isUCBSpecialProperty(const rtl::OUString & rFullName,rtl::OUString & rParsedName)19706594b87SAriel Constenla-Haile bool DAVProperties::isUCBSpecialProperty(const rtl::OUString& rFullName, rtl::OUString& rParsedName)
19806594b87SAriel Constenla-Haile {
19906594b87SAriel Constenla-Haile     sal_Int32 nLen = rFullName.getLength();
20006594b87SAriel Constenla-Haile     if ( nLen <= 0 ||
20106594b87SAriel Constenla-Haile             !rFullName.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "<prop:" ) ) ||
20206594b87SAriel Constenla-Haile             !rFullName.endsWithAsciiL( RTL_CONSTASCII_STRINGPARAM( "\">" ) ) )
20306594b87SAriel Constenla-Haile         return false;
20406594b87SAriel Constenla-Haile 
20506594b87SAriel Constenla-Haile     sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
20606594b87SAriel Constenla-Haile     sal_Int32 nEnd = rFullName.indexOf( sal_Unicode( ' ' ), nStart );
20706594b87SAriel Constenla-Haile     if ( nEnd == -1 )
20806594b87SAriel Constenla-Haile         return false;
20906594b87SAriel Constenla-Haile 
21006594b87SAriel Constenla-Haile     rtl::OUString sPropName = rFullName.copy( nStart, nEnd - nStart );
21106594b87SAriel Constenla-Haile     if ( !sPropName.getLength() )
21206594b87SAriel Constenla-Haile         return false;
21306594b87SAriel Constenla-Haile 
21406594b87SAriel Constenla-Haile     // TODO skip whitespaces?
21506594b87SAriel Constenla-Haile     if ( !rFullName.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "xmlns:prop=\"" ), ++nEnd ) )
21606594b87SAriel Constenla-Haile         return false;
21706594b87SAriel Constenla-Haile 
21806594b87SAriel Constenla-Haile     nStart = nEnd + RTL_CONSTASCII_LENGTH( "xmlns:prop=\"" );
21906594b87SAriel Constenla-Haile     nEnd = rFullName.indexOf( sal_Unicode( '"' ), nStart );
22006594b87SAriel Constenla-Haile     if ( nEnd != nLen - RTL_CONSTASCII_LENGTH( "\">" ) )
22106594b87SAriel Constenla-Haile         return false;
22206594b87SAriel Constenla-Haile 
22306594b87SAriel Constenla-Haile     rtl::OUString sNamesp = rFullName.copy( nStart, nEnd - nStart );
22406594b87SAriel Constenla-Haile     if ( !( nLen = sNamesp.getLength() ) )
22506594b87SAriel Constenla-Haile         return false;
22606594b87SAriel Constenla-Haile 
22706594b87SAriel Constenla-Haile     rtl::OUStringBuffer aBuff( sNamesp );
22806594b87SAriel Constenla-Haile     if ( sNamesp[nLen - 1] != '/' )
22906594b87SAriel Constenla-Haile         aBuff.append( sal_Unicode( '/' ) );
23006594b87SAriel Constenla-Haile     aBuff.append( sPropName );
23106594b87SAriel Constenla-Haile     rParsedName = aBuff.makeStringAndClear();
23206594b87SAriel Constenla-Haile 
23306594b87SAriel Constenla-Haile     return rParsedName.getLength();
23406594b87SAriel Constenla-Haile }
235