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.

308 lines
11 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright 1998 - 2003 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // FILE: command.cpp
  9. //
  10. //
  11. // PURPOSE: Source module for OEM customized Command(s).
  12. //
  13. //
  14. // Functions:
  15. //
  16. //
  17. //
  18. //
  19. // PLATFORMS: Windows 2000, Windows XP, Windows Server 2003
  20. //
  21. //
  22. #include "precomp.h"
  23. #include <PRCOMOEM.H>
  24. #include "oemps.h"
  25. #include "debug.h"
  26. #include "command.h"
  27. #include "resource.h"
  28. // StrSafe.h needs to be included last
  29. // to disallow bad string functions.
  30. #include <STRSAFE.H>
  31. ////////////////////////////////////////////////////////
  32. // Internal String Literals
  33. ////////////////////////////////////////////////////////
  34. const CHAR TEST_BEGINSTREAM[] = "%%Test: Before begin stream\r\n";
  35. const CHAR TEST_PSADOBE[] = "%%Test: Before %!PS-Adobe\r\n";
  36. const CHAR TEST_PAGESATEND[] = "%%Test: Replace driver's %%PagesAtend\r\n";
  37. const CHAR TEST_PAGES[] = "%%Test: Replace driver's %%Pages: (atend)\r\n";
  38. const CHAR TEST_DOCUMENTPROCESSCOLORS[] = "%%Test: Replace driver's %%DocumentProcessColors: (atend)\r\n";
  39. const CHAR TEST_COMMENTS[] = "%%Test: Before %%EndComments\r\n";
  40. const CHAR TEST_DEFAULTS[] = "%%Test: Before %%BeginDefaults and %%EndDefaults\r\n";
  41. const CHAR TEST_BEGINPROLOG[] = "%%Test: After %%BeginProlog\r\n";
  42. const CHAR TEST_ENDPROLOG[] = "%%Test: Before %%EndProlog\r\n";
  43. const CHAR TEST_BEGINSETUP[] = "%%Test: After %%BeginSetup\r\n";
  44. const CHAR TEST_ENDSETUP[] = "%%Test: Before %%EndSetup\r\n";
  45. const CHAR TEST_BEGINPAGESETUP[] = "%%Test: After %%BeginPageSetup\r\n";
  46. const CHAR TEST_ENDPAGESETUP[] = "%%Test: Before %%EndpageSetup\r\n";
  47. const CHAR TEST_PAGETRAILER[] = "%%Test: After %%PageTrailer\r\n";
  48. const CHAR TEST_TRAILER[] = "%%Test: After %%Trailer\r\n";
  49. const CHAR TEST_PAGENUMBER[] = "%%Test: Replace driver's %%Page:\r\n";
  50. const CHAR TEST_PAGEORDER[] = "%%Test: Replace driver's %%PageOrder:\r\n";
  51. const CHAR TEST_ORIENTATION[] = "%%Test: Replace driver's %%Orientation:\r\n";
  52. const CHAR TEST_BOUNDINGBOX[] = "%%Test: Replace driver's %%BoundingBox:\r\n";
  53. const CHAR TEST_DOCNEEDEDRES[] = "%%Test: Append to driver's %%DocumentNeededResourc\r\n";
  54. const CHAR TEST_DOCSUPPLIEDRES[] = "%%Test: Append to driver's %%DocumentSuppliedResou\r\n";
  55. const CHAR TEST_EOF[] = "%%Test: After %%EOF\r\n";
  56. const CHAR TEST_ENDSTREAM[] = "%%Test: After the last byte of job stream\r\n";
  57. const CHAR TEST_DOCUMENTPROCESSCOLORSATEND[] = "%%Test: DocumentProcessColorsAtend\r\n";
  58. const CHAR TEST_VMSAVE[] = "%%Test: %%VMSave\r\n";
  59. const CHAR TEST_VMRESTORE[] = "%%Test: %%VMRestore\r\n";
  60. const CHAR TEST_PLATECOLOR[] = "%%Test: %%PlateColor:\r\n";
  61. const CHAR TEST_SHOWPAGE[] = "%%Test: %%SowPage:\r\n";
  62. const CHAR TEST_PAGEBBOX[] = "%%Test: %%PageBox:\r\n";
  63. const CHAR TEST_ENDPAGECOMMENTS[] = "%%Test: %%EndPageComments:\r\n";
  64. ////////////////////////////////////////////////////////////////////////////////////
  65. // The PSCRIPT driver calls this OEM function at specific points during output
  66. // generation. This gives the OEM DLL an opportunity to insert code fragments
  67. // at specific injection points in the driver's code. It should use
  68. // DrvWriteSpoolBuf for generating any output it requires.
  69. HRESULT PSCommand(PDEVOBJ pdevobj, DWORD dwIndex, PVOID pData, DWORD cbSize,
  70. IPrintOemDriverPS* pOEMHelp, PDWORD pdwReturn)
  71. {
  72. PCSTR pProcedure = NULL;
  73. DWORD dwLen = 0;
  74. DWORD dwSize = 0;
  75. HRESULT hResult = E_FAIL;
  76. VERBOSE(DLLTEXT("Entering OEMCommand...\r\n"));
  77. switch (dwIndex)
  78. {
  79. case PSINJECT_BEGINSTREAM:
  80. VERBOSE(DLLTEXT("OEMCommand PSINJECT_BEGINSTREAM\n"));
  81. pProcedure = TEST_BEGINSTREAM;
  82. break;
  83. case PSINJECT_PSADOBE:
  84. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PSADOBE\n"));
  85. pProcedure = TEST_PSADOBE;
  86. break;
  87. case PSINJECT_PAGESATEND:
  88. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PAGESATEND\n"));
  89. pProcedure = TEST_PAGESATEND;
  90. break;
  91. case PSINJECT_PAGES:
  92. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PAGES\n"));
  93. pProcedure = TEST_PAGES;
  94. break;
  95. case PSINJECT_DOCNEEDEDRES:
  96. VERBOSE(DLLTEXT("OEMCommand PSINJECT_DOCNEEDEDRES\n"));
  97. pProcedure = TEST_DOCNEEDEDRES;
  98. break;
  99. case PSINJECT_DOCSUPPLIEDRES:
  100. VERBOSE(DLLTEXT("OEMCommand PSINJECT_DOCSUPPLIEDRES\n"));
  101. pProcedure = TEST_DOCSUPPLIEDRES;
  102. break;
  103. case PSINJECT_PAGEORDER:
  104. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PAGEORDER\n"));
  105. pProcedure = TEST_PAGEORDER;
  106. break;
  107. case PSINJECT_ORIENTATION:
  108. VERBOSE(DLLTEXT("OEMCommand PSINJECT_ORIENTATION\n"));
  109. pProcedure = TEST_ORIENTATION;
  110. break;
  111. case PSINJECT_BOUNDINGBOX:
  112. VERBOSE(DLLTEXT("OEMCommand PSINJECT_BOUNDINGBOX\n"));
  113. pProcedure = TEST_BOUNDINGBOX;
  114. break;
  115. case PSINJECT_DOCUMENTPROCESSCOLORS:
  116. VERBOSE(DLLTEXT("OEMCommand PSINJECT_DOCUMENTPROCESSCOLORS\n"));
  117. pProcedure = TEST_DOCUMENTPROCESSCOLORS;
  118. break;
  119. case PSINJECT_COMMENTS:
  120. VERBOSE(DLLTEXT("OEMCommand PSINJECT_COMMENTS\n"));
  121. pProcedure = TEST_COMMENTS;
  122. break;
  123. case PSINJECT_BEGINDEFAULTS:
  124. VERBOSE(DLLTEXT("OEMCommand PSINJECT_BEGINDEFAULTS\n"));
  125. pProcedure = TEST_DEFAULTS;
  126. break;
  127. case PSINJECT_ENDDEFAULTS:
  128. VERBOSE(DLLTEXT("OEMCommand PSINJECT_BEGINDEFAULTS\n"));
  129. pProcedure = TEST_DEFAULTS;
  130. break;
  131. case PSINJECT_BEGINPROLOG:
  132. VERBOSE(DLLTEXT("OEMCommand PSINJECT_BEGINPROLOG\n"));
  133. pProcedure = TEST_BEGINPROLOG;
  134. break;
  135. case PSINJECT_ENDPROLOG:
  136. VERBOSE(DLLTEXT("OEMCommand PSINJECT_ENDPROLOG\n"));
  137. pProcedure = TEST_ENDPROLOG;
  138. break;
  139. case PSINJECT_BEGINSETUP:
  140. VERBOSE(DLLTEXT("OEMCommand PSINJECT_BEGINSETUP\n"));
  141. pProcedure = TEST_BEGINSETUP;
  142. break;
  143. case PSINJECT_ENDSETUP:
  144. VERBOSE(DLLTEXT("OEMCommand PSINJECT_ENDSETUP\n"));
  145. pProcedure = TEST_ENDSETUP;
  146. break;
  147. case PSINJECT_BEGINPAGESETUP:
  148. VERBOSE(DLLTEXT("OEMCommand PSINJECT_BEGINPAGESETUP\n"));
  149. pProcedure = TEST_BEGINPAGESETUP;
  150. break;
  151. case PSINJECT_ENDPAGESETUP:
  152. VERBOSE(DLLTEXT("OEMCommand PSINJECT_ENDPAGESETUP\n"));
  153. pProcedure = TEST_ENDPAGESETUP;
  154. break;
  155. case PSINJECT_PAGETRAILER:
  156. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PAGETRAILER\n"));
  157. pProcedure = TEST_PAGETRAILER;
  158. break;
  159. case PSINJECT_TRAILER:
  160. VERBOSE(DLLTEXT("OEMCommand PSINJECT_TRAILER\n"));
  161. pProcedure = TEST_TRAILER;
  162. break;
  163. case PSINJECT_PAGENUMBER:
  164. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PAGENUMBER\n"));
  165. pProcedure = TEST_PAGENUMBER;
  166. break;
  167. case PSINJECT_EOF:
  168. VERBOSE(DLLTEXT("OEMCommand PSINJECT_EOF\n"));
  169. pProcedure = TEST_EOF;
  170. break;
  171. case PSINJECT_ENDSTREAM:
  172. VERBOSE(DLLTEXT("OEMCommand PSINJECT_ENDSTREAM\n"));
  173. pProcedure = TEST_ENDSTREAM;
  174. break;
  175. case PSINJECT_DOCUMENTPROCESSCOLORSATEND:
  176. VERBOSE(DLLTEXT("OEMCommand PSINJECT_DOCUMENTPROCESSCOLORSATEND\n"));
  177. pProcedure = TEST_DOCUMENTPROCESSCOLORSATEND;
  178. break;
  179. case PSINJECT_VMSAVE:
  180. VERBOSE(DLLTEXT("OEMCommand PSINJECT_VMSAVE\n"));
  181. pProcedure = TEST_VMSAVE;
  182. break;
  183. case PSINJECT_VMRESTORE:
  184. VERBOSE(DLLTEXT("OEMCommand PSINJECT_VMRESTORE\n"));
  185. pProcedure = TEST_VMRESTORE;
  186. break;
  187. case PSINJECT_PLATECOLOR:
  188. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PLATECOLOR\n"));
  189. pProcedure = TEST_PLATECOLOR;
  190. break;
  191. case PSINJECT_SHOWPAGE:
  192. VERBOSE(DLLTEXT("OEMCommand PSINJECT_SHOWPAGE\n"));
  193. pProcedure = TEST_SHOWPAGE;
  194. break;
  195. case PSINJECT_PAGEBBOX:
  196. VERBOSE(DLLTEXT("OEMCommand PSINJECT_PAGEBBOX\n"));
  197. pProcedure = TEST_PAGEBBOX;
  198. break;
  199. case PSINJECT_ENDPAGECOMMENTS:
  200. VERBOSE(DLLTEXT("OEMCommand PSINJECT_ENDPAGECOMMENTS\n"));
  201. pProcedure = TEST_ENDPAGECOMMENTS;
  202. break;
  203. default:
  204. ERR(DLLTEXT("Undefined PSCommand %d!\r\n"), dwIndex);
  205. *pdwReturn = ERROR_NOT_SUPPORTED;
  206. return E_NOTIMPL;
  207. }
  208. // INVARIANT: should have injection string.
  209. if(NULL != pProcedure)
  210. {
  211. // Write PostScript to spool file.
  212. dwLen = strlen(pProcedure);
  213. hResult = pOEMHelp->DrvWriteSpoolBuf(pdevobj, const_cast<PSTR>(pProcedure), dwLen, &dwSize);
  214. // Dump DrvWriteSpoolBuf parameters.
  215. VERBOSE(DLLTEXT("dwLen = %d\r\n"), dwLen);
  216. VERBOSE(DLLTEXT("dwSize = %d\r\n"), dwSize);
  217. //VERBOSE(DLLTEXT("pProcedure is:\r\n\t%hs\r\n"), pProcedure);
  218. // Set return values.
  219. if(SUCCEEDED(hResult) && (dwLen == dwSize))
  220. {
  221. *pdwReturn = ERROR_SUCCESS;
  222. }
  223. else
  224. {
  225. // Try to return meaningful
  226. // error value.
  227. *pdwReturn = GetLastError();
  228. if(ERROR_SUCCESS == *pdwReturn)
  229. {
  230. *pdwReturn = ERROR_WRITE_FAULT;
  231. }
  232. // Make sure we return failure
  233. // if the write didn't succeded.
  234. if(SUCCEEDED(hResult))
  235. {
  236. hResult = HRESULT_FROM_WIN32(*pdwReturn);
  237. }
  238. }
  239. }
  240. else
  241. {
  242. // This should never be reached.
  243. // Hence the RIP, but if we do
  244. // in non-debug version, we should
  245. // return appropriate values.
  246. RIP(DLLTEXT("PSCommand pProcedure is NULL!\r\n"));
  247. *pdwReturn = ERROR_NOT_SUPPORTED;
  248. hResult = E_NOTIMPL;
  249. }
  250. // dwLen should always equal dwSize.
  251. ASSERTMSG(dwLen == dwSize, DLLTEXT("number of bytes wrote should equal number of bytes written!"));
  252. return hResult;
  253. }