LCOV - code coverage report
Current view: top level - libreoffice/sot/source/sdstor - stgole.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 88 102 86.3 %
Date: 2012-12-17 Functions: 12 14 85.7 %
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          60 : StgInternalStream::StgInternalStream
      32          60 :     ( BaseStorage& rStg, const String& rName, sal_Bool bWr )
      33             : {
      34          60 :     bIsWritable = sal_True;
      35             :     sal_uInt16 nMode = bWr
      36             :                  ? STREAM_WRITE | STREAM_SHARE_DENYALL
      37          60 :                  : STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE;
      38          60 :     pStrm = rStg.OpenStream( rName, nMode );
      39             : 
      40             :     // set the error code right here in the stream
      41          60 :     SetError( rStg.GetError() );
      42          60 :     SetBufferSize( 1024 );
      43          60 : }
      44             : 
      45         120 : StgInternalStream::~StgInternalStream()
      46             : {
      47          60 :     delete pStrm;
      48          60 : }
      49             : 
      50          40 : sal_uLong StgInternalStream::GetData( void* pData, sal_uLong nSize )
      51             : {
      52          40 :     if( pStrm )
      53             :     {
      54          40 :         nSize = pStrm->Read( pData, nSize );
      55          40 :         SetError( pStrm->GetError() );
      56          40 :         return nSize;
      57             :     }
      58             :     else
      59           0 :         return 0;
      60             : }
      61             : 
      62          20 : sal_uLong StgInternalStream::PutData( const void* pData, sal_uLong nSize )
      63             : {
      64          20 :     if( pStrm )
      65             :     {
      66          20 :         nSize = pStrm->Write( pData, nSize );
      67          20 :         SetError( pStrm->GetError() );
      68          20 :         return nSize;
      69             :     }
      70             :     else
      71           0 :         return 0;
      72             : }
      73             : 
      74         100 : sal_uLong StgInternalStream::SeekPos( sal_uLong nPos )
      75             : {
      76         100 :     return pStrm ? pStrm->Seek( nPos ) : 0;
      77             : }
      78             : 
      79          20 : void StgInternalStream::FlushData()
      80             : {
      81          20 :     if( pStrm )
      82             :     {
      83          20 :         pStrm->Flush();
      84          20 :         SetError( pStrm->GetError() );
      85             :     }
      86          20 : }
      87             : 
      88          20 : void StgInternalStream::Commit()
      89             : {
      90          20 :     Flush();
      91          20 :     pStrm->Commit();
      92          20 : }
      93             : 
      94             : ///////////////////////// class StgCompObjStream /////////////////////////
      95             : 
      96          50 : StgCompObjStream::StgCompObjStream( BaseStorage& rStg, sal_Bool bWr )
      97          50 :             : StgInternalStream( rStg, rtl::OUString("\1CompObj"), bWr )
      98             : {
      99          50 :     memset( &aClsId, 0, sizeof( ClsId ) );
     100          50 :     nCbFormat = 0;
     101          50 : }
     102             : 
     103          40 : sal_Bool StgCompObjStream::Load()
     104             : {
     105          40 :     memset( &aClsId, 0, sizeof( ClsId ) );
     106          40 :     nCbFormat = 0;
     107          40 :     aUserName.Erase();
     108          40 :     if( GetError() != SVSTREAM_OK )
     109           0 :         return sal_False;
     110          40 :     Seek( 8L );     // skip the first part
     111          40 :     sal_Int32 nMarker = 0;
     112          40 :     *this >> nMarker;
     113          40 :     if( nMarker == -1L )
     114             :     {
     115          40 :         *this >> aClsId;
     116          40 :         sal_Int32 nLen1 = 0;
     117          40 :         *this >> nLen1;
     118          40 :         if ( nLen1 > 0 )
     119             :         {
     120             :             // higher bits are ignored
     121          40 :             sal_uLong nStrLen = ::std::min( nLen1, (sal_Int32)0xFFFE );
     122             : 
     123          40 :             sal_Char* p = new sal_Char[ nStrLen+1 ];
     124          40 :             p[nStrLen] = 0;
     125          40 :             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          40 :                 aUserName = nStrLen ? String( p, RTL_TEXTENCODING_MS_1252 ) : String();
     134          40 :                 nCbFormat = ReadClipboardFormat( *this );
     135             :             }
     136             :             else
     137           0 :                 SetError( SVSTREAM_GENERALERROR );
     138          40 :             delete [] p;
     139             :         }
     140             :     }
     141          40 :     return sal_Bool( GetError() == SVSTREAM_OK );
     142             : }
     143             : 
     144          10 : sal_Bool StgCompObjStream::Store()
     145             : {
     146          10 :     if( GetError() != SVSTREAM_OK )
     147           0 :         return sal_False;
     148          10 :     Seek( 0L );
     149          10 :     rtl::OString aAsciiUserName(rtl::OUStringToOString(aUserName, RTL_TEXTENCODING_MS_1252));
     150          10 :     *this << (sal_Int16) 1          // Version?
     151          10 :               << (sal_Int16) -2                     // 0xFFFE = Byte Order Indicator
     152          10 :               << (sal_Int32) 0x0A03         // Windows 3.10
     153          10 :               << (sal_Int32) -1L
     154          20 :               << aClsId             // Class ID
     155          20 :               << (sal_Int32) (aAsciiUserName.getLength() + 1)
     156          20 :               << (const char *)aAsciiUserName.getStr()
     157          10 :               << (sal_uInt8) 0;             // string terminator
     158          10 :     WriteClipboardFormat( *this, nCbFormat );
     159          10 :     *this << (sal_Int32) 0;             // terminator
     160          10 :     Commit();
     161          10 :     return sal_Bool( GetError() == SVSTREAM_OK );
     162             : }
     163             : 
     164             : /////////////////////////// class StgOleStream ///////////////////////////
     165             : 
     166          10 : StgOleStream::StgOleStream( BaseStorage& rStg, sal_Bool bWr )
     167          10 :             : StgInternalStream( rStg, rtl::OUString("\1Ole"), bWr )
     168             : {
     169          10 :     nFlags = 0;
     170          10 : }
     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          10 : sal_Bool StgOleStream::Store()
     184             : {
     185          10 :     if( GetError() != SVSTREAM_OK )
     186           0 :         return sal_False;
     187          10 :     Seek( 0L );
     188          10 :     *this << (sal_Int32) 0x02000001         // OLE version, format
     189          20 :           << (sal_Int32) nFlags             // Object flags
     190          10 :           << (sal_Int32) 0                  // Update Options
     191          10 :           << (sal_Int32) 0                  // reserved
     192          10 :           << (sal_Int32) 0;                 // Moniker 1
     193          10 :     Commit();
     194          10 :     return sal_Bool( GetError() == SVSTREAM_OK );
     195             : }
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10