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.

1374 lines
39 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: IRest.cxx
  7. //
  8. // Contents: Internal (non-public) restrictions.
  9. //
  10. // Classes: CInternalPropertyRestriction
  11. // COccRestriction
  12. // CWordRestriction
  13. // CSynRestriction
  14. // CRangeRestriction
  15. // CUnfilteredRestriction
  16. // CScopeRestriction
  17. // CPhraseRestriction
  18. //
  19. // History: 19-Sep-91 BartoszM Implemented.
  20. // 29-Aug-92 MikeHew Added serialization routines
  21. // 30-Nov-92 KyleP Removed CPhraseXpr
  22. // 14-Jan-93 KyleP Converted from expressions
  23. //
  24. //----------------------------------------------------------------------------
  25. #include <pch.cxx>
  26. #pragma hdrstop
  27. #include <vkrep.hxx>
  28. #include <norm.hxx>
  29. #include <compare.hxx>
  30. //+-------------------------------------------------------------------------
  31. //
  32. // Function: UnMarshallWideString
  33. //
  34. // Synopsis: Unmarshalls a wide string into a CoTaskMemAlloc'ed buffer.
  35. // This can't be in memdeser since it calls CoTaskMemAlloc,
  36. // which isn't available in ntdll.dll.
  37. //
  38. // Arguments: [stm] -- stream from which string is deserialized
  39. //
  40. // History: 22-Nov-95 dlee Created from a few copies
  41. //
  42. //--------------------------------------------------------------------------
  43. WCHAR * UnMarshallWideString( PDeSerStream & stm )
  44. {
  45. ULONG cc = stm.GetULong();
  46. // Protect against attack. We know our named pipes are < 64k
  47. if ( cc >= ( 65536 / sizeof WCHAR ) )
  48. return 0;
  49. XCoMem<WCHAR> xString( (WCHAR *) CoTaskMemAlloc( (cc + 1) * sizeof WCHAR ) );
  50. if ( xString.IsNull() )
  51. {
  52. // just eat the string
  53. WCHAR wc[10];
  54. while ( cc > 0 )
  55. {
  56. if ( cc >= 10 )
  57. {
  58. stm.GetWChar( wc, 10 );
  59. cc -= 10;
  60. }
  61. else
  62. {
  63. stm.GetWChar( wc, cc );
  64. cc = 0;
  65. }
  66. }
  67. }
  68. else
  69. {
  70. WCHAR * pwc = xString.GetPointer();
  71. stm.GetWChar( pwc, cc );
  72. pwc[cc] = 0;
  73. }
  74. return xString.Acquire();
  75. } //UnMarshallWideString
  76. WCHAR * UnMarshallWideStringNew( PDeSerStream & stm )
  77. {
  78. ULONG cc = stm.GetULong();
  79. // Protect against attack. We know our named pipes are < 64k
  80. if ( cc >= ( 65536 / sizeof WCHAR ) )
  81. THROW( CException( E_INVALIDARG ) );
  82. XArray<WCHAR> xString( cc + 1 );
  83. stm.GetWChar( xString.GetPointer(), cc );
  84. xString[cc] = 0;
  85. return xString.Acquire();
  86. } //UnMarshallWideStringNew
  87. //+-------------------------------------------------------------------------
  88. //
  89. // Member: CInternalPropertyRestriction::CInternalPropertyRestriction
  90. //
  91. // Synopsis: Creates property restriction
  92. //
  93. // Arguments: [relop] -- Relational operator (<, >, etc.)
  94. // [pid] -- Property id
  95. // [prval] -- Property value
  96. // [pcrst] -- 'Helper' content restriction
  97. //
  98. // History: 07-Mar-93 KyleP Created
  99. //
  100. //--------------------------------------------------------------------------
  101. CInternalPropertyRestriction::CInternalPropertyRestriction( ULONG relop,
  102. PROPID pid,
  103. CStorageVariant const & prval,
  104. CRestriction * pcrst )
  105. : CRestriction( RTInternalProp, MAX_QUERY_RANK ),
  106. _relop( relop ),
  107. _pid( pid ),
  108. _prval( prval ),
  109. _pcrst( pcrst )
  110. {
  111. if ( !_prval.IsValid() )
  112. THROW( CException( E_OUTOFMEMORY ) );
  113. }
  114. //+---------------------------------------------------------------------------
  115. //
  116. // Member: CInternalPropertyRestriction::CInternalPropertyRestriction
  117. //
  118. // Synopsis: Copy constructor
  119. //
  120. // History: 30-May-95 SitaramR Created.
  121. //
  122. //----------------------------------------------------------------------------
  123. CInternalPropertyRestriction::CInternalPropertyRestriction(
  124. CInternalPropertyRestriction const & intPropRst )
  125. : CRestriction( RTInternalProp, intPropRst.Weight() ),
  126. _relop( intPropRst.Relation() ),
  127. _pid( intPropRst.Pid() ),
  128. _prval( intPropRst.Value() ),
  129. _pcrst( 0 )
  130. {
  131. if ( !_prval.IsValid() )
  132. THROW( CException( E_OUTOFMEMORY ) );
  133. CRestriction *pHelperRst = intPropRst.GetContentHelper();
  134. if ( pHelperRst )
  135. _pcrst = pHelperRst->Clone();
  136. }
  137. //+-------------------------------------------------------------------------
  138. //
  139. // Member: CInternalPropertyRestriction::~CInternalPropertyRestriction
  140. //
  141. // Synopsis: Cleanup restriction
  142. //
  143. // History: 01-Feb-93 KyleP Created
  144. //
  145. //--------------------------------------------------------------------------
  146. CInternalPropertyRestriction::~CInternalPropertyRestriction()
  147. {
  148. delete _pcrst;
  149. SetType( RTNone ); // Avoid recursion.
  150. }
  151. void CInternalPropertyRestriction::Marshall( PSerStream & stm ) const
  152. {
  153. stm.PutULong( _relop );
  154. stm.PutULong( _pid );
  155. _prval.Marshall( stm );
  156. if ( 0 == _pcrst )
  157. stm.PutByte( 0 );
  158. else
  159. {
  160. stm.PutByte( 1 );
  161. _pcrst->Marshall( stm );
  162. }
  163. }
  164. CInternalPropertyRestriction::CInternalPropertyRestriction( ULONG ulWeight,
  165. PDeSerStream & stm )
  166. : CRestriction( RTInternalProp, ulWeight ),
  167. _relop( stm.GetULong() ),
  168. _pid( stm.GetULong() ),
  169. _prval( stm )
  170. {
  171. if ( !_prval.IsValid() )
  172. THROW( CException( E_OUTOFMEMORY ) );
  173. BYTE fRst = stm.GetByte();
  174. if ( fRst )
  175. _pcrst = CRestriction::UnMarshall( stm );
  176. else
  177. _pcrst = 0;
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // Member: CInternalPropertyRestriction::Clone, public
  182. //
  183. // Synopsis: Clones an internal property restriction
  184. //
  185. // History: 30-May-95 SitaramR Created.
  186. //
  187. //----------------------------------------------------------------------------
  188. CInternalPropertyRestriction *CInternalPropertyRestriction::Clone() const
  189. {
  190. return new CInternalPropertyRestriction( *this );
  191. }
  192. //+---------------------------------------------------------------------------
  193. //
  194. // Member: COccRestriction::COccRestriction, public
  195. //
  196. // Synopsis: Creates occurrence restriction
  197. //
  198. // Arguments: [ulType] -- type of restriction
  199. // [ulWeight] -- weight
  200. // [occ] -- occurrence
  201. // [cPrevNoiseWords] -- count of previous noise words skipped
  202. // [cPostNoiseWords] -- count of post noise words skipped
  203. //
  204. // History: 29-Nov-94 SitaramR Created.
  205. //
  206. //----------------------------------------------------------------------------
  207. COccRestriction::COccRestriction( ULONG ulType, ULONG ulWeight, OCCURRENCE occ,
  208. ULONG cPrevNoiseWords, ULONG cPostNoiseWords )
  209. : CRestriction( ulType, ulWeight ),
  210. _occ( occ ),
  211. _cPrevNoiseWords( cPrevNoiseWords),
  212. _cPostNoiseWords( cPostNoiseWords )
  213. {
  214. }
  215. //+-------------------------------------------------------------------------
  216. //
  217. // Member: COccRestriction::~COccRestriction, public
  218. //
  219. // Synopsis: Cleanup occurrence restriction
  220. //
  221. // Notes: This destructor simulates virtual destruction.
  222. //
  223. // Classes derived from COccRestriction must be sure to set their
  224. // restriction type to RTNone in their destructor, so when the
  225. // base destructor below is called the derived destructor is
  226. // not called a second time.
  227. //
  228. // History: 29-Nov-94 SitaramR Created
  229. //
  230. //--------------------------------------------------------------------------
  231. COccRestriction::~COccRestriction()
  232. {
  233. switch ( Type() )
  234. {
  235. case RTNone:
  236. break;
  237. case RTWord:
  238. ((CWordRestriction *)this)->CWordRestriction::~CWordRestriction();
  239. break;
  240. case RTSynonym:
  241. ((CSynRestriction *)this)->CSynRestriction::~CSynRestriction();
  242. break;
  243. default:
  244. ciDebugOut(( DEB_ERROR, "Unhandled child (%d) of class COccRestriction\n",
  245. Type() ));
  246. Win4Assert( !"Unhandled child of class COccRestriction" );
  247. break;
  248. }
  249. }
  250. //+-------------------------------------------------------------------------
  251. //
  252. // Member: COccRestriction::IsValid(), public
  253. //
  254. // History: 14-Nov-95 KyleP Created
  255. //
  256. // Returns: TRUE if all memory allocations, etc. succeeded.
  257. //
  258. //--------------------------------------------------------------------------
  259. BOOL COccRestriction::IsValid() const
  260. {
  261. BOOL fValid = TRUE;
  262. switch ( Type() )
  263. {
  264. case RTWord:
  265. fValid = ((CWordRestriction *)this)->CWordRestriction::IsValid();
  266. break;
  267. case RTSynonym:
  268. fValid = ((CSynRestriction *)this)->CSynRestriction::IsValid();
  269. break;
  270. default:
  271. ciDebugOut(( DEB_ERROR, "Unhandled child (%d) of class COccRestriction\n",
  272. Type() ));
  273. Win4Assert( !"Unhandled child of class COccRestriction" );
  274. fValid = FALSE;
  275. break;
  276. }
  277. return fValid;
  278. }
  279. //+-------------------------------------------------------------------------
  280. //
  281. // Member: COccRestriction::Marshall, public
  282. //
  283. // Synopsis: Serialize occurrence restriction
  284. //
  285. // Arguments: [stm] -- stream to serialize to
  286. //
  287. // History: 29-Nov-94 SitaramR Created
  288. //
  289. //--------------------------------------------------------------------------
  290. void COccRestriction::Marshall( PSerStream& stm ) const
  291. {
  292. stm.PutULong( _occ );
  293. stm.PutULong( _cPrevNoiseWords );
  294. stm.PutULong( _cPostNoiseWords );
  295. switch ( Type() )
  296. {
  297. case RTWord:
  298. ((CWordRestriction *)this)->Marshall( stm );
  299. break;
  300. case RTSynonym:
  301. ((CSynRestriction *)this)->Marshall( stm );
  302. break;
  303. default:
  304. ciDebugOut(( DEB_ERROR, "Unhandled child (%d) of class COccRestriction\n",
  305. Type() ));
  306. Win4Assert( !"Unhandled child of class COccRestriction" );
  307. break;
  308. }
  309. }
  310. //+-------------------------------------------------------------------------
  311. //
  312. // Member: COccRestriction::COccRestriction, public
  313. //
  314. // Synopsis: De-serialize occurrence restriction
  315. //
  316. // Arguments: [ulType] -- type of occurrence restriction
  317. // [ulWeight] -- weight of occurrence restriction
  318. // [stm] -- stream to serialize from
  319. //
  320. // History: 29-Nov-94 SitaramR Created
  321. //
  322. //--------------------------------------------------------------------------
  323. COccRestriction::COccRestriction( ULONG ulType, ULONG ulWeight, PDeSerStream& stm )
  324. : CRestriction( ulType, ulWeight )
  325. {
  326. _occ = stm.GetULong();
  327. _cPrevNoiseWords = stm.GetULong();
  328. _cPostNoiseWords = stm.GetULong();
  329. }
  330. //+-------------------------------------------------------------------------
  331. //
  332. // Member: COccRestriction::Clone, public
  333. //
  334. // Synopsis: Clone occurrence restriction
  335. //
  336. // History: 29-Nov-94 SitaramR Created
  337. //
  338. //--------------------------------------------------------------------------
  339. COccRestriction *COccRestriction::Clone() const
  340. {
  341. switch ( Type() )
  342. {
  343. case RTWord:
  344. return ((CWordRestriction *)this)->Clone();
  345. break;
  346. case RTSynonym:
  347. return ((CSynRestriction *)this)->Clone();
  348. break;
  349. default:
  350. ciDebugOut(( DEB_ERROR, "Unhandled child (%d) of class COccRestriction\n",
  351. Type() ));
  352. Win4Assert( !"Unhandled child of class COccRestriction" );
  353. return 0;
  354. break;
  355. }
  356. }
  357. //+---------------------------------------------------------------------------
  358. //
  359. // Member: CWordRestriction::CWordRestriction, public
  360. //
  361. // Synopsis: Creates word expression
  362. //
  363. // Arguments: [keyBuf] -- key to be matched
  364. // [occ] -- occurrence (if in phrase)
  365. // [isRange] -- TRUE if key is a prefix
  366. //
  367. // History: 19-Sep-91 BartoszM Created.
  368. //
  369. //----------------------------------------------------------------------------
  370. CWordRestriction::CWordRestriction ( const CKeyBuf& keyBuf,
  371. OCCURRENCE occ,
  372. ULONG cPrevNoiseWords,
  373. ULONG cPostNoiseWords,
  374. BOOL isRange )
  375. : COccRestriction( RTWord, MAX_QUERY_RANK, occ, cPrevNoiseWords, cPostNoiseWords ),
  376. _isRange(isRange)
  377. {
  378. // copy after init to 0 in case new fails and ~CWordRestriction is
  379. // called from ~CRestriction
  380. _key = keyBuf;
  381. }
  382. //+---------------------------------------------------------------------------
  383. //
  384. // Member: CWordRestriction::CWordRestriction, public
  385. //
  386. // Synopsis: Copy constuctor
  387. //
  388. // Arguments: [wordRst] -- word restriction to be copied
  389. //
  390. // History: 29-Nov-94 SitaramR Created.
  391. //
  392. //----------------------------------------------------------------------------
  393. CWordRestriction::CWordRestriction( const CWordRestriction& wordRst )
  394. : COccRestriction( RTWord, wordRst.Weight(), wordRst.Occurrence(),
  395. wordRst.CountPrevNoiseWords(), wordRst.CountPostNoiseWords() ),
  396. _isRange( wordRst.IsRange() )
  397. {
  398. // copy after init to 0 in case new fails and ~CWordRestriction is
  399. // called from ~CRestriction
  400. _key = *wordRst.GetKey();
  401. }
  402. //+-------------------------------------------------------------------------
  403. //
  404. // Member: CWordRestriction::~CWordRestriction, public
  405. //
  406. // Synopsis: Cleanup restriction
  407. //
  408. // History: 01-Feb-93 KyleP Created
  409. //
  410. //--------------------------------------------------------------------------
  411. CWordRestriction::~CWordRestriction()
  412. {
  413. SetType( RTNone ); // Avoid recursion.
  414. }
  415. void CWordRestriction::Marshall( PSerStream & stm ) const
  416. {
  417. _key.Marshall( stm );
  418. stm.PutByte( (BYTE)_isRange );
  419. }
  420. CWordRestriction::CWordRestriction( ULONG ulWeight, PDeSerStream & stm )
  421. : COccRestriction( RTWord, ulWeight, stm ),
  422. _key( stm ),
  423. _isRange( stm.GetByte() )
  424. {
  425. }
  426. //+---------------------------------------------------------------------------
  427. //
  428. // Member: CWordRestriction::Clone, public
  429. //
  430. // Synopsis: Clone restriction
  431. //
  432. // History: 29-Nov-94 SitaramR Created.
  433. //
  434. //----------------------------------------------------------------------------
  435. CWordRestriction *CWordRestriction::Clone() const
  436. {
  437. return new CWordRestriction( *this );
  438. }
  439. //+---------------------------------------------------------------------------
  440. //
  441. // Member: CSynRestriction::CSynRestriction, public
  442. //
  443. // Synopsis: Creates Syn expression
  444. //
  445. // Arguments: [occ] -- occurrence (if in phrase)
  446. // [isRange] -- is it range?
  447. //
  448. // History: 07-Feb-92 BartoszM Created.
  449. //
  450. //----------------------------------------------------------------------------
  451. const int cSynonyms = 2; // default initial count of synonyms
  452. CSynRestriction::CSynRestriction ( const CKey& key,
  453. OCCURRENCE occ,
  454. ULONG cPrevNoiseWords,
  455. ULONG cPostNoiseWords,
  456. BOOL isRange )
  457. : COccRestriction( RTNone, MAX_QUERY_RANK, occ, cPrevNoiseWords, cPostNoiseWords ),
  458. _keyArray( cSynonyms, TRUE ),
  459. _isRange(isRange)
  460. {
  461. _keyArray.Add ( key );
  462. SetType( RTSynonym );
  463. }
  464. //+---------------------------------------------------------------------------
  465. //
  466. // Member: CSynRestriction::CSynRestriction, public
  467. //
  468. // Synopsis: Copy constuctor
  469. //
  470. // Arguments: [synRst] -- synonym restriction to be copied
  471. //
  472. // History: 29-Nov-94 SitaramR Created.
  473. //
  474. //----------------------------------------------------------------------------
  475. CSynRestriction::CSynRestriction( CSynRestriction& synRst )
  476. : COccRestriction( RTNone, synRst.Weight(), synRst.Occurrence(),
  477. synRst.CountPrevNoiseWords(), synRst.CountPostNoiseWords() ),
  478. _keyArray( synRst.GetKeys(), TRUE ),
  479. _isRange( synRst.IsRange() )
  480. {
  481. SetType( RTSynonym );
  482. }
  483. //+-------------------------------------------------------------------------
  484. //
  485. // Member: CSynRestriction::~CSynRestriction, public
  486. //
  487. // Synopsis: Cleanup restriction
  488. //
  489. // History: 01-Feb-93 KyleP Created
  490. //
  491. //--------------------------------------------------------------------------
  492. CSynRestriction::~CSynRestriction()
  493. {
  494. SetType( RTNone ); // Avoid recursion.
  495. }
  496. void CSynRestriction::Marshall( PSerStream & stm ) const
  497. {
  498. _keyArray.Marshall( stm );
  499. stm.PutByte( (BYTE)_isRange );
  500. }
  501. CSynRestriction::CSynRestriction( ULONG ulWeight, PDeSerStream & stm )
  502. : COccRestriction( RTNone, ulWeight, stm),
  503. _keyArray( stm, TRUE ),
  504. _isRange( stm.GetByte() )
  505. {
  506. SetType( RTSynonym );
  507. }
  508. //+---------------------------------------------------------------------------
  509. //
  510. // Member: CSynRestriction::Clone, public
  511. //
  512. // Synopsis: Clone restriction
  513. //
  514. // History: 29-Nov-94 SitaramR Created.
  515. //
  516. //----------------------------------------------------------------------------
  517. CSynRestriction *CSynRestriction::Clone() const
  518. {
  519. return new CSynRestriction( *(CSynRestriction *)this );
  520. }
  521. //+---------------------------------------------------------------------------
  522. //
  523. // Member: CSynRestriction::AddKey, public
  524. //
  525. // Synopsis: Adds synonym key
  526. //
  527. // Arguments: [keyBuf] -- key
  528. //
  529. // History: 07-Feb-92 BartoszM Created.
  530. //
  531. //----------------------------------------------------------------------------
  532. void CSynRestriction::AddKey ( const CKeyBuf& Key )
  533. {
  534. _keyArray.Add ( Key );
  535. }
  536. //+---------------------------------------------------------------------------
  537. //
  538. // Member: CRangeRestriction::CRangeRestriction, public
  539. //
  540. // Synopsis: Creates word expression
  541. //
  542. // Arguments: [pid] -- property id
  543. // [keyStart] -- starting key
  544. // [keyEnd] -- ending key
  545. //
  546. // History: 24-Sep-92 BartoszM Created.
  547. //
  548. //----------------------------------------------------------------------------
  549. CRangeRestriction::CRangeRestriction()
  550. : CRestriction( RTRange, MAX_QUERY_RANK )
  551. {
  552. }
  553. //+---------------------------------------------------------------------------
  554. //
  555. // Member: CRangeRestriction::CRangeRestriction
  556. //
  557. // Synopsis: Copy constructor
  558. //
  559. // History: 30-May-95 SitaramR Created
  560. //
  561. //----------------------------------------------------------------------------
  562. CRangeRestriction::CRangeRestriction( const CRangeRestriction& rangeRst )
  563. : CRestriction( RTNone, rangeRst.Weight() )
  564. {
  565. const CKey *pKeyStart = rangeRst.GetStartKey();
  566. if ( pKeyStart )
  567. _keyStart = *pKeyStart;
  568. const CKey *pKeyEnd = rangeRst.GetEndKey();
  569. if ( pKeyEnd )
  570. _keyEnd = *pKeyEnd;
  571. SetType( RTRange );
  572. }
  573. //+-------------------------------------------------------------------------
  574. //
  575. // Member: CRangeRestriction::~CRangeRestriction, public
  576. //
  577. // Synopsis: Cleanup restriction
  578. //
  579. // History: 01-Feb-93 KyleP Created
  580. //
  581. //--------------------------------------------------------------------------
  582. CRangeRestriction::~CRangeRestriction()
  583. {
  584. SetType( RTNone ); // Avoid recursion.
  585. }
  586. void CRangeRestriction::Marshall( PSerStream & stm ) const
  587. {
  588. _keyStart.Marshall( stm );
  589. _keyEnd.Marshall( stm );
  590. }
  591. CRangeRestriction::CRangeRestriction( ULONG ulWeight, PDeSerStream & stm )
  592. : CRestriction( RTNone, ulWeight ),
  593. _keyStart( stm ),
  594. _keyEnd( stm )
  595. {
  596. SetType( RTRange );
  597. }
  598. //+---------------------------------------------------------------------------
  599. //
  600. // Member: CRangeRestriction::SetStartKey, public
  601. //
  602. // Arguments: [keyStart] -- starting key
  603. //
  604. // History: 24-Sep-92 BartoszM Created.
  605. //
  606. //----------------------------------------------------------------------------
  607. void CRangeRestriction::SetStartKey ( const CKeyBuf& keyStart )
  608. {
  609. _keyStart = keyStart;
  610. }
  611. //+---------------------------------------------------------------------------
  612. //
  613. // Member: CRangeRestriction::SetEndKey, public
  614. //
  615. // Arguments: [keyEnd] -- Ending key
  616. //
  617. // History: 24-Sep-92 BartoszM Created.
  618. //
  619. //----------------------------------------------------------------------------
  620. void CRangeRestriction::SetEndKey ( const CKeyBuf& keyEnd )
  621. {
  622. _keyEnd = keyEnd;
  623. }
  624. //+---------------------------------------------------------------------------
  625. //
  626. // Member: CRangeRestriction::Clone
  627. //
  628. // Synopsis: Clones a range restriction
  629. //
  630. // History: 30-May-95 SitaramR Created
  631. //
  632. //----------------------------------------------------------------------------
  633. CRangeRestriction *CRangeRestriction::Clone() const
  634. {
  635. return new CRangeRestriction( *this );
  636. }
  637. //+---------------------------------------------------------------------------
  638. //
  639. // Member: CUnfilteredRestriction::CUnfilteredRestriction, public
  640. //
  641. // History: 10-Nov-94 KyleP Created.
  642. //
  643. // Notes: This restriction is just a very special case of range
  644. // restriction that searches only for a particular value.
  645. // Standard procedure to create a range restriction is
  646. // sidetracked to save code.
  647. //
  648. //----------------------------------------------------------------------------
  649. CUnfilteredRestriction::CUnfilteredRestriction()
  650. {
  651. static const BYTE abUnfiltered[] = { VT_UI1,
  652. (BYTE)(pidUnfiltered >> 24),
  653. (BYTE)(pidUnfiltered >> 16),
  654. (BYTE)(pidUnfiltered >> 8),
  655. (BYTE) pidUnfiltered,
  656. 0,
  657. 1 };
  658. static CKeyBuf keyUnfilteredRange( pidUnfiltered, abUnfiltered, sizeof(abUnfiltered) );
  659. SetStartKey( keyUnfilteredRange );
  660. SetEndKey( keyUnfilteredRange );
  661. #if DBG == 1 && CIDBG == 1
  662. CRangeKeyRepository krep;
  663. CValueNormalizer norm( krep );
  664. OCCURRENCE occ = 1;
  665. CStorageVariant var;
  666. var.SetBOOL( (VARIANT_BOOL)0xFFFF );
  667. norm.PutValue( pidUnfiltered, occ, var );
  668. norm.PutValue( pidUnfiltered, occ, var );
  669. CRestriction * prst = krep.AcqRst();
  670. Win4Assert( prst->Type() == RTRange );
  671. CRangeRestriction * pRange = (CRangeRestriction *)prst;
  672. Win4Assert( pRange->GetStartKey()->Compare( *GetStartKey() ) == 0 );
  673. Win4Assert( pRange->GetEndKey()->Compare( *GetEndKey() ) == 0 );
  674. delete prst;
  675. #endif
  676. }
  677. //+---------------------------------------------------------------------------
  678. //
  679. // Member: CPhraseRestriction::CPhraseRestriction, public
  680. //
  681. // Synopsis: Deserializes phrase restriction
  682. //
  683. // Arguments: [ulWeight] -- restriction weight
  684. // [stm] -- stream to deserialize from
  685. //
  686. // History: 29-Nov-94 SitaramR Created.
  687. //
  688. //----------------------------------------------------------------------------
  689. CPhraseRestriction::CPhraseRestriction( ULONG ulWeight, PDeSerStream& stm )
  690. : CNodeRestriction( RTPhrase, ulWeight, stm )
  691. {
  692. #if CIDBG == 1
  693. for ( unsigned i = 0; i < _cNode; i++ )
  694. Win4Assert( _paNode[i]->Type() == RTWord || _paNode[i]->Type() == RTSynonym );
  695. #endif
  696. }
  697. //+---------------------------------------------------------------------------
  698. //
  699. // Member: CPhraseRestriction::~CPhraseRestriction, public
  700. //
  701. // History: 29-Nov-94 SitaramR Created.
  702. //
  703. //----------------------------------------------------------------------------
  704. CPhraseRestriction::~CPhraseRestriction()
  705. {
  706. if ( 0 != _paNode )
  707. {
  708. for ( unsigned i = 0; i < _cNode; i++ )
  709. {
  710. #if CIDBG == 1
  711. if ( 0 != _paNode[i] )
  712. {
  713. Win4Assert( _paNode[i]->Type() == RTWord ||
  714. _paNode[i]->Type() == RTSynonym );
  715. }
  716. #endif // CIDBG
  717. delete (COccRestriction *) _paNode[i];
  718. }
  719. delete [] _paNode;
  720. }
  721. SetType( RTNone ); // Avoid recursion.
  722. }
  723. CScopeRestriction::CScopeRestriction( WCHAR const * pwcsPath, BOOL fRecursive, BOOL fVirtual )
  724. : CRestriction( RTScope, MAX_QUERY_RANK ),
  725. _fValid( FALSE ),
  726. _fRecursive( fRecursive ),
  727. _fVirtual( fVirtual )
  728. {
  729. SetPath( pwcsPath );
  730. }
  731. CScopeRestriction * CScopeRestriction::Clone() const
  732. {
  733. return( new CScopeRestriction( _lowerFunnyPath.GetActualPath(), _fRecursive, _fVirtual ) );
  734. }
  735. CScopeRestriction::~CScopeRestriction()
  736. {
  737. SetType( RTNone ); // Avoid recursion.
  738. }
  739. void CScopeRestriction::Marshall( PSerStream & stm ) const
  740. {
  741. stm.PutWString( _lowerFunnyPath.GetActualPath() );
  742. stm.PutULong( _lowerFunnyPath.GetActualLength() );
  743. stm.PutULong( _fRecursive );
  744. stm.PutULong( _fVirtual );
  745. }
  746. CScopeRestriction::CScopeRestriction( ULONG ulWeight, PDeSerStream & stm )
  747. : CRestriction( RTScope, ulWeight ),
  748. _fValid( FALSE )
  749. {
  750. XCoMem<WCHAR> xString( UnMarshallWideString( stm ) );
  751. //
  752. // Simple validity checks; not all-inclusive. Just
  753. // return with _fValid set to FALSE and the query
  754. // will fail with an out of memory error.
  755. //
  756. // We don't support long paths for scopes.
  757. if ( wcslen( xString.GetPointer() ) >= MAX_PATH )
  758. return;
  759. // We don't support the NTFS special stream syntax
  760. if ( 0 != wcsstr( xString.GetPointer(), L"::$" ) )
  761. return;
  762. stm.GetULong(); // length not needed
  763. _fRecursive = stm.GetULong();
  764. _fVirtual = stm.GetULong();
  765. _lowerFunnyPath.SetPath( xString.Acquire() );
  766. _fValid = TRUE; // since we have a valid path
  767. }
  768. CScopeRestriction & CScopeRestriction::operator =(
  769. CScopeRestriction const & source )
  770. {
  771. _lowerFunnyPath = source._lowerFunnyPath;
  772. _fRecursive = source._fRecursive;
  773. _fVirtual = source._fVirtual;
  774. _fValid = source._fValid;
  775. return *this;
  776. }
  777. //+---------------------------------------------------------------------------
  778. //
  779. // Method: CScopeRestriction::SetPath
  780. //
  781. // Synopsis: Validates and sets a path in a scope restriction
  782. //
  783. // History: 24-Oct-96 dlee Created.
  784. //
  785. //----------------------------------------------------------------------------
  786. void CScopeRestriction::SetPath( WCHAR const * pwcsPath )
  787. {
  788. _fValid = FALSE;
  789. //
  790. // Simple validity checks; not all-inclusive. Just
  791. // return with _fValid set to FALSE and the query
  792. // wil fail with an out of memory error.
  793. //
  794. // We don't support long paths for scopes.
  795. if ( wcslen( pwcsPath ) >= MAX_PATH )
  796. return;
  797. // We don't support the NTFS special stream syntax
  798. if ( 0 != wcsstr( pwcsPath, L"::$" ) )
  799. return;
  800. _lowerFunnyPath.Truncate(0);
  801. if ( pwcsPath)
  802. {
  803. _lowerFunnyPath.SetPath( pwcsPath );
  804. _fValid = TRUE;
  805. }
  806. } //SetPath
  807. //+---------------------------------------------------------------------------
  808. //
  809. // Function: ValidateScopeRestriction
  810. //
  811. // Synopsis: Verifies a scope restriction looks ok. Can't use
  812. // CRestriction::IsValid since this needs to make sure there
  813. // aren't any odd nodes in the tree (like proximity, etc.)
  814. //
  815. // Returns: TRUE if it is ok, FALSE otherwise
  816. //
  817. // History: 24-Oct-96 dlee Created.
  818. //
  819. //----------------------------------------------------------------------------
  820. BOOL ValidateScopeRestriction( CRestriction * pRst )
  821. {
  822. if ( 0 == pRst )
  823. return FALSE;
  824. switch ( pRst->Type() )
  825. {
  826. #if 0 // someday we might support exclusion scopes
  827. case RTNot:
  828. {
  829. CRestriction *p = ((CNotRestriction *)pRst)->GetChild();
  830. return ValidateScopeRestriction( p );
  831. break;
  832. }
  833. case RTAnd:
  834. #endif // 0 // exclusion scopes
  835. case RTOr:
  836. {
  837. CNodeRestriction * p = pRst->CastToNode();
  838. for ( ULONG x = 0; x < p->Count(); x++ )
  839. {
  840. if ( !ValidateScopeRestriction( p->GetChild( x ) ) )
  841. return FALSE;
  842. }
  843. break;
  844. }
  845. case RTScope:
  846. {
  847. CScopeRestriction *p = (CScopeRestriction *) pRst;
  848. if ( !p->IsValid() )
  849. return FALSE;
  850. break;
  851. }
  852. default :
  853. {
  854. return FALSE;
  855. }
  856. }
  857. return TRUE;
  858. } //ValidateScopeRestriction
  859. #if CIDBG == 1
  860. //+-------------------------------------------------------------------------
  861. //
  862. // Function: DisplayChar
  863. //
  864. // Synopsis: Debug print the non-ascii text buffer
  865. //
  866. // Arguments: [pwString] -- Pointer to string (not null terminated)
  867. // [cString] -- len of the string in char
  868. // [infolevel] --
  869. //
  870. // History: 22-Apr-98 KitmanH Created
  871. //
  872. //--------------------------------------------------------------------------
  873. void DisplayChar( WCHAR * pwString, DWORD cString, ULONG infolevel )
  874. {
  875. BOOL fOk = TRUE;
  876. for ( unsigned i = 0; i < cString; i++ )
  877. {
  878. if ( pwString[i] > 0xFF )
  879. {
  880. fOk = FALSE;
  881. break;
  882. }
  883. }
  884. if ( fOk )
  885. {
  886. unsigned j = 0;
  887. WCHAR awcTemp[71];
  888. for ( unsigned i = 0; i < cString; i++ )
  889. {
  890. awcTemp[j] = pwString[i];
  891. j++;
  892. if ( j == sizeof(awcTemp)/sizeof(awcTemp[0]) - 1 )
  893. {
  894. awcTemp[j] = 0;
  895. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "\"%ws\"", awcTemp ));
  896. j = 0;
  897. }
  898. }
  899. awcTemp[j] = 0;
  900. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "\"%ws\"", awcTemp ));
  901. }
  902. else
  903. {
  904. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "0x" ));
  905. unsigned j = 0;
  906. for ( unsigned i = 0; i < cString; i++ )
  907. {
  908. if ( 0 == j )
  909. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "%04X", pwString[i] ));
  910. else if ( 14 == j )
  911. {
  912. vqDebugOut(( infolevel | DEB_NOCOMPNAME, " %04X\n", pwString[i] ));
  913. }
  914. else
  915. vqDebugOut(( infolevel | DEB_NOCOMPNAME, " %04X", pwString[i] ));
  916. j++;
  917. if ( j > 14 )
  918. j = 0;
  919. }
  920. }
  921. }
  922. void Display( CRestriction * pRst, int indent, ULONG infolevel )
  923. {
  924. vqDebugOut(( infolevel, " " ));
  925. for ( int i = 0; i < indent; i++ )
  926. {
  927. vqDebugOut(( infolevel | DEB_NOCOMPNAME, " " ));
  928. }
  929. switch ( pRst->Type() )
  930. {
  931. case RTContent:
  932. vqDebugOut(( infolevel | DEB_NOCOMPNAME,
  933. "CONTENT: \"%ws\", LOCALE: %lu\n",
  934. ((CContentRestriction *)pRst)->GetPhrase(),
  935. ((CContentRestriction *)pRst)->GetLocale() ));
  936. break;
  937. case RTNatLanguage:
  938. vqDebugOut(( infolevel | DEB_NOCOMPNAME,
  939. "NATURAL LANGUAGE: \"%ws\", LOCALE: %lu\n",
  940. ((CNatLanguageRestriction *)pRst)->GetPhrase(),
  941. ((CNatLanguageRestriction *)pRst)->GetLocale() ));
  942. break;
  943. case RTWord:
  944. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "WORD%s: ",
  945. ((CWordRestriction *)pRst)->IsRange() ? " PREFIX" : "" ));
  946. DisplayChar( ((CWordRestriction *)pRst)->GetKey()->GetStr(),
  947. ((CWordRestriction *)pRst)->GetKey()->StrLen(),
  948. infolevel
  949. );
  950. vqDebugOut(( infolevel | DEB_NOCOMPNAME,
  951. " PID %d OCC %d, WEIGHT %d\n",
  952. ((CWordRestriction *)pRst)->Pid(),
  953. ((CWordRestriction *)pRst)->Occurrence(),
  954. ((CWordRestriction *)pRst)->Weight() ));
  955. break;
  956. case RTSynonym:
  957. {
  958. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "SYNONYM: OCC %d ",
  959. ((CSynRestriction *)pRst)->Occurrence() ));
  960. CKeyArray & keys = ((CSynRestriction *)pRst)->GetKeys();
  961. for ( int i = 0; i < keys.Count(); i++ )
  962. {
  963. DisplayChar( keys.Get(i).GetStr(), keys.Get(i).StrLen(),
  964. infolevel );
  965. vqDebugOut(( infolevel | DEB_NOCOMPNAME, " " ));
  966. }
  967. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "\n" ));
  968. break;
  969. }
  970. case RTRange:
  971. {
  972. CRangeRestriction * pr = (CRangeRestriction *)pRst;
  973. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "RANGE: " ));
  974. char * pc = new char[pr->GetStartKey()->Count() * 2 +
  975. 1 +
  976. pr->GetEndKey()->Count() * 2 +
  977. 2];
  978. for ( unsigned i = 0; i < pr->GetStartKey()->Count(); i++ )
  979. sprintf( pc + i*2, "%02x", pr->GetStartKey()->GetBuf()[i] );
  980. pc[i*2] = '-';
  981. for ( unsigned j = 0; j < pr->GetEndKey()->Count(); j++ )
  982. sprintf( pc + i*2 + 1 + j*2, "%02x", pr->GetEndKey()->GetBuf()[j] );
  983. pc[i*2 + 1 + j*2] = '\n';
  984. pc[i*2 + 1 + j*2 + 1] = 0;
  985. vqDebugOut(( infolevel | DEB_NOCOMPNAME, pc ));
  986. delete [] pc;
  987. break;
  988. }
  989. case RTProperty:
  990. if ( ((CPropertyRestriction *)pRst)->Relation() == PRRE )
  991. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "REGEX " ));
  992. else
  993. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "PROPERTY " ));
  994. ((CPropertyRestriction *) pRst)->Value().DisplayVariant(
  995. infolevel | DEB_NOCOMPNAME,
  996. 0);
  997. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "\n" ));
  998. break;
  999. case RTInternalProp:
  1000. {
  1001. CInternalPropertyRestriction * pir = (CInternalPropertyRestriction *)pRst;
  1002. if ( pir->Relation() == PRRE )
  1003. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "REGEX pid(0x%lx) ",
  1004. pir->Pid() ));
  1005. else
  1006. {
  1007. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "PROPERTY pid(0x%lx) ", pir->Pid() ));
  1008. switch ( getBaseRelop( pir->Relation() ) )
  1009. {
  1010. case PRLT:
  1011. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "< " ));
  1012. break;
  1013. case PRLE:
  1014. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "<= " ));
  1015. break;
  1016. case PRGT:
  1017. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "> " ));
  1018. break;
  1019. case PRGE:
  1020. vqDebugOut(( infolevel | DEB_NOCOMPNAME, ">= " ));
  1021. break;
  1022. case PREQ:
  1023. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "== " ));
  1024. break;
  1025. case PRNE:
  1026. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "!= " ));
  1027. break;
  1028. case PRAllBits:
  1029. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "All bits " ));
  1030. break;
  1031. case PRSomeBits:
  1032. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "Some bits " ));
  1033. break;
  1034. default:
  1035. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "??? " ));
  1036. break;
  1037. }
  1038. if ( pir->Relation() & PRAll )
  1039. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "All " ));
  1040. else if ( pir->Relation() & PRAny )
  1041. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "Any " ));
  1042. }
  1043. pir->Value().DisplayVariant(infolevel | DEB_NOCOMPNAME, 0);
  1044. if ( pir->GetContentHelper() )
  1045. {
  1046. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "\n" ));
  1047. for ( int i = 0; i < indent+5; i++ )
  1048. {
  1049. vqDebugOut(( infolevel | DEB_NOCOMPNAME, " " ));
  1050. }
  1051. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "HELPER:\n" ));
  1052. Display( pir->GetContentHelper(), indent+3, infolevel );
  1053. }
  1054. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "\n" ));
  1055. break;
  1056. }
  1057. case RTNot:
  1058. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "NOT\n" ));
  1059. Display( ((CNotRestriction *)pRst)->GetChild(), indent + 1, infolevel );
  1060. break;
  1061. case RTAnd:
  1062. case RTOr:
  1063. case RTProximity:
  1064. case RTVector:
  1065. case RTPhrase:
  1066. {
  1067. switch( pRst->Type() )
  1068. {
  1069. case RTAnd:
  1070. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "AND\n" ));
  1071. break;
  1072. case RTOr:
  1073. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "OR\n" ));
  1074. break;
  1075. case RTNot:
  1076. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "NOT\n" ));
  1077. break;
  1078. case RTProximity:
  1079. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "PROXIMITY\n" ));
  1080. break;
  1081. case RTVector:
  1082. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "VECTOR " ));
  1083. switch ( ((CVectorRestriction *)pRst)->RankMethod() )
  1084. {
  1085. case VECTOR_RANK_MIN:
  1086. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "(Min)\n" ));
  1087. break;
  1088. case VECTOR_RANK_MAX:
  1089. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "(Max)\n" ));
  1090. break;
  1091. case VECTOR_RANK_INNER:
  1092. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "(Inner Product)\n" ));
  1093. break;
  1094. case VECTOR_RANK_DICE:
  1095. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "(Dice Coefficient)\n" ));
  1096. break;
  1097. case VECTOR_RANK_JACCARD:
  1098. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "(Jaccard Coefficient)\n" ));
  1099. break;
  1100. default:
  1101. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "(???)\n" ));
  1102. break;
  1103. }
  1104. break;
  1105. case RTPhrase:
  1106. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "PHRASE\n" ));
  1107. break;
  1108. }
  1109. CNodeRestriction * pNodeRst = pRst->CastToNode();
  1110. for ( UINT i = 0; i < pNodeRst->Count(); i++ )
  1111. {
  1112. Display( pNodeRst->GetChild( i ), indent + 1, infolevel );
  1113. }
  1114. break;
  1115. }
  1116. case RTNone:
  1117. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "NONE -- empty\n" ));
  1118. break;
  1119. default:
  1120. vqDebugOut(( infolevel | DEB_NOCOMPNAME, "UNKNOWN\n" ));
  1121. break;
  1122. }
  1123. }
  1124. #endif // CIDBG == 1