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