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.

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