1*f8e2c85aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f8e2c85aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f8e2c85aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f8e2c85aSAndrew Rist * distributed with this work for additional information 6*f8e2c85aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f8e2c85aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f8e2c85aSAndrew Rist * "License"); you may not use this file except in compliance 9*f8e2c85aSAndrew Rist * with the License. You may obtain a copy of the License at 10*f8e2c85aSAndrew Rist * 11*f8e2c85aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f8e2c85aSAndrew Rist * 13*f8e2c85aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f8e2c85aSAndrew Rist * software distributed under the License is distributed on an 15*f8e2c85aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f8e2c85aSAndrew Rist * KIND, either express or implied. See the License for the 17*f8e2c85aSAndrew Rist * specific language governing permissions and limitations 18*f8e2c85aSAndrew Rist * under the License. 19*f8e2c85aSAndrew Rist * 20*f8e2c85aSAndrew Rist *************************************************************/ 21*f8e2c85aSAndrew Rist 22*f8e2c85aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_shell.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //-------------------------------------------------------------------------- 28cdf0e10cSrcweir // File: ooofilt.cxx 29cdf0e10cSrcweir // 30cdf0e10cSrcweir // Contents: Filter Implementation for OpenOffice.Org Document using 31cdf0e10cSrcweir // Indexing Service 32cdf0e10cSrcweir // 33cdf0e10cSrcweir // Summary: The OpenOffice.org filter reads OpenOffice.org files (with the 34cdf0e10cSrcweir // extension .sxw .sxi, etc) and extract their content, author, 35cdf0e10cSrcweir // keywords,subject,comments and title to be filtered. 36cdf0e10cSrcweir // 37cdf0e10cSrcweir // Platform: Windows 2000, Windows XP 38cdf0e10cSrcweir // 39cdf0e10cSrcweir //-------------------------------------------------------------------------- 40cdf0e10cSrcweir #include "internal/contentreader.hxx" 41cdf0e10cSrcweir #include "internal/metainforeader.hxx" 42cdf0e10cSrcweir //#include "internal/utilities.hxx" 43cdf0e10cSrcweir #include "internal/registry.hxx" 44cdf0e10cSrcweir #include "internal/fileextensions.hxx" 45cdf0e10cSrcweir 46cdf0e10cSrcweir //-------------------------------------------------------------------------- 47cdf0e10cSrcweir // 48cdf0e10cSrcweir // Include file Purpose 49cdf0e10cSrcweir // 50cdf0e10cSrcweir // windows.h Win32 declarations 51cdf0e10cSrcweir // string.h string wstring declarations 52cdf0e10cSrcweir // filter.h IFilter interface declarations 53cdf0e10cSrcweir // filterr.h FACILITY_ITF error definitions for IFilter 54cdf0e10cSrcweir // ntquery.h Indexing Service declarations 55cdf0e10cSrcweir // assert.h assertion function. 56cdf0e10cSrcweir // ooofilt.hxx OpenOffice.org filter declarations 57cdf0e10cSrcweir // propspec.hxx PROPSPEC 58cdf0e10cSrcweir // 59cdf0e10cSrcweir //-------------------------------------------------------------------------- 60cdf0e10cSrcweir 61cdf0e10cSrcweir #if defined _MSC_VER 62cdf0e10cSrcweir #pragma warning(push, 1) 63cdf0e10cSrcweir #endif 64cdf0e10cSrcweir #include <windows.h> 65cdf0e10cSrcweir #if defined _MSC_VER 66cdf0e10cSrcweir #pragma warning(pop) 67cdf0e10cSrcweir #endif 68cdf0e10cSrcweir #include <string.h> 69cdf0e10cSrcweir #include <filter.h> 70cdf0e10cSrcweir #include <filterr.h> 71cdf0e10cSrcweir #include <ntquery.h> 72cdf0e10cSrcweir #include "assert.h" 73cdf0e10cSrcweir #include "ooofilt.hxx" 74cdf0e10cSrcweir #include <objidl.h> 75cdf0e10cSrcweir #include <stdio.h> 76cdf0e10cSrcweir #include "propspec.hxx" 77cdf0e10cSrcweir #ifdef __MINGW32__ 78cdf0e10cSrcweir #include <algorithm> 79cdf0e10cSrcweir using ::std::min; 80cdf0e10cSrcweir #endif 81cdf0e10cSrcweir 82cdf0e10cSrcweir #include "internal/stream_helper.hxx" 83cdf0e10cSrcweir 84cdf0e10cSrcweir //C------------------------------------------------------------------------- 85cdf0e10cSrcweir // 86cdf0e10cSrcweir // Class: COooFilter 87cdf0e10cSrcweir // 88cdf0e10cSrcweir // Summary: Implements OpenOffice.org filter class 89cdf0e10cSrcweir // 90cdf0e10cSrcweir //-------------------------------------------------------------------------- 91cdf0e10cSrcweir //M------------------------------------------------------------------------- 92cdf0e10cSrcweir // 93cdf0e10cSrcweir // Method: COooFilter::COooFilter 94cdf0e10cSrcweir // 95cdf0e10cSrcweir // Summary: Class constructor 96cdf0e10cSrcweir // 97cdf0e10cSrcweir // Arguments: void 98cdf0e10cSrcweir // 99cdf0e10cSrcweir // Purpose: Manages global instance count 100cdf0e10cSrcweir // 101cdf0e10cSrcweir //-------------------------------------------------------------------------- 102cdf0e10cSrcweir COooFilter::COooFilter() : 103cdf0e10cSrcweir m_lRefs(1), 104cdf0e10cSrcweir m_pContentReader(NULL), 105cdf0e10cSrcweir m_pMetaInfoReader(NULL), 106cdf0e10cSrcweir m_eState(FilteringContent), 107cdf0e10cSrcweir m_ulUnicodeBufferLen(0), 108cdf0e10cSrcweir m_ulUnicodeCharsRead(0), 109cdf0e10cSrcweir m_ulPropertyNum(0), 110cdf0e10cSrcweir m_ulCurrentPropertyNum(0), 111cdf0e10cSrcweir m_ulChunkID(1), 112cdf0e10cSrcweir m_fContents(FALSE), 113cdf0e10cSrcweir m_fEof(FALSE), 114cdf0e10cSrcweir m_ChunkPosition(0), 115cdf0e10cSrcweir m_cAttributes(0), 116cdf0e10cSrcweir m_pAttributes(0), 117cdf0e10cSrcweir m_pStream(NULL) 118cdf0e10cSrcweir 119cdf0e10cSrcweir { 120cdf0e10cSrcweir InterlockedIncrement( &g_lInstances ); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir //M------------------------------------------------------------------------- 123cdf0e10cSrcweir // 124cdf0e10cSrcweir // Method: COooFilter::~COooFilter 125cdf0e10cSrcweir // 126cdf0e10cSrcweir // Summary: Class destructor 127cdf0e10cSrcweir // 128cdf0e10cSrcweir // Arguments: void 129cdf0e10cSrcweir // 130cdf0e10cSrcweir // Purpose: Manages global instance count and file handle 131cdf0e10cSrcweir // 132cdf0e10cSrcweir //-------------------------------------------------------------------------- 133cdf0e10cSrcweir COooFilter::~COooFilter() 134cdf0e10cSrcweir { 135cdf0e10cSrcweir delete [] m_pAttributes; 136cdf0e10cSrcweir 137cdf0e10cSrcweir if (m_pContentReader) 138cdf0e10cSrcweir delete m_pContentReader; 139cdf0e10cSrcweir if (m_pMetaInfoReader) 140cdf0e10cSrcweir delete m_pMetaInfoReader; 141cdf0e10cSrcweir 142cdf0e10cSrcweir InterlockedDecrement( &g_lInstances ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir //M------------------------------------------------------------------------- 146cdf0e10cSrcweir // 147cdf0e10cSrcweir // Method: COooFilter::QueryInterface (IUnknown::QueryInterface) 148cdf0e10cSrcweir // 149cdf0e10cSrcweir // Summary: Queries for requested interface 150cdf0e10cSrcweir // 151cdf0e10cSrcweir // Arguments: riid 152cdf0e10cSrcweir // [in] Reference IID of requested interface 153cdf0e10cSrcweir // ppvObject 154cdf0e10cSrcweir // [out] Address that receives requested interface pointer 155cdf0e10cSrcweir // 156cdf0e10cSrcweir // Returns: S_OK 157cdf0e10cSrcweir // Interface is supported 158cdf0e10cSrcweir // E_NOINTERFACE 159cdf0e10cSrcweir // Interface is not supported 160cdf0e10cSrcweir // 161cdf0e10cSrcweir //-------------------------------------------------------------------------- 162cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::QueryInterface( 163cdf0e10cSrcweir REFIID riid, 164cdf0e10cSrcweir void ** ppvObject) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir IUnknown *pUnkTemp = 0; 167cdf0e10cSrcweir if ( IID_IFilter == riid ) 168cdf0e10cSrcweir pUnkTemp = (IUnknown *)(IFilter *)this; 169cdf0e10cSrcweir else if ( IID_IPersistFile == riid ) 170cdf0e10cSrcweir pUnkTemp = (IUnknown *)(IPersistFile *)this; 171cdf0e10cSrcweir else if ( IID_IPersist == riid ) 172cdf0e10cSrcweir pUnkTemp = (IUnknown *)(IPersist *)(IPersistFile *)this; 173cdf0e10cSrcweir else if (IID_IPersistStream == riid) 174cdf0e10cSrcweir pUnkTemp = (IUnknown *)(IPersistStream *)this; 175cdf0e10cSrcweir else if ( IID_IUnknown == riid ) 176cdf0e10cSrcweir pUnkTemp = (IUnknown *)(IPersist *)(IPersistFile *)this; 177cdf0e10cSrcweir else 178cdf0e10cSrcweir { 179cdf0e10cSrcweir *ppvObject = NULL; 180cdf0e10cSrcweir return E_NOINTERFACE; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir *ppvObject = (void *)pUnkTemp; 183cdf0e10cSrcweir pUnkTemp->AddRef(); 184cdf0e10cSrcweir return S_OK; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir //M------------------------------------------------------------------------- 187cdf0e10cSrcweir // 188cdf0e10cSrcweir // Method: COooFilter::AddRef (IUnknown::AddRef) 189cdf0e10cSrcweir // 190cdf0e10cSrcweir // Summary: Increments interface refcount 191cdf0e10cSrcweir // 192cdf0e10cSrcweir // Arguments: void 193cdf0e10cSrcweir // 194cdf0e10cSrcweir // Returns: Value of incremented interface refcount 195cdf0e10cSrcweir // 196cdf0e10cSrcweir //-------------------------------------------------------------------------- 197cdf0e10cSrcweir ULONG STDMETHODCALLTYPE COooFilter::AddRef() 198cdf0e10cSrcweir { 199cdf0e10cSrcweir return InterlockedIncrement( &m_lRefs ); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir //M------------------------------------------------------------------------- 202cdf0e10cSrcweir // 203cdf0e10cSrcweir // Method: COooFilter::Release (IUnknown::Release) 204cdf0e10cSrcweir // 205cdf0e10cSrcweir // Summary: Decrements interface refcount, deleting if unreferenced 206cdf0e10cSrcweir // 207cdf0e10cSrcweir // Arguments: void 208cdf0e10cSrcweir // 209cdf0e10cSrcweir // Returns: Value of decremented interface refcount 210cdf0e10cSrcweir // 211cdf0e10cSrcweir //-------------------------------------------------------------------------- 212cdf0e10cSrcweir ULONG STDMETHODCALLTYPE COooFilter::Release() 213cdf0e10cSrcweir { 214cdf0e10cSrcweir ULONG ulTmp = InterlockedDecrement( &m_lRefs ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir if ( 0 == ulTmp ) 217cdf0e10cSrcweir delete this; 218cdf0e10cSrcweir return ulTmp; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir //M------------------------------------------------------------------------- 221cdf0e10cSrcweir // 222cdf0e10cSrcweir // Method: COooFilter::Init (IFilter::Init) 223cdf0e10cSrcweir // 224cdf0e10cSrcweir // Summary: Initializes OpenOffice.org filter instance 225cdf0e10cSrcweir // 226cdf0e10cSrcweir // Arguments: grfFlags 227cdf0e10cSrcweir // [in] Flags for filter behavior 228cdf0e10cSrcweir // cAttributes 229cdf0e10cSrcweir // [in] Number attributes in array aAttributes 230cdf0e10cSrcweir // aAttributes 231cdf0e10cSrcweir // [in] Array of requested attribute strings 232cdf0e10cSrcweir // pFlags 233cdf0e10cSrcweir // [out] Pointer to return flags for additional properties 234cdf0e10cSrcweir // 235cdf0e10cSrcweir // Returns: S_OK 236cdf0e10cSrcweir // Initialization succeeded 237cdf0e10cSrcweir // E_FAIL 238cdf0e10cSrcweir // File not previously loaded 239cdf0e10cSrcweir // E_INVALIDARG 240cdf0e10cSrcweir // Count and contents of attributes do not agree 241cdf0e10cSrcweir // FILTER_E_ACCESS 242cdf0e10cSrcweir // Unable to access file to be filtered 243cdf0e10cSrcweir // FILTER_E_PASSWORD 244cdf0e10cSrcweir // (not implemented) 245cdf0e10cSrcweir // 246cdf0e10cSrcweir //-------------------------------------------------------------------------- 247cdf0e10cSrcweir const int COUNT_ATTRIBUTES = 5; 248cdf0e10cSrcweir 249cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::Init( 250cdf0e10cSrcweir ULONG grfFlags, 251cdf0e10cSrcweir ULONG cAttributes, 252cdf0e10cSrcweir FULLPROPSPEC const * aAttributes, 253cdf0e10cSrcweir ULONG * pFlags) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir // Enumerate OLE properties, since any NTFS file can have them 256cdf0e10cSrcweir *pFlags = IFILTER_FLAGS_OLE_PROPERTIES; 257cdf0e10cSrcweir try 258cdf0e10cSrcweir { 259cdf0e10cSrcweir m_fContents = FALSE; 260cdf0e10cSrcweir m_ulPropertyNum = 0; 261cdf0e10cSrcweir m_ulCurrentPropertyNum = 0; 262cdf0e10cSrcweir if ( m_cAttributes > 0 ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir delete[] m_pAttributes; 265cdf0e10cSrcweir m_pAttributes = 0; 266cdf0e10cSrcweir m_cAttributes = 0; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir if( 0 < cAttributes ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir // Filter properties specified in aAttributes 271cdf0e10cSrcweir if ( 0 == aAttributes ) 272cdf0e10cSrcweir return E_INVALIDARG; 273cdf0e10cSrcweir m_pAttributes = new CFullPropSpec[cAttributes]; 274cdf0e10cSrcweir m_cAttributes = cAttributes; 275cdf0e10cSrcweir // Is caller want to filter contents? 276cdf0e10cSrcweir CFullPropSpec *pAttrib = (CFullPropSpec *) aAttributes; 277cdf0e10cSrcweir ULONG ulNumAttr; 278cdf0e10cSrcweir for ( ulNumAttr = 0 ; ulNumAttr < cAttributes; ulNumAttr++ ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir if ( pAttrib[ulNumAttr].IsPropertyPropid() && 281cdf0e10cSrcweir pAttrib[ulNumAttr].GetPropertyPropid() == PID_STG_CONTENTS && 282cdf0e10cSrcweir pAttrib[ulNumAttr].GetPropSet() == guidStorage ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir m_fContents = TRUE; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir // save the requested properties. 287cdf0e10cSrcweir m_pAttributes[ulNumAttr] = pAttrib[ulNumAttr]; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir else if ( grfFlags & IFILTER_INIT_APPLY_INDEX_ATTRIBUTES ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir // Filter contents and all pseudo-properties 293cdf0e10cSrcweir m_fContents = TRUE; 294cdf0e10cSrcweir 295cdf0e10cSrcweir m_pAttributes = new CFullPropSpec[COUNT_ATTRIBUTES]; 296cdf0e10cSrcweir m_cAttributes = COUNT_ATTRIBUTES; 297cdf0e10cSrcweir m_pAttributes[0].SetPropSet( FMTID_SummaryInformation ); 298cdf0e10cSrcweir m_pAttributes[0].SetProperty( PIDSI_AUTHOR ); 299cdf0e10cSrcweir m_pAttributes[1].SetPropSet( FMTID_SummaryInformation ); 300cdf0e10cSrcweir m_pAttributes[1].SetProperty( PIDSI_TITLE ); 301cdf0e10cSrcweir m_pAttributes[2].SetPropSet( FMTID_SummaryInformation ); 302cdf0e10cSrcweir m_pAttributes[2].SetProperty( PIDSI_SUBJECT ); 303cdf0e10cSrcweir m_pAttributes[3].SetPropSet( FMTID_SummaryInformation ); 304cdf0e10cSrcweir m_pAttributes[3].SetProperty( PIDSI_KEYWORDS ); 305cdf0e10cSrcweir m_pAttributes[4].SetPropSet( FMTID_SummaryInformation ); 306cdf0e10cSrcweir m_pAttributes[4].SetProperty( PIDSI_COMMENTS ); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir else if ( 0 == grfFlags ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir // Filter only contents 311cdf0e10cSrcweir m_fContents = TRUE; 312cdf0e10cSrcweir } 313cdf0e10cSrcweir else 314cdf0e10cSrcweir m_fContents = FALSE; 315cdf0e10cSrcweir // Re-initialize 316cdf0e10cSrcweir if ( m_fContents ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir m_fEof = FALSE; 319cdf0e10cSrcweir m_eState = FilteringContent; 320cdf0e10cSrcweir m_ulUnicodeCharsRead = 0; 321cdf0e10cSrcweir m_ChunkPosition = 0; 322cdf0e10cSrcweir } 323cdf0e10cSrcweir else 324cdf0e10cSrcweir { 325cdf0e10cSrcweir m_fEof = TRUE; 326cdf0e10cSrcweir m_eState = FilteringProperty; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir m_ulChunkID = 1; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir catch (const std::exception&) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir return E_FAIL; 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir return S_OK; 336cdf0e10cSrcweir } 337cdf0e10cSrcweir //M------------------------------------------------------------------------- 338cdf0e10cSrcweir // 339cdf0e10cSrcweir // Method: COooFilter::GetChunk (IFilter::GetChunk) 340cdf0e10cSrcweir // 341cdf0e10cSrcweir // Summary: Gets the next chunk 342cdf0e10cSrcweir // 343cdf0e10cSrcweir // Arguments: ppStat 344cdf0e10cSrcweir // [out] Pointer to description of current chunk 345cdf0e10cSrcweir // Returns: S_OK 346cdf0e10cSrcweir // Chunk was successfully retrieved 347cdf0e10cSrcweir // E_FAIL 348cdf0e10cSrcweir // Character conversion failed 349cdf0e10cSrcweir // FILTER_E_ACCESS 350cdf0e10cSrcweir // General access failure occurred 351cdf0e10cSrcweir // FILTER_E_END_OF_CHUNKS 352cdf0e10cSrcweir // Previous chunk was the last chunk 353cdf0e10cSrcweir // FILTER_E_EMBEDDING_UNAVAILABLE 354cdf0e10cSrcweir // (not implemented) 355cdf0e10cSrcweir // FILTER_E_LINK_UNAVAILABLE 356cdf0e10cSrcweir // (not implemented) 357cdf0e10cSrcweir // FILTER_E_PASSWORD 358cdf0e10cSrcweir // (not implemented) 359cdf0e10cSrcweir // 360cdf0e10cSrcweir //-------------------------------------------------------------------------- 361cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::GetChunk(STAT_CHUNK * pStat) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir for(;;) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir switch ( m_eState ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir case FilteringContent: 368cdf0e10cSrcweir { 369cdf0e10cSrcweir // Read Unicodes from buffer. 370cdf0e10cSrcweir if( m_ChunkPosition == m_pContentReader ->getChunkBuffer().size() ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir m_ulUnicodeBufferLen=0; 373cdf0e10cSrcweir m_fEof = TRUE; 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir if ( !m_fContents || m_fEof ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir m_eState = FilteringProperty; 379cdf0e10cSrcweir continue; 380cdf0e10cSrcweir } 381cdf0e10cSrcweir m_pwsBuffer = m_pContentReader -> getChunkBuffer()[m_ChunkPosition].second; 382cdf0e10cSrcweir m_ulUnicodeBufferLen = m_pwsBuffer.length(); 383cdf0e10cSrcweir DWORD ChunkLCID = LocaleSetToLCID( m_pContentReader -> getChunkBuffer()[m_ChunkPosition].first ); 384cdf0e10cSrcweir // Set chunk description 385cdf0e10cSrcweir pStat->idChunk = m_ulChunkID; 386cdf0e10cSrcweir pStat->breakType = CHUNK_NO_BREAK; 387cdf0e10cSrcweir pStat->flags = CHUNK_TEXT; 388cdf0e10cSrcweir pStat->locale = ChunkLCID; 389cdf0e10cSrcweir pStat->attribute.guidPropSet = guidStorage; 390cdf0e10cSrcweir pStat->attribute.psProperty.ulKind = PRSPEC_PROPID; 391cdf0e10cSrcweir pStat->attribute.psProperty.propid = PID_STG_CONTENTS; 392cdf0e10cSrcweir pStat->idChunkSource = m_ulChunkID; 393cdf0e10cSrcweir pStat->cwcStartSource = 0; 394cdf0e10cSrcweir pStat->cwcLenSource = 0; 395cdf0e10cSrcweir m_ulUnicodeCharsRead = 0; 396cdf0e10cSrcweir m_ulChunkID++; 397cdf0e10cSrcweir m_ChunkPosition++; 398cdf0e10cSrcweir return S_OK; 399cdf0e10cSrcweir } 400cdf0e10cSrcweir case FilteringProperty: 401cdf0e10cSrcweir { 402cdf0e10cSrcweir if ( m_cAttributes == 0 ) 403cdf0e10cSrcweir return FILTER_E_END_OF_CHUNKS; 404cdf0e10cSrcweir while( !( ( m_pAttributes[m_ulPropertyNum].IsPropertyPropid() ) && 405cdf0e10cSrcweir ( m_pAttributes[m_ulPropertyNum].GetPropSet() == FMTID_SummaryInformation ) )|| 406cdf0e10cSrcweir ( ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_AUTHOR ) && 407cdf0e10cSrcweir ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_TITLE ) && 408cdf0e10cSrcweir ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_SUBJECT ) && 409cdf0e10cSrcweir ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_KEYWORDS ) && 410cdf0e10cSrcweir ( m_pAttributes[m_ulPropertyNum].GetPropertyPropid() != PIDSI_COMMENTS ) ) ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir if ( m_ulPropertyNum < m_cAttributes ) 413cdf0e10cSrcweir m_ulPropertyNum++; 414cdf0e10cSrcweir else 415cdf0e10cSrcweir break; 416cdf0e10cSrcweir } 417cdf0e10cSrcweir if ( m_ulPropertyNum == m_cAttributes) 418cdf0e10cSrcweir return FILTER_E_END_OF_CHUNKS; 419cdf0e10cSrcweir else 420cdf0e10cSrcweir { 421cdf0e10cSrcweir // Set chunk description 422cdf0e10cSrcweir pStat->idChunk = m_ulChunkID; 423cdf0e10cSrcweir pStat->breakType = CHUNK_EOS; 424cdf0e10cSrcweir pStat->flags = CHUNK_VALUE; 425cdf0e10cSrcweir pStat->locale = GetSystemDefaultLCID(); 426cdf0e10cSrcweir pStat->attribute.guidPropSet = FMTID_SummaryInformation; 427cdf0e10cSrcweir pStat->attribute.psProperty.ulKind = PRSPEC_PROPID; 428cdf0e10cSrcweir pStat->attribute.psProperty.propid = m_pAttributes[m_ulPropertyNum].GetPropertyPropid(); 429cdf0e10cSrcweir pStat->idChunkSource = m_ulChunkID; 430cdf0e10cSrcweir pStat->cwcStartSource = 0; 431cdf0e10cSrcweir pStat->cwcLenSource = 0; 432cdf0e10cSrcweir m_ulCurrentPropertyNum = m_ulPropertyNum; 433cdf0e10cSrcweir m_ulPropertyNum++; 434cdf0e10cSrcweir m_ulChunkID++; 435cdf0e10cSrcweir return S_OK; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir default: 439cdf0e10cSrcweir return E_FAIL; 440cdf0e10cSrcweir }//switch(...) 441cdf0e10cSrcweir }//for(;;) 442cdf0e10cSrcweir } 443cdf0e10cSrcweir //M------------------------------------------------------------------------- 444cdf0e10cSrcweir // 445cdf0e10cSrcweir // Method: COooFilter::GetText (IFilter::GetText) 446cdf0e10cSrcweir // 447cdf0e10cSrcweir // Summary: Retrieves UNICODE text for index 448cdf0e10cSrcweir // 449cdf0e10cSrcweir // Arguments: pcwcBuffer 450cdf0e10cSrcweir // [in] Pointer to size of UNICODE buffer 451cdf0e10cSrcweir // [out] Pointer to count of UNICODE characters returned 452cdf0e10cSrcweir // awcBuffer 453cdf0e10cSrcweir // [out] Pointer to buffer to receive UNICODE text 454cdf0e10cSrcweir // 455cdf0e10cSrcweir // Returns: S_OK 456cdf0e10cSrcweir // Text successfully retrieved, but text remains in chunk 457cdf0e10cSrcweir // FILTER_E_NO_MORE_TEXT 458cdf0e10cSrcweir // All of the text in the current chunk has been returned 459cdf0e10cSrcweir // FILTER_S_LAST_TEXT 460cdf0e10cSrcweir // Next call to GetText will return FILTER_E_NO_MORE_TEXT 461cdf0e10cSrcweir // 462cdf0e10cSrcweir //-------------------------------------------------------------------------- 463cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::GetText(ULONG * pcwcBuffer, WCHAR * awcBuffer) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir switch ( m_eState ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir case FilteringProperty: 468cdf0e10cSrcweir return FILTER_E_NO_TEXT; 469cdf0e10cSrcweir case FilteringContent: 470cdf0e10cSrcweir { 471cdf0e10cSrcweir if ( !m_fContents || 0 == m_ulUnicodeBufferLen ) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir *pcwcBuffer = 0; 474cdf0e10cSrcweir return FILTER_E_NO_MORE_TEXT; 475cdf0e10cSrcweir } 476cdf0e10cSrcweir // Copy UNICODE characters in chunk buffer to output UNICODE buffer 477cdf0e10cSrcweir ULONG ulToCopy = min( *pcwcBuffer, m_ulUnicodeBufferLen - m_ulUnicodeCharsRead ); 478cdf0e10cSrcweir ZeroMemory(awcBuffer, sizeof(awcBuffer)); 479cdf0e10cSrcweir wmemcpy( awcBuffer, m_pwsBuffer.c_str() + m_ulUnicodeCharsRead, ulToCopy ); 480cdf0e10cSrcweir m_ulUnicodeCharsRead += ulToCopy; 481cdf0e10cSrcweir *pcwcBuffer = ulToCopy; 482cdf0e10cSrcweir if ( m_ulUnicodeBufferLen == m_ulUnicodeCharsRead ) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir m_ulUnicodeCharsRead = 0; 485cdf0e10cSrcweir m_ulUnicodeBufferLen = 0; 486cdf0e10cSrcweir return FILTER_S_LAST_TEXT; 487cdf0e10cSrcweir } 488cdf0e10cSrcweir return S_OK; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir default: 491cdf0e10cSrcweir return E_FAIL; 492cdf0e10cSrcweir } 493cdf0e10cSrcweir } 494cdf0e10cSrcweir //M------------------------------------------------------------------------- 495cdf0e10cSrcweir // 496cdf0e10cSrcweir // Method: GetMetaInfoNameFromPropertyId 497cdf0e10cSrcweir // 498cdf0e10cSrcweir // Summary: helper function to convert PropertyID into respective 499cdf0e10cSrcweir // MetaInfo names. 500cdf0e10cSrcweir // 501cdf0e10cSrcweir // Arguments: ulPropID 502cdf0e10cSrcweir // [in] property ID 503cdf0e10cSrcweir // 504cdf0e10cSrcweir // Returns: corresponding metainfo names. 505cdf0e10cSrcweir // 506cdf0e10cSrcweir //-------------------------------------------------------------------------- 507cdf0e10cSrcweir 508cdf0e10cSrcweir ::std::wstring GetMetaInfoNameFromPropertyId( ULONG ulPropID ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir switch ( ulPropID ) 511cdf0e10cSrcweir { 512cdf0e10cSrcweir case PIDSI_AUTHOR: return META_INFO_AUTHOR; 513cdf0e10cSrcweir case PIDSI_TITLE: return META_INFO_TITLE; 514cdf0e10cSrcweir case PIDSI_SUBJECT: return META_INFO_SUBJECT; 515cdf0e10cSrcweir case PIDSI_KEYWORDS: return META_INFO_KEYWORDS; 516cdf0e10cSrcweir case PIDSI_COMMENTS: return META_INFO_DESCRIPTION; 517cdf0e10cSrcweir default: return EMPTY_STRING; 518cdf0e10cSrcweir } 519cdf0e10cSrcweir } 520cdf0e10cSrcweir //M------------------------------------------------------------------------- 521cdf0e10cSrcweir // 522cdf0e10cSrcweir // Method: COooFilter::GetValue (IFilter::GetValue) 523cdf0e10cSrcweir // 524cdf0e10cSrcweir // Summary: Retrieves properites for index 525cdf0e10cSrcweir // 526cdf0e10cSrcweir // Arguments: ppPropValue 527cdf0e10cSrcweir // [out] Address that receives pointer to property value 528cdf0e10cSrcweir // 529cdf0e10cSrcweir // Returns: FILTER_E_NO_VALUES 530cdf0e10cSrcweir // Always 531cdf0e10cSrcweir // FILTER_E_NO_MORE_VALUES 532cdf0e10cSrcweir // (not implemented) 533cdf0e10cSrcweir // 534cdf0e10cSrcweir //-------------------------------------------------------------------------- 535cdf0e10cSrcweir 536cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::GetValue(PROPVARIANT ** ppPropValue) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir if (m_eState == FilteringContent) 539cdf0e10cSrcweir return FILTER_E_NO_VALUES; 540cdf0e10cSrcweir else if (m_eState == FilteringProperty) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir if ( m_cAttributes == 0 || ( m_ulCurrentPropertyNum == m_ulPropertyNum ) ) 543cdf0e10cSrcweir return FILTER_E_NO_MORE_VALUES; 544cdf0e10cSrcweir PROPVARIANT *pPropVar = (PROPVARIANT *) CoTaskMemAlloc( sizeof (PROPVARIANT) ); 545cdf0e10cSrcweir if ( pPropVar == 0 ) 546cdf0e10cSrcweir return E_OUTOFMEMORY; 547cdf0e10cSrcweir ::std::wstring wsTagName= GetMetaInfoNameFromPropertyId( m_pAttributes[m_ulCurrentPropertyNum].GetPropertyPropid() ); 548cdf0e10cSrcweir if ( wsTagName == EMPTY_STRING ) 549cdf0e10cSrcweir return FILTER_E_NO_VALUES; 550cdf0e10cSrcweir ::std::wstring wsTagData = m_pMetaInfoReader->getTagData(wsTagName); 551cdf0e10cSrcweir pPropVar->vt = VT_LPWSTR; 552cdf0e10cSrcweir size_t cw = wsTagData.length() + 1; // reserve one for the '\0' 553cdf0e10cSrcweir pPropVar->pwszVal = static_cast<WCHAR*>( CoTaskMemAlloc(cw*sizeof(WCHAR)) ); 554cdf0e10cSrcweir if (pPropVar->pwszVal == 0) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir CoTaskMemFree(pPropVar); 557cdf0e10cSrcweir return E_OUTOFMEMORY; 558cdf0e10cSrcweir } 559cdf0e10cSrcweir wmemcpy(pPropVar->pwszVal, wsTagData.c_str(), cw); 560cdf0e10cSrcweir *ppPropValue = pPropVar; 561cdf0e10cSrcweir m_ulCurrentPropertyNum = m_ulPropertyNum; 562cdf0e10cSrcweir return S_OK; 563cdf0e10cSrcweir } 564cdf0e10cSrcweir else 565cdf0e10cSrcweir return E_FAIL; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir //M------------------------------------------------------------------------- 568cdf0e10cSrcweir // 569cdf0e10cSrcweir // Method: COooFilter::BindRegion (IFilter::BindRegion) 570cdf0e10cSrcweir // 571cdf0e10cSrcweir // Summary: Creates moniker or other interface for indicated text 572cdf0e10cSrcweir // 573cdf0e10cSrcweir // Arguments: origPos 574cdf0e10cSrcweir // [in] Description of text location and extent 575cdf0e10cSrcweir // riid 576cdf0e10cSrcweir // [in] Reference IID of specified interface 577cdf0e10cSrcweir // ppunk 578cdf0e10cSrcweir // [out] Address that receives requested interface pointer 579cdf0e10cSrcweir // 580cdf0e10cSrcweir // Returns: E_NOTIMPL 581cdf0e10cSrcweir // Always 582cdf0e10cSrcweir // FILTER_W_REGION_CLIPPED 583cdf0e10cSrcweir // (not implemented) 584cdf0e10cSrcweir // 585cdf0e10cSrcweir //-------------------------------------------------------------------------- 586cdf0e10cSrcweir 587cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::BindRegion( 588cdf0e10cSrcweir FILTERREGION /*origPos*/, 589cdf0e10cSrcweir REFIID /*riid*/, 590cdf0e10cSrcweir void ** /*ppunk*/) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir // BindRegion is currently reserved for future use 593cdf0e10cSrcweir return E_NOTIMPL; 594cdf0e10cSrcweir } 595cdf0e10cSrcweir //M------------------------------------------------------------------------- 596cdf0e10cSrcweir // 597cdf0e10cSrcweir // Method: COooFilter::GetClassID (IPersist::GetClassID) 598cdf0e10cSrcweir // 599cdf0e10cSrcweir // Summary: Retrieves the class id of the filter class 600cdf0e10cSrcweir // 601cdf0e10cSrcweir // Arguments: pClassID 602cdf0e10cSrcweir // [out] Pointer to the class ID of the filter 603cdf0e10cSrcweir // 604cdf0e10cSrcweir // Returns: S_OK 605cdf0e10cSrcweir // Always 606cdf0e10cSrcweir // E_FAIL 607cdf0e10cSrcweir // (not implemented) 608cdf0e10cSrcweir //-------------------------------------------------------------------------- 609cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::GetClassID(CLSID * pClassID) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir *pClassID = CLSID_COooFilter; 612cdf0e10cSrcweir return S_OK; 613cdf0e10cSrcweir } 614cdf0e10cSrcweir //M------------------------------------------------------------------------- 615cdf0e10cSrcweir // 616cdf0e10cSrcweir // Method: COooFilter::IsDirty (IPersistFile::IsDirty) 617cdf0e10cSrcweir // 618cdf0e10cSrcweir // Summary: Checks whether file has changed since last save 619cdf0e10cSrcweir // 620cdf0e10cSrcweir // Arguments: void 621cdf0e10cSrcweir // 622cdf0e10cSrcweir // Returns: S_FALSE 623cdf0e10cSrcweir // Always 624cdf0e10cSrcweir // S_OK 625cdf0e10cSrcweir // (not implemented) 626cdf0e10cSrcweir // 627cdf0e10cSrcweir //-------------------------------------------------------------------------- 628cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::IsDirty() 629cdf0e10cSrcweir { 630cdf0e10cSrcweir // File is opened read-only and never changes 631cdf0e10cSrcweir return S_FALSE; 632cdf0e10cSrcweir } 633cdf0e10cSrcweir //M------------------------------------------------------------------------- 634cdf0e10cSrcweir // 635cdf0e10cSrcweir // Method: COooFilter::Load (IPersistFile::Load) 636cdf0e10cSrcweir // 637cdf0e10cSrcweir // Summary: Opens and initializes the specified file 638cdf0e10cSrcweir // 639cdf0e10cSrcweir // Arguments: pszFileName 640cdf0e10cSrcweir // [in] Pointer to zero-terminated string 641cdf0e10cSrcweir // of absolute path of file to open 642cdf0e10cSrcweir // dwMode 643cdf0e10cSrcweir // [in] Access mode to open the file 644cdf0e10cSrcweir // 645cdf0e10cSrcweir // Returns: S_OK 646cdf0e10cSrcweir // File was successfully loaded 647cdf0e10cSrcweir // E_OUTOFMEMORY 648cdf0e10cSrcweir // File could not be loaded due to insufficient memory 649cdf0e10cSrcweir // E_FAIL 650cdf0e10cSrcweir // (not implemented) 651cdf0e10cSrcweir // 652cdf0e10cSrcweir //-------------------------------------------------------------------------- 653cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::Load(LPCWSTR pszFileName, DWORD /*dwMode*/) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir // Load just sets the filename for GetChunk to read and ignores the mode 656cdf0e10cSrcweir m_pwszFileName = getShortPathName( pszFileName ); 657cdf0e10cSrcweir 658cdf0e10cSrcweir // Open the file previously specified in call to IPersistFile::Load and get content. 659cdf0e10cSrcweir try 660cdf0e10cSrcweir { 661cdf0e10cSrcweir if (m_pMetaInfoReader) 662cdf0e10cSrcweir delete m_pMetaInfoReader; 663cdf0e10cSrcweir m_pMetaInfoReader = new CMetaInfoReader(WStringToString(m_pwszFileName)); 664cdf0e10cSrcweir 665cdf0e10cSrcweir if (m_pContentReader) 666cdf0e10cSrcweir delete m_pContentReader; 667cdf0e10cSrcweir m_pContentReader = new CContentReader(WStringToString(m_pwszFileName), m_pMetaInfoReader->getDefaultLocale()); 668cdf0e10cSrcweir } 669cdf0e10cSrcweir catch (const std::exception&) 670cdf0e10cSrcweir { 671cdf0e10cSrcweir return E_FAIL; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir return S_OK; 674cdf0e10cSrcweir } 675cdf0e10cSrcweir //M------------------------------------------------------------------------- 676cdf0e10cSrcweir // 677cdf0e10cSrcweir // Method: COooFilter::Save (IPersistFile::Save) 678cdf0e10cSrcweir // 679cdf0e10cSrcweir // Summary: Saves a copy of the current file being filtered 680cdf0e10cSrcweir // 681cdf0e10cSrcweir // Arguments: pszFileName 682cdf0e10cSrcweir // [in] Pointer to zero-terminated string of 683cdf0e10cSrcweir // absolute path of where to save file 684cdf0e10cSrcweir // fRemember 685cdf0e10cSrcweir // [in] Whether the saved copy is made the current file 686cdf0e10cSrcweir // 687cdf0e10cSrcweir // Returns: E_FAIL 688cdf0e10cSrcweir // Always 689cdf0e10cSrcweir // S_OK 690cdf0e10cSrcweir // (not implemented) 691cdf0e10cSrcweir // 692cdf0e10cSrcweir //-------------------------------------------------------------------------- 693cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::Save(LPCWSTR /*pszFileName*/, BOOL /*fRemember*/) 694cdf0e10cSrcweir { 695cdf0e10cSrcweir // File is opened read-only; saving it is an error 696cdf0e10cSrcweir return E_FAIL; 697cdf0e10cSrcweir } 698cdf0e10cSrcweir //M------------------------------------------------------------------------- 699cdf0e10cSrcweir // 700cdf0e10cSrcweir // Method: COooFilter::SaveCompleted (IPersistFile::SaveCompleted) 701cdf0e10cSrcweir // 702cdf0e10cSrcweir // Summary: Determines whether a file save is completed 703cdf0e10cSrcweir // 704cdf0e10cSrcweir // Arguments: pszFileName 705cdf0e10cSrcweir // [in] Pointer to zero-terminated string of 706cdf0e10cSrcweir // absolute path where file was previously saved 707cdf0e10cSrcweir // 708cdf0e10cSrcweir // Returns: S_OK 709cdf0e10cSrcweir // Always 710cdf0e10cSrcweir // 711cdf0e10cSrcweir //-------------------------------------------------------------------------- 712cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::SaveCompleted(LPCWSTR /*pszFileName*/) 713cdf0e10cSrcweir { 714cdf0e10cSrcweir // File is opened read-only, so "save" is always finished 715cdf0e10cSrcweir return S_OK; 716cdf0e10cSrcweir } 717cdf0e10cSrcweir 718cdf0e10cSrcweir //M------------------------------------------------------------------------- 719cdf0e10cSrcweir // 720cdf0e10cSrcweir // Method: COooFilter::Load (IPersistStream::Load) 721cdf0e10cSrcweir // 722cdf0e10cSrcweir // Summary: Initializes an object from the stream where it was previously saved 723cdf0e10cSrcweir // 724cdf0e10cSrcweir // Arguments: pStm 725cdf0e10cSrcweir // [in] Pointer to stream from which object should be loaded 726cdf0e10cSrcweir // 727cdf0e10cSrcweir // 728cdf0e10cSrcweir // Returns: S_OK 729cdf0e10cSrcweir // E_OUTOFMEMORY 730cdf0e10cSrcweir // E_FAIL 731cdf0e10cSrcweir // 732cdf0e10cSrcweir // 733cdf0e10cSrcweir //-------------------------------------------------------------------------- 734cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::Load(IStream *pStm) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir zlib_filefunc_def z_filefunc; 737cdf0e10cSrcweir 738cdf0e10cSrcweir m_pStream = PrepareIStream( pStm, z_filefunc ); 739cdf0e10cSrcweir 740cdf0e10cSrcweir try 741cdf0e10cSrcweir { 742cdf0e10cSrcweir if (m_pMetaInfoReader) 743cdf0e10cSrcweir delete m_pMetaInfoReader; 744cdf0e10cSrcweir m_pMetaInfoReader = new CMetaInfoReader((void*)m_pStream, &z_filefunc); 745cdf0e10cSrcweir 746cdf0e10cSrcweir if (m_pContentReader) 747cdf0e10cSrcweir delete m_pContentReader; 748cdf0e10cSrcweir m_pContentReader = new CContentReader((void*)m_pStream, m_pMetaInfoReader->getDefaultLocale(), &z_filefunc); 749cdf0e10cSrcweir } 750cdf0e10cSrcweir catch (const std::exception&) 751cdf0e10cSrcweir { 752cdf0e10cSrcweir return E_FAIL; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir return S_OK; 755cdf0e10cSrcweir } 756cdf0e10cSrcweir 757cdf0e10cSrcweir //M------------------------------------------------------------------------- 758cdf0e10cSrcweir // 759cdf0e10cSrcweir // Method: COooFilter::GetSizeMax (IPersistStream::GetSizeMax) 760cdf0e10cSrcweir // 761cdf0e10cSrcweir // Summary: Returns the size in bytes of the stream neede to save the object. 762cdf0e10cSrcweir // 763cdf0e10cSrcweir // Arguments: pcbSize 764cdf0e10cSrcweir // [out] Pointer to a 64 bit unsigned int indicating the size needed 765cdf0e10cSrcweir // 766cdf0e10cSrcweir // Returns: E_NOTIMPL 767cdf0e10cSrcweir // 768cdf0e10cSrcweir // 769cdf0e10cSrcweir //-------------------------------------------------------------------------- 770cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::GetSizeMax(ULARGE_INTEGER * /*pcbSize*/) 771cdf0e10cSrcweir { 772cdf0e10cSrcweir // 773cdf0e10cSrcweir return E_NOTIMPL; 774cdf0e10cSrcweir } 775cdf0e10cSrcweir 776cdf0e10cSrcweir //M------------------------------------------------------------------------- 777cdf0e10cSrcweir // 778cdf0e10cSrcweir // Method: COooFilter::Save (IPersistStream::Save) 779cdf0e10cSrcweir // 780cdf0e10cSrcweir // Summary: Save object to specified stream 781cdf0e10cSrcweir // 782cdf0e10cSrcweir // Arguments: pStm 783cdf0e10cSrcweir // [in] Pointer to stream 784cdf0e10cSrcweir // 785cdf0e10cSrcweir // fClearDirty 786cdf0e10cSrcweir // [in] Indicates whether to clear dirty flag 787cdf0e10cSrcweir // 788cdf0e10cSrcweir // Returns: E_NOTIMPL 789cdf0e10cSrcweir // 790cdf0e10cSrcweir // 791cdf0e10cSrcweir //-------------------------------------------------------------------------- 792cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::Save(IStream * /*pStm*/, BOOL ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir // 795cdf0e10cSrcweir return E_NOTIMPL; 796cdf0e10cSrcweir } 797cdf0e10cSrcweir 798cdf0e10cSrcweir //M------------------------------------------------------------------------- 799cdf0e10cSrcweir // 800cdf0e10cSrcweir // Method: COooFilter::GetCurFile (IPersistFile::GetCurFile) 801cdf0e10cSrcweir // 802cdf0e10cSrcweir // Summary: Returns a copy of the current file name 803cdf0e10cSrcweir // 804cdf0e10cSrcweir // Arguments: ppszFileName 805cdf0e10cSrcweir // [out] Address to receive pointer to zero-terminated 806cdf0e10cSrcweir // string for absolute path to current file 807cdf0e10cSrcweir // 808cdf0e10cSrcweir // Returns: S_OK 809cdf0e10cSrcweir // A valid absolute path was successfully returned 810cdf0e10cSrcweir // S_FALSE 811cdf0e10cSrcweir // (not implemented) 812cdf0e10cSrcweir // E_OUTOFMEMORY 813cdf0e10cSrcweir // Operation failed due to insufficient memory 814cdf0e10cSrcweir // E_FAIL 815cdf0e10cSrcweir // Operation failed due to some reason 816cdf0e10cSrcweir // other than insufficient memory 817cdf0e10cSrcweir // 818cdf0e10cSrcweir //------------------------------------------------------------------------- 819cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilter::GetCurFile(LPWSTR * ppszFileName) 820cdf0e10cSrcweir { 821cdf0e10cSrcweir if ( EMPTY_STRING == m_pwszFileName ) 822cdf0e10cSrcweir return E_FAIL; 823cdf0e10cSrcweir else 824cdf0e10cSrcweir *ppszFileName = (LPWSTR)m_pwszFileName.c_str(); 825cdf0e10cSrcweir return S_OK; 826cdf0e10cSrcweir } 827cdf0e10cSrcweir 828cdf0e10cSrcweir //M------------------------------------------------------------------------- 829cdf0e10cSrcweir // 830cdf0e10cSrcweir // Method: COooFilterCF::COooFilterCF 831cdf0e10cSrcweir // 832cdf0e10cSrcweir // Summary: Class factory constructor 833cdf0e10cSrcweir // 834cdf0e10cSrcweir // Arguments: void 835cdf0e10cSrcweir // 836cdf0e10cSrcweir // Purpose: Manages global instance count 837cdf0e10cSrcweir // 838cdf0e10cSrcweir //-------------------------------------------------------------------------- 839cdf0e10cSrcweir COooFilterCF::COooFilterCF() : 840cdf0e10cSrcweir m_lRefs(1) 841cdf0e10cSrcweir { 842cdf0e10cSrcweir InterlockedIncrement( &g_lInstances ); 843cdf0e10cSrcweir } 844cdf0e10cSrcweir //M------------------------------------------------------------------------- 845cdf0e10cSrcweir // 846cdf0e10cSrcweir // Method: COooFilterCF::~COooFilterCF 847cdf0e10cSrcweir // 848cdf0e10cSrcweir // Summary: Class factory destructor 849cdf0e10cSrcweir // 850cdf0e10cSrcweir // Arguments: void 851cdf0e10cSrcweir // 852cdf0e10cSrcweir // Purpose: Manages global instance count 853cdf0e10cSrcweir // 854cdf0e10cSrcweir //-------------------------------------------------------------------------- 855cdf0e10cSrcweir COooFilterCF::~COooFilterCF() 856cdf0e10cSrcweir { 857cdf0e10cSrcweir InterlockedDecrement( &g_lInstances ); 858cdf0e10cSrcweir } 859cdf0e10cSrcweir //M------------------------------------------------------------------------- 860cdf0e10cSrcweir // 861cdf0e10cSrcweir // Method: COooFilterCF::QueryInterface (IUnknown::QueryInterface) 862cdf0e10cSrcweir // 863cdf0e10cSrcweir // Summary: Queries for requested interface 864cdf0e10cSrcweir // 865cdf0e10cSrcweir // Arguments: riid 866cdf0e10cSrcweir // [in] Reference IID of requested interface 867cdf0e10cSrcweir // ppvObject 868cdf0e10cSrcweir // [out] Address that receives requested interface pointer 869cdf0e10cSrcweir // 870cdf0e10cSrcweir // Returns: S_OK 871cdf0e10cSrcweir // Interface is supported 872cdf0e10cSrcweir // E_NOINTERFACE 873cdf0e10cSrcweir // Interface is not supported 874cdf0e10cSrcweir // 875cdf0e10cSrcweir //-------------------------------------------------------------------------- 876cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilterCF::QueryInterface(REFIID riid, void ** ppvObject) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir IUnknown *pUnkTemp; 879cdf0e10cSrcweir 880cdf0e10cSrcweir if ( IID_IClassFactory == riid ) 881cdf0e10cSrcweir pUnkTemp = (IUnknown *)(IClassFactory *)this; 882cdf0e10cSrcweir else if ( IID_IUnknown == riid ) 883cdf0e10cSrcweir pUnkTemp = (IUnknown *)this; 884cdf0e10cSrcweir else 885cdf0e10cSrcweir { 886cdf0e10cSrcweir *ppvObject = NULL; 887cdf0e10cSrcweir return E_NOINTERFACE; 888cdf0e10cSrcweir } 889cdf0e10cSrcweir *ppvObject = (void *)pUnkTemp; 890cdf0e10cSrcweir pUnkTemp->AddRef(); 891cdf0e10cSrcweir return S_OK; 892cdf0e10cSrcweir } 893cdf0e10cSrcweir //M------------------------------------------------------------------------- 894cdf0e10cSrcweir // 895cdf0e10cSrcweir // Method: COooFilterCF::AddRef (IUknown::AddRef) 896cdf0e10cSrcweir // 897cdf0e10cSrcweir // Summary: Increments interface refcount 898cdf0e10cSrcweir // 899cdf0e10cSrcweir // Arguments: void 900cdf0e10cSrcweir // 901cdf0e10cSrcweir // Returns: Value of incremented interface refcount 902cdf0e10cSrcweir // 903cdf0e10cSrcweir //------------------------------------------------------------------------- 904cdf0e10cSrcweir ULONG STDMETHODCALLTYPE COooFilterCF::AddRef() 905cdf0e10cSrcweir { 906cdf0e10cSrcweir return InterlockedIncrement( &m_lRefs ); 907cdf0e10cSrcweir } 908cdf0e10cSrcweir //M------------------------------------------------------------------------- 909cdf0e10cSrcweir // 910cdf0e10cSrcweir // Method: COooFilterCF::Release (IUnknown::Release) 911cdf0e10cSrcweir // 912cdf0e10cSrcweir // Summary: Decrements interface refcount, deleting if unreferenced 913cdf0e10cSrcweir // 914cdf0e10cSrcweir // Arguments: void 915cdf0e10cSrcweir // 916cdf0e10cSrcweir // Returns: Value of decremented refcount 917cdf0e10cSrcweir // 918cdf0e10cSrcweir //-------------------------------------------------------------------------- 919cdf0e10cSrcweir ULONG STDMETHODCALLTYPE COooFilterCF::Release() 920cdf0e10cSrcweir { 921cdf0e10cSrcweir ULONG ulTmp = InterlockedDecrement( &m_lRefs ); 922cdf0e10cSrcweir 923cdf0e10cSrcweir if ( 0 == ulTmp ) 924cdf0e10cSrcweir delete this; 925cdf0e10cSrcweir return ulTmp; 926cdf0e10cSrcweir } 927cdf0e10cSrcweir //M------------------------------------------------------------------------- 928cdf0e10cSrcweir // 929cdf0e10cSrcweir // Method: COooFilterCF::CreateInstance (IClassFactory::CreateInstance) 930cdf0e10cSrcweir // 931cdf0e10cSrcweir // Summary: Creates new OpenOffice.org filter object 932cdf0e10cSrcweir // 933cdf0e10cSrcweir // Arguments: pUnkOuter 934cdf0e10cSrcweir // [in] Pointer to IUnknown interface of aggregating object 935cdf0e10cSrcweir // riid 936cdf0e10cSrcweir // [in] Reference IID of requested interface 937cdf0e10cSrcweir // ppvObject 938cdf0e10cSrcweir // [out] Address that receives requested interface pointer 939cdf0e10cSrcweir // 940cdf0e10cSrcweir // Returns: S_OK 941cdf0e10cSrcweir // OpenOffice.org filter object was successfully created 942cdf0e10cSrcweir // CLASS_E_NOAGGREGATION 943cdf0e10cSrcweir // pUnkOuter parameter was non-NULL 944cdf0e10cSrcweir // E_NOINTERFACE 945cdf0e10cSrcweir // (not implemented) 946cdf0e10cSrcweir // E_OUTOFMEMORY 947cdf0e10cSrcweir // OpenOffice.org filter object could not be created 948cdf0e10cSrcweir // due to insufficient memory 949cdf0e10cSrcweir // E_UNEXPECTED 950cdf0e10cSrcweir // Unsuccessful due to an unexpected condition 951cdf0e10cSrcweir // 952cdf0e10cSrcweir //-------------------------------------------------------------------------- 953cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilterCF::CreateInstance( 954cdf0e10cSrcweir IUnknown * pUnkOuter, 955cdf0e10cSrcweir REFIID riid, 956cdf0e10cSrcweir void * * ppvObject) 957cdf0e10cSrcweir { 958cdf0e10cSrcweir COooFilter *pIUnk = 0; 959cdf0e10cSrcweir if ( 0 != pUnkOuter ) 960cdf0e10cSrcweir return CLASS_E_NOAGGREGATION; 961cdf0e10cSrcweir pIUnk = new COooFilter(); 962cdf0e10cSrcweir if ( 0 != pIUnk ) 963cdf0e10cSrcweir { 964cdf0e10cSrcweir if ( SUCCEEDED( pIUnk->QueryInterface( riid , ppvObject ) ) ) 965cdf0e10cSrcweir { 966cdf0e10cSrcweir // Release extra refcount from QueryInterface 967cdf0e10cSrcweir pIUnk->Release(); 968cdf0e10cSrcweir } 969cdf0e10cSrcweir else 970cdf0e10cSrcweir { 971cdf0e10cSrcweir delete pIUnk; 972cdf0e10cSrcweir return E_UNEXPECTED; 973cdf0e10cSrcweir } 974cdf0e10cSrcweir } 975cdf0e10cSrcweir else 976cdf0e10cSrcweir return E_OUTOFMEMORY; 977cdf0e10cSrcweir return S_OK; 978cdf0e10cSrcweir } 979cdf0e10cSrcweir 980cdf0e10cSrcweir //M------------------------------------------------------------------------- 981cdf0e10cSrcweir // 982cdf0e10cSrcweir // Method: COooFilterCF::LockServer (IClassFactory::LockServer) 983cdf0e10cSrcweir // 984cdf0e10cSrcweir // Summary: Forces/allows filter class to remain loaded/be unloaded 985cdf0e10cSrcweir // 986cdf0e10cSrcweir // Arguments: fLock 987cdf0e10cSrcweir // [in] TRUE to lock, FALSE to unlock 988cdf0e10cSrcweir // 989cdf0e10cSrcweir // Returns: S_OK 990cdf0e10cSrcweir // Always 991cdf0e10cSrcweir // E_FAIL 992cdf0e10cSrcweir // (not implemented) 993cdf0e10cSrcweir // E_OUTOFMEMORY 994cdf0e10cSrcweir // (not implemented) 995cdf0e10cSrcweir // E_UNEXPECTED 996cdf0e10cSrcweir // (not implemented) 997cdf0e10cSrcweir // 998cdf0e10cSrcweir //-------------------------------------------------------------------------- 999cdf0e10cSrcweir SCODE STDMETHODCALLTYPE COooFilterCF::LockServer(BOOL fLock) 1000cdf0e10cSrcweir { 1001cdf0e10cSrcweir if( fLock ) 1002cdf0e10cSrcweir InterlockedIncrement( &g_lInstances ); 1003cdf0e10cSrcweir else 1004cdf0e10cSrcweir InterlockedDecrement( &g_lInstances ); 1005cdf0e10cSrcweir return S_OK; 1006cdf0e10cSrcweir } 1007cdf0e10cSrcweir //+------------------------------------------------------------------------- 1008cdf0e10cSrcweir // 1009cdf0e10cSrcweir // DLL: ooofilt.dll 1010cdf0e10cSrcweir // 1011cdf0e10cSrcweir // Summary: Implements Dynamic Link Library functions for OpenOffice.org filter 1012cdf0e10cSrcweir // 1013cdf0e10cSrcweir //-------------------------------------------------------------------------- 1014cdf0e10cSrcweir //F------------------------------------------------------------------------- 1015cdf0e10cSrcweir // 1016cdf0e10cSrcweir // Function: DllMain 1017cdf0e10cSrcweir // 1018cdf0e10cSrcweir // Summary: Called from C-Runtime on process/thread attach/detach 1019cdf0e10cSrcweir // 1020cdf0e10cSrcweir // Arguments: hInstance 1021cdf0e10cSrcweir // [in] Handle to the DLL 1022cdf0e10cSrcweir // fdwReason 1023cdf0e10cSrcweir // [in] Reason for calling DLL entry point 1024cdf0e10cSrcweir // lpReserve 1025cdf0e10cSrcweir // [in] Details of DLL initialization and cleanup 1026cdf0e10cSrcweir // 1027cdf0e10cSrcweir // Returns: TRUE 1028cdf0e10cSrcweir // Always 1029cdf0e10cSrcweir // 1030cdf0e10cSrcweir //-------------------------------------------------------------------------- 1031cdf0e10cSrcweir extern "C" BOOL WINAPI DllMain( 1032cdf0e10cSrcweir HINSTANCE hInstance, 1033cdf0e10cSrcweir DWORD fdwReason, 1034cdf0e10cSrcweir LPVOID /*lpvReserved*/ 1035cdf0e10cSrcweir ) 1036cdf0e10cSrcweir { 1037cdf0e10cSrcweir if ( DLL_PROCESS_ATTACH == fdwReason ) 1038cdf0e10cSrcweir DisableThreadLibraryCalls( hInstance ); 1039cdf0e10cSrcweir return TRUE; 1040cdf0e10cSrcweir } 1041cdf0e10cSrcweir //F------------------------------------------------------------------------- 1042cdf0e10cSrcweir // 1043cdf0e10cSrcweir // Function: DllGetClassObject 1044cdf0e10cSrcweir // 1045cdf0e10cSrcweir // Summary: Create OpenOffice.org filter class factory object 1046cdf0e10cSrcweir // 1047cdf0e10cSrcweir // Arguments: cid 1048cdf0e10cSrcweir // [in] Class ID of class that class factory creates 1049cdf0e10cSrcweir // iid 1050cdf0e10cSrcweir // [in] Reference IID of requested class factory interface 1051cdf0e10cSrcweir // ppvObj 1052cdf0e10cSrcweir // [out] Address that receives requested interface pointer 1053cdf0e10cSrcweir // 1054cdf0e10cSrcweir // Returns: S_OK 1055cdf0e10cSrcweir // Class factory object was created successfully 1056cdf0e10cSrcweir // CLASS_E_CLASSNOTAVAILABLE 1057cdf0e10cSrcweir // DLL does not support the requested class 1058cdf0e10cSrcweir // E_INVALIDARG 1059cdf0e10cSrcweir // (not implemented 1060cdf0e10cSrcweir // E_OUTOFMEMORY 1061cdf0e10cSrcweir // Insufficient memory to create the class factory object 1062cdf0e10cSrcweir // E_UNEXPECTED 1063cdf0e10cSrcweir // Unsuccessful due to an unexpected condition 1064cdf0e10cSrcweir // 1065cdf0e10cSrcweir //------------------------------------------------------------------------- 1066cdf0e10cSrcweir extern "C" SCODE STDMETHODCALLTYPE DllGetClassObject( 1067cdf0e10cSrcweir REFCLSID cid, 1068cdf0e10cSrcweir REFIID iid, 1069cdf0e10cSrcweir void ** ppvObj 1070cdf0e10cSrcweir ) 1071cdf0e10cSrcweir { 1072cdf0e10cSrcweir IUnknown *pResult = 0; 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir if ( CLSID_COooFilter == cid ) 1075cdf0e10cSrcweir pResult = (IUnknown *) new COooFilterCF; 1076cdf0e10cSrcweir else 1077cdf0e10cSrcweir return CLASS_E_CLASSNOTAVAILABLE; 1078cdf0e10cSrcweir if ( 0 != pResult ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir if( SUCCEEDED( pResult->QueryInterface( iid, ppvObj ) ) ) 1081cdf0e10cSrcweir // Release extra refcount from QueryInterface 1082cdf0e10cSrcweir pResult->Release(); 1083cdf0e10cSrcweir else 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir delete pResult; 1086cdf0e10cSrcweir return E_UNEXPECTED; 1087cdf0e10cSrcweir } 1088cdf0e10cSrcweir } 1089cdf0e10cSrcweir else 1090cdf0e10cSrcweir return E_OUTOFMEMORY; 1091cdf0e10cSrcweir return S_OK; 1092cdf0e10cSrcweir } 1093cdf0e10cSrcweir //F------------------------------------------------------------------------- 1094cdf0e10cSrcweir // 1095cdf0e10cSrcweir // Function: DllCanUnloadNow 1096cdf0e10cSrcweir // 1097cdf0e10cSrcweir // Summary: Indicates whether it is possible to unload DLL 1098cdf0e10cSrcweir // 1099cdf0e10cSrcweir // Arguments: void 1100cdf0e10cSrcweir // 1101cdf0e10cSrcweir // Returns: S_OK 1102cdf0e10cSrcweir // DLL can be unloaded now 1103cdf0e10cSrcweir // S_FALSE 1104cdf0e10cSrcweir // DLL must remain loaded 1105cdf0e10cSrcweir // 1106cdf0e10cSrcweir //-------------------------------------------------------------------------- 1107cdf0e10cSrcweir extern "C" SCODE STDMETHODCALLTYPE DllCanUnloadNow() 1108cdf0e10cSrcweir { 1109cdf0e10cSrcweir if ( 0 >= g_lInstances ) 1110cdf0e10cSrcweir return S_OK; 1111cdf0e10cSrcweir else 1112cdf0e10cSrcweir return S_FALSE; 1113cdf0e10cSrcweir } 1114cdf0e10cSrcweir //F------------------------------------------------------------------------- 1115cdf0e10cSrcweir // 1116cdf0e10cSrcweir // Function: DllRegisterServer 1117cdf0e10cSrcweir // DllUnregisterServer 1118cdf0e10cSrcweir // 1119cdf0e10cSrcweir // Summary: Registers and unregisters DLL server 1120cdf0e10cSrcweir // 1121cdf0e10cSrcweir // Returns: DllRegisterServer 1122cdf0e10cSrcweir // S_OK 1123cdf0e10cSrcweir // Registration was successful 1124cdf0e10cSrcweir // SELFREG_E_CLASS 1125cdf0e10cSrcweir // Registration was unsuccessful 1126cdf0e10cSrcweir // SELFREG_E_TYPELIB 1127cdf0e10cSrcweir // (not implemented) 1128cdf0e10cSrcweir // E_OUTOFMEMORY 1129cdf0e10cSrcweir // (not implemented) 1130cdf0e10cSrcweir // E_UNEXPECTED 1131cdf0e10cSrcweir // (not implemented) 1132cdf0e10cSrcweir // DllUnregisterServer 1133cdf0e10cSrcweir // S_OK 1134cdf0e10cSrcweir // Unregistration was successful 1135cdf0e10cSrcweir // S_FALSE 1136cdf0e10cSrcweir // Unregistration was successful, but other 1137cdf0e10cSrcweir // entries still exist for the DLL's classes 1138cdf0e10cSrcweir // SELFREG_E_CLASS 1139cdf0e10cSrcweir // (not implemented) 1140cdf0e10cSrcweir // SELFREG_E_TYPELIB 1141cdf0e10cSrcweir // (not implemented) 1142cdf0e10cSrcweir // E_OUTOFMEMORY 1143cdf0e10cSrcweir // (not implemented) 1144cdf0e10cSrcweir // E_UNEXPECTED 1145cdf0e10cSrcweir // (not implemented) 1146cdf0e10cSrcweir // 1147cdf0e10cSrcweir //-------------------------------------------------------------------------- 1148cdf0e10cSrcweir 1149cdf0e10cSrcweir 1150cdf0e10cSrcweir //F------------------------------------------------------------------------- 1151cdf0e10cSrcweir // 1152cdf0e10cSrcweir // helper functions to register the Indexing Service. 1153cdf0e10cSrcweir // 1154cdf0e10cSrcweir //-------------------------------------------------------------------------- 1155cdf0e10cSrcweir 1156cdf0e10cSrcweir namespace /* private */ 1157cdf0e10cSrcweir { 1158cdf0e10cSrcweir const char* GUID_PLACEHOLDER = "{GUID}"; 1159cdf0e10cSrcweir const char* GUID_PERSIST_PLACEHOLDER = "{GUIDPERSIST}"; 1160cdf0e10cSrcweir const char* EXTENSION_PLACEHOLDER = "{EXT}"; 1161cdf0e10cSrcweir const char* FORWARDKEY_PLACEHOLDER = "{FWDKEY}"; 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir const char* CLSID_GUID_INPROC_ENTRY = "CLSID\\{GUID}\\InProcServer32"; 1164cdf0e10cSrcweir const char* CLSID_GUID_ENTRY = "CLSID\\{GUID}"; 1165cdf0e10cSrcweir const char* CLSID_GUID_PERSIST_ADDIN_ENTRY = "CLSID\\{GUID}\\PersistentAddinsRegistered\\{GUIDPERSIST}"; 1166cdf0e10cSrcweir const char* CLSID_PERSIST_ENTRY = "CLSID\\{GUID}\\PersistentHandler"; 1167cdf0e10cSrcweir const char* EXT_PERSIST_ENTRY = "{EXT}\\PersistentHandler"; 1168cdf0e10cSrcweir 1169cdf0e10cSrcweir const char* INDEXING_FILTER_DLLSTOREGISTER = "SYSTEM\\CurrentControlSet\\Control\\ContentIndex"; 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir //--------------------------- 1172cdf0e10cSrcweir // "String Placeholder" -> 1173cdf0e10cSrcweir // "String Replacement" 1174cdf0e10cSrcweir //--------------------------- 1175cdf0e10cSrcweir 1176cdf0e10cSrcweir void SubstitutePlaceholder(std::string& String, const std::string& Placeholder, const std::string& Replacement) 1177cdf0e10cSrcweir { 1178cdf0e10cSrcweir std::string::size_type idx = String.find(Placeholder); 1179cdf0e10cSrcweir std::string::size_type len = Placeholder.length(); 1180cdf0e10cSrcweir 1181cdf0e10cSrcweir while (std::string::npos != idx) 1182cdf0e10cSrcweir { 1183cdf0e10cSrcweir String.replace(idx, len, Replacement); 1184cdf0e10cSrcweir idx = String.find(Placeholder); 1185cdf0e10cSrcweir } 1186cdf0e10cSrcweir } 1187cdf0e10cSrcweir 1188cdf0e10cSrcweir //---------------------------------------------- 1189cdf0e10cSrcweir // Make the registry entry and set Filter Handler 1190cdf0e10cSrcweir // HKCR\CLSID\{7BC0E710-5703-45be-A29D-5D46D8B39262} = OpenOffice.org Filter 1191cdf0e10cSrcweir // InProcServer32 (Default) = Path\ooofilt.dll 1192cdf0e10cSrcweir // ThreadingModel = Both 1193cdf0e10cSrcweir //---------------------------------------------- 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir HRESULT RegisterFilterHandler(const char* FilePath, const CLSID& FilterGuid) 1196cdf0e10cSrcweir { 1197cdf0e10cSrcweir std::string ClsidEntry = CLSID_GUID_ENTRY; 1198cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry, GUID_PLACEHOLDER, ClsidToString(FilterGuid)); 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry.c_str(), "", "OpenOffice.org Filter")) 1201cdf0e10cSrcweir return E_FAIL; 1202cdf0e10cSrcweir 1203cdf0e10cSrcweir ClsidEntry = CLSID_GUID_INPROC_ENTRY; 1204cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry, GUID_PLACEHOLDER, ClsidToString(FilterGuid)); 1205cdf0e10cSrcweir 1206cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry.c_str(), "", FilePath)) 1207cdf0e10cSrcweir return E_FAIL; 1208cdf0e10cSrcweir 1209cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry.c_str(), "ThreadingModel", "Both")) 1210cdf0e10cSrcweir return E_FAIL; 1211cdf0e10cSrcweir 1212cdf0e10cSrcweir return S_OK; 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir //---------------------------------------------- 1216cdf0e10cSrcweir // Make the registry entry and set Persistent Handler 1217cdf0e10cSrcweir // HKCR\CLSID\{7BC0E713-5703-45be-A29D-5D46D8B39262} = OpenOffice.org Persistent Handler 1218cdf0e10cSrcweir // PersistentAddinsRegistered 1219cdf0e10cSrcweir // {89BCB740-6119-101A-BCB7-00DD010655AF} = {7BC0E710-5703-45be-A29D-5D46D8B39262} 1220cdf0e10cSrcweir //---------------------------------------------- 1221cdf0e10cSrcweir 1222cdf0e10cSrcweir HRESULT RegisterPersistentHandler(const CLSID& FilterGuid, const CLSID& PersistentGuid) 1223cdf0e10cSrcweir { 1224cdf0e10cSrcweir std::string ClsidEntry_Persist = CLSID_GUID_ENTRY; 1225cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry_Persist, GUID_PLACEHOLDER, ClsidToString(PersistentGuid)); 1226cdf0e10cSrcweir 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry_Persist.c_str(), "", "OpenOffice.org Persistent Handler")) 1229cdf0e10cSrcweir return E_FAIL; 1230cdf0e10cSrcweir 1231cdf0e10cSrcweir // Add missing entry 1232cdf0e10cSrcweir std::string ClsidEntry_Persist_Entry = CLSID_PERSIST_ENTRY; 1233cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry_Persist_Entry, 1234cdf0e10cSrcweir GUID_PLACEHOLDER, 1235cdf0e10cSrcweir ClsidToString(PersistentGuid)); 1236cdf0e10cSrcweir 1237cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry_Persist_Entry.c_str(), "", ClsidToString(PersistentGuid).c_str())) 1238cdf0e10cSrcweir return E_FAIL; 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir std::string ClsidEntry_Persist_Addin = CLSID_GUID_PERSIST_ADDIN_ENTRY; 1241cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry_Persist_Addin, 1242cdf0e10cSrcweir GUID_PLACEHOLDER, 1243cdf0e10cSrcweir ClsidToString(PersistentGuid)); 1244cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry_Persist_Addin, 1245cdf0e10cSrcweir GUID_PERSIST_PLACEHOLDER, 1246cdf0e10cSrcweir ClsidToString(CLSID_PERSISTENT_HANDLER_ADDIN)); 1247cdf0e10cSrcweir 1248cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry_Persist_Addin.c_str(), "", ClsidToString(FilterGuid).c_str() )) 1249cdf0e10cSrcweir return E_FAIL; 1250cdf0e10cSrcweir 1251cdf0e10cSrcweir return S_OK; 1252cdf0e10cSrcweir } 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir //--------------------------- 1255cdf0e10cSrcweir // Unregister Filter Handler or persistent handler 1256cdf0e10cSrcweir //--------------------------- 1257cdf0e10cSrcweir 1258cdf0e10cSrcweir HRESULT UnregisterHandler(const CLSID& Guid) 1259cdf0e10cSrcweir { 1260cdf0e10cSrcweir std::string tmp = "CLSID\\"; 1261cdf0e10cSrcweir tmp += ClsidToString(Guid); 1262cdf0e10cSrcweir return DeleteRegistryKey(HKEY_CLASSES_ROOT, tmp.c_str()) ? S_OK : E_FAIL; 1263cdf0e10cSrcweir } 1264cdf0e10cSrcweir 1265cdf0e10cSrcweir //--------------------------- 1266cdf0e10cSrcweir // Register Indexing Service ext and class. 1267cdf0e10cSrcweir // HKCR\{EXT}\PersistentHandler = {7BC0E713-5703-45be-A29D-5D46D8B39262} 1268cdf0e10cSrcweir // HKCR\{GUID\PersistentHandler = {7BC0E713-5703-45be-A29D-5D46D8B39262} 1269cdf0e10cSrcweir //--------------------------- 1270cdf0e10cSrcweir 1271cdf0e10cSrcweir HRESULT RegisterSearchHandler(const char* ModuleFileName) 1272cdf0e10cSrcweir { 1273cdf0e10cSrcweir if (FAILED(RegisterFilterHandler(ModuleFileName, CLSID_FILTER_HANDLER))) 1274cdf0e10cSrcweir return E_FAIL; 1275cdf0e10cSrcweir 1276cdf0e10cSrcweir if (FAILED(RegisterPersistentHandler(CLSID_FILTER_HANDLER, CLSID_PERSISTENT_HANDLER ))) 1277cdf0e10cSrcweir return E_FAIL; 1278cdf0e10cSrcweir 1279cdf0e10cSrcweir std::string sExtPersistEntry; 1280cdf0e10cSrcweir 1281cdf0e10cSrcweir for(size_t i = 0; i < OOFileExtensionTableSize; i++) 1282cdf0e10cSrcweir { 1283cdf0e10cSrcweir // first, register extension. 1284cdf0e10cSrcweir sExtPersistEntry = EXT_PERSIST_ENTRY; 1285cdf0e10cSrcweir SubstitutePlaceholder(sExtPersistEntry, EXTENSION_PLACEHOLDER, OOFileExtensionTable[i].ExtensionAnsi); 1286cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, 1287cdf0e10cSrcweir sExtPersistEntry.c_str(), 1288cdf0e10cSrcweir "", 1289cdf0e10cSrcweir ClsidToString(CLSID_PERSISTENT_HANDLER).c_str())) 1290cdf0e10cSrcweir return E_FAIL; 1291cdf0e10cSrcweir 1292cdf0e10cSrcweir // second, register class. 1293cdf0e10cSrcweir char extClassName[MAX_PATH]; 1294cdf0e10cSrcweir if (QueryRegistryKey(HKEY_CLASSES_ROOT, OOFileExtensionTable[i].ExtensionAnsi, "", extClassName,MAX_PATH)) 1295cdf0e10cSrcweir { 1296cdf0e10cSrcweir ::std::string extCLSIDName( extClassName ); 1297cdf0e10cSrcweir extCLSIDName += "\\CLSID"; 1298cdf0e10cSrcweir char extCLSID[MAX_PATH]; 1299cdf0e10cSrcweir 1300cdf0e10cSrcweir if (QueryRegistryKey( HKEY_CLASSES_ROOT, extCLSIDName.c_str(), "", extCLSID, MAX_PATH)) 1301cdf0e10cSrcweir { 1302cdf0e10cSrcweir std::string ClsidEntry_CLSID_Persist = CLSID_PERSIST_ENTRY; 1303cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry_CLSID_Persist, 1304cdf0e10cSrcweir GUID_PLACEHOLDER, 1305cdf0e10cSrcweir extCLSID); 1306cdf0e10cSrcweir 1307cdf0e10cSrcweir if (!SetRegistryKey(HKEY_CLASSES_ROOT, 1308cdf0e10cSrcweir ClsidEntry_CLSID_Persist.c_str(), 1309cdf0e10cSrcweir "", 1310cdf0e10cSrcweir ClsidToString(CLSID_PERSISTENT_HANDLER).c_str() )) 1311cdf0e10cSrcweir return E_FAIL; 1312cdf0e10cSrcweir } 1313cdf0e10cSrcweir } 1314cdf0e10cSrcweir } 1315cdf0e10cSrcweir 1316cdf0e10cSrcweir return S_OK; 1317cdf0e10cSrcweir } 1318cdf0e10cSrcweir 1319cdf0e10cSrcweir // Register Indexing Service ext and class. 1320cdf0e10cSrcweir HRESULT UnregisterSearchHandler() 1321cdf0e10cSrcweir { 1322cdf0e10cSrcweir std::string sExtPersistEntry; 1323cdf0e10cSrcweir 1324cdf0e10cSrcweir for (size_t i = 0; i < OOFileExtensionTableSize; i++) 1325cdf0e10cSrcweir { 1326cdf0e10cSrcweir // first, unregister extension 1327cdf0e10cSrcweir sExtPersistEntry = EXT_PERSIST_ENTRY; 1328cdf0e10cSrcweir SubstitutePlaceholder(sExtPersistEntry, EXTENSION_PLACEHOLDER, OOFileExtensionTable[i].ExtensionAnsi); 1329cdf0e10cSrcweir DeleteRegistryKey(HKEY_CLASSES_ROOT, sExtPersistEntry.c_str()); 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir // second, unregister class 1332cdf0e10cSrcweir char extClassName[MAX_PATH]; 1333cdf0e10cSrcweir if (QueryRegistryKey(HKEY_CLASSES_ROOT, OOFileExtensionTable[i].ExtensionAnsi, "", extClassName,MAX_PATH)) 1334cdf0e10cSrcweir { 1335cdf0e10cSrcweir ::std::string extCLSIDName( extClassName ); 1336cdf0e10cSrcweir extCLSIDName += "\\CLSID"; 1337cdf0e10cSrcweir char extCLSID[MAX_PATH]; 1338cdf0e10cSrcweir 1339cdf0e10cSrcweir if (QueryRegistryKey( HKEY_CLASSES_ROOT, extCLSIDName.c_str(), "", extCLSID, MAX_PATH)) 1340cdf0e10cSrcweir { 1341cdf0e10cSrcweir std::string ClsidEntry_CLSID_Persist = CLSID_PERSIST_ENTRY; 1342cdf0e10cSrcweir SubstitutePlaceholder(ClsidEntry_CLSID_Persist, 1343cdf0e10cSrcweir GUID_PLACEHOLDER, 1344cdf0e10cSrcweir extCLSID); 1345cdf0e10cSrcweir 1346cdf0e10cSrcweir DeleteRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry_CLSID_Persist.c_str()); 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir } 1349cdf0e10cSrcweir } 1350cdf0e10cSrcweir 1351cdf0e10cSrcweir return ((UnregisterHandler(CLSID_FILTER_HANDLER)==S_OK) && (UnregisterHandler(CLSID_PERSISTENT_HANDLER)==S_OK))?S_OK:E_FAIL; 1352cdf0e10cSrcweir } 1353cdf0e10cSrcweir 1354cdf0e10cSrcweir //--------------------------- 1355cdf0e10cSrcweir // add or remove an entry to DllsToRegister entry of Indexing 1356cdf0e10cSrcweir // Filter to let Indexing Service register our filter automatically 1357cdf0e10cSrcweir // each time. 1358cdf0e10cSrcweir //--------------------------- 1359cdf0e10cSrcweir HRESULT AddOrRemoveDllsToRegisterList( const ::std::string & DllPath, bool isAdd ) 1360cdf0e10cSrcweir { 1361cdf0e10cSrcweir char DllsToRegisterList[4096]; 1362cdf0e10cSrcweir if (QueryRegistryKey(HKEY_LOCAL_MACHINE, 1363cdf0e10cSrcweir INDEXING_FILTER_DLLSTOREGISTER, 1364cdf0e10cSrcweir "DLLsToRegister", 1365cdf0e10cSrcweir DllsToRegisterList, 1366cdf0e10cSrcweir 4096)) 1367cdf0e10cSrcweir { 1368cdf0e10cSrcweir char * pChar = DllsToRegisterList; 1369cdf0e10cSrcweir for ( ; *pChar != '\0' || *(pChar +1) != '\0'; pChar++) 1370cdf0e10cSrcweir if ( *pChar == '\0') 1371cdf0e10cSrcweir *pChar = ';'; 1372cdf0e10cSrcweir *pChar = ';'; 1373cdf0e10cSrcweir *(pChar+1) = '\0'; 1374cdf0e10cSrcweir 1375cdf0e10cSrcweir ::std::string DllList(DllsToRegisterList); 1376cdf0e10cSrcweir if ( ( isAdd )&&( DllList.find( DllPath ) == ::std::string::npos ) ) 1377cdf0e10cSrcweir DllList.append( DllPath ); 1378cdf0e10cSrcweir else if ( ( !isAdd )&&( DllList.find( DllPath ) != ::std::string::npos ) ) 1379cdf0e10cSrcweir DllList.erase( DllList.find( DllPath )-1, DllPath.length()+1 ); 1380cdf0e10cSrcweir else 1381cdf0e10cSrcweir return S_OK; 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir pChar = DllsToRegisterList; 1384cdf0e10cSrcweir for ( size_t nChar = 0; nChar < DllList.length(); pChar++,nChar++) 1385cdf0e10cSrcweir { 1386cdf0e10cSrcweir if ( DllList[nChar] == ';') 1387cdf0e10cSrcweir *pChar = '\0'; 1388cdf0e10cSrcweir else 1389cdf0e10cSrcweir *pChar = DllList[nChar]; 1390cdf0e10cSrcweir } 1391cdf0e10cSrcweir *pChar = *( pChar+1 ) ='\0'; 1392cdf0e10cSrcweir 1393cdf0e10cSrcweir HKEY hSubKey; 1394cdf0e10cSrcweir int rc = RegCreateKeyExA(HKEY_LOCAL_MACHINE, 1395cdf0e10cSrcweir INDEXING_FILTER_DLLSTOREGISTER, 1396cdf0e10cSrcweir 0, 1397cdf0e10cSrcweir "", 1398cdf0e10cSrcweir REG_OPTION_NON_VOLATILE, 1399cdf0e10cSrcweir KEY_WRITE, 1400cdf0e10cSrcweir 0, 1401cdf0e10cSrcweir &hSubKey, 1402cdf0e10cSrcweir 0); 1403cdf0e10cSrcweir 1404cdf0e10cSrcweir if (ERROR_SUCCESS == rc) 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir rc = RegSetValueExA( hSubKey, 1407cdf0e10cSrcweir "DLLsToRegister", 1408cdf0e10cSrcweir 0, 1409cdf0e10cSrcweir REG_MULTI_SZ, 1410cdf0e10cSrcweir reinterpret_cast<const BYTE*>(DllsToRegisterList), 1411cdf0e10cSrcweir DllList.length() + 2); 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir RegCloseKey(hSubKey); 1414cdf0e10cSrcweir } 1415cdf0e10cSrcweir 1416cdf0e10cSrcweir return (ERROR_SUCCESS == rc)?S_OK:E_FAIL; 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir 1419cdf0e10cSrcweir return S_OK; 1420cdf0e10cSrcweir } 1421cdf0e10cSrcweir 1422cdf0e10cSrcweir } // namespace /* private */ 1423cdf0e10cSrcweir 1424cdf0e10cSrcweir STDAPI DllRegisterServer() 1425cdf0e10cSrcweir { 1426cdf0e10cSrcweir /* 1427cdf0e10cSrcweir TCHAR ModuleFileName[MAX_PATH]; 1428cdf0e10cSrcweir 1429cdf0e10cSrcweir GetModuleFileName( 1430cdf0e10cSrcweir GetModuleHandle(MODULE_NAME_FILTER), 1431cdf0e10cSrcweir ModuleFileName, 1432cdf0e10cSrcweir sizeof(ModuleFileName)); 1433cdf0e10cSrcweir 1434cdf0e10cSrcweir HRESULT hr = S_OK; 1435cdf0e10cSrcweir 1436cdf0e10cSrcweir 1437cdf0e10cSrcweir // register search handler 1438cdf0e10cSrcweir #ifdef UNICODE 1439cdf0e10cSrcweir if (FAILED(RegisterSearchHandler(WStringToString(ModuleFileName).c_str()))) 1440cdf0e10cSrcweir hr = E_FAIL; 1441cdf0e10cSrcweir if (FAILED(AddOrRemoveDllsToRegisterList(WStringToString(ModuleFileName).c_str(), true))) 1442cdf0e10cSrcweir hr = E_FAIL; 1443cdf0e10cSrcweir #else 1444cdf0e10cSrcweir if (FAILED(RegisterSearchHandler(ModuleFileName))) 1445cdf0e10cSrcweir hr = E_FAIL; 1446cdf0e10cSrcweir if (FAILED(AddOrRemoveDllsToRegisterList(ModuleFileName, true))) 1447cdf0e10cSrcweir hr = E_FAIL; 1448cdf0e10cSrcweir #endif 1449cdf0e10cSrcweir 1450cdf0e10cSrcweir 1451cdf0e10cSrcweir return hr; 1452cdf0e10cSrcweir */ 1453cdf0e10cSrcweir return S_OK; 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir 1456cdf0e10cSrcweir //--------------------------- 1457cdf0e10cSrcweir // 1458cdf0e10cSrcweir //--------------------------- 1459cdf0e10cSrcweir 1460cdf0e10cSrcweir STDAPI DllUnregisterServer() 1461cdf0e10cSrcweir { 1462cdf0e10cSrcweir /* 1463cdf0e10cSrcweir TCHAR ModuleFileName[MAX_PATH]; 1464cdf0e10cSrcweir 1465cdf0e10cSrcweir GetModuleFileName( 1466cdf0e10cSrcweir GetModuleHandle(MODULE_NAME_FILTER), 1467cdf0e10cSrcweir ModuleFileName, 1468cdf0e10cSrcweir sizeof(ModuleFileName)); 1469cdf0e10cSrcweir 1470cdf0e10cSrcweir HRESULT hr = S_OK; 1471cdf0e10cSrcweir 1472cdf0e10cSrcweir // unregister search handler 1473cdf0e10cSrcweir if (FAILED(UnregisterSearchHandler())) 1474cdf0e10cSrcweir hr = E_FAIL; 1475cdf0e10cSrcweir 1476cdf0e10cSrcweir #ifdef UNICODE 1477cdf0e10cSrcweir if (FAILED(AddOrRemoveDllsToRegisterList(WStringToString(ModuleFileName).c_str(),false))) 1478cdf0e10cSrcweir hr = E_FAIL; 1479cdf0e10cSrcweir #else 1480cdf0e10cSrcweir if (FAILED(AddOrRemoveDllsToRegisterList(ModuleFileName, false))) 1481cdf0e10cSrcweir hr = E_FAIL; 1482cdf0e10cSrcweir #endif 1483cdf0e10cSrcweir 1484cdf0e10cSrcweir return hr; 1485cdf0e10cSrcweir */ 1486cdf0e10cSrcweir return S_OK; 1487cdf0e10cSrcweir } 1488