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.

270 lines
7.3 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/3/11-takashim
  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. extern BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra);
  21. extern 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. #if DBG
  27. LPCSTR OEM_INFO[] = { "Bad Index",
  28. "OEMGI_GETSIGNATURE",
  29. "OEMGI_GETINTERFACEVERSION",
  30. "OEMGI_GETVERSION",
  31. };
  32. VERBOSE(("OEMGetInfo(%s) entry.\n", OEM_INFO[dwInfo]));
  33. #endif // DBG
  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 size of DWORD bytes.
  48. *pcbNeeded = sizeof(DWORD);
  49. // Validate buffer size. Minimum size is four bytes.
  50. if( (NULL == pBuffer) || (sizeof(DWORD) > 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. #if DBG
  75. LPCSTR OEMDevMode_fMode[] = { "NULL",
  76. "OEMDM_SIZE",
  77. "OEMDM_DEFAULT",
  78. "OEMDM_CONVERT",
  79. "OEMDM_MERGE",
  80. };
  81. VERBOSE(("OEMDevMode(%s) entry.\n", OEMDevMode_fMode[dwMode]));
  82. #endif // DBG
  83. // Validate parameters.
  84. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  85. {
  86. ERR(("OEMDevMode() ERROR_INVALID_PARAMETER.\n"));
  87. VDumpOEMDevModeParam(pOEMDevModeParam);
  88. return FALSE;
  89. }
  90. // Verify OEM extra data size.
  91. if( (dwMode != OEMDM_SIZE) &&
  92. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  93. {
  94. ERR(("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\n"));
  95. return FALSE;
  96. }
  97. // Handle dwMode.
  98. switch(dwMode)
  99. {
  100. case OEMDM_SIZE:
  101. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  102. break;
  103. case OEMDM_DEFAULT:
  104. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  105. case OEMDM_CONVERT:
  106. // nothing to convert for this private devmode. So just initialize it.
  107. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  108. case OEMDM_MERGE:
  109. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  110. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  111. {
  112. WARNING(("OEMUD OEMDevMode(): not valid OEM Extra Data.\n"));
  113. return FALSE;
  114. }
  115. break;
  116. }
  117. return TRUE;
  118. }
  119. //////////////////////////////////////////////////////////////////////////
  120. // Function: BIsValidOEMDevModeParam
  121. //
  122. // Description: Validates OEM_DEVMODEPARAM structure.
  123. //
  124. //
  125. // Parameters:
  126. //
  127. // dwMode calling mode
  128. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  129. //
  130. //
  131. // Returns: TRUE if valid; FALSE otherwise.
  132. //
  133. //
  134. // Comments:
  135. //
  136. //
  137. // History:
  138. // NOTICE-2002/3/11-takashim
  139. // // 02/11/97 APresley Created.
  140. //
  141. //////////////////////////////////////////////////////////////////////////
  142. static BOOL BIsValidOEMDevModeParam(
  143. DWORD dwMode,
  144. POEMDMPARAM pOEMDevModeParam)
  145. {
  146. BOOL bValid = TRUE;
  147. if(NULL == pOEMDevModeParam)
  148. {
  149. WARNING(("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\n"));
  150. return FALSE;
  151. }
  152. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  153. {
  154. WARNING(("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\n"));
  155. bValid = FALSE;
  156. }
  157. if(NULL == pOEMDevModeParam->hPrinter)
  158. {
  159. WARNING(("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\n"));
  160. bValid = FALSE;
  161. }
  162. if(NULL == pOEMDevModeParam->hModule)
  163. {
  164. WARNING(("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\n"));
  165. bValid = FALSE;
  166. }
  167. if( (0 != pOEMDevModeParam->cbBufSize) &&
  168. (NULL == pOEMDevModeParam->pOEMDMOut)
  169. )
  170. {
  171. WARNING(("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\n"));
  172. bValid = FALSE;
  173. }
  174. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  175. {
  176. WARNING(("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\n"));
  177. bValid = FALSE;
  178. }
  179. return bValid;
  180. }
  181. //////////////////////////////////////////////////////////////////////////
  182. // Function: VDumpOEMDevModeParam
  183. //
  184. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  185. //
  186. //
  187. // Parameters:
  188. //
  189. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  190. //
  191. //
  192. // Returns: N/A.
  193. //
  194. //
  195. // Comments:
  196. //
  197. //
  198. // History:
  199. // NOTICE-2002/3/11-takashim
  200. // // 02/18/97 APresley Created.
  201. //
  202. //////////////////////////////////////////////////////////////////////////
  203. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  204. {
  205. // Can't dump if pOEMDevModeParam NULL.
  206. if(NULL != pOEMDevModeParam)
  207. {
  208. VERBOSE(("\n\tOEM_DEVMODEPARAM dump:\n\n"));
  209. VERBOSE(("\tcbSize = %d.\n", pOEMDevModeParam->cbSize));
  210. VERBOSE(("\thPrinter = %#lx.\n", pOEMDevModeParam->hPrinter));
  211. VERBOSE(("\thModule = %#lx.\n", pOEMDevModeParam->hModule));
  212. VERBOSE(("\tpPublicDMIn = %#lx.\n", pOEMDevModeParam->pPublicDMIn));
  213. VERBOSE(("\tpPublicDMOut = %#lx.\n", pOEMDevModeParam->pPublicDMOut));
  214. VERBOSE(("\tpOEMDMIn = %#lx.\n", pOEMDevModeParam->pOEMDMIn));
  215. VERBOSE(("\tpOEMDMOut = %#lx.\n", pOEMDevModeParam->pOEMDMOut));
  216. VERBOSE(("\tcbBufSize = %d.\n", pOEMDevModeParam->cbBufSize));
  217. }
  218. }