LibreOffice Module ucb (master)  1
neon/DAVProperties.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 
30 #include <string.h>
31 
32 #include <o3tl/string_view.hxx>
33 
34 #include "DAVProperties.hxx"
35 
36 using namespace webdav_ucp;
37 
38 void DAVProperties::createNeonPropName( const OUString & rFullName,
39  NeonPropName & rName )
40 {
41  if ( rFullName.startsWith( "DAV:" ) )
42  {
43  rName.nspace = "DAV:";
44  rName.name
45  = strdup( OUStringToOString(
46  rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
47  RTL_TEXTENCODING_UTF8 ).getStr() );
48  }
49  else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
50  {
51  rName.nspace = "http://apache.org/dav/props/";
52  rName.name
53  = strdup( OUStringToOString(
54  rFullName.copy(
55  RTL_CONSTASCII_LENGTH(
56  "http://apache.org/dav/props/" ) ),
57  RTL_TEXTENCODING_UTF8 ).getStr() );
58  }
59  else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
60  {
61  rName.nspace = "http://ucb.openoffice.org/dav/props/";
62  rName.name
63  = strdup( OUStringToOString(
64  rFullName.copy(
65  RTL_CONSTASCII_LENGTH(
66  "http://ucb.openoffice.org/dav/props/" ) ),
67  RTL_TEXTENCODING_UTF8 ).getStr() );
68  }
69  else if ( rFullName.startsWith( "<prop:" ) )
70  {
71  // Support for 3rd party namespaces/props
72 
73  OString aFullName
74  = OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 );
75 
76  // Format: <prop:the_propname xmlns:prop="the_namespace">
77 
78  sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
79  sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart;
80  rName.name = strdup( aFullName.copy( nStart, nLen ).getStr() );
81 
82  nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after ="
83  nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart;
84  rName.nspace = strdup( aFullName.copy( nStart, nLen ).getStr() );
85  }
86  else
87  {
88  // Add our namespace to our own properties.
89  rName.nspace = "http://ucb.openoffice.org/dav/props/";
90  rName.name
91  = strdup( OUStringToOString( rFullName,
92  RTL_TEXTENCODING_UTF8 ).getStr() );
93  }
94 }
95 
96 void DAVProperties::createUCBPropName( const char * nspace,
97  const char * name,
98  OUString & rFullName )
99 {
100  OUString aNameSpace
101  = OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 );
102  OUString aName
103  = OStringToOUString( name, RTL_TEXTENCODING_UTF8 );
104 
105  if ( aNameSpace.isEmpty() )
106  {
107  // Some servers send XML without proper namespaces. Assume "DAV:"
108  // in this case, if name is a well-known dav property name.
109  // Although this is not 100% correct, it solves many problems.
110  if ( o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::RESOURCETYPE).substr(4)) ||
111  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::RESOURCETYPE).substr(4)) ||
112  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::SUPPORTEDLOCK).substr(4)) ||
113  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::LOCKDISCOVERY).substr(4)) ||
114  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::CREATIONDATE).substr(4)) ||
115  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::DISPLAYNAME).substr(4)) ||
116  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::GETCONTENTLANGUAGE).substr(4)) ||
117  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::GETCONTENTLENGTH).substr(4)) ||
118  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::GETCONTENTTYPE).substr(4)) ||
119  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::GETETAG).substr(4)) ||
120  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::GETLASTMODIFIED).substr(4)) ||
121  o3tl::equalsIgnoreAsciiCase(aName, std::u16string_view(DAVProperties::SOURCE).substr(4)) )
122  aNameSpace = "DAV:";
123  }
124 
125  // Note: Concatenating strings BEFORE comparing against known namespaces
126  // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
127  rFullName = aNameSpace;
128  rFullName += aName;
129 
130  if ( rFullName.startsWith( "DAV:" ) )
131  {
132  // Okay, Just concat strings.
133  }
134  else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
135  {
136  // Okay, Just concat strings.
137  }
138  else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
139  {
140  // Remove namespace from our own properties.
141  rFullName = rFullName.copy(
142  RTL_CONSTASCII_LENGTH(
143  "http://ucb.openoffice.org/dav/props/" ) );
144  }
145  else
146  {
147  // Create property name that encodes, namespace and name ( XML ).
148  rFullName = "<prop:" + aName + " xmlns:prop=\"" + aNameSpace + "\">";
149  }
150 }
151 
153 {
154  return ( rName.nspace &&
155  ( rtl_str_compareIgnoreAsciiCase(
156  rName.nspace, "http://ucb.openoffice.org/dav/props/" )
157  == 0 ) );
158 }
159 
161  const OUString& rFullName, OUString& rParsedName)
162 {
163  if ( !rFullName.startsWith( "<prop:" ) || !rFullName.endsWith( "\">" ) )
164  return false;
165 
166  sal_Int32 nStart = strlen( "<prop:" );
167  sal_Int32 nEnd = rFullName.indexOf( ' ', nStart );
168  if ( nEnd <= nStart ) // incl. -1 for "not found"
169  return false;
170 
171  OUString sPropName( rFullName.copy( nStart, nEnd - nStart ) );
172 
173  // TODO skip whitespaces?
174  if ( !rFullName.match( "xmlns:prop=\"", ++nEnd ) )
175  return false;
176 
177  nStart = nEnd + strlen( "xmlns:prop=\"" );
178  nEnd = rFullName.indexOf( '"', nStart );
179  if ( nEnd != rFullName.getLength() - sal_Int32( strlen( "\">" ) )
180  || nEnd == nStart )
181  {
182  return false;
183  }
184 
185  rParsedName = rFullName.copy( nStart, nEnd - nStart );
186  if ( !rParsedName.endsWith( "/" ) )
187  rParsedName += "/";
188  rParsedName += sPropName;
189 
190  return rParsedName.getLength();
191 }
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static constexpr OUStringLiteral RESOURCETYPE
static constexpr OUStringLiteral GETCONTENTTYPE
static constexpr OUStringLiteral LOCKDISCOVERY
static constexpr OUStringLiteral SUPPORTEDLOCK
static constexpr OUStringLiteral GETCONTENTLANGUAGE
ne_propname NeonPropName
Definition: NeonTypes.hxx:50
static void createNeonPropName(const OUString &rFullName, NeonPropName &rName)
static constexpr OUStringLiteral GETCONTENTLENGTH
static bool isUCBDeadProperty(const NeonPropName &rName)
static constexpr OUStringLiteral CREATIONDATE
static bool isUCBSpecialProperty(const OUString &rFullName, OUString &rParsedName)
static constexpr OUStringLiteral SOURCE
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
OUString aName
static constexpr OUStringLiteral DISPLAYNAME
static constexpr OUStringLiteral GETETAG
static void createUCBPropName(const char *nspace, const char *name, OUString &rFullName)
static constexpr OUStringLiteral GETLASTMODIFIED