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.

293 lines
7.5 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/18-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. static BOOL BIsValidOEMDevModeParam(DWORD dwMode, POEMDMPARAM pOEMDevModeParam);
  21. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam);
  22. BOOL APIENTRY OEMGetInfo(DWORD dwInfo, PVOID pBuffer, DWORD cbSize, PDWORD pcbNeeded)
  23. {
  24. LPCSTR OEM_INFO[] = { "Bad Index",
  25. "OEMGI_GETSIGNATURE",
  26. "OEMGI_GETINTERFACEVERSION",
  27. "OEMGI_GETVERSION",
  28. };
  29. VERBOSE(("OEMGetInfo(%s) entry.\n", OEM_INFO[dwInfo]));
  30. // Validate parameters.
  31. if( ( (OEMGI_GETSIGNATURE != dwInfo) &&
  32. (OEMGI_GETINTERFACEVERSION != dwInfo) &&
  33. (OEMGI_GETVERSION != dwInfo) ) ||
  34. (NULL == pcbNeeded)
  35. )
  36. {
  37. WARNING(("OEMGetInfo() ERROR_INVALID_PARAMETER.\n"));
  38. // Did not write any bytes.
  39. if(NULL != pcbNeeded)
  40. *pcbNeeded = 0;
  41. return FALSE;
  42. }
  43. // Need/wrote 4 bytes.
  44. *pcbNeeded = 4;
  45. // Validate buffer size. Minimum size is four bytes.
  46. if( (NULL == pBuffer) || (4 > cbSize) )
  47. {
  48. WARNING(("OEMGetInfo() ERROR_INSUFFICIENT_BUFFER.\n"));
  49. return FALSE;
  50. }
  51. // Write information to buffer.
  52. switch(dwInfo)
  53. {
  54. case OEMGI_GETSIGNATURE:
  55. *(LPDWORD)pBuffer = OEM_SIGNATURE;
  56. break;
  57. case OEMGI_GETINTERFACEVERSION:
  58. *(LPDWORD)pBuffer = PRINTER_OEMINTF_VERSION;
  59. break;
  60. case OEMGI_GETVERSION:
  61. *(LPDWORD)pBuffer = OEM_VERSION;
  62. break;
  63. }
  64. return TRUE;
  65. }
  66. BOOL APIENTRY OEMDevMode(
  67. DWORD dwMode,
  68. POEMDMPARAM pOEMDevModeParam)
  69. {
  70. LPCSTR OEMDevMode_fMode[] = { "NULL",
  71. "OEMDM_SIZE",
  72. "OEMDM_DEFAULT",
  73. "OEMDM_CONVERT",
  74. "OEMDM_MERGE",
  75. };
  76. VERBOSE(("OEMDevMode(%s) entry.\n", OEMDevMode_fMode[dwMode]));
  77. // Validate parameters.
  78. if(!BIsValidOEMDevModeParam(dwMode, pOEMDevModeParam))
  79. {
  80. WARNING(("OEMDevMode() ERROR_INVALID_PARAMETER.\n"));
  81. VDumpOEMDevModeParam(pOEMDevModeParam);
  82. return FALSE;
  83. }
  84. // Verify OEM extra data size.
  85. if( (dwMode != OEMDM_SIZE) &&
  86. sizeof(OEMUD_EXTRADATA) > pOEMDevModeParam->cbBufSize )
  87. {
  88. WARNING(("OEMDevMode() ERROR_INSUFFICIENT_BUFFER.\n"));
  89. return FALSE;
  90. }
  91. // Handle dwMode.
  92. switch(dwMode)
  93. {
  94. case OEMDM_SIZE:
  95. pOEMDevModeParam->cbBufSize = sizeof(OEMUD_EXTRADATA);
  96. break;
  97. case OEMDM_DEFAULT:
  98. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  99. case OEMDM_CONVERT:
  100. // nothing to convert for this private devmode. So just initialize it.
  101. return BInitOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut);
  102. case OEMDM_MERGE:
  103. if(!BMergeOEMExtraData((POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMIn,
  104. (POEMUD_EXTRADATA)pOEMDevModeParam->pOEMDMOut) )
  105. {
  106. WARNING(("OEMUD OEMDevMode(): not valid OEM Extra Data.\n"));
  107. return FALSE;
  108. }
  109. break;
  110. }
  111. return TRUE;
  112. }
  113. static BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  114. {
  115. // Initialize OEM Extra data.
  116. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  117. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  118. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  119. return TRUE;
  120. }
  121. static BOOL BMergeOEMExtraData(
  122. POEMUD_EXTRADATA pdmIn,
  123. POEMUD_EXTRADATA pdmOut
  124. )
  125. {
  126. return TRUE;
  127. }
  128. //////////////////////////////////////////////////////////////////////////
  129. // Function: BIsValidOEMDevModeParam
  130. //
  131. // Description: Validates OEM_DEVMODEPARAM structure.
  132. //
  133. //
  134. // Parameters:
  135. //
  136. // dwMode calling mode
  137. // pOEMDevModeParam Pointer to a OEMDEVMODEPARAM structure.
  138. //
  139. //
  140. // Returns: TRUE if valid; FALSE otherwise.
  141. //
  142. //
  143. // Comments:
  144. //
  145. //
  146. // History:
  147. // 02/11/97 APresley Created.
  148. //
  149. //////////////////////////////////////////////////////////////////////////
  150. static BOOL BIsValidOEMDevModeParam(
  151. DWORD dwMode,
  152. POEMDMPARAM pOEMDevModeParam)
  153. {
  154. BOOL bValid = TRUE;
  155. if(NULL == pOEMDevModeParam)
  156. {
  157. WARNING(("OEMUD IsValidOEMDevModeParam(): pOEMDevModeParam is NULL.\n"));
  158. return FALSE;
  159. }
  160. if(sizeof(OEMDMPARAM) > pOEMDevModeParam->cbSize)
  161. {
  162. WARNING(("OEMUD IsValidOEMDevModeParam(): cbSize is smaller than sizeof(OEM_DEVMODEPARAM).\n"));
  163. bValid = FALSE;
  164. }
  165. if(NULL == pOEMDevModeParam->hPrinter)
  166. {
  167. WARNING(("OEMUD IsValidOEMDevModeParam(): hPrinter is NULL.\n"));
  168. bValid = FALSE;
  169. }
  170. if(NULL == pOEMDevModeParam->hModule)
  171. {
  172. WARNING(("OEMUD IsValidOEMDevModeParam(): hModule is NULL.\n"));
  173. bValid = FALSE;
  174. }
  175. if( (0 != pOEMDevModeParam->cbBufSize) &&
  176. (NULL == pOEMDevModeParam->pOEMDMOut)
  177. )
  178. {
  179. WARNING(("OEMUD IsValidOEMDevModeParam(): pOEMDMOut is NULL when it should not be.\n"));
  180. bValid = FALSE;
  181. }
  182. if( (OEMDM_MERGE == dwMode) && (NULL == pOEMDevModeParam->pOEMDMIn) )
  183. {
  184. WARNING(("OEMUD IsValidOEMDevModeParam(): pOEMDMIn is NULL when it should not be.\n"));
  185. bValid = FALSE;
  186. }
  187. return bValid;
  188. }
  189. //////////////////////////////////////////////////////////////////////////
  190. // Function: VDumpOEMDevModeParam
  191. //
  192. // Description: Debug dump of OEM_DEVMODEPARAM structure.
  193. //
  194. //
  195. // Parameters:
  196. //
  197. // pOEMDevModeParam Pointer to an OEM DevMode param structure.
  198. //
  199. //
  200. // Returns: N/A.
  201. //
  202. //
  203. // Comments:
  204. //
  205. //
  206. // History:
  207. // 02/18/97 APresley Created.
  208. //
  209. //////////////////////////////////////////////////////////////////////////
  210. static void VDumpOEMDevModeParam(POEMDMPARAM pOEMDevModeParam)
  211. {
  212. #if DBG
  213. // Can't dump if pOEMDevModeParam NULL.
  214. if(NULL != pOEMDevModeParam)
  215. {
  216. INT iTemp = giDebugLevel;
  217. VERBOSE(("\n\tOEM_DEVMODEPARAM dump:\n\n"));
  218. VERBOSE(("\tcbSize = %d.\n", pOEMDevModeParam->cbSize));
  219. VERBOSE(("\thPrinter = %#lx.\n", pOEMDevModeParam->hPrinter));
  220. VERBOSE(("\thModule = %#lx.\n", pOEMDevModeParam->hModule));
  221. VERBOSE(("\tpPublicDMIn = %#lx.\n", pOEMDevModeParam->pPublicDMIn));
  222. VERBOSE(("\tpPublicDMOut = %#lx.\n", pOEMDevModeParam->pPublicDMOut));
  223. VERBOSE(("\tpOEMDMIn = %#lx.\n", pOEMDevModeParam->pOEMDMIn));
  224. VERBOSE(("\tpOEMDMOut = %#lx.\n", pOEMDevModeParam->pOEMDMOut));
  225. VERBOSE(("\tcbBufSize = %d.\n", pOEMDevModeParam->cbBufSize));
  226. giDebugLevel = iTemp;
  227. }
  228. #endif // DBG
  229. }