Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
5.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2001.
  5. //
  6. // File: nullstem.hxx
  7. //
  8. // Contents: Null stemmer. MSSearch in SQL and Exchange has a bug where
  9. // if a wordbreaker is defined and no stemmer is defined it
  10. // trashes memory and AVs. This is a workaround since CH
  11. // languages resources out of the box no longer define stemmers.
  12. //
  13. // Classes: CNullStemmer
  14. //
  15. // History: 7-Jun-01 dlee Created
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. extern long gulcInstances;
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Class: CNullStemmer
  23. //
  24. // Purpose: Returns the word passed in. Needed for backward
  25. // compatibility with SQL Server and Exchange 2000.
  26. //
  27. // History: 7-Jun-01 dlee Created
  28. //
  29. //----------------------------------------------------------------------------
  30. class CNullStemmer : public IStemmer
  31. {
  32. public:
  33. SCODE STDMETHODCALLTYPE QueryInterface( REFIID riid,
  34. void **ppvObject )
  35. {
  36. if ( 0 == ppvObject )
  37. return E_INVALIDARG;
  38. if ( IID_IStemmer == riid )
  39. *ppvObject = (IUnknown *)(IStemmer *) this;
  40. else if ( IID_IUnknown == riid )
  41. *ppvObject = (IUnknown *) this;
  42. else
  43. {
  44. *ppvObject = 0;
  45. return E_NOINTERFACE;
  46. }
  47. AddRef();
  48. return S_OK;
  49. }
  50. ULONG STDMETHODCALLTYPE AddRef()
  51. {
  52. return InterlockedIncrement( &_cRefs );
  53. }
  54. ULONG STDMETHODCALLTYPE Release()
  55. {
  56. unsigned long c = InterlockedDecrement( &_cRefs );
  57. if ( 0 == c )
  58. delete this;
  59. return c;
  60. }
  61. SCODE STDMETHODCALLTYPE Init( ULONG ulMaxTokenSize, BOOL *pfLicense )
  62. {
  63. if ( 0 == pfLicense )
  64. return E_INVALIDARG;
  65. *pfLicense = TRUE;
  66. return S_OK;
  67. }
  68. SCODE STDMETHODCALLTYPE GetLicenseToUse( const WCHAR **ppwcsLicense )
  69. {
  70. if ( 0 == ppwcsLicense )
  71. return E_INVALIDARG;
  72. *ppwcsLicense = L"Copyright Microsoft, 1991-2001";
  73. return S_OK;
  74. }
  75. SCODE STDMETHODCALLTYPE StemWord( WCHAR const *pwcInBuf, ULONG cwc, IStemSink *pStemSink )
  76. {
  77. if ( 0 == pwcInBuf || 0 == pStemSink )
  78. return E_INVALIDARG;
  79. return pStemSink->PutWord( pwcInBuf, cwc );
  80. }
  81. CNullStemmer() : _cRefs( 1 )
  82. {
  83. InterlockedIncrement( &gulcInstances );
  84. }
  85. ~CNullStemmer()
  86. {
  87. InterlockedDecrement( &gulcInstances );
  88. }
  89. private:
  90. long _cRefs;
  91. };
  92. //+---------------------------------------------------------------------------
  93. //
  94. // Class: CDefWordBreakerCF
  95. //
  96. // Purpose: Class factory for default word breaker
  97. //
  98. // History: 07-Feb-95 SitaramR Created
  99. //
  100. //----------------------------------------------------------------------------
  101. class CNullStemmerCF : public IClassFactory
  102. {
  103. public:
  104. CNullStemmerCF() : _cRefs( 1 )
  105. {
  106. InterlockedIncrement( &gulcInstances );
  107. }
  108. //
  109. // From IUnknown
  110. //
  111. SCODE STDMETHODCALLTYPE QueryInterface( REFIID riid,
  112. void ** ppvObject )
  113. {
  114. if ( 0 == ppvObject )
  115. return E_INVALIDARG;
  116. if ( IID_IClassFactory == riid )
  117. *ppvObject = (IUnknown *)(IClassFactory *)this;
  118. else if ( IID_IUnknown == riid )
  119. *ppvObject = (IUnknown *)this;
  120. else
  121. {
  122. *ppvObject = 0;
  123. return E_NOINTERFACE;
  124. }
  125. AddRef();
  126. return S_OK;
  127. }
  128. ULONG STDMETHODCALLTYPE AddRef()
  129. {
  130. return InterlockedIncrement( &_cRefs );
  131. }
  132. ULONG STDMETHODCALLTYPE Release()
  133. {
  134. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  135. if ( 0 == uTmp )
  136. delete this;
  137. return uTmp;
  138. }
  139. //
  140. // From IClassFactory
  141. //
  142. SCODE STDMETHODCALLTYPE CreateInstance( IUnknown * pUnkOuter,
  143. REFIID riid,
  144. void ** ppvObject )
  145. {
  146. if ( 0 == ppvObject )
  147. return E_INVALIDARG;
  148. CNullStemmer *pIUnk = 0;
  149. SCODE sc = S_OK;
  150. TRY
  151. {
  152. pIUnk = new CNullStemmer();
  153. sc = pIUnk->QueryInterface( riid , ppvObject );
  154. pIUnk->Release(); // Release extra refcount from QueryInterface
  155. }
  156. CATCH(CException, e)
  157. {
  158. Win4Assert( 0 == pIUnk );
  159. sc = e.GetErrorCode();
  160. }
  161. END_CATCH;
  162. return sc;
  163. }
  164. SCODE STDMETHODCALLTYPE LockServer( BOOL fLock )
  165. {
  166. if ( fLock )
  167. InterlockedIncrement( &gulcInstances );
  168. else
  169. InterlockedDecrement( &gulcInstances );
  170. return S_OK;
  171. }
  172. private:
  173. virtual ~CNullStemmerCF()
  174. {
  175. InterlockedDecrement( &gulcInstances );
  176. }
  177. long _cRefs;
  178. };