Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name wrapper.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SYSTEM_ZLIB -D BOOST_ALL_NO_LIB -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sdext/source/pdfimport/inc -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/sdext/pdfimport -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libxml2 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx

/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx

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 <config_folders.h>
21
22#include <contentsink.hxx>
23#include <pdfparse.hxx>
24#include <pdfihelper.hxx>
25#include <wrapper.hxx>
26
27#include <osl/file.h>
28#include <osl/file.hxx>
29#include <osl/thread.h>
30#include <osl/process.h>
31#include <osl/diagnose.h>
32#include <rtl/bootstrap.hxx>
33#include <rtl/ustring.hxx>
34#include <rtl/ustrbuf.hxx>
35#include <rtl/strbuf.hxx>
36#include <sal/log.hxx>
37
38#include <comphelper/propertysequence.hxx>
39#include <com/sun/star/io/XInputStream.hpp>
40#include <com/sun/star/uno/XComponentContext.hpp>
41#include <com/sun/star/awt/FontDescriptor.hpp>
42#include <com/sun/star/beans/XMaterialHolder.hpp>
43#include <com/sun/star/rendering/PathCapType.hpp>
44#include <com/sun/star/rendering/PathJoinType.hpp>
45#include <com/sun/star/rendering/XPolyPolygon2D.hpp>
46#include <com/sun/star/geometry/Matrix2D.hpp>
47#include <com/sun/star/geometry/AffineMatrix2D.hpp>
48#include <com/sun/star/geometry/RealRectangle2D.hpp>
49#include <com/sun/star/geometry/RealSize2D.hpp>
50#include <com/sun/star/task/XInteractionHandler.hpp>
51
52#include <basegfx/point/b2dpoint.hxx>
53#include <basegfx/polygon/b2dpolypolygon.hxx>
54#include <basegfx/polygon/b2dpolygon.hxx>
55#include <basegfx/utils/unopolypolygon.hxx>
56
57#include <vcl/metric.hxx>
58#include <vcl/font.hxx>
59#include <vcl/virdev.hxx>
60
61#include <memory>
62#include <unordered_map>
63#include <string.h>
64#include <stdlib.h>
65
66#include <rtl/character.hxx>
67
68using namespace com::sun::star;
69
70namespace pdfi
71{
72
73namespace
74{
75
76// identifier of the strings coming from the out-of-process xpdf
77// converter
78enum parseKey {
79 CLIPPATH,
80 DRAWCHAR,
81 DRAWIMAGE,
82 DRAWLINK,
83 DRAWMASK,
84 DRAWMASKEDIMAGE,
85 DRAWSOFTMASKEDIMAGE,
86 ENDPAGE,
87 ENDTEXTOBJECT,
88 EOCLIPPATH,
89 EOFILLPATH,
90 FILLPATH,
91 HYPERLINK,
92 INTERSECTCLIP,
93 INTERSECTEOCLIP,
94 POPSTATE,
95 PUSHSTATE,
96 RESTORESTATE,
97 SAVESTATE,
98 SETBLENDMODE,
99 SETFILLCOLOR,
100 SETFONT,
101 SETLINECAP,
102 SETLINEDASH,
103 SETLINEJOIN,
104 SETLINEWIDTH,
105 SETMITERLIMIT,
106 SETPAGENUM,
107 SETSTROKECOLOR,
108 SETTEXTRENDERMODE,
109 SETTRANSFORMATION,
110 STARTPAGE,
111 STROKEPATH,
112 UPDATEBLENDMODE,
113 UPDATECTM,
114 UPDATEFILLCOLOR,
115 UPDATEFILLOPACITY,
116 UPDATEFLATNESS,
117 UPDATEFONT,
118 UPDATELINECAP,
119 UPDATELINEDASH,
120 UPDATELINEJOIN,
121 UPDATELINEWIDTH,
122 UPDATEMITERLIMIT,
123 UPDATESTROKECOLOR,
124 UPDATESTROKEOPACITY,
125 NONE
126};
127
128#if defined _MSC_VER && defined __clang__1
129#pragma clang diagnostic push
130#pragma clang diagnostic ignored "-Wdeprecated-register"
131#pragma clang diagnostic ignored "-Wextra-tokens"
132#endif
133#include <hash.cxx>
134#if defined _MSC_VER && defined __clang__1
135#pragma clang diagnostic pop
136#endif
137
138class Parser
139{
140 typedef std::unordered_map< sal_Int64,
141 FontAttributes > FontMapType;
142
143 ScopedVclPtr<VirtualDevice> m_xDev;
144 const uno::Reference<uno::XComponentContext> m_xContext;
145 const ContentSinkSharedPtr m_pSink;
146 const oslFileHandle m_pErr;
147 OString m_aLine;
148 FontMapType m_aFontMap;
149 sal_Int32 m_nNextToken;
150 sal_Int32 m_nCharIndex;
151
152
153 OString readNextToken();
154 void readInt32( sal_Int32& o_Value );
155 sal_Int32 readInt32();
156 void readInt64( sal_Int64& o_Value );
157 void readDouble( double& o_Value );
158 double readDouble();
159 void readBinaryData( uno::Sequence<sal_Int8>& rBuf );
160
161 uno::Reference<rendering::XPolyPolygon2D> readPath();
162
163 void readChar();
164 void readLineCap();
165 void readLineDash();
166 void readLineJoin();
167 void readTransformation();
168 rendering::ARGBColor readColor();
169 static void parseFontFamilyName( FontAttributes& aResult );
170 void readFont();
171 uno::Sequence<beans::PropertyValue> readImageImpl();
172
173 void readImage();
174 void readMask();
175 void readLink();
176 void readMaskedImage();
177 void readSoftMaskedImage();
178 static sal_Int32 parseFontCheckForString(const sal_Unicode* pCopy, sal_Int32 nCopyLen,
179 const char* pAttrib, sal_Int32 nAttribLen,
180 FontAttributes& rResult, bool bItalic, bool bBold);
181 static sal_Int32 parseFontRemoveSuffix(const sal_Unicode* pCopy, sal_Int32 nCopyLen,
182 const char* pAttrib, sal_Int32 nAttribLen);
183
184public:
185 Parser( const ContentSinkSharedPtr& rSink,
186 oslFileHandle pErr,
187 const uno::Reference<uno::XComponentContext>& xContext ) :
188 m_xContext(xContext),
189 m_pSink(rSink),
190 m_pErr(pErr),
191 m_aLine(),
192 m_aFontMap(101),
193 m_nNextToken(-1),
194 m_nCharIndex(-1)
195 {}
196
197 void parseLine( const OString& rLine );
198};
199
200/** Unescapes line-ending characters in input string. These
201 characters are encoded as pairs of characters: '\\' 'n', resp.
202 '\\' 'r'. This function converts them back to '\n', resp. '\r'.
203 */
204OString lcl_unescapeLineFeeds(const OString& i_rStr)
205{
206 const size_t nOrigLen(sal::static_int_cast<size_t>(i_rStr.getLength()));
207 const char* const pOrig(i_rStr.getStr());
208 std::unique_ptr<char[]> pBuffer(new char[nOrigLen + 1]);
209
210 const char* pRead(pOrig);
211 char* pWrite(pBuffer.get());
212 const char* pCur(pOrig);
213 while ((pCur = strchr(pCur, '\\')) != nullptr)
214 {
215 const char cNext(pCur[1]);
216 if (cNext == 'n' || cNext == 'r' || cNext == '\\')
217 {
218 const size_t nLen(pCur - pRead);
219 strncpy(pWrite, pRead, nLen);
220 pWrite += nLen;
221 *pWrite = cNext == 'n' ? '\n' : (cNext == 'r' ? '\r' : '\\');
222 ++pWrite;
223 pCur = pRead = pCur + 2;
224 }
225 else
226 {
227 // Just continue on the next character. The current
228 // block will be copied the next time it goes through the
229 // 'if' branch.
230 ++pCur;
231 }
232 }
233 // maybe there are some data to copy yet
234 if (sal::static_int_cast<size_t>(pRead - pOrig) < nOrigLen)
235 {
236 const size_t nLen(nOrigLen - (pRead - pOrig));
237 strncpy(pWrite, pRead, nLen);
238 pWrite += nLen;
239 }
240 *pWrite = '\0';
241
242 OString aResult(pBuffer.get());
243 return aResult;
244}
245
246OString Parser::readNextToken()
247{
248 OSL_PRECOND(m_nCharIndex!=-1,"insufficient input")do { if (true && (!(m_nCharIndex!=-1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "248" ": "), "%s", "insufficient input"); } } while (false
)
;
249 return m_aLine.getToken(m_nNextToken,' ',m_nCharIndex);
250}
251
252void Parser::readInt32( sal_Int32& o_Value )
253{
254 o_Value = readNextToken().toInt32();
255}
256
257sal_Int32 Parser::readInt32()
258{
259 return readNextToken().toInt32();
260}
261
262void Parser::readInt64( sal_Int64& o_Value )
263{
264 o_Value = readNextToken().toInt64();
265}
266
267void Parser::readDouble( double& o_Value )
268{
269 o_Value = readNextToken().toDouble();
270}
271
272double Parser::readDouble()
273{
274 return readNextToken().toDouble();
275}
276
277void Parser::readBinaryData( uno::Sequence<sal_Int8>& rBuf )
278{
279 sal_Int32 nFileLen( rBuf.getLength() );
280 sal_Int8* pBuf( rBuf.getArray() );
281 sal_uInt64 nBytesRead(0);
282 oslFileError nRes=osl_File_E_None;
283 while( nFileLen )
284 {
285 nRes = osl_readFile( m_pErr, pBuf, nFileLen, &nBytesRead );
286 if (osl_File_E_None != nRes )
287 break;
288 pBuf += nBytesRead;
289 nFileLen -= sal::static_int_cast<sal_Int32>(nBytesRead);
290 }
291
292 OSL_PRECOND(nRes==osl_File_E_None, "inconsistent data")do { if (true && (!(nRes==osl_File_E_None))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "292" ": "), "%s", "inconsistent data"); } } while (false
)
;
293}
294
295uno::Reference<rendering::XPolyPolygon2D> Parser::readPath()
296{
297 const OString aSubPathMarker( "subpath" );
298
299 if( readNextToken() != aSubPathMarker )
300 OSL_PRECOND(false, "broken path")do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "300" ": "), "%s", "broken path"); } } while (false)
;
301
302 basegfx::B2DPolyPolygon aResult;
303 while( m_nCharIndex != -1 )
304 {
305 basegfx::B2DPolygon aSubPath;
306
307 sal_Int32 nClosedFlag;
308 readInt32( nClosedFlag );
309 aSubPath.setClosed( nClosedFlag != 0 );
310
311 sal_Int32 nContiguousControlPoints(0);
312 sal_Int32 nDummy=m_nCharIndex;
313 OString aCurrToken( m_aLine.getToken(m_nNextToken,' ',nDummy) );
314
315 while( m_nCharIndex != -1 && aCurrToken != aSubPathMarker )
316 {
317 sal_Int32 nCurveFlag;
318 double nX, nY;
319 readDouble( nX );
320 readDouble( nY );
321 readInt32( nCurveFlag );
322
323 aSubPath.append(basegfx::B2DPoint(nX,nY));
324 if( nCurveFlag )
325 {
326 ++nContiguousControlPoints;
327 }
328 else if( nContiguousControlPoints )
329 {
330 OSL_PRECOND(nContiguousControlPoints==2,"broken bezier path")do { if (true && (!(nContiguousControlPoints==2))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "330" ": "), "%s", "broken bezier path"); } } while (false
)
;
331
332 // have two control points before us. the current one
333 // is a normal point - thus, convert previous points
334 // into bezier segment
335 const sal_uInt32 nPoints( aSubPath.count() );
336 const basegfx::B2DPoint aCtrlA( aSubPath.getB2DPoint(nPoints-3) );
337 const basegfx::B2DPoint aCtrlB( aSubPath.getB2DPoint(nPoints-2) );
338 const basegfx::B2DPoint aEnd( aSubPath.getB2DPoint(nPoints-1) );
339 aSubPath.remove(nPoints-3, 3);
340 aSubPath.appendBezierSegment(aCtrlA, aCtrlB, aEnd);
341
342 nContiguousControlPoints=0;
343 }
344
345 // one token look-ahead (new subpath or more points?
346 nDummy=m_nCharIndex;
347 aCurrToken = m_aLine.getToken(m_nNextToken,' ',nDummy);
348 }
349
350 aResult.append( aSubPath );
351 if( m_nCharIndex != -1 )
352 readNextToken();
353 }
354
355 return static_cast<rendering::XLinePolyPolygon2D*>(
356 new basegfx::unotools::UnoPolyPolygon(aResult));
357}
358
359void Parser::readChar()
360{
361 double fontSize;
362 geometry::Matrix2D aUnoMatrix;
363 geometry::RealRectangle2D aRect;
364
365 readDouble(aRect.X1);
366 readDouble(aRect.Y1);
367 readDouble(aRect.X2);
368 readDouble(aRect.Y2);
369 readDouble(aUnoMatrix.m00);
370 readDouble(aUnoMatrix.m01);
371 readDouble(aUnoMatrix.m10);
372 readDouble(aUnoMatrix.m11);
373 readDouble(fontSize);
374
375 OString aChars;
376
377 if (m_nCharIndex != -1)
378 aChars = lcl_unescapeLineFeeds( m_aLine.copy( m_nCharIndex ) );
379
380 // chars gobble up rest of line
381 m_nCharIndex = -1;
382
383 m_pSink->drawGlyphs(OStringToOUString(aChars, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
384 aRect, aUnoMatrix, fontSize);
385}
386
387void Parser::readLineCap()
388{
389 sal_Int8 nCap(rendering::PathCapType::BUTT);
390 switch( readInt32() )
391 {
392 default:
393 case 0: nCap = rendering::PathCapType::BUTT; break;
394 case 1: nCap = rendering::PathCapType::ROUND; break;
395 case 2: nCap = rendering::PathCapType::SQUARE; break;
396 }
397 m_pSink->setLineCap(nCap);
398}
399
400void Parser::readLineDash()
401{
402 if( m_nCharIndex == -1 )
403 {
404 m_pSink->setLineDash( uno::Sequence<double>(), 0.0 );
405 return;
406 }
407
408 const double nOffset(readDouble());
409 const sal_Int32 nLen(readInt32());
410
411 uno::Sequence<double> aDashArray(nLen);
412 double* pArray=aDashArray.getArray();
413 for( sal_Int32 i=0; i<nLen; ++i )
414 *pArray++ = readDouble();
415
416 m_pSink->setLineDash( aDashArray, nOffset );
417}
418
419void Parser::readLineJoin()
420{
421 sal_Int8 nJoin(rendering::PathJoinType::MITER);
422 switch( readInt32() )
423 {
424 default:
425 case 0: nJoin = rendering::PathJoinType::MITER; break;
426 case 1: nJoin = rendering::PathJoinType::ROUND; break;
427 case 2: nJoin = rendering::PathJoinType::BEVEL; break;
428 }
429 m_pSink->setLineJoin(nJoin);
430}
431
432void Parser::readTransformation()
433{
434 geometry::AffineMatrix2D aMat;
435 readDouble(aMat.m00);
436 readDouble(aMat.m10);
437 readDouble(aMat.m01);
438 readDouble(aMat.m11);
439 readDouble(aMat.m02);
440 readDouble(aMat.m12);
441 m_pSink->setTransformation( aMat );
442}
443
444rendering::ARGBColor Parser::readColor()
445{
446 rendering::ARGBColor aRes;
447 readDouble(aRes.Red);
448 readDouble(aRes.Green);
449 readDouble(aRes.Blue);
450 readDouble(aRes.Alpha);
451 return aRes;
452}
453
454sal_Int32 Parser::parseFontCheckForString(
455 const sal_Unicode* pCopy, sal_Int32 nCopyLen,
456 const char* pAttrib, sal_Int32 nAttribLen,
457 FontAttributes& rResult, bool bItalic, bool bBold)
458{
459 if (nCopyLen < nAttribLen)
460 return 0;
461 for (sal_Int32 i = 0; i < nAttribLen; ++i)
462 {
463 sal_uInt32 nCode = pAttrib[i];
464 if (rtl::toAsciiLowerCase(pCopy[i]) != nCode
465 && rtl::toAsciiUpperCase(pCopy[i]) != nCode)
466 return 0;
467 }
468 rResult.isItalic |= bItalic;
469 rResult.isBold |= bBold;
470 return nAttribLen;
471}
472
473sal_Int32 Parser::parseFontRemoveSuffix(
474 const sal_Unicode* pCopy, sal_Int32 nCopyLen,
475 const char* pAttrib, sal_Int32 nAttribLen)
476{
477 if (nCopyLen < nAttribLen)
478 return 0;
479 for (sal_Int32 i = 0; i < nAttribLen; ++i)
480 if ( pCopy[nCopyLen - nAttribLen + i] != pAttrib[i] )
481 return 0;
482 return nAttribLen;
483}
484
485void Parser::parseFontFamilyName( FontAttributes& rResult )
486{
487 OUStringBuffer aNewFamilyName( rResult.familyName.getLength() );
488
489 const sal_Unicode* pCopy = rResult.familyName.getStr();
490 sal_Int32 nLen = rResult.familyName.getLength();
491 // parse out truetype subsets (e.g. BAAAAA+Thorndale)
492 if( nLen > 8 && pCopy[6] == '+' )
493 {
494 pCopy += 7;
495 nLen -= 7;
496 }
497
498 // TODO: Looks like this block needs to be refactored
499 while( nLen )
500 {
501 if (parseFontRemoveSuffix(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("PSMT")(&("PSMT")[0]), ((sal_Int32)(sizeof(sal_n_array_size("PSMT"
)))-1)
))
502 {
503 nLen -= RTL_CONSTASCII_LENGTH("PSMT")((sal_Int32)((sizeof(sal_n_array_size("PSMT")))-1));
504 }
505 else if (parseFontRemoveSuffix(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("MT")(&("MT")[0]), ((sal_Int32)(sizeof(sal_n_array_size("MT"))
)-1)
))
506 {
507 nLen -= RTL_CONSTASCII_LENGTH("MT")((sal_Int32)((sizeof(sal_n_array_size("MT")))-1));
508 }
509
510 if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("Italic")(&("Italic")[0]), ((sal_Int32)(sizeof(sal_n_array_size("Italic"
)))-1)
, rResult, true, false))
511 {
512 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("Italic")((sal_Int32)((sizeof(sal_n_array_size("Italic")))-1));
513 nLen -= nAttribLen;
514 pCopy += nAttribLen;
515 }
516 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-LightOblique")(&("-LightOblique")[0]), ((sal_Int32)(sizeof(sal_n_array_size
("-LightOblique")))-1)
, rResult, true, false))
517 {
518 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-LightOblique")((sal_Int32)((sizeof(sal_n_array_size("-LightOblique")))-1));
519 nLen -= nAttribLen;
520 pCopy += nAttribLen;
521 }
522 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Light")(&("-Light")[0]), ((sal_Int32)(sizeof(sal_n_array_size("-Light"
)))-1)
, rResult, false, false))
523 {
524 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Light")((sal_Int32)((sizeof(sal_n_array_size("-Light")))-1));
525 nLen -= nAttribLen;
526 pCopy += nAttribLen;
527 }
528 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-BoldOblique")(&("-BoldOblique")[0]), ((sal_Int32)(sizeof(sal_n_array_size
("-BoldOblique")))-1)
, rResult, true, true))
529 {
530 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-BoldOblique")((sal_Int32)((sizeof(sal_n_array_size("-BoldOblique")))-1));
531 nLen -= nAttribLen;
532 pCopy += nAttribLen;
533 }
534 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Bold")(&("-Bold")[0]), ((sal_Int32)(sizeof(sal_n_array_size("-Bold"
)))-1)
, rResult, false, true))
535 {
536 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Bold")((sal_Int32)((sizeof(sal_n_array_size("-Bold")))-1));
537 nLen -= nAttribLen;
538 pCopy += nAttribLen;
539 }
540 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("Bold")(&("Bold")[0]), ((sal_Int32)(sizeof(sal_n_array_size("Bold"
)))-1)
, rResult, false, true))
541 {
542 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("Bold")((sal_Int32)((sizeof(sal_n_array_size("Bold")))-1));
543 nLen -= nAttribLen;
544 pCopy += nAttribLen;
545 }
546 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Roman")(&("-Roman")[0]), ((sal_Int32)(sizeof(sal_n_array_size("-Roman"
)))-1)
, rResult, false, false))
547 {
548 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Roman")((sal_Int32)((sizeof(sal_n_array_size("-Roman")))-1));
549 nLen -= nAttribLen;
550 pCopy += nAttribLen;
551 }
552 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Oblique")(&("-Oblique")[0]), ((sal_Int32)(sizeof(sal_n_array_size(
"-Oblique")))-1)
, rResult, true, false))
553 {
554 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Oblique")((sal_Int32)((sizeof(sal_n_array_size("-Oblique")))-1));
555 nLen -= nAttribLen;
556 pCopy += nAttribLen;
557 }
558 else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Reg")(&("-Reg")[0]), ((sal_Int32)(sizeof(sal_n_array_size("-Reg"
)))-1)
, rResult, false, false))
559 {
560 sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Reg")((sal_Int32)((sizeof(sal_n_array_size("-Reg")))-1));
561 nLen -= nAttribLen;
562 pCopy += nAttribLen;
563 }
564 else if(nLen > 0)
565 {
566 if( *pCopy != '-' )
567 aNewFamilyName.append( *pCopy );
568 pCopy++;
569 nLen--;
570 }
571 }
572 rResult.familyName = aNewFamilyName.makeStringAndClear();
573}
574
575void Parser::readFont()
576{
577 OString aFontName;
578 sal_Int64 nFontID;
579 sal_Int32 nIsEmbedded, nIsBold, nIsItalic, nIsUnderline, nFileLen;
580 double nSize;
581
582 readInt64(nFontID);
583 readInt32(nIsEmbedded);
584 readInt32(nIsBold);
585 readInt32(nIsItalic);
586 readInt32(nIsUnderline);
587 readDouble(nSize);
588 readInt32(nFileLen);
589
590 nSize = nSize < 0.0 ? -nSize : nSize;
591 aFontName = lcl_unescapeLineFeeds( m_aLine.copy( m_nCharIndex ) );
592
593 // name gobbles up rest of line
594 m_nCharIndex = -1;
595
596 FontMapType::const_iterator pFont( m_aFontMap.find(nFontID) );
597 if( pFont != m_aFontMap.end() )
598 {
599 OSL_PRECOND(nFileLen==0,"font data for known font")do { if (true && (!(nFileLen==0))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "599" ": "), "%s", "font data for known font"); } } while
(false)
;
600 FontAttributes aRes(pFont->second);
601 aRes.size = nSize;
602 m_pSink->setFont( aRes );
603
604 return;
605 }
606
607 // yet unknown font - get info and add to map
608 FontAttributes aResult( OStringToOUString( aFontName,
609 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ),
610 nIsBold != 0,
611 nIsItalic != 0,
612 nIsUnderline != 0,
613 nSize,
614 1.0);
615
616 // extract textual attributes (bold, italic in the name, etc.)
617 parseFontFamilyName(aResult);
618 // need to read font file?
619 if( nFileLen )
620 {
621 uno::Sequence<sal_Int8> aFontFile(nFileLen);
622 readBinaryData( aFontFile );
623
624 awt::FontDescriptor aFD;
625 uno::Sequence< uno::Any > aArgs(1);
626 aArgs[0] <<= aFontFile;
627
628 try
629 {
630 uno::Reference< beans::XMaterialHolder > xMat(
631 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
632 "com.sun.star.awt.FontIdentificator", aArgs, m_xContext ),
633 uno::UNO_QUERY );
634 if( xMat.is() )
635 {
636 uno::Any aRes( xMat->getMaterial() );
637 if( aRes >>= aFD )
638 {
639 if (!aFD.Name.isEmpty())
640 {
641 aResult.familyName = aFD.Name;
642 parseFontFamilyName(aResult);
643 }
644 aResult.isBold = (aFD.Weight > 100.0);
645 aResult.isItalic = (aFD.Slant == awt::FontSlant_OBLIQUE ||
646 aFD.Slant == awt::FontSlant_ITALIC );
647 aResult.isUnderline = false;
648 aResult.size = 0;
649 }
650 }
651 }
652 catch( uno::Exception& )
653 {
654 }
655
656 if( aResult.familyName.isEmpty() )
657 {
658 // last fallback
659 aResult.familyName = "Arial";
660 aResult.isUnderline = false;
661 }
662
663 }
664
665 if (!m_xDev)
666 m_xDev.disposeAndReset(VclPtr<VirtualDevice>::Create());
667
668 vcl::Font font(aResult.familyName, Size(0, 1000));
669 m_xDev->SetFont(font);
670 FontMetric metric(m_xDev->GetFontMetric());
671 aResult.ascent = metric.GetAscent() / 1000.0;
672
673 m_aFontMap[nFontID] = aResult;
674
675 aResult.size = nSize;
676 m_pSink->setFont(aResult);
677}
678
679uno::Sequence<beans::PropertyValue> Parser::readImageImpl()
680{
681 OString aToken = readNextToken();
682 const sal_Int32 nImageSize( readInt32() );
683
684 OUString aFileName;
685 if( aToken == "PNG" )
686 aFileName = "DUMMY.PNG";
687 else if( aToken == "JPEG" )
688 aFileName = "DUMMY.JPEG";
689 else if( aToken == "PBM" )
690 aFileName = "DUMMY.PBM";
691 else
692 {
693 SAL_WARN_IF(aToken != "PPM","sdext.pdfimport","Invalid bitmap format")do { if (true && (aToken != "PPM")) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "Invalid bitmap format"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "693" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Invalid bitmap format"), 0); } else {
::std::ostringstream sal_detail_stream; sal_detail_stream <<
"Invalid bitmap format"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "693" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Invalid bitmap format") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "693" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Invalid bitmap format"), 0); } else {
::std::ostringstream sal_detail_stream; sal_detail_stream <<
"Invalid bitmap format"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "693" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
694 aFileName = "DUMMY.PPM";
695 }
696
697 uno::Sequence<sal_Int8> aDataSequence(nImageSize);
698 readBinaryData( aDataSequence );
699
700 uno::Sequence< uno::Any > aStreamCreationArgs(1);
701 aStreamCreationArgs[0] <<= aDataSequence;
702
703 uno::Reference< uno::XComponentContext > xContext( m_xContext, uno::UNO_SET_THROW );
704 uno::Reference< lang::XMultiComponentFactory > xFactory( xContext->getServiceManager(), uno::UNO_SET_THROW );
705 uno::Reference< io::XInputStream > xDataStream(
706 xFactory->createInstanceWithArgumentsAndContext( "com.sun.star.io.SequenceInputStream", aStreamCreationArgs, m_xContext ),
707 uno::UNO_QUERY_THROW );
708
709 uno::Sequence<beans::PropertyValue> aSequence( comphelper::InitPropertySequence({
710 { "URL", uno::makeAny(aFileName) },
711 { "InputStream", uno::makeAny( xDataStream ) },
712 { "InputSequence", uno::makeAny(aDataSequence) }
713 }));
714
715 return aSequence;
716}
717
718void Parser::readImage()
719{
720 sal_Int32 nWidth, nHeight,nMaskColors;
721 readInt32(nWidth);
722 readInt32(nHeight);
723 readInt32(nMaskColors);
724
725 uno::Sequence<beans::PropertyValue> aImg( readImageImpl() );
726
727 if( nMaskColors )
728 {
729 uno::Sequence<sal_Int8> aDataSequence(nMaskColors);
730 readBinaryData( aDataSequence );
731
732 uno::Sequence<uno::Any> aMaskRanges(2);
733
734 uno::Sequence<double> aMinRange(nMaskColors/2);
735 uno::Sequence<double> aMaxRange(nMaskColors/2);
736 for( sal_Int32 i=0; i<nMaskColors/2; ++i )
737 {
738 aMinRange[i] = aDataSequence[i] / 255.0;
739 aMaxRange[i] = aDataSequence[i+nMaskColors/2] / 255.0;
740 }
741
742 aMaskRanges[0] <<= aMinRange;
743 aMaskRanges[1] <<= aMaxRange;
744
745 m_pSink->drawColorMaskedImage( aImg, aMaskRanges );
746 }
747 else
748 m_pSink->drawImage( aImg );
749}
750
751void Parser::readMask()
752{
753 sal_Int32 nWidth, nHeight, nInvert;
754 readInt32(nWidth);
755 readInt32(nHeight);
756 readInt32(nInvert);
757
758 m_pSink->drawMask( readImageImpl(), nInvert != 0);
759}
760
761void Parser::readLink()
762{
763 geometry::RealRectangle2D aBounds;
764 readDouble(aBounds.X1);
765 readDouble(aBounds.Y1);
766 readDouble(aBounds.X2);
767 readDouble(aBounds.Y2);
768
769 m_pSink->hyperLink( aBounds,
770 OStringToOUString( lcl_unescapeLineFeeds(
771 m_aLine.copy(m_nCharIndex) ),
772 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) );
773 // name gobbles up rest of line
774 m_nCharIndex = -1;
775}
776
777void Parser::readMaskedImage()
778{
779 sal_Int32 nWidth, nHeight, nMaskWidth, nMaskHeight, nMaskInvert;
780 readInt32(nWidth);
781 readInt32(nHeight);
782 readInt32(nMaskWidth);
783 readInt32(nMaskHeight);
784 readInt32(nMaskInvert);
785
786 const uno::Sequence<beans::PropertyValue> aImage( readImageImpl() );
787 const uno::Sequence<beans::PropertyValue> aMask ( readImageImpl() );
788 m_pSink->drawMaskedImage( aImage, aMask, nMaskInvert != 0 );
789}
790
791void Parser::readSoftMaskedImage()
792{
793 sal_Int32 nWidth, nHeight, nMaskWidth, nMaskHeight;
794 readInt32(nWidth);
795 readInt32(nHeight);
796 readInt32(nMaskWidth);
797 readInt32(nMaskHeight);
798
799 const uno::Sequence<beans::PropertyValue> aImage( readImageImpl() );
800 const uno::Sequence<beans::PropertyValue> aMask ( readImageImpl() );
801 m_pSink->drawAlphaMaskedImage( aImage, aMask );
802}
803
804void Parser::parseLine( const OString& rLine )
805{
806 OSL_PRECOND( m_pSink, "Invalid sink" )do { if (true && (!(m_pSink))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "806" ": "), "%s", "Invalid sink"); } } while (false)
;
807 OSL_PRECOND( m_pErr, "Invalid filehandle" )do { if (true && (!(m_pErr))) { sal_detail_logFormat(
(SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "807" ": "), "%s", "Invalid filehandle"); } } while (false
)
;
808 OSL_PRECOND( m_xContext.is(), "Invalid service factory" )do { if (true && (!(m_xContext.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "808" ": "), "%s", "Invalid service factory"); } } while
(false)
;
809
810 m_nNextToken = 0; m_nCharIndex = 0; m_aLine = rLine;
811 const OString& rCmd = readNextToken();
812 const hash_entry* pEntry = PdfKeywordHash::in_word_set( rCmd.getStr(),
813 rCmd.getLength() );
814 OSL_ASSERT(pEntry)do { if (true && (!(pEntry))) { sal_detail_logFormat(
(SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "814" ": "), "OSL_ASSERT: %s", "pEntry"); } } while (false
)
;
815 switch( pEntry->eKey )
816 {
817 case CLIPPATH:
818 m_pSink->intersectClip(readPath()); break;
819 case DRAWCHAR:
820 readChar(); break;
821 case DRAWIMAGE:
822 readImage(); break;
823 case DRAWLINK:
824 readLink(); break;
825 case DRAWMASK:
826 readMask(); break;
827 case DRAWMASKEDIMAGE:
828 readMaskedImage(); break;
829 case DRAWSOFTMASKEDIMAGE:
830 readSoftMaskedImage(); break;
831 case ENDPAGE:
832 m_pSink->endPage(); break;
833 case ENDTEXTOBJECT:
834 m_pSink->endText(); break;
835 case EOCLIPPATH:
836 m_pSink->intersectEoClip(readPath()); break;
837 case EOFILLPATH:
838 m_pSink->eoFillPath(readPath()); break;
839 case FILLPATH:
840 m_pSink->fillPath(readPath()); break;
841 case RESTORESTATE:
842 m_pSink->popState(); break;
843 case SAVESTATE:
844 m_pSink->pushState(); break;
845 case SETPAGENUM:
846 m_pSink->setPageNum( readInt32() ); break;
847 case STARTPAGE:
848 {
849 const double nWidth ( readDouble() );
850 const double nHeight( readDouble() );
851 m_pSink->startPage( geometry::RealSize2D( nWidth, nHeight ) );
852 break;
853 }
854 case STROKEPATH:
855 m_pSink->strokePath(readPath()); break;
856 case UPDATECTM:
857 readTransformation(); break;
858 case UPDATEFILLCOLOR:
859 m_pSink->setFillColor( readColor() ); break;
860 case UPDATEFLATNESS:
861 m_pSink->setFlatness( readDouble( ) ); break;
862 case UPDATEFONT:
863 readFont(); break;
864 case UPDATELINECAP:
865 readLineCap(); break;
866 case UPDATELINEDASH:
867 readLineDash(); break;
868 case UPDATELINEJOIN:
869 readLineJoin(); break;
870 case UPDATELINEWIDTH:
871 m_pSink->setLineWidth( readDouble() );break;
872 case UPDATEMITERLIMIT:
873 m_pSink->setMiterLimit( readDouble() ); break;
874 case UPDATESTROKECOLOR:
875 m_pSink->setStrokeColor( readColor() ); break;
876 case UPDATESTROKEOPACITY:
877 break;
878 case SETTEXTRENDERMODE:
879 m_pSink->setTextRenderMode( readInt32() ); break;
880
881 case NONE:
882 default:
883 OSL_PRECOND(false,"Unknown input")do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "883" ": "), "%s", "Unknown input"); } } while (false)
;
884 break;
885 }
886
887 // all consumed?
888 SAL_WARN_IF(m_nCharIndex!=-1, "sdext.pdfimport", "leftover scanner input")do { if (true && (m_nCharIndex!=-1)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "leftover scanner input"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "888" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "leftover scanner input"), 0); } else {
::std::ostringstream sal_detail_stream; sal_detail_stream <<
"leftover scanner input"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "888" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "leftover scanner input") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "888" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "leftover scanner input"), 0); } else {
::std::ostringstream sal_detail_stream; sal_detail_stream <<
"leftover scanner input"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "888" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
889}
890
891} // namespace
892
893static bool checkEncryption( const OUString& i_rPath,
894 const uno::Reference< task::XInteractionHandler >& i_xIHdl,
895 OUString& io_rPwd,
896 bool& o_rIsEncrypted,
897 const OUString& i_rDocName
898 )
899{
900 bool bSuccess = false;
901 OString aPDFFile = OUStringToOString( i_rPath, osl_getThreadTextEncoding() );
902
903 std::unique_ptr<pdfparse::PDFEntry> pEntry( pdfparse::PDFReader::read( aPDFFile.getStr() ));
904 if( pEntry )
905 {
906 pdfparse::PDFFile* pPDFFile = dynamic_cast<pdfparse::PDFFile*>(pEntry.get());
907 if( pPDFFile )
908 {
909 o_rIsEncrypted = pPDFFile->isEncrypted();
910 if( o_rIsEncrypted )
911 {
912 if( pPDFFile->usesSupportedEncryptionFormat() )
913 {
914 bool bAuthenticated = false;
915 if( !io_rPwd.isEmpty() )
916 {
917 OString aIsoPwd = OUStringToOString( io_rPwd,
918 RTL_TEXTENCODING_ISO_8859_1(((rtl_TextEncoding) 12)) );
919 bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd.getStr() );
920 }
921 if( bAuthenticated )
922 bSuccess = true;
923 else
924 {
925 if( i_xIHdl.is() )
926 {
927 bool bEntered = false;
928 do
929 {
930 bEntered = getPassword( i_xIHdl, io_rPwd, ! bEntered, i_rDocName );
931 OString aIsoPwd = OUStringToOString( io_rPwd,
932 RTL_TEXTENCODING_ISO_8859_1(((rtl_TextEncoding) 12)) );
933 bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd.getStr() );
934 } while( bEntered && ! bAuthenticated );
935 }
936
937 bSuccess = bAuthenticated;
938 }
939 }
940 else if( i_xIHdl.is() )
941 {
942 reportUnsupportedEncryptionFormat( i_xIHdl );
943 //TODO: this should either be handled further down the
944 // call stack, or else information that this has already
945 // been handled should be passed down the call stack, so
946 // that SfxBaseModel::load does not show an additional
947 // "General Error" message box
948 }
949 }
950 else
951 bSuccess = true;
952 }
953 }
954 return bSuccess;
955}
956
957namespace {
958
959class Buffering
960{
961 static const int SIZE = 64*1024;
962 std::unique_ptr<char[]> aBuffer;
963 oslFileHandle& pOut;
964 size_t pos;
965 sal_uInt64 left;
966
967public:
968 explicit Buffering(oslFileHandle& out) : aBuffer(new char[SIZE]), pOut(out), pos(0), left(0) {}
969
970 oslFileError read(char *pChar, short count, sal_uInt64* pBytesRead)
971 {
972 oslFileError nRes = osl_File_E_None;
973 sal_uInt64 nBytesRead = 0;
974 while (count > 0)
975 {
976 if (left == 0)
977 {
978 nRes = osl_readFile(pOut, aBuffer.get(), SIZE, &left);
979 if (nRes != osl_File_E_None || left == 0)
980 {
981 *pBytesRead = nBytesRead;
982 return nRes;
983 }
984 pos = 0;
985 }
986 *pChar = aBuffer.get()[pos];
987 --count;
988 ++pos;
989 --left;
990 ++pChar;
991 ++nBytesRead;
992 }
993 *pBytesRead = nBytesRead;
994 return osl_File_E_None;
995 }
996};
997
998}
999
1000bool xpdf_ImportFromFile(const OUString& rURL,
1001 const ContentSinkSharedPtr& rSink,
1002 const uno::Reference<task::XInteractionHandler>& xIHdl,
1003 const OUString& rPwd,
1004 const uno::Reference<uno::XComponentContext>& xContext,
1005 const OUString& rFilterOptions)
1006{
1007 OSL_ASSERT(rSink)do { if (true && (!(rSink))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1007" ": "), "OSL_ASSERT: %s", "rSink"); } } while (false
)
;
1
Taking false branch
2
Loop condition is false. Exiting loop
1008
1009 OUString aSysUPath;
1010 if( osl_getSystemPathFromFileURL( rURL.pData, &aSysUPath.pData ) != osl_File_E_None )
3
Assuming the condition is false
4
Taking false branch
1011 {
1012 SAL_WARN(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getSystemPathFromFileURL("
<< rURL << ") failed") == 1) { ::sal_detail_log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
rURL << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< rURL << ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getSystemPathFromFileURL(" << rURL <<
") failed") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
rURL << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< rURL << ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1013 "sdext.pdfimport",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getSystemPathFromFileURL("
<< rURL << ") failed") == 1) { ::sal_detail_log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
rURL << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< rURL << ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getSystemPathFromFileURL(" << rURL <<
") failed") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
rURL << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< rURL << ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1014 "getSystemPathFromFileURL(" << rURL << ") failed")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getSystemPathFromFileURL("
<< rURL << ") failed") == 1) { ::sal_detail_log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
rURL << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< rURL << ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getSystemPathFromFileURL(" << rURL <<
") failed") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
rURL << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< rURL << ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1014" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1015 return false;
1016 }
1017 OUString aDocName( rURL.copy( rURL.lastIndexOf( '/' )+1 ) );
1018
1019 // check for encryption, if necessary get password
1020 OUString aPwd( rPwd );
1021 bool bIsEncrypted = false;
1022 if( !checkEncryption( aSysUPath, xIHdl, aPwd, bIsEncrypted, aDocName ) )
5
Taking false branch
1023 {
1024 SAL_INFO(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "checkEncryption(" <<
aSysUPath << ") failed") == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_INFO), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "checkEncryption(" << aSysUPath
<< ") failed"), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "checkEncryption(" << aSysUPath
<< ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "checkEncryption(" << aSysUPath << ") failed"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "checkEncryption(" << aSysUPath
<< ") failed"), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "checkEncryption(" << aSysUPath
<< ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1025 "sdext.pdfimport",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "checkEncryption(" <<
aSysUPath << ") failed") == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_INFO), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "checkEncryption(" << aSysUPath
<< ") failed"), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "checkEncryption(" << aSysUPath
<< ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "checkEncryption(" << aSysUPath << ") failed"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "checkEncryption(" << aSysUPath
<< ") failed"), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "checkEncryption(" << aSysUPath
<< ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1026 "checkEncryption(" << aSysUPath << ") failed")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "checkEncryption(" <<
aSysUPath << ") failed") == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_INFO), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "checkEncryption(" << aSysUPath
<< ") failed"), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "checkEncryption(" << aSysUPath
<< ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "checkEncryption(" << aSysUPath << ") failed"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "checkEncryption(" << aSysUPath
<< ") failed"), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "checkEncryption(" << aSysUPath
<< ") failed"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1026" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1027 return false;
1028 }
1029
1030 // Determine xpdfimport executable URL:
1031 OUString converterURL("$BRAND_BASE_DIR/" LIBO_BIN_FOLDER"program" "/xpdfimport");
1032 rtl::Bootstrap::expandMacros(converterURL); //TODO: detect failure
1033
1034 // Determine pathname of xpdfimport_err.pdf:
1035 OUString errPathname("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER"share" "/xpdfimport/xpdfimport_err.pdf");
1036 rtl::Bootstrap::expandMacros(errPathname); //TODO: detect failure
1037 if (osl::FileBase::getSystemPathFromFileURL(errPathname, errPathname)
6
Assuming the condition is false
7
Taking false branch
1038 != osl::FileBase::E_None)
1039 {
1040 SAL_WARN(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getSystemPathFromFileURL("
<< errPathname << ") failed") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
errPathname << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< errPathname << ") failed"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getSystemPathFromFileURL(" << errPathname <<
") failed") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
errPathname << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< errPathname << ") failed"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1041 "sdext.pdfimport",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getSystemPathFromFileURL("
<< errPathname << ") failed") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
errPathname << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< errPathname << ") failed"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getSystemPathFromFileURL(" << errPathname <<
") failed") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
errPathname << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< errPathname << ") failed"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1042 "getSystemPathFromFileURL(" << errPathname << ") failed")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getSystemPathFromFileURL("
<< errPathname << ") failed") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
errPathname << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< errPathname << ") failed"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getSystemPathFromFileURL(" << errPathname <<
") failed") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getSystemPathFromFileURL(" <<
errPathname << ") failed"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "getSystemPathFromFileURL("
<< errPathname << ") failed"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1042" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1043 return false;
1044 }
1045
1046 // spawn separate process to keep LGPL/GPL code apart.
1047
1048 OUString aOptFlag("-o");
1049 rtl_uString* args[] = { aSysUPath.pData, errPathname.pData,
1050 aOptFlag.pData, rFilterOptions.pData };
1051 sal_Int32 nArgs = rFilterOptions.isEmpty() ? 2 : 4;
8
'?' condition is false
1052
1053 oslProcess aProcess;
1054 oslFileHandle pIn = nullptr;
1055 oslFileHandle pOut = nullptr;
1056 oslFileHandle pErr = nullptr;
1057 oslSecurity pSecurity = osl_getCurrentSecurity ();
1058 oslProcessError eErr =
1059 osl_executeProcess_WithRedirectedIO(converterURL.pData,
1060 args,
1061 nArgs,
1062 osl_Process_SEARCHPATH0x0002|osl_Process_HIDDEN0x0010,
1063 pSecurity,
1064 nullptr, nullptr, 0,
1065 &aProcess, &pIn, &pOut, &pErr);
1066 osl_freeSecurityHandle(pSecurity);
1067
1068 bool bRet=true;
1069 try
1070 {
1071 if( eErr!=osl_Process_E_None )
9
Assuming 'eErr' is equal to osl_Process_E_None
10
Taking false branch
1072 {
1073 SAL_WARN(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "executeProcess of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "executeProcess of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1074 "sdext.pdfimport",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "executeProcess of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "executeProcess of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1075 "executeProcess of " << converterURL << " failed with "do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "executeProcess of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "executeProcess of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1076 << +eErr)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "executeProcess of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "executeProcess of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "executeProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"executeProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1076" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1077 return false;
1078 }
1079
1080 if( pIn )
11
Assuming 'pIn' is null
12
Taking false branch
1081 {
1082 OStringBuffer aBuf(256);
1083 if( bIsEncrypted )
1084 aBuf.append( OUStringToOString( aPwd, RTL_TEXTENCODING_ISO_8859_1(((rtl_TextEncoding) 12)) ) );
1085 aBuf.append( '\n' );
1086
1087 sal_uInt64 nWritten = 0;
1088 osl_writeFile( pIn, aBuf.getStr(), sal_uInt64(aBuf.getLength()), &nWritten );
1089 }
1090
1091 if( pOut && pErr )
13
Assuming 'pOut' is non-null
14
Assuming 'pErr' is non-null
15
Taking true branch
1092 {
1093 // read results of PDF parser. One line - one call to
1094 // OutputDev. stderr is used for alternate streams, like
1095 // embedded fonts and bitmaps
1096 Parser aParser(rSink,pErr,xContext);
1097 Buffering aBuffering(pOut);
1098 OStringBuffer line;
1099 for( ;; )
16
Loop condition is true. Entering loop body
1100 {
1101 char aChar('\n');
1102 sal_uInt64 nBytesRead;
1103 oslFileError nRes;
1104
1105 // skip garbage \r \n at start of line
1106 for (;;)
17
Loop condition is true. Entering loop body
1107 {
1108 nRes = aBuffering.read(&aChar, 1, &nBytesRead);
1109 if (osl_File_E_None != nRes
17.1
'nRes' is equal to osl_File_E_None
17.1
'nRes' is equal to osl_File_E_None
17.1
'nRes' is equal to osl_File_E_None
17.1
'nRes' is equal to osl_File_E_None
|| nBytesRead
17.2
'nBytesRead' is not equal to 1
17.2
'nBytesRead' is not equal to 1
17.2
'nBytesRead' is not equal to 1
17.2
'nBytesRead' is not equal to 1
!= 1 || (aChar != '\n' && aChar != '\r') )
1110 break;
18
Execution continues on line 1112
1111 }
1112 if ( osl_File_E_None != nRes
18.1
'nRes' is equal to osl_File_E_None
18.1
'nRes' is equal to osl_File_E_None
18.1
'nRes' is equal to osl_File_E_None
18.1
'nRes' is equal to osl_File_E_None
)
19
Taking false branch
1113 break;
1114
1115 if( aChar != '\n' && aChar != '\r' )
1116 line.append( aChar );
1117
1118 for (;;)
20
Loop condition is true. Entering loop body
1119 {
1120 nRes = aBuffering.read(&aChar, 1, &nBytesRead);
1121 if ( osl_File_E_None != nRes
20.1
'nRes' is equal to osl_File_E_None
20.1
'nRes' is equal to osl_File_E_None
20.1
'nRes' is equal to osl_File_E_None
20.1
'nRes' is equal to osl_File_E_None
|| nBytesRead
20.2
'nBytesRead' is not equal to 1
20.2
'nBytesRead' is not equal to 1
20.2
'nBytesRead' is not equal to 1
20.2
'nBytesRead' is not equal to 1
!= 1 || aChar == '\n' || aChar == '\r' )
1122 break;
21
Execution continues on line 1125
1123 line.append( aChar );
1124 }
1125 if ( osl_File_E_None != nRes
21.1
'nRes' is equal to osl_File_E_None
21.1
'nRes' is equal to osl_File_E_None
21.1
'nRes' is equal to osl_File_E_None
21.1
'nRes' is equal to osl_File_E_None
)
22
Taking false branch
1126 break;
1127 if ( line.isEmpty() )
23
Taking true branch
1128 break;
24
Execution continues on line 313
1129
1130 aParser.parseLine(line.makeStringAndClear());
1131 }
1132 }
25
Calling implicit destructor for 'Parser'
26
Calling '~ScopedVclPtr'
1133 }
1134 catch( uno::Exception& )
1135 {
1136 // crappy C file interface. need manual resource dealloc
1137 bRet = false;
1138 }
1139
1140 if( pIn )
1141 osl_closeFile(pIn);
1142 if( pOut )
1143 osl_closeFile(pOut);
1144 if( pErr )
1145 osl_closeFile(pErr);
1146 eErr = osl_joinProcess(aProcess);
1147 if (eErr == osl_Process_E_None)
1148 {
1149 oslProcessInfo info;
1150 info.Size = sizeof info;
1151 eErr = osl_getProcessInfo(aProcess, osl_Process_EXITCODE0x0002, &info);
1152 if (eErr == osl_Process_E_None)
1153 {
1154 if (info.Code != 0)
1155 {
1156 SAL_WARN(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with exit code " << info
.Code) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1157 "sdext.pdfimport",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with exit code " << info
.Code) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1158 "getProcessInfo of " << converterURLdo { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with exit code " << info
.Code) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1159 << " failed with exit code " << info.Code)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with exit code " << info
.Code) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with exit code " << info.Code), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "getProcessInfo of " << converterURL <<
" failed with exit code " << info.Code; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1159" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1160 bRet = false;
1161 }
1162 }
1163 else
1164 {
1165 SAL_WARN(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1166 "sdext.pdfimport",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1167 "getProcessInfo of " << converterURL << " failed with "do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1168 << +eErr)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "getProcessInfo of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "getProcessInfo of " << converterURL <<
" failed with " << +eErr) == 1) { ::sal_detail_log( (::
SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "getProcessInfo of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"getProcessInfo of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1168" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1169 bRet = false;
1170 }
1171 }
1172 else
1173 {
1174 SAL_WARN(do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "joinProcess of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "joinProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"joinProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "joinProcess of " << converterURL << " failed with "
<< +eErr) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "joinProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"joinProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1175 "sdext.pdfimport",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "joinProcess of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "joinProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"joinProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "joinProcess of " << converterURL << " failed with "
<< +eErr) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "joinProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"joinProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
1176 "joinProcess of " << converterURL << " failed with " << +eErr)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sdext.pdfimport")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "joinProcess of " <<
converterURL << " failed with " << +eErr) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sdext.pdfimport"
), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "joinProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"joinProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "joinProcess of " << converterURL << " failed with "
<< +eErr) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "joinProcess of " << converterURL
<< " failed with " << +eErr), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"joinProcess of " << converterURL << " failed with "
<< +eErr; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sdext.pdfimport"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1176" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1177 bRet = false;
1178 }
1179 osl_freeProcessHandle(aProcess);
1180 return bRet;
1181}
1182
1183
1184bool xpdf_ImportFromStream( const uno::Reference< io::XInputStream >& xInput,
1185 const ContentSinkSharedPtr& rSink,
1186 const uno::Reference<task::XInteractionHandler >& xIHdl,
1187 const OUString& rPwd,
1188 const uno::Reference< uno::XComponentContext >& xContext,
1189 const OUString& rFilterOptions )
1190{
1191 OSL_ASSERT(xInput.is())do { if (true && (!(xInput.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1191" ": "), "OSL_ASSERT: %s", "xInput.is()"); } } while
(false)
;
1192 OSL_ASSERT(rSink)do { if (true && (!(rSink))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/pdfimport/wrapper/wrapper.cxx"
":" "1192" ": "), "OSL_ASSERT: %s", "rSink"); } } while (false
)
;
1193
1194 // convert XInputStream to local temp file
1195 oslFileHandle aFile = nullptr;
1196 OUString aURL;
1197 if( osl_createTempFile( nullptr, &aFile, &aURL.pData ) != osl_File_E_None )
1198 return false;
1199
1200 // copy content, buffered...
1201 const sal_uInt32 nBufSize = 4096;
1202 uno::Sequence<sal_Int8> aBuf( nBufSize );
1203 sal_uInt64 nBytes = 0;
1204 sal_uInt64 nWritten = 0;
1205 bool bSuccess = true;
1206 do
1207 {
1208 try
1209 {
1210 nBytes = xInput->readBytes( aBuf, nBufSize );
1211 }
1212 catch( css::uno::Exception& )
1213 {
1214 osl_closeFile( aFile );
1215 throw;
1216 }
1217 if( nBytes > 0 )
1218 {
1219 osl_writeFile( aFile, aBuf.getConstArray(), nBytes, &nWritten );
1220 if( nWritten != nBytes )
1221 {
1222 bSuccess = false;
1223 break;
1224 }
1225 }
1226 }
1227 while( nBytes == nBufSize );
1228
1229 osl_closeFile( aFile );
1230
1231 if ( bSuccess )
1232 bSuccess = xpdf_ImportFromFile( aURL, rSink, xIHdl, rPwd, xContext, rFilterOptions );
1233 osl_removeFile( aURL.pData );
1234
1235 return bSuccess;
1236}
1237
1238}
1239
1240/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
28
Calling copy constructor for 'Reference<VirtualDevice>'
31
Returning from copy constructor for 'Reference<VirtualDevice>'
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
32
Calling 'Reference::clear'
39
Returning; memory was released
205 if (aTmp.get()) {
40
Calling 'Reference::get'
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
27
Calling 'VclPtr::disposeAndClear'
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
29
Assuming field 'm_pBody' is non-null
30
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody
32.1
Field 'm_pBody' is non-null
32.1
Field 'm_pBody' is non-null
32.1
Field 'm_pBody' is non-null
32.1
Field 'm_pBody' is non-null
)
33
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
34
Calling 'VclReferenceBase::release'
38
Returning; memory was released
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
41
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
35
Assuming the condition is true
36
Taking true branch
40 delete this;
37
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif