fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / webdav / DAVProperties.cxx
blob34537d29e663a460ad182fba0b851ca1ff27644d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <string.h>
21 #include "DAVProperties.hxx"
22 #include <rtl/ustrbuf.hxx>
24 using namespace http_dav_ucp;
26 const OUString DAVProperties::CREATIONDATE =
27 OUString( "DAV:creationdate" );
28 const OUString DAVProperties::DISPLAYNAME =
29 OUString( "DAV:displayname" );
30 const OUString DAVProperties::GETCONTENTLANGUAGE =
31 OUString( "DAV:getcontentlanguage" );
32 const OUString DAVProperties::GETCONTENTLENGTH =
33 OUString( "DAV:getcontentlength" );
34 const OUString DAVProperties::GETCONTENTTYPE =
35 OUString( "DAV:getcontenttype" );
36 const OUString DAVProperties::GETETAG =
37 OUString( "DAV:getetag" );
38 const OUString DAVProperties::GETLASTMODIFIED =
39 OUString( "DAV:getlastmodified" );
40 const OUString DAVProperties::LOCKDISCOVERY =
41 OUString( "DAV:lockdiscovery" );
42 const OUString DAVProperties::RESOURCETYPE =
43 OUString( "DAV:resourcetype" );
44 const OUString DAVProperties::SUPPORTEDLOCK =
45 OUString( "DAV:supportedlock" );
47 const OUString DAVProperties::EXECUTABLE =
48 OUString( "http://apache.org/dav/props/executable" );
51 // static
52 void DAVProperties::createSerfPropName( const OUString & rFullName,
53 SerfPropName & rName )
55 if ( rFullName.startsWith( "DAV:" ) )
57 rName.nspace = "DAV:";
58 rName.name
59 = strdup( OUStringToOString(
60 rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
61 RTL_TEXTENCODING_UTF8 ).getStr() );
63 else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
65 rName.nspace = "http://apache.org/dav/props/";
66 rName.name
67 = strdup( OUStringToOString(
68 rFullName.copy(
69 RTL_CONSTASCII_LENGTH(
70 "http://apache.org/dav/props/" ) ),
71 RTL_TEXTENCODING_UTF8 ).getStr() );
73 else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
75 rName.nspace = "http://ucb.openoffice.org/dav/props/";
76 rName.name
77 = strdup( OUStringToOString(
78 rFullName.copy(
79 RTL_CONSTASCII_LENGTH(
80 "http://ucb.openoffice.org/dav/props/" ) ),
81 RTL_TEXTENCODING_UTF8 ).getStr() );
83 else if ( rFullName.startsWith( "<prop:" ) )
85 // Support for 3rd party namespaces/props
87 OString aFullName
88 = OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 );
90 // Format: <prop:the_propname xmlns:prop="the_namespace">
92 sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
93 sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart;
94 rName.name = strdup( aFullName.copy( nStart, nLen ).getStr() );
96 nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after ="
97 nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart;
98 rName.nspace = strdup( aFullName.copy( nStart, nLen ).getStr() );
100 else
102 // Add our namespace to our own properties.
103 rName.nspace = "http://ucb.openoffice.org/dav/props/";
104 rName.name
105 = strdup( OUStringToOString( rFullName,
106 RTL_TEXTENCODING_UTF8 ).getStr() );
111 // static
112 void DAVProperties::createUCBPropName( const char * nspace,
113 const char * name,
114 OUString & rFullName )
116 OUString aNameSpace
117 = OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 );
118 OUString aName
119 = OStringToOUString( name, RTL_TEXTENCODING_UTF8 );
121 if ( !aNameSpace.getLength() )
123 // Some servers send XML without proper namespaces. Assume "DAV:"
124 // in this case, if name is a well-known dav property name.
125 // Although this is not 100% correct, it solves many problems.
127 if ( DAVProperties::RESOURCETYPE.matchIgnoreAsciiCase( aName, 4 ) ||
128 DAVProperties::SUPPORTEDLOCK.matchIgnoreAsciiCase( aName, 4 ) ||
129 DAVProperties::LOCKDISCOVERY.matchIgnoreAsciiCase( aName, 4 ) ||
130 DAVProperties::CREATIONDATE.matchIgnoreAsciiCase( aName, 4 ) ||
131 DAVProperties::DISPLAYNAME.matchIgnoreAsciiCase( aName, 4 ) ||
132 DAVProperties::GETCONTENTLANGUAGE.matchIgnoreAsciiCase( aName, 4 ) ||
133 DAVProperties::GETCONTENTLENGTH.matchIgnoreAsciiCase( aName, 4 ) ||
134 DAVProperties::GETCONTENTTYPE.matchIgnoreAsciiCase( aName, 4 ) ||
135 DAVProperties::GETETAG.matchIgnoreAsciiCase( aName, 4 ) ||
136 DAVProperties::GETLASTMODIFIED.matchIgnoreAsciiCase( aName, 4 ) )
138 aNameSpace = "DAV:";
142 // Note: Concatenating strings BEFORE comparing against known namespaces
143 // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
144 rFullName = aNameSpace;
145 rFullName += aName;
147 if ( rFullName.startsWith( "DAV:" ) )
149 // Okay, Just concat strings.
151 else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
153 // Okay, Just concat strings.
155 else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
157 // Remove namespace from our own properties.
158 rFullName = rFullName.copy(
159 RTL_CONSTASCII_LENGTH(
160 "http://ucb.openoffice.org/dav/props/" ) );
162 else
164 // Create property name that encodes, namespace and name ( XML ).
165 rFullName = "<prop:";
166 rFullName += aName;
167 rFullName += " xmlns:prop=\"";
168 rFullName += aNameSpace;
169 rFullName += "\">";
174 // static
175 bool DAVProperties::isUCBDeadProperty( const SerfPropName & rName )
177 return ( rName.nspace &&
178 ( rtl_str_compareIgnoreAsciiCase(
179 rName.nspace, "http://ucb.openoffice.org/dav/props/" )
180 == 0 ) );
183 bool DAVProperties::isUCBSpecialProperty(const rtl::OUString& rFullName, rtl::OUString& rParsedName)
185 sal_Int32 nLen = rFullName.getLength();
186 if ( nLen <= 0 ||
187 !rFullName.startsWith( "<prop:" ) ||
188 !rFullName.endsWith( "\">" ) )
189 return false;
191 sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
192 sal_Int32 nEnd = rFullName.indexOf( ' ', nStart );
193 if ( nEnd == -1 )
194 return false;
196 rtl::OUString sPropName = rFullName.copy( nStart, nEnd - nStart );
197 if ( !sPropName.getLength() )
198 return false;
200 // TODO skip whitespaces?
201 if ( !rFullName.match( "xmlns:prop=\"", ++nEnd ) )
202 return false;
204 nStart = nEnd + RTL_CONSTASCII_LENGTH( "xmlns:prop=\"" );
205 nEnd = rFullName.indexOf( '"', nStart );
206 if ( nEnd != nLen - RTL_CONSTASCII_LENGTH( "\">" ) )
207 return false;
209 rtl::OUString sNamesp = rFullName.copy( nStart, nEnd - nStart );
210 if ( !( nLen = sNamesp.getLength() ) )
211 return false;
213 rtl::OUStringBuffer aBuff( sNamesp );
214 if ( sNamesp[nLen - 1] != '/' )
215 aBuff.append( '/' );
216 aBuff.append( sPropName );
217 rParsedName = aBuff.makeStringAndClear();
219 return rParsedName.getLength();
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */