LCOV - code coverage report
Current view: top level - libreoffice/sot/source/sdstor - stgole.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 102 43.1 %
Date: 2012-12-27 Functions: 6 14 42.9 %
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             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "rtl/string.h"
      22             : #include "rtl/string.h"
      23             : #include "stgole.hxx"
      24             : #include "sot/storinfo.hxx"     // Read/WriteClipboardFormat()
      25             : 
      26             : #ifdef _MSC_VER
      27             : #pragma warning(disable: 4342)
      28             : #endif
      29             : ///////////////////////// class StgInternalStream ////////////////////////
      30             : 
      31          14 : StgInternalStream::StgInternalStream
      32          14 :     ( BaseStorage& rStg, const String& rName, sal_Bool bWr )
      33             : {
      34          14 :     bIsWritable = sal_True;
      35             :     sal_uInt16 nMode = bWr
      36             :                  ? STREAM_WRITE | STREAM_SHARE_DENYALL
      37          14 :                  : STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE;
      38          14 :     pStrm = rStg.OpenStream( rName, nMode );
      39             : 
      40             :     // set the error code right here in the stream
      41          14 :     SetError( rStg.GetError() );
      42          14 :     SetBufferSize( 1024 );
      43          14 : }
      44             : 
      45          28 : StgInternalStream::~StgInternalStream()
      46             : {
      47          14 :     delete pStrm;
      48          14 : }
      49             : 
      50          14 : sal_uLong StgInternalStream::GetData( void* pData, sal_uLong nSize )
      51             : {
      52          14 :     if( pStrm )
      53             :     {
      54          14 :         nSize = pStrm->Read( pData, nSize );
      55          14 :         SetError( pStrm->GetError() );
      56          14 :         return nSize;
      57             :     }
      58             :     else
      59           0 :         return 0;
      60             : }
      61             : 
      62           0 : sal_uLong StgInternalStream::PutData( const void* pData, sal_uLong nSize )
      63             : {
      64           0 :     if( pStrm )
      65             :     {
      66           0 :         nSize = pStrm->Write( pData, nSize );
      67           0 :         SetError( pStrm->GetError() );
      68           0 :         return nSize;
      69             :     }
      70             :     else
      71           0 :         return 0;
      72             : }
      73             : 
      74          28 : sal_uLong StgInternalStream::SeekPos( sal_uLong nPos )
      75             : {
      76          28 :     return pStrm ? pStrm->Seek( nPos ) : 0;
      77             : }
      78             : 
      79           0 : void StgInternalStream::FlushData()
      80             : {
      81           0 :     if( pStrm )
      82             :     {
      83           0 :         pStrm->Flush();
      84           0 :         SetError( pStrm->GetError() );
      85             :     }
      86           0 : }
      87             : 
      88           0 : void StgInternalStream::Commit()
      89             : {
      90           0 :     Flush();
      91           0 :     pStrm->Commit();
      92           0 : }
      93             : 
      94             : ///////////////////////// class StgCompObjStream /////////////////////////
      95             : 
      96          14 : StgCompObjStream::StgCompObjStream( BaseStorage& rStg, sal_Bool bWr )
      97          14 :             : StgInternalStream( rStg, rtl::OUString("\1CompObj"), bWr )
      98             : {
      99          14 :     memset( &aClsId, 0, sizeof( ClsId ) );
     100          14 :     nCbFormat = 0;
     101          14 : }
     102             : 
     103          14 : sal_Bool StgCompObjStream::Load()
     104             : {
     105          14 :     memset( &aClsId, 0, sizeof( ClsId ) );
     106          14 :     nCbFormat = 0;
     107          14 :     aUserName.Erase();
     108          14 :     if( GetError() != SVSTREAM_OK )
     109           0 :         return sal_False;
     110          14 :     Seek( 8L );     // skip the first part
     111          14 :     sal_Int32 nMarker = 0;
     112          14 :     *this >> nMarker;
     113          14 :     if( nMarker == -1L )
     114             :     {
     115          14 :         *this >> aClsId;
     116          14 :         sal_Int32 nLen1 = 0;
     117          14 :         *this >> nLen1;
     118          14 :         if ( nLen1 > 0 )
     119             :         {
     120             :             // higher bits are ignored
     121          14 :             sal_uLong nStrLen = ::std::min( nLen1, (sal_Int32)0xFFFE );
     122             : 
     123          14 :             sal_Char* p = new sal_Char[ nStrLen+1 ];
     124          14 :             p[nStrLen] = 0;
     125          14 :             if( Read( p, nStrLen ) == nStrLen )
     126             :             {
     127             :                 //The encoding here is "ANSI", which is pretty useless seeing as
     128             :                 //the actual codepage used doesn't seem to be specified/stored
     129             :                 //anywhere :-(. Might as well pick 1252 and be consistent on
     130             :                 //all platforms and envs
     131             :                 //http://www.openoffice.org/nonav/issues/showattachment.cgi/68668/Orginal%20Document.doc
     132             :                 //for a good edge-case example
     133          14 :                 aUserName = nStrLen ? String( p, RTL_TEXTENCODING_MS_1252 ) : String();
     134          14 :                 nCbFormat = ReadClipboardFormat( *this );
     135             :             }
     136             :             else
     137           0 :                 SetError( SVSTREAM_GENERALERROR );
     138          14 :             delete [] p;
     139             :         }
     140             :     }
     141          14 :     return sal_Bool( GetError() == SVSTREAM_OK );
     142             : }
     143             : 
     144           0 : sal_Bool StgCompObjStream::Store()
     145             : {
     146           0 :     if( GetError() != SVSTREAM_OK )
     147           0 :         return sal_False;
     148           0 :     Seek( 0L );
     149           0 :     rtl::OString aAsciiUserName(rtl::OUStringToOString(aUserName, RTL_TEXTENCODING_MS_1252));
     150           0 :     *this << (sal_Int16) 1          // Version?
     151           0 :               << (sal_Int16) -2                     // 0xFFFE = Byte Order Indicator
     152           0 :               << (sal_Int32) 0x0A03         // Windows 3.10
     153           0 :               << (sal_Int32) -1L
     154           0 :               << aClsId             // Class ID
     155           0 :               << (sal_Int32) (aAsciiUserName.getLength() + 1)
     156           0 :               << (const char *)aAsciiUserName.getStr()
     157           0 :               << (sal_uInt8) 0;             // string terminator
     158           0 :     WriteClipboardFormat( *this, nCbFormat );
     159           0 :     *this << (sal_Int32) 0;             // terminator
     160           0 :     Commit();
     161           0 :     return sal_Bool( GetError() == SVSTREAM_OK );
     162             : }
     163             : 
     164             : /////////////////////////// class StgOleStream ///////////////////////////
     165             : 
     166           0 : StgOleStream::StgOleStream( BaseStorage& rStg, sal_Bool bWr )
     167           0 :             : StgInternalStream( rStg, rtl::OUString("\1Ole"), bWr )
     168             : {
     169           0 :     nFlags = 0;
     170           0 : }
     171             : 
     172           0 : sal_Bool StgOleStream::Load()
     173             : {
     174           0 :     nFlags = 0;
     175           0 :     if( GetError() != SVSTREAM_OK )
     176           0 :         return sal_False;
     177           0 :     sal_Int32 version = 0;
     178           0 :     Seek( 0L );
     179           0 :     *this >> version >> nFlags;
     180           0 :     return sal_Bool( GetError() == SVSTREAM_OK );
     181             : }
     182             : 
     183           0 : sal_Bool StgOleStream::Store()
     184             : {
     185           0 :     if( GetError() != SVSTREAM_OK )
     186           0 :         return sal_False;
     187           0 :     Seek( 0L );
     188           0 :     *this << (sal_Int32) 0x02000001         // OLE version, format
     189           0 :           << (sal_Int32) nFlags             // Object flags
     190           0 :           << (sal_Int32) 0                  // Update Options
     191           0 :           << (sal_Int32) 0                  // reserved
     192           0 :           << (sal_Int32) 0;                 // Moniker 1
     193           0 :     Commit();
     194           0 :     return sal_Bool( GetError() == SVSTREAM_OK );
     195             : }
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10