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.

289 lines
7.9 KiB

  1. //-----------------------------------------------------------------------------
  2. // This files contains the module name for this mini driver. Each mini driver
  3. // must have a unique module name. The module name is used to obtain the
  4. // module handle of this Mini Driver. The module handle is used by the
  5. // generic library to load in tables from the Mini Driver.
  6. //-----------------------------------------------------------------------------
  7. /*++
  8. Copyright (c) 1996-1999 Microsoft Corporation
  9. Module Name:
  10. cmdcb.c
  11. Abstract:
  12. Implementation of GPD command callback for "test.gpd":
  13. OEMCommandCallback
  14. Environment:
  15. Windows NT Unidrv driver
  16. Revision History:
  17. // NOTICE-2002/3/11-takashim
  18. // 04/07/97 -zhanw-
  19. // Created it.
  20. --*/
  21. #include "pdev.h"
  22. //////////////////////////////////////////////////////////////////////////
  23. // Function: BInitOEMExtraData
  24. //
  25. // Description: Initializes OEM Extra data.
  26. //
  27. //
  28. // Parameters:
  29. //
  30. // pOEMExtra Pointer to a OEM Extra data.
  31. //
  32. // dwSize Size of OEM extra data.
  33. //
  34. //
  35. // Returns: TRUE if successful; FALSE otherwise.
  36. //
  37. //
  38. // Comments:
  39. //
  40. //
  41. // History:
  42. // NOTICE-2002/3/11-takashim
  43. // // 02/11/97 APresley Created.
  44. //
  45. //////////////////////////////////////////////////////////////////////////
  46. BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  47. {
  48. // Initialize OEM Extra data.
  49. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  50. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  51. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  52. return TRUE;
  53. }
  54. //////////////////////////////////////////////////////////////////////////
  55. // Function: BMergeOEMExtraData
  56. //
  57. // Description: Validates and merges OEM Extra data.
  58. //
  59. //
  60. // Parameters:
  61. //
  62. // pdmIn pointer to an input OEM private devmode containing the settings
  63. // to be validated and merged. Its size is current.
  64. //
  65. // pdmOut pointer to the output OEM private devmode containing the
  66. // default settings.
  67. //
  68. //
  69. // Returns: TRUE if valid; FALSE otherwise.
  70. //
  71. //
  72. // Comments:
  73. //
  74. //
  75. // History:
  76. // NOTICE-2002/3/11-takashim
  77. // // 02/11/97 APresley Created.
  78. // // 04/08/97 ZhanW Modified the interface
  79. //
  80. //////////////////////////////////////////////////////////////////////////
  81. BOOL BMergeOEMExtraData(
  82. POEMUD_EXTRADATA pdmIn,
  83. POEMUD_EXTRADATA pdmOut
  84. )
  85. {
  86. if(pdmIn) {
  87. //
  88. // copy over the private fields, if they are valid
  89. //
  90. }
  91. return TRUE;
  92. }
  93. #define MINJOBLEN 48
  94. #define MAX_NAMELEN 31
  95. #define WRITESPOOLBUF(p, s, n) \
  96. ((p)->pDrvProcs->DrvWriteSpoolBuf(p, s, n))
  97. //
  98. // Command callback ID's
  99. //
  100. // Do not reorder the following CMD_BARCODEPOS_X group.
  101. #define CMD_BARCODEPOS_0 100
  102. #define CMD_BARCODEPOS_1 101
  103. #define CMD_BARCODEPOS_2 102
  104. #define CMD_BARCODEPOS_3 103
  105. #define CMD_BARCODEPOS_4 104
  106. #define CMD_BARCODEPOS_5 105
  107. #define CMD_BARCODEPOS_6 106
  108. #define CMD_BARCODEPOS_7 107
  109. #define CMD_BARCODEPOS_8 108
  110. // SECURITY:#553895: Mandatory changes (e.g. strsafe.h)
  111. /*
  112. * OEMCommandCallback
  113. */
  114. INT APIENTRY OEMCommandCallback(
  115. PDEVOBJ pdevobj,
  116. DWORD dwCmdCbID,
  117. DWORD dwCount,
  118. PDWORD pdwParams
  119. )
  120. {
  121. INT iRet = 0;
  122. INT iBCID;
  123. INT iDocument;
  124. INT iDocuTemp;
  125. INT iUserName;
  126. INT iUserTemp;
  127. DWORD cbNeeded = 0;
  128. DWORD cReturned = 0;
  129. DWORD CmdSize;
  130. PBYTE pCmd = NULL;
  131. PBYTE pDocument = NULL;
  132. PBYTE pUserName = NULL;
  133. PBYTE pTemp, pNext, pEnd;
  134. PJOB_INFO_1 pJobInfo = NULL;
  135. FILETIME ft, lft;
  136. SYSTEMTIME st;
  137. BYTE ch[MINJOBLEN];
  138. PBYTE pch;
  139. VERBOSE(("OEMCommandCallback entry - %d, %d\r\n", dwCmdCbID, dwCount));
  140. ASSERT(VALID_PDEVOBJ(pdevobj));
  141. switch (dwCmdCbID) {
  142. case CMD_BARCODEPOS_0:
  143. case CMD_BARCODEPOS_1:
  144. case CMD_BARCODEPOS_2:
  145. case CMD_BARCODEPOS_3:
  146. case CMD_BARCODEPOS_4:
  147. case CMD_BARCODEPOS_5:
  148. case CMD_BARCODEPOS_6:
  149. case CMD_BARCODEPOS_7:
  150. case CMD_BARCODEPOS_8:
  151. iBCID = (dwCmdCbID - CMD_BARCODEPOS_0);
  152. //
  153. // Get the first JOB info
  154. //
  155. if (0 != EnumJobs(pdevobj->hPrinter, 0, 1, 1, NULL, 0,
  156. &cbNeeded, &cReturned)
  157. || ERROR_INSUFFICIENT_BUFFER != GetLastError()
  158. || 0 == cbNeeded) {
  159. goto out;
  160. }
  161. if ((pJobInfo = (PJOB_INFO_1)MemAlloc(cbNeeded)) == NULL)
  162. goto out;
  163. if (!EnumJobs(pdevobj->hPrinter, 0, 1, 1, (LPBYTE)pJobInfo, cbNeeded,
  164. &cbNeeded, &cReturned))
  165. goto out;
  166. // Convert to multi-byte
  167. iDocument = WideCharToMultiByte(CP_ACP, 0, pJobInfo->pDocument, -1,
  168. NULL, 0, NULL, NULL);
  169. if (!iDocument)
  170. goto out;
  171. if ((pDocument = (PBYTE)MemAlloc(iDocument)) == NULL)
  172. goto out;
  173. if (!WideCharToMultiByte(CP_ACP, 0, pJobInfo->pDocument, -1,
  174. pDocument, iDocument, NULL, NULL))
  175. goto out;
  176. pTemp = pDocument;
  177. pEnd = &pDocument[min(iDocument - 1, MAX_NAMELEN)];
  178. while (*pTemp) {
  179. // Make sure it is the same context as WideCharTo...
  180. pNext = CharNextExA(CP_ACP, pTemp, 0);
  181. if (pNext > pEnd)
  182. break;
  183. pTemp = pNext;
  184. }
  185. iDocument = (INT)(pTemp - pDocument);
  186. pDocument[iDocument] = '\0';
  187. // Convert to multi-byte
  188. iUserName = WideCharToMultiByte(CP_ACP, 0, pJobInfo->pUserName, -1,
  189. NULL, 0, NULL, NULL);
  190. if (!iUserName)
  191. goto out;
  192. if ((pUserName = (PBYTE)MemAlloc(iUserName)) == NULL)
  193. goto out;
  194. if (!WideCharToMultiByte(CP_ACP, 0, pJobInfo->pUserName, -1,
  195. pUserName, iUserName, NULL, NULL))
  196. goto out;
  197. pTemp = pUserName;
  198. pEnd = &pUserName[min(iUserName - 1, MAX_NAMELEN)];
  199. while (*pTemp) {
  200. // Make sure it is the same context as WideCharTo...
  201. pNext = CharNextExA(CP_ACP, pTemp, 0);
  202. if (pNext > pEnd)
  203. break;
  204. pTemp = pNext;
  205. }
  206. iUserName = (INT)(pTemp - pUserName);
  207. pUserName[iUserName] = '\0';
  208. // Convert to local time
  209. if (!SystemTimeToFileTime(&pJobInfo->Submitted, &ft)
  210. || !FileTimeToLocalFileTime(&ft, &lft)
  211. || !FileTimeToSystemTime(&lft, &st)) {
  212. goto out;
  213. }
  214. // Output commands
  215. CmdSize = 10 + // barcode position and share
  216. iDocument + // document name
  217. iUserName + // user name
  218. 16 + // Date & Time
  219. 32; // Other characters
  220. if ((pCmd = (PBYTE)MemAlloc(CmdSize)) == NULL)
  221. goto out;
  222. if (FAILED(StringCchPrintfExA(pCmd, CmdSize, &pch, NULL, 0,
  223. "%d,0,\"%s\",\"%s\",\"%4d/%02d/%02d %02d:%02d\";EXIT;",
  224. iBCID, pDocument, pUserName,
  225. st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute)))
  226. goto out;
  227. WRITESPOOLBUF(pdevobj, pCmd, (DWORD)(pch - pCmd));
  228. goto done;
  229. out:
  230. if (FAILED(StringCchPrintfExA(ch, sizeof ch, &pch, NULL, 0,
  231. "%d,0,\"Windows2000\",\"Kyocera\",\"\";EXIT;",
  232. iBCID)))
  233. goto done;
  234. WRITESPOOLBUF(pdevobj, ch, (DWORD)(pch - ch));
  235. done:
  236. if (pCmd) MemFree(pCmd);
  237. if (pUserName) MemFree(pUserName);
  238. if (pDocument) MemFree(pDocument);
  239. if (pJobInfo) MemFree(pJobInfo);
  240. break;
  241. }
  242. return iRet;
  243. }