Leaked source code of windows server 2003
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.

227 lines
5.3 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 GenerateWordForms(
  76. WCHAR const *pwcInBuf,
  77. ULONG cwc,
  78. IWordFormSink *pStemSink )
  79. {
  80. if ( 0 == pwcInBuf || 0 == pStemSink )
  81. return E_INVALIDARG;
  82. return pStemSink->PutWord( pwcInBuf, cwc );
  83. }
  84. CNullStemmer() : _cRefs( 1 )
  85. {
  86. InterlockedIncrement( &gulcInstances );
  87. }
  88. ~CNullStemmer()
  89. {
  90. InterlockedDecrement( &gulcInstances );
  91. }
  92. private:
  93. long _cRefs;
  94. };
  95. //+---------------------------------------------------------------------------
  96. //
  97. // Class: CDefWordBreakerCF
  98. //
  99. // Purpose: Class factory for default word breaker
  100. //
  101. // History: 07-Feb-95 SitaramR Created
  102. //
  103. //----------------------------------------------------------------------------
  104. class CNullStemmerCF : public IClassFactory
  105. {
  106. public:
  107. CNullStemmerCF() : _cRefs( 1 )
  108. {
  109. InterlockedIncrement( &gulcInstances );
  110. }
  111. //
  112. // From IUnknown
  113. //
  114. SCODE STDMETHODCALLTYPE QueryInterface( REFIID riid,
  115. void ** ppvObject )
  116. {
  117. if ( 0 == ppvObject )
  118. return E_INVALIDARG;
  119. if ( IID_IClassFactory == riid )
  120. *ppvObject = (IUnknown *)(IClassFactory *)this;
  121. else if ( IID_IUnknown == riid )
  122. *ppvObject = (IUnknown *)this;
  123. else
  124. {
  125. *ppvObject = 0;
  126. return E_NOINTERFACE;
  127. }
  128. AddRef();
  129. return S_OK;
  130. }
  131. ULONG STDMETHODCALLTYPE AddRef()
  132. {
  133. return InterlockedIncrement( &_cRefs );
  134. }
  135. ULONG STDMETHODCALLTYPE Release()
  136. {
  137. unsigned long uTmp = InterlockedDecrement( &_cRefs );
  138. if ( 0 == uTmp )
  139. delete this;
  140. return uTmp;
  141. }
  142. //
  143. // From IClassFactory
  144. //
  145. SCODE STDMETHODCALLTYPE CreateInstance( IUnknown * pUnkOuter,
  146. REFIID riid,
  147. void ** ppvObject )
  148. {
  149. if ( 0 == ppvObject )
  150. return E_INVALIDARG;
  151. CNullStemmer *pIUnk = 0;
  152. SCODE sc = S_OK;
  153. TRY
  154. {
  155. pIUnk = new CNullStemmer();
  156. sc = pIUnk->QueryInterface( riid , ppvObject );
  157. pIUnk->Release(); // Release extra refcount from QueryInterface
  158. }
  159. CATCH(CException, e)
  160. {
  161. Win4Assert( 0 == pIUnk );
  162. sc = e.GetErrorCode();
  163. }
  164. END_CATCH;
  165. return sc;
  166. }
  167. SCODE STDMETHODCALLTYPE LockServer( BOOL fLock )
  168. {
  169. if ( fLock )
  170. InterlockedIncrement( &gulcInstances );
  171. else
  172. InterlockedDecrement( &gulcInstances );
  173. return S_OK;
  174. }
  175. private:
  176. virtual ~CNullStemmerCF()
  177. {
  178. InterlockedDecrement( &gulcInstances );
  179. }
  180. long _cRefs;
  181. };