LCOV - code coverage report
Current view: top level - ucb/source/ucp/webdav-neon - DAVProperties.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 84 15.5 %
Date: 2015-06-13 12:38:46 Functions: 2 6 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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           2 : const OUString DAVProperties::CREATIONDATE("DAV:creationdate");
      36           2 : const OUString DAVProperties::DISPLAYNAME("DAV:displayname");
      37           2 : const OUString DAVProperties::GETCONTENTLANGUAGE("DAV:getcontentlanguage");
      38           2 : const OUString DAVProperties::GETCONTENTLENGTH("DAV:getcontentlength");
      39           2 : const OUString DAVProperties::GETCONTENTTYPE("DAV:getcontenttype");
      40           2 : const OUString DAVProperties::GETETAG("DAV:getetag");
      41           2 : const OUString DAVProperties::GETLASTMODIFIED("DAV:getlastmodified");
      42           2 : const OUString DAVProperties::LOCKDISCOVERY("DAV:lockdiscovery");
      43           2 : const OUString DAVProperties::RESOURCETYPE("DAV:resourcetype");
      44           2 : const OUString DAVProperties::SOURCE("DAV:source");
      45           2 : const OUString DAVProperties::SUPPORTEDLOCK("DAV:supportedlock");
      46             : 
      47           2 : const OUString DAVProperties::EXECUTABLE("http://apache.org/dav/props/executable");
      48             : 
      49           0 : void DAVProperties::createNeonPropName( const OUString & rFullName,
      50             :                                         NeonPropName & rName )
      51             : {
      52           0 :     if ( rFullName.startsWith( "DAV:" ) )
      53             :     {
      54           0 :         rName.nspace = "DAV:";
      55             :         rName.name
      56             :             = strdup( OUStringToOString(
      57             :                         rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
      58           0 :                         RTL_TEXTENCODING_UTF8 ).getStr() );
      59             :     }
      60           0 :     else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
      61             :     {
      62           0 :         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           0 :                         RTL_TEXTENCODING_UTF8 ).getStr() );
      69             :     }
      70           0 :     else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
      71             :     {
      72           0 :         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           0 :                         RTL_TEXTENCODING_UTF8 ).getStr() );
      79             :     }
      80           0 :     else if ( rFullName.startsWith( "<prop:" ) )
      81             :     {
      82             :         // Support for 3rd party namespaces/props
      83             : 
      84             :         OString aFullName
      85           0 :             = OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 );
      86             : 
      87             :         // Format: <prop:the_propname xmlns:prop="the_namespace">
      88             : 
      89           0 :         sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
      90           0 :         sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart;
      91           0 :         rName.name = strdup( aFullName.copy( nStart, nLen ).getStr() );
      92             : 
      93           0 :         nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after ="
      94           0 :         nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart;
      95           0 :         rName.nspace = strdup( aFullName.copy( nStart, nLen ).getStr() );
      96             :     }
      97             :     else
      98             :     {
      99             :         // Add our namespace to our own properties.
     100           0 :         rName.nspace = "http://ucb.openoffice.org/dav/props/";
     101             :         rName.name
     102             :             = strdup( OUStringToOString( rFullName,
     103           0 :                                               RTL_TEXTENCODING_UTF8 ).getStr() );
     104             :     }
     105           0 : }
     106             : 
     107           0 : void DAVProperties::createUCBPropName( const char * nspace,
     108             :                                        const char * name,
     109             :                                        OUString & rFullName )
     110             : {
     111             :     OUString aNameSpace
     112           0 :         = OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 );
     113             :     OUString aName
     114           0 :         = OStringToOUString( name,   RTL_TEXTENCODING_UTF8 );
     115             : 
     116           0 :     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           0 :         if ( DAVProperties::RESOURCETYPE.matchIgnoreAsciiCase( aName, 4 )  ||
     123           0 :              DAVProperties::SUPPORTEDLOCK.matchIgnoreAsciiCase( aName, 4 ) ||
     124           0 :              DAVProperties::LOCKDISCOVERY.matchIgnoreAsciiCase( aName, 4 ) ||
     125           0 :              DAVProperties::CREATIONDATE.matchIgnoreAsciiCase( aName, 4 ) ||
     126           0 :              DAVProperties::DISPLAYNAME.matchIgnoreAsciiCase( aName, 4 ) ||
     127           0 :              DAVProperties::GETCONTENTLANGUAGE.matchIgnoreAsciiCase( aName, 4 ) ||
     128           0 :              DAVProperties::GETCONTENTLENGTH.matchIgnoreAsciiCase( aName, 4 ) ||
     129           0 :              DAVProperties::GETCONTENTTYPE.matchIgnoreAsciiCase( aName, 4 ) ||
     130           0 :              DAVProperties::GETETAG.matchIgnoreAsciiCase( aName, 4 ) ||
     131           0 :              DAVProperties::GETLASTMODIFIED.matchIgnoreAsciiCase( aName, 4 ) ||
     132           0 :              DAVProperties::SOURCE.matchIgnoreAsciiCase( aName, 4 ) )
     133           0 :             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           0 :     rFullName  = aNameSpace;
     139           0 :     rFullName += aName;
     140             : 
     141           0 :     if ( rFullName.startsWith( "DAV:" ) )
     142             :     {
     143             :         // Okay, Just concat strings.
     144             :     }
     145           0 :     else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
     146             :     {
     147             :         // Okay, Just concat strings.
     148             :     }
     149           0 :     else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
     150             :     {
     151             :         // Remove namespace from our own properties.
     152           0 :         rFullName = rFullName.copy(
     153             :                         RTL_CONSTASCII_LENGTH(
     154           0 :                             "http://ucb.openoffice.org/dav/props/" ) );
     155             :     }
     156             :     else
     157             :     {
     158             :         // Create property name that encodes, namespace and name ( XML ).
     159           0 :         rFullName  = "<prop:" + aName + " xmlns:prop=\"" + aNameSpace + "\">";
     160           0 :     }
     161           0 : }
     162             : 
     163           0 : bool DAVProperties::isUCBDeadProperty( const NeonPropName & rName )
     164             : {
     165           0 :     return ( rName.nspace &&
     166             :              ( rtl_str_compareIgnoreAsciiCase(
     167           0 :                  rName.nspace, "http://ucb.openoffice.org/dav/props/" )
     168           0 :                == 0 ) );
     169             : }
     170             : 
     171           0 : bool DAVProperties::isUCBSpecialProperty(
     172             :     const OUString& rFullName, OUString& rParsedName)
     173             : {
     174           0 :     if ( !rFullName.startsWith( "<prop:" ) || !rFullName.endsWith( "\">" ) )
     175           0 :         return false;
     176             : 
     177           0 :     sal_Int32 nStart = strlen( "<prop:" );
     178           0 :     sal_Int32 nEnd = rFullName.indexOf( ' ', nStart );
     179           0 :     if ( nEnd <= nStart ) // incl. -1 for "not found"
     180           0 :         return false;
     181             : 
     182           0 :     OUString sPropName( rFullName.copy( nStart, nEnd - nStart ) );
     183             : 
     184             :     // TODO skip whitespaces?
     185           0 :     if ( !rFullName.match( "xmlns:prop=\"", ++nEnd ) )
     186           0 :         return false;
     187             : 
     188           0 :     nStart = nEnd + strlen( "xmlns:prop=\"" );
     189           0 :     nEnd = rFullName.indexOf( '"', nStart );
     190           0 :     if ( nEnd != rFullName.getLength() - sal_Int32( strlen( "\">" ) )
     191           0 :          || nEnd == nStart )
     192             :     {
     193           0 :         return false;
     194             :     }
     195             : 
     196           0 :     rParsedName = rFullName.copy( nStart, nEnd - nStart );
     197           0 :     if ( !rParsedName.endsWith( "/" ) )
     198           0 :         rParsedName += "/";
     199           0 :     rParsedName += sPropName;
     200             : 
     201           0 :     return rParsedName.getLength();
     202           6 : }
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11