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.

1067 lines
36 KiB

  1. /*
  2. * Module Name:
  3. * capture.c
  4. * Copyright (c) 1995 Microsoft Corporation
  5. *
  6. * Abstract:
  7. *
  8. * SYNTAX (Command line)
  9. * - Usage: Capture [/Options]
  10. *
  11. * Author : Congpa You (Congpay)
  12. *
  13. * Revision history :
  14. * - 05/24/94 congpay Created
  15. */
  16. #include "common.h"
  17. extern char *RemoveSpaces (char * buffer);
  18. typedef struct _CAPTURE_PARAMS {
  19. UCHAR nLPT;
  20. char serverName[MAX_NAME_LEN];
  21. char queueName[MAX_QUEUE_NAME_LEN];
  22. char bannerUserName[MAX_BANNER_USER_NAME];
  23. char filePath[_MAX_PATH];
  24. unsigned int NDSCapture;
  25. NETWARE_CAPTURE_FLAGS_RW captureFlagsRW;
  26. }CAPTURE_PARAMS, *PCAPTURE_PARAMS;
  27. /* Local Functions*/
  28. void UpcaseArg(int argc, char ** argv);
  29. int IsShowOption (int argc, char ** argv);
  30. int IsServerSpecified (int argc, char ** argv);
  31. int IsNoOption (char * option);
  32. int IsQuestionMark (int argc, char ** argv);
  33. int IsValidOption (char *input, char *option, char *shortoption);
  34. void ShowCapture(void);
  35. void GetJobNameFromArg (int argc, char ** argv, char *jobName);
  36. int InitCaptureParams (unsigned int conn,
  37. char *jobName,
  38. PCAPTURE_PARAMS pCaptureParams);
  39. int ReadArguments (int argc,
  40. char ** argv,
  41. char *jobName,
  42. PCAPTURE_PARAMS pCaptureParams);
  43. int CStartCapture(unsigned int conn,
  44. PCAPTURE_PARAMS pCaptureParams);
  45. int GetPrinterDefaultQueue( PCAPTURE_PARAMS, PBYTE );
  46. void
  47. Capture (char ** argv, unsigned int argc)
  48. {
  49. char jobName[MAX_JOB_NAME_LEN]="";
  50. CAPTURE_PARAMS captureParams;
  51. unsigned int conn;
  52. UpcaseArg(argc, argv);
  53. memset( (PBYTE)&captureParams, 0, sizeof(captureParams) );
  54. captureParams.nLPT = 0;
  55. captureParams.serverName[0] = 0;
  56. captureParams.queueName[0] = 0;
  57. captureParams.bannerUserName[0] = 0;
  58. captureParams.filePath[0] = 0;
  59. if ( fNDS )
  60. {
  61. captureParams.NDSCapture = TRUE;
  62. }
  63. else
  64. {
  65. captureParams.NDSCapture = FALSE;
  66. }
  67. if ( IsServerSpecified( argc, argv ) )
  68. captureParams.NDSCapture = FALSE;
  69. // If the option is show, show the current capture settings.
  70. if (IsShowOption (argc, argv))
  71. {
  72. ShowCapture();
  73. return;
  74. }
  75. // If the option is ?, show the usage.
  76. if (IsQuestionMark(argc, argv))
  77. {
  78. DisplayMessage(IDR_CAPTURE_USAGE);
  79. return;
  80. }
  81. // If /Job=jobname is in the parameter, get the jobname.
  82. GetJobNameFromArg (argc, argv, jobName);
  83. if (!CGetDefaultConnectionID (&conn) ||
  84. !InitCaptureParams (conn, jobName, &captureParams) ||
  85. !ReadArguments (argc,
  86. argv,
  87. jobName,
  88. &captureParams))
  89. return;
  90. // Terminate old capture.
  91. EndCapture ((unsigned char) captureParams.nLPT);
  92. (void) CStartCapture(conn, &captureParams);
  93. return;
  94. }
  95. void UpcaseArg(int argc, char ** argv)
  96. {
  97. int i;
  98. for (i = 0; i < argc ; i++)
  99. _strupr (argv[i]);
  100. }
  101. /*
  102. Return TRUE if input is /Show option.
  103. FALSE otherwise.
  104. */
  105. int IsShowOption (int argc,char ** argv)
  106. {
  107. int bIsShowOption = FALSE;
  108. char * p;
  109. if (argc == 2)
  110. {
  111. p = argv[1];
  112. while ((*p == '/') || (*p == '\\') || (*p == '-'))
  113. p++;
  114. if (!strncmp (p, __SHOW__, max (2, strlen(p))))
  115. bIsShowOption = TRUE;
  116. }
  117. return(bIsShowOption);
  118. }
  119. /*
  120. Return TRUE if input is /? option.
  121. FALSE otherwise.
  122. */
  123. int IsQuestionMark (int argc, char ** argv)
  124. {
  125. int bIsQuestionMark = FALSE;
  126. char * p;
  127. if (argc == 2)
  128. {
  129. p = argv[1];
  130. while ((*p == '/') || (*p == '\\') || (*p == '-'))
  131. p++;
  132. if (*p == '?')
  133. bIsQuestionMark = TRUE;
  134. }
  135. return(bIsQuestionMark);
  136. }
  137. int IsNoOption (char * option)
  138. {
  139. int bIsNoOption = FALSE;
  140. char * p;
  141. p = option;
  142. while ((*p == '/') || (*p == '\\') || (*p == '-'))
  143. p++;
  144. if (!strncmp (p, __OPT_NO__, max (1, strlen(p))))
  145. bIsNoOption = TRUE;
  146. return(bIsNoOption);
  147. }
  148. /*
  149. Return TRUE if the input match option or shortoption.
  150. FALSE otherwise.
  151. */
  152. int IsValidOption (char *input, char *option, char *shortoption)
  153. {
  154. int bValideInput = FALSE;
  155. while ((*input == '/') || (*input == '\\') || (*input == '-'))
  156. input++;
  157. if (!strcmp (input, shortoption))
  158. {
  159. bValideInput = TRUE;
  160. }
  161. else if (!strcmp (input, option))
  162. {
  163. bValideInput = TRUE;
  164. }
  165. return(bValideInput);
  166. }
  167. void GetJobNameFromArg (int argc, char ** argv, char *jobName)
  168. {
  169. int i;
  170. char *pEqual;
  171. for (i = 0; i < argc; i++)
  172. {
  173. if (pEqual = strchr (argv[i], '='))
  174. {
  175. *pEqual = 0;
  176. if (IsValidOption (argv[i], __JOB__, __SHORT_FOR_JOB__) &&
  177. *(pEqual+1) != 0 &&
  178. strlen (pEqual+1) < MAX_JOB_NAME_LEN)
  179. strcpy (jobName, pEqual+1);
  180. *pEqual = '=';
  181. }
  182. }
  183. return;
  184. }
  185. int IsServerSpecified (int argc, char ** argv)
  186. {
  187. int i;
  188. for (i = 0; i < argc; i++)
  189. {
  190. if (IsValidOption (argv[i], __SERVER__, __SHORT_FOR_SERVER__))
  191. return TRUE;
  192. }
  193. return FALSE;
  194. }
  195. /*
  196. Initialize the capture flags with job config or default value.
  197. */
  198. int InitCaptureParams (unsigned int conn,
  199. char *jobName,
  200. PCAPTURE_PARAMS pCaptureParams)
  201. {
  202. PS_JOB_RECORD psJobRecord;
  203. unsigned int iRet = 0;
  204. // Get job configuration.
  205. if (jobName[0] == 0)
  206. {
  207. // Get Default Job Name.
  208. if ( Is40Server( conn ) )
  209. {
  210. iRet = PS40JobGetDefault( pCaptureParams->NDSCapture,
  211. 0,
  212. NULL,
  213. jobName,
  214. &psJobRecord );
  215. }
  216. else
  217. {
  218. iRet = PSJobGetDefault( conn,
  219. 0,
  220. NULL,
  221. jobName,
  222. &psJobRecord );
  223. }
  224. if ( iRet )
  225. {
  226. if (iRet == PS_ERR_OPENING_DB || iRet == PS_ERR_GETTING_DEFAULT)
  227. {
  228. pCaptureParams->nLPT = 1;
  229. pCaptureParams->bannerUserName[0]=0;
  230. pCaptureParams->serverName[0]=0;
  231. pCaptureParams->queueName[0]=0;
  232. pCaptureParams->filePath[0]=0;
  233. pCaptureParams->captureFlagsRW.JobControlFlags = 0;
  234. pCaptureParams->captureFlagsRW.TabSize = 8;
  235. pCaptureParams->captureFlagsRW.NumCopies = 1;
  236. pCaptureParams->captureFlagsRW.PrintFlags = DEFAULT_PRINT_FLAGS;
  237. pCaptureParams->captureFlagsRW.FormName[0] = 0;
  238. pCaptureParams->captureFlagsRW.FormType = 0;
  239. pCaptureParams->captureFlagsRW.FlushCaptureTimeout = 0;
  240. pCaptureParams->captureFlagsRW.FlushCaptureOnClose = 0;
  241. strcpy (pCaptureParams->captureFlagsRW.BannerText, DEFAULT_BANNER_TEXT);
  242. return(TRUE);
  243. }
  244. else
  245. {
  246. DisplayError (iRet, "PSJobGetDefault");
  247. return(FALSE);
  248. }
  249. }
  250. }
  251. else
  252. {
  253. if ( Is40Server( conn ) )
  254. {
  255. iRet = PS40JobRead( pCaptureParams->NDSCapture,
  256. NULL,
  257. jobName,
  258. &psJobRecord);
  259. }
  260. else
  261. {
  262. iRet = PSJobRead(conn,
  263. NULL,
  264. jobName,
  265. &psJobRecord);
  266. }
  267. if ( iRet )
  268. {
  269. if ( ( iRet == PS_ERR_READING_RECORD) ||
  270. ( iRet == PS_ERR_OPENING_DB) )
  271. DisplayMessage(IDR_JOB_NOT_FOUND, jobName);
  272. else
  273. DisplayError (iRet, "PSJobRead");
  274. return(FALSE);
  275. }
  276. }
  277. pCaptureParams->captureFlagsRW.JobControlFlags = 0;
  278. pCaptureParams->captureFlagsRW.TabSize = psJobRecord.TabSize;
  279. pCaptureParams->captureFlagsRW.NumCopies = psJobRecord.Copies;
  280. pCaptureParams->captureFlagsRW.PrintFlags =
  281. ((psJobRecord.PrintJobFlag & PS_JOB_EXPAND_TABS)? 0 : CAPTURE_FLAG_EXPAND_TABS)
  282. +((psJobRecord.PrintJobFlag & PS_JOB_NO_FORMFEED)? CAPTURE_FLAG_NO_FORMFEED : 0)
  283. +((psJobRecord.PrintJobFlag & PS_JOB_NOTIFY)? CAPTURE_FLAG_NOTIFY : 0)
  284. +((psJobRecord.PrintJobFlag & PS_JOB_PRINT_BANNER)? CAPTURE_FLAG_PRINT_BANNER : 0);
  285. pCaptureParams->captureFlagsRW.FormType = 0;
  286. pCaptureParams->captureFlagsRW.FlushCaptureTimeout = psJobRecord.TimeOutCount;
  287. pCaptureParams->captureFlagsRW.FlushCaptureOnClose = !(psJobRecord.PrintJobFlag & PS_JOB_AUTO_END);
  288. strcpy (pCaptureParams->captureFlagsRW.FormName, psJobRecord.FormName);
  289. strcpy (pCaptureParams->captureFlagsRW.BannerText, (psJobRecord.BannerName[0] == 0)? DEFAULT_BANNER_TEXT : psJobRecord.BannerName);
  290. pCaptureParams->nLPT = psJobRecord.LocalPrinter;
  291. strcpy (pCaptureParams->bannerUserName, psJobRecord.Name);
  292. if ( psJobRecord.PrintJobFlag & PS_JOB_ENV_DS ) {
  293. strcpy (pCaptureParams->serverName, "");
  294. if ( psJobRecord.PrintJobFlag & PS_JOB_DS_PRINTER )
  295. GetPrinterDefaultQueue( pCaptureParams, psJobRecord.u.DSObjectName );
  296. else
  297. strcpy (pCaptureParams->queueName, psJobRecord.u.DSObjectName );
  298. }
  299. else {
  300. strcpy (pCaptureParams->serverName, psJobRecord.u.NonDS.FileServer);
  301. strcpy (pCaptureParams->queueName, psJobRecord.u.NonDS.PrintQueue);
  302. }
  303. pCaptureParams->filePath[0]=0;
  304. return(TRUE);
  305. }
  306. int ReadArguments (int argc,
  307. char ** argv,
  308. char *jobName,
  309. PCAPTURE_PARAMS pCaptureParams)
  310. {
  311. int i, fValidOption = TRUE, fValidParam = TRUE;
  312. char *pEqual = NULL;
  313. for (i = 1; i < argc; i++)
  314. {
  315. if (IsNoOption(argv[i]))
  316. {
  317. if (i != argc - 1)
  318. {
  319. i++;
  320. if (IsValidOption (argv[i], __NOTIFY__, __SHORT_FOR_NOTIFY__))
  321. {
  322. pCaptureParams->captureFlagsRW.PrintFlags &= (0xFF-CAPTURE_FLAG_NOTIFY);
  323. }
  324. else if (IsValidOption (argv[i], __AUTOENDCAP__, __SHORT_FOR_AUTOENDCAP__))
  325. {
  326. pCaptureParams->captureFlagsRW.FlushCaptureOnClose = 1;
  327. }
  328. else if (IsValidOption (argv[i], __TABS__, __SHORT_FOR_TABS__))
  329. {
  330. pCaptureParams->captureFlagsRW.PrintFlags &= (0xFF - CAPTURE_FLAG_EXPAND_TABS);
  331. }
  332. else if (IsValidOption (argv[i], __BANNER__, __SHORT_FOR_BANNER__))
  333. {
  334. pCaptureParams->captureFlagsRW.PrintFlags &= (0xFF - CAPTURE_FLAG_PRINT_BANNER);
  335. }
  336. else if (IsValidOption (argv[i], __FORMFEED__, __SHORT_FOR_FORMFEED__))
  337. {
  338. pCaptureParams->captureFlagsRW.PrintFlags |= CAPTURE_FLAG_NO_FORMFEED;
  339. }
  340. else
  341. {
  342. i--;
  343. fValidOption = FALSE;
  344. break;
  345. }
  346. }
  347. else
  348. {
  349. fValidOption = FALSE;
  350. break;
  351. }
  352. }
  353. else if (IsValidOption (argv[i], __NOTIFY__, __SHORT_FOR_NOTIFY__))
  354. {
  355. pCaptureParams->captureFlagsRW.PrintFlags |= CAPTURE_FLAG_NOTIFY;
  356. }
  357. else if (IsValidOption (argv[i], __NONOTIFY__, __SHORT_FOR_NONOTIFY__))
  358. {
  359. pCaptureParams->captureFlagsRW.PrintFlags &= (0xFF - CAPTURE_FLAG_NOTIFY);
  360. }
  361. else if (IsValidOption (argv[i], __AUTOENDCAP__, __SHORT_FOR_AUTOENDCAP__))
  362. {
  363. pCaptureParams->captureFlagsRW.FlushCaptureOnClose = 0;
  364. }
  365. else if (IsValidOption (argv[i], __NOAUTOENDCAP__, __SHORT_FOR_NOAUTOENDCAP__))
  366. {
  367. pCaptureParams->captureFlagsRW.FlushCaptureOnClose = 1;
  368. }
  369. else if (IsValidOption (argv[i], __NOTABS__, __SHORT_FOR_NOTABS__))
  370. {
  371. pCaptureParams->captureFlagsRW.PrintFlags &= (0xFF - CAPTURE_FLAG_EXPAND_TABS);
  372. }
  373. else if (IsValidOption (argv[i], __NOBANNER__, __SHORT_FOR_NOBANNER__))
  374. {
  375. pCaptureParams->captureFlagsRW.PrintFlags &= (0xFF - CAPTURE_FLAG_PRINT_BANNER);
  376. }
  377. else if (IsValidOption (argv[i], __FORMFEED__, __SHORT_FOR_FORMFEED__))
  378. {
  379. pCaptureParams->captureFlagsRW.PrintFlags &= (0xFF - CAPTURE_FLAG_NO_FORMFEED);
  380. }
  381. else if (IsValidOption (argv[i], __NOFORMFEED__, __SHORT_FOR_NOFORMFEED__))
  382. {
  383. pCaptureParams->captureFlagsRW.PrintFlags |= CAPTURE_FLAG_NO_FORMFEED;
  384. }
  385. else if (IsValidOption (argv[i], __KEEP__, __SHORT_FOR_KEEP__))
  386. {
  387. pCaptureParams->captureFlagsRW.PrintFlags |= CAPTURE_FLAG_KEEP;
  388. }
  389. else
  390. {
  391. // All other valid options should have '=' sign in it.
  392. // Except for LX LPX LPTX
  393. //
  394. pEqual = strchr (argv[i], '=');
  395. // Optionally a ':' works too
  396. if (pEqual == NULL ) {
  397. pEqual = strchr (argv[i], ':');
  398. }
  399. if (pEqual != NULL)
  400. *pEqual = 0;
  401. if (IsValidOption (argv[i], __TIMEOUT__, __SHORT_FOR_TIMEOUT__))
  402. {
  403. if (pEqual == NULL || *(pEqual+1) == 0)
  404. {
  405. DisplayMessage(IDR_TIME_OUT_EXPECTED);
  406. fValidParam = FALSE;
  407. break;
  408. }
  409. pCaptureParams->captureFlagsRW.FlushCaptureTimeout = (USHORT) atoi (pEqual+1);
  410. if (pCaptureParams->captureFlagsRW.FlushCaptureTimeout > 1000)
  411. {
  412. DisplayMessage(IDR_TIMEOUT_OUTOF_RANGE);
  413. fValidParam = FALSE;
  414. break;
  415. }
  416. }
  417. else if (IsValidOption (argv[i], __LOCAL__, __SHORT_FOR_LOCAL__))
  418. {
  419. if (pEqual == NULL || *(pEqual+1) == 0)
  420. {
  421. DisplayMessage(IDR_LPT_NUMBER_EXPECTED);
  422. fValidParam = FALSE;
  423. break;
  424. }
  425. pCaptureParams->nLPT = (unsigned char) atoi (pEqual+1);
  426. if (pCaptureParams->nLPT < 1 || pCaptureParams->nLPT > 3)
  427. {
  428. DisplayMessage(IDR_INVALID_LPT_NUMBER);
  429. fValidParam = FALSE;
  430. break;
  431. }
  432. }
  433. else if (IsValidOption (argv[i], __LOCAL_3__, __LOCAL_2__))
  434. {
  435. if (pEqual == NULL || *(pEqual+1) == 0)
  436. {
  437. DisplayMessage(IDR_LPT_NUMBER_EXPECTED);
  438. fValidParam = FALSE;
  439. break;
  440. }
  441. pCaptureParams->nLPT = (unsigned char) atoi (pEqual+1);
  442. if (pCaptureParams->nLPT < 1 || pCaptureParams->nLPT > 3)
  443. {
  444. DisplayMessage(IDR_INVALID_LPT_NUMBER);
  445. fValidParam = FALSE;
  446. break;
  447. }
  448. }
  449. else if (IsValidOption (argv[i], __JOB__, __SHORT_FOR_JOB__))
  450. {
  451. if (pEqual == NULL ||
  452. *(pEqual+1) == 0 ||
  453. strlen (pEqual+1) > MAX_JOB_NAME_LEN - 1)
  454. {
  455. fValidOption = FALSE;
  456. break;
  457. }
  458. strcpy (jobName, pEqual+1);
  459. }
  460. else if (IsValidOption (argv[i], __SERVER__, __SHORT_FOR_SERVER__))
  461. {
  462. if (pEqual == NULL ||
  463. *(pEqual+1) == 0 ||
  464. strlen (pEqual+1) > MAX_NAME_LEN - 1)
  465. {
  466. fValidOption = FALSE;
  467. break;
  468. }
  469. pCaptureParams->NDSCapture = FALSE;
  470. strcpy (pCaptureParams->serverName, pEqual+1);
  471. }
  472. else if (IsValidOption (argv[i], __QUEUE__, __SHORT_FOR_QUEUE__))
  473. {
  474. if (pEqual == NULL ||
  475. *(pEqual+1) == 0 ||
  476. strlen (pEqual+1) > MAX_QUEUE_NAME_LEN - 1) //compatible.
  477. {
  478. fValidOption = FALSE;
  479. break;
  480. }
  481. strcpy (pCaptureParams->queueName, pEqual+1);
  482. }
  483. else if (IsValidOption (argv[i], __PRINTER__, __SHORT_FOR_PRINTER__))
  484. {
  485. if (pEqual == NULL ||
  486. *(pEqual+1) == 0 ||
  487. !pCaptureParams->NDSCapture ||
  488. strlen (pEqual+1) > MAX_QUEUE_NAME_LEN - 1) //compatible.
  489. {
  490. fValidOption = FALSE;
  491. break;
  492. }
  493. GetPrinterDefaultQueue( pCaptureParams, pEqual+1 );
  494. }
  495. else if (IsValidOption (argv[i], __CREATE__, __SHORT_FOR_CREATE__))
  496. {
  497. if (pEqual != NULL) //compatible.
  498. {
  499. if (strlen (pEqual+1) > _MAX_PATH - 1)
  500. {
  501. DisplayMessage(IDR_INVALID_PATH_NAME, pEqual+1);
  502. fValidParam = FALSE;
  503. break;
  504. }
  505. strcpy (pCaptureParams->filePath, pEqual+1);
  506. }
  507. }
  508. else if (IsValidOption (argv[i], __FORM__, __SHORT_FOR_FORM__))
  509. {
  510. int j = 1;
  511. int bAllNumbers = TRUE;
  512. if (pEqual == NULL || *(pEqual+1) == 0)
  513. {
  514. DisplayMessage(IDR_FORM_EXPECTED);
  515. fValidParam = FALSE;
  516. break;
  517. }
  518. if (strlen (pEqual+1) > 3) // Only allow 3 digits number.
  519. {
  520. DisplayMessage(IDR_INVALID_FORM_NAME, pEqual+1);
  521. fValidParam = FALSE;
  522. break;
  523. }
  524. while (*(pEqual+j) != 0)
  525. {
  526. if (!isdigit (*(pEqual+j)))
  527. {
  528. bAllNumbers = FALSE;
  529. break;
  530. }
  531. j++;
  532. }
  533. if (bAllNumbers)
  534. {
  535. pCaptureParams->captureFlagsRW.FormType = (USHORT) atoi (pEqual+1);
  536. if (pCaptureParams->captureFlagsRW.FormType > 255)
  537. {
  538. DisplayMessage(IDR_INVALID_FORM_TYPE);
  539. fValidParam = FALSE;
  540. break;
  541. }
  542. }
  543. else
  544. {
  545. DisplayMessage(IDR_INVALID_FORM_NAME, pEqual+1);
  546. fValidParam = FALSE;
  547. break;
  548. }
  549. }
  550. else if (IsValidOption (argv[i], __COPIES__, __SHORT_FOR_COPIES__))
  551. {
  552. if (pEqual == NULL || *(pEqual+1) == 0)
  553. {
  554. DisplayMessage(IDR_COPIES_EXPECTED);
  555. fValidParam = FALSE;
  556. break;
  557. }
  558. pCaptureParams->captureFlagsRW.NumCopies = (USHORT) atoi (pEqual+1);
  559. if (pCaptureParams->captureFlagsRW.NumCopies < 1 ||
  560. pCaptureParams->captureFlagsRW.NumCopies > 255)
  561. {
  562. DisplayMessage(IDR_COPIES_OUTOF_RANGE);
  563. fValidParam = FALSE;
  564. break;
  565. }
  566. }
  567. else if (IsValidOption (argv[i], __TABS__, __SHORT_FOR_TABS__))
  568. {
  569. if (pEqual == NULL || *(pEqual+1) == 0)
  570. {
  571. DisplayMessage(IDR_TAB_SIZE_EXPECTED);
  572. fValidParam = FALSE;
  573. break;
  574. }
  575. pCaptureParams->captureFlagsRW.TabSize = (BYTE) atoi (pEqual+1);
  576. if (pCaptureParams->captureFlagsRW.TabSize < 1 ||
  577. pCaptureParams->captureFlagsRW.TabSize > 18)
  578. {
  579. DisplayMessage(IDR_TABSIZE_OUTOF_RANGE);
  580. fValidParam = FALSE;
  581. break;
  582. }
  583. pCaptureParams->captureFlagsRW.PrintFlags |= CAPTURE_FLAG_EXPAND_TABS;
  584. }
  585. else if (IsValidOption (argv[i], __NAME__, __SHORT_FOR_NAME__))
  586. {
  587. if (pEqual == NULL ||
  588. *(pEqual+1) == 0 ||
  589. strlen (pEqual+1) > MAX_BANNER_USER_NAME - 1)
  590. {
  591. fValidOption = FALSE;
  592. break;
  593. }
  594. strcpy (pCaptureParams->bannerUserName, pEqual+1);
  595. }
  596. else if (IsValidOption (argv[i], __BANNER__, __SHORT_FOR_BANNER__))
  597. {
  598. if (pEqual != NULL)
  599. {
  600. if (strlen (pEqual+1) > MAX_BANNER_USER_NAME - 1)
  601. {
  602. DisplayMessage(IDR_INVALID_BANNER, pEqual+1);
  603. fValidParam = FALSE;
  604. break;
  605. }
  606. strcpy (pCaptureParams->captureFlagsRW.BannerText, pEqual+1);
  607. pCaptureParams->captureFlagsRW.PrintFlags |= CAPTURE_FLAG_PRINT_BANNER;
  608. }
  609. }
  610. //
  611. // Kludge for LX LPX LPTX parameters
  612. // Note that L:X L=X, etc are also valid
  613. //
  614. else if ( ( pEqual == NULL ) && ( *(argv[i]) == 'L' ) ) {
  615. pEqual = argv[i];
  616. pEqual++;
  617. if ( *pEqual == 'P' ) {
  618. pEqual++;
  619. if ( *pEqual == 'T' ) {
  620. pEqual++;
  621. }
  622. }
  623. pCaptureParams->nLPT = (unsigned char) atoi (pEqual);
  624. if (pCaptureParams->nLPT < 1 || pCaptureParams->nLPT > 3)
  625. {
  626. DisplayMessage(IDR_INVALID_LPT_NUMBER);
  627. fValidParam = FALSE;
  628. break;
  629. }
  630. }
  631. else
  632. {
  633. fValidOption = FALSE;
  634. break;
  635. }
  636. }
  637. }
  638. if (fValidOption && fValidParam)
  639. {
  640. sprintf (pCaptureParams->captureFlagsRW.JobDescription, __JOB_DESCRIPTION__, pCaptureParams->nLPT);
  641. return(TRUE);
  642. }
  643. else
  644. {
  645. if (!fValidOption)
  646. {
  647. if (pEqual)
  648. *pEqual = '=';
  649. DisplayMessage(IDR_UNKNOW_FLAG, argv[i]);
  650. }
  651. DisplayMessage(IDR_CAPTURE_USAGE);
  652. return(FALSE);
  653. }
  654. }
  655. /*
  656. Show the capture setting.
  657. */
  658. void ShowCapture(void)
  659. {
  660. unsigned int iRet = 0;
  661. int i;
  662. char * queueName;
  663. for (i = 1; i <= 3; i++ )
  664. {
  665. NETWARE_CAPTURE_FLAGS_RW captureFlagsRW;
  666. NETWARE_CAPTURE_FLAGS_RO captureFlagsRO;
  667. if (iRet = GetCaptureFlags ((unsigned char)i,
  668. &captureFlagsRW,
  669. &captureFlagsRO))
  670. {
  671. DisplayError (iRet, "GetCaptureFlags");
  672. }
  673. else
  674. {
  675. char *serverName;
  676. WCHAR timeOut[256];
  677. WCHAR tabs[256];
  678. if (captureFlagsRO.LPTCaptureFlag == 0)
  679. {
  680. DisplayMessage(IDR_NOT_ACTIVE, i);
  681. }
  682. else
  683. {
  684. serverName = captureFlagsRO.ServerName;
  685. if ( !CaptureStringsLoaded ) {
  686. (void) LoadString( NULL, IDR_DISABLED, __DISABLED__, 256 );
  687. (void) LoadString( NULL, IDR_ENABLED, __ENABLED__, 256 );
  688. (void) LoadString( NULL, IDR_YES, __YES__, 256 );
  689. (void) LoadString( NULL, IDR_NO, __NO__, 256 );
  690. (void) LoadString( NULL, IDR_SECONDS, __SECONDS__, 256 );
  691. (void) LoadString( NULL, IDR_CONVERT_TO_SPACE, __CONVERT_TO_SPACE__, 256 );
  692. (void) LoadString( NULL, IDR_NO_CONVERSION, __NO_CONVERSION__, 256 );
  693. (void) LoadString( NULL, IDR_NOTIFY_USER, __NOTIFY_USER__, 256 );
  694. (void) LoadString( NULL, IDR_NOT_NOTIFY_USER, __NOT_NOTIFY_USER__, 256 );
  695. (void) LoadString( NULL, IDR_NONE, __NONE__, 256 );
  696. }
  697. if (captureFlagsRW.FlushCaptureTimeout)
  698. wsprintf (timeOut, __SECONDS__, captureFlagsRW.FlushCaptureTimeout);
  699. else
  700. (void) LoadString( NULL, IDR_DISABLED, timeOut, 256 );
  701. if (captureFlagsRW.PrintFlags & CAPTURE_FLAG_EXPAND_TABS)
  702. wsprintf(tabs, __CONVERT_TO_SPACE__, captureFlagsRW.TabSize);
  703. else
  704. (void) LoadString( NULL, IDR_NO_CONVERSION, tabs, 256 );
  705. queueName = captureFlagsRO.QueueName;
  706. if ( fNDS )
  707. {
  708. if ( captureFlagsRW.PrintFlags & CAPTURE_FLAG_PRINT_BANNER )
  709. {
  710. DisplayMessage(IDR_LPT_STATUS_NDS, i, queueName,
  711. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NOTIFY? __NOTIFY_USER__ : __NOT_NOTIFY_USER__, //Notify
  712. __DISABLED__, //Capture Defaults
  713. captureFlagsRW.FlushCaptureOnClose? __DISABLED__ : __ENABLED__, //AutoEndCap
  714. captureFlagsRW.BannerText, //Banner
  715. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NO_FORMFEED? __NO__ : __YES__, //Form Feed
  716. captureFlagsRW.NumCopies, //Copies
  717. tabs, //Tabs
  718. captureFlagsRW.FormType, timeOut); //Timeout Counts
  719. }
  720. else
  721. {
  722. DisplayMessage(IDR_LPT_STATUS_NO_BANNER_NDS, i, queueName,
  723. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NOTIFY? __NOTIFY_USER__ : __NOT_NOTIFY_USER__, //Notify
  724. __DISABLED__, //Capture Defaults
  725. captureFlagsRW.FlushCaptureOnClose? __DISABLED__ : __ENABLED__, //AutoEndCap
  726. __NONE__, //Banner
  727. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NO_FORMFEED? __NO__ : __YES__, //Form Feed
  728. captureFlagsRW.NumCopies, //Copies
  729. tabs, //Tabs
  730. captureFlagsRW.FormType, timeOut); //Timeout Counts
  731. }
  732. }
  733. else
  734. {
  735. if ( captureFlagsRW.PrintFlags & CAPTURE_FLAG_PRINT_BANNER )
  736. {
  737. DisplayMessage(IDR_LPT_STATUS, i, serverName, queueName,
  738. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NOTIFY? __NOTIFY_USER__ : __NOT_NOTIFY_USER__, //Notify
  739. __DISABLED__, //Capture Defaults
  740. captureFlagsRW.FlushCaptureOnClose? __DISABLED__ : __ENABLED__, //AutoEndCap
  741. captureFlagsRW.BannerText, //Banner
  742. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NO_FORMFEED? __NO__ : __YES__, //Form Feed
  743. captureFlagsRW.NumCopies, //Copies
  744. tabs, //Tabs
  745. captureFlagsRW.FormType, timeOut); //Timeout Counts
  746. }
  747. else
  748. {
  749. DisplayMessage(IDR_LPT_STATUS_NO_BANNER, i, serverName, queueName,
  750. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NOTIFY? __NOTIFY_USER__ : __NOT_NOTIFY_USER__, //Notify
  751. __DISABLED__, //Capture Defaults
  752. captureFlagsRW.FlushCaptureOnClose? __DISABLED__ : __ENABLED__, //AutoEndCap
  753. __NONE__, //Banner
  754. captureFlagsRW.PrintFlags & CAPTURE_FLAG_NO_FORMFEED? __NO__ : __YES__, //Form Feed
  755. captureFlagsRW.NumCopies, //Copies
  756. tabs, //Tabs
  757. captureFlagsRW.FormType, timeOut); //Timeout Counts
  758. }
  759. }
  760. }
  761. }
  762. }
  763. }
  764. int CStartCapture(unsigned int conn,
  765. PCAPTURE_PARAMS pCaptureParams)
  766. {
  767. unsigned int iRet = 0;
  768. unsigned char FullPath[255 + NCP_VOLUME_LENGTH];
  769. unsigned char DirPath[255];
  770. unsigned char VolumeName[NCP_VOLUME_LENGTH];
  771. WORD status;
  772. // Get connection handle.
  773. if ( !pCaptureParams->NDSCapture )
  774. {
  775. if ( pCaptureParams->serverName[0] == 0 )
  776. {
  777. if (iRet = GetFileServerName (conn, pCaptureParams->serverName))
  778. {
  779. DisplayError (iRet, "GetFileServerName");
  780. return (1);
  781. }
  782. }
  783. else
  784. {
  785. if (iRet = GetConnectionHandle (pCaptureParams->serverName, &conn))
  786. {
  787. if ( iRet = NTLoginToFileServer( pCaptureParams->serverName, "GUEST", "" ) ) {
  788. switch ( iRet ) {
  789. case ERROR_INVALID_PASSWORD:
  790. case ERROR_NO_SUCH_USER:
  791. case ERROR_CONNECTION_COUNT_LIMIT:
  792. case ERROR_LOGIN_TIME_RESTRICTION:
  793. case ERROR_LOGIN_WKSTA_RESTRICTION:
  794. case ERROR_ACCOUNT_DISABLED:
  795. case ERROR_PASSWORD_EXPIRED:
  796. case ERROR_REMOTE_SESSION_LIMIT_EXCEEDED:
  797. DisplayMessage( IDR_CAPTURE_FAILED, pCaptureParams->queueName );
  798. DisplayMessage( IDR_ACCESS_DENIED );
  799. break;
  800. default:
  801. DisplayMessage(IDR_SERVER_NOT_FOUND, pCaptureParams->serverName);
  802. }
  803. return (1);
  804. }
  805. else {
  806. if (iRet = GetConnectionHandle (pCaptureParams->serverName, &conn)) {
  807. DisplayMessage(IDR_SERVER_NOT_FOUND, pCaptureParams->serverName);
  808. return (1);
  809. }
  810. }
  811. }
  812. }
  813. }
  814. if (pCaptureParams->filePath[0] != 0)
  815. {
  816. DisplayMessage(IDR_FILE_CAPTURE_UNSUPPORTED);
  817. return (1);
  818. }
  819. else
  820. {
  821. if (pCaptureParams->queueName[0] == 0)
  822. {
  823. if ( pCaptureParams->NDSCapture )
  824. {
  825. DisplayMessage(IDR_NO_QUEUE);
  826. return (1);
  827. }
  828. else
  829. {
  830. // Try to get the default queue ID and name.
  831. if (iRet = GetDefaultPrinterQueue (conn, pCaptureParams->serverName, pCaptureParams->queueName))
  832. {
  833. DisplayMessage(IDR_NO_PRINTERS, pCaptureParams->serverName);
  834. return (1);
  835. }
  836. }
  837. }
  838. // Start queue capture.
  839. if ( pCaptureParams->NDSCapture )
  840. {
  841. char szCanonName[MAX_QUEUE_NAME_LEN];
  842. // Get the full name of the printer queue
  843. // The redirectory wants root based names for
  844. // everything.
  845. iRet = NDSCanonicalizeName( pCaptureParams->queueName,
  846. szCanonName,
  847. NDS_NAME_CHARS,
  848. TRUE );
  849. if ( iRet && ( pCaptureParams->queueName[0] != '.' ) )
  850. {
  851. // If that didn't work, see if it's a root
  852. // based name without the leading period.
  853. strcpy( szCanonName, "." );
  854. strcat( szCanonName, pCaptureParams->queueName );
  855. iRet = NDSCanonicalizeName( szCanonName,
  856. szCanonName,
  857. MAX_QUEUE_NAME_LEN,
  858. TRUE );
  859. }
  860. if ( iRet )
  861. iRet = ERROR_BAD_NETPATH;
  862. else
  863. iRet = StartQueueCapture ( conn,
  864. pCaptureParams->nLPT,
  865. NDSTREE,
  866. szCanonName );
  867. }
  868. else
  869. {
  870. iRet = StartQueueCapture (conn,
  871. pCaptureParams->nLPT,
  872. pCaptureParams->serverName,
  873. pCaptureParams->queueName);
  874. }
  875. if ( iRet )
  876. {
  877. switch ( iRet ) {
  878. case ERROR_ACCESS_DENIED:
  879. case ERROR_INVALID_PASSWORD:
  880. DisplayMessage (IDR_CAPTURE_FAILED, pCaptureParams->queueName);
  881. DisplayMessage (IDR_ACCESS_DENIED);
  882. break;
  883. case ERROR_EXTENDED_ERROR:
  884. NTPrintExtendedError();
  885. break;
  886. case ERROR_BAD_NET_NAME:
  887. case ERROR_BAD_NETPATH:
  888. if ( pCaptureParams->NDSCapture )
  889. DisplayMessage (IDR_NDSQUEUE_NOT_EXIST,
  890. pCaptureParams->queueName,
  891. pCaptureParams->serverName );
  892. else
  893. DisplayMessage (IDR_QUEUE_NOT_EXIST,
  894. pCaptureParams->queueName,
  895. pCaptureParams->serverName );
  896. break;
  897. default:
  898. DisplayError (iRet, "StartQueueCapture");
  899. break;
  900. }
  901. return (1);
  902. }
  903. }
  904. if (pCaptureParams->captureFlagsRW.FlushCaptureOnClose == 1)
  905. DisplayMessage(IDR_NO_AUTOENDCAP);
  906. if ( pCaptureParams->NDSCapture )
  907. DisplayMessage(IDR_NDSSUCCESS_QUEUE, pCaptureParams->nLPT,
  908. pCaptureParams->queueName);
  909. else
  910. DisplayMessage(IDR_SUCCESS_QUEUE, pCaptureParams->nLPT,
  911. pCaptureParams->queueName, pCaptureParams->serverName);
  912. return(0);
  913. }
  914. /*
  915. * Given an NDS printer name, fill in the default queue name
  916. *
  917. */
  918. int
  919. GetPrinterDefaultQueue( PCAPTURE_PARAMS pCaptureParams,
  920. PBYTE PrinterName )
  921. {
  922. BYTE Fixup[ MAX_QUEUE_NAME_LEN];
  923. PBYTE ptr;
  924. unsigned int iRet;
  925. iRet = NDSGetProperty ( PrinterName, "Default Queue",
  926. pCaptureParams->queueName,
  927. MAX_QUEUE_NAME_LEN,
  928. NULL );
  929. if ( iRet )
  930. {
  931. /*
  932. * Strip off the . in front and add context at end
  933. */
  934. ptr = RemoveSpaces (PrinterName);
  935. if ( *ptr == '.' )
  936. {
  937. ptr++;
  938. strncpy( Fixup, ptr, MAX_QUEUE_NAME_LEN );
  939. }
  940. else
  941. {
  942. strncpy( Fixup, ptr, MAX_QUEUE_NAME_LEN );
  943. if ( Fixup[strlen(Fixup)-1] != '.' )
  944. {
  945. strcat( Fixup, "." );
  946. }
  947. (void) NDSGetContext( Fixup + strlen(Fixup),
  948. MAX_QUEUE_NAME_LEN - strlen(Fixup) );
  949. }
  950. iRet = NDSGetProperty ( Fixup, "Default Queue",
  951. pCaptureParams->queueName,
  952. MAX_QUEUE_NAME_LEN,
  953. NULL );
  954. if ( !iRet )
  955. ConvertUnicodeToAscii( pCaptureParams->queueName );
  956. }
  957. return iRet;
  958. }