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.

195 lines
6.9 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // util.h
  6. //
  7. // alanbos 13-Feb-98 Created.
  8. //
  9. // Useful things
  10. //
  11. //***************************************************************************
  12. #ifndef _UTIL_H_
  13. #define _UTIL_H_
  14. HRESULT WmiVariantChangeType (VARIANT &vOut, VARIANT *pvIn, CIMTYPE lCimType);
  15. HRESULT WmiConvertSafeArray (VARIANT &vOut, SAFEARRAY *pArray, CIMTYPE lCimType);
  16. HRESULT WmiConvertDispatchArray (VARIANT &vOut, CComPtr<IDispatch> & pIDispatch, CIMTYPE lCimType);
  17. bool GetSafeArrayDimensions (SAFEARRAY &sArray, long &lLower, long &lUpper);
  18. HRESULT ConvertDispatchToArray (VARIANT *pDest, VARIANT *pSrc, CIMTYPE lCimType = CIM_ILLEGAL,
  19. BOOL bIsQualifier = false, VARTYPE requiredQualifierType = VT_NULL);
  20. HRESULT MapToCIMOMObject (VARIANT *pVal);
  21. HRESULT MapFromCIMOMObject (CSWbemServices *pService, VARIANT *pVal,
  22. ISWbemInternalObject *pObject = NULL,
  23. BSTR propertyName = NULL,
  24. long index = -1);
  25. HRESULT ConvertArray(VARIANT * pDest, VARIANT * pSrc, BOOL bQualTypesOnly = false,
  26. VARTYPE requiredVarType = VT_NULL);
  27. HRESULT ConvertArrayRev(VARIANT * pDest, VARIANT * pSrc);
  28. HRESULT ConvertBSTRArray(SAFEARRAY **ppDest, SAFEARRAY *pSrc);
  29. HRESULT QualifierVariantChangeType(VARIANT* pvDest, VARIANT* pvSrc, VARTYPE vtNew);
  30. VARTYPE GetAcceptableQualType(VARTYPE vt);
  31. HRESULT BuildStringArray (SAFEARRAY *pArray, VARIANT & var);
  32. HRESULT SetFromStringArray (SAFEARRAY **ppArray, VARIANT *pVar);
  33. BSTR FormatAssociatorsQuery (BSTR strObjectPath, BSTR strAssocClass,
  34. BSTR strResultClass, BSTR strResultRole, BSTR strRole, VARIANT_BOOL bClassesOnly,
  35. VARIANT_BOOL bSchemaOnly, BSTR strRequiredAssocQualifier, BSTR strRequiredQualifier);
  36. BSTR FormatReferencesQuery (BSTR strObjectPath, BSTR strResultClass, BSTR strRole,
  37. VARIANT_BOOL bClassesOnly, VARIANT_BOOL bSchemaOnly, BSTR strRequiredQualifier);
  38. BSTR FormatMultiQuery (SAFEARRAY &pClassList, long iNumElements);
  39. void CheckArrayBounds (SAFEARRAY *psa, long index);
  40. void SetSite (VARIANT *pVal, ISWbemInternalObject *pSObject, BSTR propertyName, long index = -1);
  41. void SetWbemError (CSWbemServices *pService);
  42. void ResetLastErrors ();
  43. void SetException (EXCEPINFO *pExcepInfo, HRESULT hr, BSTR m_objectName);
  44. BSTR MapHresultToWmiDescription (HRESULT hr);
  45. void MapNulls (DISPPARAMS FAR* pdispparams);
  46. void EnsureGlobalsInitialized ();
  47. // CIM <-> VARIANT type coercion functions
  48. VARTYPE CimTypeToVtType(CIMTYPE lType);
  49. WbemCimtypeEnum GetCIMType (VARIANT &var, CIMTYPE iCIMType,
  50. bool bIsArray = false, long lLBound = 0, long lUBound = 0);
  51. bool CanCoerceString (const BSTR & bsValue, WbemCimtypeEnum cimType);
  52. WbemCimtypeEnum MapVariantTypeToCimType (VARIANT *pVal, CIMTYPE cimType = CIM_ILLEGAL);
  53. bool ReadUI64(LPCWSTR wsz, unsigned __int64& rui64);
  54. bool ReadI64(LPCWSTR wsz, __int64& rui64);
  55. bool IsNullOrEmptyVariant (VARIANT & var);
  56. bool RemoveElementFromArray (SAFEARRAY & array, VARTYPE vt, long iIndex);
  57. bool ShiftLeftElement (SAFEARRAY & array, VARTYPE vt, long iIndex);
  58. bool ShiftElementsToRight (SAFEARRAY & array, VARTYPE vt, long iStartIndex,
  59. long iEndIndex, long iShift);
  60. bool MatchBSTR (VARIANT & var, BSTR & bstrVal);
  61. bool MatchUI1 (VARIANT & var, unsigned char bVal);
  62. bool MatchI2 (VARIANT & var, short iVal);
  63. bool MatchI4 (VARIANT & var, long lVal);
  64. bool MatchR4 (VARIANT & var, float fltVal);
  65. bool MatchR8 (VARIANT & var, double dblVal);
  66. bool MatchBool (VARIANT & var, VARIANT_BOOL boolVal);
  67. bool MatchValue (VARIANT &var1, VARIANT &var2);
  68. #define WBEMS_PDN_SCHEME L"WINMGMTS:"
  69. #define WBEMS_LEFT_PAREN L"("
  70. #define WBEMS_RIGHT_PAREN L")"
  71. #define WBEMS_LEFT_CURLY L"{"
  72. #define WBEMS_RIGHT_CURLY L"}"
  73. #define WBEMS_LEFT_SQBRK L"["
  74. #define WBEMS_RIGHT_SQBRK L"]"
  75. #define WBEMS_LEFT_ANGLE L"<"
  76. #define WBEMS_RIGHT_ANGLE L">"
  77. #define WBEMS_EQUALS L"="
  78. #define WBEMS_COMMA L","
  79. #define WBEMS_EXCLAMATION L"!"
  80. #define WBEMS_AUTH_LEVEL L"authenticationLevel"
  81. #define WBEMS_AUTH_DEFAULT L"default"
  82. #define WBEMS_AUTH_NONE L"none"
  83. #define WBEMS_AUTH_CONNECT L"connect"
  84. #define WBEMS_AUTH_CALL L"call"
  85. #define WBEMS_AUTH_PKT L"pkt"
  86. #define WBEMS_AUTH_PKT_INT L"pktIntegrity"
  87. #define WBEMS_AUTH_PKT_PRIV L"pktPrivacy"
  88. #define WBEMS_IMPERSON_LEVEL L"impersonationLevel"
  89. #define WBEMS_IMPERSON_ANON L"anonymous"
  90. #define WBEMS_IMPERSON_IDENTIFY L"identify"
  91. #define WBEMS_IMPERSON_IMPERSON L"impersonate"
  92. #define WBEMS_IMPERSON_DELEGATE L"delegate"
  93. #define WBEMS_LOCALE L"locale"
  94. #define WBEMS_AUTHORITY L"authority"
  95. #define WBEMS_RK_SCRIPTING _T("Software\\Microsoft\\Wbem\\Scripting")
  96. #define WBEMS_RV_DEFNS _T("Default Namespace")
  97. #define WBEMS_RV_ENABLEFORASP _T("Enable for ASP")
  98. #define WBEMS_RV_DEFAULTIMPLEVEL _T("Default Impersonation Level")
  99. #define WBEMS_DEFNS _T("root\\cimv2")
  100. // Strings for queries
  101. #define WBEMS_QUERY_ASSOCOF OLESTR("associators of ")
  102. #define WBEMS_QUERY_OPENBRACE OLESTR("{")
  103. #define WBEMS_QUERY_CLOSEBRACE OLESTR("}")
  104. #define WBEMS_QUERY_WHERE OLESTR(" where ")
  105. #define WBEMS_QUERY_ASSOCCLASS OLESTR(" AssocClass ")
  106. #define WBEMS_QUERY_EQUALS OLESTR("=")
  107. #define WBEMS_QUERY_CLASSDEFS OLESTR(" ClassDefsOnly ")
  108. #define WBEMS_QUERY_REQASSOCQ OLESTR(" RequiredAssocQualifier ")
  109. #define WBEMS_QUERY_REQQUAL OLESTR(" RequiredQualifier ")
  110. #define WBEMS_QUERY_RESCLASS OLESTR(" ResultClass ")
  111. #define WBEMS_QUERY_RESROLE OLESTR(" ResultRole ")
  112. #define WBEMS_QUERY_ROLE OLESTR(" Role ")
  113. #define WBEMS_QUERY_SCHEMAONLY OLESTR(" SchemaOnly ")
  114. #define WBEMS_QUERY_REFOF OLESTR("references of ")
  115. #define WBEMS_QUERY_SELECT OLESTR("select * from ")
  116. #define WBEMS_QUERY_GO OLESTR(" go ")
  117. // System properties
  118. #define WBEMS_SP_CLASS OLESTR("__CLASS")
  119. #define WBEMS_SP_PATH OLESTR("__PATH")
  120. #define WBEMS_SP_RELPATH OLESTR("__RELPATH")
  121. #define WBEMS_SP_SERVER OLESTR("__SERVER")
  122. #define WBEMS_SP_NAMESPACE OLESTR("__NAMESPACE")
  123. #define WBEMS_SP_GENUS OLESTR("__GENUS")
  124. #define WBEMS_SP_DERIVATION OLESTR("__DERIVATION")
  125. // Context variables
  126. #define WBEMS_CV_GET_EXTENSIONS OLESTR("__GET_EXTENSIONS")
  127. #define WBEMS_CV_GET_EXT_CLIENT_REQUEST OLESTR("__GET_EXT_CLIENT_REQUEST")
  128. #define WBEMS_CV_GET_EXT_PROPERTIES OLESTR("__GET_EXT_PROPERTIES")
  129. #define WBEMS_CV_CLONE_SOURCE_PATH OLESTR("__CloneSourcePath")
  130. #define WBEMS_CV_OWNER OLESTR("INCLUDE_OWNER")
  131. #define WBEMS_CV_GROUP OLESTR("INCLUDE_GROUP")
  132. #define WBEMS_CV_DACL OLESTR("INCLUDE_DACL")
  133. #define WBEMS_CV_SACL OLESTR("INCLUDE_SACL")
  134. #define ENGLISH_LOCALE 1033
  135. // Useful cleanup macros
  136. #define RELEASEANDNULL(x) \
  137. if (x) \
  138. { \
  139. x->Release (); \
  140. x = NULL; \
  141. }
  142. #define FREEANDNULL(x) \
  143. if (x) \
  144. { \
  145. SysFreeString (x); \
  146. x = NULL; \
  147. }
  148. #define DELETEANDNULL(x) \
  149. if (x) \
  150. { \
  151. delete x; \
  152. x = NULL; \
  153. }
  154. #ifdef _RDEBUG
  155. extern void _RRPrint(int line, const char *file, const char *func,
  156. const char *str, long code, const char *str2);
  157. #define _RD(a) a
  158. #define _RPrint(a,b,c,d) _RRPrint(__LINE__,__FILE__,a,b,c,d)
  159. #else
  160. #define _RD(a)
  161. #define _RPrint(a,b,c,d)
  162. #endif
  163. #endif