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