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.

211 lines
7.1 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMI OLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // Parameter handling Routines
  7. //
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef _UTLPARAM_H_
  10. #define _UTLPARAM_H_
  11. #define PARAM_MARKER L'?'
  12. class CCommand;
  13. const BYTE PARAMINFO_CONVERT_IUNKNOWN = 0x01;
  14. const DWORD CUTLPARAM_DEFAULT_PARAMS = 0x00000001;
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. //
  17. // Parameter information struct.
  18. //
  19. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  20. struct PARAMINFO
  21. {
  22. LPWSTR pwszParamName; //parameter name
  23. DBPARAMFLAGS dwFlags; //parameter flags
  24. DBLENGTH cbColLength; //max length of param as represented
  25. DBLENGTH cbValueMax; //max length of the param as represented by the OLE DB type
  26. DBLENGTH ulParamSize; //max length of the param as defined for ICommandWithParameters::GetParameterInfo
  27. DBSTATUS dwStatus; //status flags
  28. DBTYPE wOLEDBType; //corresponding OLE DB type
  29. LONG CIMType;
  30. BYTE * pbData;
  31. LONG Flavor;
  32. DBORDINAL iOrdinal;
  33. PARAMINFO() { this->Init(); }
  34. ~PARAMINFO() { delete pwszParamName; }
  35. void Init() { pwszParamName = NULL; dwFlags = 0; cbColLength = 0;cbValueMax = 0; dwStatus = 0;wOLEDBType = 0; pbData = NULL; }
  36. };
  37. typedef PARAMINFO *PPARAMINFO;
  38. struct WMIBINDINFO
  39. {
  40. DBBINDING* pBinding; // Original binding data
  41. PARAMINFO* pParamInfo; // Parameter information
  42. WMIBINDINFO* pNextBindInfo; // Next binding for the output parameter
  43. WORD wFlags; // Flags
  44. WORD iBatchedRPC; // Index to which batched RPC this param was used
  45. };
  46. typedef WMIBINDINFO *PWMIBINDINFO;
  47. // Get binding
  48. inline DBBINDING* GetBinding(PWMIBINDINFO pBindInfo)
  49. {
  50. if (pBindInfo->wFlags & DBPARAMIO_INPUT){
  51. for (; pBindInfo; pBindInfo = pBindInfo->pNextBindInfo){
  52. if (pBindInfo->pBinding->eParamIO & DBPARAMIO_INPUT){
  53. break;
  54. }
  55. assert(pBindInfo);
  56. }
  57. }
  58. return pBindInfo->pBinding;
  59. }
  60. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61. //
  62. // Utility class for parameter and binding information
  63. //
  64. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. class CUtlParam
  66. {
  67. private:
  68. ULONG m_cRef; // reference count
  69. DBPARAMS m_dbparams; // parameters
  70. ULONG_PTR m_cbRowSize; // # of bytes allocated for a single set of params
  71. CImpIAccessor* m_pIAccessor; // accessor interface
  72. ULONG m_cParams; // # of parameters in the command
  73. WMIBINDINFO* m_prgBindInfo; //@cmember binding information
  74. PPARAMINFO* m_rgpParamInfo; // parm info derived from bind info
  75. ULONG m_cParamInfo; // # of param info structs derived
  76. // from the bind info
  77. DWORD m_dwStatus; // status information
  78. public:
  79. CUtlParam();
  80. ~CUtlParam();
  81. // Increments the Reference count
  82. STDMETHODIMP_(ULONG) AddRef(void);
  83. // Decrements the Reference count
  84. STDMETHODIMP_(ULONG) Release(void);
  85. // Get the number parameters in the command
  86. ULONG CParams() const { return m_cParams; }
  87. // Get the number parameter sets
  88. ULONG CParamSets() const { return (ULONG)m_dbparams.cParamSets; }
  89. // Are there any default parameters?
  90. BOOL FHaveDefaultParams() const
  91. {
  92. return (m_dwStatus & CUTLPARAM_DEFAULT_PARAMS) != 0;
  93. }
  94. //==================================================================================
  95. // Builds the binding information needed to execute a command with parameters
  96. //==================================================================================
  97. STDMETHODIMP BuildBindInfo( CCommand *pcmd, DBPARAMS *pParams, const IID* piid );
  98. //==================================================================================
  99. // Builds the parameter information for the command from the binding information.
  100. //==================================================================================
  101. STDMETHODIMP BuildParamInfo( CCommand *pcmd, // IN | Command Structure
  102. const IID* piid // IN | Interface that invoked this method
  103. );
  104. // Get the parameter information for a parameter
  105. inline PARAMINFO* GetParamInfo(ULONG iParam) const
  106. {
  107. return NULL;
  108. }
  109. // Set the status data for a parameter
  110. inline void SetStatus(DBBINDING *pBind, DBSTATUS dbstatus)
  111. {
  112. if (pBind->dwPart & DBPART_STATUS)
  113. {
  114. BYTE *pbData;
  115. ULONG iParamSet;
  116. for ( pbData = (BYTE*)m_dbparams.pData, iParamSet = 0;
  117. iParamSet < m_dbparams.cParamSets;
  118. pbData += m_cbRowSize, iParamSet++ )
  119. {
  120. *(DBSTATUS *)(pbData + pBind->obStatus) = dbstatus;
  121. }
  122. }
  123. }
  124. // Bind a parameter to its data
  125. void BindParamData( ULONG iParamSet, ULONG iParam, DBBINDING* pBinding,BYTE** ppbValue, DWORD** ppdwLength,
  126. DWORD* pdwLength,DBSTATUS** ppdwStatus, DBSTATUS* pdwStatus, DBTYPE* pdbtype );
  127. // Bind the pointers to parameter data
  128. inline void BindParamPtrs
  129. (
  130. ULONG iParamSet, // IN | parameter set ordinal
  131. ULONG iParam, // IN | parameter ordinal
  132. DBBINDING* pBinding, // IN | Binding information
  133. BYTE** ppbValue, // OUT | pointer to the param value
  134. DWORD** ppdwLength, // OUT | pointer to the length of param value
  135. DBSTATUS** ppdwStatus // OUT | pointer to the status for the param
  136. )
  137. {
  138. assert(iParamSet && iParamSet <= m_dbparams.cParamSets);
  139. assert(iParam && iParam <= m_cParams);
  140. assert(pBinding);
  141. assert(pBinding->iOrdinal == iParam);
  142. assert(ppbValue);
  143. assert(ppdwLength);
  144. assert(ppdwStatus);
  145. BYTE* pbData = (BYTE*)m_dbparams.pData + (iParamSet-1)*m_cbRowSize;
  146. *ppbValue = (pBinding->dwPart & DBPART_VALUE)
  147. ? pbData + pBinding->obValue : NULL;
  148. *ppdwStatus = (pBinding->dwPart & DBPART_STATUS)
  149. ? (DBSTATUS*)(pbData + pBinding->obStatus) : NULL;
  150. *ppdwLength = (pBinding->dwPart & DBPART_LENGTH)
  151. ? (DWORD*)(pbData + pBinding->obLength) : NULL;
  152. }
  153. // Bind a parameter to its data
  154. inline BOOL FIsDefaultParam
  155. (
  156. ULONG iParamSet, // IN | parameter set ordinal
  157. ULONG iParam, // IN | parameter ordinal
  158. DBBINDING* pBinding // IN | Binding information
  159. )
  160. {
  161. assert(iParamSet && iParamSet <= m_dbparams.cParamSets);
  162. assert(iParam && iParam <= m_cParams);
  163. assert(pBinding);
  164. assert(pBinding->iOrdinal == iParam);
  165. if (pBinding->dwPart & DBPART_STATUS)
  166. {
  167. BYTE* pbData = (BYTE*)m_dbparams.pData + (iParamSet-1)*m_cbRowSize;
  168. assert(!IsBadReadPtr(pbData+pBinding->obStatus,sizeof(DBSTATUS)));
  169. if (DBSTATUS_S_DEFAULT == *((DBSTATUS*)(pbData + pBinding->obStatus)))
  170. return TRUE;
  171. }
  172. return FALSE;
  173. }
  174. // Get the length of the bound data
  175. ULONG GetBindLength
  176. (
  177. DBBINDING *pBinding, // IN | Binding information
  178. DWORD* pdwLength, // IN | bound length
  179. BYTE *pbData // IN | Pointer to param data
  180. );
  181. // Set bind status for parameters to DBSTATUS_E_UNAVAILABLE
  182. void SetParamsUnavailable(ULONG iParamSetFailed, ULONG iParamFailed,BOOL fBackOut);
  183. };
  184. typedef CUtlParam *PCUTLPARAM;
  185. #endif // UTLPARAM