1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_ucb.hxx" 26 27 #include <string.h> 28 #include "DAVProperties.hxx" 29 30 using namespace webdav_ucp; 31 32 const ::rtl::OUString DAVProperties::CREATIONDATE = 33 ::rtl::OUString::createFromAscii( "DAV:creationdate" ); 34 const ::rtl::OUString DAVProperties::DISPLAYNAME = 35 ::rtl::OUString::createFromAscii( "DAV:displayname" ); 36 const ::rtl::OUString DAVProperties::GETCONTENTLANGUAGE = 37 ::rtl::OUString::createFromAscii( "DAV:getcontentlanguage" ); 38 const ::rtl::OUString DAVProperties::GETCONTENTLENGTH = 39 ::rtl::OUString::createFromAscii( "DAV:getcontentlength" ); 40 const ::rtl::OUString DAVProperties::GETCONTENTTYPE = 41 ::rtl::OUString::createFromAscii( "DAV:getcontenttype" ); 42 const ::rtl::OUString DAVProperties::GETETAG = 43 ::rtl::OUString::createFromAscii( "DAV:getetag" ); 44 const ::rtl::OUString DAVProperties::GETLASTMODIFIED = 45 ::rtl::OUString::createFromAscii( "DAV:getlastmodified" ); 46 const ::rtl::OUString DAVProperties::LOCKDISCOVERY = 47 ::rtl::OUString::createFromAscii( "DAV:lockdiscovery" ); 48 const ::rtl::OUString DAVProperties::RESOURCETYPE = 49 ::rtl::OUString::createFromAscii( "DAV:resourcetype" ); 50 const ::rtl::OUString DAVProperties::SOURCE = 51 ::rtl::OUString::createFromAscii( "DAV:source" ); 52 const ::rtl::OUString DAVProperties::SUPPORTEDLOCK = 53 ::rtl::OUString::createFromAscii( "DAV:supportedlock" ); 54 55 const ::rtl::OUString DAVProperties::EXECUTABLE = 56 ::rtl::OUString::createFromAscii( 57 "http://apache.org/dav/props/executable" ); 58 59 // ------------------------------------------------------------------- 60 // static 61 void DAVProperties::createNeonPropName( const rtl::OUString & rFullName, 62 NeonPropName & rName ) 63 { 64 if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DAV:" ) ) == 0 ) 65 { 66 rName.nspace = "DAV:"; 67 rName.name 68 = strdup( rtl::OUStringToOString( 69 rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ), 70 RTL_TEXTENCODING_UTF8 ) ); 71 } 72 else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( 73 "http://apache.org/dav/props/" ) ) == 0 ) 74 { 75 rName.nspace = "http://apache.org/dav/props/"; 76 rName.name 77 = strdup( rtl::OUStringToOString( 78 rFullName.copy( 79 RTL_CONSTASCII_LENGTH( 80 "http://apache.org/dav/props/" ) ), 81 RTL_TEXTENCODING_UTF8 ) ); 82 } 83 else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( 84 "http://ucb.openoffice.org/dav/props/" ) ) == 0 ) 85 { 86 rName.nspace = "http://ucb.openoffice.org/dav/props/"; 87 rName.name 88 = strdup( rtl::OUStringToOString( 89 rFullName.copy( 90 RTL_CONSTASCII_LENGTH( 91 "http://ucb.openoffice.org/dav/props/" ) ), 92 RTL_TEXTENCODING_UTF8 ) ); 93 } 94 else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( 95 "<prop:" ) ) == 0 ) 96 { 97 // Support for 3rd party namespaces/props 98 99 rtl::OString aFullName 100 = rtl::OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 ); 101 102 // Format: <prop:the_propname xmlns:prop="the_namespace"> 103 104 sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" ); 105 sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart; 106 rName.name = strdup( aFullName.copy( nStart, nLen ) ); 107 108 nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after =" 109 nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart; 110 rName.nspace = strdup( aFullName.copy( nStart, nLen ) ); 111 } 112 else 113 { 114 // Add our namespace to our own properties. 115 rName.nspace = "http://ucb.openoffice.org/dav/props/"; 116 rName.name 117 = strdup( rtl::OUStringToOString( rFullName, 118 RTL_TEXTENCODING_UTF8 ) ); 119 } 120 } 121 122 // ------------------------------------------------------------------- 123 // static 124 void DAVProperties::createUCBPropName( const char * nspace, 125 const char * name, 126 rtl::OUString & rFullName ) 127 { 128 rtl::OUString aNameSpace 129 = rtl::OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 ); 130 rtl::OUString aName 131 = rtl::OStringToOUString( name, RTL_TEXTENCODING_UTF8 ); 132 133 if ( !aNameSpace.getLength() ) 134 { 135 // Some servers send XML without proper namespaces. Assume "DAV:" 136 // in this case, if name is a well-known dav property name. 137 // Although this is not 100% correct, it solves many problems. 138 139 if ( DAVProperties::RESOURCETYPE.matchIgnoreAsciiCase( aName, 4 ) || 140 DAVProperties::SUPPORTEDLOCK.matchIgnoreAsciiCase( aName, 4 ) || 141 DAVProperties::LOCKDISCOVERY.matchIgnoreAsciiCase( aName, 4 ) || 142 DAVProperties::CREATIONDATE.matchIgnoreAsciiCase( aName, 4 ) || 143 DAVProperties::DISPLAYNAME.matchIgnoreAsciiCase( aName, 4 ) || 144 DAVProperties::GETCONTENTLANGUAGE.matchIgnoreAsciiCase( aName, 4 ) || 145 DAVProperties::GETCONTENTLENGTH.matchIgnoreAsciiCase( aName, 4 ) || 146 DAVProperties::GETCONTENTTYPE.matchIgnoreAsciiCase( aName, 4 ) || 147 DAVProperties::GETETAG.matchIgnoreAsciiCase( aName, 4 ) || 148 DAVProperties::GETLASTMODIFIED.matchIgnoreAsciiCase( aName, 4 ) || 149 DAVProperties::SOURCE.matchIgnoreAsciiCase( aName, 4 ) ) 150 aNameSpace = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DAV:" ) ); 151 } 152 153 // Note: Concatenating strings BEFORE comparing against known namespaces 154 // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ). 155 rFullName = aNameSpace; 156 rFullName += aName; 157 158 if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( 159 "DAV:" ) ) == 0 ) 160 { 161 // Okay, Just concat strings. 162 } 163 else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( 164 "http://apache.org/dav/props/" ) ) == 0 ) 165 { 166 // Okay, Just concat strings. 167 } 168 else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( 169 "http://ucb.openoffice.org/dav/props/" ) ) == 0 ) 170 { 171 // Remove namespace from our own properties. 172 rFullName = rFullName.copy( 173 RTL_CONSTASCII_LENGTH( 174 "http://ucb.openoffice.org/dav/props/" ) ); 175 } 176 else 177 { 178 // Create property name that encodes, namespace and name ( XML ). 179 rFullName = rtl::OUString::createFromAscii( "<prop:" ); 180 rFullName += aName; 181 rFullName += rtl::OUString::createFromAscii( " xmlns:prop=\"" ); 182 rFullName += aNameSpace; 183 rFullName += rtl::OUString::createFromAscii( "\">" ); 184 } 185 } 186 187 // ------------------------------------------------------------------- 188 // static 189 bool DAVProperties::isUCBDeadProperty( const NeonPropName & rName ) 190 { 191 return ( rName.nspace && 192 ( rtl_str_compareIgnoreAsciiCase( 193 rName.nspace, "http://ucb.openoffice.org/dav/props/" ) 194 == 0 ) ); 195 } 196