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.

368 lines
9.6 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. #include "pdev.h" // defined in sub-directory such as DDICMDCB, FONTCB, etc.
  15. #include <strsafe.h>
  16. DWORD gdwDrvMemPoolTag = 'meoD'; // lib.h requires this global var, for debugging
  17. ////////////////////////////////////////////////////////
  18. // INTERNAL PROTOTYPES
  19. ////////////////////////////////////////////////////////
  20. static BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra);
  21. static BOOL BMergeOEMExtraData(POEMUD_EXTRADATA pdmIn, POEMUD_EXTRADATA pdmOut);
  22. static BOOL BIsValidOEMDevModeParam(DWORD dwMode, POEMDMPARAM pOEMDevModeParam);
  23. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam);
  24. BOOL APIENTRY OEMGetInfo(DWORD dwInfo, PVOID pBuffer, DWORD cbSize, PDWORD pcbNeeded)
  25. {
  26. LPTSTR OEM_INFO[] = { __TEXT("Bad Index"),
  27. __TEXT("OEMGI_GETSIGNATURE"),
  28. __TEXT("OEMGI_GETINTERFACEVERSION"),
  29. __TEXT("OEMGI_GETVERSION"),
  30. };
  31. //DbgPrint(DLLTEXT("OEMGetInfo(%s) entry.\r\n"), OEM_INFO[dwInfo]);
  32. // Validate parameters.
  33. if( ( (OEMGI_GETSIGNATURE != dwInfo) &&
  34. (OEMGI_GETINTERFACEVERSION != dwInfo) &&
  35. (OEMGI_GETVERSION != dwInfo) ) ||
  36. (NULL == pcbNeeded)
  37. )
  38. {
  39. //DbgPrint(ERRORTEXT("OEMGetInfo() ERROR_INVALID_PARAMETER.\r\n"));
  40. // Did not write any bytes.
  41. if(NULL != pcbNeeded)
  42. *pcbNeeded = 0;
  43. return FALSE;
  44. }
  45. // Need/wrote 4 bytes.
  46. *pcbNeeded = 4;
  47. // Validate buffer size. Minimum size is four bytes.
  48. if( (NULL == pBuffer) || (4 > cbSize) )
  49. {
  50. //DbgPrint(ERRORTEXT("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\r\n"));
  51. return FALSE;
  52. }
  53. // Write information to buffer.
  54. switch(dwInfo)
  55. {
  56. case OEMGI_GETSIGNATURE:
  57. *(LPDWORD)pBuffer = OEM_SIGNATURE;
  58. break;
  59. case OEMGI_GETINTERFACEVERSION:
  60. *(LPDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  61. break;
  62. case OEMGI_GETVERSION:
  63. *(LPDWORD)pBuffer = OEM_VERSION;
  64. break;
  65. }
  66. return TRUE;
  67. }
  68. BOOL APIENTRY OEMDevMode(
  69. DWORD dwMode,
  70. POEMDMPARAM pOEMDevModeParam)
  71. {
  72. LPTSTR OEMDevMode_fMode[] = { __TEXT("NULL"),
  73. __TEXT("OEMDM_SIZE"),
  74. __TEXT("OEMDM_DEFAULT"),
  75. __TEXT("OEMDM_CONVERT"),
  76. __TEXT("OEMDM_MERGE"),
  77. };
  78. //DbgPrint(DLLTEXT("OEMDevMode(%s) entry.\r\n"), OEMDevMode_fMode[dwMode]);
  79. // Validate parameters.
  80. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  81. {
  82. //DbgPrint(ERRORTEXT("OEMDevMode() ERROR_INVALID_PARAMETER.\r\n"));
  83. VDumpOEMDevModeParam(pOEMDevModeParam);
  84. return FALSE;
  85. }
  86. // Verify OEM extra data size.
  87. if( (dwMode != OEMDM_SIZE) &&
  88. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  89. {
  90. //DbgPrint(ERRORTEXT("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\r\n"));
  91. return FALSE;
  92. }
  93. // Handle dwMode.
  94. switch(dwMode)
  95. {
  96. case OEMDM_SIZE:
  97. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  98. break;
  99. case OEMDM_DEFAULT:
  100. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  101. case OEMDM_CONVERT:
  102. // nothing to convert for this private devmode. So just initialize it.
  103. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  104. case OEMDM_MERGE:
  105. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  106. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  107. {
  108. //DbgPrint(__TEXT("OEMUD OEMDevMode(): not valid OEM Extra Data.\r\n"));
  109. return FALSE;
  110. }
  111. break;
  112. }
  113. return TRUE;
  114. }
  115. //////////////////////////////////////////////////////////////////////////
  116. // Function: BInitOEMExtraData
  117. //
  118. // Description: Initializes OEM Extra data.
  119. //
  120. //
  121. // Parameters:
  122. //
  123. // pOEMExtra Pointer to a OEM Extra data.
  124. //
  125. // dwSize Size of OEM extra data.
  126. //
  127. //
  128. // Returns: TRUE if successful; FALSE otherwise.
  129. //
  130. //
  131. // Comments:
  132. //
  133. //
  134. // History:
  135. // 02/11/97 APresley Created.
  136. //
  137. //////////////////////////////////////////////////////////////////////////
  138. static BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  139. {
  140. // Initialize OEM Extra data.
  141. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  142. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  143. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  144. memcpy(pOEMExtra->cbTestString, TESTSTRING, sizeof(TESTSTRING));
  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. if(pdmIn)
  179. {
  180. //
  181. // copy over the private fields, if they are valid
  182. //
  183. memcmp(pdmOut->cbTestString, pdmIn->cbTestString, sizeof(TESTSTRING));
  184. }
  185. return TRUE;
  186. }
  187. //////////////////////////////////////////////////////////////////////////
  188. // Function: BIsValidOEMDevModeParam
  189. //
  190. // Description: Validates OEM_DEVMODEPARAM structure.
  191. //
  192. //
  193. // Parameters:
  194. //
  195. // dwMode calling mode
  196. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  197. //
  198. //
  199. // Returns: TRUE if valid; FALSE otherwise.
  200. //
  201. //
  202. // Comments:
  203. //
  204. //
  205. // History:
  206. // 02/11/97 APresley Created.
  207. //
  208. //////////////////////////////////////////////////////////////////////////
  209. static BOOL BIsValidOEMDevModeParam(
  210. DWORD dwMode,
  211. POEMDMPARAM pOEMDevModeParam)
  212. {
  213. BOOL bValid = TRUE;
  214. if(NULL == pOEMDevModeParam)
  215. {
  216. //DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\r\n"));
  217. return FALSE;
  218. }
  219. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  220. {
  221. //DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\r\n"));
  222. bValid = FALSE;
  223. }
  224. if(NULL == pOEMDevModeParam->hPrinter)
  225. {
  226. //DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\r\n"));
  227. bValid = FALSE;
  228. }
  229. if(NULL == pOEMDevModeParam->hModule)
  230. {
  231. //DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\r\n"));
  232. bValid = FALSE;
  233. }
  234. if( (0 != pOEMDevModeParam->cbBufSize) &&
  235. (NULL == pOEMDevModeParam->pOEMDMOut)
  236. )
  237. {
  238. //DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\r\n"));
  239. bValid = FALSE;
  240. }
  241. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  242. {
  243. //DbgPrint(__TEXT("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\r\n"));
  244. bValid = FALSE;
  245. }
  246. return bValid;
  247. }
  248. //////////////////////////////////////////////////////////////////////////
  249. // Function: VDumpOEMDevModeParam
  250. //
  251. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  252. //
  253. //
  254. // Parameters:
  255. //
  256. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  257. //
  258. //
  259. // Returns: N/A.
  260. //
  261. //
  262. // Comments:
  263. //
  264. //
  265. // History:
  266. // 02/18/97 APresley Created.
  267. //
  268. //////////////////////////////////////////////////////////////////////////
  269. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  270. {
  271. // Can't dump if pOEMDevModeParam NULL.
  272. if(NULL != pOEMDevModeParam)
  273. {
  274. //DbgPrint(__TEXT("\r\n\tOEM_DEVMODEPARAM dump:\r\n\r\n"));
  275. //DbgPrint(__TEXT("\tcbSize = %d.\r\n"), pOEMDevModeParam->cbSize);
  276. //DbgPrint(__TEXT("\thPrinter = %#lx.\r\n"), pOEMDevModeParam->hPrinter);
  277. //DbgPrint(__TEXT("\thModule = %#lx.\r\n"), pOEMDevModeParam->hModule);
  278. //DbgPrint(__TEXT("\tpPublicDMIn = %#lx.\r\n"), pOEMDevModeParam->pPublicDMIn);
  279. //DbgPrint(__TEXT("\tpPublicDMOut = %#lx.\r\n"), pOEMDevModeParam->pPublicDMOut);
  280. //DbgPrint(__TEXT("\tpOEMDMIn = %#lx.\r\n"), pOEMDevModeParam->pOEMDMIn);
  281. //DbgPrint(__TEXT("\tpOEMDMOut = %#lx.\r\n"), pOEMDevModeParam->pOEMDMOut);
  282. //DbgPrint(__TEXT("\tcbBufSize = %d.\r\n"), pOEMDevModeParam->cbBufSize);
  283. }
  284. }
  285. //
  286. // Functions for outputting debug messages
  287. //
  288. #if 0
  289. VOID DbgPrint(IN LPCTSTR pstrFormat, ...)
  290. {
  291. va_list ap;
  292. va_start(ap, pstrFormat);
  293. EngDebugPrint("", (PCHAR) pstrFormat, ap);
  294. va_end(ap);
  295. }
  296. #endif