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.

341 lines
8.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: output.h
  7. //
  8. // Contents: Header file for classes and function used for display
  9. //
  10. // History: 3-oct-2000 hiteshr Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "gettable.h"
  14. HRESULT LocalCopyString(LPTSTR* ppResult, LPCTSTR pString);
  15. //+--------------------------------------------------------------------------
  16. //
  17. // Class: CDisplay
  18. //
  19. // Purpose: This class is used for displaying a column
  20. //
  21. // History: 3-oct-2000 hiteshr Created
  22. //
  23. //---------------------------------------------------------------------------
  24. class CDisplay
  25. {
  26. #define MAXPAD 80
  27. public:
  28. //
  29. //Initialize the Pad
  30. //
  31. CDisplay()
  32. {
  33. PadChar = L' ';
  34. //Initialize the pad.
  35. for( int i = 0; i < MAXPAD; ++i)
  36. Pad[i] = PadChar;
  37. }
  38. //
  39. //Display width number of Pad Charachter
  40. //
  41. VOID DisplayPad(LONG width)
  42. {
  43. if(width <= 0 )
  44. return;
  45. if(width >= MAXPAD)
  46. width = MAXPAD -1;
  47. Pad[width] = 0;
  48. WriteStandardOut(L"%s",Pad);
  49. Pad[width] = PadChar;
  50. }
  51. //
  52. //Dispaly a column with two starting pad,
  53. //column value and two ending pad
  54. //
  55. VOID DisplayColumn(LONG width, PCWSTR lpszValue)
  56. {
  57. //Display Two PadChar in the begining
  58. DisplayPad(2);
  59. if(lpszValue)
  60. {
  61. WriteStandardOut(lpszValue);
  62. //lpszValue is null terminated.
  63. DisplayPad(width- static_cast<LONG>(wcslen(lpszValue)));
  64. }
  65. else
  66. DisplayPad(width);
  67. //Display Two Trailing Padchar
  68. DisplayPad(2);
  69. }
  70. //
  71. //Display Newline
  72. //
  73. VOID DisplayNewLine()
  74. {
  75. WriteStandardOut(L"%s",L"\r\n");
  76. }
  77. private:
  78. WCHAR Pad[MAXPAD];
  79. WCHAR PadChar;
  80. };
  81. //+--------------------------------------------------------------------------
  82. //
  83. // Class: CFormatInfo
  84. //
  85. // Purpose: Used to format table columns and display table
  86. //
  87. // History: 17-Oct-2000 JeffJon Created
  88. //
  89. //---------------------------------------------------------------------------
  90. class CFormatInfo
  91. {
  92. public:
  93. //
  94. // Constructor
  95. //
  96. CFormatInfo();
  97. //
  98. // Destructor
  99. //
  100. ~CFormatInfo();
  101. //
  102. // Public methods
  103. //
  104. HRESULT Initialize(DWORD dwSampleSize, bool bShowAsList = false, bool bQuiet = false);
  105. inline DWORD GetColWidth(DWORD dwColNum)
  106. {
  107. ASSERT(m_bInitialized);
  108. if(dwColNum >= m_dwNumColumns)
  109. {
  110. ASSERT(FALSE);
  111. return 0;
  112. }
  113. return m_pColWidth[dwColNum];
  114. }
  115. inline void SetColWidth(DWORD dwColNum, DWORD dwWidth)
  116. {
  117. ASSERT(m_bInitialized);
  118. if(dwColNum >= m_dwNumColumns)
  119. {
  120. ASSERT(FALSE);
  121. return;
  122. }
  123. if(dwWidth > m_pColWidth[dwColNum])
  124. {
  125. m_pColWidth[dwColNum] = dwWidth;
  126. }
  127. }
  128. HRESULT AddRow(PDSGET_DISPLAY_INFO pDisplayInfo, DWORD dwColumnCount);
  129. DWORD GetRowCount() { return m_dwTotalRows; }
  130. inline HRESULT Get(DWORD dwRow, DWORD dwCol, CComBSTR& refsbstrColValue)
  131. {
  132. refsbstrColValue.Empty();
  133. ASSERT(m_bInitialized);
  134. if(dwRow >= m_dwTotalRows || dwCol >= m_dwNumColumns)
  135. {
  136. ASSERT(FALSE);
  137. return E_INVALIDARG;
  138. }
  139. refsbstrColValue += m_ppDisplayInfoArray[dwRow][dwCol].GetValue(0);
  140. for (DWORD dwIdx = 1; dwIdx < m_ppDisplayInfoArray[dwRow][dwCol].GetValueCount(); dwIdx++)
  141. {
  142. refsbstrColValue += L";";
  143. refsbstrColValue += m_ppDisplayInfoArray[dwRow][dwCol].GetValue(dwIdx);
  144. }
  145. return S_OK;
  146. }
  147. void DisplayHeaders()
  148. {
  149. ASSERT(m_bInitialized);
  150. if (!m_bQuiet)
  151. {
  152. for( DWORD i = 0; i < m_dwNumColumns; ++i)
  153. {
  154. m_display.DisplayColumn(GetColWidth(i),m_ppDisplayInfoArray[0][i].GetDisplayName());
  155. }
  156. NewLine();
  157. }
  158. }
  159. void DisplayColumn(DWORD dwRow, DWORD dwCol)
  160. {
  161. ASSERT(m_bInitialized);
  162. if(dwRow >= m_dwTotalRows || dwCol >= m_dwNumColumns)
  163. {
  164. ASSERT(FALSE);
  165. return ;
  166. }
  167. if (!m_bQuiet)
  168. {
  169. CComBSTR sbstrValue;
  170. HRESULT hr = Get(dwRow, dwCol, sbstrValue);
  171. if (SUCCEEDED(hr))
  172. {
  173. m_display.DisplayColumn(GetColWidth(dwCol), sbstrValue);
  174. }
  175. }
  176. }
  177. void DisplayColumn(DWORD dwCol, PCWSTR pszValue)
  178. {
  179. ASSERT(m_bInitialized);
  180. if(dwCol >= m_dwNumColumns)
  181. {
  182. ASSERT(FALSE);
  183. return;
  184. }
  185. if (!m_bQuiet)
  186. {
  187. m_display.DisplayColumn(GetColWidth(dwCol), pszValue);
  188. }
  189. }
  190. void Display()
  191. {
  192. ASSERT(m_bInitialized);
  193. if (!m_bListFormat && !m_bQuiet)
  194. {
  195. DisplayHeaders();
  196. for(DWORD i = 0; i < m_dwTotalRows; ++i)
  197. {
  198. for(DWORD j = 0; j < m_dwNumColumns; ++j)
  199. {
  200. DisplayColumn(i,j);
  201. }
  202. NewLine();
  203. }
  204. }
  205. }
  206. void NewLine()
  207. {
  208. if (!m_bQuiet)
  209. {
  210. m_display.DisplayNewLine();
  211. }
  212. }
  213. private:
  214. //
  215. // Private data
  216. //
  217. bool m_bInitialized;
  218. bool m_bListFormat;
  219. bool m_bQuiet;
  220. //
  221. //Number of rows to be used for calulating
  222. //column width. This is also the size of the table.
  223. //
  224. DWORD m_dwSampleSize;
  225. //
  226. //Count of rows in cache
  227. //
  228. DWORD m_dwTotalRows;
  229. //
  230. //Number of columns
  231. //
  232. DWORD m_dwNumColumns;
  233. //
  234. // Array of column widths
  235. //
  236. DWORD* m_pColWidth;
  237. //
  238. // Array of column header/value pairs
  239. //
  240. PDSGET_DISPLAY_INFO* m_ppDisplayInfoArray;
  241. CDisplay m_display;
  242. };
  243. //+--------------------------------------------------------------------------
  244. //
  245. // Function: DsGetOutputValuesList
  246. //
  247. // Synopsis: This function gets the values for the columns and then adds
  248. // the row to the format helper
  249. //
  250. // Arguments: [pszDN IN] : the DN of the object
  251. // [refBasePathsInfo IN] : reference to path info
  252. // [refCredentialObject IN] : reference to the credential manager
  253. // [pCommandArgs IN] : Command line arguments
  254. // [pObjectEntry IN] : Entry in the object table being processed
  255. // [pAttrInfo IN] : the values to display
  256. // [dwAttrCount IN] : Number of arributes in above array
  257. // [spDirObject IN] : Interface pointer to the object
  258. // [refFormatInfo IN]: Reference to the format helper
  259. //
  260. // Returns: HRESULT : S_OK if everything succeeded
  261. // E_INVALIDARG
  262. //
  263. // History: 16-Oct-2000 JeffJon Created
  264. //
  265. //---------------------------------------------------------------------------
  266. HRESULT DsGetOutputValuesList(PCWSTR pszDN,
  267. CDSCmdBasePathsInfo& refBasePathsInfo,
  268. const CDSCmdCredentialObject& refCredentialObject,
  269. PARG_RECORD pCommandArgs,
  270. PDSGetObjectTableEntry pObjectEntry,
  271. DWORD dwAttrCount,
  272. PADS_ATTR_INFO pAttrInfo,
  273. CComPtr<IDirectoryObject>& spDirObject,
  274. CFormatInfo& refFormatInfo);
  275. //+--------------------------------------------------------------------------
  276. //
  277. // Function: GetStringFromADs
  278. //
  279. // Synopsis: Converts Value into string depending upon type
  280. // Arguments: [pValues - IN]: Value to be converted to string
  281. // [dwADsType-IN]: ADSTYPE of pValue
  282. // [ppBuffer - OUT]:Address of an output buffer which gets the string
  283. // [dwBufferLen-IN]:Size of output buffer
  284. // [pszAttrName-IN]:Name of the attribute being formatted
  285. // Returns HRESULT S_OK if Successful
  286. // E_INVALIDARG
  287. // Anything else is a failure code from an ADSI
  288. // call
  289. //
  290. //
  291. // History: 05-OCT-2000 hiteshr Created
  292. //
  293. //---------------------------------------------------------------------------
  294. HRESULT GetStringFromADs(IN const ADSVALUE *pValues,
  295. IN ADSTYPE dwADsType,
  296. OUT LPWSTR* ppBuffer,
  297. IN PCWSTR pszAttrName);