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.

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