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.

346 lines
9.2 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-568220-2002/03/07-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-289908-2002/03/08-yasuho-: pOEMDM -> pdevOEM
  21. static BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra);
  22. static BOOL BMergeOEMExtraData(POEMUD_EXTRADATA pdmIn, POEMUD_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. LPTSTR OEM_INFO[] = { __TEXT("Bad Index"),
  28. __TEXT("OEMGI_GETSIGNATURE"),
  29. __TEXT("OEMGI_GETINTERFACEVERSION"),
  30. __TEXT("OEMGI_GETVERSION"),
  31. };
  32. // DbgPrint(DLLTEXT("OEMGetInfo(%s) entry.\r\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. // DbgPrint(ERRORTEXT("OEMGetInfo() ERROR_INVALID_PARAMETER.\r\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. // DbgPrint(ERRORTEXT("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\r\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. LPTSTR OEMDevMode_fMode[] = { __TEXT("NULL"),
  74. __TEXT("OEMDM_SIZE"),
  75. __TEXT("OEMDM_DEFAULT"),
  76. __TEXT("OEMDM_CONVERT"),
  77. __TEXT("OEMDM_MERGE"),
  78. };
  79. // DbgPrint(DLLTEXT("OEMDevMode(%s) entry.\r\n"), OEMDevMode_fMode[dwMode]);
  80. // Validate parameters.
  81. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  82. {
  83. // DbgPrint(ERRORTEXT("OEMDevMode() ERROR_INVALID_PARAMETER.\r\n"));
  84. VDumpOEMDevModeParam(pOEMDevModeParam);
  85. return FALSE;
  86. }
  87. // Verify OEM extra data size.
  88. if( (dwMode != OEMDM_SIZE) &&
  89. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  90. {
  91. // DbgPrint(ERRORTEXT("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\r\n"));
  92. return FALSE;
  93. }
  94. // Handle dwMode.
  95. switch(dwMode)
  96. {
  97. case OEMDM_SIZE:
  98. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  99. break;
  100. case OEMDM_DEFAULT:
  101. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  102. case OEMDM_CONVERT:
  103. // nothing to convert for this private devmode. So just initialize it.
  104. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  105. case OEMDM_MERGE:
  106. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  107. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  108. {
  109. // DbgPrint(__TEXT("OEMUD OEMDevMode(): not valid OEM Extra Data.\r\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. //
  135. // History:
  136. // 02/11/97 APresley Created.
  137. //
  138. //////////////////////////////////////////////////////////////////////////
  139. static BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  140. {
  141. // Initialize OEM Extra data.
  142. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_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. //
  168. // History:
  169. // 02/11/97 APresley Created.
  170. // 04/08/97 ZhanW Modified the interface
  171. //
  172. //////////////////////////////////////////////////////////////////////////
  173. static BOOL BMergeOEMExtraData(
  174. POEMUD_EXTRADATA pdmIn,
  175. POEMUD_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. //
  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. // DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\r\n"));
  210. return FALSE;
  211. }
  212. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  213. {
  214. // DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\r\n"));
  215. bValid = FALSE;
  216. }
  217. if(NULL == pOEMDevModeParam->hPrinter)
  218. {
  219. // DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\r\n"));
  220. bValid = FALSE;
  221. }
  222. if(NULL == pOEMDevModeParam->hModule)
  223. {
  224. // DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\r\n"));
  225. bValid = FALSE;
  226. }
  227. if( (0 != pOEMDevModeParam->cbBufSize) &&
  228. (NULL == pOEMDevModeParam->pOEMDMOut)
  229. )
  230. {
  231. // DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\r\n"));
  232. bValid = FALSE;
  233. }
  234. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  235. {
  236. // DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\r\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. //
  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. // DbgPrint(__TEXT("\r\n\tOEM_DEVMODEPARAM dump:\r\n\r\n"));
  268. // DbgPrint(__TEXT("\tcbSize = %d.\r\n"), pOEMDevModeParam->cbSize);
  269. // DbgPrint(__TEXT("\thPrinter = %#lx.\r\n"), pOEMDevModeParam->hPrinter);
  270. // DbgPrint(__TEXT("\thModule = %#lx.\r\n"), pOEMDevModeParam->hModule);
  271. // DbgPrint(__TEXT("\tpPublicDMIn = %#lx.\r\n"), pOEMDevModeParam->pPublicDMIn);
  272. // DbgPrint(__TEXT("\tpPublicDMOut = %#lx.\r\n"), pOEMDevModeParam->pPublicDMOut);
  273. // DbgPrint(__TEXT("\tpOEMDMIn = %#lx.\r\n"), pOEMDevModeParam->pOEMDMIn);
  274. // DbgPrint(__TEXT("\tpOEMDMOut = %#lx.\r\n"), pOEMDevModeParam->pOEMDMOut);
  275. // DbgPrint(__TEXT("\tcbBufSize = %d.\r\n"), pOEMDevModeParam->cbBufSize);
  276. }
  277. }