LCOV - code coverage report
Current view: top level - sot/source/sdstor - stgole.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 86 100 86.0 %
Date: 2014-11-03 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             : #include <algorithm>
      21             : 
      22             : #include "rtl/string.h"
      23             : #include "stgole.hxx"
      24             : #include "sot/storinfo.hxx"
      25             : #include <boost/scoped_array.hpp>
      26             : 
      27             : #ifdef _MSC_VER
      28             : #pragma warning(disable: 4342)
      29             : #endif
      30             : ///////////////////////// class StgInternalStream
      31             : 
      32         172 : StgInternalStream::StgInternalStream( BaseStorage& rStg, const OUString& rName, bool bWr )
      33             : {
      34         172 :     bIsWritable = true;
      35             :     sal_uInt16 nMode = bWr
      36             :                  ? STREAM_WRITE | STREAM_SHARE_DENYALL
      37         172 :                  : STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE;
      38         172 :     pStrm = rStg.OpenStream( rName, nMode );
      39             : 
      40             :     // set the error code right here in the stream
      41         172 :     SetError( rStg.GetError() );
      42         172 :     SetBufferSize( 1024 );
      43         172 : }
      44             : 
      45         344 : StgInternalStream::~StgInternalStream()
      46             : {
      47         172 :     delete pStrm;
      48         172 : }
      49             : 
      50          48 : sal_uLong StgInternalStream::GetData( void* pData, sal_uLong nSize )
      51             : {
      52          48 :     if( pStrm )
      53             :     {
      54          48 :         nSize = pStrm->Read( pData, nSize );
      55          48 :         SetError( pStrm->GetError() );
      56          48 :         return nSize;
      57             :     }
      58             :     else
      59           0 :         return 0;
      60             : }
      61             : 
      62         124 : sal_uLong StgInternalStream::PutData( const void* pData, sal_uLong nSize )
      63             : {
      64         124 :     if( pStrm )
      65             :     {
      66         124 :         nSize = pStrm->Write( pData, nSize );
      67         124 :         SetError( pStrm->GetError() );
      68         124 :         return nSize;
      69             :     }
      70             :     else
      71           0 :         return 0;
      72             : }
      73             : 
      74         220 : sal_uInt64 StgInternalStream::SeekPos(sal_uInt64 const nPos)
      75             : {
      76         220 :     return pStrm ? pStrm->Seek( nPos ) : 0;
      77             : }
      78             : 
      79         124 : void StgInternalStream::FlushData()
      80             : {
      81         124 :     if( pStrm )
      82             :     {
      83         124 :         pStrm->Flush();
      84         124 :         SetError( pStrm->GetError() );
      85             :     }
      86         124 : }
      87             : 
      88         124 : void StgInternalStream::Commit()
      89             : {
      90         124 :     Flush();
      91         124 :     pStrm->Commit();
      92         124 : }
      93             : 
      94             : ///////////////////////// class StgCompObjStream
      95             : 
      96         110 : StgCompObjStream::StgCompObjStream( BaseStorage& rStg, bool bWr )
      97         110 :     : StgInternalStream( rStg, OUString("\1CompObj"), bWr )
      98             : {
      99         110 :     memset( &aClsId, 0, sizeof( ClsId ) );
     100         110 :     nCbFormat = 0;
     101         110 : }
     102             : 
     103          48 : bool StgCompObjStream::Load()
     104             : {
     105          48 :     memset( &aClsId, 0, sizeof( ClsId ) );
     106          48 :     nCbFormat = 0;
     107          48 :     aUserName = "";
     108          48 :     if( GetError() != SVSTREAM_OK )
     109           0 :         return false;
     110          48 :     Seek( 8L );     // skip the first part
     111          48 :     sal_Int32 nMarker = 0;
     112          48 :     ReadInt32( nMarker );
     113          48 :     if( nMarker == -1L )
     114             :     {
     115          48 :         ReadClsId( *this, aClsId );
     116          48 :         sal_Int32 nLen1 = 0;
     117          48 :         ReadInt32( nLen1 );
     118          48 :         if ( nLen1 > 0 )
     119             :         {
     120             :             // higher bits are ignored
     121          48 :             sal_uLong nStrLen = ::std::min( nLen1, (sal_Int32)0xFFFE );
     122             : 
     123          48 :             boost::scoped_array<sal_Char> p(new sal_Char[ nStrLen+1 ]);
     124          48 :             p[nStrLen] = 0;
     125          48 :             if( Read( p.get(), 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             :                 //https://issues.apache.org/ooo/attachment.cgi?id=68668
     132             :                 //for a good edge-case example
     133          48 :                 aUserName = nStrLen ? OUString( p.get(), nStrLen, RTL_TEXTENCODING_MS_1252 ) : OUString();
     134          48 :                 nCbFormat = ReadClipboardFormat( *this );
     135             :             }
     136             :             else
     137           0 :                 SetError( SVSTREAM_GENERALERROR );
     138             :         }
     139             :     }
     140          48 :     return GetError() == SVSTREAM_OK;
     141             : }
     142             : 
     143          62 : bool StgCompObjStream::Store()
     144             : {
     145          62 :     if( GetError() != SVSTREAM_OK )
     146           0 :         return false;
     147          62 :     Seek( 0L );
     148          62 :     OString aAsciiUserName(OUStringToOString(aUserName, RTL_TEXTENCODING_MS_1252));
     149          62 :     WriteInt16(  1 );          // Version?
     150          62 :     WriteInt16(  -2 );                     // 0xFFFE = Byte Order Indicator
     151          62 :     WriteInt32( 0x0A03 );         // Windows 3.10
     152          62 :     WriteInt32( -1L );
     153          62 :     WriteClsId( *this, aClsId );             // Class ID
     154          62 :     WriteInt32( (aAsciiUserName.getLength() + 1) );
     155          62 :     WriteCharPtr( (const char *)aAsciiUserName.getStr() );
     156          62 :     WriteUChar(  0 );             // string terminator
     157          62 :     WriteClipboardFormat( *this, nCbFormat );
     158          62 :     WriteInt32( 0 );             // terminator
     159          62 :     Commit();
     160          62 :     return GetError() == SVSTREAM_OK;
     161             : }
     162             : 
     163             : /////////////////////////// class StgOleStream
     164             : 
     165          62 : StgOleStream::StgOleStream( BaseStorage& rStg, bool bWr )
     166          62 :     : StgInternalStream( rStg, OUString("\1Ole"), bWr )
     167             : {
     168          62 :     nFlags = 0;
     169          62 : }
     170             : 
     171           0 : bool StgOleStream::Load()
     172             : {
     173           0 :     nFlags = 0;
     174           0 :     if( GetError() != SVSTREAM_OK )
     175           0 :         return false;
     176             : 
     177           0 :     sal_Int32 version = 0;
     178           0 :     Seek( 0L );
     179           0 :     ReadInt32( version ).ReadUInt32( nFlags );
     180           0 :     return GetError() == SVSTREAM_OK;
     181             : }
     182             : 
     183          62 : bool StgOleStream::Store()
     184             : {
     185          62 :     if( GetError() != SVSTREAM_OK )
     186           0 :         return false;
     187             : 
     188          62 :     Seek( 0L );
     189          62 :     WriteInt32( 0x02000001 );         // OLE version, format
     190          62 :     WriteInt32( nFlags );             // Object flags
     191          62 :     WriteInt32( 0 );                  // Update Options
     192          62 :     WriteInt32( 0 );                  // reserved
     193          62 :     WriteInt32( 0 );                 // Moniker 1
     194          62 :     Commit();
     195          62 :     return GetError() == SVSTREAM_OK;
     196             : }
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10