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.

347 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. Implementation of OEMGetInfo and OEMDevMode.
  7. Shared by all Unidrv OEM test dll's.
  8. Environment:
  9. Windows NT Unidrv driver
  10. Revision History:
  11. 04/07/97 -zhanw-
  12. Created it.
  13. --*/
  14. // NTRAID#NTBUG9-572152-2002/03/12-yasuho-: Remove the dead code.
  15. #include "pdev.h" // defined in sub-directory such as DDICMDCB, FONTCB, etc.
  16. DWORD gdwDrvMemPoolTag = 'meoD'; // lib.h requires this global var, for debugging
  17. ////////////////////////////////////////////////////////
  18. // INTERNAL PROTOTYPES
  19. ////////////////////////////////////////////////////////
  20. // NTRAID#NTBUG9-493148-2002/03/12-yasuho-:
  21. // Stress break: PDEV resetting via OEMDevMode().
  22. static BOOL BInitOEMExtraData(POEM_EXTRADATA pOEMExtra);
  23. static BOOL BMergeOEMExtraData(POEM_EXTRADATA pdmIn, POEM_EXTRADATA pdmOut);
  24. static BOOL BIsValidOEMDevModeParam(DWORD dwMode, POEMDMPARAM pOEMDevModeParam);
  25. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam);
  26. BOOL APIENTRY OEMGetInfo(DWORD dwInfo, PVOID pBuffer, DWORD cbSize, PDWORD pcbNeeded)
  27. {
  28. LPCSTR OEM_INFO[] = { "Bad Index",
  29. "OEMGI_GETSIGNATURE",
  30. "OEMGI_GETINTERFACEVERSION",
  31. "OEMGI_GETVERSION",
  32. };
  33. VERBOSE(("OEMGetInfo(%s) entry.\n", OEM_INFO[dwInfo]));
  34. // Validate parameters.
  35. if( ( (OEMGI_GETSIGNATURE != dwInfo) &&
  36. (OEMGI_GETINTERFACEVERSION != dwInfo) &&
  37. (OEMGI_GETVERSION != dwInfo) ) ||
  38. (NULL == pcbNeeded)
  39. )
  40. {
  41. ERR(("OEMGetInfo() ERROR_INVALID_PARAMETER.\n"));
  42. // Did not write any bytes.
  43. if(NULL != pcbNeeded)
  44. *pcbNeeded = 0;
  45. return FALSE;
  46. }
  47. // Need/wrote 4 bytes.
  48. *pcbNeeded = 4;
  49. // Validate buffer size. Minimum size is four bytes.
  50. if( (NULL == pBuffer) || (4 > cbSize) )
  51. {
  52. ERR(("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\n"));
  53. return FALSE;
  54. }
  55. // Write information to buffer.
  56. switch(dwInfo)
  57. {
  58. case OEMGI_GETSIGNATURE:
  59. *(LPDWORD)pBuffer = OEM_SIGNATURE;
  60. break;
  61. case OEMGI_GETINTERFACEVERSION:
  62. *(LPDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  63. break;
  64. case OEMGI_GETVERSION:
  65. *(LPDWORD)pBuffer = OEM_VERSION;
  66. break;
  67. }
  68. return TRUE;
  69. }
  70. BOOL APIENTRY OEMDevMode(
  71. DWORD dwMode,
  72. POEMDMPARAM pOEMDevModeParam)
  73. {
  74. LPCSTR OEMDevMode_fMode[] = { "NULL",
  75. "OEMDM_SIZE",
  76. "OEMDM_DEFAULT",
  77. "OEMDM_CONVERT",
  78. "OEMDM_MERGE",
  79. };
  80. VERBOSE(("OEMDevMode(%s) entry.\n", OEMDevMode_fMode[dwMode]));
  81. // Validate parameters.
  82. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  83. {
  84. ERR(("OEMDevMode() ERROR_INVALID_PARAMETER.\n"));
  85. VDumpOEMDevModeParam(pOEMDevModeParam);
  86. return FALSE;
  87. }
  88. // Verify OEM extra data size.
  89. if( (dwMode != OEMDM_SIZE) &&
  90. sizeof(OEM_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  91. {
  92. ERR(("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\n"));
  93. return FALSE;
  94. }
  95. // Handle dwMode.
  96. switch(dwMode)
  97. {
  98. case OEMDM_SIZE:
  99. pOEMDevModeParam->cbBufSize = sizeof(OEM_EXTRADATA);
  100. break;
  101. case OEMDM_DEFAULT:
  102. return BInitOEMExtraData((POEM_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  103. case OEMDM_CONVERT:
  104. // nothing to convert for this private devmode. So just initialize it.
  105. return BInitOEMExtraData((POEM_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  106. case OEMDM_MERGE:
  107. if(!BMergeOEMExtraData((POEM_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  108. (POEM_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  109. {
  110. VERBOSE(("OEMUD OEMDevMode(): not valid OEM Extra Data.\n"));
  111. return FALSE;
  112. }
  113. break;
  114. }
  115. return TRUE;
  116. }
  117. //////////////////////////////////////////////////////////////////////////
  118. // Function: BInitOEMExtraData
  119. //
  120. // Description: Initializes OEM Extra data.
  121. //
  122. //
  123. // Parameters:
  124. //
  125. // pOEMExtra Pointer to a OEM Extra data.
  126. //
  127. // dwSize Size of OEM extra data.
  128. //
  129. //
  130. // Returns: TRUE if successful; FALSE otherwise.
  131. //
  132. //
  133. // Comments:
  134. //
  135. //
  136. // History:
  137. // 02/11/97 APresley Created.
  138. //
  139. //////////////////////////////////////////////////////////////////////////
  140. static BOOL BInitOEMExtraData(POEM_EXTRADATA pOEMExtra)
  141. {
  142. // Initialize OEM Extra data.
  143. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEM_EXTRADATA);
  144. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  145. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  146. return TRUE;
  147. }
  148. //////////////////////////////////////////////////////////////////////////
  149. // Function: BMergeOEMExtraData
  150. //
  151. // Description: Validates and merges OEM Extra data.
  152. //
  153. //
  154. // Parameters:
  155. //
  156. // pdmIn pointer to an input OEM private devmode containing the settings
  157. // to be validated and merged. Its size is current.
  158. //
  159. // pdmOut pointer to the output OEM private devmode containing the
  160. // default settings.
  161. //
  162. //
  163. // Returns: TRUE if valid; FALSE otherwise.
  164. //
  165. //
  166. // Comments:
  167. //
  168. //
  169. // History:
  170. // 02/11/97 APresley Created.
  171. // 04/08/97 ZhanW Modified the interface
  172. //
  173. //////////////////////////////////////////////////////////////////////////
  174. static BOOL BMergeOEMExtraData(
  175. POEM_EXTRADATA pdmIn,
  176. POEM_EXTRADATA pdmOut
  177. )
  178. {
  179. return TRUE;
  180. }
  181. //////////////////////////////////////////////////////////////////////////
  182. // Function: BIsValidOEMDevModeParam
  183. //
  184. // Description: Validates OEM_DEVMODEPARAM structure.
  185. //
  186. //
  187. // Parameters:
  188. //
  189. // dwMode calling mode
  190. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  191. //
  192. //
  193. // Returns: TRUE if valid; FALSE otherwise.
  194. //
  195. //
  196. // Comments:
  197. //
  198. //
  199. // History:
  200. // 02/11/97 APresley Created.
  201. //
  202. //////////////////////////////////////////////////////////////////////////
  203. static BOOL BIsValidOEMDevModeParam(
  204. DWORD dwMode,
  205. POEMDMPARAM pOEMDevModeParam)
  206. {
  207. BOOL bValid = TRUE;
  208. if(NULL == pOEMDevModeParam)
  209. {
  210. VERBOSE(("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\n"));
  211. return FALSE;
  212. }
  213. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  214. {
  215. VERBOSE(("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\n"));
  216. bValid = FALSE;
  217. }
  218. if(NULL == pOEMDevModeParam->hPrinter)
  219. {
  220. VERBOSE(("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\n"));
  221. bValid = FALSE;
  222. }
  223. if(NULL == pOEMDevModeParam->hModule)
  224. {
  225. VERBOSE(("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\n"));
  226. bValid = FALSE;
  227. }
  228. if( (0 != pOEMDevModeParam->cbBufSize) &&
  229. (NULL == pOEMDevModeParam->pOEMDMOut)
  230. )
  231. {
  232. VERBOSE(("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\n"));
  233. bValid = FALSE;
  234. }
  235. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  236. {
  237. VERBOSE(("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\n"));
  238. bValid = FALSE;
  239. }
  240. return bValid;
  241. }
  242. //////////////////////////////////////////////////////////////////////////
  243. // Function: VDumpOEMDevModeParam
  244. //
  245. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  246. //
  247. //
  248. // Parameters:
  249. //
  250. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  251. //
  252. //
  253. // Returns: N/A.
  254. //
  255. //
  256. // Comments:
  257. //
  258. //
  259. // History:
  260. // 02/18/97 APresley Created.
  261. //
  262. //////////////////////////////////////////////////////////////////////////
  263. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  264. {
  265. // Can't dump if pOEMDevModeParam NULL.
  266. if(NULL != pOEMDevModeParam)
  267. {
  268. VERBOSE(("\n\tOEM_DEVMODEPARAM dump:\r\n\r\n"));
  269. VERBOSE(("\tcbSize = %d.\n", pOEMDevModeParam->cbSize));
  270. VERBOSE(("\thPrinter = %#lx.\n", pOEMDevModeParam->hPrinter));
  271. VERBOSE(("\thModule = %#lx.\n", pOEMDevModeParam->hModule));
  272. VERBOSE(("\tpPublicDMIn = %#lx.\n", pOEMDevModeParam->pPublicDMIn));
  273. VERBOSE(("\tpPublicDMOut = %#lx.\n", pOEMDevModeParam->pPublicDMOut));
  274. VERBOSE(("\tpOEMDMIn = %#lx.\n", pOEMDevModeParam->pOEMDMIn));
  275. VERBOSE(("\tpOEMDMOut = %#lx.\n", pOEMDevModeParam->pOEMDMOut));
  276. VERBOSE(("\tcbBufSize = %d.\n", pOEMDevModeParam->cbBufSize));
  277. }
  278. }