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.

2362 lines
58 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: aqadmcli.cpp
  5. //
  6. // Description:
  7. // Unit test for AQAdmin interface
  8. //
  9. // Author:
  10. // Aldrin Teganeanu (aldrint)
  11. // Mike Swafford (MikeSwa)
  12. //
  13. // History:
  14. // 6/5/99 - MikeSwa Updated to new AQAdmin interface
  15. //
  16. // Copyright (C) 1998 Microsoft Corporation
  17. //
  18. //-----------------------------------------------------------------------------
  19. #include "stdinc.h"
  20. const CLSID CLSID_MAQAdmin = {0x0427FFA4,0xAF27,0x11d2,{0x8F,0xAF,0x00,0xC0,0x4F,0xA3,0x78,0xFF}};
  21. //Utility for converting To UNICODE... uses LocalAlloc()
  22. LPWSTR wszGetUnicodeArg(LPSTR szSrc, DWORD cSrc)
  23. {
  24. LPWSTR wszDest = NULL;
  25. CHAR chSave = '\0';
  26. if (!szSrc || !cSrc)
  27. return NULL;
  28. wszDest = (LPWSTR) LocalAlloc(LPTR, (cSrc+1)*sizeof(WCHAR));
  29. if (!wszDest)
  30. return NULL;
  31. chSave = szSrc[cSrc];
  32. szSrc[cSrc] = '\0';
  33. MultiByteToWideChar(CP_ACP,
  34. 0,
  35. szSrc,
  36. -1,
  37. wszDest,
  38. cSrc+1);
  39. szSrc[cSrc] = chSave;
  40. return wszDest;
  41. }
  42. //prints queue link info if it has it
  43. void PrintQueueLinkInfo(IUnknown *pIUnknown)
  44. {
  45. HRESULT hr = S_OK;
  46. IUniqueId *pIUniqueId = NULL;
  47. QUEUELINK_ID *pqlid = NULL;
  48. CHAR szGuid[100] = "";
  49. hr = pIUnknown->QueryInterface(IID_IUniqueId,
  50. (void **) &pIUniqueId);
  51. if (FAILED(hr))
  52. goto Exit;
  53. hr = pIUniqueId->GetUniqueId(&pqlid);
  54. if (FAILED(hr)) {
  55. printf ("GetQueueLinkId failied with hr 0x%08X\n", hr);
  56. goto Exit;
  57. }
  58. //
  59. // Get string-ized form of GUID
  60. //
  61. StringFromGUID2(pqlid->uuid, (LPOLESTR) szGuid, sizeof(szGuid)-1);
  62. printf("QLID:: type %s : Name %S : ID 0x%08X : Guid %S\n",
  63. (pqlid->qltType == QLT_LINK) ? "link" : ((pqlid->qltType == QLT_QUEUE) ? "queue" : "none"),
  64. pqlid->szName, pqlid->dwId, szGuid);
  65. Exit:
  66. if (pIUniqueId)
  67. pIUniqueId->Release();
  68. }
  69. //Helper function qo QI and call ApplyActionToMessages
  70. HRESULT ApplyActionToMessages(IUnknown *pIUnknown,
  71. MESSAGE_FILTER *pFilter,
  72. MESSAGE_ACTION Action,
  73. DWORD *pcMsgs)
  74. {
  75. HRESULT hr = S_OK;
  76. IAQMessageAction *pIAQMessageAction = NULL;
  77. if (!pIUnknown)
  78. return E_POINTER;
  79. hr = pIUnknown->QueryInterface(IID_IAQMessageAction,
  80. (void **) &pIAQMessageAction);
  81. if (FAILED(hr))
  82. return hr;
  83. if (!pIAQMessageAction)
  84. return E_FAIL;
  85. hr = pIAQMessageAction->ApplyActionToMessages(pFilter, Action, pcMsgs);
  86. pIAQMessageAction->Release();
  87. return hr;
  88. }
  89. HRESULT CAQAdminCli::SetMsgAction(MESSAGE_ACTION *pAction, CCmdInfo *pCmd)
  90. {
  91. char buf[64];
  92. HRESULT hr = S_OK;
  93. hr = pCmd->GetValue("ma", buf);
  94. if(SUCCEEDED(hr))
  95. {
  96. // set the action
  97. if(!lstrcmpi(buf, "DEL"))
  98. (*pAction) = MA_DELETE;
  99. else if(!lstrcmpi(buf, "DEL_S"))
  100. (*pAction) = MA_DELETE_SILENT;
  101. else if(!lstrcmpi(buf, "FREEZE"))
  102. (*pAction) = MA_FREEZE_GLOBAL;
  103. else if(!lstrcmpi(buf, "THAW"))
  104. (*pAction) = MA_THAW_GLOBAL;
  105. else if(!lstrcmpi(buf, "COUNT"))
  106. (*pAction) = MA_COUNT;
  107. else
  108. hr = E_FAIL;
  109. }
  110. return hr;
  111. }
  112. //---[ CAQAdminCli::SetServer ]------------------------------------------------
  113. //
  114. //
  115. // Description:
  116. // Sets the remote server and virtual server to connect to
  117. // Parameters:
  118. // IN szServerName The name of the server to connect to
  119. // IN szVSNumber The stringized version number of the virtual
  120. // server to connect to.
  121. // Returns:
  122. // S_OK on success
  123. // Error code from GetVirtualServerAdminITF
  124. // History:
  125. // 6/5/99 - MikeSwa Updated to supply UNICODE arguments
  126. //
  127. //-----------------------------------------------------------------------------
  128. HRESULT CAQAdminCli::SetServer(LPSTR szServerName, LPSTR szVSNumber)
  129. {
  130. IVSAQAdmin *pTmpVS = NULL;
  131. WCHAR wszServerName[200];
  132. WCHAR wszVSNumber[200] = L"1";
  133. DWORD cServerName = 0;
  134. DWORD cVSNumber = 0;
  135. HRESULT hr = S_OK;
  136. *wszServerName = L'\0';
  137. if (szServerName && *szServerName)
  138. {
  139. cServerName = strlen(szServerName);
  140. if (cServerName*sizeof(WCHAR) < sizeof(wszServerName))
  141. {
  142. MultiByteToWideChar(CP_ACP,
  143. 0,
  144. szServerName,
  145. -1,
  146. wszServerName,
  147. cServerName+1);
  148. }
  149. }
  150. if (szVSNumber && *szVSNumber)
  151. {
  152. cVSNumber = strlen(szVSNumber);
  153. if (cVSNumber*sizeof(WCHAR) < sizeof(wszVSNumber))
  154. {
  155. MultiByteToWideChar(CP_ACP,
  156. 0,
  157. szVSNumber,
  158. -1,
  159. wszVSNumber,
  160. cVSNumber+1);
  161. }
  162. }
  163. // not going to release the old server until I'm sure
  164. // that I got the new one.
  165. hr = m_pAdmin->GetVirtualServerAdminITF(wszServerName, wszVSNumber, &pTmpVS);
  166. if(FAILED(hr))
  167. {
  168. printf("Error: GetVirtualServerAdminITF for \"%s\" failed with 0x%x\n", szServerName, hr);
  169. }
  170. else
  171. {
  172. if(NULL != m_pVS)
  173. m_pVS->Release();
  174. m_pVS = pTmpVS;
  175. }
  176. return hr;
  177. }
  178. BOOL CAQAdminCli::StringToUTCTime(LPSTR szTime, SYSTEMTIME *pstUTCTime)
  179. {
  180. // read the date
  181. WORD wMonth, wDay, wYear, wHour, wMinute, wSecond, wMilliseconds;
  182. BOOL res;
  183. int n = sscanf(szTime, "%d/%d/%d %d:%d:%d:%d",
  184. &(wMonth),
  185. &(wDay),
  186. &(wYear),
  187. &(wHour),
  188. &(wMinute),
  189. &(wSecond),
  190. &(wMilliseconds));
  191. if(n == 7)
  192. {
  193. // check if it's GMT or UTC time
  194. if(NULL == strstr(szTime, "UTC") && NULL == strstr(szTime, "GMT"))
  195. {
  196. // this is local time
  197. SYSTEMTIME stLocTime;
  198. ZeroMemory(&stLocTime, sizeof(SYSTEMTIME));
  199. stLocTime.wMonth = wMonth;
  200. stLocTime.wDay = wDay;
  201. stLocTime.wYear = wYear;
  202. stLocTime.wHour = wHour;
  203. stLocTime.wMinute = wMinute;
  204. stLocTime.wSecond = wSecond;
  205. stLocTime.wMilliseconds = wMilliseconds;
  206. // convert from local time to UTC time
  207. if(!LocalTimeToUTC(&stLocTime, pstUTCTime))
  208. {
  209. printf("Cannot convert from local time to UTC\n");
  210. res = FALSE;
  211. goto Exit;
  212. }
  213. }
  214. else
  215. {
  216. // it's already UTC time
  217. pstUTCTime->wMonth = wMonth;
  218. pstUTCTime->wDay = wDay;
  219. pstUTCTime->wYear = wYear;
  220. pstUTCTime->wHour = wHour;
  221. pstUTCTime->wMinute = wMinute;
  222. pstUTCTime->wSecond = wSecond;
  223. pstUTCTime->wMilliseconds = wMilliseconds;
  224. }
  225. }
  226. Exit:
  227. return res;
  228. }
  229. BOOL CAQAdminCli::LocalTimeToUTC(SYSTEMTIME *pstLocTime, SYSTEMTIME *pstUTCTime)
  230. {
  231. // the only way I know how to do it is:
  232. // - convert local system time to local file time
  233. // - convert local file time to UTC file time
  234. // - convert UTC file time to UTC system time
  235. FILETIME ftLocTime, ftUTCTime;
  236. BOOL res;
  237. res = SystemTimeToFileTime(pstLocTime, &ftLocTime);
  238. res = res && LocalFileTimeToFileTime(&ftLocTime, &ftUTCTime);
  239. res = res && FileTimeToSystemTime(&ftUTCTime, pstUTCTime);
  240. return res;
  241. }
  242. void CAQAdminCli::FreeStruct(LINK_INFO *pStruct)
  243. {
  244. if(NULL != pStruct->szLinkName)
  245. {
  246. pStruct->szLinkName = NULL;
  247. }
  248. }
  249. void CAQAdminCli::FreeStruct(QUEUE_INFO *pStruct)
  250. {
  251. if(NULL != pStruct->szQueueName)
  252. {
  253. pStruct->szQueueName = NULL;
  254. }
  255. if(NULL != pStruct->szLinkName)
  256. {
  257. pStruct->szLinkName = NULL;
  258. }
  259. }
  260. void CAQAdminCli::FreeStruct(MESSAGE_INFO *pStruct)
  261. {
  262. if(NULL != pStruct->szMessageId)
  263. {
  264. pStruct->szMessageId = NULL;
  265. }
  266. if(NULL != pStruct->szSender)
  267. {
  268. pStruct->szSender = NULL;
  269. }
  270. if(NULL != pStruct->szSubject)
  271. {
  272. pStruct->szSubject = NULL;
  273. }
  274. if(NULL != pStruct->szRecipients)
  275. {
  276. pStruct->szRecipients = NULL;
  277. }
  278. if(NULL != pStruct->szCCRecipients)
  279. {
  280. pStruct->szCCRecipients = NULL;
  281. }
  282. if(NULL != pStruct->szBCCRecipients)
  283. {
  284. pStruct->szBCCRecipients = NULL;
  285. }
  286. }
  287. void CAQAdminCli::FreeStruct(MESSAGE_FILTER *pStruct)
  288. {
  289. if(NULL != pStruct->szMessageId)
  290. {
  291. LocalFree((void*)pStruct->szMessageId);
  292. pStruct->szMessageId = NULL;
  293. }
  294. if(NULL != pStruct->szMessageSender)
  295. {
  296. LocalFree((void*)pStruct->szMessageSender);
  297. pStruct->szMessageSender = NULL;
  298. }
  299. if(NULL != pStruct->szMessageRecipient)
  300. {
  301. LocalFree((void*)pStruct->szMessageRecipient);
  302. pStruct->szMessageRecipient = NULL;
  303. }
  304. }
  305. ////////////////////////////////////////////////////////////////////////////
  306. // Method: SetMsgFilter()
  307. // Member of:
  308. // Arguments:
  309. // Returns:
  310. // Description:
  311. ////////////////////////////////////////////////////////////////////////////
  312. HRESULT CAQAdminCli::SetMsgFilter(MESSAGE_FILTER *pFilter, CCmdInfo *pCmd)
  313. {
  314. HRESULT hr = S_OK;
  315. char *buf = NULL;
  316. int nFlagsOK = 0;
  317. ZeroMemory(pFilter, sizeof(MESSAGE_FILTER));
  318. pFilter->dwVersion = CURRENT_QUEUE_ADMIN_VERSION;
  319. hr = pCmd->AllocValue("flags", &buf);
  320. if(SUCCEEDED(hr))
  321. {
  322. // set the filter type
  323. char *token = strtok(buf, "|");
  324. while(token != NULL)
  325. {
  326. // strip the spaces
  327. char *st, *en;
  328. for(st = token; isspace(*st); st++);
  329. for(en = st; *en; en++);
  330. for(--en; en > st && isspace(*en); en--);
  331. if(en - st + 1 > 0)
  332. {
  333. // found a flag
  334. char flag[64];
  335. ZeroMemory(flag, sizeof(flag));
  336. CopyMemory(flag, st, en - st + 1);
  337. if(!lstrcmpi(flag, "MSGID"))
  338. {
  339. nFlagsOK++;
  340. pFilter->fFlags |= MF_MESSAGEID;
  341. }
  342. else if(!lstrcmpi(flag, "SENDER"))
  343. {
  344. nFlagsOK++;
  345. pFilter->fFlags |= MF_SENDER;
  346. }
  347. else if(!lstrcmpi(flag, "RCPT"))
  348. {
  349. nFlagsOK++;
  350. pFilter->fFlags |= MF_RECIPIENT;
  351. }
  352. else if(!lstrcmpi(flag, "SIZE"))
  353. {
  354. nFlagsOK++;
  355. pFilter->fFlags |= MF_SIZE;
  356. }
  357. else if(!lstrcmpi(flag, "TIME"))
  358. {
  359. nFlagsOK++;
  360. pFilter->fFlags |= MF_TIME;
  361. }
  362. else if(!lstrcmpi(flag, "FROZEN"))
  363. {
  364. nFlagsOK++;
  365. pFilter->fFlags |= MF_FROZEN;
  366. }
  367. else if(!lstrcmpi(flag, "NOT"))
  368. {
  369. nFlagsOK++;
  370. pFilter->fFlags |= MF_INVERTSENSE;
  371. }
  372. else if(!lstrcmpi(flag, "ALL"))
  373. {
  374. nFlagsOK++;
  375. pFilter->fFlags |= MF_ALL;
  376. }
  377. }
  378. token = strtok(NULL, "|");
  379. }
  380. }
  381. // if no valid flags or no flags at all fail
  382. if(0 == nFlagsOK)
  383. {
  384. printf("Error: no flags specified for the filter\n");
  385. hr = E_FAIL;
  386. goto Exit;
  387. }
  388. // set the message id
  389. nFlagsOK = 0;
  390. hr = pCmd->AllocValue("id", &buf);
  391. if(SUCCEEDED(hr))
  392. {
  393. // strip the spaces
  394. char *st, *en;
  395. for(st = buf; isspace(*st); st++);
  396. for(en = st; *en; en++);
  397. for(--en; en > st && isspace(*en); en--);
  398. if(en - st + 1 > 0)
  399. {
  400. // found a string
  401. pFilter->szMessageId = wszGetUnicodeArg(st, (DWORD) (en-st+1));
  402. if(NULL == pFilter->szMessageId)
  403. {
  404. printf("Error: LocalAlloc failed\n");
  405. hr = E_OUTOFMEMORY;
  406. }
  407. nFlagsOK++;
  408. }
  409. }
  410. // set the message sender
  411. nFlagsOK = 0;
  412. hr = pCmd->AllocValue("sender", &buf);
  413. if(SUCCEEDED(hr))
  414. {
  415. // strip the spaces
  416. char *st, *en;
  417. for(st = buf; isspace(*st); st++);
  418. for(en = st; *en; en++);
  419. for(--en; en > st && isspace(*en); en--);
  420. if(en - st + 1 > 0)
  421. {
  422. // found a string
  423. pFilter->szMessageSender = wszGetUnicodeArg(st, (DWORD) (en-st+1));
  424. if(NULL == pFilter->szMessageSender)
  425. {
  426. printf("Error: LocalAlloc failed\n");
  427. hr = E_OUTOFMEMORY;
  428. }
  429. nFlagsOK++;
  430. }
  431. }
  432. // set the message recipient
  433. nFlagsOK = 0;
  434. hr = pCmd->AllocValue("rcpt", &buf);
  435. if(SUCCEEDED(hr))
  436. {
  437. // strip the spaces
  438. char *st, *en;
  439. for(st = buf; isspace(*st); st++);
  440. for(en = st; *en; en++);
  441. for(--en; en > st && isspace(*en); en--);
  442. if(en - st + 1 > 0)
  443. {
  444. // found a string
  445. pFilter->szMessageRecipient = wszGetUnicodeArg(st, (DWORD) (en-st+1));
  446. if(NULL == pFilter->szMessageRecipient)
  447. {
  448. printf("Error: LocalAlloc failed\n");
  449. hr = E_OUTOFMEMORY;
  450. }
  451. nFlagsOK++;
  452. }
  453. }
  454. // set the min message size
  455. nFlagsOK = 0;
  456. hr = pCmd->AllocValue("size", &buf);
  457. if(SUCCEEDED(hr))
  458. {
  459. // strip the spaces
  460. char *st, *en;
  461. for(st = buf; isspace(*st); st++);
  462. for(en = st; *en; en++);
  463. for(--en; en > st && isspace(*en); en--);
  464. if(en - st + 1 > 0)
  465. {
  466. // found a string
  467. char aux[64];
  468. CopyMemory(aux, st, en - st + 1);
  469. int n = atoi(aux);
  470. pFilter->dwLargerThanSize = n;
  471. nFlagsOK++;
  472. }
  473. }
  474. // set the message date
  475. nFlagsOK = 0;
  476. hr = pCmd->AllocValue("date", &buf);
  477. if(SUCCEEDED(hr))
  478. {
  479. if(StringToUTCTime(buf, &(pFilter->stOlderThan)))
  480. nFlagsOK++;
  481. }
  482. // if no valid no. or no no. at all, set the default
  483. if(0 == nFlagsOK)
  484. {
  485. ZeroMemory(&(pFilter->stOlderThan), sizeof(SYSTEMTIME));
  486. }
  487. // if we came this far all is well
  488. hr = S_OK;
  489. Exit:
  490. if(NULL != buf)
  491. delete [] buf;
  492. // TODO: validate the filter
  493. return hr;
  494. }
  495. ////////////////////////////////////////////////////////////////////////////
  496. // Method: SetMsgEnumFilter()
  497. // Member of:
  498. // Arguments:
  499. // Returns:
  500. // Description:
  501. ////////////////////////////////////////////////////////////////////////////
  502. //1/18/99: AldrinT: updated flag parsing for SENDER and RCPT
  503. HRESULT CAQAdminCli::SetMsgEnumFilter(MESSAGE_ENUM_FILTER *pFilter, CCmdInfo *pCmd)
  504. {
  505. HRESULT hr;
  506. char *buf = NULL;
  507. int nFlagsOK = 0;
  508. ZeroMemory(pFilter, sizeof(MESSAGE_ENUM_FILTER));
  509. pFilter->dwVersion = CURRENT_QUEUE_ADMIN_VERSION;
  510. hr = pCmd->AllocValue("ft", &buf);
  511. if(SUCCEEDED(hr))
  512. {
  513. // set the filter type
  514. char *token = strtok(buf, "|");
  515. while(token != NULL)
  516. {
  517. // strip the spaces
  518. char *st, *en;
  519. for(st = token; isspace(*st); st++);
  520. for(en = st; *en; en++);
  521. for(--en; en > st && isspace(*en); en--);
  522. if(en - st + 1 > 0)
  523. {
  524. // found a flag
  525. char flag[64];
  526. ZeroMemory(flag, sizeof(flag));
  527. CopyMemory(flag, st, en - st + 1);
  528. if(!lstrcmpi(flag, "FIRST_N"))
  529. {
  530. nFlagsOK++;
  531. pFilter->mefType |= MEF_FIRST_N_MESSAGES;
  532. }
  533. else if(!lstrcmpi(flag, "OLDER"))
  534. {
  535. nFlagsOK++;
  536. pFilter->mefType |= MEF_OLDER_THAN;
  537. }
  538. else if(!lstrcmpi(flag, "OLDEST"))
  539. {
  540. nFlagsOK++;
  541. pFilter->mefType |= MEF_N_OLDEST_MESSAGES;
  542. }
  543. else if(!lstrcmpi(flag, "LARGER"))
  544. {
  545. nFlagsOK++;
  546. pFilter->mefType |= MEF_LARGER_THAN;
  547. }
  548. else if(!lstrcmpi(flag, "LARGEST"))
  549. {
  550. nFlagsOK++;
  551. pFilter->mefType |= MEF_N_LARGEST_MESSAGES;
  552. }
  553. else if(!lstrcmpi(flag, "FROZEN"))
  554. {
  555. nFlagsOK++;
  556. pFilter->mefType |= MEF_FROZEN;
  557. }
  558. else if(!lstrcmpi(flag, "NOT"))
  559. {
  560. nFlagsOK++;
  561. pFilter->mefType |= MEF_INVERTSENSE;
  562. }
  563. else if(!lstrcmpi(flag, "ALL"))
  564. {
  565. nFlagsOK++;
  566. pFilter->mefType |= MEF_ALL;
  567. }
  568. else if(!lstrcmpi(flag, "SENDER"))
  569. {
  570. nFlagsOK++;
  571. pFilter->mefType |= MEF_SENDER;
  572. }
  573. else if(!lstrcmpi(flag, "RCPT"))
  574. {
  575. nFlagsOK++;
  576. pFilter->mefType |= MEF_RECIPIENT;
  577. }
  578. }
  579. token = strtok(NULL, "|");
  580. }
  581. }
  582. // Ifdef'd code because this is actually a valid state for skipping messages
  583. // 12/13/98 - MikeSwa
  584. #ifdef NEVER
  585. // if no valid flags or no flags at all, fail
  586. if(0 == nFlagsOK)
  587. {
  588. printf("Error: no flags specified for the filter\n");
  589. hr = E_FAIL;
  590. goto Exit;
  591. }
  592. #endif
  593. // set the message number
  594. nFlagsOK = 0;
  595. hr = pCmd->AllocValue("mn", &buf);
  596. if(SUCCEEDED(hr))
  597. {
  598. // strip the spaces
  599. char *st, *en;
  600. for(st = buf; isspace(*st); st++);
  601. for(en = st; *en; en++);
  602. for(--en; en > st && isspace(*en); en--);
  603. if(en - st + 1 > 0)
  604. {
  605. // found a flag
  606. char flag[64];
  607. ZeroMemory(flag, sizeof(flag));
  608. CopyMemory(flag, st, en - st + 1);
  609. int n = atoi(flag);
  610. if(0 == n)
  611. {
  612. printf("Error: message no. is 0 or not an integer. Using default.\n");
  613. }
  614. else
  615. {
  616. nFlagsOK++;
  617. pFilter->cMessages = n;
  618. }
  619. }
  620. }
  621. // set the message size
  622. nFlagsOK = 0;
  623. hr = pCmd->AllocValue("ms", &buf);
  624. if(SUCCEEDED(hr))
  625. {
  626. // strip the spaces
  627. char *st, *en;
  628. for(st = buf; isspace(*st); st++);
  629. for(en = st; *en; en++);
  630. for(--en; en > st && isspace(*en); en--);
  631. if(en - st + 1 > 0)
  632. {
  633. // found a flag
  634. char flag[64];
  635. ZeroMemory(flag, sizeof(flag));
  636. CopyMemory(flag, st, en - st + 1);
  637. int n = atoi(flag);
  638. nFlagsOK++;
  639. pFilter->cbSize = n;
  640. }
  641. }
  642. // if no valid no. or no no. at all, set the default
  643. if(0 == nFlagsOK)
  644. pFilter->cbSize = 0;
  645. // set the message date
  646. nFlagsOK = 0;
  647. hr = pCmd->AllocValue("md", &buf);
  648. if(SUCCEEDED(hr))
  649. {
  650. if(StringToUTCTime(buf, &(pFilter->stDate)))
  651. nFlagsOK++;
  652. }
  653. // if no valid no. or no no. at all, set the default
  654. if(0 == nFlagsOK)
  655. {
  656. ZeroMemory(&(pFilter->stDate), sizeof(SYSTEMTIME));
  657. }
  658. // set the skip message number
  659. nFlagsOK = 0;
  660. hr = pCmd->AllocValue("sk", &buf);
  661. if(SUCCEEDED(hr))
  662. {
  663. // strip the spaces
  664. char *st, *en;
  665. for(st = buf; isspace(*st); st++);
  666. for(en = st; *en; en++);
  667. for(--en; en > st && isspace(*en); en--);
  668. if(en - st + 1 > 0)
  669. {
  670. // found a flag
  671. char flag[64];
  672. ZeroMemory(flag, sizeof(flag));
  673. CopyMemory(flag, st, en - st + 1);
  674. int n = atoi(flag);
  675. nFlagsOK++;
  676. pFilter->cSkipMessages = n;
  677. }
  678. }
  679. // if no valid no. or no no. at all, set the default
  680. if(0 == nFlagsOK)
  681. {
  682. pFilter->cSkipMessages = 0;
  683. }
  684. // set the sender value
  685. nFlagsOK = 0;
  686. hr = pCmd->AllocValue("msndr", &buf);
  687. if(SUCCEEDED(hr))
  688. {
  689. // strip the spaces
  690. char *st, *en;
  691. for(st = buf; isspace(*st); st++);
  692. for(en = st; *en; en++);
  693. for(--en; en > st && isspace(*en); en--);
  694. if(en - st + 1 > 0)
  695. {
  696. // found a string
  697. pFilter->szMessageSender = wszGetUnicodeArg(st, (DWORD) (en-st+1));
  698. if(NULL == pFilter->szMessageSender)
  699. {
  700. printf("Error: LocalAlloc failed\n");
  701. hr = E_OUTOFMEMORY;
  702. }
  703. nFlagsOK++;
  704. }
  705. }
  706. // set the recipient value
  707. nFlagsOK = 0;
  708. hr = pCmd->AllocValue("mrcpt", &buf);
  709. if(SUCCEEDED(hr))
  710. {
  711. // strip the spaces
  712. char *st, *en;
  713. for(st = buf; isspace(*st); st++);
  714. for(en = st; *en; en++);
  715. for(--en; en > st && isspace(*en); en--);
  716. if(en - st + 1 > 0)
  717. {
  718. // found a string
  719. pFilter->szMessageRecipient = wszGetUnicodeArg(st, (DWORD) (en-st+1));
  720. if(NULL == pFilter->szMessageRecipient)
  721. {
  722. printf("Error: LocalAlloc failed\n");
  723. hr = E_OUTOFMEMORY;
  724. }
  725. nFlagsOK++;
  726. }
  727. }
  728. if(!pFilter->mefType)
  729. {
  730. pFilter->cMessages = 1;
  731. pFilter->mefType |= MEF_FIRST_N_MESSAGES;
  732. }
  733. // if we came this far all is well
  734. hr = S_OK;
  735. // TODO: validate the filter
  736. if(NULL != buf)
  737. delete [] buf;
  738. return hr;
  739. }
  740. ////////////////////////////////////////////////////////////////////////////
  741. // Method: IsContinue()
  742. // Member of:
  743. // Arguments:
  744. // Returns:
  745. // Description:
  746. ////////////////////////////////////////////////////////////////////////////
  747. BOOL CAQAdminCli::IsContinue(LPSTR pszTag, LPWSTR wszVal)
  748. {
  749. int nValidTags = 0;
  750. CHAR szVal[200] = "";
  751. for(CCmdInfo::CArgList *p = m_pFilterCmd->pArgs; NULL != p; p = p->pNext)
  752. {
  753. // set the tag to the default value if not already set
  754. if(p->szTag[0] == 0 && m_pFilterCmd->szDefTag[0] != 0)
  755. lstrcpy(p->szTag, m_pFilterCmd->szDefTag);
  756. // count valid tags
  757. if(!lstrcmpi(p->szTag, pszTag))
  758. nValidTags++;
  759. }
  760. if(!nValidTags)
  761. return TRUE;
  762. //Convert in param to ASCII
  763. WideCharToMultiByte(CP_ACP, 0, wszVal, -1, szVal,
  764. sizeof(szVal), NULL, NULL);
  765. for(p = m_pFilterCmd->pArgs; NULL != p; p = p->pNext)
  766. {
  767. if(pszTag && lstrcmpi(p->szTag, pszTag))
  768. continue;
  769. if(szVal && lstrcmpi(p->szVal, szVal))
  770. continue;
  771. return TRUE;
  772. }
  773. return FALSE;
  774. }
  775. ////////////////////////////////////////////////////////////////////////////
  776. // Method: PrintMsgInfo()
  777. // Member of:
  778. // Arguments:
  779. // Returns:
  780. // Description:
  781. ////////////////////////////////////////////////////////////////////////////
  782. HRESULT CAQAdminCli::PrintMsgInfo()
  783. {
  784. HRESULT hr;
  785. int nCrtLink, nCrtQueue, nCrtMsg;
  786. IEnumVSAQLinks *pLinkEnum = NULL;
  787. IEnumLinkQueues *pQueueEnum = NULL;
  788. IAQEnumMessages *pMsgEnum = NULL;
  789. IVSAQLink *pLink = NULL;
  790. ILinkQueue *pQueue = NULL;
  791. IAQMessage *pMsg = NULL;
  792. LINK_INFO linkInf;
  793. QUEUE_INFO queueInf;
  794. MESSAGE_INFO msgInf;
  795. ZeroMemory(&linkInf, sizeof(LINK_INFO));
  796. ZeroMemory(&queueInf, sizeof(QUEUE_INFO));
  797. ZeroMemory(&msgInf, sizeof(MESSAGE_INFO));
  798. hr = m_pVS->GetLinkEnum(&pLinkEnum);
  799. if(FAILED(hr))
  800. {
  801. printf("GetLinkEnum failed with 0x%x\n", hr);
  802. goto Exit;
  803. }
  804. for(nCrtLink = 1; TRUE; nCrtLink++)
  805. {
  806. if(NULL != pLink)
  807. {
  808. pLink->Release();
  809. pLink = NULL;
  810. }
  811. FreeStruct(&linkInf);
  812. hr = GetLink(pLinkEnum, &pLink, &linkInf);
  813. if(hr == S_FALSE)
  814. {
  815. if(nCrtLink == 1)
  816. puts("No links.");
  817. goto Exit;
  818. }
  819. else if(FAILED(hr))
  820. {
  821. break;
  822. }
  823. else if(hr == S_OK)
  824. {
  825. // check if we want messages for this link
  826. if(!IsContinue("ln", linkInf.szLinkName))
  827. continue;
  828. hr = pLink->GetQueueEnum(&pQueueEnum);
  829. if(FAILED(hr))
  830. {
  831. printf("Error: Link %d: pLink->GetQueueEnum failed with 0x%x\n", nCrtLink, hr);
  832. continue;
  833. }
  834. for(nCrtQueue = 1; TRUE; nCrtQueue++)
  835. {
  836. if(NULL != pQueue)
  837. {
  838. pQueue->Release();
  839. pQueue = NULL;
  840. }
  841. FreeStruct(&queueInf);
  842. hr = GetQueue(pQueueEnum, &pQueue, &queueInf);
  843. if(hr == S_FALSE)
  844. {
  845. if(nCrtQueue == 1)
  846. puts("No queues.");
  847. break;
  848. }
  849. else if(FAILED(hr))
  850. break;
  851. // check if we want messages for this queue
  852. if(!IsContinue("qn", queueInf.szQueueName))
  853. continue;
  854. if(!lstrcmpi(m_pActionCmd->szCmdKey, "MSG_INFO"))
  855. {
  856. MESSAGE_ENUM_FILTER Filter;
  857. // enum the messages
  858. SetMsgEnumFilter(&Filter, m_pFilterCmd);
  859. hr = pQueue->GetMessageEnum(&Filter, &pMsgEnum);
  860. if(FAILED(hr))
  861. {
  862. printf("Error: Link %d, Queue %d: pQueue->GetMessageEnum failed with 0x%x\n", nCrtLink, nCrtQueue, hr);
  863. continue;
  864. }
  865. printf("---- Messages in queue %S ----\n", queueInf.szQueueName);
  866. for(nCrtMsg = 1; TRUE; nCrtMsg++)
  867. {
  868. FreeStruct(&msgInf);
  869. hr = GetMsg(pMsgEnum, &pMsg, &msgInf);
  870. if(NULL != pMsg)
  871. {
  872. pMsg->Release();
  873. pMsg = NULL;
  874. }
  875. if(hr == S_FALSE)
  876. {
  877. if(nCrtMsg == 1)
  878. puts("No messages.");
  879. break;
  880. }
  881. else if(hr == S_OK)
  882. {
  883. PInfo(nCrtMsg, msgInf);
  884. }
  885. else if(FAILED(hr))
  886. break;
  887. }
  888. }
  889. else if(!lstrcmpi(m_pActionCmd->szCmdKey, "DEL_MSG"))
  890. {
  891. MESSAGE_FILTER Filter;
  892. DWORD cMsgs = 0;
  893. hr = SetMsgFilter(&Filter, m_pFilterCmd);
  894. if(SUCCEEDED(hr))
  895. {
  896. hr = ApplyActionToMessages(pQueue, &Filter, MA_DELETE_SILENT, &cMsgs);
  897. if(FAILED(hr))
  898. printf("Error: Link %d, Queue %d: pQueue->ApplyActionToMessages failed with 0x%x\n", nCrtLink, nCrtQueue, hr);
  899. else
  900. printf("Operation succeeded on %d messages\n", cMsgs);
  901. }
  902. FreeStruct(&Filter);
  903. }
  904. }
  905. if(NULL != pQueue)
  906. {
  907. pQueue->Release();
  908. pQueue = NULL;
  909. }
  910. if(NULL != pQueueEnum)
  911. {
  912. pQueueEnum->Release();
  913. pQueueEnum = NULL;
  914. }
  915. }
  916. }
  917. Exit:
  918. FreeStruct(&linkInf);
  919. FreeStruct(&queueInf);
  920. FreeStruct(&msgInf);
  921. if(NULL != pLink)
  922. {
  923. pLink->Release();
  924. pLink = NULL;
  925. }
  926. if(NULL != pLinkEnum)
  927. {
  928. pLinkEnum->Release();
  929. }
  930. if(NULL != pMsgEnum)
  931. {
  932. pMsgEnum->Release();
  933. }
  934. return hr;
  935. }
  936. ////////////////////////////////////////////////////////////////////////////
  937. // Method: PrintQueueInfo()
  938. // Member of: CAQAdminCli
  939. // Arguments: none
  940. // Returns: S_OK
  941. // Description:
  942. ////////////////////////////////////////////////////////////////////////////
  943. HRESULT CAQAdminCli::PrintQueueInfo()
  944. {
  945. HRESULT hr;
  946. int nCrtLink, nCrtQueue;
  947. IEnumVSAQLinks *pLinkEnum = NULL;
  948. IEnumLinkQueues *pQueueEnum = NULL;
  949. IVSAQLink *pLink = NULL;
  950. ILinkQueue *pQueue = NULL;
  951. LINK_INFO linkInf;
  952. QUEUE_INFO queueInf;
  953. ZeroMemory(&linkInf, sizeof(LINK_INFO));
  954. ZeroMemory(&queueInf, sizeof(QUEUE_INFO));
  955. hr = m_pVS->GetLinkEnum(&pLinkEnum);
  956. if(FAILED(hr))
  957. {
  958. printf("Error: GetLinkEnum failed with 0x%x\n", hr);
  959. goto Exit;
  960. }
  961. for(nCrtLink = 1; TRUE; nCrtLink++)
  962. {
  963. if(NULL != pLink)
  964. {
  965. pLink->Release();
  966. pLink = NULL;
  967. }
  968. FreeStruct(&linkInf);
  969. hr = GetLink(pLinkEnum, &pLink, &linkInf);
  970. if(hr == S_FALSE)
  971. {
  972. if(nCrtLink == 1)
  973. puts("No links.");
  974. break;
  975. }
  976. else if(FAILED(hr))
  977. {
  978. break;
  979. }
  980. else if(hr == S_OK)
  981. {
  982. // check if we want queues for this link
  983. if(!IsContinue("ln", linkInf.szLinkName))
  984. continue;
  985. hr = pLink->GetQueueEnum(&pQueueEnum);
  986. if(FAILED(hr))
  987. {
  988. printf("Error: Link %d: pLink->GetQueueEnum failed with 0x%x\n", nCrtLink, hr);
  989. continue;
  990. }
  991. PrintQueueLinkInfo(pLink);
  992. printf("---- Queues for link %S ----\n", linkInf.szLinkName);
  993. for(nCrtQueue = 1; TRUE; nCrtQueue++)
  994. {
  995. if(NULL != pQueue)
  996. {
  997. pQueue->Release();
  998. pQueue = NULL;
  999. }
  1000. FreeStruct(&queueInf);
  1001. hr = GetQueue(pQueueEnum, &pQueue, &queueInf);
  1002. if(hr == S_FALSE)
  1003. {
  1004. if(nCrtQueue == 1)
  1005. puts("No queues.");
  1006. break;
  1007. }
  1008. else if(FAILED(hr))
  1009. {
  1010. break;
  1011. }
  1012. else if(hr == S_OK)
  1013. {
  1014. // check if we want this queue
  1015. if(!IsContinue("qn", queueInf.szQueueName))
  1016. continue;
  1017. PrintQueueLinkInfo(pQueue);
  1018. if(!lstrcmpi(m_pActionCmd->szCmdKey, "QUEUE_INFO"))
  1019. PInfo(nCrtQueue, queueInf);
  1020. else if(!lstrcmpi(m_pActionCmd->szCmdKey, "MSGACTION"))
  1021. {
  1022. MESSAGE_ACTION Action;
  1023. MESSAGE_FILTER Filter;
  1024. char buf[64];
  1025. ZeroMemory(buf, sizeof(buf));
  1026. hr = SetMsgAction(&Action, m_pFilterCmd);
  1027. if(FAILED(hr))
  1028. {
  1029. printf("Error: must specify a message action\n");
  1030. }
  1031. else
  1032. {
  1033. DWORD cMsgs = 0;
  1034. // set the filter
  1035. hr = SetMsgFilter(&Filter, m_pFilterCmd);
  1036. if(SUCCEEDED(hr))
  1037. {
  1038. hr = ApplyActionToMessages(pQueue, &Filter, Action, &cMsgs);
  1039. if(FAILED(hr))
  1040. {
  1041. printf("Link %S, Queue %S: pLink->ApplyActionToMessages failed with 0x%x\n", linkInf.szLinkName, queueInf.szQueueName, hr);
  1042. }
  1043. else
  1044. printf("Link %S, Queue %S: pLink->ApplyActionToMessages succeeded on %d Messages\n", linkInf.szLinkName, queueInf.szQueueName, cMsgs);
  1045. }
  1046. FreeStruct(&Filter);
  1047. }
  1048. }
  1049. }
  1050. }
  1051. if(NULL != pQueueEnum)
  1052. {
  1053. pQueueEnum->Release();
  1054. pQueueEnum = NULL;
  1055. }
  1056. if(NULL != pQueue)
  1057. {
  1058. pQueue->Release();
  1059. pQueue = NULL;
  1060. }
  1061. }
  1062. if(NULL != pLink)
  1063. {
  1064. pLink->Release();
  1065. pLink = NULL;
  1066. }
  1067. }
  1068. Exit:
  1069. FreeStruct(&linkInf);
  1070. FreeStruct(&queueInf);
  1071. if(NULL != pLinkEnum)
  1072. {
  1073. pLinkEnum->Release();
  1074. }
  1075. return hr;
  1076. }
  1077. ////////////////////////////////////////////////////////////////////////////
  1078. // Method: PrintLinkInfo()
  1079. // Member of: CAQAdminCli
  1080. // Arguments: none
  1081. // Returns: S_OK
  1082. // Description:
  1083. ////////////////////////////////////////////////////////////////////////////
  1084. HRESULT CAQAdminCli::PrintLinkInfo()
  1085. {
  1086. HRESULT hr;
  1087. IEnumVSAQLinks *pLinkEnum = NULL;
  1088. int nCrt = 0;
  1089. LINK_INFO linkInf;
  1090. ZeroMemory(&linkInf, sizeof(LINK_INFO));
  1091. hr = m_pVS->GetLinkEnum(&pLinkEnum);
  1092. if(FAILED(hr))
  1093. {
  1094. printf("Error: GetLinkEnum failed with 0x%x\n", hr);
  1095. goto Exit;
  1096. }
  1097. for(nCrt = 1; TRUE; nCrt++)
  1098. {
  1099. IVSAQLink *pLink = NULL;
  1100. FreeStruct(&linkInf);
  1101. hr = GetLink(pLinkEnum, &pLink, &linkInf);
  1102. if(hr == S_FALSE)
  1103. {
  1104. if(nCrt == 1)
  1105. puts("No links.");
  1106. break;
  1107. }
  1108. else if(FAILED(hr))
  1109. {
  1110. break;
  1111. }
  1112. else if(hr == S_OK)
  1113. {
  1114. // check if we want link info. for this link
  1115. if(!IsContinue("ln", linkInf.szLinkName))
  1116. {
  1117. pLink->Release();
  1118. pLink = NULL;
  1119. continue;
  1120. }
  1121. if(!lstrcmpi(m_pActionCmd->szCmdKey, "LINK_INFO"))
  1122. PInfo(nCrt, linkInf);
  1123. else if(!lstrcmpi(m_pActionCmd->szCmdKey, "FREEZE"))
  1124. {
  1125. hr = pLink->SetLinkState(LA_FREEZE);
  1126. if(SUCCEEDED(hr))
  1127. printf("Link %S was frozen\n", linkInf.szLinkName);
  1128. else
  1129. printf("Link %S: SetLinkState() failed with 0x%x\n", linkInf.szLinkName, hr);
  1130. }
  1131. else if(!lstrcmpi(m_pActionCmd->szCmdKey, "THAW"))
  1132. {
  1133. hr = pLink->SetLinkState(LA_THAW);
  1134. if(SUCCEEDED(hr))
  1135. printf("Link %S was un-frozen\n", linkInf.szLinkName);
  1136. else
  1137. printf("Link %S: SetLinkState() failed with 0x%x\n", linkInf.szLinkName, hr);
  1138. }
  1139. else if(!lstrcmpi(m_pActionCmd->szCmdKey, "KICK"))
  1140. {
  1141. hr = pLink->SetLinkState(LA_KICK);
  1142. if(SUCCEEDED(hr))
  1143. printf("Link %S was kicked\n", linkInf.szLinkName);
  1144. else
  1145. printf("Link %S: SetLinkState() failed with 0x%x\n", linkInf.szLinkName, hr);
  1146. }
  1147. else if(!lstrcmpi(m_pActionCmd->szCmdKey, "MSGACTION"))
  1148. {
  1149. MESSAGE_ACTION Action;
  1150. MESSAGE_FILTER Filter;
  1151. char buf[64];
  1152. ZeroMemory(buf, sizeof(buf));
  1153. hr = SetMsgAction(&Action, m_pFilterCmd);
  1154. if(FAILED(hr))
  1155. {
  1156. printf("Error: must specify a message action\n");
  1157. }
  1158. else
  1159. {
  1160. DWORD cMsgs = 0;
  1161. // set the filter
  1162. hr = SetMsgFilter(&Filter, m_pFilterCmd);
  1163. if(SUCCEEDED(hr))
  1164. {
  1165. hr = ApplyActionToMessages(pLink, &Filter, Action, &cMsgs);
  1166. if(FAILED(hr))
  1167. {
  1168. printf("Link %S: pLink->ApplyActionToMessages failed with 0x%x\n", linkInf.szLinkName, hr);
  1169. }
  1170. else
  1171. printf("Link %S: pLink->ApplyActionToMessages succeeded on %d Messages\n", linkInf.szLinkName, cMsgs);
  1172. }
  1173. FreeStruct(&Filter);
  1174. }
  1175. }
  1176. }
  1177. if(NULL != pLink)
  1178. {
  1179. pLink->Release();
  1180. pLink = NULL;
  1181. }
  1182. }
  1183. Exit:
  1184. FreeStruct(&linkInf);
  1185. if(NULL != pLinkEnum)
  1186. {
  1187. pLinkEnum->Release();
  1188. }
  1189. return hr;
  1190. }
  1191. ////////////////////////////////////////////////////////////////////////////
  1192. // Method: PInfo()
  1193. // Member of:
  1194. // Arguments:
  1195. // Returns:
  1196. // Description:
  1197. ////////////////////////////////////////////////////////////////////////////
  1198. void CAQAdminCli::PInfo(int nCrt, MESSAGE_INFO msgInf)
  1199. {
  1200. // convert the UTC time to local time
  1201. SYSTEMTIME stLocSubmit, stLocRecv, stLocExpire;
  1202. BOOL res;
  1203. CHAR szTimeSuffix[] = " UTC";
  1204. LPWSTR wszCurrent = NULL;
  1205. SYSTEMTIME *pstSubmit = &msgInf.stSubmission;
  1206. SYSTEMTIME *pstReceived = &msgInf.stReceived;
  1207. SYSTEMTIME *pstExpire = &msgInf.stExpiry;
  1208. res = SystemTimeToTzSpecificLocalTime(NULL, &msgInf.stSubmission, &stLocSubmit);
  1209. res = res && SystemTimeToTzSpecificLocalTime(NULL, &msgInf.stReceived, &stLocRecv);
  1210. res = res && SystemTimeToTzSpecificLocalTime(NULL, &msgInf.stExpiry, &stLocExpire);
  1211. if(res)
  1212. {
  1213. //Use localized times
  1214. pstSubmit = &stLocSubmit;
  1215. pstReceived = &stLocRecv;
  1216. pstExpire = &stLocExpire;
  1217. szTimeSuffix[1] = '\0'; //" \0TC"
  1218. }
  1219. printf("%d.Message ID: %S, Priority: %s %s, Version: %ld, Size: %ld\n"
  1220. " Flags 0x%08X\n"
  1221. " %ld EnvRecipients (%ld bytes): \n",
  1222. nCrt,
  1223. msgInf.szMessageId,
  1224. msgInf.fMsgFlags & MP_HIGH ? "High" : (msgInf.fMsgFlags & MP_NORMAL ? "Normal" : "Low"),
  1225. msgInf.fMsgFlags & MP_MSG_FROZEN ? "(frozen)" : "",
  1226. msgInf.dwVersion,
  1227. msgInf.cbMessageSize,
  1228. msgInf.fMsgFlags,
  1229. msgInf.cEnvRecipients,
  1230. msgInf.cbEnvRecipients);
  1231. //spit out recipients
  1232. wszCurrent = msgInf.mszEnvRecipients;
  1233. while (wszCurrent && *wszCurrent)
  1234. {
  1235. printf("\t%S\n", wszCurrent);
  1236. while (*wszCurrent)
  1237. wszCurrent++;
  1238. wszCurrent++;
  1239. }
  1240. //print error if msgInf.mszEnvRecipients is malformed
  1241. if ((1+wszCurrent-msgInf.mszEnvRecipients)*sizeof(WCHAR) != msgInf.cbEnvRecipients)
  1242. {
  1243. printf("\tERROR mszEnvRecipients malformatted (found %ld instead of %ld bytes)\n",
  1244. (wszCurrent-msgInf.mszEnvRecipients)*sizeof(WCHAR),
  1245. msgInf.cbEnvRecipients);
  1246. }
  1247. printf(" %ld Recipients: %S\n"
  1248. " %ld Cc recipients: %S\n"
  1249. " %ld Bcc recipients: %S\n"
  1250. " Sender: %S\n"
  1251. " Subject: %S\n"
  1252. " Submitted: %d/%d/%d at %d:%02d:%02d:%03d%s\n"
  1253. " Received: %d/%d/%d at %d:%02d:%02d:%03d%s\n"
  1254. " Expires: %d/%d/%d at %d:%02d:%02d:%03d%s\n"
  1255. " %ld Failed Delivery attempts\n",
  1256. msgInf.cRecipients,
  1257. msgInf.szRecipients,
  1258. msgInf.cCCRecipients,
  1259. msgInf.szCCRecipients,
  1260. msgInf.cBCCRecipients,
  1261. msgInf.szBCCRecipients,
  1262. msgInf.szSender,
  1263. msgInf.szSubject,
  1264. pstSubmit->wMonth,
  1265. pstSubmit->wDay,
  1266. pstSubmit->wYear,
  1267. pstSubmit->wHour,
  1268. pstSubmit->wMinute,
  1269. pstSubmit->wSecond,
  1270. pstSubmit->wMilliseconds,
  1271. szTimeSuffix,
  1272. pstReceived->wMonth,
  1273. pstReceived->wDay,
  1274. pstReceived->wYear,
  1275. pstReceived->wHour,
  1276. pstReceived->wMinute,
  1277. pstReceived->wSecond,
  1278. pstReceived->wMilliseconds,
  1279. szTimeSuffix,
  1280. pstExpire->wMonth,
  1281. pstExpire->wDay,
  1282. pstExpire->wYear,
  1283. pstExpire->wHour,
  1284. pstExpire->wMinute,
  1285. pstExpire->wSecond,
  1286. pstExpire->wMilliseconds,
  1287. szTimeSuffix,
  1288. msgInf.cFailures);
  1289. }
  1290. ////////////////////////////////////////////////////////////////////////////
  1291. // Method: PInfo()
  1292. // Member of:
  1293. // Arguments:
  1294. // Returns:
  1295. // Description:
  1296. ////////////////////////////////////////////////////////////////////////////
  1297. void CAQAdminCli::PInfo(int nCrt, QUEUE_INFO queueInf)
  1298. {
  1299. printf( "%d.Name: %S, Version: %ld, No. of messages: %ld\n"
  1300. " Link name: %S, Volume: %ld\n",
  1301. nCrt,
  1302. queueInf.szQueueName,
  1303. queueInf.dwVersion,
  1304. queueInf.cMessages,
  1305. queueInf.szLinkName,
  1306. queueInf.cbQueueVolume);
  1307. }
  1308. ////////////////////////////////////////////////////////////////////////////
  1309. // Method: PInfo()
  1310. // Member of:
  1311. // Arguments:
  1312. // Returns:
  1313. // Description:
  1314. ////////////////////////////////////////////////////////////////////////////
  1315. void CAQAdminCli::PInfo(int nCrt, LINK_INFO linkInf)
  1316. {
  1317. // convert the UTC time to local time
  1318. SYSTEMTIME stLocNextConn, stLocOldest;
  1319. BOOL res;
  1320. char *pszFormat, *pszState;
  1321. SYSTEMTIME *pstNext, *pstOld;
  1322. char szSupportedLinkActions[50] = "";
  1323. if (linkInf.fStateFlags & LI_ACTIVE )
  1324. pszState = "Active";
  1325. else if (linkInf.fStateFlags & LI_READY)
  1326. pszState = "Ready";
  1327. else if (linkInf.fStateFlags & LI_RETRY)
  1328. pszState = "Retry";
  1329. else if (linkInf.fStateFlags & LI_SCHEDULED)
  1330. pszState = "Scheduled";
  1331. else if (linkInf.fStateFlags & LI_REMOTE)
  1332. pszState = "Remote";
  1333. else if (linkInf.fStateFlags & LI_FROZEN)
  1334. pszState = "Frozen";
  1335. else
  1336. pszState = "Unknown";
  1337. if (linkInf.dwSupportedLinkActions & LA_FREEZE)
  1338. strcpy(szSupportedLinkActions, "Freeze");
  1339. if (linkInf.dwSupportedLinkActions & LA_THAW)
  1340. strcat(szSupportedLinkActions, " Thaw");
  1341. if (linkInf.dwSupportedLinkActions & LA_KICK)
  1342. strcat(szSupportedLinkActions, " Kick");
  1343. if (!szSupportedLinkActions[0])
  1344. strcpy(szSupportedLinkActions, "Link can only be viewed.");
  1345. res = SystemTimeToTzSpecificLocalTime(NULL, &linkInf.stNextScheduledConnection, &stLocNextConn);
  1346. res = res && SystemTimeToTzSpecificLocalTime(NULL, &linkInf.stOldestMessage, &stLocOldest);
  1347. if(res)
  1348. {
  1349. pszFormat = "%d.Name: %S, Version: %ld\n"
  1350. " No. of messages: %ld, State: %s [0x%08X], Volume: %ld\n"
  1351. " Next scheduled connection: %d/%d/%d at %d:%02d:%02d:%03d\n"
  1352. " Oldest message: %d/%d/%d at %d:%02d:%02d:%03d\n"
  1353. " Supported Link Actions: %s\n"
  1354. " Link Diagnostic: %S\n";
  1355. pstNext = &stLocNextConn;
  1356. pstOld = &stLocOldest;
  1357. }
  1358. else
  1359. {
  1360. pszFormat = "%d.Name: %S, Version: %ld\n"
  1361. " No. of messages: %ld, State: %s [0x%08X], Volume: %ld\n"
  1362. " Next scheduled connection: %d/%d/%d at %d:%02d:%02d:%03d UTC\n"
  1363. " Oldest message: %d/%d/%d at %d:%02d:%02d:%03d UTC\n"
  1364. " Supported Link Actions: %s\n"
  1365. " Link Diagnostic: %S\n";
  1366. pstNext = &linkInf.stNextScheduledConnection;
  1367. pstOld = &linkInf.stOldestMessage;
  1368. }
  1369. printf(pszFormat,
  1370. nCrt,
  1371. linkInf.szLinkName,
  1372. linkInf.dwVersion,
  1373. linkInf.cMessages,
  1374. pszState,
  1375. linkInf.fStateFlags,
  1376. linkInf.cbLinkVolume.LowPart,
  1377. pstNext->wMonth,
  1378. pstNext->wDay,
  1379. pstNext->wYear,
  1380. pstNext->wHour,
  1381. pstNext->wMinute,
  1382. pstNext->wSecond,
  1383. pstNext->wMilliseconds,
  1384. pstOld->wMonth,
  1385. pstOld->wDay,
  1386. pstOld->wYear,
  1387. pstOld->wHour,
  1388. pstOld->wMinute,
  1389. pstOld->wSecond,
  1390. pstOld->wMilliseconds,
  1391. szSupportedLinkActions,
  1392. linkInf.szExtendedStateInfo);
  1393. }
  1394. ////////////////////////////////////////////////////////////////////////////
  1395. // Method: GetMsg()
  1396. // Member of:
  1397. // Arguments:
  1398. // Returns:
  1399. // Description:
  1400. ////////////////////////////////////////////////////////////////////////////
  1401. HRESULT CAQAdminCli::GetMsg(IN IAQEnumMessages *pMsgEnum, OUT IAQMessage **ppMsg, IN OUT MESSAGE_INFO *pMsgInf)
  1402. {
  1403. HRESULT hr;
  1404. DWORD cFetched;
  1405. hr = pMsgEnum->Next(1, ppMsg, &cFetched);
  1406. if(hr == S_FALSE)
  1407. {
  1408. goto Exit;
  1409. }
  1410. else if(FAILED(hr))
  1411. {
  1412. printf("pMsgEnum->Next failed with 0x%x\n", hr);
  1413. goto Exit;
  1414. }
  1415. else if(NULL == (*ppMsg))
  1416. {
  1417. printf("pMsg is NULL.\n", hr);
  1418. goto Exit;
  1419. }
  1420. else
  1421. {
  1422. ZeroMemory(pMsgInf, sizeof(MESSAGE_INFO));
  1423. pMsgInf->dwVersion = CURRENT_QUEUE_ADMIN_VERSION;
  1424. hr = (*ppMsg)->GetInfo(pMsgInf);
  1425. if(FAILED(hr))
  1426. {
  1427. printf("pMsg->GetInfo failed with 0x%x\n", hr);
  1428. goto Exit;
  1429. }
  1430. }
  1431. Exit:
  1432. return hr;
  1433. }
  1434. ////////////////////////////////////////////////////////////////////////////
  1435. // Method: GetQueue()
  1436. // Member of: CAQAdminCli
  1437. // Arguments:
  1438. // Returns: S_FALSE - no more links
  1439. // S_OK - success
  1440. // Description: Caller must allocate pQueueInf
  1441. ////////////////////////////////////////////////////////////////////////////
  1442. HRESULT CAQAdminCli::GetQueue(IN IEnumLinkQueues *pQueueEnum, OUT ILinkQueue **ppQueue, IN OUT QUEUE_INFO *pQueueInf)
  1443. {
  1444. HRESULT hr;
  1445. DWORD cFetched;
  1446. if (NULL == pQueueEnum)
  1447. return S_FALSE;
  1448. hr = pQueueEnum->Next(1, ppQueue, &cFetched);
  1449. if(hr == S_FALSE)
  1450. {
  1451. goto Exit;
  1452. }
  1453. else if(FAILED(hr))
  1454. {
  1455. printf("pQueueEnum->Next failed with 0x%x\n", hr);
  1456. goto Exit;
  1457. }
  1458. else if(NULL == (*ppQueue))
  1459. {
  1460. printf("pQueue is NULL.\n", hr);
  1461. goto Exit;
  1462. }
  1463. else
  1464. {
  1465. ZeroMemory(pQueueInf, sizeof(QUEUE_INFO));
  1466. pQueueInf->dwVersion = CURRENT_QUEUE_ADMIN_VERSION;
  1467. hr = (*ppQueue)->GetInfo(pQueueInf);
  1468. if(FAILED(hr))
  1469. {
  1470. printf("pQueue->GetInfo failed with 0x%x\n", hr);
  1471. goto Exit;
  1472. }
  1473. }
  1474. Exit:
  1475. return hr;
  1476. }
  1477. ////////////////////////////////////////////////////////////////////////////
  1478. // Method: GetLink()
  1479. // Member of: CAQAdminCli
  1480. // Arguments:
  1481. // Returns: S_FALSE - no more links
  1482. // S_OK - success
  1483. // Description: Caller must allocate pLinkInf
  1484. ////////////////////////////////////////////////////////////////////////////
  1485. HRESULT CAQAdminCli::GetLink(IN IEnumVSAQLinks *pLinkEnum, OUT IVSAQLink **ppLink, IN OUT LINK_INFO *pLinkInf)
  1486. {
  1487. HRESULT hr;
  1488. DWORD cFetched;
  1489. hr = pLinkEnum->Next(1, ppLink, &cFetched);
  1490. if(hr == S_FALSE)
  1491. {
  1492. goto Exit;
  1493. }
  1494. else if(FAILED(hr))
  1495. {
  1496. printf("pLinkEnum->Next failed with 0x%x\n", hr);
  1497. goto Exit;
  1498. }
  1499. else if(NULL == (*ppLink))
  1500. {
  1501. printf("pLink is NULL.\n", hr);
  1502. goto Exit;
  1503. }
  1504. else
  1505. {
  1506. ZeroMemory(pLinkInf, sizeof(LINK_INFO));
  1507. pLinkInf->dwVersion = CURRENT_QUEUE_ADMIN_VERSION;
  1508. hr = (*ppLink)->GetInfo(pLinkInf);
  1509. if(FAILED(hr))
  1510. {
  1511. printf("pLink->GetInfo failed with 0x%x\n", hr);
  1512. if (HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) == hr)
  1513. printf("RPC Server Unavailable.\n");
  1514. else if ( hr == E_POINTER )
  1515. printf("Null pointer.\n");
  1516. else if ( hr == E_OUTOFMEMORY )
  1517. printf("Out of memory.\n");
  1518. else if ( hr == E_INVALIDARG )
  1519. printf("Invalid argument.\n");
  1520. else
  1521. printf("Unknown error.\n");
  1522. goto Exit;
  1523. }
  1524. }
  1525. Exit:
  1526. return hr;
  1527. }
  1528. ////////////////////////////////////////////////////////////////////////////
  1529. // Method: ~CAQAdminCli()
  1530. // Member of:
  1531. // Arguments:
  1532. // Returns:
  1533. // Description:
  1534. ////////////////////////////////////////////////////////////////////////////
  1535. CAQAdminCli::~CAQAdminCli()
  1536. {
  1537. if(NULL != m_pFilterCmd)
  1538. delete (CCmdInfo*) m_pFilterCmd;
  1539. if(NULL != m_pActionCmd)
  1540. delete (CCmdInfo*) m_pActionCmd;
  1541. }
  1542. ////////////////////////////////////////////////////////////////////////////
  1543. // Method: Cleanup()
  1544. // Member of:
  1545. // Arguments:
  1546. // Returns:
  1547. // Description:
  1548. ////////////////////////////////////////////////////////////////////////////
  1549. void CAQAdminCli::Cleanup()
  1550. {
  1551. if(m_pAdmin)
  1552. m_pAdmin->Release();
  1553. if(m_pVS)
  1554. m_pVS->Release();
  1555. }
  1556. ////////////////////////////////////////////////////////////////////////////
  1557. // Method: CAQAdminCli()
  1558. // Member of:
  1559. // Arguments:
  1560. // Returns:
  1561. // Description:
  1562. ////////////////////////////////////////////////////////////////////////////
  1563. CAQAdminCli::CAQAdminCli()
  1564. {
  1565. m_pAdmin = NULL;
  1566. m_pVS = NULL;
  1567. m_dwDispFlags = (DispFlags) (DF_LINK | DF_QUEUE | DF_MSG);
  1568. m_pFilterCmd = NULL;
  1569. m_pActionCmd = NULL;
  1570. m_fUseMTA = FALSE;
  1571. }
  1572. ////////////////////////////////////////////////////////////////////////////
  1573. // Method: StopAllLinks()
  1574. // Member of:
  1575. // Arguments:
  1576. // Returns:
  1577. // Description:
  1578. ////////////////////////////////////////////////////////////////////////////
  1579. HRESULT CAQAdminCli::StopAllLinks()
  1580. {
  1581. HRESULT hr;
  1582. hr = m_pVS->StopAllLinks();
  1583. if(FAILED(hr))
  1584. {
  1585. printf("m_pAdmin->StopAllLinks failed with 0x%x\n", hr);
  1586. }
  1587. else
  1588. printf("StopAllLinks succeeded\n", hr);
  1589. return hr;
  1590. }
  1591. ////////////////////////////////////////////////////////////////////////////
  1592. // Method: StartAllLinks()
  1593. // Member of:
  1594. // Arguments:
  1595. // Returns:
  1596. // Description:
  1597. ////////////////////////////////////////////////////////////////////////////
  1598. HRESULT CAQAdminCli::StartAllLinks()
  1599. {
  1600. HRESULT hr;
  1601. hr = m_pVS->StartAllLinks();
  1602. if(FAILED(hr))
  1603. {
  1604. printf("StartAllLinks failed with 0x%x\n", hr);
  1605. }
  1606. else
  1607. printf("StartAllLinks succeeded\n", hr);
  1608. return hr;
  1609. }
  1610. ////////////////////////////////////////////////////////////////////////////
  1611. // Method: GetGlobalLinkState()
  1612. // Member of:
  1613. // Arguments:
  1614. // Returns:
  1615. // Description:
  1616. ////////////////////////////////////////////////////////////////////////////
  1617. HRESULT CAQAdminCli::GetGlobalLinkState()
  1618. {
  1619. HRESULT hr;
  1620. hr = m_pVS->GetGlobalLinkState();
  1621. if(FAILED(hr))
  1622. {
  1623. printf("GetGlobalLinkState failed with 0x%x\n", hr);
  1624. }
  1625. else if (S_OK == hr)
  1626. {
  1627. printf("Links UP\n");
  1628. }
  1629. else
  1630. {
  1631. printf("Links STOPPED by admin\n");
  1632. }
  1633. return hr;
  1634. }
  1635. HRESULT CAQAdminCli::MessageAction(MESSAGE_FILTER *pFilter, MESSAGE_ACTION action)
  1636. {
  1637. HRESULT hr = S_OK;
  1638. DWORD cMsgs = 0;
  1639. hr = ApplyActionToMessages(m_pVS, pFilter, action, &cMsgs);
  1640. if(FAILED(hr))
  1641. {
  1642. printf("m_pAdmin->ApplyActionToMessages failed with 0x%x\n", hr);
  1643. }
  1644. else
  1645. printf("ApplyActionToMessages succeeded on %d Messages\n", cMsgs);
  1646. return hr;
  1647. }
  1648. ////////////////////////////////////////////////////////////////////////////
  1649. // Method: Help()
  1650. // Member of:
  1651. // Arguments:
  1652. // Returns:
  1653. // Description:
  1654. ////////////////////////////////////////////////////////////////////////////
  1655. void CAQAdminCli::Help()
  1656. {
  1657. puts( "\n Commands:\n"
  1658. "====================\n"
  1659. "setserver [sn] [,vs=VSnumber] - sets the server to administer. Default is localhost,\n"
  1660. " first virtual server\n"
  1661. "linkinfo [ln,ln,...] - prints link information for specified links or\n"
  1662. " for all links (no arguments)\n"
  1663. "queueinfo [ln,ln,...] - prints queue information for specified links or\n"
  1664. " for all links (no arguments)\n"
  1665. "msginfo [qn,qn,...,] eflt - prints message information for specified queues or\n"
  1666. " for all queues (no 'qn' arguments)\n"
  1667. "delmsg [qn,qn,...,] flt - deletes messages from specified queues or\n"
  1668. " from all queues (no 'qn' arguments)\n"
  1669. "msgaction mac, flt - applies msg. action to specified messages\n"
  1670. "linkaction ln [,ln,...], lac - applies link action to specified links\n"
  1671. " [, mac, flt] if action is \"MSGACTION\", must specify mac and flt\n"
  1672. "queueaction qn [,qn,...], qac - applies queue action to specified queues\n"
  1673. " [, mac, flt] if action is \"MSGACTION\", must specify mac and flt\n"
  1674. "stopalllinks - stops all the links\n"
  1675. "startalllinks - starts all the links\n"
  1676. "checklinks - checks the global status of the links\n"
  1677. "freezelink ln [,ln,...] - freezes the specified links\n"
  1678. "meltlink ln [,ln,...] - un-freezes the specified links\n"
  1679. "kicklink ln [,ln,...] - kicks (forces a connect) for the specified links\n"
  1680. "useMTA - uses the MTA AQ administrator\n"
  1681. "useSMTP - uses the SMTP AQ administrator\n"
  1682. "?, help - this help\n"
  1683. "quit - exits the program\n"
  1684. "!cmd - executes shell command 'cmd'\n"
  1685. "\nwhere\n\n"
  1686. "ln = link name\n"
  1687. "qn = queue name\n"
  1688. "sn = server name\n"
  1689. "mac = \"ma=<action>\" message action. Actions are: \"DEL\"|\"DEL_S\"|\"FREEZE\"|\"THAW\"|\"COUNT\"\n"
  1690. "lac = \"la=<action>\" link action. Actions: \"KICK\"|\"FREEZE\"|\"THAW\"|\"MSGACTION\"\n"
  1691. "qac = \"qa=<action>\" queue action. Actions: \"MSGACTION\"\n"
  1692. "eflt = \"token,token,...\" msg. enum. filter. Following tokens are suported:\n"
  1693. " \"ft=<flags>\" Flags are: \"FIRST_N\"|\"OLDER\"|\"OLDEST\"|\"LARGER\"|\"LARGEST\"|\"NOT\"|\"SENDER\"|\"RCPT\"|\"ALL\"\n"
  1694. " (filter type. Flags can be or'ed)\n"
  1695. " \"mn=<number>\" (number of messages)\n"
  1696. " \"ms=<number>\" (message size)\n"
  1697. " \"md=<date>\" (message date mm/dd/yy hh:mm:ss:mil [UTC])\n"
  1698. " \"sk=<number>\" (skip messages)\n"
  1699. " \"msndr=<string>\" (message sender)\n"
  1700. " \"mrcpt=<string>\" (message recipient)\n"
  1701. "flt = \"token,token,...\" msg. filter. Following tokens are suported:\n"
  1702. " \"flags=<flags>\" Flags are: \"MSGID\"|\"SENDER\"|\"RCPT\"|\"SIZE\"|\"TIME\"|\"FROZEN\"|\"NOT\"|\"ALL\"\n"
  1703. " (filter flags. Flags can be or'ed)\n"
  1704. " \"id=<string>\" (message id as shown by msginfo)\n"
  1705. " \"sender=<string>\" (the sender of the message)\n"
  1706. " \"rcpt=<string>\" (the recipient of the message)\n"
  1707. " \"size=<number>\" (the minimum message size)\n"
  1708. " \"date=<date>\" (oldest message date mm/dd/yy hh:mm:ss:mil [UTC])\n"
  1709. );
  1710. }
  1711. ////////////////////////////////////////////////////////////////////////////
  1712. // Method: Init()
  1713. // Member of:
  1714. // Arguments:
  1715. // Returns:
  1716. // Description:
  1717. ////////////////////////////////////////////////////////////////////////////
  1718. HRESULT CAQAdminCli::Init()
  1719. {
  1720. HRESULT hr;
  1721. hr = CoCreateInstance(CLSID_AQAdmin,
  1722. NULL,
  1723. CLSCTX_INPROC_SERVER,
  1724. IID_IAQAdmin,
  1725. (void **) &m_pAdmin);
  1726. if(FAILED(hr))
  1727. {
  1728. printf("CoCreateInstance failed with 0x%x\n", hr);
  1729. goto Exit;
  1730. }
  1731. hr = m_pAdmin->GetVirtualServerAdminITF(NULL, L"1", &m_pVS);
  1732. if(FAILED(hr))
  1733. {
  1734. printf("GetVirtualServerAdminITF failed with 0x%x\n", hr);
  1735. goto Exit;
  1736. }
  1737. Exit:
  1738. return hr;
  1739. }
  1740. ////////////////////////////////////////////////////////////////////////////
  1741. // Method: Init()
  1742. // Member of:
  1743. // Arguments:
  1744. // Returns:
  1745. // Description:
  1746. ////////////////////////////////////////////////////////////////////////////
  1747. HRESULT CAQAdminCli::UseMTA(BOOL fUseMTA)
  1748. {
  1749. HRESULT hr;
  1750. IAQAdmin *pAdminTmp = NULL;
  1751. // don't release the old one unless you can create the new one.
  1752. if(fUseMTA)
  1753. hr = CoCreateInstance(CLSID_MAQAdmin,
  1754. NULL,
  1755. CLSCTX_INPROC_SERVER,
  1756. IID_IAQAdmin,
  1757. (void **) &pAdminTmp);
  1758. else
  1759. hr = CoCreateInstance(CLSID_AQAdmin,
  1760. NULL,
  1761. CLSCTX_INPROC_SERVER,
  1762. IID_IAQAdmin,
  1763. (void **) &pAdminTmp);
  1764. if(FAILED(hr))
  1765. {
  1766. printf("CoCreateInstance failed with 0x%x\n", hr);
  1767. goto Exit;
  1768. }
  1769. else
  1770. {
  1771. if(NULL != m_pAdmin)
  1772. {
  1773. m_pAdmin->Release();
  1774. m_pAdmin = NULL;
  1775. }
  1776. m_pAdmin = pAdminTmp;
  1777. m_fUseMTA = fUseMTA;
  1778. printf("AQ Admin is %s.\n", fUseMTA ? "MTA" : "SMTP");
  1779. }
  1780. hr = m_pAdmin->GetVirtualServerAdminITF(NULL, L"1", &m_pVS);
  1781. if(FAILED(hr))
  1782. {
  1783. printf("GetVirtualServerAdminITF failed with 0x%x\n", hr);
  1784. goto Exit;
  1785. }
  1786. Exit:
  1787. return hr;
  1788. }
  1789. HRESULT ExecuteCmd(CAQAdminCli& Admcli, LPSTR szCmd)
  1790. {
  1791. HRESULT hr = S_OK;
  1792. BOOL fQuit = FALSE;
  1793. // see if it's a system command
  1794. if(szCmd[0] == '!')
  1795. {
  1796. system(szCmd + 1);
  1797. goto Exit;
  1798. }
  1799. Admcli.m_pFilterCmd = new CCmdInfo(szCmd);
  1800. if(NULL == Admcli.m_pFilterCmd)
  1801. {
  1802. printf("Cannot allocate command info.\n");
  1803. hr = E_OUTOFMEMORY;
  1804. goto Exit;
  1805. }
  1806. if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "quit"))
  1807. {
  1808. fQuit = TRUE;
  1809. goto Exit;
  1810. }
  1811. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "freezelink"))
  1812. {
  1813. // set default tag to 'ln'
  1814. Admcli.m_pFilterCmd->SetDefTag("ln");
  1815. // check there's at least one link name
  1816. hr = Admcli.m_pFilterCmd->GetValue("ln", NULL);
  1817. if(FAILED(hr))
  1818. {
  1819. printf("Error: must have at least one link name\n");
  1820. }
  1821. else
  1822. {
  1823. Admcli.m_pActionCmd = new CCmdInfo("FREEZE");
  1824. Admcli.PrintLinkInfo();
  1825. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1826. Admcli.m_pActionCmd = NULL;
  1827. }
  1828. }
  1829. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "meltlink"))
  1830. {
  1831. // set default tag to 'ln'
  1832. Admcli.m_pFilterCmd->SetDefTag("ln");
  1833. // check there's at least one link name
  1834. hr = Admcli.m_pFilterCmd->GetValue("ln", NULL);
  1835. if(FAILED(hr))
  1836. {
  1837. printf("Error: must have at least one link name\n");
  1838. }
  1839. else
  1840. {
  1841. Admcli.m_pActionCmd = new CCmdInfo("THAW");
  1842. Admcli.PrintLinkInfo();
  1843. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1844. Admcli.m_pActionCmd = NULL;
  1845. }
  1846. }
  1847. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "kicklink"))
  1848. {
  1849. // set default tag to 'ln'
  1850. Admcli.m_pFilterCmd->SetDefTag("ln");
  1851. // check there's at least one link name
  1852. hr = Admcli.m_pFilterCmd->GetValue("ln", NULL);
  1853. if(FAILED(hr))
  1854. {
  1855. printf("Error: must have at least one link name\n");
  1856. }
  1857. else
  1858. {
  1859. Admcli.m_pActionCmd = new CCmdInfo("KICK");
  1860. Admcli.PrintLinkInfo();
  1861. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1862. Admcli.m_pActionCmd = NULL;
  1863. }
  1864. }
  1865. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "linkaction"))
  1866. {
  1867. char buf[64];
  1868. // set default tag to 'ln'
  1869. Admcli.m_pFilterCmd->SetDefTag("ln");
  1870. // check there's at least one link name
  1871. hr = Admcli.m_pFilterCmd->GetValue("ln", NULL);
  1872. if(FAILED(hr))
  1873. {
  1874. printf("Error: must have at least one link name\n");
  1875. }
  1876. else
  1877. {
  1878. // check there's an action
  1879. hr = Admcli.m_pFilterCmd->GetValue("la", buf);
  1880. if(FAILED(hr))
  1881. {
  1882. printf("Error: must have a link action\n");
  1883. }
  1884. else
  1885. {
  1886. Admcli.m_pActionCmd = new CCmdInfo(buf);
  1887. Admcli.PrintLinkInfo();
  1888. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1889. Admcli.m_pActionCmd = NULL;
  1890. }
  1891. }
  1892. }
  1893. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "queueaction"))
  1894. {
  1895. char buf[64];
  1896. // set default tag to 'ln'
  1897. Admcli.m_pFilterCmd->SetDefTag("qn");
  1898. // check there's at least one link name
  1899. hr = Admcli.m_pFilterCmd->GetValue("qn", NULL);
  1900. if(FAILED(hr))
  1901. {
  1902. printf("Error: must have at least one queue name\n");
  1903. }
  1904. else
  1905. {
  1906. // check there's an action
  1907. hr = Admcli.m_pFilterCmd->GetValue("qa", buf);
  1908. if(FAILED(hr))
  1909. {
  1910. printf("Error: must have a queue action\n");
  1911. }
  1912. else
  1913. {
  1914. Admcli.m_pActionCmd = new CCmdInfo(buf);
  1915. Admcli.PrintQueueInfo();
  1916. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1917. Admcli.m_pActionCmd = NULL;
  1918. }
  1919. }
  1920. }
  1921. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "linkinfo"))
  1922. {
  1923. //Admcli.m_dwDispFlags = CAQAdminCli::DF_LINK;
  1924. // set default tag to 'ln'
  1925. Admcli.m_pFilterCmd->SetDefTag("ln");
  1926. Admcli.m_pActionCmd = new CCmdInfo("LINK_INFO");
  1927. Admcli.PrintLinkInfo();
  1928. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1929. Admcli.m_pActionCmd = NULL;
  1930. }
  1931. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "queueinfo"))
  1932. {
  1933. //Admcli.m_dwDispFlags = CAQAdminCli::DF_QUEUE;
  1934. // set default tag to 'ln'
  1935. Admcli.m_pFilterCmd->SetDefTag("ln");
  1936. Admcli.m_pActionCmd = new CCmdInfo("QUEUE_INFO");
  1937. Admcli.PrintQueueInfo();
  1938. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1939. Admcli.m_pActionCmd = NULL;
  1940. }
  1941. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "msginfo"))
  1942. {
  1943. //Admcli.m_dwDispFlags = CAQAdminCli::DF_MSG;
  1944. //Admcli.GetLinkInfo();
  1945. // set default tag to 'qn'
  1946. Admcli.m_pFilterCmd->SetDefTag("qn");
  1947. Admcli.m_pActionCmd = new CCmdInfo("MSG_INFO");
  1948. Admcli.PrintMsgInfo();
  1949. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1950. Admcli.m_pActionCmd = NULL;
  1951. }
  1952. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "delmsg"))
  1953. {
  1954. // set default tag to 'qn'
  1955. Admcli.m_pFilterCmd->SetDefTag("qn");
  1956. Admcli.m_pActionCmd = new CCmdInfo("DEL_MSG");
  1957. Admcli.PrintMsgInfo();
  1958. delete (CCmdInfo*) Admcli.m_pActionCmd;
  1959. Admcli.m_pActionCmd = NULL;
  1960. }
  1961. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "useMTA"))
  1962. {
  1963. Admcli.UseMTA(TRUE);
  1964. }
  1965. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "useSMTP"))
  1966. {
  1967. Admcli.UseMTA(FALSE);
  1968. }
  1969. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "msgaction"))
  1970. {
  1971. MESSAGE_ACTION Action;
  1972. MESSAGE_FILTER Filter;
  1973. char buf[64];
  1974. BOOL fActOK = TRUE;
  1975. ZeroMemory(buf, sizeof(buf));
  1976. // set default tag to 'ma'
  1977. Admcli.m_pFilterCmd->SetDefTag("ma");
  1978. Admcli.m_pFilterCmd->GetValue("ma", buf);
  1979. // set the action
  1980. hr = Admcli.SetMsgAction(&Action, Admcli.m_pFilterCmd);
  1981. if(FAILED(hr))
  1982. {
  1983. printf("Error: must specify an action\n");
  1984. fActOK = FALSE;
  1985. }
  1986. if(fActOK)
  1987. {
  1988. // set the filter
  1989. hr = Admcli.SetMsgFilter(&Filter, Admcli.m_pFilterCmd);
  1990. if(SUCCEEDED(hr))
  1991. {
  1992. Admcli.MessageAction(&Filter, Action);
  1993. }
  1994. Admcli.FreeStruct(&Filter);
  1995. }
  1996. }
  1997. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "stopalllinks"))
  1998. {
  1999. Admcli.StopAllLinks();
  2000. }
  2001. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "startalllinks"))
  2002. {
  2003. Admcli.StartAllLinks();
  2004. }
  2005. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "setserver"))
  2006. {
  2007. char buf[MAX_SERVER_NAME];
  2008. char vsn[32];
  2009. char *pServer = NULL;
  2010. Admcli.m_pFilterCmd->SetDefTag("sn");
  2011. hr = Admcli.m_pFilterCmd->GetValue("sn", buf);
  2012. if(FAILED(hr))
  2013. pServer = NULL;
  2014. else
  2015. pServer = (LPSTR)buf;
  2016. hr = Admcli.m_pFilterCmd->GetValue("vs", vsn);
  2017. if(FAILED(hr))
  2018. lstrcpy(vsn, "1");
  2019. hr = Admcli.SetServer(pServer, (LPSTR)vsn);
  2020. if(FAILED(hr))
  2021. printf("setserver failed. Using the old server.\n");
  2022. else
  2023. printf("setserver succeeded.\n");
  2024. }
  2025. else if (!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "checklinks"))
  2026. {
  2027. Admcli.GetGlobalLinkState();
  2028. }
  2029. else if(!lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "?") ||
  2030. !lstrcmpi(Admcli.m_pFilterCmd->szCmdKey, "help"))
  2031. {
  2032. Admcli.Help();
  2033. }
  2034. else
  2035. {
  2036. puts("Unknown command. Type '?' for on-line help");
  2037. }
  2038. if(Admcli.m_pFilterCmd)
  2039. {
  2040. delete Admcli.m_pFilterCmd;
  2041. Admcli.m_pFilterCmd = NULL;
  2042. }
  2043. Exit:
  2044. // S_FALSE means "quit" for the main command loop. Return S_OK
  2045. // (or error) unless fQuit is true
  2046. if(fQuit)
  2047. return S_FALSE;
  2048. else if(S_FALSE == hr)
  2049. return S_OK;
  2050. else
  2051. return hr;
  2052. }
  2053. int __cdecl main(int argc, char **argv)
  2054. {
  2055. HRESULT hr;
  2056. char szCmd[4096];
  2057. char szCmdTmp[MAX_CMD_LEN];
  2058. CAQAdminCli Admcli;
  2059. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  2060. if(FAILED(hr))
  2061. {
  2062. printf("CoInitializeEx failed w/ 0x%x\n", hr);
  2063. return hr;
  2064. }
  2065. hr = Admcli.Init();
  2066. if(FAILED(hr))
  2067. {
  2068. goto Exit;
  2069. }
  2070. // check if we have cmd line commands
  2071. if(argc > 1)
  2072. {
  2073. for(int i = 1; i < argc; i++)
  2074. {
  2075. if(!lstrcmpi(argv[i], "-?") || !lstrcmpi(argv[i], "/?"))
  2076. {
  2077. Admcli.Help();
  2078. goto Exit;
  2079. }
  2080. else
  2081. {
  2082. // this is a command
  2083. ZeroMemory(szCmd, sizeof(szCmd));
  2084. if(argv[i][0] == '\"' && argv[i][lstrlen(argv[i])-1] == '\"')
  2085. {
  2086. // strip quotes
  2087. CopyMemory(szCmd, argv[i]+1, lstrlen(argv[i])-2);
  2088. }
  2089. else
  2090. CopyMemory(szCmd, argv[i], lstrlen(argv[i]));
  2091. ExecuteCmd(Admcli, szCmd);
  2092. }
  2093. }
  2094. goto Exit;
  2095. }
  2096. puts("\nAQ administrator tool v 1.0\nType '?' or 'help' for list of commands.\n");
  2097. while(TRUE)
  2098. {
  2099. char *cmd = NULL;
  2100. printf(">");
  2101. ZeroMemory(szCmd, sizeof(szCmd));
  2102. if(!Admcli.m_fUseMTA)
  2103. {
  2104. szCmd[0] = 127;
  2105. cmd = _cgets(szCmd);
  2106. }
  2107. else
  2108. {
  2109. // read line by line until CRLF.CRLF
  2110. do
  2111. {
  2112. ZeroMemory(szCmdTmp, sizeof(szCmdTmp));
  2113. szCmdTmp[0] = 127;
  2114. cmd = _cgets(szCmdTmp);
  2115. if(!lstrcmp(cmd, "."))
  2116. break;
  2117. lstrcat(szCmd, cmd);
  2118. }
  2119. while(TRUE);
  2120. cmd = szCmd;
  2121. }
  2122. hr = ExecuteCmd(Admcli, cmd);
  2123. if(S_FALSE == hr)
  2124. break;
  2125. }
  2126. Exit:
  2127. Admcli.Cleanup();
  2128. CoUninitialize();
  2129. return hr;
  2130. }
  2131. #include "aqadmin.c"