LibreOffice Module shell (master) 1
ooofilt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21// File: ooofilt.cxx
22// Contents: Filter Implementation for OpenOffice.Org Document using
23// Indexing Service
24// Summary: The LibreOffice filter reads OpenOffice.org XML files (with
25// the extension .sxw .sxi, etc) and ODF files and extract
26// their content, author, keywords,subject,comments and title
27// to be filtered.
28
29// Platform: Windows 2000, Windows XP
30
31#include <contentreader.hxx>
32#include <metainforeader.hxx>
33#include <registry.hxx>
34#include <fileextensions.hxx>
35
36
37// Include file Purpose
38// windows.h Win32 declarations
39// string.h string wstring declarations
40// filter.h IFilter interface declarations
41// filterr.h FACILITY_ITF error definitions for IFilter
42// ntquery.h Indexing Service declarations
43// assert.h assertion function.
44// ooofilt.hxx LibreOffice filter declarations
45// propspec.hxx PROPSPEC
46
47
48#if !defined WIN32_LEAN_AND_MEAN
49# define WIN32_LEAN_AND_MEAN
50#endif
51#include <windows.h>
52
53#include <string.h>
54#include <filter.h>
55#include <filterr.h>
56#include <ntquery.h>
57#include <assert.h>
58#include "ooofilt.hxx"
59#include <objidl.h>
60#include <stdio.h>
61#include "propspec.hxx"
62
63#include <stream_helper.hxx>
64
65#include <olectl.h> // declarations of DllRegisterServer/DllUnregisterServer
66
67//C-------------------------------------------------------------------------
68// Class: COooFilter
69// Summary: Implements LibreOffice filter class
70
71//M-------------------------------------------------------------------------
72// Method: COooFilter::COooFilter
73// Summary: Class constructor
74// Arguments: void
75// Purpose: Manages global instance count
76
78 m_lRefs(1),
79 m_pContentReader(nullptr),
80 m_pMetaInfoReader(nullptr),
82 m_ulUnicodeBufferLen(0),
83 m_ulUnicodeCharsRead(0),
84 m_ulPropertyNum(0),
85 m_ulCurrentPropertyNum(0),
86 m_ulChunkID(1),
87 m_fContents(false),
88 m_fEof(false),
89 m_ChunkPosition(0),
90 m_cAttributes(0),
91 m_pAttributes(nullptr),
92 m_pStream(nullptr)
93
94{
95 InterlockedIncrement( &g_lInstances );
96}
97//M-------------------------------------------------------------------------
98// Method: COooFilter::~COooFilter
99// Summary: Class destructor
100// Arguments: void
101// Purpose: Manages global instance count and file handle
102
104{
105 delete [] m_pAttributes;
106 delete m_pContentReader;
107 delete m_pMetaInfoReader;
108 delete m_pStream;
109
110 InterlockedDecrement( &g_lInstances );
111}
112
113//M-------------------------------------------------------------------------
114// Method: COooFilter::QueryInterface (IUnknown::QueryInterface)
115// Summary: Queries for requested interface // Arguments: riid
116// [in] Reference IID of requested interface
117// ppvObject
118// [out] Address that receives requested interface pointer
119// Returns: S_OK
120// Interface is supported
121// E_NOINTERFACE
122// Interface is not supported
123
124HRESULT STDMETHODCALLTYPE COooFilter::QueryInterface(
125 REFIID riid,
126 void ** ppvObject)
127{
128 IUnknown *pUnkTemp = nullptr;
129 if ( IID_IFilter == riid )
130 pUnkTemp = static_cast<IFilter *>(this);
131 else if ( IID_IPersistFile == riid )
132 pUnkTemp = static_cast<IPersistFile *>(this);
133 else if ( IID_IPersist == riid )
134 pUnkTemp = static_cast<IPersistFile *>(this);
135 else if (IID_IPersistStream == riid)
136 pUnkTemp = static_cast<IPersistStream *>(this);
137 else if ( IID_IUnknown == riid )
138 pUnkTemp = static_cast<IPersistFile *>(this);
139 else
140 {
141 *ppvObject = nullptr;
142 return E_NOINTERFACE;
143 }
144 *ppvObject = pUnkTemp;
145 pUnkTemp->AddRef();
146 return S_OK;
147}
148//M-------------------------------------------------------------------------
149// Method: COooFilter::AddRef (IUnknown::AddRef)
150// Summary: Increments interface refcount
151// Arguments: void
152// Returns: Value of incremented interface refcount
153
154ULONG STDMETHODCALLTYPE COooFilter::AddRef()
155{
156 return InterlockedIncrement( &m_lRefs );
157}
158//M-------------------------------------------------------------------------
159// Method: COooFilter::Release (IUnknown::Release)
160// Summary: Decrements interface refcount, deleting if unreferenced
161// Arguments: void
162// Returns: Value of decremented interface refcount
163
164ULONG STDMETHODCALLTYPE COooFilter::Release()
165{
166 ULONG ulTmp = InterlockedDecrement( &m_lRefs );
167
168 if ( 0 == ulTmp )
169 delete this;
170 return ulTmp;
171}
172//M-------------------------------------------------------------------------
173// Method: COooFilter::Init (IFilter::Init)
174// Summary: Initializes LibreOffice filter instance
175// Arguments: grfFlags
176// [in] Flags for filter behavior
177// cAttributes
178// [in] Number attributes in array aAttributes
179// aAttributes
180// [in] Array of requested attribute strings
181// pFlags
182// [out] Pointer to return flags for additional properties
183// Returns: S_OK
184// Initialization succeeded
185// E_FAIL
186// File not previously loaded
187// E_INVALIDARG
188// Count and contents of attributes do not agree
189// FILTER_E_ACCESS
190// Unable to access file to be filtered
191// FILTER_E_PASSWORD
192// (not implemented)
193
194const int COUNT_ATTRIBUTES = 5;
195
196SCODE STDMETHODCALLTYPE COooFilter::Init(
197 ULONG grfFlags,
198 ULONG cAttributes,
199 FULLPROPSPEC const * aAttributes,
200 ULONG * pFlags)
201{
202 // Enumerate OLE properties, since any NTFS file can have them
203 *pFlags = IFILTER_FLAGS_OLE_PROPERTIES;
204 try
205 {
206 m_fContents = false;
207 m_ulPropertyNum = 0;
209 if ( m_cAttributes > 0 )
210 {
211 delete[] m_pAttributes;
212 m_pAttributes = nullptr;
213 m_cAttributes = 0;
214 }
215 if( 0 < cAttributes )
216 {
217 // Filter properties specified in aAttributes
218 if ( nullptr == aAttributes )
219 return E_INVALIDARG;
220 m_pAttributes = new CFullPropSpec[cAttributes];
221 m_cAttributes = cAttributes;
222 // Is caller want to filter contents?
223 CFullPropSpec const *pAttrib = reinterpret_cast<CFullPropSpec const *>(aAttributes);
224 ULONG ulNumAttr;
225 for ( ulNumAttr = 0 ; ulNumAttr < cAttributes; ulNumAttr++ )
226 {
227 if ( pAttrib[ulNumAttr].IsPropertyPropid() &&
228 pAttrib[ulNumAttr].GetPropertyPropid() == PID_STG_CONTENTS &&
229 pAttrib[ulNumAttr].GetPropSet() == guidStorage )
230 {
231 m_fContents = true;
232 }
233 // save the requested properties.
234 m_pAttributes[ulNumAttr] = pAttrib[ulNumAttr];
235 }
236 }
237 else if ( grfFlags & IFILTER_INIT_APPLY_INDEX_ATTRIBUTES )
238 {
239 // Filter contents and all pseudo-properties
240 m_fContents = true;
241
244 m_pAttributes[0].SetPropSet( FMTID_SummaryInformation );
245 m_pAttributes[0].SetProperty( PIDSI_AUTHOR );
246 m_pAttributes[1].SetPropSet( FMTID_SummaryInformation );
247 m_pAttributes[1].SetProperty( PIDSI_TITLE );
248 m_pAttributes[2].SetPropSet( FMTID_SummaryInformation );
249 m_pAttributes[2].SetProperty( PIDSI_SUBJECT );
250 m_pAttributes[3].SetPropSet( FMTID_SummaryInformation );
251 m_pAttributes[3].SetProperty( PIDSI_KEYWORDS );
252 m_pAttributes[4].SetPropSet( FMTID_SummaryInformation );
253 m_pAttributes[4].SetProperty( PIDSI_COMMENTS );
254 }
255 else if ( 0 == grfFlags )
256 {
257 // Filter only contents
258 m_fContents = true;
259 }
260 else
261 m_fContents = false;
262 // Re-initialize
263 if ( m_fContents )
264 {
265 m_fEof = false;
268 m_ChunkPosition = 0;
269 }
270 else
271 {
272 m_fEof = true;
274 }
275 m_ulChunkID = 1;
276 }
277 catch (const std::exception&)
278 {
279 return E_FAIL;
280 }
281
282 return S_OK;
283}
284//M-------------------------------------------------------------------------
285// Method: COooFilter::GetChunk (IFilter::GetChunk)
286// Summary: Gets the next chunk
287// Arguments: ppStat
288// [out] Pointer to description of current chunk
289// Returns: S_OK
290// Chunk was successfully retrieved
291// E_FAIL
292// Character conversion failed
293// FILTER_E_ACCESS
294// General access failure occurred
295// FILTER_E_END_OF_CHUNKS
296// Previous chunk was the last chunk
297// FILTER_E_EMBEDDING_UNAVAILABLE
298// (not implemented)
299// FILTER_E_LINK_UNAVAILABLE
300// (not implemented)
301// FILTER_E_PASSWORD
302// (not implemented)
303
304SCODE STDMETHODCALLTYPE COooFilter::GetChunk(STAT_CHUNK * pStat)
305{
306 for(;;)
307 {
308 switch ( m_eState )
309 {
311 {
312 if( m_ChunkPosition == m_pContentReader ->getChunkBuffer().size() )
313 {
315 m_fEof = true;
316 }
317
318 if ( !m_fContents || m_fEof )
319 {
321 continue;
322 }
323 m_pwsBuffer = m_pContentReader -> getChunkBuffer()[m_ChunkPosition].second;
324 m_ulUnicodeBufferLen = static_cast<ULONG>(m_pwsBuffer.length());
325 DWORD ChunkLCID = LocaleSetToLCID( m_pContentReader -> getChunkBuffer()[m_ChunkPosition].first );
326 // Set chunk description
327 pStat->idChunk = m_ulChunkID;
328 pStat->breakType = CHUNK_NO_BREAK;
329 pStat->flags = CHUNK_TEXT;
330 pStat->locale = ChunkLCID;
331 pStat->attribute.guidPropSet = guidStorage;
332 pStat->attribute.psProperty.ulKind = PRSPEC_PROPID;
333 pStat->attribute.psProperty.propid = PID_STG_CONTENTS;
334 pStat->idChunkSource = m_ulChunkID;
335 pStat->cwcStartSource = 0;
336 pStat->cwcLenSource = 0;
338 m_ulChunkID++;
340 return S_OK;
341 }
343 {
344 if ( m_cAttributes == 0 )
345 return FILTER_E_END_OF_CHUNKS;
346 while( !( ( m_pAttributes[m_ulPropertyNum].IsPropertyPropid() ) &&
347 ( m_pAttributes[m_ulPropertyNum].GetPropSet() == FMTID_SummaryInformation ) )||
348 ( ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_AUTHOR ) &&
349 ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_TITLE ) &&
350 ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_SUBJECT ) &&
351 ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_KEYWORDS ) &&
352 ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_COMMENTS ) ) )
353 {
356 else
357 break;
358 }
360 return FILTER_E_END_OF_CHUNKS;
361 else
362 {
363 // Set chunk description
364 pStat->idChunk = m_ulChunkID;
365 pStat->breakType = CHUNK_EOS;
366 pStat->flags = CHUNK_VALUE;
367 pStat->locale = GetSystemDefaultLCID();
368 pStat->attribute.guidPropSet = FMTID_SummaryInformation;
369 pStat->attribute.psProperty.ulKind = PRSPEC_PROPID;
370 pStat->attribute.psProperty.propid = m_pAttributes[m_ulPropertyNum].GetPropertyPropid();
371 pStat->idChunkSource = m_ulChunkID;
372 pStat->cwcStartSource = 0;
373 pStat->cwcLenSource = 0;
376 m_ulChunkID++;
377 return S_OK;
378 }
379 }
380 }//switch(...)
381 }//for(;;)
382}
383//M-------------------------------------------------------------------------
384// Method: COooFilter::GetText (IFilter::GetText)
385// Summary: Retrieves UNICODE text for index
386// Arguments: pcwcBuffer
387// [in] Pointer to size of UNICODE buffer
388// [out] Pointer to count of UNICODE characters returned
389// awcBuffer
390// [out] Pointer to buffer to receive UNICODE text
391// Returns: S_OK
392// Text successfully retrieved, but text remains in chunk
393// FILTER_E_NO_MORE_TEXT
394// All of the text in the current chunk has been returned
395// FILTER_S_LAST_TEXT
396// Next call to GetText will return FILTER_E_NO_MORE_TEXT
397
398SCODE STDMETHODCALLTYPE COooFilter::GetText(ULONG * pcwcBuffer, WCHAR * awcBuffer)
399{
400 switch ( m_eState )
401 {
403 return FILTER_E_NO_TEXT;
405 {
406 if ( !m_fContents || 0 == m_ulUnicodeBufferLen )
407 {
408 *pcwcBuffer = 0;
409 return FILTER_E_NO_MORE_TEXT;
410 }
411 // Copy UNICODE characters in chunk buffer to output UNICODE buffer
412 ULONG ulToCopy = min( *pcwcBuffer, m_ulUnicodeBufferLen - m_ulUnicodeCharsRead );
413 wmemcpy( awcBuffer, m_pwsBuffer.c_str() + m_ulUnicodeCharsRead, ulToCopy );
414 ZeroMemory(
415 awcBuffer + ulToCopy, (*pcwcBuffer - ulToCopy) * sizeof (WCHAR));
416 m_ulUnicodeCharsRead += ulToCopy;
417 *pcwcBuffer = ulToCopy;
419 {
422 return FILTER_S_LAST_TEXT;
423 }
424 return S_OK;
425 }
426 }
427 return E_FAIL; // Should not happen!
428}
429//M-------------------------------------------------------------------------
430// Method: GetMetaInfoNameFromPropertyId
431// Summary: helper function to convert PropertyID into respective
432// MetaInfo names.
433// Arguments: ulPropID
434// [in] property ID
435// Returns: corresponding metainfo names.
436
437
438static ::std::wstring GetMetaInfoNameFromPropertyId( ULONG ulPropID )
439{
440 switch ( ulPropID )
441 {
442 case PIDSI_AUTHOR: return META_INFO_AUTHOR;
443 case PIDSI_TITLE: return META_INFO_TITLE;
444 case PIDSI_SUBJECT: return META_INFO_SUBJECT;
445 case PIDSI_KEYWORDS: return META_INFO_KEYWORDS;
446 case PIDSI_COMMENTS: return META_INFO_DESCRIPTION;
447 default: return EMPTY_STRING;
448 }
449}
450//M-------------------------------------------------------------------------
451// Method: COooFilter::GetValue (IFilter::GetValue)
452// Summary: Retrieves properties for index
453// Arguments: ppPropValue
454// [out] Address that receives pointer to property value
455// Returns: FILTER_E_NO_VALUES
456// Always
457// FILTER_E_NO_MORE_VALUES
458// (not implemented)
459
460
461SCODE STDMETHODCALLTYPE COooFilter::GetValue(PROPVARIANT ** ppPropValue)
462{
464 return FILTER_E_NO_VALUES;
465 else // m_eState == FilteringProperty
466 {
468 return FILTER_E_NO_MORE_VALUES;
469 PROPVARIANT *pPropVar = static_cast<PROPVARIANT *>(CoTaskMemAlloc( sizeof (PROPVARIANT) ));
470 if ( pPropVar == nullptr )
471 return E_OUTOFMEMORY;
472 ::std::wstring wsTagName= GetMetaInfoNameFromPropertyId( m_pAttributes[m_ulCurrentPropertyNum].GetPropertyPropid() );
473 if ( wsTagName == EMPTY_STRING )
474 return FILTER_E_NO_VALUES;
475 ::std::wstring wsTagData = m_pMetaInfoReader->getTagData(wsTagName);
476 pPropVar->vt = VT_LPWSTR;
477 size_t cw = wsTagData.length() + 1; // reserve one for the '\0'
478 pPropVar->pwszVal = static_cast<WCHAR*>( CoTaskMemAlloc(cw*sizeof(WCHAR)) );
479 if (pPropVar->pwszVal == nullptr)
480 {
481 CoTaskMemFree(pPropVar);
482 return E_OUTOFMEMORY;
483 }
484 wmemcpy(pPropVar->pwszVal, wsTagData.c_str(), cw);
485 *ppPropValue = pPropVar;
487 return S_OK;
488 }
489}
490//M-------------------------------------------------------------------------
491// Method: COooFilter::BindRegion (IFilter::BindRegion)
492// Summary: Creates moniker or other interface for indicated text
493// Arguments: origPos
494// [in] Description of text location and extent
495// riid
496// [in] Reference IID of specified interface
497// ppunk
498// [out] Address that receives requested interface pointer
499// Returns: E_NOTIMPL
500// Always
501// FILTER_W_REGION_CLIPPED
502// (not implemented)
503
504
505SCODE STDMETHODCALLTYPE COooFilter::BindRegion(
506 FILTERREGION /*origPos*/,
507 REFIID /*riid*/,
508 void ** /*ppunk*/)
509{
510 // BindRegion is currently reserved for future use
511 return E_NOTIMPL;
512}
513//M-------------------------------------------------------------------------
514// Method: COooFilter::GetClassID (IPersist::GetClassID)
515// Summary: Retrieves the class id of the filter class
516// Arguments: pClassID
517// [out] Pointer to the class ID of the filter
518// Returns: S_OK
519// Always
520// E_FAIL
521// (not implemented)
522
523HRESULT STDMETHODCALLTYPE COooFilter::GetClassID(CLSID * pClassID)
524{
525 *pClassID = CLSID_COooFilter;
526 return S_OK;
527}
528//M-------------------------------------------------------------------------
529// Method: COooFilter::IsDirty (IPersistFile::IsDirty)
530// Summary: Checks whether file has changed since last save
531// Arguments: void
532// Returns: S_FALSE
533// Always
534// S_OK
535// (not implemented)
536
537HRESULT STDMETHODCALLTYPE COooFilter::IsDirty()
538{
539 // File is opened read-only and never changes
540 return S_FALSE;
541}
542//M-------------------------------------------------------------------------
543// Method: COooFilter::Load (IPersistFile::Load)
544// Summary: Opens and initializes the specified file
545// Arguments: pszFileName
546// [in] Pointer to zero-terminated string
547// of absolute path of file to open
548// dwMode
549// [in] Access mode to open the file
550// Returns: S_OK
551// File was successfully loaded
552// E_OUTOFMEMORY
553// File could not be loaded due to insufficient memory
554// E_FAIL
555// (not implemented)
556
557HRESULT STDMETHODCALLTYPE COooFilter::Load(LPCOLESTR pszFileName, DWORD /*dwMode*/)
558{
559 // Load just sets the filename for GetChunk to read and ignores the mode
560 m_pwszFileName = getShortPathName( pszFileName );
561
562 // Open the file previously specified in call to IPersistFile::Load and get content.
563 try
564 {
565 delete m_pMetaInfoReader;
567
568 delete m_pContentReader;
570 }
571 catch (const std::exception&)
572 {
573 return E_FAIL;
574 }
575 return S_OK;
576}
577//M-------------------------------------------------------------------------
578// Method: COooFilter::Save (IPersistFile::Save)
579// Summary: Saves a copy of the current file being filtered
580// Arguments: pszFileName
581// [in] Pointer to zero-terminated string of
582// absolute path of where to save file
583// fRemember
584// [in] Whether the saved copy is made the current file
585// Returns: E_FAIL
586// Always
587// S_OK
588// (not implemented)
589
590HRESULT STDMETHODCALLTYPE COooFilter::Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/)
591{
592 // File is opened read-only; saving it is an error
593 return E_FAIL;
594}
595//M-------------------------------------------------------------------------
596// Method: COooFilter::SaveCompleted (IPersistFile::SaveCompleted)
597// Summary: Determines whether a file save is completed
598// Arguments: pszFileName
599// [in] Pointer to zero-terminated string of
600// absolute path where file was previously saved
601// Returns: S_OK
602// Always
603
604HRESULT STDMETHODCALLTYPE COooFilter::SaveCompleted(LPCOLESTR /*pszFileName*/)
605{
606 // File is opened read-only, so "save" is always finished
607 return S_OK;
608}
609
610//M-------------------------------------------------------------------------
611// Method: COooFilter::Load (IPersistStream::Load)
612// Summary: Initializes an object from the stream where it was previously saved
613// Arguments: pStm
614// [in] Pointer to stream from which object should be loaded
615// Returns: S_OK
616// E_OUTOFMEMORY
617// E_FAIL
618
619HRESULT STDMETHODCALLTYPE COooFilter::Load(IStream *pStm)
620{
621 m_pStream = new BufferStream(pStm);
622 try
623 {
624 delete m_pMetaInfoReader;
626
627 delete m_pContentReader;
629 }
630 catch (const std::exception&)
631 {
632 return E_FAIL;
633 }
634 return S_OK;
635}
636
637//M-------------------------------------------------------------------------
638// Method: COooFilter::GetSizeMax (IPersistStream::GetSizeMax)
639// Summary: Returns the size in bytes of the stream needed to save the object.
640// Arguments: pcbSize
641// [out] Pointer to a 64 bit unsigned int indicating the size needed
642// Returns: E_NOTIMPL
643
644HRESULT STDMETHODCALLTYPE COooFilter::GetSizeMax(ULARGE_INTEGER * /*pcbSize*/)
645{
646 return E_NOTIMPL;
647}
648
649//M-------------------------------------------------------------------------
650// Method: COooFilter::Save (IPersistStream::Save)
651// Summary: Save object to specified stream
652// Arguments: pStm
653// [in] Pointer to stream
654// fClearDirty
655// [in] Indicates whether to clear dirty flag
656// Returns: E_NOTIMPL
657
658HRESULT STDMETHODCALLTYPE COooFilter::Save(IStream * /*pStm*/, BOOL )
659{
660 return E_NOTIMPL;
661}
662
663//M-------------------------------------------------------------------------
664// Method: COooFilter::GetCurFile (IPersistFile::GetCurFile)
665// Summary: Returns a copy of the current file name
666// Arguments: ppszFileName
667// [out] Address to receive pointer to zero-terminated
668// string for absolute path to current file
669// Returns: S_OK
670// A valid absolute path was successfully returned
671// S_FALSE
672// (not implemented)
673// E_OUTOFMEMORY
674// Operation failed due to insufficient memory
675// E_FAIL
676// Operation failed due to some reason
677// other than insufficient memory
678
679HRESULT STDMETHODCALLTYPE COooFilter::GetCurFile(LPOLESTR * ppszFileName)
680{
682 return E_FAIL;
683 else
684 *ppszFileName = const_cast<LPWSTR>(m_pwszFileName.c_str());
685 return S_OK;
686}
687
688//M-------------------------------------------------------------------------
689// Method: COooFilterCF::COooFilterCF
690// Summary: Class factory constructor
691// Arguments: void
692// Purpose: Manages global instance count
693
695 m_lRefs(1)
696{
697 InterlockedIncrement( &g_lInstances );
698}
699//M-------------------------------------------------------------------------
700// Method: COooFilterCF::~COooFilterCF
701// Summary: Class factory destructor
702// Arguments: void
703// Purpose: Manages global instance count
704
706{
707 InterlockedDecrement( &g_lInstances );
708}
709//M-------------------------------------------------------------------------
710// Method: COooFilterCF::QueryInterface (IUnknown::QueryInterface)
711// Summary: Queries for requested interface
712// Arguments: riid
713// [in] Reference IID of requested interface
714// ppvObject
715// [out] Address that receives requested interface pointer
716// Returns: S_OK
717// Interface is supported
718// E_NOINTERFACE
719// Interface is not supported
720
721HRESULT STDMETHODCALLTYPE COooFilterCF::QueryInterface(REFIID riid, void ** ppvObject)
722{
723 IUnknown *pUnkTemp;
724
725 if ( IID_IClassFactory == riid )
726 pUnkTemp = this;
727 else if ( IID_IUnknown == riid )
728 pUnkTemp = this;
729 else
730 {
731 *ppvObject = nullptr;
732 return E_NOINTERFACE;
733 }
734 *ppvObject = pUnkTemp;
735 pUnkTemp->AddRef();
736 return S_OK;
737}
738//M-------------------------------------------------------------------------
739// Method: COooFilterCF::AddRef (IUnknown::AddRef)
740// Summary: Increments interface refcount
741// Arguments: void
742// Returns: Value of incremented interface refcount
743
744ULONG STDMETHODCALLTYPE COooFilterCF::AddRef()
745{
746 return InterlockedIncrement( &m_lRefs );
747}
748//M-------------------------------------------------------------------------
749// Method: COooFilterCF::Release (IUnknown::Release)
750// Summary: Decrements interface refcount, deleting if unreferenced
751// Arguments: void
752// Returns: Value of decremented refcount
753
754ULONG STDMETHODCALLTYPE COooFilterCF::Release()
755{
756 ULONG ulTmp = InterlockedDecrement( &m_lRefs );
757
758 if ( 0 == ulTmp )
759 delete this;
760 return ulTmp;
761}
762//M-------------------------------------------------------------------------
763// Method: COooFilterCF::CreateInstance (IClassFactory::CreateInstance)
764// Summary: Creates new LibreOffice filter object
765// Arguments: pUnkOuter
766// [in] Pointer to IUnknown interface of aggregating object
767// riid
768// [in] Reference IID of requested interface
769// ppvObject
770// [out] Address that receives requested interface pointer
771// Returns: S_OK
772// LibreOffice filter object was successfully created
773// CLASS_E_NOAGGREGATION
774// pUnkOuter parameter was non-NULL
775// E_NOINTERFACE
776// (not implemented)
777// E_OUTOFMEMORY
778// LibreOffice filter object could not be created
779// due to insufficient memory
780// E_UNEXPECTED
781// Unsuccessful due to an unexpected condition
782
783HRESULT STDMETHODCALLTYPE COooFilterCF::CreateInstance(
784 IUnknown * pUnkOuter,
785 REFIID riid,
786 void * * ppvObject)
787{
788 COooFilter *pIUnk = nullptr;
789 if ( nullptr != pUnkOuter )
790 return CLASS_E_NOAGGREGATION;
791 pIUnk = new COooFilter();
792 if ( SUCCEEDED( pIUnk->QueryInterface( riid , ppvObject ) ) )
793 {
794 // Release extra refcount from QueryInterface
795 pIUnk->Release();
796 }
797 else
798 {
799 delete pIUnk;
800 return E_UNEXPECTED;
801 }
802 return S_OK;
803}
804
805//M-------------------------------------------------------------------------
806// Method: COooFilterCF::LockServer (IClassFactory::LockServer)
807// Summary: Forces/allows filter class to remain loaded/be unloaded
808// Arguments: fLock
809// [in] TRUE to lock, FALSE to unlock
810// Returns: S_OK
811// Always
812// E_FAIL
813// (not implemented)
814// E_OUTOFMEMORY
815// (not implemented)
816// E_UNEXPECTED
817// (not implemented)
818
819HRESULT STDMETHODCALLTYPE COooFilterCF::LockServer(BOOL fLock)
820{
821 if( fLock )
822 InterlockedIncrement( &g_lInstances );
823 else
824 InterlockedDecrement( &g_lInstances );
825 return S_OK;
826}
827//+-------------------------------------------------------------------------
828// DLL: ooofilt.dll
829// Summary: Implements Dynamic Link Library functions for LibreOffice filter
830
831//F-------------------------------------------------------------------------
832// Function: DllMain
833// Summary: Called from C-Runtime on process/thread attach/detach
834// Arguments: hInstance
835// [in] Handle to the DLL
836// fdwReason
837// [in] Reason for calling DLL entry point
838// lpReserve
839// [in] Details of DLL initialization and cleanup
840// Returns: TRUE
841// Always
842
843extern "C" BOOL WINAPI DllMain(
844 HINSTANCE hInstance,
845 DWORD fdwReason,
846 LPVOID /*lpvReserved*/
847)
848{
849 if ( DLL_PROCESS_ATTACH == fdwReason )
850 DisableThreadLibraryCalls( hInstance );
851 return TRUE;
852}
853//F-------------------------------------------------------------------------
854// Function: DllGetClassObject
855// Summary: Create LibreOffice filter class factory object
856// Arguments: cid
857// [in] Class ID of class that class factory creates
858// iid
859// [in] Reference IID of requested class factory interface
860// ppvObj
861// [out] Address that receives requested interface pointer
862// Returns: S_OK
863// Class factory object was created successfully
864// CLASS_E_CLASSNOTAVAILABLE
865// DLL does not support the requested class
866// E_INVALIDARG
867// (not implemented
868// E_OUTOFMEMORY
869// Insufficient memory to create the class factory object
870// E_UNEXPECTED
871// Unsuccessful due to an unexpected condition
872
873extern "C" HRESULT STDMETHODCALLTYPE DllGetClassObject(
874 REFCLSID cid,
875 REFIID iid,
876 LPVOID * ppvObj
877)
878{
879 COooFilterCF* pImpl = nullptr;
880 IUnknown *pResult = nullptr;
881
882 if ( CLSID_COooFilter == cid )
883 {
884 pImpl = new COooFilterCF;
885 pResult = pImpl;
886 }
887 else
888 return CLASS_E_CLASSNOTAVAILABLE;
889 if( SUCCEEDED( pResult->QueryInterface( iid, ppvObj ) ) )
890 // Release extra refcount from QueryInterface
891 pResult->Release();
892 else
893 {
894 delete pImpl;
895 return E_UNEXPECTED;
896 }
897 return S_OK;
898}
899//F-------------------------------------------------------------------------
900// Function: DllCanUnloadNow
901// Summary: Indicates whether it is possible to unload DLL
902// Arguments: void
903// Returns: S_OK
904// DLL can be unloaded now
905// S_FALSE
906// DLL must remain loaded
907
908extern "C" HRESULT STDMETHODCALLTYPE DllCanUnloadNow()
909{
910 if ( 0 >= g_lInstances )
911 return S_OK;
912 else
913 return S_FALSE;
914}
915//F-------------------------------------------------------------------------
916// Function: DllRegisterServer
917// DllUnregisterServer
918// Summary: Registers and unregisters DLL server
919// Returns: DllRegisterServer
920// S_OK
921// Registration was successful
922// SELFREG_E_CLASS
923// Registration was unsuccessful
924// SELFREG_E_TYPELIB
925// (not implemented)
926// E_OUTOFMEMORY
927// (not implemented)
928// E_UNEXPECTED
929// (not implemented)
930// DllUnregisterServer
931// S_OK
932// Unregistration was successful
933// S_FALSE
934// Unregistration was successful, but other
935// entries still exist for the DLL's classes
936// SELFREG_E_CLASS
937// (not implemented)
938// SELFREG_E_TYPELIB
939// (not implemented)
940// E_OUTOFMEMORY
941// (not implemented)
942// E_UNEXPECTED
943// (not implemented)
944
946{
947 return S_OK;
948}
949
950
952{
953 return S_OK;
954}
955
956/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PROPID GetPropertyPropid() const
Definition: propspec.hxx:112
void SetProperty(PROPID pidProperty)
Definition: propspec.cxx:132
void SetPropSet(GUID const &guidPropSet)
Definition: propspec.hxx:96
GUID const & GetPropSet() const
Definition: propspec.hxx:100
std::wstring getTagData(const std::wstring &TagName)
Get a specific tag content, compound tags will be returned as comma separated list.
LocaleSet_t getDefaultLocale()
Get the default language of the whole document.
virtual ULONG STDMETHODCALLTYPE AddRef() override
Definition: ooofilt.cxx:744
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override
Definition: ooofilt.cxx:721
virtual HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObject) override
Definition: ooofilt.cxx:783
virtual ULONG STDMETHODCALLTYPE Release() override
Definition: ooofilt.cxx:754
virtual ~COooFilterCF()
Definition: ooofilt.cxx:705
virtual HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) override
Definition: ooofilt.cxx:819
LONG m_lRefs
Definition: ooofilt.hxx:190
COooFilter()
Definition: ooofilt.cxx:77
ULONG m_ulUnicodeCharsRead
Definition: ooofilt.hxx:143
virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize) override
Definition: ooofilt.cxx:644
virtual ULONG STDMETHODCALLTYPE Release() override
Definition: ooofilt.cxx:164
CContentReader * m_pContentReader
Definition: ooofilt.hxx:138
CFullPropSpec * m_pAttributes
Definition: ooofilt.hxx:152
CMetaInfoReader * m_pMetaInfoReader
Definition: ooofilt.hxx:139
virtual SCODE STDMETHODCALLTYPE Init(ULONG grfFlags, ULONG cAttributes, FULLPROPSPEC const *aAttributes, ULONG *pFlags) override
Definition: ooofilt.cxx:196
ULONG m_ChunkPosition
Definition: ooofilt.hxx:150
virtual SCODE STDMETHODCALLTYPE GetValue(PROPVARIANT **ppPropValue) override
Definition: ooofilt.cxx:461
virtual SCODE STDMETHODCALLTYPE GetText(ULONG *pcwcBuffer, WCHAR *awcBuffer) override
Definition: ooofilt.cxx:398
ULONG m_cAttributes
Definition: ooofilt.hxx:151
bool m_fEof
Definition: ooofilt.hxx:148
::std::wstring m_pwszFileName
Definition: ooofilt.hxx:141
FilterState m_eState
Definition: ooofilt.hxx:140
virtual HRESULT STDMETHODCALLTYPE IsDirty() override
Definition: ooofilt.cxx:537
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override
Definition: ooofilt.cxx:124
virtual SCODE STDMETHODCALLTYPE GetChunk(STAT_CHUNK *pStat) override
Definition: ooofilt.cxx:304
ULONG m_ulChunkID
Definition: ooofilt.hxx:146
StreamInterface * m_pStream
Definition: ooofilt.hxx:153
::std::wstring m_pwsBuffer
Definition: ooofilt.hxx:149
virtual HRESULT STDMETHODCALLTYPE Save(LPCOLESTR pszFileName, BOOL fRemember) override
Definition: ooofilt.cxx:590
virtual HRESULT STDMETHODCALLTYPE SaveCompleted(LPCOLESTR pszFileName) override
Definition: ooofilt.cxx:604
ULONG m_ulCurrentPropertyNum
Definition: ooofilt.hxx:145
virtual SCODE STDMETHODCALLTYPE BindRegion(FILTERREGION origPos, REFIID riid, void **ppunk) override
Definition: ooofilt.cxx:505
virtual ~COooFilter()
Definition: ooofilt.cxx:103
bool m_fContents
Definition: ooofilt.hxx:147
ULONG m_ulUnicodeBufferLen
Definition: ooofilt.hxx:142
virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID) override
Definition: ooofilt.cxx:523
LONG m_lRefs
Definition: ooofilt.hxx:137
virtual HRESULT STDMETHODCALLTYPE GetCurFile(LPOLESTR *ppszFileName) override
Definition: ooofilt.cxx:679
ULONG m_ulPropertyNum
Definition: ooofilt.hxx:144
virtual ULONG STDMETHODCALLTYPE AddRef() override
Definition: ooofilt.cxx:154
virtual HRESULT STDMETHODCALLTYPE Load(LPCOLESTR pszFileName, DWORD dwMode) override
Definition: ooofilt.cxx:557
#define META_INFO_AUTHOR
Definition: config.hxx:35
#define EMPTY_STRING
Definition: config.hxx:31
#define META_INFO_SUBJECT
Definition: config.hxx:36
#define META_INFO_KEYWORDS
Definition: config.hxx:37
#define META_INFO_TITLE
Definition: config.hxx:34
#define META_INFO_DESCRIPTION
Definition: config.hxx:39
GtkMediaStream * m_pStream
#define TRUE
size
constexpr OUStringLiteral first
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
const int COUNT_ATTRIBUTES
Definition: ooofilt.cxx:194
HRESULT STDMETHODCALLTYPE DllGetClassObject(REFCLSID cid, REFIID iid, LPVOID *ppvObj)
Definition: ooofilt.cxx:873
STDAPI DllRegisterServer()
Definition: ooofilt.cxx:945
STDAPI DllUnregisterServer()
Definition: ooofilt.cxx:951
::std::wstring GetMetaInfoNameFromPropertyId(ULONG ulPropID)
Definition: ooofilt.cxx:438
HRESULT STDMETHODCALLTYPE DllCanUnloadNow()
Definition: ooofilt.cxx:908
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID)
Definition: ooofilt.cxx:843
LONG g_lInstances
Definition: ooofilt.hxx:35
FilterState
Definition: ooofilt.hxx:68
GUID const CLSID_COooFilter
Definition: ooofilt.hxx:44
GUID const guidStorage
Definition: ooofilt.hxx:36
#define VT_LPWSTR
const wchar_t *typedef BOOL
LCID LocaleSetToLCID(const LocaleSet_t &Locale)
convert LocaleSet pair into Microsoft List of Locale ID (LCID) according to ISO-639 and ISO-3166.
Definition: utilities.cxx:154
std::wstring getShortPathName(const std::wstring &aLongName)
helper function to convert windows paths to short form.
Definition: utilities.cxx:122