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.

430 lines
16 KiB

  1. /*++
  2. Copyright (c) 1996-2002 Microsoft Corp. & Ricoh Co., Ltd. All rights reserved.
  3. FILE: RIAFRES.C
  4. Abstract: Main file for OEM rendering plugin module.
  5. Functions: OEMCommandCallback
  6. OEMHalftonePattern
  7. Environment: Windows NT Unidrv5 driver
  8. Revision History:
  9. 02/25/2000 -Masatoshi Kubokura-
  10. Created it.
  11. 06/07/2000 -Masatoshi Kubokura-
  12. V.1.11
  13. 08/02/2000 -Masatoshi Kubokura-
  14. V.1.11 for NT4
  15. 10/17/2000 -Masatoshi Kubokura-
  16. Last modified for XP inbox.
  17. 09/28/2001 -Masatoshi Kubokura-
  18. Implement OEMHalftonePattern
  19. 03/01/2002 -Masatoshi Kubokura-
  20. Include strsafe.h.
  21. Add FileNameBufSize as arg3 at RWFileData().
  22. Use safe_sprintfA() instead of sprintf().
  23. 03/29/2002 -Masatoshi Kubokura-
  24. Check pdevobj NULL pointer before using at OEMCommandCallback().
  25. 04/02/2002 -Masatoshi Kubokura-
  26. Use safe_strlenA() instead of strlen().
  27. --*/
  28. #include "pdev.h"
  29. #ifndef WINNT_40
  30. #include "strsafe.h" // @Feb/26/2002
  31. #endif // !WINNT_40
  32. //
  33. // Misc definitions and declarations.
  34. //
  35. #ifndef WINNT_40
  36. #define strcmp lstrcmpA
  37. //#define sprintf wsprintfA
  38. //#define strlen lstrlenA // @Aug/01/2000
  39. #endif // !WINNT_40
  40. // external prototypes
  41. // @Feb/26/2002 ->
  42. //extern BOOL RWFileData(PFILEDATA pFileData, LPWSTR pwszFileName, LONG type);
  43. extern BOOL RWFileData(PFILEDATA pFileData, LPWSTR pwszFileName, LONG FileNameBufSize, LONG type);
  44. // @Feb/26/2002 <-
  45. // command definition
  46. static BYTE PJL_PROOFJOB[] = "@PJL PROOFJOB\n";
  47. static BYTE PJL_SECUREJOB[] = "@PJL SECUREJOB\n"; // Aficio AP3200 and later (GW model)
  48. static BYTE PJL_DISKIMAGE_OFF[] = "@PJL SET DISKIMAGE=OFF\n";
  49. static BYTE PJL_DISKIMAGE_PORT[] = "@PJL SET DISKIMAGE=PORTRAIT\n";
  50. static BYTE PJL_DISKIMAGE_LAND[] = "@PJL SET DISKIMAGE=LANDSCAPE\n";
  51. static BYTE PJL_ORIENT_PORT[] = "@PJL SET ORIENTATION=PORTRAIT\n";
  52. static BYTE PJL_ORIENT_LAND[] = "@PJL SET ORIENTATION=LANDSCAPE\n";
  53. static BYTE PJL_JOBPASSWORD[] = "@PJL SET JOBPASSWORD=%s\n";
  54. static BYTE PJL_USERID[] = "@PJL SET USERID=\x22%s\x22\n";
  55. static BYTE PJL_USERCODE[] = "@PJL SET USERCODE=\x22%s\x22\n";
  56. static BYTE PJL_TIME_DATE[] = "@PJL SET TIME=\x22%02d:%02d:%02d\x22\n@PJL SET DATE=\x22%04d/%02d/%02d\x22\n";
  57. static BYTE PJL_STARTJOB_AUTOTRAYCHANGE_OFF[] = "\x1B%%-12345X@PJL JOB NAME=\x22%s\x22\n@PJL SET AUTOTRAYCHANGE=OFF\n";
  58. static BYTE PJL_STARTJOB_AUTOTRAYCHANGE_ON[] = "\x1B%%-12345X@PJL JOB NAME=\x22%s\x22\n@PJL SET AUTOTRAYCHANGE=ON\n";
  59. static BYTE PJL_ENDJOB[] = "\x1B%%-12345X@PJL EOJ NAME=\x22%s\x22\n\x1B%%-12345X";
  60. static BYTE PJL_QTY_JOBOFFSET_OFF[] = "@PJL SET QTY=%d\n@PJL SET JOBOFFSET=OFF\n";
  61. static BYTE PJL_QTY_JOBOFFSET_ROTATE[] = "@PJL SET QTY=%d\n@PJL SET JOBOFFSET=ROTATE\n";
  62. static BYTE PJL_QTY_JOBOFFSET_SHIFT[] = "@PJL SET QTY=%d\n@PJL SET JOBOFFSET=SHIFT\n";
  63. static BYTE P5_COPIES[] = "\x1B&l%dX";
  64. static BYTE P6_ENDPAGE[] = "\xc1%c%c\xf8\x31\x44";
  65. static BYTE P6_ENDSESSION[] = "\x49\x42";
  66. static BYTE HTPattern_AdonisP3[256] = {
  67. 109, 55, 62, 115, 134, 217, 208, 154, 111, 58, 64, 117, 135, 220, 211, 155,
  68. 103, 2, 22, 69, 160, 226, 248, 199, 104, 10, 26, 72, 163, 228, 251, 201,
  69. 97, 49, 38, 77, 168, 233, 241, 191, 98, 50, 44, 79, 169, 236, 242, 193,
  70. 128, 90, 84, 122, 141, 175, 183, 147, 129, 92, 86, 123, 142, 177, 185, 148,
  71. 139, 224, 215, 158, 112, 59, 66, 119, 137, 222, 213, 157, 114, 60, 67, 120,
  72. 166, 231, 255, 206, 106, 14, 32, 74, 164, 230, 252, 204, 108, 18, 35, 75,
  73. 173, 239, 246, 197, 100, 51, 47, 80, 171, 237, 244, 195, 101, 53, 48, 82,
  74. 145, 181, 189, 152, 131, 93, 87, 124, 144, 179, 186, 150, 132, 95, 89, 126,
  75. 111, 58, 65, 118, 136, 221, 212, 156, 110, 56, 63, 116, 135, 218, 209, 154,
  76. 105, 10, 26, 73, 163, 228, 251, 202, 104, 6, 22, 70, 161, 227, 250, 200,
  77. 99, 50, 44, 79, 170, 236, 243, 194, 98, 49, 41, 78, 168, 234, 242, 192,
  78. 130, 92, 86, 124, 143, 178, 185, 149, 129, 91, 85, 122, 141, 176, 184, 147,
  79. 138, 223, 214, 158, 114, 61, 68, 121, 140, 225, 216, 159, 113, 59, 67, 119,
  80. 165, 230, 253, 205, 109, 18, 35, 76, 167, 232, 255, 207, 107, 14, 32, 74,
  81. 172, 238, 245, 196, 102, 54, 48, 83, 174, 240, 247, 198, 101, 51, 47, 81,
  82. 144, 180, 187, 151, 133, 96, 89, 127, 146, 182, 190, 153, 132, 94, 88, 125
  83. };
  84. INT safe_sprintfA(
  85. char* pszDest,
  86. size_t cchDest,
  87. const char* pszFormat,
  88. ...)
  89. {
  90. #ifndef WINNT_40
  91. HRESULT hr;
  92. char* pszDestEnd;
  93. size_t cchRemaining;
  94. #endif // !WINNT_40
  95. va_list argList;
  96. INT retSize = 0;
  97. va_start(argList, pszFormat);
  98. #ifndef WINNT_40
  99. hr = StringCchVPrintfExA(pszDest, cchDest, &pszDestEnd, &cchRemaining,
  100. STRSAFE_NO_TRUNCATION, pszFormat, argList);
  101. if (SUCCEEDED(hr))
  102. retSize = cchDest - cchRemaining;
  103. #else // WINNT_40
  104. if ((retSize = vsprintf(pszDest, pszFormat, argList)) < 0)
  105. retSize = 0;
  106. #endif // WINNT_40
  107. va_end(argList);
  108. return retSize;
  109. } //*** safe_sprintfA
  110. INT safe_strlenA(
  111. char* psz,
  112. size_t cchMax)
  113. {
  114. #ifndef WINNT_40
  115. HRESULT hr;
  116. size_t cch = 0;
  117. hr = StringCchLengthA(psz, cchMax, &cch);
  118. VERBOSE(("** safe_strlenA: size(lstrlen)=%d **\n", lstrlenA(psz)));
  119. VERBOSE(("** safe_strlenA: size(StringCchLength)=%d **\n", cch));
  120. if (SUCCEEDED(hr))
  121. return cch;
  122. else
  123. return 0;
  124. #else // WINNT_40
  125. return strlen(psz);
  126. #endif // WINNT_40
  127. } //*** safe_strlenA
  128. INT APIENTRY OEMCommandCallback(
  129. PDEVOBJ pdevobj,
  130. DWORD dwCmdCbID,
  131. DWORD dwCount,
  132. PDWORD pdwParams)
  133. {
  134. INT ocmd;
  135. BYTE Cmd[256];
  136. #ifdef WINNT_40 // @Aug/01/2000
  137. ENG_TIME_FIELDS st;
  138. #else // !WINNT_40
  139. SYSTEMTIME st;
  140. #endif // !WINNT_40
  141. FILEDATA FileData;
  142. // @Mar/29/2002 ->
  143. // POEMUD_EXTRADATA pOEMExtra = MINIPRIVATE_DM(pdevobj);
  144. // POEMPDEV pOEM = MINIDEV_DATA(pdevobj);
  145. POEMUD_EXTRADATA pOEMExtra;
  146. POEMPDEV pOEM;
  147. // @Mar/29/2002 <-
  148. DWORD dwCopy;
  149. #if DBG
  150. // You can see debug messages on debugger terminal. (debug mode boot)
  151. giDebugLevel = DBG_VERBOSE;
  152. // You can debug with MS Visual Studio. (normal mode boot)
  153. // DebugBreak();
  154. #endif // DBG
  155. VERBOSE(("OEMCommandCallback() entry (%ld).\n", dwCmdCbID));
  156. // verify pdevobj okay
  157. ASSERT(VALID_PDEVOBJ(pdevobj));
  158. // @Mar/29/2002 ->
  159. pOEMExtra = MINIPRIVATE_DM(pdevobj);
  160. pOEM = MINIDEV_DATA(pdevobj);
  161. // @Mar/29/2002 <-
  162. // Check whether copy# is in the range. @Sep/07/2000
  163. switch (dwCmdCbID)
  164. {
  165. case CMD_COLLATE_JOBOFFSET_OFF:
  166. case CMD_COLLATE_JOBOFFSET_ROTATE:
  167. case CMD_COLLATE_JOBOFFSET_SHIFT:
  168. case CMD_COPIES_P5:
  169. case CMD_ENDPAGE_P6:
  170. if((dwCopy = *pdwParams) > 999L) // *pdwParams: NumOfCopies
  171. dwCopy = 999L;
  172. else if(dwCopy < 1L)
  173. dwCopy = 1L;
  174. break;
  175. }
  176. // Emit commands.
  177. ocmd = 0;
  178. switch (dwCmdCbID)
  179. {
  180. case CMD_STARTJOB_AUTOTRAYCHANGE_OFF: // Aficio AP3200 and later (GW model)
  181. case CMD_STARTJOB_PORT_AUTOTRAYCHANGE_OFF: // Aficio 551,700,850,1050
  182. case CMD_STARTJOB_LAND_AUTOTRAYCHANGE_OFF: // Aficio 551,700,850,1050
  183. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_STARTJOB_AUTOTRAYCHANGE_OFF, pOEM->JobName);
  184. goto _EMIT_JOB_NAME;
  185. case CMD_STARTJOB_AUTOTRAYCHANGE_ON: // Aficio AP3200 and later (GW model)
  186. case CMD_STARTJOB_PORT_AUTOTRAYCHANGE_ON: // Aficio 551,700,850,1050
  187. case CMD_STARTJOB_LAND_AUTOTRAYCHANGE_ON: // Aficio 551,700,850,1050
  188. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_STARTJOB_AUTOTRAYCHANGE_ON, pOEM->JobName);
  189. _EMIT_JOB_NAME:
  190. // Emit job name
  191. VERBOSE((" Start Job=%s\n", Cmd));
  192. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  193. ocmd = 0;
  194. switch (pOEMExtra->JobType)
  195. {
  196. default:
  197. case IDC_RADIO_JOB_NORMAL:
  198. if (CMD_STARTJOB_PORT_AUTOTRAYCHANGE_OFF == dwCmdCbID ||
  199. CMD_STARTJOB_PORT_AUTOTRAYCHANGE_ON == dwCmdCbID ||
  200. CMD_STARTJOB_LAND_AUTOTRAYCHANGE_OFF == dwCmdCbID ||
  201. CMD_STARTJOB_LAND_AUTOTRAYCHANGE_ON == dwCmdCbID)
  202. {
  203. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_DISKIMAGE_OFF);
  204. }
  205. if (IDC_RADIO_LOG_ENABLED == pOEMExtra->LogDisabled)
  206. goto _EMIT_USERID_USERCODE;
  207. break;
  208. case IDC_RADIO_JOB_SAMPLE:
  209. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_PROOFJOB);
  210. if (CMD_STARTJOB_PORT_AUTOTRAYCHANGE_OFF == dwCmdCbID ||
  211. CMD_STARTJOB_PORT_AUTOTRAYCHANGE_ON == dwCmdCbID ||
  212. CMD_STARTJOB_LAND_AUTOTRAYCHANGE_OFF == dwCmdCbID ||
  213. CMD_STARTJOB_LAND_AUTOTRAYCHANGE_ON == dwCmdCbID)
  214. {
  215. ocmd += safe_sprintfA(&Cmd[ocmd], sizeof(Cmd) - ocmd, PJL_DISKIMAGE_OFF);
  216. }
  217. goto _CHECK_PRINT_DONE;
  218. case IDC_RADIO_JOB_SECURE:
  219. switch (dwCmdCbID)
  220. {
  221. case CMD_STARTJOB_AUTOTRAYCHANGE_OFF: // Aficio AP3200 and later (GW model)
  222. case CMD_STARTJOB_AUTOTRAYCHANGE_ON:
  223. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_SECUREJOB);
  224. break;
  225. case CMD_STARTJOB_PORT_AUTOTRAYCHANGE_OFF: // Aficio 551,700,850,1050
  226. case CMD_STARTJOB_PORT_AUTOTRAYCHANGE_ON:
  227. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_DISKIMAGE_PORT);
  228. break;
  229. case CMD_STARTJOB_LAND_AUTOTRAYCHANGE_OFF: // Aficio 551,700,850,1050
  230. case CMD_STARTJOB_LAND_AUTOTRAYCHANGE_ON:
  231. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_DISKIMAGE_LAND);
  232. break;
  233. }
  234. ocmd += safe_sprintfA(&Cmd[ocmd], sizeof(Cmd) - ocmd, PJL_JOBPASSWORD, pOEMExtra->PasswordBuf);
  235. _CHECK_PRINT_DONE:
  236. // If previous print is finished and hold-options flag isn't valid,
  237. // do not emit sample-print/secure-print command.
  238. // This prevents unexpected job until user pushes Apply button on the
  239. // Job/Log property sheet.
  240. FileData.fUiOption = 0;
  241. // @Feb/26/2002 ->
  242. // RWFileData(&FileData, pOEMExtra->SharedFileName, GENERIC_READ);
  243. RWFileData(&FileData, pOEMExtra->SharedFileName, sizeof(pOEMExtra->SharedFileName), GENERIC_READ);
  244. // @Feb/26/2002 <-
  245. if (BITTEST32(FileData.fUiOption, PRINT_DONE) &&
  246. !BITTEST32(pOEMExtra->fUiOption, HOLD_OPTIONS))
  247. {
  248. VERBOSE(("** Emit Nothing. **\n"));
  249. ocmd = 0;
  250. }
  251. _EMIT_USERID_USERCODE:
  252. if (1 <= safe_strlenA(pOEMExtra->UserIdBuf, sizeof(pOEMExtra->UserIdBuf)))
  253. ocmd += safe_sprintfA(&Cmd[ocmd], sizeof(Cmd) - ocmd, PJL_USERID, pOEMExtra->UserIdBuf);
  254. else
  255. ocmd += safe_sprintfA(&Cmd[ocmd], sizeof(Cmd) - ocmd, PJL_USERID, "?");
  256. if (1 <= safe_strlenA(pOEMExtra->UserCodeBuf, sizeof(pOEMExtra->UserCodeBuf)))
  257. ocmd += safe_sprintfA(&Cmd[ocmd], sizeof(Cmd) - ocmd, PJL_USERCODE, pOEMExtra->UserCodeBuf);
  258. #ifdef WINNT_40 // @Aug/01/2000
  259. EngQueryLocalTime(&st);
  260. ocmd += safe_sprintfA(&Cmd[ocmd], sizeof(Cmd) - ocmd, PJL_TIME_DATE,
  261. st.usHour, st.usMinute, st.usSecond,
  262. st.usYear, st.usMonth, st.usDay);
  263. #else // !WINNT_40
  264. GetLocalTime(&st);
  265. ocmd += safe_sprintfA(&Cmd[ocmd], sizeof(Cmd) - ocmd, PJL_TIME_DATE,
  266. st.wHour, st.wMinute, st.wSecond,
  267. st.wYear, st.wMonth, st.wDay);
  268. #endif // !WINNT_40
  269. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  270. break;
  271. }
  272. // Emit orientation (Aficio 551,700,850,1050)
  273. switch (dwCmdCbID)
  274. {
  275. case CMD_STARTJOB_PORT_AUTOTRAYCHANGE_OFF:
  276. case CMD_STARTJOB_PORT_AUTOTRAYCHANGE_ON:
  277. WRITESPOOLBUF(pdevobj, PJL_ORIENT_PORT, sizeof(PJL_ORIENT_PORT)-1);
  278. break;
  279. case CMD_STARTJOB_LAND_AUTOTRAYCHANGE_OFF:
  280. case CMD_STARTJOB_LAND_AUTOTRAYCHANGE_ON:
  281. WRITESPOOLBUF(pdevobj, PJL_ORIENT_LAND, sizeof(PJL_ORIENT_LAND)-1);
  282. break;
  283. }
  284. break;
  285. case CMD_COLLATE_JOBOFFSET_OFF: // @Sep/08/2000
  286. if (IDC_RADIO_JOB_SAMPLE != pOEMExtra->JobType) // if NOT Sample Print, QTY=1 is emitted here.
  287. dwCopy = 1L;
  288. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_QTY_JOBOFFSET_OFF, dwCopy);
  289. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  290. break;
  291. case CMD_COLLATE_JOBOFFSET_ROTATE: // @Sep/07/2000
  292. if (IDC_RADIO_JOB_SAMPLE == pOEMExtra->JobType) // if Sample Print
  293. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_QTY_JOBOFFSET_ROTATE, dwCopy); // QTY=n is emitted here.
  294. else
  295. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_QTY_JOBOFFSET_OFF, 1); // QTY=1 is emitted here.
  296. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  297. break;
  298. case CMD_COLLATE_JOBOFFSET_SHIFT: // @Sep/07/2000
  299. if (IDC_RADIO_JOB_SAMPLE == pOEMExtra->JobType) // if Sample Print
  300. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_QTY_JOBOFFSET_SHIFT, dwCopy); // QTY=n is emitted here.
  301. else
  302. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_QTY_JOBOFFSET_OFF, 1); // QTY=1 is emitted here.
  303. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  304. break;
  305. case CMD_COPIES_P5: // @Sep/07/2000
  306. if (IDC_RADIO_JOB_SAMPLE == pOEMExtra->JobType) // if Sample Print (QTY=n was emitted before.)
  307. dwCopy = 1L;
  308. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), P5_COPIES, dwCopy);
  309. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  310. break;
  311. case CMD_ENDPAGE_P6: // @Sep/07/2000
  312. if (IDC_RADIO_JOB_SAMPLE == pOEMExtra->JobType) // if Sample Print (QTY=n was emitted before.)
  313. dwCopy = 1L;
  314. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), P6_ENDPAGE, (BYTE)dwCopy, (BYTE)(dwCopy >> 8));
  315. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  316. break;
  317. case CMD_ENDJOB_P6: // @Aug/23/2000
  318. WRITESPOOLBUF(pdevobj, P6_ENDSESSION, sizeof(P6_ENDSESSION)-1);
  319. // go through
  320. case CMD_ENDJOB_P5:
  321. ocmd = safe_sprintfA(Cmd, sizeof(Cmd), PJL_ENDJOB, pOEM->JobName);
  322. VERBOSE((" End Job=%s\n", Cmd));
  323. WRITESPOOLBUF(pdevobj, Cmd, ocmd);
  324. switch (pOEMExtra->JobType)
  325. {
  326. case IDC_RADIO_JOB_SAMPLE:
  327. case IDC_RADIO_JOB_SECURE:
  328. // Set PRINT_DONE flag in the file
  329. FileData.fUiOption = pOEMExtra->fUiOption;
  330. BITSET32(FileData.fUiOption, PRINT_DONE);
  331. // @Feb/26/2002 ->
  332. // RWFileData(&FileData, pOEMExtra->SharedFileName, GENERIC_WRITE);
  333. RWFileData(&FileData, pOEMExtra->SharedFileName, sizeof(pOEMExtra->SharedFileName), GENERIC_WRITE);
  334. // @Feb/26/2002 <-
  335. break;
  336. default:
  337. break;
  338. }
  339. break;
  340. default:
  341. ERR((("Unknown callback ID = %d.\n"), dwCmdCbID));
  342. break;
  343. }
  344. #if DBG
  345. giDebugLevel = DBG_ERROR;
  346. #endif // DBG
  347. return 0;
  348. } //*** OEMCommandCallback
  349. BOOL APIENTRY OEMHalftonePattern(
  350. PDEVOBJ pdevobj,
  351. PBYTE pHTPattern,
  352. DWORD dwHTPatternX,
  353. DWORD dwHTPatternY,
  354. DWORD dwHTNumPatterns,
  355. DWORD dwCallbackID,
  356. PBYTE pResource,
  357. DWORD dwResourceSize)
  358. {
  359. PBYTE pSrc;
  360. DWORD dwLen = sizeof(HTPattern_AdonisP3);
  361. #if DBG
  362. giDebugLevel = DBG_VERBOSE;
  363. #endif // DBG
  364. VERBOSE(("OEMHalftonePattern() entry (CallbackID:%ld, PatX=%ld).\n", dwCallbackID, dwHTPatternX));
  365. if (dwLen != (((dwHTPatternX * dwHTPatternY) + 3) / 4) * 4 * dwHTNumPatterns)
  366. return FALSE;
  367. pSrc = HTPattern_AdonisP3;
  368. while (dwLen-- > 0)
  369. *pHTPattern++ = *pSrc++;
  370. VERBOSE(("OEMHalftonePattern() exit\n"));
  371. #if DBG
  372. giDebugLevel = DBG_ERROR;
  373. #endif // DBG
  374. return TRUE;
  375. } //*** OEMHalftonePattern