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.

241 lines
5.4 KiB

  1. //+------------------------------------------------------------
  2. //
  3. // Copyright (C) 1998, Microsoft Corporation
  4. //
  5. // File: icatqueries.cpp
  6. //
  7. // Contents: CICategorizerQueriesIMP implementation
  8. //
  9. // Classes:
  10. // CICategorizerQueriesIMP
  11. //
  12. // Functions:
  13. //
  14. // History:
  15. // jstamerj 1998/07/15 14:25:18: Created.
  16. //
  17. //-------------------------------------------------------------
  18. #include "precomp.h"
  19. //+------------------------------------------------------------
  20. //
  21. // Function: QueryInterface
  22. //
  23. // Synopsis: Returns pointer to this object for IUnknown and ICategorizerQueries
  24. //
  25. // Arguments:
  26. // iid -- interface ID
  27. // ppv -- pvoid* to fill in with pointer to interface
  28. //
  29. // Returns:
  30. // S_OK: Success
  31. // E_NOINTERFACE: Don't support that interface
  32. //
  33. // History:
  34. // jstamerj 980612 14:07:57: Created.
  35. //
  36. //-------------------------------------------------------------
  37. STDMETHODIMP CICategorizerQueriesIMP::QueryInterface(
  38. REFIID iid,
  39. LPVOID *ppv)
  40. {
  41. *ppv = NULL;
  42. if(iid == IID_IUnknown) {
  43. *ppv = (LPVOID) this;
  44. } else if (iid == IID_ICategorizerQueries) {
  45. *ppv = (LPVOID) this;
  46. } else {
  47. return E_NOINTERFACE;
  48. }
  49. AddRef();
  50. return S_OK;
  51. }
  52. //+------------------------------------------------------------
  53. //
  54. // Function: AddRef
  55. //
  56. // Synopsis: adds a reference to this object
  57. //
  58. // Arguments: NONE
  59. //
  60. // Returns: New reference count
  61. //
  62. // History:
  63. // jstamerj 980611 20:07:14: Created.
  64. //
  65. //-------------------------------------------------------------
  66. ULONG CICategorizerQueriesIMP::AddRef()
  67. {
  68. return InterlockedIncrement((PLONG)&m_cRef);
  69. }
  70. //+------------------------------------------------------------
  71. //
  72. // Function: Release
  73. //
  74. // Synopsis: releases a reference
  75. //
  76. // Arguments: NONE
  77. //
  78. // Returns: New reference count
  79. //
  80. // History:
  81. // jstamerj 980611 20:07:33: Created.
  82. //
  83. //-------------------------------------------------------------
  84. ULONG CICategorizerQueriesIMP::Release()
  85. {
  86. LONG lNewRefCount;
  87. lNewRefCount = InterlockedDecrement((PLONG)&m_cRef);
  88. // We are allocated on the stack
  89. return lNewRefCount;
  90. }
  91. //+------------------------------------------------------------
  92. //
  93. // Function: CICategorizerQueriesIMP::SetQueryString
  94. //
  95. // Synopsis: Set the query string for a batch of ICategorizerItems
  96. //
  97. // Arguments:
  98. // pszQueryString: QueryString to set or NULL to unset any query string
  99. //
  100. // Returns:
  101. // S_OK: Success
  102. // E_OUTOFMEMORY
  103. //
  104. // History:
  105. // jstamerj 1998/07/15 14:28:18: Created.
  106. //
  107. //-------------------------------------------------------------
  108. STDMETHODIMP CICategorizerQueriesIMP::SetQueryString(
  109. IN LPSTR pszQueryString)
  110. {
  111. HRESULT hr = S_OK;
  112. DWORD dwOldLength;
  113. DWORD dwNewLength;
  114. CatFunctEnterEx((LPARAM)this, "CICategorizerQueriesIMP::SetQueryString");
  115. //
  116. // If pszQueryString is NULL, release any existing buffer and set
  117. // ptr to NULL
  118. //
  119. if(pszQueryString == NULL) {
  120. if(*m_ppsz != NULL)
  121. delete *m_ppsz;
  122. *m_ppsz = NULL;
  123. return S_OK;
  124. }
  125. //
  126. // Get the lengths of new and old strings
  127. //
  128. dwNewLength = lstrlen(pszQueryString);
  129. if(*m_ppsz) {
  130. dwOldLength = lstrlen(*m_ppsz);
  131. if(dwNewLength <= dwOldLength) {
  132. //
  133. // Re-use the same buffer
  134. //
  135. lstrcpy(*m_ppsz, pszQueryString);
  136. return S_OK;
  137. } else {
  138. //
  139. // Free the existing buffer and realloc below
  140. //
  141. delete *m_ppsz;
  142. }
  143. }
  144. *m_ppsz = new CHAR[ dwNewLength + 1 ];
  145. if(*m_ppsz == NULL)
  146. {
  147. hr = E_OUTOFMEMORY;
  148. ERROR_LOG("new CHAR[]");
  149. return hr;
  150. }
  151. lstrcpy(*m_ppsz, pszQueryString);
  152. CatFunctLeaveEx((LPARAM)this);
  153. return S_OK;
  154. }
  155. //+------------------------------------------------------------
  156. //
  157. // Function: CICategorizerQueriesIMP::SetQueryStringNoAlloc
  158. //
  159. // Synopsis: Internal method to set the query string without
  160. // ReAllocing the buffer
  161. //
  162. // Arguments:
  163. // pszQueryString: QueryString to set
  164. //
  165. // Returns:
  166. // S_OK: Success
  167. //
  168. // History:
  169. // jstamerj 1998/07/15 16:08:45: Created.
  170. //
  171. //-------------------------------------------------------------
  172. HRESULT CICategorizerQueriesIMP::SetQueryStringNoAlloc(
  173. IN LPSTR pszQueryString)
  174. {
  175. //
  176. // Free the old buffer, if any
  177. //
  178. if(*m_ppsz)
  179. delete *m_ppsz;
  180. //
  181. // Set the new string to the caller's pointer
  182. //
  183. *m_ppsz = pszQueryString;
  184. return S_OK;
  185. }
  186. //+------------------------------------------------------------
  187. //
  188. // Function: CICategorizerQueriesIMP::GetQueryString
  189. //
  190. // Synopsis: Retrieve pointer to the current query string. Note that
  191. // this pointer will become bogus of SetQueryString is called again
  192. //
  193. // Arguments:
  194. // ppszQueryString: ptr to set to the query string ptr.
  195. //
  196. // Returns:
  197. // S_OK: Success
  198. //
  199. // History:
  200. // jstamerj 1998/07/20 15:06:34: Created.
  201. //
  202. //-------------------------------------------------------------
  203. STDMETHODIMP CICategorizerQueriesIMP::GetQueryString(
  204. LPSTR *ppszQueryString)
  205. {
  206. _ASSERT(ppszQueryString);
  207. //
  208. // Give out our string pointer
  209. //
  210. *ppszQueryString = *m_ppsz;
  211. return S_OK;
  212. }