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
7.2 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. WBEMUTIL.CPP
  5. Abstract:
  6. General utility functions prototypes and macros.
  7. History:
  8. a-raymcc 17-Apr-96 Created.
  9. --*/
  10. #ifndef _WBEMUTIL_H_
  11. #define _WBEMUTIL_H_
  12. #include "corepol.h"
  13. #define STRSAFE_NO_DEPRECATE
  14. #include <strsafe.h>
  15. #include <stdio.h>
  16. void _inline DbgPrintfA(ULONG_PTR pBuff, const char * fmt,...)
  17. {
  18. char pBuff_[128];
  19. va_list argptr;
  20. va_start(argptr, fmt);
  21. StringCchVPrintfA(pBuff_,128,fmt,argptr);
  22. OutputDebugStringA(pBuff_);
  23. va_end(argptr);
  24. };
  25. //
  26. // must be used this way DBG_PRINTFA((pBuff,"FormatString %s %d",Param1,Param2,etc))
  27. //
  28. #ifdef DBG
  29. #define DBG_PRINTFA( a ) { ULONG_PTR pBuff = 0; DbgPrintfA a ; }
  30. #else
  31. #define DBG_PRINTFA( a )
  32. #endif
  33. BOOL POLARITY WbemGetMachineShutdown();
  34. BOOL POLARITY WbemSetMachineShutdown(BOOL bVal);
  35. #ifndef VARIANT_TRUE
  36. #define VARIANT_TRUE ((VARIANT_BOOL) 0xFFFF)
  37. #define VARIANT_FALSE (0)
  38. #endif
  39. #define DUP_STRING_NEW(dest,src) \
  40. { size_t tmpLenDoNotReuse = wcslen(src)+1; \
  41. dest = new wchar_t[tmpLenDoNotReuse]; \
  42. if (dest) StringCchCopyW(dest,tmpLenDoNotReuse , src); }
  43. #ifdef __cplusplus
  44. inline wchar_t *Macro_CloneLPWSTR(LPCWSTR src)
  45. {
  46. if (!src)
  47. return 0;
  48. wchar_t *dest = new wchar_t[wcslen(src) + 1];
  49. if (!dest)
  50. return 0;
  51. memcpy(dest, src, sizeof(wchar_t)*(wcslen(src) + 1));
  52. return dest;
  53. }
  54. #endif
  55. #if (defined DBG || defined _DBG)
  56. #if defined(__cplusplus)
  57. void inline PrintAssert(const wchar_t * msg) { OutputDebugStringW(msg); }
  58. void inline PrintAssert(const char * msg) { OutputDebugStringA(msg); }
  59. #else
  60. void _inline PrintAssert(const wchar_t * msg) { OutputDebugStringW(msg); }
  61. #endif
  62. #pragma message("_ASSERTs are being expanded.")
  63. #define _ASSERT(exp, msg) { if (!(exp)) { PrintAssert( msg ); DebugBreak(); } }
  64. #else
  65. #define _ASSERT(exp, msg)
  66. #endif
  67. #ifdef DBG
  68. #define _DBG_MSG_ASSERT(X, msg) { if (!(X)) { OutputDebugStringW( msg ); DebugBreak(); } }
  69. #define _DBG_ASSERT(X) { if (!(X)) { DebugBreak(); } }
  70. #else
  71. #define _DBG_MSG_ASSERT(X, msg)
  72. #define _DBG_ASSERT(X)
  73. #endif
  74. //LOGGING module.
  75. //This is an index into an array in wbemutil.cpp which uses
  76. //the filenames specified next
  77. #define LOG_WBEMCORE 0
  78. #define LOG_WINMGMT 1
  79. #define LOG_ESS 2
  80. #define LOG_WBEMPROX 3
  81. #define LOG_WBEMSTUB 4
  82. #define LOG_QUERY 5
  83. #define LOG_MOFCOMP 6
  84. #define LOG_EVENTLOG 7
  85. #define LOG_WBEMDISP 8
  86. #define LOG_STDPROV 9
  87. #define LOG_WIMPROV 10
  88. #define LOG_WMIOLEDB 11
  89. #define LOG_WMIADAP 12
  90. #define LOG_REPDRV 13
  91. #define LOG_PROVSS 14
  92. #define LOG_EVTPROV 15
  93. #define LOG_VIEWPROV 16
  94. #define LOG_DSPROV 17
  95. #define LOG_SNMPPROV 18
  96. #define LOG_PROVTHRD 19
  97. #define LOG_MAX_PROV 20
  98. //These are the log file names (possibly other things
  99. //as well!) which is used in conjunction with the above
  100. //ids.
  101. #define FILENAME_PREFIX_CORE TEXT("wbemcore")
  102. #define FILENAME_PREFIX_EXE TEXT("WinMgmt")
  103. #define FILENAME_PREFIX_EXE_W L"WinMgmt"
  104. #define FILENAME_PREFIX_CLI_MARSH TEXT("wbemprox")
  105. #define FILENAME_PREFIX_SERV_MARSH TEXT("wbemstub")
  106. #define FILENAME_PREFIX_ESS TEXT("wbemess")
  107. #define FILENAME_PREFIX_QUERY TEXT("query")
  108. #define FILENAME_PROFIX_MOFCOMP TEXT("mofcomp")
  109. #define FILENAME_PROFIX_EVENTLOG TEXT("eventlog")
  110. #define FILENAME_PROFIX_WBEMDISP TEXT("wbemdisp")
  111. #define FILENAME_PROFIX_STDPROV TEXT("stdprov")
  112. #define FILENAME_PROFIX_WMIPROV TEXT("wmiprov")
  113. #define FILENAME_PROFIX_WMIOLEDB TEXT("wmioledb")
  114. #define FILENAME_PREFIX_WMIADAP TEXT("wmiadap")
  115. #define FILENAME_PREFIX_REPDRV TEXT("replog")
  116. #define FILENAME_PREFIX_PROVSS TEXT("provss")
  117. #define FILENAME_PREFIX_EVTPROV TEXT("ntevt")
  118. #define FILENAME_PREFIX_VIEWPROV TEXT("viewprov")
  119. #define FILENAME_PREFIX_DSPROV TEXT("dsprovider")
  120. #define FILENAME_PREFIX_SNMPPROV TEXT("wbemsnmp")
  121. #define FILENAME_PREFIX_PROVTHRD TEXT("provthrd")
  122. // True if unicode identifier, _, a-z, A-Z or 0x100-0xffef
  123. BOOL POLARITY isunialpha(wchar_t c);
  124. BOOL POLARITY isunialphanum(wchar_t c);
  125. BOOL POLARITY IsValidElementName(LPCWSTR wszName, DWORD MaxAllow);
  126. // Can't use overloading and/or default parameters because
  127. // "C" files use these guys. No, I'm not happy about
  128. // this!
  129. BOOL POLARITY IsValidElementName2(LPCWSTR wszName, DWORD MaxAllow, BOOL bAllowUnderscore);
  130. BOOL POLARITY LoggingLevelEnabled(DWORD nLevel);
  131. DWORD POLARITY GetLoggingLevelEnabled();
  132. #define TRACE(x) DebugTrace x
  133. #define ERRORTRACE(x) ErrorTrace x
  134. #define DEBUGTRACE(x) DebugTrace x
  135. int POLARITY DebugTrace(char cCaller, const char *fmt, ...);
  136. int POLARITY ErrorTrace(char cCaller, const char *fmt, ...);
  137. int POLARITY CriticalFailADAPTrace(const char *string);
  138. // BLOB manipulation.
  139. // ==================
  140. BLOB POLARITY BlobCopy(const BLOB *pSrc);
  141. void POLARITY BlobClear(BLOB *pSrc);
  142. void POLARITY BlobAssign(BLOB *pSrc, LPVOID pBytes, DWORD dwCount, BOOL bAcquire);
  143. #define BlobInit(p) \
  144. ((p)->cbSize = 0, (p)->pBlobData = 0)
  145. #define BlobLength(p) ((p)->cbSize)
  146. #define BlobDataPtr(p) ((p)->pBlobData)
  147. // Object ref count helpers.
  148. // =========================
  149. void ObjectCreated(DWORD,IUnknown * pThis);
  150. void ObjectDestroyed(DWORD,IUnknown * pThis);
  151. #define MAX_OBJECT_TYPES 16
  152. #define OBJECT_TYPE_LOCATOR 0
  153. #define OBJECT_TYPE_CLSOBJ 1
  154. #define OBJECT_TYPE_PROVIDER 2
  155. #define OBJECT_TYPE_QUALIFIER 3
  156. #define OBJECT_TYPE_NOTIFY 4
  157. #define OBJECT_TYPE_OBJENUM 5
  158. #define OBJECT_TYPE_FACTORY 6
  159. #define OBJECT_TYPE_WBEMLOGIN 7
  160. #define OBJECT_TYPE_WBEMLOGINHELP 8
  161. #define OBJECT_TYPE_CORE_BUSY 9
  162. #define OBJECT_TYPE_STATUS 10
  163. #define OBJECT_TYPE_BACKUP_RESTORE 11
  164. #define OBJECT_TYPE_PATH_PARSER 12
  165. #define OBJECT_TYPE_WMIARRAY 13
  166. #define OBJECT_TYPE_OBJ_FACTORY 14
  167. #define OBJECT_TYPE_FREEFORM_OBJ 15
  168. //Creates directories recursively
  169. BOOL POLARITY WbemCreateDirectory(const TCHAR *szDirectory);
  170. HRESULT POLARITY TestDirExistAndCreateWithSDIfNotThere(TCHAR * pDirectory, TCHAR * pSDDLString);
  171. #define VT_EMBEDDED_OBJECT VT_UNKNOWN
  172. #define V_EMBEDDED_OBJECT(VAR) V_UNKNOWN(VAR)
  173. #define I_EMBEDDED_OBJECT IUnknown
  174. #define IDISPATCH_METHODS_STUB \
  175. STDMETHOD(GetTypeInfoCount)(UINT* pctinfo) \
  176. {return E_NOTIMPL;} \
  177. STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)\
  178. {return E_NOTIMPL;} \
  179. STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR** rgszNames, UINT cNames,\
  180. LCID lcid, DISPID* rgdispid) \
  181. {return E_NOTIMPL;} \
  182. STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,\
  183. DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, \
  184. UINT* puArgErr) \
  185. {return E_NOTIMPL;} \
  186. // Quick WCHAR to MBS conversion helper
  187. BOOL POLARITY AllocWCHARToMBS( WCHAR* pWstr, char** ppStr );
  188. // Helpers needed in a couple of places.
  189. LPTSTR POLARITY GetWMIADAPCmdLine( int nExtra );
  190. BOOL POLARITY IsNtSetupRunning();
  191. #endif