LCOV - code coverage report
Current view: top level - ucb/source/ucp/webdav - LockEntrySequence.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 83 0.0 %
Date: 2012-08-25 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 68 0.0 %

           Branch data     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 <ne_xml.h>
      32                 :            : #include "LockEntrySequence.hxx"
      33                 :            : 
      34                 :            : using namespace webdav_ucp;
      35                 :            : using namespace com::sun::star;
      36                 :            : 
      37                 :            : //////////////////////////////////////////////////////////////////////////
      38                 :            : 
      39                 :            : struct LockEntrySequenceParseContext
      40                 :            : {
      41                 :            :     ucb::LockEntry * pEntry;
      42                 :            :     bool hasScope;
      43                 :            :     bool hasType;
      44                 :            : 
      45                 :          0 :     LockEntrySequenceParseContext()
      46                 :          0 :     : pEntry( 0 ), hasScope( false ), hasType( false ) {}
      47                 :          0 :     ~LockEntrySequenceParseContext() { delete pEntry; }
      48                 :            : };
      49                 :            : 
      50                 :            : #define STATE_TOP (1)
      51                 :            : 
      52                 :            : #define STATE_LOCKENTRY (STATE_TOP)
      53                 :            : #define STATE_LOCKSCOPE (STATE_TOP + 1)
      54                 :            : #define STATE_EXCLUSIVE (STATE_TOP + 2)
      55                 :            : #define STATE_SHARED    (STATE_TOP + 3)
      56                 :            : #define STATE_LOCKTYPE  (STATE_TOP + 4)
      57                 :            : #define STATE_WRITE     (STATE_TOP + 5)
      58                 :            : 
      59                 :            : //////////////////////////////////////////////////////////////////////////
      60                 :          0 : extern "C" int LockEntrySequence_startelement_callback(
      61                 :            :     void *,
      62                 :            :     int parent,
      63                 :            :     const char * /*nspace*/,
      64                 :            :     const char *name,
      65                 :            :     const char ** )
      66                 :            : {
      67         [ #  # ]:          0 :     if ( name != 0 )
      68                 :            :     {
      69   [ #  #  #  #  :          0 :         switch ( parent )
                      # ]
      70                 :            :         {
      71                 :            :             case NE_XML_STATEROOT:
      72         [ #  # ]:          0 :                 if ( strcmp( name, "lockentry" ) == 0 )
      73                 :          0 :                     return STATE_LOCKENTRY;
      74                 :          0 :                 break;
      75                 :            : 
      76                 :            :             case STATE_LOCKENTRY:
      77         [ #  # ]:          0 :                 if ( strcmp( name, "lockscope" ) == 0 )
      78                 :          0 :                     return STATE_LOCKSCOPE;
      79         [ #  # ]:          0 :                 else if ( strcmp( name, "locktype" ) == 0 )
      80                 :          0 :                     return STATE_LOCKTYPE;
      81                 :            : 
      82                 :            : #define IIS_BUGS_WORKAROUND
      83                 :            : 
      84                 :            : #ifdef IIS_BUGS_WORKAROUND
      85                 :            :                 /* IIS (6) returns XML violating RFC 4918
      86                 :            :                    for DAV:supportedlock property value.
      87                 :            : 
      88                 :            :                    <lockentry>
      89                 :            :                        <write></write>
      90                 :            :                        <shared></shared>
      91                 :            :                    </lockentry>
      92                 :            :                    <lockentry>
      93                 :            :                        <write></write>
      94                 :            :                        <exclusive></exclusive>
      95                 :            :                    </lockentry>
      96                 :            : 
      97                 :            :                    Bother...
      98                 :            :                 */
      99         [ #  # ]:          0 :                 else if ( strcmp( name, "exclusive" ) == 0 )
     100                 :          0 :                     return STATE_EXCLUSIVE;
     101         [ #  # ]:          0 :                 else if ( strcmp( name, "shared" ) == 0 )
     102                 :          0 :                     return STATE_SHARED;
     103         [ #  # ]:          0 :                 else if ( strcmp( name, "write" ) == 0 )
     104                 :          0 :                     return STATE_WRITE;
     105                 :            : #endif
     106                 :          0 :                 break;
     107                 :            : 
     108                 :            :             case STATE_LOCKSCOPE:
     109         [ #  # ]:          0 :                 if ( strcmp( name, "exclusive" ) == 0 )
     110                 :          0 :                     return STATE_EXCLUSIVE;
     111         [ #  # ]:          0 :                 else if ( strcmp( name, "shared" ) == 0 )
     112                 :          0 :                     return STATE_SHARED;
     113                 :          0 :                 break;
     114                 :            : 
     115                 :            :             case STATE_LOCKTYPE:
     116         [ #  # ]:          0 :                 if ( strcmp( name, "write" ) == 0 )
     117                 :          0 :                     return STATE_WRITE;
     118                 :          0 :                 break;
     119                 :            :         }
     120                 :            :     }
     121                 :          0 :     return NE_XML_DECLINE;
     122                 :            : }
     123                 :            : 
     124                 :            : //////////////////////////////////////////////////////////////////////////
     125                 :          0 : extern "C" int LockEntrySequence_chardata_callback(
     126                 :            :     void *,
     127                 :            :     int,
     128                 :            :     const char *,
     129                 :            :     size_t )
     130                 :            : {
     131                 :          0 :     return 0; // zero to continue, non-zero to abort parsing
     132                 :            : }
     133                 :            : 
     134                 :            : //////////////////////////////////////////////////////////////////////////
     135                 :          0 : extern "C" int LockEntrySequence_endelement_callback(
     136                 :            :     void *userdata,
     137                 :            :     int state,
     138                 :            :     const char *,
     139                 :            :     const char * )
     140                 :            : {
     141                 :            :     LockEntrySequenceParseContext * pCtx
     142                 :          0 :                 = static_cast< LockEntrySequenceParseContext * >( userdata );
     143         [ #  # ]:          0 :     if ( !pCtx->pEntry )
     144                 :          0 :         pCtx->pEntry = new ucb::LockEntry;
     145                 :            : 
     146   [ #  #  #  #  :          0 :     switch ( state )
                #  #  # ]
     147                 :            :     {
     148                 :            :         case STATE_EXCLUSIVE:
     149                 :          0 :             pCtx->pEntry->Scope = ucb::LockScope_EXCLUSIVE;
     150                 :          0 :             pCtx->hasScope = true;
     151                 :          0 :             break;
     152                 :            : 
     153                 :            :         case STATE_SHARED:
     154                 :          0 :             pCtx->pEntry->Scope = ucb::LockScope_SHARED;
     155                 :          0 :             pCtx->hasScope = true;
     156                 :          0 :             break;
     157                 :            : 
     158                 :            :         case STATE_WRITE:
     159                 :          0 :             pCtx->pEntry->Type = ucb::LockType_WRITE;
     160                 :          0 :             pCtx->hasType = true;
     161                 :          0 :             break;
     162                 :            : 
     163                 :            :         case STATE_LOCKSCOPE:
     164         [ #  # ]:          0 :             if ( !pCtx->hasScope )
     165                 :          0 :                 return 1; // abort
     166                 :          0 :             break;
     167                 :            : 
     168                 :            :         case STATE_LOCKTYPE:
     169         [ #  # ]:          0 :             if ( !pCtx->hasType )
     170                 :          0 :                 return 1; // abort
     171                 :          0 :             break;
     172                 :            : 
     173                 :            :         case STATE_LOCKENTRY:
     174 [ #  # ][ #  # ]:          0 :             if ( !pCtx->hasType || !pCtx->hasScope )
     175                 :          0 :                 return 1; // abort
     176                 :          0 :             break;
     177                 :            : 
     178                 :            :         default:
     179                 :          0 :             break;
     180                 :            :     }
     181                 :          0 :     return 0; // zero to continue, non-zero to abort parsing
     182                 :            : }
     183                 :            : 
     184                 :            : //////////////////////////////////////////////////////////////////////////
     185                 :            : // static
     186                 :          0 : bool LockEntrySequence::createFromXML( const rtl::OString & rInData,
     187                 :            :                                        uno::Sequence<
     188                 :            :                                                 ucb::LockEntry > & rOutData )
     189                 :            : {
     190                 :          0 :     const sal_Int32 TOKEN_LENGTH = 12; // </lockentry>
     191                 :          0 :     bool success = true;
     192                 :            : 
     193                 :            :     // rInData may contain multiple <lockentry>...</lockentry> tags.
     194                 :          0 :     sal_Int32 nCount = 0;
     195                 :          0 :     sal_Int32 nStart = 0;
     196                 :          0 :     sal_Int32 nEnd   = rInData.indexOf( "</lockentry>" );
     197         [ #  # ]:          0 :     while ( nEnd > -1 )
     198                 :            :     {
     199         [ #  # ]:          0 :         ne_xml_parser * parser = ne_xml_create();
     200         [ #  # ]:          0 :         if ( !parser )
     201                 :            :         {
     202                 :          0 :             success = false;
     203                 :            :             break;
     204                 :            :         }
     205                 :            : 
     206                 :          0 :         LockEntrySequenceParseContext aCtx;
     207                 :            :         ne_xml_push_handler( parser,
     208                 :            :                              LockEntrySequence_startelement_callback,
     209                 :            :                              LockEntrySequence_chardata_callback,
     210                 :            :                              LockEntrySequence_endelement_callback,
     211         [ #  # ]:          0 :                              &aCtx );
     212                 :            : 
     213                 :            :         ne_xml_parse( parser,
     214                 :          0 :                       rInData.getStr() + nStart,
     215         [ #  # ]:          0 :                       nEnd - nStart + TOKEN_LENGTH );
     216                 :            : 
     217         [ #  # ]:          0 :         success = !ne_xml_failed( parser );
     218                 :            : 
     219         [ #  # ]:          0 :         ne_xml_destroy( parser );
     220                 :            : 
     221         [ #  # ]:          0 :         if ( !success )
     222                 :            :             break;
     223                 :            : 
     224         [ #  # ]:          0 :         if ( aCtx.pEntry )
     225                 :            :         {
     226                 :          0 :             nCount++;
     227         [ #  # ]:          0 :             if ( nCount > rOutData.getLength() )
     228         [ #  # ]:          0 :                 rOutData.realloc( rOutData.getLength() + 2 );
     229                 :            : 
     230         [ #  # ]:          0 :             rOutData[ nCount - 1 ] = *aCtx.pEntry;
     231                 :            :         }
     232                 :            : 
     233                 :          0 :         nStart = nEnd + TOKEN_LENGTH;
     234         [ #  # ]:          0 :         nEnd   = rInData.indexOf( "</lockentry>", nStart );
     235                 :          0 :     }
     236                 :            : 
     237                 :          0 :     rOutData.realloc( nCount );
     238                 :          0 :     return success;
     239                 :            : }
     240                 :            : 
     241                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10