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 .
20 #include "DAVProperties.hxx"
21 #include <rtl/ustrbuf.hxx>
22 #include <o3tl/string_view.hxx>
25 using namespace http_dav_ucp
;
29 void DAVProperties::createSerfPropName( ::std::u16string_view
const rFullName
,
30 SerfPropName
& rName
)
32 if (o3tl::starts_with(rFullName
, u
"DAV:"))
34 rName
.nspace
= "DAV:";
36 = strdup( OUStringToOString(
37 rFullName
.substr(RTL_CONSTASCII_LENGTH("DAV:")),
38 RTL_TEXTENCODING_UTF8
).getStr() );
40 else if (o3tl::starts_with(rFullName
, u
"http://apache.org/dav/props/"))
42 rName
.nspace
= "http://apache.org/dav/props/";
44 = strdup( OUStringToOString(
46 RTL_CONSTASCII_LENGTH(
47 "http://apache.org/dav/props/" ) ),
48 RTL_TEXTENCODING_UTF8
).getStr() );
50 else if (o3tl::starts_with(rFullName
, u
"http://ucb.openoffice.org/dav/props/"))
52 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
54 = strdup( OUStringToOString(
56 RTL_CONSTASCII_LENGTH(
57 "http://ucb.openoffice.org/dav/props/" ) ),
58 RTL_TEXTENCODING_UTF8
).getStr() );
60 else if (o3tl::starts_with(rFullName
, u
"<prop:"))
62 // Support for 3rd party namespaces/props
65 = OUStringToOString( rFullName
, RTL_TEXTENCODING_UTF8
);
67 // Format: <prop:the_propname xmlns:prop="the_namespace">
69 sal_Int32 nStart
= RTL_CONSTASCII_LENGTH( "<prop:" );
70 sal_Int32 nLen
= aFullName
.indexOf( ' ' ) - nStart
;
71 rName
.name
= strdup( aFullName
.copy( nStart
, nLen
).getStr() );
73 nStart
= aFullName
.indexOf( '=', nStart
+ nLen
) + 2; // after ="
74 nLen
= aFullName
.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart
;
75 rName
.nspace
= strdup( aFullName
.copy( nStart
, nLen
).getStr() );
79 // this must not be a URI - WebDAVResponseParser must have converted it
80 // to the "<prop:" form above
81 assert(rFullName
.find(':') == ::std::u16string_view::npos
);
82 // Add our namespace to our own properties.
83 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
85 = strdup( OUStringToOString( rFullName
,
86 RTL_TEXTENCODING_UTF8
).getStr() );
92 void DAVProperties::createUCBPropName( const char * nspace
,
94 OUString
& rFullName
)
97 = OStringToOUString( nspace
, RTL_TEXTENCODING_UTF8
);
99 = OStringToOUString( name
, RTL_TEXTENCODING_UTF8
);
101 if ( !aNameSpace
.getLength() )
103 // Some servers send XML without proper namespaces. Assume "DAV:"
104 // in this case, if name is a well-known dav property name.
105 // Although this is not 100% correct, it solves many problems.
107 if (o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::RESOURCETYPE
).substr(4)) ||
108 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::SUPPORTEDLOCK
).substr(4)) ||
109 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::LOCKDISCOVERY
).substr(4)) ||
110 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::CREATIONDATE
).substr(4)) ||
111 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::DISPLAYNAME
).substr(4)) ||
112 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::GETCONTENTLANGUAGE
).substr(4)) ||
113 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::GETCONTENTLENGTH
).substr(4)) ||
114 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::GETCONTENTTYPE
).substr(4)) ||
115 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::GETETAG
).substr(4)) ||
116 o3tl::equalsIgnoreAsciiCase(aName
, std::u16string_view(DAVProperties::GETLASTMODIFIED
).substr(4)))
122 // Note: Concatenating strings BEFORE comparing against known namespaces
123 // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
124 rFullName
= aNameSpace
;
127 if ( rFullName
.startsWith( "DAV:" ) )
129 // Okay, Just concat strings.
131 else if ( rFullName
.startsWith( "http://apache.org/dav/props/" ) )
133 // Okay, Just concat strings.
135 else if ( rFullName
.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
137 // Remove namespace from our own properties.
138 rFullName
= rFullName
.copy(
139 RTL_CONSTASCII_LENGTH(
140 "http://ucb.openoffice.org/dav/props/" ) );
144 // Create property name that encodes, namespace and name ( XML ).
145 rFullName
= "<prop:";
147 rFullName
+= " xmlns:prop=\"";
148 rFullName
+= aNameSpace
;
155 bool DAVProperties::isUCBDeadProperty( const SerfPropName
& rName
)
157 return ( rName
.nspace
&&
158 ( rtl_str_compareIgnoreAsciiCase(
159 rName
.nspace
, "http://ucb.openoffice.org/dav/props/" )
163 bool DAVProperties::isUCBSpecialProperty(std::u16string_view rFullName
, OUString
& rParsedName
)
165 size_t nLen
= rFullName
.size();
167 !o3tl::starts_with(rFullName
, u
"<prop:" ) ||
168 !o3tl::starts_with(rFullName
, u
"\">" ) )
171 sal_Int32 nStart
= RTL_CONSTASCII_LENGTH( "<prop:" );
172 size_t nEnd
= rFullName
.find( ' ', nStart
);
173 if ( nEnd
== std::u16string_view::npos
)
176 std::u16string_view sPropName
= rFullName
.substr( nStart
, nEnd
- nStart
);
177 if ( sPropName
.empty() )
180 // TODO skip whitespaces?
182 if ( !o3tl::starts_with(rFullName
.substr(nEnd
), u
"xmlns:prop=\"" ) )
185 nStart
= nEnd
+ RTL_CONSTASCII_LENGTH( "xmlns:prop=\"" );
186 nEnd
= rFullName
.find( '"', nStart
);
187 if ( nEnd
!= nLen
- RTL_CONSTASCII_LENGTH( "\">" ) )
190 std::u16string_view sNamesp
= rFullName
.substr( nStart
, nEnd
- nStart
);
191 nLen
= sNamesp
.size();
195 OUStringBuffer
aBuff( sNamesp
);
196 if ( sNamesp
[nLen
- 1] != '/' )
198 aBuff
.append( sPropName
);
199 rParsedName
= aBuff
.makeStringAndClear();
201 return rParsedName
.getLength();
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */