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.

466 lines
13 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. extern bool g_bQuiet;
  14. extern int g_iQueryLimit;
  15. extern bool g_bDeafultLimit;
  16. HRESULT LocalCopyString(LPTSTR* ppResult, LPCTSTR pString);
  17. //+--------------------------------------------------------------------------
  18. //
  19. // Class: CDisplay
  20. //
  21. // Purpose: This class is used for displaying a column
  22. //
  23. // History: 3-oct-2000 hiteshr Created
  24. //
  25. //---------------------------------------------------------------------------
  26. class CDisplay
  27. {
  28. #define MAXPAD 80
  29. public:
  30. //
  31. //Initialize the Pad
  32. //
  33. CDisplay()
  34. {
  35. PadChar = L' ';
  36. //Initialize the pad.
  37. for( int i = 0; i < MAXPAD; ++i)
  38. Pad[i] = PadChar;
  39. }
  40. //
  41. //Display width number of Pad Charachter
  42. //
  43. VOID DisplayPad(LONG width)
  44. {
  45. if(width <= 0 )
  46. return;
  47. if(width >= MAXPAD)
  48. width = MAXPAD -1;
  49. Pad[width] = 0;
  50. DisplayOutputNoNewline(Pad);
  51. Pad[width] = PadChar;
  52. }
  53. //
  54. //Dispaly a column with two starting pad,
  55. //column value and two ending pad
  56. //
  57. VOID DisplayColumn(LONG width, LPWSTR lpszValue)
  58. {
  59. //Display Two PadChar in the begining
  60. DisplayPad(2);
  61. if(lpszValue)
  62. {
  63. DisplayOutputNoNewline(lpszValue);
  64. DisplayPad(width- static_cast<LONG>(wcslen(lpszValue)));
  65. }
  66. else
  67. DisplayPad(width);
  68. //Display Two Trailing Padchar
  69. DisplayPad(2);
  70. }
  71. //
  72. //Display Newline
  73. //
  74. VOID DisplayNewLine()
  75. {
  76. DisplayOutputNoNewline(L"\r\n");
  77. }
  78. private:
  79. WCHAR Pad[MAXPAD];
  80. WCHAR PadChar;
  81. };
  82. //+--------------------------------------------------------------------------
  83. //
  84. // Class: CFormaInfo
  85. //
  86. // Purpose: Used to format table columns and display table
  87. //
  88. // History: 3-oct-2000 hiteshr Created
  89. //
  90. //---------------------------------------------------------------------------
  91. class CFormatInfo
  92. {
  93. public:
  94. CFormatInfo():m_cCol(0),
  95. m_ppszOutPutVal(NULL),
  96. m_pColWidth(NULL),
  97. m_bInit(FALSE),
  98. m_cTotalRow(-1)
  99. {};
  100. ~CFormatInfo()
  101. {
  102. if(m_ppszOutPutVal)
  103. {
  104. for(LONG i = 0; i < m_SampleSize*m_cCol; ++i)
  105. LocalFree(m_ppszOutPutVal[i]);
  106. }
  107. LocalFree(m_ppszOutPutVal);
  108. LocalFree(m_pColWidth);
  109. }
  110. //
  111. //Do the initialization
  112. //
  113. HRESULT Init(LONG sampleSize, LONG cCol, LPWSTR * ppszColHeaders)
  114. {
  115. if(!sampleSize || !cCol || !ppszColHeaders)
  116. {
  117. ASSERT(FALSE);
  118. return E_INVALIDARG;
  119. }
  120. m_SampleSize = sampleSize;
  121. m_cCol = cCol;
  122. m_ppszColHeaders = ppszColHeaders;
  123. m_ppszOutPutVal = (LPWSTR*)LocalAlloc(LPTR,m_SampleSize*cCol*sizeof(LPWSTR*));
  124. if(!m_ppszOutPutVal)
  125. return E_OUTOFMEMORY;
  126. m_pColWidth = (LONG*)LocalAlloc(LPTR, cCol*sizeof(LONG*));
  127. if(!m_pColWidth)
  128. return E_OUTOFMEMORY;
  129. //
  130. //Initialize the minimum column width to width of column heading
  131. //
  132. for(LONG i = 0; i < m_cCol; ++i)
  133. m_pColWidth[i] = static_cast<LONG>(wcslen(m_ppszColHeaders[i]));
  134. m_bInit = TRUE;
  135. return S_OK;
  136. };
  137. //
  138. //Get the Column Width
  139. //
  140. inline
  141. LONG GetColWidth(LONG col)
  142. {
  143. ASSERT(m_bInit);
  144. if(col >= m_cCol)
  145. {
  146. ASSERT(FALSE);
  147. return 0;
  148. }
  149. return m_pColWidth[col];
  150. }
  151. //
  152. //Set the column Width
  153. //
  154. inline
  155. VOID SetColWidth(LONG col, LONG width)
  156. {
  157. ASSERT(m_bInit);
  158. if(col >= m_cCol)
  159. {
  160. ASSERT(FALSE);
  161. return;
  162. }
  163. if(width > m_pColWidth[col])
  164. m_pColWidth[col] = width;
  165. }
  166. //
  167. //Cache the value and update column width
  168. //
  169. BOOL Set(LONG row, LONG col, LPWSTR pszValue)
  170. {
  171. ASSERT(m_bInit);
  172. if(row >= m_SampleSize || col >= m_cCol)
  173. {
  174. ASSERT(FALSE);
  175. return FALSE;
  176. }
  177. if(pszValue)
  178. {
  179. SetColWidth(col, static_cast<LONG>(wcslen(pszValue)));
  180. LocalCopyString((LPWSTR*)(m_ppszOutPutVal + (row*m_cCol) + col),pszValue);
  181. }
  182. if(row>= m_cTotalRow)
  183. m_cTotalRow = row +1;
  184. return TRUE;
  185. }
  186. //
  187. //Total number of rows in cache
  188. //
  189. LONG GetRowCount()
  190. {
  191. return m_cTotalRow;
  192. }
  193. //
  194. //Get the value
  195. //
  196. inline
  197. LPWSTR Get(LONG row, LONG col)
  198. {
  199. ASSERT(m_bInit);
  200. if(row >= m_cTotalRow || col >= m_cCol)
  201. {
  202. ASSERT(FALSE);
  203. return NULL;
  204. }
  205. return (LPWSTR)(*(m_ppszOutPutVal + row*m_cCol +col));
  206. }
  207. //
  208. //Display headers
  209. //
  210. VOID DisplayHeaders()
  211. {
  212. if (g_bQuiet)
  213. {
  214. return;
  215. }
  216. if(!m_ppszColHeaders)
  217. {
  218. ASSERT(m_ppszColHeaders);
  219. return;
  220. }
  221. for( long i = 0; i < m_cCol; ++i)
  222. {
  223. m_display.DisplayColumn(GetColWidth(i),m_ppszColHeaders[i]);
  224. }
  225. NewLine();
  226. }
  227. //
  228. //Display a coulmn which is in cache
  229. //
  230. VOID DisplayColumn(LONG row,LONG col)
  231. {
  232. ASSERT(m_bInit);
  233. if(row >= m_cTotalRow || col >= m_cCol)
  234. {
  235. ASSERT(FALSE);
  236. return ;
  237. }
  238. m_display.DisplayColumn(GetColWidth(col),Get(row,col));
  239. }
  240. //
  241. //Display the value using column width for col
  242. //
  243. VOID DisplayColumn(LONG col, LPWSTR pszValue)
  244. {
  245. if(col >= m_cCol)
  246. {
  247. ASSERT(FALSE);
  248. return;
  249. }
  250. m_display.DisplayColumn(GetColWidth(col),pszValue);
  251. }
  252. //
  253. //Display all rows in cache
  254. //
  255. VOID DisplayAllRows()
  256. {
  257. for(long i = 0; i < m_cTotalRow; ++i)
  258. {
  259. for(long j = 0; j < m_cCol; ++j)
  260. DisplayColumn(i,j);
  261. NewLine();
  262. }
  263. }
  264. //
  265. //Display a newline
  266. //
  267. VOID NewLine(){m_display.DisplayNewLine();}
  268. private:
  269. //
  270. //True if Init is called
  271. //
  272. BOOL m_bInit;
  273. //
  274. //Number of rows to be used for calulating
  275. //column width. This is also the size of the table.
  276. //
  277. LONG m_SampleSize;
  278. //
  279. //Count of rows in cache
  280. //
  281. LONG m_cTotalRow;
  282. //
  283. //Number of columns
  284. //
  285. LONG m_cCol;
  286. LPWSTR *m_ppszOutPutVal;
  287. LONG * m_pColWidth;
  288. //
  289. // Array of column headers. Its assumed that its length is same as m_cCol
  290. //
  291. LPWSTR *m_ppszColHeaders;
  292. CDisplay m_display;
  293. };
  294. //+--------------------------------------------------------------------------
  295. //
  296. // Synopsis: Defines the scopes that a search can be run against when
  297. // looking for a server object
  298. //
  299. // NOTE: If SERVER_QUERY_SCOPE_FOREST is not set then we are scoped
  300. // against a site.
  301. //
  302. //---------------------------------------------------------------------------
  303. #define SERVER_QUERY_SCOPE_SITE 0x00000001
  304. #define SERVER_QUERY_SCOPE_FOREST 0x00000002
  305. #define SERVER_QUERY_SCOPE_DOMAIN 0x00000004
  306. //+--------------------------------------------------------------------------
  307. //
  308. // Function: GetServerSearchRoot
  309. //
  310. // Synopsis: Builds the path to the root of the search as determined by
  311. // the parameters passed in from the command line.
  312. //
  313. // Arguments: [pCommandArgs IN] : the table of the command line input
  314. // [refBasePathsInfo IN] : reference to the base paths info
  315. // [refsbstrDN OUT] : reference to a CComBSTR that will
  316. // receive the DN at which to start
  317. // the search
  318. //
  319. // Returns: DWORD : one of: SERVER_QUERY_SCOPE_FOREST,
  320. // SERVER_QUERY_SCOPE_DOMAIN,
  321. // SERVER_QUERY_SCOPE_SITE
  322. // which define the scope being used
  323. //
  324. // History: 11-Dec-2000 JeffJon Created
  325. //
  326. //---------------------------------------------------------------------------
  327. DWORD GetServerSearchRoot(IN PARG_RECORD pCommandArgs,
  328. IN CDSCmdBasePathsInfo& refBasePathsInfo,
  329. OUT CComBSTR& refsbstrDN);
  330. //+--------------------------------------------------------------------------
  331. //
  332. // Function: GetSubnetSearchRoot
  333. //
  334. // Synopsis: Builds search root path for Subnet. Its always
  335. // cn=subnet,cn=site in configuration container
  336. //
  337. // Arguments: [refBasePathsInfo IN] : reference to the base paths info
  338. // [refsbstrDN OUT] : reference to a CComBSTR that will
  339. // receive the DN at which to start
  340. // the search
  341. //
  342. // Returns: HRESULT
  343. //
  344. // History: 11-Dec-2000 JeffJon Created
  345. //
  346. //---------------------------------------------------------------------------
  347. VOID GetSubnetSearchRoot(IN CDSCmdBasePathsInfo& refBasePathsInfo,
  348. OUT CComBSTR& refsbstrDN);
  349. //+--------------------------------------------------------------------------
  350. //
  351. // Function: GetSiteContainerPath
  352. //
  353. // Synopsis: Returns the DN for site container in Configuration
  354. // container
  355. //
  356. // Arguments: [refBasePathsInfo IN] : reference to the base paths info
  357. // [refsbstrDN OUT] : reference to a CComBSTR that will
  358. // receive the DN
  359. //
  360. // Returns: HRESULT
  361. //
  362. // History: 24-April-2001 hiteshr Created
  363. //
  364. //---------------------------------------------------------------------------
  365. VOID GetSiteContainerPath(IN CDSCmdBasePathsInfo& refBasePathsInfo,
  366. OUT CComBSTR& refSubSiteSuffix);
  367. //+--------------------------------------------------------------------------
  368. //
  369. // Function: DsQueryServerOutput
  370. //
  371. // Synopsis: This functions outputs the query results for server object.
  372. //
  373. // Arguments: [outputFormat IN] Output format specified at commandline.
  374. // [ppszAttributes IN] List of attributes fetched by query
  375. // [cAttributes,IN] Number of arributes in above array
  376. // [refServerSearch,IN]reference to the search Object
  377. // [refCredObject IN] reference to the credential object
  378. // [refBasePathsInfo IN] reference to the base paths info
  379. // [pCommandArgs,IN] The pointer to the commands table
  380. //
  381. // Returns: HRESULT : S_OK if everything succeeded
  382. // E_INVALIDARG
  383. // Anything else is a failure code from an ADSI call
  384. //
  385. // History: 08-Dec-2000 JeffJon Created
  386. //
  387. //---------------------------------------------------------------------------
  388. HRESULT DsQueryServerOutput( IN DSQUERY_OUTPUT_FORMAT outputFormat,
  389. IN LPWSTR* ppszAttributes,
  390. IN DWORD cAttributes,
  391. IN CDSSearch& refServerSearch,
  392. IN const CDSCmdCredentialObject& refCredObject,
  393. IN CDSCmdBasePathsInfo& refBasePathsInfo,
  394. IN PARG_RECORD pCommandArgs);
  395. //+--------------------------------------------------------------------------
  396. //
  397. // Function: DsQueryOutput
  398. //
  399. // Synopsis: This functions outputs the query results.
  400. //
  401. // Arguments: [outputFormat IN] Output format specified at commandline.
  402. // [ppszAttributes IN] List of attributes fetched by query
  403. // [cAttributes,IN] Number of arributes in above array
  404. // [*pSeach,IN] Search Object which has queryhandle
  405. // [bListFormat IN] Is Output to shown in List Format.
  406. // This is valid for "dsquery *" only.
  407. // Returns: HRESULT : S_OK if everything succeeded
  408. // E_INVALIDARG
  409. // Anything else is a failure code from an ADSI call
  410. //
  411. // History: 25-Sep-2000 hiteshr Created
  412. //
  413. //---------------------------------------------------------------------------
  414. HRESULT DsQueryOutput( IN DSQUERY_OUTPUT_FORMAT outputFormat,
  415. IN LPWSTR * ppszAttributes,
  416. IN DWORD cAttributes,
  417. IN CDSSearch *pSearch,
  418. IN BOOL bListFormat );