xref: /trunk/main/ucb/source/ucp/webdav/DAVProperties.cxx (revision 59ddfc10bd384e83978dcd8c83c4a7ba8f8fdec1)
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
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir #include "DAVProperties.hxx"
29cdf0e10cSrcweir 
30*59ddfc10SAndre Fischer using namespace http_dav_ucp;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir const ::rtl::OUString DAVProperties::CREATIONDATE =
33cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:creationdate" );
34cdf0e10cSrcweir const ::rtl::OUString DAVProperties::DISPLAYNAME =
35cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:displayname" );
36cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETCONTENTLANGUAGE =
37cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getcontentlanguage" );
38cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETCONTENTLENGTH =
39cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getcontentlength" );
40cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETCONTENTTYPE =
41cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getcontenttype" );
42cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETETAG =
43cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getetag" );
44cdf0e10cSrcweir const ::rtl::OUString DAVProperties::GETLASTMODIFIED =
45cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:getlastmodified" );
46cdf0e10cSrcweir const ::rtl::OUString DAVProperties::LOCKDISCOVERY =
47cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:lockdiscovery" );
48cdf0e10cSrcweir const ::rtl::OUString DAVProperties::RESOURCETYPE =
49cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:resourcetype" );
50cdf0e10cSrcweir const ::rtl::OUString DAVProperties::SUPPORTEDLOCK =
51cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DAV:supportedlock" );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir const ::rtl::OUString DAVProperties::EXECUTABLE =
54cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii(
55cdf0e10cSrcweir                                 "http://apache.org/dav/props/executable" );
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // -------------------------------------------------------------------
58cdf0e10cSrcweir // static
59*59ddfc10SAndre Fischer void DAVProperties::createSerfPropName( const rtl::OUString & rFullName,
60*59ddfc10SAndre Fischer                                         SerfPropName & rName )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DAV:" ) ) == 0 )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         rName.nspace = "DAV:";
65cdf0e10cSrcweir         rName.name
66cdf0e10cSrcweir             = strdup( rtl::OUStringToOString(
67cdf0e10cSrcweir                         rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
68cdf0e10cSrcweir                                         RTL_TEXTENCODING_UTF8 ) );
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
71cdf0e10cSrcweir                 "http://apache.org/dav/props/" ) ) == 0 )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         rName.nspace = "http://apache.org/dav/props/";
74cdf0e10cSrcweir         rName.name
75cdf0e10cSrcweir             = strdup( rtl::OUStringToOString(
76cdf0e10cSrcweir                         rFullName.copy(
77cdf0e10cSrcweir                             RTL_CONSTASCII_LENGTH(
78cdf0e10cSrcweir                                 "http://apache.org/dav/props/" ) ),
79cdf0e10cSrcweir                             RTL_TEXTENCODING_UTF8 ) );
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
82cdf0e10cSrcweir                 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         rName.nspace = "http://ucb.openoffice.org/dav/props/";
85cdf0e10cSrcweir         rName.name
86cdf0e10cSrcweir             = strdup( rtl::OUStringToOString(
87cdf0e10cSrcweir                         rFullName.copy(
88cdf0e10cSrcweir                             RTL_CONSTASCII_LENGTH(
89cdf0e10cSrcweir                                 "http://ucb.openoffice.org/dav/props/" ) ),
90cdf0e10cSrcweir                             RTL_TEXTENCODING_UTF8 ) );
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
93cdf0e10cSrcweir                 "<prop:" ) ) == 0 )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         // Support for 3rd party namespaces/props
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         rtl::OString aFullName
98cdf0e10cSrcweir             = rtl::OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         // Format: <prop:the_propname xmlns:prop="the_namespace">
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
103cdf0e10cSrcweir         sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart;
104cdf0e10cSrcweir         rName.name = strdup( aFullName.copy( nStart, nLen ) );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after ="
107cdf0e10cSrcweir         nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart;
108cdf0e10cSrcweir         rName.nspace = strdup( aFullName.copy( nStart, nLen ) );
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir     else
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         // Add our namespace to our own properties.
113cdf0e10cSrcweir         rName.nspace = "http://ucb.openoffice.org/dav/props/";
114cdf0e10cSrcweir         rName.name
115cdf0e10cSrcweir             = strdup( rtl::OUStringToOString( rFullName,
116cdf0e10cSrcweir                                               RTL_TEXTENCODING_UTF8 ) );
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // -------------------------------------------------------------------
121cdf0e10cSrcweir // static
122cdf0e10cSrcweir void DAVProperties::createUCBPropName( const char * nspace,
123cdf0e10cSrcweir                                        const char * name,
124cdf0e10cSrcweir                                        rtl::OUString & rFullName )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     rtl::OUString aNameSpace
127cdf0e10cSrcweir         = rtl::OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 );
128cdf0e10cSrcweir     rtl::OUString aName
129cdf0e10cSrcweir         = rtl::OStringToOUString( name,   RTL_TEXTENCODING_UTF8 );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     if ( !aNameSpace.getLength() )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         // Some servers send XML without proper namespaces. Assume "DAV:"
134cdf0e10cSrcweir         // in this case, if name is a well-known dav property name.
135cdf0e10cSrcweir         // Although this is not 100% correct, it solves many problems.
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         if ( DAVProperties::RESOURCETYPE.matchIgnoreAsciiCase( aName, 4 )  ||
138cdf0e10cSrcweir              DAVProperties::SUPPORTEDLOCK.matchIgnoreAsciiCase( aName, 4 ) ||
139cdf0e10cSrcweir              DAVProperties::LOCKDISCOVERY.matchIgnoreAsciiCase( aName, 4 ) ||
140cdf0e10cSrcweir              DAVProperties::CREATIONDATE.matchIgnoreAsciiCase( aName, 4 ) ||
141cdf0e10cSrcweir              DAVProperties::DISPLAYNAME.matchIgnoreAsciiCase( aName, 4 ) ||
142cdf0e10cSrcweir              DAVProperties::GETCONTENTLANGUAGE.matchIgnoreAsciiCase( aName, 4 ) ||
143cdf0e10cSrcweir              DAVProperties::GETCONTENTLENGTH.matchIgnoreAsciiCase( aName, 4 ) ||
144cdf0e10cSrcweir              DAVProperties::GETCONTENTTYPE.matchIgnoreAsciiCase( aName, 4 ) ||
145cdf0e10cSrcweir              DAVProperties::GETETAG.matchIgnoreAsciiCase( aName, 4 ) ||
146*59ddfc10SAndre Fischer              DAVProperties::GETLASTMODIFIED.matchIgnoreAsciiCase( aName, 4 ) )
147*59ddfc10SAndre Fischer         {
148cdf0e10cSrcweir             aNameSpace = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DAV:" ) );
149cdf0e10cSrcweir         }
150*59ddfc10SAndre Fischer     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // Note: Concatenating strings BEFORE comparing against known namespaces
153cdf0e10cSrcweir     //       is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
154cdf0e10cSrcweir     rFullName  = aNameSpace;
155cdf0e10cSrcweir     rFullName += aName;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
158cdf0e10cSrcweir                 "DAV:" ) ) == 0 )
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         // Okay, Just concat strings.
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
163cdf0e10cSrcweir                 "http://apache.org/dav/props/" ) ) == 0 )
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         // Okay, Just concat strings.
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir     else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
168cdf0e10cSrcweir                 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir         // Remove namespace from our own properties.
171cdf0e10cSrcweir         rFullName = rFullName.copy(
172cdf0e10cSrcweir                         RTL_CONSTASCII_LENGTH(
173cdf0e10cSrcweir                             "http://ucb.openoffice.org/dav/props/" ) );
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir     else
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         // Create property name that encodes, namespace and name ( XML ).
178cdf0e10cSrcweir         rFullName  = rtl::OUString::createFromAscii( "<prop:" );
179cdf0e10cSrcweir         rFullName += aName;
180cdf0e10cSrcweir         rFullName += rtl::OUString::createFromAscii( " xmlns:prop=\"" );
181cdf0e10cSrcweir         rFullName += aNameSpace;
182cdf0e10cSrcweir         rFullName += rtl::OUString::createFromAscii( "\">" );
183cdf0e10cSrcweir     }
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir // -------------------------------------------------------------------
187cdf0e10cSrcweir // static
188*59ddfc10SAndre Fischer bool DAVProperties::isUCBDeadProperty( const SerfPropName & rName )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     return ( rName.nspace &&
191cdf0e10cSrcweir              ( rtl_str_compareIgnoreAsciiCase(
192cdf0e10cSrcweir                  rName.nspace, "http://ucb.openoffice.org/dav/props/" )
193cdf0e10cSrcweir                == 0 ) );
194cdf0e10cSrcweir }
195